@ferris1225/pi-subagents 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +461 -381
- package/agents/cleaner.md +16 -6
- package/agents/documenter.md +46 -0
- package/agents/explorer.md +15 -11
- package/agents/reviewer.md +8 -4
- package/agents/worker.md +9 -4
- package/package.json +55 -55
- package/src/agents.ts +53 -0
- package/src/announcements.ts +18 -1
- package/src/completion.ts +160 -160
- package/src/config.ts +43 -13
- package/src/dispatch.ts +233 -303
- package/src/fixloop.ts +259 -62
- package/src/index.ts +3 -3
- package/src/models.ts +189 -189
- package/src/monitor.ts +101 -22
- package/src/prompt.ts +47 -12
- package/src/recovery.ts +145 -145
- package/src/rpc-run.ts +29 -10
- package/src/runtime.ts +13 -7
- package/src/session-fork.ts +80 -80
- package/src/setup.ts +162 -130
- package/src/spawn.ts +53 -13
- package/src/thread-lifecycle.ts +240 -54
- package/src/tools.ts +65 -37
- package/src/widget.ts +68 -22
- package/src/worktree.ts +27 -4
package/README.md
CHANGED
|
@@ -6,326 +6,484 @@
|
|
|
6
6
|

|
|
7
7
|

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