@boyingliu01/xp-gate 0.39.2 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/adapters/gate-12-file-hygiene.sh +103 -15
  2. package/adapters/gate-6-layers.sh +158 -16
  3. package/gate-12-file-hygiene.sh +103 -15
  4. package/gate-6-layers.sh +158 -16
  5. package/hooks/gate-12-file-hygiene.sh +103 -15
  6. package/hooks/gate-6-layers.sh +158 -16
  7. package/hooks/gate-entries/gate-5-entry.sh +52 -2
  8. package/hooks/gate-entries/gate-6-entry.sh +86 -3
  9. package/hooks/lib/gate-12-blob-scan.awk +42 -2
  10. package/hooks/pre-commit +46 -2
  11. package/lib/gate-runner.js +52 -13
  12. package/mutation/init-baseline.ts +82 -26
  13. package/mutation/runners/mutmut-runner.ts +110 -26
  14. package/package.json +1 -1
  15. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  16. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  17. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  18. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  19. package/plugins/dsh/package.json +1 -1
  20. package/plugins/dsh/scripts/prepack.cjs +39 -14
  21. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  22. package/plugins/dsh/skills/reinstall-xp-gate/.architecture-skip +8 -0
  23. package/plugins/dsh/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
  24. package/plugins/dsh/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
  25. package/plugins/dsh/skills/reinstall-xp-gate/LICENSE +21 -0
  26. package/plugins/dsh/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
  27. package/plugins/dsh/skills/reinstall-xp-gate/README.md +167 -0
  28. package/plugins/dsh/skills/reinstall-xp-gate/SKILL.md +271 -0
  29. package/plugins/dsh/skills/reinstall-xp-gate/TODO.md +253 -0
  30. package/plugins/dsh/skills/reinstall-xp-gate/VERSION +1 -0
  31. package/plugins/dsh/skills/reinstall-xp-gate/package.json +28 -0
  32. package/plugins/dsh/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
  33. package/plugins/dsh/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
  34. package/plugins/dsh/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
  35. package/plugins/dsh/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
  36. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
  37. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
  38. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
  39. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
  40. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
  41. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
  42. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
  43. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
  44. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
  45. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
  46. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
  47. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/probes.mjs +128 -0
  48. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
  49. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
  50. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
  51. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
  52. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
  53. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +181 -0
  54. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
  55. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
  56. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
  57. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
  58. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
  59. package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
  60. package/plugins/dsh/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
  61. package/plugins/dsh/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
  62. package/plugins/dsh/skills/reinstall-xp-gate/scripts/reinstall.mjs +305 -0
  63. package/plugins/dsh/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
  64. package/plugins/dsh/skills/reinstall-xp-gate/scripts/verify.mjs +239 -0
  65. package/plugins/dsh/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
  66. package/plugins/dsh/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
  67. package/plugins/dsh/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
  68. package/plugins/dsh/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
  69. package/plugins/dsh/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
  70. package/plugins/dsh/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
  71. package/plugins/dsh/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
  72. package/plugins/dsh/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
  73. package/plugins/dsh/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
  74. package/plugins/dsh/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
  75. package/plugins/dsh/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
  76. package/plugins/dsh/skills/reinstall-xp-gate/tests/proc.test.mjs +255 -0
  77. package/plugins/dsh/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
  78. package/plugins/dsh/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
  79. package/plugins/dsh/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
  80. package/plugins/dsh/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
  81. package/plugins/dsh/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
  82. package/plugins/dsh/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
  83. package/plugins/dsh/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
  84. package/plugins/dsh/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
  85. package/plugins/dsh/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
  86. package/plugins/dsh/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
  87. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  88. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  89. package/plugins/opencode/package.json +1 -1
  90. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  91. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  92. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  93. package/plugins/qoder/plugin.json +1 -1
  94. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  95. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  96. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  97. package/principles/adapters/function-body.ts +60 -0
  98. package/principles/adapters/typescript.ts +54 -4
  99. package/principles/config.ts +16 -3
  100. package/scripts/delphi-repo-tools.cjs +4 -1
  101. package/skills/delphi-review/AGENTS.md +1 -1
  102. package/skills/sprint-flow/AGENTS.md +1 -1
  103. package/skills/test-specification-alignment/AGENTS.md +1 -1
