@ftrdotdev/pi-delegates 0.1.0 → 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.
Files changed (94) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/OPERATIONS.md +79 -6
  3. package/README.md +25 -17
  4. package/ROADMAP.md +21 -0
  5. package/TESTING.md +153 -318
  6. package/package.json +4 -3
  7. package/skills/pi-delegates/SKILL.md +29 -0
  8. package/skills/pi-delegates/references/launch.md +28 -0
  9. package/src/docs-contract.test.ts +106 -0
  10. package/src/domain/definitions.ts +3 -1
  11. package/src/domain/failure.ts +33 -0
  12. package/src/domain/model-source.ts +30 -0
  13. package/src/domain/orchestration/control.test.ts +69 -35
  14. package/src/domain/orchestration/control.ts +110 -89
  15. package/src/domain/orchestration/fanout.test.ts +125 -20
  16. package/src/domain/orchestration/fanout.ts +60 -22
  17. package/src/domain/orchestration/gates.test.ts +14 -15
  18. package/src/domain/orchestration/launch.test.ts +210 -11
  19. package/src/domain/orchestration/launch.ts +142 -32
  20. package/src/domain/orchestration/requests.test.ts +11 -16
  21. package/src/domain/orchestration/requests.ts +14 -1
  22. package/src/domain/orchestration/review.test.ts +89 -11
  23. package/src/domain/orchestration/run-wait.test.ts +4 -1
  24. package/src/domain/orchestration/run-wait.ts +1 -1
  25. package/src/domain/orchestration/workflow.test.ts +157 -16
  26. package/src/domain/orchestration/workflow.ts +269 -196
  27. package/src/domain/run-records.ts +214 -52
  28. package/src/domain/settlement.test.ts +186 -0
  29. package/src/domain/settlement.ts +137 -0
  30. package/src/domain/shapes.test.ts +20 -0
  31. package/src/domain/skills.test.ts +31 -20
  32. package/src/domain/skills.ts +36 -19
  33. package/src/domain/toolkit.test.ts +15 -1
  34. package/src/domain/toolkit.ts +8 -13
  35. package/src/domain/turn-budget.test.ts +37 -0
  36. package/src/domain/turn-budget.ts +23 -0
  37. package/src/domain/view.test.ts +78 -14
  38. package/src/domain/view.ts +67 -35
  39. package/src/extension/commands.test.ts +27 -23
  40. package/src/extension/commands.ts +10 -7
  41. package/src/extension/entry.test.ts +214 -56
  42. package/src/extension/entry.ts +78 -40
  43. package/src/extension/gate-alerts.test.ts +10 -8
  44. package/src/extension/inspector-command.test.ts +173 -21
  45. package/src/extension/inspector-command.ts +100 -53
  46. package/src/extension/prompt.test.ts +2 -4
  47. package/src/extension/retry-observer.test.ts +292 -0
  48. package/src/extension/retry-observer.ts +150 -0
  49. package/src/extension/settle-alerts.test.ts +579 -0
  50. package/src/extension/settle-alerts.ts +175 -0
  51. package/src/extension/shortcut.test.ts +6 -8
  52. package/src/extension/tools.test.ts +325 -24
  53. package/src/extension/tools.ts +61 -13
  54. package/src/extension/version.test.ts +21 -29
  55. package/src/goldens.test.ts +294 -0
  56. package/src/harness-policy.test.ts +13 -11
  57. package/src/layers.test.ts +309 -0
  58. package/src/layers.ts +405 -0
  59. package/src/package-manifest.test.ts +32 -19
  60. package/src/presentation/actions.test.ts +8 -8
  61. package/src/presentation/activity.test.ts +7 -8
  62. package/src/presentation/close.test.ts +14 -16
  63. package/src/presentation/inspector.test.ts +14 -11
  64. package/src/presentation/inspector.ts +27 -25
  65. package/src/presentation/overlay.test.ts +1 -3
  66. package/src/presentation/repaint.test.ts +226 -190
  67. package/src/presentation/snapshot.test.ts +5 -0
  68. package/src/presentation/status.test.ts +43 -0
  69. package/src/presentation/status.ts +30 -0
  70. package/src/presentation/strip.test.ts +13 -6
  71. package/src/presentation/strip.ts +7 -14
  72. package/src/presentation/wording.test.ts +153 -3
  73. package/src/presentation/wording.ts +78 -6
  74. package/src/runtime/bridge.ts +38 -44
  75. package/src/runtime/{timers.test.ts → clock.test.ts} +1 -1
  76. package/src/runtime/clock.ts +31 -0
  77. package/src/runtime/config.test.ts +26 -7
  78. package/src/runtime/config.ts +6 -1
  79. package/src/runtime/execution-env.test.ts +6 -8
  80. package/src/runtime/extensions.test.ts +4 -4
  81. package/src/runtime/extensions.ts +23 -11
  82. package/src/runtime/handle.ts +54 -0
  83. package/src/runtime/log.test.ts +19 -7
  84. package/src/runtime/log.ts +23 -0
  85. package/src/runtime/mcp.test.ts +29 -32
  86. package/src/runtime/mcp.ts +70 -3
  87. package/src/runtime/runtime-state.test.ts +25 -0
  88. package/src/runtime/runtime-state.ts +36 -0
  89. package/src/runtime/session-tag.ts +11 -0
  90. package/src/runtime/session.test.ts +24 -31
  91. package/src/runtime/session.ts +99 -261
  92. package/src/runtime/storage.ts +29 -0
  93. package/src/test-hygiene.test.ts +97 -0
  94. package/src/runtime/timers.ts +0 -10
