gsd-pi 2.41.0-dev.3557dc4 → 2.41.0-dev.5a170d0

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 (123) hide show
  1. package/README.md +1 -1
  2. package/dist/resources/extensions/gsd/auto/loop.js +80 -0
  3. package/dist/resources/extensions/gsd/auto/phases.js +2 -2
  4. package/dist/resources/extensions/gsd/auto/session.js +6 -0
  5. package/dist/resources/extensions/gsd/auto-dashboard.js +2 -0
  6. package/dist/resources/extensions/gsd/auto.js +28 -1
  7. package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +7 -2
  8. package/dist/resources/extensions/gsd/commands/catalog.js +32 -0
  9. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +146 -0
  10. package/dist/resources/extensions/gsd/context-injector.js +74 -0
  11. package/dist/resources/extensions/gsd/custom-execution-policy.js +47 -0
  12. package/dist/resources/extensions/gsd/custom-verification.js +145 -0
  13. package/dist/resources/extensions/gsd/custom-workflow-engine.js +164 -0
  14. package/dist/resources/extensions/gsd/dashboard-overlay.js +1 -0
  15. package/dist/resources/extensions/gsd/definition-loader.js +352 -0
  16. package/dist/resources/extensions/gsd/dev-execution-policy.js +24 -0
  17. package/dist/resources/extensions/gsd/dev-workflow-engine.js +82 -0
  18. package/dist/resources/extensions/gsd/engine-resolver.js +40 -0
  19. package/dist/resources/extensions/gsd/engine-types.js +8 -0
  20. package/dist/resources/extensions/gsd/execution-policy.js +8 -0
  21. package/dist/resources/extensions/gsd/graph.js +225 -0
  22. package/dist/resources/extensions/gsd/run-manager.js +134 -0
  23. package/dist/resources/extensions/gsd/workflow-engine.js +7 -0
  24. package/dist/resources/skills/create-workflow/SKILL.md +103 -0
  25. package/dist/resources/skills/create-workflow/references/feature-patterns.md +128 -0
  26. package/dist/resources/skills/create-workflow/references/verification-policies.md +76 -0
  27. package/dist/resources/skills/create-workflow/references/yaml-schema-v1.md +46 -0
  28. package/dist/resources/skills/create-workflow/templates/blog-post-pipeline.yaml +60 -0
  29. package/dist/resources/skills/create-workflow/templates/code-audit.yaml +60 -0
  30. package/dist/resources/skills/create-workflow/templates/release-checklist.yaml +66 -0
  31. package/dist/resources/skills/create-workflow/templates/workflow-definition.yaml +32 -0
  32. package/dist/resources/skills/create-workflow/workflows/create-from-scratch.md +104 -0
  33. package/dist/resources/skills/create-workflow/workflows/create-from-template.md +72 -0
  34. package/dist/web/standalone/.next/BUILD_ID +1 -1
  35. package/dist/web/standalone/.next/app-path-routes-manifest.json +13 -13
  36. package/dist/web/standalone/.next/build-manifest.json +2 -2
  37. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  38. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  39. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  42. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  47. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/index.html +1 -1
  55. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  60. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app-paths-manifest.json +13 -13
  62. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  63. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  64. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  65. package/package.json +1 -1
  66. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  67. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -0
  68. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  69. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +5 -0
  70. package/src/resources/extensions/gsd/auto/loop.ts +91 -0
  71. package/src/resources/extensions/gsd/auto/phases.ts +2 -2
  72. package/src/resources/extensions/gsd/auto/session.ts +6 -0
  73. package/src/resources/extensions/gsd/auto-dashboard.ts +2 -0
  74. package/src/resources/extensions/gsd/auto.ts +31 -1
  75. package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +9 -2
  76. package/src/resources/extensions/gsd/commands/catalog.ts +32 -0
  77. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +164 -0
  78. package/src/resources/extensions/gsd/context-injector.ts +100 -0
  79. package/src/resources/extensions/gsd/custom-execution-policy.ts +73 -0
  80. package/src/resources/extensions/gsd/custom-verification.ts +180 -0
  81. package/src/resources/extensions/gsd/custom-workflow-engine.ts +216 -0
  82. package/src/resources/extensions/gsd/dashboard-overlay.ts +1 -0
  83. package/src/resources/extensions/gsd/definition-loader.ts +462 -0
  84. package/src/resources/extensions/gsd/dev-execution-policy.ts +51 -0
  85. package/src/resources/extensions/gsd/dev-workflow-engine.ts +110 -0
  86. package/src/resources/extensions/gsd/engine-resolver.ts +57 -0
  87. package/src/resources/extensions/gsd/engine-types.ts +71 -0
  88. package/src/resources/extensions/gsd/execution-policy.ts +43 -0
  89. package/src/resources/extensions/gsd/graph.ts +312 -0
  90. package/src/resources/extensions/gsd/run-manager.ts +180 -0
  91. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +100 -118
  92. package/src/resources/extensions/gsd/tests/auto-secrets-gate.test.ts +2 -2
  93. package/src/resources/extensions/gsd/tests/bundled-workflow-defs.test.ts +180 -0
  94. package/src/resources/extensions/gsd/tests/captures.test.ts +12 -1
  95. package/src/resources/extensions/gsd/tests/commands-workflow-custom.test.ts +283 -0
  96. package/src/resources/extensions/gsd/tests/context-injector.test.ts +313 -0
  97. package/src/resources/extensions/gsd/tests/continue-here.test.ts +20 -20
  98. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +540 -0
  99. package/src/resources/extensions/gsd/tests/custom-verification.test.ts +382 -0
  100. package/src/resources/extensions/gsd/tests/custom-workflow-engine.test.ts +339 -0
  101. package/src/resources/extensions/gsd/tests/dashboard-custom-engine.test.ts +87 -0
  102. package/src/resources/extensions/gsd/tests/definition-loader.test.ts +778 -0
  103. package/src/resources/extensions/gsd/tests/dev-engine-wrapper.test.ts +318 -0
  104. package/src/resources/extensions/gsd/tests/e2e-workflow-pipeline-integration.test.ts +476 -0
  105. package/src/resources/extensions/gsd/tests/engine-interfaces-contract.test.ts +271 -0
  106. package/src/resources/extensions/gsd/tests/graph-operations.test.ts +599 -0
  107. package/src/resources/extensions/gsd/tests/iterate-engine-integration.test.ts +429 -0
  108. package/src/resources/extensions/gsd/tests/run-manager.test.ts +229 -0
  109. package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +45 -0
  110. package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +195 -105
  111. package/src/resources/extensions/gsd/workflow-engine.ts +38 -0
  112. package/src/resources/skills/create-workflow/SKILL.md +103 -0
  113. package/src/resources/skills/create-workflow/references/feature-patterns.md +128 -0
  114. package/src/resources/skills/create-workflow/references/verification-policies.md +76 -0
  115. package/src/resources/skills/create-workflow/references/yaml-schema-v1.md +46 -0
  116. package/src/resources/skills/create-workflow/templates/blog-post-pipeline.yaml +60 -0
  117. package/src/resources/skills/create-workflow/templates/code-audit.yaml +60 -0
  118. package/src/resources/skills/create-workflow/templates/release-checklist.yaml +66 -0
  119. package/src/resources/skills/create-workflow/templates/workflow-definition.yaml +32 -0
  120. package/src/resources/skills/create-workflow/workflows/create-from-scratch.md +104 -0
  121. package/src/resources/skills/create-workflow/workflows/create-from-template.md +72 -0
  122. /package/dist/web/standalone/.next/static/{JBSIr4fSfHXs5g5x2ZBSC → K7GYOOPvQWX6TKYEKhODM}/_buildManifest.js +0 -0
  123. /package/dist/web/standalone/.next/static/{JBSIr4fSfHXs5g5x2ZBSC → K7GYOOPvQWX6TKYEKhODM}/_ssgManifest.js +0 -0
