@opengsd/gsd-core 1.7.0 → 1.9.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 (261) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.opencode/plugins/gsd-core.js +45 -1
  4. package/README.md +2 -0
  5. package/agents/gsd-code-fixer.md +1 -1
  6. package/agents/gsd-codebase-mapper.md +1 -1
  7. package/agents/gsd-debug-session-manager.md +78 -4
  8. package/agents/gsd-debugger.md +87 -29
  9. package/agents/gsd-executor.md +49 -9
  10. package/agents/gsd-intel-updater.md +3 -3
  11. package/agents/gsd-phase-researcher.md +4 -2
  12. package/agents/gsd-plan-checker.md +20 -0
  13. package/agents/gsd-planner.md +44 -59
  14. package/agents/gsd-project-researcher.md +2 -2
  15. package/agents/gsd-ui-auditor.md +0 -40
  16. package/agents/gsd-verifier.md +2 -2
  17. package/bin/install.js +1338 -135
  18. package/commands/gsd/ai-integration-phase.md +1 -1
  19. package/commands/gsd/mempalace-capture.md +9 -5
  20. package/commands/gsd/new-milestone.md +1 -1
  21. package/commands/gsd/plan-phase.md +5 -3
  22. package/commands/gsd/plan-review-convergence.md +7 -2
  23. package/gsd-core/bin/gsd-tools.cjs +2690 -2472
  24. package/gsd-core/bin/lib/adapter-imperative.cjs +8 -1
  25. package/gsd-core/bin/lib/agent-command-router.cjs +20 -5
  26. package/gsd-core/bin/lib/api-coverage.cjs +360 -53
  27. package/gsd-core/bin/lib/audit.cjs +8 -8
  28. package/gsd-core/bin/lib/broken-windows.cjs +716 -0
  29. package/gsd-core/bin/lib/capability-command-router.cjs +733 -0
  30. package/gsd-core/bin/lib/capability-consent.cjs +40 -1
  31. package/gsd-core/bin/lib/capability-lifecycle.cjs +58 -0
  32. package/gsd-core/bin/lib/capability-loader.cjs +23 -1
  33. package/gsd-core/bin/lib/capability-registry.cjs +1450 -160
  34. package/gsd-core/bin/lib/capability-trust.cjs +468 -33
  35. package/gsd-core/bin/lib/capability-validator.cjs +882 -6
  36. package/gsd-core/bin/lib/capability-writer.cjs +6 -1
  37. package/gsd-core/bin/lib/check-command-router.cjs +140 -27
  38. package/gsd-core/bin/lib/cjs-command-router-adapter.cjs +15 -0
  39. package/gsd-core/bin/lib/claude-orchestration-command-router.cjs +209 -31
  40. package/gsd-core/bin/lib/claude-orchestration.cjs +203 -25
  41. package/gsd-core/bin/lib/command-aliases.cjs +14 -0
  42. package/gsd-core/bin/lib/commands.cjs +326 -21
  43. package/gsd-core/bin/lib/config-loader.cjs +214 -30
  44. package/gsd-core/bin/lib/config.cjs +158 -22
  45. package/gsd-core/bin/lib/core-utils.cjs +6 -1
  46. package/gsd-core/bin/lib/decisions.cjs +32 -8
  47. package/gsd-core/bin/lib/docs.cjs +6 -0
  48. package/gsd-core/bin/lib/estimate-cli.cjs +336 -0
  49. package/gsd-core/bin/lib/external-descriptor-trust.cjs +14 -2
  50. package/gsd-core/bin/lib/frontmatter.cjs +125 -15
  51. package/gsd-core/bin/lib/gap-checker.cjs +17 -2
  52. package/gsd-core/bin/lib/host-integration.cjs +215 -8
  53. package/gsd-core/bin/lib/init.cjs +155 -66
  54. package/gsd-core/bin/lib/install-engine.cjs +299 -23
  55. package/gsd-core/bin/lib/install-profiles.cjs +239 -1
  56. package/gsd-core/bin/lib/installer-migrations/005-opencode-baseline-commands-dir.cjs +146 -0
  57. package/gsd-core/bin/lib/installer-migrations/006-pi-extension-cjs-to-js.cjs +91 -0
  58. package/gsd-core/bin/lib/installer-migrations.cjs +44 -5
  59. package/gsd-core/bin/lib/markdown-sectionizer.cjs +107 -0
  60. package/gsd-core/bin/lib/milestone.cjs +248 -14
  61. package/gsd-core/bin/lib/model-catalog.cjs +69 -4
  62. package/gsd-core/bin/lib/model-resolver.cjs +189 -7
  63. package/gsd-core/bin/lib/observability/logger.cjs +7 -2
  64. package/gsd-core/bin/lib/onboard-projection.cjs +11 -8
  65. package/gsd-core/bin/lib/phase-command-router.cjs +10 -1
  66. package/gsd-core/bin/lib/phase-estimation.cjs +398 -0
  67. package/gsd-core/bin/lib/phase-id.cjs +304 -9
  68. package/gsd-core/bin/lib/phase.cjs +258 -17
  69. package/gsd-core/bin/lib/plan-drift-guard.cjs +1 -1
  70. package/gsd-core/bin/lib/plan-scan.cjs +70 -2
  71. package/gsd-core/bin/lib/planning-workspace.cjs +9 -2
  72. package/gsd-core/bin/lib/profile-output.cjs +34 -8
  73. package/gsd-core/bin/lib/review-lane-descriptor.cjs +927 -0
  74. package/gsd-core/bin/lib/review-lane-invocation.cjs +348 -0
  75. package/gsd-core/bin/lib/review-lane-runner.cjs +594 -0
  76. package/gsd-core/bin/lib/review-reviewer-selection.cjs +114 -32
  77. package/gsd-core/bin/lib/roadmap-parser.cjs +61 -10
  78. package/gsd-core/bin/lib/roadmap.cjs +23 -7
  79. package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +38 -5
  80. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +23 -9
  81. package/gsd-core/bin/lib/runtime-hooks-surface.cjs +156 -0
  82. package/gsd-core/bin/lib/runtime-name-policy.cjs +15 -2
  83. package/gsd-core/bin/lib/smart-entry.cjs +70 -5
  84. package/gsd-core/bin/lib/state-document.cjs +171 -24
  85. package/gsd-core/bin/lib/state-transition.cjs +50 -11
  86. package/gsd-core/bin/lib/state.cjs +206 -32
  87. package/gsd-core/bin/lib/surface.cjs +51 -9
  88. package/gsd-core/bin/lib/uat-predicate.cjs +6 -4
  89. package/gsd-core/bin/lib/uat.cjs +428 -11
  90. package/gsd-core/bin/lib/ui-consideration-probe.cjs +2 -2
  91. package/gsd-core/bin/lib/unusable-input.cjs +216 -0
  92. package/gsd-core/bin/lib/validate.cjs +44 -8
  93. package/gsd-core/bin/lib/verification.cjs +163 -31
  94. package/gsd-core/bin/lib/verify.cjs +348 -42
  95. package/gsd-core/bin/lib/worktree-safety.cjs +360 -15
  96. package/gsd-core/bin/shared/config-defaults.manifest.json +1 -0
  97. package/gsd-core/bin/shared/config-schema.manifest.json +4 -15
  98. package/gsd-core/bin/shared/model-catalog.json +5 -0
  99. package/gsd-core/bin/shared/runtime-aliases.manifest.json +5 -0
  100. package/gsd-core/references/api-coverage.md +37 -7
  101. package/gsd-core/references/checkpoints.md +1 -1
  102. package/gsd-core/references/common-bug-patterns.md +13 -0
  103. package/gsd-core/references/context-budget.md +40 -0
  104. package/gsd-core/references/debugger-bug-taxonomy.md +111 -0
  105. package/gsd-core/references/debugger-fix-acceptance.md +157 -0
  106. package/gsd-core/references/debugger-philosophy.md +1 -0
  107. package/gsd-core/references/debugger-prevention.md +98 -0
  108. package/gsd-core/references/debugger-rca-branching.md +98 -0
  109. package/gsd-core/references/debugger-repro-hardening.md +130 -0
  110. package/gsd-core/references/debugger-sbfl.md +110 -0
  111. package/gsd-core/references/debugger-semantic-recall.md +81 -0
  112. package/gsd-core/references/execute-phase-quota-recovery.md +55 -0
  113. package/gsd-core/references/execute-phase-requirement-revert.md +8 -0
  114. package/gsd-core/references/execute-phase-response-language.md +7 -0
  115. package/gsd-core/references/gate-prompts.md +6 -3
  116. package/gsd-core/references/model-profile-resolution.md +64 -13
  117. package/gsd-core/references/offer-next.md +88 -0
  118. package/gsd-core/references/planner-antipatterns.md +6 -0
  119. package/gsd-core/references/planner-mvp-mode.md +12 -13
  120. package/gsd-core/references/planner-preconditions.md +156 -0
  121. package/gsd-core/references/planner-reversibility.md +132 -0
  122. package/gsd-core/references/planning-config.md +2 -1
  123. package/gsd-core/references/reviewer-instances.md +28 -19
  124. package/gsd-core/references/runtime-aware-dispatch.md +42 -0
  125. package/gsd-core/references/skeleton-template.md +1 -1
  126. package/gsd-core/references/thinking-models-planning.md +3 -1
  127. package/gsd-core/references/ui-consideration-probe.md +2 -2
  128. package/gsd-core/references/worktree-branch-check.md +4 -4
  129. package/gsd-core/templates/DEBUG.md +5 -3
  130. package/gsd-core/templates/summary-minimal.md +4 -0
  131. package/gsd-core/templates/summary-standard.md +4 -0
  132. package/gsd-core/templates/summary.md +7 -0
  133. package/gsd-core/workflows/add-phase.md +2 -0
  134. package/gsd-core/workflows/add-tests.md +3 -1
  135. package/gsd-core/workflows/add-todo.md +32 -1
  136. package/gsd-core/workflows/ai-integration-phase.md +8 -6
  137. package/gsd-core/workflows/audit-fix.md +6 -2
  138. package/gsd-core/workflows/audit-milestone.md +8 -0
  139. package/gsd-core/workflows/autonomous.md +19 -15
  140. package/gsd-core/workflows/check-todos.md +5 -3
  141. package/gsd-core/workflows/cleanup.md +7 -1
  142. package/gsd-core/workflows/code-review-fix.md +14 -6
  143. package/gsd-core/workflows/code-review.md +93 -24
  144. package/gsd-core/workflows/complete-milestone.md +3 -0
  145. package/gsd-core/workflows/debug.md +35 -7
  146. package/gsd-core/workflows/diagnose-issues.md +5 -1
  147. package/gsd-core/workflows/discovery-phase.md +7 -0
  148. package/gsd-core/workflows/discuss-phase/modes/advisor.md +2 -4
  149. package/gsd-core/workflows/discuss-phase/modes/auto.md +0 -6
  150. package/gsd-core/workflows/discuss-phase/templates/context.md +16 -2
  151. package/gsd-core/workflows/discuss-phase-assumptions.md +18 -9
  152. package/gsd-core/workflows/discuss-phase.md +2 -2
  153. package/gsd-core/workflows/do.md +7 -1
  154. package/gsd-core/workflows/docs-update.md +9 -0
  155. package/gsd-core/workflows/eval-review.md +4 -1
  156. package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +4 -0
  157. package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +160 -0
  158. package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +4 -4
  159. package/gsd-core/workflows/execute-phase/steps/regression-gate.md +2 -2
  160. package/gsd-core/workflows/execute-phase.md +110 -149
  161. package/gsd-core/workflows/execute-plan.md +20 -8
  162. package/gsd-core/workflows/explore.md +4 -0
  163. package/gsd-core/workflows/extract-learnings.md +21 -0
  164. package/gsd-core/workflows/graduation.md +3 -0
  165. package/gsd-core/workflows/health.md +7 -1
  166. package/gsd-core/workflows/help/modes/full.md +9 -5
  167. package/gsd-core/workflows/import.md +11 -2
  168. package/gsd-core/workflows/inbox.md +7 -0
  169. package/gsd-core/workflows/ingest-docs.md +19 -10
  170. package/gsd-core/workflows/manager.md +3 -1
  171. package/gsd-core/workflows/map-codebase.md +17 -10
  172. package/gsd-core/workflows/mvp-phase.md +3 -0
  173. package/gsd-core/workflows/new-milestone.md +79 -23
  174. package/gsd-core/workflows/new-project.md +28 -19
  175. package/gsd-core/workflows/new-workspace.md +3 -1
  176. package/gsd-core/workflows/next.md +5 -2
  177. package/gsd-core/workflows/onboard.md +3 -0
  178. package/gsd-core/workflows/plan-phase.md +56 -51
  179. package/gsd-core/workflows/plan-review-convergence.md +61 -12
  180. package/gsd-core/workflows/plant-seed.md +3 -0
  181. package/gsd-core/workflows/profile-user.md +7 -1
  182. package/gsd-core/workflows/progress.md +31 -3
  183. package/gsd-core/workflows/quick.md +33 -10
  184. package/gsd-core/workflows/remove-workspace.md +3 -0
  185. package/gsd-core/workflows/review.md +172 -585
  186. package/gsd-core/workflows/scan.md +10 -2
  187. package/gsd-core/workflows/secure-phase.md +13 -2
  188. package/gsd-core/workflows/settings-integrations.md +3 -0
  189. package/gsd-core/workflows/settings.md +3 -0
  190. package/gsd-core/workflows/ship.md +88 -11
  191. package/gsd-core/workflows/sketch.md +3 -0
  192. package/gsd-core/workflows/smart-entry.md +4 -1
  193. package/gsd-core/workflows/spike.md +7 -1
  194. package/gsd-core/workflows/ui-phase.md +11 -2
  195. package/gsd-core/workflows/ui-review.md +11 -1
  196. package/gsd-core/workflows/undo.md +7 -0
  197. package/gsd-core/workflows/update.md +106 -5
  198. package/gsd-core/workflows/validate-phase.md +13 -2
  199. package/gsd-core/workflows/verify-phase.md +2 -2
  200. package/gsd-core/workflows/verify-work.md +15 -4
  201. package/hooks/dist/gsd-context-monitor.js +27 -9
  202. package/hooks/dist/gsd-cursor-session-start.js +6 -2
  203. package/hooks/dist/gsd-cursor-stop.js +6 -2
  204. package/hooks/dist/gsd-cursor-subagent-start.js +6 -2
  205. package/hooks/dist/gsd-graphify-update.sh +9 -0
  206. package/hooks/dist/gsd-phase-boundary.sh +14 -2
  207. package/hooks/dist/gsd-prompt-guard.js +101 -2
  208. package/hooks/dist/gsd-read-guard.js +100 -2
  209. package/hooks/dist/gsd-read-injection-scanner.js +109 -2
  210. package/hooks/dist/gsd-statusline.js +97 -9
  211. package/hooks/dist/gsd-workflow-guard.js +110 -6
  212. package/hooks/dist/gsd-worktree-path-guard.js +132 -8
  213. package/hooks/dist/lib/cursor-workspace.js +74 -0
  214. package/hooks/gsd-context-monitor.js +27 -9
  215. package/hooks/gsd-cursor-session-start.js +6 -2
  216. package/hooks/gsd-cursor-stop.js +6 -2
  217. package/hooks/gsd-cursor-subagent-start.js +6 -2
  218. package/hooks/gsd-graphify-update.sh +9 -0
  219. package/hooks/gsd-phase-boundary.sh +14 -2
  220. package/hooks/gsd-prompt-guard.js +101 -2
  221. package/hooks/gsd-read-guard.js +100 -2
  222. package/hooks/gsd-read-injection-scanner.js +109 -2
  223. package/hooks/gsd-statusline.js +97 -9
  224. package/hooks/gsd-workflow-guard.js +110 -6
  225. package/hooks/gsd-worktree-path-guard.js +132 -8
  226. package/hooks/lib/cursor-workspace.js +74 -0
  227. package/package.json +10 -8
  228. package/pi/gsd.cjs +34 -3
  229. package/scripts/changeset/lint.cjs +1 -0
  230. package/scripts/changeset/parse.cjs +26 -0
  231. package/scripts/check-coverage-gate.cjs +51 -0
  232. package/scripts/check-glossary-refs.cjs +244 -0
  233. package/scripts/ci-rebase-check.cjs +48 -4
  234. package/scripts/ci-test-scope.cjs +67 -17
  235. package/scripts/gen-adr-index.cjs +528 -0
  236. package/scripts/gen-capability-matrix.cjs +26 -2
  237. package/scripts/gen-capability-registry.cjs +132 -34
  238. package/scripts/gen-emitted-baseline.cjs +145 -0
  239. package/scripts/gen-test-timings.cjs +201 -0
  240. package/scripts/lint-compiled-artifact-sync.cjs +146 -0
  241. package/scripts/lint-emitted-drift-ack.cjs +149 -0
  242. package/scripts/lint-fix-has-regression-test.cjs +131 -0
  243. package/scripts/lint-portable-timeout.cjs +140 -0
  244. package/scripts/lint-resolution-provenance.cjs +9 -0
  245. package/scripts/lint-test-file-count.allowlist.json +1 -0
  246. package/scripts/mutation-matrix.cjs +4 -0
  247. package/scripts/prompt-injection-scan.sh +6 -0
  248. package/scripts/registry-schema.cjs +57 -8
  249. package/scripts/release-notes/conventional-title.cjs +19 -1
  250. package/scripts/release-notes/format-github-release-notes.cjs +7 -3
  251. package/scripts/release-tarball-smoke.cjs +18 -11
  252. package/scripts/run-tests.cjs +420 -58
  253. package/scripts/workflow-size.cjs +16 -8
  254. package/skills/gsd-ai-integration-phase/SKILL.md +1 -1
  255. package/skills/gsd-mempalace-capture/SKILL.md +9 -5
  256. package/skills/gsd-new-milestone/SKILL.md +1 -1
  257. package/skills/gsd-plan-phase/SKILL.md +5 -3
  258. package/skills/gsd-plan-review-convergence/SKILL.md +7 -2
  259. package/vscode/package.json +1 -1
  260. package/scripts/gen-golden-install-parity-zcode.cjs +0 -77
  261. package/scripts/update-size-baseline.cjs +0 -68
