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