@boyingliu01/xp-gate 0.41.10 → 0.41.56

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 +283 -31
  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
@@ -17,12 +17,12 @@
17
17
 
18
18
  | # | 条目 | 判据(必须能指出位置) |
19
19
  |---|------|------------------------|
20
- | 1 | **需求可追溯** | `specification.yaml` 有 REQ + AC;测试文件带 `@covers AC-xxx`;`scripts/__tests__/ac-reference-guard.test.cjs` 通过 |
20
+ | 1 | **需求可追溯** | `specification.yaml` 有 REQ + AC;测试文件带 `@covers AC-xxx`。**(xp-gate 自身仓库额外要求)** `scripts/__tests__/ac-reference-guard.test.cjs` 通过;你的项目用等价的「AC 必须存在于 spec」检查 |
21
21
  | 2 | **测试先行** | 实现前存在失败的测试;或说明为何不适用(纯文档/配置) |
22
22
  | 3 | **测试真的能失败** | 至少一个变异体/破坏被测试抓住。「测试通过」在从未运行时和「功能正确」无法区分 |
23
23
  | 4 | **验证命令已运行** | 记录实际命令与输出,不是「应该是绿的」。CI 命令与本地命令一致 |
24
24
  | 5 | **门禁未降级** | 无 `--no-verify`;无新增基线额度来吸收本次改动自身的告警 |
25
- | 6 | **镜像已同步** | 改了 `githooks/`/`skills/`/`plugins/` → `bash scripts/check-hook-mirror.sh` 输出 PASS |
25
+ | 6 | **镜像已同步** | **(仅 xp-gate 自身仓库)** 改了 `githooks/`/`skills/`/`plugins/` → `bash scripts/check-hook-mirror.sh` 输出 PASS。你的项目若没有镜像树,本条不适用——填「不适用」而不是发明等价检查 |
26
26
  | 7 | **不做未经要求的相邻改动** | 每行改动可追溯到本 REQ;顺手发现的无关死代码只提及不删除 |
27
27
  | 8 | **已知限制已写明** | 没做的部分、以及为什么没做,写进 issue/提交,而不是留空 |
28
28
  | 9 | **文档与实现一致** | 门禁数量、CLI 表、阈值等出现在多处的事实同步更新(见 `AGENTS.md` "Known Drift") |
@@ -38,7 +38,7 @@
38
38
  | 4 | **Gate 4 Principles** | 14 条 Clean Code/SOLID 规则,任一 error/warning 即拦(按 `.principlesrc`) | `xp-gate check 4 <file>`;避免超长参数表、空 catch、`as any` |
39
39
  | 5 | **Gate 1 Lint** | 适配器 lint 任一 error | 提交前跑一次项目 lint;不要留未用变量/导入 |
40
40
  | 6 | **Gate 5 测试** | 测试全绿 + 覆盖率 ≥80%(新 .ts/.tsx 无测试直接 BLOCK) | 新代码先写测试(TDD);`npx vitest run <file>` |
41
- | 7 | **mirror/sync 纪律** | 改 `githooks/` 或 `skills/` 后必须 `node src/npm-package/scripts/sync-package-content.js --fix` 且 `bash scripts/check-hook-mirror.sh` 报 PASS | 忘了同步会在 pre-push 的 mirror 校验被打回 |
41
+ | 7 | **mirror/sync 纪律** | **(仅 xp-gate 自身仓库)** 改 `githooks/` 或 `skills/` 后必须 `node src/npm-package/scripts/sync-package-content.js --fix` 且 `bash scripts/check-hook-mirror.sh` 报 PASS | 忘了同步会在 pre-push 的 mirror 校验被打回;无镜像树的项目本条不适用 |
42
42
 
43
43
  **权威清单用 `xp-gate gate-rules` 现取,不要背上面这张表。** 上表是手抄的,阈值真正定义在
44
44
  `.principlesrc`、`jscpd.conf.json` 和 `githooks/pre-commit` 里。`xp-gate gate-rules` 从那些
