@tianhai/pi-workflow-kit 0.4.1 → 0.5.1
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 +29 -5
- package/docs/developer-usage-guide.md +3 -4
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md +56 -0
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-implementation.md +196 -0
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-design.md +185 -0
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-implementation.md +334 -0
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-design.md +251 -0
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-implementation.md +253 -0
- package/extensions/constants.ts +6 -0
- package/extensions/plan-tracker.ts +7 -1
- package/extensions/subagent/index.ts +73 -8
- package/extensions/workflow-monitor/workflow-next-completions.ts +68 -0
- package/extensions/workflow-monitor/workflow-next-state.ts +112 -0
- package/extensions/workflow-monitor/workflow-tracker.ts +28 -6
- package/extensions/workflow-monitor.ts +64 -77
- package/package.json +1 -1
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
|
|
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
|
|
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) |
|
|
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
|
|
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
|
|
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
|
{
|
package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
```
|
|
@@ -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
|