gsd-pi 2.73.1-dev.1040fb0 → 2.73.1-dev.49397e5

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 (192) hide show
  1. package/dist/cli-web-branch.d.ts +4 -3
  2. package/dist/cli-web-branch.js +10 -7
  3. package/dist/cli.js +99 -206
  4. package/dist/headless-query.js +4 -1
  5. package/dist/logo.d.ts +1 -1
  6. package/dist/logo.js +1 -1
  7. package/dist/onboarding.js +59 -53
  8. package/dist/resource-loader.js +2 -2
  9. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +59 -1
  10. package/dist/resources/extensions/gsd/auto/detect-stuck.js +11 -4
  11. package/dist/resources/extensions/gsd/auto/phases.js +60 -10
  12. package/dist/resources/extensions/gsd/auto-dispatch.js +11 -3
  13. package/dist/resources/extensions/gsd/auto-post-unit.js +93 -57
  14. package/dist/resources/extensions/gsd/auto-start.js +3 -0
  15. package/dist/resources/extensions/gsd/auto-timeout-recovery.js +13 -0
  16. package/dist/resources/extensions/gsd/auto-verification.js +88 -3
  17. package/dist/resources/extensions/gsd/auto.js +37 -10
  18. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +21 -8
  19. package/dist/resources/extensions/gsd/commands/catalog.js +26 -1
  20. package/dist/resources/extensions/gsd/commands/handlers/ops.js +20 -0
  21. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +68 -9
  22. package/dist/resources/extensions/gsd/commands-add-tests.js +111 -0
  23. package/dist/resources/extensions/gsd/commands-backlog.js +140 -0
  24. package/dist/resources/extensions/gsd/commands-do.js +79 -0
  25. package/dist/resources/extensions/gsd/commands-maintenance.js +6 -6
  26. package/dist/resources/extensions/gsd/commands-pr-branch.js +180 -0
  27. package/dist/resources/extensions/gsd/commands-session-report.js +82 -0
  28. package/dist/resources/extensions/gsd/commands-ship.js +187 -0
  29. package/dist/resources/extensions/gsd/db-writer.js +3 -5
  30. package/dist/resources/extensions/gsd/docs/preferences-reference.md +1 -1
  31. package/dist/resources/extensions/gsd/gsd-db.js +321 -0
  32. package/dist/resources/extensions/gsd/index.js +15 -2
  33. package/dist/resources/extensions/gsd/md-importer.js +3 -4
  34. package/dist/resources/extensions/gsd/memory-store.js +19 -51
  35. package/dist/resources/extensions/gsd/milestone-validation-gates.js +13 -12
  36. package/dist/resources/extensions/gsd/native-git-bridge.js +7 -4
  37. package/dist/resources/extensions/gsd/notification-widget.js +2 -2
  38. package/dist/resources/extensions/gsd/prompts/add-tests.md +35 -0
  39. package/dist/resources/extensions/gsd/state.js +66 -15
  40. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +3 -14
  41. package/dist/resources/extensions/gsd/triage-resolution.js +2 -5
  42. package/dist/resources/extensions/gsd/workflow-manifest.js +8 -69
  43. package/dist/resources/extensions/gsd/workflow-migration.js +21 -22
  44. package/dist/resources/extensions/gsd/workflow-projections.js +4 -1
  45. package/dist/resources/extensions/gsd/workflow-reconcile.js +14 -11
  46. package/dist/tsconfig.extensions.tsbuildinfo +1 -0
  47. package/dist/web/standalone/.next/BUILD_ID +1 -1
  48. package/dist/web/standalone/.next/app-path-routes-manifest.json +14 -14
  49. package/dist/web/standalone/.next/build-manifest.json +2 -2
  50. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  51. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  52. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  60. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  65. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  66. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  67. package/dist/web/standalone/.next/server/app/index.html +1 -1
  68. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  70. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app-paths-manifest.json +14 -14
  75. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  76. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  77. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  78. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  79. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  80. package/package.json +3 -3
  81. package/packages/mcp-server/tsconfig.json +1 -0
  82. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -0
  83. package/packages/native/tsconfig.tsbuildinfo +1 -0
  84. package/packages/pi-agent-core/tsconfig.json +1 -0
  85. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -0
  86. package/packages/pi-ai/tsconfig.json +1 -0
  87. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -0
  88. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +138 -0
  89. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  90. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  91. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +10 -2
  92. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  93. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts +2 -1
  94. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  95. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +9 -3
  96. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  97. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts +2 -0
  98. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.d.ts.map +1 -0
  99. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js +52 -0
  100. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.test.js.map +1 -0
  101. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  102. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +21 -4
  103. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  104. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  105. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +11 -3
  106. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  107. package/packages/pi-coding-agent/package.json +1 -1
  108. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +157 -0
  109. package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +12 -6
  110. package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.test.ts +73 -0
  111. package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.ts +9 -3
  112. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +21 -4
  113. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +11 -3
  114. package/packages/pi-coding-agent/tsconfig.json +1 -0
  115. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -0
  116. package/packages/pi-tui/dist/__tests__/tui.test.js +60 -1
  117. package/packages/pi-tui/dist/__tests__/tui.test.js.map +1 -1
  118. package/packages/pi-tui/dist/tui.d.ts +8 -0
  119. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  120. package/packages/pi-tui/dist/tui.js +32 -3
  121. package/packages/pi-tui/dist/tui.js.map +1 -1
  122. package/packages/pi-tui/src/__tests__/tui.test.ts +76 -1
  123. package/packages/pi-tui/src/tui.ts +31 -3
  124. package/packages/pi-tui/tsconfig.json +1 -0
  125. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -0
  126. package/packages/rpc-client/tsconfig.json +1 -0
  127. package/packages/rpc-client/tsconfig.tsbuildinfo +1 -0
  128. package/pkg/package.json +1 -1
  129. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +95 -1
  130. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +88 -0
  131. package/src/resources/extensions/gsd/auto/detect-stuck.ts +12 -4
  132. package/src/resources/extensions/gsd/auto/loop-deps.ts +6 -0
  133. package/src/resources/extensions/gsd/auto/phases.ts +90 -10
  134. package/src/resources/extensions/gsd/auto-dispatch.ts +10 -4
  135. package/src/resources/extensions/gsd/auto-post-unit.ts +107 -58
  136. package/src/resources/extensions/gsd/auto-start.ts +3 -0
  137. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +17 -0
  138. package/src/resources/extensions/gsd/auto-verification.ts +98 -3
  139. package/src/resources/extensions/gsd/auto.ts +38 -14
  140. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +24 -8
  141. package/src/resources/extensions/gsd/commands/catalog.ts +26 -1
  142. package/src/resources/extensions/gsd/commands/handlers/ops.ts +20 -0
  143. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +74 -9
  144. package/src/resources/extensions/gsd/commands-add-tests.ts +137 -0
  145. package/src/resources/extensions/gsd/commands-backlog.ts +182 -0
  146. package/src/resources/extensions/gsd/commands-do.ts +109 -0
  147. package/src/resources/extensions/gsd/commands-maintenance.ts +6 -6
  148. package/src/resources/extensions/gsd/commands-pr-branch.ts +234 -0
  149. package/src/resources/extensions/gsd/commands-session-report.ts +101 -0
  150. package/src/resources/extensions/gsd/commands-ship.ts +219 -0
  151. package/src/resources/extensions/gsd/db-writer.ts +3 -5
  152. package/src/resources/extensions/gsd/docs/preferences-reference.md +1 -1
  153. package/src/resources/extensions/gsd/gsd-db.ts +467 -0
  154. package/src/resources/extensions/gsd/index.ts +18 -2
  155. package/src/resources/extensions/gsd/md-importer.ts +3 -5
  156. package/src/resources/extensions/gsd/memory-store.ts +31 -62
  157. package/src/resources/extensions/gsd/milestone-validation-gates.ts +13 -14
  158. package/src/resources/extensions/gsd/native-git-bridge.ts +11 -12
  159. package/src/resources/extensions/gsd/notification-widget.ts +2 -2
  160. package/src/resources/extensions/gsd/prompts/add-tests.md +35 -0
  161. package/src/resources/extensions/gsd/state.ts +80 -17
  162. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +2 -2
  163. package/src/resources/extensions/gsd/tests/auto-post-unit-step-message.test.ts +53 -0
  164. package/src/resources/extensions/gsd/tests/commands-backlog.test.ts +158 -0
  165. package/src/resources/extensions/gsd/tests/commands-do.test.ts +127 -0
  166. package/src/resources/extensions/gsd/tests/commands-pr-branch.test.ts +68 -0
  167. package/src/resources/extensions/gsd/tests/commands-session-report.test.ts +82 -0
  168. package/src/resources/extensions/gsd/tests/commands-ship.test.ts +71 -0
  169. package/src/resources/extensions/gsd/tests/commands-workflow-custom.test.ts +14 -0
  170. package/src/resources/extensions/gsd/tests/complete-milestone-false-merge.test.ts +142 -0
  171. package/src/resources/extensions/gsd/tests/completed-at-reconcile.test.ts +42 -0
  172. package/src/resources/extensions/gsd/tests/derive-state-crossval.test.ts +3 -2
  173. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +3 -2
  174. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +68 -8
  175. package/src/resources/extensions/gsd/tests/derive-state.test.ts +3 -3
  176. package/src/resources/extensions/gsd/tests/extension-bootstrap-isolation.test.ts +154 -0
  177. package/src/resources/extensions/gsd/tests/integration/state-machine-edge-cases.test.ts +4 -2
  178. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +68 -1
  179. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +140 -0
  180. package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +180 -0
  181. package/src/resources/extensions/gsd/tests/state-machine-full-walkthrough.test.ts +5 -7
  182. package/src/resources/extensions/gsd/tests/token-profile.test.ts +1 -1
  183. package/src/resources/extensions/gsd/tests/validate-milestone-stuck-guard.test.ts +179 -0
  184. package/src/resources/extensions/gsd/tests/workflow-logger-wiring.test.ts +223 -0
  185. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +3 -11
  186. package/src/resources/extensions/gsd/triage-resolution.ts +2 -7
  187. package/src/resources/extensions/gsd/workflow-manifest.ts +9 -104
  188. package/src/resources/extensions/gsd/workflow-migration.ts +21 -29
  189. package/src/resources/extensions/gsd/workflow-projections.ts +8 -1
  190. package/src/resources/extensions/gsd/workflow-reconcile.ts +15 -15
  191. /package/dist/web/standalone/.next/static/{5dzOW4v8Vz23I5xRsiNSk → tAsSblRKK1lG7MVOwsO92}/_buildManifest.js +0 -0
  192. /package/dist/web/standalone/.next/static/{5dzOW4v8Vz23I5xRsiNSk → tAsSblRKK1lG7MVOwsO92}/_ssgManifest.js +0 -0
