@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.
- package/README.md +44 -494
- package/docs/developer-usage-guide.md +41 -401
- package/docs/oversight-model.md +13 -34
- package/docs/workflow-phases.md +32 -46
- package/extensions/workflow-guard.ts +67 -0
- package/package.json +3 -7
- package/skills/brainstorming/SKILL.md +16 -59
- package/skills/executing-tasks/SKILL.md +26 -227
- package/skills/finalizing/SKILL.md +33 -0
- package/skills/writing-plans/SKILL.md +23 -132
- package/ROADMAP.md +0 -16
- package/agents/code-reviewer.md +0 -18
- package/agents/config.ts +0 -5
- package/agents/implementer.md +0 -26
- package/agents/spec-reviewer.md +0 -13
- package/agents/worker.md +0 -17
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md +0 -56
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-implementation.md +0 -196
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-design.md +0 -185
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-implementation.md +0 -334
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-design.md +0 -251
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-implementation.md +0 -253
- package/extensions/constants.ts +0 -15
- package/extensions/lib/logging.ts +0 -138
- package/extensions/plan-tracker.ts +0 -502
- package/extensions/subagent/agents.ts +0 -144
- package/extensions/subagent/concurrency.ts +0 -52
- package/extensions/subagent/env.ts +0 -47
- package/extensions/subagent/index.ts +0 -1181
- package/extensions/subagent/lifecycle.ts +0 -25
- package/extensions/subagent/timeout.ts +0 -13
- package/extensions/workflow-monitor/debug-monitor.ts +0 -98
- package/extensions/workflow-monitor/git.ts +0 -31
- package/extensions/workflow-monitor/heuristics.ts +0 -58
- package/extensions/workflow-monitor/investigation.ts +0 -52
- package/extensions/workflow-monitor/reference-tool.ts +0 -42
- package/extensions/workflow-monitor/skip-confirmation.ts +0 -19
- package/extensions/workflow-monitor/tdd-monitor.ts +0 -137
- package/extensions/workflow-monitor/test-runner.ts +0 -37
- package/extensions/workflow-monitor/verification-monitor.ts +0 -61
- package/extensions/workflow-monitor/warnings.ts +0 -81
- package/extensions/workflow-monitor/workflow-handler.ts +0 -358
- package/extensions/workflow-monitor/workflow-next-completions.ts +0 -68
- package/extensions/workflow-monitor/workflow-next-state.ts +0 -112
- package/extensions/workflow-monitor/workflow-tracker.ts +0 -253
- package/extensions/workflow-monitor/workflow-transitions.ts +0 -55
- package/extensions/workflow-monitor.ts +0 -872
- package/skills/dispatching-parallel-agents/SKILL.md +0 -194
- package/skills/receiving-code-review/SKILL.md +0 -196
- package/skills/systematic-debugging/SKILL.md +0 -170
- package/skills/systematic-debugging/condition-based-waiting-example.ts +0 -158
- package/skills/systematic-debugging/condition-based-waiting.md +0 -115
- package/skills/systematic-debugging/defense-in-depth.md +0 -122
- package/skills/systematic-debugging/find-polluter.sh +0 -63
- package/skills/systematic-debugging/reference/rationalizations.md +0 -61
- package/skills/systematic-debugging/root-cause-tracing.md +0 -169
- package/skills/test-driven-development/SKILL.md +0 -266
- package/skills/test-driven-development/reference/examples.md +0 -101
- package/skills/test-driven-development/reference/rationalizations.md +0 -67
- package/skills/test-driven-development/reference/when-stuck.md +0 -33
- package/skills/test-driven-development/testing-anti-patterns.md +0 -299
- package/skills/using-git-worktrees/SKILL.md +0 -231
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import type { SessionEntry } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
import type { PlanTrackerDetails, PlanTrackerTask } from "../plan-tracker.js";
|
|
3
|
-
import { DebugMonitor, type DebugViolation } from "./debug-monitor";
|
|
4
|
-
import { isSourceFile } from "./heuristics";
|
|
5
|
-
import { isInvestigationCommand, isInvestigationToolCall } from "./investigation";
|
|
6
|
-
import { TddMonitor, type TddPhase, type TddViolation } from "./tdd-monitor";
|
|
7
|
-
import { parseTestCommand, parseTestResult } from "./test-runner";
|
|
8
|
-
import { VerificationMonitor, type VerificationViolation } from "./verification-monitor";
|
|
9
|
-
import { type Phase, type PhaseStatus, WorkflowTracker, type WorkflowTrackerState } from "./workflow-tracker";
|
|
10
|
-
|
|
11
|
-
export type Violation = TddViolation | DebugViolation;
|
|
12
|
-
|
|
13
|
-
export interface ToolCallResult {
|
|
14
|
-
violation: Violation | null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface SuperpowersStateSnapshot {
|
|
18
|
-
workflow: WorkflowTrackerState;
|
|
19
|
-
tdd: {
|
|
20
|
-
phase: TddPhase;
|
|
21
|
-
testFiles: string[];
|
|
22
|
-
sourceFiles: string[];
|
|
23
|
-
redVerificationPending: boolean;
|
|
24
|
-
nonCodeMode: boolean;
|
|
25
|
-
};
|
|
26
|
-
debug: {
|
|
27
|
-
active: boolean;
|
|
28
|
-
investigated: boolean;
|
|
29
|
-
fixAttempts: number;
|
|
30
|
-
};
|
|
31
|
-
verification: {
|
|
32
|
-
verified: boolean;
|
|
33
|
-
verificationWaived: boolean;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type SuperpowersStatePatch = {
|
|
38
|
-
workflow?: Partial<WorkflowTrackerState> & {
|
|
39
|
-
phases?: Partial<Record<Phase, PhaseStatus>>;
|
|
40
|
-
artifacts?: Partial<Record<Phase, string | null>>;
|
|
41
|
-
prompted?: Partial<Record<Phase, boolean>>;
|
|
42
|
-
};
|
|
43
|
-
tdd?: Partial<SuperpowersStateSnapshot["tdd"]>;
|
|
44
|
-
debug?: Partial<SuperpowersStateSnapshot["debug"]>;
|
|
45
|
-
verification?: Partial<SuperpowersStateSnapshot["verification"]>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const TDD_DEFAULTS = {
|
|
49
|
-
phase: "idle" as TddPhase,
|
|
50
|
-
testFiles: [] as string[],
|
|
51
|
-
sourceFiles: [] as string[],
|
|
52
|
-
redVerificationPending: false,
|
|
53
|
-
nonCodeMode: false,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const DEBUG_DEFAULTS = {
|
|
57
|
-
active: false,
|
|
58
|
-
investigated: false,
|
|
59
|
-
fixAttempts: 0,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const VERIFICATION_DEFAULTS = {
|
|
63
|
-
verified: false,
|
|
64
|
-
verificationWaived: false,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export interface WorkflowHandler {
|
|
68
|
-
handleToolCall(toolName: string, input: Record<string, unknown>): ToolCallResult;
|
|
69
|
-
handleReadOrInvestigation(toolName: string, path: string): void;
|
|
70
|
-
handleBashResult(command: string, output: string, exitCode: number | undefined): void;
|
|
71
|
-
/** @internal Used in tests; will be wired to bash events in future */
|
|
72
|
-
handleBashInvestigation(command: string): void;
|
|
73
|
-
isDebugActive(): boolean;
|
|
74
|
-
getDebugFixAttempts(): number;
|
|
75
|
-
getTddPhase(): string;
|
|
76
|
-
getWidgetText(): string;
|
|
77
|
-
getTddState(): ReturnType<TddMonitor["getState"]>;
|
|
78
|
-
checkCommitGate(command: string): VerificationViolation | null;
|
|
79
|
-
recordVerificationWaiver(): void;
|
|
80
|
-
restoreTddState(phase: TddPhase, testFiles: string[], sourceFiles: string[], redVerificationPending?: boolean): void;
|
|
81
|
-
handleInputText(text: string): boolean;
|
|
82
|
-
handleFileWritten(path: string): boolean;
|
|
83
|
-
handlePlanTrackerToolCall(input: Record<string, unknown>): boolean;
|
|
84
|
-
handlePlanTrackerToolResult(details: PlanTrackerDetails | undefined): boolean;
|
|
85
|
-
getWorkflowState(): WorkflowTrackerState | null;
|
|
86
|
-
getFullState(): SuperpowersStateSnapshot;
|
|
87
|
-
setFullState(snapshot: SuperpowersStatePatch): void;
|
|
88
|
-
restoreWorkflowStateFromBranch(branch: SessionEntry[]): void;
|
|
89
|
-
markWorkflowPrompted(phase: Phase): boolean;
|
|
90
|
-
completeCurrentWorkflowPhase(): boolean;
|
|
91
|
-
advanceWorkflowTo(phase: Phase): boolean;
|
|
92
|
-
skipWorkflowPhases(phases: Phase[]): boolean;
|
|
93
|
-
handleSkillFileRead(path: string): boolean;
|
|
94
|
-
resetState(): void;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function deriveNonCodeMode(tasks: PlanTrackerTask[]): boolean {
|
|
98
|
-
const activeTask = tasks.find((task) => task.status === "in_progress");
|
|
99
|
-
return activeTask?.type === "non-code";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function areAllTasksTerminal(tasks: PlanTrackerTask[]): boolean {
|
|
103
|
-
return tasks.length > 0 && tasks.every((task) => task.status === "complete" || task.status === "blocked");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function createWorkflowHandler(): WorkflowHandler {
|
|
107
|
-
const tdd = new TddMonitor();
|
|
108
|
-
const debug = new DebugMonitor();
|
|
109
|
-
const verification = new VerificationMonitor();
|
|
110
|
-
const tracker = new WorkflowTracker();
|
|
111
|
-
let debugFailStreak = 0;
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
handleToolCall(toolName: string, input: Record<string, unknown>): ToolCallResult {
|
|
115
|
-
// Track investigation from tool calls (LSP, kota, web search)
|
|
116
|
-
if (isInvestigationToolCall(toolName, input)) {
|
|
117
|
-
debug.onInvestigation();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (toolName === "write" || toolName === "edit") {
|
|
121
|
-
const path = input.path as string | undefined;
|
|
122
|
-
if (path) {
|
|
123
|
-
if (isSourceFile(path)) {
|
|
124
|
-
verification.onSourceWritten();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Debug violations take precedence, and when debug is active we don't
|
|
128
|
-
// additionally enforce TDD write-order violations.
|
|
129
|
-
if (debug.isActive() && isSourceFile(path)) {
|
|
130
|
-
const debugViolation = debug.onSourceWritten(path);
|
|
131
|
-
return { violation: debugViolation };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const tddViolation = tdd.onFileWritten(path);
|
|
135
|
-
return { violation: tddViolation };
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return { violation: null };
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
handleReadOrInvestigation(toolName: string, _path: string): void {
|
|
142
|
-
if (toolName === "read") {
|
|
143
|
-
debug.onInvestigation();
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
handleBashResult(command: string, output: string, exitCode: number | undefined): void {
|
|
148
|
-
if (isInvestigationCommand(command)) {
|
|
149
|
-
debug.onInvestigation();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (/\bgit\s+commit\b/.test(command)) {
|
|
153
|
-
debugFailStreak = 0;
|
|
154
|
-
tdd.onCommit();
|
|
155
|
-
debug.onCommit();
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (parseTestCommand(command)) {
|
|
160
|
-
const passed = parseTestResult(output, exitCode);
|
|
161
|
-
if (passed !== null) {
|
|
162
|
-
if (passed) {
|
|
163
|
-
verification.recordVerification();
|
|
164
|
-
} else {
|
|
165
|
-
verification.reset();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const excludeFromDebug = !passed && tdd.getPhase() === "red-pending";
|
|
169
|
-
|
|
170
|
-
tdd.onTestResult(passed);
|
|
171
|
-
|
|
172
|
-
if (passed) {
|
|
173
|
-
debugFailStreak = 0;
|
|
174
|
-
debug.onTestPassed();
|
|
175
|
-
} else if (!excludeFromDebug) {
|
|
176
|
-
debugFailStreak += 1;
|
|
177
|
-
const tddPhase = tdd.getPhase();
|
|
178
|
-
if (debugFailStreak >= 1 && tddPhase === "idle") {
|
|
179
|
-
debug.onTestFailed();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
handleBashInvestigation(command: string): void {
|
|
187
|
-
if (isInvestigationCommand(command)) {
|
|
188
|
-
debug.onInvestigation();
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
isDebugActive(): boolean {
|
|
193
|
-
return debug.isActive();
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
getDebugFixAttempts(): number {
|
|
197
|
-
return debug.getFixAttempts();
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
getTddPhase(): string {
|
|
201
|
-
return tdd.getPhase();
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
getWidgetText(): string {
|
|
205
|
-
const parts: string[] = [];
|
|
206
|
-
|
|
207
|
-
const phase = tdd.getPhase();
|
|
208
|
-
if (phase !== "idle") {
|
|
209
|
-
parts.push(`TDD: ${phase.toUpperCase()}`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (debug.isActive()) {
|
|
213
|
-
parts.push("Debug: ACTIVE");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return parts.join(" | ");
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
getTddState() {
|
|
220
|
-
return tdd.getState();
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
checkCommitGate(command: string) {
|
|
224
|
-
return verification.checkCommitGate(command);
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
recordVerificationWaiver() {
|
|
228
|
-
verification.recordVerificationWaiver();
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
restoreTddState(phase: TddPhase, testFiles: string[], sourceFiles: string[], redVerificationPending = false) {
|
|
232
|
-
tdd.setState(phase, testFiles, sourceFiles, redVerificationPending);
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
handleInputText(text: string) {
|
|
236
|
-
return tracker.onInputText(text);
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
handleFileWritten(path: string) {
|
|
240
|
-
return tracker.onFileWritten(path);
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
handlePlanTrackerToolCall(input: Record<string, unknown>) {
|
|
244
|
-
if (input.action === "init") {
|
|
245
|
-
tdd.setNonCodeMode(false);
|
|
246
|
-
return tracker.onPlanTrackerInit();
|
|
247
|
-
}
|
|
248
|
-
return false;
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
handlePlanTrackerToolResult(details: PlanTrackerDetails | undefined) {
|
|
252
|
-
if (!details) return false;
|
|
253
|
-
|
|
254
|
-
let changed = false;
|
|
255
|
-
const nextNonCodeMode = deriveNonCodeMode(details.tasks);
|
|
256
|
-
if (tdd.getState().nonCodeMode !== nextNonCodeMode) {
|
|
257
|
-
tdd.setNonCodeMode(nextNonCodeMode);
|
|
258
|
-
changed = true;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (areAllTasksTerminal(details.tasks) && tracker.getState().currentPhase === "execute") {
|
|
262
|
-
changed = tracker.completeCurrent() || changed;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return changed;
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
getWorkflowState() {
|
|
269
|
-
return tracker.getState();
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
getFullState() {
|
|
273
|
-
return {
|
|
274
|
-
workflow: tracker.getState(),
|
|
275
|
-
tdd: tdd.getState(),
|
|
276
|
-
debug: debug.getState(),
|
|
277
|
-
verification: verification.getState(),
|
|
278
|
-
};
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
setFullState(snapshot: SuperpowersStatePatch) {
|
|
282
|
-
if (snapshot.workflow) {
|
|
283
|
-
const defaultWorkflow = new WorkflowTracker().getState();
|
|
284
|
-
tracker.setState({
|
|
285
|
-
...defaultWorkflow,
|
|
286
|
-
...snapshot.workflow,
|
|
287
|
-
phases: { ...defaultWorkflow.phases, ...snapshot.workflow.phases },
|
|
288
|
-
artifacts: { ...defaultWorkflow.artifacts, ...snapshot.workflow.artifacts },
|
|
289
|
-
prompted: { ...defaultWorkflow.prompted, ...snapshot.workflow.prompted },
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
if (snapshot.tdd) {
|
|
293
|
-
const tddState = { ...TDD_DEFAULTS, ...snapshot.tdd };
|
|
294
|
-
tdd.setState(
|
|
295
|
-
tddState.phase,
|
|
296
|
-
tddState.testFiles,
|
|
297
|
-
tddState.sourceFiles,
|
|
298
|
-
tddState.redVerificationPending,
|
|
299
|
-
tddState.nonCodeMode,
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
if (snapshot.debug) {
|
|
303
|
-
debug.setState({ ...DEBUG_DEFAULTS, ...snapshot.debug });
|
|
304
|
-
}
|
|
305
|
-
if (snapshot.verification) {
|
|
306
|
-
verification.setState({ ...VERIFICATION_DEFAULTS, ...snapshot.verification });
|
|
307
|
-
}
|
|
308
|
-
debugFailStreak = 0;
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
restoreWorkflowStateFromBranch(branch: SessionEntry[]) {
|
|
312
|
-
const state = WorkflowTracker.reconstructFromBranch(branch);
|
|
313
|
-
if (state) {
|
|
314
|
-
tracker.setState(state);
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
markWorkflowPrompted(phase: Phase) {
|
|
319
|
-
return tracker.markPrompted(phase);
|
|
320
|
-
},
|
|
321
|
-
|
|
322
|
-
completeCurrentWorkflowPhase() {
|
|
323
|
-
return tracker.completeCurrent();
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
advanceWorkflowTo(phase) {
|
|
327
|
-
return tracker.advanceTo(phase);
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
skipWorkflowPhases(phases) {
|
|
331
|
-
return tracker.skipPhases(phases);
|
|
332
|
-
},
|
|
333
|
-
|
|
334
|
-
handleSkillFileRead(path: string) {
|
|
335
|
-
return tracker.onSkillFileRead(path);
|
|
336
|
-
},
|
|
337
|
-
|
|
338
|
-
resetState() {
|
|
339
|
-
const freshState: SuperpowersStateSnapshot = {
|
|
340
|
-
workflow: new WorkflowTracker().getState(),
|
|
341
|
-
tdd: { ...TDD_DEFAULTS, testFiles: [], sourceFiles: [] },
|
|
342
|
-
debug: { ...DEBUG_DEFAULTS },
|
|
343
|
-
verification: { ...VERIFICATION_DEFAULTS },
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
tracker.setState(freshState.workflow);
|
|
347
|
-
tdd.setState(
|
|
348
|
-
freshState.tdd.phase,
|
|
349
|
-
freshState.tdd.testFiles,
|
|
350
|
-
freshState.tdd.sourceFiles,
|
|
351
|
-
freshState.tdd.redVerificationPending,
|
|
352
|
-
);
|
|
353
|
-
debug.setState(freshState.debug);
|
|
354
|
-
verification.setState(freshState.verification);
|
|
355
|
-
debugFailStreak = 0;
|
|
356
|
-
},
|
|
357
|
-
};
|
|
358
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { AutocompleteItem } from "@mariozechner/pi-tui";
|
|
4
|
-
|
|
5
|
-
const WORKFLOW_NEXT_PHASES = ["brainstorm", "plan", "execute", "finalize"] as const;
|
|
6
|
-
const ARTIFACT_SUFFIX_BY_PHASE = {
|
|
7
|
-
brainstorm: null,
|
|
8
|
-
plan: "-design.md",
|
|
9
|
-
execute: "-implementation.md",
|
|
10
|
-
finalize: "-implementation.md",
|
|
11
|
-
} as const;
|
|
12
|
-
|
|
13
|
-
type WorkflowNextPhase = (typeof WORKFLOW_NEXT_PHASES)[number];
|
|
14
|
-
|
|
15
|
-
function getPhaseCompletions(prefix: string): AutocompleteItem[] | null {
|
|
16
|
-
const normalized = prefix.replace(/^\s+/, "");
|
|
17
|
-
const firstToken = normalized.split(/\s+/, 1)[0] ?? "";
|
|
18
|
-
const completingFirstArg = normalized.length === 0 || !/\s/.test(normalized);
|
|
19
|
-
|
|
20
|
-
if (completingFirstArg || !WORKFLOW_NEXT_PHASES.includes(firstToken as WorkflowNextPhase)) {
|
|
21
|
-
const phasePrefix = completingFirstArg ? normalized : firstToken;
|
|
22
|
-
const items = WORKFLOW_NEXT_PHASES.filter((phase) => phase.startsWith(phasePrefix)).map((phase) => ({
|
|
23
|
-
value: phase,
|
|
24
|
-
label: phase,
|
|
25
|
-
}));
|
|
26
|
-
return items.length > 0 ? items : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function listArtifactsForPhase(phase: WorkflowNextPhase, typedPrefix: string): AutocompleteItem[] | null {
|
|
33
|
-
const suffix = ARTIFACT_SUFFIX_BY_PHASE[phase];
|
|
34
|
-
if (!suffix) return null;
|
|
35
|
-
|
|
36
|
-
const plansDir = path.join(process.cwd(), "docs", "plans");
|
|
37
|
-
if (!fs.existsSync(plansDir)) return null;
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const items = fs
|
|
41
|
-
.readdirSync(plansDir)
|
|
42
|
-
.filter((name) => name.endsWith(suffix))
|
|
43
|
-
.map((name) => path.join("docs", "plans", name))
|
|
44
|
-
.filter((relPath) => relPath.startsWith(typedPrefix))
|
|
45
|
-
.map((relPath) => ({ value: `${phase} ${relPath}`, label: relPath }));
|
|
46
|
-
|
|
47
|
-
return items.length > 0 ? items : null;
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function getWorkflowNextCompletions(prefix: string): Promise<AutocompleteItem[] | null> {
|
|
54
|
-
const phaseCompletions = getPhaseCompletions(prefix);
|
|
55
|
-
if (phaseCompletions) return phaseCompletions;
|
|
56
|
-
|
|
57
|
-
const normalized = prefix.replace(/^\s+/, "");
|
|
58
|
-
const match = normalized.match(/^(\S+)(?:\s+(.*))?$/);
|
|
59
|
-
const phase = match?.[1] as WorkflowNextPhase | undefined;
|
|
60
|
-
const artifactPrefix = match?.[2] ?? "";
|
|
61
|
-
const startingSecondArg = /\s$/.test(prefix) || artifactPrefix.length > 0;
|
|
62
|
-
|
|
63
|
-
if (phase && WORKFLOW_NEXT_PHASES.includes(phase) && startingSecondArg) {
|
|
64
|
-
return listArtifactsForPhase(phase, artifactPrefix);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure helper functions for /workflow-next handoff validation and derived state.
|
|
3
|
-
*
|
|
4
|
-
* These functions have no side effects and no dependencies on the extension runtime,
|
|
5
|
-
* making them straightforward to test and reason about.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { type Phase, type PhaseStatus, WORKFLOW_PHASES, type WorkflowTrackerState } from "./workflow-tracker";
|
|
9
|
-
|
|
10
|
-
/** Map of each phase to its immediate next phase (null for finalize). */
|
|
11
|
-
const NEXT_PHASE: Record<Phase, Phase | null> = {
|
|
12
|
-
brainstorm: "plan",
|
|
13
|
-
plan: "execute",
|
|
14
|
-
execute: "finalize",
|
|
15
|
-
finalize: null,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Validate whether a `/workflow-next` request is allowed.
|
|
20
|
-
*
|
|
21
|
-
* Rules:
|
|
22
|
-
* - A current phase must exist in the workflow state.
|
|
23
|
-
* - The current phase must have status exactly "complete".
|
|
24
|
-
* - The requested phase must be the immediate next phase.
|
|
25
|
-
*
|
|
26
|
-
* Returns `null` if the handoff is valid, or an error message string.
|
|
27
|
-
*/
|
|
28
|
-
export function validateNextWorkflowPhase(currentState: WorkflowTrackerState, requestedPhase: Phase): string | null {
|
|
29
|
-
const current = currentState.currentPhase;
|
|
30
|
-
|
|
31
|
-
if (!current) {
|
|
32
|
-
return "No workflow phase is active. Start a workflow first or use /workflow-reset.";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const next = NEXT_PHASE[current];
|
|
36
|
-
if (next === null) {
|
|
37
|
-
return `Cannot hand off: ${current} is the final phase. Use /workflow-reset for a new task.`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const currentStatus = currentState.phases[current];
|
|
41
|
-
|
|
42
|
-
// Same-phase handoff
|
|
43
|
-
if (requestedPhase === current) {
|
|
44
|
-
return `Cannot hand off to ${requestedPhase} from ${current}. Use /workflow-reset for a new task or continue in this session.`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Backward handoff
|
|
48
|
-
const currentIdx = WORKFLOW_PHASES.indexOf(current);
|
|
49
|
-
const requestedIdx = WORKFLOW_PHASES.indexOf(requestedPhase);
|
|
50
|
-
if (requestedIdx < currentIdx) {
|
|
51
|
-
return `Cannot hand off to ${requestedPhase} from ${current}: backward transitions are not allowed.`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Current phase not complete
|
|
55
|
-
if (currentStatus !== "complete") {
|
|
56
|
-
return `Cannot hand off to ${requestedPhase} because ${current} is not complete (status: ${currentStatus}).`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Direct jump (skipping intermediate phases)
|
|
60
|
-
if (requestedPhase !== next) {
|
|
61
|
-
return `Cannot hand off to ${requestedPhase} from ${current}. /workflow-next only supports the immediate next phase: ${next}.`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Derive the workflow state snapshot for a new session created by `/workflow-next`.
|
|
69
|
-
*
|
|
70
|
-
* Rules:
|
|
71
|
-
* - All phases before the requested phase are marked "complete".
|
|
72
|
-
* - The requested phase is marked "active".
|
|
73
|
-
* - All phases after the requested phase are marked "pending".
|
|
74
|
-
* - currentPhase is set to the requested phase.
|
|
75
|
-
* - Artifacts and prompted flags are preserved for earlier phases.
|
|
76
|
-
*/
|
|
77
|
-
export function deriveWorkflowHandoffState(
|
|
78
|
-
currentState: WorkflowTrackerState,
|
|
79
|
-
requestedPhase: Phase,
|
|
80
|
-
): WorkflowTrackerState {
|
|
81
|
-
const requestedIdx = WORKFLOW_PHASES.indexOf(requestedPhase);
|
|
82
|
-
|
|
83
|
-
const newPhases = { ...currentState.phases };
|
|
84
|
-
const newArtifacts = { ...currentState.artifacts };
|
|
85
|
-
const newPrompted = { ...currentState.prompted };
|
|
86
|
-
|
|
87
|
-
for (let i = 0; i < WORKFLOW_PHASES.length; i++) {
|
|
88
|
-
const phase = WORKFLOW_PHASES[i]!;
|
|
89
|
-
|
|
90
|
-
if (i < requestedIdx) {
|
|
91
|
-
// Earlier phases: mark complete, preserve artifacts/prompted
|
|
92
|
-
newPhases[phase] = "complete";
|
|
93
|
-
} else if (i === requestedIdx) {
|
|
94
|
-
// Target phase: active
|
|
95
|
-
newPhases[phase] = "active";
|
|
96
|
-
newArtifacts[phase] = currentState.artifacts[phase] ?? null;
|
|
97
|
-
newPrompted[phase] = false;
|
|
98
|
-
} else {
|
|
99
|
-
// Later phases: pending, clear artifacts/prompted
|
|
100
|
-
newPhases[phase] = "pending";
|
|
101
|
-
newArtifacts[phase] = null;
|
|
102
|
-
newPrompted[phase] = false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
phases: newPhases as Record<Phase, PhaseStatus>,
|
|
108
|
-
currentPhase: requestedPhase,
|
|
109
|
-
artifacts: newArtifacts as Record<Phase, string | null>,
|
|
110
|
-
prompted: newPrompted as Record<Phase, boolean>,
|
|
111
|
-
};
|
|
112
|
-
}
|