@boyingliu01/xp-gate 0.41.10 → 0.41.52

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 (123) hide show
  1. package/adapters/gate-3.sh +28 -1
  2. package/adapters/gate-6-layers.sh +18 -1
  3. package/bin/xp-gate.js +13 -0
  4. package/gate-3.sh +28 -1
  5. package/gate-6-layers.sh +18 -1
  6. package/gates/python-health.ts +74 -26
  7. package/gates/test-layers.ts +94 -9
  8. package/hooks/gate-3.sh +28 -1
  9. package/hooks/gate-6-layers.sh +18 -1
  10. package/hooks/gate-entries/gate-11-entry.sh +21 -0
  11. package/hooks/gate-entries/gate-2-entry.sh +15 -0
  12. package/hooks/install.sh +15 -3
  13. package/hooks/pre-commit +90 -13
  14. package/hooks/pre-push +10 -1
  15. package/hooks/sprint-gate.sh +101 -13
  16. package/lib/check-alignment-runner.cjs +97 -0
  17. package/lib/check.js +6 -0
  18. package/lib/crap-cli.js +14 -6
  19. package/lib/delphi-setup.js +13 -0
  20. package/lib/doctor-tui.js +205 -102
  21. package/lib/doctor.js +146 -7
  22. package/lib/gate-runner.js +14 -3
  23. package/lib/init-install.js +299 -0
  24. package/lib/init-languages.js +158 -0
  25. package/lib/init-manifest.js +165 -0
  26. package/lib/init-md-injection.js +58 -0
  27. package/lib/init.js +134 -500
  28. package/lib/install-skill.js +66 -1
  29. package/lib/layer-baseline.cjs +94 -0
  30. package/lib/mattpocock-license-verdict.json +7 -0
  31. package/lib/uninstall-skills.js +140 -0
  32. package/lib/uninstall.js +41 -100
  33. package/lib/update-skill.js +9 -1
  34. package/package.json +3 -1
  35. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  36. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  37. package/plugins/claude-code/skills/delphi-review/INSTALL.md +22 -3
  38. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  39. package/plugins/claude-code/skills/sprint-flow/references/definition-of-done.md +2 -2
  40. package/plugins/claude-code/skills/sprint-flow/references/phase-3-build.md +1 -1
  41. package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +2 -2
  42. package/plugins/claude-code/skills/sprint-flow/references/phase-6-close.md +17 -0
  43. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  44. package/plugins/dsh/lib/delphi-evidence.d.ts +59 -0
  45. package/plugins/dsh/lib/delphi-evidence.d.ts.map +1 -0
  46. package/plugins/dsh/lib/delphi-evidence.js +128 -0
  47. package/plugins/dsh/lib/delphi-finding.d.ts +123 -0
  48. package/plugins/dsh/lib/delphi-finding.d.ts.map +1 -0
  49. package/plugins/dsh/lib/delphi-finding.js +332 -0
  50. package/plugins/dsh/lib/delphi-findings-parse.d.ts +29 -0
  51. package/plugins/dsh/lib/delphi-findings-parse.d.ts.map +1 -0
  52. package/plugins/dsh/lib/delphi-findings-parse.js +138 -0
  53. package/plugins/dsh/lib/delphi-ledger.d.ts +55 -0
  54. package/plugins/dsh/lib/delphi-ledger.d.ts.map +1 -0
  55. package/plugins/dsh/lib/delphi-ledger.js +124 -0
  56. package/plugins/dsh/lib/delphi-run.d.ts +7 -0
  57. package/plugins/dsh/lib/delphi-run.d.ts.map +1 -1
  58. package/plugins/dsh/lib/delphi-run.js +48 -18
  59. package/plugins/dsh/lib/delphi-seats.d.ts +34 -0
  60. package/plugins/dsh/lib/delphi-seats.d.ts.map +1 -0
  61. package/plugins/dsh/lib/delphi-seats.js +40 -0
  62. package/plugins/dsh/lib/evidence.d.ts +21 -0
  63. package/plugins/dsh/lib/evidence.d.ts.map +1 -1
  64. package/plugins/dsh/lib/evidence.js +3 -0
  65. package/plugins/dsh/lib/index.d.ts.map +1 -1
  66. package/plugins/dsh/lib/index.js +12 -0
  67. package/plugins/dsh/package.json +1 -1
  68. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  69. package/plugins/dsh/skills/delphi-review/INSTALL.md +22 -3
  70. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  71. package/plugins/dsh/skills/sprint-flow/references/definition-of-done.md +2 -2
  72. package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +1 -1
  73. package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +2 -2
  74. package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +17 -0
  75. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  76. package/plugins/dsh/src/delphi-evidence.test.ts +100 -0
  77. package/plugins/dsh/src/delphi-evidence.ts +201 -0
  78. package/plugins/dsh/src/delphi-finding.test.ts +333 -0
  79. package/plugins/dsh/src/delphi-finding.ts +446 -0
  80. package/plugins/dsh/src/delphi-findings-parse.test.ts +100 -0
  81. package/plugins/dsh/src/delphi-findings-parse.ts +158 -0
  82. package/plugins/dsh/src/delphi-findings.test.ts +4 -0
  83. package/plugins/dsh/src/delphi-ledger.test.ts +210 -0
  84. package/plugins/dsh/src/delphi-ledger.ts +158 -0
  85. package/plugins/dsh/src/delphi-run.test.ts +71 -68
  86. package/plugins/dsh/src/delphi-run.ts +80 -24
  87. package/plugins/dsh/src/delphi-seats.test.ts +117 -0
  88. package/plugins/dsh/src/delphi-seats.ts +50 -0
  89. package/plugins/dsh/src/evidence-findings.test.ts +75 -0
  90. package/plugins/dsh/src/evidence.ts +25 -0
  91. package/plugins/dsh/src/index.ts +14 -0
  92. package/plugins/opencode/package.json +1 -1
  93. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  94. package/plugins/opencode/skills/delphi-review/INSTALL.md +22 -3
  95. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  96. package/plugins/opencode/skills/sprint-flow/references/definition-of-done.md +2 -2
  97. package/plugins/opencode/skills/sprint-flow/references/phase-3-build.md +1 -1
  98. package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +2 -2
  99. package/plugins/opencode/skills/sprint-flow/references/phase-6-close.md +17 -0
  100. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  101. package/plugins/qoder/plugin.json +1 -1
  102. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  103. package/plugins/qoder/skills/delphi-review/INSTALL.md +22 -3
  104. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  105. package/plugins/qoder/skills/sprint-flow/references/definition-of-done.md +2 -2
  106. package/plugins/qoder/skills/sprint-flow/references/phase-3-build.md +1 -1
  107. package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +2 -2
  108. package/plugins/qoder/skills/sprint-flow/references/phase-6-close.md +17 -0
  109. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  110. package/principles/index.ts +50 -1
  111. package/scripts/delphi-config-read.cjs +43 -6
  112. package/scripts/delphi-external-review.cjs +69 -12
  113. package/scripts/delphi-prompts.cjs +47 -1
  114. package/skills/delphi-review/AGENTS.md +1 -1
  115. package/skills/delphi-review/INSTALL.md +22 -3
  116. package/skills/sprint-flow/AGENTS.md +1 -1
  117. package/skills/sprint-flow/references/definition-of-done.md +2 -2
  118. package/skills/sprint-flow/references/phase-3-build.md +1 -1
  119. package/skills/sprint-flow/references/phase-4-verify.md +2 -2
  120. package/skills/sprint-flow/references/phase-6-close.md +17 -0
  121. package/skills/test-specification-alignment/AGENTS.md +1 -1
  122. package/sprint-gate.sh +101 -13
  123. package/mutation/stryker-types.ts +0 -14