@@ -632,6 +632,9 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
632
632
  }
633
633
  ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
634
634
  ctx.ui.setFooter(hideFooter);
635
+ // Hide gsd-health during AUTO — gsd-progress is the single source of truth
636
+ // for last-commit / cost / health signal while auto is running.
637
+ ctx.ui.setWidget("gsd-health", undefined);
635
638
  const modeLabel = s.stepMode ? "Step-mode" : "Auto-mode";
636
639
  const pendingCount = (state.registry ?? []).filter((m) => m.status !== "complete" && m.status !== "parked").length;
637
640
  const scopeMsg = pendingCount > 1
@@ -156,6 +156,19 @@ export async function recoverTimedOutUnit(ctx, pi, unitType, unitId, reason, rct
156
156
  ctx.ui.notify(`${reason === "idle" ? "Idle" : "Timeout"} recovery: steering ${unitType} ${unitId} to produce ${expected} (attempt ${attemptNumber}, session ${recoveryAttempts + 1}/${maxRecoveryAttempts}).`, "warning");
157
157
  return "recovered";
158
158
  }
159
+ // #4175: For complete-milestone, never write a blocker placeholder — a stub
160
+ // SUMMARY has no recovery value (milestone is terminal), it does not update
161
+ // DB status, and downstream merge paths can treat the stub as a legitimate
162
+ // completion signal. Pause instead so the worktree branch is preserved.
163
+ if (unitType === "complete-milestone") {
164
+ writeUnitRuntimeRecord(basePath, unitType, unitId, currentUnitStartedAt, {
165
+ phase: "paused",
166
+ recoveryAttempts: recoveryAttempts + 1,
167
+ lastRecoveryReason: reason,
168
+ });
169
+ ctx.ui.notify(`Milestone ${unitId} ${reason}-recovery exhausted ${maxRecoveryAttempts} attempt(s) — worktree branch preserved. Re-run /gsd auto once blockers are resolved.`, "error");
170
+ return "paused";
171
+ }
159
172
  // Retries exhausted — write a blocker placeholder and advance the pipeline
