@holmes-lab/holmes-kit 0.39.0 → 0.40.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 (325) hide show
  1. package/CHANGELOG.md +578 -6
  2. package/README.md +120 -41
  3. package/dist/.build-id +1 -1
  4. package/dist/holmes/admission/core/admission-policy.d.ts +37 -0
  5. package/dist/holmes/admission/core/admission-policy.js +147 -0
  6. package/dist/holmes/admission/core/bounded-reader.d.ts +56 -0
  7. package/dist/holmes/admission/core/bounded-reader.js +135 -0
  8. package/dist/holmes/admission/core/change-classifier.d.ts +34 -0
  9. package/dist/holmes/admission/core/change-classifier.js +278 -0
  10. package/dist/holmes/admission/core/config-loader.d.ts +30 -0
  11. package/dist/holmes/admission/core/config-loader.js +145 -0
  12. package/dist/holmes/admission/core/event-judgement.d.ts +37 -0
  13. package/dist/holmes/admission/core/event-judgement.js +251 -0
  14. package/dist/holmes/admission/core/path-rules.d.ts +35 -0
  15. package/dist/holmes/admission/core/path-rules.js +88 -0
  16. package/dist/holmes/admission/core/pin.d.ts +7 -0
  17. package/dist/holmes/admission/core/pin.js +29 -0
  18. package/dist/holmes/admission/core/ports.d.ts +48 -0
  19. package/dist/holmes/admission/core/ports.js +11 -0
  20. package/dist/holmes/admission/core/range-resolver.d.ts +32 -0
  21. package/dist/holmes/admission/core/range-resolver.js +51 -0
  22. package/dist/holmes/admission/core/self-containment.d.ts +1 -0
  23. package/dist/holmes/admission/core/self-containment.js +125 -0
  24. package/dist/holmes/admission/core/signature-source.d.ts +9 -0
  25. package/dist/holmes/admission/core/signature-source.js +4 -0
  26. package/dist/holmes/admission/core/transition-planner.d.ts +15 -0
  27. package/dist/holmes/admission/core/transition-planner.js +14 -0
  28. package/dist/holmes/admission/core/verdict.d.ts +38 -0
  29. package/dist/holmes/admission/core/verdict.js +17 -0
  30. package/dist/holmes/admission/core/wiring.d.ts +44 -0
  31. package/dist/holmes/admission/core/wiring.js +618 -0
  32. package/dist/holmes/admission/forge/git-object-port.d.ts +4 -0
  33. package/dist/holmes/admission/forge/git-object-port.js +132 -0
  34. package/dist/holmes/assoc/assoc-arm.d.ts +1 -1
  35. package/dist/holmes/assoc/assoc-arm.js +1 -1
  36. package/dist/holmes/cli/agents.d.ts +8 -0
  37. package/dist/holmes/cli/agents.js +9 -5
  38. package/dist/holmes/cli/approve-cli.d.ts +2 -0
  39. package/dist/holmes/cli/approve-cli.js +392 -0
  40. package/dist/holmes/cli/approve-ref.d.ts +13 -7
  41. package/dist/holmes/cli/approve-ref.js +30 -10
  42. package/dist/holmes/cli/approve-status.d.ts +26 -2
  43. package/dist/holmes/cli/approve-status.js +98 -18
  44. package/dist/holmes/cli/approve-watch.d.ts +5 -0
  45. package/dist/holmes/cli/approve-watch.js +10 -5
  46. package/dist/holmes/cli/approve.d.ts +49 -13
  47. package/dist/holmes/cli/approve.js +249 -67
  48. package/dist/holmes/cli/attest.js +2 -1
  49. package/dist/holmes/cli/autonomy.d.ts +4 -1
  50. package/dist/holmes/cli/autonomy.js +17 -10
  51. package/dist/holmes/cli/codex-oracle.d.ts +11 -0
  52. package/dist/holmes/cli/codex-oracle.js +5 -1
  53. package/dist/holmes/cli/codex-toml.d.ts +10 -0
  54. package/dist/holmes/cli/codex-toml.js +36 -2
  55. package/dist/holmes/cli/doctor-boundary.d.ts +76 -0
  56. package/dist/holmes/cli/doctor-boundary.js +308 -0
  57. package/dist/holmes/cli/doctor-locks.d.ts +15 -0
  58. package/dist/holmes/cli/doctor-locks.js +119 -0
  59. package/dist/holmes/cli/doctor.d.ts +2 -0
  60. package/dist/holmes/cli/doctor.js +34 -5
  61. package/dist/holmes/cli/flags.d.ts +23 -0
  62. package/dist/holmes/cli/flags.js +89 -0
  63. package/dist/holmes/cli/index.d.ts +5 -1
  64. package/dist/holmes/cli/index.js +226 -442
  65. package/dist/holmes/cli/init.js +33 -0
  66. package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
  67. package/dist/holmes/cli/interactive-prompt.js +98 -16
  68. package/dist/holmes/cli/lock-recover.d.ts +5 -0
  69. package/dist/holmes/cli/lock-recover.js +126 -0
  70. package/dist/holmes/cli/mcp-processes.js +1 -1
  71. package/dist/holmes/cli/release-docs.js +1 -1
  72. package/dist/holmes/cli/run-exec.d.ts +141 -0
  73. package/dist/holmes/cli/run-exec.js +1435 -0
  74. package/dist/holmes/cli/run-provision.d.ts +3 -1
  75. package/dist/holmes/cli/run-provision.js +255 -44
  76. package/dist/holmes/cli/run-wiring.d.ts +69 -0
  77. package/dist/holmes/cli/run-wiring.js +270 -0
  78. package/dist/holmes/cli/run.d.ts +21 -0
  79. package/dist/holmes/cli/run.js +341 -92
  80. package/dist/holmes/cli/runtime-binding-approval.js +32 -19
  81. package/dist/holmes/cli/screen-safe.d.ts +3 -92
  82. package/dist/holmes/cli/screen-safe.js +18 -756
  83. package/dist/holmes/config/config.d.ts +19 -0
  84. package/dist/holmes/config/config.js +18 -3
  85. package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
  86. package/dist/holmes/cpg/import-resolver.js +1 -1
  87. package/dist/holmes/governance/approval-decisions.d.ts +47 -0
  88. package/dist/holmes/governance/approval-decisions.js +29 -0
  89. package/dist/holmes/governance/approval-grants.d.ts +220 -1
  90. package/dist/holmes/governance/approval-grants.js +612 -33
  91. package/dist/holmes/governance/approval-queue.d.ts +26 -0
  92. package/dist/holmes/governance/approval-queue.js +109 -11
  93. package/dist/holmes/governance/approval-spend.d.ts +95 -0
  94. package/dist/holmes/governance/approval-spend.js +191 -0
  95. package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
  96. package/dist/holmes/governance/autonomous-shell.js +332 -0
  97. package/dist/holmes/governance/autonomy.d.ts +12 -0
  98. package/dist/holmes/governance/autonomy.js +51 -15
  99. package/dist/holmes/governance/constitution.d.ts +5 -0
  100. package/dist/holmes/governance/constitution.js +32 -12
  101. package/dist/holmes/governance/full-autonomy.d.ts +10 -0
  102. package/dist/holmes/governance/full-autonomy.js +103 -7
  103. package/dist/holmes/governance/harness-catalog.d.ts +103 -0
  104. package/dist/holmes/governance/harness-catalog.js +348 -0
  105. package/dist/holmes/governance/human-channel.d.ts +38 -0
  106. package/dist/holmes/governance/human-channel.js +49 -0
  107. package/dist/holmes/governance/install-manifest.d.ts +22 -0
  108. package/dist/holmes/governance/install-manifest.js +160 -0
  109. package/dist/holmes/governance/ledger-rechain.js +2 -0
  110. package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
  111. package/dist/holmes/governance/ledger-store.conformance.js +66 -0
  112. package/dist/holmes/governance/ledger-store.d.ts +88 -11
  113. package/dist/holmes/governance/ledger-store.js +186 -8
  114. package/dist/holmes/governance/provenance-chain.d.ts +16 -4
  115. package/dist/holmes/governance/provenance-chain.js +19 -4
  116. package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
  117. package/dist/holmes/governance/provenance-ledger.js +53 -18
  118. package/dist/holmes/governance/push-gate-runner.d.ts +2 -0
  119. package/dist/holmes/governance/push-gate-runner.js +50 -9
  120. package/dist/holmes/governance/push-gate.d.ts +13 -2
  121. package/dist/holmes/governance/push-gate.js +106 -14
  122. package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
  123. package/dist/holmes/governance/recorded-pairs.js +522 -0
  124. package/dist/holmes/governance/replica-id.d.ts +1 -1
  125. package/dist/holmes/governance/replica-id.js +1 -1
  126. package/dist/holmes/governance/spec-seam.d.ts +59 -0
  127. package/dist/holmes/governance/spec-seam.js +587 -0
  128. package/dist/holmes/governance/spend-kinds.d.ts +16 -0
  129. package/dist/holmes/governance/spend-kinds.js +18 -0
  130. package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
  131. package/dist/holmes/guardrail/advisory-line.js +718 -0
  132. package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
  133. package/dist/holmes/guardrail/decision-ledger.js +2 -1
  134. package/dist/holmes/guardrail/impact-gate.d.ts +7 -0
  135. package/dist/holmes/guardrail/impact-gate.js +33 -6
  136. package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
  137. package/dist/holmes/guardrail/line-continuation.js +39 -0
  138. package/dist/holmes/guardrail/operator-person.d.ts +28 -4
  139. package/dist/holmes/guardrail/operator-person.js +57 -11
  140. package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
  141. package/dist/holmes/guardrail/refusal-codes.js +64 -10
  142. package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
  143. package/dist/holmes/guardrail/risk-classifier.js +228 -16
  144. package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
  145. package/dist/holmes/guardrail/risk-gate.js +7 -34
  146. package/dist/holmes/guardrail/risk-types.d.ts +10 -0
  147. package/dist/holmes/guardrail/run-plan-scope.js +3 -1
  148. package/dist/holmes/guardrail/run-refusals.js +24 -8
  149. package/dist/holmes/guardrail/run-stages.d.ts +5 -0
  150. package/dist/holmes/guardrail/run-stages.js +25 -5
  151. package/dist/holmes/guardrail/scope-judgment.js +1 -1
  152. package/dist/holmes/guardrail/shell-words.js +24 -3
  153. package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
  154. package/dist/holmes/guardrail/unresolved-write.js +556 -0
  155. package/dist/holmes/guardrail/write-target.d.ts +3 -0
  156. package/dist/holmes/guardrail/write-target.js +26 -5
  157. package/dist/holmes/hooks/pre-tool-use.d.ts +116 -1
  158. package/dist/holmes/hooks/pre-tool-use.js +1176 -170
  159. package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
  160. package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
  161. package/dist/holmes/hooks/session-start.js +17 -1
  162. package/dist/holmes/hooks/stop.d.ts +23 -0
  163. package/dist/holmes/hooks/stop.js +86 -33
  164. package/dist/holmes/mcp/approval-adapters.js +3 -1
  165. package/dist/holmes/mcp/approval-commit.js +3 -2
  166. package/dist/holmes/mcp/approval-policy.d.ts +2 -1
  167. package/dist/holmes/mcp/approval-policy.js +3 -1
  168. package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
  169. package/dist/holmes/mcp/handlers/approval-ask.d.ts +3 -0
  170. package/dist/holmes/mcp/handlers/approval-ask.js +18 -7
  171. package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
  172. package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
  173. package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
  174. package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
  175. package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
  176. package/dist/holmes/mcp/handlers/entity-store.js +133 -59
  177. package/dist/holmes/mcp/handlers/maintenance-analysis.d.ts +13 -0
  178. package/dist/holmes/mcp/handlers/maintenance-analysis.js +59 -2
  179. package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
  180. package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
  181. package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
  182. package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
  183. package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
  184. package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
  185. package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
  186. package/dist/holmes/mcp/handlers/review-queries.js +8 -1
  187. package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
  188. package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
  189. package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
  190. package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
  191. package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
  192. package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
  193. package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
  194. package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
  195. package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
  196. package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
  197. package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
  198. package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
  199. package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
  200. package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
  201. package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
  202. package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
  203. package/dist/holmes/mcp/handlers/test-execution.d.ts +471 -4
  204. package/dist/holmes/mcp/handlers/test-execution.js +199 -21
  205. package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
  206. package/dist/holmes/mcp/handlers.d.ts +557 -82
  207. package/dist/holmes/mcp/handlers.js +74 -23
  208. package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
  209. package/dist/holmes/mcp/harness-attestation.js +325 -53
  210. package/dist/holmes/mcp/maintenance-analyze.d.ts +6 -1
  211. package/dist/holmes/mcp/maintenance-analyze.js +13 -11
  212. package/dist/holmes/mcp/maintenance-evidence.d.ts +9 -0
  213. package/dist/holmes/mcp/maintenance-evidence.js +35 -3
  214. package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
  215. package/dist/holmes/mcp/server-staleness.js +1 -1
  216. package/dist/holmes/mcp/server.js +9 -8
  217. package/dist/holmes/mcp/spec-id-guard.js +1 -1
  218. package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
  219. package/dist/holmes/mcp/tool-schemas.js +42 -9
  220. package/dist/holmes/project/act-root.d.ts +19 -0
  221. package/dist/holmes/project/act-root.js +100 -0
  222. package/dist/holmes/project/baseline.d.ts +15 -2
  223. package/dist/holmes/project/baseline.js +14 -8
  224. package/dist/holmes/project/bounded-group.d.ts +47 -0
  225. package/dist/holmes/project/bounded-group.js +140 -0
  226. package/dist/holmes/project/bounded-io.d.ts +51 -2
  227. package/dist/holmes/project/bounded-io.js +140 -6
  228. package/dist/holmes/project/change-source.d.ts +4 -0
  229. package/dist/holmes/project/change-source.js +14 -6
  230. package/dist/holmes/project/instance-id.d.ts +10 -0
  231. package/dist/holmes/project/instance-id.js +233 -0
  232. package/dist/holmes/project/machine-identity.d.ts +25 -0
  233. package/dist/holmes/project/machine-identity.js +133 -0
  234. package/dist/holmes/project/owned-lock.d.ts +84 -0
  235. package/dist/holmes/project/owned-lock.js +263 -0
  236. package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
  237. package/dist/holmes/project/plain-lock-fs.js +126 -0
  238. package/dist/holmes/project/request-lock.d.ts +85 -0
  239. package/dist/holmes/project/request-lock.js +459 -0
  240. package/dist/holmes/project/root.d.ts +12 -4
  241. package/dist/holmes/project/root.js +29 -8
  242. package/dist/holmes/project/run-records.d.ts +19 -0
  243. package/dist/holmes/project/run-records.js +94 -12
  244. package/dist/holmes/project/screen-text.d.ts +94 -0
  245. package/dist/holmes/project/screen-text.js +763 -0
  246. package/dist/holmes/project/spend-lock.d.ts +82 -0
  247. package/dist/holmes/project/spend-lock.js +413 -0
  248. package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
  249. package/dist/holmes/refresh/freshness-coordinator.js +1 -1
  250. package/dist/holmes/review/condition-hunk-replay.js +4 -2
  251. package/dist/holmes/review/confidence-calibration.d.ts +1 -1
  252. package/dist/holmes/review/confidence-calibration.js +1 -1
  253. package/dist/holmes/review/content-verify.js +1 -1
  254. package/dist/holmes/review/evidence-mode.d.ts +21 -0
  255. package/dist/holmes/review/evidence-mode.js +33 -0
  256. package/dist/holmes/review/head-worktree.d.ts +55 -0
  257. package/dist/holmes/review/head-worktree.js +329 -0
  258. package/dist/holmes/review/hop-ablation.d.ts +4 -4
  259. package/dist/holmes/review/hop-ablation.js +5 -5
  260. package/dist/holmes/review/mrp.js +13 -3
  261. package/dist/holmes/review/point-in-time-replay.js +12 -3
  262. package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
  263. package/dist/holmes/review/rank-diagnosis.js +1 -1
  264. package/dist/holmes/review/replay-corpus.d.ts +10 -4
  265. package/dist/holmes/review/replay-corpus.js +25 -9
  266. package/dist/holmes/review/requirement-triage.js +2 -2
  267. package/dist/holmes/review/run-provenance.d.ts +45 -0
  268. package/dist/holmes/review/run-provenance.js +314 -0
  269. package/dist/holmes/review/semantic-arm.d.ts +3 -3
  270. package/dist/holmes/review/semantic-arm.js +3 -3
  271. package/dist/holmes/review/test-evidence.d.ts +174 -0
  272. package/dist/holmes/review/test-evidence.js +330 -2
  273. package/dist/holmes/review/test-outcomes.js +3 -1
  274. package/dist/holmes/review/test-reports.d.ts +94 -0
  275. package/dist/holmes/review/test-reports.js +382 -0
  276. package/dist/holmes/review/test-runner.d.ts +180 -58
  277. package/dist/holmes/review/test-runner.js +560 -324
  278. package/dist/holmes/review/test-selection-breadth.js +2 -2
  279. package/dist/holmes/review/test-units.d.ts +159 -0
  280. package/dist/holmes/review/test-units.js +814 -0
  281. package/dist/holmes/review/verdicts.d.ts +105 -8
  282. package/dist/holmes/review/verdicts.js +640 -36
  283. package/dist/holmes/rtm/anchor-census.d.ts +9 -0
  284. package/dist/holmes/rtm/anchor-census.js +151 -0
  285. package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
  286. package/dist/holmes/rtm/anchor-ids.js +45 -2
  287. package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
  288. package/dist/holmes/rtm/comment-ranges.js +104 -0
  289. package/dist/holmes/rtm/counted-tests.d.ts +1 -0
  290. package/dist/holmes/rtm/counted-tests.js +63 -0
  291. package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
  292. package/dist/holmes/rtm/known-defects.js +1 -1
  293. package/dist/holmes/rtm/localize.js +1 -1
  294. package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
  295. package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
  296. package/dist/holmes/rtm/test-scope.d.ts +31 -0
  297. package/dist/holmes/rtm/test-scope.js +166 -5
  298. package/dist/holmes/rtm/trace-gaps.js +1 -1
  299. package/dist/holmes/runtime/dispatch.d.ts +10 -0
  300. package/dist/holmes/runtime/dispatch.js +12 -1
  301. package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
  302. package/dist/holmes/semantic/cloud-usage.js +1 -1
  303. package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
  304. package/dist/holmes/semantic/unreadable-paths.js +1 -1
  305. package/dist/holmes/spec/approval-blockers.js +1 -1
  306. package/dist/holmes/spec/entity-store.d.ts +6 -1
  307. package/dist/holmes/spec/entity-store.js +16 -2
  308. package/dist/holmes/spec/entity-transaction.d.ts +7 -2
  309. package/dist/holmes/spec/entity-transaction.js +87 -170
  310. package/dist/holmes/spec/spec-store.d.ts +12 -6
  311. package/dist/holmes/spec/spec-store.js +4 -2
  312. package/dist/holmes/spec/spec-types.js +1 -1
  313. package/dist/holmes/spec/succession-guard.d.ts +56 -0
  314. package/dist/holmes/spec/succession-guard.js +187 -0
  315. package/dist/holmes/spec/succession.d.ts +70 -0
  316. package/dist/holmes/spec/succession.js +171 -0
  317. package/dist/holmes/spec/transition-policy.d.ts +2 -2
  318. package/docs/install-guide.md +9 -3
  319. package/docs/language-support.md +78 -0
  320. package/package.json +4 -3
  321. package/playbooks/author-slice/PLAYBOOK.md +1 -1
  322. package/playbooks/promote-slice/PLAYBOOK.md +5 -1
  323. package/playbooks/publish/PLAYBOOK.md +47 -34
  324. package/dist/holmes/review/manual-baseline.d.ts +0 -209
  325. package/dist/holmes/review/manual-baseline.js +0 -2847
