@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.
- package/CHANGELOG.md +1228 -0
- package/README.md +1041 -0
- package/docs/compaction.md +403 -0
- package/docs/custom-tools.md +541 -0
- package/docs/extension-loading.md +1004 -0
- package/docs/hooks.md +867 -0
- package/docs/rpc.md +1040 -0
- package/docs/sdk.md +994 -0
- package/docs/session-tree-plan.md +441 -0
- package/docs/session.md +240 -0
- package/docs/skills.md +290 -0
- package/docs/theme.md +637 -0
- package/docs/tree.md +197 -0
- package/docs/tui.md +341 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +124 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/question/index.ts +84 -0
- package/examples/custom-tools/subagent/README.md +172 -0
- package/examples/custom-tools/subagent/agents/planner.md +37 -0
- package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
- package/examples/custom-tools/subagent/agents/scout.md +50 -0
- package/examples/custom-tools/subagent/agents/worker.md +24 -0
- package/examples/custom-tools/subagent/agents.ts +156 -0
- package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
- package/examples/custom-tools/subagent/commands/implement.md +10 -0
- package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
- package/examples/custom-tools/subagent/index.ts +1002 -0
- package/examples/custom-tools/todo/index.ts +212 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +49 -0
- package/examples/hooks/confirm-destructive.ts +59 -0
- package/examples/hooks/custom-compaction.ts +116 -0
- package/examples/hooks/dirty-repo-guard.ts +52 -0
- package/examples/hooks/file-trigger.ts +41 -0
- package/examples/hooks/git-checkpoint.ts +53 -0
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +34 -0
- package/examples/hooks/protected-paths.ts +30 -0
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/snake.ts +343 -0
- package/examples/hooks/status-line.ts +40 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +44 -0
- package/examples/sdk/04-skills.ts +44 -0
- package/examples/sdk/05-tools.ts +90 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +36 -0
- package/examples/sdk/08-slash-commands.ts +42 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +95 -0
- package/examples/sdk/README.md +154 -0
- package/package.json +81 -0
- package/src/cli/args.ts +246 -0
- package/src/cli/file-processor.ts +72 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/plugin-cli.ts +650 -0
- package/src/cli/session-picker.ts +41 -0
- package/src/cli.ts +10 -0
- package/src/commands/init.md +20 -0
- package/src/config.ts +159 -0
- package/src/core/agent-session.ts +1900 -0
- package/src/core/auth-storage.ts +236 -0
- package/src/core/bash-executor.ts +196 -0
- package/src/core/compaction/branch-summarization.ts +343 -0
- package/src/core/compaction/compaction.ts +742 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +154 -0
- package/src/core/custom-tools/index.ts +21 -0
- package/src/core/custom-tools/loader.ts +248 -0
- package/src/core/custom-tools/types.ts +169 -0
- package/src/core/custom-tools/wrapper.ts +28 -0
- package/src/core/exec.ts +129 -0
- package/src/core/export-html/index.ts +211 -0
- package/src/core/export-html/template.css +781 -0
- package/src/core/export-html/template.html +54 -0
- package/src/core/export-html/template.js +1185 -0
- package/src/core/export-html/vendor/highlight.min.js +1213 -0
- package/src/core/export-html/vendor/marked.min.js +6 -0
- package/src/core/hooks/index.ts +16 -0
- package/src/core/hooks/loader.ts +312 -0
- package/src/core/hooks/runner.ts +434 -0
- package/src/core/hooks/tool-wrapper.ts +99 -0
- package/src/core/hooks/types.ts +773 -0
- package/src/core/index.ts +52 -0
- package/src/core/mcp/client.ts +158 -0
- package/src/core/mcp/config.ts +154 -0
- package/src/core/mcp/index.ts +45 -0
- package/src/core/mcp/loader.ts +68 -0
- package/src/core/mcp/manager.ts +181 -0
- package/src/core/mcp/tool-bridge.ts +148 -0
- package/src/core/mcp/transports/http.ts +316 -0
- package/src/core/mcp/transports/index.ts +6 -0
- package/src/core/mcp/transports/stdio.ts +252 -0
- package/src/core/mcp/types.ts +220 -0
- package/src/core/messages.ts +189 -0
- package/src/core/model-registry.ts +317 -0
- package/src/core/model-resolver.ts +393 -0
- package/src/core/plugins/doctor.ts +59 -0
- package/src/core/plugins/index.ts +38 -0
- package/src/core/plugins/installer.ts +189 -0
- package/src/core/plugins/loader.ts +338 -0
- package/src/core/plugins/manager.ts +672 -0
- package/src/core/plugins/parser.ts +105 -0
- package/src/core/plugins/paths.ts +32 -0
- package/src/core/plugins/types.ts +190 -0
- package/src/core/sdk.ts +760 -0
- package/src/core/session-manager.ts +1128 -0
- package/src/core/settings-manager.ts +443 -0
- package/src/core/skills.ts +437 -0
- package/src/core/slash-commands.ts +248 -0
- package/src/core/system-prompt.ts +439 -0
- package/src/core/timings.ts +25 -0
- package/src/core/tools/ask.ts +211 -0
- package/src/core/tools/bash-interceptor.ts +120 -0
- package/src/core/tools/bash.ts +250 -0
- package/src/core/tools/context.ts +32 -0
- package/src/core/tools/edit-diff.ts +475 -0
- package/src/core/tools/edit.ts +208 -0
- package/src/core/tools/exa/company.ts +59 -0
- package/src/core/tools/exa/index.ts +64 -0
- package/src/core/tools/exa/linkedin.ts +59 -0
- package/src/core/tools/exa/logger.ts +56 -0
- package/src/core/tools/exa/mcp-client.ts +368 -0
- package/src/core/tools/exa/render.ts +196 -0
- package/src/core/tools/exa/researcher.ts +90 -0
- package/src/core/tools/exa/search.ts +337 -0
- package/src/core/tools/exa/types.ts +168 -0
- package/src/core/tools/exa/websets.ts +248 -0
- package/src/core/tools/find.ts +261 -0
- package/src/core/tools/grep.ts +555 -0
- package/src/core/tools/index.ts +202 -0
- package/src/core/tools/ls.ts +140 -0
- package/src/core/tools/lsp/client.ts +605 -0
- package/src/core/tools/lsp/config.ts +147 -0
- package/src/core/tools/lsp/edits.ts +101 -0
- package/src/core/tools/lsp/index.ts +804 -0
- package/src/core/tools/lsp/render.ts +447 -0
- package/src/core/tools/lsp/rust-analyzer.ts +145 -0
- package/src/core/tools/lsp/types.ts +463 -0
- package/src/core/tools/lsp/utils.ts +486 -0
- package/src/core/tools/notebook.ts +229 -0
- package/src/core/tools/path-utils.ts +61 -0
- package/src/core/tools/read.ts +240 -0
- package/src/core/tools/renderers.ts +540 -0
- package/src/core/tools/task/agents.ts +153 -0
- package/src/core/tools/task/artifacts.ts +114 -0
- package/src/core/tools/task/bundled-agents/browser.md +71 -0
- package/src/core/tools/task/bundled-agents/explore.md +82 -0
- package/src/core/tools/task/bundled-agents/plan.md +54 -0
- package/src/core/tools/task/bundled-agents/reviewer.md +59 -0
- package/src/core/tools/task/bundled-agents/task.md +53 -0
- package/src/core/tools/task/bundled-commands/architect-plan.md +10 -0
- package/src/core/tools/task/bundled-commands/implement-with-critic.md +11 -0
- package/src/core/tools/task/bundled-commands/implement.md +11 -0
- package/src/core/tools/task/commands.ts +213 -0
- package/src/core/tools/task/discovery.ts +208 -0
- package/src/core/tools/task/executor.ts +367 -0
- package/src/core/tools/task/index.ts +388 -0
- package/src/core/tools/task/model-resolver.ts +115 -0
- package/src/core/tools/task/parallel.ts +38 -0
- package/src/core/tools/task/render.ts +232 -0
- package/src/core/tools/task/types.ts +99 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/web-fetch.ts +2370 -0
- package/src/core/tools/web-search/auth.ts +193 -0
- package/src/core/tools/web-search/index.ts +537 -0
- package/src/core/tools/web-search/providers/anthropic.ts +198 -0
- package/src/core/tools/web-search/providers/exa.ts +302 -0
- package/src/core/tools/web-search/providers/perplexity.ts +195 -0
- package/src/core/tools/web-search/render.ts +182 -0
- package/src/core/tools/web-search/types.ts +180 -0
- package/src/core/tools/write.ts +99 -0
- package/src/index.ts +176 -0
- package/src/main.ts +464 -0
- package/src/migrations.ts +135 -0
- package/src/modes/index.ts +43 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +86 -0
- package/src/modes/interactive/components/bash-execution.ts +196 -0
- package/src/modes/interactive/components/bordered-loader.ts +41 -0
- package/src/modes/interactive/components/branch-summary-message.ts +42 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
- package/src/modes/interactive/components/custom-editor.ts +122 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/footer.ts +381 -0
- package/src/modes/interactive/components/hook-editor.ts +117 -0
- package/src/modes/interactive/components/hook-input.ts +64 -0
- package/src/modes/interactive/components/hook-message.ts +96 -0
- package/src/modes/interactive/components/hook-selector.ts +91 -0
- package/src/modes/interactive/components/model-selector.ts +247 -0
- package/src/modes/interactive/components/oauth-selector.ts +120 -0
- package/src/modes/interactive/components/plugin-settings.ts +479 -0
- package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
- package/src/modes/interactive/components/session-selector.ts +204 -0
- package/src/modes/interactive/components/settings-selector.ts +453 -0
- package/src/modes/interactive/components/show-images-selector.ts +45 -0
- package/src/modes/interactive/components/theme-selector.ts +62 -0
- package/src/modes/interactive/components/thinking-selector.ts +64 -0
- package/src/modes/interactive/components/tool-execution.ts +675 -0
- package/src/modes/interactive/components/tree-selector.ts +866 -0
- package/src/modes/interactive/components/user-message-selector.ts +159 -0
- package/src/modes/interactive/components/user-message.ts +18 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/components/welcome.ts +183 -0
- package/src/modes/interactive/interactive-mode.ts +2516 -0
- package/src/modes/interactive/theme/dark.json +101 -0
- package/src/modes/interactive/theme/light.json +98 -0
- package/src/modes/interactive/theme/theme-schema.json +308 -0
- package/src/modes/interactive/theme/theme.ts +998 -0
- package/src/modes/print-mode.ts +128 -0
- package/src/modes/rpc/rpc-client.ts +527 -0
- package/src/modes/rpc/rpc-mode.ts +483 -0
- package/src/modes/rpc/rpc-types.ts +203 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/clipboard.ts +265 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/shell.ts +276 -0
- 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.
|