160
173
  // instead of silently stalling.
161
174
  const placeholder = writeBlockerPlaceholder(unitType, unitId, basePath, `${reason} recovery exhausted ${maxRecoveryAttempts} attempts without producing the artifact.`);
@@ -10,10 +10,15 @@
10
10
  * checks the result and handles control flow.
11
11
  */
12
12
  import { mkdirSync, writeFileSync } from "node:fs";
13
- import { resolveSlicePath } from "./paths.js";
13
+ import { resolveSlicePath, resolveMilestoneFile } from "./paths.js";
14
14
  import { parseUnitId } from "./unit-id.js";
15
- import { isDbAvailable, getTask, getSliceTasks } from "./gsd-db.js";
15
+ import { isDbAvailable, getTask, getSliceTasks, getMilestoneSlices } from "./gsd-db.js";
16
16
  import { loadEffectiveGSDPreferences } from "./preferences.js";
17
+ import { extractVerdict } from "./verdict-parser.js";
18
+ import { isClosedStatus } from "./status-guards.js";
19
+ import { loadFile } from "./files.js";
20
+ import { parseRoadmap } from "./parsers-legacy.js";
21
+ import { isMilestoneComplete } from "./state.js";
17
22
  import { runVerificationGate, formatFailureContext, captureRuntimeErrors, runDependencyAudit, } from "./verification-gate.js";
18
23
  import { writeVerificationJSON } from "./verification-evidence.js";
19
24
  import { logWarning } from "./workflow-logger.js";
@@ -22,6 +27,80 @@ import { join } from "node:path";
22
27
  function isInfraVerificationFailure(stderr) {
23
28
  return /\b(ENOENT|ENOTFOUND|ETIMEDOUT|ECONNRESET|EAI_AGAIN|spawn\s+\S+\s+ENOENT|command not found)\b/i.test(stderr);
24
29
  }
30
+ /**
31
+ * Post-unit guard for `validate-milestone` units (#4094).
32
+ *
33
+ * When validate-milestone writes verdict=needs-remediation, the agent is
34
+ * expected to also call gsd_reassess_roadmap in the same turn to add
35
+ * remediation slices. If they don't, the state machine re-derives
36
+ * `phase: validating-milestone` indefinitely (all slices still complete +
37
+ * verdict still needs-remediation), wasting ~3 dispatches before the stuck
38
+ * detector fires.
39
+ *
40
+ * This guard fires immediately on the first occurrence: if VALIDATION.md
41
+ * verdict is needs-remediation and no incomplete slices exist for the
42
+ * milestone, pause the auto-loop with a clear blocker.
43
+ */
44
+ async function runValidateMilestonePostCheck(vctx, pauseAuto) {
45
+ const { s, ctx, pi } = vctx;
46
+ if (!s.currentUnit)
47
+ return "continue";
48
+ const { milestone: mid } = parseUnitId(s.currentUnit.id);
49
+ if (!mid)
50
+ return "continue";
51
+ const validationFile = resolveMilestoneFile(s.basePath, mid, "VALIDATION");
52
+ if (!validationFile)
53
+ return "continue";
54
+ const validationContent = await loadFile(validationFile);
55
+ if (!validationContent)
56
+ return "continue";
57
+ const verdict = extractVerdict(validationContent);
58
+ if (verdict !== "needs-remediation")
59
+ return "continue";
60
+ const incompleteSliceCount = await countIncompleteSlices(s.basePath, mid);
61
+ // If any non-closed slices exist, the agent successfully queued remediation
62
+ // work — proceed normally. The state machine will execute those slices and
63
+ // re-validate per the #3596/#3670 fix.
64
+ if (incompleteSliceCount > 0)
65
+ return "continue";
66
+ ctx.ui.notify(`Milestone ${mid} validation returned verdict=needs-remediation but no remediation slices were added. Pausing for human review.`, "error");
67
+ process.stderr.write(`validate-milestone: pausing — verdict=needs-remediation with no incomplete slices for ${mid}. ` +
68
+ `The agent must call gsd_reassess_roadmap to add remediation slices before re-validation.\n`);
69
+ await pauseAuto(ctx, pi);
70
+ return "pause";
71
+ }
72
+ /**
73
+ * Count slices for a milestone that are not in a closed status.
74
+ * DB-backed projects are authoritative (#4094 peer review); falls back to
75
+ * roadmap parsing only when the DB is unavailable.
76
+ */
77
+ async function countIncompleteSlices(basePath, milestoneId) {
78
+ if (isDbAvailable()) {
79
+ const slices = getMilestoneSlices(milestoneId);
80
+ if (slices.length === 0) {
81
+ // No DB rows — treat as "unknown", do not pause.
82
+ return 1;
83
+ }
84
+ return slices.filter((slice) => !isClosedStatus(slice.status)).length;
85
+ }
86
+ // Filesystem fallback: parse the roadmap markdown.
87
+ try {
88
+ const roadmapFile = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
89
+ if (!roadmapFile)
90
+ return 1;
91
+ const roadmapContent = await loadFile(roadmapFile);
92
+ if (!roadmapContent)
93
+ return 1;
94
+ const roadmap = parseRoadmap(roadmapContent);
95
+ if (roadmap.slices.length === 0)
96
+ return 1;
97
+ return isMilestoneComplete(roadmap) ? 0 : 1;
98
+ }
99
+ catch {
100
+ // Parsing failures should not cause false-positive pauses.
101
+ return 1;
102
+ }
103
+ }
25
104
  /**
26
105
  * Run the verification gate for the current execute-task unit.
27
106
  * Returns:
@@ -31,7 +110,13 @@ function isInfraVerificationFailure(stderr) {
31
110
  */
