@opengsd/gsd-pi 1.1.1-dev.9bb7453 → 1.1.1-dev.9f86580

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 (219) hide show
  1. package/dist/resources/.managed-resources-content-hash +1 -1
  2. package/dist/resources/extensions/browser-tools/engine/managed-gsd-browser.js +18 -2
  3. package/dist/resources/extensions/browser-tools/engine/selection.js +1 -1
  4. package/dist/resources/extensions/browser-tools/extension-manifest.json +1 -1
  5. package/dist/resources/extensions/browser-tools/index.js +29 -2
  6. package/dist/resources/extensions/browser-tools/web-app-detect.js +52 -0
  7. package/dist/resources/extensions/gsd/auto/phases.js +45 -3
  8. package/dist/resources/extensions/gsd/auto/session.js +2 -0
  9. package/dist/resources/extensions/gsd/auto-dispatch.js +21 -2
  10. package/dist/resources/extensions/gsd/auto-model-selection.js +26 -0
  11. package/dist/resources/extensions/gsd/auto-prompts.js +4 -0
  12. package/dist/resources/extensions/gsd/auto-recovery.js +3 -4
  13. package/dist/resources/extensions/gsd/auto-timers.js +24 -10
  14. package/dist/resources/extensions/gsd/auto-unit-tool-scope.js +18 -66
  15. package/dist/resources/extensions/gsd/auto-worktree.js +18 -5
  16. package/dist/resources/extensions/gsd/auto.js +26 -4
  17. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +16 -10
  18. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +48 -29
  19. package/dist/resources/extensions/gsd/bootstrap/system-context.js +1 -1
  20. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +18 -29
  21. package/dist/resources/extensions/gsd/closeout-consistency-gate.js +61 -0
  22. package/dist/resources/extensions/gsd/commands/handlers/auto.js +10 -0
  23. package/dist/resources/extensions/gsd/commands-mcp-status.js +1 -1
  24. package/dist/resources/extensions/gsd/config-overlay.js +1 -0
  25. package/dist/resources/extensions/gsd/context-masker.js +129 -5
  26. package/dist/resources/extensions/gsd/guided-flow.js +93 -108
  27. package/dist/resources/extensions/gsd/milestone-closeout.js +3 -1
  28. package/dist/resources/extensions/gsd/pending-auto-start.js +0 -1
  29. package/dist/resources/extensions/gsd/planner-handoff.js +98 -0
  30. package/dist/resources/extensions/gsd/preferences-models.js +1 -0
  31. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  32. package/dist/resources/extensions/gsd/prompts/run-uat.md +5 -19
  33. package/dist/resources/extensions/gsd/prompts/system.md +1 -1
  34. package/dist/resources/extensions/gsd/recovery-classification.js +20 -0
  35. package/dist/resources/extensions/gsd/skill-manifest.js +12 -0
  36. package/dist/resources/extensions/gsd/tool-contract.js +6 -1
  37. package/dist/resources/extensions/gsd/tool-presentation-plan.js +47 -7
  38. package/dist/resources/extensions/gsd/tools/complete-slice.js +28 -1
  39. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +113 -8
  40. package/dist/resources/extensions/gsd/unit-tool-contracts.js +193 -0
  41. package/dist/resources/extensions/gsd/workflow-mcp.js +5 -78
  42. package/dist/resources/extensions/gsd/worktree-manager.js +26 -0
  43. package/dist/resources/extensions/gsd/worktree-reentry.js +96 -0
  44. package/dist/resources/extensions/shared/gsd-browser-cli.js +6 -0
  45. package/dist/web/standalone/.next/BUILD_ID +1 -1
  46. package/dist/web/standalone/.next/app-path-routes-manifest.json +5 -5
  47. package/dist/web/standalone/.next/build-manifest.json +2 -2
  48. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  49. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  50. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  58. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  60. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  65. package/dist/web/standalone/.next/server/app/index.html +1 -1
  66. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  67. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  68. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  70. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app-paths-manifest.json +5 -5
  73. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  74. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  75. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  76. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  77. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  78. package/package.json +1 -1
  79. package/packages/cloud-mcp-gateway/package.json +2 -2
  80. package/packages/contracts/package.json +1 -1
  81. package/packages/daemon/package.json +4 -4
  82. package/packages/gsd-agent-core/package.json +5 -5
  83. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  84. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +5 -0
  85. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
  86. package/packages/gsd-agent-modes/package.json +7 -7
  87. package/packages/mcp-server/package.json +3 -3
  88. package/packages/native/package.json +1 -1
  89. package/packages/pi-agent-core/dist/agent-loop.js +4 -3
  90. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  91. package/packages/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
  92. package/packages/pi-agent-core/dist/harness/agent-harness.js +3 -1
  93. package/packages/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
  94. package/packages/pi-agent-core/dist/harness/types.d.ts +1 -0
  95. package/packages/pi-agent-core/dist/harness/types.d.ts.map +1 -1
  96. package/packages/pi-agent-core/dist/harness/types.js.map +1 -1
  97. package/packages/pi-agent-core/dist/types.d.ts +3 -1
  98. package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
  99. package/packages/pi-agent-core/dist/types.js.map +1 -1
  100. package/packages/pi-agent-core/package.json +1 -1
  101. package/packages/pi-ai/dist/models.generated.d.ts +157 -18
  102. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  103. package/packages/pi-ai/dist/models.generated.js +159 -36
  104. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  105. package/packages/pi-ai/dist/providers/transform-messages.d.ts.map +1 -1
  106. package/packages/pi-ai/dist/providers/transform-messages.js +8 -1
  107. package/packages/pi-ai/dist/providers/transform-messages.js.map +1 -1
  108. package/packages/pi-ai/package.json +1 -1
  109. package/packages/pi-coding-agent/dist/core/extensions/extension-upstream-types.d.ts +3 -0
  110. package/packages/pi-coding-agent/dist/core/extensions/extension-upstream-types.d.ts.map +1 -1
  111. package/packages/pi-coding-agent/dist/core/extensions/extension-upstream-types.js.map +1 -1
  112. package/packages/pi-coding-agent/dist/core/tools/bash.js +2 -2
  113. package/packages/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
  114. package/packages/pi-coding-agent/dist/core/tools/edit.d.ts.map +1 -1
  115. package/packages/pi-coding-agent/dist/core/tools/edit.js +3 -2
  116. package/packages/pi-coding-agent/dist/core/tools/edit.js.map +1 -1
  117. package/packages/pi-coding-agent/dist/core/tools/render-utils.d.ts +1 -0
  118. package/packages/pi-coding-agent/dist/core/tools/render-utils.d.ts.map +1 -1
  119. package/packages/pi-coding-agent/dist/core/tools/render-utils.js +6 -0
  120. package/packages/pi-coding-agent/dist/core/tools/render-utils.js.map +1 -1
  121. package/packages/pi-coding-agent/dist/core/tools/write.d.ts.map +1 -1
  122. package/packages/pi-coding-agent/dist/core/tools/write.js +3 -2
  123. package/packages/pi-coding-agent/dist/core/tools/write.js.map +1 -1
  124. package/packages/pi-coding-agent/package.json +7 -7
  125. package/packages/pi-tui/package.json +1 -1
  126. package/packages/rpc-client/package.json +2 -2
  127. package/pkg/package.json +1 -1
  128. package/scripts/install/handoff.js +16 -3
  129. package/src/resources/extensions/browser-tools/engine/managed-gsd-browser.ts +21 -2
  130. package/src/resources/extensions/browser-tools/engine/selection.ts +1 -1
  131. package/src/resources/extensions/browser-tools/extension-manifest.json +1 -1
  132. package/src/resources/extensions/browser-tools/index.ts +36 -5
  133. package/src/resources/extensions/browser-tools/tests/browser-engine-selection.test.mjs +2 -2
  134. package/src/resources/extensions/browser-tools/tests/gsd-browser-launch-config.test.mjs +37 -0
  135. package/src/resources/extensions/browser-tools/tests/web-app-detect.test.mjs +68 -0
  136. package/src/resources/extensions/browser-tools/web-app-detect.ts +63 -0
  137. package/src/resources/extensions/gsd/auto/phases.ts +48 -6
  138. package/src/resources/extensions/gsd/auto/session.ts +2 -0
  139. package/src/resources/extensions/gsd/auto-dispatch.ts +48 -2
  140. package/src/resources/extensions/gsd/auto-model-selection.ts +26 -0
  141. package/src/resources/extensions/gsd/auto-prompts.ts +4 -0
  142. package/src/resources/extensions/gsd/auto-recovery.ts +3 -3
  143. package/src/resources/extensions/gsd/auto-timers.ts +25 -9
  144. package/src/resources/extensions/gsd/auto-unit-tool-scope.ts +43 -74
  145. package/src/resources/extensions/gsd/auto-worktree.ts +23 -5
  146. package/src/resources/extensions/gsd/auto.ts +28 -4
  147. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +16 -10
  148. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +63 -29
  149. package/src/resources/extensions/gsd/bootstrap/system-context.ts +1 -1
  150. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +50 -54
  151. package/src/resources/extensions/gsd/closeout-consistency-gate.ts +137 -0
  152. package/src/resources/extensions/gsd/commands/handlers/auto.ts +9 -0
  153. package/src/resources/extensions/gsd/commands-mcp-status.ts +1 -1
  154. package/src/resources/extensions/gsd/config-overlay.ts +1 -0
  155. package/src/resources/extensions/gsd/context-masker.ts +152 -5
  156. package/src/resources/extensions/gsd/guided-flow.ts +128 -135
  157. package/src/resources/extensions/gsd/milestone-closeout.ts +3 -1
  158. package/src/resources/extensions/gsd/pending-auto-start.ts +0 -2
  159. package/src/resources/extensions/gsd/planner-handoff.ts +149 -0
  160. package/src/resources/extensions/gsd/preferences-models.ts +1 -0
  161. package/src/resources/extensions/gsd/preferences-types.ts +8 -0
  162. package/src/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  163. package/src/resources/extensions/gsd/prompts/run-uat.md +5 -19
  164. package/src/resources/extensions/gsd/prompts/system.md +1 -1
  165. package/src/resources/extensions/gsd/recovery-classification.ts +20 -0
  166. package/src/resources/extensions/gsd/skill-manifest.ts +12 -0
  167. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +99 -0
  168. package/src/resources/extensions/gsd/tests/auto-model-selection-tool-poisoning.test.ts +66 -4
  169. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +10 -2
  170. package/src/resources/extensions/gsd/tests/auto-start-bootstrap-await-3420.test.ts +4 -1
  171. package/src/resources/extensions/gsd/tests/auto-supervisor.test.mjs +4 -0
  172. package/src/resources/extensions/gsd/tests/auto-warning-noise-regression.test.ts +12 -2
  173. package/src/resources/extensions/gsd/tests/bundled-skill-triggers.test.ts +9 -0
  174. package/src/resources/extensions/gsd/tests/check-auto-start-pending-gate.test.ts +9 -15
  175. package/src/resources/extensions/gsd/tests/check-auto-start-ready-guard.test.ts +26 -16
  176. package/src/resources/extensions/gsd/tests/commands-dispatcher-unmerged-milestone.test.ts +21 -0
  177. package/src/resources/extensions/gsd/tests/complete-slice-verification-gate.test.ts +118 -0
  178. package/src/resources/extensions/gsd/tests/context-masker.test.ts +56 -1
  179. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +1 -0
  180. package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +40 -1
  181. package/src/resources/extensions/gsd/tests/dispatch-rule-coverage.test.ts +24 -0
  182. package/src/resources/extensions/gsd/tests/gate-1b-orphan-discrimination.test.ts +31 -79
  183. package/src/resources/extensions/gsd/tests/guided-flow-session-isolation.test.ts +5 -3
  184. package/src/resources/extensions/gsd/tests/guided-flow-state-rebuild.test.ts +40 -4
  185. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +8 -0
  186. package/src/resources/extensions/gsd/tests/integration/parallel-merge.test.ts +16 -0
  187. package/src/resources/extensions/gsd/tests/integration/run-uat.test.ts +7 -1
  188. package/src/resources/extensions/gsd/tests/interrupted-session-auto.test.ts +27 -0
  189. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +1 -0
  190. package/src/resources/extensions/gsd/tests/mcp-project-config.test.ts +7 -1
  191. package/src/resources/extensions/gsd/tests/mcp-status.test.ts +1 -1
  192. package/src/resources/extensions/gsd/tests/merge-closeout-consistency-gate.test.ts +63 -0
  193. package/src/resources/extensions/gsd/tests/merge-db-cycle.test.ts +10 -1
  194. package/src/resources/extensions/gsd/tests/milestone-closeout.test.ts +9 -1
  195. package/src/resources/extensions/gsd/tests/planner-handoff.test.ts +100 -0
  196. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +147 -5
  197. package/src/resources/extensions/gsd/tests/provider-switch-observer.test.ts +55 -0
  198. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +44 -0
  199. package/src/resources/extensions/gsd/tests/run-uat-composer.test.ts +4 -0
  200. package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +56 -0
  201. package/src/resources/extensions/gsd/tests/skill-manifest.test.ts +4 -3
  202. package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +4 -4
  203. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +77 -10
  204. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +409 -0
  205. package/src/resources/extensions/gsd/tests/worktree-reentry.test.ts +102 -0
  206. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +15 -0
  207. package/src/resources/extensions/gsd/tool-contract.ts +7 -1
  208. package/src/resources/extensions/gsd/tool-presentation-plan.ts +82 -7
  209. package/src/resources/extensions/gsd/tools/complete-slice.ts +29 -1
  210. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +146 -9
  211. package/src/resources/extensions/gsd/unit-tool-contracts.ts +210 -0
  212. package/src/resources/extensions/gsd/workflow-mcp.ts +5 -78
  213. package/src/resources/extensions/gsd/worktree-manager.ts +32 -0
  214. package/src/resources/extensions/gsd/worktree-reentry.ts +103 -0
  215. package/src/resources/extensions/shared/gsd-browser-cli.ts +6 -0
  216. package/src/resources/extensions/gsd/tests/gate-1b-recovery-bound-corrections.test.ts +0 -246
  217. package/src/resources/extensions/gsd/tests/gate-1b-recovery-bound.test.ts +0 -218
  218. /package/dist/web/standalone/.next/static/{jBtwT9v1u2lUA3UEOy_ZH → zzYMrKpPGfRQRxSFO32Jr}/_buildManifest.js +0 -0
  219. /package/dist/web/standalone/.next/static/{jBtwT9v1u2lUA3UEOy_ZH → zzYMrKpPGfRQRxSFO32Jr}/_ssgManifest.js +0 -0
@@ -98,6 +98,7 @@ import {
98
98
  getDiscussionMilestoneId,
99
99
  hasPendingAutoStart,
100
100
  setPendingAutoStart,
101
+ type PendingAutoStartEntry,
101
102
  } from "./pending-auto-start.js";
102
103
  import { clearGuidedUnitContext, setGuidedUnitContext } from "./guided-unit-context.js";
103
104
 
@@ -320,6 +321,116 @@ export function _roadmapHasParseableSlicesForTest(
320
321
  return parseRoadmapSlices(roadmapContent).length > 0;
321
322
  }
322
323
 
324
+ function hasExecutablePlanForHandoff(milestoneId: string, roadmapFile: string | null): boolean {
325
+ if (isDbAvailable()) {
326
+ return getMilestoneSlices(milestoneId).length > 0;
327
+ }
328
+ if (!roadmapFile) return false;
329
+ try {
330
+ return parseRoadmapSlices(readFileSync(roadmapFile, "utf-8")).length > 0;
331
+ } catch (e) {
332
+ logWarning(
333
+ "guided",
334
+ `failed to parse roadmap slices for ${milestoneId}: ${(e as Error).message}`,
335
+ );
336
+ return false;
337
+ }
338
+ }
339
+
340
+ function formatAcceptedDiscussHandoffMessage(
341
+ milestoneId: string,
342
+ contextFile: string | null,
343
+ hasExecutablePlan: boolean,
344
+ ): string {
345
+ if (hasExecutablePlan) return `Milestone ${milestoneId} ready.`;
346
+ if (contextFile) return `Milestone ${milestoneId} context captured. Continuing the planning pipeline.`;
347
+ return `Milestone ${milestoneId} planning artifacts captured. Continuing the planning pipeline.`;
348
+ }
349
+
350
+ function manifestContainsMilestone(basePath: string, milestoneId: string): boolean {
351
+ try {
352
+ const manifest = readManifest(basePath);
353
+ return (
354
+ Array.isArray(manifest?.milestones) &&
355
+ manifest.milestones.some(m => m.id === milestoneId)
356
+ );
357
+ } catch (e) {
358
+ logWarning("guided", `R3b: failed to read state manifest: ${(e as Error).message}`);
359
+ return false;
360
+ }
361
+ }
362
+
363
+ function notifyDbRowRecoveryFailed(entry: PendingAutoStartEntry): void {
364
+ entry.ctx.ui.notify(
365
+ `Milestone ${entry.milestoneId}: DB row recovery failed ${entry.r3bRecoveryCount} times. ` +
366
+ `Re-run /gsd to reset the recovery counter, or run /gsd-debug to diagnose without resetting.`,
367
+ "error",
368
+ );
369
+ }
370
+
371
+ function noteDbRowRecoveryMiss(entry: PendingAutoStartEntry): void {
372
+ entry.r3bRecoveryCount += 1;
373
+ if (entry.r3bRecoveryCount >= MAX_DB_ROW_RECOVERIES) {
374
+ notifyDbRowRecoveryFailed(entry);
375
+ }
376
+ }
377
+
378
+ function ensureMilestoneRowForAcceptedHandoff(
379
+ entry: PendingAutoStartEntry,
380
+ contextFile: string | null,
381
+ ): boolean {
382
+ if (!isDbAvailable()) return true;
383
+
384
+ const { basePath, milestoneId } = entry;
385
+ const milestoneRow = getMilestone(milestoneId);
386
+ if (milestoneRow) return true;
387
+
388
+ if (manifestContainsMilestone(basePath, milestoneId)) {
389
+ logWarning(
390
+ "guided",
391
+ `R3b: getMilestone(${milestoneId}) returned null but manifest has the row — treating as stale read`,
392
+ );
393
+ return true;
394
+ }
395
+
396
+ if (!contextFile) {
397
+ entry.ctx.ui.notify(
398
+ `Milestone ${milestoneId}: discuss artifacts on disk but no DB row exists. ` +
399
+ `PROJECT.md may have failed to register milestones. ` +
400
+ `Re-save PROJECT.md with canonical "- [ ] M001: Title — One-liner" lines, ` +
401
+ `then re-run /gsd to recover.`,
402
+ "error",
403
+ );
404
+ return false;
405
+ }
406
+
407
+ if (entry.r3bRecoveryCount >= MAX_DB_ROW_RECOVERIES) {
408
+ logWarning(
409
+ "guided",
410
+ `R3b: milestone ${milestoneId} DB-row recovery limit reached ` +
411
+ `(${entry.r3bRecoveryCount}/${MAX_DB_ROW_RECOVERIES}); user already notified`,
412
+ );
413
+ return false;
414
+ }
415
+
416
+ logWarning(
417
+ "guided",
418
+ `R3b: ${milestoneId} has CONTEXT.md but no DB row — inserting placeholder "queued" row ` +
419
+ `(attempt ${entry.r3bRecoveryCount + 1}/${MAX_DB_ROW_RECOVERIES})`,
420
+ );
421
+
422
+ try {
423
+ insertMilestone({ id: milestoneId, title: milestoneId, status: "queued" });
424
+ } catch (e) {
425
+ logWarning("guided", `R3b: insertMilestone failed: ${(e as Error).message}`);
426
+ }
427
+
428
+ if (getMilestone(milestoneId)) return true;
429
+
430
+ noteDbRowRecoveryMiss(entry);
431
+ return false;
432
+ }
433
+
323
434
  // ─── Commit Instruction Helpers ──────────────────────────────────────────────
