@boyingliu01/xp-gate 0.41.10 → 0.41.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/adapters/gate-3.sh +28 -1
  2. package/adapters/gate-6-layers.sh +18 -1
  3. package/bin/xp-gate.js +13 -0
  4. package/gate-3.sh +28 -1
  5. package/gate-6-layers.sh +18 -1
  6. package/gates/python-health.ts +74 -26
  7. package/gates/test-layers.ts +94 -9
  8. package/hooks/gate-3.sh +28 -1
  9. package/hooks/gate-6-layers.sh +18 -1
  10. package/hooks/gate-entries/gate-11-entry.sh +21 -0
  11. package/hooks/gate-entries/gate-2-entry.sh +15 -0
  12. package/hooks/install.sh +15 -3
  13. package/hooks/pre-commit +90 -13
  14. package/hooks/pre-push +10 -1
  15. package/hooks/sprint-gate.sh +101 -13
  16. package/lib/check-alignment-runner.cjs +97 -0
  17. package/lib/check.js +6 -0
  18. package/lib/crap-cli.js +14 -6
  19. package/lib/delphi-setup.js +13 -0
  20. package/lib/doctor-tui.js +205 -102
  21. package/lib/doctor.js +146 -7
  22. package/lib/gate-runner.js +14 -3
  23. package/lib/init-install.js +299 -0
  24. package/lib/init-languages.js +158 -0
  25. package/lib/init-manifest.js +165 -0
  26. package/lib/init-md-injection.js +58 -0
  27. package/lib/init.js +134 -500
  28. package/lib/install-skill.js +66 -1
  29. package/lib/layer-baseline.cjs +94 -0
  30. package/lib/mattpocock-license-verdict.json +7 -0
  31. package/lib/uninstall-skills.js +140 -0
  32. package/lib/uninstall.js +41 -100
  33. package/lib/update-skill.js +9 -1
  34. package/package.json +3 -1
  35. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  36. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  37. package/plugins/claude-code/skills/delphi-review/INSTALL.md +22 -3
  38. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  39. package/plugins/claude-code/skills/sprint-flow/references/definition-of-done.md +2 -2
  40. package/plugins/claude-code/skills/sprint-flow/references/phase-3-build.md +1 -1
  41. package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +2 -2
  42. package/plugins/claude-code/skills/sprint-flow/references/phase-6-close.md +17 -0
  43. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  44. package/plugins/dsh/lib/delphi-evidence.d.ts +59 -0
  45. package/plugins/dsh/lib/delphi-evidence.d.ts.map +1 -0
  46. package/plugins/dsh/lib/delphi-evidence.js +128 -0
  47. package/plugins/dsh/lib/delphi-finding.d.ts +123 -0
  48. package/plugins/dsh/lib/delphi-finding.d.ts.map +1 -0
  49. package/plugins/dsh/lib/delphi-finding.js +332 -0
  50. package/plugins/dsh/lib/delphi-findings-parse.d.ts +29 -0
  51. package/plugins/dsh/lib/delphi-findings-parse.d.ts.map +1 -0
  52. package/plugins/dsh/lib/delphi-findings-parse.js +138 -0
  53. package/plugins/dsh/lib/delphi-ledger.d.ts +55 -0
  54. package/plugins/dsh/lib/delphi-ledger.d.ts.map +1 -0
  55. package/plugins/dsh/lib/delphi-ledger.js +124 -0
  56. package/plugins/dsh/lib/delphi-run.d.ts +7 -0
  57. package/plugins/dsh/lib/delphi-run.d.ts.map +1 -1
  58. package/plugins/dsh/lib/delphi-run.js +48 -18
  59. package/plugins/dsh/lib/delphi-seats.d.ts +34 -0
  60. package/plugins/dsh/lib/delphi-seats.d.ts.map +1 -0
  61. package/plugins/dsh/lib/delphi-seats.js +40 -0
  62. package/plugins/dsh/lib/evidence.d.ts +21 -0
  63. package/plugins/dsh/lib/evidence.d.ts.map +1 -1
  64. package/plugins/dsh/lib/evidence.js +3 -0
  65. package/plugins/dsh/lib/index.d.ts.map +1 -1
  66. package/plugins/dsh/lib/index.js +12 -0
  67. package/plugins/dsh/package.json +1 -1
  68. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  69. package/plugins/dsh/skills/delphi-review/INSTALL.md +22 -3
  70. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  71. package/plugins/dsh/skills/sprint-flow/references/definition-of-done.md +2 -2
  72. package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +1 -1
  73. package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +2 -2
  74. package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +17 -0
  75. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  76. package/plugins/dsh/src/delphi-evidence.test.ts +100 -0
  77. package/plugins/dsh/src/delphi-evidence.ts +201 -0
  78. package/plugins/dsh/src/delphi-finding.test.ts +333 -0
  79. package/plugins/dsh/src/delphi-finding.ts +446 -0
  80. package/plugins/dsh/src/delphi-findings-parse.test.ts +100 -0
  81. package/plugins/dsh/src/delphi-findings-parse.ts +158 -0
  82. package/plugins/dsh/src/delphi-findings.test.ts +4 -0
  83. package/plugins/dsh/src/delphi-ledger.test.ts +210 -0
  84. package/plugins/dsh/src/delphi-ledger.ts +158 -0
  85. package/plugins/dsh/src/delphi-run.test.ts +71 -68
  86. package/plugins/dsh/src/delphi-run.ts +80 -24
  87. package/plugins/dsh/src/delphi-seats.test.ts +117 -0
  88. package/plugins/dsh/src/delphi-seats.ts +50 -0
  89. package/plugins/dsh/src/evidence-findings.test.ts +75 -0
  90. package/plugins/dsh/src/evidence.ts +25 -0
  91. package/plugins/dsh/src/index.ts +14 -0
  92. package/plugins/opencode/package.json +1 -1
  93. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  94. package/plugins/opencode/skills/delphi-review/INSTALL.md +22 -3
  95. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  96. package/plugins/opencode/skills/sprint-flow/references/definition-of-done.md +2 -2
  97. package/plugins/opencode/skills/sprint-flow/references/phase-3-build.md +1 -1
  98. package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +2 -2
  99. package/plugins/opencode/skills/sprint-flow/references/phase-6-close.md +17 -0
  100. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  101. package/plugins/qoder/plugin.json +1 -1
  102. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  103. package/plugins/qoder/skills/delphi-review/INSTALL.md +22 -3
  104. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  105. package/plugins/qoder/skills/sprint-flow/references/definition-of-done.md +2 -2
  106. package/plugins/qoder/skills/sprint-flow/references/phase-3-build.md +1 -1
  107. package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +2 -2
  108. package/plugins/qoder/skills/sprint-flow/references/phase-6-close.md +17 -0
  109. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  110. package/principles/index.ts +50 -1
  111. package/scripts/delphi-config-read.cjs +43 -6
  112. package/scripts/delphi-external-review.cjs +69 -12
  113. package/scripts/delphi-prompts.cjs +47 -1
  114. package/skills/delphi-review/AGENTS.md +1 -1
  115. package/skills/delphi-review/INSTALL.md +22 -3
  116. package/skills/sprint-flow/AGENTS.md +1 -1
  117. package/skills/sprint-flow/references/definition-of-done.md +2 -2
  118. package/skills/sprint-flow/references/phase-3-build.md +1 -1
  119. package/skills/sprint-flow/references/phase-4-verify.md +2 -2
  120. package/skills/sprint-flow/references/phase-6-close.md +17 -0
  121. package/skills/test-specification-alignment/AGENTS.md +1 -1
  122. package/sprint-gate.sh +101 -13
  123. package/mutation/stryker-types.ts +0 -14
