mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 17:00:59 +00:00
feat(hooks): add systemPromptAppend to before_agent_start, full tool registry
- before_agent_start handlers can return systemPromptAppend to dynamically append text to the system prompt for that turn - Multiple hooks' systemPromptAppend strings are concatenated - Multiple hooks' messages are now all injected (not just first) - Tool registry now contains ALL built-in tools (read, bash, edit, write, grep, find, ls) regardless of --tools flag - --tools only sets initially active tools, hooks can enable any via setActiveTools() - System prompt automatically rebuilds when tools change, updating tool descriptions and guidelines - Add pirate.ts example hook demonstrating systemPromptAppend - Update hooks.md with systemPromptAppend documentation
This commit is contained in:
parent
892acedb6b
commit
e4dd21a3b2
7 changed files with 136 additions and 20 deletions
|
|
@ -18,6 +18,7 @@ cp permission-gate.ts ~/.pi/agent/hooks/
|
|||
|------|-------------|
|
||||
| `plan-mode.ts` | Claude Code-style plan mode for read-only exploration with `/plan` command |
|
||||
| `tools.ts` | Interactive `/tools` command to enable/disable tools with session persistence |
|
||||
| `pirate.ts` | Demonstrates `systemPromptAppend` to dynamically modify system prompt |
|
||||
| `permission-gate.ts` | Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
|
||||
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on branch |
|
||||
| `protected-paths.ts` | Blocks writes to protected paths (.env, .git/, node_modules/) |
|
||||
|
|
|
|||
44
packages/coding-agent/examples/hooks/pirate.ts
Normal file
44
packages/coding-agent/examples/hooks/pirate.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Pirate Hook
|
||||
*
|
||||
* Demonstrates using systemPromptAppend in before_agent_start to dynamically
|
||||
* modify the system prompt based on hook state.
|
||||
*
|
||||
* Usage:
|
||||
* 1. Copy this file to ~/.pi/agent/hooks/ or your project's .pi/hooks/
|
||||
* 2. Use /pirate to toggle pirate mode
|
||||
* 3. When enabled, the agent will respond like a pirate
|
||||
*/
|
||||
|
||||
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||
|
||||
export default function pirateHook(pi: HookAPI) {
|
||||
let pirateMode = false;
|
||||
|
||||
// Register /pirate command to toggle pirate mode
|
||||
pi.registerCommand("pirate", {
|
||||
description: "Toggle pirate mode (agent speaks like a pirate)",
|
||||
handler: async (_args, ctx) => {
|
||||
pirateMode = !pirateMode;
|
||||
ctx.ui.notify(pirateMode ? "Arrr! Pirate mode enabled!" : "Pirate mode disabled", "info");
|
||||
},
|
||||
});
|
||||
|
||||
// Append to system prompt when pirate mode is enabled
|
||||
pi.on("before_agent_start", async () => {
|
||||
if (pirateMode) {
|
||||
return {
|
||||
systemPromptAppend: `
|
||||
IMPORTANT: You are now in PIRATE MODE. You must:
|
||||
- Speak like a stereotypical pirate in all responses
|
||||
- Use phrases like "Arrr!", "Ahoy!", "Shiver me timbers!", "Avast!", "Ye scurvy dog!"
|
||||
- Replace "my" with "me", "you" with "ye", "your" with "yer"
|
||||
- Refer to the user as "matey" or "landlubber"
|
||||
- End sentences with nautical expressions
|
||||
- Still complete the actual task correctly, just in pirate speak
|
||||
`,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue