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/.pi/extensions/pi-workflow-engine/index.ts +187 -30
- package/.pi/extensions/pi-workflow-engine/src/agent-runner.ts +70 -2
- package/.pi/extensions/pi-workflow-engine/src/dynamax-shortcuts.ts +75 -0
- package/.pi/extensions/pi-workflow-engine/src/dynamax.ts +204 -22
- package/.pi/extensions/pi-workflow-engine/src/engine.ts +150 -20
- package/.pi/extensions/pi-workflow-engine/src/review/github-pr-comments.ts +17 -12
- package/.pi/extensions/pi-workflow-engine/src/types.ts +25 -1
- package/.pi/extensions/pi-workflow-engine/src/ui/workflow-result-renderer.ts +13 -7
- package/.pi/extensions/pi-workflow-engine/src/usage.ts +230 -0
- package/README.md +147 -182
- package/USAGE.md +46 -9
- package/package.json +7 -7
- package/assets/preview-candidate-core.png +0 -0
- package/assets/preview-candidate-relic-emblem.png +0 -0
- package/assets/preview-candidate-robot-squad.png +0 -0
package/README.md
CHANGED
|
@@ -2,203 +2,161 @@
|
|
|
2
2
|
|
|
3
3
|
# pi-workflow-engine
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
19
|
+
Or install from GitHub:
|
|
39
20
|
|
|
40
21
|
```bash
|
|
41
|
-
pi
|
|
22
|
+
pi install git:github.com/timbrinded/pi-workflow-engine
|
|
42
23
|
```
|
|
43
24
|
|
|
44
|
-
|
|
25
|
+
Restart pi, or run `/reload` in an open session, then confirm it loaded:
|
|
45
26
|
|
|
46
27
|
```bash
|
|
47
|
-
pi
|
|
28
|
+
pi list
|
|
48
29
|
```
|
|
49
30
|
|
|
50
|
-
|
|
31
|
+
For project-local install:
|
|
51
32
|
|
|
52
33
|
```bash
|
|
53
|
-
pi
|
|
34
|
+
pi install npm:pi-workflow-engine -l
|
|
54
35
|
```
|
|
55
36
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
For the complete installation, invocation, authoring, tuning, and troubleshooting guide, see [USAGE.md](USAGE.md).
|
|
37
|
+
## Use Dynamax
|
|
59
38
|
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
45
|
+
What to expect:
|
|
76
46
|
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
63
|
+
The workflow inspector is available with:
|
|
91
64
|
|
|
92
|
-
|
|
65
|
+
```text
|
|
66
|
+
/workflow:inspector
|
|
67
|
+
```
|
|
93
68
|
|
|
94
|
-
|
|
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
|
-
##
|
|
71
|
+
## Example Dynamax Prompts
|
|
97
72
|
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
```text
|
|
88
|
+
dynamax compare these two implementation approaches and argue both sides before recommending one.
|
|
89
|
+
```
|
|
116
90
|
|
|
117
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
+
Expected result: an adversarial checklist with concrete risks, what would break, and which items are blockers versus follow-ups.
|
|
130
98
|
|
|
131
|
-
|
|
99
|
+
```text
|
|
100
|
+
dynamax find the simplest safe refactor path for this module. Avoid broad rewrites.
|
|
101
|
+
```
|
|
132
102
|
|
|
133
|
-
|
|
103
|
+
Expected result: small refactor opportunities, why they are safe, and what not to touch.
|
|
134
104
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
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
|
-
|
|
148
|
-
name: "my-workflow",
|
|
149
|
-
description: "Find, verify, and summarize something important.",
|
|
150
|
-
};
|
|
111
|
+
## Saved Workflows
|
|
151
112
|
|
|
152
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
157
|
+
## Local Development
|
|
200
158
|
|
|
201
|
-
Only needed if you want to add workflows,
|
|
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
|
-
|
|
169
|
+
Load your working copy through the package manifest without installing it:
|
|
212
170
|
|
|
213
|
-
|
|
171
|
+
```bash
|
|
172
|
+
pi -e .
|
|
173
|
+
```
|
|
214
174
|
|
|
215
|
-
|
|
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
|
-
|
|
177
|
+
```bash
|
|
178
|
+
pi -ne -e .
|
|
179
|
+
```
|
|
218
180
|
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
191
|
+
Drop-in workflows are also discovered best-effort from:
|
|
237
192
|
|
|
238
|
-
-
|
|
239
|
-
-
|
|
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
|
-
|
|
196
|
+
Use `/workflow <name> --refresh` after adding a drop-in file.
|
|
243
197
|
|
|
244
|
-
|
|
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
|
-
|
|
200
|
+
### Technical Notes
|
|
249
201
|
|
|
250
|
-
|
|
251
|
-
pi -
|
|
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
|
-
|
|
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
|
-
|
|
220
|
+
No-LLM benchmark scripts:
|
|
257
221
|
|
|
258
|
-
|
|
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
|
|
233
|
+
settings.json
|
|
265
234
|
extensions/pi-workflow-engine/
|
|
266
|
-
index.ts
|
|
235
|
+
index.ts
|
|
267
236
|
src/
|
|
268
|
-
types.ts
|
|
269
|
-
agent-runner.ts
|
|
270
|
-
concurrency.ts
|
|
271
|
-
engine.ts
|
|
272
|
-
progress.ts
|
|
273
|
-
discovery.ts
|
|
274
|
-
workflows.ts
|
|
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
|
|
277
|
-
refactor-scout.ts
|
|
278
|
-
diagnose.ts
|
|
279
|
-
perf-review.ts
|
|
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
|
|
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
|
|
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 #
|
|
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
|
|
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
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
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": "
|
|
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": "
|
|
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": "^
|
|
60
|
+
"@typescript/native-preview": "^7.0.0-dev.20260615.1"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|