@systemfsoftware/agent 0.0.0-stage → 0.1.0-beta.192

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 (717) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ActivityStore-CEy3oY41.mjs +90 -0
  3. package/dist/ActivityStore-CEy3oY41.mjs.map +1 -0
  4. package/dist/ActivityStore-CPXWRHGz.d.mts +91 -0
  5. package/dist/Admin-BcQDrWKY.mjs +329 -0
  6. package/dist/Admin-BcQDrWKY.mjs.map +1 -0
  7. package/dist/Admin-BfolLkHj.d.mts +5678 -0
  8. package/dist/Agent-Bn3zMhDH.mjs +60 -0
  9. package/dist/Agent-Bn3zMhDH.mjs.map +1 -0
  10. package/dist/Agent-DSVEpq4e.d.mts +219 -0
  11. package/dist/AgentError-RkUaetX8.d.mts +128 -0
  12. package/dist/AgentError-yFdnS9bl.mjs +141 -0
  13. package/dist/AgentError-yFdnS9bl.mjs.map +1 -0
  14. package/dist/AgentPolicy-CI7LRBQa.mjs +116 -0
  15. package/dist/AgentPolicy-CI7LRBQa.mjs.map +1 -0
  16. package/dist/AgentPolicy-D-GmZQex.d.mts +128 -0
  17. package/dist/AgentRegistration-Dg53p6du.mjs +14 -0
  18. package/dist/AgentRegistration-Dg53p6du.mjs.map +1 -0
  19. package/dist/AgentRuntime-CoGy_5dm.d.mts +751 -0
  20. package/dist/AgentRuntime-CzP4I4RB.mjs +5249 -0
  21. package/dist/AgentRuntime-CzP4I4RB.mjs.map +1 -0
  22. package/dist/AgentUpdates-7xT0It_R.d.mts +54 -0
  23. package/dist/AgentUpdates-BS_6gR5K.mjs +66 -0
  24. package/dist/AgentUpdates-BS_6gR5K.mjs.map +1 -0
  25. package/dist/BrowserUse-C9vict2M.d.mts +196 -0
  26. package/dist/BrowserUse-DjEyFDLZ.mjs +156 -0
  27. package/dist/BrowserUse-DjEyFDLZ.mjs.map +1 -0
  28. package/dist/Budget-CXh_ChFJ.d.mts +112 -0
  29. package/dist/Budget-j1UkthgY.mjs +351 -0
  30. package/dist/Budget-j1UkthgY.mjs.map +1 -0
  31. package/dist/CodeExecutor-B_Vt1Ghy.mjs +281 -0
  32. package/dist/CodeExecutor-B_Vt1Ghy.mjs.map +1 -0
  33. package/dist/CodeExecutor-D5-Rda75.d.mts +198 -0
  34. package/dist/CodeMode-B7JvfKAD.d.mts +159 -0
  35. package/dist/CodeMode-BI7WhUkr.mjs +555 -0
  36. package/dist/CodeMode-BI7WhUkr.mjs.map +1 -0
  37. package/dist/CommittedActivity-DXyCKCtX.mjs +146 -0
  38. package/dist/CommittedActivity-DXyCKCtX.mjs.map +1 -0
  39. package/dist/CommittedActivity-LWOKXqdi.d.mts +62 -0
  40. package/dist/Compaction-C0hWAmOG.mjs +15 -0
  41. package/dist/Compaction-C0hWAmOG.mjs.map +1 -0
  42. package/dist/Compaction-e5cNeFmY.d.mts +5 -0
  43. package/dist/ContextCompactor-Chm9BLrD.d.mts +165 -0
  44. package/dist/ContextCompactor-DV4NOQvg.mjs +134 -0
  45. package/dist/ContextCompactor-DV4NOQvg.mjs.map +1 -0
  46. package/dist/ContextHistory-C80rW5M7.mjs +76 -0
  47. package/dist/ContextHistory-C80rW5M7.mjs.map +1 -0
  48. package/dist/ContextHistory-akQ1Td7a.d.mts +65 -0
  49. package/dist/ContextTools-917r7gpv.d.mts +186 -0
  50. package/dist/ContextTools-p8JDPo-W.mjs +88 -0
  51. package/dist/ContextTools-p8JDPo-W.mjs.map +1 -0
  52. package/dist/ContextWindow-BJZI4MMt.d.mts +61 -0
  53. package/dist/ContextWindow-kbFcs1IF.mjs +63 -0
  54. package/dist/ContextWindow-kbFcs1IF.mjs.map +1 -0
  55. package/dist/Digest-BDToAbaX.d.mts +25 -0
  56. package/dist/Digest-CU6IWj-2.mjs +106 -0
  57. package/dist/Digest-CU6IWj-2.mjs.map +1 -0
  58. package/dist/DurableAgentRuntime-BHXo8GPJ.mjs +8432 -0
  59. package/dist/DurableAgentRuntime-BHXo8GPJ.mjs.map +1 -0
  60. package/dist/DurableFailpoint-BD5nowNl.mjs +98 -0
  61. package/dist/DurableFailpoint-BD5nowNl.mjs.map +1 -0
  62. package/dist/DurableFailpoint-Cqi5tyof.d.mts +42 -0
  63. package/dist/DurableStep-CzVIho7y.mjs +54 -0
  64. package/dist/DurableStep-CzVIho7y.mjs.map +1 -0
  65. package/dist/DurableStep-cI_Ho_rU.d.mts +109 -0
  66. package/dist/EventSource-BwZVkEQi.mjs +66 -0
  67. package/dist/EventSource-BwZVkEQi.mjs.map +1 -0
  68. package/dist/EventSource-C0TCBeIf.d.mts +52 -0
  69. package/dist/FailureDiagnostic-DdHV2eFs.mjs +304 -0
  70. package/dist/FailureDiagnostic-DdHV2eFs.mjs.map +1 -0
  71. package/dist/FailureDiagnostic-DpzYNI8f.d.mts +232 -0
  72. package/dist/IdGenerator-BCzwV0ZI.mjs +29 -0
  73. package/dist/IdGenerator-BCzwV0ZI.mjs.map +1 -0
  74. package/dist/IdGenerator-BY8NH74o.d.mts +26 -0
  75. package/dist/Identifiers-LWd4837I.mjs +41 -0
  76. package/dist/Identifiers-LWd4837I.mjs.map +1 -0
  77. package/dist/Identifiers-qafW4EP0.d.mts +38 -0
  78. package/dist/InMemory-BrTm6XEO.mjs +57 -0
  79. package/dist/InMemory-BrTm6XEO.mjs.map +1 -0
  80. package/dist/InMemory-C3qXFT5k.d.mts +46 -0
  81. package/dist/InMemory.d.mts +2 -0
  82. package/dist/InMemory.mjs +1 -0
  83. package/dist/InteractiveBrowser-B-hlNJy5.mjs +237 -0
  84. package/dist/InteractiveBrowser-B-hlNJy5.mjs.map +1 -0
  85. package/dist/InteractiveBrowser-nnML0r7w.d.mts +258 -0
  86. package/dist/LifecyclePublication-BDc_ug5v.mjs +204 -0
  87. package/dist/LifecyclePublication-BDc_ug5v.mjs.map +1 -0
  88. package/dist/Memory-CT5bDZqi.d.mts +57 -0
  89. package/dist/Memory-Dl9ecPpm.mjs +204 -0
  90. package/dist/Memory-Dl9ecPpm.mjs.map +1 -0
  91. package/dist/MemoryNamespace-BtnlH_E6.d.mts +35 -0
  92. package/dist/MemoryNamespace-DZSpjLj9.mjs +116 -0
  93. package/dist/MemoryNamespace-DZSpjLj9.mjs.map +1 -0
  94. package/dist/MemoryNotes-4CRzkPBD.d.mts +425 -0
  95. package/dist/MemoryNotes-i41TsH11.mjs +132 -0
  96. package/dist/MemoryNotes-i41TsH11.mjs.map +1 -0
  97. package/dist/MemoryReference-Dd3KSMa7.d.mts +77 -0
  98. package/dist/MemoryReference-RFU0HQJG.mjs +108 -0
  99. package/dist/MemoryReference-RFU0HQJG.mjs.map +1 -0
  100. package/dist/MemoryRevalidation--aAh_Pfq.mjs +136 -0
  101. package/dist/MemoryRevalidation--aAh_Pfq.mjs.map +1 -0
  102. package/dist/MemoryRevalidation-FsJ8E61W.d.mts +64 -0
  103. package/dist/MemoryStore-Bg5RunTk.d.mts +187 -0
  104. package/dist/MemoryStore-E0J99hb2.mjs +245 -0
  105. package/dist/MemoryStore-E0J99hb2.mjs.map +1 -0
  106. package/dist/MessageDelivery-BE2Yf3FC.mjs +615 -0
  107. package/dist/MessageDelivery-BE2Yf3FC.mjs.map +1 -0
  108. package/dist/MessageDelivery-Dh6GZBt_.d.mts +1129 -0
  109. package/dist/Messaging-BqWHYf93.d.mts +216 -0
  110. package/dist/Messaging-DgSiv4f4.mjs +154 -0
  111. package/dist/Messaging-DgSiv4f4.mjs.map +1 -0
  112. package/dist/Messaging-DhM-APnP.d.mts +1074 -0
  113. package/dist/MessagingHost-Bm5e-kAX.mjs +117 -0
  114. package/dist/MessagingHost-Bm5e-kAX.mjs.map +1 -0
  115. package/dist/MessagingHost-CubWeYKN.d.mts +80 -0
  116. package/dist/OperationAuthorizer-VSiHCC2S.mjs +72 -0
  117. package/dist/OperationAuthorizer-VSiHCC2S.mjs.map +1 -0
  118. package/dist/OperationAuthorizer-y-F-Ox_Q.d.mts +62 -0
  119. package/dist/Output-DQ8mWcgf.mjs +7 -0
  120. package/dist/Output-DQ8mWcgf.mjs.map +1 -0
  121. package/dist/Output-SbOdlBFL.d.mts +22 -0
  122. package/dist/PageCapture-BfRURUOA.mjs +275 -0
  123. package/dist/PageCapture-BfRURUOA.mjs.map +1 -0
  124. package/dist/PageCapture-C_mE72Sd.d.mts +216 -0
  125. package/dist/PageScreenshot-BJTASs4o.mjs +53 -0
  126. package/dist/PageScreenshot-BJTASs4o.mjs.map +1 -0
  127. package/dist/PageScreenshot-CaoaH7mc.d.mts +48 -0
  128. package/dist/PersistentHistory-BrtZ0g2j.d.mts +14 -0
  129. package/dist/PersistentHistory-CTAVhHKH.mjs +147 -0
  130. package/dist/PersistentHistory-CTAVhHKH.mjs.map +1 -0
  131. package/dist/PreparedInputAdmission-Ci18uY4s.d.mts +973 -0
  132. package/dist/PreparedInputAdmission-adqVJJa6.mjs +95 -0
  133. package/dist/PreparedInputAdmission-adqVJJa6.mjs.map +1 -0
  134. package/dist/ProvisionalText-BcKpPYKQ.d.mts +70 -0
  135. package/dist/ProvisionalText-DXddTK4c.mjs +47 -0
  136. package/dist/ProvisionalText-DXddTK4c.mjs.map +1 -0
  137. package/dist/Receipt-B-FlCaNH.mjs +35 -0
  138. package/dist/Receipt-B-FlCaNH.mjs.map +1 -0
  139. package/dist/Receipt-B4feBxMY.d.mts +31 -0
  140. package/dist/RecordFormat-DoNh-AFe.mjs +79 -0
  141. package/dist/RecordFormat-DoNh-AFe.mjs.map +1 -0
  142. package/dist/RecordFormat-ZMus8Dx8.d.mts +52 -0
  143. package/dist/Records-C645aQks.mjs +1145 -0
  144. package/dist/Records-C645aQks.mjs.map +1 -0
  145. package/dist/Records-C9I1nCL9.d.mts +1423 -0
  146. package/dist/Recovery-zWy_kmZq.mjs +736 -0
  147. package/dist/Recovery-zWy_kmZq.mjs.map +1 -0
  148. package/dist/Redaction-C0zLBAn6.d.mts +28 -0
  149. package/dist/Redaction-CtyCBMEj.mjs +116 -0
  150. package/dist/Redaction-CtyCBMEj.mjs.map +1 -0
  151. package/dist/RememberingStore-BO-OnCgP.mjs +23 -0
  152. package/dist/RememberingStore-BO-OnCgP.mjs.map +1 -0
  153. package/dist/RememberingStore-DgqXmILx.d.mts +14 -0
  154. package/dist/RunContinuation-BVAHoYlN.d.mts +127 -0
  155. package/dist/RunContinuation-Bpfp087i.mjs +1060 -0
  156. package/dist/RunContinuation-Bpfp087i.mjs.map +1 -0
  157. package/dist/RunEvent-CwgDzXcH.d.mts +465 -0
  158. package/dist/RunEvent-DJxENnJi.mjs +345 -0
  159. package/dist/RunEvent-DJxENnJi.mjs.map +1 -0
  160. package/dist/RunEventSink-B8uM8bw2.mjs +22 -0
  161. package/dist/RunEventSink-B8uM8bw2.mjs.map +1 -0
  162. package/dist/RunEventSink-f-T4jbNB.d.mts +105 -0
  163. package/dist/RunHooks-Bob22Bcj.d.mts +40 -0
  164. package/dist/RunHooks-DWuLBVdU.mjs +60 -0
  165. package/dist/RunHooks-DWuLBVdU.mjs.map +1 -0
  166. package/dist/RunJournal-C_1eqQdr.mjs +1107 -0
  167. package/dist/RunJournal-C_1eqQdr.mjs.map +1 -0
  168. package/dist/RunOptions-BVSa3BO2.d.mts +560 -0
  169. package/dist/RunOptions-COEUCrx4.mjs +61 -0
  170. package/dist/RunOptions-COEUCrx4.mjs.map +1 -0
  171. package/dist/RunPolicyUsage-B-JXRZYO.mjs +25 -0
  172. package/dist/RunPolicyUsage-B-JXRZYO.mjs.map +1 -0
  173. package/dist/RunPolicyUsage-jvJo0vJp.d.mts +21 -0
  174. package/dist/RunStorage-CsQQ0Y5u.mjs +304 -0
  175. package/dist/RunStorage-CsQQ0Y5u.mjs.map +1 -0
  176. package/dist/Sandbox-37vXP0BV.d.mts +24 -0
  177. package/dist/Sandbox-Bze6pHYc.mjs +30 -0
  178. package/dist/Sandbox-Bze6pHYc.mjs.map +1 -0
  179. package/dist/Schedule-BY0lzbij.mjs +336 -0
  180. package/dist/Schedule-BY0lzbij.mjs.map +1 -0
  181. package/dist/ScheduleTransition-CjVP48I8.d.mts +22 -0
  182. package/dist/ScheduleTransition-DtNzlN9k.mjs +180 -0
  183. package/dist/ScheduleTransition-DtNzlN9k.mjs.map +1 -0
  184. package/dist/Scheduling-BpJN9E1j.mjs +699 -0
  185. package/dist/Scheduling-BpJN9E1j.mjs.map +1 -0
  186. package/dist/Scheduling-DYTM29s9.d.mts +57 -0
  187. package/dist/SemanticMemory-BRV0cuWg.mjs +300 -0
  188. package/dist/SemanticMemory-BRV0cuWg.mjs.map +1 -0
  189. package/dist/SemanticMemory-rgWlhW87.d.mts +431 -0
  190. package/dist/SemanticMemoryIndex-D7yNEWpt.d.mts +826 -0
  191. package/dist/SemanticMemoryIndex-godQDjNx.mjs +186 -0
  192. package/dist/SemanticMemoryIndex-godQDjNx.mjs.map +1 -0
  193. package/dist/SemanticMemoryRevalidation-Bm3_pfsI.d.mts +44 -0
  194. package/dist/SemanticMemoryRevalidation-D8VV-eU6.mjs +179 -0
  195. package/dist/SemanticMemoryRevalidation-D8VV-eU6.mjs.map +1 -0
  196. package/dist/Subagent-CSIRUgUo.mjs +1315 -0
  197. package/dist/Subagent-CSIRUgUo.mjs.map +1 -0
  198. package/dist/Subagent-CXEI5YZ8.d.mts +2368 -0
  199. package/dist/SubagentContract-B7vQPueI.d.mts +176 -0
  200. package/dist/SubagentContract-C-7AxTm_.mjs +187 -0
  201. package/dist/SubagentContract-C-7AxTm_.mjs.map +1 -0
  202. package/dist/SubagentHost-BEnICu7g.mjs +70 -0
  203. package/dist/SubagentHost-BEnICu7g.mjs.map +1 -0
  204. package/dist/SubagentHost-CKhz1vbH.d.mts +167 -0
  205. package/dist/SubagentReservations-BYNAHPpm.mjs +465 -0
  206. package/dist/SubagentReservations-BYNAHPpm.mjs.map +1 -0
  207. package/dist/SubagentReservations-WrmIVzO5.d.mts +185 -0
  208. package/dist/SubmissionLedger-WG0beEyt.mjs +921 -0
  209. package/dist/SubmissionLedger-WG0beEyt.mjs.map +1 -0
  210. package/dist/SubmissionStatus-CPZsOM5a.mjs +17 -0
  211. package/dist/SubmissionStatus-CPZsOM5a.mjs.map +1 -0
  212. package/dist/Subscription-BhQbmUD-.mjs +340 -0
  213. package/dist/Subscription-BhQbmUD-.mjs.map +1 -0
  214. package/dist/Subscription-CC--_OnU.d.mts +815 -0
  215. package/dist/SubscriptionInput-BEeB0Cj8.d.mts +42 -0
  216. package/dist/SubscriptionInput-Xcd4JjEs.mjs +53 -0
  217. package/dist/SubscriptionInput-Xcd4JjEs.mjs.map +1 -0
  218. package/dist/SubscriptionTransition-CWt9UVH0.d.mts +23 -0
  219. package/dist/SubscriptionTransition-lrf733c8.mjs +154 -0
  220. package/dist/SubscriptionTransition-lrf733c8.mjs.map +1 -0
  221. package/dist/Subscriptions-4K_qu_2f.mjs +638 -0
  222. package/dist/Subscriptions-4K_qu_2f.mjs.map +1 -0
  223. package/dist/Subscriptions-BF3aSf8X.d.mts +75 -0
  224. package/dist/Thread-B8JApGHa.mjs +283 -0
  225. package/dist/Thread-B8JApGHa.mjs.map +1 -0
  226. package/dist/Thread-BnAtkJl4.d.mts +116 -0
  227. package/dist/ThreadArchiveRange-1PMdjpdJ.mjs +64 -0
  228. package/dist/ThreadArchiveRange-1PMdjpdJ.mjs.map +1 -0
  229. package/dist/ThreadContextHistory-BSStMOLX.mjs +211 -0
  230. package/dist/ThreadContextHistory-BSStMOLX.mjs.map +1 -0
  231. package/dist/ThreadContextHistory-lTZ8Ftq1.d.mts +33 -0
  232. package/dist/ThreadContextHistoryProjection-Cp7_RR6V.d.mts +59 -0
  233. package/dist/ThreadContextHistoryProjection-_8uNz-h1.mjs +149 -0
  234. package/dist/ThreadContextHistoryProjection-_8uNz-h1.mjs.map +1 -0
  235. package/dist/ThreadHistory-BkyGfv5E.d.mts +76 -0
  236. package/dist/ThreadHistory-Blt_W31N.mjs +69 -0
  237. package/dist/ThreadHistory-Blt_W31N.mjs.map +1 -0
  238. package/dist/ThreadImport-C8Tqiezd.mjs +491 -0
  239. package/dist/ThreadImport-C8Tqiezd.mjs.map +1 -0
  240. package/dist/ThreadImport-DaSmrlRi.d.mts +843 -0
  241. package/dist/ThreadInvariants-DyPhMeo-.d.mts +23 -0
  242. package/dist/ThreadInvariants-fniroLRY.mjs +154 -0
  243. package/dist/ThreadInvariants-fniroLRY.mjs.map +1 -0
  244. package/dist/ThreadProjectionMaintenance-D6fBjr1q.mjs +37 -0
  245. package/dist/ThreadProjectionMaintenance-D6fBjr1q.mjs.map +1 -0
  246. package/dist/ThreadProjectionMaintenance-DjUy7kCa.d.mts +51 -0
  247. package/dist/ThreadStore-BMUAp5Ta.mjs +937 -0
  248. package/dist/ThreadStore-BMUAp5Ta.mjs.map +1 -0
  249. package/dist/ThreadTransfer-B3NkyO_y.mjs +154 -0
  250. package/dist/ThreadTransfer-B3NkyO_y.mjs.map +1 -0
  251. package/dist/ThreadTransfer-BM02cbOo.d.mts +63 -0
  252. package/dist/ThreadWork-C-xa2Boi.mjs +484 -0
  253. package/dist/ThreadWork-C-xa2Boi.mjs.map +1 -0
  254. package/dist/ToolBroker-DkoVyx6T.mjs +42 -0
  255. package/dist/ToolBroker-DkoVyx6T.mjs.map +1 -0
  256. package/dist/ToolBroker-Dy2xM6ht.d.mts +134 -0
  257. package/dist/ToolDiscovery-DHySvLQd.mjs +211 -0
  258. package/dist/ToolDiscovery-DHySvLQd.mjs.map +1 -0
  259. package/dist/ToolDiscovery-VjamzX3q.d.mts +119 -0
  260. package/dist/ToolExposure-Cn7xETn5.d.mts +6 -0
  261. package/dist/ToolExposure-D7id9Gt5.d.mts +37 -0
  262. package/dist/ToolExposure-DCvQWFIa.mjs +9 -0
  263. package/dist/ToolExposure-DCvQWFIa.mjs.map +1 -0
  264. package/dist/ToolExposure-DNME8BkG.d.mts +44 -0
  265. package/dist/ToolExposure-DPnq8Won.mjs +30 -0
  266. package/dist/ToolExposure-DPnq8Won.mjs.map +1 -0
  267. package/dist/ToolExposure-DaGaF5tj.mjs +20 -0
  268. package/dist/ToolExposure-DaGaF5tj.mjs.map +1 -0
  269. package/dist/ToolExposure.d.mts +4 -0
  270. package/dist/ToolExposure.mjs +4 -0
  271. package/dist/ToolReconciler-6bb7xlip.d.mts +81 -0
  272. package/dist/ToolReconciler-DJQd3SZA.mjs +87 -0
  273. package/dist/ToolReconciler-DJQd3SZA.mjs.map +1 -0
  274. package/dist/ToolResult-By5KAje4.d.mts +79 -0
  275. package/dist/ToolResult-DwZxjlHw.mjs +160 -0
  276. package/dist/ToolResult-DwZxjlHw.mjs.map +1 -0
  277. package/dist/ToolResultStorage-BmoRewhh.mjs +46 -0
  278. package/dist/ToolResultStorage-BmoRewhh.mjs.map +1 -0
  279. package/dist/ToolResultStorage-Bp5fm0do.d.mts +49 -0
  280. package/dist/ToolResults-C4-HsMCp.d.mts +33 -0
  281. package/dist/ToolResults-nCgBlTp2.mjs +45 -0
  282. package/dist/ToolResults-nCgBlTp2.mjs.map +1 -0
  283. package/dist/Usage-B0xgME5f.mjs +340 -0
  284. package/dist/Usage-B0xgME5f.mjs.map +1 -0
  285. package/dist/Usage-Bc-jXe_9.d.mts +128 -0
  286. package/dist/WakeScheduler-DVYj66C-.mjs +74 -0
  287. package/dist/WakeScheduler-DVYj66C-.mjs.map +1 -0
  288. package/dist/WakeScheduler-SFqj67Sk.d.mts +74 -0
  289. package/dist/WebCapture-CA4ZarW2.mjs +64 -0
  290. package/dist/WebCapture-CA4ZarW2.mjs.map +1 -0
  291. package/dist/WebCapture-pzIeUJ5W.d.mts +49 -0
  292. package/dist/WebSearch-CD0V--qh.d.mts +18 -0
  293. package/dist/WebSearch-DnbOzRL_.mjs +30 -0
  294. package/dist/WebSearch-DnbOzRL_.mjs.map +1 -0
  295. package/dist/Worker-CQu8Qp1j.mjs +267 -0
  296. package/dist/Worker-CQu8Qp1j.mjs.map +1 -0
  297. package/dist/Worker-xxucY_0b.d.mts +468 -0
  298. package/dist/WorkerAdmission-BhFjx86s.mjs +162 -0
  299. package/dist/WorkerAdmission-BhFjx86s.mjs.map +1 -0
  300. package/dist/WorkerAdmission-BnRuXLWF.d.mts +171 -0
  301. package/dist/WorkerHost-DtYzi54D.d.mts +150 -0
  302. package/dist/WorkerHost-DuQug9Bq.mjs +73 -0
  303. package/dist/WorkerHost-DuQug9Bq.mjs.map +1 -0
  304. package/dist/agent-registration-CNs2twrr.mjs +262 -0
  305. package/dist/agent-registration-CNs2twrr.mjs.map +1 -0
  306. package/dist/capabilities/BrowserUse.d.mts +2 -0
  307. package/dist/capabilities/BrowserUse.mjs +1 -0
  308. package/dist/capabilities/Budget.d.mts +2 -0
  309. package/dist/capabilities/Budget.mjs +1 -0
  310. package/dist/capabilities/CodeMode.d.mts +2 -0
  311. package/dist/capabilities/CodeMode.mjs +1 -0
  312. package/dist/capabilities/ContextTools.d.mts +2 -0
  313. package/dist/capabilities/ContextTools.mjs +1 -0
  314. package/dist/capabilities/MemoryNotes.d.mts +2 -0
  315. package/dist/capabilities/MemoryNotes.mjs +1 -0
  316. package/dist/capabilities/Messaging.d.mts +3 -0
  317. package/dist/capabilities/Messaging.mjs +4 -0
  318. package/dist/capabilities/Redaction.d.mts +2 -0
  319. package/dist/capabilities/Redaction.mjs +1 -0
  320. package/dist/capabilities/RunHooks.d.mts +2 -0
  321. package/dist/capabilities/RunHooks.mjs +1 -0
  322. package/dist/capabilities/SemanticMemory.d.mts +2 -0
  323. package/dist/capabilities/SemanticMemory.mjs +1 -0
  324. package/dist/capabilities/Subagent.d.mts +4 -0
  325. package/dist/capabilities/Subagent.mjs +6 -0
  326. package/dist/capabilities/SubagentReservations.d.mts +2 -0
  327. package/dist/capabilities/SubagentReservations.mjs +1 -0
  328. package/dist/capabilities/ToolDiscovery.d.mts +2 -0
  329. package/dist/capabilities/ToolDiscovery.mjs +1 -0
  330. package/dist/capabilities/ToolResults.d.mts +2 -0
  331. package/dist/capabilities/ToolResults.mjs +1 -0
  332. package/dist/capabilities/WebCapture.d.mts +2 -0
  333. package/dist/capabilities/WebCapture.mjs +1 -0
  334. package/dist/capabilities/WebSearch.d.mts +2 -0
  335. package/dist/capabilities/WebSearch.mjs +1 -0
  336. package/dist/compaction-C3hXuO4Z.mjs +539 -0
  337. package/dist/compaction-C3hXuO4Z.mjs.map +1 -0
  338. package/dist/completion-B_WDnSg-.d.mts +11 -0
  339. package/dist/core/Agent.d.mts +2 -0
  340. package/dist/core/Agent.mjs +1 -0
  341. package/dist/core/AgentError.d.mts +2 -0
  342. package/dist/core/AgentError.mjs +1 -0
  343. package/dist/core/AgentPolicy.d.mts +2 -0
  344. package/dist/core/AgentPolicy.mjs +1 -0
  345. package/dist/core/AgentUpdates.d.mts +2 -0
  346. package/dist/core/AgentUpdates.mjs +1 -0
  347. package/dist/core/FailureDiagnostic.d.mts +2 -0
  348. package/dist/core/FailureDiagnostic.mjs +1 -0
  349. package/dist/core/IdGenerator.d.mts +2 -0
  350. package/dist/core/IdGenerator.mjs +1 -0
  351. package/dist/core/Identifiers.d.mts +2 -0
  352. package/dist/core/Identifiers.mjs +1 -0
  353. package/dist/core/Memory.d.mts +2 -0
  354. package/dist/core/Memory.mjs +1 -0
  355. package/dist/core/MemoryNamespace.d.mts +2 -0
  356. package/dist/core/MemoryNamespace.mjs +1 -0
  357. package/dist/core/MemoryReference.d.mts +2 -0
  358. package/dist/core/MemoryReference.mjs +1 -0
  359. package/dist/core/MemoryRevalidation.d.mts +2 -0
  360. package/dist/core/MemoryRevalidation.mjs +1 -0
  361. package/dist/core/MemoryStore.d.mts +2 -0
  362. package/dist/core/MemoryStore.mjs +1 -0
  363. package/dist/core/ProvisionalText.d.mts +2 -0
  364. package/dist/core/ProvisionalText.mjs +1 -0
  365. package/dist/core/Receipt.d.mts +2 -0
  366. package/dist/core/Receipt.mjs +1 -0
  367. package/dist/core/RememberingStore.d.mts +2 -0
  368. package/dist/core/RememberingStore.mjs +1 -0
  369. package/dist/core/RunEvent.d.mts +3 -0
  370. package/dist/core/RunEvent.mjs +1 -0
  371. package/dist/core/RunPolicyUsage.d.mts +2 -0
  372. package/dist/core/RunPolicyUsage.mjs +1 -0
  373. package/dist/core/SemanticMemoryIndex.d.mts +2 -0
  374. package/dist/core/SemanticMemoryIndex.mjs +1 -0
  375. package/dist/core/SemanticMemoryRevalidation.d.mts +2 -0
  376. package/dist/core/SemanticMemoryRevalidation.mjs +1 -0
  377. package/dist/core/SubagentContract.d.mts +2 -0
  378. package/dist/core/SubagentContract.mjs +1 -0
  379. package/dist/core/Thread.d.mts +2 -0
  380. package/dist/core/Thread.mjs +1 -0
  381. package/dist/core/ToolResult.d.mts +2 -0
  382. package/dist/core/ToolResult.mjs +1 -0
  383. package/dist/core/ToolResultStorage.d.mts +2 -0
  384. package/dist/core/ToolResultStorage.mjs +1 -0
  385. package/dist/core/Usage.d.mts +2 -0
  386. package/dist/core/Usage.mjs +1 -0
  387. package/dist/core/Worker.d.mts +3 -0
  388. package/dist/core/Worker.mjs +3 -0
  389. package/dist/durable/ActivityStore.d.mts +2 -0
  390. package/dist/durable/ActivityStore.mjs +1 -0
  391. package/dist/durable/Admin.d.mts +2 -0
  392. package/dist/durable/Admin.mjs +1 -0
  393. package/dist/durable/AgentRegistration.d.mts +3 -0
  394. package/dist/durable/AgentRegistration.mjs +2 -0
  395. package/dist/durable/CommittedActivity.d.mts +2 -0
  396. package/dist/durable/CommittedActivity.mjs +1 -0
  397. package/dist/durable/Digest.d.mts +2 -0
  398. package/dist/durable/Digest.mjs +3 -0
  399. package/dist/durable/DurableAgentRuntime.d.mts +3 -0
  400. package/dist/durable/DurableAgentRuntime.mjs +4 -0
  401. package/dist/durable/DurableFailpoint.d.mts +2 -0
  402. package/dist/durable/DurableFailpoint.mjs +1 -0
  403. package/dist/durable/DurableFailpointTestControl.d.mts +14 -0
  404. package/dist/durable/DurableFailpointTestControl.mjs +21 -0
  405. package/dist/durable/DurableFailpointTestControl.mjs.map +1 -0
  406. package/dist/durable/EventSource.d.mts +2 -0
  407. package/dist/durable/EventSource.mjs +1 -0
  408. package/dist/durable/LifecyclePublication.d.mts +2 -0
  409. package/dist/durable/LifecyclePublication.mjs +1 -0
  410. package/dist/durable/MessageDelivery.d.mts +2 -0
  411. package/dist/durable/MessageDelivery.mjs +1 -0
  412. package/dist/durable/MessageDeliveryStoreConformance.d.mts +401 -0
  413. package/dist/durable/MessageDeliveryStoreConformance.mjs +273 -0
  414. package/dist/durable/MessageDeliveryStoreConformance.mjs.map +1 -0
  415. package/dist/durable/OperationAuthorizer.d.mts +2 -0
  416. package/dist/durable/OperationAuthorizer.mjs +1 -0
  417. package/dist/durable/PersistentHistory.d.mts +2 -0
  418. package/dist/durable/PersistentHistory.mjs +1 -0
  419. package/dist/durable/PreparedInputAdmission.d.mts +2 -0
  420. package/dist/durable/PreparedInputAdmission.mjs +1 -0
  421. package/dist/durable/RecordFormat.d.mts +2 -0
  422. package/dist/durable/RecordFormat.mjs +1 -0
  423. package/dist/durable/Records.d.mts +2 -0
  424. package/dist/durable/Records.mjs +1 -0
  425. package/dist/durable/Recovery.d.mts +2 -0
  426. package/dist/durable/Recovery.mjs +1 -0
  427. package/dist/durable/RunContinuation.d.mts +4 -0
  428. package/dist/durable/RunContinuation.mjs +4 -0
  429. package/dist/durable/RunJournal.d.mts +2 -0
  430. package/dist/durable/RunJournal.mjs +1 -0
  431. package/dist/durable/RunStorage.d.mts +2 -0
  432. package/dist/durable/RunStorage.mjs +1 -0
  433. package/dist/durable/Schedule.d.mts +2 -0
  434. package/dist/durable/Schedule.mjs +1 -0
  435. package/dist/durable/ScheduleStoreConformance.d.mts +16 -0
  436. package/dist/durable/ScheduleStoreConformance.mjs +421 -0
  437. package/dist/durable/ScheduleStoreConformance.mjs.map +1 -0
  438. package/dist/durable/ScheduleTransition.d.mts +2 -0
  439. package/dist/durable/ScheduleTransition.mjs +1 -0
  440. package/dist/durable/Scheduling.d.mts +2 -0
  441. package/dist/durable/Scheduling.mjs +1 -0
  442. package/dist/durable/SettlementPublisher.d.mts +2 -0
  443. package/dist/durable/SettlementPublisher.mjs +99 -0
  444. package/dist/durable/SettlementPublisher.mjs.map +1 -0
  445. package/dist/durable/SqlMemoryStore.d.mts +729 -0
  446. package/dist/durable/SqlMemoryStore.mjs +626 -0
  447. package/dist/durable/SqlMemoryStore.mjs.map +1 -0
  448. package/dist/durable/SqlStorageOwner.d.mts +18 -0
  449. package/dist/durable/SqlStorageOwner.mjs +6 -0
  450. package/dist/durable/SqlStorageOwner.mjs.map +1 -0
  451. package/dist/durable/SubmissionLedger.d.mts +3 -0
  452. package/dist/durable/SubmissionLedger.mjs +3 -0
  453. package/dist/durable/SubmissionLedgerConformance.d.mts +31 -0
  454. package/dist/durable/SubmissionLedgerConformance.mjs +2090 -0
  455. package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -0
  456. package/dist/durable/SubmissionStatus.d.mts +2 -0
  457. package/dist/durable/SubmissionStatus.mjs +1 -0
  458. package/dist/durable/Subscription.d.mts +2 -0
  459. package/dist/durable/Subscription.mjs +1 -0
  460. package/dist/durable/SubscriptionInput.d.mts +2 -0
  461. package/dist/durable/SubscriptionInput.mjs +1 -0
  462. package/dist/durable/SubscriptionStoreConformance.d.mts +15 -0
  463. package/dist/durable/SubscriptionStoreConformance.mjs +816 -0
  464. package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -0
  465. package/dist/durable/SubscriptionTransition.d.mts +2 -0
  466. package/dist/durable/SubscriptionTransition.mjs +1 -0
  467. package/dist/durable/Subscriptions.d.mts +2 -0
  468. package/dist/durable/Subscriptions.mjs +1 -0
  469. package/dist/durable/ThreadArchiveRange.d.mts +2 -0
  470. package/dist/durable/ThreadArchiveRange.mjs +1 -0
  471. package/dist/durable/ThreadContextHistory.d.mts +2 -0
  472. package/dist/durable/ThreadContextHistory.mjs +1 -0
  473. package/dist/durable/ThreadContextHistoryProjection.d.mts +2 -0
  474. package/dist/durable/ThreadContextHistoryProjection.mjs +1 -0
  475. package/dist/durable/ThreadImport.d.mts +2 -0
  476. package/dist/durable/ThreadImport.mjs +1 -0
  477. package/dist/durable/ThreadInvariants.d.mts +2 -0
  478. package/dist/durable/ThreadInvariants.mjs +1 -0
  479. package/dist/durable/ThreadProjectionMaintenance.d.mts +2 -0
  480. package/dist/durable/ThreadProjectionMaintenance.mjs +1 -0
  481. package/dist/durable/ThreadReader.d.mts +2 -0
  482. package/dist/durable/ThreadReader.mjs +1 -0
  483. package/dist/durable/ThreadStore.d.mts +3 -0
  484. package/dist/durable/ThreadStore.mjs +3 -0
  485. package/dist/durable/ThreadStoreConformance.d.mts +53 -0
  486. package/dist/durable/ThreadStoreConformance.mjs +402 -0
  487. package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
  488. package/dist/durable/ThreadTransfer.d.mts +2 -0
  489. package/dist/durable/ThreadTransfer.mjs +1 -0
  490. package/dist/durable/ThreadWork.d.mts +2 -0
  491. package/dist/durable/ThreadWork.mjs +1 -0
  492. package/dist/durable/ToolReconciler.d.mts +2 -0
  493. package/dist/durable/ToolReconciler.mjs +1 -0
  494. package/dist/durable/WakeScheduler.d.mts +2 -0
  495. package/dist/durable/WakeScheduler.mjs +1 -0
  496. package/dist/durable/WorkerAdmission.d.mts +2 -0
  497. package/dist/durable/WorkerAdmission.mjs +1 -0
  498. package/dist/durable/WorkerHost.d.mts +2 -0
  499. package/dist/durable/WorkerHost.mjs +1 -0
  500. package/dist/engine/AgentRuntime.d.mts +2 -0
  501. package/dist/engine/AgentRuntime.mjs +1 -0
  502. package/dist/engine/Compaction.d.mts +4 -0
  503. package/dist/engine/Compaction.mjs +2 -0
  504. package/dist/engine/ContextCompactor.d.mts +2 -0
  505. package/dist/engine/ContextCompactor.mjs +1 -0
  506. package/dist/engine/ContextHistory.d.mts +2 -0
  507. package/dist/engine/ContextHistory.mjs +1 -0
  508. package/dist/engine/ContextWindow.d.mts +2 -0
  509. package/dist/engine/ContextWindow.mjs +1 -0
  510. package/dist/engine/DurableStep.d.mts +2 -0
  511. package/dist/engine/DurableStep.mjs +3 -0
  512. package/dist/engine/MessagingHost.d.mts +2 -0
  513. package/dist/engine/MessagingHost.mjs +1 -0
  514. package/dist/engine/Output.d.mts +3 -0
  515. package/dist/engine/Output.mjs +2 -0
  516. package/dist/engine/RunEventSink.d.mts +2 -0
  517. package/dist/engine/RunEventSink.mjs +1 -0
  518. package/dist/engine/RunOptions.d.mts +2 -0
  519. package/dist/engine/RunOptions.mjs +1 -0
  520. package/dist/engine/SubagentHost.d.mts +2 -0
  521. package/dist/engine/SubagentHost.mjs +1 -0
  522. package/dist/engine/ThreadHistory.d.mts +2 -0
  523. package/dist/engine/ThreadHistory.mjs +1 -0
  524. package/dist/engine/ToolBroker.d.mts +2 -0
  525. package/dist/engine/ToolBroker.mjs +1 -0
  526. package/dist/index.d.mts +90 -0
  527. package/dist/index.mjs +101 -0
  528. package/dist/output-contract-CYA4oBhe.mjs +128 -0
  529. package/dist/output-contract-CYA4oBhe.mjs.map +1 -0
  530. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  531. package/dist/run-context-reader-CHox63hg.d.mts +17 -0
  532. package/dist/sandbox/CodeExecutor.d.mts +2 -0
  533. package/dist/sandbox/CodeExecutor.mjs +1 -0
  534. package/dist/sandbox/InteractiveBrowser.d.mts +2 -0
  535. package/dist/sandbox/InteractiveBrowser.mjs +1 -0
  536. package/dist/sandbox/PageCapture.d.mts +2 -0
  537. package/dist/sandbox/PageCapture.mjs +1 -0
  538. package/dist/sandbox/PageScreenshot.d.mts +2 -0
  539. package/dist/sandbox/PageScreenshot.mjs +1 -0
  540. package/dist/sandbox/Sandbox.d.mts +2 -0
  541. package/dist/sandbox/Sandbox.mjs +1 -0
  542. package/dist/subagent-policy-xRJhrc0a.mjs +133 -0
  543. package/dist/subagent-policy-xRJhrc0a.mjs.map +1 -0
  544. package/dist/tool-execution-Cl7v8fXU.mjs +16 -0
  545. package/dist/tool-execution-Cl7v8fXU.mjs.map +1 -0
  546. package/dist/tool-operations-CauPonM8.mjs +84 -0
  547. package/dist/tool-operations-CauPonM8.mjs.map +1 -0
  548. package/dist/utf8-Bl0ZhhGe.mjs +27 -0
  549. package/dist/utf8-Bl0ZhhGe.mjs.map +1 -0
  550. package/package.json +491 -3
  551. package/src/InMemory.ts +79 -0
  552. package/src/ToolExposure.ts +2 -0
  553. package/src/capabilities/BrowserUse.ts +212 -0
  554. package/src/capabilities/Budget.ts +544 -0
  555. package/src/capabilities/CodeMode.ts +1129 -0
  556. package/src/capabilities/ContextTools.ts +131 -0
  557. package/src/capabilities/MemoryNotes.ts +177 -0
  558. package/src/capabilities/Messaging.ts +260 -0
  559. package/src/capabilities/Redaction.ts +163 -0
  560. package/src/capabilities/RunHooks.ts +116 -0
  561. package/src/capabilities/SemanticMemory.ts +402 -0
  562. package/src/capabilities/Subagent.ts +2343 -0
  563. package/src/capabilities/SubagentReservations.ts +807 -0
  564. package/src/capabilities/ToolDiscovery.ts +291 -0
  565. package/src/capabilities/ToolResults.ts +50 -0
  566. package/src/capabilities/WebCapture.ts +64 -0
  567. package/src/capabilities/WebSearch.ts +45 -0
  568. package/src/capabilities/internal/subagent-background.ts +1137 -0
  569. package/src/capabilities/internal/subagent-contract.ts +92 -0
  570. package/src/capabilities/internal/subagent-policy.ts +205 -0
  571. package/src/capabilities/internal/subagent-reporting.ts +152 -0
  572. package/src/core/Agent.ts +528 -0
  573. package/src/core/AgentError.ts +189 -0
  574. package/src/core/AgentPolicy.ts +194 -0
  575. package/src/core/AgentUpdates.ts +104 -0
  576. package/src/core/FailureDiagnostic.ts +392 -0
  577. package/src/core/IdGenerator.ts +42 -0
  578. package/src/core/Identifiers.ts +64 -0
  579. package/src/core/Memory.ts +283 -0
  580. package/src/core/MemoryNamespace.ts +202 -0
  581. package/src/core/MemoryReference.ts +120 -0
  582. package/src/core/MemoryRevalidation.ts +151 -0
  583. package/src/core/MemoryStore.ts +371 -0
  584. package/src/core/Messaging.ts +72 -0
  585. package/src/core/ProvisionalText.ts +53 -0
  586. package/src/core/Receipt.ts +42 -0
  587. package/src/core/RememberingStore.ts +22 -0
  588. package/src/core/RunEvent.ts +345 -0
  589. package/src/core/RunPolicyUsage.ts +19 -0
  590. package/src/core/SemanticMemoryIndex.ts +259 -0
  591. package/src/core/SemanticMemoryRevalidation.ts +220 -0
  592. package/src/core/SubagentContract.ts +263 -0
  593. package/src/core/Thread.ts +447 -0
  594. package/src/core/ToolExposure.ts +75 -0
  595. package/src/core/ToolResult.ts +204 -0
  596. package/src/core/ToolResultStorage.ts +56 -0
  597. package/src/core/Usage.ts +562 -0
  598. package/src/core/Worker.ts +236 -0
  599. package/src/core/internal/agent-updates.ts +42 -0
  600. package/src/core/internal/completion.ts +33 -0
  601. package/src/core/internal/json.ts +17 -0
  602. package/src/core/internal/memory-document.ts +39 -0
  603. package/src/core/internal/message-status.ts +60 -0
  604. package/src/core/internal/strict-schema.ts +14 -0
  605. package/src/core/internal/tool-execution.ts +33 -0
  606. package/src/core/internal/utf8.ts +32 -0
  607. package/src/durable/ActivityStore.ts +131 -0
  608. package/src/durable/Admin.ts +504 -0
  609. package/src/durable/AgentRegistration.ts +16 -0
  610. package/src/durable/CommittedActivity.ts +262 -0
  611. package/src/durable/Digest.ts +57 -0
  612. package/src/durable/DurableAgentRuntime.ts +12758 -0
  613. package/src/durable/DurableFailpoint.ts +108 -0
  614. package/src/durable/DurableFailpointTestControl.ts +39 -0
  615. package/src/durable/EventSource.ts +179 -0
  616. package/src/durable/LifecyclePublication.ts +343 -0
  617. package/src/durable/MessageDelivery.ts +949 -0
  618. package/src/durable/MessageDeliveryStoreConformance.ts +407 -0
  619. package/src/durable/OperationAuthorizer.ts +89 -0
  620. package/src/durable/PersistentHistory.ts +322 -0
  621. package/src/durable/PreparedInputAdmission.ts +128 -0
  622. package/src/durable/RecordFormat.ts +113 -0
  623. package/src/durable/Records.ts +1396 -0
  624. package/src/durable/Recovery.ts +1022 -0
  625. package/src/durable/RunContinuation.ts +1946 -0
  626. package/src/durable/RunJournal.ts +1926 -0
  627. package/src/durable/RunStorage.ts +533 -0
  628. package/src/durable/Schedule.ts +445 -0
  629. package/src/durable/ScheduleStoreConformance.ts +642 -0
  630. package/src/durable/ScheduleTransition.ts +267 -0
  631. package/src/durable/Scheduling.ts +1031 -0
  632. package/src/durable/SettlementPublisher.ts +172 -0
  633. package/src/durable/SqlMemoryStore.ts +1042 -0
  634. package/src/durable/SqlStorageOwner.ts +25 -0
  635. package/src/durable/SubmissionLedger.ts +1247 -0
  636. package/src/durable/SubmissionLedgerConformance.ts +4695 -0
  637. package/src/durable/SubmissionStatus.ts +14 -0
  638. package/src/durable/Subscription.ts +527 -0
  639. package/src/durable/SubscriptionInput.ts +145 -0
  640. package/src/durable/SubscriptionStoreConformance.ts +1275 -0
  641. package/src/durable/SubscriptionTransition.ts +330 -0
  642. package/src/durable/Subscriptions.ts +1245 -0
  643. package/src/durable/ThreadArchiveRange.ts +91 -0
  644. package/src/durable/ThreadContextHistory.ts +338 -0
  645. package/src/durable/ThreadContextHistoryProjection.ts +219 -0
  646. package/src/durable/ThreadImport.ts +1199 -0
  647. package/src/durable/ThreadInvariants.ts +312 -0
  648. package/src/durable/ThreadProjectionMaintenance.ts +72 -0
  649. package/src/durable/ThreadReader.ts +21 -0
  650. package/src/durable/ThreadStore.ts +1258 -0
  651. package/src/durable/ThreadStoreConformance.ts +877 -0
  652. package/src/durable/ThreadTransfer.ts +263 -0
  653. package/src/durable/ThreadWork.ts +713 -0
  654. package/src/durable/ToolReconciler.ts +112 -0
  655. package/src/durable/WakeScheduler.ts +125 -0
  656. package/src/durable/WorkerAdmission.ts +98 -0
  657. package/src/durable/WorkerHost.ts +204 -0
  658. package/src/durable/internal/StorageOwner.ts +181 -0
  659. package/src/durable/internal/agent-registration.ts +713 -0
  660. package/src/durable/internal/agent-updates.ts +338 -0
  661. package/src/durable/internal/canonical-json.ts +110 -0
  662. package/src/durable/internal/evidence.ts +29 -0
  663. package/src/durable/internal/foreign-diagnostic.ts +48 -0
  664. package/src/durable/internal/history-prompt.ts +87 -0
  665. package/src/durable/internal/initial-context.ts +215 -0
  666. package/src/durable/internal/journal-metadata.ts +188 -0
  667. package/src/durable/internal/message-status.ts +18 -0
  668. package/src/durable/internal/messaging-host.ts +615 -0
  669. package/src/durable/internal/prompt-footprint.ts +47 -0
  670. package/src/durable/internal/prompt-history-cache.ts +604 -0
  671. package/src/durable/internal/record-encoding.ts +258 -0
  672. package/src/durable/internal/record-ownership.ts +68 -0
  673. package/src/durable/internal/run-context-reader.ts +51 -0
  674. package/src/durable/internal/run-context.ts +211 -0
  675. package/src/durable/internal/schedule-time.ts +304 -0
  676. package/src/durable/internal/thread-import-reader.ts +85 -0
  677. package/src/durable/internal/thread-initialization.ts +181 -0
  678. package/src/durable/internal/thread-transfer-source.ts +7 -0
  679. package/src/durable/internal/tool-operations.ts +138 -0
  680. package/src/durable/internal/transfer-dependencies.ts +40 -0
  681. package/src/durable/internal/usage-totals.ts +36 -0
  682. package/src/durable/internal/worker-host.ts +4041 -0
  683. package/src/durable/internal/worker-runtime.ts +10 -0
  684. package/src/engine/AgentRuntime.ts +100 -0
  685. package/src/engine/Compaction.ts +11 -0
  686. package/src/engine/ContextCompactor.ts +302 -0
  687. package/src/engine/ContextHistory.ts +75 -0
  688. package/src/engine/ContextWindow.ts +81 -0
  689. package/src/engine/DurableStep.ts +115 -0
  690. package/src/engine/MessagingHost.ts +118 -0
  691. package/src/engine/Output.ts +2 -0
  692. package/src/engine/RunEventSink.ts +124 -0
  693. package/src/engine/RunOptions.ts +664 -0
  694. package/src/engine/SubagentHost.ts +231 -0
  695. package/src/engine/ThreadHistory.ts +125 -0
  696. package/src/engine/ToolBroker.ts +159 -0
  697. package/src/engine/ToolExposure.ts +49 -0
  698. package/src/engine/internal/agent-runtime.ts +11137 -0
  699. package/src/engine/internal/bounded-value.ts +312 -0
  700. package/src/engine/internal/compaction.ts +673 -0
  701. package/src/engine/internal/error-diagnostic.ts +39 -0
  702. package/src/engine/internal/image-tokens.ts +61 -0
  703. package/src/engine/internal/interpreter-options.ts +569 -0
  704. package/src/engine/internal/output-contract.ts +226 -0
  705. package/src/engine/internal/primitive-delta.ts +103 -0
  706. package/src/engine/internal/provider-result-staging.ts +211 -0
  707. package/src/engine/internal/provisional-text.ts +107 -0
  708. package/src/engine/internal/tool-derivative.ts +47 -0
  709. package/src/engine/internal/tool-exposure.ts +228 -0
  710. package/src/engine/internal/tool-telemetry.ts +488 -0
  711. package/src/index.ts +100 -0
  712. package/src/sandbox/CodeExecutor.ts +352 -0
  713. package/src/sandbox/InteractiveBrowser.ts +343 -0
  714. package/src/sandbox/PageCapture.ts +391 -0
  715. package/src/sandbox/PageScreenshot.ts +83 -0
  716. package/src/sandbox/Sandbox.ts +29 -0
  717. package/README.md +0 -3