@@ -737,10 +737,37 @@ LIZARD_LENGTH_MAX="${LIZARD_LENGTH_MAX:-1000}"
737
737
  # Columns (lizard --csv): 1 NLOC, 2 CCN, 3 token, 4 PARAM, 5 length.
738
738
  # LENGTH_MAX is lizard's own 1000, so this reports what lizard reports
739
739
  # rather than inventing a second opinion. CCN still decides on its own.
740
+ # #747: lizard does NOT fail on source it cannot parse. Measured with lizard
741
+ # 1.25 on this host:
742
+ #
743
+ # printf 'function broken( {\n if (a) {\n' > bad.ts
744
+ # lizard --csv bad.ts -> 2,2,7,1,2,"broken@1-2@bad.ts",...,"broken ( {} if ( a )",1,2
745
+ # exit code: 0
746
+ #
747
+ # A two-line fragment that is not valid TypeScript came back as a function with
748
+ # CCN 2 -- indistinguishable, in the columns read below, from a genuine small
749
+ # function. Counting it would score a failed parse as a clean result.
750
+ #
751
+ # The signal that IS in the CSV: column 9 is the signature, and a parse that
752
+ # stopped at a brace leaves the brace in it.
753
+ #
754
+ # unparsed: "broken ( {} if ( a )" <- a `{` where the parameter list was
755
+ # parsed: "f ( a )"
756
+ #
757
+ # Rows like that are counted SEPARATELY and reported, never folded into the
758
+ # warning count -- a number produced by a failed parse is not a low number, it
759
+ # is no number.
760
+ CC_UNPARSED_ROWS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, '
761
+ NF > 1 && $9 ~ /[{}]/ { c++ }
762
+ END { print c + 0 }
763
+ ')
740
764
  CC_WARNINGS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, -v t="$CCN_THRESHOLD" -v lenmax="$LIZARD_LENGTH_MAX" '
741
- NF > 1 && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
765
+ NF > 1 && $9 !~ /[{}]/ && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
742
766
  END { print c + 0 }
743
767
  ')
768
+ if [ "${CC_UNPARSED_ROWS:-0}" -gt 0 ]; then
769
+ echo " ⚠ lizard could not parse ${CC_UNPARSED_ROWS} function(s) — their complexity was NOT evaluated (#747)"
770
+ fi
744
771
  # A lizard that produced no parsable row must not read as "clean". Without
745
772
  # this, a crashing or mis-invoked lizard yields 0 warnings and the gate
746
773
  # reports PASSED on zero analysed functions -- the same silent-success
@@ -161,7 +161,24 @@ LAYER_TSV=$(awk '
161
161
  listkey = ""
162
162
  next
163
163
  }
