hidden-thinking-label.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Hidden Thinking Label Extension
  3. *
  4. * Demonstrates `ctx.ui.setHiddenThinkingLabel()` for customizing the label shown
  5. * when thinking blocks are hidden.
  6. *
  7. * Usage:
  8. * pi --extension examples/extensions/hidden-thinking-label.ts
  9. *
  10. * Test:
  11. * 1. Load this extension
  12. * 2. Hide thinking blocks with Ctrl+T
  13. * 3. Ask for something that produces reasoning output
  14. * 4. The collapsed thinking block label will show the custom text
  15. *
  16. * Commands:
  17. * /thinking-label <text> Set a custom hidden thinking label
  18. * /thinking-label Reset to the default label
  19. */
  20. import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
  21. const DEFAULT_LABEL = "Pondering...";
  22. export default function (pi: ExtensionAPI) {
  23. let label = DEFAULT_LABEL;
  24. const applyLabel = (ctx: ExtensionContext) => {
  25. ctx.ui.setHiddenThinkingLabel(label);
  26. };
  27. pi.on("session_start", async (_event, ctx) => {
  28. applyLabel(ctx);
  29. });
  30. pi.registerCommand("thinking-label", {
  31. description: "Set the hidden thinking label. Use without args to reset.",
  32. handler: async (args, ctx) => {
  33. const nextLabel = args.trim();
  34. if (!nextLabel) {
  35. label = DEFAULT_LABEL;
  36. ctx.ui.setHiddenThinkingLabel();
  37. ctx.ui.notify(`Hidden thinking label reset to: ${DEFAULT_LABEL}`);
  38. return;
  39. }
  40. label = nextLabel;
  41. ctx.ui.setHiddenThinkingLabel(label);
  42. ctx.ui.notify(`Hidden thinking label set to: ${label}`);
  43. },
  44. });
  45. }