@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,199 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-2 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 2: Duplicate Code Detection (NEW gate)
22
+ # Uses jscpd, or similar tools, specific to language
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_2_run() {
28
+ 2>&1 echo ""
29
+ 2>&1 echo "→ Gate 2: Duplicate code detection..."
30
+ GATE_2_START=$(gate_start_ms)
31
+ GATE_2_STATUS="PASS"
32
+
33
+ if ! gate_enabled 2; then
34
+ echo "⏭️ SKIPPED - Gate 2: Duplicate code (not selected by XP_GATE_ONLY_GATE)"
35
+ GATE_2_STATUS="SKIP"
36
+ GATE_2_DETAIL="not_selected"
37
+
38
+ elif [ "$PROJECT_LANG" = "documentation-only" ] || [ "$DOCS_ONLY_COMMIT" = true ]; then
39
+ echo "⏭️ SKIPPED - Duplicate code (documentation-only ${DOCS_ONLY_COMMIT:+commit})."
40
+ GATE_2_STATUS="SKIP"
41
+ # GATE_2_DETAIL feeds record_gate_audit's detail field. The previous
42
+ # GATE_2_REASON was assigned and never read by anything, which is worse than
43
+ # useless: it looks like the skip reason reaches the audit journal when it does
44
+ # not (no set -u, so nothing complained).
45
+ GATE_2_DETAIL="docs_only_change"
46
+
47
+ else
48
+ for CURRENT_LANG in $PROJECT_LANGS; do
49
+ echo " ── Checking $CURRENT_LANG ──"
50
+ case "$CURRENT_LANG" in
51
+ typescript)
52
+ if ! require_tool "jscpd" "Gate 2" "npm install -D jscpd"; then
53
+ return 1
54
+ fi
55
+
56
+ echo "Running jscpd for duplicate code detection..."
57
+ # #477: only pass --config when the file actually exists, and let jscpd's report
58
+ # decide the message. Before this, a missing config produced "os error 2" and a
59
+ # non-zero exit that the gate translated into a fabricated "found duplicated
60
+ # code"; a real clone report that exited 0 was announced as a clean pass.
61
+ JSCPD_CONFIG=$(resolve_jscpd_config)
62
+ JSCPD_ARGS=()
63
+ if [ -n "$JSCPD_CONFIG" ]; then
64
+ JSCPD_ARGS=(--config "$JSCPD_CONFIG")
65
+ else
66
+ # #591: with no project config, jscpd's own defaults treat .yaml/.txt/.log as
67
+ # scannable source, so an exemptions manifest, a golden snapshot and two build
68
+ # logs were reported as "duplicated code" (measured: 48.72% on a fixture with
69
+ # no source in it). Print the baseline that is actually in force, or the user
70
+ # cannot tell what was scanned.
71
+ echo "ℹ️ No jscpd.conf.json found - using the xp-gate default ignore set"
72
+ echo " $(jscpd_default_ignore_patterns)"
73
+ fi
74
+ # #591: drop data/evidence/build-output paths before the scan. Real source
75
+ # extensions are untouched, so this narrows the noise, not the gate.
76
+ JSCPD_SCAN_FILES=""
77
+ while IFS= read -r _jf; do
78
+ [ -n "$_jf" ] || continue
79
+ if ! jscpd_is_default_ignored "$_jf"; then
80
+ JSCPD_SCAN_FILES="$JSCPD_SCAN_FILES $_jf"
81
+ fi
82
+ done <<EOF_CHANGED
83
+ $CHANGED_FILES
84
+ EOF_CHANGED
85
+ JSCPD_OUTPUT=$(mktemp)
86
+ JSCPD_EXIT=0
87
+ # shellcheck disable=SC2086 # pre-existing splitting of the file list; #477/#591 change the scan set, not the splitting
88
+ jscpd ${JSCPD_ARGS[@]+"${JSCPD_ARGS[@]}"} $JSCPD_SCAN_FILES > "$JSCPD_OUTPUT" 2>&1 || JSCPD_EXIT=$?
89
+ head -30 "$JSCPD_OUTPUT" || true
90
+ JSCPD_OUTCOME=$(classify_jscpd_run "$JSCPD_EXIT" "$(cat "$JSCPD_OUTPUT")")
91
+ rm -f "$JSCPD_OUTPUT"
92
+ if [ "$JSCPD_OUTCOME" = "duplicates" ]; then
93
+ echo "ℹ️ jscpd found duplicated code (warning, not blocking by default)"
94
+ echo " Consider refactoring duplicate code blocks."
95
+ elif [ "$JSCPD_OUTCOME" = "error" ]; then
96
+ echo "⚠️ jscpd exited with code $JSCPD_EXIT without a report — the output above is its real error"
97
+ echo "⏭️ SKIPPED - Duplicate code (jscpd run error)"
98
+ GATE_2_STATUS="SKIP"
99
+ else
100
+ echo "✅ PASSED - jscpd duplicate code check completed."
101
+ fi
102
+ ;;
103
+
104
+ python)
105
+ if command -v pylint &> /dev/null; then
106
+ echo "Running pylint duplicate detection..."
107
+ pylint --disable=all --enable=duplicate-code $(echo "$CHANGED_FILES" | grep "\.py$")
108
+ DUPLICATE_EXIT=$?
109
+ if [ "$DUPLICATE_EXIT" -ne 0 ]; then
110
+ echo "ℹ️ pylint found duplicate code (warning, not typically blocking)"
111
+ else
112
+ echo "✅ PASSED - pylint found no duplicates."
113
+ fi
114
+ else
115
+ echo "ℹ️ pylint not found — skipping Python duplicate code check."
116
+ echo " Install pylint: pip install pylint"
117
+ fi
118
+ ;;
119
+
120
+ go)
121
+ if ! require_tool "jscpd" "Gate 2" "npm install -D jscpd"; then
122
+ return 1
123
+ fi
124
+
125
+ echo "Running jscpd for Go duplicate code detection..."
126
+ FILES_TO_CHECK=$(echo "$CHANGED_FILES" | grep "\.go$" | head -20)
127
+ if [ -n "$FILES_TO_CHECK" ]; then
128
+ # #392-#9: capture jscpd's real exit code via temp file instead of piping
129
+ # through head (which would swallow the exit status under pipefail analysis).
130
+ GO_JSCPD_TMP=$(mktemp)
131
+ jscpd $FILES_TO_CHECK > "$GO_JSCPD_TMP" 2>&1
132
+ JSCPD_GO_EXIT=$?
133
+ head -10 "$GO_JSCPD_TMP"
134
+ rm -f "$GO_JSCPD_TMP"
135
+ if [ "$JSCPD_GO_EXIT" -ne 0 ]; then
136
+ echo "⚠️ jscpd (Go) exited with code $JSCPD_GO_EXIT"
137
+ fi
138
+ fi
139
+ echo "✅ PASSED - Go duplicate code check completed."
140
+ ;;
141
+
142
+ powershell)
143
+ echo "ℹ️ No PowerShell-native duplicate detector (jscpd does not support .ps1)"
144
+ echo "⏭️ SKIPPED - Duplicate code (no tool for PowerShell)"
145
+ ;;
146
+
147
+ shell)
148
+ echo "ℹ️ Duplicate detection not typically used for shell scripts"
149
+ echo "⏭️ SKIPPED - Duplicate code (no tool for shell scripts)"
150
+ ;;
151
+
152
+ *)
153
+ SOURCE_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|scala|kt|cpp|c|h|rs|php|dart|swift|cs|csx|fs|vb)$' || true)
154
+ if [ -n "$SOURCE_FILES" ]; then
155
+ if ! require_tool "jscpd" "Gate 2" "npm install -D jscpd"; then
156
+ return 1
157
+ fi
158
+ echo "Running jscpd for duplicate code detection..."
159
+ # #591 point 4: this branch piped straight into `head`, so jscpd's exit status
160
+ # was replaced by head's (and SIGPIPE under pipefail) — inconsistent with the
161
+ # temp-file treatment the typescript branch already had from #477/#392. The
162
+ # #591 default ignore set applies here too.
163
+ GENERIC_JSCPD_FILES=""
164
+ while IFS= read -r _gf; do
165
+ [ -n "$_gf" ] || continue
166
+ if ! jscpd_is_default_ignored "$_gf"; then
167
+ GENERIC_JSCPD_FILES="$GENERIC_JSCPD_FILES $_gf"
168
+ fi
169
+ done <<EOF_GENERIC
170
+ $SOURCE_FILES
171
+ EOF_GENERIC
172
+ if [ -n "$GENERIC_JSCPD_FILES" ]; then
173
+ GENERIC_JSCPD_TMP=$(mktemp)
174
+ # shellcheck disable=SC2086
175
+ jscpd $GENERIC_JSCPD_FILES > "$GENERIC_JSCPD_TMP" 2>&1 || GENERIC_JSCPD_EXIT=$?
176
+ head -15 "$GENERIC_JSCPD_TMP" || true
177
+ rm -f "$GENERIC_JSCPD_TMP"
178
+ if [ "${GENERIC_JSCPD_EXIT:-0}" -ne 0 ]; then
179
+ echo "⚠️ jscpd exited with code $GENERIC_JSCPD_EXIT (see output above)"
180
+ fi
181
+ fi
182
+ echo "✅ PASSED - jscpd check completed."
183
+ else
184
+ echo "✅ PASSED - No source files detected for duplicate checking."
185
+ fi
186
+ ;;
187
+ esac
188
+ done
189
+ fi
190
+ # Set at the top of this gate; a branch may already have marked it SKIP (#477). The
191
+ # audit must record what happened, not what the gate defaults to.
192
+ record_gate_audit "gate-2" "duplicate-code" "$GATE_2_STATUS" "0" "$GATE_2_START" "${GATE_2_DETAIL:-}"
193
+ return 0
194
+ }
195
+
196
+
197
+
198
+ # Called by pre-commit's ordered driver.
199
+
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-3 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 3: Cyclomatic Complexity Check
22
+ # Extracted to gate-3.sh for maintainability
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_3_run() {
28
+ #
29
+ # A2 gates the SOURCE, not a branch inside gate-3.sh. GATE_DIR resolves through
30
+ # three tiers and, on an installed machine, lands on
31
+ # ~/.config/xp-gate/adapters/ -- a COPY that predates this change. An edit
32
+ # inside gate-N.sh is therefore inert exactly where it matters most, which is
33
+ # the same trap githooks/AGENTS.md documents for the hooks themselves (verified:
34
+ # a build here reports GATE_DIR=/c/Users/think/.config/xp-gate/adapters, whose
35
+ # gate-4.sh has none of this change). Checking here works against either copy.
36
+ if gate_enabled 3; then
37
+ source "$GATE_DIR/gate-3.sh"
38
+ else
39
+ echo ""
40
+ echo "→ Gate 3: Cyclomatic complexity..."
41
+ echo "⏭️ SKIPPED - Gate 3: Complexity (not selected by XP_GATE_ONLY_GATE)"
42
+ GATE_3_START=$(gate_start_ms)
43
+ GATE_3_STATUS="SKIP"
44
+ GATE_3_REASON="not_selected"
45
+ record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "0" "$GATE_3_START" "not_selected"
46
+ fi
47
+ return 0
48
+ }
49
+
50
+
51
+
52
+ # Called by pre-commit's ordered driver.
53
+
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # gate-4 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 4: Principles Checker (Clean Code + SOLID)
22
+ # Extracted to gate-4.sh for maintainability
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_4_run() {
28
+ if gate_enabled 4; then
29
+ source "$GATE_DIR/gate-4.sh"
30
+ else
31
+ echo ""
32
+ echo "→ Gate 4: Principles checker..."
33
+ echo "⏭️ SKIPPED - Gate 4: Principles (not selected by XP_GATE_ONLY_GATE)"
34
+ GATE_4_START=$(gate_start_ms)
35
+ GATE_4_STATUS="SKIP"
36
+ GATE_4_REASON="not_selected"
37
+ WARNING_COUNT=0
38
+ record_gate_audit "gate-4" "principles" "$GATE_4_STATUS" "0" "$GATE_4_START" "not_selected"
39
+ fi
40
+ return 0
41
+ }
42
+
43
+
44
+
45
+ # Called by pre-commit's ordered driver.
46
+