164
- if (indent == layerindent && body ~ /^- /) { next }
164
+ # #811: a `- name: X` line at the layer indent STARTS a layer in the sequence form
165
+ # (`layers:` followed by `- name:` items) and must not be skipped. The previous
166
+ # `{ next }` dropped every such line, so the standard spelling parsed to zero layers
167
+ # and the gate reported `layer_config_unparsable` on a config that was perfectly
168
+ # valid -- the verdict depended on how the file was written, not on the code.
169
+ #
170
+ # Both destructuring shapes are accepted: `- name: X` (the name rides on the dash)
171
+ # and `-` alone followed by an indented `name:` line.
172
+ if (indent == layerindent && body ~ /^- /) {
173
+ if (body ~ /^-[ \t]*name:[ \t]*/) {
174
+ flush()
175
+ name = unq(substr(body, index(body, ":") + 1))
176
+ listkey = ""
177
+ }
178
+ # A bare `-` opens a record whose `name:` comes on the next, deeper line; the
179
+ # existing `^name:` branch below picks it up once `layerindent` advances.
180
+ next
181
+ }
165
182
  if (name == "") next
166
183
  if (body ~ /^name:/) { name = unq(substr(body, 6)) }
167
184
  # `pattern:` and `patterns:` are both accepted. The singular form is the one
