@boyingliu01/xp-gate 0.38.65 → 0.38.71

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 (34) hide show
  1. package/adapters/gate-12-file-hygiene.sh +17 -2
  2. package/gate-10.sh +23 -0
  3. package/gate-12-file-hygiene.sh +156 -52
  4. package/gate-13-compiler-strictness.sh +321 -9
  5. package/gate-7.sh +2 -2
  6. package/gate-8.sh +70 -1
  7. package/hooks/gate-10.sh +23 -0
  8. package/hooks/gate-12-file-hygiene.sh +156 -52
  9. package/hooks/gate-13-compiler-strictness.sh +321 -9
  10. package/hooks/gate-7.sh +2 -2
  11. package/hooks/gate-8.sh +70 -1
  12. package/hooks/gate-entries/gate-13-entry.sh +23 -2
  13. package/hooks/gate-entries/gate-5-entry.sh +10 -0
  14. package/lib/mattpocock-license-verdict.json +1 -1
  15. package/package.json +1 -1
  16. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  17. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  18. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  19. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  20. package/plugins/dsh/package.json +1 -1
  21. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  22. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  23. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  24. package/plugins/opencode/package.json +1 -1
  25. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  26. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  27. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  28. package/plugins/qoder/plugin.json +1 -1
  29. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  30. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  31. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  32. package/skills/delphi-review/AGENTS.md +1 -1
  33. package/skills/sprint-flow/AGENTS.md +1 -1
  34. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -124,10 +124,25 @@ EOF
124
124
  # The AWK scanner that answers all three content checks in one process. Resolved
125
125
  # next to this script's own directory chain, like every other shared library, so
126
126
  # a global install (~/.config/xp-gate/) and the tracked tree both work.
127
+ #
128
+ # The layouts this must cover, all of which keep the scanner in a `lib/` beside
129
+ # the gate script:
130
+ #
131
+ # githooks/gate-12-file-hygiene.sh -> githooks/lib/gate-12-blob-scan.awk
132
+ # githooks/adapters/gate-12-file-hygiene.sh -> githooks/lib/gate-12-blob-scan.awk (one level up)
133
+ # ~/.config/xp-gate/adapters/gate-12-...sh -> ~/.config/xp-gate/lib/... (one level up)
134
+ #
135
+ # Candidates are normalised with `cd ... && pwd` before the `-f` test: measured
136
+ # 2026-11-20 on Git for Windows, `[ -f ".../githooks/../lib/x" ]` answers FALSE --
137
+ # the test builtin does not resolve `..`. When the loop finds nothing,
138
+ # GATE_12_SCANNER stays empty, `_g12_scan_blobs` bails at its own `-f` guard, and
139
+ # all three checks report nothing while the gate prints PASS.
127
140
  if [ -z "${GATE_12_SCANNER:-}" ]; then
128
- for _g12_dir in "${GATE_DIR:-}" "$(dirname "${BASH_SOURCE[0]}")/.." \
129
- "$(dirname "${BASH_SOURCE[0]}")/../.."; do
141
+ _g12_here=$(dirname "${BASH_SOURCE[0]}")
142
+ for _g12_dir in "${GATE_DIR:-}" "$_g12_here" "$_g12_here/.." "$_g12_here/../.."; do
130
143
  [ -n "$_g12_dir" ] || continue
144
+ # Normalise; a directory that cannot be entered is not a candidate.
145
+ _g12_dir=$(cd "$_g12_dir" 2>/dev/null && pwd) || continue
131
146
  if [ -f "$_g12_dir/lib/gate-12-blob-scan.awk" ]; then
132
147
  GATE_12_SCANNER="$_g12_dir/lib/gate-12-blob-scan.awk"
133
148
  break
package/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
@@ -34,6 +34,9 @@ if [ -z "$STAGED_FILES" ]; then
34
34
  echo " ✅ PASSED - File Hygiene (no files to check)"
35
35
  GATE_12_STATUS="SKIP"
36
36
  record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "0" "$GATE_12_START"
