@opengsd/gsd-core 1.11.0 → 1.12.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 (395) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/agents/gsd-code-fixer.md +1 -1
  4. package/agents/gsd-debug-session-manager.md +1 -1
  5. package/agents/gsd-debugger.md +1 -1
  6. package/agents/gsd-dom-verifier.md +169 -0
  7. package/agents/gsd-eval-auditor.md +1 -1
  8. package/agents/gsd-executor.md +17 -9
  9. package/agents/gsd-framework-selector.md +1 -3
  10. package/agents/gsd-intel-updater.md +1 -1
  11. package/agents/gsd-mempalace-curator.md +0 -1
  12. package/agents/gsd-pattern-mapper.md +11 -0
  13. package/agents/gsd-phase-researcher.md +3 -1
  14. package/agents/gsd-plan-checker.md +15 -55
  15. package/agents/gsd-planner.md +6 -4
  16. package/agents/gsd-project-researcher.md +1 -1
  17. package/agents/gsd-research-synthesizer.md +2 -2
  18. package/agents/gsd-roadmapper.md +15 -11
  19. package/agents/gsd-ui-checker.md +63 -4
  20. package/agents/gsd-ui-researcher.md +41 -3
  21. package/agents/gsd-verifier.md +1 -1
  22. package/bin/install.js +609 -134
  23. package/commands/gsd/discuss-phase.md +1 -1
  24. package/commands/gsd/import.md +1 -1
  25. package/commands/gsd/quick.md +8 -4
  26. package/gsd-core/bin/gsd-tools.cjs +567 -51
  27. package/gsd-core/bin/lib/active-workstream-store.cjs +8 -0
  28. package/gsd-core/bin/lib/adr-parser.cjs +13 -7
  29. package/gsd-core/bin/lib/agent-install-check.cjs +162 -0
  30. package/gsd-core/bin/lib/api-coverage.cjs +30 -9
  31. package/gsd-core/bin/lib/artifacts.cjs +2 -0
  32. package/gsd-core/bin/lib/assumption-delta.cjs +30 -11
  33. package/gsd-core/bin/lib/audit.cjs +163 -41
  34. package/gsd-core/bin/lib/broken-windows.cjs +306 -28
  35. package/gsd-core/bin/lib/capability-lock.cjs +10 -4
  36. package/gsd-core/bin/lib/capability-registry.cjs +336 -95
  37. package/gsd-core/bin/lib/capability-state.cjs +18 -3
  38. package/gsd-core/bin/lib/capability-validator.cjs +205 -18
  39. package/gsd-core/bin/lib/check-command-router.cjs +145 -5
  40. package/gsd-core/bin/lib/cli-exit.cjs +496 -10
  41. package/gsd-core/bin/lib/code-review-depth.cjs +288 -0
  42. package/gsd-core/bin/lib/codex-agent-toml.cjs +410 -4
  43. package/gsd-core/bin/lib/command-arg-projection.cjs +144 -14
  44. package/gsd-core/bin/lib/command-routing-hub.cjs +31 -2
  45. package/gsd-core/bin/lib/commands.cjs +543 -44
  46. package/gsd-core/bin/lib/complexity-trigger.cjs +26 -6
  47. package/gsd-core/bin/lib/config-loader.cjs +118 -29
  48. package/gsd-core/bin/lib/config.cjs +92 -2
  49. package/gsd-core/bin/lib/configuration.cjs +129 -37
  50. package/gsd-core/bin/lib/core-utils.cjs +84 -7
  51. package/gsd-core/bin/lib/edge-probe.cjs +9 -1
  52. package/gsd-core/bin/lib/estimate-cli.cjs +55 -11
  53. package/gsd-core/bin/lib/exit-code-registry.cjs +98 -0
  54. package/gsd-core/bin/lib/frontmatter.cjs +840 -305
  55. package/gsd-core/bin/lib/gap-checker.cjs +27 -3
  56. package/gsd-core/bin/lib/git-base-branch.cjs +174 -39
  57. package/gsd-core/bin/lib/health-diagnostic-rules/consistency.cjs +7 -3
  58. package/gsd-core/bin/lib/health-diagnostic-rules/roadmap-disk-consistency.cjs +6 -3
  59. package/gsd-core/bin/lib/health-diagnostic-rules/worktree-health.cjs +22 -8
  60. package/gsd-core/bin/lib/health-diagnostic.cjs +23 -3
  61. package/gsd-core/bin/lib/host-integration.cjs +39 -6
  62. package/gsd-core/bin/lib/init-command-router.cjs +118 -21
  63. package/gsd-core/bin/lib/init.cjs +120 -41
  64. package/gsd-core/bin/lib/install-engine.cjs +68 -3
  65. package/gsd-core/bin/lib/install-model-override-resolver.cjs +33 -1
  66. package/gsd-core/bin/lib/install-profiles.cjs +78 -4
  67. package/gsd-core/bin/lib/installer-migration-report.cjs +3 -0
  68. package/gsd-core/bin/lib/installer-migrations/010-antigravity-retire-confighome-artifacts.cjs +169 -0
  69. package/gsd-core/bin/lib/installer-migrations.cjs +10 -7
  70. package/gsd-core/bin/lib/intel.cjs +101 -26
  71. package/gsd-core/bin/lib/io.cjs +160 -15
  72. package/gsd-core/bin/lib/learnings.cjs +85 -14
  73. package/gsd-core/bin/lib/legacy-cleanup.cjs +8 -2
  74. package/gsd-core/bin/lib/markdown-table.cjs +52 -4
  75. package/gsd-core/bin/lib/milestone.cjs +90 -5
  76. package/gsd-core/bin/lib/model-catalog.cjs +177 -19
  77. package/gsd-core/bin/lib/model-resolver.cjs +10 -28
  78. package/gsd-core/bin/lib/onboard-projection.cjs +5 -1
  79. package/gsd-core/bin/lib/phase-estimation.cjs +17 -8
  80. package/gsd-core/bin/lib/phase-id.cjs +70 -4
  81. package/gsd-core/bin/lib/phase-lifecycle.cjs +24 -16
  82. package/gsd-core/bin/lib/phase-locator.cjs +138 -17
  83. package/gsd-core/bin/lib/phase.cjs +405 -84
  84. package/gsd-core/bin/lib/plan-document.cjs +263 -0
  85. package/gsd-core/bin/lib/plan-scan.cjs +13 -2
  86. package/gsd-core/bin/lib/planning-command-router.cjs +61 -0
  87. package/gsd-core/bin/lib/planning-inspect.cjs +1168 -0
  88. package/gsd-core/bin/lib/planning-snapshot.cjs +18 -14
  89. package/gsd-core/bin/lib/planning-workspace.cjs +56 -0
  90. package/gsd-core/bin/lib/probe-core.cjs +4 -1
  91. package/gsd-core/bin/lib/profile-pipeline-command-router.cjs +50 -7
  92. package/gsd-core/bin/lib/profile-pipeline.cjs +6 -3
  93. package/gsd-core/bin/lib/real-home-guard.cjs +419 -0
  94. package/gsd-core/bin/lib/refactor-trigger-command-router.cjs +71 -45
  95. package/gsd-core/bin/lib/review-lane-descriptor.cjs +9 -9
  96. package/gsd-core/bin/lib/roadmap-command-router.cjs +45 -31
  97. package/gsd-core/bin/lib/roadmap-parser.cjs +79 -16
  98. package/gsd-core/bin/lib/roadmap.cjs +74 -19
  99. package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +96 -8
  100. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +34 -1
  101. package/gsd-core/bin/lib/runtime-hooks-surface.cjs +287 -55
  102. package/gsd-core/bin/lib/runtime-identity.cjs +234 -0
  103. package/gsd-core/bin/lib/runtime-slash.cjs +72 -2
  104. package/gsd-core/bin/lib/shell-command-projection.cjs +71 -8
  105. package/gsd-core/bin/lib/smart-entry.cjs +12 -22
  106. package/gsd-core/bin/lib/spec-section.cjs +12 -7
  107. package/gsd-core/bin/lib/state-command-router.cjs +47 -18
  108. package/gsd-core/bin/lib/state-contract.cjs +359 -0
  109. package/gsd-core/bin/lib/state-document.cjs +186 -0
  110. package/gsd-core/bin/lib/state-md-schema.cjs +221 -0
  111. package/gsd-core/bin/lib/state-transition.cjs +517 -101
  112. package/gsd-core/bin/lib/state.cjs +946 -163
  113. package/gsd-core/bin/lib/surface.cjs +10 -2
  114. package/gsd-core/bin/lib/task-command-router.cjs +111 -1
  115. package/gsd-core/bin/lib/task-content-resolution.cjs +368 -0
  116. package/gsd-core/bin/lib/teams-status.cjs +4 -1
  117. package/gsd-core/bin/lib/uat-predicate.cjs +58 -20
  118. package/gsd-core/bin/lib/uat.cjs +1376 -125
  119. package/gsd-core/bin/lib/ui-consideration-probe.cjs +9 -1
  120. package/gsd-core/bin/lib/ui-safety-gate.cjs +37 -7
  121. package/gsd-core/bin/lib/unusable-input.cjs +13 -0
  122. package/gsd-core/bin/lib/validate-command-router.cjs +2 -2
  123. package/gsd-core/bin/lib/vendor/README.md +43 -5
  124. package/gsd-core/bin/lib/vendor/js-yaml.cjs +3014 -0
  125. package/gsd-core/bin/lib/verification.cjs +14 -1
  126. package/gsd-core/bin/lib/verify-command-grounding.cjs +846 -0
  127. package/gsd-core/bin/lib/verify.cjs +95 -40
  128. package/gsd-core/bin/lib/workstream-name-policy.cjs +25 -4
  129. package/gsd-core/bin/lib/worktree-base-ref.cjs +66 -12
  130. package/gsd-core/bin/lib/worktree-safety.cjs +177 -21
  131. package/gsd-core/bin/shared/config-defaults.manifest.json +7 -1
  132. package/gsd-core/bin/shared/config-schema.manifest.json +5 -0
  133. package/gsd-core/bin/shared/exit-codes.json +8 -0
  134. package/gsd-core/bin/shared/exit-codes.sh +20 -0
  135. package/gsd-core/bin/shared/model-catalog.json +8 -1
  136. package/gsd-core/references/agent-contracts.md +3 -2
  137. package/gsd-core/references/api-coverage.md +24 -2
  138. package/gsd-core/references/autonomous-smart-discuss.md +3 -3
  139. package/gsd-core/references/checkpoints.md +37 -19
  140. package/gsd-core/references/decimal-phase-calculation.md +5 -5
  141. package/gsd-core/references/edge-probe.md +8 -0
  142. package/gsd-core/references/execute-mvp-tdd.md +1 -3
  143. package/gsd-core/references/execute-phase-between-wave-reset.md +9 -12
  144. package/gsd-core/references/execute-phase-wave-guard.md +11 -9
  145. package/gsd-core/references/failing-direction.md +78 -0
  146. package/gsd-core/references/gate-prompts.md +1 -1
  147. package/gsd-core/references/git-integration.md +5 -5
  148. package/gsd-core/references/git-planning-commit.md +3 -3
  149. package/gsd-core/references/gsd-run-resolver.md +1 -1
  150. package/gsd-core/references/loop-hook-dispatch.md +22 -0
  151. package/gsd-core/references/model-profiles.md +1 -1
  152. package/gsd-core/references/nyquist-compliance.md +74 -0
  153. package/gsd-core/references/offer-next.md +3 -5
  154. package/gsd-core/references/phase-argument-parsing.md +3 -3
  155. package/gsd-core/references/planner-failing-direction.md +53 -0
  156. package/gsd-core/references/planner-human-verify-mode.md +15 -1
  157. package/gsd-core/references/planner-revision.md +1 -1
  158. package/gsd-core/references/planner-verify-command-grounding.md +17 -0
  159. package/gsd-core/references/planning-config.md +37 -8
  160. package/gsd-core/references/reviewer-instances.md +31 -0
  161. package/gsd-core/references/runtime-aware-dispatch.md +1 -1
  162. package/gsd-core/references/tdd.md +1 -3
  163. package/gsd-core/references/ui-brand.md +65 -21
  164. package/gsd-core/references/ui-consideration-probe.md +1 -1
  165. package/gsd-core/references/universal-anti-patterns.md +2 -2
  166. package/gsd-core/references/verify-command-path-resolvability.md +42 -0
  167. package/gsd-core/references/verify-mvp-mode.md +1 -1
  168. package/gsd-core/references/workstream-flag.md +11 -11
  169. package/gsd-core/templates/README.md +1 -1
  170. package/gsd-core/templates/SECURITY.md +3 -3
  171. package/gsd-core/templates/UI-SPEC.md +25 -3
  172. package/gsd-core/templates/VALIDATION.md +3 -3
  173. package/gsd-core/templates/phase-prompt.md +3 -0
  174. package/gsd-core/templates/state.md +7 -0
  175. package/gsd-core/workflows/_runtime-launcher.snippet.sh +1 -1
  176. package/gsd-core/workflows/add-backlog.md +1 -1
  177. package/gsd-core/workflows/add-phase.md +3 -3
  178. package/gsd-core/workflows/add-tests.md +3 -8
  179. package/gsd-core/workflows/add-todo.md +1 -1
  180. package/gsd-core/workflows/ai-integration-phase.md +4 -9
  181. package/gsd-core/workflows/audit-fix.md +12 -3
  182. package/gsd-core/workflows/audit-milestone.md +9 -9
  183. package/gsd-core/workflows/audit-uat.md +17 -2
  184. package/gsd-core/workflows/autonomous/steps/converge-fail-fast.md +2 -2
  185. package/gsd-core/workflows/autonomous.md +10 -26
  186. package/gsd-core/workflows/check-todos.md +1 -1
  187. package/gsd-core/workflows/cleanup.md +2 -2
  188. package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +1 -1
  189. package/gsd-core/workflows/code-review-fix.md +1 -1
  190. package/gsd-core/workflows/code-review.md +121 -40
  191. package/gsd-core/workflows/complete-milestone.md +15 -10
  192. package/gsd-core/workflows/debug.md +5 -3
  193. package/gsd-core/workflows/diagnose-issues.md +12 -6
  194. package/gsd-core/workflows/discuss-phase/modes/advisor.md +1 -1
  195. package/gsd-core/workflows/discuss-phase/modes/chain.md +3 -7
  196. package/gsd-core/workflows/discuss-phase/modes/text.md +1 -1
  197. package/gsd-core/workflows/discuss-phase-assumptions/steps/auto-advance-dispatch.md +1 -3
  198. package/gsd-core/workflows/discuss-phase-assumptions.md +2 -2
  199. package/gsd-core/workflows/discuss-phase.md +1 -1
  200. package/gsd-core/workflows/do.md +3 -6
  201. package/gsd-core/workflows/docs-update.md +5 -4
  202. package/gsd-core/workflows/edit-phase.md +1 -1
  203. package/gsd-core/workflows/eval-review.md +4 -9
  204. package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +1 -1
  205. package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +113 -11
  206. package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +1 -1
  207. package/gsd-core/workflows/execute-phase/steps/partial-wave.md +1 -1
  208. package/gsd-core/workflows/execute-phase/steps/per-plan-executor-routing.md +1 -1
  209. package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +22 -4
  210. package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +2 -2
  211. package/gsd-core/workflows/execute-phase/steps/protected-branch.md +21 -0
  212. package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +2 -2
  213. package/gsd-core/workflows/execute-phase/steps/wave-post-gate-hooks.md +39 -0
  214. package/gsd-core/workflows/execute-phase.md +38 -54
  215. package/gsd-core/workflows/execute-plan.md +17 -12
  216. package/gsd-core/workflows/explore.md +1 -1
  217. package/gsd-core/workflows/extract-learnings.md +1 -1
  218. package/gsd-core/workflows/fast.md +2 -2
  219. package/gsd-core/workflows/forensics.md +1 -1
  220. package/gsd-core/workflows/graduation.md +5 -5
  221. package/gsd-core/workflows/health.md +3 -6
  222. package/gsd-core/workflows/import.md +14 -11
  223. package/gsd-core/workflows/inbox.md +4 -5
  224. package/gsd-core/workflows/ingest-docs.md +44 -11
  225. package/gsd-core/workflows/insert-phase.md +5 -5
  226. package/gsd-core/workflows/list-seeds.md +5 -3
  227. package/gsd-core/workflows/list-workspaces.md +1 -1
  228. package/gsd-core/workflows/manager.md +12 -23
  229. package/gsd-core/workflows/map-codebase.md +1 -1
  230. package/gsd-core/workflows/milestone-summary.md +1 -1
  231. package/gsd-core/workflows/mvp-phase.md +2 -2
  232. package/gsd-core/workflows/new-milestone.md +9 -21
  233. package/gsd-core/workflows/new-project/steps/auto-mode-config.md +1 -1
  234. package/gsd-core/workflows/new-project.md +12 -26
  235. package/gsd-core/workflows/new-workspace.md +1 -1
  236. package/gsd-core/workflows/next.md +2 -2
  237. package/gsd-core/workflows/pause-work.md +1 -1
  238. package/gsd-core/workflows/plan-phase/steps/adr-ingest-express-path.md +1 -1
  239. package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +1 -1
  240. package/gsd-core/workflows/plan-phase/steps/prd-express-path.md +2 -4
  241. package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +3 -3
  242. package/gsd-core/workflows/plan-phase.md +121 -42
  243. package/gsd-core/workflows/plan-review-convergence.md +46 -9
  244. package/gsd-core/workflows/plant-seed.md +2 -2
  245. package/gsd-core/workflows/pr-branch.md +187 -51
  246. package/gsd-core/workflows/profile-user.md +16 -14
  247. package/gsd-core/workflows/progress.md +27 -12
  248. package/gsd-core/workflows/quick/steps/discussion-phase.md +1 -3
  249. package/gsd-core/workflows/quick/steps/plan-checker-loop.md +1 -3
  250. package/gsd-core/workflows/quick/steps/quick-verification.md +2 -4
  251. package/gsd-core/workflows/quick/steps/research-phase.md +2 -4
  252. package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +3 -3
  253. package/gsd-core/workflows/quick.md +20 -29
  254. package/gsd-core/workflows/remove-phase.md +4 -4
  255. package/gsd-core/workflows/remove-workspace.md +2 -2
  256. package/gsd-core/workflows/resume-project.md +8 -12
  257. package/gsd-core/workflows/review.md +193 -15
  258. package/gsd-core/workflows/scan.md +1 -1
  259. package/gsd-core/workflows/secure-phase.md +2 -2
  260. package/gsd-core/workflows/settings-advanced.md +7 -9
  261. package/gsd-core/workflows/settings-integrations.md +64 -31
  262. package/gsd-core/workflows/settings.md +3 -5
  263. package/gsd-core/workflows/ship.md +12 -6
  264. package/gsd-core/workflows/sketch-wrap-up.md +11 -17
  265. package/gsd-core/workflows/sketch.md +12 -18
  266. package/gsd-core/workflows/smart-entry.md +3 -5
  267. package/gsd-core/workflows/spec-phase.md +23 -1
  268. package/gsd-core/workflows/spike-wrap-up.md +7 -11
  269. package/gsd-core/workflows/spike.md +20 -31
  270. package/gsd-core/workflows/stats.md +2 -2
  271. package/gsd-core/workflows/sync-skills.md +1 -1
  272. package/gsd-core/workflows/thread.md +11 -7
  273. package/gsd-core/workflows/transition.md +5 -5
  274. package/gsd-core/workflows/ui-phase.md +10 -16
  275. package/gsd-core/workflows/ui-review.md +6 -10
  276. package/gsd-core/workflows/ultraplan-phase.md +5 -13
  277. package/gsd-core/workflows/undo.md +8 -16
  278. package/gsd-core/workflows/update.md +6 -10
  279. package/gsd-core/workflows/validate-phase.md +2 -2
  280. package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +25 -1
  281. package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +1 -1
  282. package/gsd-core/workflows/verify-work.md +57 -18
  283. package/hooks/dist/gsd-agent-isolation-guard.js +77 -38
  284. package/hooks/dist/gsd-config-reload.js +18 -12
  285. package/hooks/dist/gsd-context-monitor.js +19 -10
  286. package/hooks/dist/gsd-cursor-post-tool.js +3 -1
  287. package/hooks/dist/gsd-cursor-pre-tool.js +3 -1
  288. package/hooks/dist/gsd-cursor-session-start.js +2 -1
  289. package/hooks/dist/gsd-cursor-stop.js +2 -1
  290. package/hooks/dist/gsd-cursor-subagent-start.js +28 -23
  291. package/hooks/dist/gsd-cursor-subagent-stop.js +3 -1
  292. package/hooks/dist/gsd-ensure-canonical-path.js +2 -1
  293. package/hooks/dist/gsd-graphify-update.sh +22 -18
  294. package/hooks/dist/gsd-node-runner.sh +76 -0
  295. package/hooks/dist/gsd-phase-boundary.sh +1 -0
  296. package/hooks/dist/gsd-prompt-guard.js +16 -7
  297. package/hooks/dist/gsd-read-guard.js +16 -7
  298. package/hooks/dist/gsd-read-injection-scanner.js +17 -8
  299. package/hooks/dist/gsd-session-state.sh +1 -0
  300. package/hooks/dist/gsd-statusline.js +215 -26
  301. package/hooks/dist/gsd-validate-commit.sh +80 -6
  302. package/hooks/dist/gsd-windsurf-pre-command.js +16 -11
  303. package/hooks/dist/gsd-windsurf-pre-write.js +22 -13
  304. package/hooks/dist/gsd-workflow-guard.js +34 -16
  305. package/hooks/dist/gsd-worktree-path-guard.js +36 -21
  306. package/hooks/dist/gsd-write-guard.js +35 -25
  307. package/hooks/dist/lib/cli-exit.js +560 -0
  308. package/hooks/dist/lib/exit-code-registry.js +98 -0
  309. package/hooks/dist/lib/git-probe.js +84 -0
  310. package/hooks/dist/lib/hook-exit.js +81 -0
  311. package/hooks/dist/managed-hooks-registry.cjs +3 -0
  312. package/hooks/gsd-agent-isolation-guard.js +77 -38
  313. package/hooks/gsd-config-reload.js +18 -12
  314. package/hooks/gsd-context-monitor.js +19 -10
  315. package/hooks/gsd-cursor-post-tool.js +3 -1
  316. package/hooks/gsd-cursor-pre-tool.js +3 -1
  317. package/hooks/gsd-cursor-session-start.js +2 -1
  318. package/hooks/gsd-cursor-stop.js +2 -1
  319. package/hooks/gsd-cursor-subagent-start.js +28 -23
  320. package/hooks/gsd-cursor-subagent-stop.js +3 -1
  321. package/hooks/gsd-ensure-canonical-path.js +2 -1
  322. package/hooks/gsd-graphify-update.sh +22 -18
  323. package/hooks/gsd-node-runner.sh +76 -0
  324. package/hooks/gsd-phase-boundary.sh +1 -0
  325. package/hooks/gsd-prompt-guard.js +16 -7
  326. package/hooks/gsd-read-guard.js +16 -7
  327. package/hooks/gsd-read-injection-scanner.js +17 -8
  328. package/hooks/gsd-session-state.sh +1 -0
  329. package/hooks/gsd-statusline.js +215 -26
  330. package/hooks/gsd-validate-commit.sh +80 -6
  331. package/hooks/gsd-windsurf-pre-command.js +16 -11
  332. package/hooks/gsd-windsurf-pre-write.js +22 -13
  333. package/hooks/gsd-workflow-guard.js +34 -16
  334. package/hooks/gsd-worktree-path-guard.js +36 -21
  335. package/hooks/gsd-write-guard.js +35 -25
  336. package/hooks/lib/cli-exit.js +560 -0
  337. package/hooks/lib/exit-code-registry.js +98 -0
  338. package/hooks/lib/git-probe.js +84 -0
  339. package/hooks/lib/hook-exit.js +81 -0
  340. package/hooks/managed-hooks-registry.cjs +3 -0
  341. package/package.json +12 -7
  342. package/scripts/base64-scan.sh +74 -12
  343. package/scripts/build-hooks.js +5 -0
  344. package/scripts/check-glossary-refs.cjs +77 -15
  345. package/scripts/check-mutation-score-ratchet.cjs +156 -0
  346. package/scripts/ci-check-job-near-cap.cjs +49 -0
  347. package/scripts/ci-pr-mergeability.cjs +262 -0
  348. package/scripts/ci-test-scope.cjs +45 -12
  349. package/scripts/ci-timeout-report.cjs +230 -0
  350. package/scripts/docs-guard-registry.cjs +396 -0
  351. package/scripts/gen-capability-registry.cjs +8 -6
  352. package/scripts/gen-exit-code-docs.cjs +318 -0
  353. package/scripts/gen-exit-code-registry.cjs +891 -0
  354. package/scripts/gen-features.cjs +836 -0
  355. package/scripts/gen-hooks-cli-exit.cjs +239 -0
  356. package/scripts/gen-install-tree-fixtures.cjs +2 -2
  357. package/scripts/gen-loop-host-contract.cjs +134 -1
  358. package/scripts/gen-scripts-cli-exit.cjs +185 -0
  359. package/scripts/gen-state-md-docs.cjs +727 -0
  360. package/scripts/{test-failure-reasons.cjs → gsd-test-gate-reasons.cjs} +6 -0
  361. package/scripts/lib/ci-job-timing.cjs +72 -0
  362. package/scripts/lib/cli-exit.cjs +546 -44
  363. package/scripts/lib/drift-scan.cjs +32 -2
  364. package/scripts/lib/exit-code-registry.cjs +98 -0
  365. package/scripts/lib/ndjson-reporter.cjs +119 -0
  366. package/scripts/lint-allow-test-rule-refs.unverified-ceiling.json +1 -1
  367. package/scripts/lint-docs-guard-registration.cjs +495 -0
  368. package/scripts/lint-docs-guard-registration.exempt-baseline.cjs +193 -0
  369. package/scripts/lint-eslint-glob-coverage.allowlist.json +4 -0
  370. package/scripts/{lint-fix-has-regression-test.cjs → lint-fix-has-regression-tests.cjs} +12 -6
  371. package/scripts/lint-health-diagnostic-rule-table.cjs +65 -8
  372. package/scripts/lint-mutation-test-derivation-drift.cjs +86 -0
  373. package/scripts/lint-phase-enumeration-drift.cjs +21 -8
  374. package/scripts/lint-planning-prompt-drift.cjs +38 -1
  375. package/scripts/lint-removed-but-needed.cjs +184 -16
  376. package/scripts/lint-seam-enforcement.cjs +182 -0
  377. package/scripts/lint-slug-derivation-drift.cjs +921 -0
  378. package/scripts/lint-source-test-name-collision.cjs +241 -0
  379. package/scripts/lint-state-write-path-drift.cjs +337 -432
  380. package/scripts/lint-test-file-count.allowlist.json +122 -4
  381. package/scripts/lint-test-file-count.cjs +25 -3
  382. package/scripts/lint-unreachable-guard-drift.cjs +51 -64
  383. package/scripts/lint-vendored-deps.cjs +208 -35
  384. package/scripts/mutation-matrix.cjs +599 -50
  385. package/scripts/prompt-injection-scan.sh +75 -14
  386. package/scripts/secret-scan.sh +75 -13
  387. package/scripts/select-docs-guards.cjs +56 -0
  388. package/scripts/sync-runtime-launcher.cjs +22 -3
  389. package/skills/gsd-discuss-phase/SKILL.md +1 -1
  390. package/skills/gsd-import/SKILL.md +1 -1
  391. package/skills/gsd-quick/SKILL.md +8 -4
  392. package/vscode/package.json +1 -1
  393. package/bin/lib/ui-safety-gate.cjs +0 -109
  394. package/scripts/lint-emitted-drift-ack.cjs +0 -344
  395. package/scripts/state-write-path-drift-baseline.json +0 -19
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime identity — prove which package's `gsd-tools` actually executed (#3146).
4
+ *
5
+ * The predecessor package `get-shit-done-cc` publishes a colliding `gsd-tools`
6
+ * bin (verified 2026-08-24 against 1.42.3: `bin.gsd-tools -> bin/gsd-sdk.js`),
7
+ * and exposes verbs of the same name with different semantics. #3129 is the
8
+ * worked example: `phases.clear` archives here and **deletes** there, and the
9
+ * output is success-shaped either way, so 43 phase directories went missing
10
+ * with no warning.
11
+ *
12
+ * That collision is now prevented in the resolver rather than detected here:
13
+ * the launcher's PATH branch resolves `gsd_run`, which only this package
14
+ * publishes and which self-locates to its sibling shim, so a foreign binary is
15
+ * unreachable from PATH. The path-based branches — a project-local install, a
16
+ * runtime config directory — have no such structural guarantee: they trust
17
+ * their configured location. #3841 closes that remaining route by making the
18
+ * launcher preamble PROBE the resolved tool once, before any verb runs, and
19
+ * warn when it cannot prove it is this package. This module backs both the
20
+ * `runtime-identity` verb the preamble calls and the vocabulary that gate
21
+ * reports in (`IDENTITY_STATUS`).
22
+ *
23
+ * The rollout is warn-then-fail (the #3146 maintainer ruling): the preamble
24
+ * prints one actionable line and proceeds. It cannot hard-fail yet because
25
+ * `no_identity_verb` does not distinguish a foreign package from an
26
+ * `@opengsd/gsd-core` older than the verb — and during rollout the old-version
27
+ * case is the common one, so a hard failure would stop working installs.
28
+ *
29
+ * Parsing is deliberately STRICT. The whole value of the check is telling "us"
30
+ * from "not us"; a lenient parse that accepts the predecessor's usage text as
31
+ * close-enough would reproduce the exact silent success #3129 already produced.
32
+ * Liberality is spent on visibility instead — distinct reason codes, each
33
+ * naming what actually happened.
34
+ *
35
+ * The classifier and the shell preamble are held in agreement by a
36
+ * cross-surface parity test (#3841): both read stdout only and must reach the
37
+ * same verdict for the same payload, or the preamble's warning and this
38
+ * module's diagnostic would silently diverge on the same input.
39
+ */
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.IDENTITY_RAW_PREFIX = exports.IDENTITY_STATUS = exports.EXPECTED_PACKAGE_NAME = void 0;
42
+ exports.classifyIdentityProbe = classifyIdentityProbe;
43
+ exports.statusForVerdict = statusForVerdict;
44
+ exports.buildIdentityPayload = buildIdentityPayload;
45
+ exports.explainVerdict = explainVerdict;
46
+ exports.cmdRuntimeIdentity = cmdRuntimeIdentity;
47
+ const package_identity_cjs_1 = require("./package-identity.cjs");
48
+ const capability_loader_cjs_1 = require("./capability-loader.cjs");
49
+ /** The package name a legitimate GSD runtime reports. Baked at build time (#498). */
50
+ exports.EXPECTED_PACKAGE_NAME = package_identity_cjs_1.packageName;
51
+ /**
52
+ * The two-valued status the launcher preamble exports as `GSD_IDENTITY_STATUS`
53
+ * (#3841). Frozen so it is a VALUE a test can assert on: CONTRIBUTING forbids
54
+ * proving the gate fired by matching its human-readable warning prose.
55
+ *
56
+ * Two values, not five: the shell has no use for the distinction between
57
+ * `no_identity_verb` and `unparseable` — it either holds proof or it does not.
58
+ * The five-way {@link IdentityReason} stays the diagnostic vocabulary;
59
+ * {@link statusForVerdict} is the only bridge between them.
60
+ */
61
+ exports.IDENTITY_STATUS = Object.freeze({
62
+ OK: 'ok',
63
+ UNVERIFIED: 'unverified',
64
+ });
65
+ /**
66
+ * The exact byte prefix the preamble anchors its `case` pattern to.
67
+ *
68
+ * ANCHORED, never a substring search. `JSON.stringify` emits keys in insertion
69
+ * order and `buildIdentityPayload` inserts `packageName` first, so a genuine
70
+ * `--raw` payload always STARTS with this. An unanchored match would verify the
71
+ * decoy `{"packageName":"get-shit-done-cc","note":"@opengsd/gsd-core"}`, which
72
+ * is exactly the shape a colliding package could publish.
73
+ *
74
+ * The preamble anchors at BOTH ends: its `case` pattern is this prefix, then
75
+ * anything, then a literal `}`, so a truncated payload fails too. That is safe
76
+ * for any future additive field — a JSON object's own closing brace is always
77
+ * the last character, whatever the last value's type. It also pairs the literal
78
+ * `{` for the raw-text brace guards the preamble is inlined into (#3841); the
79
+ * pairing is a consequence of the stronger check, not the reason for it.
80
+ */
81
+ exports.IDENTITY_RAW_PREFIX = `{"packageName":"${exports.EXPECTED_PACKAGE_NAME}"`;
82
+ /** Cap on echoed probe output so a warning can never dump a whole usage screen. */
83
+ const EVIDENCE_MAX_CHARS = 200;
84
+ function excerpt(text) {
85
+ const flat = text.replace(/\s+/g, ' ').trim();
86
+ return flat.length > EVIDENCE_MAX_CHARS ? `${flat.slice(0, EVIDENCE_MAX_CHARS)}…` : flat;
87
+ }
88
+ /**
89
+ * `stdout` as a plain JSON object, or `null` when it is not one.
90
+ *
91
+ * `JSON.parse` accepts `0`, `"str"`, `[]`, `null` and `true`; arrays and `null`
92
+ * are also `object` to `typeof`. All are rejected here so no downstream
93
+ * truthiness check can mistake `[]` for a verified identity.
94
+ */
95
+ function parseIdentityRecord(stdout) {
96
+ let parsed;
97
+ try {
98
+ parsed = JSON.parse(stdout);
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
104
+ return null;
105
+ return parsed;
106
+ }
107
+ /**
108
+ * Pure classifier: probe result -> verdict. Total — never throws, for any input.
109
+ *
110
+ * Non-object JSON (`0`, `"str"`, `[]`, `null`, `true`) is `unparseable`, not
111
+ * `ok` and not a crash: `JSON.parse` accepts all of them, so a naive truthiness
112
+ * check would let `[]` through as a verified identity.
113
+ */
114
+ function classifyIdentityProbe(probe, expected = exports.EXPECTED_PACKAGE_NAME) {
115
+ if (probe.spawnFailed || probe.timedOut) {
116
+ return {
117
+ reason: 'probe_failed',
118
+ expected,
119
+ detail: probe.timedOut ? 'identity probe timed out' : 'identity probe could not be spawned',
120
+ };
121
+ }
122
+ // PARSE BEFORE CONSULTING THE EXIT CODE (#3841).
123
+ //
124
+ // The exit-code rule below is right for its stated reason -- the predecessor
125
+ // prints a usage screen and exits 1, and that is "something else answered",
126
+ // not a parse problem -- but it used to run FIRST, so it also caught a tool
127
+ // that had already proved its identity and merely exited non-zero afterwards.
128
+ // The shell preamble this module speaks for reads stdout ONLY (its command
129
+ // substitution discards the status), so the two surfaces disagreed on exactly
130
+ // that input: shell `ok`, classifier `no_identity_verb`. Measured against the
131
+ // real snippet, not inferred. Since this classifier is the engine for the
132
+ // announced hard-fail phase, such an install would have flipped from verified
133
+ // to refused at rollout, in the phase where that stops the run.
134
+ //
135
+ // The predecessor defence is unaffected: a usage screen yields no usable
136
+ // payload, so it still falls through to the exit-code branch below.
137
+ const record = parseIdentityRecord(probe.stdout);
138
+ if (record !== null) {
139
+ const actual = record.packageName;
140
+ if (typeof actual === 'string' && actual.length > 0) {
141
+ // Unknown keys are ignored so a future payload addition cannot fail an
142
+ // older check. The shell anchor is deliberately open in the middle for the
143
+ // same reason, and the parity suite pins both halves of that (case P10).
144
+ const version = typeof record.version === 'string' ? record.version : undefined;
145
+ if (actual !== expected)
146
+ return { reason: 'identity_mismatch', expected, actual, version };
147
+ // ANCHOR PARITY (#3841). The shell preamble cannot parse JSON: it matches
148
+ // a `case` pattern anchored at the START of stdout, so a payload only
149
+ // verifies there when it begins at the first byte and serializes
150
+ // `packageName` first. A purely structural parse would accept
151
+ // `{"note":"x","packageName":"<us>"}` and a leading-whitespace payload
152
+ // that the shell rejects -- a FAIL-OPEN disagreement between the two
153
+ // surfaces.
154
+ //
155
+ // Reproduce those two properties SEMANTICALLY rather than byte-matching
156
+ // IDENTITY_RAW_PREFIX. The prefix describes the `--raw` wire format, but
157
+ // this classifier is also handed the DEFAULT pretty serialization
158
+ // (`runtime-identity` with no `--raw`, which is two-space indented) --
159
+ // byte-matching the compact prefix rejected that, which the remote matrix
160
+ // caught. `startsWith('{')` and a first-key check hold for both.
161
+ const firstKey = Object.keys(record)[0];
162
+ if (!probe.stdout.startsWith('{') || firstKey !== 'packageName') {
163
+ return {
164
+ reason: 'unparseable',
165
+ expected,
166
+ detail: 'payload names this package but is not in the anchored wire shape',
167
+ };
168
+ }
169
+ return { reason: 'ok', expected, actual, version };
170
+ }
171
+ }
172
+ // Nothing was proved. NOW the exit status is the discriminator: a non-zero
173
+ // exit means a binary that does not implement this verb answered.
174
+ if (probe.exitCode !== 0) {
175
+ return {
176
+ reason: 'no_identity_verb',
177
+ expected,
178
+ detail: `exit ${String(probe.exitCode)}: ${excerpt(probe.stdout)}`,
179
+ };
180
+ }
181
+ return {
182
+ reason: 'unparseable',
183
+ expected,
184
+ detail: record === null ? excerpt(probe.stdout) : 'payload has no usable packageName',
185
+ };
186
+ }
187
+ /**
188
+ * Collapse a five-way verdict onto the two-valued shell status.
189
+ *
190
+ * Total by construction: anything that is not `ok` is `unverified`. A future
191
+ * sixth reason code therefore fails CLOSED here rather than silently verifying.
192
+ */
193
+ function statusForVerdict(verdict) {
194
+ return verdict.reason === 'ok' ? exports.IDENTITY_STATUS.OK : exports.IDENTITY_STATUS.UNVERIFIED;
195
+ }
196
+ /**
197
+ * Build this runtime's identity payload.
198
+ *
199
+ * Version is REPORTED but not asserted in the warn phase, so a dev tree
200
+ * reporting readHostVersion()'s fail-closed `0.0.0` still verifies. Carrying it
201
+ * now means the hard-fail phase can gate on compatibility without a payload
202
+ * change (and therefore without a second round of Hyrum's-Law exposure).
203
+ */
204
+ function buildIdentityPayload(deps = {}) {
205
+ const readVersion = deps.readVersion ?? (() => (0, capability_loader_cjs_1.readHostVersion)());
206
+ const readName = deps.readPackageName ?? (() => exports.EXPECTED_PACKAGE_NAME);
207
+ return { packageName: readName(), version: readVersion() };
208
+ }
209
+ /** Render a verdict as the one-line actionable warning the preamble prints. */
210
+ function explainVerdict(verdict, resolvedPath) {
211
+ const head = `WARNING: "${resolvedPath}" did not report a ${verdict.expected} identity.`;
212
+ const why = {
213
+ ok: 'identity verified',
214
+ identity_mismatch: `it reported "${verdict.actual ?? '(unknown)'}" instead`,
215
+ no_identity_verb: 'it does not implement the runtime-identity verb — either a different package, or a gsd-core predating the verb',
216
+ unparseable: 'its response could not be parsed as an identity payload',
217
+ probe_failed: 'the identity probe could not be run',
218
+ };
219
+ const tail = 'A workflow shipped by this package may be running against a different tool. ' +
220
+ 'See docs/how-to/diagnose-a-foreign-gsd-tools.md';
221
+ const evidence = verdict.detail ? ` (${verdict.detail})` : '';
222
+ return `${head} Reason: ${why[verdict.reason]}${evidence}. ${tail}`;
223
+ }
224
+ /**
225
+ * CLI arm for `gsd-tools runtime-identity`.
226
+ *
227
+ * Kept on the CJS fast path for the same reason as `current-timestamp`: it is a
228
+ * pure local read, and the launcher preamble spawns it once per workflow run,
229
+ * so SDK bridge startup would be a per-run tax on every workflow.
230
+ */
231
+ function cmdRuntimeIdentity(raw = false, deps = {}) {
232
+ const payload = buildIdentityPayload(deps);
233
+ process.stdout.write(`${JSON.stringify(payload, null, raw ? 0 : 2)}\n`);
234
+ }
@@ -29,6 +29,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.formatGsdSlash = formatGsdSlash;
32
+ exports.readInstallRuntimeMarker = readInstallRuntimeMarker;
33
+ exports._setInstallRuntimeMarkerForTests = _setInstallRuntimeMarkerForTests;
34
+ exports._resetInstallRuntimeMarkerCacheForTests = _resetInstallRuntimeMarkerCacheForTests;
32
35
  exports.resolveExplicitRuntime = resolveExplicitRuntime;
33
36
  exports.resolveRuntime = resolveRuntime;
34
37
  exports.formatGsdSlashFor = formatGsdSlashFor;
@@ -75,6 +78,58 @@ function formatGsdSlash(commandName, runtime) {
75
78
  }
76
79
  return `/gsd-${token}${tail}`;
77
80
  }
81
+ // ─── #3897 rung 2: the per-install `.gsd-runtime` marker, promoted from ──────
82
+ // model-resolver.cts (#2297) to this module — the canonical owner of runtime
83
+ // identity (resolveRuntime, formatGsdSlash). `bin/install.js` writes
84
+ // `<install>/gsd-core/.gsd-runtime` beside VERSION for every runtime install
85
+ // (#2297). This module compiles to `gsd-core/bin/lib/runtime-slash.cjs`
86
+ // (ADR-457) — the SAME directory `model-resolver.cjs` compiles to — so the
87
+ // `__dirname`-relative path below is unchanged from the promoted original.
88
+ //
89
+ // Cache + test-seam shape, byte-for-behaviour preserved from
90
+ // model-resolver.cts:65-77 (N5): module-level `let`, `try/catch -> null`,
91
+ // `_setInstallRuntimeMarkerForTests` / `_resetInstallRuntimeMarkerCacheForTests`.
92
+ // `model-resolver.cts` now imports this implementation instead of holding its
93
+ // own copy; the two `hooks/*.js` marker readers delegate here too (through
94
+ // `ensureRuntimeBuild()`, per `scripts/lint-hooks-runtime-build-seam.cjs`).
95
+ let _installMarkerCache;
96
+ /**
97
+ * Read the per-install runtime marker, cached for the process lifetime.
98
+ * Never throws (N4) — an absent/unreadable marker (dev/source tree, an
99
+ * install predating #2297, EACCES, hostile content, ...) is "no signal",
100
+ * never a resolution failure; a throw here would break a session in
101
+ * `gsd-agent-isolation-guard.js`, which is worse than resolving the wrong
102
+ * runtime.
103
+ *
104
+ * The raw marker string is returned as-is (trimmed) — callers MUST route it
105
+ * through `resolveRuntimeNameFromCandidates` before trusting it (N1); this
106
+ * function itself does not normalize so its cached value matches exactly
107
+ * what #2297's tests already assert about the underlying file read.
108
+ */
109
+ function readInstallRuntimeMarker() {
110
+ if (_installMarkerCache !== undefined)
111
+ return _installMarkerCache;
112
+ try {
113
+ const markerPath = node_path_1.default.join(__dirname, '..', '..', '.gsd-runtime');
114
+ const raw = node_fs_1.default.readFileSync(markerPath, 'utf8').trim();
115
+ _installMarkerCache = raw || null;
116
+ }
117
+ catch {
118
+ // No marker: dev/source tree, or an install predating #2297. Fall through
119
+ // to the 'claude' default (keeps tier aliases — never worse than the bug).
120
+ _installMarkerCache = null;
121
+ }
122
+ return _installMarkerCache;
123
+ }
124
+ // Test seams for the install-marker rung (the dev/source tree has no marker,
125
+ // so the file read always bottoms out at 'claude' — these let tests exercise
126
+ // the third precedence rung and reset the module-level cache between cases).
127
+ function _setInstallRuntimeMarkerForTests(value) {
128
+ _installMarkerCache = value;
129
+ }
130
+ function _resetInstallRuntimeMarkerCacheForTests() {
131
+ _installMarkerCache = undefined;
132
+ }
78
133
  /**
79
134
  * Resolve the explicit runtime for a project directory, from the two
80
135
  * explicit sources only — no default is applied.
@@ -121,17 +176,32 @@ function resolveExplicitRuntime(projectDir, env = process.env) {
121
176
  /**
122
177
  * Resolve the effective runtime for a project directory.
123
178
  *
124
- * process.env.GSD_RUNTIME > config.runtime > 'claude'
179
+ * process.env.GSD_RUNTIME > config.runtime > install marker > 'claude'
125
180
  *
126
181
  * Mirrors the precedence already used by profile-output.cjs and the rest of
127
182
  * the runtime resolution chain. Returns a lowercased string so downstream
128
183
  * comparisons can be case-blind.
129
184
  *
185
+ * #3897 rung 2: the per-install `.gsd-runtime` marker is the THIRD rung,
186
+ * between the two explicit sources and the 'claude' default — matching
187
+ * model-resolver.cts's own description of it as "the third precedence rung"
188
+ * before this reader was promoted here. The marker's raw contents are never
189
+ * trusted verbatim (N1): they are routed through the SAME
190
+ * `resolveRuntimeNameFromCandidates` normalization the env rung uses, so an
191
+ * unknown or hostile marker value degrades exactly like an unknown
192
+ * GSD_RUNTIME value would.
193
+ *
130
194
  * @param projectDir - path to the project directory, or null/undefined
131
195
  * @returns the resolved runtime name
132
196
  */
133
197
  function resolveRuntime(projectDir) {
134
- return resolveExplicitRuntime(projectDir) ?? 'claude';
198
+ const explicit = resolveExplicitRuntime(projectDir);
199
+ if (explicit)
200
+ return explicit;
201
+ const markerRuntime = (0, runtime_name_policy_cjs_1.resolveRuntimeNameFromCandidates)(readInstallRuntimeMarker());
202
+ if (markerRuntime)
203
+ return markerRuntime;
204
+ return 'claude';
135
205
  }
136
206
  /**
137
207
  * Convenience: format using the runtime resolved from a project directory.
@@ -19,6 +19,7 @@ exports.PATH_ACTION_REASON = void 0;
19
19
  exports.toPosixPath = toPosixPath;
20
20
  exports.toNativePath = toNativePath;
21
21
  exports.posixNormalize = posixNormalize;
22
+ exports.toComparablePathKey = toComparablePathKey;
22
23
  exports.hookCommandNeedsPowerShellCallOperator = hookCommandNeedsPowerShellCallOperator;
23
24
  exports.formatHookCommandForRuntime = formatHookCommandForRuntime;
24
25
  exports.shellHookOmitsBashRunner = shellHookOmitsBashRunner;
@@ -43,6 +44,7 @@ exports.projectPersistentPathExportActions = projectPersistentPathExportActions;
43
44
  exports.isSpawnTimeout = isSpawnTimeout;
44
45
  exports.execGit = execGit;
45
46
  exports.execNpm = execNpm;
47
+ exports.envGet = envGet;
46
48
  exports.resolveExecutableBinary = resolveExecutableBinary;
47
49
  exports.projectSpawnInvocation = projectSpawnInvocation;
48
50
  exports.execTool = execTool;
@@ -50,6 +52,7 @@ exports.resolveGsdToolsPath = resolveGsdToolsPath;
50
52
  exports.dispatchGsdCommand = dispatchGsdCommand;
51
53
  exports.probeTty = probeTty;
52
54
  exports.normalizeContent = normalizeContent;
55
+ exports.contentChangedAfterNormalize = contentChangedAfterNormalize;
53
56
  exports.retryRenameSync = retryRenameSync;
54
57
  exports.platformWriteSync = platformWriteSync;
55
58
  exports.platformReadSync = platformReadSync;
@@ -95,6 +98,20 @@ function toNativePath(p) {
95
98
  function posixNormalize(p) {
96
99
  return p.replace(/\\/g, '/');
97
100
  }
101
+ /**
102
+ * #3663 — comparison key for a path that must equal another path regardless
103
+ * of spelling: separator form (forward slashes via posixNormalize), relative
104
+ * segments and trailing separators (path.resolve + strip), and — ONLY on
105
+ * win32's case-insensitive filesystem — letter casing. POSIX stays
106
+ * case-sensitive: differently-cased paths are genuinely different
107
+ * directories there. This module owns the platform-conditional fold so the
108
+ * policy lives at the seam instead of accreting per-call-site copies (the
109
+ * class init.cts's normalizeForCompare/toComparableRaw predate).
110
+ */
111
+ function toComparablePathKey(p, platform = process.platform) {
112
+ const normalized = posixNormalize(node_path_1.default.resolve(p)).replace(/\/+$/g, '');
113
+ return platform === 'win32' ? normalized.toLowerCase() : normalized;
114
+ }
98
115
  /**
99
116
  * Return true when a managed hook command must be prefixed with PowerShell's
100
117
  * call operator so a quoted executable token is invokable by the target
@@ -218,6 +235,13 @@ const MANAGED_HOOK_BASENAMES_BY_SURFACE = {
218
235
  'gsd-read-injection-scanner.js',
219
236
  'gsd-update-banner.js',
220
237
  'gsd-workflow-guard.js',
238
+ // #3662: the three PreToolUse guards are GSD-managed JS hooks (registered
239
+ // only-if-absent by applySettingsJsonHooks) but sat outside this set, so
240
+ // the #2979 runner rewriter never reached them — the issue's reported
241
+ // mixed state lived on exactly these hooks.
242
+ 'gsd-write-guard.js',
243
+ 'gsd-agent-isolation-guard.js',
244
+ 'gsd-worktree-path-guard.js',
221
245
  ]),
222
246
  'codex-toml': new Set([
223
247
  'gsd-check-update.js',
@@ -237,6 +261,14 @@ const MANAGED_HOOK_COMMAND_BASENAMES_BY_SURFACE = {
237
261
  'gsd-session-state.sh',
238
262
  'gsd-validate-commit.sh',
239
263
  'gsd-phase-boundary.sh',
264
+ // #3662: same three guards as MANAGED_HOOK_BASENAMES_BY_SURFACE above —
265
+ // their absence here meant isManagedHookCommand never recognized them, so
266
+ // the settings.json→settings.local.json migration filter (and uninstall
267
+ // cleanup) skipped GSD's own guard entries. Folded-in fix, surfaced by the
268
+ // #3662 issue thread.
269
+ 'gsd-write-guard.js',
270
+ 'gsd-agent-isolation-guard.js',
271
+ 'gsd-worktree-path-guard.js',
240
272
  ]),
241
273
  'codex-toml': new Set([
242
274
  'gsd-check-update.js',
@@ -330,9 +362,15 @@ const ANCHORED_HOOK_SCRIPT_TOKEN = /^"\$[A-Za-z_][A-Za-z0-9_]*"\//;
330
362
  * Non-Windows keeps the original script token shape when provided (single
331
363
  * quote / bareword / quoted), while Windows normalizes to double-quoted
332
364
  * forward-slash path tokens for stable cross-shell behavior.
365
+ *
366
+ * #3662: `runnerToken` is the runner the current install would emit — since
367
+ * #3662 that is the runtime-resolving chain token (see
368
+ * buildNodeRunnerChainToken), not a bare absolute path, so re-projected
369
+ * entries converge onto a runner that resolves in every environment sharing
370
+ * the config root.
333
371
  */
334
- function projectLegacySettingsHookCommand({ absoluteRunner, scriptPath, scriptToken, runtime = 'generic', platform = process.platform, }) {
335
- if (!absoluteRunner || !scriptPath)
372
+ function projectLegacySettingsHookCommand({ runnerToken, scriptPath, scriptToken, runtime = 'generic', platform = process.platform, }) {
373
+ if (!runnerToken || !scriptPath)
336
374
  return null;
337
375
  const normalizedScriptPath = platform === 'win32' ? posixNormalize(scriptPath) : scriptPath;
338
376
  // #1693: a script path already carrying a `"$CLAUDE_PROJECT_DIR"`-anchored
@@ -351,7 +389,7 @@ function projectLegacySettingsHookCommand({ absoluteRunner, scriptPath, scriptTo
351
389
  : JSON.stringify(normalizedScriptPath))
352
390
  : (scriptToken || JSON.stringify(normalizedScriptPath));
353
391
  return projectShellCommandText({
354
- runnerToken: absoluteRunner,
392
+ runnerToken,
355
393
  argTokens: [commandScriptToken],
356
394
  runtime,
357
395
  platform,
@@ -628,8 +666,12 @@ function _isFile(candidate, requireExecutable = false, platform = process.platfo
628
666
  *
629
667
  * Exact match wins when present, so a caller who sets the canonical name pays
630
668
  * no scan.
669
+ *
670
+ * Exported so callers outside this seam can route an exact-case-sensitive env
671
+ * read through it instead of accessing a non-`process.env` object directly
672
+ * (see `local/no-exact-case-env-access`).
631
673
  */
632
- function _envGet(env, name) {
674
+ function envGet(env, name) {
633
675
  const exact = env[name];
634
676
  if (exact !== undefined)
635
677
  return exact;
@@ -728,7 +770,7 @@ function resolveExecutableBinary(name, opts = {}) {
728
770
  return _isFile(name, requireExecutable, platform) ? name : null;
729
771
  }
730
772
  const env = opts.env ?? process.env;
731
- const rawPath = opts.pathOverride !== undefined ? opts.pathOverride : (_envGet(env, 'PATH') || '');
773
+ const rawPath = opts.pathOverride !== undefined ? opts.pathOverride : (envGet(env, 'PATH') || '');
732
774
  const pathSegments = String(rawPath).split(node_path_1.default.delimiter).filter(Boolean);
733
775
  const segments = [...(opts.prependPaths ?? []), ...pathSegments];
734
776
  if (platform !== 'win32') {
@@ -739,7 +781,7 @@ function resolveExecutableBinary(name, opts = {}) {
739
781
  }
740
782
  return null;
741
783
  }
742
- const exts = String(_envGet(env, 'PATHEXT') || DEFAULT_PATHEXT).split(';').filter(Boolean);
784
+ const exts = String(envGet(env, 'PATHEXT') || DEFAULT_PATHEXT).split(';').filter(Boolean);
743
785
  // A name already ending in a PATHEXT-listed extension is an address, not a stem:
744
786
  // probing `foo.exe` as `foo.exe.EXE` would miss the file sitting right there.
745
787
  // Compared case-insensitively because PATHEXT casing is not guaranteed.
@@ -840,7 +882,7 @@ function projectSpawnInvocation(command, args = [], opts = {}) {
840
882
  return resolved ? { command: resolved, args, resolved } : { command, args, resolved: null };
841
883
  }
842
884
  return {
843
- command: String(_envGet(env, 'ComSpec') || 'cmd.exe'),
885
+ command: String(envGet(env, 'ComSpec') || 'cmd.exe'),
844
886
  args: ['/d', '/s', '/c', _buildVerbatimCmdLine(target, args)],
845
887
  resolved,
846
888
  windowsVerbatimArguments: true,
@@ -1022,7 +1064,11 @@ function _normalizeMd(content) {
1022
1064
  if (i === 0 || !insideFence[i - 1])
1023
1065
  result.push('');
1024
1066
  }
1025
- if (/^(\s*[-*+]\s|\s*\d+\.\s)/.test(line) && i > 0 && prevTrimmed !== '' && !/^(\s*[-*+]\s|\s*\d+\.\s)/.test(prev) && prevTrimmed !== '---')
1067
+ // #3854: the `!/^\s/.test(prev)` guard mirrors the after-a-bullet rule below —
1068
+ // an indented non-bullet line is a CONTINUATION of the previous list item, not a
1069
+ // preceding paragraph, so no separating blank may be injected before this bullet
1070
+ // (that injection converted every tight multi-line list to a loose one on write).
1071
+ if (/^(\s*[-*+]\s|\s*\d+\.\s)/.test(line) && i > 0 && prevTrimmed !== '' && !/^(\s*[-*+]\s|\s*\d+\.\s)/.test(prev) && !/^\s/.test(prev) && prevTrimmed !== '---')
1026
1072
  result.push('');
1027
1073
  result.push(line);
1028
1074
  if (/^#{1,6}\s/.test(trimmed) && i < lines.length - 1 && (lines[i + 1] ?? '').trimEnd() !== '')
@@ -1052,6 +1098,23 @@ function normalizeContent(filePath, content, opts = {}) {
1052
1098
  }
1053
1099
  return { content: normalized, encoding };
1054
1100
  }
1101
+ /**
1102
+ * True iff persisting `after` via `platformWriteSync` would land different
1103
+ * on-disk bytes than `before` already has (or would have, normalized the
1104
+ * same way). `platformWriteSync` runs Markdown normalization (CRLF strip,
1105
+ * blank-line-run collapse, single trailing newline) before writing, so a
1106
+ * caller comparing raw pre-normalize strings (`after !== before`) can report
1107
+ * `true` even when the persisted bytes are byte-identical — e.g. a
1108
+ * transform that regenerates a section fresh on every call, including a
1109
+ * genuine no-op re-run, in a different-but-equivalent raw shape than the
1110
+ * already-normalized on-disk original (#3685 / #3691). Any "did this write
1111
+ * change the file?" flag MUST go through this seam (or an equivalent
1112
+ * post-write re-read of the actual on-disk bytes) instead of a raw `!==` —
1113
+ * do not simplify this back to a direct string comparison.
1114
+ */
1115
+ function contentChangedAfterNormalize(filePath, before, after) {
1116
+ return normalizeContent(filePath, after).content !== normalizeContent(filePath, before).content;
1117
+ }
1055
1118
  // Rename errnos that are transient on Windows: a concurrent reader (or an AV
1056
1119
  // scanner / indexer) holding the target open makes renameSync fail briefly.
1057
1120
  // Same idiom as capability-ledger.cts / capability-consent.cts.
@@ -43,6 +43,10 @@ const node_fs_1 = __importDefault(require("node:fs"));
43
43
  const node_path_1 = __importDefault(require("node:path"));
44
44
  const node_child_process_1 = require("node:child_process");
45
45
  const markdown_sectionizer_cjs_1 = require("./markdown-sectionizer.cjs");
46
+ // #3696: the calendar-validity predicate moved to the STATE.md document module
47
+ // so `state validate` can assert the same `last_activity` invariant this reader
48
+ // already enforces (ADR-227). Two copies would let the two surfaces disagree
49
+ // about whether a STATE.md is usable — which is the defect #3696 reports.
46
50
  // eslint-disable-next-line @typescript-eslint/no-require-imports
47
51
  const ioMod = require("./io.cjs");
48
52
  const { output } = ioMod;
@@ -160,26 +164,6 @@ const ISO_LEADING_RE = /^(\d{4})-(\d{2})-(\d{2})((?:[T ]\d{2}:\d{2}(?::\d{2}(?:\
160
164
  * failed open on every letter-led description and re-opened #2570.
161
165
  */
162
166
  const ZONE_DESIGNATOR_RE = /^\s*[A-Z]{2,5}(?![A-Za-z])/;
163
- /**
164
- * True only when y/m/d name a date that actually exists on the calendar.
165
- *
166
- * `Date.parse` validates shape but not value: it rolls an out-of-range day
167
- * FORWARD rather than rejecting it (`2026-02-30` -> `2026-03-02`,
168
- * `2026-04-31` -> `2026-05-01`). Shape-only validation would therefore
169
- * propagate a different, wrong instant instead of failing safe — precisely
170
- * what ADR-227 ("validate shape AND value; on failure of either layer coerce
171
- * to the contract's safe default, never propagate") exists to prevent. A
172
- * round-trip through Date.UTC detects the rollover: any component the
173
- * constructor normalised comes back changed.
174
- */
175
- function isRealCalendarDate(year, month, day) {
176
- if (month < 1 || month > 12 || day < 1 || day > 31)
177
- return false;
178
- const probe = new Date(Date.UTC(year, month - 1, day));
179
- return (probe.getUTCFullYear() === year &&
180
- probe.getUTCMonth() === month - 1 &&
181
- probe.getUTCDate() === day);
182
- }
183
167
  function parseActivityTimestamp(raw) {
184
168
  if (!raw)
185
169
  return null;
@@ -190,7 +174,7 @@ function parseActivityTimestamp(raw) {
190
174
  // Reject an impossible calendar date outright rather than letting
191
175
  // Date.parse substitute a rolled-forward one. null = "no activity signal",
192
176
  // the safe default staleActivity already fails open on.
193
- if (!isRealCalendarDate(Number(year), Number(month), Number(day)))
177
+ if (!stateDocument.isRealCalendarDate(Number(year), Number(month), Number(day)))
194
178
  return null;
195
179
  // The date is real, so stay as liberal as before (Postel): a whole-string
196
180
  // parse still wins when the engine can make sense of the value. Reading the
@@ -542,7 +526,13 @@ function classify(s) {
542
526
  return 'planning';
543
527
  if (/\bexecut(e|ing)|active|in.progress|building\b/i.test(s.status))
544
528
  return 'executing';
545
- if (/\bverify|review|needs.review|pending.review\b/i.test(s.status))
529
+ // #3864: `verif` (not `verify`) — the same stem state-document's
530
+ // normalizeStateStatus matches. "verified" and "verification" contain no
531
+ // "verify" substring, so the exact word left them falling through to
532
+ // `unknown` (or idle-stranded on a clean unpushed tree — differently
533
+ // wrong). verify_failed is tested above, so a failed verification still
534
+ // wins over this branch.
535
+ if (/\bverif|review|needs.review|pending.review\b/i.test(s.status))
546
536
  return 'verify-pending';
547
537
  if (isIdleStranded(s))
548
538
  return 'idle-stranded';
@@ -26,6 +26,9 @@ exports.SECTION_HEADERS = void 0;
26
26
  exports.countSectionDataRows = countSectionDataRows;
27
27
  exports.specSectionStatus = specSectionStatus;
28
28
  const node_fs_1 = __importDefault(require("node:fs"));
29
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
30
+ const cliExitModule = require("./cli-exit.cjs");
31
+ const { ExitError, runMain } = cliExitModule;
29
32
  /**
30
33
  * Canonical SPEC section header matchers — the SINGLE source of truth for the headings
31
34
  * `templates/spec.md` renders. Suffix-tolerant by design: `prohibitions` matches BOTH
@@ -101,11 +104,13 @@ const VALID_KEYS = ['edges', 'prohibitions'];
101
104
  // 2 only on a usage error (missing args / bad key). `require.main === module` so it runs only when
102
105
  // the compiled `.cjs` is executed directly, never when imported by tests.
103
106
  if (require.main === module) {
104
- const specFile = process.argv[2];
105
- const key = process.argv[3];
106
- if (!specFile || !key || !VALID_KEYS.includes(key)) {
107
- process.stderr.write('usage: spec-section.cjs <specFile> <edges|prohibitions>\n');
108
- process.exit(2);
109
- }
110
- process.stdout.write(JSON.stringify(specSectionStatus(specFile, key)) + '\n');
107
+ runMain(() => {
108
+ const specFile = process.argv[2];
109
+ const key = process.argv[3];
110
+ if (!specFile || !key || !VALID_KEYS.includes(key)) {
111
+ process.stderr.write('usage: spec-section.cjs <specFile> <edges|prohibitions>\n');
112
+ throw new ExitError(2);
113
+ }
114
+ process.stdout.write(JSON.stringify(specSectionStatus(specFile, key)) + '\n');
115
+ });
111
116
  }