@ferris1225/pi-subagents 6.0.5 → 7.0.0
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/CHANGELOG.md +34 -0
- package/README.md +226 -265
- package/index.ts +13 -5
- package/package.json +11 -10
- package/src/configuration/config.ts +63 -159
- package/src/configuration/models.ts +11 -48
- package/src/configuration/setup.ts +69 -165
- package/src/configuration/ui.ts +60 -173
- package/src/delegation/builtin-agents.ts +5 -24
- package/src/delegation/dispatch.ts +17 -27
- package/src/delegation/orchestration.ts +22 -0
- package/src/delegation/prompt.ts +12 -6
- package/src/execution/run-control.ts +2 -4
- package/src/execution/spawn.ts +36 -160
- package/src/lifecycle/completion.ts +2 -13
- package/src/lifecycle/durable.ts +2 -7
- package/src/lifecycle/thread-lifecycle.ts +5 -5
- package/src/lifecycle/thread-shared.ts +7 -17
- package/src/presentation/announcements.ts +15 -17
- package/src/presentation/format.ts +5 -6
- package/src/configuration/role-migration.ts +0 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.0.0
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- Make lead/worker orchestration the only workflow. Main judges difficulty,
|
|
8
|
+
delegates simple bounded work by default, splits complex tasks or handles
|
|
9
|
+
their difficult core, and always reviews the actual diff and evidence.
|
|
10
|
+
Remove sentinel and the role matrix.
|
|
11
|
+
- Replace legacy configuration on startup with versioned worker settings:
|
|
12
|
+
one model and thinking preference shared by artisan and scout. Delete the
|
|
13
|
+
old config without a backup and direct users to `/subagents-setup`; preserve
|
|
14
|
+
sessions, worktrees, results, and recovery records.
|
|
15
|
+
- Remove automatic main-model worker retries. Provider failures return evidence
|
|
16
|
+
to main. An unavailable configured worker blocks dispatch and keeps its setting
|
|
17
|
+
instead of silently consuming main-model quota.
|
|
18
|
+
- Reject unreadable settings and invalid worker model references at dispatch,
|
|
19
|
+
while keeping main available to explain the problem.
|
|
20
|
+
- Require Pi >= 1.5.2 and align development SDKs to 1.5.2.
|
|
21
|
+
|
|
22
|
+
### Changes
|
|
23
|
+
|
|
24
|
+
- Simplify setup to Model, Thinking, and Reset with searchable pickers, compact
|
|
25
|
+
narrow-terminal hints, and Pi's blocked status while awaiting input.
|
|
26
|
+
- Keep live main/worker assignments separate from the stable prompt for caching.
|
|
27
|
+
Use compact briefs, preserved worker sessions, focused corrections, and reuse
|
|
28
|
+
of valid evidence to limit repeated work. Return invalid plans and repeated
|
|
29
|
+
failed fixes to main; worker completion explicitly requests main's review.
|
|
30
|
+
- Rewrite the README around the new workflow, breaking reset, budget tradeoffs,
|
|
31
|
+
prompt research, Pi APIs, controls, and recovery behavior.
|
|
32
|
+
- Prefer an exact configured provider reference over its alias regardless of
|
|
33
|
+
catalog order. Remove obsolete role migration and duplicate delivery logic.
|
|
34
|
+
- Bound test-file concurrency to four so native Windows shell probes do not
|
|
35
|
+
time out under process-heavy parallel suites; retain runtime concurrency tests.
|
|
36
|
+
|
|
3
37
|
## 6.0.5
|
|
4
38
|
|
|
5
39
|
### Fixes
|
package/README.md
CHANGED
|
@@ -1,292 +1,253 @@
|
|
|
1
1
|
# pi-subagents
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Lead/worker orchestration for [Pi](https://github.com/earendil-works/pi).
|
|
4
|
+
Your capable main model judges difficulty, plans, handles complex work, reviews
|
|
5
|
+
the actual changes, and owns the final answer. Cheaper workers execute simple,
|
|
6
|
+
bounded tasks with their own context, model, tools, and retained sessions.
|
|
7
|
+
|
|
8
|
+
Requires **Pi >= 1.5.2** and **Node.js >= 22.19.0**. Development and native CLI
|
|
9
|
+
integration tests use the **Pi 1.5.2 SDK**.
|
|
10
|
+
|
|
11
|
+
## Get started
|
|
12
|
+
|
|
13
|
+
1. Install the extension:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pi install npm:@ferris1225/pi-subagents
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Choose a capable main model with Pi's model selector; it always owns review.
|
|
20
|
+
3. Run `/subagents-setup` and select a capable, cost-effective worker model.
|
|
21
|
+
4. Give main your task. Orchestration is the default and only workflow.
|
|
22
|
+
|
|
23
|
+
The setup panel has three rows: **Model**, **Thinking**, and **Reset**.
|
|
24
|
+
Use ↑/↓ and Enter; Esc returns without changing a picker selection. Changes save
|
|
25
|
+
immediately. The model picker supports search, paste, paging, and Tab for details.
|
|
26
|
+
The menu keeps the current main model visible. Long values can be paged with
|
|
27
|
+
PgUp/PgDn, and the panel adapts to narrow terminals.
|
|
28
|
+
|
|
29
|
+
Workers initially **follow main** with **medium** thinking. Choose a separate
|
|
30
|
+
worker model to use a cheaper model for execution. The extension does not guess
|
|
31
|
+
model quality or promise savings from token prices. A saved thinking preference
|
|
32
|
+
survives model changes and is clamped to the chosen model's supported levels.
|
|
33
|
+
Reset restores Follow main and medium thinking.
|
|
34
|
+
|
|
35
|
+
The goal is to reduce expensive main-model usage, budget, and quota consumption.
|
|
36
|
+
Total tokens can increase because briefs, separate contexts, and review also cost
|
|
37
|
+
tokens. Judge savings by total task cost and main-model usage, including retries
|
|
38
|
+
and rework. Compact handoffs, retained worker sessions, reuse of valid checks, and
|
|
39
|
+
delegating execution are the mechanisms; no savings benchmark is claimed here.
|
|
40
|
+
|
|
41
|
+
## Upgrading to v7
|
|
42
|
+
|
|
43
|
+
**This is a breaking release.** On the first session start after upgrading, the
|
|
44
|
+
old `pi-subagents.json` is deleted and replaced with fresh worker settings.
|
|
45
|
+
Old per-role model/thinking values are discarded, with no legacy config backup.
|
|
46
|
+
Pi displays a notice directing you to `/subagents-setup`.
|
|
47
|
+
|
|
48
|
+
The old role matrix, optional delegation policy, independent reviewer, and
|
|
49
|
+
`sentinel` role are gone. Main performs review. Calls naming retired roles
|
|
50
|
+
are rejected.
|
|
51
|
+
|
|
52
|
+
Only the settings file is reset. Existing sessions, results, worktrees, and
|
|
53
|
+
recovery evidence remain protected. Retired-role records can still be inspected
|
|
54
|
+
or stopped; they do not create a supported reviewer role or resume automatically.
|
|
55
|
+
|
|
56
|
+
The new configuration is stored at `~/.pi/agent/pi-subagents.json`:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"version": 1,
|
|
61
|
+
"thinking": "medium"
|
|
62
|
+
}
|
|
63
|
+
```
|
|
5
64
|
|
|
6
|
-
|
|
65
|
+
Selecting a worker adds `model: "provider/model-id"`. This is one shared worker
|
|
66
|
+
setting, not a map of roles. `PI_CODING_AGENT_DIR` overrides the agent directory.
|
|
67
|
+
An unavailable or out-of-scope worker stays configured and blocks dispatch until
|
|
68
|
+
availability is restored or you select another model. Provider failures return
|
|
69
|
+
to main with evidence; the extension never starts a main-model worker as a retry.
|
|
70
|
+
Unreadable settings or an invalid model reference also stop new dispatches instead
|
|
71
|
+
of silently selecting main. Repair the file or run `/subagents-setup`.
|
|
72
|
+
|
|
73
|
+
## How orchestration works
|
|
74
|
+
|
|
75
|
+
1. **Main judges difficulty and plans.** It investigates the decisions that
|
|
76
|
+
determine the approach, resolves ambiguity, and defines acceptance criteria
|
|
77
|
+
and write boundaries. It splits complex tasks into simple worker briefs and
|
|
78
|
+
keeps the difficult core when delegation would create more rework.
|
|
79
|
+
2. **Workers execute.** Main sends a self-contained brief. Each worker owns a
|
|
80
|
+
bounded task and its checks, returning a compact result with changed paths,
|
|
81
|
+
verification evidence, and blockers.
|
|
82
|
+
3. **Main reviews.** After worktree integration, main checks the actual diff,
|
|
83
|
+
relevant callers, acceptance criteria, and test evidence. Worker completion
|
|
84
|
+
is explicitly marked as a review handoff, not approval.
|
|
85
|
+
4. **Main corrects or accepts.** Focused corrections go back to the owning worker
|
|
86
|
+
through its retained session. Main repairs an invalid plan or takes over when
|
|
87
|
+
assumptions fail. It owns final validation, release, and the user-facing answer.
|
|
88
|
+
|
|
89
|
+
Simple edits, fixes, tests, docs, and bounded research go to cheaper workers by
|
|
90
|
+
default. Main decides what is simple enough for the configured worker; there is
|
|
91
|
+
no keyword classifier or automatic model ranking. Complex or uncertain work can
|
|
92
|
+
stay in main. Review and final acceptance always stay in main, never in a cheap
|
|
93
|
+
reviewer. Main avoids repeating completed worker effort. Questions and review-only requests do not authorize
|
|
94
|
+
implementation. Explicit requests to work in main take precedence. Parallel workers require independent
|
|
95
|
+
scope and disjoint write ownership; a fix and its regression tests share an owner.
|
|
96
|
+
|
|
97
|
+
There are two worker tool scopes, both using the same model/thinking settings:
|
|
98
|
+
|
|
99
|
+
| Scope | Tool parameter | Access |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| Implementation | `artisan` | Parent's live tools, including codemode; implements and checks the plan |
|
|
102
|
+
| Read-only research | `scout` | Proven read-only lookups; no commands, builds, tests, or edits |
|
|
7
103
|
|
|
8
|
-
|
|
9
|
-
|
|
104
|
+
The read-only scope preserves a tool boundary for research. It is not a separate
|
|
105
|
+
reviewer. Children cannot delegate or release. Main and workers exchange briefs,
|
|
106
|
+
results, and feedback, rather than copying the parent's full conversation.
|
|
10
107
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
108
|
+
Planning, review, and the instruction to return after two unsuccessful fixes
|
|
109
|
+
are model instructions, not a runtime verdict engine or a hard retry counter.
|
|
110
|
+
Cancellation, role admission, tool boundaries, and worktree lifecycle are enforced
|
|
111
|
+
by the extension. No automatic review score certifies a worker's result.
|
|
14
112
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
reference, effective reasoning level, requested level when clamped, and
|
|
21
|
-
default/override source. Each selection saves immediately; Esc returns without
|
|
22
|
-
applying a picker selection and keeps focus. Model pickers support search,
|
|
23
|
-
paste, and paging. On short terminals, PgUp/PgDn scrolls the settings while the
|
|
24
|
-
selected role and field stay pinned.
|
|
25
|
-
|
|
26
|
-
All roles follow the main model by default; thinking defaults to `low` for scout
|
|
27
|
-
and `high` for artisan and sentinel. The panel distinguishes defaults from overrides and
|
|
28
|
-
shows the effective level when model capabilities clamp a preference. Changing
|
|
29
|
-
a model preserves the thinking preference. Settings live in
|
|
30
|
-
`~/.pi/agent/pi-subagents.json` as `agentModels` and `agentThinkingLevels`.
|
|
31
|
-
Session start removes a model override that no authenticated provider offers
|
|
32
|
-
anymore; an override outside the session's model scope is kept and only skipped
|
|
33
|
-
while routing that session.
|
|
34
|
-
|
|
35
|
-
## Agents
|
|
36
|
-
|
|
37
|
-
| Agent | Use for | Access |
|
|
38
|
-
| --- | --- | --- |
|
|
39
|
-
| `scout` | Code, documentation, and web research with citations | Read-only tools; no commands or edits |
|
|
40
|
-
| `artisan` | Implementation and fixes with tests and checks | Parent's tool surface, including codemode |
|
|
41
|
-
| `sentinel` | Inspect an implementation or diff and challenge claims or assumptions for defects and regressions | Parent's tool surface; instructed not to edit |
|
|
42
|
-
|
|
43
|
-
The main model chooses from these role descriptions; names alone do not route a
|
|
44
|
-
task. Use `sentinel` to inspect implementations/diffs or challenge a specific claim
|
|
45
|
-
or assumption with counterexamples and focused checks.
|
|
46
|
-
|
|
47
|
-
Sentinel may run focused checks, so its no-edit boundary is an instruction, not
|
|
48
|
-
a tool-enforced restriction. Change reviews focus on introduced defects; a wider
|
|
49
|
-
audit needs an explicit brief. All roles reuse existing facts and valid checks,
|
|
50
|
-
filling gaps rather than repeating main or upstream work.
|
|
51
|
-
|
|
52
|
-
Only `scout`, `artisan`, and `sentinel` are valid runtime role names.
|
|
53
|
-
Existing model/thinking settings and interrupted run records migrate on load
|
|
54
|
-
(`reviewer`, `critic`, and `skeptic` map to `sentinel`) and are saved with the
|
|
55
|
-
current names. Explicit valid settings under the current names win. Custom roles
|
|
56
|
-
are not supported. Retained records from older releases remain available for recovery.
|
|
57
|
-
|
|
58
|
-
Children receive a self-contained brief and project instructions, but no parent
|
|
59
|
-
conversation. They cannot delegate or release. Main owns planning, integration,
|
|
60
|
-
and the final result. Keep a fix and its regression tests with one owner.
|
|
61
|
-
|
|
62
|
-
## Delegate
|
|
63
|
-
|
|
64
|
-
Pi proactively looks for useful bounded phases to delegate; no special request
|
|
65
|
-
is required. Focused ownership, isolated context, parallel progress, and an
|
|
66
|
-
independent check can each justify a child. A substantial self-contained fix can
|
|
67
|
-
go to one artisan together with its regression tests, even when there is nothing
|
|
68
|
-
to parallelize. Quick source checks and small understood edits stay in main.
|
|
69
|
-
Choose team size from independent work. Explicit requests to work in main or
|
|
70
|
-
avoid subagents take precedence.
|
|
71
|
-
|
|
72
|
-
Use one owner per deliverable, including its regression tests. Brief the child
|
|
73
|
-
with the outcome, done condition, relevant paths, established evidence, write
|
|
74
|
-
boundaries, required checks, and a compact expected result. Scout retrieves
|
|
75
|
-
sources; artisan implements, while sentinel can execute focused checks. This policy applies the context-isolation,
|
|
76
|
-
focused-role, and coordination-cost guidance in the official
|
|
77
|
-
[Codex subagents](https://developers.openai.com/codex/subagents) and
|
|
78
|
-
[Claude Code subagents](https://code.claude.com/docs/en/sub-agents) docs to Pi's
|
|
79
|
-
one-shot leaf runs.
|
|
80
|
-
|
|
81
|
-
A review request produces findings. Main applies fixes when changes are
|
|
82
|
-
authorized and requests focused confirmation only when material uncertainty
|
|
83
|
-
remains. Before reporting success, main checks each done condition and any
|
|
84
|
-
blockers in the child's answer as well as the integrated diff.
|
|
85
|
-
|
|
86
|
-
Ask Pi to delegate explicitly, or call the tool directly:
|
|
113
|
+
## Briefs and calls
|
|
114
|
+
|
|
115
|
+
A useful brief names the **outcome**, **acceptance criteria**, **relevant paths and
|
|
116
|
+
evidence**, **write boundary**, **checks**, **return conditions**, and **expected
|
|
117
|
+
result**. Pass established facts forward and assign only missing work.
|
|
87
118
|
|
|
88
119
|
```ts
|
|
89
120
|
subagent({
|
|
90
121
|
agent: "artisan",
|
|
91
|
-
task:
|
|
122
|
+
task: [
|
|
123
|
+
"Fix cache invalidation in src/cache.ts and its regression test.",
|
|
124
|
+
"Acceptance: a write invalidates the matching key without clearing unrelated keys.",
|
|
125
|
+
"Evidence: the stale read starts in Cache.get; keep the current public API.",
|
|
126
|
+
"Write only src/cache.ts and test/cache.test.ts.",
|
|
127
|
+
"Run the cache tests. Return to main if the storage interface contradicts this plan.",
|
|
128
|
+
"Report the outcome, changed paths, command/results, and blockers for main's review.",
|
|
129
|
+
].join("\n"),
|
|
130
|
+
wait: true,
|
|
92
131
|
});
|
|
93
132
|
```
|
|
94
133
|
|
|
95
|
-
Independent tasks can
|
|
134
|
+
Independent tasks use `tasks: [{ agent, task }, ...]`. Each task can also specify
|
|
135
|
+
`cwd` and `isolation`. Duplicate normalized tasks in the same cwd are rejected
|
|
136
|
+
while active or settled; reuse the result or continue the existing work.
|
|
96
137
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
task: "Fix config validation and its regression tests.",
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
agent: "artisan",
|
|
106
|
-
task: "Update docs/providers.md from the established API citations.",
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
```
|
|
138
|
+
Use `wait: true` for an immediate dependency. Print/JSON sessions wait by
|
|
139
|
+
default; TUI/RPC sessions return background receipts. A launch receipt is not
|
|
140
|
+
completion. Main continues independent work, then pauses until results arrive.
|
|
141
|
+
Results are delivered once, after integration. Awaited failures are tool errors.
|
|
142
|
+
Answers exceeding 40 lines or 8,000 characters link their full-result artifact.
|
|
111
143
|
|
|
112
|
-
|
|
113
|
-
`subagent_message` follow-ups default to waiting in one-shot `pi -p` / JSON sessions,
|
|
114
|
-
so the parent stays alive until the work finishes. TUI and RPC sessions default
|
|
115
|
-
to background delivery; `wait: false` explicitly selects it in any mode. Each
|
|
116
|
-
result is delivered once, after integration, either in the waiting tool call or
|
|
117
|
-
as a background completion. Awaited failures are tool errors with retained evidence.
|
|
118
|
-
An answer longer than 40 lines or 8,000 characters is not inlined; its delivery
|
|
119
|
-
names the full-result file instead.
|
|
120
|
-
|
|
121
|
-
A launch receipt only confirms delegation and lists every started run id. Main
|
|
122
|
-
continues independent work or pauses until the completion wakes it, then
|
|
123
|
-
finishes the requested outcome and final checks. It does not poll or treat a
|
|
124
|
-
successful launch as task completion.
|
|
125
|
-
Equal normalized tasks in the same cwd are rejected as duplicates while active
|
|
126
|
-
or settled in the current session. Reuse the result, or use `subagent_message`
|
|
127
|
-
for an additional bounded step.
|
|
128
|
-
|
|
129
|
-
## Status, cancellation, and recovery
|
|
130
|
-
|
|
131
|
-
| Tool | Use |
|
|
144
|
+
| Tool | Purpose |
|
|
132
145
|
| --- | --- |
|
|
133
|
-
| `subagent_status({ id: 12 })` | Inspect
|
|
134
|
-
| `subagent_message({ id: 12, message: "
|
|
135
|
-
| `subagent_message({ id: 12, message: "
|
|
146
|
+
| `subagent_status({ id: 12 })` | Inspect progress, result, session availability, and recovery paths |
|
|
147
|
+
| `subagent_message({ id: 12, message: "Fix the remaining edge case", wait: true })` | Steer an active worker or continue completed work |
|
|
148
|
+
| `subagent_message({ id: 12, message: "Next bounded task", context: "summary" })` | Start from a compact summary instead of the earlier transcript |
|
|
136
149
|
| `subagent_stop({ id: "12" })` | Stop a run and retire its retained session |
|
|
137
|
-
| `subagent_stop({ all: true })` | Stop all active
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
caller's directory
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Each worktree
|
|
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
|
-
|
|
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
|
-
A settled provider failure can hand off once to the main model in the same
|
|
225
|
-
session. State and full-result files live under
|
|
226
|
-
`~/.pi/agent/ferris-pi-subagents/`, grouped by project. `PI_CODING_AGENT_DIR`
|
|
227
|
-
overrides the agent directory.
|
|
228
|
-
|
|
229
|
-
## Pi codemode compatibility
|
|
230
|
-
|
|
231
|
-
Call `subagent` and the control tools directly. They use Pi's `model-only`
|
|
232
|
-
exposure and are intentionally unavailable as nested `tools.subagent(...)` calls
|
|
233
|
-
inside codemode. Children can still use codemode with their inherited callable
|
|
234
|
-
tools. Indirect tools retain their exposure; scout promotes approved read-only
|
|
235
|
-
tools for direct use. It waits up to ten seconds for startup registration and
|
|
236
|
-
activates later arrivals between turns. Read-only classification uses Pi tool
|
|
237
|
-
metadata.
|
|
238
|
-
|
|
239
|
-
Child RPC dialogs that require confirmation, selection, or text input are
|
|
240
|
-
cancelled with a matching response and an explanation, so an unattended child
|
|
241
|
-
does not hang waiting for an invisible dialog. No confirmation is approved
|
|
242
|
-
automatically.
|
|
243
|
-
|
|
244
|
-
## Storage and cleanup
|
|
245
|
-
|
|
246
|
-
Each project root holds `sessions/`, `worktrees/`, `tmp/` and `results/`. Startup
|
|
247
|
-
hygiene already drops temp leftovers, artifacts whose Pi process is gone, result
|
|
248
|
-
files past their retention window, and project roots idle for three days. Parked
|
|
249
|
-
recovery work and manifest references are protected during these sweeps.
|
|
250
|
-
Interrupted checkpoints expire after 30 days when no recorded owner or child
|
|
251
|
-
from the current boot is alive; expired checkpoints are pruned before restore.
|
|
252
|
-
Missing session files do not erase validated recovery paths. Unreadable or
|
|
253
|
-
malformed manifests leave artifacts intact and skip automatic reclamation;
|
|
254
|
-
explicit cleanup reports the error. Startup warns about failed recovery inspection
|
|
255
|
-
and continues initializing the progress widget.
|
|
256
|
-
|
|
257
|
-
Reclamation is automatic: a settlement may trigger one paced sweep (at most every
|
|
258
|
-
five minutes) that drops dead-owner artifacts, expired result files, and settled
|
|
259
|
-
session copies older than 30 minutes, then trims the oldest settled sessions
|
|
260
|
-
until a project fits its 1.5 GB budget. Under budget pressure, settled sessions
|
|
261
|
-
older than five minutes can be removed. Live runs, parked recovery work, and
|
|
262
|
-
manifest references remain protected. Automatic follow-ups use the retained
|
|
263
|
-
summary when a completed run's transcript has expired. Session shutdown waits
|
|
264
|
-
for cleanup already in progress and prevents new settlement sweeps.
|
|
265
|
-
|
|
266
|
-
`/subagents-cleanup` immediately reclaims unclaimed dead-owner artifacts and idle
|
|
267
|
-
project roots, reporting usage and freed bytes. `/subagents-cleanup dry-run`
|
|
268
|
-
measures without deleting anything; any other argument is rejected without
|
|
269
|
-
deleting. Session age and budget reclamation runs automatically on settlement.
|
|
150
|
+
| `subagent_stop({ all: true })` | Stop all active work in this session |
|
|
151
|
+
|
|
152
|
+
Follow-ups use `context: "auto"` by default: a private copy of the retained session,
|
|
153
|
+
or an explicit summary fallback when it expired. `context: "session"` requires full
|
|
154
|
+
history. Continuations retain the session ID/cache key and re-read files in their
|
|
155
|
+
current workspace. Summary continuations cannot rely on omitted history.
|
|
156
|
+
|
|
157
|
+
Steering waits for a matching RPC acknowledgement. Received/queued means Pi queued
|
|
158
|
+
the instruction, not that the model acted on it. A rejected or missing
|
|
159
|
+
acknowledgement is an error. Failed or interrupted runs require main to inspect
|
|
160
|
+
partial work; they do not restart automatically.
|
|
161
|
+
|
|
162
|
+
## Isolation and control
|
|
163
|
+
|
|
164
|
+
Implementation uses a detached Git worktree by default, even for one worker.
|
|
165
|
+
Read-only research uses the caller's directory. Without a Git repository or
|
|
166
|
+
committed HEAD, automatic isolation reports a shared-directory fallback.
|
|
167
|
+
Explicit `isolation: "worktree"` requires isolation; `"shared"` writes directly
|
|
168
|
+
in the caller's checkout.
|
|
169
|
+
|
|
170
|
+
Each worktree snapshots current tracked and non-ignored untracked files,
|
|
171
|
+
including uncommitted work. The child is told how original paths map into its
|
|
172
|
+
worktree. Integration applies only its delta, is serialized per repository,
|
|
173
|
+
and preserves the caller's index, branch, and HEAD. Failures retain recovery
|
|
174
|
+
artifacts. Worktrees isolate Git changes, not permissions.
|
|
175
|
+
|
|
176
|
+
Escape cancels unfinished workers without waking main. Main receives a cancellation
|
|
177
|
+
receipt on the next user turn. Tree navigation, new/resume/fork/reload, and shutdown
|
|
178
|
+
stop old work; interrupted evidence remains available for recovery.
|
|
179
|
+
|
|
180
|
+
The task widget shows status, elapsed time, model, thinking, tokens, and worktree
|
|
181
|
+
state in at most ten lines. Independent workers can start together; only
|
|
182
|
+
integration into the original checkout is serialized.
|
|
183
|
+
|
|
184
|
+
## Pi integration
|
|
185
|
+
|
|
186
|
+
Workers run the native Pi CLI in RPC mode with piped I/O and retained sessions.
|
|
187
|
+
Delegation/control tools are model-only: call them directly, outside codemode.
|
|
188
|
+
Workers inherit reachable tools without activating unrelated direct tools; scout
|
|
189
|
+
gets only tools whose metadata proves them read-only.
|
|
190
|
+
|
|
191
|
+
Unattended confirmation/input dialogs are cancelled, never auto-approved. Windows
|
|
192
|
+
child processes and their Node descendants use the existing hidden-console
|
|
193
|
+
policy; process-tree cancellation remains active on every supported platform.
|
|
194
|
+
A provider failure returns control and evidence to main without an automatic
|
|
195
|
+
upgrade to main's model. Pi's own same-model retry behavior remains unchanged.
|
|
196
|
+
|
|
197
|
+
[Pi 1.5.2](https://github.com/earendil-works/pi/blob/v1.5.2/packages/coding-agent/CHANGELOG.md)
|
|
198
|
+
fixes sessions whose original directory disappeared. Private continuation
|
|
199
|
+
copies still rebind their cwd while retaining their session ID. Pi 1.5.1 added
|
|
200
|
+
message threads, idle cache warming, and classifier access through
|
|
201
|
+
`ctx.modelRegistry.classify()`. This extension keeps Pi's provider behavior and
|
|
202
|
+
cache settings; exited workers do not keep warming caches between runs.
|
|
203
|
+
Classifier routing is not used: main makes the plan after investigation.
|
|
204
|
+
The settings modal uses Pi's `blocked` status while awaiting input.
|
|
205
|
+
|
|
206
|
+
## Storage
|
|
207
|
+
|
|
208
|
+
Durable data lives under `~/.pi/agent/ferris-pi-subagents/`, grouped by project:
|
|
209
|
+
sessions, worktrees, temporary state, and result artifacts.
|
|
210
|
+
|
|
211
|
+
Startup and paced settlement cleanup reclaim dead-owner artifacts, expired results,
|
|
212
|
+
and old settled sessions. Settled session retention is normally 30 minutes with
|
|
213
|
+
a 1.5 GB project budget; budget pressure can remove sessions older than five
|
|
214
|
+
minutes. Interrupted records expire after 30 days when their recorded processes
|
|
215
|
+
are no longer alive. Live work, parked recovery, and referenced artifacts are
|
|
216
|
+
protected. Unreadable manifests prevent reclamation.
|
|
217
|
+
|
|
218
|
+
`/subagents-cleanup dry-run` reports usage; `/subagents-cleanup` reclaims eligible
|
|
219
|
+
artifacts. Unknown arguments are rejected. Shutdown drains cleanup already running.
|
|
220
|
+
|
|
221
|
+
## Design references
|
|
222
|
+
|
|
223
|
+
The prompt policy draws on these official descriptions:
|
|
224
|
+
|
|
225
|
+
- [Devin Fusion](https://cognition.com/blog/local-fusion): separate lead/worker
|
|
226
|
+
contexts, compact briefs and feedback, and lead-owned review.
|
|
227
|
+
- [Antigravity Orchestrator](https://antigravity.google/docs/models#orchestrator):
|
|
228
|
+
planning, execution, and returning control when the plan needs repair.
|
|
229
|
+
- [Anthropic's multi-agent engineering](https://www.anthropic.com/research/multi-agent-research-system):
|
|
230
|
+
explicit objectives, output formats, sources, boundaries, and effort proportional to the task.
|
|
231
|
+
- [Context engineering](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents):
|
|
232
|
+
focused instructions and small, relevant context.
|
|
233
|
+
|
|
234
|
+
These inform this extension's design; benchmark savings from other products do
|
|
235
|
+
not establish savings here. Local tests verify routing, delivery, isolation, and
|
|
236
|
+
UI behavior, not comparative model quality or cost.
|
|
270
237
|
|
|
271
238
|
## Development
|
|
272
239
|
|
|
273
|
-
Runtime code lives under `src/`; the package has no skill or workflow resource
|
|
274
|
-
directories. Built-in prompts change with the code and its tests.
|
|
275
|
-
|
|
276
|
-
| Module | Responsibility |
|
|
277
|
-
| --- | --- |
|
|
278
|
-
| `delegation/` | Built-in roles, parent routing prompt, and duplicate-dispatch admission |
|
|
279
|
-
| `configuration/` | Model and thinking settings, plus the standalone setup modal panel |
|
|
280
|
-
| `presentation/` | Running task board, activity, status, and result formatting |
|
|
281
|
-
| `execution/`, `lifecycle/`, `isolation/` | Child processes, durable state, cancellation, worktrees, and recovery |
|
|
282
|
-
|
|
283
240
|
```bash
|
|
284
241
|
npm ci
|
|
285
242
|
npm run check
|
|
286
243
|
```
|
|
287
244
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
245
|
+
Runtime modules live in `src/`: configuration/UI, orchestration prompts,
|
|
246
|
+
execution, lifecycle, isolation/recovery, and presentation. Native integration tests
|
|
247
|
+
use a local fixture provider and do not consume paid model requests.
|
|
248
|
+
|
|
249
|
+
Pushes of an unpublished version to `main` run checks on Windows, macOS, and
|
|
250
|
+
Linux, then [publish to npm and create a GitHub Release](./.github/workflows/publish.yml).
|
|
251
|
+
Do not publish locally.
|
|
291
252
|
|
|
292
253
|
[Changelog](./CHANGELOG.md) · [MIT license](./LICENSE)
|
package/index.ts
CHANGED
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
|
|
22
22
|
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
23
23
|
import { Text } from "@earendil-works/pi-tui";
|
|
24
|
-
import { getConfigPath } from "./src/configuration/config.ts";
|
|
24
|
+
import { errorMessage, getConfigPath, loadConfig } from "./src/configuration/config.ts";
|
|
25
25
|
import { runSetup } from "./src/configuration/setup.ts";
|
|
26
26
|
import { loadBuiltinAgents } from "./src/delegation/agents.ts";
|
|
27
27
|
import { registerSubagentTool } from "./src/delegation/dispatch.ts";
|
|
28
28
|
import { buildDelegationDirective, installDelegationSections } from "./src/delegation/prompt.ts";
|
|
29
|
+
import { buildOrchestrationSection } from "./src/delegation/orchestration.ts";
|
|
29
30
|
import { currentSubagentDepth, getSubagentsRoot } from "./src/execution/spawn.ts";
|
|
30
31
|
import { createDispatchCore } from "./src/lifecycle/dispatch-core.ts";
|
|
31
32
|
import { registerCancellationHooks } from "./src/lifecycle/cancellation.ts";
|
|
@@ -73,7 +74,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
73
74
|
registerCancellationHooks(pi, runtime);
|
|
74
75
|
|
|
75
76
|
pi.registerCommand("subagents-setup", {
|
|
76
|
-
description: "Configure
|
|
77
|
+
description: "Configure the worker model and thinking level",
|
|
77
78
|
handler: async (_args, ctx) => {
|
|
78
79
|
await runSetup(ctx, configPath);
|
|
79
80
|
},
|
|
@@ -112,16 +113,23 @@ export default function (pi: ExtensionAPI): void {
|
|
|
112
113
|
|
|
113
114
|
// Install the routing contract as prompt sections when the host can diff them.
|
|
114
115
|
// A full systemPrompt return forces an opaque prompt and invalidates the cache.
|
|
115
|
-
pi.on("before_agent_start", async (event) => {
|
|
116
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
116
117
|
await runtime.durableRestore;
|
|
117
118
|
const agents = loadBuiltinAgents();
|
|
118
119
|
const sources = [...runtime.threads.values()];
|
|
120
|
+
let orchestration: string;
|
|
121
|
+
try {
|
|
122
|
+
orchestration = buildOrchestrationSection(await loadConfig(configPath), ctx);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
orchestration = "Worker dispatch is paused because settings could not be loaded: " + errorMessage(error)
|
|
125
|
+
+ " Repair the settings or run /subagents-setup. Do not substitute main-model workers.";
|
|
126
|
+
}
|
|
119
127
|
const sections = event.systemPromptOptions?.sections;
|
|
120
128
|
if (sections) {
|
|
121
|
-
installDelegationSections(sections, agents, sources);
|
|
129
|
+
installDelegationSections(sections, agents, sources, orchestration);
|
|
122
130
|
return undefined;
|
|
123
131
|
}
|
|
124
|
-
const directive = buildDelegationDirective(agents, sources);
|
|
132
|
+
const directive = buildDelegationDirective(agents, sources, orchestration);
|
|
125
133
|
if (!directive) return undefined;
|
|
126
134
|
return { systemPrompt: `${event.systemPrompt}\n${directive}` };
|
|
127
135
|
});
|