32
111
  export async function runPostUnitVerification(vctx, pauseAuto) {
33
112
  const { s, ctx, pi } = vctx;
34
- if (!s.currentUnit || s.currentUnit.type !== "execute-task") {
113
+ if (!s.currentUnit) {
114
+ return "continue";
115
+ }
116
+ if (s.currentUnit.type === "validate-milestone") {
117
+ return await runValidateMilestonePostCheck(vctx, pauseAuto);
118
+ }
119
+ if (s.currentUnit.type !== "execute-task") {
35
120
  return "continue";
36
121
  }
37
122
  try {
@@ -36,7 +36,7 @@ import { captureAvailableSkills, resetSkillTelemetry, } from "./skill-telemetry.
36
36
  import { getRtkSessionSavings } from "../shared/rtk-session-stats.js";
37
37
  import { deactivateGSD } from "../shared/gsd-phase-state.js";
38
38
  import { initMetrics, resetMetrics, getLedger, getProjectTotals, formatCost, formatTokenCount, } from "./metrics.js";
39
- import { logWarning } from "./workflow-logger.js";
39
+ import { setLogBasePath, logWarning } from "./workflow-logger.js";
40
40
  import { homedir } from "node:os";
41
41
  import { join } from "node:path";
42
42
  import { pathToFileURL } from "node:url";
@@ -55,14 +55,15 @@ import { initRegistry, convertDispatchRules } from "./rule-registry.js";
55
55
  import { emitJournalEvent as _emitJournalEvent } from "./journal.js";
56
56
  import { updateProgressWidget as _updateProgressWidget, updateSliceProgressCache, clearSliceProgressCache, hideFooter, } from "./auto-dashboard.js";
57
57
  import { registerSigtermHandler as _registerSigtermHandler, deregisterSigtermHandler as _deregisterSigtermHandler, } from "./auto-supervisor.js";
58
- import { isDbAvailable } from "./gsd-db.js";
58
+ import { isDbAvailable, getMilestone } from "./gsd-db.js";
59
59
  import { countPendingCaptures } from "./captures.js";
60
60
  import { clearCmuxSidebar, logCmuxEvent, syncCmuxSidebar } from "../cmux/index.js";
61
61
  // ── Extracted modules ──────────────────────────────────────────────────────
62
62
  import { startUnitSupervision } from "./auto-timers.js";
63
63
  import { runPostUnitVerification } from "./auto-verification.js";
64
- import { postUnitPreVerification, postUnitPostVerification, } from "./auto-post-unit.js";
64
+ import { autoCommitUnit, postUnitPreVerification, postUnitPostVerification, } from "./auto-post-unit.js";
65
65
  import { bootstrapAutoSession, openProjectDbIfPresent } from "./auto-start.js";
66
+ import { initHealthWidget } from "./health-widget.js";
66
67
  import { autoLoop, resolveAgentEnd, resolveAgentEndCancelled, _resetPendingResolve, isSessionSwitchInFlight } from "./auto-loop.js";
67
68
  import { WorktreeResolver, } from "./worktree-resolver.js";
68
69
  import { reorderForCaching } from "./prompt-ordering.js";
@@ -397,6 +398,8 @@ function handleLostSessionLock(ctx, lockStatus) {
397
398
  ctx?.ui.setStatus("gsd-auto", undefined);
398
399
  ctx?.ui.setWidget("gsd-progress", undefined);
399
400
  ctx?.ui.setFooter(undefined);
401
+ if (ctx)
402
+ initHealthWidget(ctx);
400
403
  }
401
404
  /**
402
405
  * Lightweight cleanup after autoLoop exits via step-wizard break.
@@ -431,6 +434,7 @@ function cleanupAfterLoopExit(ctx) {
431
434
  ctx.ui.setStatus("gsd-auto", undefined);
432
435
  ctx.ui.setWidget("gsd-progress", undefined);
433
436
  ctx.ui.setFooter(undefined);
437
+ initHealthWidget(ctx);
434
438
  }
435
439
  // Restore CWD out of worktree back to original project root
436
440
  if (s.originalBasePath) {
@@ -501,17 +505,30 @@ export async function stopAuto(ctx, pi, reason) {
501
505
  ? { notify: ctx.ui.notify.bind(ctx.ui) }
502
506
  : { notify: () => { } };
503
507
  const resolver = buildResolver();
504
- // Check if the milestone is complete SUMMARY file is the authoritative signal.
508
+ // Check if the milestone is complete. DB status is the authoritative
509
+ // signal — only a successful gsd_complete_milestone call flips it to
510
+ // "complete" (tools/complete-milestone.ts). SUMMARY file presence is
511
+ // NOT sufficient: a blocker placeholder stub or a partial write can
512
+ // leave a file behind without the milestone actually being done,
513
+ // which previously caused stopAuto to merge a failed milestone and
514
+ // emit a misleading metadata-only merge warning (#4175).
515
+ // DB-unavailable projects fall back to SUMMARY-file presence.
505
516
  let milestoneComplete = false;
506
517
  try {
507
- const summaryPath = resolveMilestoneFile(s.originalBasePath || s.basePath, s.currentMilestoneId, "SUMMARY");
508
- if (!summaryPath) {
509
- // Also check in the worktree path (SUMMARY may not be synced yet)
510
- const wtSummaryPath = resolveMilestoneFile(s.basePath, s.currentMilestoneId, "SUMMARY");
511
- milestoneComplete = wtSummaryPath !== null;
518
+ if (isDbAvailable()) {
519
+ const dbRow = getMilestone(s.currentMilestoneId);
520
+ milestoneComplete = dbRow?.status === "complete";
512
521
  }
513
522
  else {
514
- milestoneComplete = true;
523
+ const summaryPath = resolveMilestoneFile(s.originalBasePath || s.basePath, s.currentMilestoneId, "SUMMARY");
524
+ if (!summaryPath) {
525
+ // Also check in the worktree path (SUMMARY may not be synced yet)
526
+ const wtSummaryPath = resolveMilestoneFile(s.basePath, s.currentMilestoneId, "SUMMARY");
527
+ milestoneComplete = wtSummaryPath !== null;
528
+ }
529
+ else {
530
+ milestoneComplete = true;
531
+ }
515
532
  }
516
533
  }
517
534
  catch (err) {
@@ -676,6 +693,8 @@ export async function stopAuto(ctx, pi, reason) {
676
693
  ctx?.ui.setStatus("gsd-auto", undefined);
677
694
  ctx?.ui.setWidget("gsd-progress", undefined);
678
695
  ctx?.ui.setFooter(undefined);
696
+ if (ctx)
697
+ initHealthWidget(ctx);
679
698
  restoreProjectRootEnv();
680
699
  restoreMilestoneLockEnv();
681
700
  // Reset all session state in one call
@@ -762,6 +781,8 @@ export async function pauseAuto(ctx, _pi, _errorContext) {
762
781
  ctx?.ui.setStatus("gsd-auto", "paused");
763
782
  ctx?.ui.setWidget("gsd-progress", undefined);
764
783
  ctx?.ui.setFooter(undefined);
784
+ if (ctx)
785
+ initHealthWidget(ctx);
765
786
  const resumeCmd = s.stepMode ? "/gsd next" : "/gsd auto";
766
787
  ctx?.ui.notify(`${s.stepMode ? "Step" : "Auto"}-mode paused (Escape). Type to interact, or ${resumeCmd} to resume.`, "info");
767
788
  }
@@ -863,6 +884,7 @@ function buildLoopDeps() {
863
884
  getMainBranch,
864
885
  // Unit closeout + runtime records
865
886
  closeoutUnit,
887
+ autoCommitUnit,
866
888
  recordOutcome,
867
889
  writeLock,
868
890
  captureAvailableSkills,
@@ -1060,6 +1082,11 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
1060
1082
  s.stepMode = requestedStepMode;
1061
1083
  s.cmdCtx = ctx;
1062
1084
  s.basePath = base;
1085
+ // Ensure the workflow-logger audit log is pinned to the project root
1086
+ // even when auto-mode is entered via a path that bypasses the
1087
+ // bootstrap/dynamic-tools ensureDbOpen() → setLogBasePath() chain
1088
+ // (e.g. /clear resume, hot-reload).
1089
+ setLogBasePath(base);
1063
1090
  s.unitDispatchCount.clear();
1064
1091
  s.unitLifetimeDispatches.clear();
1065
1092
  if (!getLedger())
@@ -1,5 +1,4 @@
1
1
  // GSD2 — Extension registration: wires all GSD tools, commands, and hooks into pi
2
- import { registerGSDCommand } from "../commands.js";
3
2
  import { registerExitCommand } from "../exit-command.js";
4
3
  import { registerWorktreeCommand } from "../worktree-command.js";
5
4
  import { registerDbTools } from "./db-tools.js";
@@ -9,6 +8,7 @@ import { registerQueryTools } from "./query-tools.js";
9
8
  import { registerHooks } from "./register-hooks.js";
10
9
  import { registerShortcuts } from "./register-shortcuts.js";
11
10
  import { writeCrashLog } from "./crash-log.js";
11
+ import { logWarning } from "../workflow-logger.js";
12
12
  export { writeCrashLog } from "./crash-log.js";
13
13
  export function handleRecoverableExtensionProcessError(err) {
14
14
  if (err.code === "EPIPE") {
@@ -52,7 +52,8 @@ function installEpipeGuard() {
52
52
  }
53
53
  }
54
54
  export function registerGsdExtension(pi) {
55
- registerGSDCommand(pi);
55
+ // Note: registerGSDCommand is called by index.ts before this function,
56
+ // so we intentionally skip it here to avoid double-registration.
56
57
  registerWorktreeCommand(pi);
57
58
  registerExitCommand(pi);
58
59
  installEpipeGuard();
@@ -62,10 +63,22 @@ export function registerGsdExtension(pi) {
62
63
  process.exit(0);
63
64
  },
64
65
  });
65
- registerDynamicTools(pi);
66
- registerDbTools(pi);
67
- registerJournalTools(pi);
68
- registerQueryTools(pi);
69
- registerShortcuts(pi);
70
- registerHooks(pi);
66
+ // Wrap non-critical registrations individually so one failure
67
+ // doesn't prevent the others from loading.
68
+ const nonCriticalRegistrations = [
69
+ ["dynamic-tools", () => registerDynamicTools(pi)],
70
+ ["db-tools", () => registerDbTools(pi)],
71
+ ["journal-tools", () => registerJournalTools(pi)],
72
+ ["query-tools", () => registerQueryTools(pi)],
73
+ ["shortcuts", () => registerShortcuts(pi)],
74
+ ["hooks", () => registerHooks(pi)],
75
+ ];
76
+ for (const [name, register] of nonCriticalRegistrations) {
77
+ try {
78
+ register();
79
+ }
80
+ catch (err) {
81
+ logWarning("bootstrap", `Failed to register ${name}: ${err instanceof Error ? err.message : String(err)}`);
82
+ }
83
+ }
71
84
  }
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { loadRegistry } from "../workflow-templates.js";
5
5
  import { resolveProjectRoot } from "../worktree.js";
6
6
  const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
7
- export const GSD_COMMAND_DESCRIPTION = "GSD — Get Shit Done: /gsd help|start|templates|next|auto|stop|pause|status|widget|visualize|queue|quick|discuss|capture|triage|dispatch|history|undo|undo-task|reset-slice|rate|skip|export|cleanup|model|mode|prefs|config|keys|hooks|run-hook|skill-health|doctor|logs|forensics|changelog|migrate|remote|steer|knowledge|new-milestone|parallel|cmux|park|unpark|init|setup|inspect|extensions|update|fast|mcp|rethink|codebase|notifications";
7
+ export const GSD_COMMAND_DESCRIPTION = "GSD — Get Shit Done: /gsd help|start|templates|next|auto|stop|pause|status|widget|visualize|queue|quick|discuss|capture|triage|dispatch|history|undo|undo-task|reset-slice|rate|skip|export|cleanup|model|mode|prefs|config|keys|hooks|run-hook|skill-health|doctor|logs|forensics|changelog|migrate|remote|steer|knowledge|new-milestone|parallel|cmux|park|unpark|init|setup|inspect|extensions|update|fast|mcp|rethink|codebase|notifications|ship|do|session-report|backlog|pr-branch|add-tests";
8
8
  export const TOP_LEVEL_SUBCOMMANDS = [
9
9
  { cmd: "help", desc: "Categorized command reference with descriptions" },
10
10
  { cmd: "next", desc: "Explicit step mode (same as /gsd)" },
@@ -62,6 +62,12 @@ export const TOP_LEVEL_SUBCOMMANDS = [
62
62
  { cmd: "rethink", desc: "Conversational project reorganization — reorder, park, discard, add milestones" },
63
63
  { cmd: "workflow", desc: "Custom workflow lifecycle (new, run, list, validate, pause, resume)" },
64
64
  { cmd: "codebase", desc: "Generate, refresh, and inspect the codebase map cache (.gsd/CODEBASE.md)" },
65
+ { cmd: "ship", desc: "Create PR from milestone artifacts and open for review" },
66
+ { cmd: "do", desc: "Route freeform text to the right GSD command" },
67
+ { cmd: "session-report", desc: "Session cost, tokens, and work summary" },
68
+ { cmd: "backlog", desc: "Manage backlog items (add, promote, remove, list)" },
69
+ { cmd: "pr-branch", desc: "Create clean PR branch filtering .gsd/ commits" },
70
+ { cmd: "add-tests", desc: "Generate tests for completed slices" },
65
71
  ];
66
72
  const NESTED_COMPLETIONS = {
67
73
  auto: [
@@ -231,6 +237,25 @@ const NESTED_COMPLETIONS = {
231
237
  { cmd: "stats", desc: "Show file count, description coverage, and generation time" },
232
238
  { cmd: "help", desc: "Show usage and available subcommands" },
233
239
  ],
240
+ ship: [
241
+ { cmd: "--dry-run", desc: "Preview PR without creating" },
242
+ { cmd: "--draft", desc: "Open as draft PR" },
243
+ { cmd: "--base", desc: "Override target branch (default: main)" },
244
+ { cmd: "--force", desc: "Ship even with pending tasks" },
245
+ ],
246
+ "session-report": [
247
+ { cmd: "--json", desc: "Machine-readable JSON output" },
248
+ { cmd: "--save", desc: "Save report to .gsd/reports/" },
249
+ ],
250
+ backlog: [
251
+ { cmd: "add", desc: "Add item to backlog" },
252
+ { cmd: "promote", desc: "Promote backlog item to active slice" },
253
+ { cmd: "remove", desc: "Remove backlog item" },
254
+ ],
255
+ "pr-branch": [
256
+ { cmd: "--dry-run", desc: "Preview what would be filtered" },
257
+ { cmd: "--name", desc: "Custom branch name" },
258
+ ],
234
259
  };
235
260
  function filterOptions(partial, options, prefix = "") {
236
261
  const normalizedPrefix = prefix ? `${prefix} ` : "";
@@ -8,6 +8,9 @@ import { handleExport } from "../../export.js";
8
8
  import { handleHistory } from "../../history.js";
9
9
  import { handleUndo } from "../../undo.js";
10
10
  import { handleRemote } from "../../../remote-questions/mod.js";
11
+ import { handleShip } from "../../commands-ship.js";
12
+ import { handleSessionReport } from "../../commands-session-report.js";
13
+ import { handlePrBranch } from "../../commands-pr-branch.js";
11
14
  import { projectRoot } from "../context.js";
12
15
  export async function handleOpsCommand(trimmed, ctx, pi) {
13
16
  if (trimmed === "init") {
@@ -213,5 +216,22 @@ Examples:
213
216
  await handleCodebase(trimmed.replace(/^codebase\s*/, "").trim(), ctx, pi);
214
217
  return true;
215
218
  }
