@boyingliu01/xp-gate 0.37.0 → 0.37.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 (55) hide show
  1. package/adapters/typescript.sh +11 -1
  2. package/gate-10.sh +66 -0
  3. package/gate-13-compiler-strictness.sh +81 -1
  4. package/gate-6-layers.sh +375 -0
  5. package/hooks/gate-10.sh +66 -0
  6. package/hooks/gate-13-compiler-strictness.sh +81 -1
  7. package/hooks/gate-6-layers.sh +375 -0
  8. package/hooks/gate-registry.sh +2 -2
  9. package/hooks/hook-module-resolution.sh +1 -1
  10. package/hooks/lib/layer-baseline.cjs +88 -0
  11. package/hooks/lib/typecheck.sh +28 -5
  12. package/hooks/pre-commit +96 -11
  13. package/lib/__tests__/detect-deps-gate-identity.test.js +135 -0
  14. package/lib/__tests__/doctor-drift-round2.test.js +4 -1
  15. package/lib/__tests__/doctor-executed-surface.test.js +45 -24
  16. package/lib/__tests__/doctor-module-drift.test.js +13 -7
  17. package/lib/__tests__/doctor-module-resolution-parity.test.js +74 -2
  18. package/lib/__tests__/doctor.test.js +17 -0
  19. package/lib/__tests__/gate-runner-tsx-invocation.test.js +149 -0
  20. package/lib/__tests__/gate-runner.test.js +23 -7
  21. package/lib/__tests__/phase-transition.test.js +19 -1
  22. package/lib/__tests__/sprint-status-rework.test.js +32 -12
  23. package/lib/detect-deps.js +7 -1
  24. package/lib/doctor.js +81 -17
  25. package/lib/gate-runner.js +101 -7
  26. package/lib/hook-module-resolution.js +18 -6
  27. package/lib/layer-baseline.cjs +88 -0
  28. package/lib/mattpocock-license-verdict.json +1 -1
  29. package/mock-policy/AGENTS.md +1 -1
  30. package/mutation/AGENTS.md +1 -1
  31. package/package.json +2 -1
  32. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  33. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  34. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  35. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  36. package/plugins/dsh/package.json +1 -1
  37. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  38. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  39. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  40. package/plugins/opencode/package.json +1 -1
  41. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  42. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  43. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  44. package/plugins/qoder/plugin.json +1 -1
  45. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  46. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  47. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  48. package/principles/AGENTS.md +1 -1
  49. package/principles/adapters/csharp.ts +73 -42
  50. package/principles/adapters/java.ts +9 -5
  51. package/principles/adapters/typescript.ts +130 -45
  52. package/principles/index.ts +30 -14
  53. package/skills/delphi-review/AGENTS.md +1 -1
  54. package/skills/sprint-flow/AGENTS.md +1 -1
  55. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Layer-baseline comparison for Gate 6's layer check.
4
+ *
5
+ * Reads findings on stdin (one per line, fields separated by real TABs) and a
6
+ * JSON ledger as argv[2], and writes the findings that are NOT in the ledger.
7
+ *
8
+ * Exit 4 when the ledger exists but cannot be parsed. The caller treats that as
9
+ * BLOCK (fail-closed): a ledger that silently reads as empty would turn every
10
+ * accepted violation back into a new one, and the next natural response — re-run
11
+ * with a bigger baseline — quietly launders the debt.
12
+ *
13
+ * Why this is a file and not an inline `node -e`: the first version embedded
14
+ * this in bash single quotes, and the TAB separators ended up inside a JSON
15
+ * string literal, which JSON.parse rejects (raw control character). The error
16
+ * was then swallowed by `2>/dev/null`, so the ratchet silently reset on every
17
+ * run. Three levels of quoting is where that hid; one level is enough.
18
+ *
19
+ * Ledger shape:
20
+ * { "accepted": [ { "file", "from", "to", "imports" }, ... ] }
21
+ *
22
+ * A plain tab-joined string is also accepted for entries, so hand-written and
23
+ * generated ledgers both work.
24
+ */
25
+
26
+ 'use strict';
27
+
28
+ const fs = require('fs');
29
+
30
+ const SEVERITY_EXIT_UNREADABLE = 4;
31
+
32
+ /** Normalise one ledger entry to the tab-joined form used on stdin. */
33
+ function toKey(entry) {
34
+ if (typeof entry === 'string') {
35
+ return entry;
36
+ }
37
+ if (entry && typeof entry === 'object') {
38
+ return [entry.file, entry.from, entry.to, entry.imports].join('\t');
39
+ }
40
+ return '';
41
+ }
42
+
43
+ /** Read and validate the ledger. Throws when it cannot be used. */
44
+ function readLedger(path) {
45
+ const raw = fs.readFileSync(path, 'utf8');
46
+ const parsed = JSON.parse(raw);
47
+ const accepted = Array.isArray(parsed.accepted) ? parsed.accepted : [];
48
+ return new Set(accepted.map(toKey).filter(Boolean));
49
+ }
50
+
51
+ /** Split stdin into findings and drop the baselined ones. */
52
+ function filterFindings(raw, known) {
53
+ return raw
54
+ .split('\n')
55
+ .filter(Boolean)
56
+ .filter(line => !known.has(line));
57
+ }
58
+
59
+ function main() {
60
+ const ledgerPath = process.argv[2];
61
+ if (!ledgerPath) {
62
+ process.stderr.write('usage: layer-baseline.cjs <ledger.json> < findings\n');
63
+ process.exit(SEVERITY_EXIT_UNREADABLE);
64
+ return;
65
+ }
66
+
67
+ let known;
68
+ try {
69
+ known = readLedger(ledgerPath);
70
+ } catch (err) {
71
+ process.stderr.write(`layer-baseline unreadable: ${err.message}\n`);
72
+ process.exit(SEVERITY_EXIT_UNREADABLE);
73
+ return;
74
+ }
75
+
76
+ let raw = '';
77
+ process.stdin.setEncoding('utf8');
78
+ process.stdin.on('data', chunk => {
79
+ raw += chunk;
80
+ });
81
+ process.stdin.on('end', () => {
82
+ process.stdout.write(filterFindings(raw, known).join('\n'));
83
+ });
84
+ }
85
+
86
+ main();
87
+
88
+ module.exports = { toKey, readLedger, filterFindings };
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-07T12:39:49.883Z",
5
+ "checked_at": "2026-11-09T03:15:43.031Z",
6
6
  "source": "network"
