@smthrs/harness 0.0.0-stage → 1.0.0-rc.4

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 (476) hide show
  1. package/CHANGELOG.md +387 -0
  2. package/LICENSE +21 -0
  3. package/README.md +138 -2
  4. package/dist/cjs/AgentEvent.d.ts +3092 -0
  5. package/dist/cjs/AgentEvent.d.ts.map +1 -0
  6. package/dist/cjs/AgentEvent.js +1116 -0
  7. package/dist/cjs/AgentEvent.js.map +7 -0
  8. package/dist/cjs/CallLedger.d.ts +378 -0
  9. package/dist/cjs/CallLedger.d.ts.map +1 -0
  10. package/dist/cjs/CallLedger.js +240 -0
  11. package/dist/cjs/CallLedger.js.map +7 -0
  12. package/dist/cjs/Cell.d.ts +774 -0
  13. package/dist/cjs/Cell.d.ts.map +1 -0
  14. package/dist/cjs/Cell.js +431 -0
  15. package/dist/cjs/Cell.js.map +7 -0
  16. package/dist/cjs/CellCalls.d.ts +115 -0
  17. package/dist/cjs/CellCalls.d.ts.map +1 -0
  18. package/dist/cjs/CellCalls.js +98 -0
  19. package/dist/cjs/CellCalls.js.map +7 -0
  20. package/dist/cjs/CellHistory.d.ts +102 -0
  21. package/dist/cjs/CellHistory.d.ts.map +1 -0
  22. package/dist/cjs/CellHistory.js +54 -0
  23. package/dist/cjs/CellHistory.js.map +7 -0
  24. package/dist/cjs/CellTurn.d.ts +1071 -0
  25. package/dist/cjs/CellTurn.d.ts.map +1 -0
  26. package/dist/cjs/CellTurn.js +2618 -0
  27. package/dist/cjs/CellTurn.js.map +7 -0
  28. package/dist/cjs/CellValidation.d.ts +94 -0
  29. package/dist/cjs/CellValidation.d.ts.map +1 -0
  30. package/dist/cjs/CellValidation.js +218 -0
  31. package/dist/cjs/CellValidation.js.map +7 -0
  32. package/dist/cjs/Compaction.d.ts +158 -0
  33. package/dist/cjs/Compaction.d.ts.map +1 -0
  34. package/dist/cjs/Compaction.js +189 -0
  35. package/dist/cjs/Compaction.js.map +7 -0
  36. package/dist/cjs/CompletionClaim.d.ts +801 -0
  37. package/dist/cjs/CompletionClaim.d.ts.map +1 -0
  38. package/dist/cjs/CompletionClaim.js +303 -0
  39. package/dist/cjs/CompletionClaim.js.map +7 -0
  40. package/dist/cjs/ContextWindow.d.ts +435 -0
  41. package/dist/cjs/ContextWindow.d.ts.map +1 -0
  42. package/dist/cjs/ContextWindow.js +319 -0
  43. package/dist/cjs/ContextWindow.js.map +7 -0
  44. package/dist/cjs/EngineLike.d.ts +546 -0
  45. package/dist/cjs/EngineLike.d.ts.map +1 -0
  46. package/dist/cjs/EngineLike.js +114 -0
  47. package/dist/cjs/EngineLike.js.map +7 -0
  48. package/dist/cjs/ExternalTranscript.d.ts +349 -0
  49. package/dist/cjs/ExternalTranscript.d.ts.map +1 -0
  50. package/dist/cjs/ExternalTranscript.js +826 -0
  51. package/dist/cjs/ExternalTranscript.js.map +7 -0
  52. package/dist/cjs/FailedCall.d.ts +132 -0
  53. package/dist/cjs/FailedCall.d.ts.map +1 -0
  54. package/dist/cjs/FailedCall.js +53 -0
  55. package/dist/cjs/FailedCall.js.map +7 -0
  56. package/dist/cjs/FlowBinding.d.ts +289 -0
  57. package/dist/cjs/FlowBinding.d.ts.map +1 -0
  58. package/dist/cjs/FlowBinding.js +251 -0
  59. package/dist/cjs/FlowBinding.js.map +7 -0
  60. package/dist/cjs/HarnessError.d.ts +57 -0
  61. package/dist/cjs/HarnessError.d.ts.map +1 -0
  62. package/dist/cjs/HarnessError.js +75 -0
  63. package/dist/cjs/HarnessError.js.map +7 -0
  64. package/dist/cjs/Judgement.d.ts +289 -0
  65. package/dist/cjs/Judgement.d.ts.map +1 -0
  66. package/dist/cjs/Judgement.js +240 -0
  67. package/dist/cjs/Judgement.js.map +7 -0
  68. package/dist/cjs/Monitor.d.ts +374 -0
  69. package/dist/cjs/Monitor.d.ts.map +1 -0
  70. package/dist/cjs/Monitor.js +233 -0
  71. package/dist/cjs/Monitor.js.map +7 -0
  72. package/dist/cjs/NarrowedCheck.d.ts +523 -0
  73. package/dist/cjs/NarrowedCheck.d.ts.map +1 -0
  74. package/dist/cjs/NarrowedCheck.js +263 -0
  75. package/dist/cjs/NarrowedCheck.js.map +7 -0
  76. package/dist/cjs/Notifications.d.ts +42 -0
  77. package/dist/cjs/Notifications.d.ts.map +1 -0
  78. package/dist/cjs/Notifications.js +177 -0
  79. package/dist/cjs/Notifications.js.map +7 -0
  80. package/dist/cjs/Plan.d.ts +127 -0
  81. package/dist/cjs/Plan.d.ts.map +1 -0
  82. package/dist/cjs/Plan.js +77 -0
  83. package/dist/cjs/Plan.js.map +7 -0
  84. package/dist/cjs/QuickJSSandbox.d.ts +151 -0
  85. package/dist/cjs/QuickJSSandbox.d.ts.map +1 -0
  86. package/dist/cjs/QuickJSSandbox.js +987 -0
  87. package/dist/cjs/QuickJSSandbox.js.map +7 -0
  88. package/dist/cjs/Relevance.d.ts +213 -0
  89. package/dist/cjs/Relevance.d.ts.map +1 -0
  90. package/dist/cjs/Relevance.js +183 -0
  91. package/dist/cjs/Relevance.js.map +7 -0
  92. package/dist/cjs/Sandbox.d.ts +637 -0
  93. package/dist/cjs/Sandbox.d.ts.map +1 -0
  94. package/dist/cjs/Sandbox.js +260 -0
  95. package/dist/cjs/Sandbox.js.map +7 -0
  96. package/dist/cjs/Steering.d.ts +464 -0
  97. package/dist/cjs/Steering.d.ts.map +1 -0
  98. package/dist/cjs/Steering.js +153 -0
  99. package/dist/cjs/Steering.js.map +7 -0
  100. package/dist/cjs/StructuredOutput.d.ts +252 -0
  101. package/dist/cjs/StructuredOutput.d.ts.map +1 -0
  102. package/dist/cjs/StructuredOutput.js +266 -0
  103. package/dist/cjs/StructuredOutput.js.map +7 -0
  104. package/dist/cjs/Sufficiency.d.ts +195 -0
  105. package/dist/cjs/Sufficiency.d.ts.map +1 -0
  106. package/dist/cjs/Sufficiency.js +110 -0
  107. package/dist/cjs/Sufficiency.js.map +7 -0
  108. package/dist/cjs/Supervisor.d.ts +719 -0
  109. package/dist/cjs/Supervisor.d.ts.map +1 -0
  110. package/dist/cjs/Supervisor.js +313 -0
  111. package/dist/cjs/Supervisor.js.map +7 -0
  112. package/dist/cjs/Tokens.d.ts +86 -0
  113. package/dist/cjs/Tokens.d.ts.map +1 -0
  114. package/dist/cjs/Tokens.js +72 -0
  115. package/dist/cjs/Tokens.js.map +7 -0
  116. package/dist/cjs/Transcript.d.ts +171 -0
  117. package/dist/cjs/Transcript.d.ts.map +1 -0
  118. package/dist/cjs/Transcript.js +342 -0
  119. package/dist/cjs/Transcript.js.map +7 -0
  120. package/dist/cjs/TruncatedOutput.d.ts +186 -0
  121. package/dist/cjs/TruncatedOutput.d.ts.map +1 -0
  122. package/dist/cjs/TruncatedOutput.js +143 -0
  123. package/dist/cjs/TruncatedOutput.js.map +7 -0
  124. package/dist/cjs/UnmovedTree.d.ts +113 -0
  125. package/dist/cjs/UnmovedTree.d.ts.map +1 -0
  126. package/dist/cjs/UnmovedTree.js +38 -0
  127. package/dist/cjs/UnmovedTree.js.map +7 -0
  128. package/dist/cjs/UnresolvedFailure.d.ts +196 -0
  129. package/dist/cjs/UnresolvedFailure.d.ts.map +1 -0
  130. package/dist/cjs/UnresolvedFailure.js +77 -0
  131. package/dist/cjs/UnresolvedFailure.js.map +7 -0
  132. package/dist/cjs/VacuousVerification.d.ts +237 -0
  133. package/dist/cjs/VacuousVerification.d.ts.map +1 -0
  134. package/dist/cjs/VacuousVerification.js +91 -0
  135. package/dist/cjs/VacuousVerification.js.map +7 -0
  136. package/dist/cjs/VariablesPanel.d.ts +117 -0
  137. package/dist/cjs/VariablesPanel.d.ts.map +1 -0
  138. package/dist/cjs/VariablesPanel.js +108 -0
  139. package/dist/cjs/VariablesPanel.js.map +7 -0
  140. package/dist/cjs/index.d.ts +172 -0
  141. package/dist/cjs/index.d.ts.map +1 -0
  142. package/dist/cjs/index.js +99 -0
  143. package/dist/cjs/index.js.map +7 -0
  144. package/dist/cjs/internal/bytes.d.ts +36 -0
  145. package/dist/cjs/internal/bytes.d.ts.map +1 -0
  146. package/dist/cjs/internal/bytes.js +57 -0
  147. package/dist/cjs/internal/bytes.js.map +7 -0
  148. package/dist/cjs/internal/cellPrompt.d.ts +122 -0
  149. package/dist/cjs/internal/cellPrompt.d.ts.map +1 -0
  150. package/dist/cjs/internal/cellPrompt.js +146 -0
  151. package/dist/cjs/internal/cellPrompt.js.map +7 -0
  152. package/dist/cjs/internal/compactable.d.ts +44 -0
  153. package/dist/cjs/internal/compactable.d.ts.map +1 -0
  154. package/dist/cjs/internal/compactable.js +56 -0
  155. package/dist/cjs/internal/compactable.js.map +7 -0
  156. package/dist/cjs/internal/compactionMarks.d.ts +278 -0
  157. package/dist/cjs/internal/compactionMarks.d.ts.map +1 -0
  158. package/dist/cjs/internal/compactionMarks.js +212 -0
  159. package/dist/cjs/internal/compactionMarks.js.map +7 -0
  160. package/dist/cjs/internal/demandText.d.ts +95 -0
  161. package/dist/cjs/internal/demandText.d.ts.map +1 -0
  162. package/dist/cjs/internal/demandText.js +70 -0
  163. package/dist/cjs/internal/demandText.js.map +7 -0
  164. package/dist/cjs/internal/elide.d.ts +109 -0
  165. package/dist/cjs/internal/elide.d.ts.map +1 -0
  166. package/dist/cjs/internal/elide.js +59 -0
  167. package/dist/cjs/internal/elide.js.map +7 -0
  168. package/dist/cjs/internal/frame.d.ts +463 -0
  169. package/dist/cjs/internal/frame.d.ts.map +1 -0
  170. package/dist/cjs/internal/frame.js +514 -0
  171. package/dist/cjs/internal/frame.js.map +7 -0
  172. package/dist/cjs/internal/nonNegativeSafeInt.d.ts +20 -0
  173. package/dist/cjs/internal/nonNegativeSafeInt.d.ts.map +1 -0
  174. package/dist/cjs/internal/nonNegativeSafeInt.js +29 -0
  175. package/dist/cjs/internal/nonNegativeSafeInt.js.map +7 -0
  176. package/dist/cjs/internal/paidUsage.d.ts +52 -0
  177. package/dist/cjs/internal/paidUsage.d.ts.map +1 -0
  178. package/dist/cjs/internal/paidUsage.js +70 -0
  179. package/dist/cjs/internal/paidUsage.js.map +7 -0
  180. package/dist/cjs/internal/printChannel.d.ts +233 -0
  181. package/dist/cjs/internal/printChannel.d.ts.map +1 -0
  182. package/dist/cjs/internal/printChannel.js +165 -0
  183. package/dist/cjs/internal/printChannel.js.map +7 -0
  184. package/dist/cjs/internal/printsObservation.d.ts +26 -0
  185. package/dist/cjs/internal/printsObservation.d.ts.map +1 -0
  186. package/dist/cjs/internal/printsObservation.js +27 -0
  187. package/dist/cjs/internal/printsObservation.js.map +7 -0
  188. package/dist/cjs/internal/refusal.d.ts +40 -0
  189. package/dist/cjs/internal/refusal.d.ts.map +1 -0
  190. package/dist/cjs/internal/refusal.js +45 -0
  191. package/dist/cjs/internal/refusal.js.map +7 -0
  192. package/dist/cjs/internal/supervision.d.ts +174 -0
  193. package/dist/cjs/internal/supervision.d.ts.map +1 -0
  194. package/dist/cjs/internal/supervision.js +402 -0
  195. package/dist/cjs/internal/supervision.js.map +7 -0
  196. package/dist/cjs/internal/unfinishedWork.d.ts +99 -0
  197. package/dist/cjs/internal/unfinishedWork.d.ts.map +1 -0
  198. package/dist/cjs/internal/unfinishedWork.js +80 -0
  199. package/dist/cjs/internal/unfinishedWork.js.map +7 -0
  200. package/dist/cjs/internal/unobservedCall.d.ts +112 -0
  201. package/dist/cjs/internal/unobservedCall.d.ts.map +1 -0
  202. package/dist/cjs/internal/unobservedCall.js +345 -0
  203. package/dist/cjs/internal/unobservedCall.js.map +7 -0
  204. package/dist/cjs/internal/untrustedData.d.ts +14 -0
  205. package/dist/cjs/internal/untrustedData.d.ts.map +1 -0
  206. package/dist/cjs/internal/untrustedData.js +30 -0
  207. package/dist/cjs/internal/untrustedData.js.map +7 -0
  208. package/dist/cjs/package.json +1 -0
  209. package/dist/esm/AgentEvent.d.ts +3092 -0
  210. package/dist/esm/AgentEvent.d.ts.map +1 -0
  211. package/dist/esm/AgentEvent.js +1610 -0
  212. package/dist/esm/AgentEvent.js.map +1 -0
  213. package/dist/esm/CallLedger.d.ts +378 -0
  214. package/dist/esm/CallLedger.d.ts.map +1 -0
  215. package/dist/esm/CallLedger.js +506 -0
  216. package/dist/esm/CallLedger.js.map +1 -0
  217. package/dist/esm/Cell.d.ts +774 -0
  218. package/dist/esm/Cell.d.ts.map +1 -0
  219. package/dist/esm/Cell.js +772 -0
  220. package/dist/esm/Cell.js.map +1 -0
  221. package/dist/esm/CellCalls.d.ts +115 -0
  222. package/dist/esm/CellCalls.d.ts.map +1 -0
  223. package/dist/esm/CellCalls.js +97 -0
  224. package/dist/esm/CellCalls.js.map +1 -0
  225. package/dist/esm/CellHistory.d.ts +102 -0
  226. package/dist/esm/CellHistory.d.ts.map +1 -0
  227. package/dist/esm/CellHistory.js +91 -0
  228. package/dist/esm/CellHistory.js.map +1 -0
  229. package/dist/esm/CellTurn.d.ts +1071 -0
  230. package/dist/esm/CellTurn.d.ts.map +1 -0
  231. package/dist/esm/CellTurn.js +3410 -0
  232. package/dist/esm/CellTurn.js.map +1 -0
  233. package/dist/esm/CellValidation.d.ts +94 -0
  234. package/dist/esm/CellValidation.d.ts.map +1 -0
  235. package/dist/esm/CellValidation.js +335 -0
  236. package/dist/esm/CellValidation.js.map +1 -0
  237. package/dist/esm/Compaction.d.ts +158 -0
  238. package/dist/esm/Compaction.d.ts.map +1 -0
  239. package/dist/esm/Compaction.js +216 -0
  240. package/dist/esm/Compaction.js.map +1 -0
  241. package/dist/esm/CompletionClaim.d.ts +801 -0
  242. package/dist/esm/CompletionClaim.d.ts.map +1 -0
  243. package/dist/esm/CompletionClaim.js +833 -0
  244. package/dist/esm/CompletionClaim.js.map +1 -0
  245. package/dist/esm/ContextWindow.d.ts +435 -0
  246. package/dist/esm/ContextWindow.d.ts.map +1 -0
  247. package/dist/esm/ContextWindow.js +427 -0
  248. package/dist/esm/ContextWindow.js.map +1 -0
  249. package/dist/esm/EngineLike.d.ts +546 -0
  250. package/dist/esm/EngineLike.d.ts.map +1 -0
  251. package/dist/esm/EngineLike.js +218 -0
  252. package/dist/esm/EngineLike.js.map +1 -0
  253. package/dist/esm/ExternalTranscript.d.ts +349 -0
  254. package/dist/esm/ExternalTranscript.d.ts.map +1 -0
  255. package/dist/esm/ExternalTranscript.js +985 -0
  256. package/dist/esm/ExternalTranscript.js.map +1 -0
  257. package/dist/esm/FailedCall.d.ts +132 -0
  258. package/dist/esm/FailedCall.d.ts.map +1 -0
  259. package/dist/esm/FailedCall.js +131 -0
  260. package/dist/esm/FailedCall.js.map +1 -0
  261. package/dist/esm/FlowBinding.d.ts +289 -0
  262. package/dist/esm/FlowBinding.d.ts.map +1 -0
  263. package/dist/esm/FlowBinding.js +376 -0
  264. package/dist/esm/FlowBinding.js.map +1 -0
  265. package/dist/esm/HarnessError.d.ts +57 -0
  266. package/dist/esm/HarnessError.d.ts.map +1 -0
  267. package/dist/esm/HarnessError.js +85 -0
  268. package/dist/esm/HarnessError.js.map +1 -0
  269. package/dist/esm/Judgement.d.ts +289 -0
  270. package/dist/esm/Judgement.d.ts.map +1 -0
  271. package/dist/esm/Judgement.js +305 -0
  272. package/dist/esm/Judgement.js.map +1 -0
  273. package/dist/esm/Monitor.d.ts +374 -0
  274. package/dist/esm/Monitor.d.ts.map +1 -0
  275. package/dist/esm/Monitor.js +370 -0
  276. package/dist/esm/Monitor.js.map +1 -0
  277. package/dist/esm/NarrowedCheck.d.ts +523 -0
  278. package/dist/esm/NarrowedCheck.d.ts.map +1 -0
  279. package/dist/esm/NarrowedCheck.js +612 -0
  280. package/dist/esm/NarrowedCheck.js.map +1 -0
  281. package/dist/esm/Notifications.d.ts +42 -0
  282. package/dist/esm/Notifications.d.ts.map +1 -0
  283. package/dist/esm/Notifications.js +215 -0
  284. package/dist/esm/Notifications.js.map +1 -0
  285. package/dist/esm/Plan.d.ts +127 -0
  286. package/dist/esm/Plan.d.ts.map +1 -0
  287. package/dist/esm/Plan.js +97 -0
  288. package/dist/esm/Plan.js.map +1 -0
  289. package/dist/esm/QuickJSSandbox.d.ts +151 -0
  290. package/dist/esm/QuickJSSandbox.d.ts.map +1 -0
  291. package/dist/esm/QuickJSSandbox.js +1364 -0
  292. package/dist/esm/QuickJSSandbox.js.map +1 -0
  293. package/dist/esm/Relevance.d.ts +213 -0
  294. package/dist/esm/Relevance.d.ts.map +1 -0
  295. package/dist/esm/Relevance.js +254 -0
  296. package/dist/esm/Relevance.js.map +1 -0
  297. package/dist/esm/Sandbox.d.ts +637 -0
  298. package/dist/esm/Sandbox.d.ts.map +1 -0
  299. package/dist/esm/Sandbox.js +464 -0
  300. package/dist/esm/Sandbox.js.map +1 -0
  301. package/dist/esm/Steering.d.ts +464 -0
  302. package/dist/esm/Steering.d.ts.map +1 -0
  303. package/dist/esm/Steering.js +193 -0
  304. package/dist/esm/Steering.js.map +1 -0
  305. package/dist/esm/StructuredOutput.d.ts +252 -0
  306. package/dist/esm/StructuredOutput.d.ts.map +1 -0
  307. package/dist/esm/StructuredOutput.js +430 -0
  308. package/dist/esm/StructuredOutput.js.map +1 -0
  309. package/dist/esm/Sufficiency.d.ts +195 -0
  310. package/dist/esm/Sufficiency.d.ts.map +1 -0
  311. package/dist/esm/Sufficiency.js +207 -0
  312. package/dist/esm/Sufficiency.js.map +1 -0
  313. package/dist/esm/Supervisor.d.ts +719 -0
  314. package/dist/esm/Supervisor.d.ts.map +1 -0
  315. package/dist/esm/Supervisor.js +575 -0
  316. package/dist/esm/Supervisor.js.map +1 -0
  317. package/dist/esm/Tokens.d.ts +86 -0
  318. package/dist/esm/Tokens.d.ts.map +1 -0
  319. package/dist/esm/Tokens.js +92 -0
  320. package/dist/esm/Tokens.js.map +1 -0
  321. package/dist/esm/Transcript.d.ts +171 -0
  322. package/dist/esm/Transcript.d.ts.map +1 -0
  323. package/dist/esm/Transcript.js +424 -0
  324. package/dist/esm/Transcript.js.map +1 -0
  325. package/dist/esm/TruncatedOutput.d.ts +186 -0
  326. package/dist/esm/TruncatedOutput.d.ts.map +1 -0
  327. package/dist/esm/TruncatedOutput.js +257 -0
  328. package/dist/esm/TruncatedOutput.js.map +1 -0
  329. package/dist/esm/UnmovedTree.d.ts +113 -0
  330. package/dist/esm/UnmovedTree.d.ts.map +1 -0
  331. package/dist/esm/UnmovedTree.js +90 -0
  332. package/dist/esm/UnmovedTree.js.map +1 -0
  333. package/dist/esm/UnresolvedFailure.d.ts +196 -0
  334. package/dist/esm/UnresolvedFailure.d.ts.map +1 -0
  335. package/dist/esm/UnresolvedFailure.js +218 -0
  336. package/dist/esm/UnresolvedFailure.js.map +1 -0
  337. package/dist/esm/VacuousVerification.d.ts +237 -0
  338. package/dist/esm/VacuousVerification.d.ts.map +1 -0
  339. package/dist/esm/VacuousVerification.js +245 -0
  340. package/dist/esm/VacuousVerification.js.map +1 -0
  341. package/dist/esm/VariablesPanel.d.ts +117 -0
  342. package/dist/esm/VariablesPanel.d.ts.map +1 -0
  343. package/dist/esm/VariablesPanel.js +142 -0
  344. package/dist/esm/VariablesPanel.js.map +1 -0
  345. package/dist/esm/index.d.ts +172 -0
  346. package/dist/esm/index.d.ts.map +1 -0
  347. package/dist/esm/index.js +172 -0
  348. package/dist/esm/index.js.map +1 -0
  349. package/dist/esm/internal/bytes.d.ts +36 -0
  350. package/dist/esm/internal/bytes.d.ts.map +1 -0
  351. package/dist/esm/internal/bytes.js +70 -0
  352. package/dist/esm/internal/bytes.js.map +1 -0
  353. package/dist/esm/internal/cellPrompt.d.ts +122 -0
  354. package/dist/esm/internal/cellPrompt.d.ts.map +1 -0
  355. package/dist/esm/internal/cellPrompt.js +276 -0
  356. package/dist/esm/internal/cellPrompt.js.map +1 -0
  357. package/dist/esm/internal/compactable.d.ts +44 -0
  358. package/dist/esm/internal/compactable.d.ts.map +1 -0
  359. package/dist/esm/internal/compactable.js +71 -0
  360. package/dist/esm/internal/compactable.js.map +1 -0
  361. package/dist/esm/internal/compactionMarks.d.ts +278 -0
  362. package/dist/esm/internal/compactionMarks.d.ts.map +1 -0
  363. package/dist/esm/internal/compactionMarks.js +317 -0
  364. package/dist/esm/internal/compactionMarks.js.map +1 -0
  365. package/dist/esm/internal/demandText.d.ts +95 -0
  366. package/dist/esm/internal/demandText.d.ts.map +1 -0
  367. package/dist/esm/internal/demandText.js +128 -0
  368. package/dist/esm/internal/demandText.js.map +1 -0
  369. package/dist/esm/internal/elide.d.ts +109 -0
  370. package/dist/esm/internal/elide.d.ts.map +1 -0
  371. package/dist/esm/internal/elide.js +123 -0
  372. package/dist/esm/internal/elide.js.map +1 -0
  373. package/dist/esm/internal/frame.d.ts +463 -0
  374. package/dist/esm/internal/frame.d.ts.map +1 -0
  375. package/dist/esm/internal/frame.js +861 -0
  376. package/dist/esm/internal/frame.js.map +1 -0
  377. package/dist/esm/internal/nonNegativeSafeInt.d.ts +20 -0
  378. package/dist/esm/internal/nonNegativeSafeInt.d.ts.map +1 -0
  379. package/dist/esm/internal/nonNegativeSafeInt.js +20 -0
  380. package/dist/esm/internal/nonNegativeSafeInt.js.map +1 -0
  381. package/dist/esm/internal/paidUsage.d.ts +52 -0
  382. package/dist/esm/internal/paidUsage.d.ts.map +1 -0
  383. package/dist/esm/internal/paidUsage.js +72 -0
  384. package/dist/esm/internal/paidUsage.js.map +1 -0
  385. package/dist/esm/internal/printChannel.d.ts +233 -0
  386. package/dist/esm/internal/printChannel.d.ts.map +1 -0
  387. package/dist/esm/internal/printChannel.js +376 -0
  388. package/dist/esm/internal/printChannel.js.map +1 -0
  389. package/dist/esm/internal/printsObservation.d.ts +26 -0
  390. package/dist/esm/internal/printsObservation.d.ts.map +1 -0
  391. package/dist/esm/internal/printsObservation.js +29 -0
  392. package/dist/esm/internal/printsObservation.js.map +1 -0
  393. package/dist/esm/internal/refusal.d.ts +40 -0
  394. package/dist/esm/internal/refusal.d.ts.map +1 -0
  395. package/dist/esm/internal/refusal.js +47 -0
  396. package/dist/esm/internal/refusal.js.map +1 -0
  397. package/dist/esm/internal/supervision.d.ts +174 -0
  398. package/dist/esm/internal/supervision.d.ts.map +1 -0
  399. package/dist/esm/internal/supervision.js +485 -0
  400. package/dist/esm/internal/supervision.js.map +1 -0
  401. package/dist/esm/internal/unfinishedWork.d.ts +99 -0
  402. package/dist/esm/internal/unfinishedWork.d.ts.map +1 -0
  403. package/dist/esm/internal/unfinishedWork.js +85 -0
  404. package/dist/esm/internal/unfinishedWork.js.map +1 -0
  405. package/dist/esm/internal/unobservedCall.d.ts +112 -0
  406. package/dist/esm/internal/unobservedCall.d.ts.map +1 -0
  407. package/dist/esm/internal/unobservedCall.js +501 -0
  408. package/dist/esm/internal/unobservedCall.js.map +1 -0
  409. package/dist/esm/internal/untrustedData.d.ts +14 -0
  410. package/dist/esm/internal/untrustedData.d.ts.map +1 -0
  411. package/dist/esm/internal/untrustedData.js +15 -0
  412. package/dist/esm/internal/untrustedData.js.map +1 -0
  413. package/docs/README.md +129 -0
  414. package/docs/api.md +1869 -0
  415. package/docs/concepts.md +238 -0
  416. package/docs/external-transcripts.md +245 -0
  417. package/docs/guides/bind-flows.md +167 -0
  418. package/docs/guides/drive-the-loop.md +265 -0
  419. package/docs/guides/run-cells.md +262 -0
  420. package/docs/guides/workerd.md +144 -0
  421. package/docs/installation.md +69 -0
  422. package/docs/quickstart.md +121 -0
  423. package/docs/reference.md +954 -0
  424. package/docs/troubleshooting.md +177 -0
  425. package/package.json +463 -3
  426. package/src/AgentEvent.ts +1772 -0
  427. package/src/CallLedger.ts +560 -0
  428. package/src/Cell.ts +926 -0
  429. package/src/CellCalls.ts +198 -0
  430. package/src/CellHistory.ts +128 -0
  431. package/src/CellTurn.ts +4450 -0
  432. package/src/CellValidation.ts +382 -0
  433. package/src/Compaction.ts +330 -0
  434. package/src/CompletionClaim.ts +1013 -0
  435. package/src/ContextWindow.ts +669 -0
  436. package/src/EngineLike.ts +614 -0
  437. package/src/ExternalTranscript.ts +1142 -0
  438. package/src/FailedCall.ts +163 -0
  439. package/src/FlowBinding.ts +603 -0
  440. package/src/HarnessError.ts +98 -0
  441. package/src/Judgement.ts +526 -0
  442. package/src/Monitor.ts +579 -0
  443. package/src/NarrowedCheck.ts +694 -0
  444. package/src/Notifications.ts +262 -0
  445. package/src/Plan.ts +113 -0
  446. package/src/QuickJSSandbox.ts +1557 -0
  447. package/src/Relevance.ts +352 -0
  448. package/src/Sandbox.ts +908 -0
  449. package/src/Steering.ts +405 -0
  450. package/src/StructuredOutput.ts +484 -0
  451. package/src/Sufficiency.ts +247 -0
  452. package/src/Supervisor.ts +798 -0
  453. package/src/Tokens.ts +108 -0
  454. package/src/Transcript.ts +513 -0
  455. package/src/TruncatedOutput.ts +297 -0
  456. package/src/UnmovedTree.ts +121 -0
  457. package/src/UnresolvedFailure.ts +240 -0
  458. package/src/VacuousVerification.ts +280 -0
  459. package/src/VariablesPanel.ts +165 -0
  460. package/src/index.ts +204 -0
  461. package/src/internal/bytes.ts +70 -0
  462. package/src/internal/cellPrompt.ts +337 -0
  463. package/src/internal/compactable.ts +76 -0
  464. package/src/internal/compactionMarks.ts +454 -0
  465. package/src/internal/demandText.ts +145 -0
  466. package/src/internal/elide.ts +130 -0
  467. package/src/internal/frame.ts +1178 -0
  468. package/src/internal/nonNegativeSafeInt.ts +24 -0
  469. package/src/internal/paidUsage.ts +90 -0
  470. package/src/internal/printChannel.ts +434 -0
  471. package/src/internal/printsObservation.ts +31 -0
  472. package/src/internal/refusal.ts +53 -0
  473. package/src/internal/supervision.ts +652 -0
  474. package/src/internal/unfinishedWork.ts +123 -0
  475. package/src/internal/unobservedCall.ts +536 -0
  476. package/src/internal/untrustedData.ts +19 -0
