@ferris1225/pi-subagents 4.1.13 → 4.1.16

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 CHANGED
@@ -1,291 +1,333 @@
1
- # pi-subagents
2
-
3
- [![npm version](https://img.shields.io/npm/v/@ferris1225/pi-subagents?color=blue)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
4
- [![downloads](https://img.shields.io/npm/dm/@ferris1225/pi-subagents)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
5
- [![license](https://img.shields.io/npm/l/@ferris1225/pi-subagents)](./LICENSE)
6
- ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
- ![pi](https://img.shields.io/badge/pi-extension-orange)
8
-
9
- A managed engineering team for [pi](https://github.com/earendil-works/pi): five
10
- specialized sub-agents, durable threads, automatic quality gates, and Git
11
- worktree isolation — installed once, then your main agent delegates on its own.
12
-
13
- ## Why pi-subagents
14
-
15
- Delegation should **remove** coordination work, not create more of it. Most
16
- sub-agent launchers stop at "spawn a child with a prompt"; the coordination
17
- burden — when to delegate, how wide to fan out, who reviews, what happens when a
18
- model dies, how results come back — stays with you. pi-subagents owns that
19
- burden:
20
-
21
- - **The main model actually delegates.** A lean delegation directive is injected
22
- into its system prompt: substantive work goes to children so the main context
23
- stays lean for orchestration, trivial work stays inline, and nothing is
24
- re-explained twice. No custom prompts needed.
25
- - **Fan-out is the model's call, not a cap.** One parallel dispatch carries as
26
- many tasks as the work genuinely decomposes into. The runtime paces execution
27
- at four concurrent child processes; extra tasks simply queue, so wide batches
28
- never fail and never flood your context (results deliver compact, with the
29
- full text on disk).
30
- - **Quality gates are built in.** Successful worker/cleaner runs continue
31
- through one independent reviewer gate, and `REVIEW_FAIL` findings return to
32
- the main agent with concrete fix instructions — it resolves them itself,
33
- without stopping to ask you. No black-box auto-fix chain edits code behind
34
- your back.
35
- - **Documentation stops drifting.** Writers sync the docs they directly affect;
36
- after a passing gate, the documenter runs only when the reviewer actually
37
- reports drift.
38
- - **Parallel edits are safe.** Parallel workers default to isolated Git
39
- worktrees and integrate back without touching your index; shared-checkout
40
- writers serialize through one repository lane.
41
- - **Work survives everything.** Threads keep retained sessions across resume,
42
- stop, and pi reloads or crashes; a model failure hands the same session to
43
- the current main model instead of losing progress.
44
- - **Failures are visible.** Crashes, partial starts, and integration failures
45
- come back as results with recovery records — never as silent hangs.
46
-
47
- ## How it works
48
-
49
- ```text
50
- You
51
- └─ pi main agent
52
- ├─ explorer ─── retrieval index only (never an automatic gate)
53
- ├─ worker ───── implements ─┬─▶ reviewer ─┬─ docs CLEAN → deliver
54
- ├─ cleaner ──── cleans up ──┘ └─ NEEDED/missing → documenter
55
- ├─ documenter ─ explicit docs/comments task → deliver
56
- └─ reviewer ─── advisory report (no VERDICT), or managed gate
57
- └─ REVIEW_FAIL findings + fix instructions main agent fixes
58
-
59
- Worker and cleaner update existing docs/comments they directly affect. The stable
60
- parent returns one final result when its complete managed workflow settles.
61
- ```
62
-
63
- Every child is an isolated leaf Pi process with its own context window and no
64
- memory of your conversation the brief is its only input. Completions resume
65
- the main agent automatically; there is no polling loop.
66
-
67
- ## Quick start
68
-
69
- Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
70
-
71
- ```bash
72
- pi install npm:@ferris1225/pi-subagents
73
- ```
74
-
75
- Open pi and run `/subagents-setup` to pick agents and models. Fresh installs
76
- enable `explorer`, `worker`, `cleaner`, and `reviewer`; `documenter` is opt-in.
77
- Then just ask:
78
-
79
- ```text
80
- Map how authentication works, fix the refresh race, run the tests, and review the diff.
81
- ```
82
-
83
- The main agent decides when delegation pays off; you can also call the tools
84
- directly for exact control.
85
-
86
- ## The team
87
-
88
- | Agent | Access | Best for |
89
- | --- | --- | --- |
90
- | `explorer` | Read-only | Broad search, unfamiliar-area mapping, symbol/dependency tracing. Fast model, returns a retrieval index — never proof. |
91
- | `worker` | Full | A self-contained implementation, fix, refactor, or test task carried through verification. |
92
- | `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, deduplication. Every safe proven cut applies without item-by-item approval. |
93
- | `documenter` | Docs/comments | Conditional final diff sync, or an explicit standalone docs/comments task. May make zero edits; never changes runtime behavior. |
94
- | `reviewer` | Read-only | Audits, code-health checks, plans, PR/issue validation, and independent gates. |
95
-
96
- A good brief carries the goal, exact paths, constraints, and expected output
97
- the injected delegation guidance does this automatically when the main agent
98
- dispatches for you.
99
-
100
- ## Dispatch and fan-out
101
-
102
- ```ts
103
- // One task
104
- subagent({ agent: "worker", task: "Fix the cache invalidation bug in src/cache, add regression tests, run the checks." });
105
-
106
- // Parallel: as many genuinely independent units as the work has
107
- subagent({
108
- tasks: [
109
- { agent: "explorer", task: "Trace model fallback from dispatch to completion." },
110
- { agent: "worker", task: "Add edge-case tests for config migration." },
111
- ],
112
- });
113
- ```
114
-
115
- The main agent owns the breadth there is no per-call task cap. The runtime
116
- runs four child processes at once and queues the rest; a generation that moves
117
- on to its managed stages (gate review, docs sync) releases its slot, so managed
118
- work never starves new dispatches. One child owns one coherent deliverable and
119
- its files; dependent work starts only after its prerequisite delivers.
120
-
121
- ## Review gates and fixes
122
-
123
- ```ts
124
- subagent({ agent: "reviewer", task: "Gate the current diff for correctness, regressions, and missing tests." });
125
- ```
126
-
127
- A gate ends with `VERDICT: REVIEW_PASS` or `REVIEW_FAIL`, plus
128
- `DOCUMENTATION: CLEAN`/`NEEDED` when documenter is enabled. Only `REVIEW_PASS`
129
- continues to documentation: CLEAN delivers immediately; NEEDED or a missing
130
- marker runs one final docs sync. A `REVIEW_FAIL` delivers the full findings
131
- each with a concrete fix instruction straight back to the main agent, which
132
- resolves them itself (inline or via a worker it briefs) without waiting for you;
133
- only a genuinely destructive or scope-changing fix is worth asking about.
134
-
135
- Re-verifying your own fixes? Dispatch with `advisory: true`: the report comes
136
- back to the main window and never starts anything, even if a verdict slips
137
- through. Generic audits and read-only reviews are advisory by default: no
138
- `VERDICT`, no edits.
139
-
140
- `cleaner` is dispatch-authorized cleanup: asking for an audit never silently
141
- authorizes code changes, and asking for cleanup never rewards speculative
142
- deletion. A top-level `documenter` is an explicit docs-writing task that
143
- delivers without another gate.
144
-
145
- ## Safe parallel editing
146
-
147
- - Single tasks default to the shared checkout; parallel `worker` tasks default
148
- to detached Git worktrees (requires a committed `HEAD`; read-only agents
149
- reject worktree mode).
150
- - An isolated workflow's reviewer and documenter run inside the same worktree;
151
- tracked, deleted, untracked, and binary changes integrate back exactly once
152
- after the workflow settles — nothing is staged and your index is untouched.
153
- - Shared-checkout writers (and reviewers snapshotting their diff) serialize
154
- through one repository lane, so two shared writers never race.
155
- - Setup or integration failures keep the useful patch/worktree and record
156
- recovery info in `~/.pi/agent/pi-subagents-recovery.json`; a parked isolated
157
- thread keeps its worktree and resumes there.
158
-
159
- ## Follow, redirect, or stop
160
-
161
- Every dispatch returns a stable `#id` the handle for all control tools:
162
-
163
- | Tool | What it does |
164
- | --- | --- |
165
- | `subagent_control` | `resume` a parked/settled thread with its full retained context, optionally with a new `objective` appended. |
166
- | `subagent_status` | List active and recent runs, or return one run's full result and failed-tool diagnostics. |
167
- | `subagent_wait` | Non-blocking in-turn lookup; `timeoutMs` only when you must wait. |
168
- | `subagent_stop` | Destructively cancel, deliver the partial output, retire the thread. |
169
-
170
- ```ts
171
- subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
172
- ```
173
-
174
- Threads are durable: parked/settled sessions, worktree checkpoints, and state
175
- live under `~/.pi/agent/` (not the OS temp directory) and are restored when pi
176
- reloads or restarts a reload interrupts a live run into a restorable
177
- checkpoint instead of losing it. Settled results stay resumable for 7 days,
178
- parked work for 30. All control operations are bounded; they never hang on a
179
- generation that is still settling.
180
-
181
- ## Results and live status
182
-
183
- The TUI widget projects each managed workflow as a timeline plus its current
184
- child:
185
-
186
- ```text
187
- #12 worker workflow · src/cache.ts · wt:a91f3c · 42s
188
- implement review ○ docs
189
- #15 reviewer · final review · claude-sonnet-4-5/high · 10s
190
- ○ #23 worker · queued · redirect to ripgrep crates · 5m02s
191
- ```
192
-
193
- Completions resume the main agent automatically with a compact block (40 lines
194
- by default; longer output lands unchanged in a temporary Markdown artifact
195
- reachable via `subagent_status`). Roles author result-only handoffs — outcome,
196
- paths, verification, unresolved blockers — and the main agent is told to add
197
- its conclusion, not restate what you already saw.
198
-
199
- ## Models, thinking, and vision
200
-
201
- Each agent runs on the current main model or one picked in `/subagents-setup`
202
- (vision/text-only labels included). If a selected model is missing, rate-limited,
203
- or fails at the provider level, the **same retained session** continues on the
204
- main model — finished searches, reads, and edits are preserved; ordinary task
205
- failures do not trigger a handoff. Thinking defaults to **Auto**: the role's
206
- preference, clamped to what the effective model supports. `/subagents-setup`
207
- *Configure an agent* also offers a manual strength per agent, listing only the
208
- levels that model supports. There is no separate
209
- vision mode: assign a multimodal model and name the image paths in the task.
210
-
211
- Every dispatch, managed stage, resume, retry, and fallback snapshots the
212
- parent's currently active tools: roles without an explicit list inherit the
213
- full set; explicit lists keep their Pi built-in boundary while their shell slot
214
- (`bash`/`powershell`) follows the parent and active extension tools are
215
- appended. Read-only roles never gain `edit`/`write`; all `subagent*` tools are
216
- stripped so children stay leaves. An empty snapshot starts the child with
217
- `--no-tools`.
218
-
219
- ## Configuration
220
-
221
- `/subagents-setup` stays one level deep: enabled agents, per-agent models and
222
- thinking strengths, and the delegation-injection toggle. Everything else is
223
- config-file only, stored at
224
- `~/.pi/agent/pi-subagents.json` (follows `PI_CODING_AGENT_DIR`):
225
-
226
- ```json
227
- {
228
- "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
229
- "agentModels": { "explorer": "anthropic/claude-haiku-4-5" },
230
- "agentThinkingLevels": { "reviewer": "high" },
231
- "notifyOnReviewPass": false,
232
- "maxResultLines": 40,
233
- "proactiveInjection": true,
234
- "agentScope": "user",
235
- "idleTimeoutSec": 90
236
- }
237
- ```
238
-
239
- | Field | Meaning |
240
- | --- | --- |
241
- | `enabledAgents` | Agents available for discovery and delegation. `[]` disables all. |
242
- | `agentModels` | Optional `provider/model-id` per agent; missing = current main model. |
243
- | `agentThinkingLevels` | Optional manual level per agent; missing = Auto. |
244
- | `notifyOnReviewPass` | Deliver a standalone passing gate without waking the main agent. Default `false`. |
245
- | `maxResultLines` | Lines kept in a completion message before the artifact takes over. Default `40`. |
246
- | `proactiveInjection` | Inject the delegation directive into the main system prompt. Default `true`. |
247
- | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
248
- | `idleTimeoutSec` | Seconds without child RPC output before termination; `0` disables. Default `90`. |
249
-
250
- Invalid values fall back safely; stale keys (including the former
251
- `maxConcurrency`/`maxFixRounds` knobs) are dropped automatically. At session
252
- start, model overrides Pi no longer reports are removed with a one-time notice.
253
-
254
- ## Custom agents
255
-
256
- Built-ins ship in the package; add or replace them with Markdown files:
257
-
258
- - User agents: `~/.pi/agent/agents/`
259
- - Project agents: nearest `.pi/agents/` in a trusted project
260
- - Precedence: project > user > built-in (same `name` wins)
261
-
262
- ```yaml
263
- ---
264
- name: explorer
265
- description: Fast read-only codebase reconnaissance
266
- model: anthropic/claude-haiku-4-5
267
- thinking: low
268
- tools: read, bash
269
- ---
270
- …additional system prompt…
271
- ```
272
-
273
- Wizard choices override frontmatter defaults; an explicit `tools` list stays the
274
- capability boundary (shell slot follows the parent, active extension tools are
275
- appended), and omitting it inherits the parent's complete active set.
276
-
277
- ## Development
278
-
279
- ```bash
280
- npm install
281
- npm run check
282
- npm test
283
- ```
284
-
285
- No bundled runtime dependencies pi and TypeBox are peers. Source is split by
286
- responsibility: dispatch/workflow policy, thread lifecycle, RPC transport,
287
- worktree integration, completion delivery, tools, and TUI status.
288
-
289
- ## License
290
-
291
- MIT
1
+ # pi-subagents
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@ferris1225/pi-subagents?color=blue)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
4
+ [![downloads](https://img.shields.io/npm/dm/@ferris1225/pi-subagents)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
5
+ [![license](https://img.shields.io/npm/l/@ferris1225/pi-subagents)](./LICENSE)
6
+ ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
+ ![pi](https://img.shields.io/badge/pi-extension-orange)
8
+
9
+ A managed engineering team for [pi](https://github.com/earendil-works/pi): five
10
+ specialized sub-agents, durable threads, automatic quality gates, and Git
11
+ worktree isolation — installed once, then your main agent delegates on its own.
12
+
13
+ ## Why pi-subagents
14
+
15
+ Delegation should **remove** coordination work, not create more of it. Most
16
+ sub-agent launchers stop at "spawn a child with a prompt"; the coordination
17
+ burden — when to delegate, how wide to fan out, who reviews, what happens when a
18
+ model dies, how results come back — stays with you. pi-subagents owns that
19
+ burden:
20
+
21
+ - **The main model actually delegates.** A lean delegation directive is injected
22
+ into its system prompt: child contexts are cheap and yours is scarce
23
+ non-trivial implementation defaults to `worker`, trivial work stays inline,
24
+ and dispatching never blocks or ends the main turn, so it can fire several
25
+ dispatches and keep working while they run.
26
+ - **Fan-out is the model's call, not a cap.** One parallel dispatch carries as
27
+ many tasks as the work genuinely decomposes into. The runtime paces execution
28
+ at a process-slot pool that scales with the machine (cores/2, bounded 4–16);
29
+ extra tasks simply queue and start automatically as slots free, so wide
30
+ batches never fail, never flood your context (results deliver compact, with
31
+ the full text on disk), and queueing is always visible pacing — never a
32
+ hidden dispatch limit.
33
+ - **Quality gates are built in and converge by themselves.** Successful
34
+ worker/cleaner runs continue through one independent reviewer gate. A failing
35
+ gate is fixed by the reviewer itself — the same retained session gets write
36
+ access and applies its own fix instructions, then a converging re-review
37
+ verifies the fixes — bounded rounds; a still-failing gate returns to the main
38
+ agent with every finding and fix instruction. No guessing what satisfies the
39
+ reviewer.
40
+ - **Documentation stops drifting.** Writers sync the docs they directly affect;
41
+ documentation drift is an ordinary gate finding, and dispatching the
42
+ documenter for real remaining drift stays the main agent's decision.
43
+ - **Parallel edits are safe.** Parallel workers default to isolated Git
44
+ worktrees and integrate back without touching your index; shared-checkout
45
+ writers serialize through one repository lane.
46
+ - **Work survives everything.** Threads keep retained sessions across resume,
47
+ stop, and pi reloads or crashes; a model failure hands the same session to
48
+ the current main model instead of losing progress.
49
+ - **Failures are visible.** Crashes, partial starts, and integration failures
50
+ come back as results with recovery records — never as silent hangs.
51
+
52
+ ## How it works
53
+
54
+ ```text
55
+ You
56
+ └─ pi main agent
57
+ ├─ explorer ─── retrieval index only (never an automatic gate)
58
+ ├─ worker ───── implements ─┬─▶ reviewer ─ PASS → deliver
59
+ ├─ cleaner ──── cleans up ──┘ └─ FAIL reviewer fixes itself
60
+ ├─ documenter explicit docs/comments task deliver │
61
+ └─ reviewer ─── advisory report (no VERDICT), or managed gate ◀──────┘
62
+ └─ direct REVIEW_FAIL → findings + fix instructions → main agent fixes
63
+
64
+ Worker and cleaner update existing docs/comments they directly affect. The stable
65
+ parent returns one final result when its complete managed workflow settles.
66
+ ```
67
+
68
+ Every child is an isolated leaf Pi process with its own context window and no
69
+ memory of your conversation the brief is its only input. Completions resume
70
+ the main agent automatically; there is no polling loop.
71
+
72
+ ## Quick start
73
+
74
+ Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
75
+
76
+ ```bash
77
+ pi install npm:@ferris1225/pi-subagents
78
+ ```
79
+
80
+ Open pi and run `/subagents-setup` to pick agents, models, and thinking
81
+ strengths. Fresh installs enable all five built-in agents on the current main
82
+ model, and until a config file exists each session start points you at
83
+ `/subagents-setup`. Then just ask:
84
+
85
+ ```text
86
+ Map how authentication works, fix the refresh race, run the tests, and review the diff.
87
+ ```
88
+
89
+ The main agent decides when delegation pays off; you can also call the tools
90
+ directly for exact control.
91
+
92
+ ## The team
93
+
94
+ | Agent | Access | Best for |
95
+ | ------------ | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
96
+ | `explorer` | Read-only | Broad search, unfamiliar-area mapping, symbol/dependency tracing. Fast model, returns a retrieval index never proof. |
97
+ | `worker` | Full | The default route for any non-trivial, self-contained implementation, fix, refactor, or test task carried through verification. |
98
+ | `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, deduplication. Every safe proven cut applies without item-by-item approval. |
99
+ | `documenter` | Docs/comments | Standalone docs/comments work, including syncing real drift a change left behind. May make zero edits; never changes runtime behavior. |
100
+ | `reviewer` | Read-only (review) / full (fix stage) | Audits, code-health checks, plans, PR/issue validation, and independent gates; a failing managed gate continues into the reviewer's own write-enabled fix stage. |
101
+
102
+ A good brief carries the goal, exact paths, constraints, and expected output —
103
+ the injected delegation guidance does this automatically when the main agent
104
+ dispatches for you.
105
+
106
+ ## Dispatch and fan-out
107
+
108
+ ```ts
109
+ // One task
110
+ subagent({
111
+ agent: "worker",
112
+ task: "Fix the cache invalidation bug in src/cache, add regression tests, run the checks.",
113
+ });
114
+
115
+ // Parallel: as many genuinely independent units as the work has
116
+ subagent({
117
+ tasks: [
118
+ {
119
+ agent: "explorer",
120
+ task: "Trace model fallback from dispatch to completion.",
121
+ },
122
+ { agent: "worker", task: "Add edge-case tests for config migration." },
123
+ ],
124
+ });
125
+ ```
126
+
127
+ The main agent owns the breadth there is no per-call task cap. The runtime
128
+ runs a machine-scaled pool of child processes at once and queues the rest;
129
+ dispatch confirmations and `subagent_status` state the live running/queued
130
+ counts and the slot capacity, so pacing is never mistaken for a limit. A
131
+ generation that moves on to its managed stages (gate review, fix rounds) or
132
+ waits on the shared-checkout writer lane releases its slot, so neither managed
133
+ work nor serialized writers starve new dispatches. Parallel write-capable
134
+ agents default to isolated worktrees and integrate via a three-way merge, so
135
+ disjoint edits from parallel workers land without conflicts. One child owns one
136
+ coherent deliverable and its files; dependent work starts only after its
137
+ prerequisite delivers.
138
+
139
+ ## Review gates and fixes
140
+
141
+ ```ts
142
+ subagent({
143
+ agent: "reviewer",
144
+ task: "Gate the current diff for correctness, regressions, and missing tests.",
145
+ });
146
+ ```
147
+
148
+ A gate ends with exactly one verdict line: `VERDICT: REVIEW_PASS` or
149
+ `REVIEW_FAIL`. Every gate finding carries a concrete fix instruction, and the
150
+ reviewer must surface the complete finding set in one pass never rationing
151
+ findings across later rounds.
152
+
153
+ A failing **managed** gate (after a top-level worker/cleaner) converges inside
154
+ the workflow: the same retained reviewer session continues with write access
155
+ and applies its own fix instructions, then a fresh gate verifies the fixes and
156
+ hunts regressions they introduced (re-reviews converge on the fixes instead of
157
+ re-scanning the whole surface). The loop is bounded to two fix rounds, after
158
+ which the still-failing gate returns to the main agent with every finding.
159
+
160
+ A failing gate **you dispatched directly** returns the full findings to the
161
+ main agent, which resolves them itself (inline or via a worker it briefs)
162
+ without waiting for you; only a genuinely destructive or scope-changing fix is
163
+ worth asking about. It re-verifies once, then reports remaining findings and
164
+ moves on gate dispatches never loop. Generic audits and read-only reviews
165
+ are advisory by default: no `VERDICT`, no edits.
166
+
167
+ `cleaner` is dispatch-authorized cleanup: asking for an audit never silently
168
+ authorizes code changes, and asking for cleanup never rewards speculative
169
+ deletion. A top-level `documenter` is an explicit docs-writing task that
170
+ delivers without another gate.
171
+
172
+ ## Safe parallel editing
173
+
174
+ - Single tasks default to the shared checkout; every parallel write-capable
175
+ agent (`worker`, `cleaner`, `documenter`, custom writers) defaults to a
176
+ detached Git worktree (requires a committed `HEAD`; read-only agents reject
177
+ worktree mode), so parallel writers run concurrently.
178
+ - An isolated workflow's reviewer and documenter run inside the same worktree;
179
+ tracked, deleted, untracked, and binary changes integrate back exactly once
180
+ after the workflow settles — nothing is staged and your index is untouched.
181
+ - Integration is a three-way merge: parallel workers that touched disjoint
182
+ files or regions land cleanly even when earlier patches drifted the checkout.
183
+ A genuine overlap keeps conflict markers in the checkout plus the retained
184
+ worktree and patch for you to resolve.
185
+ - Shared-checkout writers (and reviewers snapshotting their diff) serialize
186
+ through one repository lane, so two shared writers never race.
187
+ - Setup or integration failures keep the useful patch/worktree and record
188
+ recovery info in `~/.pi/agent/pi-subagents-recovery.json`; a parked isolated
189
+ thread keeps its worktree and resumes there.
190
+
191
+ ## Follow, redirect, or stop
192
+
193
+ Every dispatch returns a stable `#id` the handle for all control tools:
194
+
195
+ | Tool | What it does |
196
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197
+ | `subagent_control` | `resume` a parked/settled thread with its full retained context, optionally with a new `objective` appended. Only interrupted (parked) threads survive a reload. |
198
+ | `subagent_status` | List active and recent runs, or return one run's full result and failed-tool diagnostics. |
199
+ | `subagent_wait` | Non-blocking in-turn lookup; `timeoutMs` only when you must wait. |
200
+ | `subagent_stop` | Destructively cancel, deliver the partial output, retire the thread. |
201
+
202
+ ```ts
203
+ subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
204
+ ```
205
+
206
+ Threads are durable while work is unfinished: parked sessions, worktree
207
+ checkpoints, and result excerpts live under
208
+ `~/.pi/agent/ferris-pi-subagents/<project>/` (grouped per project; not the OS
209
+ temp directory) and are restored when pi reloads or restarts a reload
210
+ interrupts a live run into a restorable checkpoint instead of losing it. A
211
+ thread that completes or fails cleanly drops its durable record, so the
212
+ threads manifest exists only
213
+ while interrupted work needs it; parked work stays resumable for 30 days, and
214
+ a project directory idle for three days is deleted wholesale on the next load
215
+ (parked threads' references always win), so per-project storage never grows
216
+ forever. All control operations are bounded; they never hang on a generation
217
+ that is still settling.
218
+
219
+ ## Results and live status
220
+
221
+ The TUI widget projects each managed workflow as a timeline plus its current
222
+ child:
223
+
224
+ ```text
225
+ ◆ #12 worker workflow · src/cache.ts · wt:a91f3c · 42s
226
+ ✓ implement ─ ● review ─ ○ docs
227
+ └ ● #15 reviewer · final review · claude-sonnet-4-5/high · 10s
228
+ #23 worker · queued · redirect to ripgrep crates · 5m02s
229
+ ```
230
+
231
+ The widget is capped at ten lines: when many runs are live at once, extra rows
232
+ collapse into a `… +N more (subagent_status)` marker so the editor area keeps
233
+ its space; `subagent_status` always shows the full picture.
234
+
235
+ Completions resume the main agent automatically with a compact block (40 lines
236
+ by default; longer output lands unchanged in a temporary Markdown artifact
237
+ reachable via `subagent_status`). Roles author result-only handoffs — outcome,
238
+ paths, verification, unresolved blockers — and the main agent is told to add
239
+ its conclusion, not restate what you already saw.
240
+
241
+ ## Models, thinking, and vision
242
+
243
+ Each agent runs on the current main model or one picked in `/subagents-setup`
244
+ (vision/text-only labels included). If a selected model is missing, rate-limited,
245
+ or fails at the provider level, the **same retained session** continues on the
246
+ main model finished searches, reads, and edits are preserved; ordinary task
247
+ failures do not trigger a handoff. Thinking defaults to **Auto**: the role's
248
+ preference, clamped to what the effective model supports. `/subagents-setup`
249
+ _Configure an agent_ also offers a manual strength per agent, listing only the
250
+ levels that model supports. There is no separate
251
+ vision mode: assign a multimodal model and name the image paths in the task.
252
+
253
+ Every dispatch, managed stage, resume, retry, and fallback snapshots the
254
+ parent's currently active tools: roles without an explicit list inherit the
255
+ full set; explicit lists keep their Pi built-in boundary while their shell slot
256
+ (`bash`/`powershell`) follows the parent and active extension tools are
257
+ appended. Read-only roles never gain `edit`/`write`; all `subagent*` tools are
258
+ stripped so children stay leaves. An empty snapshot starts the child with
259
+ `--no-tools`.
260
+
261
+ ## Configuration
262
+
263
+ `/subagents-setup` stays one level deep: enabled agents, per-agent models and
264
+ thinking strengths, and the delegation-injection toggle. Everything else is
265
+ config-file only, stored at
266
+ `~/.pi/agent/pi-subagents.json` (follows `PI_CODING_AGENT_DIR`):
267
+
268
+ ```json
269
+ {
270
+ "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
271
+ "agentModels": { "explorer": "anthropic/claude-haiku-4-5" },
272
+ "agentThinkingLevels": { "reviewer": "high" },
273
+ "notifyOnReviewPass": false,
274
+ "maxResultLines": 40,
275
+ "proactiveInjection": true,
276
+ "agentScope": "user",
277
+ "idleTimeoutSec": 90
278
+ }
279
+ ```
280
+
281
+ | Field | Meaning |
282
+ | --------------------- | --------------------------------------------------------------------------------- |
283
+ | `enabledAgents` | Agents available for discovery and delegation. `[]` disables all. |
284
+ | `agentModels` | Optional `provider/model-id` per agent; missing = current main model. |
285
+ | `agentThinkingLevels` | Optional manual level per agent; missing = Auto. |
286
+ | `notifyOnReviewPass` | Deliver a standalone passing gate without waking the main agent. Default `false`. |
287
+ | `maxResultLines` | Lines kept in a completion message before the artifact takes over. Default `40`. |
288
+ | `proactiveInjection` | Inject the delegation directive into the main system prompt. Default `true`. |
289
+ | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
290
+ | `idleTimeoutSec` | Seconds without child RPC output before termination; `0` disables. Default `90`. |
291
+
292
+ Invalid values fall back safely; stale keys (including the former
293
+ `maxConcurrency`/`maxFixRounds` knobs) are dropped automatically. At session
294
+ start, model overrides Pi no longer reports are removed with a one-time notice.
295
+
296
+ ## Custom agents
297
+
298
+ Built-ins ship in the package; add or replace them with Markdown files:
299
+
300
+ - User agents: `~/.pi/agent/agents/`
301
+ - Project agents: nearest `.pi/agents/` in a trusted project
302
+ - Precedence: project > user > built-in (same `name` wins)
303
+
304
+ ```yaml
305
+ ---
306
+ name: explorer
307
+ description: Fast read-only codebase reconnaissance
308
+ model: anthropic/claude-haiku-4-5
309
+ thinking: low
310
+ tools: read, bash
311
+ ---
312
+ …additional system prompt…
313
+ ```
314
+
315
+ Wizard choices override frontmatter defaults; an explicit `tools` list stays the
316
+ capability boundary (shell slot follows the parent, active extension tools are
317
+ appended), and omitting it inherits the parent's complete active set.
318
+
319
+ ## Development
320
+
321
+ ```bash
322
+ npm install
323
+ npm run check
324
+ npm test
325
+ ```
326
+
327
+ No bundled runtime dependencies — pi and TypeBox are peers. Source is split by
328
+ responsibility: dispatch/workflow policy, thread lifecycle, RPC transport,
329
+ worktree integration, completion delivery, tools, and TUI status.
330
+
331
+ ## License
332
+
333
+ MIT