@holmes-lab/holmes-kit 0.38.0 → 0.40.0

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 (308) hide show
  1. package/CHANGELOG.md +370 -6
  2. package/README.md +58 -40
  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 +50 -13
  47. package/dist/holmes/cli/approve.js +260 -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 +45 -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 +206 -424
  65. package/dist/holmes/cli/init.js +33 -0
  66. package/dist/holmes/cli/lock-recover.d.ts +5 -0
  67. package/dist/holmes/cli/lock-recover.js +126 -0
  68. package/dist/holmes/cli/mcp-processes.d.ts +32 -0
  69. package/dist/holmes/cli/mcp-processes.js +132 -0
  70. package/dist/holmes/cli/release-docs.js +1 -1
  71. package/dist/holmes/cli/run-exec.d.ts +141 -0
  72. package/dist/holmes/cli/run-exec.js +1435 -0
  73. package/dist/holmes/cli/run-provision.d.ts +8 -0
  74. package/dist/holmes/cli/run-provision.js +325 -0
  75. package/dist/holmes/cli/run-wiring.d.ts +69 -0
  76. package/dist/holmes/cli/run-wiring.js +270 -0
  77. package/dist/holmes/cli/run.d.ts +26 -0
  78. package/dist/holmes/cli/run.js +364 -83
  79. package/dist/holmes/cli/runtime-binding-approval.js +32 -19
  80. package/dist/holmes/cli/screen-safe.d.ts +3 -92
  81. package/dist/holmes/cli/screen-safe.js +18 -756
  82. package/dist/holmes/config/config.d.ts +2 -0
  83. package/dist/holmes/config/config.js +5 -2
  84. package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
  85. package/dist/holmes/cpg/import-resolver.js +1 -1
  86. package/dist/holmes/governance/approval-decisions.d.ts +47 -0
  87. package/dist/holmes/governance/approval-decisions.js +29 -0
  88. package/dist/holmes/governance/approval-grants.d.ts +220 -1
  89. package/dist/holmes/governance/approval-grants.js +612 -33
  90. package/dist/holmes/governance/approval-queue.d.ts +31 -0
  91. package/dist/holmes/governance/approval-queue.js +122 -11
  92. package/dist/holmes/governance/approval-spend.d.ts +95 -0
  93. package/dist/holmes/governance/approval-spend.js +191 -0
  94. package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
  95. package/dist/holmes/governance/autonomous-shell.js +332 -0
  96. package/dist/holmes/governance/autonomy.d.ts +5 -0
  97. package/dist/holmes/governance/autonomy.js +16 -11
  98. package/dist/holmes/governance/constitution.d.ts +5 -0
  99. package/dist/holmes/governance/constitution.js +32 -12
  100. package/dist/holmes/governance/full-autonomy.d.ts +10 -0
  101. package/dist/holmes/governance/full-autonomy.js +103 -7
  102. package/dist/holmes/governance/harness-catalog.d.ts +103 -0
  103. package/dist/holmes/governance/harness-catalog.js +348 -0
  104. package/dist/holmes/governance/human-channel.d.ts +38 -0
  105. package/dist/holmes/governance/human-channel.js +49 -0
  106. package/dist/holmes/governance/install-manifest.d.ts +22 -0
  107. package/dist/holmes/governance/install-manifest.js +160 -0
  108. package/dist/holmes/governance/ledger-rechain.js +2 -0
  109. package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
  110. package/dist/holmes/governance/ledger-store.conformance.js +66 -0
  111. package/dist/holmes/governance/ledger-store.d.ts +88 -11
  112. package/dist/holmes/governance/ledger-store.js +186 -8
  113. package/dist/holmes/governance/provenance-chain.d.ts +16 -4
  114. package/dist/holmes/governance/provenance-chain.js +19 -4
  115. package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
  116. package/dist/holmes/governance/provenance-ledger.js +53 -18
  117. package/dist/holmes/governance/push-gate-runner.js +11 -7
  118. package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
  119. package/dist/holmes/governance/recorded-pairs.js +522 -0
  120. package/dist/holmes/governance/replica-id.d.ts +1 -1
  121. package/dist/holmes/governance/replica-id.js +1 -1
  122. package/dist/holmes/governance/spec-seam.d.ts +59 -0
  123. package/dist/holmes/governance/spec-seam.js +587 -0
  124. package/dist/holmes/governance/spend-kinds.d.ts +16 -0
  125. package/dist/holmes/governance/spend-kinds.js +18 -0
  126. package/dist/holmes/governance/tool-actions.js +2 -0
  127. package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
  128. package/dist/holmes/guardrail/decision-ledger.js +2 -1
  129. package/dist/holmes/guardrail/impact-gate.d.ts +1 -0
  130. package/dist/holmes/guardrail/impact-gate.js +1 -1
  131. package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
  132. package/dist/holmes/guardrail/line-continuation.js +39 -0
  133. package/dist/holmes/guardrail/operator-person.d.ts +28 -4
  134. package/dist/holmes/guardrail/operator-person.js +57 -11
  135. package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
  136. package/dist/holmes/guardrail/refusal-codes.js +70 -10
  137. package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
  138. package/dist/holmes/guardrail/risk-classifier.js +245 -15
  139. package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
  140. package/dist/holmes/guardrail/risk-gate.js +7 -34
  141. package/dist/holmes/guardrail/risk-types.d.ts +10 -0
  142. package/dist/holmes/guardrail/run-plan-scope.js +3 -1
  143. package/dist/holmes/guardrail/run-refusals.d.ts +6 -1
  144. package/dist/holmes/guardrail/run-refusals.js +36 -14
  145. package/dist/holmes/guardrail/run-stages.d.ts +10 -0
  146. package/dist/holmes/guardrail/run-stages.js +46 -6
  147. package/dist/holmes/guardrail/scope-judgment.js +1 -1
  148. package/dist/holmes/guardrail/shell-words.js +24 -3
  149. package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
  150. package/dist/holmes/guardrail/unresolved-write.js +556 -0
  151. package/dist/holmes/guardrail/write-target.d.ts +3 -0
  152. package/dist/holmes/guardrail/write-target.js +26 -5
  153. package/dist/holmes/hooks/pre-tool-use.d.ts +105 -1
  154. package/dist/holmes/hooks/pre-tool-use.js +1167 -168
  155. package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
  156. package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
  157. package/dist/holmes/hooks/session-start.d.ts +5 -0
  158. package/dist/holmes/hooks/session-start.js +29 -1
  159. package/dist/holmes/hooks/stop.d.ts +23 -0
  160. package/dist/holmes/hooks/stop.js +88 -33
  161. package/dist/holmes/mcp/approval-adapters.js +3 -1
  162. package/dist/holmes/mcp/approval-commit.js +3 -2
  163. package/dist/holmes/mcp/approval-policy.d.ts +2 -1
  164. package/dist/holmes/mcp/approval-policy.js +3 -1
  165. package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
  166. package/dist/holmes/mcp/handlers/approval-ask.d.ts +14 -0
  167. package/dist/holmes/mcp/handlers/approval-ask.js +31 -6
  168. package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
  169. package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
  170. package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
  171. package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
  172. package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
  173. package/dist/holmes/mcp/handlers/entity-store.js +133 -59
  174. package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
  175. package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
  176. package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
  177. package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
  178. package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
  179. package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
  180. package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
  181. package/dist/holmes/mcp/handlers/review-queries.js +8 -1
  182. package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
  183. package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
  184. package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
  185. package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
  186. package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
  187. package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
  188. package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
  189. package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
  190. package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
  191. package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
  192. package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
  193. package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
  194. package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
  195. package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
  196. package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
  197. package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
  198. package/dist/holmes/mcp/handlers/test-execution.d.ts +1 -1
  199. package/dist/holmes/mcp/handlers/workspace-preflight.d.ts +5 -0
  200. package/dist/holmes/mcp/handlers/workspace-preflight.js +10 -2
  201. package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
  202. package/dist/holmes/mcp/handlers.d.ts +99 -79
  203. package/dist/holmes/mcp/handlers.js +93 -25
  204. package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
  205. package/dist/holmes/mcp/harness-attestation.js +325 -53
  206. package/dist/holmes/mcp/maintenance-analyze.d.ts +1 -1
  207. package/dist/holmes/mcp/maintenance-analyze.js +9 -9
  208. package/dist/holmes/mcp/maintenance-evidence.js +31 -2
  209. package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
  210. package/dist/holmes/mcp/server-staleness.d.ts +43 -0
  211. package/dist/holmes/mcp/server-staleness.js +158 -0
  212. package/dist/holmes/mcp/server.js +34 -9
  213. package/dist/holmes/mcp/spec-id-guard.js +1 -1
  214. package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
  215. package/dist/holmes/mcp/tool-schemas.js +42 -2
  216. package/dist/holmes/project/act-root.d.ts +19 -0
  217. package/dist/holmes/project/act-root.js +100 -0
  218. package/dist/holmes/project/baseline.js +4 -3
  219. package/dist/holmes/project/bounded-group.d.ts +47 -0
  220. package/dist/holmes/project/bounded-group.js +140 -0
  221. package/dist/holmes/project/bounded-io.d.ts +50 -2
  222. package/dist/holmes/project/bounded-io.js +138 -6
  223. package/dist/holmes/project/change-source.js +2 -2
  224. package/dist/holmes/project/instance-id.d.ts +10 -0
  225. package/dist/holmes/project/instance-id.js +233 -0
  226. package/dist/holmes/project/machine-identity.d.ts +25 -0
  227. package/dist/holmes/project/machine-identity.js +133 -0
  228. package/dist/holmes/project/owned-lock.d.ts +84 -0
  229. package/dist/holmes/project/owned-lock.js +263 -0
  230. package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
  231. package/dist/holmes/project/plain-lock-fs.js +126 -0
  232. package/dist/holmes/project/request-lock.d.ts +85 -0
  233. package/dist/holmes/project/request-lock.js +459 -0
  234. package/dist/holmes/project/root.d.ts +12 -4
  235. package/dist/holmes/project/root.js +26 -7
  236. package/dist/holmes/project/run-records.d.ts +19 -0
  237. package/dist/holmes/project/run-records.js +94 -12
  238. package/dist/holmes/project/screen-text.d.ts +94 -0
  239. package/dist/holmes/project/screen-text.js +763 -0
  240. package/dist/holmes/project/spend-lock.d.ts +82 -0
  241. package/dist/holmes/project/spend-lock.js +413 -0
  242. package/dist/holmes/project/workspace-preflight.d.ts +5 -0
  243. package/dist/holmes/project/workspace-preflight.js +24 -1
  244. package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
  245. package/dist/holmes/refresh/freshness-coordinator.js +1 -1
  246. package/dist/holmes/review/condition-hunk-replay.js +4 -2
  247. package/dist/holmes/review/confidence-calibration.d.ts +1 -1
  248. package/dist/holmes/review/confidence-calibration.js +1 -1
  249. package/dist/holmes/review/content-verify.js +1 -1
  250. package/dist/holmes/review/hop-ablation.d.ts +4 -4
  251. package/dist/holmes/review/hop-ablation.js +5 -5
  252. package/dist/holmes/review/point-in-time-replay.js +12 -3
  253. package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
  254. package/dist/holmes/review/rank-diagnosis.js +1 -1
  255. package/dist/holmes/review/replay-corpus.d.ts +10 -4
  256. package/dist/holmes/review/replay-corpus.js +25 -9
  257. package/dist/holmes/review/requirement-triage.js +2 -2
  258. package/dist/holmes/review/semantic-arm.d.ts +3 -3
  259. package/dist/holmes/review/semantic-arm.js +3 -3
  260. package/dist/holmes/review/test-outcomes.js +3 -1
  261. package/dist/holmes/review/test-runner.d.ts +11 -0
  262. package/dist/holmes/review/test-runner.js +31 -10
  263. package/dist/holmes/review/test-selection-breadth.js +2 -2
  264. package/dist/holmes/review/verdicts.d.ts +109 -7
  265. package/dist/holmes/review/verdicts.js +653 -34
  266. package/dist/holmes/rtm/anchor-census.d.ts +9 -0
  267. package/dist/holmes/rtm/anchor-census.js +151 -0
  268. package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
  269. package/dist/holmes/rtm/anchor-ids.js +45 -2
  270. package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
  271. package/dist/holmes/rtm/comment-ranges.js +104 -0
  272. package/dist/holmes/rtm/counted-tests.d.ts +1 -0
  273. package/dist/holmes/rtm/counted-tests.js +63 -0
  274. package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
  275. package/dist/holmes/rtm/known-defects.js +1 -1
  276. package/dist/holmes/rtm/localize.js +1 -1
  277. package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
  278. package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
  279. package/dist/holmes/rtm/test-scope.d.ts +31 -0
  280. package/dist/holmes/rtm/test-scope.js +166 -5
  281. package/dist/holmes/rtm/trace-gaps.js +1 -1
  282. package/dist/holmes/runtime/dispatch.d.ts +10 -0
  283. package/dist/holmes/runtime/dispatch.js +12 -1
  284. package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
  285. package/dist/holmes/semantic/cloud-usage.js +1 -1
  286. package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
  287. package/dist/holmes/semantic/unreadable-paths.js +1 -1
  288. package/dist/holmes/spec/approval-blockers.js +1 -1
  289. package/dist/holmes/spec/entity-store.d.ts +6 -1
  290. package/dist/holmes/spec/entity-store.js +16 -2
  291. package/dist/holmes/spec/entity-transaction.d.ts +7 -2
  292. package/dist/holmes/spec/entity-transaction.js +87 -170
  293. package/dist/holmes/spec/spec-store.d.ts +12 -6
  294. package/dist/holmes/spec/spec-store.js +4 -2
  295. package/dist/holmes/spec/spec-types.js +1 -1
  296. package/dist/holmes/spec/succession-guard.d.ts +56 -0
  297. package/dist/holmes/spec/succession-guard.js +187 -0
  298. package/dist/holmes/spec/succession.d.ts +70 -0
  299. package/dist/holmes/spec/succession.js +171 -0
  300. package/dist/holmes/spec/transition-policy.d.ts +2 -2
  301. package/docs/install-guide.md +9 -3
  302. package/docs/language-support.md +78 -0
  303. package/package.json +4 -3
  304. package/playbooks/author-slice/PLAYBOOK.md +1 -1
  305. package/playbooks/promote-slice/PLAYBOOK.md +5 -1
  306. package/playbooks/publish/PLAYBOOK.md +45 -33
  307. package/dist/holmes/review/manual-baseline.d.ts +0 -209
  308. package/dist/holmes/review/manual-baseline.js +0 -2847