@@ -0,0 +1,244 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Verifies the machine-checkable claims in CONTEXT.md against the shipped
6
+ * tree, so the glossary cannot silently re-rot the way the ADR index did
7
+ * before scripts/gen-adr-index.cjs (#2340).
8
+ *
9
+ * Unlike gen-adr-index.cjs this gate has NO `--write` — CONTEXT.md's prose is
10
+ * hand-authored, not a derived artifact this tool can regenerate. It only
11
+ * verifies.
12
+ *
13
+ * Two checks:
14
+ *
15
+ * A. File references resolve. Every backticked token in CONTEXT.md that
16
+ * looks like a file path — and whose path is inside a TRACKED_PREFIXES
17
+ * directory (or is one of the two named exact files) — must exist on
18
+ * disk. Everything else (generated bin/lib/*.cjs, `.planning/` runtime
19
+ * artifacts, `~/`- or `/`-rooted paths, bare filenames, example data
20
+ * shapes like `capability.json`) is deliberately ignored: asserting
21
+ * those would false-fail a clean checkout, which is the exact trap this
22
+ * gate exists to avoid falling into itself.
23
+ *
24
+ * B. `allRuntimes` enum parity. CONTEXT.md documents the runtime enum's
25
+ * count and member list in prose (e.g. "Runtime enum: `allRuntimes` (17
26
+ * values: claude, ...)"). This is compared against the real
27
+ * `allRuntimes` array literal in bin/install.js — both the count and the
28
+ * member set — so adding/removing a runtime without updating the prose
29
+ * is caught.
30
+ *
31
+ * Usage:
32
+ * node scripts/check-glossary-refs.cjs # print findings to stdout
33
+ * node scripts/check-glossary-refs.cjs --check # exit 1 on any finding
34
+ */
35
+
36
+ const fs = require('node:fs');
37
+ const path = require('node:path');
38
+
39
+ const { ExitError, runMain } = require('./lib/cli-exit.cjs');
40
+
41
+ const ROOT = path.resolve(__dirname, '..');
42
+ const CONTEXT_PATH = path.join(ROOT, 'CONTEXT.md');
43
+ const INSTALL_JS_PATH = path.join(ROOT, 'bin', 'install.js');
44
+
45
+ /**
46
+ * Directory prefixes this gate can verify against the shipped tree. A token
47
+ * outside these — most importantly `gsd-core/bin/lib/**`, which is generated
48
+ * and gitignored — is not a claim this gate can check, so it is skipped
49
+ * rather than asserted.
50
+ */
51
+ const TRACKED_PREFIXES = [
52
+ 'src/',
53
+ 'tests/',
54
+ 'scripts/',
55
+ 'docs/',
56
+ 'gsd-core/references/',
57
+ 'gsd-core/workflows/',
58
+ 'gsd-core/templates/',
59
+ 'gsd-core/contexts/',
60
+ '.github/',
61
+ 'eslint-rules/',
62
+ ];
63
+
64
+ /** The only bare (no-prefix-match) tokens this gate checks by exact name. */
65
+ const TRACKED_EXACT = new Set(['bin/install.js', 'package.json']);
66
+
67
+ /**
68
+ * Paths CONTEXT.md documents whose ABSENCE is the healthy steady state (#2778).
69
+ *
70
+ * `TRACKED_PREFIXES` skips claims this gate *cannot* check. This is the narrower
71
+ * third case: a claim it must not check, because "does not exist" is the correct
72
+ * state rather than drift.
73
+ *
74
+ * `tests/emitted-drift-ack.json` is the acknowledgment file from ADR-2719 §3. Its
75
+ * whole design property is that it appears in the changed-files list ONLY when
76
+ * something rippled unexpectedly — "touching it IS the alarm". A permanently
77
+ * committed copy would signal nothing, which is exactly why the ADR rejected
78
+ * shipping an empty stub. So the file is absent on a healthy `next` and present
79
+ * only inside a PR that needs it, and asserting either way is wrong.
80
+ *
81
+ * Until #2778 this passed only by accident: CONTEXT.md's `RULESET.` entries are
82
+ * themselves backtick-wrapped and contain backticks, so the sequential pairing in
83
+ * `extractTrackedRefs` happened to leave this token outside a code span. Any edit
84
+ * that shifted the parity — such as #2778's own — exposed it. A gate that passes
85
+ * by luck is not passing; naming the exemption makes the intent explicit and
86
+ * survives the next edit.
87
+ */
88
+ const INTENTIONALLY_ABSENT = new Set(['tests/emitted-drift-ack.json']);
89
+
90
+ /**
91
+ * Shape a backticked token must have to even be considered a path candidate:
92
+ * one or more `/`-separated segments of word/dot/dash characters, with an
93
+ * optional trailing `:<line>` suffix. Anything else inside backticks (CLI
94
+ * invocations with spaces, function signatures with parens/commas, bare
95
+ * identifiers, env vars) is prose, not a path reference.
96
+ */
97
+ const PATH_TOKEN_RE = /^[\w.-]+(?:\/[\w.-]+)*(?::\d+)?$/;
98
+
99
+ /** Whether `token` (line-suffix already stripped) is one this gate checks. */
100
+ function isTracked(token) {
101
+ if (INTENTIONALLY_ABSENT.has(token)) return false;
102
+ return TRACKED_EXACT.has(token) || TRACKED_PREFIXES.some((prefix) => token.startsWith(prefix));
103
+ }
104
+
105
+ /**
106
+ * True if joining `token` to ROOT stays inside ROOT. `PATH_TOKEN_RE` admits `.`
107
+ * inside a segment, so a token like `src/../../../etc/passwd` matches and (via
108
+ * the `src/` prefix) reads as "tracked" — `path.join(ROOT, token)` would then
109
+ * normalize to an out-of-tree absolute path and `fs.existsSync` would probe it,
110
+ * turning a doc lint into a filesystem-existence oracle on the CI host. A
111
+ * CONTEXT.md reference is always a plain in-repo path, so a `..` escape is never
112
+ * legitimate: confine to ROOT and drop anything that climbs out.
113
+ */
114
+ function isWithinRoot(token) {
115
+ const resolved = path.resolve(ROOT, token);
116
+ return resolved === ROOT || resolved.startsWith(ROOT + path.sep);
117
+ }
118
+
119
+ /**
120
+ * Every distinct, trackable file-path token referenced in `text`, with any
121
+ * trailing `:<line>` suffix stripped.
122
+ */
123
+ function extractTrackedRefs(text) {
124
+ const tokens = new Set();
125
+ const re = /`([^`]+)`/g;
126
+ let m;
127
+ while ((m = re.exec(text)) !== null) {
128
+ const raw = m[1];
129
+ if (!PATH_TOKEN_RE.test(raw)) continue;
130
+ const token = raw.replace(/:\d+$/, '');
131
+ if (!isTracked(token)) continue;
132
+ if (!isWithinRoot(token)) continue;
133
+ tokens.add(token);
134
+ }
135
+ return tokens;
136
+ }
137
+
138
+ /** Check A: every tracked reference must resolve on disk. */
139
+ function checkFileRefs(contextText) {
140
+ const tokens = [...extractTrackedRefs(contextText)].sort();
141
+ const findings = [];
142
+ for (const token of tokens) {
143
+ if (!fs.existsSync(path.join(ROOT, token))) {
144
+ findings.push(`CONTEXT.md references \`${token}\` which does not exist in the repo.`);
145
+ }
146
+ }
147
+ return { findings, checked: tokens.length };
148
+ }
149
+
150
+ /** The glossary's own claim: `Runtime enum: `allRuntimes` (N values: a, b, c)`. */
151
+ const ALLRUNTIMES_CLAIM_RE = /Runtime enum:\s*`allRuntimes`\s*\((\d+)\s*values:\s*([^)]*)\)/;
152
+
153
+ function parseClaimedRuntimes(contextText) {
154
+ const m = contextText.match(ALLRUNTIMES_CLAIM_RE);
155
+ if (!m) return null;
156
+ return {
157
+ count: Number(m[1]),
158
+ members: m[2]
159
+ .split(',')
160
+ .map((s) => s.trim())
161
+ .filter(Boolean),
162
+ };
163
+ }
164
+
165
+ /** The real `allRuntimes = [...]` array literal in bin/install.js. */
166
+ const ALLRUNTIMES_ARRAY_RE = /allRuntimes\s*=\s*\[([^\]]*)\]/;
167
+
168
+ function parseRealRuntimes(installJsText) {
169
+ const m = installJsText.match(ALLRUNTIMES_ARRAY_RE);
170
+ if (!m) return null;
171
+ return [...m[1].matchAll(/'([^']+)'/g)].map((mm) => mm[1]);
172
+ }
173
+
174
+ /** Check B: CONTEXT.md's prose count + member set must match bin/install.js. */
175
+ function checkAllRuntimesParity(contextText, installJsText) {
176
+ const claimed = parseClaimedRuntimes(contextText);
177
+ if (!claimed) {
178
+ return [
179
+ 'CONTEXT.md is missing the `allRuntimes` enum-count sentence ' +
180
+ '("Runtime enum: `allRuntimes` (N values: ...)") that this gate checks against bin/install.js.',
181
+ ];
182
+ }
183
+
184
+ const real = parseRealRuntimes(installJsText);
185
+ if (!real) {
186
+ return ['bin/install.js does not contain a parseable `allRuntimes = [...]` array literal.'];
187
+ }
188
+
189
+ const findings = [];
190
+ if (claimed.count !== real.length) {
191
+ findings.push(
192
+ `CONTEXT.md's allRuntimes enum-count sentence claims ${claimed.count} values but bin/install.js's ` +
193
+ `allRuntimes array has ${real.length}.`,
194
+ );
195
+ }
196
+
197
+ const claimedSet = new Set(claimed.members);
198
+ const realSet = new Set(real);
199
+ const missingFromProse = real.filter((r) => !claimedSet.has(r)).sort();
200
+ const noLongerReal = claimed.members.filter((c) => !realSet.has(c)).sort();
201
+ if (missingFromProse.length > 0 || noLongerReal.length > 0) {
202
+ const parts = [];
203
+ if (missingFromProse.length > 0) parts.push(`missing from CONTEXT.md's list: ${missingFromProse.join(', ')}`);
204
+ if (noLongerReal.length > 0) parts.push(`no longer in bin/install.js's allRuntimes: ${noLongerReal.join(', ')}`);
205
+ findings.push(`CONTEXT.md's allRuntimes member list has drifted from bin/install.js (${parts.join('; ')}).`);
206
+ }
207
+
208
+ return findings;
209
+ }
210
+
211
+ function main() {
212
+ const [, , flag] = process.argv;
213
+
214
+ const contextText = fs.readFileSync(CONTEXT_PATH, 'utf8');
215
+ const installJsText = fs.readFileSync(INSTALL_JS_PATH, 'utf8');
216
+
217
+ const fileRefs = checkFileRefs(contextText);
218
+ const runtimeFindings = checkAllRuntimesParity(contextText, installJsText);
219
+ const findings = [...fileRefs.findings, ...runtimeFindings];
220
+
221
+ if (flag === '--check') {
222
+ if (findings.length > 0) {
223
+ process.stderr.write(`CONTEXT.md glossary has ${findings.length} drift finding(s).\n\n`);
224
+ for (const f of findings) process.stderr.write(` ✗ ${f}\n`);
225
+ process.stderr.write('\n');
226
+ throw new ExitError(1);
227
+ }
228
+ process.stdout.write(
229
+ `CONTEXT.md glossary references are current (${fileRefs.checked} refs checked, allRuntimes parity ok).\n`,
230
+ );
231
+ return;
232
+ }
233
+
234
+ if (findings.length === 0) {
235
+ process.stdout.write(
236
+ `CONTEXT.md glossary references are current (${fileRefs.checked} refs checked, allRuntimes parity ok).\n`,
237
+ );
238
+ } else {
239
+ process.stdout.write(`CONTEXT.md glossary has ${findings.length} drift finding(s):\n\n`);
240
+ for (const f of findings) process.stdout.write(` ✗ ${f}\n`);
241
+ }
242
+ }
243
+
244
+ runMain(main);
@@ -8,6 +8,22 @@
8
8
  // GITHUB_BASE_REF — PR base branch name (set by GitHub Actions on pull_request events)
