mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 13:03:42 +00:00
refactor(hooks): address PR feedback
- Rename getTools/setTools to getActiveTools/setActiveTools - Add getAllTools to enumerate all configured tools - Remove text_delta event (use turn_end/agent_end instead) - Add shortcut conflict detection: - Skip shortcuts that conflict with built-in shortcuts (with warning) - Log warnings when hooks register same shortcut (last wins) - Add note about prompt cache invalidation in setActiveTools - Update plan-mode hook to use agent_end for [DONE:id] parsing
This commit is contained in:
parent
5b634ddf75
commit
4ecf3f9422
13 changed files with 175 additions and 153 deletions
|
|
@ -306,21 +306,6 @@ pi.on("turn_end", async (event, ctx) => {
|
|||
});
|
||||
```
|
||||
|
||||
#### text_delta
|
||||
|
||||
Fired for each chunk of streaming text from the assistant. Useful for real-time monitoring of agent output.
|
||||
|
||||
```typescript
|
||||
pi.on("text_delta", async (event, ctx) => {
|
||||
// event.text - the new text chunk
|
||||
|
||||
// Example: watch for specific patterns in streaming output
|
||||
if (event.text.includes("[DONE:")) {
|
||||
// Handle completion marker
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
#### context
|
||||
|
||||
Fired before each LLM call. Modify messages non-destructively (session unchanged).
|
||||
|
|
@ -782,25 +767,35 @@ const result = await pi.exec("git", ["status"], {
|
|||
// result.stdout, result.stderr, result.code, result.killed
|
||||
```
|
||||
|
||||
### pi.getTools()
|
||||
### pi.getActiveTools()
|
||||
|
||||
Get the names of currently active tools:
|
||||
|
||||
```typescript
|
||||
const toolNames = pi.getTools();
|
||||
const toolNames = pi.getActiveTools();
|
||||
// ["read", "bash", "edit", "write"]
|
||||
```
|
||||
|
||||
### pi.setTools(toolNames)
|
||||
### pi.getAllTools()
|
||||
|
||||
Get all configured tools (built-in via --tools or default, plus custom tools):
|
||||
|
||||
```typescript
|
||||
const allTools = pi.getAllTools();
|
||||
// ["read", "bash", "edit", "write", "my-custom-tool"]
|
||||
```
|
||||
|
||||
### pi.setActiveTools(toolNames)
|
||||
|
||||
Set the active tools by name. Changes take effect on the next agent turn.
|
||||
Note: This will invalidate prompt caching for the next request.
|
||||
|
||||
```typescript
|
||||
// Switch to read-only mode (plan mode)
|
||||
pi.setTools(["read", "bash", "grep", "find", "ls"]);
|
||||
pi.setActiveTools(["read", "bash", "grep", "find", "ls"]);
|
||||
|
||||
// Restore full access
|
||||
pi.setTools(["read", "bash", "edit", "write"]);
|
||||
pi.setActiveTools(["read", "bash", "edit", "write"]);
|
||||
```
|
||||
|
||||
Only built-in tools can be enabled/disabled. Custom tools are always active. Unknown tool names are ignored.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue