@opengsd/gsd-core 1.9.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (426) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -3
  3. package/.opencode/plugins/gsd-core.js +8 -1
  4. package/agents/gsd-code-fixer.md +27 -3
  5. package/agents/gsd-debug-session-manager.md +11 -0
  6. package/agents/gsd-debugger.md +12 -246
  7. package/agents/gsd-doc-synthesizer.md +2 -4
  8. package/agents/gsd-executor.md +12 -10
  9. package/agents/gsd-integration-checker.md +3 -0
  10. package/agents/gsd-mempalace-curator.md +5 -2
  11. package/agents/gsd-phase-researcher.md +20 -1
  12. package/agents/gsd-plan-checker.md +46 -0
  13. package/agents/gsd-planner.md +49 -54
  14. package/agents/gsd-roadmapper.md +21 -3
  15. package/agents/gsd-user-profiler.md +3 -0
  16. package/agents/gsd-verifier.md +26 -73
  17. package/bin/install.js +1272 -1238
  18. package/bin/lib/ui-safety-gate.cjs +2 -0
  19. package/commands/gsd/code-review.md +1 -1
  20. package/commands/gsd/execute-phase.md +1 -1
  21. package/commands/gsd/map-codebase.md +1 -1
  22. package/commands/gsd/mempalace-capture.md +2 -2
  23. package/commands/gsd/mempalace-recall.md +1 -1
  24. package/commands/gsd/new-milestone.md +2 -2
  25. package/commands/gsd/plan-phase.md +1 -1
  26. package/commands/gsd/quick.md +1 -1
  27. package/commands/gsd/review-backlog.md +2 -1
  28. package/commands/gsd/verify-work.md +1 -1
  29. package/gsd-core/bin/gsd-tools.cjs +1009 -115
  30. package/gsd-core/bin/lib/active-workstream-store.cjs +153 -12
  31. package/gsd-core/bin/lib/agent-install-check.cjs +268 -38
  32. package/gsd-core/bin/lib/api-coverage.cjs +123 -5
  33. package/gsd-core/bin/lib/artifacts.cjs +3 -0
  34. package/gsd-core/bin/lib/assumption-delta.cjs +2 -4
  35. package/gsd-core/bin/lib/audit-command-router.cjs +9 -2
  36. package/gsd-core/bin/lib/audit.cjs +926 -202
  37. package/gsd-core/bin/lib/broken-windows.cjs +36 -6
  38. package/gsd-core/bin/lib/capability-consent.cjs +149 -15
  39. package/gsd-core/bin/lib/capability-lifecycle.cjs +45 -0
  40. package/gsd-core/bin/lib/capability-registry.cjs +608 -148
  41. package/gsd-core/bin/lib/capability-source.cjs +92 -0
  42. package/gsd-core/bin/lib/capability-trust.cjs +444 -25
  43. package/gsd-core/bin/lib/capability-validator.cjs +507 -24
  44. package/gsd-core/bin/lib/capability-writer.cjs +3 -2
  45. package/gsd-core/bin/lib/check-command-router.cjs +114 -38
  46. package/gsd-core/bin/lib/claude-orchestration.cjs +56 -3
  47. package/gsd-core/bin/lib/codex-agent-toml.cjs +329 -0
  48. package/gsd-core/bin/lib/command-aliases.cjs +94 -0
  49. package/gsd-core/bin/lib/command-roster.cjs +44 -1
  50. package/gsd-core/bin/lib/commands.cjs +665 -99
  51. package/gsd-core/bin/lib/commonjs-marker.cjs +142 -0
  52. package/gsd-core/bin/lib/complexity-trigger.cjs +1172 -0
  53. package/gsd-core/bin/lib/config-loader.cjs +76 -0
  54. package/gsd-core/bin/lib/config.cjs +22 -2
  55. package/gsd-core/bin/lib/context-composer.cjs +278 -0
  56. package/gsd-core/bin/lib/context-predicates.cjs +506 -0
  57. package/gsd-core/bin/lib/core-utils.cjs +217 -40
  58. package/gsd-core/bin/lib/decisions.cjs +23 -0
  59. package/gsd-core/bin/lib/docs.cjs +3 -2
  60. package/gsd-core/bin/lib/external-job.cjs +19 -4
  61. package/gsd-core/bin/lib/fallow-runner.cjs +20 -44
  62. package/gsd-core/bin/lib/frontmatter.cjs +239 -32
  63. package/gsd-core/bin/lib/gap-checker.cjs +68 -7
  64. package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +57 -6
  65. package/gsd-core/bin/lib/git-base-branch.cjs +160 -15
  66. package/gsd-core/bin/lib/graphify.cjs +142 -27
  67. package/gsd-core/bin/lib/gsd2-import.cjs +37 -5
  68. package/gsd-core/bin/lib/health-diagnostic-rules/agent-install.cjs +101 -0
  69. package/gsd-core/bin/lib/health-diagnostic-rules/config-validation.cjs +348 -0
  70. package/gsd-core/bin/lib/health-diagnostic-rules/consistency.cjs +145 -0
  71. package/gsd-core/bin/lib/health-diagnostic-rules/install-surface-shadowing.cjs +98 -0
  72. package/gsd-core/bin/lib/health-diagnostic-rules/milestone-archive-hygiene.cjs +100 -0
  73. package/gsd-core/bin/lib/health-diagnostic-rules/phase-structure.cjs +222 -0
  74. package/gsd-core/bin/lib/health-diagnostic-rules/roadmap-disk-consistency.cjs +265 -0
  75. package/gsd-core/bin/lib/health-diagnostic-rules/root-existence.cjs +161 -0
  76. package/gsd-core/bin/lib/health-diagnostic-rules/state-consistency.cjs +303 -0
  77. package/gsd-core/bin/lib/health-diagnostic-rules/worktree-health.cjs +173 -0
  78. package/gsd-core/bin/lib/health-diagnostic-types.cjs +68 -0
  79. package/gsd-core/bin/lib/health-diagnostic.cjs +431 -0
  80. package/gsd-core/bin/lib/host-integration.cjs +13 -1
  81. package/gsd-core/bin/lib/host-runtime-detection.cjs +134 -0
  82. package/gsd-core/bin/lib/init-command-router.cjs +83 -8
  83. package/gsd-core/bin/lib/init.cjs +1325 -169
  84. package/gsd-core/bin/lib/install-effort-resolver.cjs +73 -30
  85. package/gsd-core/bin/lib/install-engine.cjs +805 -264
  86. package/gsd-core/bin/lib/install-fs-adapter.cjs +262 -0
  87. package/gsd-core/bin/lib/install-model-override-resolver.cjs +203 -0
  88. package/gsd-core/bin/lib/install-profiles.cjs +160 -57
  89. package/gsd-core/bin/lib/install-scope.cjs +270 -0
  90. package/gsd-core/bin/lib/install-shadow-report.cjs +385 -0
  91. package/gsd-core/bin/lib/installed-surface-resolver.cjs +381 -0
  92. package/gsd-core/bin/lib/installer-migration-authoring.cjs +3 -1
  93. package/gsd-core/bin/lib/installer-migration-report.cjs +4 -0
  94. package/gsd-core/bin/lib/installer-migrations/007-retire-config-root-commonjs-marker.cjs +149 -0
  95. package/gsd-core/bin/lib/installer-migrations/008-cursor-retire-commands-surface.cjs +55 -0
  96. package/gsd-core/bin/lib/installer-migrations/009-pi-retire-reserved-hooks-dir.cjs +199 -0
  97. package/gsd-core/bin/lib/installer-migrations.cjs +206 -13
  98. package/gsd-core/bin/lib/io.cjs +38 -3
  99. package/gsd-core/bin/lib/markdown-sectionizer.cjs +8 -1
  100. package/gsd-core/bin/lib/markdown-table.cjs +133 -20
  101. package/gsd-core/bin/lib/mcp-catalog.cjs +518 -0
  102. package/gsd-core/bin/lib/mcp-server.cjs +135 -3
  103. package/gsd-core/bin/lib/milestone-lock.cjs +248 -0
  104. package/gsd-core/bin/lib/milestone.cjs +821 -109
  105. package/gsd-core/bin/lib/model-catalog.cjs +59 -1
  106. package/gsd-core/bin/lib/model-resolver.cjs +183 -40
  107. package/gsd-core/bin/lib/normalize-test-command.cjs +1 -1
  108. package/gsd-core/bin/lib/pattern.cjs +122 -0
  109. package/gsd-core/bin/lib/phase-estimation.cjs +1 -1
  110. package/gsd-core/bin/lib/phase-id.cjs +507 -36
  111. package/gsd-core/bin/lib/phase-lifecycle.cjs +28 -3
  112. package/gsd-core/bin/lib/phase-locator.cjs +258 -58
  113. package/gsd-core/bin/lib/phase.cjs +891 -156
  114. package/gsd-core/bin/lib/plan-dependency-graph.cjs +303 -0
  115. package/gsd-core/bin/lib/plan-drift-guard.cjs +120 -0
  116. package/gsd-core/bin/lib/plan-scan.cjs +86 -2
  117. package/gsd-core/bin/lib/planning-scope.cjs +31 -0
  118. package/gsd-core/bin/lib/planning-snapshot.cjs +890 -0
  119. package/gsd-core/bin/lib/planning-workspace.cjs +60 -6
  120. package/gsd-core/bin/lib/probe-core.cjs +1 -1
  121. package/gsd-core/bin/lib/profile-output.cjs +1 -1
  122. package/gsd-core/bin/lib/prompt-budget.cjs +128 -165
  123. package/gsd-core/bin/lib/refactor-trigger-command-router.cjs +740 -0
  124. package/gsd-core/bin/lib/retired-artifact-cleanup.cjs +85 -0
  125. package/gsd-core/bin/lib/review-lane-descriptor.cjs +108 -0
  126. package/gsd-core/bin/lib/review-lane-invocation.cjs +30 -0
  127. package/gsd-core/bin/lib/review-lane-runner.cjs +447 -68
  128. package/gsd-core/bin/lib/review-reviewer-selection.cjs +13 -18
  129. package/gsd-core/bin/lib/roadmap-command-router.cjs +76 -9
  130. package/gsd-core/bin/lib/roadmap-parser.cjs +1035 -194
  131. package/gsd-core/bin/lib/roadmap-upgrade.cjs +37 -10
  132. package/gsd-core/bin/lib/roadmap.cjs +405 -84
  133. package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +795 -100
  134. package/gsd-core/bin/lib/runtime-artifact-install-plan.cjs +14 -2
  135. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +440 -57
  136. package/gsd-core/bin/lib/runtime-config-adapter-registry.cjs +3 -2
  137. package/gsd-core/bin/lib/runtime-homes.cjs +220 -41
  138. package/gsd-core/bin/lib/runtime-hooks-surface.cjs +220 -44
  139. package/gsd-core/bin/lib/runtime-name-policy.cjs +3 -1
  140. package/gsd-core/bin/lib/runtime-slash.cjs +27 -9
  141. package/gsd-core/bin/lib/section-manifest.cjs +209 -0
  142. package/gsd-core/bin/lib/security.cjs +104 -5
  143. package/gsd-core/bin/lib/shell-command-projection.cjs +388 -30
  144. package/gsd-core/bin/lib/smart-entry.cjs +154 -22
  145. package/gsd-core/bin/lib/state-command-router.cjs +5 -1
  146. package/gsd-core/bin/lib/state-document.cjs +152 -8
  147. package/gsd-core/bin/lib/state-transition.cjs +424 -105
  148. package/gsd-core/bin/lib/state.cjs +1927 -401
  149. package/gsd-core/bin/lib/surface.cjs +35 -10
  150. package/gsd-core/bin/lib/text-lines.cjs +80 -0
  151. package/gsd-core/bin/lib/token-scanner.cjs +76 -0
  152. package/gsd-core/bin/lib/uat-predicate.cjs +20 -4
  153. package/gsd-core/bin/lib/uat.cjs +706 -64
  154. package/gsd-core/bin/lib/ui-frontend-evidence.cjs +157 -0
  155. package/gsd-core/bin/lib/ui-safety-gate.cjs +14 -5
  156. package/gsd-core/bin/lib/unusable-input.cjs +33 -0
  157. package/gsd-core/bin/lib/update-context.cjs +8 -2
  158. package/gsd-core/bin/lib/user-artifact-staging.cjs +705 -0
  159. package/gsd-core/bin/lib/validate.cjs +20 -6
  160. package/gsd-core/bin/lib/vendor/README.md +37 -0
  161. package/gsd-core/bin/lib/vendor/re2js.cjs +6480 -0
  162. package/gsd-core/bin/lib/vendor/re2js.d.cts +938 -0
  163. package/gsd-core/bin/lib/verification-command-router.cjs +2 -1
  164. package/gsd-core/bin/lib/verification.cjs +287 -20
  165. package/gsd-core/bin/lib/verify.cjs +368 -880
  166. package/gsd-core/bin/lib/workflow-fragments.cjs +557 -0
  167. package/gsd-core/bin/lib/workstream-inventory-builder.cjs +203 -19
  168. package/gsd-core/bin/lib/workstream-inventory.cjs +576 -31
  169. package/gsd-core/bin/lib/workstream.cjs +8 -2
  170. package/gsd-core/bin/lib/worktree-base-ref.cjs +50 -6
  171. package/gsd-core/bin/lib/worktree-safety.cjs +450 -125
  172. package/gsd-core/bin/shared/config-defaults.manifest.json +1 -0
  173. package/gsd-core/bin/shared/config-schema.manifest.json +9 -1
  174. package/gsd-core/references/agent-contracts.md +43 -26
  175. package/gsd-core/references/artifact-types.md +10 -3
  176. package/gsd-core/references/autonomous-ui-design-contract.md +42 -0
  177. package/gsd-core/references/checkpoints.md +2 -2
  178. package/gsd-core/references/context-budget.md +1 -1
  179. package/gsd-core/references/debugger-techniques.md +255 -0
  180. package/gsd-core/references/dispatch-isolation-gate.md +138 -0
  181. package/gsd-core/references/doc-conflict-engine.md +1 -1
  182. package/gsd-core/references/execute-mvp-tdd.md +3 -3
  183. package/gsd-core/references/execute-phase-between-wave-reset.md +6 -2
  184. package/gsd-core/references/execute-phase-context-guard.md +1 -1
  185. package/gsd-core/references/execute-phase-response-language.md +1 -1
  186. package/gsd-core/references/execute-phase-wave-guard.md +6 -2
  187. package/gsd-core/references/gate-prompts.md +1 -1
  188. package/gsd-core/references/git-planning-commit.md +2 -1
  189. package/gsd-core/references/loop-hook-dispatch.md +39 -2
  190. package/gsd-core/references/model-profiles.md +12 -4
  191. package/gsd-core/references/mvp-concepts.md +9 -9
  192. package/gsd-core/references/planner-guidance.md +3 -9
  193. package/gsd-core/references/planner-preconditions.md +1 -1
  194. package/gsd-core/references/planner-reviews.md +1 -1
  195. package/gsd-core/references/planning-config.md +8 -6
  196. package/gsd-core/references/research-documentation-lookup.md +5 -3
  197. package/gsd-core/references/revision-loop.md +1 -1
  198. package/gsd-core/references/specless-probe-fallback.md +8 -7
  199. package/gsd-core/references/universal-anti-patterns.md +3 -3
  200. package/gsd-core/references/verifier-phase-gates.md +192 -0
  201. package/gsd-core/references/verifier-wiring-patterns.md +100 -0
  202. package/gsd-core/references/verify-mvp-mode.md +1 -1
  203. package/gsd-core/references/workstream-flag.md +22 -6
  204. package/gsd-core/references/worktree-branch-check.md +2 -2
  205. package/gsd-core/templates/discussion-log.md +1 -1
  206. package/gsd-core/templates/phase-prompt.md +2 -4
  207. package/gsd-core/templates/state.md +4 -4
  208. package/gsd-core/templates/summary-complex.md +2 -0
  209. package/gsd-core/templates/summary-minimal.md +2 -0
  210. package/gsd-core/templates/summary-standard.md +2 -0
  211. package/gsd-core/templates/summary.md +2 -0
  212. package/gsd-core/templates/verification-report.md +9 -1
  213. package/gsd-core/workflows/ai-integration-phase.md +9 -11
  214. package/gsd-core/workflows/audit-milestone.md +3 -0
  215. package/gsd-core/workflows/autonomous/steps/converge-banner.md +1 -0
  216. package/gsd-core/workflows/autonomous/steps/converge-dispatch-bg.md +11 -0
  217. package/gsd-core/workflows/autonomous/steps/converge-dispatch-inline.md +7 -0
  218. package/gsd-core/workflows/autonomous/steps/converge-fail-fast.md +21 -0
  219. package/gsd-core/workflows/autonomous/steps/converge-loop.md +7 -0
  220. package/gsd-core/workflows/autonomous.md +33 -70
  221. package/gsd-core/workflows/cleanup.md +62 -3
  222. package/gsd-core/workflows/code-review/steps/dispatch-fix.md +39 -0
  223. package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +93 -0
  224. package/gsd-core/workflows/code-review-fix.md +37 -10
  225. package/gsd-core/workflows/code-review.md +74 -166
  226. package/gsd-core/workflows/complete-milestone/steps/git-tag.md +29 -0
  227. package/gsd-core/workflows/complete-milestone.md +160 -95
  228. package/gsd-core/workflows/debug.md +16 -17
  229. package/gsd-core/workflows/diagnose-issues.md +56 -8
  230. package/gsd-core/workflows/discuss-phase/modes/chain.md +2 -1
  231. package/gsd-core/workflows/discuss-phase/modes/default.md +1 -1
  232. package/gsd-core/workflows/discuss-phase-assumptions/steps/auto-advance-dispatch.md +15 -0
  233. package/gsd-core/workflows/discuss-phase-assumptions.md +7 -17
  234. package/gsd-core/workflows/docs-update/steps/dispatch-monorepo-packages.md +51 -0
  235. package/gsd-core/workflows/docs-update.md +8 -51
  236. package/gsd-core/workflows/edit-phase.md +26 -1
  237. package/gsd-core/workflows/eval-review.md +3 -5
  238. package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +64 -7
  239. package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +50 -0
  240. package/gsd-core/workflows/execute-phase/steps/partial-wave.md +31 -0
  241. package/gsd-core/workflows/execute-phase/steps/per-plan-executor-routing.md +77 -0
  242. package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +21 -0
  243. package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +42 -0
  244. package/gsd-core/workflows/execute-phase/steps/regression-gate.md +43 -37
  245. package/gsd-core/workflows/execute-phase.md +103 -187
  246. package/gsd-core/workflows/execute-plan.md +36 -4
  247. package/gsd-core/workflows/explore.md +131 -4
  248. package/gsd-core/workflows/fast.md +10 -2
  249. package/gsd-core/workflows/health.md +73 -4
  250. package/gsd-core/workflows/help/modes/full.md +6 -1
  251. package/gsd-core/workflows/import.md +4 -4
  252. package/gsd-core/workflows/ingest-docs.md +7 -6
  253. package/gsd-core/workflows/mvp-phase.md +6 -3
  254. package/gsd-core/workflows/new-milestone/steps/project-md-milestone-write.md +16 -0
  255. package/gsd-core/workflows/new-milestone/steps/reset-phase-safety.md +19 -0
  256. package/gsd-core/workflows/new-milestone.md +35 -47
  257. package/gsd-core/workflows/new-project/steps/auto-mode-config.md +176 -0
  258. package/gsd-core/workflows/new-project/steps/auto-mode-detection.md +32 -0
  259. package/gsd-core/workflows/new-project/steps/codebase-map-offer.md +18 -0
  260. package/gsd-core/workflows/new-project.md +27 -240
  261. package/gsd-core/workflows/next.md +12 -0
  262. package/gsd-core/workflows/plan-phase/steps/adr-ingest-express-path.md +15 -0
  263. package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +110 -0
  264. package/gsd-core/workflows/plan-phase/steps/prd-express-gate.md +8 -0
  265. package/gsd-core/workflows/plan-phase/steps/research-only-early-exit.md +17 -0
  266. package/gsd-core/workflows/plan-phase/steps/research-only-modifiers.md +16 -0
  267. package/gsd-core/workflows/plan-phase/steps/reviews-prerequisite.md +17 -0
  268. package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +149 -0
  269. package/gsd-core/workflows/plan-phase.md +89 -209
  270. package/gsd-core/workflows/plan-review-convergence.md +50 -2
  271. package/gsd-core/workflows/progress/steps/forensic-audit.md +125 -0
  272. package/gsd-core/workflows/progress/steps/mvp-display.md +18 -0
  273. package/gsd-core/workflows/progress.md +45 -159
  274. package/gsd-core/workflows/quick/steps/discussion-phase.md +124 -0
  275. package/gsd-core/workflows/quick/steps/plan-checker-loop.md +111 -0
  276. package/gsd-core/workflows/quick/steps/quick-verification.md +67 -0
  277. package/gsd-core/workflows/quick/steps/research-phase.md +72 -0
  278. package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +37 -0
  279. package/gsd-core/workflows/quick.md +55 -405
  280. package/gsd-core/workflows/resume-project.md +3 -0
  281. package/gsd-core/workflows/review/steps/reviewer-instances-note-1.md +4 -0
  282. package/gsd-core/workflows/review/steps/reviewer-instances-note-2.md +3 -0
  283. package/gsd-core/workflows/review.md +41 -13
  284. package/gsd-core/workflows/section-manifest.json +219 -0
  285. package/gsd-core/workflows/secure-phase.md +1 -1
  286. package/gsd-core/workflows/session-report.md +2 -1
  287. package/gsd-core/workflows/settings.md +66 -2
  288. package/gsd-core/workflows/ship.md +104 -44
  289. package/gsd-core/workflows/sketch.md +1 -1
  290. package/gsd-core/workflows/spec-phase.md +41 -20
  291. package/gsd-core/workflows/spike-wrap-up.md +20 -5
  292. package/gsd-core/workflows/spike.md +50 -16
  293. package/gsd-core/workflows/sync-skills.md +106 -13
  294. package/gsd-core/workflows/transition/steps/workstream-collision-check.md +17 -0
  295. package/gsd-core/workflows/transition.md +53 -31
  296. package/gsd-core/workflows/ui-phase.md +13 -12
  297. package/gsd-core/workflows/ui-review.md +2 -2
  298. package/gsd-core/workflows/update/steps/channel-banner.md +7 -0
  299. package/gsd-core/workflows/update.md +19 -8
  300. package/gsd-core/workflows/validate-phase.md +1 -1
  301. package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +36 -0
  302. package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +21 -0
  303. package/gsd-core/workflows/verify-work.md +17 -65
  304. package/hooks/dist/gsd-agent-isolation-guard.js +517 -0
  305. package/hooks/dist/gsd-check-update-worker.js +64 -12
  306. package/hooks/dist/gsd-check-update.js +19 -1
  307. package/hooks/dist/gsd-cursor-pre-tool.js +0 -3
  308. package/hooks/dist/gsd-cursor-subagent-start.js +607 -26
  309. package/hooks/dist/gsd-cursor-subagent-stop.js +3 -2
  310. package/hooks/dist/gsd-prompt-guard.js +21 -20
  311. package/hooks/dist/gsd-read-injection-scanner.js +45 -24
  312. package/hooks/dist/gsd-statusline.js +90 -6
  313. package/hooks/dist/gsd-update-banner.js +22 -1
  314. package/hooks/dist/gsd-workflow-guard.js +134 -36
  315. package/hooks/dist/gsd-worktree-path-guard.js +2 -1
  316. package/hooks/dist/gsd-write-guard.js +359 -0
  317. package/hooks/dist/lib/git-cmd.js +92 -59
  318. package/hooks/dist/lib/injection-patterns.js +45 -0
  319. package/hooks/dist/lib/isolation-deny-reason.js +39 -0
  320. package/hooks/dist/lib/isolation-sentinel.js +277 -0
  321. package/hooks/dist/managed-hooks-registry.cjs +2 -0
  322. package/hooks/gsd-agent-isolation-guard.js +517 -0
  323. package/hooks/gsd-check-update-worker.js +64 -12
  324. package/hooks/gsd-check-update.js +19 -1
  325. package/hooks/gsd-cursor-pre-tool.js +0 -3
  326. package/hooks/gsd-cursor-subagent-start.js +607 -26
  327. package/hooks/gsd-cursor-subagent-stop.js +3 -2
  328. package/hooks/gsd-prompt-guard.js +21 -20
  329. package/hooks/gsd-read-injection-scanner.js +45 -24
  330. package/hooks/gsd-statusline.js +90 -6
  331. package/hooks/gsd-update-banner.js +22 -1
  332. package/hooks/gsd-workflow-guard.js +134 -36
  333. package/hooks/gsd-worktree-path-guard.js +2 -1
  334. package/hooks/gsd-write-guard.js +359 -0
  335. package/hooks/hooks.json +12 -0
  336. package/hooks/lib/git-cmd.js +92 -59
  337. package/hooks/lib/injection-patterns.js +45 -0
  338. package/hooks/lib/isolation-deny-reason.js +39 -0
  339. package/hooks/lib/isolation-sentinel.js +277 -0
  340. package/hooks/managed-hooks-registry.cjs +2 -0
  341. package/package.json +31 -10
  342. package/pi/gsd.cjs +71 -12
  343. package/scripts/baselines/planning-prompt-drift-baseline.json +4 -0
  344. package/scripts/baselines/planning-snapshot-bypass-baseline.json +12 -0
  345. package/scripts/baselines/unreachable-guard-drift-baseline.json +4 -0
  346. package/scripts/build-hooks.js +9 -0
  347. package/scripts/changeset/lint.cjs +68 -6
  348. package/scripts/changeset/serialize.cjs +5 -1
  349. package/scripts/check-alias-drift.cjs +7 -43
  350. package/scripts/check-contract-drift.cjs +297 -0
  351. package/scripts/ci-test-scope.cjs +19 -2
  352. package/scripts/command-contract-helpers.cjs +903 -1
  353. package/scripts/gen-adr-index.cjs +728 -38
  354. package/scripts/gen-capability-matrix.cjs +1 -1
  355. package/scripts/gen-capability-registry.cjs +3 -15
  356. package/scripts/gen-context-index.cjs +439 -0
  357. package/scripts/gen-health-docs.cjs +390 -0
  358. package/scripts/gen-inventory-manifest.cjs +150 -4
  359. package/scripts/gen-loop-host-contract.cjs +4 -24
  360. package/scripts/gen-prompt-budget-parity-corpus.cjs +645 -0
  361. package/scripts/gen-registry.cjs +3 -14
  362. package/scripts/gen-section-manifest.cjs +638 -0
  363. package/scripts/generate-package-identity.cjs +4 -2
  364. package/scripts/lib/alias-drift-families.cjs +46 -0
  365. package/scripts/lib/drift-scan.cjs +278 -0
  366. package/scripts/lint-allow-test-rule-refs.allowlist.json +15 -54
  367. package/scripts/lint-allow-test-rule-refs.effective-ceiling.json +4 -0
  368. package/scripts/lint-allow-test-rule-refs.unverified-ceiling.json +3 -0
  369. package/scripts/lint-canary-version-leak.cjs +73 -0
  370. package/scripts/lint-command-contract.cjs +96 -13
  371. package/scripts/lint-compiled-artifact-sync.cjs +6 -1
  372. package/scripts/lint-completion-predicate-drift.cjs +933 -0
  373. package/scripts/lint-completion-ratio-drift.cjs +214 -0
  374. package/scripts/lint-default-flip-documentation.cjs +193 -0
  375. package/scripts/lint-docs-command-form.cjs +195 -0
  376. package/scripts/lint-docs-required.cjs +9 -1
  377. package/scripts/lint-emitted-drift-ack.cjs +215 -20
  378. package/scripts/lint-eslint-glob-coverage.allowlist.json +34 -0
  379. package/scripts/lint-eslint-glob-coverage.cjs +340 -0
  380. package/scripts/lint-example-parser-parity.cjs +395 -0
  381. package/scripts/lint-frontmatter-scalar-broad-grep.cjs +237 -0
  382. package/scripts/lint-health-diagnostic-rule-table.cjs +404 -0
  383. package/scripts/lint-hooks-runtime-build-seam.cjs +262 -0
  384. package/scripts/lint-milestone-window-drift.cjs +468 -0
  385. package/scripts/lint-phase-enumeration-drift.cjs +479 -0
  386. package/scripts/lint-plan-count-drift.cjs +318 -0
  387. package/scripts/lint-planning-artifact-writer-drift.cjs +398 -0
  388. package/scripts/lint-planning-prompt-drift.cjs +434 -0
  389. package/scripts/lint-planning-snapshot-bypass-drift.cjs +544 -0
  390. package/scripts/lint-regression-test-names.cjs +15 -13
  391. package/scripts/lint-removed-but-needed.cjs +320 -0
  392. package/scripts/lint-state-field-drift.cjs +805 -0
  393. package/scripts/lint-state-write-path-drift.cjs +1045 -0
  394. package/scripts/lint-test-file-count.allowlist.json +40 -3
  395. package/scripts/lint-unreachable-guard-drift.cjs +843 -0
  396. package/scripts/lint-vendored-deps.cjs +124 -0
  397. package/scripts/mutation-matrix.cjs +13 -0
  398. package/scripts/pr-changed-files.cjs +63 -0
  399. package/scripts/pr-template-policy.cjs +14 -4
  400. package/scripts/prompt-injection-scan.sh +52 -6
  401. package/scripts/require-issue-link-policy.cjs +192 -0
  402. package/scripts/state-write-path-drift-baseline.json +19 -0
  403. package/scripts/sync-runtime-launcher.cjs +2 -4
  404. package/skills/gsd-autonomous/SKILL.md +0 -1
  405. package/skills/gsd-code-review/SKILL.md +1 -1
  406. package/skills/gsd-execute-phase/SKILL.md +1 -2
  407. package/skills/gsd-map-codebase/SKILL.md +1 -1
  408. package/skills/gsd-mempalace-capture/SKILL.md +2 -2
  409. package/skills/gsd-mempalace-recall/SKILL.md +1 -1
  410. package/skills/gsd-new-milestone/SKILL.md +2 -2
  411. package/skills/gsd-next/SKILL.md +0 -1
  412. package/skills/gsd-plan-phase/SKILL.md +1 -2
  413. package/skills/gsd-progress/SKILL.md +0 -1
  414. package/skills/gsd-quick/SKILL.md +1 -1
  415. package/skills/gsd-review-backlog/SKILL.md +2 -1
  416. package/skills/gsd-stats/SKILL.md +0 -1
  417. package/skills/gsd-verify-work/SKILL.md +1 -1
  418. package/vscode/package.json +1 -1
  419. package/gsd-core/workflows/discovery-phase.md +0 -298
  420. package/gsd-core/workflows/plan-milestone-gaps.md +0 -281
  421. package/gsd-core/workflows/verify-phase.md +0 -577
  422. package/scripts/affected-tests-lib.cjs +0 -554
  423. package/scripts/gen-emitted-baseline.cjs +0 -145
  424. package/scripts/lint-allow-test-rule-refs.cjs +0 -162
  425. package/scripts/run-affected-tests.cjs +0 -7
  426. package/scripts/run-tests.cjs +0 -1050
@@ -27,50 +27,142 @@ const planScan = require("./plan-scan.cjs");
27
27
  const planningWorkspace = require("./planning-workspace.cjs");
28
28
  const { planningPaths, planningRoot, getActiveWorkstream } = planningWorkspace;
29
29
  const state_document_cjs_1 = require("./state-document.cjs");
30
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- frontmatter.cjs is an export= CommonJS module
31
+ const frontmatterMod = require("./frontmatter.cjs");
32
+ const { extractFrontmatter, stripFrontmatter } = frontmatterMod;
33
+ const markdown_table_cjs_1 = require("./markdown-table.cjs");
34
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- verification.cjs is an export= CommonJS module
35
+ const verificationMod = require("./verification.cjs");
36
+ const { isPhaseComplete } = verificationMod;
37
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- phase-id.cjs is an export= CommonJS module
38
+ const phaseIdMod = require("./phase-id.cjs");
39
+ const { phaseKeyFromDir, phaseKeyFromProse, parentPhaseKey } = phaseIdMod;
40
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- roadmap-parser.cjs is an export= CommonJS module
41
+ const roadmapParserMod = require("./roadmap-parser.cjs");
42
+ const { getMilestonePhaseFilter, isMilestoneShippedInRoadmap } = roadmapParserMod;
30
43
  const workstream_inventory_builder_cjs_1 = require("./workstream-inventory-builder.cjs");
