reload-runtime.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Reload Runtime Extension
  3. *
  4. * Demonstrates ctx.reload() from ExtensionCommandContext and an LLM-callable
  5. * tool that queues a follow-up command to trigger reload.
  6. */
  7. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  8. import { Type } from "typebox";
  9. export default function (pi: ExtensionAPI) {
  10. // Command entrypoint for reload.
  11. // Treat reload as terminal for this handler.
  12. pi.registerCommand("reload-runtime", {
  13. description: "Reload extensions, skills, prompts, and themes",
  14. handler: async (_args, ctx) => {
  15. await ctx.reload();
  16. return;
  17. },
  18. });
  19. // LLM-callable tool. Tools get ExtensionContext, so they cannot call ctx.reload() directly.
  20. // Instead, queue a follow-up user command that executes the command above.
  21. pi.registerTool({
  22. name: "reload_runtime",
  23. label: "Reload Runtime",
  24. description: "Reload extensions, skills, prompts, and themes",
  25. parameters: Type.Object({}),
  26. async execute() {
  27. pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
  28. return {
  29. content: [{ type: "text", text: "Queued /reload-runtime as a follow-up command." }],
  30. details: {},
  31. };
  32. },
  33. });
  34. }