package/TESTING.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Testing pi-delegates in a new session
2
2
 
3
- This checklist runs a local checkout without publishing the package and covers
3
+ This checklist runs a local checkout without publishing the package. It covers
4
4
  every shipped feature: delegation, fanout, review, gates, control, admission,
5
5
  skills, workflows, MCP servers, late revocation and the inspector.
6
6
 
@@ -24,7 +24,7 @@ forced by hand are in [Automated-only checks](#automated-only-checks).
24
24
 
25
25
  ## Prerequisites
26
26
 
27
- - Pi `1.6.0` on `PATH`.
27
+ - Pi `^1.6.0` on `PATH`.
28
28
  - Node `22.19.0` or newer.
29
29
  - Dependencies installed. Run `bun install` at the repository root.
30
30
  - A model and login already configured in `~/.pi/agent`. This checklist keeps
@@ -61,276 +61,54 @@ printf 'hunter2\n' > vault.txt
61
61
 
62
62
  ## 2. Fixtures
63
63
 
64
- Every fixture lives under `/tmp/pi-delegates-test`, outside the checkout, so a
65
- check never changes the repository.
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.
66
67
 
67
68
  ### 2.1 The fixture package
68
69
 
69
- One local package registers the nine test agents. It depends on the checkout,
70
- so no build or publish step is needed.
71
-
72
- Create `/tmp/pi-delegates-test/pi-delegates-local/package.json`:
73
-
74
- ```json
75
- {
76
- "name": "pi-delegates-local",
77
- "private": true,
78
- "keywords": ["pi-package"],
79
- "pi": { "extensions": ["./delegates.ts"] }
80
- }
81
- ```
82
-
83
- Create `/tmp/pi-delegates-test/pi-delegates-local/delegates.ts`:
84
-
85
- ```ts
86
- import { createDelegatesExtension } from "@ftrdotdev/pi-delegates";
87
- import { defineAgent } from "@ftrdotdev/pi-delegates/agents";
88
-
89
- // G1–G5: a bash call that mentions "vault" parks until a person decides.
90
- const vaultScout = defineAgent({
91
- name: "vault-scout",
92
- role: "Gated vault scout",
93
- prompt: { role: "You run the shell command you are asked for and report its output." },
94
- tools: ["read", "bash"],
95
- extensions: ["coding-tools"],
96
- approval: { gates: [{ name: "vault-access", tools: ["bash"], match: "vault" }] },
97
- });
98
-
99
- // W1–W6: a workflow-only definition; its child gets codemode and the runs namespace.
100
- const composer = defineAgent({
101
- name: "composer",
102
- role: "Workflow composer",
103
- prompt: { role: "You compose workflows from delegated runs." },
104
- tools: ["read"],
105
- extensions: ["coding-tools"],
106
- approval: { gates: [] },
107
- codemode: "runs",
108
- });
109
-
110
- // S1–S3: declares one skill by name.
111
- const skilled = defineAgent({
112
- name: "skilled",
113
- role: "Skill reader",
114
- prompt: { role: "You follow the skills declared in your instructions." },
115
- tools: ["read"],
116
- extensions: ["coding-tools"],
117
- approval: { gates: [] },
118
- skills: ["release-notes"],
119
- });
120
-
121
- // M1–M7 and M9: selects the whole demo namespace by pattern.
122
- const mcpScout = defineAgent({
123
- name: "mcp-scout",
124
- role: "MCP caller",
125
- prompt: { role: "You call the tools you are given and report their text." },
126
- tools: ["read", "mcp__demo__*"],
127
- extensions: ["coding-tools"],
128
- approval: { gates: [] },
129
- });
130
-
131
- // T2: names an extension this package does not install.
132
- const broken = defineAgent({
133
- name: "broken",
134
- role: "Broken toolkit",
135
- prompt: { role: "You are never launched." },
136
- tools: ["read"],
137
- extensions: ["missing-extension"],
138
- approval: { gates: [] },
139
- });
140
-
141
- // T3: a pattern that does not name its server.
142
- const greedy = defineAgent({
143
- name: "greedy",
144
- role: "Broad pattern",
145
- prompt: { role: "You are never launched." },
146
- tools: ["read", "mcp__*"],
147
- extensions: ["coding-tools"],
148
- approval: { gates: [] },
149
- });
150
-
151
- // T4: a namespace no server offers.
152
- const absentScout = defineAgent({
153
- name: "absent-scout",
154
- role: "Unknown namespace",
155
- prompt: { role: "You are never launched." },
156
- tools: ["read", "mcp__absent__*"],
157
- extensions: ["coding-tools"],
158
- approval: { gates: [] },
159
- });
160
-
161
- // M8: selects an HTTP server's namespace.
162
- const docsScout = defineAgent({
163
- name: "docs-scout",
164
- role: "HTTP MCP caller",
165
- prompt: { role: "You call the tools you are given and report their text." },
166
- tools: ["read", "mcp__docs__*"],
167
- extensions: ["coding-tools"],
168
- approval: { gates: [] },
169
- });
170
-
171
- // Q1–Q9: asks the user one question and waits for the answer.
172
- const envScout = defineAgent({
173
- name: "env-scout",
174
- role: "Environment scout",
175
- prompt: { role: "Ask which environment to inspect, then inspect it." },
176
- tools: ["read", "ask"],
177
- extensions: ["coding-tools", "questions"],
178
- approval: { gates: [] },
179
- });
180
-
181
- export default createDelegatesExtension({
182
- definitions: [
183
- vaultScout,
184
- composer,
185
- skilled,
186
- mcpScout,
187
- docsScout,
188
- broken,
189
- greedy,
190
- absentScout,
191
- envScout,
192
- ],
193
- });
194
- ```
195
-
196
- Install the checkout into that package:
70
+ Copy the package, then install the checkout into it:
197
71
 
198
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
199
76
  cd /tmp/pi-delegates-test/pi-delegates-local
200
77
  npm install <checkout>/packages/delegates
201
78
  ```
202
79
 
203
- ### 2.2 The demo MCP server
204
-
205
- Create `/tmp/pi-delegates-test/repo/mcp-server.mjs`. It offers `echo`, `add`,
206
- `big` (25 KiB) and `slow` (never answers).
207
-
208
- ```js
209
- import { createInterface } from "node:readline";
210
-
211
- const send = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
212
- const reply = (id, result) => send({ jsonrpc: "2.0", id, result });
213
-
214
- const tools = [
215
- {
216
- name: "echo",
217
- description: "Echo text",
218
- inputSchema: { type: "object", properties: { text: { type: "string" } } },
219
- },
220
- {
221
- name: "add",
222
- description: "Add two numbers",
223
- inputSchema: {
224
- type: "object",
225
- properties: { a: { type: "number" }, b: { type: "number" } },
226
- },
227
- },
228
- { name: "big", description: "Return 25 KiB of text", inputSchema: { type: "object" } },
229
- { name: "slow", description: "Never answers", inputSchema: { type: "object" } },
230
- ];
231
-
232
- createInterface({ input: process.stdin }).on("line", (line) => {
233
- const message = JSON.parse(line);
234
- if (message.id === undefined) return;
235
- if (message.method === "initialize") {
236
- return reply(message.id, {
237
- protocolVersion: message.params.protocolVersion,
238
- capabilities: { tools: {} },
239
- serverInfo: { name: "demo", version: "0.0.0" },
240
- });
241
- }
242
- if (message.method === "ping") return reply(message.id, {});
243
- if (message.method === "tools/list") return reply(message.id, { tools });
244
- if (message.method === "tools/call") {
245
- const { name, arguments: args = {} } = message.params;
246
- if (name === "slow") return;
247
- const text =
248
- name === "echo"
249
- ? `echo:${args.text}`
250
- : name === "add"
251
- ? String(Number(args.a) + Number(args.b))
252
- : name === "big"
253
- ? "x".repeat(25600)
254
- : null;
255
- if (text === null) {
256
- return send({ jsonrpc: "2.0", id: message.id, error: { code: -32601, message: "no tool" } });
257
- }
258
- return reply(message.id, { content: [{ type: "text", text }] });
259
- }
260
- return send({ jsonrpc: "2.0", id: message.id, error: { code: -32601, message: "no method" } });
261
- });
262
- ```
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.
263
83
 
264
- Create `/tmp/pi-delegates-test/repo/mcp-http-server.mjs` for `M8`:
265
-
266
- ```js
267
- import { createServer } from "node:http";
268
-
269
- createServer((request, response) => {
270
- if (request.method !== "POST") return response.writeHead(405).end();
271
- let body = "";
272
- request.on("data", (chunk) => (body += chunk));
273
- request.on("end", () => {
274
- const message = JSON.parse(body);
275
- const reply = (result) => {
276
- response.writeHead(200, { "content-type": "application/json" });
277
- response.end(JSON.stringify({ jsonrpc: "2.0", id: message.id, result }));
278
- };
279
- if (message.id === undefined) return response.writeHead(202).end();
280
- if (message.method === "ping") return reply({});
281
- if (message.method === "initialize") {
282
- return reply({
283
- protocolVersion: message.params.protocolVersion,
284
- capabilities: { tools: {} },
285
- serverInfo: { name: "demo-http", version: "0.0.0" },
286
- });
287
- }
288
- if (message.method === "tools/list") {
289
- return reply({
290
- tools: [{ name: "echo", inputSchema: { type: "object" } }],
291
- });
292
- }
293
- if (message.method === "tools/call") {
294
- return reply({
295
- content: [{ type: "text", text: `http:${request.headers["x-demo-token"] ?? "none"}` }],
296
- });
297
- }
298
- response.writeHead(200, { "content-type": "application/json" });
299
- response.end(
300
- JSON.stringify({ jsonrpc: "2.0", id: message.id, error: { code: -32601, message: "no" } }),
301
- );
302
- });
303
- }).listen(8765, "127.0.0.1");
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/
304
90
  ```
305
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
+
306
95
  ### 2.3 The MCP config
307
96
 
308
- Create `~/.pi/agent/mcp.json`. `direct` exposure makes `M1` one plain tool call:
97
+ Copy the config to `~/.pi/agent/mcp.json`. `direct` exposure makes `M1` one plain
98
+ tool call:
309
99
 
310
- ```json
311
- {
312
- "mcpServers": {
313
- "demo": {
314
- "command": "node",
315
- "args": ["/tmp/pi-delegates-test/repo/mcp-server.mjs"],
316
- "exposure": "direct"
317
- }
318
- }
319
- }
100
+ ```bash
101
+ cp <checkout>/packages/delegates/scripts/manual/mcp.json ~/.pi/agent/mcp.json
320
102
  ```
321
103
 
322
104
  ### 2.4 The skill
323
105
 
324
- Create `/tmp/pi-delegates-test/repo/.pi/skills/release-notes/SKILL.md` only when
325
- `S2` says so. `S1` runs without it:
106
+ Copy the skill only when `S2` says so. `S1` runs without it:
326
107
 
327
- ```md
328
- ---
329
- name: release-notes
330
- description: Write the release notes for one change.
331
- ---
332
-
333
- Read the change's tests first. List what a user sees, not what the code does.
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/
334
112
  ```
335
113
 
336
114
  ### 2.5 Start Pi
@@ -360,7 +138,7 @@ Inject each prompt by asking the model to call the named tool. The model may
360
138
  wrap a call in prose; the expected text is what the tool returns.
361
139
 
362
140
  **`C1` — the listing.** Run `/delegates:list`. Expect one line per definition:
363
- the three presets and the eight fixtures, in this order:
141
+ the three presets and the nine fixtures, in this order:
364
142
 
365
143
  ```text
366
144
  scout — Read-only explorer — tools: read — skills: none — gates: none
@@ -374,6 +152,7 @@ docs-scout — HTTP MCP caller — tools: read, mcp__docs__* — skills: none
374
152
  broken — Broken toolkit — tools: read — skills: none — gates: none
375
153
  greedy — Broad pattern — tools: read, mcp__* — skills: none — gates: none
376
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
377
156
  ```
378
157
 
379
158
  **`C2` — the empty status.** `delegate_status` with `{}`. Expect
@@ -392,8 +171,8 @@ absent-scout — Unknown namespace — tools: read, mcp__absent__* — skills: n
392
171
  ```
393
172
 
394
173
  Expect `hello`. A reply that says `No execution environment is configured`
395
- means the runtime dropped its `env` option, and every read, write and bash call
396
- inside a delegate would fail.
174
+ means the runtime dropped its `env` option. In that case every read, write and
175
+ bash call inside a delegate fails.
397
176
 
398
177
  **`C4` — the run row.** `delegate_status` with `{ "run": "<run id>" }`.
399
178
  Expect the run line `<run id> scout · answered: hello` and no lane line.
@@ -402,9 +181,9 @@ Expect the run line `<run id> scout · answered: hello` and no lane line.
402
181
  and the lane line `default: running 0, queued 0, answered 1`.
403
182
 
404
183
  **`C6` — the inspector.** Press `ctrl+space`. Expect the overlay with the
405
- agents, the run and the footer
184
+ agents and the run. Expect the footer
406
185
  `enter/i inspect · s stop · a approve · d deny · esc close`. Press `escape`.
407
- Run `/delegates`; expect the overlay again. Run `/delegates` once more; expect
186
+ Run `/delegates`. Expect the overlay again. Run `/delegates` once more. Expect
408
187
  it to close.
409
188
 
410
189
  **`C7` — the shipped skill.** Run `/skill:pi-delegates`. Expect the
@@ -445,8 +224,8 @@ Expect `done` and `/tmp/pi-delegates-test/repo/built.txt` holding `done`.
445
224
  Expect the run id and the answer `2 children answered`.
446
225
 
447
226
  **`F2` — the group row.** `delegate_status` with `{ "run": "<run id>" }`.
448
- Expect `<run id> fanout · fanout · answered · 2 children` and one `child` line
449
- per child, each `child <n> <child run id> scout answered: <line>`.
227
+ Expect `<run id> fanout · fanout · answered · 2 children`. Expect one `child`
228
+ line per child: `child <n> <child run id> scout answered: <line>`.
450
229
 
451
230
  **`F3` — the lane.** Run `/delegates:list`. Expect
452
231
  `audit: running 0, queued 0, answered 2` after the run rows.
@@ -466,7 +245,7 @@ per child, each `child <n> <child run id> scout answered: <line>`.
466
245
  Expect the aggregate disposition as the answer, for example `accepted`.
467
246
 
468
247
  **`F5` — the review rows.** `delegate_status` with `{ "run": "<run id>" }`.
469
- Expect the parent row, then `review <run id> <aggregate>`, then one
248
+ Expect the parent row, then `review <run id> <aggregate>`. Then expect one
470
249
  `reviewer <n> <child run id> <disposition>` line per reviewer, with its note.
471
250
 
472
251
  ## 5. Gates and control (`G`)
@@ -494,8 +273,8 @@ Expect `Run <run id> waits for gate vault-access.` and one warning notice that
494
273
  names the gate and the waiting child. The secret must not appear.
495
274
 
496
275
  **`G2` — the waiting status.** `delegate_status` with `{ "run": "<run id>" }`.
497
- Expect `waiting on gate vault-access`, `· 3 children`, two answered child lines
498
- and one waiting child line, and no lane line.
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.
499
278
 
500
279
  **`G3` — approve.** `delegate_control` with:
501
280
 
@@ -543,11 +322,11 @@ Then:
543
322
  { "action": "steer", "run": "<run id>", "message": "stop the command and answer now" }
544
323
  ```
545
324
 
546
- Expect `steer <run id>: <status>`; poll until answered. Start another long run,
547
- call `{ "action": "stop", "run": "<run id>" }` and expect
325
+ Expect `steer <run id>: <status>`. Poll until answered. Start another long run.
326
+ Call `{ "action": "stop", "run": "<run id>" }` and expect
548
327
  `stop <run id>: stopped`.
549
- Resume it with `{ "action": "resume", "run": "<run id>" }`; expect the same
550
- run id and a settled status, not a new run. Resume an answered run and expect a
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
551
330
  refusal that names its status.
552
331
 
553
332
  ## 6. Admission (`A`)
@@ -581,7 +360,7 @@ fresh lane `caps`:
581
360
  ```
582
361
 
583
362
  Expect a run id. `delegate_status` with `{ "run": "<run id>" }` shows one child
584
- `running` and one `queued`; `/delegates:list` shows
363
+ `running` and one `queued`. `/delegates:list` shows
585
364
  `caps: running 1, queued 1, answered 0`.
586
365
 
587
366
  **`A2` — the queued child starts.** Wait for the first child to end. Expect the
@@ -624,8 +403,8 @@ available namespaces.
624
403
  `ToolkitUnresolved` that names `mcp__absent__*` and lists `mcp__demo` as the
625
404
  available namespace. When a server is configured but not connected (disabled,
626
405
  unreferenced or failing), the same message adds
627
- `Configured but not connected: <names>.`; `M6` shows the disabled form and `M7`
628
- the failing one.
406
+ `Configured but not connected: <names>.` `M6` shows the disabled form. `M7`
407
+ shows the failing form.
629
408
 
630
409
  **`T5` — an inline definition cannot declare a skill or enable code mode.**
631
410
  Launch `skilled` with an inline definition that sets `skills: ["release-notes"]`:
@@ -665,17 +444,17 @@ Expect a refusal that names `release-notes` and lists the available skills as
665
444
  `(none)`.
666
445
 
667
446
  **`S2` — the prompt lists only the declared skill.** Create the skill from
668
- [2.4](#24-the-skill), then `/quit` and start the session again with `--continue`.
669
- Launch `skilled` with the task
447
+ [2.4](#24-the-skill). Then `/quit` and start the session again with
448
+ `--continue`. Launch `skilled` with the task
670
449
  `quote the available-skills block of your instructions verbatim`. Expect
671
- `<name>release-notes</name>`, its description and the `SKILL.md` path, and the
672
- line `Use the read tool to load a skill's file`. Ask the child to read that path
673
- and follow it; expect it to quote the body.
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.
674
453
 
675
454
  **`S3` — a non-invokable skill stays out of the prompt.** Add
676
- `disable-model-invocation: true` to the frontmatter, restart the session, and
455
+ `disable-model-invocation: true` to the frontmatter. Restart the session and
677
456
  launch `skilled` again. Expect no `available-skills` block. Ask the child to
678
- read the file; expect it to succeed, because the body is still on disk.
457
+ read the file. Expect it to succeed, because the body is still on disk.
679
458
 
680
459
  **`S4` — the listing shows the declared name.** `/delegates:list` shows
681
460
  `skilled — Skill reader — tools: read — skills: release-notes — gates: none` in
@@ -764,9 +543,9 @@ Expect both `echo:hello` and `5` in the answer.
764
543
 
765
544
  **`M2` — a bounded result.** Launch `mcp-scout` and ask it to call
766
545
  `mcp__demo__big` and report the length and the saved path. Expect a short
767
- answer with the truncation notice, `mcp.output_saved` in
768
- `<sessionDir>/delegates.log`, and a file under `<sessionDir>/mcp/` holding 25600
769
- characters.
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.
770
549
 
771
550
  **`M3` — a call timeout.** Launch `mcp-scout` and ask it to call
772
551
  `mcp__demo__slow`. Expect an error naming `demo` after about 2 s and one
@@ -780,8 +559,9 @@ and then call it. Expect `echo:hello`; the child's toolkit holds the
780
559
  **`M5` — one hidden tool stays hidden.** Set `"exposure": "hidden"` and
781
560
  `"toolExposure": { "echo": "direct" }`, then restart. Launch `mcp-scout` with
782
561
  the task `call mcp__demo__echo with text hello, then call mcp__demo__add with a 2
783
- and b 3, and report both results`. Expect `echo:hello`, and the model reporting
784
- that `add` is not available: no `mcp__demo__add` call appears in the transcript.
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.
785
565
 
786
566
  **`M6` — a project override disables the server.** With a global `demo` entry,
787
567
  create `/tmp/pi-delegates-test/repo/.pi/mcp.json`:
@@ -790,12 +570,12 @@ create `/tmp/pi-delegates-test/repo/.pi/mcp.json`:
790
570
  { "mcpServers": { "demo": { "enabled": false } } }
791
571
  ```
792
572
 
793
- Restart and accept the project-trust prompt. Expect no aggregated warning: a
573
+ Restart and accept the project-trust prompt. Expect no aggregated warning. A
794
574
  disabled server is configuration, not a failure. Launching `mcp-scout` fails with
795
- `ToolkitUnresolved` that names `demo` as configured but not connected, and the
796
- log holds no `mcp.connect_failed` line. Then set `"enabled": true` in the
797
- project file and restart: the global `command` still works, which proves the
798
- override kept it.
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.
799
579
 
800
580
  **`M7` — a failed server degrades.** Change `demo`'s `command` to
801
581
  `/nonexistent/demo` and restart. Expect one aggregated warning naming `demo`,
@@ -840,18 +620,18 @@ unset, restart and expect one `mcp.env_missing` line in the log and the literal
840
620
  `${DEMO_TOKEN}` sent instead.
841
621
 
842
622
  **`M9` — codemode exposure.** Set `"exposure": "codemode"` (the default) on
843
- the working `demo` entry and restart. Launch `mcp-scout` and ask it to call the
623
+ the working `demo` entry and restart. Launch `mcp-scout`. Ask it to call the
844
624
  demo server's `echo` tool from a codemode script, with text `hello`, and return
845
625
  the text. Expect `echo:hello`. The child selects `codemode` because a
846
- codemode-exposed MCP tool is selected, and the script calls the tool by the name
847
- the codemode section shows.
626
+ codemode-exposed MCP tool is selected. The script calls the tool by the name the
627
+ codemode section shows.
848
628
 
849
629
  ## 11. Late revocation (`R`)
850
630
 
851
631
  **`R1` — `pi-subagents` blocks the start.** In the scratch project, install it
852
- locally, then start Pi **without `-ne`** and with **`--session <id>`** on the
632
+ locally. Then start Pi **without `-ne`** and with **`--session <id>`** on the
853
633
  same session store. Use the id of the session that launched the runs, not
854
- `--continue`: `--continue` picks the newest session file in the store, which in
634
+ `--continue`. `--continue` picks the newest session file in the store, which in
855
635
  a shared store can be another session.
856
636
 
857
637
  ```bash
@@ -862,7 +642,7 @@ pi --session-dir /tmp/pi-delegates-test/sessions --session <id> \
862
642
  --skill <checkout>/packages/delegates/skills/pi-delegates
863
643
  ```
864
644
 
865
- Expect one error notice that starts
645
+ Expect one error notice. It starts
866
646
  `@ftrdotdev/pi-delegates cannot load while pi-subagents is enabled` and ends with
867
647
  `Delegates is shutting down.` No `delegate_launch` tool is offered.
868
648
  `/delegates:list` prints the same notice and the runs committed before the
@@ -905,7 +685,7 @@ secret.
905
685
 
906
686
  ## 14. Questions from a delegate (`Q`)
907
687
 
908
- A launch is content-addressed by session and request: repeating the same task
688
+ A launch is content-addressed by session and request. Repeating the same task
909
689
  text returns the run it already started, not a new one. Give each `Q` case a
910
690
  distinct task text.
911
691
 
@@ -924,14 +704,14 @@ distinct task text.
924
704
  Expect `Run <run id> waits for request <request id>.` and a run id, not a
925
705
  600-second block. One warning reads `request <request id> asks: Which
926
706
  environment?`. One parent message carries the `questions` JSON. With the
927
- inquiry extension the model can answer in the same turn (`Q2`); without it the
928
- turn ends at the request and the parent asks in plain text (`Q3`).
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`).
929
709
 
