@ferris1225/pi-subagents 4.1.9 → 4.1.12
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 +161 -507
- package/agents/cleaner.md +51 -51
- package/agents/documenter.md +39 -39
- package/agents/explorer.md +40 -40
- package/agents/reviewer.md +6 -7
- package/agents/worker.md +2 -2
- package/package.json +1 -1
- package/src/background.ts +6 -6
- package/src/config.ts +4 -2
- package/src/dispatch.ts +12 -88
- package/src/monitor.ts +1 -1
- package/src/prompt.ts +22 -40
- package/src/runtime.ts +3 -3
- package/src/setup.ts +25 -193
- package/src/thread-lifecycle.ts +54 -54
- package/src/{fixloop.ts → workflow.ts} +248 -378
package/README.md
CHANGED
|
@@ -6,17 +6,45 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
A managed engineering team for [pi](https://github.com/earendil-works/pi): five
|
|
10
|
+
specialized sub-agents, durable threads, automatic quality gates, and Git
|
|
11
|
+
worktree isolation — installed once, then your main agent delegates on its own.
|
|
12
|
+
|
|
13
|
+
## Why pi-subagents
|
|
14
|
+
|
|
15
|
+
Delegation should **remove** coordination work, not create more of it. Most
|
|
16
|
+
sub-agent launchers stop at "spawn a child with a prompt"; the coordination
|
|
17
|
+
burden — when to delegate, how wide to fan out, who reviews, what happens when a
|
|
18
|
+
model dies, how results come back — stays with you. pi-subagents owns that
|
|
19
|
+
burden:
|
|
20
|
+
|
|
21
|
+
- **The main model actually delegates.** A lean delegation directive is injected
|
|
22
|
+
into its system prompt: substantive work goes to children so the main context
|
|
23
|
+
stays lean for orchestration, trivial work stays inline, and nothing is
|
|
24
|
+
re-explained twice. No custom prompts needed.
|
|
25
|
+
- **Fan-out is the model's call, not a cap.** One parallel dispatch carries as
|
|
26
|
+
many tasks as the work genuinely decomposes into. The runtime paces execution
|
|
27
|
+
at four concurrent child processes; extra tasks simply queue, so wide batches
|
|
28
|
+
never fail and never flood your context (results deliver compact, with the
|
|
29
|
+
full text on disk).
|
|
30
|
+
- **Quality gates are built in.** Successful worker/cleaner runs continue
|
|
31
|
+
through one independent reviewer gate, and `REVIEW_FAIL` findings return to
|
|
32
|
+
the main agent with concrete fix instructions — it resolves them itself,
|
|
33
|
+
without stopping to ask you. No black-box auto-fix chain edits code behind
|
|
34
|
+
your back.
|
|
35
|
+
- **Documentation stops drifting.** Writers sync the docs they directly affect;
|
|
36
|
+
after a passing gate, the documenter runs only when the reviewer actually
|
|
37
|
+
reports drift.
|
|
38
|
+
- **Parallel edits are safe.** Parallel workers default to isolated Git
|
|
39
|
+
worktrees and integrate back without touching your index; shared-checkout
|
|
40
|
+
writers serialize through one repository lane.
|
|
41
|
+
- **Work survives everything.** Threads keep retained sessions across resume,
|
|
42
|
+
stop, and pi reloads or crashes; a model failure hands the same session to
|
|
43
|
+
the current main model instead of losing progress.
|
|
44
|
+
- **Failures are visible.** Crashes, partial starts, and integration failures
|
|
45
|
+
come back as results with recovery records — never as silent hangs.
|
|
46
|
+
|
|
47
|
+
## How it works
|
|
20
48
|
|
|
21
49
|
```text
|
|
22
50
|
You
|
|
@@ -26,51 +54,15 @@ You
|
|
|
26
54
|
├─ cleaner ──── cleans up ──┘ └─ NEEDED/missing → documenter
|
|
27
55
|
├─ documenter ─ explicit docs/comments task → deliver
|
|
28
56
|
└─ reviewer ─── advisory report (no VERDICT), or managed gate
|
|
29
|
-
└─ REVIEW_FAIL →
|
|
57
|
+
└─ REVIEW_FAIL → findings + fix instructions → main agent fixes
|
|
30
58
|
|
|
31
59
|
Worker and cleaner update existing docs/comments they directly affect. The stable
|
|
32
60
|
parent returns one final result when its complete managed workflow settles.
|
|
33
61
|
```
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## Why use pi-subagents?
|
|
39
|
-
|
|
40
|
-
Use pi-subagents when delegation should **remove coordination work**, not create
|
|
41
|
-
more of it.
|
|
42
|
-
|
|
43
|
-
- **The right specialist gets the right job.** Research, implementation, cleanup,
|
|
44
|
-
and review have separate roles, tools, and operating rules.
|
|
45
|
-
- **You do not babysit background work.** Results wake the main agent automatically;
|
|
46
|
-
there is no polling loop and no “go check whether it finished” step.
|
|
47
|
-
- **Parallel edits stay safe.** Parallel workers use temporary, isolated Git
|
|
48
|
-
checkouts (worktrees) by default, then apply their changes back without
|
|
49
|
-
touching your index.
|
|
50
|
-
- **Documentation stops drifting without a mandatory extra pass.** Workers and
|
|
51
|
-
cleaners synchronize directly affected existing docs. After `REVIEW_PASS`,
|
|
52
|
-
enabled `documenter` runs only for `DOCUMENTATION: NEEDED` (or conservatively
|
|
53
|
-
for a missing marker); with reviewer disabled, it remains the fallback.
|
|
54
|
-
- **Review can close the loop.** A failed gate can automatically dispatch a
|
|
55
|
-
worker, request another independent review, and repeat up to a hard limit;
|
|
56
|
-
documentation is considered only after the terminal `REVIEW_PASS`.
|
|
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, resumable threads that survive reloads |
|
|
69
|
-
| Concurrent writers in one checkout | Git worktree isolation for parallel workers |
|
|
70
|
-
| A review report you must act on manually | Independent worker/cleaner gate, one bounded fix round, and conditional docs sync |
|
|
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 |
|
|
63
|
+
Every child is an isolated leaf Pi process with its own context window and no
|
|
64
|
+
memory of your conversation — the brief is its only input. Completions resume
|
|
65
|
+
the main agent automatically; there is no polling loop.
|
|
74
66
|
|
|
75
67
|
## Quick start
|
|
76
68
|
|
|
@@ -80,124 +72,38 @@ Requires **pi >= 0.83.0** and **Node.js >= 22.19.0**.
|
|
|
80
72
|
pi install npm:@ferris1225/pi-subagents
|
|
81
73
|
```
|
|
82
74
|
|
|
83
|
-
Open pi and run
|
|
84
|
-
|
|
85
|
-
|
|
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:
|
|
75
|
+
Open pi and run `/subagents-setup` to pick agents and models. Fresh installs
|
|
76
|
+
enable `explorer`, `worker`, `cleaner`, and `reviewer`; `documenter` is opt-in.
|
|
77
|
+
Then just ask:
|
|
95
78
|
|
|
96
79
|
```text
|
|
97
80
|
Map how authentication works, fix the refresh race, run the tests, and review the diff.
|
|
98
81
|
```
|
|
99
82
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
```text
|
|
105
|
-
Compare screenshots/settings.png with design.png and report every visual mismatch.
|
|
106
|
-
```
|
|
83
|
+
The main agent decides when delegation pays off; you can also call the tools
|
|
84
|
+
directly for exact control.
|
|
107
85
|
|
|
108
|
-
The
|
|
109
|
-
explicitly when you want exact control.
|
|
110
|
-
|
|
111
|
-
## Managed workflow behavior
|
|
112
|
-
|
|
113
|
-
The runtime deliberately keeps delegation conservative:
|
|
114
|
-
|
|
115
|
-
- Small work with a known target stays in the main thread on direct tools.
|
|
116
|
-
`explorer` is worthwhile for broad reconnaissance only; it returns a retrieval
|
|
117
|
-
index, never an automatic gate, and downstream roles re-read load-bearing code.
|
|
118
|
-
- `worker` and `cleaner` remain distinct write-capable entry roles. Each updates
|
|
119
|
-
existing README/docs/examples/comments directly affected by its change. After
|
|
120
|
-
success, one enabled independent `reviewer` gate runs, with the existing bounded
|
|
121
|
-
worker ↔ reviewer fix loop for `REVIEW_FAIL`. Every gate finding carries a
|
|
122
|
-
concrete fix instruction; the worker implements those instructions or ships a
|
|
123
|
-
sounder fix with an explicit pushback, and re-review judges the resulting code —
|
|
124
|
-
only open findings and defects the fix itself introduced can continue the loop.
|
|
125
|
-
- When `documenter` is enabled, every managed reviewer gate is asked for a
|
|
126
|
-
standalone `DOCUMENTATION: CLEAN` or `DOCUMENTATION: NEEDED` line. Only
|
|
127
|
-
`REVIEW_PASS` can authorize the final sync: NEEDED includes
|
|
128
|
-
`## Documentation notes` and runs it, CLEAN removes the pending docs stage,
|
|
129
|
-
and a missing marker on that passing gate conservatively runs it.
|
|
130
|
-
- A process failure, missing verdict, or terminal `REVIEW_FAIL` never starts
|
|
131
|
-
documentation writing. With reviewer disabled, the writer → documenter
|
|
132
|
-
fallback remains. Documentation drift is non-gating only while documenter is
|
|
133
|
-
available; otherwise it is an ordinary review finding.
|
|
134
|
-
- A top-level `documenter` is already an explicit docs/comments writing task. It
|
|
135
|
-
still uses the shared writer lane and may use worktree isolation, but delivers
|
|
136
|
-
directly after success instead of starting another reviewer.
|
|
137
|
-
|
|
138
|
-
No workflow decision depends on diff line count, file count, or a size heuristic.
|
|
139
|
-
|
|
140
|
-
## Meet the team
|
|
86
|
+
## The team
|
|
141
87
|
|
|
142
88
|
| Agent | Access | Best for |
|
|
143
89
|
| --- | --- | --- |
|
|
144
|
-
| `explorer` | Read-only | Broad
|
|
145
|
-
| `worker` | Full | A self-contained implementation,
|
|
146
|
-
| `cleaner` | Full | Explicitly authorized cleanup, removal, simplification,
|
|
147
|
-
| `documenter` | Docs/comments | Conditional final diff sync or an explicit standalone
|
|
148
|
-
| `reviewer` | Read-only | Audits, code-health checks, plans, PR
|
|
149
|
-
|
|
150
|
-
Children have no memory of the parent conversation. A good manual brief includes
|
|
151
|
-
the goal, exact paths, constraints, and expected output. The injected delegation
|
|
152
|
-
guidance does this automatically when the main agent dispatches on your behalf.
|
|
153
|
-
|
|
154
|
-
### Tool, plugin, skill, and context inheritance
|
|
155
|
-
|
|
156
|
-
Every initial dispatch, managed stage, retained resume, startup retry,
|
|
157
|
-
and selected-to-main fallback snapshots the parent session's currently active
|
|
158
|
-
tools. Roles without an explicit tool list (such as shipped `worker` and
|
|
159
|
-
`cleaner`) inherit that complete set. An explicit role list remains its Pi
|
|
160
|
-
built-in permission boundary, but its existing shell slot follows the parent
|
|
161
|
-
(`bash`, `powershell`, both, or neither) and parent-active extension/SDK tools
|
|
162
|
-
are appended; inactive plugin names declared in frontmatter are not enabled.
|
|
163
|
-
Therefore `explorer` and `reviewer` never gain Pi's built-in `edit`/`write`;
|
|
164
|
-
`documenter` keeps them for docs/comments; and a custom agent keeps the built-in
|
|
165
|
-
capabilities declared in its own frontmatter. All `subagent*` control tools are
|
|
166
|
-
removed from children so they remain leaves. An empty inherited snapshot starts
|
|
167
|
-
the child with `--no-tools` instead of falling back to Pi's defaults.
|
|
168
|
-
|
|
169
|
-
`powershell` is the Pi tool name. On Windows, it selects native `pwsh.exe` when
|
|
170
|
-
available and falls back to `powershell.exe`. Parent-active plugin tools such as
|
|
171
|
-
web search or API/documentation lookup are available to every child when that
|
|
172
|
-
plugin also loads there. Global skills and trusted project skills load normally
|
|
173
|
-
inside each child Pi process.
|
|
174
|
-
|
|
175
|
-
Each child is an independent Pi session and uses Pi's normal global/project
|
|
176
|
-
`compaction` settings. Auto-compaction therefore remains enabled by default when
|
|
177
|
-
a child's model context approaches its limit. Retained resume sessions keep
|
|
178
|
-
their existing conversation and compaction summaries instead of starting over.
|
|
179
|
-
|
|
180
|
-
## Everyday workflows
|
|
181
|
-
|
|
182
|
-
### Delegate one task
|
|
90
|
+
| `explorer` | Read-only | Broad search, unfamiliar-area mapping, symbol/dependency tracing. Fast model, returns a retrieval index — never proof. |
|
|
91
|
+
| `worker` | Full | A self-contained implementation, fix, refactor, or test task carried through verification. |
|
|
92
|
+
| `cleaner` | Full | Explicitly authorized cleanup, removal, simplification, deduplication. Every safe proven cut applies without item-by-item approval. |
|
|
93
|
+
| `documenter` | Docs/comments | Conditional final diff sync, or an explicit standalone docs/comments task. May make zero edits; never changes runtime behavior. |
|
|
94
|
+
| `reviewer` | Read-only | Audits, code-health checks, plans, PR/issue validation, and independent gates. |
|
|
183
95
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
task: "Map the test setup. Report exact files, commands, and CI entry points.",
|
|
188
|
-
});
|
|
189
|
-
```
|
|
96
|
+
A good brief carries the goal, exact paths, constraints, and expected output —
|
|
97
|
+
the injected delegation guidance does this automatically when the main agent
|
|
98
|
+
dispatches for you.
|
|
190
99
|
|
|
191
|
-
|
|
192
|
-
subagent({
|
|
193
|
-
agent: "worker",
|
|
194
|
-
task: "Fix the cache invalidation bug in src/cache, add regression tests, and run the relevant checks.",
|
|
195
|
-
});
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Fan out independent work
|
|
100
|
+
## Dispatch and fan-out
|
|
199
101
|
|
|
200
102
|
```ts
|
|
103
|
+
// One task
|
|
104
|
+
subagent({ agent: "worker", task: "Fix the cache invalidation bug in src/cache, add regression tests, run the checks." });
|
|
105
|
+
|
|
106
|
+
// Parallel: as many genuinely independent units as the work has
|
|
201
107
|
subagent({
|
|
202
108
|
tasks: [
|
|
203
109
|
{ agent: "explorer", task: "Trace model fallback from dispatch to completion." },
|
|
@@ -206,364 +112,121 @@ subagent({
|
|
|
206
112
|
});
|
|
207
113
|
```
|
|
208
114
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
own managed stages (gate review, auto-fix rounds, documentation sync), that
|
|
215
|
-
generation releases its slot, so long fix chains never starve new dispatches.
|
|
115
|
+
The main agent owns the breadth — there is no per-call task cap. The runtime
|
|
116
|
+
runs four child processes at once and queues the rest; a generation that moves
|
|
117
|
+
on to its managed stages (gate review, docs sync) releases its slot, so managed
|
|
118
|
+
work never starves new dispatches. One child owns one coherent deliverable and
|
|
119
|
+
its files; dependent work starts only after its prerequisite delivers.
|
|
216
120
|
|
|
217
|
-
|
|
121
|
+
## Review gates and fixes
|
|
218
122
|
|
|
219
123
|
```ts
|
|
220
|
-
subagent({
|
|
221
|
-
agent: "reviewer",
|
|
222
|
-
task: "Gate the current diff for correctness, regressions, and missing tests.",
|
|
223
|
-
});
|
|
124
|
+
subagent({ agent: "reviewer", task: "Gate the current diff for correctness, regressions, and missing tests." });
|
|
224
125
|
```
|
|
225
126
|
|
|
226
|
-
A gate
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
127
|
+
A gate ends with `VERDICT: REVIEW_PASS` or `REVIEW_FAIL`, plus
|
|
128
|
+
`DOCUMENTATION: CLEAN`/`NEEDED` when documenter is enabled. Only `REVIEW_PASS`
|
|
129
|
+
continues to documentation: CLEAN delivers immediately; NEEDED or a missing
|
|
130
|
+
marker runs one final docs sync. A `REVIEW_FAIL` delivers the full findings —
|
|
131
|
+
each with a concrete fix instruction — straight back to the main agent, which
|
|
132
|
+
resolves them itself (inline or via a worker it briefs) without waiting for you;
|
|
133
|
+
only a genuinely destructive or scope-changing fix is worth asking about.
|
|
231
134
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
└─ NEEDED/missing → documenter
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
Each step gets a fresh model context. The chain shares the same code state and
|
|
240
|
-
passes every full reviewer and worker report forward; it does not reuse one
|
|
241
|
-
context window. Re-review converges instead of re-auditing: it rules on every
|
|
242
|
-
previous finding once, judges the code as it now stands (a sound worker fix
|
|
243
|
-
counts even when it deviates from the instruction), and adds new findings only
|
|
244
|
-
for defects the fix round's own edits introduced or exposed — issues unrelated
|
|
245
|
-
to those edits belong to a fresh gate, not to the loop. Internal children bypass top-level lifecycle policy, so they
|
|
246
|
-
cannot recursively start another chain. Gate reviewers keep documentation drift
|
|
247
|
-
out of the code verdict while `documenter` is enabled by recording it under
|
|
248
|
-
`## Documentation notes`; with documenter disabled, drift is a normal finding.
|
|
249
|
-
|
|
250
|
-
The loop is fixed at one worker fix round (the fix is re-reviewed once); anything
|
|
251
|
-
still unresolved is delivered back to the main window for the decision instead of
|
|
252
|
-
burning more rounds. Disabling the `worker` agent is the way to turn fixes off. The post-writer review gate still
|
|
253
|
-
runs regardless, and only a terminal `REVIEW_PASS` can decide whether docs
|
|
254
|
-
sync is needed. Generic audits and read-only reviews are advisory: they omit
|
|
255
|
-
`VERDICT` and documentation machine markers, remain read-only, and never trigger
|
|
256
|
-
edits.
|
|
257
|
-
|
|
258
|
-
### Clean up without guessing
|
|
259
|
-
|
|
260
|
-
`cleaner` is only for requests that authorize cleanup edits. Once dispatched,
|
|
261
|
-
that authorization covers every safe, proven in-scope cut without another
|
|
262
|
-
item-by-item confirmation. It checks reachability, ownership, history, and
|
|
263
|
-
boundaries before removing, simplifying, or consolidating anything, then verifies
|
|
264
|
-
the result.
|
|
265
|
-
|
|
266
|
-
Repeated code is a first-class cleanup target. Cleaner compares contracts,
|
|
267
|
-
invariants, side effects, ownership, and reasons to change—not just matching
|
|
268
|
-
text—then extracts the smallest stable shared implementation and migrates all
|
|
269
|
-
in-scope callers. It keeps similar code separate when domains or future change
|
|
270
|
-
axes genuinely differ, avoiding a generic abstraction that is worse than the
|
|
271
|
-
duplication.
|
|
272
|
-
|
|
273
|
-
```text
|
|
274
|
-
explicit cleanup request → cleaner applies cuts + syncs affected docs → reviewer gate → conditional documenter
|
|
275
|
-
read-only cleanup audit → reviewer reports candidates only
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
This separation matters: asking for an audit does not silently authorize code
|
|
279
|
-
changes, and asking for cleanup does not reward speculative deletion.
|
|
280
|
-
|
|
281
|
-
### Keep comments and README/docs synchronized
|
|
282
|
-
|
|
283
|
-
`documenter` has two deliberate launch paths.
|
|
284
|
-
|
|
285
|
-
**For a pending worker or cleaner change**, those writers first synchronize
|
|
286
|
-
existing docs/comments directly affected by their edits. When the role is
|
|
287
|
-
enabled, runtime schedules a final sync only after terminal `REVIEW_PASS` when
|
|
288
|
-
the reviewer emits `DOCUMENTATION: NEEDED` or omits the marker; do not dispatch
|
|
289
|
-
a duplicate. If reviewer is disabled, documenter remains the conservative final
|
|
290
|
-
fallback. If documenter is disabled, documentation drift is an ordinary reviewer
|
|
291
|
-
finding.
|
|
292
|
-
|
|
293
|
-
**For standalone documentation work**, explicitly authorize the desired scope
|
|
294
|
-
(a whole-codebase maintenance pass must be explicit):
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
subagent({
|
|
298
|
-
agent: "documenter",
|
|
299
|
-
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.",
|
|
300
|
-
});
|
|
301
|
-
```
|
|
135
|
+
Re-verifying your own fixes? Dispatch with `advisory: true`: the report comes
|
|
136
|
+
back to the main window and never starts anything, even if a verdict slips
|
|
137
|
+
through. Generic audits and read-only reviews are advisory by default: no
|
|
138
|
+
`VERDICT`, no edits.
|
|
302
139
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
140
|
+
`cleaner` is dispatch-authorized cleanup: asking for an audit never silently
|
|
141
|
+
authorizes code changes, and asking for cleanup never rewards speculative
|
|
142
|
+
deletion. A top-level `documenter` is an explicit docs-writing task that
|
|
143
|
+
delivers without another gate.
|
|
307
144
|
|
|
308
145
|
## Safe parallel editing
|
|
309
146
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
- Read-only `explorer` and `reviewer` tasks reject worktree mode because they do
|
|
322
|
-
not need a writable checkout.
|
|
323
|
-
|
|
324
|
-
Worktree mode requires a Git repository with a committed `HEAD`. For an isolated
|
|
325
|
-
worker/cleaner, its automatic reviewer and any needed documenter run inside that
|
|
326
|
-
same worktree. A top-level isolated documenter writes there and then delivers
|
|
327
|
-
directly. Isolated workflows can still run in parallel; writer, fix, and any
|
|
328
|
-
documentation changes are integrated only after the final managed stage
|
|
329
|
-
settles. Tracked, deleted, untracked, and binary changes are then carried back
|
|
330
|
-
to the original checkout without staging or modifying the parent index.
|
|
331
|
-
|
|
332
|
-
Repository-lane discovery uses the Git top-level even in an empty repository, so
|
|
333
|
-
root and nested paths share one lane before the first commit. Every shared
|
|
334
|
-
`worker`, `cleaner`, and `documenter` writer—and each shared `reviewer` snapshot
|
|
335
|
-
when managed writers are enabled—uses that lane. Standalone documentation,
|
|
336
|
-
writer-only configurations, and workflows without reviewer cannot race another
|
|
337
|
-
writer or documentation sync. Isolated agents keep doing model work in parallel,
|
|
338
|
-
but their final apply waits for the same lane.
|
|
339
|
-
|
|
340
|
-
Normal completion, stop, and shutdown share one finalization result, so isolated
|
|
341
|
-
state is applied at most once. If stop or shutdown wins after the top-level
|
|
342
|
-
child settles, no downstream role starts and the stable top-level session remains
|
|
343
|
-
the checkpoint. If setup or integration fails, pi-subagents keeps the useful
|
|
344
|
-
patch or worktree when possible and records recovery information in:
|
|
345
|
-
|
|
346
|
-
```text
|
|
347
|
-
~/.pi/agent/pi-subagents-recovery.json
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
A parked isolated thread keeps its worktree. Resume continues there.
|
|
147
|
+
- Single tasks default to the shared checkout; parallel `worker` tasks default
|
|
148
|
+
to detached Git worktrees (requires a committed `HEAD`; read-only agents
|
|
149
|
+
reject worktree mode).
|
|
150
|
+
- An isolated workflow's reviewer and documenter run inside the same worktree;
|
|
151
|
+
tracked, deleted, untracked, and binary changes integrate back exactly once
|
|
152
|
+
after the workflow settles — nothing is staged and your index is untouched.
|
|
153
|
+
- Shared-checkout writers (and reviewers snapshotting their diff) serialize
|
|
154
|
+
through one repository lane, so two shared writers never race.
|
|
155
|
+
- Setup or integration failures keep the useful patch/worktree and record
|
|
156
|
+
recovery info in `~/.pi/agent/pi-subagents-recovery.json`; a parked isolated
|
|
157
|
+
thread keeps its worktree and resumes there.
|
|
351
158
|
|
|
352
|
-
## Follow, redirect, or stop
|
|
159
|
+
## Follow, redirect, or stop
|
|
353
160
|
|
|
354
|
-
|
|
355
|
-
managed worker/cleaner or fix chain, that parent id represents the whole workflow;
|
|
356
|
-
each internal reviewer, fix, and conditionally launched documenter gets a
|
|
357
|
-
separate queryable id in the final summary. No internal completion wakes the
|
|
358
|
-
main agent.
|
|
161
|
+
Every dispatch returns a stable `#id` — the handle for all control tools:
|
|
359
162
|
|
|
360
163
|
| Tool | What it does |
|
|
361
164
|
| --- | --- |
|
|
362
|
-
| `subagent_control` | `resume` a parked
|
|
363
|
-
| `subagent_status` |
|
|
364
|
-
| `subagent_wait` |
|
|
365
|
-
| `subagent_stop` | Destructively cancel
|
|
165
|
+
| `subagent_control` | `resume` a parked/settled thread with its full retained context, optionally with a new `objective` appended. |
|
|
166
|
+
| `subagent_status` | List active and recent runs, or return one run's full result and failed-tool diagnostics. |
|
|
167
|
+
| `subagent_wait` | Non-blocking in-turn lookup; `timeoutMs` only when you must wait. |
|
|
168
|
+
| `subagent_stop` | Destructively cancel, deliver the partial output, retire the thread. |
|
|
366
169
|
|
|
367
170
|
```ts
|
|
368
|
-
subagent_control({ action: "resume", id: 7 });
|
|
369
171
|
subagent_control({ action: "resume", id: 7, objective: "Finish the tests." });
|
|
370
172
|
```
|
|
371
173
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
Use `stop` only when you want to discard that thread's future continuation. Stop
|
|
379
|
-
and session shutdown abort the active internal stage, suppress stale delivery,
|
|
380
|
-
and leave worktree finalization to the same one-time lifecycle owner. `stop-all`
|
|
381
|
-
interrupts every lane holder before waiting for finalization, avoiding
|
|
382
|
-
self-deadlock when an isolated apply is queued behind shared work.
|
|
383
|
-
|
|
384
|
-
Every control operation is bounded: stop and resume never wait indefinitely on a
|
|
385
|
-
generation that is still settling (for example an isolated apply queued behind
|
|
386
|
-
the managed repository lane). Stop proceeds after a bounded deadline once it owns
|
|
387
|
-
the lifecycle, a still-running integration continues in the background, and a
|
|
388
|
-
durable recovery record is persisted pointing at the retained worktree/patch so
|
|
389
|
-
stopped work is never lost.
|
|
390
|
-
|
|
391
|
-
### Re-verify your own fixes without triggering auto-fix
|
|
392
|
-
|
|
393
|
-
When the main window fixes review findings itself and wants an independent
|
|
394
|
-
confirmation, dispatch the reviewer with `advisory: true`:
|
|
395
|
-
|
|
396
|
-
```ts
|
|
397
|
-
subagent({ agent: "reviewer", task: "Re-verify the pending diff.", advisory: true });
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
The reviewer is told to report findings only (no `VERDICT`/`DOCUMENTATION`
|
|
401
|
-
markers), and even if a verdict slips through, the runtime refuses to start the
|
|
402
|
-
auto-fix chain for an advisory dispatch — the report always comes back to the
|
|
403
|
-
main window for the decision.
|
|
404
|
-
|
|
405
|
-
## Survive reloads and restarts
|
|
406
|
-
|
|
407
|
-
Retained sessions, worktree checkpoints, and thread state live next to your pi
|
|
408
|
-
agent config, never in the OS temp directory:
|
|
409
|
-
|
|
410
|
-
```text
|
|
411
|
-
~/.pi/agent/pi-subagents-threads.json # durable thread manifest
|
|
412
|
-
~/.pi/agent/pi-subagents-state/ # retained sessions and worktree temp state
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
When pi reloads (or the process crashes and restarts), the extension restores
|
|
416
|
-
parked and settled threads from that manifest: `subagent_status` lists them
|
|
417
|
-
again, `subagent_control resume` continues one with its full retained context,
|
|
418
|
-
and a one-time notice reports how many threads were restored. New run ids never
|
|
419
|
-
collide with restored ones. A reload that interrupts a live run converts it to a
|
|
420
|
-
restorable checkpoint instead of losing it, and child processes orphaned by the
|
|
421
|
-
reload are killed so the on-disk session is the single source of truth.
|
|
422
|
-
|
|
423
|
-
Retention is fixed, not configurable: settled results stay resumable for 7 days,
|
|
424
|
-
parked work (which may hold unintegrated changes) for 30 days. Expired records
|
|
425
|
-
are removed at load together with their artifacts. `subagent_stop` removes a
|
|
426
|
-
thread's record immediately. Startup also sweeps leaked temp directories whose
|
|
427
|
-
owning process is gone and state-root directories no record references, so
|
|
428
|
-
crashes between creation and the first checkpoint do not accumulate garbage.
|
|
174
|
+
Threads are durable: parked/settled sessions, worktree checkpoints, and state
|
|
175
|
+
live under `~/.pi/agent/` (not the OS temp directory) and are restored when pi
|
|
176
|
+
reloads or restarts — a reload interrupts a live run into a restorable
|
|
177
|
+
checkpoint instead of losing it. Settled results stay resumable for 7 days,
|
|
178
|
+
parked work for 30. All control operations are bounded; they never hang on a
|
|
179
|
+
generation that is still settling.
|
|
429
180
|
|
|
430
181
|
## Results and live status
|
|
431
182
|
|
|
432
|
-
The
|
|
433
|
-
|
|
434
|
-
with its stable run id — the handle for `subagent_control`, `subagent_status`,
|
|
435
|
-
and `subagent_stop`:
|
|
183
|
+
The TUI widget projects each managed workflow as a timeline plus its current
|
|
184
|
+
child:
|
|
436
185
|
|
|
437
186
|
```text
|
|
438
|
-
◆ #12 worker workflow · src/cache.ts · wt:a91f3c
|
|
187
|
+
◆ #12 worker workflow · src/cache.ts · wt:a91f3c · 42s
|
|
439
188
|
✓ implement ─ ● review ─ ○ docs
|
|
440
189
|
└ ● #15 reviewer · final review · claude-sonnet-4-5/high · 10s
|
|
441
|
-
git diff
|
|
442
190
|
○ #23 worker · queued · redirect to ripgrep crates · 5m02s
|
|
443
191
|
```
|
|
444
192
|
|
|
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
|
-
A parked parent remains queryable. Final messages contain one managed-workflow
|
|
470
|
-
summary with aggregate token/cost totals and every internal id. Built-in roles
|
|
471
|
-
author their own result-only handoff—outcome, relevant paths, verification, and unresolved
|
|
472
|
-
blockers—without a second summarization layer that could distort the result.
|
|
473
|
-
They omit task/process narration and recovered transient tool failures. The
|
|
474
|
-
80-line delivery cap remains a safety limit; long output is written unchanged to
|
|
475
|
-
a temporary Markdown artifact, and explicit `subagent_status` lookup keeps the
|
|
476
|
-
complete report and failed-tool diagnostics available by id.
|
|
477
|
-
|
|
478
|
-
The main agent is told not to paraphrase a result you have already seen. It should
|
|
479
|
-
add only its own conclusion or next action instead of charging you twice for the
|
|
480
|
-
same explanation.
|
|
481
|
-
|
|
482
|
-
## Models, thinking, and image work
|
|
483
|
-
|
|
484
|
-
Each agent can use the current main model or one selected in `/subagents-setup`.
|
|
485
|
-
The setup picker shows authenticated models and labels them `vision` or
|
|
486
|
-
`text-only`.
|
|
487
|
-
|
|
488
|
-
```text
|
|
489
|
-
selected agent model → current main model
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
If the selected model is missing, unavailable, rate-limited, out of quota, or
|
|
493
|
-
fails at the provider level, the current main model continues the same retained
|
|
494
|
-
session. Searches, reads, reasoning, and edits already completed are preserved.
|
|
495
|
-
Ordinary tool and test failures remain task failures and do not trigger a model
|
|
496
|
-
handoff.
|
|
497
|
-
|
|
498
|
-
Model changes apply immediately to work that has not started: a run still
|
|
499
|
-
waiting for a concurrency slot re-resolves its route when it actually starts,
|
|
500
|
-
and managed workflow stages (fix rounds, re-reviews, the conditional documenter)
|
|
501
|
-
re-read the config before each stage launches. Only an already-running child
|
|
502
|
-
keeps the model it started with.
|
|
503
|
-
|
|
504
|
-
Thinking defaults to **Auto**. pi-subagents starts from the role's preference and
|
|
505
|
-
chooses only a level the effective model actually supports. A fallback re-checks
|
|
506
|
-
the level for the main model. `documenter` deliberately ships with the same fast,
|
|
507
|
-
low-thinking profile as `explorer`; migration and manual enablement copy any
|
|
508
|
-
configured explorer route, and you can still override it independently.
|
|
509
|
-
|
|
510
|
-
There is no separate vision mode. Assign a multimodal model to the agent and name
|
|
511
|
-
the image paths in the task:
|
|
512
|
-
|
|
513
|
-
```ts
|
|
514
|
-
subagent({
|
|
515
|
-
agent: "reviewer",
|
|
516
|
-
task: "Compare screenshots/settings.png with design.png and list every visual mismatch.",
|
|
517
|
-
});
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
## Reliability without duplicate work
|
|
521
|
-
|
|
522
|
-
- **Startup recovery:** silent, zero-activity failures before prompt dispatch
|
|
523
|
-
retry with extended jittered backoff. A dispatched prompt is never replayed,
|
|
524
|
-
even when its ACK is lost.
|
|
525
|
-
- **Idle watchdog:** a run with no RPC output for `idleTimeoutSec` is terminated;
|
|
526
|
-
selected-model failures can continue on the current main model.
|
|
527
|
-
- **Retained context:** model handoff, resume, and cross-reload
|
|
528
|
-
restore build on the same session history instead of repeating discovery.
|
|
529
|
-
- **Visible failures:** process crashes, partial parallel starts, model failures,
|
|
530
|
-
and Git integration failures are returned as failures rather than silent hangs.
|
|
531
|
-
- **Safe status text:** live tool activity is credential-redacted and stripped of
|
|
532
|
-
terminal control characters.
|
|
533
|
-
- **No runaway trees:** child processes are leaves; they cannot dispatch more
|
|
534
|
-
sub-agents.
|
|
193
|
+
Completions resume the main agent automatically with a compact block (40 lines
|
|
194
|
+
by default; longer output lands unchanged in a temporary Markdown artifact
|
|
195
|
+
reachable via `subagent_status`). Roles author result-only handoffs — outcome,
|
|
196
|
+
paths, verification, unresolved blockers — and the main agent is told to add
|
|
197
|
+
its conclusion, not restate what you already saw.
|
|
198
|
+
|
|
199
|
+
## Models, thinking, and vision
|
|
200
|
+
|
|
201
|
+
Each agent runs on the current main model or one picked in `/subagents-setup`
|
|
202
|
+
(vision/text-only labels included). If a selected model is missing, rate-limited,
|
|
203
|
+
or fails at the provider level, the **same retained session** continues on the
|
|
204
|
+
main model — finished searches, reads, and edits are preserved; ordinary task
|
|
205
|
+
failures do not trigger a handoff. Thinking defaults to **Auto**: the role's
|
|
206
|
+
preference, clamped to what the effective model supports. There is no separate
|
|
207
|
+
vision mode: assign a multimodal model and name the image paths in the task.
|
|
208
|
+
|
|
209
|
+
Every dispatch, managed stage, resume, retry, and fallback snapshots the
|
|
210
|
+
parent's currently active tools: roles without an explicit list inherit the
|
|
211
|
+
full set; explicit lists keep their Pi built-in boundary while their shell slot
|
|
212
|
+
(`bash`/`powershell`) follows the parent and active extension tools are
|
|
213
|
+
appended. Read-only roles never gain `edit`/`write`; all `subagent*` tools are
|
|
214
|
+
stripped so children stay leaves. An empty snapshot starts the child with
|
|
215
|
+
`--no-tools`.
|
|
535
216
|
|
|
536
217
|
## Configuration
|
|
537
218
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
```text
|
|
542
|
-
/subagents-setup
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
In nested setup screens, `Esc` returns one level: thinking → model → agent
|
|
546
|
-
selection → settings. Runtime value pickers return to the Runtime settings menu,
|
|
547
|
-
and other nested pickers return to the main settings menu. Only `Esc` from the
|
|
548
|
-
top-level settings menu exits the wizard; completed agent choices are saved when
|
|
549
|
-
leaving that configuration pass.
|
|
550
|
-
|
|
551
|
-
Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
|
|
552
|
-
`PI_CODING_AGENT_DIR` when that environment variable is set.
|
|
219
|
+
`/subagents-setup` stays one level deep: enabled agents, per-agent models, and
|
|
220
|
+
the delegation-injection toggle. Everything else is config-file only, stored at
|
|
221
|
+
`~/.pi/agent/pi-subagents.json` (follows `PI_CODING_AGENT_DIR`):
|
|
553
222
|
|
|
554
223
|
```json
|
|
555
224
|
{
|
|
556
225
|
"enabledAgents": ["explorer", "worker", "cleaner", "documenter", "reviewer"],
|
|
557
|
-
"agentModels": {
|
|
558
|
-
|
|
559
|
-
"documenter": "anthropic/claude-haiku-4-5"
|
|
560
|
-
},
|
|
561
|
-
"agentThinkingLevels": {
|
|
562
|
-
"documenter": "low",
|
|
563
|
-
"reviewer": "high"
|
|
564
|
-
},
|
|
226
|
+
"agentModels": { "explorer": "anthropic/claude-haiku-4-5" },
|
|
227
|
+
"agentThinkingLevels": { "reviewer": "high" },
|
|
565
228
|
"notifyOnReviewPass": false,
|
|
566
|
-
"maxResultLines":
|
|
229
|
+
"maxResultLines": 40,
|
|
567
230
|
"proactiveInjection": true,
|
|
568
231
|
"agentScope": "user",
|
|
569
232
|
"idleTimeoutSec": 90
|
|
@@ -572,32 +235,26 @@ Configuration is stored at `~/.pi/agent/pi-subagents.json` and follows
|
|
|
572
235
|
|
|
573
236
|
| Field | Meaning |
|
|
574
237
|
| --- | --- |
|
|
575
|
-
| `enabledAgents` |
|
|
576
|
-
| `agentModels` | Optional `provider/model-id` per agent
|
|
577
|
-
| `agentThinkingLevels` | Optional manual level per agent
|
|
578
|
-
| `notifyOnReviewPass` |
|
|
579
|
-
| `maxResultLines` | Lines kept in a completion message before the
|
|
580
|
-
| `proactiveInjection` |
|
|
238
|
+
| `enabledAgents` | Agents available for discovery and delegation. `[]` disables all. |
|
|
239
|
+
| `agentModels` | Optional `provider/model-id` per agent; missing = current main model. |
|
|
240
|
+
| `agentThinkingLevels` | Optional manual level per agent; missing = Auto. |
|
|
241
|
+
| `notifyOnReviewPass` | Deliver a standalone passing gate without waking the main agent. Default `false`. |
|
|
242
|
+
| `maxResultLines` | Lines kept in a completion message before the artifact takes over. Default `40`. |
|
|
243
|
+
| `proactiveInjection` | Inject the delegation directive into the main system prompt. Default `true`. |
|
|
581
244
|
| `agentScope` | Discover `user`, `project`, or `both` agent directories. Default `user`. |
|
|
582
|
-
| `idleTimeoutSec` | Seconds without RPC output before termination
|
|
245
|
+
| `idleTimeoutSec` | Seconds without child RPC output before termination; `0` disables. Default `90`. |
|
|
583
246
|
|
|
584
|
-
Invalid values fall back safely
|
|
585
|
-
`maxConcurrency
|
|
586
|
-
|
|
587
|
-
shape is saved back. At session start, per-agent model overrides that Pi no
|
|
588
|
-
longer reports as available are removed with a one-time notice; those agents
|
|
589
|
-
fall back to the current main model until you re-pick them in
|
|
590
|
-
`/subagents-setup`.
|
|
247
|
+
Invalid values fall back safely; stale keys (including the former
|
|
248
|
+
`maxConcurrency`/`maxFixRounds` knobs) are dropped automatically. At session
|
|
249
|
+
start, model overrides Pi no longer reports are removed with a one-time notice.
|
|
591
250
|
|
|
592
|
-
## Custom
|
|
251
|
+
## Custom agents
|
|
593
252
|
|
|
594
|
-
Built-ins ship in the package
|
|
253
|
+
Built-ins ship in the package; add or replace them with Markdown files:
|
|
595
254
|
|
|
596
255
|
- User agents: `~/.pi/agent/agents/`
|
|
597
|
-
- Project agents: nearest `.pi/agents/`
|
|
598
|
-
- Precedence: project
|
|
599
|
-
|
|
600
|
-
To replace a built-in, use the same filename and `name`. Optional frontmatter:
|
|
256
|
+
- Project agents: nearest `.pi/agents/` in a trusted project
|
|
257
|
+
- Precedence: project > user > built-in (same `name` wins)
|
|
601
258
|
|
|
602
259
|
```yaml
|
|
603
260
|
---
|
|
@@ -607,14 +264,12 @@ model: anthropic/claude-haiku-4-5
|
|
|
607
264
|
thinking: low
|
|
608
265
|
tools: read, bash
|
|
609
266
|
---
|
|
267
|
+
…additional system prompt…
|
|
610
268
|
```
|
|
611
269
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
an existing shell slot follows the parent, and active extension/SDK tools are
|
|
616
|
-
appended as described above. Omitting `tools` inherits the parent's complete
|
|
617
|
-
active set.
|
|
270
|
+
Wizard choices override frontmatter defaults; an explicit `tools` list stays the
|
|
271
|
+
capability boundary (shell slot follows the parent, active extension tools are
|
|
272
|
+
appended), and omitting it inherits the parent's complete active set.
|
|
618
273
|
|
|
619
274
|
## Development
|
|
620
275
|
|
|
@@ -624,11 +279,10 @@ npm run check
|
|
|
624
279
|
npm test
|
|
625
280
|
```
|
|
626
281
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
delivery, tools, and TUI status.
|
|
282
|
+
No bundled runtime dependencies — pi and TypeBox are peers. Source is split by
|
|
283
|
+
responsibility: dispatch/workflow policy, thread lifecycle, RPC transport,
|
|
284
|
+
worktree integration, completion delivery, tools, and TUI status.
|
|
631
285
|
|
|
632
286
|
## License
|
|
633
287
|
|
|
634
|
-
|
|
288
|
+
MIT
|