@tianhai/pi-workflow-kit 0.5.3 → 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.
Files changed (70) hide show
  1. package/README.md +50 -490
  2. package/docs/developer-usage-guide.md +41 -401
  3. package/docs/oversight-model.md +13 -34
  4. package/docs/plans/2026-04-11-finalizing-merge-options-design.md +33 -0
  5. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-design.md +50 -0
  6. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-implementation.md +98 -0
  7. package/docs/plans/completed/2026-04-11-finalizing-merge-options-design.md +33 -0
  8. package/docs/plans/completed/2026-04-11-finalizing-merge-options-implementation.md +75 -0
  9. package/docs/plans/completed/2026-04-11-workspace-setup-design.md +28 -0
  10. package/docs/plans/completed/2026-04-11-workspace-setup-implementation.md +57 -0
  11. package/docs/workflow-phases.md +32 -46
  12. package/extensions/workflow-guard.ts +67 -0
  13. package/package.json +3 -7
  14. package/skills/brainstorming/SKILL.md +20 -67
  15. package/skills/executing-tasks/SKILL.md +49 -214
  16. package/skills/finalizing/SKILL.md +67 -0
  17. package/skills/writing-plans/SKILL.md +29 -129
  18. package/ROADMAP.md +0 -16
  19. package/agents/code-reviewer.md +0 -18
  20. package/agents/config.ts +0 -5
  21. package/agents/implementer.md +0 -26
  22. package/agents/spec-reviewer.md +0 -13
  23. package/agents/worker.md +0 -17
  24. package/docs/plans/2026-04-10-brainstorming-boundary-enforcement-design.md +0 -60
  25. package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md +0 -56
  26. package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-implementation.md +0 -196
  27. package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-design.md +0 -185
  28. package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-implementation.md +0 -334
  29. package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-design.md +0 -251
  30. package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-implementation.md +0 -253
  31. package/extensions/constants.ts +0 -15
  32. package/extensions/lib/logging.ts +0 -138
  33. package/extensions/plan-tracker.ts +0 -508
  34. package/extensions/subagent/agents.ts +0 -144
  35. package/extensions/subagent/concurrency.ts +0 -52
  36. package/extensions/subagent/env.ts +0 -47
  37. package/extensions/subagent/index.ts +0 -1181
  38. package/extensions/subagent/lifecycle.ts +0 -25
  39. package/extensions/subagent/timeout.ts +0 -13
  40. package/extensions/workflow-monitor/debug-monitor.ts +0 -98
  41. package/extensions/workflow-monitor/git.ts +0 -31
  42. package/extensions/workflow-monitor/heuristics.ts +0 -58
  43. package/extensions/workflow-monitor/investigation.ts +0 -52
  44. package/extensions/workflow-monitor/reference-tool.ts +0 -42
  45. package/extensions/workflow-monitor/skip-confirmation.ts +0 -19
  46. package/extensions/workflow-monitor/tdd-monitor.ts +0 -137
  47. package/extensions/workflow-monitor/test-runner.ts +0 -37
  48. package/extensions/workflow-monitor/verification-monitor.ts +0 -61
  49. package/extensions/workflow-monitor/warnings.ts +0 -81
  50. package/extensions/workflow-monitor/workflow-handler.ts +0 -363
  51. package/extensions/workflow-monitor/workflow-next-completions.ts +0 -68
  52. package/extensions/workflow-monitor/workflow-next-state.ts +0 -112
  53. package/extensions/workflow-monitor/workflow-tracker.ts +0 -286
  54. package/extensions/workflow-monitor/workflow-transitions.ts +0 -88
  55. package/extensions/workflow-monitor.ts +0 -909
  56. package/skills/dispatching-parallel-agents/SKILL.md +0 -194
  57. package/skills/receiving-code-review/SKILL.md +0 -196
  58. package/skills/systematic-debugging/SKILL.md +0 -170
  59. package/skills/systematic-debugging/condition-based-waiting-example.ts +0 -158
  60. package/skills/systematic-debugging/condition-based-waiting.md +0 -115
  61. package/skills/systematic-debugging/defense-in-depth.md +0 -122
  62. package/skills/systematic-debugging/find-polluter.sh +0 -63
  63. package/skills/systematic-debugging/reference/rationalizations.md +0 -61
  64. package/skills/systematic-debugging/root-cause-tracing.md +0 -169
  65. package/skills/test-driven-development/SKILL.md +0 -266
  66. package/skills/test-driven-development/reference/examples.md +0 -101
  67. package/skills/test-driven-development/reference/rationalizations.md +0 -67
  68. package/skills/test-driven-development/reference/when-stuck.md +0 -33
  69. package/skills/test-driven-development/testing-anti-patterns.md +0 -299
  70. package/skills/using-git-worktrees/SKILL.md +0 -231