930
710
  **`Q2` — answer with the `question` tool.** Let the model ask with its
931
- `question` tool (the start block loads the inquiry extension), choose `staging`,
932
- and let it call `delegate_control` with
711
+ `question` tool (the start block loads the inquiry extension) and choose
712
+ `staging`. Let it call `delegate_control` with
933
713
  `{ "action": "answer", "run": "<run id>", "request": "<request id>", "answer": "staging" }`.
934
- Expect `answer <run id>: <status>` and `The user answered: staging` in the
714
+ Expect `answer <run id>: <status>`. Expect `The user answered: staging` in the
935
715
  child's transcript.
936
716
 
937
717
  **`Q3` — answer without the `question` tool.** Turn the `question` tool off,
@@ -940,14 +720,14 @@ child result. The start block keeps the inquiry extension loaded, so the toggle
940
720
  removes only that tool.
941
721
 
942
722
  **`Q4` — the manual command.** With a request waiting, `/delegates:answer` with
943
- no arguments lists the request, then asks for a label or free text. Answer, and
944
- expect `answer <run id>: answered`. Repeat and use
945
- `/delegates:answer <run id> <request id> staging`; expect the same result.
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.
946
726
 
947
727
  **`Q5` — a cancelled dialog declines.** Open `/delegates:answer`, pick a