9
9
  // GITHUB_REPOSITORY — owner/repo (set by GitHub Actions)
10
10
  //
11
+ // Optional:
12
+ // CI_REBASE_BASE_SHA — pin the merge to one exact base commit (#2472).
13
+ //
14
+ // Why the pin matters. Every job of a run executes this step independently, at
15
+ // whatever wall-clock moment it gets there — and Windows/macOS installs skew
16
+ // that by minutes across a 12-job matrix. Merging the moving `origin/<branch>`
17
+ // ref means that if the base advances mid-run, different jobs merge different
18
+ // trees. That was survivable when jobs only had to agree on pass/fail, but the
19
+ // sharded lane makes them agree on a PARTITION: each shard job computes the
20
+ // whole split and keeps its own slice, so jobs working from different trees can
21
+ // place a file in two shards or in none. Each job still looks internally
22
+ // consistent, so nothing errors — a test silently never runs and CI stays
23
+ // green. Pinning every job to `github.event.pull_request.base.sha`, which is
24
+ // fixed for the life of the run, removes the divergence at its source rather
25
+ // than detecting it after the fact.
26
+ //
11
27
  // Exit 0 = merged cleanly (or merge was a no-op).
12
28
  // Exit 1 = merge conflict or fetch failure.
13
29
 
