@opengsd/gsd-core 1.8.0 → 1.9.1

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 (177) 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 +31 -1
  4. package/agents/gsd-code-fixer.md +107 -34
  5. package/agents/gsd-codebase-mapper.md +1 -1
  6. package/agents/gsd-debug-session-manager.md +36 -0
  7. package/agents/gsd-executor.md +20 -7
  8. package/agents/gsd-intel-updater.md +3 -3
  9. package/agents/gsd-phase-researcher.md +4 -2
  10. package/agents/gsd-plan-checker.md +20 -0
  11. package/agents/gsd-planner.md +15 -23
  12. package/agents/gsd-project-researcher.md +2 -2
  13. package/agents/gsd-ui-auditor.md +0 -40
  14. package/bin/install.js +236 -107
  15. package/commands/gsd/plan-review-convergence.md +5 -1
  16. package/gsd-core/bin/gsd-tools.cjs +882 -4
  17. package/gsd-core/bin/lib/api-coverage.cjs +22 -8
  18. package/gsd-core/bin/lib/audit.cjs +8 -8
  19. package/gsd-core/bin/lib/capability-consent.cjs +40 -1
  20. package/gsd-core/bin/lib/capability-lifecycle.cjs +58 -0
  21. package/gsd-core/bin/lib/capability-loader.cjs +23 -1
  22. package/gsd-core/bin/lib/capability-registry.cjs +1353 -132
  23. package/gsd-core/bin/lib/capability-trust.cjs +468 -33
  24. package/gsd-core/bin/lib/capability-validator.cjs +882 -6
  25. package/gsd-core/bin/lib/check-command-router.cjs +12 -2
  26. package/gsd-core/bin/lib/cjs-command-router-adapter.cjs +15 -0
  27. package/gsd-core/bin/lib/claude-orchestration-command-router.cjs +102 -12
  28. package/gsd-core/bin/lib/claude-orchestration.cjs +125 -22
  29. package/gsd-core/bin/lib/commands.cjs +246 -18
  30. package/gsd-core/bin/lib/config-loader.cjs +200 -28
  31. package/gsd-core/bin/lib/config.cjs +90 -5
  32. package/gsd-core/bin/lib/estimate-cli.cjs +336 -0
  33. package/gsd-core/bin/lib/frontmatter.cjs +125 -15
  34. package/gsd-core/bin/lib/host-integration.cjs +215 -8
  35. package/gsd-core/bin/lib/init.cjs +44 -19
  36. package/gsd-core/bin/lib/install-engine.cjs +1 -0
  37. package/gsd-core/bin/lib/milestone.cjs +36 -9
  38. package/gsd-core/bin/lib/model-catalog.cjs +51 -1
  39. package/gsd-core/bin/lib/observability/logger.cjs +7 -2
  40. package/gsd-core/bin/lib/phase-command-router.cjs +10 -1
  41. package/gsd-core/bin/lib/phase-estimation.cjs +398 -0
  42. package/gsd-core/bin/lib/phase-id.cjs +278 -5
  43. package/gsd-core/bin/lib/phase.cjs +61 -6
  44. package/gsd-core/bin/lib/plan-drift-guard.cjs +1 -1
  45. package/gsd-core/bin/lib/plan-scan.cjs +1 -1
  46. package/gsd-core/bin/lib/planning-workspace.cjs +9 -2
  47. package/gsd-core/bin/lib/profile-output.cjs +34 -8
  48. package/gsd-core/bin/lib/project-root.cjs +48 -0
  49. package/gsd-core/bin/lib/review-lane-descriptor.cjs +927 -0
  50. package/gsd-core/bin/lib/review-lane-invocation.cjs +348 -0
  51. package/gsd-core/bin/lib/review-lane-runner.cjs +594 -0
  52. package/gsd-core/bin/lib/review-reviewer-selection.cjs +114 -32
  53. package/gsd-core/bin/lib/roadmap-parser.cjs +54 -6
  54. package/gsd-core/bin/lib/roadmap.cjs +10 -4
  55. package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +31 -4
  56. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +1 -1
  57. package/gsd-core/bin/lib/runtime-hooks-surface.cjs +140 -0
  58. package/gsd-core/bin/lib/runtime-name-policy.cjs +15 -2
  59. package/gsd-core/bin/lib/smart-entry.cjs +1 -1
  60. package/gsd-core/bin/lib/state-document.cjs +164 -20
  61. package/gsd-core/bin/lib/state-transition.cjs +28 -10
  62. package/gsd-core/bin/lib/state.cjs +141 -21
  63. package/gsd-core/bin/lib/uat-predicate.cjs +6 -4
  64. package/gsd-core/bin/lib/uat.cjs +9 -7
  65. package/gsd-core/bin/lib/ui-consideration-probe.cjs +2 -2
  66. package/gsd-core/bin/lib/unusable-input.cjs +216 -0
  67. package/gsd-core/bin/lib/validate.cjs +32 -0
  68. package/gsd-core/bin/lib/verification.cjs +51 -14
  69. package/gsd-core/bin/lib/verify.cjs +146 -22
  70. package/gsd-core/bin/lib/worktree-safety.cjs +360 -15
  71. package/gsd-core/bin/shared/config-defaults.manifest.json +1 -0
  72. package/gsd-core/bin/shared/config-schema.manifest.json +1 -13
  73. package/gsd-core/bin/shared/model-catalog.json +5 -0
  74. package/gsd-core/bin/shared/runtime-aliases.manifest.json +5 -0
  75. package/gsd-core/references/context-budget.md +40 -0
  76. package/gsd-core/references/gate-prompts.md +6 -3
  77. package/gsd-core/references/model-profile-resolution.md +64 -13
  78. package/gsd-core/references/offer-next.md +88 -0
  79. package/gsd-core/references/planning-config.md +2 -1
  80. package/gsd-core/references/reviewer-instances.md +28 -21
  81. package/gsd-core/references/runtime-aware-dispatch.md +42 -0
  82. package/gsd-core/references/ui-consideration-probe.md +2 -2
  83. package/gsd-core/references/worktree-branch-check.md +4 -4
  84. package/gsd-core/templates/summary-minimal.md +4 -0
  85. package/gsd-core/templates/summary-standard.md +4 -0
  86. package/gsd-core/templates/summary.md +7 -0
  87. package/gsd-core/workflows/ai-integration-phase.md +4 -4
  88. package/gsd-core/workflows/audit-fix.md +4 -0
  89. package/gsd-core/workflows/audit-milestone.md +8 -0
  90. package/gsd-core/workflows/autonomous.md +19 -15
  91. package/gsd-core/workflows/check-todos.md +2 -2
  92. package/gsd-core/workflows/code-review-fix.md +14 -6
  93. package/gsd-core/workflows/code-review.md +93 -21
  94. package/gsd-core/workflows/debug.md +10 -2
  95. package/gsd-core/workflows/diagnose-issues.md +4 -0
  96. package/gsd-core/workflows/discuss-phase/modes/advisor.md +2 -4
  97. package/gsd-core/workflows/discuss-phase/modes/auto.md +0 -6
  98. package/gsd-core/workflows/discuss-phase-assumptions.md +15 -9
  99. package/gsd-core/workflows/discuss-phase.md +2 -2
  100. package/gsd-core/workflows/docs-update.md +8 -0
  101. package/gsd-core/workflows/eval-review.md +1 -1
  102. package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +4 -0
  103. package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +160 -0
  104. package/gsd-core/workflows/execute-phase.md +85 -115
  105. package/gsd-core/workflows/execute-plan.md +5 -4
  106. package/gsd-core/workflows/explore.md +4 -0
  107. package/gsd-core/workflows/extract-learnings.md +21 -0
  108. package/gsd-core/workflows/help/modes/full.md +3 -3
  109. package/gsd-core/workflows/import.md +4 -1
  110. package/gsd-core/workflows/ingest-docs.md +4 -0
  111. package/gsd-core/workflows/map-codebase.md +13 -6
  112. package/gsd-core/workflows/new-milestone.md +10 -2
  113. package/gsd-core/workflows/new-project.md +11 -4
  114. package/gsd-core/workflows/next.md +5 -2
  115. package/gsd-core/workflows/plan-phase.md +42 -46
  116. package/gsd-core/workflows/plan-review-convergence.md +18 -14
  117. package/gsd-core/workflows/progress.md +1 -1
  118. package/gsd-core/workflows/quick.md +14 -3
  119. package/gsd-core/workflows/review.md +146 -575
  120. package/gsd-core/workflows/scan.md +9 -1
  121. package/gsd-core/workflows/secure-phase.md +10 -2
  122. package/gsd-core/workflows/ship.md +41 -11
  123. package/gsd-core/workflows/smart-entry.md +1 -1
  124. package/gsd-core/workflows/ui-phase.md +8 -1
  125. package/gsd-core/workflows/ui-review.md +8 -1
  126. package/gsd-core/workflows/update.md +104 -5
  127. package/gsd-core/workflows/validate-phase.md +10 -2
  128. package/gsd-core/workflows/verify-work.md +8 -1
  129. package/hooks/dist/gsd-cursor-session-start.js +6 -2
  130. package/hooks/dist/gsd-cursor-stop.js +6 -2
  131. package/hooks/dist/gsd-cursor-subagent-start.js +6 -2
  132. package/hooks/dist/gsd-graphify-update.sh +9 -0
  133. package/hooks/dist/gsd-phase-boundary.sh +14 -2
  134. package/hooks/dist/gsd-prompt-guard.js +101 -2
  135. package/hooks/dist/gsd-read-guard.js +100 -2
  136. package/hooks/dist/gsd-read-injection-scanner.js +109 -2
  137. package/hooks/dist/gsd-statusline.js +9 -6
  138. package/hooks/dist/gsd-workflow-guard.js +110 -6
  139. package/hooks/dist/gsd-worktree-path-guard.js +132 -8
  140. package/hooks/dist/lib/cursor-workspace.js +74 -0
  141. package/hooks/gsd-cursor-session-start.js +6 -2
  142. package/hooks/gsd-cursor-stop.js +6 -2
  143. package/hooks/gsd-cursor-subagent-start.js +6 -2
  144. package/hooks/gsd-graphify-update.sh +9 -0
  145. package/hooks/gsd-phase-boundary.sh +14 -2
  146. package/hooks/gsd-prompt-guard.js +101 -2
  147. package/hooks/gsd-read-guard.js +100 -2
  148. package/hooks/gsd-read-injection-scanner.js +109 -2
  149. package/hooks/gsd-statusline.js +9 -6
  150. package/hooks/gsd-workflow-guard.js +110 -6
  151. package/hooks/gsd-worktree-path-guard.js +132 -8
  152. package/hooks/lib/cursor-workspace.js +74 -0
  153. package/package.json +7 -7
  154. package/pi/gsd.cjs +26 -1
  155. package/scripts/check-coverage-gate.cjs +51 -0
  156. package/scripts/check-glossary-refs.cjs +24 -0
  157. package/scripts/ci-test-scope.cjs +67 -17
  158. package/scripts/gen-adr-index.cjs +6 -4
  159. package/scripts/gen-capability-matrix.cjs +26 -2
  160. package/scripts/gen-capability-registry.cjs +132 -34
  161. package/scripts/gen-emitted-baseline.cjs +145 -0
  162. package/scripts/gen-registry.cjs +39 -15
  163. package/scripts/lint-compiled-artifact-sync.cjs +146 -0
  164. package/scripts/lint-emitted-drift-ack.cjs +149 -0
  165. package/scripts/lint-fix-has-regression-test.cjs +131 -0
  166. package/scripts/lint-resolution-provenance.cjs +9 -0
  167. package/scripts/mutation-matrix.cjs +4 -0
  168. package/scripts/prompt-injection-scan.sh +6 -0
  169. package/scripts/registry-schema.cjs +372 -94
  170. package/scripts/release-notes/conventional-title.cjs +19 -1
  171. package/scripts/release-notes/format-github-release-notes.cjs +7 -3
  172. package/scripts/validate-registry.cjs +10 -6
  173. package/scripts/workflow-size.cjs +16 -8
  174. package/skills/gsd-plan-review-convergence/SKILL.md +5 -1
  175. package/vscode/package.json +1 -1
  176. package/scripts/gen-golden-install-parity-zcode.cjs +0 -77
  177. package/scripts/update-size-baseline.cjs +0 -68