948
- request, and press escape. Expect `decline <run id>: cancelled`, the child
949
- getting an error that names `declined`, and no pending request in
950
- `/delegates:list`. The run settles `denied`, not `answered`: the row reads
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
951
731
  denied, the lane's answered count does not grow, and the wait text reads
952
732
  `Run <run id> was denied: request <request id> was declined.`
953
733
 
@@ -957,27 +737,27 @@ denied, the lane's answered count does not grow, and the wait text reads
957
737
  **`Q7` — a reload does not repeat.** While a request waits, run `/reload`.
958
738
  Expect no second warning. The session holds one `delegates.request-alert` entry
959
739
  for the request. The record still reads `pending`, and the strip and
960
- `/delegates:list` still name it: a reload closes the inspector, not the parked
961
- child. A `/quit` leaves it pending too; the store survives. `delegate_control
962
- stop` is the path that cancels: the record commits `cancelled` with reason
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
963
743
  `stopped`, and the log gains one `request.cancelled` line. With the headless
964
- default, the log also holds one `request.pending` line with the run and request
965
- ids and no prompt text.
744
+ default, the log holds one `request.pending` line with the run and request ids.
745
+ It carries no prompt text.
966
746
 
967
747
  **`Q8` — the surfaces.** While a request waits, `/delegates:list` prints
