@earendil-works/pi-coding-agent
Version:
Coding agent CLI with read, bash, edit, write tools and session management
31 lines (26 loc) • 696 B
text/typescript
/**
* Bash Spawn Hook Example
*
* Adjusts command, cwd, and env before execution.
*
* Usage:
* pi -e ./bash-spawn-hook.ts
*/
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { createBashTool } from "@earendil-works/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);
},
});
}