@@ -36,8 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.approvalRequestOf = approvalRequestOf;
37
37
  exports.nextActionOf = nextActionOf;
38
38
  exports.createOperatorInspectionHandlers = createOperatorInspectionHandlers;
39
- // @implements A-SPEC-605, A-SPEC-605.1, A-SPEC-779.3
40
- // @implements A-SPEC-642
39
+ // @implements A-SPEC-605, A-SPEC-605.1, A-SPEC-779.3, A-SPEC-245.17, A-SPEC-794.33, A-SPEC-794.34, A-SPEC-794.35, A-SPEC-794.37, A-SPEC-794.40, A-SPEC-794.41, A-SPEC-794.42, A-SPEC-794.44
40
+ // @implements A-SPEC-642, A-SPEC-245.9, A-SPEC-245.15
41
41
  // @implements A-SPEC-631
42
42
  // @implements A-SPEC-768
43
43
  const fs = __importStar(require("node:fs"));
@@ -49,6 +49,7 @@ const ledger_timeline_1 = require("../../governance/ledger-timeline");
49
49
  const provenance_ledger_1 = require("../../governance/provenance-ledger");
50
50
  const provenance_chain_1 = require("../../governance/provenance-chain");
51
51
  const approval_grants_1 = require("../../governance/approval-grants");
