@boyingliu01/xp-gate 0.38.82 → 0.38.84

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 (31) hide show
  1. package/adapters/gate-4.sh +44 -0
  2. package/adapters/python.sh +27 -1
  3. package/gate-4.sh +44 -0
  4. package/hooks/gate-4.sh +44 -0
  5. package/lib/__tests__/crap.test.js +173 -0
  6. package/lib/crap-cli.js +51 -5
  7. package/lib/crap.js +47 -1
  8. package/lib/mattpocock-license-verdict.json +1 -1
  9. package/lib/principles.js +11 -1
  10. package/package.json +1 -1
  11. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  12. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  13. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  14. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  15. package/plugins/dsh/package.json +1 -1
  16. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  17. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  18. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  19. package/plugins/opencode/package.json +1 -1
  20. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  21. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  22. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  23. package/plugins/qoder/plugin.json +1 -1
  24. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  25. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  26. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  27. package/principles/adapters/base.ts +30 -1
  28. package/principles/analyzer.ts +9 -0
  29. package/skills/delphi-review/AGENTS.md +1 -1
  30. package/skills/sprint-flow/AGENTS.md +1 -1
  31. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -219,6 +219,50 @@ else
219
219
  ERROR_COUNT=${ERROR_COUNT:-0}
220
220
  WARNING_COUNT=$(grep -cE '"severity"[[:space:]]*:[[:space:]]*"warning"' "$PRINCIPLES_JSON" 2>/dev/null || true)
221
221
  WARNING_COUNT=${WARNING_COUNT:-0}
