@boyingliu01/xp-gate 0.38.6 → 0.38.7

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 (31) hide show
  1. package/adapters/gate-7.sh +7 -2
  2. package/gate-7.sh +7 -2
  3. package/hooks/gate-7.sh +7 -2
  4. package/hooks/gate-entries/gate-0-entry.sh +249 -28
  5. package/hooks/gate-entries/gate-1-entry.sh +81 -3
  6. package/lib/mattpocock-license-verdict.json +1 -1
  7. package/mock-policy/AGENTS.md +1 -1
  8. package/mutation/AGENTS.md +1 -1
  9. package/package.json +1 -1
  10. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  11. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  12. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  13. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  14. package/plugins/dsh/package.json +1 -1
  15. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  16. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  17. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  18. package/plugins/opencode/package.json +1 -1
  19. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  20. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  21. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  22. package/plugins/qoder/plugin.json +1 -1
  23. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  24. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  25. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  26. package/principles/AGENTS.md +1 -1
  27. package/principles/analyzer.ts +12 -1
  28. package/principles/config.ts +179 -0
  29. package/skills/delphi-review/AGENTS.md +1 -1
  30. package/skills/sprint-flow/AGENTS.md +1 -1
  31. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -16,8 +16,13 @@ IAC_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -
16
16
  # shellcheck disable=SC2034
17
17
  GATE_7_SCANNED_FILES=0
18
18
  if [ -z "$IAC_FILES" ]; then
19
- echo "✅ PASSED - No IaC files detected in changes."
20
- GATE_7_STATUS="PASS"
19
+ # #800: "nothing to scan" must never be rendered as "scanned and clean".
20
+ # This branch used to print PASSED and set GATE_7_STATUS=PASS, while the report
21
+ # simultaneously carried scanned_files=0 -- the gate contradicted itself, and
22
+ # the PASS was what downstream consumers read. A change set with no IaC file is
23
+ # a SKIP with a reason, exactly like the no-adapter branch below.
24
+ echo "⏭️ SKIPPED - IaC security (no IaC files in this change set)."
25
+ GATE_7_STATUS="SKIP"
21
26
  else
22
27
  # Consumed by the sourcing parent, not here (see #548).
23
28
  # shellcheck disable=SC2034
package/gate-7.sh CHANGED
@@ -16,8 +16,13 @@ IAC_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -
16
16
  # shellcheck disable=SC2034
17
17
  GATE_7_SCANNED_FILES=0
18
18
  if [ -z "$IAC_FILES" ]; then
19
- echo "✅ PASSED - No IaC files detected in changes."
20
- GATE_7_STATUS="PASS"
19
+ # #800: "nothing to scan" must never be rendered as "scanned and clean".
20
+ # This branch used to print PASSED and set GATE_7_STATUS=PASS, while the report
21
+ # simultaneously carried scanned_files=0 -- the gate contradicted itself, and
22
+ # the PASS was what downstream consumers read. A change set with no IaC file is
23
+ # a SKIP with a reason, exactly like the no-adapter branch below.
24
+ echo "⏭️ SKIPPED - IaC security (no IaC files in this change set)."
25
+ GATE_7_STATUS="SKIP"
21
26
  else
22
27
  # Consumed by the sourcing parent, not here (see #548).
23
28
  # shellcheck disable=SC2034
package/hooks/gate-7.sh CHANGED
@@ -16,8 +16,13 @@ IAC_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -
16
16
  # shellcheck disable=SC2034
17
17
  GATE_7_SCANNED_FILES=0
18
18
  if [ -z "$IAC_FILES" ]; then
19
- echo "✅ PASSED - No IaC files detected in changes."
20
- GATE_7_STATUS="PASS"
19
+ # #800: "nothing to scan" must never be rendered as "scanned and clean".
20
+ # This branch used to print PASSED and set GATE_7_STATUS=PASS, while the report
21
+ # simultaneously carried scanned_files=0 -- the gate contradicted itself, and
22
+ # the PASS was what downstream consumers read. A change set with no IaC file is
23
+ # a SKIP with a reason, exactly like the no-adapter branch below.
24
+ echo "⏭️ SKIPPED - IaC security (no IaC files in this change set)."
25
+ GATE_7_STATUS="SKIP"
21
26
  else
22
27
  # Consumed by the sourcing parent, not here (see #548).
23
28
  # shellcheck disable=SC2034
@@ -43,18 +43,45 @@ GATE_0_STATUS="PASS"
43
43
 
44
44
  CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null) || CURRENT_BRANCH=""
45
45
  CURRENT_BRANCH=$(printf '%s' "$CURRENT_BRANCH" | tr -d '\r\n'); [ -n "$CURRENT_BRANCH" ] || CURRENT_BRANCH="HEAD"
46
- PROTECTED_BRANCHES="master develop trunk mainline"
46
+ # #806 D1: `main` was missing from this list, so the gate ran its check on ZERO
47
+ # commits in any repo whose default branch is `main` -- which is git's own modern
48
+ # default, GitHub's default, and this repository's current branch. Measured on
49
+ # this repo: a commit staging production source with VERSION/CHANGELOG untouched
50
+ # printed "PASSED - Version Consistency Check (non-protected branch: main)".
51
+ # The literal list stays as the baseline for the historical names, but the
52
+ # authoritative answer for "what is the default branch" is git's own local
53
+ # `origin/HEAD`, consulted below -- a repo that renames its default (or inits
54
+ # with `git init -b trunk`) then needs no edit here. Read locally on purpose:
55
+ # `git remote show origin` would hit the network, and a gate must never wait on
56
+ # the network.
57
+ PROTECTED_BRANCHES="main master develop trunk mainline"
47
58
  # #711: same shape as the branch/commit captures above — `git rev-parse` can