37
+ # shellcheck disable=SC2317 # the gate body is SOURCED, never run to completion here:
38
+ # the driver calls gate_12_run and treats a returned rc as the verdict, so the
39
+ # lines after this return ARE reachable in production (see pre-commit).
37
40
  return 0 2>/dev/null || true
38
41
  fi
39
42
 
@@ -63,30 +66,129 @@ HYGIENE_FILES=""
63
66
  # NUL), and `grep -I` only suppresses output on a binary input -- it does not make
64
67
  # `grep -q` fail, which is why that shortcut still reported text.
65
68
  is_binary_staged_file() {
66
- local _file="$1"
67
- case "$(git diff --cached --numstat -- "$_file" 2>/dev/null)" in
68
- -[[:space:]]-*) return 0 ;; # binary: git could not count lines
69
- *) return 1 ;; # text (or empty -- nothing for the line checks)
69
+ case " $GATE_12_BINARY_SET " in
70
+ *" $1 "*) return 0 ;; # binary: git could not count lines
71
+ *) return 1 ;; # text (or empty -- nothing for the line checks)
70
72
  esac
71
73
  }
72
74
 
73
- # --- Check 1: Trailing whitespace ---
74
- TRAILING_WS_FILES=""
75
- if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
76
- while IFS= read -r file; do
77
- [ -z "$file" ] && continue
78
- # Skip binary files : they have no lines to check
79
- if is_binary_staged_file "$file"; then
80
- continue
81
- fi
82
- # Check staged content for trailing whitespace (spaces/tabs at end of lines)
83
- if git show ":$file" 2>/dev/null | grep -qE '[[:space:]]$'; then
84
- TRAILING_WS_FILES="$TRAILING_WS_FILES $file"
85
- fi
75
+ # Classify the WHOLE change set in one git call.
76
+ #
77
+ # This used to be `git diff --cached --numstat -- "$file"` inside
78
+ # is_binary_staged_file, i.e. one process per file PER CHECK that asked. Three
79
+ # checks ask, so every staged text file cost three git spawns just to learn
80
+ # "text", before any check looked at a byte:
81
+ #
82
+ # measured 2026-11-19, plain-text fixture, this machine:
83
+ # 300 staged files 4m22s (~0.87 s/file)
84
+ # 100 staged files 2m36s
85
+ # 0 staged files 0.5s (the loop never runs)
86
+ #
87
+ # and the audit journal agrees -- 1208 credible file-hygiene rows, median 4.2s,
88
+ # p90 41.7s, 244 over 20s. The cost is process creation, not bytes examined, so
89
+ # it scales with the change set; a text check should not be the second most
90
+ # expensive gate in the chain.
91
+ #
92
+ # `--numstat` already reports the whole index in one shot and marks a binary
93
+ # entry as `-\t-\t<path>`. Same predicate, computed once. If git fails the set
94
+ # stays empty and every file is treated as text -- identical to the old per-file
95
+ # fallback (a failed `git diff` produced no finding).
96
+ GATE_12_BINARY_SET=" "
97
+ while IFS=$'\t' read -r _g12_adds _g12_dels _g12_path; do
98
+ [ -z "$_g12_path" ] && continue
99
+ case "$_g12_adds" in
100
+ -) GATE_12_BINARY_SET="${GATE_12_BINARY_SET}${_g12_path} " ;;
101
+ esac
86
102
  done <<EOF
87
- $STAGED_FILES
103
+ $(git diff --cached --numstat --diff-filter=d 2>/dev/null | grep -vE '(^|/)(node_modules|\.stryker-tmp|vendor)/')
88
104
  EOF
