open-multi-agent-kit 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +2 -2
  3. package/dist/approval-api.d.ts +5 -0
  4. package/dist/approval-api.d.ts.map +1 -0
  5. package/dist/approval-api.js +5 -0
  6. package/dist/approval-api.js.map +1 -0
  7. package/dist/cli/session-picker.d.ts +2 -2
  8. package/dist/cli/session-picker.d.ts.map +1 -1
  9. package/dist/cli/session-picker.js.map +1 -1
  10. package/dist/commands/verified-run-cli.d.ts.map +1 -1
  11. package/dist/commands/verified-run-cli.js +69 -22
  12. package/dist/commands/verified-run-cli.js.map +1 -1
  13. package/dist/commands/verified-run-signal.d.ts +3 -0
  14. package/dist/commands/verified-run-signal.d.ts.map +1 -0
  15. package/dist/commands/verified-run-signal.js +15 -0
  16. package/dist/commands/verified-run-signal.js.map +1 -0
  17. package/dist/coordination/broker.d.ts.map +1 -1
  18. package/dist/coordination/broker.js +13 -6
  19. package/dist/coordination/broker.js.map +1 -1
  20. package/dist/coordination/operation.d.ts +1 -0
  21. package/dist/coordination/operation.d.ts.map +1 -1
  22. package/dist/coordination/operation.js +55 -3
  23. package/dist/coordination/operation.js.map +1 -1
  24. package/dist/coordination/resource.d.ts +1 -1
  25. package/dist/coordination/resource.d.ts.map +1 -1
  26. package/dist/coordination/resource.js +10 -4
  27. package/dist/coordination/resource.js.map +1 -1
  28. package/dist/coordination/types.d.ts.map +1 -1
  29. package/dist/coordination/types.js +1 -1
  30. package/dist/coordination/types.js.map +1 -1
  31. package/dist/core/adaptorch-bridge.d.ts +1 -1
  32. package/dist/core/adaptorch-bridge.d.ts.map +1 -1
  33. package/dist/core/adaptorch-bridge.js +1 -1
  34. package/dist/core/adaptorch-bridge.js.map +1 -1
  35. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  36. package/dist/core/agent-session-runtime.js +16 -16
  37. package/dist/core/agent-session-runtime.js.map +1 -1
  38. package/dist/core/agent-session.d.ts.map +1 -1
  39. package/dist/core/agent-session.js +32 -33
  40. package/dist/core/agent-session.js.map +1 -1
  41. package/dist/core/canonical-json.d.ts +3 -0
  42. package/dist/core/canonical-json.d.ts.map +1 -0
  43. package/dist/core/canonical-json.js +20 -0
  44. package/dist/core/canonical-json.js.map +1 -0
  45. package/dist/core/compaction/compaction.d.ts +7 -3
  46. package/dist/core/compaction/compaction.d.ts.map +1 -1
  47. package/dist/core/compaction/compaction.js +14 -29
  48. package/dist/core/compaction/compaction.js.map +1 -1
  49. package/dist/core/compaction/fallback.d.ts +16 -5
  50. package/dist/core/compaction/fallback.d.ts.map +1 -1
  51. package/dist/core/compaction/fallback.js +4 -3
  52. package/dist/core/compaction/fallback.js.map +1 -1
  53. package/dist/core/compaction/model-failover.d.ts +21 -0
  54. package/dist/core/compaction/model-failover.d.ts.map +1 -0
  55. package/dist/core/compaction/model-failover.js +46 -0
  56. package/dist/core/compaction/model-failover.js.map +1 -0
  57. package/dist/core/compaction/session-summary.d.ts +21 -0
  58. package/dist/core/compaction/session-summary.d.ts.map +1 -0
  59. package/dist/core/compaction/session-summary.js +27 -0
  60. package/dist/core/compaction/session-summary.js.map +1 -0
  61. package/dist/core/export-html/template.js +14 -0
  62. package/dist/core/extensions/index.d.ts +1 -1
  63. package/dist/core/extensions/index.d.ts.map +1 -1
  64. package/dist/core/extensions/index.js.map +1 -1
  65. package/dist/core/extensions/session-lifecycle-types.d.ts +14 -0
  66. package/dist/core/extensions/session-lifecycle-types.d.ts.map +1 -0
  67. package/dist/core/extensions/session-lifecycle-types.js +2 -0
  68. package/dist/core/extensions/session-lifecycle-types.js.map +1 -0
  69. package/dist/core/extensions/types.d.ts +4 -9
  70. package/dist/core/extensions/types.d.ts.map +1 -1
  71. package/dist/core/extensions/types.js.map +1 -1
  72. package/dist/core/http-dispatcher.d.ts.map +1 -1
  73. package/dist/core/http-dispatcher.js +10 -1
  74. package/dist/core/http-dispatcher.js.map +1 -1
  75. package/dist/core/keybindings.d.ts.map +1 -1
  76. package/dist/core/keybindings.js +3 -6
  77. package/dist/core/keybindings.js.map +1 -1
  78. package/dist/core/legacy-resource-policy.d.ts +7 -0
  79. package/dist/core/legacy-resource-policy.d.ts.map +1 -0
  80. package/dist/core/legacy-resource-policy.js +9 -0
  81. package/dist/core/legacy-resource-policy.js.map +1 -0
  82. package/dist/core/mcp/config.d.ts.map +1 -1
  83. package/dist/core/mcp/config.js +17 -3
  84. package/dist/core/mcp/config.js.map +1 -1
  85. package/dist/core/mcp/connection-queue.d.ts +12 -0
  86. package/dist/core/mcp/connection-queue.d.ts.map +1 -0
  87. package/dist/core/mcp/connection-queue.js +46 -0
  88. package/dist/core/mcp/connection-queue.js.map +1 -0
  89. package/dist/core/mcp/manager-runtime.d.ts +55 -0
  90. package/dist/core/mcp/manager-runtime.d.ts.map +1 -0
  91. package/dist/core/mcp/manager-runtime.js +66 -0
  92. package/dist/core/mcp/manager-runtime.js.map +1 -0
  93. package/dist/core/mcp/manager.d.ts +12 -68
  94. package/dist/core/mcp/manager.d.ts.map +1 -1
  95. package/dist/core/mcp/manager.js +33 -113
  96. package/dist/core/mcp/manager.js.map +1 -1
  97. package/dist/core/mcp/protocol.d.ts.map +1 -1
  98. package/dist/core/mcp/protocol.js +70 -40
  99. package/dist/core/mcp/protocol.js.map +1 -1
  100. package/dist/core/package-manager.d.ts +4 -0
  101. package/dist/core/package-manager.d.ts.map +1 -1
  102. package/dist/core/package-manager.js +59 -129
  103. package/dist/core/package-manager.js.map +1 -1
  104. package/dist/core/package-resource-patterns.d.ts +7 -0
  105. package/dist/core/package-resource-patterns.d.ts.map +1 -0
  106. package/dist/core/package-resource-patterns.js +99 -0
  107. package/dist/core/package-resource-patterns.js.map +1 -0
  108. package/dist/core/provider-resilience.d.ts +9 -0
  109. package/dist/core/provider-resilience.d.ts.map +1 -1
  110. package/dist/core/provider-resilience.js +15 -0
  111. package/dist/core/provider-resilience.js.map +1 -1
  112. package/dist/core/reasoning-router-v4.d.ts +5 -2
  113. package/dist/core/reasoning-router-v4.d.ts.map +1 -1
  114. package/dist/core/reasoning-router-v4.js.map +1 -1
  115. package/dist/core/resource-loader.d.ts.map +1 -1
  116. package/dist/core/resource-loader.js +4 -8
  117. package/dist/core/resource-loader.js.map +1 -1
  118. package/dist/core/run-execution-api.d.ts +8 -1
  119. package/dist/core/run-execution-api.d.ts.map +1 -1
  120. package/dist/core/run-execution-api.js +4 -0
  121. package/dist/core/run-execution-api.js.map +1 -1
  122. package/dist/core/run-journal.d.ts +1 -2
  123. package/dist/core/run-journal.d.ts.map +1 -1
  124. package/dist/core/run-journal.js +2 -19
  125. package/dist/core/run-journal.js.map +1 -1
  126. package/dist/core/session-listing.d.ts +51 -0
  127. package/dist/core/session-listing.d.ts.map +1 -0
  128. package/dist/core/session-listing.js +111 -0
  129. package/dist/core/session-listing.js.map +1 -0
  130. package/dist/core/session-manager.d.ts +12 -37
  131. package/dist/core/session-manager.d.ts.map +1 -1
  132. package/dist/core/session-manager.js +12 -118
  133. package/dist/core/session-manager.js.map +1 -1
  134. package/dist/core/session-message-text.d.ts +5 -0
  135. package/dist/core/session-message-text.d.ts.map +1 -0
  136. package/dist/core/session-message-text.js +9 -0
  137. package/dist/core/session-message-text.js.map +1 -0
  138. package/dist/core/skills-catalog-cache.d.ts +2 -0
  139. package/dist/core/skills-catalog-cache.d.ts.map +1 -1
  140. package/dist/core/skills-catalog-cache.js +71 -17
  141. package/dist/core/skills-catalog-cache.js.map +1 -1
  142. package/dist/core/tools/read.d.ts.map +1 -1
  143. package/dist/core/tools/read.js +1 -1
  144. package/dist/core/tools/read.js.map +1 -1
  145. package/dist/core/verified-run/authority-clock.d.ts +3 -0
  146. package/dist/core/verified-run/authority-clock.d.ts.map +1 -0
  147. package/dist/core/verified-run/authority-clock.js +25 -0
  148. package/dist/core/verified-run/authority-clock.js.map +1 -0
  149. package/dist/core/verified-run/authority-errors.d.ts +10 -0
  150. package/dist/core/verified-run/authority-errors.d.ts.map +1 -0
  151. package/dist/core/verified-run/authority-errors.js +17 -0
  152. package/dist/core/verified-run/authority-errors.js.map +1 -0
  153. package/dist/core/verified-run/authority-events.d.ts +126 -0
  154. package/dist/core/verified-run/authority-events.d.ts.map +1 -0
  155. package/dist/core/verified-run/authority-events.js +482 -0
  156. package/dist/core/verified-run/authority-events.js.map +1 -0
  157. package/dist/core/verified-run/authority-journal.d.ts +27 -0
  158. package/dist/core/verified-run/authority-journal.d.ts.map +1 -0
  159. package/dist/core/verified-run/authority-journal.js +83 -0
  160. package/dist/core/verified-run/authority-journal.js.map +1 -0
  161. package/dist/core/verified-run/authority-meaning.d.ts +13 -0
  162. package/dist/core/verified-run/authority-meaning.d.ts.map +1 -0
  163. package/dist/core/verified-run/authority-meaning.js +40 -0
  164. package/dist/core/verified-run/authority-meaning.js.map +1 -0
  165. package/dist/core/verified-run/authority-runtime.d.ts +82 -0
  166. package/dist/core/verified-run/authority-runtime.d.ts.map +1 -0
  167. package/dist/core/verified-run/authority-runtime.js +169 -0
  168. package/dist/core/verified-run/authority-runtime.js.map +1 -0
  169. package/dist/core/verified-run/authority-store.d.ts +204 -0
  170. package/dist/core/verified-run/authority-store.d.ts.map +1 -0
  171. package/dist/core/verified-run/authority-store.js +852 -0
  172. package/dist/core/verified-run/authority-store.js.map +1 -0
  173. package/dist/core/verified-run/broker.d.ts +8 -1
  174. package/dist/core/verified-run/broker.d.ts.map +1 -1
  175. package/dist/core/verified-run/broker.js +94 -90
  176. package/dist/core/verified-run/broker.js.map +1 -1
  177. package/dist/core/verified-run/candidate-policy.d.ts +10 -0
  178. package/dist/core/verified-run/candidate-policy.d.ts.map +1 -0
  179. package/dist/core/verified-run/candidate-policy.js +33 -0
  180. package/dist/core/verified-run/candidate-policy.js.map +1 -0
  181. package/dist/core/verified-run/candidate.d.ts.map +1 -1
  182. package/dist/core/verified-run/candidate.js +5 -10
  183. package/dist/core/verified-run/candidate.js.map +1 -1
  184. package/dist/core/verified-run/coordinator.d.ts +35 -17
  185. package/dist/core/verified-run/coordinator.d.ts.map +1 -1
  186. package/dist/core/verified-run/coordinator.js +111 -57
  187. package/dist/core/verified-run/coordinator.js.map +1 -1
  188. package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
  189. package/dist/core/verified-run/dag-phase.js +1 -1
  190. package/dist/core/verified-run/dag-phase.js.map +1 -1
  191. package/dist/core/verified-run/dag-recovery.d.ts +5 -1
  192. package/dist/core/verified-run/dag-recovery.d.ts.map +1 -1
  193. package/dist/core/verified-run/dag-recovery.js +10 -4
  194. package/dist/core/verified-run/dag-recovery.js.map +1 -1
  195. package/dist/core/verified-run/event-parser.d.ts.map +1 -1
  196. package/dist/core/verified-run/event-parser.js +33 -0
  197. package/dist/core/verified-run/event-parser.js.map +1 -1
  198. package/dist/core/verified-run/evidence-read-projection.d.ts +4 -0
  199. package/dist/core/verified-run/evidence-read-projection.d.ts.map +1 -0
  200. package/dist/core/verified-run/evidence-read-projection.js +27 -0
  201. package/dist/core/verified-run/evidence-read-projection.js.map +1 -0
  202. package/dist/core/verified-run/evidence.d.ts +12 -1
  203. package/dist/core/verified-run/evidence.d.ts.map +1 -1
  204. package/dist/core/verified-run/evidence.js +51 -2
  205. package/dist/core/verified-run/evidence.js.map +1 -1
  206. package/dist/core/verified-run/git-candidate-preflight.d.ts +4 -0
  207. package/dist/core/verified-run/git-candidate-preflight.d.ts.map +1 -0
  208. package/dist/core/verified-run/git-candidate-preflight.js +34 -0
  209. package/dist/core/verified-run/git-candidate-preflight.js.map +1 -0
  210. package/dist/core/verified-run/git-effect-supervisor.d.ts +24 -0
  211. package/dist/core/verified-run/git-effect-supervisor.d.ts.map +1 -0
  212. package/dist/core/verified-run/git-effect-supervisor.js +174 -0
  213. package/dist/core/verified-run/git-effect-supervisor.js.map +1 -0
  214. package/dist/core/verified-run/git-execution.d.ts +27 -0
  215. package/dist/core/verified-run/git-execution.d.ts.map +1 -0
  216. package/dist/core/verified-run/git-execution.js +118 -0
  217. package/dist/core/verified-run/git-execution.js.map +1 -0
  218. package/dist/core/verified-run/git-plumbing.d.ts +37 -0
  219. package/dist/core/verified-run/git-plumbing.d.ts.map +1 -0
  220. package/dist/core/verified-run/git-plumbing.js +171 -0
  221. package/dist/core/verified-run/git-plumbing.js.map +1 -0
  222. package/dist/core/verified-run/git-publication-worker.d.ts +2 -0
  223. package/dist/core/verified-run/git-publication-worker.d.ts.map +1 -0
  224. package/dist/core/verified-run/git-publication-worker.js +54 -0
  225. package/dist/core/verified-run/git-publication-worker.js.map +1 -0
  226. package/dist/core/verified-run/git-sandbox-layout.d.ts +4 -0
  227. package/dist/core/verified-run/git-sandbox-layout.d.ts.map +1 -0
  228. package/dist/core/verified-run/git-sandbox-layout.js +29 -0
  229. package/dist/core/verified-run/git-sandbox-layout.js.map +1 -0
  230. package/dist/core/verified-run/git-worker-protocol.d.ts +19 -0
  231. package/dist/core/verified-run/git-worker-protocol.d.ts.map +1 -0
  232. package/dist/core/verified-run/git-worker-protocol.js +109 -0
  233. package/dist/core/verified-run/git-worker-protocol.js.map +1 -0
  234. package/dist/core/verified-run/git-worker-runtime.d.ts +19 -0
  235. package/dist/core/verified-run/git-worker-runtime.d.ts.map +1 -0
  236. package/dist/core/verified-run/git-worker-runtime.js +74 -0
  237. package/dist/core/verified-run/git-worker-runtime.js.map +1 -0
  238. package/dist/core/verified-run/journal.d.ts +2 -3
  239. package/dist/core/verified-run/journal.d.ts.map +1 -1
  240. package/dist/core/verified-run/journal.js.map +1 -1
  241. package/dist/core/verified-run/namespace-identity.d.ts.map +1 -1
  242. package/dist/core/verified-run/namespace-identity.js +1 -1
  243. package/dist/core/verified-run/namespace-identity.js.map +1 -1
  244. package/dist/core/verified-run/owned-execution.d.ts +10 -1
  245. package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
  246. package/dist/core/verified-run/owned-execution.js +124 -31
  247. package/dist/core/verified-run/owned-execution.js.map +1 -1
  248. package/dist/core/verified-run/phase-context.d.ts +2 -0
  249. package/dist/core/verified-run/phase-context.d.ts.map +1 -1
  250. package/dist/core/verified-run/phase-context.js.map +1 -1
  251. package/dist/core/verified-run/projection.d.ts.map +1 -1
  252. package/dist/core/verified-run/projection.js +51 -1
  253. package/dist/core/verified-run/projection.js.map +1 -1
  254. package/dist/core/verified-run/publish-preflight.d.ts +12 -0
  255. package/dist/core/verified-run/publish-preflight.d.ts.map +1 -0
  256. package/dist/core/verified-run/publish-preflight.js +38 -0
  257. package/dist/core/verified-run/publish-preflight.js.map +1 -0
  258. package/dist/core/verified-run/publish-start.d.ts +5 -0
  259. package/dist/core/verified-run/publish-start.d.ts.map +1 -0
  260. package/dist/core/verified-run/publish-start.js +7 -0
  261. package/dist/core/verified-run/publish-start.js.map +1 -0
  262. package/dist/core/verified-run/recovery-projection.d.ts.map +1 -1
  263. package/dist/core/verified-run/recovery-projection.js +5 -0
  264. package/dist/core/verified-run/recovery-projection.js.map +1 -1
  265. package/dist/core/verified-run/recovery.d.ts +5 -1
  266. package/dist/core/verified-run/recovery.d.ts.map +1 -1
  267. package/dist/core/verified-run/recovery.js +10 -4
  268. package/dist/core/verified-run/recovery.js.map +1 -1
  269. package/dist/core/verified-run/run-plan.d.ts +17 -0
  270. package/dist/core/verified-run/run-plan.d.ts.map +1 -0
  271. package/dist/core/verified-run/run-plan.js +18 -0
  272. package/dist/core/verified-run/run-plan.js.map +1 -0
  273. package/dist/core/verified-run/run-publish-owned.d.ts +6 -0
  274. package/dist/core/verified-run/run-publish-owned.d.ts.map +1 -0
  275. package/dist/core/verified-run/run-publish-owned.js +199 -0
  276. package/dist/core/verified-run/run-publish-owned.js.map +1 -0
  277. package/dist/core/verified-run/run-publish.d.ts +19 -0
  278. package/dist/core/verified-run/run-publish.d.ts.map +1 -0
  279. package/dist/core/verified-run/run-publish.js +210 -0
  280. package/dist/core/verified-run/run-publish.js.map +1 -0
  281. package/dist/core/verified-run/run-status-owned.d.ts +4 -0
  282. package/dist/core/verified-run/run-status-owned.d.ts.map +1 -0
  283. package/dist/core/verified-run/run-status-owned.js +14 -0
  284. package/dist/core/verified-run/run-status-owned.js.map +1 -0
  285. package/dist/core/verified-run/run-status.d.ts +133 -0
  286. package/dist/core/verified-run/run-status.d.ts.map +1 -0
  287. package/dist/core/verified-run/run-status.js +193 -0
  288. package/dist/core/verified-run/run-status.js.map +1 -0
  289. package/dist/core/verified-run/run-types.d.ts +31 -0
  290. package/dist/core/verified-run/run-types.d.ts.map +1 -1
  291. package/dist/core/verified-run/run-types.js.map +1 -1
  292. package/dist/core/verified-run/storage.d.ts.map +1 -1
  293. package/dist/core/verified-run/storage.js +1 -1
  294. package/dist/core/verified-run/storage.js.map +1 -1
  295. package/dist/core/verified-run/supervisor-adapter.d.ts +77 -0
  296. package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
  297. package/dist/core/verified-run/supervisor-adapter.js +164 -0
  298. package/dist/core/verified-run/supervisor-adapter.js.map +1 -0
  299. package/dist/core/verified-run/verification-phase.d.ts.map +1 -1
  300. package/dist/core/verified-run/verification-phase.js +1 -1
  301. package/dist/core/verified-run/verification-phase.js.map +1 -1
  302. package/dist/core/verified-run/writer-phase.d.ts.map +1 -1
  303. package/dist/core/verified-run/writer-phase.js +1 -0
  304. package/dist/core/verified-run/writer-phase.js.map +1 -1
  305. package/dist/core/verified-run/writer-recovery.d.ts +2 -0
  306. package/dist/core/verified-run/writer-recovery.d.ts.map +1 -1
  307. package/dist/core/verified-run/writer-recovery.js +1 -0
  308. package/dist/core/verified-run/writer-recovery.js.map +1 -1
  309. package/dist/core/workload-shard-execution-types.d.ts +4 -1
  310. package/dist/core/workload-shard-execution-types.d.ts.map +1 -1
  311. package/dist/core/workload-shard-execution-types.js.map +1 -1
  312. package/dist/core/workload-shard-executor.d.ts +2 -2
  313. package/dist/core/workload-shard-executor.d.ts.map +1 -1
  314. package/dist/core/workload-shard-executor.js +16 -37
  315. package/dist/core/workload-shard-executor.js.map +1 -1
  316. package/dist/core/workload-shard-frontier.d.ts +5 -0
  317. package/dist/core/workload-shard-frontier.d.ts.map +1 -0
  318. package/dist/core/workload-shard-frontier.js +47 -0
  319. package/dist/core/workload-shard-frontier.js.map +1 -0
  320. package/dist/core/workload-shard-runner.d.ts.map +1 -1
  321. package/dist/core/workload-shard-runner.js +28 -17
  322. package/dist/core/workload-shard-runner.js.map +1 -1
  323. package/dist/index.d.ts +2 -5
  324. package/dist/index.d.ts.map +1 -1
  325. package/dist/index.js +1 -4
  326. package/dist/index.js.map +1 -1
  327. package/dist/main.d.ts.map +1 -1
  328. package/dist/main.js +2 -1
  329. package/dist/main.js.map +1 -1
  330. package/dist/metacognition/bridge-result.d.ts +148 -0
  331. package/dist/metacognition/bridge-result.d.ts.map +1 -0
  332. package/dist/metacognition/bridge-result.js +46 -0
  333. package/dist/metacognition/bridge-result.js.map +1 -0
  334. package/dist/metacognition/calibration-selective.d.ts.map +1 -1
  335. package/dist/metacognition/calibration-selective.js +8 -2
  336. package/dist/metacognition/calibration-selective.js.map +1 -1
  337. package/dist/metacognition/index.d.ts +1 -0
  338. package/dist/metacognition/index.d.ts.map +1 -1
  339. package/dist/metacognition/index.js +1 -0
  340. package/dist/metacognition/index.js.map +1 -1
  341. package/dist/metacognition/risk.d.ts.map +1 -1
  342. package/dist/metacognition/risk.js +28 -14
  343. package/dist/metacognition/risk.js.map +1 -1
  344. package/dist/metacognition/runtime-bridge.d.ts +41 -14
  345. package/dist/metacognition/runtime-bridge.d.ts.map +1 -1
  346. package/dist/metacognition/runtime-bridge.js +357 -39
  347. package/dist/metacognition/runtime-bridge.js.map +1 -1
  348. package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
  349. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/assistant-message.js +42 -26
  351. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  352. package/dist/modes/interactive/components/chat-container.d.ts +7 -0
  353. package/dist/modes/interactive/components/chat-container.d.ts.map +1 -0
  354. package/dist/modes/interactive/components/chat-container.js +14 -0
  355. package/dist/modes/interactive/components/chat-container.js.map +1 -0
  356. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  357. package/dist/modes/interactive/components/dynamic-border.js +4 -2
  358. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  359. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  360. package/dist/modes/interactive/components/login-dialog.js +0 -1
  361. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  362. package/dist/modes/interactive/components/session-selector-async-search.d.ts +33 -0
  363. package/dist/modes/interactive/components/session-selector-async-search.d.ts.map +1 -0
  364. package/dist/modes/interactive/components/session-selector-async-search.js +109 -0
  365. package/dist/modes/interactive/components/session-selector-async-search.js.map +1 -0
  366. package/dist/modes/interactive/components/session-selector-loaders.d.ts +6 -0
  367. package/dist/modes/interactive/components/session-selector-loaders.d.ts.map +1 -0
  368. package/dist/modes/interactive/components/session-selector-loaders.js +9 -0
  369. package/dist/modes/interactive/components/session-selector-loaders.js.map +1 -0
  370. package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
  371. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  372. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  373. package/dist/modes/interactive/components/session-selector-tree.d.ts +16 -0
  374. package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
  375. package/dist/modes/interactive/components/session-selector-tree.js +46 -0
  376. package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
  377. package/dist/modes/interactive/components/session-selector.d.ts +6 -1
  378. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  379. package/dist/modes/interactive/components/session-selector.js +36 -76
  380. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  381. package/dist/modes/interactive/components/tool-execution-images.d.ts +32 -0
  382. package/dist/modes/interactive/components/tool-execution-images.d.ts.map +1 -0
  383. package/dist/modes/interactive/components/tool-execution-images.js +144 -0
  384. package/dist/modes/interactive/components/tool-execution-images.js.map +1 -0
  385. package/dist/modes/interactive/components/tool-execution.d.ts +3 -4
  386. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  387. package/dist/modes/interactive/components/tool-execution.js +22 -71
  388. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  389. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  390. package/dist/modes/interactive/interactive-mode.js +7 -9
  391. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  392. package/dist/modes/interactive/tui-diagnostics.d.ts +8 -4
  393. package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -1
  394. package/dist/modes/interactive/tui-diagnostics.js +35 -1
  395. package/dist/modes/interactive/tui-diagnostics.js.map +1 -1
  396. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  397. package/dist/modes/rpc/rpc-mode.js +14 -17
  398. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  399. package/dist/modes/rpc/rpc-response.d.ts +5 -0
  400. package/dist/modes/rpc/rpc-response.d.ts.map +1 -0
  401. package/dist/modes/rpc/rpc-response.js +17 -0
  402. package/dist/modes/rpc/rpc-response.js.map +1 -0
  403. package/dist/utils/exif-orientation.d.ts.map +1 -1
  404. package/dist/utils/exif-orientation.js +2 -3
  405. package/dist/utils/exif-orientation.js.map +1 -1
  406. package/dist/utils/tools-manager.d.ts.map +1 -1
  407. package/dist/utils/tools-manager.js +3 -5
  408. package/dist/utils/tools-manager.js.map +1 -1
  409. package/docs/adaptorch-preview-spec.md +7 -7
  410. package/docs/atomic-commit-planning.md +69 -0
  411. package/docs/compaction.md +26 -1
  412. package/docs/extensions.md +14 -0
  413. package/docs/mcp.md +22 -0
  414. package/docs/metacognition.md +79 -0
  415. package/docs/model-catalog-refresh.md +159 -1
  416. package/docs/models.md +1 -1
  417. package/docs/runtime-algorithms.md +49 -4
  418. package/docs/session-format.md +8 -0
  419. package/docs/sessions.md +19 -0
  420. package/docs/skills.md +19 -0
  421. package/docs/terminal-setup.md +15 -0
  422. package/docs/tui.md +41 -0
  423. package/docs/verified-run-safety.md +75 -0
  424. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  425. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  426. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  427. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  428. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  429. package/examples/extensions/gondolin/package-lock.json +2 -2
  430. package/examples/extensions/gondolin/package.json +1 -1
  431. package/examples/extensions/sandbox/package-lock.json +2 -2
  432. package/examples/extensions/sandbox/package.json +1 -1
  433. package/examples/extensions/with-deps/package-lock.json +2 -2
  434. package/examples/extensions/with-deps/package.json +1 -1
  435. package/npm-shrinkwrap.json +18 -18
  436. package/package.json +6 -8