48
59
  # print a partial line before failing, so `|| echo "."` can yield "<something>\n."
49
60
  # and every later `cd "$ROOT_DIR"` / path join would silently use a two-line value.
50
61
  ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null) || ROOT_DIR=""
51
62
  ROOT_DIR=$(printf '%s' "$ROOT_DIR" | tr -d '\r\n'); [ -n "$ROOT_DIR" ] || ROOT_DIR="."
52
63
 
64
+ # The default branch as this clone records it. `symbolic-ref` resolves the local
65
+ # ref only, so this is free and offline; it is absent in a repo that never
66
+ # fetched (a fresh `git init` has no origin), in which case the literal list above
67
+ # is all the information there is.
68
+ ORIGIN_DEFAULT_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null) || ORIGIN_DEFAULT_BRANCH=""
69
+ # Strip the remote prefix: "origin/main" -> "main".
70
+ ORIGIN_DEFAULT_BRANCH="${ORIGIN_DEFAULT_BRANCH#origin/}"
71
+ ORIGIN_DEFAULT_BRANCH=$(printf '%s' "$ORIGIN_DEFAULT_BRANCH" | tr -d '\r\n')
72
+
53
73
  # Optional: project-level .protected-branches config file
54
74
  if [ -f "$ROOT_DIR/.protected-branches" ]; then
55
75
  PROTECTED_BRANCHES="$PROTECTED_BRANCHES $(cat "$ROOT_DIR/.protected-branches" | tr '\n' ' ')"
56
76
  fi
57
77
 
78
+ # Derived last so an explicit .protected-branches entry cannot be shadowed by a
79
+ # probe failure, and empty values are dropped rather than added as a blank token
80
+ # that would make `[ "$CURRENT_BRANCH" = "" ]` true for a detached HEAD.
81
+ if [ -n "$ORIGIN_DEFAULT_BRANCH" ]; then
82
+ PROTECTED_BRANCHES="$PROTECTED_BRANCHES $ORIGIN_DEFAULT_BRANCH"
83
+ fi
84
+
58
85
  is_protected=false
59
86
  for branch in $PROTECTED_BRANCHES; do
60
87
  if [ "$CURRENT_BRANCH" = "$branch" ]; then
@@ -113,6 +140,13 @@ if [ "$is_protected" = "true" ]; then
113
140
  GATE_0_DETAIL="not_selected"
114
141
  elif [ "${SKIP_VERSION_CHECK:-}" = "1" ]; then
115
142
  echo "⏭️ SKIPPED - Gate 0: Version consistency (SKIP_VERSION_CHECK=1 env var)"
143
+ # #806 D2: this arm used to only echo, so GATE_0_STATUS kept its
144
+ # initialization value of PASS. The report (gate-13-entry.sh) counts PASS and
145
+ # SKIP in different buckets, so a skipped gate inflated the passed count and
146
+ # "skipped" was indistinguishable from "verified" -- the same defect class as
147
+ # #800, which rendered a Gate 7 SKIP as PASSED. Set it explicitly.
148
+ GATE_0_STATUS="SKIP"
149
+ GATE_0_DETAIL="skip_version_check_env"
116
150
  else
117
151
  for file in $STAGED_FILES; do
118
152
  case "$file" in
@@ -149,61 +183,248 @@ if [ "$is_protected" = "true" ]; then
149
183
  SYNC_STAGED=$((SYNC_STAGED + 1))
150
184
  fi
151
185
  done
152
- # Stage AGENTS.md files with header-only modifications (header refresh is the only thing sync-version touches in AGENTS.md)
186
+ # Stage AGENTS.md files with header-only modifications.
187
+ #
188
+ # #806 D4: this used to be `if ! git diff --quiet -- "$agents_file";
189
+ # then git add "$agents_file"; fi`, i.e. ANY modification was treated as
190
+ # a header refresh. A developer with a half-written AGENTS.md section
191
+ # would have it silently folded into an unrelated VERSION-bump commit.
192
+ # The comment said "headers" but the code never checked.
193
+ #
194
+ # sync-version rewrites exactly one line per AGENTS.md -- the pattern
195
+ # `/^\*\*Version:\*\*.*$/m` in scripts/sync-version.cjs -- so the
196
+ # legitimate diff is a single changed line matching that shape. Anything
197
+ # else means the working tree carries edits this commit did not intend to
198
+ # include, and `git add` would commit them on the user's behalf.
199
+ #
200
+ # The check is on the diff's changed lines (`^-`/`^+`, excluding the
201
+ # +++/--- file headers), not on the file content: a body line that happens
202
+ # to start with `**Version:**` is not a header refresh either.
153
203
  while IFS= read -r -d '' agents_file; do
154
- if ! git diff --quiet -- "$agents_file" 2>/dev/null; then
155
- git add "$agents_file"
156
- SYNC_STAGED=$((SYNC_STAGED + 1))
204
+ git diff --quiet -- "$agents_file" 2>/dev/null && continue
205
+ # Changed lines only. `--unified=0` keeps the hunks tight, and the
206
+ # file-header lines are dropped so they cannot be mistaken for content.
207
+ _changed_lines=$(git diff --unified=0 -- "$agents_file" 2>/dev/null \
208
+ | grep -E '^[+-]' | grep -vE '^(\+\+\+|---)')
209
+ if [ -z "$_changed_lines" ]; then
210
+ continue
211
+ fi
212
+ # Every changed line must be a version header (mode change adds none,
213
+ # so an empty diff is already handled above).
214
+ if printf '%s\n' "$_changed_lines" | grep -qvE '^[+-]\*\*Version:\*\*'; then
215
+ echo " ⚠️ NOT auto-staged: $agents_file has changes beyond the version header."
216
+ echo " Stage it yourself if you intend to include them: git add '$agents_file'"
217
+ continue
157
218
  fi
