@xzzpig/pi-subagents 0.18.0 → 0.19.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 (95) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +1 -1
  3. package/docs/agents.md +18 -12
  4. package/docs/configuration.md +66 -9
  5. package/docs/extension-api.md +5 -4
  6. package/docs/missions.md +13 -13
  7. package/docs/models.md +2 -2
  8. package/docs/observability.md +2 -2
  9. package/docs/standalone-background.md +1 -1
  10. package/docs/tool-reference.md +63 -86
  11. package/docs/workflows.md +170 -172
  12. package/node_modules/@xzzpig/pi-components/package.json +4 -4
  13. package/package.json +6 -6
  14. package/prompts/review-loop.md +1 -1
  15. package/skills/council-mode/SKILL.md +1 -1
  16. package/skills/pi-subagents/SKILL.md +12 -5
  17. package/skills/pi-subagents/references/constraints-and-recipes.md +3 -3
  18. package/skills/pi-subagents/references/execution-controls.md +68 -67
  19. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  20. package/skills/pi-subagents/references/multi-lane-orchestration.md +1 -1
  21. package/skills/pi-subagents/references/prompting-and-roles.md +45 -48
  22. package/src/agents/advertised-agent-prompt.ts +21 -41
  23. package/src/agents/agent-management.ts +2 -2
  24. package/src/agents/agents.ts +7 -0
  25. package/src/api/preflight.ts +67 -62
  26. package/src/extension/config.ts +12 -4
  27. package/src/extension/control-notices.ts +3 -0
  28. package/src/extension/doctor.ts +1 -0
  29. package/src/extension/fanout-child.ts +12 -3
  30. package/src/extension/herdr-pi-bridge.ts +2 -0
  31. package/src/extension/index.ts +68 -159
  32. package/src/extension/public-execution.ts +69 -35
  33. package/src/extension/reply-workflow-script.ts +58 -0
  34. package/src/extension/rpc.ts +29 -10
  35. package/src/extension/schemas.ts +36 -133
  36. package/src/extension/tool-activation.ts +57 -108
  37. package/src/extension/tool-description.ts +62 -27
  38. package/src/extension/upgrade-notice.ts +40 -0
  39. package/src/integrations/herdr-status.ts +19 -3
  40. package/src/intercom/native-supervisor-channel.ts +4 -1
  41. package/src/runs/background/async-execution.ts +58 -53
  42. package/src/runs/background/async-job-tracker.ts +63 -22
  43. package/src/runs/background/async-retention.ts +46 -16
  44. package/src/runs/background/await-async-run.ts +76 -0
  45. package/src/runs/background/chain-root-attachment.ts +4 -4
  46. package/src/runs/background/control-channel.ts +18 -2
  47. package/src/runs/background/notify.ts +5 -0
  48. package/src/runs/background/run-child-session.ts +4 -1
  49. package/src/runs/background/run-status.ts +6 -0
  50. package/src/runs/background/runner-aliases.ts +30 -2
  51. package/src/runs/background/runner-child-launch.ts +3 -0
  52. package/src/runs/background/scheduled-runs.ts +5 -5
  53. package/src/runs/background/subagent-runner.ts +15 -1
  54. package/src/runs/foreground/async-stop-action.ts +17 -3
  55. package/src/runs/foreground/execution.ts +130 -125
  56. package/src/runs/foreground/subagent-executor.ts +487 -288
  57. package/src/runs/shared/async-status-projection.ts +5 -0
  58. package/src/runs/shared/child-launch.ts +15 -2
  59. package/src/runs/shared/child-session.ts +92 -6
  60. package/src/runs/shared/child-tool-plan.ts +15 -3
  61. package/src/runs/shared/dynamic-fanout.ts +1 -1
  62. package/src/runs/shared/mcp-config-sources.ts +2 -1
  63. package/src/runs/shared/mcp-direct-tool-allowlist.ts +103 -11
  64. package/src/runs/shared/model-resolution.ts +29 -9
  65. package/src/runs/shared/model-scope.ts +28 -9
  66. package/src/runs/shared/nested-events.ts +55 -55
  67. package/src/runs/shared/parallel-utils.ts +2 -0
  68. package/src/runs/shared/pi-spawn.ts +7 -95
  69. package/src/runs/shared/subagent-prompt-runtime.ts +2 -0
  70. package/src/runs/shared/worktree.ts +1 -1
  71. package/src/shared/disabled-features.ts +123 -0
  72. package/src/shared/extension-context.ts +13 -0
  73. package/src/shared/model-info.ts +9 -0
  74. package/src/shared/settings.ts +1 -1
  75. package/src/shared/types.ts +21 -0
  76. package/src/slash/prompt-template-bridge.ts +2 -2
  77. package/src/slash/slash-commands.ts +10 -5
  78. package/src/slash/subagents-admin.ts +24 -24
  79. package/src/tui/fleet-status.ts +14 -6
  80. package/src/tui/fleet.ts +14 -2
  81. package/src/tui/render.ts +113 -52
  82. package/src/tui/running-tone.ts +28 -0
  83. package/src/watchdog/diff-tool.ts +23 -9
  84. package/src/watchdog/register-child.ts +3 -3
  85. package/src/watchdog/register-main.ts +3 -3
  86. package/src/watchdog/review.ts +2 -2
  87. package/src/watchdog/turn-delta.ts +1 -1
  88. package/src/workflows/chat-progress.ts +2 -2
  89. package/src/workflows/scripted-workflow.ts +117 -37
  90. package/src/workflows/structured-workflow-scripts.ts +177 -0
  91. package/src/workflows/workflow-checklist.ts +6 -0
  92. package/src/workflows/workflow-receipt.ts +8 -2
  93. package/src/workflows/workflow-resources.ts +37 -12
  94. package/src/workflows/workflow-reuse.ts +120 -0
  95. package/src/workflows/workflow-revival.ts +123 -0
package/docs/workflows.md CHANGED
@@ -25,6 +25,10 @@ A failure in the subagent workflow, child launch, prompt runtime, extension load
25
25
 