105
+
106
+ # --- Checks 1 and 2 share ONE process per file, not two --------------------
107
+ #
108
+ # Both checks read the same blob. They used to read it separately:
109
+ #
110
+ # git show ":$file" | grep -qE '[[:space:]]$' # trailing whitespace
111
+ # git show ":$file" | tail -c 1 # missing EOF newline
112
+ #
113
+ # so the content was produced twice per file. `git cat-file --batch` streams both
114
+ # answers from a single process for the whole change set.
115
+ #
116
+ # The two predicates are unchanged, which is the point of the rewrite:
117
+ # trailing whitespace -> a line ending in space/tab exists in the blob
118
+ # missing EOF newline -> the blob is non-empty and its last byte is not \n
119
+ #
120
+ # The last byte is taken with `od`, not command substitution: `$(...)` strips
121
+ # every trailing newline, which is the original defect this check documents --
122
+ # a correctly terminated file reported its last visible character and was flagged
123
+ # every time.
124
+ # The AWK scanner that answers all three content checks in one process. Resolved
125
+ # next to this script's own directory chain, like every other shared library, so
126
+ # a global install (~/.config/xp-gate/) and the tracked tree both work.
127
+ #
128
+ # The layouts this must cover, all of which keep the scanner in a `lib/` beside
129
+ # the gate script:
130
+ #
131
+ # githooks/gate-12-file-hygiene.sh -> githooks/lib/gate-12-blob-scan.awk
132
+ # githooks/adapters/gate-12-file-hygiene.sh -> githooks/lib/gate-12-blob-scan.awk (one level up)
133
+ # ~/.config/xp-gate/adapters/gate-12-...sh -> ~/.config/xp-gate/lib/... (one level up)
134
+ #
135
+ # Candidates are normalised with `cd ... && pwd` before the `-f` test: measured
136
+ # 2026-11-20 on Git for Windows, `[ -f ".../githooks/../lib/x" ]` answers FALSE --
137
+ # the test builtin does not resolve `..`. When the loop finds nothing,
138
+ # GATE_12_SCANNER stays empty, `_g12_scan_blobs` bails at its own `-f` guard, and
139
+ # all three checks report nothing while the gate prints PASS.
140
+ if [ -z "${GATE_12_SCANNER:-}" ]; then
141
+ _g12_here=$(dirname "${BASH_SOURCE[0]}")
142
+ for _g12_dir in "${GATE_DIR:-}" "$_g12_here" "$_g12_here/.." "$_g12_here/../.."; do
143
+ [ -n "$_g12_dir" ] || continue
144
+ # Normalise; a directory that cannot be entered is not a candidate.
145
+ _g12_dir=$(cd "$_g12_dir" 2>/dev/null && pwd) || continue
146
+ if [ -f "$_g12_dir/lib/gate-12-blob-scan.awk" ]; then
147
+ GATE_12_SCANNER="$_g12_dir/lib/gate-12-blob-scan.awk"
148
+ break
149
+ fi
150
+ done
151
+ unset _g12_dir
89
152
  fi
153
+ GATE_12_SCANNER="${GATE_12_SCANNER:-}"
154
+
155
+ GATE_12_HAS_TRAILING_WS=" "
156
+ GATE_12_MISSING_EOF=" "
157
+ GATE_12_HAS_CONFLICT=" "
158
+
159
+ _g12_scan_blobs() {
160
+ # ONE awk process for the whole change set (see githooks/lib/gate-12-blob-scan.awk
161
+ # for the measurements that made this a rewrite rather than a tidy-up).
162
+ #
163
+ # The path list is |-separated because a staged path may contain a newline.
164
+ local _paths _out
165
+ _paths=$(printf %s "$STAGED_FILES" | tr '\n' '|')
166
+ [ -z "$_paths" ] && return 0
167
+ _out=$(printf '%s\n' "$STAGED_FILES" | sed 's/^/:/' \
168
+ | git cat-file --batch 2>/dev/null \
169
+ | awk -v paths="$_paths" -f "$GATE_12_SCANNER" 2>/dev/null) || return 0
170
+ [ -z "$_out" ] && return 0
171
+ GATE_12_HAS_TRAILING_WS=$(printf %s "$_out" | sed -n 's/^WS://p')
172
+ GATE_12_MISSING_EOF=$(printf %s "$_out" | sed -n 's/^NOEOF://p')
173
+ GATE_12_HAS_CONFLICT=$(printf %s "$_out" | sed -n 's/^CONFLICT://p')
174
+ }
175
+
176
+ if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
177
+ _g12_scan_blobs
178
+ fi
179
+
180
+ _g12_in_set() {
181
+ case " $1 " in
182
+ *" $2 "*) return 0 ;;
183
+ *) return 1 ;;
184
+ esac
185
+ }
186
+
187
+ # --- Check 1: Trailing whitespace ---
188
+ TRAILING_WS_FILES=""
189
+ for file in $GATE_12_HAS_TRAILING_WS; do
190
+ TRAILING_WS_FILES="$TRAILING_WS_FILES $file"
191
+ done
90
192
 
