@boyingliu01/xp-gate 0.37.3 → 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 (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 +452 -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 +534 -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,135 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ HOOKS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+
6
+ # The deploy manifest is a bash array projection generated from
7
+ # src/npm-package/lib/deploy-manifest.js (REQ-DEPLOY-001). Arrays only exist in
8
+ # bash: under POSIX sh they expand to nothing, so the installer would copy zero
9
+ # files and still exit 0. Fail closed before doing anything else.
10
+ if [ -z "${BASH_VERSION:-}" ]; then
11
+ echo "Error: githooks/install.sh must run under bash (the deployment manifest is a bash array)." >&2
12
+ echo " Try: bash githooks/install.sh" >&2
13
+ exit 1
14
+ fi
15
+
16
+ DEPLOY_MANIFEST="$HOOKS_DIR/deploy-manifest.sh"
17
+ if [ ! -f "$DEPLOY_MANIFEST" ]; then
18
+ echo "Error: missing $DEPLOY_MANIFEST" >&2
19
+ echo " Regenerate it with: node scripts/generate-deploy-manifest.cjs" >&2
20
+ exit 1
21
+ fi
22
+ # shellcheck source=/dev/null
23
+ . "$DEPLOY_MANIFEST"
24
+
25
+ if ! git rev-parse --git-dir &>/dev/null; then
26
+ echo "Error: Not a git repository. Must be run from within a project."
27
+ exit 1
28
+ fi
29
+
30
+ GIT_DIR=$(git rev-parse --git-dir)
31
+ GIT_DIR=$(cd "$GIT_DIR" && pwd)
32
+ PROJECT_ROOT=$(git rev-parse --show-toplevel)
33
+
34
+ TARGET_HOOKS="$GIT_DIR/hooks"
35
+ mkdir -p "$TARGET_HOOKS"
36
+ TARGET_GITHOOKS="$PROJECT_ROOT/githooks"
37
+
38
+ echo "Installing OpenCode quality gates..."
39
+ echo ""
40
+
41
+ for hook in "${DEPLOY_HOOK_FILES[@]}"; do
42
+ src="$HOOKS_DIR/$hook"
43
+ if [ -f "$src" ]; then
44
+ cp "$src" "$TARGET_HOOKS/$hook"
45
+ chmod +x "$TARGET_HOOKS/$hook"
46
+ echo " + $hook ($HOOKS_DIR/$hook) -> .git/hooks/"
47
+ fi
48
+ done
49
+
50
+ # #505: hook-module-resolution.sh is GENERATED from
51
+ # src/npm-package/lib/hook-module-resolution.js, so a clean checkout has no copy.
52
+ # pre-commit aborts with "FATAL: cannot load hook-module-resolution.sh" when it is
53
+ # missing -- deliberately, because running without the module resolution order
54
+ # means the hook cannot find its own dependencies. That made a fresh clone
55
+ # unusable until someone knew to run the generator, which is what CI's
56
+ # First Commit Gates job reported.
57
+ #
58
+ # Generate it here when it is absent AND the generator is available (a consumer
59
+ # project installed via `xp-gate init` gets the generated file shipped, not the
60
+ # generator, so the absence of the generator is normal there and not an error).
61
+ if [ ! -f "$HOOKS_DIR/hook-module-resolution.sh" ]; then
62
+ if [ -f "$PROJECT_ROOT/scripts/generate-hook-resolution.cjs" ] && command -v node >/dev/null 2>&1; then
63
+ ( cd "$PROJECT_ROOT" && node scripts/generate-hook-resolution.cjs >/dev/null 2>&1 ) || true
64
+ [ -f "$HOOKS_DIR/hook-module-resolution.sh" ] \
65
+ && echo " + generated hook-module-resolution.sh"
66
+ fi
67
+ fi
68
+
69
+ # Install the gate scripts from the manifest. The old hand-written list named 7
70
+ # of 11 and silently omitted gate-6-layers.sh, gate-12-file-hygiene.sh and
71
+ # gate-registry.sh — gates that then never ran in an installed repo.
72
+ for gate in "${DEPLOY_GATE_FILES[@]}" hook-module-resolution.sh; do
73
+ src="$HOOKS_DIR/$gate"
74
+ if [ -f "$src" ]; then
75
+ cp "$src" "$TARGET_HOOKS/$gate"
76
+ chmod +x "$TARGET_HOOKS/$gate"
77
+ echo " + $gate ($HOOKS_DIR/$gate) -> .git/hooks/"
78
+ fi
79
+ done
80
+
81
+ # Install the non-hook modules (lib/*, adapter-common.sh, deploy-manifest.sh,
82
+ # install.sh) from the manifest.
83
+ #
84
+ # A hook resolves them against its own directory ($SCRIPT_DIR/lib/...), so they
85
+ # have to sit next to the installed copy: without lib/, pre-commit loses now_ms()
86
+ # and, since #473, Gate 5's handle_test_failure — whose absence fails closed into
87
+ # a block on every commit.
88
+ #
89
+ # REQ-DEPLOY-002: this loop used to glob "$HOOKS_DIR"/lib/*, which installed
90
+ # whatever happened to be in that directory whether or not any manifest declared
91
+ # it. Two consequences: adapter-common.sh / deploy-manifest.sh / install.sh (not
92
+ # under lib/) were never installed, and a file added to lib/ shipped with no
93
+ # manifest entry — so "is the manifest complete" could not be answered by
94
+ # reading the manifest.
95
+ for module in "${DEPLOY_MODULE_FILES[@]}"; do
96
+ src="$HOOKS_DIR/$module"
97
+ if [ -f "$src" ]; then
98
+ mkdir -p "$TARGET_HOOKS/$(dirname "$module")"
99
+ cp "$src" "$TARGET_HOOKS/$module"
100
+ chmod +x "$TARGET_HOOKS/$module"
101
+ echo " + $module -> .git/hooks/$module"
102
+ fi
103
+ done
104
+
105
+ if [ -d "$TARGET_GITHOOKS" ]; then
106
+ if [ "$1" != "--force" ]; then
107
+ mkdir -p "$TARGET_GITHOOKS/adapters"
108
+ if [ -f "$HOOKS_DIR/adapter-common.sh" ]; then
109
+ cp "$HOOKS_DIR/adapter-common.sh" "$TARGET_GITHOOKS/adapter-common.sh"
110
+ echo " + adapter-common.sh -> $TARGET_GITHOOKS/"
111
+ fi
112
+ cp -n "$HOOKS_DIR/adapters/"*.sh "$TARGET_GITHOOKS/adapters/" 2>/dev/null || true
113
+ echo " + adapters/*.sh (merged into $TARGET_GITHOOKS/adapters/)"
114
+ echo ""
115
+ echo "Git hooks and adapter infrastructure installed to current project."
116
+ echo " Hooks: $TARGET_HOOKS/{pre-commit,pre-push,post-merge}"
117
+ echo " Adapters: $TARGET_GITHOOKS/adapter-common.sh + adapters/"
118
+ echo ""
119
+ echo "On next commit, quality gates will run automatically."
120
+ exit 0
121
+ fi
122
+ fi
123
+
124
+ mkdir -p "$TARGET_GITHOOKS/adapters"
125
+ cp "$HOOKS_DIR/adapter-common.sh" "$TARGET_GITHOOKS/adapter-common.sh"
126
+ cp "$HOOKS_DIR/adapters/"*.sh "$TARGET_GITHOOKS/adapters/"
127
+
128
+ echo " + adapter-common.sh -> $TARGET_GITHOOKS/"
129
+ echo " + adapters/*.sh -> $TARGET_GITHOOKS/adapters/"
130
+ echo ""
131
+ echo "Git hooks and adapter infrastructure installed to current project."
132
+ echo " Hooks: $TARGET_HOOKS/{pre-commit,pre-push}"
133
+ echo " Adapters: $TARGET_GITHOOKS/adapter-common.sh + adapters/"
134
+ echo ""
135
+ echo "On next commit, quality gates will run automatically."
@@ -2,32 +2,68 @@
2
2
  # ============================================================================
3
3
  # now_ms() — Cross-platform epoch-milliseconds timestamp (Issue #370 fix)
4
4
  #
5
- # Windows Git Bash's `date +%s%3N` outputs literal "N" (e.g. "1753001234N")
6
- # and exits 0, so || fallback chains never trigger. This function:
7
- # 1. Prefers `node -e 'console.log(Date.now())'` (cross-platform, always ms)
8
- # 2. Validates output with ^[0-9]+$ regex
9
- # 3. Falls back to `date +%s` (seconds × 1000) if node output is invalid
10
- # 4. Final fallback: echo 0
5
+ # RETURNS: epoch milliseconds on stdout, or nothing (empty) when no source is
6
+ # available. Callers treat empty as "unmeasurable", never as 0: a fabricated zero
7
+ # would make every duration look like an instant gate.
8
+ #
9
+ # ORDER OF METHODS, fastest first. This function is called twice per gate, so its
10
+ # per-call cost is multiplied by 2 x (number of gates) on every commit:
11
+ #
12
+ # 1. $EPOCHREALTIME — bash 5+ builtin, NO fork, ~0 ms.
13
+ # "1794406209.964280" -> drop the dot -> microseconds.
14
+ # 2. date +%s%3N — one fork, ~5 ms where the platform supports %N.
15
+ # Git Bash on Windows historically printed a literal "N"
16
+ # ("1753001234N") and exited 0, so the output is validated
17
+ # and a non-numeric result is REJECTED rather than used.
18
+ # 3. date +%s — whole seconds only; multiplied by 1000. Coarse, but it
19
+ # still separates "gates are slow" from "the hook around
20
+ # them is".
21
+ #
22
+ # `node -e 'Date.now()'` used to be method 1. It is correct and cross-platform but
23
+ # costs ~580 ms per call on Windows, and at 2-4 calls per gate across 14 gates it
24
+ # added ~60 s to every commit (#798). It is deliberately NOT used here: a clock
25
+ # that dominates the thing it measures is worse than a clock with fewer digits.
11
26
  #
12
27
  # Source this file: source "$(dirname "${BASH_SOURCE[0]}")/lib/now-ms.sh"
13
28
  # ============================================================================
14
29
 
15
30
  now_ms() {
16
31
  local ts
17
- # Preferred: node (cross-platform, always produces epoch milliseconds)
18
- ts=$(node -e 'console.log(Date.now())' 2>/dev/null)
19
- if [[ "$ts" =~ ^[0-9]+$ ]]; then
20
- echo "$ts"
21
- return
22
- fi
23
32
 
24
- # Fallback: date +%s (seconds only — multiply by 1000 for ms)
25
- ts=$(date +%s 2>/dev/null)
26
- if [[ "$ts" =~ ^[0-9]+$ ]]; then
27
- echo $((ts * 1000))
28
- return
33
+ # 1. bash 5+ builtin clock. Zero forks.
34
+ if [ -n "${EPOCHREALTIME:-}" ]; then
35
+ case "$EPOCHREALTIME" in
36
+ *[!0-9.]* | "") : ;; # unexpected shape, fall through
37
+ *)
38
+ # "1794406209.964280" -> "1794406209964280" -> first 13 digits = ms.
39
+ ts="${EPOCHREALTIME/./}"
40
+ case "$ts" in
41
+ [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*)
42
+ echo "${ts:0:13}"
43
+ return
44
+ ;;
45
+ esac
46
+ ;;
47
+ esac
29
48
  fi