@@ -0,0 +1,987 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var QuickJSSandbox_exports = {};
30
+ __export(QuickJSSandbox_exports, {
31
+ ComputeClock: () => ComputeClock,
32
+ Variant: () => Variant,
33
+ cacheSuccessful: () => cacheSuccessful,
34
+ layer: () => layer,
35
+ layerClockLive: () => layerClockLive,
36
+ layerVariant: () => layerVariant,
37
+ layerVariantLive: () => layerVariantLive,
38
+ layerWithVariant: () => layerWithVariant,
39
+ loadModule: () => loadModule,
40
+ make: () => make,
41
+ makeWithClock: () => makeWithClock,
42
+ makeWithVariant: () => makeWithVariant
43
+ });
44
+ module.exports = __toCommonJS(QuickJSSandbox_exports);
45
+ var import_quickjs_singlefile_browser_release_sync = __toESM(require("@jitl/quickjs-singlefile-browser-release-sync"), 1);
46
+ var import_effect = require("effect");
47
+ var import_quickjs_emscripten_core = require("quickjs-emscripten-core");
48
+ var Cell = __toESM(require("./Cell.js"), 1);
49
+ var bytes = __toESM(require("./internal/bytes.js"), 1);
50
+ var elide = __toESM(require("./internal/elide.js"), 1);
51
+ var printChannel = __toESM(require("./internal/printChannel.js"), 1);
52
+ var import_refusal = require("./internal/refusal.js");
53
+ var Sandbox = __toESM(require("./Sandbox.js"), 1);
54
+ var VariablesPanel = __toESM(require("./VariablesPanel.js"), 1);
55
+ const preludeIntrinsics = ` var keysOf = Object.keys
56
+ var freezeValue = Object.freeze
57
+ var prototypeOf = Object.getPrototypeOf
58
+ var objectPrototype = Object.prototype
59
+ var define = Object.defineProperty
60
+ var isArray = Array.isArray
61
+ var stringify = JSON.stringify
62
+ var parse = JSON.parse
63
+ var finite = Number.isFinite
64
+ var render = String
65
+ var Fault = TypeError
66
+ var Deferred = Promise
67
+ var argumentsOf = Array.prototype.slice`;
68
+ const preludeHelpers = `${preludeIntrinsics}
69
+ var freeze = function (value) {
70
+ if (value !== null && typeof value === "object") {
71
+ keysOf(value).forEach(function (key) { freeze(value[key]) })
72
+ freezeValue(value)
73
+ }
74
+ return value
75
+ }
76
+ var encode = function (label, input) {
77
+ var seen = []
78
+ var visit = function (value) {
79
+ if (value === null || typeof value === "string" || typeof value === "boolean") return
80
+ if (typeof value === "number" && finite(value)) return
81
+ if (typeof value !== "object") throw new Fault(label + " must be JSON-serializable")
82
+ if (seen.indexOf(value) >= 0) throw new Fault(label + " must be JSON-serializable")
83
+ var prototype = prototypeOf(value)
84
+ if (!isArray(value) && prototype !== objectPrototype && prototype !== null) {
85
+ throw new Fault(label + " must be JSON-serializable")
86
+ }
87
+ seen.push(value)
88
+ keysOf(value).forEach(function (key) { visit(value[key]) })
89
+ seen.pop()
90
+ }
91
+ visit(input)
92
+ return stringify(input)
93
+ }
94
+ var settleEnvelope = function (settled) {
95
+ // A failed call RESOLVES with the failure envelope; only teardown throws.
96
+ // See Cell.callFailure for why.
97
+ if (settled.ok) return settled.value
98
+ if (settled.aborted) throw new Error(settled.failure.error.message)
99
+ return settled.failure
100
+ }
101
+ var dispatch = function (flow, input, at) { return bridge(flow, input, at).then(settleEnvelope) }
102
+ // The at option is whatever the cell wrote, so it is encoded defensively
103
+ // rather than strictly: a value JSON cannot hold travels as null and the
104
+ // boundary answers it as an ordinary invalid_input, instead of throwing out
105
+ // of a cell that has already paid for the calls before this line.
106
+ var encodeAt = function (value) {
107
+ try { return encode("ctx.call at", value === undefined ? null : value) } catch (error) { return "null" }
108
+ }`;
109
+ const baseHandle = Cell.checkpoint(Cell.baseCheckpoint);
110
+ const checkpointFlow = "checkpoint";
111
+ const decodedAt = (encoded) => encoded === "" ? void 0 : import_effect.Schema.decodeUnknownSync(import_effect.Schema.Json)(JSON.parse(encoded));
112
+ const preludeCall = (guard) => ` call: function (flow, input, options) {
113
+ if (typeof flow !== "string") return Deferred.reject(new Fault("ctx.call expects a flow name as its first argument"))
114
+ ${guard} var encoded = encode("ctx.call input", input === undefined ? null : input)
115
+ var at = options === null || typeof options !== "object" ? undefined : options.at
116
+ if (at === undefined) return dispatch(flow, encoded, "")
117
+ // A handle the cell never awaited is a promise, and that spelling is the
118
+ // one the ruling wrote: \`const cp = ctx.checkpoint()\`. The pin lands where
119
+ // that line is, because the queue settles in issue order, so awaiting the
120
+ // handle later cannot move the tree it names. Both spellings are accepted.
121
+ if (at !== null && typeof at === "object" && typeof at.then === "function") {
122
+ return at.then(function (resolved) { return dispatch(flow, encoded, encodeAt(resolved)) })
123
+ }
124
+ return dispatch(flow, encoded, encodeAt(at))
125
+ },
126
+ checkpoint: function () {
127
+ ${guard} return pin().then(settleEnvelope)
128
+ },
129
+ base: freeze(parse(${JSON.stringify(JSON.stringify(baseHandle))})),`;
130
+ const sealedCall = Cell.callFailure(
131
+ (0, import_refusal.refusal)(
132
+ "run_completed",
133
+ "This run was already completed: an earlier line of this cell called ctx.done or ctx.park, which takes effect where it is called, so no further flow call is dispatched."
134
+ )
135
+ );
136
+ const replPrelude = (catalog) => `(function () {
137
+ var bridge = globalThis.__call
138
+ var pin = globalThis.__checkpoint
139
+ var print = globalThis.__print
140
+ var intent = globalThis.__intent
141
+ ${preludeHelpers}
142
+ delete globalThis.__call
143
+ delete globalThis.__checkpoint
144
+ delete globalThis.__print
145
+ delete globalThis.__intent
146
+ delete globalThis.Date
147
+ delete Math.random
148
+ // Removed for the same reason as the two above: it makes the realm answer a
149
+ // question dishonestly. Every reading the panel probe takes goes through the
150
+ // intrinsics captured before any cell ran, and every property comes off its
151
+ // own descriptor, so a cell can neither rebind reflection nor hide weight
152
+ // behind a getter. Neither defence survives a value that IS the trap: a proxy
153
+ // answers \`getOwnPropertyNames\` from its handler, so one wrapping a
154
+ // megabyte-wide target weighs as an empty object while the realm holds the
155
+ // target alive, and the run's only ceiling over string data reads zero for it.
156
+ // No reading of a proxy can be trusted \u2014 any number it reports is a number the
157
+ // handler chose \u2014 and nothing else in this realm can construct one, so the
158
+ // constructor goes rather than the accounting. \`Reflect\` stays: it offers no
159
+ // way to make a proxy and the probe does not read through it.
160
+ delete globalThis.Proxy
161
+ // The seal: once this frame has said how the run ends, it has ended, and the
162
+ // calls a cell would have made after that line are not dispatched. It lives
163
+ // here rather than on the host because ctx.call has to answer synchronously,
164
+ // and it is cleared per frame by the function this prelude returns \u2014 a park
165
+ // whose reason is refused is asked again inside the same frame, and a realm
166
+ // still sealed from the refused attempt would answer that retry with nothing.
167
+ var catalog = freeze(${catalog})
168
+ var sealed = null
169
+ var sealedEnvelope = freeze(parse(${JSON.stringify(JSON.stringify(sealedCall))}))
170
+ var unprintable = function (value, error) {
171
+ var kind = isArray(value) ? "array" : typeof value
172
+ var why = error !== null && typeof error === "object" && error.message ? error.message : render(error)
173
+ return "[unprintable " + kind + ": " + why + " \u2014 the value is still bound, so print the part of it you need]"
174
+ }
175
+ var show = function (values) {
176
+ var parts = []
177
+ for (var index = 0; index < values.length; index++) {
178
+ var value = values[index]
179
+ if (typeof value === "string") parts.push({ text: value })
180
+ else if (value === undefined) parts.push({ text: "undefined" })
181
+ else {
182
+ var encoded = null
183
+ var refused = false
184
+ try { encoded = stringify(value) } catch (error) { refused = true; parts.push({ text: unprintable(value, error) }) }
185
+ // JSON answers \`undefined\` rather than throwing for a value it has no
186
+ // notation for at all \u2014 a function, a symbol \u2014 and those read best as
187
+ // themselves. It throws only for a value it cannot walk, and that is
188
+ // the one case where naming the reason beats printing "[object Object]".
189
+ if (!refused) parts.push(encoded === undefined ? { text: render(value) } : { json: parse(encoded) })
190
+ }
191
+ }
192
+ print(stringify(parts))
193
+ }
194
+ var line = function () { show(argumentsOf.call(arguments)) }
195
+ var host = function (name, value) {
196
+ define(globalThis, name, { value: value, writable: false, enumerable: true, configurable: false })
197
+ }
198
+ host("console", freezeValue({ log: line, info: line, warn: line, error: line }))
199
+ host("ctx", freezeValue({
200
+ ${preludeCall(` if (sealed !== null) return Deferred.resolve(sealed)
201
+ `)}
202
+ get flows() { return catalog },
203
+ done: function (output) {
204
+ if (sealed !== null) return
205
+ if (arguments.length === 0) {
206
+ throw new Fault("ctx.done(output) takes the run's answer; call it with the value the task asked for")
207
+ }
208
+ var encoded = encode("ctx.done output", output === undefined ? null : output)
209
+ sealed = sealedEnvelope
210
+ intent("done", encoded)
211
+ },
212
+ park: function (reason, message) {
213
+ if (sealed !== null) return
214
+ var encoded = encode("ctx.park message", { reason: reason === undefined ? null : reason, message: message === undefined ? "" : message })
215
+ sealed = sealedEnvelope
216
+ intent("park", encoded)
217
+ },
218
+ justify: function (text) { intent("justify", encode("ctx.justify text", text === undefined ? "" : text)) }
219
+ }))
220
+ // Handed back to the host, which calls it as each frame opens. See the seal
221
+ // above for why the clearing is per frame rather than per run.
222
+ return function (nextCatalog) {
223
+ sealed = null
224
+ if (nextCatalog !== undefined) catalog = freeze(parse(nextCatalog))
225
+ }
226
+ })()`;
227
+ const Catalog = import_effect.Schema.Record(import_effect.Schema.String, Cell.FlowProjection);
228
+ const catalogOf = (flows) => {
229
+ const encoded = import_effect.Schema.encodeSync(Catalog)(flows);
230
+ const normalized = Object.fromEntries(
231
+ Object.entries(encoded).map(([name, projection]) => [
232
+ name,
233
+ Object.fromEntries(
234
+ Object.entries(projection).flatMap(
235
+ ([field, value]) => import_effect.Option.isOption(value) ? import_effect.Option.isSome(value) ? [[field, value.value]] : [] : [[field, value]]
236
+ )
237
+ )
238
+ ])
239
+ );
240
+ return JSON.stringify(normalized);
241
+ };
242
+ const raisedFrom = (dumped) => {
243
+ if (typeof dumped === "object" && dumped !== null) {
244
+ const record = dumped;
245
+ return new Cell.Raised({
246
+ name: typeof record.name === "string" ? record.name : "Error",
247
+ // Never `String(object)`: a cell that threw a structured value is told
248
+ // what it threw. See `Sandbox` `describe`.
249
+ message: typeof record.message === "string" ? record.message : Sandbox.raisedOutcome(dumped).message
250
+ });
251
+ }
252
+ return new Cell.Raised({ name: "Error", message: String(dumped) });
253
+ };
254
+ const handleFromJson = (context, defineDataProperty, value, depth = 0) => {
255
+ if (value === null) return context.null;
256
+ switch (typeof value) {
257
+ case "boolean":
258
+ return value ? context.true : context.false;
259
+ case "number":
260
+ return context.newNumber(value);
261
+ case "string":
262
+ return context.newString(value);
263
+ }
264
+ if (depth >= 128) throw new Error("The flow result exceeds 128 levels of JSON nesting");
265
+ const container = Array.isArray(value) ? context.newArray() : context.newObject();
266
+ try {
267
+ for (const [key, item] of Object.entries(value)) {
268
+ const child = handleFromJson(context, defineDataProperty, item, depth + 1);
269
+ try {
270
+ const property = context.newString(key);
271
+ try {
272
+ context.unwrapResult(
273
+ context.callFunction(defineDataProperty, context.undefined, container, property, child)
274
+ ).dispose();
275
+ } finally {
276
+ property.dispose();
277
+ }
278
+ } finally {
279
+ child.dispose();
280
+ }
281
+ }
282
+ return container;
283
+ } catch (error) {
284
+ container.dispose();
285
+ throw error;
286
+ }
287
+ };
288
+ const cacheSuccessful = (load) => {
289
+ let loaded;
290
+ return () => {
291
+ if (loaded === void 0) {
292
+ const pending = load();
293
+ loaded = pending;
294
+ void pending.catch(() => {
295
+ loaded = void 0;
296
+ });
297
+ }
298
+ return loaded;
299
+ };
300
+ };
301
+ class Variant extends import_effect.Context.Service()(
302
+ "@smthrs/harness/QuickJSSandbox/Variant"
303
+ ) {
304
+ }
305
+ const layerVariantLive = import_effect.Layer.succeed(Variant)({ variant: import_quickjs_singlefile_browser_release_sync.default });
306
+ const layerVariant = (variant) => import_effect.Layer.succeed(Variant)({ variant });
307
+ const compiled = /* @__PURE__ */ new WeakMap();
308
+ const loaderFor = (variant) => {
309
+ const known = compiled.get(variant);
310
+ if (known !== void 0) return known;
311
+ const loader = cacheSuccessful(() => (0, import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(variant));
312
+ compiled.set(variant, loader);
313
+ return loader;
314
+ };
315
+ class ComputeClock extends import_effect.Context.Service()(
316
+ "@smthrs/harness/QuickJSSandbox/ComputeClock"
317
+ ) {
318
+ }
319
+ const layerClockLive = import_effect.Layer.succeed(ComputeClock)({ now: () => Date.now() });
320
+ const capabilities = {
321
+ calls: true,
322
+ memoryBytes: true,
323
+ steps: true,
324
+ timeMs: true
325
+ };
326
+ const timeLimitExceeded = (timeMs) => new Cell.Rejected({
327
+ code: "limit_exceeded",
328
+ message: `This cell exceeded its wall-clock limit of ${timeMs} milliseconds`
329
+ });
330
+ const parkReasons = ["waiting-input", "waiting-event", "waiting-quota"];
331
+ const parkPayload = import_effect.Schema.decodeUnknownSync(
332
+ import_effect.Schema.Struct({ reason: import_effect.Schema.Json, message: import_effect.Schema.Json })
333
+ );
334
+ const printParts = import_effect.Schema.decodeUnknownSync(
335
+ import_effect.Schema.Array(
336
+ import_effect.Schema.Union([
337
+ import_effect.Schema.Struct({ text: import_effect.Schema.String }),
338
+ import_effect.Schema.Struct({ json: import_effect.Schema.Json })
339
+ ])
340
+ )
341
+ );
342
+ const printed = (encoded) => {
343
+ const parts = printParts(JSON.parse(encoded));
344
+ const rendered = parts.map((part) => "text" in part ? part.text : printChannel.render(part.json));
345
+ const whole = rendered.reduce(
346
+ (joined, part, index) => index === 0 ? part : joined + (part.includes("\n") || rendered[index - 1].includes("\n") ? "\n" : " ") + part,
347
+ ""
348
+ );
349
+ const wholeBytes = bytes.size(whole);
350
+ if (wholeBytes <= Sandbox.printFrameBytes) return { text: whole, bytes: wholeBytes };
351
+ const edge = Math.floor(Sandbox.printFrameBytes / 2);
352
+ return {
353
+ text: `${elide.headSlice(whole, edge)}${elide.tailSlice(whole, edge)}`,
354
+ bytes: wholeBytes
355
+ };
356
+ };
357
+ const replOutcome = (recorded, justification) => {
358
+ if (recorded !== void 0 && recorded.kind === "park") {
359
+ const reason = parkReasons.find((candidate) => candidate === recorded.reason);
360
+ if (reason === void 0) {
361
+ return new Cell.Rejected({
362
+ code: "invalid_transition",
363
+ message: `ctx.park was called with reason ${JSON.stringify(recorded.reason)}. Call it as ctx.park(reason, message) with reason one of "waiting-input", "waiting-event" or "waiting-quota".`
364
+ });
365
+ }
366
+ return new Cell.Settled({
367
+ transition: Sandbox.replTransition({ _tag: "Park", reason, message: recorded.message }, justification)
368
+ });
369
+ }
370
+ return new Cell.Settled({
371
+ transition: Sandbox.replTransition(
372
+ recorded === void 0 ? void 0 : { _tag: "Done", output: recorded.output, value: recorded.value },
373
+ justification
374
+ )
375
+ });
376
+ };
377
+ const weighNodes = 2e5;
378
+ const weighDepth = 32;
379
+ const panelProbe = (baseline) => `(function (ownNames, descriptorOf, keysOf, isArray, stringify, String, mapSize, mapEntries, mapNext, setSize, setValues, setNext, skip) {
380
+ return function () {
381
+ var names = ownNames(globalThis)
382
+ var out = []
383
+ var total = 0
384
+ var budget = ${weighNodes}
385
+ var partial = false
386
+ var partialRoot = null
387
+ var partialBytes = 0
388
+ // The ancestors of the value being weighed, and the whole of this walk's
389
+ // repeat detection. A cycle is the one repeat that MUST be cut, because it
390
+ // never ends, and an ancestor list cuts it at the cost of the depth ceiling
391
+ // rather than of the whole graph. Two siblings that share one object are
392
+ // counted twice, which over-states such a realm: a ceiling that errs toward
393
+ // refusing is the safe direction, and the refusal is spent on the frame it
394
+ // lands in, so the next cell runs and can restructure. A Set or a WeakSet
395
+ // would dedupe them properly and cannot be used here: allocating either
396
+ // inside a realm that is at its heap ceiling, which is the realm this probe
397
+ // exists to weigh, leaves the runtime unable to assert itself empty at
398
+ // teardown and aborts the host process.
399
+ var path = []
400
+ var weigh = function (value, depth) {
401
+ var kind = typeof value
402
+ if (depth > ${weighDepth}) {
403
+ partial = true
404
+ return 0
405
+ }
406
+ if (budget <= 0) {
407
+ partial = true
408
+ return 0
409
+ }
410
+ budget = budget - 1
411
+ // Code units, not UTF-8 bytes, and deliberately: this walk answers "how
412
+ // much of the host's memory is this realm holding", and QuickJS stores a
413
+ // string as one or two bytes per code unit, so a unit count is the honest
414
+ // reading of the thing being bounded. It is also the only O(1) one, and
415
+ // that is load-bearing: the probe runs at frame close under the cell's own
416
+ // interrupt budget, so a scan of a two-hundred-megabyte realm is killed
417
+ // part way and a realm that cannot be weighed at all reads as weighing
418
+ // nothing. UTF-8 bytes are the unit of what the model is SHOWN, which is
419
+ // the print channel and the call ledger, not of what the realm holds.
420
+ if (kind === "string") return value.length
421
+ if (value === null || kind !== "object") return 8
422
+ for (var up = 0; up < path.length; up++) if (path[up] === value) return 8
423
+ path.push(value)
424
+ var sum = 8
425
+ // An array is walked by index so keysOf never allocates a second array as
426
+ // long as the first. Each transient descriptor dies with its iteration,
427
+ // and the same node budget that bounds the walk bounds that pressure.
428
+ // Reading through the descriptor is load-bearing: an index accessor is
429
+ // cell code, not data the memory probe may execute.
430
+ if (isArray(value)) {
431
+ var count = value.length
432
+ for (var item = 0; item < count && !partial; item++) {
433
+ var property = descriptorOf(value, String(item))
434
+ if (property === undefined || !("value" in property)) sum = sum + 8
435
+ else sum = sum + weigh(property.value, depth + 1)
436
+ }
437
+ path.pop()
438
+ return sum
439
+ }
440
+ // Collection entries live in internal slots, not own properties. Use
441
+ // captured native methods for both branding and iteration: instanceof,
442
+ // Symbol.iterator, and methods read from the value are cell-controlled.
443
+ // Catch only a failed brand check, never an incomplete entry traversal.
444
+ var isMap = false
445
+ var isSet = false
446
+ try {
447
+ mapSize(value)
448
+ isMap = true
449
+ } catch (error) {
450
+ try { setSize(value); isSet = true } catch (error) {}
451
+ }
452
+ if (isMap || isSet) {
453
+ // Iterator allocation can exhaust the heap too. Let that failure reach
454
+ // the outer catch so the reading is partial rather than empty.
455
+ var iterator = isMap ? mapEntries(value) : setValues(value)
456
+ while (!partial) {
457
+ var entry = isMap ? mapNext(iterator) : setNext(iterator)
458
+ if (entry.done) break
459
+ if (isMap) {
460
+ sum = sum + weigh(entry.value[0], depth + 1)
461
+ sum = sum + weigh(entry.value[1], depth + 1)
462
+ } else sum = sum + weigh(entry.value, depth + 1)
463
+ }
464
+ }
465
+ var keys = keysOf(value)
466
+ for (var key = 0; key < keys.length && !partial; key++) {
467
+ var property = descriptorOf(value, keys[key])
468
+ sum = sum + keys[key].length
469
+ if (property === undefined || !("value" in property)) sum = sum + 8
470
+ else sum = sum + weigh(property.value, depth + 1)
471
+ }
472
+ path.pop()
473
+ return sum
474
+ }
475
+ var dataProperty = function (value, name, fallbackValue) {
476
+ var descriptor = descriptorOf(value, name)
477
+ return descriptor !== undefined && "value" in descriptor ? descriptor.value : fallbackValue
478
+ }
479
+ for (var index = 0; index < names.length; index++) {
480
+ var name = names[index]
481
+ if (skip.indexOf(name) >= 0) continue
482
+ var before = total
483
+ try {
484
+ var descriptor = descriptorOf(globalThis, name)
485
+ if (descriptor === undefined || !("value" in descriptor)) {
486
+ total = total + 8
487
+ out.push({ name: name, type: descriptor === undefined ? "unreadable" : "accessor", size: "", bytes: 8 })
488
+ continue
489
+ }
490
+ var value = descriptor.value
491
+ var kind = typeof value
492
+ var bytes = weigh(value, 0)
493
+ total = total + bytes
494
+ if (value === null) out.push({ name: name, type: "null", size: "", bytes: bytes })
495
+ else if (kind === "undefined") out.push({ name: name, type: "unset", size: "", bytes: bytes })
496
+ else if (kind === "string") out.push({ name: name, type: "string", size: value.length + " chars", bytes: bytes })
497
+ else if (kind === "function") out.push({ name: name, type: "function", size: "arity " + dataProperty(value, "length", 0), bytes: bytes })
498
+ else if (isArray(value)) out.push({ name: name, type: "array", size: dataProperty(value, "length", 0) + " items", bytes: bytes })
499
+ else if (kind === "object") out.push({ name: name, type: "object", size: keysOf(value).length + " keys", bytes: bytes })
500
+ else out.push({ name: name, type: kind, size: String(value), bytes: bytes })
501
+ if (partial) {
502
+ partialRoot = name
503
+ partialBytes = bytes
504
+ break
505
+ }
506
+ } catch (error) {
507
+ // A name the probe cannot read at all: a proxy that refuses reflection,
508
+ // or a realm so large that walking it is itself what runs out of heap.
509
+ // Either way this reading is a floor and not a total, so it is reported
510
+ // as partial rather than weighed at nothing. No accessor is invoked to
511
+ // get here: every property read above goes through its own descriptor.
512
+ total = before + 8
513
+ out.push({ name: name, type: "unreadable", size: "", bytes: 8 })
514
+ partial = true
515
+ partialRoot = name
516
+ partialBytes = 8
517
+ break
518
+ }
519
+ }
520
+ return stringify(partialRoot === null
521
+ ? { names: out, bytes: total, partial: false }
522
+ : { names: out, bytes: total, partial: true, partialRoot: partialRoot, partialBytes: partialBytes })
523
+ }
524
+ })(
525
+ Object.getOwnPropertyNames,
526
+ Object.getOwnPropertyDescriptor,
527
+ Object.keys,
528
+ Array.isArray,
529
+ JSON.stringify,
530
+ String,
531
+ Function.prototype.call.bind(Object.getOwnPropertyDescriptor(Map.prototype, "size").get),
532
+ Function.prototype.call.bind(Map.prototype.entries),
533
+ Function.prototype.call.bind(Object.getPrototypeOf(new Map().entries()).next),
534
+ Function.prototype.call.bind(Object.getOwnPropertyDescriptor(Set.prototype, "size").get),
535
+ Function.prototype.call.bind(Set.prototype.values),
536
+ Function.prototype.call.bind(Object.getPrototypeOf(new Set().values()).next),
537
+ JSON.parse(${baseline})
538
+ )`;
539
+ const Weighed = import_effect.Schema.Struct({
540
+ name: import_effect.Schema.String,
541
+ type: import_effect.Schema.String,
542
+ size: import_effect.Schema.String,
543
+ bytes: import_effect.Schema.Number
544
+ });
545
+ const ProbeReading = {
546
+ names: import_effect.Schema.Array(Weighed),
547
+ bytes: import_effect.Schema.Number
548
+ };
549
+ const decodeProbe = import_effect.Schema.decodeUnknownSync(
550
+ import_effect.Schema.Union([
551
+ import_effect.Schema.Struct({ ...ProbeReading, partial: import_effect.Schema.Literal(false) }),
552
+ import_effect.Schema.Struct({
553
+ ...ProbeReading,
554
+ partial: import_effect.Schema.Literal(true),
555
+ partialRoot: import_effect.Schema.String,
556
+ partialBytes: import_effect.Schema.Number
557
+ })
558
+ ])
559
+ );
560
+ const overBudget = (held, ceiling, weighed) => {
561
+ const heaviest = [...weighed].sort((left, right) => right.bytes - left.bytes).slice(0, 3).map((entry) => `${entry.name} (${entry.bytes})`);
562
+ return new Cell.Rejected({
563
+ code: "limit_exceeded",
564
+ message: `The names this realm holds weigh ${held} bytes, over this run's ceiling of ${ceiling}. Nothing ran this frame, and your next cell does run: spend it freeing the largest by assigning over them \u2014 ${heaviest.join(", ")} \u2014 because a name a cell bound can be reassigned but never deleted. Every other name is still bound, and a realm still over the ceiling after that cell is refused again.`
565
+ });
566
+ };
567
+ const tooLargeToWeigh = (held, ceiling, root, bytes2) => new Cell.Rejected({
568
+ code: "limit_exceeded",
569
+ message: `This realm is too large to measure: weighing it stopped inside ${root} (${bytes2}) before it finished, so the ${held} bytes counted are a floor and not a total, and this run's ceiling of ${ceiling} is treated as spent. Nothing ran this frame, and your next cell does run: spend it freeing that name by assigning over it, because a name a cell bound can be reassigned but never deleted. Every other name is still bound, and a realm still too large to weigh after that cell is refused again.`
570
+ });
571
+ const openRealm = (module2, options, clock) => import_effect.Effect.gen(function* () {
572
+ const realmLimits = Sandbox.withDefaults(capabilities, options.limits);
573
+ let timeMs = realmLimits.timeMs ?? Sandbox.defaultLimits.timeMs;
574
+ const memoryBytes = realmLimits.memoryBytes ?? Sandbox.defaultLimits.memoryBytes;
575
+ let stepBudget = realmLimits.steps;
576
+ let clockBase = clock.now();
577
+ let steps = 0;
578
+ let exhausted;
579
+ let pending = [];
580
+ let closing = true;
581
+ let ordinal = 0;
582
+ let boundary = { terminal: "timeout", dispatched: -1, settled: -1 };
583
+ let lines = [];
584
+ let retained = 0;
585
+ let unread = 0;
586
+ let recorded;
587
+ let justification;
588
+ const acquired = yield* import_effect.Effect.acquireRelease(
589
+ import_effect.Effect.sync(() => {
590
+ const runtime2 = module2.newRuntime();
591
+ if (realmLimits.memoryBytes !== void 0) {
592
+ runtime2.setMemoryLimit(realmLimits.memoryBytes);
593
+ }
594
+ runtime2.setInterruptHandler(() => {
595
+ if (clock.now() - clockBase >= timeMs) {
596
+ exhausted = exhausted ?? timeLimitExceeded(timeMs);
597
+ return true;
598
+ }
599
+ if (stepBudget !== void 0 && ++steps > stepBudget) {
600
+ exhausted = exhausted ?? new Cell.Rejected({
601
+ code: "limit_exceeded",
602
+ message: `This cell exceeded its limit of ${stepBudget} interpreter steps`
603
+ });
604
+ return true;
605
+ }
606
+ return false;
607
+ });
608
+ const context2 = runtime2.newContext();
609
+ return { runtime: runtime2, context: context2 };
610
+ }),
611
+ ({ context: context2, runtime: runtime2 }) => import_effect.Effect.sync(() => {
612
+ context2.dispose();
613
+ runtime2.dispose();
614
+ })
615
+ );
616
+ const { context, runtime } = acquired;
617
+ const defineDataProperty = yield* import_effect.Effect.acquireRelease(
618
+ import_effect.Effect.sync(
619
+ () => context.unwrapResult(context.evalCode(
620
+ `(function (defineProperty) {
621
+ return function (object, key, value) {
622
+ defineProperty(object, key, {
623
+ value: value,
624
+ writable: true,
625
+ enumerable: true,
626
+ configurable: true
627
+ })
628
+ }
629
+ })(Object.defineProperty)`
630
+ ))
631
+ ),
632
+ (handle) => import_effect.Effect.sync(() => handle.dispose())
633
+ );
634
+ const install = (name, implementation) => {
635
+ const handle = context.newFunction(name, implementation);
636
+ context.setProp(context.global, name, handle);
637
+ handle.dispose();
638
+ };
639
+ const heapUsed = () => {
640
+ const snapshot2 = runtime.computeMemoryUsage();
641
+ try {
642
+ const usage = context.dump(snapshot2);
643
+ return usage.memory_used_size;
644
+ } finally {
645
+ snapshot2.dispose();
646
+ }
647
+ };
648
+ const abort = (message) => {
649
+ closing = true;
650
+ for (const call of pending.splice(0)) call.abort(message);
651
+ };
652
+ const queue = (kind, flow, input, at) => {
653
+ if (closing) throw new Error("The cell is closing; no further host calls are accepted");
654
+ const deferred = context.newPromise();
655
+ const reply = (payload) => {
656
+ const remaining = Math.max(0, memoryBytes - heapUsed());
657
+ let payloadBytes = 64 * 1024;
658
+ const values = [payload];
659
+ while (values.length > 0 && payloadBytes < remaining) {
660
+ const value = values.pop();
661
+ payloadBytes += 64;
662
+ if (typeof value === "string") payloadBytes += bytes.size(value) * 2;
663
+ else if (value !== null && typeof value === "object") {
664
+ for (const [key, child] of Object.entries(value)) {
665
+ payloadBytes += 128 + bytes.size(key) * 2;
666
+ values.push(child);
667
+ }
668
+ }
669
+ }
670
+ if (payloadBytes >= remaining) {
671
+ exhausted = exhausted ?? new Cell.Rejected({
672
+ code: "limit_exceeded",
673
+ reason: "heap",
674
+ message: `The flow result is estimated to need ${payloadBytes} bytes of QuickJS heap, but only ${remaining} bytes remain under this run's ceiling of ${memoryBytes}. The result was not materialized.`
675
+ });
676
+ deferred.resolve(context.undefined);
677
+ deferred.dispose();
678
+ return;
679
+ }
680
+ let handle;
681
+ try {
682
+ handle = handleFromJson(context, defineDataProperty, payload);
683
+ deferred.resolve(handle);
684
+ } catch {
685
+ exhausted = new Cell.Rejected({
686
+ code: "limit_exceeded",
687
+ reason: "heap",
688
+ message: "Materializing the flow result exceeded the realm's limits."
689
+ });
690
+ deferred.resolve(context.undefined);
691
+ } finally {
692
+ handle?.dispose();
693
+ deferred.dispose();
694
+ }
695
+ };
696
+ pending.push({
697
+ ordinal: ordinal++,
698
+ flow,
699
+ input,
700
+ kind,
701
+ ...at === void 0 ? {} : { at },
702
+ settle: (result) => reply(
703
+ result.outcome === "success" ? { ok: true, value: result.value ?? null } : { ok: false, aborted: false, failure: Cell.callFailure(result) }
704
+ ),
705
+ abort: (message) => reply({
706
+ ok: false,
707
+ aborted: true,
708
+ failure: Cell.callFailure((0, import_refusal.refusal)(void 0, message))
709
+ })
710
+ });
711
+ return deferred.handle;
712
+ };
713
+ install("__call", (flowHandle, inputHandle, atHandle) => queue(
714
+ "call",
715
+ context.getString(flowHandle),
716
+ import_effect.Schema.decodeUnknownSync(import_effect.Schema.Json)(JSON.parse(context.getString(inputHandle))),
717
+ decodedAt(context.getString(atHandle))
718
+ ));
719
+ install("__checkpoint", () => queue("checkpoint", checkpointFlow, null, void 0));
720
+ install("__print", (partsHandle) => {
721
+ if (retained >= Sandbox.printRetainedBytes) {
722
+ unread = unread + 1;
723
+ return context.undefined;
724
+ }
725
+ const line = printed(context.getString(partsHandle));
726
+ retained = retained + bytes.size(line.text) + 1;
727
+ lines.push(line);
728
+ return context.undefined;
729
+ });
730
+ install("__intent", (kindHandle, payloadHandle) => {
731
+ const kind = context.getString(kindHandle);
732
+ const payload = import_effect.Schema.decodeUnknownSync(import_effect.Schema.Json)(JSON.parse(context.getString(payloadHandle)));
733
+ if (kind === "done") recorded = { kind: "done", output: Cell.renderText(payload), value: payload };
734
+ else if (kind === "park") {
735
+ const park = parkPayload(payload);
736
+ recorded = { kind: "park", reason: park.reason, message: Cell.renderText(park.message) };
737
+ } else justification = Cell.renderText(payload);
738
+ return context.undefined;
739
+ });
740
+ const installed = context.evalCode(replPrelude(catalogOf(options.flows)));
741
+ if (installed.error !== void 0) {
742
+ const failure = context.dump(installed.error);
743
+ installed.error.dispose();
744
+ return yield* new Sandbox.SandboxError({
745
+ code: "runtime_failed",
746
+ message: "The sandbox prelude failed to install",
747
+ cause: failure
748
+ });
749
+ }
750
+ const openFrame = installed.value;
751
+ yield* import_effect.Effect.addFinalizer(() => import_effect.Effect.sync(() => openFrame.dispose()));
752
+ const snapshot = context.unwrapResult(
753
+ context.evalCode("JSON.stringify(Object.getOwnPropertyNames(globalThis))")
754
+ );
755
+ const baseline = context.getString(snapshot);
756
+ snapshot.dispose();
757
+ const probe = context.unwrapResult(context.evalCode(panelProbe(JSON.stringify(baseline))));
758
+ yield* import_effect.Effect.addFinalizer(() => import_effect.Effect.sync(() => probe.dispose()));
759
+ let bindings = [];
760
+ let weighed = [];
761
+ let held = 0;
762
+ let unweighed;
763
+ const evaluateFrame = (evaluation, limits) => {
764
+ const totalMs = limits.totalMs ?? Sandbox.defaultLimits.totalMs;
765
+ const frameStarted = clock.now();
766
+ let pausedAtForFrame;
767
+ let pausedMs = 0;
768
+ return import_effect.Effect.gen(function* () {
769
+ timeMs = limits.timeMs ?? Sandbox.defaultLimits.timeMs;
770
+ stepBudget = limits.steps;
771
+ clockBase = clock.now();
772
+ steps = 0;
773
+ exhausted = void 0;
774
+ pending = [];
775
+ closing = false;
776
+ ordinal = 0;
777
+ boundary = { terminal: "timeout", dispatched: -1, settled: -1 };
778
+ lines = [];
779
+ retained = 0;
780
+ unread = 0;
781
+ recorded = void 0;
782
+ justification = void 0;
783
+ if (evaluation.flows === void 0) {
784
+ context.unwrapResult(context.callFunction(openFrame, context.undefined)).dispose();
785
+ } else {
786
+ const catalog = context.newString(catalogOf(evaluation.flows));
787
+ try {
788
+ context.unwrapResult(context.callFunction(openFrame, context.undefined, catalog)).dispose();
789
+ } finally {
790
+ catalog.dispose();
791
+ }
792
+ }
793
+ const frameOf = (outcome2) => ({
794
+ outcome: outcome2,
795
+ ...outcome2._tag === "rejected" && outcome2.code === "limit_exceeded" ? { boundary: { ...boundary, terminal: "settled" } } : {},
796
+ prints: printChannel.buffer(lines, unread),
797
+ bindings
798
+ });
799
+ if (unweighed !== void 0) {
800
+ const refusal2 = tooLargeToWeigh(held, memoryBytes, unweighed.root, unweighed.bytes);
801
+ unweighed = void 0;
802
+ held = 0;
803
+ return frameOf(refusal2);
804
+ }
805
+ if (held > memoryBytes) {
806
+ const refusal2 = overBudget(held, memoryBytes, weighed);
807
+ held = 0;
808
+ return frameOf(refusal2);
809
+ }
810
+ const compiled2 = evaluation.program ?? Sandbox.compile(evaluation.cell);
811
+ if (compiled2 instanceof Cell.Rejected) return frameOf(compiled2);
812
+ const started = context.evalCode(compiled2, `cell-${evaluation.frame}.js`, 128);
813
+ if (started.error !== void 0) {
814
+ const failure = context.dump(started.error);
815
+ started.error.dispose();
816
+ return frameOf(
817
+ new Cell.Rejected({
818
+ code: "compile_failed",
819
+ /* v8 ignore next -- QuickJS reports a compile failure as an Error object, so the `message` arm is what a parser disagreement takes; `String(failure)` only discharges the `unknown` `context.dump` is typed as */
820
+ message: `The cell did not compile: ${typeof failure === "object" && failure !== null && "message" in failure ? String(failure.message) : String(failure)}`
821
+ })
822
+ );
823
+ }
824
+ const cellHandle = started.value;
825
+ let settled;
826
+ const poll = () => {
827
+ if (closing) return;
828
+ runtime.executePendingJobs();
829
+ if (exhausted !== void 0) {
830
+ settled = exhausted;
831
+ return;
832
+ }
833
+ const state = context.getPromiseState(cellHandle);
834
+ if (state.type === "pending") return;
835
+ if (state.type === "fulfilled") {
836
+ state.value.dispose();
837
+ settled = replOutcome(recorded, justification);
838
+ return;
839
+ }
840
+ const error = context.dump(state.error);
841
+ state.error.dispose();
842
+ settled = raisedFrom(error);
843
+ };
844
+ const outcome = yield* Sandbox.driveCell({
845
+ pending,
846
+ replay: evaluation.replay,
847
+ progress: (dispatched, settled2) => {
848
+ boundary = { terminal: "timeout", dispatched, settled: settled2 };
849
+ },
850
+ ...evaluation.mint === void 0 ? {} : {
851
+ mint: (mint) => import_effect.Effect.suspend(() => {
852
+ const pausedAt = clock.now();
853
+ return evaluation.mint(mint).pipe(
854
+ import_effect.Effect.onExit(
855
+ () => import_effect.Effect.sync(() => {
856
+ clockBase += clock.now() - pausedAt;
857
+ })
858
+ )
859
+ );
860
+ })
861
+ },
862
+ ...evaluation.bounded === void 0 ? {} : { bounded: evaluation.bounded },
863
+ flush: () => poll(),
864
+ finished: () => {
865
+ poll();
866
+ if (settled !== void 0) return settled;
867
+ if (pending.length > 0) return void 0;
868
+ return new Cell.Rejected({
869
+ code: "stalled",
870
+ message: "The cell awaited something that never settles. Inside a cell the only thing worth awaiting is ctx.call."
871
+ });
872
+ },
873
+ abort,
874
+ handler: (call) => import_effect.Effect.suspend(() => {
875
+ const pausedAt = clock.now();
876
+ const pausesFrame = limits.pauseTotalMsFor?.includes(call.flow) === true;
877
+ if (pausesFrame) pausedAtForFrame = pausedAt;
878
+ return evaluation.call(call).pipe(
879
+ import_effect.Effect.onExit(
880
+ () => import_effect.Effect.sync(() => {
881
+ clockBase += clock.now() - pausedAt;
882
+ if (pausesFrame) {
883
+ pausedMs += clock.now() - pausedAt;
884
+ pausedAtForFrame = void 0;
885
+ }
886
+ })
887
+ )
888
+ );
889
+ }),
890
+ limits
891
+ }).pipe(
892
+ // Closing is irreversible within this frame. Rejecting a bridge
893
+ // resumes user catch/finally blocks, so admission must close before
894
+ // any of those jobs can allocate another host-owned promise handle.
895
+ import_effect.Effect.ensuring(
896
+ import_effect.Effect.sync(() => {
897
+ closing = true;
898
+ try {
899
+ for (let jobs = 0; ; jobs++) {
900
+ abort("The cell was interrupted");
901
+ if (jobs >= 1024 || !runtime.hasPendingJob()) break;
902
+ runtime.executePendingJobs(1).dispose();
903
+ }
904
+ } finally {
905
+ cellHandle.dispose();
906
+ }
907
+ })
908
+ )
909
+ );
910
+ if (evaluation.replay !== void 0) {
911
+ return { outcome: evaluation.replay.outcome, prints: "", bindings, boundary: evaluation.replay.boundary };
912
+ }
913
+ const read = context.callFunction(probe, context.undefined);
914
+ if (read.error === void 0) {
915
+ const measured = decodeProbe(JSON.parse(context.getString(read.value)));
916
+ read.value.dispose();
917
+ weighed = measured.names;
918
+ held = measured.bytes;
919
+ unweighed = measured.partial ? { root: measured.partialRoot, bytes: measured.partialBytes } : void 0;
920
+ bindings = measured.names.map(
921
+ (entry) => new VariablesPanel.Binding({ name: entry.name, type: entry.type, size: entry.size })
922
+ );
923
+ } else {
924
+ read.error.dispose();
925
+ }
926
+ return frameOf(outcome);
927
+ }).pipe(
928
+ limits.pauseTotalMsFor?.length && evaluation.replay === void 0 ? import_effect.Effect.raceFirst(import_effect.Effect.gen(function* () {
929
+ for (; ; ) {
930
+ const now = clock.now();
931
+ const elapsed = now - frameStarted - pausedMs - (pausedAtForFrame === void 0 ? 0 : now - pausedAtForFrame);
932
+ const remaining = totalMs - elapsed;
933
+ if (remaining <= 0) {
934
+ return {
935
+ outcome: timeLimitExceeded(totalMs),
936
+ boundary,
937
+ prints: "",
938
+ bindings
939
+ };
940
+ }
941
+ yield* import_effect.Effect.sleep(import_effect.Duration.millis(Math.max(1, remaining)));
942
+ }
943
+ })) : import_effect.Effect.timeoutOrElse({
944
+ // Replay is stopped by its recorded boundary, not a second clock.
945
+ duration: evaluation.replay === void 0 ? totalMs : Infinity,
946
+ orElse: () => import_effect.Effect.succeed({
947
+ outcome: timeLimitExceeded(totalMs),
948
+ boundary,
949
+ prints: "",
950
+ bindings
951
+ })
952
+ })
953
+ );
954
+ };
955
+ const evaluate = (evaluation) => Sandbox.evaluationLimits(realmLimits, evaluation.limits).pipe(
956
+ import_effect.Effect.flatMap((limits) => evaluateFrame(evaluation, limits))
957
+ );
958
+ return { evaluate };
959
+ });
960
+ const loadModule = (loader) => import_effect.Effect.tryPromise({
961
+ try: loader,
962
+ catch: (cause) => new Sandbox.SandboxError({
963
+ code: "runtime_failed",
964
+ message: "QuickJS WebAssembly module could not be loaded",
965
+ cause
966
+ })
967
+ });
968
+ const makeWithVariant = import_effect.Effect.gen(function* () {
969
+ const clock = yield* ComputeClock;
970
+ const { variant } = yield* Variant;
971
+ const module2 = yield* loadModule(loaderFor(variant));
972
+ return Sandbox.make({
973
+ capabilities,
974
+ openRealm: (options) => openRealm(module2, options, clock)
975
+ });
976
+ });
977
+ const makeWithClock = makeWithVariant.pipe(
978
+ import_effect.Effect.provide(layerVariantLive)
979
+ );
980
+ const make = makeWithClock.pipe(
981
+ import_effect.Effect.provide(layerClockLive)
982
+ );
983
+ const layerWithVariant = import_effect.Layer.effect(
984
+ Sandbox.Sandbox
985
+ )(makeWithVariant.pipe(import_effect.Effect.provide(layerClockLive)));
986
+ const layer = import_effect.Layer.effect(Sandbox.Sandbox)(make);
987
+ //# sourceMappingURL=QuickJSSandbox.js.map