@tianhai/pi-workflow-kit 0.4.1 → 0.5.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
@@ -90,7 +90,7 @@ No configuration required after install. Skills and extensions activate automati
90
90
 
91
91
  ## Upgrading from `pi-superpowers`
92
92
 
93
- If you're currently using [`pi-superpowers`](https://github.com/coctostan/pi-superpowers), `@tianhai/pi-workflow-kit` is intended as a drop-in upgrade: you keep the same skill names and workflow, but you also get **active, runtime enforcement** via extensions.
93
+ If you're currently using `pi-superpowers`, `@tianhai/pi-workflow-kit` is intended as a drop-in upgrade: you keep the same skill names and workflow, but you also get **active, runtime enforcement** via extensions.
94
94
 
95
95
  ### What stays the same
96
96
  - The same core workflow skills (e.g. `/skill:brainstorming`, `/skill:writing-plans`, `/skill:executing-tasks`, etc.)
@@ -232,7 +232,8 @@ At phase boundaries, prompts the agent once (non-enforcing) with options:
232
232
 
233
233
  When transitioning into **finalize**, the monitor pre-fills the editor with a reminder to consider documentation updates and to capture learnings before merging/shipping.
234
234
 
235
- The `/workflow-next` command starts a new session with artifact context:
235
+ The `/workflow-next` command starts a new session with artifact context and enforces immediate-next-only handoff:
236
+
236
237
  ```
237
238
  /workflow-next plan docs/plans/2026-02-10-my-feature-design.md
238
239
  /workflow-next execute docs/plans/2026-02-11-my-feature-implementation.md
@@ -241,6 +242,13 @@ The `/workflow-next` command starts a new session with artifact context:
241
242
 
242
243
  Valid phases: `brainstorm`, `plan`, `execute`, `finalize`.
243
244
 
245
+ Handoff rules:
246
+ - Only the **immediate next** phase is allowed (e.g. `plan → execute`, `execute → finalize`).
247
+ - The current phase must be **complete** before handing off.
248
+ - Same-phase, backward, and direct-jump transitions are rejected.
249
+ - Prior completed phases, artifacts, and prompted flags are **preserved** in the new session.
250
+ - TDD, debug, and verification state start **fresh** in the new session.
251
+
244
252
  #### Reference Tool
245
253
 
246
254
  Serves detailed guidance on demand, keeping skill files lean while making reference content available when the agent needs it:
@@ -306,6 +314,16 @@ A bundled `subagent` tool lets the orchestrating agent spawn isolated subprocess
306
314
 
307
315
  Agent definitions live in `agents/*.md` and use YAML frontmatter to declare tools, model, extensions, and a system prompt body.
308
316
 
317
+ ### Model Selection Precedence
318
+
319
+ When the `subagent` tool launches a child `pi` process, it resolves the model in this order:
320
+
321
+ 1. Agent frontmatter `model:`
322
+ 2. The parent session's current provider + model
323
+ 3. Bundled fallback `DEFAULT_MODEL`
324
+
325
+ If a subagent inherits the parent session model, Pi passes both `--provider` and `--model` to the child process to avoid ambiguous cross-provider lookups.
326
+
309
327
  ### Single Agent
310
328
 
311
329
  ```ts
@@ -350,11 +368,17 @@ extensions: ../extensions/my-guard.ts
350
368
  System prompt body here.
351
369
  ```
352
370
 
371
+ If `model:` is omitted, the agent will inherit the parent session's current model when available, and only fall back to the bundled default if there is no active session model.
372
+
373
+ ### Troubleshooting
374
+
375
+ If a bundled reviewer or worker unexpectedly asks for the wrong provider credentials, check whether the agent is explicitly pinned with `model:`. Unpinned agents now inherit the parent session's current model, which avoids cases where a non-Anthropic session accidentally launched a Claude-based subagent and failed with an Anthropic API key error.
376
+
353
377
  ## Compared to Superpowers
354
378
 
355
- Based on [Superpowers](https://github.com/obra/superpowers) by Jesse Vincent, ported to pi as [pi-superpowers](https://github.com/coctostan/pi-superpowers), then extended with active enforcement.
379
+ Based on [Superpowers](https://github.com/obra/superpowers) by Jesse Vincent, ported to pi as `pi-superpowers`, then extended with active enforcement.
356
380
 
357
- | | [Superpowers](https://github.com/obra/superpowers) | [pi-superpowers](https://github.com/coctostan/pi-superpowers) | **pi-workflow-kit** |
381
+ | | [Superpowers](https://github.com/obra/superpowers) | `pi-superpowers` | **pi-workflow-kit** |
358
382
  |---|---|---|---|
359
383
  | **Platform** | Claude Code | pi | pi |
360
384
  | **Skills** | 8 workflow skills | Same 12 skills (pi port) → now 8 skills (simplified workflow) | **8 skills** (simplified: 4-phase workflow with unified executing-tasks) |
@@ -485,7 +509,7 @@ pi install npm:@tianhai/pi-workflow-kit
485
509
 
486
510
  ## Attribution
487
511
 
488
- Skill content adapted from [Superpowers](https://github.com/obra/superpowers) by Jesse Vincent (MIT). This package builds on [pi-superpowers](https://github.com/coctostan/pi-superpowers) with active enforcement extensions, leaner skill files, on-demand reference content, and workflow tracking.
512
+ Skill content adapted from [Superpowers](https://github.com/obra/superpowers) by Jesse Vincent (MIT). This package builds on `pi-superpowers` with active enforcement extensions, leaner skill files, on-demand reference content, and workflow tracking.
489
513
 
490
514
  ## Migration from `@yinlootan/pi-superpowers-plus`
491
515
 
@@ -120,10 +120,9 @@ Invoke skills directly in the Pi session:
120
120
 
121
121
  ### Workflow handoff
122
122
 
123
- Start a fresh session for the next phase:
123
+ Start a fresh session for the next phase. `/workflow-next` enforces immediate-next-only transitions and preserves prior completed workflow history (phases, artifacts, prompted flags) across the handoff:
124
124
 
125
125
  ```text
126
- /workflow-next brainstorm
127
126
  /workflow-next plan docs/plans/2026-04-09-feature-design.md
128
127
  /workflow-next execute docs/plans/2026-04-09-feature-implementation.md
129
128
  /workflow-next finalize docs/plans/2026-04-09-feature-implementation.md
@@ -426,7 +425,7 @@ pi install npm:@tianhai/pi-workflow-kit
426
425
  - Let `plan_tracker` reflect the real lifecycle instead of keeping state only in chat
427
426
  - Use `subagent(..., agentScope: "both")` when you want bundled agents
428
427
  - Treat workflow monitor warnings as signals to correct process, not as noise
429
- - Use `/workflow-next` when handing off between large phases or sessions
428
+ - Use `/workflow-next` when handing off between sequential workflow phases
430
429
 
431
430
  ## Common mistakes to avoid
432
431
 
@@ -439,7 +438,7 @@ pi install npm:@tianhai/pi-workflow-kit
439
438
 
440
439
  ## Migration note
441
440
 
442
- If you previously installed `@yinlootan/pi-superpowers-plus`, replace it with:
441
+ If you previously installed `@yinlootan/pi-superpowers-plus`, replace it with `@tianhai/pi-workflow-kit`:
443
442
 
444
443
  ```json
445
444
  {
@@ -0,0 +1,185 @@
1
+ # /workflow-next Autocomplete Design
2
+
3
+ Date: 2026-04-09
4
+
5
+ ## Summary
6
+
7
+ Add argument autocomplete to the `/workflow-next` extension command so the workflow phase is easier to enter and the optional artifact argument is easier to discover.
8
+
9
+ The command should support:
10
+ - phase autocomplete for `brainstorm`, `plan`, `execute`, and `finalize`
11
+ - workflow-aware artifact suggestions after a valid phase is entered
12
+ - strict phase-to-artifact mapping:
13
+ - `plan` → `docs/plans/*-design.md`
14
+ - `execute` → `docs/plans/*-implementation.md`
15
+ - `finalize` → `docs/plans/*-implementation.md`
16
+ - `brainstorm` → no artifact suggestions
17
+
18
+ This is a UX-only improvement. It must not change workflow tracking, session creation, or `/workflow-next` validation behavior.
19
+
20
+ ## Goals
21
+
22
+ - Make `/workflow-next` faster and less error-prone to use
23
+ - Surface valid workflow phases directly in slash-command autocomplete
24
+ - Suggest likely plan artifacts without requiring users to remember exact filenames
25
+ - Keep runtime behavior unchanged outside command completion
26
+
27
+ ## Non-goals
28
+
29
+ - Infer suggestions from workflow tracker state
30
+ - Change `/workflow-next` command semantics or validation
31
+ - Add artifact suggestions for `brainstorm`
32
+ - Implement broad filesystem completion beyond workflow-specific plan artifacts
33
+
34
+ ## Recommended Approach
35
+
36
+ Keep command registration in `extensions/workflow-monitor.ts`, but extract completion logic into a focused helper module, e.g.:
37
+
38
+ - `extensions/workflow-monitor/workflow-next-completions.ts`
39
+
40
+ This helper should be stateless and filesystem-based. It should accept the raw argument prefix and return command completion items using pi's `getArgumentCompletions` hook.
41
+
42
+ This keeps the command registration simple while making the completion logic independently testable and easier to maintain than inline logic inside the already-large workflow monitor extension.
43
+
44
+ ## Architecture
45
+
46
+ ### Command registration
47
+
48
+ The existing `/workflow-next` command remains the single public entry point.
49
+
50
+ Enhance its registration with `getArgumentCompletions(prefix)`.
51
+
52
+ Responsibilities stay split as follows:
53
+ - `handler(args, ctx)` remains the source of truth for execution and validation
54
+ - `getArgumentCompletions(prefix)` provides UX hints only
55
+ - completion helper handles parsing, matching, and file discovery
56
+
57
+ ### Completion helper
58
+
59
+ The helper module should expose a small API, such as:
60
+ - a list of valid workflow phases
61
+ - a function that returns completion items for a raw argument prefix
62
+
63
+ Internally it should:
64
+ 1. determine whether the user is completing the first argument or second argument
65
+ 2. return filtered phase suggestions when completing the first argument
66
+ 3. after an exact valid phase is present, return artifact suggestions based on strict phase mapping
67
+ 4. return `null` when no suggestions are appropriate
68
+
69
+ ## Components
70
+
71
+ ### 1. Phase completion
72
+
73
+ Supported phases:
74
+ - `brainstorm`
75
+ - `plan`
76
+ - `execute`
77
+ - `finalize`
78
+
79
+ Behavior:
80
+ - empty prefix returns all phases
81
+ - partial first token returns phases filtered by prefix
82
+ - invalid first token still returns matching phase suggestions when possible
83
+ - phase completion applies only to the first argument
84
+
85
+ ### 2. Artifact completion
86
+
87
+ Artifact suggestions activate only after the first token exactly matches a valid phase and the user begins the second argument.
88
+
89
+ Strict mapping:
90
+ - `plan` → only files under `docs/plans/` ending in `-design.md`
91
+ - `execute` → only files under `docs/plans/` ending in `-implementation.md`
92
+ - `finalize` → only files under `docs/plans/` ending in `-implementation.md`
93
+ - `brainstorm` → no artifact suggestions
94
+
95
+ Returned suggestions should use relative paths such as:
96
+ - `docs/plans/2026-04-09-feature-design.md`
97
+ - `docs/plans/2026-04-09-feature-implementation.md`
98
+
99
+ ### 3. Filesystem discovery
100
+
101
+ Artifact completion should scan `docs/plans/` in the current working directory and filter matching filenames by suffix and typed prefix.
102
+
103
+ The logic should be conservative:
104
+ - if `docs/plans/` does not exist, return `null`
105
+ - if no files match the required suffix, return `null`
106
+ - if a typed artifact prefix narrows the set, return only matching entries
107
+
108
+ No workflow-state coupling is needed.
109
+
110
+ ## Data flow
111
+
112
+ 1. User types `/workflow-next ...`
113
+ 2. pi invokes `getArgumentCompletions(prefix)` for the command
114
+ 3. the completion helper parses the raw argument prefix
115
+ 4. helper decides between phase mode and artifact mode
116
+ 5. helper returns:
117
+ - phase suggestions, or
118
+ - matching artifact path suggestions, or
119
+ - `null`
120
+ 6. user selects a suggestion
121
+ 7. existing `/workflow-next` handler runs unchanged when the command is submitted
122
+
123
+ This preserves a clean separation: autocomplete assists input, while the handler remains authoritative for correctness.
124
+
125
+ ## Error handling
126
+
127
+ The completion path should fail quietly.
128
+
129
+ Expected behavior:
130
+ - missing `docs/plans/` → no suggestions
131
+ - unreadable directory or filesystem error → no suggestions
132
+ - `brainstorm` second argument → no suggestions
133
+ - invalid phase token → stay in phase suggestion mode instead of trying artifact inference
134
+
135
+ The command handler should continue to enforce valid usage and show the existing error message for invalid submitted phases.
136
+
137
+ ## Testing strategy
138
+
139
+ Add focused tests around `/workflow-next` command registration and completion behavior.
140
+
141
+ Primary test coverage:
142
+ - no args returns all four phases
143
+ - partial phase like `pl` returns `plan`
144
+ - `plan ` suggests only `docs/plans/*-design.md`
145
+ - `execute ` suggests only `docs/plans/*-implementation.md`
146
+ - `finalize ` suggests only `docs/plans/*-implementation.md`
147
+ - `brainstorm ` returns no artifact suggestions
148
+ - artifact prefix filtering works for partial paths
149
+ - invalid first token stays in phase-suggestion mode
150
+ - missing `docs/plans/` returns `null`
151
+ - no matching files returns `null`
152
+
153
+ Implementation detail for tests:
154
+ - extend `tests/extension/workflow-monitor/workflow-next-command.test.ts`
155
+ - capture the registered command object, not just the handler
156
+ - create temporary `docs/plans/` fixtures in a temp cwd
157
+ - assert returned completion items directly
158
+
159
+ ## Risks and trade-offs
160
+
161
+ ### Chosen trade-off
162
+
163
+ Use strict workflow-specific suggestions instead of broad generic path completion.
164
+
165
+ Benefits:
166
+ - better guidance for the intended workflow
167
+ - faster selection of the right artifact files
168
+ - lower cognitive load for users
169
+
170
+ Cost:
171
+ - more custom logic than plain phase-only completion
172
+ - artifact matching rules must stay aligned with workflow naming conventions
173
+
174
+ ### Why not use workflow state
175
+
176
+ State-aware suggestions could be smarter, but they would add coupling to session state and create more edge cases. For this improvement, filesystem-based suggestions are sufficient and easier to reason about.
177
+
178
+ ## Acceptance criteria
179
+
180
+ - `/workflow-next` autocompletes phase names
181
+ - after a valid phase, artifact suggestions follow the strict mapping above
182
+ - suggestions are filtered by the typed prefix
183
+ - `brainstorm` does not suggest artifacts
184
+ - invalid submitted phases are still rejected by the handler
185
+ - existing `/workflow-next` behavior is otherwise unchanged
@@ -0,0 +1,334 @@
1
+ # /workflow-next Autocomplete Implementation Plan
2
+
3
+ > **REQUIRED SUB-SKILL:** Use the executing-tasks skill to implement this plan task-by-task.
4
+
5
+ **Goal:** Add argument autocomplete to `/workflow-next` for workflow phases and workflow-specific plan artifacts without changing command execution, validation, or session creation behavior.
6
+
7
+ **Architecture:** Add a small stateless helper module under `extensions/workflow-monitor/` that parses the raw argument prefix and returns `AutocompleteItem[] | null` from pi's `getArgumentCompletions` hook. Keep `extensions/workflow-monitor.ts` as the command registration entry point and leave the existing `/workflow-next` handler logic unchanged so autocomplete stays UX-only.
8
+
9
+ **Tech Stack:** TypeScript, Node.js `fs`/`path`, pi extension command API, Vitest
10
+
11
+ ---
12
+
13
+ Reference design artifact: `docs/plans/2026-04-09-workflow-next-autocomplete-design.md`
14
+
15
+ ### Task 1: Add phase autocomplete for `/workflow-next`
16
+
17
+ **Type:** code
18
+ **TDD scenario:** New feature — full TDD cycle
19
+
20
+ **Files:**
21
+ - Create: `extensions/workflow-monitor/workflow-next-completions.ts`
22
+ - Modify: `extensions/workflow-monitor.ts:1-38`
23
+ - Modify: `extensions/workflow-monitor.ts:813-851`
24
+ - Test: `tests/extension/workflow-monitor/workflow-next-command.test.ts:1-102`
25
+
26
+ **Step 1: Write the failing test**
27
+
28
+ ```ts
29
+ function getWorkflowNextCommand() {
30
+ let command: any;
31
+ const fakePi: any = {
32
+ on() {},
33
+ registerTool() {},
34
+ appendEntry() {},
35
+ registerCommand(name: string, opts: any) {
36
+ if (name === "workflow-next") command = opts;
37
+ },
38
+ };
39
+
40
+ workflowMonitorExtension(fakePi);
41
+ expect(command).toBeTruthy();
42
+ return command;
43
+ }
44
+
45
+ test("returns all workflow phases when no args are typed", async () => {
46
+ const command = getWorkflowNextCommand();
47
+ const items = await command.getArgumentCompletions("");
48
+ expect(items).toEqual([
49
+ { value: "brainstorm", label: "brainstorm" },
50
+ { value: "plan", label: "plan" },
51
+ { value: "execute", label: "execute" },
52
+ { value: "finalize", label: "finalize" },
53
+ ]);
54
+ });
55
+
56
+ test("keeps suggesting phases until the first arg is an exact valid phase", async () => {
57
+ const command = getWorkflowNextCommand();
58
+ const items = await command.getArgumentCompletions("pla docs/plans/");
59
+ expect(items).toEqual([{ value: "plan", label: "plan" }]);
60
+ });
61
+ ```
62
+
63
+ **Step 2: Run test to verify it fails**
64
+
65
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts -t "returns all workflow phases when no args are typed"`
66
+ Expected: FAIL with `command.getArgumentCompletions is not a function` or an equivalent assertion failure because `/workflow-next` does not expose completions yet.
67
+
68
+ **Step 3: Write minimal implementation**
69
+
70
+ ```ts
71
+ // extensions/workflow-monitor/workflow-next-completions.ts
72
+ import type { AutocompleteItem } from "@mariozechner/pi-tui";
73
+
74
+ const WORKFLOW_NEXT_PHASES = ["brainstorm", "plan", "execute", "finalize"] as const;
75
+
76
+ export async function getWorkflowNextCompletions(prefix: string): Promise<AutocompleteItem[] | null> {
77
+ const normalized = prefix.replace(/^\s+/, "");
78
+ const [firstToken = ""] = normalized.split(/\s+/, 1);
79
+ const completingFirstArg = normalized.length === 0 || !/\s/.test(normalized);
80
+
81
+ if (completingFirstArg || !WORKFLOW_NEXT_PHASES.includes(firstToken as (typeof WORKFLOW_NEXT_PHASES)[number])) {
82
+ const phasePrefix = completingFirstArg ? normalized : firstToken;
83
+ const items = WORKFLOW_NEXT_PHASES.filter((phase) => phase.startsWith(phasePrefix)).map((phase) => ({
84
+ value: phase,
85
+ label: phase,
86
+ }));
87
+ return items.length > 0 ? items : null;
88
+ }
89
+
90
+ return null;
91
+ }
92
+
93
+ // extensions/workflow-monitor.ts
94
+ pi.registerCommand("workflow-next", {
95
+ description: "Start a fresh session for the next workflow phase (optionally referencing an artifact path)",
96
+ getArgumentCompletions: getWorkflowNextCompletions,
97
+ async handler(args, ctx) {
98
+ // existing handler body stays unchanged
99
+ },
100
+ });
101
+ ```
102
+
103
+ **Step 4: Run test to verify it passes**
104
+
105
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts -t "workflow phases"`
106
+ Expected: PASS for the new phase-autocomplete assertions and PASS for the existing kickoff/validation tests.
107
+
108
+ **Step 5: Commit**
109
+
110
+ ```bash
111
+ git add tests/extension/workflow-monitor/workflow-next-command.test.ts extensions/workflow-monitor.ts extensions/workflow-monitor/workflow-next-completions.ts
112
+ git commit -m "feat: add workflow-next phase autocomplete"
113
+ ```
114
+
115
+ ### Task 2: Add `plan` artifact suggestions for design docs
116
+
117
+ **Type:** code
118
+ **TDD scenario:** New feature — full TDD cycle
119
+
120
+ **Files:**
121
+ - Modify: `extensions/workflow-monitor/workflow-next-completions.ts`
122
+ - Test: `tests/extension/workflow-monitor/workflow-next-command.test.ts:1-102`
123
+
124
+ **Step 1: Write the failing test**
125
+
126
+ ```ts
127
+ import * as fs from "node:fs";
128
+ import * as path from "node:path";
129
+ import { withTempCwd } from "./test-helpers";
130
+
131
+ test("suggests only design artifacts for plan phase", async () => {
132
+ const tempDir = withTempCwd();
133
+ const plansDir = path.join(tempDir, "docs", "plans");
134
+ fs.mkdirSync(plansDir, { recursive: true });
135
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-design.md"), "");
136
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-implementation.md"), "");
137
+
138
+ const command = getWorkflowNextCommand();
139
+ const items = await command.getArgumentCompletions("plan ");
140
+
141
+ expect(items).toEqual([
142
+ {
143
+ value: "docs/plans/2026-04-09-alpha-design.md",
144
+ label: "docs/plans/2026-04-09-alpha-design.md",
145
+ },
146
+ ]);
147
+ });
148
+
149
+ test("filters plan artifact suggestions by typed prefix", async () => {
150
+ const tempDir = withTempCwd();
151
+ const plansDir = path.join(tempDir, "docs", "plans");
152
+ fs.mkdirSync(plansDir, { recursive: true });
153
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-design.md"), "");
154
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-beta-design.md"), "");
155
+
156
+ const command = getWorkflowNextCommand();
157
+ const items = await command.getArgumentCompletions("plan docs/plans/2026-04-09-al");
158
+
159
+ expect(items).toEqual([
160
+ {
161
+ value: "docs/plans/2026-04-09-alpha-design.md",
162
+ label: "docs/plans/2026-04-09-alpha-design.md",
163
+ },
164
+ ]);
165
+ });
166
+ ```
167
+
168
+ **Step 2: Run test to verify it fails**
169
+
170
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts -t "design artifacts for plan phase"`
171
+ Expected: FAIL because phase completion works, but second-argument artifact completion still returns `null`.
172
+
173
+ **Step 3: Write minimal implementation**
174
+
175
+ ```ts
176
+ import * as fs from "node:fs";
177
+ import * as path from "node:path";
178
+ import type { AutocompleteItem } from "@mariozechner/pi-tui";
179
+
180
+ function listPlanArtifacts(suffix: string, typedPrefix: string): AutocompleteItem[] | null {
181
+ const plansDir = path.join(process.cwd(), "docs", "plans");
182
+ if (!fs.existsSync(plansDir)) return null;
183
+
184
+ const items = fs
185
+ .readdirSync(plansDir)
186
+ .filter((name) => name.endsWith(suffix))
187
+ .map((name) => path.join("docs", "plans", name))
188
+ .filter((relPath) => relPath.startsWith(typedPrefix))
189
+ .map((relPath) => ({ value: relPath, label: relPath }));
190
+
191
+ return items.length > 0 ? items : null;
192
+ }
193
+
194
+ export async function getWorkflowNextCompletions(prefix: string): Promise<AutocompleteItem[] | null> {
195
+ // keep task-1 phase behavior
196
+ const match = prefix.replace(/^\s+/, "").match(/^(\S+)(?:\s+(.*))?$/);
197
+ const phase = match?.[1] ?? "";
198
+ const artifactPrefix = match?.[2] ?? "";
199
+ const startingSecondArg = /\s$/.test(prefix) || artifactPrefix.length > 0;
200
+
201
+ if (phase === "plan" && startingSecondArg) {
202
+ return listPlanArtifacts("-design.md", artifactPrefix);
203
+ }
204
+
205
+ return previousPhaseLogic(prefix);
206
+ }
207
+ ```
208
+
209
+ **Step 4: Run test to verify it passes**
210
+
211
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts -t "plan"`
212
+ Expected: PASS for the new `plan` artifact tests and PASS for the phase completion tests from Task 1.
213
+
214
+ **Step 5: Commit**
215
+
216
+ ```bash
217
+ git add tests/extension/workflow-monitor/workflow-next-command.test.ts extensions/workflow-monitor/workflow-next-completions.ts
218
+ git commit -m "feat: add workflow-next plan artifact autocomplete"
219
+ ```
220
+
221
+ ### Task 3: Complete execute/finalize artifact mapping and quiet failure behavior
222
+
223
+ **Type:** code
224
+ **TDD scenario:** New feature — full TDD cycle
225
+
226
+ **Files:**
227
+ - Modify: `extensions/workflow-monitor/workflow-next-completions.ts`
228
+ - Test: `tests/extension/workflow-monitor/workflow-next-command.test.ts:1-102`
229
+
230
+ **Step 1: Write the failing test**
231
+
232
+ ```ts
233
+ test("suggests only implementation artifacts for execute and finalize", async () => {
234
+ const tempDir = withTempCwd();
235
+ const plansDir = path.join(tempDir, "docs", "plans");
236
+ fs.mkdirSync(plansDir, { recursive: true });
237
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-design.md"), "");
238
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-implementation.md"), "");
239
+
240
+ const command = getWorkflowNextCommand();
241
+
242
+ await expect(command.getArgumentCompletions("execute ")).resolves.toEqual([
243
+ {
244
+ value: "docs/plans/2026-04-09-alpha-implementation.md",
245
+ label: "docs/plans/2026-04-09-alpha-implementation.md",
246
+ },
247
+ ]);
248
+
249
+ await expect(command.getArgumentCompletions("finalize ")).resolves.toEqual([
250
+ {
251
+ value: "docs/plans/2026-04-09-alpha-implementation.md",
252
+ label: "docs/plans/2026-04-09-alpha-implementation.md",
253
+ },
254
+ ]);
255
+ });
256
+
257
+ test("returns null for brainstorm artifact completion", async () => {
258
+ const command = getWorkflowNextCommand();
259
+ await expect(command.getArgumentCompletions("brainstorm ")).resolves.toBeNull();
260
+ });
261
+
262
+ test("returns null when docs/plans is missing or has no matching files", async () => {
263
+ withTempCwd();
264
+ const command = getWorkflowNextCommand();
265
+ await expect(command.getArgumentCompletions("execute ")).resolves.toBeNull();
266
+
267
+ const plansDir = path.join(process.cwd(), "docs", "plans");
268
+ fs.mkdirSync(plansDir, { recursive: true });
269
+ fs.writeFileSync(path.join(plansDir, "2026-04-09-alpha-design.md"), "");
270
+ await expect(command.getArgumentCompletions("execute ")).resolves.toBeNull();
271
+ });
272
+ ```
273
+
274
+ **Step 2: Run test to verify it fails**
275
+
276
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts -t "implementation artifacts for execute and finalize"`
277
+ Expected: FAIL because only `plan` artifact completion exists and `execute`/`finalize` still return `null`.
278
+
279
+ **Step 3: Write minimal implementation**
280
+
281
+ ```ts
282
+ const ARTIFACT_SUFFIX_BY_PHASE = {
283
+ brainstorm: null,
284
+ plan: "-design.md",
285
+ execute: "-implementation.md",
286
+ finalize: "-implementation.md",
287
+ } as const;
288
+
289
+ function listArtifactsForPhase(phase: keyof typeof ARTIFACT_SUFFIX_BY_PHASE, typedPrefix: string) {
290
+ const suffix = ARTIFACT_SUFFIX_BY_PHASE[phase];
291
+ if (!suffix) return null;
292
+
293
+ const plansDir = path.join(process.cwd(), "docs", "plans");
294
+ if (!fs.existsSync(plansDir)) return null;
295
+
296
+ try {
297
+ const items = fs
298
+ .readdirSync(plansDir)
299
+ .filter((name) => name.endsWith(suffix))
300
+ .map((name) => path.join("docs", "plans", name))
301
+ .filter((relPath) => relPath.startsWith(typedPrefix))
302
+ .map((relPath) => ({ value: relPath, label: relPath }));
303
+
304
+ return items.length > 0 ? items : null;
305
+ } catch {
306
+ return null;
307
+ }
308
+ }
309
+
310
+ export async function getWorkflowNextCompletions(prefix: string): Promise<AutocompleteItem[] | null> {
311
+ // keep task-1 phase completion logic for empty / partial / invalid first tokens
312
+ // switch to artifact mode only after an exact valid phase plus second-arg context
313
+ if (phaseIsExactlyValid && startingSecondArg) {
314
+ return listArtifactsForPhase(phase, artifactPrefix);
315
+ }
316
+
317
+ return phaseSuggestionsOrNull;
318
+ }
319
+ ```
320
+
321
+ **Step 4: Run test to verify it passes**
322
+
323
+ Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts`
324
+ Expected: PASS for all `/workflow-next` tests, including kickoff behavior, invalid-phase validation, phase autocomplete, artifact autocomplete, and quiet-null cases.
325
+
326
+ Then run: `npm test`
327
+ Expected: PASS across the full Vitest suite with no regressions in the workflow monitor extension.
328
+
329
+ **Step 5: Commit**
330
+
331
+ ```bash
332
+ git add tests/extension/workflow-monitor/workflow-next-command.test.ts extensions/workflow-monitor/workflow-next-completions.ts
333
+ git commit -m "feat: finish workflow-next artifact autocomplete"
334
+ ```