@boyingliu01/xp-gate 0.37.2 → 0.38.0

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 (118) 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/common-process.ts +36 -7
  16. package/gates/gate-9.ts +17 -8
  17. package/gates/python-health.ts +215 -24
  18. package/hooks/adapter-common.sh +12 -2
  19. package/hooks/deploy-manifest.sh +100 -0
  20. package/hooks/gate-10.sh +99 -26
  21. package/hooks/gate-12-file-hygiene.sh +13 -1
  22. package/hooks/gate-driver.sh +120 -0
  23. package/hooks/gate-entries/gate-0-entry.sh +825 -0
  24. package/hooks/gate-entries/gate-1-entry.sh +767 -0
  25. package/hooks/gate-entries/gate-10-entry.sh +52 -0
  26. package/hooks/gate-entries/gate-11-entry.sh +120 -0
  27. package/hooks/gate-entries/gate-12-entry.sh +44 -0
  28. package/hooks/gate-entries/gate-12b-entry.sh +178 -0
  29. package/hooks/gate-entries/gate-12c-entry.sh +80 -0
  30. package/hooks/gate-entries/gate-13-entry.sh +584 -0
  31. package/hooks/gate-entries/gate-2-entry.sh +199 -0
  32. package/hooks/gate-entries/gate-3-entry.sh +53 -0
  33. package/hooks/gate-entries/gate-4-entry.sh +46 -0
  34. package/hooks/gate-entries/gate-5-entry.sh +1729 -0
  35. package/hooks/gate-entries/gate-6-entry.sh +658 -0
  36. package/hooks/gate-entries/gate-7-entry.sh +41 -0
  37. package/hooks/gate-entries/gate-8-entry.sh +33 -0
  38. package/hooks/gate-entries/gate-9-entry.sh +307 -0
  39. package/hooks/gate-entries/subdir-restore.sh +27 -0
  40. package/hooks/gate-registry.sh +51 -15
  41. package/hooks/hook-module-resolution.sh +73 -0
  42. package/hooks/install.sh +135 -0
  43. package/hooks/lib/now-ms.sh +55 -19
  44. package/hooks/lib/toolchain-path.sh +50 -6
  45. package/hooks/pre-commit +256 -5091
  46. package/hooks/pre-push +212 -25
  47. package/lib/__tests__/arch-config-template.test.js +190 -0
  48. package/lib/__tests__/baseline-shell-scope.test.js +60 -0
  49. package/lib/__tests__/crap-cli.test.js +14 -3
  50. package/lib/__tests__/deploy-manifest-check-wired.test.js +138 -0
  51. package/lib/__tests__/deploy-manifest-completeness.test.js +151 -0
  52. package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +40 -0
  53. package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +74 -0
  54. package/lib/__tests__/deploy-manifest-projection.test.js +66 -0
  55. package/lib/__tests__/deploy-manifest-shell-parity.test.js +108 -0
  56. package/lib/__tests__/deploy-manifest.test.js +97 -0
  57. package/lib/__tests__/doctor.test.js +51 -7
  58. package/lib/__tests__/gate-coverage.test.js +79 -12
  59. package/lib/__tests__/gate-numbering.test.js +28 -1
  60. package/lib/__tests__/install-sh-deploy-manifest.test.js +80 -0
  61. package/lib/__tests__/mirror-sync.test.js +45 -3
  62. package/lib/__tests__/npm-package.test.js +10 -7
  63. package/lib/__tests__/sastd-client.test.js +452 -0
  64. package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +69 -0
  65. package/lib/__tests__/sprint-status-rework.test.js +1 -0
  66. package/lib/arch-config-template.js +87 -0
  67. package/lib/baseline.js +54 -2
  68. package/lib/deploy-manifest.js +174 -0
  69. package/lib/doctor.js +46 -14
  70. package/lib/gate-capability.js +291 -0
  71. package/lib/gate-coverage.js +194 -74
  72. package/lib/gate-identity.js +349 -0
  73. package/lib/gate-runner.js +11 -1
  74. package/lib/hook-module-resolution.js +27 -0
  75. package/lib/init.js +72 -5
  76. package/lib/mattpocock-license-verdict.json +1 -1
  77. package/lib/sastd-client.js +534 -0
  78. package/lib/shared-utils.js +31 -9
  79. package/lib/uninstall.js +10 -7
  80. package/lib/update-hooks.js +27 -18
  81. package/mock-policy/AGENTS.md +1 -1
  82. package/mutation/AGENTS.md +1 -1
  83. package/package.json +3 -1
  84. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  85. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  86. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  87. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +2 -2
  88. package/plugins/dsh/package.json +1 -1
  89. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  90. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  91. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +2 -2
  92. package/plugins/opencode/package.json +1 -1
  93. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  94. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  95. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +2 -2
  96. package/plugins/qoder/plugin.json +1 -1
  97. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  98. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  99. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +2 -2
  100. package/principles/AGENTS.md +1 -1
  101. package/principles/__tests__/analyzer.test.ts +2 -1
  102. package/principles/__tests__/config-enforcement.test.ts +1 -0
  103. package/principles/__tests__/types.test.ts +1 -0
  104. package/principles/adapters/base.ts +14 -1
  105. package/principles/adapters/duplication.ts +134 -0
  106. package/principles/rules/__tests__/clean-code/large-file.test.ts +2 -1
  107. package/principles/rules/clean-code/code-duplication.ts +75 -9
  108. package/principles/types.ts +39 -0
  109. package/scripts/__tests__/check-mattpocock-license.test.js +36 -3
  110. package/scripts/__tests__/sync-package-content.test.js +12 -2
  111. package/scripts/generate-mirrors.cjs +125 -0
  112. package/scripts/sync-package-content.js +64 -20
  113. package/skills/delphi-review/AGENTS.md +1 -1
  114. package/skills/sprint-flow/AGENTS.md +1 -1
  115. package/skills/test-specification-alignment/AGENTS.md +2 -2
  116. package/adapters/gate-9.sh +0 -245
  117. package/gate-9.sh +0 -245
  118. package/hooks/gate-9.sh +0 -245
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # Ordered gate driver (#798)
4
+ #
5
+ # WHY THIS FILE EXISTS
6
+ # The gate order used to BE the physical order of 16 inline blocks inside
7
+ # pre-commit. Reordering meant moving thousands of lines between blocks, and
8
+ # the first attempt at doing that moved the hook's epilogue along with the
9
+ # last gate: every gate after it silently stopped running while `bash -n`,
10
+ # a line count check and five ordering assertions all passed. Gate 5a stopped
11
+ # blocking commits and only a behavioural fingerprint caught it.
12
+ #
13
+ # Order is now data. Each gate body lives in githooks/gate-entries/ and is
14
+ # called by name from XP_GATE_ORDER below. Moving a gate is a one-line edit
15
+ # that cannot detach its body from its position.
16
+ #
17
+ # CONTRACT FOR ENTRY FILES
18
+ # gate_NN_run() returns 0 to let the commit continue and non-zero to stop it.
19
+ # It never calls `exit`: the driver owns that decision, so the EXIT trap that
20
+ # writes the quality report keeps firing on the gate's status (see
21
+ # scripts/wrap-gate-entries.cjs for why return/exit are equivalent here).
22
+ # ============================================================================
23
+
24
+ # Gate execution order. THIS LIST IS THE ORDER OF THE PRE-COMMIT CHAIN.
25
+ #
26
+ # Ordered by cost, cheapest-rejecting first (#798). A gate that rejects a
27
+ # commit should do so before the expensive ones spend their time:
28
+ #
29
+ # 1. Compile Gate 13 (compiler), Gate 9 (build integrity)
30
+ # The compiler is the cheapest and strictest analysis any
31
+ # compiled language has, and nothing downstream is meaningful
32
+ # if it fails.
33
+ # 2. StaticCheck Gate 1 (linters / third-party static analysis)
34
+ # 3. SimianCheck Gate 2 (duplicate code)
35
+ # 4. CCNCheck Gate 3 (cyclomatic complexity)
36
+ # 5. Security Gate 8 (secrets), Gate 10 (SAST), Gate 7 (IaC)
37
+ # 6. RegressiveTest Gate 5 (test run + coverage) - the most expensive gate,
38
+ # so it runs LAST among the checks.
39
+ # tail Gate 6 (architecture), Gate 4 (principles)
40
+ #
41
+ # The prelude (0, 11, 12/12b/12c) runs first because it is cheap and decides
42
+ # whether the commit is even a candidate (version consistency, sprint state,
43
+ # file hygiene/conflict markers).
44
+ XP_GATE_ORDER="0 11 12 12b 12c 13 9 1 2 3 8 10 7 5 6 4"
45
+
46
+ # Gates that expect to run inside $PROJECT_SUBDIR. The `cd` back to the original
47
+ # directory is emitted after the LAST of these in the order above; deriving it
48
+ # (instead of leaving the restore inside gate 8's block) is what makes the
49
+ # restore survive a reorder.
50
+ XP_GATE_SUBDIR_GATES="${XP_GATE_SUBDIR_GATES:-0 11 12 12b 12c 13 9 1 2 3 8}"
51
+
52
+ # Source every gate body once, before the chain runs. Sourcing defines the
53
+ # gate_NN_run functions; it does not execute them.
54
+ _xp_gate_load_entries() {
55
+ local entry_dir="$1" key fname
56
+ for key in $XP_GATE_ORDER; do
57
+ fname="$entry_dir/gate-${key}-entry.sh"
58
+ if [ ! -f "$fname" ]; then
59
+ echo "❌ FATAL: gate entry missing: $fname" >&2
60
+ echo " The order lists gate '$key' but its body file is absent." >&2
61
+ echo " Fix: reinstall the hooks (xp-gate doctor --sync-hooks)." >&2
62
+ return 1
63
+ fi
64
+ # shellcheck source=/dev/null
65
+ . "$fname" || {
66
+ echo "❌ FATAL: gate entry failed to load: $fname" >&2
67
+ return 1
68
+ }
69
+ done
70
+ return 0
71
+ }
72
+
73
+ # Run the ordered chain.
74
+ #
75
+ # A gate that returns non-zero stops the commit. The driver exits with that
76
+ # status rather than returning it: only a real `exit` fires pre-commit's EXIT
77
+ # trap, and that trap is what writes the quality report for a blocked commit.
78
+ _xp_gate_run_chain() {
79
+ local key fn rc
80
+ local last_subdir=""
81
+
82
+ # Derive which gate is the LAST one expecting $PROJECT_SUBDIR, so the restore
83
+ # is emitted at the right point regardless of how the order is edited.
84
+ for key in $XP_GATE_ORDER; do
85
+ case " $XP_GATE_SUBDIR_GATES " in
86
+ *" $key "*) last_subdir="$key" ;;
87
+ esac
88
+ done
89
+
90
+ for key in $XP_GATE_ORDER; do
91
+ fn="gate_${key}_run"
92
+
93
+ if ! declare -F "$fn" >/dev/null 2>&1; then
94
+ echo "❌ FATAL: gate '$key' was loaded but defines no $fn()" >&2
95
+ echo " The entry file exists but its function signature does not match" >&2
96
+ echo " its order key. This gate did NOT run." >&2
97
+ exit 1
98
+ fi
99
+
100
+ "$fn"
101
+ rc=$?
102
+ if [ "$rc" -ne 0 ]; then
103
+ exit "$rc"
104
+ fi
105
+
106
+ if [ "$key" = "$last_subdir" ]; then
107
+ # Resolve beside THIS file, not via $GATE_DIR: pre-commit's preamble points
108
+ # GATE_DIR at ADAPTER_DIR for adapter lookup, so it does not name the
109
+ # directory the gate bodies live in.
110
+ local _chain_dir
111
+ _chain_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
112
+ if [ -f "$_chain_dir/gate-entries/subdir-restore.sh" ]; then
113
+ # shellcheck source=/dev/null
114
+ . "$_chain_dir/gate-entries/subdir-restore.sh"
115
+ xp_gate_subdir_restore
116
+ fi
117
+ fi
118
+ done
119
+ return 0
120
+ }