@ferris1225/pi-subagents 4.1.1 → 4.1.3

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,326 +6,484 @@
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
- Focused background delegation for [pi](https://pi.dev): `explorer` / `worker` /
10
- `cleaner` / `reviewer` agents run in **isolated child processes** and hand their
11
- results back to the main agent automatically. Install it, and the main model
12
- starts using it on its own no prompt engineering, no babysitting.
13
-
14
- ## 4.0.1 automatic explorer config migration
15
-
16
- Version 4 renames the built-in reconnaissance role from `explore` to `explorer`
17
- without retaining a runtime alias. Version 4.0.1 automatically migrates the old
18
- name in `enabledAgents`, `agentModels`, and `agentThinkingLevels`, then persists
19
- the normalized configuration; an already configured `explorer` value wins a
20
- conflict. `cleaner` is apply-only: explicit cleanup intent authorizes it to prove
21
- and perform every safe in-scope cut, while generic or read-only assessments go to
22
- `reviewer` without triggering auto-fix.
23
-
24
- The main delegation directive is now the single authoritative routing policy;
25
- duplicated tool guidelines were removed to cut the default parent injection by
26
- more than half without changing process isolation, worktree rules, retained-session
27
- fallback, or result handoff. Agent frontmatter model defaults remain because they
28
- still select a model when no current main model exists; frontmatter comments do not
29
- enter model context.
30
-
31
- Every dispatch retains its stable run id and can be steered, parked, resumed,
32
- retargeted, or forked. The active widget continues to show task, effective model
33
- and thinking level, activity, and elapsed time.
34
-
35
- The common quality loop now runs end to end without waking the main agent between
36
- steps:
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.
37
21
 
38
22
  ```text
39
- reviewer (find issues) → worker (fix every finding) → reviewer (verify) → final PASS/FAIL
23
+ You
24
+ └─ pi main agent
25
+ ├─ explorer ─── maps the codebase
26
+ ├─ worker ───── implements ─┬─▶ documenter ─▶ reviewer
27
+ ├─ cleaner ──── cleans up ──┘ (enabled roles only)
28
+ ├─ documenter ─ synchronizes docs ─▶ reviewer
29
+ └─ reviewer ─── advisory report (no VERDICT), or managed gate
30
+ ├─ REVIEW_PASS + documenter → documenter → fresh reviewer
31
+ └─ REVIEW_FAIL → worker → optional documenter → reviewer
32
+
33
+ The stable parent run returns one final result when the complete workflow settles.
40
34
  ```
41
35
 
42
- Gate reviews use a single flat findings list no severity triage. Every reported
43
- finding is fixed before the change is accepted, and each re-review converges on
44
- an open-finding set: the worker's explicit rejections are adjudicated once, only
45
- defects a fix round introduced or exposed are added, and resolved items never
46
- re-open. `maxFixRounds` stays the hard cap, so a chain always settles and wakes
47
- the main agent with the full picture. Advisory reviewer requests (generic audits,
48
- code health, plans, and proposed solutions) return evidence without a machine
49
- verdict, so they never start auto-fix.
50
-
51
- Cleanup stays a separate lifecycle: only an explicit request authorizing cleanup,
52
- removal, or simplification edits dispatches the evidence-first `cleaner`. It proves
53
- candidates, applies every safe in-scope cut end to end, and may validly make zero
54
- edits; non-trivial changes still go through the independent `reviewer` gate.
55
-
56
- Each chain is delivered as one concise completion group whose footer totals the
57
- aggregate token usage and cost of every included run, while full per-run reports
58
- remain available through `subagent_status`. Its parent stays `running`
59
- until the whole chain settles; completed internal rounds leave active status
60
- immediately, so no `done` row keeps accumulating elapsed time. Selected-to-main
61
- model handoffs keep the same retained context, and isolated parallel workers use
62
- detached Git worktrees whose changes are applied back without touching the parent
63
- index.
64
-
65
- ## Highlights
66
-
67
- - **Zero-setup proactive dispatch** the extension injects a delegation directive
68
- into the main system prompt, so the main model sends broad searches to `explorer`,
69
- self-contained implementations to `worker`, edit-authorizing cleanup to `cleaner`,
70
- and generic assessments or pre-commit gates to `reviewer`. You just use pi;
71
- delegation happens by itself.
72
- - **Multimodal work is a model choice, not a mode** — an agent that should see
73
- screenshots, mockups, or its own rendered pages simply gets a multimodal model
74
- through `/subagents-setup` (the picker labels each model `vision` or
75
- `text-only`). The agent reads images with its `read` tool on whatever model it
76
- runs; no per-task flag, no separate vision override.
77
- - **Results come back on their own** completions are delivered as messages that
78
- wake the main agent automatically, even mid-turn. No polling, no `sleep`, no
79
- "go check" step. `subagent_wait` is a **non-blocking** in-turn lookup by default
80
- (pass `timeoutMs` to block); `subagent_status` inspects runs; `subagent_stop`
81
- cancels one and delivers its partial output.
82
- - **Active-only live widget, as a tree** — each queued or running sub-agent gets one compact
83
- width-aware primary line with task, effective model/thinking, and elapsed time; current
84
- activity appears only when present on an indented second line. Auto-fix rounds nest under
85
- the triggering reviewer row that owns the chain, so it is always visible who dispatched
86
- what; no run ids appear here — the tree and the task label identify each row:
87
- ```text
88
- ● reviewer · review diff of src/foo.ts · claude-sonnet-4-5/high · 42s
89
- ├ ● worker · fix round 1 · src/foo.ts · claude-sonnet-4-5/high · 10s
90
- │ grep cacheKey
91
- └ ○ reviewer · re-review round 1 · claude-sonnet-4-5/high · 3s
92
- ```
93
- Long tasks and activity paths truncate first (preserving a useful path tail when
94
- possible), groups have no blank rows, and settled/parked runs disappear immediately.
95
- - **Results are not re-narrated** — a sub-agent's completion is shown to you
96
- verbatim, and the main agent is told not to paraphrase it back. It replies with
97
- only its own conclusion or next step, so the same findings are never paid for
98
- twice in tokens.
99
- - **Evidence-first cleanup, not deletion by guesswork** — `cleaner` is apply-only:
100
- an explicit cleanup request authorizes edits, but each candidate must be proved
101
- before every safe in-scope cut is applied and verified. Finding nothing safe and
102
- making zero edits remains valid. Generic/read-only assessments go to `reviewer`;
103
- cleaner is periodic/intent-driven, never PR-count-driven or an automatic gate.
104
- - **A quality gate that closes the loop** — when a gate reviewer returns
105
- `REVIEW_FAIL`, the extension dispatches a worker briefed with the concrete
106
- findings, then a re-review, up to `maxFixRounds` times — and only then wakes the
107
- main agent. Advisory reviewer reports omit that verdict and never trigger edits.
108
- Every reported finding gets fixed (no severity triage), and re-reviews converge
109
- on an open-finding set instead of ping-ponging: worker rejections are adjudicated
110
- once, only defects the fix round introduced are added, and resolved items never
111
- re-open. Every round stays in the triggering reviewer's cwd, and chains that target the
112
- same repository are serialized so shared-checkout edits cannot race.
113
- - **Direct fallback with real thinking capabilities** — each agent has at most
114
- one selected model. An unavailable selection, rate limit, invalid key, quota,
115
- missing model, or provider failure hands directly to the current main model.
116
- A child-only provider adapter forces inner request retries to zero; transient
117
- stream drops still use Pi's outer turn retry, and only a settled model-level
118
- failure hands off, without changing user settings. Auto thinking clamps the
119
- agent preference to the
120
- effective model's real `thinkingLevelMap`; manual setup shows only levels that
121
- model supports.
122
- - **Resumes, retargets, and forks preserve context** — every run is session-backed.
123
- `subagent_control` can steer active work, retarget it after a stable abort,
124
- park/resume it under the same run id, or fork a parked/settled checkpoint into
125
- a new independent run. Concurrent resume calls are serialized.
126
- - **Concise but honest completions** — group completions end with aggregate token
127
- and cost totals across every included run; failed-tool diagnostics stay out of the
128
- delivered message and remain one `subagent_status` call away. Actual process,
129
- model, and integration failures still surface as failures.
130
- - **Parallel fan-out with filesystem isolation** — independent tasks run up to a
131
- configurable limit (default 4). Parallel workers default to detached Git
132
- worktrees; tracked, deleted, untracked, and binary changes are applied back
133
- without touching the parent index. Failed integration keeps recovery artifacts.
134
- - **Recursion is structurally impossible** — children are leaf processes; the
135
- `subagent` tool is excluded from their toolset.
136
- - **Zero runtime dependencies** — agents are plain Markdown files; overriding or
137
- adding one is writing a file.
138
- - **Update announcements** — when a new configurable feature ships, you are told
139
- about it once (a persisted marker stops the notice from nagging).
140
-
141
- ## What this adds beyond generic subagent dispatch
142
-
143
- This package combines several concrete runtime behaviors rather than only exposing
144
- an undifferentiated child-agent launcher:
145
-
146
- - language-agnostic semantic role guidance for cleanup intent;
147
- - a dedicated evidence-first cleaner, with cleanup kept separate from the
148
- independent reviewer gate;
149
- - isolated, retained threads that can be steered, parked, resumed, retargeted, or
150
- forked under stable run ids;
151
- - the reviewer → worker auto-fix → reviewer loop, fixing every finding under a
152
- convergence contract with a hard round cap;
153
- - failed-tool diagnostics available by run id through `subagent_status`;
154
- - direct selected→main fallback plus capability-aware Auto thinking;
155
- - detached Git worktree isolation for parallel workers and opt-in write-capable
156
- cleaner runs.
157
-
158
- ## Install
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.** Enabled `documenter` runs automatically
52
+ after successful workers/cleaners and before the final reviewer. It can also
53
+ run an explicitly requested whole-codebase maintenance pass.
54
+ - **Review can close the loop.** A failed gate can automatically dispatch a worker,
55
+ run documentation sync, request another independent review, and repeat up to a
56
+ hard limit.
57
+ - **Agents remain controllable.** Every run has a stable id and retained session,
58
+ so you can change direction or continue later without starting from zero.
59
+ - **Failures are handled, not hidden.** Model failures can hand the same session to
60
+ the current main model; pre-prompt startup races retry safely; process and
61
+ integration failures are reported with recovery details.
62
+
63
+ ### More than a basic sub-agent launcher
64
+
65
+ | A basic launcher often gives you… | pi-subagents gives you… |
66
+ | --- | --- |
67
+ | One generic child role | Five focused engineering roles |
68
+ | A one-shot prompt | Retained, steerable, resumable, forkable threads |
69
+ | Concurrent writers in one checkout | Git worktree isolation for parallel workers |
70
+ | A review report you must act on manually | Automatic writer → documenter → reviewer delivery and bounded fix rounds |
71
+ | Manual polling or follow-up | Automatic result delivery that resumes the main agent |
72
+ | A hard failure when the selected model is unavailable | Direct handoff to the current main model |
73
+ | Synchronized retries during startup contention | Extended jittered backoff that reduces retry collisions |
74
+
75
+ ## Quick start
76
+
77
+ Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
159
78
 
160
79
  ```bash
161
80
  pi install npm:@ferris1225/pi-subagents
162
81
  ```
163
82
 
164
- Requires pi **>= 0.83.0**. After installation, open the setup wizard in an
165
- interactive TUI session:
83
+ Open pi and run the setup wizard:
166
84
 
167
85
  ```text
168
86
  /subagents-setup
169
87
  ```
170
88
 
171
- Fresh installs enable `explorer`, `worker`, `cleaner`, and `reviewer` — you can
172
- start delegating immediately. Configs written before `cleaner` shipped are
173
- upgraded on load: `cleaner` is defaulted into the existing `enabledAgents` list
174
- and inherits your configured `reviewer` model and thinking level, with a
175
- one-time notice at the next session start. Disabling it again in
176
- `/subagents-setup` is respected and never undone.
89
+ Fresh installs enable `explorer`, `worker`, `cleaner`, and `reviewer`.
90
+ `documenter` is available in the wizard but stays off until you select it. You
91
+ can keep the current main model for every role or choose a different model and
92
+ thinking level per agent.
177
93
 
178
- ## The agents
94
+ Then ask for work in plain language:
179
95
 
180
- | Agent | Access | Purpose |
181
- | --- | --- | --- |
182
- | `explorer` | Read-only | Fast codebase reconnaissance: broad/open-ended search, multi-file lookups, mapping unfamiliar code. Returns compressed, structured retrieval leads. |
183
- | `worker` | Full | Implements, fixes, refactors, and tests a self-contained task end to end, then reports honest verification. |
184
- | `cleaner` | Full | Proves and applies every safe in-scope cleanup authorized by an explicit cleanup/removal/simplification request; zero edits is valid. Supports worktree isolation. |
185
- | `reviewer` | Read-only | Handles generic audits, code health, plans, proposed solutions, PR/issue validation, and independent pre-commit gates. Advisory reports do not trigger auto-fix. |
96
+ ```text
97
+ Map how authentication works, fix the refresh race, run the tests, and review the diff.
98
+ ```
99
+
100
+ ```text
101
+ Clean up src/cache. Remove only code you can prove is dead, then verify the result.
102
+ ```
103
+
104
+ ```text
105
+ Compare screenshots/settings.png with design.png and report every visual mismatch.
106
+ ```
107
+
108
+ The main agent decides when delegation is useful. You can also call the tools
109
+ explicitly when you want exact control.
110
+
111
+ ## What changed in 4.1.2
112
+
113
+ ### Documentation sync as a real workflow stage
114
+
115
+ The new `documenter` is a write-capable, explorer-class role with two modes:
116
+
117
+ 1. **Pre-commit diff sync** — after the last code edit and before the final
118
+ reviewer, it compares the actual diff with comments, README/docs, examples,
119
+ commands, config, defaults, and lifecycle descriptions.
120
+ 2. **Whole-codebase maintenance** — when explicitly requested, it scans an
121
+ existing project for stale comments and documentation and applies every safe,
122
+ verified correction in scope.
123
+
124
+ It never changes runtime behavior, commits, pushes, publishes, or bumps versions.
125
+ When enabled, runtime now treats it as a managed stage: successful top-level
126
+ `worker`/`cleaner` runs continue through `documenter → reviewer`, a successful
127
+ whole-codebase `documenter` continues through reviewer, and auto-fix rounds use
128
+ `worker → documenter → reviewer`. Existing non-empty configs receive `documenter`
129
+ once and inherit the configured `explorer` model and thinking level; fresh
130
+ installs leave it as an explicit setup choice.
131
+
132
+ ### Safer startup contention recovery
186
133
 
187
- Each agent runs in its own isolated `pi` process with a clean context window; it
188
- has no memory of your conversation, so briefs must be self-contained (goal, exact
189
- paths, constraints, expected output).
134
+ Startup contention is much harder to exhaust. A child that exits or fails its RPC
135
+ readiness handshake before the initial prompt is dispatched is retried through a
136
+ longer backoff window. Each default delay also gets additive jitter, reducing the
137
+ chance that several children retry in the same lockstep waves. The base window
138
+ covers stale startup locks and leaves headroom beyond the default four-way fan-out.
190
139
 
191
- ## Usage
140
+ Only a failure known to precede prompt dispatch qualifies. Once the parent sends a
141
+ prompt command, pi-subagents will not replay it—even if the ACK is lost or an idle
142
+ watchdog wins the race—because Pi may already have started the model or tools.
143
+ This recovery therefore cannot repeat model calls or edits.
192
144
 
193
- ### Single task
145
+ ## Meet the team
146
+
147
+ | Agent | Access | Best for |
148
+ | --- | --- | --- |
149
+ | `explorer` | Read-only | Broad codebase search, unfamiliar-area mapping, symbol and dependency tracing, and multi-file reconnaissance. |
150
+ | `worker` | Full | A self-contained implementation, bug fix, refactor, or test task carried through verification. |
151
+ | `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, and duplicate-code consolidation. Dispatch authorizes every safe in-scope cut; it must prove each one. |
152
+ | `documenter` | Docs/comments | Pre-commit diff sync or explicitly requested whole-codebase documentation maintenance. Uses an explorer-class model, may make zero edits, and never changes runtime behavior. |
153
+ | `reviewer` | Read-only | Audits, code-health checks, plans, PR or issue validation, documentation-drift checks, and fresh pre-commit gates. |
154
+
155
+ Children have no memory of the parent conversation. A good manual brief includes
156
+ the goal, exact paths, constraints, and expected output. The injected delegation
157
+ guidance does this automatically when the main agent dispatches on your behalf.
158
+
159
+ ### Tool, plugin, skill, and context inheritance
160
+
161
+ Every initial dispatch, managed stage, retained resume, fork, startup retry,
162
+ and selected-to-main fallback snapshots the parent session's currently active
163
+ tools. Roles without an explicit tool list (such as shipped `worker` and
164
+ `cleaner`) inherit that complete set. An explicit role list remains its Pi
165
+ built-in permission boundary, but its existing shell slot follows the parent
166
+ (`bash`, `powershell`, both, or neither) and parent-active extension/SDK tools
167
+ are appended; inactive plugin names declared in frontmatter are not enabled.
168
+ Therefore `explorer` and `reviewer` never gain Pi's built-in `edit`/`write`;
169
+ `documenter` keeps them for docs/comments; and a custom agent keeps the built-in
170
+ capabilities declared in its own frontmatter. All `subagent*` control tools are
171
+ removed from children so they remain leaves. An empty inherited snapshot starts
172
+ the child with `--no-tools` instead of falling back to Pi's defaults.
173
+
174
+ `powershell` is the Pi tool name. On Windows, it selects native `pwsh.exe` when
175
+ available and falls back to `powershell.exe`. Parent-active plugin tools such as
176
+ web search or API/documentation lookup are available to every child when that
177
+ plugin also loads there. Global skills and trusted project skills load normally
178
+ inside each child Pi process.
179
+
180
+ Each child is an independent Pi session and uses Pi's normal global/project
181
+ `compaction` settings. Auto-compaction therefore remains enabled by default when
182
+ a child's model context approaches its limit. Retained resume/fork sessions keep
183
+ their existing conversation and compaction summaries instead of starting over.
184
+
185
+ ## Everyday workflows
186
+
187
+ ### Delegate one task
194
188
 
195
189
  ```ts
196
- subagent({ agent: "explorer", task: "Map the test setup: which files run what, and how is CI wired? Report exact paths." });
197
- subagent({ agent: "worker", task: "Implement X in src/foo.ts, add tests, run npm test." });
198
- subagent({ agent: "reviewer", task: "Audit src/cache for dead-code candidates and redundant state; report evidence only." });
199
- subagent({ agent: "cleaner", task: "Clean up src/cache: prove and apply every safe dead-code or redundancy cut, update tests/docs, and verify." });
200
- subagent({ agent: "reviewer", task: "Gate the diff of src/index.ts and tests/load.test.ts for correctness and edge cases." });
190
+ subagent({
191
+ agent: "explorer",
192
+ task: "Map the test setup. Report exact files, commands, and CI entry points.",
193
+ });
201
194
  ```
202
195
 
203
- ### Parallel tasks
196
+ ```ts
197
+ subagent({
198
+ agent: "worker",
199
+ task: "Fix the cache invalidation bug in src/cache, add regression tests, and run the relevant checks.",
200
+ });
201
+ ```
202
+
203
+ ### Fan out independent work
204
204
 
205
205
  ```ts
206
206
  subagent({
207
207
  tasks: [
208
- { agent: "explorer", task: "Where is the selected-to-main handoff logic?" },
209
- { agent: "worker", task: "Add unit tests for models.ts." },
208
+ { agent: "explorer", task: "Trace model fallback from dispatch to completion." },
209
+ { agent: "worker", task: "Add edge-case tests for config migration." },
210
210
  ],
211
211
  });
212
212
  ```
213
213
 
214
- ### Cleanup routing and lifecycle
214
+ Independent tasks run up to `maxConcurrency` (default `4`). One parallel call may
215
+ contain at most that many tasks and is rejected if it exceeds the limit. Accepted
216
+ background work from separate calls waits in the shared queue when all slots are
217
+ busy.
218
+
219
+ ### Run an independent quality gate
220
+
221
+ ```ts
222
+ subagent({
223
+ agent: "reviewer",
224
+ task: "Gate the current diff for correctness, regressions, and missing tests.",
225
+ });
226
+ ```
227
+
228
+ A gate reviewer ends with `REVIEW_PASS` or `REVIEW_FAIL`. A direct pass is not
229
+ accepted as the final gate while `documenter` is enabled: runtime first syncs the
230
+ actual pending diff, then starts a fresh reviewer. A failure uses the bounded loop:
231
+
232
+ ```text
233
+ reviewer → worker fixes every open finding → optional documenter sync → reviewer checks again → PASS/FAIL
234
+ ```
235
+
236
+ Each step gets a fresh model context. The chain shares the same code state and
237
+ passes every full reviewer, worker, and documenter report forward; it does not
238
+ reuse one context window. Internal children bypass top-level lifecycle policy, so
239
+ they cannot recursively start another chain.
215
240
 
216
- The injected guidance sends only explicit, edit-authorizing cleanup intent to
217
- `cleaner` in whatever language the conversation uses: clean up/remove dead code,
218
- reduce redundancy, simplify, remove over-engineering, or run a maintenance cleanup
219
- pass. Cleaner first proves reachability, ownership, history, and boundaries, then
220
- applies every safe in-scope cut end to end and verifies it. No proven safe cut means
221
- zero edits, not a forced deletion.
241
+ `maxFixRounds` limits worker fix attempts only. Initial post-writer documentation
242
+ and final review still run when it is `0`. Generic audits and read-only reviews
243
+ are advisory: they omit `VERDICT`, remain read-only, and never trigger edits.
222
244
 
223
- Generic or explicitly read-only **audit**, **inspect**, **report**, **review**,
224
- **code-health**, **plan**, **proposed-solution**, or cleanup-candidate assessment
225
- requests go to `reviewer`. Those are advisory reviews: they omit the machine
226
- `REVIEW_PASS` / `REVIEW_FAIL` marker, cannot start auto-fix, and do not authorize
227
- the main agent to edit. A follow-up change needs an explicit user request. A
228
- reviewer emits the marker only for an explicit diff/pre-commit acceptance gate.
245
+ ### Clean up without guessing
246
+
247
+ `cleaner` is only for requests that authorize cleanup edits. Once dispatched,
248
+ that authorization covers every safe, proven in-scope cut without another
249
+ item-by-item confirmation. It checks reachability, ownership, history, and
250
+ boundaries before removing, simplifying, or consolidating anything, then verifies
251
+ the result.
252
+
253
+ Repeated code is a first-class cleanup target. Cleaner compares contracts,
254
+ invariants, side effects, ownership, and reasons to change—not just matching
255
+ text—then extracts the smallest stable shared implementation and migrates all
256
+ in-scope callers. It keeps similar code separate when domains or future change
257
+ axes genuinely differ, avoiding a generic abstraction that is worse than the
258
+ duplication.
229
259
 
230
260
  ```text
231
- explicit edit-authorizing cleanup → cleaner → reviewer gate
232
- read-only/generic assessment → reviewer advisory report (no auto-fix)
233
- reviewer gate REVIEW_FAIL → worker auto-fix → reviewer gate
261
+ explicit cleanup request → cleaner applies proven cuts documenter syncs docs → reviewer gates the diff
262
+ read-only cleanup audit → reviewer reports candidates only
234
263
  ```
235
264
 
236
- Cleaner is never dispatched by PR count and never acts as the commit gate. The
237
- auto-fix portion runs only for gate verdicts and only when enabled by
238
- `maxFixRounds`.
265
+ This separation matters: asking for an audit does not silently authorize code
266
+ changes, and asking for cleanup does not reward speculative deletion.
267
+
268
+ ### Keep comments and README/docs synchronized
239
269
 
240
- ### Image work (screenshots / mockups / designs)
270
+ `documenter` has two deliberate launch paths.
241
271
 
242
- There is no vision flag or separate vision model. Give the agent a multimodal
243
- model in `/subagents-setup` and name the exact image paths in the task:
272
+ **For a pending worker or cleaner change**, enable the role. Runtime schedules it
273
+ automatically against the actual diff before the final reviewer; do not dispatch
274
+ a duplicate manual sync. If reviewer is disabled, documenter becomes the final
275
+ managed stage. If documenter is disabled, reviewer follows the writer directly.
276
+
277
+ **For an existing project**, explicitly authorize a broad maintenance pass:
244
278
 
245
279
  ```ts
246
280
  subagent({
247
- agent: "reviewer",
248
- task: "Compare the UI in screenshots/settings.png against the mockup design.png; list every visual mismatch.",
281
+ agent: "documenter",
282
+ 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.",
249
283
  });
250
284
  ```
251
285
 
252
- The sub-agent reads images with its `read` tool on its configured model; the
253
- setup picker labels each model `vision` or `text-only` so the choice is visible.
254
- The live widget line, dispatch result row, and `subagent_status` all show each
255
- run's effective model id, and a selected→main handoff is labeled with its
256
- origin.
286
+ A successful explicit whole-codebase documenter also continues automatically to
287
+ reviewer when enabled. A generic or read-only documentation audit still belongs
288
+ to `reviewer`. `documenter` is the last writer, never the approver:
257
289
 
258
- ### Controlling and stopping
290
+ ```text
291
+ worker / cleaner / documenter / auto-fix worker → enabled downstream roles → one final delivery
292
+ ```
293
+
294
+ ## Safe parallel editing
295
+
296
+ A Git worktree is a temporary second checkout of the same repository. It shares
297
+ Git history with your main checkout but has its own files, so two workers do not
298
+ overwrite each other while they run.
299
+
300
+ Every child has process and context isolation. Write-capable tasks can also have
301
+ filesystem isolation:
302
+
303
+ - A single task defaults to `isolation: "shared"`.
304
+ - Parallel `worker` tasks default to `isolation: "worktree"`.
305
+ - `cleaner` and `documenter` support worktree mode when explicitly requested;
306
+ their default remains shared.
307
+ - Read-only `explorer` and `reviewer` tasks reject worktree mode because they do
308
+ not need a writable checkout.
309
+
310
+ Worktree mode requires a Git repository with a committed `HEAD`. For an isolated
311
+ writer, automatic documenter/reviewer children run inside that same worktree.
312
+ Those isolated stages can still run in parallel; writer and documentation changes
313
+ are integrated only after the final reviewer settles. Tracked, deleted, untracked,
314
+ and binary changes are then carried back to the original checkout without staging
315
+ or modifying the parent index.
316
+
317
+ Repository-lane discovery uses the Git top-level even in an empty repository, so
318
+ root and nested paths share one lane before the first commit. Every shared
319
+ `worker`, `cleaner`, and `documenter` writer—and each shared `reviewer` snapshot
320
+ when managed writers are enabled—uses that lane. Standalone documentation,
321
+ writer-only configurations, and workflows without reviewer cannot race another
322
+ writer or documentation sync. Isolated agents keep doing model work in parallel,
323
+ but their final apply waits for the same lane.
324
+
325
+ Normal completion, stop, and shutdown share one finalization result, so isolated
326
+ state is applied at most once. If park, stop, or shutdown wins after the top-level
327
+ child settles, no downstream role starts and the stable top-level session remains
328
+ the checkpoint. If setup or integration fails, pi-subagents keeps the useful
329
+ patch or worktree when possible and records recovery information in:
330
+
331
+ ```text
332
+ ~/.pi/agent/pi-subagents-recovery.json
333
+ ```
259
334
 
260
- Dispatch confirmations, tool result rows, and completion blocks all show the
261
- stable `#id`, so a thread remains directly controllable after its live UI is gone
262
- (the widget itself identifies rows by tree position and task instead of ids).
335
+ A parked isolated thread keeps its worktree. Resume continues there. Forking an
336
+ isolated checkpoint is available after that checkpoint has settled and integrated.
263
337
 
264
- - `subagent_control` `steer`, `retarget`, `park`, `resume`, or `fork` a logical
265
- thread by stable run id. Resume accepts an optional replacement objective;
266
- fork creates a new id and leaves the source unchanged. Park active work before
267
- forking it.
268
- - `subagent_wait` — in-turn result lookup. **Non-blocking by default**: a settled
269
- run returns immediately; an active run tells the model to end its turn. Pass
270
- `timeoutMs` only when you must stay in the turn.
271
- - `subagent_status` — active/parked/finished runs and full result by run id.
272
- - `subagent_stop` — destructive cancellation. It retires that thread's retained
273
- session (independent forks survive) and delivers exactly one aborted partial
274
- result after the run and any worktree integration have quiesced.
338
+ ## Follow, redirect, or stop a run
275
339
 
276
- Examples:
340
+ Dispatch confirmations and completion messages include a stable `#id`. That
341
+ parent id represents the whole managed workflow; each internal documenter,
342
+ reviewer, and fix step gets a separate queryable id in the final summary. No
343
+ internal completion wakes the main agent.
344
+
345
+ | Tool | What it does |
346
+ | --- | --- |
347
+ | `subagent_control` | `steer`, `retarget`, `park`, `resume`, or `fork` a logical thread. |
348
+ | `subagent_status` | Show active and recent runs, or return the full result for one id. |
349
+ | `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. |
350
+ | `subagent_stop` | Destructively cancel work, deliver partial output, and retire that thread's retained session. Independent forks survive. |
277
351
 
278
352
  ```ts
279
353
  subagent_control({ action: "steer", id: 7, instruction: "Check the Windows path too." });
280
354
  subagent_control({ action: "park", id: 7 });
281
355
  subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
282
- subagent_control({ action: "fork", id: 7, objective: "Try the smaller alternative." });
356
+ subagent_control({ action: "fork", id: 7, objective: "Try the smaller design instead." });
357
+ ```
358
+
359
+ Use `steer` or `retarget` only while the top-level RPC child is active. `steer`
360
+ queues guidance without changing the displayed objective; `retarget` aborts that
361
+ generation's objective and replaces it in the same session. During an automatic
362
+ documenter, reviewer, or fix stage, use `park` or `stop`. `resume` without an
363
+ `objective` continues the currently displayed goal; supplying one appends that
364
+ explicit goal to the retained conversation and makes it the new displayed goal.
365
+ It never clears prior context. `fork` follows the same objective rule on a copied
366
+ branch while leaving its source unchanged. Widget labels distinguish retained,
367
+ appended, retargeted, and forked objectives.
368
+
369
+ Use `park` to preserve the newest active stage and release its process slot;
370
+ parking during documentation retains the documenter's partial/session, not an
371
+ older writer or review. A resumed logical run keeps cumulative active elapsed
372
+ time across all generations while excluding the parked interval. Use `stop` only
373
+ when you want to discard that thread's future continuation. Stop and session
374
+ shutdown abort the active internal stage, suppress stale delivery, and leave
375
+ worktree finalization to the same one-time lifecycle owner. `stop-all` interrupts
376
+ every lane holder before waiting for finalization, avoiding self-deadlock when an
377
+ isolated apply is queued behind shared work.
378
+
379
+ ## Results and live status
380
+
381
+ The active TUI widget shows queued and running work as a compact tree:
382
+
383
+ ```text
384
+ ● reviewer workflow · review diff of src/cache.ts · 42s
385
+ ├ ● worker · fix round 1 · src/cache.ts · claude-sonnet-4-5/high · 10s
386
+ │ grep cacheKey
387
+ ├ ● documenter · docs round 1 · claude-haiku-4-5/low · 4s
388
+ └ ○ reviewer · re-review round 1 · claude-sonnet-4-5/high · 3s
389
+ ```
390
+
391
+ A managed root keeps its original top-level role and workflow-wide elapsed
392
+ time, but deliberately omits model/thinking because several model stages own
393
+ that row over its lifetime. The active nested row shows the current stage's
394
+ actual role, selected/fallback model, thinking level, stage elapsed time, and
395
+ activity. Per-stage usage stays attached to that stage; only the final summary
396
+ is labeled and calculated as an aggregate.
397
+
398
+ Completed internal rows disappear from the widget; a parked parent remains
399
+ queryable. Final messages contain one managed-workflow summary with aggregate
400
+ token/cost totals and every internal id. Built-in roles author their own
401
+ result-only handoff—outcome, relevant paths, verification, and unresolved
402
+ blockers—without a second summarization layer that could distort the result.
403
+ They omit task/process narration and recovered transient tool failures. The
404
+ 80-line delivery cap remains a safety limit; long output is written unchanged to
405
+ a temporary Markdown artifact, and explicit `subagent_status` lookup keeps the
406
+ complete report and failed-tool diagnostics available by id.
407
+
408
+ The main agent is told not to paraphrase a result you have already seen. It should
409
+ add only its own conclusion or next action instead of charging you twice for the
410
+ same explanation.
411
+
412
+ ## Models, thinking, and image work
413
+
414
+ Each agent can use the current main model or one selected in `/subagents-setup`.
415
+ The setup picker shows authenticated models and labels them `vision` or
416
+ `text-only`.
417
+
418
+ ```text
419
+ selected agent model → current main model
283
420
  ```
284
421
 
285
- ### Worktree isolation
286
-
287
- Single tasks default to `isolation: "shared"`. Parallel `worker` tasks default
288
- to `isolation: "worktree"`; opt into shared mode only when a worker must see the
289
- caller's live uncommitted tree. `cleaner` is also write-capable and supports
290
- worktree mode when explicitly requested (its default remains shared). Worktree
291
- mode requires a Git repository with a committed `HEAD` and is rejected for the
292
- read-only `explorer` and `reviewer` agents.
293
-
294
- A parked isolated thread keeps its current worktree. Resume it there; fork is
295
- available after that isolated checkpoint settles and its seed is integrated.
296
- Resuming or forking a settled isolated thread creates a fresh worktree, merges a
297
- recorded checkpoint onto the current `HEAD` (including when the seed was already
298
- committed), and clones the Pi session with the new cwd. Forks then integrate only
299
- their unique follow-on edits, so a shared seed is applied once. A run remains
300
- active while final Git integration is in progress and becomes `done` only after
301
- that boundary finishes.
302
-
303
- Every Git operation has a 120-second deadline and process-tree cleanup; captured
304
- Git output and binary patches are capped at 64 MiB. Setup/bound failures surface
305
- instead of hanging. Finalization failures retain the patch/worktree when
306
- available and are recorded in `~/.pi/agent/pi-subagents-recovery.json`; later
307
- sessions show the recovery paths again until the artifacts are removed.
422
+ If the selected model is missing, unavailable, rate-limited, out of quota, or
423
+ fails at the provider level, the current main model continues the same retained
424
+ session. Searches, reads, reasoning, and edits already completed are preserved.
425
+ Ordinary tool and test failures remain task failures and do not trigger a model
426
+ handoff.
427
+
428
+ Thinking defaults to **Auto**. pi-subagents starts from the role's preference and
429
+ chooses only a level the effective model actually supports. A fallback re-checks
430
+ the level for the main model. `documenter` deliberately ships with the same fast,
431
+ low-thinking profile as `explorer`; migration and manual enablement copy any
432
+ configured explorer route, and you can still override it independently.
433
+
434
+ There is no separate vision mode. Assign a multimodal model to the agent and name
435
+ the image paths in the task:
436
+
437
+ ```ts
438
+ subagent({
439
+ agent: "reviewer",
440
+ task: "Compare screenshots/settings.png with design.png and list every visual mismatch.",
441
+ });
442
+ ```
443
+
444
+ ## Reliability without duplicate work
445
+
446
+ - **Startup recovery:** silent, zero-activity failures before prompt dispatch
447
+ retry with extended jittered backoff. A dispatched prompt is never replayed,
448
+ even when its ACK is lost.
449
+ - **Idle watchdog:** a run with no RPC output for `idleTimeoutSec` is terminated;
450
+ selected-model failures can continue on the current main model.
451
+ - **Retained context:** model handoff, park/resume, retarget, and fork build on the
452
+ same session history instead of repeating discovery.
453
+ - **Visible failures:** process crashes, partial parallel starts, model failures,
454
+ and Git integration failures are returned as failures rather than silent hangs.
455
+ - **Safe status text:** live tool activity is credential-redacted and stripped of
456
+ terminal control characters.
457
+ - **No runaway trees:** child processes are leaves; they cannot dispatch more
458
+ sub-agents.
308
459
 
309
460
  ## Configuration
310
461
 
311
- Stored at `~/.pi/agent/pi-subagents.json` (follows `PI_CODING_AGENT_DIR` when
312
- set). `/subagents-setup` has four top-level choices: enable agents, configure one
313
- agent's model/thinking, runtime settings, or full setup.
314
- After one agent's model + thinking picks, the wizard returns to the agent picker
315
- so several agents can be configured in one pass; Esc at any step ends the pass
316
- and keeps every agent already configured. There is no backup pool or global thinking menu. Model pickers show only in-scope
317
- models with configured authentication and display their real supported thinking
318
- levels. Thinking defaults to **Auto**; manual overrides show only levels supported
319
- by that agent's effective model. `notifyOnReviewPass` and `maxResultLines` remain
320
- direct-file settings.
462
+ The wizard covers enabled agents, per-agent models and thinking, concurrency,
463
+ auto-fix rounds, and the idle timeout:
464
+
465
+ ```text
466
+ /subagents-setup
467
+ ```
468
+
469
+ In nested setup screens, `Esc` returns one level: thinking model → agent
470
+ selection settings. Runtime value pickers return to the Runtime settings menu,
471
+ and other nested pickers return to the main settings menu. Only `Esc` from the
472
+ top-level settings menu exits the wizard; completed agent choices are saved when
473
+ leaving that configuration pass.
474
+
475
+ Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
476
+ `PI_CODING_AGENT_DIR` when that environment variable is set.
321
477
 
322
478
  ```json
323
479
  {
324
- "enabledAgents": ["explorer", "worker", "cleaner", "reviewer"],
480
+ "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
325
481
  "agentModels": {
326
- "explorer": "anthropic/claude-haiku-4-5"
482
+ "explorer": "anthropic/claude-haiku-4-5",
483
+ "documenter": "anthropic/claude-haiku-4-5"
327
484
  },
328
485
  "agentThinkingLevels": {
486
+ "documenter": "low",
329
487
  "reviewer": "high"
330
488
  },
331
489
  "notifyOnReviewPass": false,
@@ -338,127 +496,52 @@ direct-file settings.
338
496
  }
339
497
  ```
340
498
 
341
- | Field | Description |
499
+ | Field | Meaning |
342
500
  | --- | --- |
343
- | `enabledAgents` | Agent names exposed to discovery and prompt injection. An empty array disables all agents. |
344
- | `agentModels` | Optional selected `provider/model-id` per agent. Missing = current main model. Model-level failure hands directly to current main. |
345
- | `agentThinkingLevels` | Optional manual preference per agent. Missing = Auto (agent frontmatter preference, or `high`, clamped to the effective model's supported levels). |
346
- | `notifyOnReviewPass` | When `true`, a passing reviewer result is delivered without waking the main agent (default `false`). |
347
- | `maxResultLines` | Max lines of a sub-agent result carried in the completion message (default `80`). Longer results are truncated; full text is written to an extension-named temporary `.md`. At session start and on each write, only recognized result files older than 7 days are removed; each canonical project path has its own newest-50 bucket. |
348
- | `proactiveInjection` | Whether to add the delegation directive to the main system prompt. |
349
- | `agentScope` | `user`, `project`, or `both`; controls which user/project agent directories are discovered. |
350
- | `maxConcurrency` | Max sub-agent processes running at once (1–16, default 4), and the max tasks one parallel `subagent` call accepts. Extra work waits in the queue. |
351
- | `maxFixRounds` | Auto-fix rounds when a reviewer returns `REVIEW_FAIL` (default 2; `0` disables the loop). Hard cap: the chain always settles, delivers its condensed summary, and wakes the main agent. |
352
- | `idleTimeoutSec` | Idle watchdog: a sub-agent whose stdout goes silent for this long is terminated; a selected model then hands to current main. `0` disables it. Default 90. |
353
-
354
- ### Model routing and thinking
355
-
356
- ```text
357
- selected agent model current main-window model
358
- ```
359
-
360
- Without a selected model, current main runs immediately; agent frontmatter `model`
361
- is used only when no main model exists, so the shipped defaults remain behaviorally
362
- load-bearing. From an agent Markdown file, only the body after frontmatter becomes
363
- the child's appended system prompt; model-selection comments inside YAML
364
- frontmatter are parser comments, not model prompt tokens. A selection missing from Pi's live
365
- available catalog is skipped. Any model-level runtime failure — rate limit,
366
- quota, invalid key/auth, missing model, provider error, or idle model stream —
367
- hands directly to current main, including stream errors that retain partial text.
368
- A child-only Pi extension wraps the selected provider's registered API stream
369
- with `maxRetries: 0` so a deterministic auth/quota miss fails fast. Transient
370
- stream drops such as xAI `terminated` still use Pi's outer turn retry — the
371
- parent does not `abort_retry` them — and only a settled model-level failure
372
- hands off to current main. This uses supported extension/RPC surfaces in Node
373
- and standalone/Bun builds, never rewrites global or project settings, and does
374
- not alter descendant tool environments. Tool/test failures stay on the same
375
- model because they are task failures, not model availability failures. A child is
376
- probed with RPC `get_state` before the first prompt so the 30s command ACK clock
377
- does not include process boot. Only a zero-activity startup miss can retry — a
378
- silent fast exit, a `get_state` handshake timeout, or an initial prompt ACK
379
- timeout before any agent/turn/stream/tool activity. Those transport misses are
380
- not model-level failures and do not hand the task to the main window. An accepted
381
- prompt or any activity forbids replay.
382
-
383
- Auto thinking starts from the Agent's declared preference (`low` for `explorer`,
384
- `high` for the other built-ins) and uses Pi's capability map to clamp it to the
385
- actual model. Non-reasoning models resolve to `off`; `xhigh`/`max` appear in setup
386
- only when that model explicitly supports them. A selected→main handoff re-clamps
387
- thinking for the main model.
388
-
389
- ### Choosing an explorer model
390
-
391
- Choose a competent fast code model for `explorer`, not automatically the cheapest
392
- model. Cheap reconnaissance is useful for mechanical symbol/path discovery, but
393
- a missed dynamic entrypoint or ownership edge can cost more through downstream
394
- rework. Direct main-model handoff handles provider/runtime failure; it cannot
395
- detect a plausible but incomplete answer.
396
-
397
- `explorer` therefore returns an index of exact paths, lines, symbols, and explicit
398
- uncertainty. The main agent, worker, or cleaner must re-read load-bearing files
399
- before editing or deciding deletion, security, compatibility, persistence, or
400
- dynamic reachability. Prefer a stronger model or direct specialist for complex
401
- dynamic loading, concurrency, migrations, and security-sensitive code.
402
-
403
- ### Resuming retained context
404
-
405
- Every run stores its Pi session in a private temp directory. A selected→main
406
- handoff resumes that same session, so searches, reads, reasoning, and edits remain
407
- in context. A parked, completed, or failed thread can later be resumed under its
408
- stable id:
409
-
410
- ```ts
411
- subagent_control({ action: "resume", id: 7 });
412
- subagent_control({ action: "resume", id: 7, objective: "Continue with the repaired credentials." });
501
+ | `enabledAgents` | Agent names available for discovery and delegation. `[]` disables all agents. |
502
+ | `agentModels` | Optional `provider/model-id` per agent. Missing means use the current main model. |
503
+ | `agentThinkingLevels` | Optional manual level per agent. Missing means Auto. |
504
+ | `notifyOnReviewPass` | When `true`, a standalone passing gate is delivered without waking the main agent. Managed workflows still wake once at final delivery. Default `false`. |
505
+ | `maxResultLines` | Lines kept in a completion message before the full result moves to a temporary artifact. Default `80`. |
506
+ | `proactiveInjection` | Teach the main model when and how to delegate. Default `true`. |
507
+ | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
508
+ | `maxConcurrency` | Running process limit and maximum tasks in one parallel call, from `1` to `16`. Default `4`. |
509
+ | `maxFixRounds` | Maximum worker fixes after `REVIEW_FAIL`; each fix is followed by optional documenter and reviewer. `0` disables fixes but not initial post-writer docs/review. Default `2`. |
510
+ | `idleTimeoutSec` | Seconds without RPC output before termination. `0` disables the watchdog. Default `90`. |
511
+
512
+ Invalid values fall back safely. Older configs are normalized automatically. The
513
+ former built-in name `explore` migrates to `explorer`, and pre-cleaner non-empty
514
+ agent lists receive `cleaner` once. Existing non-empty configs also receive
515
+ `documenter` once, inserted before `reviewer`, with any configured `explorer`
516
+ model and thinking copied across. Fresh installs do not enable `documenter`
517
+ until the user selects it. Later deliberate disables are respected.
518
+
519
+ ## Custom and overridden agents
520
+
521
+ Built-ins ship in the package. You can add or replace agents with Markdown files:
522
+
523
+ - User agents: `~/.pi/agent/agents/`
524
+ - Project agents: nearest `.pi/agents/` directory in a trusted project
525
+ - Precedence: project overrides user, user overrides built-in
526
+
527
+ To replace a built-in, use the same filename and `name`. Optional frontmatter:
528
+
529
+ ```yaml
530
+ ---
531
+ name: explorer
532
+ description: Fast read-only codebase reconnaissance
533
+ model: anthropic/claude-haiku-4-5
534
+ thinking: low
535
+ tools: read, bash
536
+ ---
413
537
  ```
414
538
 
415
- Use `fork` when both paths should remain available. `subagent_stop` is the
416
- explicit destructive operation that retires a retained session; otherwise
417
- sessions live until the parent Pi session shuts down.
418
-
419
- ### Configuration migration
420
-
421
- Config loading normalizes schema fields and removes invalid or obsolete keys,
422
- including `agentBackupModels`, global `thinkingLevel`, `maxParallelTasks`, and
423
- `maxSubagentDepth`. Per-agent thinking preferences remain capability-clamped.
424
-
425
- The built-in reconnaissance role is now `explorer`, with no runtime `explore`
426
- alias. Config loading automatically renames the old key in `enabledAgents`,
427
- `agentModels`, and `agentThinkingLevels`, deduplicates an old/new pair, and persists
428
- the normalized file. When both model or thinking keys are valid, the explicit
429
- `explorer` value wins. Other configured non-empty names are preserved. A
430
- pre-existing non-empty `enabledAgents` list also gains `cleaner` exactly once
431
- (inserted before `reviewer`, inheriting the configured `reviewer` model and
432
- thinking level); an explicit empty list is honored, and a later deliberate
433
- disable is remembered via a stamp in `announcedFeatures`.
434
-
435
- ## Agent discovery and overrides
436
-
437
- - Built-in agents ship with the package; user agents live in `~/.pi/agent/agents/`;
438
- project agents in the nearest `.pi/agents/` directory are loaded only when Pi
439
- trusts that project.
440
- - For duplicate names: project overrides user overrides built-in. Keep the
441
- matching filename and `name` field to replace a built-in agent.
442
- - Optional frontmatter: `model` (default model reference), `thinking` (default
443
- thinking strength), `tools` (comma-separated tool allow-list; absent = all
444
- tools). Config overrides win at spawn.
445
-
446
- ## How it stays reliable
447
-
448
- - **Direct model recovery** — unavailable selections skip immediately; any
449
- selected-model provider/auth/quota/rate-limit failure hands directly to current
450
- main with thinking re-clamped to the main model.
451
- - **Startup-race retries** — a silent zero-activity child exit (concurrent pi
452
- startup lock contention) is relaunched with backoff; only clean silent exits
453
- qualify, so real work is never duplicated.
454
- - **Idle watchdog** — a stalled selected-model stream (no output for
455
- `idleTimeoutSec`) terminates the child and hands the retained session to current
456
- main.
457
- - **Dispatch failures surface** — partial parallel startup reports every failed
458
- item and reason; if none start, the tool throws so Pi records a real tool error.
459
- Dispatch crashes likewise produce a failed result instead of a silent hang.
460
- - **Safe live status** — tool activity is credential-redacted and stripped of terminal control sequences before `subagent_status` can return it.
461
- - **Leaf children** — no nested delegation, no runaway trees.
539
+ The Markdown body becomes the child's additional system prompt. Configuration
540
+ chosen in `/subagents-setup` takes precedence over frontmatter defaults. A
541
+ custom agent's explicit `tools` list remains its Pi built-in capability boundary;
542
+ an existing shell slot follows the parent, and active extension/SDK tools are
543
+ appended as described above. Omitting `tools` inherits the parent's complete
544
+ active set.
462
545
 
463
546
  ## Development
464
547
 
@@ -468,14 +551,11 @@ npm run check
468
551
  npm test
469
552
  ```
470
553
 
471
- The source is modular: `dispatch.ts` (public dispatch contract + auto-fix),
472
- `thread-lifecycle.ts` (queued generations, resume/fork, and isolation settlement),
473
- `rpc-run.ts` / `spawn.ts` (persistent child transport + selected→main handoff),
474
- `worktree.ts` / `session-fork.ts` (filesystem/session branching), `tools.ts`
475
- (wait/status/control/stop), `widget.ts` (active-only TUI status), `announcements.ts`
476
- (recovery and feature notices), and `runtime.ts` (session-scoped ownership). No runtime
477
- dependencies beyond pi peer dependencies.
554
+ The package has no bundled runtime dependencies; it uses pi and TypeBox as peer
555
+ packages. Source is split by responsibility: managed dispatch/workflow policy,
556
+ retained thread lifecycle, RPC transport, worktree integration, completion
557
+ delivery, tools, and TUI status.
478
558
 
479
559
  ## License
480
560
 
481
- MIT
561
+ [MIT](./LICENSE)