@@ -148,12 +148,12 @@ ELSE:
148
148
 
149
149
  | # | 条目 | 在 VERIFY 的检查方式 |
150
150
  |---|------|----------------------|
151
- | 1 | 需求可追溯 | `npx vitest run scripts/__tests__/ac-reference-guard.test.cjs` 通过(测试引用的 AC 都在 spec 里) |
151
+ | 1 | 需求可追溯 | 测试引用的 AC 都在 spec 里。**(xp-gate 自身仓库额外要求)** `npx vitest run scripts/__tests__/ac-reference-guard.test.cjs` 通过;你的项目用等价的自带检查 |
152
152
  | 2 | 测试先行 | 有 RED 证据(提交历史或记录),或说明为何不适用 |
153
153
  | 3 | **测试真的能失败** | 至少证明过一个变异体会被抓住——「测试通过」在从未运行时与「功能正确」无法区分 |
154
154
  | 4 | 验证命令已运行 | 记录实际命令 + 输出,不是「应该是绿的」 |
155
155
  | 5 | 门禁未降级 | 无 `--no-verify`;无为了本次改动新增的基线额度 |
156
- | 6 | 镜像已同步 | `bash scripts/check-hook-mirror.sh` → PASS |
156
+ | 6 | 镜像已同步 | **(仅 xp-gate 自身仓库)** `bash scripts/check-hook-mirror.sh` → PASS;无镜像树的项目本条不适用 |
157
157
 
158
158
  第 5 项值得单独说明:**加基线额度来吸收自己刚产生的告警,等于把门禁关掉一次。**
159
159
  `.warnings-baseline.json` 只应记录「改动之前就存在」的告警。
@@ -23,6 +23,10 @@
23
23
 
24
24
  **Purpose**: `.sprint-state/` is gitignored and lives inside the worktree. When the worktree is removed during CLEANUP, all sprint state is lost. This step copies it into the main repository before cleanup.
25
25
 