222
+
223
+ # Languages the checker COULD NOT read. The reporter has always printed
224
+ # this to the console ("⚠️ NOT ANALYSED: python — an adapter exists but no
225
+ # clean-code rule can read it"), and the JSON has always carried it in
226
+ # summary.unanalysedLanguages. The gate read neither, so a commit whose
227
+ # only changed file was a .py went out as
228
+ #
229
+ # {"name":"Clean Code + SOLID","status":"PASS","reason":"","warnings":0}
230
+ #
231
+ # MEASURED 2026-11-22 on a probe repo holding one .py file: the commit
232
+ # console showed NOT ANALYSED, the report recorded PASS with an empty
233
+ # reason, and nothing in the journal distinguished that from a commit
234
+ # whose TypeScript was genuinely reviewed.
235
+ #
236
+ # This is the family's exact shape -- "not checked" recorded as "passed"
237
+ # -- one level down from the verdict: the verdict is honest on the console
238
+ # and dishonest in the record a later reader actually consults.
239
+ #
240
+ # The status stays PASS rather than SKIP: some files WERE analysed, and
241
+ # demoting a real review to SKIP because a sibling file's language has no
242
+ # rules would trade one wrong record for another. What must survive is the
243
+ # REASON, which is what this assignment adds.
244
+ # The reporter pretty-prints with `JSON.stringify(out, null, 2)`, so the
245
+ # array arrives SPLIT ACROSS LINES:
246
+ #
247
+ # "unanalysedLanguages": [
248
+ # "python"
249
+ # ]
250
+ #
251
+ # A single-line `sed` range silently matches nothing and the bug would
252
+ # look fixed while recording nothing -- the exact failure this change
253
+ # exists to remove. Flatten first, then extract; both steps are needed.
254
+ _PJ_FLAT=$(tr -d "
255
+ " < "$PRINCIPLES_JSON" 2>/dev/null | tr -s " ")
256
+ UNANALYSED_LANGS=$(printf '%s' "$_PJ_FLAT" \
257
+ | sed -n 's/.*"unanalysedLanguages"[[:space:]]*:[[:space:]]*\[\([^]]*\)\].*/\1/p' \
258
+ | tr -d '"' | tr ',' ' ' | tr -s ' ' | sed 's/^ *//; s/ *$//')
259
+ unset _PJ_FLAT
260
+ if [ -n "$UNANALYSED_LANGS" ]; then
261
+ echo "⚠️ Not analysed: ${UNANALYSED_LANGS} — an adapter exists but no clean-code rule reads it."
262
+ echo " Those files were NOT checked; this PASS covers only the rest."
263
+ GATE_4_REASON="unanalysed:${UNANALYSED_LANGS// /,}"
264
+ fi
265
+
222
266
  rm -f "$PRINCIPLES_JSON"
223
267
 
224
268
  if [ "$ERROR_COUNT" -gt 0 ]; then
@@ -30,7 +30,10 @@ unset _ac_candidate
30
30
  # scope declaration may name a single .py file.
31
31
  _mypy_target_usable() {
32
32
  [ -e "$1" ] || return 1
33
- [ -n "$(find "$1" -name '*.py' -print 2>/dev/null | grep .)" ]
33
+ # SC2143: the exit status IS the answer, so `grep -q` -- it also stops at the
34
+ # first hit instead of buffering every match in a large target. No `-print`
35
+ # needed either: grep only needs to know that a line exists.
36
+ find "$1" -name '*.py' 2>/dev/null | grep -q .
34
37
  }
35
38
 
36
39
  run_static_analysis() {
@@ -233,6 +236,29 @@ run_tests() {
233
236
  return $PYTEST_EXIT
234
237
  }
235
238
 
239
+ # run_coverage() below executes and judges every test: `pytest ... --cov=src`
240
+ # runs the suite, sets PYTEST_EXIT, and returns 1 on any of the three non-verdict
241
+ # arms it already inspects. So the separate run_tests() pass adds no verdict,
242
+ # only a second full pytest start.
243
+ #
244
+ # MEASURED 2026-11-20 on this machine, a probe repo holding ONE test:
245
+ #
246
+ # run_tests 7016 / 10669 / 15237 ms (pytest -n auto, no --cov)
247
+ # run_coverage 16660 / 11221 / 14485 ms (pytest -n auto --cov=src)
248
+ # both 23676 / 21890 / 29722 ms
249
+ #
250
+ # The suite is ONE test. Half of that wall clock was the same two-second test
251
+ # being started twice, and the proportion only grows on a repo whose tests are
252
+ # fast: what dominates is pytest start-up plus, on Windows, xdist spawning one
253
+ # worker per core (a single test went from 3935 ms serial to 10604 ms under
254
+ # `-n auto`, so the parallelism is itself a cost at small test counts).
255
+ #
256
+ # Which is why the declaration matters most HERE: python's tests are commonly the
257
+ # cheapest per commit, so the doubled start-up is the largest share of its cost.
258
+ #
259
+ # Undeclared adapters keep the safe double-run default -- see adapter-common.sh.
260
+ coverage_runs_tests() { return 0; }
261
+
236
262
  run_coverage() {
237
263
  require_tool pytest "pytest" || return 1
238
264
 
package/gate-4.sh CHANGED
@@ -219,6 +219,50 @@ else
219
219
  ERROR_COUNT=${ERROR_COUNT:-0}
220
220
  WARNING_COUNT=$(grep -cE '"severity"[[:space:]]*:[[:space:]]*"warning"' "$PRINCIPLES_JSON" 2>/dev/null || true)
221
221
  WARNING_COUNT=${WARNING_COUNT:-0}
222
+
223
+ # Languages the checker COULD NOT read. The reporter has always printed
224
+ # this to the console ("⚠️ NOT ANALYSED: python — an adapter exists but no
225
+ # clean-code rule can read it"), and the JSON has always carried it in
226
+ # summary.unanalysedLanguages. The gate read neither, so a commit whose
227
+ # only changed file was a .py went out as
228
+ #
229
+ # {"name":"Clean Code + SOLID","status":"PASS","reason":"","warnings":0}
230
+ #
231
+ # MEASURED 2026-11-22 on a probe repo holding one .py file: the commit
232
+ # console showed NOT ANALYSED, the report recorded PASS with an empty
233
+ # reason, and nothing in the journal distinguished that from a commit
234
+ # whose TypeScript was genuinely reviewed.
235
+ #
236
+ # This is the family's exact shape -- "not checked" recorded as "passed"
237
+ # -- one level down from the verdict: the verdict is honest on the console
238
+ # and dishonest in the record a later reader actually consults.
239
+ #
240
+ # The status stays PASS rather than SKIP: some files WERE analysed, and
241
+ # demoting a real review to SKIP because a sibling file's language has no
242
+ # rules would trade one wrong record for another. What must survive is the
243
+ # REASON, which is what this assignment adds.
244
+ # The reporter pretty-prints with `JSON.stringify(out, null, 2)`, so the
245
+ # array arrives SPLIT ACROSS LINES:
246
+ #
247
+ # "unanalysedLanguages": [
248
+ # "python"
249
+ # ]
250
+ #
251
+ # A single-line `sed` range silently matches nothing and the bug would
252
+ # look fixed while recording nothing -- the exact failure this change
253
+ # exists to remove. Flatten first, then extract; both steps are needed.
254
+ _PJ_FLAT=$(tr -d "
255
+ " < "$PRINCIPLES_JSON" 2>/dev/null | tr -s " ")
256
+ UNANALYSED_LANGS=$(printf '%s' "$_PJ_FLAT" \
257
+ | sed -n 's/.*"unanalysedLanguages"[[:space:]]*:[[:space:]]*\[\([^]]*\)\].*/\1/p' \
258
+ | tr -d '"' | tr ',' ' ' | tr -s ' ' | sed 's/^ *//; s/ *$//')
259
+ unset _PJ_FLAT
260
+ if [ -n "$UNANALYSED_LANGS" ]; then
261
+ echo "⚠️ Not analysed: ${UNANALYSED_LANGS} — an adapter exists but no clean-code rule reads it."
262
+ echo " Those files were NOT checked; this PASS covers only the rest."
263
+ GATE_4_REASON="unanalysed:${UNANALYSED_LANGS// /,}"
264
+ fi
265
+
222
266
  rm -f "$PRINCIPLES_JSON"
223
267
 
224
268
  if [ "$ERROR_COUNT" -gt 0 ]; then
package/hooks/gate-4.sh CHANGED
@@ -219,6 +219,50 @@ else
219
219
  ERROR_COUNT=${ERROR_COUNT:-0}
220
220
  WARNING_COUNT=$(grep -cE '"severity"[[:space:]]*:[[:space:]]*"warning"' "$PRINCIPLES_JSON" 2>/dev/null || true)
221
221
  WARNING_COUNT=${WARNING_COUNT:-0}
222
+
223
+ # Languages the checker COULD NOT read. The reporter has always printed
224
+ # this to the console ("⚠️ NOT ANALYSED: python — an adapter exists but no
225
+ # clean-code rule can read it"), and the JSON has always carried it in
226
+ # summary.unanalysedLanguages. The gate read neither, so a commit whose
227
+ # only changed file was a .py went out as
228
+ #
229
+ # {"name":"Clean Code + SOLID","status":"PASS","reason":"","warnings":0}
230
+ #
231
+ # MEASURED 2026-11-22 on a probe repo holding one .py file: the commit
232
+ # console showed NOT ANALYSED, the report recorded PASS with an empty
233
+ # reason, and nothing in the journal distinguished that from a commit
234
+ # whose TypeScript was genuinely reviewed.
235
+ #
236
+ # This is the family's exact shape -- "not checked" recorded as "passed"
237
+ # -- one level down from the verdict: the verdict is honest on the console
238
+ # and dishonest in the record a later reader actually consults.
239
+ #
240
+ # The status stays PASS rather than SKIP: some files WERE analysed, and
241
+ # demoting a real review to SKIP because a sibling file's language has no
242
+ # rules would trade one wrong record for another. What must survive is the
243
+ # REASON, which is what this assignment adds.
244
+ # The reporter pretty-prints with `JSON.stringify(out, null, 2)`, so the
245
+ # array arrives SPLIT ACROSS LINES:
246
+ #
247
+ # "unanalysedLanguages": [
248
+ # "python"
249
+ # ]
250
+ #
251
+ # A single-line `sed` range silently matches nothing and the bug would
252
+ # look fixed while recording nothing -- the exact failure this change
253
+ # exists to remove. Flatten first, then extract; both steps are needed.
254
+ _PJ_FLAT=$(tr -d "
255
+ " < "$PRINCIPLES_JSON" 2>/dev/null | tr -s " ")
256
+ UNANALYSED_LANGS=$(printf '%s' "$_PJ_FLAT" \
257
+ | sed -n 's/.*"unanalysedLanguages"[[:space:]]*:[[:space:]]*\[\([^]]*\)\].*/\1/p' \
258
+ | tr -d '"' | tr ',' ' ' | tr -s ' ' | sed 's/^ *//; s/ *$//')
259
+ unset _PJ_FLAT
260
+ if [ -n "$UNANALYSED_LANGS" ]; then
261
+ echo "⚠️ Not analysed: ${UNANALYSED_LANGS} — an adapter exists but no clean-code rule reads it."
262
+ echo " Those files were NOT checked; this PASS covers only the rest."
263
+ GATE_4_REASON="unanalysed:${UNANALYSED_LANGS// /,}"
264
+ fi
265
+
222
266
  rm -f "$PRINCIPLES_JSON"
223
267
 
224
268
  if [ "$ERROR_COUNT" -gt 0 ]; then
@@ -319,3 +319,176 @@ describe('#858 discoverCoverageFile', () => {
319
319
  expect(discoverCoverageFile('/tmp/explicit.json')).toBe('/tmp/explicit.json');
320
320
  });
321
321
  });
322
+
323
+ /**
324
+ * @test REQ-CRAP-858-B join a coverage summary that only names basenames
325
+ * @intent 0.38.79.0 taught readFileCoverage to parse Node's
326
+ * coverage-summary.json, and the user's real project still reported
327
+ * "measured 0 functions". The parse was fine; the JOIN was impossible.
328
+ *
329
+ * Node writes the key as the BASENAME only:
330
+ *
331
+ * coverage/coverage-summary.json keys : agents.mjs
332
+ * lizard --csv path : scripts\lib\agents.mjs
333
+ *
334
+ * No path-based match can ever hit that, and lizard's backslashes break
335
+ * even a name that did carry a directory. So the file was measured,
336
+ * the coverage was read, and every function still came out unmeasured.
337
+ *
338
+ * Two rules the fallback must obey, both learned from the issue:
339
+ * 1. exact normalised path first -- basename is only a fallback;
340
+ * 2. a basename that maps to MORE THAN ONE file is ambiguous, and an
341
+ * ambiguous match must be recorded as unmeasured, never guessed.
342
+ * Guessing would attribute A's coverage to B and silently produce a
343
+ * wrong CRAP ranking, which is worse than saying "not measured".
344
+ * @covers AC-858-07 basename keys join to nested paths
345
+ * @covers AC-858-08 backslash paths normalise on both sides
346
+ * @covers AC-858-09 an ambiguous basename is not guessed
347
+ * @covers AC-858-10 all-unmeasured output is NOT_CHECKED, never a green tick
348
+ */
349
+ describe('#858 a basename-only summary still joins, and ambiguity is not guessed', () => {
350
+ const { readFileCoverage, joinCoverage } = require('../crap.js');
351
+
352
+ const lizard = (file, ccn = 8) => ({ file, name: 'f', ccn, line: 1 });
353
+
354
+ function summaryFile(obj) {
355
+ const p = path.join(os.tmpdir(), `cov858b-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
356
+ fs.writeFileSync(p, JSON.stringify(obj));
357
+ return p;
358
+ }
359
+
360
+ it('AC-858-07: a basename key joins to a nested lizard path', () => {
361
+ // The exact shape the issue measured.
362
+ const file = summaryFile({
363
+ total: { lines: { total: 1, covered: 1, pct: 100 } },
364
+ 'agents.mjs': { functions: { total: 4, covered: 1, pct: 25 } },
365
+ });
366
+ const joined = joinCoverage(
367
+ [lizard('scripts\\lib\\agents.mjs')],
368
+ readFileCoverage(file),
369
+ );
370
+ expect(joined[0].cov).toBeCloseTo(0.25, 5);
371
+ });
372
+
373
+ it('AC-858-08: absolute and relative spellings normalise to the same key', () => {
374
+ const file = summaryFile({
375
+ total: { lines: { total: 1, covered: 1, pct: 100 } },
376
+ 'C:/repo/src/lib/x.mjs': { functions: { total: 2, covered: 2, pct: 100 } },
377
+ });
378
+ const joined = joinCoverage([lizard('C:\\repo\\src\\lib\\x.mjs')], readFileCoverage(file));
379
+ expect(joined[0].cov).toBeCloseTo(1, 5);
380
+ });
381
+
382
+ it('AC-858-09: an ambiguous basename is left unmeasured, not guessed', () => {
383
+ // Two distinct files called util.mjs, but the summary names only one.
384
+ // Attributing that coverage to the other would silently mis-rank it.
385
+ const file = summaryFile({
386
+ total: { lines: { total: 1, covered: 1, pct: 100 } },
387
+ 'util.mjs': { functions: { total: 2, covered: 0, pct: 0 } },
388
+ });
389
+ const joined = joinCoverage(
390
+ [lizard('src/a/util.mjs'), lizard('src/b/util.mjs')],
391
+ readFileCoverage(file),
392
+ );
393
+ for (const row of joined) {
394
+ expect(row.cov, `${row.file} must stay unmeasured`).toBeNull();
395
+ }
396
+ });
397
+
398
+ it('AC-858-09b: an exact path match still wins over an ambiguous basename', () => {
399
+ // src/a/util.mjs is named in full, so it IS measured even though the bare
400
+ // basename is ambiguous. Precision beats the fallback.
401
+ const file = summaryFile({
402
+ total: { lines: { total: 1, covered: 1, pct: 100 } },
403
+ 'src/a/util.mjs': { functions: { total: 2, covered: 1, pct: 50 } },
404
+ });
405
+ const joined = joinCoverage(
406
+ [lizard('src/a/util.mjs'), lizard('src/b/util.mjs')],
407
+ readFileCoverage(file),
408
+ );
409
+ expect(joined[0].cov).toBeCloseTo(0.5, 5);
410
+ expect(joined[1].cov).toBeNull();
411
+ });
412
+ });
413
+
414
+ /**
415
+ * @test REQ-CRAP-858-C an all-unmeasured run is not a pass
416
+ * @intent The last item in the issue's acceptance table, and the one it called
417
+ * "the thing most worth fixing": when no function has coverage, the
418
+ * report printed
419
+ *
420
+ * measured 0 functions, 1 unmeasured
421
+ * ✅ Nothing at or above CRAP 6.
422
+ *
423
+ * A green tick over a ranking that never happened. The reader is told the
424
+ * code is fine when the truth is that nothing was measured -- the same
425
+ * "not checked rendered as passed" defect as #732, in the one place the
426
+ * issue says matters most.
427
+ * @covers AC-858-10 all-unmeasured renders NOT_CHECKED with a reason
428
+ */
429
+ describe('#858 an all-unmeasured ranking is NOT_CHECKED, not a green tick', () => {
430
+ const { render } = require('../crap-cli.js');
431
+
432
+ const opts = { paths: ['src'], threshold: 6, top: 20 };
433
+
434
+ it('AC-858-10: measured 0 renders NOT_CHECKED and no success tick', () => {
435
+ const text = render({ measured: 0, unmeasured: 3, threshold: 6, hotspots: [] }, opts);
436
+ expect(text).toContain('NOT_CHECKED');
437
+ // The tick is the actual defect; asserting its absence is the point.
438
+ expect(text).not.toContain('✅');
439
+ expect(text).not.toContain('Nothing at or above');
440
+ });
441
+
442
+ it('AC-858-10b: a real measurement with no hotspots still says so plainly', () => {
443
+ // Anti-vacuity: measured work that found nothing must remain a clean result,
444
+ // otherwise the fix just replaces one wrong message with another.
445
+ const text = render({ measured: 2, unmeasured: 0, threshold: 6, hotspots: [] }, opts);
446
+ expect(text).toContain('Nothing at or above CRAP 6');
447
+ expect(text).not.toContain('NOT_CHECKED');
448
+ });
449
+ });
450
+
451
+ /**
452
+ * @test REQ-CRAP-858-D the scan target is discovered, not assumed to be src
453
+ * @intent `--paths` defaulted to `src`. On a project whose code lives in
454
+ * `scripts/` -- the reporter's own repo, and every Node ESM package laid
455
+ * out that way -- that produced
456
+ *
457
+ * No functions found. Check that lizard is installed and --paths
458
+ * points at real code: lizard --csv -C 99999 src
459
+ *
460
+ * for a repository full of analysable code. The message made the user
461
+ * guess what to type next; the tool could have looked.
462
+ * @covers AC-858-11 conventional roots are discovered, and explicit --paths wins
463
+ */
464
+ describe('#858 discoverSourcePaths', () => {
465
+ const fs = require('fs');
466
+ const os = require('os');
467
+ const path = require('path');
468
+ const { discoverSourcePaths } = require('../crap-cli.js');
469
+
470
+ let dir;
471
+ beforeEach(() => {
472
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'crap858d-'));
473
+ });
474
+ afterEach(() => {
475
+ fs.rmSync(dir, { recursive: true, force: true });
476
+ });
477
+
478
+ it('AC-858-11: finds scripts/ when there is no src/', () => {
479
+ fs.mkdirSync(path.join(dir, 'scripts'));
480
+ expect(discoverSourcePaths(dir)).toEqual(['scripts']);
481
+ });
482
+
483
+ it('AC-858-11b: finds several conventional roots at once', () => {
484
+ fs.mkdirSync(path.join(dir, 'src'));
485
+ fs.mkdirSync(path.join(dir, 'lib'));
486
+ expect(discoverSourcePaths(dir)).toEqual(['src', 'lib']);
487
+ });
488
+
489
+ it('AC-858-11c: falls back to the working directory, never to an empty list', () => {
490
+ // An empty list would make lizard scan nothing while the report claimed there
491
+ // was no code -- indistinguishable from a project that legitimately has none.
492
+ expect(discoverSourcePaths(dir)).toEqual(['.']);
493
+ });
494
+ });
package/lib/crap-cli.js CHANGED
@@ -65,14 +65,42 @@ function discoverCoverageFile(explicit, cwd) {
65
65
  return path.join(coverageDir, candidates[0]);
66
66
  }
67
67
 
68
+ /**
69
+ * Pick the source roots to scan when --paths was not given (#858).
70
+ *
71
+ * Hardcoding `src` made the command useless on any project whose code lives
72
+ * elsewhere -- the user's own repo keeps it in `scripts/`, and the report then
73
+ * said "No functions found ... --paths points at real code", leaving them to
74
+ * guess. The conventions below cover the layouts that actually occur:
75
+ *
76
+ * src, lib, scripts, app, packages, source (a directory)
77
+ * a single top-level entry file (bin/xp-gate.js style)
78
+ *
79
+ * Falls back to the working directory itself, which is what a caller who passed
80
+ * no flags most plausibly meant. Returning ['.'] rather than [] matters: an empty
81
+ * list makes lizard scan nothing and the report claim there is no code.
82
+ */
83
+ function discoverSourcePaths(cwd) {
84
+ const root = cwd || process.cwd();
85
+ const candidates = ['src', 'lib', 'scripts', 'app', 'packages', 'source'];
86
+ const found = candidates.filter(name => {
87
+ try {
88
+ return fs.statSync(path.join(root, name)).isDirectory();
89
+ } catch {
90
+ return false;
91
+ }
92
+ });
93
+ return found.length ? found : ['.'];
94
+ }
95
+
68
96
  function parseArgs(argv) {
69
97
  const opts = {
70
98
  top: 20,
71
99
  threshold: 6,
72
100
  json: false,
73
- // #858: discovered after parsing, not fixed here. `--coverage` still wins.
101
+ // #858: both discovered after parsing. `--coverage` and `--paths` still win.
74
102
  coverage: null,
75
- paths: ['src'],
103
+ paths: null,
76
104
  includeMirrors: false,
77
105
  help: false,
78
106
  };
@@ -156,6 +184,17 @@ function render(report, opts) {
156
184
 
157
185
  if (!report.hotspots.length) {
158
186
  lines.push('');
187
+ // #858: with nothing measured, "Nothing at or above CRAP 6" is a statement
188
+ // about a ranking that never happened, and the tick made it read as approval.
189
+ // Unmeasured functions are counted, not scored -- so an all-unmeasured run
190
+ // has no verdict to give, and must say that instead of implying a clean one.
191
+ if (!report.measured) {
192
+ lines.push('❌ NOT_CHECKED — no function had coverage, so nothing was ranked.');
193
+ lines.push(' This is not a clean result: every function above is unmeasured.');
194
+ lines.push(' A coverage summary was found, but no entry matched a scanned file.');
195
+ lines.push(' Check --paths and that the coverage file names the files you scanned.');
196
+ return lines.join('\n');
197
+ }
159
198
  lines.push(`✅ Nothing at or above CRAP ${report.threshold}.`);
160
199
  return lines.join('\n');
161
200
  }
@@ -180,14 +219,19 @@ async function handleCrap(argv) {
180
219
  return 0;
181
220
  }
182
221
 
222
+ // Both discoveries must run BEFORE lizard is invoked: the scan target is an
223
+ // input to it. (Placed after, `--paths` discovery had no effect at all and the
224
+ // command still scanned the literal default.)
225
+ opts.coverage = discoverCoverageFile(opts.coverage);
226
+
227
+ if (!opts.paths || !opts.paths.length) opts.paths = discoverSourcePaths();
228
+
183
229
  const csv = runLizard(opts.paths);
184
230
  if (csv === null) {
185
231
  console.error('✗ Could not run lizard. Install it with: pip install --user lizard');
186
232
  return 1;
187
233
  }
188
234
 
189
- opts.coverage = discoverCoverageFile(opts.coverage);
190
-
191
235
  if (!fs.existsSync(opts.coverage)) {
192
236
  // #858: name the artifact that WOULD have been accepted. A user on Node's own
193
237
  // runner is told "npx vitest run --coverage" and reasonably concludes CRAP
@@ -223,4 +267,6 @@ async function handleCrap(argv) {
223
267
  return 0;
224
268
  }
225
269
 
226
- module.exports = { handleCrap, parseArgs, render, runLizard, discoverCoverageFile };
270
+ module.exports = {
271
+ handleCrap, parseArgs, render, runLizard, discoverCoverageFile, discoverSourcePaths,
272
+ };
package/lib/crap.js CHANGED
@@ -101,9 +101,55 @@ function relativiseArtifactPath(absPath, root) {
101
101
  * @returns {Array<object>} each with `cov` and `crap` (either may be null)
102
102
  */
103
103
  function joinCoverage(functions, coverage) {
104
+ const map = coverage instanceof Map ? coverage : new Map();
105
+
106
+ // #858: build the basename index once, and record how many DISTINCT keys share
107
+ // each basename. A count above one means the summary cannot disambiguate, and
108
+ // guessing there would attribute one file's coverage to another -- a wrong
109
+ // ranking, which is worse than an honest "unmeasured".
110
+ const byBasename = new Map();
111
+ const ambiguous = new Set();
112
+
113
+ // The map side: two distinct coverage keys sharing one basename are ambiguous.
114
+ for (const key of map.keys()) {
115
+ const base = path.basename(String(key).split('\\').join('/'));
116
+ const seen = byBasename.get(base);
117
+ if (seen !== undefined && seen !== key) {
118
+ ambiguous.add(base);
119
+ continue;
120
+ }
121
+ byBasename.set(base, key);
122
+ }
123
+
124
+ // The function side matters just as much, and is the case the issue measured:
125
+ // the summary names `util.mjs` once, but the code has src/a/util.mjs AND
126
+ // src/b/util.mjs. Handing that one ratio to either is a coin flip, so the name
127
+ // is ambiguous even though the summary is internally consistent.
128
+ const namesOnFunctions = new Map();
129
+ for (const fn of functions) {
130
+ const base = path.basename(toRepoRelative(fn.file));
131
+ namesOnFunctions.set(base, (namesOnFunctions.get(base) ?? 0) + 1);
132
+ }
133
+ for (const [base, count] of namesOnFunctions) {
134
+ if (count > 1) ambiguous.add(base);
135
+ }
136
+
104
137
  return functions.map((fn) => {
105
138
  const key = toRepoRelative(fn.file);
106
- const cov = coverage instanceof Map ? coverage.get(key) : undefined;
139
+
140
+ // 1. exact normalised path
141
+ let cov = map.get(key);
142
+
143
+ // 2. basename fallback, only when the path did not match and the name is
144
+ // unambiguous. Node's own summary carries basenames only, so without this
145
+ // step a measured file is indistinguishable from an unmeasured one.
146
+ if (cov === undefined) {
147
+ const base = path.basename(key);
148
+ if (!ambiguous.has(base) && byBasename.has(base)) {
149
+ cov = map.get(byBasename.get(base));
150
+ }
151
+ }
152
+
107
153
  const known = cov === undefined ? null : cov;
108
154
  return { ...fn, file: key, cov: known, crap: computeCrap(fn.ccn, known) };
109
155
  });
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-21T18:05:03.180Z",
5
+ "checked_at": "2026-11-22T06:27:38.627Z",
6
6
  "source": "network"
7
7
  }
package/lib/principles.js CHANGED
@@ -217,9 +217,19 @@ function findPrinciplesEntry() {
217
217
  // `.cs`/`.csx` were the gap: analyzer.ts registered CSharpAdapter, this walk
218
218
  // never offered the files, so `xp-gate principles <csharp-dir>` reported
219
219
  // "Files checked: 0" — indistinguishable from "no violations".
220
+ //
221
+ // #732: the walk must list EXACTLY the extensions `adapterMap` registers, or the
222
+ // two disagree and the disagreement is invisible — the engine advertises a
223
+ // language it can analyse while the walk never hands it a file. `.mts`/`.cts`
224
+ // were missing here for that reason; AC-758-02 pins the two lists together.
220
225
  const SOURCE_EXTENSIONS = new Set([
221
- '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs',
226
+ '.ts', '.tsx', '.mts', '.cts',
227
+ '.js', '.jsx', '.mjs', '.cjs',
222
228
  '.py', '.go', '.java', '.kt', '.kts',
229
+ // #731 shipped PhpAdapter and this walk kept dropping .php/.phtml, so the two
230
+ // lists disagreed in exactly the way #717 was about -- an adapter that existed
231
+ // and never received a file. AC-758-02 compares them, which is how it surfaced.
232
+ '.php', '.phtml',
223
233
  '.cs', '.csx',
224
234
  '.dart', '.swift', '.cpp', '.cc', '.cxx', '.c', '.h', '.hpp',
225
235
  '.m', '.mm',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.38.82",
3
+ "version": "0.38.84",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.82",
3
+ "version": "0.38.84",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/dsh-plugin-xp-gate",
3
- "version": "0.38.82",
3
+ "version": "0.38.84",
4
4
  "description": "XP-Gate deterministic quality gates + AI workflow skills as a DeepSeek Harness (DSH) native plugin: gate-check / gate-principles / gate-arch tools + 12 SKILL.md skills",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.38.82",
3
+ "version": "0.38.84",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.82",
3
+ "version": "0.38.84",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Qoder. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -15,18 +15,47 @@ export abstract class BaseAdapter implements Adapter {
15
15
 
16
16
  detectLanguage(): string {
17
17
  const extension = extname(this.filePath).toLowerCase();
18
-
18
+
19
+ // The SECOND map that decides whether an adapter's file gets analysed. An
20
+ // adapter can exist and still be discarded: analyzer.ts drops anything whose
21
+ // detectLanguage() is 'unknown'. So a missing entry here is just as fatal as
22
+ // a missing adapterMap entry, and the two were out of step in the same way.
23
+ //
24
+ // #732: mjs/cjs/mts/cts added. Without them a .mjs file passed the shell
25
+ // filter, got an adapter, and was then thrown away at this line -- Gate 4
26
+ // reported a clean PASS over files it never read.
27
+ //
28
+ // .php/.phtml (#731) and .cs/.csx/.cpp/.c/.h/.hpp/.m/.mm (#717) were also
29
+ // missing here while their adapters existed, so the same silent discard
30
+ // applied to them. Covered by the capability test rather than by hand.
19
31
  const languageMap: Record<string, string> = {
20
32
  '.ts': 'typescript',
21
33
  '.tsx': 'typescript',
34
+ '.mts': 'typescript',
35
+ '.cts': 'typescript',
22
36
  '.js': 'javascript',
23
37
  '.jsx': 'javascript',
38
+ '.mjs': 'javascript',
39
+ '.cjs': 'javascript',
24
40
  '.py': 'python',
25
41
  '.go': 'go',
26
42
  '.java': 'java',
27
43
  '.kt': 'kotlin',
44
+ '.kts': 'kotlin',
28
45
  '.dart': 'dart',
29
46
  '.swift': 'swift',
47
+ '.php': 'php',
48
+ '.phtml': 'php',
49
+ '.cs': 'csharp',
50
+ '.csx': 'csharp',
51
+ '.cpp': 'cpp',
52
+ '.cxx': 'cpp',
53
+ '.cc': 'cpp',
54
+ '.c': 'c',
55
+ '.hpp': 'cpp',
56
+ '.h': 'c',
57
+ '.m': 'objectivec',
58
+ '.mm': 'objectivec',
30
59
  };
31
60
 
32
61
  return languageMap[extension] || 'unknown';
@@ -72,6 +72,15 @@ export function getAdapterForFile(filePath: string): Adapter | null {
72
72
  '.tsx': TypeScriptAdapter,
73
73
  '.js': TypeScriptAdapter,
74
74
  '.jsx': TypeScriptAdapter,
75
+ // #732: the four module variants. This is the SECOND of the two inner maps
76
+ // that decide whether a file reaching Gate 4 is actually analysed -- the
77
+ // shell filter (githooks/lib/file-classifier.sh) only decides what reaches
78
+ // the gate. Fixing that one and not this one left Gate 4 reporting
79
+ // "✅ PASSED / Files checked: 0" over a project with 36 .mjs files.
80
+ '.mjs': TypeScriptAdapter,
81
+ '.cjs': TypeScriptAdapter,
82
+ '.mts': TypeScriptAdapter,
83
+ '.cts': TypeScriptAdapter,
75
84
  '.py': PythonAdapter,
76
85
  '.go': GoAdapter,
77
86
  '.java': JavaAdapter,
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.82.0
6
+ **Version:** 0.38.84.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.