@@ -35,6 +51,28 @@ function runOrThrow(cmd, args, label) {
35
51
  const token = process.env.GITHUB_TOKEN || '';
36
52
  const baseBranch = process.env.GITHUB_BASE_REF || 'main';
37
53
  const repo = process.env.GITHUB_REPOSITORY || '';
54
+ // Resolve what to fetch and what to merge, pinned together so they can never
55
+ // disagree. Pure and exported so the pin contract is testable without spawning
56
+ // git: env in, refs out.
57
+ //
58
+ // Only a full 40-hex sha is accepted. Anything else — empty on push/dispatch
59
+ // events, or a malformed/injected value — falls back to the branch ref,
60
+ // preserving the pre-#2472 behavior rather than handing an arbitrary string to
61
+ // `git fetch` as a refspec.
62
+ function resolveBaseRefs(env = process.env, fallbackBranch = 'main') {
63
+ const branch = env.GITHUB_BASE_REF || fallbackBranch;
64
+ const raw = env.CI_REBASE_BASE_SHA || '';
65
+ const sha = /^[0-9a-f]{40}$/.test(raw) ? raw : null;
66
+ return {
67
+ branch,
68
+ sha,
69
+ pinned: sha !== null,
70
+ fetchRef: sha || branch,
71
+ mergeRef: sha || `origin/${branch}`,
72
+ };
73
+ }
74
+
75
+ const { fetchRef, mergeRef } = resolveBaseRefs(process.env, 'main');
38
76
 
39
77
  function main() {
40
78
  // Configure git identity (needed for merge commit).
@@ -52,12 +90,12 @@ function main() {
52
90
 
53
91
  // Fetch base branch with retry.
54
92
  for (let attempt = 1; attempt <= 3; attempt++) {
55
- const result = run('git', ['fetch', 'origin', baseBranch]);
93
+ const result = run('git', ['fetch', 'origin', fetchRef]);
56
94
  if (result) {
57
95
  break;
58
96
  }
59
97
  if (attempt === 3) {
60
- throw new ExitError(1, `::error::git fetch origin ${baseBranch} failed after 3 attempts.`);
98
+ throw new ExitError(1, `::error::git fetch origin ${fetchRef} failed after 3 attempts.`);
61
99
  }
62
100
  // Wait before retry: attempt * 4 seconds.
63
101
  const waitMs = attempt * 4000;
@@ -67,7 +105,7 @@ function main() {
67
105
 
68
106
  // Attempt merge.
69
107
  try {
70
- execFileSync('git', ['merge', '--no-edit', '--no-ff', `origin/${baseBranch}`], { stdio: 'inherit' });
108
+ execFileSync('git', ['merge', '--no-edit', '--no-ff', mergeRef], { stdio: 'inherit' });
71
109
  } catch (e) {
72
110
  process.stderr.write(
73
111
  `::error::This PR cannot cleanly merge origin/${baseBranch}. Rebase your branch onto current ${baseBranch} and push again.\n`
@@ -83,4 +121,10 @@ function main() {
83
121
  }
84
122
  }
85
123
 
86
- runMain(main);
124
+ // Only run when invoked as the CI step. Guarded so a test can require this
125
+ // module for resolveBaseRefs without firing git fetch/merge as a side effect.
126
+ if (require.main === module) {
127
+ runMain(main);
128
+ }
129
+
130
+ module.exports = { resolveBaseRefs };
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ const path = require('path');
4
5
  const { execFileSync } = require('child_process');
5
6
  const { existsSync, readdirSync, appendFileSync } = require('fs');
6
7
 
@@ -105,9 +106,8 @@ const RULES = [
105
106
  fullMatrix: true,
106
107
  tests: [
107
108
  'tests/check-env.test.cjs',
108
- 'tests/npm-integrity-gate.test.cjs',
109
+ 'tests/npm-integrity-gate.test.cjs', // #2758: absorbs the former tests/bug-3588-npm-audit-clean.test.cjs (folded into it by consolidation epic #1969 B6 #1975; the stale filename here was a silent coverage hole this rule never actually re-selected)
109
110
  'tests/package-manifest.test.cjs',
110
- 'tests/bug-3588-npm-audit-clean.test.cjs',
111
111
  ],
112
112
  },
113
113
  {
@@ -116,9 +116,9 @@ const RULES = [
116
116
  // still trigger the migrated module's tests (otherwise CI silently skips them).
117
117
  match: path => path.startsWith('src/') || path === 'tsconfig.build.json',
118
118
  tests: [
119
- 'tests/semver-compare.test.cjs',
120
- 'tests/bug-10-semver-policy-consolidation.test.cjs',
121
- 'tests/golden-install-parity.test.cjs', // any src/installer change can alter emitted install artifacts → re-verify golden install parity (drift guard)
119
+ 'tests/semver-compare.test.cjs', // #2758: absorbs the former tests/bug-10-semver-policy-consolidation.test.cjs (folded into it by consolidation epic #1969 B3 #1972; the stale filename here was a silent coverage hole this rule never actually re-selected)
120
+ 'tests/emitted-provenance.test.cjs', // any src/installer change can alter emitted install artifacts → re-verify provenance totality (#2724: golden-install-parity retired, this is the sole gate)
121
+ 'tests/emitted-attribution.test.cjs',
122
122
  ],
123
123
  },
124
124
  {
@@ -142,19 +142,23 @@ const RULES = [
142
142
  // SCOPED_LANE_EXCLUDE guard below, which also drops it when it is itself a
143
143
  // changed test file.
144
144
  'tests/runtime-artifact-layout.test.cjs',
145
- 'tests/golden-install-parity.test.cjs', // any src/installer change can alter emitted install artifacts → re-verify golden install parity (drift guard)
145
+ 'tests/emitted-provenance.test.cjs', // any src/installer change can alter emitted install artifacts → re-verify provenance totality (#2724: golden-install-parity retired, this is the sole gate)
146
+ 'tests/emitted-attribution.test.cjs',
146
147
  ],
147
148
  },
148
149
  {
149
- name: 'shipped install content (golden-parity drift guard, #2267)',
150
+ name: 'shipped install content (emitted-attribution drift guard, #2267/#2724)',
150
151
  // Every source file the installer EMITS into a runtime layout is captured by
151
- // golden-install-parity + the install-tree snapshot. A source edit here that
152
- // changes emitted output MUST re-verify the fixtures — otherwise stale golden
153
- // fixtures merge silently (#2266: a hooks/gsd-statusline.js edit changed
154
- // installed output but no rule selected golden-parity, so stale fixtures
155
- // shipped to next undetected). Union semantics: this ADDS the parity guard on
156
- // top of each path's existing content-specific tests. Targeted lane only (the
157
- // golden test skips win32 by design), no fullMatrix.
152
+ // the emitted-attribution differential + the install-tree snapshot. A source
153
+ // edit here that changes emitted output MUST re-verify (#2266: a
154
+ // hooks/gsd-statusline.js edit changed installed output but no rule selected
155
+ // the drift guard, so a stale emitted state shipped to next undetected).
156
+ // Union semantics: this ADDS the drift guard on top of each path's existing
157
+ // content-specific tests. Targeted lane only (the real-tree test skips win32
158
+ // by design), no fullMatrix.
159
+ // #2724: golden-install-parity.test.cjs is retired (ADR-2719 Phase 4); the
160
+ // emitted differential (ADR-2719 Phase 2/3) is now the sole gate for a PR
161
+ // editing only shipped content, the archetypal emitted-ripple case.
158
162
  // NOTE: intentionally NOT a blanket 'gsd-core/' prefix, for two reasons:
159
163
  // (1) gsd-core/bin/** is tsc-compiled runtime output — EXCLUDED_PREFIXES-
160
164
  // excluded from both manifests, and already covered by the 'installer and
@@ -172,8 +176,9 @@ const RULES = [
172
176
  (path.startsWith('gsd-core/bin/shared/') && path.endsWith('.json')) ||
173
177
  ['scripts/fix-slash-commands.cjs', 'scripts/gen-capability-registry.cjs', 'scripts/gen-loop-host-contract.cjs'].includes(path),
174
178
  tests: [
175
- 'tests/golden-install-parity.test.cjs',
176
179
  'tests/golden-install-tree.test.cjs',
180
+ 'tests/emitted-provenance.test.cjs',
181
+ 'tests/emitted-attribution.test.cjs',
177
182
  ],
178
183
  },
179
184
  {
@@ -236,7 +241,13 @@ const RULES = [
236
241
  'tests/workflow-size-budget.test.cjs',
237
242
  'tests/workflow-guard-registration.test.cjs',
238
243
  'tests/commands.test.cjs',
239
- 'tests/bug-3683-workflow-colon-namespace-leak.test.cjs',
244
+ // #2758: was 'tests/bug-3683-workflow-colon-namespace-leak.test.cjs', deleted by
245
+ // consolidation epic #1969 (B6 #1975) and folded into slash-command-namespace.test.cjs
246
+ // ("folded:bug-3683-workflow-colon-namespace-leak" describe block). The stale filename
247
+ // here was itself an instance of this issue's defect class — silently dropped by
248
+ // existingTests() below, so gsd-core/workflows/ changes stopped re-running this
249
+ // regression's coverage with nothing signaling it.
250
+ 'tests/slash-command-namespace.test.cjs',
240
251
  ],
241
252
  },
242
253
  {
@@ -291,6 +302,41 @@ const RULES = [
291
302
  },
292
303
  ];
293
304
 
305
+ /**
306
+ * Every RULES[].tests entry (deduped, across every rule) that does NOT exist on
307
+ * disk. #2758: a rule naming a test file that no longer exists is not merely
308
+ * inert — existingTests() below silently drops it out of targeted_tests, with
309
+ * nothing in the CI output signaling why. Phase 4 (#2724) deletes
310
+ * tests/golden-install-parity.test.cjs; without this check, any rule still
311
+ * naming it would stop selecting the guard entirely and CI would stay green
312
+ * throughout. Pure and independent of which rule / which file: it catches ANY
313
+ * phantom entry, not only the two names this issue is about.
314
+ * Paths resolve relative to the repo root (this file's parent directory), not
315
+ * the caller's cwd, so the check behaves identically whether invoked as the CLI
316
+ * (`node scripts/ci-test-scope.cjs ...`, cwd == repo root by convention) or
317
+ * required directly by a test.
318
+ */
319
+ function missingRuleTestFiles(rules) {
320
+ const referenced = new Set();
321
+ for (const rule of rules) {
322
+ for (const f of rule.tests) referenced.add(f);
323
+ }
324
+ return [...referenced].filter(f => !existsSync(path.join(__dirname, '..', f))).sort();
325
+ }
326
+
327
+ // Fail loudly at module load, mirroring the PROTECTED_WORKFLOWS check above —
328
+ // this fires on EVERY invocation of the CLI (including the real `changes` job
329
+ // in .github/workflows/test.yml), not only when a test suite happens to run.
330
+ {
331
+ const missing = missingRuleTestFiles(RULES);
332
+ if (missing.length > 0) {
333
+ throw new Error(
334
+ `ci-test-scope: RULES reference test file(s) that do not exist on disk ` +
335
+ `(silent coverage hole — see #2758):\n ${missing.join('\n ')}`,
336
+ );
337
+ }
338
+ }
339
+
294
340
  function usage() {
295
341
  return [
296
342
  'Usage:',
@@ -523,4 +569,8 @@ function main() {
523
569
  }
524
570
  }
525
571
 
526
- runMain(main);
572
+ if (require.main === module) {
573
+ runMain(main);
574
+ }
575
+
576
+ module.exports = { RULES, missingRuleTestFiles };