mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 14:03:49 +00:00
feat(coding-agent): add hook API for CLI flags, shortcuts, and tool control
Hook API additions: - pi.getTools() / pi.setTools(toolNames) - dynamically enable/disable tools - pi.registerFlag(name, options) / pi.getFlag(name) - register custom CLI flags - pi.registerShortcut(shortcut, options) - register keyboard shortcuts Plan mode hook (examples/hooks/plan-mode.ts): - /plan command or Shift+P shortcut to toggle - --plan CLI flag to start in plan mode - Read-only tools: read, bash, grep, find, ls - Bash restricted to non-destructive commands (blocks rm, mv, git commit, etc.) - Interactive prompt after each response: execute, stay, or refine - Shows plan indicator in footer when active - State persists across sessions
This commit is contained in:
parent
059292ead1
commit
c956a726ed
13 changed files with 636 additions and 46 deletions
|
|
@ -775,6 +775,44 @@ pi.setTools(["read", "bash", "edit", "write"]);
|
|||
|
||||
Only built-in tools can be enabled/disabled. Custom tools are always active. Unknown tool names are ignored.
|
||||
|
||||
### pi.registerFlag(name, options)
|
||||
|
||||
Register a CLI flag for this hook. Flag values are accessible via `pi.getFlag()`.
|
||||
|
||||
```typescript
|
||||
pi.registerFlag("plan", {
|
||||
description: "Start in plan mode (read-only)",
|
||||
type: "boolean", // or "string"
|
||||
default: false,
|
||||
});
|
||||
```
|
||||
|
||||
### pi.getFlag(name)
|
||||
|
||||
Get the value of a CLI flag registered by this hook.
|
||||
|
||||
```typescript
|
||||
if (pi.getFlag("plan") === true) {
|
||||
// plan mode enabled via --plan flag
|
||||
}
|
||||
```
|
||||
|
||||
### pi.registerShortcut(shortcut, options)
|
||||
|
||||
Register a keyboard shortcut for this hook. The handler is called when the shortcut is pressed.
|
||||
|
||||
```typescript
|
||||
pi.registerShortcut("shift+p", {
|
||||
description: "Toggle plan mode",
|
||||
handler: async (ctx) => {
|
||||
// toggle mode
|
||||
ctx.ui.notify("Plan mode toggled");
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Shortcut format: `modifier+key` where modifier can be `shift`, `ctrl`, `alt`, or combinations like `ctrl+shift`.
|
||||
|
||||
## Examples
|
||||
|
||||
### Permission Gate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue