pi-workflow-engine 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,203 +2,161 @@
2
2
 
3
3
  # pi-workflow-engine
4
4
 
5
- Programmable multi-agent workflows for the [pi](https://pi.dev) coding agent.
5
+ Zero-dependency Dynamax workflows for [pi](https://pi.dev): opt into live, parallel subagents when one coding agent is not enough.
6
6
 
7
- This is not just a way to run a prompt. It is a way to turn an agentic procedure into code: scope the task, fork isolated subagents, fan out across review lenses, validate every handoff with schemas, verify candidate findings, and synthesize one ranked result.
7
+ Use `dynamax` when a task needs several independent passes: review from different angles, compare options, chase a bug through multiple suspects, or stress-test a plan. pi can spin up a temporary workflow, run focused subagents in parallel, show progress in the TUI, and return one synthesized result.
8
8
 
9
- The built-in workflows are advisory: they inspect, fan out, verify, and report. They do not edit files. Start with `/workflow code-review`, or use the focused scouts for refactors, diagnosis, and performance.
9
+ The package ships no bundled runtime dependencies. It uses the pi SDK and pi's bundled core packages, so installing it does not pull in a second agent stack.
10
10
 
11
- ## Why workflows matter
12
-
13
- The best agentic coding work is rarely a single chat turn. It is a repeatable loop of context gathering, delegated investigation, structured handoffs, verification, and synthesis.
14
-
15
- `pi-workflow-engine` brings that shape to pi with static TypeScript workflows:
16
-
17
- - **Procedures, not prompts**: write the workflow once, then invoke it with `/workflow` or let the host agent call the `workflow` tool.
18
- - **Isolated subagents**: each `agent()` runs in its own in-memory pi session, so exploratory work does not pollute the main conversation.
19
- - **Parallel cognition**: run many focused agents at once, with a shared concurrency cap so large workflows stay bounded.
20
- - **Typed handoffs**: pass structured data between stages using typebox schemas instead of asking the model to emit parseable prose.
21
- - **Verifier stages**: make verification part of the control flow, not an optional final instruction.
22
- - **Live progress**: surface phases, agent status, counters, and lane items in the TUI while the run is still moving.
23
-
24
- The result is closer to an executable review playbook than a chatbot shortcut.
11
+ The built-in workflows are advisory. They inspect, verify, and report; they do not edit files.
25
12
 
26
13
  ## Install
27
14
 
28
- ```bash
29
- pi install git:github.com/timbrinded/pi-workflow-engine
30
- ```
31
-
32
- Or from npm:
33
-
34
15
  ```bash
35
16
  pi install npm:pi-workflow-engine
36
17
  ```
37
18
 
38
- That's all. pi fetches the package and serves its core dependencies from its own bundle, so there is no clone, install, or build step. The package entrypoint is the canonical pi extension module at `.pi/extensions/pi-workflow-engine/index.ts`. Restart pi, or run `/reload` in an open session, then confirm it is registered:
19
+ Or install from GitHub:
39
20
 
40
21
  ```bash
41
- pi list
22
+ pi install git:github.com/timbrinded/pi-workflow-engine
42
23
  ```
43
24
 
44
- Scope it to a single repo instead of globally. This writes to that repo's `.pi/settings.json`:
25
+ Restart pi, or run `/reload` in an open session, then confirm it loaded:
45
26
 
46
27
  ```bash
47
- pi install git:github.com/timbrinded/pi-workflow-engine -l
28
+ pi list
48
29
  ```
49
30
 
50
- Uninstall with:
31
+ For project-local install:
51
32
 
52
33
  ```bash
53
- pi remove git:github.com/timbrinded/pi-workflow-engine
34
+ pi install npm:pi-workflow-engine -l
54
35
  ```
55
36
 
56
- ## Usage
57
-
58
- For the complete installation, invocation, authoring, tuning, and troubleshooting guide, see [USAGE.md](USAGE.md).
37
+ ## Use Dynamax
59
38
 
60
- In a pi session, from inside a git repo with changes:
39
+ Put the word `dynamax` in your prompt when you want pi to use a custom multi-agent workflow for the current task.
61
40
 
62
41
  ```text
63
- /workflow code-review # review the current branch or open PR
64
- /workflow code-review HEAD~3 # review a ref range, target, or focus area
65
- /workflow refactor-scout src/ # find safe refactor opportunities
66
- /workflow diagnose "typecheck fails after the schema change"
67
- /workflow perf-review "workflow startup latency"
68
- /workflow code-review --inspect # open the live workflow inspector while the run is active
69
- /workflow:inspector # reopen the last completed workflow inspector
70
- /workflow code-review --result-viewer # explicitly open the post-review results viewer
71
- /workflow code-review --review-viewer # alias for --result-viewer
72
- /workflow code-review --no-result-viewer # explicitly keep the post-review viewer closed
42
+ dynamax investigate why typecheck started failing after this branch
73
43
  ```
74
44
 
75
- The host agent can also invoke the `workflow` tool mid-conversation. It accepts either a registered workflow `name` or a one-off inline workflow `script`:
45
+ What to expect:
76
46
 
77
- ```text
78
- Run the code-review workflow on this PR and use the result before deciding what to fix.
79
- ```
47
+ 1. pi decides whether a saved workflow fits or whether to write a one-off workflow.
48
+ 2. The workflow runs focused subagents in parallel.
49
+ 3. You can watch phases, agents, findings, and logs in the workflow inspector.
50
+ 4. You get a summarized result with evidence, risks, next steps, and workflow-level token/cost totals gathered from subagent sessions.
51
+ 5. You can then ask pi to make changes using that result.
80
52
 
81
- Opt into dynamic multi-agent orchestration with the literal `dynamax` token, or keep it sticky for the session:
53
+ Workflow usage totals are reported on the workflow result itself. pi's built-in footer and `/session` stats may still show host-session usage only unless pi core adds a first-class extension usage API.
54
+
55
+ Dynamax is one-shot by default. It applies to the next agent run and then clears. Keep it on for the session with:
82
56
 
83
57
  ```text
84
- dynamax inspect this bug with multiple focused agents
85
58
  /workflow:dynamax on
86
59
  /workflow:dynamax status
87
60
  /workflow:dynamax off
88
61
  ```
89
62
 
90
- `dynamax` is a permission signal for the host agent: once opted in, it may run an existing named workflow or author an inline workflow script through the `workflow` tool. In interactive mode, `/workflow` with no arguments also offers `✍ Author temporary one-shot workflow…`; choose it, type a brief, and pi will ask the host agent to author/run a temporary inline workflow.
63
+ The workflow inspector is available with:
91
64
 
92
- The advisory workflows inspect and report only; they do not edit files. They return the same shape: summary, ranked findings, evidence, impact, recommendations, and next steps.
65
+ ```text
66
+ /workflow:inspector
67
+ ```
93
68
 
94
- The package also ships the `workflow-code-review-actions` skill. When you select review findings in the results viewer, the parent agent can use that skill to either make minimal local fixes or raise GitHub PR inline comments through GitHub MCP/tools or `gh`.
69
+ In interactive mode, `/workflow` with no arguments also offers `Author temporary one-shot workflow...`. Choose it, type a brief, and pi will ask the host agent to write and run a temporary workflow.
95
70
 
96
- ## Built-in workflows
71
+ ## Example Dynamax Prompts
97
72
 
98
- - `code-review`: Reviews the current branch, open PR, ref range, or target. It looks for correctness bugs and cleanup issues, then independently verifies candidates before ranking them.
99
- - `refactor-scout`: Looks for small, safe refactor opportunities: duplication, complexity, weak types, boundary leaks, dead code, and convention drift.
100
- - `diagnose`: Investigates a symptom, failing command, or regression. It generates competing root-cause hypotheses, verifies them, and returns the most likely causes with next validation steps.
101
- - `perf-review`: Reviews a slow path or workload for bottleneck hypotheses, measurement gaps, and safe optimization directions. It avoids claiming certainty when measurement evidence is missing.
73
+ Use Dynamax when you want breadth, independent judgment, or adversarial pressure before editing.
102
74
 
103
- ## The code-review workflow
75
+ ```text
76
+ dynamax do an adversarial review of this branch. I want correctness bugs, hidden coupling, test gaps, and over-engineered parts called out separately.
77
+ ```
104
78
 
105
- The bundled review workflow is deliberately shaped like a serious review process:
79
+ Expected result: several review angles run independently, likely findings are verified, duplicates are merged, and you get a ranked report with concrete evidence before deciding what to fix.
106
80
 
107
- 1. **Scope**: detect the open PR or branch diff, list changed files, and read relevant project conventions.
108
- 2. **Find**: fan out across focused review lenses such as logic bugs, error paths, edge cases, simplification, and conventions.
109
- 3. **Gate and dedupe**: bound candidates to changed lines and collapse duplicate findings before spending verifier tokens.
110
- 4. **Verify**: send each survivor to an independent verifier that must confirm, mark plausible, or refute with evidence.
111
- 5. **Synthesize**: produce one ranked report with stats, verdicts, and concrete locations.
81
+ ```text
82
+ dynamax investigate this flaky test. Split the work between recent diffs, test setup, async timing, and external dependencies.
83
+ ```
112
84
 
113
- After a direct TUI `/workflow code-review` run produces findings, pi records a readable table-formatted result message without asking whether to open another surface. Use `--result-viewer`/`--review-viewer` when you want the interactive findings viewer to open immediately, or `--no-result-viewer`/`--no-review-viewer` when a script or alias should explicitly keep it closed. Use `/workflow:inspector` after a run to reopen the last completed workflow inspector.
85
+ Expected result: parallel hypotheses, evidence for or against each one, and the most likely root cause with a small validation step.
114
86
 
115
- Viewer controls:
87
+ ```text
88
+ dynamax compare these two implementation approaches and argue both sides before recommending one.
89
+ ```
116
90
 
117
- - `↑`/`↓`: move between findings.
118
- - `1`-`9`: jump directly to a visible finding.
119
- - `space`: tag/untag the current finding.
120
- - `a`: tag or untag all visible findings.
121
- - `enter`: expand/collapse the detail pane.
122
- - `←`/`→` or `pageup`/`pagedown`: scroll detail text.
123
- - `f`: hand selected findings to the parent agent for minimal local fixes.
124
- - `c`: comment on selected findings upstream.
125
- - `q`/`escape`: close the viewer.
91
+ Expected result: separate agents inspect each approach, another pass looks for failure modes, and the final answer separates tradeoffs from the recommendation.
126
92
 
127
- GitHub inline comments require a GitHub PR checkout, an authenticated `gh`, and findings with changed-file line numbers. If direct PR context resolution or posting is unavailable, the viewer queues a parent-agent fallback prompt that can use installed GitHub MCP/tools, project skills, or `gh`. Workflow tool invocations remain non-interactive: they do not prompt or open the viewer, and they return table-formatted results only.
93
+ ```text
94
+ dynamax review this migration plan like a hostile reviewer. Focus on rollback, data loss, concurrency, and missing operational steps.
95
+ ```
128
96
 
129
- The review lenses live in `.pi/extensions/pi-workflow-engine/workflows/code-review.ts`. That is where your repo's real failure modes belong.
97
+ Expected result: an adversarial checklist with concrete risks, what would break, and which items are blockers versus follow-ups.
130
98
 
131
- ## Authoring workflows
99
+ ```text
100
+ dynamax find the simplest safe refactor path for this module. Avoid broad rewrites.
101
+ ```
132
102
 
133
- A workflow is a TypeScript module that exports `meta` plus a default `async (api) => result`. The injected `api` gives you the primitives:
103
+ Expected result: small refactor opportunities, why they are safe, and what not to touch.
134
104
 
135
- | Primitive | Behaviour |
136
- |-----------|-----------|
137
- | `agent(prompt, { schema })` | Runs a subagent in an isolated session. With a typebox `schema`, returns validated structured data; otherwise returns final text. |
138
- | `parallel(thunks)` | Runs every thunk concurrently and waits for all results. |
139
- | `pipeline(items, ...stages)` | Runs each item through all stages independently, with no barrier between stages. |
140
- | `phase(title)` / `log(msg)` | Drives the live progress tree shown in the TUI and stderr breadcrumbs when headless. |
141
- | `progress(event)` | Emits structured progress for richer workflow UI surfaces. |
105
+ ```text
106
+ dynamax inspect this performance issue. Separate measurement gaps from real bottleneck hypotheses.
107
+ ```
142
108
 
143
- ```ts
144
- import { Type } from "typebox";
145
- import type { WorkflowApi, WorkflowMeta } from "../src/types.ts";
109
+ Expected result: a performance-focused report that distinguishes known evidence from guesses and suggests the next measurement command.
146
110
 
147
- export const meta: WorkflowMeta = {
148
- name: "my-workflow",
149
- description: "Find, verify, and summarize something important.",
150
- };
111
+ ## Saved Workflows
151
112
 
152
- const FindingSchema = Type.Object({
153
- summary: Type.String(),
154
- file: Type.String(),
155
- line: Type.Optional(Type.Number()),
156
- });
113
+ You can also run saved workflows directly:
157
114
 
158
- export default async function run({ agent, parallel, phase }: WorkflowApi) {
159
- phase("Find");
115
+ ```text
116
+ /workflow code-review
117
+ /workflow code-review HEAD~3
118
+ /workflow refactor-scout src/
119
+ /workflow diagnose "typecheck fails after the schema change"
120
+ /workflow perf-review "workflow startup latency"
121
+ ```
160
122
 
161
- const findings = await parallel([
162
- () => agent("Find correctness bugs in the diff.", { schema: FindingSchema, thinkingLevel: "low" }),
163
- () => agent("Find error-handling bugs in the diff.", { schema: FindingSchema, thinkingLevel: "low" }),
164
- ]);
123
+ Built-ins:
165
124
 
166
- phase("Synthesize");
167
- return agent(`Summarize these findings: ${JSON.stringify(findings)}`, { thinkingLevel: "medium" });
168
- }
169
- ```
125
+ - `code-review`: reviews a PR, branch diff, ref range, or target.
126
+ - `refactor-scout`: finds small, safe refactor opportunities.
127
+ - `diagnose`: investigates a bug, failing command, or regression.
128
+ - `perf-review`: reviews a slow path or performance concern.
170
129
 
171
- Inline workflow scripts use the same primitives, but are passed as a string to the `workflow` tool instead of being saved as files. A minimal inline workflow starts with `export const meta` and uses the injected Type object for schemas:
172
-
173
- ```ts
174
- export const meta = {
175
- name: "inline-review",
176
- description: "One-off focused review workflow.",
177
- };
178
-
179
- export default async function run({ agent, parallel, phase, args }) {
180
- phase("Find");
181
- const Finding = Type.Object({ summary: Type.String() });
182
- const findings = await parallel([
183
- () => agent(`Find correctness issues: ${args}`, { schema: Finding, thinkingLevel: "low" }),
184
- () => agent(`Find edge cases: ${args}`, { schema: Finding, thinkingLevel: "low" }),
185
- ]);
186
- return { summary: JSON.stringify(findings) };
187
- }
130
+ Useful flags:
131
+
132
+ ```text
133
+ /workflow code-review --inspect
134
+ /workflow code-review --result-viewer
135
+ /workflow code-review --no-result-viewer
136
+ /workflow code-review --concurrency=4
137
+ /workflow code-review --refresh
188
138
  ```
189
139
 
190
- Inline v1 rules: no imports, no dynamic `import()`, pure-literal `meta`, schemas must use the injected Type value, and scripts run in-process with the extension's permissions. This v1 path is permissive rather than sandboxed.
140
+ The code-review workflow can open an interactive findings viewer. Select findings and hand them back to the parent agent for minimal fixes, or ask it to raise GitHub PR comments when `gh` is authenticated and PR context is available.
141
+
142
+ For the full command guide, see [USAGE.md](USAGE.md).
143
+
144
+ ## What Dynamax Is Good For
145
+
146
+ Use it for:
191
147
 
192
- Under the hood:
148
+ - adversarial reviews before you trust a plan or diff;
149
+ - debugging where several causes are plausible;
150
+ - design comparisons where you want both sides argued;
151
+ - refactor scouting where broad rewrites would be risky;
152
+ - performance investigations where measurement gaps matter;
153
+ - documentation reviews where consistency and reader expectations both matter.
193
154
 
194
- - **Each `agent()` is an in-process pi `AgentSession`** using `createAgentSession` and `SessionManager.inMemory()`.
195
- - **Structured output is a terminating tool**. The engine registers one tool whose `parameters` is your schema; pi validates the call and the engine captures the args. There is no JSON scraping.
196
- - **A single global semaphore caps concurrent agents**, so `parallel` and `pipeline` can nest freely while every `agent()` call still respects the run cap.
197
- - **Three surfaces are registered**: `/workflow <name> [args]` for direct use, grouped workflow commands such as `/workflow:dynamax on|off|status` and `/workflow:inspector`, and a `workflow` tool for host-agent delegation by `name` or inline `script`.
155
+ Do not use it for every tiny task. A single prompt is still better for simple edits, one-file explanations, and obvious mechanical changes.
198
156
 
199
- ## Local development
157
+ ## Local Development
200
158
 
201
- Only needed if you want to add workflows, customise workflows, or contribute. Using the bundled workflows requires none of this.
159
+ Only needed if you want to add workflows, customize workflows, or contribute. Using the package does not require a clone, install, or build step.
202
160
 
203
161
  ```bash
204
162
  git clone https://github.com/timbrinded/pi-workflow-engine
@@ -208,77 +166,84 @@ bun run typecheck
208
166
  bun run test
209
167
  ```
210
168
 
211
- The test suite is no-LLM and uses Bun's built-in `bun test` runner, not a third-party test framework.
169
+ Load your working copy through the package manifest without installing it:
212
170
 
213
- ### Performance controls and benchmarks
171
+ ```bash
172
+ pi -e .
173
+ ```
214
174
 
215
- The workflow engine is measurement-first: tune only after checking queue wait, local orchestration, discovery, and UI render costs on the machine where you run pi.
175
+ If you also have the global package installed, pi may report duplicate `/workflow` or `workflow` tool diagnostics. Remove one source or load only this working copy:
216
176
 
217
- Runtime controls:
177
+ ```bash
178
+ pi -ne -e .
179
+ ```
218
180
 
219
- - `PI_WORKFLOW_PERF=1` enables the internal per-run performance recorder used by the orchestration instrumentation.
220
- - `PI_WORKFLOW_CONCURRENCY=N` sets the per-run agent semaphore cap. The default remains `min(8, max(2, CPU count))`.
221
- - `PI_WORKFLOW_PARALLEL_SUBMISSION_LIMIT=N` limits how many `parallel()` thunks are submitted at once; this is separate from the running-agent semaphore cap.
222
- - `PI_WORKFLOW_LANE_ITEM_LIMIT=N` caps retained progress lane items per lane; snapshots report how many older items are hidden.
223
- - Slash commands can override selected controls per run: `/workflow <name> --concurrency=N --parallel-limit=N ...`.
181
+ ### Add A Workflow
224
182
 
225
- No-LLM benchmark scripts:
183
+ A workflow is a TypeScript module that exports `meta` plus a default async function. The `api` object gives you `agent`, `parallel`, `pipeline`, `workflow`, `phase`, `log`, and `progress`.
226
184
 
227
- ```bash
228
- bun run bench:concurrency -- --items 200 --concurrency 8 --json
229
- bun run bench:discovery -- --iterations 3 --json
230
- bun run bench:startup -- --json
231
- bun run bench:ui -- --agents 1000 --lane-items 1000 --json
232
- ```
185
+ Guaranteed built-ins are statically registered:
233
186
 
234
- Add `--out` to write machine-local JSON under `.artifacts/benchmarks/`. These timings are advisory, not portable thresholds.
187
+ 1. Add `.pi/extensions/pi-workflow-engine/workflows/<name>.ts`.
188
+ 2. Import it in `.pi/extensions/pi-workflow-engine/src/workflows.ts`.
189
+ 3. Add it to `BUILTIN_WORKFLOWS`.
235
190
 
236
- Guardrails:
191
+ Drop-in workflows are also discovered best-effort from:
237
192
 
238
- - Do not pool or reuse subagent sessions until `agent.create_session_ms` is proven material and isolation semantics are reviewed.
239
- - Do not lazy-load guaranteed built-in workflow modules until pi/jiti bundled `typebox` identity is proven for that path.
240
- - Do not raise the default concurrency without queue-wait versus run-time evidence.
193
+ - `.pi/extensions/pi-workflow-engine/workflows/*.ts`
194
+ - `~/.pi/agent/workflows/*.ts`
241
195
 
242
- Load your working copy through the package manifest without installing it. This is ephemeral and exercises the same `.pi/extensions/pi-workflow-engine/index.ts` entrypoint that installed packages use:
196
+ Use `/workflow <name> --refresh` after adding a drop-in file.
243
197
 
244
- ```bash
245
- pi -e .
246
- ```
198
+ Inline workflows are passed to the `workflow` tool as a script string. They are useful for one-off Dynamax orchestration. Inline v1 rules: no imports, no dynamic `import()`, pure-literal `meta`, schemas must use the injected `Type` value, and scripts run in-process with the extension's permissions.
247
199
 
248
- This repo also includes `.pi/settings.json` for project-local auto-discovery. If you also have the global package installed, pi may report duplicate `/workflow` or `workflow` tool diagnostics; remove one source or force pi to ignore discovered extensions and load this working copy instead:
200
+ ### Technical Notes
249
201
 
250
- ```bash
251
- pi -ne -e .
252
- ```
202
+ - Each `agent()` runs an in-process pi `AgentSession` with `SessionManager.inMemory()`.
203
+ - Workflow results aggregate the finalized assistant usage from those subagent sessions before disposal and show token/cost totals separately from pi's host-session footer accounting.
204
+ - Structured output uses a terminating tool whose `parameters` is your schema. pi validates the call; the engine captures the args. There is no JSON scraping.
205
+ - A single run-level semaphore caps concurrent agents, so nested `parallel`, `pipeline`, and `workflow()` calls stay bounded.
206
+ - Built-in workflows stay statically imported so they share pi's bundled `typebox` identity.
207
+ - Set `thinkingLevel` per fan-out agent. Otherwise many subagents can inherit an expensive global reasoning level.
208
+ - Set `model` per agent only when needed: bare ids are Anthropic shorthand, and `provider/id` targets other providers.
209
+ Omitted models inherit the host/session default; malformed or unknown explicit refs fail fast.
210
+
211
+ ### Performance Controls
212
+
213
+ Runtime controls:
253
214
 
254
- Add a built-in workflow by creating `.pi/extensions/pi-workflow-engine/workflows/<name>.ts`, importing it in `.pi/extensions/pi-workflow-engine/src/workflows.ts`, and adding it to `BUILTIN_WORKFLOWS`. Statically imported workflows share pi's bundled `typebox`, which guarantees schema validation. Files in `.pi/extensions/pi-workflow-engine/workflows/` and `~/.pi/agent/workflows/` are also discovered dynamically at runtime on a best-effort basis.
215
+ - `PI_WORKFLOW_PERF=1` enables per-run performance timing. This is timing-only; workflow usage/cost totals are reported separately when subagent usage is available.
216
+ - `PI_WORKFLOW_CONCURRENCY=N` sets the per-run agent cap. The default is `min(8, max(2, CPU count))`.
217
+ - `PI_WORKFLOW_PARALLEL_SUBMISSION_LIMIT=N` limits how many `parallel()` thunks are submitted at once.
218
+ - `PI_WORKFLOW_LANE_ITEM_LIMIT=N` caps retained progress lane items per lane.
255
219
 
256
- Keep guaranteed built-ins statically imported. Optimize cold startup at the extension entrypoint or discovery boundary first; do not lazy-load built-in workflow modules unless a test proves pi/jiti preserves the same bundled `typebox` identity for dynamically imported built-ins.
220
+ No-LLM benchmark scripts:
257
221
 
258
- Tune the built-in review workflow by editing the `ANGLES` array in `.pi/extensions/pi-workflow-engine/workflows/code-review.ts`. Tune `model`, `thinkingLevel`, and `tools` per `agent()` call, and use `PI_WORKFLOW_CONCURRENCY` or `/workflow <name> --concurrency=N` for measured per-run concurrency experiments.
222
+ ```bash
223
+ bun run bench:concurrency -- --items 200 --concurrency 8 --json
224
+ bun run bench:discovery -- --iterations 3 --json
225
+ bun run bench:startup -- --json
226
+ bun run bench:ui -- --agents 1000 --lane-items 1000 --json
227
+ ```
259
228
 
260
229
  ### Layout
261
230
 
262
231
  ```text
263
232
  .pi/
264
- settings.json project-local pi resource settings
233
+ settings.json
265
234
  extensions/pi-workflow-engine/
266
- index.ts canonical extension entry; registers the command and tool
235
+ index.ts
267
236
  src/
268
- types.ts WorkflowApi / WorkflowModule contracts
269
- agent-runner.ts createAgentSession + terminating-tool schema bridge
270
- concurrency.ts Semaphore, parallel(), pipeline()
271
- engine.ts runWorkflow(); binds primitives to one run
272
- progress.ts live phase/agent tree via ctx.ui.setWidget
273
- discovery.ts static registry + best-effort drop-in loading
274
- workflows.ts statically registered built-in workflows
237
+ types.ts
238
+ agent-runner.ts
239
+ concurrency.ts
240
+ engine.ts
241
+ progress.ts
242
+ discovery.ts
243
+ workflows.ts
275
244
  workflows/
276
- code-review.ts scope -> find -> verify -> synthesize
277
- refactor-scout.ts advisory refactor opportunities
278
- diagnose.ts advisory bug diagnosis
279
- perf-review.ts advisory performance investigation
245
+ code-review.ts
246
+ refactor-scout.ts
247
+ diagnose.ts
248
+ perf-review.ts
280
249
  ```
281
-
282
- ## License
283
-
284
- MIT. See [LICENSE](LICENSE).
package/USAGE.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Usage
2
2
 
3
- `pi-workflow-engine` adds multi-agent workflows to pi. Most users only need two surfaces:
3
+ `pi-workflow-engine` adds zero-dependency Dynamax workflows to pi: opt into live, parallel subagents for the tasks that need a custom investigation instead of one long prompt. Most users only need these surfaces:
4
4
 
5
5
  - `/workflow <name> [args]` to run a saved workflow directly.
6
- - `/workflow:*` commands for related actions such as inspector reopening and dynamax sticky mode.
6
+ - `/workflow:*` commands for related actions such as inspector reopening and Dynamax control.
7
7
  - `dynamax` as a literal one-shot opt-in token when you want the host agent to author a one-off inline workflow for investigation/review.
8
8
 
9
9
  ## Run a workflow
@@ -24,7 +24,7 @@ Useful flags:
24
24
 
25
25
  ```text
26
26
  /workflow code-review --inspect # show the live inspector while the run is active
27
- /workflow:inspector # reopen the last completed workflow inspector
27
+ /workflow:inspector # open the current or last workflow inspector
28
28
  /workflow code-review --result-viewer # explicitly open the findings viewer
29
29
  /workflow code-review --review-viewer # alias for --result-viewer
30
30
  /workflow code-review --concurrency=4 # cap concurrent subagents
@@ -42,9 +42,9 @@ Useful flags:
42
42
 
43
43
  `code-review` auto-detects a diff when you do not pass args. If there is an open GitHub PR for the current branch, it uses that PR diff; otherwise it falls back to branch-vs-main/master or `HEAD~1`.
44
44
 
45
- ## Use `dynamax` for inline workflows
45
+ ## Use Dynamax for custom workflows
46
46
 
47
- Use `dynamax` when the built-in workflows are not specific enough and you want the main pi agent to author a temporary workflow for the current question.
47
+ Use `dynamax` when the built-in workflows are not specific enough and you want the main pi agent to author a temporary workflow for the current question. It is the fastest path from "this needs multiple angles" to a live fan-out, verifier pass, and synthesized result.
48
48
 
49
49
  Interactive shortcut: run `/workflow` with no arguments, choose `✍ Author temporary one-shot workflow…`, and type a brief. pi will send that brief back to the host agent as a `dynamax` request so it can author and run an inline workflow with the `workflow` tool's `script` argument.
50
50
 
@@ -58,7 +58,7 @@ dynamax create a one-off workflow to compare the parser and tests before we chan
58
58
  dynamax use parallel agents to review this design and report the risks
59
59
  ```
60
60
 
61
- Sticky for the session:
61
+ Sticky mode and inspector shortcut:
62
62
 
63
63
  ```text
64
64
  /workflow:dynamax on
@@ -66,7 +66,25 @@ Sticky for the session:
66
66
  /workflow:dynamax status
67
67
  ```
68
68
 
69
- With dynamax enabled, the host agent usually calls the `workflow` tool with `script`: a one-off inline workflow. It can still call a saved workflow by `name` when one already fits.
69
+ The workflow inspector is also registered as a first-class shortcut shown by `/hotkeys`; the default is `ctrl+shift+m`. `ctrl+o` is intentionally not used because pi already uses it for tool-output expansion and tree filtering.
70
+
71
+ When only the literal `dynamax` token is used, the opt-in is one-shot: the next agent run receives the workflow permission reminder, stays visibly active for that run, then clears after the run ends. When `/workflow:dynamax on` is used, the opt-in is sticky for the current pi session until `/workflow:dynamax off`. Sticky mode, one-shot pending mode, and active Dynamax workflow runs show compact TUI status with `/workflow:dynamax on|off` and the inspector shortcut; off mode clears that status line.
72
+
73
+ When the host agent calls the `workflow` tool from a TUI session, pi opens the live workflow inspector for that run. The compact workflow widget still shows the latest moving status above the editor, but the inspector is the richer view for phases, agents, findings, and logs.
74
+
75
+ Configure the inspector shortcut by creating `~/.pi/agent/extensions/pi-workflow-engine.json`:
76
+
77
+ ```json
78
+ {
79
+ "shortcuts": {
80
+ "inspector": "ctrl+shift+x"
81
+ }
82
+ }
83
+ ```
84
+
85
+ Set `"inspector": null` to disable the shortcut while keeping `/workflow:dynamax` and `/workflow:inspector` available.
86
+
87
+ With Dynamax enabled, the host agent usually calls the `workflow` tool with `script`: a one-off inline workflow tailored to your prompt. It can still call a saved workflow by `name` when one already fits.
70
88
 
71
89
  ## Workflow results
72
90
 
@@ -77,7 +95,10 @@ Workflow results are rendered in pi with:
77
95
  - locations and evidence;
78
96
  - recommendations;
79
97
  - next steps;
80
- - run stats when available.
98
+ - run stats when available;
99
+ - workflow-level token and cost totals gathered from subagent sessions when provider usage is available.
100
+
101
+ These workflow usage totals are separate from `--perf`, which is internal timing only. They are also separate from pi's built-in footer and `/session` totals, which may still show host-session usage only unless pi core adds a first-class extension usage API. If a model has no pricing configured, token totals can be non-zero while displayed cost remains `$0.000`.
81
102
 
82
103
  During a run, pi shows live phases and subagent status. Use `--inspect` if you want a larger live view while the workflow is active, then `/workflow:inspector` if you want to bring the last completed inspector back up afterward.
83
104
 
@@ -121,9 +142,25 @@ Core primitives:
121
142
  | `pipeline(items, ...stages)` | Runs each item through stages independently. |
122
143
  | `phase(title)` / `log(message)` | Updates workflow progress UI. |
123
144
  | `progress(event)` | Emits counters, summaries, and lane items. |
145
+ | `workflow(ref, args?)` | Runs another workflow inline as a sub-step and returns its result. |
124
146
 
125
147
  Set `thinkingLevel` on fan-out agents. Otherwise many subagents can inherit an expensive global reasoning level.
126
148
 
149
+ Set `model` only when a subagent should use a specific model. Bare ids keep the Anthropic shorthand; `provider/id` targets built-in, custom, or local providers. Omitted models inherit the host/session default; malformed or unknown explicit refs fail fast.
150
+
151
+ ### Compose workflows
152
+
153
+ `workflow(ref, args?)` runs a registered workflow by name as a sub-step, returning its result. The child shares the parent run's concurrency cap, abort signal, and perf timing, and its phases nest under `<name> ▸ <phase>` in the live UI.
154
+
155
+ ```ts
156
+ export default async function run({ workflow }: WorkflowApi) {
157
+ const review = await workflow("code-review", "HEAD~3");
158
+ return { review };
159
+ }
160
+ ```
161
+
162
+ Nesting is one level only: calling `workflow()` from inside a sub-workflow rejects. Resolution throws on an unknown name — wrap the call in `try/catch` if a missing sub-workflow should be non-fatal (note `parallel()` rejects the whole batch on the first error, so catch inside each thunk for per-branch resilience).
163
+
127
164
  ### Where workflows live
128
165
 
129
166
  Guaranteed built-ins are statically registered:
@@ -178,7 +215,7 @@ Only tune these when a workflow is too slow, too expensive, or too noisy:
178
215
  | --- | --- |
179
216
  | `--concurrency=N` / `PI_WORKFLOW_CONCURRENCY=N` | Cap concurrent subagents. Default is `min(8, max(2, CPU count))`. |
180
217
  | `--parallel-limit=N` / `PI_WORKFLOW_PARALLEL_SUBMISSION_LIMIT=N` | Limit eager `parallel()` submission. |
181
- | `--perf` / `PI_WORKFLOW_PERF=1` | Include internal timing aggregates. |
218
+ | `--perf` / `PI_WORKFLOW_PERF=1` | Include internal timing aggregates. Usage/cost totals are reported separately from perf. |
182
219
  | `PI_WORKFLOW_LANE_ITEM_LIMIT=N` | Cap retained progress lane items. |
183
220
 
184
221
  ## Common fixes
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "pi-workflow-engine",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
- "description": "A customisable multi-agent workflow-orchestration engine for the pi coding agent.",
5
+ "description": "Zero-dependency Dynamax workflows for pi: live parallel subagents, typed handoffs, synthesized results.",
6
6
  "keywords": [
7
7
  "pi-package",
8
8
  "pi-extension",
@@ -23,7 +23,7 @@
23
23
  "files": [
24
24
  ".pi/extensions/pi-workflow-engine",
25
25
  ".pi/settings.json",
26
- "assets",
26
+ "assets/preview.png",
27
27
  "skills",
28
28
  "README.md",
29
29
  "USAGE.md",
@@ -35,8 +35,8 @@
35
35
  "image": "https://raw.githubusercontent.com/timbrinded/pi-workflow-engine/master/assets/preview.png"
36
36
  },
37
37
  "scripts": {
38
- "typecheck": "tsc --noEmit",
39
- "test": "bun test",
38
+ "typecheck": "tsgo --noEmit",
39
+ "test": "bun test --timeout=30000",
40
40
  "test:changedlines": "bun test tests/changedlines.test.ts",
41
41
  "test:concurrency": "bun test tests/concurrency.test.ts",
42
42
  "test:smoke": "bun test tests/discovery.test.ts",
@@ -46,7 +46,7 @@
46
46
  "bench:discovery": "bun run scripts/bench/discovery.ts",
47
47
  "bench:startup": "bun run scripts/bench/startup.ts",
48
48
  "bench:ui": "bun run scripts/bench/ui.ts",
49
- "prepublishOnly": "tsc --noEmit && bun run test"
49
+ "prepublishOnly": "tsgo --noEmit && bun run test"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@earendil-works/pi-agent-core": "*",
@@ -57,6 +57,6 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^22",
60
- "typescript": "^5.6.0"
60
+ "@typescript/native-preview": "^7.0.0-dev.20260615.1"
61
61
  }
62
62
  }
Binary file