@boyingliu01/xp-gate 0.37.3 → 0.38.1

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 (116) hide show
  1. package/adapter-common.sh +12 -2
  2. package/adapters/csharp.sh +73 -2
  3. package/adapters/dart.sh +13 -0
  4. package/adapters/go.sh +5 -0
  5. package/adapters/iac.sh +46 -3
  6. package/adapters/java.sh +6 -0
  7. package/adapters/kotlin.sh +6 -0
  8. package/adapters/shell.sh +119 -34
  9. package/adapters/swift.sh +6 -0
  10. package/adapters/typescript.sh +98 -34
  11. package/bin/xp-gate.js +48 -2
  12. package/gate-10.sh +99 -26
  13. package/gate-12-file-hygiene.sh +13 -1
  14. package/gate-registry.sh +197 -0
  15. package/gates/python-health.ts +67 -29
  16. package/hooks/adapter-common.sh +12 -2
  17. package/hooks/deploy-manifest.sh +100 -0
  18. package/hooks/gate-10.sh +99 -26
  19. package/hooks/gate-12-file-hygiene.sh +13 -1
  20. package/hooks/gate-driver.sh +120 -0
  21. package/hooks/gate-entries/gate-0-entry.sh +825 -0
  22. package/hooks/gate-entries/gate-1-entry.sh +767 -0
  23. package/hooks/gate-entries/gate-10-entry.sh +52 -0
  24. package/hooks/gate-entries/gate-11-entry.sh +120 -0
  25. package/hooks/gate-entries/gate-12-entry.sh +44 -0
  26. package/hooks/gate-entries/gate-12b-entry.sh +178 -0
  27. package/hooks/gate-entries/gate-12c-entry.sh +80 -0
  28. package/hooks/gate-entries/gate-13-entry.sh +584 -0
  29. package/hooks/gate-entries/gate-2-entry.sh +199 -0
  30. package/hooks/gate-entries/gate-3-entry.sh +53 -0
  31. package/hooks/gate-entries/gate-4-entry.sh +46 -0
  32. package/hooks/gate-entries/gate-5-entry.sh +1729 -0
  33. package/hooks/gate-entries/gate-6-entry.sh +658 -0
  34. package/hooks/gate-entries/gate-7-entry.sh +41 -0
  35. package/hooks/gate-entries/gate-8-entry.sh +33 -0
  36. package/hooks/gate-entries/gate-9-entry.sh +307 -0
  37. package/hooks/gate-entries/subdir-restore.sh +27 -0
  38. package/hooks/gate-registry.sh +51 -15
  39. package/hooks/hook-module-resolution.sh +73 -0
  40. package/hooks/install.sh +135 -0
  41. package/hooks/lib/now-ms.sh +55 -19
  42. package/hooks/lib/toolchain-path.sh +50 -6
  43. package/hooks/pre-commit +256 -5091
  44. package/hooks/pre-push +212 -25
  45. package/lib/__tests__/arch-config-template.test.js +190 -0
  46. package/lib/__tests__/baseline-shell-scope.test.js +60 -0
  47. package/lib/__tests__/crap-cli.test.js +14 -3
  48. package/lib/__tests__/deploy-manifest-check-wired.test.js +138 -0
  49. package/lib/__tests__/deploy-manifest-completeness.test.js +151 -0
  50. package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +40 -0
  51. package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +74 -0
  52. package/lib/__tests__/deploy-manifest-projection.test.js +66 -0
  53. package/lib/__tests__/deploy-manifest-shell-parity.test.js +108 -0
  54. package/lib/__tests__/deploy-manifest.test.js +97 -0
  55. package/lib/__tests__/doctor.test.js +51 -7
  56. package/lib/__tests__/gate-coverage.test.js +79 -12
  57. package/lib/__tests__/gate-numbering.test.js +28 -1
  58. package/lib/__tests__/install-sh-deploy-manifest.test.js +80 -0
  59. package/lib/__tests__/mirror-sync.test.js +45 -3
  60. package/lib/__tests__/npm-package.test.js +10 -7
  61. package/lib/__tests__/sastd-client.test.js +514 -0
  62. package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +69 -0
  63. package/lib/__tests__/sprint-status-rework.test.js +1 -0
  64. package/lib/arch-config-template.js +87 -0
  65. package/lib/baseline.js +54 -2
  66. package/lib/deploy-manifest.js +174 -0
  67. package/lib/doctor.js +46 -14
  68. package/lib/gate-capability.js +291 -0
  69. package/lib/gate-coverage.js +194 -74
  70. package/lib/gate-identity.js +349 -0
  71. package/lib/gate-runner.js +11 -1
  72. package/lib/hook-module-resolution.js +27 -0
  73. package/lib/init.js +72 -5
  74. package/lib/mattpocock-license-verdict.json +1 -1
  75. package/lib/sastd-client.js +572 -0
  76. package/lib/shared-utils.js +31 -9
  77. package/lib/uninstall.js +10 -7
  78. package/lib/update-hooks.js +27 -18
  79. package/mock-policy/AGENTS.md +1 -1
  80. package/mutation/AGENTS.md +1 -1
  81. package/package.json +3 -1
  82. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  83. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  84. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  85. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  86. package/plugins/dsh/package.json +1 -1
  87. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  88. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  89. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  90. package/plugins/opencode/package.json +1 -1
  91. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  92. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  93. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  94. package/plugins/qoder/plugin.json +1 -1
  95. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  96. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  97. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  98. package/principles/AGENTS.md +1 -1
  99. package/principles/__tests__/analyzer.test.ts +2 -1
  100. package/principles/__tests__/config-enforcement.test.ts +1 -0
  101. package/principles/__tests__/types.test.ts +1 -0
  102. package/principles/adapters/base.ts +14 -1
  103. package/principles/adapters/duplication.ts +134 -0
  104. package/principles/rules/__tests__/clean-code/large-file.test.ts +2 -1
  105. package/principles/rules/clean-code/code-duplication.ts +75 -9
  106. package/principles/types.ts +39 -0
  107. package/scripts/__tests__/check-mattpocock-license.test.js +36 -3
  108. package/scripts/__tests__/sync-package-content.test.js +12 -2
  109. package/scripts/generate-mirrors.cjs +125 -0
  110. package/scripts/sync-package-content.js +64 -20
  111. package/skills/delphi-review/AGENTS.md +1 -1
  112. package/skills/sprint-flow/AGENTS.md +1 -1
  113. package/skills/test-specification-alignment/AGENTS.md +1 -1
  114. package/adapters/gate-9.sh +0 -245
  115. package/gate-9.sh +0 -245
  116. package/hooks/gate-9.sh +0 -245
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-7 entry — extracted from pre-commit by scripts/extract-gates.cjs
4
+ #
5
+ # WHY THIS FILE EXISTS (#798)
6
+ # The gate order used to BE the physical order of blocks in a 6341-line
7
+ # hook, so changing the order meant moving thousands of lines. An attempt at
8
+ # that also moved the hook epilogue, after which every gate past Gate 13
9
+ # silently stopped running while `bash -n`, a line count and five ordering
10
+ # tests all passed. Gate 5a stopped blocking and only a behavioural test
11
+ # noticed. With one file per gate, order is a list of names in
12
+ # pre-commit's GATE_ORDER and cannot detach a body from its position.
13
+ #
14
+ # THE BODY BELOW IS A BYTE-EXACT SLICE of the original block. It is wrapped
15
+ # in a function so the gate keeps its own variable scope, and is called from
16
+ # pre-commit at the point the driver reaches it. Edit the gate here from now
17
+ # on - there is no copy left in the hook.
18
+ # ============================================================================
19
+
20
+ # ============================================================================
21
+ # GATE 7: IaC Security Scanning (Terraform, Kubernetes, Docker)
22
+ # Extracted to gate-7.sh for maintainability
23
+ # v0.14.3+ (Issue #312): Skip if no IaC files changed
24
+ # ============================================================================
25
+ # Gate body. `return` is used instead of `exit` so the driver decides to
26
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
27
+ # here, and why sub-shell exits are deliberately left as `exit`.
28
+ gate_7_run() {
29
+ if any_changed_files_match "\.tf$" "\.tfvars$" "Dockerfile" "\.kube/" "\.ya?ml$"; then
30
+ source "$GATE_DIR/gate-7.sh"
31
+ else
32
+ echo "✅ PASSED - No IaC files changed, skipping Gate 7."
33
+ fi
34
+ return 0
35
+ }
36
+
37
+
38
+
39
+
40
+ # Called by pre-commit's ordered driver.
41
+
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-8 entry — extracted from pre-commit by scripts/extract-gates.cjs
4
+ #
5
+ # WHY THIS FILE EXISTS (#798)
6
+ # The gate order used to BE the physical order of blocks in a 6341-line
7
+ # hook, so changing the order meant moving thousands of lines. An attempt at
8
+ # that also moved the hook epilogue, after which every gate past Gate 13
9
+ # silently stopped running while `bash -n`, a line count and five ordering
10
+ # tests all passed. Gate 5a stopped blocking and only a behavioural test
11
+ # noticed. With one file per gate, order is a list of names in
12
+ # pre-commit's GATE_ORDER and cannot detach a body from its position.
13
+ #
14
+ # THE BODY BELOW IS A BYTE-EXACT SLICE of the original block. It is wrapped
15
+ # in a function so the gate keeps its own variable scope, and is called from
16
+ # pre-commit at the point the driver reaches it. Edit the gate here from now
17
+ # on - there is no copy left in the hook.
18
+ # ============================================================================
19
+
20
+ # GATE 8: Secret Scanning (gitleaks)
21
+ # Extracted to gate-8.sh for maintainability
22
+ # ============================================================================
23
+ # Gate body. `return` is used instead of `exit` so the driver decides to
24
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
25
+ # here, and why sub-shell exits are deliberately left as `exit`.
26
+ gate_8_run() {
27
+ source "$GATE_DIR/gate-8.sh"
28
+ return 0
29
+ }
30
+
31
+
32
+ # Called by pre-commit's ordered driver.
33
+
@@ -0,0 +1,307 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-9 entry — extracted from pre-commit by scripts/extract-gates.cjs
4
+ #
5
+ # WHY THIS FILE EXISTS (#798)
6
+ # The gate order used to BE the physical order of blocks in a 6341-line
7
+ # hook, so changing the order meant moving thousands of lines. An attempt at
8
+ # that also moved the hook epilogue, after which every gate past Gate 13
9
+ # silently stopped running while `bash -n`, a line count and five ordering
10
+ # tests all passed. Gate 5a stopped blocking and only a behavioural test
11
+ # noticed. With one file per gate, order is a list of names in
12
+ # pre-commit's GATE_ORDER and cannot detach a body from its position.
13
+ #
14
+ # THE BODY BELOW IS A BYTE-EXACT SLICE of the original block. It is wrapped
15
+ # in a function so the gate keeps its own variable scope, and is called from
16
+ # pre-commit at the point the driver reaches it. Edit the gate here from now
17
+ # on - there is no copy left in the hook.
18
+ # ============================================================================
19
+
20
+ # ============================================================================
21
+ # GATE 9: Build Integrity Check (TypeScript compilation + package + imports)
22
+ # ============================================================================
23
+
24
+ # Gate body. `return` is used instead of `exit` so the driver decides to
25
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
26
+ # here, and why sub-shell exits are deliberately left as `exit`.
27
+ gate_9_run() {
28
+ # Java build-integrity dispatch (#507 S5, DR-003). The old gate only knew
29
+ # TypeScript: a Maven project got a permanent SKIP -- "not a TypeScript
30
+ # project" -- which is exactly the silent-no-coverage path this sprint
31
+ # removes. Verdict codes (mirror of the java.sh G1 contract):
32
+ # 0=PASS 2=BLOCK(compile failed) 3=SKIP+WARN(reason printed)
33
+ resolve_build_integrity_timeout() {
34
+ local file=".xp-gate/build-integrity-timeout" val=""
35
+ if [ -f "$file" ]; then
36
+ val=$(tr -d '[:space:]' < "$file")
37
+ fi
38
+ if [ -z "$val" ]; then
39
+ echo "180"
40
+ return 0
41
+ fi
42
+ case "$val" in
43
+ ''|*[!0-9]*|0)
44
+ echo "WARN - invalid $file value '${val}' (expected a positive integer), falling back to 180s" >&2
45
+ echo "180"
46
+ ;;
47
+ *) echo "$val" ;;
48
+ esac
49
+ }
50
+
51
+ # (#708) A Java build failure has one overwhelmingly common cause that the gate
52
+ # used to say nothing about: the wrong JDK. The real reason is buried in the last
53
+ # 20 lines of Maven output, while the gate's own verdict line was only
54
+ # "❌ Java build failed (exit 1)".
55
+ #
56
+ # Measured: a pom with <maven.compiler.release>8</maven.compiler.release> built
57
+ # with JDK 8 fails with "无效的标记: --release" (invalid flag: --release) — a
58
+ # message that points at the compiler ARGUMENTS and at the project CONFIG while
59
+ # actually pointing at the JDK on PATH. Getting from that message to "change the
60
+ # JDK" takes one inference, and the gate's verdict line supplied no premise for
61
+ # it. The person debugging this suspected the release setting, then the plugin
62
+ # version, then .mvn/jvm.config — all wrong; the fix was a different JDK.
63
+ #
64
+ # So: on failure, print what JDK actually ran, what the project asks for, and —
65
+ # when the output carries the tell — state the conclusion instead of the symptom.
66
+ # Diagnostics must never change the verdict; this only adds lines.
67
+ java_bi_report_jdk_context() {
68
+ local build_out="$1"
69
+ local java_version="" java_home_val="${JAVA_HOME:-}"
70
+ # `java -version` writes to stderr on every JDK. Take the version line verbatim
71
+ # rather than parsing it: this is a diagnostic, and the raw line is what a
72
+ # person would paste into a bug report.
73
+ if command -v java >/dev/null 2>&1; then
74
+ java_version=$(java -version 2>&1 | sed -n '1p')
75
+ fi
76
+ if [ -n "$java_version" ]; then
77
+ echo " JDK in use: ${java_version}"
78
+ else
79
+ echo " JDK in use: (java not on PATH)"
80
+ fi
81
+ if [ -n "$java_home_val" ]; then
82
+ echo " JAVA_HOME: ${java_home_val}"
83
+ else
84
+ echo " JAVA_HOME: (unset)"
85
+ fi
86
+
87
+ # What the project requires. Maven declares it three ways; Gradle declares it in
88
+ # its build script. Report whichever exists — the comparison is the user's, but
89
+ # only if both halves are visible.
90
+ local declared=""
91
+ if [ -f "pom.xml" ]; then
92
+ local mvn_release mvn_source
93
+ mvn_release=$(grep -o '<maven\.compiler\.release>[[:space:]]*[0-9][0-9]*' pom.xml 2>/dev/null \
94
+ | sed 's/.*>[[:space:]]*//' | head -1)
95
+ mvn_source=$(grep -o '<maven\.compiler\.source>[[:space:]]*[0-9][0-9]*' pom.xml 2>/dev/null \
96
+ | sed 's/.*>[[:space:]]*//' | head -1)
97
+ if [ -n "$mvn_release" ]; then
98
+ declared="maven.compiler.release=${mvn_release}"
99
+ elif [ -n "$mvn_source" ]; then
100
+ declared="maven.compiler.source=${mvn_source}"
101
+ fi
102
+ fi
103
+ if [ -z "$declared" ] && [ -f "build.gradle" ]; then
104
+ local g_compat
105
+ g_compat=$(grep -o "sourceCompatibility[[:space:]]*=[[:space:]]*['\"]\{0,1\}[0-9][0-9]*" build.gradle 2>/dev/null \
106
+ | sed "s/.*[=][[:space:]]*['\"]\{0,1\}//" | head -1)
107
+ [ -n "$g_compat" ] && declared="sourceCompatibility=${g_compat}"
108
+ fi
109
+ if [ -z "$declared" ] && [ -f "build.gradle.kts" ]; then
110
+ local k_compat
111
+ k_compat=$(grep -o 'sourceCompatibility[[:space:]]*=[[:space:]]*JavaVersion\.VERSION_[0-9_]*' build.gradle.kts 2>/dev/null \
112
+ | sed 's/.*VERSION_//' | tr '_' '.' | head -1)
113
+ [ -n "$k_compat" ] && declared="sourceCompatibility=${k_compat}"
114
+ fi
115
+
116
+ if [ -n "$declared" ]; then
117
+ echo " Project requires: ${declared}"
118
+ else
119
+ echo " Project requires: (no JDK floor declared in pom.xml/build.gradle)"
120
+ fi
121
+
122
+ # The tell. `--release` only exists from JDK 9, so its rejection is a direct
123
+ # statement about the JDK, not about the pom. Saying so converts a search into
124
+ # a fix.
125
+ case "$build_out" in
126
+ *--release*)
127
+ if printf '%s' "$build_out" | grep -qiE 'invalid flag|无效的标记|illegal option|unrecognized|unknown option'; then
128
+ echo " 💡 The build passed '--release' to javac and the JDK rejected it."
129
+ echo " '--release' requires JDK 9 or newer; the JDK above is older than that."
130
+ echo " Switch to a JDK >= 9 (or remove the release/source setting if it is not intended)."
131
+ fi
132
+ ;;
133
+ esac
134
+ }
135
+
136
+ run_java_build_integrity() {
137
+ local timeout_s build_bin
138
+ # Wrapper first: mvnw pins the project's own Maven version.
139
+ if [ -x "./mvnw" ]; then
140
+ build_bin="./mvnw"
141
+ elif command -v mvn >/dev/null 2>&1; then
142
+ build_bin="mvn"
143
+ else
144
+ echo " ⚠️ Java changes staged but no Maven build tool found (mvnw/mvn)"
145
+ echo " ⏭️ SKIPPED - Build integrity Java (no build tool)"
146
+ return 3
147
+ fi
148
+
149
+ timeout_s=$(resolve_build_integrity_timeout)
150
+ # (#708) Keep the output: the failure branch has to read it to tell a wrong-JDK
151
+ # failure from any other one. Displayed through `tail -20` exactly as before, so
152
+ # the visible build log is unchanged.
153
+ local bi_out
154
+ if command -v timeout >/dev/null 2>&1; then
155
+ bi_out=$(timeout "$timeout_s" "$build_bin" -q -DskipTests compile 2>&1)
156
+ else
157
+ bi_out=$("$build_bin" -q -DskipTests compile 2>&1)
158
+ fi
159
+ local rc=$?
160
+ printf '%s\n' "$bi_out" | tail -20
161
+ if [ "$rc" -eq 0 ]; then
162
+ echo " ✅ Java build integrity verified (mvn -q -DskipTests compile)."
163
+ return 0
164
+ fi
165
+ if [ "$rc" -eq 124 ]; then
166
+ echo " ⏱️ Java build timed out after ${timeout_s}s."
167
+ echo " ⏭️ SKIPPED - Build integrity Java (timeout)"
168
+ return 3
169
+ fi
170
+ echo " ❌ Java build failed (exit $rc)"
171
+ java_bi_report_jdk_context "$bi_out"
172
+ return 2
173
+ }
174
+
175
+ 2>&1 echo ""
176
+ 2>&1 echo "→ Gate 9: Build integrity... "
177
+ GATE_9_START=$(gate_start_ms)
178
+ # Sub-status aggregation (#507 Delphi round-1 B-MAJOR-4): each half records
179
+ # its own outcome; GATE_9_STATUS is aggregated after both. The previous
180
+ # single-variable design made a Maven-only repo (TS half never runs, Java
181
+ # half passes) record an ETERNAL SKIP -- a real compile verification that
182
+ # never appeared as PASS, contradicting S5's own motivation.
183
+ GATE_9_TS_STATUS="SKIP"
184
+ GATE_9_JAVA_STATUS="SKIP"
185
+ GATE_9_STATUS="SKIP"
186
+
187
+ if [ "$DOCS_ONLY_COMMIT" = true ]; then
188
+ # REQ-F2: tsc cannot observe a markdown edit. The commit-level docs-only
189
+ # verdict was already consulted by Gates 2 and 5 but not here, so a pure docs
190
+ # commit still paid ~11s for a compile that had nothing new to compile.
191
+ # Recorded as SKIP (not PASS): nothing was verified.
192
+ GATE_9_TS_STATUS="SKIP"
193
+ GATE_9_JAVA_STATUS="SKIP"
194
+ echo " ⏭️ SKIPPED - Build integrity (docs-only commit)."
195
+ elif [ "$PROJECT_LANG" = "documentation-only" ]; then
196
+ echo " ⏭️ SKIPPED - Build integrity (documentation project)."
197
+ elif [ -f "package.json" ] && [ -f "tsconfig.json" ]; then
198
+ GATE_9_SCRIPT=""
199
+ if [ -f "$PROJECT_ROOT/src/build-integrity/gate-10.ts" ]; then
200
+ GATE_9_SCRIPT="$PROJECT_ROOT/src/build-integrity/gate-10.ts"
201
+ elif [ -f ".xp-gate/modules/build-integrity/gate-10.ts" ]; then
202
+ GATE_9_SCRIPT=".xp-gate/modules/build-integrity/gate-10.ts"
203
+ elif [ -f "$HOME/.config/xp-gate/modules/build-integrity/gate-10.ts" ]; then
204
+ GATE_9_SCRIPT="$HOME/.config/xp-gate/modules/build-integrity/gate-10.ts"
205
+ fi
206
+
207
+ # #581: the script path goes to node.exe. On WSL $HOME is /home/<user>, which node.exe
208
+ # resolves to <current drive>:\home\<user>\... -- module not found -- and Gate 9 then
209
+ # reported "Build integrity check failed" with advice to fix type errors in the USER'S
210
+ # code. Convert the path first so the failure, if any, is a real one.
211
+ if [ -n "$GATE_9_SCRIPT" ]; then
212
+ GATE_9_SCRIPT=$(to_native_path "$GATE_9_SCRIPT")
213
+ fi
214
+ # Same for the project root, which reaches both node and tsx as an absolute path.
215
+ GATE_9_PROJECT_ROOT=$(to_native_path "$PROJECT_ROOT")
216
+
217
+ if [ -n "$GATE_9_SCRIPT" ]; then
218
+ CHANGED_FILES_CSV=$(echo "$CHANGED_FILES" | tr ' ' ',')
219
+ GATE_9_OUTPUT=$(mktemp)
220
+ if RUN_TSX_TIMEOUT=120s run_tsx "$GATE_9_SCRIPT" --changed-files "$CHANGED_FILES_CSV" --project-root "$GATE_9_PROJECT_ROOT" --timeout 115000 > "$GATE_9_OUTPUT" 2>&1; then
221
+ GATE_9_TS_STATUS="PASS"
222
+ echo " ✅ Build integrity check passed."
223
+ else
224
+ GATE_9_EXIT=$?
225
+ if [ $GATE_9_EXIT -eq 124 ]; then
226
+ GATE_9_TS_STATUS="SKIP"
227
+ echo " ⏱️ Build integrity check timed out (120s). SKIPPED."
228
+ else
229
+ GATE_9_TS_STATUS="BLOCK"
230
+ cat "$GATE_9_OUTPUT"
231
+ echo ""
232
+ echo "❌ BLOCKED - Gate 9: Build integrity check failed"
233
+ echo "Fix type errors, broken imports, or package manifest issues before committing."
234
+ rm -f "$GATE_9_OUTPUT"
235
+ return 1
236
+ fi
237
+ fi
238
+ rm -f "$GATE_9_OUTPUT"
239
+ else
240
+ echo " ℹ️ Build integrity script not found - skipping"
241
+ echo " ⏭️ SKIPPED - Build integrity (gate-10.ts not available)"
242
+ fi
243
+ else
244
+ echo " ℹ️ Not a TypeScript project - skipping build integrity check"
245
+ echo " ⏭️ SKIPPED - Build integrity (not a TypeScript project)"
246
+ fi
247
+
248
+ # Java dispatch (#507 S5): runs when .java files are staged, regardless of
249
+ # whether the TypeScript half ran. Gradle-only repos SKIP+WARN (gradle
250
+ # support is backlog; DR-003).
251
+ if echo "$CHANGED_FILES" | grep -q '\.java$'; then
252
+ if [ -f "pom.xml" ]; then
253
+ JAVA_BI_EXIT=0
254
+ run_java_build_integrity || JAVA_BI_EXIT=$?
255
+ case "$JAVA_BI_EXIT" in
256
+ 0)
257
+ GATE_9_JAVA_STATUS="PASS"
258
+ ;;
259
+ 2)
260
+ GATE_9_JAVA_STATUS="BLOCK"
261
+ echo ""
262
+ echo "❌ BLOCKED - Gate 9: Java build integrity check failed"
263
+ echo "Fix the compile errors before committing."
264
+ return 1
265
+ ;;
266
+ *)
267
+ GATE_9_JAVA_STATUS="SKIP"
268
+ echo " ⏭️ SKIPPED - Build integrity Java (see reason above)"
269
+ ;;
270
+ esac
271
+ elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
272
+ echo " ⚠️ Java changes staged but this is a Gradle project - build integrity for Gradle is not implemented yet"
273
+ echo " ⏭️ SKIPPED - Build integrity Java (Gradle backlog, #507 DR-003)"
274
+ else
275
+ echo " ℹ️ Java changes staged but no Maven/Gradle build file - skipping Java build integrity"
276
+ fi
277
+ fi
278
+
279
+ # Aggregate the two halves (#507 Delphi round-1 B-MAJOR-4): PASS when every
280
+ # half that RAN passed (TS PASS + Java SKIP, or vice versa, both count),
281
+ # SKIP only when NOTHING ran, BLOCK on any failure (normally unreachable --
282
+ # failing halves exit 1 inline). This replaces the blind-review MINOR-1
283
+ # single-variable guard: with explicit sub-statuses a Java PASS no longer
284
+ # "resurrects" a TS SKIP -- each half keeps its own record and the gate
285
+ # reflects the union of what was actually verified.
286
+ GATE_9_STATUS="SKIP"
287
+ if [ "$GATE_9_TS_STATUS" = "PASS" ] || [ "$GATE_9_JAVA_STATUS" = "PASS" ]; then
288
+ GATE_9_STATUS="PASS"
289
+ fi
290
+ if [ "$GATE_9_TS_STATUS" = "BLOCK" ] || [ "$GATE_9_JAVA_STATUS" = "BLOCK" ]; then
291
+ GATE_9_STATUS="BLOCK"
292
+ fi
293
+
294
+ GATE_9_END=$(gate_start_ms)
295
+ GATE_9_DURATION_MS=$((GATE_9_END - GATE_9_START))
296
+ GATE_9_DURATION=$((GATE_9_DURATION_MS / 1000))
297
+ echo "✅ Gate 9 completed in ${GATE_9_DURATION}s"
298
+ record_gate_audit "gate-9" "build-integrity" "$GATE_9_STATUS" "0" "$GATE_9_START"
299
+ echo ""
300
+ # ============================================================================
301
+ return 0
302
+ }
303
+
304
+
305
+
306
+ # Called by pre-commit's ordered driver.
307
+
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # PROJECT_SUBDIR restore — extracted from pre-commit by scripts/extract-gates.cjs
4
+ #
5
+ # The hook does `cd "$PROJECT_SUBDIR"` before Gate 0 for single-language
6
+ # projects and must `cd` back once the gates that need the subdirectory are
7
+ # done. This block used to live inside Gate 8's region only because Gate 8
8
+ # was the last such gate in the file; once the order is a list, that
9
+ # correspondence is gone. The driver sources this file right after the LAST
10
+ # gate in GATE_ORDER that is a SUBDIR_GATE, which is derived, not hardcoded.
11
+ # ============================================================================
12
+
13
+ # Gate body. `return` is used instead of `exit` so the driver decides to
14
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
15
+ # here, and why sub-shell exits are deliberately left as `exit`.
16
+ xp_gate_subdir_restore() {
17
+ # Switch back to original directory if we were in a subdirectory
18
+ if [ -n "$ORIGINAL_DIR" ]; then
19
+ cd "$ORIGINAL_DIR"
20
+ fi
21
+ return 0
22
+ }
23
+
24
+
25
+
26
+ # Sourced by pre-commit's ordered driver after the last subdir gate.
27
+
@@ -47,22 +47,58 @@
47
47
  # look up by name — which is how #717's wrong-file patch happened.
