@boyingliu01/xp-gate 0.38.4 → 0.38.6

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 (64) hide show
  1. package/adapters/gate-10.sh +478 -0
  2. package/adapters/gate-12-file-hygiene.sh +315 -0
  3. package/adapters/gate-13-compiler-strictness.sh +1443 -0
  4. package/adapters/gate-6-layers.sh +375 -0
  5. package/adapters/gate-8.sh +13 -1
  6. package/adapters/iac.sh +60 -27
  7. package/adapters/shell.sh +50 -2
  8. package/build-integrity/gate-10.ts +63 -4
  9. package/gate-12-file-hygiene.sh +15 -7
  10. package/gate-8.sh +13 -1
  11. package/hooks/gate-12-file-hygiene.sh +15 -7
  12. package/hooks/gate-8.sh +13 -1
  13. package/hooks/gate-entries/gate-1-entry.sh +44 -3
  14. package/hooks/gate-entries/gate-10-entry.sh +7 -0
  15. package/hooks/gate-entries/gate-11-entry.sh +7 -0
  16. package/hooks/gate-entries/gate-12-entry.sh +7 -0
  17. package/hooks/gate-entries/gate-12b-entry.sh +7 -0
  18. package/hooks/gate-entries/gate-12c-entry.sh +7 -0
  19. package/hooks/gate-entries/gate-13-entry.sh +7 -0
  20. package/hooks/gate-entries/gate-5-entry.sh +56 -2
  21. package/hooks/gate-entries/gate-6-entry.sh +93 -2
  22. package/hooks/gate-entries/gate-7-entry.sh +7 -0
  23. package/hooks/gate-entries/gate-8-entry.sh +7 -0
  24. package/hooks/gate-entries/gate-9-entry.sh +7 -0
  25. package/hooks/post-commit +9 -0
  26. package/hooks/pre-push +11 -2
  27. package/lib/mattpocock-license-verdict.json +1 -1
  28. package/mock-policy/AGENTS.md +1 -1
  29. package/mutation/AGENTS.md +1 -1
  30. package/package.json +1 -1
  31. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  32. package/plugins/claude-code/bin/xp-gate-version-check.sh +6 -0
  33. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  34. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  35. package/plugins/claude-code/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  36. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  37. package/plugins/dsh/package.json +1 -1
  38. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  39. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  40. package/plugins/dsh/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  41. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  42. package/plugins/opencode/package.json +1 -1
  43. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  44. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  45. package/plugins/opencode/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  46. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  47. package/plugins/qoder/plugin.json +1 -1
  48. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  49. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  50. package/plugins/qoder/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  51. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  52. package/principles/AGENTS.md +1 -1
  53. package/scripts/generate-mirrors.cjs +85 -28
  54. package/scripts/sync-package-content.js +5 -0
  55. package/skills/delphi-review/AGENTS.md +1 -1
  56. package/skills/sprint-flow/AGENTS.md +1 -1
  57. package/skills/test-specification-alignment/AGENTS.md +1 -1
  58. package/build-integrity/__tests__/ccn-refactor-gate10.test.ts +0 -133
  59. package/build-integrity/__tests__/gate-10.test.ts +0 -340
  60. package/build-integrity/__tests__/import-resolver.test.ts +0 -747
  61. package/build-integrity/__tests__/orchestrator.test.ts +0 -302
  62. package/build-integrity/__tests__/quote-masker.test.ts +0 -177
  63. package/skills/sprint-flow/__tests__/sprint-flow.test.cjs +0 -457
  64. package/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +0 -48