26
26
  Stop and report the exact failure, run/status, and repository/cwd/worktree/branch/ref state. Before a same-protocol retry or asking the owner, verify the worktree is clean or capture the partial diff. Retry or fix the `subagent` path only through a clear same-protocol action. For backlog lanes and other subagent-governed workflows, external/foreground/CLI fallback requires explicit owner approval. `interactive_shell` remains valid when the user explicitly requests visible foreground/CLI work or the task is outside the governed subagent protocol.
27
27
 
28
+ Failed workflow details and async `status.json` include `workflow.failureKind` as `validation`, `script`, `child`, `return-serialization`, `timeout`, `detached-child`, or `runtime`. `validation` means the host rejected the script before it ran (syntax or portability) or at completion (unawaited calls); errors thrown into a running script, including rejected `runs.run` parameters and runtime `SyntaxError`s, are `script` because the script could catch them, and failed children are `child`. `runtime` covers host setup and infrastructure failures, such as an unavailable cwd or a crashed worker. A workflow that is stopped or reloaded is not a failure and has no `failureKind`.
29
+
30
+ When `/reload`, a session resume, or a pi-web project switch replaces the extension runtime, a running async workflow stops with `workflow.stopCause: "runtime-replaced"` in `status.json`, and its awaited async children keep running. When the same workflow script is launched again with the same `args` in that session, a `runs.run` with the same key and params returns a child that already finished successfully without launching it, and waits for a child that is still running instead of starting another. Those results carry `reused: true`, their step and trace entry are marked `reused`, and the new run records `workflow.reusedFrom`. Failed and stopped children, and children that ran in-process, launch again. Reuse applies only when the newest run of that script and args in the session was stopped this way; a user stop or a completed run ends it.
31
+
28
32
  Pi core may print a generic `pi -ne` extension-load hint; that out-of-repo hint is not protocol-approved fallback. A verified compaction abort may continue the retained child once on its already resolved model; it does not authorize an execution-mode or model switch.
29
33
 
30
34
  ## Prompt shortcuts
@@ -41,9 +45,17 @@ The package includes reusable prompt templates for common workflows. You do not
41
45
 
42
46
  Add `autofix` to `/parallel-review` or `/parallel-cleanup` to apply only the synthesized fixes worth doing now after reviewers return.
43
47
 