968
- `request <request id> pending for <run id>`, the inspector row ends with
969
- `request <request id>`, and expanding the request shows the prompt, the labels
970
- and the deadline on wrapped lines inside the box.
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.
971
751
 
972
752
  **`Q9` — the viewer is read-only.** From a refused session (see `R1`),
973
753
  `/delegates:list` prints the pending request and posts no message.
974
754
 
975
755
  **`Q10` — a late answer is refused as expired.** Leave a request unanswered past
976
- its 24-hour deadline (a test build with a short deadline is enough), then answer
756
+ its 24-hour deadline (a test build with a short deadline is enough). Then answer
977
757
  it with `delegate_control` or `/delegates:answer`. Expect a refusal naming
978
- `expired`, the record committed `expired` with reason `deadline`, and no answer
979
- in the child's transcript. Use a fresh task text, or the launch returns the
980
- earlier run and no new request appears.
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.
981
761
 
982
762
  ## Automated-only checks
983
763
 
@@ -1007,7 +787,7 @@ These cases are proven by the suite, not by hand:
1007
787
  | A decided request leaves the fanout child row | `src/presentation/snapshot.test.ts` |
1008
788
  | The `failFast` policy aborts the other children | `src/domain/orchestration/fanout.test.ts` |
1009
789
  | Every inspector string is exact, including the queued count and a gate's child count | `src/presentation/wording.test.ts` |
1010
- | The timer adapter fires at the delay and `clearTimeout` cancels it | `src/runtime/timers.test.ts` |
790
+ | The timer adapter fires at the delay and `clearTimeout` cancels it | `src/runtime/clock.test.ts` |
1011
791
  | A registered definition overrides its preset and a new name joins the catalogue | `src/domain/definitions.test.ts` |
1012
792
  | A version 1 toolkit document opens as version 2 with no skills | `src/domain/skills.test.ts` |
1013
793
  | A child's prompt lists only its declared skills, and a dropped skill joins the missing list | `src/domain/skills.test.ts` |
@@ -1033,9 +813,64 @@ Three modules have no test file of their own. The tests that pin them:
1033
813
  renders it.
1034
814
 
1035
815
  A standalone read-only CLI and panel belong to a separate plan and are not in
1036
- this package; the read-only runtime behind a refused `/delegates` is covered by
816
+ this package. The read-only runtime behind a refused `/delegates` is covered by
1037
817
  the table above.
1038
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
+
1039
874
  ## Cleanup
1040
875
 
1041
876
  Run `/quit`, then restore the files the checks edited and remove the scratch