52
+ const approve_1 = require("../../cli/approve");
52
53
  const approval_queue_1 = require("../../governance/approval-queue");
53
54
  /**
54
55
  * @implements A-SPEC-768
@@ -72,8 +73,26 @@ function approvalRequestOf(root, specId) {
72
73
  const d = q.decisions[id];
73
74
  if (!d)
74
75
  return undefined;
75
- if (d.event === 'granted')
76
- return { id, state: d.consumedTs ? 'consumed' : 'granted', ts: d.consumedTs ?? d.ts };
76
+ // @implements A-SPEC-245.9 (1b-6) — a live grant is reported with its use count and expiry
77
+ if (d.event === 'granted') {
78
+ // @implements A-SPEC-794.35 — one judgement with --status and --list: what `resolveApproval` says of the act now
79
+ // (A-M2: an expired, other-target or other-workspace file read `granted` here while it covered nothing)
80
+ // @implements A-SPEC-245.17 (item 4) — a grant past its expiry (or with an empty one) is expired, not granted
81
+ // @implements A-SPEC-245.18 (5c) — an expiry that is not a date is expired too: `grantedStateOf`, the one order (794.37)
82
+ const grant = (0, approval_grants_1.requestGrantState)(root, id, { kind: 'spec-approve', target: specId }, new Date().toISOString());
83
+ const state = (0, approval_grants_1.grantedStateOf)({ covers: grant.state === 'covers', claimed: grant.state === 'claimed', ...(d.consumedTs ? { consumedTs: d.consumedTs } : {}), ...(d.expires !== undefined ? { expires: d.expires } : {}) }, Date.now());
84
+ if (state === 'live')
85
+ return { id, state: 'granted', validity: (0, approve_1.grantValidityText)(d.expires), ts: d.ts };
86
+ if (state === 'claimed')
87
+ return { id, state: 'claimed', ts: d.ts };
88
+ if (state === 'consumed')
89
+ return { id, state: 'consumed', ts: d.consumedTs };
90
+ if (state === 'expired')
91
+ return { id, state: 'expired', ts: d.expires || d.ts };
92
+ // @implements A-SPEC-794.33, A-SPEC-794.34 — a granted row no grant covers is unusable: "call spec_approve now" sent
93
+ // the agent into a refusal (a removed file, a dangling link, a file that does not parse)
94
+ return { id, state: 'unusable', ts: d.ts, ...(grant.state === 'none' && grant.staleClaim ? { reason: 'a process that ended left its claim on this grant; holmes-kit doctor names it' } : {}) };
95
+ }
77
96
  return { id, state: d.event, ...(d.reason ? { reason: d.reason } : {}), ts: d.ts };
78
97
  }
79
98
  catch {
@@ -93,8 +112,13 @@ function nextActionOf(described, request) {
93
112
  case 'denied': return `denied — ${request.reason ?? 'no reason recorded'}. Do not re-request the same act; report it to the user.`;
94
113
  case 'revoked': return `revoked — ${request.reason ?? 'no reason recorded'}. Do not re-request the same act; report it to the user.`;
95
114
  // @implements A-SPEC-779.3
96
- case 'withdrawn': return `withdrawn by the run that filed it — ${request.reason ?? 'no reason recorded'}. If the seal is still needed, spec_approve files a new request.`;
97
- case 'granted': return 'granted — call spec_approve now; the grant seals it.';
115
+ case 'withdrawn': return `withdrawn by whoever filed it, a run or a session's MCP server — ${request.reason ?? 'no reason recorded'}. If the seal is still needed, spec_approve files a new request.`;
116
+ case 'granted': return `granted (${request.validity ?? 'single use'}) — call spec_approve now; the grant seals it once.`;
117
+ // @implements A-SPEC-794.33
118
+ case 'unusable': return `granted, but the grant covers nothing now (${request.reason ?? 'its file is missing, unreadable, expired or bound elsewhere'}) — call spec_approve to file a new request and wait for the decision.`;
119
+ // @implements A-SPEC-794.35
120
+ case 'claimed': return 'granted, and an act holds the grant now — do not call spec_approve again; call approval_status after that act ends.';
121
+ case 'expired': return `expired — the grant ended unused (${request.ts ?? 'no time recorded'}); it covers nothing. Call spec_approve to file a new request and wait for the decision.`;
98
122
  case 'consumed': return 'the grant was consumed but this spec is not sealed — call spec_approve again, and report its refusal to the user if it refuses.';
99
123
  case 'pending': return "pending the operator's decision — wait, then call approval_status again; when sealed is true, retry spec_approve immediately.";
100
124
  default: break;
@@ -115,6 +139,9 @@ function createOperatorInspectionHandlers(context) {
115
139
  */