@@ -1,60 +0,0 @@
1
- # Brainstorming Skill Boundary Enforcement
2
-
3
- **Date:** 2026-04-10
4
- **Status:** approved
5
-
6
- ## Problem
7
-
8
- The brainstorming skill's boundaries are advisory only — a quiet `## Boundaries` bullet list mid-file that the model reads then ignores once a task "feels" straightforward. There is no structural enforcement (pi doesn't implement `allowed-tools`, no tool-blocking extension API).
9
-
10
- In practice, `/skill:brainstorming` was invoked, the skill was loaded, and the agent immediately jumped to reading code, diagnosing the bug, and editing source files — violating every boundary.
11
-
12
- ## Design
13
-
14
- Two changes to `skills/brainstorming/SKILL.md`:
15
-
16
- ### 1. Add `allowed-tools` frontmatter
17
-
18
- ```yaml
19
- allowed-tools: read bash
20
- ```
21
-
22
- Pi doesn't parse this field yet, but:
23
- - It's part of the Agent Skills spec (experimental)
24
- - Future pi versions may inject it into the system prompt
25
- - Serves as machine-readable declaration of intent
26
- - Zero cost today
27
-
28
- ### 2. Replace quiet Boundaries section with prominent top-of-file block
29
-
30
- Move from a mid-file `## Boundaries` section to a visually distinct blockquote immediately after the `# Heading`, before the Overview:
31
-
32
- ```markdown
33
- > ⚠️ **BOUNDARY — DO NOT VIOLATE**
34
- >
35
- > This skill is **read-only exploration**. You MUST NOT use `edit` or `write` tools.
36
- > The only tools allowed are `read` and `bash` (for investigation only).
37
- >
38
- > - ✅ Read code and docs: yes
39
- > - ✅ Write to `docs/plans/`: yes (design documents only)
40
- > - ❌ Edit or create any other files: **absolutely no**
41
- >
42
- > If you find yourself reaching for `edit` or `write`, **stop**. Present what
43
- > you found as a design section and ask the user to approve it first.
44
- ```
45
-
46
- Key improvements over current form:
47
- - **Blockquote + warning emoji** — visually distinct from normal content
48
- - **"DO NOT VIOLATE"** — strong language models respond to
49
- - **Names forbidden tools explicitly** (`edit`, `write`) — no ambiguity
50
- - **Recovery instruction** — "stop, present what you found" — constructive next step
51
- - **Positioned at the top** — seen before the Overview, not buried mid-file
52
-
53
- ## Out of scope
54
-
55
- - Extension-level enforcement (requires pi core changes to support tool call interception)
56
- - Changing other skills' boundaries (this is a pattern, but brainstorming is the most frequently violated)
57
-
58
- ## Testing
59
-
60
- Manual verification: invoke `/skill:brainstorming`, confirm the model does not reach for `edit`/`write` during exploration.
@@ -1,56 +0,0 @@
1
- # Cleanup legacy state file and enforce thinking-phase boundaries
2
-
3
- Date: 2026-04-09
4
-
5
- ## Problem
6
-
7
- 1. **Legacy state file still read:** `workflow-monitor.ts` still has `getLegacyStateFilePath()` and a fallback read path for `.pi/superpowers-state.json`. The new filename (`workflow-kit-state.json`) is correct for writes, but the old one is still checked on read.
8
-
9
- 2. **Brainstorm/plan phases not enforced:** When the agent writes code during brainstorm or plan phase, the extension only warns (strike-based escalation allows first offense). The agent can ignore the warning and proceed with implementation work.
10
-
11
- 3. **`/workflow-next` tab completions lose the phase word:** When selecting a file artifact completion (e.g. `docs/plans/2026-04-09-foo-design.md`), pi replaces the entire argument prefix including the phase word. `/workflow-next plan des` → select file → `/workflow-next docs/plans/...` ("plan" gone).
12
-
13
- Note: Tab key does not trigger slash command argument completions at all (pi-side behavior — falls through to file path completion when `force=true`). Argument suggestions only appear on typing. This cannot be fixed on our side.
14
-
15
- ## Scope
16
-
17
- Three changes:
18
-
19
- ### 1. Remove `superpowers-state.json` legacy fallback
20
-
21
- **`extensions/workflow-monitor.ts`:**
22
- - Remove `getLegacyStateFilePath()` function
23
- - In `reconstructState()`, remove the `else if (stateFilePath === undefined)` branch that reads the legacy filename
24
-
25
- **`tests/extension/workflow-monitor/state-persistence.test.ts`:**
26
- - Update two tests in `"file-based state persistence"` describe that write/read `superpowers-state.json` to use `workflow-kit-state.json`
27
- - Fix test name `"getStateFilePath returns .pi/superpowers-state.json in cwd"`
28
- - Remove the `"state file rename to .pi/workflow-kit-state.json with legacy fallback"` describe block (4 tests) — this migration behavior no longer exists
29
-
30
- ### 2. Enforce brainstorm/plan phase boundaries
31
-
32
- **`extensions/workflow-monitor.ts`:**
33
- - Replace the `maybeEscalate("process", ctx)` call + `pendingProcessWarnings.set(...)` with an immediate `{ blocked: true, reason: ... }` return that includes a reminder about what the agent should be doing instead
34
- - Remove `"process"` from `ViolationBucket` type and `strikes` record (only `"practice"` remains, still used by TDD)
35
- - Remove `pendingProcessWarnings` map (no longer needed)
36
-
37
- ### 3. Fix phase word lost on artifact completion selection
38
-
39
- **`extensions/workflow-monitor/workflow-next-completions.ts`:**
40
- - In `listArtifactsForPhase`, prepend the phase to `item.value` so pi's prefix replacement preserves it:
41
- - `value: "plan docs/plans/2026-04-09-foo-design.md"` (replaces "plan des" → keeps "plan")
42
- - `label: "docs/plans/2026-04-09-foo-design.md"` (display stays clean)
43
- - Applies to all phases with artifacts: plan, execute, finalize
44
-
45
- ### Tests
46
-
47
- **`tests/extension/workflow-monitor/workflow-next-completions.test.ts`:**
48
- - Update artifact completion tests to expect `value` with phase prefix (e.g. `"plan docs/plans/..."`)
49
-
50
- ## What stays the same
51
-
52
- - `persistState()` already writes only to `.pi/workflow-kit-state.json` — no changes
53
- - `maybeEscalate()` stays (still used for `"practice"` / TDD violations)
54
- - The `isThinkingPhase` check (`phase === "brainstorm" || phase === "plan"`) already covers both phases — same treatment
55
- - `docs/plans/` writes remain allowed during brainstorm/plan phases
56
- - Tab not triggering argument completions is a pi-side issue — not in scope
@@ -1,196 +0,0 @@
1
- # Cleanup legacy state, enforce thinking phases, fix autocomplete
2
-
3
- > **REQUIRED SUB-SKILL:** Use the executing-tasks skill to implement this plan task-by-task.
4
-
5
- **Goal:** Remove legacy `superpowers-state.json` fallback, block non-plans writes during brainstorm/plan phases, and fix artifact completions losing the phase word.
6
-
7
- **Architecture:** Three independent changes in `workflow-monitor.ts` and `workflow-next-completions.ts` with corresponding test updates. Each change is self-contained.
8
-
9
- **Tech Stack:** TypeScript, Node.js, vitest, pi extension API
10
-
11
- ---
12
-
13
- ### Task 1: Remove `superpowers-state.json` legacy fallback
14
-
15
- **Type:** code
16
- **TDD scenario:** Modifying tested code — run existing tests first
17
-
18
- **Files:**
19
- - Modify: `extensions/workflow-monitor.ts:67-100`
20
- - Modify: `tests/extension/workflow-monitor/state-persistence.test.ts:274-500`
21
-
22
- **Step 1: Run existing state persistence tests**
23
-
24
- Run: `npx vitest run tests/extension/workflow-monitor/state-persistence.test.ts`
25
- Expected: All tests pass
26
-
27
- **Step 2: Remove `getLegacyStateFilePath` and legacy fallback in source**
28
-
29
- In `extensions/workflow-monitor.ts`:
30
-
31
- 1. Delete the `getLegacyStateFilePath` function (3 lines).
32
- 2. In `reconstructState`, simplify the file-read block — remove the `else if (stateFilePath === undefined)` branch that tries the legacy filename. The remaining code becomes:
33
-
34
- ```typescript
35
- if (stateFilePath !== false) {
36
- try {
37
- const statePath = stateFilePath ?? getStateFilePath();
38
- if (fs.existsSync(statePath)) {
39
- const raw = fs.readFileSync(statePath, "utf-8");
40
- fileData = JSON.parse(raw);
41
- }
42
- } catch (err) {
43
- log.warn(
44
- `Failed to read state file, falling back to session entries: ${err instanceof Error ? err.message : err}`,
45
- );
46
- }
47
- }
48
- ```
49
-
50
- **Step 3: Update tests**
51
-
52
- In `tests/extension/workflow-monitor/state-persistence.test.ts`:
53
-
54
- 1. Fix test name on line 274: `"getStateFilePath returns .pi/superpowers-state.json in cwd"` → `"getStateFilePath returns .pi/workflow-kit-state.json in cwd"`
55
- 2. On line 318: change `"superpowers-state.json"` → `"workflow-kit-state.json"`
56
- 3. On line 337: change `"superpowers-state.json"` → `"workflow-kit-state.json"`
57
- 4. Delete the entire `describe("state file rename to .pi/workflow-kit-state.json with legacy fallback", () => { ... })` block (4 tests, from line ~404 to ~530)
58
-
59
- **Step 4: Run tests**
60
-
61
- Run: `npx vitest run tests/extension/workflow-monitor/state-persistence.test.ts`
62
- Expected: All tests pass
63
-
64
- **Step 5: Run full test suite**
65
-
66
- Run: `npx vitest run`
67
- Expected: All tests pass
68
-
69
- **Step 6: Commit**
70
-
71
- ```bash
72
- git add extensions/workflow-monitor.ts tests/extension/workflow-monitor/state-persistence.test.ts
73
- git commit -m "refactor: remove superpowers-state.json legacy fallback"
74
- ```
75
-
76
- ---
77
-
78
- ### Task 2: Enforce brainstorm/plan phase boundaries (block immediately)
79
-
80
- **Type:** code
81
- **TDD scenario:** Modifying tested code — update existing tests first
82
-
83
- **Files:**
84
- - Modify: `extensions/workflow-monitor.ts:135-520`
85
- - Modify: `tests/extension/workflow-monitor/phase-aware-write-enforcement.test.ts`
86
-
87
- **Step 1: Run existing enforcement tests**
88
-
89
- Run: `npx vitest run tests/extension/workflow-monitor/phase-aware-write-enforcement.test.ts`
90
- Expected: All tests pass
91
-
92
- **Step 2: Update source — block immediately instead of escalating**
93
-
94
- In `extensions/workflow-monitor.ts`:
95
-
96
- 1. Remove `pendingProcessWarnings` map declaration (line ~135).
97
- 2. Change `ViolationBucket` type from `"process" | "practice"` to `"practice"`.
98
- 3. Change `strikes` from `{ process: 0, practice: 0 }` to `{ practice: 0 }`.
99
- 4. Change `sessionAllowed` type to `Partial<Record<"practice", boolean>>`.
100
- 5. In `maybeEscalate`, change parameter type from `ViolationBucket` to `"practice"`.
101
- 6. In `tool_result` handler, remove the `pendingProcessWarnings.get(toolCallId)` / `.delete(toolCallId)` block (3 lines).
102
- 7. In `tool_call` handler (~line 506-516), replace the `maybeEscalate("process", ctx)` + `pendingProcessWarnings.set(...)` block with:
103
-
104
- ```typescript
105
- return {
106
- blocked: true,
107
- reason:
108
- `⚠️ PROCESS VIOLATION: Wrote ${filePath} during ${phase} phase.\n` +
109
- "During brainstorming/planning you may only write to docs/plans/. " +
110
- "Read code and docs to understand the problem, then discuss the design before implementing.",
111
- };
112
- ```
113
-
114
- **Step 3: Update tests**
115
-
116
- In `tests/extension/workflow-monitor/phase-aware-write-enforcement.test.ts`:
117
-
118
- 1. The first test (`"warns when writing outside docs/plans during brainstorm"`) currently checks for an injected warning in the tool result. After the change, the write is blocked in `on_tool_call` before it executes, so `on_tool_result` is never reached. Replace the test to check that `onToolCall` returns `{ blocked: true }` with a `reason` containing `"PROCESS VIOLATION"` and `"brainstorm"`. Remove the `onToolResult` call and its assertion.
119
-
120
- 2. Add a new test: `"blocks immediately on first violation during plan phase"` — same pattern as brainstorm but with `currentPhase: "plan"`, verify `{ blocked: true, reason: expect.stringContaining("PROCESS VIOLATION") }`.
121
-
122
- 3. The test `"second process violation hard-blocks (interactive)"` is no longer relevant — blocking is immediate now. Delete it.
123
-
124
- **Step 4: Run enforcement tests**
125
-
126
- Run: `npx vitest run tests/extension/workflow-monitor/phase-aware-write-enforcement.test.ts`
127
- Expected: All tests pass
128
-
129
- **Step 5: Run full test suite**
130
-
131
- Run: `npx vitest run`
132
- Expected: All tests pass
133
-
134
- **Step 6: Commit**
135
-
136
- ```bash
137
- git add extensions/workflow-monitor.ts tests/extension/workflow-monitor/phase-aware-write-enforcement.test.ts
138
- git commit -m "feat: block writes outside docs/plans immediately during brainstorm/plan phases"
139
- ```
140
-
141
- ---
142
-
143
- ### Task 3: Fix artifact completions losing the phase word
144
-
145
- **Type:** code
146
- **TDD scenario:** Modifying tested code — update existing tests first
147
-
148
- **Files:**
149
- - Modify: `extensions/workflow-monitor/workflow-next-completions.ts:50-60`
150
- - Modify: `tests/extension/workflow-monitor/workflow-next-command.test.ts`
151
-
152
- **Step 1: Run existing completion tests**
153
-
154
- Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts`
155
- Expected: All tests pass
156
-
157
- **Step 2: Update source — prepend phase to artifact values**
158
-
159
- In `extensions/workflow-monitor/workflow-next-completions.ts`, in `listArtifactsForPhase`, the function needs the `phase` parameter included in `item.value`. Change the final `.map()`:
160
-
161
- ```typescript
162
- // Before:
163
- .map((relPath) => ({ value: relPath, label: relPath }));
164
-
165
- // After:
166
- .map((relPath) => ({ value: `${phase} ${relPath}`, label: relPath }));
167
- ```
168
-
169
- This ensures pi's `applyCompletion` replaces the full prefix (e.g. `"plan des"`) with `"plan docs/plans/..."` — preserving the phase word.
170
-
171
- **Step 3: Update tests**
172
-
173
- In `tests/extension/workflow-monitor/workflow-next-command.test.ts`, update these tests to expect `value` with the phase prefix:
174
-
175
- 1. `"suggests only design artifacts for plan phase"` — change `value: "docs/plans/..."` to `value: "plan docs/plans/..."`, keep `label` unchanged.
176
-
177
- 2. `"filters plan artifact suggestions by typed prefix"` — same value change.
178
-
179
- 3. `"suggests only implementation artifacts for execute and finalize"` — change execute value to `"execute docs/plans/..."` and finalize value to `"finalize docs/plans/..."`.
180
-
181
- **Step 4: Run completion tests**
182
-
183
- Run: `npx vitest run tests/extension/workflow-monitor/workflow-next-command.test.ts`
184
- Expected: All tests pass
185
-
186
- **Step 5: Run full test suite**
187
-
188
- Run: `npx vitest run`
189
- Expected: All tests pass
190
-
191
- **Step 6: Commit**
192
-
193
- ```bash
194
- git add extensions/workflow-monitor/workflow-next-completions.ts tests/extension/workflow-monitor/workflow-next-command.test.ts
195
- git commit -m "fix: preserve phase word in /workflow-next artifact completions"
196
- ```
@@ -1,185 +0,0 @@
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