219
+ if (trimmed === "ship" || trimmed.startsWith("ship ")) {
220
+ await handleShip(trimmed.replace(/^ship\s*/, "").trim(), ctx, pi);
221
+ return true;
222
+ }
223
+ if (trimmed === "session-report" || trimmed.startsWith("session-report ")) {
224
+ await handleSessionReport(trimmed.replace(/^session-report\s*/, "").trim(), ctx);
225
+ return true;
226
+ }
227
+ if (trimmed === "pr-branch" || trimmed.startsWith("pr-branch ")) {
228
+ await handlePrBranch(trimmed.replace(/^pr-branch\s*/, "").trim(), ctx);
229
+ return true;
230
+ }
231
+ if (trimmed === "add-tests" || trimmed.startsWith("add-tests ")) {
232
+ const { handleAddTests } = await import("../../commands-add-tests.js");
233
+ await handleAddTests(trimmed.replace(/^add-tests\s*/, "").trim(), ctx, pi);
234
+ return true;
235
+ }
216
236
  return false;
217
237
  }
@@ -25,6 +25,61 @@ const WORKFLOW_USAGE = [
25
25
  " pause — Pause custom workflow auto-mode",
26
26
  " resume — Resume paused custom workflow auto-mode",
27
27
  ].join("\n");