31
44
  // ─── Implementation ───────────────────────────────────────────────────────────
32
45
  function workstreamsRoot(cwd) {
33
46
  return node_path_1.default.join(planningRoot(cwd), 'workstreams');
34
47
  }
35
- function countRoadmapPhases(roadmapPath, fallbackCount) {
48
+ /**
49
+ * #3185 (ADR-3180 Decision 1): count the phases the CURRENT milestone
50
+ * declares, not every `Phase` heading in the file.
51
+ *
52
+ * This previously matched `^#{2,4}\s+Phase\s+…` across the whole ROADMAP with
53
+ * no milestone window and no sentinel filter, so it counted 999.* backlog and
54
+ * Phase 0 headings and spanned every milestone the document had ever had.
55
+ * `getMilestonePhaseFilter` already computes exactly this number for the
56
+ * scoped window (`phaseCount`, sentinel-filtered), and `inspectWorkstream` in
57
+ * this same file already passes a resolved `currentVersion` to it — this
58
+ * function was the sibling copy that never got the fix.
59
+ */
60
+ function countRoadmapPhases(roadmapPath, fallbackCount, cwd, ws, versionOverride) {
36
61
  try {
37
- const roadmapContent = node_fs_1.default.readFileSync(roadmapPath, 'utf-8');
38
- const matches = roadmapContent.match(/^#{2,4}\s+Phase\s+[\w][\w.-]*/gm);
39
- return matches ? matches.length : fallbackCount;
62
+ if (!node_fs_1.default.existsSync(roadmapPath))
63
+ return fallbackCount;
64
+ if (!cwd)
65
+ return fallbackCount;
66
+ const filter = getMilestonePhaseFilter(cwd, versionOverride ?? null, null, ws ?? null);
67
+ // A pass-all degrade (phaseCount 0) means the window declared no phases —
68
+ // fall back rather than reporting a confident zero.
69
+ return filter.phaseCount > 0 ? filter.phaseCount : fallbackCount;
40
70
  }
41
71
  catch {
42
72
  return fallbackCount;
43
73
  }
44
74
  }
45
- function countPhaseFiles(phaseDir) {
46
- const scan = planScan(phaseDir);
47
- return { planCount: scan.planCount, summaryCount: scan.summaryCount };
75
+ /**
76
+ * #2562: parse the ROADMAP `## Progress` table into canonical phase keys with
77
+ * their milestone attribution, e.g. `| 30. Name | v10.0 | 1/3 | … |` →
78
+ * `{ key: '30', version: 'v10.0' }`. The table is the authoritative per-phase
79
+ * milestone attribution and — crucially — lists phases declared but never
80
+ * scaffolded (no directory), which a directory-only scan misses. `Plans
81
+ * Complete` is present in BOTH RoadmapProgress variants, so this matches the
82
+ * flat (no Milestone column → every `version` null) and milestone-grouped
83
+ * shapes alike.
84
+ *
85
+ * Row keys come from `phaseKeyFromProse`, the same owner-module derivation
86
+ * `phaseKeyFromDir` uses for directories, so a `| 01. … |` row and a `1-slug`
87
+ * directory cannot land in different key spaces (the padding-asymmetry defect).
88
+ */
89
+ function parseRoadmapProgressRows(roadmapPath) {
90
+ let content;
91
+ try {
92
+ content = node_fs_1.default.readFileSync(roadmapPath, 'utf-8');
93
+ }
94
+ catch {
95
+ return []; /* no roadmap */
96
+ }
97
+ // Milestone-ATTRIBUTING shape first. Both shapes carry `Plans Complete`, so
98
+ // probing that column first would pick a flat table appearing earlier in the
99
+ // document over a milestone-grouped one later — every row would come back
100
+ // unattributed and be treated as current-milestone, silently over-including.
101
+ const table = (0, markdown_table_cjs_1.findTableWithColumns)(content, ['Phase', 'Milestone'])
102
+ ?? (0, markdown_table_cjs_1.findTableWithColumns)(content, ['Phase', 'Plans Complete']);
103
+ if (!table)
104
+ return [];
105
+ const rows = [];
106
+ for (const row of table.rows) {
107
+ const key = phaseKeyFromProse(row['Phase']);
108
+ if (key === null)
109
+ continue;
110
+ const cell = (row['Milestone'] ?? '').trim();
111
+ rows.push({ key, version: /^v\d+(?:\.\d+)+$/.test(cell) ? cell : null });
112
+ }
113
+ return rows;
48
114
  }
49
- function readStateProjection(statePath) {
115
+ /**
116
+ * #2562: the workstream's CURRENT milestone version, read from the STATE.md
117
+ * `milestone:` frontmatter field (the reliable per-workstream signal — the
118
+ * ROADMAP's own in-progress markers can be stale, e.g. a lingering 🚧 on an
119
+ * already-shipped milestone). Falls back to the ROADMAP in-progress heading
120
+ * marker only when STATE has no field.
121
+ */
122
+ function readCurrentMilestoneVersion(statePath, roadmapPath) {
50
123
  try {
51
- const stateContent = node_fs_1.default.readFileSync(statePath, 'utf-8');
52
- return {
53
- status: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Status') || 'unknown',
54
- current_phase: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Current Phase'),
55
- last_activity: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Last Activity'),
56
- };
124
+ const m = node_fs_1.default.readFileSync(statePath, 'utf-8').match(/^milestone:\s*["']?(v\d+(?:\.\d+)+)["']?/m);
125
+ if (m)
126
+ return m[1];
57
127
  }
58
128
  catch {
59
- return {
60
- status: 'unknown',
61
- current_phase: null,
62
- last_activity: null,
63
- };
129
+ /* no state */
130
+ }
131
+ try {
132
+ const rm = node_fs_1.default.readFileSync(roadmapPath, 'utf-8').match(/(?:🚧|🔄)\s*\*\*(v\d+(?:\.\d+)+)\b/);
133
+ if (rm)
134
+ return rm[1];
135
+ }
136
+ catch {
137
+ /* no roadmap */
138
+ }
139
+ return null;
140
+ }
141
+ /**
142
+ * #2562: does the CURRENT milestone's own ROADMAP heading carry a shipped
143
+ * marker? Delegated to `roadmap-parser`, the module that owns milestone-heading
144
+ * classification: heading/`<summary>` lines only (never a bullet that merely
145
+ * names the version), version-token boundary-matched so `v2.0` does not match
146
+ * inside `v2.0.1`, and in-progress markers win. Scoped to the current version,
147
+ * so a prior milestone's collapsed `<details><summary>✅ … SHIPPED</summary>`
148
+ * block can never mark the current milestone complete.
149
+ */
150
+ function currentMilestoneHeadingShipped(roadmapPath, version) {
151
+ try {
152
+ return isMilestoneShippedInRoadmap(node_fs_1.default.readFileSync(roadmapPath, 'utf-8'), version);
153
+ }
154
+ catch {
155
+ return false; /* no roadmap */
64
156
  }
65
157
  }
66
158
  /**
67
- * #1913: detect an authoritative shipped signal for a workstream so the
68
- * inventory status is never trusted from the mutable STATE.md `Status` field
69
- * alone. Returns true when EITHER an archived milestone snapshot is present
70
- * under `<planningBase>/milestones/` OR the workstream ROADMAP carries a
71
- * SHIPPED marker — both are hard to desync, unlike the hand-maintained field.
159
+ * Legacy pre-#2562 shipped detection: ANY archived milestone snapshot OR a
160
+ * SHIPPED marker anywhere in the ROADMAP. Over-broad (project-lifetime, not
161
+ * milestone-scoped) — retained ONLY as the fallback when the current milestone
162
+ * version cannot be determined (malformed/legacy STATE.md with no `milestone:`
163
+ * field), so those projects keep #1913's stale-field protection.
72
164
  */
73
- function workstreamMilestoneShipped(roadmapPath, planningBase) {
165
+ function legacyMilestoneShipped(roadmapPath, planningBase) {
74
166
  try {
75
167
  const milestonesDir = node_path_1.default.join(planningBase, 'milestones');
76
168
  for (const entry of node_fs_1.default.readdirSync(milestonesDir, { withFileTypes: true })) {
@@ -90,6 +182,219 @@ function workstreamMilestoneShipped(roadmapPath, planningBase) {
90
182
  }
91
183
  return false;
92
184
  }
185
+ /**
186
+ * #2562: directory mtime, used only to break a duplicate-phase-key tie in the
187
+ * rollup (keep the more recently touched directory — the Bug #2445 rule). 0 on
188
+ * a stat failure, which loses the tie rather than throwing.
189
+ */
190
+ function phaseDirMtime(phaseDir) {
191
+ try {
192
+ return node_fs_1.default.statSync(phaseDir).mtimeMs;
193
+ }
194
+ catch {
195
+ return 0;
196
+ }
197
+ }
198
+ function countPhaseFiles(phaseDir) {
199
+ const scan = planScan(phaseDir);
200
+ return { planCount: scan.planCount, summaryCount: scan.summaryCount };
201
+ }
202
+ function verificationLedgerPath(wsDir) {
203
+ return node_path_1.default.join(wsDir, '.verification-ledger.json');
204
+ }
205
+ function readVerificationLedger(wsDir) {
206
+ const ledgerPath = verificationLedgerPath(wsDir);
207
+ let raw;
208
+ try {
209
+ raw = node_fs_1.default.readFileSync(ledgerPath, 'utf-8');
210
+ }
211
+ catch (err) {
212
+ // `fs.readFileSync` FOLLOWS symlinks, so a broken symlink at this path
213
+ // (the entry exists, its target does not) reports the EXACT SAME
214
+ // `ENOENT` as genuine absence — `code` alone cannot distinguish
215
+ // "nothing was ever here" from "something is here and cannot be read".
216
+ // `fs.lstatSync` does NOT follow symlinks, so it still finds the
217
+ // symlink entry itself even when its target is gone. Only when NEITHER
218
+ // call finds anything is this genuinely `'absent'` (pre-adoption); a
219
+ // present-but-broken symlink is evidence something existed and must
220
+ // fail CLOSED like any other unreadable ledger, not fall open.
221
+ const code = err?.code;
222
+ if (code === 'ENOENT') {
223
+ try {
224
+ node_fs_1.default.lstatSync(ledgerPath);
225
+ return { state: 'corrupt', entries: {} }; // a symlink entry exists; its target does not
226
+ }
227
+ catch (lstatErr) {
228
+ // #2645 review: every OTHER failure path in this function fails
229
+ // CLOSED — this one must too. A failed `lstatSync` is only proof of
230
+ // absence when IT ALSO reports `ENOENT`; anything else (a raced
231
+ // permission change, a path component that became inaccessible
232
+ // between the two calls, …) is not evidence the file was never
233
+ // there, and a bare `catch {}` here would silently fall OPEN exactly
234
+ // like the two-state design this fix replaced.
235
+ const lstatCode = lstatErr?.code;
236
+ if (lstatCode === 'ENOENT')
237
+ return { state: 'absent', entries: {} }; // truly nothing at this path
238
+ return { state: 'corrupt', entries: {} };
239
+ }
240
+ }
241
+ // Any OTHER read failure (EACCES, EISDIR, …) also means the path EXISTS
242
+ // in some form but this process cannot see its content right now — that
243
+ // is corruption from this reader's point of view, not absence, and must
244
+ // fail closed rather than silently falling back to the ungated
245
+ // pre-adoption behavior.
246
+ return { state: 'corrupt', entries: {} };
247
+ }
248
+ let parsed;
249
+ try {
250
+ parsed = JSON.parse(raw);
251
+ }
252
+ catch {
253
+ return { state: 'corrupt', entries: {} };
254
+ }
255
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
256
+ return { state: 'corrupt', entries: {} };
257
+ }
258
+ const out = {};
259
+ for (const [key, value] of Object.entries(parsed)) {
260
+ if (typeof value === 'string')
261
+ out[key] = value;
262
+ }
263
+ return { state: 'ok', entries: out };
264
+ }
265
+ // #2645 review: Windows can transiently hold the rename target busy (AV
266
+ // scanners, indexers) — the SAME retry shape `broken-windows.cts`'s
267
+ // `writeLedgerAtomic`/`renameWithRetry` already uses for its own ledger
268
+ // write, mirrored here rather than imported (that function is private to
269
+ // its module) so this fix does not widen its own blast radius by exporting
270
+ // a new cross-module utility.
271
+ const LEDGER_RENAME_RETRY_ERRNOS = new Set(['EPERM', 'EBUSY', 'EACCES']);
272
+ const LEDGER_RENAME_MAX_ATTEMPTS = 5;
273
+ const LEDGER_RENAME_BACKOFF_MS = 25;
274
+ function renameVerificationLedgerWithRetry(tmpPath, finalPath) {
275
+ let lastErr;
276
+ for (let attempt = 0; attempt < LEDGER_RENAME_MAX_ATTEMPTS; attempt++) {
277
+ try {
278
+ node_fs_1.default.renameSync(tmpPath, finalPath);
279
+ return;
280
+ }
281
+ catch (err) {
282
+ lastErr = err;
283
+ const code = (err && typeof err === 'object' && 'code' in err) ? String(err.code) : '';
284
+ if (code && LEDGER_RENAME_RETRY_ERRNOS.has(code) && attempt < LEDGER_RENAME_MAX_ATTEMPTS - 1) {
285
+ // Exponential-ish backoff: 25ms, 50ms, 100ms, 200ms. Transient
286
+ // Windows locks usually clear well inside that window.
287
+ const delay = LEDGER_RENAME_BACKOFF_MS * Math.pow(2, attempt);
288
+ const start = Date.now();
289
+ while (Date.now() - start < delay) {
290
+ // Deliberate short busy-wait — no async/timer seam is available
291
+ // in this synchronous read path.
292
+ }
293
+ continue;
294
+ }
295
+ throw err;
296
+ }
297
+ }
298
+ throw lastErr;
299
+ }
300
+ function writeVerificationLedger(wsDir, ledger) {
301
+ // #2645 review: atomic write. A crash or a concurrent read mid-write
302
+ // against `verificationLedgerPath(wsDir)` directly would leave (or briefly
303
+ // expose) TRUNCATED JSON — and now that `'corrupt'` carries real semantic
304
+ // weight (it fails CLOSED, holding every phase with no live report at
305
+ // `'unrecorded'`), producing a corrupt file ourselves is a self-inflicted
306
+ // version of the exact failure mode this fix exists to survive. Write to a
307
+ // sibling temp file in the SAME directory (same filesystem — `rename` is
308
+ // only atomic within one) and rename into place: a reader can only ever
309
+ // observe the prior complete content or the new complete content.
310
+ const finalPath = verificationLedgerPath(wsDir);
311
+ const tmpPath = `${finalPath}.${process.pid}.tmp`;
312
+ try {
313
+ node_fs_1.default.mkdirSync(wsDir, { recursive: true });
314
+ node_fs_1.default.writeFileSync(tmpPath, `${JSON.stringify(ledger, null, 2)}\n`, 'utf-8');
315
+ renameVerificationLedgerWithRetry(tmpPath, finalPath);
316
+ }
317
+ catch {
318
+ // Best-effort persistence: a missing parent directory that `mkdirSync`
319
+ // itself cannot create, a read-only filesystem, a write failure, or a
320
+ // rename failure that exhausts its retries must not break inventory
321
+ // reads, which are otherwise pure. Losing this observation only
322
+ // re-opens the pre-#2645 window for THIS run; the next successful read
323
+ // while a report is on disk repairs it. Clean up a half-written temp
324
+ // file so repeated failures cannot accumulate orphaned
325
+ // `.verification-ledger.json.<pid>.tmp` files.
326
+ try {
327
+ node_fs_1.default.unlinkSync(tmpPath);
328
+ }
329
+ catch { /* nothing to clean up, or cleanup itself failed — not fatal */ }
330
+ }
331
+ }
332
+ function readStateProjection(statePath) {
333
+ try {
334
+ const stateContent = node_fs_1.default.readFileSync(statePath, 'utf-8');
335
+ // #3187: route Status/Current Phase/Last Activity through the single
336
+ // #1760 fallback-chain owner (state-document.cjs's stateFieldValue)
337
+ // instead of a frontmatter-blind stateExtractField(stateContent, …) call,
338
+ // mirroring cmdStateValidate/cmdStateSnapshot — a STATE.md whose fields
339
+ // live only in frontmatter is no longer projected as absent here.
340
+ const fm = extractFrontmatter(stateContent, statePath);
341
+ const body = stripFrontmatter(stateContent);
342
+ return {
343
+ status: (0, state_document_cjs_1.stateFieldValue)(fm, body, 'status', 'Status').value || 'unknown',
344
+ current_phase: (0, state_document_cjs_1.stateFieldValue)(fm, body, 'current_phase', 'Current Phase').value,
345
+ last_activity: (0, state_document_cjs_1.stateFieldValue)(fm, body, 'last_activity', 'Last Activity').value,
346
+ };
347
+ }
348
+ catch {
349
+ // Read/parse failure (missing file, permission fault, etc.) degrades to
350
+ // an all-unknown projection — unchanged. Not widened to also carry a
351
+ // `scope` here: doing so would ripple `StateProjection`
352
+ // (workstream-inventory-builder.cjs) and every consumer of this
353
+ // read-only rollup — the design doc's blast-radius table rates
354
+ // `readStateProjection` "low"/Tier-2, and this call site's migration is
355
+ // scoped to routing the fallback chain, not to widening the return type.
356
+ // The existing all-unknown degrade already distinguishes "could not
357
+ // read" from any real field value; only its scope-vs-absence *reason*
358
+ // stays uncaptured, same as before this change.
359
+ return {
360
+ status: 'unknown',
361
+ current_phase: null,
362
+ last_activity: null,
363
+ };
364
+ }
365
+ }
366
+ /**
367
+ * #1913 + #2562: detect an authoritative shipped signal for a workstream's
368
+ * CURRENT milestone, so the inventory status is never trusted from the mutable
369
+ * STATE.md `Status` field alone (#1913) yet is never pinned to "milestone
370
+ * complete" by a PRIOR milestone's shipped marker (#2562).
371
+ *
372
+ * When the current milestone version is known, the signal is scoped to it:
373
+ * an archived snapshot `milestones/<version>-ROADMAP.md` (the canonical
374
+ * "milestone shipped" artifact) OR the current milestone's own ROADMAP line
375
+ * marked shipped. When the version cannot be determined, we fall back to the
376
+ * over-broad legacy detection to preserve #1913's protection for those
377
+ * (malformed/legacy) projects.
378
+ *
379
+ * Returns WHICH signal fired, not merely that one did. The two differ in how
380
+ * much they can be trusted and therefore in how the builder cross-validates
381
+ * them against the milestone's own artifacts — see the `shippedContradicted`
382
+ * block in `workstream-inventory-builder.cts`. Collapsing them to a boolean is
383
+ * what forced a single completeness check to serve two incompatible shapes.
384
+ */
385
+ function workstreamShippedSignal(roadmapPath, planningBase, currentVersion) {
386
+ if (!currentVersion) {
387
+ return legacyMilestoneShipped(roadmapPath, planningBase) ? 'legacy' : null;
388
+ }
389
+ // Canonical shipped artifact: the archived ROADMAP snapshot of the CURRENT
390
+ // milestone (`vX.Y-ROADMAP.md`), written at milestone close. REQUIREMENTS
391
+ // snapshots are intentionally NOT accepted — they can be written at milestone
392
+ // START (requirements-locked), so they do not imply shipped.
393
+ const snapshot = node_path_1.default.join(planningBase, 'milestones', `${currentVersion}-ROADMAP.md`);
394
+ if (node_fs_1.default.existsSync(snapshot))
395
+ return 'snapshot';
396
+ return currentMilestoneHeadingShipped(roadmapPath, currentVersion) ? 'heading' : null;
397
+ }
93
398
  function sortWorkstreamInventories(inventories, activeWorkstreamName) {
94
399
  return [...inventories].sort((a, b) => {
95
400
  const aActive = a.name === activeWorkstreamName ? 1 : 0;
@@ -105,13 +410,248 @@ function inspectWorkstream(cwd, name, options = {}) {
105
410
  if (!node_fs_1.default.existsSync(wsDir))
106
411
  return null;
107
412
  const activeWorkstreamName = options.active === undefined ? getActiveWorkstream(cwd) : options.active;
413
+ const writeDiagnostic = options.writeDiagnostic ?? ((message) => process.stderr.write(message));
108
414
  const p = planningPaths(cwd, name);
109
415
  const phaseDirNames = readSubdirectories(p.phases);
110
- // Collect per-phase file counts
111
- const phaseFilesCounts = phaseDirNames.map(dir => {
112
- const counts = countPhaseFiles(node_path_1.default.join(p.phases, dir));
113
- return { directory: dir, planCount: counts.planCount, summaryCount: counts.summaryCount };
416
+ // #2562: scope progress to the CURRENT milestone. Membership and the
417
+ // denominator are derived in ONE key space (`phaseKeyFromDir` /
418
+ // `phaseKeyFromProse`, both from the phase-id owner module) so the two sides
419
+ // of the rollup cannot disagree.
420
+ const currentVersion = readCurrentMilestoneVersion(p.state, p.roadmap);
421
+ const progressRows = parseRoadmapProgressRows(p.roadmap);
422
+ // Phase keys the ROADMAP attributes to the current milestone. A row whose
423
+ // Milestone cell is blank or malformed is INCLUDED rather than dropped: a
424
+ // phase we cannot attribute must still be visible to the rollup. Dropping it
425
+ // from both sides was the silent-deletion defect — it let an unstarted phase
426
+ // vanish and the percentage round to 100. Over-inclusive-never-under is the
427
+ // degrade direction this codebase already commits to for unparseable roadmap
428
+ // input (see the getMilestonePhaseFilter catch in roadmap-parser.cts).
429
+ const currentMilestoneKeys = new Set();
430
+ if (currentVersion) {
431
+ for (const row of progressRows) {
432
+ if (row.version === null || row.version === currentVersion)
433
+ currentMilestoneKeys.add(row.key);
434
+ }
435
+ }
436
+ // Roadmap-heading membership, from the module that OWNS milestone-phase
437
+ // filtering. Consulted only when it is genuinely scoped to a single milestone
438
+ // (`versionScoped`); the unversioned whole-roadmap shape spans the project's
439
+ // lifetime and would re-admit prior-milestone phases — the very defect here.
440
+ const headingFilter = getMilestonePhaseFilter(cwd, currentVersion, null, name);
441
+ const headingScoped = headingFilter.versionScoped && headingFilter.phaseCount > 0;
442
+ // Phase keys the ROADMAP attributes to some OTHER milestone. A row carrying an
443
+ // explicit version that is not the current one is a positive claim by a prior
444
+ // (or future) milestone — the only reliable evidence that a phase does NOT
445
+ // belong to the current one.
446
+ const claimedElsewhere = new Set();
447
+ for (const row of progressRows) {
448
+ if (row.version !== null && row.version !== currentVersion)
449
+ claimedElsewhere.add(row.key);
450
+ }
451
+ // #2562: the current milestone is DECLARED but nothing attributes a phase to
452
+ // it yet — the window right after `/gsd-new-milestone`, where STATE.md's
453
+ // `milestone:` field updates the moment the heading lands but the Progress
454
+ // table and phase sections have not caught up.
455
+ //
456
+ // Treating that as "unscoped" was a hole in the original fix: scoping switched
457
+ // off entirely and the fallback below counted the project's ENTIRE phase
458
+ // history as both numerator and denominator, so a workstream whose current
459
+ // milestone had zero phases done reported 100% off its predecessors' work.
460
+ // That is the very symptom #2562 reports, reached by a different route.
461
+ //
462
+ // Three independent signals witness it; ANY of them is enough, and each covers
463
+ // a ROADMAP shape the others miss:
464
+ // - `versionSectionFound` — the milestone's own section exists but declares
465
+ // no phases (heading-only ROADMAPs, and the common `## v3.0` stub).
466
+ // - `missingExplicitVersion` — the ROADMAP versions its milestones but has
467
+ // no section for this one at all.
468
+ // - a Progress table that attributes every row elsewhere (`claimedElsewhere`
469
+ // non-empty while `currentMilestoneKeys` is empty).
470
+ // A ROADMAP that attributes NO versions anywhere matches none of them: its
471
+ // rows parse with `version: null`, land in `currentMilestoneKeys`, and never
472
+ // reach here. That is deliberate — for a free-form legacy project the
473
+ // whole-roadmap count IS the current milestone, and `readCurrentMilestoneVersion`
474
+ // hands back a non-null version for almost every project, so keying off
475
+ // `currentVersion` alone would regress every one of them to 0%.
476
+ const currentMilestoneDeclaredEmpty = currentVersion !== null &&
477
+ currentMilestoneKeys.size === 0 &&
478
+ !headingScoped &&
479
+ (headingFilter.versionSectionFound || headingFilter.missingExplicitVersion || claimedElsewhere.size > 0);
480
+ // A dir-only phase joins the current milestone when the roadmap names it, or
481
+ // when it is a sub-phase (`30.1-…`) of a phase the roadmap names — sub-phases
482
+ // inserted mid-milestone rarely get a row of their own. Membership feeds BOTH
483
+ // the numerator and (via `milestoneKeys` below) the denominator, so a member
484
+ // can never exceed the denominator that counts it.
485
+ const scoped = currentMilestoneKeys.size > 0 || headingScoped || currentMilestoneDeclaredEmpty;
486
+ const isDirInCurrentMilestone = (dir) => {
487
+ if (!scoped)
488
+ return true;
489
+ const key = phaseKeyFromDir(dir);
490
+ if (currentMilestoneKeys.has(key))
491
+ return true;
492
+ const parent = parentPhaseKey(key);
493
+ if (parent !== null && currentMilestoneKeys.has(parent))
494
+ return true;
495
+ // An empty current milestone has no roadmap declarations to match against,
496
+ // so membership inverts: a directory belongs UNLESS another milestone claims
497
+ // it. A phase scaffolded before the roadmap caught up would otherwise vanish
498
+ // from both sides of the rollup — under-reporting, the direction this
499
+ // codebase never degrades in.
500
+ if (currentMilestoneDeclaredEmpty) {
501
+ const parentKey = parentPhaseKey(key);
502
+ return !claimedElsewhere.has(key) && (parentKey === null || !claimedElsewhere.has(parentKey));
503
+ }
504
+ return headingScoped && headingFilter(dir);
505
+ };
506
+ // Collect per-phase file counts (+ canonical key, milestone membership,
507
+ // verification verdict). `phaseKey` lets the builder de-duplicate stale
508
+ // same-numbered directories (Bug #2445's scenario) in the rollup.
509
+ //
510
+ // #2645 review: built from `[...phaseDirNames].sort()`, NOT the raw
511
+ // `phaseDirNames` (unsorted `readdirSync` order — `readSubdirectories`'s
512
+ // default). `buildWorkstreamInventory`'s own de-dup (`rollupDirByKey`,
513
+ // workstream-inventory-builder.cts) iterates the SAME sorted order; the
514
+ // ledger-winner tie-break below (incumbent wins unless a later entry has a
515
+ // STRICTLY newer mtime) only agrees with the builder's winner on an exact
516
+ // mtime tie if both walk entries in the same order. Iterating unsorted
517
+ // input here let the two independently pick different "winning"
518
+ // directories for one phase key on a tie — reopening the stale-duplicate-
519
+ // clobbers-live-verdict hole criterion 4 exists to close.
520
+ const rawPhaseEntries = [...phaseDirNames].sort().map(dir => {
521
+ const phaseDir = node_path_1.default.join(p.phases, dir);
522
+ const counts = countPhaseFiles(phaseDir);
523
+ // ADR-3180 §7.4 (#3186): routed through the single canonical owner
524
+ // (`isPhaseComplete`, src/verification.cts) instead of calling
525
+ // `readVerificationStatus` directly and re-deriving "is this phase
526
+ // complete" locally from its `.status`. `completionResult.value.complete`
527
+ // is threaded down to the builder below (as `PhaseFilesCount.complete`)
528
+ // so `buildWorkstreamInventory` — a pure, I/O-free projection that
529
+ // cannot call the owner itself — consumes the owner's verdict rather
530
+ // than re-deriving a second one from summary/plan counts.
531
+ const completionResult = isPhaseComplete(phaseDir);
532
+ const verificationResult = completionResult.value.verification;
533
+ // #3057 B3: routing is UNCHANGED — `liveVerificationStatus` below is still
534
+ // `.status`, exactly as before, so the ledger/rollup logic that consumes
535
+ // it is unaffected. This only makes an indeterminate staleness check
536
+ // visible (stderr), matching cmdGitBaseBranch's own non-blocking
537
+ // unverified-fallback diagnostic (#3057 B4) — the closest existing idiom,
538
+ // since `WorkstreamInventory`'s aggregate return shape carries no
539
+ // per-phase verification detail for this to attach to.
540
+ if (verificationResult.staleCheckIndeterminate) {
541
+ writeDiagnostic(`⚠ workstream-inventory: verification staleness check could not complete for phase directory '${dir}' in workstream '${name}' — routed as not-stale, but this was not actually verified. See #3057.\n`, { phaseDir: dir, reason: 'staleCheckIndeterminate' });
542
+ }
543
+ return {
544
+ directory: dir,
545
+ phaseKey: phaseKeyFromDir(dir),
546
+ mtimeMs: phaseDirMtime(phaseDir),
547
+ planCount: counts.planCount,
548
+ summaryCount: counts.summaryCount,
549
+ inMilestone: isDirInCurrentMilestone(dir),
550
+ liveVerificationStatus: verificationResult.status,
551
+ // ADR-3180 §7.4 (#3186): the owner's verdict, read live off disk — never
552
+ // ledger-adjusted (see the phaseFilesCounts map below; the ledger only
553
+ // ever substitutes a 'missing' status with a remembered one, and under
554
+ // disk-strict neither 'missing' nor 'unrecorded' is ever complete, so
555
+ // there is nothing for the ledger to override here).
556
+ complete: completionResult.value.complete,
557
+ };
114
558
  });
559
+ // #2645: only the directory Bug #2445's de-dup rollup would actually pick
560
+ // for a phase key may read or write that key's ledger entry. Letting every
561
+ // same-keyed directory (including a stale leftover) write would let a
562
+ // stale duplicate's stale verdict clobber the live directory's remembered
563
+ // one.
564
+ //
565
+ // #2645 review — CORRECTED: an earlier version of this comment claimed the
566
+ // milestone-scoping exclusion (`scoped && entry.inMilestone === false`)
567
+ // was safe to drop here as "out of scope", and hand-wrote a scoping-free
568
+ // tie-break rule. That was a real bug, not a scope call: in a SCOPED
569
+ // workstream, a stale OUT-of-milestone directory sharing a phase key with
570
+ // the live IN-milestone one can have a newer mtime (plausible after a
571
+ // checkout/rebase resets mtimes) and would then win THIS selection while
572
+ // the builder's own `rollupDirByKey` — which DOES apply the scoping filter
573
+ // — picks the live directory instead. `isLedgerWinner` would then be false
574
+ // for the live directory, so deleting ITS `*-VERIFICATION.md` would never
575
+ // consult the ledger and would reopen #2645's exact hole for the phase
576
+ // that actually counts toward `completed_phases` — reachable with a plain
577
+ // `rm`, no ledger tampering required. Fixed by calling the SAME shared
578
+ // `pickRollupWinners` the builder's `rollupDirByKey` now also calls, with
579
+ // the identical scoping filter, rather than a second hand-written copy.
580
+ const ledgerWinnerByKey = (0, workstream_inventory_builder_cjs_1.pickRollupWinners)(rawPhaseEntries, (entry) => entry.phaseKey, (entry) => entry.mtimeMs, (entry) => !(scoped && entry.inMilestone === false));
581
+ const ledgerRead = readVerificationLedger(wsDir);
582
+ // Both `'corrupt'` and `'ok'` start from whatever entries could actually be
583
+ // trusted (empty for `'corrupt'` — nothing in an unparseable file is
584
+ // trusted) and get REPAIRED below by any real verdict this call observes;
585
+ // only `'absent'` skips the ledger mechanism entirely (pre-adoption).
586
+ const verificationLedger = ledgerRead.entries;
587
+ let ledgerDirty = false;
588
+ for (const winner of ledgerWinnerByKey.values()) {
589
+ if (winner.liveVerificationStatus === 'missing')
590
+ continue;
591
+ if (verificationLedger[winner.phaseKey] !== winner.liveVerificationStatus) {
592
+ verificationLedger[winner.phaseKey] = winner.liveVerificationStatus;
593
+ ledgerDirty = true;
594
+ }
595
+ }
596
+ // A `'corrupt'` read that observes no real verdict this call has nothing to
597
+ // repair with — writing an empty `{}` would DESTROY whatever the corrupt
598
+ // file's bytes might still hold (a human could recover it by hand; this
599
+ // fix must not foreclose that). Only write when there is something real to
600
+ // persist, exactly as for `'absent'`/`'ok'`.
601
+ if (ledgerDirty)
602
+ writeVerificationLedger(wsDir, verificationLedger);
603
+ const phaseFilesCounts = rawPhaseEntries.map(entry => {
604
+ const isLedgerWinner = ledgerWinnerByKey.get(entry.phaseKey) === entry;
605
+ let verificationStatus = entry.liveVerificationStatus;
606
+ if (entry.liveVerificationStatus === 'missing' && isLedgerWinner) {
607
+ if (ledgerRead.state === 'absent') {
608
+ // State 1: pre-adoption. Exactly today's behavior — 'missing' is
609
+ // NOT in FAILING_VERIFICATION_STATUSES, so this does not gate.
610
+ verificationStatus = 'missing';
611
+ }
612
+ else {
613
+ // States 2/3 ('corrupt' or 'ok'): this workstream has adopted the
614
+ // ledger. A remembered entry wins; no entry fails CLOSED to the
615
+ // 'unrecorded' sentinel rather than falling open to 'missing'.
616
+ const remembered = verificationLedger[entry.phaseKey];
617
+ verificationStatus = remembered !== undefined ? remembered : 'unrecorded';
618
+ }
619
+ }
620
+ return {
621
+ directory: entry.directory,
622
+ phaseKey: entry.phaseKey,
623
+ mtimeMs: entry.mtimeMs,
624
+ planCount: entry.planCount,
625
+ summaryCount: entry.summaryCount,
626
+ inMilestone: entry.inMilestone,
627
+ verificationStatus,
628
+ complete: entry.complete,
629
+ };
630
+ });
631
+ // The denominator is the union of what the roadmap DECLARES for the current
632
+ // milestone (including never-scaffolded phases) and the keys of the member
633
+ // directories (including dir-only sub-phases). One key space, so
634
+ // `completed_phases <= denominator` holds by construction rather than by a
635
+ // `Math.min` cap that hid the inconsistency.
636
+ const milestoneKeys = new Set(currentMilestoneKeys);
637
+ for (const entry of phaseFilesCounts) {
638
+ if (entry.inMilestone)
639
+ milestoneKeys.add(entry.phaseKey);
640
+ }
641
+ const currentMilestonePhaseCount = scoped
642
+ ? Math.max(milestoneKeys.size, headingScoped ? headingFilter.phaseCount : 0)
643
+ : 0;
644
+ // Unscoped fallback: the denominator must STILL count phases the ROADMAP
645
+ // declares in its Progress table but never scaffolded — the heading-only
646
+ // count drops them, even when other headings exist. Union the declared rows
647
+ // with the phase directories so neither source can silently shrink it.
648
+ let fallbackPhaseCount = countRoadmapPhases(p.roadmap, phaseDirNames.length, cwd, name, currentVersion);
649
+ if (!scoped && progressRows.length > 0) {
650
+ const union = new Set(progressRows.map(row => row.key));
651
+ for (const entry of phaseFilesCounts)
652
+ union.add(entry.phaseKey);
653
+ fallbackPhaseCount = union.size;
654
+ }
115
655
  return (0, workstream_inventory_builder_cjs_1.buildWorkstreamInventory)({
116
656
  name,
117
657
  projectDir: cwd,
@@ -119,14 +659,19 @@ function inspectWorkstream(cwd, name, options = {}) {
119
659
  phaseDirNames,
120
660
  activeWorkstreamName: activeWorkstreamName ?? '',
121
661
  phaseFilesCounts,
122
- roadmapPhaseCount: countRoadmapPhases(p.roadmap, phaseDirNames.length),
662
+ roadmapPhaseCount: fallbackPhaseCount,
663
+ currentMilestonePhaseCount,
664
+ // Stated, not inferred from the count: a declared-but-empty current
665
+ // milestone is legitimately scoped AND legitimately zero-phase, and the
666
+ // builder cannot tell those apart from `currentMilestonePhaseCount` alone.
667
+ milestoneScoped: scoped,
123
668
  stateProjection: readStateProjection(p.state),
124
669
  filesExist: {
125
670
  roadmap: node_fs_1.default.existsSync(p.roadmap),
126
671
  state: node_fs_1.default.existsSync(p.state),
127
672
  requirements: node_fs_1.default.existsSync(p.requirements),
128
673
  },
129
- milestoneShipped: workstreamMilestoneShipped(p.roadmap, p.planning),
674
+ milestoneShippedSignal: workstreamShippedSignal(p.roadmap, p.planning, currentVersion),
130
675
  });
131
676
  }
132
677
  function listWorkstreamInventories(cwd) {