@@ -1,46 +1,139 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { realpathSync } from "node:fs";
2
3
  import { performance } from "node:perf_hooks";
3
4
  import { executeSandbox } from "./broker.js";
4
- import { VerifiedRunError } from "./storage.js";
5
- /** The mandatory durable intent boundary is shared by command and AgentSession writers. */
5
+ import { digestObject, VerifiedRunError } from "./storage.js";
6
+ /**
7
+ * The filesystem claim a dispatched process is authorized for: exactly the
8
+ * workspace bind it receives inside the namespace — nothing wider. Keys are
9
+ * the resolved absolute path minus the leading slash so prefix containment
10
+ * matches real tree containment; `realpathSync` keeps two spellings of the
11
+ * same directory one claim.
12
+ */
13
+ function workspaceClaim(workspace, access, generation) {
14
+ let root;
15
+ try {
16
+ root = realpathSync(workspace);
17
+ }
18
+ catch {
19
+ throw new VerifiedRunError("authority_claim");
20
+ }
21
+ return Object.freeze([
22
+ {
23
+ namespace: "filesystem",
24
+ instanceId: "verified-run",
25
+ canonicalKey: root.replace(/^\/+/, ""),
26
+ access,
27
+ generation: String(generation),
28
+ },
29
+ ]);
30
+ }
31
+ /** Rejection codes that can only be produced before the supervisor spawned. */
32
+ const NEVER_SPAWNED = new Set(["cancelled", "deadline", "unsupported_boundary"]);
33
+ /**
34
+ * Mandatory durable dispatch intent, shared by command and AgentSession
35
+ * writers. There is no ungated execution lane: a journal without an anchored
36
+ * budget cannot commit a process identity, so the supervisor boundary would
37
+ * be unprovable and must refuse dispatch. Every dispatch now also crosses the
38
+ * durable authority boundary — grant → intent → start → termination witness
39
+ * — so a restart can reconcile effects the journal alone cannot settle.
40
+ */
6
41
  export async function executeRunCommand(journal, request, policy) {
7
42
  if (Math.floor(request.deadline - performance.now()) <= 0)
8
43
  throw new VerifiedRunError("deadline");
9
44
  if (policy.signal?.aborted)
10
45
  throw new VerifiedRunError("cancelled");
46
+ // The supervisor boundary only exists once a budget (and therefore the
47
+ // gated driver) is anchored. Dispatching without it would run code whose
48
+ // termination cannot be witnessed — refuse rather than degrade.
49
+ if (!journal.state.budget)
50
+ throw new VerifiedRunError("unsupported_boundary");
51
+ const authority = policy.authority;
11
52
  const generation = journal.state.generation;
12
53
  const executionId = randomUUID();
13
- journal.append({
14
- kind: "dispatch",
15
- executionId,
16
- role: request.role,
17
- claimId: request.claimId,
18
- ...(request.taskId === undefined ? {} : { taskId: request.taskId }),
19
- });
54
+ const claims = workspaceClaim(request.workspace, request.role === "writer" ? "write" : "read", generation);
20
55
  const timeoutMs = Math.floor(request.deadline - performance.now());
21
- if (timeoutMs <= 0 || policy.signal?.aborted) {
22
- const failure = policy.signal?.aborted ? "cancelled" : "deadline";
23
- journal.append({ kind: "exited", executionId, failure });
24
- throw new VerifiedRunError(failure);
25
- }
26
- const result = await executeSandbox({
27
- workspace: request.workspace,
28
- argv: request.argv,
29
- writable: request.role === "writer",
30
- timeoutMs,
31
- cleanupMs: policy.cleanupMs,
32
- maxOutputBytes: policy.maxOutputBytes,
33
- ...(policy.signal ? { signal: policy.signal } : {}),
34
- ...(journal.state.budget
35
- ? {
36
- onReady: (identity) => {
37
- if (journal.state.generation !== generation)
38
- throw new VerifiedRunError("stale_generation");
39
- journal.append({ kind: "process_ready", executionId, identity });
40
- },
41
- }
42
- : {}),
56
+ const admission = authority.store.acquire({
57
+ sessionId: authority.sessionId,
58
+ incarnation: authority.incarnation,
59
+ commandId: executionId,
60
+ intentDigest: digestObject({ argv: request.argv, claims, role: request.role }),
61
+ claims,
62
+ now: Date.now(),
63
+ ttl: timeoutMs + policy.cleanupMs + 30000,
43
64
  });
65
+ if (admission.status !== "granted") {
66
+ // A fresh executionId can only collide with a conflicting or wedged
67
+ // claim — quarantined effects hold theirs until witnessed (fail closed).
68
+ throw new VerifiedRunError("authority_blocked");
69
+ }
70
+ const token = admission.token;
71
+ let supervisorInvoked = false;
72
+ let readyObserved = false;
73
+ let result;
74
+ try {
75
+ journal.append({
76
+ kind: "dispatch",
77
+ executionId,
78
+ role: request.role,
79
+ claimId: request.claimId,
80
+ ...(request.taskId === undefined ? {} : { taskId: request.taskId }),
81
+ });
82
+ if (timeoutMs <= 0 || policy.signal?.aborted) {
83
+ const failure = policy.signal?.aborted ? "cancelled" : "deadline";
84
+ // Provably pre-spawn: the intent never reached the adapter, so the grant
85
+ // settles immediately instead of wedging as an unwitnessed live effect.
86
+ authority.store.cancel(token);
87
+ authority.store.confirmTerminated(token);
88
+ journal.append({ kind: "exited", executionId, failure });
89
+ throw new VerifiedRunError(failure);
90
+ }
91
+ // The intent commits before the adapter is invoked: from this record on,
92
+ // the effect may be live and a crash must quarantine it, never assume
93
+ // it did not run.
94
+ if (!authority.store.dispatchIntent(token, executionId))
95
+ throw new VerifiedRunError("authority");
96
+ supervisorInvoked = true;
97
+ result = await executeSandbox({
98
+ workspace: request.workspace,
99
+ argv: request.argv,
100
+ writable: request.role === "writer",
101
+ timeoutMs: Math.floor(request.deadline - performance.now()),
102
+ cleanupMs: policy.cleanupMs,
103
+ maxOutputBytes: policy.maxOutputBytes,
104
+ ...(policy.signal ? { signal: policy.signal } : {}),
105
+ onReady: (identity) => {
106
+ readyObserved = true;
107
+ if (journal.state.generation !== generation)
108
+ throw new VerifiedRunError("stale_generation");
109
+ journal.append({ kind: "process_ready", executionId, identity });
110
+ if (!authority.store.effectStarted(token, claims, identity))
111
+ throw new VerifiedRunError("authority");
112
+ },
113
+ });
114
+ }
115
+ catch (error) {
116
+ // Only pre-spawn rejections prove nothing ran; everything else may have
117
+ // a live or dying effect, which stays owned until a witness or a later
118
+ // reconcile settles it.
119
+ try {
120
+ authority.store.cancel(token);
121
+ if (!supervisorInvoked ||
122
+ (!readyObserved && error instanceof VerifiedRunError && NEVER_SPAWNED.has(error.code)))
123
+ authority.store.confirmTerminated(token);
124
+ }
125
+ catch (cleanupError) {
126
+ throw new AggregateError([error, cleanupError], "Execution ownership cleanup failed");
127
+ }
128
+ throw error;
129
+ }
130
+ if (result.failure === "cancelled")
131
+ authority.store.cancel(token);
132
+ // Resolve means both witnesses fired: the direct child closed and the
133
+ // recorded namespace drained empty. That is the termination-observed event
134
+ // — the grant releases its claims here and nowhere else.
135
+ if (!authority.store.confirmTerminated(token))
136
+ throw new VerifiedRunError("authority");
44
137
  if (journal.state.generation !== generation)
45
138
  throw new VerifiedRunError("stale_generation");
46
139
  journal.append({ kind: "exited", executionId, failure: request.role === "writer" ? result.failure : null });
@@ -1 +1 @@
1
- {"version":3,"file":"owned-execution.js","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgBhD,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,OAA2B,EAC3B,OAAwB,EACxB,MAIC,EACyB;IAC1B,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,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AM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM;YACvB,CAAC,CAAC;gBACA,OAAO,EAAE,CAAC,QAA2B,EAAE,EAAE,CAAC;oBACzC,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU;wBAAE,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;oBAC5F,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAAA,CACjE;aACD;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC,CAAC;IACH,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU;QAAE,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IAC5F,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,CAC1C","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n\treadonly taskId?: string;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/** The mandatory durable intent boundary is shared by command and AgentSession writers. */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tjournal.append({\n\t\tkind: \"dispatch\",\n\t\texecutionId,\n\t\trole: request.role,\n\t\tclaimId: request.claimId,\n\t\t...(request.taskId === undefined ? {} : { taskId: request.taskId }),\n\t});\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\tthrow new VerifiedRunError(failure);\n\t}\n\tconst result = await executeSandbox({\n\t\tworkspace: request.workspace,\n\t\targv: request.argv,\n\t\twritable: request.role === \"writer\",\n\t\ttimeoutMs,\n\t\tcleanupMs: policy.cleanupMs,\n\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t...(journal.state.budget\n\t\t\t? {\n\t\t\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
1
+ {"version":3,"file":"owned-execution.js","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgB9D;;;;;;GAMG;AACH,SAAS,cAAc,CACtB,SAAiB,EACjB,MAAwB,EACxB,UAAkB,EACc;IAChC,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACJ,IAAI,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB;YACC,SAAS,EAAE,YAAY;YACvB,UAAU,EAAE,cAAc;YAC1B,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,MAAM;YACN,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;SAC9B;KACD,CAAC,CAAC;AAAA,CACH;AAED,+EAA+E;AAC/E,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAEjF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,OAA2B,EAC3B,OAAwB,EACxB,MAKC,EACyB;IAC1B,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,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C;QAC3C,CAAC;QAAC,OAAO,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,oCAAoC,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,WAAW;QAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClE,sEAAsE;IACtE,2EAA2E;IAC3E,2DAAyD;IACzD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACvF,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU;QAAE,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IAC5F,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,CAC1C","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { realpathSync } from \"node:fs\";\nimport { performance } from \"node:perf_hooks\";\nimport type { ResourceClaimInput } from \"../../coordination/resource.ts\";\nimport type { GrantToken } from \"../../coordination/types.ts\";\nimport type { RunAuthority } from \"./authority-runtime.ts\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n\treadonly taskId?: string;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/**\n * The filesystem claim a dispatched process is authorized for: exactly the\n * workspace bind it receives inside the namespace — nothing wider. Keys are\n * the resolved absolute path minus the leading slash so prefix containment\n * matches real tree containment; `realpathSync` keeps two spellings of the\n * same directory one claim.\n */\nfunction workspaceClaim(\n\tworkspace: string,\n\taccess: \"read\" | \"write\",\n\tgeneration: number,\n): readonly ResourceClaimInput[] {\n\tlet root: string;\n\ttry {\n\t\troot = realpathSync(workspace);\n\t} catch {\n\t\tthrow new VerifiedRunError(\"authority_claim\");\n\t}\n\treturn Object.freeze([\n\t\t{\n\t\t\tnamespace: \"filesystem\",\n\t\t\tinstanceId: \"verified-run\",\n\t\t\tcanonicalKey: root.replace(/^\\/+/, \"\"),\n\t\t\taccess,\n\t\t\tgeneration: String(generation),\n\t\t},\n\t]);\n}\n\n/** Rejection codes that can only be produced before the supervisor spawned. */\nconst NEVER_SPAWNED = new Set([\"cancelled\", \"deadline\", \"unsupported_boundary\"]);\n\n/**\n * Mandatory durable dispatch intent, shared by command and AgentSession\n * writers. There is no ungated execution lane: a journal without an anchored\n * budget cannot commit a process identity, so the supervisor boundary would\n * be unprovable and must refuse dispatch. Every dispatch now also crosses the\n * durable authority boundary — grant → intent → start → termination witness\n * — so a restart can reconcile effects the journal alone cannot settle.\n */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly authority: RunAuthority;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t// The supervisor boundary only exists once a budget (and therefore the\n\t// gated driver) is anchored. Dispatching without it would run code whose\n\t// termination cannot be witnessed — refuse rather than degrade.\n\tif (!journal.state.budget) throw new VerifiedRunError(\"unsupported_boundary\");\n\tconst authority = policy.authority;\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tconst claims = workspaceClaim(request.workspace, request.role === \"writer\" ? \"write\" : \"read\", generation);\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tconst admission = authority.store.acquire({\n\t\tsessionId: authority.sessionId,\n\t\tincarnation: authority.incarnation,\n\t\tcommandId: executionId,\n\t\tintentDigest: digestObject({ argv: request.argv, claims, role: request.role }),\n\t\tclaims,\n\t\tnow: Date.now(),\n\t\tttl: timeoutMs + policy.cleanupMs + 30000,\n\t});\n\tif (admission.status !== \"granted\") {\n\t\t// A fresh executionId can only collide with a conflicting or wedged\n\t\t// claim — quarantined effects hold theirs until witnessed (fail closed).\n\t\tthrow new VerifiedRunError(\"authority_blocked\");\n\t}\n\tconst token: GrantToken = admission.token;\n\tlet supervisorInvoked = false;\n\tlet readyObserved = false;\n\tlet result: SandboxOutcome;\n\ttry {\n\t\tjournal.append({\n\t\t\tkind: \"dispatch\",\n\t\t\texecutionId,\n\t\t\trole: request.role,\n\t\t\tclaimId: request.claimId,\n\t\t\t...(request.taskId === undefined ? {} : { taskId: request.taskId }),\n\t\t});\n\t\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\t\t// Provably pre-spawn: the intent never reached the adapter, so the grant\n\t\t\t// settles immediately instead of wedging as an unwitnessed live effect.\n\t\t\tauthority.store.cancel(token);\n\t\t\tauthority.store.confirmTerminated(token);\n\t\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\t\tthrow new VerifiedRunError(failure);\n\t\t}\n\t\t// The intent commits before the adapter is invoked: from this record on,\n\t\t// the effect may be live and a crash must quarantine it, never assume\n\t\t// it did not run.\n\t\tif (!authority.store.dispatchIntent(token, executionId)) throw new VerifiedRunError(\"authority\");\n\t\tsupervisorInvoked = true;\n\t\tresult = await executeSandbox({\n\t\t\tworkspace: request.workspace,\n\t\t\targv: request.argv,\n\t\t\twritable: request.role === \"writer\",\n\t\t\ttimeoutMs: Math.floor(request.deadline - performance.now()),\n\t\t\tcleanupMs: policy.cleanupMs,\n\t\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\treadyObserved = true;\n\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\tif (!authority.store.effectStarted(token, claims, identity)) throw new VerifiedRunError(\"authority\");\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// Only pre-spawn rejections prove nothing ran; everything else may have\n\t\t// a live or dying effect, which stays owned until a witness or a later\n\t\t// reconcile settles it.\n\t\ttry {\n\t\t\tauthority.store.cancel(token);\n\t\t\tif (\n\t\t\t\t!supervisorInvoked ||\n\t\t\t\t(!readyObserved && error instanceof VerifiedRunError && NEVER_SPAWNED.has(error.code))\n\t\t\t)\n\t\t\t\tauthority.store.confirmTerminated(token);\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Execution ownership cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t}\n\tif (result.failure === \"cancelled\") authority.store.cancel(token);\n\t// Resolve means both witnesses fired: the direct child closed and the\n\t// recorded namespace drained empty. That is the termination-observed event\n\t// — the grant releases its claims here and nowhere else.\n\tif (!authority.store.confirmTerminated(token)) throw new VerifiedRunError(\"authority\");\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
@@ -1,9 +1,11 @@
1
1
  import type { RunContract } from "omk-protocol";
2
+ import type { RunAuthority } from "./authority-runtime.ts";
2
3
  import type { VerifiedRunJournal } from "./journal.ts";
3
4
  export interface RunPhaseContext {
4
5
  readonly contract: RunContract;
5
6
  readonly runPath: string;
6
7
  readonly journal: VerifiedRunJournal;
8
+ readonly authority: RunAuthority;
7
9
  readonly signal?: AbortSignal;
8
10
  }
9
11
  //# sourceMappingURL=phase-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phase-context.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/phase-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B","sourcesContent":["import type { RunContract } from \"omk-protocol\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\n\nexport interface RunPhaseContext {\n\treadonly contract: RunContract;\n\treadonly runPath: string;\n\treadonly journal: VerifiedRunJournal;\n\treadonly signal?: AbortSignal;\n}\n"]}
1
+ {"version":3,"file":"phase-context.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/phase-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B","sourcesContent":["import type { RunContract } from \"omk-protocol\";\nimport type { RunAuthority } from \"./authority-runtime.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\n\nexport interface RunPhaseContext {\n\treadonly contract: RunContract;\n\treadonly runPath: string;\n\treadonly journal: VerifiedRunJournal;\n\treadonly authority: RunAuthority;\n\treadonly signal?: AbortSignal;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"phase-context.js","sourceRoot":"","sources":["../../../src/core/verified-run/phase-context.ts"],"names":[],"mappings":"","sourcesContent":["import type { RunContract } from \"omk-protocol\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\n\nexport interface RunPhaseContext {\n\treadonly contract: RunContract;\n\treadonly runPath: string;\n\treadonly journal: VerifiedRunJournal;\n\treadonly signal?: AbortSignal;\n}\n"]}
1
+ {"version":3,"file":"phase-context.js","sourceRoot":"","sources":["../../../src/core/verified-run/phase-context.ts"],"names":[],"mappings":"","sourcesContent":["import type { RunContract } from \"omk-protocol\";\nimport type { RunAuthority } from \"./authority-runtime.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\n\nexport interface RunPhaseContext {\n\treadonly contract: RunContract;\n\treadonly runPath: string;\n\treadonly journal: VerifiedRunJournal;\n\treadonly authority: RunAuthority;\n\treadonly signal?: AbortSignal;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAC;AAI/E,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CAkLrE","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { type ProcessReduction, reduceProcessEvent } from \"./process-projection.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst progress: ProcessReduction = { dispatched: new Set(), checked: new Set(), activeRole: \"writer\" };\n\tconst commands = new Set([first.command.commandId]);\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\" || state.receiptDigest) throw new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\":\n\t\t\tcase \"process_ready\":\n\t\t\tcase \"exited\":\n\t\t\t\treduceProcessEvent(context, event, progress);\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, {\n\t\t\t\t\tcommands,\n\t\t\t\t\tchecked: progress.checked,\n\t\t\t\t\tactiveRole: progress.activeRole,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tprogress.checked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAC;AAI/E,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CA0OrE","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { type ProcessReduction, reduceProcessEvent } from \"./process-projection.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tpublication: \"none\",\n\t\t\tpublicationCandidateOid: null,\n\t\t\tpublicationRef: null,\n\t\t\tpublicationCommandId: null,\n\t\t\tpublicationFailure: null,\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tlastRecovery: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst progress: ProcessReduction = { dispatched: new Set(), checked: new Set(), activeRole: \"writer\" };\n\tconst commands = new Set([first.command.commandId]);\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\") throw new VerifiedRunError(\"integrity\");\n\t\tif (\n\t\t\tstate.receiptDigest &&\n\t\t\tevent.kind !== \"publish_intent\" &&\n\t\t\tevent.kind !== \"published\" &&\n\t\t\tevent.kind !== \"publish_failed\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\":\n\t\t\tcase \"process_ready\":\n\t\t\tcase \"exited\":\n\t\t\t\treduceProcessEvent(context, event, progress);\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, {\n\t\t\t\t\tcommands,\n\t\t\t\t\tchecked: progress.checked,\n\t\t\t\t\tactiveRole: progress.activeRole,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tprogress.checked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"publish_intent\":\n\t\t\t\tif (\n\t\t\t\t\tstate.verification !== \"verified\" ||\n\t\t\t\t\tstate.application !== \"candidate_ready\" ||\n\t\t\t\t\tstate.settlement !== \"settled\" ||\n\t\t\t\t\t!state.receiptDigest ||\n\t\t\t\t\tstate.receiptDigest !== event.receiptDigest ||\n\t\t\t\t\tstate.candidateDigest !== event.candidateDigest ||\n\t\t\t\t\tstate.generation !== event.generation ||\n\t\t\t\t\tevent.targetRef !== \"refs/omk/accepted\" ||\n\t\t\t\t\tstate.publication === \"intent\" ||\n\t\t\t\t\tstate.publication === \"accepted\"\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tpublication: \"intent\",\n\t\t\t\t\tpublicationCandidateOid: event.candidateOid,\n\t\t\t\t\tpublicationRef: event.targetRef,\n\t\t\t\t\tpublicationCommandId: event.commandId,\n\t\t\t\t\tpublicationFailure: null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"published\":\n\t\t\t\tif (\n\t\t\t\t\tstate.publication !== \"intent\" ||\n\t\t\t\t\tstate.publicationCommandId !== event.commandId ||\n\t\t\t\t\tstate.publicationCandidateOid !== event.candidateOid\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, publication: \"accepted\", publicationCommandId: null };\n\t\t\t\tbreak;\n\t\t\tcase \"publish_failed\":\n\t\t\t\tif (state.publication !== \"intent\" || state.publicationCommandId !== event.commandId)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tpublication: event.code === \"reconciliation-required\" ? \"reconciliation_required\" : \"failed\",\n\t\t\t\t\tpublicationCommandId: null,\n\t\t\t\t\tpublicationFailure: event.code,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tlastRecovery: context.state.lastRecovery ? Object.freeze(context.state.lastRecovery) : null,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
@@ -24,10 +24,16 @@ export function projectRun(events) {
24
24
  settlement: "open",
25
25
  verification: "not_requested",
26
26
  application: "not_requested",
27
+ publication: "none",
28
+ publicationCandidateOid: null,
29
+ publicationRef: null,
30
+ publicationCommandId: null,
31
+ publicationFailure: null,
27
32
  candidateDigest: null,
28
33
  inputDigest: null,
29
34
  receiptDigest: null,
30
35
  failure: null,
36
+ lastRecovery: null,
31
37
  activeExecutionIds: [],
32
38
  writerOpen: false,
33
39
  modelRequests: 0,
@@ -53,7 +59,12 @@ export function projectRun(events) {
53
59
  const commands = new Set([first.command.commandId]);
54
60
  for (const event of events.slice(1)) {
55
61
  const state = context.state;
56
- if (state.execution === "failed" || state.receiptDigest)
62
+ if (state.execution === "failed")
63
+ throw new VerifiedRunError("integrity");
64
+ if (state.receiptDigest &&
65
+ event.kind !== "publish_intent" &&
66
+ event.kind !== "published" &&
67
+ event.kind !== "publish_failed")
57
68
  throw new VerifiedRunError("integrity");
58
69
  switch (event.kind) {
59
70
  case "created":
@@ -158,6 +169,44 @@ export function projectRun(events) {
158
169
  settlement: state.activeExecutionIds.length || state.writerOpen ? "quarantined" : "settled",
159
170
  };
160
171
  break;
172
+ case "publish_intent":
173
+ if (state.verification !== "verified" ||
174
+ state.application !== "candidate_ready" ||
175
+ state.settlement !== "settled" ||
176
+ !state.receiptDigest ||
177
+ state.receiptDigest !== event.receiptDigest ||
178
+ state.candidateDigest !== event.candidateDigest ||
179
+ state.generation !== event.generation ||
180
+ event.targetRef !== "refs/omk/accepted" ||
181
+ state.publication === "intent" ||
182
+ state.publication === "accepted")
183
+ throw new VerifiedRunError("integrity");
184
+ context.state = {
185
+ ...state,
186
+ publication: "intent",
187
+ publicationCandidateOid: event.candidateOid,
188
+ publicationRef: event.targetRef,
189
+ publicationCommandId: event.commandId,
190
+ publicationFailure: null,
191
+ };
192
+ break;
193
+ case "published":
194
+ if (state.publication !== "intent" ||
195
+ state.publicationCommandId !== event.commandId ||
196
+ state.publicationCandidateOid !== event.candidateOid)
197
+ throw new VerifiedRunError("integrity");
198
+ context.state = { ...state, publication: "accepted", publicationCommandId: null };
199
+ break;
200
+ case "publish_failed":
201
+ if (state.publication !== "intent" || state.publicationCommandId !== event.commandId)
202
+ throw new VerifiedRunError("integrity");
203
+ context.state = {
204
+ ...state,
205
+ publication: event.code === "reconciliation-required" ? "reconciliation_required" : "failed",
206
+ publicationCommandId: null,
207
+ publicationFailure: event.code,
208
+ };
209
+ break;
161
210
  default: {
162
211
  const exhaustive = event;
163
212
  throw new VerifiedRunError(String(exhaustive));
@@ -167,6 +216,7 @@ export function projectRun(events) {
167
216
  }
168
217
  return Object.freeze({
169
218
  ...context.state,
219
+ lastRecovery: context.state.lastRecovery ? Object.freeze(context.state.lastRecovery) : null,
170
220
  activeExecutionIds: Object.freeze([...context.state.activeExecutionIds]),
171
221
  processes: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),
172
222
  tasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),
@@ -1 +1 @@
1
- {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/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,SAAS,CAAC;gBACT,MAAM,UAAU,GAAU,KAAK,CAAC;gBAChC,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;YAChD,CAAC;QACF,CAAC;QACD,OAAO,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,GAAG,OAAO,CAAC,KAAK;QAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACxE,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;KAC5E,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { type ProcessReduction, reduceProcessEvent } from \"./process-projection.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst progress: ProcessReduction = { dispatched: new Set(), checked: new Set(), activeRole: \"writer\" };\n\tconst commands = new Set([first.command.commandId]);\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\" || state.receiptDigest) throw new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\":\n\t\t\tcase \"process_ready\":\n\t\t\tcase \"exited\":\n\t\t\t\treduceProcessEvent(context, event, progress);\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, {\n\t\t\t\t\tcommands,\n\t\t\t\t\tchecked: progress.checked,\n\t\t\t\t\tactiveRole: progress.activeRole,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tprogress.checked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAyB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,MAA2B,EAAiB;IACtE,MAAM,KAAK,GAAG,MAAM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ection } from \"./dag-types.ts\";\nimport { type ProcessReduction, reduceProcessEvent } from \"./process-projection.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tpublication: \"none\",\n\t\t\tpublicationCandidateOid: null,\n\t\t\tpublicationRef: null,\n\t\t\tpublicationCommandId: null,\n\t\t\tpublicationFailure: null,\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tlastRecovery: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst progress: ProcessReduction = { dispatched: new Set(), checked: new Set(), activeRole: \"writer\" };\n\tconst commands = new Set([first.command.commandId]);\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\") throw new VerifiedRunError(\"integrity\");\n\t\tif (\n\t\t\tstate.receiptDigest &&\n\t\t\tevent.kind !== \"publish_intent\" &&\n\t\t\tevent.kind !== \"published\" &&\n\t\t\tevent.kind !== \"publish_failed\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\":\n\t\t\tcase \"process_ready\":\n\t\t\tcase \"exited\":\n\t\t\t\treduceProcessEvent(context, event, progress);\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, {\n\t\t\t\t\tcommands,\n\t\t\t\t\tchecked: progress.checked,\n\t\t\t\t\tactiveRole: progress.activeRole,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tprogress.checked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"publish_intent\":\n\t\t\t\tif (\n\t\t\t\t\tstate.verification !== \"verified\" ||\n\t\t\t\t\tstate.application !== \"candidate_ready\" ||\n\t\t\t\t\tstate.settlement !== \"settled\" ||\n\t\t\t\t\t!state.receiptDigest ||\n\t\t\t\t\tstate.receiptDigest !== event.receiptDigest ||\n\t\t\t\t\tstate.candidateDigest !== event.candidateDigest ||\n\t\t\t\t\tstate.generation !== event.generation ||\n\t\t\t\t\tevent.targetRef !== \"refs/omk/accepted\" ||\n\t\t\t\t\tstate.publication === \"intent\" ||\n\t\t\t\t\tstate.publication === \"accepted\"\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tpublication: \"intent\",\n\t\t\t\t\tpublicationCandidateOid: event.candidateOid,\n\t\t\t\t\tpublicationRef: event.targetRef,\n\t\t\t\t\tpublicationCommandId: event.commandId,\n\t\t\t\t\tpublicationFailure: null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"published\":\n\t\t\t\tif (\n\t\t\t\t\tstate.publication !== \"intent\" ||\n\t\t\t\t\tstate.publicationCommandId !== event.commandId ||\n\t\t\t\t\tstate.publicationCandidateOid !== event.candidateOid\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, publication: \"accepted\", publicationCommandId: null };\n\t\t\t\tbreak;\n\t\t\tcase \"publish_failed\":\n\t\t\t\tif (state.publication !== \"intent\" || state.publicationCommandId !== event.commandId)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tpublication: event.code === \"reconciliation-required\" ? \"reconciliation_required\" : \"failed\",\n\t\t\t\t\tpublicationCommandId: null,\n\t\t\t\t\tpublicationFailure: event.code,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tlastRecovery: context.state.lastRecovery ? Object.freeze(context.state.lastRecovery) : null,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { RunContract, RunPublishCommand } from "omk-protocol";
2
+ import type { JournalSnapshot } from "./journal.ts";
3
+ import type { RunProjection } from "./run-types.ts";
4
+ export declare function publishPolicyDigest(contract: RunContract): string;
5
+ export declare function assertPublishable(snapshot: JournalSnapshot, command: RunPublishCommand, runPath: string): {
6
+ readonly contract: RunContract;
7
+ readonly state: RunProjection & {
8
+ readonly candidateDigest: string;
9
+ readonly receiptDigest: string;
10
+ };
11
+ };
12
+ //# sourceMappingURL=publish-preflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-preflight.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/publish-preflight.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAInE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAOjE;AAED,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,MAAM,GACb;IACF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG;QAAE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CACrG,CA6BA","sourcesContent":["import type { RunContract, RunPublishCommand } from \"omk-protocol\";\nimport { commandEnvironmentDigest } from \"./broker.ts\";\nimport { readRunEvidence } from \"./evidence.ts\";\nimport { OMK_ACCEPTED_REF } from \"./git-plumbing.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\nexport function publishPolicyDigest(contract: RunContract): string {\n\treturn digestObject({\n\t\tapply: contract.apply,\n\t\tprofile: contract.profile,\n\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\twritablePaths: contract.writablePaths,\n\t});\n}\n\nexport function assertPublishable(\n\tsnapshot: JournalSnapshot,\n\tcommand: RunPublishCommand,\n\trunPath: string,\n): {\n\treadonly contract: RunContract;\n\treadonly state: RunProjection & { readonly candidateDigest: string; readonly receiptDigest: string };\n} {\n\tconst first = snapshot.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"missing_run\");\n\tconst contract = first.contract;\n\tconst state = snapshot.state;\n\tif (\n\t\tstate.verification !== \"verified\" ||\n\t\tstate.application !== \"candidate_ready\" ||\n\t\tstate.settlement !== \"settled\" ||\n\t\t!state.receiptDigest ||\n\t\t!state.candidateDigest ||\n\t\tstate.activeExecutionIds.length !== 0 ||\n\t\tstate.writerOpen\n\t)\n\t\tthrow new VerifiedRunError(\"unverified\");\n\tif (\n\t\tcommand.candidateDigest !== state.candidateDigest ||\n\t\tcommand.receiptDigest !== state.receiptDigest ||\n\t\tcommand.policyDigest !== publishPolicyDigest(contract)\n\t)\n\t\tthrow new VerifiedRunError(\"invalid_binding\");\n\tconst evidence = readRunEvidence(runPath, snapshot, commandEnvironmentDigest(contract, \"gated-v1\"));\n\tif (\n\t\t!evidence.verified ||\n\t\tevidence.candidateDigest !== state.candidateDigest ||\n\t\tevidence.receiptDigest !== state.receiptDigest\n\t)\n\t\tthrow new VerifiedRunError(\"invalid_binding\");\n\treturn { contract, state: { ...state, candidateDigest: state.candidateDigest, receiptDigest: state.receiptDigest } };\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { commandEnvironmentDigest } from "./broker.js";
2
+ import { readRunEvidence } from "./evidence.js";
3
+ import { OMK_ACCEPTED_REF } from "./git-plumbing.js";
4
+ import { digestObject, VerifiedRunError } from "./storage.js";
5
+ export function publishPolicyDigest(contract) {
6
+ return digestObject({
7
+ apply: contract.apply,
8
+ profile: contract.profile,
9
+ targetRef: OMK_ACCEPTED_REF,
10
+ writablePaths: contract.writablePaths,
11
+ });
12
+ }
13
+ export function assertPublishable(snapshot, command, runPath) {
14
+ const first = snapshot.records[0]?.event;
15
+ if (first?.kind !== "created")
16
+ throw new VerifiedRunError("missing_run");
17
+ const contract = first.contract;
18
+ const state = snapshot.state;
19
+ if (state.verification !== "verified" ||
20
+ state.application !== "candidate_ready" ||
21
+ state.settlement !== "settled" ||
22
+ !state.receiptDigest ||
23
+ !state.candidateDigest ||
24
+ state.activeExecutionIds.length !== 0 ||
25
+ state.writerOpen)
26
+ throw new VerifiedRunError("unverified");
27
+ if (command.candidateDigest !== state.candidateDigest ||
28
+ command.receiptDigest !== state.receiptDigest ||
29
+ command.policyDigest !== publishPolicyDigest(contract))
30
+ throw new VerifiedRunError("invalid_binding");
31
+ const evidence = readRunEvidence(runPath, snapshot, commandEnvironmentDigest(contract, "gated-v1"));
32
+ if (!evidence.verified ||
33
+ evidence.candidateDigest !== state.candidateDigest ||
34
+ evidence.receiptDigest !== state.receiptDigest)
35
+ throw new VerifiedRunError("invalid_binding");
36
+ return { contract, state: { ...state, candidateDigest: state.candidateDigest, receiptDigest: state.receiptDigest } };
37
+ }
38
+ //# sourceMappingURL=publish-preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-preflight.js","sourceRoot":"","sources":["../../../src/core/verified-run/publish-preflight.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACv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B,CAAC,iBAAiB,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IACpG,IACC,CAAC,QAAQ,CAAC,QAAQ;QAClB,QAAQ,CAAC,eAAe,KAAK,KAAK,CAAC,eAAe;QAClD,QAAQ,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAE9C,MAAM,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IAC/C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,EAAE,CAAC;AAAA,CACrH","sourcesContent":["import type { RunContract, RunPublishCommand } from \"omk-protocol\";\nimport { commandEnvironmentDigest } from \"./broker.ts\";\nimport { readRunEvidence } from \"./evidence.ts\";\nimport { OMK_ACCEPTED_REF } from \"./git-plumbing.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\nexport function publishPolicyDigest(contract: RunContract): string {\n\treturn digestObject({\n\t\tapply: contract.apply,\n\t\tprofile: contract.profile,\n\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\twritablePaths: contract.writablePaths,\n\t});\n}\n\nexport function assertPublishable(\n\tsnapshot: JournalSnapshot,\n\tcommand: RunPublishCommand,\n\trunPath: string,\n): {\n\treadonly contract: RunContract;\n\treadonly state: RunProjection & { readonly candidateDigest: string; readonly receiptDigest: string };\n} {\n\tconst first = snapshot.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"missing_run\");\n\tconst contract = first.contract;\n\tconst state = snapshot.state;\n\tif (\n\t\tstate.verification !== \"verified\" ||\n\t\tstate.application !== \"candidate_ready\" ||\n\t\tstate.settlement !== \"settled\" ||\n\t\t!state.receiptDigest ||\n\t\t!state.candidateDigest ||\n\t\tstate.activeExecutionIds.length !== 0 ||\n\t\tstate.writerOpen\n\t)\n\t\tthrow new VerifiedRunError(\"unverified\");\n\tif (\n\t\tcommand.candidateDigest !== state.candidateDigest ||\n\t\tcommand.receiptDigest !== state.receiptDigest ||\n\t\tcommand.policyDigest !== publishPolicyDigest(contract)\n\t)\n\t\tthrow new VerifiedRunError(\"invalid_binding\");\n\tconst evidence = readRunEvidence(runPath, snapshot, commandEnvironmentDigest(contract, \"gated-v1\"));\n\tif (\n\t\t!evidence.verified ||\n\t\tevidence.candidateDigest !== state.candidateDigest ||\n\t\tevidence.receiptDigest !== state.receiptDigest\n\t)\n\t\tthrow new VerifiedRunError(\"invalid_binding\");\n\treturn { contract, state: { ...state, candidateDigest: state.candidateDigest, receiptDigest: state.receiptDigest } };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { ResourceClaimInput } from "../../coordination/resource.ts";
2
+ import type { GrantToken } from "../../coordination/types.ts";
3
+ import type { AuthorityStore } from "./authority-store.ts";
4
+ export declare function assertPublishEffectStart(store: AuthorityStore, token: GrantToken, claims: readonly ResourceClaimInput[], _pending: boolean, now?: number): void;
5
+ //# sourceMappingURL=publish-start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-start.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/publish-start.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,QAAQ,EAAE,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACV,IAAI,CAGN","sourcesContent":["import type { ResourceClaimInput } from \"../../coordination/resource.ts\";\nimport type { GrantToken } from \"../../coordination/types.ts\";\nimport type { AuthorityStore } from \"./authority-store.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport function assertPublishEffectStart(\n\tstore: AuthorityStore,\n\ttoken: GrantToken,\n\tclaims: readonly ResourceClaimInput[],\n\t_pending: boolean,\n\tnow?: number,\n): void {\n\t// A lookup result cannot substitute for a fresh durable start transition.\n\tif (!store.effectStarted(token, claims, undefined, now)) throw new VerifiedRunError(\"authority\");\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { VerifiedRunError } from "./storage.js";
2
+ export function assertPublishEffectStart(store, token, claims, _pending, now) {
3
+ // A lookup result cannot substitute for a fresh durable start transition.
4
+ if (!store.effectStarted(token, claims, undefined, now))
5
+ throw new VerifiedRunError("authority");
6
+ }
7
+ //# sourceMappingURL=publish-start.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-start.js","sourceRoot":"","sources":["../../../src/core/verified-run/publish-start.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,wBAAwB,CACvC,KAAqB,EACrB,KAAiB,EACjB,MAAqC,EACrC,QAAiB,EACjB,GAAY,EACL;IACP,0EAA0E;IAC1E,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;AAAA,CACjG","sourcesContent":["import type { ResourceClaimInput } from \"../../coordination/resource.ts\";\nimport type { GrantToken } from \"../../coordination/types.ts\";\nimport type { AuthorityStore } from \"./authority-store.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport function assertPublishEffectStart(\n\tstore: AuthorityStore,\n\ttoken: GrantToken,\n\tclaims: readonly ResourceClaimInput[],\n\t_pending: boolean,\n\tnow?: number,\n): void {\n\t// A lookup result cannot substitute for a fresh durable start transition.\n\tif (!store.effectStarted(token, claims, undefined, now)) throw new VerifiedRunError(\"authority\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-projection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGhE,KAAK,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,GAAG,eAAe,CAAA;CAAE,CAAC,CAAC;AAEnG,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE;IACT,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC3C,GACC,IAAI,CAyFN","sourcesContent":["import { MAX_VERIFIED_RUN_GENERATIONS } from \"omk-protocol\";\nimport { retryTaskProjection } from \"./dag-retry-projection.ts\";\nimport type { RunEvent, WriterReduction } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\ntype RecoveryEvent = Extract<RunEvent, { kind: \"resumed\" | \"writer_restarted\" | \"tasks_retried\" }>;\n\n/** Shared generation/command fence; only the writer variant resets attempt-local progress. */\nexport function reduceRecoveryEvent(\n\tcontext: WriterReduction,\n\tevent: RecoveryEvent,\n\tprogress: {\n\t\treadonly commands: Set<string>;\n\t\treadonly checked: Set<string>;\n\t\treadonly activeRole: \"writer\" | \"verifier\";\n\t},\n): void {\n\tconst state = context.state;\n\tconst command = event.command;\n\tif (!state.budget) throw new VerifiedRunError(\"resume_unavailable\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tif (command.expectedRevision !== state.revision || command.expectedGeneration !== state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tif (\n\t\tcommand.runId !== state.runId ||\n\t\tcommand.contractDigest !== digestObject(context.contract) ||\n\t\tprogress.commands.has(command.commandId)\n\t)\n\t\tthrow new VerifiedRunError(\"command_conflict\");\n\tif (\n\t\tevent.reconciledExecutionIds.length !== state.activeExecutionIds.length ||\n\t\tevent.reconciledExecutionIds.some((id, index) => id !== state.activeExecutionIds[index])\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tlet deadline: number;\n\tlet tasks = state.tasks;\n\tswitch (event.kind) {\n\t\tcase \"resumed\":\n\t\t\tif (\n\t\t\t\t!state.candidateDigest ||\n\t\t\t\tstate.writerOpen ||\n\t\t\t\tstate.verificationDeadlineMs === null ||\n\t\t\t\tevent.command.candidateDigest !== state.candidateDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"resume_unavailable\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"verifier\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tdeadline = state.verificationDeadlineMs;\n\t\t\tbreak;\n\t\tcase \"tasks_retried\":\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\ttasks = retryTaskProjection(context, event);\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\");\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tcase \"writer_restarted\":\n\t\t\tif (context.contract.profile === \"linux-command-dag-v1\") throw new VerifiedRunError(\"task_recovery_required\");\n\t\t\tif (\n\t\t\t\t!state.inputDigest ||\n\t\t\t\tstate.candidateDigest ||\n\t\t\t\tevent.command.baseDigest !== state.inputDigest ||\n\t\t\t\tstate.inputDigest !== context.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (\n\t\t\t\tcontext.contract.profile === \"linux-scripted-agent-v1\" &&\n\t\t\t\tcontext.contract.writer.maxRequests - state.modelRequests < context.contract.writer.steps.length + 1\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"model_request_limit\");\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = false;\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tif (event.observedMs < (state.lastClockMs ?? state.budget.startedMs) || event.observedMs >= deadline)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tprogress.commands.add(command.commandId);\n\tprogress.checked.clear();\n\tcontext.state = {\n\t\t...state,\n\t\tgeneration: state.generation + 1,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement: \"settled\",\n\t\tverification: \"not_requested\",\n\t\twriterOpen: false,\n\t\tactiveExecutionIds: [],\n\t\tprocesses: [],\n\t\tfailure: null,\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
1
+ {"version":3,"file":"recovery-projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-projection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGhE,KAAK,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,GAAG,eAAe,CAAA;CAAE,CAAC,CAAC;AAEnG,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE;IACT,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC3C,GACC,IAAI,CA8FN","sourcesContent":["import { MAX_VERIFIED_RUN_GENERATIONS } from \"omk-protocol\";\nimport { retryTaskProjection } from \"./dag-retry-projection.ts\";\nimport type { RunEvent, WriterReduction } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\ntype RecoveryEvent = Extract<RunEvent, { kind: \"resumed\" | \"writer_restarted\" | \"tasks_retried\" }>;\n\n/** Shared generation/command fence; only the writer variant resets attempt-local progress. */\nexport function reduceRecoveryEvent(\n\tcontext: WriterReduction,\n\tevent: RecoveryEvent,\n\tprogress: {\n\t\treadonly commands: Set<string>;\n\t\treadonly checked: Set<string>;\n\t\treadonly activeRole: \"writer\" | \"verifier\";\n\t},\n): void {\n\tconst state = context.state;\n\tconst command = event.command;\n\tif (!state.budget) throw new VerifiedRunError(\"resume_unavailable\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tif (command.expectedRevision !== state.revision || command.expectedGeneration !== state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tif (\n\t\tcommand.runId !== state.runId ||\n\t\tcommand.contractDigest !== digestObject(context.contract) ||\n\t\tprogress.commands.has(command.commandId)\n\t)\n\t\tthrow new VerifiedRunError(\"command_conflict\");\n\tif (\n\t\tevent.reconciledExecutionIds.length !== state.activeExecutionIds.length ||\n\t\tevent.reconciledExecutionIds.some((id, index) => id !== state.activeExecutionIds[index])\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tlet deadline: number;\n\tlet tasks = state.tasks;\n\tswitch (event.kind) {\n\t\tcase \"resumed\":\n\t\t\tif (\n\t\t\t\t!state.candidateDigest ||\n\t\t\t\tstate.writerOpen ||\n\t\t\t\tstate.verificationDeadlineMs === null ||\n\t\t\t\tevent.command.candidateDigest !== state.candidateDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"resume_unavailable\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"verifier\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tdeadline = state.verificationDeadlineMs;\n\t\t\tbreak;\n\t\tcase \"tasks_retried\":\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\ttasks = retryTaskProjection(context, event);\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\");\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tcase \"writer_restarted\":\n\t\t\tif (context.contract.profile === \"linux-command-dag-v1\") throw new VerifiedRunError(\"task_recovery_required\");\n\t\t\tif (\n\t\t\t\t!state.inputDigest ||\n\t\t\t\tstate.candidateDigest ||\n\t\t\t\tevent.command.baseDigest !== state.inputDigest ||\n\t\t\t\tstate.inputDigest !== context.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (\n\t\t\t\tcontext.contract.profile === \"linux-scripted-agent-v1\" &&\n\t\t\t\tcontext.contract.writer.maxRequests - state.modelRequests < context.contract.writer.steps.length + 1\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"model_request_limit\");\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = false;\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tif (event.observedMs < (state.lastClockMs ?? state.budget.startedMs) || event.observedMs >= deadline)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tprogress.commands.add(command.commandId);\n\tprogress.checked.clear();\n\tcontext.state = {\n\t\t...state,\n\t\tgeneration: state.generation + 1,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement: \"settled\",\n\t\tverification: \"not_requested\",\n\t\twriterOpen: false,\n\t\tactiveExecutionIds: [],\n\t\tprocesses: [],\n\t\tfailure: null,\n\t\tlastRecovery: {\n\t\t\tkind: event.kind,\n\t\t\tcommandId: command.commandId,\n\t\t\tgeneration: state.generation + 1,\n\t\t},\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
@@ -82,6 +82,11 @@ export function reduceRecoveryEvent(context, event, progress) {
82
82
  activeExecutionIds: [],
83
83
  processes: [],
84
84
  failure: null,
85
+ lastRecovery: {
86
+ kind: event.kind,
87
+ commandId: command.commandId,
88
+ generation: state.generation + 1,
89
+ },
85
90
  lastClockMs: event.observedMs,
86
91
  };
87
92
  }