28
+ function splitWorkflowRunArgs(input) {
29
+ const tokens = [];
30
+ let current = "";
31
+ let quote = null;
32
+ let escapeNext = false;
33
+ for (const ch of input) {
34
+ if (escapeNext) {
35
+ current += ch;
36
+ escapeNext = false;
37
+ continue;
38
+ }
39
+ if (ch === "\\") {
40
+ escapeNext = true;
41
+ continue;
42
+ }
43
+ if (quote) {
44
+ if (ch === quote) {
45
+ quote = null;
46
+ }
47
+ else {
48
+ current += ch;
49
+ }
50
+ continue;
51
+ }
52
+ if (ch === '"' || ch === "'") {
53
+ quote = ch;
54
+ continue;
55
+ }
56
+ if (/\s/.test(ch)) {
57
+ if (current) {
58
+ tokens.push(current);
59
+ current = "";
60
+ }
61
+ continue;
62
+ }
63
+ current += ch;
64
+ }
65
+ if (escapeNext)
66
+ current += "\\";
67
+ if (current)
68
+ tokens.push(current);
69
+ return tokens;
70
+ }
71
+ export function parseWorkflowRunArgs(args) {
72
+ const parts = splitWorkflowRunArgs(args);
73
+ const defName = parts[0] ?? "";
74
+ const overrides = {};
75
+ for (let i = 1; i < parts.length; i++) {
76
+ const eqIdx = parts[i].indexOf("=");
77
+ if (eqIdx > 0) {
78
+ overrides[parts[i].slice(0, eqIdx)] = parts[i].slice(eqIdx + 1);
79
+ }
80
+ }
81
+ return { defName, overrides };
82
+ }
28
83
  async function handleCustomWorkflow(sub, ctx, pi) {
29
84
  // Bare `/gsd workflow` — show usage
30
85
  if (!sub) {
@@ -43,15 +98,7 @@ async function handleCustomWorkflow(sub, ctx, pi) {
43
98
  ctx.ui.notify("Usage: /gsd workflow run <name> [param=value ...]", "warning");
44
99
  return true;
45
100
  }
46
- const parts = args.split(/\s+/);
47
- const defName = parts[0];
48
- const overrides = {};
49
- for (let i = 1; i < parts.length; i++) {
50
- const eqIdx = parts[i].indexOf("=");
51
- if (eqIdx > 0) {
52
- overrides[parts[i].slice(0, eqIdx)] = parts[i].slice(eqIdx + 1);
53
- }
54
- }
101
+ const { defName, overrides } = parseWorkflowRunArgs(args);
55
102
  try {
56
103
  const base = projectRoot();
57
104
  const runDir = createRun(base, defName, Object.keys(overrides).length > 0 ? overrides : undefined);
@@ -146,6 +193,18 @@ async function handleCustomWorkflow(sub, ctx, pi) {
146
193
  return true;
147
194
  }
148
195
  export async function handleWorkflowCommand(trimmed, ctx, pi) {
196
+ // ── /gsd do — natural language routing (must be early to route to other commands) ──
197
+ if (trimmed === "do" || trimmed.startsWith("do ")) {
198
+ const { handleDo } = await import("../../commands-do.js");
199
+ await handleDo(trimmed.replace(/^do\s*/, "").trim(), ctx, pi);
200
+ return true;
201
+ }
202
+ // ── Backlog management ──
203
+ if (trimmed === "backlog" || trimmed.startsWith("backlog ")) {
204
+ const { handleBacklog } = await import("../../commands-backlog.js");
205
+ await handleBacklog(trimmed.replace(/^backlog\s*/, "").trim(), ctx, pi);
206
+ return true;
207
+ }
149
208
  // ── Custom workflow commands (`/gsd workflow ...`) ──
150
209
  if (trimmed === "workflow" || trimmed.startsWith("workflow ")) {
151
210
  const sub = trimmed.slice("workflow".length).trim();
@@ -0,0 +1,111 @@
1
+ /**
2
+ * GSD Command — /gsd add-tests
3
+ *
4
+ * Generates tests for a completed slice by dispatching an LLM prompt
5
+ * with implementation context (summaries, changed files, test patterns).
6
+ */
7
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { deriveState } from "./state.js";
10
+ import { gsdRoot, resolveSliceFile } from "./paths.js";
11
+ import { loadPrompt } from "./prompt-loader.js";
12
+ function findLastCompletedSlice(basePath, milestoneId) {
13
+ // Scan disk for slices that have a SUMMARY.md (indicating completion)
14
+ const slicesDir = join(gsdRoot(basePath), "milestones", milestoneId, "slices");
15
+ if (!existsSync(slicesDir))
16
+ return null;
17
+ try {
18
+ const entries = readdirSync(slicesDir, { withFileTypes: true })
19
+ .filter((e) => e.isDirectory() && /^S\d+$/.test(e.name))
20
+ .sort((a, b) => b.name.localeCompare(a.name)); // reverse order — latest first
21
+ for (const entry of entries) {
22
+ const summaryPath = join(slicesDir, entry.name, `${entry.name}-SUMMARY.md`);
23
+ if (existsSync(summaryPath))
24
+ return entry.name;
25
+ }
26
+ }
27
+ catch {
28
+ // non-fatal
29
+ }
30
+ return null;
31
+ }
32
+ function readSliceSummary(basePath, milestoneId, sliceId) {
33
+ const summaryPath = resolveSliceFile(basePath, milestoneId, sliceId, "SUMMARY");
34
+ if (summaryPath && existsSync(summaryPath)) {
35
+ const content = readFileSync(summaryPath, "utf-8");
36
+ const titleMatch = content.match(/^#\s+(.+)/m);
37
+ return { title: titleMatch?.[1] ?? sliceId, content };
38
+ }
39
+ return { title: sliceId, content: "(no summary available)" };
40
+ }
41
+ function detectTestPatterns(basePath) {
42
+ const patterns = [];
43
+ // Check for common test configs
44
+ const checks = [
45
+ { file: "jest.config.ts", name: "Jest" },
46
+ { file: "jest.config.js", name: "Jest" },
47
+ { file: "vitest.config.ts", name: "Vitest" },
48
+ { file: "vitest.config.js", name: "Vitest" },
49
+ { file: ".mocharc.yml", name: "Mocha" },
50
+ ];
51
+ for (const check of checks) {
52
+ if (existsSync(join(basePath, check.file))) {
53
+ patterns.push(`Framework: ${check.name} (${check.file})`);
54
+ }
55
+ }
56
+ // Look for existing test files to infer patterns
57
+ const testDirs = ["tests", "test", "src/__tests__", "__tests__"];
58
+ for (const dir of testDirs) {
59
+ const fullDir = join(basePath, dir);
60
+ if (existsSync(fullDir)) {
61
+ try {
62
+ const files = readdirSync(fullDir).filter((f) => f.endsWith(".test.ts") || f.endsWith(".spec.ts") || f.endsWith(".test.js"));
63
+ if (files.length > 0) {
64
+ patterns.push(`Test directory: ${dir}/ (${files.length} test files)`);
65
+ // Read first test file for patterns
66
+ const samplePath = join(fullDir, files[0]);
67
+ const sample = readFileSync(samplePath, "utf-8").slice(0, 500);
68
+ patterns.push(`Sample pattern from ${files[0]}:\n${sample}`);
69
+ break;
70
+ }
71
+ }
72
+ catch {
73
+ // non-fatal
74
+ }
75
+ }
76
+ }
77
+ return patterns.length > 0 ? patterns.join("\n") : "No test framework detected. Use Node.js built-in test runner.";
78
+ }
79
+ export async function handleAddTests(args, ctx, pi) {
80
+ const basePath = process.cwd();
81
+ const state = await deriveState(basePath);
82
+ if (!state.activeMilestone) {
83
+ ctx.ui.notify("No active milestone.", "warning");
84
+ return;
85
+ }
86
+ const milestoneId = state.activeMilestone.id;
87
+ // Determine target
88
+ const targetId = args.trim() || findLastCompletedSlice(basePath, milestoneId);
89
+ if (!targetId) {
90
+ ctx.ui.notify("No completed slices found. Specify a slice ID: /gsd add-tests S03", "warning");
91
+ return;
92
+ }
93
+ // Gather context
94
+ const summary = readSliceSummary(basePath, milestoneId, targetId);
95
+ const testPatterns = detectTestPatterns(basePath);
96
+ ctx.ui.notify(`Generating tests for ${targetId}: "${summary.title}"...`, "info");
97
+ try {
98
+ const prompt = loadPrompt("add-tests", {
99
+ sliceId: targetId,
100
+ sliceTitle: summary.title,
101
+ sliceSummary: summary.content,
102
+ existingTestPatterns: testPatterns,
103
+ workingDirectory: basePath,
104
+ });
105
+ pi.sendMessage({ customType: "gsd-add-tests", content: prompt, display: false }, { triggerTurn: true });
106
+ }
107
+ catch (err) {
108
+ const msg = err instanceof Error ? err.message : String(err);
109
+ ctx.ui.notify(`Failed to dispatch test generation: ${msg}`, "error");
110
+ }
111
+ }