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.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"os/exec"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"kit/ext"
|
|
)
|
|
|
|
// Init expands inline bash expressions in user prompts before they reach the
|
|
// LLM. Text like !{git branch --show-current} is replaced with the command's
|
|
// stdout. Inspired by Pi's inline-bash.ts.
|
|
//
|
|
// Examples:
|
|
//
|
|
// "Fix the tests on !{git branch --show-current}"
|
|
// → "Fix the tests on main"
|
|
//
|
|
// "The current directory is !{pwd}"
|
|
// → "The current directory is /home/user/project"
|
|
//
|
|
// Usage: kit -e examples/extensions/inline-bash.go
|
|
func Init(api ext.API) {
|
|
// Matches !{...} with non-greedy content.
|
|
re := regexp.MustCompile(`!\{([^}]+)\}`)
|
|
|
|
api.OnInput(func(ev ext.InputEvent, ctx ext.Context) *ext.InputResult {
|
|
if !re.MatchString(ev.Text) {
|
|
return nil
|
|
}
|
|
|
|
expanded := re.ReplaceAllStringFunc(ev.Text, func(match string) string {
|
|
// Extract the command between !{ and }.
|
|
cmd := re.FindStringSubmatch(match)[1]
|
|
cmd = strings.TrimSpace(cmd)
|
|
|
|
out, err := exec.Command("bash", "-c", cmd).Output()
|
|
if err != nil {
|
|
return match // keep original on error
|
|
}
|
|
return strings.TrimSpace(string(out))
|
|
})
|
|
|
|
return &ext.InputResult{
|
|
Action: "transform",
|
|
Text: expanded,
|
|
}
|
|
})
|
|
}
|