324
435
 
325
436
  /** Build commit instruction for planning prompts. .gsd/ is managed externally and always gitignored. */
@@ -344,10 +455,8 @@ interface PendingDeepProjectSetupEntry {
344
455
  // phrase before giving up and asking the user to re-run /gsd.
345
456
  const MAX_READY_REJECTS = 2;
346
457
 
347
- // H1 (#5012): cap for Gate 1b plan-blocked recovery hints. After this many
348
- // consecutive recovery attempts the loop is stopped and the user is directed
349
- // to investigate manually.
350
- const MAX_PLAN_BLOCKED_RECOVERIES = 3;
458
+ // Cap failed in-flight DB row repair attempts before escalating to the user.
459
+ const MAX_DB_ROW_RECOVERIES = 3;
351
460
 
352
461
  // #4573: matches the canonical ready phrase the discuss prompt asks the LLM
353
462
  // to emit. Accepts any M-prefixed milestone ID (three digits + optional
@@ -613,72 +722,12 @@ export function checkAutoStartAfterDiscuss(lookupBasePath?: string): boolean {
613
722
  }
614
723
  }
615
724
 
616
- // Gate 1b: Discriminate plan-blocked from discuss-incomplete when the DB row is queued.
617
- // If the DB is available and the row is still "queued" but CONTEXT.md already exists on
618
- // disk, the discuss phase completed but gsd_plan_milestone was hard-blocked by the
619
- // depth-verification gate. Emit a recovery hint so the next agent turn can retry
620
- // gsd_plan_milestone, then return false (keep blocking auto-start).
621
- // If CONTEXT.md does not exist (discuss-incomplete), Gate 1 already blocked above.
622
- if (isDbAvailable()) {
623
- const dbRow = getMilestone(milestoneId);
624
- if (dbRow?.status === "queued" && contextFile) {
625
- if (entry.planBlockedRecoveryCount >= MAX_PLAN_BLOCKED_RECOVERIES) {
626
- // H1: recovery loop cap reached — stop triggering new turns, escalate to user.
627
- logWarning(
628
- "guided",
629
- `Gate 1b: milestone ${milestoneId} plan-blocked recovery limit reached ` +
630
- `(${entry.planBlockedRecoveryCount}/${MAX_PLAN_BLOCKED_RECOVERIES}); escalating to user`,
631
- );
632
- ctx.ui.notify(
633
- `Milestone ${milestoneId} plan_milestone has been blocked ${entry.planBlockedRecoveryCount} times. ` +
634
- `Re-run /gsd to reset the recovery counter, or run /gsd-debug to diagnose without resetting.`,
635
- "error",
636
- );
637
- return false;
638
- }
639
- logWarning(
640
- "guided",
641
- `Gate 1b: milestone ${milestoneId} queued with CONTEXT.md present — ` +
642
- `plan_milestone was blocked; emitting recovery hint ` +
643
- `(attempt ${entry.planBlockedRecoveryCount + 1}/${MAX_PLAN_BLOCKED_RECOVERIES})`,
644
- );
645
- ctx.ui.notify(
646
- `Milestone ${milestoneId}: context file exists but milestone is still queued. ` +
647
- `Retrying gsd_plan_milestone to complete the blocked planning step.`,
648
- "warning",
649
- );
650
- try {
651
- pi.sendMessage(
652
- {
653
- customType: "gsd-plan-milestone-blocked-recovery",
654
- content:
655
- `Milestone ${milestoneId} has ${contextFile} on disk but its DB row is still ` +
656
- `"queued". The gsd_plan_milestone tool was previously blocked by the ` +
657
- `depth-verification gate. Call gsd_plan_milestone now to complete the ` +
658
- `planning phase.`,
659
- display: false,
660
- },
661
- { triggerTurn: true },
662
- );
663
- // Increment only after a successful dispatch so transient sendMessage
664
- // failures do not consume recovery budget.
665
- entry.planBlockedRecoveryCount += 1;
666
- } catch (e) {
667
- logWarning("guided", `Gate 1b recovery sendMessage failed: ${(e as Error).message}`);
668
- }
669
- return false;
670
- }
671
- }
672
-
673
- // Gate 2: STATE.md must exist — written as the last step in the discuss
674
- // output phase. This prevents auto-start from firing during Phase 3
675
- // (sequential readiness gates for remaining milestones) in multi-milestone
676
- // discussions, where M001-CONTEXT.md exists but M002/M003 haven't been
677
- // processed yet.
678
- const stateFilePath = entry.scope.stateFile();
679
- if (!existsSync(stateFilePath)) return false; // discussion not finalized yet
725
+ // Gate 1b: accept the in-flight discuss handoff. A queued DB row with pinned
726
+ // CONTEXT.md is Discussion Complete, Planning Pending, not a plan-blocked
727
+ // failure. If the row is missing, only this pending handoff may repair it.
728
+ if (!ensureMilestoneRowForAcceptedHandoff(entry, contextFile)) return false;
680
729
 