116
140
  async approval_status(a) {
117
141
  context.assertStoreReachable('approval_status', a.root); // @implements A-SPEC-419
142
+ // @implements A-SPEC-794.41 — a request id is the wrong key, and "not found" read as "no such request" (D11)
143
+ if (/^req-/.test(a.id))
144
+ return { ok: false, reason: `${a.id} is a request id: approval_status takes a spec id (a request a session's MCP server filed for a spec shows under approval_status <spec id>) and cannot see a request a hook filed — for one a refusal named, call approval_ask with its id` }; // A-SPEC-794.44 — no typed command (A-SPEC-792.1)
118
145
  const all = await context.listSpecs();
119
146
  if (all.filter((s) => s.id === a.id).length > 1) {
120
147
  return {
@@ -361,7 +388,11 @@ function createOperatorInspectionHandlers(context) {
361
388
  const dir = path.join(dest.root, '.ax', 'ledger');
362
389
  const store = new ledger_store_1.FileLedgerStore(dir);
363
390
  const pending = store.doubleSpends();
364
- const match = pending.find((d) => d.nonce === nonce);
391
+ // @implements A-SPEC-245.17 (6a) — every pending entry of the nonce (a double spend and the revocation it overran)
392
+ // is closed by one row naming all their events, so one reconcile (one approval) settles the nonce
393
+ const entries = pending.filter((d) => d.nonce === nonce);
394
+ const match = entries.length === 0 ? undefined
395
+ : { ...entries[0], events: [...new Map(entries.flatMap((d) => d.events).map((e) => [`${e.replicaId ?? ''}\0${e.hash}`, e])).values()] };
365
396
  if (!match) {
366
397
  return { ok: true, reconciled: false, nonce, pending: pending.map((d) => d.nonce),
367
398
  reason: pending.length === 0 ? 'the merged ledger holds no unreconciled double-spend' : `${nonce} is not an unreconciled double-spend; pending: ${pending.map((d) => d.nonce).join(', ')}` };
@@ -385,15 +416,47 @@ function createOperatorInspectionHandlers(context) {
385
416
  if (chainBreaks.length > 0) {
386
417
  return { ok: false, code: 'audit-conflict', reason: 'ledger_reconcile cannot extend a broken chain: ' + chainBreaks.map((b) => `${b.replicaId ?? 'legacy'}: ${b.detail ?? 'broken'}`).join('; ') };
387
418
  }
388
- store.append({
389
- ts: now, actor: resolved.approval.actor, kind: provenance_ledger_1.DOUBLE_SPEND_RECONCILED,
390
- summary: `reconciled cross-replica double-spend of ${nonce}: ${match.events.length} consumptions on ${replicas.join(', ')}`.slice(0, 200),
391
- inputs: [nonce, ...match.events.map((e) => 'event:' + e.hash), ...replicas.map((r) => 'replica:' + r)],
392
- rationale: typeof a.rationale === 'string' && a.rationale.trim() !== '' ? a.rationale.trim() : resolved.approval.rationale,
393
- authorization: (0, provenance_chain_1.authorizationRef)(resolved.approval.actor, resolved.approval.token),
394
- });
395
- if (resolved.source === 'grant' && resolved.approval.nonce)
396
- (0, approval_grants_1.consumeGrantFile)(resolved.root ?? dest.root, String(resolved.approval.nonce));
419
+ // @implements A-SPEC-245.3 — the grant is claimed for the append it authorizes and committed after it
420
+ const claim = resolved.source === 'grant' && resolved.approval.nonce ? (0, approval_grants_1.claimGrant)(resolved.root ?? dest.root, String(resolved.approval.nonce)) : undefined;
421
+ if (claim === null)
422
+ return { ok: false, code: 'grant-in-use', reason: `the approval grant for reconciling ${nonce} is in use by another act — nothing was appended; retry, or ask for a new approval` };
423
+ let spent = false;
424
+ try {
425
+ // @implements A-SPEC-245.9 (1b-1), N9 — the grant's spend row, once across replicas, then the reconcile row
426
+ if (claim) {
427
+ (0, approval_grants_1.spendGrantApprovals)(resolved.root ?? dest.root, [resolved.approval], `ledger-reconcile ${nonce}`);
428
+ spent = true;
429
+ }
430
+ store.append({
431
+ ts: now, actor: resolved.approval.actor, kind: provenance_ledger_1.DOUBLE_SPEND_RECONCILED,
432
+ summary: `reconciled cross-replica double-spend of ${nonce}: ${match.events.length} consumptions on ${replicas.join(', ')}`.slice(0, 200),
433
+ inputs: [nonce, ...match.events.map((e) => 'event:' + e.hash), ...replicas.map((r) => 'replica:' + r)],
434
+ rationale: typeof a.rationale === 'string' && a.rationale.trim() !== '' ? a.rationale.trim() : resolved.approval.rationale,
435
+ authorization: (0, provenance_chain_1.authorizationRef)(resolved.approval.actor, resolved.approval.token),
436
+ });
437
+ }
438
+ catch (e) {
439
+ // @implements A-SPEC-245.15 (item 2) — a failed append after the spend commits the claim: the grant is used
440
+ if (spent) {
441
+ try {
442
+ claim?.commit();
443
+ }
444
+ catch (c) {
445
+ process.stderr.write(`[Holmes-Kit] ${c.message}\n`);
446
+ }
447
+ }
448
+ else
449
+ claim?.release();
450
+ if (e instanceof approval_grants_1.GrantSpendRefusal)
451
+ return { ok: false, code: 'grant-spend-refused', reason: `${nonce} was not reconciled: ${e.message}` };
452
+ throw e;
453
+ }
454
+ try {
455
+ claim?.commit();
456
+ }
457
+ catch (e) {
458
+ process.stderr.write(`[Holmes-Kit] ${e.message}\n`);
459
+ }
397
460
  return { ok: true, reconciled: true, nonce, events: match.events, remaining: store.doubleSpends().map((d) => d.nonce) };
398
461
  },
399
462
  // @implements A-SPEC-545.3 — "show me the RTM dashboard" launches (idempotently) the server the
@@ -63,7 +63,7 @@ export declare function createPhaseQueryHandlers(context: PhaseQueryContext): {
63
63
  }[];
64
64
  matched: number;
65
65
  ok?: undefined;
66
- reason?: undefined;
66
+ readonly reason?: undefined;
67
67
  }>;
68
68
  phase_check(a: {
69
69
  action?: Action;
@@ -45,7 +45,7 @@ export declare function createRequirementTriageHandlers(context: RequirementTria
45
45
  suppressed?: true | undefined;
46
46
  availability: string;
47
47
  missingLineages?: string[] | undefined;
48
- tier: "local" | "none" | "cloud";
48
+ tier: "none" | "local" | "cloud";
49
49
  covered: number;
50
50
  total: number;
51
51
  unlineaged: number;
@@ -105,7 +105,7 @@ export declare function createRequirementTriageHandlers(context: RequirementTria
105
105
  suppressed?: true | undefined;
106
106
  availability: string;
107
107
  missingLineages?: string[] | undefined;
108
- tier: "local" | "none" | "cloud";
108
+ tier: "none" | "local" | "cloud";
109
109
  covered: number;
110
110
  total: number;
111
111
  unlineaged: number;
@@ -187,7 +187,7 @@ export declare function createRequirementTriageHandlers(context: RequirementTria
187
187
  suppressed?: true | undefined;
188
188
  availability: string;
189
189
  missingLineages?: string[] | undefined;
190
- tier: "local" | "none" | "cloud";
190
+ tier: "none" | "local" | "cloud";
191
191
  covered: number;
192
192
  total: number;
193
193
  unlineaged: number;
@@ -253,7 +253,7 @@ export declare function createRequirementTriageHandlers(context: RequirementTria
253
253
  suppressed?: true | undefined;
254
254
  availability: string;
255
255
  missingLineages?: string[] | undefined;
256
- tier: "local" | "none" | "cloud";
256
+ tier: "none" | "local" | "cloud";
257
257
  covered: number;
258
258
  total: number;
259
259
  unlineaged: number;
@@ -68,7 +68,7 @@ export declare function createReviewEvidenceHandlers(context: ReviewEvidenceCont
68
68
  };
69
69
  reviewNeeded: ReviewNeeded[];
70
70
  ok?: undefined;
71
- reason?: undefined;
71
+ readonly reason?: undefined;
72
72
  } | {
73
73
  reviewNeeded: Array<{
74
74
  spec: string;
@@ -85,6 +85,6 @@ export declare function createReviewEvidenceHandlers(context: ReviewEvidenceCont
85
85
  minor: number;
86
86
  };
87
87
  ok?: undefined;
88
- reason?: undefined;
88
+ readonly reason?: undefined;
89
89
  }>;
90
90
  };
@@ -35,13 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.summarizeReviewNeeded = summarizeReviewNeeded;
37
37
  exports.createReviewEvidenceHandlers = createReviewEvidenceHandlers;
38
- // @implements A-SPEC-718.1, A-SPEC-718.2, A-SPEC-718, A-SPEC-746, A-SPEC-617, A-SPEC-100.2, A-SPEC-102.1, A-SPEC-133, A-SPEC-135, A-SPEC-141, A-SPEC-157, A-SPEC-160, A-SPEC-189, A-SPEC-191, A-SPEC-244, A-SPEC-245, A-SPEC-263.1, A-SPEC-497.1, A-SPEC-732
38
+ // @implements A-SPEC-718.1, A-SPEC-718.2, A-SPEC-718, A-SPEC-746, A-SPEC-617, A-SPEC-100.2, A-SPEC-102.1, A-SPEC-133, A-SPEC-135, A-SPEC-141, A-SPEC-157, A-SPEC-160, A-SPEC-189, A-SPEC-191, A-SPEC-244, A-SPEC-245, A-SPEC-263.1, A-SPEC-497.1, A-SPEC-732, A-SPEC-245.9
39
39
  const path = __importStar(require("node:path"));
40
40
  const findings_1 = require("../../review/findings");
41
41
  const review_targets_1 = require("../../review/review-targets");
42
42
  const elicit_approval_1 = require("../elicit-approval");
43
43
  const basis_1 = require("../basis");
44
44
  const ledger_store_1 = require("../../governance/ledger-store");
45
+ const approval_spend_1 = require("../../governance/approval-spend");
45
46
  const ledger_lock_1 = require("../../governance/ledger-lock");
46
47
  const approval_grants_1 = require("../../governance/approval-grants");
47
48
  const provenance_chain_1 = require("../../governance/provenance-chain");
@@ -255,7 +256,7 @@ function createReviewEvidenceHandlers(context) {
255
256
  // harm class the env nonce fixed in its round-4; collected now, spent only once the
256
257
  // whole batch has validated (directly before the append, like the nonce block).
257
258
  if (rrResolved.source === 'grant' && rrResolved.root && rrResolved.approval.nonce) {
258
- grantConsumptions.push({ root: rrResolved.root, nonce: rrResolved.approval.nonce });
259
+ grantConsumptions.push({ root: rrResolved.root, nonce: rrResolved.approval.nonce, approval: rrResolved.approval });
259
260
  }
260
261
  liftedCriticals.push(f.id);
261
262
  // The nonce block below enforces single-use on the ENV approval — so it must key on the
@@ -337,14 +338,22 @@ function createReviewEvidenceHandlers(context) {
337
338
  if (ledgerFile === null) {
338
339
  throw context.refusal('review_record: 단일 사용 승인(nonce)을 기록할 프로젝트 원장을 확정할 수 없습니다 — 1회성을 보장할 수 없어 거부합니다');
339
340
  }
340
- const won = (0, provenance_chain_1.consumeNonceExclusively)(String(approval.nonce), ledgerFile, {
341
- ts: new Date().toISOString(), actor: approval.actor, kind: 'nonce-consumed',
342
- summary: `consumed single-use approval for: review-resolve ${envLiftedCriticals.join(', ')}`.slice(0, 200),
343
- inputs: [(0, provenance_chain_1.nonceFingerprint)(String(approval.nonce))], rationale: approval.rationale,
344
- authorization: (0, provenance_chain_1.authorizationRef)(approval.actor, approval.token),
345
- }, { isNonceConsumed: (0, ledger_store_1.nonceConsumedIn)(ledgerFile) });
346
- if (!won) {
347
- throw context.refusal(`review_record: 단일 사용 승인(nonce)이 이미 소비되었습니다 — 재사용은 거부됩니다. 새 승인을 발급받으십시오`);
341
+ // @implements A-SPEC-245.9 (1b-1) — spent through spendApprovals under the workspace spend lock
342
+ let spent;
343
+ try {
344
+ spent = (0, approval_spend_1.spendApprovals)((0, approval_spend_1.projectRootOfChain)(ledgerFile), [{
345
+ nonce: String(approval.nonce), actor: approval.actor,
346
+ summary: `consumed single-use approval for: review-resolve ${envLiftedCriticals.join(', ')}`.slice(0, 200),
347
+ rationale: approval.rationale, authorization: (0, provenance_chain_1.authorizationRef)(approval.actor, approval.token),
348
+ }], {});
349
+ }
350
+ catch {
351
+ spent = 'error';
352
+ }
353
+ if (spent === 'error' || spent.ok === false) {
354
+ throw context.refusal(spent !== 'error' && spent.reason === 'spent'
355
+ ? `review_record: 단일 사용 승인(nonce)이 이미 소비되었습니다 — 재사용은 거부됩니다. 새 승인을 발급받으십시오`
356
+ : `review_record: ${(0, approval_spend_1.spendRefusalReason)(spent)}`);
348
357
  }
349
358
  }
350
359
  }
@@ -353,8 +362,23 @@ function createReviewEvidenceHandlers(context) {
353
362
  // burned the grant with nothing recorded — the exact harm the round-2 deferral was written
354
363
  // to fix, reintroduced through the env throw path). Only the append itself follows, and it
355
364
  // fails loudly.
365
+ // @implements A-SPEC-245.9 (1b-1) — each grant's row once across replicas under the spend lock, then its file
366
+ // (one call per workspace root, so every grant of the batch is spent or none is)
367
+ const grantRoots = new Map();
368
+ for (const g of grantConsumptions)
369
+ grantRoots.set(g.root, [...(grantRoots.get(g.root) ?? []), g.approval]);
370
+ for (const [root, approvals] of grantRoots) {
371
+ try {
372
+ (0, approval_grants_1.spendGrantApprovals)(root, approvals, `review-resolve ${liftedCriticals.join(', ')}`);
373
+ }
374
+ catch (e) {
375
+ if (e instanceof approval_grants_1.GrantSpendRefusal)
376
+ throw context.refusal(`review_record: ${e.message}`);
377
+ throw e;
378
+ }
379
+ }
356
380
  for (const g of grantConsumptions)
357
- (0, approval_grants_1.consumeGrantFile)(g.root, g.nonce);
381
+ (0, approval_grants_1.spendGrants)(g.root, [g.nonce]); // A-SPEC-245.2
358
382
  // @implements A-SPEC-157 — the server's OWN observation, not anything the caller sent.
359
383
  // @implements A-SPEC-160 — the ONLY caller that reads the on-disk build, so the divergence
360
384
  // marker can be sealed. Append INSIDE the same lock as the guard (round-6 TOCTOU).
@@ -60,6 +60,11 @@ export declare function createReviewQueryHandlers(context: ReviewQueryContext):
60
60
  since?: string;
61
61
  budget?: number;
62
62
  }): Promise<{
63
+ testCountDiagnostics?: {
64
+ file: string;
65
+ aspecs: string[];
66
+ reason: string;
67
+ }[] | undefined;
63
68
  scopeFallback?: "full" | undefined;
64
69
  package: import("../../review/package").ReviewPackage;
65
70
  unscannedChangedFiles: string[];
@@ -69,7 +69,14 @@ function createReviewQueryHandlers(context) {
69
69
  // did NOT ingest, computed from the same changedFiles/scanned already
70
70
  // derived above — no new git/scan calls.
71
71
  const { unscanned: unscannedChangedFiles } = (0, coverage_1.partitionChangedFiles)(changedFiles, scanned.map((f) => f.sourcePath));
72
- return { package: pkg, unscannedChangedFiles, changeSource, ...(scopeFallback ? { scopeFallback } : {}) };
72
+ // @implements A-SPEC-750.2 — the anchored test files ART-4 reads as empty, and why
73
+ const testCountDiagnostics = (() => { try {
74
+ return (0, test_scope_1.zeroCountDiagnostics)(root);
75
+ }
76
+ catch {
77
+ return undefined;
78
+ } })();
79
+ return { package: pkg, unscannedChangedFiles, changeSource, ...(scopeFallback ? { scopeFallback } : {}), ...(testCountDiagnostics ? { testCountDiagnostics } : {}) };
73
80
  }
74
81
  finally {
75
82
  g.close(); // release native SQLite handle even if assembly throws
@@ -6,7 +6,10 @@ export interface ReviewVerdictContext {
6
6
  attestation: () => {
7
7
  attested: boolean;
8
8
  reason?: string;
9
+ harness?: string;
9
10
  };
11
+ /** @implements A-SPEC-792.22 — the one form gate: a refusal reason, or null. */
12
+ formGate: () => string | null;
10
13
  env: () => NodeJS.ProcessEnv;
11
14
  }
12
15
  export declare function createReviewVerdictHandlers(context: ReviewVerdictContext): {
@@ -11,6 +11,7 @@ exports.createReviewVerdictHandlers = createReviewVerdictHandlers;
11
11
  const elicit_approval_1 = require("../elicit-approval");
12
12
  const verdicts_1 = require("../../review/verdicts");
13
13
  const approval_ask_1 = require("./approval-ask");
14
+ const human_channel_1 = require("../../governance/human-channel");
14
15
  /** interpretElicitResult's reasons: a client's automatic decline and a question are not a verdict. */
15
16
  const AUTOMATIC_DECLINE = 'the session client declined the approval form';
16
17
  const QUESTION = '질문: ';
@@ -34,8 +35,14 @@ function createReviewVerdictHandlers(context) {
34
35
  return refuse(`this session cannot show an approval form (${attestation.reason ?? 'not launched by a harness'})`);
35
36
  if (!context.elicit)
36
37
  return refuse('this session cannot show an approval form (the client did not advertise forms)');
37
- if (!approval_ask_1.FORM_WAITS_FOR_PERSON.has(client))
38
- return refuse(`a review verdict in the form is not yet measured for ${client} (it might answer forms by itself)`);
38
+ // @implements A-SPEC-792.22 — the one form gate, and a name is not enough: the attested harness must be claude too
39
+ const gated = context.formGate();
40
+ if (gated !== null)
41
+ return refuse(gated);
42
+ const harness = attestation.harness;
43
+ if (!approval_ask_1.FORM_WAITS_FOR_PERSON.has(client) || (harness !== undefined && harness !== 'claude')) {
44
+ return refuse(`a review verdict in the form is not yet measured for ${client}${harness !== undefined ? ` (attested as ${harness})` : ''} (it might answer forms by itself)`);
45
+ }
39
46
  const range = (0, verdicts_1.resolveRange)(root, a.base, a.head);
40
47
  if ('error' in range)
41
48
  return { ok: false, reason: range.error };
@@ -59,7 +66,7 @@ function createReviewVerdictHandlers(context) {
59
66
  const r = (0, verdicts_1.recordVerdict)(root, {
60
67
  base: range.base, head: range.head, verdict: granted ? 'pass' : 'fail',
61
68
  findings: granted ? [] : [reason ?? 'failed in the session form'],
62
- }, { env, cwd: root, interactive: false, answeredBy: `elicitation:${client}` });
69
+ }, { env, cwd: root, interactive: false, answeredBy: (0, human_channel_1.humanChannelActor)('elicitation', harness ?? 'unattested') }); // @implements A-SPEC-792.25
63
70
  if (!r.ok)
64
71
  return { ok: false, reason: r.reason };
65
72
  return { ok: true, decision: r.record.verdict, independent: r.record.independent, base: range.base, head: range.head };
@@ -9,7 +9,7 @@ export interface RiskAssessmentContext {
9
9
  boundNonceLedger(): string | null;
10
10
  }
11
11
  export declare function createRiskAssessmentHandlers(context: RiskAssessmentContext): {
12
- risk_check(a: {
12
+ risk_check(raw: {
13
13
  root?: string;
14
14
  action: RiskAction;
15
15
  approval?: Approval;
@@ -20,6 +20,11 @@ export declare function createRiskAssessmentHandlers(context: RiskAssessmentCont
20
20
  rationale?: string;
21
21
  }): Promise<{
22
22
  assessment: import("../../guardrail/risk-types").RiskAssessment;
23
- gate: import("../../guardrail/risk-gate").GateResult;
23
+ gate: {
24
+ blocked: boolean;
25
+ level: import("../../guardrail/risk-types").RiskLevel;
26
+ requiresApproval: boolean;
27
+ reasons: string[];
28
+ };
24
29
  }>;
25
30
  };
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createRiskAssessmentHandlers = createRiskAssessmentHandlers;
37
37
  // @implements A-SPEC-607, A-SPEC-100.2, A-SPEC-128
38
- // @implements A-SPEC-642
38
+ // @implements A-SPEC-642, A-SPEC-245.9
39
39
  const path = __importStar(require("node:path"));
40
40
  const spec_parser_1 = require("../../spec/spec-parser");
41
41
  const rtm_graph_1 = require("../../rtm/rtm-graph");
@@ -45,11 +45,33 @@ const risk_gate_1 = require("../../guardrail/risk-gate");
45
45
  const cspec_change_1 = require("../../guardrail/cspec-change");
46
46
  const provenance_chain_1 = require("../../governance/provenance-chain");
47
47
  const ledger_store_1 = require("../../governance/ledger-store");
48
+ const approval_spend_1 = require("../../governance/approval-spend");
48
49
  const decision_ledger_1 = require("../../guardrail/decision-ledger");
50
+ const human_channel_1 = require("../../governance/human-channel");
49
51
  function createRiskAssessmentHandlers(context) {
50
52
  return {
51
53
  // @implements A-SPEC-125.4
52
- async risk_check(a) {
54
+ async risk_check(raw) {
55
+ // @implements A-SPEC-792.25 — a tool's input never speaks for a person: an approval or actor that claims a
56
+ // person channel is refused outright, and every other actor from the input is recorded as tool-input:<actor>
57
+ // (F1-e.0d: a forged elicitation:claude-code approval was ledgered as a person's)
58
+ if ((0, human_channel_1.isHumanChannelActor)(raw.approval?.actor) || (0, human_channel_1.isHumanChannelActor)(raw.actor)) {
59
+ const assessment = (0, risk_classifier_1.assessRisk)({ ...raw.action });
60
+ const reasons = ['a tool input cannot carry a person\'s approval — a person-channel actor is written only by the server after its form gate'];
61
+ // @implements A-SPEC-792.26 — the refused forgery leaves a trace (nothing is spent): a blocked row by the input
62
+ const claim = (0, human_channel_1.isHumanChannelActor)(raw.approval?.actor) ? raw.approval?.actor : raw.actor;
63
+ const bound = context.boundNonceLedger();
64
+ try {
65
+ new decision_ledger_1.DecisionLedger(bound !== null ? path.join(path.dirname(bound), 'decisions.jsonl') : path.join(raw.root ?? '.', '.ax', 'ledger', 'decisions.jsonl')).record([{
66
+ ts: raw.ts, actor: (0, human_channel_1.toolInputActor)(claim), action: { ...raw.action }, level: assessment.level, decision: 'blocked',
67
+ rationale: raw.rationale ?? '', reasons: ['refused: a person-channel claim from tool input', ...assessment.reasons]
68
+ }]);
69
+ }
70
+ catch { /* 기록 실패가 이미 계산된 판정을 뒤집지 않는다 */ }
71
+ return { assessment, gate: { blocked: true, level: assessment.level, requiresApproval: true, reasons } };
72
+ }
73
+ const a = { ...raw, ...(raw.actor !== undefined ? { actor: (0, human_channel_1.toolInputActor)(raw.actor) } : {}),
74
+ ...(raw.approval ? { approval: { ...raw.approval, actor: (0, human_channel_1.toolInputActor)(raw.approval.actor) } } : {}) };
53
75
  const action = { ...a.action };
54
76
  if (a.root && a.changedSymbols && a.changedSymbols.length) {
55
77
  // @implements A-SPEC-189 §14 (round 13) — the derivation was computed and discarded, so the
@@ -114,22 +136,22 @@ function createRiskAssessmentHandlers(context) {
114
136
  }
115
137
  if (assessment.level === 'hard-hitl' && !gate.blocked && covers && (0, provenance_chain_1.nonceDeclared)(a.approval?.nonce)) {
116
138
  const ledgerFile = context.boundNonceLedger();
117
- let won = false;
139
+ // @implements A-SPEC-245.9 (1b-1) — spent through spendApprovals under the workspace spend lock
140
+ let spent = 'error';
118
141
  try {
119
- won = ledgerFile !== null && (0, provenance_chain_1.consumeNonceExclusively)(String(a.approval.nonce), ledgerFile, {
120
- ts: a.ts, actor: a.approval.actor, kind: 'nonce-consumed',
121
- summary: `consumed single-use approval for: ${coverTarget.kind} ${(0, provenance_chain_1.redactTarget)('command', coverTarget.target)}`.slice(0, 200),
122
- inputs: [(0, provenance_chain_1.nonceFingerprint)(String(a.approval.nonce))], rationale: a.approval.rationale,
123
- authorization: (0, provenance_chain_1.authorizationRef)(a.approval.actor, a.approval.token),
124
- }, { isNonceConsumed: (0, ledger_store_1.nonceConsumedIn)(ledgerFile) });
142
+ spent = ledgerFile === null ? 'error' : (0, approval_spend_1.spendApprovals)((0, approval_spend_1.projectRootOfChain)(ledgerFile), [{
143
+ nonce: String(a.approval.nonce), actor: a.approval.actor,
144
+ summary: `consumed single-use approval for: ${coverTarget.kind} ${(0, provenance_chain_1.redactTarget)('command', coverTarget.target)}`.slice(0, 200),
145
+ rationale: a.approval.rationale, authorization: (0, provenance_chain_1.authorizationRef)(a.approval.actor, a.approval.token),
146
+ }], {});
125
147
  }
126
148
  catch {
127
- won = false;
149
+ spent = 'error';
128
150
  } // 배타 확보 실패 = 허용 불가(fail-closed)
129
- if (!won) {
151
+ if (spent === 'error' || spent.ok === false) {
130
152
  gate = { ...gate, blocked: true, reasons: [...gate.reasons, ledgerFile === null
131
153
  ? '단일 사용 승인(nonce)을 기록할 프로젝트 원장을 확정할 수 없습니다 — 1회성을 보장할 수 없어 거부합니다(.ax 를 가진 프로젝트에 바인딩된 서버에서 호출하십시오)'
132
- : '단일 사용 승인(nonce)이 이미 소비되었습니다 — 재사용은 부재와 같이 거부됩니다'] };
154
+ : (0, approval_spend_1.spendRefusalReason)(spent)] };
133
155
  }
134
156
  }
135
157
  // Honest provenance: a confirm-level action that was NOT blocked but received no COVERING
@@ -44,7 +44,7 @@ export declare function createRuntimeBindingToolHandlers(context: RuntimeBinding
44
44
  ok: boolean;
45
45
  applied: boolean;
46
46
  operation: string;
47
- reason?: undefined;
47
+ readonly reason?: undefined;
48
48
  } | {
49
49
  planDigest: string;
50
50
  conflicts: string[];
@@ -55,7 +55,7 @@ export declare function createRuntimeBindingToolHandlers(context: RuntimeBinding
55
55
  }[];
56
56
  ok: boolean;
57
57
  applied: boolean;
58
- reason?: undefined;
58
+ readonly reason?: undefined;
59
59
  } | {
60
60
  planDigest: string;
61
61
  conflicts: string[];
@@ -59,7 +59,7 @@ export declare function createSliceOrchestrationHandlers(context: SliceOrchestra
59
59
  ok: boolean;
60
60
  specsCreated: string[];
61
61
  unreadable: string[];
62
- reason?: undefined;
62
+ readonly reason?: undefined;
63
63
  existing?: undefined;
64
64
  }>;
65
65
  spec_slice_approve(a: {
@@ -80,6 +80,11 @@ export declare function createSliceOrchestrationHandlers(context: SliceOrchestra
80
80
  targetFile?: string;
81
81
  aspecId?: string;
82
82
  }): Promise<{
83
+ diagnosis?: {
84
+ file: string;
85
+ aspecs: string[];
86
+ reason: string;
87
+ }[] | undefined;
83
88
  ok: boolean;
84
89
  actionsTaken: string[];
85
90
  refused: {
@@ -462,6 +462,19 @@ depends_on:
462
462
  }
463
463
  }
464
464
  }
465
+ // @implements A-SPEC-750.2 — an anchored test file that counts zero is diagnosed, not answered with "nothing to do"
466
+ let diagnosis;
467
+ if (a.aspecId) {
468
+ const family = (id) => id === a.aspecId || id.startsWith(`${a.aspecId}.`);
469
+ try {
470
+ diagnosis = require('../../rtm/test-scope').zeroCountDiagnostics(root).filter((d) => d.aspecs.some(family));
471
+ for (const d of diagnosis)
472
+ actionsTaken.push(`Diagnosed: ${d.file} counts no real cases for ${a.aspecId} (${d.reason}) — ART-4 reads this file as empty; fix the counted shape, do not unseal the spec`);
473
+ }
474
+ catch {
475
+ diagnosis = undefined;
476
+ }
477
+ }
465
478
  const rawHandlers = context.rawHandlersForStore(rawStore);
466
479
  const approveRes = await rawHandlers.spec_slice_approve({ root, sliceName: a.aspecId ?? 'slice' });
467
480
  if (approveRes.approvedSpecs?.length > 0) {
@@ -473,7 +486,7 @@ depends_on:
473
486
  const refused = approveRes.refused ?? [];
474
487
  for (const r of refused)
475
488
  actionsTaken.push(`Refused ${r.id}: ${r.reason}`);
476
- return { ok: refused.length === 0, actionsTaken, refused };
489
+ return { ok: refused.length === 0, actionsTaken, refused, ...(diagnosis ? { diagnosis } : {}) };
477
490
  },
478
491
  };
479
492
  }
@@ -72,18 +72,28 @@ export declare function createSpecApprovalHandlers(context: SpecApprovalContext)
72
72
  reason: string;
73
73
  blockers: string[];
74
74
  approvalIntent?: undefined;
75
+ code?: undefined;
75
76
  conflict?: undefined;
76
77
  } | {
77
78
  ok: boolean;
78
79
  reason: string;
79
80
  blockers?: undefined;
80
81
  approvalIntent?: undefined;
82
+ code?: undefined;
81
83
  conflict?: undefined;
82
84
  } | {
83
85
  ok: boolean;
84
86
  reason: string;
85
87
  approvalIntent: ApprovalIntent;
86
88
  blockers?: undefined;
89
+ code?: undefined;
90
+ conflict?: undefined;
91
+ } | {
92
+ ok: boolean;
93
+ code: string;
94
+ reason: string;
95
+ blockers?: undefined;
96
+ approvalIntent?: undefined;
87
97
  conflict?: undefined;
88
98
  } | {
89
99
  ok: boolean;
@@ -91,6 +101,7 @@ export declare function createSpecApprovalHandlers(context: SpecApprovalContext)
91
101
  conflict: import("../../spec/version-conflict").ConflictDetail;
92
102
  blockers?: undefined;
93
103
  approvalIntent?: undefined;
104
+ code?: undefined;
94
105
  } | {
95
106
  ancestorWarning?: string | undefined;
96
107
  scaffoldWarning?: string | undefined;
@@ -99,7 +110,7 @@ export declare function createSpecApprovalHandlers(context: SpecApprovalContext)
99
110
  advisoryIds?: Partial<Record<string, string>> | undefined;
100
111
  killsAdvisory?: import("../../review/kills-check").KillsAdvisory | undefined;
101
112
  fttFulfilment?: import("../../rtm/ftt-fulfilment").FttFulfilment | undefined;
102
- impactAdvisoryUnavailable?: "unreadable" | "empty" | undefined;
113
+ impactAdvisoryUnavailable?: "empty" | "unreadable" | undefined;
103
114
  impactGraph?: {
104
115
  status: "current" | "stale" | "unverified";
105
116
  sourceCommit: string | null;
@@ -111,9 +122,10 @@ export declare function createSpecApprovalHandlers(context: SpecApprovalContext)
111
122
  approved: string;
112
123
  digest: string;
113
124
  ok?: undefined;
114
- reason?: undefined;
125
+ readonly reason?: undefined;
115
126
  blockers?: undefined;
116
127
  approvalIntent?: undefined;
128
+ code?: undefined;
117
129
  conflict?: undefined;
118
130
  }>;
119
131
  /**
@@ -144,7 +156,7 @@ export declare function createSpecApprovalHandlers(context: SpecApprovalContext)
144
156
  pinned: string[];
145
157
  findings: import("../../spec/validator").Finding[];
146
158
  citations: unknown[];
147
- reason?: undefined;
159
+ readonly reason?: undefined;
148
160
  }>;
149
161
  };
150
162
  /**