7
7
  }
@@ -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.37.0.0
6
+ **Version:** 0.37.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Mock layering policy enforcement — Gate M3 of pre-push hook. Ensures integration tests use real implementations for internal dependencies, mock external dependencies, and annotate pending mocks with removal plans. Combines project scope scanning, mock decision engine, and per-file validation into a single pipeline.
@@ -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.37.0.0
6
+ **Version:** 0.37.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **Gate M** (incremental mutation testing) + **Gate M2** helpers (test-layer detection used by `src/mock-policy/`). Pre-push quality gate. TypeScript-only; uses Stryker.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
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"
@@ -22,6 +22,7 @@
22
22
  "scripts/",
23
23
  "gate-3.sh",
24
24
  "gate-4.sh",
25
+ "gate-6-layers.sh",
25
26
  "gate-7.sh",
26
27
  "gate-8.sh",
27
28
  "gate-9.sh",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
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.37.0.0
6
+ **Version:** 0.37.1.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.37.0.0
6
+ **Version:** 0.37.1.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, 40-67% token savings vs parallel). 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.37.0.0
6
+ **Version:** 0.37.1.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.37.0",
3
+ "version": "0.37.1",
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.37.0.0
6
+ **Version:** 0.37.1.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.37.0.0
6
+ **Version:** 0.37.1.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, 40-67% token savings vs parallel). 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.37.0.0
6
+ **Version:** 0.37.1.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.37.0",
3
+ "version": "0.37.1",
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.37.0.0
6
+ **Version:** 0.37.1.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.37.0.0
6
+ **Version:** 0.37.1.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, 40-67% token savings vs parallel). 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.37.0.0
6
+ **Version:** 0.37.1.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.37.0",
3
+ "version": "0.37.1",
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.37.0.0
6
+ **Version:** 0.37.1.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.37.0.0
6
+ **Version:** 0.37.1.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, 40-67% token savings vs parallel). 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.37.0.0
6
+ **Version:** 0.37.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -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.37.0.0
6
+ **Version:** 0.37.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Clean Code & SOLID principles checker — **Gate 4** of pre-commit. 14 rules × 9 language adapters, SARIF 2.1.0 output. Houses the **Boy Scout Rule** enforcement engine (Gate 6) and warning-baseline storage.
@@ -22,6 +22,50 @@ interface CSharpLexState {
22
22
  rawStringQuoteCount: number;
23
23
  }
24
24
 