219
+ git add "$agents_file"
220
+ SYNC_STAGED=$((SYNC_STAGED + 1))
158
221
  done < <(find "$ROOT_DIR" -name 'AGENTS.md' -not -path '*/node_modules/*' -not -path '*/.git/*' -print0)
159
222
  echo " auto-staged $SYNC_STAGED file(s) from sync-version (package.json × ≤6 + AGENTS.md headers)"
160
223
  else
161
- echo "⚠️ sync-version failed; see /tmp/xp-gate-sync-version.log — continuing without auto-sync"
224
+ # #806 D3b: this used to warn and CONTINUE, then fall through to
225
+ # "✅ PASSED - (VERSION/CHANGELOG staged)". The step that just failed is
226
+ # exactly the fan-out this branch exists to perform, so continuing meant
227
+ # committing a half-updated version surface under a green Gate 0 -- the
228
+ # failure the gate is named after, reported as success. A version bump
229
+ # whose fan-out did not happen is not a version bump.
230
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
231
+ VERSION CONSISTENCY CHECK (Gate 0)
232
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
233
+ ❌ BLOCKED - VERSION is staged but sync-version FAILED, so the version
234
+ surface is only half updated.
235
+
236
+ See the log for the cause:
237
+ /tmp/xp-gate-sync-version.log
238
+
239
+ Fix the failure and retry, or bump the version with the HUD:
240
+ node scripts/sync-version.cjs
241
+ "
242
+ GATE_0_STATUS="BLOCK"
243
+ record_gate_audit "gate-0" "version-consistency" "$GATE_0_STATUS" "1" "$GATE_0_START" "sync_version_failed"
244
+ return 1
245
+ fi
246
+ fi
247
+
248
+ # ── #806 D3a: the consistency check the gate is NAMED after ──────────────
249
+ #
250
+ # Everything above only verified that VERSION or CHANGELOG.md was STAGED.
251
+ # Nothing compared the version literals, so the exact drift this gate exists
252
+ # to prevent could sit in a clean checkout while Gate 0 reported PASS.
253
+ # Measured when this was written: the repository WAS consistent
254
+ # (VERSION=0.38.5.0, package.json=0.38.5.0, package-lock.json=0.38.5.0,
255
+ # npm-package + plugin manifests=0.38.5) and nothing asserted it.
256
+ #
257
+ # Two formats, because scripts/sync-version.cjs defines two:
258
+ # FULL --- MAJOR.MINOR.PATCH.MICRO (4 parts) for VERSION, root
259
+ # package.json, and package-lock.json (top-level AND packages[""]).
260
+ # NPM --- the same string minus MICRO (3 parts) for the npm-package and
261
+ # plugin manifests, which npm requires to be semver.
262
+ # Comparing the 3-part group against the 4-part VERSION would flag EVERY
263
+ # correct repository, so the expectation is computed per file, not once.
264
+ _full_version=$(tr -d ' \t\r\n' < "$ROOT_DIR/VERSION" 2>/dev/null)
265
+ if [ -n "$_full_version" ]; then
266
+ # MICRO-stripped form, mirroring `FULL_VERSION.replace(/\.\d+$/, '')`.
267
+ _npm_version=$(printf '%s' "$_full_version" | sed -E 's/\.[0-9]+$//')
268
+ _version_drift=""
269
+
270
+ # A missing file is not drift -- not every project has every manifest, and
271
+ # inventing a failure for an absent optional file would block repositories
272
+ # that legitimately do not carry it. Only a WRONG value is drift.
273
+ for _vf in package.json src/npm-package/package.json \
274
+ plugins/claude-code/.claude-plugin/plugin.json \
275
+ plugins/opencode/package.json plugins/qoder/plugin.json \
276
+ plugins/dsh/package.json; do
277
+ [ -f "$ROOT_DIR/$_vf" ] || continue
278
+ case "$_vf" in
279
+ package.json) _expected="$_full_version" ;;
280
+ *) _expected="$_npm_version" ;;
281
+ esac
282
+ # Extract the top-level "version" string with node when available (JSON
283
+ # is not parseable with sed reliably), falling back to a narrow grep that
284
+ # only accepts a top-level-looking `"version": "x"` on its own line.
285
+ _actual=""
286
+ if command -v node >/dev/null 2>&1; then
287
+ _actual=$(node -e '
288
+ try {
289
+ const j = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
290
+ if (j && typeof j.version === "string") process.stdout.write(j.version);
291
+ } catch (e) { /* unparseable: leave empty, reported below */ }
292
+ ' "$ROOT_DIR/$_vf" 2>/dev/null)
293
+ fi
294
+ if [ -z "$_actual" ]; then
295
+ # Fallback for environments without node. Deliberately NOT anchored to
296
+ # `^[[:space:]]*"version"`: that only matches pretty-printed JSON, and
297
+ # a minified manifest (`{"version":"1.0.0"}`) then produced "no version
298
+ # field found" for a file that has one -- measured while writing this,
299
+ # where every fixture manifest is minified and the check reported drift
300
+ # on all of them.
301
+ #
302
+ # `grep -m1` limits LINES, not matches: on a minified single-line file
303
+ # it returned every `"version"` occurrence (top-level and any nested
304
+ # one), so the value came back as two concatenated lines and never
305
+ # matched. `head -1` after the extraction keeps exactly the first.
306
+ _actual=$(grep -oE '"version"[[:space:]]*:[[:space:]]*"[^"]*"' "$ROOT_DIR/$_vf" 2>/dev/null \
307
+ | head -1 \
308
+ | sed -E 's/.*:[[:space:]]*"([^"]*)"$/\1/')
309
+ fi
310
+ if [ -z "$_actual" ]; then
311
+ _version_drift="${_version_drift}
312
+ - $_vf: no version field found (expected $_expected)"
313
+ elif [ "$_actual" != "$_expected" ]; then
314
+ _version_drift="${_version_drift}
315
+ - $_vf: $_actual (expected $_expected)"
316
+ fi
317
+ done
318
+
319
+ # package-lock.json carries the version twice: the top-level field and
320
+ # packages[""]. Both must match, because npm reads the latter for the root
321
+ # entry and a stale one is the classic half-synced lockfile.
322
+ if [ -f "$ROOT_DIR/package-lock.json" ]; then
323
+ if command -v node >/dev/null 2>&1; then
324
+ _lock_versions=$(node -e '
325
+ try {
326
+ const j = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
327
+ const out = [];
328
+ if (j && typeof j.version === "string") out.push("top:" + j.version);
329
+ if (j && j.packages && j.packages[""] && typeof j.packages[""].version === "string") {
330
+ out.push("root:" + j.packages[""].version);
331
+ }
332
+ process.stdout.write(out.join("\n"));
333
+ } catch (e) { /* unparseable: reported as missing below */ }
334
+ ' "$ROOT_DIR/package-lock.json" 2>/dev/null)
335
+ if [ -n "$_lock_versions" ]; then
336
+ while IFS= read -r _lv; do
337
+ [ -n "$_lv" ] || continue
338
+ _where="${_lv%%:*}"
339
+ _value="${_lv#*:}"
340
+ if [ "$_value" != "$_full_version" ]; then
341
+ case "$_where" in
342
+ top) _label="package-lock.json (top-level version)" ;;
343
+ root) _label="package-lock.json (packages[\"\"].version)" ;;
344
+ *) _label="package-lock.json ($_where)" ;;
345
+ esac
346
+ _version_drift="${_version_drift}
347
+ - $_label: $_value (expected $_full_version)"
348
+ fi
349
+ done <<EOF
350
+ $_lock_versions
351
+ EOF
352
+ fi
353
+ fi
354
+ fi
355
+
356
+ if [ -n "$_version_drift" ]; then
357
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
358
+ VERSION CONSISTENCY CHECK (Gate 0)
359
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
360
+ ❌ BLOCKED - VERSION is $_full_version but these files disagree:$_version_drift
361
+
362
+ Run the fan-out to repair them:
363
+ node scripts/sync-version.cjs
364
+
365
+ #806 D3a: this check exists because the gate is named for it. Before it was
366
+ added, the gate only verified that VERSION was STAGED, so a forgotten
367
+ sync-version left a drifted checkout under a green Gate 0.
368
+ "
369
+ GATE_0_STATUS="BLOCK"
370
+ record_gate_audit "gate-0" "version-consistency" "$GATE_0_STATUS" "1" "$GATE_0_START" "version_drift"
371
+ return 1
162
372
  fi
