@tianhai/pi-workflow-kit 0.5.1 → 0.6.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 (62) hide show
  1. package/README.md +44 -494
  2. package/docs/developer-usage-guide.md +41 -401
  3. package/docs/oversight-model.md +13 -34
  4. package/docs/workflow-phases.md +32 -46
  5. package/extensions/workflow-guard.ts +67 -0
  6. package/package.json +3 -7
  7. package/skills/brainstorming/SKILL.md +16 -59
  8. package/skills/executing-tasks/SKILL.md +26 -227
  9. package/skills/finalizing/SKILL.md +33 -0
  10. package/skills/writing-plans/SKILL.md +23 -132
  11. package/ROADMAP.md +0 -16
  12. package/agents/code-reviewer.md +0 -18
  13. package/agents/config.ts +0 -5
  14. package/agents/implementer.md +0 -26
  15. package/agents/spec-reviewer.md +0 -13
  16. package/agents/worker.md +0 -17
  17. package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md +0 -56
  18. package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-implementation.md +0 -196
  19. package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-design.md +0 -185
  20. package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-implementation.md +0 -334
  21. package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-design.md +0 -251
  22. package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-implementation.md +0 -253
  23. package/extensions/constants.ts +0 -15
  24. package/extensions/lib/logging.ts +0 -138
  25. package/extensions/plan-tracker.ts +0 -502
  26. package/extensions/subagent/agents.ts +0 -144
  27. package/extensions/subagent/concurrency.ts +0 -52
  28. package/extensions/subagent/env.ts +0 -47
  29. package/extensions/subagent/index.ts +0 -1181
  30. package/extensions/subagent/lifecycle.ts +0 -25
  31. package/extensions/subagent/timeout.ts +0 -13
  32. package/extensions/workflow-monitor/debug-monitor.ts +0 -98
  33. package/extensions/workflow-monitor/git.ts +0 -31
  34. package/extensions/workflow-monitor/heuristics.ts +0 -58
  35. package/extensions/workflow-monitor/investigation.ts +0 -52
  36. package/extensions/workflow-monitor/reference-tool.ts +0 -42
  37. package/extensions/workflow-monitor/skip-confirmation.ts +0 -19
  38. package/extensions/workflow-monitor/tdd-monitor.ts +0 -137
  39. package/extensions/workflow-monitor/test-runner.ts +0 -37
  40. package/extensions/workflow-monitor/verification-monitor.ts +0 -61
  41. package/extensions/workflow-monitor/warnings.ts +0 -81
  42. package/extensions/workflow-monitor/workflow-handler.ts +0 -358
  43. package/extensions/workflow-monitor/workflow-next-completions.ts +0 -68
  44. package/extensions/workflow-monitor/workflow-next-state.ts +0 -112
  45. package/extensions/workflow-monitor/workflow-tracker.ts +0 -253
  46. package/extensions/workflow-monitor/workflow-transitions.ts +0 -55
  47. package/extensions/workflow-monitor.ts +0 -872
  48. package/skills/dispatching-parallel-agents/SKILL.md +0 -194
  49. package/skills/receiving-code-review/SKILL.md +0 -196
  50. package/skills/systematic-debugging/SKILL.md +0 -170
  51. package/skills/systematic-debugging/condition-based-waiting-example.ts +0 -158
  52. package/skills/systematic-debugging/condition-based-waiting.md +0 -115
  53. package/skills/systematic-debugging/defense-in-depth.md +0 -122
  54. package/skills/systematic-debugging/find-polluter.sh +0 -63
  55. package/skills/systematic-debugging/reference/rationalizations.md +0 -61
  56. package/skills/systematic-debugging/root-cause-tracing.md +0 -169
  57. package/skills/test-driven-development/SKILL.md +0 -266
  58. package/skills/test-driven-development/reference/examples.md +0 -101
  59. package/skills/test-driven-development/reference/rationalizations.md +0 -67
  60. package/skills/test-driven-development/reference/when-stuck.md +0 -33
  61. package/skills/test-driven-development/testing-anti-patterns.md +0 -299
  62. package/skills/using-git-worktrees/SKILL.md +0 -231