@@ -0,0 +1,1129 @@
1
+ import * as Tool from 'effect/ai/Tool'
2
+ import * as Toolkit from 'effect/ai/Toolkit'
3
+ import * as Cause from 'effect/Cause'
4
+ import * as Context from 'effect/Context'
5
+ import * as Duration from 'effect/Duration'
6
+ import * as Effect from 'effect/Effect'
7
+ import * as Exit from 'effect/Exit'
8
+ import type * as Layer from 'effect/Layer'
9
+ import * as Option from 'effect/Option'
10
+ import * as Schema from 'effect/Schema'
11
+ import type * as Scope from 'effect/Scope'
12
+
13
+ import { utf8ByteLength } from '../core/internal/utf8'
14
+ import { AdditionalToolCatalog, IncludesCatalogDocumentation } from '../core/ToolExposure'
15
+ import {
16
+ type ProgrammaticCallOutcome,
17
+ ProgrammaticCallRecord,
18
+ ToolBroker,
19
+ type ToolBrokerConfigurationError,
20
+ type ToolBrokerPass,
21
+ type ToolBrokerUnavailableError,
22
+ } from '../engine/ToolBroker'
23
+ import { CurrentToolCatalog } from '../engine/ToolExposure'
24
+ import {
25
+ type CodeExecutionError,
26
+ CodeExecutionHost,
27
+ CodeExecutionLimits,
28
+ CodeExecutionNamespace,
29
+ CodeExecutionRequest,
30
+ type CodeExecutionResult,
31
+ CodeExecutor,
32
+ type CodeHostCall,
33
+ type CodeHostCallResult,
34
+ JsIdentifier,
35
+ } from '../sandbox/CodeExecutor'
36
+ import { NetworkDisabled } from '../sandbox/Sandbox'
37
+
38
+ /**
39
+ * Code Mode (D-035, ADR-0017; capability spec §9.1): one native Effect AI
40
+ * Tool whose input is bounded JavaScript source, executed in one isolated
41
+ * `CodeExecutor` pass that may call an explicit construction-time allowlist
42
+ * of existing Tools through typed sandbox globals and the engine-owned
43
+ * `ToolBroker`. The builder follows the Delegation pattern: an explicit
44
+ * record of selected Tools plus namespace mapping fixed at construction,
45
+ * returning an ordinary Tool and a handler Layer, with no ambient registry
46
+ * (CAP-014). Deployment class `E` only.
47
+ */
48
+
49
+ const maxFailureTextLength = 4 * 1024
50
+ const BoundedFailureText = Schema.String.check(Schema.isMaxLength(maxFailureTextLength))
51
+ const BoundedErrorTag = Schema.NonEmptyString.check(Schema.isMaxLength(256))
52
+ const BoundedLogLine = Schema.String.check(Schema.isMaxLength(16 * 1024))
53
+ const BoundedLogs = Schema.Array(BoundedLogLine).check(Schema.isMaxLength(4_096))
54
+ const BoundedCode = Schema.NonEmptyString.check(Schema.isMaxLength(512 * 1024))
55
+
56
+ /** A pass-local report, available to the host even when the caller interrupts execution. */
57
+ export const CodeModePassReport = Schema.Struct({
58
+ status: Schema.Literals(['completed', 'failed', 'interrupted', 'defect']),
59
+ calls: Schema.Array(ProgrammaticCallRecord),
60
+ })
61
+
62
+ export type CodeModePassReport = typeof CodeModePassReport.Type
63
+
64
+ const encodedJsonByteLength = (value: unknown): number | undefined => {
65
+ try {
66
+ const encoded = JSON.stringify(value)
67
+
68
+ return encoded === undefined ? undefined : utf8ByteLength(encoded)
69
+ } catch {
70
+ return undefined
71
+ }
72
+ }
73
+
74
+ /** Model-decoded Code Mode parameters: one async function expression. */
75
+ export const CodeModeParameters = Schema.Struct({
76
+ code: BoundedCode,
77
+ })
78
+
79
+ /**
80
+ * The bounded model-visible success: the program's JSON result plus captured
81
+ * logs, both already passed through the aggregate egress budget (CAP-016).
82
+ */
83
+ export class CodeModeSuccess extends Schema.Class<CodeModeSuccess>(
84
+ '@effect-agent/capabilities/CodeModeSuccess',
85
+ )({
86
+ result: Schema.Json,
87
+ logs: BoundedLogs,
88
+ }) {}
89
+
90
+ /**
91
+ * The bounded model-visible failure envelope. `failureMode: "return"` turns
92
+ * it into a failed Tool result, so a model can correct a failing program
93
+ * without a blind retry; it carries the same bounded log capture as success
94
+ * plus the bounded thrown value where one exists, all inside the same
95
+ * aggregate egress budget (CAP-016).
96
+ */
97
+ export class CodeModeFailure extends Schema.TaggedError<CodeModeFailure>()('CodeModeFailure', {
98
+ errorTag: BoundedErrorTag,
99
+ message: BoundedFailureText,
100
+ logs: BoundedLogs,
101
+ thrown: Schema.optionalKey(Schema.Json),
102
+ /** Invocation-ordered evidence that fits the egress budget. This is not a replay plan. */
103
+ calls: Schema.optionalKey(Schema.Array(ProgrammaticCallRecord)),
104
+ omittedCalls: Schema.optionalKey(Schema.Natural),
105
+ }) {}
106
+
107
+ /** A selective documentation request is invalid or cannot fit its declared byte budget. */
108
+ export class CodeModeDescriptionError extends Schema.TaggedError<CodeModeDescriptionError>()(
109
+ 'CodeModeDescriptionError',
110
+ {
111
+ reason: Schema.Literals([
112
+ 'invalid-selection',
113
+ 'unknown-method',
114
+ 'invalid-bound',
115
+ 'invalid-schema',
116
+ 'limit-exceeded',
117
+ ]),
118
+ message: BoundedFailureText,
119
+ },
120
+ ) {}
121
+
122
+ const DescriptionMethods = Schema.Array(Schema.NonEmptyString.check(Schema.isMaxLength(257))).check(
123
+ Schema.isMinLength(1),
124
+ Schema.isMaxLength(64),
125
+ Schema.isUnique(),
126
+ )
127
+
128
+ const DescriptionByteLimit = Schema.Int.check(
129
+ Schema.isBetween({ minimum: 1, maximum: 256 * 1024 }),
130
+ )
131
+
132
+ /** The namespace-record shape accepted by `CodeMode.make`. */
133
+ export type CodeModeNamespaces = Record<string, Record<string, Tool.Any>>
134
+
135
+ /**
136
+ * Union of every Tool selected across all namespaces, computed distributively
137
+ * per namespace: indexing the namespace union with the INTERSECTION of method
138
+ * keys would erase every Tool once two namespaces have disjoint methods.
139
+ */
140
+ export type CodeModeSelectedTool<Namespaces extends CodeModeNamespaces> = {
141
+ [Namespace in keyof Namespaces]: Namespaces[Namespace][keyof Namespaces[Namespace]]
142
+ }[keyof Namespaces]
143
+
144
+ /** The selected Tools re-keyed by their own Tool names. */
145
+ export type CodeModeSelectedRecord<Namespaces extends CodeModeNamespaces> = {
146
+ readonly [T in CodeModeSelectedTool<Namespaces> as T['name']]: T
147
+ }
148
+
149
+ /**
150
+ * The native Effect AI Tool created by `CodeMode.make` (CAP-014). Its only
151
+ * per-call dependency is the engine-provided `ToolBroker`; the `CodeExecutor`
152
+ * and every selected handler and redaction service are construction requirements of the handler
153
+ * Layer instead, so they stay visible in the composed `R`.
154
+ */
155
+ export type CodeModeTool<Name extends string> = Tool.Tool<
156
+ Name,
157
+ {
158
+ readonly parameters: typeof CodeModeParameters
159
+ readonly success: typeof CodeModeSuccess
160
+ readonly failure: typeof CodeModeFailure
161
+ readonly failureMode: 'return'
162
+ },
163
+ ToolBroker
164
+ >
165
+
166
+ /** Singleton Tool record provided by one Code Mode handler Layer. */
167
+ export type CodeModeTools<Name extends string> = {
168
+ readonly [Key in Name]: CodeModeTool<Name>
169
+ }
170
+
171
+ /** Construction requirements of the Code Mode handler Layer. */
172
+ export type CodeModeLayerRequirements<
173
+ Namespaces extends CodeModeNamespaces,
174
+ RedactionRequirements = never,
175
+ > =
176
+ | CodeExecutor
177
+ | Exclude<RedactionRequirements, Scope.Scope>
178
+ | Tool.HandlersFor<CodeModeSelectedRecord<Namespaces>>
179
+ | Tool.HandlerServices<CodeModeSelectedTool<Namespaces>>
180
+
181
+ export interface CodeModeOptions<
182
+ Namespaces extends CodeModeNamespaces,
183
+ RedactionRequirements = never,
184
+ > {
185
+ /** Model-visible description; the builder appends the sandbox contract. */
186
+ readonly description: string
187
+ /** Include all sandbox declarations in the model-facing description. Defaults to true. */
188
+ readonly includeDeclarations?: boolean | undefined
189
+ /**
190
+ * Explicit allowlist: namespace name → method name → native Effect AI
191
+ * Tool. Reads and mutations are allowed; calls requiring additional approval fail closed.
192
+ */
193
+ readonly tools: Namespaces
194
+ /** Executor limits for one pass; a bounded default applies when omitted. */
195
+ readonly limits?: CodeExecutionLimits | undefined
196
+ /**
197
+ * Aggregate model-visible egress budget in UTF-8 bytes across the final
198
+ * result, captured logs, and any thrown value (CAP-016). Default 65536.
199
+ */
200
+ readonly maxEgressBytes?: number | undefined
201
+ /**
202
+ * Host-only ephemeral report after executor resources and invocation fibers close, including
203
+ * failure, defect, and interruption. It contains no arguments/results and is never a checkpoint.
204
+ * Keep this total callback bounded; its services are captured with the handler Layer.
205
+ */
206
+ readonly onPassExit?:
207
+ | ((report: CodeModePassReport) => Effect.Effect<void, never, RedactionRequirements>)
208
+ | undefined
209
+ /**
210
+ * Optional aggregate redaction pass applied to the model-visible egress
211
+ * before the byte budget. Its services are acquired with the handler Layer;
212
+ * temporary resources close with each redaction invocation.
213
+ * It must be total; a defect stays a defect.
214
+ */
215
+ readonly redactEgress?:
216
+ | ((egress: {
217
+ readonly result: Schema.Json
218
+ readonly logs: ReadonlyArray<string>
219
+ }) => Effect.Effect<
220
+ {
221
+ readonly result: Schema.Json
222
+ readonly logs: ReadonlyArray<string>
223
+ },
224
+ never,
225
+ RedactionRequirements
226
+ >)
227
+ | undefined
228
+ }
229
+
230
+ /**
231
+ * An immutable Code Mode definition: one model-facing Tool over an explicit
232
+ * allowlist, plus the handler Layer that runs generated programs through the
233
+ * `CodeExecutor` port and the engine-owned broker. It owns no acquired
234
+ * resources.
235
+ */
236
+ export interface CodeModeDefinition<
237
+ Name extends string,
238
+ Namespaces extends CodeModeNamespaces,
239
+ RedactionRequirements = never,
240
+ > {
241
+ readonly name: Name
242
+ /** The assembled model-facing description, optionally including all declarations. */
243
+ readonly description: string
244
+ /** Lazily rendered TypeScript documentation; throws if an encoded schema cannot be rendered. */
245
+ readonly declarations: string
246
+ /**
247
+ * Render complete encoded-schema declarations for 1–64 unique, exact namespace.method names.
248
+ * The UTF-8 byte limit defaults to 16384 and must be an integer from 1 through 262144.
249
+ * Oversized documentation fails rather than truncating a declaration. This host operation
250
+ * does not authorize a model to see the selected methods; filter selections by current
251
+ * visibility and inherited grants before returning its output to a model.
252
+ */
253
+ readonly describe: (
254
+ methods: ReadonlyArray<string>,
255
+ options?: { readonly maxBytes?: number | undefined },
256
+ ) => Effect.Effect<string, CodeModeDescriptionError>
257
+ /** The executor-facing namespace catalog derived from the allowlist. */
258
+ readonly namespaces: ReadonlyArray<CodeExecutionNamespace>
259
+ readonly limits: CodeExecutionLimits
260
+ readonly maxEgressBytes: number
261
+ /** The ordinary Effect AI Tool to include in the model-facing Toolkit. */
262
+ readonly tool: CodeModeTool<Name>
263
+ /** Handler Layer; selected handler requirements stay visible in `R`. */
264
+ readonly handlers: Layer.Layer<
265
+ Tool.HandlersFor<CodeModeTools<Name>>,
266
+ never,
267
+ CodeModeLayerRequirements<Namespaces, RedactionRequirements>
268
+ >
269
+ }
270
+
271
+ const defaultLimits = CodeExecutionLimits.make({
272
+ maxSourceBytes: 256 * 1024,
273
+ maxWallTime: Duration.seconds(30),
274
+ maxLogBytes: 256 * 1024,
275
+ maxResultBytes: 1024 * 1024,
276
+ maxHostCalls: 64,
277
+ maxHostCallArgumentBytes: 256 * 1024,
278
+ maxHostCallResultBytes: 1024 * 1024,
279
+ })
280
+
281
+ const defaultMaxEgressBytes = 64 * 1024
282
+
283
+ // ---------------------------------------------------------------------------
284
+ // Declaration rendering (capability spec §9.1): the encoded side of each
285
+ // Schema — the JSON that actually crosses the sandbox boundary — rendered as
286
+ // TypeScript documentation via the same JSON-schema derivation Effect AI
287
+ // applies to Tool parameters. A schema the renderer cannot express fails when
288
+ // its declaration is requested rather than degrading to `unknown`.
289
+ // ---------------------------------------------------------------------------
290
+
291
+ const MAX_RENDER_DEPTH = 24
292
+
293
+ const isJsonSchemaRecord = (value: unknown): value is Record<string, unknown> =>
294
+ typeof value === 'object' && value !== null && !Array.isArray(value)
295
+
296
+ const renderJsonSchemaType = (
297
+ schema: unknown,
298
+ defs: Record<string, unknown>,
299
+ depth: number,
300
+ indent: string,
301
+ ): string => {
302
+ if (depth > MAX_RENDER_DEPTH) {
303
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously bounds recursive Schema declaration rendering before creating the Tool.
304
+ throw new Error('Code Mode declaration rendering exceeded its depth bound')
305
+ }
306
+ if (!isJsonSchemaRecord(schema)) {
307
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects unsupported JSON Schema declaration fragments.
308
+ throw new Error(`Code Mode cannot render the JSON schema fragment ${JSON.stringify(schema)}`)
309
+ }
310
+ // An empty schema is explicitly unconstrained, including Schema.Json's array items.
311
+ // This is a faithful declaration; unrecognized nonempty fragments still fail below.
312
+ if (Object.keys(schema).length === 0) return 'unknown'
313
+ const reference = schema.$ref
314
+
315
+ if (typeof reference === 'string') {
316
+ const match = /^#\/\$defs\/(.+)$/.exec(reference)
317
+ // JSON-pointer tokens escape `/` as `~1` and `~` as `~0`.
318
+ const key = match === null ? undefined : match[1].replaceAll('~1', '/').replaceAll('~0', '~')
319
+ const resolved = key === undefined ? undefined : defs[key]
320
+
321
+ if (resolved === undefined) {
322
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects unresolved declaration references.
323
+ throw new Error(`Code Mode cannot resolve the JSON schema reference ${reference}`)
324
+ }
325
+
326
+ return renderJsonSchemaType(resolved, defs, depth + 1, indent)
327
+ }
328
+ if (Array.isArray(schema.enum)) {
329
+ return schema.enum.map((value) => JSON.stringify(value)).join(' | ')
330
+ }
331
+ if ('const' in schema) {
332
+ return JSON.stringify(schema.const)
333
+ }
334
+ const union = schema.anyOf ?? schema.oneOf
335
+
336
+ if (Array.isArray(union)) {
337
+ return union.map((member) => renderJsonSchemaType(member, defs, depth + 1, indent)).join(' | ')
338
+ }
339
+ const type = schema.type
340
+
341
+ if (Array.isArray(type)) {
342
+ return type
343
+ .map((member) => renderJsonSchemaType({ ...schema, type: member }, defs, depth + 1, indent))
344
+ .join(' | ')
345
+ }
346
+ switch (type) {
347
+ case 'string': {
348
+ return 'string'
349
+ }
350
+ case 'number':
351
+ case 'integer': {
352
+ return 'number'
353
+ }
354
+ case 'boolean': {
355
+ return 'boolean'
356
+ }
357
+ case 'null': {
358
+ return 'null'
359
+ }
360
+ case 'array': {
361
+ if (!('items' in schema)) {
362
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously requires item schemas for array declarations.
363
+ throw new Error('Code Mode cannot render an array schema without items')
364
+ }
365
+
366
+ return `ReadonlyArray<${renderJsonSchemaType(schema.items, defs, depth + 1, indent)}>`
367
+ }
368
+ case 'object':
369
+ case undefined: {
370
+ if (isJsonSchemaRecord(schema.properties)) {
371
+ const required = Array.isArray(schema.required) ? schema.required : []
372
+ const inner = `${indent} `
373
+
374
+ const fields = Object.entries(schema.properties).map(([key, property]) => {
375
+ const optional = required.includes(key) ? '' : '?'
376
+ // A JSON property name need not be a TypeScript identifier.
377
+ const rendered = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key)
378
+
379
+ return `${inner}readonly ${rendered}${optional}: ${renderJsonSchemaType(property, defs, depth + 1, inner)};`
380
+ })
381
+
382
+ return fields.length === 0 ? '{}' : `{\n${fields.join('\n')}\n${indent}}`
383
+ }
384
+ if (isJsonSchemaRecord(schema.additionalProperties)) {
385
+ return `Record<string, ${renderJsonSchemaType(schema.additionalProperties, defs, depth + 1, indent)}>`
386
+ }
387
+ // Schema.Record(Schema.String, Schema.Never) accepts only an empty object.
388
+ if (
389
+ type === 'object' &&
390
+ !('properties' in schema) &&
391
+ !('patternProperties' in schema) &&
392
+ schema.additionalProperties === false
393
+ ) {
394
+ return 'Record<string, never>'
395
+ }
396
+ // A bare `{ "type": "object" }` states "any JSON object" (Schema.Json's
397
+ // object member derives to exactly this); rendering it as an
398
+ // unconstrained record is faithful, not a deriver degradation.
399
+ if (type === 'object' && !('properties' in schema) && !('additionalProperties' in schema)) {
400
+ return 'Record<string, unknown>'
401
+ }
402
+ break
403
+ }
404
+ default: {
405
+ break
406
+ }
407
+ }
408
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects declaration schemas it cannot faithfully render.
409
+ throw new Error(
410
+ `Code Mode cannot render the JSON schema fragment ${
411
+ JSON.stringify(schema).slice(0, 200)
412
+ }; fix or simplify the Tool's Schema`,
413
+ )
414
+ }
415
+
416
+ const renderTopLevel = (jsonSchema: unknown, indent: string): string => {
417
+ const defs = isJsonSchemaRecord(jsonSchema) && isJsonSchemaRecord(jsonSchema.$defs)
418
+ ? jsonSchema.$defs
419
+ : ({} as Record<string, unknown>)
420
+
421
+ return renderJsonSchemaType(jsonSchema, defs, 0, indent)
422
+ }
423
+
424
+ const decodeIdentifier = Schema.decodeUnknownOption(JsIdentifier)
425
+
426
+ interface ResolvedMethod {
427
+ readonly namespace: string
428
+ readonly method: string
429
+ readonly tool: Tool.Any
430
+ /** Private cache populated only when this method's documentation is requested. */
431
+ declaration: string | undefined
432
+ }
433
+
434
+ /** Render one encoded Tool signature; the definition caches it on first request. */
435
+ const renderMethodDeclaration = (method: string, tool: Tool.Any): string => {
436
+ const parameters = renderTopLevel(Tool.getJsonSchema(tool), ' ')
437
+ const success = renderTopLevel(Tool.getJsonSchemaFromSchema(tool.successSchema), ' ')
438
+
439
+ // A description is arbitrary text: newlines and comment terminators
440
+ // must not be able to break out of the documentation comment.
441
+ const safeDescription = tool.description?.replaceAll('*/', '*\\/').replaceAll(/\s*\n\s*/g, ' ')
442
+
443
+ const description = safeDescription === undefined ? '' : ` /** ${safeDescription} */\n`
444
+
445
+ return `${description} ${method}(input: ${parameters}): Promise<${success}>;`
446
+ }
447
+
448
+ const renderDeclarations = (methods: ReadonlyArray<ResolvedMethod>): string => {
449
+ const namespaces = new Map<string, Array<string>>()
450
+
451
+ for (const method of methods) {
452
+ const existing = namespaces.get(method.namespace) ?? []
453
+
454
+ existing.push(method.declaration ??= renderMethodDeclaration(method.method, method.tool))
455
+ namespaces.set(method.namespace, existing)
456
+ }
457
+
458
+ const blocks = [...namespaces.entries()].map(
459
+ ([namespace, lines]) => `declare const ${namespace}: {\n${lines.join('\n')}\n};`,
460
+ )
461
+
462
+ return blocks.join('\n\n')
463
+ }
464
+
465
+ // ---------------------------------------------------------------------------
466
+ // Aggregate model-visible egress (CAP-016): the final result, captured logs,
467
+ // and any thrown value share one byte budget. Logs are truncated line-by-line
468
+ // with an explicit marker; a result that alone exceeds the budget is a typed
469
+ // failure rather than silent truncation.
470
+ // ---------------------------------------------------------------------------
471
+
472
+ const truncationMarker = '… logs truncated by the egress budget'
473
+ const MAX_EGRESS_LOG_LINE_CHARACTERS = 16_000
474
+
475
+ /**
476
+ * Budget charge of one log line as it actually crosses to the model: the
477
+ * JSON-encoded string (quotes, escapes) plus one array separator. Charging
478
+ * raw UTF-8 would undercount model-visible bytes for escape-heavy content.
479
+ */
480
+ const encodedLogLineBytes = (line: string): number => {
481
+ try {
482
+ return utf8ByteLength(JSON.stringify(line)) + 1
483
+ } catch {
484
+ return Number.MAX_SAFE_INTEGER
485
+ }
486
+ }
487
+
488
+ const budgetedLogs = (
489
+ logs: ReadonlyArray<string>,
490
+ remainingBytes: number,
491
+ ): ReadonlyArray<string> => {
492
+ const kept: Array<string> = []
493
+ let used = 0
494
+ let truncated = false
495
+
496
+ for (const raw of logs) {
497
+ // Per-line cap keeps every kept line inside the BoundedLogLine schema.
498
+ const line = raw.length > MAX_EGRESS_LOG_LINE_CHARACTERS
499
+ ? `${raw.slice(0, MAX_EGRESS_LOG_LINE_CHARACTERS - 1)}…`
500
+ : raw
501
+
502
+ const bytes = encodedLogLineBytes(line)
503
+
504
+ if (kept.length >= 4_096 || used + bytes > remainingBytes) {
505
+ truncated = true
506
+ break
507
+ }
508
+ kept.push(line)
509
+ used += bytes
510
+ }
511
+ if (truncated) {
512
+ // Truncation is never silent: drop kept lines from the end until the
513
+ // marker itself fits inside the budget.
514
+ const markerBytes = encodedLogLineBytes(truncationMarker)
515
+
516
+ while (kept.length > 0 && used + markerBytes > remainingBytes) {
517
+ used -= encodedLogLineBytes(kept.pop() ?? '')
518
+ }
519
+ if (markerBytes <= remainingBytes) {
520
+ kept.push(truncationMarker)
521
+ }
522
+ }
523
+
524
+ return kept
525
+ }
526
+
527
+ const boundedMessage = (message: string): string => message.slice(0, maxFailureTextLength)
528
+
529
+ const executionFailureMessage = (error: CodeExecutionError): string => {
530
+ switch (error._tag) {
531
+ case 'CodeExecutionTimeoutError': {
532
+ return `The program exceeded its ${Duration.format(error.maxWallTime)} ${error.kind} budget`
533
+ }
534
+ case 'CodeOutputLimitError': {
535
+ return `The ${error.surface} limit of ${error.limit} bytes was exceeded (${error.observed} bytes observed)`
536
+ }
537
+ case 'CodeHostCallLimitError': {
538
+ return `The pass exceeded its executor cap of ${error.limit} host calls`
539
+ }
540
+ default: {
541
+ return error.message
542
+ }
543
+ }
544
+ }
545
+
546
+ /** UTF-8-aware truncation so a message can never exceed the aggregate budget. */
547
+ const truncateToUtf8Bytes = (value: string, maxBytes: number): string => {
548
+ if (utf8ByteLength(value) <= maxBytes) {
549
+ return value
550
+ }
551
+ let output = ''
552
+ let used = 0
553
+
554
+ for (const character of value) {
555
+ const bytes = utf8ByteLength(character)
556
+
557
+ if (used + bytes + 3 > maxBytes) {
558
+ break
559
+ }
560
+ output += character
561
+ used += bytes
562
+ }
563
+
564
+ return `${output}…`
565
+ }
566
+
567
+ type EgressRedactor<Requirements = never> = NonNullable<
568
+ CodeModeOptions<CodeModeNamespaces, Requirements>['redactEgress']
569
+ >
570
+
571
+ // ---------------------------------------------------------------------------
572
+ // Builder
573
+ // ---------------------------------------------------------------------------
574
+
575
+ const make = <
576
+ const Name extends string,
577
+ Namespaces extends CodeModeNamespaces,
578
+ RedactionRequirements = never,
579
+ >(
580
+ name: Name,
581
+ options: CodeModeOptions<Namespaces, RedactionRequirements>,
582
+ ): CodeModeDefinition<Name, Namespaces, RedactionRequirements> => {
583
+ const limits = options.limits ?? defaultLimits
584
+ const maxEgressBytes = options.maxEgressBytes ?? defaultMaxEgressBytes
585
+
586
+ // Fail closed on an invalid egress bound: NaN would make every size
587
+ // comparison false and Infinity would remove the bound entirely.
588
+ if (
589
+ !Number.isSafeInteger(maxEgressBytes) ||
590
+ maxEgressBytes < 256 ||
591
+ maxEgressBytes > 4 * 1024 * 1024
592
+ ) {
593
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects invalid egress bounds before creating the Tool.
594
+ throw new Error(
595
+ `Code Mode maxEgressBytes must be an integer between 256 and ${4 * 1024 * 1024}; received ${
596
+ String(maxEgressBytes)
597
+ }`,
598
+ )
599
+ }
600
+
601
+ // Construction-time fail-closed validation (CAP-014).
602
+ const methods: Array<ResolvedMethod> = []
603
+ const toolsByName = new Map<string, Tool.Any>()
604
+ const methodToTool = new Map<string, string>()
605
+
606
+ for (const [namespace, namespaceMethods] of Object.entries(options.tools)) {
607
+ if (Option.isNone(decodeIdentifier(namespace))) {
608
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously requires valid JavaScript namespace identifiers.
609
+ throw new Error(`Code Mode namespace ${namespace} is not a valid JavaScript identifier`)
610
+ }
611
+ const entries = Object.entries(namespaceMethods)
612
+
613
+ if (entries.length === 0) {
614
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects namespaces without callable methods.
615
+ throw new Error(`Code Mode namespace ${namespace} declares no methods`)
616
+ }
617
+ for (const [method, tool] of entries) {
618
+ if (Option.isNone(decodeIdentifier(method))) {
619
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously requires valid JavaScript method identifiers.
620
+ throw new Error(
621
+ `Code Mode method ${namespace}.${method} is not a valid JavaScript identifier`,
622
+ )
623
+ }
624
+ const approval = tool.needsApproval
625
+
626
+ if (approval !== undefined && approval !== false) {
627
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects approval-requiring Tools from its programmatic allowlist.
628
+ throw new Error(
629
+ `Code Mode rejects Tool ${tool.name} (${namespace}.${method}): approval-requiring Tools cannot be invoked programmatically in the ephemeral slice`,
630
+ )
631
+ }
632
+ const existing = toolsByName.get(tool.name)
633
+
634
+ if (existing !== undefined && existing !== tool) {
635
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously rejects conflicting Tools sharing one name.
636
+ throw new Error(
637
+ `Code Mode selected two different Tools named ${tool.name}; Tool names must identify one Tool`,
638
+ )
639
+ }
640
+ toolsByName.set(tool.name, tool)
641
+ methodToTool.set(`${namespace}.${method}`, tool.name)
642
+ methods.push({ namespace, method, tool, declaration: undefined })
643
+ }
644
+ }
645
+ if (methods.length === 0) {
646
+ // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- CodeMode.make synchronously requires a nonempty Tool allowlist.
647
+ throw new Error('Code Mode requires at least one allowlisted Tool')
648
+ }
649
+
650
+ let declarations = options.includeDeclarations === false ? undefined : renderDeclarations(methods)
651
+
652
+ const methodsByPath = new Map(
653
+ methods.map((method) => [`${method.namespace}.${method.method}`, method]),
654
+ )
655
+
656
+ const describe = Effect.fnUntraced(function*(
657
+ selected: ReadonlyArray<string>,
658
+ options?: { readonly maxBytes?: number | undefined },
659
+ ) {
660
+ const paths = yield* Schema.decodeEffect(DescriptionMethods)(selected).pipe(
661
+ Effect.mapError(() =>
662
+ CodeModeDescriptionError.make({
663
+ reason: 'invalid-selection',
664
+ message: 'Select between 1 and 64 unique namespace.method names, each at most 257 characters',
665
+ })
666
+ ),
667
+ )
668
+
669
+ const maxBytes = yield* Schema.decodeEffect(DescriptionByteLimit)(
670
+ options?.maxBytes ?? 16 * 1024,
671
+ ).pipe(
672
+ Effect.mapError(() =>
673
+ CodeModeDescriptionError.make({
674
+ reason: 'invalid-bound',
675
+ message: 'The documentation byte limit must be an integer between 1 and 262144',
676
+ })
677
+ ),
678
+ )
679
+
680
+ const selectedMethods: Array<ResolvedMethod> = []
681
+
682
+ for (const path of paths) {
683
+ const method = methodsByPath.get(path)
684
+
685
+ if (method === undefined) {
686
+ return yield* CodeModeDescriptionError.make({
687
+ reason: 'unknown-method',
688
+ message: 'The selection contains a method outside this Code Mode allowlist',
689
+ })
690
+ }
691
+ selectedMethods.push(method)
692
+ }
693
+
694
+ const documentation = yield* Effect.try({
695
+ try: () => renderDeclarations(selectedMethods),
696
+ catch: () =>
697
+ CodeModeDescriptionError.make({
698
+ reason: 'invalid-schema',
699
+ message: 'A selected method cannot be documented as TypeScript',
700
+ }),
701
+ })
702
+
703
+ if (utf8ByteLength(documentation) > maxBytes) {
704
+ return yield* CodeModeDescriptionError.make({
705
+ reason: 'limit-exceeded',
706
+ message:
707
+ `The selected declarations exceed the ${maxBytes}-byte documentation limit; select fewer methods or raise the limit`,
708
+ })
709
+ }
710
+
711
+ return documentation
712
+ })
713
+
714
+ const namespaces = [...new Set(methods.map((method) => method.namespace))].map((namespace) =>
715
+ CodeExecutionNamespace.make({
716
+ name: namespace,
717
+ methods: methods
718
+ .filter((method) => method.namespace === namespace)
719
+ .map((method) => method.method),
720
+ })
721
+ )
722
+
723
+ const description = [
724
+ options.description,
725
+ '',
726
+ 'The `code` argument must be one JavaScript async function expression; the sandbox invokes it exactly once with no arguments. It runs isolated with no ambient network, filesystem, environment, or secrets. Return one JSON value. `console.log` output is captured within a bounded budget and returned alongside the result.',
727
+ 'Namespace methods return Promises. An expected Tool failure rejects with a JSON envelope carrying a stable `_tag`; catch it to branch. Use Promise.all for independent calls; the host bounds concurrency. Await every call you need. Writes may complete before a failure: inspect call outcomes and never blindly retry a program.',
728
+ ...(declarations === undefined ? [] : ['', 'Sandbox globals:', '```ts', declarations, '```']),
729
+ ].join('\n')
730
+
731
+ const tool = Tool.make(name, {
732
+ description,
733
+ parameters: CodeModeParameters,
734
+ success: CodeModeSuccess,
735
+ failure: CodeModeFailure,
736
+ failureMode: 'return',
737
+ })
738
+ .annotate(Tool.Readonly, false)
739
+ .annotate(ToolExecutionClassAnnotation, 'uncertain')
740
+ .annotate(IncludesCatalogDocumentation, options.includeDeclarations !== false)
741
+ .annotate(
742
+ AdditionalToolCatalog,
743
+ Object.freeze(
744
+ methods.map(({ namespace, method, tool }) => Object.freeze({ namespace, method, tool })),
745
+ ),
746
+ )
747
+ .addDependency(ToolBroker) as CodeModeTool<Name>
748
+
749
+ const outerToolkit = Toolkit.make(tool)
750
+
751
+ /**
752
+ * The nested namespace record collapses into one Toolkit keyed by exact
753
+ * Tool names. The assertion restores the name-keyed record type TypeScript
754
+ * cannot compute from `Map` iteration; construction above guarantees the
755
+ * name uniqueness the type states.
756
+ */
757
+ const selectedToolkit = Toolkit.make(...toolsByName.values()) as unknown as Toolkit.Toolkit<
758
+ CodeModeSelectedRecord<Namespaces>
759
+ >
760
+
761
+ const executionRequest = (
762
+ code: string,
763
+ visibleNamespaces: ReadonlyArray<CodeExecutionNamespace>,
764
+ ): CodeExecutionRequest =>
765
+ CodeExecutionRequest.make({
766
+ language: 'javascript',
767
+ source: code,
768
+ namespaces: visibleNamespaces,
769
+ network: NetworkDisabled.make({}),
770
+ limits,
771
+ })
772
+
773
+ const routeHostCall = (
774
+ pass: ToolBrokerPass,
775
+ hostCall: CodeHostCall,
776
+ visiblePaths: ReadonlySet<string> | undefined,
777
+ ): Effect.Effect<CodeHostCallResult> =>
778
+ Effect.gen(function*() {
779
+ const path = `${hostCall.namespace}.${hostCall.method}`
780
+
781
+ const toolName = visiblePaths === undefined || visiblePaths.has(path) ? methodToTool.get(path) : undefined
782
+
783
+ if (toolName === undefined) {
784
+ return {
785
+ _tag: 'CodeHostCallFailure',
786
+ error: {
787
+ _tag: 'UnknownCodeModeMethod',
788
+ message: 'The requested method is not available in this pass',
789
+ },
790
+ } as const
791
+ }
792
+
793
+ const outcome: ProgrammaticCallOutcome = yield* pass.invoke({
794
+ toolName,
795
+ encodedArguments: hostCall.argument,
796
+ })
797
+
798
+ switch (outcome._tag) {
799
+ case 'ProgrammaticCallSuccess': {
800
+ const value = decodeBrokerJson(outcome.encodedResult)
801
+
802
+ return Option.isSome(value)
803
+ ? ({ _tag: 'CodeHostCallSuccess', value: value.value } as const)
804
+ : ({ _tag: 'CodeHostCallFailure', error: brokerProtocolEnvelope } as const)
805
+ }
806
+ case 'ProgrammaticCallFailure': {
807
+ const value = decodeBrokerJson(outcome.encodedResult)
808
+
809
+ return {
810
+ _tag: 'CodeHostCallFailure',
811
+ error: Option.isSome(value) ? value.value : brokerProtocolEnvelope,
812
+ } as const
813
+ }
814
+ case 'ProgrammaticCallError': {
815
+ return {
816
+ _tag: 'CodeHostCallFailure',
817
+ error: { _tag: outcome.errorTag, message: outcome.message },
818
+ } as const
819
+ }
820
+ }
821
+ })
822
+
823
+ const build = Effect.gen(function*() {
824
+ const captured = yield* Effect.context<
825
+ Tool.HandlerServices<
826
+ CodeModeSelectedRecord<Namespaces>[keyof CodeModeSelectedRecord<Namespaces>]
827
+ >
828
+ >()
829
+
830
+ const redactionServices = yield* Effect.context<Exclude<RedactionRequirements, Scope.Scope>>()
831
+ const configuredRedactor = options.redactEgress
832
+
833
+ const redact: EgressRedactor | undefined = configuredRedactor === undefined
834
+ ? undefined
835
+ : (egress) =>
836
+ Effect.scoped(configuredRedactor(egress)).pipe(
837
+ // Merge invocation-local services before opening the redaction Scope.
838
+ // The inner Scope shadows any Scope retained in the construction context.
839
+ Effect.updateContext((current: Context.Context<never>) => Context.merge(current, redactionServices)),
840
+ )
841
+
842
+ const withHandler = yield* selectedToolkit
843
+ const executor = yield* CodeExecutor
844
+
845
+ const successEgress = (
846
+ execution: CodeExecutionResult,
847
+ ): Effect.Effect<CodeModeSuccess, CodeModeFailure> =>
848
+ Effect.gen(function*() {
849
+ let egress: { readonly result: Schema.Json; readonly logs: ReadonlyArray<string> } = {
850
+ result: execution.value,
851
+ logs: execution.logs,
852
+ }
853
+
854
+ if (redact !== undefined) {
855
+ egress = yield* redact(egress)
856
+ }
857
+ const resultBytes = encodedJsonByteLength(egress.result)
858
+
859
+ if (resultBytes === undefined || resultBytes > maxEgressBytes) {
860
+ return yield* CodeModeFailure.make({
861
+ errorTag: 'CodeModeEgressExceeded',
862
+ message: `The program result of ${
863
+ resultBytes ?? 'unencodable'
864
+ } bytes exceeds the ${maxEgressBytes}-byte model-visible egress budget; return a smaller value`,
865
+ logs: budgetedLogs(egress.logs, Math.max(0, maxEgressBytes - 256)),
866
+ })
867
+ }
868
+
869
+ return CodeModeSuccess.make({
870
+ result: egress.result,
871
+ logs: budgetedLogs(egress.logs, maxEgressBytes - resultBytes),
872
+ })
873
+ })
874
+
875
+ /**
876
+ * The failure half of the aggregate egress policy (CAP-016): the configured
877
+ * redaction pass covers failure logs and thrown values exactly like success
878
+ * egress — a program cannot leak by logging and then throwing — and the
879
+ * message itself is bounded by the budget, not only by its own schema cap.
880
+ */
881
+ const failureEgress = (
882
+ error: CodeExecutionError | ToolBrokerUnavailableError | ToolBrokerConfigurationError,
883
+ ): Effect.Effect<CodeModeFailure> =>
884
+ Effect.gen(function*() {
885
+ if (
886
+ error._tag === 'ToolBrokerUnavailableError' ||
887
+ error._tag === 'ToolBrokerConfigurationError'
888
+ ) {
889
+ return CodeModeFailure.make({
890
+ errorTag: error._tag,
891
+ message: truncateToUtf8Bytes(boundedMessage(error.message), maxEgressBytes),
892
+ logs: [],
893
+ })
894
+ }
895
+ let logs: ReadonlyArray<string> = 'logs' in error ? error.logs : []
896
+ let candidateThrown = error._tag === 'CodeProgramFailedError' ? error.thrown : undefined
897
+
898
+ if (redact !== undefined) {
899
+ const redacted = yield* redact({ result: candidateThrown ?? null, logs })
900
+
901
+ logs = redacted.logs
902
+ candidateThrown = candidateThrown === undefined ? undefined : redacted.result
903
+ }
904
+
905
+ const message = truncateToUtf8Bytes(
906
+ boundedMessage(executionFailureMessage(error)),
907
+ maxEgressBytes,
908
+ )
909
+
910
+ const messageBytes = utf8ByteLength(message)
911
+
912
+ // `thrown` is included only when it fits TOGETHER with the message inside
913
+ // the aggregate budget, and it reduces the log allowance only when it is
914
+ // actually included.
915
+ const candidateBytes = candidateThrown === undefined ? undefined : encodedJsonByteLength(candidateThrown)
916
+
917
+ const includeThrown = candidateThrown !== undefined &&
918
+ candidateBytes !== undefined &&
919
+ messageBytes + candidateBytes <= maxEgressBytes
920
+
921
+ const remaining = Math.max(
922
+ 0,
923
+ maxEgressBytes - messageBytes - (includeThrown ? (candidateBytes ?? 0) : 0),
924
+ )
925
+
926
+ return CodeModeFailure.make({
927
+ errorTag: error._tag,
928
+ message,
929
+ logs: budgetedLogs(logs, remaining),
930
+ ...(includeThrown ? { thrown: candidateThrown } : {}),
931
+ })
932
+ })
933
+
934
+ const invoke = Effect.fnUntraced(function*(parameters: { readonly code: string }) {
935
+ const broker = yield* ToolBroker
936
+ // Resolve invocation authority before restoring captured construction services. A Layer
937
+ // built under an older Run must not restore that Run's catalogue or hidden method names.
938
+ const catalogue = yield* Effect.serviceOption(CurrentToolCatalog)
939
+
940
+ const visiblePaths = Option.isNone(catalogue)
941
+ ? undefined
942
+ : new Set(
943
+ catalogue.value.entries.flatMap((entry) =>
944
+ entry.kind === 'code-mode' &&
945
+ entry.nativeToolName === name &&
946
+ methodsByPath.get(`${entry.namespace}.${entry.method}`)?.tool.name === entry.tool.name
947
+ ? [`${entry.namespace}.${entry.method}`]
948
+ : []
949
+ ),
950
+ )
951
+
952
+ const visibleNamespaces = visiblePaths === undefined
953
+ ? namespaces
954
+ : namespaces.flatMap((namespace) => {
955
+ const allowed = namespace.methods.filter((method) => visiblePaths.has(`${namespace.name}.${method}`))
956
+
957
+ return allowed.length === 0
958
+ ? []
959
+ : [CodeExecutionNamespace.make({ name: namespace.name, methods: allowed })]
960
+ })
961
+
962
+ let calls: ReadonlyArray<ProgrammaticCallRecord> = []
963
+
964
+ const execution = Effect.gen(function*() {
965
+ const pass = yield* broker.openPass(withHandler, {
966
+ maxResultBytes: limits.maxHostCallResultBytes,
967
+ concurrency: limits.maxHostCallConcurrency ?? 4,
968
+ })
969
+
970
+ const host = CodeExecutionHost.of({
971
+ call: (hostCall) => routeHostCall(pass, hostCall, visiblePaths),
972
+ })
973
+
974
+ return yield* executor.execute(executionRequest(parameters.code, visibleNamespaces)).pipe(
975
+ Effect.provideService(CodeExecutionHost, host),
976
+ Effect.scoped,
977
+ Effect.onExit((exit) =>
978
+ Effect.gen(function*() {
979
+ calls = yield* pass.snapshot
980
+ if (options.onPassExit !== undefined) {
981
+ yield* Effect.scoped(
982
+ options.onPassExit({
983
+ status: Exit.isSuccess(exit)
984
+ ? 'completed'
985
+ : Cause.hasInterrupts(exit.cause)
986
+ ? 'interrupted'
987
+ : Cause.hasDies(exit.cause)
988
+ ? 'defect'
989
+ : 'failed',
990
+ calls,
991
+ }),
992
+ ).pipe(Effect.provideContext(redactionServices))
993
+ }
994
+ })
995
+ ),
996
+ )
997
+ }).pipe(
998
+ Effect.scoped,
999
+ // Keep invocation authority innermost while restoring the declared handler services.
1000
+ Effect.provideService(ToolBroker, broker),
1001
+ Effect.updateContext((current: Context.Context<never>) => Context.merge(current, captured)),
1002
+ )
1003
+
1004
+ return yield* execution.pipe(
1005
+ Effect.catch((error) => failureEgress(error).pipe(Effect.flatMap(Effect.fail))),
1006
+ Effect.flatMap(successEgress),
1007
+ Effect.mapError((failure) => {
1008
+ if (calls.length === 0) return failure
1009
+
1010
+ const complete = CodeModeFailure.make({
1011
+ errorTag: failure.errorTag,
1012
+ message: failure.message,
1013
+ logs: failure.logs,
1014
+ ...(failure.thrown === undefined ? {} : { thrown: failure.thrown }),
1015
+ calls,
1016
+ omittedCalls: 0,
1017
+ })
1018
+
1019
+ if ((encodedJsonByteLength(complete) ?? Infinity) <= maxEgressBytes) return complete
1020
+
1021
+ // Evidence takes priority over logs and thrown values. Never silently omit calls.
1022
+ const base = {
1023
+ errorTag: failure.errorTag,
1024
+ message: truncateToUtf8Bytes(failure.message, Math.min(256, maxEgressBytes / 4)),
1025
+ logs: [],
1026
+ }
1027
+
1028
+ const kept: Array<ProgrammaticCallRecord> = []
1029
+
1030
+ for (const call of calls) {
1031
+ const candidate = CodeModeFailure.make({
1032
+ ...base,
1033
+ calls: [...kept, call],
1034
+ omittedCalls: calls.length - kept.length - 1,
1035
+ })
1036
+
1037
+ if ((encodedJsonByteLength(candidate) ?? Infinity) > maxEgressBytes) break
1038
+ kept.push(call)
1039
+ }
1040
+
1041
+ return CodeModeFailure.make({
1042
+ ...base,
1043
+ calls: kept,
1044
+ omittedCalls: calls.length - kept.length,
1045
+ })
1046
+ }),
1047
+ )
1048
+ })
1049
+
1050
+ return { [name]: invoke } as unknown as Toolkit.HandlersFrom<CodeModeTools<Name>>
1051
+ })
1052
+
1053
+ /**
1054
+ * TypeScript cannot unify the two spellings of the singleton Tool record
1055
+ * (`CodeModeTools<Name>` versus the toolkit's name-remapped form) over a
1056
+ * generic `Name`, nor reduce the deferred `Exclude` when `toLayer`
1057
+ * subtracts what `build` consumed; the assertions pin the layer to its
1058
+ * documented requirement surface and never bypass validation.
1059
+ */
1060
+ const handlers = outerToolkit.toLayer(
1061
+ build as unknown as Effect.Effect<
1062
+ Toolkit.HandlersFrom<Toolkit.ToolsByName<readonly [CodeModeTool<Name>]>>,
1063
+ never,
1064
+ | CodeExecutor
1065
+ | Tool.HandlersFor<CodeModeSelectedRecord<Namespaces>>
1066
+ | Tool.HandlerServices<
1067
+ CodeModeSelectedRecord<Namespaces>[keyof CodeModeSelectedRecord<Namespaces>]
1068
+ >
1069
+ | Exclude<RedactionRequirements, Scope.Scope>
1070
+ >,
1071
+ ) as unknown as Layer.Layer<
1072
+ Tool.HandlersFor<CodeModeTools<Name>>,
1073
+ never,
1074
+ CodeModeLayerRequirements<Namespaces, RedactionRequirements>
1075
+ >
1076
+
1077
+ if (declarations !== undefined) {
1078
+ return Object.freeze({
1079
+ name,
1080
+ description,
1081
+ declarations,
1082
+ describe,
1083
+ namespaces,
1084
+ limits,
1085
+ maxEgressBytes,
1086
+ tool,
1087
+ handlers,
1088
+ })
1089
+ }
1090
+
1091
+ return Object.freeze({
1092
+ name,
1093
+ description,
1094
+ get declarations() {
1095
+ return (declarations ??= renderDeclarations(methods))
1096
+ },
1097
+ describe,
1098
+ namespaces,
1099
+ limits,
1100
+ maxEgressBytes,
1101
+ tool,
1102
+ handlers,
1103
+ })
1104
+ }
1105
+
1106
+ /**
1107
+ * Fail-closed JSON boundary for broker outcomes: hostile values can throw
1108
+ * from trap getters during decode, and a value outside the JSON surface must
1109
+ * become a typed failure envelope — never a fabricated success.
1110
+ */
1111
+ const decodeBrokerJson = (value: unknown): Option.Option<Schema.Json> => {
1112
+ try {
1113
+ return Schema.decodeUnknownOption(Schema.Json)(value)
1114
+ } catch {
1115
+ return Option.none()
1116
+ }
1117
+ }
1118
+
1119
+ const brokerProtocolEnvelope: Schema.Json = {
1120
+ _tag: 'CodeModeProtocolError',
1121
+ message: 'The broker returned a value outside the JSON surface',
1122
+ }
1123
+
1124
+ // The engine annotation is imported under a local alias to keep the builder
1125
+ // readable next to Effect AI's own `Tool.Readonly` annotation.
1126
+ import { ToolExecutionClass as ToolExecutionClassAnnotation } from '../engine/DurableStep'
1127
+
1128
+ /** Code Mode builder namespace (capability spec §9.1). */
1129
+ export { make }