@@ -12,15 +12,34 @@ This guide walks you through setting up the Delphi consensus review skill in you
12
12
 
13
13
  ## Quick Setup (3 steps)
14
14
 
15
- ### Step 1: Copy the configuration template
15
+ ### Step 1: Create ONE configuration, machine-wide by default
16
+
17
+ Two locations are read, and **a project-root file always wins over the machine-wide
18
+ one**. That precedence is the single most important thing on this page:
19
+
20
+ | Location | Scope | When to use it |
21
+ |---|---|---|
22
+ | `~/.config/xp-gate/.delphi-config.json` | every project on this machine | **the normal choice** |
23
+ | `<repo>/.delphi-config.json` | that repo only, and it **overrides** the above | only to pin different seats for one repo |
16
24
 
17
25
  ```bash
18
- # From your project root (where opencode.json lives):
19
- cp skills/delphi-review/.delphi-config.json.example .delphi-config.json
26
+ # Recommended: one config for the whole machine.
27
+ mkdir -p ~/.config/xp-gate
28
+ cp skills/delphi-review/.delphi-config.json.example ~/.config/xp-gate/.delphi-config.json
20
29
  ```
21
30
 
31
+ > **If you copy it into the repo root instead, every later edit to the machine-wide
32
+ > config becomes a no-op for that repo.** `xp-gate doctor delphi` reports this as
33
+ > `Delphi config shadow (#541)`; deleting the repo-root copy makes it go away. Do not
34
+ > put a copy in every project "to be safe" — that is what creates the shadow. Measured
35
+ > 2026-11-17: a consumer followed the old version of this page, then fixed the global
36
+ > seats and kept getting the old ones, because the repo copy silently won.
37
+
22
38
  This file maps abstract expert roles to agent names. You typically don't need to edit this unless you want custom agent names.