@@ -33,18 +33,30 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.verdictsFile = void 0;
36
+ exports.commitSnapshotFile = exports.authorsFile = exports.verdictsFile = void 0;
37
37
  exports.agentHarnessMarker = agentHarnessMarker;
38
38
  exports.harnessAncestor = harnessAncestor;
39
+ exports.operatorAncestry = operatorAncestry;
39
40
  exports.rangeAnchors = rangeAnchors;
41
+ exports.judgmentGitEnv = judgmentGitEnv;
42
+ exports.historyFiles = historyFiles;
43
+ exports.historyMoved = historyMoved;
40
44
  exports.resolveRange = resolveRange;
45
+ exports.runAuthoredCommits = runAuthoredCommits;
46
+ exports.runAuthorship = runAuthorship;
47
+ exports.commitObjects = commitObjects;
48
+ exports.snapshotRunCommits = snapshotRunCommits;
49
+ exports.reflogLength = reflogLength;
50
+ exports.recordRunAuthorship = recordRunAuthorship;
51
+ exports.rangeAuthors = rangeAuthors;
52
+ exports.rangeAuthorship = rangeAuthorship;
41
53
  exports.authorRuns = authorRuns;
42
54
  exports.readVerdicts = readVerdicts;
43
55
  exports.recordVerdict = recordVerdict;
