@boyingliu01/xp-gate 0.37.0 → 0.37.2

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 (60) 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/sprint-flow/references/phase-5-ship.md +6 -2
  36. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  37. package/plugins/dsh/package.json +1 -1
  38. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  39. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  40. package/plugins/dsh/skills/sprint-flow/references/phase-5-ship.md +6 -2
  41. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  42. package/plugins/opencode/package.json +1 -1
  43. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  44. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  45. package/plugins/opencode/skills/sprint-flow/references/phase-5-ship.md +6 -2
  46. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  47. package/plugins/qoder/plugin.json +1 -1
  48. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  49. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  50. package/plugins/qoder/skills/sprint-flow/references/phase-5-ship.md +6 -2
  51. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  52. package/principles/AGENTS.md +1 -1
  53. package/principles/adapters/csharp.ts +73 -42
  54. package/principles/adapters/java.ts +9 -5
  55. package/principles/adapters/typescript.ts +130 -45
  56. package/principles/index.ts +30 -14
  57. package/skills/delphi-review/AGENTS.md +1 -1
  58. package/skills/sprint-flow/AGENTS.md +1 -1
  59. package/skills/sprint-flow/references/phase-5-ship.md +6 -2
  60. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -187,6 +187,123 @@ function lineOf(src: string, index: number): number {
187
187
  return src.substring(0, index).split('\n').length;
188
188
  }
189
189
 