23
39
 
40
+ Pass `--config <path>` to point at a specific file for one run; a relative path that
41
+ does not exist in the current directory falls back to the machine-wide config.
42
+
24
43
  ### Step 2: Add agent definitions to opencode.json
25
44
 
26
45
  Copy the `agent` block from `skills/delphi-review/opencode.json.delphi.example` into your `opencode.json`.
@@ -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.52.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.
@@ -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.52.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
package/sprint-gate.sh CHANGED
@@ -176,6 +176,48 @@ read_phase() {
176
176
 
177
177
  # --- Helper: read delphi verdict ---
178
178
  # Returns verdict string or empty if unreadable
179
+ # --- Helper: an ISO-8601 timestamp as epoch seconds, or empty ---
180
+ # Extracted from read_sprint_age_days so the verdict-vs-sprint comparison (#807) parses
181
+ # dates the same way the age check does. Two parsers would be two chances to disagree.
182
+ iso_to_epoch() {
183
+ local iso="$1"
184
+ [ -n "$iso" ] && [ "$iso" != "null" ] || { echo ""; return; }
185
+ local epoch=""
186
+ # GNU date first, BSD date second, node last.
187
+ epoch=$(date -u -d "$iso" +%s 2>/dev/null || true)
188
+ if [ -z "$epoch" ]; then epoch=$(date -u -j -f "%Y-%m-%dT%H:%M:%S" "${iso%%.*}Z" +%s 2>/dev/null || true); fi
189
+ if [ -z "$epoch" ] && command -v node >/dev/null 2>&1; then
190
+ epoch=$(node -e "const t=Date.parse(process.argv[1]); if(Number.isFinite(t)) console.log(Math.floor(t/1000))" "$iso" 2>/dev/null || true)
191
+ fi
192
+ echo "$epoch"
193
+ }
194
+
195
+ # --- Helper: does the approval belong to the CURRENT sprint? (#807) ---
196
+ # Prints "yes", "no", or "unknown". An approval dated BEFORE the sprint started belongs to
197
+ # a previous sprint and endorses nothing: measured in a consumer repo, a verdict from 22
198
+ # days before the sprint licensed `checks-passed` on every commit afterwards, and the
199
+ # message told the user their change had been reviewed.
200
+ #
201
+ # "unknown" is returned rather than "yes" when either date is unreadable, so the caller can
202
+ # refuse instead of assuming the approval is current.
203
+ approval_is_current() {
204
+ local sprint_started approved_at start_epoch approved_epoch
205
+ sprint_started=$(json_extract "$SPRINT_STATE_JSON" '.started_at // ""' 2>/dev/null || echo "")
206
+ approved_at=$(json_extract "$APPROVED_FILE" '.timestamp // ""' 2>/dev/null || echo "")
207
+ if [ -z "$sprint_started" ] || [ -z "$approved_at" ] \
208
+ || [ "$sprint_started" = "null" ] || [ "$approved_at" = "null" ]; then
209
+ echo "unknown"
210
+ return
211
+ fi
212
+ start_epoch=$(iso_to_epoch "$sprint_started")
213
+ approved_epoch=$(iso_to_epoch "$approved_at")
214
+ if [ -z "$start_epoch" ] || [ -z "$approved_epoch" ]; then
215
+ echo "unknown"
216
+ return
217
+ fi
218
+ if [ "$approved_epoch" -lt "$start_epoch" ]; then echo "no"; else echo "yes"; fi
219
+ }
220
+
179
221
  read_verdict() {
180
222
  if [ ! -f "$APPROVED_FILE" ]; then
181
223
  echo ""
@@ -219,7 +261,23 @@ read_sprint_age_days() {
219
261
  if [ -z "$started" ] || [ "$started" = "null" ]; then
220
262
  started=$(json_extract "$SPRINT_STATE_JSON" '.updated_at // ""' 2>/dev/null || echo "")
221
263
  fi
264
+ # #865: last resort is the state file's own mtime. Without it, a state file
265
+ # written before started_at existed reports "age unknown" forever -- and the
266
+ # measured case was a sprint untouched for over a year whose age could not be
267
+ # computed from the file that had been sitting there unmodified the whole time.
268
+ #
269
+ # mtime is a LOWER bound on idleness, not an exact start: an edit to the file
270
+ # resets it. That is the honest reading -- "nothing has touched this sprint's
271
+ # state since then" -- and it is strictly better than "unknown".
222
272
  if [ -z "$started" ] || [ "$started" = "null" ]; then
273
+ local mtime_epoch now_epoch
274
+ mtime_epoch=$(stat -c %Y "$SPRINT_STATE_JSON" 2>/dev/null || stat -f %m "$SPRINT_STATE_JSON" 2>/dev/null || echo "")
275
+ now_epoch=$(date +%s 2>/dev/null || echo "")
276
+ if [ -n "$mtime_epoch" ] && [ -n "$now_epoch" ] \
277
+ && [ "$mtime_epoch" -gt 0 ] 2>/dev/null && [ "$now_epoch" -gt 0 ] 2>/dev/null; then
278
+ echo $(( (now_epoch - mtime_epoch) / 86400 ))
279
+ return
280
+ fi
223
281
  echo ""
224
282
  return
225
283
  fi
@@ -251,6 +309,20 @@ read_sprint_age_days() {
251
309
  # enough that the reported 12-day case is caught within two days of it firing.
252
310
  SPRINT_STALE_DAYS="${SPRINT_STALE_DAYS:-14}"
253
311
 
312
+ # Whether the sprint looks abandoned (#551, reordered by #865).
313
+ #
314
+ # Sets SPRINT_AGE_DAYS as a side effect, because the caller reports it. Returns 0
315
+ # when the sprint is stale, 1 otherwise -- including when the age is unknown, since
316
+ # an unmeasurable sprint is not evidence of staleness.
317
+ sprint_is_stale() {
318
+ SPRINT_STATUS=$(read_sprint_status)
319
+ SPRINT_AGE_DAYS=$(read_sprint_age_days)
320
+ [ "$SPRINT_STATUS" = "in_progress" ] || return 1
321
+ [ -n "$SPRINT_AGE_DAYS" ] || return 1
322
+ [ "$SPRINT_AGE_DAYS" -ge "$SPRINT_STALE_DAYS" ] 2>/dev/null || return 1
323
+ return 0
324
+ }
325
+
254
326
  # --- Pre-commit mode ---
255
327
  if [ "$MODE" = "pre-commit" ]; then
256
328
  PHASE=$(read_phase)
@@ -267,6 +339,22 @@ if [ "$MODE" = "pre-commit" ]; then
267
339
 
268
340
  # Phase >= 1 means PLAN is completed — delphi-review must be APPROVED
269
341
  if [ "$PHASE" -ge 1 ] 2>/dev/null; then
342
+ # #865: staleness FIRST, before any approval check.
343
+ #
344
+ # This block used to sit after them, so it was only reachable when
345
+ # delphi-reviewed.json existed. A sprint abandoned a year ago but never
346
+ # approved therefore hit "delphi-review not APPROVED" and was DENIED -- the
347
+ # same hard block a sprint opened this morning gets. #551 had already fixed the
348
+ # opposite error (zombie reading as PASS); this is that fix's other side, and
349
+ # the `skip` it should give was unreachable between the two.
350
+ #
351
+ # Ordering is the whole fix: "nobody is driving this sprint" is a fact about
352
+ # the sprint, and it does not become false because an approval file is missing.
353
+ if sprint_is_stale; then
354
+ echo "{\"decision\":\"skip\",\"reason\":\"STALE SPRINT: status=in_progress for ${SPRINT_AGE_DAYS} days (threshold ${SPRINT_STALE_DAYS}) — not certifying it. Finish it (sprint-flow close) or clear .sprint-state/sprint-state.json\"}"
355
+ exit 0
356
+ fi
357
+
270
358
  # Check if delphi-reviewed.json exists
271
359
  if [ ! -f "$APPROVED_FILE" ]; then
272
360
  echo '{"decision":"deny","reason":"delphi-review not APPROVED. Complete Phase 1 before committing code changes."}'
@@ -291,21 +379,21 @@ if [ "$MODE" = "pre-commit" ]; then
291
379
  echo "{\"decision\":\"deny\",\"reason\":\"delphi-review verdict is '${VERDICT}', not APPROVED. Fix issues and re-run: /delphi-review\"}"
292
380
  exit 1
293
381
  fi
294
-
295
- # #551: staleness. A sprint left at status=in_progress past the threshold is
296
- # abandoned, not validated -- reporting PASS for it means the gate cannot
297
- # distinguish an advancing sprint from a forgotten one, and it injects
298
- # ancient phase_history into every unrelated commit's audit trail. SKIP is
299
- # the honest answer: the gate declines to certify a sprint nobody is
300
- # driving, without blocking work that has nothing to do with it.
301
- SPRINT_STATUS=$(read_sprint_status)
302
- SPRINT_AGE_DAYS=$(read_sprint_age_days)
303
- if [ "$SPRINT_STATUS" = "in_progress" ] && [ -n "$SPRINT_AGE_DAYS" ] \
304
- && [ "$SPRINT_AGE_DAYS" -ge "$SPRINT_STALE_DAYS" ] 2>/dev/null; then
305
- echo "{\"decision\":\"skip\",\"reason\":\"STALE SPRINT: status=in_progress for ${SPRINT_AGE_DAYS} days (threshold ${SPRINT_STALE_DAYS}) — not certifying it. Finish it (sprint-flow close) or clear .sprint-state/sprint-state.json\"}"
306
- exit 0
382
+ # #807: the approval must belong to THIS sprint. The verdict file is not cleared when
383
+ # a sprint closes, so a leftover APPROVED endorsed every commit afterwards with the
384
+ # message "delphi-review APPROVED" -- and nothing downstream could notice, because the
385
+ # gate reported success.
386
+ APPROVAL_CURRENT=$(approval_is_current)
387
+ if [ "$APPROVAL_CURRENT" != "yes" ]; then
388
+ echo "{\"decision\":\"deny\",\"reason\":\"delphi-reviewed.json ${APPROVAL_CURRENT} a current approval: verdict=${VERDICT}, approval timestamp=$(json_extract "$APPROVED_FILE" '.timestamp // \"(none)\"' 2>/dev/null), sprint started_at=$(json_extract "$SPRINT_STATE_JSON" '.started_at // \"(none)\"' 2>/dev/null). Re-run: /delphi-review\"}"
389
+ exit 1
307
390
  fi
308
391
 
392
+ # The staleness verdict was taken above, BEFORE the approval checks (#865).
393
+ # It is not repeated here: a second copy would be a second place to keep
394
+ # correct, and the reported defect was precisely this check living in the
395
+ # wrong spot.
396
+
309
397
  # All checks passed. Name the age so "validated" is not an unconditional
310
398
  # claim: a 29-day-old sprint under a 30-day threshold is a very different
311
399
  # situation from one opened today, and the log should say which it is.
@@ -1,14 +0,0 @@
1
- export interface StrykerFileReport {
2
- mutationScore: number;
3
- nrOfMutants: number;
4
- nrOfKilledMutants: number;
5
- nrOfSurvivedMutants: number;
6
- }
7
-
8
- export interface StrykerReport {
9
- mutationScore: number;
10
- nrOfMutants: number;
11
- nrOfKilledMutants: number;
12
- nrOfSurvivedMutants: number;
13
- files?: Record<string, StrykerFileReport>;
14
- }