681
- // Gate 3: Multi-milestone completeness warning
730
+ // Gate 2: Multi-milestone completeness warning
682
731
  // Parse PROJECT.md for milestone sequence, warn if any are missing context.
683
732
  // Don't block — milestones can be intentionally queued without context.
684
733
  const projectFile = resolveGsdRootFile(basePath, "PROJECT");
@@ -705,7 +754,7 @@ export function checkAutoStartAfterDiscuss(lookupBasePath?: string): boolean {
705
754
  } catch (e) { logWarning("guided", `PROJECT.md parsing failed: ${(e as Error).message}`); }
706
755
  }
707
756
 
708
- // Gate 4: Discussion manifest process verification (multi-milestone only)
757
+ // Gate 3: Discussion manifest process verification (multi-milestone only)
709
758
  // The LLM writes DISCUSSION-MANIFEST.json after each Phase 3 gate decision.
710
759
  // When it exists, validate it before auto-starting. Project history alone is
711
760
  // not a reliable signal for the current discussion mode.
@@ -747,71 +796,12 @@ export function checkAutoStartAfterDiscuss(lookupBasePath?: string): boolean {
747
796
  try { unlinkSync(manifestPath); } catch (e) { logWarning("guided", `manifest unlink failed: ${(e as Error).message}`); }
748
797
  }
