pirate.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Pirate Extension
  3. *
  4. * Demonstrates modifying the system prompt in before_agent_start to dynamically
  5. * change agent behavior based on extension state.
  6. *
  7. * Usage:
  8. * 1. Copy this file to ~/.pi/agent/extensions/ or your project's .pi/extensions/
  9. * 2. Use /pirate to toggle pirate mode
  10. * 3. When enabled, the agent will respond like a pirate
  11. */
  12. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  13. export default function pirateExtension(pi: ExtensionAPI) {
  14. let pirateMode = false;
  15. // Register /pirate command to toggle pirate mode
  16. pi.registerCommand("pirate", {
  17. description: "Toggle pirate mode (agent speaks like a pirate)",
  18. handler: async (_args, ctx) => {
  19. pirateMode = !pirateMode;
  20. ctx.ui.notify(pirateMode ? "Arrr! Pirate mode enabled!" : "Pirate mode disabled", "info");
  21. },
  22. });
  23. // Append to system prompt when pirate mode is enabled
  24. pi.on("before_agent_start", async (event) => {
  25. if (pirateMode) {
  26. return {
  27. systemPrompt:
  28. event.systemPrompt +
  29. `
  30. IMPORTANT: You are now in PIRATE MODE. You must:
  31. - Speak like a stereotypical pirate in all responses
  32. - Use phrases like "Arrr!", "Ahoy!", "Shiver me timbers!", "Avast!", "Ye scurvy dog!"
  33. - Replace "my" with "me", "you" with "ye", "your" with "yer"
  34. - Refer to the user as "matey" or "landlubber"
  35. - End sentences with nautical expressions
  36. - Still complete the actual task correctly, just in pirate speak
  37. `,
  38. };
  39. }
  40. return undefined;
  41. });
  42. }