@ferris1225/pi-subagents 4.1.2 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,506 +1,584 @@
1
- # pi-subagents
2
-
3
- [![npm version](https://img.shields.io/npm/v/@ferris1225/pi-subagents?color=blue)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
4
- [![downloads](https://img.shields.io/npm/dm/@ferris1225/pi-subagents)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
5
- [![license](https://img.shields.io/npm/l/@ferris1225/pi-subagents)](./LICENSE)
6
- ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
- ![pi](https://img.shields.io/badge/pi-extension-orange)
8
-
9
- ## 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.
21
-
22
- ```text
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 documenterreviewer
32
-
33
- The stable parent run returns one final result when the complete workflow settles.
34
- ```
35
-
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**.
78
-
79
- ```bash
80
- pi install npm:@ferris1225/pi-subagents
81
- ```
82
-
83
- Open pi and run the setup wizard:
84
-
85
- ```text
86
- /subagents-setup
87
- ```
88
-
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.
93
-
94
- Then ask for work in plain language:
95
-
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
133
-
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.
139
-
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.
144
-
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
- ## Everyday workflows
160
-
161
- ### Delegate one task
162
-
163
- ```ts
164
- subagent({
165
- agent: "explorer",
166
- task: "Map the test setup. Report exact files, commands, and CI entry points.",
167
- });
168
- ```
169
-
170
- ```ts
171
- subagent({
172
- agent: "worker",
173
- task: "Fix the cache invalidation bug in src/cache, add regression tests, and run the relevant checks.",
174
- });
175
- ```
176
-
177
- ### Fan out independent work
178
-
179
- ```ts
180
- subagent({
181
- tasks: [
182
- { agent: "explorer", task: "Trace model fallback from dispatch to completion." },
183
- { agent: "worker", task: "Add edge-case tests for config migration." },
184
- ],
185
- });
186
- ```
187
-
188
- Independent tasks run up to `maxConcurrency` (default `4`). One parallel call may
189
- contain at most that many tasks and is rejected if it exceeds the limit. Accepted
190
- background work from separate calls waits in the shared queue when all slots are
191
- busy.
192
-
193
- ### Run an independent quality gate
194
-
195
- ```ts
196
- subagent({
197
- agent: "reviewer",
198
- task: "Gate the current diff for correctness, regressions, and missing tests.",
199
- });
200
- ```
201
-
202
- A gate reviewer ends with `REVIEW_PASS` or `REVIEW_FAIL`. A direct pass is not
203
- accepted as the final gate while `documenter` is enabled: runtime first syncs the
204
- actual pending diff, then starts a fresh reviewer. A failure uses the bounded loop:
205
-
206
- ```text
207
- reviewer worker fixes every open finding → optional documenter sync → reviewer checks again → PASS/FAIL
208
- ```
209
-
210
- Each step gets a fresh model context. The chain shares the same code state and
211
- passes every full reviewer, worker, and documenter report forward; it does not
212
- reuse one context window. Internal children bypass top-level lifecycle policy, so
213
- they cannot recursively start another chain.
214
-
215
- `maxFixRounds` limits worker fix attempts only. Initial post-writer documentation
216
- and final review still run when it is `0`. Generic audits and read-only reviews
217
- are advisory: they omit `VERDICT`, remain read-only, and never trigger edits.
218
-
219
- ### Clean up without guessing
220
-
221
- `cleaner` is only for requests that authorize cleanup edits. Once dispatched,
222
- that authorization covers every safe, proven in-scope cut without another
223
- item-by-item confirmation. It checks reachability, ownership, history, and
224
- boundaries before removing, simplifying, or consolidating anything, then verifies
225
- the result.
226
-
227
- Repeated code is a first-class cleanup target. Cleaner compares contracts,
228
- invariants, side effects, ownership, and reasons to change—not just matching
229
- text—then extracts the smallest stable shared implementation and migrates all
230
- in-scope callers. It keeps similar code separate when domains or future change
231
- axes genuinely differ, avoiding a generic abstraction that is worse than the
232
- duplication.
233
-
234
- ```text
235
- explicit cleanup request cleaner applies proven cuts documenter syncs docs reviewer gates the diff
236
- read-only cleanup audit → reviewer reports candidates only
237
- ```
238
-
239
- This separation matters: asking for an audit does not silently authorize code
240
- changes, and asking for cleanup does not reward speculative deletion.
241
-
242
- ### Keep comments and README/docs synchronized
243
-
244
- `documenter` has two deliberate launch paths.
245
-
246
- **For a pending worker or cleaner change**, enable the role. Runtime schedules it
247
- automatically against the actual diff before the final reviewer; do not dispatch
248
- a duplicate manual sync. If reviewer is disabled, documenter becomes the final
249
- managed stage. If documenter is disabled, reviewer follows the writer directly.
250
-
251
- **For an existing project**, explicitly authorize a broad maintenance pass:
252
-
253
- ```ts
254
- subagent({
255
- agent: "documenter",
256
- 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.",
257
- });
258
- ```
259
-
260
- A successful explicit whole-codebase documenter also continues automatically to
261
- reviewer when enabled. A generic or read-only documentation audit still belongs
262
- to `reviewer`. `documenter` is the last writer, never the approver:
263
-
264
- ```text
265
- worker / cleaner / documenter / auto-fix worker enabled downstream roles one final delivery
266
- ```
267
-
268
- ## Safe parallel editing
269
-
270
- A Git worktree is a temporary second checkout of the same repository. It shares
271
- Git history with your main checkout but has its own files, so two workers do not
272
- overwrite each other while they run.
273
-
274
- Every child has process and context isolation. Write-capable tasks can also have
275
- filesystem isolation:
276
-
277
- - A single task defaults to `isolation: "shared"`.
278
- - Parallel `worker` tasks default to `isolation: "worktree"`.
279
- - `cleaner` and `documenter` support worktree mode when explicitly requested;
280
- their default remains shared.
281
- - Read-only `explorer` and `reviewer` tasks reject worktree mode because they do
282
- not need a writable checkout.
283
-
284
- Worktree mode requires a Git repository with a committed `HEAD`. For an isolated
285
- writer, automatic documenter/reviewer children run inside that same worktree.
286
- Those isolated stages can still run in parallel; writer and documentation changes
287
- are integrated only after the final reviewer settles. Tracked, deleted, untracked,
288
- and binary changes are then carried back to the original checkout without staging
289
- or modifying the parent index.
290
-
291
- Repository-lane discovery uses the Git top-level even in an empty repository, so
292
- root and nested paths share one lane before the first commit. Every shared
293
- `worker`, `cleaner`, and `documenter` writer—and each shared `reviewer` snapshot
294
- when managed writers are enabled—uses that lane. Standalone documentation,
295
- writer-only configurations, and workflows without reviewer cannot race another
296
- writer or documentation sync. Isolated agents keep doing model work in parallel,
297
- but their final apply waits for the same lane.
298
-
299
- Normal completion, stop, and shutdown share one finalization result, so isolated
300
- state is applied at most once. If park, stop, or shutdown wins after the top-level
301
- child settles, no downstream role starts and the stable top-level session remains
302
- the checkpoint. If setup or integration fails, pi-subagents keeps the useful
303
- patch or worktree when possible and records recovery information in:
304
-
305
- ```text
306
- ~/.pi/agent/pi-subagents-recovery.json
307
- ```
308
-
309
- A parked isolated thread keeps its worktree. Resume continues there. Forking an
310
- isolated checkpoint is available after that checkpoint has settled and integrated.
311
-
312
- ## Follow, redirect, or stop a run
313
-
314
- Dispatch confirmations and completion messages include a stable `#id`. That
315
- parent id represents the whole managed workflow; each internal documenter,
316
- reviewer, and fix step gets a separate queryable id in the final summary. No
317
- internal completion wakes the main agent.
318
-
319
- | Tool | What it does |
320
- | --- | --- |
321
- | `subagent_control` | `steer`, `retarget`, `park`, `resume`, or `fork` a logical thread. |
322
- | `subagent_status` | Show active and recent runs, or return the full result for one id. |
323
- | `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. |
324
- | `subagent_stop` | Destructively cancel work, deliver partial output, and retire that thread's retained session. Independent forks survive. |
325
-
326
- ```ts
327
- subagent_control({ action: "steer", id: 7, instruction: "Check the Windows path too." });
328
- subagent_control({ action: "park", id: 7 });
329
- subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
330
- subagent_control({ action: "fork", id: 7, objective: "Try the smaller design instead." });
331
- ```
332
-
333
- Use `steer` or `retarget` only while the top-level RPC child is active. During an
334
- automatic documenter, reviewer, or fix stage, use `park` or `stop`; park and then
335
- `resume` with a new objective when you need to redirect retained context. Use
336
- `park` to preserve the newest active stage and release its process slot; parking
337
- during documentation retains the
338
- documenter's partial/session, not an older writer or review. Use `stop` only when
339
- you want to discard that thread's future continuation. Stop and session shutdown
340
- abort the active internal stage, suppress stale delivery, and leave worktree
341
- finalization to the same one-time lifecycle owner. `stop-all` interrupts every
342
- lane holder before waiting for finalization, avoiding self-deadlock when an
343
- isolated apply is queued behind shared work.
344
-
345
- ## Results and live status
346
-
347
- The active TUI widget shows queued and running work as a compact tree:
348
-
349
- ```text
350
- reviewer · review diff of src/cache.ts · claude-sonnet-4-5/high · 42s
351
- worker · fix round 1 · src/cache.ts · claude-sonnet-4-5/high · 10s
352
- │ grep cacheKey
353
- documenter · docs round 1 · claude-haiku-4-5/low · 4s
354
- └ ○ reviewer · re-review round 1 · claude-sonnet-4-5/high · 3s
355
- ```
356
-
357
- Completed internal rows disappear from the widget; a parked parent remains
358
- queryable. Final messages contain one managed-workflow summary with aggregate
359
- token/cost totals and every internal id. Long output is truncated in the
360
- conversation and written to a temporary Markdown artifact; `subagent_status`
361
- keeps each complete run report available by id.
362
-
363
- The main agent is told not to paraphrase a result you have already seen. It should
364
- add only its own conclusion or next action instead of charging you twice for the
365
- same explanation.
366
-
367
- ## Models, thinking, and image work
368
-
369
- Each agent can use the current main model or one selected in `/subagents-setup`.
370
- The setup picker shows authenticated models and labels them `vision` or
371
- `text-only`.
372
-
373
- ```text
374
- selected agent model current main model
375
- ```
376
-
377
- If the selected model is missing, unavailable, rate-limited, out of quota, or
378
- fails at the provider level, the current main model continues the same retained
379
- session. Searches, reads, reasoning, and edits already completed are preserved.
380
- Ordinary tool and test failures remain task failures and do not trigger a model
381
- handoff.
382
-
383
- Thinking defaults to **Auto**. pi-subagents starts from the role's preference and
384
- chooses only a level the effective model actually supports. A fallback re-checks
385
- the level for the main model. `documenter` deliberately ships with the same fast,
386
- low-thinking profile as `explorer`; migration and manual enablement copy any
387
- configured explorer route, and you can still override it independently.
388
-
389
- There is no separate vision mode. Assign a multimodal model to the agent and name
390
- the image paths in the task:
391
-
392
- ```ts
393
- subagent({
394
- agent: "reviewer",
395
- task: "Compare screenshots/settings.png with design.png and list every visual mismatch.",
396
- });
397
- ```
398
-
399
- ## Reliability without duplicate work
400
-
401
- - **Startup recovery:** silent, zero-activity failures before prompt dispatch
402
- retry with extended jittered backoff. A dispatched prompt is never replayed,
403
- even when its ACK is lost.
404
- - **Idle watchdog:** a run with no RPC output for `idleTimeoutSec` is terminated;
405
- selected-model failures can continue on the current main model.
406
- - **Retained context:** model handoff, park/resume, retarget, and fork build on the
407
- same session history instead of repeating discovery.
408
- - **Visible failures:** process crashes, partial parallel starts, model failures,
409
- and Git integration failures are returned as failures rather than silent hangs.
410
- - **Safe status text:** live tool activity is credential-redacted and stripped of
411
- terminal control characters.
412
- - **No runaway trees:** child processes are leaves; they cannot dispatch more
413
- sub-agents.
414
-
415
- ## Configuration
416
-
417
- The wizard covers enabled agents, per-agent models and thinking, concurrency,
418
- auto-fix rounds, and the idle timeout:
419
-
420
- ```text
421
- /subagents-setup
422
- ```
423
-
424
- Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
425
- `PI_CODING_AGENT_DIR` when that environment variable is set.
426
-
427
- ```json
428
- {
429
- "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
430
- "agentModels": {
431
- "explorer": "anthropic/claude-haiku-4-5",
432
- "documenter": "anthropic/claude-haiku-4-5"
433
- },
434
- "agentThinkingLevels": {
435
- "documenter": "low",
436
- "reviewer": "high"
437
- },
438
- "notifyOnReviewPass": false,
439
- "maxResultLines": 80,
440
- "proactiveInjection": true,
441
- "agentScope": "user",
442
- "maxConcurrency": 4,
443
- "maxFixRounds": 2,
444
- "idleTimeoutSec": 90
445
- }
446
- ```
447
-
448
- | Field | Meaning |
449
- | --- | --- |
450
- | `enabledAgents` | Agent names available for discovery and delegation. `[]` disables all agents. |
451
- | `agentModels` | Optional `provider/model-id` per agent. Missing means use the current main model. |
452
- | `agentThinkingLevels` | Optional manual level per agent. Missing means Auto. |
453
- | `notifyOnReviewPass` | When `true`, a standalone passing gate is delivered without waking the main agent. Managed workflows still wake once at final delivery. Default `false`. |
454
- | `maxResultLines` | Lines kept in a completion message before the full result moves to a temporary artifact. Default `80`. |
455
- | `proactiveInjection` | Teach the main model when and how to delegate. Default `true`. |
456
- | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
457
- | `maxConcurrency` | Running process limit and maximum tasks in one parallel call, from `1` to `16`. Default `4`. |
458
- | `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`. |
459
- | `idleTimeoutSec` | Seconds without RPC output before termination. `0` disables the watchdog. Default `90`. |
460
-
461
- Invalid values fall back safely. Older configs are normalized automatically. The
462
- former built-in name `explore` migrates to `explorer`, and pre-cleaner non-empty
463
- agent lists receive `cleaner` once. Existing non-empty configs also receive
464
- `documenter` once, inserted before `reviewer`, with any configured `explorer`
465
- model and thinking copied across. Fresh installs do not enable `documenter`
466
- until the user selects it. Later deliberate disables are respected.
467
-
468
- ## Custom and overridden agents
469
-
470
- Built-ins ship in the package. You can add or replace agents with Markdown files:
471
-
472
- - User agents: `~/.pi/agent/agents/`
473
- - Project agents: nearest `.pi/agents/` directory in a trusted project
474
- - Precedence: project overrides user, user overrides built-in
475
-
476
- To replace a built-in, use the same filename and `name`. Optional frontmatter:
477
-
478
- ```yaml
479
- ---
480
- name: explorer
481
- description: Fast read-only codebase reconnaissance
482
- model: anthropic/claude-haiku-4-5
483
- thinking: low
484
- tools: read, bash
485
- ---
486
- ```
487
-
488
- The Markdown body becomes the child's additional system prompt. Configuration
489
- chosen in `/subagents-setup` takes precedence over frontmatter defaults.
490
-
491
- ## Development
492
-
493
- ```bash
494
- npm install
495
- npm run check
496
- npm test
497
- ```
498
-
499
- The package has no bundled runtime dependencies; it uses pi and TypeBox as peer
500
- packages. Source is split by responsibility: managed dispatch/workflow policy,
501
- retained thread lifecycle, RPC transport, worktree integration, completion
502
- delivery, tools, and TUI status.
503
-
504
- ## License
505
-
506
- [MIT](./LICENSE)
1
+ # pi-subagents
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@ferris1225/pi-subagents?color=blue)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
4
+ [![downloads](https://img.shields.io/npm/dm/@ferris1225/pi-subagents)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
5
+ [![license](https://img.shields.io/npm/l/@ferris1225/pi-subagents)](./LICENSE)
6
+ ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
+ ![pi](https://img.shields.io/badge/pi-extension-orange)
8
+
9
+ ## 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.
21
+
22
+ ```text
23
+ You
24
+ └─ pi main agent
25
+ ├─ explorer ─── maps the codebase
26
+ ├─ worker ───── implements ─┬─▶ reviewer ─▶ documenter
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 → final documentation sync
31
+ └─ REVIEW_FAIL → worker → reviewer (fix rounds) final docs
32
+
33
+ The stable parent run returns one final result when the complete workflow settles.
34
+ ```
35
+
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
+ once after the review gate settles after successful workers/cleaners or
53
+ fix rounds, never per fix round. It can also run an explicitly requested
54
+ whole-codebase maintenance pass.
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
+ one final documentation sync follows the settled chain.
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 | Automatic writer → reviewer → documenter delivery and bounded fix rounds |
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 |
75
+
76
+ ## Quick start
77
+
78
+ Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
79
+
80
+ ```bash
81
+ pi install npm:@ferris1225/pi-subagents
82
+ ```
83
+
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:
96
+
97
+ ```text
98
+ Map how authentication works, fix the refresh race, run the tests, and review the diff.
99
+ ```
100
+
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
+ ```
108
+
109
+ The main agent decides when delegation is useful. You can also call the tools
110
+ explicitly when you want exact control.
111
+
112
+ ## What changed in 4.1.4
113
+
114
+ ### Documentation sync moved after the review gate
115
+
116
+ `documenter` now runs once at the end of a managed chain instead of before the
117
+ reviewer and once per fix round:
118
+
119
+ ```text
120
+ before: worker documenter reviewer (worker documenter → reviewer) × N
121
+ after: worker reviewer (worker reviewer) × N documenter
122
+ ```
123
+
124
+ Code fixes no longer invalidate a docs pass written moments earlier, fix rounds
125
+ stop paying for documenter runs and re-reviewing their churn, and a direct
126
+ passing gate gets one final documentation sync instead of a second full review.
127
+ Gate reviewers record documentation drift as non-gating `## Documentation notes`
128
+ that the final documenter applies; when `documenter` is disabled, drift stays a
129
+ normal gate finding. The sync is skipped when a chain ends on a failing gate.
130
+
131
+ ## What changed in 4.1.2
132
+
133
+ ### Documentation sync as a real workflow stage
134
+
135
+ The new `documenter` is a write-capable, explorer-class role with two modes:
136
+
137
+ 1. **Pre-commit diff sync** after the last code edit and before the final
138
+ reviewer, it compares the actual diff with comments, README/docs, examples,
139
+ commands, config, defaults, and lifecycle descriptions.
140
+ 2. **Whole-codebase maintenance** when explicitly requested, it scans an
141
+ existing project for stale comments and documentation and applies every safe,
142
+ verified correction in scope.
143
+
144
+ It never changes runtime behavior, commits, pushes, publishes, or bumps versions.
145
+ When enabled, runtime now treats it as a managed stage: successful top-level
146
+ `worker`/`cleaner` runs continue through `documenter → reviewer`, a successful
147
+ whole-codebase `documenter` continues through reviewer, and auto-fix rounds use
148
+ `worker documenter reviewer`. Existing non-empty configs receive `documenter`
149
+ once and inherit the configured `explorer` model and thinking level; fresh
150
+ installs leave it as an explicit setup choice.
151
+
152
+ ### Safer startup contention recovery
153
+
154
+ Startup contention is much harder to exhaust. A child that exits or fails its RPC
155
+ readiness handshake before the initial prompt is dispatched is retried through a
156
+ longer backoff window. Each default delay also gets additive jitter, reducing the
157
+ chance that several children retry in the same lockstep waves. The base window
158
+ covers stale startup locks and leaves headroom beyond the default four-way fan-out.
159
+
160
+ Only a failure known to precede prompt dispatch qualifies. Once the parent sends a
161
+ prompt command, pi-subagents will not replay it—even if the ACK is lost or an idle
162
+ watchdog wins the race—because Pi may already have started the model or tools.
163
+ This recovery therefore cannot repeat model calls or edits.
164
+
165
+ ## Meet the team
166
+
167
+ | Agent | Access | Best for |
168
+ | --- | --- | --- |
169
+ | `explorer` | Read-only | Broad codebase search, unfamiliar-area mapping, symbol and dependency tracing, and multi-file reconnaissance. |
170
+ | `worker` | Full | A self-contained implementation, bug fix, refactor, or test task carried through verification. |
171
+ | `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, and duplicate-code consolidation. Dispatch authorizes every safe in-scope cut; it must prove each one. |
172
+ | `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. |
173
+ | `reviewer` | Read-only | Audits, code-health checks, plans, PR or issue validation, documentation-drift checks, and fresh pre-commit gates. |
174
+
175
+ Children have no memory of the parent conversation. A good manual brief includes
176
+ the goal, exact paths, constraints, and expected output. The injected delegation
177
+ guidance does this automatically when the main agent dispatches on your behalf.
178
+
179
+ ### Tool, plugin, skill, and context inheritance
180
+
181
+ Every initial dispatch, managed stage, retained resume, fork, startup retry,
182
+ and selected-to-main fallback snapshots the parent session's currently active
183
+ tools. Roles without an explicit tool list (such as shipped `worker` and
184
+ `cleaner`) inherit that complete set. An explicit role list remains its Pi
185
+ built-in permission boundary, but its existing shell slot follows the parent
186
+ (`bash`, `powershell`, both, or neither) and parent-active extension/SDK tools
187
+ are appended; inactive plugin names declared in frontmatter are not enabled.
188
+ Therefore `explorer` and `reviewer` never gain Pi's built-in `edit`/`write`;
189
+ `documenter` keeps them for docs/comments; and a custom agent keeps the built-in
190
+ capabilities declared in its own frontmatter. All `subagent*` control tools are
191
+ removed from children so they remain leaves. An empty inherited snapshot starts
192
+ the child with `--no-tools` instead of falling back to Pi's defaults.
193
+
194
+ `powershell` is the Pi tool name. On Windows, it selects native `pwsh.exe` when
195
+ available and falls back to `powershell.exe`. Parent-active plugin tools such as
196
+ web search or API/documentation lookup are available to every child when that
197
+ plugin also loads there. Global skills and trusted project skills load normally
198
+ inside each child Pi process.
199
+
200
+ Each child is an independent Pi session and uses Pi's normal global/project
201
+ `compaction` settings. Auto-compaction therefore remains enabled by default when
202
+ a child's model context approaches its limit. Retained resume/fork sessions keep
203
+ their existing conversation and compaction summaries instead of starting over.
204
+
205
+ ## Everyday workflows
206
+
207
+ ### Delegate one task
208
+
209
+ ```ts
210
+ subagent({
211
+ agent: "explorer",
212
+ task: "Map the test setup. Report exact files, commands, and CI entry points.",
213
+ });
214
+ ```
215
+
216
+ ```ts
217
+ subagent({
218
+ agent: "worker",
219
+ task: "Fix the cache invalidation bug in src/cache, add regression tests, and run the relevant checks.",
220
+ });
221
+ ```
222
+
223
+ ### Fan out independent work
224
+
225
+ ```ts
226
+ subagent({
227
+ tasks: [
228
+ { agent: "explorer", task: "Trace model fallback from dispatch to completion." },
229
+ { agent: "worker", task: "Add edge-case tests for config migration." },
230
+ ],
231
+ });
232
+ ```
233
+
234
+ Independent tasks run up to `maxConcurrency` (default `4`). One parallel call may
235
+ contain at most that many tasks and is rejected if it exceeds the limit. Accepted
236
+ background work from separate calls waits in the shared queue when all slots are
237
+ busy.
238
+
239
+ ### Run an independent quality gate
240
+
241
+ ```ts
242
+ subagent({
243
+ agent: "reviewer",
244
+ task: "Gate the current diff for correctness, regressions, and missing tests.",
245
+ });
246
+ ```
247
+
248
+ A gate reviewer ends with `REVIEW_PASS` or `REVIEW_FAIL`. A direct pass is
249
+ final for the code: runtime runs the final documentation sync once (when
250
+ `documenter` is enabled) and delivers. A failure uses the bounded loop:
251
+
252
+ ```text
253
+ reviewer → worker fixes every open finding → reviewer checks again → … → final documentation sync
254
+ ```
255
+
256
+ Each step gets a fresh model context. The chain shares the same code state and
257
+ passes every full reviewer and worker report forward; it does not reuse one
258
+ context window. Internal children bypass top-level lifecycle policy, so they
259
+ cannot recursively start another chain. Gate reviewers keep documentation drift
260
+ out of the verdict while `documenter` is enabled by recording it as
261
+ `## Documentation notes` for the final documenter.
262
+
263
+ `maxFixRounds` limits worker fix attempts only. The post-writer review gate and
264
+ the final documentation sync still run when it is `0`. Generic audits and
265
+ read-only reviews are advisory: they omit `VERDICT`, remain read-only, and
266
+ never trigger edits.
267
+
268
+ ### Clean up without guessing
269
+
270
+ `cleaner` is only for requests that authorize cleanup edits. Once dispatched,
271
+ that authorization covers every safe, proven in-scope cut without another
272
+ item-by-item confirmation. It checks reachability, ownership, history, and
273
+ boundaries before removing, simplifying, or consolidating anything, then verifies
274
+ the result.
275
+
276
+ Repeated code is a first-class cleanup target. Cleaner compares contracts,
277
+ invariants, side effects, ownership, and reasons to change—not just matching
278
+ text—then extracts the smallest stable shared implementation and migrates all
279
+ in-scope callers. It keeps similar code separate when domains or future change
280
+ axes genuinely differ, avoiding a generic abstraction that is worse than the
281
+ duplication.
282
+
283
+ ```text
284
+ explicit cleanup request cleaner applies proven cuts reviewer gates the diff → documenter syncs docs
285
+ read-only cleanup audit → reviewer reports candidates only
286
+ ```
287
+
288
+ This separation matters: asking for an audit does not silently authorize code
289
+ changes, and asking for cleanup does not reward speculative deletion.
290
+
291
+ ### Keep comments and README/docs synchronized
292
+
293
+ `documenter` has two deliberate launch paths.
294
+
295
+ **For a pending worker or cleaner change**, enable the role. Runtime schedules
296
+ one final sync automatically against the actual diff after the review gate
297
+ settles; do not dispatch a duplicate manual sync. If reviewer is disabled,
298
+ documenter becomes the final managed stage directly after the writer. If
299
+ documenter is disabled, reviewer follows the writer directly.
300
+
301
+ **For an existing project**, explicitly authorize a broad maintenance pass:
302
+
303
+ ```ts
304
+ subagent({
305
+ agent: "documenter",
306
+ 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.",
307
+ });
308
+ ```
309
+
310
+ A successful explicit whole-codebase documenter also continues automatically to
311
+ reviewer when enabled. A generic or read-only documentation audit still belongs
312
+ to `reviewer`. `documenter` is the last writer, never the approver:
313
+
314
+ ```text
315
+ worker / cleaner / documenter / auto-fix worker enabled downstream roles → one final delivery
316
+ ```
317
+
318
+ ## Safe parallel editing
319
+
320
+ A Git worktree is a temporary second checkout of the same repository. It shares
321
+ Git history with your main checkout but has its own files, so two workers do not
322
+ overwrite each other while they run.
323
+
324
+ Every child has process and context isolation. Write-capable tasks can also have
325
+ filesystem isolation:
326
+
327
+ - A single task defaults to `isolation: "shared"`.
328
+ - Parallel `worker` tasks default to `isolation: "worktree"`.
329
+ - `cleaner` and `documenter` support worktree mode when explicitly requested;
330
+ their default remains shared.
331
+ - Read-only `explorer` and `reviewer` tasks reject worktree mode because they do
332
+ not need a writable checkout.
333
+
334
+ Worktree mode requires a Git repository with a committed `HEAD`. For an isolated
335
+ writer, automatic reviewer/documenter children run inside that same worktree.
336
+ Those isolated stages can still run in parallel; writer, fix, and documentation
337
+ changes are integrated only after the final managed stage settles. Tracked,
338
+ deleted, untracked, and binary changes are then carried back to the original
339
+ checkout without staging or modifying the parent index.
340
+
341
+ Repository-lane discovery uses the Git top-level even in an empty repository, so
342
+ root and nested paths share one lane before the first commit. Every shared
343
+ `worker`, `cleaner`, and `documenter` writer—and each shared `reviewer` snapshot
344
+ when managed writers are enabled—uses that lane. Standalone documentation,
345
+ writer-only configurations, and workflows without reviewer cannot race another
346
+ writer or documentation sync. Isolated agents keep doing model work in parallel,
347
+ but their final apply waits for the same lane.
348
+
349
+ Normal completion, stop, and shutdown share one finalization result, so isolated
350
+ state is applied at most once. If park, stop, or shutdown wins after the top-level
351
+ child settles, no downstream role starts and the stable top-level session remains
352
+ the checkpoint. If setup or integration fails, pi-subagents keeps the useful
353
+ patch or worktree when possible and records recovery information in:
354
+
355
+ ```text
356
+ ~/.pi/agent/pi-subagents-recovery.json
357
+ ```
358
+
359
+ A parked isolated thread keeps its worktree. Resume continues there. Forking an
360
+ isolated checkpoint is available after that checkpoint has settled and integrated.
361
+
362
+ ## Follow, redirect, or stop a run
363
+
364
+ Dispatch confirmations and completion messages include a stable `#id`. That
365
+ parent id represents the whole managed workflow; each internal documenter,
366
+ reviewer, and fix step gets a separate queryable id in the final summary. No
367
+ internal completion wakes the main agent.
368
+
369
+ | Tool | What it does |
370
+ | --- | --- |
371
+ | `subagent_control` | `steer`, `retarget`, `park`, `resume`, or `fork` a logical thread. |
372
+ | `subagent_status` | Show active and recent runs, or return the full result for one id. |
373
+ | `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. |
374
+ | `subagent_stop` | Destructively cancel work, deliver partial output, and retire that thread's retained session. Independent forks survive. |
375
+
376
+ ```ts
377
+ subagent_control({ action: "steer", id: 7, instruction: "Check the Windows path too." });
378
+ subagent_control({ action: "park", id: 7 });
379
+ subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
380
+ subagent_control({ action: "fork", id: 7, objective: "Try the smaller design instead." });
381
+ ```
382
+
383
+ Use `steer` or `retarget` only while the top-level RPC child is active. `steer`
384
+ queues guidance without changing the displayed objective; `retarget` aborts that
385
+ generation's objective and replaces it in the same session. During an automatic
386
+ documenter, reviewer, or fix stage, use `park` or `stop`. `resume` without an
387
+ `objective` continues the currently displayed goal; supplying one appends that
388
+ explicit goal to the retained conversation and makes it the new displayed goal.
389
+ It never clears prior context. `fork` follows the same objective rule on a copied
390
+ branch while leaving its source unchanged. Widget labels distinguish retained,
391
+ appended, retargeted, and forked objectives.
392
+
393
+ Use `park` to preserve the newest active stage and release its process slot;
394
+ parking during documentation retains the documenter's partial/session, not an
395
+ older writer or review. A resumed logical run keeps cumulative active elapsed
396
+ time across all generations while excluding the parked interval. Use `stop` only
397
+ when you want to discard that thread's future continuation. Stop and session
398
+ shutdown abort the active internal stage, suppress stale delivery, and leave
399
+ worktree finalization to the same one-time lifecycle owner. `stop-all` interrupts
400
+ every lane holder before waiting for finalization, avoiding self-deadlock when an
401
+ isolated apply is queued behind shared work.
402
+
403
+ ## Results and live status
404
+
405
+ The active TUI widget shows queued and running work as a compact tree:
406
+
407
+ ```text
408
+ reviewer workflow · review diff of src/cache.ts · 42s
409
+ worker · fix round 1 · src/cache.ts · claude-sonnet-4-5/high · 10s
410
+ │ grep cacheKey
411
+ documenter · final documentation sync · claude-haiku-4-5/low · 3s
412
+ ```
413
+
414
+ A managed root keeps its original top-level role and workflow-wide elapsed
415
+ time, but deliberately omits model/thinking because several model stages own
416
+ that row over its lifetime. The active nested row shows the current stage's
417
+ actual role, selected/fallback model, thinking level, stage elapsed time, and
418
+ activity. Per-stage usage stays attached to that stage; only the final summary
419
+ is labeled and calculated as an aggregate.
420
+
421
+ Completed internal rows disappear from the widget; a parked parent remains
422
+ queryable. Final messages contain one managed-workflow summary with aggregate
423
+ token/cost totals and every internal id. Built-in roles author their own
424
+ result-only handoff—outcome, relevant paths, verification, and unresolved
425
+ blockers—without a second summarization layer that could distort the result.
426
+ They omit task/process narration and recovered transient tool failures. The
427
+ 80-line delivery cap remains a safety limit; long output is written unchanged to
428
+ a temporary Markdown artifact, and explicit `subagent_status` lookup keeps the
429
+ complete report and failed-tool diagnostics available by id.
430
+
431
+ The main agent is told not to paraphrase a result you have already seen. It should
432
+ add only its own conclusion or next action instead of charging you twice for the
433
+ same explanation.
434
+
435
+ ## Models, thinking, and image work
436
+
437
+ Each agent can use the current main model or one selected in `/subagents-setup`.
438
+ The setup picker shows authenticated models and labels them `vision` or
439
+ `text-only`.
440
+
441
+ ```text
442
+ selected agent model → current main model
443
+ ```
444
+
445
+ If the selected model is missing, unavailable, rate-limited, out of quota, or
446
+ fails at the provider level, the current main model continues the same retained
447
+ session. Searches, reads, reasoning, and edits already completed are preserved.
448
+ Ordinary tool and test failures remain task failures and do not trigger a model
449
+ handoff.
450
+
451
+ Thinking defaults to **Auto**. pi-subagents starts from the role's preference and
452
+ chooses only a level the effective model actually supports. A fallback re-checks
453
+ the level for the main model. `documenter` deliberately ships with the same fast,
454
+ low-thinking profile as `explorer`; migration and manual enablement copy any
455
+ configured explorer route, and you can still override it independently.
456
+
457
+ There is no separate vision mode. Assign a multimodal model to the agent and name
458
+ the image paths in the task:
459
+
460
+ ```ts
461
+ subagent({
462
+ agent: "reviewer",
463
+ task: "Compare screenshots/settings.png with design.png and list every visual mismatch.",
464
+ });
465
+ ```
466
+
467
+ ## Reliability without duplicate work
468
+
469
+ - **Startup recovery:** silent, zero-activity failures before prompt dispatch
470
+ retry with extended jittered backoff. A dispatched prompt is never replayed,
471
+ even when its ACK is lost.
472
+ - **Idle watchdog:** a run with no RPC output for `idleTimeoutSec` is terminated;
473
+ selected-model failures can continue on the current main model.
474
+ - **Retained context:** model handoff, park/resume, retarget, and fork build on the
475
+ same session history instead of repeating discovery.
476
+ - **Visible failures:** process crashes, partial parallel starts, model failures,
477
+ and Git integration failures are returned as failures rather than silent hangs.
478
+ - **Safe status text:** live tool activity is credential-redacted and stripped of
479
+ terminal control characters.
480
+ - **No runaway trees:** child processes are leaves; they cannot dispatch more
481
+ sub-agents.
482
+
483
+ ## Configuration
484
+
485
+ The wizard covers enabled agents, per-agent models and thinking, concurrency,
486
+ auto-fix rounds, and the idle timeout:
487
+
488
+ ```text
489
+ /subagents-setup
490
+ ```
491
+
492
+ In nested setup screens, `Esc` returns one level: thinking → model → agent
493
+ selection → settings. Runtime value pickers return to the Runtime settings menu,
494
+ and other nested pickers return to the main settings menu. Only `Esc` from the
495
+ top-level settings menu exits the wizard; completed agent choices are saved when
496
+ leaving that configuration pass.
497
+
498
+ Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
499
+ `PI_CODING_AGENT_DIR` when that environment variable is set.
500
+
501
+ ```json
502
+ {
503
+ "enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
504
+ "agentModels": {
505
+ "explorer": "anthropic/claude-haiku-4-5",
506
+ "documenter": "anthropic/claude-haiku-4-5"
507
+ },
508
+ "agentThinkingLevels": {
509
+ "documenter": "low",
510
+ "reviewer": "high"
511
+ },
512
+ "notifyOnReviewPass": false,
513
+ "maxResultLines": 80,
514
+ "proactiveInjection": true,
515
+ "agentScope": "user",
516
+ "maxConcurrency": 4,
517
+ "maxFixRounds": 2,
518
+ "idleTimeoutSec": 90
519
+ }
520
+ ```
521
+
522
+ | Field | Meaning |
523
+ | --- | --- |
524
+ | `enabledAgents` | Agent names available for discovery and delegation. `[]` disables all agents. |
525
+ | `agentModels` | Optional `provider/model-id` per agent. Missing means use the current main model. |
526
+ | `agentThinkingLevels` | Optional manual level per agent. Missing means Auto. |
527
+ | `notifyOnReviewPass` | When `true`, a standalone passing gate is delivered without waking the main agent. Managed workflows still wake once at final delivery. Default `false`. |
528
+ | `maxResultLines` | Lines kept in a completion message before the full result moves to a temporary artifact. Default `80`. |
529
+ | `proactiveInjection` | Teach the main model when and how to delegate. Default `true`. |
530
+ | `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
531
+ | `maxConcurrency` | Running process limit and maximum tasks in one parallel call, from `1` to `16`. Default `4`. |
532
+ | `maxFixRounds` | Maximum worker fixes after `REVIEW_FAIL`; each fix is re-reviewed by a reviewer, and one final documentation sync runs after the chain settles. `0` disables fixes but not the post-writer review gate or final docs. Default `2`. |
533
+ | `idleTimeoutSec` | Seconds without RPC output before termination. `0` disables the watchdog. Default `90`. |
534
+
535
+ Invalid values fall back safely. Older configs are normalized automatically. The
536
+ former built-in name `explore` migrates to `explorer`, and pre-cleaner non-empty
537
+ agent lists receive `cleaner` once. Existing non-empty configs also receive
538
+ `documenter` once, inserted before `reviewer`, with any configured `explorer`
539
+ model and thinking copied across. Fresh installs do not enable `documenter`
540
+ until the user selects it. Later deliberate disables are respected.
541
+
542
+ ## Custom and overridden agents
543
+
544
+ Built-ins ship in the package. You can add or replace agents with Markdown files:
545
+
546
+ - User agents: `~/.pi/agent/agents/`
547
+ - Project agents: nearest `.pi/agents/` directory in a trusted project
548
+ - Precedence: project overrides user, user overrides built-in
549
+
550
+ To replace a built-in, use the same filename and `name`. Optional frontmatter:
551
+
552
+ ```yaml
553
+ ---
554
+ name: explorer
555
+ description: Fast read-only codebase reconnaissance
556
+ model: anthropic/claude-haiku-4-5
557
+ thinking: low
558
+ tools: read, bash
559
+ ---
560
+ ```
561
+
562
+ The Markdown body becomes the child's additional system prompt. Configuration
563
+ chosen in `/subagents-setup` takes precedence over frontmatter defaults. A
564
+ custom agent's explicit `tools` list remains its Pi built-in capability boundary;
565
+ an existing shell slot follows the parent, and active extension/SDK tools are
566
+ appended as described above. Omitting `tools` inherits the parent's complete
567
+ active set.
568
+
569
+ ## Development
570
+
571
+ ```bash
572
+ npm install
573
+ npm run check
574
+ npm test
575
+ ```
576
+
577
+ The package has no bundled runtime dependencies; it uses pi and TypeBox as peer
578
+ packages. Source is split by responsibility: managed dispatch/workflow policy,
579
+ retained thread lifecycle, RPC transport, worktree integration, completion
580
+ delivery, tools, and TUI status.
581
+
582
+ ## License
583
+
584
+ [MIT](./LICENSE)