@ferris1225/pi-subagents 4.1.8 → 4.1.11

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
@@ -6,18 +6,45 @@
6
6
  ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
7
  ![pi](https://img.shields.io/badge/pi-extension-orange)
8
8
 
9
- ## Give pi a dependable engineering team
10
-
11
- **pi-subagents** turns delegation in [pi](https://pi.dev) into a complete workflow,
12
- not just a way to launch another prompt.
13
-
14
- Your main agent can send research to `explorer`, implementation to `worker`,
15
- intentional cleanup and duplicate-code consolidation to `cleaner`, documentation
16
- synchronization to `documenter`, and independent checks to `reviewer`. Each role
17
- runs in its own child process with a clean context, works in the background, and
18
- returns its result automatically. Active top-level work can be steered or
19
- retargeted; managed stages can be parked, resumed, stopped, or forked without
20
- losing retained context.
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
21
48
 
22
49
  ```text
23
50
  You
@@ -27,51 +54,15 @@ You
27
54
  ├─ cleaner ──── cleans up ──┘ └─ NEEDED/missing → documenter
28
55
  ├─ documenter ─ explicit docs/comments task → deliver
29
56
  └─ reviewer ─── advisory report (no VERDICT), or managed gate
30
- └─ REVIEW_FAIL → workerreviewer (bounded fix rounds)
57
+ └─ REVIEW_FAIL → findings + fix instructions main agent fixes
31
58
 
32
59
  Worker and cleaner update existing docs/comments they directly affect. The stable
33
60
  parent returns one final result when its complete managed workflow settles.
34
61
  ```
35
62
 
36
- Install it once and keep using pi normally. The extension teaches the main model
37
- when to delegate, so most users do not need custom prompts or manual orchestration.
38
-
39
- ## Why use pi-subagents?
40
-
41
- Use pi-subagents when delegation should **remove coordination work**, not create
42
- more of it.
43
-
44
- - **The right specialist gets the right job.** Research, implementation, cleanup,
45
- and review have separate roles, tools, and operating rules.
46
- - **You do not babysit background work.** Results wake the main agent automatically;
47
- there is no polling loop and no “go check whether it finished” step.
48
- - **Parallel edits stay safe.** Parallel workers use temporary, isolated Git
49
- checkouts (worktrees) by default, then apply their changes back without
50
- touching your index.
51
- - **Documentation stops drifting without a mandatory extra pass.** Workers and
52
- cleaners synchronize directly affected existing docs. After `REVIEW_PASS`,
53
- enabled `documenter` runs only for `DOCUMENTATION: NEEDED` (or conservatively
54
- for a missing marker); with reviewer disabled, it remains the fallback.
55
- - **Review can close the loop.** A failed gate can automatically dispatch a
56
- worker, request another independent review, and repeat up to a hard limit;
57
- documentation is considered only after the terminal `REVIEW_PASS`.
58
- - **Agents remain controllable.** Every run has a stable id and retained session,
59
- so you can change direction or continue later without starting from zero.
60
- - **Failures are handled, not hidden.** Model failures can hand the same session to
61
- the current main model; pre-prompt startup races retry safely; process and
62
- integration failures are reported with recovery details.
63
-
64
- ### More than a basic sub-agent launcher
65
-
66
- | A basic launcher often gives you… | pi-subagents gives you… |
67
- | --- | --- |
68
- | One generic child role | Five focused engineering roles |
69
- | A one-shot prompt | Retained, steerable, resumable, forkable threads |
70
- | Concurrent writers in one checkout | Git worktree isolation for parallel workers |
71
- | A review report you must act on manually | Independent worker/cleaner gate, bounded fix rounds, and conditional docs sync |
72
- | Manual polling or follow-up | Automatic result delivery that resumes the main agent |
73
- | A hard failure when the selected model is unavailable | Direct handoff to the current main model |
74
- | Synchronized retries during startup contention | Extended jittered backoff that reduces retry collisions |
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.
75
66
 
76
67
  ## Quick start
77
68
 
@@ -81,124 +72,38 @@ Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
81
72
  pi install npm:@ferris1225/pi-subagents
82
73
  ```
83
74
 
84
- Open pi and run the setup wizard:
85
-
86
- ```text
87
- /subagents-setup
88
- ```
89
-
90
- Fresh installs enable `explorer`, `worker`, `cleaner`, and `reviewer`.
91
- `documenter` is available in the wizard but stays off until you select it. You
92
- can keep the current main model for every role or choose a different model and
93
- thinking level per agent.
94
-
95
- Then ask for work in plain language:
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:
96
78
 
97
79
  ```text
98
80
  Map how authentication works, fix the refresh race, run the tests, and review the diff.
99
81
  ```
100
82
 
101
- ```text
102
- Clean up src/cache. Remove only code you can prove is dead, then verify the result.
103
- ```
104
-
105
- ```text
106
- Compare screenshots/settings.png with design.png and report every visual mismatch.
107
- ```
83
+ The main agent decides when delegation pays off; you can also call the tools
84
+ directly for exact control.
108
85
 
109
- The main agent decides when delegation is useful. You can also call the tools
110
- explicitly when you want exact control.
111
-
112
- ## Managed workflow behavior
113
-
114
- The runtime deliberately keeps delegation conservative:
115
-
116
- - Small work with a known target stays in the main thread on direct tools.
117
- `explorer` is worthwhile for broad reconnaissance only; it returns a retrieval
118
- index, never an automatic gate, and downstream roles re-read load-bearing code.
119
- - `worker` and `cleaner` remain distinct write-capable entry roles. Each updates
120
- existing README/docs/examples/comments directly affected by its change. After
121
- success, one enabled independent `reviewer` gate runs, with the existing bounded
122
- worker ↔ reviewer fix loop for `REVIEW_FAIL`. Every gate finding carries a
123
- concrete fix instruction; the worker implements those instructions or ships a
124
- sounder fix with an explicit pushback, and re-review judges the resulting code —
125
- only open findings and defects the fix itself introduced can continue the loop.
126
- - When `documenter` is enabled, every managed reviewer gate is asked for a
127
- standalone `DOCUMENTATION: CLEAN` or `DOCUMENTATION: NEEDED` line. Only
128
- `REVIEW_PASS` can authorize the final sync: NEEDED includes
129
- `## Documentation notes` and runs it, CLEAN removes the pending docs stage,
130
- and a missing marker on that passing gate conservatively runs it.
131
- - A process failure, missing verdict, or terminal `REVIEW_FAIL` never starts
132
- documentation writing. With reviewer disabled, the writer → documenter
133
- fallback remains. Documentation drift is non-gating only while documenter is
134
- available; otherwise it is an ordinary review finding.
135
- - A top-level `documenter` is already an explicit docs/comments writing task. It
136
- still uses the shared writer lane and may use worktree isolation, but delivers
137
- directly after success instead of starting another reviewer.
138
-
139
- No workflow decision depends on diff line count, file count, or a size heuristic.
140
-
141
- ## Meet the team
86
+ ## The team
142
87
 
143
88
  | Agent | Access | Best for |
144
89
  | --- | --- | --- |
145
- | `explorer` | Read-only | Broad codebase search, unfamiliar-area mapping, symbol and dependency tracing, and multi-file reconnaissance. |
146
- | `worker` | Full | A self-contained implementation, bug fix, refactor, or test task carried through verification. |
147
- | `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, and duplicate-code consolidation. Dispatch authorizes every safe in-scope cut; it must prove each one. |
148
- | `documenter` | Docs/comments | Conditional final diff sync or an explicit standalone documentation/comment task (including explicitly broad maintenance). Uses an explorer-class model, may make zero edits, and never changes runtime behavior. |
149
- | `reviewer` | Read-only | Audits, code-health checks, plans, PR or issue validation, documentation-drift checks, and fresh pre-commit gates. |
150
-
151
- Children have no memory of the parent conversation. A good manual brief includes
152
- the goal, exact paths, constraints, and expected output. The injected delegation
153
- guidance does this automatically when the main agent dispatches on your behalf.
154
-
155
- ### Tool, plugin, skill, and context inheritance
156
-
157
- Every initial dispatch, managed stage, retained resume, fork, startup retry,
158
- and selected-to-main fallback snapshots the parent session's currently active
159
- tools. Roles without an explicit tool list (such as shipped `worker` and
160
- `cleaner`) inherit that complete set. An explicit role list remains its Pi
161
- built-in permission boundary, but its existing shell slot follows the parent
162
- (`bash`, `powershell`, both, or neither) and parent-active extension/SDK tools
163
- are appended; inactive plugin names declared in frontmatter are not enabled.
164
- Therefore `explorer` and `reviewer` never gain Pi's built-in `edit`/`write`;
165
- `documenter` keeps them for docs/comments; and a custom agent keeps the built-in
166
- capabilities declared in its own frontmatter. All `subagent*` control tools are
167
- removed from children so they remain leaves. An empty inherited snapshot starts
168
- the child with `--no-tools` instead of falling back to Pi's defaults.
169
-
170
- `powershell` is the Pi tool name. On Windows, it selects native `pwsh.exe` when
171
- available and falls back to `powershell.exe`. Parent-active plugin tools such as
172
- web search or API/documentation lookup are available to every child when that
173
- plugin also loads there. Global skills and trusted project skills load normally
174
- inside each child Pi process.
175
-
176
- Each child is an independent Pi session and uses Pi's normal global/project
177
- `compaction` settings. Auto-compaction therefore remains enabled by default when
178
- a child's model context approaches its limit. Retained resume/fork sessions keep
179
- their existing conversation and compaction summaries instead of starting over.
180
-
181
- ## Everyday workflows
182
-
183
- ### Delegate one task
184
-
185
- ```ts
186
- subagent({
187
- agent: "explorer",
188
- task: "Map the test setup. Report exact files, commands, and CI entry points.",
189
- });
190
- ```
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. |
191
95
 
192
- ```ts
193
- subagent({
194
- agent: "worker",
195
- task: "Fix the cache invalidation bug in src/cache, add regression tests, and run the relevant checks.",
196
- });
197
- ```
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.
198
99
 
199
- ### Fan out independent work
100
+ ## Dispatch and fan-out
200
101
 
201
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
202
107
  subagent({
203
108
  tasks: [
204
109
  { agent: "explorer", task: "Trace model fallback from dispatch to completion." },
@@ -207,332 +112,121 @@ subagent({
207
112
  });
208
113
  ```
209
114
 
210
- Independent tasks run up to a fixed limit of `4` concurrent sub-agent processes.
211
- One parallel call may contain at most that many tasks and is rejected if it
212
- exceeds the limit. Accepted background work from separate calls waits in the
213
- shared queue when all slots are busy.
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.
214
120
 
215
- ### Run an independent quality gate
121
+ ## Review gates and fixes
216
122
 
217
123
  ```ts
218
- subagent({
219
- agent: "reviewer",
220
- task: "Gate the current diff for correctness, regressions, and missing tests.",
221
- });
222
- ```
223
-
224
- A gate reviewer ends with `REVIEW_PASS` or `REVIEW_FAIL` and independently
225
- emits `DOCUMENTATION: CLEAN` or `DOCUMENTATION: NEEDED` when documenter is
226
- enabled. Only `REVIEW_PASS` can continue to documentation: CLEAN delivers
227
- immediately, while NEEDED (or a missing marker on that passing gate) runs one
228
- final docs sync. A failure uses the bounded loop:
229
-
230
- ```text
231
- reviewer → worker applies each fix instruction (or rebuts with a sounder fix)
232
- → reviewer re-reviews the result → …
233
- REVIEW_PASS ─┬─ CLEAN → deliver
234
- └─ NEEDED/missing → documenter
235
- ```
236
-
237
- Each step gets a fresh model context. The chain shares the same code state and
238
- passes every full reviewer and worker report forward; it does not reuse one
239
- context window. Re-review converges instead of re-auditing: it rules on every
240
- previous finding once, judges the code as it now stands (a sound worker fix
241
- counts even when it deviates from the instruction), and adds new findings only
242
- for defects the fix round's own edits introduced or exposed — issues unrelated
243
- to those edits belong to a fresh gate, not to the loop. Internal children bypass top-level lifecycle policy, so they
244
- cannot recursively start another chain. Gate reviewers keep documentation drift
245
- out of the code verdict while `documenter` is enabled by recording it under
246
- `## Documentation notes`; with documenter disabled, drift is a normal finding.
247
-
248
- The loop is fixed at two worker fix rounds (each fix is re-reviewed); disabling
249
- the `worker` agent is the way to turn fixes off. The post-writer review gate still
250
- runs regardless, and only a terminal `REVIEW_PASS` can decide whether docs
251
- sync is needed. Generic audits and read-only reviews are advisory: they omit
252
- `VERDICT` and documentation machine markers, remain read-only, and never trigger
253
- edits.
254
-
255
- ### Clean up without guessing
256
-
257
- `cleaner` is only for requests that authorize cleanup edits. Once dispatched,
258
- that authorization covers every safe, proven in-scope cut without another
259
- item-by-item confirmation. It checks reachability, ownership, history, and
260
- boundaries before removing, simplifying, or consolidating anything, then verifies
261
- the result.
262
-
263
- Repeated code is a first-class cleanup target. Cleaner compares contracts,
264
- invariants, side effects, ownership, and reasons to change—not just matching
265
- text—then extracts the smallest stable shared implementation and migrates all
266
- in-scope callers. It keeps similar code separate when domains or future change
267
- axes genuinely differ, avoiding a generic abstraction that is worse than the
268
- duplication.
269
-
270
- ```text
271
- explicit cleanup request → cleaner applies cuts + syncs affected docs → reviewer gate → conditional documenter
272
- read-only cleanup audit → reviewer reports candidates only
124
+ subagent({ agent: "reviewer", task: "Gate the current diff for correctness, regressions, and missing tests." });
273
125
  ```
274
126
 
275
- This separation matters: asking for an audit does not silently authorize code
276
- changes, and asking for cleanup does not reward speculative deletion.
277
-
278
- ### Keep comments and README/docs synchronized
279
-
280
- `documenter` has two deliberate launch paths.
281
-
282
- **For a pending worker or cleaner change**, those writers first synchronize
283
- existing docs/comments directly affected by their edits. When the role is
284
- enabled, runtime schedules a final sync only after terminal `REVIEW_PASS` when
285
- the reviewer emits `DOCUMENTATION: NEEDED` or omits the marker; do not dispatch
286
- a duplicate. If reviewer is disabled, documenter remains the conservative final
287
- fallback. If documenter is disabled, documentation drift is an ordinary reviewer
288
- finding.
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.
289
134
 
290
- **For standalone documentation work**, explicitly authorize the desired scope
291
- (a whole-codebase maintenance pass must be explicit):
292
-
293
- ```ts
294
- subagent({
295
- agent: "documenter",
296
- task: "Run a whole-codebase documentation maintenance pass. Verify comments, docstrings, README files, docs, and examples against the implementation; update every safe stale statement in scope.",
297
- });
298
- ```
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.
299
139
 
300
- A successful top-level documenter delivers directly without another reviewer.
301
- It still occupies the shared writer lane and can use worktree isolation. A
302
- generic or read-only documentation audit belongs to `reviewer`; `documenter` is
303
- a docs/comments writer, never the code approver.
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.
304
144
 
305
145
  ## Safe parallel editing
306
146
 
307
- A Git worktree is a temporary second checkout of the same repository. It shares
308
- Git history with your main checkout but has its own files, so two workers do not
309
- overwrite each other while they run.
310
-
311
- Every child has process and context isolation. Write-capable tasks can also have
312
- filesystem isolation:
313
-
314
- - A single task defaults to `isolation: "shared"`.
315
- - Parallel `worker` tasks default to `isolation: "worktree"`.
316
- - `cleaner` and `documenter` support worktree mode when explicitly requested;
317
- their default remains shared.
318
- - Read-only `explorer` and `reviewer` tasks reject worktree mode because they do
319
- not need a writable checkout.
320
-
321
- Worktree mode requires a Git repository with a committed `HEAD`. For an isolated
322
- worker/cleaner, its automatic reviewer and any needed documenter run inside that
323
- same worktree. A top-level isolated documenter writes there and then delivers
324
- directly. Isolated workflows can still run in parallel; writer, fix, and any
325
- documentation changes are integrated only after the final managed stage
326
- settles. Tracked, deleted, untracked, and binary changes are then carried back
327
- to the original checkout without staging or modifying the parent index.
328
-
329
- Repository-lane discovery uses the Git top-level even in an empty repository, so
330
- root and nested paths share one lane before the first commit. Every shared
331
- `worker`, `cleaner`, and `documenter` writer—and each shared `reviewer` snapshot
332
- when managed writers are enabled—uses that lane. Standalone documentation,
333
- writer-only configurations, and workflows without reviewer cannot race another
334
- writer or documentation sync. Isolated agents keep doing model work in parallel,
335
- but their final apply waits for the same lane.
336
-
337
- Normal completion, stop, and shutdown share one finalization result, so isolated
338
- state is applied at most once. If park, stop, or shutdown wins after the top-level
339
- child settles, no downstream role starts and the stable top-level session remains
340
- the checkpoint. If setup or integration fails, pi-subagents keeps the useful
341
- patch or worktree when possible and records recovery information in:
342
-
343
- ```text
344
- ~/.pi/agent/pi-subagents-recovery.json
345
- ```
346
-
347
- A parked isolated thread keeps its worktree. Resume continues there. Forking an
348
- isolated checkpoint is available after that checkpoint has settled and integrated.
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.
349
158
 
350
- ## Follow, redirect, or stop a run
159
+ ## Follow, redirect, or stop
351
160
 
352
- Dispatch confirmations and completion messages include a stable `#id`. For a
353
- managed worker/cleaner or fix chain, that parent id represents the whole workflow;
354
- each internal reviewer, fix, and conditionally launched documenter gets a
355
- separate queryable id in the final summary. No internal completion wakes the
356
- main agent.
161
+ Every dispatch returns a stable `#id` the handle for all control tools:
357
162
 
358
163
  | Tool | What it does |
359
164
  | --- | --- |
360
- | `subagent_control` | `steer`, `retarget`, `park`, `resume`, or `fork` a logical thread. |
361
- | `subagent_status` | Show active and recent runs, or return the full result for one id. |
362
- | `subagent_wait` | Look up a result in the current turn. It is non-blocking by default; use `timeoutMs` only when you must wait in-turn. |
363
- | `subagent_stop` | Destructively cancel work, deliver partial output, and retire that thread's retained session. Independent forks survive. |
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. |
364
169
 
365
170
  ```ts
366
- subagent_control({ action: "steer", id: 7, instruction: "Check the Windows path too." });
367
- subagent_control({ action: "park", id: 7 });
368
171
  subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
369
- subagent_control({ action: "fork", id: 7, objective: "Try the smaller design instead." });
370
172
  ```
371
173
 
372
- Use `steer` or `retarget` only while the top-level RPC child is active. `steer`
373
- queues guidance without changing the displayed objective; `retarget` aborts that
374
- generation's objective and replaces it in the same session. During an automatic
375
- documenter, reviewer, or fix stage, use `park` or `stop`. `resume` without an
376
- `objective` continues the currently displayed goal; supplying one appends that
377
- explicit goal to the retained conversation and makes it the new displayed goal.
378
- It never clears prior context. `fork` follows the same objective rule on a copied
379
- branch while leaving its source unchanged. Widget labels distinguish retained,
380
- appended, retargeted, and forked objectives.
381
-
382
- Use `park` to preserve the newest active stage and release its process slot;
383
- parking during documentation retains the documenter's partial/session, not an
384
- older writer or review. A resumed logical run keeps cumulative active elapsed
385
- time across all generations while excluding the parked interval. Use `stop` only
386
- when you want to discard that thread's future continuation. Stop and session
387
- shutdown abort the active internal stage, suppress stale delivery, and leave
388
- worktree finalization to the same one-time lifecycle owner. `stop-all` interrupts
389
- every lane holder before waiting for finalization, avoiding self-deadlock when an
390
- isolated apply is queued behind shared work.
391
-
392
- Every control operation is bounded: park, stop, resume, and fork never wait
393
- indefinitely on a generation that is still settling (for example an isolated
394
- apply queued behind the managed repository lane). Stop proceeds after a bounded
395
- deadline once it owns the lifecycle, a still-running integration continues in the
396
- background, and a durable recovery record is persisted pointing at the retained
397
- worktree/patch so stopped work is never lost.
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.
398
180
 
399
181
  ## Results and live status
400
182
 
401
- The active TUI widget shows standalone runs normally and projects each managed
402
- workflow as a compact timeline plus its current internal child. Every row leads
403
- with its stable run id — the handle for `subagent_control`, `subagent_status`,
404
- and `subagent_stop`:
183
+ The TUI widget projects each managed workflow as a timeline plus its current
184
+ child:
405
185
 
406
186
  ```text
407
- ◆ #12 worker workflow · src/cache.ts · wt:a91f3c · 42s
187
+ ◆ #12 worker workflow · src/cache.ts · wt:a91f3c · 42s
408
188
  ✓ implement ─ ● review ─ ○ docs
409
189
  └ ● #15 reviewer · final review · claude-sonnet-4-5/high · 10s
410
- git diff
411
190
  ○ #23 worker · queued · redirect to ripgrep crates · 5m02s
412
191
  ```
413
192
 
414
- Success is green, the active stage uses the accent color and bold text, pending
415
- stages are dim, `REQUEST_CHANGES` is warning-colored, and process failure is an
416
- error. Fix paths show their budget (`fix 1/2`, `re-review 1/2`). The timeline
417
- contains only stages that ran or are currently planned; `DOCUMENTATION: CLEAN`
418
- removes pending docs instead of pretending that stage ran.
419
-
420
- Worktree-isolated runs carry a group badge on the row that owns the worktree:
421
- `wt:<id>` while active, `wt:<id> applying` while the settled patch is being
422
- applied to the original checkout, then `applied`/`clean`, or `retained` when
423
- integration failed. The short id changes when a resumed generation creates a
424
- continuation worktree, so a group boundary change is visible at a glance.
425
- Nested stage rows inherit the group through the tree instead of repeating the
426
- badge. Queued rows say `queued` and omit model/thinking the route is
427
- re-resolved when the run actually starts.
428
-
429
- A managed root keeps its original top-level role and workflow-wide elapsed time,
430
- but omits model/thinking because several model stages own it. The active nested
431
- row shows the current role, relation, selected/fallback model, thinking, stage
432
- elapsed, and activity. Completed internal rows can disappear while their stage
433
- remains visible on the parent until the workflow settles. Standalone,
434
- resume/retarget, and fork labels retain their existing semantics; narrow layouts
435
- prioritize the current stage and elapsed tail. Adjacent workflows add no blank
436
- separator rows.
437
-
438
- A parked parent remains queryable. Final messages contain one managed-workflow
439
- summary with aggregate token/cost totals and every internal id. Built-in roles
440
- author their own result-only handoff—outcome, relevant paths, verification, and unresolved
441
- blockers—without a second summarization layer that could distort the result.
442
- They omit task/process narration and recovered transient tool failures. The
443
- 80-line delivery cap remains a safety limit; long output is written unchanged to
444
- a temporary Markdown artifact, and explicit `subagent_status` lookup keeps the
445
- complete report and failed-tool diagnostics available by id.
446
-
447
- The main agent is told not to paraphrase a result you have already seen. It should
448
- add only its own conclusion or next action instead of charging you twice for the
449
- same explanation.
450
-
451
- ## Models, thinking, and image work
452
-
453
- Each agent can use the current main model or one selected in `/subagents-setup`.
454
- The setup picker shows authenticated models and labels them `vision` or
455
- `text-only`.
456
-
457
- ```text
458
- selected agent model → current main model
459
- ```
460
-
461
- If the selected model is missing, unavailable, rate-limited, out of quota, or
462
- fails at the provider level, the current main model continues the same retained
463
- session. Searches, reads, reasoning, and edits already completed are preserved.
464
- Ordinary tool and test failures remain task failures and do not trigger a model
465
- handoff.
466
-
467
- Model changes apply immediately to work that has not started: a run still
468
- waiting for a concurrency slot re-resolves its route when it actually starts,
469
- and managed workflow stages (fix rounds, re-reviews, the conditional documenter)
470
- re-read the config before each stage launches. Only an already-running child
471
- keeps the model it started with.
472
-
473
- Thinking defaults to **Auto**. pi-subagents starts from the role's preference and
474
- chooses only a level the effective model actually supports. A fallback re-checks
475
- the level for the main model. `documenter` deliberately ships with the same fast,
476
- low-thinking profile as `explorer`; migration and manual enablement copy any
477
- configured explorer route, and you can still override it independently.
478
-
479
- There is no separate vision mode. Assign a multimodal model to the agent and name
480
- the image paths in the task:
481
-
482
- ```ts
483
- subagent({
484
- agent: "reviewer",
485
- task: "Compare screenshots/settings.png with design.png and list every visual mismatch.",
486
- });
487
- ```
488
-
489
- ## Reliability without duplicate work
490
-
491
- - **Startup recovery:** silent, zero-activity failures before prompt dispatch
492
- retry with extended jittered backoff. A dispatched prompt is never replayed,
493
- even when its ACK is lost.
494
- - **Idle watchdog:** a run with no RPC output for `idleTimeoutSec` is terminated;
495
- selected-model failures can continue on the current main model.
496
- - **Retained context:** model handoff, park/resume, retarget, and fork build on the
497
- same session history instead of repeating discovery.
498
- - **Visible failures:** process crashes, partial parallel starts, model failures,
499
- and Git integration failures are returned as failures rather than silent hangs.
500
- - **Safe status text:** live tool activity is credential-redacted and stripped of
501
- terminal control characters.
502
- - **No runaway trees:** child processes are leaves; they cannot dispatch more
503
- sub-agents.
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. There is no separate
207
+ vision mode: assign a multimodal model and name the image paths in the task.
208
+
209
+ Every dispatch, managed stage, resume, retry, and fallback snapshots the
210
+ parent's currently active tools: roles without an explicit list inherit the
211
+ full set; explicit lists keep their Pi built-in boundary while their shell slot
212
+ (`bash`/`powershell`) follows the parent and active extension tools are
213
+ appended. Read-only roles never gain `edit`/`write`; all `subagent*` tools are
214
+ stripped so children stay leaves. An empty snapshot starts the child with
215
+ `--no-tools`.
504
216
 
505
217
  ## Configuration
506
218
 
507
- The wizard covers enabled agents, per-agent models and thinking, and the idle
508
- timeout:
509
-
510
- ```text
511
- /subagents-setup
512
- ```
513
-
514
- In nested setup screens, `Esc` returns one level: thinking → model → agent
515
- selection → settings. Runtime value pickers return to the Runtime settings menu,
516
- and other nested pickers return to the main settings menu. Only `Esc` from the
517
- top-level settings menu exits the wizard; completed agent choices are saved when
518
- leaving that configuration pass.
519
-
520
- Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
521
- `PI_CODING_AGENT_DIR` when that environment variable is set.
219
+ `/subagents-setup` stays one level deep: enabled agents, per-agent models, and
220
+ the delegation-injection toggle. Everything else is config-file only, stored at
221
+ `~/.pi/agent/pi-subagents.json` (follows `PI_CODING_AGENT_DIR`):
522
222
 
523
223
  ```json
524
224
  {
525
225
  "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
526
- "agentModels": {
527
- "explorer": "anthropic/claude-haiku-4-5",
528
- "documenter": "anthropic/claude-haiku-4-5"
529
- },
530
- "agentThinkingLevels": {
531
- "documenter": "low",
532
- "reviewer": "high"
533
- },
226
+ "agentModels": { "explorer": "anthropic/claude-haiku-4-5" },
227
+ "agentThinkingLevels": { "reviewer": "high" },
534
228
  "notifyOnReviewPass": false,
535
- "maxResultLines": 80,
229
+ "maxResultLines": 40,
536
230
  "proactiveInjection": true,
537
231
  "agentScope": "user",
538
232
  "idleTimeoutSec": 90
@@ -541,32 +235,26 @@ Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
541
235
 
542
236
  | Field | Meaning |
543
237
  | --- | --- |
544
- | `enabledAgents` | Agent names available for discovery and delegation. `[]` disables all agents. |
545
- | `agentModels` | Optional `provider/model-id` per agent. Missing means use the current main model. |
546
- | `agentThinkingLevels` | Optional manual level per agent. Missing means Auto. |
547
- | `notifyOnReviewPass` | When `true`, a standalone passing gate is delivered without waking the main agent. Managed workflows still wake once at final delivery. Default `false`. |
548
- | `maxResultLines` | Lines kept in a completion message before the full result moves to a temporary artifact. Default `80`. |
549
- | `proactiveInjection` | Teach the main model when and how to delegate. Default `true`. |
238
+ | `enabledAgents` | Agents available for discovery and delegation. `[]` disables all. |
239
+ | `agentModels` | Optional `provider/model-id` per agent; missing = current main model. |
240
+ | `agentThinkingLevels` | Optional manual level per agent; missing = Auto. |
241
+ | `notifyOnReviewPass` | Deliver a standalone passing gate without waking the main agent. Default `false`. |
242
+ | `maxResultLines` | Lines kept in a completion message before the artifact takes over. Default `40`. |
243
+ | `proactiveInjection` | Inject the delegation directive into the main system prompt. Default `true`. |
550
244
  | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
551
- | `idleTimeoutSec` | Seconds without RPC output before termination. `0` disables the watchdog. Default `90`. |
245
+ | `idleTimeoutSec` | Seconds without child RPC output before termination; `0` disables. Default `90`. |
552
246
 
553
- Invalid values fall back safely. Keys from older versions (including the former
554
- `maxConcurrency` and `maxFixRounds` tuning options, now fixed at `4` concurrent
555
- processes and `2` fix rounds) are dropped automatically and the normalized
556
- shape is saved back. At session start, per-agent model overrides that Pi no
557
- longer reports as available are removed with a one-time notice; those agents
558
- fall back to the current main model until you re-pick them in
559
- `/subagents-setup`.
247
+ Invalid values fall back safely; stale keys (including the former
248
+ `maxConcurrency`/`maxFixRounds` knobs) are dropped automatically. At session
249
+ start, model overrides Pi no longer reports are removed with a one-time notice.
560
250
 
561
- ## Custom and overridden agents
251
+ ## Custom agents
562
252
 
563
- Built-ins ship in the package. You can add or replace agents with Markdown files:
253
+ Built-ins ship in the package; add or replace them with Markdown files:
564
254
 
565
255
  - User agents: `~/.pi/agent/agents/`
566
- - Project agents: nearest `.pi/agents/` directory in a trusted project
567
- - Precedence: project overrides user, user overrides built-in
568
-
569
- To replace a built-in, use the same filename and `name`. Optional frontmatter:
256
+ - Project agents: nearest `.pi/agents/` in a trusted project
257
+ - Precedence: project > user > built-in (same `name` wins)
570
258
 
571
259
  ```yaml
572
260
  ---
@@ -576,14 +264,12 @@ model: anthropic/claude-haiku-4-5
576
264
  thinking: low
577
265
  tools: read, bash
578
266
  ---
267
+ …additional system prompt…
579
268
  ```
580
269
 
581
- The Markdown body becomes the child's additional system prompt. Configuration
582
- chosen in `/subagents-setup` takes precedence over frontmatter defaults. A
583
- custom agent's explicit `tools` list remains its Pi built-in capability boundary;
584
- an existing shell slot follows the parent, and active extension/SDK tools are
585
- appended as described above. Omitting `tools` inherits the parent's complete
586
- active set.
270
+ Wizard choices override frontmatter defaults; an explicit `tools` list stays the
271
+ capability boundary (shell slot follows the parent, active extension tools are
272
+ appended), and omitting it inherits the parent's complete active set.
587
273
 
588
274
  ## Development
589
275
 
@@ -593,11 +279,10 @@ npm run check
593
279
  npm test
594
280
  ```
595
281
 
596
- The package has no bundled runtime dependencies; it uses pi and TypeBox as peer
597
- packages. Source is split by responsibility: managed dispatch/workflow policy,
598
- retained thread lifecycle, RPC transport, worktree integration, completion
599
- delivery, tools, and TUI status.
282
+ No bundled runtime dependencies pi and TypeBox are peers. Source is split by
283
+ responsibility: dispatch/workflow policy, thread lifecycle, RPC transport,
284
+ worktree integration, completion delivery, tools, and TUI status.
600
285
 
601
286
  ## License
602
287
 
603
- [MIT](./LICENSE)
288
+ MIT