open-multi-agent-kit 0.98.3 → 0.98.5

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 (468) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +12 -2
  3. package/dist/cli/args.d.ts +1 -0
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +14 -0
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/help.d.ts.map +1 -1
  8. package/dist/cli/help.js +3 -0
  9. package/dist/cli/help.js.map +1 -1
  10. package/dist/cli/mcp-attach.d.ts +3 -3
  11. package/dist/cli/mcp-attach.d.ts.map +1 -1
  12. package/dist/cli/mcp-attach.js +5 -4
  13. package/dist/cli/mcp-attach.js.map +1 -1
  14. package/dist/cli/model-contract.d.ts +5 -0
  15. package/dist/cli/model-contract.d.ts.map +1 -0
  16. package/dist/cli/model-contract.js +45 -0
  17. package/dist/cli/model-contract.js.map +1 -0
  18. package/dist/commands/adaptorch-doctor-cli.d.ts.map +1 -1
  19. package/dist/commands/adaptorch-doctor-cli.js +32 -10
  20. package/dist/commands/adaptorch-doctor-cli.js.map +1 -1
  21. package/dist/commands/init-cli.d.ts +12 -0
  22. package/dist/commands/init-cli.d.ts.map +1 -0
  23. package/dist/commands/init-cli.js +76 -0
  24. package/dist/commands/init-cli.js.map +1 -0
  25. package/dist/commands/provider-sync-cli.d.ts +27 -0
  26. package/dist/commands/provider-sync-cli.d.ts.map +1 -0
  27. package/dist/commands/provider-sync-cli.js +177 -0
  28. package/dist/commands/provider-sync-cli.js.map +1 -0
  29. package/dist/commands/run-command.d.ts +9 -0
  30. package/dist/commands/run-command.d.ts.map +1 -0
  31. package/dist/commands/run-command.js +34 -0
  32. package/dist/commands/run-command.js.map +1 -0
  33. package/dist/commands/verified-run-cli.d.ts +6 -0
  34. package/dist/commands/verified-run-cli.d.ts.map +1 -0
  35. package/dist/commands/verified-run-cli.js +190 -0
  36. package/dist/commands/verified-run-cli.js.map +1 -0
  37. package/dist/core/active-skill-state.d.ts +7 -0
  38. package/dist/core/active-skill-state.d.ts.map +1 -0
  39. package/dist/core/active-skill-state.js +25 -0
  40. package/dist/core/active-skill-state.js.map +1 -0
  41. package/dist/core/agent-session-services.d.ts +10 -1
  42. package/dist/core/agent-session-services.d.ts.map +1 -1
  43. package/dist/core/agent-session-services.js +43 -0
  44. package/dist/core/agent-session-services.js.map +1 -1
  45. package/dist/core/agent-session.d.ts +7 -9
  46. package/dist/core/agent-session.d.ts.map +1 -1
  47. package/dist/core/agent-session.js +91 -126
  48. package/dist/core/agent-session.js.map +1 -1
  49. package/dist/core/codex-chatgpt-web-bridge.d.ts +99 -0
  50. package/dist/core/codex-chatgpt-web-bridge.d.ts.map +1 -0
  51. package/dist/core/codex-chatgpt-web-bridge.js +192 -0
  52. package/dist/core/codex-chatgpt-web-bridge.js.map +1 -0
  53. package/dist/core/codex-chatgpt-web-sync.d.ts +50 -0
  54. package/dist/core/codex-chatgpt-web-sync.d.ts.map +1 -0
  55. package/dist/core/codex-chatgpt-web-sync.js +119 -0
  56. package/dist/core/codex-chatgpt-web-sync.js.map +1 -0
  57. package/dist/core/compaction/compaction-headroom.d.ts +30 -0
  58. package/dist/core/compaction/compaction-headroom.d.ts.map +1 -0
  59. package/dist/core/compaction/compaction-headroom.js +48 -0
  60. package/dist/core/compaction/compaction-headroom.js.map +1 -0
  61. package/dist/core/compaction/compaction.d.ts +2 -29
  62. package/dist/core/compaction/compaction.d.ts.map +1 -1
  63. package/dist/core/compaction/compaction.js +19 -47
  64. package/dist/core/compaction/compaction.js.map +1 -1
  65. package/dist/core/compaction/overflow-retry-guard.d.ts +20 -0
  66. package/dist/core/compaction/overflow-retry-guard.d.ts.map +1 -0
  67. package/dist/core/compaction/overflow-retry-guard.js +38 -0
  68. package/dist/core/compaction/overflow-retry-guard.js.map +1 -0
  69. package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
  70. package/dist/core/context-budget-headroom-types.js +1 -1
  71. package/dist/core/context-budget-headroom-types.js.map +1 -1
  72. package/dist/core/context-budget-token-counter-types.d.ts +27 -0
  73. package/dist/core/context-budget-token-counter-types.d.ts.map +1 -0
  74. package/dist/core/context-budget-token-counter-types.js +2 -0
  75. package/dist/core/context-budget-token-counter-types.js.map +1 -0
  76. package/dist/core/context-budget-token-counter.d.ts +2 -26
  77. package/dist/core/context-budget-token-counter.d.ts.map +1 -1
  78. package/dist/core/context-budget-token-counter.js +2 -0
  79. package/dist/core/context-budget-token-counter.js.map +1 -1
  80. package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
  81. package/dist/core/context-budget-v2-scoring.js +14 -10
  82. package/dist/core/context-budget-v2-scoring.js.map +1 -1
  83. package/dist/core/domain-router.d.ts.map +1 -1
  84. package/dist/core/domain-router.js +1 -1
  85. package/dist/core/domain-router.js.map +1 -1
  86. package/dist/core/grok-harness-dispatch.d.ts +4 -0
  87. package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
  88. package/dist/core/grok-harness-dispatch.js +20 -3
  89. package/dist/core/grok-harness-dispatch.js.map +1 -1
  90. package/dist/core/grok-harness.d.ts +15 -9
  91. package/dist/core/grok-harness.d.ts.map +1 -1
  92. package/dist/core/grok-harness.js +34 -8
  93. package/dist/core/grok-harness.js.map +1 -1
  94. package/dist/core/mcp/tools.d.ts +2 -2
  95. package/dist/core/mcp/tools.d.ts.map +1 -1
  96. package/dist/core/mcp/tools.js +29 -3
  97. package/dist/core/mcp/tools.js.map +1 -1
  98. package/dist/core/model-registry-schema.d.ts +1081 -0
  99. package/dist/core/model-registry-schema.d.ts.map +1 -0
  100. package/dist/core/model-registry-schema.js +148 -0
  101. package/dist/core/model-registry-schema.js.map +1 -0
  102. package/dist/core/model-registry.d.ts.map +1 -1
  103. package/dist/core/model-registry.js +1 -146
  104. package/dist/core/model-registry.js.map +1 -1
  105. package/dist/core/model-resolver.d.ts +2 -1
  106. package/dist/core/model-resolver.d.ts.map +1 -1
  107. package/dist/core/model-resolver.js +2 -1
  108. package/dist/core/model-resolver.js.map +1 -1
  109. package/dist/core/prompt-preset.d.ts +1 -1
  110. package/dist/core/prompt-preset.d.ts.map +1 -1
  111. package/dist/core/prompt-preset.js +16 -1
  112. package/dist/core/prompt-preset.js.map +1 -1
  113. package/dist/core/prompt-settlement.d.ts +4 -3
  114. package/dist/core/prompt-settlement.d.ts.map +1 -1
  115. package/dist/core/prompt-settlement.js.map +1 -1
  116. package/dist/core/provider-display-names.d.ts.map +1 -1
  117. package/dist/core/provider-display-names.js +1 -0
  118. package/dist/core/provider-display-names.js.map +1 -1
  119. package/dist/core/provider-resilience.d.ts +8 -0
  120. package/dist/core/provider-resilience.d.ts.map +1 -1
  121. package/dist/core/provider-resilience.js +20 -3
  122. package/dist/core/provider-resilience.js.map +1 -1
  123. package/dist/core/provider-usage-types.d.ts +42 -0
  124. package/dist/core/provider-usage-types.d.ts.map +1 -0
  125. package/dist/core/provider-usage-types.js +2 -0
  126. package/dist/core/provider-usage-types.js.map +1 -0
  127. package/dist/core/provider-usage.d.ts +2 -31
  128. package/dist/core/provider-usage.d.ts.map +1 -1
  129. package/dist/core/provider-usage.js +4 -0
  130. package/dist/core/provider-usage.js.map +1 -1
  131. package/dist/core/redaction.d.ts.map +1 -1
  132. package/dist/core/redaction.js +18 -2
  133. package/dist/core/redaction.js.map +1 -1
  134. package/dist/core/run-budget-policy.d.ts +18 -0
  135. package/dist/core/run-budget-policy.d.ts.map +1 -0
  136. package/dist/core/run-budget-policy.js +52 -0
  137. package/dist/core/run-budget-policy.js.map +1 -0
  138. package/dist/core/run-budget.d.ts +33 -0
  139. package/dist/core/run-budget.d.ts.map +1 -0
  140. package/dist/core/run-budget.js +89 -0
  141. package/dist/core/run-budget.js.map +1 -0
  142. package/dist/core/run-execution-api.d.ts +15 -0
  143. package/dist/core/run-execution-api.d.ts.map +1 -0
  144. package/dist/core/run-execution-api.js +7 -0
  145. package/dist/core/run-execution-api.js.map +1 -0
  146. package/dist/core/run-journal.d.ts.map +1 -1
  147. package/dist/core/run-journal.js +30 -208
  148. package/dist/core/run-journal.js.map +1 -1
  149. package/dist/core/sandbox/policy-merge.d.ts +6 -0
  150. package/dist/core/sandbox/policy-merge.d.ts.map +1 -0
  151. package/dist/core/sandbox/policy-merge.js +74 -0
  152. package/dist/core/sandbox/policy-merge.js.map +1 -0
  153. package/dist/core/sandbox/policy-paths.d.ts +4 -0
  154. package/dist/core/sandbox/policy-paths.d.ts.map +1 -0
  155. package/dist/core/sandbox/policy-paths.js +21 -0
  156. package/dist/core/sandbox/policy-paths.js.map +1 -0
  157. package/dist/core/sandbox/policy-types.d.ts +75 -0
  158. package/dist/core/sandbox/policy-types.d.ts.map +1 -0
  159. package/dist/core/sandbox/policy-types.js +2 -0
  160. package/dist/core/sandbox/policy-types.js.map +1 -0
  161. package/dist/core/sandbox/policy.d.ts +3 -77
  162. package/dist/core/sandbox/policy.d.ts.map +1 -1
  163. package/dist/core/sandbox/policy.js +3 -98
  164. package/dist/core/sandbox/policy.js.map +1 -1
  165. package/dist/core/sdk-provider-stream.d.ts +14 -0
  166. package/dist/core/sdk-provider-stream.d.ts.map +1 -0
  167. package/dist/core/sdk-provider-stream.js +38 -0
  168. package/dist/core/sdk-provider-stream.js.map +1 -0
  169. package/dist/core/sdk.d.ts +5 -1
  170. package/dist/core/sdk.d.ts.map +1 -1
  171. package/dist/core/sdk.js +17 -33
  172. package/dist/core/sdk.js.map +1 -1
  173. package/dist/core/session-bash-service.d.ts +2 -2
  174. package/dist/core/session-bash-service.d.ts.map +1 -1
  175. package/dist/core/session-bash-service.js +21 -9
  176. package/dist/core/session-bash-service.js.map +1 -1
  177. package/dist/core/session-failure-cause.d.ts.map +1 -1
  178. package/dist/core/session-failure-cause.js +15 -3
  179. package/dist/core/session-failure-cause.js.map +1 -1
  180. package/dist/core/session-prompt-lifecycle.d.ts +25 -0
  181. package/dist/core/session-prompt-lifecycle.d.ts.map +1 -0
  182. package/dist/core/session-prompt-lifecycle.js +87 -0
  183. package/dist/core/session-prompt-lifecycle.js.map +1 -0
  184. package/dist/core/session-run-budget.d.ts +28 -0
  185. package/dist/core/session-run-budget.d.ts.map +1 -0
  186. package/dist/core/session-run-budget.js +127 -0
  187. package/dist/core/session-run-budget.js.map +1 -0
  188. package/dist/core/session-run-termination.d.ts +18 -0
  189. package/dist/core/session-run-termination.d.ts.map +1 -0
  190. package/dist/core/session-run-termination.js +72 -0
  191. package/dist/core/session-run-termination.js.map +1 -0
  192. package/dist/core/session-termination-types.d.ts +97 -0
  193. package/dist/core/session-termination-types.d.ts.map +1 -0
  194. package/dist/core/session-termination-types.js +26 -0
  195. package/dist/core/session-termination-types.js.map +1 -0
  196. package/dist/core/session-termination.d.ts +3 -97
  197. package/dist/core/session-termination.d.ts.map +1 -1
  198. package/dist/core/session-termination.js +25 -29
  199. package/dist/core/session-termination.js.map +1 -1
  200. package/dist/core/skill-selector.d.ts +40 -0
  201. package/dist/core/skill-selector.d.ts.map +1 -0
  202. package/dist/core/skill-selector.js +102 -0
  203. package/dist/core/skill-selector.js.map +1 -0
  204. package/dist/core/slash-commands.d.ts.map +1 -1
  205. package/dist/core/slash-commands.js +1 -0
  206. package/dist/core/slash-commands.js.map +1 -1
  207. package/dist/core/subagent-lane-launcher.d.ts +3 -2
  208. package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
  209. package/dist/core/subagent-lane-launcher.js +24 -13
  210. package/dist/core/subagent-lane-launcher.js.map +1 -1
  211. package/dist/core/tools/render-utils.d.ts.map +1 -1
  212. package/dist/core/tools/render-utils.js +2 -4
  213. package/dist/core/tools/render-utils.js.map +1 -1
  214. package/dist/core/turn-metrics-record.d.ts +55 -0
  215. package/dist/core/turn-metrics-record.d.ts.map +1 -0
  216. package/dist/core/turn-metrics-record.js +149 -0
  217. package/dist/core/turn-metrics-record.js.map +1 -0
  218. package/dist/core/turn-metrics.d.ts +4 -56
  219. package/dist/core/turn-metrics.d.ts.map +1 -1
  220. package/dist/core/turn-metrics.js +12 -60
  221. package/dist/core/turn-metrics.js.map +1 -1
  222. package/dist/core/verified-run/broker.d.ts +26 -0
  223. package/dist/core/verified-run/broker.d.ts.map +1 -0
  224. package/dist/core/verified-run/broker.js +210 -0
  225. package/dist/core/verified-run/broker.js.map +1 -0
  226. package/dist/core/verified-run/candidate.d.ts +24 -0
  227. package/dist/core/verified-run/candidate.d.ts.map +1 -0
  228. package/dist/core/verified-run/candidate.js +167 -0
  229. package/dist/core/verified-run/candidate.js.map +1 -0
  230. package/dist/core/verified-run/check-receipt.d.ts +18 -0
  231. package/dist/core/verified-run/check-receipt.d.ts.map +1 -0
  232. package/dist/core/verified-run/check-receipt.js +92 -0
  233. package/dist/core/verified-run/check-receipt.js.map +1 -0
  234. package/dist/core/verified-run/coordinator.d.ts +39 -0
  235. package/dist/core/verified-run/coordinator.d.ts.map +1 -0
  236. package/dist/core/verified-run/coordinator.js +190 -0
  237. package/dist/core/verified-run/coordinator.js.map +1 -0
  238. package/dist/core/verified-run/dag-candidates.d.ts +8 -0
  239. package/dist/core/verified-run/dag-candidates.d.ts.map +1 -0
  240. package/dist/core/verified-run/dag-candidates.js +65 -0
  241. package/dist/core/verified-run/dag-candidates.js.map +1 -0
  242. package/dist/core/verified-run/dag-phase.d.ts +7 -0
  243. package/dist/core/verified-run/dag-phase.d.ts.map +1 -0
  244. package/dist/core/verified-run/dag-phase.js +92 -0
  245. package/dist/core/verified-run/dag-phase.js.map +1 -0
  246. package/dist/core/verified-run/dag-projection.d.ts +7 -0
  247. package/dist/core/verified-run/dag-projection.d.ts.map +1 -0
  248. package/dist/core/verified-run/dag-projection.js +90 -0
  249. package/dist/core/verified-run/dag-projection.js.map +1 -0
  250. package/dist/core/verified-run/dag-recovery.d.ts +13 -0
  251. package/dist/core/verified-run/dag-recovery.d.ts.map +1 -0
  252. package/dist/core/verified-run/dag-recovery.js +98 -0
  253. package/dist/core/verified-run/dag-recovery.js.map +1 -0
  254. package/dist/core/verified-run/dag-retry-projection.d.ts +9 -0
  255. package/dist/core/verified-run/dag-retry-projection.d.ts.map +1 -0
  256. package/dist/core/verified-run/dag-retry-projection.js +43 -0
  257. package/dist/core/verified-run/dag-retry-projection.js.map +1 -0
  258. package/dist/core/verified-run/dag-types.d.ts +47 -0
  259. package/dist/core/verified-run/dag-types.d.ts.map +1 -0
  260. package/dist/core/verified-run/dag-types.js +2 -0
  261. package/dist/core/verified-run/dag-types.js.map +1 -0
  262. package/dist/core/verified-run/event-parser.d.ts +3 -0
  263. package/dist/core/verified-run/event-parser.d.ts.map +1 -0
  264. package/dist/core/verified-run/event-parser.js +153 -0
  265. package/dist/core/verified-run/event-parser.js.map +1 -0
  266. package/dist/core/verified-run/events.d.ts +4 -0
  267. package/dist/core/verified-run/events.d.ts.map +1 -0
  268. package/dist/core/verified-run/events.js +3 -0
  269. package/dist/core/verified-run/events.js.map +1 -0
  270. package/dist/core/verified-run/evidence-binding.d.ts +18 -0
  271. package/dist/core/verified-run/evidence-binding.d.ts.map +1 -0
  272. package/dist/core/verified-run/evidence-binding.js +81 -0
  273. package/dist/core/verified-run/evidence-binding.js.map +1 -0
  274. package/dist/core/verified-run/evidence.d.ts +27 -0
  275. package/dist/core/verified-run/evidence.d.ts.map +1 -0
  276. package/dist/core/verified-run/evidence.js +100 -0
  277. package/dist/core/verified-run/evidence.js.map +1 -0
  278. package/dist/core/verified-run/journal.d.ts +32 -0
  279. package/dist/core/verified-run/journal.d.ts.map +1 -0
  280. package/dist/core/verified-run/journal.js +103 -0
  281. package/dist/core/verified-run/journal.js.map +1 -0
  282. package/dist/core/verified-run/namespace-identity.d.ts +11 -0
  283. package/dist/core/verified-run/namespace-identity.d.ts.map +1 -0
  284. package/dist/core/verified-run/namespace-identity.js +77 -0
  285. package/dist/core/verified-run/namespace-identity.js.map +1 -0
  286. package/dist/core/verified-run/owned-execution.d.ts +21 -0
  287. package/dist/core/verified-run/owned-execution.d.ts.map +1 -0
  288. package/dist/core/verified-run/owned-execution.js +43 -0
  289. package/dist/core/verified-run/owned-execution.js.map +1 -0
  290. package/dist/core/verified-run/phase-context.d.ts +9 -0
  291. package/dist/core/verified-run/phase-context.d.ts.map +1 -0
  292. package/dist/core/verified-run/phase-context.js +2 -0
  293. package/dist/core/verified-run/phase-context.js.map +1 -0
  294. package/dist/core/verified-run/process-gate.d.ts +5 -0
  295. package/dist/core/verified-run/process-gate.d.ts.map +1 -0
  296. package/dist/core/verified-run/process-gate.js +31 -0
  297. package/dist/core/verified-run/process-gate.js.map +1 -0
  298. package/dist/core/verified-run/projection.d.ts +4 -0
  299. package/dist/core/verified-run/projection.d.ts.map +1 -0
  300. package/dist/core/verified-run/projection.js +219 -0
  301. package/dist/core/verified-run/projection.js.map +1 -0
  302. package/dist/core/verified-run/recovery-clock.d.ts +19 -0
  303. package/dist/core/verified-run/recovery-clock.d.ts.map +1 -0
  304. package/dist/core/verified-run/recovery-clock.js +69 -0
  305. package/dist/core/verified-run/recovery-clock.js.map +1 -0
  306. package/dist/core/verified-run/recovery-command.d.ts +11 -0
  307. package/dist/core/verified-run/recovery-command.d.ts.map +1 -0
  308. package/dist/core/verified-run/recovery-command.js +73 -0
  309. package/dist/core/verified-run/recovery-command.js.map +1 -0
  310. package/dist/core/verified-run/recovery-projection.d.ts +12 -0
  311. package/dist/core/verified-run/recovery-projection.d.ts.map +1 -0
  312. package/dist/core/verified-run/recovery-projection.js +88 -0
  313. package/dist/core/verified-run/recovery-projection.js.map +1 -0
  314. package/dist/core/verified-run/recovery.d.ts +12 -0
  315. package/dist/core/verified-run/recovery.d.ts.map +1 -0
  316. package/dist/core/verified-run/recovery.js +115 -0
  317. package/dist/core/verified-run/recovery.js.map +1 -0
  318. package/dist/core/verified-run/run-types.d.ts +103 -0
  319. package/dist/core/verified-run/run-types.d.ts.map +1 -0
  320. package/dist/core/verified-run/run-types.js +2 -0
  321. package/dist/core/verified-run/run-types.js.map +1 -0
  322. package/dist/core/verified-run/scripted-writer.d.ts +15 -0
  323. package/dist/core/verified-run/scripted-writer.d.ts.map +1 -0
  324. package/dist/core/verified-run/scripted-writer.js +94 -0
  325. package/dist/core/verified-run/scripted-writer.js.map +1 -0
  326. package/dist/core/verified-run/session-port.d.ts +27 -0
  327. package/dist/core/verified-run/session-port.d.ts.map +1 -0
  328. package/dist/core/verified-run/session-port.js +2 -0
  329. package/dist/core/verified-run/session-port.js.map +1 -0
  330. package/dist/core/verified-run/storage.d.ts +15 -0
  331. package/dist/core/verified-run/storage.d.ts.map +1 -0
  332. package/dist/core/verified-run/storage.js +96 -0
  333. package/dist/core/verified-run/storage.js.map +1 -0
  334. package/dist/core/verified-run/verification-phase.d.ts +5 -0
  335. package/dist/core/verified-run/verification-phase.d.ts.map +1 -0
  336. package/dist/core/verified-run/verification-phase.js +56 -0
  337. package/dist/core/verified-run/verification-phase.js.map +1 -0
  338. package/dist/core/verified-run/work-recovery.d.ts +8 -0
  339. package/dist/core/verified-run/work-recovery.d.ts.map +1 -0
  340. package/dist/core/verified-run/work-recovery.js +44 -0
  341. package/dist/core/verified-run/work-recovery.js.map +1 -0
  342. package/dist/core/verified-run/writer-completion.d.ts +4 -0
  343. package/dist/core/verified-run/writer-completion.d.ts.map +1 -0
  344. package/dist/core/verified-run/writer-completion.js +27 -0
  345. package/dist/core/verified-run/writer-completion.js.map +1 -0
  346. package/dist/core/verified-run/writer-phase.d.ts +8 -0
  347. package/dist/core/verified-run/writer-phase.d.ts.map +1 -0
  348. package/dist/core/verified-run/writer-phase.js +76 -0
  349. package/dist/core/verified-run/writer-phase.js.map +1 -0
  350. package/dist/core/verified-run/writer-projection.d.ts +11 -0
  351. package/dist/core/verified-run/writer-projection.d.ts.map +1 -0
  352. package/dist/core/verified-run/writer-projection.js +70 -0
  353. package/dist/core/verified-run/writer-projection.js.map +1 -0
  354. package/dist/core/verified-run/writer-recovery.d.ts +16 -0
  355. package/dist/core/verified-run/writer-recovery.d.ts.map +1 -0
  356. package/dist/core/verified-run/writer-recovery.js +107 -0
  357. package/dist/core/verified-run/writer-recovery.js.map +1 -0
  358. package/dist/core/workload-permit-pool.d.ts +1 -3
  359. package/dist/core/workload-permit-pool.d.ts.map +1 -1
  360. package/dist/core/workload-permit-pool.js +11 -11
  361. package/dist/core/workload-permit-pool.js.map +1 -1
  362. package/dist/guardrails/evidence-system.d.ts +1 -1
  363. package/dist/guardrails/evidence-system.d.ts.map +1 -1
  364. package/dist/guardrails/evidence-system.js +18 -29
  365. package/dist/guardrails/evidence-system.js.map +1 -1
  366. package/dist/guardrails/merge-gate-result.d.ts +4 -0
  367. package/dist/guardrails/merge-gate-result.d.ts.map +1 -0
  368. package/dist/guardrails/merge-gate-result.js +32 -0
  369. package/dist/guardrails/merge-gate-result.js.map +1 -0
  370. package/dist/index.d.ts +3 -2
  371. package/dist/index.d.ts.map +1 -1
  372. package/dist/index.js +2 -2
  373. package/dist/index.js.map +1 -1
  374. package/dist/main.d.ts.map +1 -1
  375. package/dist/main.js +17 -23
  376. package/dist/main.js.map +1 -1
  377. package/dist/modes/interactive/components/session-failure.d.ts +13 -0
  378. package/dist/modes/interactive/components/session-failure.d.ts.map +1 -0
  379. package/dist/modes/interactive/components/session-failure.js +81 -0
  380. package/dist/modes/interactive/components/session-failure.js.map +1 -0
  381. package/dist/modes/interactive/interactive-login-options.d.ts +27 -0
  382. package/dist/modes/interactive/interactive-login-options.d.ts.map +1 -0
  383. package/dist/modes/interactive/interactive-login-options.js +54 -0
  384. package/dist/modes/interactive/interactive-login-options.js.map +1 -0
  385. package/dist/modes/interactive/interactive-mode.d.ts +8 -4
  386. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  387. package/dist/modes/interactive/interactive-mode.js +183 -171
  388. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  389. package/dist/modes/interactive/interactive-resume-command.d.ts +3 -0
  390. package/dist/modes/interactive/interactive-resume-command.d.ts.map +1 -0
  391. package/dist/modes/interactive/interactive-resume-command.js +24 -0
  392. package/dist/modes/interactive/interactive-resume-command.js.map +1 -0
  393. package/dist/modes/interactive/interactive-tool-result.d.ts +32 -0
  394. package/dist/modes/interactive/interactive-tool-result.d.ts.map +1 -0
  395. package/dist/modes/interactive/interactive-tool-result.js +59 -0
  396. package/dist/modes/interactive/interactive-tool-result.js.map +1 -0
  397. package/dist/modes/interactive/tui-diagnostics.d.ts +36 -0
  398. package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -0
  399. package/dist/modes/interactive/tui-diagnostics.js +105 -0
  400. package/dist/modes/interactive/tui-diagnostics.js.map +1 -0
  401. package/dist/modes/interactive/tui-runtime-info.d.ts +20 -0
  402. package/dist/modes/interactive/tui-runtime-info.d.ts.map +1 -0
  403. package/dist/modes/interactive/tui-runtime-info.js +76 -0
  404. package/dist/modes/interactive/tui-runtime-info.js.map +1 -0
  405. package/dist/modes/print-mode.d.ts.map +1 -1
  406. package/dist/modes/print-mode.js +22 -0
  407. package/dist/modes/print-mode.js.map +1 -1
  408. package/dist/utils/clipboard-image.d.ts.map +1 -1
  409. package/dist/utils/clipboard-image.js +10 -60
  410. package/dist/utils/clipboard-image.js.map +1 -1
  411. package/dist/utils/terminal-links.d.ts +13 -0
  412. package/dist/utils/terminal-links.d.ts.map +1 -0
  413. package/dist/utils/terminal-links.js +68 -0
  414. package/dist/utils/terminal-links.js.map +1 -0
  415. package/dist/utils/windows-clipboard-image.d.ts +16 -0
  416. package/dist/utils/windows-clipboard-image.d.ts.map +1 -0
  417. package/dist/utils/windows-clipboard-image.js +87 -0
  418. package/dist/utils/windows-clipboard-image.js.map +1 -0
  419. package/docs/adaptorch-onboarding.md +80 -0
  420. package/docs/containerization.md +12 -0
  421. package/docs/context-files.md +97 -0
  422. package/docs/correctness-wall.md +8 -0
  423. package/docs/custom-provider.md +35 -0
  424. package/docs/development.md +28 -3
  425. package/docs/environment-variables.md +2 -0
  426. package/docs/grok-harness.md +4 -0
  427. package/docs/harness-boundaries.md +154 -0
  428. package/docs/harness-improvements.md +90 -0
  429. package/docs/json.md +19 -0
  430. package/docs/keybindings.md +2 -2
  431. package/docs/mcp.md +22 -2
  432. package/docs/metrics.md +66 -16
  433. package/docs/model-catalog-refresh.md +190 -0
  434. package/docs/model-contract.md +168 -0
  435. package/docs/models.md +21 -4
  436. package/docs/provider-resilience.md +5 -3
  437. package/docs/providers.md +68 -1
  438. package/docs/quickstart.md +4 -0
  439. package/docs/release-audit-0.98.4.md +112 -0
  440. package/docs/release-audit-0.98.5.md +84 -0
  441. package/docs/review-bundle-followup.md +195 -0
  442. package/docs/run-protocol.md +33 -1
  443. package/docs/runtime-algorithms.md +45 -0
  444. package/docs/sdk.md +204 -2
  445. package/docs/sessions.md +1 -1
  446. package/docs/settings.md +17 -1
  447. package/docs/skills.md +2 -0
  448. package/docs/tb21-audit.md +131 -0
  449. package/docs/terminal-setup.md +20 -0
  450. package/docs/usage.md +77 -1
  451. package/docs/verified-run-testing.md +417 -0
  452. package/docs/verified-run.md +388 -0
  453. package/docs/windows.md +48 -0
  454. package/examples/README.md +4 -0
  455. package/examples/context/AGENTS.md +64 -0
  456. package/examples/context/CLAUDE.md +17 -0
  457. package/examples/context/INTERNET.md +42 -0
  458. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  459. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  460. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  461. package/examples/extensions/gondolin/package-lock.json +2 -2
  462. package/examples/extensions/gondolin/package.json +1 -1
  463. package/examples/extensions/sandbox/package-lock.json +2 -2
  464. package/examples/extensions/sandbox/package.json +1 -1
  465. package/examples/extensions/with-deps/package-lock.json +2 -2
  466. package/examples/extensions/with-deps/package.json +1 -1
  467. package/npm-shrinkwrap.json +18 -18
  468. package/package.json +6 -6
