@timmyjl12/pi-subagents 0.20.0 → 0.21.1
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 +862 -827
- package/README.md +1125 -1080
- package/dist/active-agents-prompt.d.ts +31 -9
- package/dist/active-agents-prompt.js +73 -9
- package/dist/agent-color.js +9 -1
- package/dist/agent-file-toggle.d.ts +1 -1
- package/dist/agent-manager.d.ts +405 -18
- package/dist/agent-manager.js +1661 -131
- package/dist/agent-runner.d.ts +45 -6
- package/dist/agent-runner.js +109 -18
- package/dist/agent-types.d.ts +30 -7
- package/dist/agent-types.js +38 -9
- package/dist/awaited-result.d.ts +37 -0
- package/dist/awaited-result.js +150 -0
- package/dist/child-session-shutdown.d.ts +19 -1
- package/dist/child-session-shutdown.js +60 -11
- package/dist/cleanup-plans.d.ts +10 -0
- package/dist/cleanup-plans.js +112 -0
- package/dist/cross-extension-rpc.d.ts +8 -1
- package/dist/cross-extension-rpc.js +59 -5
- package/dist/custom-agents.d.ts +34 -9
- package/dist/custom-agents.js +308 -111
- package/dist/default-agents.d.ts +1 -1
- package/dist/env.d.ts +1 -1
- package/dist/error-log.d.ts +6 -0
- package/dist/error-log.js +8 -0
- package/dist/force-main-model.d.ts +21 -0
- package/dist/force-main-model.js +28 -0
- package/dist/goal-bridge.d.ts +155 -0
- package/dist/goal-bridge.js +305 -0
- package/dist/group-join.d.ts +5 -1
- package/dist/group-join.js +52 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2827 -333
- package/dist/invocation-config.d.ts +30 -3
- package/dist/invocation-config.js +30 -1
- package/dist/memory.d.ts +1 -1
- package/dist/mention-clone.d.ts +1 -1
- package/dist/model-scope.d.ts +1 -1
- package/dist/nested-tools.d.ts +22 -1
- package/dist/nested-tools.js +120 -26
- package/dist/output-file.d.ts +15 -4
- package/dist/output-file.js +146 -43
- package/dist/prompts.d.ts +1 -1
- package/dist/recovery.d.ts +1 -1
- package/dist/report-cleanup.d.ts +204 -0
- package/dist/report-cleanup.js +1632 -0
- package/dist/report-store.d.ts +738 -0
- package/dist/report-store.js +3616 -0
- package/dist/schedule-store.d.ts +14 -6
- package/dist/schedule-store.js +88 -58
- package/dist/schedule.d.ts +20 -8
- package/dist/schedule.js +135 -74
- package/dist/settings.d.ts +39 -11
- package/dist/settings.js +22 -5
- package/dist/status-note.d.ts +1 -1
- package/dist/structured-output.d.ts +1 -1
- package/dist/types.d.ts +32 -3
- package/dist/ui/agent-mention.d.ts +2 -2
- package/dist/ui/agent-widget.d.ts +82 -13
- package/dist/ui/agent-widget.js +155 -37
- package/dist/ui/cleanup-preview.d.ts +59 -0
- package/dist/ui/cleanup-preview.js +466 -0
- package/dist/ui/conversation-viewer.d.ts +4 -4
- package/dist/ui/conversation-viewer.js +10 -6
- package/dist/ui/fleet-list.d.ts +3 -3
- package/dist/ui/fleet-list.js +3 -3
- package/dist/ui/fleet-overlay.d.ts +37 -6
- package/dist/ui/fleet-overlay.js +214 -18
- package/dist/ui/hub-feed.d.ts +52 -0
- package/dist/ui/hub-feed.js +148 -0
- package/dist/ui/native-transcript.js +5 -1
- package/dist/ui/schedule-menu.d.ts +1 -1
- package/dist/ui/schedule-menu.js +1 -1
- package/dist/ui/workflow-card.d.ts +4 -4
- package/dist/ui/workflow-dialog.d.ts +4 -4
- package/dist/ui/workflow-dialog.js +8 -3
- package/dist/ui/workflow-menu.d.ts +2 -2
- package/dist/usage.d.ts +12 -0
- package/dist/usage.js +28 -1
- package/dist/workflow/entry.d.ts +3 -3
- package/dist/workflow/host.d.ts +7 -4
- package/dist/workflow/host.js +162 -48
- package/dist/workflow/journal.d.ts +23 -7
- package/dist/workflow/journal.js +80 -23
- package/dist/workflow/progress.d.ts +1 -1
- package/dist/workflow/runtime.d.ts +45 -6
- package/dist/workflow/runtime.js +105 -16
- package/dist/workflow/task.d.ts +13 -4
- package/dist/workflow/task.js +7 -1
- package/dist/workflow/tool-description.d.ts +7 -2
- package/dist/workflow/tool-description.js +10 -5
- package/docs/{FORK.md → DEVELOPMENT.md} +4 -4
- package/docs/artifacts.md +93 -0
- package/docs/rpc.md +252 -189
- package/docs/runtime-performance.md +53 -0
- package/docs/workflows.md +48 -18
- package/examples/agent-tool-description.md +2 -2
- package/examples/workflows/review-panel.js +6 -3
- package/package.json +5 -5
- package/src/active-agents-prompt.ts +115 -39
- package/src/agent-color.ts +10 -2
- package/src/agent-file-toggle.ts +2 -2
- package/src/agent-manager.ts +3312 -1601
- package/src/agent-runner.ts +164 -36
- package/src/agent-types.ts +56 -11
- package/src/awaited-result.ts +187 -0
- package/src/child-session-shutdown.ts +114 -46
- package/src/cleanup-plans.ts +112 -0
- package/src/cross-extension-rpc.ts +68 -9
- package/src/custom-agents.ts +384 -112
- package/src/default-agents.ts +1 -1
- package/src/enabled-models.ts +1 -1
- package/src/env.ts +1 -1
- package/src/error-log.ts +10 -1
- package/src/force-main-model.ts +29 -0
- package/src/goal-bridge.ts +468 -0
- package/src/group-join.ts +56 -9
- package/src/index.ts +2987 -349
- package/src/invocation-config.ts +50 -4
- package/src/memory.ts +1 -1
- package/src/mention-clone.ts +3 -3
- package/src/model-scope.ts +1 -1
- package/src/nested-tools.ts +164 -33
- package/src/output-file.ts +168 -46
- package/src/prompts.ts +1 -1
- package/src/recovery.ts +2 -2
- package/src/report-cleanup.ts +2044 -0
- package/src/report-store.ts +4133 -0
- package/src/schedule-store.ts +244 -201
- package/src/schedule.ts +144 -80
- package/src/settings.ts +61 -16
- package/src/skill-loader.ts +1 -1
- package/src/standalone-fallback.ts +2 -2
- package/src/status-note.ts +1 -1
- package/src/structured-output.ts +1 -1
- package/src/types.ts +33 -3
- package/src/ui/agent-mention.ts +3 -3
- package/src/ui/agent-widget.ts +179 -45
- package/src/ui/cleanup-preview.ts +518 -0
- package/src/ui/conversation-viewer.ts +19 -15
- package/src/ui/fleet-list.ts +7 -7
- package/src/ui/fleet-overlay.ts +1048 -847
- package/src/ui/hub-feed.ts +179 -0
- package/src/ui/native-transcript.ts +7 -3
- package/src/ui/schedule-menu.ts +4 -4
- package/src/ui/workflow-card.ts +4 -4
- package/src/ui/workflow-dialog.ts +10 -6
- package/src/ui/workflow-menu.ts +4 -4
- package/src/usage.ts +53 -3
- package/src/workflow/collisions.ts +1 -1
- package/src/workflow/entry.ts +3 -3
- package/src/workflow/host.ts +174 -54
- package/src/workflow/journal.ts +80 -23
- package/src/workflow/progress.ts +1 -1
- package/src/workflow/runtime.ts +146 -23
- package/src/workflow/saved.ts +3 -3
- package/src/workflow/task.ts +18 -7
- package/src/workflow/tool-description.ts +10 -5
package/docs/workflows.md
CHANGED
|
@@ -29,23 +29,36 @@ There is no `/workflows` command. The tool is model-invoked, so you get a workfl
|
|
|
29
29
|
|
|
30
30
|
You do not have to say "workflow" — the model picks the tool — but saying it removes the ambiguity when the task is borderline.
|
|
31
31
|
|
|
32
|
+
#### Choosing the role
|
|
33
|
+
|
|
34
|
+
Every `agent()` runs an agent type. The run default is the tool call's `agentType`, else `workflowDefaultAgentType` (default `task`); `agent({agentType: "..."})` overrides it for one call. `task` is user-defined, not a built-in: define `.pi/agents/task.md` with a model pin, or set `workflowDefaultAgentType` to an available pinned role. If the default role cannot be resolved, the run refuses to spawn instead of using `fallbackSubagent`. The same protection applies to explicitly selected `task`/`explore`; explicit other role requests retain the configured fallback policy.
|
|
35
|
+
|
|
36
|
+
Ask for a role in words and the model passes it as `agentType`: *"use explore for this workflow"* becomes `SubagentWorkflow({agentType: "explore", ...})`, and *"use principal_engineer for the architecture decision"* becomes `agent("...", {agentType: "principal_engineer"})`. The prompt does not enforce a role by itself — the `agentType` value does. Other explicitly named valid roles remain supported.
|
|
37
|
+
|
|
38
|
+
Premium roles are explicit-only. A global `principal_engineer` role is a **user-defined example, not shipped with this package**: pin `openai-codex/gpt-6.1-sol` with `thinking: xhigh`, and select it only when asked, with `{agentType: "principal_engineer"}`. Do not make it a workflow default unless the user asks for it.
|
|
39
|
+
|
|
40
|
+
A role's own `model:` and `thinking:` pins outrank the `model` and `effort` options in the script. `task`/`explore` need a model pin or explicit `model`, even when selected explicitly; they never implicitly inherit the parent. Other unpinned roles may use the main model when selected explicitly — `agent({agentType})` or the run's `agentType`. `general-purpose` is the selectable parent twin; choosing it as a configured default deliberately uses the main model. An unavailable pin fails the workflow — built-in pins included. `/subagents off` forces the main session's model for every child.
|
|
41
|
+
|
|
32
42
|
### 2. Read what came back
|
|
33
43
|
|
|
34
|
-
The tool returns immediately. The run continues in the background and notifies you when it is done.
|
|
44
|
+
The tool returns immediately. The run continues in the background and notifies you when it is done. That completion notification carries the script's complete final outcome — the value checked at the JSON boundary, with no character cap — so a summary your script returns reaches the model whole. The card and inspector stay compact views of the run, and nothing extra is persisted beyond the existing journal and transcript card.
|
|
35
45
|
|
|
36
46
|
```text
|
|
37
47
|
Workflow "auth-audit" started in the background.
|
|
38
48
|
Task ID: wf_9f3ab21c04de
|
|
49
|
+
Default agent role: task
|
|
39
50
|
Script: /var/folders/xy/…/pi-subagents-501/Users-me-project/<session>/tasks/wf_9f3ab21c04de.workflow.js
|
|
40
51
|
|
|
41
52
|
You will be notified when it finishes — do NOT poll or sleep waiting for it.
|
|
42
53
|
To iterate, edit the script file and call SubagentWorkflow again with scriptPath.
|
|
43
54
|
```
|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
Four things in there matter.
|
|
46
57
|
|
|
47
58
|
**`Task ID`** is what `resumeFromRunId` takes, and what `/agents → Workflows` lists the run under.
|
|
48
59
|
|
|
60
|
+
**`Default agent role`** is the role this run's `agent()` calls use when they name none. It is frozen for the run: a resume reuses it unless the resume call supplies `agentType`.
|
|
61
|
+
|
|
49
62
|
**`Script`** is the file to edit. **It is a scratch file in your system temp directory, not in your project** — it will not survive a reboot or a temp sweep. If the workflow turns out to be worth keeping, copy it somewhere durable; see [Save it](#5-save-it). The path means something slightly different depending on how the run was started: for an inline script it is a copy the tool just wrote, and for a run started from `scriptPath` or `name` it is *your own file*, reported straight back.
|
|
50
63
|
|
|
51
64
|
**The last line is addressed to the model, not to you.** You do not call `SubagentWorkflow` yourself — you tell the model to re-run the workflow at that path.
|
|
@@ -70,7 +83,7 @@ A **card in the transcript**, updating as the run goes:
|
|
|
70
83
|
|
|
71
84
|
A **`workflow` row in FleetView**, above the agents, carrying its agent counts where a description would go. `⏎` on it opens the inspector rather than a conversation overlay.
|
|
72
85
|
|
|
73
|
-
Each row names the model the child *actually* ran on — read back from its session once pi has resolved its defaults, not the string the script asked for — so a fuzzy `model: "haiku"` reads as the model it resolved to, and an `agent()` that named no model
|
|
86
|
+
Each row names the model the child *actually* ran on — read back from its session once pi has resolved its defaults, not the string the script asked for — so a fuzzy `model: "haiku"` reads as the model it resolved to, and an `agent()` that named no model shows the model its role pinned.
|
|
74
87
|
|
|
75
88
|
The **inspector**, at `/agents → Workflows` — two panes, two levels: phases on the left, that phase's agents on the right, and `⏎` to descend into one agent's prompt, activity and outcome. The detail pane has room for the canonical `provider/model-id` and the thinking level, including a level pi clamped (`thinking: low (asked max)`). The full key table is in [the README](../README.md#commands); the four that change the run rather than the view are:
|
|
76
89
|
|
|
@@ -97,11 +110,15 @@ A run's own agents are not listed separately in the fleet list, the widget, the
|
|
|
97
110
|
|
|
98
111
|
Open the path from the `Script:` line, change it, and ask the model to run it again with `scriptPath`. That is the whole loop, and it is why the script is written to disk at all: iterating means editing a file, not asking the model to re-emit source it already produced.
|
|
99
112
|
|
|
113
|
+
The edit and the re-run are separate steps. Wait for the file edit to complete before calling `SubagentWorkflow({scriptPath})`; never put both in the same parallel tool batch. The runtime cannot order unrelated file tools, and there is no hash or version check, so the run can otherwise read the old file or a partial write.
|
|
114
|
+
|
|
115
|
+
A resume keeps the original run's default role and `args` unless the new call explicitly supplies `agentType` or `args`.
|
|
116
|
+
|
|
100
117
|
Re-running normally re-pays for every agent. `resumeFromRunId` avoids that:
|
|
101
118
|
|
|
102
119
|
> Its unchanged leading `agent()` calls return their recorded results instantly; the first changed or failed call, and everything after it, runs live.
|
|
103
120
|
|
|
104
|
-
Every run journals each settled `agent()` call beside its script as `<run id>.workflow.jsonl`, and the resume replays the **unchanged prefix** of that journal. It is a prefix and not a lookup table on purpose: a later call that still matches came from a run whose earlier stages no longer exist, so its recorded answer was produced downstream of work that has changed.
|
|
121
|
+
Every run journals each settled `agent()` call beside its script as `<run id>.workflow.jsonl`, and the resume replays the **unchanged prefix** of that journal. New entries match the effective role and whether it was selected explicitly (per-call or run-level). Switching between explicit and implicit selection ends their cached prefix, even if the role name stays the same. Matching legacy entries still replay without a new model call: their original role-selection provenance cannot be revalidated, but fresh calls always use the current safety checks. It is a prefix and not a lookup table on purpose: a later call that still matches came from a run whose earlier stages no longer exist, so its recorded answer was produced downstream of work that has changed. A run reports completion only after the records it accepted are flushed, so an immediate resume sees every settled call; writes stay best-effort, and one that fails costs a future replay rather than the run.
|
|
105
122
|
|
|
106
123
|
Four things it will not do:
|
|
107
124
|
|
|
@@ -141,7 +158,7 @@ const root = args?.root ?? 'src/'
|
|
|
141
158
|
const listing = await agent(`List every file under ${root}. One path per line, nothing else.`)
|
|
142
159
|
```
|
|
143
160
|
|
|
144
|
-
`args` is whatever was passed to the tool, verbatim, and it must be JSON-shaped. Now *"run the audit workflow against src/api"* and *"…against src/admin"* are the same workflow.
|
|
161
|
+
`args` is whatever was passed to the tool, verbatim, and it must be JSON-shaped. Any JSON value is valid — object, array, string, number, boolean, null — and nothing is coerced or parsed. If you want an object in the script, pass an object: `args: {probes: [...]}`. `args: "{\"probes\":[...]}"` arrives as a string, so `args.probes` and `args.filter` fail; the error names the script line that used it. Omit `args` for `undefined`. Now *"run the audit workflow against src/api"* and *"…against src/admin"* are the same workflow.
|
|
145
162
|
|
|
146
163
|
## A worked example
|
|
147
164
|
|
|
@@ -222,7 +239,8 @@ export const meta = {
|
|
|
222
239
|
| `script` | string | Inline source. Must begin with `export const meta = { name, description }` |
|
|
223
240
|
| `scriptPath` | string | A script file, absolute or project-relative. **Takes precedence over `script`** — this is how an edited workflow is re-run |
|
|
224
241
|
| `name` | string | A saved workflow — `<name>.js` in one of the three directories above. Lowest precedence |
|
|
225
|
-
| `
|
|
242
|
+
| `agentType` | string | Default role for this run's `agent()` calls. Falls back to `workflowDefaultAgentType` (default `task`); a per-call `agent({agentType})` wins. `task` must be user-defined; an unknown or disabled role is refused, not replaced with `general-purpose` |
|
|
243
|
+
| `args` | any | Handed to the script as the `args` global, verbatim. Any JSON value; pass objects/arrays as actual JSON values, not stringified ones |
|
|
226
244
|
| `resumeFromRunId` | string | Replay an earlier run in this session. Matches `^wf_[a-z0-9-]{6,}$` |
|
|
227
245
|
| `title` / `description` | string | Accepted and ignored — for Claude Code parity, so a ported call does not fail. A workflow is named by its `meta` block |
|
|
228
246
|
|
|
@@ -238,15 +256,15 @@ Spawns one subagent and resolves to its final text — or, with `schema`, to a v
|
|
|
238
256
|
|---|---|---|
|
|
239
257
|
| `label` | string | Display name in the progress tree. Also the handle `resume` addresses |
|
|
240
258
|
| `phase` | string | Put this agent in a named group, overriding the ambient `phase()`. **Use it inside `pipeline`/`parallel` stages**, where the ambient phase races |
|
|
241
|
-
| `agentType` | string | Which
|
|
242
|
-
| `model` | string | `provider/modelId`, or fuzzy like `haiku` |
|
|
243
|
-
| `effort` | string | `minimal`, `low`, `medium`, `high`, `xhigh`, `max`.
|
|
259
|
+
| `agentType` | string | Which role to use. Defaults to the run's `agentType`, then `workflowDefaultAgentType` (default `task`); per-call wins. The role must exist and be enabled; `task` is user-defined. A role's pins outrank `model`/`effort` |
|
|
260
|
+
| `model` | string | Exact `provider/modelId`, or fuzzy like `haiku`. A role's `model:` pin wins. Required for unpinned task/explore and default-derived roles. Other explicitly selected unpinned roles may use the parent; general-purpose is the selectable twin. `/subagents off` forces the main model |
|
|
261
|
+
| `effort` | string | `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. A role's `thinking:` pin wins; omitted uses that pin, or the run's normal thinking default when unpinned |
|
|
244
262
|
| `isolation` | `"worktree"` | Run in a throwaway git worktree. Only when agents write files in parallel and would collide — it costs setup time and disk per agent |
|
|
245
263
|
| `gate` | string | A shell command run after the agent finishes; a non-zero exit fails the agent and its output becomes the error |
|
|
246
264
|
| `resume` | string | Continue the child that ran under that label instead of starting fresh |
|
|
247
265
|
| `schema` | object | A JSON Schema with an object root. Resolves to the validated object instead of text |
|
|
248
266
|
|
|
249
|
-
Any other key is rejected **by name** at the call.
|
|
267
|
+
Any other key is rejected **by name** at the call. Option *values* are resolved when the child spawns: an `agentType` that names no enabled role is refused, never silently replaced with `general-purpose`. Explicit requests for non-task/explore roles may use the configured `fallbackSubagent`. Missing workflow defaults and task/explore roles are configuration errors and never redirect through that generic fallback.
|
|
250
268
|
|
|
251
269
|
Combination rules: `resume` cannot be combined with `agentType`, `model`, `effort`, `isolation`, `gate` or `schema` — a resumed child keeps the agent type, model and tree it was started with, and its session predates the `StructuredOutput` tool.
|
|
252
270
|
|
|
@@ -265,7 +283,7 @@ Prefer `pipeline` unless a stage genuinely needs every prior result *together*
|
|
|
265
283
|
|
|
266
284
|
### `workflow(nameOrRef, args?)`
|
|
267
285
|
|
|
268
|
-
Runs a saved workflow inline and returns its value. Pass a name, or `{ scriptPath }`. `args` becomes the child's `args` global.
|
|
286
|
+
Runs a saved workflow inline and returns its value. Pass a name, or `{ scriptPath }`. `args` becomes the child's `args` global, with the same JSON-shape rules as the tool's `args`. The child inherits this run's default role (`agentType`), so nested `agent()` calls use it too.
|
|
269
287
|
|
|
270
288
|
The child runs in the *same* worker and vm context under its own globals, so it shares this run's concurrency cap, agent counter, abort signal, journal and budget by construction — its agents are simply this run's agents, controllable from the same inspector. What it does not share is phase state: the child's phases render as their own `▸ <name>` group.
|
|
271
289
|
|
|
@@ -275,7 +293,7 @@ The child runs in the *same* worker and vm context under its own globals, so it
|
|
|
275
293
|
|
|
276
294
|
- **`phase(title)`** — start a new progress group; subsequent `agent()` calls are grouped under it. Inside `pipeline`/`parallel` stages use the `phase` *option* instead, since the ambient phase races.
|
|
277
295
|
- **`log(message)`** — a progress line under the tree, for you to read.
|
|
278
|
-
- **`args`** — whatever was passed as the tool's `args`, verbatim; `undefined` if
|
|
296
|
+
- **`args`** — whatever was passed as the tool's `args`, verbatim; any JSON value, `undefined` if omitted. A string is not decoded into an object.
|
|
279
297
|
- **`budget`** — `{ total, spent(), remaining() }`. **`total` is always `null` here**: it comes from a token-target directive pi does not have. That is deliberate rather than broken — Claude Code scripts guard on it (`while (budget.total && budget.remaining() > 50_000)`), and those guards correctly do not fire instead of throwing on a missing global. `remaining()` is `Infinity` with no target. `spent()` is real, and counts output tokens this run's agents have used.
|
|
280
298
|
|
|
281
299
|
### Where files live
|
|
@@ -286,7 +304,7 @@ The child runs in the *same* worker and vm context under its own globals, so it
|
|
|
286
304
|
| The resume journal | the same directory, `<run id>.workflow.jsonl` |
|
|
287
305
|
| Saved workflows | `.pi/workflows/` → `.agents/workflows/` → `<agent dir>/workflows/`, first hit wins |
|
|
288
306
|
|
|
289
|
-
The first two are scratch: temp storage, wiped by a reboot or a temp sweep. Only the third is durable, and copying a script there is a manual step.
|
|
307
|
+
The first two are scratch: temp storage, wiped by a reboot or a temp sweep. Only the third is durable, and copying a script there is a manual step. `/subagents cleanup session` or `global` can also remove eligible generated copies and journals after preview/confirmation, including a run with zero agents. Active runs and external/saved sources stay protected; removing a journal deliberately removes its replay data. See [artifact cleanup](artifacts.md).
|
|
290
308
|
|
|
291
309
|
### Limits and caps
|
|
292
310
|
|
|
@@ -300,7 +318,7 @@ The first two are scratch: temp storage, wiped by a reboot or a temp sweep. Only
|
|
|
300
318
|
|
|
301
319
|
These are three different things and are easy to conflate: 1000 is a budget for the whole run, the concurrency figure is how many run *simultaneously*, and 4096 is per call rather than per run. Excess items queue rather than melting the machine.
|
|
302
320
|
|
|
303
|
-
Above 25 scheduled agents, or 1.5M tokens actual or projected, the card adds `⚠ Large workflow · /agents → Workflows to stop`.
|
|
321
|
+
Above 25 scheduled agents, or 1.5M tokens actual or projected, the card adds `⚠ Large workflow · /agents → Workflows to stop`. That line is advisory: there is no separate approval prompt and no per-run token budget. The caps above are the only hard limits.
|
|
304
322
|
|
|
305
323
|
A run's concurrency limit is its own, independent of the session's `maxConcurrent` and `maxConcurrentForeground` pools — its agents do not enter either.
|
|
306
324
|
|
|
@@ -308,6 +326,8 @@ A run's concurrency limit is its own, independent of the session's `maxConcurren
|
|
|
308
326
|
|
|
309
327
|
`workflowsEnabled` is **on**; leaving it unset means *auto*, which is on unless another extension already offers a `Workflow` or `SubagentWorkflow` tool, in which case this one stands down for the session. Setting it explicitly pins it. See [Persistent settings](../README.md#persistent-settings).
|
|
310
328
|
|
|
329
|
+
`workflowDefaultAgentType` (default `task`) sets the role a run uses when the tool call omits `agentType`. `task` is not built in: define it with a model pin, or choose an available pinned role. The setting is read when a run starts; a resume keeps its recorded default unless the call replaces it. Set it in `subagents.json` (global or project) or via `/agents → Settings → Workflow default agent`; a stored name is kept even while that role is unavailable.
|
|
330
|
+
|
|
311
331
|
`pi --subagents-workflow-file=<path>` runs a workflow at startup, including headless under `pi -p`. Use the `=` form — the bare `--flag value` spelling swallows the next argument. See [CLI flags](../README.md#cli-flags).
|
|
312
332
|
|
|
313
333
|
## Recipes
|
|
@@ -373,8 +393,17 @@ The script called `Date.now()`, `new Date()` or `Math.random()`. A script that v
|
|
|
373
393
|
**`agent() opts.<key> is not a recognised option.`**
|
|
374
394
|
A typo, or an option from a different tool. The supported set is `label`, `phase`, `model`, `agentType`, `isolation`, `gate`, `resume`, `effort`, `schema`.
|
|
375
395
|
|
|
376
|
-
|
|
377
|
-
|
|
396
|
+
**`agentType` names no enabled role / the run will not start.**
|
|
397
|
+
Roles are strict. `task` is user-defined, so define `.pi/agents/task.md` with a model pin or set `workflowDefaultAgentType` to an available pinned role. Missing defaults and task/explore roles are refused, even with a generic fallback configured. Only explicitly selected other role requests can use `fallbackSubagent`. Role names match case-insensitively, and a disabled agent does not count. Naming a role in the prompt does not enforce it — the model must pass `agentType`.
|
|
398
|
+
|
|
399
|
+
**The run failed because a role has no model pin.**
|
|
400
|
+
`task`/`explore` are refused without a pin or explicit `model`, even when selected by name. Other default-derived unpinned roles are also refused; explicitly selecting another unpinned role allows parent inheritance. Select `general-purpose` when you deliberately want the main-model twin. A role pin always wins over `model`; an unavailable pin fails the workflow. `/subagents off` forces the main model.
|
|
401
|
+
|
|
402
|
+
**The script saw `args` as a string.**
|
|
403
|
+
Pass actual JSON: `args: {probes:[...]}`, not `args: '{"probes":[...]}'`. Values are not parsed or coerced. Top-level `args` accepts any JSON value, including scalars.
|
|
404
|
+
|
|
405
|
+
**`scriptPath` ran the old script, or a parse error came from a half-written file.**
|
|
406
|
+
Make the edit one completed tool call, then call `SubagentWorkflow({scriptPath})` in a later step. Never put the edit and the workflow call in the same parallel batch: file tools are not ordered relative to this tool, and there is no hash check.
|
|
378
407
|
|
|
379
408
|
**`agent()` returned `null`.**
|
|
380
409
|
The agent failed terminally, or you skipped it with `s` in the inspector. These are indistinguishable to the script. With `schema`, it also covers a child that never produced a payload matching the schema.
|
|
@@ -418,20 +447,21 @@ Different:
|
|
|
418
447
|
- The tool is **`SubagentWorkflow`**, not `Workflow` — pi's tool registry is flat across extensions, and the winner of a name clash also overwrites the loser's description.
|
|
419
448
|
- **`budget.total` is always `null`**, because pi has no token-target directive. Claude Code's `budget.total`-guarded patterns therefore run unchanged, just without firing.
|
|
420
449
|
- **`schema` is pressured, not forced** — see the troubleshooting entry above.
|
|
450
|
+
- **Role defaults and model pins are stricter.** A run uses `task`/`workflowDefaultAgentType` (not a built-in general-purpose default), each role must resolve, and a default-reached unpinned role is refused (pin it or pass `model`); selecting another unpinned role explicitly permits the main model, while task/explore still require a pin or explicit model. Claude Code's workflow subagent is built in.
|
|
421
451
|
- If both extensions are loaded, this one **stands down** rather than offering the model two orchestrators.
|
|
422
452
|
|
|
423
453
|
Additions on this side: `gate`, `resume`, `effort`, journal-backed `resumeFromRunId`, and the un-awaited-`agent()` check. All are optional, which is what keeps a Claude Code script portable.
|
|
424
454
|
|
|
425
455
|
## Examples
|
|
426
456
|
|
|
427
|
-
Every file below is executed by `test/workflow-examples.test.ts` against a stub host on each CI run, so none of them can silently rot.
|
|
457
|
+
Every file below is executed by `test/workflow-examples.test.ts` against a stub host on each CI run, so none of them can silently rot. The stub does not model your role registry: before running one in a session, define `task` with a model pin (or set `workflowDefaultAgentType`), and give any default-reached unpinned role in the example an explicit `model`.
|
|
428
458
|
|
|
429
459
|
| File | Demonstrates | Runs as-is? |
|
|
430
460
|
|---|---|---|
|
|
431
461
|
| [`fan-out-audit.js`](../examples/workflows/fan-out-audit.js) | Runtime fan-out, `pipeline`, `label`, per-stage `phase` | Yes — takes `args.root` |
|
|
432
462
|
| [`structured-findings.js`](../examples/workflows/structured-findings.js) | `schema` on both stages, objects instead of prose | Yes |
|
|
433
463
|
| [`gated-fix.js`](../examples/workflows/gated-fix.js) | `gate`, `isolation: "worktree"`, `resume` retry loop | Needs a real test command |
|
|
434
|
-
| [`review-panel.js`](../examples/workflows/review-panel.js) | An earned `parallel` barrier, `effort` tiering, `model` |
|
|
464
|
+
| [`review-panel.js`](../examples/workflows/review-panel.js) | An earned `parallel` barrier, `effort` tiering, `model` | Requires the selected `reviewModel`/`judgeModel` (default `haiku`/`sonnet`) to be available; both are explicit |
|
|
435
465
|
| [`compose.js`](../examples/workflows/compose.js) | `workflow()` nesting and `args` plumbing | Needs `lib/count-child.js` saved |
|
|
436
466
|
|
|
437
467
|
Copy one into `.pi/workflows/` to make it yours.
|
|
@@ -17,8 +17,8 @@ If the target is already known, use a direct tool — `read` for a known path, `
|
|
|
17
17
|
- When you launch multiple agents for independent work, send them in a single message with multiple tool uses so they run concurrently. If the user specifies that they want you to run agents "in parallel", you MUST send a single message with multiple Agent tool use content blocks.
|
|
18
18
|
- When the agent is done, it returns a single message back to you. The result is not visible to the user — to show the user, send a text message with a concise summary.
|
|
19
19
|
- Trust but verify: an agent's summary describes what it intended to do, not necessarily what it did. When an agent writes or edits code, check the actual changes before reporting the work as done.
|
|
20
|
-
- Agents run in the background by default. When an agent runs in the background, you will be automatically notified when it completes — do NOT sleep, poll, or proactively check on its progress. Continue with other work or respond to the user instead.
|
|
21
|
-
- **Foreground vs background**: Pass `run_in_background: false` only when your very next action depends on the agent's result and nothing else could usefully happen while it runs — e.g., a research agent whose finding gates the edit you're about to make. Otherwise let it run in the background (the default) — this includes fire-and-forget work, independent investigations, and anything where the user might hand you something else in the meantime. Wanting the result "next" is not enough on its own.
|
|
20
|
+
- Agents run in the background by default. When an agent runs in the background, you will be automatically notified when it completes, and that notification carries the agent's complete final report — do NOT sleep, poll, or proactively check on its progress. Continue with other work or respond to the user instead.
|
|
21
|
+
- **Foreground vs background**: Pass `run_in_background: false` only when your very next action depends on the agent's result and nothing else could usefully happen while it runs — e.g., a research agent whose finding gates the edit you're about to make. Otherwise let it run in the background (the default) — this includes fire-and-forget work, independent investigations, and anything where the user might hand you something else in the meantime. Wanting the result "next" is not enough on its own. In the terminal UI a foreground request is a logical await anyway: it returns PENDING immediately and releases your turn, and the agent's complete final report arrives automatically in a later turn (headless/print runs still block inline).
|
|
22
22
|
- **Don't race**: after launching a background agent, you know nothing about its results. Never fabricate or predict them in any format — not as prose, summary, or structured output. The completion notification arrives in a later turn; it is never something you write yourself. If the user asks before it lands, say the agent is still running — give status, not a guess.
|
|
23
23
|
- Use resume with an agent ID to continue a previous agent's work. A new (non-resume) Agent call starts a fresh agent with no memory of prior runs, so the prompt must be self-contained.
|
|
24
24
|
- Use steer_subagent to send mid-run messages to a running background agent.
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* every one of them is in. That — a prompt that compares results against each
|
|
11
11
|
* other — is what justifies a barrier.
|
|
12
12
|
*
|
|
13
|
-
* args: { target?: string, lenses?: string[] }
|
|
13
|
+
* args: { target?: string, lenses?: string[], reviewModel?: string, judgeModel?: string }
|
|
14
|
+
* Requires the explicitly selected models (default haiku/sonnet) to be available.
|
|
14
15
|
*
|
|
15
16
|
* Run: ask the model — "run the workflow at examples/workflows/review-panel.js
|
|
16
17
|
* against src/auth.ts".
|
|
@@ -32,7 +33,9 @@ const reviews = await parallel(
|
|
|
32
33
|
lenses.map(lens => () =>
|
|
33
34
|
agent(`Review ${target} through the lens of ${lens} alone. Be specific and brief.`, {
|
|
34
35
|
label: `review:${lens}`,
|
|
35
|
-
|
|
36
|
+
agentType: 'general-purpose',
|
|
37
|
+
model: args?.reviewModel ?? 'haiku',
|
|
38
|
+
// This unpinned role honors effort; a custom role's thinking pin wins.
|
|
36
39
|
effort: 'low',
|
|
37
40
|
}),
|
|
38
41
|
),
|
|
@@ -57,7 +60,7 @@ const verdict = await agent(
|
|
|
57
60
|
`Reconcile these reviews of ${target}. Where they disagree, say which is right and why.`,
|
|
58
61
|
...usable.map(r => `\n## ${r.lens}\n${r.text}`),
|
|
59
62
|
].join('\n'),
|
|
60
|
-
{ label: 'synthesize', effort: 'high', agentType: 'Plan' },
|
|
63
|
+
{ label: 'synthesize', effort: 'high', agentType: 'Plan', model: args?.judgeModel ?? 'sonnet' },
|
|
61
64
|
)
|
|
62
65
|
|
|
63
66
|
return { reviewed: usable.length, verdict }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timmyjl12/pi-subagents",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Claude Code-style subagents and workflow orchestration for pi, with coordinated fallback recovery and an interactive child-session workspace.
|
|
3
|
+
"version": "0.21.1",
|
|
4
|
+
"description": "Claude Code-style subagents and workflow orchestration for pi, with coordinated fallback recovery and an interactive child-session workspace.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/timmyjl12/pi-subagents.git"
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@biomejs/biome": "^2.4.14",
|
|
58
|
-
"@earendil-works/pi-ai": "^1.
|
|
59
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
60
|
-
"@earendil-works/pi-tui": "^1.
|
|
58
|
+
"@earendil-works/pi-ai": "^1.5.2",
|
|
59
|
+
"@earendil-works/pi-coding-agent": "^1.5.2",
|
|
60
|
+
"@earendil-works/pi-tui": "^1.5.2",
|
|
61
61
|
"@sinclair/typebox": "^0.34.49",
|
|
62
62
|
"@types/node": "^25.5.0",
|
|
63
63
|
"@vitest/coverage-istanbul": "^4.1.10",
|
|
@@ -1,39 +1,115 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main-session awareness of live subagents.
|
|
3
|
-
*
|
|
4
|
-
* A compact `<pi-subagents>`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Main-session awareness of live subagents.
|
|
3
|
+
*
|
|
4
|
+
* A compact `<pi-subagents>` status message lists running/queued agents, so the
|
|
5
|
+
* main model can interpret "cancel that task" and choose the appropriate stop
|
|
6
|
+
* or steer tool.
|
|
7
|
+
*
|
|
8
|
+
* Delivered as a hidden custom message appended at the next prompt — and only
|
|
9
|
+
* when the list differs from the last one on the branch — rather than as a
|
|
10
|
+
* system-prompt section. A section edit rewrites the prompt head: providers
|
|
11
|
+
* without mid-conversation system messages (pi collapses them into the head)
|
|
12
|
+
* lose the whole cached prefix on every start and finish, and append-mode
|
|
13
|
+
* children inherit the volatile list through `ctx.getSystemPrompt()`. An
|
|
14
|
+
* appended message leaves everything already sent untouched.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import type { AgentRecord } from "./types.ts";
|
|
19
|
+
|
|
20
|
+
/** `customType` of the status message; `display: false` keeps it out of the TUI. */
|
|
21
|
+
export const ACTIVE_AGENTS_MESSAGE_TYPE = "subagents-active";
|
|
22
|
+
|
|
23
|
+
/** Rows listed in the message; the rest are summarized as a count. */
|
|
24
|
+
const MAX_ROWS = 10;
|
|
25
|
+
|
|
26
|
+
const NONE_ACTIVE = "No subagents are running or queued now.";
|
|
27
|
+
|
|
28
|
+
type ListedRecord = Pick<AgentRecord, "id" | "handle" | "alias" | "description" | "status" | "isBackground">;
|
|
29
|
+
|
|
30
|
+
/** The subset of a branch entry this module reads. */
|
|
31
|
+
type BranchEntry = Pick<SessionEntry, "type"> & {
|
|
32
|
+
id?: string;
|
|
33
|
+
customType?: string;
|
|
34
|
+
content?: unknown;
|
|
35
|
+
firstKeptEntryId?: string | null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* List text for the running/queued agents, or undefined when there are none.
|
|
40
|
+
* Contains only stable fields — no durations or token counts — so the text
|
|
41
|
+
* changes only when the set of agents or their status does.
|
|
42
|
+
*/
|
|
43
|
+
export function buildActiveAgentsSection(records: readonly ListedRecord[]): string | undefined {
|
|
44
|
+
const active = records.filter(r => r.status === "running" || r.status === "queued");
|
|
45
|
+
if (active.length === 0) return undefined;
|
|
46
|
+
const rows = active.slice(0, MAX_ROWS).map(r => {
|
|
47
|
+
const handle = r.alias ?? r.handle;
|
|
48
|
+
const mode = r.isBackground === false ? "foreground" : "background";
|
|
49
|
+
const description = r.description.replace(/\s+/g, " ").trim();
|
|
50
|
+
return `- ${r.id}${handle ? ` (@${handle})` : ""} — ${description} — ${r.status}, ${mode}`;
|
|
51
|
+
});
|
|
52
|
+
if (active.length > MAX_ROWS) rows.push(`- …and ${active.length - MAX_ROWS} more`);
|
|
53
|
+
return [
|
|
54
|
+
"Subagents currently running or queued:",
|
|
55
|
+
...rows,
|
|
56
|
+
"If the user asks to cancel/stop one of these, call stop_subagent with its id or handle; to redirect it, call steer_subagent.",
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The branch as the model still sees it after compaction. Mirrors pi's
|
|
62
|
+
* `buildContextEntries`: the latest compaction entry stands in for everything
|
|
63
|
+
* before it, except the entries it retained (`firstKeptEntryId` onwards) and
|
|
64
|
+
* everything after it. A branch that is already projected — the compaction
|
|
65
|
+
* first — passes through unchanged.
|
|
66
|
+
*/
|
|
67
|
+
function projectedBranch(branch: readonly BranchEntry[]): readonly BranchEntry[] {
|
|
68
|
+
let compactionAt = -1;
|
|
69
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
70
|
+
if (branch[i].type === "compaction") {
|
|
71
|
+
compactionAt = i;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (compactionAt < 0) return branch;
|
|
76
|
+
const firstKept = branch[compactionAt].firstKeptEntryId;
|
|
77
|
+
const keptFrom = firstKept ? branch.findIndex(entry => entry.id === firstKept) : -1;
|
|
78
|
+
const retained = keptFrom >= 0 && keptFrom < compactionAt ? branch.slice(keptFrom, compactionAt) : [];
|
|
79
|
+
return [...retained, ...branch.slice(compactionAt + 1)];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Text of the latest status message the model still has on this branch. */
|
|
83
|
+
function lastAnnouncement(branch: readonly BranchEntry[]): string | undefined {
|
|
84
|
+
const visible = projectedBranch(branch);
|
|
85
|
+
for (let i = visible.length - 1; i >= 0; i--) {
|
|
86
|
+
const entry = visible[i];
|
|
87
|
+
if (entry.type !== "custom_message" || entry.customType !== ACTIVE_AGENTS_MESSAGE_TYPE) continue;
|
|
88
|
+
if (typeof entry.content === "string") return entry.content;
|
|
89
|
+
if (!Array.isArray(entry.content)) return undefined;
|
|
90
|
+
return entry.content
|
|
91
|
+
.map((part: { type?: unknown; text?: unknown }) => (part.type === "text" && typeof part.text === "string" ? part.text : ""))
|
|
92
|
+
.join("");
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Status message content to append at this prompt, or undefined when the
|
|
99
|
+
* branch already carries the current list. Once agents drain, the model is
|
|
100
|
+
* told so exactly once; a branch that never listed any gets nothing.
|
|
101
|
+
*/
|
|
102
|
+
export function nextActiveAgentsMessage(
|
|
103
|
+
records: readonly ListedRecord[],
|
|
104
|
+
branch: readonly BranchEntry[],
|
|
105
|
+
): string | undefined {
|
|
106
|
+
const list = buildActiveAgentsSection(records);
|
|
107
|
+
const last = lastAnnouncement(branch);
|
|
108
|
+
const wrap = (body: string) => `<pi-subagents>\n${body}\n</pi-subagents>`;
|
|
109
|
+
if (list) {
|
|
110
|
+
const text = wrap(list);
|
|
111
|
+
return text === last ? undefined : text;
|
|
112
|
+
}
|
|
113
|
+
const idle = wrap(NONE_ACTIVE);
|
|
114
|
+
return last === undefined || last === idle ? undefined : idle;
|
|
115
|
+
}
|
package/src/agent-color.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Agents uses, so those definitions render as written.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { getConfig } from "./agent-types.
|
|
10
|
+
import { getConfig } from "./agent-types.ts";
|
|
11
11
|
|
|
12
12
|
const NAMED_AGENT_COLORS: Readonly<Record<string, string>> = {
|
|
13
13
|
// Claude Code's eight subagent colors, as its default theme renders them.
|
|
@@ -157,5 +157,13 @@ export function renderAgentName(
|
|
|
157
157
|
): string {
|
|
158
158
|
if (!type) return renderAgentNameLabel("Agent", undefined, theme, style);
|
|
159
159
|
const config = getConfig(type);
|
|
160
|
-
|
|
160
|
+
// displayName is user-authored config free text. Every caller feeds the
|
|
161
|
+
// result to a terminal ROW; a control byte here must not break the row.
|
|
162
|
+
// ANSI styling is added by renderAgentNameLabel after this flattening.
|
|
163
|
+
const displayName = config.displayName.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, " ")
|
|
164
|
+
.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, " ")
|
|
165
|
+
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]+/g, " ")
|
|
166
|
+
.replace(/\s+/g, " ")
|
|
167
|
+
.trim();
|
|
168
|
+
return renderAgentNameLabel(displayName || type, config.color, theme, style);
|
|
161
169
|
}
|
package/src/agent-file-toggle.ts
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
import { existsSync } from "node:fs";
|
|
29
29
|
import { join, sep } from "node:path";
|
|
30
30
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
31
|
-
import { parseAgentFrontmatter } from "./custom-agents.
|
|
32
|
-
import type { AgentConfig } from "./types.
|
|
31
|
+
import { parseAgentFrontmatter } from "./custom-agents.ts";
|
|
32
|
+
import type { AgentConfig } from "./types.ts";
|
|
33
33
|
|
|
34
34
|
export type AgentFileLocation = "project" | "workspace" | "personal";
|
|
35
35
|
|