190
+ /**
191
+ * Offsets of the literals that are the initializer of a named constant.
192
+ *
193
+ * `const NAME = 3` / `const NAME: T = 3`. The magic-number rule skips a number
194
+ * that IS the initializer of a named constant, because the rule's own advice is
195
+ * "consider using a named constant instead" — reporting the constant it just
196
+ * asked for made the violation unfixable.
197
+ *
198
+ * The value's OFFSET is captured rather than the value itself so the literal can
199
+ * be matched positionally: the same number appearing twice must be judged
200
+ * separately, and only the declaration occurrence is exempt.
201
+ *
202
+ * Lives at module scope: as a method it pushed `TypeScriptAdapter` to 16
203
+ * methods, past the god-class threshold of 15, for a pure helper that never
204
+ * reads instance state.
205
+ */
206
+ function namedConstLiteralOffsets(masked: string): Set<number> {
207
+ const namedConstRe = /\b(?:const|readonly)\s+[A-Za-z_$][\w$]*\s*(?::[^=;]+)?=\s*(-?\d+(?:\.\d+)?)\s*;/g;
208
+ const offsets = new Set<number>();
209
+ let c: RegExpExecArray | null;
210
+ while ((c = namedConstRe.exec(masked)) !== null) {
211
+ offsets.add(c.index + c[0].lastIndexOf(c[1]));
212
+ }
213
+ return offsets;
214
+ }
215
+
216
+ /** One `import ... from '...'` statement. */
217
+ const IMPORT_STATEMENT = /^[ \t]*import\s+(?:type\s+)?([\s\S]*?)\s+from\s+['"][^'"]+['"]/gm;
218
+
219
+ /** True when the statement this match belongs to is `import type ...`. */
220
+ const TYPE_ONLY_IMPORT = /^import\s+type\b/;
221
+
222
+ type ImportBinding = { name: string; line: number; used: boolean; type?: string };
223
+
224
+ /**
225
+ * Every binding named by an import statement, plus the span each statement
226
+ * occupies.
227
+ *
228
+ * The spans are returned because usage counting needs the statements BLANKED
229
+ * first: an imported name obviously appears inside its own `import` line, so
230
+ * scanning the raw file marks every import as used. Inlined into the accessor
231
+ * that consumes this, the whole job scored CCN 8 against a baseline of 5.
232
+ */
233
+ function collectImportBindings(src: string): {
234
+ entries: ImportBinding[];
235
+ importSpans: Array<[number, number]>;
236
+ } {
237
+ const entries: ImportBinding[] = [];
238
+ const importSpans: Array<[number, number]> = [];
239
+ let m: RegExpExecArray | null;
240
+ while ((m = IMPORT_STATEMENT.exec(src)) !== null) {
241
+ const line = lineOf(src, m.index);
242
+ const isTypeOnly = TYPE_ONLY_IMPORT.test(m[0]);
243
+ for (const binding of parseImportClause(m[1].trim(), isTypeOnly)) {
244
+ entries.push({ ...binding, line, used: false });
245
+ }
246
+ importSpans.push([m.index, m.index + m[0].length]);
247
+ }
248
+ return { entries, importSpans };
249
+ }
250
+
251
+ /**
252
+ * `text` with each span replaced by spaces.
253
+ *
254
+ * Spaces rather than deletion: line numbers and column offsets of everything
255
+ * after the span must keep pointing at the original characters.
256
+ */
257
+ function blankSpans(text: string, spans: Array<[number, number]>): string {
258
+ let out = text;
259
+ // Reverse order so an earlier span's offsets stay valid while later ones are
260
+ // rewritten; ascending order would shift every subsequent span.
261
+ for (const [start, end] of [...spans].reverse()) {
262
+ out = out.substring(0, start) + ' '.repeat(end - start) + out.substring(end);
263
+ }
264
+ return out;
265
+ }
266
+
267
+ /** True when `name` appears in `body` as a whole identifier, not a property. */
268
+ function isReferenced(name: string, body: string): boolean {
269
+ const escaped = name.replace(/\$/g, '\\$');
270
+ return new RegExp(`(?<![\\w$.])${escaped}(?![\\w$])`, 'g').test(body);
271
+ }
272
+
273
+ /**
274
+ * A class member declaration: `name(...) {`. Not anchored to line start so
275
+ * minified single-line bodies count too.
276
+ *
277
+ * Module scope because a regex literal is dense in `|` and `?`, which the
278
+ * complexity analyzer counts as branches — inlined, this pattern alone is most of
279
+ * what made `collectClassMethods` score CCN 16 against a baseline of 6.
280
+ */
281
+ const CLASS_MEMBER = /(?<![\w$.])(?:public\s+|private\s+|protected\s+|static\s+|async\s+|readonly\s+|get\s+|set\s+|\*\s*)*(\w+)\s*\(/g;
282
+
283
+ /**
284
+ * Whether a CLASS_MEMBER hit is really a method, rather than a shape that only
285
+ * looks like one.
286
+ *
287
+ * Three rejections, each a distinct reason, so the caller's loop stays a filter:
288
+ * a control-flow keyword (`if (a > 0) {` matches the shape), a call site
289
+ * (`foo(x)` is not a declaration), and a declaration with no body brace.
290
+ */
291
+ function isMethodShaped(masked: string, name: string, nameIndex: number, parenIndex: number): boolean {
292
+ if (CONTROL_KEYWORDS.has(name)) return false;
293
+ if (isCallPosition(masked, nameIndex)) return false;
294
+ // Only treat as a method when a body brace follows the parameter list.
295
+ return findBodyBrace(masked, parenIndex) !== -1;
296
+ }
297
+
298
+ /**
299
+ * An arrow-function assignment: `const name = (...) =>` / `let name = x =>`.
300
+ *
301
+ * Module scope because a regex literal is dense in `|` and `?`, which the
302
+ * complexity analyzer counts as branches; inlined, this pattern was most of what
303
+ * made `collectArrowFunctions` score CCN 9 against a baseline of 4.
304
+ */
305
+ const ARROW_ASSIGNMENT = /(?:const|let|var)\s+(\w+)\s*(?::[^=]+)?=\s*(?:async\s*)?/g;
306
+
190
307
  /** The three quoted states shared by the parameter/paren scanners. */
191
308
  /** Count top-level, comma-separated parameters in a raw parameter list. */
192
309
  function countParams(rawList: string): number {
@@ -499,17 +616,9 @@ export class TypeScriptAdapter extends BaseAdapter implements Adapter {
499
616
  */
500
617
  extract(): Array<{ value: number; line: number }> {
501
618
  const src = this.fileContent;
502
- const results: Array<{ value: number; line: number }> = [];
503
619
  const masked = this.maskedSource;
504
-
505
- // `const NAME = 3` / `const NAME: T = 3` -- capture the value's offset so the
506
- // literal can be matched positionally rather than by value.
507
- const namedConstRe = /\b(?:const|readonly)\s+[A-Za-z_$][\w$]*\s*(?::[^=;]+)?=\s*(-?\d+(?:\.\d+)?)\s*;/g;
508
- const namedConstOffsets = new Set<number>();
509
- let c: RegExpExecArray | null;
510
- while ((c = namedConstRe.exec(masked)) !== null) {
511
- namedConstOffsets.add(c.index + c[0].lastIndexOf(c[1]));
512
- }
620
+ const namedConstOffsets = namedConstLiteralOffsets(masked);
621
+ const results: Array<{ value: number; line: number }> = [];
513
622
 
514
623
  const numRe = /(?<![\w$.])(-?\d+(?:\.\d+)?)(?![\w$])/g;
515
624
  let m: RegExpExecArray | null;
@@ -529,30 +638,12 @@ export class TypeScriptAdapter extends BaseAdapter implements Adapter {
529
638
  */
530
639
  get imports(): Array<{ name: string; line: number; used: boolean; type?: string }> {
531
640
  const src = this.fileContent;
532
- const entries: Array<{ name: string; line: number; used: boolean; type?: string }> = [];
533
- const importRe = /^[ \t]*import\s+(?:type\s+)?([\s\S]*?)\s+from\s+['"][^'"]+['"]/gm;
534
- const importSpans: Array<[number, number]> = [];
535
- let m: RegExpExecArray | null;
536
-
537
- while ((m = importRe.exec(src)) !== null) {
538
- const line = lineOf(src, m.index);
539
- const isTypeOnly = /^import\s+type\b/.test(m[0]);
540
- for (const binding of parseImportClause(m[1].trim(), isTypeOnly)) {
541
- entries.push({ ...binding, line, used: false });
542
- }
543
- importSpans.push([m.index, m.index + m[0].length]);
544
- }
545
-
546
- // Count identifier usage outside import statements.
547
- let body = src;
548
- for (const [start, end] of [...importSpans].reverse()) {
549
- body = body.substring(0, start) + ' '.repeat(end - start) + body.substring(end);
550
- }
551
- for (const entry of entries) {
552
- const useRe = new RegExp(`(?<![\\w$.])${entry.name.replace(/\$/g, '\\$')}(?![\\w$])`, 'g');
553
- entry.used = useRe.test(body);
554
- }
555
-
641
+ const { entries, importSpans } = collectImportBindings(src);
642
+ // Usage is judged against the file with every import statement blanked out.
643
+ // Inlined, this accessor scored CCN 8 against a baseline of 5 because it did
644
+ // three jobs at once: find the imports, mask them, then count references.
645
+ const body = blankSpans(src, importSpans);
646
+ for (const entry of entries) entry.used = isReferenced(entry.name, body);
556
647
  return entries;
557
648
  }
558
649
 
@@ -661,31 +752,25 @@ export class TypeScriptAdapter extends BaseAdapter implements Adapter {
661
752
  */
662
753
  private collectClassMethods(seen: Set<string>, found: FunctionMetrics[]): void {
663
754
  const masked = this.maskedSource;
664
- const memberRe = /(?<![\w$.])(?:public\s+|private\s+|protected\s+|static\s+|async\s+|readonly\s+|get\s+|set\s+|\*\s*)*(\w+)\s*\(/g;
665
755
  let m: RegExpExecArray | null;
666
- while ((m = memberRe.exec(masked)) !== null) {
667
- if (CONTROL_KEYWORDS.has(m[1])) continue;
756
+ while ((m = CLASS_MEMBER.exec(masked)) !== null) {
668
757
  // The pattern ends with `\(`, so the match's last character IS the opening
669
758
  // paren. Re-searching with indexOf() could drift to a later `(` inside the
670
759
  // parameter list or a type annotation, which corrupted the reported span.
671
760
  const parenIndex = m.index + m[0].length - 1;
672
761
  const nameIndex = parenIndex - m[1].length;
673
- if (isCallPosition(masked, nameIndex)) continue;
674
- // Only treat as a method when a body brace follows the parameter list.
675
- const bodyOpen = findBodyBrace(masked, parenIndex);
676
- if (bodyOpen === -1) continue;
762
+ if (!isMethodShaped(masked, m[1], nameIndex, parenIndex)) continue;
677
763
  if (!claimMember(seen, m[1], nameIndex)) continue;
678
- found.push(this.buildFunction(m[1], 'method', nameIndex, parenIndex, bodyOpen));
764
+ found.push(this.buildFunction(m[1], 'method', nameIndex, parenIndex, findBodyBrace(masked, parenIndex)));
679
765
  }
680
766
  }
681
767
 
682
768
  /** Arrow consts / assignments: `const name = (...) =>` / `name = x =>`. */
683
769
  private collectArrowFunctions(seen: Set<string>, found: FunctionMetrics[]): void {
684
770
  const masked = this.maskedSource;
685
- const arrowRe = /(?:const|let|var)\s+(\w+)\s*(?::[^=]+)?=\s*(?:async\s*)?/g;
686
771
  let m: RegExpExecArray | null;
687
- while ((m = arrowRe.exec(masked)) !== null) {
688
- const arrow = this.parseArrowAt(m, arrowRe.lastIndex);
772
+ while ((m = ARROW_ASSIGNMENT.exec(masked)) !== null) {
773
+ const arrow = this.parseArrowAt(m, ARROW_ASSIGNMENT.lastIndex);
689
774
  if (!arrow) continue;
690
775
  const nameIndex = m.index + m[0].length - m[1].length;
691
776
  if (!claimMember(seen, m[1], nameIndex)) continue;
@@ -176,23 +176,39 @@ function findDirectories(paths: readonly string[]): string[] {
176
176
  return dirs;
177
177
  }
178
178
 
179
- export async function main(args: string[]): Promise<number> {
180
- const options = parseArgs(args);
181
-
182
- if (options.files.length === 0) {
179
+ /**
180
+ * Reject a usage the checker cannot honestly answer, reporting why.
181
+ *
182
+ * Two cases, one decision: nothing was analysed, so "no violations found" would
183
+ * be a claim about files that were never read. An empty argument list is a
184
+ * usage error; so is a directory handed in where a file was expected — the
185
+ * latter previously reached `analyze`, which could not read it, filed NO error,
186
+ * and reported `Files checked: 0` with "✓ No violations found" and exit 0. That
187
+ * is the same false-clean shape #623 fixed for unreadable files, except a
188
+ * directory produced silence because reading it fails differently from opening
189
+ * a file.
190
+ *
191
+ * Returns true when it has reported and the caller must stop.
192
+ */
193
+ function refuseUnanalysableInput(files: readonly string[]): boolean {
194
+ if (files.length === 0) {
183
195
  usageMessage();
184
- return USAGE_EXIT;
196
+ return true;
185
197
  }
198
+ const directories = findDirectories(files);
199
+ if (directories.length === 0) return false;
200
+ console.error(
201
+ `Cannot analyse a directory: ${directories.length} path(s) are directories, not files`,
202
+ );
203
+ for (const dir of directories) console.error(` ${dir}`);
204
+ console.error('Pass individual files, or run the gate wrapper: xp-gate check 4 <dir>');
205
+ return true;
206
+ }
186
207
 
187
- const directories = findDirectories(options.files);
188
- if (directories.length > 0) {
189
- console.error(
190
- `Cannot analyse a directory: ${directories.length} path(s) are directories, not files`,
191
- );
192
- for (const dir of directories) console.error(` ${dir}`);
193
- console.error('Pass individual files, or run the gate wrapper: xp-gate check 4 <dir>');
194
- return USAGE_EXIT;
195
- }
208
+ export async function main(args: string[]): Promise<number> {
209
+ const options = parseArgs(args);
210
+
211
+ if (refuseUnanalysableInput(options.files)) return USAGE_EXIT;
196
212
 
197
213
  // Install the loaded config so rules read the PROJECT's thresholds. The
198
214
  // previous `await loadConfig();` discarded the result, so `.principlesrc` was
@@ -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.2.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.2.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.
@@ -45,8 +45,12 @@
45
45
  - 添加新版本条目 (## [X.Y.Z.W] - YYYY-MM-DD)
46
46
  - 按 ### Added / ### Fixed / ### Changed 分类
47
47
 
48
- 4. 运行 sync-version.sh:
49
- bash scripts/sync-version.sh
48
+ 4. 运行 sync-version:
49
+ bash scripts/sync-version.sh # 薄包装,实际执行 sync-version.cjs
50
+ # 两个入口等价——.sh 只是 exec 同一个 .cjs,目标清单只有一份。
51
+ # 2026-11-09 之前它们是两份独立实现且已经漂移:bash 版不处理
52
+ # package-lock.json 与 plugins/dsh/package.json,还会把 .stryker-tmp
53
+ # 下的副本一起改写(报 401 files 而非 41)。按本文档执行会静默漏掉两个文件。
50
54
 
51
55
  5. 验证:
52
56
  git diff VERSION # 确认版本号变更
@@ -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.2.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.