@ferris1225/pi-subagents 4.0.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 +506 -478
- package/agents/cleaner.md +51 -41
- package/agents/documenter.md +44 -0
- package/agents/reviewer.md +71 -70
- package/agents/worker.md +4 -1
- package/package.json +2 -2
- package/src/agents.ts +12 -0
- package/src/announcements.ts +34 -7
- package/src/completion.ts +160 -160
- package/src/config.ts +86 -15
- package/src/dispatch.ts +637 -704
- package/src/fixloop.ts +266 -52
- package/src/index.ts +93 -93
- package/src/models.ts +189 -189
- package/src/monitor.ts +12 -3
- package/src/prompt.ts +47 -12
- package/src/recovery.ts +145 -145
- package/src/rpc-run.ts +23 -7
- package/src/runtime.ts +8 -7
- package/src/session-fork.ts +80 -80
- package/src/setup.ts +36 -5
- package/src/spawn.ts +45 -11
- package/src/thread-lifecycle.ts +203 -49
- package/src/tools.ts +23 -9
- package/src/widget.ts +4 -4
- package/src/worktree.ts +27 -4
package/README.md
CHANGED
|
@@ -1,478 +1,506 @@
|
|
|
1
|
-
# pi-subagents
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
4
|
-
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
5
|
-
[](./LICENSE)
|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
This
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
subagent({
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
`
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
the
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
their
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
only
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
`
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
1
|
+
# pi-subagents
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
4
|
+
[](https://www.npmjs.com/package/@ferris1225/pi-subagents)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+

|
|
7
|
+

|
|
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)
|