@oh-my-pi/pi-coding-agent 1.337.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CHANGELOG.md +1228 -0
  2. package/README.md +1041 -0
  3. package/docs/compaction.md +403 -0
  4. package/docs/custom-tools.md +541 -0
  5. package/docs/extension-loading.md +1004 -0
  6. package/docs/hooks.md +867 -0
  7. package/docs/rpc.md +1040 -0
  8. package/docs/sdk.md +994 -0
  9. package/docs/session-tree-plan.md +441 -0
  10. package/docs/session.md +240 -0
  11. package/docs/skills.md +290 -0
  12. package/docs/theme.md +637 -0
  13. package/docs/tree.md +197 -0
  14. package/docs/tui.md +341 -0
  15. package/examples/README.md +21 -0
  16. package/examples/custom-tools/README.md +124 -0
  17. package/examples/custom-tools/hello/index.ts +20 -0
  18. package/examples/custom-tools/question/index.ts +84 -0
  19. package/examples/custom-tools/subagent/README.md +172 -0
  20. package/examples/custom-tools/subagent/agents/planner.md +37 -0
  21. package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
  22. package/examples/custom-tools/subagent/agents/scout.md +50 -0
  23. package/examples/custom-tools/subagent/agents/worker.md +24 -0
  24. package/examples/custom-tools/subagent/agents.ts +156 -0
  25. package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
  26. package/examples/custom-tools/subagent/commands/implement.md +10 -0
  27. package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
  28. package/examples/custom-tools/subagent/index.ts +1002 -0
  29. package/examples/custom-tools/todo/index.ts +212 -0
  30. package/examples/hooks/README.md +56 -0
  31. package/examples/hooks/auto-commit-on-exit.ts +49 -0
  32. package/examples/hooks/confirm-destructive.ts +59 -0
  33. package/examples/hooks/custom-compaction.ts +116 -0
  34. package/examples/hooks/dirty-repo-guard.ts +52 -0
  35. package/examples/hooks/file-trigger.ts +41 -0
  36. package/examples/hooks/git-checkpoint.ts +53 -0
  37. package/examples/hooks/handoff.ts +150 -0
  38. package/examples/hooks/permission-gate.ts +34 -0
  39. package/examples/hooks/protected-paths.ts +30 -0
  40. package/examples/hooks/qna.ts +119 -0
  41. package/examples/hooks/snake.ts +343 -0
  42. package/examples/hooks/status-line.ts +40 -0
  43. package/examples/sdk/01-minimal.ts +22 -0
  44. package/examples/sdk/02-custom-model.ts +49 -0
  45. package/examples/sdk/03-custom-prompt.ts +44 -0
  46. package/examples/sdk/04-skills.ts +44 -0
  47. package/examples/sdk/05-tools.ts +90 -0
  48. package/examples/sdk/06-hooks.ts +61 -0
  49. package/examples/sdk/07-context-files.ts +36 -0
  50. package/examples/sdk/08-slash-commands.ts +42 -0
  51. package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
  52. package/examples/sdk/10-settings.ts +38 -0
  53. package/examples/sdk/11-sessions.ts +48 -0
  54. package/examples/sdk/12-full-control.ts +95 -0
  55. package/examples/sdk/README.md +154 -0
  56. package/package.json +81 -0
  57. package/src/cli/args.ts +246 -0
  58. package/src/cli/file-processor.ts +72 -0
  59. package/src/cli/list-models.ts +104 -0
  60. package/src/cli/plugin-cli.ts +650 -0
  61. package/src/cli/session-picker.ts +41 -0
  62. package/src/cli.ts +10 -0
  63. package/src/commands/init.md +20 -0
  64. package/src/config.ts +159 -0
  65. package/src/core/agent-session.ts +1900 -0
  66. package/src/core/auth-storage.ts +236 -0
  67. package/src/core/bash-executor.ts +196 -0
  68. package/src/core/compaction/branch-summarization.ts +343 -0
  69. package/src/core/compaction/compaction.ts +742 -0
  70. package/src/core/compaction/index.ts +7 -0
  71. package/src/core/compaction/utils.ts +154 -0
  72. package/src/core/custom-tools/index.ts +21 -0
  73. package/src/core/custom-tools/loader.ts +248 -0
  74. package/src/core/custom-tools/types.ts +169 -0
  75. package/src/core/custom-tools/wrapper.ts +28 -0
  76. package/src/core/exec.ts +129 -0
  77. package/src/core/export-html/index.ts +211 -0
  78. package/src/core/export-html/template.css +781 -0
  79. package/src/core/export-html/template.html +54 -0
  80. package/src/core/export-html/template.js +1185 -0
  81. package/src/core/export-html/vendor/highlight.min.js +1213 -0
  82. package/src/core/export-html/vendor/marked.min.js +6 -0
  83. package/src/core/hooks/index.ts +16 -0
  84. package/src/core/hooks/loader.ts +312 -0
  85. package/src/core/hooks/runner.ts +434 -0
  86. package/src/core/hooks/tool-wrapper.ts +99 -0
  87. package/src/core/hooks/types.ts +773 -0
  88. package/src/core/index.ts +52 -0
  89. package/src/core/mcp/client.ts +158 -0
  90. package/src/core/mcp/config.ts +154 -0
  91. package/src/core/mcp/index.ts +45 -0
  92. package/src/core/mcp/loader.ts +68 -0
  93. package/src/core/mcp/manager.ts +181 -0
  94. package/src/core/mcp/tool-bridge.ts +148 -0
  95. package/src/core/mcp/transports/http.ts +316 -0
  96. package/src/core/mcp/transports/index.ts +6 -0
  97. package/src/core/mcp/transports/stdio.ts +252 -0
  98. package/src/core/mcp/types.ts +220 -0
  99. package/src/core/messages.ts +189 -0
  100. package/src/core/model-registry.ts +317 -0
  101. package/src/core/model-resolver.ts +393 -0
  102. package/src/core/plugins/doctor.ts +59 -0
  103. package/src/core/plugins/index.ts +38 -0
  104. package/src/core/plugins/installer.ts +189 -0
  105. package/src/core/plugins/loader.ts +338 -0
  106. package/src/core/plugins/manager.ts +672 -0
  107. package/src/core/plugins/parser.ts +105 -0
  108. package/src/core/plugins/paths.ts +32 -0
  109. package/src/core/plugins/types.ts +190 -0
  110. package/src/core/sdk.ts +760 -0
  111. package/src/core/session-manager.ts +1128 -0
  112. package/src/core/settings-manager.ts +443 -0
  113. package/src/core/skills.ts +437 -0
  114. package/src/core/slash-commands.ts +248 -0
  115. package/src/core/system-prompt.ts +439 -0
  116. package/src/core/timings.ts +25 -0
  117. package/src/core/tools/ask.ts +211 -0
  118. package/src/core/tools/bash-interceptor.ts +120 -0
  119. package/src/core/tools/bash.ts +250 -0
  120. package/src/core/tools/context.ts +32 -0
  121. package/src/core/tools/edit-diff.ts +475 -0
  122. package/src/core/tools/edit.ts +208 -0
  123. package/src/core/tools/exa/company.ts +59 -0
  124. package/src/core/tools/exa/index.ts +64 -0
  125. package/src/core/tools/exa/linkedin.ts +59 -0
  126. package/src/core/tools/exa/logger.ts +56 -0
  127. package/src/core/tools/exa/mcp-client.ts +368 -0
  128. package/src/core/tools/exa/render.ts +196 -0
  129. package/src/core/tools/exa/researcher.ts +90 -0
  130. package/src/core/tools/exa/search.ts +337 -0
  131. package/src/core/tools/exa/types.ts +168 -0
  132. package/src/core/tools/exa/websets.ts +248 -0
  133. package/src/core/tools/find.ts +261 -0
  134. package/src/core/tools/grep.ts +555 -0
  135. package/src/core/tools/index.ts +202 -0
  136. package/src/core/tools/ls.ts +140 -0
  137. package/src/core/tools/lsp/client.ts +605 -0
  138. package/src/core/tools/lsp/config.ts +147 -0
  139. package/src/core/tools/lsp/edits.ts +101 -0
  140. package/src/core/tools/lsp/index.ts +804 -0
  141. package/src/core/tools/lsp/render.ts +447 -0
  142. package/src/core/tools/lsp/rust-analyzer.ts +145 -0
  143. package/src/core/tools/lsp/types.ts +463 -0
  144. package/src/core/tools/lsp/utils.ts +486 -0
  145. package/src/core/tools/notebook.ts +229 -0
  146. package/src/core/tools/path-utils.ts +61 -0
  147. package/src/core/tools/read.ts +240 -0
  148. package/src/core/tools/renderers.ts +540 -0
  149. package/src/core/tools/task/agents.ts +153 -0
  150. package/src/core/tools/task/artifacts.ts +114 -0
  151. package/src/core/tools/task/bundled-agents/browser.md +71 -0
  152. package/src/core/tools/task/bundled-agents/explore.md +82 -0
  153. package/src/core/tools/task/bundled-agents/plan.md +54 -0
  154. package/src/core/tools/task/bundled-agents/reviewer.md +59 -0
  155. package/src/core/tools/task/bundled-agents/task.md +53 -0
  156. package/src/core/tools/task/bundled-commands/architect-plan.md +10 -0
  157. package/src/core/tools/task/bundled-commands/implement-with-critic.md +11 -0
  158. package/src/core/tools/task/bundled-commands/implement.md +11 -0
  159. package/src/core/tools/task/commands.ts +213 -0
  160. package/src/core/tools/task/discovery.ts +208 -0
  161. package/src/core/tools/task/executor.ts +367 -0
  162. package/src/core/tools/task/index.ts +388 -0
  163. package/src/core/tools/task/model-resolver.ts +115 -0
  164. package/src/core/tools/task/parallel.ts +38 -0
  165. package/src/core/tools/task/render.ts +232 -0
  166. package/src/core/tools/task/types.ts +99 -0
  167. package/src/core/tools/truncate.ts +265 -0
  168. package/src/core/tools/web-fetch.ts +2370 -0
  169. package/src/core/tools/web-search/auth.ts +193 -0
  170. package/src/core/tools/web-search/index.ts +537 -0
  171. package/src/core/tools/web-search/providers/anthropic.ts +198 -0
  172. package/src/core/tools/web-search/providers/exa.ts +302 -0
  173. package/src/core/tools/web-search/providers/perplexity.ts +195 -0
  174. package/src/core/tools/web-search/render.ts +182 -0
  175. package/src/core/tools/web-search/types.ts +180 -0
  176. package/src/core/tools/write.ts +99 -0
  177. package/src/index.ts +176 -0
  178. package/src/main.ts +464 -0
  179. package/src/migrations.ts +135 -0
  180. package/src/modes/index.ts +43 -0
  181. package/src/modes/interactive/components/armin.ts +382 -0
  182. package/src/modes/interactive/components/assistant-message.ts +86 -0
  183. package/src/modes/interactive/components/bash-execution.ts +196 -0
  184. package/src/modes/interactive/components/bordered-loader.ts +41 -0
  185. package/src/modes/interactive/components/branch-summary-message.ts +42 -0
  186. package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
  187. package/src/modes/interactive/components/custom-editor.ts +122 -0
  188. package/src/modes/interactive/components/diff.ts +147 -0
  189. package/src/modes/interactive/components/dynamic-border.ts +25 -0
  190. package/src/modes/interactive/components/footer.ts +381 -0
  191. package/src/modes/interactive/components/hook-editor.ts +117 -0
  192. package/src/modes/interactive/components/hook-input.ts +64 -0
  193. package/src/modes/interactive/components/hook-message.ts +96 -0
  194. package/src/modes/interactive/components/hook-selector.ts +91 -0
  195. package/src/modes/interactive/components/model-selector.ts +247 -0
  196. package/src/modes/interactive/components/oauth-selector.ts +120 -0
  197. package/src/modes/interactive/components/plugin-settings.ts +479 -0
  198. package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
  199. package/src/modes/interactive/components/session-selector.ts +204 -0
  200. package/src/modes/interactive/components/settings-selector.ts +453 -0
  201. package/src/modes/interactive/components/show-images-selector.ts +45 -0
  202. package/src/modes/interactive/components/theme-selector.ts +62 -0
  203. package/src/modes/interactive/components/thinking-selector.ts +64 -0
  204. package/src/modes/interactive/components/tool-execution.ts +675 -0
  205. package/src/modes/interactive/components/tree-selector.ts +866 -0
  206. package/src/modes/interactive/components/user-message-selector.ts +159 -0
  207. package/src/modes/interactive/components/user-message.ts +18 -0
  208. package/src/modes/interactive/components/visual-truncate.ts +50 -0
  209. package/src/modes/interactive/components/welcome.ts +183 -0
  210. package/src/modes/interactive/interactive-mode.ts +2516 -0
  211. package/src/modes/interactive/theme/dark.json +101 -0
  212. package/src/modes/interactive/theme/light.json +98 -0
  213. package/src/modes/interactive/theme/theme-schema.json +308 -0
  214. package/src/modes/interactive/theme/theme.ts +998 -0
  215. package/src/modes/print-mode.ts +128 -0
  216. package/src/modes/rpc/rpc-client.ts +527 -0
  217. package/src/modes/rpc/rpc-mode.ts +483 -0
  218. package/src/modes/rpc/rpc-types.ts +203 -0
  219. package/src/utils/changelog.ts +99 -0
  220. package/src/utils/clipboard.ts +265 -0
  221. package/src/utils/fuzzy.ts +108 -0
  222. package/src/utils/mime.ts +30 -0
  223. package/src/utils/shell.ts +276 -0
  224. package/src/utils/tools-manager.ts +274 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Question Tool - Let the LLM ask the user a question with options