91
193
  if [ -n "$TRAILING_WS_FILES" ]; then
92
194
  echo " ⚠️ Trailing whitespace detected in:"
@@ -105,26 +207,17 @@ fi
105
207
  # Every staged text file was a false positive, which is how a check that always
106
208
  # fires looks exactly like a strict check. `git show | tail -c 1` keeps the byte.
107
209
  file_missing_eof_newline() {
108
- local last_byte
109
- last_byte=$(git show ":$1" 2>/dev/null | tail -c 1)
110
- # Empty output means the blob is empty: there is no line to terminate.
111
- [ -n "$last_byte" ]
210
+ # Answered by _g12_scan_blobs, from the same single process that answered
211
+ # Check 1. Kept as a named predicate because that is the question being asked;
212
+ # the implementation is a set lookup now.
213
+ _g12_in_set "$GATE_12_MISSING_EOF" "$1"
112
214
  }
113
215
 
114
216
  NO_EOF_NEWLINE_FILES=""
115
217
  if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
116
- while IFS= read -r file; do
117
- [ -z "$file" ] && continue
118
- # Skip binary files
119
- if is_binary_staged_file "$file"; then
120
- continue
121
- fi
122
- if file_missing_eof_newline "$file"; then
123
- NO_EOF_NEWLINE_FILES="$NO_EOF_NEWLINE_FILES $file"
124
- fi
125
- done <<EOF
126
- $STAGED_FILES
127
- EOF
218
+ for file in $GATE_12_MISSING_EOF; do
219
+ NO_EOF_NEWLINE_FILES="$NO_EOF_NEWLINE_FILES $file"
220
+ done
128
221
  fi
129
222
 
130
223
  if [ -n "$NO_EOF_NEWLINE_FILES" ]; then
@@ -148,19 +241,9 @@ if [ "${GATE_12_DOCS_ONLY:-false}" = true ]; then
148
241
  CONFLICT_MARKER_FILES="$STAGED_FILES"
149
242
  fi
150
243
  else
151
- while IFS= read -r file; do
152
- [ -z "$file" ] && continue
153
- # Skip binary files
154
- if is_binary_staged_file "$file"; then
155
- continue
156
- fi
157
- # Check for conflict markers in staged content
158
- if git show ":$file" 2>/dev/null | grep -qE '^(<{7}|={7}|>{7})([[:space:]]|$)'; then
159
- CONFLICT_MARKER_FILES="$CONFLICT_MARKER_FILES $file"
160
- fi
161
- done <<EOF
162
- $STAGED_FILES
163
- EOF
244
+ for file in $GATE_12_HAS_CONFLICT; do
245
+ CONFLICT_MARKER_FILES="$CONFLICT_MARKER_FILES $file"
246
+ done
164
247
  fi
165
248
 
166
249
  if [ -n "$CONFLICT_MARKER_FILES" ]; then
@@ -178,7 +261,22 @@ if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
178
261
  while IFS= read -r file; do
179
262
  [ -z "$file" ] && continue
180
263
  [ ! -f "$file" ] && continue