@@ -0,0 +1,12 @@
1
+ import { type RunResumeCommand } from "omk-protocol";
2
+ import type { RunProjection } from "./run-types.ts";
3
+ export interface RecoveryInspection {
4
+ readonly state: RunProjection;
5
+ readonly readiness: "ready" | "terminal" | "legacy" | "candidate_missing" | "unsettled" | "expired" | "clock_changed" | "clock_rollback" | "clock_unavailable" | "recovery_limit" | "integrity";
6
+ readonly remainingVerifyMs: number | null;
7
+ /** A ready inspection is advisory; exclusive ownership is acquired only by resume. */
8
+ readonly ownership: "lease_required";
9
+ }
10
+ export declare function inspectRunRecovery(runPath: string): RecoveryInspection;
11
+ export declare function resumeFrozenCandidate(runPath: string, command: RunResumeCommand, signal?: AbortSignal): Promise<RunProjection>;
12
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,SAAS,EACf,OAAO,GACP,UAAU,GACV,QAAQ,GACR,mBAAmB,GACnB,WAAW,GACX,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,mBAAmB,GACnB,gBAAgB,GAChB,WAAW,CAAC;IACf,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,sFAAsF;IACtF,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACrC;AAsCD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CA0CtE;AAED,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,aAAa,CAAC,CAkBxB","sourcesContent":["import { join } from \"node:path\";\nimport { MAX_VERIFIED_RUN_GENERATIONS, type RunResumeCommand } from \"omk-protocol\";\nimport { commandEnvironmentDigest, probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightCheckReceipts } from \"./check-receipt.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport { probeNamespace } from \"./namespace-identity.ts\";\nimport { readRunClock, remainingVerification } from \"./recovery-clock.ts\";\nimport { requireRunJournal, withRecoveryLease } from \"./recovery-command.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { readRegularFile, VerifiedRunError } from \"./storage.ts\";\nimport { verifyCandidate } from \"./verification-phase.ts\";\n\nexport interface RecoveryInspection {\n\treadonly state: RunProjection;\n\treadonly readiness:\n\t\t| \"ready\"\n\t\t| \"terminal\"\n\t\t| \"legacy\"\n\t\t| \"candidate_missing\"\n\t\t| \"unsettled\"\n\t\t| \"expired\"\n\t\t| \"clock_changed\"\n\t\t| \"clock_rollback\"\n\t\t| \"clock_unavailable\"\n\t\t| \"recovery_limit\"\n\t\t| \"integrity\";\n\treadonly remainingVerifyMs: number | null;\n\t/** A ready inspection is advisory; exclusive ownership is acquired only by resume. */\n\treadonly ownership: \"lease_required\";\n}\n\nfunction assertCandidateRecoverable(runPath: string, journal: JournalSnapshot): number {\n\tconst state = journal.state;\n\tif (state.receiptDigest || state.execution === \"failed\") throw new VerifiedRunError(\"resume_terminal\");\n\tif (!state.budget || !state.environmentDigest) throw new VerifiedRunError(\"recovery_legacy\");\n\tif (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)\n\t\tthrow new VerifiedRunError(\"candidate_missing\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tconst clock = readRunClock();\n\tconst remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);\n\tif (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs)) throw new VerifiedRunError(\"clock_rollback\");\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\tfor (const id of state.activeExecutionIds) {\n\t\tconst dispatch = journal.records.find(\n\t\t\t(record) =>\n\t\t\t\trecord.generation === state.generation &&\n\t\t\t\trecord.event.kind === \"dispatch\" &&\n\t\t\t\trecord.event.executionId === id,\n\t\t)?.event;\n\t\tconst identity = state.processes.find((process) => process.executionId === id)?.identity;\n\t\tif (\n\t\t\tdispatch?.kind !== \"dispatch\" ||\n\t\t\tdispatch.role !== \"verifier\" ||\n\t\t\t!identity ||\n\t\t\tprobeNamespace(identity) !== \"gone\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"unsettled\");\n\t}\n\tconst first = journal.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\tif (readRegularFile(join(runPath, \"issuer.key\"), 32).length !== 32) throw new VerifiedRunError(\"integrity\");\n\tloadCandidate(runPath, state.candidateDigest, first.contract.budget);\n\tif (commandEnvironmentDigest(first.contract, \"gated-v1\") !== state.environmentDigest)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn remaining;\n}\n\nexport function inspectRunRecovery(runPath: string): RecoveryInspection {\n\tconst journal = requireRunJournal(runPath);\n\tlet readiness: RecoveryInspection[\"readiness\"] = \"ready\";\n\tlet remainingVerifyMs: number | null = null;\n\ttry {\n\t\tremainingVerifyMs = assertCandidateRecoverable(runPath, journal);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tswitch (error instanceof VerifiedRunError ? error.code : \"integrity\") {\n\t\t\tcase \"resume_terminal\":\n\t\t\t\treadiness = \"terminal\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_legacy\":\n\t\t\t\treadiness = \"legacy\";\n\t\t\t\tbreak;\n\t\t\tcase \"deadline\":\n\t\t\t\treadiness = \"expired\";\n\t\t\t\tremainingVerifyMs = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"candidate_missing\":\n\t\t\t\treadiness = \"candidate_missing\";\n\t\t\t\tbreak;\n\t\t\tcase \"unsettled\":\n\t\t\t\treadiness = \"unsettled\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_changed\":\n\t\t\t\treadiness = \"clock_changed\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_rollback\":\n\t\t\t\treadiness = \"clock_rollback\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_unavailable\":\n\t\t\t\treadiness = \"clock_unavailable\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_limit\":\n\t\t\t\treadiness = \"recovery_limit\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treadiness = \"integrity\";\n\t\t}\n\t}\n\treturn Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: \"lease_required\" });\n}\n\nexport async function resumeFrozenCandidate(\n\trunPath: string,\n\tcommand: RunResumeCommand,\n\tsignal?: AbortSignal,\n): Promise<RunProjection> {\n\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\treturn withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tconst first = snapshot.records[0]?.event;\n\t\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\t\tpreflightCheckReceipts(first.contract);\n\t\tprobeVerifiedSandbox();\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tjournal.append({\n\t\t\tkind: \"resumed\",\n\t\t\tcommand,\n\t\t\tobservedMs: readRunClock().nowMs,\n\t\t\treconciledExecutionIds: snapshot.state.activeExecutionIds,\n\t\t});\n\t\treturn verifyCandidate({ runPath, journal, contract: first.contract, ...(signal ? { signal } : {}) });\n\t});\n}\n"]}
@@ -0,0 +1,115 @@
1
+ import { join } from "node:path";
2
+ import { MAX_VERIFIED_RUN_GENERATIONS } from "omk-protocol";
3
+ import { commandEnvironmentDigest, probeVerifiedSandbox } from "./broker.js";
4
+ import { loadCandidate } from "./candidate.js";
5
+ import { preflightCheckReceipts } from "./check-receipt.js";
6
+ import { probeNamespace } from "./namespace-identity.js";
7
+ import { readRunClock, remainingVerification } from "./recovery-clock.js";
8
+ import { requireRunJournal, withRecoveryLease } from "./recovery-command.js";
9
+ import { readRegularFile, VerifiedRunError } from "./storage.js";
10
+ import { verifyCandidate } from "./verification-phase.js";
11
+ function assertCandidateRecoverable(runPath, journal) {
12
+ const state = journal.state;
13
+ if (state.receiptDigest || state.execution === "failed")
14
+ throw new VerifiedRunError("resume_terminal");
15
+ if (!state.budget || !state.environmentDigest)
16
+ throw new VerifiedRunError("recovery_legacy");
17
+ if (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)
18
+ throw new VerifiedRunError("candidate_missing");
19
+ if (state.generation >= MAX_VERIFIED_RUN_GENERATIONS)
20
+ throw new VerifiedRunError("recovery_limit");
21
+ const clock = readRunClock();
22
+ const remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);
23
+ if (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs))
24
+ throw new VerifiedRunError("clock_rollback");
25
+ if (remaining <= 0)
26
+ throw new VerifiedRunError("deadline");
27
+ for (const id of state.activeExecutionIds) {
28
+ const dispatch = journal.records.find((record) => record.generation === state.generation &&
29
+ record.event.kind === "dispatch" &&
30
+ record.event.executionId === id)?.event;
31
+ const identity = state.processes.find((process) => process.executionId === id)?.identity;
32
+ if (dispatch?.kind !== "dispatch" ||
33
+ dispatch.role !== "verifier" ||
34
+ !identity ||
35
+ probeNamespace(identity) !== "gone")
36
+ throw new VerifiedRunError("unsettled");
37
+ }
38
+ const first = journal.records[0]?.event;
39
+ if (first?.kind !== "created")
40
+ throw new VerifiedRunError("integrity");
41
+ if (readRegularFile(join(runPath, "issuer.key"), 32).length !== 32)
42
+ throw new VerifiedRunError("integrity");
43
+ loadCandidate(runPath, state.candidateDigest, first.contract.budget);
44
+ if (commandEnvironmentDigest(first.contract, "gated-v1") !== state.environmentDigest)
45
+ throw new VerifiedRunError("integrity");
46
+ return remaining;
47
+ }
48
+ export function inspectRunRecovery(runPath) {
49
+ const journal = requireRunJournal(runPath);
50
+ let readiness = "ready";
51
+ let remainingVerifyMs = null;
52
+ try {
53
+ remainingVerifyMs = assertCandidateRecoverable(runPath, journal);
54
+ }
55
+ catch (error) {
56
+ if (!(error instanceof Error))
57
+ throw error;
58
+ switch (error instanceof VerifiedRunError ? error.code : "integrity") {
59
+ case "resume_terminal":
60
+ readiness = "terminal";
61
+ break;
62
+ case "recovery_legacy":
63
+ readiness = "legacy";
64
+ break;
65
+ case "deadline":
66
+ readiness = "expired";
67
+ remainingVerifyMs = 0;
68
+ break;
69
+ case "candidate_missing":
70
+ readiness = "candidate_missing";
71
+ break;
72
+ case "unsettled":
73
+ readiness = "unsettled";
74
+ break;
75
+ case "clock_changed":
76
+ readiness = "clock_changed";
77
+ break;
78
+ case "clock_rollback":
79
+ readiness = "clock_rollback";
80
+ break;
81
+ case "clock_unavailable":
82
+ readiness = "clock_unavailable";
83
+ break;
84
+ case "recovery_limit":
85
+ readiness = "recovery_limit";
86
+ break;
87
+ default:
88
+ readiness = "integrity";
89
+ }
90
+ }
91
+ return Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: "lease_required" });
92
+ }
93
+ export async function resumeFrozenCandidate(runPath, command, signal) {
94
+ if (signal?.aborted)
95
+ throw new VerifiedRunError("cancelled");
96
+ return withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {
97
+ assertCandidateRecoverable(runPath, snapshot);
98
+ const first = snapshot.records[0]?.event;
99
+ if (first?.kind !== "created")
100
+ throw new VerifiedRunError("integrity");
101
+ preflightCheckReceipts(first.contract);
102
+ probeVerifiedSandbox();
103
+ assertCandidateRecoverable(runPath, snapshot);
104
+ if (signal?.aborted)
105
+ throw new VerifiedRunError("cancelled");
106
+ journal.append({
107
+ kind: "resumed",
108
+ command,
109
+ observedMs: readRunClock().nowMs,
110
+ reconciledExecutionIds: snapshot.state.activeExecutionIds,
111
+ });
112
+ return verifyCandidate({ runPath, journal, contract: first.contract, ...(signal ? { signal } : {}) });
113
+ });
114
+ }
115
+ //# sourceMappingURL=recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.js","sourceRoot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d,IAAI,EAAE,SAAS;YACf,OAAO;YACP,UAAU,EAAE,YAAY,EAAE,CAAC,KAAK;YAChC,sBAAsB,EAAE,QAAQ,CAAC,KAAK,CAAC,kBAAkB;SACzD,CAAC,CAAC;QACH,OAAO,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAAA,CACtG,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport { MAX_VERIFIED_RUN_GENERATIONS, type RunResumeCommand } from \"omk-protocol\";\nimport { commandEnvironmentDigest, probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightCheckReceipts } from \"./check-receipt.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport { probeNamespace } from \"./namespace-identity.ts\";\nimport { readRunClock, remainingVerification } from \"./recovery-clock.ts\";\nimport { requireRunJournal, withRecoveryLease } from \"./recovery-command.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { readRegularFile, VerifiedRunError } from \"./storage.ts\";\nimport { verifyCandidate } from \"./verification-phase.ts\";\n\nexport interface RecoveryInspection {\n\treadonly state: RunProjection;\n\treadonly readiness:\n\t\t| \"ready\"\n\t\t| \"terminal\"\n\t\t| \"legacy\"\n\t\t| \"candidate_missing\"\n\t\t| \"unsettled\"\n\t\t| \"expired\"\n\t\t| \"clock_changed\"\n\t\t| \"clock_rollback\"\n\t\t| \"clock_unavailable\"\n\t\t| \"recovery_limit\"\n\t\t| \"integrity\";\n\treadonly remainingVerifyMs: number | null;\n\t/** A ready inspection is advisory; exclusive ownership is acquired only by resume. */\n\treadonly ownership: \"lease_required\";\n}\n\nfunction assertCandidateRecoverable(runPath: string, journal: JournalSnapshot): number {\n\tconst state = journal.state;\n\tif (state.receiptDigest || state.execution === \"failed\") throw new VerifiedRunError(\"resume_terminal\");\n\tif (!state.budget || !state.environmentDigest) throw new VerifiedRunError(\"recovery_legacy\");\n\tif (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)\n\t\tthrow new VerifiedRunError(\"candidate_missing\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tconst clock = readRunClock();\n\tconst remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);\n\tif (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs)) throw new VerifiedRunError(\"clock_rollback\");\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\tfor (const id of state.activeExecutionIds) {\n\t\tconst dispatch = journal.records.find(\n\t\t\t(record) =>\n\t\t\t\trecord.generation === state.generation &&\n\t\t\t\trecord.event.kind === \"dispatch\" &&\n\t\t\t\trecord.event.executionId === id,\n\t\t)?.event;\n\t\tconst identity = state.processes.find((process) => process.executionId === id)?.identity;\n\t\tif (\n\t\t\tdispatch?.kind !== \"dispatch\" ||\n\t\t\tdispatch.role !== \"verifier\" ||\n\t\t\t!identity ||\n\t\t\tprobeNamespace(identity) !== \"gone\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"unsettled\");\n\t}\n\tconst first = journal.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\tif (readRegularFile(join(runPath, \"issuer.key\"), 32).length !== 32) throw new VerifiedRunError(\"integrity\");\n\tloadCandidate(runPath, state.candidateDigest, first.contract.budget);\n\tif (commandEnvironmentDigest(first.contract, \"gated-v1\") !== state.environmentDigest)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn remaining;\n}\n\nexport function inspectRunRecovery(runPath: string): RecoveryInspection {\n\tconst journal = requireRunJournal(runPath);\n\tlet readiness: RecoveryInspection[\"readiness\"] = \"ready\";\n\tlet remainingVerifyMs: number | null = null;\n\ttry {\n\t\tremainingVerifyMs = assertCandidateRecoverable(runPath, journal);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tswitch (error instanceof VerifiedRunError ? error.code : \"integrity\") {\n\t\t\tcase \"resume_terminal\":\n\t\t\t\treadiness = \"terminal\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_legacy\":\n\t\t\t\treadiness = \"legacy\";\n\t\t\t\tbreak;\n\t\t\tcase \"deadline\":\n\t\t\t\treadiness = \"expired\";\n\t\t\t\tremainingVerifyMs = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"candidate_missing\":\n\t\t\t\treadiness = \"candidate_missing\";\n\t\t\t\tbreak;\n\t\t\tcase \"unsettled\":\n\t\t\t\treadiness = \"unsettled\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_changed\":\n\t\t\t\treadiness = \"clock_changed\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_rollback\":\n\t\t\t\treadiness = \"clock_rollback\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_unavailable\":\n\t\t\t\treadiness = \"clock_unavailable\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_limit\":\n\t\t\t\treadiness = \"recovery_limit\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treadiness = \"integrity\";\n\t\t}\n\t}\n\treturn Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: \"lease_required\" });\n}\n\nexport async function resumeFrozenCandidate(\n\trunPath: string,\n\tcommand: RunResumeCommand,\n\tsignal?: AbortSignal,\n): Promise<RunProjection> {\n\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\treturn withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tconst first = snapshot.records[0]?.event;\n\t\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\t\tpreflightCheckReceipts(first.contract);\n\t\tprobeVerifiedSandbox();\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tjournal.append({\n\t\t\tkind: \"resumed\",\n\t\t\tcommand,\n\t\t\tobservedMs: readRunClock().nowMs,\n\t\t\treconciledExecutionIds: snapshot.state.activeExecutionIds,\n\t\t});\n\t\treturn verifyCandidate({ runPath, journal, contract: first.contract, ...(signal ? { signal } : {}) });\n\t});\n}\n"]}
@@ -0,0 +1,103 @@
1
+ import type { RunContract, RunResumeCommand, RunStartCommand, RunTaskRetryCommand, RunWriterRestartCommand } from "omk-protocol";
2
+ import type { DagEvent, RunTaskCheckpoint, RunTaskProjection } from "./dag-types.ts";
3
+ import type { NamespaceIdentity } from "./namespace-identity.ts";
4
+ import type { RecoveryBudget } from "./recovery-clock.ts";
5
+ export type RunEvent = DagEvent | {
6
+ readonly kind: "created";
7
+ readonly contract: RunContract;
8
+ readonly command: RunStartCommand;
9
+ } | {
10
+ readonly kind: "budget_anchored";
11
+ readonly budget: RecoveryBudget;
12
+ readonly environmentDigest: string;
13
+ readonly driver: "linux-pidns-gate-v1";
14
+ } | {
15
+ readonly kind: "dispatch";
16
+ readonly executionId: string;
17
+ readonly role: "writer" | "verifier";
18
+ readonly claimId: string | null;
19
+ } | {
20
+ readonly kind: "input_checkpoint";
21
+ readonly digest: string;
22
+ } | {
23
+ readonly kind: "process_ready";
24
+ readonly executionId: string;
25
+ readonly identity: NamespaceIdentity;
26
+ } | {
27
+ readonly kind: "writer_opened";
28
+ } | {
29
+ readonly kind: "model_request";
30
+ readonly requestId: string;
31
+ } | {
32
+ readonly kind: "writer_closed";
33
+ readonly completed: boolean;
34
+ } | {
35
+ readonly kind: "exited";
36
+ readonly executionId: string;
37
+ readonly failure: string | null;
38
+ } | {
39
+ readonly kind: "candidate";
40
+ readonly digest: string;
41
+ readonly observedMs?: number;
42
+ readonly verificationDeadlineMs?: number;
43
+ } | {
44
+ readonly kind: "resumed";
45
+ readonly command: RunResumeCommand;
46
+ readonly observedMs: number;
47
+ readonly reconciledExecutionIds: readonly string[];
48
+ } | {
49
+ readonly kind: "writer_restarted";
50
+ readonly command: RunWriterRestartCommand;
51
+ readonly observedMs: number;
52
+ readonly reconciledExecutionIds: readonly string[];
53
+ } | {
54
+ readonly kind: "tasks_retried";
55
+ readonly command: RunTaskRetryCommand;
56
+ readonly observedMs: number;
57
+ readonly reconciledExecutionIds: readonly string[];
58
+ readonly adopted: readonly RunTaskCheckpoint[];
59
+ } | {
60
+ readonly kind: "evaluated";
61
+ readonly receiptDigest: string;
62
+ readonly verified: boolean;
63
+ } | {
64
+ readonly kind: "failed";
65
+ readonly code: string;
66
+ };
67
+ export interface RunProjection {
68
+ readonly runId: string;
69
+ readonly revision: number;
70
+ readonly generation: number;
71
+ readonly execution: "ready" | "running" | "paused" | "succeeded" | "failed";
72
+ readonly settlement: "open" | "draining" | "settled" | "quarantined";
73
+ readonly verification: "not_requested" | "verified" | "violated" | "inconclusive";
74
+ readonly application: "not_requested" | "candidate_ready";
75
+ readonly candidateDigest: string | null;
76
+ readonly inputDigest: string | null;
77
+ readonly receiptDigest: string | null;
78
+ readonly failure: string | null;
79
+ readonly activeExecutionIds: readonly string[];
80
+ readonly writerOpen: boolean;
81
+ readonly modelRequests: number;
82
+ readonly tasks: readonly RunTaskProjection[];
83
+ readonly budget: RecoveryBudget | null;
84
+ readonly environmentDigest: string | null;
85
+ readonly verificationDeadlineMs: number | null;
86
+ readonly lastClockMs: number | null;
87
+ readonly processes: readonly {
88
+ readonly executionId: string;
89
+ readonly identity: NamespaceIdentity;
90
+ }[];
91
+ }
92
+ /** Mutable reduction bookkeeping, confined to one replay call. */
93
+ export interface WriterReduction {
94
+ readonly contract: RunContract;
95
+ state: RunProjection;
96
+ writerFinished: boolean;
97
+ writerStarted: boolean;
98
+ producerStarted: boolean;
99
+ writerCommands: number;
100
+ requestBaseline: number;
101
+ readonly requests: Set<string>;
102
+ }
103
+ //# sourceMappingURL=run-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,SAAS;QAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;KAAE,EAAE,CAAC;CACtG;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B","sourcesContent":["import type {\n\tRunContract,\n\tRunResumeCommand,\n\tRunStartCommand,\n\tRunTaskRetryCommand,\n\tRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { DagEvent, RunTaskCheckpoint, RunTaskProjection } from \"./dag-types.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport type { RecoveryBudget } from \"./recovery-clock.ts\";\n\nexport type RunEvent =\n\t| DagEvent\n\t| { readonly kind: \"created\"; readonly contract: RunContract; readonly command: RunStartCommand }\n\t| {\n\t\t\treadonly kind: \"budget_anchored\";\n\t\t\treadonly budget: RecoveryBudget;\n\t\t\treadonly environmentDigest: string;\n\t\t\treadonly driver: \"linux-pidns-gate-v1\";\n\t }\n\t| {\n\t\t\treadonly kind: \"dispatch\";\n\t\t\treadonly executionId: string;\n\t\t\treadonly role: \"writer\" | \"verifier\";\n\t\t\treadonly claimId: string | null;\n\t }\n\t| { readonly kind: \"input_checkpoint\"; readonly digest: string }\n\t| { readonly kind: \"process_ready\"; readonly executionId: string; readonly identity: NamespaceIdentity }\n\t| { readonly kind: \"writer_opened\" }\n\t| { readonly kind: \"model_request\"; readonly requestId: string }\n\t| { readonly kind: \"writer_closed\"; readonly completed: boolean }\n\t| { readonly kind: \"exited\"; readonly executionId: string; readonly failure: string | null }\n\t| {\n\t\t\treadonly kind: \"candidate\";\n\t\t\treadonly digest: string;\n\t\t\treadonly observedMs?: number;\n\t\t\treadonly verificationDeadlineMs?: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"resumed\";\n\t\t\treadonly command: RunResumeCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t }\n\t| {\n\t\t\treadonly kind: \"writer_restarted\";\n\t\t\treadonly command: RunWriterRestartCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t }\n\t| {\n\t\t\treadonly kind: \"tasks_retried\";\n\t\t\treadonly command: RunTaskRetryCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t\t\treadonly adopted: readonly RunTaskCheckpoint[];\n\t }\n\t| { readonly kind: \"evaluated\"; readonly receiptDigest: string; readonly verified: boolean }\n\t| { readonly kind: \"failed\"; readonly code: string };\n\nexport interface RunProjection {\n\treadonly runId: string;\n\treadonly revision: number;\n\treadonly generation: number;\n\treadonly execution: \"ready\" | \"running\" | \"paused\" | \"succeeded\" | \"failed\";\n\treadonly settlement: \"open\" | \"draining\" | \"settled\" | \"quarantined\";\n\treadonly verification: \"not_requested\" | \"verified\" | \"violated\" | \"inconclusive\";\n\treadonly application: \"not_requested\" | \"candidate_ready\";\n\treadonly candidateDigest: string | null;\n\treadonly inputDigest: string | null;\n\treadonly receiptDigest: string | null;\n\treadonly failure: string | null;\n\treadonly activeExecutionIds: readonly string[];\n\treadonly writerOpen: boolean;\n\treadonly modelRequests: number;\n\treadonly tasks: readonly RunTaskProjection[];\n\treadonly budget: RecoveryBudget | null;\n\treadonly environmentDigest: string | null;\n\treadonly verificationDeadlineMs: number | null;\n\treadonly lastClockMs: number | null;\n\treadonly processes: readonly { readonly executionId: string; readonly identity: NamespaceIdentity }[];\n}\n\n/** Mutable reduction bookkeeping, confined to one replay call. */\nexport interface WriterReduction {\n\treadonly contract: RunContract;\n\tstate: RunProjection;\n\twriterFinished: boolean;\n\twriterStarted: boolean;\n\tproducerStarted: boolean;\n\twriterCommands: number;\n\trequestBaseline: number;\n\treadonly requests: Set<string>;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-types.js","sourceRoot":"","sources":["../../../src/core/verified-run/run-types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n\tRunContract,\n\tRunResumeCommand,\n\tRunStartCommand,\n\tRunTaskRetryCommand,\n\tRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { DagEvent, RunTaskCheckpoint, RunTaskProjection } from \"./dag-types.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport type { RecoveryBudget } from \"./recovery-clock.ts\";\n\nexport type RunEvent =\n\t| DagEvent\n\t| { readonly kind: \"created\"; readonly contract: RunContract; readonly command: RunStartCommand }\n\t| {\n\t\t\treadonly kind: \"budget_anchored\";\n\t\t\treadonly budget: RecoveryBudget;\n\t\t\treadonly environmentDigest: string;\n\t\t\treadonly driver: \"linux-pidns-gate-v1\";\n\t }\n\t| {\n\t\t\treadonly kind: \"dispatch\";\n\t\t\treadonly executionId: string;\n\t\t\treadonly role: \"writer\" | \"verifier\";\n\t\t\treadonly claimId: string | null;\n\t }\n\t| { readonly kind: \"input_checkpoint\"; readonly digest: string }\n\t| { readonly kind: \"process_ready\"; readonly executionId: string; readonly identity: NamespaceIdentity }\n\t| { readonly kind: \"writer_opened\" }\n\t| { readonly kind: \"model_request\"; readonly requestId: string }\n\t| { readonly kind: \"writer_closed\"; readonly completed: boolean }\n\t| { readonly kind: \"exited\"; readonly executionId: string; readonly failure: string | null }\n\t| {\n\t\t\treadonly kind: \"candidate\";\n\t\t\treadonly digest: string;\n\t\t\treadonly observedMs?: number;\n\t\t\treadonly verificationDeadlineMs?: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"resumed\";\n\t\t\treadonly command: RunResumeCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t }\n\t| {\n\t\t\treadonly kind: \"writer_restarted\";\n\t\t\treadonly command: RunWriterRestartCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t }\n\t| {\n\t\t\treadonly kind: \"tasks_retried\";\n\t\t\treadonly command: RunTaskRetryCommand;\n\t\t\treadonly observedMs: number;\n\t\t\treadonly reconciledExecutionIds: readonly string[];\n\t\t\treadonly adopted: readonly RunTaskCheckpoint[];\n\t }\n\t| { readonly kind: \"evaluated\"; readonly receiptDigest: string; readonly verified: boolean }\n\t| { readonly kind: \"failed\"; readonly code: string };\n\nexport interface RunProjection {\n\treadonly runId: string;\n\treadonly revision: number;\n\treadonly generation: number;\n\treadonly execution: \"ready\" | \"running\" | \"paused\" | \"succeeded\" | \"failed\";\n\treadonly settlement: \"open\" | \"draining\" | \"settled\" | \"quarantined\";\n\treadonly verification: \"not_requested\" | \"verified\" | \"violated\" | \"inconclusive\";\n\treadonly application: \"not_requested\" | \"candidate_ready\";\n\treadonly candidateDigest: string | null;\n\treadonly inputDigest: string | null;\n\treadonly receiptDigest: string | null;\n\treadonly failure: string | null;\n\treadonly activeExecutionIds: readonly string[];\n\treadonly writerOpen: boolean;\n\treadonly modelRequests: number;\n\treadonly tasks: readonly RunTaskProjection[];\n\treadonly budget: RecoveryBudget | null;\n\treadonly environmentDigest: string | null;\n\treadonly verificationDeadlineMs: number | null;\n\treadonly lastClockMs: number | null;\n\treadonly processes: readonly { readonly executionId: string; readonly identity: NamespaceIdentity }[];\n}\n\n/** Mutable reduction bookkeeping, confined to one replay call. */\nexport interface WriterReduction {\n\treadonly contract: RunContract;\n\tstate: RunProjection;\n\twriterFinished: boolean;\n\twriterStarted: boolean;\n\tproducerStarted: boolean;\n\twriterCommands: number;\n\trequestBaseline: number;\n\treadonly requests: Set<string>;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { RunScriptedWriter } from "omk-protocol";
2
+ import type { OwnedRunResult } from "./owned-execution.ts";
3
+ import type { VerifiedRunRuntime } from "./session-port.ts";
4
+ export interface ScriptedWriterContext {
5
+ readonly runtime: VerifiedRunRuntime;
6
+ readonly workspace: string;
7
+ readonly deadline: number;
8
+ readonly requestLimit: number;
9
+ readonly signal?: AbortSignal;
10
+ readonly beforeRequest: () => void;
11
+ readonly executeStep: (index: number, signal?: AbortSignal) => Promise<OwnedRunResult>;
12
+ }
13
+ /** Offline reference adapter. The real AgentSession is trusted host code; every command stays in bwrap. */
14
+ export declare function executeScriptedWriter(writer: RunScriptedWriter, goal: string, context: ScriptedWriterContext): Promise<void>;
15
+ //# sourceMappingURL=scripted-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripted-writer.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/scripted-writer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,mBAAmB,CAAC;AAGhF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,IAAI,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACvF;AAED,2GAA2G;AAC3G,wBAAsB,qBAAqB,CAC1C,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA8Ef","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { Agent, type AgentTool } from \"omk-agent-core\";\nimport { fauxAssistantMessage, fauxToolCall, registerFauxProvider, streamSimple } from \"omk-ai\";\nimport type { RunScriptedWriter } from \"omk-protocol\";\nimport { Type } from \"typebox\";\nimport { convertToLlm } from \"../messages.ts\";\nimport { RunBudgetExceededError } from \"../run-budget-policy.ts\";\nimport type { OwnedRunResult } from \"./owned-execution.ts\";\nimport type { VerifiedRunRuntime, VerifiedRunSession } from \"./session-port.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface ScriptedWriterContext {\n\treadonly runtime: VerifiedRunRuntime;\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly requestLimit: number;\n\treadonly signal?: AbortSignal;\n\treadonly beforeRequest: () => void;\n\treadonly executeStep: (index: number, signal?: AbortSignal) => Promise<OwnedRunResult>;\n}\n\n/** Offline reference adapter. The real AgentSession is trusted host code; every command stays in bwrap. */\nexport async function executeScriptedWriter(\n\twriter: RunScriptedWriter,\n\tgoal: string,\n\tcontext: ScriptedWriterContext,\n): Promise<void> {\n\tif (context.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst faux = registerFauxProvider({ provider: `verified-scripted-${randomUUID()}` });\n\tlet session: VerifiedRunSession | undefined;\n\tlet failure: unknown;\n\tlet completedSteps = 0;\n\tconst cancel = (): void => session?.agent.abort();\n\ttry {\n\t\tconst model = faux.getModel();\n\t\tconst schema = Type.Object(\n\t\t\t{ index: Type.Integer({ minimum: 0, maximum: writer.steps.length - 1 }) },\n\t\t\t{ additionalProperties: false },\n\t\t);\n\t\tconst tool: AgentTool<typeof schema> = {\n\t\t\tname: \"verified_step\",\n\t\t\tlabel: \"Execute approved step\",\n\t\t\tdescription: \"Execute one contract-approved step in order.\",\n\t\t\tparameters: schema,\n\t\t\texecute: async (_id, args, signal) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (failure || args.index !== completedSteps || !writer.steps[args.index])\n\t\t\t\t\t\tthrow new VerifiedRunError(\"writer_step\");\n\t\t\t\t\tconst { result } = await context.executeStep(args.index, signal);\n\t\t\t\t\tif (result.failure) throw new VerifiedRunError(result.failure);\n\t\t\t\t\tcompletedSteps += 1;\n\t\t\t\t\treturn { content: [{ type: \"text\", text: result.stdout.toString(\"utf8\") }], details: {} };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailure = error;\n\t\t\t\t\tcancel();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tfaux.setResponses([\n\t\t\t...writer.steps.map((_step, index) => fauxAssistantMessage(fauxToolCall(tool.name, { index }))),\n\t\t\tfauxAssistantMessage(\"Contracted steps finished; only the supervisor may verify the candidate.\"),\n\t\t]);\n\t\tconst agent = new Agent({\n\t\t\tinitialState: { model, tools: [] },\n\t\t\tconvertToLlm,\n\t\t\tgetApiKey: () => \"synthetic-local-only\",\n\t\t\tstreamFn: (selected, input, options) => {\n\t\t\t\tcontext.beforeRequest();\n\t\t\t\treturn streamSimple(selected, input, options);\n\t\t\t},\n\t\t});\n\t\tsession = context.runtime.createSession({ agent, tool, workspace: context.workspace });\n\t\tcontext.signal?.addEventListener(\"abort\", cancel, { once: true });\n\t\tif (context.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tconst remaining = Math.floor(context.deadline - performance.now());\n\t\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\t\tawait session.prompt(goal, {\n\t\t\texpandPromptTemplates: false,\n\t\t\trunBudget: { timeoutMs: remaining, maxRequests: context.requestLimit, maxConcurrentRequests: 1 },\n\t\t});\n\t\tif (failure) throw failure;\n\t\tif (\n\t\t\tcompletedSteps !== writer.steps.length ||\n\t\t\tsession.lastTermination?.kind !== \"completed\" ||\n\t\t\tsession.getRunBudgetSnapshot()?.activeRequests !== 0\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"writer_incomplete\");\n\t} catch (error) {\n\t\tif (failure instanceof VerifiedRunError) throw failure;\n\t\tif (error instanceof RunBudgetExceededError)\n\t\t\tthrow new VerifiedRunError(error.code === \"requests\" ? \"model_request_limit\" : \"deadline\");\n\t\tthrow error;\n\t} finally {\n\t\tcontext.signal?.removeEventListener(\"abort\", cancel);\n\t\ttry {\n\t\t\tif (session) {\n\t\t\t\tawait session.abort();\n\t\t\t\tsession.dispose();\n\t\t\t}\n\t\t} finally {\n\t\t\tfaux.unregister();\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,94 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { performance } from "node:perf_hooks";
3
+ import { Agent } from "omk-agent-core";
4
+ import { fauxAssistantMessage, fauxToolCall, registerFauxProvider, streamSimple } from "omk-ai";
5
+ import { Type } from "typebox";
6
+ import { convertToLlm } from "../messages.js";
7
+ import { RunBudgetExceededError } from "../run-budget-policy.js";
8
+ import { VerifiedRunError } from "./storage.js";
9
+ /** Offline reference adapter. The real AgentSession is trusted host code; every command stays in bwrap. */
10
+ export async function executeScriptedWriter(writer, goal, context) {
11
+ if (context.signal?.aborted)
12
+ throw new VerifiedRunError("cancelled");
13
+ const faux = registerFauxProvider({ provider: `verified-scripted-${randomUUID()}` });
14
+ let session;
15
+ let failure;
16
+ let completedSteps = 0;
17
+ const cancel = () => session?.agent.abort();
18
+ try {
19
+ const model = faux.getModel();
20
+ const schema = Type.Object({ index: Type.Integer({ minimum: 0, maximum: writer.steps.length - 1 }) }, { additionalProperties: false });
21
+ const tool = {
22
+ name: "verified_step",
23
+ label: "Execute approved step",
24
+ description: "Execute one contract-approved step in order.",
25
+ parameters: schema,
26
+ execute: async (_id, args, signal) => {
27
+ try {
28
+ if (failure || args.index !== completedSteps || !writer.steps[args.index])
29
+ throw new VerifiedRunError("writer_step");
30
+ const { result } = await context.executeStep(args.index, signal);
31
+ if (result.failure)
32
+ throw new VerifiedRunError(result.failure);
33
+ completedSteps += 1;
34
+ return { content: [{ type: "text", text: result.stdout.toString("utf8") }], details: {} };
35
+ }
36
+ catch (error) {
37
+ failure = error;
38
+ cancel();
39
+ throw error;
40
+ }
41
+ },
42
+ };
43
+ faux.setResponses([
44
+ ...writer.steps.map((_step, index) => fauxAssistantMessage(fauxToolCall(tool.name, { index }))),
45
+ fauxAssistantMessage("Contracted steps finished; only the supervisor may verify the candidate."),
46
+ ]);
47
+ const agent = new Agent({
48
+ initialState: { model, tools: [] },
49
+ convertToLlm,
50
+ getApiKey: () => "synthetic-local-only",
51
+ streamFn: (selected, input, options) => {
52
+ context.beforeRequest();
53
+ return streamSimple(selected, input, options);
54
+ },
55
+ });
56
+ session = context.runtime.createSession({ agent, tool, workspace: context.workspace });
57
+ context.signal?.addEventListener("abort", cancel, { once: true });
58
+ if (context.signal?.aborted)
59
+ throw new VerifiedRunError("cancelled");
60
+ const remaining = Math.floor(context.deadline - performance.now());
61
+ if (remaining <= 0)
62
+ throw new VerifiedRunError("deadline");
63
+ await session.prompt(goal, {
64
+ expandPromptTemplates: false,
65
+ runBudget: { timeoutMs: remaining, maxRequests: context.requestLimit, maxConcurrentRequests: 1 },
66
+ });
67
+ if (failure)
68
+ throw failure;
69
+ if (completedSteps !== writer.steps.length ||
70
+ session.lastTermination?.kind !== "completed" ||
71
+ session.getRunBudgetSnapshot()?.activeRequests !== 0)
72
+ throw new VerifiedRunError("writer_incomplete");
73
+ }
74
+ catch (error) {
75
+ if (failure instanceof VerifiedRunError)
76
+ throw failure;
77
+ if (error instanceof RunBudgetExceededError)
78
+ throw new VerifiedRunError(error.code === "requests" ? "model_request_limit" : "deadline");
79
+ throw error;
80
+ }
81
+ finally {
82
+ context.signal?.removeEventListener("abort", cancel);
83
+ try {
84
+ if (session) {
85
+ await session.abort();
86
+ session.dispose();
87
+ }
88
+ }
89
+ finally {
90
+ faux.unregister();
91
+ }
92
+ }
93
+ }
94
+ //# sourceMappingURL=scripted-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripted-writer.js","sourceRoot":"","sources":["../../../src/core/verified-run/scripted-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEhG,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAYhD,2GAA2G;AAC3G,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,MAAyB,EACzB,IAAY,EACZ,OAA8B,EACd;IAChB,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACrE,MAAM,IAAI,GAAG,oBAAoB,CAAC,EAAE,QAAQ,EAAE,qBAAqB,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IACrF,IAAI,OAAuC,CAAC;IAC5C,IAAI,OAAgB,CAAC;IACrB,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,MAAM,MAAM,GAAG,GAA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BAAgB,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;YAC1B,qBAAqB,EAAE,KAAK;YAC5B,SAAS,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,CAAC,YAAY,EAAE,qBAAqB,EAAE,CAAC,EAAE;SAChG,CAAC,CAAC;QACH,IAAI,OAAO;YAAE,MAAM,OAAO,CAAC;QAC3B,IACC,cAAc,KAAK,MAAM,CAAC,KAAK,CAAC,MAAM;YACtC,OAAO,CAAC,eAAe,EAAE,IAAI,KAAK,WAAW;YAC7C,OAAO,CAAC,oBAAoB,EAAE,EAAE,cAAc,KAAK,CAAC;YAEpD,MAAM,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,OAAO,YAAY,gBAAgB;YAAE,MAAM,OAAO,CAAC;QACvD,IAAI,KAAK,YAAY,sBAAsB;YAC1C,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC5F,MAAM,KAAK,CAAC;IACb,CAAC;YAAS,CAAC;QACV,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC;YACJ,IAAI,OAAO,EAAE,CAAC;gBACb,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,OAAO,EAAE,CAAC;YACnB,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,UAAU,EAAE,CAAC;QACnB,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { Agent, type AgentTool } from \"omk-agent-core\";\nimport { fauxAssistantMessage, fauxToolCall, registerFauxProvider, streamSimple } from \"omk-ai\";\nimport type { RunScriptedWriter } from \"omk-protocol\";\nimport { Type } from \"typebox\";\nimport { convertToLlm } from \"../messages.ts\";\nimport { RunBudgetExceededError } from \"../run-budget-policy.ts\";\nimport type { OwnedRunResult } from \"./owned-execution.ts\";\nimport type { VerifiedRunRuntime, VerifiedRunSession } from \"./session-port.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface ScriptedWriterContext {\n\treadonly runtime: VerifiedRunRuntime;\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly requestLimit: number;\n\treadonly signal?: AbortSignal;\n\treadonly beforeRequest: () => void;\n\treadonly executeStep: (index: number, signal?: AbortSignal) => Promise<OwnedRunResult>;\n}\n\n/** Offline reference adapter. The real AgentSession is trusted host code; every command stays in bwrap. */\nexport async function executeScriptedWriter(\n\twriter: RunScriptedWriter,\n\tgoal: string,\n\tcontext: ScriptedWriterContext,\n): Promise<void> {\n\tif (context.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst faux = registerFauxProvider({ provider: `verified-scripted-${randomUUID()}` });\n\tlet session: VerifiedRunSession | undefined;\n\tlet failure: unknown;\n\tlet completedSteps = 0;\n\tconst cancel = (): void => session?.agent.abort();\n\ttry {\n\t\tconst model = faux.getModel();\n\t\tconst schema = Type.Object(\n\t\t\t{ index: Type.Integer({ minimum: 0, maximum: writer.steps.length - 1 }) },\n\t\t\t{ additionalProperties: false },\n\t\t);\n\t\tconst tool: AgentTool<typeof schema> = {\n\t\t\tname: \"verified_step\",\n\t\t\tlabel: \"Execute approved step\",\n\t\t\tdescription: \"Execute one contract-approved step in order.\",\n\t\t\tparameters: schema,\n\t\t\texecute: async (_id, args, signal) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (failure || args.index !== completedSteps || !writer.steps[args.index])\n\t\t\t\t\t\tthrow new VerifiedRunError(\"writer_step\");\n\t\t\t\t\tconst { result } = await context.executeStep(args.index, signal);\n\t\t\t\t\tif (result.failure) throw new VerifiedRunError(result.failure);\n\t\t\t\t\tcompletedSteps += 1;\n\t\t\t\t\treturn { content: [{ type: \"text\", text: result.stdout.toString(\"utf8\") }], details: {} };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailure = error;\n\t\t\t\t\tcancel();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tfaux.setResponses([\n\t\t\t...writer.steps.map((_step, index) => fauxAssistantMessage(fauxToolCall(tool.name, { index }))),\n\t\t\tfauxAssistantMessage(\"Contracted steps finished; only the supervisor may verify the candidate.\"),\n\t\t]);\n\t\tconst agent = new Agent({\n\t\t\tinitialState: { model, tools: [] },\n\t\t\tconvertToLlm,\n\t\t\tgetApiKey: () => \"synthetic-local-only\",\n\t\t\tstreamFn: (selected, input, options) => {\n\t\t\t\tcontext.beforeRequest();\n\t\t\t\treturn streamSimple(selected, input, options);\n\t\t\t},\n\t\t});\n\t\tsession = context.runtime.createSession({ agent, tool, workspace: context.workspace });\n\t\tcontext.signal?.addEventListener(\"abort\", cancel, { once: true });\n\t\tif (context.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tconst remaining = Math.floor(context.deadline - performance.now());\n\t\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\t\tawait session.prompt(goal, {\n\t\t\texpandPromptTemplates: false,\n\t\t\trunBudget: { timeoutMs: remaining, maxRequests: context.requestLimit, maxConcurrentRequests: 1 },\n\t\t});\n\t\tif (failure) throw failure;\n\t\tif (\n\t\t\tcompletedSteps !== writer.steps.length ||\n\t\t\tsession.lastTermination?.kind !== \"completed\" ||\n\t\t\tsession.getRunBudgetSnapshot()?.activeRequests !== 0\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"writer_incomplete\");\n\t} catch (error) {\n\t\tif (failure instanceof VerifiedRunError) throw failure;\n\t\tif (error instanceof RunBudgetExceededError)\n\t\t\tthrow new VerifiedRunError(error.code === \"requests\" ? \"model_request_limit\" : \"deadline\");\n\t\tthrow error;\n\t} finally {\n\t\tcontext.signal?.removeEventListener(\"abort\", cancel);\n\t\ttry {\n\t\t\tif (session) {\n\t\t\t\tawait session.abort();\n\t\t\t\tsession.dispose();\n\t\t\t}\n\t\t} finally {\n\t\t\tfaux.unregister();\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { Agent, AgentTool } from "omk-agent-core";
2
+ import type { RunBudgetLimits } from "../run-budget-policy.ts";
3
+ /** Host composition port: not accepted from a contract, worker message or RPC payload. */
4
+ export interface VerifiedRunSession {
5
+ readonly agent: Pick<Agent, "abort">;
6
+ readonly lastTermination?: {
7
+ readonly kind: string;
8
+ };
9
+ prompt(goal: string, options: {
10
+ readonly expandPromptTemplates: false;
11
+ readonly runBudget: RunBudgetLimits;
12
+ }): Promise<void>;
13
+ getRunBudgetSnapshot(): {
14
+ readonly activeRequests: number;
15
+ } | undefined;
16
+ abort(): Promise<void>;
17
+ dispose(): void;
18
+ }
19
+ export interface VerifiedRunSessionInput {
20
+ readonly agent: Agent;
21
+ readonly tool: AgentTool;
22
+ readonly workspace: string;
23
+ }
24
+ export interface VerifiedRunRuntime {
25
+ readonly createSession: (input: VerifiedRunSessionInput) => VerifiedRunSession;
26
+ }
27
+ //# sourceMappingURL=session-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-port.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/session-port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,0FAA0F;AAC1F,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,MAAM,CACL,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,QAAQ,CAAC,qBAAqB,EAAE,KAAK,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAA;KAAE,GACrF,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,oBAAoB,IAAI;QAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CAChB;AACD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AACD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,kBAAkB,CAAC;CAC/E","sourcesContent":["import type { Agent, AgentTool } from \"omk-agent-core\";\nimport type { RunBudgetLimits } from \"../run-budget-policy.ts\";\n\n/** Host composition port: not accepted from a contract, worker message or RPC payload. */\nexport interface VerifiedRunSession {\n\treadonly agent: Pick<Agent, \"abort\">;\n\treadonly lastTermination?: { readonly kind: string };\n\tprompt(\n\t\tgoal: string,\n\t\toptions: { readonly expandPromptTemplates: false; readonly runBudget: RunBudgetLimits },\n\t): Promise<void>;\n\tgetRunBudgetSnapshot(): { readonly activeRequests: number } | undefined;\n\tabort(): Promise<void>;\n\tdispose(): void;\n}\nexport interface VerifiedRunSessionInput {\n\treadonly agent: Agent;\n\treadonly tool: AgentTool;\n\treadonly workspace: string;\n}\nexport interface VerifiedRunRuntime {\n\treadonly createSession: (input: VerifiedRunSessionInput) => VerifiedRunSession;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=session-port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-port.js","sourceRoot":"","sources":["../../../src/core/verified-run/session-port.ts"],"names":[],"mappings":"","sourcesContent":["import type { Agent, AgentTool } from \"omk-agent-core\";\nimport type { RunBudgetLimits } from \"../run-budget-policy.ts\";\n\n/** Host composition port: not accepted from a contract, worker message or RPC payload. */\nexport interface VerifiedRunSession {\n\treadonly agent: Pick<Agent, \"abort\">;\n\treadonly lastTermination?: { readonly kind: string };\n\tprompt(\n\t\tgoal: string,\n\t\toptions: { readonly expandPromptTemplates: false; readonly runBudget: RunBudgetLimits },\n\t): Promise<void>;\n\tgetRunBudgetSnapshot(): { readonly activeRequests: number } | undefined;\n\tabort(): Promise<void>;\n\tdispose(): void;\n}\nexport interface VerifiedRunSessionInput {\n\treadonly agent: Agent;\n\treadonly tool: AgentTool;\n\treadonly workspace: string;\n}\nexport interface VerifiedRunRuntime {\n\treadonly createSession: (input: VerifiedRunSessionInput) => VerifiedRunSession;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ export declare class VerifiedRunError extends Error {
2
+ readonly code: string;
3
+ constructor(code: string);
4
+ }
5
+ export declare const digestBytes: (bytes: string | Uint8Array<ArrayBufferLike>) => string;
6
+ export declare const digestObject: (value: unknown) => string;
7
+ export declare function readRegularFile(path: string, maxBytes: number): Buffer;
8
+ export declare function readJson(path: string, maxBytes?: number): unknown;
9
+ export declare function publishBytes(path: string, bytes: Uint8Array): void;
10
+ export declare function publishObject(path: string, value: unknown): string;
11
+ /** Resolve existing parents without creating state. State must never be part of a mounted workspace. */
12
+ export declare function stateRunPath(root: string, id: string): string;
13
+ export declare function assertStateOutsideWorkspace(stateRoot: string, workspace: string): void;
14
+ export declare function assertDirectory(path: string): void;
15
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/storage.ts"],"names":[],"mappings":"AAMA,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,YAAY,IAAI,EAAE,MAAM,EAIvB;CACD;AAED,eAAO,MAAM,WAAW,yDAA2F,CAAC;AACpH,eAAO,MAAM,YAAY,4BAAgE,CAAC;AAE1F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAetE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAU,GAAG,OAAO,CAOlE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAOlE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAIlE;AAED,wGAAwG;AACxG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAwBtF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAElD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, realpathSync } from \"node:fs\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { writeExclusiveFileDurablySync } from \"../durable-file-io.ts\";\nimport { canonicalJson } from \"../run-journal.ts\";\n\nexport class VerifiedRunError extends Error {\n\treadonly code: string;\n\tconstructor(code: string) {\n\t\tsuper(`verified-run: ${code}`);\n\t\tthis.name = \"VerifiedRunError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport const digestBytes = (bytes: Uint8Array | string): string => createHash(\"sha256\").update(bytes).digest(\"hex\");\nexport const digestObject = (value: unknown): string => digestBytes(canonicalJson(value));\n\nexport function readRegularFile(path: string, maxBytes: number): Buffer {\n\tconst fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);\n\ttry {\n\t\tconst before = fstatSync(fd, { bigint: true });\n\t\tif (!before.isFile() || before.nlink !== 1n) throw new VerifiedRunError(\"file_type\");\n\t\tif (before.size > BigInt(maxBytes)) throw new VerifiedRunError(\"storage_limit\");\n\t\tconst bytes = readFileSync(fd);\n\t\tconst after = fstatSync(fd, { bigint: true });\n\t\tif (before.size !== after.size || before.ctimeNs !== after.ctimeNs || BigInt(bytes.length) !== before.size) {\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t}\n\t\treturn bytes;\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nexport function readJson(path: string, maxBytes = 1048576): unknown {\n\ttry {\n\t\treturn JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(readRegularFile(path, maxBytes)));\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError || error instanceof TypeError) throw new VerifiedRunError(\"integrity\");\n\t\tthrow error;\n\t}\n}\n\nexport function publishBytes(path: string, bytes: Uint8Array): void {\n\ttry {\n\t\twriteExclusiveFileDurablySync(path, bytes);\n\t} catch (error) {\n\t\tif (!(error instanceof Error && \"code\" in error && error.code === \"EEXIST\")) throw error;\n\t\tif (!readRegularFile(path, bytes.length).equals(Buffer.from(bytes))) throw new VerifiedRunError(\"integrity\");\n\t}\n}\n\nexport function publishObject(path: string, value: unknown): string {\n\tconst bytes = Buffer.from(canonicalJson(value));\n\tpublishBytes(path, bytes);\n\treturn digestBytes(bytes);\n}\n\n/** Resolve existing parents without creating state. State must never be part of a mounted workspace. */\nexport function stateRunPath(root: string, id: string): string {\n\tif (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(id)) throw new VerifiedRunError(\"run_id\");\n\treturn join(resolve(root), id);\n}\n\nexport function assertStateOutsideWorkspace(stateRoot: string, workspace: string): void {\n\tlet cursor = resolve(stateRoot);\n\tconst tail: string[] = [];\n\twhile (true) {\n\t\ttry {\n\t\t\tcursor = join(realpathSync(cursor), ...tail);\n\t\t\tbreak;\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof Error && \"code\" in error && error.code === \"ENOENT\")) throw error;\n\t\t\ttail.unshift(basename(cursor));\n\t\t\tcursor = dirname(cursor);\n\t\t}\n\t}\n\tconst base = realpathSync(workspace);\n\tconst under = relative(base, cursor);\n\tconst contains = relative(cursor, base);\n\tif (\n\t\tunder === \"\" ||\n\t\t(!under.startsWith(\"../\") && under !== \"..\") ||\n\t\tcontains === \"\" ||\n\t\t(!contains.startsWith(\"../\") && contains !== \"..\")\n\t) {\n\t\tthrow new VerifiedRunError(\"state_scope\");\n\t}\n}\n\nexport function assertDirectory(path: string): void {\n\tif (!lstatSync(path).isDirectory() || realpathSync(path) !== resolve(path)) throw new VerifiedRunError(\"file_type\");\n}\n"]}
@@ -0,0 +1,96 @@
1
+ import { createHash } from "node:crypto";
2
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, realpathSync } from "node:fs";
3
+ import { basename, dirname, join, relative, resolve } from "node:path";
4
+ import { writeExclusiveFileDurablySync } from "../durable-file-io.js";
5
+ import { canonicalJson } from "../run-journal.js";
6
+ export class VerifiedRunError extends Error {
7
+ code;
8
+ constructor(code) {
9
+ super(`verified-run: ${code}`);
10
+ this.name = "VerifiedRunError";
11
+ this.code = code;
12
+ }
13
+ }
14
+ export const digestBytes = (bytes) => createHash("sha256").update(bytes).digest("hex");
15
+ export const digestObject = (value) => digestBytes(canonicalJson(value));
16
+ export function readRegularFile(path, maxBytes) {
17
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
18
+ try {
19
+ const before = fstatSync(fd, { bigint: true });
20
+ if (!before.isFile() || before.nlink !== 1n)
21
+ throw new VerifiedRunError("file_type");
22
+ if (before.size > BigInt(maxBytes))
23
+ throw new VerifiedRunError("storage_limit");
24
+ const bytes = readFileSync(fd);
25
+ const after = fstatSync(fd, { bigint: true });
26
+ if (before.size !== after.size || before.ctimeNs !== after.ctimeNs || BigInt(bytes.length) !== before.size) {
27
+ throw new VerifiedRunError("integrity");
28
+ }
29
+ return bytes;
30
+ }
31
+ finally {
32
+ closeSync(fd);
33
+ }
34
+ }
35
+ export function readJson(path, maxBytes = 1048576) {
36
+ try {
37
+ return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(readRegularFile(path, maxBytes)));
38
+ }
39
+ catch (error) {
40
+ if (error instanceof SyntaxError || error instanceof TypeError)
41
+ throw new VerifiedRunError("integrity");
42
+ throw error;
43
+ }
44
+ }
45
+ export function publishBytes(path, bytes) {
46
+ try {
47
+ writeExclusiveFileDurablySync(path, bytes);
48
+ }
49
+ catch (error) {
50
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
51
+ throw error;
52
+ if (!readRegularFile(path, bytes.length).equals(Buffer.from(bytes)))
53
+ throw new VerifiedRunError("integrity");
54
+ }
55
+ }
56
+ export function publishObject(path, value) {
57
+ const bytes = Buffer.from(canonicalJson(value));
58
+ publishBytes(path, bytes);
59
+ return digestBytes(bytes);
60
+ }
61
+ /** Resolve existing parents without creating state. State must never be part of a mounted workspace. */
62
+ export function stateRunPath(root, id) {
63
+ if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(id))
64
+ throw new VerifiedRunError("run_id");
65
+ return join(resolve(root), id);
66
+ }
67
+ export function assertStateOutsideWorkspace(stateRoot, workspace) {
68
+ let cursor = resolve(stateRoot);
69
+ const tail = [];
70
+ while (true) {
71
+ try {
72
+ cursor = join(realpathSync(cursor), ...tail);
73
+ break;
74
+ }
75
+ catch (error) {
76
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
77
+ throw error;
78
+ tail.unshift(basename(cursor));
79
+ cursor = dirname(cursor);
80
+ }
81
+ }
82
+ const base = realpathSync(workspace);
83
+ const under = relative(base, cursor);
84
+ const contains = relative(cursor, base);
85
+ if (under === "" ||
86
+ (!under.startsWith("../") && under !== "..") ||
87
+ contains === "" ||
88
+ (!contains.startsWith("../") && contains !== "..")) {
89
+ throw new VerifiedRunError("state_scope");
90
+ }
91
+ }
92
+ export function assertDirectory(path) {
93
+ if (!lstatSync(path).isDirectory() || realpathSync(path) !== resolve(path))
94
+ throw new VerifiedRunError("file_type");
95
+ }
96
+ //# sourceMappingURL=storage.js.map