163
373
  fi
164
- echo "✅ PASSED - Gate 0: Version Consistency Check (VERSION/CHANGELOG staged)"
374
+
375
+ echo "✅ PASSED - Gate 0: Version Consistency Check (VERSION/CHANGELOG staged, versions consistent)"
165
376
  else
166
377
  # Check for doc-only changes (no source code files)
167
378
  #
168
379
  # The extension list must cover every language an adapter supports, not just
169
380
  # the C-family languages this repo happens to be written in. It previously
170
381
  # stopped at `*.java`, so a staged .kt/.cs/.swift/.dart/.sh/.ps1 file made
171
- # Gate 0 report "doc-only changes" — and the doc-only path skips the REST OF
172
- # THE CHAIN. A Kotlin-only commit therefore ran no code gate at all, while
173
- # reading green. Found once the Kotlin fixtures stopped skipping themselves
174
- # (the skips had hidden it): kotlin-gate reported Gate 0 "doc-only" for a
175
- # fixture whose only staged file was BadCode.kt.
382
+ # Gate 0 report "doc-only changes" — and every downstream gate that asks
383
+ # "did any code file change?" then said no, so a Kotlin-only commit ran no
384
+ # code gate at all while reading green. Found once the Kotlin fixtures
385
+ # stopped skipping themselves (the skips had hidden it): kotlin-gate reported
386
+ # Gate 0 "doc-only" for a fixture whose only staged file was BadCode.kt.
387
+ #
388
+ # #806 D6: this comment used to say "the doc-only path skips the REST OF THE
389
+ # CHAIN", which is not how it works and would send a maintainer to the wrong
390
+ # place. Gate 0 does not skip anything -- it returns 0 and the driver
391
+ # continues. The skipping happens in each downstream gate, which asks the
392
+ # shared `changed-file-matcher` predicates whether the change set contains
393
+ # anything it should scan (see changed-file-matcher.test.bats: "doc-only
394
+ # staged files skip code, IaC, and SAST gates").
176
395
  #
177
396
  # Keep this identical to gate-5-entry.sh's CODE_EXTENSIONS, which is the list
178
397
  # the coverage gate already trusts. A second hand-maintained copy is exactly
179
398
  # how these two drifted apart.