@@ -0,0 +1,315 @@
1
+ # ============================================================================
2
+ # GATE 12: File Hygiene Check
3
+ # Detects common file quality issues in staged files:
4
+ # - Trailing whitespace
5
+ # - Missing EOF newline
6
+ # - Merge conflict markers (<<<<<<< , =======, >>>>>>>)
7
+ # - Oversized files (>1MB default, configurable)
8
+ # ============================================================================
9
+
10
+ 2>&1 echo ""
11
+ 2>&1 echo "→ Gate 12: File hygiene check..."
12
+ GATE_12_START=$(gate_start_ms)
13
+
14
+ # Configuration (can be overridden via environment)
15
+ MAX_FILE_SIZE_BYTES="${XP_GATE_MAX_FILE_SIZE:-1048576}" # 1MB default
16
+
17
+ # Get list of staged files (excluding deleted files)
18
+ #
19
+ # Third-party trees are excluded. In a fresh `git init` fixture the CI's
20
+ # "First Commit Gates" job does `git add -A` before committing, so every
21
+ # node_modules/ file becomes staged — and third-party packages legitimately
22
+ # CONTAIN `<<<<<<<` text as documentation (semver/README.md, various NOTICE.txt).
23
+ # Gate 12 then reported "merge conflict markers detected" for files no author
24
+ # wrote, blocking the fixture commit, on every commit for months. A hygiene check
25
+ # that reads vendored documentation as a conflict is not finding anything.
26
+ #
27
+ # This is the same class as the __pycache__ filter in check-hook-mirror.sh (#587):
28
+ # build/dependency artefacts are not project source and must not be judged as it.
29
+ STAGED_FILES=$(git diff --cached --name-only --diff-filter=d 2>/dev/null \
30
+ | grep -vE '(^|/)(node_modules|\.stryker-tmp|vendor)/' || true)
31
+
32
+ if [ -z "$STAGED_FILES" ]; then
33
+ echo " ℹ️ No staged files — skipping"
34
+ echo " ✅ PASSED - File Hygiene (no files to check)"
35
+ GATE_12_STATUS="SKIP"
36
+ record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "0" "$GATE_12_START"
37
+ return 0 2>/dev/null || true
38
+ fi
39
+
40
+ # REQ-F2: a docs-only commit cannot introduce code regressions; conflict
41
+ # markers and YAML/JSON syntax are still checked (diff-scoped below).
42
+ if [ "${DOCS_ONLY_COMMIT:-false}" = true ]; then
43
+ echo " ⏭️ SKIPPED - File hygiene heavy checks (documentation-only commit; diff-scoped checks still run)."
44
+ GATE_12_STATUS="SKIP"
45
+ GATE_12_DOCS_ONLY=true
46
+ fi
47
+
48
+ HYGIENE_ISSUES=0
49
+ HYGIENE_FILES=""
50
+
51
+ # Is this staged file binary (so line-based checks do not apply)?
52
+ #
53
+ # This replaces `grep -q $'\x00'`, which was a no-op guard: bash strips NUL from
54
+ # `$'\x00'`, so the pattern was the EMPTY string and `grep -q ""` matches any
55
+ # non-empty input. Every staged file was therefore judged binary and `continue`d,
56
+ # silently disabling Check 1 (trailing whitespace), Check 2 (missing EOF newline)
57
+ # and -- worst -- Check 3 (merge conflict markers, a BLOCK-level check). Checks 4
58
+ # and 5 lacked the guard, which is why the gate looked half-working.
59
+ #
60
+ # Ask git instead of guessing: `--numstat` reports a binary entry as `-\t-\t<path>`
61
+ # because git already made that determination. A byte-level NUL test cannot be
62
+ # written with a shell pattern at all (variables and command substitution both drop
63
+ # NUL), and `grep -I` only suppresses output on a binary input -- it does not make
64
+ # `grep -q` fail, which is why that shortcut still reported text.
65
+ 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)
70
+ esac
71
+ }
72
+
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
86
+ done <<EOF
87
+ $STAGED_FILES
88
+ EOF
89
+ fi
90
+
91
+ if [ -n "$TRAILING_WS_FILES" ]; then
92
+ echo " ⚠️ Trailing whitespace detected in:"
93
+ for f in $TRAILING_WS_FILES; do
94
+ echo " - $f"
95
+ done
96
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
97
+ HYGIENE_FILES="$HYGIENE_FILES trailing-whitespace"
98
+ fi
99
+
100
+ # --- Check 2: Missing EOF newline ---
101
+ # Reads the LAST BYTE from the raw blob. The previous form captured the content
102
+ # with $(...) and then asked for its final character: command substitution
103
+ # strips every trailing newline, so a file that ends correctly produced its last
104
+ # visible character — never empty — and was reported as missing its newline.
105
+ # Every staged text file was a false positive, which is how a check that always
106
+ # fires looks exactly like a strict check. `git show | tail -c 1` keeps the byte.
107
+ 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" ]
112
+ }
113
+
114
+ NO_EOF_NEWLINE_FILES=""
115
+ 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
128
+ fi
129
+
130
+ if [ -n "$NO_EOF_NEWLINE_FILES" ]; then
131
+ echo " ⚠️ Missing EOF newline in:"
132
+ for f in $NO_EOF_NEWLINE_FILES; do
133
+ echo " - $f"
134
+ done
135
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
136
+ HYGIENE_FILES="$HYGIENE_FILES no-eof-newline"
137
+ fi
138
+
139
+ # --- Check 3: Merge conflict markers ---
140
+ # Runs in BOTH modes. Docs-only commits read the staged DIFF (hunk cost)
141
+ # instead of every full blob — a marker line must be ADDED to matter, so
142
+ # '^+' minus '+++' headers is the precise scope.
143
+ # Exactly 7 chars + a space/EOL boundary: longer runs (Maven `====` log separators, RST/setext underlines) are not conflicts.
144
+ CONFLICT_MARKER_FILES=""
145
+ if [ "${GATE_12_DOCS_ONLY:-false}" = true ]; then
146
+ if git diff --cached --no-color --diff-filter=d 2>/dev/null \
147
+ | grep -E '^\+' | grep -v '^+++' | grep -qE '^\+(<{7}|={7}|>{7})([[:space:]]|$)'; then
148
+ CONFLICT_MARKER_FILES="$STAGED_FILES"
149
+ fi
150
+ 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
164
+ fi
165
+
166
+ if [ -n "$CONFLICT_MARKER_FILES" ]; then
167
+ echo " ❌ Merge conflict markers detected in:"
168
+ for f in $CONFLICT_MARKER_FILES; do
169
+ echo " - $f"
170
+ done
171
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
172
+ HYGIENE_FILES="$HYGIENE_FILES conflict-markers"
173
+ fi
174
+
175
+ # --- Check 4: Oversized files ---
176
+ OVERSIZED_FILES=""
177
+ if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
178
+ while IFS= read -r file; do
179
+ [ -z "$file" ] && continue
180
+ [ ! -f "$file" ] && continue
181
+ FILE_SIZE=$(wc -c < "$file" 2>/dev/null | tr -d ' ')
182
+ if [ -n "$FILE_SIZE" ] && [ "$FILE_SIZE" -gt "$MAX_FILE_SIZE_BYTES" ]; then
183
+ SIZE_MB=$((FILE_SIZE / 1048576))
184
+ OVERSIZED_FILES="$OVERSIZED_FILES $file(${SIZE_MB}MB)"
185
+ fi
186
+ done <<EOF
187
+ $STAGED_FILES
188
+ EOF
189
+ fi
190
+
191
+ if [ -n "$OVERSIZED_FILES" ]; then
192
+ echo " ⚠️ Oversized files (>${MAX_FILE_SIZE_BYTES} bytes):"
193
+ for f in $OVERSIZED_FILES; do
194
+ echo " - $f"
195
+ done
196
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
197
+ HYGIENE_FILES="$HYGIENE_FILES oversized-files"
198
+ fi
199
+
200
+ # --- Check 5: YAML/JSON syntax validation (Issue #351) ---
201
+ # Only check staged YAML/JSON files that have changes
202
+ #
203
+ # #772: these were accumulated into a space-separated STRING and re-split with an
204
+ # unquoted `for f in $YAML_JSON_ERRORS`. Parser messages contain spaces, so one
205
+ # broken file printed as a run of fake "filenames" -- PyYAML's
206
+ # "while parsing a flow sequence" became five entries. The list under
207
+ # "YAML/JSON syntax errors:" reads as the set of files to go fix, so the split
208
+ # sent the reader hunting for files that do not exist. Arrays keep each entry
209
+ # whole no matter what the message contains.
210
+ YAML_JSON_ERRORS=()
211
+ YAML_JSON_CHECK_COUNT=0
212
+
213
+ # Detect available validators
214
+ YAML_CMD=""
215
+ if command -v python3 >/dev/null 2>&1; then
216
+ YAML_CMD="python3"
217
+ elif command -v python >/dev/null 2>&1; then
218
+ YAML_CMD="python"
219
+ fi
220
+
221
+ JSON_CMD=""
222
+ if command -v node >/dev/null 2>&1; then
223
+ JSON_CMD="node"
224
+ elif command -v jq >/dev/null 2>&1; then
225
+ JSON_CMD="jq"
226
+ fi
227
+
228
+ # Check which staged YAML/JSON files actually changed (REQ-F3: a repo with 40
229
+ # YAML configs but one edited file validates ONE blob, not forty).
230
+ CHANGED_YAML_JSON=$(git diff --cached --name-only --diff-filter=d -- '*.yml' '*.yaml' '*.json' 2>/dev/null)
231
+
232
+ while IFS= read -r file; do
233
+ [ -z "$file" ] && continue
234
+ [ ! -f "$file" ] && continue
235
+
236
+ case "$file" in
237
+ *.yml|*.yaml)
238
+ if [ -n "$YAML_CMD" ]; then
239
+ YAML_JSON_CHECK_COUNT=$((YAML_JSON_CHECK_COUNT + 1))
240
+ # Validate YAML syntax using Python's yaml module
241
+ YAML_ERROR=$(git show ":$file" 2>/dev/null | $YAML_CMD -c "
242
+ import sys, yaml
243
+ try:
244
+ yaml.safe_load(sys.stdin.read())
245
+ except yaml.YAMLError as e:
246
+ print(str(e).split(chr(10))[0])
247
+ sys.exit(1)
248
+ except Exception:
249
+ pass
250
+ " 2>&1)
251
+ if [ $? -ne 0 ] && [ -n "$YAML_ERROR" ]; then
252
+ YAML_JSON_ERRORS+=("$file(yaml:$YAML_ERROR)")
253
+ fi
254
+ fi
255
+ ;;
256
+ *.json)
257
+ YAML_JSON_CHECK_COUNT=$((YAML_JSON_CHECK_COUNT + 1))
258
+ if [ "$JSON_CMD" = "node" ]; then
259
+ JSON_ERROR=$(git show ":$file" 2>/dev/null | node -e "
260
+ 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
+ " 2>&1)
262
+ if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
263
+ YAML_JSON_ERRORS+=("$file(json:$JSON_ERROR)")
264
+ fi
265
+ elif [ "$JSON_CMD" = "jq" ]; then
266
+ 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)")
269
+ fi
270
+ fi
271
+ ;;
272
+ esac
273
+ done <<EOF
274
+ $CHANGED_YAML_JSON
275
+ EOF
276
+
277
+ if [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
278
+ echo " ❌ YAML/JSON syntax errors:"
279
+ for f in "${YAML_JSON_ERRORS[@]}"; do
280
+ echo " - $f"
281
+ done
282
+ HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
283
+ HYGIENE_FILES="$HYGIENE_FILES yaml-json-syntax"
284
+ elif [ "$YAML_JSON_CHECK_COUNT" -gt 0 ]; then
285
+ echo " ✅ YAML/JSON syntax OK ($YAML_JSON_CHECK_COUNT file(s) checked)"
286
+ fi
287
+
288
+ # --- Result ---
289
+ if [ "${GATE_12_DOCS_ONLY:-false}" = true ] && [ "$HYGIENE_ISSUES" -eq 0 ]; then
290
+ echo " ✅ PASSED - File Hygiene (docs-only commit: diff-scoped conflict-marker + YAML/JSON checks clean)."
291
+ GATE_12_STATUS="PASS"
292
+ record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "0" "$GATE_12_START" "" "docs_only_change"
293
+ return 0 2>/dev/null || true
294
+ fi
295
+ if [ "$HYGIENE_ISSUES" -eq 0 ]; then
296
+ echo " ✅ PASSED - No file hygiene issues detected."
297
+ GATE_12_STATUS="PASS"
298
+ else
299
+ # Hard blocks: conflict markers + YAML/JSON syntax errors
300
+ if [ -n "$CONFLICT_MARKER_FILES" ] || [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
301
+ echo ""
302
+ echo "❌ BLOCKED - File hygiene violations must be fixed before commit."
303
+ GATE_12_STATUS="BLOCK"
304
+ record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "$HYGIENE_ISSUES" "$GATE_12_START"
305
+ exit 1
306
+ else
307
+ echo ""
308
+ echo " ⚠️ WARNINGS - $HYGIENE_ISSUES file hygiene issue(s) found."
309
+ echo " Fix recommended but not blocking (no conflict markers or syntax errors)."
310
+ echo " Issues:$HYGIENE_FILES"
311
+ GATE_12_STATUS="WARN"
312
+ fi
313
+ fi
314
+
315
+ record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "$HYGIENE_ISSUES" "$GATE_12_START"