30
49
 
31
- # Final fallback
32
- echo 0
50
+ # 2. date with nanoseconds. Validated: Git Bash may emit a literal "N".
51
+ ts=$(date +%s%3N 2>/dev/null)
52
+ case "$ts" in
53
+ *[!0-9]* | "") : ;; # non-numeric (the "N" bug) — reject, do not guess
54
+ *)
55
+ # Guard against the seconds-only shape a %N-less date would produce.
56
+ if [ "${#ts}" -ge 12 ]; then
57
+ echo "$ts"
58
+ return
59
+ fi
60
+ ;;
61
+ esac
62
+
63
+ # 3. Whole seconds. Coarse but honest.
64
+ ts=$(date +%s 2>/dev/null)
65
+ case "$ts" in
66
+ *[!0-9]* | "") return ;;
67
+ *) echo $((ts * 1000)) ;;
68
+ esac
33
69
  }
@@ -253,12 +253,17 @@ resolve_tool_path() {
253
253
  return 0
254
254
  fi
255
255
 
256
- # npx knows about the project's own node_modules.
257
- if tool_is_available npx; then
258
- if npx --no-install "$_tool" --version >/dev/null 2>&1; then
259
- printf '%s\n' "$_tool"
260
- return 0
261
- fi
256
+ # Project-local node_modules/.bin.
257
+ #
258
+ # This replaced an `npx --no-install <tool> --version` probe. `--no-install`
259
+ # does stop the package being installed, but the probe still ASKS the registry
260
+ # every time (measured: 697 ms cache miss, 105 ms revalidating on a hit) and
261
+ # can even answer yes for a tool the project never depended on once the npx
262
+ # cache has been populated. Resolving the binary's real path is both cheaper
263
+ # and truthful. See docs/incidents/2026-11-09-command-could-not-run-*.
264
+ if [ -x "$_base/node_modules/.bin/$_tool" ]; then
265
+ printf '%s\n' "$_base/node_modules/.bin/$_tool"
266
+ return 0
262
267
  fi
263
268
 
264
269
  # Subproject node_modules/.bin, shallow then one level deep. A monorepo's ui/ or
@@ -274,6 +279,45 @@ resolve_tool_path() {
274
279
  return 1
275
280
  }
276
281
 
282
+ # Is the npx fallback explicitly enabled?
283
+ #
284
+ # Same convention as src/gates/common-process.ts (#21 / REQ-GATE-PROBE-SHORTCUT):
285
+ # `npx <tool> --version` answers "is it installed?" by hitting the registry and,
286
+ # when it is not, INSTALLING it -- so the probe changes the environment it was
287
+ # asked about. It stays off unless the project opts in.
288
+ probe_npx_enabled() {
289
+ case "${XP_GATE_NPX_PROBE:-}" in
290
+ 1 | true | TRUE | yes | YES) return 0 ;;
291
+ *) return 1 ;;
292
+ esac
293
+ }
294
+
295
+ # Can Gate 6 run archlint? Local artefacts only, unless opted in.
296
+ #
297
+ # Gate 6 used to answer this with `npx @archlinter/cli --version`, the last
298
+ # registry-consulting probe in the hooks. On a machine without archlint that
299
+ # downloaded the package, printed a version, and let the gate run a tool the
300
+ # project never depended on -- while every sibling branch above it checked a
301
+ # local artefact. A missing archlint is BLOCK-with-hint here (Gate 6 is not
302
+ # fail-open like the tool-missing SKIP path), so the honest answer matters.
303
+ probe_archlint_available() {
304
+ local _root="${1:-.}"
305
+ if [ -f "$_root/node_modules/@archlinter/cli/bin/archlint.js" ] && command -v node >/dev/null 2>&1; then
306
+ return 0
307
+ fi
308
+ if [ -x "$_root/node_modules/.bin/archlint" ]; then
309
+ return 0
310
+ fi
311
+ if command -v archlint >/dev/null 2>&1; then
312
+ return 0
313
+ fi
314
+ if probe_npx_enabled && command -v npx >/dev/null 2>&1; then
315
+ (cd "$_root" 2>/dev/null && npx @archlinter/cli --version) >/dev/null 2>&1
316
+ return $?
317
+ fi
318
+ return 1
319
+ }
320
+
277
321
  # Put the directory of a resolved tool on PATH, so the tool's own siblings are
278
322
  # reachable, and print that directory.
279
323
  #