44
- ## Scripted workflows (workflowScript)
48
+ ## Scripted workflows
49
+
50
+ Use direct `{ agent, task }` for one bounded child. Use a workflow script when the parent needs a stable keyed child, sequence, fanout, steering, retry, or aggregation. For ordinary parallel fanout, use `await runs.all([{ key, agent, task }, ...])`. It resolves to an ordered array, not a key map, so use indexes, destructuring, or `.map(...)`, not `results.<key>`. Do not read `.output` from unawaited `runs.run` launches. Store a `runs.run` promise only when the script later observes it with `await`, `Promise.race`, or `Promise.all`, such as steering a live child before awaiting its result. Scripts are ordinary JavaScript statement bodies. Use an explicit `return` for a useful result.
51
+
52
+ The `workflow` field selects the script source:
53
+
54
+ - `workflow: true` runs the one ```` ```js workflow ```` fenced block written in the same assistant reply as the `subagent` call. The script is plain text in the reply, so it needs no JSON string escaping. A reply can carry exactly one such block and one `workflow: true` call; zero or several blocks fail. A line containing only ```` ``` ```` (three or more backticks, optionally followed by spaces or tabs) ends the block, so keep Markdown fences inside quoted strings.
55
+ - A string containing `/` (or `\` in a Windows path), such as `workflow: "./workflows/review.js"`, is a script file.
56
+ - Any other string, such as `workflow: "review"`, is a [named workflow resource](#named-workflow-resources-for-permission-extensions).
45
57
 
46
- Use direct `{ agent, task }` for one bounded child. Use `workflowScript` when the parent needs a stable keyed child, sequence, fanout, steering, retry, or aggregation. For ordinary parallel fanout, use `await runs.all([{ key, agent, task }, ...])`. It resolves to an ordered array, not a key map, so use indexes, destructuring, or `.map(...)`, not `results.<key>`. Do not read `.output` from unawaited `runs.run` launches. Store a `runs.run` promise only when the script later observes it with `await`, `Promise.race`, or `Promise.all`, such as steering a live child before awaiting its result. Scripts are ordinary JavaScript statement bodies. Use an explicit `return` for a useful result:
58
+ `workflow: true` works only from a model tool call. Slash commands, RPC, and schedules pass scripts through their own inputs. Examples below that show only a ```` ```js workflow ```` block run with `subagent({ workflow: true })` in the same reply.
47
59
 
48
60
  For multi-step or parallel work, make exactly one top-level `subagent` workflow call with `async:true` and launch children only inside it. Read this guide for recipes rather than constructing a second top-level orchestration. Available sandbox helpers include `runs.run`, `runs.all`, `runs.lanes`, `runs.steer`, `runs.status`, `runs.ref`/`runs.refs`, `emit`, `console`, standard JavaScript, and mission `state` when enabled. No filesystem, shell, arbitrary Pi tools, or host globals are available; named resources alone may grant `runs.host` authority.
49
61
 
@@ -57,26 +69,28 @@ A workflow can finish dispatch while these children remain running. Its summary
57
69
 
58
70
  Validate a script without launching children:
59
71
 
72
+ ```js workflow
73
+ const results = await runs.all([{ key: "scan", agent: "scout", task: "Scan" }]);
74
+ return results[0].output;
75
+ ```
76
+
60
77
  ```js
61
- subagent({ action: "validate", workflowScript: `
62
- const results = await runs.all([{ key: "scan", agent: "scout", task: "Scan" }]);
63
- return results[0].output;
64
- ` });
78
+ subagent({ action: "validate", workflow: true });
65
79
  ```
66
80
 
67
- For a script stored in a file, use `workflowScriptPath` instead of `workflowScript`:
81
+ For a script stored in a file, pass its path:
68
82
 
69
83
  ```js
70
- subagent({ workflowScriptPath: "workflows/review.js", cwd: "/path/to/project" });
71
- subagent({ action: "validate", workflowScriptPath: "workflows/review.js" });
84
+ subagent({ workflow: "./workflows/review.js", cwd: "/path/to/project" });
85
+ subagent({ action: "validate", workflow: "./workflows/review.js" });
72
86
  ```
73
87
 
74
- The fields are mutually exclusive. Relative paths resolve against the request `cwd`; absolute paths pass through. The host reads the file before validation, schedule creation, or workflow sandbox execution. The sandbox still has no filesystem access. Missing, unreadable, and empty files return file input errors instead of script syntax errors.
88
+ Relative paths resolve against the request `cwd`; absolute paths pass through. The host reads the file before validation, schedule creation, or workflow sandbox execution. The sandbox still has no filesystem access. Missing, unreadable, and empty files return file input errors instead of script syntax errors.
75
89
 
76
- Inline and file-backed scripts accept bounded plain-JSON `args`:
90
+ Reply-block and file-backed scripts accept bounded plain-JSON `args`:
77
91
 
78
92
  ```js
79
- subagent({ workflowScriptPath: "workflows/review.js", args: { target: "src/workflows" } });
93
+ subagent({ workflow: "./workflows/review.js", args: { target: "src/workflows" } });
80
94
  // workflows/review.js
81
95
  return runs.run("review", { agent: "reviewer", task: `Review ${args.target}` });
82
96
  ```
@@ -92,18 +106,20 @@ subagent({ workflow: "review", args: { task: "Review the change" } });
92
106
  subagent({ workflow: "run-ci", args: { command: "npm test" } });
93
107
  ```
94
108
 
95
- The host resolves the name and validates bounded plain-JSON `args` before starting the workflow. Resource provenance is recorded in workflow details and receipts for downstream permission/policy checks. Resource authority is not caller-supplied: `runs.host` is available only when the resolved resource explicitly grants the requested host key and command. Inline `workflowScript` and `workflowScriptPath` remain raw, unknown-provenance inputs, so their `runs.host` calls are unavailable through the public execution boundary. Named resources cannot be combined with `agent`, `task`, `workflowScript`, or `workflowScriptPath`; this first slice ships only the package-owned `review` and `run-ci` resources, not a user/project resource registry.
109
+ The host resolves the name and validates bounded plain-JSON `args` before starting the workflow. Resource provenance is recorded in workflow details and receipts for downstream permission/policy checks. Resource authority is not caller-supplied: `runs.host` is available only when the resolved resource explicitly grants the requested host key and command. Reply-block (`workflow: true`) and file-path scripts remain raw, unknown-provenance inputs, so their `runs.host` calls are unavailable through the public execution boundary. Named resources cannot be combined with `agent` or `task`; this first slice ships only the package-owned `review` and `run-ci` resources, not a user/project resource registry.
96
110
 
97
111
  ### Opt-in bounded workflows
98
112
 
99
113
  Composite workflows have no default parent deadline. Add bounds only when the workflow contract calls for them:
100
114
 
115
+ ```js workflow
116
+ const scan = await runs.run("scan", { agent: "scout", task: "Inspect the named files." });
117
+ return runs.run("review", { agent: "reviewer", task: "Review:\n" + scan.output });
118
+ ```
119
+
101
120
  ```js
102
121
  subagent({
103
- workflowScript: `
104
- const scan = await runs.run("scan", { agent: "scout", task: "Inspect the named files." });
105
- return runs.run("review", { agent: "reviewer", task: "Review:\n" + scan.output });
106
- `,
122
+ workflow: true,
107
123
  timeoutMs: 900000,
108
124
  toolBudget: { soft: 40, hard: 60 },
109
125
  usageBudget: { tokens: { soft: 100000, hard: 150000 } }
@@ -118,80 +134,76 @@ subagent({
118
134
 
119
135
  These controls are opt-in. Avoid tight hard budgets for mutation-capable workers unless the workflow has an explicit checkpoint and handoff path.
120
136
 
121
- The optional `preflight` lane hints apply only to raw `workflowScript` or `workflowScriptPath` requests, not named workflows or direct child calls. They are display-only: mismatched coverage warns but never changes execution authority.
137
+ The optional `preflight` lane hints apply only to raw scripts (`workflow: true` or a script path), not named workflows or direct child calls. They are display-only: mismatched coverage warns but never changes execution authority.
122
138
 
123
- The result is `{ ok, errors }`. Invalid scripts return a tool error and include line and column data when available. Validation checks syntax, portable nested-async rules, literal `runs.run` and `runs.all` keys and child `baseRef` values, duplicate literal keys in one `runs.all` group, direct keyed access to a known `runs.all` result, and statically clear non-JSON boundary values. Dynamic keys and other runtime-only values are accepted without a warning. Validation does not discover agents, launch children, or create run artifacts.
139
+ The result is `{ ok, errors }`. Invalid scripts return a tool error and include line and column data when available. Validation checks syntax, portable nested-async rules, literal `runs.run` and `runs.all` keys and child `baseRef` values, duplicate literal keys in one `runs.all` group, direct keyed access to a known `runs.all` result, and statically clear non-JSON boundary values. It also looks up literal `agent` names in `runs.run`, `runs.all`, and `runs.lanes` children against the agents discovered for the request `cwd` and `agentScope`, and reports unknown or ambiguous names with a close match when one exists. Children with their own `cwd`, `agentScope`, or `resume`, object spreads, and names built at runtime are left to launch time. Dynamic keys and other runtime-only values are accepted without a warning. Validation does not launch children or create run artifacts. Executing a workflow runs the same agent-name check first, so an unknown literal agent fails before any child launches.
140
+
141
+ ```js workflow
142
+ const scan = await runs.run("scan", { label: "Map codebase behavior", agent: "scout", task: "Scan the codebase" });
143
+ const reviews = await runs.all([
144
+ { key: "correctness", label: "Review codebase correctness", agent: "reviewer", task: "Review correctness: " + scan.output },
145
+ { key: "tests", label: "Review test coverage", agent: "reviewer", task: "Review tests: " + scan.output }
146
+ ]);
147
+ return reviews.map(result => result.output);
148
+ ```
124
149
 
125
150
  ```js
126
- subagent({ workflowScript: `
127
- const scan = await runs.run("scan", { label: "Map codebase behavior", agent: "scout", task: "Scan the codebase" });
128
- const reviews = await runs.all([
129
- { key: "correctness", label: "Review codebase correctness", agent: "reviewer", task: "Review correctness: " + scan.output },
130
- { key: "tests", label: "Review test coverage", agent: "reviewer", task: "Review tests: " + scan.output }
131
- ]);
132
- return reviews.map(result => result.output);
133
- ` });
151
+ subagent({ workflow: true });
134
152
  ```
135
153
 
136
- Keep helper functions portable across Node and Bun. Use top-level `await`, plain helper functions that return `runs.run(...)`, or explicit Promise chains. Do not define nested `async function` helpers, async arrows, or async methods inside `workflowScript`; native async helpers hide child-launch observation in Bun and are rejected.
154
+ Keep helper functions portable across Node and Bun. Use top-level `await`, plain helper functions that return `runs.run(...)`, or explicit Promise chains. Do not define nested `async function` helpers, async arrows, or async methods inside a workflow script; native async helpers hide child-launch observation in Bun and are rejected.
137
155
 
138
- ```js
139
- subagent({ workflowScript: `
140
- function scan() {
141
- return runs.run("scan", { label: "Map codebase behavior", agent: "scout", task: "Scan the codebase" });
142
- }
143
- const result = await scan();
144
- return result.output;
145
- ` });
156
+ ```js workflow
157
+ function scan() {
158
+ return runs.run("scan", { label: "Map codebase behavior", agent: "scout", task: "Scan the codebase" });
159
+ }
160
+ const result = await scan();
161
+ return result.output;
146
162
  ```
147
163
 
148
164
  Chaining is still supported. The supported form is scripted chaining: await one `runs.run(...)` result, then pass its output into the next step. Parallel fanout uses `runs.all(...)` inside the same script.
149
165
 
150
- ```js
151
- subagent({ workflowScript: `
152
- const plan = await runs.run("plan", { label: "Plan migration behavior", agent: "scout", task: "Plan the migration" });
153
- const patch = await runs.run("patch", { label: "Implement migration behavior", agent: "worker", task: "Implement this plan:\n" + plan.output });
154
- return patch.output;
155
- ` });
166
+ ```js workflow
167
+ const plan = await runs.run("plan", { label: "Plan migration behavior", agent: "scout", task: "Plan the migration" });
168
+ const patch = await runs.run("patch", { label: "Implement migration behavior", agent: "worker", task: "Implement this plan:\n" + plan.output });
169
+ return patch.output;
156
170
  ```
157
171
 
158
172
  ### Parallel sequential lanes
159
173
 
160
- For a bounded set of independent chains, `runs.lanes(...)` removes the mechanical loop that would otherwise connect each lane's stages. It is a helper inside `workflowScript`, not a new top-level `subagent` execution mode:
161
-
162
- ```js
163
- subagent({ workflowScript: `
164
- const board = await runs.lanes([
165
- {
166
- key: "api",
167
- stages: [
168
- { key: "writer", label: "Implement API behavior", agent: "worker", task: "Implement the API change" },
169
- { key: "challenge", label: "Challenge API behavior", resume: "previous", task: "Challenge the API implementation" },
170
- { key: "review", label: "Review API behavior", agent: "reviewer", task: "Review the API lane" }
171
- ]
172
- },
173
- {
174
- key: "ui",
175
- stages: [
176
- { key: "writer", label: "Implement UI behavior", agent: "worker", task: "Implement the UI change" },
177
- { key: "review", label: "Review UI behavior", agent: "reviewer", task: "Review the UI lane" }
178
- ]
179
- }
180
- ]);
181
- return board.map((lane) => ({
182
- key: lane.key,
183
- state: lane.state,
184
- failedStage: lane.failedStage,
185
- stages: lane.stages.map((stage) => ({
186
- key: stage.key,
187
- state: stage.state,
188
- ok: stage.ok,
189
- runId: stage.runId,
190
- outputReference: stage.outputReference,
191
- verdict: stage.verdict
192
- }))
193
- }));
194
- ` });
174
+ For a bounded set of independent chains, `runs.lanes(...)` removes the mechanical loop that would otherwise connect each lane's stages. It is a helper inside a workflow script, not a new top-level `subagent` execution mode:
175
+
176
+ ```js workflow
177
+ const board = await runs.lanes([
178
+ {
179
+ key: "api",
180
+ stages: [
181
+ { key: "writer", label: "Implement API behavior", agent: "worker", task: "Implement the API change" },
182
+ { key: "challenge", label: "Challenge API behavior", resume: "previous", task: "Challenge the API implementation" },
183
+ { key: "review", label: "Review API behavior", agent: "reviewer", task: "Review the API lane" }
184
+ ]
185
+ },
186
+ {
187
+ key: "ui",
188
+ stages: [
189
+ { key: "writer", label: "Implement UI behavior", agent: "worker", task: "Implement the UI change" },
190
+ { key: "review", label: "Review UI behavior", agent: "reviewer", task: "Review the UI lane" }
191
+ ]
192
+ }
193
+ ]);
194
+ return board.map((lane) => ({
195
+ key: lane.key,
196
+ state: lane.state,
197
+ failedStage: lane.failedStage,
198
+ stages: lane.stages.map((stage) => ({
199
+ key: stage.key,
200
+ state: stage.state,
201
+ ok: stage.ok,
202
+ runId: stage.runId,
203
+ outputReference: stage.outputReference,
204
+ verdict: stage.verdict
205
+ }))
206
+ }));
195
207
  ```
196
208
 
197
209
  The first stage from every lane is launched in one existing `runs.all(...)` batch. Later stages in each lane start only after the preceding stage settles. A later stage with `resume: "previous"` requires the preceding child to return a retained `runId`; the helper then uses the existing retained-resume launch checks and does not accept an arbitrary run id. Generated child keys use `<lane>.<stage>`, while the returned board uses the local lane and stage keys.
@@ -206,18 +218,16 @@ Two ways to put a small classifier (a script, a lookup, a fast evaluation model)
206
218
 
207
219
  **A typed gate** runs a command after a child finishes and turns its JSON stdout into that child's `structuredOutput`:
208
220
 
209
- ```js
210
- subagent({ workflowScript: `
211
- const review = await runs.run("review", {
212
- agent: "reviewer", task: packet,
213
- output: "reports/review.md", outputMode: "file-only",
214
- gate: { command: "classify --report reports/review.md", output: "json" }
215
- });
216
- if (review.structuredOutput.verdict === "blocked") {
217
- return runs.run("fix", { agent: "worker", task: "Fix the findings in reports/review.md" });
218
- }
219
- return { verdict: review.structuredOutput.verdict, report: "reports/review.md" };
220
- ` });
221
+ ```js workflow
222
+ const review = await runs.run("review", {
223
+ agent: "reviewer", task: args.packet,
224
+ output: "reports/review.md", outputMode: "file-only",
225
+ gate: { command: "classify --report reports/review.md", output: "json" }
226
+ });
227
+ if (review.structuredOutput.verdict === "blocked") {
228
+ return runs.run("fix", { agent: "worker", task: "Fix the findings in reports/review.md" });
229
+ }
230
+ return { verdict: review.structuredOutput.verdict, report: "reports/review.md" };
221
231
  ```
222
232
 
223
233
  The parent receives a pointer plus a verdict instead of the review text. See [typed gates](tool-reference.md#typed-gates) for the contract and failure rules.
@@ -262,13 +272,11 @@ The first named resource version supports only `npm test` and `npm run typecheck
262
272
 
263
273
  Use `await runs.steer(key, message, options?)` after `runs.run` or `runs.all` has launched that stable key. Scripts do not target raw run ids. The optional fields are `mode: "steer" | "follow_up" | "auto"`, a non-negative child `index`, and a positive `ackTimeoutMs`.
264
274
 
265
- ```js
266
- subagent({ workflowScript: `
267
- const writer = runs.run("writer", { agent: "worker", task: "Implement the change" });
268
- const evidence = await runs.run("evidence", { agent: "scout", task: "Find the exact contract" });
269
- const receipt = await runs.steer("writer", "Also check: " + evidence.output, { mode: "follow_up" });
270
- return { writer: await writer, receipt };
271
- ` });
275
+ ```js workflow
276
+ const writer = runs.run("writer", { agent: "worker", task: "Implement the change" });
277
+ const evidence = await runs.run("evidence", { agent: "scout", task: "Find the exact contract" });
278
+ const receipt = await runs.steer("writer", "Also check: " + evidence.output, { mode: "follow_up" });
279
+ return { writer: await writer, receipt };
272
280
  ```
273
281
 
274
282
  The receipt state is `queued`, `delivered`, `missed`, or `failed`. For an async child, `delivered` means it consumed the correlated user input; for a foreground child, it means the in-process Pi transport accepted the input. It does not mean the model followed it. `missed` means the keyed child became terminal or had no live route before delivery. This first slice uses the existing foreground and async steering transports but does not start steering recovery. Workflow traces include one steering attempt entry and one receipt entry.
@@ -279,111 +287,99 @@ Always await or return a `runs.steer` promise. The workflow waits for an observe
279
287
 
280
288
  `runs.run` starts a keyed child when you call it. You do not need separate `runs.start`, `runs.next`, or `runs.collect` helpers for rolling councils or staged reviews. This is the advanced exception to ordinary `runs.all` fanout: keep launched promises only when the script later observes each one with direct `await`, `Promise.race`, or `Promise.all`. Use `Promise.race` to wait for the next completed child, steer a still-running sibling by its stable key, and use `Promise.all` to collect the remaining children.
281
289
 
282
- ```js
283
- subagent({ workflowScript: `
284
- let pending = [
285
- { key: "analysis-a", promise: runs.run("analysis-a", { agent: "reviewer", task: "Analyze option A" }).then((result) => ({ key: "analysis-a", result })) },
286
- { key: "analysis-b", promise: runs.run("analysis-b", { agent: "reviewer", task: "Analyze option B" }).then((result) => ({ key: "analysis-b", result })) },
287
- { key: "critic", promise: runs.run("critic", { agent: "reviewer", task: "Find the strongest objection" }).then((result) => ({ key: "critic", result })) }
288
- ];
290
+ ```js workflow
291
+ let pending = [
292
+ { key: "analysis-a", promise: runs.run("analysis-a", { agent: "reviewer", task: "Analyze option A" }).then((result) => ({ key: "analysis-a", result })) },
293
+ { key: "analysis-b", promise: runs.run("analysis-b", { agent: "reviewer", task: "Analyze option B" }).then((result) => ({ key: "analysis-b", result })) },
294
+ { key: "critic", promise: runs.run("critic", { agent: "reviewer", task: "Find the strongest objection" }).then((result) => ({ key: "critic", result })) }
295
+ ];
289
296
 
290
- const first = await Promise.race(pending.map((child) => child.promise));
291
- pending = pending.filter((child) => child.key !== first.key);
297
+ const first = await Promise.race(pending.map((child) => child.promise));
298
+ pending = pending.filter((child) => child.key !== first.key);
292
299
 
293
- const target = pending.find((child) => child.key === "critic") ?? pending[0];
294
- const receipt = await runs.steer(target.key, "Challenge this early result:\n" + first.result.output, { mode: "auto" });
295
- const rest = await Promise.all(pending.map((child) => child.promise));
300
+ const target = pending.find((child) => child.key === "critic") ?? pending[0];
301
+ const receipt = await runs.steer(target.key, "Challenge this early result:\n" + first.result.output, { mode: "auto" });
302
+ const rest = await Promise.all(pending.map((child) => child.promise));
296
303
 
297
- return { first: first.result.output, rest: rest.map((child) => child.result.output), receipt };
298
- ` });
304
+ return { first: first.result.output, rest: rest.map((child) => child.result.output), receipt };
299
305
  ```
300
306
 
301
307
  The workflow trace records the run completions and steering receipt. Scripts cannot access the filesystem or control inboxes; returned run and artifact references are data only. If the keyed child is terminal, stale, or has no live route when `runs.steer` runs, the receipt reports `missed` or `failed` and the script can decide whether to continue.
302
308
 
303
309
  Use named outputs when later workflow steps need structured data or durable references:
304
310
 
305
- ```js
306
- subagent({ workflowScript: `
307
- const inventory = await runs.run("inventory", {
308
- agent: "scout",
309
- task: "List the files that need review.",
310
- outputSchema: {
311
- type: "object",
312
- properties: { files: { type: "array", items: { type: "string" } } },
313
- required: ["files"],
314
- additionalProperties: false
315
- }
316
- });
317
- return runs.run("review", {
318
- agent: "reviewer",
319
- task: "Review these files: " + inventory.structuredOutput.files.join(", ")
320
- });
321
- ` });
311
+ ```js workflow
312
+ const inventory = await runs.run("inventory", {
313
+ agent: "scout",
314
+ task: "List the files that need review.",
315
+ outputSchema: {
316
+ type: "object",
317
+ properties: { files: { type: "array", items: { type: "string" } } },
318
+ required: ["files"],
319
+ additionalProperties: false
320
+ }
321
+ });
322
+ return runs.run("review", {
323
+ agent: "reviewer",
324
+ task: "Review these files: " + inventory.structuredOutput.files.join(", ")
325
+ });
322
326
  ```
323
327
 
324
328
  For dynamic fanout, have one step return a structured list, check it in JavaScript, then map the bounded entries into `runs.all(...)`:
325
329
 
326
- ```js
327
- subagent({ workflowScript: `
328
- const targets = await runs.run("targets", {
329
- agent: "scout",
330
- task: "Return up to five source files that need review.",
331
- outputSchema: {
332
- type: "object",
333
- properties: { files: { type: "array", items: { type: "string" }, maxItems: 5 } },
334
- required: ["files"],
335
- additionalProperties: false
336
- }
337
- });
338
- const files = targets.structuredOutput.files.slice(0, 5);
339
- return runs.all(files.map((file, index) => ({
340
- key: "review-" + index,
341
- agent: "reviewer",
342
- task: "Review " + file
343
- })));
344
- ` });
330
+ ```js workflow
331
+ const targets = await runs.run("targets", {
332
+ agent: "scout",
333
+ task: "Return up to five source files that need review.",
334
+ outputSchema: {
335
+ type: "object",
336
+ properties: { files: { type: "array", items: { type: "string" }, maxItems: 5 } },
337
+ required: ["files"],
338
+ additionalProperties: false
339
+ }
340
+ });
341
+ const files = targets.structuredOutput.files.slice(0, 5);
342
+ return runs.all(files.map((file, index) => ({
343
+ key: "review-" + index,
344
+ agent: "reviewer",
345
+ task: "Review " + file
346
+ })));
345
347
  ```
346
348
 
347
349
  For intermediate data that only later steps need, prefer the prior child's returned output or `structuredOutput` instead of writing shared files:
348
350
 
349
- ```js
350
- subagent({ workflowScript: `
351
- const scan = await runs.run("scan", { agent: "scout", task: "Find the files that need fixes." });
352
- return runs.run("fix", { agent: "worker", task: "Implement these findings:\n" + scan.output });
353
- ` });
351
+ ```js workflow
352
+ const scan = await runs.run("scan", { agent: "scout", task: "Find the files that need fixes." });
353
+ return runs.run("fix", { agent: "worker", task: "Implement these findings:\n" + scan.output });
354
354
  ```
355
355
 
356
356
  `{chain_dir}` remains available inside scripted workflow step templates for legacy-compatible path templates. It expands to the workflow cwd, not to private temporary storage.
357
357
 
358
358
  ### Migrating old chain shapes
359
359
 
360
- Legacy top-level `chain`, `tasks`, `parallel`, `chainDir`, `/chain`, `/parallel`, `/run-chain`, and durable `.chain.md` execution are no longer the public workflow API. Rewrite them as JavaScript:
360
+ Legacy top-level `chain`, `tasks`, `parallel`, `chainDir`, `/chain`, `/parallel`, `/run-chain`, and durable `.chain.md` execution are no longer the public workflow API. Rewrite them as JavaScript. The exception is `disabledFeatures: ["workflow-scripts"]`, which replaces workflow scripts with top-level `chain` and `tasks` (see [configuration](configuration.md#chain-and-tasks-without-workflow-scripts)).
361
361
 
362
- ```js
362
+ ```js workflow
363
363
  // Old shape, no longer supported:
364
364
  // { chain: [{ agent: "scout", task: "Scan" }, { agent: "worker", task: "Fix from {previous}" }] }
365
365
 
366
- // Current shape:
367
- { workflowScript: `
368
- const scan = await runs.run("scan", { agent: "scout", task: "Scan" });
369
- return runs.run("fix", { agent: "worker", task: "Fix from: " + scan.output });
370
- ` }
366
+ // Current shape: this ```js workflow block plus subagent({ workflow: true })
367
+ const scan = await runs.run("scan", { agent: "scout", task: "Scan" });
368
+ return runs.run("fix", { agent: "worker", task: "Fix from: " + scan.output });
371
369
  ```
372
370
 
373
- ```js
371
+ ```js workflow
374
372
  // Old shape, no longer supported:
375
373
  // { tasks: [{ agent: "reviewer", task: "Review API" }, { agent: "reviewer", task: "Review UI" }] }
376
374
 
377
- // Current shape:
378
- { workflowScript: `
379
- return runs.all([
380
- { key: "api", agent: "reviewer", task: "Review API" },
381
- { key: "ui", agent: "reviewer", task: "Review UI" }
382
- ]);
383
- ` }
375
+ // Current shape: this ```js workflow block plus subagent({ workflow: true })
376
+ return runs.all([
377
+ { key: "api", agent: "reviewer", task: "Review API" },
378
+ { key: "ui", agent: "reviewer", task: "Review UI" }
379
+ ]);
384
380
  ```
385
381
 
386
- For long task text with Markdown fences or shell blocks, use quoted lines instead of a raw template literal:
382
+ For long task text with Markdown fences or shell blocks, use quoted lines instead of a raw template literal. In a reply block, a line containing only ```` ``` ```` would end the block:
387
383
 
388
384
  ````js
389
385
  const task = [
@@ -401,7 +397,7 @@ A plain workflow creates one enclosing mission by default. Its children do not c
401
397
 
402
398
  Use stable child keys and keep process logic in ordinary JavaScript. `runs.run` launches one child, `runs.all` launches independent children together, and later steps can use each completed child's `output`. Put long task text in arrays joined with `"\n"` so Markdown fences do not conflict with the script string.
403
399
 
404
- For a process you run often, save the task as a prompt template under `.pi/prompts/` or `~/.pi/agent/prompts/` and launch it with `/prompt-workflow`. The adapter compiles prompt steps into `workflowScript`, so templates describe the work instead of embedding raw `subagent` tool-call JSON. You can ask the parent agent to create or update these prompt files from a process described in natural language.
400
+ For a process you run often, save the task as a prompt template under `.pi/prompts/` or `~/.pi/agent/prompts/` and launch it with `/prompt-workflow`. The adapter compiles prompt steps into a workflow script, so templates describe the work instead of embedding raw `subagent` tool calls. You can ask the parent agent to create or update these prompt files from a process described in natural language.
405
401
 
406
402
  ```md
407
403
  ---
@@ -426,6 +422,8 @@ For watched same-repo workflows, pass `async:false` only when the parent must bl
426
422
 
427
423
  Synchronous workflows publish trace and `emit(...)` updates through the tool update callback regardless of `chatProgress`, including RPC/headless and cross-repository runs. These updates include `details.workflow` and `details.workflowChildren`; `chatProgress: "off"` disables the live card, not transport progress. Running foreground child rows additionally expose bounded `activity` (current tool, timing, and counters), plus resolved model/thinking when available, keyed by `childId`. Activity-only updates coalesce over 100 ms; lifecycle updates remain immediate. Activity clears when children settle, and is not persisted for async workflows. Tool names are limited to 256 UTF-8 bytes and each activity object is below 2 KiB (including JSON escaping); arguments and transcripts are not forwarded.
428
424
 
425
+ The workflow result text keeps the Return, Emitted, and Console sections, and a failed workflow's error, under 200 KB and 5000 lines, or under `maxOutput` when set. Each call-trace error is cut to 500 characters. A cut adds a `[TRUNCATED: ... - full output at <path>]` line. The full text goes to the workflow `output` file when one is set, otherwise to `<run>_workflow-result.md` in the run's artifacts directory, outside the `outputs/` tree where children save their reports. That file has the same retention as the other run artifacts: age-based cleanup removes it from temp and session artifact directories, and `artifactDir: "project"` files are kept. The status line, the rest of each trace line, warnings, and output-path mappings are never cut. Async completion notices and `action: "status"` show short previews; a cut preview or async error ends in `…` and names the run's `status.json`, which holds the full `workflow.value`, `workflow.emits`, and `error`.
426
+
429
427
  The legacy `/chain`, `/parallel`, and `/run-chain` commands are not registered.
430
428
 
431
429
  ## Direct commands
@@ -446,11 +444,11 @@ return { api: api.artifactPaths, ui: ui.artifactPaths };
446
444
 
447
445
  Each child uses the existing worktree lifecycle: it branches from clean HEAD, journals ownership before launch, captures a patch and handoff manifest, then removes cleanly captured temporary worktrees and branches. The handoff manifest path remains available in the child's `artifactPaths`; return or emit it when the orchestrator needs to apply or inspect the patches. `runs.ref` stays concise and intentionally omits full paths.
448
446
 
449
- A top-level `{ workflowScript, worktree: true }` makes isolation the default for every workflow child. An individual child can override that default with `worktree: false`. Keep one writer when parallel writes are not intentionally isolated.
447
+ A top-level `{ workflow: true, worktree: true }` makes isolation the default for every workflow child. An individual child can override that default with `worktree: false`. Keep one writer when parallel writes are not intentionally isolated.
450
448
 
451
449
  Before a materialized `runs.run` or `runs.all` group dispatches fresh children, isolated sources must be Git repositories with clean working trees (excluding `.pi/subagents/` runtime state). A rejected group dispatches no children and spends no fan-out slots or child output claims; key-level failure traces can remain. Checks are shared only within that group, are cancellable, and run again at allocation because sources can change. Retained resumes keep their stored contracts. Select the correct cwd or arrange an operator-approved commit/stash; isolation is never dropped automatically.
452
450
 
453
- Use `baseRef` to branch managed worktrees from `HEAD` or a supported named ref such as `refs/heads/release`, `refs/tags/v1`, or `origin/main`. Full 40/64-character commit IDs and revision expressions such as `HEAD~1` are unsupported. For example, `{ workflowScript, worktree: true, baseRef: "refs/heads/release" }` applies the release ref to children unless a child supplies its own `baseRef`. If omitted, the default `HEAD` is resolved at worktree allocation, not when the script is validated or a schedule is created. The source checkout must still be clean, and the ref must resolve to a commit before any worktree is allocated.
451
+ Use `baseRef` to branch managed worktrees from `HEAD` or a supported named ref such as `refs/heads/release`, `refs/tags/v1`, or `origin/main`. Full 40/64-character commit IDs and revision expressions such as `HEAD~1` are unsupported. For example, `{ workflow: true, worktree: true, baseRef: "refs/heads/release" }` applies the release ref to children unless a child supplies its own `baseRef`. If omitted, the default `HEAD` is resolved at worktree allocation, not when the script is validated or a schedule is created. The source checkout must still be clean, and the ref must resolve to a commit before any worktree is allocated.
454
452
 
455
453
  Configure the worktree provider, native path layout, base directory, and setup hook in [configuration.md](configuration.md).
456
454
 
@@ -519,7 +517,7 @@ For A → B → C, C's request belongs to B, not A. B can escalate a separate qu
519
517
 
520
518
  Child-side routine completion handoffs are not expected. If a child appears stalled, needs-attention notices show up in the parent session with useful next actions, such as checking `subagent({ action: "status" })`, interrupting the run, or nudging the child.
521
519
 
522
- If a `workflowScript` child detaches through `contact_supervisor`, the enclosing async workflow stays `paused` until that child exits. Then the extension reconciles it to `complete` or `failed`. Wait on the child until that happens.
520
+ If a workflow script child detaches through `contact_supervisor`, the enclosing async workflow stays `paused` until that child exits. Then the extension reconciles it to `complete` or `failed`. Wait on the child until that happens.
523
521
 
524
522
  If messages do not show up, run `/subagents-doctor`. Advanced users can tune the bridge with `intercomBridge` in [configuration.md](configuration.md).
525
523
 
@@ -567,4 +565,4 @@ Then run it through the native adapter:
567
565
 
568
566
  The adapter delegates to the named subagent, applies `model`, `skill`, `cwd`, and fork/fresh context metadata, and supports runtime overrides such as `--subagent reviewer`, `--fork`, `--fresh`, and `--bg`.
569
567
 
570
- Prompt templates with `chain:` frontmatter are translated into `workflowScript` and launched through `/prompt-workflow`; `/chain-prompts` is no longer registered.
568
+ Prompt templates with `chain:` frontmatter are translated into a workflow script and launched through `/prompt-workflow`; `/chain-prompts` is no longer registered.
@@ -31,12 +31,12 @@
31
31
  "test": "vitest --run"
32
32
  },
33
33
  "peerDependencies": {
34
- "@earendil-works/pi-ai": ">=0.83.0 <1",
35
- "@earendil-works/pi-coding-agent": ">=0.83.0 <1",
36
- "@earendil-works/pi-tui": ">=0.83.0 <1"
34
+ "@earendil-works/pi-ai": ">=1.0.0 <2",
35
+ "@earendil-works/pi-coding-agent": ">=1.0.0 <2",
36
+ "@earendil-works/pi-tui": ">=1.0.0 <2"
37
37
  },
38
38
  "devDependencies": {
39
- "@earendil-works/pi-ai": "0.83.0",
39
+ "@earendil-works/pi-ai": "catalog:",
40
40
  "@earendil-works/pi-coding-agent": "catalog:",
41
41
  "@earendil-works/pi-tui": "catalog:",
42
42
  "@types/node": "catalog:",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xzzpig/pi-subagents",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Pi extension for single-agent delegation and scripted multi-agent workflows",
5
5
  "author": "Nico Bailon",
6
6
  "license": "MIT",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@earendil-works/pi-agent-core": "*",
71
- "@earendil-works/pi-ai": ">=0.86.1",
71
+ "@earendil-works/pi-ai": ">=1.0.0 <2",
72
72
  "@earendil-works/pi-coding-agent": "*",
73
73
  "@earendil-works/pi-tui": "*",
74
74
  "typebox": "*"
@@ -94,13 +94,13 @@
94
94
  "@xzzpig/pi-components": "0.4.0",
95
95
  "acorn": "8.18.0",
96
96
  "jiti": "2.7.0",
97
- "undici": "8.10.0",
97
+ "undici": "8.10.2",
98
98
  "yaml": "2.8.3"
99
99
  },
100
100
  "devDependencies": {
101
- "@earendil-works/pi-agent-core": "0.87.0",
102
- "@earendil-works/pi-ai": "0.87.0",
103
- "@earendil-works/pi-tui": "0.87.0",
101
+ "@earendil-works/pi-agent-core": "1.0.0",
102
+ "@earendil-works/pi-ai": "1.0.0",
103
+ "@earendil-works/pi-tui": "1.0.0",
104
104
  "@oxlint/plugins": "1.80.0",
105
105
  "@types/node": "24.13.3",
106
106
  "oxlint": "1.80.0",
@@ -8,7 +8,7 @@ Use the `subagent` tool. Keep the parent session as the loop controller and fina
8
8
 
9
9
  Default to a maximum of 3 review rounds unless I specify a different cap. Count a review round each time fresh-context reviewers inspect the current diff after a worker pass. Stop early when reviewers find no P0 findings, no P1 fixes worth doing now, and no approved P2 notes that should be handled in this loop.
10
10
 
11
- If the invocation includes an implementation request, first launch one async `worker` to implement the approved scope. If the current diff is already the target, start with review. The sequence can be launched up front with `workflowScript` when it is already clear, or continued as follow-up single-agent runs after each async completion. For an initial workflowScript, pass `async: true` so the main chat is unblocked; do not set `clarify: true` unless I explicitly want the foreground clarify UI. Use only one writer against the active worktree at a time unless I explicitly ask for isolated worktrees.
11
+ If the invocation includes an implementation request, first launch one async `worker` to implement the approved scope. If the current diff is already the target, start with review. The sequence can be launched up front as a workflow script (a ```` ```js workflow ```` block plus `subagent({ workflow: true })`) when it is already clear, or continued as follow-up single-agent runs after each async completion. For an initial workflow script, pass `async: true` so the main chat is unblocked; do not set `clarify: true` unless I explicitly want the foreground clarify UI. Use only one writer against the active worktree at a time unless I explicitly ask for isolated worktrees.
12
12
 
13
13
  As a conservative orchestration policy, do not set a hard `toolBudget` or tight `usageBudget` on implementation or fix workers. A default tool budget blocks read/search tools rather than mutation tools, and reported usage has no reservation model, so count or usage limits still do not measure delivery safety. Give each writer a narrow delivery slice and an outer elapsed deadline with enough margin. Before that deadline, request a checkpoint after the current tool returns with changed files, build/test state, remaining work, and commit or PR state. An elapsed timeout is not a mutation-safe boundary and must not be the checkpoint trigger.
14
14
 
@@ -32,7 +32,7 @@ Pass 1 is independent reports. Pass 2 is one cross-exam. Run Pass 3 only when `-
32
32
 
33
33
  1. Write the council brief: question, scope, non-goals, evidence targets, roster, known advisor context modes, and pass cap.
34
34
  2. Tell the user the roster, context modes, and pass cap.
35
- 3. Launch one async `workflowScript` with `runs.all` for Pass 1. Use stable keys, `phase: "Council pass 1"`, concise labels, and `output: false` unless separate artifacts are useful. Set `context` only when the profile context is known or a fallback rule requires it.
35
+ 3. Launch one async workflow script (a ```` ```js workflow ```` block plus `subagent({ workflow: true, async: true })`) with `runs.all` for Pass 1. Use stable keys, `phase: "Council pass 1"`, concise labels, and `output: false` unless separate artifacts are useful. Set `context` only when the profile context is known or a fallback rule requires it.
36
36
  4. Return one aggregate Pass 1 receipt. On completion, tell the user completion count, agreement count, dispute count, and whether Pass 2 is needed.
37
37
  5. Synthesize the claim matrix in the parent: agreements, disputed claims, missing proof, owner decisions, and at most five material relay claims per advisor.
38
38
  6. For Pass 2, tell the user which claims are relayed and why they matter. Resume each advisor with a curated challenge packet. A resume needs a retained run id and task; it excludes `agent` and rejects `gate`. Record each new run id; Pass 3 resumes those latest ids with new stable keys.