package/gate-6-layers.sh CHANGED
@@ -43,17 +43,24 @@ set -uo pipefail
43
43
  LAYER_CONFIG="${XP_GATE_LAYER_CONFIG:-architecture.yaml}"
44
44
  LAYER_BASELINE="${XP_GATE_LAYER_BASELINE:-.layer-baseline.json}"
45
45
  LAYER_SCAN_ROOT="${XP_GATE_LAYER_SCAN_ROOT:-.}"
46
- LAYER_REASON=""
47
46
 
48
47
  # ─── Output helpers ─────────────────────────────────────────────────────────
49
48
  _layers_say() { echo " $*"; }
50
49
 
51
- _layers_verdict() {
50
+ function _layers_verdict() {
52
51
  local code="$1" text="$2" reason="${3:-}"
53
- _layers_say "$text"
52
+ # An empty text is deliberate on the blocking path: the violation lines were
53
+ # already printed, and this call exists only to attach the reason and the exit
54
+ # code. Printing the empty string would emit a blank indented line.
55
+ [ -n "$text" ] && _layers_say "$text"
56
+ # The reason reaches the gate entry through the printed line, not through a
57
+ # variable: this script runs as a child process, so nothing it assigns can be
58
+ # read by the caller. Storing it in LAYER_REASON as well made it a write-only
59
+ # global -- shellcheck SC2034, which this repository treats as a real defect
60
+ # rather than noise (the same signal that exposed GATE_6_LAYER_STATUS being
61
+ # assigned six times and read zero).
54
62
  if [ -n "$reason" ]; then
55
63
  _layers_say " reason: $reason"
56
- LAYER_REASON="$reason"
57
64
  fi
58
65
  exit "$code"
59
66
  }
@@ -71,7 +78,37 @@ fi
71
78
  LAYER_TSV=$(awk '
72
79
  function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s }
73
80
  function unq(s) { s = trim(s); gsub(/^["\047]|["\047]$/, "", s); return s }
74
- # Split a YAML flow/block list into a comma-joined string of unquoted items.
81
+ # #785: a YAML list has TWO spellings and this parser only understood one.
82
+ # allowedImports: [shared] # flow -- on the same line as the key
83
+ # allowedImports: # block -- items on the FOLLOWING lines
84
+ # - shared
85
+ # The block form parsed to an EMPTY string, i.e. an allow-list that permits
86
+ # nothing, so a repository using the standard spelling had every legal import
87
+ # reported as a violation. That direction is the expensive one: a gate that
88
+ # accuses compliant code gets baselined, and a baselined gate stops being read.
89
+ #
90
+ # `listkey` records which list a bare `- item` sequence belongs to. It is reset
91
+ # by any other key, so an item can never attach to the wrong list.
92
+ #
93
+ # list_value() takes the inline part (flow, or a one-line scalar) and records
94
+ # the key so that a following block sequence can be appended. It returns the
95
+ # same comma-joined form clean() produces, so downstream code is unchanged.
96
+ function list_value(which, rest, v) {
97
+ v = clean(rest)
98
+ listkey = (v == "" ? which : "")
99
+ return v
100
+ }
101
+ # Append one `- item` line to the list named by listkey.
102
+ function append_item(which, line, item, cur) {
103
+ item = unq(trim(substr(trim(line), 2)))
104
+ if (item == "") return
105
+ cur = (which == "pattern") ? pattern : (which == "allowed") ? allowed : forbidden
106
+ cur = (cur == "" ? item : cur "," item)
107
+ if (which == "pattern") pattern = cur
108
+ else if (which == "allowed") allowed = cur
109
+ else forbidden = cur
110
+ }
111
+ # Split a YAML flow list into a comma-joined string of unquoted items.
75
112
  function clean(v, k,i,p,out) {
76
113
  v = trim(v); sub(/#.*$/, "", v); v = trim(v)
77
114
  sub(/^\[/, "", v); sub(/\]$/, "", v)
@@ -104,6 +141,7 @@ LAYER_TSV=$(awk '
104
141
  BEGIN {
105
142
  inlayers = 0; layerindent = -1
106
143
  name = ""; pattern = ""; allowed = ""; forbidden = ""
144
+ listkey = ""
107
145
  }
108
146
  /^[ \t]*#/ { next }
109
147
  /^[ \t]*$/ { next }
@@ -120,6 +158,7 @@ LAYER_TSV=$(awk '
120
158
  if (indent == layerindent && body ~ /^[A-Za-z0-9_-]+:[ \t]*$/) {
121
159
  flush()
122
160
  name = substr(body, 1, index(body, ":") - 1)
161
+ listkey = ""
123
162
  next
124
163
  }
125
164
  if (indent == layerindent && body ~ /^- /) { next }
@@ -131,9 +170,26 @@ LAYER_TSV=$(awk '
131
170
  # naturally. Accepting only one of the two made a correct config parse to an
132
171
  # empty pattern list, which then matched no file and reported "0 violations"
133
172
  # — the silent-pass shape this gate exists to remove.
134
- else if (body ~ /^patterns?:/) { pattern = clean(substr(body, index(body, ":") + 1)) }
135
- else if (body ~ /^allowedImports:/ || body ~ /^allowed_imports:/) { allowed = clean(substr(body, index(body, ":") + 1)) }
136
- else if (body ~ /^forbiddenImports:/ || body ~ /^forbidden_imports:/) { forbidden = clean(substr(body, index(body, ":") + 1)) }
173
+ else if (body ~ /^patterns?:/) { pattern = list_value("pattern", substr(body, index(body, ":") + 1)) }
174
+ else if (body ~ /^allowedImports:/ || body ~ /^allowed_imports:/) { allowed = list_value("allowed", substr(body, index(body, ":") + 1)) }
175
+ else if (body ~ /^forbiddenImports:/ || body ~ /^forbidden_imports:/) { forbidden = list_value("forbidden", substr(body, index(body, ":") + 1)) }
176
+ else if (listkey != "" && body ~ /^- /) { append_item(listkey, body) }
177
+ # #785 follow-up (Delphi round 1, two experts independently): ANY other line
178
+ # ends the block sequence. Without this, an unrecognised key -- `notes:`,
179
+ # `description:`, a field added later -- left `listkey` pointing at the list
180
+ # above, and the items under that key were appended to it.
181
+ #
182
+ # Measured 2026-08-30 before the fix: `allowedImports:` block list followed by
183
+ # `notes:` + `- shared` silently added `shared` to the allow-list. Silent in
184
+ # that direction, and a DENIAL in the other, which is the worse half: a
185
+ # comment holding in a block list could deny an import that nobody forbade.
186
+ #
187
+ # Reset rather than "only when the line is not an item": an item belongs to
188
+ # the key that IMMEDIATELY precedes it, and a blank line or a comment between
189
+ # them ends the sequence in YAML too. (Blank and comment lines are skipped
190
+ # before this block, so they do not reset -- matching YAML, where they are
191
+ # not significant.)
192
+ else if (body ~ /^[A-Za-z0-9_-]+:/) { listkey = "" }
137
193
  }
138
194
  END { flush() }
139
195
  ' "$LAYER_CONFIG" 2>/dev/null)
@@ -194,6 +250,9 @@ LAYER_CLASSIFIED=0
194
250
  # and a stdin-driven loop leaves FILENAME empty — every file would be assigned
195
251
  # layer 0 and the scan would report a clean tree. That is exactly the failure
196
252
  # mode this gate exists to prevent, so the plumbing has to be right first.
253
+ # shellcheck disable=SC2086 # $FILE_LIST MUST be word-split: awk builds FILENAME
254
+ # from ARGV, and one quoted argument would be treated as a single filename, which
255
+ # leaves every file unclassified (see the comment on FILENAME above).
197
256
  FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk '
198
257
  BEGIN {
199
258
  n = 0
@@ -235,11 +294,76 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
235
294
  }
236
295
  return best
237
296
  }
297
+ # #862: the same lookup for a RESOLVED IMPORT TARGET.
298
+ #
299
+ # resolve() strips the extension from a specifier, so `./router` arrives as
300
+ # `src/router` while a pattern that names a FILE keeps it (`src/router.js`).
301
+ # Matching only the literal form left every file-level boundary unenforced --
302
+ # and an unclassified target is not a violation, so the verdict was "0
303
+ # violations" over a real forbidden edge.
304
+ #
305
+ # A compiled pattern regex is therefore tried in both directions: as written,
306
+ # and against the extension-stripped target. Directory patterns
307
+ # (`src/lib/**`) end in a slash or a wildcard and match the first way, so they
308
+ # are unaffected.
309
+ function layer_of_target(tgt, best, k, j, cand, exts) {
310
+ best = layer_of(tgt)
311
+ if (best != 0) return best
312
+ # The target has NO extension (resolve() stripped it) while a FILE pattern
313
+ # keeps one -- so the candidate is the target WITH each possible extension,
314
+ # not the other way round. Getting this backwards looks equivalent and is
315
+ # not: there is nothing to strip from `src/router`.
316
+ if (tgt ~ /[.](ts|tsx|js|jsx|mjs|cjs)$/) return 0
317
+ exts = "ts tsx js jsx mjs cjs"
318
+ k = split(exts, E)
319
+ for (j = 1; j <= k; j++) {
320
+ cand = tgt "." E[j]
321
+ best = layer_of(cand)
322
+ if (best != 0) return best
323
+ }
324
+ return 0
325
+ }
238
326
  function in_csv(list, val, k, j, p) {
239
327
  k = split(list, p, ",")
240
328
  for (j = 1; j <= k; j++) if (p[j] == val) return 1
241
329
  return 0
242
330
  }
331
+ # Does one list ENTRY describe this import? Two accepted forms, one answer.
332
+ #
333
+ # * a bare layer name -- matches the destination layer ("shared")
334
+ # * a path glob -- matched against the resolved target path
335
+ #
336
+ # #862: the resolved target has its EXTENSION STRIPPED (resolve() maps
337
+ # `./router` onto `src/router`), while a pattern naming a FILE keeps it
338
+ # (`src/router.js`). The two never compared equal, so a file-level boundary was
339
+ # never enforced -- and an unclassified target is not a violation, so the gate
340
+ # reported "0 violations" over a real forbidden edge. Directory patterns end in
341
+ # `/` or `/**` and were unaffected, which is why this survived: every example in
342
+ # the docs used a directory.
343
+ #
344
+ # Both spellings of the tail are tried, so a file pattern works whether the
345
+ # author wrote it with or without the extension.
346
+ function entry_matches(entry, tgt, dstname, stem) {
347
+ if (entry == dstname) return 1
348
+ if (entry ~ /[*]/) {
349
+ if (tgt ~ pat2re(entry)) return 1
350
+ stem = entry
351
+ if (sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", stem) && stem != entry) {
352
+ if (tgt ~ pat2re(stem)) return 1
353
+ }
354
+ return 0
355
+ }
356
+ if (tgt == entry || tgt ~ ("^" entry "/")) return 1
357
+ # A file pattern without a trailing slash: compare the extension-stripped
358
+ # target against the extension-stripped entry, and the target against the
359
+ # entry as written.
360
+ stem = entry
361
+ if (stem ~ /[.](ts|tsx|js|jsx|mjs|cjs)$/) {
362
+ sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", stem)
363
+ if (tgt == stem) return 1
364
+ }
365
+ return 0
366
+ }
243
367
  # `allowedImports` is written as path globs in this config ("src/shared/**")
244
368
  # but reads naturally as layer names ("domain"). Accept both: a path glob is
245
369
  # matched against the resolved target path, a bare identifier against the
@@ -250,9 +374,7 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
250
374
  k = split(lallow[idx], p, ",")
251
375
  for (j = 1; j <= k; j++) {
252
376
  if (p[j] == "") continue
253
- if (p[j] == dstname) return 1
254
- if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
255
- if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
377
+ if (entry_matches(p[j], tgt, dstname)) return 1
256
378
  }
257
379
  return 0
258
380
  }
@@ -266,9 +388,7 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
266
388
  k = split(lforb[idx], p, ",")
267
389
  for (j = 1; j <= k; j++) {
268
390
  if (p[j] == "") continue
269
- if (p[j] == dstname) return 1
270
- if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
271
- if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
391
+ if (entry_matches(p[j], tgt, dstname)) return 1
272
392
  }
273
393
  return 0
274
394
  }
@@ -328,7 +448,11 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
328
448
  if (src == 0 || spec == "") continue
329
449
  tgt = resolve(file, spec)
330
450
  if (tgt == "") continue
331
- dst = layer_of(tgt)
451
+ # #862: a FILE-level layer pattern keeps its extension while the resolved
452
+ # target does not, so membership is looked up through layer_of_target().
453
+ # An unclassified target is silently not a violation, which is how a real
454
+ # forbidden edge became "0 violations".
455
+ dst = layer_of_target(tgt)
332
456
  if (dst == 0 || dst == src) continue
333
457
  # Denial before grant: an explicit forbiddenImports entry is never
334
458
  # cancelled by a broader allowedImports entry.
@@ -423,4 +547,22 @@ if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
423
547
  fi
424
548
  _layers_say " A layer may import only what its allowedImports lists."
425
549
  _layers_say " To accept an existing violation, record it in $LAYER_BASELINE."
426
- exit 1
550
+ # #852: this block used a bare `exit 1`, so the exit-1 path was the ONE verdict
551
+ # that carried no `reason:` line. The gate entry recovers the reason by parsing
552
+ # `reason:` out of this output, so a real, measured layer BLOCK arrived at the
553
+ # report with an empty reason -- which then fell through to the
554
+ # "layers_config_not_enforced" placeholder and described the opposite situation
555
+ # (nothing measured, rather than a violation found).
556
+ #
557
+ # Going through _layers_verdict makes the reason structural: every exit code
558
+ # this script can produce now says why. A verdict without a reason is treated as
559
+ # a defect in this repository, and this was the last path that produced one.
560
+ #
561
+ # The edge kind is part of the reason because the two diagnoses differ: a
562
+ # forbidden edge must be removed, an unlisted one must be declared.
563
+ if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
564
+ _layers_reason="layer_violation_forbidden_import"
565
+ else
566
+ _layers_reason="layer_violation_unlisted_import"
567
+ fi
568
+ _layers_verdict 1 "" "$_layers_reason"
@@ -155,6 +155,9 @@ GATE_12_SCANNER="${GATE_12_SCANNER:-}"
155
155
  GATE_12_HAS_TRAILING_WS=" "
156
156
  GATE_12_MISSING_EOF=" "
157
157
  GATE_12_HAS_CONFLICT=" "
158
+ # #863: set when the blob scanner refused (exit 3) or failed. An unset value means
159
+ # the scan completed; the verdict block reads it before reporting clean.
160
+ GATE_12_BLOB_SCAN_ERROR=""
158
161
 
159
162
  _g12_scan_blobs() {
160
163
  # ONE awk process for the whole change set (see githooks/lib/gate-12-blob-scan.awk
@@ -164,9 +167,22 @@ _g12_scan_blobs() {
164
167
  local _paths _out
165
168
  _paths=$(printf %s "$STAGED_FILES" | tr '\n' '|')
166
169
  [ -z "$_paths" ] && return 0
170
+ local _rc
167
171
  _out=$(printf '%s\n' "$STAGED_FILES" | sed 's/^/:/' \
168
172
  | git cat-file --batch 2>/dev/null \
169
- | awk -v paths="$_paths" -f "$GATE_12_SCANNER" 2>/dev/null) || return 0
173
+ | LC_ALL=C awk -v paths="$_paths" -f "$GATE_12_SCANNER" 2>/dev/null)
174
+ _rc=$?
175
+ # #863: a REFUSED scanner is not a clean scan. This used to be `|| return 0`,
176
+ # which turned the scanner's own exit 3 ("I am counting characters, not bytes")
177
+ # into "nothing found" -- the guard stated the rule and the caller discarded it,
178
+ # which is the same fail-open one level up.
179
+ #
180
+ # Exit 3 is the scanner's deliberate refusal; any other non-zero means it did
181
+ # not complete. Both are recorded as UNCHECKED, never as clean.
182
+ if [ "$_rc" -ne 0 ]; then
183
+ GATE_12_BLOB_SCAN_ERROR="blob scanner exited $_rc without scanning"
184
+ return 0
185
+ fi
170
186
  [ -z "$_out" ] && return 0
171
187
  GATE_12_HAS_TRAILING_WS=$(printf %s "$_out" | sed -n 's/^WS://p')
172
188
  GATE_12_MISSING_EOF=$(printf %s "$_out" | sed -n 's/^NOEOF://p')
@@ -307,14 +323,28 @@ fi
307
323
  # whole no matter what the message contains.
308
324
  YAML_JSON_ERRORS=()
309
325
  YAML_JSON_CHECK_COUNT=0
326
+ # #838: files for which the validator COULD NOT RUN. Counted separately from
327
+ # errors and from checked, because the three are different facts and merging any
328
+ # two of them is how "not checked" becomes "checked and clean".
329
+ YAML_JSON_UNCHECKED=0
330
+ YAML_JSON_UNCHECKED_WHY=""
310
331
 
311
- # Detect available validators
332
+ # Detect available validators.
333
+ #
334
+ # #838: CAPABILITY, not presence. `command -v python3` answers "is there a
335
+ # python3 binary", which is not the question -- an interpreter without PyYAML (a
336
+ # Windows Store stub, a slim container, a pyenv that has not installed it) passes
337
+ # the probe and then fails the import. The probe below actually imports yaml, so
338
+ # a validator is selected only when it can do the job.
312
339
  YAML_CMD=""
313
- if command -v python3 >/dev/null 2>&1; then
314
- YAML_CMD="python3"
315
- elif command -v python >/dev/null 2>&1; then
316
- YAML_CMD="python"
317
- fi
340
+ for _g12_py in python3 python; do
341
+ if command -v "$_g12_py" >/dev/null 2>&1 \
342
+ && "$_g12_py" -c 'import yaml' >/dev/null 2>&1; then
343
+ YAML_CMD="$_g12_py"
344
+ break
345
+ fi
346
+ done
347
+ unset _g12_py
318
348
 
319
349
  JSON_CMD=""
320
350
  if command -v node >/dev/null 2>&1; then
@@ -334,8 +364,11 @@ while IFS= read -r file; do
334
364
  case "$file" in
335
365
  *.yml|*.yaml)
336
366
  if [ -n "$YAML_CMD" ]; then
337
- YAML_JSON_CHECK_COUNT=$((YAML_JSON_CHECK_COUNT + 1))
338
- # Validate YAML syntax using Python's yaml module
367
+ # A failure of the VALIDATOR is not a verdict on the FILE, and staying
368
+ # silent about it is what #838 measured. The second except arm prints an
369
+ # STX marker (chr(2)) so this side can tell "the tool is broken" from
370
+ # "the file is broken" by exit code 2 vs 1. The python snippet stays
371
+ # comment-free: it lives inside a double-quoted shell string.
339
372
  YAML_ERROR=$(git show ":$file" 2>/dev/null | $YAML_CMD -c "
340
373
  import sys, yaml
341
374
  try:
@@ -343,13 +376,47 @@ try:
343
376
  except yaml.YAMLError as e:
344
377
  print(str(e).split(chr(10))[0])
345
378
  sys.exit(1)
346
- except Exception:
347
- pass
348
- " 2>&1)
379
+ except Exception as e:
380
+ print(chr(2) + str(e).split(chr(10))[0])
381
+ sys.exit(2)
382
+ " 2>/dev/null)
349
383
  _g12_rc=$?
350
- if [ "$_g12_rc" -ne 0 ] && [ -n "$YAML_ERROR" ]; then
351
- YAML_JSON_ERRORS+=("$file(yaml:$YAML_ERROR)")
352
- fi
384
+ # #838: the counter moved BACK, out of the pre-check. Counting a file as
385
+ # "checked" before checking it made the summary claim work that never
386
+ # happened.
387
+ #
388
+ # An empty message with a non-zero exit is the tool failing, not the file
389
+ # passing. It is counted and named, because "could not validate" must not
390
+ # become "valid" by default.
391
+ #
392
+ # THE EXIT STATUS IS THE VERDICT. stderr is not captured at all (`2>/dev/null`
393
+ # on the invocation): a deprecation warning from a healthy interpreter is
394
+ # noise, and Delphi round-1 measured that treating it as failure made the
395
+ # check cry wolf over VALID yaml -- with a misleading "Install PyYAML"
396
+ # hint. Conflating noise with failure costs the same as reporting a pass
397
+ # over a real defect: people stop reading the output.
398
+ case "$_g12_rc" in
399
+ 0)
400
+ YAML_JSON_CHECK_COUNT=$((YAML_JSON_CHECK_COUNT + 1))
401
+ ;;
402
+ 1)
403
+ # The validator ran and rejected the file. The message is the reason.
404
+ YAML_JSON_CHECK_COUNT=$((YAML_JSON_CHECK_COUNT + 1))
405
+ YAML_JSON_ERRORS+=("$file(yaml:${YAML_ERROR#$'\002'})")
406
+ ;;
407
+ *)
408
+ # Anything else is the TOOL failing, with or without a message.
409
+ YAML_JSON_UNCHECKED=$((YAML_JSON_UNCHECKED + 1))
410
+ if [ -n "$YAML_ERROR" ]; then
411
+ YAML_JSON_UNCHECKED_WHY="yaml validator exited $_g12_rc: ${YAML_ERROR#$'\002'}"
412
+ else
413
+ YAML_JSON_UNCHECKED_WHY="yaml validator exited $_g12_rc with no message"
414
+ fi
415
+ ;;
416
+ esac
417
+ else
418
+ YAML_JSON_UNCHECKED=$((YAML_JSON_UNCHECKED + 1))
419
+ YAML_JSON_UNCHECKED_WHY="no python3/python interpreter with PyYAML on PATH"
353
420
  fi