25
+ /**
26
+ * C# method declaration: optional modifiers, return type, name, params, then
27
+ * either a block `{`, an expression body `=>`, or `;` (abstract / interface
28
+ * members). `async` and generics (`Task<int>`) must be tolerated or every async
29
+ * method in a modern codebase is invisible.
30
+ *
31
+ * Module scope, not a local in `extractFunctions`: the complexity analyzer
32
+ * counts branches by scanning the function body text, and a regex literal is
33
+ * dense in `|` and `?`. Kept inline, these two patterns alone put
34
+ * `extractFunctions` at CCN 18 — a number that described the regex source
35
+ * rather than the code. The patterns are constant, so module scope is also where
36
+ * they belong.
37
+ */
38
+ const METHOD_DECLARATION =
39
+ /(?:^|\n)[ \t]*(?:(?:public|private|protected|internal|static|async|override|virtual|sealed|abstract|extern|unsafe|new|partial)\s+)*(?:[\w.<>\[\],?]+\s+)?([A-Za-z_]\w*)\s*(?:<[^>]*>)?\s*\(([^)]*)\)\s*(?:where\s[^{;]*)?(?:=>|\{|;)/g;
40
+
41
+ /**
42
+ * Constructors: `public Foo(...)` has no return type, so METHOD_DECLARATION can
43
+ * miss it when the modifier list is empty or minimal. Same module-scope
44
+ * rationale.
45
+ */
46
+ const CONSTRUCTOR_DECLARATION =
47
+ /(?:^|\n)[ \t]*(?:(?:public|private|protected|internal|static)\s+)*([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?::\s*(?:base|this)\s*\([^)]*\)\s*)?\{/g;
48
+
49
+ /**
50
+ * A C# type declaration.
51
+ *
52
+ * The trailing group accepts BOTH shapes a type declaration takes: a body (`{`)
53
+ * and a body-less primary-constructor record (`record Delta(int X);`, C# 9+).
54
+ * Requiring `{` made every such record invisible to the god-class / large-file
55
+ * rules. Module scope for the same reason as METHOD_DECLARATION: a regex literal
56
+ * is dense in `|` and `?`, which the complexity analyzer counts as branches.
57
+ */
58
+ const CLASS_DECLARATION =
59
+ /\b(?:(?:public|private|protected|internal|static|sealed|abstract|partial|readonly|unsafe|new)\s+)*(class|interface|struct|record|enum)\s+([A-Za-z_]\w*)\s*(?:<[^>]*>)?\s*(?:\([^)]*\))?\s*(?::\s*[^{\n;]+)?\s*(?:\{|;)/g;
60
+
61
+ /** One member declaration inside a type body, for the god-class rule. */
62
+ const MEMBER_DECLARATION = /\b(?:public|private|protected|internal)\s+[^;{}]*\([^)]*\)\s*(?:=>|\{)/g;
63
+
64
+ /** How many accessor-prefixed members a type body declares. */
65
+ function countMemberDeclarations(body: string): number {
66
+ return (body.match(MEMBER_DECLARATION) || []).length;
67
+ }
68
+
25
69
  /**
26
70
  * C# language adapter for the principles checker (Gate 4).
27
71
  *
@@ -49,66 +93,53 @@ export class CSharpAdapter extends BaseAdapter implements Adapter {
49
93
  return this.createParseResult('csharp');
50
94
  }
51
95
 
52
- extractFunctions(): unknown[] {
53
- const matches: unknown[] = [];
54
-
55
- // C# method declaration: optional modifiers, return type, name, params,
56
- // then either a block `{`, an expression body `=>`, or `;` (abstract /
57
- // interface members). `async` and generics (`Task<int>`) must be tolerated
58
- // or every async method in a modern codebase is invisible.
59
- const methodRegex =
60
- /(?:^|\n)[ \t]*(?:(?:public|private|protected|internal|static|async|override|virtual|sealed|abstract|extern|unsafe|new|partial)\s+)*(?:[\w.<>\[\],?]+\s+)?([A-Za-z_]\w*)\s*(?:<[^>]*>)?\s*\(([^)]*)\)\s*(?:where\s[^{;]*)?(?:=>|\{|;)/g;
61
-
96
+ /**
97
+ * Scan `regex` over the file and record one code match per surviving hit.
98
+ *
99
+ * Methods and constructors are found by two different patterns, but they
100
+ * produce the same shape (name, paramCount, body metrics) and share the
101
+ * reserved-word guard. Keeping the two loops separate duplicated that logic
102
+ * and raised this method's complexity for no benefit.
103
+ */
104
+ private collectDeclarations(
105
+ regex: RegExp,
106
+ kind: 'function' | 'constructor',
107
+ into: unknown[],
108
+ ): void {
109
+ regex.lastIndex = 0;
62
110
  let match: RegExpExecArray | null;
63
- while ((match = methodRegex.exec(this.fileContent)) !== null) {
111
+ while ((match = regex.exec(this.fileContent)) !== null) {
64
112
  const name = match[1];
65
- // Constructors and `new` expressions look like the pattern above; the
113
+ // Constructors and `new` expressions look like the patterns above; the
66
114
  // reserved words are not method names as far as the rules care.
67
115
  if (CSharpAdapter.RESERVED.has(name)) continue;
68
116
 
69
117
  const params = match[2].trim();
70
- const paramCount = params === '' ? 0 : params.split(',').length;
71
-
72
- matches.push(this.createCodeMatch(name, 'function', match.index));
73
- const fnMatch = matches[matches.length - 1];
74
- this.annotate(fnMatch, 'paramCount', paramCount);
75
- this.annotateBodyMetrics(fnMatch);
76
- }
77
-
78
- // Constructors: `public Foo(...)` has no return type, so the regex above
79
- // can miss it when the modifier list is empty or minimal.
80
- const ctorRegex = /(?:^|\n)[ \t]*(?:(?:public|private|protected|internal|static)\s+)*([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?::\s*(?:base|this)\s*\([^)]*\)\s*)?\{/g;
81
- while ((match = ctorRegex.exec(this.fileContent)) !== null) {
82
- const name = match[1];
83
- if (CSharpAdapter.RESERVED.has(name)) continue;
84
- const params = match[2].trim();
85
- const paramCount = params === '' ? 0 : params.split(',').length;
86
- matches.push(this.createCodeMatch(name, 'constructor', match.index));
87
- const ctorMatch = matches[matches.length - 1];
88
- this.annotate(ctorMatch, 'paramCount', paramCount);
89
- this.annotateBodyMetrics(ctorMatch);
118
+ const codeMatch = this.createCodeMatch(name, kind, match.index);
119
+ this.annotate(codeMatch, 'paramCount', params === '' ? 0 : params.split(',').length);
120
+ this.annotateBodyMetrics(codeMatch);
121
+ into.push(codeMatch);
90
122
  }
123
+ }
91
124
 
125
+ extractFunctions(): unknown[] {
126
+ const matches: unknown[] = [];
127
+ this.collectDeclarations(METHOD_DECLARATION, 'function', matches);
128
+ this.collectDeclarations(CONSTRUCTOR_DECLARATION, 'constructor', matches);
92
129
  return matches;
93
130
  }
94
131
 
95
132
  extractClasses(): unknown[] {
96
133
  const matches: unknown[] = [];
97
- // The trailing group accepts BOTH shapes a type declaration takes: a body
98
- // (`{`) and a body-less primary-constructor record (`record Delta(int X);`,
99
- // C# 9+). Requiring `{` made every such record invisible to the god-class /
100
- // large-file rules.
101
- const classRegex =
102
- /\b(?:(?:public|private|protected|internal|static|sealed|abstract|partial|readonly|unsafe|new)\s+)*(class|interface|struct|record|enum)\s+([A-Za-z_]\w*)\s*(?:<[^>]*>)?\s*(?:\([^)]*\))?\s*(?::\s*[^{\n;]+)?\s*(?:\{|;)/g;
103
134
 
104
135
  let match: RegExpExecArray | null;
105
- while ((match = classRegex.exec(this.fileContent)) !== null) {
106
- matches.push(this.createCodeMatch(match[2], match[1], match.index));
136
+ while ((match = CLASS_DECLARATION.exec(this.fileContent)) !== null) {
137
+ const codeMatch = this.createCodeMatch(match[2], match[1], match.index);
107
138
  const body = this.extractCodeBlock(match.index);
108
139
  // methodCount feeds the god-class rule; counting declarations in the body
109
140
  // is the only signal available without a real parser.
110
- const methodCount = (body.match(/\b(?:public|private|protected|internal)\s+[^;{}]*\([^)]*\)\s*(?:=>|\{)/g) || []).length;
111
- this.annotate(matches[matches.length - 1], 'methodCount', methodCount);
141
+ this.annotate(codeMatch, 'methodCount', countMemberDeclarations(body));
142
+ matches.push(codeMatch);
112
143
  }
113
144
 
114
145
  return matches;
@@ -230,14 +230,18 @@ export const javaParse = {
230
230
  // parameter, so the commas inside its arguments must not be counted.
231
231
  // Which characters change depth and which separate is data, not control
232
232
  // flow -- table lookups keep the scan to a single conditional.
233
+ //
234
+ // A comma counts only at depth zero, expressed as ONE condition rather than
235
+ // a nested pair: the earlier form tested `ch === ','` and then re-tested
236
+ // `depth === 0` inside it, which the complexity budget charged twice for a
237
+ // single decision. The `?? 0` default moved into the lookup itself for the
238
+ // same reason -- it was a third branch on a table that answers for every
239
+ // nesting character.
233
240
  let depth = 0;
234
241
  let count = 1;
235
242
  for (const ch of trimmed) {
236
- if (ch === ',') {
237
- if (depth === 0) count += 1;
238
- continue;
239
- }
240
- depth += PARAM_NESTING[ch] ?? 0;
243
+ if (ch === ',' && depth === 0) count += 1;
244
+ depth += PARAM_NESTING[ch] || 0;
241
245
  }
242
246
  return count;
243
247
  },