48
48
  # ============================================================================
49
49
 
50
- # name|number|impl|blocks
50
+ # name|number|impl|blocks|hook
51
+ #
52
+ # The `hook` field is LAST so a 4-field reader (any consumer installed from an
53
+ # older package) keeps working: appending a field does not move the ones it
54
+ # already reads.
55
+ #
56
+ # Numbers are POSITIONAL LABELS, never identities, and nothing here orders them
57
+ # numerically — pre-push numbers are strings (M, M2, ML, UI, MW, S). Do not add
58
+ # `-gt`/`-lt`/`$((` logic against this field;
59
+ # scripts/__tests__/gate-identity-cross-surface.test.cjs greps for it.
60
+ #
61
+ # `impl` names the file that DECIDES the gate. Where a gate is an inline block
62
+ # plus a helper that renders the verdict, name the helper: `impl` answers "which
63
+ # file do I edit to change this gate", and `inline` answered that wrongly for
64
+ # gate 6 (#715) — the layer verdict comes from gate-6-layers.sh.
51
65
  GATE_REGISTRY_ROWS=(
52
- "version-consistency|0|inline|YES"
53
- "code-quality|1|inline|YES"
54
- "duplicate-code|2|inline|NO"
55
- "complexity|3|gate-3.sh|YES"
56
- "principles|4|gate-4.sh|YES"
57
- "tests-coverage|5|inline|YES"
58
- "architecture|6|inline|YES"
59
- "iac-security|7|gate-7.sh|YES"
60
- "secret-scanning|8|gate-8.sh|YES"
61
- "build-integrity|9|inline|YES"
62
- "sast|10|gate-10.sh|YES"
63
- "sprint-flow|11|sprint-gate.sh|YES"
64
- "file-hygiene|12|gate-12-file-hygiene.sh|NO"
65
- "compiler-strictness|13|gate-13-compiler-strictness.sh|YES"
66
+ "version-consistency|0|inline|YES|pre-commit"
67
+ "code-quality|1|inline|YES|pre-commit"
68
+ "duplicate-code|2|inline|NO|pre-commit"
69
+ "complexity|3|gate-3.sh|YES|pre-commit"
70
+ "principles|4|gate-4.sh|YES|pre-commit"
71
+ "tests-coverage|5|inline|YES|pre-commit"
72
+ "architecture|6|gate-6-layers.sh|YES|pre-commit"
73
+ "iac-security|7|gate-7.sh|YES|pre-commit"
74
+ "secret-scanning|8|gate-8.sh|YES|pre-commit"
75
+ "build-integrity|9|inline|YES|pre-commit"
76
+ "sast|10|gate-10.sh|YES|pre-commit"
77
+ "sprint-flow|11|sprint-gate.sh|YES|pre-commit"
78
+ "file-hygiene|12|gate-12-file-hygiene.sh|NO|pre-commit"
79
+ "compiler-strictness|13|gate-13-compiler-strictness.sh|YES|pre-commit"
80
+ # pre-push. Registering these is identity bookkeeping only — pre-push keeps
81
+ # deciding its own execution order and skip semantics. Before this the
82
+ # registry knew nothing about half the gates this project runs (#769).
83
+ "mutation|M|inline|YES|pre-push"
84
+ "mock-density|M2|inline|NO|pre-push"
85
+ "mock-layering|ML|inline|YES|pre-push"
86
+ "ui-sprint|UI|inline|YES|pre-push"
87
+ "code-walkthrough|MW|inline|YES|pre-push"
88
+ "prepush-sprint|S|sprint-gate.sh|YES|pre-push"
89
+ )
90
+
91
+ # Report-key overrides for rows whose historical artifact key is not derivable
92
+ # as gate{number}_{name}. ONE entry today. Kept beside the rows so a second
93
+ # mapping cannot appear next to the comparison logic where it would be invisible.
94
+ # Compare on NAME, never on these keys: an override must not excuse a mismatch.
95
+ #
96
+ # Not read by any shell code here -- it exists for the Node reader in
97
+ # src/npm-package/lib/gate-identity.js, which parses this block directly. Some
98
+ # shells do not inherit unexported array variables across a `source`, so it is
99
+ # exported rather than left dangling (which also keeps shellcheck honest).
100
+ export GATE_REPORT_KEY_OVERRIDES=(
101
+ "code-quality|gate1_static_analysis"
66
102
  )
