@ftrdotdev/pi-delegates 0.0.0-stage → 0.2.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 +128 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +130 -0
- package/README.md +456 -2
- package/ROADMAP.md +179 -0
- package/TESTING.md +896 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +94 -4
- package/skills/pi-delegates/SKILL.md +176 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +184 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +163 -0
- package/src/domain/failure.ts +33 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1332 -0
- package/src/domain/orchestration/control.ts +457 -0
- package/src/domain/orchestration/fanout.test.ts +524 -0
- package/src/domain/orchestration/fanout.ts +372 -0
- package/src/domain/orchestration/gates.test.ts +685 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +372 -0
- package/src/domain/orchestration/launch.ts +691 -0
- package/src/domain/orchestration/requests.test.ts +695 -0
- package/src/domain/orchestration/requests.ts +782 -0
- package/src/domain/orchestration/review.test.ts +292 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +265 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1566 -0
- package/src/domain/orchestration/workflow.ts +778 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +689 -0
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +185 -0
- package/src/domain/skills.test.ts +477 -0
- package/src/domain/skills.ts +114 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +215 -0
- package/src/domain/toolkit.ts +374 -0
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +803 -0
- package/src/domain/view.ts +491 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +485 -0
- package/src/extension/commands.ts +230 -0
- package/src/extension/entry.test.ts +1276 -0
- package/src/extension/entry.ts +380 -0
- package/src/extension/gate-alerts.test.ts +237 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1343 -0
- package/src/extension/inspector-command.ts +685 -0
- package/src/extension/prompt.test.ts +108 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +62 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +1294 -0
- package/src/extension/tools.ts +553 -0
- package/src/extension/version.test.ts +115 -0
- package/src/extension/version.ts +97 -0
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +76 -0
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +170 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +386 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +359 -0
- package/src/presentation/inspector.test.ts +682 -0
- package/src/presentation/inspector.ts +442 -0
- package/src/presentation/overlay.test.ts +553 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +365 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +535 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +203 -0
- package/src/presentation/strip.ts +67 -0
- package/src/presentation/wording.test.ts +388 -0
- package/src/presentation/wording.ts +294 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +128 -0
- package/src/runtime/clock.test.ts +31 -0
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +63 -0
- package/src/runtime/config.ts +92 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +33 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +152 -0
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +140 -0
- package/src/runtime/log.ts +91 -0
- package/src/runtime/mcp.test.ts +1450 -0
- package/src/runtime/mcp.ts +1005 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +352 -0
- package/src/runtime/session.ts +263 -0
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
package/TESTING.md
ADDED
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
# Testing pi-delegates in a new session
|
|
2
|
+
|
|
3
|
+
This checklist runs a local checkout without publishing the package. It covers
|
|
4
|
+
every shipped feature: delegation, fanout, review, gates, control, admission,
|
|
5
|
+
skills, workflows, MCP servers, late revocation and the inspector.
|
|
6
|
+
|
|
7
|
+
Run the checks in order in one session. Each check names the prompt to inject
|
|
8
|
+
and the expected result, so a failure names one feature. Checks that cannot be
|
|
9
|
+
forced by hand are in [Automated-only checks](#automated-only-checks).
|
|
10
|
+
|
|
11
|
+
| Prefix | Feature |
|
|
12
|
+
| ------ | --------------------------------------------- |
|
|
13
|
+
| `C` | Session basics, commands, one launch, restart |
|
|
14
|
+
| `F` | Fanout and review |
|
|
15
|
+
| `G` | Gates, alerts and control |
|
|
16
|
+
| `A` | Admission caps |
|
|
17
|
+
| `T` | Toolkit resolution and pattern grammar |
|
|
18
|
+
| `S` | Skills |
|
|
19
|
+
| `W` | Workflows |
|
|
20
|
+
| `M` | MCP servers |
|
|
21
|
+
| `R` | Late revocation |
|
|
22
|
+
| `L` | Failure log |
|
|
23
|
+
| `Q` | Questions from a delegate |
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
- Pi `^1.6.0` on `PATH`.
|
|
28
|
+
- Node `22.19.0` or newer.
|
|
29
|
+
- Dependencies installed. Run `bun install` at the repository root.
|
|
30
|
+
- A model and login already configured in `~/.pi/agent`. This checklist keeps
|
|
31
|
+
that configuration and redirects only the session store.
|
|
32
|
+
|
|
33
|
+
Back up the two agent files the checks edit, then restore them in
|
|
34
|
+
[Cleanup](#cleanup). Stop if a copy fails: cleanup deletes a file with no
|
|
35
|
+
backup.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
if [ -f ~/.pi/agent/mcp.json ]; then cp ~/.pi/agent/mcp.json ~/.pi/agent/mcp.json.bak; fi
|
|
39
|
+
if [ -f ~/.pi/agent/delegates.json ]; then cp ~/.pi/agent/delegates.json ~/.pi/agent/delegates.json.bak; fi
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 1. Isolate the session
|
|
43
|
+
|
|
44
|
+
Create a scratch working directory and a separate session store:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
mkdir -p /tmp/pi-delegates-test/repo /tmp/pi-delegates-test/sessions
|
|
48
|
+
cd /tmp/pi-delegates-test/repo
|
|
49
|
+
git init
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`git init` gives the child tools a repository to read. Add files for the read
|
|
53
|
+
checks:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
printf 'hello\n' > note.txt
|
|
57
|
+
printf 'alpha\n' > alpha.txt
|
|
58
|
+
printf 'beta\n' > beta.txt
|
|
59
|
+
printf 'hunter2\n' > vault.txt
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 2. Fixtures
|
|
63
|
+
|
|
64
|
+
Copy every fixture under `/tmp/pi-delegates-test`, outside the checkout, so a
|
|
65
|
+
check never changes the repository. The files live in `scripts/manual/` in the
|
|
66
|
+
checkout.
|
|
67
|
+
|
|
68
|
+
### 2.1 The fixture package
|
|
69
|
+
|
|
70
|
+
Copy the package, then install the checkout into it:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
mkdir -p /tmp/pi-delegates-test
|
|
74
|
+
cp -R <checkout>/packages/delegates/scripts/manual/pi-delegates-local \
|
|
75
|
+
/tmp/pi-delegates-test/pi-delegates-local
|
|
76
|
+
cd /tmp/pi-delegates-test/pi-delegates-local
|
|
77
|
+
npm install <checkout>/packages/delegates
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`delegates.ts` registers the nine test agents, and each comment names the checks
|
|
81
|
+
that use the agent. The package depends on the checkout, so no build or publish
|
|
82
|
+
step is needed.
|
|
83
|
+
|
|
84
|
+
### 2.2 The demo MCP servers
|
|
85
|
+
|
|
86
|
+
Copy both servers into the scratch repository:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
cp -R <checkout>/packages/delegates/scripts/manual/repo/. /tmp/pi-delegates-test/repo/
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`mcp-server.mjs` offers `echo`, `add`, `big` (25 KiB) and `slow` (never answers).
|
|
93
|
+
`mcp-http-server.mjs` answers on `127.0.0.1:8765` for `M8`.
|
|
94
|
+
|
|
95
|
+
### 2.3 The MCP config
|
|
96
|
+
|
|
97
|
+
Copy the config to `~/.pi/agent/mcp.json`. `direct` exposure makes `M1` one plain
|
|
98
|
+
tool call:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
cp <checkout>/packages/delegates/scripts/manual/mcp.json ~/.pi/agent/mcp.json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 2.4 The skill
|
|
105
|
+
|
|
106
|
+
Copy the skill only when `S2` says so. `S1` runs without it:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
mkdir -p /tmp/pi-delegates-test/repo/.pi/skills
|
|
110
|
+
cp -R <checkout>/packages/delegates/scripts/manual/release-notes \
|
|
111
|
+
/tmp/pi-delegates-test/repo/.pi/skills/
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 2.5 Start Pi
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
cd /tmp/pi-delegates-test/repo
|
|
118
|
+
pi -ne --session-dir /tmp/pi-delegates-test/sessions \
|
|
119
|
+
-e /tmp/pi-delegates-test/pi-delegates-local \
|
|
120
|
+
-e <checkout>/packages/inquiry \
|
|
121
|
+
--skill <checkout>/packages/delegates/skills/pi-delegates
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- `-e` loads the fixture package, which imports the checkout.
|
|
125
|
+
- `-e <checkout>/packages/inquiry` loads the `question` tool the parent model
|
|
126
|
+
uses in `Q2`. `-ne` alone leaves it out, so `Q2` cannot test the dialog path.
|
|
127
|
+
- `-ne` disables other extensions, so a globally installed copy cannot load
|
|
128
|
+
twice and `pi-subagents` cannot block. `R1` removes `-ne` on purpose.
|
|
129
|
+
- `--skill` loads the shipped agent skill. `-e` does not load it.
|
|
130
|
+
- `--session-dir` keeps the test sessions out of your normal store.
|
|
131
|
+
|
|
132
|
+
Do not also pass `-e <checkout>/packages/delegates`: two copies register the
|
|
133
|
+
tools twice.
|
|
134
|
+
|
|
135
|
+
## 3. Session basics (`C`)
|
|
136
|
+
|
|
137
|
+
Inject each prompt by asking the model to call the named tool. The model may
|
|
138
|
+
wrap a call in prose; the expected text is what the tool returns.
|
|
139
|
+
|
|
140
|
+
**`C1` — the listing.** Run `/delegates:list`. Expect one line per definition:
|
|
141
|
+
the three presets and the nine fixtures, in this order:
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
scout — Read-only explorer — tools: read — skills: none — gates: none
|
|
145
|
+
builder — Implementation agent — tools: read, bash, write, edit — skills: none — gates: none
|
|
146
|
+
reviewer — Review agent — tools: read — skills: none — gates: none
|
|
147
|
+
vault-scout — Gated vault scout — tools: read, bash — skills: none — gates: vault-access
|
|
148
|
+
composer — Workflow composer — tools: read — skills: none — gates: none
|
|
149
|
+
skilled — Skill reader — tools: read — skills: release-notes — gates: none
|
|
150
|
+
mcp-scout — MCP caller — tools: read, mcp__demo__* — skills: none — gates: none
|
|
151
|
+
docs-scout — HTTP MCP caller — tools: read, mcp__docs__* — skills: none — gates: none
|
|
152
|
+
broken — Broken toolkit — tools: read — skills: none — gates: none
|
|
153
|
+
greedy — Broad pattern — tools: read, mcp__* — skills: none — gates: none
|
|
154
|
+
absent-scout — Unknown namespace — tools: read, mcp__absent__* — skills: none — gates: none
|
|
155
|
+
env-scout — Environment scout — tools: read, ask — skills: none — gates: none
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**`C2` — the empty status.** `delegate_status` with `{}`. Expect
|
|
159
|
+
`No delegation runs in this session.`
|
|
160
|
+
|
|
161
|
+
**`C3` — one launch.** `delegate_launch` with:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"request": {
|
|
166
|
+
"kind": "single",
|
|
167
|
+
"agent": "scout",
|
|
168
|
+
"task": "read note.txt and reply with its only line"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Expect `hello`. A reply that says `No execution environment is configured`
|
|
174
|
+
means the runtime dropped its `env` option. In that case every read, write and
|
|
175
|
+
bash call inside a delegate fails.
|
|
176
|
+
|
|
177
|
+
**`C4` — the run row.** `delegate_status` with `{ "run": "<run id>" }`.
|
|
178
|
+
Expect the run line `<run id> scout · answered: hello` and no lane line.
|
|
179
|
+
|
|
180
|
+
**`C5` — the session listing.** Run `/delegates:list` again. Expect the run row
|
|
181
|
+
and the lane line `default: running 0, queued 0, answered 1`.
|
|
182
|
+
|
|
183
|
+
**`C6` — the inspector.** Press `ctrl+space`. Expect the overlay with the
|
|
184
|
+
agents and the run. Expect the footer
|
|
185
|
+
`enter/i inspect · s stop · a approve · d deny · esc close`. Press `escape`.
|
|
186
|
+
Run `/delegates`. Expect the overlay again. Run `/delegates` once more. Expect
|
|
187
|
+
it to close.
|
|
188
|
+
|
|
189
|
+
**`C7` — the shipped skill.** Run `/skill:pi-delegates`. Expect the
|
|
190
|
+
when-to-delegate rules, the launch shapes and the note that an MCP pattern must
|
|
191
|
+
name its server.
|
|
192
|
+
|
|
193
|
+
**`C8` — write access.** `delegate_launch` with a builder:
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"request": {
|
|
198
|
+
"kind": "single",
|
|
199
|
+
"agent": "builder",
|
|
200
|
+
"task": "create built.txt in the working directory with the word done in it, then reply with done"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Expect `done` and `/tmp/pi-delegates-test/repo/built.txt` holding `done`.
|
|
206
|
+
|
|
207
|
+
## 4. Fanout and review (`F`)
|
|
208
|
+
|
|
209
|
+
**`F1` — a fanout.** `delegate_launch` with:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"request": {
|
|
214
|
+
"kind": "fanout",
|
|
215
|
+
"lane": "audit",
|
|
216
|
+
"agents": [
|
|
217
|
+
{ "agent": "scout", "task": "read alpha.txt and reply with its only line" },
|
|
218
|
+
{ "agent": "scout", "task": "read beta.txt and reply with its only line" }
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Expect the run id and the answer `2 children answered`.
|
|
225
|
+
|
|
226
|
+
**`F2` — the group row.** `delegate_status` with `{ "run": "<run id>" }`.
|
|
227
|
+
Expect `<run id> fanout · fanout · answered · 2 children`. Expect one `child`
|
|
228
|
+
line per child: `child <n> <child run id> scout answered: <line>`.
|
|
229
|
+
|
|
230
|
+
**`F3` — the lane.** Run `/delegates:list`. Expect
|
|
231
|
+
`audit: running 0, queued 0, answered 2` after the run rows.
|
|
232
|
+
|
|
233
|
+
**`F4` — a review.** `delegate_launch` with:
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"request": {
|
|
238
|
+
"kind": "review",
|
|
239
|
+
"task": "review the top-level layout of this repository and name the files a new contributor should read first",
|
|
240
|
+
"reviewers": [{ "agent": "reviewer" }, { "agent": "reviewer" }]
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Expect the aggregate disposition as the answer, for example `accepted`.
|
|
246
|
+
|
|
247
|
+
**`F5` — the review rows.** `delegate_status` with `{ "run": "<run id>" }`.
|
|
248
|
+
Expect the parent row, then `review <run id> <aggregate>`. Then expect one
|
|
249
|
+
`reviewer <n> <child run id> <disposition>` line per reviewer, with its note.
|
|
250
|
+
|
|
251
|
+
## 5. Gates and control (`G`)
|
|
252
|
+
|
|
253
|
+
**`G1` — a parked child.** `delegate_launch` with:
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"request": {
|
|
258
|
+
"kind": "fanout",
|
|
259
|
+
"lane": "gate-demo",
|
|
260
|
+
"agents": [
|
|
261
|
+
{ "agent": "scout", "task": "read alpha.txt and reply with its only line" },
|
|
262
|
+
{ "agent": "scout", "task": "read note.txt and reply with its only line" },
|
|
263
|
+
{
|
|
264
|
+
"agent": "vault-scout",
|
|
265
|
+
"task": "run the shell command cat vault.txt and report the output line"
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Expect `Run <run id> waits for gate vault-access.` and one warning notice that
|
|
273
|
+
names the gate and the waiting child. The secret must not appear.
|
|
274
|
+
|
|
275
|
+
**`G2` — the waiting status.** `delegate_status` with `{ "run": "<run id>" }`.
|
|
276
|
+
Expect `waiting on gate vault-access` and `· 3 children`. Expect two answered
|
|
277
|
+
child lines and one waiting child line. Expect no lane line.
|
|
278
|
+
|
|
279
|
+
**`G3` — approve.** `delegate_control` with:
|
|
280
|
+
|
|
281
|
+
```json
|
|
282
|
+
{ "action": "approve", "run": "<run id>", "gate": "vault-access" }
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Expect `approve <run id>: <status>` and the child finishing. A second approve of
|
|
286
|
+
the same gate is refused.
|
|
287
|
+
|
|
288
|
+
**`G4` — deny.** Repeat `G1`, then call:
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
{ "action": "deny", "run": "<run id>", "gate": "vault-access" }
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Expect the child to end denied and the run to settle without running the
|
|
295
|
+
command.
|
|
296
|
+
|
|
297
|
+
**`G5` — the gate line.** With a gate parked, run `/delegates:list`. Expect
|
|
298
|
+
`gate vault-access pending for <run id>`.
|
|
299
|
+
|
|
300
|
+
**`G6` — steer, stop, resume.** Put a short wait in
|
|
301
|
+
`~/.pi/agent/delegates.json` and restart the session:
|
|
302
|
+
|
|
303
|
+
```json
|
|
304
|
+
{ "defaults": { "launchWaitMs": 1000 } }
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Launch a builder that runs `sleep 20`. Expect `running` and a run id:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"request": {
|
|
312
|
+
"kind": "single",
|
|
313
|
+
"agent": "builder",
|
|
314
|
+
"task": "run the shell command sleep 20, then list the files in the working directory"
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Then:
|
|
320
|
+
|
|
321
|
+
```json
|
|
322
|
+
{ "action": "steer", "run": "<run id>", "message": "stop the command and answer now" }
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Expect `steer <run id>: <status>`. Poll until answered. Start another long run.
|
|
326
|
+
Call `{ "action": "stop", "run": "<run id>" }` and expect
|
|
327
|
+
`stop <run id>: stopped`.
|
|
328
|
+
Resume it with `{ "action": "resume", "run": "<run id>" }`. Expect the same
|
|
329
|
+
run id and a settled status, not a new run. Resume an answered run. Expect a
|
|
330
|
+
refusal that names its status.
|
|
331
|
+
|
|
332
|
+
## 6. Admission (`A`)
|
|
333
|
+
|
|
334
|
+
Keep `launchWaitMs: 1000`. Add caps:
|
|
335
|
+
|
|
336
|
+
```json
|
|
337
|
+
{ "caps": { "laneCap": 1, "sessionCeiling": 2 }, "defaults": { "launchWaitMs": 1000 } }
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**`A1` — one running, one queued.** Launch a fanout of two slow builders in a
|
|
341
|
+
fresh lane `caps`:
|
|
342
|
+
|
|
343
|
+
```json
|
|
344
|
+
{
|
|
345
|
+
"request": {
|
|
346
|
+
"kind": "fanout",
|
|
347
|
+
"lane": "caps",
|
|
348
|
+
"agents": [
|
|
349
|
+
{
|
|
350
|
+
"agent": "builder",
|
|
351
|
+
"task": "run the shell command sleep 15, then reply with first"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
"agent": "builder",
|
|
355
|
+
"task": "run the shell command sleep 15, then reply with second"
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Expect a run id. `delegate_status` with `{ "run": "<run id>" }` shows one child
|
|
363
|
+
`running` and one `queued`. `/delegates:list` shows
|
|
364
|
+
`caps: running 1, queued 1, answered 0`.
|
|
365
|
+
|
|
366
|
+
**`A2` — the queued child starts.** Wait for the first child to end. Expect the
|
|
367
|
+
second to start and both to answer.
|
|
368
|
+
|
|
369
|
+
## 7. Toolkit resolution (`T`)
|
|
370
|
+
|
|
371
|
+
Each check must fail before a run exists; `/delegates:list` must show no new run.
|
|
372
|
+
|
|
373
|
+
**`T1` — an inline definition cannot widen tools.** Launch `vault-scout` with an
|
|
374
|
+
inline definition that adds `write`:
|
|
375
|
+
|
|
376
|
+
```json
|
|
377
|
+
{
|
|
378
|
+
"request": {
|
|
379
|
+
"kind": "single",
|
|
380
|
+
"agent": "vault-scout",
|
|
381
|
+
"task": "deploy the service",
|
|
382
|
+
"definition": {
|
|
383
|
+
"name": "vault-scout",
|
|
384
|
+
"role": "narrowed",
|
|
385
|
+
"prompt": { "role": "narrowed" },
|
|
386
|
+
"tools": ["read", "bash", "write"]
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Expect a refusal that names `write` and says the inline tools exceed the
|
|
393
|
+
registered set.
|
|
394
|
+
|
|
395
|
+
**`T2` — a missing extension.** Launch `broken`. Expect an error that names
|
|
396
|
+
`missing-extension` and lists the available extensions.
|
|
397
|
+
|
|
398
|
+
**`T3` — a pattern must name its server.** Launch `greedy`. Expect the grammar
|
|
399
|
+
message `Only "mcp__<server>__*" patterns are allowed: mcp__*.` and the
|
|
400
|
+
available namespaces.
|
|
401
|
+
|
|
402
|
+
**`T4` — an unknown namespace.** Launch `absent-scout`. Expect
|
|
403
|
+
`ToolkitUnresolved` that names `mcp__absent__*` and lists `mcp__demo` as the
|
|
404
|
+
available namespace. When a server is configured but not connected (disabled,
|
|
405
|
+
unreferenced or failing), the same message adds
|
|
406
|
+
`Configured but not connected: <names>.` `M6` shows the disabled form. `M7`
|
|
407
|
+
shows the failing form.
|
|
408
|
+
|
|
409
|
+
**`T5` — an inline definition cannot declare a skill or enable code mode.**
|
|
410
|
+
Launch `skilled` with an inline definition that sets `skills: ["release-notes"]`:
|
|
411
|
+
|
|
412
|
+
```json
|
|
413
|
+
{
|
|
414
|
+
"request": {
|
|
415
|
+
"kind": "single",
|
|
416
|
+
"agent": "skilled",
|
|
417
|
+
"task": "write release notes",
|
|
418
|
+
"definition": {
|
|
419
|
+
"name": "skilled",
|
|
420
|
+
"role": "narrowed",
|
|
421
|
+
"prompt": { "role": "narrowed" },
|
|
422
|
+
"tools": ["read"],
|
|
423
|
+
"skills": ["release-notes"]
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Expect a refusal naming `skills`. A second request with `"codemode": "runs"` in
|
|
430
|
+
the inline definition is refused the same way.
|
|
431
|
+
|
|
432
|
+
## 8. Skills (`S`)
|
|
433
|
+
|
|
434
|
+
**`S1` — a missing skill fails the launch.** With no skill directory yet, launch
|
|
435
|
+
`skilled`:
|
|
436
|
+
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"request": { "kind": "single", "agent": "skilled", "task": "write release notes" }
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Expect a refusal that names `release-notes` and lists the available skills as
|
|
444
|
+
`(none)`.
|
|
445
|
+
|
|
446
|
+
**`S2` — the prompt lists only the declared skill.** Create the skill from
|
|
447
|
+
[2.4](#24-the-skill). Then `/quit` and start the session again with
|
|
448
|
+
`--continue`. Launch `skilled` with the task
|
|
449
|
+
`quote the available-skills block of your instructions verbatim`. Expect
|
|
450
|
+
`<name>release-notes</name>`, its description and the `SKILL.md` path. Expect
|
|
451
|
+
the line `Use the read tool to load a skill's file`. Ask the child to read that
|
|
452
|
+
path and follow it. Expect it to quote the body.
|
|
453
|
+
|
|
454
|
+
**`S3` — a non-invokable skill stays out of the prompt.** Add
|
|
455
|
+
`disable-model-invocation: true` to the frontmatter. Restart the session and
|
|
456
|
+
launch `skilled` again. Expect no `available-skills` block. Ask the child to
|
|
457
|
+
read the file. Expect it to succeed, because the body is still on disk.
|
|
458
|
+
|
|
459
|
+
**`S4` — the listing shows the declared name.** `/delegates:list` shows
|
|
460
|
+
`skilled — Skill reader — tools: read — skills: release-notes — gates: none` in
|
|
461
|
+
`S1`, `S2` and `S3`.
|
|
462
|
+
|
|
463
|
+
## 9. Workflows (`W`)
|
|
464
|
+
|
|
465
|
+
**`W1` — a script answers.** `delegate_launch` with:
|
|
466
|
+
|
|
467
|
+
```json
|
|
468
|
+
{
|
|
469
|
+
"request": {
|
|
470
|
+
"kind": "workflow",
|
|
471
|
+
"agent": "composer",
|
|
472
|
+
"script": "return 'workflow-ok'"
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Expect the answer `workflow-ok`. `delegate_status` with the run id shows the
|
|
478
|
+
row `composer · workflow · answered: workflow-ok` and no lane line.
|
|
479
|
+
|
|
480
|
+
**`W2` — two children from one script.** `delegate_launch` with:
|
|
481
|
+
|
|
482
|
+
```json
|
|
483
|
+
{
|
|
484
|
+
"request": {
|
|
485
|
+
"kind": "workflow",
|
|
486
|
+
"agent": "composer",
|
|
487
|
+
"script": "const a = await tools.launch({ agent: 'scout', task: 'read alpha.txt and reply with its only line' }); const b = await tools.launch({ agent: 'scout', task: 'read beta.txt and reply with its only line' }); return a.answer + ' | ' + b.answer"
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Expect `alpha | beta` (or the file lines, in that order). `delegate_status`
|
|
493
|
+
shows both children nested under the workflow, each with its answer.
|
|
494
|
+
|
|
495
|
+
**`W3` — a workflow definition refuses a single launch.** Launch `composer`
|
|
496
|
+
with `kind: "single"`. Expect a refusal that says it runs workflows only and
|
|
497
|
+
names `kind: "workflow"`. No run appears.
|
|
498
|
+
|
|
499
|
+
**`W4` — a non-workflow definition refuses a workflow launch.** Launch `scout`
|
|
500
|
+
with `kind: "workflow"` and `script: "return 1"`. Expect a refusal that names
|
|
501
|
+
`codemode: "runs"`. No run appears.
|
|
502
|
+
|
|
503
|
+
**`W5` — a workflow cannot resume.** Take the `W1` run id and call
|
|
504
|
+
`{ "action": "resume", "run": "<run id>" }`. Expect a refusal that names the
|
|
505
|
+
workflow mode.
|
|
506
|
+
|
|
507
|
+
**`W6` — a script gate.** `delegate_launch` with:
|
|
508
|
+
|
|
509
|
+
```json
|
|
510
|
+
{
|
|
511
|
+
"request": {
|
|
512
|
+
"kind": "workflow",
|
|
513
|
+
"agent": "composer",
|
|
514
|
+
"script": "const g = await tools.gate({ name: 'ship' }); return g.decision"
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
With `launchWaitMs` short, expect `running` and a pending gate `script:ship` in
|
|
520
|
+
`/delegates:list`. Approve with
|
|
521
|
+
`{ "action": "approve", "run": "<run id>", "gate": "script:ship" }`; the script
|
|
522
|
+
answers `approved`. Repeat and deny; expect `denied`.
|
|
523
|
+
|
|
524
|
+
## 10. MCP servers (`M`)
|
|
525
|
+
|
|
526
|
+
Each check edits `~/.pi/agent/mcp.json` and restarts the session. Keep the run
|
|
527
|
+
ids you need and restore the original file in [Cleanup](#cleanup).
|
|
528
|
+
|
|
529
|
+
**`M1` — a direct tool.** With the config from [2.3](#23-the-mcp-config) and
|
|
530
|
+
`"timeout": 2` beside `demo`, restart. Launch `mcp-scout` with:
|
|
531
|
+
|
|
532
|
+
```json
|
|
533
|
+
{
|
|
534
|
+
"request": {
|
|
535
|
+
"kind": "single",
|
|
536
|
+
"agent": "mcp-scout",
|
|
537
|
+
"task": "call mcp__demo__echo with text hello, then call mcp__demo__add with a 2 and b 3, and report both results"
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
Expect both `echo:hello` and `5` in the answer.
|
|
543
|
+
|
|
544
|
+
**`M2` — a bounded result.** Launch `mcp-scout` and ask it to call
|
|
545
|
+
`mcp__demo__big` and report the length and the saved path. Expect a short
|
|
546
|
+
answer with the truncation notice. Expect `mcp.output_saved` in
|
|
547
|
+
`<sessionDir>/delegates.log`. Expect a file under `<sessionDir>/mcp/` holding
|
|
548
|
+
25600 characters.
|
|
549
|
+
|
|
550
|
+
**`M3` — a call timeout.** Launch `mcp-scout` and ask it to call
|
|
551
|
+
`mcp__demo__slow`. Expect an error naming `demo` after about 2 s and one
|
|
552
|
+
`mcp.call_timeout` line in the log. The child must not hang.
|
|
553
|
+
|
|
554
|
+
**`M4` — deferred exposure.** Set `"exposure": "deferred"` on `demo` and
|
|
555
|
+
restart. Launch `mcp-scout` and ask it to find the echo tool with `tool_search`
|
|
556
|
+
and then call it. Expect `echo:hello`; the child's toolkit holds the
|
|
557
|
+
`tool-search` extension, so the model had to load the tool first.
|
|
558
|
+
|
|
559
|
+
**`M5` — one hidden tool stays hidden.** Set `"exposure": "hidden"` and
|
|
560
|
+
`"toolExposure": { "echo": "direct" }`, then restart. Launch `mcp-scout` with
|
|
561
|
+
the task `call mcp__demo__echo with text hello, then call mcp__demo__add with a 2
|
|
562
|
+
and b 3, and report both results`. Expect `echo:hello`. Expect the model to
|
|
563
|
+
report that `add` is not available. No `mcp__demo__add` call appears in the
|
|
564
|
+
transcript.
|
|
565
|
+
|
|
566
|
+
**`M6` — a project override disables the server.** With a global `demo` entry,
|
|
567
|
+
create `/tmp/pi-delegates-test/repo/.pi/mcp.json`:
|
|
568
|
+
|
|
569
|
+
```json
|
|
570
|
+
{ "mcpServers": { "demo": { "enabled": false } } }
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Restart and accept the project-trust prompt. Expect no aggregated warning. A
|
|
574
|
+
disabled server is configuration, not a failure. Launching `mcp-scout` fails with
|
|
575
|
+
`ToolkitUnresolved`, which names `demo` as configured but not connected. The log
|
|
576
|
+
holds no `mcp.connect_failed` line. Then set `"enabled": true` in the project
|
|
577
|
+
file and restart. The global `command` still works, which proves the override
|
|
578
|
+
kept it.
|
|
579
|
+
|
|
580
|
+
**`M7` — a failed server degrades.** Change `demo`'s `command` to
|
|
581
|
+
`/nonexistent/demo` and restart. Expect one aggregated warning naming `demo`,
|
|
582
|
+
the session to load, and `/delegates:list` to work. The log holds one
|
|
583
|
+
`mcp.connect_failed` line. Launching `mcp-scout` fails with `ToolkitUnresolved`
|
|
584
|
+
that names `demo` as configured but not connected.
|
|
585
|
+
|
|
586
|
+
**`M8` — an HTTP server and a `${NAME}` header.** Start the HTTP fixture:
|
|
587
|
+
|
|
588
|
+
```bash
|
|
589
|
+
node /tmp/pi-delegates-test/repo/mcp-http-server.mjs
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
Add `docs` and remove the bad `demo` command:
|
|
593
|
+
|
|
594
|
+
```json
|
|
595
|
+
{
|
|
596
|
+
"mcpServers": {
|
|
597
|
+
"docs": {
|
|
598
|
+
"url": "http://127.0.0.1:8765/mcp",
|
|
599
|
+
"headers": { "X-Demo-Token": "${DEMO_TOKEN}" }
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Start Pi with `DEMO_TOKEN=abc` in the environment, restart the session, and
|
|
606
|
+
launch `docs-scout`:
|
|
607
|
+
|
|
608
|
+
```json
|
|
609
|
+
{
|
|
610
|
+
"request": {
|
|
611
|
+
"kind": "single",
|
|
612
|
+
"agent": "docs-scout",
|
|
613
|
+
"task": "call mcp__docs__echo and report its text"
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
Expect `http:abc`: the header expanded from the environment. With `DEMO_TOKEN`
|
|
619
|
+
unset, restart and expect one `mcp.env_missing` line in the log and the literal
|
|
620
|
+
`${DEMO_TOKEN}` sent instead.
|
|
621
|
+
|
|
622
|
+
**`M9` — codemode exposure.** Set `"exposure": "codemode"` (the default) on
|
|
623
|
+
the working `demo` entry and restart. Launch `mcp-scout`. Ask it to call the
|
|
624
|
+
demo server's `echo` tool from a codemode script, with text `hello`, and return
|
|
625
|
+
the text. Expect `echo:hello`. The child selects `codemode` because a
|
|
626
|
+
codemode-exposed MCP tool is selected. The script calls the tool by the name the
|
|
627
|
+
codemode section shows.
|
|
628
|
+
|
|
629
|
+
## 11. Late revocation (`R`)
|
|
630
|
+
|
|
631
|
+
**`R1` — `pi-subagents` blocks the start.** In the scratch project, install it
|
|
632
|
+
locally. Then start Pi **without `-ne`** and with **`--session <id>`** on the
|
|
633
|
+
same session store. Use the id of the session that launched the runs, not
|
|
634
|
+
`--continue`. `--continue` picks the newest session file in the store, which in
|
|
635
|
+
a shared store can be another session.
|
|
636
|
+
|
|
637
|
+
```bash
|
|
638
|
+
cd /tmp/pi-delegates-test/repo
|
|
639
|
+
pi install npm:pi-subagents --local
|
|
640
|
+
pi --session-dir /tmp/pi-delegates-test/sessions --session <id> \
|
|
641
|
+
-e /tmp/pi-delegates-test/pi-delegates-local \
|
|
642
|
+
--skill <checkout>/packages/delegates/skills/pi-delegates
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Expect one error notice. It starts
|
|
646
|
+
`@ftrdotdev/pi-delegates cannot load while pi-subagents is enabled` and ends with
|
|
647
|
+
`Delegates is shutting down.` No `delegate_launch` tool is offered.
|
|
648
|
+
`/delegates:list` prints the same notice and the runs committed before the
|
|
649
|
+
refusal. The log holds one `coexistence.revoked` line.
|
|
650
|
+
|
|
651
|
+
**`R2` — removing it restores the package.** Run
|
|
652
|
+
`pi remove npm:pi-subagents --local`, then `/reload` in the session. Expect the
|
|
653
|
+
three tools again and the earlier runs still listed by `/delegates:list`.
|
|
654
|
+
|
|
655
|
+
## 12. Restart (`N`)
|
|
656
|
+
|
|
657
|
+
**`N1` — runs survive.** `/quit`, then start again with `--continue` and the
|
|
658
|
+
same `--session-dir`. `/delegates:list` shows the previous runs and
|
|
659
|
+
`delegate_status` with `{}` is not empty.
|
|
660
|
+
|
|
661
|
+
**`N2` — the store path.** Each session's store sits beside its session file:
|
|
662
|
+
|
|
663
|
+
```bash
|
|
664
|
+
find /tmp/pi-delegates-test/sessions -name 'delegates-*.sqlite'
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
A refused session reads this file read-only. No shipped command opens it.
|
|
668
|
+
|
|
669
|
+
## 13. Failure log (`L`)
|
|
670
|
+
|
|
671
|
+
The log is `<sessionDir>/delegates.log`, one JSON object per line. Each line has
|
|
672
|
+
a stable `code` and a `detail` a person reads. Nothing parses `detail`.
|
|
673
|
+
|
|
674
|
+
**`L1` — a config diagnostic.** Put `{` in `~/.pi/agent/delegates.json`, restart,
|
|
675
|
+
and read the log. Expect one `warn` line with `"code":"config.invalid_json"` and
|
|
676
|
+
the file path in `detail`. Restore the file.
|
|
677
|
+
|
|
678
|
+
**`L2` — a cancelled launch.** Start the `G6` launch and press `ctrl+c` while it
|
|
679
|
+
waits. Expect one `wait.aborted` line and a run that ends `stopped`.
|
|
680
|
+
|
|
681
|
+
**`L3` — one line per failure kind.** Across `M1`–`M9`, the log holds at most
|
|
682
|
+
one line per problem: `mcp.connect_failed`, `mcp.env_missing`,
|
|
683
|
+
`mcp.call_timeout`, `mcp.output_saved`. No line holds a header value or a
|
|
684
|
+
secret.
|
|
685
|
+
|
|
686
|
+
## 14. Questions from a delegate (`Q`)
|
|
687
|
+
|
|
688
|
+
A launch is content-addressed by session and request. Repeating the same task
|
|
689
|
+
text returns the run it already started, not a new one. Give each `Q` case a
|
|
690
|
+
distinct task text.
|
|
691
|
+
|
|
692
|
+
**`Q1` — a child asks.** `delegate_launch` with:
|
|
693
|
+
|
|
694
|
+
```json
|
|
695
|
+
{
|
|
696
|
+
"request": {
|
|
697
|
+
"kind": "single",
|
|
698
|
+
"agent": "env-scout",
|
|
699
|
+
"task": "ask which environment to inspect, then reply with the chosen label"
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
Expect `Run <run id> waits for request <request id>.` and a run id, not a
|
|
705
|
+
600-second block. One warning reads `request <request id> asks: Which
|
|
706
|
+
environment?`. One parent message carries the `questions` JSON. With the
|
|
707
|
+
inquiry extension the model can answer in the same turn (`Q2`). Without it the
|
|
708
|
+
turn ends at the request, and the parent asks in plain text (`Q3`).
|
|
709
|
+
|
|
710
|
+
**`Q2` — answer with the `question` tool.** Let the model ask with its
|
|
711
|
+
`question` tool (the start block loads the inquiry extension) and choose
|
|
712
|
+
`staging`. Let it call `delegate_control` with
|
|
713
|
+
`{ "action": "answer", "run": "<run id>", "request": "<request id>", "answer": "staging" }`.
|
|
714
|
+
Expect `answer <run id>: <status>`. Expect `The user answered: staging` in the
|
|
715
|
+
child's transcript.
|
|
716
|
+
|
|
717
|
+
**`Q3` — answer without the `question` tool.** Turn the `question` tool off,
|
|
718
|
+
repeat `Q1`, and answer in plain text. Expect the same verb to work and the same
|
|
719
|
+
child result. The start block keeps the inquiry extension loaded, so the toggle
|
|
720
|
+
removes only that tool.
|
|
721
|
+
|
|
722
|
+
**`Q4` — the manual command.** With a request waiting, `/delegates:answer` with
|
|
723
|
+
no arguments lists the request, then asks for a label or free text. Answer.
|
|
724
|
+
Expect `answer <run id>: answered`. Repeat with
|
|
725
|
+
`/delegates:answer <run id> <request id> staging`. Expect the same result.
|
|
726
|
+
|
|
727
|
+
**`Q5` — a cancelled dialog declines.** Open `/delegates:answer`, pick a
|
|
728
|
+
request, and press escape. Expect `decline <run id>: cancelled`. Expect the
|
|
729
|
+
child to get an error that names `declined`, and no pending request in
|
|
730
|
+
`/delegates:list`. The run settles `denied`, not `answered`. The row reads
|
|
731
|
+
denied, the lane's answered count does not grow, and the wait text reads
|
|
732
|
+
`Run <run id> was denied: request <request id> was declined.`
|
|
733
|
+
|
|
734
|
+
**`Q6` — a second answer is refused.** Answer a request, then repeat the same
|
|
735
|
+
`delegate_control` call. Expect a refusal naming `answered` and no change.
|
|
736
|
+
|
|
737
|
+
**`Q7` — a reload does not repeat.** While a request waits, run `/reload`.
|
|
738
|
+
Expect no second warning. The session holds one `delegates.request-alert` entry
|
|
739
|
+
for the request. The record still reads `pending`, and the strip and
|
|
740
|
+
`/delegates:list` still name it. A reload closes the inspector, not the parked
|
|
741
|
+
child. A `/quit` leaves it pending too. The store survives. `delegate_control
|
|
742
|
+
stop` is the path that cancels. The record commits `cancelled` with reason
|
|
743
|
+
`stopped`, and the log gains one `request.cancelled` line. With the headless
|
|
744
|
+
default, the log holds one `request.pending` line with the run and request ids.
|
|
745
|
+
It carries no prompt text.
|
|
746
|
+
|
|
747
|
+
**`Q8` — the surfaces.** While a request waits, `/delegates:list` prints
|
|
748
|
+
`request <request id> pending for <run id>`. The inspector row ends with
|
|
749
|
+
`request <request id>`. Expanding the request shows the prompt, the labels and
|
|
750
|
+
the deadline on wrapped lines inside the box.
|
|
751
|
+
|
|
752
|
+
**`Q9` — the viewer is read-only.** From a refused session (see `R1`),
|
|
753
|
+
`/delegates:list` prints the pending request and posts no message.
|
|
754
|
+
|
|
755
|
+
**`Q10` — a late answer is refused as expired.** Leave a request unanswered past
|
|
756
|
+
its 24-hour deadline (a test build with a short deadline is enough). Then answer
|
|
757
|
+
it with `delegate_control` or `/delegates:answer`. Expect a refusal naming
|
|
758
|
+
`expired`. Expect the record committed `expired` with reason `deadline`, and no
|
|
759
|
+
answer in the child's transcript. Use a fresh task text. Otherwise the launch
|
|
760
|
+
returns the earlier run, and no new request appears.
|
|
761
|
+
|
|
762
|
+
## Automated-only checks
|
|
763
|
+
|
|
764
|
+
These cases are proven by the suite, not by hand:
|
|
765
|
+
|
|
766
|
+
| Case | Test |
|
|
767
|
+
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
768
|
+
| A storage failure logs `report.storage_failed` once and closes the runtime | `src/runtime/session.test.ts` |
|
|
769
|
+
| A stored toolkit name that no longer resolves is refused and written to `RunDoc.diagnostics` | `src/domain/orchestration/control.test.ts` |
|
|
770
|
+
| The session view returns the newest 50 runs and counts the rest | `src/domain/view.test.ts` |
|
|
771
|
+
| A timeout leaves no armed timer; a gate wakes the wait | `src/domain/orchestration/run-wait.test.ts` |
|
|
772
|
+
| A request wait resolves on a commit, a spurious advance re-checks, the backstop catches a lost push | `src/domain/orchestration/run-wait.test.ts` |
|
|
773
|
+
| An answer wakes the child, a second answer and an expired answer are refused, and `stop` cancels | `src/domain/orchestration/control.test.ts` |
|
|
774
|
+
| `stop` cancels the parked request and writes one `request.cancelled` line | `src/domain/orchestration/control.test.ts` |
|
|
775
|
+
| A declined request settles the run denied, names the request, and leaves the lane answered count | `src/domain/orchestration/control.test.ts` |
|
|
776
|
+
| The answer command declines only when the answer dialog is cancelled | `src/extension/commands.test.ts` |
|
|
777
|
+
| The picker hides free text when the request forbids it, and a failed direct answer logs one line | `src/extension/commands.test.ts` |
|
|
778
|
+
| A pending request past its deadline expires; the sweep retires old records, drops stray rows and counts one | `src/domain/orchestration/requests.test.ts` |
|
|
779
|
+
| A request with no options must allow free text, or the tool refuses it | `src/domain/orchestration/requests.test.ts` |
|
|
780
|
+
| An aborted parked call cancels the record once and writes one `request.cancelled` line | `src/domain/orchestration/requests.test.ts` |
|
|
781
|
+
| A reload announces nothing twice; the log-only host writes one id-only line | `src/extension/request-alerts.test.ts` |
|
|
782
|
+
| A headless mode writes the id-only line; `tui` and `rpc` use the toast host | `src/extension/request-alerts.test.ts` |
|
|
783
|
+
| A request index commit republishes the snapshot with the pending request | `src/presentation/inspector.test.ts` |
|
|
784
|
+
| A request committed after the inspector attached reaches it without a restart (missing attachments retry) | `src/presentation/inspector.test.ts` |
|
|
785
|
+
| The inspector and the overlay name a pending request, and an expired one leaves them | `src/presentation/snapshot.test.ts`, `src/presentation/overlay.test.ts` |
|
|
786
|
+
| The request expansion wraps the prompt, labels and deadline to the box | `src/presentation/wording.test.ts` |
|
|
787
|
+
| A decided request leaves the fanout child row | `src/presentation/snapshot.test.ts` |
|
|
788
|
+
| The `failFast` policy aborts the other children | `src/domain/orchestration/fanout.test.ts` |
|
|
789
|
+
| Every inspector string is exact, including the queued count and a gate's child count | `src/presentation/wording.test.ts` |
|
|
790
|
+
| The timer adapter fires at the delay and `clearTimeout` cancels it | `src/runtime/clock.test.ts` |
|
|
791
|
+
| A registered definition overrides its preset and a new name joins the catalogue | `src/domain/definitions.test.ts` |
|
|
792
|
+
| A version 1 toolkit document opens as version 2 with no skills | `src/domain/skills.test.ts` |
|
|
793
|
+
| A child's prompt lists only its declared skills, and a dropped skill joins the missing list | `src/domain/skills.test.ts` |
|
|
794
|
+
| A script over 64 KiB is refused before a run exists | `src/domain/orchestration/workflow.test.ts` |
|
|
795
|
+
| A restart mid-script reattaches without duplicating or re-claiming children | `src/domain/orchestration/workflow.test.ts` |
|
|
796
|
+
| A script cannot stop or steer its own run | `src/domain/orchestration/workflow.test.ts` |
|
|
797
|
+
| A connect timeout, a dropped connection and a bounded result are one line and one file | `src/runtime/mcp.test.ts` |
|
|
798
|
+
| A viewer builds no MCP layer and reports no MCP name missing | `src/runtime/mcp.test.ts` |
|
|
799
|
+
| A conflict that appears mid-session withdraws the tools and closes the runtime | `src/extension/entry.test.ts` |
|
|
800
|
+
| A conflict that registers after the start is refused before the first turn | `src/extension/entry.test.ts` |
|
|
801
|
+
| A refused `/delegates` reads the store read-only | `src/extension/commands.test.ts` |
|
|
802
|
+
|
|
803
|
+
Three modules have no test file of their own. The tests that pin them:
|
|
804
|
+
|
|
805
|
+
- `src/domain/names.ts` — `src/domain/orchestration/workflow.test.ts`
|
|
806
|
+
compares the registered snapshot tools with `RUN_TOOL_NAMES` and asserts
|
|
807
|
+
that the model is offered none of them.
|
|
808
|
+
- `src/domain/orchestration/admission.ts` —
|
|
809
|
+
`src/domain/orchestration/fanout.test.ts` calls `available` and `liveCounts`
|
|
810
|
+
with inspection records and owned tasks.
|
|
811
|
+
- `src/presentation/shortcut.ts` — `src/extension/shortcut.test.ts` accepts the
|
|
812
|
+
default and rejects malformed keys; `src/presentation/wording.test.ts`
|
|
813
|
+
renders it.
|
|
814
|
+
|
|
815
|
+
A standalone read-only CLI and panel belong to a separate plan and are not in
|
|
816
|
+
this package. The read-only runtime behind a refused `/delegates` is covered by
|
|
817
|
+
the table above.
|
|
818
|
+
|
|
819
|
+
## Test harness
|
|
820
|
+
|
|
821
|
+
The suite runs with `isolate: false`, from `baseTestConfig` in
|
|
822
|
+
`packages/test-kit/src/vitest-config.ts`. One worker process runs one file after
|
|
823
|
+
another, so every test file must leave no state behind.
|
|
824
|
+
`src/harness-policy.test.ts` asserts the setting. `@effect/vitest` closes each
|
|
825
|
+
file's layer when the file ends. That close is why a test opens its resources
|
|
826
|
+
through a layer and not by hand.
|
|
827
|
+
|
|
828
|
+
`test-support/layer-kit.ts` holds the shared pieces. `platformLayer` is
|
|
829
|
+
`Layer.mergeAll(NodeFileSystem.layer, NodePath.layer)`, and `layerKit(layer)`
|
|
830
|
+
merges a file's own layer with `platformLayer`. Two ways to use them:
|
|
831
|
+
|
|
832
|
+
- `test-support/platform.ts` gives promise helpers over its own `ManagedRuntime`,
|
|
833
|
+
built from `layerKit(Layer.empty)`: `makeTempDir`, `makeDir`, `writeText`,
|
|
834
|
+
`readText`, `readDir`, `dirEntries`, `removePath`, `existsPath`, `join`,
|
|
835
|
+
`relativePath`. Thirty files under `src` import them. The helpers reuse
|
|
836
|
+
`platformLayer`, not a file's runtime instance. They suit a test whose
|
|
837
|
+
assertions are plain `async` functions.
|
|
838
|
+
- `it.layer(layerKit(TestLayer()))` runs a file's Effect tests against one build.
|
|
839
|
+
`it.layer(layerKit(TestLayer()), { buildPerTest: true })` gives every test its
|
|
840
|
+
own build. Two files hoist a layer this way:
|
|
841
|
+
`src/presentation/repaint.test.ts` and `src/goldens.test.ts`. Both still inline
|
|
842
|
+
`Layer.mergeAll(NodeFileSystem.layer, NodePath.layer)` instead of calling
|
|
843
|
+
`layerKit`.
|
|
844
|
+
|
|
845
|
+
**The `buildPerTest` rule.** Per-test is the default, not the exception. A file
|
|
846
|
+
that constructs fresh state per test (`MemoryStorage`, a sqlite store, a temp
|
|
847
|
+
directory) passes `buildPerTest: true`. Hoist a layer to suite scope only when
|
|
848
|
+
the layer builds no mutable state, as `src/goldens.test.ts` does.
|
|
849
|
+
|
|
850
|
+
No test file under `src` imports a `node:` module. `src/test-hygiene.test.ts`
|
|
851
|
+
enforces four rules over `src`, with an empty allow list:
|
|
852
|
+
|
|
853
|
+
- No test file imports `node:`.
|
|
854
|
+
- No file outside `src/layers.ts` calls `Layer.build(`.
|
|
855
|
+
- No file outside `src/layers.ts` calls `.layer(`.
|
|
856
|
+
- No file builds a `runtime: () =>` provider.
|
|
857
|
+
|
|
858
|
+
The files that keep a `node:` import (`src/runtime/bridge.ts`,
|
|
859
|
+
`src/runtime/session.ts`, `src/runtime/mcp.ts`, `src/runtime/log.ts`,
|
|
860
|
+
`src/runtime/config.ts`, `src/extension/version.ts`,
|
|
861
|
+
`src/extension/shortcut.ts`, `src/extension/commands.ts`,
|
|
862
|
+
`src/extension/entry.ts`, `src/extension/inspector-command.ts`) are shipped code.
|
|
863
|
+
`src/runtime/log.ts` imports `node:fs` for `fileLogSink`, which appends one JSON
|
|
864
|
+
line per write.
|
|
865
|
+
|
|
866
|
+
Two paths outside `src` keep a `node:` import, and the guard exempts both by
|
|
867
|
+
pattern (`scripts/**`, `test-support/fixtures/**`):
|
|
868
|
+
|
|
869
|
+
- `scripts/manual/repo/mcp-server.mjs` and `mcp-http-server.mjs`, which are
|
|
870
|
+
standalone Node scripts.
|
|
871
|
+
- `test-support/fixtures/hygiene/node-import.fixture.ts`, the guard's own bad
|
|
872
|
+
example.
|
|
873
|
+
|
|
874
|
+
## Cleanup
|
|
875
|
+
|
|
876
|
+
Run `/quit`, then restore the files the checks edited and remove the scratch
|
|
877
|
+
directory:
|
|
878
|
+
|
|
879
|
+
```bash
|
|
880
|
+
if [ -f ~/.pi/agent/mcp.json.bak ]; then
|
|
881
|
+
mv ~/.pi/agent/mcp.json.bak ~/.pi/agent/mcp.json
|
|
882
|
+
else
|
|
883
|
+
rm -f ~/.pi/agent/mcp.json
|
|
884
|
+
fi
|
|
885
|
+
if [ -f ~/.pi/agent/delegates.json.bak ]; then
|
|
886
|
+
mv ~/.pi/agent/delegates.json.bak ~/.pi/agent/delegates.json
|
|
887
|
+
else
|
|
888
|
+
rm -f ~/.pi/agent/delegates.json
|
|
889
|
+
fi
|
|
890
|
+
cd /tmp/pi-delegates-test/repo && pi remove npm:pi-subagents --local 2>/dev/null || true
|
|
891
|
+
rm -rf /tmp/pi-delegates-test
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
The checklist adds nothing to `~/.pi/agent/settings.json`, so no other
|
|
895
|
+
`pi remove` step is needed. Delete `~/.pi/agent/mcp.json` only when it did not
|
|
896
|
+
exist before the run.
|