effect-agent 0.1.0-beta.85 → 0.1.0-beta.87

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 (751) hide show
  1. package/dist/Agent-CN0EWRsR.d.mts +226 -0
  2. package/dist/Agent-RklVROrm.mjs +83 -0
  3. package/dist/Agent-RklVROrm.mjs.map +1 -0
  4. package/dist/AgentError-CggcAQ7V.d.mts +101 -0
  5. package/dist/AgentPolicy-CetmQrf3.d.mts +96 -0
  6. package/dist/AgentRuntime-BLyETCPo.mjs +4562 -0
  7. package/dist/AgentRuntime-BLyETCPo.mjs.map +1 -0
  8. package/dist/AgentRuntime-uxR_a4VM.d.mts +346 -0
  9. package/dist/AgentUpdates-DMJ-_xow.d.mts +53 -0
  10. package/dist/ContextCompactor-Dxu5zhOL.d.mts +161 -0
  11. package/dist/ContextWindow-DRQ5Mbm2.d.mts +58 -0
  12. package/dist/DurableAgentRuntime-uggeJpv3.mjs +6368 -0
  13. package/dist/DurableAgentRuntime-uggeJpv3.mjs.map +1 -0
  14. package/dist/DurableFailpoint-Oinuuedm.d.mts +41 -0
  15. package/dist/DurableStep-Cry_iol4.d.mts +103 -0
  16. package/dist/Ephemeral.d.mts +22 -0
  17. package/dist/Ephemeral.mjs +22 -0
  18. package/dist/Ephemeral.mjs.map +1 -0
  19. package/dist/EventSource-OqS_P9ug.d.mts +51 -0
  20. package/dist/Identifiers-CN2s30fF.d.mts +40 -0
  21. package/dist/MemoryNamespace-BbRW5p71.d.mts +36 -0
  22. package/dist/MemoryReference-B8Q3UJoJ.d.mts +79 -0
  23. package/dist/Messaging-CkcIdt4I.d.mts +490 -0
  24. package/dist/MessagingHost-CRk0kXzT.d.mts +246 -0
  25. package/dist/MessagingHost-CWi_PP3g.mjs +137 -0
  26. package/dist/MessagingHost-CWi_PP3g.mjs.map +1 -0
  27. package/dist/OperationAuthorizer-TzcQtpX5.d.mts +61 -0
  28. package/dist/Output-D6SkedVx.d.mts +25 -0
  29. package/dist/PageCapture-Df8Xwskw.d.mts +583 -0
  30. package/dist/PageScreenshot-BpgZKAxl.d.mts +48 -0
  31. package/dist/PreparedInputAdmission-C4HbjHgl.d.mts +38 -0
  32. package/dist/Receipt-BAHyigAF.d.mts +33 -0
  33. package/dist/Records-BAGkekt8.d.mts +3570 -0
  34. package/dist/RunEvent-DIrzkjLr.d.mts +460 -0
  35. package/dist/RunEventSink-D5aVhISG.d.mts +108 -0
  36. package/dist/RunJournal-Cgg1kNvc.mjs +825 -0
  37. package/dist/RunJournal-Cgg1kNvc.mjs.map +1 -0
  38. package/dist/RunOptions-g1aigcKI.d.mts +915 -0
  39. package/dist/RunPolicyUsage-ClZxyR46.d.mts +21 -0
  40. package/dist/Sandbox-CEsDWBLq.d.mts +173 -0
  41. package/dist/Schedule-H3SEYX9g.d.mts +842 -0
  42. package/dist/Scheduling-C9aIP8zT.mjs +691 -0
  43. package/dist/Scheduling-C9aIP8zT.mjs.map +1 -0
  44. package/dist/Subagent-Cy_hU1tv.mjs +1469 -0
  45. package/dist/Subagent-Cy_hU1tv.mjs.map +1 -0
  46. package/dist/Subagent-DyfzHNdv.d.mts +826 -0
  47. package/dist/SubagentContract-DdT7Cqe6.d.mts +116 -0
  48. package/dist/SubagentHost-CJUBQlcc.d.mts +140 -0
  49. package/dist/Subscription-BEP8oQO5.d.mts +921 -0
  50. package/dist/SubscriptionInput-vAAOBrK7.d.mts +41 -0
  51. package/dist/Thread-DOBQ0QUY.d.mts +96 -0
  52. package/dist/ThreadHistory-tS1KwxHR.d.mts +60 -0
  53. package/dist/ToolBroker-DWs4tZra.d.mts +133 -0
  54. package/dist/ToolExposure-9uF_Yo0T.mjs +10 -0
  55. package/dist/ToolExposure-9uF_Yo0T.mjs.map +1 -0
  56. package/dist/ToolExposure-C93U1sPu.mjs +30 -0
  57. package/dist/ToolExposure-C93U1sPu.mjs.map +1 -0
  58. package/dist/ToolExposure-UCN12eCd.d.mts +39 -0
  59. package/dist/ToolExposure-r2eOWk4F.d.mts +46 -0
  60. package/dist/ToolExposure.d.mts +6 -5
  61. package/dist/ToolExposure.mjs +17 -9
  62. package/dist/ToolExposure.mjs.map +1 -1
  63. package/dist/ToolReconciler-DQVaJfpE.d.mts +76 -0
  64. package/dist/ToolResult-DmmgoChv.d.mts +61 -0
  65. package/dist/Usage-Dx0aknfk.d.mts +121 -0
  66. package/dist/WakeScheduler-EjUF-GhC.d.mts +56 -0
  67. package/dist/Worker-CaPYykpe.d.mts +228 -0
  68. package/dist/agent-registration-CWDMOAZA.mjs +172 -0
  69. package/dist/agent-registration-CWDMOAZA.mjs.map +1 -0
  70. package/dist/capabilities/Approval.d.mts +114 -0
  71. package/dist/capabilities/Approval.mjs +226 -0
  72. package/dist/capabilities/Approval.mjs.map +1 -0
  73. package/dist/capabilities/Budget.d.mts +112 -0
  74. package/dist/capabilities/Budget.mjs +346 -0
  75. package/dist/capabilities/Budget.mjs.map +1 -0
  76. package/dist/capabilities/CodeMode.d.mts +157 -0
  77. package/dist/capabilities/CodeMode.mjs +522 -0
  78. package/dist/capabilities/CodeMode.mjs.map +1 -0
  79. package/dist/capabilities/Commands.d.mts +55 -0
  80. package/dist/capabilities/Commands.mjs +57 -0
  81. package/dist/capabilities/Commands.mjs.map +1 -0
  82. package/dist/capabilities/ContextTools.d.mts +321 -0
  83. package/dist/capabilities/ContextTools.mjs +126 -0
  84. package/dist/capabilities/ContextTools.mjs.map +1 -0
  85. package/dist/capabilities/Mcp.d.mts +108 -0
  86. package/dist/capabilities/Mcp.mjs +260 -0
  87. package/dist/capabilities/Mcp.mjs.map +1 -0
  88. package/dist/capabilities/McpClient.d.mts +115 -0
  89. package/dist/capabilities/McpClient.mjs +506 -0
  90. package/dist/capabilities/McpClient.mjs.map +1 -0
  91. package/dist/capabilities/MemoryNotes.d.mts +424 -0
  92. package/dist/capabilities/MemoryNotes.mjs +128 -0
  93. package/dist/capabilities/MemoryNotes.mjs.map +1 -0
  94. package/dist/capabilities/Messaging.d.mts +3 -0
  95. package/dist/capabilities/Messaging.mjs +151 -0
  96. package/dist/capabilities/Messaging.mjs.map +1 -0
  97. package/dist/capabilities/ModelContext.d.mts +89 -0
  98. package/dist/capabilities/ModelContext.mjs +168 -0
  99. package/dist/capabilities/ModelContext.mjs.map +1 -0
  100. package/dist/capabilities/Redaction.d.mts +37 -0
  101. package/dist/capabilities/Redaction.mjs +104 -0
  102. package/dist/capabilities/Redaction.mjs.map +1 -0
  103. package/dist/capabilities/Remembering.d.mts +434 -0
  104. package/dist/capabilities/Remembering.mjs +290 -0
  105. package/dist/capabilities/Remembering.mjs.map +1 -0
  106. package/dist/capabilities/RunHooks.d.mts +82 -0
  107. package/dist/capabilities/RunHooks.mjs +144 -0
  108. package/dist/capabilities/RunHooks.mjs.map +1 -0
  109. package/dist/capabilities/SemanticMemory.d.mts +431 -0
  110. package/dist/capabilities/SemanticMemory.mjs +315 -0
  111. package/dist/capabilities/SemanticMemory.mjs.map +1 -0
  112. package/dist/capabilities/Subagent.d.mts +4 -0
  113. package/dist/capabilities/Subagent.mjs +5 -0
  114. package/dist/capabilities/SubagentReservations.d.mts +186 -0
  115. package/dist/capabilities/SubagentReservations.mjs +479 -0
  116. package/dist/capabilities/SubagentReservations.mjs.map +1 -0
  117. package/dist/capabilities/ToolDiscovery.d.mts +109 -0
  118. package/dist/capabilities/ToolDiscovery.mjs +211 -0
  119. package/dist/capabilities/ToolDiscovery.mjs.map +1 -0
  120. package/dist/capabilities/WebCapture.d.mts +163 -0
  121. package/dist/capabilities/WebCapture.mjs +335 -0
  122. package/dist/capabilities/WebCapture.mjs.map +1 -0
  123. package/dist/capabilities/WebSearch.d.mts +71 -0
  124. package/dist/capabilities/WebSearch.mjs +112 -0
  125. package/dist/capabilities/WebSearch.mjs.map +1 -0
  126. package/dist/compaction-C2OTceKw.mjs +505 -0
  127. package/dist/compaction-C2OTceKw.mjs.map +1 -0
  128. package/dist/core/Agent.d.mts +2 -0
  129. package/dist/core/Agent.mjs +2 -0
  130. package/dist/core/AgentError.d.mts +2 -0
  131. package/dist/core/AgentError.mjs +117 -0
  132. package/dist/core/AgentError.mjs.map +1 -0
  133. package/dist/core/AgentPolicy.d.mts +2 -0
  134. package/dist/core/AgentPolicy.mjs +94 -0
  135. package/dist/core/AgentPolicy.mjs.map +1 -0
  136. package/dist/core/AgentUpdates.d.mts +2 -0
  137. package/dist/core/AgentUpdates.mjs +63 -0
  138. package/dist/core/AgentUpdates.mjs.map +1 -0
  139. package/dist/core/IdGenerator.d.mts +26 -0
  140. package/dist/core/IdGenerator.mjs +27 -0
  141. package/dist/core/IdGenerator.mjs.map +1 -0
  142. package/dist/core/Identifiers.d.mts +2 -0
  143. package/dist/core/Identifiers.mjs +43 -0
  144. package/dist/core/Identifiers.mjs.map +1 -0
  145. package/dist/core/Memory.d.mts +57 -0
  146. package/dist/core/Memory.mjs +203 -0
  147. package/dist/core/Memory.mjs.map +1 -0
  148. package/dist/core/MemoryNamespace.d.mts +2 -0
  149. package/dist/core/MemoryNamespace.mjs +116 -0
  150. package/dist/core/MemoryNamespace.mjs.map +1 -0
  151. package/dist/core/MemoryReference.d.mts +2 -0
  152. package/dist/core/MemoryReference.mjs +109 -0
  153. package/dist/core/MemoryReference.mjs.map +1 -0
  154. package/dist/core/MemoryRevalidation.d.mts +65 -0
  155. package/dist/core/MemoryRevalidation.mjs +126 -0
  156. package/dist/core/MemoryRevalidation.mjs.map +1 -0
  157. package/dist/core/MemoryStore.d.mts +186 -0
  158. package/dist/core/MemoryStore.mjs +243 -0
  159. package/dist/core/MemoryStore.mjs.map +1 -0
  160. package/dist/core/Receipt.d.mts +2 -0
  161. package/dist/core/Receipt.mjs +36 -0
  162. package/dist/core/Receipt.mjs.map +1 -0
  163. package/dist/core/RememberingStore.d.mts +1562 -0
  164. package/dist/core/RememberingStore.mjs +190 -0
  165. package/dist/core/RememberingStore.mjs.map +1 -0
  166. package/dist/core/RunEvent.d.mts +2 -0
  167. package/dist/core/RunEvent.mjs +337 -0
  168. package/dist/core/RunEvent.mjs.map +1 -0
  169. package/dist/core/RunPolicyUsage.d.mts +2 -0
  170. package/dist/core/RunPolicyUsage.mjs +21 -0
  171. package/dist/core/RunPolicyUsage.mjs.map +1 -0
  172. package/dist/core/SemanticMemoryIndex.d.mts +826 -0
  173. package/dist/core/SemanticMemoryIndex.mjs +185 -0
  174. package/dist/core/SemanticMemoryIndex.mjs.map +1 -0
  175. package/dist/core/SemanticMemoryRevalidation.d.mts +45 -0
  176. package/dist/core/SemanticMemoryRevalidation.mjs +191 -0
  177. package/dist/core/SemanticMemoryRevalidation.mjs.map +1 -0
  178. package/dist/core/SubagentContract.d.mts +2 -0
  179. package/dist/core/SubagentContract.mjs +148 -0
  180. package/dist/core/SubagentContract.mjs.map +1 -0
  181. package/dist/core/Thread.d.mts +2 -0
  182. package/dist/core/Thread.mjs +250 -0
  183. package/dist/core/Thread.mjs.map +1 -0
  184. package/dist/core/ToolResult.d.mts +2 -0
  185. package/dist/core/ToolResult.mjs +140 -0
  186. package/dist/core/ToolResult.mjs.map +1 -0
  187. package/dist/core/Usage.d.mts +2 -0
  188. package/dist/core/Usage.mjs +319 -0
  189. package/dist/core/Usage.mjs.map +1 -0
  190. package/dist/core/Worker.d.mts +3 -0
  191. package/dist/core/Worker.mjs +147 -0
  192. package/dist/core/Worker.mjs.map +1 -0
  193. package/dist/durable/ActivityStore.d.mts +116 -0
  194. package/dist/durable/ActivityStore.mjs +131 -0
  195. package/dist/durable/ActivityStore.mjs.map +1 -0
  196. package/dist/durable/Admin.d.mts +2 -0
  197. package/dist/durable/Admin.mjs +328 -0
  198. package/dist/durable/Admin.mjs.map +1 -0
  199. package/dist/durable/AgentRegistration.d.mts +2 -0
  200. package/dist/durable/AgentRegistration.mjs +14 -0
  201. package/dist/durable/AgentRegistration.mjs.map +1 -0
  202. package/dist/durable/Certification.d.mts +111 -0
  203. package/dist/durable/Certification.mjs +159 -0
  204. package/dist/durable/Certification.mjs.map +1 -0
  205. package/dist/durable/CommittedActivity.d.mts +62 -0
  206. package/dist/durable/CommittedActivity.mjs +159 -0
  207. package/dist/durable/CommittedActivity.mjs.map +1 -0
  208. package/dist/durable/Digest.d.mts +2 -0
  209. package/dist/durable/Digest.mjs +50 -0
  210. package/dist/durable/Digest.mjs.map +1 -0
  211. package/dist/durable/DurableAgentRuntime.d.mts +3 -0
  212. package/dist/durable/DurableAgentRuntime.mjs +3 -0
  213. package/dist/durable/DurableFailpoint.d.mts +2 -0
  214. package/dist/durable/DurableFailpoint.mjs +94 -0
  215. package/dist/durable/DurableFailpoint.mjs.map +1 -0
  216. package/dist/durable/DurableFailpointTestControl.d.mts +15 -0
  217. package/dist/durable/DurableFailpointTestControl.mjs +19 -0
  218. package/dist/durable/DurableFailpointTestControl.mjs.map +1 -0
  219. package/dist/durable/EventSource.d.mts +2 -0
  220. package/dist/durable/EventSource.mjs +65 -0
  221. package/dist/durable/EventSource.mjs.map +1 -0
  222. package/dist/durable/GitHubWorkflowSource.d.mts +144 -0
  223. package/dist/durable/GitHubWorkflowSource.mjs +209 -0
  224. package/dist/durable/GitHubWorkflowSource.mjs.map +1 -0
  225. package/dist/durable/MessageDelivery.d.mts +492 -0
  226. package/dist/durable/MessageDelivery.mjs +495 -0
  227. package/dist/durable/MessageDelivery.mjs.map +1 -0
  228. package/dist/durable/MessageDeliveryStoreConformance.d.mts +358 -0
  229. package/dist/durable/MessageDeliveryStoreConformance.mjs +243 -0
  230. package/dist/durable/MessageDeliveryStoreConformance.mjs.map +1 -0
  231. package/dist/durable/OperationAuthorizer.d.mts +2 -0
  232. package/dist/durable/OperationAuthorizer.mjs +70 -0
  233. package/dist/durable/OperationAuthorizer.mjs.map +1 -0
  234. package/dist/durable/PersistentHistory.d.mts +16 -0
  235. package/dist/durable/PersistentHistory.mjs +125 -0
  236. package/dist/durable/PersistentHistory.mjs.map +1 -0
  237. package/dist/durable/PreparedInputAdmission.d.mts +2 -0
  238. package/dist/durable/PreparedInputAdmission.mjs +34 -0
  239. package/dist/durable/PreparedInputAdmission.mjs.map +1 -0
  240. package/dist/durable/Records.d.mts +2 -0
  241. package/dist/durable/Records.mjs +795 -0
  242. package/dist/durable/Records.mjs.map +1 -0
  243. package/dist/durable/Recovery.d.mts +2 -0
  244. package/dist/durable/Recovery.mjs +739 -0
  245. package/dist/durable/Recovery.mjs.map +1 -0
  246. package/dist/durable/RunJournal.d.mts +2 -0
  247. package/dist/durable/RunJournal.mjs +2 -0
  248. package/dist/durable/Schedule.d.mts +2 -0
  249. package/dist/durable/Schedule.mjs +382 -0
  250. package/dist/durable/Schedule.mjs.map +1 -0
  251. package/dist/durable/ScheduleStoreConformance.d.mts +18 -0
  252. package/dist/durable/ScheduleStoreConformance.mjs +420 -0
  253. package/dist/durable/ScheduleStoreConformance.mjs.map +1 -0
  254. package/dist/durable/ScheduleTransition.d.mts +24 -0
  255. package/dist/durable/ScheduleTransition.mjs +180 -0
  256. package/dist/durable/ScheduleTransition.mjs.map +1 -0
  257. package/dist/durable/Scheduling.d.mts +54 -0
  258. package/dist/durable/Scheduling.mjs +2 -0
  259. package/dist/durable/SqlMemoryStore.d.mts +30 -0
  260. package/dist/durable/SqlMemoryStore.mjs +435 -0
  261. package/dist/durable/SqlMemoryStore.mjs.map +1 -0
  262. package/dist/durable/SqlMessageDeliveryStore.d.mts +40 -0
  263. package/dist/durable/SqlMessageDeliveryStore.mjs +167 -0
  264. package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -0
  265. package/dist/durable/SqlStorageV2Upgrade.d.mts +22 -0
  266. package/dist/durable/SqlStorageV2Upgrade.mjs +459 -0
  267. package/dist/durable/SqlStorageV2Upgrade.mjs.map +1 -0
  268. package/dist/durable/SqlSubscriptionStore.d.mts +63 -0
  269. package/dist/durable/SqlSubscriptionStore.mjs +751 -0
  270. package/dist/durable/SqlSubscriptionStore.mjs.map +1 -0
  271. package/dist/durable/SubmissionLedger.d.mts +3 -0
  272. package/dist/durable/SubmissionLedger.mjs +914 -0
  273. package/dist/durable/SubmissionLedger.mjs.map +1 -0
  274. package/dist/durable/SubmissionLedgerConformance.d.mts +30 -0
  275. package/dist/durable/SubmissionLedgerConformance.mjs +1986 -0
  276. package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -0
  277. package/dist/durable/SubmissionStatus.d.mts +2 -0
  278. package/dist/durable/SubmissionStatus.mjs +18 -0
  279. package/dist/durable/SubmissionStatus.mjs.map +1 -0
  280. package/dist/durable/Subscription.d.mts +2 -0
  281. package/dist/durable/Subscription.mjs +360 -0
  282. package/dist/durable/Subscription.mjs.map +1 -0
  283. package/dist/durable/SubscriptionInput.d.mts +2 -0
  284. package/dist/durable/SubscriptionInput.mjs +52 -0
  285. package/dist/durable/SubscriptionInput.mjs.map +1 -0
  286. package/dist/durable/SubscriptionStoreConformance.d.mts +17 -0
  287. package/dist/durable/SubscriptionStoreConformance.mjs +625 -0
  288. package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -0
  289. package/dist/durable/SubscriptionTools.d.mts +273 -0
  290. package/dist/durable/SubscriptionTools.mjs +190 -0
  291. package/dist/durable/SubscriptionTools.mjs.map +1 -0
  292. package/dist/durable/SubscriptionTransition.d.mts +21 -0
  293. package/dist/durable/SubscriptionTransition.mjs +148 -0
  294. package/dist/durable/SubscriptionTransition.mjs.map +1 -0
  295. package/dist/durable/Subscriptions.d.mts +73 -0
  296. package/dist/durable/Subscriptions.mjs +627 -0
  297. package/dist/durable/Subscriptions.mjs.map +1 -0
  298. package/dist/durable/ThreadContextHistory.d.mts +32 -0
  299. package/dist/durable/ThreadContextHistory.mjs +152 -0
  300. package/dist/durable/ThreadContextHistory.mjs.map +1 -0
  301. package/dist/durable/ThreadContextHistoryProjection.d.mts +60 -0
  302. package/dist/durable/ThreadContextHistoryProjection.mjs +149 -0
  303. package/dist/durable/ThreadContextHistoryProjection.mjs.map +1 -0
  304. package/dist/durable/ThreadInvariants.d.mts +74 -0
  305. package/dist/durable/ThreadInvariants.mjs +200 -0
  306. package/dist/durable/ThreadInvariants.mjs.map +1 -0
  307. package/dist/durable/ThreadProjection.d.mts +78 -0
  308. package/dist/durable/ThreadProjection.mjs +158 -0
  309. package/dist/durable/ThreadProjection.mjs.map +1 -0
  310. package/dist/durable/ThreadProjectionMaintenance.d.mts +49 -0
  311. package/dist/durable/ThreadProjectionMaintenance.mjs +33 -0
  312. package/dist/durable/ThreadProjectionMaintenance.mjs.map +1 -0
  313. package/dist/durable/ThreadStore.d.mts +2 -0
  314. package/dist/durable/ThreadStore.mjs +147 -0
  315. package/dist/durable/ThreadStore.mjs.map +1 -0
  316. package/dist/durable/ThreadStoreConformance.d.mts +29 -0
  317. package/dist/durable/ThreadStoreConformance.mjs +248 -0
  318. package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
  319. package/dist/durable/ToolReconciler.d.mts +2 -0
  320. package/dist/durable/ToolReconciler.mjs +81 -0
  321. package/dist/durable/ToolReconciler.mjs.map +1 -0
  322. package/dist/durable/WakeScheduler.d.mts +2 -0
  323. package/dist/durable/WakeScheduler.mjs +85 -0
  324. package/dist/durable/WakeScheduler.mjs.map +1 -0
  325. package/dist/durable/WorkerHost.d.mts +129 -0
  326. package/dist/durable/WorkerHost.mjs +77 -0
  327. package/dist/durable/WorkerHost.mjs.map +1 -0
  328. package/dist/engine/AgentRuntime.d.mts +2 -0
  329. package/dist/engine/AgentRuntime.mjs +2 -0
  330. package/dist/engine/Compaction.d.mts +7 -0
  331. package/dist/engine/Compaction.mjs +16 -0
  332. package/dist/engine/Compaction.mjs.map +1 -0
  333. package/dist/engine/ContextCompactor.d.mts +2 -0
  334. package/dist/engine/ContextCompactor.mjs +119 -0
  335. package/dist/engine/ContextCompactor.mjs.map +1 -0
  336. package/dist/engine/ContextHistory.d.mts +65 -0
  337. package/dist/engine/ContextHistory.mjs +76 -0
  338. package/dist/engine/ContextHistory.mjs.map +1 -0
  339. package/dist/engine/ContextWindow.d.mts +2 -0
  340. package/dist/engine/ContextWindow.mjs +59 -0
  341. package/dist/engine/ContextWindow.mjs.map +1 -0
  342. package/dist/engine/DurableStep.d.mts +2 -0
  343. package/dist/engine/DurableStep.mjs +62 -0
  344. package/dist/engine/DurableStep.mjs.map +1 -0
  345. package/dist/engine/MessagingHost.d.mts +2 -0
  346. package/dist/engine/MessagingHost.mjs +2 -0
  347. package/dist/engine/Output.d.mts +2 -0
  348. package/dist/engine/Output.mjs +8 -0
  349. package/dist/engine/Output.mjs.map +1 -0
  350. package/dist/engine/RunEventSink.d.mts +2 -0
  351. package/dist/engine/RunEventSink.mjs +22 -0
  352. package/dist/engine/RunEventSink.mjs.map +1 -0
  353. package/dist/engine/RunOptions.d.mts +2 -0
  354. package/dist/engine/RunOptions.mjs +122 -0
  355. package/dist/engine/RunOptions.mjs.map +1 -0
  356. package/dist/engine/SubagentHost.d.mts +2 -0
  357. package/dist/engine/SubagentHost.mjs +72 -0
  358. package/dist/engine/SubagentHost.mjs.map +1 -0
  359. package/dist/engine/ThreadHistory.d.mts +2 -0
  360. package/dist/engine/ThreadHistory.mjs +67 -0
  361. package/dist/engine/ThreadHistory.mjs.map +1 -0
  362. package/dist/engine/ToolBroker.d.mts +2 -0
  363. package/dist/engine/ToolBroker.mjs +42 -0
  364. package/dist/engine/ToolBroker.mjs.map +1 -0
  365. package/dist/foreign-diagnostic-DBQ1XHKh.mjs +37 -0
  366. package/dist/foreign-diagnostic-DBQ1XHKh.mjs.map +1 -0
  367. package/dist/index.d.mts +88 -54
  368. package/dist/index.mjs +97 -54
  369. package/dist/output-contract-BC7tjlGw.mjs +84 -0
  370. package/dist/output-contract-BC7tjlGw.mjs.map +1 -0
  371. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  372. package/dist/sandbox/CodeExecutor.d.mts +194 -0
  373. package/dist/sandbox/CodeExecutor.mjs +278 -0
  374. package/dist/sandbox/CodeExecutor.mjs.map +1 -0
  375. package/dist/sandbox/InteractiveBrowser.d.mts +142 -0
  376. package/dist/sandbox/InteractiveBrowser.mjs +165 -0
  377. package/dist/sandbox/InteractiveBrowser.mjs.map +1 -0
  378. package/dist/sandbox/PageCapture.d.mts +2 -0
  379. package/dist/sandbox/PageCapture.mjs +450 -0
  380. package/dist/sandbox/PageCapture.mjs.map +1 -0
  381. package/dist/sandbox/PageCrawl.d.mts +88 -0
  382. package/dist/sandbox/PageCrawl.mjs +124 -0
  383. package/dist/sandbox/PageCrawl.mjs.map +1 -0
  384. package/dist/sandbox/PageScreenshot.d.mts +2 -0
  385. package/dist/sandbox/PageScreenshot.mjs +53 -0
  386. package/dist/sandbox/PageScreenshot.mjs.map +1 -0
  387. package/dist/sandbox/ProtectedBrowser.d.mts +252 -0
  388. package/dist/sandbox/ProtectedBrowser.mjs +270 -0
  389. package/dist/sandbox/ProtectedBrowser.mjs.map +1 -0
  390. package/dist/sandbox/Sandbox.d.mts +2 -0
  391. package/dist/sandbox/Sandbox.mjs +208 -0
  392. package/dist/sandbox/Sandbox.mjs.map +1 -0
  393. package/dist/utf8-BYfhEkcj.mjs +11 -0
  394. package/dist/utf8-BYfhEkcj.mjs.map +1 -0
  395. package/dist/utf8-DchGZRBd.mjs +23 -0
  396. package/dist/utf8-DchGZRBd.mjs.map +1 -0
  397. package/package.json +1 -1
  398. package/src/Ephemeral.ts +17 -0
  399. package/src/ToolExposure.ts +2 -2
  400. package/src/capabilities/Approval.ts +352 -0
  401. package/src/capabilities/Budget.ts +536 -0
  402. package/src/capabilities/CodeMode.ts +1090 -0
  403. package/src/capabilities/Commands.ts +86 -0
  404. package/src/capabilities/ContextTools.ts +184 -0
  405. package/src/capabilities/Mcp.ts +427 -0
  406. package/src/capabilities/McpClient.ts +967 -0
  407. package/src/capabilities/MemoryNotes.ts +174 -0
  408. package/src/capabilities/Messaging.ts +261 -0
  409. package/src/capabilities/ModelContext.ts +354 -0
  410. package/src/capabilities/Redaction.ts +157 -0
  411. package/src/capabilities/Remembering.ts +550 -0
  412. package/src/capabilities/RunHooks.ts +280 -0
  413. package/src/capabilities/SemanticMemory.ts +447 -0
  414. package/src/capabilities/Subagent.ts +2277 -0
  415. package/src/capabilities/SubagentReservations.ts +850 -0
  416. package/src/capabilities/ToolDiscovery.ts +339 -0
  417. package/src/capabilities/WebCapture.ts +722 -0
  418. package/src/capabilities/WebSearch.ts +184 -0
  419. package/src/capabilities/internal/subagent-background.ts +1106 -0
  420. package/src/capabilities/internal/subagent-contract.ts +142 -0
  421. package/src/capabilities/internal/subagent-policy.ts +235 -0
  422. package/src/capabilities/internal/subagent-reporting.ts +261 -0
  423. package/src/capabilities/internal/utf8.ts +10 -0
  424. package/src/core/Agent.ts +575 -0
  425. package/src/core/AgentError.ts +152 -0
  426. package/src/core/AgentPolicy.ts +153 -0
  427. package/src/core/AgentUpdates.ts +100 -0
  428. package/src/core/IdGenerator.ts +39 -0
  429. package/src/core/Identifiers.ts +48 -0
  430. package/src/core/Memory.ts +290 -0
  431. package/src/core/MemoryNamespace.ts +196 -0
  432. package/src/core/MemoryReference.ts +121 -0
  433. package/src/core/MemoryRevalidation.ts +185 -0
  434. package/src/core/MemoryStore.ts +368 -0
  435. package/src/core/Messaging.ts +90 -0
  436. package/src/core/Receipt.ts +42 -0
  437. package/src/core/RememberingStore.ts +300 -0
  438. package/src/core/RunEvent.ts +366 -0
  439. package/src/core/RunPolicyUsage.ts +17 -0
  440. package/src/core/SemanticMemoryIndex.ts +250 -0
  441. package/src/core/SemanticMemoryRevalidation.ts +254 -0
  442. package/src/core/SubagentContract.ts +196 -0
  443. package/src/core/Thread.ts +371 -0
  444. package/src/core/ToolExposure.ts +74 -0
  445. package/src/core/ToolResult.ts +170 -0
  446. package/src/core/Usage.ts +529 -0
  447. package/src/core/Worker.ts +173 -0
  448. package/src/core/internal/agent-updates.ts +32 -0
  449. package/src/core/internal/utf8.ts +23 -0
  450. package/src/durable/ActivityStore.ts +160 -0
  451. package/src/durable/Admin.ts +496 -0
  452. package/src/durable/AgentRegistration.ts +13 -0
  453. package/src/durable/Certification.ts +210 -0
  454. package/src/durable/CommittedActivity.ts +296 -0
  455. package/src/durable/Digest.ts +93 -0
  456. package/src/durable/DurableAgentRuntime.ts +10340 -0
  457. package/src/durable/DurableFailpoint.ts +103 -0
  458. package/src/durable/DurableFailpointTestControl.ts +39 -0
  459. package/src/durable/EventSource.ts +172 -0
  460. package/src/durable/GitHubWorkflowSource.ts +453 -0
  461. package/src/durable/MessageDelivery.ts +708 -0
  462. package/src/durable/MessageDeliveryStoreConformance.ts +363 -0
  463. package/src/durable/OperationAuthorizer.ts +85 -0
  464. package/src/durable/PersistentHistory.ts +260 -0
  465. package/src/durable/PreparedInputAdmission.ts +44 -0
  466. package/src/durable/Records.ts +1010 -0
  467. package/src/durable/Recovery.ts +1018 -0
  468. package/src/durable/RunJournal.ts +1479 -0
  469. package/src/durable/Schedule.ts +504 -0
  470. package/src/durable/ScheduleStoreConformance.ts +638 -0
  471. package/src/durable/ScheduleTransition.ts +265 -0
  472. package/src/durable/Scheduling.ts +1077 -0
  473. package/src/durable/SqlMemoryStore.ts +774 -0
  474. package/src/durable/SqlMessageDeliveryStore.ts +302 -0
  475. package/src/durable/SqlStorageV2Upgrade.ts +500 -0
  476. package/src/durable/SqlSubscriptionStore.ts +1440 -0
  477. package/src/durable/SubmissionLedger.ts +1201 -0
  478. package/src/durable/SubmissionLedgerConformance.ts +4579 -0
  479. package/src/durable/SubmissionStatus.ts +14 -0
  480. package/src/durable/Subscription.ts +544 -0
  481. package/src/durable/SubscriptionInput.ts +144 -0
  482. package/src/durable/SubscriptionStoreConformance.ts +945 -0
  483. package/src/durable/SubscriptionTools.ts +327 -0
  484. package/src/durable/SubscriptionTransition.ts +302 -0
  485. package/src/durable/Subscriptions.ts +1210 -0
  486. package/src/durable/ThreadContextHistory.ts +227 -0
  487. package/src/durable/ThreadContextHistoryProjection.ts +216 -0
  488. package/src/durable/ThreadInvariants.ts +442 -0
  489. package/src/durable/ThreadProjection.ts +269 -0
  490. package/src/durable/ThreadProjectionMaintenance.ts +67 -0
  491. package/src/durable/ThreadStore.ts +242 -0
  492. package/src/durable/ThreadStoreConformance.ts +710 -0
  493. package/src/durable/ToolReconciler.ts +105 -0
  494. package/src/durable/WakeScheduler.ts +134 -0
  495. package/src/durable/WorkerHost.ts +171 -0
  496. package/src/durable/internal/agent-registration.ts +525 -0
  497. package/src/durable/internal/agent-updates.ts +302 -0
  498. package/src/durable/internal/foreign-diagnostic.ts +47 -0
  499. package/src/durable/internal/journal-checkpoint.ts +104 -0
  500. package/src/durable/internal/journal-metadata.ts +107 -0
  501. package/src/durable/internal/messaging-host.ts +608 -0
  502. package/src/durable/internal/schedule-time.ts +303 -0
  503. package/src/durable/internal/storage-v2-layout.ts +163 -0
  504. package/src/durable/internal/storage-v2.ts +73 -0
  505. package/src/durable/internal/worker-host.ts +2467 -0
  506. package/src/durable/internal/worker-runtime.ts +9 -0
  507. package/src/engine/AgentRuntime.ts +37 -0
  508. package/src/engine/Compaction.ts +11 -0
  509. package/src/engine/ContextCompactor.ts +277 -0
  510. package/src/engine/ContextHistory.ts +73 -0
  511. package/src/engine/ContextWindow.ts +72 -0
  512. package/src/engine/DurableStep.ts +132 -0
  513. package/src/engine/MessagingHost.ts +110 -0
  514. package/src/engine/Output.ts +2 -0
  515. package/src/engine/RunEventSink.ts +132 -0
  516. package/src/engine/RunOptions.ts +1077 -0
  517. package/src/engine/SubagentHost.ts +181 -0
  518. package/src/engine/ThreadHistory.ts +120 -0
  519. package/src/engine/ToolBroker.ts +157 -0
  520. package/src/engine/ToolExposure.ts +48 -0
  521. package/src/engine/internal/agent-runtime.ts +10117 -0
  522. package/src/engine/internal/bounded-value.ts +315 -0
  523. package/src/engine/internal/compaction.ts +678 -0
  524. package/src/engine/internal/error-diagnostic.ts +39 -0
  525. package/src/engine/internal/output-contract.ts +173 -0
  526. package/src/engine/internal/primitive-delta.ts +80 -0
  527. package/src/engine/internal/provider-result-staging.ts +211 -0
  528. package/src/engine/internal/tool-derivative.ts +106 -0
  529. package/src/engine/internal/tool-exposure.ts +224 -0
  530. package/src/engine/internal/tool-telemetry.ts +484 -0
  531. package/src/index.ts +96 -53
  532. package/src/sandbox/CodeExecutor.ts +352 -0
  533. package/src/sandbox/InteractiveBrowser.ts +257 -0
  534. package/src/sandbox/PageCapture.ts +692 -0
  535. package/src/sandbox/PageCrawl.ts +148 -0
  536. package/src/sandbox/PageScreenshot.ts +81 -0
  537. package/src/sandbox/ProtectedBrowser.ts +413 -0
  538. package/src/sandbox/Sandbox.ts +241 -0
  539. package/dist/Agent.d.mts +0 -5
  540. package/dist/Agent.mjs +0 -10
  541. package/dist/Agent.mjs.map +0 -1
  542. package/dist/AgentError.d.mts +0 -5
  543. package/dist/AgentError.mjs +0 -10
  544. package/dist/AgentError.mjs.map +0 -1
  545. package/dist/AgentPolicy.d.mts +0 -5
  546. package/dist/AgentPolicy.mjs +0 -10
  547. package/dist/AgentPolicy.mjs.map +0 -1
  548. package/dist/AgentRuntime.d.mts +0 -5
  549. package/dist/AgentRuntime.mjs +0 -10
  550. package/dist/AgentRuntime.mjs.map +0 -1
  551. package/dist/AgentUpdates.d.mts +0 -5
  552. package/dist/AgentUpdates.mjs +0 -10
  553. package/dist/AgentUpdates.mjs.map +0 -1
  554. package/dist/Approval.d.mts +0 -5
  555. package/dist/Approval.mjs +0 -10
  556. package/dist/Approval.mjs.map +0 -1
  557. package/dist/Budget.d.mts +0 -5
  558. package/dist/Budget.mjs +0 -10
  559. package/dist/Budget.mjs.map +0 -1
  560. package/dist/CodeMode.d.mts +0 -5
  561. package/dist/CodeMode.mjs +0 -10
  562. package/dist/CodeMode.mjs.map +0 -1
  563. package/dist/Commands.d.mts +0 -5
  564. package/dist/Commands.mjs +0 -10
  565. package/dist/Commands.mjs.map +0 -1
  566. package/dist/Compaction.d.mts +0 -5
  567. package/dist/Compaction.mjs +0 -10
  568. package/dist/Compaction.mjs.map +0 -1
  569. package/dist/ContextCompactor.d.mts +0 -5
  570. package/dist/ContextCompactor.mjs +0 -10
  571. package/dist/ContextCompactor.mjs.map +0 -1
  572. package/dist/ContextHistory.d.mts +0 -5
  573. package/dist/ContextHistory.mjs +0 -10
  574. package/dist/ContextHistory.mjs.map +0 -1
  575. package/dist/ContextTools.d.mts +0 -5
  576. package/dist/ContextTools.mjs +0 -10
  577. package/dist/ContextTools.mjs.map +0 -1
  578. package/dist/ContextWindow.d.mts +0 -5
  579. package/dist/ContextWindow.mjs +0 -10
  580. package/dist/ContextWindow.mjs.map +0 -1
  581. package/dist/DurableStep.d.mts +0 -5
  582. package/dist/DurableStep.mjs +0 -10
  583. package/dist/DurableStep.mjs.map +0 -1
  584. package/dist/EphemeralThreads.d.mts +0 -5
  585. package/dist/EphemeralThreads.mjs +0 -10
  586. package/dist/EphemeralThreads.mjs.map +0 -1
  587. package/dist/IdGenerator.d.mts +0 -5
  588. package/dist/IdGenerator.mjs +0 -10
  589. package/dist/IdGenerator.mjs.map +0 -1
  590. package/dist/Identifiers.d.mts +0 -5
  591. package/dist/Identifiers.mjs +0 -10
  592. package/dist/Identifiers.mjs.map +0 -1
  593. package/dist/Mcp.d.mts +0 -5
  594. package/dist/Mcp.mjs +0 -10
  595. package/dist/Mcp.mjs.map +0 -1
  596. package/dist/McpClient.d.mts +0 -5
  597. package/dist/McpClient.mjs +0 -10
  598. package/dist/McpClient.mjs.map +0 -1
  599. package/dist/Memory.d.mts +0 -5
  600. package/dist/Memory.mjs +0 -10
  601. package/dist/Memory.mjs.map +0 -1
  602. package/dist/MemoryNamespace.d.mts +0 -5
  603. package/dist/MemoryNamespace.mjs +0 -10
  604. package/dist/MemoryNamespace.mjs.map +0 -1
  605. package/dist/MemoryNotes.d.mts +0 -5
  606. package/dist/MemoryNotes.mjs +0 -10
  607. package/dist/MemoryNotes.mjs.map +0 -1
  608. package/dist/MemoryReference.d.mts +0 -5
  609. package/dist/MemoryReference.mjs +0 -10
  610. package/dist/MemoryReference.mjs.map +0 -1
  611. package/dist/MemoryRevalidation.d.mts +0 -5
  612. package/dist/MemoryRevalidation.mjs +0 -10
  613. package/dist/MemoryRevalidation.mjs.map +0 -1
  614. package/dist/MemoryStore.d.mts +0 -5
  615. package/dist/MemoryStore.mjs +0 -10
  616. package/dist/MemoryStore.mjs.map +0 -1
  617. package/dist/Messaging.d.mts +0 -5
  618. package/dist/Messaging.mjs +0 -10
  619. package/dist/Messaging.mjs.map +0 -1
  620. package/dist/MessagingHost.d.mts +0 -5
  621. package/dist/MessagingHost.mjs +0 -10
  622. package/dist/MessagingHost.mjs.map +0 -1
  623. package/dist/ModelContext.d.mts +0 -5
  624. package/dist/ModelContext.mjs +0 -10
  625. package/dist/ModelContext.mjs.map +0 -1
  626. package/dist/Receipt.d.mts +0 -5
  627. package/dist/Receipt.mjs +0 -10
  628. package/dist/Receipt.mjs.map +0 -1
  629. package/dist/Redaction.d.mts +0 -5
  630. package/dist/Redaction.mjs +0 -10
  631. package/dist/Redaction.mjs.map +0 -1
  632. package/dist/Remembering.d.mts +0 -5
  633. package/dist/Remembering.mjs +0 -10
  634. package/dist/Remembering.mjs.map +0 -1
  635. package/dist/RememberingStore.d.mts +0 -5
  636. package/dist/RememberingStore.mjs +0 -10
  637. package/dist/RememberingStore.mjs.map +0 -1
  638. package/dist/RunEvent.d.mts +0 -5
  639. package/dist/RunEvent.mjs +0 -10
  640. package/dist/RunEvent.mjs.map +0 -1
  641. package/dist/RunEventSink.d.mts +0 -5
  642. package/dist/RunEventSink.mjs +0 -10
  643. package/dist/RunEventSink.mjs.map +0 -1
  644. package/dist/RunHooks.d.mts +0 -5
  645. package/dist/RunHooks.mjs +0 -10
  646. package/dist/RunHooks.mjs.map +0 -1
  647. package/dist/RunOptions.d.mts +0 -5
  648. package/dist/RunOptions.mjs +0 -10
  649. package/dist/RunOptions.mjs.map +0 -1
  650. package/dist/RunPolicyUsage.d.mts +0 -5
  651. package/dist/RunPolicyUsage.mjs +0 -10
  652. package/dist/RunPolicyUsage.mjs.map +0 -1
  653. package/dist/SemanticMemory.d.mts +0 -5
  654. package/dist/SemanticMemory.mjs +0 -10
  655. package/dist/SemanticMemory.mjs.map +0 -1
  656. package/dist/SemanticMemoryIndex.d.mts +0 -5
  657. package/dist/SemanticMemoryIndex.mjs +0 -10
  658. package/dist/SemanticMemoryIndex.mjs.map +0 -1
  659. package/dist/SemanticMemoryRevalidation.d.mts +0 -5
  660. package/dist/SemanticMemoryRevalidation.mjs +0 -10
  661. package/dist/SemanticMemoryRevalidation.mjs.map +0 -1
  662. package/dist/Subagent.d.mts +0 -5
  663. package/dist/Subagent.mjs +0 -10
  664. package/dist/Subagent.mjs.map +0 -1
  665. package/dist/SubagentContract.d.mts +0 -5
  666. package/dist/SubagentContract.mjs +0 -10
  667. package/dist/SubagentContract.mjs.map +0 -1
  668. package/dist/SubagentHost.d.mts +0 -5
  669. package/dist/SubagentHost.mjs +0 -10
  670. package/dist/SubagentHost.mjs.map +0 -1
  671. package/dist/SubagentReservations.d.mts +0 -5
  672. package/dist/SubagentReservations.mjs +0 -10
  673. package/dist/SubagentReservations.mjs.map +0 -1
  674. package/dist/ThreadHistory.d.mts +0 -5
  675. package/dist/ThreadHistory.mjs +0 -10
  676. package/dist/ThreadHistory.mjs.map +0 -1
  677. package/dist/ToolBroker.d.mts +0 -5
  678. package/dist/ToolBroker.mjs +0 -10
  679. package/dist/ToolBroker.mjs.map +0 -1
  680. package/dist/ToolDiscovery.d.mts +0 -5
  681. package/dist/ToolDiscovery.mjs +0 -10
  682. package/dist/ToolDiscovery.mjs.map +0 -1
  683. package/dist/ToolResult.d.mts +0 -5
  684. package/dist/ToolResult.mjs +0 -10
  685. package/dist/ToolResult.mjs.map +0 -1
  686. package/dist/Usage.d.mts +0 -5
  687. package/dist/Usage.mjs +0 -10
  688. package/dist/Usage.mjs.map +0 -1
  689. package/dist/WebCapture.d.mts +0 -5
  690. package/dist/WebCapture.mjs +0 -10
  691. package/dist/WebCapture.mjs.map +0 -1
  692. package/dist/WebSearch.d.mts +0 -5
  693. package/dist/WebSearch.mjs +0 -10
  694. package/dist/WebSearch.mjs.map +0 -1
  695. package/dist/Worker.d.mts +0 -5
  696. package/dist/Worker.mjs +0 -10
  697. package/dist/Worker.mjs.map +0 -1
  698. package/dist/rolldown-runtime-BBjsoOtd.mjs +0 -27
  699. package/src/Agent.ts +0 -1
  700. package/src/AgentError.ts +0 -1
  701. package/src/AgentPolicy.ts +0 -1
  702. package/src/AgentRuntime.ts +0 -1
  703. package/src/AgentUpdates.ts +0 -1
  704. package/src/Approval.ts +0 -1
  705. package/src/Budget.ts +0 -1
  706. package/src/CodeMode.ts +0 -1
  707. package/src/Commands.ts +0 -1
  708. package/src/Compaction.ts +0 -1
  709. package/src/ContextCompactor.ts +0 -1
  710. package/src/ContextHistory.ts +0 -1
  711. package/src/ContextTools.ts +0 -1
  712. package/src/ContextWindow.ts +0 -1
  713. package/src/DurableStep.ts +0 -1
  714. package/src/EphemeralThreads.ts +0 -1
  715. package/src/IdGenerator.ts +0 -1
  716. package/src/Identifiers.ts +0 -1
  717. package/src/Mcp.ts +0 -1
  718. package/src/McpClient.ts +0 -1
  719. package/src/Memory.ts +0 -1
  720. package/src/MemoryNamespace.ts +0 -1
  721. package/src/MemoryNotes.ts +0 -1
  722. package/src/MemoryReference.ts +0 -1
  723. package/src/MemoryRevalidation.ts +0 -1
  724. package/src/MemoryStore.ts +0 -1
  725. package/src/Messaging.ts +0 -1
  726. package/src/MessagingHost.ts +0 -1
  727. package/src/ModelContext.ts +0 -1
  728. package/src/Receipt.ts +0 -1
  729. package/src/Redaction.ts +0 -1
  730. package/src/Remembering.ts +0 -1
  731. package/src/RememberingStore.ts +0 -1
  732. package/src/RunEvent.ts +0 -1
  733. package/src/RunEventSink.ts +0 -1
  734. package/src/RunHooks.ts +0 -1
  735. package/src/RunOptions.ts +0 -1
  736. package/src/RunPolicyUsage.ts +0 -1
  737. package/src/SemanticMemory.ts +0 -1
  738. package/src/SemanticMemoryIndex.ts +0 -1
  739. package/src/SemanticMemoryRevalidation.ts +0 -1
  740. package/src/Subagent.ts +0 -1
  741. package/src/SubagentContract.ts +0 -1
  742. package/src/SubagentHost.ts +0 -1
  743. package/src/SubagentReservations.ts +0 -1
  744. package/src/ThreadHistory.ts +0 -1
  745. package/src/ToolBroker.ts +0 -1
  746. package/src/ToolDiscovery.ts +0 -1
  747. package/src/ToolResult.ts +0 -1
  748. package/src/Usage.ts +0 -1
  749. package/src/WebCapture.ts +0 -1
  750. package/src/WebSearch.ts +0 -1
  751. package/src/Worker.ts +0 -1