44
56
  exports.gateRange = gateRange;
45
57
  exports.failingRounds = failingRounds;
46
58
  exports.rangeStatus = rangeStatus;
47
- // @implements A-SPEC-102.2, A-SPEC-102.7, A-SPEC-102.8, A-SPEC-779.6, A-SPEC-102.10
59
+ // @implements A-SPEC-102.2, A-SPEC-102.7, A-SPEC-102.8, A-SPEC-779.6, A-SPEC-102.10, A-SPEC-102.11, A-SPEC-102.13, A-SPEC-102.14, A-SPEC-102.15, A-SPEC-732.2, A-SPEC-732.4, A-SPEC-732.5, A-SPEC-102.27, A-SPEC-102.28, A-SPEC-102.29, A-SPEC-102.30
48
60
  /**
49
61
  * @implements A-SPEC-102.2 — a review is a verdict that names who reviewed which commits. The ledger lives in the main
50
62
  * checkout (`.ax/reviews/verdicts.jsonl`, append-only), so a review recorded in a worktree outlives the worktree. A
@@ -52,6 +64,7 @@ exports.rangeStatus = rangeStatus;
52
64
  * passes the gate.
53
65
  */
54
66
  const node_child_process_1 = require("node:child_process");
67
+ const crypto = __importStar(require("node:crypto"));
55
68
  const fs = __importStar(require("node:fs"));
56
69
  const path = __importStar(require("node:path"));
57
70
  const anchors_1 = require("../guardrail/anchors");
@@ -61,25 +74,29 @@ const run_mode_1 = require("../governance/run-mode");
61
74
  const bounded_io_1 = require("../project/bounded-io");
62
75
  const run_records_1 = require("../project/run-records");
63
76
  const harness_attestation_1 = require("../mcp/harness-attestation");
77
+ const harness_catalog_1 = require("../governance/harness-catalog");
78
+ const human_channel_1 = require("../governance/human-channel");
64
79
  const SOLID_ITEMS = ['S', 'O', 'L', 'I', 'D'];
65
80
  /**
66
- * @implements A-SPEC-102.7 — the environment marker of an agent tool call: Claude Code and Codex set these in the
67
- * processes their tools start. No agy marker is known; a tool call there has no terminal, which the TTY check catches.
81
+ * @implements A-SPEC-102.7 — the environment marker of an agent tool call: the harnesses set these in the processes
82
+ * their tools start. @implements A-SPEC-102.8 — agy: any ANTIGRAVITY_* variable (which one was not measured).
83
+ * @implements A-SPEC-102.27 — the markers are the harness catalog's (cursor-agent and opencode among them); a user or
84
+ * project file may only add to them. @implements A-SPEC-102.29 — the catalog is the caller's: no default reads cwd or home
68
85
  */
