@bacnh85/pi-subagent 0.3.1 → 0.5.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/README.md +28 -64
- package/agent-format.md +8 -3
- package/agents/reviewer.md +28 -22
- package/agents/scout.md +3 -3
- package/agents/worker.md +2 -2
- package/{agents.ts → extensions/agents.ts} +18 -9
- package/{index.ts → extensions/index.ts} +411 -117
- package/extensions/model.ts +86 -0
- package/extensions/package.json +3 -0
- package/{render.ts → extensions/render.ts} +33 -15
- package/{runner.ts → extensions/runner.ts} +54 -10
- package/extensions/service.ts +79 -0
- package/extensions/thread-viewer.ts +393 -0
- package/extensions/threads.ts +116 -0
- package/package.json +36 -29
package/README.md
CHANGED
|
@@ -1,88 +1,52 @@
|
|
|
1
1
|
# pi-subagent
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **In-process execution**: Uses `createAgentSession()` directly — no `spawn("pi")` overhead
|
|
8
|
-
- **Minimal token budget**: Only the agent's system prompt (no AGENTS.md, no extensions, no thinking)
|
|
9
|
-
- **Streaming progress**: Real-time tool-call and text updates during execution
|
|
10
|
-
- **Three modes**: single, parallel (max 8 tasks, 4 concurrent), chain (sequential with `{previous}`)
|
|
11
|
-
- **Abort support**: Esc propagates to all sub-agents
|
|
12
|
-
- **TUI rendering**: Collapsed/expanded views with tool-call formatting and usage stats
|
|
13
|
-
- **Bundled agents**: scout, reviewer, worker — overridable with your own
|
|
3
|
+
Isolated in-process subagents for Pi. The `subagent` tool supports single, parallel (8 tasks, 4 concurrent), and chained execution; `/agent` opens inspectable child threads.
|
|
14
4
|
|
|
15
5
|
## Install
|
|
16
6
|
|
|
17
7
|
```bash
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
pi install ./extensions/pi-subagent
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Or test directly:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
pi -e ./extensions/pi-subagent
|
|
8
|
+
pi install npm:@bacnh85/pi-subagent
|
|
9
|
+
# local checkout
|
|
10
|
+
pi install ./pi-subagent
|
|
28
11
|
```
|
|
29
12
|
|
|
30
|
-
##
|
|
13
|
+
## Bundled roles
|
|
31
14
|
|
|
32
|
-
|
|
15
|
+
| Role | Model | Thinking | Tools |
|
|
16
|
+
| --- | --- | --- | --- |
|
|
17
|
+
| `scout` | parent model | low | read, grep, find, ls |
|
|
18
|
+
| `reviewer` | parent model | high | read, grep, find, ls |
|
|
19
|
+
| `worker` | parent model | medium | standard coding tools |
|
|
20
|
+
| `general-purpose` | parent model | off | standard coding tools |
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
Use scout to find authentication code in this project
|
|
36
|
-
```
|
|
22
|
+
Bundled roles inherit the parent model so they work with the account already active in Pi. User/project agent files may override `model` and `thinking`.
|
|
37
23
|
|
|
38
|
-
|
|
24
|
+
## Agent files
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
Run 2 scouts in parallel: one for models, one for providers
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Chain workflow
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
Chain: scout finds auth code, then reviewer checks it for security issues
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Included Agents
|
|
51
|
-
|
|
52
|
-
| Agent | Model | Tools | Purpose |
|
|
53
|
-
|-------|-------|-------|---------|
|
|
54
|
-
| `scout` | Haiku | read, grep, find, ls | Fast codebase recon |
|
|
55
|
-
| `reviewer` | Sonnet | read, grep, find, ls, bash | Code review |
|
|
56
|
-
| `worker` | Sonnet | all | General implementation |
|
|
57
|
-
|
|
58
|
-
## Custom Agents
|
|
59
|
-
|
|
60
|
-
Create Markdown files with YAML frontmatter in `~/.pi/agent/agents/` (user-level) or `.pi/agents/` (project-level):
|
|
26
|
+
Create `~/.pi/agent/agents/*.md` or `.pi/agents/*.md`:
|
|
61
27
|
|
|
62
28
|
```markdown
|
|
63
29
|
---
|
|
64
|
-
name:
|
|
65
|
-
description:
|
|
66
|
-
tools: read, grep, find, ls
|
|
67
|
-
|
|
30
|
+
name: scout-fast
|
|
31
|
+
description: Locate relevant files and symbols
|
|
32
|
+
tools: read, grep, find, ls
|
|
33
|
+
thinking: low
|
|
34
|
+
model: optional-provider/optional-model
|
|
68
35
|
---
|
|
69
36
|
|
|
70
|
-
|
|
37
|
+
Return concise evidence with file/symbol anchors.
|
|
71
38
|
```
|
|
72
39
|
|
|
73
|
-
|
|
40
|
+
Project agents require confirmation when requested through the public tool. Definitions are cached with file-signature invalidation; `/subagent reload` clears the cache.
|
|
41
|
+
|
|
42
|
+
## Context and limits
|
|
74
43
|
|
|
75
|
-
|
|
44
|
+
Children use in-memory SDK sessions with no extensions, skills, prompt templates, or automatic `AGENTS.md` loading. The optional `instructions` argument passes a bounded 16 KB task/repository contract. Only Pi built-in tools are available; Serena, FFF, web, and Munin are not available in lean children.
|
|
76
45
|
|
|
77
|
-
|
|
46
|
+
Threads are session-memory only and are cleared when Pi replaces or reloads the session. Timeout and parent cancellation propagate to child sessions. Subagents cannot recursively invoke `subagent`.
|
|
78
47
|
|
|
79
|
-
|
|
80
|
-
- Skipping AGENTS.md, extensions, skills, prompt templates
|
|
81
|
-
- Disabling thinking, compaction, retry
|
|
82
|
-
- Using in-memory sessions (no disk I/O)
|
|
83
|
-
- Sharing the parent's auth/model infrastructure
|
|
48
|
+
## Extension contract
|
|
84
49
|
|
|
85
|
-
|
|
50
|
+
`pi-subagent` owns the `pi-subagent:run` event contract for one named-agent request. `pi-review` uses it for isolated review. Requests use an immediate boolean `accept()` claim and exactly one `respond()` callback; this suppresses duplicate responders while missing services and timeouts remain caller-controlled.
|
|
86
51
|
|
|
87
|
-
|
|
88
|
-
- Peer dependencies satisfied by the pi runtime (no extra npm install needed)
|
|
52
|
+
See [`agent-format.md`](./agent-format.md) for all frontmatter fields.
|
package/agent-format.md
CHANGED
|
@@ -8,7 +8,7 @@ Sub-agents are defined as Markdown files with YAML frontmatter.
|
|
|
8
8
|
|----------|-------|
|
|
9
9
|
| `~/.pi/agent/agents/*.md` | User-level (all projects) |
|
|
10
10
|
| `.pi/agents/*.md` | Project-level |
|
|
11
|
-
| `<
|
|
11
|
+
| `<package>/agents/*.md` | Bundled with pi-subagent |
|
|
12
12
|
|
|
13
13
|
Project agents override user agents with the same name when `agentScope: "both"`.
|
|
14
14
|
|
|
@@ -19,7 +19,8 @@ Project agents override user agents with the same name when `agentScope: "both"`
|
|
|
19
19
|
name: my-agent # Required. Unique identifier (kebab-case).
|
|
20
20
|
description: ... # Required. When to use this agent.
|
|
21
21
|
tools: read, grep, ... # Optional. Comma-separated tool names. Defaults to all.
|
|
22
|
-
model:
|
|
22
|
+
model: provider/model # Optional. Defaults to parent's model.
|
|
23
|
+
thinking: low # Optional: off|minimal|low|medium|high|xhigh|max.
|
|
23
24
|
---
|
|
24
25
|
```
|
|
25
26
|
|
|
@@ -47,13 +48,17 @@ Model IDs are resolved via `getModel("provider", "id")`. Common values:
|
|
|
47
48
|
|
|
48
49
|
If not specified, defaults to the parent session's model.
|
|
49
50
|
|
|
51
|
+
## Instruction handoff
|
|
52
|
+
|
|
53
|
+
Children do not automatically load repository instructions. Callers may pass an `instructions` task contract, truncated to 16 KB. Use this for relevant repository rules or review contracts rather than copying the parent transcript.
|
|
54
|
+
|
|
50
55
|
## Token Budget
|
|
51
56
|
|
|
52
57
|
Each sub-agent runs with:
|
|
53
58
|
- **System prompt**: agent body only (~200-1K tokens typical)
|
|
54
59
|
- **No AGENTS.md**: saves 500-5K tokens
|
|
55
60
|
- **No extensions/skills loaded**: saves 200-1K tokens
|
|
56
|
-
- **Thinking
|
|
61
|
+
- **Thinking per role**: defaults off; bundled scout/reviewer/worker choose low/high/medium
|
|
57
62
|
- **No compaction**: avoids compaction token cost
|
|
58
63
|
|
|
59
64
|
This is ~10x leaner than spawning a full `pi` process.
|
package/agents/reviewer.md
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: reviewer
|
|
3
|
-
description: Code review specialist. Use for
|
|
4
|
-
tools: read, grep, find, ls
|
|
5
|
-
|
|
3
|
+
description: Code review specialist. Use for correctness, security, regression, and meaningful test-gap review.
|
|
4
|
+
tools: read, grep, find, ls
|
|
5
|
+
thinking: high
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
You are
|
|
8
|
+
You are an independent senior code reviewer. Inspect the requested Git scope with read-only tools.
|
|
9
9
|
|
|
10
|
-
Focus on:
|
|
11
|
-
1.
|
|
12
|
-
2.
|
|
13
|
-
3.
|
|
14
|
-
4.
|
|
15
|
-
5. **Best practices**: Idiomatic patterns, testability, documentation
|
|
10
|
+
Focus only on actionable issues introduced by the reviewed change:
|
|
11
|
+
1. Correctness and edge cases
|
|
12
|
+
2. Security and data loss
|
|
13
|
+
3. Regressions and API compatibility
|
|
14
|
+
4. Missing tests that allow a likely bug to escape
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
Avoid style noise, praise, and speculative redesign. Every finding needs code evidence.
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Return JSON only:
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"summary": "compact scope/result summary",
|
|
22
|
+
"findings": [
|
|
23
|
+
{
|
|
24
|
+
"severity": "critical|high|medium|low",
|
|
25
|
+
"file": "relative/path",
|
|
26
|
+
"line": 1,
|
|
27
|
+
"issue": "what is wrong and why it matters",
|
|
28
|
+
"evidence": "specific inspected code evidence",
|
|
29
|
+
"suggestedFix": "smallest safe fix",
|
|
30
|
+
"blocking": true
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
```
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
For each issue:
|
|
24
|
-
- **Severity**: critical | high | medium | low
|
|
25
|
-
- **File**: path with line numbers
|
|
26
|
-
- **Problem**: What's wrong
|
|
27
|
-
- **Fix**: Suggested change (code block)
|
|
28
|
-
|
|
29
|
-
## Overall Assessment
|
|
30
|
-
Green/yellow/red with reasoning.
|
|
36
|
+
Use an empty `findings` array when clean. Do not modify files or Git state.
|
package/agents/scout.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: scout
|
|
3
3
|
description: Fast codebase recon that returns compressed context for handoff. Use for finding files, understanding structure, locating symbols.
|
|
4
4
|
tools: read, grep, find, ls
|
|
5
|
-
|
|
5
|
+
thinking: low
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
You are a scout. Quickly investigate a codebase and return structured findings that another agent can use without re-reading everything.
|
|
@@ -22,8 +22,8 @@ Strategy:
|
|
|
22
22
|
|
|
23
23
|
Output format:
|
|
24
24
|
|
|
25
|
-
##
|
|
26
|
-
List
|
|
25
|
+
## Evidence
|
|
26
|
+
List exact file/symbol anchors and relevant line ranges:
|
|
27
27
|
1. `path/to/file.ts` (lines 10-50) - Description of what's here
|
|
28
28
|
2. `path/to/other.ts` (lines 100-150) - Description
|
|
29
29
|
3. ...
|
package/agents/worker.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: worker
|
|
3
|
-
description: General-purpose coding agent with full tool access. Use
|
|
4
|
-
|
|
3
|
+
description: General-purpose coding agent with full tool access. Use only when explicitly requested for isolated implementation.
|
|
4
|
+
thinking: medium
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
You are a skilled software engineer. Implement the requested task with care and precision.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent discovery and configuration for pi-
|
|
2
|
+
* Agent discovery and configuration for pi-subagent.
|
|
3
3
|
*
|
|
4
4
|
* Loads agent definitions from Markdown files with YAML frontmatter.
|
|
5
5
|
* Discovers from user-level (~/.pi/agent/agents/), project-level
|
|
@@ -18,6 +18,7 @@ export interface AgentConfig {
|
|
|
18
18
|
description: string;
|
|
19
19
|
tools?: string[];
|
|
20
20
|
model?: string;
|
|
21
|
+
thinking?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
21
22
|
systemPrompt: string;
|
|
22
23
|
source: "user" | "project" | "bundled";
|
|
23
24
|
filePath: string;
|
|
@@ -32,6 +33,7 @@ interface AgentCache {
|
|
|
32
33
|
userDir: string;
|
|
33
34
|
projectDir: string | null;
|
|
34
35
|
bundledDir: string;
|
|
36
|
+
scope: AgentScope;
|
|
35
37
|
agents: AgentConfig[];
|
|
36
38
|
projectAgentsDir: string | null;
|
|
37
39
|
/** File-level signature per directory (name:mtime:size for each .md file) */
|
|
@@ -69,20 +71,25 @@ function loadAgentsFromDir(dir: string, source: "user" | "project" | "bundled"):
|
|
|
69
71
|
continue;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
const { frontmatter, body } = parseFrontmatter<Record<string,
|
|
74
|
+
const { frontmatter, body } = parseFrontmatter<Record<string, unknown>>(content);
|
|
73
75
|
|
|
74
|
-
if (
|
|
76
|
+
if (typeof frontmatter.name !== "string" || typeof frontmatter.description !== "string") continue;
|
|
75
77
|
|
|
76
|
-
const tools =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const tools =
|
|
79
|
+
typeof frontmatter.tools === "string"
|
|
80
|
+
? frontmatter.tools.split(",").map((t) => t.trim()).filter(Boolean)
|
|
81
|
+
: Array.isArray(frontmatter.tools)
|
|
82
|
+
? (frontmatter.tools as unknown[]).filter((t): t is string => typeof t === "string")
|
|
83
|
+
: undefined;
|
|
80
84
|
|
|
81
85
|
agents.push({
|
|
82
86
|
name: frontmatter.name,
|
|
83
87
|
description: frontmatter.description,
|
|
84
88
|
tools: tools && tools.length > 0 ? tools : undefined,
|
|
85
|
-
model: frontmatter.model
|
|
89
|
+
model: typeof frontmatter.model === "string" ? frontmatter.model : undefined,
|
|
90
|
+
thinking: typeof frontmatter.thinking === "string" && ["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(frontmatter.thinking)
|
|
91
|
+
? frontmatter.thinking as AgentConfig["thinking"]
|
|
92
|
+
: undefined,
|
|
86
93
|
systemPrompt: body,
|
|
87
94
|
source,
|
|
88
95
|
filePath,
|
|
@@ -151,7 +158,8 @@ export function discoverAgents(
|
|
|
151
158
|
_cache &&
|
|
152
159
|
_cache.userDir === userDir &&
|
|
153
160
|
_cache.projectDir === projectAgentsDir &&
|
|
154
|
-
_cache.bundledDir === bundledAgentsDir
|
|
161
|
+
_cache.bundledDir === bundledAgentsDir &&
|
|
162
|
+
_cache.scope === scope
|
|
155
163
|
) {
|
|
156
164
|
let stale = false;
|
|
157
165
|
for (const [dir, cachedSig] of _cache.dirSignatures) {
|
|
@@ -195,6 +203,7 @@ export function discoverAgents(
|
|
|
195
203
|
userDir,
|
|
196
204
|
projectDir: projectAgentsDir,
|
|
197
205
|
bundledDir: bundledAgentsDir,
|
|
206
|
+
scope,
|
|
198
207
|
agents,
|
|
199
208
|
projectAgentsDir,
|
|
200
209
|
dirSignatures,
|