@@ -0,0 +1,1018 @@
1
+ import { Effect, Schema } from "effect";
2
+
3
+ import { ThreadId, SettlementId, SubmissionId, ToolCallId } from "../core/Identifiers.ts";
4
+ import { SettlementOutcome, ToolCallPrepared } from "./Records.ts";
5
+ import {
6
+ ChildReservationId,
7
+ submissionSettlementId,
8
+ WaitingChild,
9
+ type ChildAttachmentSnapshot,
10
+ type ChildBudgetReservationSnapshot,
11
+ type RecoverySnapshot,
12
+ } from "./SubmissionLedger.ts";
13
+
14
+ /** One canonical `ToolCallPrepared` without a settling or resolving canonical record (DUR-009). */
15
+ export class OpenToolCallEvidence extends Schema.Class<OpenToolCallEvidence>(
16
+ "@effect-agent/thread/OpenToolCallEvidence",
17
+ )({
18
+ toolCallId: ToolCallId,
19
+ toolName: ToolCallPrepared.fields.toolName,
20
+ turn: ToolCallPrepared.fields.turn,
21
+ }) {}
22
+
23
+ /**
24
+ * A committed tool-declaring response with ZERO prepared and ZERO settled records for its Turn:
25
+ * the provably-safe durability §15 window — no prepared records means no handler ran, so the
26
+ * declared batch resumes without model re-invocation and without Unknown.
27
+ */
28
+ export class DeclaredPendingBatchEvidence extends Schema.Class<DeclaredPendingBatchEvidence>(
29
+ "@effect-agent/thread/DeclaredPendingBatchEvidence",
30
+ )({
31
+ turn: ToolCallPrepared.fields.turn,
32
+ callCount: Schema.Int.check(Schema.isGreaterThan(0)),
33
+ }) {}
34
+
35
+ /** One canonical `ToolApprovalRequested` without a canonical `ToolApprovalDecided`. */
36
+ export class PendingApprovalEvidence extends Schema.Class<PendingApprovalEvidence>(
37
+ "@effect-agent/thread/PendingApprovalEvidence",
38
+ )({
39
+ toolCallId: ToolCallId,
40
+ turn: ToolCallPrepared.fields.turn,
41
+ }) {}
42
+
43
+ /**
44
+ * The authoritative tri-state admission answer recorded as pure classifier evidence (SUB-031):
45
+ * the recovery pass queries `resolveAdmission` with the deterministic child idempotency key for
46
+ * a requested-but-unstarted delegation call and records the result here. Absence of this field
47
+ * means the lookup was not performed — the classifier treats that exactly like `indeterminate`
48
+ * (fail-closed: only a proven `not-admitted` ever permits an admission attempt).
49
+ */
50
+ export const DelegationAdmissionEvidence = Schema.Literals([
51
+ "not-admitted",
52
+ "admitted",
53
+ "indeterminate",
54
+ ]);
55
+
56
+ export type DelegationAdmissionEvidence = typeof DelegationAdmissionEvidence.Type;
57
+
58
+ /**
59
+ * One prepared-without-outcome parent Tool Call that IS a delegation (plan §4.1), separated from
60
+ * `openToolCalls` because its establishment protocol is idempotent by construction and must
61
+ * NEVER be marked Unknown (spec §13 vs. DUR-009). Delegation detection is durable and
62
+ * fail-closed: canonical preparation records carry the definition-owned execution kind;
63
+ * child reservations and request records must agree with that classification. Names never
64
+ * authorize replay, including in the pre-reservation window. The
65
+ * `requested`/`started`/`joined` flags come from the parent-log canonical records; the child
66
+ * identity fields are present exactly when those records (or the reservation attachment) carry
67
+ * them.
68
+ */
69
+ export class OpenDelegationCallEvidence extends Schema.Class<OpenDelegationCallEvidence>(
70
+ "@effect-agent/thread/OpenDelegationCallEvidence",
71
+ )({
72
+ toolCallId: ToolCallId,
73
+ toolName: ToolCallPrepared.fields.toolName,
74
+ turn: ToolCallPrepared.fields.turn,
75
+ /** The canonical `SubagentRequested` record exists for this call. */
76
+ requested: Schema.Boolean,
77
+ /** The canonical `SubagentStarted` record exists for this call. */
78
+ started: Schema.Boolean,
79
+ /** The canonical `SubagentJoined` record exists for this call. */
80
+ joined: Schema.Boolean,
81
+ childThreadId: Schema.optionalKey(ThreadId),
82
+ childSubmissionId: Schema.optionalKey(SubmissionId),
83
+ admission: Schema.optionalKey(DelegationAdmissionEvidence),
84
+ }) {}
85
+
86
+ /**
87
+ * Canonical-log facts about one Submission, read strongly consistently alongside the ledger
88
+ * `RecoverySnapshot` (STORE-003). Canonical history wins over every ledger marker (DUR-015), so
89
+ * the classifier consults these facts before trusting ledger state — with one deliberate Phase 5
90
+ * inversion: a RECORDED terminal outcome now beats open tool calls, because a canonical
91
+ * settlement is never revisited (DUR-002/DUR-015); the P4 rule that unknown-beats-settlement is
92
+ * gone.
93
+ *
94
+ * `openToolCalls` is the DUR-009 seam: every `ToolCallPrepared` without a matching
95
+ * `ToolCallSettled` or `ToolCallResolved`. S2 separates `openDelegationCalls` from it (plan
96
+ * §4.1): a delegation's prepared-without-outcome state is provably replay-safe, so those calls
97
+ * route through the Subagent recovery rows and never through `MarkUnknown`. Names and
98
+ * operational reservation rows cannot upgrade ordinary classification. `joinedInputCovered`
99
+ * implements the plan §2.5 prompt-coverage rule for the joined side: a joined input is covered
100
+ * iff a later `ModelResponseRecorded` of the host Run exists after the `input:{sid}` record.
101
+ * `hostSettlementOutcome` is the joined-side view of the host's canonical `SubmissionSettled`
102
+ * record, present exactly when that record exists.
103
+ */
104
+ export class RecoveryEvidence extends Schema.Class<RecoveryEvidence>(
105
+ "@effect-agent/thread/RecoveryEvidence",
106
+ )({
107
+ /** The Thread exists in the ThreadStore. */
108
+ threadMaterialized: Schema.Boolean,
109
+ /** The deterministic canonical `UserInputRecorded` record (`input:{sid}`) is committed. */
110
+ inputRecorded: Schema.Boolean,
111
+ /**
112
+ * The committed canonical `SubmissionSettled` outcome (`settlement:{sid}`). Present exactly
113
+ * when the canonical settlement record exists, so the flag and the outcome cannot diverge.
114
+ */
115
+ recordedSettlementOutcome: Schema.optionalKey(SettlementOutcome),
116
+ /** The deterministic canonical `AbortRequested` record (`abort:{sid}`) is committed. */
117
+ abortRecorded: Schema.Boolean,
118
+ /** Prepared ordinary Tool Calls without a canonical settled/resolved outcome (DUR-009). */
119
+ openToolCalls: Schema.Array(OpenToolCallEvidence),
120
+ /**
121
+ * Delegation Tool Calls with an open parent-side obligation (plan §4.1), removed from
122
+ * `openToolCalls`. Wire-required; construction alone defaults it so pre-S2 evidence
123
+ * assemblers stay valid while the classifier's fail-closed detection still protects them.
124
+ */
125
+ openDelegationCalls: Schema.Array(OpenDelegationCallEvidence).pipe(
126
+ Schema.withConstructorDefault(Effect.succeed([])),
127
+ ),
128
+ /** Only persisted orchestration classification authorizes idempotent host-operation replay. */
129
+ openWorkerCalls: Schema.optionalKey(Schema.Array(OpenToolCallEvidence)),
130
+ /** A declared-but-unprepared tool batch: response canonical, zero prepared, zero settled. */
131
+ declaredPendingBatch: Schema.optionalKey(DeclaredPendingBatchEvidence),
132
+ /** Canonically requested approvals without a canonical decision. */
133
+ approvalsPending: Schema.Array(PendingApprovalEvidence),
134
+ /** Joined-side prompt coverage (plan §2.5); `true` whenever the Submission is not joined. */
135
+ joinedInputCovered: Schema.Boolean,
136
+ /** Joined-side view of the host's canonical settlement record, when it exists. */
137
+ hostSettlementOutcome: Schema.optionalKey(SettlementOutcome),
138
+ /**
139
+ * The Thread carries its canonical `SubagentLineageRecorded` record. Only
140
+ * consulted for a parent-linked Submission: a child whose lineage is not yet canonical defers
141
+ * its own materialization/readiness repair to the parent's idempotent establishment
142
+ * (`AwaitParentEstablishment`). Defaults to `false` so an assembler that does not compute it
143
+ * stays fail-closed: deferring is safe because the parent's establishment completes the child;
144
+ * running a Turn before lineage is recorded would violate the child establishment ordering.
145
+ */
146
+ subagentLineageRecorded: Schema.Boolean.pipe(
147
+ Schema.withConstructorDefault(Effect.succeed(false)),
148
+ ),
149
+ }) {}
150
+
151
+ /** Ledger admission committed but the Thread is not durable: finish materialization,
152
+ * append `ThreadCreated`, and mark readiness (crash between admit and materialize). */
153
+ export class CompleteMaterialization extends Schema.TaggedClass<CompleteMaterialization>(
154
+ "@effect-agent/thread/CompleteMaterialization",
155
+ )("CompleteMaterialization", { submissionId: SubmissionId }) {}
156
+
157
+ /** Thread durable but the readiness marker is missing: idempotent `markReady`. */
158
+ export class RepairReadiness extends Schema.TaggedClass<RepairReadiness>(
159
+ "@effect-agent/thread/RepairReadiness",
160
+ )("RepairReadiness", { submissionId: SubmissionId }) {}
161
+
162
+ /** No canonical input yet: append the deterministic `UserInputRecorded` record and mark it. */
163
+ export class ApplyInput extends Schema.TaggedClass<ApplyInput>("@effect-agent/thread/ApplyInput")(
164
+ "ApplyInput",
165
+ { submissionId: SubmissionId },
166
+ ) {}
167
+
168
+ /** Canonical input exists but the ledger marker was lost: repair the marker only (DUR-015). */
169
+ export class RepairInputMarker extends Schema.TaggedClass<RepairInputMarker>(
170
+ "@effect-agent/thread/RepairInputMarker",
171
+ )("RepairInputMarker", { submissionId: SubmissionId }) {}
172
+
173
+ /** Input applied and no terminal work reserved: a worker resumes the Run from the last committed
174
+ * Turn boundary (D6; the model may be re-invoked, duplicate cost is observable — the resuming
175
+ * worker appends `ModelResponseInterrupted` when superseding a prior owner, durability §9). */
176
+ export class ResumeFromTurnBoundary extends Schema.TaggedClass<ResumeFromTurnBoundary>(
177
+ "@effect-agent/thread/ResumeFromTurnBoundary",
178
+ )("ResumeFromTurnBoundary", { submissionId: SubmissionId }) {}
179
+
180
+ /** A settlement is reserved but not canonical: append the EXACT reserved record, then finalize. */
181
+ export class AppendReservedSettlement extends Schema.TaggedClass<AppendReservedSettlement>(
182
+ "@effect-agent/thread/AppendReservedSettlement",
183
+ )("AppendReservedSettlement", {
184
+ submissionId: SubmissionId,
185
+ settlementId: SettlementId,
186
+ outcome: SettlementOutcome,
187
+ }) {}
188
+
189
+ /** The canonical settlement record exists: rebuild/finalize the ledger from history and never
190
+ * rewrite history from the cached ledger status (DUR-011, DUR-015). */
191
+ export class FinalizeLedgerFromHistory extends Schema.TaggedClass<FinalizeLedgerFromHistory>(
192
+ "@effect-agent/thread/FinalizeLedgerFromHistory",
193
+ )("FinalizeLedgerFromHistory", {
194
+ submissionId: SubmissionId,
195
+ settlementId: SettlementId,
196
+ outcome: SettlementOutcome,
197
+ }) {}
198
+
199
+ /** A durable abort intent exists, no terminal outcome is reserved, and no attached-child
200
+ * obligation remains open: settle aborted (DUR-012). The executor first appends
201
+ * `ToolCallUnknown` audit records for any open ordinary calls — abort settles the obligation but
202
+ * never asserts external rollback (durability §13). */
203
+ export class SettleAborted extends Schema.TaggedClass<SettleAborted>(
204
+ "@effect-agent/thread/SettleAborted",
205
+ )("SettleAborted", { submissionId: SubmissionId }) {}
206
+
207
+ /** Prepared ordinary Tool Calls have no canonical outcome: the executor reconciles each open
208
+ * call (recovered result / never-started / safe-retry) and marks the remainder Unknown — never
209
+ * an automatic replay (DUR-009/DUR-017). Delegation calls are excluded: their establishment is
210
+ * idempotent by construction and routes through the Subagent rows instead (plan §4.3). */
211
+ export class MarkUnknown extends Schema.TaggedClass<MarkUnknown>(
212
+ "@effect-agent/thread/MarkUnknown",
213
+ )("MarkUnknown", {
214
+ submissionId: SubmissionId,
215
+ reason: Schema.String,
216
+ openToolCallIds: Schema.Array(ToolCallId),
217
+ }) {}
218
+
219
+ /** A committed tool-declaring response has zero prepared and zero settled records: a worker
220
+ * resumes the declared batch — no model re-invocation, no Unknown (durability §15). S2 also
221
+ * routes an open delegation call WITHOUT establishment evidence here (spec §13 row 1): the
222
+ * declared batch re-executes and the idempotent establishment converges on one child. */
223
+ export class ResumePendingToolBatch extends Schema.TaggedClass<ResumePendingToolBatch>(
224
+ "@effect-agent/thread/ResumePendingToolBatch",
225
+ )("ResumePendingToolBatch", {
226
+ submissionId: SubmissionId,
227
+ turn: DeclaredPendingBatchEvidence.fields.turn,
228
+ }) {}
229
+
230
+ /** Canonically requested approvals lack decisions: the lane waits durably (the executor repairs
231
+ * the ledger suspension from history when the suspend transition itself was lost). */
232
+ export class AwaitApprovalDecision extends Schema.TaggedClass<AwaitApprovalDecision>(
233
+ "@effect-agent/thread/AwaitApprovalDecision",
234
+ )("AwaitApprovalDecision", { submissionId: SubmissionId }) {}
235
+
236
+ /** Every pending approval has a durable decision: a worker resumes the declared batch via the
237
+ * batch-resume seam, appending the canonical `ToolApprovalDecided` records first. */
238
+ export class ResumeSuspended extends Schema.TaggedClass<ResumeSuspended>(
239
+ "@effect-agent/thread/ResumeSuspended",
240
+ )("ResumeSuspended", { submissionId: SubmissionId }) {}
241
+
242
+ /** Unknown Outcomes lack covering resolutions: the lane stays blocked awaiting the authorized
243
+ * DUR-017 resolution path; the obligation stays visible, nothing replays. */
244
+ export class AwaitUnknownResolution extends Schema.TaggedClass<AwaitUnknownResolution>(
245
+ "@effect-agent/thread/AwaitUnknownResolution",
246
+ )("AwaitUnknownResolution", { submissionId: SubmissionId }) {}
247
+
248
+ /** Durable resolution intents cover every open call: apply them canonically
249
+ * (`ToolCallResolved` + `ToolCallSettled` for recovered results) and reopen the lane. */
250
+ export class ApplyUnknownResolutions extends Schema.TaggedClass<ApplyUnknownResolutions>(
251
+ "@effect-agent/thread/ApplyUnknownResolutions",
252
+ )("ApplyUnknownResolutions", { submissionId: SubmissionId }) {}
253
+
254
+ /** `joining` without a canonical `input:{sid}` record: revert to `ready` — the input was never
255
+ * consumed and will be delivered exactly once later (DUR-016). */
256
+ export class RevertJoining extends Schema.TaggedClass<RevertJoining>(
257
+ "@effect-agent/thread/RevertJoining",
258
+ )("RevertJoining", { submissionId: SubmissionId }) {}
259
+
260
+ /** The canonical input exists but the `joined` marker was lost: repair the marker only, exactly
261
+ * like `RepairInputMarker` (DUR-015/DUR-016); the input reattaches, never duplicates. */
262
+ export class RepairJoinMarker extends Schema.TaggedClass<RepairJoinMarker>(
263
+ "@effect-agent/thread/RepairJoinMarker",
264
+ )("RepairJoinMarker", { submissionId: SubmissionId }) {}
265
+
266
+ /** The host Run settled canonically: settle this joined Submission with the host outcome
267
+ * (each joined Submission is owed its own settlement, DUR-002). */
268
+ export class SettleJoinedWithHost extends Schema.TaggedClass<SettleJoinedWithHost>(
269
+ "@effect-agent/thread/SettleJoinedWithHost",
270
+ )("SettleJoinedWithHost", {
271
+ submissionId: SubmissionId,
272
+ outcome: SettlementOutcome,
273
+ }) {}
274
+
275
+ /** The Submission is `joined` and its host Run is still live: nothing to repair — the input
276
+ * reattaches through the host's resume and the Submission settles with the host. */
277
+ export class AwaitHostSettlement extends Schema.TaggedClass<AwaitHostSettlement>(
278
+ "@effect-agent/thread/AwaitHostSettlement",
279
+ )("AwaitHostSettlement", {
280
+ submissionId: SubmissionId,
281
+ hostSubmissionId: Schema.optionalKey(SubmissionId),
282
+ }) {}
283
+
284
+ /** A canonical `SubagentRequested` exists and the authoritative admission lookup proved
285
+ * `notAdmitted`: idempotently admit the intended child from the canonical request payload — it
286
+ * carries the encoded child input (D3), the intended child identity, and every digest — then
287
+ * materialize the child Thread, append its immutable lineage, and mark it ready. No live
288
+ * delegation handler is required (spec §13, SUB-016/SUB-031). */
289
+ export class CompleteChildAdmission extends Schema.TaggedClass<CompleteChildAdmission>(
290
+ "@effect-agent/thread/CompleteChildAdmission",
291
+ )("CompleteChildAdmission", {
292
+ submissionId: SubmissionId,
293
+ toolCallId: ToolCallId,
294
+ }) {}
295
+
296
+ /** A canonical `SubagentRequested` exists but the authoritative admission lookup answered
297
+ * `indeterminate` — or was not (yet) performed: wait and retry the authoritative owner directly.
298
+ * Absence from a projection is never proof of absence and a second admission NEVER occurs
299
+ * (spec §12, SUB-031). */
300
+ export class AwaitChildAdmissionResolution extends Schema.TaggedClass<AwaitChildAdmissionResolution>(
301
+ "@effect-agent/thread/AwaitChildAdmissionResolution",
302
+ )("AwaitChildAdmissionResolution", {
303
+ submissionId: SubmissionId,
304
+ toolCallId: ToolCallId,
305
+ }) {}
306
+
307
+ /** The child Submission is admitted but the parent's `SubagentStarted` link is missing (or its
308
+ * reservation attachment was lost): resolve the SAME child by its deterministic idempotency key
309
+ * and append the exact deterministic start record, then attach the child to its reservation —
310
+ * the same Receipt on every replay (spec §13, SUB-016/SUB-017). */
311
+ export class RepairSubagentStartLink extends Schema.TaggedClass<RepairSubagentStartLink>(
312
+ "@effect-agent/thread/RepairSubagentStartLink",
313
+ )("RepairSubagentStartLink", {
314
+ submissionId: SubmissionId,
315
+ toolCallId: ToolCallId,
316
+ }) {}
317
+
318
+ /** Children are established and at least one is nonterminal while the parent lane is NOT
319
+ * durably suspended: restore the `waitingForChild` suspension so the lane holds no worker
320
+ * permit while each child runs on its own lane. Recovery reattaches the one existing child and
321
+ * NEVER spawns a replacement (spec §13, SUB-018/SUB-030). */
322
+ export class EnsureWaitingForChild extends Schema.TaggedClass<EnsureWaitingForChild>(
323
+ "@effect-agent/thread/EnsureWaitingForChild",
324
+ )("EnsureWaitingForChild", {
325
+ submissionId: SubmissionId,
326
+ children: Schema.NonEmptyArray(WaitingChild),
327
+ }) {}
328
+
329
+ /** The parent is durably suspended `WaitingForChild` and at least one listed child is not yet
330
+ * provably settled: the lane stays dormant and consumes no permit; the child's Settlement wakes
331
+ * it durably (spec §12 step 10). An unresolved ordinary Tool inside a child keeps the parent
332
+ * here honestly — the obligation stays visible and aged, nothing is fabricated (SUB-021). */
333
+ export class AwaitChildSettlement extends Schema.TaggedClass<AwaitChildSettlement>(
334
+ "@effect-agent/thread/AwaitChildSettlement",
335
+ )("AwaitChildSettlement", { submissionId: SubmissionId }) {}
336
+
337
+ /** Every relevant child is provably settled but the parent has not joined (legacy data, or a
338
+ * canonical settlement whose idempotent wake still needs replay): record/replay the durable wake
339
+ * so a claiming worker resumes the declared batch and joins each child's canonical Settlement —
340
+ * the join itself needs the parent Binding and is deferred to that worker (spec §13). */
341
+ export class ResumeWaitingParent extends Schema.TaggedClass<ResumeWaitingParent>(
342
+ "@effect-agent/thread/ResumeWaitingParent",
343
+ )("ResumeWaitingParent", {
344
+ submissionId: SubmissionId,
345
+ children: Schema.NonEmptyArray(WaitingChild),
346
+ }) {}
347
+
348
+ /** The canonical `SubagentJoined` record exists but the reservation release is incomplete:
349
+ * replay `beginChildBudgetRelease` with the accounting decision FROM the canonical record, then
350
+ * apply `releaseChildBudget` — budget stays unavailable until repair, never available twice
351
+ * (spec §12 join step 6, DUR-015). */
352
+ export class ApplyJoinAccounting extends Schema.TaggedClass<ApplyJoinAccounting>(
353
+ "@effect-agent/thread/ApplyJoinAccounting",
354
+ )("ApplyJoinAccounting", {
355
+ submissionId: SubmissionId,
356
+ toolCallId: ToolCallId,
357
+ reservationId: ChildReservationId,
358
+ }) {}
359
+
360
+ /** Parent abort is canonical while attached children are nonterminal: idempotently issue each
361
+ * child's durable abort command and keep the parent waiting for the joins —
362
+ * request-abort-and-join is the ONLY close behavior; the replayed command returns the recorded
363
+ * child intent unchanged, so the intent row IS the propagation marker (spec §13.1, SUB-022,
364
+ * DUR-012). */
365
+ export class PropagateChildAbort extends Schema.TaggedClass<PropagateChildAbort>(
366
+ "@effect-agent/thread/PropagateChildAbort",
367
+ )("PropagateChildAbort", {
368
+ submissionId: SubmissionId,
369
+ children: Schema.NonEmptyArray(WaitingChild),
370
+ }) {}
371
+
372
+ /** A child budget reservation can no longer bind a child — its request is absent with no
373
+ * resumable batch, or the parent is aborting and the child provably never admitted: freeze the
374
+ * deterministic zero-consumed accounting decision and release the unused allocation exactly
375
+ * once (spec §13/§14: "releases the reservation exactly once"). */
376
+ export class ReleaseOrphanChildReservation extends Schema.TaggedClass<ReleaseOrphanChildReservation>(
377
+ "@effect-agent/thread/ReleaseOrphanChildReservation",
378
+ )("ReleaseOrphanChildReservation", {
379
+ submissionId: SubmissionId,
380
+ reservationIds: Schema.NonEmptyArray(ChildReservationId),
381
+ }) {}
382
+
383
+ /**
384
+ * A parent-linked `admitted` Submission whose Thread lacks the canonical
385
+ * `SubagentLineageRecorded` record: the child lane DEFERS its own materialization/readiness
386
+ * repair — the parent's idempotent establishment (admit → materialize → lineage → ready)
387
+ * completes it, so a child never runs a Turn before its lineage record is canonical.
388
+ * This preserves the child establishment ordering. It is ordering/liveness hygiene, not a
389
+ * safety repair — the join already fails closed without lineage (SUB-019).
390
+ */
391
+ export class AwaitParentEstablishment extends Schema.TaggedClass<AwaitParentEstablishment>(
392
+ "@effect-agent/thread/AwaitParentEstablishment",
393
+ )("AwaitParentEstablishment", {
394
+ submissionId: SubmissionId,
395
+ parentSubmissionId: SubmissionId,
396
+ parentToolCallId: ToolCallId,
397
+ }) {}
398
+
399
+ /** The Submission is settled; nothing is owed. */
400
+ export class NoAction extends Schema.TaggedClass<NoAction>("@effect-agent/thread/NoAction")(
401
+ "NoAction",
402
+ { submissionId: SubmissionId },
403
+ ) {}
404
+
405
+ /** The executable recovery decision table's output alphabet (plan §Recovery classifier). */
406
+ export const RecoveryDecision = Schema.Union([
407
+ CompleteMaterialization,
408
+ RepairReadiness,
409
+ ApplyInput,
410
+ RepairInputMarker,
411
+ ResumeFromTurnBoundary,
412
+ AppendReservedSettlement,
413
+ FinalizeLedgerFromHistory,
414
+ SettleAborted,
415
+ MarkUnknown,
416
+ ResumePendingToolBatch,
417
+ AwaitApprovalDecision,
418
+ ResumeSuspended,
419
+ AwaitUnknownResolution,
420
+ ApplyUnknownResolutions,
421
+ RevertJoining,
422
+ RepairJoinMarker,
423
+ SettleJoinedWithHost,
424
+ AwaitHostSettlement,
425
+ CompleteChildAdmission,
426
+ AwaitChildAdmissionResolution,
427
+ RepairSubagentStartLink,
428
+ EnsureWaitingForChild,
429
+ AwaitChildSettlement,
430
+ ResumeWaitingParent,
431
+ ApplyJoinAccounting,
432
+ PropagateChildAbort,
433
+ ReleaseOrphanChildReservation,
434
+ AwaitParentEstablishment,
435
+ NoAction,
436
+ ]);
437
+
438
+ export type RecoveryDecision = typeof RecoveryDecision.Type;
439
+
440
+ /**
441
+ * The classifier's merged per-call view of one delegation Tool Call: canonical parent-log flags
442
+ * from the evidence, the reservation row, and the child attachment from the ledger snapshot.
443
+ */
444
+ interface DelegationCallView {
445
+ readonly toolCallId: ToolCallId;
446
+ turn: number | undefined;
447
+ /** A prepared-without-outcome record exists, so the declared batch is worker-resumable. */
448
+ open: boolean;
449
+ requested: boolean;
450
+ started: boolean;
451
+ joined: boolean;
452
+ admission: DelegationAdmissionEvidence | undefined;
453
+ childSubmissionId: SubmissionId | undefined;
454
+ reservation: ChildBudgetReservationSnapshot | undefined;
455
+ attachment: ChildAttachmentSnapshot | undefined;
456
+ }
457
+
458
+ /** The attachment proves the child's canonical Settlement exists. */
459
+ const isTerminalAttachment = (attachment: ChildAttachmentSnapshot): boolean =>
460
+ attachment.childState === "settled" || attachment.childOutcome !== undefined;
461
+
462
+ /**
463
+ * Merge every durable delegation-detection source into per-call views (plan §4.1): the
464
+ * explicitly classified `openDelegationCalls`, reservation rows and child attachments.
465
+ * Reservations may need cleanup, but never upgrade an ordinary call into a replayable delegation.
466
+ */
467
+ const delegationViewsOf = (
468
+ snapshot: RecoverySnapshot,
469
+ evidence: RecoveryEvidence,
470
+ ): Array<DelegationCallView> => {
471
+ const views = new Map<ToolCallId, DelegationCallView>();
472
+
473
+ const ensure = (toolCallId: ToolCallId): DelegationCallView => {
474
+ const existing = views.get(toolCallId);
475
+
476
+ if (existing !== undefined) return existing;
477
+
478
+ const created: DelegationCallView = {
479
+ toolCallId,
480
+ turn: undefined,
481
+ open: false,
482
+ requested: false,
483
+ started: false,
484
+ joined: false,
485
+ admission: undefined,
486
+ childSubmissionId: undefined,
487
+ reservation: undefined,
488
+ attachment: undefined,
489
+ };
490
+
491
+ views.set(toolCallId, created);
492
+
493
+ return created;
494
+ };
495
+
496
+ for (const call of evidence.openDelegationCalls) {
497
+ const view = ensure(call.toolCallId);
498
+
499
+ view.turn = call.turn;
500
+ view.open = true;
501
+ view.requested = call.requested;
502
+ view.started = call.started;
503
+ view.joined = call.joined;
504
+ view.admission = call.admission;
505
+ view.childSubmissionId = call.childSubmissionId;
506
+ }
507
+ for (const reservation of snapshot.childReservations) {
508
+ let view = views.get(reservation.parentToolCallId);
509
+
510
+ if (view === undefined) {
511
+ view = ensure(reservation.parentToolCallId);
512
+ }
513
+ view.reservation = reservation;
514
+ if (view.childSubmissionId === undefined && reservation.childSubmissionId !== undefined) {
515
+ view.childSubmissionId = reservation.childSubmissionId;
516
+ }
517
+ }
518
+ for (const attachment of snapshot.childAttachments) {
519
+ const view = ensure(attachment.toolCallId);
520
+
521
+ view.attachment = attachment;
522
+ if (view.childSubmissionId === undefined) {
523
+ view.childSubmissionId = attachment.childSubmissionId;
524
+ }
525
+ }
526
+
527
+ return [...views.values()];
528
+ };
529
+
530
+ const waitingChildOf = (view: DelegationCallView, childSubmissionId: SubmissionId): WaitingChild =>
531
+ WaitingChild.make({ toolCallId: view.toolCallId, childSubmissionId });
532
+
533
+ const nonEmpty = <A>(values: ReadonlyArray<A>): readonly [A, ...Array<A>] | undefined => {
534
+ const [first, ...rest] = values;
535
+
536
+ return first === undefined ? undefined : [first, ...rest];
537
+ };
538
+
539
+ /**
540
+ * The reservation's frozen accounting decision has not been applied: whether frozen by a
541
+ * canonical join or by an orphan zero-consumed decision, `releasePending` always finishes
542
+ * through the idempotent `releaseChildBudget` replay — never through a second freeze, whose
543
+ * divergent accounting would conflict (`ChildReservationConflict`).
544
+ */
545
+ const releasePendingReservation = (
546
+ view: DelegationCallView,
547
+ ): ChildBudgetReservationSnapshot | undefined =>
548
+ view.reservation !== undefined && view.reservation.status === "releasePending"
549
+ ? view.reservation
550
+ : undefined;
551
+
552
+ /** The reservation still holds unfrozen allocation (`reserved`). */
553
+ const reservedReservation = (
554
+ view: DelegationCallView,
555
+ ): ChildBudgetReservationSnapshot | undefined =>
556
+ view.reservation !== undefined && view.reservation.status === "reserved"
557
+ ? view.reservation
558
+ : undefined;
559
+
560
+ /**
561
+ * The spec §13 Subagent rows for a live (non-suspended) parent WITHOUT a durable abort intent,
562
+ * in most-repairing-first order. Returns `undefined` when no delegation obligation is open so
563
+ * the ordinary rows apply.
564
+ */
565
+ const classifyDelegationRepairs = (
566
+ submissionId: SubmissionId,
567
+ views: ReadonlyArray<DelegationCallView>,
568
+ ): RecoveryDecision | undefined => {
569
+ const applyJoins: Array<DelegationCallView> = [];
570
+ const completeAdmissions: Array<DelegationCallView> = [];
571
+ const repairStartLinks: Array<DelegationCallView> = [];
572
+ const awaitAdmissions: Array<DelegationCallView> = [];
573
+ const resumeBatches: Array<DelegationCallView> = [];
574
+ const waiting: Array<WaitingChild> = [];
575
+ const terminalUnjoined: Array<WaitingChild> = [];
576
+ const orphanReservations: Array<ChildBudgetReservationSnapshot> = [];
577
+
578
+ for (const view of views) {
579
+ if (view.reservation !== undefined && view.reservation.status === "released") {
580
+ // The reservation lifecycle is complete: release happens only after the canonical join
581
+ // (or a provably-childless orphan decision), so no parent-side budget or waiting
582
+ // obligation remains on this call.
583
+ continue;
584
+ }
585
+ if (releasePendingReservation(view) !== undefined) {
586
+ // Row: budget release incomplete with the accounting decision already frozen → finish
587
+ // the idempotent release; a second freeze would conflict.
588
+ applyJoins.push(view);
589
+ continue;
590
+ }
591
+ if (view.joined) {
592
+ // Row: parent join canonical, budget release incomplete → apply the canonical accounting.
593
+ if (reservedReservation(view) !== undefined) applyJoins.push(view);
594
+ continue;
595
+ }
596
+ if (view.started && view.childSubmissionId !== undefined) {
597
+ // Rows: started + child nonterminal → waiting; child terminal + join missing → wake.
598
+ const child = waitingChildOf(view, view.childSubmissionId);
599
+
600
+ if (view.attachment !== undefined && isTerminalAttachment(view.attachment)) {
601
+ terminalUnjoined.push(child);
602
+ } else {
603
+ waiting.push(child);
604
+ }
605
+ continue;
606
+ }
607
+ if (view.started || view.childSubmissionId !== undefined || view.admission === "admitted") {
608
+ // Row: child admitted, parent start record missing (or the start/attachment link is
609
+ // incomplete) → resolve the same child by key and append the exact link.
610
+ repairStartLinks.push(view);
611
+ continue;
612
+ }
613
+ if (view.requested) {
614
+ // Rows: requested + notAdmitted → admit exactly one child; indeterminate (or unqueried,
615
+ // fail-closed) → wait/retry the authoritative owner, never a second admission.
616
+ if (view.admission === "not-admitted") completeAdmissions.push(view);
617
+ else awaitAdmissions.push(view);
618
+ continue;
619
+ }
620
+ if (view.open) {
621
+ // Row: no reservation and no request (or reservation without a request on a live parent)
622
+ // → the declared batch re-executes; establishment is idempotent by construction.
623
+ resumeBatches.push(view);
624
+ continue;
625
+ }
626
+ const reservation = reservedReservation(view);
627
+
628
+ if (reservation !== undefined) {
629
+ // Row: reservation exists, request absent, no resumable batch → release exactly once.
630
+ orphanReservations.push(reservation);
631
+ }
632
+ }
633
+
634
+ const applyJoin = applyJoins[0];
635
+
636
+ if (applyJoin?.reservation !== undefined) {
637
+ return ApplyJoinAccounting.make({
638
+ submissionId,
639
+ toolCallId: applyJoin.toolCallId,
640
+ reservationId: applyJoin.reservation.reservationId,
641
+ });
642
+ }
643
+ const completeAdmission = completeAdmissions[0];
644
+
645
+ if (completeAdmission !== undefined) {
646
+ return CompleteChildAdmission.make({ submissionId, toolCallId: completeAdmission.toolCallId });
647
+ }
648
+ const repairStartLink = repairStartLinks[0];
649
+
650
+ if (repairStartLink !== undefined) {
651
+ return RepairSubagentStartLink.make({ submissionId, toolCallId: repairStartLink.toolCallId });
652
+ }
653
+ const awaitAdmission = awaitAdmissions[0];
654
+
655
+ if (awaitAdmission !== undefined) {
656
+ return AwaitChildAdmissionResolution.make({
657
+ submissionId,
658
+ toolCallId: awaitAdmission.toolCallId,
659
+ });
660
+ }
661
+ const resumeBatch = resumeBatches[0];
662
+
663
+ if (resumeBatch?.turn !== undefined) {
664
+ return ResumePendingToolBatch.make({ submissionId, turn: resumeBatch.turn });
665
+ }
666
+ const waitingChildren = nonEmpty([...waiting, ...terminalUnjoined]);
667
+
668
+ if (waiting.length > 0 && waitingChildren !== undefined) {
669
+ return EnsureWaitingForChild.make({ submissionId, children: waitingChildren });
670
+ }
671
+ const settledChildren = nonEmpty(terminalUnjoined);
672
+
673
+ if (settledChildren !== undefined) {
674
+ return ResumeWaitingParent.make({ submissionId, children: settledChildren });
675
+ }
676
+ const orphans = nonEmpty(orphanReservations.map((reservation) => reservation.reservationId));
677
+
678
+ if (orphans !== undefined) {
679
+ return ReleaseOrphanChildReservation.make({ submissionId, reservationIds: orphans });
680
+ }
681
+
682
+ return undefined;
683
+ };
684
+
685
+ /**
686
+ * The spec §13/§13.1 Subagent rows under a canonical parent abort intent: request-abort-and-join
687
+ * is the only close behavior, so a nonterminal attached child converts `SettleAborted` into
688
+ * `PropagateChildAbort`, terminal-but-unjoined children are joined first, incomplete releases
689
+ * are applied, provably childless reservations release exactly once, and only a parent with no
690
+ * open child obligation settles aborted. Returns `undefined` for exactly that last case.
691
+ */
692
+ const classifyDelegationAbort = (
693
+ submissionId: SubmissionId,
694
+ views: ReadonlyArray<DelegationCallView>,
695
+ ): RecoveryDecision | undefined => {
696
+ const awaitAdmissions: Array<DelegationCallView> = [];
697
+ const repairStartLinks: Array<DelegationCallView> = [];
698
+ const nonterminal: Array<WaitingChild> = [];
699
+ const terminalUnjoined: Array<WaitingChild> = [];
700
+ const applyJoins: Array<DelegationCallView> = [];
701
+ const orphanReservations: Array<ChildBudgetReservationSnapshot> = [];
702
+
703
+ for (const view of views) {
704
+ if (view.reservation !== undefined && view.reservation.status === "released") {
705
+ // Fully closed (release only follows the canonical join or a provably-childless orphan
706
+ // decision): nothing left to abort, join, or release for this call.
707
+ continue;
708
+ }
709
+ if (releasePendingReservation(view) !== undefined) {
710
+ // The accounting decision is already frozen: finish the idempotent release; a second
711
+ // (zero-consumed) freeze would conflict with the frozen decision.
712
+ applyJoins.push(view);
713
+ continue;
714
+ }
715
+ if (view.joined) {
716
+ if (reservedReservation(view) !== undefined) applyJoins.push(view);
717
+ continue;
718
+ }
719
+ if (view.childSubmissionId !== undefined) {
720
+ if (!view.started) {
721
+ // The child exists but the canonical start link is missing: repair it first so the
722
+ // abort command targets a canonically linked child.
723
+ repairStartLinks.push(view);
724
+ continue;
725
+ }
726
+ const child = waitingChildOf(view, view.childSubmissionId);
727
+
728
+ if (view.attachment !== undefined && isTerminalAttachment(view.attachment)) {
729
+ terminalUnjoined.push(child);
730
+ } else {
731
+ nonterminal.push(child);
732
+ }
733
+ continue;
734
+ }
735
+ if (view.started || view.admission === "admitted") {
736
+ repairStartLinks.push(view);
737
+ continue;
738
+ }
739
+ if (view.requested) {
740
+ if (view.admission === "not-admitted") {
741
+ // Provably childless request under abort: never admit a child merely to abort it;
742
+ // release the unused reservation exactly once.
743
+ const reservation = reservedReservation(view);
744
+
745
+ if (reservation !== undefined) orphanReservations.push(reservation);
746
+ } else {
747
+ // Indeterminate or unqueried: a child may exist — never release, settle, or re-admit
748
+ // until the authoritative owner answers (SUB-031).
749
+ awaitAdmissions.push(view);
750
+ }
751
+ continue;
752
+ }
753
+ const reservation = reservedReservation(view);
754
+
755
+ if (reservation !== undefined) orphanReservations.push(reservation);
756
+ // An open delegation call with no reservation carries no child obligation: establishment
757
+ // never started, so the ordinary aborted settlement (with its unknown-audit for open
758
+ // calls) is honest.
759
+ }
760
+
761
+ const awaitAdmission = awaitAdmissions[0];
762
+
763
+ if (awaitAdmission !== undefined) {
764
+ return AwaitChildAdmissionResolution.make({
765
+ submissionId,
766
+ toolCallId: awaitAdmission.toolCallId,
767
+ });
768
+ }
769
+ const repairStartLink = repairStartLinks[0];
770
+
771
+ if (repairStartLink !== undefined) {
772
+ return RepairSubagentStartLink.make({ submissionId, toolCallId: repairStartLink.toolCallId });
773
+ }
774
+ const abortChildren = nonEmpty(nonterminal);
775
+
776
+ if (abortChildren !== undefined) {
777
+ return PropagateChildAbort.make({ submissionId, children: abortChildren });
778
+ }
779
+ const settledChildren = nonEmpty(terminalUnjoined);
780
+
781
+ if (settledChildren !== undefined) {
782
+ return ResumeWaitingParent.make({ submissionId, children: settledChildren });
783
+ }
784
+ const applyJoin = applyJoins[0];
785
+
786
+ if (applyJoin?.reservation !== undefined) {
787
+ return ApplyJoinAccounting.make({
788
+ submissionId,
789
+ toolCallId: applyJoin.toolCallId,
790
+ reservationId: applyJoin.reservation.reservationId,
791
+ });
792
+ }
793
+ const orphans = nonEmpty(orphanReservations.map((reservation) => reservation.reservationId));
794
+
795
+ if (orphans !== undefined) {
796
+ return ReleaseOrphanChildReservation.make({ submissionId, reservationIds: orphans });
797
+ }
798
+
799
+ return undefined;
800
+ };
801
+
802
+ /**
803
+ * Pure recovery classifier (durability §14, DUR-013): a finite persisted snapshot plus canonical
804
+ * evidence deterministically selects exactly one decision. Precedence, most-settled first
805
+ * (plan §4.2/§4.3 — note the deliberate P5 reorder: canonical settlement and reservation beat
806
+ * open tool calls, because a recorded terminal outcome is never revisited, DUR-002/DUR-015; and
807
+ * the three S2 edits: the abort row propagates to nonterminal attached children, delegation
808
+ * calls never mark Unknown, and the suspended row branches on the suspension reason):
809
+ *
810
+ * 1. `settled` → NoAction — terminal outcomes are never revisited (DUR-002).
811
+ * 2. canonical settlement record → FinalizeLedgerFromHistory — history beats every ledger
812
+ * marker (DUR-015), including a missing or divergent reservation AND open tool calls.
813
+ * 3. reservation → FinalizeLedgerFromHistory when finalized, else AppendReservedSettlement —
814
+ * the reserved record is the single exact outcome owed (DUR-011); it also beats a pending
815
+ * abort intent (DUR-012).
816
+ * 4. joined-side states (DUR-016): `joining` without canonical input → RevertJoining; `joining`
817
+ * with canonical input → RepairJoinMarker (marker lost); `joined` + host settled →
818
+ * SettleJoinedWithHost; `joined` + host live → AwaitHostSettlement (deferred).
819
+ * 5. abort intent → the S2 abort rows (spec §13.1 request-abort-and-join): an unproven child
820
+ * admission waits, an admitted-but-unlinked child repairs its start link, a nonterminal
821
+ * attached child gets PropagateChildAbort — the parent does NOT settle — terminal children
822
+ * are joined, incomplete releases applied, provably childless reservations released; ONLY a
823
+ * parent with no open child obligation reaches SettleAborted, where open ordinary calls
824
+ * become `ToolCallUnknown` audit records, never a rollback claim (§13). SettleAborted is
825
+ * position-blind by design (P7 §7(c)): an aborted, never-claimed `ready` Submission earns it
826
+ * ANYWHERE in the queue — the executor settles it immediately without waiting for it to head
827
+ * the lane, because settlement order of never-run work is not execution order (DUR-004
828
+ * bounds execution order; DUR-012 permits settling inactive accepted work without an
829
+ * Attempt).
830
+ * 6. ordinary open tool calls (state not yet `unknown`) → MarkUnknown — reconcile-then-mark,
831
+ * never an automatic replay (DUR-009). Delegation calls are EXCLUDED (plan §4.3's most
832
+ * important edit): their prepared-without-outcome state is provably replay-safe and routes
833
+ * through rows 5/8/9 instead. A lane already `unknown` is in the DUR-017 resolution regime
834
+ * (row 7) and is not re-marked.
835
+ * 7. state `unknown` → ApplyUnknownResolutions when durable intents cover every open ordinary
836
+ * call, else AwaitUnknownResolution.
837
+ * 8. state `suspended` branches on the stored reason: `WaitingForChild` → ResumeWaitingParent
838
+ * when every listed child is provably settled (replay the idempotent wake), else
839
+ * AwaitChildSettlement (SUB-030); `ApprovalPending` keeps the P5 behavior — undecided
840
+ * canonical approval requests → AwaitApprovalDecision (repairing a lost suspend transition
841
+ * from history), every request decided → ResumeSuspended.
842
+ * 9. the S2 establishment/join rows for a live parent (spec §13, most-repairing first):
843
+ * ApplyJoinAccounting → CompleteChildAdmission → RepairSubagentStartLink →
844
+ * AwaitChildAdmissionResolution → ResumePendingToolBatch (idempotent handler re-entry) →
845
+ * EnsureWaitingForChild → ResumeWaitingParent → ReleaseOrphanChildReservation.
846
+ * 10. declared-but-unprepared tool batch → ResumePendingToolBatch — no handler ran (no prepared
847
+ * records), so the batch resumes with no model re-invocation and no Unknown (§15).
848
+ * 11. `admitted` → a parent-linked Submission whose Thread lacks the canonical lineage
849
+ * record defers (AwaitParentEstablishment: the parent's idempotent establishment
850
+ * completes it); otherwise
851
+ * CompleteMaterialization / RepairReadiness by Thread durability.
852
+ * 12. otherwise → ApplyInput / RepairInputMarker / ResumeFromTurnBoundary by canonical input
853
+ * evidence, with the ledger marker repaired from history, never the reverse.
854
+ *
855
+ * A CHILD Submission (one whose snapshot carries `parentLinkage`) classifies through exactly
856
+ * the same rows as any Submission — child recovery proceeds under its own ownership token and
857
+ * epoch (spec §13, SUB-020); nothing here consults the parent's lane.
858
+ *
859
+ * Ownership leases are deliberately ignored here: the executor's fenced claim is the only
860
+ * authority over liveness, and a stale Attempt is fenced by producer epoch regardless (DUR-006).
861
+ */
862
+ export const classifyRecovery = (
863
+ snapshot: RecoverySnapshot,
864
+ evidence: RecoveryEvidence,
865
+ ): RecoveryDecision => {
866
+ const submissionId = snapshot.submission.submissionId;
867
+ const state = snapshot.submission.state;
868
+
869
+ if (state === "settled") {
870
+ return NoAction.make({ submissionId });
871
+ }
872
+ if (evidence.recordedSettlementOutcome !== undefined) {
873
+ return FinalizeLedgerFromHistory.make({
874
+ submissionId,
875
+ settlementId: snapshot.reservation?.settlementId ?? submissionSettlementId(submissionId),
876
+ outcome: evidence.recordedSettlementOutcome,
877
+ });
878
+ }
879
+ if (snapshot.reservation !== undefined) {
880
+ if (snapshot.reservation.finalized) {
881
+ return FinalizeLedgerFromHistory.make({
882
+ submissionId,
883
+ settlementId: snapshot.reservation.settlementId,
884
+ outcome: snapshot.reservation.outcome,
885
+ });
886
+ }
887
+
888
+ return AppendReservedSettlement.make({
889
+ submissionId,
890
+ settlementId: snapshot.reservation.settlementId,
891
+ outcome: snapshot.reservation.outcome,
892
+ });
893
+ }
894
+ if (state === "joining") {
895
+ return evidence.inputRecorded
896
+ ? RepairJoinMarker.make({ submissionId })
897
+ : RevertJoining.make({ submissionId });
898
+ }
899
+ if (state === "joined") {
900
+ if (evidence.hostSettlementOutcome !== undefined) {
901
+ return SettleJoinedWithHost.make({
902
+ submissionId,
903
+ outcome: evidence.hostSettlementOutcome,
904
+ });
905
+ }
906
+
907
+ return AwaitHostSettlement.make({
908
+ submissionId,
909
+ ...(snapshot.hostSubmissionId === undefined
910
+ ? {}
911
+ : { hostSubmissionId: snapshot.hostSubmissionId }),
912
+ });
913
+ }
914
+ const delegationViews = delegationViewsOf(snapshot, evidence);
915
+
916
+ if (snapshot.abortIntent !== undefined) {
917
+ return (
918
+ classifyDelegationAbort(submissionId, delegationViews) ?? SettleAborted.make({ submissionId })
919
+ );
920
+ }
921
+
922
+ const delegationCallIds = new Set<string>(
923
+ evidence.openDelegationCalls.map((call) => call.toolCallId),
924
+ );
925
+
926
+ const ordinaryOpenCalls = evidence.openToolCalls.filter(
927
+ (call) => !delegationCallIds.has(call.toolCallId),
928
+ );
929
+
930
+ if (state !== "unknown" && ordinaryOpenCalls.length > 0) {
931
+ return MarkUnknown.make({
932
+ submissionId,
933
+ reason: "An ordinary Tool call may have executed without a canonical outcome",
934
+ openToolCallIds: ordinaryOpenCalls.map((call) => call.toolCallId),
935
+ });
936
+ }
937
+ if (state === "unknown") {
938
+ const resolved = new Set(
939
+ snapshot.unknownResolutions.map((resolution) => resolution.toolCallId),
940
+ );
941
+
942
+ const covered = ordinaryOpenCalls.every((call) => resolved.has(call.toolCallId));
943
+
944
+ return covered
945
+ ? ApplyUnknownResolutions.make({ submissionId })
946
+ : AwaitUnknownResolution.make({ submissionId });
947
+ }
948
+ const decided = new Set(snapshot.approvalDecisions.map((decision) => decision.toolCallId));
949
+
950
+ const undecidedApprovals = evidence.approvalsPending.filter(
951
+ (pending) => !decided.has(pending.toolCallId),
952
+ );
953
+
954
+ if (state === "suspended") {
955
+ const reason = snapshot.suspension?.reason;
956
+
957
+ if (reason !== undefined && reason._tag === "WaitingForChild") {
958
+ const terminalChildIds = new Set(
959
+ snapshot.childAttachments
960
+ .filter(isTerminalAttachment)
961
+ .map((attachment) => attachment.childSubmissionId),
962
+ );
963
+
964
+ return reason.children.every((child) => terminalChildIds.has(child.childSubmissionId))
965
+ ? ResumeWaitingParent.make({ submissionId, children: reason.children })
966
+ : AwaitChildSettlement.make({ submissionId });
967
+ }
968
+
969
+ return undecidedApprovals.length === 0
970
+ ? ResumeSuspended.make({ submissionId })
971
+ : AwaitApprovalDecision.make({ submissionId });
972
+ }
973
+ if (undecidedApprovals.length > 0) {
974
+ return AwaitApprovalDecision.make({ submissionId });
975
+ }
976
+ const delegationDecision = classifyDelegationRepairs(submissionId, delegationViews);
977
+
978
+ if (delegationDecision !== undefined) {
979
+ return delegationDecision;
980
+ }
981
+ if (evidence.declaredPendingBatch !== undefined) {
982
+ return ResumePendingToolBatch.make({
983
+ submissionId,
984
+ turn: evidence.declaredPendingBatch.turn,
985
+ });
986
+ }
987
+ const workerCall = evidence.openWorkerCalls?.[0];
988
+
989
+ if (workerCall !== undefined) {
990
+ return ResumePendingToolBatch.make({ submissionId, turn: workerCall.turn });
991
+ }
992
+ if (state === "admitted") {
993
+ // A parent-linked child never self-repairs readiness before its immutable
994
+ // lineage record is canonical — the parent's establishment appends lineage BEFORE
995
+ // markReady, so the parent completes the child idempotently.
996
+ const linkage = snapshot.submission.parentLinkage ?? snapshot.parentLinkage;
997
+
998
+ if (linkage !== undefined && !evidence.subagentLineageRecorded) {
999
+ return AwaitParentEstablishment.make({
1000
+ submissionId,
1001
+ parentSubmissionId: linkage.parentSubmissionId,
1002
+ parentToolCallId: linkage.parentToolCallId,
1003
+ });
1004
+ }
1005
+
1006
+ return evidence.threadMaterialized
1007
+ ? RepairReadiness.make({ submissionId })
1008
+ : CompleteMaterialization.make({ submissionId });
1009
+ }
1010
+ if (!evidence.inputRecorded) {
1011
+ return ApplyInput.make({ submissionId });
1012
+ }
1013
+ if (snapshot.inputApplied === undefined) {
1014
+ return RepairInputMarker.make({ submissionId });
1015
+ }
1016
+
1017
+ return ResumeFromTurnBoundary.make({ submissionId });
1018
+ };