@@ -2321,6 +2321,11 @@ export class InteractiveMode {
2321
2321
  }
2322
2322
 
2323
2323
  private handleCtrlZ(): void {
2324
+ // On Windows, SIGTSTP doesn't exist - Ctrl+Z is not supported
2325
+ if (process.platform === "win32") {
2326
+ return;
2327
+ }
2328
+
2324
2329
  // Ignore SIGINT while suspended so Ctrl+C in the terminal does not
2325
2330
  // kill the backgrounded process. The handler is removed on resume.
2326
2331
  const ignoreSigint = () => {};
@@ -28,6 +28,7 @@ import {
28
28
  } from "./phases.js";
29
29
  import { debugLog } from "../debug-logger.js";
30
30
  import { isInfrastructureError } from "./infra-errors.js";
31
+ import { resolveEngine } from "../engine-resolver.js";
31
32
 
32
33
  /**
33
34
  * Main auto-mode execution loop. Iterates: derive → dispatch → guards →
@@ -117,6 +118,96 @@ export async function autoLoop(
117
118
  deps.emitJournalEvent({ ts: new Date().toISOString(), flowId, seq: nextSeq(), eventType: "iteration-start", data: { iteration } });
118
119
  let iterData: IterationData;
119
120
 
121
+ // ── Custom engine path ──────────────────────────────────────────────
122
+ // When activeEngineId is a non-dev value, bypass runPreDispatch and
123
+ // runDispatch entirely — the custom engine drives its own state via
124
+ // GRAPH.yaml. Shares runGuards and runUnitPhase with the dev path.
125
+ // After unit execution, verifies then reconciles via the engine layer.
126
+ //
127
+ // GSD_ENGINE_BYPASS=1 skips the engine layer entirely — falls through
128
+ // to the dev path below.
129
+ if (s.activeEngineId != null && s.activeEngineId !== "dev" && !sidecarItem && process.env.GSD_ENGINE_BYPASS !== "1") {
130
+ debugLog("autoLoop", { phase: "custom-engine-derive", iteration, engineId: s.activeEngineId });
131
+
132
+ const { engine, policy } = resolveEngine({
133
+ activeEngineId: s.activeEngineId,
134
+ activeRunDir: s.activeRunDir,
135
+ });
136
+
137
+ const engineState = await engine.deriveState(s.basePath);
138
+ if (engineState.isComplete) {
139
+ await deps.stopAuto(ctx, pi, "Workflow complete");
140
+ break;
141
+ }
142
+
143
+ debugLog("autoLoop", { phase: "custom-engine-dispatch", iteration });
144
+ const dispatch = await engine.resolveDispatch(engineState, { basePath: s.basePath });
145
+
146
+ if (dispatch.action === "stop") {
147
+ await deps.stopAuto(ctx, pi, dispatch.reason ?? "Engine stopped");
148
+ break;
149
+ }
150
+ if (dispatch.action === "skip") {
151
+ continue;
152
+ }
153
+
154
+ // dispatch.action === "dispatch"
155
+ const step = dispatch.step!;
156
+ const gsdState = await deps.deriveState(s.basePath);
157
+
158
+ iterData = {
159
+ unitType: step.unitType,
160
+ unitId: step.unitId,
161
+ prompt: step.prompt,
162
+ finalPrompt: step.prompt,
163
+ pauseAfterUatDispatch: false,
164
+ observabilityIssues: [],
165
+ state: gsdState,
166
+ mid: s.currentMilestoneId ?? "workflow",
167
+ midTitle: "Workflow",
168
+ isRetry: false,
169
+ previousTier: undefined,
170
+ };
171
+
172
+ // ── Progress widget (mirrors dev path in runDispatch) ──
173
+ deps.updateProgressWidget(ctx, iterData.unitType, iterData.unitId, iterData.state);
174
+
175
+ // ── Guards (shared with dev path) ──
176
+ const guardsResult = await runGuards(ic, s.currentMilestoneId ?? "workflow");
177
+ if (guardsResult.action === "break") break;
178
+
179
+ // ── Unit execution (shared with dev path) ──
180
+ const unitPhaseResult = await runUnitPhase(ic, iterData, loopState);
181
+ if (unitPhaseResult.action === "break") break;
182
+
183
+ // ── Verify first, then reconcile (only mark complete on pass) ──
184
+ debugLog("autoLoop", { phase: "custom-engine-verify", iteration, unitId: iterData.unitId });
185
+ const verifyResult = await policy.verify(iterData.unitType, iterData.unitId, { basePath: s.basePath });
186
+ if (verifyResult === "pause") {
187
+ await deps.pauseAuto(ctx, pi);
188
+ break;
189
+ }
190
+ if (verifyResult === "retry") {
191
+ debugLog("autoLoop", { phase: "custom-engine-verify-retry", iteration, unitId: iterData.unitId });
192
+ continue;
193
+ }
194
+
195
+ // Verification passed — mark step complete
196
+ debugLog("autoLoop", { phase: "custom-engine-reconcile", iteration, unitId: iterData.unitId });
197
+ await engine.reconcile(engineState, {
198
+ unitType: iterData.unitType,
199
+ unitId: iterData.unitId,
200
+ startedAt: s.currentUnit?.startedAt ?? Date.now(),
201
+ finishedAt: Date.now(),
202
+ });
203
+
204
+ deps.clearUnitTimeout();
205
+ consecutiveErrors = 0;
206
+ deps.emitJournalEvent({ ts: new Date().toISOString(), flowId, seq: nextSeq(), eventType: "iteration-end", data: { iteration } });
207
+ debugLog("autoLoop", { phase: "iteration-complete", iteration });
208
+ continue;
209
+ }
210
+
120
211
  if (!sidecarItem) {
121
212
  // ── Phase 1: Pre-dispatch ─────────────────────────────────────────
122
213
  const preDispatchResult = await runPreDispatch(ic, loopState);
@@ -1133,9 +1133,9 @@ export async function runUnitPhase(
1133
1133
  );
1134
1134
  }
1135
1135
 
1136
- const isHookUnit = unitType.startsWith("hook/");
1136
+ const skipArtifactVerification = unitType.startsWith("hook/") || unitType === "custom-step";
1137
1137
  const artifactVerified =
1138
- isHookUnit ||
1138
+ skipArtifactVerification ||
1139
1139
  deps.verifyExpectedArtifact(unitType, unitId, s.basePath);
1140
1140
  if (artifactVerified) {
1141
1141
  s.completedUnits.push({
@@ -83,6 +83,8 @@ export class AutoSession {
83
83
  paused = false;
84
84
  stepMode = false;
85
85
  verbose = false;
86
+ activeEngineId: string | null = null;
87
+ activeRunDir: string | null = null;
86
88
  cmdCtx: ExtensionCommandContext | null = null;
87
89
 
88
90
  // ── Paths ────────────────────────────────────────────────────────────────
@@ -174,6 +176,8 @@ export class AutoSession {
174
176
  this.paused = false;
175
177
  this.stepMode = false;
176
178
  this.verbose = false;
179
+ this.activeEngineId = null;
180
+ this.activeRunDir = null;
177
181
  this.cmdCtx = null;
178
182
 
179
183
  // Paths
@@ -226,6 +230,8 @@ export class AutoSession {
226
230
  paused: this.paused,
227
231
  stepMode: this.stepMode,
228
232
  basePath: this.basePath,
233
+ activeEngineId: this.activeEngineId,
234
+ activeRunDir: this.activeRunDir,
229
235
  currentMilestoneId: this.currentMilestoneId,
230
236
  currentUnit: this.currentUnit,
231
237
  completedUnits: this.completedUnits.length,
@@ -79,6 +79,7 @@ export function unitVerb(unitType: string): string {
79
79
  case "rewrite-docs": return "rewriting";
80
80
  case "reassess-roadmap": return "reassessing";
81
81
  case "run-uat": return "running UAT";
82
+ case "custom-step": return "executing workflow step";
82
83
  default: return unitType;
83
84
  }
84
85
  }
@@ -97,6 +98,7 @@ export function unitPhaseLabel(unitType: string): string {
97
98
  case "rewrite-docs": return "REWRITE";
98
99
  case "reassess-roadmap": return "REASSESS";
99
100
  case "run-uat": return "UAT";
101
+ case "custom-step": return "WORKFLOW";
100
102
  default: return unitType.toUpperCase();
101
103
  }
102
104
  }
@@ -358,6 +358,22 @@ export function isAutoPaused(): boolean {
358
358
  return s.paused;
359
359
  }
360
360
 
361
+ export function setActiveEngineId(id: string | null): void {
362
+ s.activeEngineId = id;
363
+ }
364
+
365
+ export function getActiveEngineId(): string | null {
366
+ return s.activeEngineId;
367
+ }
368
+
369
+ export function setActiveRunDir(runDir: string | null): void {
370
+ s.activeRunDir = runDir;
371
+ }
372
+
373
+ export function getActiveRunDir(): string | null {
374
+ return s.activeRunDir;
375
+ }
376
+
361
377
  /**
362
378
  * Return the model captured at auto-mode start for this session.
363
379
  * Used by error-recovery to fall back to the session's own model
@@ -782,6 +798,8 @@ export async function pauseAuto(
782
798
  stepMode: s.stepMode,
783
799
  pausedAt: new Date().toISOString(),
784
800
  sessionFile: s.pausedSessionFile,
801
+ activeEngineId: s.activeEngineId,
802
+ activeRunDir: s.activeRunDir,
785
803
  };
786
804
  const runtimeDir = join(gsdRoot(s.originalBasePath || s.basePath), "runtime");
787
805
  mkdirSync(runtimeDir, { recursive: true });
@@ -1018,7 +1036,19 @@ export async function startAuto(
1018
1036
  const pausedPath = join(gsdRoot(base), "runtime", "paused-session.json");
1019
1037
  if (existsSync(pausedPath)) {
1020
1038
  const meta = JSON.parse(readFileSync(pausedPath, "utf-8"));
1021
- if (meta.milestoneId) {
1039
+ if (meta.activeEngineId && meta.activeEngineId !== "dev") {
1040
+ // Custom workflow resume — restore engine state
1041
+ s.activeEngineId = meta.activeEngineId;
1042
+ s.activeRunDir = meta.activeRunDir ?? null;
1043
+ s.originalBasePath = meta.originalBasePath || base;
1044
+ s.stepMode = meta.stepMode ?? requestedStepMode;
1045
+ s.paused = true;
1046
+ try { unlinkSync(pausedPath); } catch { /* non-fatal */ }
1047
+ ctx.ui.notify(
1048
+ `Resuming paused custom workflow${meta.activeRunDir ? ` (${meta.activeRunDir})` : ""}.`,
1049
+ "info",
1050
+ );
1051
+ } else if (meta.milestoneId) {
1022
1052
  // Validate the milestone still exists and isn't already complete (#1664).
1023
1053
  const mDir = resolveMilestonePath(base, meta.milestoneId);
1024
1054
  const summaryFile = resolveMilestoneFile(base, meta.milestoneId, "SUMMARY");
@@ -24,8 +24,15 @@ let enabled = true;
24
24
  function hashToolCall(toolName: string, args: Record<string, unknown>): string {
25
25
  const h = createHash("sha256");
26
26
  h.update(toolName);
27
- // Sort keys for deterministic hashing regardless of object key order
28
- h.update(JSON.stringify(args, Object.keys(args).sort()));
27
+ // Sort keys recursively for deterministic hashing regardless of object key order
28
+ h.update(JSON.stringify(args, (_key, value) =>
29
+ value && typeof value === "object" && !Array.isArray(value)
30
+ ? Object.keys(value).sort().reduce<Record<string, unknown>>((o, k) => {
31
+ o[k] = value[k];
32
+ return o;
33
+ }, {})
34
+ : value
35
+ ));
29
36
  return h.digest("hex").slice(0, 16);
30
37
  }
31
38
 
@@ -3,6 +3,7 @@ import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
 
5
5
  import { loadRegistry } from "../workflow-templates.js";
6
+ import { resolveProjectRoot } from "../worktree.js";
6
7
 
7
8
  const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
8
9
 
@@ -65,6 +66,7 @@ export const TOP_LEVEL_SUBCOMMANDS: readonly GsdCommandDefinition[] = [
65
66
  { cmd: "templates", desc: "List available workflow templates" },
66
67
  { cmd: "extensions", desc: "Manage extensions (list, enable, disable, info)" },
67
68
  { cmd: "fast", desc: "Toggle OpenAI service tier (on/off/flex/status)" },
69
+ { cmd: "workflow", desc: "Custom workflow lifecycle (new, run, list, validate, pause, resume)" },
68
70
  ];
69
71
 
70
72
  const NESTED_COMPLETIONS: CompletionMap = {
@@ -206,6 +208,14 @@ const NESTED_COMPLETIONS: CompletionMap = {
206
208
  { cmd: "ok", desc: "Model was appropriate for this task" },
207
209
  { cmd: "under", desc: "Model was underqualified for this task" },
208
210
  ],
211
+ workflow: [
212
+ { cmd: "new", desc: "Create a new workflow definition (via skill)" },
213
+ { cmd: "run", desc: "Create a run and start auto-mode" },
214
+ { cmd: "list", desc: "List workflow runs" },
215
+ { cmd: "validate", desc: "Validate a workflow definition YAML" },
216
+ { cmd: "pause", desc: "Pause custom workflow auto-mode" },
217
+ { cmd: "resume", desc: "Resume paused custom workflow auto-mode" },
218
+ ],
209
219
  };
210
220
 
211
221
  function filterOptions(
@@ -309,6 +319,28 @@ export function getGsdArgumentCompletions(prefix: string) {
309
319
  return [{ value: "undo --force", label: "--force", description: "Skip confirmation prompt" }];
310
320
  }
311
321
 
322
+ // Workflow definition-name completion for `workflow run <name>` and `workflow validate <name>`
323
+ if (command === "workflow" && (subcommand === "run" || subcommand === "validate") && parts.length <= 3) {
324
+ try {
325
+ const defsDir = join(resolveProjectRoot(process.cwd()), ".gsd", "workflow-defs");
326
+ if (existsSync(defsDir)) {
327
+ return readdirSync(defsDir)
328
+ .filter((f) => f.endsWith(".yaml") && f.startsWith(third))
329
+ .map((f) => {
330
+ const name = f.replace(/\.yaml$/, "");
331
+ return {
332
+ value: `workflow ${subcommand} ${name}`,
333
+ label: name,
334
+ description: `Workflow definition: ${name}`,
335
+ };
336
+ });
337
+ }
338
+ } catch {
339
+ // ignore filesystem errors during completion
340
+ }
341
+ return [];
342
+ }
343
+
312
344
  const nested = NESTED_COMPLETIONS[command];
313
345
  if (nested && parts.length <= 2) {
314
346
  return filterOptions(subcommand, nested, command);
@@ -2,6 +2,7 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent
2
2
 
3
3
  import { existsSync, readFileSync, unlinkSync } from "node:fs";
4
4
  import { join } from "node:path";
5
+ import { parse as parseYaml } from "yaml";
5
6
 
6
7
  import { handleQuick } from "../../quick.js";
7
8
  import { showDiscuss, showHeadlessMilestoneCreation, showQueue } from "../../guided-flow.js";
@@ -13,8 +14,171 @@ import { loadEffectiveGSDPreferences } from "../../preferences.js";
13
14
  import { nextMilestoneId } from "../../milestone-ids.js";
14
15
  import { findMilestoneIds } from "../../guided-flow.js";
15
16
  import { projectRoot } from "../context.js";
17
+ import { createRun, listRuns } from "../../run-manager.js";
18
+ import {
19
+ setActiveEngineId,
20
+ setActiveRunDir,
21
+ startAuto,
22
+ pauseAuto,
23
+ isAutoActive,
24
+ getActiveEngineId,
25
+ } from "../../auto.js";
26
+ import { validateDefinition } from "../../definition-loader.js";
27
+
28
+ // ─── Custom Workflow Subcommands ─────────────────────────────────────────
29
+
30
+ const WORKFLOW_USAGE = [
31
+ "Usage: /gsd workflow <subcommand>",
32
+ "",
33
+ " new — Create a new workflow definition (via skill)",
34
+ " run <name> [k=v] — Create a run and start auto-mode",
35
+ " list [name] — List workflow runs (optionally filtered by name)",
36
+ " validate <name> — Validate a workflow definition YAML",
37
+ " pause — Pause custom workflow auto-mode",
38
+ " resume — Resume paused custom workflow auto-mode",
39
+ ].join("\n");
40
+
41
+ async function handleCustomWorkflow(
42
+ sub: string,
43
+ ctx: ExtensionCommandContext,
44
+ pi: ExtensionAPI,
45
+ ): Promise<boolean> {
46
+ // Bare `/gsd workflow` — show usage
47
+ if (!sub) {
48
+ ctx.ui.notify(WORKFLOW_USAGE, "info");
49
+ return true;
50
+ }
51
+
52
+ // ── new ──
53
+ if (sub === "new") {
54
+ ctx.ui.notify("Use the create-workflow skill: /skill create-workflow", "info");
55
+ return true;
56
+ }
57
+
58
+ // ── run <name> [param=value ...] ──
59
+ if (sub === "run" || sub.startsWith("run ")) {
60
+ const args = sub.slice("run".length).trim();
61
+ if (!args) {
62
+ ctx.ui.notify("Usage: /gsd workflow run <name> [param=value ...]", "warning");
63
+ return true;
64
+ }
65
+ const parts = args.split(/\s+/);
66
+ const defName = parts[0];
67
+ const overrides: Record<string, string> = {};
68
+ for (let i = 1; i < parts.length; i++) {
69
+ const eqIdx = parts[i].indexOf("=");
70
+ if (eqIdx > 0) {
71
+ overrides[parts[i].slice(0, eqIdx)] = parts[i].slice(eqIdx + 1);
72
+ }
73
+ }
74
+ try {
75
+ const base = projectRoot();
76
+ const runDir = createRun(base, defName, Object.keys(overrides).length > 0 ? overrides : undefined);
77
+ setActiveEngineId("custom");
78
+ setActiveRunDir(runDir);
79
+ ctx.ui.notify(`Created workflow run: ${defName}\nRun dir: ${runDir}`, "info");
80
+ await startAuto(ctx, pi, base, false);
81
+ } catch (err) {
82
+ // Clean up engine state so a failed workflow run doesn't pollute the next /gsd auto
83
+ setActiveEngineId(null);
84
+ setActiveRunDir(null);
85
+ const msg = err instanceof Error ? err.message : String(err);
86
+ ctx.ui.notify(`Failed to run workflow "${defName}": ${msg}`, "error");
87
+ }
88
+ return true;
89
+ }
90
+
91
+ // ── list [name] ──
92
+ if (sub === "list" || sub.startsWith("list ")) {
93
+ const filterName = sub.slice("list".length).trim() || undefined;
94
+ const base = projectRoot();
95
+ const runs = listRuns(base, filterName);
96
+ if (runs.length === 0) {
97
+ ctx.ui.notify("No workflow runs found.", "info");
98
+ return true;
99
+ }
100
+ const lines = runs.map((r) => {
101
+ const stepInfo = `${r.steps.completed}/${r.steps.total} steps`;
102
+ return `• ${r.name} [${r.timestamp}] — ${r.status} (${stepInfo})`;
103
+ });
104
+ ctx.ui.notify(lines.join("\n"), "info");
105
+ return true;
106
+ }
107
+
108
+ // ── validate <name> ──
109
+ if (sub === "validate" || sub.startsWith("validate ")) {
110
+ const defName = sub.slice("validate".length).trim();
111
+ if (!defName) {
112
+ ctx.ui.notify("Usage: /gsd workflow validate <name>", "warning");
113
+ return true;
114
+ }
115
+ const base = projectRoot();
116
+ const defPath = join(base, ".gsd", "workflow-defs", `${defName}.yaml`);
117
+ if (!existsSync(defPath)) {
118
+ ctx.ui.notify(`Definition not found: ${defPath}`, "error");
119
+ return true;
120
+ }
121
+ try {
122
+ const raw = readFileSync(defPath, "utf-8");
123
+ const parsed = parseYaml(raw);
124
+ const result = validateDefinition(parsed);
125
+ if (result.valid) {
126
+ ctx.ui.notify(`✓ "${defName}" is a valid workflow definition.`, "info");
127
+ } else {
128
+ ctx.ui.notify(`✗ "${defName}" has errors:\n - ${result.errors.join("\n - ")}`, "error");
129
+ }
130
+ } catch (err) {
131
+ const msg = err instanceof Error ? err.message : String(err);
132
+ ctx.ui.notify(`Failed to validate "${defName}": ${msg}`, "error");
133
+ }
134
+ return true;
135
+ }
136
+
137
+ // ── pause ──
138
+ if (sub === "pause") {
139
+ const engineId = getActiveEngineId();
140
+ if (engineId === "dev" || engineId === null) {
141
+ ctx.ui.notify("No custom workflow is running. Use /gsd pause for dev workflow.", "warning");
142
+ return true;
143
+ }
144
+ if (!isAutoActive()) {
145
+ ctx.ui.notify("Auto-mode is not active.", "warning");
146
+ return true;
147
+ }
148
+ await pauseAuto(ctx, pi);
149
+ ctx.ui.notify("Custom workflow paused.", "info");
150
+ return true;
151
+ }
152
+
153
+ // ── resume ──
154
+ if (sub === "resume") {
155
+ const engineId = getActiveEngineId();
156
+ if (engineId === "dev" || engineId === null) {
157
+ ctx.ui.notify("No custom workflow to resume. Use /gsd auto for dev workflow.", "warning");
158
+ return true;
159
+ }
160
+ try {
161
+ await startAuto(ctx, pi, projectRoot(), false);
162
+ ctx.ui.notify("Custom workflow resumed.", "info");
163
+ } catch (err) {
164
+ const msg = err instanceof Error ? err.message : String(err);
165
+ ctx.ui.notify(`Failed to resume workflow: ${msg}`, "error");
166
+ }
167
+ return true;
168
+ }
169
+
170
+ // Unknown subcommand — show usage
171
+ ctx.ui.notify(`Unknown workflow subcommand: "${sub}"\n\n${WORKFLOW_USAGE}`, "warning");
172
+ return true;
173
+ }
16
174
 
17
175
  export async function handleWorkflowCommand(trimmed: string, ctx: ExtensionCommandContext, pi: ExtensionAPI): Promise<boolean> {
176
+ // ── Custom workflow commands (`/gsd workflow ...`) ──
177
+ if (trimmed === "workflow" || trimmed.startsWith("workflow ")) {
178
+ const sub = trimmed.slice("workflow".length).trim();
179
+ return handleCustomWorkflow(sub, ctx, pi);
180
+ }
181
+
18
182
  if (trimmed === "queue") {
19
183
  await showQueue(ctx, pi, projectRoot());
20
184
  return true;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * context-injector.ts — Inject prior step artifacts as context into step prompts.
3
+ *
4
+ * Reads the frozen DEFINITION.yaml from a run directory, finds the current step's
5
+ * `contextFrom` references, locates each referenced step's `produces` artifacts
6
+ * on disk, reads their content (truncated to 10k chars), and prepends formatted
7
+ * context blocks to the step prompt.
8
+ *
9
+ * Observability:
10
+ * - Truncation is logged via console.warn when it occurs, preventing silent overflow.
11
+ * - Missing artifact files are skipped silently (the step may not have produced them yet).
12
+ * - Unknown step IDs in contextFrom produce a console.warn for diagnosis.
13
+ * - The frozen DEFINITION.yaml on disk is the single source of truth for contextFrom config.
14
+ */
15
+
16
+ import { readFileSync, existsSync } from "node:fs";
17
+ import { join, resolve, sep } from "node:path";
18
+ import type { StepDefinition } from "./definition-loader.js";
19
+ import { readFrozenDefinition } from "./custom-workflow-engine.js";
20
+
21
+ /** Maximum characters per artifact to prevent context window blowout. */
22
+ const MAX_CONTEXT_CHARS = 10_000;
23
+
24
+ /**
25
+ * Inject context from prior step artifacts into a step's prompt.
26
+ *
27
+ * Reads the frozen DEFINITION.yaml from `runDir`, finds the step matching
28
+ * `stepId`, and for each step ID in its `contextFrom` array, looks up that
29
+ * step's `produces` paths, reads them from disk (relative to `runDir`),
30
+ * truncates to MAX_CONTEXT_CHARS, and prepends as labeled context blocks.
31
+ *
32
+ * @param runDir — absolute path to the workflow run directory
33
+ * @param stepId — the step ID whose prompt to enrich
34
+ * @param prompt — the original step prompt
35
+ * @returns The prompt with context blocks prepended, or unchanged if no context applies
36
+ * @throws Error if DEFINITION.yaml is missing or unreadable
37
+ */
38
+ export function injectContext(
39
+ runDir: string,
40
+ stepId: string,
41
+ prompt: string,
42
+ ): string {
43
+ const def = readFrozenDefinition(runDir);
44
+
45
+ const step = def.steps.find((s: StepDefinition) => s.id === stepId);
46
+ if (!step || !step.contextFrom || step.contextFrom.length === 0) {
47
+ return prompt;
48
+ }
49
+
50
+ const contextBlocks: string[] = [];
51
+
52
+ for (const refStepId of step.contextFrom) {
53
+ const refStep = def.steps.find((s: StepDefinition) => s.id === refStepId);
54
+ if (!refStep) {
55
+ console.warn(
56
+ `context-injector: step "${stepId}" references unknown step "${refStepId}" in contextFrom — skipping`,
57
+ );
58
+ continue;
59
+ }
60
+
61
+ if (!refStep.produces || refStep.produces.length === 0) {
62
+ continue;
63
+ }
64
+
65
+ for (const relPath of refStep.produces) {
66
+ const absPath = resolve(runDir, relPath);
67
+ // Path traversal guard: ensure resolved path stays within runDir
68
+ if (!absPath.startsWith(resolve(runDir) + sep) && absPath !== resolve(runDir)) {
69
+ console.warn(
70
+ `context-injector: artifact path "${relPath}" resolves outside runDir — skipping`,
71
+ );
72
+ continue;
73
+ }
74
+ if (!existsSync(absPath)) {
75
+ // Artifact not yet produced or optional — skip silently
76
+ continue;
77
+ }
78
+
79
+ let content = readFileSync(absPath, "utf-8");
80
+
81
+ if (content.length > MAX_CONTEXT_CHARS) {
82
+ console.warn(
83
+ `context-injector: truncating artifact "${relPath}" from step "${refStepId}" ` +
84
+ `(${content.length} chars → ${MAX_CONTEXT_CHARS} chars)`,
85
+ );
86
+ content = content.slice(0, MAX_CONTEXT_CHARS) + "\n...[truncated]";
87
+ }
88
+
89
+ contextBlocks.push(
90
+ `--- Context from step "${refStepId}" (file: ${relPath}) ---\n${content}\n---`,
91
+ );
92
+ }
93
+ }
94
+
95
+ if (contextBlocks.length === 0) {
96
+ return prompt;
97
+ }
98
+
99
+ return contextBlocks.join("\n\n") + "\n\n" + prompt;
100
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * custom-execution-policy.ts — ExecutionPolicy for custom workflows.
3
+ *
4
+ * Delegates verification to the step-level verification module which reads
5
+ * the frozen DEFINITION.yaml and dispatches to the appropriate policy handler.
6
+ *
7
+ * Observability:
8
+ * - verify() returns the outcome from runCustomVerification() — four policies
9
+ * are supported: content-heuristic, shell-command, prompt-verify, human-review.
10
+ * - selectModel() returns null — defers to loop defaults.
11
+ * - recover() returns retry — simple default recovery strategy.
12
+ */
13
+
14
+ import type { ExecutionPolicy } from "./execution-policy.js";
15
+ import type { RecoveryAction, CloseoutResult } from "./engine-types.js";
16
+ import { runCustomVerification } from "./custom-verification.js";
17
+
18
+ export class CustomExecutionPolicy implements ExecutionPolicy {
19
+ private readonly runDir: string;
20
+
21
+ constructor(runDir: string) {
22
+ this.runDir = runDir;
23
+ }
24
+
25
+ /** No workspace preparation needed for custom workflows. */
26
+ async prepareWorkspace(_basePath: string, _milestoneId: string): Promise<void> {
27
+ // No-op — custom workflows don't need worktree setup
28
+ }
29
+
30
+ /** Defer model selection to loop defaults. */
31
+ async selectModel(
32
+ _unitType: string,
33
+ _unitId: string,
34
+ _context: { basePath: string },
35
+ ): Promise<{ tier: string; modelDowngraded: boolean } | null> {
36
+ return null;
37
+ }
38
+
39
+ /**
40
+ * Verify step output by dispatching to the step's configured verification policy.
41
+ *
42
+ * Extracts the step ID from unitId (format: "<workflowName>/<stepId>")
43
+ * and calls runCustomVerification() which reads the frozen DEFINITION.yaml
44
+ * to determine which policy to apply.
45
+ */
46
+ async verify(
47
+ _unitType: string,
48
+ unitId: string,
49
+ _context: { basePath: string },
50
+ ): Promise<"continue" | "retry" | "pause"> {
51
+ const parts = unitId.split("/");
52
+ const stepId = parts[parts.length - 1];
53
+ return runCustomVerification(this.runDir, stepId);
54
+ }
55
+
56
+ /** Default recovery: retry the step. */
57
+ async recover(
58
+ _unitType: string,
59
+ _unitId: string,
60
+ _context: { basePath: string },
61
+ ): Promise<RecoveryAction> {
62
+ return { outcome: "retry", reason: "Default retry" };
63
+ }
64
+
65
+ /** No-op closeout — no commits or artifact capture. */
66
+ async closeout(
67
+ _unitType: string,
68
+ _unitId: string,
69
+ _context: { basePath: string; startedAt: number },
70
+ ): Promise<CloseoutResult> {
71
+ return { committed: false, artifacts: [] };
72
+ }
73
+ }