pi-workflow-engine 0.5.0 → 0.7.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.
@@ -16,6 +16,7 @@ import {
16
16
  verdictConfidence,
17
17
  } from "../src/workflow-advisory-utils.ts";
18
18
  import { captureDiff } from "../src/diff-capture.ts";
19
+ import type { ReviewContext } from "../src/review/review-issues.ts";
19
20
  import type { WorkflowApi, WorkflowMeta, WorkflowRunStats } from "../src/types.ts";
20
21
 
21
22
  export const meta: WorkflowMeta = {
@@ -137,6 +138,15 @@ export default async function run(api: WorkflowApi): Promise<unknown> {
137
138
  if (scope.files.length === 0) {
138
139
  return { summary: "No changes found to review.", findings: [], nextSteps: ["Provide a PR, ref range, or changed files to review."], stats: makeStats(0, 0) };
139
140
  }
141
+
142
+ const reviewContext: ReviewContext = {
143
+ workflowName: "code-review",
144
+ target,
145
+ diffCommand: scope.diffCommand,
146
+ files: scope.files,
147
+ summary: scope.summary,
148
+ };
149
+
140
150
  log(`${scope.files.length} changed files`);
141
151
 
142
152
  // Capture the diff once, deterministically, so findings can be bounded to changed lines in code.
@@ -259,7 +269,7 @@ export default async function run(api: WorkflowApi): Promise<unknown> {
259
269
  log(`${verified.length} verified → ${surviving.length} kept`);
260
270
 
261
271
  if (surviving.length === 0) {
262
- return { summary: "No findings survived verification.", findings: [], nextSteps: ["No code-review action is recommended from this workflow run."], stats };
272
+ return { summary: "No findings survived verification.", findings: [], nextSteps: ["No code-review action is recommended from this workflow run."], stats, reviewContext };
263
273
  }
264
274
 
265
275
  // ─── Synthesize: rank, merge, report ───
@@ -283,10 +293,10 @@ export default async function run(api: WorkflowApi): Promise<unknown> {
283
293
  { phase: "Synthesize", label: "synthesize", thinkingLevel: "medium", schema: AdvisoryReportSchema },
284
294
  );
285
295
 
286
- if (!report) return { summary: "Synthesis produced no output.", findings: [], nextSteps: ["Re-run the workflow or inspect verifier evidence manually."], stats };
296
+ if (!report) return { summary: "Synthesis produced no output.", findings: [], nextSteps: ["Re-run the workflow or inspect verifier evidence manually."], stats, reviewContext };
287
297
 
288
298
  const findings = backfillAdvisoryFindings(report.findings, ranked, {
289
299
  impact: "Impact not restated by synthesis.",
290
300
  });
291
- return { ...report, findings, stats };
301
+ return { ...report, findings, stats, reviewContext };
292
302
  }
package/README.md CHANGED
@@ -65,7 +65,11 @@ In a pi session, from inside a git repo with changes:
65
65
  /workflow refactor-scout src/ # find safe refactor opportunities
66
66
  /workflow diagnose "typecheck fails after the schema change"
67
67
  /workflow perf-review "workflow startup latency"
68
- /workflow code-review --inspect # open the live workflow inspector
68
+ /workflow code-review --inspect # open the live workflow inspector while the run is active
69
+ /workflow:inspector # open the current or last 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
69
73
  ```
70
74
 
71
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`:
@@ -78,15 +82,17 @@ Opt into dynamic multi-agent orchestration with the literal `dynamax` token, or
78
82
 
79
83
  ```text
80
84
  dynamax inspect this bug with multiple focused agents
81
- /dynamax on
82
- /dynamax status
83
- /dynamax off
85
+ /workflow:dynamax on
86
+ /workflow:dynamax status
87
+ /workflow:dynamax off
84
88
  ```
85
89
 
86
- `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.
90
+ `dynamax` is a one-shot 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. Dynamax workflow-tool runs open the live workflow inspector in the TUI while they run. `/workflow:dynamax on|off|status` controls sticky mode, and `/hotkeys` shows the registered inspector shortcut (`ctrl+shift+m` by default). Sticky mode, one-shot pending mode, and active Dynamax workflow runs show compact status with the relevant commands while active and leave no persistent UI when cleared. 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.
87
91
 
88
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.
89
93
 
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`.
95
+
90
96
  ## Built-in workflows
91
97
 
92
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.
@@ -104,6 +110,22 @@ The bundled review workflow is deliberately shaped like a serious review process
104
110
  4. **Verify**: send each survivor to an independent verifier that must confirm, mark plausible, or refute with evidence.
105
111
  5. **Synthesize**: produce one ranked report with stats, verdicts, and concrete locations.
106
112
 
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` during or after a run to open the workflow inspector.
114
+
115
+ Viewer controls:
116
+
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.
126
+
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.
128
+
107
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.
108
130
 
109
131
  ## Authoring workflows
@@ -172,7 +194,7 @@ Under the hood:
172
194
  - **Each `agent()` is an in-process pi `AgentSession`** using `createAgentSession` and `SessionManager.inMemory()`.
173
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.
174
196
  - **A single global semaphore caps concurrent agents**, so `parallel` and `pipeline` can nest freely while every `agent()` call still respects the run cap.
175
- - **Three surfaces are registered**: `/workflow <name> [args]` for direct use, `/dynamax on|off|status` for sticky orchestration opt-in, and a `workflow` tool for host-agent delegation by `name` or inline `script`.
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`.
176
198
 
177
199
  ## Local development
178
200
 
@@ -186,7 +208,7 @@ bun run typecheck
186
208
  bun run test
187
209
  ```
188
210
 
189
- The test suite is no-LLM and uses Bun's built-in `bun test` runner, not a third-party test framework.
211
+ Typechecking uses TypeScript Native Preview (`tsgo`) through `bun run typecheck`. The test suite is no-LLM and uses Bun's built-in `bun test` runner, not a third-party test framework.
190
212
 
191
213
  ### Performance controls and benchmarks
192
214
 
package/USAGE.md CHANGED
@@ -1,9 +1,10 @@
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 multi-agent workflows to pi. Most users only need these surfaces:
4
4
 
5
5
  - `/workflow <name> [args]` to run a saved workflow directly.
6
- - `dynamax` when you want the host agent to author a one-off inline workflow for investigation/review.
6
+ - `/workflow:*` commands for related actions such as inspector reopening and Dynamax control.
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.
7
8
 
8
9
  ## Run a workflow
9
10
 
@@ -22,7 +23,10 @@ The built-in workflows are advisory. They inspect, verify, and report; they do *
22
23
  Useful flags:
23
24
 
24
25
  ```text
25
- /workflow code-review --inspect # show live inspector
26
+ /workflow code-review --inspect # show the live inspector while the run is active
27
+ /workflow:inspector # open the current or last workflow inspector
28
+ /workflow code-review --result-viewer # explicitly open the findings viewer
29
+ /workflow code-review --review-viewer # alias for --result-viewer
26
30
  /workflow code-review --concurrency=4 # cap concurrent subagents
27
31
  /workflow code-review --refresh # rediscover newly added workflow files
28
32
  ```
@@ -54,15 +58,33 @@ dynamax create a one-off workflow to compare the parser and tests before we chan
54
58
  dynamax use parallel agents to review this design and report the risks
55
59
  ```
56
60
 
57
- Sticky for the session:
61
+ Sticky mode and inspector shortcut:
58
62
 
59
63
  ```text
60
- /dynamax on
61
- /dynamax off
62
- /dynamax status
64
+ /workflow:dynamax on
65
+ /workflow:dynamax off
66
+ /workflow:dynamax status
63
67
  ```
64
68
 
65
- 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. It can still call a saved workflow by `name` when one already fits.
66
88
 
67
89
  ## Workflow results
68
90
 
@@ -75,7 +97,9 @@ Workflow results are rendered in pi with:
75
97
  - next steps;
76
98
  - run stats when available.
77
99
 
78
- During a run, pi shows live phases and subagent status. Use `--inspect` if you want a larger live view.
100
+ 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.
101
+
102
+ Code-review findings are rendered as a formatted result message by default. pi no longer asks whether to open the findings viewer. Use `--result-viewer` or `--review-viewer` when you want to inspect findings interactively, press `enter` to expand/collapse the nicely formatted finding text, and use `1`-`9` to jump directly to a visible finding.
79
103
 
80
104
  ## Author a saved workflow
81
105
 
@@ -115,9 +139,23 @@ Core primitives:
115
139
  | `pipeline(items, ...stages)` | Runs each item through stages independently. |
116
140
  | `phase(title)` / `log(message)` | Updates workflow progress UI. |
117
141
  | `progress(event)` | Emits counters, summaries, and lane items. |
142
+ | `workflow(ref, args?)` | Runs another workflow inline as a sub-step and returns its result. |
118
143
 
119
144
  Set `thinkingLevel` on fan-out agents. Otherwise many subagents can inherit an expensive global reasoning level.
120
145
 
146
+ ### Compose workflows
147
+
148
+ `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.
149
+
150
+ ```ts
151
+ export default async function run({ workflow }: WorkflowApi) {
152
+ const review = await workflow("code-review", "HEAD~3");
153
+ return { review };
154
+ }
155
+ ```
156
+
157
+ 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).
158
+
121
159
  ### Where workflows live
122
160
 
123
161
  Guaranteed built-ins are statically registered:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-workflow-engine",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "A customisable multi-agent workflow-orchestration engine for the pi coding agent.",
6
6
  "keywords": [
@@ -23,18 +23,20 @@
23
23
  "files": [
24
24
  ".pi/extensions/pi-workflow-engine",
25
25
  ".pi/settings.json",
26
- "assets",
26
+ "assets/preview.png",
27
+ "skills",
27
28
  "README.md",
28
29
  "USAGE.md",
29
30
  "LICENSE"
30
31
  ],
31
32
  "pi": {
32
33
  "extensions": [".pi/extensions/pi-workflow-engine/index.ts"],
34
+ "skills": ["skills"],
33
35
  "image": "https://raw.githubusercontent.com/timbrinded/pi-workflow-engine/master/assets/preview.png"
34
36
  },
35
37
  "scripts": {
36
- "typecheck": "tsc --noEmit",
37
- "test": "bun test",
38
+ "typecheck": "tsgo --noEmit",
39
+ "test": "bun test --timeout=30000",
38
40
  "test:changedlines": "bun test tests/changedlines.test.ts",
39
41
  "test:concurrency": "bun test tests/concurrency.test.ts",
40
42
  "test:smoke": "bun test tests/discovery.test.ts",
@@ -44,7 +46,7 @@
44
46
  "bench:discovery": "bun run scripts/bench/discovery.ts",
45
47
  "bench:startup": "bun run scripts/bench/startup.ts",
46
48
  "bench:ui": "bun run scripts/bench/ui.ts",
47
- "prepublishOnly": "tsc --noEmit && bun run test"
49
+ "prepublishOnly": "tsgo --noEmit && bun run test"
48
50
  },
49
51
  "peerDependencies": {
50
52
  "@earendil-works/pi-agent-core": "*",
@@ -55,6 +57,6 @@
55
57
  },
56
58
  "devDependencies": {
57
59
  "@types/node": "^22",
58
- "typescript": "^5.6.0"
60
+ "@typescript/native-preview": "^7.0.0-dev.20260615.1"
59
61
  }
60
62
  }
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: workflow-code-review-actions
3
+ description: "Act on selected code-review findings from pi-workflow-engine: make minimal fixes or post GitHub PR inline comments using gh, GitHub MCP/tools, or project-specific tools."
4
+ ---
5
+
6
+ Use this skill when the parent agent receives selected code-review finding JSON from `pi-workflow-engine`.
7
+
8
+ ## Inputs
9
+
10
+ The prompt will include compact JSON with:
11
+
12
+ - `context`: workflow name, target, diff command, changed files, and optional summary.
13
+ - `issues`: selected findings with `id`, `summary`, `category`, `severity`, `confidence`, `location`, `impact`, `evidence`, and `recommendation`.
14
+
15
+ ## Fix mode
16
+
17
+ When mode is `fix selected code-review findings`:
18
+
19
+ 1. Inspect the selected issue JSON before editing.
20
+ 2. Make minimal edits that address only the selected findings.
21
+ 3. Preserve unrelated user changes and avoid broad refactors.
22
+ 4. Run focused validation if available for the touched files or behavior.
23
+ 5. Summarize changed files and validation results.
24
+ 6. Do not post GitHub PR comments in fix mode.
25
+
26
+ ## Comment mode
27
+
28
+ When mode is `post inline GitHub PR comments`:
29
+
30
+ 1. Do not edit files or make code changes.
31
+ 2. Prefer installed GitHub MCP/tools if visible in the active tool list.
32
+ 3. If no GitHub MCP/tools are available, use `gh`:
33
+ - Resolve the PR with `gh pr view --json number,headRefOid,url,headRepositoryOwner,headRepository`.
34
+ - Resolve the repository with `gh repo view --json nameWithOwner` when owner/name is missing.
35
+ - Post each inline comment with `gh api repos/{owner}/{repo}/pulls/{number}/comments` and include `commit_id`, `path`, `line`, and `side=RIGHT`.
36
+ 4. Keep each comment concise: summary, severity/confidence/category, impact, evidence, and recommendation.
37
+ 5. Report posted, skipped, and failed counts.
38
+
39
+ ## Safety rules
40
+
41
+ - Do not post duplicate comments.
42
+ - Do not comment line-less findings inline.
43
+ - Ask the user if the upstream PR cannot be identified.
44
+ - Keep actions scoped to the selected issue IDs only.
Binary file