3
+ */
4
+
5
+ import type { CustomTool, CustomToolFactory } from "@oh-my-pi/pi-coding-agent";
6
+
7
+ interface QuestionDetails {
8
+ question: string;
9
+ options: string[];
10
+ answer: string | null;
11
+ }
12
+
13
+ const factory: CustomToolFactory = (pi) => {
14
+ const { Type } = pi.typebox;
15
+ const { Text } = pi.pi;
16
+
17
+ const QuestionParams = Type.Object({
18
+ question: Type.String({ description: "The question to ask the user" }),
19
+ options: Type.Array(Type.String(), { description: "Options for the user to choose from" }),
20
+ });
21
+
22
+ const tool: CustomTool<typeof QuestionParams, QuestionDetails> = {
23
+ name: "question",
24
+ label: "Question",
25
+ description: "Ask the user a question and let them pick from options. Use when you need user input to proceed.",
26
+ parameters: QuestionParams,
27
+
28
+ async execute(_toolCallId, params, _onUpdate, _ctx, _signal) {
29
+ if (!pi.hasUI) {
30
+ return {
31
+ content: [{ type: "text", text: "Error: UI not available (running in non-interactive mode)" }],
32
+ details: { question: params.question, options: params.options, answer: null },
33
+ };
34
+ }
35
+
36
+ if (params.options.length === 0) {
37
+ return {
38
+ content: [{ type: "text", text: "Error: No options provided" }],
39
+ details: { question: params.question, options: [], answer: null },
40
+ };
41
+ }
42
+
43
+ const answer = await pi.ui.select(params.question, params.options);
44
+
45
+ if (answer === undefined) {
46
+ return {
47
+ content: [{ type: "text", text: "User cancelled the selection" }],
48
+ details: { question: params.question, options: params.options, answer: null },
49
+ };
50
+ }
51
+
52
+ return {
53
+ content: [{ type: "text", text: `User selected: ${answer}` }],
54
+ details: { question: params.question, options: params.options, answer },
55
+ };
56
+ },
57
+
58
+ renderCall(args, theme) {
59
+ let text = theme.fg("toolTitle", theme.bold("question ")) + theme.fg("muted", args.question);
60
+ if (args.options?.length) {
61
+ text += `\n${theme.fg("dim", ` Options: ${args.options.join(", ")}`)}`;
62
+ }
63
+ return new Text(text, 0, 0);
64
+ },
65
+
66
+ renderResult(result, _options, theme) {
67
+ const { details } = result;
68
+ if (!details) {
69
+ const text = result.content[0];
70
+ return new Text(text?.type === "text" ? text.text : "", 0, 0);
71
+ }
72
+
73
+ if (details.answer === null) {
74
+ return new Text(theme.fg("warning", "Cancelled"), 0, 0);
75
+ }
76
+
77
+ return new Text(theme.fg("success", "✓ ") + theme.fg("accent", details.answer), 0, 0);
78
+ },
79
+ };
80
+
81
+ return tool;
82
+ };
83
+
84
+ export default factory;
@@ -0,0 +1,172 @@
1
+ # Subagent Example
2
+
3
+ Delegate tasks to specialized subagents with isolated context windows.
4
+
5
+ ## Features
6
+
7
+ - **Isolated context**: Each subagent runs in a separate `pi` process
8
+ - **Streaming output**: See tool calls and progress as they happen
9
+ - **Parallel streaming**: All parallel tasks stream updates simultaneously
10
+ - **Markdown rendering**: Final output rendered with proper formatting (expanded view)
11
+ - **Usage tracking**: Shows turns, tokens, cost, and context usage per agent
12
+ - **Abort support**: Ctrl+C propagates to kill subagent processes
13
+
14
+ ## Structure
15
+
16
+ ```
17
+ subagent/
18
+ ├── README.md # This file
19
+ ├── subagent.ts # The custom tool (entry point)
20
+ ├── agents.ts # Agent discovery logic
21
+ ├── agents/ # Sample agent definitions
22
+ │ ├── scout.md # Fast recon, returns compressed context
23
+ │ ├── planner.md # Creates implementation plans
24
+ │ ├── reviewer.md # Code review
25
+ │ └── worker.md # General-purpose (full capabilities)
26
+ └── commands/ # Workflow presets
27
+ ├── implement.md # scout -> planner -> worker
28
+ ├── scout-and-plan.md # scout -> planner (no implementation)
29
+ └── implement-and-review.md # worker -> reviewer -> worker
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ From the repository root, symlink the files:
35
+
36
+ ```bash
37
+ # Symlink the tool (must be in a subdirectory with index.ts)
38
+ mkdir -p ~/.pi/agent/tools/subagent
39
+ ln -sf "$(pwd)/packages/coding-agent/examples/custom-tools/subagent/subagent.ts" ~/.pi/agent/tools/subagent/index.ts
40
+ ln -sf "$(pwd)/packages/coding-agent/examples/custom-tools/subagent/agents.ts" ~/.pi/agent/tools/subagent/agents.ts
41
+
42
+ # Symlink agents
43
+ mkdir -p ~/.pi/agent/agents
44
+ for f in packages/coding-agent/examples/custom-tools/subagent/agents/*.md; do
45
+ ln -sf "$(pwd)/$f" ~/.pi/agent/agents/$(basename "$f")
46
+ done
47
+
48
+ # Symlink workflow commands
49
+ mkdir -p ~/.pi/agent/commands
50
+ for f in packages/coding-agent/examples/custom-tools/subagent/commands/*.md; do
51
+ ln -sf "$(pwd)/$f" ~/.pi/agent/commands/$(basename "$f")
52
+ done
53
+ ```
54
+
55
+ ## Security Model
56
+
57
+ This tool executes a separate `pi` subprocess with a delegated system prompt and tool/model configuration.
58
+
59
+ **Project-local agents** (`.pi/agents/*.md`) are repo-controlled prompts that can instruct the model to read files, run bash commands, etc.
60
+
61
+ **Default behavior:** Only loads **user-level agents** from `~/.pi/agent/agents`.
62
+
63
+ To enable project-local agents, pass `agentScope: "both"` (or `"project"`). Only do this for repositories you trust.
64
+
65
+ When running interactively, the tool prompts for confirmation before running project-local agents. Set `confirmProjectAgents: false` to disable.
66
+
67
+ ## Usage
68
+
69
+ ### Single agent
70
+ ```
71
+ Use scout to find all authentication code
72
+ ```
73
+
74
+ ### Parallel execution
75
+ ```
76
+ Run 2 scouts in parallel: one to find models, one to find providers
77
+ ```
78
+
79
+ ### Chained workflow
80
+ ```
81
+ Use a chain: first have scout find the read tool, then have planner suggest improvements
82
+ ```
83
+
84
+ ### Workflow commands
85
+ ```
86
+ /implement add Redis caching to the session store
87
+ /scout-and-plan refactor auth to support OAuth
88
+ /implement-and-review add input validation to API endpoints
89
+ ```
90
+
91
+ ## Tool Modes
92
+
93
+ | Mode | Parameter | Description |
94
+ |------|-----------|-------------|
95
+ | Single | `{ agent, task }` | One agent, one task |
96
+ | Parallel | `{ tasks: [...] }` | Multiple agents run concurrently (max 8, 4 concurrent) |
97
+ | Chain | `{ chain: [...] }` | Sequential with `{previous}` placeholder |
98
+
99
+ ## Output Display
100
+
101
+ **Collapsed view** (default):
102
+ - Status icon (✓/✗/⏳) and agent name
103
+ - Last 5-10 items (tool calls and text)
104
+ - Usage stats: `3 turns ↑input ↓output RcacheRead WcacheWrite $cost ctx:contextTokens model`
105
+
106
+ **Expanded view** (Ctrl+O):
107
+ - Full task text
108
+ - All tool calls with formatted arguments
109
+ - Final output rendered as Markdown
110
+ - Per-task usage (for chain/parallel)
111
+
112
+ **Parallel mode streaming**:
113
+ - Shows all tasks with live status (⏳ running, ✓ done, ✗ failed)
114
+ - Updates as each task makes progress
115
+ - Shows "2/3 done, 1 running" status
116
+
117
+ **Tool call formatting** (mimics built-in tools):
118
+ - `$ command` for bash
119
+ - `read ~/path:1-10` for read
120
+ - `grep /pattern/ in ~/path` for grep
121
+ - etc.
122
+
123
+ ## Agent Definitions
124
+
125
+ Agents are markdown files with YAML frontmatter:
126
+
127
+ ```markdown
128
+ ---
129
+ name: my-agent
130
+ description: What this agent does
131
+ tools: read, grep, find, ls
132
+ model: claude-haiku-4-5
133
+ ---
134
+
135
+ System prompt for the agent goes here.
136
+ ```
137
+
138
+ **Locations:**
139
+ - `~/.pi/agent/agents/*.md` - User-level (always loaded)
140
+ - `.pi/agents/*.md` - Project-level (only with `agentScope: "project"` or `"both"`)
141
+
142
+ Project agents override user agents with the same name when `agentScope: "both"`.
143
+
144
+ ## Sample Agents
145
+
146
+ | Agent | Purpose | Model | Tools |
147
+ |-------|---------|-------|-------|
148
+ | `scout` | Fast codebase recon | Haiku | read, grep, find, ls, bash |
149
+ | `planner` | Implementation plans | Sonnet | read, grep, find, ls |
150
+ | `reviewer` | Code review | Sonnet | read, grep, find, ls, bash |
151
+ | `worker` | General-purpose | Sonnet | (all default) |
152
+
153
+ ## Workflow Commands
154
+
155
+ | Command | Flow |
156
+ |---------|------|
157
+ | `/implement <query>` | scout → planner → worker |
158
+ | `/scout-and-plan <query>` | scout → planner |
159
+ | `/implement-and-review <query>` | worker → reviewer → worker |
160
+
161
+ ## Error Handling
162
+
163
+ - **Exit code != 0**: Tool returns error with stderr/output
164
+ - **stopReason "error"**: LLM error propagated with error message
165
+ - **stopReason "aborted"**: User abort (Ctrl+C) kills subprocess, throws error
166
+ - **Chain mode**: Stops at first failing step, reports which step failed
167
+
168
+ ## Limitations
169
+
170
+ - Output truncated to last 10 items in collapsed view (expand to see all)
171
+ - Agents discovered fresh on each invocation (allows editing mid-session)
172
+ - Parallel mode limited to 8 tasks, 4 concurrent
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: planner
3
+ description: Creates implementation plans from context and requirements
4
+ tools: read, grep, find, ls
5
+ model: claude-sonnet-4-5
6
+ ---
7
+
8
+ You are a planning specialist. You receive context (from a scout) and requirements, then produce a clear implementation plan.
9
+
10
+ You must NOT make any changes. Only read, analyze, and plan.
11
+
12
+ Input format you'll receive:
13
+ - Context/findings from a scout agent
14
+ - Original query or requirements
15
+
16
+ Output format:
17
+
18
+ ## Goal
19
+ One sentence summary of what needs to be done.
20
+
21
+ ## Plan
22
+ Numbered steps, each small and actionable:
23
+ 1. Step one - specific file/function to modify
24
+ 2. Step two - what to add/change
25
+ 3. ...
26
+
27
+ ## Files to Modify
28
+ - `path/to/file.ts` - what changes
29
+ - `path/to/other.ts` - what changes
30
+
31
+ ## New Files (if any)
32
+ - `path/to/new.ts` - purpose
33
+
34
+ ## Risks
35
+ Anything to watch out for.
36
+
37
+ Keep the plan concrete. The worker agent will execute it verbatim.
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: reviewer
3
+ description: Code review specialist for quality and security analysis
4
+ tools: read, grep, find, ls, bash
5
+ model: claude-sonnet-4-5
6
+ ---
7
+
8
+ You are a senior code reviewer. Analyze code for quality, security, and maintainability.
9
+
10
+ Bash is for read-only commands only: `git diff`, `git log`, `git show`. Do NOT modify files or run builds.
11
+ Assume tool permissions are not perfectly enforceable; keep all bash usage strictly read-only.
12
+
13
+ Strategy:
14
+ 1. Run `git diff` to see recent changes (if applicable)
15
+ 2. Read the modified files
16
+ 3. Check for bugs, security issues, code smells
17
+
18
+ Output format:
19
+
20
+ ## Files Reviewed
21
+ - `path/to/file.ts` (lines X-Y)
22
+
23
+ ## Critical (must fix)
24
+ - `file.ts:42` - Issue description
25
+
26
+ ## Warnings (should fix)
27
+ - `file.ts:100` - Issue description
28
+
29
+ ## Suggestions (consider)
30
+ - `file.ts:150` - Improvement idea
31
+
32
+ ## Summary
33
+ Overall assessment in 2-3 sentences.
34
+
35
+ Be specific with file paths and line numbers.
@@ -0,0 +1,50 @@
1
+ ---
2
+ name: scout
3
+ description: Fast codebase recon that returns compressed context for handoff to other agents
4
+ tools: read, grep, find, ls, bash
5
+ model: claude-haiku-4-5
6
+ ---
7
+
8
+ You are a scout. Quickly investigate a codebase and return structured findings that another agent can use without re-reading everything.
9
+
10
+ Your output will be passed to an agent who has NOT seen the files you explored.
11
+
12
+ Thoroughness (infer from task, default medium):
13
+ - Quick: Targeted lookups, key files only
14
+ - Medium: Follow imports, read critical sections
15
+ - Thorough: Trace all dependencies, check tests/types
16
+
17
+ Strategy:
18
+ 1. grep/find to locate relevant code
19
+ 2. Read key sections (not entire files)
20
+ 3. Identify types, interfaces, key functions
21
+ 4. Note dependencies between files
22
+
23
+ Output format:
24
+
25
+ ## Files Retrieved
26
+ List with exact line ranges:
27
+ 1. `path/to/file.ts` (lines 10-50) - Description of what's here
28
+ 2. `path/to/other.ts` (lines 100-150) - Description
29
+ 3. ...
30
+
31
+ ## Key Code
32
+ Critical types, interfaces, or functions:
33
+
34
+ ```typescript
35
+ interface Example {
36
+ // actual code from the files
37
+ }
38
+ ```
39
+
40
+ ```typescript
41
+ function keyFunction() {
42
+ // actual implementation
43
+ }
44
+ ```
45
+
46
+ ## Architecture
47
+ Brief explanation of how the pieces connect.
48
+
49
+ ## Start Here
50
+ Which file to look at first and why.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: worker
3
+ description: General-purpose subagent with full capabilities, isolated context
4
+ model: claude-sonnet-4-5
5
+ ---
6
+
7
+ You are a worker agent with full capabilities. You operate in an isolated context window to handle delegated tasks without polluting the main conversation.
8
+
9
+ Work autonomously to complete the assigned task. Use all available tools as needed.
10
+
11
+ Output format when finished:
12
+
13
+ ## Completed
14
+ What was done.
15
+
16
+ ## Files Changed
17
+ - `path/to/file.ts` - what changed
18
+
19
+ ## Notes (if any)
20
+ Anything the main agent should know.
21
+
22
+ If handing off to another agent (e.g. reviewer), include:
23
+ - Exact file paths changed
24
+ - Key functions/types touched (short list)
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Agent discovery and configuration
3
+ */
4
+
5
+ import * as fs from "node:fs";
6
+ import * as os from "node:os";
7
+ import * as path from "node:path";
8
+
9
+ export type AgentScope = "user" | "project" | "both";
10
+
11
+ export interface AgentConfig {
12
+ name: string;
13
+ description: string;
14
+ tools?: string[];
15
+ model?: string;
16
+ systemPrompt: string;
17
+ source: "user" | "project";
18
+ filePath: string;
19
+ }
20
+
21
+ export interface AgentDiscoveryResult {
22
+ agents: AgentConfig[];
23
+ projectAgentsDir: string | null;
24
+ }
25
+
26
+ function parseFrontmatter(content: string): { frontmatter: Record<string, string>; body: string } {
27
+ const frontmatter: Record<string, string> = {};
28
+ const normalized = content.replace(/\r\n/g, "\n");
29
+
30
+ if (!normalized.startsWith("---")) {
31
+ return { frontmatter, body: normalized };
32
+ }
33
+
34
+ const endIndex = normalized.indexOf("\n---", 3);
35
+ if (endIndex === -1) {
36
+ return { frontmatter, body: normalized };
37
+ }
38
+
39
+ const frontmatterBlock = normalized.slice(4, endIndex);
40
+ const body = normalized.slice(endIndex + 4).trim();
41
+
42
+ for (const line of frontmatterBlock.split("\n")) {
43
+ const match = line.match(/^([\w-]+):\s*(.*)$/);
44
+ if (match) {
45
+ let value = match[2].trim();
46
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
47
+ value = value.slice(1, -1);
48
+ }
49
+ frontmatter[match[1]] = value;
50
+ }
51
+ }
52
+
53
+ return { frontmatter, body };
54
+ }
55
+
56
+ function loadAgentsFromDir(dir: string, source: "user" | "project"): AgentConfig[] {
57
+ const agents: AgentConfig[] = [];
58
+
59
+ if (!fs.existsSync(dir)) {
60
+ return agents;
61
+ }
62
+
63
+ let entries: fs.Dirent[];
64
+ try {
65
+ entries = fs.readdirSync(dir, { withFileTypes: true });
66
+ } catch {
67
+ return agents;
68
+ }
69
+
70
+ for (const entry of entries) {
71
+ if (!entry.name.endsWith(".md")) continue;
72
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
73
+
74
+ const filePath = path.join(dir, entry.name);
75
+ let content: string;
76
+ try {
77
+ content = fs.readFileSync(filePath, "utf-8");
78
+ } catch {
79
+ continue;
80
+ }
81
+
82
+ const { frontmatter, body } = parseFrontmatter(content);
83
+
84
+ if (!frontmatter.name || !frontmatter.description) {
85
+ continue;
86
+ }
87
+
88
+ const tools = frontmatter.tools
89
+ ?.split(",")
90
+ .map((t) => t.trim())
91
+ .filter(Boolean);
92
+
93
+ agents.push({
94
+ name: frontmatter.name,
95
+ description: frontmatter.description,
96
+ tools: tools && tools.length > 0 ? tools : undefined,
97
+ model: frontmatter.model,
98
+ systemPrompt: body,
99
+ source,
100
+ filePath,
101
+ });
102
+ }
103
+
104
+ return agents;
105
+ }
106
+
107
+ function isDirectory(p: string): boolean {
108
+ try {
109
+ return fs.statSync(p).isDirectory();
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ function findNearestProjectAgentsDir(cwd: string): string | null {
116
+ let currentDir = cwd;
117
+ while (true) {
118
+ const candidate = path.join(currentDir, ".pi", "agents");
119
+ if (isDirectory(candidate)) return candidate;
120
+
121
+ const parentDir = path.dirname(currentDir);
122
+ if (parentDir === currentDir) return null;
123
+ currentDir = parentDir;
124
+ }
125
+ }
126
+
127
+ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryResult {
128
+ const userDir = path.join(os.homedir(), ".pi", "agent", "agents");
129
+ const projectAgentsDir = findNearestProjectAgentsDir(cwd);
130
+
131
+ const userAgents = scope === "project" ? [] : loadAgentsFromDir(userDir, "user");
132
+ const projectAgents = scope === "user" || !projectAgentsDir ? [] : loadAgentsFromDir(projectAgentsDir, "project");
133
+
134
+ const agentMap = new Map<string, AgentConfig>();
135
+
136
+ if (scope === "both") {
137
+ for (const agent of userAgents) agentMap.set(agent.name, agent);
138
+ for (const agent of projectAgents) agentMap.set(agent.name, agent);
139
+ } else if (scope === "user") {
140
+ for (const agent of userAgents) agentMap.set(agent.name, agent);
141
+ } else {
142
+ for (const agent of projectAgents) agentMap.set(agent.name, agent);
143
+ }
144
+
145
+ return { agents: Array.from(agentMap.values()), projectAgentsDir };
146
+ }
147
+
148
+ export function formatAgentList(agents: AgentConfig[], maxItems: number): { text: string; remaining: number } {
149
+ if (agents.length === 0) return { text: "none", remaining: 0 };
150
+ const listed = agents.slice(0, maxItems);
151
+ const remaining = agents.length - listed.length;
152
+ return {
153
+ text: listed.map((a) => `${a.name} (${a.source}): ${a.description}`).join("; "),
154
+ remaining,
155
+ };
156
+ }
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Worker implements, reviewer reviews, worker applies feedback
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "worker" agent to implement: $@
7
+ 2. Then, use the "reviewer" agent to review the implementation from the previous step (use {previous} placeholder)
8
+ 3. Finally, use the "worker" agent to apply the feedback from the review (use {previous} placeholder)
9
+
10
+ Execute this as a chain, passing output between steps via {previous}.
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Full implementation workflow - scout gathers context, planner creates plan, worker implements
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "scout" agent to find all code relevant to: $@
7
+ 2. Then, use the "planner" agent to create an implementation plan for "$@" using the context from the previous step (use {previous} placeholder)
8
+ 3. Finally, use the "worker" agent to implement the plan from the previous step (use {previous} placeholder)
9
+
10
+ Execute this as a chain, passing output between steps via {previous}.
@@ -0,0 +1,9 @@
1
+ ---
2
+ description: Scout gathers context, planner creates implementation plan (no implementation)
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "scout" agent to find all code relevant to: $@
7
+ 2. Then, use the "planner" agent to create an implementation plan for "$@" using the context from the previous step (use {previous} placeholder)
8
+
9
+ Execute this as a chain, passing output between steps via {previous}. Do NOT implement - just return the plan.