mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 15:03:31 +00:00
BREAKING CHANGE: ToolDefinition.execute parameter order changed from (id, params, onUpdate, ctx, signal) to (id, params, signal, onUpdate, ctx). This aligns with AgentTool.execute so wrapping built-in tools no longer requires parameter reordering. Update extensions by swapping signal and onUpdate parameters.
30 lines
692 B
TypeScript
30 lines
692 B
TypeScript
/**
|
|
* Bash Spawn Hook Example
|
|
*
|
|
* Adjusts command, cwd, and env before execution.
|
|
*
|
|
* Usage:
|
|
* pi -e ./bash-spawn-hook.ts
|
|
*/
|
|
|
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
import { createBashTool } from "@mariozechner/pi-coding-agent";
|
|
|
|
export default function (pi: ExtensionAPI) {
|
|
const cwd = process.cwd();
|
|
|
|
const bashTool = createBashTool(cwd, {
|
|
spawnHook: ({ command, cwd, env }) => ({
|
|
command: `source ~/.profile\n${command}`,
|
|
cwd,
|
|
env: { ...env, PI_SPAWN_HOOK: "1" },
|
|
}),
|
|
});
|
|
|
|
pi.registerTool({
|
|
...bashTool,
|
|
execute: async (id, params, signal, onUpdate, _ctx) => {
|
|
return bashTool.execute(id, params, signal, onUpdate);
|
|
},
|
|
});
|
|
}
|