session-name.ts 785 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Session naming example.
  3. *
  4. * Shows setSessionName/getSessionName to give sessions friendly names
  5. * that appear in the session selector instead of the first message.
  6. *
  7. * Usage: /session-name [name] - set or show session name
  8. */
  9. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  10. export default function (pi: ExtensionAPI) {
  11. pi.registerCommand("session-name", {
  12. description: "Set or show session name (usage: /session-name [new name])",
  13. handler: async (args, ctx) => {
  14. const name = args.trim();
  15. if (name) {
  16. pi.setSessionName(name);
  17. ctx.ui.notify(`Session named: ${name}`, "info");
  18. } else {
  19. const current = pi.getSessionName();
  20. ctx.ui.notify(current ? `Session: ${current}` : "No session name set", "info");
  21. }
  22. },
  23. });
  24. }