@ferris1225/pi-subagents 4.1.1 → 4.1.2

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,481 +1,506 @@
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
- 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:
37
-
38
- ```text
39
- reviewer (find issues) → worker (fix every finding) → reviewer (verify) → final PASS/FAIL
40
- ```
41
-
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
159
-
160
- ```bash
161
- pi install npm:@ferris1225/pi-subagents
162
- ```
163
-
164
- Requires pi **>= 0.83.0**. After installation, open the setup wizard in an
165
- interactive TUI session:
166
-
167
- ```text
168
- /subagents-setup
169
- ```
170
-
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.
177
-
178
- ## The agents
179
-
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. |
186
-
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).
190
-
191
- ## Usage
192
-
193
- ### Single task
194
-
195
- ```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." });
201
- ```
202
-
203
- ### Parallel tasks
204
-
205
- ```ts
206
- subagent({
207
- tasks: [
208
- { agent: "explorer", task: "Where is the selected-to-main handoff logic?" },
209
- { agent: "worker", task: "Add unit tests for models.ts." },
210
- ],
211
- });
212
- ```
213
-
214
- ### Cleanup routing and lifecycle
215
-
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.
222
-
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.
229
-
230
- ```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
234
- ```
235
-
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`.
239
-
240
- ### Image work (screenshots / mockups / designs)
241
-
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:
244
-
245
- ```ts
246
- subagent({
247
- agent: "reviewer",
248
- task: "Compare the UI in screenshots/settings.png against the mockup design.png; list every visual mismatch.",
249
- });
250
- ```
251
-
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.
257
-
258
- ### Controlling and stopping
259
-
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).
263
-
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.
275
-
276
- Examples:
277
-
278
- ```ts
279
- subagent_control({ action: "steer", id: 7, instruction: "Check the Windows path too." });
280
- subagent_control({ action: "park", id: 7 });
281
- subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
282
- subagent_control({ action: "fork", id: 7, objective: "Try the smaller alternative." });
283
- ```
284
-
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.
308
-
309
- ## Configuration
310
-
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.
321
-
322
- ```json
323
- {
324
- "enabledAgents": ["explorer", "worker", "cleaner", "reviewer"],
325
- "agentModels": {
326
- "explorer": "anthropic/claude-haiku-4-5"
327
- },
328
- "agentThinkingLevels": {
329
- "reviewer": "high"
330
- },
331
- "notifyOnReviewPass": false,
332
- "maxResultLines": 80,
333
- "proactiveInjection": true,
334
- "agentScope": "user",
335
- "maxConcurrency": 4,
336
- "maxFixRounds": 2,
337
- "idleTimeoutSec": 90
338
- }
339
- ```
340
-
341
- | Field | Description |
342
- | --- | --- |
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." });
413
- ```
414
-
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.
462
-
463
- ## Development
464
-
465
- ```bash
466
- npm install
467
- npm run check
468
- npm test
469
- ```
470
-
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.
478
-
479
- ## License
480
-
481
- MIT
1
+ # pi-subagents
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@ferris1225/pi-subagents?color=blue)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
4
+ [![downloads](https://img.shields.io/npm/dm/@ferris1225/pi-subagents)](https://www.npmjs.com/package/@ferris1225/pi-subagents)
5
+ [![license](https://img.shields.io/npm/l/@ferris1225/pi-subagents)](./LICENSE)
6
+ ![platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
7
+ ![pi](https://img.shields.io/badge/pi-extension-orange)
8
+
9
+ ## 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 documenter reviewer
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)