749
798
 
750
- // R3b: belt-and-suspenders for silent registration failure. The discuss flow
751
- // finished and STATE.md exists, but the milestone may never have landed in
752
- // the DB. Without this guard, the user sees "Milestone M001 ready." and then
753
- // /gsd reports "No Active Milestone".
754
- if (isDbAvailable()) {
755
- const milestoneRow = getMilestone(milestoneId);
756
- if (!milestoneRow) {
757
- let manifestHasMilestone = false;
758
- try {
759
- const manifest = readManifest(basePath);
760
- manifestHasMilestone = Array.isArray(manifest?.milestones) && manifest.milestones.some(m => m.id === milestoneId);
761
- } catch (e) {
762
- logWarning("guided", `R3b: failed to read state manifest: ${(e as Error).message}`);
763
- }
764
- if (manifestHasMilestone) {
765
- logWarning("guided", `R3b: getMilestone(${milestoneId}) returned null but manifest has the row — treating as stale read`);
766
- } else if (contextFile) {
767
- // R3b-recovery: CONTEXT.md is on disk but gsd_plan_milestone was never called
768
- // (likely blocked by the depth-verification gate re-firing on post-verification
769
- // text). Auto-register as "queued" so Gate 1b can pick it up and retry
770
- // gsd_plan_milestone on the next checkAutoStartAfterDiscuss call.
771
- if (entry.r3bRecoveryCount >= MAX_PLAN_BLOCKED_RECOVERIES) {
772
- logWarning(
773
- "guided",
774
- `R3b: milestone ${milestoneId} DB-row recovery limit reached ` +
775
- `(${entry.r3bRecoveryCount}/${MAX_PLAN_BLOCKED_RECOVERIES}); escalating to user`,
776
- );
777
- ctx.ui.notify(
778
- `Milestone ${milestoneId}: DB row recovery failed ${entry.r3bRecoveryCount} times. ` +
779
- `Re-run /gsd to reset the recovery counter, or run /gsd-debug to diagnose without resetting.`,
780
- "error",
781
- );
782
- return false;
783
- }
784
- logWarning(
785
- "guided",
786
- `R3b: ${milestoneId} has CONTEXT.md but no DB row — inserting placeholder "queued" row ` +
787
- `for Gate 1b recovery (attempt ${entry.r3bRecoveryCount + 1}/${MAX_PLAN_BLOCKED_RECOVERIES})`,
788
- );
789
- try {
790
- insertMilestone({ id: milestoneId, title: milestoneId, status: "queued" });
791
- } catch (e) {
792
- logWarning("guided", `R3b: insertMilestone failed: ${(e as Error).message}`);
793
- }
794
- entry.r3bRecoveryCount += 1;
795
- ctx.ui.notify(
796
- `Milestone ${milestoneId}: context file exists but DB row was missing — recovering. Retrying gsd_plan_milestone.`,
797
- "warning",
798
- );
799
- return false;
800
- } else {
801
- ctx.ui.notify(
802
- `Milestone ${milestoneId}: discuss artifacts on disk but no DB row exists. ` +
803
- `PROJECT.md may have failed to register milestones. ` +
804
- `Re-save PROJECT.md with canonical "- [ ] M001: Title — One-liner" lines, ` +
805
- `then re-run /gsd to recover.`,
806
- "error",
807
- );
808
- return false;
809
- }
810
- }
811
- }
812
-
813
799
  deletePendingAutoStart(basePath);
814
- ctx.ui.notify(`Milestone ${milestoneId} ready.`, "success");
800
+ const hasExecutablePlan = hasExecutablePlanForHandoff(milestoneId, roadmapFile);
801
+ ctx.ui.notify(
802
+ formatAcceptedDiscussHandoffMessage(milestoneId, contextFile, hasExecutablePlan),
803
+ "success",
804
+ );
815
805
  if (entry.startAuto !== false) {
816
806
  scheduleAutoStartAfterIdle(ctx, pi, basePath, false, { step: step ?? true });
817
807
  }
@@ -1168,7 +1158,10 @@ async function dispatchWorkflow(
1168
1158
  ? ctx.modelRegistry.getProviderAuthMode(ctx.model.provider)
1169
1159
  : undefined,
1170
1160
  baseUrl: result.appliedModel?.baseUrl ?? ctx.model?.baseUrl,
1171
- activeTools: typeof pi.getActiveTools === "function" ? pi.getActiveTools() : [],
1161
+ // Guided flow starts the MCP workflow server as part of dispatch, so the
1162
+ // parent session's activeTools doesn't include MCP tools yet. The MCP
1163
+ // launch config check (detectWorkflowMcpLaunchConfig) is the right gate
1164
+ // here — not whether MCP tools are pre-registered in the parent session.
1172
1165
  },
