@boyingliu01/xp-gate 0.38.65 → 0.38.70
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.
- package/adapters/gate-12-file-hygiene.sh +17 -2
- package/gate-10.sh +23 -0
- package/gate-12-file-hygiene.sh +156 -52
- package/gate-13-compiler-strictness.sh +321 -9
- package/gate-7.sh +2 -2
- package/gate-8.sh +70 -1
- package/hooks/gate-10.sh +23 -0
- package/hooks/gate-12-file-hygiene.sh +156 -52
- package/hooks/gate-13-compiler-strictness.sh +321 -9
- package/hooks/gate-7.sh +2 -2
- package/hooks/gate-8.sh +70 -1
- package/hooks/gate-entries/gate-13-entry.sh +23 -2
- package/hooks/gate-entries/gate-5-entry.sh +10 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -44,6 +44,13 @@ GATE13_FAIL=1
|
|
|
44
44
|
GATE13_BLOCK=2
|
|
45
45
|
# shellcheck disable=SC2034 # public contract
|
|
46
46
|
GATE13_WARN=3
|
|
47
|
+
# "Nothing to evaluate", as a verdict distinct from WARN. WARN means "looked at it
|
|
48
|
+
# and it is not clean"; SKIP means "there was nothing here". Conflating them is the
|
|
49
|
+
# defect family this codebase keeps repeating, and until now the C/C++ arm answered
|
|
50
|
+
# PASS -- the worst of the three -- when no C/C++ file was staged, recording
|
|
51
|
+
# "nothing to compile" as "compiled and clean".
|
|
52
|
+
# shellcheck disable=SC2034 # public contract: the entry maps this to SKIP
|
|
53
|
+
GATE13_SKIP=4
|
|
47
54
|
|
|
48
55
|
GATE13_DEFAULT_TIMEOUT=120
|
|
49
56
|
|
|
@@ -468,10 +475,51 @@ gate13_baseline_exists() {
|
|
|
468
475
|
# Prints the diagnostics on stderr; the COUNT goes to stdout.
|
|
469
476
|
# ---------------------------------------------------------------------------
|
|
470
477
|
gate13_count_warnings() {
|
|
478
|
+
local cc="$1" flags="$2" file="$3" out warnings errors
|
|
479
|
+
# shellcheck disable=SC2086 # flags is a deliberately word-split flag list
|
|
480
|
+
out=$("$cc" -fsyntax-only $flags "$file" 2>&1)
|
|
481
|
+
warnings=$(printf '%s\n' "$out" | grep -E 'warning:' | grep -vcE '^\s*$' || true)
|
|
482
|
+
# ERRORS COUNT TOO, AND THEY ARE THE POINT.
|
|
483
|
+
#
|
|
484
|
+
# This used to be `grep 'warning:' | grep -vc`. A file that does not COMPILE emits
|
|
485
|
+
# `error:` lines and no `warning:` lines, so it scored 0 -- identical to a clean
|
|
486
|
+
# file -- and the added-file branch below blocks only on cnt > 0. Measured on a
|
|
487
|
+
# new file containing `int broken( { return 0; }`:
|
|
488
|
+
#
|
|
489
|
+
# g++ says: bad.cpp:1:11: error: Unmatched '('
|
|
490
|
+
# gate said: (nothing) -- PASS
|
|
491
|
+
#
|
|
492
|
+
# while the banner two functions up promises "new files are still -Werror".
|
|
493
|
+
# Counting errors alongside warnings is the minimum honest reading: the caller's
|
|
494
|
+
# question is "is this file worse than clean", and a file that does not parse is
|
|
495
|
+
# worse than one that merely warns.
|
|
496
|
+
errors=$(printf '%s\n' "$out" | grep -E 'error:' | grep -vcE '^\s*$' || true)
|
|
497
|
+
printf '%s\n' "$(( ${warnings:-0} + ${errors:-0} ))"
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
# Count ONLY compiler errors -- a translation unit that does not compile.
|
|
501
|
+
#
|
|
502
|
+
# Separate from gate13_count_warnings on purpose. The two questions are different:
|
|
503
|
+
# gate13_count_warnings -> "is this file worse than clean?" (baseline ratchet)
|
|
504
|
+
# gate13_count_errors -> "does this file compile at all?" (absolute)
|
|
505
|
+
#
|
|
506
|
+
# The ratchet legitimately tolerates a known warning count, and a file with no
|
|
507
|
+
# baseline entry is report-only so that adopting the gate does not mean fixing
|
|
508
|
+
# every pre-existing warning first. Neither exemption may extend to an ERROR:
|
|
509
|
+
# pre-existing errors are not "debt to adopt", and code that does not build has no
|
|
510
|
+
# business being committed.
|
|
511
|
+
#
|
|
512
|
+
# Measured 2026-11-19 with the language matrix, cpp fixture:
|
|
513
|
+
# a.cpp = `int main() { return not_a_symbol; }`
|
|
514
|
+
# g++: "error: 'not_a_symbol' was not declared in this scope"
|
|
515
|
+
# Gate 13: SKIP (no baseline) -> the error was not reported at all
|
|
516
|
+
# The file had a baseline-eligible path only because it was MODIFIED rather than
|
|
517
|
+
# added, which is the ordinary case for every existing project.
|
|
518
|
+
gate13_count_errors() {
|
|
471
519
|
local cc="$1" flags="$2" file="$3" out
|
|
472
520
|
# shellcheck disable=SC2086 # flags is a deliberately word-split flag list
|
|
473
521
|
out=$("$cc" -fsyntax-only $flags "$file" 2>&1)
|
|
474
|
-
printf '%s\n' "$out" | grep -E '
|
|
522
|
+
printf '%s\n' "$(printf '%s\n' "$out" | grep -E 'error:' | grep -vcE '^\s*$' || true)"
|
|
475
523
|
}
|
|
476
524
|
|
|
477
525
|
# ============================================================================
|
|
@@ -775,7 +823,11 @@ gate13_run_java_analysis() {
|
|
|
775
823
|
|
|
776
824
|
srcs=$(gate13_java_sources)
|
|
777
825
|
if [ -z "$srcs" ]; then
|
|
778
|
-
|
|
826
|
+
# SKIP, not PASS: no sources for this arm means it evaluated nothing.
|
|
827
|
+
# Answering PASS here made the arm claim a clean result it never computed, and
|
|
828
|
+
# it suppressed the whole gate's SKIP verdict (measured: a Ruby-only project
|
|
829
|
+
# with no declared checker reported Gate 13 PASS).
|
|
830
|
+
return "$GATE13_SKIP"
|
|
779
831
|
fi
|
|
780
832
|
|
|
781
833
|
if [ "${GATE13_FORCE_NO_JAVA_TOOLCHAIN:-}" = "1" ]; then
|
|
@@ -828,6 +880,31 @@ gate13_run_java_analysis() {
|
|
|
828
880
|
fi
|
|
829
881
|
if [ "$rc" -ne 0 ]; then
|
|
830
882
|
if [ "$degraded" -eq 1 ]; then
|
|
883
|
+
# Degraded mode means the -Xlint flags could not be injected, so this
|
|
884
|
+
# run cannot say anything about compiler STRICTNESS. It can still say
|
|
885
|
+
# something about COMPILABILITY, and the two were being conflated: every
|
|
886
|
+
# non-zero exit was waved through as "usually missing offline
|
|
887
|
+
# dependencies".
|
|
888
|
+
#
|
|
889
|
+
# Measured 2026-11-19, language matrix, java fixture:
|
|
890
|
+
#
|
|
891
|
+
# src/main/java/A.java : public int f() { return "no"; }
|
|
892
|
+
# mvn -o compile : [ERROR] COMPILATION ERROR :
|
|
893
|
+
# ... 不兼容的类型: java.lang.String无法转换为int
|
|
894
|
+
# ... Compilation failure
|
|
895
|
+
# gate 13 : "Java build failed (mvn exit 1) in degraded
|
|
896
|
+
# mode — not attributed to Gate 13" -> WARN
|
|
897
|
+
# commit ALLOWED
|
|
898
|
+
#
|
|
899
|
+
# A missing-dependency failure does not print COMPILATION ERROR; it fails
|
|
900
|
+
# while resolving artifacts ("Could not resolve dependencies", "Non-resolvable
|
|
901
|
+
# parent POM"). javac reporting an error in a source file is not an
|
|
902
|
+
# environment problem, and the file in question is the one being committed.
|
|
903
|
+
if printf '%s\n' "$mvn_out" | grep -qE 'COMPILATION ERROR|Compilation failure'; then
|
|
904
|
+
echo " ❌ Java compilation failed (mvn exit ${rc}) — javac reported errors in the sources"
|
|
905
|
+
printf '%s\n' "$mvn_out" | grep -E 'ERROR' | head -10 | sed 's/^/ /'
|
|
906
|
+
return "$GATE13_FAIL"
|
|
907
|
+
fi
|
|
831
908
|
# We already know the lint flags were not applied, so a build failure
|
|
832
909
|
# here says nothing about compiler strictness — it is usually missing
|
|
833
910
|
# offline dependencies. Reporting it as FAIL would blame this gate for
|
|
@@ -1005,29 +1082,218 @@ gate13_analyzer_supported() {
|
|
|
1005
1082
|
return 1
|
|
1006
1083
|
}
|
|
1007
1084
|
|
|
1085
|
+
# ============================================================================
|
|
1086
|
+
# DECLARED ADAPTER CHECKS (REQ-GATE13-CAPABILITY)
|
|
1087
|
+
#
|
|
1088
|
+
# Gate 13 used to cover exactly C/C++, Java and C# -- the three languages whose
|
|
1089
|
+
# compiler somebody wired in here. Every other language with a compiler or type
|
|
1090
|
+
# checker (Go, Rust, Dart, Kotlin, Swift, PHP, Ruby, ...) was simply not asked.
|
|
1091
|
+
# Measured 2026-11-19: a Go file containing `var x int = "not an int"` passed the
|
|
1092
|
+
# entire chain, and the one gate whose subject is compiler errors reported PASS on
|
|
1093
|
+
# a project it had not looked at.
|
|
1094
|
+
#
|
|
1095
|
+
# The fix is deliberately NOT a list of languages here. githooks/AGENTS.md:
|
|
1096
|
+
#
|
|
1097
|
+
# "Declare capabilities on the adapter, never enumerate language names. A hand
|
|
1098
|
+
# written list of languages can only ever contain what someone remembered;
|
|
1099
|
+
# this was patched twice before becoming a rule. The default is the safe side."
|
|
1100
|
+
#
|
|
1101
|
+
# So a language opts in by defining ONE function in its adapter:
|
|
1102
|
+
#
|
|
1103
|
+
# compiler_check_command() { printf '%s' 'go vet ./...'; }
|
|
1104
|
+
#
|
|
1105
|
+
# printing a command that compiles or type-checks the project and exits non-zero
|
|
1106
|
+
# when it finds an error. An adapter that does not define it is not asked, and the
|
|
1107
|
+
# gate contains no notion of which languages those are. Adding Go, Rust or Dart is
|
|
1108
|
+
# a change to that adapter alone.
|
|
1109
|
+
#
|
|
1110
|
+
# Two deliberate choices:
|
|
1111
|
+
#
|
|
1112
|
+
# * The command runs from the PROJECT root, not per file. Compilers are
|
|
1113
|
+
# whole-project by nature -- `tsc --noEmit`, `go vet ./...`, `cargo check` --
|
|
1114
|
+
# and a per-file invocation would need the gate to know each tool's argument
|
|
1115
|
+
# shape. The project root is what the gate already runs in.
|
|
1116
|
+
#
|
|
1117
|
+
# * A declared checker that fails BLOCKS. That is the opposite of the C/C++ arm's
|
|
1118
|
+
# baseline ratchet (which only blocks a RISE in warning count) and it is
|
|
1119
|
+
# correct: these commands report errors, not warnings, so there is no existing
|
|
1120
|
+
# count to be tolerant of.
|
|
1121
|
+
# ============================================================================
|
|
1122
|
+
|
|
1123
|
+
# Print the command an adapter declares for compile-time checking, or nothing.
|
|
1124
|
+
# Resolution order matches the gate's existing adapter lookup: the adapter is
|
|
1125
|
+
# already sourced by the time this is called (pre-commit sources the language
|
|
1126
|
+
# adapter first), so a defined function is the answer and an undefined one is the
|
|
1127
|
+
# absence of a claim.
|
|
1128
|
+
gate13_declared_checker() {
|
|
1129
|
+
# An adapter may already be sourced by the caller (a test, or a future gate
|
|
1130
|
+
# driver that shares one scope). Honour that first -- it is the cheap path and
|
|
1131
|
+
# it keeps the function usable without a repository.
|
|
1132
|
+
if declare -f compiler_check_command >/dev/null 2>&1; then
|
|
1133
|
+
local cmd
|
|
1134
|
+
cmd=$(compiler_check_command 2>/dev/null || true)
|
|
1135
|
+
[ -n "$cmd" ] && printf '%s' "$cmd"
|
|
1136
|
+
return 0
|
|
1137
|
+
fi
|
|
1138
|
+
|
|
1139
|
+
# Otherwise SOURCE the adapter for each detected language and ask it.
|
|
1140
|
+
#
|
|
1141
|
+
# This branch is the difference between the capability existing and the
|
|
1142
|
+
# capability working. pre-commit sources adapter-common.sh only; language
|
|
1143
|
+
# adapters are sourced by Gate 1 inside its own subshell, so by the time Gate 13
|
|
1144
|
+
# runs there is no adapter in scope. The first end-to-end run of this feature
|
|
1145
|
+
# therefore printed "no compiler/type-checker declared" on a Go project whose Go
|
|
1146
|
+
# adapter DID declare one -- the declaration existed and nothing loaded it.
|
|
1147
|
+
#
|
|
1148
|
+
# PROJECT_LANGS is the authority for which languages this repository has
|
|
1149
|
+
# (githooks/AGENTS.md). It is used to FIND the adapter, never to decide what a
|
|
1150
|
+
# language can do -- that decision stays with compiler_check_command.
|
|
1151
|
+
local lang path cmd
|
|
1152
|
+
for lang in ${PROJECT_LANGS:-}; do
|
|
1153
|
+
path=$(gate13_adapter_path "$lang") || continue
|
|
1154
|
+
[ -n "$path" ] && [ -f "$path" ] || continue
|
|
1155
|
+
# Subshell per adapter: sourcing a language adapter defines run_lint,
|
|
1156
|
+
# run_static_analysis and friends, and the LAST one sourced would silently
|
|
1157
|
+
# overwrite the ones before it.
|
|
1158
|
+
cmd=$(
|
|
1159
|
+
# shellcheck source=/dev/null
|
|
1160
|
+
. "$path" >/dev/null 2>&1 || exit 0
|
|
1161
|
+
if declare -f compiler_check_command >/dev/null 2>&1; then
|
|
1162
|
+
compiler_check_command 2>/dev/null || true
|
|
1163
|
+
fi
|
|
1164
|
+
)
|
|
1165
|
+
if [ -n "$cmd" ]; then
|
|
1166
|
+
printf '%s' "$cmd"
|
|
1167
|
+
return 0
|
|
1168
|
+
fi
|
|
1169
|
+
done
|
|
1170
|
+
return 1
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
# Find the adapter file for a language, using the same resolution the hook uses.
|
|
1174
|
+
# Returns non-zero (and prints nothing) when the language has no adapter file.
|
|
1175
|
+
gate13_adapter_path() {
|
|
1176
|
+
local lang="$1" dir
|
|
1177
|
+
|
|
1178
|
+
# The hook's own resolver, when present. It encodes the 3-tier order in one
|
|
1179
|
+
# place so the gate and `xp-gate doctor` cannot disagree.
|
|
1180
|
+
if declare -f resolve_adapter_path >/dev/null 2>&1; then
|
|
1181
|
+
local p
|
|
1182
|
+
p=$(resolve_adapter_path "$lang" 2>/dev/null) || p=""
|
|
1183
|
+
[ -n "$p" ] && [ -f "$p" ] && { printf '%s' "$p"; return 0; }
|
|
1184
|
+
fi
|
|
1185
|
+
|
|
1186
|
+
# Fallback for direct invocation (tests, `xp-gate check`): the global install
|
|
1187
|
+
# first, then this file's own directory, which is the tracked tree.
|
|
1188
|
+
for dir in "$HOME/.config/xp-gate/adapters" \
|
|
1189
|
+
"$(dirname "${BASH_SOURCE[0]}")" \
|
|
1190
|
+
"${ADAPTER_DIR:-}"; do
|
|
1191
|
+
[ -n "$dir" ] || continue
|
|
1192
|
+
if [ -f "$dir/${lang}.sh" ]; then
|
|
1193
|
+
printf '%s' "$dir/${lang}.sh"
|
|
1194
|
+
return 0
|
|
1195
|
+
fi
|
|
1196
|
+
done
|
|
1197
|
+
return 1
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
# Run the declared checker for whichever language adapter defines one.
|
|
1201
|
+
#
|
|
1202
|
+
# Returns GATE13_PASS when the checker ran and reported no error, GATE13_BLOCK when
|
|
1203
|
+
# it reported one, and GATE13_SKIP when nothing was declared -- never PASS for the
|
|
1204
|
+
# last case, which is the whole defect this function exists to end.
|
|
1205
|
+
gate13_run_declared_checks() {
|
|
1206
|
+
local cmd out rc
|
|
1207
|
+
|
|
1208
|
+
cmd=$(gate13_declared_checker) || cmd=""
|
|
1209
|
+
if [ -z "$cmd" ]; then
|
|
1210
|
+
# No adapter claimed a compile-time checker. Say so plainly rather than
|
|
1211
|
+
# inventing a tool: this is the arm that used to report PASS on languages it
|
|
1212
|
+
# never looked at.
|
|
1213
|
+
gate13_reason "Gate 13: no compiler/type-checker declared for this language -- compiler errors not checked"
|
|
1214
|
+
echo " i No compile-time checker declared by this project's language adapter."
|
|
1215
|
+
return "$GATE13_SKIP"
|
|
1216
|
+
fi
|
|
1217
|
+
|
|
1218
|
+
echo " -> declared compile-time checker: ${cmd}"
|
|
1219
|
+
|
|
1220
|
+
# `eval` on a string is normally a smell. It is what the adapter contract asks
|
|
1221
|
+
# for -- a command with arguments, chosen by the adapter -- and the alternative
|
|
1222
|
+
# (tuple-encoding it through a function call) would force every adapter to
|
|
1223
|
+
# implement the same quoting. Bounded by: the string comes from our own tracked
|
|
1224
|
+
# adapters, never from the change set or from config.
|
|
1225
|
+
# shellcheck disable=SC2086 # $cmd is a deliberately word-split command line
|
|
1226
|
+
out=$(cd "$(gate13_project_root)" && eval "$cmd" 2>&1)
|
|
1227
|
+
rc=$?
|
|
1228
|
+
|
|
1229
|
+
if [ "$rc" -ne 0 ]; then
|
|
1230
|
+
echo " X Declared compile-time check FAILED (${cmd})"
|
|
1231
|
+
local line shown=0
|
|
1232
|
+
# Show the first lines that look like diagnostics, plus a bounded tail, so a
|
|
1233
|
+
# failed run is actionable without dumping a whole build log into the commit.
|
|
1234
|
+
while IFS= read -r line; do
|
|
1235
|
+
[ -n "$line" ] || continue
|
|
1236
|
+
case "$line" in
|
|
1237
|
+
*error*|*Error*|*cannot*|*undefined*|*mismatch*)
|
|
1238
|
+
echo " ${line}"
|
|
1239
|
+
shown=$((shown + 1))
|
|
1240
|
+
[ "$shown" -ge 10 ] && break
|
|
1241
|
+
;;
|
|
1242
|
+
esac
|
|
1243
|
+
done <<EOF
|
|
1244
|
+
$out
|
|
1245
|
+
EOF
|
|
1246
|
+
if [ "$shown" -eq 0 ]; then
|
|
1247
|
+
printf '%s\n' "$out" | tail -5 | sed 's/^/ /'
|
|
1248
|
+
fi
|
|
1249
|
+
return "$GATE13_BLOCK"
|
|
1250
|
+
fi
|
|
1251
|
+
|
|
1252
|
+
echo " OK Declared compile-time check passed (${cmd})"
|
|
1253
|
+
return "$GATE13_PASS"
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
# The directory the declared command should run in. Uses the same root the rest of
|
|
1257
|
+
# the gate uses so a repository check and a hook check agree on scope.
|
|
1258
|
+
gate13_project_root() {
|
|
1259
|
+
if [ -n "${PROJECT_ROOT:-}" ]; then
|
|
1260
|
+
printf '%s' "$PROJECT_ROOT"
|
|
1261
|
+
return 0
|
|
1262
|
+
fi
|
|
1263
|
+
git rev-parse --show-toplevel 2>/dev/null || printf '.'
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1008
1266
|
gate13_run_analyzer() {
|
|
1009
1267
|
local cc
|
|
1010
1268
|
local files=""
|
|
1011
1269
|
local f cnt total=0 blocking=0
|
|
1012
1270
|
local workdir
|
|
1013
1271
|
|
|
1014
|
-
|
|
1272
|
+
# Not enabled is "this arm has nothing to say", not "the analysis was clean".
|
|
1273
|
+
gate13_analyzer_enabled || return "$GATE13_SKIP"
|
|
1015
1274
|
|
|
1016
1275
|
cc=$(gate13_select_cc)
|
|
1017
1276
|
[ -n "$cc" ] || {
|
|
1018
1277
|
echo " ⚠️ -fanalyzer requested but no C compiler is usable; analyzer stage skipped"
|
|
1019
|
-
|
|
1278
|
+
# WARN, not SKIP: the arm was asked to run and could not. That is a degraded
|
|
1279
|
+
# result the reader must see, not a quiet "nothing here".
|
|
1280
|
+
return "$GATE13_WARN"
|
|
1020
1281
|
}
|
|
1021
1282
|
|
|
1022
1283
|
if ! gate13_analyzer_supported "$cc"; then
|
|
1023
1284
|
echo " ℹ️ $(gate13_compiler_id "$cc") has no -fanalyzer support; analyzer stage skipped"
|
|
1024
|
-
|
|
1285
|
+
# The compiler exists but cannot do this analysis: degraded, not clean.
|
|
1286
|
+
return "$GATE13_WARN"
|
|
1025
1287
|
fi
|
|
1026
1288
|
|
|
1027
1289
|
files=$(gate13_analyzer_files)
|
|
1028
1290
|
if [ -z "$files" ]; then
|
|
1029
1291
|
echo " ℹ️ -fanalyzer: no staged .c files"
|
|
1030
|
-
|
|
1292
|
+
# SKIP, not PASS: this arm evaluated nothing. Returning 0 here made it look
|
|
1293
|
+
# like a successful analysis, which then suppressed the SKIP verdict for the
|
|
1294
|
+
# whole gate (measured: a Ruby-only project with no checker declared reported
|
|
1295
|
+
# Gate 13 PASS because this arm answered "clean").
|
|
1296
|
+
return "$GATE13_SKIP"
|
|
1031
1297
|
fi
|
|
1032
1298
|
|
|
1033
1299
|
workdir="${TMPDIR:-/tmp}/gate13_analyzer_$$"
|
|
@@ -1095,8 +1361,23 @@ gate13_run_cpp_analysis() {
|
|
|
1095
1361
|
local classified
|
|
1096
1362
|
classified=$(gate13_classify_changed)
|
|
1097
1363
|
if [ -z "$classified" ]; then
|
|
1364
|
+
# SKIP, not PASS, and not WARN either.
|
|
1365
|
+
#
|
|
1366
|
+
# PASS said "compiled and clean" about a change set this arm never read. WARN
|
|
1367
|
+
# would say "looked at it and it is not clean", which is also false. The only
|
|
1368
|
+
# honest answer to "there is no C/C++ here" is "there is no C/C++ here", which
|
|
1369
|
+
# is what GATE13_SKIP is for -- the entry maps it to a SKIP verdict carrying
|
|
1370
|
+
# this reason, instead of the WARN that every unrecognised code used to become.
|
|
1371
|
+
#
|
|
1372
|
+
# Measured consequence of the old answer (2026-11-19): a Go file with
|
|
1373
|
+
# `var x int = "not an int"` staged on a Go-only project produced
|
|
1374
|
+
# Gate 9 : SKIP (not a TypeScript project -- correct, with a reason)
|
|
1375
|
+
# Gate 13 : PASS ("No staged C/C++ source files")
|
|
1376
|
+
# so the chain reported a passing compiler-strictness gate on a commit whose
|
|
1377
|
+
# compiler-level error it had not looked for.
|
|
1378
|
+
gate13_reason "Gate 13: no staged C/C++ source files -- nothing to compile"
|
|
1098
1379
|
echo " ℹ️ No staged C/C++ source files — nothing to compile"
|
|
1099
|
-
return "$
|
|
1380
|
+
return "$GATE13_SKIP"
|
|
1100
1381
|
fi
|
|
1101
1382
|
|
|
1102
1383
|
budget=$(gate13_timeout_budget)
|
|
@@ -1144,7 +1425,10 @@ gate13_run_cpp_analysis() {
|
|
|
1144
1425
|
if [ "$tier" = "warn-only" ]; then
|
|
1145
1426
|
echo " ⚠️ ${f}: ${cnt} warning(s) (warn-only tier, not blocking)"
|
|
1146
1427
|
else
|
|
1147
|
-
|
|
1428
|
+
# "diagnostic(s)" not "warning(s)": since errors are counted too, a file
|
|
1429
|
+
# that does not compile reports here, and calling that a warning would
|
|
1430
|
+
# understate what has to be fixed.
|
|
1431
|
+
echo " ❌ ${f}: ${cnt} diagnostic(s) in a NEW file"
|
|
1148
1432
|
blocking=$((blocking + 1))
|
|
1149
1433
|
fi
|
|
1150
1434
|
fi
|
|
@@ -1154,6 +1438,28 @@ gate13_run_cpp_analysis() {
|
|
|
1154
1438
|
if [ -z "$base" ]; then
|
|
1155
1439
|
baseline_seen=1
|
|
1156
1440
|
cnt=$(gate13_count_warnings "$cxx" "$flags" "$f")
|
|
1441
|
+
# Report-only applies to the RATCHET, not to compilability. A modified file
|
|
1442
|
+
# with no baseline entry is exempt from "no worse than before", because
|
|
1443
|
+
# adopting the gate must not mean clearing every pre-existing warning first.
|
|
1444
|
+
# It is not exempt from compiling: an error is not inherited debt, it is a
|
|
1445
|
+
# file that does not build.
|
|
1446
|
+
#
|
|
1447
|
+
# Measured 2026-11-19 (language matrix, cpp fixture):
|
|
1448
|
+
# a.cpp = int main() { return not_a_symbol; }
|
|
1449
|
+
# g++ "error: 'not_a_symbol' was not declared in this scope"
|
|
1450
|
+
# gate: "0 warning(s) (no baseline entry, report-only)" -> commit allowed
|
|
1451
|
+
_g13_errs=$(gate13_count_errors "$cxx" "$flags" "$f")
|
|
1452
|
+
_g13_errs=${_g13_errs:-0}
|
|
1453
|
+
if [ "$_g13_errs" -gt 0 ]; then
|
|
1454
|
+
findings=$((findings + _g13_errs))
|
|
1455
|
+
if [ "$tier" = "warn-only" ]; then
|
|
1456
|
+
echo " ⚠️ ${f}: does NOT compile (${_g13_errs} error(s)); warn-only tier, not blocking"
|
|
1457
|
+
else
|
|
1458
|
+
echo " ❌ ${f}: does NOT compile (${_g13_errs} error(s)) — a missing baseline is no excuse"
|
|
1459
|
+
blocking=$((blocking + 1))
|
|
1460
|
+
fi
|
|
1461
|
+
continue
|
|
1462
|
+
fi
|
|
1157
1463
|
echo " ℹ️ ${f}: ${cnt:-0} warning(s) (no baseline entry, report-only)"
|
|
1158
1464
|
continue
|
|
1159
1465
|
fi
|
|
@@ -1387,6 +1693,8 @@ gate13_csharp_changed_warning_count() {
|
|
|
1387
1693
|
# - the separators differ, so the diagnostic path is folded to "/" first.
|
|
1388
1694
|
# Comparing raw strings matched nothing and reported 0 warnings on a file that
|
|
1389
1695
|
# has two.
|
|
1696
|
+
# shellcheck disable=SC1003 # see the tr below: the backslash pairs are tr escapes,
|
|
1697
|
+
# and single quotes already keep the shell from touching them.
|
|
1390
1698
|
printf '%s\n' "$out" \
|
|
1391
1699
|
| grep -E ': (warning|error) [A-Z]+[0-9]+' \
|
|
1392
1700
|
| sed -n 's/^\(.*\)(.*$/\1/p' \
|
|
@@ -1418,7 +1726,11 @@ gate13_run_csharp_analysis() {
|
|
|
1418
1726
|
|
|
1419
1727
|
sources=$(gate13_csharp_sources)
|
|
1420
1728
|
if [ -z "$sources" ]; then
|
|
1421
|
-
|
|
1729
|
+
# SKIP, not PASS: no sources for this arm means it evaluated nothing.
|
|
1730
|
+
# Answering PASS here made the arm claim a clean result it never computed, and
|
|
1731
|
+
# it suppressed the whole gate's SKIP verdict (measured: a Ruby-only project
|
|
1732
|
+
# with no declared checker reported Gate 13 PASS).
|
|
1733
|
+
return "$GATE13_SKIP"
|
|
1422
1734
|
fi
|
|
1423
1735
|
|
|
1424
1736
|
if ! gate13_csharp_has_manifest; then
|
package/gate-7.sh
CHANGED
|
@@ -38,9 +38,9 @@ else
|
|
|
38
38
|
# by __tests__/gate-7-adapter-resolution.test.bats).
|
|
39
39
|
IAC_ADAPTER=""
|
|
40
40
|
for _candidate in \
|
|
41
|
+
"$HOME/.config/xp-gate/adapters/iac.sh" \
|
|
41
42
|
"githooks/adapters/iac.sh" \
|
|
42
|
-
"${SCRIPT_DIR:-}/adapters/iac.sh"
|
|
43
|
-
"$HOME/.config/xp-gate/adapters/iac.sh"; do
|
|
43
|
+
"${SCRIPT_DIR:-}/adapters/iac.sh"; do
|
|
44
44
|
if [ -n "$_candidate" ] && [ -f "$_candidate" ]; then
|
|
45
45
|
IAC_ADAPTER="$_candidate"
|
|
46
46
|
break
|
package/gate-8.sh
CHANGED
|
@@ -28,7 +28,72 @@ gate8_cleanup() {
|
|
|
28
28
|
rm -f "${GATE8_TEMP[@]}" 2>/dev/null
|
|
29
29
|
fi
|
|
30
30
|
}
|
|
31
|
-
trap
|
|
31
|
+
# CHAIN the previous EXIT trap instead of replacing it.
|
|
32
|
+
#
|
|
33
|
+
# Measured 2026-11-19: `trap gate8_cleanup EXIT` overwrote whatever trap was
|
|
34
|
+
# already installed. pre-commit installs `_quality_report_on_exit` at its top
|
|
35
|
+
# precisely so that a BLOCKED commit still writes its report, and Gate 8 runs
|
|
36
|
+
# before the blocking gates -- so from the moment Gate 8 ran, that trap was gone.
|
|
37
|
+
#
|
|
38
|
+
# The consequence is the worst possible shape: a commit that PASSES writes its
|
|
39
|
+
# report (the epilogue calls generate_quality_report directly), and a commit that
|
|
40
|
+
# is BLOCKED writes nothing. The one run an operator needs to diagnose is the one
|
|
41
|
+
# with no record.
|
|
42
|
+
#
|
|
43
|
+
# Reproduced in a go fixture: the chain stopped at Gate 5, and
|
|
44
|
+
#
|
|
45
|
+
# ls .xp-gate/reports/pre-commit | wc -l -> 0
|
|
46
|
+
#
|
|
47
|
+
# while the same fixture with XP_GATE_ONLY_GATE=8 (chain completes) produced 1.
|
|
48
|
+
# Reading the live trap at the end of the hook showed `trap -- 'gate8_cleanup'
|
|
49
|
+
# EXIT` -- the report trap had been replaced, not chained.
|
|
50
|
+
#
|
|
51
|
+
# `trap -p EXIT` prints a form that can be eval'd back, which is the same
|
|
52
|
+
# technique pre-commit's own source_gate_lib uses to survive a sourced library
|
|
53
|
+
# that installs a trap. The difference here: that library wants to REINSTALL the
|
|
54
|
+
# old trap, whereas this gate has to RUN it, so only the command body is kept.
|
|
55
|
+
#
|
|
56
|
+
# Stripping matters and was caught by the test, not by reading: evaluating the
|
|
57
|
+
# whole string ("trap -- 'cmd' EXIT") reinstalls the old trap instead of invoking
|
|
58
|
+
# it, so the chain silently did nothing and the report still went missing.
|
|
59
|
+
_GATE8_PREV_EXIT_TRAP=""
|
|
60
|
+
_gate8_raw_trap="$(trap -p EXIT 2>/dev/null || true)"
|
|
61
|
+
if [ -n "$_gate8_raw_trap" ]; then
|
|
62
|
+
_gate8_body="${_gate8_raw_trap#trap -- }" # drop 'trap -- '
|
|
63
|
+
_gate8_body="${_gate8_body% EXIT}" # drop the trailing ' EXIT'
|
|
64
|
+
_gate8_body="${_gate8_body#\'}" # drop the surrounding quotes
|
|
65
|
+
_gate8_body="${_gate8_body%\'}"
|
|
66
|
+
_GATE8_PREV_EXIT_TRAP="$_gate8_body"
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
gate8_cleanup_and_chain() {
|
|
70
|
+
# CAPTURE $? FIRST, then RESTORE it before handing control on.
|
|
71
|
+
#
|
|
72
|
+
# pre-commit's `_quality_report_on_exit` reads `$?` as its very first statement
|
|
73
|
+
# and exits with that status -- that is what makes the hook exit non-zero when a
|
|
74
|
+
# gate blocked. Running cleanup first overwrote $? with the status of `rm`, so
|
|
75
|
+
# the chained trap saw 0 and the hook exited 0.
|
|
76
|
+
#
|
|
77
|
+
# Measured 2026-11-19, go fixture, Gate 5 blocked (coverage 0%):
|
|
78
|
+
# before any fix : commit refused (rc=1), report NOT written
|
|
79
|
+
# chain without restoring : commit ALLOWED (rc=0), report written
|
|
80
|
+
#
|
|
81
|
+
# The second row is a WORSE bug than the one being fixed -- a chain that
|
|
82
|
+
# preserves the report by letting blocked commits through. `( exit N )` on its
|
|
83
|
+
# own does not help (the subshell's status is discarded), but it does set $? to
|
|
84
|
+
# N for the next command in this shell, which is what the eval below observes.
|
|
85
|
+
# Verified directly: a chained trap reading $? after this sequence sees the
|
|
86
|
+
# original status, and the hook still exits with it.
|
|
87
|
+
local _g8_saved=$?
|
|
88
|
+
gate8_cleanup
|
|
89
|
+
if [ -n "${_GATE8_PREV_EXIT_TRAP:-}" ]; then
|
|
90
|
+
(exit "$_g8_saved")
|
|
91
|
+
eval "$_GATE8_PREV_EXIT_TRAP"
|
|
92
|
+
return "$_g8_saved"
|
|
93
|
+
fi
|
|
94
|
+
return "$_g8_saved"
|
|
95
|
+
}
|
|
96
|
+
trap gate8_cleanup_and_chain EXIT
|
|
32
97
|
|
|
33
98
|
# Gitleaks availability check
|
|
34
99
|
GITLEAKS_CMD=""
|
|
@@ -90,9 +155,13 @@ GITLEAKS_REPORT="${TMPDIR:-/tmp}/gitleaks-report.json"
|
|
|
90
155
|
rm -f "$GITLEAKS_REPORT"
|
|
91
156
|
if [ "${GATE_SCOPE:-diff}" = "all" ]; then
|
|
92
157
|
echo " Scope: --all (scanning the working tree, not the index)"
|
|
158
|
+
# GITLEAKS_CONFIG is either empty or a single --config=PATH token; quoting it
|
|
159
|
+
# would pass an empty argument to gitleaks. It is split on purpose.
|
|
160
|
+
# shellcheck disable=SC2086
|
|
93
161
|
GITLEAKS_OUTPUT=$($GITLEAKS_CMD dir --no-git --redact --no-banner $GITLEAKS_CONFIG --report-format=json --report-path="$GITLEAKS_REPORT" 2>&1)
|
|
94
162
|
GITLEAKS_EXIT=$?
|
|
95
163
|
else
|
|
164
|
+
# shellcheck disable=SC2086 # see above: empty or one --config= token
|
|
96
165
|
GITLEAKS_OUTPUT=$($GITLEAKS_CMD git --staged --redact --no-banner $GITLEAKS_CONFIG --report-format=json --report-path="$GITLEAKS_REPORT" 2>&1)
|
|
97
166
|
GITLEAKS_EXIT=$?
|
|
98
167
|
fi
|
package/hooks/gate-10.sh
CHANGED
|
@@ -210,6 +210,29 @@ gate10_resolve_ruleset() {
|
|
|
210
210
|
}
|
|
211
211
|
# @@RULES-RESOLVER-END@@
|
|
212
212
|
|
|
213
|
+
|
|
214
|
+
# --- Telemetry: never let an upload be the gate's runtime -------------------
|
|
215
|
+
#
|
|
216
|
+
# This file's own header already named telemetry as part of the import chain
|
|
217
|
+
# behind semgrep's ~9s startup -- and then never disabled it. Measured
|
|
218
|
+
# 2026-11-19, one trivial file, ABBA-alternated so a time trend cannot explain it:
|
|
219
|
+
#
|
|
220
|
+
# semgrep scan --config=auto ... 8095ms / 98595ms
|
|
221
|
+
# SEMGREP_SEND_METRICS=off (same command) 402ms / 481ms
|
|
222
|
+
#
|
|
223
|
+
# A 20x difference that moves with the network. That is exactly the bimodal shape
|
|
224
|
+
# the audit journal had recorded all along and nobody read: of 445 credible
|
|
225
|
+
# sast-security rows, 184 finished under 2s (the metrics POST failed fast) and 225
|
|
226
|
+
# took over 10s (it hung), with the fastest at 191ms and the slowest at 247s.
|
|
227
|
+
# Gate 10 was the single largest p90 share in the chain -- 35.6% -- because its
|
|
228
|
+
# runtime was network wait, which is the one thing a commit gate may not spend
|
|
229
|
+
# time on.
|
|
230
|
+
#
|
|
231
|
+
# Default OFF. The override exists because a team may legitimately want its own
|
|
232
|
+
# semgrep metrics for central rule tuning; what must not be true is that
|
|
233
|
+
# contacting semgrep.dev is the DEFAULT for every commit on every checkout.
|
|
234
|
+
SEMGREP_SEND_METRICS="${XP_GATE_SEMGREP_METRICS:-off}"
|
|
235
|
+
export SEMGREP_SEND_METRICS
|
|
213
236
|
# Semgrep availability check
|
|
214
237
|
SEMGREP_CMD=""
|
|
215
238
|
if command -v semgrep >/dev/null 2>&1; then
|