@makaio/framework 1.0.0-dev-1789000242829 → 1.0.0-dev-1789056039016

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 (288) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapters/claude/index.d.mts +60 -60
  3. package/dist/adapters/config/index.d.mts +1 -1
  4. package/dist/adapters/index.d.mts +2 -2
  5. package/dist/adapters/node.d.mts +1 -1
  6. package/dist/artifact--nbPrvm5.mjs +1 -0
  7. package/dist/attempt-control-evidence-BKw1U3wL.mjs +1 -0
  8. package/dist/bootstrap-start-client-D7t7d9ty.mjs +1 -0
  9. package/dist/bus/index.mjs +1 -1
  10. package/dist/clients/index.d.mts +1 -1
  11. package/dist/clients/managed-install.d.mts +1 -1
  12. package/dist/code-execution/worker-entry.d.mts +1 -1
  13. package/dist/contracts/adapter/index.d.mts +2 -2
  14. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  15. package/dist/contracts/artifact/index.d.mts +3 -3
  16. package/dist/contracts/artifact/index.mjs +1 -1
  17. package/dist/contracts/auth/index.d.mts +2 -2
  18. package/dist/contracts/automation-trigger/index.d.mts +3 -3
  19. package/dist/contracts/canonical-model/index.d.mts +1 -1
  20. package/dist/contracts/capabilities/index.d.mts +1 -1
  21. package/dist/contracts/client/index.d.mts +2 -2
  22. package/dist/contracts/code-execution/index.d.mts +1 -1
  23. package/dist/contracts/common/index.d.mts +1 -1
  24. package/dist/contracts/config/index.d.mts +1 -1
  25. package/dist/contracts/extension/index.d.mts +5 -5
  26. package/dist/contracts/facet/index.d.mts +1 -1
  27. package/dist/contracts/harness/index.d.mts +1 -1
  28. package/dist/contracts/host/index.d.mts +1 -1
  29. package/dist/contracts/index.d.mts +287 -61
  30. package/dist/contracts/index.mjs +1 -1
  31. package/dist/contracts/materialization/index.d.mts +2 -2
  32. package/dist/contracts/model-registry/index.d.mts +1 -1
  33. package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
  34. package/dist/contracts/platform/index.d.mts +1 -1
  35. package/dist/contracts/provider/index.d.mts +2 -2
  36. package/dist/contracts/reaction/index.d.mts +1 -1
  37. package/dist/contracts/session/index.d.mts +2 -2
  38. package/dist/contracts/shared/index.d.mts +2 -2
  39. package/dist/contracts/skill/index.d.mts +1 -1
  40. package/dist/contracts/telemetry/index.d.mts +1 -1
  41. package/dist/contracts/timeout/index.d.mts +1 -1
  42. package/dist/contracts/variant/index.d.mts +1 -1
  43. package/dist/contracts/worker/index.d.mts +3 -3
  44. package/dist/contracts/worker/index.mjs +1 -1
  45. package/dist/contracts/workflow/index.d.mts +2 -2
  46. package/dist/contracts/workflow/index.mjs +1 -1
  47. package/dist/{contribution-BfEEQ8YZ.d.mts → contribution-BWanQHUz.d.mts} +2 -2
  48. package/dist/{definition-6d5JBi55.d.mts → definition-DSOXLpQj.d.mts} +1 -1
  49. package/dist/{detached-extension-handle-BJnk3WEh.mjs → detached-extension-handle-BNvRSUVO.mjs} +1 -1
  50. package/dist/{execution-attempt-repository-DSpz2kyW.d.mts → execution-attempt-repository-BoNwNybg.d.mts} +85 -3
  51. package/dist/{hook-responses-CpEfxEmG.d.mts → hook-responses-DVjMuGh9.d.mts} +1 -1
  52. package/dist/{index-CCNCo440.d.mts → index-B4KCyY6J.d.mts} +16 -16
  53. package/dist/{index-Bj2JCo9V.d.mts → index-BXair-QK.d.mts} +1 -1
  54. package/dist/{index-BfzuauBt2.d.mts → index-BgKU1PuR2.d.mts} +1 -1
  55. package/dist/{index-DvoitgXV.d.mts → index-C0jn5nKJ.d.mts} +11 -11
  56. package/dist/{index-CRM23ToM2.d.mts → index-CAURP-Tl2.d.mts} +3 -3
  57. package/dist/{index-BTluq4-E.d.mts → index-CKvliyuY.d.mts} +4847 -1730
  58. package/dist/{index-BlHq_Ksb.d.mts → index-CLmjrH8K.d.mts} +2 -2
  59. package/dist/{index-GTCM4lXx.d.mts → index-CO6ADD43.d.mts} +25 -25
  60. package/dist/{index-BM-FPWjs2.d.mts → index-CTNGL-cq2.d.mts} +1 -1
  61. package/dist/{index-CDhbUjUH.d.mts → index-CU9xmTkP.d.mts} +1 -1
  62. package/dist/{index-hm8NV4CJ2.d.mts → index-CVP9K9-a2.d.mts} +8 -8
  63. package/dist/{index-BfwHYuRf.d.mts → index-Caai1zAG.d.mts} +1 -1
  64. package/dist/{index-D7IZQNhD.d.mts → index-CgYGg-Ne2.d.mts} +2 -2
  65. package/dist/{index-Bn6sN1op.d.mts → index-DUH2eTyC.d.mts} +1 -1
  66. package/dist/{index-C742b1FV.d.mts → index-DUdGqxHD.d.mts} +1 -1
  67. package/dist/{index-Dzozmb5u.d.mts → index-Ddk-kjif.d.mts} +3 -3
  68. package/dist/{index-DY_0TRvM.d.mts → index-DhW9WHFS.d.mts} +2 -2
  69. package/dist/{index-6kg8YFYt.d.mts → index-DnZksNTM.d.mts} +1 -1
  70. package/dist/{index-B3G-Hzwn.d.mts → index-Dp3UZQv_.d.mts} +1 -1
  71. package/dist/{index-BxJRljy-.d.mts → index-Dtc5UYJG.d.mts} +237 -102
  72. package/dist/{index-DR308wUB2.d.mts → index-H2NL2OwF2.d.mts} +119 -7
  73. package/dist/{index-CjMMvZch.d.mts → index-LRAmVQLj.d.mts} +278 -44
  74. package/dist/kernel/cli/index.d.mts +2 -2
  75. package/dist/kernel/cli/register.d.mts +1 -1
  76. package/dist/kernel/extension/index.d.mts +1 -1
  77. package/dist/kernel/index.d.mts +5 -5
  78. package/dist/kernel/namespace/index.d.mts +1 -1
  79. package/dist/kernel/observability/index.d.mts +1 -1
  80. package/dist/kernel/providers/index.d.mts +1 -1
  81. package/dist/kernel/window/index.d.mts +1 -1
  82. package/dist/{lib-BmXBuE-w.mjs → lib-B1Mvm4hQ.mjs} +1 -1
  83. package/dist/{lib-R-c_q77C.mjs → lib-D1-cvcTz.mjs} +1 -1
  84. package/dist/{load-extensions-Bu10B5B1.d.mts → load-extensions-D6SVKBPw.d.mts} +1 -1
  85. package/dist/{load-extensions-s4YmICgn.mjs → load-extensions-bwisKaW0.mjs} +1 -1
  86. package/dist/{namespace-btfJrUf6.d.mts → namespace-CYYFqmtJ.d.mts} +6 -6
  87. package/dist/{namespace-CfA0C0JR.d.mts → namespace-CfNNUjVv.d.mts} +2 -2
  88. package/dist/{namespace-BHb_9sh4.d.mts → namespace-DyWNxLt1.d.mts} +6 -6
  89. package/dist/{namespace-Dmbm2JzV.d.mts → namespace-l1Rcc4mp.d.mts} +2 -2
  90. package/dist/node/bus-server/index.d.mts +1 -1
  91. package/dist/node/bus-server/server-lifecycle.d.mts +1 -1
  92. package/dist/{package-BaTrCWZl.d.mts → package-CnR_tOsW.d.mts} +21 -3
  93. package/dist/package-tvzH3A0x.mjs +7 -0
  94. package/dist/package.json +1 -1
  95. package/dist/rules/index.d.mts +1 -1
  96. package/dist/rules/schemas.d.mts +1 -1
  97. package/dist/runtime-bun/index.mjs +1 -1
  98. package/dist/runtime-node/code-execution/index.d.mts +2 -2
  99. package/dist/runtime-node/extension-discovery.d.mts +1 -1
  100. package/dist/runtime-node/extension-validation.d.mts +1 -1
  101. package/dist/runtime-node/extension-validation.mjs +1 -1
  102. package/dist/runtime-node/index.d.mts +6 -6
  103. package/dist/runtime-node/index.mjs +21 -21
  104. package/dist/runtime-node/makaio-config.d.mts +1 -1
  105. package/dist/runtime-node/workflow-execution-bus-access.mjs +1 -1
  106. package/dist/runtime-node/workflow-worker/index.d.mts +2 -2
  107. package/dist/runtime-node/workflow-worker/index.mjs +1 -1
  108. package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
  109. package/dist/{schemas-DYIVJDlx.d.mts → schemas-BGcAiQE0.d.mts} +4 -4
  110. package/dist/{schemas-CQe4xCRn.d.mts → schemas-D6JvwH-h.d.mts} +2 -2
  111. package/dist/{schemas-Cz7H2f7S.d.mts → schemas-DChhgfU0.d.mts} +7 -7
  112. package/dist/{schemas-yXs929kr.d.mts → schemas-Dt1YwXLN.d.mts} +7 -7
  113. package/dist/{schemas-BkCqhK3X.d.mts → schemas-FkLOBJgq.d.mts} +4 -4
  114. package/dist/{schemas-GyKYcV-Z2.d.mts → schemas-Fn-eeay32.d.mts} +7 -7
  115. package/dist/{schemas-bcDK-fK3.d.mts → schemas-_NrySTmN.d.mts} +7 -7
  116. package/dist/services/adapter-runtime/index.d.mts +3 -3
  117. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  118. package/dist/services/adapter-runtime/schemas.d.mts +1 -1
  119. package/dist/services/adapter-subsystem/index.d.mts +3 -3
  120. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  121. package/dist/services/agent-runtime/index.d.mts +2 -2
  122. package/dist/services/agent-runtime/namespace.d.mts +1 -1
  123. package/dist/services/agent-runtime/schemas.d.mts +1 -1
  124. package/dist/services/capability/index.d.mts +2 -2
  125. package/dist/services/code-execution/index.d.mts +1 -1
  126. package/dist/services/codebase/index.d.mts +2 -2
  127. package/dist/services/codebase/namespace.d.mts +1 -1
  128. package/dist/services/codebase/schemas.d.mts +1 -1
  129. package/dist/services/compression/index.d.mts +2 -2
  130. package/dist/services/compression/namespace.d.mts +1 -1
  131. package/dist/services/compression/schemas.d.mts +1 -1
  132. package/dist/services/context-rules/index.d.mts +1 -1
  133. package/dist/services/execution-target/index.d.mts +3 -3
  134. package/dist/services/execution-target/namespace.d.mts +1 -1
  135. package/dist/services/execution-target/schemas.d.mts +1 -1
  136. package/dist/services/filesystem/index.d.mts +1 -1
  137. package/dist/services/filesystem/namespace.d.mts +6 -6
  138. package/dist/services/filesystem/schemas.d.mts +3 -3
  139. package/dist/services/git/namespace.d.mts +2 -2
  140. package/dist/services/git/schemas.d.mts +1 -1
  141. package/dist/services/index.d.mts +57 -57
  142. package/dist/services/log-import/browser.d.mts +2 -2
  143. package/dist/services/log-import/index.d.mts +2 -2
  144. package/dist/services/log-import/log-import.d.mts +1 -1
  145. package/dist/services/materialization/index.d.mts +1 -1
  146. package/dist/services/model-registry/index.d.mts +1 -1
  147. package/dist/services/preferences/index.d.mts +2 -2
  148. package/dist/services/preferences/schemas.d.mts +1 -1
  149. package/dist/services/preferences/storage-namespace.d.mts +2 -2
  150. package/dist/services/provider-context/index.d.mts +1 -1
  151. package/dist/services/session/handlers/index.d.mts +1 -1
  152. package/dist/services/session/index.d.mts +9 -9
  153. package/dist/services/session/messages/namespace.d.mts +1 -1
  154. package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
  155. package/dist/services/session/session-events/namespace.d.mts +1 -1
  156. package/dist/services/session/storage/namespace.d.mts +1 -1
  157. package/dist/services/session/storage/schema.d.mts +1 -1
  158. package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
  159. package/dist/services/session/turns/namespace.d.mts +1 -1
  160. package/dist/services/session-editor/index.d.mts +1 -1
  161. package/dist/services/settings/index.d.mts +3 -3
  162. package/dist/services/settings/namespace.d.mts +4 -4
  163. package/dist/services/settings/storage/clients-namespace.d.mts +1 -1
  164. package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
  165. package/dist/services/settings/storage/index.d.mts +3 -3
  166. package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
  167. package/dist/services/subagent/index.d.mts +1 -1
  168. package/dist/services/subagent-template/index.d.mts +2 -2
  169. package/dist/services/subagent-template/namespace.d.mts +1 -1
  170. package/dist/services/subagent-template/schemas.d.mts +1 -1
  171. package/dist/services/tool-approval/index.d.mts +1 -1
  172. package/dist/services/tools/index.d.mts +1 -1
  173. package/dist/services/tray-menu/index.d.mts +3 -3
  174. package/dist/services/tray-menu/namespace.d.mts +1 -1
  175. package/dist/services/tray-menu/schemas.d.mts +1 -1
  176. package/dist/services/turn/index.d.mts +1 -1
  177. package/dist/services/turn/namespace.d.mts +1 -1
  178. package/dist/services/workflow-transitions/index.d.mts +1 -1
  179. package/dist/{src-CmLn6zYj.mjs → src-BZdlyUxT.mjs} +1 -1
  180. package/dist/storage/drizzle/client.d.mts +1 -1
  181. package/dist/storage/drizzle/index.d.mts +1 -1
  182. package/dist/storage/handlers/drizzle/index.d.mts +1 -1
  183. package/dist/storage/handlers/index.d.mts +1 -1
  184. package/dist/{storage-namespace-zRXWqAfO.d.mts → storage-namespace-BUSNKZLw.d.mts} +10 -10
  185. package/dist/{transition-bYkXnLY2.d.mts → transition-D2VKNtv6.d.mts} +2 -2
  186. package/dist/{types-Bnc-pdB12.d.mts → types-DafDuOcH2.d.mts} +1 -1
  187. package/dist/{types-BNKqcHfP.d.mts → types-DyXXIK4c.d.mts} +3 -3
  188. package/dist/ui-kernel/index.d.mts +4 -4
  189. package/dist/ui-kernel/pages/namespace.d.mts +4 -4
  190. package/dist/ui-kernel/pages/schemas.d.mts +1 -1
  191. package/dist/{view-builder-CA5qUx85.d.mts → view-builder-BFEvUe6n.d.mts} +1 -1
  192. package/dist/worker-L8vWpbYa.mjs +1 -0
  193. package/dist/{workflow-5yHn_Knq.mjs → workflow-DNks09Ip.mjs} +1 -1
  194. package/dist/workflow-engine/execution-attempt-repository.d.mts +1 -1
  195. package/dist/workflow-engine/index.d.mts +98 -60
  196. package/dist/workflow-engine/index.mjs +1 -1
  197. package/dist/workflow-engine/package.d.mts +1 -1
  198. package/dist/workflow-engine/package.mjs +1 -1
  199. package/dist/workflow-engine/provider-operation.d.mts +1 -1
  200. package/dist/workflow-engine/testing/conformance.d.mts +1 -1
  201. package/dist/workflow-engine/testing/conformance.mjs +2 -2
  202. package/dist/workflow-engine/testing/index.d.mts +3 -1
  203. package/dist/workflow-engine/testing/index.mjs +1 -1
  204. package/dist/workflow-engine/testing/sqlite.d.mts +1 -1
  205. package/dist/workflow-engine/testing/sqlite.mjs +50 -33
  206. package/dist/workflow-worker-BDA-E_pm.mjs +2 -0
  207. package/package.json +1 -1
  208. package/dist/artifact-Cxm5ZX7L.mjs +0 -1
  209. package/dist/bootstrap-start-client-rW55mDI-.mjs +0 -1
  210. package/dist/package-BT94BLu4.mjs +0 -7
  211. package/dist/worker-Cx1JDOB9.mjs +0 -1
  212. package/dist/workflow-worker-BAO7pQpx.mjs +0 -2
  213. /package/dist/{adapter-binding-DhANVB-O.d.mts → adapter-binding-CTssGlH_.d.mts} +0 -0
  214. /package/dist/{attempt-fixtures-CMx-2OlG.mjs → attempt-fixtures-B8FSy_vs.mjs} +0 -0
  215. /package/dist/{attempt-record-codec-D2Gb_epJ.mjs → attempt-record-codec-BrungudT.mjs} +0 -0
  216. /package/dist/{base-orchestrator-tAgnJAKu.d.mts → base-orchestrator-C5Z9Aowq.d.mts} +0 -0
  217. /package/dist/{capability-service-Cpkonrc0.d.mts → capability-service-DX3wLjdt.d.mts} +0 -0
  218. /package/dist/{client-At2zn3yg.d.mts → client-BsXMxeCN.d.mts} +0 -0
  219. /package/dist/{client-binary-version-verifier-EOj8xXqm.d.mts → client-binary-version-verifier-uMFQoKZj.d.mts} +0 -0
  220. /package/dist/{clients-namespace-CVRwXq8f.d.mts → clients-namespace-1hXA6qNd.d.mts} +0 -0
  221. /package/dist/{config-namespace-D7GbrasR.d.mts → config-namespace-Bpq9WOY4.d.mts} +0 -0
  222. /package/dist/{create-static-mount-BIH26VH8.mjs → create-static-mount-Cr24q94C.mjs} +0 -0
  223. /package/dist/{definition-VK1rERAp.d.mts → definition-Ckt_WmJw.d.mts} +0 -0
  224. /package/dist/{extension-context-Cpf_n5FH.d.mts → extension-context-BGNUn34r.d.mts} +0 -0
  225. /package/dist/{extension-discovery-B0ZL076T.d.mts → extension-discovery-Dx118u_N.d.mts} +0 -0
  226. /package/dist/{filesystem-service-BWoNtujU.d.mts → filesystem-service-DtApanQk.d.mts} +0 -0
  227. /package/dist/{index-Bk0Xjk-B.d.mts → index-1AKlC3kZ.d.mts} +0 -0
  228. /package/dist/{index-CDA33y5A.d.mts → index-5KVPGsig.d.mts} +0 -0
  229. /package/dist/{index-8a41yDOl.d.mts → index-B4lidHiL.d.mts} +0 -0
  230. /package/dist/{index-Bzxs2nVR.d.mts → index-BLhNHkiK.d.mts} +0 -0
  231. /package/dist/{index-DzHc6hsJ.d.mts → index-Bw7benCh.d.mts} +0 -0
  232. /package/dist/{index-DXSVC0bM.d.mts → index-C0zo4Id_.d.mts} +0 -0
  233. /package/dist/{index-BL1F1xYB.d.mts → index-C3n8beRR.d.mts} +0 -0
  234. /package/dist/{index-C8oBOTl_.d.mts → index-C86rKLPD.d.mts} +0 -0
  235. /package/dist/{index-BIlFSGnW.d.mts → index-CIl66QhT.d.mts} +0 -0
  236. /package/dist/{index-Dckvm0Ml2.d.mts → index-CK5GEXLB2.d.mts} +0 -0
  237. /package/dist/{index-D4XNkbM4.d.mts → index-CUcEfh31.d.mts} +0 -0
  238. /package/dist/{index-DwY1Mt9a.d.mts → index-CrDp6vHG.d.mts} +0 -0
  239. /package/dist/{index-CilWtThn.d.mts → index-CrvTRZqh.d.mts} +0 -0
  240. /package/dist/{index-DCfYa3cF.d.mts → index-CzKJC3Bt.d.mts} +0 -0
  241. /package/dist/{index-BBkJsViX2.d.mts → index-D4FE3jHM2.d.mts} +0 -0
  242. /package/dist/{index-Ccaqmi0J.d.mts → index-DK8lSIvY.d.mts} +0 -0
  243. /package/dist/{index-Du-eXjEN.d.mts → index-DLsopffG.d.mts} +0 -0
  244. /package/dist/{index-BcPO9w0j.d.mts → index-DNN9jOVO.d.mts} +0 -0
  245. /package/dist/{index-C75h1xHF2.d.mts → index-DO0QO0ux2.d.mts} +0 -0
  246. /package/dist/{index-krTCFThl2.d.mts → index-DSRxn5Zr2.d.mts} +0 -0
  247. /package/dist/{index-CSJOBx3H.d.mts → index-Dfv9hyZE.d.mts} +0 -0
  248. /package/dist/{index-BpsurXEW.d.mts → index-DqS8eCAT.d.mts} +0 -0
  249. /package/dist/{index-CjazerMN.d.mts → index-Dv5aNxoa.d.mts} +0 -0
  250. /package/dist/{index-CWeWBh-_.d.mts → index-DxxORQny.d.mts} +0 -0
  251. /package/dist/{index-BTHdi23O.d.mts → index-DyBuGOvY.d.mts} +0 -0
  252. /package/dist/{index-CVh7ZP2I.d.mts → index-fpGFhEmI.d.mts} +0 -0
  253. /package/dist/{index-DwKPj8jD.d.mts → index-lLuIAmRB.d.mts} +0 -0
  254. /package/dist/{index-Bn1JTbn_2.d.mts → index-qLkIGcgv2.d.mts} +0 -0
  255. /package/dist/{index-DCHdW5g-.d.mts → index-tCFckLG6.d.mts} +0 -0
  256. /package/dist/{json-value-BKUDMT7k.d.mts → json-value-Bjl8jzom.d.mts} +0 -0
  257. /package/dist/{jsonl-transport-3yp3clGp.mjs → jsonl-transport-D4ch0vsf.mjs} +0 -0
  258. /package/dist/{lib-DF6sgNx_.mjs → lib-BLdnqIFF.mjs} +0 -0
  259. /package/dist/{namespace-fEBskugJ.d.mts → namespace--mFdPlbu.d.mts} +0 -0
  260. /package/dist/{namespace-KTRWfIPy.d.mts → namespace-Bivbsfms.d.mts} +0 -0
  261. /package/dist/{namespace-BiEV44Mk.d.mts → namespace-C-4xI2rm.d.mts} +0 -0
  262. /package/dist/{namespace-B0_Sg-1m.d.mts → namespace-CQPcYS-Q.d.mts} +0 -0
  263. /package/dist/{namespace-BNNFD-ul.d.mts → namespace-CvCk6Y9i.d.mts} +0 -0
  264. /package/dist/{namespace-BgaVgd00.d.mts → namespace-DXrdGpbs.d.mts} +0 -0
  265. /package/dist/{namespace-B3MnuAqp.d.mts → namespace-Dwf7aOLt.d.mts} +0 -0
  266. /package/dist/{namespace-Czr38fiF.d.mts → namespace-E4ajXk0W.d.mts} +0 -0
  267. /package/dist/{namespace-CY-9Evdf.d.mts → namespace-TX9DlWiQ.d.mts} +0 -0
  268. /package/dist/{namespace-CjmNxtr1.d.mts → namespace-XUB3XnBK.d.mts} +0 -0
  269. /package/dist/{orchestrator-shared-Cwc6JKkV.d.mts → orchestrator-shared-D2I9gyOl.d.mts} +0 -0
  270. /package/dist/{packages-DTz_1dCa.d.mts → packages-Dj9Nul23.d.mts} +0 -0
  271. /package/dist/{providers-namespace-Bming6U8.d.mts → providers-namespace-BA0JT--_.d.mts} +0 -0
  272. /package/dist/{runtime-inputs-DeOea-ab.d.mts → runtime-inputs-CIYLDuBM.d.mts} +0 -0
  273. /package/dist/{schema-DFCBjTB7.d.mts → schema-B098Jz9p.d.mts} +0 -0
  274. /package/dist/{schemas-DqWwz4eR.d.mts → schemas-ADuQFkhH.d.mts} +0 -0
  275. /package/dist/{schemas-BLy33xay.d.mts → schemas-BZyi7v9g.d.mts} +0 -0
  276. /package/dist/{schemas-CSeLgroC.d.mts → schemas-D9WJH6We.d.mts} +0 -0
  277. /package/dist/{schemas-DwqibWUL.d.mts → schemas-DKy_XYjq.d.mts} +0 -0
  278. /package/dist/{schemas-DTBWnWjN.d.mts → schemas-DMxM4U1A.d.mts} +0 -0
  279. /package/dist/{server-lifecycle-_m_x1_TC.d.mts → server-lifecycle-B8UabaW3.d.mts} +0 -0
  280. /package/dist/{session-lineage-CEyJWg_J.d.mts → session-lineage-CoNs4WZy.d.mts} +0 -0
  281. /package/dist/{src-DdaPoQOD.mjs → src-D9PYcdDS.mjs} +0 -0
  282. /package/dist/{storage-namespace-definition-CsaZPU3n.d.mts → storage-namespace-definition-1uCuoHvM.d.mts} +0 -0
  283. /package/dist/{types-CccTiXH2.d.mts → types-BlaguWul.d.mts} +0 -0
  284. /package/dist/{types-nor1SQLZ.d.mts → types-CbXf822E.d.mts} +0 -0
  285. /package/dist/{types-DjxvRcX6.d.mts → types-KF8zuMhi.d.mts} +0 -0
  286. /package/dist/{types-Dswhi1L9.d.mts → types-RWRXplnM.d.mts} +0 -0
  287. /package/dist/{types-DXGVwrQn.d.mts → types-nY8yr3th.d.mts} +0 -0
  288. /package/dist/{window-registry-DQ7udUzI.d.mts → window-registry-Dq5uOWpH.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- import { I as RecordAllocationInput, Mt as AttemptOutcomeControlObservation$1, P as ProvisioningClaimDecision, Pt as ExecutionAttemptCancellationIntent$1, dt as ProviderOperationOwnershipRecord, it as ProviderOperationClaim, j as OutcomeCodec, r as AllocationRecordingDecision, rt as ProcessBoundProvisionerLossProof, s as AttemptControlState, u as BeginProvisioningInput, w as ExecutionOwnerId, x as ExecutionAttemptRepository, y as ExecutionAttemptRecord, yt as ExecutionAttemptOutcomeDecision } from "../../execution-attempt-repository-DSpz2kyW.mjs";
1
+ import { Ht as AttemptControlEvidence, I as RecordAllocationInput, Mt as AttemptOutcomeControlObservation$1, P as ProvisioningClaimDecision, Pt as ExecutionAttemptCancellationIntent$1, dt as ProviderOperationOwnershipRecord, it as ProviderOperationClaim, j as OutcomeCodec, r as AllocationRecordingDecision, rt as ProcessBoundProvisionerLossProof, s as AttemptControlState, u as BeginProvisioningInput, w as ExecutionOwnerId, x as ExecutionAttemptRepository, y as ExecutionAttemptRecord, yt as ExecutionAttemptOutcomeDecision } from "../../execution-attempt-repository-BoNwNybg.mjs";
2
2
  import { BoundedRecoveryEvidence, ExecutionAttemptInstruction, ExecutionAttemptPreparationResult, ProviderAllocationRef, WorkerAllocationLifetime, WorkflowRunResult } from "@makaio/framework/contracts";
3
3
 
4
4
  //#region subsystems/workflow-engine/src/testing/attempt-record-codec.d.ts
@@ -62,6 +62,8 @@ interface InMemoryAttemptRepositoryState {
62
62
  readonly requestBindings: Map<string, Map<string, string>>;
63
63
  /** First owner cancellation request for each attempt, surviving controller replacement. */
64
64
  readonly cancellations: Map<string, ExecutionAttemptCancellationIntent$1>;
65
+ /** Immutable facts keyed by Attempt, then numeric revision and generation. */
66
+ readonly controlEvidence: Map<string, Map<string, AttemptControlEvidence>>;
65
67
  }
66
68
  /**
67
69
  * The in-memory realization together with the state backing it.
@@ -1 +1 @@
1
- import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,l as c,m as l,n as u,o as d,s as f,u as p,v as m,x as h,y as g}from"../../execution-attempt-repository-CWbgCTwA.mjs";import{a as _,i as v,n as y,o as b,t as x}from"../../execution-attempt-owner-recovery-D4APLAvt.mjs";import{isProviderOperationResolved as S}from"../provider-operation.mjs";import{a as C,c as w,d as T,f as E,i as D,l as ee,n as O,o as k,p as A,r as j,s as M,t as N,u as P}from"../../attempt-record-codec-D2Gb_epJ.mjs";import{a as F,c as I,d as L,f as R,i as z,l as B,m as V,n as H,o as U,p as W,r as G,s as K,t as q,u as J}from"../../attempt-fixtures-CMx-2OlG.mjs";import{randomUUID as Y}from"node:crypto";import{BoundedRecoveryEvidenceSchema as X}from"@makaio/framework/contracts";function Z(e){if(e.kind===`accepted`||e.kind===`duplicate`)return e;throw Error(`Expected a committed test outcome, received ${e.kind}`)}function Q(e,t){return{...e,status:`settled`,settlementKind:t,claimable:!1,operationStartGate:`closed`}}function $(F,I={}){let L=I.attempts??new Map,R=I.operations??new Map,z=e=>R.get(e)?.obligation===`terminal-convergence`,B=I.committedOutcomes??new Map,V=I.outcomeControlObservations??new Map,H=I.activeAttempts??new Map,U=I.requestBindings??new Map,W=I.cancellations??new Map,G=e=>{let t=e.settlementKind!=null,n=!t&&H.get(e.executionId)===e.executionAttemptId;return s({matchesExecution:!0,settled:t,active:n,allocated:n&&e.allocationRef!==null&&!z(e.executionAttemptId)})},K=e=>{let t=L.get(e.executionAttemptId),n=R.get(e.executionAttemptId);return!t||!n?{kind:`not-found`}:S(t,n)?{kind:`resolved`,attempt:t}:n.token===null||n.token!==e.token||n.generation!==e.generation||n.ownerId!==e.ownerId?{kind:`stale`,attempt:t}:{kind:`authorized`,attempt:t,operation:n}},q=(e,t)=>{e.completionEvidence===null&&R.set(e.executionAttemptId,{...e,completionEvidence:t})},J=(e,t)=>{let n=M(e.allocationRef),r=K(e.claim);if(r.kind!==`not-found`&&T(r.attempt,n),r.kind===`resolved`)return{kind:`resolved`,allocationRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i,operation:a}=r;if(i.allocationRef!==null)return f(i.allocationRef,n)?{kind:`duplicate`,allocationRef:i.allocationRef}:{kind:`conflict`,allocationRef:i.allocationRef};let o=H.get(i.executionId)===i.executionAttemptId;return L.set(i.executionAttemptId,{...i,status:i.settlementKind===null?`allocated`:i.status,allocationRef:n,claimable:i.settlementKind===null&&t&&o}),R.set(a.executionAttemptId,{...a,obligation:`allocation-control`}),{kind:`recorded`}},Z={async getAttemptWithAllocation(e){return L.get(e)??null},async recordDiscoveredAllocation(e){return J(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=w(e),r=K(e.claim);if(r.kind===`stale`)return{kind:`stale`,storedRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i}=r;return i.executionId===e.executionId?i.allocationRef===null?{kind:`not-allocated`}:f(i.allocationRef,t)?(L.set(i.executionAttemptId,{...i,allocationRef:n}),{kind:`evolved`}):{kind:`stale`,storedRef:i.allocationRef}:{kind:`not-found`}},async getRecoverableAttempts(e){let t=D(new Date().toISOString()),n=[];for(let r of L.values())r.executionId===e&&r.status===`allocated`&&r.allocationRef!==null&&r.claimable===!0&&r.settlementKind==null&&(r.claimExpiresAt!=null&&D(r.claimExpiresAt)<t||n.push(A(r)));return n.sort(O)},async listOpenProviderOperations(e){if(!Number.isSafeInteger(e.limit)||e.limit<=0)throw RangeError(`limit must be a positive safe integer`);let t=D(e.observedAt),n=[];for(let e of R.values()){let r=L.get(e.executionAttemptId);!r||S(r,e)||e.ownerId!==null&&e.leaseExpiresAt!==null&&D(e.leaseExpiresAt)>t||n.push({attempt:r,operation:e})}return n.sort((e,t)=>O(e.attempt,t.attempt)).slice(0,e.limit)}},$=e=>{let t=j(e.bootstrapTimeoutMs);if(L.has(e.executionAttemptId))throw new u(e.executionAttemptId);let n={executionAttemptId:e.executionAttemptId,executionId:e.executionId,instruction:e.instruction,preparationReceipts:Object.freeze([]),status:`pending`,allocationRef:null,...t,providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null,...N},r=H.get(e.executionId),i=r===void 0?void 0:L.get(r);return i!==void 0&&L.set(i.executionAttemptId,{...i,claimable:i.status===`allocated`?!1:i.claimable,operationStartGate:`closed`}),L.set(e.executionAttemptId,n),H.set(e.executionId,e.executionAttemptId),n};return{async createAttempt(e){return $({...e,instruction:b(e.instruction)})},async ensureAttempt(e){let t=v(e),n=U.get(t.executionId),r=n?.get(t.requestKey);if(r!==void 0)return y(t,L.get(r)??null);let i=$(t),a=n??new Map;return a.set(t.requestKey,i.executionAttemptId),U.set(t.executionId,a),{kind:`created`,attempt:structuredClone(i)}},async readAttemptSettlement(e){let t=_(e);return x(t,{attempt:L.get(t.executionAttemptId)??null,activeAttemptId:H.get(t.executionId)??null,outcomeText:B.get(t.executionAttemptId)??null,controlObservation:V.get(t.executionAttemptId)??null},F)},async readBootstrapStartState(e){let t=L.get(e.executionAttemptId);return!t||t.executionId!==e.executionId?null:{settled:t.settlementKind!=null,active:H.get(e.executionId)===e.executionAttemptId,allocated:t.allocationRef!==null,allocationTerminated:z(e.executionAttemptId),operationStartGate:t.operationStartGate,bootstrapDeadlineAt:t.bootstrapDeadlineAt??null}},async beginProvisioning(e){let t=k(e.allocationLifetime),n=L.get(e.executionAttemptId);if(!n||n.executionId!==e.executionId)return{kind:`not-found`};if(H.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(n.settlementKind!=null)return{kind:`resolved`,allocationRef:n.allocationRef};if(n.allocationRef!==null)return{kind:`allocated`,allocationRef:n.allocationRef};if(n.operationStartGate===`closed`)return{kind:`fenced`};if(n.status!==`pending`)return{kind:`already-provisioning`};L.set(e.executionAttemptId,{...n,status:`provisioning`,providerId:e.providerId,allocationLifetime:t,provisionerIncarnationId:e.provisionerIncarnationId});let r={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:C(e.leaseExpiresAt)};return R.set(e.executionAttemptId,{executionAttemptId:e.executionAttemptId,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null,completionEvidence:null}),{kind:`started`,claim:r}},async getProviderOperation(e){return R.get(e)??null},async renewProviderOperationClaim(e){let t=K(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let n=C(e.leaseExpiresAt);return R.set(e.claim.executionAttemptId,{...t.operation,leaseExpiresAt:n}),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:n}}},async takeOverProviderOperation(e){let t=L.get(e.executionAttemptId),n=R.get(e.executionAttemptId);if(!t||!n)return{kind:`not-found`};if(S(t,n))return{kind:`resolved`};if(n.ownerId!==null&&n.leaseExpiresAt!==null&&D(n.leaseExpiresAt)>D(e.observedAt))return{kind:`stale`};let r={executionAttemptId:e.executionAttemptId,generation:n.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:C(e.leaseExpiresAt)};return R.set(e.executionAttemptId,{...n,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt}),{kind:`claimed`,claim:r}},async handoffProviderOperation(e){let t=e.evidence===void 0?void 0:X.parse(e.evidence),n=K(e.claim);return n.kind===`authorized`?(R.set(e.claim.executionAttemptId,{...n.operation,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t??n.operation.lastFailure}),{kind:`recorded`}):{kind:n.kind}},async recordProviderOperationUncertainty(e){let t=X.parse(e.evidence),n=K(e.claim);return n.kind===`authorized`?(R.set(e.claim.executionAttemptId,{...n.operation,failureCount:n.operation.failureCount+1,lastFailure:t}),{kind:`recorded`}):{kind:n.kind}},async completeProviderOperation(e){let t=X.parse(e.evidence),n=L.get(e.claim.executionAttemptId),r=R.get(e.claim.executionAttemptId);return!n||!r?{kind:`not-found`}:r.token!==e.claim.token||r.generation!==e.claim.generation||r.ownerId!==e.claim.ownerId?{kind:`stale`}:S(n,r)?{kind:`already-completed`}:r.completionEvidence===null?(q(r,t),n.settlementKind===null?{kind:`evidence-recorded`}:{kind:`completed`}):{kind:`evidence-recorded`}},async recordAllocation(e){return J(e,!0)},async recordProvisioningAbsent(e){let t=X.parse(e.evidence),n=K(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.allocationRef===null?r.settlementKind===null?(L.set(r.executionAttemptId,Q(r,`abandoned`)),q(i,t),{kind:`recorded`}):(q(i,t),{kind:`completed`}):{kind:`allocated`,allocationRef:r.allocationRef}:{kind:`not-found`}},async recordProvisionerIncarnationLost(e){let t=X.parse(e.proof.evidence),n=K(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n,a=g(r,e);return a===null?r.settlementKind===null?(L.set(r.executionAttemptId,Q(r,`abandoned`)),q(i,t),{kind:`recorded`}):(q(i,t),{kind:`completed`}):a},async recordAllocationTerminated(e){let t=X.parse(e.evidence),n=K(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.allocationRef===null?{kind:`not-allocated`}:(R.set(i.executionAttemptId,{...i,obligation:`terminal-convergence`,lastFailure:t}),{kind:`recorded`})},async recordInfrastructureFailure(e){let t=K(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let{attempt:n,operation:r}=t;return n.executionId===e.executionId?n.settlementKind===null?n.allocationRef===null?{kind:`not-allocated`}:r.obligation===`terminal-convergence`?(L.set(n.executionAttemptId,Q(n,`infrastructure-failure`)),{kind:`recorded`}):{kind:`not-terminated`}:{kind:`resolved`}:{kind:`not-found`}},async registerRuntime(e){let t=L.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};let n=G(t)??h(t,e);if(n!==null)return n;let r=t.runtimeGeneration+1;return L.set(t.executionAttemptId,{...t,runtimeGeneration:r,runtimeIncarnationId:e.runtimeIncarnationId,runtimeReadyAt:null,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null}),{kind:`registered`,runtimeGeneration:r}},async admitOperation(e){let t=L.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};let n=G(t);if(n!==null)return n;let r=o(t,e,t.activeOperationId!==null&&t.activeOperationKey===e.admissionKey&&t.activeOperationAdmittedAt===null?C(new Date().toISOString()):``,t);if(r!==null)return r;let i=crypto.randomUUID(),a=C(new Date().toISOString());return L.set(t.executionAttemptId,{...t,activeOperationId:i,activeOperationKind:e.operationKind,activeOperationKey:e.admissionKey,activeOperationGeneration:t.runtimeGeneration,activeOperationAdmittedAt:a}),{kind:`admitted`,operationId:i,runtimeGeneration:t.runtimeGeneration,admittedAt:a}},async getInstruction(e){let t=L.get(e.executionAttemptId);return t?.executionId===e.executionId?t.instruction:null},async reportOperation(e){let t=P(e.result),n=L.get(e.executionAttemptId);if(n===void 0||n.executionId!==e.executionId)return{kind:`not-found`};let r=m({matchesExecution:!0,settled:n.settlementKind!=null,active:H.get(e.executionId)===e.executionAttemptId,allocated:n.allocationRef!==null&&!z(e.executionAttemptId)},n,n,{...e,result:t});if(r!==null)return r;let i=ee([...n.preparationReceipts,{operationId:e.operationId,runtimeGeneration:e.runtimeGeneration,result:t}]);return L.set(e.executionAttemptId,{...n,preparationReceipts:i,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:e.operationId}),{kind:`accepted`,binding:t.binding}},async completeOperation(t){let n=L.get(t.executionAttemptId);if(n===void 0)return{kind:`not-found`};if(n.settlementKind!=null)return{kind:`resolved`};let r=e(n,t);return r===null?(L.set(n.executionAttemptId,{...n,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:t.operationId}),{kind:`completed`}):r},async markRuntimeReady(e){let t=C(e.readyAt),r=L.get(e.executionAttemptId);if(r===void 0||r.executionId!==e.executionId)return{kind:`not-found`};let i=G(r)??n(r,e);return i===null?(L.set(r.executionAttemptId,{...r,runtimeReadyAt:t}),{kind:`ready`,acceptedAt:t}):i},async getAttemptControlState(e){let t=L.get(e);return t===void 0?null:E(t)},async requestAttemptCancellation(e){let t=i(e),n=L.get(t.executionAttemptId);if(n===void 0||n.executionId!==t.executionId)return{kind:`not-found`};let r=c(W.get(t.executionAttemptId)??null,t,new Date().toISOString());return r.kind===`conflict`?r:(W.set(t.executionAttemptId,{...r.intent}),L.set(t.executionAttemptId,{...n,operationStartGate:`closed`}),r)},async requestCancellation(e){let t=a(e),n={...t,requestKey:Y()},r=new Date().toISOString(),i=[...L].filter(([,e])=>e.executionId===t.executionId).map(([e,t])=>{let i=c(W.get(e)??null,n,r);if(i.kind===`conflict`)throw Error(`Conflicting generated cancellation request key`);return{id:e,attempt:t,intent:i.intent}});for(let{id:e,attempt:t,intent:n}of i)W.set(e,{...n}),L.set(e,{...t,operationStartGate:`closed`})},async readCancellation(e){let t=W.get(e);return t===void 0?null:{...t}},async getActiveAttempt(e,t){return H.get(e)===t?L.get(t)??null:null},canonicalizeOutcome(e){return d(F,e)},decodeOutcome(e){return t(F,e)},async commitOutcome(e){let n=e.result;if(H.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let i=L.get(e.executionAttemptId);if(i===void 0)return{kind:`fenced`};let a=B.get(e.executionAttemptId);if(a!==void 0){let i=t(F,a);return r(a,n.text)?{kind:`duplicate`,outcome:i,text:a,controlObservation:structuredClone(V.get(e.executionAttemptId)??null)}:{kind:`conflict`}}if(i.settlementKind!=null)return{kind:`conflict`};l(i,e.runtimeFence);let o=p(W.get(e.executionAttemptId)??null);return B.set(e.executionAttemptId,n.text),V.set(e.executionAttemptId,o),L.set(e.executionAttemptId,Q(i,`outcome`)),{kind:`accepted`,outcome:t(F,n.text),text:n.text,controlObservation:structuredClone(o)}},async abandonPendingAttempt(e,t){if(H.get(t)!==e)return{kind:`fenced`};let n=L.get(e);return n?n.status===`allocated`?{kind:`allocated`}:n.status===`provisioning`?{kind:`provisioning`}:n.status===`settled`?{kind:n.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:(L.set(e,Q(n,`abandoned`)),{kind:`abandoned`}):{kind:`fenced`}},recovery:Z,attempts:L,operations:R,committedOutcomes:B,outcomeControlObservations:V,activeAttempts:H,requestBindings:U,cancellations:W}}export{N as INITIAL_ATTEMPT_CONTROL_STATE,q as TEST_OWNER_ID,H as TEST_PROVIDER_ID,G as TEST_PROVISIONER_INCARNATION_ID,z as allocateTestAttempt,F as beginTestProvisioning,$ as createInMemoryAttemptRepository,U as driveTestAttemptToAllocated,K as leaseAt,I as makeBeginProvisioningInput,B as makeEvidence,J as makeProcessLossProof,L as makeTestAllocationRef,R as makeTestInstruction,W as makeTestWorkflowResult,Z as requireCommittedOutcome,V as workflowRunResultOutcomeCodec};
1
+ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,l as c,m as l,n as u,o as ee,s as d,u as f,v as p,x as m,y as h}from"../../execution-attempt-repository-CWbgCTwA.mjs";import{a as g,i as _,n as v,o as y,t as te}from"../../execution-attempt-owner-recovery-D4APLAvt.mjs";import{i as b,n as x,r as ne,t as S}from"../../attempt-control-evidence-BKw1U3wL.mjs";import{isProviderOperationResolved as C}from"../provider-operation.mjs";import{a as w,c as T,d as E,f as D,i as O,l as k,n as A,o as j,p as re,r as ie,s as M,t as N,u as P}from"../../attempt-record-codec-BrungudT.mjs";import{a as F,c as I,d as L,f as R,i as z,l as B,m as V,n as H,o as U,p as W,r as G,s as K,t as q,u as J}from"../../attempt-fixtures-B8FSy_vs.mjs";import{randomUUID as ae}from"node:crypto";import{BoundedRecoveryEvidenceSchema as Y}from"@makaio/framework/contracts";function X(e){if(e.kind===`accepted`||e.kind===`duplicate`)return e;throw Error(`Expected a committed test outcome, received ${e.kind}`)}function Z(e,t){return{...e,status:`settled`,settlementKind:t,claimable:!1,operationStartGate:`closed`}}function Q(F,I={}){let L=I.attempts??new Map,R=I.operations??new Map,z=e=>R.get(e)?.obligation===`terminal-convergence`,B=I.committedOutcomes??new Map,V=I.outcomeControlObservations??new Map,H=I.activeAttempts??new Map,U=I.requestBindings??new Map,W=I.cancellations??new Map,G=I.controlEvidence??new Map,K=e=>{let t=e.settlementKind!=null,n=!t&&H.get(e.executionId)===e.executionAttemptId;return s({matchesExecution:!0,settled:t,active:n,allocated:n&&e.allocationRef!==null&&!z(e.executionAttemptId)})},q=e=>{let t=L.get(e.executionAttemptId),n=R.get(e.executionAttemptId);return!t||!n?{kind:`not-found`}:C(t,n)?{kind:`resolved`,attempt:t}:n.token===null||n.token!==e.token||n.generation!==e.generation||n.ownerId!==e.ownerId?{kind:`stale`,attempt:t}:{kind:`authorized`,attempt:t,operation:n}},J=(e,t)=>{e.completionEvidence===null&&R.set(e.executionAttemptId,{...e,completionEvidence:t})},X=(e,t)=>{let n=M(e.allocationRef),r=q(e.claim);if(r.kind!==`not-found`&&E(r.attempt,n),r.kind===`resolved`)return{kind:`resolved`,allocationRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i,operation:a}=r;if(i.allocationRef!==null)return d(i.allocationRef,n)?{kind:`duplicate`,allocationRef:i.allocationRef}:{kind:`conflict`,allocationRef:i.allocationRef};let o=H.get(i.executionId)===i.executionAttemptId;return L.set(i.executionAttemptId,{...i,status:i.settlementKind===null?`allocated`:i.status,allocationRef:n,claimable:i.settlementKind===null&&t&&o}),R.set(a.executionAttemptId,{...a,obligation:`allocation-control`}),{kind:`recorded`}},Q={async getAttemptWithAllocation(e){return L.get(e)??null},async recordDiscoveredAllocation(e){return X(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=T(e),r=q(e.claim);if(r.kind===`stale`)return{kind:`stale`,storedRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i}=r;return i.executionId===e.executionId?i.allocationRef===null?{kind:`not-allocated`}:d(i.allocationRef,t)?(L.set(i.executionAttemptId,{...i,allocationRef:n}),{kind:`evolved`}):{kind:`stale`,storedRef:i.allocationRef}:{kind:`not-found`}},async getRecoverableAttempts(e){let t=O(new Date().toISOString()),n=[];for(let r of L.values())r.executionId===e&&r.status===`allocated`&&r.allocationRef!==null&&r.claimable===!0&&r.settlementKind==null&&(r.claimExpiresAt!=null&&O(r.claimExpiresAt)<t||n.push(re(r)));return n.sort(A)},async listOpenProviderOperations(e){if(!Number.isSafeInteger(e.limit)||e.limit<=0)throw RangeError(`limit must be a positive safe integer`);let t=O(e.observedAt),n=[];for(let e of R.values()){let r=L.get(e.executionAttemptId);!r||C(r,e)||e.ownerId!==null&&e.leaseExpiresAt!==null&&O(e.leaseExpiresAt)>t||n.push({attempt:r,operation:e})}return n.sort((e,t)=>A(e.attempt,t.attempt)).slice(0,e.limit)}},$=e=>{let t=ie(e.bootstrapTimeoutMs);if(L.has(e.executionAttemptId))throw new u(e.executionAttemptId);let n={executionAttemptId:e.executionAttemptId,executionId:e.executionId,instruction:e.instruction,preparationReceipts:Object.freeze([]),status:`pending`,allocationRef:null,...t,providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null,...N},r=H.get(e.executionId),i=r===void 0?void 0:L.get(r);return i!==void 0&&L.set(i.executionAttemptId,{...i,claimable:i.status===`allocated`?!1:i.claimable,operationStartGate:`closed`}),L.set(e.executionAttemptId,n),H.set(e.executionId,e.executionAttemptId),n};return{async createAttempt(e){return $({...e,instruction:y(e.instruction)})},async ensureAttempt(e){let t=_(e),n=U.get(t.executionId),r=n?.get(t.requestKey);if(r!==void 0)return v(t,L.get(r)??null);let i=$(t),a=n??new Map;return a.set(t.requestKey,i.executionAttemptId),U.set(t.executionId,a),{kind:`created`,attempt:structuredClone(i)}},async readAttemptSettlement(e){let t=g(e);return te(t,{attempt:L.get(t.executionAttemptId)??null,activeAttemptId:H.get(t.executionId)??null,outcomeText:B.get(t.executionAttemptId)??null,controlObservation:V.get(t.executionAttemptId)??null},F)},async readBootstrapStartState(e){let t=L.get(e.executionAttemptId);return!t||t.executionId!==e.executionId?null:{settled:t.settlementKind!=null,active:H.get(e.executionId)===e.executionAttemptId,allocated:t.allocationRef!==null,allocationTerminated:z(e.executionAttemptId),operationStartGate:t.operationStartGate,bootstrapDeadlineAt:t.bootstrapDeadlineAt??null}},async beginProvisioning(e){let t=j(e.allocationLifetime),n=L.get(e.executionAttemptId);if(!n||n.executionId!==e.executionId)return{kind:`not-found`};if(H.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(n.settlementKind!=null)return{kind:`resolved`,allocationRef:n.allocationRef};if(n.allocationRef!==null)return{kind:`allocated`,allocationRef:n.allocationRef};if(n.operationStartGate===`closed`)return{kind:`fenced`};if(n.status!==`pending`)return{kind:`already-provisioning`};L.set(e.executionAttemptId,{...n,status:`provisioning`,providerId:e.providerId,allocationLifetime:t,provisionerIncarnationId:e.provisionerIncarnationId});let r={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:w(e.leaseExpiresAt)};return R.set(e.executionAttemptId,{executionAttemptId:e.executionAttemptId,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null,completionEvidence:null}),{kind:`started`,claim:r}},async getProviderOperation(e){return R.get(e)??null},async renewProviderOperationClaim(e){let t=q(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let n=w(e.leaseExpiresAt);return R.set(e.claim.executionAttemptId,{...t.operation,leaseExpiresAt:n}),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:n}}},async takeOverProviderOperation(e){let t=L.get(e.executionAttemptId),n=R.get(e.executionAttemptId);if(!t||!n)return{kind:`not-found`};if(C(t,n))return{kind:`resolved`};if(n.ownerId!==null&&n.leaseExpiresAt!==null&&O(n.leaseExpiresAt)>O(e.observedAt))return{kind:`stale`};let r={executionAttemptId:e.executionAttemptId,generation:n.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:w(e.leaseExpiresAt)};return R.set(e.executionAttemptId,{...n,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt}),{kind:`claimed`,claim:r}},async handoffProviderOperation(e){let t=e.evidence===void 0?void 0:Y.parse(e.evidence),n=q(e.claim);return n.kind===`authorized`?(R.set(e.claim.executionAttemptId,{...n.operation,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t??n.operation.lastFailure}),{kind:`recorded`}):{kind:n.kind}},async recordProviderOperationUncertainty(e){let t=Y.parse(e.evidence),n=q(e.claim);return n.kind===`authorized`?(R.set(e.claim.executionAttemptId,{...n.operation,failureCount:n.operation.failureCount+1,lastFailure:t}),{kind:`recorded`}):{kind:n.kind}},async completeProviderOperation(e){let t=Y.parse(e.evidence),n=L.get(e.claim.executionAttemptId),r=R.get(e.claim.executionAttemptId);return!n||!r?{kind:`not-found`}:r.token!==e.claim.token||r.generation!==e.claim.generation||r.ownerId!==e.claim.ownerId?{kind:`stale`}:C(n,r)?{kind:`already-completed`}:r.completionEvidence===null?(J(r,t),n.settlementKind===null?{kind:`evidence-recorded`}:{kind:`completed`}):{kind:`evidence-recorded`}},async recordAllocation(e){return X(e,!0)},async recordProvisioningAbsent(e){let t=Y.parse(e.evidence),n=q(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.allocationRef===null?r.settlementKind===null?(L.set(r.executionAttemptId,Z(r,`abandoned`)),J(i,t),{kind:`recorded`}):(J(i,t),{kind:`completed`}):{kind:`allocated`,allocationRef:r.allocationRef}:{kind:`not-found`}},async recordProvisionerIncarnationLost(e){let t=Y.parse(e.proof.evidence),n=q(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n,a=h(r,e);return a===null?r.settlementKind===null?(L.set(r.executionAttemptId,Z(r,`abandoned`)),J(i,t),{kind:`recorded`}):(J(i,t),{kind:`completed`}):a},async recordAllocationTerminated(e){let t=Y.parse(e.evidence),n=q(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.allocationRef===null?{kind:`not-allocated`}:(R.set(i.executionAttemptId,{...i,obligation:`terminal-convergence`,lastFailure:t}),{kind:`recorded`})},async recordInfrastructureFailure(e){let t=q(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let{attempt:n,operation:r}=t;return n.executionId===e.executionId?n.settlementKind===null?n.allocationRef===null?{kind:`not-allocated`}:r.obligation===`terminal-convergence`?(L.set(n.executionAttemptId,Z(n,`infrastructure-failure`)),{kind:`recorded`}):{kind:`not-terminated`}:{kind:`resolved`}:{kind:`not-found`}},async registerRuntime(e){let t=L.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};let n=K(t)??m(t,e);if(n!==null)return n;let r=t.runtimeGeneration+1;return L.set(t.executionAttemptId,{...t,runtimeGeneration:r,runtimeIncarnationId:e.runtimeIncarnationId,runtimeReadyAt:null,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null}),{kind:`registered`,runtimeGeneration:r}},async admitOperation(e){let t=L.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};let n=K(t);if(n!==null)return n;let r=o(t,e,t.activeOperationId!==null&&t.activeOperationKey===e.admissionKey&&t.activeOperationAdmittedAt===null?w(new Date().toISOString()):``,t);if(r!==null)return r;let i=crypto.randomUUID(),a=w(new Date().toISOString());return L.set(t.executionAttemptId,{...t,activeOperationId:i,activeOperationKind:e.operationKind,activeOperationKey:e.admissionKey,activeOperationGeneration:t.runtimeGeneration,activeOperationAdmittedAt:a}),{kind:`admitted`,operationId:i,runtimeGeneration:t.runtimeGeneration,admittedAt:a}},async getInstruction(e){let t=L.get(e.executionAttemptId);return t?.executionId===e.executionId?t.instruction:null},async reportOperation(e){let t=P(e.result),n=L.get(e.executionAttemptId);if(n===void 0||n.executionId!==e.executionId)return{kind:`not-found`};let r=p({matchesExecution:!0,settled:n.settlementKind!=null,active:H.get(e.executionId)===e.executionAttemptId,allocated:n.allocationRef!==null&&!z(e.executionAttemptId)},n,n,{...e,result:t});if(r!==null)return r;let i=k([...n.preparationReceipts,{operationId:e.operationId,runtimeGeneration:e.runtimeGeneration,result:t}]);return L.set(e.executionAttemptId,{...n,preparationReceipts:i,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:e.operationId}),{kind:`accepted`,binding:t.binding}},async completeOperation(t){let n=L.get(t.executionAttemptId);if(n===void 0)return{kind:`not-found`};if(n.settlementKind!=null)return{kind:`resolved`};let r=e(n,t);return r===null?(L.set(n.executionAttemptId,{...n,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:t.operationId}),{kind:`completed`}):r},async markRuntimeReady(e){let t=w(e.readyAt),r=L.get(e.executionAttemptId);if(r===void 0||r.executionId!==e.executionId)return{kind:`not-found`};let i=K(r)??n(r,e);return i===null?(L.set(r.executionAttemptId,{...r,runtimeReadyAt:t}),{kind:`ready`,acceptedAt:t}):i},async getAttemptControlState(e){let t=L.get(e);return t===void 0?null:D(t)},async requestAttemptCancellation(e){let t=i(e),n=L.get(t.executionAttemptId);if(n===void 0||n.executionId!==t.executionId)return{kind:`not-found`};let r=c(W.get(t.executionAttemptId)??null,t,new Date().toISOString());return r.kind===`conflict`?r:(W.set(t.executionAttemptId,{...r.intent}),L.set(t.executionAttemptId,{...n,operationStartGate:`closed`}),r)},async requestCancellation(e){let t=a(e),n={...t,requestKey:ae()},r=new Date().toISOString(),i=[...L].filter(([,e])=>e.executionId===t.executionId).map(([e,t])=>{let i=c(W.get(e)??null,n,r);if(i.kind===`conflict`)throw Error(`Conflicting generated cancellation request key`);return{id:e,attempt:t,intent:i.intent}});for(let{id:e,attempt:t,intent:n}of i)W.set(e,{...n}),L.set(e,{...t,operationStartGate:`closed`})},async readCancellation(e){let t=W.get(e);return t===void 0?null:{...t}},async readAttemptCancellationControl(e){let{executionId:t,executionAttemptId:n}=e,r=L.get(n);return r===void 0||r.executionId!==t?null:structuredClone({control:D(r),cancellation:W.get(n)??null,evidence:[...G.get(n)?.values()??[]].sort((e,t)=>e.controlRevision-t.controlRevision||e.runtimeGeneration-t.runtimeGeneration)})},async recordAttemptControlReceipt(e){let t=ne(e),{executionId:n,...r}=t,{executionAttemptId:i,controlRevision:a,runtimeGeneration:o}=t,s=`${a}:${o}`,c=G.get(i)??new Map,l=c.get(s),u=S(L.get(i)??null,W.get(i)??null,l?.receipt??null,t);return u.kind===`accepted`&&(c.set(s,{controlRevision:a,runtimeGeneration:o,receipt:r,report:l?.report??null}),G.set(i,c)),u},async reportAttemptControl(e){let t=b(e),{executionId:n,...r}=t,{executionAttemptId:i,controlRevision:a,runtimeGeneration:o}=t,s=`${a}:${o}`,c=G.get(i)??new Map,l=c.get(s),u=x(L.get(i)??null,W.get(i)??null,l?.report??null,t);return u.kind===`accepted`&&(c.set(s,{controlRevision:a,runtimeGeneration:o,receipt:l?.receipt??null,report:r}),G.set(i,c)),u},async getActiveAttempt(e,t){return H.get(e)===t?L.get(t)??null:null},canonicalizeOutcome(e){return ee(F,e)},decodeOutcome(e){return t(F,e)},async commitOutcome(e){let n=e.result;if(H.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let i=L.get(e.executionAttemptId);if(i===void 0)return{kind:`fenced`};let a=B.get(e.executionAttemptId);if(a!==void 0){let i=t(F,a);return r(a,n.text)?{kind:`duplicate`,outcome:i,text:a,controlObservation:structuredClone(V.get(e.executionAttemptId)??null)}:{kind:`conflict`}}if(i.settlementKind!=null)return{kind:`conflict`};l(i,e.runtimeFence);let o=f(W.get(e.executionAttemptId)??null);return B.set(e.executionAttemptId,n.text),V.set(e.executionAttemptId,o),L.set(e.executionAttemptId,Z(i,`outcome`)),{kind:`accepted`,outcome:t(F,n.text),text:n.text,controlObservation:structuredClone(o)}},async abandonPendingAttempt(e,t){if(H.get(t)!==e)return{kind:`fenced`};let n=L.get(e);return n?n.status===`allocated`?{kind:`allocated`}:n.status===`provisioning`?{kind:`provisioning`}:n.status===`settled`?{kind:n.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:(L.set(e,Z(n,`abandoned`)),{kind:`abandoned`}):{kind:`fenced`}},recovery:Q,attempts:L,operations:R,committedOutcomes:B,outcomeControlObservations:V,activeAttempts:H,requestBindings:U,cancellations:W,controlEvidence:G}}export{N as INITIAL_ATTEMPT_CONTROL_STATE,q as TEST_OWNER_ID,H as TEST_PROVIDER_ID,G as TEST_PROVISIONER_INCARNATION_ID,z as allocateTestAttempt,F as beginTestProvisioning,Q as createInMemoryAttemptRepository,U as driveTestAttemptToAllocated,K as leaseAt,I as makeBeginProvisioningInput,B as makeEvidence,J as makeProcessLossProof,L as makeTestAllocationRef,R as makeTestInstruction,W as makeTestWorkflowResult,X as requireCommittedOutcome,V as workflowRunResultOutcomeCodec};
@@ -1,4 +1,4 @@
1
- import { j as OutcomeCodec, x as ExecutionAttemptRepository } from "../../execution-attempt-repository-DSpz2kyW.mjs";
1
+ import { j as OutcomeCodec, x as ExecutionAttemptRepository } from "../../execution-attempt-repository-BoNwNybg.mjs";
2
2
  import { MakaioDatabase } from "@makaio/framework/storage/drizzle";
3
3
 
4
4
  //#region subsystems/workflow-engine/src/testing/sqlite-attempt-repository.d.ts
@@ -1,4 +1,11 @@
1
- import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,n as te,o as ne,r as u,s as d,t as f,u as re,v as ie,x as ae,y as oe}from"../../execution-attempt-repository-CWbgCTwA.mjs";import{a as se,i as ce,n as le,o as p,t as ue}from"../../execution-attempt-owner-recovery-D4APLAvt.mjs";import{PROVIDER_OPERATION_OBLIGATIONS as m,isProviderOperationResolved as h}from"../provider-operation.mjs";import{a as g,c as de,d as fe,i as _,l as v,o as pe,p as me,r as y,s as he,t as ge,u as _e}from"../../attempt-record-codec-D2Gb_epJ.mjs";import{z as b}from"zod";import{BoundedRecoveryEvidenceSchema as x,ExecutionAttemptOperationKindSchema as S,ProviderAllocationRefSchema as C,WorkerAllocationLifetimeSchema as w}from"@makaio/framework/contracts";import{getRawSqlExecutor as ve,isSqliteUniqueViolationError as ye,serializeByKey as T,serializeDatabaseOperation as be}from"@makaio/framework/storage/drizzle";import{sql as E}from"drizzle-orm";const xe=[`CREATE TABLE IF NOT EXISTS test_execution_attempt_cancellation (
1
+ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,n as te,o as ne,r as u,s as d,t as f,u as re,v as ie,x as ae,y as oe}from"../../execution-attempt-repository-CWbgCTwA.mjs";import{a as se,i as ce,n as le,o as p,t as ue}from"../../execution-attempt-owner-recovery-D4APLAvt.mjs";import{i as de,n as fe,r as pe,t as me}from"../../attempt-control-evidence-BKw1U3wL.mjs";import{PROVIDER_OPERATION_OBLIGATIONS as m,isProviderOperationResolved as h}from"../provider-operation.mjs";import{a as g,c as he,d as ge,i as _,l as v,o as _e,p as ve,r as y,s as ye,t as be,u as xe}from"../../attempt-record-codec-BrungudT.mjs";import{z as b}from"zod";import{BoundedRecoveryEvidenceSchema as x,ExecutionAttemptControlReceiptSchema as Se,ExecutionAttemptControlReportSchema as Ce,ExecutionAttemptOperationKindSchema as S,ProviderAllocationRefSchema as C,WorkerAllocationLifetimeSchema as w}from"@makaio/framework/contracts";import{getRawSqlExecutor as we,isSqliteUniqueViolationError as Te,serializeByKey as T,serializeDatabaseOperation as Ee}from"@makaio/framework/storage/drizzle";import{sql as E}from"drizzle-orm";const De=[`CREATE TABLE IF NOT EXISTS test_execution_attempt_control_evidence (
2
+ execution_attempt_id TEXT NOT NULL,
3
+ control_revision INTEGER NOT NULL,
4
+ runtime_generation INTEGER NOT NULL,
5
+ receipt_json TEXT,
6
+ report_json TEXT,
7
+ PRIMARY KEY (execution_attempt_id, control_revision, runtime_generation)
8
+ )`,`CREATE TABLE IF NOT EXISTS test_execution_attempt_cancellation (
2
9
  execution_attempt_id TEXT PRIMARY KEY,
3
10
  request_key TEXT NOT NULL,
4
11
  control_revision INTEGER NOT NULL,
@@ -52,7 +59,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
52
59
  failure_count INTEGER NOT NULL DEFAULT 0,
53
60
  last_failure TEXT,
54
61
  completion_evidence TEXT
55
- )`];function D(e,t,n){let r=e.find(e=>e===t);if(r===void 0)throw Error(`Stored '${n}' value '${t}' is not part of the port's vocabulary`);return r}function O(e,t){return e===null?null:t(JSON.parse(e))}const k=b.object({requestKey:b.string().min(1),controlRevision:b.number().int().positive(),requestedAt:b.string().datetime(),reason:b.string().optional()}),A=b.object({controlRevision:b.number().int().nonnegative(),cancellation:k.nullable()});function j(e){if(e===null)return null;let t=A.parse(JSON.parse(e));if(t.controlRevision!==(t.cancellation?.controlRevision??0))throw Error(`Stored outcome control revision does not match its cancellation receipt`);return t}function M(e){return{runtimeGeneration:e.runtime_generation,runtimeIncarnationId:e.runtime_incarnation_id,runtimeReadyAt:e.runtime_ready_at,operationStartGate:D(f,e.operation_start_gate,`operation_start_gate`),activeOperationId:e.active_operation_id,activeOperationKind:e.active_operation_kind===null?null:S.parse(e.active_operation_kind),activeOperationKey:e.active_operation_key,activeOperationGeneration:e.active_operation_generation,activeOperationAdmittedAt:e.active_operation_admitted_at,lastCompletedOperationId:e.last_completed_operation_id}}function N(e){return{...M(e),executionAttemptId:e.execution_attempt_id,executionId:e.execution_id,instruction:p(JSON.parse(e.instruction)),preparationReceipts:v(JSON.parse(e.preparation_receipts)),status:D(c,e.status,`status`),allocationRef:O(e.allocation_ref,e=>C.parse(e)),createdAt:e.created_at,bootstrapDeadlineAt:e.bootstrap_deadline_at,providerId:e.provider_id,allocationLifetime:e.allocation_lifetime===null?null:w.parse(e.allocation_lifetime),provisionerIncarnationId:e.provisioner_incarnation_id,settlementKind:e.settlement_kind===null?null:D(u,e.settlement_kind,`settlement_kind`),claimable:e.claimable!==0,claimExpiresAt:e.claim_expires_at}}function P(e){return{executionAttemptId:e.execution_attempt_id,generation:e.generation,ownerId:e.owner_id,token:e.token,leaseExpiresAt:e.lease_expires_at,obligation:D(m,e.obligation,`obligation`),failureCount:e.failure_count,lastFailure:O(e.last_failure,e=>x.parse(e)),completionEvidence:O(e.completion_evidence,e=>x.parse(e))}}const F=new Map,I=new Map;function L(e){if(typeof e!=`object`||!e)return!1;let t=e,n=typeof t.message==`string`?t.message:``;return n.includes(`SQLITE_BUSY`)||n.startsWith(`Failed query: BEGIN IMMEDIATE`)||n.startsWith(`Failed query: COMMIT`)||L(t.cause)}function R(e){if(typeof e!=`object`||!e)return!1;let t=e;return(typeof t.message==`string`?t.message:``).includes(`no transaction is active`)||R(t.cause)}async function z(){await new Promise(e=>setImmediate(e))}async function Se(e){for(let t=0;;t+=1)try{await e.run(E.raw(`COMMIT`));return}catch(e){if(!L(e)||t===100)throw e;await z()}}async function Ce(e,t){return T(F,e,t)}async function we(e,t){return T(I,e,t)}const B=new WeakMap;async function Te(e,t){let n=(await t.all(E.raw(`PRAGMA database_list`))).find(e=>e.name===`main`)?.file??null;if(n!==null&&n!==``)return`file:${n}`;let r=B.get(e);if(r!==void 0)return r;let i=`connection:${crypto.randomUUID()}`;return B.set(e,i),i}async function V(e,t){let n=await e();if(typeof n!=`function`)return n;if((await n()).rowsAffected>0)return typeof t==`function`?t():t;let r=await e();if(typeof r!=`function`)return r;throw Error(`A guarded transition affected no rows while durable state still permitted it`)}function H(e){return E`EXISTS (SELECT 1 FROM test_provider_operation
62
+ )`];function D(e,t,n){let r=e.find(e=>e===t);if(r===void 0)throw Error(`Stored '${n}' value '${t}' is not part of the port's vocabulary`);return r}function O(e,t){return e===null?null:t(JSON.parse(e))}const k=b.object({requestKey:b.string().min(1),controlRevision:b.number().int().positive(),requestedAt:b.string().datetime(),reason:b.string().optional()}),A=b.object({controlRevision:b.number().int().nonnegative(),cancellation:k.nullable()});function j(e){if(e===null)return null;let t=A.parse(JSON.parse(e));if(t.controlRevision!==(t.cancellation?.controlRevision??0))throw Error(`Stored outcome control revision does not match its cancellation receipt`);return t}function M(e){return{runtimeGeneration:e.runtime_generation,runtimeIncarnationId:e.runtime_incarnation_id,runtimeReadyAt:e.runtime_ready_at,operationStartGate:D(f,e.operation_start_gate,`operation_start_gate`),activeOperationId:e.active_operation_id,activeOperationKind:e.active_operation_kind===null?null:S.parse(e.active_operation_kind),activeOperationKey:e.active_operation_key,activeOperationGeneration:e.active_operation_generation,activeOperationAdmittedAt:e.active_operation_admitted_at,lastCompletedOperationId:e.last_completed_operation_id}}function N(e){return{...M(e),executionAttemptId:e.execution_attempt_id,executionId:e.execution_id,instruction:p(JSON.parse(e.instruction)),preparationReceipts:v(JSON.parse(e.preparation_receipts)),status:D(c,e.status,`status`),allocationRef:O(e.allocation_ref,e=>C.parse(e)),createdAt:e.created_at,bootstrapDeadlineAt:e.bootstrap_deadline_at,providerId:e.provider_id,allocationLifetime:e.allocation_lifetime===null?null:w.parse(e.allocation_lifetime),provisionerIncarnationId:e.provisioner_incarnation_id,settlementKind:e.settlement_kind===null?null:D(u,e.settlement_kind,`settlement_kind`),claimable:e.claimable!==0,claimExpiresAt:e.claim_expires_at}}function P(e){return{executionAttemptId:e.execution_attempt_id,generation:e.generation,ownerId:e.owner_id,token:e.token,leaseExpiresAt:e.lease_expires_at,obligation:D(m,e.obligation,`obligation`),failureCount:e.failure_count,lastFailure:O(e.last_failure,e=>x.parse(e)),completionEvidence:O(e.completion_evidence,e=>x.parse(e))}}const F=new Map,I=new Map;function L(e){if(typeof e!=`object`||!e)return!1;let t=e,n=typeof t.message==`string`?t.message:``;return n.includes(`SQLITE_BUSY`)||n.startsWith(`Failed query: BEGIN IMMEDIATE`)||n.startsWith(`Failed query: COMMIT`)||L(t.cause)}function R(e){if(typeof e!=`object`||!e)return!1;let t=e;return(typeof t.message==`string`?t.message:``).includes(`no transaction is active`)||R(t.cause)}async function z(){await new Promise(e=>setImmediate(e))}async function Oe(e){for(let t=0;;t+=1)try{await e.run(E.raw(`COMMIT`));return}catch(e){if(!L(e)||t===100)throw e;await z()}}async function ke(e,t){return T(F,e,t)}async function Ae(e,t){return T(I,e,t)}const B=new WeakMap;async function je(e,t){let n=(await t.all(E.raw(`PRAGMA database_list`))).find(e=>e.name===`main`)?.file??null;if(n!==null&&n!==``)return`file:${n}`;let r=B.get(e);if(r!==void 0)return r;let i=`connection:${crypto.randomUUID()}`;return B.set(e,i),i}async function V(e,t){let n=await e();if(typeof n!=`function`)return n;if((await n()).rowsAffected>0)return typeof t==`function`?t():t;let r=await e();if(typeof r!=`function`)return r;throw Error(`A guarded transition affected no rows while durable state still permitted it`)}function H(e){return E`EXISTS (SELECT 1 FROM test_provider_operation
56
63
  WHERE execution_attempt_id = ${e.executionAttemptId}
57
64
  AND generation = ${e.generation}
58
65
  AND owner_id = ${e.ownerId}
@@ -68,33 +75,35 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
68
75
  WHERE execution_attempt_id = ${e}
69
76
  AND obligation = ${`terminal-convergence`})`}function K(){return E`EXISTS (SELECT 1 FROM test_active_execution_attempt
70
77
  WHERE execution_id = test_execution_attempt.execution_id
71
- AND execution_attempt_id = test_execution_attempt.execution_attempt_id)`}async function q(c,u){let b=ve(c);await b.run(E.raw(`PRAGMA busy_timeout = 0`));let S=await Te(c,b);await Ce(S,async()=>{for(let e of xe)await b.run(E.raw(e));let e=await b.all(E.raw(`PRAGMA table_info(test_execution_attempt)`));e.some(e=>e.name===`bootstrap_deadline_at`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt ADD COLUMN bootstrap_deadline_at TEXT`)),e.some(e=>e.name===`outcome_control_observation`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt ADD COLUMN outcome_control_observation TEXT`));let t=await b.all(E.raw(`PRAGMA table_info(test_execution_attempt_cancellation)`));t.some(e=>e.name===`request_key`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt_cancellation ADD COLUMN request_key TEXT`)),t.some(e=>e.name===`control_revision`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt_cancellation ADD COLUMN control_revision INTEGER NOT NULL DEFAULT 1`));let n=await b.all(E`SELECT execution_attempt_id FROM test_execution_attempt_cancellation WHERE request_key IS NULL`);for(let e of n)await b.run(E`UPDATE test_execution_attempt_cancellation SET request_key = ${crypto.randomUUID()}
72
- WHERE execution_attempt_id = ${e.execution_attempt_id} AND request_key IS NULL`);(await b.all(E.raw(`PRAGMA table_info(test_provider_operation)`))).some(e=>e.name===`completion_evidence`)||await b.run(E.raw(`ALTER TABLE test_provider_operation ADD COLUMN completion_evidence TEXT`))});let C,w=async e=>be(c,()=>we(S,async()=>{if(C!==void 0)throw Error(`This repository was retired by a failed transaction rollback`,{cause:C});for(let t=0;;t+=1)try{return await b.withSession(async t=>{let n=!1;try{await t.run(E.raw(`BEGIN IMMEDIATE`)),n=!0;let r=await e(t);return await Se(t),r}catch(e){try{await t.run(E.raw(`ROLLBACK`))}catch(t){throw!n&&R(t)?e:(C=AggregateError([e,t],`Transaction rollback failed`),C)}throw e}})}catch(e){if(!L(e)||t===100)throw e;await z()}})),T=async(e,t)=>{let[n]=await e.all(E`SELECT request_key, control_revision, requested_at, reason
73
- FROM test_execution_attempt_cancellation WHERE execution_attempt_id = ${t}`);return n===void 0?null:k.parse({requestKey:n.request_key,controlRevision:n.control_revision,requestedAt:n.requested_at,...n.reason===null?{}:{reason:n.reason}})},O=async(e,t,n)=>{await e.run(E`INSERT INTO test_execution_attempt_cancellation
78
+ AND execution_attempt_id = test_execution_attempt.execution_attempt_id)`}async function q(c,u){let b=we(c);await b.run(E.raw(`PRAGMA busy_timeout = 0`));let S=await je(c,b);await ke(S,async()=>{for(let e of De)await b.run(E.raw(e));let e=await b.all(E.raw(`PRAGMA table_info(test_execution_attempt)`));e.some(e=>e.name===`bootstrap_deadline_at`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt ADD COLUMN bootstrap_deadline_at TEXT`)),e.some(e=>e.name===`outcome_control_observation`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt ADD COLUMN outcome_control_observation TEXT`));let t=await b.all(E.raw(`PRAGMA table_info(test_execution_attempt_cancellation)`));t.some(e=>e.name===`request_key`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt_cancellation ADD COLUMN request_key TEXT`)),t.some(e=>e.name===`control_revision`)||await b.run(E.raw(`ALTER TABLE test_execution_attempt_cancellation ADD COLUMN control_revision INTEGER NOT NULL DEFAULT 1`));let n=await b.all(E`SELECT execution_attempt_id FROM test_execution_attempt_cancellation WHERE request_key IS NULL`);for(let e of n)await b.run(E`UPDATE test_execution_attempt_cancellation SET request_key = ${crypto.randomUUID()}
79
+ WHERE execution_attempt_id = ${e.execution_attempt_id} AND request_key IS NULL`);(await b.all(E.raw(`PRAGMA table_info(test_provider_operation)`))).some(e=>e.name===`completion_evidence`)||await b.run(E.raw(`ALTER TABLE test_provider_operation ADD COLUMN completion_evidence TEXT`))});let C,w=async e=>Ee(c,()=>Ae(S,async()=>{if(C!==void 0)throw Error(`This repository was retired by a failed transaction rollback`,{cause:C});for(let t=0;;t+=1)try{return await b.withSession(async t=>{let n=!1;try{await t.run(E.raw(`BEGIN IMMEDIATE`)),n=!0;let r=await e(t);return await Oe(t),r}catch(e){try{await t.run(E.raw(`ROLLBACK`))}catch(t){throw!n&&R(t)?e:(C=AggregateError([e,t],`Transaction rollback failed`),C)}throw e}})}catch(e){if(!L(e)||t===100)throw e;await z()}})),T=async(e,t)=>{let[n]=await e.all(E`SELECT request_key, control_revision, requested_at, reason
80
+ FROM test_execution_attempt_cancellation WHERE execution_attempt_id = ${t}`);return n===void 0?null:k.parse({requestKey:n.request_key,controlRevision:n.control_revision,requestedAt:n.requested_at,...n.reason===null?{}:{reason:n.reason}})},O=async(e,t)=>(await e.all(E`SELECT control_revision, runtime_generation, receipt_json, report_json
81
+ FROM test_execution_attempt_control_evidence WHERE execution_attempt_id = ${t}
82
+ ORDER BY control_revision, runtime_generation`)).map(e=>({controlRevision:e.control_revision,runtimeGeneration:e.runtime_generation,receipt:e.receipt_json===null?null:Se.parse(JSON.parse(e.receipt_json)),report:e.report_json===null?null:Ce.parse(JSON.parse(e.report_json))})),A=async(e,t,n)=>{await e.run(E`INSERT INTO test_execution_attempt_cancellation
74
83
  (execution_attempt_id, request_key, control_revision, requested_at, reason)
75
84
  VALUES (${t}, ${n.requestKey}, ${n.controlRevision},
76
85
  ${n.requestedAt}, ${n.reason??null})`),await e.run(E`UPDATE test_execution_attempt SET operation_start_gate = 'closed'
77
- WHERE execution_attempt_id = ${t}`)},A=async(e,t)=>(await e.all(E`SELECT * FROM test_execution_attempt WHERE execution_attempt_id = ${t}`))[0],F=async(e,t)=>(await e.all(E`SELECT * FROM test_provider_operation WHERE execution_attempt_id = ${t}`))[0],I=async(e,t)=>(await F(e,t))?.obligation===`terminal-convergence`,B=async(e,t)=>(await e.all(E`SELECT execution_attempt_id FROM test_active_execution_attempt WHERE execution_id = ${t}`))[0]?.execution_attempt_id??null,q=async(e,t)=>{let n=t.settlement_kind!==null,r=!n&&await B(e,t.execution_id)===t.execution_attempt_id;return s({matchesExecution:!0,settled:n,active:r,allocated:r&&t.allocation_ref!==null&&!await I(e,t.execution_attempt_id)})},J=async(e,t)=>{let n=await A(e,t.executionAttemptId),r=await F(e,t.executionAttemptId);if(n===void 0||r===void 0)return{kind:`not-found`};let i=N(n);return h(i,P(r))?{kind:`resolved`,attempt:i}:r.token===null||r.token!==t.token||r.generation!==t.generation||r.owner_id!==t.ownerId?{kind:`stale`,attempt:i}:{kind:`authorized`,attempt:i,attemptRow:n,operation:r}},Y=async(e,t)=>{let n=await J(e,t);return n.kind===`authorized`?void 0:{kind:n.kind}},X=async(e,t,n,r)=>{let i=await e.run(E`UPDATE test_execution_attempt
86
+ WHERE execution_attempt_id = ${t}`)},F=async(e,t)=>(await e.all(E`SELECT * FROM test_execution_attempt WHERE execution_attempt_id = ${t}`))[0],I=async(e,t)=>(await e.all(E`SELECT * FROM test_provider_operation WHERE execution_attempt_id = ${t}`))[0],B=async(e,t)=>(await I(e,t))?.obligation===`terminal-convergence`,q=async(e,t)=>(await e.all(E`SELECT execution_attempt_id FROM test_active_execution_attempt WHERE execution_id = ${t}`))[0]?.execution_attempt_id??null,J=async(e,t)=>{let n=t.settlement_kind!==null,r=!n&&await q(e,t.execution_id)===t.execution_attempt_id;return s({matchesExecution:!0,settled:n,active:r,allocated:r&&t.allocation_ref!==null&&!await B(e,t.execution_attempt_id)})},Y=async(e,t)=>{let n=await F(e,t.executionAttemptId),r=await I(e,t.executionAttemptId);if(n===void 0||r===void 0)return{kind:`not-found`};let i=N(n);return h(i,P(r))?{kind:`resolved`,attempt:i}:r.token===null||r.token!==t.token||r.generation!==t.generation||r.owner_id!==t.ownerId?{kind:`stale`,attempt:i}:{kind:`authorized`,attempt:i,attemptRow:n,operation:r}},X=async(e,t)=>{let n=await Y(e,t);return n.kind===`authorized`?void 0:{kind:n.kind}},Z=async(e,t,n,r)=>{let i=await e.run(E`UPDATE test_execution_attempt
78
87
  SET status = ${`settled`}, settlement_kind = ${n}, claimable = ${0},
79
88
  operation_start_gate = ${`closed`}
80
89
  WHERE execution_attempt_id = ${t}
81
90
  AND settlement_kind IS NULL
82
- AND ${r}`);return i.rowsAffected,i},Z=async(e,t,n,r,i,a)=>{if(!a){let a=await X(e,t,`abandoned`,r);if(a.rowsAffected===0)return a;if((await e.run(E`UPDATE test_provider_operation
91
+ AND ${r}`);return i.rowsAffected,i},Q=async(e,t,n,r,i,a)=>{if(!a){let a=await Z(e,t,`abandoned`,r);if(a.rowsAffected===0)return a;if((await e.run(E`UPDATE test_provider_operation
83
92
  SET completion_evidence = ${JSON.stringify(i)}
84
93
  WHERE execution_attempt_id = ${t}
85
94
  AND ${H(n)}
86
- AND completion_evidence IS NULL`)).rowsAffected===0&&(await F(e,t))?.completion_evidence===null)throw Error(`Pre-allocation settlement succeeded without provider completion evidence`);return a}return e.run(E`UPDATE test_provider_operation
95
+ AND completion_evidence IS NULL`)).rowsAffected===0&&(await I(e,t))?.completion_evidence===null)throw Error(`Pre-allocation settlement succeeded without provider completion evidence`);return a}return e.run(E`UPDATE test_provider_operation
87
96
  SET completion_evidence = ${JSON.stringify(i)}
88
97
  WHERE execution_attempt_id = ${t}
89
98
  AND ${H(n)}
90
- AND completion_evidence IS NULL`)},Q=(e,t)=>{let n=he(e.allocationRef),r=t?E`CASE WHEN settlement_kind IS NULL AND ${K()} THEN 1 ELSE 0 END`:E`${0}`;return w(t=>V(async()=>{let i=await J(t,e.claim);if(i.kind!==`not-found`&&fe(i.attempt,n),i.kind===`resolved`)return{kind:`resolved`,allocationRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i;return a.allocationRef===null?async()=>{let i=await t.run(E`UPDATE test_execution_attempt
99
+ AND completion_evidence IS NULL`)},Me=(e,t)=>{let n=ye(e.allocationRef),r=t?E`CASE WHEN settlement_kind IS NULL AND ${K()} THEN 1 ELSE 0 END`:E`${0}`;return w(t=>V(async()=>{let i=await Y(t,e.claim);if(i.kind!==`not-found`&&ge(i.attempt,n),i.kind===`resolved`)return{kind:`resolved`,allocationRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i;return a.allocationRef===null?async()=>{let i=await t.run(E`UPDATE test_execution_attempt
91
100
  SET status = CASE WHEN settlement_kind IS NULL THEN ${`allocated`} ELSE status END,
92
101
  allocation_ref = ${JSON.stringify(n)},
93
102
  claimable = ${r}
94
103
  WHERE execution_attempt_id = ${a.executionAttemptId}
95
104
  AND allocation_ref IS NULL
96
105
  AND ${W(e.claim)}`);return i.rowsAffected===0||await t.run(E`UPDATE test_provider_operation SET obligation = ${`allocation-control`}
97
- WHERE execution_attempt_id = ${a.executionAttemptId}`),i}:d(a.allocationRef,n)?{kind:`duplicate`,allocationRef:a.allocationRef}:{kind:`conflict`,allocationRef:a.allocationRef}},{kind:`recorded`}))},Ee={async getAttemptWithAllocation(e){return w(async t=>{let n=await A(t,e);return n===void 0?null:N(n)})},async recordDiscoveredAllocation(e){return Q(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=de(e);return w(r=>V(async()=>{let i=await J(r,e.claim);if(i.kind===`stale`)return{kind:`stale`,storedRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a,attemptRow:o}=i;return a.executionId===e.executionId?a.allocationRef===null?{kind:`not-allocated`}:d(a.allocationRef,t)?()=>r.run(E`UPDATE test_execution_attempt SET allocation_ref = ${JSON.stringify(n)}
106
+ WHERE execution_attempt_id = ${a.executionAttemptId}`),i}:d(a.allocationRef,n)?{kind:`duplicate`,allocationRef:a.allocationRef}:{kind:`conflict`,allocationRef:a.allocationRef}},{kind:`recorded`}))},Ne={async getAttemptWithAllocation(e){return w(async t=>{let n=await F(t,e);return n===void 0?null:N(n)})},async recordDiscoveredAllocation(e){return Me(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=he(e);return w(r=>V(async()=>{let i=await Y(r,e.claim);if(i.kind===`stale`)return{kind:`stale`,storedRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a,attemptRow:o}=i;return a.executionId===e.executionId?a.allocationRef===null?{kind:`not-allocated`}:d(a.allocationRef,t)?()=>r.run(E`UPDATE test_execution_attempt SET allocation_ref = ${JSON.stringify(n)}
98
107
  WHERE execution_attempt_id = ${a.executionAttemptId}
99
108
  AND execution_id = ${e.executionId}
100
109
  AND allocation_ref = ${o.allocation_ref}
@@ -105,7 +114,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
105
114
  AND allocation_ref IS NOT NULL
106
115
  AND claimable = ${1}
107
116
  AND (claim_expires_at IS NULL OR claim_expires_at >= ${n})
108
- ORDER BY created_at ASC, execution_attempt_id ASC`)).map(e=>me(N(e)))})},async listOpenProviderOperations(e){let t=g(e.observedAt);if(!Number.isSafeInteger(e.limit)||e.limit<=0)throw RangeError(`Provider-operation recovery limit must be a positive safe integer`);return w(async n=>(await n.all(E`SELECT attempt.*, operation.generation, operation.owner_id, operation.token, operation.lease_expires_at,
117
+ ORDER BY created_at ASC, execution_attempt_id ASC`)).map(e=>ve(N(e)))})},async listOpenProviderOperations(e){let t=g(e.observedAt);if(!Number.isSafeInteger(e.limit)||e.limit<=0)throw RangeError(`Provider-operation recovery limit must be a positive safe integer`);return w(async n=>(await n.all(E`SELECT attempt.*, operation.generation, operation.owner_id, operation.token, operation.lease_expires_at,
109
118
  operation.obligation, operation.failure_count, operation.last_failure, operation.completion_evidence
110
119
  FROM test_execution_attempt AS attempt
111
120
  INNER JOIN test_provider_operation AS operation
@@ -119,7 +128,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
119
128
  ORDER BY attempt.created_at ASC, attempt.execution_attempt_id ASC
120
129
  LIMIT ${e.limit}`)).map(e=>({attempt:N(e),operation:P(e)})))}},$=async(e,t,n)=>{let{instruction:r}=t,{createdAt:i,bootstrapDeadlineAt:a}=n;try{await e.run(E`INSERT INTO test_execution_attempt
121
130
  (execution_attempt_id, execution_id, instruction, status, claimable, created_at, bootstrap_deadline_at)
122
- VALUES (${t.executionAttemptId}, ${t.executionId}, ${JSON.stringify(r)}, ${`pending`}, ${0}, ${i}, ${a})`)}catch(e){throw ye(e)?new te(t.executionAttemptId,{cause:e}):e}return await e.run(E`UPDATE test_execution_attempt
131
+ VALUES (${t.executionAttemptId}, ${t.executionId}, ${JSON.stringify(r)}, ${`pending`}, ${0}, ${i}, ${a})`)}catch(e){throw Te(e)?new te(t.executionAttemptId,{cause:e}):e}return await e.run(E`UPDATE test_execution_attempt
123
132
  SET claimable = ${0}
124
133
  WHERE execution_attempt_id = (
125
134
  SELECT execution_attempt_id
@@ -135,9 +144,9 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
135
144
  )`),await e.run(E`INSERT INTO test_active_execution_attempt (execution_id, execution_attempt_id)
136
145
  VALUES (${t.executionId}, ${t.executionAttemptId})
137
146
  ON CONFLICT(execution_id)
138
- DO UPDATE SET execution_attempt_id = excluded.execution_attempt_id`),{...ge,executionAttemptId:t.executionAttemptId,executionId:t.executionId,instruction:r,preparationReceipts:Object.freeze([]),status:`pending`,allocationRef:null,createdAt:i,bootstrapDeadlineAt:a,providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null}};return{async createAttempt(e){let t={...e,instruction:p(e.instruction)},n=y(e.bootstrapTimeoutMs);return w(e=>$(e,t,n))},async ensureAttempt(e){let t=ce(e);return w(async e=>{let n=(await e.all(E`SELECT execution_attempt_id FROM test_execution_attempt_request
139
- WHERE execution_id = ${t.executionId} AND request_key = ${t.requestKey}`))[0];if(n!==void 0){let r=await A(e,n.execution_attempt_id);return le(t,r===void 0?null:N(r))}let r=await $(e,t,y(t.bootstrapTimeoutMs));return await e.run(E`INSERT INTO test_execution_attempt_request (execution_id, request_key, execution_attempt_id)
140
- VALUES (${t.executionId}, ${t.requestKey}, ${r.executionAttemptId})`),{kind:`created`,attempt:structuredClone(r)}})},async readAttemptSettlement(e){let t=se(e);return w(async e=>{let n=await A(e,t.executionAttemptId);return n===void 0||n.execution_id!==t.executionId?{kind:`not-found`}:ue(t,{attempt:N(n),activeAttemptId:await B(e,t.executionId),outcomeText:n.workflow_result,controlObservation:j(n.outcome_control_observation)},u)})},async readBootstrapStartState(e){return w(async t=>{let n=await A(t,e.executionAttemptId);return n===void 0||n.execution_id!==e.executionId?null:{settled:n.settlement_kind!==null,active:await B(t,e.executionId)===e.executionAttemptId,allocated:n.allocation_ref!==null,allocationTerminated:await I(t,e.executionAttemptId),operationStartGate:D(f,n.operation_start_gate,`operation_start_gate`),bootstrapDeadlineAt:n.bootstrap_deadline_at}})},async beginProvisioning(e){let t=pe(e.allocationLifetime),n={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:g(e.leaseExpiresAt)};return w(r=>V(async()=>{let i=await A(r,e.executionAttemptId);if(i===void 0||i.execution_id!==e.executionId)return{kind:`not-found`};let a=N(i);return await B(r,e.executionId)===e.executionAttemptId?a.settlementKind==null?a.allocationRef===null?a.operationStartGate===`closed`?{kind:`fenced`}:a.status===`pending`?async()=>{let i=await r.run(E`UPDATE test_execution_attempt
147
+ DO UPDATE SET execution_attempt_id = excluded.execution_attempt_id`),{...be,executionAttemptId:t.executionAttemptId,executionId:t.executionId,instruction:r,preparationReceipts:Object.freeze([]),status:`pending`,allocationRef:null,createdAt:i,bootstrapDeadlineAt:a,providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null}};return{async createAttempt(e){let t={...e,instruction:p(e.instruction)},n=y(e.bootstrapTimeoutMs);return w(e=>$(e,t,n))},async ensureAttempt(e){let t=ce(e);return w(async e=>{let n=(await e.all(E`SELECT execution_attempt_id FROM test_execution_attempt_request
148
+ WHERE execution_id = ${t.executionId} AND request_key = ${t.requestKey}`))[0];if(n!==void 0){let r=await F(e,n.execution_attempt_id);return le(t,r===void 0?null:N(r))}let r=await $(e,t,y(t.bootstrapTimeoutMs));return await e.run(E`INSERT INTO test_execution_attempt_request (execution_id, request_key, execution_attempt_id)
149
+ VALUES (${t.executionId}, ${t.requestKey}, ${r.executionAttemptId})`),{kind:`created`,attempt:structuredClone(r)}})},async readAttemptSettlement(e){let t=se(e);return w(async e=>{let n=await F(e,t.executionAttemptId);return n===void 0||n.execution_id!==t.executionId?{kind:`not-found`}:ue(t,{attempt:N(n),activeAttemptId:await q(e,t.executionId),outcomeText:n.workflow_result,controlObservation:j(n.outcome_control_observation)},u)})},async readBootstrapStartState(e){return w(async t=>{let n=await F(t,e.executionAttemptId);return n===void 0||n.execution_id!==e.executionId?null:{settled:n.settlement_kind!==null,active:await q(t,e.executionId)===e.executionAttemptId,allocated:n.allocation_ref!==null,allocationTerminated:await B(t,e.executionAttemptId),operationStartGate:D(f,n.operation_start_gate,`operation_start_gate`),bootstrapDeadlineAt:n.bootstrap_deadline_at}})},async beginProvisioning(e){let t=_e(e.allocationLifetime),n={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:g(e.leaseExpiresAt)};return w(r=>V(async()=>{let i=await F(r,e.executionAttemptId);if(i===void 0||i.execution_id!==e.executionId)return{kind:`not-found`};let a=N(i);return await q(r,e.executionId)===e.executionAttemptId?a.settlementKind==null?a.allocationRef===null?a.operationStartGate===`closed`?{kind:`fenced`}:a.status===`pending`?async()=>{let i=await r.run(E`UPDATE test_execution_attempt
141
150
  SET status = ${`provisioning`},
142
151
  provider_id = ${e.providerId},
143
152
  allocation_lifetime = ${t},
@@ -151,43 +160,43 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
151
160
  AND ${K()}`);return i.rowsAffected===0||await r.run(E`INSERT INTO test_provider_operation
152
161
  (execution_attempt_id, generation, owner_id, token, lease_expires_at, obligation, failure_count)
153
162
  VALUES (${e.executionAttemptId}, ${n.generation}, ${n.ownerId}, ${n.token},
154
- ${n.leaseExpiresAt}, ${`provisioning-resolution`}, ${0})`),i}:{kind:`already-provisioning`}:{kind:`allocated`,allocationRef:a.allocationRef}:{kind:`resolved`,allocationRef:a.allocationRef}:{kind:`fenced`}},{kind:`started`,claim:n}))},async getProviderOperation(e){return w(async t=>{let n=await F(t,e);return n===void 0?null:P(n)})},async renewProviderOperationClaim(e){let t=g(e.leaseExpiresAt);return w(n=>V(async()=>await Y(n,e.claim)??(()=>n.run(E`UPDATE test_provider_operation SET lease_expires_at = ${t}
163
+ ${n.leaseExpiresAt}, ${`provisioning-resolution`}, ${0})`),i}:{kind:`already-provisioning`}:{kind:`allocated`,allocationRef:a.allocationRef}:{kind:`resolved`,allocationRef:a.allocationRef}:{kind:`fenced`}},{kind:`started`,claim:n}))},async getProviderOperation(e){return w(async t=>{let n=await I(t,e);return n===void 0?null:P(n)})},async renewProviderOperationClaim(e){let t=g(e.leaseExpiresAt);return w(n=>V(async()=>await X(n,e.claim)??(()=>n.run(E`UPDATE test_provider_operation SET lease_expires_at = ${t}
155
164
  WHERE execution_attempt_id = ${e.claim.executionAttemptId}
156
- AND ${W(e.claim)}`)),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:t}}))},async takeOverProviderOperation(e){return w(async t=>{let n=await A(t,e.executionAttemptId),r=await F(t,e.executionAttemptId);if(n===void 0||r===void 0)return{kind:`not-found`};if(h(N(n),P(r)))return{kind:`resolved`};let i=g(e.observedAt);if(r.owner_id!==null&&r.lease_expires_at!==null&&_(r.lease_expires_at)>_(i))return{kind:`stale`};let a={executionAttemptId:e.executionAttemptId,generation:r.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:g(e.leaseExpiresAt)},{rowsAffected:o}=await t.run(E`UPDATE test_provider_operation
165
+ AND ${W(e.claim)}`)),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:t}}))},async takeOverProviderOperation(e){return w(async t=>{let n=await F(t,e.executionAttemptId),r=await I(t,e.executionAttemptId);if(n===void 0||r===void 0)return{kind:`not-found`};if(h(N(n),P(r)))return{kind:`resolved`};let i=g(e.observedAt);if(r.owner_id!==null&&r.lease_expires_at!==null&&_(r.lease_expires_at)>_(i))return{kind:`stale`};let a={executionAttemptId:e.executionAttemptId,generation:r.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:g(e.leaseExpiresAt)},{rowsAffected:o}=await t.run(E`UPDATE test_provider_operation
157
166
  SET generation = ${a.generation}, owner_id = ${a.ownerId}, token = ${a.token},
158
167
  lease_expires_at = ${a.leaseExpiresAt}
159
168
  WHERE execution_attempt_id = ${e.executionAttemptId}
160
169
  AND generation = ${r.generation}
161
- AND ${U(e.executionAttemptId)}`);if(o===0){let n=await A(t,e.executionAttemptId),r=await F(t,e.executionAttemptId);return n!==void 0&&r!==void 0&&h(N(n),P(r))?{kind:`resolved`}:{kind:`stale`}}return{kind:`claimed`,claim:a}})},async handoffProviderOperation(e){let t=e.evidence===void 0?null:x.parse(e.evidence);return w(n=>V(async()=>await Y(n,e.claim)??(()=>n.run(t===null?E`UPDATE test_provider_operation
170
+ AND ${U(e.executionAttemptId)}`);if(o===0){let n=await F(t,e.executionAttemptId),r=await I(t,e.executionAttemptId);return n!==void 0&&r!==void 0&&h(N(n),P(r))?{kind:`resolved`}:{kind:`stale`}}return{kind:`claimed`,claim:a}})},async handoffProviderOperation(e){let t=e.evidence===void 0?null:x.parse(e.evidence);return w(n=>V(async()=>await X(n,e.claim)??(()=>n.run(t===null?E`UPDATE test_provider_operation
162
171
  SET owner_id = NULL, token = NULL, lease_expires_at = NULL
163
172
  WHERE execution_attempt_id = ${e.claim.executionAttemptId}
164
173
  AND ${W(e.claim)}`:E`UPDATE test_provider_operation
165
174
  SET owner_id = NULL, token = NULL, lease_expires_at = NULL,
166
175
  last_failure = ${JSON.stringify(t)}
167
176
  WHERE execution_attempt_id = ${e.claim.executionAttemptId}
168
- AND ${W(e.claim)}`)),{kind:`recorded`}))},async recordProviderOperationUncertainty(e){let t=x.parse(e.evidence);return w(n=>V(async()=>await Y(n,e.claim)??(()=>n.run(E`UPDATE test_provider_operation
177
+ AND ${W(e.claim)}`)),{kind:`recorded`}))},async recordProviderOperationUncertainty(e){let t=x.parse(e.evidence);return w(n=>V(async()=>await X(n,e.claim)??(()=>n.run(E`UPDATE test_provider_operation
169
178
  SET failure_count = failure_count + 1, last_failure = ${JSON.stringify(t)}
170
179
  WHERE execution_attempt_id = ${e.claim.executionAttemptId}
171
- AND ${W(e.claim)}`)),{kind:`recorded`}))},async completeProviderOperation(e){let t=x.parse(e.evidence);return w(async n=>{let r=await A(n,e.claim.executionAttemptId),i=await F(n,e.claim.executionAttemptId);if(r===void 0||i===void 0)return{kind:`not-found`};if(!(i.generation===e.claim.generation&&i.owner_id===e.claim.ownerId&&i.token===e.claim.token))return{kind:`stale`};if(h(N(r),P(i)))return{kind:`already-completed`};if(i.completion_evidence!==null)return{kind:`evidence-recorded`};if((await n.run(E`UPDATE test_provider_operation
180
+ AND ${W(e.claim)}`)),{kind:`recorded`}))},async completeProviderOperation(e){let t=x.parse(e.evidence);return w(async n=>{let r=await F(n,e.claim.executionAttemptId),i=await I(n,e.claim.executionAttemptId);if(r===void 0||i===void 0)return{kind:`not-found`};if(!(i.generation===e.claim.generation&&i.owner_id===e.claim.ownerId&&i.token===e.claim.token))return{kind:`stale`};if(h(N(r),P(i)))return{kind:`already-completed`};if(i.completion_evidence!==null)return{kind:`evidence-recorded`};if((await n.run(E`UPDATE test_provider_operation
172
181
  SET completion_evidence = ${JSON.stringify(t)}
173
182
  WHERE execution_attempt_id = ${e.claim.executionAttemptId}
174
183
  AND ${H(e.claim)}
175
- AND completion_evidence IS NULL`)).rowsAffected>0){let t=await A(n,e.claim.executionAttemptId);return t===void 0?{kind:`not-found`}:t.settlement_kind===null?{kind:`evidence-recorded`}:{kind:`completed`}}let a=await A(n,e.claim.executionAttemptId),o=await F(n,e.claim.executionAttemptId);return a===void 0||o===void 0?{kind:`not-found`}:o.generation===e.claim.generation&&o.owner_id===e.claim.ownerId&&o.token===e.claim.token?h(N(a),P(o))?{kind:`already-completed`}:o.completion_evidence===null?{kind:`stale`}:{kind:`evidence-recorded`}:{kind:`stale`}})},async recordAllocation(e){return Q(e,!0)},async recordProvisioningAbsent(e){let t=x.parse(e.evidence),n=!1;return w(r=>V(async()=>{let i=await J(r,e.claim);if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i;return a.executionId===e.executionId?a.allocationRef===null?(n=a.settlementKind!==null,()=>Z(r,a.executionAttemptId,e.claim,E`execution_id = ${e.executionId}
184
+ AND completion_evidence IS NULL`)).rowsAffected>0){let t=await F(n,e.claim.executionAttemptId);return t===void 0?{kind:`not-found`}:t.settlement_kind===null?{kind:`evidence-recorded`}:{kind:`completed`}}let a=await F(n,e.claim.executionAttemptId),o=await I(n,e.claim.executionAttemptId);return a===void 0||o===void 0?{kind:`not-found`}:o.generation===e.claim.generation&&o.owner_id===e.claim.ownerId&&o.token===e.claim.token?h(N(a),P(o))?{kind:`already-completed`}:o.completion_evidence===null?{kind:`stale`}:{kind:`evidence-recorded`}:{kind:`stale`}})},async recordAllocation(e){return Me(e,!0)},async recordProvisioningAbsent(e){let t=x.parse(e.evidence),n=!1;return w(r=>V(async()=>{let i=await Y(r,e.claim);if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i;return a.executionId===e.executionId?a.allocationRef===null?(n=a.settlementKind!==null,()=>Q(r,a.executionAttemptId,e.claim,E`execution_id = ${e.executionId}
176
185
  AND allocation_ref IS NULL
177
- AND ${H(e.claim)}`,t,n)):{kind:`allocated`,allocationRef:a.allocationRef}:{kind:`not-found`}},()=>n?{kind:`completed`}:{kind:`recorded`}))},async recordProvisionerIncarnationLost(e){let t=x.parse(e.proof.evidence),n=!1;return w(r=>V(async()=>{let i=await J(r,e.claim);if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i,o=oe(a,e);return o===null?(n=a.settlementKind!==null,()=>Z(r,a.executionAttemptId,e.claim,E`execution_id = ${e.executionId}
186
+ AND ${H(e.claim)}`,t,n)):{kind:`allocated`,allocationRef:a.allocationRef}:{kind:`not-found`}},()=>n?{kind:`completed`}:{kind:`recorded`}))},async recordProvisionerIncarnationLost(e){let t=x.parse(e.proof.evidence),n=!1;return w(r=>V(async()=>{let i=await Y(r,e.claim);if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i,o=oe(a,e);return o===null?(n=a.settlementKind!==null,()=>Q(r,a.executionAttemptId,e.claim,E`execution_id = ${e.executionId}
178
187
  AND allocation_ref IS NULL
179
188
  AND allocation_lifetime = ${`provisioner-process-bound`}
180
189
  AND provisioner_incarnation_id = ${e.proof.provisionerIncarnationId}
181
- AND ${H(e.claim)}`,t,n)):o},()=>n?{kind:`completed`}:{kind:`recorded`}))},async recordAllocationTerminated(e){let t=x.parse(e.evidence);return w(n=>V(async()=>{let r=await J(n,e.claim);if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i}=r;return i.allocationRef===null?{kind:`not-allocated`}:()=>n.run(E`UPDATE test_provider_operation
190
+ AND ${H(e.claim)}`,t,n)):o},()=>n?{kind:`completed`}:{kind:`recorded`}))},async recordAllocationTerminated(e){let t=x.parse(e.evidence);return w(n=>V(async()=>{let r=await Y(n,e.claim);if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i}=r;return i.allocationRef===null?{kind:`not-allocated`}:()=>n.run(E`UPDATE test_provider_operation
182
191
  SET obligation = ${`terminal-convergence`}, last_failure = ${JSON.stringify(t)}
183
192
  WHERE execution_attempt_id = ${i.executionAttemptId}
184
193
  AND ${W(e.claim)}
185
194
  AND EXISTS (SELECT 1 FROM test_execution_attempt
186
195
  WHERE execution_attempt_id = ${i.executionAttemptId}
187
- AND allocation_ref IS NOT NULL)`)},{kind:`recorded`}))},async recordInfrastructureFailure(e){return w(t=>V(async()=>{let n=await J(t,e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.settlementKind===null?r.allocationRef===null?{kind:`not-allocated`}:D(m,i.obligation,`obligation`)===`terminal-convergence`?()=>X(t,r.executionAttemptId,`infrastructure-failure`,E`execution_id = ${e.executionId}
196
+ AND allocation_ref IS NOT NULL)`)},{kind:`recorded`}))},async recordInfrastructureFailure(e){return w(t=>V(async()=>{let n=await Y(t,e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.settlementKind===null?r.allocationRef===null?{kind:`not-allocated`}:D(m,i.obligation,`obligation`)===`terminal-convergence`?()=>Z(t,r.executionAttemptId,`infrastructure-failure`,E`execution_id = ${e.executionId}
188
197
  AND allocation_ref IS NOT NULL
189
198
  AND ${G(r.executionAttemptId)}
190
- AND ${H(e.claim)}`):{kind:`not-terminated`}:{kind:`resolved`}:{kind:`not-found`}},{kind:`recorded`}))},async registerRuntime(e){return w(async t=>{let n=0,r=await V(async()=>{let r=await A(t,e.executionAttemptId);if(r===void 0||r.execution_id!==e.executionId)return{kind:`not-found`};let i=await q(t,r);if(i!==null)return i;let a=M(r),o=ae(a,e);return o===null?(n=a.runtimeGeneration+1,()=>t.run(E`UPDATE test_execution_attempt
199
+ AND ${H(e.claim)}`):{kind:`not-terminated`}:{kind:`resolved`}:{kind:`not-found`}},{kind:`recorded`}))},async registerRuntime(e){return w(async t=>{let n=0,r=await V(async()=>{let r=await F(t,e.executionAttemptId);if(r===void 0||r.execution_id!==e.executionId)return{kind:`not-found`};let i=await J(t,r);if(i!==null)return i;let a=M(r),o=ae(a,e);return o===null?(n=a.runtimeGeneration+1,()=>t.run(E`UPDATE test_execution_attempt
191
200
  SET runtime_generation = ${n},
192
201
  runtime_incarnation_id = ${e.runtimeIncarnationId},
193
202
  runtime_ready_at = NULL,
@@ -203,7 +212,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
203
212
  AND (active_operation_id IS NULL OR active_operation_kind = ${`runtime-probe`})
204
213
  AND allocation_ref IS NOT NULL
205
214
  AND NOT ${G(e.executionAttemptId)}
206
- AND ${K()}`)):o},{kind:`applied`});return r.kind===`applied`?{kind:`registered`,runtimeGeneration:n}:r})},async admitOperation(e){let t=crypto.randomUUID(),n=g(new Date().toISOString()),r=e.operationKind===`runtime-probe`?E`1 = 1`:E`runtime_ready_at IS NOT NULL`;return w(i=>V(async()=>{let a=await A(i,e.executionAttemptId);if(a===void 0||a.execution_id!==e.executionId)return{kind:`not-found`};let s=await q(i,a);if(s!==null)return s;let c=o(M(a),e,n,N(a));return c===null?()=>i.run(E`UPDATE test_execution_attempt
215
+ AND ${K()}`)):o},{kind:`applied`});return r.kind===`applied`?{kind:`registered`,runtimeGeneration:n}:r})},async admitOperation(e){let t=crypto.randomUUID(),n=g(new Date().toISOString()),r=e.operationKind===`runtime-probe`?E`1 = 1`:E`runtime_ready_at IS NOT NULL`;return w(i=>V(async()=>{let a=await F(i,e.executionAttemptId);if(a===void 0||a.execution_id!==e.executionId)return{kind:`not-found`};let s=await J(i,a);if(s!==null)return s;let c=o(M(a),e,n,N(a));return c===null?()=>i.run(E`UPDATE test_execution_attempt
207
216
  SET active_operation_id = ${t},
208
217
  active_operation_kind = ${e.operationKind},
209
218
  active_operation_key = ${e.admissionKey},
@@ -220,7 +229,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
220
229
  AND allocation_ref IS NOT NULL
221
230
  AND NOT ${G(e.executionAttemptId)}
222
231
  AND ${r}
223
- AND ${K()}`):c},{kind:`admitted`,operationId:t,runtimeGeneration:e.runtimeGeneration,admittedAt:n}))},async getInstruction(e){return w(async t=>{let n=await A(t,e.executionAttemptId);return n?.execution_id===e.executionId?p(JSON.parse(n.instruction)):null})},async reportOperation(e){let t=_e(e.result);return w(n=>V(async()=>{let r=await A(n,e.executionAttemptId);if(r===void 0||r.execution_id!==e.executionId)return{kind:`not-found`};let i=N(r),a=ie({matchesExecution:!0,settled:r.settlement_kind!==null,active:await B(n,e.executionId)===e.executionAttemptId,allocated:r.allocation_ref!==null&&!await I(n,e.executionAttemptId)},i,i,{...e,result:t});if(a!==null)return a;let o=v([...i.preparationReceipts,{operationId:e.operationId,runtimeGeneration:e.runtimeGeneration,result:t}]);return()=>n.run(E`UPDATE test_execution_attempt
232
+ AND ${K()}`):c},{kind:`admitted`,operationId:t,runtimeGeneration:e.runtimeGeneration,admittedAt:n}))},async getInstruction(e){return w(async t=>{let n=await F(t,e.executionAttemptId);return n?.execution_id===e.executionId?p(JSON.parse(n.instruction)):null})},async reportOperation(e){let t=xe(e.result);return w(n=>V(async()=>{let r=await F(n,e.executionAttemptId);if(r===void 0||r.execution_id!==e.executionId)return{kind:`not-found`};let i=N(r),a=ie({matchesExecution:!0,settled:r.settlement_kind!==null,active:await q(n,e.executionId)===e.executionAttemptId,allocated:r.allocation_ref!==null&&!await B(n,e.executionAttemptId)},i,i,{...e,result:t});if(a!==null)return a;let o=v([...i.preparationReceipts,{operationId:e.operationId,runtimeGeneration:e.runtimeGeneration,result:t}]);return()=>n.run(E`UPDATE test_execution_attempt
224
233
  SET preparation_receipts = ${JSON.stringify(o)},
225
234
  active_operation_id = NULL,
226
235
  active_operation_kind = NULL,
@@ -239,7 +248,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
239
248
  AND preparation_receipts = ${r.preparation_receipts}
240
249
  AND allocation_ref IS NOT NULL
241
250
  AND NOT ${G(e.executionAttemptId)}
242
- AND ${K()}`)},{kind:`accepted`,binding:t.binding}))},async completeOperation(t){return w(n=>V(async()=>{let r=await A(n,t.executionAttemptId);if(r===void 0)return{kind:`not-found`};if(r.settlement_kind!==null)return{kind:`resolved`};let i=e(M(r),t);return i===null?()=>n.run(E`UPDATE test_execution_attempt
251
+ AND ${K()}`)},{kind:`accepted`,binding:t.binding}))},async completeOperation(t){return w(n=>V(async()=>{let r=await F(n,t.executionAttemptId);if(r===void 0)return{kind:`not-found`};if(r.settlement_kind!==null)return{kind:`resolved`};let i=e(M(r),t);return i===null?()=>n.run(E`UPDATE test_execution_attempt
243
252
  SET active_operation_id = NULL,
244
253
  active_operation_kind = NULL,
245
254
  active_operation_key = NULL,
@@ -250,7 +259,7 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
250
259
  AND settlement_kind IS NULL
251
260
  AND active_operation_id = ${t.operationId}
252
261
  AND active_operation_kind IN (${`runtime-probe`}, ${`workflow-run`})
253
- AND active_operation_generation = ${t.runtimeGeneration}`):i},{kind:`completed`}))},async markRuntimeReady(e){let t=g(e.readyAt);return w(r=>V(async()=>{let i=await A(r,e.executionAttemptId);if(i===void 0||i.execution_id!==e.executionId)return{kind:`not-found`};let a=await q(r,i);if(a!==null)return a;let o=n(M(i),e);return o===null?()=>r.run(E`UPDATE test_execution_attempt SET runtime_ready_at = ${t}
262
+ AND active_operation_generation = ${t.runtimeGeneration}`):i},{kind:`completed`}))},async markRuntimeReady(e){let t=g(e.readyAt);return w(r=>V(async()=>{let i=await F(r,e.executionAttemptId);if(i===void 0||i.execution_id!==e.executionId)return{kind:`not-found`};let a=await J(r,i);if(a!==null)return a;let o=n(M(i),e);return o===null?()=>r.run(E`UPDATE test_execution_attempt SET runtime_ready_at = ${t}
254
263
  WHERE execution_attempt_id = ${e.executionAttemptId}
255
264
  AND execution_id = ${e.executionId}
256
265
  AND settlement_kind IS NULL
@@ -259,20 +268,28 @@ import{_ as e,a as t,b as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as ee,
259
268
  AND active_operation_id IS NULL
260
269
  AND allocation_ref IS NOT NULL
261
270
  AND NOT ${G(e.executionAttemptId)}
262
- AND ${K()}`):o},{kind:`ready`,acceptedAt:t}))},async getAttemptControlState(e){return w(async t=>{let n=await A(t,e);return n===void 0?null:M(n)})},async requestAttemptCancellation(e){let t=i(e);return w(async e=>{let n=await A(e,t.executionAttemptId);if(n===void 0||n.execution_id!==t.executionId)return{kind:`not-found`};let r=l(await T(e,t.executionAttemptId),t,new Date().toISOString());return r.kind===`accepted`&&await O(e,t.executionAttemptId,r.intent),r})},async requestCancellation(e){let t=a(e),n={requestKey:crypto.randomUUID(),reason:t.reason};await w(async e=>{let r=await e.all(E`SELECT execution_attempt_id FROM test_execution_attempt WHERE execution_id = ${t.executionId}`),i=new Date().toISOString(),a=[];for(let t of r){let r=l(await T(e,t.execution_attempt_id),n,i);if(r.kind===`conflict`)throw Error(`Generated cancellation request key conflicts with its receipt`);a.push({executionAttemptId:t.execution_attempt_id,decision:r})}for(let{executionAttemptId:t,decision:n}of a)n.kind===`accepted`&&await O(e,t,n.intent)})},async readCancellation(e){return w(t=>T(t,e))},async getActiveAttempt(e,t){return w(async n=>{if(await B(n,e)!==t)return null;let r=await A(n,t);return r===void 0?null:N(r)})},canonicalizeOutcome(e){return ne(u,e)},decodeOutcome(e){return t(u,e)},async commitOutcome(e){let n=e.result,i=e.runtimeFence,a=i===void 0?E`1 = 1`:E`
271
+ AND ${K()}`):o},{kind:`ready`,acceptedAt:t}))},async getAttemptControlState(e){return w(async t=>{let n=await F(t,e);return n===void 0?null:M(n)})},async requestAttemptCancellation(e){let t=i(e);return w(async e=>{let n=await F(e,t.executionAttemptId);if(n===void 0||n.execution_id!==t.executionId)return{kind:`not-found`};let r=l(await T(e,t.executionAttemptId),t,new Date().toISOString());return r.kind===`accepted`&&await A(e,t.executionAttemptId,r.intent),r})},async requestCancellation(e){let t=a(e),n={requestKey:crypto.randomUUID(),reason:t.reason};await w(async e=>{let r=await e.all(E`SELECT execution_attempt_id FROM test_execution_attempt WHERE execution_id = ${t.executionId}`),i=new Date().toISOString(),a=[];for(let t of r){let r=l(await T(e,t.execution_attempt_id),n,i);if(r.kind===`conflict`)throw Error(`Generated cancellation request key conflicts with its receipt`);a.push({executionAttemptId:t.execution_attempt_id,decision:r})}for(let{executionAttemptId:t,decision:n}of a)n.kind===`accepted`&&await A(e,t,n.intent)})},async readCancellation(e){return w(t=>T(t,e))},async readAttemptCancellationControl(e){let{executionId:t,executionAttemptId:n}=e;return w(async e=>{let r=await F(e,n);return r===void 0||r.execution_id!==t?null:{control:M(r),cancellation:await T(e,n),evidence:await O(e,n)}})},async recordAttemptControlReceipt(e){let t=pe(e),{executionId:n,...r}=t,{executionAttemptId:i,controlRevision:a,runtimeGeneration:o}=t;return w(async e=>{let n=await F(e,i),s=(await O(e,i)).find(e=>e.controlRevision===a&&e.runtimeGeneration===o),c=me(n===void 0?null:N(n),await T(e,i),s?.receipt??null,t);return c.kind===`accepted`&&await e.run(E`INSERT INTO test_execution_attempt_control_evidence
272
+ (execution_attempt_id, control_revision, runtime_generation, receipt_json)
273
+ VALUES (${i}, ${a}, ${o}, ${JSON.stringify(r)})
274
+ ON CONFLICT (execution_attempt_id, control_revision, runtime_generation)
275
+ DO UPDATE SET receipt_json = excluded.receipt_json`),c})},async reportAttemptControl(e){let t=de(e),{executionId:n,...r}=t,{executionAttemptId:i,controlRevision:a,runtimeGeneration:o}=t;return w(async e=>{let n=await F(e,i),s=(await O(e,i)).find(e=>e.controlRevision===a&&e.runtimeGeneration===o),c=fe(n===void 0?null:N(n),await T(e,i),s?.report??null,t);return c.kind===`accepted`&&await e.run(E`INSERT INTO test_execution_attempt_control_evidence
276
+ (execution_attempt_id, control_revision, runtime_generation, report_json)
277
+ VALUES (${i}, ${a}, ${o}, ${JSON.stringify(r)})
278
+ ON CONFLICT (execution_attempt_id, control_revision, runtime_generation)
279
+ DO UPDATE SET report_json = excluded.report_json`),c})},async getActiveAttempt(e,t){return w(async n=>{if(await q(n,e)!==t)return null;let r=await F(n,t);return r===void 0?null:N(r)})},canonicalizeOutcome(e){return ne(u,e)},decodeOutcome(e){return t(u,e)},async commitOutcome(e){let n=e.result,i=e.runtimeFence,a=i===void 0?E`1 = 1`:E`
263
280
  runtime_generation = ${i.runtimeGeneration}
264
281
  AND ${i.operationId===null?E`active_operation_id IS NULL`:E`active_operation_id = ${i.operationId}
265
- AND active_operation_generation = ${i.runtimeGeneration}`}`;return w(o=>{let s=null;return V(async()=>{if(await B(o,e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let c=await A(o,e.executionAttemptId);if(c===void 0)return{kind:`fenced`};let l=c.workflow_result;if(l!==null){let e=t(u,l);return r(l,n.text)?{kind:`duplicate`,outcome:e,text:l,controlObservation:j(c.outcome_control_observation)}:{kind:`conflict`}}return c.settlement_kind===null?(i!==void 0&&ee(M(c),i),s=re(await T(o,e.executionAttemptId)),async()=>{let t=await o.run(E`UPDATE test_execution_attempt SET workflow_result = ${n.text},
282
+ AND active_operation_generation = ${i.runtimeGeneration}`}`;return w(o=>{let s=null;return V(async()=>{if(await q(o,e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let c=await F(o,e.executionAttemptId);if(c===void 0)return{kind:`fenced`};let l=c.workflow_result;if(l!==null){let e=t(u,l);return r(l,n.text)?{kind:`duplicate`,outcome:e,text:l,controlObservation:j(c.outcome_control_observation)}:{kind:`conflict`}}return c.settlement_kind===null?(i!==void 0&&ee(M(c),i),s=re(await T(o,e.executionAttemptId)),async()=>{let t=await o.run(E`UPDATE test_execution_attempt SET workflow_result = ${n.text},
266
283
  outcome_control_observation = ${JSON.stringify(s)}
267
284
  WHERE execution_attempt_id = ${e.executionAttemptId}
268
285
  AND workflow_result IS NULL
269
286
  AND settlement_kind IS NULL
270
287
  AND ${a}
271
- AND ${K()}`);return t.rowsAffected===0?t:X(o,e.executionAttemptId,`outcome`,E`workflow_result IS NOT NULL`)}):{kind:`conflict`}},()=>({kind:`accepted`,outcome:t(u,n.text),text:n.text,controlObservation:s}))})},async abandonPendingAttempt(e,t){return w(n=>V(async()=>{if(await B(n,t)!==e)return{kind:`fenced`};let r=await A(n,e);if(r===void 0)return{kind:`fenced`};let i=N(r);return i.status===`allocated`?{kind:`allocated`}:i.status===`provisioning`?{kind:`provisioning`}:i.status===`settled`?{kind:i.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:()=>n.run(E`UPDATE test_execution_attempt
288
+ AND ${K()}`);return t.rowsAffected===0?t:Z(o,e.executionAttemptId,`outcome`,E`workflow_result IS NOT NULL`)}):{kind:`conflict`}},()=>({kind:`accepted`,outcome:t(u,n.text),text:n.text,controlObservation:s}))})},async abandonPendingAttempt(e,t){return w(n=>V(async()=>{if(await q(n,t)!==e)return{kind:`fenced`};let r=await F(n,e);if(r===void 0)return{kind:`fenced`};let i=N(r);return i.status===`allocated`?{kind:`allocated`}:i.status===`provisioning`?{kind:`provisioning`}:i.status===`settled`?{kind:i.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:()=>n.run(E`UPDATE test_execution_attempt
272
289
  SET status = ${`settled`}, settlement_kind = ${`abandoned`}, claimable = ${0},
273
290
  operation_start_gate = ${`closed`}
274
291
  WHERE execution_attempt_id = ${e}
275
292
  AND execution_id = ${t}
276
293
  AND status = ${`pending`}
277
294
  AND settlement_kind IS NULL
278
- AND ${K()}`)},{kind:`abandoned`}))},recovery:Ee}}export{q as createSqliteAttemptRepository};
295
+ AND ${K()}`)},{kind:`abandoned`}))},recovery:Ne}}export{q as createSqliteAttemptRepository};
@@ -0,0 +1,2 @@
1
+ import{resolveMakaioHome as e}from"./runtime-node/makaio-config.mjs";import{t}from"./extension-package-provenance-Dr7JXjLS.mjs";import{_ as n,d as r,l as i,n as a,o,r as s,u as c,x as l,y as u}from"./bootstrap-start-client-D7t7d9ty.mjs";import{mintOrRotateWorkflowExecutionBusSecret as d}from"./runtime-node/workflow-execution-bus-access.mjs";import{z as f}from"zod";import{execFile as p,spawn as m}from"node:child_process";import{promisify as ee}from"node:util";import*as h from"node:fs/promises";import{access as te}from"node:fs/promises";import*as g from"node:path";import{basename as ne,isAbsolute as re,join as ie,relative as ae}from"node:path";import*as _ from"node:crypto";import{randomUUID as v}from"node:crypto";import{constants as oe}from"node:fs";import{AdapterSubjects as se,BoundedRecoveryEvidenceSchema as y,ExecutionAttemptSchemas as b,ExecutionAttemptSubjects as x,FrameworkContractNamespaces as ce,FrameworkStorageNamespaces as le,JsonValueSchema as ue,PRE_REQUEST_REJECTION_CODE as de,PROVIDER_ALLOCATION_REF_VERSION as fe,ProviderAllocationRefSchema as pe,RECOVERY_EVIDENCE_LIMITS as S,WorkerCapabilitiesSchema as me,WorkerSchemas as he,WorkerSubjects as C,WorkflowRunContextSchema as ge,WorkflowRunResultSchema as _e,WorkflowWorkerConfigSchema as ve,createWorkflowCancelSubject as ye}from"@makaio/framework/contracts";import{BusAbortError as be,createBusInstance as w,isRequestCancellation as T,waitForSubscriptionPropagation as xe}from"@makaio/framework/bus";import{ExtensionCoordinator as Se,KernelSubjects as Ce,coalesceExtensionOverrides as we,filterEligibleExtensions as Te}from"@makaio/framework/kernel";import{BaseService as Ee}from"@makaio/framework/service-base";import{AdapterRuntimeSubjects as De,registerAdapterRuntimeIdentityHandlers as Oe}from"@makaio/framework/services/adapter-runtime";import{devNull as E}from"node:os";import{CLIDetectionNamespace as ke,CLIDetectionSubjects as Ae}from"@makaio/framework/services/cli-detection/namespace";import{SessionOrchestratorToken as je,ToolRegistryToken as Me,canonicalModelPackage as Ne,createSubagentServicePackage as Pe,createToolContributionProcessor as Fe,frameworkCorePackages as D,sessionBridgePackage as Ie,sessionOrchestratorPackage as Le,sessionPackage as Re,sessionStoragePackage as ze,toolRegistryPackage as Be}from"@makaio/framework/services";import{AdapterSubsystemSubjects as Ve}from"@makaio/framework/services/adapter-subsystem";import{createClientsCorePackage as He}from"@makaio/framework/clients";import{AdapterSubsystemToken as O,createAdapterSubsystemContributionProcessor as Ue,createAdapterSubsystemPackage as We,orderAfterAdapterSubsystem as Ge}from"@makaio/framework/adapter-subsystem";import{execa as Ke}from"execa";import qe from"piscina";import{ExecutionAttemptAuthority as Je,WORKFLOW_WORKLOAD_KIND as Ye,WORKFLOW_WORKLOAD_VERSION as Xe,WorkflowStorageSubjects as Ze,buildWorkflowAttemptInstruction as Qe,parseWorkflowAttemptInstruction as k,runAuthorityDispatchedAttempt as $e,toCommittedWorkflowRunnerCompletion as et}from"@makaio/framework/workflow-engine";import{runWorkflowOrchestrator as tt}from"@makaio/framework/workflow-engine/workflow-orchestrator";import{setTimeout as nt}from"node:timers/promises";function A(e){return e.on(se.getCapabilities,async t=>{let{adapterName:n,adapterId:r}=t.payload;if(r){await t.next();return}if(n){let r=await e.requestOptional(De.resolveId,{adapterName:n}),i=r.handled?r.data.adapterId:void 0;i&&(t.payload.adapterId=i)}await t.next()},{priority:20})}function j(e){let{coordinator:t,configRepository:n,platformDefaults:r,prepareAuthRuntime:i,runtimeSnapshotHandlerPriority:a,runtimeDefinitionHandlerPriority:o}=e,s=We({configRepository:n,coordinator:t,platformDefaults:r,...i!==void 0&&{prepareAuthRuntime:i},...a!==void 0&&{runtimeSnapshotHandlerPriority:a},...o!==void 0&&{runtimeDefinitionHandlerPriority:o}});return t.registerContributionProcessor(Ue({getAdapterSubsystemService:()=>t.getExtensionService(O)})),{adapterSubsystemPackage:s}}function M(e){let{bus:t,currentMachineId:n}=e,r=Oe(t,{currentMachineId:n,listKnownAdapterNames:e.listKnownAdapterNames??(async()=>{let{configs:e}=await t.request(Ve.listAdapterConfigs,{});return e.map(e=>e.name)}),...e.resolveLiveAdapterId!==void 0&&{resolveLiveAdapterId:e.resolveLiveAdapterId},...e.resolveLiveAdapterIdentity!==void 0&&{resolveLiveAdapterIdentity:e.resolveLiveAdapterIdentity},...e.listLiveAdapterIdentities!==void 0&&{listLiveAdapterIdentities:e.listLiveAdapterIdentities}}),i=A(t);return{cleanup:()=>{r.cleanup(),i()}}}function N(e,t){if(!(e instanceof Error))return!1;let{rootPackageName:n,subpath:r}=rt(t),i=(r===void 0?[t]:[t,n]).flatMap(e=>[`Cannot find package '${e}'`,`Cannot find module '${e}'`,`Cannot find package "${e}"`,`Cannot find module "${e}"`]),a=e;return(a.code===`ERR_MODULE_NOT_FOUND`||a.code===`MODULE_NOT_FOUND`)&&i.some(t=>e.message.includes(t))||a.code===`ERR_PACKAGE_PATH_NOT_EXPORTED`&&r!==void 0&&e.message.includes(`Package subpath '${r}' is not defined by "exports"`)&&it(e.message,n)?!0:i.some(t=>e.message.includes(t))}async function P(e){try{return await import(e)}catch(t){if(N(t,e))return null;throw t}}function rt(e){let t=e.split(`/`);return e.startsWith(`@`)?{rootPackageName:t.slice(0,2).join(`/`),subpath:t.length>2?`./${t.slice(2).join(`/`)}`:void 0}:{rootPackageName:t[0]??e,subpath:t.length>1?`./${t.slice(1).join(`/`)}`:void 0}}function it(e,t){let n=t,r=t.replaceAll(`/`,`\\`);return e.includes(`/${n}/package.json`)||e.includes(`\\${r}\\package.json`)}async function F(e,t=process.env,n=process.platform){let r=t[Object.keys(t).find(e=>e.toUpperCase()===`PATH`)??`PATH`]??``,i=(t.PATHEXT??`.EXE;.CMD;.BAT;.COM`).split(`;`).filter(Boolean),a=n===`win32`?g.extname(e)===``?i:[``,...i]:[``];for(let t of r.split(g.delimiter)){let n=t.replace(/^"|"$/gu,``),r=g.resolve(n||process.cwd());for(let t of a){let n=g.join(r,`${e}${t}`);try{return await te(n,oe.X_OK),n}catch{}}}}async function I(e,t=5e3,n=1e3){let{stdout:r}=await Ke(e,[`--version`],{forceKillAfterDelay:n,timeout:t});return r}function at(e){return e.match(/(\d+\.\d+\.\d+)/u)?.[1]??`unknown`}async function ot(e,t=F,n=I){try{let r=await t(e);if(r===void 0)return{binary:e,found:!1};let i=await n(r);return i.length===0?{binary:e,found:!1}:{binary:e,found:!0,path:r,version:at(i)}}catch{return{binary:e,found:!1}}}async function st(e,t=F,n=I){return Promise.all(e.map(e=>ot(e,t,n)))}var ct=class extends Ee{constructor(e){super(e)}onInit(){this.registerHandler(Ae.scan,async e=>{let t=await st(e.payload.binaries);e.setResult({results:t})})}};const L={name:`makaio.cli-detection`,displayName:`CLI Detection`,version:`0.1.0`,critical:!0,surface:`any`,namespaces:[ke],create:e=>new ct(e.bus)};function R(e,t){e.push(...lt(t))}function lt(e){return e===void 0?[]:typeof e==`function`?[e]:[...e]}function ut(e,t=[]){let n=new Set([e]),r=new Set,i=new Map;for(let e of t)typeof e==`string`?n.add(e):(r.add(e.id),e.version!==void 0&&i.set(e.id,e.version));return{hosts:n,capabilities:r,...i.size>0?{capabilityVersions:i}:{}}}function dt(e=[]){return e.some(e=>typeof e==`string`&&e===`node`)?e:[`node`,...e]}function ft(e){return we(Te(mt(e.packages,e.configProvider),e.surface,e.runtimeEnvironment))}function pt(e,n){let r=ft(n),i=new Set(r.map(t));return e.filter(({ownerPackage:e})=>i.has(e)).map(({package:e})=>e)}function mt(e,t){return t?e.filter(e=>t.loadEnabled(e.name)!==!1):e}function ht(e,t){return e.filter(e=>e.runtimeOwnership?.[t]===!0).map(e=>e.name)}function gt(e,t){let n=ht(e,t);if(n.length>1)throw Error(`Multiple extensions own runtimeOwnership.${t}: ${n.join(`, `)}`)}function _t(e){return gt(e,`sessionOrchestrator`),ht(e,`sessionOrchestrator`).length===0}function vt(e){return e===!0||_t(e)?D:D.filter(e=>e.name!==je.name)}function yt(e,t,n){let r=[];try{for(let i of e){let e=i.runtimeBoot;e&&R(r,e.configure({bus:t,registerContributionProcessor:e=>{r.push(n.registerContributionProcessor(e))},forEachActiveExtension:e=>{n.forEachActiveExtension(e)}}))}}catch(e){let t=[];for(let e of[...r].reverse())try{e()}catch(e){t.push(e)}throw t.length>0?AggregateError([e,...t],`Extension boot contribution failed and rollback cleanup reported additional errors`,{cause:e}):e}return r}function bt(){let e=process.env.MAKAIO_SKIP_EXTENSIONS;if(!e)return new Set;let t=e.split(`,`).map(e=>e.trim()).filter(Boolean);return new Set(t)}var xt=class{pool;constructor(e){this.pool=new qe({filename:e.workerEntry,maxThreads:e.maxConcurrency??4,idleTimeout:e.idleTimeoutMs??3e4})}async run(e,t,n){return this.pool.run(e,{signal:t,transferList:n})}onMessage(e){return this.pool.on(`message`,e),()=>this.pool.off(`message`,e)}async dispose(){await this.pool.destroy()}},z=class extends Error{code;constructor(e,t){super(e),this.code=t,this.name=`MaterializationError`}};function B(e,t,n){let r=g.resolve(t)+g.sep,i=g.resolve(e);if(i!==g.resolve(t)&&!i.startsWith(r))throw new z(`${n} escapes allowed root: ${e} is not within ${t}`,`containment-violation`)}async function V(e,t,n,r){let i=r??await h.realpath(t),a;try{a=await h.realpath(e)}catch{return e}let o=i+g.sep;if(a!==i&&!a.startsWith(o))throw new z(`${n} escapes allowed root via symlink: real path ${a} is not within ${i}`,`symlink-escape`);return a}function St(e){let t=e.indexOf(`-`);if(t===-1)throw new z(`Invalid SRI integrity format: ${e}`,`contribution-integrity-mismatch`);return{algorithm:e.slice(0,t),digest:e.slice(t+1)}}async function Ct(e,t){let n=await h.readFile(e);return _.createHash(t).update(n).digest(`base64`)}const H=new Set([`.git`,`node_modules`]);function wt(e){return H.has(e.toLowerCase())}async function Tt(e,t){let n=t.toLowerCase();if(!H.has(n))return!1;if(t===n)return!0;try{let[r,i]=await Promise.all([h.lstat(g.join(e,t)),h.lstat(g.join(e,n))]);return r.dev===i.dev&&r.ino===i.ino}catch(e){if(e.code===`ENOENT`)return!1;throw e}}const Et=H,Dt=new Set([`.DS_Store`]);async function Ot(e,t){let n=_.createHash(t),r=[];async function i(t){let n=await h.readdir(t,{withFileTypes:!0});for(let a of n){let n=g.join(t,a.name);if(a.isSymbolicLink())throw new z(`Contribution package contains a symbolic link: ${g.relative(e,n)}`,`symlink-escape`);if(a.isDirectory()){Et.has(a.name)||await i(n);continue}if(a.isFile()){Dt.has(a.name)||r.push(g.relative(e,n));continue}throw new z(`Contribution package contains an unsupported filesystem entry: ${g.relative(e,n)}`,`contribution-integrity-mismatch`)}}await i(e),r.sort();for(let t of r)n.update(t.split(g.sep).join(`/`)),n.update(`\0`),n.update(await h.readFile(g.join(e,t))),n.update(`\0`);return`${t}-${n.digest(`base64`)}`}async function kt(e,t=`sha256`){let n=_.createHash(t),r=[];async function i(t){let n=await h.readdir(t,{withFileTypes:!0});for(let a of n){let n=g.join(t,a.name);if(!await Tt(t,a.name)){if(a.isDirectory()){await i(n);continue}if(a.isFile()){r.push(g.relative(e,n));continue}throw a.isSymbolicLink()?new z(`Workspace root contains a symbolic link: ${g.relative(e,n)}`,`symlink-escape`):new z(`Workspace root contains an unsupported filesystem entry: ${g.relative(e,n)}`,`unsupported-filesystem-entry`)}}}await i(e),r.sort();for(let t of r){n.update(t),n.update(`\0`);let r=await h.readFile(g.join(e,t));n.update(r),n.update(`\0`)}return`${t}-${n.digest(`base64`)}`}async function At(e,t,n){let r=g.join(t,`node_modules`,e.packageName);B(r,t,`Contribution package directory`),await V(r,t,`Contribution package directory`,n);let i=g.join(r,`package.json`),a;try{a=await h.readFile(i,`utf-8`)}catch{throw new z(`Contribution package not found: ${e.packageName} (expected at ${r})`,`contribution-missing`)}let o=JSON.parse(a);if(o.name!==e.packageName)throw new z(`Contribution identity mismatch: expected ${e.packageName}, found ${o.name??`<none>`}`,`contribution-missing`);if(o.version!==e.version)throw new z(`Contribution version mismatch for ${e.packageName}: expected ${e.version}, found ${o.version??`<none>`}`,`contribution-version-mismatch`);let s=g.join(r,e.entrypoint);B(s,r,`Contribution entrypoint`),await V(s,t,`Contribution entrypoint`,n);try{await h.access(s)}catch{throw new z(`Contribution entrypoint not found for ${e.packageName}: ${e.entrypoint}`,`contribution-entrypoint-mismatch`)}let{algorithm:c}=St(e.integrity),l;try{l=await Ot(r,c)}catch(t){if(t instanceof z)throw t;let n=typeof t==`object`&&t&&`code`in t&&typeof t.code==`string`?t.code:void 0;throw n!==void 0&&!n.startsWith(`ERR_`)?new z(`Contribution package cannot be read for ${e.packageName}`,`contribution-entrypoint-mismatch`):t}if(l!==e.integrity)throw new z(`Contribution integrity mismatch for ${e.packageName}: expected ${e.integrity}, computed ${l}`,`contribution-integrity-mismatch`);return s}async function jt(e,t,n){let r=await n.resolveWorkspaceRoot(e.workspaceId);if(r===void 0)throw new z(`Unknown workspace ID: ${e.workspaceId}`,`unknown-workspace`);try{if(!(await h.stat(r)).isDirectory())throw new z(`Workspace root is not a directory: ${r}`,`containment-violation`)}catch(e){throw e instanceof z?e:new z(`Workspace root does not exist: ${r}`,`containment-violation`)}let i=await h.realpath(r),a=g.resolve(r,e.sourcePath);if(B(a,r,`Source path`),g.relative(r,a).split(g.sep).some(wt))throw new z(`Workflow source path selects excluded workspace content: ${e.sourcePath}`,`source-path-mismatch`);await V(a,r,`Source path`,i);let o=await kt(r);if(o!==e.rootDigest)throw new z(`Workspace root digest mismatch: expected ${e.rootDigest}, computed ${o}`,`digest-mismatch`);try{await h.access(a)}catch{throw new z(`Workflow source file not found: ${a}`,`source-missing`)}return{workspaceRoot:r,sourcePath:a,contributionEntrypoints:await Promise.all(t.map(e=>At(e,r,i))),platform:process.platform,arch:process.arch}}var U=class{options;manifest;pool;constructor(e){this.options=e,this.manifest=e.manifest}async run(e,t,n){this.pool??=new xt(this.options);let r=n??this.manifest,i=await this.materializeTask(e,r,t);return{state:`uncommitted`,result:await this.pool.run(i,t)}}runWithReadiness(e,t,r,i){this.pool??=new xt(this.options);let a=this.pool,o,s=!1,c,u=new Promise((t,n)=>{c=n,o=a.onMessage(n=>{l(n)&&n.executionAttemptId===i.executionAttemptId&&(n.executionId!==e.executionId||n.cancelSubject!==e.cancelSubject||(s=!0,o?.(),t(n)))})}),d=r??this.manifest,f=n(i.bootstrapDeadlineAt,t,async(t,n)=>{let r=await this.materializeTask(e,d,n);return a.run({...r,kind:`attempt-bound`,executionAttemptId:i.executionAttemptId,bootstrapDeadlineAt:i.bootstrapDeadlineAt,bootstrapPort:t},n,[t])});return f.then(()=>{s||(s=!0,o?.(),c(Error(`Workflow worker completed before ready signal: ${e.executionId}`)))},e=>{s||(s=!0,o?.(),c(e instanceof Error?e:Error(String(e))))}),{result:f,ready:u}}async dispose(){await this.pool?.dispose()}async materializeTask(e,t,n){if(n.throwIfAborted(),!(e.source.kind===`path`||t.contributionRefs.length>0))return{kind:`unbound`,config:e,manifest:t,contributionEntrypoints:[]};let r=e.materializationSpec;if(r?.kind!==`local-directory`)throw Error(`ThinWorkflowPiscinaRunner requires a local-directory materialization spec for path-backed workflows or declared contributions.`);if(this.options.resolveWorkspaceRoot===void 0)throw Error(`ThinWorkflowPiscinaRunner requires a host workspace-root resolver for local-directory materialization.`);let i=await jt(r,t.contributionRefs,{resolveWorkspaceRoot:this.options.resolveWorkspaceRoot});if(n.throwIfAborted(),e.source.kind!==`path`)throw Error(`local-directory materialization requires a path-backed workflow source.`);return{kind:`unbound`,config:{...e,source:{kind:`path`,path:i.sourcePath}},manifest:t,contributionEntrypoints:i.contributionEntrypoints}}};function Mt(e){return e.mode===`source`?ie(e.moduleDir,`workflow-worker`,`worker-entry.ts`):ie(e.moduleDir,`workflow-worker`,`worker-entry.mjs`)}var Nt=class{options;terminalAuthority=`authority`;constructor(e){this.options=e}async run(e,t,n,r){let i={...e,terminalAuthority:`authority`},a=n??this.options.manifest,o=this.options.requirements,s=r?.dispatchMetadata;t.throwIfAborted();let c=e.source.kind===`path`?await this.options.readRunContext?.(e.executionId,t):void 0;t.throwIfAborted();let l=Qe({id:v(),revision:`1`,config:e,...c==null?{}:{runContext:c},preservation:{required:[]}});return et(await $e({authority:this.options.authority,executionId:e.executionId,instruction:l,withAttemptCreation:r?.withAttemptCreation,dispatch:e=>this.options.dispatch({executionAttemptId:e,config:i,...a!==void 0&&{manifest:a},...o!==void 0&&{requirements:o},...s!==void 0&&{metadata:s}},t)}),e)}},Pt=class{#e;constructor(e){this.#e=e.bus}async run(e,t,n){let i=ve.parse(e),a=await r(i);return{state:`uncommitted`,result:await tt({config:await c(i,a,this.#e,t),loaded:a,bus:this.#e,signal:t})}}};function Ft(){return{contributionRefs:[]}}function It(e){if(e.workflowRunner?.mode===`worker`&&!e.executionAttemptRepository)throw Error(`Worker dispatch mode requires an ExecutionAttemptRepository. Pass 'executionAttemptRepository' to createNodeWorkflowRunnerPackageOptions when workflowRunner.mode is 'worker'.`);let t;if(e.executionAttemptRepository){let n=e.executionAttemptBootstrapTimeoutMs;if(n===void 0)throw Error(`An ExecutionAttemptRepository requires executionAttemptBootstrapTimeoutMs`);t=new Je(e.executionAttemptRepository,{bootstrapTimeoutMs:n})}let n=ne(e.runtimeModuleDir)===`src`?`source`:`dist`,r=Lt({moduleDir:e.runtimeModuleDir,defaultWorkerEntryMode:n,runner:e.workflowRunner,bus:e.bus,authority:t});return{...r!==void 0&&{workflowRunner:r},executorConfig:{busUrl:e.busUrl,busAuth:{kind:`none`},platformDefaults:e.platformDefaults,makaioHome:e.makaioHome},...e.executionAttemptRepository!==void 0&&{executionAttemptRepository:e.executionAttemptRepository},...t!==void 0&&{executionAttemptAuthority:t},...e.workflowMaterializationSpecResolvers!==void 0&&{workflowMaterializationSpecResolvers:e.workflowMaterializationSpecResolvers}}}function Lt(e){let{runner:t}=e;if(t)switch(t.mode){case void 0:case`in-process`:if(e.bus===void 0)throw Error(`InProcessWorkflowRunner requires a bus instance. Pass 'bus' to createNodeWorkflowRunner when runner.mode is 'in-process'.`);return new Pt({bus:e.bus});case`worker`:{if(e.authority===void 0)throw Error(`WorkerRunner requires an ExecutionAttemptAuthority. Pass 'authority' to createNodeWorkflowRunner when runner.mode is 'worker'.`);let n=e.bus,r=t.dispatch??(n===void 0?void 0:(e,t)=>n.request(C.dispatch,{executionAttemptId:e.executionAttemptId,config:e.config,manifest:e.manifest,requirements:e.requirements,metadata:e.metadata},{signal:t}));if(r===void 0)throw Error(`WorkerRunner requires either a dispatch function or a bus instance. Pass 'bus' to createNodeWorkflowRunner when runner.mode is 'worker'.`);return new Nt({dispatch:r,authority:e.authority,...n!==void 0&&{readRunContext:async(e,t)=>(await n.request(Ze.getRunContext,{executionId:e},{signal:t})).runContext},...t.manifest!==void 0&&{manifest:t.manifest},...t.requirements!==void 0&&{requirements:t.requirements}})}case`piscina`:return new U({workerEntry:t.workerEntry??Mt({moduleDir:e.moduleDir,mode:t.workerEntryMode??e.defaultWorkerEntryMode}),manifest:t.manifest??Ft(),...t.resolveWorkspaceRoot!==void 0&&{resolveWorkspaceRoot:t.resolveWorkspaceRoot},maxConcurrency:t.maxConcurrency,idleTimeoutMs:t.idleTimeoutMs})}}const Rt=new Set([`accepted`,`duplicate`]);var W=class extends Error{decision;result;reason;constructor(e,t,n=`authority-rejected`){super(`Outcome delivery ${n===`deadline-exceeded`?`deadline exceeded`:`rejected by Authority`} (decision=${e}, executionId=${t.executionId}, status=${t.status})`),this.decision=e,this.result=t,this.reason=n,this.name=`OutcomeDeliveryError`}},G=class extends Error{decision;payload;reason;constructor(e,t,n=`authority-rejected`){super(`Attempt outcome delivery ${n===`deadline-exceeded`?`deadline exceeded`:`rejected by Authority`} (decision=${e}, executionAttemptId=${t.executionAttemptId}, outcome=${t.outcome.kind})`),this.decision=e,this.payload=t,this.reason=n,this.name=`AttemptOutcomeDeliveryError`}},zt=class extends Error{reason;constructor(e=`deadline-exceeded`){super(`Authority request delivery deadline exceeded`),this.reason=e,this.name=`AuthorityRequestDeliveryError`}};function Bt(e){let t={maxRetries:e?.maxRetries??7,baseDelayMs:e?.baseDelayMs??1e3,maxDelayMs:e?.maxDelayMs??3e4,deadlineMs:e?.deadlineMs??12e4};if(!Number.isSafeInteger(t.maxRetries)||t.maxRetries<0)throw TypeError(`Outcome submission maxRetries must be a non-negative safe integer, got ${t.maxRetries}`);for(let[e,n]of Object.entries({baseDelayMs:t.baseDelayMs,maxDelayMs:t.maxDelayMs,deadlineMs:t.deadlineMs}))if(!Number.isFinite(n)||n<=0)throw TypeError(`Outcome submission ${e} must be a positive finite number, got ${n}`);return t}async function Vt(e,t,n,r){let i=t.baseDelayMs*2**(e-1),a=n-Date.now(),o=Math.min(i,t.maxDelayMs,a);await new Promise(e=>setTimeout(e,o));let s=n-Date.now();if(s<=0)return!1;if(r!==void 0){let e;try{await Promise.race([r(),new Promise(t=>{e=setTimeout(t,s)})])}catch{}finally{e!==void 0&&clearTimeout(e)}}return Date.now()<n}async function Ht(e,t,n,r){let i=Bt(n?.retry),a=n?.reconnect,o=Date.now()+i.deadlineMs,s;for(let n=0;n<=i.maxRetries;n++){if(o-Date.now()<=0||n>0&&!await Vt(n,i,o,a))throw t();try{let n=o-Date.now();if(n<=0)throw t();return await e(n)}catch(e){if(r(e))throw e;if(s=e,Date.now()>=o)throw t()}}throw s??t()}async function K(e,t){return await Ht(e,()=>new zt,t,()=>!1)}async function Ut(e,t,n){return await Ht(async n=>{let r=await e(n);if(Rt.has(r))return r;throw t(r)},()=>t(`deadline-exceeded`,`deadline-exceeded`),n,e=>e instanceof W||e instanceof G)}async function Wt(e,t,n){return await Ut(async n=>(await e.request(C.control.outcome.submit,{executionAttemptId:t.executionAttemptId,executionId:t.executionId,result:t.result},{timeout:n})).decision,(e,n)=>n===void 0?new W(e,t.result):new W(e,t.result,n),n)}async function Gt(e,t,n){return await Ut(async n=>(await e.request(x.outcome.submit,t,{timeout:n})).decision,(e,n)=>n===void 0?new G(e,t):new G(e,t,n),n)}const Kt={maxRetries:3,baseDelayMs:200,maxDelayMs:2e3,deadlineMs:1e4},qt={persistentStorage:!0,customCapabilities:[`workflow.local-runtime`,`workflow.thin-runner`],suspensionStrategy:`wait-in-process`,supportsRecovery:!1,materializationModes:[`local-directory`]},Jt={code:`outcome-acknowledged`,summary:`Piscina runner settled and the Authority acknowledged its workflow outcome`},Yt={code:`outcome-delivery-ended`,summary:`Piscina runner settled and its bounded workflow outcome delivery ended`};function q(e){let t=new Set,n;return{publish:r=>{if(n!==void 0)return;let i=r();n=i;let a=[...t];t.clear();for(let t of a)try{t(i)}catch(t){console.error(`${e} observer failed:`,t)}},observe:e=>n===void 0?(t.add(e),()=>t.delete(e)):(e(n),()=>void 0)}}function Xt(e){let t=q(`[PiscinaThinWorkflowProvider] Infrastructure-conclusion`);return{conclude:n=>{t.publish(()=>({evidence:y.parse({source:e.slice(0,S.source),summary:n.slice(0,S.summary),observedAt:new Date().toISOString()})}))},observe:t.observe}}function Zt(e,t){let n=q(`[PiscinaThinWorkflowProvider] Provider-completion`),r=q(`[PiscinaThinWorkflowProvider] Local-observation-loss`),i;return{completion:{complete:r=>{i===void 0&&n.publish(()=>{let n=y.parse({source:e.slice(0,S.source),code:r.code,summary:r.summary,observedAt:new Date().toISOString()});return t(),i=`completion`,n})},observe:n.observe},localObservationLoss:{lose:()=>{i===void 0&&r.publish(()=>(i=`local-observation-loss`,{}))},observe:e=>r.observe(()=>e())}}}var Qt=class{executionAttemptId;controller;detachCallerAbort;infrastructure;completion;localObservationLoss;revokeBusIdentity;constructor(e,t,n,r,i,a,o){this.executionAttemptId=e,this.controller=t,this.detachCallerAbort=n,this.infrastructure=r,this.completion=i,this.localObservationLoss=a,this.revokeBusIdentity=o}cancel(e){return this.controller.abort(e??`Worker cancelled`),this.detachCallerAbort(),Promise.resolve()}terminate(){return this.controller.abort(`Worker terminated`),this.detachCallerAbort(),this.revokeBusIdentity(),Promise.resolve()}release(){return this.detachCallerAbort(),Promise.resolve()}observeInfrastructureConclusion(e){return this.infrastructure.observe(e)}observeProviderCompletion(e){return this.completion.observe(e)}observeLocalObservationLoss(e){return this.localObservationLoss.observe(e)}},$t=class{options;environment=`piscina`;allocationLifetime=`provisioner-process-bound`;baseCapabilities;constructor(e){this.options=e,this.baseCapabilities=me.parse({...qt,...e.baseCapabilities,suspensionStrategy:e.baseCapabilities?.suspensionStrategy??qt.suspensionStrategy,supportsRecovery:!1})}get id(){return this.options.id}get displayName(){return this.options.displayName}async provision(e,t){t.throwIfAborted();let n=await this.resolveLaunchBeforeAllocation(e,t);if(t.throwIfAborted(),`kind`in n)return n;let r=n,i=new AbortController,a=Xt(this.id),o=()=>{i.abort(t.reason)};t.addEventListener(`abort`,o,{once:!0});let s=()=>t.removeEventListener(`abort`,o),c;try{let{executionAttemptId:n,executionId:o}=e,l=this.buildAllocationRef(n),u=d({executionAttemptId:n,executionId:o}),f=!1,p=()=>{f||(f=!0,u.cleanup())};c=p;let m=Zt(this.id,p),ee=new Qt(n,i,s,a,m.completion,m.localObservationLoss,p);t.throwIfAborted();let h=this.options.runner.runWithReadiness({...r,busAuth:{kind:`hmac`,secret:u.secret}},i.signal,e.runtimeInputs.workerManifest,{executionAttemptId:n,bootstrapDeadlineAt:e.bootstrapDeadlineAt});return h.ready.then(()=>this.submitOutcomeOnSettlement(h.result,o,n,r.workflowId,a.conclude,m.completion.complete),e=>{i.abort(e),h.result.catch(()=>void 0),c?.(),a.conclude(`Piscina worker for attempt '${n}' was refused before its workflow run was admitted: `+(e instanceof Error?e.message:String(e))),m.localObservationLoss.lose()}),{kind:`allocated`,allocationRef:l,handle:ee}}catch(e){throw i.abort(e),s(),c?.(),e}}async resolveLaunchBeforeAllocation(e,t){try{let n=await this.options.launchResolver(e,t);return t.throwIfAborted(),n.busUrl?n:this.confirmedAbsent(`Piscina workflow configuration has no bus URL before local allocation setup`)}catch{return t.throwIfAborted(),this.confirmedAbsent(`Workflow launch resolution failed before Piscina local allocation setup`)}}confirmedAbsent(e){return{kind:`confirmed-absent`,evidence:y.parse({source:`piscina-thin-workflow-provider`,code:de,summary:e,observedAt:new Date().toISOString()})}}async submitOutcomeOnSettlement(e,t,n,r,i,a){let o;try{o=await e}catch(e){o={executionId:t,workflowId:r,status:`failed`,error:e instanceof Error?e.message:String(e)}}try{let e={...Kt,...this.options.outcomeRetry};await Wt(this.options.bus,{executionAttemptId:n,executionId:t,result:o},{retry:e})}catch(e){e instanceof W?console.error(`[PiscinaThinWorkflowProvider] Outcome rejected for execution '${t}' attempt '${n}' (decision=${e.decision}):`,e):console.error(`[PiscinaThinWorkflowProvider] Failed to submit outcome for execution '${t}' attempt '${n}':`,e),i(`Piscina worker for attempt '${n}' ended without an acknowledged outcome because outcome submission could not be completed`),a(Yt);return}a(Jt)}buildAllocationRef(e){let t={version:fe,providerId:this.id,providerData:{executionAttemptId:e,allocatedAt:Date.now()}};return pe.parse(t)}};function en(e){return async(t,n)=>{n.throwIfAborted();let r=await e({executionId:t.executionId,executionAttemptId:t.executionAttemptId});if(n.throwIfAborted(),r===null)throw Error(`Workflow launch instruction is unavailable for execution '${t.executionId}' attempt '${t.executionAttemptId}'`);let i=k(r);if(i.executionId!==t.executionId)throw Error(`Workflow instruction execution '${i.executionId}' does not match Worker request '${t.executionId}'`);return ve.parse({source:i.source,...i.definitionSnapshot===void 0?{}:{definition:i.definitionSnapshot},executionId:i.executionId,workflowId:i.workflowId,triggerPayload:i.triggerPayload,...i.triggerMode===void 0?{}:{triggerMode:i.triggerMode},inputs:i.inputs,...i.config===void 0?{}:{config:i.config},...i.artifactRef===void 0?{}:{artifactRef:i.artifactRef},scope:i.scope,...t.connection.busUrl===void 0?{}:{busUrl:t.connection.busUrl},busAuth:t.connection.busAuth,...t.connection.env===void 0?{}:{env:t.connection.env},coordinatorSessionId:i.coordinatorSessionId,cancelSubject:i.cancelSubject,suspensionStrategy:t.runtimeInputs.suspensionStrategy,terminalAuthority:i.terminalAuthority,...i.materializationSpec===void 0?{}:{materializationSpec:i.materializationSpec}})}}const tn=[ze,Ie,Re];function nn(e){let t;return()=>(t??=(async()=>{let t=[];for(let n of[...e].reverse())try{await n()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Isolated workflow runtime shutdown reported errors`)})(),t)}function rn(e,t,n){return M({bus:e,currentMachineId:n,resolveLiveAdapterId:e=>t.getExtensionService(O)?.resolveLiveAdapterId(e),resolveLiveAdapterIdentity:e=>t.getExtensionService(O)?.resolveLiveAdapterIdentity(e),listLiveAdapterIdentities:()=>t.getExtensionService(O)?.getLiveAdapterIdentities()??[]})}async function an(e){let t=w();t.registerNamespaces([...ce,...le]);let{context:n}=e,r=new Se(t,{surface:`headless`,extensionContextBase:{cwd:n.cwd,platform:n.platform,homedir:n.homedir,makaioHome:n.makaioHome,username:n.username,machineId:n.machineId,tryImport:P}}),i,a=[()=>t.disconnect()],o=nn(a);try{await e.connectAuthority(t);let s=[...e.contributedPackages,...await e.loadContributedPackages?.(t)??[]],{adapterSubsystemPackage:c}=j({coordinator:r,configRepository:e.configRepository,platformDefaults:{cwd:n.cwd},runtimeSnapshotHandlerPriority:1,runtimeDefinitionHandlerPriority:1,...e.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:e.prepareAuthRuntime}}),l=He({definitions:s.flatMap(e=>e.clients??[]),binaryResolutionPolicy:`global-only`});r.registerContributionProcessor(Fe());let u=[...tn,c,Ne,..._t(s)?[Le]:[],Pe(1),Be,L,l,...Ge(s)];r.load(u),a.push(...yt(u,t,r)),a.push(()=>r.shutdown()),await r.startAll(),i=rn(t,r,n.machineId),a.push(()=>{i?.cleanup(),i=void 0});let d=r.getExtensionService(Me);if(d===void 0)throw Error(`Isolated workflow tool registry did not start.`);for(let t of e.toolsets)await d.register(t);return await t.emit(Ce.ready,{machineId:n.machineId}),{bus:t,coordinator:r,machineId:n.machineId,shutdown:o}}catch(e){throw await o().catch(()=>void 0),e}}function on(e){return Number.isInteger(e)&&e>=1&&e<=2147483647}function J(e,t){try{return process.kill(-e,t),`signalled`}catch(e){if(e.code!==`ESRCH`)throw e;return`absent`}}function sn(e){return typeof e==`object`&&!!e&&e.code===`ENOENT`}async function cn(e,t,n){try{process.kill(-e,0)}catch(e){if(e.code===`ESRCH`)return{alive:!1};if(e.code!==`EPERM`)throw e}if(n)return{alive:!0};let r;try{r=await ln(t)}catch(e){return sn(e)?{alive:!0,psMissing:!0}:{alive:!0}}let i=!1;for(let t of r.trim().split(`
2
+ `)){let[n,r,a]=t.trim().split(/\s+/);if(n===``||r===void 0||a!==void 0||!/^\d+$/.test(n)||r===``||Number(n)===e&&(i=!0,!r.startsWith(`Z`)))return{alive:!0}}return i?{alive:!1}:{alive:!0}}function ln(e){return new Promise((t,n)=>{p(`ps`,[`-A`,`-o`,`pgid=,stat=`],{timeout:e,maxBuffer:1024*1024},(e,r)=>{if(e!==null){n(e);return}t(r)})})}async function un(e){if(e===void 0)return{quiesced:!0,signalledLiveGroup:!1};let t=!1;try{try{t=J(e,`SIGKILL`)===`signalled`}catch(e){if(e.code!==`EPERM`)throw e}let n=Date.now()+2e3,r=!1;for(;Date.now()<n;){let i=n-Date.now();if(i<=0)break;let a=await cn(e,Math.min(1e3,i),r);if(!a.alive)return{quiesced:!0,signalledLiveGroup:t};r||=a.psMissing===!0,await nt(20)}return{quiesced:!1,cause:r?`ps-unavailable`:`poll-timeout`,signalledLiveGroup:t}}catch{return{quiesced:!1,cause:`signal-error`,signalledLiveGroup:t}}}function dn(e,t,n){let r=new Date;return n.quiesced?t||n.signalledLiveGroup?{pid:e,outcome:`signalled-and-quiesced`,observedAt:r}:{pid:e,outcome:`exited`,observedAt:r}:{pid:e,outcome:t||n.signalledLiveGroup?`signalled-unconfirmed`:`unsignalled-unconfirmed`,cause:n.cause,observedAt:r}}async function fn(e){if(e.signal?.aborted)return{status:`cancelled`,exitCode:null};if(!on(e.recipe.timeoutMs))return{status:`spawn-failed`,exitCode:null,message:`Setup timeout must be an integer between 1 and 2147483647 milliseconds`};if(process.platform===`win32`)return{status:`spawn-failed`,exitCode:null,message:`Setup process groups require a POSIX host`};try{return await pn(e)}catch{return{status:`spawn-failed`,exitCode:null,message:`Could not start the setup command`}}}function pn(e){return new Promise(t=>{let n=m(e.recipe.command,e.recipe.args,{cwd:e.workspaceRoot,env:{...process.env,...e.recipe.env,...e.env},shell:!1,detached:!0,stdio:`ignore`}),r,i,a=!1,o=e=>{if(r===void 0&&(r=e,n.pid!==void 0)){try{J(n.pid,`SIGTERM`)===`signalled`&&(a=!0)}catch(e){if(e.code!==`EPERM`){r=`stop-failed`;return}}i=setTimeout(()=>{try{n.pid!==void 0&&J(n.pid,`SIGKILL`)===`signalled`&&(a=!0)}catch(e){e.code!==`EPERM`&&(r=`stop-failed`)}},200)}},s=()=>o(`cancelled`),c=setTimeout(()=>o(`timed-out`),e.recipe.timeoutMs);e.signal?.addEventListener(`abort`,s,{once:!0}),e.signal?.aborted&&s(),n.once(`error`,()=>{r=`spawn-failed`}),n.once(`close`,o=>{clearTimeout(c),clearTimeout(i),e.signal?.removeEventListener(`abort`,s),un(n.pid).then(e=>{t({status:e.quiesced?r??(o===0?`completed`:`failed`):`stop-failed`,exitCode:o,processGroup:n.pid===void 0?void 0:dn(n.pid,a,e)})})})})}async function mn(e,t,n){if(g.isAbsolute(t)||t.includes(`\\`)||t.split(`/`).includes(`..`))throw Error(`Source root must be workspace-relative`);let r=e;for(let i of t.split(`/`).filter(e=>e!==``&&e!==`.`))if(r=g.join(r,i),B(r,e,`Source root`),await V(r,e,`Source root`,e),n&&await h.mkdir(r).catch(e=>{if(e.code!==`EEXIST`)throw e}),!(await h.stat(r)).isDirectory())throw Error(`Source root must be a directory`);return V(r,e,`Source root`,e)}async function hn(e){e.signal?.throwIfAborted();let{requirement:t}=e,n=g.resolve(e.workspaceRoot);if(!g.isAbsolute(e.workspaceRoot)||n===g.parse(n).root)throw Error(`Workspace root must be an absolute, non-filesystem-root directory`);if(t.sourceRoots.length>1)throw Error(`Multiple source roots are not implemented`);if(t.sourceRoots.some(e=>e.source!==void 0)){if(e.realizeSource===void 0)throw Error(`Source acquisition requires an installed strategy`);if(t.provisioning!==`create`||t.custody!==`disposable`)throw Error(`Source acquisition currently requires a created disposable workspace`)}if(t.provisioning===`create`&&await h.mkdir(n),!(await h.lstat(n)).isDirectory())throw Error(`Workspace root must be a directory, not a symlink`);let r=await h.realpath(n),i=[];for(let n of t.sourceRoots){let a=await mn(r,n.path,t.provisioning===`create`);n.source!==void 0&&(await e.realizeSource({source:n.source,destination:a,signal:e.signal}),e.signal?.throwIfAborted()),i.push({id:n.id,path:a})}return gn(t,{workspaceRoot:r,sourceRoots:i})}function gn(e,t){let n=t.workspaceRoot,r=e.custody,i=!1,a=!0,o;return{binding:t,async runSetup(t={}){if(o!==void 0||i||!a)throw Error(`Workspace setup is unavailable`);if(t.signal?.aborted)return{status:`cancelled`,exitCode:null};i=!0;try{let r;for(let[i,o]of e.setup.entries()){let e=await fn({...t,recipe:o,workspaceRoot:n});if(r=e,a=e.status!==`stop-failed`,e.status!==`completed`)return{...e,commandIndex:i}}let i=r?.processGroup;return i===void 0?{status:`completed`,exitCode:0}:{status:`completed`,exitCode:0,processGroup:i}}finally{i=!1}},release(){return i||!a?Promise.reject(Error(`Workspace commands have not stopped`)):(o??=r===`external`?Promise.resolve():h.rm(n,{recursive:!0,force:!0}),o)}}}function Y(e,t){return e instanceof be?T(e,t):t?.aborted===!0?e===t.reason||e instanceof DOMException&&e.name===`AbortError`?!0:e instanceof Error&&e.name===`AbortError`&&`code`in e&&e.code===`ABORT_ERR`&&Object.is(e.cause,t.reason):!1}function X(e){return(e instanceof Error?e.message:String(e)).slice(0,8192)||`Local execution failed without a diagnostic message`}function _n(e){if(e.status!==`completed`)return e.status===`cancelled`?{kind:`cancelled`}:e.status===`stop-failed`?{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace setup stop-failed`}:{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace setup ${e.status}`}}function vn(e,t){return Y(e,t)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`workspace-preparation`,message:X(e)}}async function yn(e,t,n,r){let i=b[`instruction.get`].response.parse(await e.request(x.instruction.get,{executionAttemptId:t,runtimeGeneration:n},{signal:r}));if(i.decision===`found`)return i.instruction;throw Error(`Attempt instruction read refused: ${i.refusalReason}`)}async function bn(e,t,n,r){let{executionAttemptId:i,runtimeGeneration:a}=t;t.control?.admissionPending();let o=b[`operation.admit`].response.parse(await K(async t=>await e.request(x.operation.admit,{executionAttemptId:i,runtimeGeneration:a,operationKind:n,admissionKey:r},{timeout:t}),{retry:t.retry,reconnect:t.reconnect}));if(o.decision===`refused`)throw t.control?.admissionSettled(o.refusalReason),new s(t.executionAttemptId,r,o.refusalReason);if(o.operationId===void 0)throw Error(`Attempt ${n} admission decision '${o.decision}' named no operation (executionAttemptId=${i}, admissionKey=${r})`);return t.control?.operationAdmitted(n,o.operationId),o.operationId}async function xn(e,t,n){try{return{operationId:await bn(e,t,n.operationKind,n.admissionKey)}}catch(r){if(!(r instanceof s&&r.refusalReason===`gate-closed`&&n.signal.aborted))throw r;return await Z(e,t,n.instruction,{kind:`cancelled`},void 0,n.workspace)}}function Sn(e,t){return e.find(e=>e.kind===t.workload.kind&&e.version===t.workload.version)}function Cn(e){return{signal:e??new AbortController().signal,release:()=>{}}}async function Z(e,t,n,r,i,a){i!==void 0&&t.control?.operationConcluded(i);let o=await Gt(e,{executionAttemptId:t.executionAttemptId,runtimeGeneration:t.runtimeGeneration,...i===void 0?{}:{operationId:i.operationId},outcome:r},{retry:t.retry,reconnect:t.reconnect});if(a!==void 0&&n!==void 0&&r.kind===`workload-result`&&n.preservation.required.length===0)try{await a.release()}catch{console.warn(`[makaio-worker] Acknowledged workspace cleanup failed.`)}return{outcome:r,decision:o}}async function wn(e,t,n,r){let i=b[`operation.report`].response.parse(await K(async i=>await e.request(x.operation.report,{executionAttemptId:t.executionAttemptId,runtimeGeneration:t.runtimeGeneration,operationId:n,result:{kind:`workspace-prepared`,binding:r.binding}},{timeout:i}),{retry:t.retry,reconnect:t.reconnect}));return i.decision===`refused`?void 0:i.binding}async function Tn(e,t,n,r){if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,void 0);let i=await xn(e,t,{operationKind:`workspace-preparation`,admissionKey:`workspace-preparation:${n.id}:${t.runtimeGeneration}`,signal:r,instruction:n});if(`outcome`in i)return i;let a=i.operationId;if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},Q(a,`not-started`),void 0);let o,s,c=!1;try{if(t.workspaceRoot===void 0)throw Error(`Workspace preparation requires an explicit local root`);let e=await(t.preparation??{prepare:hn}).prepare({requirement:n.workspace,workspaceRoot:t.workspaceRoot,signal:r});o=e,c=!0,s=await e.runSetup({signal:r,env:t.setupEnv})}catch(i){return await Z(e,t,n,vn(i,r),Q(a,c?`no-observation`:`not-started`),o)}let l=Q(a,s.processGroup??`no-spawn`);t.control?.operationConcluded(l);let u=_n(s);if(u!==void 0)return await Z(e,t,n,u,l,o);if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},l,o);let d=await wn(e,t,a,o);return d===void 0?await Z(e,t,n,{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace preparation report refused by the Authority`},l,o):r.aborted?await Z(e,t,n,{kind:`cancelled`},void 0,o):{handle:o,binding:d}}function Q(e,t){return{kind:`workspace-preparation`,operationId:e,setup:t}}async function En(e,t,n,r,i){if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,void 0);let a,o;if(n.workspace!==void 0){let r=await Tn(e,t,n,i.signal);if(`outcome`in r)return r;a=r.handle,o=r.binding}if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,a);let s=await xn(e,t,{operationKind:`workload-invocation`,admissionKey:`workload-invocation:${n.id}:${t.runtimeGeneration}`,signal:i.signal,instruction:n,...a===void 0?{}:{workspace:a}});if(`outcome`in s)return s;let c={kind:`workload-invocation`,operationId:s.operationId};if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},c,a);let l;try{l={kind:`workload-result`,result:ue.parse(await r.invoke({instruction:n,...o===void 0?{}:{workspace:o},signal:i.signal}))}}catch(e){l=Y(e,i.signal)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`workload-invocation`,message:X(e)}}return await Z(e,t,n,l,c,a)}async function Dn(e,t){let n;try{n=await yn(e,t.executionAttemptId,t.runtimeGeneration,t.signal)}catch(n){if(T(n,t.signal))return await Z(e,t,void 0,{kind:`cancelled`},void 0,void 0);throw n}let r=Sn(t.adapters,n);if(r===void 0)return await Z(e,t,n,{kind:`technical-failure`,stage:`startup`,message:`Required adapter '${n.workload.kind}' version '${n.workload.version}' is unavailable`},void 0,void 0);let i;try{i=await(r.bindControl?.({instruction:n,signal:t.signal})??Cn(t.signal))}catch(r){let i=Y(r,t.signal)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`startup`,message:X(r)};return await Z(e,t,n,i,void 0,void 0)}try{return await En(e,t,n,r,i)}finally{try{i.release()}catch{console.warn(`[makaio-worker] Workload control release failed.`)}}}async function On(e,t,n,r,i){let a=he[`runtime.inputs.get`].response.parse(await e.request(C.runtime.inputs.get,{executionAttemptId:t},{signal:i}));if(a.runtimeInputs===null)throw Error(`Selected Worker Runtime inputs are unavailable`);return ge.parse({...n,...a.runtimeInputs,createdAt:0,env:r})}function kn(e,t){let n=(e,t)=>{let n=ae(e,t);return n===``||!re(n)&&n!==`..`&&!n.startsWith(`../`)&&!n.startsWith(`..\\`)};return n(e,t)||n(t,e)}async function An(t,n,r,i){let a=await t.loadContributions(r,i);i.throwIfAborted();let o=e();return await an({connectAuthority:e=>t.connectBus(e,n,i),contributedPackages:[...a],configRepository:t.configRepository,context:{cwd:r.workspaceRoot,platform:r.platform,homedir:o,makaioHome:o,username:`workflow-worker`,machineId:`headless-worker-${t.executionAttemptId}`},toolsets:[...t.toolsets],...t.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:t.prepareAuthRuntime}})}function jn(e,t,n){let r={...e.workflowEnv},i,a=!0;return{adapter:{kind:Ye,version:Xe,async bindControl({instruction:t,signal:r}){let i=k(t);if(i.executionId!==e.executionId)throw Error(`Workflow instruction execution identity mismatch`);let a=new AbortController,o=n.on(ye(i.cancelSubject),()=>a.abort());try{return await xe(o),{signal:AbortSignal.any([...r===void 0?[]:[r],a.signal]),release:o}}catch(e){throw o(),e}},async invoke({instruction:o,workspace:s,signal:c}){let l=k(o);a=o.preservation.required.length!==0;let u=c??new AbortController().signal,d;try{u.throwIfAborted();let a=await On(n,e.executionAttemptId,l,r,u),o=await e.materialize(a,u);(s===void 0||!kn(o.context.workspaceRoot,s.workspaceRoot))&&(i=o.cleanup);let c=Mn(o.context,s);return u.throwIfAborted(),d=await An(e,t,c,u),u.throwIfAborted(),await e.execute(d.bus,a,c,u)}finally{await d?.shutdown()}}},async releaseExecutable(e){e===void 0||a||e.outcome.kind===`workload-result`&&(e.decision!==`accepted`&&e.decision!==`duplicate`||await i?.().catch(()=>void 0))}}}function Mn(e,t){return t===void 0?e:{...e,workspaceRoot:t.workspaceRoot}}const Nn={exited:`setup process group leader exited; whole group proven quiescent`,"signalled-and-quiesced":`setup process group signalled; group proven quiescent afterwards`,"signalled-unconfirmed":`setup process group signalled; quiescence not proven`,"unsignalled-unconfirmed":`setup process group could not be signalled; quiescence not proven`},Pn={"poll-timeout":`quiescence poll timed out`,"ps-unavailable":`ps unavailable on this host`,"signal-error":`a cleanup signal failed`};function Fn(e){let t=Nn[e.outcome];return e.cause===void 0?t:`${t} (${Pn[e.cause]})`}function $(e){return{...e.operationId===void 0?{}:{operationId:e.operationId},conclusion:{status:e.status,boundary:e.boundary,evidence:{source:e.source,summary:e.summary,observedAt:e.observedAt.toISOString(),...e.code===void 0?{}:{code:e.code}}}}}function In(e,t){if(!e.cancelReceived||e.admissionPending)return`pending`;let n=e.admittedOperation;if(n===null)return!e.admissionSettled&&!e.finished?`pending`:$({status:`achieved`,boundary:`admission-closed`,source:`headless-runtime`,summary:Ln(e.admissionRefusalReason),observedAt:t});if(n.kind===`workload-invocation`)return $({operationId:n.operationId,status:`unsupported`,boundary:`workload`,source:`headless-runtime`,summary:`generic workload adapter offers no stop evidence`,observedAt:t});let r=e.conclusion;return r===null||r.kind!==`workspace-preparation`||r.operationId!==n.operationId?`pending`:Rn(n.operationId,r.setup,t)}function Ln(e){let t=`no mutating operation admitted before cancellation`;return e===null?t:`${t}; admission refused (${e})`}function Rn(e,t,n){return $(t===`not-started`?{operationId:e,status:`achieved`,boundary:`setup-process-group`,source:`headless-runtime`,summary:`preparation admitted; setup never started before cancellation`,observedAt:n}:t===`no-spawn`?{operationId:e,status:`achieved`,boundary:`setup-process-group`,source:`setup-driver`,summary:`no live setup process group remains under this operation`,observedAt:n}:t===`no-observation`?{operationId:e,status:`unsupported`,boundary:`setup-process-group`,source:`setup-driver`,summary:`setup driver supplied no process-group observation`,observedAt:n}:{operationId:e,status:t.outcome===`signalled-unconfirmed`||t.outcome===`unsignalled-unconfirmed`?`unconfirmed`:`achieved`,boundary:`setup-process-group`,source:`setup-driver`,summary:Fn(t),observedAt:t.observedAt,code:t.outcome})}var zn=class{state={cancelReceived:!1,admissionPending:!1,admissionSettled:!1,admissionRefusalReason:null,admittedOperation:null,conclusion:null,finished:!1};onUpdate;constructor(e){this.onUpdate=e}markCancelReceived(){this.state.cancelReceived=!0,this.onUpdate()}admissionPending(){this.state.admissionPending=!0,this.onUpdate()}admissionSettled(e){this.state.admissionPending=!1,this.state.admissionSettled=!0,e!==void 0&&(this.state.admissionRefusalReason=e),this.onUpdate()}operationAdmitted(e,t){this.state.admissionPending=!1,this.state.admittedOperation={kind:e,operationId:t},this.onUpdate()}operationConcluded(e){this.state.conclusion=e,this.onUpdate()}finished(){this.state.finished=!0,this.onUpdate()}snapshot(){return{...this.state}}};function Bn(e){return!e.reportPending&&(e.lastReportStatus===void 0||e.lastReportStatus===`error`)}function Vn(e,t){return{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:e.runtimeIncarnationId,runtimeGeneration:e.runtimeGeneration,controlRevision:e.cancellation.controlRevision,requestKey:e.cancellation.requestKey,receivedAt:t.toISOString()}}async function Hn(e,t,n,r){let i={executionAttemptId:t.executionAttemptId,runtimeIncarnationId:t.runtimeIncarnationId,runtimeGeneration:t.runtimeGeneration,controlRevision:t.controlRevision,requestKey:t.requestKey,...n.operationId===void 0?{}:{operationId:n.operationId},conclusion:n.conclusion};try{let t=await K(t=>e.request(x.control.report,i,{timeout:t}),r),n=b[`control.report`].response.parse(t);return n.decision===`accepted`||n.decision===`duplicate`?{status:n.decision,response:n}:{status:`refused`,response:n}}catch(e){return{status:`error`,error:e}}}function Un(e,t){let n=new Set,r;return{dispatch(i,a,o){let s=Hn(e,i,a,t).then(e=>{r=e,n.delete(s),o(e)});n.add(s)},async settle(){for(await new Promise(e=>setImmediate(e));n.size>0;)await Promise.allSettled([...n])},get lastReport(){return r}}}async function Wn(e,t,n={}){let r=n.now??(()=>new Date),i=new Map,a=new AbortController,s=Un(e,n.reportOptions);function c(e){if(!Bn(e))return;let t=In(u.snapshot(),r());t!==`pending`&&(e.reportPending=!0,s.dispatch(e.receipt,t,t=>{e.reportPending=!1,e.lastReportStatus=t.status}))}function l(e){let{controlRevision:t}=e.cancellation,n=i.get(t);if(n!==void 0)return setImmediate(()=>c(n)),n.receipt;let o={receipt:Vn(e,r()),reportPending:!1,lastReportStatus:void 0};return i.set(t,o),setImmediate(()=>{a.abort(),u.markCancelReceived(),c(o)}),o.receipt}let u=new zn(()=>{for(let e of i.values())c(e)}),d=await o(e,t,e=>e.bus.on(x.control.deliver,async t=>{let n=b[`control.deliver`].request.safeParse(t.payload);if(!n.success){t.setResult({decision:`refused`,reason:`unsupported`});return}let r=n.data,i=e.acceptedGeneration??await e.awaitGeneration();if(i===void 0||r.runtimeGeneration!==i){t.setResult({decision:`refused`,reason:`stale-generation`});return}t.setResult({decision:`received`,receipt:l(r)})}),n.signal);return{bindGeneration:e=>d.bindGeneration(e),cleanup:()=>d.cleanup(),signal:a.signal,observer:u,settle:()=>s.settle(),get lastReport(){return s.lastReport}}}async function Gn(e,t){if(!(t.outcome.kind!==`workload-result`||e.onPostCommit===void 0))try{let n=_e.parse(t.outcome.result);await e.onPostCommit(n,t.decision)}catch{}}async function Kn(e,t){t.throwIfAborted();let n={...e.workflowEnv},r=v(),o=await u(e.bootstrapDeadlineAt,t,t=>e.bootstrap(t)),{connection:s,endpoint:c}=await a({executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r,bootstrapDeadlineAt:e.bootstrapDeadlineAt,signal:t,createConnection:()=>qn(e,o)}),l=s.bus,d=jn({...e,workflowEnv:n},o,l),f,p;try{p=await Wn(l,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r},{reportOptions:{retry:e.outcomeRetry,reconnect:()=>l.reconnect()},signal:t});let n=await i(l,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r,signal:t});return c.bindGeneration(n),p.bindGeneration(n),f=await Dn(l,{executionAttemptId:e.executionAttemptId,runtimeGeneration:n,workspaceRoot:e.workspaceRoot,setupEnv:e.setupEnv,preparation:e.preparation,adapters:[d.adapter],signal:AbortSignal.any([t,p.signal]),control:p.observer,retry:e.outcomeRetry,reconnect:()=>l.reconnect()}),await Gn(e,f),f}finally{try{await d.releaseExecutable(f)}finally{p?.observer.finished(),p?.cleanup(),await p?.settle(),c.cleanup(),await s.close()}}}function qn(e,t){let n=w();return n.registerNamespaces([...ce,...le]),{bus:n,async connect(r){try{await e.connectBus(n,t,r),r.throwIfAborted()}catch(e){throw n.disconnect(),e}},close:()=>n.disconnect()}}const Jn=ee(p),Yn=[`-c`,`core.attributesFile=${E}`],Xn=f.object({repositoryId:f.string().min(1),revision:f.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i,`Git source revision must be a full commit object ID`)}).strict();async function Zn(e,t,n){try{let r=await e.resolveRepository(t,n);if(!g.isAbsolute(r))throw Error(`Repository access did not return an absolute path`);return await h.realpath(r)}catch(e){throw Y(e,n)?e:Error(`Git source access failed`)}}async function Qn(e,t,n,r,i){let a;try{a=(await Jn(`git`,[...Yn,`cat-file`,`-t`,t],{cwd:e,env:{...process.env,...n},signal:i,timeout:r,maxBuffer:1024,shell:!1,killSignal:`SIGKILL`,encoding:`utf8`})).stdout.trim()}catch(e){throw Y(e,i)?e:Error(`Git source object inspection failed`)}if(a!==`commit`)throw Error(`Git source revision must identify a commit object`)}function $n(e){if(!on(e.timeoutMs))throw Error(`Git command timeout must be an integer between 1 and 2147483647 milliseconds`);if(process.platform===`win32`)throw Error(`Local Git source preparation requires a POSIX host`);return async({source:t,destination:n,signal:r})=>{if(r?.throwIfAborted(),t.kind!==`git`)throw Error(`Unsupported local Git source kind`);let i=Xn.parse(t.input),a=await Zn(e,i.repositoryId,r);r?.throwIfAborted();let o={...Object.fromEntries(Object.keys(process.env).filter(e=>/^git_/i.test(e)).map(e=>[e,void 0])),GIT_CONFIG_GLOBAL:E,GIT_CONFIG_SYSTEM:E,GIT_ATTR_NOSYSTEM:`1`},s=[[`init`,`--object-format=${i.revision.length===64?`sha256`:`sha1`}`],[`fetch`,`--no-tags`,`--no-write-fetch-head`,`--update-shallow`,`--`,a,i.revision],[`checkout`,`--detach`,i.revision,`--`]];for(let t of s){t[0]===`checkout`&&await Qn(n,i.revision,o,e.timeoutMs,r);let a=await fn({workspaceRoot:n,signal:r,env:o,recipe:{command:`git`,args:[...Yn,...t],env:{},timeoutMs:e.timeoutMs}});if(a.status===`cancelled`&&r?.throwIfAborted(),a.status!==`completed`)throw Error(`Git source ${t[0]} ${a.status}`)}}}function er(e){let t=$n(e);return{prepare:e=>hn({...e,realizeSource:t})}}export{R as A,M as B,Ot as C,St as D,jt as E,pt as F,A as H,vt as I,L,bt as M,yt as N,At as O,ft as P,N as R,V as S,Ct as T,j as V,Nt as _,an as a,z as b,G as c,W as d,Gt as f,Pt as g,It as h,Dn as i,dt as j,ut as k,zt as l,Lt as m,Kn as n,en as o,Wt as p,Wn as r,$t as s,er as t,Rt as u,Mt as v,kt as w,B as x,U as y,P as z};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makaio/framework",
3
- "version": "1.0.0-dev-1789000242829",
3
+ "version": "1.0.0-dev-1789056039016",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/makaio-ai/makaio-framework.git",
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-DTipWd-i.mjs";import{C as t,S as n,a as r,b as i,c as a,d as o,i as s,l as c,n as l,r as u,y as d}from"./schemas-NKlV5jqJ.mjs";import{a as f,f as ee,l as p,m}from"./kind-registration-BanX_UAF.mjs";import{t as h}from"./zod-json-schema-DGWHUOK0.mjs";import{t as g}from"./ajv-Dz-0DD7m.mjs";import{t as _}from"./2020-DvDj4r_K.mjs";import{t as te}from"./dist-DMIaE8sg.mjs";import{z as v}from"zod";import{createBusNamespace as ne}from"@makaio/framework/core";const y=v.strictObject({evidence:n}),b=v.strictObject({kind:v.literal(`text`),text:v.string()}),[x,S,C]=n.options,w=v.union([x.pick({source:!0,location:!0}).extend({content:b}),S.pick({source:!0,location:!0}).extend({content:b}),C.pick({source:!0,location:!0}).extend({content:b})]);function T(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function E(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function D(e,t){if(t===`#`)return{node:e,pointer:``};if(!t.startsWith(`#/`))return;let n;try{n=decodeURIComponent(t.slice(1))}catch{return}let r=e;for(let e of n.slice(1).split(`/`)){let t=e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`);if(Array.isArray(r)){if(!/^(0|[1-9]\d*)$/.test(t)||Number(t)>=r.length)return;r=r[Number(t)]}else{let e=T(r);if(!e||!Object.hasOwn(e,t))return;r=e[t]}}let i=typeof r==`boolean`?r:T(r);return i===void 0?void 0:{node:i,pointer:n}}function O(e,t){if(t===``)return!1;let n=e;for(let e of t.slice(1).split(`/`)){let t=e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`);if(n=Array.isArray(n)?n[Number(t)]:T(n)?.[t],typeof T(n)?.$id==`string`)return!0}return!1}function re(e,t,r){if(e[`x-makaio-value-type`]!==`evidence/v1`)return;let i=n.safeParse(t);if(!i.success)throw Error(`Invalid schema-declared evidence at ${r}`);return{evidence:i.data,dataPath:r}}function ie(e,t,n,r){if(typeof t.$ref!=`string`)return!1;if(r)return!0;let i=D(e,t.$ref);return i===void 0?!0:typeof i.node!=`boolean`&&k(e,i.node,n,O(e,i.pointer))}function k(e,t,n=new WeakSet,r=!1){let i=T(t);if(!i||n.has(i))return!1;n.add(i);let a=r||i!==e&&typeof i.$id==`string`;if(i[`x-makaio-value-type`]===`evidence/v1`||typeof i.$dynamicRef==`string`||ie(e,i,n,a)||[`additionalItems`,`additionalProperties`,`contains`,`else`,`if`,`items`,`then`,`unevaluatedItems`,`unevaluatedProperties`].some(t=>k(e,i[t],n,a))||[`allOf`,`anyOf`,`oneOf`,`prefixItems`].some(t=>Array.isArray(i[t])&&i[t].some(t=>k(e,t,n,a)))||Array.isArray(i.items)&&i.items.some(t=>k(e,t,n,a)))return!0;for(let t of[`dependentSchemas`,`dependencies`,`patternProperties`,`properties`]){let r=T(i[t]);if(r&&Object.values(r).some(t=>k(e,t,n,a)))return!0}return!1}var A=class{dataSchema;matchesSchema;occurrences=new Map;visited=new WeakMap;constructor(e,t){this.dataSchema=e,this.matchesSchema=t}extract(e){return this.visit(this.dataSchema,e,`/data`),[...this.occurrences.values()]}visit(e,t,n,r=``){let i=this.visited.get(e)??new Set;if(i.has(n))return;if(i.add(n),this.visited.set(e,i),typeof e.$dynamicRef==`string`)throw Error(`Evidence discovery does not support active $dynamicRef at ${n}`);if(typeof e.$ref==`string`){if(O(this.dataSchema,r))throw Error(`Evidence discovery does not support local $ref inside nested $id resource at ${n}`);let i=D(this.dataSchema,e.$ref);if(i===void 0)throw Error(`Cannot resolve local schema reference ${e.$ref} at ${n}`);if(typeof i.node!=`boolean`&&this.visit(i.node,t,n,i.pointer),this.dataSchema.$schema!==`https://json-schema.org/draft/2020-12/schema`)return}let a=re(e,t,n);if(a){this.occurrences.set(n,a);return}this.visitCombiners(e,t,n,r),this.visitConditional(e,t,n,r),this.visitDependencies(e,t,n,r),this.assertSupportedApplicators(e,n,r),Array.isArray(t)?this.visitArray(e,t,n,r):typeof t==`object`&&t&&this.visitObject(e,t,n,r)}visitCombiners(e,t,n,r){for(let i of[`allOf`,`anyOf`,`oneOf`]){let a=e[i];if(Array.isArray(a))for(let[e,o]of a.entries()){let a=T(o),s=`${r}/${i}/${e}`;a&&(i===`allOf`||this.matchesSchema(this.dataSchema,s,t))&&this.visit(a,t,n,s)}}}visitConditional(e,t,n,r){let i=typeof e.if==`boolean`?e.if:T(e.if);if(i===void 0)return;let a=`${r}/if`,o=this.matchesSchema(this.dataSchema,a,t);o&&typeof i!=`boolean`&&this.visit(i,t,n,a);let s=o?`then`:`else`,c=T(e[s]);c&&this.visit(c,t,n,`${r}/${s}`)}visitDependencies(e,t,n,r){if(!(typeof t!=`object`||!t||Array.isArray(t)))for(let i of[`dependentSchemas`,`dependencies`]){let a=T(e[i]);if(a)for(let[e,o]of Object.entries(a)){let a=T(o);Object.hasOwn(t,e)&&a&&this.visit(a,t,n,`${r}/${i}/${E(e)}`)}}}assertSupportedApplicators(e,t,n){for(let r of[`unevaluatedProperties`,`unevaluatedItems`])if(k(this.dataSchema,e[r],void 0,O(this.dataSchema,n)))throw Error(`Evidence under unsupported ${r} applicator at ${t}`)}visitArray(e,t,n,r){let i=Array.isArray(e.prefixItems),a=i?e.prefixItems:Array.isArray(e.items)?e.items:[];a.forEach((e,a)=>{let o=T(e),s=i?`prefixItems`:`items`;o&&a<t.length&&this.visit(o,t[a],`${n}/${a}`,`${r}/${s}/${a}`)});let o=Array.isArray(e.items)?T(e.additionalItems):T(e.items);if(o){let i=Array.isArray(e.items)?`additionalItems`:`items`;t.slice(a.length).forEach((e,t)=>this.visit(o,e,`${n}/${a.length+t}`,`${r}/${i}`))}this.visitContains(e,t,n,r)}visitContains(e,t,n,r){let i=T(e.contains);if(!i)return;let a=`${r}/contains`;t.forEach((e,t)=>{this.matchesSchema(this.dataSchema,a,e)&&this.visit(i,e,`${n}/${t}`,a)})}visitObject(e,t,n,r){let i=T(e.properties),a=T(e.patternProperties);for(let[o,s]of Object.entries(t)){let t=E(o),c=i!==void 0&&Object.hasOwn(i,o),l=T(i?.[o]);l&&this.visit(l,s,`${n}/${t}`,`${r}/properties/${t}`);let u=this.visitPatterns(a,o,s,`${n}/${t}`,r),d=T(e.additionalProperties);!c&&!u&&d&&this.visit(d,s,`${n}/${t}`,`${r}/additionalProperties`)}}visitPatterns(e,t,n,r,i){let a=!1;for(let[o,s]of Object.entries(e??{})){if(!new RegExp(o,`u`).test(t))continue;a=!0;let e=T(s);e&&this.visit(e,n,r,`${i}/patternProperties/${E(o)}`)}return a}};function j(e,t,n){return new A(e,n.matchesSchema).extract(t)}function M(e){let{dataSchema:t,hooks:n,...r}=e,i={$schema:`https://json-schema.org/draft/2020-12/schema`,...h(t)};ee(i);let a=f.parse({...r,dataSchema:i});if(a.kind!==e.kind)throw Error(`Artifact kind identifiers must not contain surrounding whitespace`);let o=v.fromJSONSchema(a.dataSchema),s=v.unknown().superRefine((e,t)=>{let n=o.safeParse(e);if(!n.success)for(let e of n.error.issues)t.addIssue({code:`custom`,path:e.path,message:e.message})}).pipe(t).superRefine((e,t)=>{try{m(e,a.titlePath)}catch(e){t.addIssue({code:`custom`,path:a.titlePath.split(`.`),message:e instanceof Error?e.message:`Artifact title must be a nonblank string`})}});return{...structuredClone(a),kind:e.kind,schemaVersion:e.schemaVersion,dataSchema:s,...n?{hooks:n}:{},toRegistration:()=>structuredClone(a)}}var N=e(g(),1),P=e(_(),1),F=e(te(),1);function I(e){let t={allErrors:!0,strict:!1,strictSchema:!0},n=e.dataSchema.$schema===`https://json-schema.org/draft/2020-12/schema`?new P.default(t):new N.default(t);return(0,F.default)(n),n.addKeyword({keyword:i,schemaType:`string`,valid:!0}),n.compile(e.dataSchema)}function L(e){return{hooks:[...e.hooks]}}const R=[`inline`,`summary`,`link`,`omit`],z=v.string().min(1),B=v.object({kinds:v.array(v.string().min(1)).optional(),hint:z.optional(),depth:v.number().int().min(1).max(20).optional(),nested:v.lazy(()=>V).optional()}),V=v.record(v.string().min(1),B);function H(e){return JSON.stringify([e.kind,e.id,e.revision])}const U=v.enum([`not-selected`,`not-found`,`depth-exceeded`,`unsupported-ref-class`,`cycle-detected`]),W=v.object({target:c,sourceRef:t,relationType:v.string().min(1),hint:z,status:v.enum([`resolved`,`unresolved`]),reason:U.optional()}).superRefine((e,t)=>{e.status===`unresolved`&&e.reason===void 0&&t.addIssue({code:v.ZodIssueCode.custom,path:[`reason`],message:`reason is required for unresolved artifact context refs`}),e.status===`resolved`&&e.reason!==void 0&&t.addIssue({code:v.ZodIssueCode.custom,path:[`reason`],message:`reason must be omitted for resolved artifact context refs`}),e.status===`resolved`&&e.target.refClass!==`artifact`&&t.addIssue({code:v.ZodIssueCode.custom,path:[`target`],message:`resolved artifact context refs must target an artifact revision`})}),G=v.object({rootRef:t,refs:v.array(W),resolved:v.array(o)}).superRefine((e,t)=>{let n=new Set(e.resolved.map(H));n.has(H(e.rootRef))||t.addIssue({code:v.ZodIssueCode.custom,path:[`resolved`],message:`resolved artifact context wire payloads must include the root artifact revision`}),e.refs.forEach((e,r)=>{n.has(H(e.sourceRef))||t.addIssue({code:v.ZodIssueCode.custom,path:[`refs`,r,`sourceRef`],message:`artifact context ref sources must have a matching revision in resolved`}),!(e.status!==`resolved`||e.target.refClass!==`artifact`)&&(n.has(H(e.target))||t.addIssue({code:v.ZodIssueCode.custom,path:[`refs`,r,`target`],message:`resolved artifact context refs must have a matching revision in resolved`}))})});function K(e){let t=G.parse(e),n=new Map(t.resolved.map(e=>[Z(e),e])),r=new Map;for(let e of t.refs){let t=Z(e.sourceRef),n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}let i=n.get(Z(t.rootRef));if(!i)throw Error(`Resolved artifact context is missing root artifact '${Z(t.rootRef)}'`);let a=q(t.rootRef,i,`inline`,r,n);return{root:a,flatten(){let e=[];return X(a,e),e}}}function q(e,t,n,r,i){return{status:`resolved`,ref:e,artifact:t,hint:n,children:Y(e,r,i,new Set([Z(e)]))}}function J(e,t,n,r,i,a,o){let s=Z(e),c=new Set(o);return c.add(s),{status:`resolved`,ref:e,artifact:t,relation:n,hint:r,children:Y(e,i,a,c)}}function Y(e,t,n,r){return(t.get(Z(e))??[]).map(e=>{if(e.status===`unresolved`)return{status:`unresolved`,target:e.target,relation:e.relationType,hint:e.hint,reason:e.reason};if(e.target.refClass!==`artifact`)throw Error(`Resolved artifact context refs must target an artifact revision`);let i=Z(e.target),a=n.get(i);if(!a)throw Error(`Resolved artifact context is missing target artifact '${i}'`);return r.has(i)?{status:`unresolved`,target:e.target,relation:e.relationType,hint:e.hint,reason:`cycle-detected`}:J(e.target,a,e.relationType,e.hint,t,n,r)})}function X(e,t){if(e.status!==`unresolved`){t.push(e.artifact);for(let n of e.children)X(n,t)}}function Z(e){return JSON.stringify([e.kind,e.id,e.revision])}const Q={"kind.register":{request:f,response:v.object({registered:v.boolean()})},"kind.list":{request:v.object({kind:v.string().min(1).optional()}),response:v.object({kinds:v.array(f)})},"relation-type.register":{request:d,response:v.object({registered:v.boolean()})},"relation-type.list":{request:v.object({type:v.string().min(1).optional()}),response:v.object({relationTypes:v.array(d)})},create:{request:o.omit({id:!0,revision:!0,timestamp:!0}).extend({id:t.shape.id.optional()}),response:v.object({artifact:o})},revise:{request:v.object({previous:t,statusPath:v.string().regex(/^(?:\/(?:[^~/]|~[01])*)+$/,`Expected a data-relative JSON Pointer`).optional(),revision:o.omit({id:!0,revision:!0,timestamp:!0})}),response:v.object({artifact:o})},resolve:{request:v.object({ref:t}),response:v.object({artifact:o.nullable()})},query:{request:r,response:v.object({artifacts:v.array(o)})},compare:{request:l,response:u},"evidence.resolve":{request:y,response:w},resolveContext:{request:v.object({ref:t,selectors:V.optional(),maxDepth:v.number().int().min(1).max(20).default(5)}),response:v.object({context:G})},created:v.object({artifact:o}),revised:v.object({previous:t,artifact:o}),"relation.added":v.object({artifact:t,relation:a}),"observation.added":v.object({artifact:t,observation:s}),"status.changed":v.object({artifact:t,path:v.string().min(1),previous:v.unknown().optional(),current:v.unknown().optional()}),"kind.changed":v.object({kind:v.string().min(1),schemaVersion:p})},$=ne(`artifact`,Q),ae=$.subjects;export{w as _,W as a,R as c,V as d,L as f,y as g,j as h,K as i,B as l,M as m,Q as n,U as o,I as p,ae as r,G as s,$ as t,z as u};