@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,52 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-10 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 10: Semgrep SAST Security Scan
22
+ # Extracted to gate-10.sh for maintainability
23
+ # v0.14.3+ (Issue #312): Skip if no code files changed
24
+ # v0.18.5 (Issue #397): Fix gate status variable collision — SAST now sets GATE_10_STATUS
25
+ # ============================================================================
26
+ # Gate body. `return` is used instead of `exit` so the driver decides to
27
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
28
+ # here, and why sub-shell exits are deliberately left as `exit`.
29
+ gate_10_run() {
30
+ if any_changed_files_match "\.(ts|tsx|js|jsx|py|go|java|kt|cpp|c|swift|m|dart|sh|ps1|psm1|cs|csx|fs|vb|rs|php|rb|lua|pl)$"; then
31
+ if [ -f "$GATE_DIR/gate-10.sh" ]; then
32
+ source "$GATE_DIR/gate-10.sh"
33
+ else
34
+ echo "⏭️ SKIPPED - SAST (gate-10.sh not found)"
35
+ GATE_10_STATUS="SKIP"
36
+ GATE_10_REASON="gate_script_missing"
37
+ fi
38
+ else
39
+ echo "⏭️ SKIPPED - No code files changed, skipping SAST scan."
40
+ # #536: "nothing to scan" is NOT "scanned and clean". Record SKIP with a
41
+ # reason so the quality report never renders this path as a PASS claim.
42
+ GATE_10_STATUS="SKIP"
43
+ GATE_10_REASON="no_code_files_changed"
44
+ fi
45
+ # ============================================================================
46
+ return 0
47
+ }
48
+
49
+
50
+
51
+ # Called by pre-commit's ordered driver.
52
+
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-11 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 11: Sprint Flow Enforcement
22
+ # Validates sprint state consistency (delphi-review APPROVED before BUILD)
23
+ # Uses sprint-gate.sh for standalone validation logic
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_11_run() {
29
+ GATE_11_START=$(gate_start_ms)
30
+ GATE_11_STATUS="PASS"
31
+
32
+ # BEGIN SPRINT_GATE_SCRIPT RESOLUTION
33
+ # Every tier is a *directory*; the resolver returns the first one that actually holds
34
+ # sprint-gate.sh. The chain used to stop at the gate-script directories, but the flat
35
+ # global layout ($GATE_DIR -> ~/.config/xp-gate/adapters) carries gate-3/4/7/8/9/10.sh
36
+ # and never this script: update-hooks installs sprint-gate.sh under
37
+ # ~/.config/xp-gate/hooks, which nothing probed, so a correctly installed machine was
38
+ # told the file was missing (#476).
39
+ SPRINT_GATE_CANDIDATES=(
40
+ "$GATE_DIR"
41
+ "$(git rev-parse --show-toplevel 2>/dev/null)/githooks"
42
+ "$SCRIPT_DIR"
43
+ "$HOME/.config/xp-gate/hooks"
44
+ )
45
+ SPRINT_GATE_SCRIPT=$(resolve_sprint_gate_script ${SPRINT_GATE_CANDIDATES[@]+"${SPRINT_GATE_CANDIDATES[@]}"})
46
+ # END SPRINT_GATE_SCRIPT RESOLUTION
47
+
48
+ echo "→ Gate 11: Sprint Flow Enforcement..."
49
+
50
+ if [ -n "$SPRINT_GATE_SCRIPT" ]; then
51
+ # The decision JSON was piped straight to the terminal with no heading, so it landed
52
+ # under Gate 10's banner and a legitimate "skip: not a sprint project" looked like a
53
+ # bare machine object. The exit status stays the authority for blocking; the JSON only
54
+ # decides which words the user reads.
55
+ SPRINT_GATE_EXIT=0
56
+ SPRINT_GATE_OUTPUT=$(bash "$SPRINT_GATE_SCRIPT" --pre-commit 2>&1) || SPRINT_GATE_EXIT=$?
57
+ SPRINT_GATE_DECISION=$(sprint_gate_decision "$SPRINT_GATE_OUTPUT")
58
+ SPRINT_GATE_DETAIL=$(sprint_gate_detail "$SPRINT_GATE_OUTPUT")
59
+
60
+ if [ "$SPRINT_GATE_EXIT" -ne 0 ]; then
61
+ GATE_11_STATUS="BLOCK"
62
+ echo "❌ BLOCKED - Gate 11: Sprint Flow (${SPRINT_GATE_DETAIL:-sprint gate denied})"
63
+ printf '%s\n' "$SPRINT_GATE_OUTPUT" | sed 's/^/ /'
64
+ record_gate_audit "gate-11" "sprint-flow" "$GATE_11_STATUS" "1" "$GATE_11_START"
65
+ # Sprint gate failure is a hard block — exit immediately
66
+ return 1
67
+ fi
68
+
69
+ case "$SPRINT_GATE_DECISION" in
70
+ skip)
71
+ echo "⏭️ SKIPPED - Gate 11: Sprint Flow (${SPRINT_GATE_DETAIL:-no reason given})"
72
+ GATE_11_STATUS="SKIP"
73
+ ;;
74
+ allow)
75
+ # #584: `allow` covered three different outcomes and all of them became
76
+ # PASS, so a sprint that was never examined raised PASSED_COUNT and the
77
+ # score. Only a genuinely validated sprint certifies this gate; the rest
78
+ # declined to evaluate and must read as SKIP with the real reason shown.
79
+ SPRINT_GATE_ALLOW_REASON=$(sprint_gate_allow_reason "$SPRINT_GATE_OUTPUT")
80
+ if [ "$SPRINT_GATE_ALLOW_REASON" = "checks-passed" ]; then
81
+ echo "✅ PASSED - Gate 11: Sprint Flow (${SPRINT_GATE_DETAIL:-sprint state validated})"
82
+ else
83
+ echo "⏭️ SKIPPED - Gate 11: Sprint Flow (${SPRINT_GATE_ALLOW_REASON}: ${SPRINT_GATE_DETAIL:-not evaluated})"
84
+ GATE_11_STATUS="SKIP"
85
+ fi
86
+ ;;
87
+ *)
88
+ # A run that succeeded but said nothing this gate understands. Pass on the exit
89
+ # status, but keep the raw output visible rather than inventing a verdict.
90
+ echo "✅ PASSED - Gate 11: Sprint Flow (no recognisable decision in the gate output)"
91
+ printf '%s\n' "$SPRINT_GATE_OUTPUT" | sed 's/^/ /'
92
+ ;;
93
+ esac
94
+ else
95
+ echo "⏭️ SKIPPED - Gate 11: Sprint Flow (sprint-gate.sh not found; searched: $(IFS=', '; printf '%s' "${SPRINT_GATE_CANDIDATES[*]}"))"
96
+ GATE_11_STATUS="SKIP"
97
+ fi
98
+
99
+ # Issue #524: pair the units. gate_start_ms is epoch MILLISECONDS (#370 helper);
100
+ # the old `date +%s` end was epoch SECONDS, so the subtraction printed about
101
+ # -1.79e12 s and poisoned .xp-gate/reports/pre-commit/*.json. now_ms is the same
102
+ # helper gate_start_ms delegates to; display divides by 1000.
103
+ GATE_11_END=$(now_ms)
104
+ GATE_11_DURATION_MS=$((GATE_11_END - GATE_11_START))
105
+ if [ "$GATE_11_DURATION_MS" -lt 0 ] 2>/dev/null; then
106
+ # Clock skew or a poisoned timestamp must not print a negative runtime.
107
+ GATE_11_DURATION_MS=0
108
+ fi
109
+ GATE_11_DURATION=$((GATE_11_DURATION_MS / 1000))
110
+ echo " Gate 11 ($GATE_11_STATUS) completed in ${GATE_11_DURATION}s"
111
+ record_gate_audit "gate-11" "sprint-flow" "$GATE_11_STATUS" "0" "$GATE_11_START"
112
+ echo ""
113
+ # ============================================================================
114
+ return 0
115
+ }
116
+
117
+
118
+
119
+ # Called by pre-commit's ordered driver.
120
+
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-12 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 12: File Hygiene Check
22
+ # Detects trailing whitespace, missing EOF newlines, merge conflict markers,
23
+ # and oversized files in staged changes.
24
+ # v0.14.15+ (Issue #350, #351)
25
+ # ============================================================================
26
+ # Gate body. `return` is used instead of `exit` so the driver decides to
27
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
28
+ # here, and why sub-shell exits are deliberately left as `exit`.
29
+ gate_12_run() {
30
+ if [ -f "$GATE_DIR/gate-12-file-hygiene.sh" ]; then
31
+ source "$GATE_DIR/gate-12-file-hygiene.sh"
32
+ elif [ -f "$(git rev-parse --show-toplevel 2>/dev/null)/githooks/gate-12-file-hygiene.sh" ]; then
33
+ source "$(git rev-parse --show-toplevel)/githooks/gate-12-file-hygiene.sh"
34
+ else
35
+ echo "⏭️ SKIPPED - Gate 12: File Hygiene (gate-12-file-hygiene.sh not found)"
36
+ fi
37
+ # ============================================================================
38
+ return 0
39
+ }
40
+
41
+
42
+
43
+ # Called by pre-commit's ordered driver.
44
+
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-12b 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 12b: Mirror Parity (#654)
22
+ #
23
+ # `githooks/**` and `plugins/*/src/**` are canonical; `src/npm-package/**` holds
24
+ # byte-identical mirrors that get published. Editing only the mirror means the next
25
+ # prepack silently regenerates it over the change -- v0.27.3 shipped exactly that
26
+ # bug, and mirror/sync rework accounts for 58 failures in the session logs.
27
+ #
28
+ # The check used to run only at pre-push, which turns a two-second fix into a
29
+ # five-minute wait. It runs here now, but ONLY over files in this commit: a
30
+ # full-tree scan on every commit is the cost that pushed it to pre-push in the
31
+ # first place.
32
+ # ============================================================================
33
+ # Gate body. `return` is used instead of `exit` so the driver decides to
34
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
35
+ # here, and why sub-shell exits are deliberately left as `exit`.
36
+ gate_12b_run() {
37
+ MIRROR_STAGED=$(git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true)
38
+ # `src/npm-package/` is in this filter because a mirror-only edit is the
39
+ # dangerous direction, not the harmless one. Keying off the canonical paths
40
+ # alone meant staging just the mirror skipped the whole block, so a fix written
41
+ # into the published copy could be committed while its source stayed wrong --
42
+ # v0.27.3 shipped exactly that (#542). The reverse mapping below resolves each
43
+ # staged mirror back to its canonical file and compares the pair either way.
44
+ if [ -n "$MIRROR_STAGED" ] && printf '%s
45
+ ' "$MIRROR_STAGED" | grep -qE '^(githooks/|plugins/[^/]+/src/|src/npm-package/(adapters|hooks|principles|build-integrity)/)'; then
46
+ # Reuse PROJECT_ROOT: `git rev-parse` costs ~90ms per fork on Windows and this
47
+ # gate must not add two of them to every commit (#640).
48
+ MIRROR_REPO_ROOT="${PROJECT_ROOT:-}"
49
+ if [ -n "$MIRROR_REPO_ROOT" ] && [ -f "$MIRROR_REPO_ROOT/scripts/check-hook-mirror.sh" ]; then
50
+ # Scope to the touched families only: a mirror pair is clean or dirty
51
+ # independently, and checking untouched families is the slow path this gate
52
+ # exists to avoid.
53
+ MIRROR_FAIL=0
54
+ while IFS= read -r _mf; do
55
+ [ -n "$_mf" ] || continue
56
+ # `__tests__/` has no mirror BY DESIGN: sync-package-content.js lists it in
57
+ # SKIP_DIRS so test suites never ship to consumers. Demanding a mirror for
58
+ # them makes every new BATS file un-committable -- the two rules contradicted
59
+ # each other, and the only way past was to edit a generated file by hand.
60
+ case "$_mf" in
61
+ */__tests__/*) continue ;;
62
+ # AGENTS.md is documentation, not a hook artifact: sync-package-content.js
63
+ # copies the hook suite, and no AGENTS.md exists under hooks/. Demanding a
64
+ # mirror for it reported a BLOCK on every doc edit (harmless only because
65
+ # GATE_FAILED was never read -- see below).
66
+ */AGENTS.md) continue ;;
67
+ # `githooks/adapters/` mirrors to `src/npm-package/adapters/`, NOT under
68
+ # `hooks/` -- that is what scripts/check-hook-mirror.sh declares (line 6)
69
+ # and what sync-package-content.js writes. The blanket `githooks/*` rule
70
+ # below sent it to `src/npm-package/hooks/adapters/<f>`, a path that has
71
+ # never existed, so ANY edit to an adapter was un-committable with
72
+ # "has no mirror at". It stayed hidden because nobody had edited an
73
+ # adapter since this gate was narrowed to diff files.
74
+ githooks/adapters/*) _mm="src/npm-package/adapters/${_mf#githooks/adapters/}" ;;
75
+ githooks/*) _mm="src/npm-package/hooks/${_mf#githooks/}" ;;
76
+ plugins/*/src/*) _mm=$(printf '%s' "$_mf" | sed 's|^plugins/\([^/]*\)/src/|src/npm-package/plugins/\1/src/|') ;;
77
+ # Reverse direction: the staged file IS the mirror. Resolve it back to
78
+ # the canonical file and let the same comparison below decide. Without
79
+ # this arm the widened filter above matches nothing and the gate stays
80
+ # blind to a mirror-only edit -- the v0.27.3 shape (#542).
81
+ src/npm-package/adapters/*) _mf="githooks/adapters/${_mf#src/npm-package/adapters/}"; _mm="src/npm-package/adapters/${_mf#githooks/adapters/}" ;;
82
+ src/npm-package/hooks/lib/*) _mf="githooks/lib/${_mf#src/npm-package/hooks/lib/}"; _mm="src/npm-package/hooks/lib/${_mf#githooks/lib/}" ;;
83
+ src/npm-package/hooks/*) _mf="githooks/${_mf#src/npm-package/hooks/}"; _mm="src/npm-package/hooks/${_mf#githooks/}" ;;
84
+ src/npm-package/principles/*) _mf="src/principles/${_mf#src/npm-package/principles/}"; _mm="src/npm-package/principles/${_mf#src/principles/}" ;;
85
+ src/npm-package/build-integrity/*) _mf="src/build-integrity/${_mf#src/npm-package/build-integrity/}"; _mm="src/npm-package/build-integrity/${_mf#src/build-integrity/}" ;;
86
+ *) continue ;;
87
+ esac
88
+ if [ ! -f "$MIRROR_REPO_ROOT/$_mm" ]; then
89
+ echo "❌ BLOCKED - Gate 12b: $_mf has no mirror at $_mm"
90
+ echo " Run: node src/npm-package/scripts/sync-package-content.js --fix"
91
+ MIRROR_FAIL=$((MIRROR_FAIL + 1))
92
+ elif ! cmp -s "$MIRROR_REPO_ROOT/$_mf" "$MIRROR_REPO_ROOT/$_mm"; then
93
+ echo "❌ BLOCKED - Gate 12b: $_mm differs from canonical $_mf"
94
+ echo " Run: node src/npm-package/scripts/sync-package-content.js --fix"
95
+ MIRROR_FAIL=$((MIRROR_FAIL + 1))
96
+ fi
97
+ done <<< "$MIRROR_STAGED"
98
+ if [ "$MIRROR_FAIL" -gt 0 ]; then
99
+ echo ""
100
+ echo "❌ BLOCKED - Gate 12b: $MIRROR_FAIL mirror parity violation(s)."
101
+ echo " The mirror is what gets published; a mirror-only fix is silently"
102
+ echo " reverted by the next prepack (v0.27.3 shipped that bug)."
103
+ # BLOCKS, and must actually block. This used to set GATE_FAILED=1, a
104
+ # variable that appears exactly once in this file -- the assignment --
105
+ # and is read nowhere, so the gate printed BLOCKED on every doc edit and
106
+ # let the commit through. A gate that reports a verdict nobody consumes is
107
+ # the same failure as a filter that accepts a file no adapter claims:
108
+ # it looks like enforcement. exit is the contract every other blocking
109
+ # gate here uses (see Gate 13: `exit "$_g13_worst"`).
110
+ #
111
+ # No GATE_12_STATUS assignment here: `exit 1` runs immediately after, so
112
+ # the journal/summary writes at the end of the hook never execute and the
113
+ # assignment would be dead -- the same "verdict nobody consumes" defect
114
+ # one line up. Dropped rather than kept as a misleading WARN label
115
+ # (code-walkthrough R2, A2/F1).
116
+ return 1
117
+ else
118
+ echo "✅ PASSED - Gate 12b: mirror parity (touched files)"
119
+ fi
120
+ fi
121
+
122
+ # ---------------------------------------------------------------------------
123
+ # Gate 12b (second half): deploy-manifest projection freshness (REQ-DEPLOY-001).
124
+ #
125
+ # `src/npm-package/lib/deploy-manifest.js` is the single source of truth and
126
+ # `githooks/deploy-manifest.sh` is a GENERATED projection of it (bash cannot
127
+ # require() JS, so the manifest is emitted as shell arrays rather than typed a
128
+ # second time). A generated projection whose generator is never run rots back
129
+ # into the hand-copied lists this whole change set removed -- the 11 lists
130
+ # that had already drifted apart before #789.
131
+ #
132
+ # The check lives HERE, in the gate that already owns "two files that must
133
+ # agree", rather than in a test: a test only runs when someone runs it, and
134
+ # the drift appears at the moment the source is edited, which is a commit.
135
+ #
136
+ # Only run when the source or the projection is in the change set. Unrelated
137
+ # commits must not pay for a node spawn.
138
+ # ---------------------------------------------------------------------------
139
+ if printf '%s\n' "$CHANGED_FILES" | grep -qE '^(src/npm-package/lib/deploy-manifest\.js|githooks/deploy-manifest\.sh|src/npm-package/hooks/deploy-manifest\.sh|scripts/generate-deploy-manifest\.cjs)$'; then
140
+ if [ ! -f "$PROJECT_ROOT/scripts/generate-deploy-manifest.cjs" ]; then
141
+ # The generator is gone. The manifest/projection pair is in this change
142
+ # set, so the projection is demonstrably in play and cannot be verified.
143
+ echo "❌ BLOCKED - Gate 12b: deploy-manifest projection cannot be verified"
144
+ echo " scripts/generate-deploy-manifest.cjs is missing but the manifest or"
145
+ echo " its projection changed in this commit."
146
+ return 1
147
+ elif ! command -v node >/dev/null 2>&1; then
148
+ # node missing while the projection is being edited: degrading this to a
149
+ # notice would hand the silent-pass outcome to exactly the contributor who
150
+ # cannot run the generator -- and hand-editing the projection is the drift
151
+ # this check exists to catch (code-walkthrough R2, F-1).
152
+ echo "❌ BLOCKED - Gate 12b: node is required to verify the deploy-manifest projection"
153
+ echo " The manifest or its projection changed but node is not on PATH."
154
+ echo " Install node, or regenerate on a machine that has it:"
155
+ echo " node scripts/generate-deploy-manifest.cjs && git add githooks/deploy-manifest.sh"
156
+ return 1
157
+ else
158
+ echo "Checking deploy-manifest projection freshness..."
159
+ if _dm_out=$(cd "$PROJECT_ROOT" && node scripts/generate-deploy-manifest.cjs --check 2>&1); then
160
+ echo "✅ PASSED - Gate 12b: deploy-manifest projection is current"
161
+ else
162
+ echo "❌ BLOCKED - Gate 12b: deploy-manifest.sh is STALE vs deploy-manifest.js"
163
+ printf '%s\n' "$_dm_out" | sed 's/^/ /'
164
+ # As above: no GATE_12_STATUS assignment -- `exit 1` means the summary
165
+ # writes never run, so the assignment would be dead (A2/F1).
166
+ echo " Fix: node scripts/generate-deploy-manifest.cjs && git add githooks/deploy-manifest.sh"
167
+ return 1
168
+ fi
169
+ fi
170
+ fi
171
+ fi
172
+ return 0
173
+ }
174
+
175
+
176
+
177
+ # Called by pre-commit's ordered driver.
178
+
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-12c 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 body. `return` is used instead of `exit` so the driver decides to
22
+ # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
23
+ # here, and why sub-shell exits are deliberately left as `exit`.
24
+ gate_12c_run() {
25
+ # Gate 12c: probe discipline
26
+ #
27
+ # A command that could not RUN is not a command that found problems. The hooks
28
+ # used to answer "is this tool installed?" with `npx <tool> --version`, whose
29
+ # contract is "install it if missing, then run it" -- so the probe changed the
30
+ # environment it was asked about. `--no-install` prevents the install and
31
+ # nothing else: it still queries the registry on every call (measured 697 ms
32
+ # cold, 105 ms revalidating) inside a commit, and once an earlier misuse fills
33
+ # the npx cache the same probe starts answering "installed" for a tool the
34
+ # project never depended on.
35
+ #
36
+ # Scoped to commits that touch hook sources: the rule can only be broken by
37
+ # editing one, and scanning 51 files on every docs-only commit is exactly the
38
+ # fixed cost the input short-circuit convention exists to avoid.
39
+ if printf '%s\n' "$STAGED_FILES" 2>/dev/null | grep -qE '^githooks/(adapters/|lib/|adapter-common\.sh|pre-commit|pre-push|post-commit|post-merge)'; then
40
+ _probe_root="${PROJECT_ROOT:-}"
41
+ if [ -n "$_probe_root" ] && [ -f "$_probe_root/scripts/check-no-npx-probe.sh" ]; then
42
+ echo ""
43
+ echo "→ Gate 12c: probe discipline..."
44
+ if (cd "$_probe_root" && bash scripts/check-no-npx-probe.sh); then
45
+ echo "✅ PASSED - Gate 12c: no gate probes tool availability through npx"
46
+ else
47
+ echo ""
48
+ echo "❌ BLOCKED - Gate 12c: a gate answers \"is this tool installed?\" by"
49
+ echo " asking the registry. A probe that installs the tool it was asked"
50
+ echo " about does not measure the environment, it changes it."
51
+ return 1
52
+ fi
53
+ fi
54
+ fi
55
+ # ============================================================================
56
+
57
+ # The compiler is the first and cheapest static analyser for a compiled language
58
+ # and XP-Gate never used it as one: cpp.sh only runs clang-tidy/cppcheck over the
59
+ # first 20 files, and Gate 9's build-integrity half is TypeScript-and-Maven only.
60
+ # A measured `g++ -Wall -Wextra` pass reports -Wnon-virtual-dtor, -Wreorder,
61
+ # -Wparentheses and -Wclass-memaccess on an innocuous-looking file; bare `javac`
62
+ # reports NOTHING for a raw type where `-Xlint:all` reports [rawtypes].
63
+ #
64
+ # Verdicts: 0 PASS, 1 FAIL (new findings -> blocked), 2 BLOCK (ran but output
65
+ # untrustworthy), 3 WARN (tool absent / cross-compiling / timeout / warn-only).
66
+ # A missing compiler is a SKIP-class WARN per the project convention, NOT a block.
67
+ #
68
+ # Escape hatches: XP_GATE_DISABLE_13=1 (kill switch),
69
+ # XP_GATE_COMPILER_STRICTNESS=strict|balanced|warn-only,
70
+ # XP_GATE_COMPILER_ANALYZER=1 (gcc -fanalyzer, C only, opt-in).
71
+ # Design: docs/plans/2026-10-26-gate-13-compiler-strictness-design.md
72
+ #
73
+ # NOTE: this block is a TAIL APPEND after Gate 12 and intentionally touches no
74
+ # line of the gates above it.
75
+ return 0
76
+ }
77
+
78
+
79
+ # Called by pre-commit's ordered driver.
80
+