1173
1166
  );
1174
1167
  if (compatibilityError) {
@@ -16,6 +16,7 @@ import { extractVerdict, isAcceptableUatVerdict } from "./verdict-parser.js";
16
16
  import { logWarning } from "./workflow-logger.js";
17
17
  import { hasImplementationArtifacts } from "./milestone-implementation-evidence.js";
18
18
  import { buildCompleteMilestonePrompt } from "./auto-prompts.js";
19
+ import { checkCloseoutConsistencyGate } from "./closeout-consistency-gate.js";
19
20
  import type { DispatchAction, DispatchContext } from "./auto-dispatch.js";
20
21
  import {
21
22
  commitPendingMilestoneCloseoutChanges,
@@ -37,7 +38,8 @@ export async function isMilestoneCloseoutSettled(mid: string, basePath: string):
37
38
  if (isDbAvailable()) {
38
39
  const milestone = getMilestone(mid);
39
40
  if (milestone && isClosedStatus(milestone.status)) {
40
- if (verifyExpectedArtifact("complete-milestone", mid, basePath)) {
41
+ const closeoutGate = checkCloseoutConsistencyGate(mid, { refreshFromDisk: true });
42
+ if (closeoutGate.ok && verifyExpectedArtifact("complete-milestone", mid, basePath)) {
41
43
  return true;
42
44
  }
43
45
  }
@@ -14,7 +14,6 @@ export interface PendingAutoStartEntry {
14
14
  createdAt: number;
15
15
  readyRejectCount?: number;
16
16
  scope: MilestoneScope;
17
- planBlockedRecoveryCount: number;
18
17
  r3bRecoveryCount: number;
19
18
  }
20
19
 
@@ -51,7 +50,6 @@ export function setPendingAutoStart(basePath: string, entry: PendingAutoStartInp
51
50
  const scope = scopeMilestone(ws, entry.milestoneId);
52
51
  pendingAutoStartMap.set(basePath, {
53
52
  createdAt: Date.now(),
54
- planBlockedRecoveryCount: 0,
55
53
  r3bRecoveryCount: 0,
56
54
  ...entry,
57
55
  scope,
@@ -0,0 +1,149 @@
1
+ // Project/App: gsd-pi
2
+ // File Purpose: Optional gsd-planner handoff after milestone planning.
3
+
4
+ import { spawn as spawnChild, type ChildProcess, type SpawnOptions } from "node:child_process";
5
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+
8
+ import { gsdRoot } from "./paths.js";
9
+
10
+ export const PLANNER_HANDOFF_RULE_NAME = "planning review handoff -> gsd-planner";
11
+ export const GSD_PLANNER_COMMAND = "gsd-planner";
12
+
13
+ export interface GsdPlannerSpawnPlan {
14
+ command: string;
15
+ args: string[];
16
+ cwd: string;
17
+ }
18
+
19
+ export interface GsdPlannerLaunchInput {
20
+ basePath: string;
21
+ milestoneId?: string | null;
22
+ extraArgs?: string[];
23
+ }
24
+
25
+ export type GsdPlannerLaunchResult =
26
+ | { status: "launched"; plan: GsdPlannerSpawnPlan }
27
+ | { status: "failed"; plan: GsdPlannerSpawnPlan; error: Error };
28
+
29
+ type SpawnLike = (
30
+ command: string,
31
+ args: readonly string[],
32
+ options: SpawnOptions,
33
+ ) => ChildProcess;
34
+
35
+ export interface GsdPlannerLaunchDeps {
36
+ spawn?: SpawnLike;
37
+ }
38
+
39
+ function handoffDir(basePath: string): string {
40
+ return join(gsdRoot(basePath), "runtime", "planner-handoffs");
41
+ }
42
+
43
+ function safeMilestoneFileSegment(milestoneId: string): string {
44
+ return milestoneId.replace(/[^A-Za-z0-9._-]/g, "_") || "unknown";
45
+ }
46
+
47
+ function handoffMarkerPath(basePath: string, milestoneId: string): string {
48
+ return join(handoffDir(basePath), `${safeMilestoneFileSegment(milestoneId)}.json`);
49
+ }
50
+
51
+ export function hasPlannerHandoffBeenOffered(basePath: string, milestoneId: string): boolean {
52
+ return existsSync(handoffMarkerPath(basePath, milestoneId));
53
+ }
54
+
55
+ export function markPlannerHandoffOffered(
56
+ basePath: string,
57
+ milestoneId: string,
58
+ source: "auto" | "command" = "auto",
59
+ ): void {
60
+ mkdirSync(handoffDir(basePath), { recursive: true });
61
+ writeFileSync(
62
+ handoffMarkerPath(basePath, milestoneId),
63
+ JSON.stringify({
64
+ milestoneId,
65
+ source,
66
+ offeredAt: new Date().toISOString(),
67
+ }, null, 2) + "\n",
68
+ "utf-8",
69
+ );
70
+ }
71
+
72
+ export function buildGsdPlannerSpawnPlan(input: GsdPlannerLaunchInput): GsdPlannerSpawnPlan {
73
+ const args = ["--project", input.basePath];
74
+ const milestoneId = input.milestoneId?.trim();
75
+ if (milestoneId) args.push("--milestone", milestoneId);
76
+ args.push(...(input.extraArgs ?? []));
77
+ return {
78
+ command: GSD_PLANNER_COMMAND,
79
+ args,
80
+ cwd: input.basePath,
81
+ };
82
+ }
83
+
84
+ function quoteArg(arg: string): string {
85
+ return /^[A-Za-z0-9_./:=@+-]+$/.test(arg) ? arg : JSON.stringify(arg);
86
+ }
87
+
88
+ export function formatGsdPlannerCommand(plan: GsdPlannerSpawnPlan): string {
89
+ return [plan.command, ...plan.args].map(quoteArg).join(" ");
90
+ }
91
+
92
+ export async function launchGsdPlanner(
93
+ input: GsdPlannerLaunchInput,
94
+ deps: GsdPlannerLaunchDeps = {},
95
+ ): Promise<GsdPlannerLaunchResult> {
96
+ const plan = buildGsdPlannerSpawnPlan(input);
97
+ const spawn = deps.spawn ?? spawnChild;
98
+
99
+ let child: ChildProcess;
100
+ try {
101
+ child = spawn(plan.command, plan.args, {
102
+ cwd: plan.cwd,
103
+ detached: true,
104
+ stdio: "ignore",
105
+ windowsHide: true,
106
+ });
107
+ } catch (err) {
108
+ return {
109
+ status: "failed",
110
+ plan,
111
+ error: err instanceof Error ? err : new Error(String(err)),
112
+ };
113
+ }
114
+
115
+ return new Promise((resolve) => {
116
+ let settled = false;
117
+ const settle = (result: GsdPlannerLaunchResult) => {
118
+ if (settled) return;
119
+ settled = true;
120
+ resolve(result);
121
+ };
122
+
123
+ child.once("error", (err) => {
124
+ settle({
125
+ status: "failed",
126
+ plan,
127
+ error: err instanceof Error ? err : new Error(String(err)),
128
+ });
129
+ });
130
+ child.once("spawn", () => {
131
+ child.unref();
132
+ settle({ status: "launched", plan });
133
+ });
134
+ });
135
+ }
136
+
137
+ export function formatPlannerHandoffPauseReason(milestoneId: string): string {
138
+ return [
139
+ `Milestone ${milestoneId} is planned. Review or customize the plan before implementation if needed.`,
140
+ `Run /gsd planner to launch ${GSD_PLANNER_COMMAND}, or run /gsd auto to continue without planner changes.`,
141
+ ].join(" ");
142
+ }
143
+
144
+ export function formatPlannerLaunchUnavailable(plan: GsdPlannerSpawnPlan, error: Error): string {
145
+ return [
146
+ `Could not launch ${GSD_PLANNER_COMMAND}: ${error.message}`,
147
+ `Install ${GSD_PLANNER_COMMAND} or run it manually: ${formatGsdPlannerCommand(plan)}`,
148
+ ].join("\n");
149
+ }
@@ -372,6 +372,7 @@ export function resolveAutoSupervisorConfig(): AutoSupervisorConfig {
372
372
  soft_timeout_minutes: configured.soft_timeout_minutes ?? 20,
373
373
  idle_timeout_minutes: configured.idle_timeout_minutes ?? 10,
374
374
  hard_timeout_minutes: configured.hard_timeout_minutes ?? 30,
375
+ stalled_tool_timeout_minutes: configured.stalled_tool_timeout_minutes ?? 5,
375
376
  ...(configured.model ? { model: configured.model } : {}),
376
377
  };
377
378
  }
@@ -256,6 +256,14 @@ export interface AutoSupervisorConfig {
256
256
  soft_timeout_minutes?: number;
257
257
  idle_timeout_minutes?: number;
258
258
  hard_timeout_minutes?: number;
259
+ /**
260
+ * Dedicated budget for a single in-flight tool call before it is treated as
261
+ * hung. Distinct from `idle_timeout_minutes`: a genuinely stuck tool should
262
+ * be recovered in minutes rather than waiting out the full idle window. A
263
+ * long-but-progressing session is not idle, so it must not share the hung-tool
264
+ * threshold.
265
+ */
266
+ stalled_tool_timeout_minutes?: number;
259
267
  }
260
268
 
261
269
  export interface RemoteQuestionsConfig {
@@ -14,7 +14,7 @@ All relevant context is preloaded below. Start immediately without re-reading th
14
14
 
15
15
  ## Already Planned? Soft Brake
16
16
 
17
- If `{{outputPath}}` exists with at least one slice line (e.g. `- [ ] **S01:`) AND `gsd_query` reports slice rows for this milestone, a prior `gsd_plan_milestone` call already persisted the plan. Do **not** re-call it; its UPSERT could overwrite existing planning. Skip to the ready phrase.
17
+ If `{{outputPath}}` exists with at least one slice line (e.g. `- [ ] **S01:`) AND `gsd_milestone_status` reports slice rows for this milestone, a prior `gsd_plan_milestone` call already persisted the plan. Do **not** re-call it; its UPSERT could overwrite existing planning. Skip to the ready phrase.
18
18
 
19
19
  If only the file or only DB rows exist, the prior write was incomplete; plan normally so the tool reconciles both.
20
20
 
@@ -27,7 +27,7 @@ You are the UAT runner. Execute every check defined in `{{uatPath}}` as deeply a
27
27
  ### Automation rules by mode
28
28
 
29
29
  - `artifact-driven` — verify with shell commands, scripts, file reads, and artifact structure checks.
30
- - `browser-executable` — use gsd-browser tools to navigate to the target URL and verify expected behavior. Prefer `mcp__gsd-browser__browser_*` tools when namespaced, or direct `browser_*` tools when surfaced without a namespace. Capture screenshots as evidence. Record pass/fail with specific assertions.
30
+ - `browser-executable` — use browser tools to navigate to the target URL and verify expected behavior. Prefer direct `browser_*` tools when available. Capture screenshots as evidence. Record pass/fail with specific assertions.
31
31
  - `runtime-executable` — execute the specified command or script. Capture stdout/stderr as evidence. Record pass/fail based on exit code and output.
32
32
  - `live-runtime` — exercise the real runtime path. Start or connect to the app/service if needed, use browser/runtime/network checks, and verify observable behavior.
33
33
  - `mixed` — run all automatable artifact-driven and live-runtime checks. Separate any remaining human-only checks explicitly.
@@ -48,7 +48,7 @@ Choose the lightest tool that proves the check honestly:
48
48
  - Run `node` / other script invocations
49
49
  - Read files and verify their contents
50
50
  - Check that expected artifacts exist and have correct structure
51
- - For live/runtime/UI checks, exercise the real flow with gsd-browser when applicable and inspect runtime/network/console state
51
+ - For live/runtime/UI checks, exercise the real flow with browser tools when applicable and inspect runtime/network/console state
52
52
  - When a check cannot be honestly automated, gather the best objective evidence you can and mark it `NEEDS-HUMAN`
53
53
 
54
54
  For each check, record:
@@ -75,24 +75,10 @@ verdict: "PASS" | "FAIL" | "PARTIAL",
75
75
  notes: "<one sentence overall verdict rationale>",
76
76
  ```
77
77
 
78
- Use this exact `presentation` shape in the save call so the audit can verify the run-uat tool surface without retrying missing fields one by one:
78
+ Use this canonical `presentation` object in the save call so the audit can verify the run-uat tool surface without retrying missing fields one by one. Keep `toolPresentationPlanId` as `{{toolPresentationPlanId}}`. If browser tools were actually presented for this run, add those concrete browser tool names to `presentedTools`; otherwise reuse this object exactly:
79
79
 
80
- ```ts
81
- presentation: {
82
- surface: "mcp",
83
- presentedTools: [
84
- "gsd_uat_exec",
85
- "gsd_uat_result_save",
86
- "gsd_resume",
87
- "gsd_milestone_status",
88
- "gsd_journal_query",
89
- ],
90
- blockedTools: [
91
- { name: "gsd_exec", reason: "forbidden during run-uat" },
92
- { name: "gsd_summary_save", reason: "forbidden during run-uat" },
93
- { name: "gsd_save_gate_result", reason: "forbidden during run-uat" },
94
- ],
95
- }
80
+ ```json
81
+ {{canonicalPresentation}}
96
82
  ```
97
83
 
98
84
  Pass `checks` with this logical shape:
@@ -118,7 +118,7 @@ Templates are in `{{templatesDir}}`.
118
118
 
119
119
  **Secrets:** Use `secure_env_collect`. Never ask the user to edit `.env` files or paste secrets.
120
120
 
121
- **Browser verification:** Verify frontend work against a running app with gsd-browser by default. Use `browser_find`/`browser_snapshot_refs` for discovery, refs/selectors -> `browser_batch` for actions, `browser_assert` for verification, and `browser_diff` -> console/network logs -> full inspection as last resort. If tools are MCP-namespaced, prefer `mcp__gsd-browser__browser_*`. Retry only with a new hypothesis.
121
+ **Browser verification:** Verify frontend work against a running app with browser tools by default. Use `browser_find`/`browser_snapshot_refs` for discovery, refs/selectors -> `browser_batch` for actions, `browser_assert` for verification, and `browser_diff` -> console/network logs -> full inspection as last resort. If browser tools are MCP-namespaced, use that host-provided browser surface. Retry only with a new hypothesis.
122
122
 
123
123
  **Database:** Never query `.gsd/gsd.db` directly via `sqlite3`, `better-sqlite3`, or `node -e require('better-sqlite3')`; the engine owns a single-writer WAL connection. Use `gsd_milestone_status`, `gsd_journal_query`, or other `gsd_*` tools.
124
124
 
@@ -6,7 +6,9 @@ import { ReconciliationFailedError } from "./state-reconciliation.js";
6
6
 
7
7
  export type RecoveryFailureKind =
8
8
  | "tool-schema"
9
+ | "tool-contract"
9
10
  | "deterministic-policy"
11
+ | "lifecycle-progression"
10
12
  | "stale-worker"
11
13
  | "worktree-invalid"
12
14
  | "verification-drift"
@@ -52,6 +54,14 @@ export function classifyFailure(input: RecoveryClassificationInput): RecoveryCla
52
54
  exitReason: "tool-schema",
53
55
  remediation: "Fix the Unit Tool Contract or tool schema before retrying.",
54
56
  };
57
+ case "tool-contract":
58
+ return {
59
+ failureKind,
60
+ action: "stop",
61
+ reason: `Tool Contract failure${unitSuffix(input)}: ${message}`,
62
+ exitReason: "tool-contract",
63
+ remediation: "Fix the Unit Tool Contract or prompt so the Unit is only asked to use tools owned by its phase.",
64
+ };
55
65
  case "deterministic-policy":
56
66
  return {
57
67
  failureKind,
@@ -60,6 +70,14 @@ export function classifyFailure(input: RecoveryClassificationInput): RecoveryCla
60
70
  exitReason: "deterministic-policy",
61
71
  remediation: "Resolve the policy blocker; retrying the same Unit will repeat the failure.",
62
72
  };
73
+ case "lifecycle-progression":
74
+ return {
75
+ failureKind,
76
+ action: "stop",
77
+ reason: `Lifecycle progression failure${unitSuffix(input)}: ${message}`,
78
+ exitReason: "lifecycle-progression",
79
+ remediation: "Route to the required owning Unit or restore the missing artifact before advancing lifecycle state.",
80
+ };
63
81
  case "stale-worker":
64
82
  return {
65
83
  failureKind,
@@ -118,6 +136,8 @@ export function classifyFailure(input: RecoveryClassificationInput): RecoveryCla
118
136
  }
119
137
 
120
138
  function inferFailureKind(message: string): RecoveryFailureKind {
139
+ if (/tool contract|auto-unit tool scope|phase-boundary gate|not permitted.*own/i.test(message)) return "tool-contract";
140
+ if (/lifecycle progression|required artifact|missing .*assessment|missing .*closeout|cannot legally (?:advance|progress)/i.test(message)) return "lifecycle-progression";
121
141
  if (/schema|invalid.*tool|tool.*invalid|enum/i.test(message)) return "tool-schema";
122
142
  if (/deterministic policy|policy rejection|write gate|blocked by policy/i.test(message)) return "deterministic-policy";
123
143
  if (/stale worker|stale lock|worker.*stale/i.test(message)) return "stale-worker";
@@ -117,6 +117,18 @@ const UNIT_TYPE_SKILL_MANIFEST: Record<string, string[]> = {
117
117
  "review",
118
118
  "accessibility",
119
119
  ],
120
+ // Slice closeout — the "closer" role: verify assembled task work, write the
121
+ // downstream-ready summary + UAT, optionally drive reviewer/security/tester
122
+ // subagents. Predictable skill set, mirrors `complete-milestone`.
123
+ "complete-slice": [
124
+ "verify-before-complete",
125
+ "test",
126
+ "review",
127
+ "security-review",
128
+ "write-docs",
129
+ "observability",
130
+ "handoff",
131
+ ],
120
132
  // `execute-task` intentionally omitted — implementation hot path covers a
121
133
  // wide surface of technologies; wildcard fallback preserves today's
122
134
  // behavior until per-task skill hints can be derived from task-plan