354
421
  ;;
355
422
  *.json)
@@ -386,6 +453,27 @@ elif [ "$YAML_JSON_CHECK_COUNT" -gt 0 ]; then
386
453
  echo " ✅ YAML/JSON syntax OK ($YAML_JSON_CHECK_COUNT file(s) checked)"
387
454
  fi
388
455
 
456
+ # #838: a validator that did not run is reported as a HYGIENE ISSUE, not a pass.
457
+ # Fail-closed, by the same rule secret scanning follows: a check that cannot run
458
+ # must not report success.
459
+ if [ "$YAML_JSON_UNCHECKED" -gt 0 ]; then
460
+ echo " ⚠️ YAML/JSON syntax NOT CHECKED for $YAML_JSON_UNCHECKED file(s): $YAML_JSON_UNCHECKED_WHY"
461
+ echo " Install PyYAML (pip install pyyaml) so this check can run."
462
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
463
+ HYGIENE_FILES="$HYGIENE_FILES yaml-validator-unavailable"
464
+ fi
465
+
466
+ # #863: the blob scanner refused or did not complete. Trailing-whitespace, EOF
467
+ # newline and conflict-marker detection all read its output, so an empty result
468
+ # set from a failed scan means those three checks DID NOT RUN. Reporting them as
469
+ # clean is the defect; this makes it a hygiene issue with the reason attached.
470
+ if [ -n "${GATE_12_BLOB_SCAN_ERROR:-}" ]; then
471
+ echo " ⚠️ Blob scan NOT COMPLETED: $GATE_12_BLOB_SCAN_ERROR"
472
+ echo " Trailing whitespace, EOF newline and conflict markers were NOT checked."
473
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
474
+ HYGIENE_FILES="$HYGIENE_FILES blob-scan-failed"
475
+ fi
476
+
389
477
  # --- Result ---
390
478
  if [ "${GATE_12_DOCS_ONLY:-false}" = true ] && [ "$HYGIENE_ISSUES" -eq 0 ]; then
391
479
  echo " ✅ PASSED - File Hygiene (docs-only commit: diff-scoped conflict-marker + YAML/JSON checks clean)."