180
- for file in $STAGED_FILES; do
181
- case "$file" in
182
- *.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.py|*.go|*.java|*.kt|*.kts|*.cs|*.csx)
183
- has_source=true
184
- ;;
185
- *.cpp|*.cc|*.cxx|*.c|*.h|*.hpp|*.swift|*.m|*.mm|*.dart|*.sh|*.ps1)
186
- has_source=true
187
- ;;
188
- *.css|*.scss|*.rs)
189
- has_source=true
190
- ;;
191
- esac
192
- done
193
-
194
- # Check for build-tooling-only changes (adapters, scripts, hooks)
399
+ # ONE loop computes both flags.
400
+ #
401
+ # #806 D5: these were two loops over $STAGED_FILES carrying a byte-identical
402
+ # extension list, so the second list could drift from the first without
403
+ # anything noticing -- the same failure mode this block's own comment warns
404
+ # about ("a second hand-maintained copy is exactly how these two drifted
405
+ # apart"). The only difference between them is the build-tooling path
406
+ # carve-out, which belongs to `has_real_source`, so it is applied inline.
407
+ has_source=false
195
408
  has_real_source=false
196
409
  for file in $STAGED_FILES; do
197
410
  case "$file" in
411
+ # Build tooling is source for `has_source` (it is code) but not for
412
+ # `has_real_source` (it needs no VERSION bump) -- so `continue` here
413
+ # skips only the second flag, keeping the single extension list below.
198
414
  src/npm-package/adapters/*|src/npm-package/scripts/*|src/npm-package/hooks/*|scripts/*|githooks/adapters/*)
199
- continue ;;
415
+ has_source=true
416
+ continue
417
+ ;;
200
418
  *.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.py|*.go|*.java|*.kt|*.kts|*.cs|*.csx)
419
+ has_source=true
201
420
  has_real_source=true
202
421
  ;;
203
422
  *.cpp|*.cc|*.cxx|*.c|*.h|*.hpp|*.swift|*.m|*.mm|*.dart|*.sh|*.ps1)
423
+ has_source=true
204
424
  has_real_source=true
205
425
  ;;
206
426
  *.css|*.scss|*.rs)
427
+ has_source=true
207
428
  has_real_source=true
208
429
  ;;
209
430
  esac
@@ -285,7 +285,16 @@ else
285
285
  # resolver probe, so there is exactly one place that decides it.
286
286
  echo "ℹ️ Biome config found but biome is not installed — SKIP Gate 1 Biome."
287
287
  echo " Install it with: npm install --save-dev @biomejs/biome"
288
- return 0
288
+ # #806 G1a: this branch used to `return 0`, which does not "skip the TS
289
+ # Biome half" -- it aborts gate_1_run entirely, so in a multi-language
290
+ # repo every language AFTER typescript was never examined. Measured on a
291
+ # fixture with PROJECT_LANGS="typescript python" and biome absent: the
292
+ # log contained `── Checking typescript ──` and never
293
+ # `── Checking python ──`, while the run reported success. Record the
294
+ # skip and let the loop continue.
295
+ GATE_1_STATUS="SKIP"
296
+ GATE_1_DETAIL="typescript: biome not installed"
297
+ continue
289
298
  fi
290
299
  if [ "$BIOME_STATUS" -ne 0 ]; then
291
300
  # Biome exits 1 with `internalError/io - No files were processed` when the
@@ -365,6 +374,11 @@ else
365
374
  if ! command -v ruff &> /dev/null; then
366
375
  echo "ℹ️ ruff not available — skipping Python linting"
367
376
  echo "⏭️ SKIPPED - Code quality (ruff not available, run: pip install ruff)"
377
+ # #806 G1a: printed a skip but left GATE_1_STATUS at its initial PASS, so the
378
+ # journal recorded "passed" for a check that never ran. The Java branch ten
379
+ # lines away sets WARN for the same situation; this is the same decision.
380
+ GATE_1_STATUS="SKIP"
381
+ GATE_1_DETAIL="python: ruff not installed"
368
382
  else
369
383
  # Run Ruff (includes syntax check, linting)
370
384
  echo "Running Ruff linting (syntax + lint)..."
@@ -525,6 +539,11 @@ else
525
539
  if ! command -v golangci-lint &> /dev/null; then
526
540
  echo "ℹ️ golangci-lint not available — skipping Go linting"
527
541
  echo "⏭️ SKIPPED - Code quality (golangci-lint not available)"
542
+ # #806 G1a: same inherited-PASS defect as the Python arm above. Verified by
543
+ # driving gate_1_run with golangci-lint absent: the skip printed and
544
+ # GATE_1_STATUS stayed "PASS" with an empty DETAIL.
545
+ GATE_1_STATUS="SKIP"
546
+ GATE_1_DETAIL="go: golangci-lint not installed"
528
547
  else
529
548
  # #534: run golangci-lint over ONLY the staged .go files (incremental),
530
549
  # not the whole repo. `golangci-lint run` with no args scans every package
@@ -795,8 +814,62 @@ else
795
814
  echo "Running lint check for $CURRENT_LANG..."
796
815
  G1L_OUTPUT=""
797
816
  G1L_EXIT=0
798
- G1L_OUTPUT=$(run_lint 2>&1) || G1L_EXIT=$?
799
- [ -n "$G1L_OUTPUT" ] && printf '%s\n' "$G1L_OUTPUT" | head -30
817
+ # #806 G1c: some adapters define `run_lint() { run_static_analysis; }`
818
+ # verbatim (kotlin, cpp, csharp, objectivec), so this arm executed the
819
+ # SAME analysis twice and printed the identical findings twice. Measured
820
+ # on the Kotlin fixture: a single detekt+ktlint pass takes 1.7-2.2 s and
821
+ # the total Gate 1 run took 6.6 s, i.e. roughly 2 s (30%) was pure
822
+ # duplication.
823
+ #
824
+ # Detected by comparing the two function DEFINITIONS, not by naming the
825
+ # languages: a language list here would be hand-maintained and would miss
826
+ # the next adapter that aliases the two -- the same way Gate 0's two
827
+ # hand-copied extension lists drifted apart (#806 D5). `declare -f`
828
+ # prints the body, so identical bodies compare equal.
829
+ #
830
+ # Errs toward doing the work: anything the gate cannot prove identical
831
+ # runs twice, which costs time but never skips verification.
832
+ #
833
+ # `declare -f` prints the function NAME plus its body, so comparing the
834
+ # two outputs directly can never be equal -- measured: kotlin's
835
+ # run_lint declaration is 42 bytes ("run_lint () { run_static_analysis; }")
836
+ # against run_static_analysis's 1710. The name line is therefore stripped
837
+ # from run_lint's declaration and the remaining body is compared with
838
+ # run_static_analysis' BODY. Two shapes have to be recognised, because an
839
+ # alias in this codebase is written both ways:
840
+ # run_lint() { run_static_analysis; } -> body is the call
841
+ # run_lint() { return run_static_analysis; } -> body is `return <call>`
842
+ # Anything else runs normally.
843
+ # Normalise to one line with no blanks. `tr -d ' \t\n'` collapses
844
+ # everything INCLUDING newlines, so no separator can be left behind.
845
+ # The first attempt ended with `tr '\n' ' '`, which left a trailing space
846
+ # ("[run_static_analysis ]") that compared unequal to the expected token,
847
+ # so the detection silently never fired while `bash -n` stayed clean.
848
+ G1_RUN_LINT_BODY=$(declare -f run_lint 2>/dev/null \
849
+ | sed -e '1d' -e '/^[[:space:]]*[{}][[:space:]]*$/d' \
850
+ | tr -d ' \t\n' | sed -e 's/;$//')
851
+ G1_ANALYSIS_BODY=$(declare -f run_static_analysis 2>/dev/null \
852
+ | sed -e '1d' -e '/^[[:space:]]*[{}][[:space:]]*$/d' \
853
+ | tr -d ' \t\n' | sed -e 's/;$//')
854
+ G1_LINT_IS_ANALYSIS=0
855
+ if [ -n "$G1_RUN_LINT_BODY" ]; then
856
+ if [ "$G1_RUN_LINT_BODY" = "run_static_analysis" ] \
857
+ || [ "$G1_RUN_LINT_BODY" = "returnrun_static_analysis" ]; then
858
+ G1_LINT_IS_ANALYSIS=1
859
+ elif [ -n "$G1_ANALYSIS_BODY" ] && [ "$G1_RUN_LINT_BODY" = "$G1_ANALYSIS_BODY" ]; then
860
+ # A literal copy of the analysis body is also "the same check".
861
+ G1_LINT_IS_ANALYSIS=1
862
+ fi
863
+ fi
864
+ if [ "$G1_LINT_IS_ANALYSIS" -eq 1 ]; then
865
+ # Same check: reuse the verdict already obtained above instead of
866
+ # paying for a second identical tool invocation.
867
+ G1L_EXIT="$G1A_EXIT"
868
+ echo " (lint and static analysis are the same check for $CURRENT_LANG — ran once)"
869
+ else
870
+ G1L_OUTPUT=$(run_lint 2>&1) || G1L_EXIT=$?
871
+ [ -n "$G1L_OUTPUT" ] && printf '%s\n' "$G1L_OUTPUT" | head -30
872
+ fi
800
873
 
801
874
  # The stricter of the two verdicts wins. Note 3 (WARN) must not mask a 1
802
875
  # or 2 from the other command: a clean formatter plus a failing analyzer
@@ -844,6 +917,11 @@ else
844
917
  # If no adapter exists for this language, skip
845
918
  echo "ℹ️ No specific adapter for $CURRENT_LANG — using generic checks if any"
846
919
  echo "⏭️ SKIPPED - Code quality (no specific checks for $CURRENT_LANG)"
920
+ # #806 G1a: an unhandled language reported SKIP in prose and PASS in the
921
+ # journal. This is the arm that covers every language xp-gate has no
922
+ # adapter for, so it was the single widest inherited-PASS hole in Gate 1.
923
+ GATE_1_STATUS="SKIP"
924
+ GATE_1_DETAIL="${CURRENT_LANG}: no adapter"
847
925
  fi
848
926
  ;;
849
927
  esac
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-16T11:06:36.263Z",
5
+ "checked_at": "2026-11-16T16:05:26.675Z",
6
6
  "source": "network"
7
7
  }
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Mock layering policy enforcement — Gate M3 of pre-push hook. Ensures integration tests use real implementations for internal dependencies, mock external dependencies, and annotate pending mocks with removal plans. Combines project scope scanning, mock decision engine, and per-file validation into a single pipeline.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **Gate M** (incremental mutation testing) + **Gate M2** helpers (test-layer detection used by `src/mock-policy/`). Pre-push quality gate. TypeScript-only; uses Stryker.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.38.6",
3
+ "version": "0.38.7",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.6",
3
+ "version": "0.38.7",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/dsh-plugin-xp-gate",
3
- "version": "0.38.5",
3
+ "version": "0.38.7",
4
4
  "description": "XP-Gate deterministic quality gates + AI workflow skills as a DeepSeek Harness (DSH) native plugin: gate-check / gate-principles / gate-arch tools + 12 SKILL.md skills",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.38.6",
3
+ "version": "0.38.7",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.5",
3
+ "version": "0.38.7",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Qoder. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Clean Code & SOLID principles checker — **Gate 4** of pre-commit. 14 rules × 9 language adapters, SARIF 2.1.0 output. Houses the **Boy Scout Rule** enforcement engine (Gate 6) and warning-baseline storage.
@@ -1,5 +1,5 @@
1
1
  import { Rule, Violation, Adapter } from './types';
2
- import { getActiveConfig } from './config';
2
+ import { getActiveConfig, resolveSeverityForFile } from './config';
3
3
  import { TypeScriptAdapter } from './adapters/typescript';
4
4
  import { PythonAdapter } from './adapters/python';
5
5
  import { GoAdapter } from './adapters/go';
@@ -129,6 +129,17 @@ function runRuleOnFile(ctx: RunRuleContext): void {
129
129
  try {
130
130
  const ruleViolations = rule.check(file, adapter);
131
131
  if (ruleViolations.length > 0) {
132
+ // Path-scoped severity overrides (#806), applied centrally so no rule has
133
+ // to know about them and a new rule cannot forget to honour them. Only the
134
+ // severity is remapped -- the violation is kept, so "reported but advisory"
135
+ // stays distinguishable from "nothing found".
136
+ for (const violation of ruleViolations) {
137
+ violation.severity = resolveSeverityForFile(
138
+ rule.id,
139
+ violation.file || file,
140
+ violation.severity
141
+ ) as Violation['severity'];
142
+ }
132
143
  violations.push(...ruleViolations);
133
144
  fileResult.violations.push(...ruleViolations);
134
145
  fileResult.ruleIds.push(rule.id);
@@ -10,6 +10,28 @@ export interface RuleConfig {
10
10
  methodThreshold?: number;
11
11
  }
12
12
 
13
+ /**
14
+ * A path-scoped severity relaxation (#806).
15
+ *
16
+ * `severity` in `rules` is one global value per rule, so a project could not both
17
+ * block a rule in production and keep it advisory in tests. Measured here with
18
+ * four rules promoted to `error`: 220 of 271 findings were in test files, so
19
+ * enabling production blocking would have blocked nearly every test edit -- and
20
+ * demoting the rule globally re-opened the defect the promotion existed to fix.
21
+ *
22
+ * These entries may only RELAX a rule (error -> warning/info). They never
23
+ * promote and never suppress: the violation is still reported, only its severity
24
+ * changes for matching paths. See `resolveSeverityForFile`.
25
+ */
26
+ export interface SeverityOverride {
27
+ // POSIX-style globs matched against the file path, e.g. any `__tests__`
28
+ // directory at any depth. Written as a line comment on purpose: a block
29
+ // comment cannot carry a globstar path, because the `/` after `**` closes it.
30
+ paths: string[];
31
+ /** `"<group>.<rule>"` -> target severity. */
32
+ rules: Record<string, string>;
33
+ }
34
+
13
35
  interface PrinciplesConfig {
14
36
  rules: {
15
37
  'clean-code': {
@@ -54,6 +76,8 @@ interface PrinciplesConfig {
54
76
  mode?: string;
55
77
  mediumProjectDefinition?: string;
56
78
  };
79
+ /** Path-scoped severity relaxations, applied in order (#806). */
80
+ overrides?: SeverityOverride[];
57
81
  }
58
82
 
59
83
  /** Config keys that carry a numeric threshold, per group. */
@@ -267,6 +291,10 @@ function mergeConfig(
267
291
  // just outside `rules`; found by the Delphi walkthrough.
268
292
  output: mergeSection(defaults.output, user.output),
269
293
  performance: mergeSection(defaults.performance, user.performance),
294
+ // Explicit: `...user` would carry the RAW block through unvalidated, so a
295
+ // malformed override would reach the resolver and fail there instead of
296
+ // being reported once, at load, with a message naming the bad entry.
297
+ overrides: parseOverrides(user.overrides, '.principlesrc'),
270
298
  rules: {
271
299
  'clean-code': mergeGroup(
272
300
  defaults.rules['clean-code'],
@@ -479,4 +507,155 @@ export function setActiveConfig(config: PrinciplesConfig): void {
479
507
  export function resetActiveConfig(): void {
480
508
  activeConfig = getDefaultConfig();
481
509
  activeConfigInstalled = false;
510
+ }
511
+
512
+ // ---------------------------------------------------------------------------
513
+ // Path-scoped severity overrides (#806)
514
+ // ---------------------------------------------------------------------------
515
+
516
+ /** Severity order, most to least severe. Used to forbid upward overrides. */
517
+ const SEVERITY_RANK: Record<string, number> = { error: 3, warning: 2, info: 1 };
518
+
519
+ /**
520
+ * Translate a POSIX-style glob to a RegExp.
521
+ *
522
+ * Deliberately small: this supports the two shapes the feature needs (`**` across
523
+ * directories, `*` within one segment) plus `?`. Anything richer belongs in a
524
+ * glob library, and pulling a dependency into `src/npm-package` is forbidden.
525
+ *
526
+ * `**` becomes `.*` (so `**​/__tests__/**` matches a nested test dir AND an
527
+ * absolute native path), `*` becomes `[^/]*`, and regex metacharacters are
528
+ * escaped so a literal `.` in `*.test.ts` does not match `a_test.ts`.
529
+ */
530
+ function globToRegExp(glob: string): RegExp {
531
+ let out = '';
532
+ for (let i = 0; i < glob.length; i++) {
533
+ const ch = glob[i];
534
+ if (ch === '*') {
535
+ if (glob[i + 1] === '*') {
536
+ out += '.*';
537
+ i++;
538
+ // `**/` may match zero segments (`src/__tests__/a.ts` for `/src/**`).
539
+ if (glob[i + 1] === '/') i++;
540
+ } else {
541
+ out += '[^/]*';
542
+ }
543
+ } else if (ch === '?') {
544
+ out += '[^/]';
545
+ } else if ('\\^$.|+()[]{}'.includes(ch)) {
546
+ out += `\\${ch}`;
547
+ } else {
548
+ out += ch;
549
+ }
550
+ }
551
+ return new RegExp(`^${out}$`);
552
+ }
553
+
554
+ /** Normalise a path for matching: native separators -> POSIX. */
555
+ function normaliseForMatch(filePath: string): string {
556
+ return filePath.replace(/\\/g, '/');
557
+ }
558
+
559
+ /**
560
+ * Whether `filePath` matches `glob`.
561
+ *
562
+ * Tries the whole path first, then every trailing segment run, so a repo-relative
563
+ * glob also matches a file handed to the checker as an absolute native path. Gate
564
+ * 4 passes repo-relative paths, but `--files` accepts absolute ones and the
565
+ * override must not silently stop applying because the caller changed shape.
566
+ */
567
+ function matchesGlob(filePath: string, glob: string): boolean {
568
+ const target = normaliseForMatch(filePath);
569
+ const re = globToRegExp(normaliseForMatch(glob));
570
+ if (re.test(target)) return true;
571
+ const segments = target.split('/');
572
+ for (let i = 1; i < segments.length; i++) {
573
+ if (re.test(segments.slice(i).join('/'))) return true;
574
+ }
575
+ return false;
576
+ }
577
+
578
+ /**
579
+ * The severity to report for one rule on one file.
580
+ *
581
+ * Starts from the declared severity (the caller passes what the rule would emit)
582
+ * and lets a matching override RELAX it. Relaxing only is enforced by rank, not
583
+ * by convention: a stray override must never turn an advisory rule into a
584
+ * blocker, because that would make the gate's reach depend on path globs nobody
585
+ * reviewed.
586
+ *
587
+ * Never suppresses the violation -- the finding is still reported. Only its
588
+ * severity changes, so the "passed with warnings" case stays distinguishable
589
+ * from "nothing found".
590
+ */
591
+ export function resolveSeverityForFile(
592
+ ruleId: string,
593
+ filePath: string,
594
+ declaredSeverity: string
595
+ ): string {
596
+ const overrides = activeConfig.overrides;
597
+ if (!Array.isArray(overrides) || overrides.length === 0) return declaredSeverity;
598
+
599
+ let effective = declaredSeverity;
600
+ const declaredRank = SEVERITY_RANK[declaredSeverity] ?? 0;
601
+ for (const entry of overrides) {
602
+ const target = entry?.rules?.[ruleId];
603
+ if (!target) continue;
604
+ const targetRank = SEVERITY_RANK[target];
605
+ // Unknown severity or an upward move: ignore rather than guess.
606
+ if (targetRank === undefined || targetRank >= declaredRank) continue;
607
+ if (!entry.paths.some(p => matchesGlob(filePath, p))) continue;
608
+ // A later override may relax further, never tighten back up.
609
+ if (targetRank < (SEVERITY_RANK[effective] ?? 0)) effective = target;
610
+ }
611
+ return effective;
612
+ }
613
+
614
+ /**
615
+ * Validate the `overrides` block, dropping malformed entries with a warning.
616
+ *
617
+ * A config typo must not take Gate 4 down, and it must not silently do nothing
618
+ * either -- both would be the silent-defaults defect this module removes. The
619
+ * same reasoning as `mergeRule`, applied to a nested structure.
620
+ */
621
+ function parseOverrides(raw: unknown, source: string): SeverityOverride[] {
622
+ if (raw === undefined) return [];
623
+ if (!Array.isArray(raw)) {
624
+ warn(`"overrides" in ${source} must be an array — ignored`);
625
+ return [];
626
+ }
627
+ const out: SeverityOverride[] = [];
628
+ for (const [index, entry] of raw.entries()) {
629
+ if (!isPlainObject(entry)) {
630
+ warn(`overrides[${index}] in ${source} must be an object — ignored`);
631
+ continue;
632
+ }
633
+ const paths = entry.paths;
634
+ if (!Array.isArray(paths) || paths.length === 0 || paths.some(p => typeof p !== 'string')) {
635
+ warn(`overrides[${index}].paths in ${source} must be a non-empty string array — ignored`);
636
+ continue;
637
+ }
638
+ const rules = entry.rules;
639
+ if (!isPlainObject(rules) || Object.keys(rules).length === 0) {
640
+ warn(`overrides[${index}].rules in ${source} must be a non-empty object — ignored`);
641
+ continue;
642
+ }
643
+ const cleanRules: Record<string, string> = {};
644
+ for (const [ruleId, severity] of Object.entries(rules)) {
645
+ if (typeof severity !== 'string' || !(SEVERITIES as readonly string[]).includes(severity)) {
646
+ warn(
647
+ `overrides[${index}].rules["${ruleId}"] in ${source} must be one of ${SEVERITIES.join('|')} — ignored`
648
+ );
649
+ continue;
650
+ }
651
+ if (!ruleId.includes('.')) {
652
+ warn(`overrides[${index}].rules["${ruleId}"] in ${source} must be "<group>.<rule>" — ignored`);
653
+ continue;
654
+ }
655
+ cleanRules[ruleId] = severity;
656
+ }
657
+ if (Object.keys(cleanRules).length === 0) continue;
658
+ out.push({ paths: paths as string[], rules: cleanRules });
659
+ }
660
+ return out;
482
661
  }
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.6.0
6
+ **Version:** 0.38.7.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.