mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
23c16bb197
Phase 2+3 extension API additions:
- Tool management: GetAllTools, SetActiveTools (plan-mode support)
- Model management: SetModel, GetAvailableModels, ModelChangedEvent
- Extension options: RegisterOption, GetOption, SetOption (env/config/default)
- Inter-extension event bus: OnCustomEvent, EmitCustomEvent
- Direct LLM completion: ctx.Complete with streaming/blocking modes
- Steer delivery mode: CancelAndSend for interrupt-and-redirect
New example extensions (10):
- plan-mode.go: read-only exploration with /plan toggle
- summarize.go: conversation summarization via ctx.Complete
- bookmark.go: persistent bookmarks via AppendEntry/GetEntries
- auto-commit.go: auto-commit on exit using last assistant message
- permission-gate.go: confirm dangerous bash commands
- protected-paths.go: block writes to .env, .git/, secrets/
- notify.go: desktop notifications on agent completion
- inline-bash.go: !{cmd} expansion in prompts
- pirate.go: system prompt persona injection
- project-rules.go: load .kit/rules/*.md into system prompt
Always-wrap tools through runner for SetActiveTools disabled-tool checking.
Removed phase1/phase2 test extensions from examples.
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"kit/ext"
|
|
)
|
|
|
|
// Init loads project-specific rules from .kit/rules/ into the system prompt.
|
|
// Each .md file in the rules directory is injected as additional context,
|
|
// giving projects a way to customise LLM behaviour without editing the
|
|
// main system prompt. Inspired by Pi's claude-rules.ts.
|
|
//
|
|
// Place rule files in:
|
|
//
|
|
// .kit/rules/code-style.md
|
|
// .kit/rules/testing.md
|
|
// .kit/rules/security.md
|
|
//
|
|
// Usage: kit -e examples/extensions/project-rules.go
|
|
func Init(api ext.API) {
|
|
var rules string
|
|
|
|
api.OnSessionStart(func(_ ext.SessionStartEvent, ctx ext.Context) {
|
|
rulesDir := filepath.Join(ctx.CWD, ".kit", "rules")
|
|
entries, err := os.ReadDir(rulesDir)
|
|
if err != nil {
|
|
return // no rules directory, nothing to do
|
|
}
|
|
|
|
var parts []string
|
|
for _, entry := range entries {
|
|
if entry.IsDir() {
|
|
continue
|
|
}
|
|
name := entry.Name()
|
|
if !strings.HasSuffix(name, ".md") && !strings.HasSuffix(name, ".txt") {
|
|
continue
|
|
}
|
|
data, err := os.ReadFile(filepath.Join(rulesDir, name))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
content := strings.TrimSpace(string(data))
|
|
if content != "" {
|
|
parts = append(parts, "## "+strings.TrimSuffix(name, filepath.Ext(name))+"\n\n"+content)
|
|
}
|
|
}
|
|
|
|
if len(parts) == 0 {
|
|
return
|
|
}
|
|
|
|
rules = "# Project Rules\n\n" + strings.Join(parts, "\n\n---\n\n")
|
|
ctx.PrintInfo(fmt.Sprintf("[project-rules] Loaded %d rule file(s) from .kit/rules/", len(parts)))
|
|
})
|
|
|
|
api.OnBeforeAgentStart(func(_ ext.BeforeAgentStartEvent, ctx ext.Context) *ext.BeforeAgentStartResult {
|
|
if rules == "" {
|
|
return nil
|
|
}
|
|
return &ext.BeforeAgentStartResult{
|
|
SystemPrompt: &rules,
|
|
}
|
|
})
|
|
}
|