package/ROADMAP.md DELETED
@@ -1,16 +0,0 @@
1
- # Roadmap
2
-
3
- Short-term priorities for `pi-workflow-kit`:
4
-
5
- - keep the simplified 4-phase workflow coherent across skills, extensions, and docs
6
- - improve `executing-tasks` ergonomics for real feature delivery
7
- - continue tightening workflow-monitor tests around phase transitions and handoffs
8
- - improve README and reference docs so package behavior is easy to trust
9
- - expand examples for non-code tasks and finalize flows
10
-
11
- Longer-term possibilities:
12
-
13
- - richer plan parsing helpers for typed task extraction
14
- - deeper TUI support for active-task detail
15
- - more bundled subagents for targeted review and maintenance tasks
16
- - optional reporting/export of workflow state
@@ -1,18 +0,0 @@
1
- ---
2
- name: code-reviewer
3
- description: "Production readiness review: quality, security, testing (read-only)"
4
- tools: read, bash, find, grep, ls
5
- ---
6
-
7
- You are a code quality reviewer.
8
-
9
- Review for:
10
- - correctness, error handling
11
- - maintainability
12
- - security and footguns
13
- - test coverage quality
14
-
15
- Return:
16
- - Strengths
17
- - Issues (Critical/Important/Minor)
18
- - Clear verdict (ready or not)
package/agents/config.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Canonical model configuration for bundled agents.
3
- * Change this one constant to update the default model for all bundled agents.
4
- */
5
- export const DEFAULT_MODEL = "claude-sonnet-4-5";
@@ -1,26 +0,0 @@
1
- ---
2
- name: implementer
3
- description: Implement tasks via TDD and commit small changes
4
- tools: read, write, edit, bash, plan_tracker, workflow_reference
5
- extensions: ../extensions/workflow-monitor, ../extensions/plan-tracker
6
- ---
7
-
8
- You are an implementation subagent.
9
-
10
- ## TDD Approach
11
-
12
- Determine which scenario applies before writing code:
13
-
14
- **New files / new features:** Full TDD. Write a failing test first, verify it fails, implement minimal code to pass, refactor.
15
-
16
- **Modifying code with existing tests:** Run existing tests first to confirm green. Make your change. Run tests again. If the change isn't covered by existing tests, add a test. If it is, you're done.
17
-
18
- **Trivial changes (typo, config, rename):** Use judgment. Run relevant tests after if they exist.
19
-
20
- **If you see a ⚠️ TDD warning:** Pause. Consider which scenario applies. If existing tests cover your change, run them and proceed. If not, write a test first.
21
-
22
- ## Rules
23
- - Keep changes minimal and scoped to the task.
24
- - Run the narrowest test(s) first, then the full suite when appropriate.
25
- - Commit when the task's tests pass.
26
- - Report: what changed, tests run, files changed, any concerns.
@@ -1,13 +0,0 @@
1
- ---
2
- name: spec-reviewer
3
- description: Verify implementation matches the plan/spec (read-only)
4
- tools: read, bash, find, grep, ls
5
- ---
6
-
7
- You are a spec compliance reviewer.
8
-
9
- Check the implementation against the provided requirements.
10
- - Identify missing requirements.
11
- - Identify scope creep / unrequested changes.
12
- - Point to exact files/lines and provide concrete fixes.
13
- Return a clear verdict: ✅ compliant / ❌ not compliant.
package/agents/worker.md DELETED
@@ -1,17 +0,0 @@
1
- ---
2
- name: worker
3
- description: General-purpose worker for isolated tasks
4
- tools: read, write, edit, bash, plan_tracker, workflow_reference
5
- extensions: ../extensions/workflow-monitor, ../extensions/plan-tracker
6
- ---
7
-
8
- You are a general-purpose subagent. Follow the task exactly.
9
-
10
- ## TDD (when changing production code)
11
-
12
- - New files: write a failing test first, then implement.
13
- - Modifying existing code: run existing tests first, make your change, run again. Add tests if not covered.
14
- - Trivial changes: run relevant tests after if they exist.
15
- - If you see a ⚠️ TDD warning, pause and decide which scenario applies before proceeding.
16
-
17
- Prefer small, test-backed changes.
@@ -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