flake-update-20260505
1/**
2 * Subagent Commands - Slash commands for common subagent workflows
3 *
4 * Provides easy-to-use slash commands that invoke the subagent tool:
5 * - /scout <query> - Fast reconnaissance with scout agent
6 * - /implement <query> - Full workflow: scout → planner → worker
7 * - /scout-and-plan <query> - Planning workflow: scout → planner
8 * - /review-code <query> - Review workflow: scout → reviewer
9 */
10
11import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
12
13export default function (pi: ExtensionAPI) {
14 // /scout - Quick reconnaissance
15 pi.registerCommand("scout", {
16 description: "Quick codebase reconnaissance with scout agent",
17 handler: async (args, ctx) => {
18 if (!args.trim()) {
19 ctx.ui.notify("Usage: /scout <query>", "error");
20 return;
21 }
22
23 // Send a message that will cause the AI to use the subagent tool
24 ctx.ui.notify("Dispatching scout agent...", "info");
25 pi.sendUserMessage(`Use the subagent tool to run the scout agent with this task: ${args}`);
26 },
27 });
28
29 // /implement - Full workflow
30 pi.registerCommand("implement", {
31 description: "Full implementation workflow: scout → planner → worker",
32 handler: async (args, ctx) => {
33 if (!args.trim()) {
34 ctx.ui.notify("Usage: /implement <query>", "error");
35 return;
36 }
37
38 ctx.ui.notify("Starting implementation workflow...", "info");
39 pi.sendUserMessage(
40 `Use the subagent tool with chain mode to implement: ${args}\n\n` +
41 `Chain:\n` +
42 `1. scout agent: find all code relevant to: ${args}\n` +
43 `2. planner agent: create implementation plan using {previous}\n` +
44 `3. worker agent: implement the plan from {previous}`
45 );
46 },
47 });
48
49 // /scout-and-plan - Planning workflow
50 pi.registerCommand("scout-and-plan", {
51 description: "Planning workflow: scout → planner (no implementation)",
52 handler: async (args, ctx) => {
53 if (!args.trim()) {
54 ctx.ui.notify("Usage: /scout-and-plan <query>", "error");
55 return;
56 }
57
58 ctx.ui.notify("Starting planning workflow...", "info");
59 pi.sendUserMessage(
60 `Use the subagent tool with chain mode for planning: ${args}\n\n` +
61 `Chain:\n` +
62 `1. scout agent: find all code relevant to: ${args}\n` +
63 `2. planner agent: create implementation plan using {previous}`
64 );
65 },
66 });
67
68 // /review-code - Review workflow
69 pi.registerCommand("review-code", {
70 description: "Code review workflow: scout → reviewer",
71 handler: async (args, ctx) => {
72 if (!args.trim()) {
73 ctx.ui.notify("Usage: /review-code <query>", "error");
74 return;
75 }
76
77 ctx.ui.notify("Starting code review...", "info");
78 pi.sendUserMessage(
79 `Use the subagent tool with chain mode to review: ${args}\n\n` +
80 `Chain:\n` +
81 `1. scout agent: find all code relevant to: ${args}\n` +
82 `2. reviewer agent: review the code from {previous}`
83 );
84 },
85 });
86
87 // /oracle - Deep analysis and debugging
88 pi.registerCommand("oracle", {
89 description: "Deep analysis, debugging, and architecture investigation with oracle agent",
90 handler: async (args, ctx) => {
91 if (!args.trim()) {
92 ctx.ui.notify("Usage: /oracle <question or problem>", "error");
93 return;
94 }
95
96 ctx.ui.notify("Dispatching oracle agent...", "info");
97 pi.sendUserMessage(`Use the subagent tool to run the oracle agent with this task: ${args}`);
98 },
99 });
100
101 // /research - Technical research with web search
102 pi.registerCommand("research", {
103 description: "Technical research with web search, GitHub, and Stack Overflow via researcher agent",
104 handler: async (args, ctx) => {
105 if (!args.trim()) {
106 ctx.ui.notify("Usage: /research <topic or question>", "error");
107 return;
108 }
109
110 ctx.ui.notify("Dispatching researcher agent...", "info");
111 pi.sendUserMessage(`Use the subagent tool to run the researcher agent with this task: ${args}`);
112 },
113 });
114
115 // /subagent-help - Show available agents
116 pi.registerCommand("subagent-help", {
117 description: "Show available subagents and usage",
118 handler: async (_args, ctx) => {
119 const help = `
120# Subagent Extension Help
121
122## Available Slash Commands
123
124- \`/scout <query>\` - Quick reconnaissance (uses Haiku, fast & cheap)
125- \`/implement <query>\` - Full workflow: scout → planner → worker
126- \`/scout-and-plan <query>\` - Planning only: scout → planner
127- \`/review-code <query>\` - Code review: scout → reviewer
128- \`/oracle <query>\` - Deep analysis, debugging, architecture investigation
129- \`/research <query>\` - Technical research with web search
130
131## Available Agents
132
133- **scout** (Haiku) - Fast recon, returns compressed context
134- **planner** (Sonnet) - Creates implementation plans
135- **reviewer** (Sonnet) - Code review
136- **worker** (Sonnet) - General purpose, full capabilities
137- **oracle** (Opus) - Deep analysis, debugging, architecture decisions
138- **researcher** (Sonnet) - Technical research with web/GitHub/SO search
139
140## Direct Tool Usage
141
142You can also ask the AI to use the subagent tool directly:
143
144**Single agent:**
145> Use scout to find all authentication code
146
147**Parallel:**
148> Run scouts in parallel: find DB schemas, find API endpoints
149
150**Chain:**
151> Chain: scout finds auth code, then planner suggests improvements
152
153## Examples
154
155\`\`\`
156/scout find all Tekton Task definitions
157/implement add Redis caching to session store
158/scout-and-plan refactor authentication module
159/review-code check security in auth handlers
160\`\`\`
161
162## Agent Details
163
164Location: ~/.pi/agent/agents/*.md
165`;
166 ctx.ui.notify("Subagent help displayed", "info");
167 console.log(help);
168 },
169 });
170}