67
103
 
68
104
  # Human-readable title for each name. Kept separate from the row above so the
@@ -51,3 +51,76 @@ HOOK_GATE_TIERS=(
51
51
  'gate_project|PROJECT_GITHOOKS|'
52
52
  'gate_script_dir|SCRIPT_DIR|'
53
53
  )
54
+
55
+ # ── Contract (schema 2) ──────────────────────────────
56
+ # Consumed by the sourcing parent, not here.
57
+ # shellcheck disable=SC2034
58
+ HOOK_RESOLUTION_SCHEMA=2
59
+
60
+ # Resolve the directory for one tier of HOOK_ADAPTER_DIR_TIERS.
61
+ #
62
+ # _hook_tier_dir <tier_id> <base_var>
63
+ # tier_id project | global | script (see HOOK_ADAPTER_DIR_TIERS)
64
+ # base_var name of the variable holding that tier's root, e.g.
65
+ # PROJECT_GITHOOKS. Passed by NAME so the caller's scope decides
66
+ # the value — this function never guesses.
67
+ #
68
+ # Prints the resolved directory on stdout, or nothing when the tier is not
69
+ # declared. Callers must treat empty output as "this tier is unavailable",
70
+ # never as "use the current directory".
71
+ #
72
+ # shellcheck disable=SC2154,SC2086,SC2295
73
+ _hook_tier_dir() {
74
+ local _tier_id="$1"
75
+ local _base_var="$2"
76
+ local _entry _entry_tier _entry_base _base_value
77
+
78
+ [ -n "$_tier_id" ] && [ -n "$_base_var" ] || return 0
79
+
80
+ for _entry in "${HOOK_ADAPTER_DIR_TIERS[@]}"; do
81
+ _entry_tier="${_entry%%|*}"
82
+ [ "$_entry_tier" = "$_tier_id" ] || continue
83
+ # "tier_id|base_var|probe_file" -> take the base_var field
84
+ _entry_base="${_entry#*|}"
85
+ _entry_base="${_entry_base%%|*}"
86
+ [ "$_entry_base" = "$_base_var" ] || continue
87
+ # Shape check before eval. Table membership already makes injection
88
+ # impossible TODAY, but that argument lives in a comment a future caller
89
+ # will not read. This makes it a property of the code: $_base_var must be
90
+ # a plain shell identifier, so nothing can reach eval that could execute.
91
+ case "$_base_var" in
92
+ *[!A-Za-z0-9_]*|"") return 0 ;;
93
+ esac
94
+ # Indirect expansion: the caller owns the variable, we only read it.
95
+ eval "_base_value=\${$_base_var:-}"
96
+ [ -n "$_base_value" ] || return 0
97
+ printf '%s\n' "$_base_value"
98
+ return 0
99
+ done
100
+ return 0
101
+ }
102
+
103
+ # Load-time contract check. A projection whose syntax is valid and whose
104
+ # function exists, but whose behaviour does not match what consumers call,
105
+ # would otherwise blow up mid-push at whichever call site runs first —
106
+ # indistinguishable, in a passing suite, from a file that is fine.
107
+ # Failing here turns it into a deterministic SKIP at source time.
108
+ # Consumed by the sourcing parent, not here.
109
+ # shellcheck disable=SC2034
110
+ _HOOK_RESOLVE_BROKEN=""
111
+ _hook_tier_dir_selfcheck() {
112
+ local _probe_out
113
+ if ! declare -F _hook_tier_dir >/dev/null 2>&1; then
114
+ _HOOK_RESOLVE_BROKEN="missing _hook_tier_dir"
115
+ return 1
116
+ fi
117
+ # Smoke call against a known input; the resolver takes the base by name,
118
+ # so overriding PROJECT_GITHOOKS for one command proves the indirection.
119
+ _probe_out="$(PROJECT_GITHOOKS="/__selfcheck__" _hook_tier_dir project PROJECT_GITHOOKS 2>/dev/null)"
120
+ if [ "$_probe_out" != "/__selfcheck__" ]; then
121
+ _HOOK_RESOLVE_BROKEN="selfcheck failed: tier_dir(project,PROJECT_GITHOOKS)=[${_probe_out}]"
122
+ return 1
123
+ fi
124
+ return 0
125
+ }
126
+ _hook_tier_dir_selfcheck || :