package/bin/xp-gate.js CHANGED
@@ -169,6 +169,19 @@ async function runAlignmentCheck(subargs) {
169
169
 
170
170
  const runnerPath = path.join(__dirname, '..', 'lib', 'check-alignment-runner.cjs');
171
171
 
172
+ // #894: the runner is referenced by PATH, so a packaging mistake turns this
173
+ // command into a bare ERR_MODULE_NOT_FOUND stack trace -- which shipped in every
174
+ // published version before 0.41.10. A gate that cannot start must say so in the
175
+ // same voice as the others: what is missing, and what the operator can do about
176
+ // it. "Cannot find module" from inside a tsx loader names neither.
177
+ if (!require('node:fs').existsSync(runnerPath)) {
178
+ console.error('❌ BLOCKED - check-alignment: the alignment runner is missing from this install.');
179
+ console.error(` Expected: ${runnerPath}`);
180
+ console.error(' This is a packaging fault, not a problem with your project.');
181
+ console.error(' Reinstall with: npm install -g @boyingliu01/xp-gate@latest');
182
+ return 1;
183
+ }
184
+
172
185
  // Primary: run the engine in-process via tsx/cjs (fast path, works in-repo
173
186
  // where tsx is a devDependency). Fall back to `npx -y tsx` when tsx is not
174
187
  // resolvable, which happens in the published global install (the package
package/gate-3.sh CHANGED
@@ -737,10 +737,37 @@ LIZARD_LENGTH_MAX="${LIZARD_LENGTH_MAX:-1000}"
737
737
  # Columns (lizard --csv): 1 NLOC, 2 CCN, 3 token, 4 PARAM, 5 length.
738
738
  # LENGTH_MAX is lizard's own 1000, so this reports what lizard reports
739
739
  # rather than inventing a second opinion. CCN still decides on its own.
740
+ # #747: lizard does NOT fail on source it cannot parse. Measured with lizard
741
+ # 1.25 on this host:
742
+ #
743
+ # printf 'function broken( {\n if (a) {\n' > bad.ts
744
+ # lizard --csv bad.ts -> 2,2,7,1,2,"broken@1-2@bad.ts",...,"broken ( {} if ( a )",1,2
745
+ # exit code: 0
746
+ #
747
+ # A two-line fragment that is not valid TypeScript came back as a function with
748
+ # CCN 2 -- indistinguishable, in the columns read below, from a genuine small
749
+ # function. Counting it would score a failed parse as a clean result.
750
+ #
751
+ # The signal that IS in the CSV: column 9 is the signature, and a parse that
752
+ # stopped at a brace leaves the brace in it.
753
+ #
754
+ # unparsed: "broken ( {} if ( a )" <- a `{` where the parameter list was
755
+ # parsed: "f ( a )"
756
+ #
757
+ # Rows like that are counted SEPARATELY and reported, never folded into the
758
+ # warning count -- a number produced by a failed parse is not a low number, it
759
+ # is no number.
760
+ CC_UNPARSED_ROWS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, '
761
+ NF > 1 && $9 ~ /[{}]/ { c++ }
762
+ END { print c + 0 }
763
+ ')
740
764
  CC_WARNINGS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, -v t="$CCN_THRESHOLD" -v lenmax="$LIZARD_LENGTH_MAX" '
741
- NF > 1 && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
765
+ NF > 1 && $9 !~ /[{}]/ && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
742
766
  END { print c + 0 }
743
767
  ')
768
+ if [ "${CC_UNPARSED_ROWS:-0}" -gt 0 ]; then
769
+ echo " ⚠ lizard could not parse ${CC_UNPARSED_ROWS} function(s) — their complexity was NOT evaluated (#747)"
770
+ fi
744
771
  # A lizard that produced no parsable row must not read as "clean". Without
745
772
  # this, a crashing or mis-invoked lizard yields 0 warnings and the gate
746
773
  # reports PASSED on zero analysed functions -- the same silent-success
package/gate-6-layers.sh CHANGED
@@ -161,7 +161,24 @@ LAYER_TSV=$(awk '
161
161
  listkey = ""
162
162
  next
163
163
  }
164
- if (indent == layerindent && body ~ /^- /) { next }
164
+ # #811: a `- name: X` line at the layer indent STARTS a layer in the sequence form
165
+ # (`layers:` followed by `- name:` items) and must not be skipped. The previous
166
+ # `{ next }` dropped every such line, so the standard spelling parsed to zero layers
167
+ # and the gate reported `layer_config_unparsable` on a config that was perfectly
168
+ # valid -- the verdict depended on how the file was written, not on the code.
169
+ #
170
+ # Both destructuring shapes are accepted: `- name: X` (the name rides on the dash)
171
+ # and `-` alone followed by an indented `name:` line.
172
+ if (indent == layerindent && body ~ /^- /) {
173
+ if (body ~ /^-[ \t]*name:[ \t]*/) {
174
+ flush()
175
+ name = unq(substr(body, index(body, ":") + 1))
176
+ listkey = ""
177
+ }
178
+ # A bare `-` opens a record whose `name:` comes on the next, deeper line; the
179
+ # existing `^name:` branch below picks it up once `layerindent` advances.
180
+ next
181
+ }
165
182
  if (name == "") next
166
183
  if (body ~ /^name:/) { name = unq(substr(body, 6)) }
167
184
  # `pattern:` and `patterns:` are both accepted. The singular form is the one
@@ -90,9 +90,37 @@ const VENV_DIR_NAMES = ['.venv', 'venv'];
90
90
  *
91
91
  * @param cwd project root to inspect; defaults to process.cwd()
92
92
  */
93
- export function hasPythonSignal(cwd?: string): boolean {
93
+ export type PythonSignalStatus = 'found' | 'absent' | 'inconclusive';
94
+
95
+ /**
96
+ * Whether this project is a Python project -- with "cannot tell" kept separate.
97
+ *
98
+ * #792: the walk is bounded (SIGNAL_MAX_DEPTH / SIGNAL_MAX_ENTRIES) and used to
99
+ * `return false` when it ran out, which already meant "no Python here". A project whose
100
+ * only `.py` file sat at depth 6 was therefore declared not-a-Python-project, and the
101
+ * chain ran to the end: mypy/pytest never probed, required tools marked
102
+ * `skipped (required)`, `healthy` computed as always-true, and the run finished with a
103
+ * confident `✅ Python environment is healthy.`
104
+ *
105
+ * Measured by the reporter across four fixture shapes differing only in depth. The
106
+ * three outcomes are not interchangeable:
107
+ *
108
+ * found a marker, venv, or .py file -> probe
109
+ * absent walked the whole tree, found none -> skip quietly
110
+ * inconclusive the walk ran out of budget -> skip LOUDLY, never healthy
111
+ *
112
+ * @param cwd directory to inspect, defaulting to the process cwd
113
+ * @returns which of the three applies
114
+ */
115
+ export function pythonSignalStatus(cwd?: string): PythonSignalStatus {
94
116
  const root = cwd || process.cwd();
95
- return hasMarkerFile(root) || hasVenvDir(root) || containsPythonFile(root);
117
+ if (hasMarkerFile(root) || hasVenvDir(root)) return 'found';
118
+ return classifyPythonFileSearch(root);
119
+ }
120
+
121
+ /** The boolean form, for callers that only need "is this Python or not". */
122
+ export function hasPythonSignal(cwd?: string): boolean {
123
+ return pythonSignalStatus(cwd) === 'found';
96
124
  }
97
125
 
98
126
  /** Is any marker file present? An unreadable root is not evidence either way. */
@@ -152,34 +180,43 @@ function budgetExhausted(depth: number, counter: { seen: number }): boolean {
152
180
  return depth > SIGNAL_MAX_DEPTH || counter.seen > SIGNAL_MAX_ENTRIES;
153
181
  }
154
182
 
183
+
155
184
  /**
156
- * Whether this directory entry is, or contains, a Python file.
185
+ * Search for a .py file, telling "none" apart from "stopped looking".
186
+ *
187
+ * The distinction is the whole point (#792): a bounded walk that returns plain `false`
188
+ * reports exhaustion as absence, and every downstream decision reads that as "not a
189
+ * Python project". A read error is the same case -- the doc comment on the old
190
+ * `containsPythonFile` said so, but the return value could not express it.
157
191
  *
158
- * The counter is incremented per ENTRY rather than per directory, so a tree with a
159
- * huge flat directory is bounded too -- the depth limit alone would not stop it.
192
+ * @param root directory to search
193
+ * @returns 'found' when one was seen, 'absent' when the tree was exhausted, else
194
+ * 'inconclusive'
160
195
  */
161
- function entryLeadsToPython(dir: string, entry: import('fs').Dirent, depth: number, counter: { seen: number }): boolean {
162
- counter.seen += 1;
163
- if (counter.seen > SIGNAL_MAX_ENTRIES) return false;
164
- if (isPythonFileEntry(entry)) return true;
165
- if (!entry.isDirectory() || shouldSkipDir(entry)) return false;
166
- return walkForPythonFile(path.join(dir, entry.name), depth + 1, counter);
196
+ function classifyPythonFileSearch(root: string): PythonSignalStatus {
197
+ try {
198
+ return walkStatus(root, 0, { seen: 0 });
199
+ } catch {
200
+ return 'inconclusive';
201
+ }
167
202
  }
168
203
 
169
- function walkForPythonFile(dir: string, depth: number, counter: { seen: number }): boolean {
170
- if (budgetExhausted(depth, counter)) return false;
204
+ function walkStatus(dir: string, depth: number, counter: { seen: number }): PythonSignalStatus {
205
+ if (budgetExhausted(depth, counter)) return 'inconclusive';
171
206
  const entries = readEntries(dir);
172
- if (!entries) return false;
173
- return entries.some((entry) => entryLeadsToPython(dir, entry, depth, counter));
207
+ if (!entries) return 'inconclusive';
208
+
209
+ for (const entry of entries) {
210
+ counter.seen += 1;
211
+ if (counter.seen > SIGNAL_MAX_ENTRIES) return 'inconclusive';
212
+ if (isPythonFileEntry(entry)) return 'found';
213
+ if (!entry.isDirectory() || shouldSkipDir(entry)) continue;
214
+ const sub = walkStatus(path.join(dir, entry.name), depth + 1, counter);
215
+ if (sub !== 'absent') return sub;
216
+ }
217
+ return 'absent';
174
218
  }
175
219
 
176
- /**
177
- * Look for any .py file under root. Returns false on a read error: "could not
178
- * look" must never be reported as "definitely not Python".
179
- */
180
- function containsPythonFile(root: string): boolean {
181
- return walkForPythonFile(root, 0, { seen: 0 });
182
- }
183
220
 
184
221
  // ── Python Detection ──
185
222
 
@@ -513,13 +550,17 @@ export function checkPythonHealth(cwd?: string): PythonHealthResult {
513
550
  // 2-4. Version, pip, and virtualenv — each appends its own issue if unhappy.
514
551
  const { pip, environment } = inspectEnvironment(python, cwd, issues);
515
552
 
516
- // 5. Check tools (input short-circuit — see resolvePythonTools)
517
- const pythonSignal = hasPythonSignal(cwd);
553
+ // 5. Check tools (input short-circuit — see resolvePythonTools).
554
+ // #792: the short-circuit is only valid when we KNOW there is no Python. "The walk
555
+ // ran out of budget" is not that answer, and treating it as one is what let a real
556
+ // Python project finish with a confident "✅ healthy".
557
+ const signal = pythonSignalStatus(cwd);
558
+ const pythonSignal = signal === 'found';
518
559
  const { tools, missingRequired } = resolvePythonTools(python.exe, cwd, pythonSignal);
519
560
 
520
561
  reportMissingTools(issues, missingRequired, python.exe, pythonSignal);
521
562
  return {
522
- healthy: isHealthy(issues, missingRequired, pythonSignal),
563
+ healthy: isHealthy(issues, missingRequired, pythonSignal, signal === 'inconclusive'),
523
564
  python, pip, environment, tools, issues,
524
565
  toolProbesRan: pythonSignal,
525
566
  };
@@ -547,8 +588,15 @@ const BLOCKING_ISSUE = /not found|minimum/;
547
588
  * unconditionally would report "unhealthy" for a repo with nothing for Python tooling
548
589
  * to check.
549
590
  */
550
- function isHealthy(issues: string[], missingRequired: unknown[], pythonSignal: boolean): boolean {
591
+ function isHealthy(
592
+ issues: string[],
593
+ missingRequired: unknown[],
594
+ pythonSignal: boolean,
595
+ inconclusive = false,
596
+ ): boolean {
551
597
  if (issues.some((issue) => BLOCKING_ISSUE.test(issue))) return false;
598
+ // #792: an inconclusive signal cannot be reported as healthy -- nothing was verified.
599
+ if (inconclusive) return false;
552
600
  return !pythonSignal || missingRequired.length === 0;
553
601
  }
554
602
 
@@ -76,9 +76,49 @@ function isExempt(filename: string): boolean {
76
76
  return EXEMPT_FILENAMES.includes(filename);
77
77
  }
78
78
 
79
- function isTestFile(filePath: string): boolean {
79
+ /**
80
+ * Test-file conventions this repository has to recognise.
81
+ *
82
+ * The first two were the only ones for a long time, and the cost was measured on a
83
+ * real .NET + JS repository (#859): 14 xunit `.cs` files, 15 `test/*.js` and 3
84
+ * `plugin/test/*.js` -- all runnable -- and `xp-gate test-layers` reported
85
+ * "Tests: 0 total". A gate that counts nothing reports 0% pairing, which reads as
86
+ * "this project has no tests" rather than "this gate cannot see them".
87
+ *
88
+ * Each entry is a convention, not a language check: the gate does not care what a
89
+ * file IS, only that its path says "test". Adding a convention here is how a new
90
+ * ecosystem becomes visible; leaving it out is how it silently stays at zero.
91
+ */
92
+ const TEST_FILE_PATTERNS: RegExp[] = [
93
+ // JS/TS littered, in-tree: foo.test.ts, foo.spec.js
94
+ /\.(?:test|spec)\.(?:ts|tsx|js|jsx|mjs|cjs)$/,
95
+ // A file inside a test DIRECTORY: test/foo.js, tests/a/b.py, plugin/test/x.js.
96
+ // The segment must stand alone, so `latest/` and `contest/` do not match.
97
+ /(?:^|\/)(?:__tests__|tests?|specs?|testcases?)(?:\/|$)/,
98
+ // Python: test_foo.py, foo_test.py
99
+ /(?:^|\/)test_[^/]*\.py$|_test\.py$/,
100
+ // .NET: xunit/nunit/mstest conventions, plus the namespace suffix.
101
+ /(?:^|\/)[A-Za-z0-9_.]*Tests?\.cs$/,
102
+ // Go: foo_test.go and anything inside a testdata directory.
103
+ /_test\.go$/,
104
+ // Java/Kotlin: FooTest.java, FooIT.kt, FooSpec.kt
105
+ /(?:Test|Tests|IT|Spec)\.(?:java|kt|kts|scala)$/,
106
+ // Shell: *.bats and *-verify.sh suites.
107
+ /\.bats$|[-_]verify\.sh$/,
108
+ // Ruby: foo_spec.rb and spec/ directories (covered by the segment rule above).
109
+ /_spec\.rb$/,
110
+ ];
111
+
112
+ /**
113
+ * Whether this path is a test, by any convention the gate knows.
114
+ *
115
+ * A path is a test if its FILENAME matches, or if it sits under a test directory.
116
+ * Both halves matter: `test/helpers.js` has no marker in its name, and
117
+ * `src/a/foo.test.ts` has no test directory.
118
+ */
119
+ export function isTestFile(filePath: string): boolean {
80
120
  const normalized = filePath.replace(/\\/g, '/');
81
- return /\.test\.(ts|js)$/.test(normalized) || /\.spec\.(ts|js)$/.test(normalized);
121
+ return TEST_FILE_PATTERNS.some((re) => re.test(normalized));
82
122
  }
83
123
 
84
124
  /** The layer a test file belongs to. */
@@ -205,15 +245,24 @@ function isSkippedDirectory(entry: fs.Dirent): boolean {
205
245
  return entry.isDirectory() && SKIPPED_DIRECTORIES.has(entry.name);
206
246
  }
207
247
 
208
- /** Extensions the layer analysis reads. */
209
- const SCANNED_EXTENSIONS = ['.ts', '.js'];
210
-
211
248
  /**
212
- * Whether this file is one the scan reports.
249
+ * Extensions the layer analysis reads.
213
250
  *
214
- * `.tsx` and `.jsx` are deliberately absent: the layer analysis pairs a source with a
215
- * test by NAME, and the JSX extensions never appeared in the sets it was built for.
251
+ * `.ts` and `.js` alone made the gate blind to every other ecosystem, and the
252
+ * blindness was silent: a .NET repository's 14 xunit `.cs` files were not
253
+ * "skipped", they were never a candidate, so the report said "Tests: 0 total".
254
+ *
255
+ * The list now covers the ecosystems `isTestFile` recognises. Pairing is still by
256
+ * NAME, which is why the additions are the languages whose test conventions put
257
+ * the name in the filename (`FooTests.cs`, `foo_test.go`, `FooTest.java`).
258
+ *
259
+ * `.tsx` and `.jsx` stay absent: they never appeared in the sets this analysis was
260
+ * built for, and adding an extension whose tests are not named after their source
261
+ * would create unpaired entries rather than pairing them.
216
262
  */
263
+ const SCANNED_EXTENSIONS = ['.ts', '.js', '.cs', '.go', '.py', '.java', '.kt', '.rb', '.bats', '.sh'];
264
+
265
+ /** Whether this file is one the scan reports. */
217
266
  function isScannableSource(name: string): boolean {
218
267
  return SCANNED_EXTENSIONS.some((ext) => name.endsWith(ext));
219
268
  }
@@ -470,9 +519,45 @@ function countNeedingTests(sourceFiles: string[]): number {
470
519
  return sourceFiles.filter((f) => !isExempt(path.basename(f)) && !isPairingOutOfScope(f)).length;
471
520
  }
472
521
 
522
+ /**
523
+ * Where tests are looked for, in addition to `src/`.
524
+ *
525
+ * `src/` alone was the scan root, so a repository keeping its tests beside the
526
+ * code -- `tests/`, `test/`, `plugin/test/`, `spec/` -- had them counted as
527
+ * nothing at all (#859). The measured case: 14 xunit `.cs`, 15 `test/*.js` and 3
528
+ * `plugin/test/*.js`, all runnable, reported as "Tests: 0 total".
529
+ *
530
+ * Only directories that EXIST are scanned, so this costs nothing on a repository
531
+ * that keeps everything under `src/`. `plugin/` is listed because plugin layouts
532
+ * put their tests one level down (`plugin/test/`), which the segment rule then
533
+ * recognises.
534
+ */
535
+ const TEST_ROOT_CANDIDATES = ['tests', 'test', 'spec', 'specs', 'plugin', '__tests__'];
536
+
537
+ /**
538
+ * Files from test roots outside `src/` that actually exist.
539
+ *
540
+ * Each entry is prefixed with its own directory so the path keeps the segment the
541
+ * classifier keys on. A missing directory contributes nothing rather than an
542
+ * error: most repositories have only `src/`, and a gate that fails on an absent
543
+ * conventional directory would fail everywhere.
544
+ */
545
+ function collectAdditionalTestRoots(dir: string): string[] {
546
+ const out: string[] = [];
547
+ for (const root of TEST_ROOT_CANDIDATES) {
548
+ const full = path.join(dir, root);
549
+ if (!fs.existsSync(full)) continue;
550
+ for (const rel of scanDirectory(full)) out.push(path.join(root, rel));
551
+ }
552
+ return out;
553
+ }
554
+
473
555
  export function analyzeTestLayers(cwd?: string): TestLayerReport {
474
556
  const dir = cwd || process.cwd();
475
- const allFiles = scanDirectory(path.join(dir, 'src'));
557
+ const allFiles = [
558
+ ...scanDirectory(path.join(dir, 'src')),
559
+ ...collectAdditionalTestRoots(dir),
560
+ ];
476
561
 
477
562
  const { sourceFiles, testFiles } = splitSourcesAndTests(allFiles);
478
563
  const shellOutsideSrc = shellSuitesOutside(testFiles, dir);
package/hooks/gate-3.sh CHANGED
@@ -737,10 +737,37 @@ LIZARD_LENGTH_MAX="${LIZARD_LENGTH_MAX:-1000}"
737
737
  # Columns (lizard --csv): 1 NLOC, 2 CCN, 3 token, 4 PARAM, 5 length.
738
738
  # LENGTH_MAX is lizard's own 1000, so this reports what lizard reports
739
739
  # rather than inventing a second opinion. CCN still decides on its own.
740
+ # #747: lizard does NOT fail on source it cannot parse. Measured with lizard
741
+ # 1.25 on this host:
742
+ #
743
+ # printf 'function broken( {\n if (a) {\n' > bad.ts
744
+ # lizard --csv bad.ts -> 2,2,7,1,2,"broken@1-2@bad.ts",...,"broken ( {} if ( a )",1,2
745
+ # exit code: 0
746
+ #
747
+ # A two-line fragment that is not valid TypeScript came back as a function with
748
+ # CCN 2 -- indistinguishable, in the columns read below, from a genuine small
749
+ # function. Counting it would score a failed parse as a clean result.
750
+ #
751
+ # The signal that IS in the CSV: column 9 is the signature, and a parse that
752
+ # stopped at a brace leaves the brace in it.
753
+ #
754
+ # unparsed: "broken ( {} if ( a )" <- a `{` where the parameter list was
755
+ # parsed: "f ( a )"
756
+ #
757
+ # Rows like that are counted SEPARATELY and reported, never folded into the
758
+ # warning count -- a number produced by a failed parse is not a low number, it
759
+ # is no number.
760
+ CC_UNPARSED_ROWS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, '
761
+ NF > 1 && $9 ~ /[{}]/ { c++ }
762
+ END { print c + 0 }
763
+ ')
740
764
  CC_WARNINGS=$(printf '%s\n' "$CC_CSV_FLAT" | awk -F, -v t="$CCN_THRESHOLD" -v lenmax="$LIZARD_LENGTH_MAX" '
741
- NF > 1 && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
765
+ NF > 1 && $9 !~ /[{}]/ && ($2 + 0 > t + 0 || $5 + 0 > lenmax + 0) { c++ }
742
766
  END { print c + 0 }
743
767
  ')
768
+ if [ "${CC_UNPARSED_ROWS:-0}" -gt 0 ]; then
769
+ echo " ⚠ lizard could not parse ${CC_UNPARSED_ROWS} function(s) — their complexity was NOT evaluated (#747)"
770
+ fi
744
771
  # A lizard that produced no parsable row must not read as "clean". Without
745
772
  # this, a crashing or mis-invoked lizard yields 0 warnings and the gate
746
773
  # reports PASSED on zero analysed functions -- the same silent-success
@@ -161,7 +161,24 @@ LAYER_TSV=$(awk '
161
161
  listkey = ""
162
162
  next
163
163
  }
164
- if (indent == layerindent && body ~ /^- /) { next }
164
+ # #811: a `- name: X` line at the layer indent STARTS a layer in the sequence form
165
+ # (`layers:` followed by `- name:` items) and must not be skipped. The previous
166
+ # `{ next }` dropped every such line, so the standard spelling parsed to zero layers
167
+ # and the gate reported `layer_config_unparsable` on a config that was perfectly
168
+ # valid -- the verdict depended on how the file was written, not on the code.
169
+ #
170
+ # Both destructuring shapes are accepted: `- name: X` (the name rides on the dash)
171
+ # and `-` alone followed by an indented `name:` line.
172
+ if (indent == layerindent && body ~ /^- /) {
173
+ if (body ~ /^-[ \t]*name:[ \t]*/) {
174
+ flush()
175
+ name = unq(substr(body, index(body, ":") + 1))
176
+ listkey = ""
177
+ }
178
+ # A bare `-` opens a record whose `name:` comes on the next, deeper line; the
179
+ # existing `^name:` branch below picks it up once `layerindent` advances.
180
+ next
181
+ }
165
182
  if (name == "") next
166
183
  if (body ~ /^name:/) { name = unq(substr(body, 6)) }
167
184
  # `pattern:` and `patterns:` are both accepted. The singular form is the one
@@ -70,6 +70,27 @@ if [ -n "$SPRINT_GATE_SCRIPT" ]; then
70
70
 
71
71
  if [ "$SPRINT_GATE_EXIT" -ne 0 ]; then
72
72
  GATE_11_STATUS="BLOCK"
73
+ # #806: a sprint gate that does not implement --pre-commit cannot ANSWER the question;
74
+ # it has not judged the commit. Reporting both cases as "sprint gate denied" told a
75
+ # consumer whose vendored copy only implements --pre-push that every commit violated
76
+ # sprint flow, and the echoed usage listing just `--pre-push` made the reader think
77
+ # they had mistyped the flag.
78
+ #
79
+ # It still BLOCKS. Refusing to block would let a stale copy silently switch the gate
80
+ # off -- the opposite failure, and the one this repository keeps fixing.
81
+ if printf '%s' "$SPRINT_GATE_OUTPUT" | grep -qiE 'usage:|unrecognized|unknown option|invalid option'; then
82
+ GATE_11_DETAIL="sprint-gate.sh does not support --pre-commit"
83
+ echo "❌ BLOCKED - Gate 11: Sprint Flow (${GATE_11_DETAIL})"
84
+ echo " resolved: $SPRINT_GATE_SCRIPT"
85
+ echo " That copy does not implement the mode Gate 11 calls, so it cannot answer a"
86
+ echo " pre-commit question. This is NOT a sprint-state violation."
87
+ echo " Project-first resolution prefers a repo-vendored githooks/sprint-gate.sh, so a"
88
+ echo " stale vendored copy wins over the global one — update it, or remove it and"
89
+ echo " run 'xp-gate doctor --sync-hooks'."
90
+ printf '%s\n' "$SPRINT_GATE_OUTPUT" | sed 's/^/ /'
91
+ record_gate_audit "gate-11" "sprint-flow" "$GATE_11_STATUS" "1" "$GATE_11_START" "$GATE_11_DETAIL"
92
+ return 1
93
+ fi
73
94
  echo "❌ BLOCKED - Gate 11: Sprint Flow (${SPRINT_GATE_DETAIL:-sprint gate denied})"
74
95
  printf '%s\n' "$SPRINT_GATE_OUTPUT" | sed 's/^/ /'
75
96
  record_gate_audit "gate-11" "sprint-flow" "$GATE_11_STATUS" "1" "$GATE_11_START" "${GATE_11_DETAIL:-}"
@@ -82,6 +82,21 @@ else
82
82
  done <<EOF_CHANGED
83
83
  $CHANGED_FILES
84
84
  EOF_CHANGED
85
+ # No scannable file means jscpd would be invoked with NO path argument, and it
86
+ # then defaults to scanning the whole tree. Measured 2026-12-01: a commit whose
87
+ # only staged file was `package.json` (an extension jscpd's --format set does
88
+ # not cover) left this list empty, so jscpd scanned every file in the repository
89
+ # -- still running after 7 minutes, against a documented 6-7 SECOND baseline for
90
+ # a normal scan. The `no_files` branch below cannot catch it: that branch is only
91
+ # reached after jscpd RUNS, and with no argument it runs for minutes before
92
+ # saying anything. Deciding here keeps the cost proportional to the change.
93
+ if [ -z "${JSCPD_SCAN_FILES// /}" ]; then
94
+ echo "⏭️ SKIPPED - Duplicate code (no changed file is in jscpd's format set)"
95
+ echo " Decided BEFORE the scan: with no path argument jscpd scans the whole tree."
96
+ GATE_2_STATUS="SKIP"
97
+ GATE_2_DETAIL="no_changed_file_in_jscpd_format"
98
+ return 0
99
+ fi
85
100
  JSCPD_OUTPUT=$(mktemp)
86
101
  JSCPD_EXIT=0
87
102
  # shellcheck disable=SC2086 # pre-existing splitting of the file list; #477/#591 change the scan set, not the splitting
package/hooks/install.sh CHANGED
@@ -38,11 +38,17 @@ TARGET_GITHOOKS="$PROJECT_ROOT/githooks"
38
38
  echo "Installing OpenCode quality gates..."
39
39
  echo ""
40
40
 
41
+ # #805: collect first, chmod once. On Windows/Git Bash every external command costs
42
+ # ~106 ms of process creation ALONE (measured: `bash -c true` = 106 ms, `bash -c chmod`
43
+ # = 144 ms), and the three deploy lists hold 60 files -- so a per-file `chmod` was 60
44
+ # invocations, ~9 s of the 17-20 s the script took. The cost is the NUMBER of commands,
45
+ # not their work, so the fix is to issue fewer.
46
+ _CHMOD_TARGETS=()
41
47
  for hook in "${DEPLOY_HOOK_FILES[@]}"; do
42
48
  src="$HOOKS_DIR/$hook"
43
49
  if [ -f "$src" ]; then
44
50
  cp "$src" "$TARGET_HOOKS/$hook"
45
- chmod +x "$TARGET_HOOKS/$hook"
51
+ _CHMOD_TARGETS+=("$TARGET_HOOKS/$hook")
46
52
  echo " + $hook ($HOOKS_DIR/$hook) -> .git/hooks/"
47
53
  fi
48
54
  done
@@ -73,7 +79,7 @@ for gate in "${DEPLOY_GATE_FILES[@]}" hook-module-resolution.sh; do
73
79
  src="$HOOKS_DIR/$gate"
74
80
  if [ -f "$src" ]; then
75
81
  cp "$src" "$TARGET_HOOKS/$gate"
76
- chmod +x "$TARGET_HOOKS/$gate"
82
+ _CHMOD_TARGETS+=("$TARGET_HOOKS/$gate")
77
83
  echo " + $gate ($HOOKS_DIR/$gate) -> .git/hooks/"
78
84
  fi
79
85
  done
@@ -97,11 +103,17 @@ for module in "${DEPLOY_MODULE_FILES[@]}"; do
97
103
  if [ -f "$src" ]; then
98
104
  mkdir -p "$TARGET_HOOKS/$(dirname "$module")"
99
105
  cp "$src" "$TARGET_HOOKS/$module"
100
- chmod +x "$TARGET_HOOKS/$module"
106
+ _CHMOD_TARGETS+=("$TARGET_HOOKS/$module")
101
107
  echo " + $module -> .git/hooks/$module"
102
108
  fi
103
109
  done
104
110
 
111
+ # #805: one invocation for the whole set. `|| true` because a single unreadable file must
112
+ # not abort an install that has already copied everything.
113
+ if [ ${#_CHMOD_TARGETS[@]} -gt 0 ]; then
114
+ chmod +x "${_CHMOD_TARGETS[@]}" 2>/dev/null || true
115
+ fi
116
+
105
117
  if [ -d "$TARGET_GITHOOKS" ]; then
106
118
  if [ "$1" != "--force" ]; then
107
119
  mkdir -p "$TARGET_GITHOOKS/adapters"