181
- FILE_SIZE=$(wc -c < "$file" 2>/dev/null | tr -d ' ')
264
+ # `wc -c` is a process per file; measured 300 files = 12.6s on this machine,
265
+ # which after the blob scanner was the largest remaining share of a 36.9s run.
266
+ # `$(<file)` is a bash builtin with no fork, and `LC_ALL=C` makes ${#var} a
267
+ # BYTE count rather than a character count -- the threshold is in bytes
268
+ # (XP_GATE_MAX_FILE_SIZE, default 1 MiB), so a multibyte file must not measure
269
+ # short and slip under it.
270
+ #
271
+ # Binary files are not excluded from this check, so the read must not choke on
272
+ # them: an unreadable blob leaves FILE_SIZE empty and the comparison is skipped,
273
+ # exactly as a failed `wc -c` did.
274
+ FILE_SIZE=""
275
+ if [ -r "$file" ]; then
276
+ _g12_content=$(LC_ALL=C IFS= read -r -d '' _g12_all < "$file" 2>/dev/null; printf '%s' "${#_g12_all}")
277
+ FILE_SIZE=$((${_g12_content:-0}))
278
+ unset _g12_content
279
+ fi
182
280
  if [ -n "$FILE_SIZE" ] && [ "$FILE_SIZE" -gt "$MAX_FILE_SIZE_BYTES" ]; then
183
281
  SIZE_MB=$((FILE_SIZE / 1048576))
184
282
  OVERSIZED_FILES="$OVERSIZED_FILES $file(${SIZE_MB}MB)"
@@ -248,7 +346,8 @@ except yaml.YAMLError as e:
248
346
  except Exception:
249
347
  pass
250
348
  " 2>&1)
251
- if [ $? -ne 0 ] && [ -n "$YAML_ERROR" ]; then
349
+ _g12_rc=$?
350
+ if [ "$_g12_rc" -ne 0 ] && [ -n "$YAML_ERROR" ]; then
252
351
  YAML_JSON_ERRORS+=("$file(yaml:$YAML_ERROR)")
253
352
  fi
254
353
  fi
@@ -259,13 +358,15 @@ except Exception:
259
358
  JSON_ERROR=$(git show ":$file" 2>/dev/null | node -e "
260
359
  let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{try{JSON.parse(d)}catch(e){console.log(e.message.split('\\n')[0]);process.exit(1)}})
261
360
  " 2>&1)
262
- if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
361
+ _g12_rc=$?
362
+ if [ "$_g12_rc" -ne 0 ] && [ -n "$JSON_ERROR" ]; then
263
363
  YAML_JSON_ERRORS+=("$file(json:$JSON_ERROR)")
264
364
  fi
265
365
  elif [ "$JSON_CMD" = "jq" ]; then
266
366
  JSON_ERROR=$(git show ":$file" 2>/dev/null | jq empty 2>&1)
267
- if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
268
- YAML_JSON_ERRORS+=("$file(json:syntax error)")
367
+ _g12_rc=$?
368
+ if [ "$_g12_rc" -ne 0 ] && [ -n "$JSON_ERROR" ]; then
369
+ YAML_JSON_ERRORS+=("$file(json:$JSON_ERROR)")
269
370
  fi
270
371
  fi
271
372
  ;;
@@ -290,6 +391,9 @@ if [ "${GATE_12_DOCS_ONLY:-false}" = true ] && [ "$HYGIENE_ISSUES" -eq 0 ]; then
290
391
  echo " ✅ PASSED - File Hygiene (docs-only commit: diff-scoped conflict-marker + YAML/JSON checks clean)."
291
392
  GATE_12_STATUS="PASS"
292
393
  record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "0" "$GATE_12_START" "" "docs_only_change"
394
+ # shellcheck disable=SC2317 # the gate body is SOURCED, never run to completion here:
395
+ # the driver calls gate_12_run and treats a returned rc as the verdict, so the
396
+ # lines after this return ARE reachable in production (see pre-commit).
293
397
  return 0 2>/dev/null || true
294
398
  fi
295
399
  if [ "$HYGIENE_ISSUES" -eq 0 ]; then