singularity-forge/docs-internal/extending-pi/11-custom-commands-user-facing-actions.md
Lex Christopherson d20d5e8fb5 docs: add Mintlify documentation site and move internal docs
Add a proper public-facing documentation site using Mintlify with 19 MDX
pages covering getting started, auto mode, commands, configuration, and
all user-facing features. Move internal/SDK documentation (Pi SDK, TUI,
context & hooks, research notes, ADRs) to docs-internal/ since they
should not be part of the public documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 09:54:41 -06:00

1.2 KiB

Custom Commands — User-Facing Actions

Commands let users invoke your extension directly via /mycommand.

pi.registerCommand("deploy", {
  description: "Deploy to an environment",
  
  // Optional: argument auto-completion
  getArgumentCompletions: (prefix: string) => {
    const envs = ["dev", "staging", "prod"];
    return envs
      .filter(e => e.startsWith(prefix))
      .map(e => ({ value: e, label: e }));
  },
  
  handler: async (args, ctx) => {
    // args = everything after "/deploy "
    // ctx = ExtensionCommandContext (has extra session control methods)
    
    await ctx.waitForIdle();  // Wait for agent to finish
    ctx.ui.notify(`Deploying to ${args}`, "info");
  },
});

Command Context Extras

Command handlers get ExtensionCommandContext which extends ExtensionContext with:

  • ctx.waitForIdle() — Wait for agent to finish
  • ctx.newSession(options?) — Create a new session
  • ctx.fork(entryId) — Fork from an entry
  • ctx.navigateTree(targetId, options?) — Navigate the session tree
  • ctx.reload() — Hot-reload everything

Important: These methods are only available in commands, not in event handlers, because they would deadlock there.