26
+ **`.xp-gate/` goes too (#836).** The tool writes its own audit surface into a DIFFERENT gitignored directory inside the same worktree: the `--skip-evidence` REASON, the gate-result snapshots, and the quality reports retro reads. Backing up only `.sprint-state/` loses them at the same moment, and the loss is silent -- the sprint closes looking complete while the record of *why* a gate was skipped no longer exists anywhere. #318 extended this list to cover state; it never covered audit.
27
+
28
+ Backup BOTH directories. A missing `.xp-gate/` is not an error (a sprint may never have triggered a gate), so the copy is conditional.
29
+
26
30
  **Execution** (immediately after SHIP→CLOSE GATE passes):
27
31
 
28
32
  ```bash
@@ -34,14 +38,27 @@ BACKUP_DIR=".sprint-history/${SPRINT_ID}"
34
38
  mkdir -p "$BACKUP_DIR"
35
39
  cp -r .sprint-state/* "$BACKUP_DIR/"
36
40
 
41
+ # 2b. Audit surface (#836) — gitignored, worktree-local, and NOT covered by the
42
+ # copy above. Missing is fine; losing a present one is not.
43
+ if [ -d .xp-gate ]; then
44
+ mkdir -p "$BACKUP_DIR/xp-gate"
45
+ cp -r .xp-gate/* "$BACKUP_DIR/xp-gate/"
46
+ fi
47
+
37
48
  # 3. Verify backup
38
49
  ls "$BACKUP_DIR/sprint-state.json" && echo "✅ Sprint state backed up to $BACKUP_DIR"
50
+ if [ -d .xp-gate ]; then
51
+ ls "$BACKUP_DIR/xp-gate/audit.jsonl" \
52
+ && echo "✅ Audit surface backed up to $BACKUP_DIR/xp-gate/" \
53
+ || echo "⚠️ .xp-gate/ existed but audit.jsonl was not copied"
54
+ fi
39
55
  ```
40
56
 
41
57
  **GATE CHECK**:
42
58
  ```
43
59
  [BACKUP] sprint-state.json copied ✓
44
60
  [BACKUP] phase-outputs/ preserved ✓
61
+ [BACKUP] .xp-gate/ audit surface copied ✓ (or: absent, nothing to copy)
45
62
  ```
46
63
 
47
64
  **Output**: `.sprint-history/<sprint-id>/` contains full sprint state, safely outside the worktree.
@@ -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.41.10.0
6
+ **Version:** 0.41.56.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Disproval evidence for a finding: what the SYSTEM observed, never a conclusion.
3
+ *
4
+ * A reviewer disproving its own finding is the one place this mechanism could be
5
+ * turned into a rubber stamp, so free text is not representable here at all.
6
+ * Each kind names the observation the runner must supply (`actualExit`,
7
+ * `actualText`, `symbolFound`), and `validateEvidence` reads only that -- the
8
+ * orchestrator supplies the command or the path, never the verdict.
9
+ *
10
+ * @test REQ-DSH-016
11
+ * @intent 证伪必须由系统实测支撑,不接受"我测过了"式的自由文本,
12
+ * 否则编排者可以给自己放行。
13
+ * @covers AC-DSH-016-03
14
+ */
15
+ /** Result of validating a piece of evidence. */
16
+ export interface EvidenceVerdict {
17
+ readonly ok: boolean;
18
+ readonly reason: string;
19
+ }
20
+ /**
21
+ * Proof that a finding is settled, as one of three system-verified kinds.
22
+ *
23
+ * Free text is deliberately NOT representable: accepting prose is what lets a
24
+ * reviewer approve its own material. Every kind carries what the SYSTEM observed,
25
+ * because the orchestrator supplies the command/path, never the conclusion.
26
+ */
27
+ export type FindingEvidence = {
28
+ readonly kind: "command";
29
+ readonly command: string;
30
+ readonly expectExit: number;
31
+ /** Exit code the system actually observed, or null when it timed out. */
32
+ readonly actualExit?: number;
33
+ readonly timedOut?: boolean;
34
+ readonly output?: string;
35
+ } | {
36
+ readonly kind: "file";
37
+ readonly path: string;
38
+ readonly lineRange: readonly [number, number];
39
+ readonly expectPattern: string;
40
+ /** Text the system actually read from that range. */
41
+ readonly actualText?: string;
42
+ } | {
43
+ readonly kind: "commit";
44
+ readonly commit: string;
45
+ readonly path: string;
46
+ readonly symbol: string;
47
+ /** Whether the system found the symbol in that path at that commit. */
48
+ readonly symbolFound?: boolean;
49
+ };
50
+ /**
51
+ * Validate one piece of disproval evidence.
52
+ *
53
+ * Every branch reads what the SYSTEM observed (`actualExit`, `actualText`,
54
+ * `symbolFound`), never a conclusion the caller wrote down. A timeout is "not
55
+ * executed", which is not the same as "disproved" -- the same rule every gate in
56
+ * this repo follows: "not checked" must never score as "passed".
57
+ */
58
+ export declare function validateEvidence(evidence: unknown): EvidenceVerdict;
59
+ //# sourceMappingURL=delphi-evidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delphi-evidence.d.ts","sourceRoot":"","sources":["../src/delphi-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAEL;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG,eAAe,CAKnE"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Disproval evidence for a finding: what the SYSTEM observed, never a conclusion.
3
+ *
4
+ * A reviewer disproving its own finding is the one place this mechanism could be
5
+ * turned into a rubber stamp, so free text is not representable here at all.
6
+ * Each kind names the observation the runner must supply (`actualExit`,
7
+ * `actualText`, `symbolFound`), and `validateEvidence` reads only that -- the
8
+ * orchestrator supplies the command or the path, never the verdict.
9
+ *
10
+ * @test REQ-DSH-016
11
+ * @intent 证伪必须由系统实测支撑,不接受"我测过了"式的自由文本,
12
+ * 否则编排者可以给自己放行。
13
+ * @covers AC-DSH-016-03
14
+ */
15
+ /**
16
+ * Validate one piece of disproval evidence.
17
+ *
18
+ * Every branch reads what the SYSTEM observed (`actualExit`, `actualText`,
19
+ * `symbolFound`), never a conclusion the caller wrote down. A timeout is "not
20
+ * executed", which is not the same as "disproved" -- the same rule every gate in
21
+ * this repo follows: "not checked" must never score as "passed".
22
+ */
23
+ export function validateEvidence(evidence) {
24
+ if (typeof evidence !== "object" || evidence === null) {
25
+ return { ok: false, reason: "evidence must be a structured object, not free text" };
26
+ }
27
+ return validatorFor(evidence)(evidence);
28
+ }
29
+ /** Read the `kind` discriminator without trusting the rest of the object. */
30
+ function kindOf(evidence) {
31
+ return typeof evidence === "object" && evidence !== null ? evidence.kind : undefined;
32
+ }
33
+ /**
34
+ * The per-kind validator, or a stand-in that always refuses.
35
+ *
36
+ * Looking the validator up in one table keeps `validateEvidence` at a single
37
+ * branch: three `if kind === ...` checks in a row is the shape that grows a
38
+ * fourth one silently.
39
+ */
40
+ function validatorFor(evidence) {
41
+ const validators = VALIDATORS;
42
+ return validators[String(kindOf(evidence))] ?? refuseUnknown;
43
+ }
44
+ /** Used both as "unknown kind" and as the marker for "no validator found". */
45
+ function refuseUnknown(evidence) {
46
+ const kind = kindOf(evidence);
47
+ return { ok: false, reason: `unknown evidence kind ${String(kind)}` };
48
+ }
49
+ /** First failing rule wins; no rule firing means the evidence holds. */
50
+ function firstFailure(rules, evidence) {
51
+ return rules.map((rule) => rule(evidence)).find((v) => v !== null) ?? null;
52
+ }
53
+ /** A non-empty string check, as a reusable rule. */
54
+ function requireString(value, field) {
55
+ if (typeof value === "string" && value.trim() !== "")
56
+ return null;
57
+ return { ok: false, reason: `${field} must be a non-empty string` };
58
+ }
59
+ const COMMAND_RULES = [
60
+ (e) => requireString(e.command, "command"),
61
+ (e) => e.timedOut === true
62
+ ? { ok: false, reason: "command timed out: it was not executed to completion, so nothing was disproved" }
63
+ : null,
64
+ (e) => Number.isInteger(e.actualExit) && Number.isInteger(e.expectExit)
65
+ ? null
66
+ : { ok: false, reason: "exit codes must be integers: the system recorded no usable exit code" },
67
+ (e) => e.actualExit === e.expectExit
68
+ ? null
69
+ : { ok: false, reason: `exit ${String(e.actualExit)} did not match the expected ${String(e.expectExit)}` },
70
+ ];
71
+ const COMMIT_RULES = [
72
+ (e) => requireString(e.symbol, "symbol"),
73
+ (e) => e.symbolFound === true ? null : { ok: false, reason: "the symbol was not found at that path in that commit" },
74
+ ];
75
+ /** Parse the pattern once; null means it is not a usable regular expression. */
76
+ function compilePattern(pattern) {
77
+ if (typeof pattern !== "string" || pattern === "")
78
+ return null;
79
+ try {
80
+ return new RegExp(pattern);
81
+ }
82
+ catch {
83
+ return null;
84
+ }
85
+ }
86
+ /** The compiled pattern and the text read, or the reason one of them is unusable. */
87
+ function fileEvidenceOf(e) {
88
+ const re = compilePattern(e.expectPattern);
89
+ if (re === null)
90
+ return { ok: false, reason: "expectPattern must be a valid non-empty regular expression" };
91
+ if (typeof e.actualText !== "string") {
92
+ return { ok: false, reason: "the system read no text from the cited range" };
93
+ }
94
+ return { re, text: e.actualText };
95
+ }
96
+ const FILE_RULES = [
97
+ (e) => {
98
+ const prepared = fileEvidenceOf(e);
99
+ if ("ok" in prepared)
100
+ return prepared;
101
+ if (prepared.re.test(prepared.text))
102
+ return null;
103
+ return { ok: false, reason: "the cited code does not contain the expected pattern" };
104
+ },
105
+ ];
106
+ /** Run a rule table and turn "no rule fired" into a pass. */
107
+ function runRules(rules, evidence, okReason) {
108
+ return firstFailure(rules, evidence) ?? { ok: true, reason: okReason };
109
+ }
110
+ /** A command disproves only when the system ran it and got the expected code. */
111
+ function validateCommand(e) {
112
+ return runRules(COMMAND_RULES, e, "command exited as expected");
113
+ }
114
+ /** A file excerpt disproves only when the system found the expected pattern in it. */
115
+ function validateFile(e) {
116
+ return runRules(FILE_RULES, e, "the cited code matches the expected pattern");
117
+ }
118
+ /** A commit assertion disproves only when the system found the symbol there. */
119
+ function validateCommit(e) {
120
+ return runRules(COMMIT_RULES, e, "the symbol exists at the cited commit");
121
+ }
122
+ /** Kind name -> validator. One row per representable evidence shape. */
123
+ const VALIDATORS = {
124
+ command: validateCommand,
125
+ file: validateFile,
126
+ commit: validateCommit,
127
+ };
128
+ //# sourceMappingURL=delphi-evidence.js.map
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The finding ledger: how a review's problems stop being written in prose.
3
+ *
4
+ * A Delphi review's cost is in its ROUNDS, and a round is wasted when a seat that
5
+ * already reported a real problem keeps voting REQUEST_CHANGES after the problem
6
+ * was fixed -- the binary verdict cannot say "still the same five issues, all
7
+ * resolved". `parseVerdict` only knows two words, so the itemization lives here:
8
+ * each problem is a finding with a stable identity, and identity is what lets a
9
+ * later round say "this one is closed" instead of "I still disapprove".
10
+ *
11
+ * Why identity is not a hash of the title: the title is natural language, and
12
+ * Chinese wording, punctuation and code snippets change between rounds. A hash
13
+ * that moves takes the freeze with it -- silently, because nothing errors; the
14
+ * review merely grows a round. So identity is a DETERMINISTIC MATCHER, pinned by
15
+ * tests, not a hope that the model says it the same way twice.
16
+ *
17
+ * @test REQ-DSH-016
18
+ * @intent 让"问题已修好"变成可判定的状态(条目已关闭),而不是靠席位改变措辞;
19
+ * 并把字面稳定性从"模型措辞稳定"转移到"确定性匹配器"。
20
+ * @covers AC-DSH-016-03
21
+ */
22
+ import type { FindingEvidence } from "./delphi-evidence.js";
23
+ export type { FindingEvidence } from "./delphi-evidence.js";
24
+ export { validateEvidence } from "./delphi-evidence.js";
25
+ export type { EvidenceVerdict } from "./delphi-evidence.js";
26
+ /** How bad a finding is. Only critical and major block; minor never does. */
27
+ export type Severity = "critical" | "major" | "minor";
28
+ /**
29
+ * Where a finding is in its life.
30
+ *
31
+ * `disproved` has no way back to `open` on purpose: disproving rests on a
32
+ * measured command or a system-verified code fact, reopening rests on an
33
+ * assertion, and an assertion must not overwrite a measurement. `resolved` CAN
34
+ * reopen, because a fix can be reverted.
35
+ */
36
+ export type FindingStatus = "open" | "resolved" | "disproved";
37
+ /** One problem reported by a seat, tracked across rounds. */
38
+ export interface Finding {
39
+ /** Assigned by the matcher, never by the model. */
40
+ readonly id: string;
41
+ /** The seat that raised it, or `"multi"` once two seats reported the same one. */
42
+ readonly seat: string;
43
+ readonly severity: Severity;
44
+ readonly title: string;
45
+ /** Normalized file path, WITHOUT a line number: line numbers drift. */
46
+ readonly location: string;
47
+ /** Lower-cased ASCII identifiers and backticked fragments; the secondary key. */
48
+ readonly keywords: readonly string[];
49
+ readonly fix: string;
50
+ readonly status: FindingStatus;
51
+ readonly evidence?: FindingEvidence;
52
+ readonly statusChangedAtRound: number;
53
+ /**
54
+ * Every seat that raised this finding, in the order they did.
55
+ *
56
+ * `seat` alone collapses to "multi" once a second seat agrees, and "multi"
57
+ * equals no role -- so a shared finding became impossible to settle and blocked
58
+ * consensus forever. The owner SET is what the ledger closes against.
59
+ */
60
+ readonly raisedBy?: readonly string[];
61
+ /**
62
+ * Set when a candidate fell in the uncertain band next to a settled entry: it
63
+ * got a NEW id (never merged on a guess) but names what it may belong to, so a
64
+ * human can join them deliberately.
65
+ */
66
+ readonly candidateOf?: string;
67
+ }
68
+ /** A finding the matcher is asked to identify, before an id has been decided. */
69
+ export interface CandidateFinding {
70
+ readonly seat: string;
71
+ readonly severity: Severity;
72
+ readonly title: string;
73
+ readonly location: string;
74
+ readonly fix: string;
75
+ }
76
+ /**
77
+ * Outcome of matching one candidate against the ledger.
78
+ *
79
+ * `matchingDisproved` names the settled entry a candidate resembles closely
80
+ * enough that minting a new id for it would be re-filing a disproved defect
81
+ * under another path -- the caller must see it before treating the new id as
82
+ * legitimate (design §2.2).
83
+ */
84
+ export interface MatchOutcome {
85
+ readonly finding: Finding;
86
+ readonly reused: boolean;
87
+ readonly matchingDisproved?: Finding;
88
+ }
89
+ /**
90
+ * The identifiers and backticked fragments in a title, lower-cased and deduped.
91
+ *
92
+ * ASCII only, deliberately: Chinese word segmentation is itself unstable, and an
93
+ * unstable key on the secondary index reproduces the drift a hash would have.
94
+ */
95
+ export declare function extractKeywords(title: string): string[];
96
+ /**
97
+ * A location without its line number.
98
+ *
99
+ * Line numbers move when an unrelated line is inserted above, which would make
100
+ * one finding look like two and defeat the freeze. The path is the stable part.
101
+ */
102
+ export declare function normalizeLocation(location: string): string;
103
+ /**
104
+ * Jaccard overlap of two keyword sets (|intersection| / |union|).
105
+ *
106
+ * Returns 0 below the keyword minimum. The guard lives HERE, not only in the
107
+ * caller: a one-keyword set has Jaccard 0 or 1 and nothing between, so a public
108
+ * score reporting 1.0 for two identical single words invites exactly the caller
109
+ * that merges on it.
110
+ */
111
+ export declare function keywordOverlap(a: readonly string[], b: readonly string[]): number;
112
+ /**
113
+ * Give a candidate its identity, reusing an existing id when it is the same
114
+ * finding.
115
+ *
116
+ * The model's own `id` is never consulted: it is a hint for humans, and letting
117
+ * it be authoritative would let a drifting model reset a frozen id by renaming
118
+ * it.
119
+ */
120
+ export declare function matchFinding(candidate: CandidateFinding, ledger: readonly Finding[]): MatchOutcome;
121
+ export type { SeatState } from "./delphi-seats.js";
122
+ export { blockingFindings, releaseSeats } from "./delphi-seats.js";
123
+ //# sourceMappingURL=delphi-finding.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