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
@@ -0,0 +1,482 @@
1
+ import { canonicalClaim, claimSetsConflict } from "../../coordination/resource.js";
2
+ import { SETTLED_EFFECT_STATES, sequence, } from "../../coordination/types.js";
3
+ import { parseNamespaceIdentity } from "./namespace-identity.js";
4
+ import { VerifiedRunError } from "./storage.js";
5
+ /** A restart that bumped the epoch but never finished reconciliation stays pending. */
6
+ export function authorityPendingReconcile(state) {
7
+ return state.reconciledEpoch !== state.epoch;
8
+ }
9
+ function text(value) {
10
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
11
+ throw new VerifiedRunError("integrity");
12
+ return value;
13
+ }
14
+ /** bootId:pid style writer labels — looser than `text` but still bounded and printable. */
15
+ function writerLabel(value) {
16
+ if (typeof value !== "string" || !/^[A-Za-z0-9_.:-]{1,160}$/.test(value))
17
+ throw new VerifiedRunError("integrity");
18
+ return value;
19
+ }
20
+ function digest(value) {
21
+ const result = text(value);
22
+ if (!/^[a-f0-9]{64}$/.test(result))
23
+ throw new VerifiedRunError("integrity");
24
+ return result;
25
+ }
26
+ function integer(value) {
27
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)
28
+ throw new VerifiedRunError("integrity");
29
+ return value;
30
+ }
31
+ function seq(value) {
32
+ try {
33
+ return sequence(value);
34
+ }
35
+ catch {
36
+ throw new VerifiedRunError("integrity");
37
+ }
38
+ }
39
+ function nextSeq(value) {
40
+ return sequence(String(BigInt(value) + 1n));
41
+ }
42
+ function claim(raw) {
43
+ if (typeof raw !== "object" || raw === null)
44
+ throw new VerifiedRunError("integrity");
45
+ const value = Object.fromEntries(Object.entries(raw));
46
+ try {
47
+ return canonicalClaim(value);
48
+ }
49
+ catch {
50
+ throw new VerifiedRunError("integrity");
51
+ }
52
+ }
53
+ function claimList(raw, limit = 256) {
54
+ if (!Array.isArray(raw) || raw.length === 0 || raw.length > limit)
55
+ throw new VerifiedRunError("integrity");
56
+ return Object.freeze(raw.map(claim));
57
+ }
58
+ function token(raw) {
59
+ if (typeof raw !== "object" || raw === null)
60
+ throw new VerifiedRunError("integrity");
61
+ const value = Object.fromEntries(Object.entries(raw));
62
+ return Object.freeze({
63
+ authorityEpoch: seq(value.authorityEpoch),
64
+ grantSequence: seq(value.grantSequence),
65
+ sessionId: text(value.sessionId),
66
+ sessionIncarnation: seq(value.sessionIncarnation),
67
+ authorizationDeadline: integer(value.authorizationDeadline),
68
+ });
69
+ }
70
+ const GRANT_STATES = new Set([
71
+ "reserved",
72
+ "starting",
73
+ "running",
74
+ "terminating",
75
+ "quarantined",
76
+ "terminated",
77
+ "cancelled",
78
+ ]);
79
+ function grantRecord(raw) {
80
+ if (typeof raw !== "object" || raw === null)
81
+ throw new VerifiedRunError("integrity");
82
+ const value = Object.fromEntries(Object.entries(raw));
83
+ if (typeof value.state !== "string" || !GRANT_STATES.has(value.state))
84
+ throw new VerifiedRunError("integrity");
85
+ if (typeof value.effectLive !== "boolean")
86
+ throw new VerifiedRunError("integrity");
87
+ if (SETTLED_EFFECT_STATES.has(value.state) && value.effectLive)
88
+ throw new VerifiedRunError("integrity");
89
+ if (value.state === "quarantined" && !value.effectLive)
90
+ throw new VerifiedRunError("integrity");
91
+ return Object.freeze({
92
+ token: token(value.token),
93
+ commandId: text(value.commandId),
94
+ intentDigest: digest(value.intentDigest),
95
+ claims: claimList(value.claims),
96
+ weight: integer(value.weight),
97
+ state: value.state,
98
+ effectLive: value.effectLive,
99
+ dispatchId: value.dispatchId === null ? null : text(value.dispatchId),
100
+ actualClaims: value.actualClaims === null ? null : claimList(value.actualClaims),
101
+ identity: value.identity === null ? null : parseNamespaceIdentity(value.identity),
102
+ });
103
+ }
104
+ function tombstone(raw) {
105
+ if (typeof raw !== "object" || raw === null)
106
+ throw new VerifiedRunError("integrity");
107
+ const value = Object.fromEntries(Object.entries(raw));
108
+ const retainedAtMs = integer(value.retainedAtMs);
109
+ const expiresAtMs = integer(value.expiresAtMs);
110
+ if (expiresAtMs <= retainedAtMs)
111
+ throw new VerifiedRunError("integrity");
112
+ return Object.freeze({
113
+ commandId: text(value.commandId),
114
+ grantSequence: seq(value.grantSequence),
115
+ resultDigest: digest(value.resultDigest),
116
+ retainedAtMs,
117
+ expiresAtMs,
118
+ });
119
+ }
120
+ function snapshotState(raw) {
121
+ if (typeof raw !== "object" || raw === null)
122
+ throw new VerifiedRunError("integrity");
123
+ const value = Object.fromEntries(Object.entries(raw));
124
+ if (!Array.isArray(value.incarnations) || !Array.isArray(value.grants) || !Array.isArray(value.tombstones))
125
+ throw new VerifiedRunError("integrity");
126
+ const grants = value.grants.map(grantRecord);
127
+ const tombstones = value.tombstones.map(tombstone);
128
+ const sequences = new Set(grants.map((grant) => grant.token.grantSequence));
129
+ if (sequences.size !== grants.length)
130
+ throw new VerifiedRunError("integrity");
131
+ // grant commandIds are unique among grants; tombstone commandIds among
132
+ // tombstones; a tombstone always references a retained grant (GC drops the
133
+ // expired tombstone+grant pair together).
134
+ if (new Set(grants.map((grant) => grant.commandId)).size !== grants.length)
135
+ throw new VerifiedRunError("integrity");
136
+ if (new Set(tombstones.map((stone) => stone.commandId)).size !== tombstones.length)
137
+ throw new VerifiedRunError("integrity");
138
+ for (const stone of tombstones)
139
+ if (!sequences.has(stone.grantSequence))
140
+ throw new VerifiedRunError("integrity");
141
+ return Object.freeze({
142
+ epoch: seq(value.epoch),
143
+ reconciledEpoch: value.reconciledEpoch === null ? null : seq(value.reconciledEpoch),
144
+ incarnations: Object.freeze(value.incarnations.map((entry) => {
145
+ if (typeof entry !== "object" || entry === null)
146
+ throw new VerifiedRunError("integrity");
147
+ const item = Object.fromEntries(Object.entries(entry));
148
+ return Object.freeze({ sessionId: text(item.sessionId), incarnation: seq(item.incarnation) });
149
+ })),
150
+ grantCounter: seq(value.grantCounter),
151
+ grants: Object.freeze(grants),
152
+ tombstones: Object.freeze(tombstones),
153
+ });
154
+ }
155
+ export function parseAuthorityEvent(raw) {
156
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
157
+ throw new VerifiedRunError("integrity");
158
+ const value = Object.fromEntries(Object.entries(raw));
159
+ switch (value.kind) {
160
+ case "authority-epoch-advanced": {
161
+ if (!Array.isArray(value.transitions) || value.transitions.length > 4096)
162
+ throw new VerifiedRunError("integrity");
163
+ const transitions = value.transitions.map((entry) => {
164
+ if (typeof entry !== "object" || entry === null)
165
+ throw new VerifiedRunError("integrity");
166
+ const item = Object.fromEntries(Object.entries(entry));
167
+ if (item.outcome !== "cancelled" && item.outcome !== "quarantined")
168
+ throw new VerifiedRunError("integrity");
169
+ return Object.freeze({ grantSequence: seq(item.grantSequence), outcome: item.outcome });
170
+ });
171
+ const seen = new Set(transitions.map((entry) => entry.grantSequence));
172
+ if (seen.size !== transitions.length)
173
+ throw new VerifiedRunError("integrity");
174
+ return {
175
+ kind: value.kind,
176
+ authorityEpoch: seq(value.authorityEpoch),
177
+ writerId: writerLabel(value.writerId),
178
+ transitions: Object.freeze(transitions),
179
+ };
180
+ }
181
+ case "authority-reconciled":
182
+ return { kind: value.kind, authorityEpoch: seq(value.authorityEpoch) };
183
+ case "session-registered":
184
+ return { kind: value.kind, sessionId: text(value.sessionId), incarnation: seq(value.incarnation) };
185
+ case "grant-reserved":
186
+ return { kind: value.kind, grant: grantRecord(value.grant) };
187
+ case "dispatch-intent":
188
+ return {
189
+ kind: value.kind,
190
+ grantSequence: seq(value.grantSequence),
191
+ authorityEpoch: seq(value.authorityEpoch),
192
+ dispatchId: text(value.dispatchId),
193
+ };
194
+ case "effect-started":
195
+ return {
196
+ kind: value.kind,
197
+ grantSequence: seq(value.grantSequence),
198
+ authorityEpoch: seq(value.authorityEpoch),
199
+ actualClaims: claimList(value.actualClaims),
200
+ ...(value.identity === undefined ? {} : { identity: parseNamespaceIdentity(value.identity) }),
201
+ };
202
+ case "cancel-requested":
203
+ case "authorization-expired": {
204
+ if (value.outcome !== "cancelled" && value.outcome !== "quarantined")
205
+ throw new VerifiedRunError("integrity");
206
+ return {
207
+ kind: value.kind,
208
+ grantSequence: seq(value.grantSequence),
209
+ authorityEpoch: seq(value.authorityEpoch),
210
+ outcome: value.outcome,
211
+ };
212
+ }
213
+ case "quarantined":
214
+ if (value.reason !== "restart")
215
+ throw new VerifiedRunError("integrity");
216
+ return {
217
+ kind: value.kind,
218
+ grantSequence: seq(value.grantSequence),
219
+ authorityEpoch: seq(value.authorityEpoch),
220
+ reason: value.reason,
221
+ };
222
+ case "termination-observed":
223
+ return {
224
+ kind: value.kind,
225
+ grantSequence: seq(value.grantSequence),
226
+ authorityEpoch: seq(value.authorityEpoch),
227
+ };
228
+ case "result-retained":
229
+ return {
230
+ kind: value.kind,
231
+ commandId: text(value.commandId),
232
+ grantSequence: seq(value.grantSequence),
233
+ resultDigest: digest(value.resultDigest),
234
+ retainedAtMs: integer(value.retainedAtMs),
235
+ expiresAtMs: integer(value.expiresAtMs),
236
+ };
237
+ case "authority-snapshot":
238
+ return {
239
+ kind: value.kind,
240
+ archivedThroughSequence: integer(value.archivedThroughSequence),
241
+ continuesHash: digest(value.continuesHash),
242
+ state: snapshotState(value.state),
243
+ };
244
+ default:
245
+ throw new VerifiedRunError("integrity");
246
+ }
247
+ }
248
+ function reduceAuthorityEvent(state, event) {
249
+ switch (event.kind) {
250
+ case "authority-epoch-advanced": {
251
+ // An epoch may only advance once the previous epoch reconciled. The
252
+ // transition set must cover every unsettled grant exactly once (S4).
253
+ if (authorityPendingReconcile(state))
254
+ throw new VerifiedRunError("integrity");
255
+ const expected = nextSeq(state.epoch ?? sequence("0"));
256
+ if (event.authorityEpoch !== expected)
257
+ throw new VerifiedRunError("integrity");
258
+ const unsettled = new Set([...state.grants.values()]
259
+ .filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state))
260
+ .map((grant) => grant.token.grantSequence));
261
+ for (const transition of event.transitions) {
262
+ const grant = state.grants.get(transition.grantSequence);
263
+ if (!grant || !unsettled.has(transition.grantSequence))
264
+ throw new VerifiedRunError("integrity");
265
+ const outcome = grant.effectLive ? "quarantined" : "cancelled";
266
+ if (transition.outcome !== outcome)
267
+ throw new VerifiedRunError("integrity");
268
+ state.grants.set(transition.grantSequence, { ...grant, state: transition.outcome });
269
+ unsettled.delete(transition.grantSequence);
270
+ }
271
+ if (unsettled.size !== 0)
272
+ throw new VerifiedRunError("integrity");
273
+ state.epoch = event.authorityEpoch;
274
+ break;
275
+ }
276
+ case "authority-reconciled": {
277
+ if (state.epoch === null || event.authorityEpoch !== state.epoch)
278
+ throw new VerifiedRunError("integrity");
279
+ if (!authorityPendingReconcile(state))
280
+ throw new VerifiedRunError("integrity");
281
+ for (const grant of state.grants.values())
282
+ if (!SETTLED_EFFECT_STATES.has(grant.state) && grant.state !== "quarantined")
283
+ throw new VerifiedRunError("integrity");
284
+ state.reconciledEpoch = event.authorityEpoch;
285
+ break;
286
+ }
287
+ case "session-registered": {
288
+ const current = state.incarnations.get(event.sessionId);
289
+ const expected = current === undefined ? sequence("1") : nextSeq(current);
290
+ if (event.incarnation !== expected)
291
+ throw new VerifiedRunError("integrity");
292
+ state.incarnations.set(event.sessionId, event.incarnation);
293
+ break;
294
+ }
295
+ case "grant-reserved": {
296
+ const grant = event.grant;
297
+ if (authorityPendingReconcile(state) || state.epoch === null)
298
+ throw new VerifiedRunError("integrity");
299
+ if (grant.state !== "reserved" ||
300
+ grant.effectLive ||
301
+ grant.dispatchId !== null ||
302
+ grant.actualClaims !== null ||
303
+ grant.identity !== null ||
304
+ grant.token.authorityEpoch !== state.epoch ||
305
+ state.incarnations.get(grant.token.sessionId) !== grant.token.sessionIncarnation ||
306
+ grant.token.grantSequence !== nextSeq(state.grantCounter) ||
307
+ state.grants.has(grant.token.grantSequence) ||
308
+ state.tombstones.has(grant.commandId) ||
309
+ [...state.grants.values()].some((other) => other.commandId === grant.commandId) ||
310
+ [...state.grants.values()].some((other) => !SETTLED_EFFECT_STATES.has(other.state) && claimSetsConflict([...grant.claims], [...other.claims])))
311
+ throw new VerifiedRunError("integrity");
312
+ state.grants.set(grant.token.grantSequence, grant);
313
+ state.grantCounter = grant.token.grantSequence;
314
+ break;
315
+ }
316
+ case "dispatch-intent": {
317
+ const grant = state.grants.get(event.grantSequence);
318
+ if (!grant ||
319
+ grant.state !== "reserved" ||
320
+ grant.token.authorityEpoch !== event.authorityEpoch ||
321
+ event.authorityEpoch !== state.epoch ||
322
+ [...state.grants.values()].some((other) => other.dispatchId === event.dispatchId))
323
+ throw new VerifiedRunError("integrity");
324
+ // A committed intent may already have spawned: the effect is possibly
325
+ // live until a termination witness says otherwise (docs/04 uncertainty
326
+ // window), so effectLive is set here, not at effect-started.
327
+ state.grants.set(event.grantSequence, {
328
+ ...grant,
329
+ state: "starting",
330
+ effectLive: true,
331
+ dispatchId: event.dispatchId,
332
+ });
333
+ break;
334
+ }
335
+ case "effect-started": {
336
+ const grant = state.grants.get(event.grantSequence);
337
+ if (!grant || (grant.state !== "reserved" && grant.state !== "starting"))
338
+ throw new VerifiedRunError("integrity");
339
+ if (event.authorityEpoch !== state.epoch || grant.token.authorityEpoch !== event.authorityEpoch)
340
+ throw new VerifiedRunError("integrity");
341
+ if (event.identity !== undefined) {
342
+ for (const other of state.grants.values()) {
343
+ if (other.token.grantSequence !== event.grantSequence &&
344
+ !SETTLED_EFFECT_STATES.has(other.state) &&
345
+ other.identity &&
346
+ other.identity.namespace === event.identity.namespace &&
347
+ other.identity.pid === event.identity.pid &&
348
+ other.identity.startTicks === event.identity.startTicks &&
349
+ other.identity.bootId === event.identity.bootId)
350
+ throw new VerifiedRunError("integrity");
351
+ }
352
+ }
353
+ state.grants.set(event.grantSequence, {
354
+ ...grant,
355
+ state: "running",
356
+ effectLive: true,
357
+ actualClaims: event.actualClaims,
358
+ identity: event.identity ?? grant.identity,
359
+ });
360
+ break;
361
+ }
362
+ case "cancel-requested":
363
+ case "authorization-expired":
364
+ case "quarantined": {
365
+ const grant = state.grants.get(event.grantSequence);
366
+ if (!grant || SETTLED_EFFECT_STATES.has(grant.state))
367
+ throw new VerifiedRunError("integrity");
368
+ if (event.authorityEpoch !== state.epoch)
369
+ throw new VerifiedRunError("integrity");
370
+ if (event.kind === "quarantined") {
371
+ if (!grant.effectLive || grant.state === "quarantined")
372
+ throw new VerifiedRunError("integrity");
373
+ state.grants.set(event.grantSequence, { ...grant, state: "quarantined" });
374
+ }
375
+ else {
376
+ const outcome = grant.effectLive ? "quarantined" : "cancelled";
377
+ if (event.outcome !== outcome)
378
+ throw new VerifiedRunError("integrity");
379
+ state.grants.set(event.grantSequence, { ...grant, state: event.outcome });
380
+ }
381
+ break;
382
+ }
383
+ case "termination-observed": {
384
+ const grant = state.grants.get(event.grantSequence);
385
+ if (!grant || SETTLED_EFFECT_STATES.has(grant.state))
386
+ throw new VerifiedRunError("integrity");
387
+ state.grants.set(event.grantSequence, { ...grant, effectLive: false, state: "terminated" });
388
+ break;
389
+ }
390
+ case "result-retained": {
391
+ const grant = state.grants.get(event.grantSequence);
392
+ if (!grant || grant.commandId !== event.commandId)
393
+ throw new VerifiedRunError("integrity");
394
+ if (event.expiresAtMs <= event.retainedAtMs || state.tombstones.has(event.commandId))
395
+ throw new VerifiedRunError("integrity");
396
+ state.tombstones.set(event.commandId, Object.freeze({
397
+ commandId: event.commandId,
398
+ grantSequence: event.grantSequence,
399
+ resultDigest: event.resultDigest,
400
+ retainedAtMs: event.retainedAtMs,
401
+ expiresAtMs: event.expiresAtMs,
402
+ }));
403
+ break;
404
+ }
405
+ case "authority-snapshot":
406
+ // Snapshots are archive boundaries, not stream events; the loader seeds
407
+ // from them directly and rejects them mid-stream.
408
+ throw new VerifiedRunError("integrity");
409
+ default: {
410
+ const exhaustive = event;
411
+ throw new VerifiedRunError(String(exhaustive));
412
+ }
413
+ }
414
+ }
415
+ /** Deterministic replay over a seeded (post-snapshot) state. */
416
+ export function projectAuthority(events, seed) {
417
+ const state = seed
418
+ ? {
419
+ epoch: seed.epoch,
420
+ reconciledEpoch: seed.reconciledEpoch,
421
+ incarnations: new Map(seed.incarnations.map((entry) => [entry.sessionId, entry.incarnation])),
422
+ grantCounter: seed.grantCounter,
423
+ grants: new Map(seed.grants.map((grant) => [grant.token.grantSequence, grant])),
424
+ tombstones: new Map(seed.tombstones.map((stone) => [stone.commandId, stone])),
425
+ }
426
+ : {
427
+ epoch: null,
428
+ reconciledEpoch: null,
429
+ incarnations: new Map(),
430
+ grantCounter: sequence("0"),
431
+ grants: new Map(),
432
+ tombstones: new Map(),
433
+ };
434
+ for (const event of events)
435
+ reduceAuthorityEvent(state, event);
436
+ return Object.freeze({
437
+ epoch: state.epoch,
438
+ reconciledEpoch: state.reconciledEpoch,
439
+ incarnations: state.incarnations,
440
+ grantCounter: state.grantCounter,
441
+ grants: state.grants,
442
+ tombstones: state.tombstones,
443
+ });
444
+ }
445
+ /** Grants still holding claims — quarantined included (broker parity). */
446
+ export function activeAuthorityGrants(state) {
447
+ return [...state.grants.values()].filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state));
448
+ }
449
+ /** Apply additional events to an existing projection (commit-time validation replay). */
450
+ export function applyAuthorityEvents(base, events) {
451
+ const state = {
452
+ epoch: base.epoch,
453
+ reconciledEpoch: base.reconciledEpoch,
454
+ incarnations: new Map(base.incarnations),
455
+ grantCounter: base.grantCounter,
456
+ grants: new Map(base.grants),
457
+ tombstones: new Map(base.tombstones),
458
+ };
459
+ for (const event of events)
460
+ reduceAuthorityEvent(state, event);
461
+ return Object.freeze({
462
+ epoch: state.epoch,
463
+ reconciledEpoch: state.reconciledEpoch,
464
+ incarnations: state.incarnations,
465
+ grantCounter: state.grantCounter,
466
+ grants: state.grants,
467
+ tombstones: state.tombstones,
468
+ });
469
+ }
470
+ export function snapshotFromProjection(state) {
471
+ if (state.epoch === null)
472
+ throw new VerifiedRunError("integrity");
473
+ return Object.freeze({
474
+ epoch: state.epoch,
475
+ reconciledEpoch: state.reconciledEpoch,
476
+ incarnations: Object.freeze([...state.incarnations.entries()].map(([sessionId, incarnation]) => Object.freeze({ sessionId, incarnation }))),
477
+ grantCounter: state.grantCounter,
478
+ grants: Object.freeze([...state.grants.values()]),
479
+ tombstones: Object.freeze([...state.tombstones.values()]),
480
+ });
481
+ }
482
+ //# sourceMappingURL=authority-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority-events.js","sourceRoot":"","sources":["../../../src/core/verified-run/authority-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAA2B,MAAM,gCAAgC,CAAC;AAC5G,OAAO,EAIN,qBAAqB,EAErB,QAAQ,GACR,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAkIhD,uFAAuF;AACvF,MAAM,UAAU,yBAAyB,CAAC,KAA0B,EAAW;IAC9E,OAAO,KAAK,CAAC,eAAe,KAAK,KAAK,CAAC,KAAK,CAAC;AAAA,CAC7C;AAED,SAAS,IAAI,CAAC,KAAc,EAAU;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAChH,OAAO,KAAK,CAAC;AAAA,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AC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;KACzD,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { canonicalClaim, claimSetsConflict, type ResourceClaimInput } from \"../../coordination/resource.ts\";\nimport {\n\ttype EffectState,\n\ttype GrantToken,\n\ttype ResourceClaim,\n\tSETTLED_EFFECT_STATES,\n\ttype Sequence,\n\tsequence,\n} from \"../../coordination/types.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { parseNamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\n/**\n * Durable authority event contract (WP03).\n *\n * Mirrors `schemas/supervisor-event.schema.json` plus the review-required\n * extensions: `authority-epoch-advanced` (S4), `authorization-expired` (S5),\n * `session-registered` (S2), `result-retained` (S3 tombstone), and\n * `authority-snapshot` (GC archive boundary, §7). Quarantine reasons are\n * carried on the transition event that caused them — `cancel-requested` /\n * `authorization-expired` / `authority-epoch-advanced` transitions — so a\n * replay can distinguish cancel from expiry from restart (S5).\n */\n\nexport interface AuthorityEpochTransition {\n\treadonly grantSequence: Sequence;\n\treadonly outcome: \"cancelled\" | \"quarantined\";\n}\n\nexport interface AuthorityGrantRecord {\n\treadonly token: GrantToken;\n\t/** Idempotency key supplied by the caller; unique across grants and tombstones. */\n\treadonly commandId: string;\n\treadonly intentDigest: string;\n\t/** Reserved claims (S6: distinct from `actualClaims` bound at effect-started). */\n\treadonly claims: readonly ResourceClaim[];\n\treadonly weight: number;\n\treadonly state: EffectState;\n\treadonly effectLive: boolean;\n\treadonly dispatchId: string | null;\n\treadonly actualClaims: readonly ResourceClaim[] | null;\n\treadonly identity: NamespaceIdentity | null;\n}\n\nexport interface AuthorityTombstone {\n\treadonly commandId: string;\n\treadonly grantSequence: Sequence;\n\treadonly resultDigest: string;\n\treadonly retainedAtMs: number;\n\treadonly expiresAtMs: number;\n}\n\nexport interface AuthoritySnapshotState {\n\treadonly epoch: Sequence;\n\treadonly reconciledEpoch: Sequence | null;\n\treadonly incarnations: readonly { readonly sessionId: string; readonly incarnation: Sequence }[];\n\treadonly grantCounter: Sequence;\n\treadonly grants: readonly AuthorityGrantRecord[];\n\treadonly tombstones: readonly AuthorityTombstone[];\n}\n\nexport type AuthorityEvent =\n\t| {\n\t\t\treadonly kind: \"authority-epoch-advanced\";\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly writerId: string;\n\t\t\treadonly transitions: readonly AuthorityEpochTransition[];\n\t }\n\t| { readonly kind: \"authority-reconciled\"; readonly authorityEpoch: Sequence }\n\t| { readonly kind: \"session-registered\"; readonly sessionId: string; readonly incarnation: Sequence }\n\t| { readonly kind: \"grant-reserved\"; readonly grant: AuthorityGrantRecord }\n\t| {\n\t\t\treadonly kind: \"dispatch-intent\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly dispatchId: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"effect-started\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly actualClaims: readonly ResourceClaim[];\n\t\t\treadonly identity?: NamespaceIdentity;\n\t }\n\t| {\n\t\t\treadonly kind: \"cancel-requested\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly outcome: \"cancelled\" | \"quarantined\";\n\t }\n\t| {\n\t\t\treadonly kind: \"authorization-expired\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly outcome: \"cancelled\" | \"quarantined\";\n\t }\n\t| {\n\t\t\treadonly kind: \"quarantined\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t\t\treadonly reason: \"restart\";\n\t }\n\t| {\n\t\t\treadonly kind: \"termination-observed\";\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly authorityEpoch: Sequence;\n\t }\n\t| {\n\t\t\treadonly kind: \"result-retained\";\n\t\t\treadonly commandId: string;\n\t\t\treadonly grantSequence: Sequence;\n\t\t\treadonly resultDigest: string;\n\t\t\treadonly retainedAtMs: number;\n\t\t\treadonly expiresAtMs: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"authority-snapshot\";\n\t\t\treadonly archivedThroughSequence: number;\n\t\t\treadonly continuesHash: string;\n\t\t\treadonly state: AuthoritySnapshotState;\n\t };\n\nexport interface AuthorityProjection {\n\treadonly epoch: Sequence | null;\n\treadonly reconciledEpoch: Sequence | null;\n\treadonly incarnations: ReadonlyMap<string, Sequence>;\n\treadonly grantCounter: Sequence;\n\treadonly grants: ReadonlyMap<Sequence, AuthorityGrantRecord>;\n\treadonly tombstones: ReadonlyMap<string, AuthorityTombstone>;\n}\n\ninterface MutableAuthorityProjection {\n\tepoch: Sequence | null;\n\treconciledEpoch: Sequence | null;\n\tincarnations: Map<string, Sequence>;\n\tgrantCounter: Sequence;\n\tgrants: Map<Sequence, AuthorityGrantRecord>;\n\ttombstones: Map<string, AuthorityTombstone>;\n}\n\n/** A restart that bumped the epoch but never finished reconciliation stays pending. */\nexport function authorityPendingReconcile(state: AuthorityProjection): boolean {\n\treturn state.reconciledEpoch !== state.epoch;\n}\n\nfunction text(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\n/** bootId:pid style writer labels — looser than `text` but still bounded and printable. */\nfunction writerLabel(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_.:-]{1,160}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction digest(value: unknown): string {\n\tconst result = text(value);\n\tif (!/^[a-f0-9]{64}$/.test(result)) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\n\nfunction integer(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction seq(value: unknown): Sequence {\n\ttry {\n\t\treturn sequence(value);\n\t} catch {\n\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n\nfunction nextSeq(value: Sequence): Sequence {\n\treturn sequence(String(BigInt(value) + 1n));\n}\n\nfunction claim(raw: unknown): ResourceClaim {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\ttry {\n\t\treturn canonicalClaim(value as unknown as ResourceClaimInput);\n\t} catch {\n\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n\nfunction claimList(raw: unknown, limit = 256): readonly ResourceClaim[] {\n\tif (!Array.isArray(raw) || raw.length === 0 || raw.length > limit) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze(raw.map(claim));\n}\n\nfunction token(raw: unknown): GrantToken {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\treturn Object.freeze({\n\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\tgrantSequence: seq(value.grantSequence),\n\t\tsessionId: text(value.sessionId),\n\t\tsessionIncarnation: seq(value.sessionIncarnation),\n\t\tauthorizationDeadline: integer(value.authorizationDeadline),\n\t});\n}\n\nconst GRANT_STATES: ReadonlySet<string> = new Set([\n\t\"reserved\",\n\t\"starting\",\n\t\"running\",\n\t\"terminating\",\n\t\"quarantined\",\n\t\"terminated\",\n\t\"cancelled\",\n]);\n\nfunction grantRecord(raw: unknown): AuthorityGrantRecord {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (typeof value.state !== \"string\" || !GRANT_STATES.has(value.state)) throw new VerifiedRunError(\"integrity\");\n\tif (typeof value.effectLive !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\tif (SETTLED_EFFECT_STATES.has(value.state as EffectState) && value.effectLive)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tif (value.state === \"quarantined\" && !value.effectLive) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\ttoken: token(value.token),\n\t\tcommandId: text(value.commandId),\n\t\tintentDigest: digest(value.intentDigest),\n\t\tclaims: claimList(value.claims),\n\t\tweight: integer(value.weight),\n\t\tstate: value.state as EffectState,\n\t\teffectLive: value.effectLive,\n\t\tdispatchId: value.dispatchId === null ? null : text(value.dispatchId),\n\t\tactualClaims: value.actualClaims === null ? null : claimList(value.actualClaims),\n\t\tidentity: value.identity === null ? null : parseNamespaceIdentity(value.identity),\n\t});\n}\n\nfunction tombstone(raw: unknown): AuthorityTombstone {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tconst retainedAtMs = integer(value.retainedAtMs);\n\tconst expiresAtMs = integer(value.expiresAtMs);\n\tif (expiresAtMs <= retainedAtMs) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\tcommandId: text(value.commandId),\n\t\tgrantSequence: seq(value.grantSequence),\n\t\tresultDigest: digest(value.resultDigest),\n\t\tretainedAtMs,\n\t\texpiresAtMs,\n\t});\n}\n\nfunction snapshotState(raw: unknown): AuthoritySnapshotState {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (!Array.isArray(value.incarnations) || !Array.isArray(value.grants) || !Array.isArray(value.tombstones))\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst grants = value.grants.map(grantRecord);\n\tconst tombstones = value.tombstones.map(tombstone);\n\tconst sequences = new Set(grants.map((grant) => grant.token.grantSequence));\n\tif (sequences.size !== grants.length) throw new VerifiedRunError(\"integrity\");\n\t// grant commandIds are unique among grants; tombstone commandIds among\n\t// tombstones; a tombstone always references a retained grant (GC drops the\n\t// expired tombstone+grant pair together).\n\tif (new Set(grants.map((grant) => grant.commandId)).size !== grants.length) throw new VerifiedRunError(\"integrity\");\n\tif (new Set(tombstones.map((stone) => stone.commandId)).size !== tombstones.length)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tfor (const stone of tombstones) if (!sequences.has(stone.grantSequence)) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\tepoch: seq(value.epoch),\n\t\treconciledEpoch: value.reconciledEpoch === null ? null : seq(value.reconciledEpoch),\n\t\tincarnations: Object.freeze(\n\t\t\tvalue.incarnations.map((entry: unknown) => {\n\t\t\t\tif (typeof entry !== \"object\" || entry === null) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tconst item: Record<string, unknown> = Object.fromEntries(Object.entries(entry));\n\t\t\t\treturn Object.freeze({ sessionId: text(item.sessionId), incarnation: seq(item.incarnation) });\n\t\t\t}),\n\t\t),\n\t\tgrantCounter: seq(value.grantCounter),\n\t\tgrants: Object.freeze(grants),\n\t\ttombstones: Object.freeze(tombstones),\n\t});\n}\n\nexport function parseAuthorityEvent(raw: unknown): AuthorityEvent {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tswitch (value.kind) {\n\t\tcase \"authority-epoch-advanced\": {\n\t\t\tif (!Array.isArray(value.transitions) || value.transitions.length > 4096)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst transitions = value.transitions.map((entry: unknown) => {\n\t\t\t\tif (typeof entry !== \"object\" || entry === null) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tconst item: Record<string, unknown> = Object.fromEntries(Object.entries(entry));\n\t\t\t\tif (item.outcome !== \"cancelled\" && item.outcome !== \"quarantined\") throw new VerifiedRunError(\"integrity\");\n\t\t\t\treturn Object.freeze({ grantSequence: seq(item.grantSequence), outcome: item.outcome });\n\t\t\t});\n\t\t\tconst seen = new Set(transitions.map((entry) => entry.grantSequence));\n\t\t\tif (seen.size !== transitions.length) throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t\twriterId: writerLabel(value.writerId),\n\t\t\t\ttransitions: Object.freeze(transitions),\n\t\t\t};\n\t\t}\n\t\tcase \"authority-reconciled\":\n\t\t\treturn { kind: value.kind, authorityEpoch: seq(value.authorityEpoch) };\n\t\tcase \"session-registered\":\n\t\t\treturn { kind: value.kind, sessionId: text(value.sessionId), incarnation: seq(value.incarnation) };\n\t\tcase \"grant-reserved\":\n\t\t\treturn { kind: value.kind, grant: grantRecord(value.grant) };\n\t\tcase \"dispatch-intent\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t\tdispatchId: text(value.dispatchId),\n\t\t\t};\n\t\tcase \"effect-started\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t\tactualClaims: claimList(value.actualClaims),\n\t\t\t\t...(value.identity === undefined ? {} : { identity: parseNamespaceIdentity(value.identity) }),\n\t\t\t};\n\t\tcase \"cancel-requested\":\n\t\tcase \"authorization-expired\": {\n\t\t\tif (value.outcome !== \"cancelled\" && value.outcome !== \"quarantined\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t\toutcome: value.outcome,\n\t\t\t};\n\t\t}\n\t\tcase \"quarantined\":\n\t\t\tif (value.reason !== \"restart\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t\treason: value.reason,\n\t\t\t};\n\t\tcase \"termination-observed\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tauthorityEpoch: seq(value.authorityEpoch),\n\t\t\t};\n\t\tcase \"result-retained\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tcommandId: text(value.commandId),\n\t\t\t\tgrantSequence: seq(value.grantSequence),\n\t\t\t\tresultDigest: digest(value.resultDigest),\n\t\t\t\tretainedAtMs: integer(value.retainedAtMs),\n\t\t\t\texpiresAtMs: integer(value.expiresAtMs),\n\t\t\t};\n\t\tcase \"authority-snapshot\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tarchivedThroughSequence: integer(value.archivedThroughSequence),\n\t\t\t\tcontinuesHash: digest(value.continuesHash),\n\t\t\t\tstate: snapshotState(value.state),\n\t\t\t};\n\t\tdefault:\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n\nfunction reduceAuthorityEvent(state: MutableAuthorityProjection, event: AuthorityEvent): void {\n\tswitch (event.kind) {\n\t\tcase \"authority-epoch-advanced\": {\n\t\t\t// An epoch may only advance once the previous epoch reconciled. The\n\t\t\t// transition set must cover every unsettled grant exactly once (S4).\n\t\t\tif (authorityPendingReconcile(state)) throw new VerifiedRunError(\"integrity\");\n\t\t\tconst expected = nextSeq(state.epoch ?? sequence(\"0\"));\n\t\t\tif (event.authorityEpoch !== expected) throw new VerifiedRunError(\"integrity\");\n\t\t\tconst unsettled = new Set(\n\t\t\t\t[...state.grants.values()]\n\t\t\t\t\t.filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state))\n\t\t\t\t\t.map((grant) => grant.token.grantSequence),\n\t\t\t);\n\t\t\tfor (const transition of event.transitions) {\n\t\t\t\tconst grant = state.grants.get(transition.grantSequence);\n\t\t\t\tif (!grant || !unsettled.has(transition.grantSequence)) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tconst outcome = grant.effectLive ? \"quarantined\" : \"cancelled\";\n\t\t\t\tif (transition.outcome !== outcome) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tstate.grants.set(transition.grantSequence, { ...grant, state: transition.outcome });\n\t\t\t\tunsettled.delete(transition.grantSequence);\n\t\t\t}\n\t\t\tif (unsettled.size !== 0) throw new VerifiedRunError(\"integrity\");\n\t\t\tstate.epoch = event.authorityEpoch;\n\t\t\tbreak;\n\t\t}\n\t\tcase \"authority-reconciled\": {\n\t\t\tif (state.epoch === null || event.authorityEpoch !== state.epoch) throw new VerifiedRunError(\"integrity\");\n\t\t\tif (!authorityPendingReconcile(state)) throw new VerifiedRunError(\"integrity\");\n\t\t\tfor (const grant of state.grants.values())\n\t\t\t\tif (!SETTLED_EFFECT_STATES.has(grant.state) && grant.state !== \"quarantined\")\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tstate.reconciledEpoch = event.authorityEpoch;\n\t\t\tbreak;\n\t\t}\n\t\tcase \"session-registered\": {\n\t\t\tconst current = state.incarnations.get(event.sessionId);\n\t\t\tconst expected = current === undefined ? sequence(\"1\") : nextSeq(current);\n\t\t\tif (event.incarnation !== expected) throw new VerifiedRunError(\"integrity\");\n\t\t\tstate.incarnations.set(event.sessionId, event.incarnation);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"grant-reserved\": {\n\t\t\tconst grant = event.grant;\n\t\t\tif (authorityPendingReconcile(state) || state.epoch === null) throw new VerifiedRunError(\"integrity\");\n\t\t\tif (\n\t\t\t\tgrant.state !== \"reserved\" ||\n\t\t\t\tgrant.effectLive ||\n\t\t\t\tgrant.dispatchId !== null ||\n\t\t\t\tgrant.actualClaims !== null ||\n\t\t\t\tgrant.identity !== null ||\n\t\t\t\tgrant.token.authorityEpoch !== state.epoch ||\n\t\t\t\tstate.incarnations.get(grant.token.sessionId) !== grant.token.sessionIncarnation ||\n\t\t\t\tgrant.token.grantSequence !== nextSeq(state.grantCounter) ||\n\t\t\t\tstate.grants.has(grant.token.grantSequence) ||\n\t\t\t\tstate.tombstones.has(grant.commandId) ||\n\t\t\t\t[...state.grants.values()].some((other) => other.commandId === grant.commandId) ||\n\t\t\t\t[...state.grants.values()].some(\n\t\t\t\t\t(other) =>\n\t\t\t\t\t\t!SETTLED_EFFECT_STATES.has(other.state) && claimSetsConflict([...grant.claims], [...other.claims]),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tstate.grants.set(grant.token.grantSequence, grant);\n\t\t\tstate.grantCounter = grant.token.grantSequence;\n\t\t\tbreak;\n\t\t}\n\t\tcase \"dispatch-intent\": {\n\t\t\tconst grant = state.grants.get(event.grantSequence);\n\t\t\tif (\n\t\t\t\t!grant ||\n\t\t\t\tgrant.state !== \"reserved\" ||\n\t\t\t\tgrant.token.authorityEpoch !== event.authorityEpoch ||\n\t\t\t\tevent.authorityEpoch !== state.epoch ||\n\t\t\t\t[...state.grants.values()].some((other) => other.dispatchId === event.dispatchId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t// A committed intent may already have spawned: the effect is possibly\n\t\t\t// live until a termination witness says otherwise (docs/04 uncertainty\n\t\t\t// window), so effectLive is set here, not at effect-started.\n\t\t\tstate.grants.set(event.grantSequence, {\n\t\t\t\t...grant,\n\t\t\t\tstate: \"starting\",\n\t\t\t\teffectLive: true,\n\t\t\t\tdispatchId: event.dispatchId,\n\t\t\t});\n\t\t\tbreak;\n\t\t}\n\t\tcase \"effect-started\": {\n\t\t\tconst grant = state.grants.get(event.grantSequence);\n\t\t\tif (!grant || (grant.state !== \"reserved\" && grant.state !== \"starting\"))\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (event.authorityEpoch !== state.epoch || grant.token.authorityEpoch !== event.authorityEpoch)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (event.identity !== undefined) {\n\t\t\t\tfor (const other of state.grants.values()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tother.token.grantSequence !== event.grantSequence &&\n\t\t\t\t\t\t!SETTLED_EFFECT_STATES.has(other.state) &&\n\t\t\t\t\t\tother.identity &&\n\t\t\t\t\t\tother.identity.namespace === event.identity.namespace &&\n\t\t\t\t\t\tother.identity.pid === event.identity.pid &&\n\t\t\t\t\t\tother.identity.startTicks === event.identity.startTicks &&\n\t\t\t\t\t\tother.identity.bootId === event.identity.bootId\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tstate.grants.set(event.grantSequence, {\n\t\t\t\t...grant,\n\t\t\t\tstate: \"running\",\n\t\t\t\teffectLive: true,\n\t\t\t\tactualClaims: event.actualClaims,\n\t\t\t\tidentity: event.identity ?? grant.identity,\n\t\t\t});\n\t\t\tbreak;\n\t\t}\n\t\tcase \"cancel-requested\":\n\t\tcase \"authorization-expired\":\n\t\tcase \"quarantined\": {\n\t\t\tconst grant = state.grants.get(event.grantSequence);\n\t\t\tif (!grant || SETTLED_EFFECT_STATES.has(grant.state)) throw new VerifiedRunError(\"integrity\");\n\t\t\tif (event.authorityEpoch !== state.epoch) throw new VerifiedRunError(\"integrity\");\n\t\t\tif (event.kind === \"quarantined\") {\n\t\t\t\tif (!grant.effectLive || grant.state === \"quarantined\") throw new VerifiedRunError(\"integrity\");\n\t\t\t\tstate.grants.set(event.grantSequence, { ...grant, state: \"quarantined\" });\n\t\t\t} else {\n\t\t\t\tconst outcome = grant.effectLive ? \"quarantined\" : \"cancelled\";\n\t\t\t\tif (event.outcome !== outcome) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tstate.grants.set(event.grantSequence, { ...grant, state: event.outcome });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"termination-observed\": {\n\t\t\tconst grant = state.grants.get(event.grantSequence);\n\t\t\tif (!grant || SETTLED_EFFECT_STATES.has(grant.state)) throw new VerifiedRunError(\"integrity\");\n\t\t\tstate.grants.set(event.grantSequence, { ...grant, effectLive: false, state: \"terminated\" });\n\t\t\tbreak;\n\t\t}\n\t\tcase \"result-retained\": {\n\t\t\tconst grant = state.grants.get(event.grantSequence);\n\t\t\tif (!grant || grant.commandId !== event.commandId) throw new VerifiedRunError(\"integrity\");\n\t\t\tif (event.expiresAtMs <= event.retainedAtMs || state.tombstones.has(event.commandId))\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tstate.tombstones.set(\n\t\t\t\tevent.commandId,\n\t\t\t\tObject.freeze({\n\t\t\t\t\tcommandId: event.commandId,\n\t\t\t\t\tgrantSequence: event.grantSequence,\n\t\t\t\t\tresultDigest: event.resultDigest,\n\t\t\t\t\tretainedAtMs: event.retainedAtMs,\n\t\t\t\t\texpiresAtMs: event.expiresAtMs,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"authority-snapshot\":\n\t\t\t// Snapshots are archive boundaries, not stream events; the loader seeds\n\t\t\t// from them directly and rejects them mid-stream.\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n}\n\n/** Deterministic replay over a seeded (post-snapshot) state. */\nexport function projectAuthority(\n\tevents: readonly AuthorityEvent[],\n\tseed?: AuthoritySnapshotState,\n): AuthorityProjection {\n\tconst state: MutableAuthorityProjection = seed\n\t\t? {\n\t\t\t\tepoch: seed.epoch,\n\t\t\t\treconciledEpoch: seed.reconciledEpoch,\n\t\t\t\tincarnations: new Map(seed.incarnations.map((entry) => [entry.sessionId, entry.incarnation])),\n\t\t\t\tgrantCounter: seed.grantCounter,\n\t\t\t\tgrants: new Map(seed.grants.map((grant) => [grant.token.grantSequence, grant])),\n\t\t\t\ttombstones: new Map(seed.tombstones.map((stone) => [stone.commandId, stone])),\n\t\t\t}\n\t\t: {\n\t\t\t\tepoch: null,\n\t\t\t\treconciledEpoch: null,\n\t\t\t\tincarnations: new Map(),\n\t\t\t\tgrantCounter: sequence(\"0\"),\n\t\t\t\tgrants: new Map(),\n\t\t\t\ttombstones: new Map(),\n\t\t\t};\n\tfor (const event of events) reduceAuthorityEvent(state, event);\n\treturn Object.freeze({\n\t\tepoch: state.epoch,\n\t\treconciledEpoch: state.reconciledEpoch,\n\t\tincarnations: state.incarnations,\n\t\tgrantCounter: state.grantCounter,\n\t\tgrants: state.grants,\n\t\ttombstones: state.tombstones,\n\t});\n}\n\n/** Grants still holding claims — quarantined included (broker parity). */\nexport function activeAuthorityGrants(state: AuthorityProjection): readonly AuthorityGrantRecord[] {\n\treturn [...state.grants.values()].filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state));\n}\n\n/** Apply additional events to an existing projection (commit-time validation replay). */\nexport function applyAuthorityEvents(\n\tbase: AuthorityProjection,\n\tevents: readonly AuthorityEvent[],\n): AuthorityProjection {\n\tconst state: MutableAuthorityProjection = {\n\t\tepoch: base.epoch,\n\t\treconciledEpoch: base.reconciledEpoch,\n\t\tincarnations: new Map(base.incarnations),\n\t\tgrantCounter: base.grantCounter,\n\t\tgrants: new Map(base.grants),\n\t\ttombstones: new Map(base.tombstones),\n\t};\n\tfor (const event of events) reduceAuthorityEvent(state, event);\n\treturn Object.freeze({\n\t\tepoch: state.epoch,\n\t\treconciledEpoch: state.reconciledEpoch,\n\t\tincarnations: state.incarnations,\n\t\tgrantCounter: state.grantCounter,\n\t\tgrants: state.grants,\n\t\ttombstones: state.tombstones,\n\t});\n}\n\nexport function snapshotFromProjection(state: AuthorityProjection): AuthoritySnapshotState {\n\tif (state.epoch === null) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\tepoch: state.epoch,\n\t\treconciledEpoch: state.reconciledEpoch,\n\t\tincarnations: Object.freeze(\n\t\t\t[...state.incarnations.entries()].map(([sessionId, incarnation]) => Object.freeze({ sessionId, incarnation })),\n\t\t),\n\t\tgrantCounter: state.grantCounter,\n\t\tgrants: Object.freeze([...state.grants.values()]),\n\t\ttombstones: Object.freeze([...state.tombstones.values()]),\n\t});\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { type AuthorityEvent, type AuthorityProjection } from "./authority-events.ts";
2
+ export declare const GENESIS_PREVIOUS: string;
3
+ export interface AuthorityRecord {
4
+ readonly version: 1;
5
+ readonly seq: number;
6
+ readonly previous: string;
7
+ readonly event: AuthorityEvent;
8
+ readonly hash: string;
9
+ }
10
+ export interface ParsedAuthority {
11
+ readonly lastSeq: number;
12
+ readonly lastHash: string;
13
+ readonly records: readonly AuthorityRecord[];
14
+ readonly events: readonly AuthorityEvent[];
15
+ readonly state: AuthorityProjection;
16
+ /** Private copy; reuse requires byte equality, not just mtime, size or inode. */
17
+ readonly bytes: Buffer;
18
+ readonly replay: {
19
+ readonly parsedRecords: number;
20
+ readonly reusedPrefixRecords: number;
21
+ };
22
+ }
23
+ export declare function materializeRecord(seq: number, previous: string, event: AuthorityEvent): AuthorityRecord;
24
+ export declare function recordLine(record: AuthorityRecord): string;
25
+ /** Inode/head fencing is checked by the owner before offering a prefix. */
26
+ export declare function parseCommitted(bytes: Buffer, prefix?: ParsedAuthority): ParsedAuthority;
27
+ //# sourceMappingURL=authority-journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority-journal.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/authority-journal.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAKxB,MAAM,uBAAuB,CAAC;AAG/B,eAAO,MAAM,gBAAgB,QAAiB,CAAC;AAC/C,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1F;AACD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,eAAe,CAGvG;AACD,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAE1D;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,eAAe,CA6DvF","sourcesContent":["import { canonicalJson } from \"../run-journal.ts\";\nimport { AuthorityStoreError } from \"./authority-errors.ts\";\nimport {\n\ttype AuthorityEvent,\n\ttype AuthorityProjection,\n\ttype AuthoritySnapshotState,\n\tapplyAuthorityEvents,\n\tparseAuthorityEvent,\n\tprojectAuthority,\n} from \"./authority-events.ts\";\nimport { digestObject } from \"./storage.ts\";\n\nexport const GENESIS_PREVIOUS = \"0\".repeat(64);\nexport interface AuthorityRecord {\n\treadonly version: 1;\n\treadonly seq: number;\n\treadonly previous: string;\n\treadonly event: AuthorityEvent;\n\treadonly hash: string;\n}\nexport interface ParsedAuthority {\n\treadonly lastSeq: number;\n\treadonly lastHash: string;\n\treadonly records: readonly AuthorityRecord[];\n\treadonly events: readonly AuthorityEvent[];\n\treadonly state: AuthorityProjection;\n\t/** Private copy; reuse requires byte equality, not just mtime, size or inode. */\n\treadonly bytes: Buffer;\n\treadonly replay: { readonly parsedRecords: number; readonly reusedPrefixRecords: number };\n}\nexport function materializeRecord(seq: number, previous: string, event: AuthorityEvent): AuthorityRecord {\n\tconst material = { version: 1 as const, seq, previous, event };\n\treturn Object.freeze({ ...material, hash: digestObject(material) });\n}\nexport function recordLine(record: AuthorityRecord): string {\n\treturn `${canonicalJson(record)}\\n`;\n}\n\n/** Inode/head fencing is checked by the owner before offering a prefix. */\nexport function parseCommitted(bytes: Buffer, prefix?: ParsedAuthority): ParsedAuthority {\n\tif (prefix && (bytes.length < prefix.bytes.length || !prefix.bytes.equals(bytes.subarray(0, prefix.bytes.length))))\n\t\tprefix = undefined;\n\tif (prefix && bytes.length === prefix.bytes.length)\n\t\treturn { ...prefix, replay: { parsedRecords: 0, reusedPrefixRecords: prefix.records.length } };\n\tif (!bytes.length)\n\t\treturn {\n\t\t\tlastSeq: 0,\n\t\t\tlastHash: GENESIS_PREVIOUS,\n\t\t\trecords: Object.freeze([]),\n\t\t\tevents: Object.freeze([]),\n\t\t\tstate: projectAuthority([]),\n\t\t\tbytes: Buffer.alloc(0),\n\t\t\treplay: { parsedRecords: 0, reusedPrefixRecords: 0 },\n\t\t};\n\tif (bytes.at(-1) !== 10) throw new AuthorityStoreError(\"corrupt\");\n\tlet text: string;\n\ttry {\n\t\ttext = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes.subarray(prefix?.bytes.length ?? 0));\n\t} catch {\n\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t}\n\tconst lines = text.slice(0, -1).split(\"\\n\");\n\tlet seed: AuthoritySnapshotState | undefined;\n\tlet previous = prefix?.lastHash ?? GENESIS_PREVIOUS;\n\tlet expectedSeq = (prefix?.lastSeq ?? 0) + 1;\n\tlet lastSeq = prefix?.lastSeq ?? 0;\n\tconst events: AuthorityEvent[] = [];\n\tconst records: AuthorityRecord[] = [];\n\tfor (const [index, line] of lines.entries()) {\n\t\tlet raw: unknown;\n\t\ttry {\n\t\t\traw = JSON.parse(line);\n\t\t} catch {\n\t\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t\t}\n\t\tif (typeof raw !== \"object\" || raw === null || !(\"event\" in raw)) throw new AuthorityStoreError(\"corrupt\");\n\t\tconst event = parseAuthorityEvent(raw.event);\n\t\tconst record =\n\t\t\tevent.kind === \"authority-snapshot\"\n\t\t\t\t? materializeRecord(event.archivedThroughSequence + 1, event.continuesHash, event)\n\t\t\t\t: materializeRecord(expectedSeq, previous, event);\n\t\tif (canonicalJson(raw) !== canonicalJson(record)) throw new AuthorityStoreError(\"corrupt\");\n\t\tif (event.kind === \"authority-snapshot\") {\n\t\t\tif (index !== 0 || (prefix && prefix.records.length > 0)) throw new AuthorityStoreError(\"corrupt\");\n\t\t\tseed = event.state;\n\t\t} else events.push(event);\n\t\trecords.push(record);\n\t\tprevious = record.hash;\n\t\tlastSeq = record.seq;\n\t\texpectedSeq = record.seq + 1;\n\t}\n\treturn {\n\t\tlastSeq,\n\t\tlastHash: previous,\n\t\trecords: Object.freeze(prefix ? [...prefix.records, ...records] : records),\n\t\tevents: Object.freeze(prefix ? [...prefix.events, ...events] : events),\n\t\tstate: prefix && !seed ? applyAuthorityEvents(prefix.state, events) : projectAuthority(events, seed),\n\t\tbytes: Buffer.from(bytes),\n\t\treplay: { parsedRecords: records.length, reusedPrefixRecords: prefix?.records.length ?? 0 },\n\t};\n}\n"]}