69
- const HARNESS_MARKERS = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CODEX_SANDBOX', 'CODEX_SANDBOX_NETWORK_DISABLED'];
70
- function agentHarnessMarker(env) {
71
- const set = (k) => typeof env[k] === 'string' && env[k] !== '';
72
- // @implements A-SPEC-102.8 — agy: any ANTIGRAVITY_* variable (which one its shell tool sets was not measured).
73
- return HARNESS_MARKERS.find(set) ?? Object.keys(env).filter((k) => k.startsWith('ANTIGRAVITY_') && set(k)).sort()[0] ?? null;
86
+ function agentHarnessMarker(env, catalog) {
87
+ return (0, harness_catalog_1.markerOf)(env, catalog);
74
88
  }
75
- function harnessAncestor(pid, lookup, maxDepth = 64) {
89
+ function harnessAncestor(pid, lookup, rule, maxDepth, catalog) {
76
90
  const chain = [];
77
91
  const seen = new Set();
78
92
  let cur = pid;
79
93
  let childCreated;
80
94
  for (let depth = 0; depth < maxDepth; depth++) {
81
- if (cur <= 1 || seen.has(cur))
95
+ if (cur <= 1)
82
96
  return { kind: 'none' };
97
+ // @implements A-SPEC-245.22 (item 3) — a loop is no person's chain: it never reaches init or an exited parent
98
+ if (seen.has(cur))
99
+ return { kind: 'unreadable', reason: `the parent chain loops at process ${cur}` };
83
100
  seen.add(cur);
84
101
  const row = lookup(cur);
85
102
  // @implements A-SPEC-779.6 — Windows does not reparent orphans: a parent that has exited is the top of the chain,
@@ -92,15 +109,36 @@ function harnessAncestor(pid, lookup, maxDepth = 64) {
92
109
  if (childCreated !== undefined && row.created !== undefined && row.created > childCreated)
93
110
  return { kind: 'none' };
94
111
  childCreated = row.created;
95
- const harness = (0, harness_attestation_1.harnessOf)(row.args, row.exe);
112
+ // @implements A-SPEC-102.27 — and the catalog's agents (cursor-agent, opencode): never the attestation's harnesses,
113
+ // where a name match would admit; here it only refuses more
114
+ const builtIn = (0, harness_attestation_1.harnessOf)(row.args, row.exe, rule);
115
+ const harness = builtIn ?? (0, harness_catalog_1.ancestorOf)(row.args, row.exe, catalog);
96
116
  chain.push(harness ?? row.args.split(/\s+/)[0] ?? '?');
97
- if (harness !== null)
98
- return { kind: 'harness', harness, chain };
117
+ // @implements A-SPEC-102.29 — the file of a name the catalog matched; a built-in harness names none
118
+ // @implements A-SPEC-102.30 — every file that added it
119
+ if (harness !== null) {
120
+ const sources = builtIn === null ? (0, harness_catalog_1.ancestorSource)(harness, catalog) : [];
121
+ return { kind: 'harness', harness, chain, ...(sources.length > 0 ? { sources } : {}) };
122
+ }
99
123
  if (row.ppid === cur)
100
- return { kind: 'none' };
124
+ return { kind: 'unreadable', reason: `process ${cur} names itself as its parent` }; // A-SPEC-245.22
101
125
  cur = row.ppid;
102
126
  }
103
- return { kind: 'none' };
127
+ // A-SPEC-245.22 (item 3) — a chain that reaches init on the walk's last step is a complete chain
128
+ if (cur <= 1)
129
+ return { kind: 'none' };
130
+ // @implements A-SPEC-245.20 (item 2) — a chain that does not end within the walk is not a person's: 70 nested shells
131
+ // under env -i passed every operator act as `none`
132
+ return { kind: 'unreadable', reason: `the parent chain is longer than ${maxDepth} processes` };
133
+ }
134
+ /**
135
+ * @implements A-SPEC-732.2 — the walk the operator-act guard and review independence run: any claude version path counts
136
+ * (an agent under a version-path session with its markers removed passed an operator act as the person; reproduced)
137
+ */
138
+ function operatorAncestry(pid, catalog, lookup = (0, harness_attestation_1.operatorLookup)()) {
139
+ // @implements A-SPEC-732.4 (L4) — the live lookup takes the walk's own rule: the two seams gave it the installed rule
140
+ // @implements A-SPEC-102.29 — and the caller's catalog, the one its marker read
141
+ return harnessAncestor(pid, lookup, harness_attestation_1.LAYOUT_RULE, 64, catalog);
104
142
  }
105
143
  /** A complete checklist, or the reason it is not one. */
106
144
  function solidIssue(solid, verdict) {
@@ -123,7 +161,7 @@ function solidIssue(solid, verdict) {
123
161
  * (measured: 100+ anchors in the hook) name half the store. Shared with the MRP, which imports it from here.
124
162
  */
125
163
  function rangeAnchors(root, base, head) {
126
- const git = (args) => (0, node_child_process_1.execFileSync)('git', args, { cwd: root, encoding: 'utf8', env: gitEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER });
164
+ const git = (args) => (0, node_child_process_1.execFileSync)('git', args, { cwd: root, encoding: 'utf8', env: judgmentEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER });
127
165
  let files;
128
166
  try {
129
167
  files = git(['diff', '--name-only', base, head]).split('\n').filter(Boolean);
@@ -161,7 +199,7 @@ function rangeAnchors(root, base, head) {
161
199
  /** The A-SPEC ids named in the commit messages of base..head. */
162
200
  function statedSpecs(root, base, head) {
163
201
  try {
164
- const log = (0, node_child_process_1.execFileSync)('git', ['log', '--format=%B', `${base}..${head}`], { cwd: root, encoding: 'utf8', env: gitEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER });
202
+ const log = (0, node_child_process_1.execFileSync)('git', ['log', '--format=%B', `${base}..${head}`], { cwd: root, encoding: 'utf8', env: judgmentEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER });
165
203
  return [...new Set(log.match(/A-SPEC-\d{3}(?:\.\d+)*/g) ?? [])].sort();
166
204
  }
167
205
  catch {
@@ -170,15 +208,56 @@ function statedSpecs(root, base, head) {
170
208
  }
171
209
  const verdictsFile = (main) => path.join(main, '.ax', 'reviews', 'verdicts.jsonl');
172
210
  exports.verdictsFile = verdictsFile;
173
- const gitEnv = () => {
174
- const env = { ...process.env };
175
- for (const k of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_COMMON_DIR'])
176
- delete env[k];
177
- return env;
178
- };
211
+ /**
212
+ * @implements A-SPEC-102.22, A-SPEC-102.26 — the git of a judgment reads the repository as stored: no inherited GIT_* variable (a
213
+ * shallow file, an object directory, alternates, config entries or a namespace all steered it), replace objects off,
214
+ * no grafts file (A-SPEC-102.22) and no prompt.
215
+ */
216
+ function judgmentGitEnv(env = process.env) {
217
+ // @implements A-SPEC-792.36, A-SPEC-792.42 — the one git environment builder (no inherited GIT_* but the two it keeps,
218
+ // and the inert pairs), plus the judgment's own three values
219
+ // A-SPEC-792.43: its own values are the shared pins (the graft file is the null device by its git spelling: Windows git
220
+ // cannot open `\\.\nul`, so it is NUL there, as A-SPEC-652.6 holds)
221
+ const io = require('../project/bounded-io');
222
+ return { ...io.gitEnv(env), ...io.judgmentPins() };
223
+ }
224
+ const judgmentEnv = () => judgmentGitEnv();
225
+ /**
226
+ * @implements A-SPEC-102.22 — the sha256 of the common dir's `shallow` and `info/grafts` (null when absent); null when
227
+ * the common dir or a present file cannot be read. Run start records it; a run review compares it.
228
+ */
229
+ function historyFiles(main) {
230
+ const common = (gitOut(main, ['rev-parse', '--path-format=absolute', '--git-common-dir']) ?? '').trim();
231
+ if (common === '')
232
+ return null;
233
+ const hashOf = (f) => {
234
+ try {
235
+ return crypto.createHash('sha256').update(fs.readFileSync(f)).digest('hex');
236
+ }
237
+ catch (e) {
238
+ return e.code === 'ENOENT' ? null : undefined;
239
+ }
240
+ };
241
+ const shallow = hashOf(path.join(common, 'shallow'));
242
+ const grafts = hashOf(path.join(common, 'info', 'grafts'));
243
+ // @implements A-SPEC-102.25 — an object store added through alternates shows commits the run's authorship never saw
244
+ const alternates = hashOf(path.join(common, 'objects', 'info', 'alternates'));
245
+ const httpAlternates = hashOf(path.join(common, 'objects', 'info', 'http-alternates'));
246
+ return shallow === undefined || grafts === undefined || alternates === undefined || httpAlternates === undefined ? null
247
+ : { shallow, grafts, alternates, http_alternates: httpAlternates };
248
+ }
249
+ /**
250
+ * @implements A-SPEC-102.25 — the history files, among those `atStart` recorded, that differ now (all of them when they
251
+ * cannot be read now). A key `atStart` does not hold is not compared: a record made before it was read.
252
+ */
253
+ function historyMoved(main, atStart) {
254
+ const now = historyFiles(main);
255
+ const held = ['shallow', 'grafts', 'alternates', 'http_alternates'].filter((k) => Object.prototype.hasOwnProperty.call(atStart, k));
256
+ return now === null ? held : held.filter((k) => now[k] !== (atStart[k] ?? null));
257
+ }
179
258
  function revParse(cwd, rev) {
180
259
  try {
181
- return (0, node_child_process_1.execFileSync)('git', ['rev-parse', '--verify', '--quiet', `${rev}^{commit}`], { cwd, encoding: 'utf8', env: gitEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER }).trim() || null;
260
+ return (0, node_child_process_1.execFileSync)('git', ['rev-parse', '--verify', '--quiet', `${rev}^{commit}`], { cwd, encoding: 'utf8', env: judgmentEnv(), stdio: ['ignore', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER }).trim() || null;
182
261
  }
183
262
  catch {
184
263
  return null;
@@ -194,9 +273,448 @@ function resolveRange(root, base, head) {
194
273
  return { error: `head ${head} does not resolve to a commit in ${root}` };
195
274
  return { base: b, head: h };
196
275
  }
197
- /** The runs whose worktree holds `headSha` as its HEAD: the head's authors. */
198
- function authorRuns(main, headSha) {
199
- return (0, run_records_1.listRuns)(main).filter((r) => revParse(r.worktree, 'HEAD') === headSha).map((r) => r.run_id);
276
+ /**
277
+ * @implements A-SPEC-102.11 — authorship is the commits a run made, recorded when it stops, not the head it sits on.
278
+ * A run stopped earlier left its line in the main checkout's authors ledger.
279
+ */
280
+ const authorsFile = (main) => path.join(main, '.ax', 'reviews', 'authors.jsonl');
281
+ exports.authorsFile = authorsFile;
282
+ const gitOut = (cwd, args, input) => {
283
+ try {
284
+ // A-SPEC-102.13: replace objects (`git replace --graft`) would let a run rewrite ancestry; they are not read here.
285
+ return (0, node_child_process_1.execFileSync)('git', args, { cwd, encoding: 'utf8', env: { ...judgmentEnv(), GIT_NO_REPLACE_OBJECTS: '1' }, stdio: ['pipe', 'pipe', 'ignore'], timeout: bounded_io_1.GIT_TIMEOUT_MS, maxBuffer: bounded_io_1.GIT_MAX_BUFFER, ...(input !== undefined ? { input } : {}) });
286
+ }
287
+ catch {
288
+ return null;
289
+ }
290
+ };
291
+ const lines = (s) => (s ?? '').split('\n').map((l) => l.trim()).filter(Boolean);
292
+ const MAX_COMMITS = 2000;
293
+ /**
294
+ * @implements A-SPEC-102.13 — the commits a run made: its whole `base..HEAD` and every reflog entry but its base, with
295
+ * no message, time or branch filter (each was an escape: Fast-forward, a backdated committer date, a branch keeping a
296
+ * detached commit — measured). Over-attribution errs on the blocking side. Null for a record without a base.
297
+ */
298
+ function runAuthoredCommits(rec) {
299
+ return runAuthorship(rec)?.commits ?? null;
300
+ }
301
+ /**
302
+ * @implements A-SPEC-102.16 — git for a run: through the worktree's own git dir recorded at run start, so a pointer file
303
+ * renamed or rewritten in the worktree does not change what is read; a record without one reads in the worktree.
304
+ */
305
+ function runGit(rec) {
306
+ const dir = typeof rec.git_dir === 'string' && rec.git_dir !== '' ? rec.git_dir : null;
307
+ return dir === null ? (args, input) => gitOut(rec.worktree, args, input) : (args, input) => gitOut(dir, ['--git-dir', dir, ...args], input);
308
+ }
309
+ const commitOf = (git, rev) => {
310
+ const out = (git(['rev-parse', '--verify', '--quiet', `${rev}^{commit}`]) ?? '').trim();
311
+ return /^[0-9a-f]{40,64}$/.test(out) ? out : null;
312
+ };
313
+ const realFolded = (p) => {
314
+ try {
315
+ const r = fs.realpathSync.native(p);
316
+ return process.platform === 'win32' ? r.toLowerCase() : r;
317
+ }
318
+ catch {
319
+ return null;
320
+ }
321
+ };
322
+ /**
323
+ * @implements A-SPEC-102.17 — the worktree's pointer resolves to a git dir other than the recorded one. A pointer git
324
+ * cannot follow at all keeps A-SPEC-102.16's reading through the recorded dir.
325
+ */
326
+ function pointerMoved(rec) {
327
+ if (typeof rec.git_dir !== 'string' || rec.git_dir === '')
328
+ return false;
329
+ const seen = (gitOut(rec.worktree, ['rev-parse', '--absolute-git-dir']) ?? '').trim();
330
+ if (seen === '')
331
+ return false;
332
+ const a = realFolded(seen);
333
+ return a === null || a !== realFolded(rec.git_dir);
334
+ }
335
+ /**
336
+ * @implements A-SPEC-102.16 — a run's authored commits (A-SPEC-102.13/102.15) and whether git could not read them: its
337
+ * HEAD, its reflog or its base..HEAD did not answer, or its pointer names another git dir (A-SPEC-102.17). An unreadable
338
+ * run never reads as "made nothing". Null for a record without a base.
339
+ */
340
+ function runAuthorship(rec, main, objects) {
341
+ if (typeof rec.base !== 'string' || rec.base === '')
342
+ return null;
343
+ const git = runGit(rec);
344
+ // @implements A-SPEC-102.19 — the commit objects that appeared in the store since the run's start are its own; the
345
+ // reflog readings below only add to them.
346
+ const delta = snapshotDelta(rec, main, objects);
347
+ const appeared = delta === null ? null : delta.reached;
348
+ // @implements A-SPEC-102.21 — a snapshotting run is attributed only what is new since its start: a commit that existed
349
+ // before (merged in, or a branch moved onto it) is not its, whatever its base..HEAD or reflog says.
350
+ // @implements A-SPEC-102.24 — and with the delta unreadable, nothing is new: the run is attributed no commit (a person
351
+ // reviews) and stays an unreadable author of its base's descendants.
352
+ const isNew = (sha) => delta !== null && (delta.fresh === null || delta.fresh.has(sha));
353
+ const base = commitOf(git, rec.base) ?? rec.base;
354
+ const head = commitOf(git, 'HEAD');
355
+ const reflogText = git(['reflog', 'show', '--format=%H', 'HEAD']);
356
+ const rangeText = git(['rev-list', `--max-count=${MAX_COMMITS}`, `${base}..HEAD`]);
357
+ const out = new Set();
358
+ // @implements A-SPEC-102.15 — the reflog is the worktree's, not the run's: only the entries added since this run
359
+ // started are its own (newest first). A reflog shorter than at start was rewritten: every entry counts then.
360
+ const reflog = lines(reflogText);
361
+ const atStart = rec.reflog_entries;
362
+ const own = typeof atStart === 'number' && Number.isInteger(atStart) && atStart >= 0 && reflog.length >= atStart
363
+ ? reflog.slice(0, reflog.length - atStart) : reflog;
364
+ for (const sha of own) {
365
+ if (/^[0-9a-f]{40,64}$/.test(sha) && sha !== base && isNew(sha))
366
+ out.add(sha);
367
+ }
368
+ for (const sha of lines(rangeText))
369
+ if (isNew(sha))
370
+ out.add(sha);
371
+ for (const sha of appeared ?? [])
372
+ out.add(sha);
373
+ // @implements A-SPEC-102.25 — history that moved under the run (alternates, shallow, grafts) may hide what it made:
374
+ // it is unreadable, and nothing it read bounds it
375
+ const atStartFiles = rec.history_files;
376
+ const historyMovedUnder = main !== undefined && atStartFiles !== null && typeof atStartFiles === 'object'
377
+ && historyMoved(main, atStartFiles).length > 0;
378
+ const unreadable = head === null || reflogText === null || rangeText === null || pointerMoved(rec) || appeared === null || historyMovedUnder;
379
+ // @implements A-SPEC-102.21 — new since the start but not reached: perhaps the run's (a dangling commit-tree), so it
380
+ // blocks the run's engine; never attributed to anyone on that account.
381
+ const candidates = delta === null || delta.fresh === null ? [] : [...delta.fresh].filter((c) => !out.has(c));
382
+ return { commits: [...out], unreadable, candidates, snapshotRead: delta !== null && !historyMovedUnder };
383
+ }
384
+ /** @implements A-SPEC-102.19 — where run start keeps a run's commit snapshot: the main checkout, out of the engine's reach. */
385
+ const commitSnapshotFile = (main, runId) => path.join(main, '.ax', 'state', 'runs', `${runId}.commits`);
386
+ exports.commitSnapshotFile = commitSnapshotFile;
387
+ /** @implements A-SPEC-102.19 — every commit object in the store `cwd` reads (loose, packed and alternates); null when git cannot list them. */
388
+ function commitObjects(cwd) {
389
+ const out = gitOut(cwd, ['cat-file', '--batch-all-objects', '--unordered', '--batch-check=%(objecttype) %(objectname)']);
390
+ if (out === null)
391
+ return null;
392
+ const set = new Set();
393
+ for (const l of out.split('\n'))
394
+ if (l.startsWith('commit '))
395
+ set.add(l.slice('commit '.length).trim());
396
+ return set;
397
+ }
398
+ /** @implements A-SPEC-102.19 — run start's snapshot of the store's commit objects; false when it could not be written. */
399
+ function snapshotRunCommits(main, runId) {
400
+ const all = commitObjects(main);
401
+ if (all === null)
402
+ return false;
403
+ try {
404
+ fs.mkdirSync(path.dirname((0, exports.commitSnapshotFile)(main, runId)), { recursive: true });
405
+ fs.writeFileSync((0, exports.commitSnapshotFile)(main, runId), [...all].sort().join('\n') + '\n', { flag: 'wx' });
406
+ return true;
407
+ }
408
+ catch {
409
+ return false;
410
+ }
411
+ }
412
+ /**
413
+ * The commits that appeared since a snapshotting run's start: `reached`, those its HEAD or branch reaches, and `fresh`,
414
+ * all of them (A-SPEC-102.21). No commits and no `fresh` for a record that took no snapshot; null when the snapshot or
415
+ * the store cannot be read (the run's authorship is then unreadable).
416
+ */
417
+ function snapshotDelta(rec, main, objects) {
418
+ if (rec.commit_snapshot !== true)
419
+ return { reached: [], fresh: null };
420
+ // A-SPEC-102.32 — non-strict: a forged pointer looks for the snapshot in the worktree, where none is (unreadable
421
+ // authorship); a throw is caught the same way
422
+ const where = main ?? (() => { try {
423
+ return (0, run_records_1.mainCheckoutOf)(rec.worktree);
424
+ }
425
+ catch {
426
+ return null;
427
+ } })();
428
+ if (where === null)
429
+ return null;
430
+ let before;
431
+ try {
432
+ before = new Set(fs.readFileSync((0, exports.commitSnapshotFile)(where, rec.run_id), 'utf8').split('\n').filter(Boolean));
433
+ }
434
+ catch {
435
+ return null;
436
+ }
437
+ const now = objects ?? commitObjects(where);
438
+ if (now === null)
439
+ return null;
440
+ // @implements A-SPEC-102.20 — only what the run's own worktree HEAD or recorded branch reaches past its base: a commit
441
+ // new elsewhere in the store (another worktree, a person, a run that stopped) is not this run's.
442
+ const branch = rec.branch;
443
+ const tips = ['HEAD', ...(typeof branch === 'string' && /^refs\/heads\/[^\s:]+$/.test(branch) ? [branch] : [])];
444
+ const reach = runGit(rec)(['rev-list', `--max-count=${MAX_COMMITS}`, ...tips, '--not', String(rec.base)]);
445
+ if (reach === null)
446
+ return null;
447
+ const reached = new Set(lines(reach));
448
+ const fresh = new Set([...now].filter((c) => !before.has(c)));
449
+ return { reached: [...fresh].filter((c) => reached.has(c)), fresh };
450
+ }
451
+ /** @implements A-SPEC-102.15 — the number of entries in a worktree's HEAD reflog, recorded at run start. */
452
+ function reflogLength(worktree) {
453
+ return lines(gitOut(worktree, ['reflog', 'show', '--format=%H', 'HEAD'])).length;
454
+ }
455
+ /** @implements A-SPEC-102.13 — whether `head` is an ancestor of (or is) `of`, in `cwd`'s object store. */
456
+ function isAncestorOrSelf(cwd, head, of) {
457
+ if (head === of)
458
+ return true;
459
+ return gitOut(cwd, ['merge-base', '--is-ancestor', head, of]) !== null;
460
+ }
461
+ /** Stable patch-ids by commit; a merge or an unreadable commit has none. */
462
+ function patchIds(cwd, shas) {
463
+ const ids = new Map();
464
+ if (shas.length === 0)
465
+ return ids;
466
+ const git = typeof cwd === 'string' ? (args, input) => gitOut(cwd, args, input) : cwd;
467
+ const patches = git(['log', '--no-walk', '--format=commit %H', '-p', ...shas]);
468
+ if (patches === null)
469
+ return ids;
470
+ for (const l of lines(git(['patch-id', '--stable'], patches))) {
471
+ const [pid, sha] = l.split(' ');
472
+ if (pid && sha)
473
+ ids.set(sha, pid);
474
+ }
475
+ return ids;
476
+ }
477
+ /** Appends the stopped run's authored commits to the authors ledger; false when they could not be recorded. */
478
+ function recordRunAuthorship(main, rec, now = () => new Date()) {
479
+ try {
480
+ const git = runGit(rec);
481
+ const head = commitOf(git, 'HEAD');
482
+ const made = runAuthorship(rec, main);
483
+ const commits = made?.commits ?? (head ? [head] : []);
484
+ const line = { ts: now().toISOString(), run_id: rec.run_id, engine: typeof rec.engine === 'string' ? rec.engine : null,
485
+ base: typeof rec.base === 'string' ? rec.base : null, head, commits, patch_ids: [...new Set(patchIds(git, commits).values())],
486
+ // @implements A-SPEC-102.16 — git could not read what the run made: the line says so, and it authors its base's ranges.
487
+ ...(made?.unreadable || (made === null && head === null) ? { unreadable: true } : {}),
488
+ ...(made && made.candidates.length > 0 ? { candidates: made.candidates } : {}), // @implements A-SPEC-102.21
489
+ // @implements A-SPEC-102.23 — how far the run could have reached: its HEAD and its branch's tip read from the main
490
+ // checkout (that survives a worktree git cannot read).
491
+ ...(() => {
492
+ // @implements A-SPEC-102.24 — only a run whose HEAD and snapshot delta were both read may be bounded by its tips
493
+ if (head === null || !made?.snapshotRead)
494
+ return {};
495
+ const branch = rec.branch;
496
+ const tip = typeof branch === 'string' && /^refs\/heads\/[^\s:]+$/.test(branch) ? revParse(main, branch) : null;
497
+ const tips = [...new Set([head, tip].filter((t) => typeof t === 'string' && t !== ''))];
498
+ return tips.length > 0 ? { stop_tips: tips } : {};
499
+ })(),
500
+ // @implements A-SPEC-774.50 — a run exec teardown that could not prove the run's sandbox empty tainted the run
501
+ ...(taintOf(main, rec.run_id) !== null ? { tainted: true, taint_reason: taintOf(main, rec.run_id) } : {}) };
502
+ fs.mkdirSync(path.dirname((0, exports.authorsFile)(main)), { recursive: true });
503
+ fs.appendFileSync((0, exports.authorsFile)(main), `${JSON.stringify(line)}\n`);
504
+ try {
505
+ fs.rmSync(taintFile(main, rec.run_id), { force: true });
506
+ }
507
+ catch { /* the ledger line now carries it */ }
508
+ return true;
509
+ }
510
+ catch {
511
+ return false;
512
+ }
513
+ }
514
+ /** @implements A-SPEC-774.50 — where run exec records a run's taint while the run is active. */
515
+ const taintFile = (main, runId) => path.join(main, '.ax', 'state', 'runs', `${runId}.tainted`);
516
+ /** The recorded taint reasons of an active run, or null when it is not tainted. */
517
+ function taintOf(main, runId) {
518
+ let text;
519
+ try {
520
+ text = fs.readFileSync(taintFile(main, runId), 'utf8');
521
+ }
522
+ catch {
523
+ return null;
524
+ }
525
+ const reasons = text.split('\n').filter(Boolean).map((l) => { try {
526
+ return String(JSON.parse(l).reason ?? 'tainted');
527
+ }
528
+ catch {
529
+ return 'tainted';
530
+ } });
531
+ return reasons.length > 0 ? reasons.join('; ') : 'tainted';
532
+ }
533
+ /**
534
+ * @implements A-SPEC-774.50 — the tainted runs that authored a commit of `base..head`: ledger lines marked tainted, and
535
+ * active runs with a taint file. Cheap when nothing is tainted (no git call at all).
536
+ */
537
+ function taintedAuthors(main, base, head) {
538
+ const runs = (0, run_records_1.listRuns)(main);
539
+ // @implements A-SPEC-774.54 — a taint that landed after its run stopped marks that run's ledger lines all the same
540
+ const activeIds = new Set(runs.map((r) => r.run_id));
541
+ let late = [];
542
+ try {
543
+ late = fs.readdirSync(path.join(main, '.ax', 'state', 'runs')).filter((n) => n.endsWith('.tainted')).map((n) => n.slice(0, -'.tainted'.length)).filter((id) => !activeIds.has(id));
544
+ }
545
+ catch {
546
+ late = [];
547
+ }
548
+ const marked = readAuthorLines(main).flatMap((l) => {
549
+ if (l.tainted)
550
+ return [l];
551
+ const reason = late.includes(l.run_id) ? taintOf(main, l.run_id) : null;
552
+ return reason !== null ? [{ ...l, tainted: true, taint_reason: reason }] : [];
553
+ });
554
+ const active = runs.filter((r) => taintOf(main, r.run_id) !== null);
555
+ if (marked.length === 0 && active.length === 0)
556
+ return [];
557
+ const shas = new Set([head, ...lines(gitOut(main, ['rev-list', `--max-count=${MAX_COMMITS}`, `${base}..${head}`]))]);
558
+ const out = [];
559
+ for (const l of marked)
560
+ if (l.commits.some((c) => shas.has(c)))
561
+ out.push({ run: l.run_id, reason: l.taint_reason ?? 'tainted' });
562
+ for (const r of active)
563
+ if ((runAuthorship(r, main)?.commits ?? []).some((c) => shas.has(c)))
564
+ out.push({ run: r.run_id, reason: taintOf(main, r.run_id) ?? 'tainted' });
565
+ return out;
566
+ }
567
+ function readAuthorLines(main) {
568
+ let text;
569
+ try {
570
+ text = fs.readFileSync((0, exports.authorsFile)(main), 'utf8');
571
+ }
572
+ catch {
573
+ return [];
574
+ }
575
+ const out = [];
576
+ for (const l of text.split('\n')) {
577
+ if (l.trim() === '')
578
+ continue;
579
+ try {
580
+ const x = JSON.parse(l);
581
+ if (typeof x.run_id !== 'string' || !Array.isArray(x.commits))
582
+ continue;
583
+ out.push({ run_id: x.run_id, ...(typeof x.engine === 'string' ? { engine: x.engine } : {}),
584
+ ...(Array.isArray(x.stop_tips) ? { stop_tips: x.stop_tips.filter((c) => typeof c === 'string') } : {}),
585
+ ...(Array.isArray(x.candidates) ? { candidates: x.candidates.filter((c) => typeof c === 'string') } : {}),
586
+ ...(typeof x.base === 'string' ? { base: x.base } : {}), ...(x.unreadable === true ? { unreadable: true } : {}),
587
+ ...(x.tainted === true ? { tainted: true, ...(typeof x.taint_reason === 'string' ? { taint_reason: x.taint_reason } : {}) } : {}),
588
+ commits: x.commits.filter((c) => typeof c === 'string'),
589
+ patch_ids: Array.isArray(x.patch_ids) ? x.patch_ids.filter((p) => typeof p === 'string') : [] });
590
+ }
591
+ catch { /* a torn line is skipped */ }
592
+ }
593
+ return out;
594
+ }
595
+ /**
596
+ * The runs that authored a commit of `base..head` (`head` alone without a base), by sha or stable patch-id: active
597
+ * runs first, then the ledger. An active run without a recorded base keeps the old rule: its worktree HEAD is the head.
598
+ */
599
+ function rangeAuthors(main, headSha, base) {
600
+ return rangeAuthorship(main, headSha, base).authors;
601
+ }
602
+ /**
603
+ * @implements A-SPEC-102.19 — the authors of `base..head` and the commits of it no recorded run made: attributed by sha
604
+ * or stable patch-id to an active run's authorship (its snapshot delta included) or an authors ledger line. A run whose
605
+ * authorship is unreadable is an author of the ranges from its base (A-SPEC-102.16) but attributes no commit (102.20).
606
+ */
607
+ function rangeAuthorship(main, headSha, base) {
608
+ const inRange = base !== undefined && base !== headSha
609
+ ? lines(gitOut(main, ['rev-list', `--max-count=${MAX_COMMITS}`, `${base}..${headSha}`]))
610
+ : [headSha];
611
+ const shas = new Set(inRange.length > 0 ? inRange : [headSha]);
612
+ let rangePids = null;
613
+ const pidsInRange = () => (rangePids ??= new Set(patchIds(main, [...shas]).values()));
614
+ const authors = [];
615
+ const add = (run, engine, unreadable = false) => {
616
+ const known = authors.find((a) => a.run === run);
617
+ if (known) {
618
+ if (unreadable)
619
+ known.unreadable = true;
620
+ return;
621
+ }
622
+ authors.push({ run, ...(typeof engine === 'string' ? { engine } : {}), ...(unreadable ? { unreadable: true } : {}) });
623
+ };
624
+ // @implements A-SPEC-102.16 — an unreadable run may have made anything after its base: every range whose head
625
+ // descends from that base (every range, when the base is unknown or does not resolve) is taken as its.
626
+ const fromBase = (b) => {
627
+ if (typeof b !== 'string' || b === '')
628
+ return true;
629
+ const c = revParse(main, b);
630
+ return c === null || isAncestorOrSelf(main, c, headSha);
631
+ };
632
+ // @implements A-SPEC-102.23 — an unreadable line's run could have made only base..tip for a tip it stopped at: it
633
+ // authors a range holding one of those commits. A line without tips, or a tip git cannot list, keeps the old rule.
634
+ const reachesIntoRange = (l) => {
635
+ if (!l.stop_tips || l.stop_tips.length === 0 || typeof l.base !== 'string' || l.base === '')
636
+ return true;
637
+ for (const tip of l.stop_tips) {
638
+ const made = gitOut(main, ['rev-list', `--max-count=${MAX_COMMITS}`, tip, '--not', l.base]);
639
+ if (made === null)
640
+ return true;
641
+ if (lines(made).some((c) => shas.has(c)))
642
+ return true;
643
+ }
644
+ return false;
645
+ };
646
+ const attributed = new Set();
647
+ const ledgerPids = new Set();
648
+ const madeBy = [];
649
+ const objects = commitObjects(main);
650
+ for (const r of (0, run_records_1.listRuns)(main)) {
651
+ const made = runAuthorship(r, main, objects);
652
+ const git = runGit(r);
653
+ const head = commitOf(git, 'HEAD');
654
+ if (made === null) {
655
+ if (head === headSha) {
656
+ add(r.run_id, r.engine);
657
+ attributed.add(headSha);
658
+ }
659
+ continue;
660
+ }
661
+ for (const c of made.commits)
662
+ attributed.add(c);
663
+ madeBy.push({ git, commits: made.commits });
664
+ if (made.unreadable && fromBase(r.base)) {
665
+ add(r.run_id, r.engine, true);
666
+ continue;
667
+ }
668
+ // @implements A-SPEC-102.13 — the old rule too: a run whose HEAD moved into the range is its author.
669
+ const ownBase = typeof r.base === 'string' ? commitOf(git, r.base) ?? r.base : null;
670
+ if (head !== null && head !== ownBase && shas.has(head)) {
671
+ add(r.run_id, r.engine);
672
+ continue;
673
+ }
674
+ if (made.commits.some((c) => shas.has(c))) {
675
+ add(r.run_id, r.engine);
676
+ continue;
677
+ }
678
+ // @implements A-SPEC-102.21 — a candidate in the range makes the run an author (its engine reviews nothing here)
679
+ if (made.candidates.some((c) => shas.has(c))) {
680
+ add(r.run_id, r.engine);
681
+ continue;
682
+ }
683
+ const pids = patchIds(git, made.commits);
684
+ if ([...pids.values()].some((p) => pidsInRange().has(p)))
685
+ add(r.run_id, r.engine);
686
+ }
687
+ for (const l of readAuthorLines(main)) {
688
+ for (const c of l.commits)
689
+ attributed.add(c);
690
+ for (const p of l.patch_ids)
691
+ ledgerPids.add(p);
692
+ if (l.unreadable && fromBase(l.base) && reachesIntoRange(l)) {
693
+ add(l.run_id, l.engine, true);
694
+ continue;
695
+ }
696
+ if (l.commits.some((c) => shas.has(c)) || l.patch_ids.some((p) => pidsInRange().has(p))) {
697
+ add(l.run_id, l.engine);
698
+ continue;
699
+ }
700
+ if ((l.candidates ?? []).some((c) => shas.has(c)))
701
+ add(l.run_id, l.engine); // @implements A-SPEC-102.21
702
+ }
703
+ // @implements A-SPEC-102.20 — an unreadable author blocks its own engine and vouches for no commit.
704
+ let unattributed = [...shas].filter((c) => !attributed.has(c));
705
+ if (unattributed.length > 0) {
706
+ const known = new Set(ledgerPids);
707
+ for (const m of madeBy)
708
+ for (const p of patchIds(m.git, m.commits).values())
709
+ known.add(p);
710
+ const pidOf = patchIds(main, unattributed);
711
+ unattributed = unattributed.filter((c) => { const p = pidOf.get(c); return p === undefined || !known.has(p); });
712
+ }
713
+ return { authors, unattributed };
714
+ }
715
+ /** The ids of the runs that authored `base..head` (`head` alone without a base). */
716
+ function authorRuns(main, headSha, base) {
717
+ return rangeAuthors(main, headSha, base).map((a) => a.run);
200
718
  }
201
719
  function readVerdicts(main) {
202
720
  let text;
@@ -229,11 +747,51 @@ function recordVerdict(root, input, ctx) {
229
747
  const roleIssue = (0, role_policy_1.roleCheck)('RECORD_REVIEW', new identity_1.EnvIdentityProvider(ctx.env).current(), (0, role_policy_1.loadRolePolicy)(root), { run: mode.run });
230
748
  if (roleIssue)
231
749
  return { ok: false, reason: roleIssue };
750
+ // A-SPEC-102.32 — non-strict: a forged pointer reads the runs and the verdict ledger of the worktree as main, so a
751
+ // tainted run of the main checkout is not seen; a pointer that cannot be opened throws out of the record
232
752
  const main = (0, run_records_1.mainCheckoutOf)(root);
233
- const authors = authorRuns(main, range.head);
753
+ // @implements A-SPEC-102.11 — the authors of the reviewed range, and the engines that wrote it.
754
+ const authorship = rangeAuthorship(main, range.head, range.base);
755
+ const authorList = authorship.authors;
756
+ const authors = authorList.map((a) => a.run);
234
757
  const run = mode.run ? mode.id : undefined;
758
+ if (run) {
759
+ // @implements A-SPEC-102.22, A-SPEC-102.25 — a history file that moved under the review run moved its ranges too
760
+ // (checked first: the same move also makes the review run an unreadable author, which would name less)
761
+ const atStart = (0, run_records_1.listRuns)(main).find((r) => r.run_id === run)?.history_files;
762
+ if (atStart !== null && typeof atStart === 'object') {
763
+ const moved = historyMoved(main, atStart);
764
+ if (moved.length > 0) {
765
+ return { ok: false, reason: `history: the repository's ${moved.join(' and ')} file changed or could not be read since run ${run} started — its ranges cannot be trusted; start a new review run or have a person review` };
766
+ }
767
+ }
768
+ }
235
769
  if (run && authors.includes(run))
236
770
  return { ok: false, reason: `self-review: run ${run} wrote ${range.head}; a review is recorded by another run or a person` };
771
+ if (run) {
772
+ const own = (0, run_records_1.listRuns)(main).find((r) => r.run_id === run);
773
+ // @implements A-SPEC-102.13 — structural: a run that existed before the head did cannot be its independent reviewer,
774
+ // whatever it did to its refs and reflog. A review run starts on the head it reviews (or after it).
775
+ const ownBase = typeof own?.base === 'string' ? own.base : null;
776
+ if (ownBase === null || !isAncestorOrSelf(root, range.head, revParse(root, ownBase) ?? ownBase)) {
777
+ return { ok: false, reason: `self-review: run ${run} started at ${ownBase ? ownBase.slice(0, 12) : 'no recorded base'}, before ${range.head.slice(0, 12)} — an independent review run starts on the head it reviews` };
778
+ }
779
+ const engine = own?.engine;
780
+ // @implements A-SPEC-102.16 — an unreadable author of no recorded engine could be any engine.
781
+ const unknown = authorList.find((a) => a.unreadable && (a.engine === engine || a.engine === undefined));
782
+ if (unknown) {
783
+ return { ok: false, reason: `self-review: the commits of run ${unknown.run} (engine ${unknown.engine ?? 'unknown'}) could not be read — git did not answer for its worktree, or its .git pointer names another git dir, so it is taken as an author of ${range.base.slice(0, 12)}..${range.head.slice(0, 12)}; another engine's run or a person reviews it` };
784
+ }
785
+ // @implements A-SPEC-102.19 — a commit whose author no run record proves could be this engine's: only a person reviews it.
786
+ if (authorship.unattributed.length > 0) {
787
+ const n = authorship.unattributed.length;
788
+ return { ok: false, reason: `self-review: ${n} commit(s) of ${range.base.slice(0, 12)}..${range.head.slice(0, 12)} (first ${authorship.unattributed[0].slice(0, 12)}) were made by no recorded run — their author is unknown, so no run reviews them; a person records this review` };
789
+ }
790
+ const same = typeof engine === 'string' ? authorList.find((a) => a.engine === engine) : undefined;
791
+ if (same) {
792
+ return { ok: false, reason: `self-review: engine ${engine} authored commits in ${range.base.slice(0, 12)}..${range.head.slice(0, 12)} (run ${same.run}) — an independent review is another engine's run or a person` };
793
+ }
794
+ }
237
795
  // @implements A-SPEC-102.7 — a checklist, when given, is complete and agrees with the verdict.
238
796
  if (input.solid !== undefined) {
239
797
  const issue = solidIssue(input.solid, input.verdict);
@@ -242,14 +800,30 @@ function recordVerdict(root, input, ctx) {
242
800
  }
243
801
  // @implements A-SPEC-102.9 — a person answered this verdict in the session's form (review_verdict). The server that
244
802
  // asked is under the harness by design, so its markers and parents say nothing about who answered; a run ignores it.
245
- const answered = !mode.run && typeof ctx.answeredBy === 'string' && ctx.answeredBy !== '';
803
+ // @implements A-SPEC-792.26 — only a minted person-channel actor answers for a person; a string claiming one does not
804
+ const answered = !mode.run && (0, human_channel_1.isMinted)(ctx.answeredBy);
246
805
  // @implements A-SPEC-102.7 — a person is a terminal outside an agent harness: an agent session's own review is not one.
247
- const marker = answered ? null : agentHarnessMarker(ctx.env);
806
+ // @implements A-SPEC-102.28 — the catalog of this verdict's project (its main checkout), not of the working directory
807
+ // @implements A-SPEC-102.29 — resolved once, for the marker and the walk alike (the walk read the working directory's)
808
+ // @implements A-SPEC-102.30 — a root whose project cannot be resolved records no verdict a person's catalog did not judge
809
+ let catalog;
810
+ try {
811
+ catalog = answered ? (0, harness_catalog_1.liveHarnessCatalog)({ root: null, reason: 'a person answered in the session form' }) : (0, harness_catalog_1.liveHarnessCatalog)(root);
812
+ }
813
+ catch (e) {
814
+ if (e instanceof harness_catalog_1.CatalogRootError)
815
+ return { ok: false, reason: e.message };
816
+ throw e;
817
+ }
818
+ const marker = answered ? null : agentHarnessMarker(ctx.env, catalog);
248
819
  // @implements A-SPEC-102.8 — the walk runs only when the cheaper conditions already hold.
249
820
  const ancestry = !answered && !mode.run && ctx.interactive && marker === null
250
- ? (ctx.ancestry ?? (() => harnessAncestor(process.ppid, (0, harness_attestation_1.systemProcLookup)())))()
821
+ ? (ctx.ancestry ?? ((c) => operatorAncestry(process.ppid, c)))(catalog) // A-SPEC-732.4 — the lookup takes the walk's rule
251
822
  : { kind: 'none' };
252
- const harness = marker ?? (ancestry.kind === 'harness' ? `process:${ancestry.harness}` : null);
823
+ // @implements A-SPEC-102.30 — the marker is the environment's text: recorded escaped
824
+ const harness = marker !== null ? (0, harness_catalog_1.printable)(marker) : ancestry.kind === 'harness' ? `process:${ancestry.harness}` : null;
825
+ // @implements A-SPEC-102.29 — the file that added the marker or name, recorded with the verdict; A-SPEC-102.30 — all of them
826
+ const harnessSources = (marker !== null ? (0, harness_catalog_1.markerSource)(marker, catalog) : ancestry.kind === 'harness' ? ancestry.sources ?? [] : []).map(harness_catalog_1.printable);
253
827
  const person = answered || (!mode.run && ctx.interactive && harness === null && ancestry.kind === 'none');
254
828
  const touched = rangeAnchors(root, range.base, range.head);
255
829
  const anchored = 'error' in touched ? [] : touched.aspecs;
@@ -266,8 +840,9 @@ function recordVerdict(root, input, ctx) {
266
840
  ...(input.engine ? { engine: input.engine } : {}),
267
841
  ...(input.model ? { model: input.model } : {}),
268
842
  person,
269
- ...(answered ? { channel: ctx.answeredBy } : {}), // @implements A-SPEC-102.9
843
+ ...(answered ? { channel: (0, human_channel_1.ledgerActor)(ctx.answeredBy) } : {}), // @implements A-SPEC-102.9, A-SPEC-792.26
270
844
  ...(harness ? { harness } : {}),
845
+ ...(harnessSources.length > 0 ? { harnessSources } : {}),
271
846
  ...(ancestry.kind === 'unreadable' ? { ancestry: ancestry.reason } : {}),
272
847
  },
273
848
  authors,
@@ -282,6 +857,8 @@ function recordVerdict(root, input, ctx) {
282
857
  }
283
858
  /** Open findings, last line per id winning, from the main checkout's and the root's findings ledgers. */
284
859
  function openFindings(root) {
860
+ // A-SPEC-102.32 — non-strict: a forged pointer reads only the worktree's findings, so the main checkout's open ones are
861
+ // not counted; a pointer that cannot be opened throws to the caller
285
862
  const main = (0, run_records_1.mainCheckoutOf)(root);
286
863
  const files = [...new Set([main, path.resolve(root)].map((d) => path.join(d, '.ax', 'ledger', 'findings.jsonl')))];
287
864
  const last = new Map();
@@ -325,6 +902,8 @@ function gateRange(root, base, head, opts) {
325
902
  return { ok: false, reasons: [range.error] };
326
903
  const reasons = [];
327
904
  let verdicts;
905
+ // A-SPEC-102.32 — non-strict: a forged pointer reads the worktree's verdict ledger instead of the main checkout's; a
906
+ // throw reads as a ledger that cannot be read
328
907
  try {
329
908
  verdicts = readVerdicts((0, run_records_1.mainCheckoutOf)(root));
330
909
  }
@@ -337,6 +916,12 @@ function gateRange(root, base, head, opts) {
337
916
  reasons.push(`no independent verdict covers ${range.base}..${range.head}`);
338
917
  else if (latest.verdict !== 'pass')
339
918
  reasons.push(`the latest independent verdict is fail (${latest.ts})`);
919
+ // @implements A-SPEC-774.50 — a range a tainted run authored is ready only on a person's independent pass
920
+ // A-SPEC-102.32 — non-strict: a forged pointer reads the worktree's runs, so the main checkout's tainted run is not seen
921
+ const tainted = taintedAuthors((0, run_records_1.mainCheckoutOf)(root), range.base, range.head);
922
+ if (tainted.length > 0 && !(latest && latest.verdict === 'pass' && latest.reviewer?.person)) {
923
+ reasons.push(`run ${tainted.map((t) => t.run).join(', ')} that authored this range is tainted (${tainted[0].reason}) — only a person's independent pass makes it ready`);
924
+ }
340
925
  const open = openFindings(root);
341
926
  for (const f of open.unreadable)
342
927
  reasons.push(`the findings ledger ${f} cannot be read`);
@@ -350,7 +935,7 @@ function gateRange(root, base, head, opts) {
350
935
  * @implements A-SPEC-102.10 — the run's review rounds that failed: independent `fail` verdicts on the run's base, across
351
936
  * every head the remediation moved to. Returned oldest first, so the last carries the findings still unresolved.
352
937
  */
353
- function failingRounds(main, base) {
938
+ function failingRounds(main, base, head, cwd = main, rec) {
354
939
  let all;
355
940
  try {
356
941
  all = readVerdicts(main);
@@ -358,7 +943,25 @@ function failingRounds(main, base) {
358
943
  catch {
359
944
  return [];
360
945
  }
361
- return all.filter((v) => v.independent && v.verdict === 'fail' && v.base === base);
946
+ if (head === undefined)
947
+ return all.filter((v) => v.independent && v.verdict === 'fail' && v.base === base);
948
+ // @implements A-SPEC-102.14 — the run's own lineage: fail verdicts whose head is a commit of base..head, under any
949
+ // recorded base. Another task sharing the base does not count; a reviewer recording another base does not escape.
950
+ const lineage = new Set([head, ...lines(gitOut(cwd, ['rev-list', `--max-count=${MAX_COMMITS}`, `${base}..${head}`]))]);
951
+ // @implements A-SPEC-102.18 — an amend or a rewrite does not reset the count: the run's own commits since its start
952
+ // (what it amended or reset away included) are its lineage too, and so is a head carrying a lineage commit's change.
953
+ if (rec)
954
+ for (const c of runAuthoredCommits(rec) ?? [])
955
+ lineage.add(c);
956
+ const failed = all.filter((v) => v.independent && v.verdict === 'fail');
957
+ const outside = [...new Set(failed.map((v) => v.head).filter((h) => !lineage.has(h)))];
958
+ if (outside.length > 0) {
959
+ const lineagePids = new Set(patchIds(cwd, [...lineage]).values());
960
+ for (const [sha, pid] of patchIds(cwd, outside))
961
+ if (lineagePids.has(pid))
962
+ lineage.add(sha);
963
+ }
964
+ return failed.filter((v) => lineage.has(v.head));
362
965
  }
363
966
  function rangeStatus(root, base, head) {
364
967
  const range = resolveRange(root, base, head);
@@ -367,6 +970,7 @@ function rangeStatus(root, base, head) {
367
970
  const open = openFindings(root);
368
971
  return {
369
972
  ...range,
973
+ // A-SPEC-102.32 — non-strict: a forged pointer shows the worktree's verdicts; one that cannot be opened throws
370
974
  verdicts: readVerdicts((0, run_records_1.mainCheckoutOf)(root)).filter((v) => v.base === range.base && v.head === range.head),
371
975
  open: { critical: open.critical, important: open.important },
372
976
  };