@@ -0,0 +1,927 @@
1
+ "use strict";
2
+ /**
3
+ * Reviewer Lane Descriptor Module (ADR-2782 Phase 1, #2794 — closes #2690).
4
+ *
5
+ * ONE place where the cross-AI reviewer lane contract is declared as data.
6
+ *
7
+ * Before this module the contract lived in three unrelated surfaces: the roster
8
+ * in `review-reviewer-selection.cts`, ~640 lines of hand-authored per-CLI bash in
9
+ * `gsd-core/workflows/review.md` `invoke_reviewers`, and the hardcoded section
10
+ * headings in `write_reviews`. A cross-cutting fix therefore landed per-leg —
11
+ * #2494 and #2605 were the same empty-output defect filed twice, and #2475 /
12
+ * #2295 / #2272 are the same shape.
13
+ *
14
+ * SCOPE (ADR-2782's phase table). This module DECLARES; it does not execute.
15
+ * `invoke_reviewers` still runs hand-authored legs until Phase 5b (#2799) makes
16
+ * it iterate. What Phase 1 buys is that a leg can no longer be added, removed,
17
+ * or renamed without the table and the REVIEWS.md section moving with it —
18
+ * `checkReviewerLaneParity` below is the `DEFECT.GENERATIVE-FIX` assertion
19
+ * (`CONTEXT.md:797`) that the roster has never had.
20
+ *
21
+ * The descriptor deliberately does NOT promise uniformity. Lane divergence is
22
+ * real and frequently correct (measured timeout floors differ; three lanes are
23
+ * HTTP endpoints with no binary; Antigravity needs a three-layer fallback for an
24
+ * upstream stdout bug). The value is one place where divergence is DECLARED.
25
+ * Behaviour that data cannot express is delegated to a named `handler`
26
+ * (ADR-2782 D6 closed enum) — never to conditionals inside the table.
27
+ *
28
+ * Field names, nesting, and enum members track ADR-2782 D1/D2/D6/D7 so Phase 2
29
+ * (#2795) harvests this shape into the capability manifest without a translation
30
+ * layer — INCLUDING `transport`'s placement at the lane level (see SpawnLane).
31
+ *
32
+ * Building this table against all eleven shipped legs surfaced four cases the
33
+ * ADR's original survey did not cover. Rather than diverge silently — which is
34
+ * exactly the translation layer this module exists to avoid — ADR-2782 was
35
+ * AMENDED in the same PR (see its Amendments section, 2026-07-29). All four are
36
+ * additive widenings of closed enums, each forced by a lane that exists today:
37
+ *
38
+ * 1. `promptChannel: 'none'` — CodeRabbit reviews the working-tree diff and is
39
+ * fed no prompt at all.
40
+ * 2. `outputChannel: 'file-arg'` — Codex writes the review via its own
41
+ * `-o/--output-last-message <FILE>` and discards stdout (#1698), because on
42
+ * Windows it emits teardown noise to stdout after the final message.
43
+ * 3. `outputArg` — the companion to (2): knowing the review lands in a file is
44
+ * useless without the argument that names the file.
45
+ * 4. `flags: string[]` — Antigravity is selected by BOTH `--antigravity` and
46
+ * `--agy`, which a single-valued field cannot express. This also flattens
47
+ * D8's uniqueness invariant across every lane's flags.
48
+ *
49
+ * Phase 2 (#2795) implements the manifest validator against the amended
50
+ * vocabulary, which is the point of amending rather than leaving it to be
51
+ * rediscovered.
52
+ */
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.DOCS_PARITY_VIOLATION = exports.LANE_SLUG_RE = exports.PARITY_VIOLATION = exports.REVIEWER_LANES = exports.ARGV_PLACEHOLDER = void 0;
55
+ exports.checkReviewerLaneParity = checkReviewerLaneParity;
56
+ exports.checkReviewerDocsParity = checkReviewerDocsParity;
57
+ /**
58
+ * Argv placeholders (Phase 5b, #2799).
59
+ *
60
+ * `args` is an argv TEMPLATE, not a prefix. The injected pieces — model, effort, output file,
61
+ * argv-borne prompt — do not all go in the same place, and no positional rule expresses that:
62
+ * `codex` injects the model in the MIDDLE (after the `exec --ephemeral` subcommand) and the output
63
+ * file later still, while `gemini` injects the model first and five lanes end with a bare `-` that
64
+ * must stay last. Splicing by position silently produced
65
+ * `codex --model M -o F exec --ephemeral …`, which is not a valid codex invocation.
66
+ *
67
+ * So each lane declares WHERE each piece goes. A placeholder expands to zero or more argv elements
68
+ * and vanishes when it has nothing to contribute (no model configured, no effort channel, prompt on
69
+ * stdin), which is what lets one template serve the configured and unconfigured cases.
70
+ *
71
+ * This is a closed four-member vocabulary with no expressions, no nesting and no conditionals — a
72
+ * placeholder set, deliberately not a template language. The moment it needs a conditional, the
73
+ * lane wants a `handler` instead (D6).
74
+ */
75
+ exports.ARGV_PLACEHOLDER = Object.freeze({
76
+ /** `modelArg` + the resolved model, or nothing. */
77
+ MODEL: '{{model}}',
78
+ /** The host's effort argv, or nothing unless `effortChannel` is `argv`. */
79
+ EFFORT: '{{effort}}',
80
+ /** `outputArg` + the review path, or nothing unless `outputChannel` is `file-arg`. */
81
+ OUTPUT: '{{output}}',
82
+ /** The argv-borne prompt, or nothing unless `promptChannel` is `argv`/`argv-file-ref`. */
83
+ PROMPT: '{{prompt}}',
84
+ });
85
+ const SPAWN_STDIN_STDOUT = {
86
+ promptChannel: 'stdin',
87
+ outputChannel: 'stdout',
88
+ };
89
+ /**
90
+ * The twelve declared lanes, in `write_reviews` order.
91
+ *
92
+ * `kimi-code` joined in Phase 5b (#2799, closes #2718) — ADR-2782's phase table lands it here
93
+ * rather than in 5a precisely so it arrives together with the iteration that can invoke it.
94
+ */
95
+ exports.REVIEWER_LANES = Object.freeze([
96
+ {
97
+ slug: 'gemini',
98
+ flags: ['--gemini'],
99
+ transport: 'spawn',
100
+ probe: { kind: 'command-exists', binary: 'gemini' },
101
+ invoke: {
102
+ binary: 'gemini',
103
+ args: ['{{model}}', '-p', '-'],
104
+ ...SPAWN_STDIN_STDOUT,
105
+ modelArg: '-m',
106
+ effortChannel: 'none',
107
+ },
108
+ timeoutFloorMs: 900_000,
109
+ emptyOutput: 'stub-with-stderr',
110
+ reviewsSection: 'Gemini',
111
+ evidenceClass: 'source-grounded',
112
+ requiresBinaries: [],
113
+ promptBudgetKey: null,
114
+ modelConfigKey: 'review.models.gemini',
115
+ handler: null,
116
+ },
117
+ {
118
+ // 1_200_000 rather than the 900_000 floor: headless Claude measured ~525 s
119
+ // on a large plan set (review.md:304).
120
+ slug: 'claude',
121
+ flags: ['--claude'],
122
+ transport: 'spawn',
123
+ probe: { kind: 'command-exists', binary: 'claude' },
124
+ invoke: {
125
+ binary: 'claude',
126
+ args: ['{{model}}', '{{effort}}', '-p', '-'],
127
+ ...SPAWN_STDIN_STDOUT,
128
+ modelArg: '--model',
129
+ effortChannel: 'argv',
130
+ },
131
+ timeoutFloorMs: 1_200_000,
132
+ emptyOutput: 'stub-with-stderr',
133
+ reviewsSection: 'Claude',
134
+ evidenceClass: 'source-grounded',
135
+ requiresBinaries: [],
136
+ promptBudgetKey: null,
137
+ modelConfigKey: 'review.models.claude',
138
+ handler: null,
139
+ },
140
+ {
141
+ // Codex captures the review through its own `-o/--output-last-message` and
142
+ // discards stdout, because on Windows it writes process-teardown noise to
143
+ // stdout AFTER the final message, which a stdout redirect would append to a
144
+ // non-empty file and slip past the empty-output guard (#1698).
145
+ slug: 'codex',
146
+ flags: ['--codex'],
147
+ transport: 'spawn',
148
+ probe: { kind: 'command-exists', binary: 'codex' },
149
+ invoke: {
150
+ binary: 'codex',
151
+ // Leg order exactly: codex exec --ephemeral --model M $EFFORT --skip-git-repo-check -o F -
152
+ args: ['exec', '--ephemeral', '{{model}}', '{{effort}}', '--skip-git-repo-check', '{{output}}', '-'],
153
+ promptChannel: 'stdin',
154
+ outputChannel: 'file-arg',
155
+ outputArg: '-o',
156
+ modelArg: '--model',
157
+ effortChannel: 'argv',
158
+ },
159
+ timeoutFloorMs: 1_200_000,
160
+ emptyOutput: 'stub-with-stderr',
161
+ reviewsSection: 'Codex',
162
+ evidenceClass: 'source-grounded',
163
+ requiresBinaries: [],
164
+ promptBudgetKey: null,
165
+ modelConfigKey: 'review.models.codex',
166
+ handler: null,
167
+ },
168
+ {
169
+ // Fed no prompt: CodeRabbit reviews the working-tree diff and accepts
170
+ // neither a prompt nor a model flag (review.md:367). Its findings are
171
+ // deliberately down-weighted in the consensus step.
172
+ slug: 'coderabbit',
173
+ flags: ['--coderabbit'],
174
+ transport: 'spawn',
175
+ probe: { kind: 'command-exists', binary: 'coderabbit' },
176
+ invoke: {
177
+ binary: 'coderabbit',
178
+ args: ['review', '--prompt-only'],
179
+ promptChannel: 'none',
180
+ outputChannel: 'stdout',
181
+ modelArg: null,
182
+ effortChannel: 'none',
183
+ },
184
+ timeoutFloorMs: 360_000,
185
+ emptyOutput: 'stub-with-stderr',
186
+ reviewsSection: 'CodeRabbit',
187
+ evidenceClass: 'diff-only',
188
+ requiresBinaries: [],
189
+ promptBudgetKey: null,
190
+ // Accepts no model flag at all (review.md:367) — not merely "none configured".
191
+ modelConfigKey: null,
192
+ handler: null,
193
+ },
194
+ {
195
+ // `--format json` is the primary invocation, not a fallback: the review text
196
+ // lives in assistant `text` parts, which the default formatter drops when the
197
+ // agent stops with no final message (#1936). Reconstruction needs jq.
198
+ slug: 'opencode',
199
+ flags: ['--opencode'],
200
+ transport: 'spawn',
201
+ probe: { kind: 'command-exists', binary: 'opencode' },
202
+ invoke: {
203
+ binary: 'opencode',
204
+ args: ['run', '{{model}}', '{{effort}}', '--format', 'json', '-'],
205
+ ...SPAWN_STDIN_STDOUT,
206
+ modelArg: '--model',
207
+ effortChannel: 'argv',
208
+ },
209
+ timeoutFloorMs: 660_000,
210
+ emptyOutput: 'stub-with-stderr',
211
+ reviewsSection: 'OpenCode',
212
+ evidenceClass: 'source-grounded',
213
+ // Phase 5b: the handler reconstructs from the JSON stream with JSON.parse, so `jq` — absent on
214
+ // stock Windows/Git-Bash (#2589) — is no longer a prerequisite for this lane.
215
+ requiresBinaries: [],
216
+ promptBudgetKey: null,
217
+ modelConfigKey: 'review.models.opencode',
218
+ // Phase 5b (#2799): was `null`. The review is REBUILT from assistant `text` parts; a plain
219
+ // stdout copy would write the raw JSON envelope as the review (#1936). See LaneHandler.
220
+ handler: 'opencode',
221
+ },
222
+ {
223
+ slug: 'qwen',
224
+ flags: ['--qwen'],
225
+ transport: 'spawn',
226
+ probe: { kind: 'command-exists', binary: 'qwen' },
227
+ invoke: {
228
+ binary: 'qwen',
229
+ args: ['-'],
230
+ ...SPAWN_STDIN_STDOUT,
231
+ modelArg: null,
232
+ effortChannel: 'none',
233
+ },
234
+ timeoutFloorMs: 900_000,
235
+ emptyOutput: 'stub-with-stderr',
236
+ reviewsSection: 'Qwen',
237
+ evidenceClass: 'source-grounded',
238
+ requiresBinaries: [],
239
+ promptBudgetKey: null,
240
+ modelConfigKey: null,
241
+ handler: null,
242
+ },
243
+ {
244
+ // `cursor-agent` is a SEPARATE binary from the `cursor` IDE launcher. Print
245
+ // mode takes the prompt as an ARGUMENT, so a full plan set is passed by file
246
+ // reference to stay clear of the 32,767-char Windows execFileSync ceiling.
247
+ slug: 'cursor',
248
+ flags: ['--cursor'],
249
+ transport: 'spawn',
250
+ probe: { kind: 'command-exists', binary: 'cursor-agent' },
251
+ invoke: {
252
+ binary: 'cursor-agent',
253
+ args: ['-p', '--mode', 'ask', '--trust', '--output-format', 'text', '{{prompt}}'],
254
+ promptChannel: 'argv-file-ref',
255
+ outputChannel: 'stdout',
256
+ modelArg: null,
257
+ effortChannel: 'none',
258
+ },
259
+ timeoutFloorMs: 900_000,
260
+ emptyOutput: 'stub-with-stderr',
261
+ reviewsSection: 'Cursor',
262
+ evidenceClass: 'source-grounded',
263
+ requiresBinaries: [],
264
+ promptBudgetKey: null,
265
+ modelConfigKey: null,
266
+ handler: null,
267
+ },
268
+ {
269
+ // Handler-owned: a three-layer fallback for an upstream stdout bug, a
270
+ // two-level timeout (600 s external cap over a 540 s native --print-timeout),
271
+ // and a stale-response watermark guard. `timeoutFloorMs` carries the OUTER
272
+ // bound only; the inner one lives in the handler (ADR-2782 D6).
273
+ slug: 'antigravity',
274
+ flags: ['--antigravity', '--agy'],
275
+ transport: 'spawn',
276
+ probe: { kind: 'command-exists', binary: 'agy' },
277
+ invoke: {
278
+ binary: 'agy',
279
+ args: ['--print-timeout', '540s', '{{model}}', '-p', '{{prompt}}'],
280
+ promptChannel: 'argv-file-ref',
281
+ outputChannel: 'stdout',
282
+ modelArg: '--model',
283
+ effortChannel: 'none',
284
+ },
285
+ timeoutFloorMs: 600_000,
286
+ emptyOutput: 'handler-owned',
287
+ reviewsSection: 'Antigravity',
288
+ evidenceClass: 'source-grounded',
289
+ // Phase 5b: the handler reads the transcript with JSON.parse per line, not `jq`.
290
+ requiresBinaries: [],
291
+ promptBudgetKey: null,
292
+ // NOT `review.models.antigravity` — the shipped key is `review.models.agy` (review.md:291) and
293
+ // Phase 4 federated it under that name. This lane is why the key is declared, not derived.
294
+ modelConfigKey: 'review.models.agy',
295
+ handler: 'antigravity',
296
+ },
297
+ {
298
+ slug: 'ollama',
299
+ flags: ['--ollama'],
300
+ transport: 'openai-http',
301
+ probe: {
302
+ kind: 'http-reachable',
303
+ hostConfigKey: 'review.ollama_host',
304
+ path: '/v1/models',
305
+ timeoutMs: 2_000,
306
+ },
307
+ invoke: {
308
+ hostConfigKey: 'review.ollama_host',
309
+ defaultHost: 'http://localhost:11434',
310
+ path: '/v1/chat/completions',
311
+ modelDiscovery: 'first-from-models-endpoint',
312
+ fallbackModel: 'llama3',
313
+ effortChannel: 'none',
314
+ },
315
+ timeoutFloorMs: 120_000,
316
+ emptyOutput: 'stub-with-stderr',
317
+ reviewsSection: 'Ollama',
318
+ evidenceClass: 'source-grounded',
319
+ // Phase 5b: the openai-compatible handler speaks HTTP directly and parses with JSON.parse, so
320
+ // neither `jq` nor `curl` is a prerequisite any more (#2589's stated Windows hazard).
321
+ requiresBinaries: [],
322
+ promptBudgetKey: 'review.max_prompt_tokens_per_reviewer.ollama',
323
+ modelConfigKey: 'review.models.ollama',
324
+ handler: 'openai-compatible',
325
+ },
326
+ {
327
+ slug: 'lm_studio',
328
+ flags: ['--lm-studio'],
329
+ transport: 'openai-http',
330
+ probe: {
331
+ kind: 'http-reachable',
332
+ hostConfigKey: 'review.lm_studio_host',
333
+ path: '/v1/models',
334
+ timeoutMs: 2_000,
335
+ },
336
+ invoke: {
337
+ hostConfigKey: 'review.lm_studio_host',
338
+ defaultHost: 'http://localhost:1234',
339
+ path: '/v1/chat/completions',
340
+ modelDiscovery: 'first-from-models-endpoint',
341
+ fallbackModel: 'local-model',
342
+ effortChannel: 'none',
343
+ },
344
+ timeoutFloorMs: 120_000,
345
+ emptyOutput: 'stub-with-stderr',
346
+ reviewsSection: 'LM Studio',
347
+ evidenceClass: 'source-grounded',
348
+ requiresBinaries: [],
349
+ promptBudgetKey: 'review.max_prompt_tokens_per_reviewer.lm_studio',
350
+ modelConfigKey: 'review.models.lm_studio',
351
+ handler: 'openai-compatible',
352
+ },
353
+ {
354
+ slug: 'llama_cpp',
355
+ flags: ['--llama-cpp'],
356
+ transport: 'openai-http',
357
+ probe: {
358
+ kind: 'http-reachable',
359
+ hostConfigKey: 'review.llama_cpp_host',
360
+ path: '/v1/models',
361
+ timeoutMs: 2_000,
362
+ },
363
+ invoke: {
364
+ hostConfigKey: 'review.llama_cpp_host',
365
+ defaultHost: 'http://localhost:8080',
366
+ path: '/v1/chat/completions',
367
+ modelDiscovery: 'first-from-models-endpoint',
368
+ fallbackModel: 'local-model',
369
+ effortChannel: 'none',
370
+ },
371
+ timeoutFloorMs: 120_000,
372
+ emptyOutput: 'stub-with-stderr',
373
+ reviewsSection: 'llama.cpp',
374
+ evidenceClass: 'source-grounded',
375
+ requiresBinaries: [],
376
+ promptBudgetKey: 'review.max_prompt_tokens_per_reviewer.llama_cpp',
377
+ modelConfigKey: 'review.models.llama_cpp',
378
+ handler: 'openai-compatible',
379
+ },
380
+ {
381
+ // Phase 5b (#2799) — closes #2718. Net-new in this phase BY DESIGN (ADR-2782's phase table):
382
+ // declaring it in 5a would have made it selectable but not invocable, producing an empty
383
+ // section for the whole 5a → 5b window.
384
+ //
385
+ // The probe is `command-capability`, not `command-exists`, and that is the entire reason D7's
386
+ // vocabulary ships wider than existence: `kimi` is claimed by BOTH the Kimi Code CLI (Node) and
387
+ // the legacy Python kimi-cli, which is a separate first-party runtime capability in this repo.
388
+ // An existence-only probe registers the wrong tool. The needle `--output-format` appears in
389
+ // Kimi Code's `--help` and is absent from the legacy CLI (whose headless flags are `--print` /
390
+ // `--work-dir`). Verified in both directions against Kimi Code CLI 0.29.2 and a stub legacy
391
+ // binary in closed PR #2776 — analysis carried forward with credit to @drungrin.
392
+ //
393
+ // The original probe there was an UNBOUNDED `kimi --help | grep` that ran on EVERY /gsd:review
394
+ // regardless of flags: a live instance of this repo's named Unbounded Subprocesses defect, and
395
+ // the review blocker. Here the bound is declared (`timeoutMs`) and the runner enforces it, and
396
+ // the probe runs only for a SELECTED lane.
397
+ slug: 'kimi-code',
398
+ flags: ['--kimi-code'],
399
+ transport: 'spawn',
400
+ probe: {
401
+ kind: 'command-capability',
402
+ binary: 'kimi',
403
+ needle: '--output-format',
404
+ timeoutMs: 5_000,
405
+ },
406
+ invoke: {
407
+ // Print mode takes the prompt as an ARGUMENT, so the full plan set goes by file reference to
408
+ // stay clear of the 32,767-char Windows execFileSync ceiling — same shape as cursor.
409
+ binary: 'kimi',
410
+ args: ['{{model}}', '-p', '{{prompt}}'],
411
+ promptChannel: 'argv-file-ref',
412
+ outputChannel: 'stdout',
413
+ modelArg: '-m',
414
+ effortChannel: 'none',
415
+ },
416
+ timeoutFloorMs: 900_000,
417
+ emptyOutput: 'stub-with-stderr',
418
+ reviewsSection: 'Kimi Code',
419
+ evidenceClass: 'source-grounded',
420
+ requiresBinaries: [],
421
+ promptBudgetKey: null,
422
+ modelConfigKey: 'review.models.kimi-code',
423
+ handler: null,
424
+ },
425
+ ].map((lane) => Object.freeze(lane)));
426
+ /* ------------------------------------------------------------------ *
427
+ * DEFECT.GENERATIVE-FIX parity (CONTEXT.md:797)
428
+ * ------------------------------------------------------------------ */
429
+ /**
430
+ * Frozen reason enum. Tests assert on these values, never on rendered prose —
431
+ * CONTRIBUTING.md "Tests assert on typed structured values". Adding a reason is
432
+ * three coordinated changes: this enum, the emitting site, and the test locking
433
+ * `Object.keys(...).sort()`.
434
+ */
435
+ exports.PARITY_VIOLATION = Object.freeze({
436
+ MALFORMED_LANE: 'malformed_lane',
437
+ INVALID_SLUG: 'invalid_slug',
438
+ ROSTER_SLUG_UNDECLARED: 'roster_slug_undeclared',
439
+ DESCRIPTOR_LANE_NOT_IN_ROSTER: 'descriptor_lane_not_in_roster',
440
+ REGISTRY_LANE_UNDECLARED: 'registry_lane_undeclared',
441
+ DESCRIPTOR_LANE_NOT_IN_REGISTRY: 'descriptor_lane_not_in_registry',
442
+ BESPOKE_LEG_PRESENT: 'bespoke_leg_present',
443
+ DUPLICATE_SLUG: 'duplicate_slug',
444
+ DUPLICATE_FLAG: 'duplicate_flag',
445
+ DUPLICATE_SECTION: 'duplicate_section',
446
+ });
447
+ /**
448
+ * The marker that used to make a hand-authored `invoke_reviewers` leg identifiable.
449
+ *
450
+ * Phase 5b (#2799) deleted every bespoke leg, so this regex flipped polarity: matching one is now
451
+ * the VIOLATION (`BESPOKE_LEG_PRESENT`) rather than the requirement. It is retained precisely
452
+ * because deleting it would leave nothing stopping a future contributor from quietly re-adding a
453
+ * per-CLI block — which is the drift (#2718 → #2781) this whole epic exists to end.
454
+ */
455
+ const LEG_MARKER_RE = /<!--\s*reviewer-lane:\s*([a-z0-9_-]+)\s*-->/g;
456
+ /**
457
+ * The slug grammar, and the reason it is enforced rather than assumed.
458
+ *
459
+ * `LEG_MARKER_RE` can only capture `[a-z0-9_-]`. A lane whose slug falls outside
460
+ * that class is therefore UNMATCHABLE in the workflow: its marker can be present
461
+ * and correct and the scan will still never see it, so the lane reports
462
+ * `LEG_MARKER_MISSING` forever with no indication why. All twelve shipped slugs
463
+ * sit inside the class (`lm_studio`, `llama_cpp` use the underscore), so this
464
+ * never bites today — but Phase 2 (#2795) admits third-party overlay lanes, and
465
+ * a slug like `acme.reviewer` would silently vanish from a review.
466
+ *
467
+ * ADR-2782 does not specify a slug grammar. Rather than widen the marker regex —
468
+ * which would make an HTML comment scanned out of prose more ambiguous, not less
469
+ * — the grammar is pinned here and a violating slug is reported as
470
+ * `INVALID_SLUG`. A loud, named violation beats a silent miss; that is the whole
471
+ * design principle of this module.
472
+ */
473
+ exports.LANE_SLUG_RE = /^[a-z0-9][a-z0-9_-]*$/;
474
+ /** Bounds of the step a bespoke leg marker could appear inside. */
475
+ const INVOKE_STEP_RE = /<step name="invoke_reviewers">([\s\S]*?)<\/step>/;
476
+ function sliceStep(workflowText, re) {
477
+ const m = workflowText.match(re);
478
+ return m ? m[1] : '';
479
+ }
480
+ function countOccurrences(haystack, re) {
481
+ const counts = new Map();
482
+ // Fresh lastIndex per call — a module-level /g regex carries state between
483
+ // calls and would silently skip matches on the second invocation.
484
+ const scanner = new RegExp(re.source, re.flags);
485
+ let m;
486
+ while ((m = scanner.exec(haystack)) !== null) {
487
+ const key = m[1].trim();
488
+ counts.set(key, (counts.get(key) ?? 0) + 1);
489
+ }
490
+ return counts;
491
+ }
492
+ /**
493
+ * Bidirectional parity across three surfaces: the descriptor, the roster
494
+ * (`KNOWN_REVIEWER_SLUGS`), and the generated capability **registry** — plus one anti-parity
495
+ * assertion against the workflow.
496
+ *
497
+ * **Re-pointed by Phase 5b (#2799).** Through Phase 5a this function also required a literal
498
+ * `<!-- reviewer-lane: <slug> -->` per lane inside `invoke_reviewers` and a literal
499
+ * `## <Section> Review` per lane inside `write_reviews`. Phase 5b deletes exactly that text: the
500
+ * workflow now iterates declared lanes and renders sections from `reviewsSection`, so there is no
501
+ * per-lane text left to scan. Those two families could not be kept without keeping the
502
+ * hand-maintained per-lane blocks this epic exists to delete.
503
+ *
504
+ * What replaced them is the parity that is actually load-bearing once lanes are data: the registry
505
+ * is what decides which lanes exist at runtime, so `descriptor ↔ registry` is checked in both
506
+ * directions. That is also the mechanical single source #2781/Phase 6 needs for its docs and locale
507
+ * gate, which per-leg text could never provide.
508
+ *
509
+ * Bidirectional is still the point. A forward-only check ("does each declared lane resolve?")
510
+ * misses the failure this exists to catch: #2718 added a lane and #2781 was the documentation drift
511
+ * that followed. A registry lane nobody declared must fail, and so must a re-added bespoke leg.
512
+ *
513
+ * Pure and total: never reads the filesystem, never throws. Empty or malformed `workflowText` /
514
+ * `registry` degrades to violations, so a caller cannot mistake a read failure for a clean bill of
515
+ * health.
516
+ *
517
+ * CRLF-insensitive: `\r` is stripped before matching, because a Windows autocrlf checkout would
518
+ * otherwise leave every marker unmatched.
519
+ */
520
+ function checkReviewerLaneParity(input) {
521
+ const { descriptor, roster } = input;
522
+ const workflowText = String(input.workflowText ?? '').replace(/\r\n/g, '\n');
523
+ const violations = [];
524
+ const add = (reason, subject) => {
525
+ violations.push({ reason, subject });
526
+ };
527
+ // --- D8 uniqueness within the descriptor itself ---
528
+ //
529
+ // Every field is validated before use rather than trusted. In Phase 1 the
530
+ // descriptor is a frozen in-source table and none of these guards can fire,
531
+ // but Phase 2 (#2795) feeds this same function manifest-derived data from
532
+ // third-party overlays — which is precisely where a malformed entry arrives.
533
+ // A checker that throws on bad input cannot report on it, and a parity gate
534
+ // that crashes is indistinguishable from one that was never run.
535
+ const seenSlug = new Set();
536
+ const seenFlag = new Set();
537
+ const seenSection = new Set();
538
+ // The declared parameter type says `ReviewerLane[]`, but this function is a
539
+ // trust boundary — narrow from `unknown` rather than believing the annotation.
540
+ const rawLanes = Array.isArray(descriptor) ? descriptor : [];
541
+ for (const raw of rawLanes) {
542
+ if (raw === null || typeof raw !== 'object') {
543
+ add(exports.PARITY_VIOLATION.MALFORMED_LANE, String(raw));
544
+ continue;
545
+ }
546
+ const lane = raw;
547
+ const slug = lane.slug;
548
+ if (typeof slug !== 'string' || !exports.LANE_SLUG_RE.test(slug)) {
549
+ add(exports.PARITY_VIOLATION.INVALID_SLUG, String(slug));
550
+ continue;
551
+ }
552
+ const section = typeof lane.reviewsSection === 'string' ? lane.reviewsSection : null;
553
+ if (seenSlug.has(slug))
554
+ add(exports.PARITY_VIOLATION.DUPLICATE_SLUG, slug);
555
+ seenSlug.add(slug);
556
+ const flags = Array.isArray(lane.flags) ? lane.flags : [];
557
+ for (const flag of flags) {
558
+ if (typeof flag !== 'string')
559
+ continue;
560
+ if (seenFlag.has(flag))
561
+ add(exports.PARITY_VIOLATION.DUPLICATE_FLAG, flag);
562
+ seenFlag.add(flag);
563
+ }
564
+ // Two lanes sharing a heading would silently MERGE their output in
565
+ // REVIEWS.md, producing a review that appears to have consensus it does
566
+ // not have (ADR-2782 D8).
567
+ if (section !== null) {
568
+ if (seenSection.has(section))
569
+ add(exports.PARITY_VIOLATION.DUPLICATE_SECTION, section);
570
+ seenSection.add(section);
571
+ }
572
+ }
573
+ // --- descriptor <-> roster ---
574
+ const rosterSet = new Set((Array.isArray(roster) ? roster : []).filter((x) => typeof x === 'string'));
575
+ for (const slug of rosterSet) {
576
+ if (!seenSlug.has(slug))
577
+ add(exports.PARITY_VIOLATION.ROSTER_SLUG_UNDECLARED, slug);
578
+ }
579
+ for (const slug of seenSlug) {
580
+ if (!rosterSet.has(slug))
581
+ add(exports.PARITY_VIOLATION.DESCRIPTOR_LANE_NOT_IN_ROSTER, slug);
582
+ }
583
+ // --- descriptor <-> registry ---
584
+ //
585
+ // The registry is what decides which lanes exist at runtime once the workflow iterates, so this
586
+ // replaces the per-leg text checks Phase 5b deleted. A non-array degrades to an empty set, which
587
+ // then reports every descriptor lane as missing — loud, not silent.
588
+ const registrySet = new Set((Array.isArray(input.registry) ? input.registry : []).filter((x) => typeof x === 'string'));
589
+ for (const slug of registrySet) {
590
+ if (!seenSlug.has(slug))
591
+ add(exports.PARITY_VIOLATION.REGISTRY_LANE_UNDECLARED, slug);
592
+ }
593
+ for (const slug of seenSlug) {
594
+ if (!registrySet.has(slug))
595
+ add(exports.PARITY_VIOLATION.DESCRIPTOR_LANE_NOT_IN_REGISTRY, slug);
596
+ }
597
+ // --- anti-parity: no bespoke leg may return ---
598
+ //
599
+ // Phase 5b deleted every hand-authored per-CLI block. Nothing in the type system stops a future
600
+ // contributor from adding one back, and a re-added block is invisible to every other check here
601
+ // (it would still be declared, still be in the roster, still be in the registry). Matching a leg
602
+ // marker is therefore now the violation.
603
+ const markerSlugs = countOccurrences(sliceStep(workflowText, INVOKE_STEP_RE), LEG_MARKER_RE);
604
+ for (const slug of markerSlugs.keys()) {
605
+ add(exports.PARITY_VIOLATION.BESPOKE_LEG_PRESENT, slug);
606
+ }
607
+ return { ok: violations.length === 0, violations };
608
+ }
609
+ /* ------------------------------------------------------------------ *
610
+ * Documentation parity (ADR-2782 Phase 6, #2800 — closes #2781/#2272)
611
+ * ------------------------------------------------------------------ */
612
+ /**
613
+ * Frozen reason enum for the DOCUMENTATION arm.
614
+ *
615
+ * Deliberately separate from `PARITY_VIOLATION` rather than an extension of it. The two functions
616
+ * answer different questions — `checkReviewerLaneParity` asks *what runs* (descriptor ↔ roster ↔
617
+ * registry), this asks *what is documented*. Fusing them would change the signature of a function
618
+ * with seven dependents and would let a stale doc make the runtime checker look red.
619
+ *
620
+ * Same three-coordinated-changes rule as its sibling: this enum, the emitting site, and the test
621
+ * locking `Object.keys(...).sort()`.
622
+ */
623
+ exports.DOCS_PARITY_VIOLATION = Object.freeze({
624
+ MALFORMED_LANE: 'malformed_lane',
625
+ DOC_FLAG_MISSING: 'doc_flag_missing',
626
+ DOC_FLAG_UNDECLARED: 'doc_flag_undeclared',
627
+ DOC_TITLE_MISSING: 'doc_title_missing',
628
+ SIGNATURE_FLAG_MISSING: 'signature_flag_missing',
629
+ DOC_UNREADABLE: 'doc_unreadable',
630
+ TABLE_ROW_MISSING: 'table_row_missing',
631
+ });
632
+ /**
633
+ * Non-lane tokens that legitimately share the `/gsd-review` signature line.
634
+ *
635
+ * `--all` is a selection control, not a reviewer lane. Without this allow-list the undeclared-flag
636
+ * arm would fire on correct documentation — the gate failing on a doc that is right is the fastest
637
+ * way to get a gate deleted.
638
+ */
639
+ const NON_LANE_SIGNATURE_FLAGS = new Set(['--all']);
640
+ /**
641
+ * Is `flag` documented in `text` under one of the two structural shapes docs actually use?
642
+ *
643
+ * Backticked is the `COMMANDS.md` table-cell shape; bracketed (`[--gemini]`) is the
644
+ * `FEATURES.md` signature shape. Requiring one of those two delimiters — rather than a bare
645
+ * substring — is what keeps prose and fenced examples from satisfying the gate, and it bounds the
646
+ * token for free: a backticked `--claude` demands its closing backtick, so a backticked
647
+ * `--claude-foo` cannot satisfy it.
648
+ *
649
+ * Literal `includes`, deliberately NOT a RegExp. `new RegExp` throws `SyntaxError` on a pattern
650
+ * beyond ~100k chars, and Phase 2 (#2795) admits third-party overlay lanes whose declared strings
651
+ * are untrusted in length — a parity gate that throws on its own input is indistinguishable from
652
+ * one that never ran. Literal matching also removes the need to escape metacharacters, which is
653
+ * what `llama.cpp` needed.
654
+ */
655
+ function flagIsDocumented(text, flag) {
656
+ return text.includes('`' + flag + '`') || text.includes('[' + flag + ']');
657
+ }
658
+ /**
659
+ * Strip fenced code blocks and HTML comments before parity matching.
660
+ *
661
+ * Both are places a flag can be *mentioned* without being *documented*: a fenced block showing
662
+ * markdown syntax, or a commented-out row left behind by an edit. Counting either is a false pass
663
+ * — the gate would report a lane as documented when a reader never sees it.
664
+ *
665
+ * Lines are replaced with empty strings rather than removed so that every downstream line index
666
+ * (the signature line, the Purpose paragraph beneath it) still refers to the same physical line.
667
+ */
668
+ function stripNonProse(text) {
669
+ const lines = text.split('\n');
670
+ const out = [];
671
+ let inFence = false;
672
+ let inComment = false;
673
+ for (const line of lines) {
674
+ const trimmed = line.trim();
675
+ if (!inComment && /^(`{3,}|~{3,})/.test(trimmed)) {
676
+ inFence = !inFence;
677
+ out.push('');
678
+ continue;
679
+ }
680
+ if (inFence) {
681
+ out.push('');
682
+ continue;
683
+ }
684
+ let working = line;
685
+ if (!inComment && working.includes('<!--') && !working.includes('-->')) {
686
+ inComment = true;
687
+ working = working.slice(0, working.indexOf('<!--'));
688
+ out.push(working);
689
+ continue;
690
+ }
691
+ if (inComment) {
692
+ if (working.includes('-->')) {
693
+ inComment = false;
694
+ working = working.slice(working.indexOf('-->') + 3);
695
+ out.push(working);
696
+ }
697
+ else {
698
+ out.push('');
699
+ }
700
+ continue;
701
+ }
702
+ // Single-line comments: strip to a FIXED POINT, then honor any unterminated opener.
703
+ //
704
+ // One pass is not enough. `<!--<!---->-->` strips the inner span and leaves a live `<!--`
705
+ // behind, so a commented-out row could survive and be counted as documented — the exact
706
+ // false pass this helper exists to prevent. (CodeQL flags the single-pass form as
707
+ // js/incomplete-multi-character-sanitization; here the consequence is a wrong verdict rather
708
+ // than an injection, but the fix is the same.) Iterating to a fixed point terminates because
709
+ // every pass strictly shortens the string.
710
+ let previous;
711
+ do {
712
+ previous = working;
713
+ working = working.replace(/<!--[\s\S]*?-->/g, '');
714
+ } while (working !== previous);
715
+ // Whatever `<!--` remains after that is unterminated, so it opens a multi-line comment that
716
+ // the `inComment` branch above will close on a later line.
717
+ const danglingOpen = working.indexOf('<!--');
718
+ if (danglingOpen !== -1) {
719
+ inComment = true;
720
+ working = working.slice(0, danglingOpen);
721
+ }
722
+ out.push(working);
723
+ }
724
+ return out.join('\n');
725
+ }
726
+ /** Every bracketed `--token` on a signature line — the line's claimed reviewer flag set. */
727
+ const BRACKETED_FLAG_RE = /\[(--[a-z0-9][a-z0-9-]*)\]/g;
728
+ /**
729
+ * Declared flags that appear in the FIRST cell of a markdown table row.
730
+ *
731
+ * The distinction is load-bearing, not cosmetic. `docs/COMMANDS.md` and every locale mirror carry
732
+ * BOTH a per-lane reviewer table (flag in cell 1) and a forwarding row that lists all 13 flags in
733
+ * cell 3. A file-scoped check is therefore satisfied by the forwarding row alone, so deleting a
734
+ * lane's actual table row — the exact #2781 regression — passes. Keying on cell 1 separates the
735
+ * two: `| `--agy` / `--antigravity` | … |` is one lane row declaring two flags, while
736
+ * `| Reviewer flags | No | … `--gemini`, `--claude` … |` is not a lane row at all.
737
+ */
738
+ function flagsInFirstTableCell(lines, declared) {
739
+ const found = new Set();
740
+ for (const line of lines) {
741
+ const trimmed = line.trim();
742
+ if (!trimmed.startsWith('|'))
743
+ continue;
744
+ const cells = trimmed.split('|');
745
+ // split('|') on "| a | b |" yields ['', ' a ', ' b ', ''] — cell 1 is index 1.
746
+ if (cells.length < 2)
747
+ continue;
748
+ const firstCell = cells[1];
749
+ for (const flag of declared) {
750
+ if (flagIsDocumented(firstCell, flag))
751
+ found.add(flag);
752
+ }
753
+ }
754
+ return found;
755
+ }
756
+ /**
757
+ * The `**Command:** ... /gsd-review ... [--flag]` signature line, if the doc carries one.
758
+ *
759
+ * Anchored on `/gsd-review` plus a bracketed flag rather than on the bolded label, because the
760
+ * label is translated in every mirror. Structure survives translation; prose does not.
761
+ */
762
+ function findSignatureLine(lines) {
763
+ return lines.findIndex((l) => /\/gsd[-:]review\b/.test(l) && l.includes('[--'));
764
+ }
765
+ /**
766
+ * Documentation parity for the declared reviewer roster (#2800; closes #2781, #2272).
767
+ *
768
+ * Gates `docs/COMMANDS.md`, its four locale mirrors, `docs/FEATURES.md` and its mirrors against
769
+ * the one declared source of truth. This is the `DEFECT.GENERATIVE-FIX` parity assertion
770
+ * `CONTEXT.md:806` requires for this roster and which has never existed for it — only the Cursor
771
+ * lane ever had one (`tests/cursor-reviewer.test.cjs`).
772
+ *
773
+ * Three arms, deliberately independent so that gaming one does not green the build:
774
+ *
775
+ * 1. **flag** — every declared flag appears, delimited, somewhere in the doc. This is the arm
776
+ * that catches #2781 (`--kimi-code` present in `docs/COMMANDS.md` and absent from all four
777
+ * mirrors).
778
+ * 2. **signature** — where a `Command:` signature line exists it is held to the FULL roster, and
779
+ * any bracketed non-lane token on it is reported. This restores per-site strictness the
780
+ * file-wide arm cannot provide.
781
+ * 3. **title** — every declared `reviewsSection` appears in the Purpose paragraph. This is the
782
+ * arm that catches the class #2800 names: the `Command:` line updated and the `Purpose:` line
783
+ * one row below not.
784
+ * 4. **table row** — a doc carrying a per-lane table must carry a row for EVERY lane, keyed on
785
+ * the FIRST cell. Without this the file-wide flag arm is satisfied by the forwarding row that
786
+ * lists all flags in cell 3, and deleting a lane's own row — the #2781 regression itself —
787
+ * goes undetected.
788
+ *
789
+ * A doc carrying no `/gsd-review` surface is **skipped, not failed** — a partial mirror that never
790
+ * claimed to document the command is not drift.
791
+ *
792
+ * Pure and total: no filesystem, no clock, never throws. A non-string document is reported as
793
+ * `DOC_UNREADABLE` rather than coerced or skipped; an empty or absent `docs` map degrades to
794
+ * violations rather than a clean bill of health, because a checker that cannot distinguish
795
+ * "nothing to read" from "everything agrees" is worse than no checker.
796
+ *
797
+ * CRLF-insensitive: a Windows `autocrlf` checkout must produce an identical verdict.
798
+ */
799
+ function checkReviewerDocsParity(input) {
800
+ const violations = [];
801
+ const skipped = [];
802
+ const add = (reason, doc, subject) => {
803
+ violations.push({ reason, doc, subject });
804
+ };
805
+ // Trust boundary: narrow from `unknown` rather than believing the annotation. Phase 2 (#2795)
806
+ // admits third-party overlay lanes into this same descriptor.
807
+ const declaredFlags = [];
808
+ const declaredTitles = [];
809
+ const rawLanes = Array.isArray(input?.descriptor)
810
+ ? input.descriptor
811
+ : [];
812
+ for (const raw of rawLanes) {
813
+ if (raw === null || typeof raw !== 'object') {
814
+ add(exports.DOCS_PARITY_VIOLATION.MALFORMED_LANE, '(descriptor)', String(raw));
815
+ continue;
816
+ }
817
+ const lane = raw;
818
+ const flags = Array.isArray(lane.flags) ? lane.flags : [];
819
+ for (const flag of flags) {
820
+ if (typeof flag === 'string' && flag.length > 0)
821
+ declaredFlags.push(flag);
822
+ }
823
+ if (typeof lane.reviewsSection === 'string' && lane.reviewsSection.length > 0) {
824
+ declaredTitles.push(lane.reviewsSection);
825
+ }
826
+ }
827
+ const declaredFlagSet = new Set(declaredFlags);
828
+ // An absent or non-object map is not "no docs to check" — it is every doc missing. Reported as
829
+ // such so the caller cannot read silence as success.
830
+ const rawDocs = input?.docs !== null && typeof input?.docs === 'object'
831
+ ? input.docs
832
+ : {};
833
+ const docLabels = Object.keys(rawDocs);
834
+ if (docLabels.length === 0) {
835
+ for (const flag of declaredFlagSet) {
836
+ add(exports.DOCS_PARITY_VIOLATION.DOC_FLAG_MISSING, '(no documents supplied)', flag);
837
+ }
838
+ return { ok: violations.length === 0, violations, skipped };
839
+ }
840
+ for (const label of docLabels) {
841
+ // A document value that is not a string is REPORTED, not coerced and not skipped.
842
+ //
843
+ // The earlier version called `String(rawValue)`, which (a) throws outright on an object with
844
+ // an own non-callable `toString` and (b) — worse — turns any other object into
845
+ // `[object Object]`, a "document" with no `/gsd-review` marker that then lands in `skipped`.
846
+ // That is a silent pass: the gate would report success for input it never actually read.
847
+ // `@typescript-eslint/no-base-to-string` flags exactly this, and it is right to.
848
+ const rawValue = rawDocs[label];
849
+ if (typeof rawValue !== 'string') {
850
+ add(exports.DOCS_PARITY_VIOLATION.DOC_UNREADABLE, label, typeof rawValue);
851
+ continue;
852
+ }
853
+ const text = rawValue.replace(/\r\n/g, '\n');
854
+ // Fenced examples and commented-out rows mention a flag without documenting it. Stripped
855
+ // BEFORE the `/gsd-review` skip check too, so a doc whose only mention is inside a fence is
856
+ // correctly treated as not documenting the command at all.
857
+ const prose = stripNonProse(text);
858
+ // Skip-if-absent. A mirror that does not document /gsd-review is a partial translation, not
859
+ // drift — gating it would make this change responsible for authoring one.
860
+ if (!/\/gsd[-:]review\b/.test(prose)) {
861
+ skipped.push(label);
862
+ continue;
863
+ }
864
+ const lines = prose.split('\n');
865
+ // --- arm 1: every declared flag is documented somewhere in the doc ---
866
+ for (const flag of declaredFlagSet) {
867
+ if (!flagIsDocumented(prose, flag)) {
868
+ add(exports.DOCS_PARITY_VIOLATION.DOC_FLAG_MISSING, label, flag);
869
+ }
870
+ }
871
+ // --- arm 4: a doc that carries a per-lane table must carry a row for EVERY lane ---
872
+ //
873
+ // Only applies when the doc actually has a lane table (>=1 declared flag in a first cell);
874
+ // FEATURES-shaped docs carry a signature line instead and are covered by arms 2 and 3.
875
+ const rowFlags = flagsInFirstTableCell(lines, declaredFlagSet);
876
+ if (rowFlags.size > 0) {
877
+ for (const flag of declaredFlagSet) {
878
+ if (!rowFlags.has(flag)) {
879
+ add(exports.DOCS_PARITY_VIOLATION.TABLE_ROW_MISSING, label, flag);
880
+ }
881
+ }
882
+ }
883
+ const sigIdx = findSignatureLine(lines);
884
+ if (sigIdx === -1)
885
+ continue; // COMMANDS.md-shaped docs carry a table, not a signature.
886
+ // --- arm 2: the signature line carries the FULL roster and nothing undeclared ---
887
+ const sigLine = lines[sigIdx];
888
+ for (const flag of declaredFlagSet) {
889
+ if (!flagIsDocumented(sigLine, flag)) {
890
+ add(exports.DOCS_PARITY_VIOLATION.SIGNATURE_FLAG_MISSING, label, flag);
891
+ }
892
+ }
893
+ // Fresh RegExp per line — a module-level /g literal carries `lastIndex` between calls and
894
+ // would silently skip matches on the second document scanned.
895
+ const scanner = new RegExp(BRACKETED_FLAG_RE.source, BRACKETED_FLAG_RE.flags);
896
+ const seenUndeclared = new Set();
897
+ let m;
898
+ while ((m = scanner.exec(sigLine)) !== null) {
899
+ const token = m[1];
900
+ if (typeof token !== 'string')
901
+ continue;
902
+ if (declaredFlagSet.has(token) || NON_LANE_SIGNATURE_FLAGS.has(token))
903
+ continue;
904
+ if (seenUndeclared.has(token))
905
+ continue;
906
+ seenUndeclared.add(token);
907
+ add(exports.DOCS_PARITY_VIOLATION.DOC_FLAG_UNDECLARED, label, token);
908
+ }
909
+ // --- arm 3: the Purpose paragraph names every declared section title ---
910
+ //
911
+ // The Purpose paragraph is the next non-blank line after the signature. Structural, so it
912
+ // survives every translated label. Absent (signature is the last line) => title arm skipped,
913
+ // the flag arms still stand.
914
+ let p = sigIdx + 1;
915
+ while (p < lines.length && lines[p].trim() === '')
916
+ p += 1;
917
+ if (p >= lines.length)
918
+ continue;
919
+ const purpose = lines[p];
920
+ for (const title of declaredTitles) {
921
+ if (!purpose.includes(title)) {
922
+ add(exports.DOCS_PARITY_VIOLATION.DOC_TITLE_MISSING, label, title);
923
+ }
924
+ }
925
+ }
926
+ return { ok: violations.length === 0, violations, skipped };
927
+ }