bash-spawn-hook.ts 696 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Bash Spawn Hook Example
  3. *
  4. * Adjusts command, cwd, and env before execution.
  5. *
  6. * Usage:
  7. * pi -e ./bash-spawn-hook.ts
  8. */
  9. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  10. import { createBashTool } from "@earendil-works/pi-coding-agent";
  11. export default function (pi: ExtensionAPI) {
  12. const cwd = process.cwd();
  13. const bashTool = createBashTool(cwd, {
  14. spawnHook: ({ command, cwd, env }) => ({
  15. command: `source ~/.profile\n${command}`,
  16. cwd,
  17. env: { ...env, PI_SPAWN_HOOK: "1" },
  18. }),
  19. });
  20. pi.registerTool({
  21. ...bashTool,
  22. execute: async (id, params, signal, onUpdate, _ctx) => {
  23. return bashTool.execute(id, params, signal, onUpdate);
  24. },
  25. });
  26. }