@animalabs/agent-framework 0.23.2 → 0.24.0

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 (338) hide show
  1. package/README.md +212 -42
  2. package/dist/src/agent.d.ts +60 -9
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +92 -12
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/server.d.ts.map +1 -1
  7. package/dist/src/api/server.js +14 -12
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/code-execution/engine.d.ts +177 -0
  10. package/dist/src/code-execution/engine.d.ts.map +1 -0
  11. package/dist/src/code-execution/engine.js +494 -0
  12. package/dist/src/code-execution/engine.js.map +1 -0
  13. package/dist/src/code-execution/index.d.ts +5 -10
  14. package/dist/src/code-execution/index.d.ts.map +1 -1
  15. package/dist/src/code-execution/index.js +5 -9
  16. package/dist/src/code-execution/index.js.map +1 -1
  17. package/dist/src/code-execution/isolate/calls.d.ts +114 -0
  18. package/dist/src/code-execution/isolate/calls.d.ts.map +1 -0
  19. package/dist/src/code-execution/isolate/calls.js +145 -0
  20. package/dist/src/code-execution/isolate/calls.js.map +1 -0
  21. package/dist/src/code-execution/isolate/child-entry.d.ts +2 -0
  22. package/dist/src/code-execution/isolate/child-entry.d.ts.map +1 -0
  23. package/dist/src/code-execution/isolate/child-entry.js +5 -0
  24. package/dist/src/code-execution/isolate/child-entry.js.map +1 -0
  25. package/dist/src/code-execution/isolate/child-main.d.ts +26 -0
  26. package/dist/src/code-execution/isolate/child-main.d.ts.map +1 -0
  27. package/dist/src/code-execution/isolate/child-main.js +132 -0
  28. package/dist/src/code-execution/isolate/child-main.js.map +1 -0
  29. package/dist/src/code-execution/isolate/child.d.ts +44 -0
  30. package/dist/src/code-execution/isolate/child.d.ts.map +1 -0
  31. package/dist/src/code-execution/isolate/child.js +315 -0
  32. package/dist/src/code-execution/isolate/child.js.map +1 -0
  33. package/dist/src/code-execution/isolate/frames.d.ts +80 -0
  34. package/dist/src/code-execution/isolate/frames.d.ts.map +1 -0
  35. package/dist/src/code-execution/isolate/frames.js +210 -0
  36. package/dist/src/code-execution/isolate/frames.js.map +1 -0
  37. package/dist/src/code-execution/isolate/output.d.ts +68 -0
  38. package/dist/src/code-execution/isolate/output.d.ts.map +1 -0
  39. package/dist/src/code-execution/isolate/output.js +143 -0
  40. package/dist/src/code-execution/isolate/output.js.map +1 -0
  41. package/dist/src/code-execution/isolate/prelude.d.ts +109 -0
  42. package/dist/src/code-execution/isolate/prelude.d.ts.map +1 -0
  43. package/dist/src/code-execution/isolate/prelude.js +401 -0
  44. package/dist/src/code-execution/isolate/prelude.js.map +1 -0
  45. package/dist/src/code-execution/isolate/protocol.d.ts +151 -0
  46. package/dist/src/code-execution/isolate/protocol.d.ts.map +1 -0
  47. package/dist/src/code-execution/isolate/protocol.js +150 -0
  48. package/dist/src/code-execution/isolate/protocol.js.map +1 -0
  49. package/dist/src/code-execution/isolate/render.d.ts +57 -0
  50. package/dist/src/code-execution/isolate/render.d.ts.map +1 -0
  51. package/dist/src/code-execution/isolate/render.js +214 -0
  52. package/dist/src/code-execution/isolate/render.js.map +1 -0
  53. package/dist/src/code-execution/isolate/runner.d.ts +250 -0
  54. package/dist/src/code-execution/isolate/runner.d.ts.map +1 -0
  55. package/dist/src/code-execution/isolate/runner.js +854 -0
  56. package/dist/src/code-execution/isolate/runner.js.map +1 -0
  57. package/dist/src/code-execution/isolate/scripts.d.ts +175 -0
  58. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -0
  59. package/dist/src/code-execution/isolate/scripts.js +357 -0
  60. package/dist/src/code-execution/isolate/scripts.js.map +1 -0
  61. package/dist/src/code-execution/quickjs.wasm +0 -0
  62. package/dist/src/code-execution/tool-definition.d.ts +93 -43
  63. package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
  64. package/dist/src/code-execution/tool-definition.js +176 -142
  65. package/dist/src/code-execution/tool-definition.js.map +1 -1
  66. package/dist/src/deadline-timer.d.ts +3 -0
  67. package/dist/src/deadline-timer.d.ts.map +1 -1
  68. package/dist/src/deadline-timer.js +1 -1
  69. package/dist/src/deadline-timer.js.map +1 -1
  70. package/dist/src/framework.d.ts +1027 -440
  71. package/dist/src/framework.d.ts.map +1 -1
  72. package/dist/src/framework.js +4093 -2238
  73. package/dist/src/framework.js.map +1 -1
  74. package/dist/src/gate/event-gate.d.ts +28 -1
  75. package/dist/src/gate/event-gate.d.ts.map +1 -1
  76. package/dist/src/gate/event-gate.js +88 -10
  77. package/dist/src/gate/event-gate.js.map +1 -1
  78. package/dist/src/held-writes.d.ts +16 -3
  79. package/dist/src/held-writes.d.ts.map +1 -1
  80. package/dist/src/held-writes.js +16 -3
  81. package/dist/src/held-writes.js.map +1 -1
  82. package/dist/src/index.d.ts +6 -6
  83. package/dist/src/index.d.ts.map +1 -1
  84. package/dist/src/index.js +9 -8
  85. package/dist/src/index.js.map +1 -1
  86. package/dist/src/mcpl/channel-registry.d.ts +471 -75
  87. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  88. package/dist/src/mcpl/channel-registry.js +1673 -337
  89. package/dist/src/mcpl/channel-registry.js.map +1 -1
  90. package/dist/src/mcpl/conversation-router.d.ts +12 -7
  91. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  92. package/dist/src/mcpl/conversation-router.js +12 -7
  93. package/dist/src/mcpl/conversation-router.js.map +1 -1
  94. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  95. package/dist/src/mcpl/convert-block.js +9 -5
  96. package/dist/src/mcpl/convert-block.js.map +1 -1
  97. package/dist/src/mcpl/inbound-source.d.ts +50 -0
  98. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  99. package/dist/src/mcpl/inbound-source.js +130 -0
  100. package/dist/src/mcpl/inbound-source.js.map +1 -1
  101. package/dist/src/mcpl/index.d.ts +2 -1
  102. package/dist/src/mcpl/index.d.ts.map +1 -1
  103. package/dist/src/mcpl/index.js +3 -2
  104. package/dist/src/mcpl/index.js.map +1 -1
  105. package/dist/src/mcpl/log-value.d.ts +6 -0
  106. package/dist/src/mcpl/log-value.d.ts.map +1 -1
  107. package/dist/src/mcpl/log-value.js +8 -0
  108. package/dist/src/mcpl/log-value.js.map +1 -1
  109. package/dist/src/mcpl/modern-connection.d.ts +15 -6
  110. package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
  111. package/dist/src/mcpl/modern-connection.js +168 -53
  112. package/dist/src/mcpl/modern-connection.js.map +1 -1
  113. package/dist/src/mcpl/prose-grammar.d.ts +4 -5
  114. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  115. package/dist/src/mcpl/prose-grammar.js +4 -5
  116. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  117. package/dist/src/mcpl/protocol-family.d.ts +97 -10
  118. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  119. package/dist/src/mcpl/protocol-family.js +173 -16
  120. package/dist/src/mcpl/protocol-family.js.map +1 -1
  121. package/dist/src/mcpl/push-coalescer.d.ts +132 -14
  122. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  123. package/dist/src/mcpl/push-coalescer.js +227 -50
  124. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  125. package/dist/src/mcpl/push-handler.d.ts +6 -1
  126. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  127. package/dist/src/mcpl/push-handler.js +4 -1
  128. package/dist/src/mcpl/push-handler.js.map +1 -1
  129. package/dist/src/mcpl/reference-fetcher.d.ts +2 -2
  130. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  131. package/dist/src/mcpl/reference-fetcher.js +4 -4
  132. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  133. package/dist/src/mcpl/server-connection.d.ts +50 -21
  134. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  135. package/dist/src/mcpl/server-connection.js +158 -74
  136. package/dist/src/mcpl/server-connection.js.map +1 -1
  137. package/dist/src/mcpl/tags.d.ts +24 -0
  138. package/dist/src/mcpl/tags.d.ts.map +1 -1
  139. package/dist/src/mcpl/tags.js +33 -0
  140. package/dist/src/mcpl/tags.js.map +1 -1
  141. package/dist/src/mcpl/tool-result-normalize.d.ts +2 -1
  142. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  143. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  144. package/dist/src/mcpl/transport.d.ts +55 -7
  145. package/dist/src/mcpl/transport.d.ts.map +1 -1
  146. package/dist/src/mcpl/transport.js +163 -34
  147. package/dist/src/mcpl/transport.js.map +1 -1
  148. package/dist/src/mcpl/types.d.ts +22 -6
  149. package/dist/src/mcpl/types.d.ts.map +1 -1
  150. package/dist/src/mcpl/types.js.map +1 -1
  151. package/dist/src/module-registry.d.ts +4 -2
  152. package/dist/src/module-registry.d.ts.map +1 -1
  153. package/dist/src/module-registry.js +100 -13
  154. package/dist/src/module-registry.js.map +1 -1
  155. package/dist/src/modules/discord/index.d.ts.map +1 -1
  156. package/dist/src/modules/discord/index.js +8 -13
  157. package/dist/src/modules/discord/index.js.map +1 -1
  158. package/dist/src/modules/history/index.d.ts.map +1 -1
  159. package/dist/src/modules/history/index.js +27 -4
  160. package/dist/src/modules/history/index.js.map +1 -1
  161. package/dist/src/modules/history/semantic.d.ts +15 -3
  162. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  163. package/dist/src/modules/history/semantic.js +27 -5
  164. package/dist/src/modules/history/semantic.js.map +1 -1
  165. package/dist/src/modules/index.d.ts +1 -1
  166. package/dist/src/modules/index.d.ts.map +1 -1
  167. package/dist/src/modules/index.js.map +1 -1
  168. package/dist/src/modules/unknown-tool.d.ts +4 -1
  169. package/dist/src/modules/unknown-tool.d.ts.map +1 -1
  170. package/dist/src/modules/unknown-tool.js +4 -1
  171. package/dist/src/modules/unknown-tool.js.map +1 -1
  172. package/dist/src/modules/workspace/branch-intent.d.ts +3 -1
  173. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  174. package/dist/src/modules/workspace/branch-intent.js +3 -1
  175. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  176. package/dist/src/modules/workspace/edit-plan.d.ts +265 -0
  177. package/dist/src/modules/workspace/edit-plan.d.ts.map +1 -0
  178. package/dist/src/modules/workspace/edit-plan.js +794 -0
  179. package/dist/src/modules/workspace/edit-plan.js.map +1 -0
  180. package/dist/src/modules/workspace/edit-text.d.ts +117 -0
  181. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -0
  182. package/dist/src/modules/workspace/edit-text.js +584 -0
  183. package/dist/src/modules/workspace/edit-text.js.map +1 -0
  184. package/dist/src/modules/workspace/effects.d.ts +5 -4
  185. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  186. package/dist/src/modules/workspace/effects.js +78 -25
  187. package/dist/src/modules/workspace/effects.js.map +1 -1
  188. package/dist/src/modules/workspace/index.d.ts +484 -61
  189. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  190. package/dist/src/modules/workspace/index.js +2173 -645
  191. package/dist/src/modules/workspace/index.js.map +1 -1
  192. package/dist/src/modules/workspace/observe.d.ts +213 -38
  193. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  194. package/dist/src/modules/workspace/observe.js +416 -36
  195. package/dist/src/modules/workspace/observe.js.map +1 -1
  196. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  197. package/dist/src/modules/workspace/reconcile.js +15 -8
  198. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  199. package/dist/src/modules/workspace/text.d.ts +32 -0
  200. package/dist/src/modules/workspace/text.d.ts.map +1 -0
  201. package/dist/src/modules/workspace/text.js +67 -0
  202. package/dist/src/modules/workspace/text.js.map +1 -0
  203. package/dist/src/modules/workspace/types.d.ts +210 -6
  204. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  205. package/dist/src/modules/workspace/types.js.map +1 -1
  206. package/dist/src/modules/workspace/watcher.d.ts +3 -2
  207. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  208. package/dist/src/modules/workspace/watcher.js.map +1 -1
  209. package/dist/src/operator-log.d.ts +52 -24
  210. package/dist/src/operator-log.d.ts.map +1 -1
  211. package/dist/src/operator-log.js.map +1 -1
  212. package/dist/src/recovery/discord-awareness-outbox.d.ts +496 -72
  213. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  214. package/dist/src/recovery/discord-awareness-outbox.js +1196 -289
  215. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  216. package/dist/src/recovery/offline-branch.d.ts +26 -1
  217. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  218. package/dist/src/recovery/offline-branch.js +164 -39
  219. package/dist/src/recovery/offline-branch.js.map +1 -1
  220. package/dist/src/recovery/recover-cli.js +23 -4
  221. package/dist/src/recovery/recover-cli.js.map +1 -1
  222. package/dist/src/send-tools.d.ts +11 -0
  223. package/dist/src/send-tools.d.ts.map +1 -0
  224. package/dist/src/send-tools.js +11 -0
  225. package/dist/src/send-tools.js.map +1 -0
  226. package/dist/src/tool-result-guard.d.ts +4 -3
  227. package/dist/src/tool-result-guard.d.ts.map +1 -1
  228. package/dist/src/tool-result-guard.js +5 -4
  229. package/dist/src/tool-result-guard.js.map +1 -1
  230. package/dist/src/tool-result-history.d.ts +1 -1
  231. package/dist/src/tool-result-history.js +1 -1
  232. package/dist/src/tune-out/coordinator.d.ts +21 -0
  233. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  234. package/dist/src/tune-out/coordinator.js +139 -37
  235. package/dist/src/tune-out/coordinator.js.map +1 -1
  236. package/dist/src/types/agent.d.ts +4 -0
  237. package/dist/src/types/agent.d.ts.map +1 -1
  238. package/dist/src/types/events.d.ts +62 -9
  239. package/dist/src/types/events.d.ts.map +1 -1
  240. package/dist/src/types/framework.d.ts +62 -58
  241. package/dist/src/types/framework.d.ts.map +1 -1
  242. package/dist/src/types/module.d.ts +40 -8
  243. package/dist/src/types/module.d.ts.map +1 -1
  244. package/dist/src/types/trace.d.ts +111 -10
  245. package/dist/src/types/trace.d.ts.map +1 -1
  246. package/dist/src/usage/types.d.ts +16 -0
  247. package/dist/src/usage/types.d.ts.map +1 -1
  248. package/dist/src/usage/usage-tracker.d.ts +14 -1
  249. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  250. package/dist/src/usage/usage-tracker.js +81 -41
  251. package/dist/src/usage/usage-tracker.js.map +1 -1
  252. package/package.json +6 -5
  253. package/src/agent.ts +93 -12
  254. package/src/api/server.ts +14 -12
  255. package/src/code-execution/engine.ts +595 -0
  256. package/src/code-execution/index.ts +5 -17
  257. package/src/code-execution/isolate/calls.ts +199 -0
  258. package/src/code-execution/isolate/child-entry.ts +5 -0
  259. package/src/code-execution/isolate/child-main.ts +132 -0
  260. package/src/code-execution/isolate/child.ts +327 -0
  261. package/src/code-execution/isolate/frames.ts +209 -0
  262. package/src/code-execution/isolate/output.ts +161 -0
  263. package/src/code-execution/isolate/prelude.ts +409 -0
  264. package/src/code-execution/isolate/protocol.ts +240 -0
  265. package/src/code-execution/isolate/render.ts +230 -0
  266. package/src/code-execution/isolate/runner.ts +911 -0
  267. package/src/code-execution/isolate/scripts.ts +479 -0
  268. package/src/code-execution/quickjs.wasm +0 -0
  269. package/src/code-execution/quickjs.wasm.LICENSES +149 -0
  270. package/src/code-execution/tool-definition.ts +236 -167
  271. package/src/deadline-timer.ts +1 -1
  272. package/src/framework.ts +4468 -2418
  273. package/src/gate/event-gate.ts +78 -11
  274. package/src/held-writes.ts +17 -3
  275. package/src/index.ts +30 -22
  276. package/src/mcpl/channel-registry.ts +1825 -368
  277. package/src/mcpl/conversation-router.ts +12 -7
  278. package/src/mcpl/convert-block.ts +9 -5
  279. package/src/mcpl/inbound-source.ts +131 -0
  280. package/src/mcpl/index.ts +4 -2
  281. package/src/mcpl/log-value.ts +9 -0
  282. package/src/mcpl/modern-connection.ts +162 -53
  283. package/src/mcpl/prose-grammar.ts +4 -5
  284. package/src/mcpl/protocol-family.ts +199 -21
  285. package/src/mcpl/push-coalescer.ts +306 -62
  286. package/src/mcpl/push-handler.ts +10 -2
  287. package/src/mcpl/reference-fetcher.ts +4 -4
  288. package/src/mcpl/server-connection.ts +180 -79
  289. package/src/mcpl/tags.ts +36 -0
  290. package/src/mcpl/tool-result-normalize.ts +2 -1
  291. package/src/mcpl/transport.ts +162 -33
  292. package/src/mcpl/types.ts +23 -6
  293. package/src/module-registry.ts +92 -13
  294. package/src/modules/discord/index.ts +8 -13
  295. package/src/modules/history/index.ts +25 -3
  296. package/src/modules/history/semantic.ts +29 -6
  297. package/src/modules/index.ts +1 -0
  298. package/src/modules/unknown-tool.ts +4 -1
  299. package/src/modules/workspace/branch-intent.ts +3 -1
  300. package/src/modules/workspace/edit-plan.ts +954 -0
  301. package/src/modules/workspace/edit-text.ts +618 -0
  302. package/src/modules/workspace/effects.ts +70 -19
  303. package/src/modules/workspace/index.ts +2247 -642
  304. package/src/modules/workspace/observe.ts +465 -56
  305. package/src/modules/workspace/reconcile.ts +14 -7
  306. package/src/modules/workspace/text.ts +68 -0
  307. package/src/modules/workspace/types.ts +211 -6
  308. package/src/modules/workspace/watcher.ts +3 -2
  309. package/src/operator-log.ts +47 -19
  310. package/src/recovery/discord-awareness-outbox.ts +1500 -356
  311. package/src/recovery/offline-branch.ts +189 -55
  312. package/src/recovery/recover-cli.ts +25 -4
  313. package/src/send-tools.ts +11 -0
  314. package/src/tool-result-guard.ts +6 -5
  315. package/src/tool-result-history.ts +1 -1
  316. package/src/tune-out/coordinator.ts +163 -42
  317. package/src/types/agent.ts +4 -0
  318. package/src/types/events.ts +62 -9
  319. package/src/types/framework.ts +62 -58
  320. package/src/types/module.ts +40 -8
  321. package/src/types/trace.ts +121 -15
  322. package/src/usage/types.ts +16 -0
  323. package/src/usage/usage-tracker.ts +86 -43
  324. package/dist/src/code-execution/py-runner.d.ts +0 -191
  325. package/dist/src/code-execution/py-runner.d.ts.map +0 -1
  326. package/dist/src/code-execution/py-runner.js +0 -655
  327. package/dist/src/code-execution/py-runner.js.map +0 -1
  328. package/dist/src/code-execution/runtime-py.d.ts +0 -50
  329. package/dist/src/code-execution/runtime-py.d.ts.map +0 -1
  330. package/dist/src/code-execution/runtime-py.js +0 -677
  331. package/dist/src/code-execution/runtime-py.js.map +0 -1
  332. package/dist/src/mcpl/prose-stream-router.d.ts +0 -88
  333. package/dist/src/mcpl/prose-stream-router.d.ts.map +0 -1
  334. package/dist/src/mcpl/prose-stream-router.js +0 -291
  335. package/dist/src/mcpl/prose-stream-router.js.map +0 -1
  336. package/src/code-execution/py-runner.ts +0 -791
  337. package/src/code-execution/runtime-py.ts +0 -677
  338. package/src/mcpl/prose-stream-router.ts +0 -268
@@ -0,0 +1,68 @@
1
+ /**
2
+ * A script's output, bounded once, in the parent: every return, whether a
3
+ * yield, a wait or the ending's, gives what the script wrote since the
4
+ * previous one, its first and last characters within the bound and a count of
5
+ * what was dropped between. A long stretch keeps its start, since that's
6
+ * often where its trouble began, such as the first error before a cascade.
7
+ *
8
+ * The child can't know when the parent returns, since its frames reach it only
9
+ * while its guest is idle, so the bound sits in the parent: the child holds
10
+ * one bounded batch of what the guest writes and flushes it, and the parent
11
+ * keeps the head and tail of each return's stretch, starting both afresh at
12
+ * each return. Memory is bounded by construction on both sides; the price is
13
+ * that a printing loop's whole output crosses the pipe, in batches.
14
+ */
15
+ export interface OutputBounds {
16
+ /** Characters kept from the start of each return's stretch. */
17
+ headChars: number;
18
+ /** Characters kept from its end. */
19
+ tailChars: number;
20
+ }
21
+ export declare const DEFAULT_OUTPUT_BOUNDS: OutputBounds;
22
+ /** The most one output frame carries, so a single large write is sent in pieces. */
23
+ export declare const MAX_BATCH_CHARS: number;
24
+ /** The child's side: what the guest wrote since the last flush, at most a batch of it at a time. */
25
+ export declare class OutputBatch {
26
+ private pending;
27
+ private size;
28
+ /** Characters waiting to be flushed. */
29
+ get unflushed(): number;
30
+ /** True once the batch is full, so the caller flushes now. */
31
+ write(text: string): boolean;
32
+ /** The waiting text in pieces of at most a batch each, emptying it; empty when nothing waits. */
33
+ flush(): string[];
34
+ }
35
+ /** A return's stretch of output: its head and tail, and the count dropped between them. */
36
+ export interface OutputWindow {
37
+ head: string;
38
+ tail: string;
39
+ dropped: number;
40
+ }
41
+ /**
42
+ * The stretch as the model sees it: the head, a line naming what was dropped
43
+ * if anything was, and the tail. Past `max`, its start and its end are cut
44
+ * alike to fit it, each taking the room the other doesn't need, and the count
45
+ * takes in what they gave up, so a return held to its agent's inline cap
46
+ * still shows both ends. A `max` that leaves no room for that line gets the
47
+ * line alone, which passes it.
48
+ */
49
+ export declare function renderOutput(w: OutputWindow, max?: number): string;
50
+ /** The parent's side: the head and tail of what arrived since the last return, and the count dropped between. */
51
+ export declare class WindowOutput {
52
+ private readonly bounds;
53
+ private head;
54
+ private tail;
55
+ private dropped;
56
+ constructor(bounds: OutputBounds);
57
+ /** Add text the child flushed. */
58
+ apply(text: string): void;
59
+ /** Characters dropped from the stretch so far. */
60
+ get droppedChars(): number;
61
+ /** The stretch as it stands. */
62
+ window(): OutputWindow;
63
+ /** The stretch as the model sees it, whole (renderOutput). */
64
+ render(): string;
65
+ /** The stretch, and a fresh one from here. */
66
+ take(): OutputWindow;
67
+ }
68
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/code-execution/isolate/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,EAAE,YAAqD,CAAC;AAE1F,oFAAoF;AACpF,eAAO,MAAM,eAAe,QAAY,CAAC;AASzC,oGAAoG;AACpG,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,IAAI,CAAK;IAEjB,wCAAwC;IACxC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,8DAA8D;IAC9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK3B;IAED,iGAAiG;IACjG,KAAK,IAAI,MAAM,EAAE,CAahB;CACF;AAED,2FAA2F;AAC3F,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,SAAW,GAAG,MAAM,CAgBpE;AAED,iHAAiH;AACjH,qBAAa,YAAY;IAKX,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,OAAO,CAAK;IAEpB,YAA6B,MAAM,EAAE,YAAY,EAAI;IAErD,kCAAkC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAqBxB;IAED,kDAAkD;IAClD,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,gCAAgC;IAChC,MAAM,IAAI,YAAY,CAErB;IAED,8DAA8D;IAC9D,MAAM,IAAI,MAAM,CAEf;IAED,8CAA8C;IAC9C,IAAI,IAAI,YAAY,CAMnB;CACF"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * A script's output, bounded once, in the parent: every return, whether a
3
+ * yield, a wait or the ending's, gives what the script wrote since the
4
+ * previous one, its first and last characters within the bound and a count of
5
+ * what was dropped between. A long stretch keeps its start, since that's
6
+ * often where its trouble began, such as the first error before a cascade.
7
+ *
8
+ * The child can't know when the parent returns, since its frames reach it only
9
+ * while its guest is idle, so the bound sits in the parent: the child holds
10
+ * one bounded batch of what the guest writes and flushes it, and the parent
11
+ * keeps the head and tail of each return's stretch, starting both afresh at
12
+ * each return. Memory is bounded by construction on both sides; the price is
13
+ * that a printing loop's whole output crosses the pipe, in batches.
14
+ */
15
+ export const DEFAULT_OUTPUT_BOUNDS = { headChars: 8_000, tailChars: 8_000 };
16
+ /** The most one output frame carries, so a single large write is sent in pieces. */
17
+ export const MAX_BATCH_CHARS = 64 * 1024;
18
+ /** Where to cut `text` near `at` without parting a surrogate pair: one earlier if `at` falls inside one. */
19
+ function safeCut(text, at) {
20
+ if (at <= 0 || at >= text.length)
21
+ return Math.max(0, Math.min(at, text.length));
22
+ const before = text.charCodeAt(at - 1);
23
+ return before >= 0xd800 && before <= 0xdbff ? at - 1 : at;
24
+ }
25
+ /** The child's side: what the guest wrote since the last flush, at most a batch of it at a time. */
26
+ export class OutputBatch {
27
+ pending = [];
28
+ size = 0;
29
+ /** Characters waiting to be flushed. */
30
+ get unflushed() {
31
+ return this.size;
32
+ }
33
+ /** True once the batch is full, so the caller flushes now. */
34
+ write(text) {
35
+ if (text.length === 0)
36
+ return this.size >= MAX_BATCH_CHARS;
37
+ this.pending.push(text);
38
+ this.size += text.length;
39
+ return this.size >= MAX_BATCH_CHARS;
40
+ }
41
+ /** The waiting text in pieces of at most a batch each, emptying it; empty when nothing waits. */
42
+ flush() {
43
+ if (this.size === 0)
44
+ return [];
45
+ let text = this.pending.join('');
46
+ this.pending = [];
47
+ this.size = 0;
48
+ const pieces = [];
49
+ while (text.length > MAX_BATCH_CHARS) {
50
+ const cut = safeCut(text, MAX_BATCH_CHARS);
51
+ pieces.push(text.slice(0, cut));
52
+ text = text.slice(cut);
53
+ }
54
+ if (text.length > 0)
55
+ pieces.push(text);
56
+ return pieces;
57
+ }
58
+ }
59
+ /** The line naming what was dropped, at its longest, as renderOutput puts it between the head and the tail. */
60
+ const DROPPED_LINE_CHARS = `\n[… ${Number.MAX_SAFE_INTEGER} characters of output dropped here …]\n`.length;
61
+ /**
62
+ * The stretch as the model sees it: the head, a line naming what was dropped
63
+ * if anything was, and the tail. Past `max`, its start and its end are cut
64
+ * alike to fit it, each taking the room the other doesn't need, and the count
65
+ * takes in what they gave up, so a return held to its agent's inline cap
66
+ * still shows both ends. A `max` that leaves no room for that line gets the
67
+ * line alone, which passes it.
68
+ */
69
+ export function renderOutput(w, max = Infinity) {
70
+ const whole = w.dropped === 0 ? w.head + w.tail : `${w.head}\n[… ${w.dropped} characters of output dropped here …]\n${w.tail}`;
71
+ if (whole.length <= max)
72
+ return whole;
73
+ const room = Math.max(0, Math.floor(max) - DROPPED_LINE_CHARS);
74
+ // With nothing dropped yet, the head and the tail are one stretch, whose end
75
+ // lies in the head while the tail is short or empty: it's cut as one.
76
+ const [first, last] = w.dropped === 0 ? [whole, whole] : [w.head, w.tail];
77
+ const lastKeep = Math.min(last.length, Math.max(Math.floor(room / 2), room - first.length));
78
+ const head = first.slice(0, safeCut(first, Math.min(first.length, room - lastKeep)));
79
+ // Kept from the end, never starting on a pair's second half.
80
+ let from = last.length - lastKeep;
81
+ const at = last.charCodeAt(from);
82
+ if (from > 0 && at >= 0xdc00 && at <= 0xdfff)
83
+ from += 1;
84
+ const tail = last.slice(from);
85
+ const dropped = w.dropped === 0 ? whole.length - head.length - tail.length : w.dropped + (first.length - head.length) + from;
86
+ return `${head}\n[… ${dropped} characters of output dropped here …]\n${tail}`;
87
+ }
88
+ /** The parent's side: the head and tail of what arrived since the last return, and the count dropped between. */
89
+ export class WindowOutput {
90
+ bounds;
91
+ head = '';
92
+ tail = '';
93
+ dropped = 0;
94
+ constructor(bounds) {
95
+ this.bounds = bounds;
96
+ }
97
+ /** Add text the child flushed. */
98
+ apply(text) {
99
+ let rest = text;
100
+ if (this.tail.length === 0 && this.dropped === 0) {
101
+ const room = this.bounds.headChars - this.head.length;
102
+ if (room > 0) {
103
+ const cut = safeCut(rest, room);
104
+ this.head += rest.slice(0, cut);
105
+ rest = rest.slice(cut);
106
+ if (rest.length === 0)
107
+ return;
108
+ }
109
+ }
110
+ this.tail += rest;
111
+ const over = this.tail.length - this.bounds.tailChars;
112
+ if (over > 0) {
113
+ // Drop from the front, never splitting a pair: the cut moves later by one if it would.
114
+ let cut = over;
115
+ const at = this.tail.charCodeAt(cut - 1);
116
+ if (at >= 0xd800 && at <= 0xdbff)
117
+ cut += 1;
118
+ this.dropped += cut;
119
+ this.tail = this.tail.slice(cut);
120
+ }
121
+ }
122
+ /** Characters dropped from the stretch so far. */
123
+ get droppedChars() {
124
+ return this.dropped;
125
+ }
126
+ /** The stretch as it stands. */
127
+ window() {
128
+ return { head: this.head, tail: this.tail, dropped: this.dropped };
129
+ }
130
+ /** The stretch as the model sees it, whole (renderOutput). */
131
+ render() {
132
+ return renderOutput(this.window());
133
+ }
134
+ /** The stretch, and a fresh one from here. */
135
+ take() {
136
+ const window = this.window();
137
+ this.head = '';
138
+ this.tail = '';
139
+ this.dropped = 0;
140
+ return window;
141
+ }
142
+ }
143
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../src/code-execution/isolate/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH,MAAM,CAAC,MAAM,qBAAqB,GAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAE1F,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,4GAA4G;AAC5G,SAAS,OAAO,CAAC,IAAY,EAAE,EAAU;IACvC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACvC,OAAO,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5D,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CAAC,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The guest's prelude: JavaScript the engine evaluates before a script, which
3
+ * builds what a script meets from the binding's two globals, `__host(name,
4
+ * argsJson)` and `__output(stream, text)`:
5
+ *
6
+ * - `tools[name](args)`, each tool by its exact name, answering one result
7
+ * shape, `{ content, structuredContent, isError }`. A refusal before
8
+ * dispatch rejects with an Error carrying the refusal's fields. Reading a
9
+ * name that isn't a tool throws at once, naming the close matches.
10
+ * At most MAX_CALLS_IN_FLIGHT are out at once, and one past them waits
11
+ * here, in the script's own memory, until one is answered.
12
+ * - `ALL_TOOLS`, each tool's name, description and input schema.
13
+ * - `text(value)` and `console.log/info/warn/error/debug(...)`, which write
14
+ * the script's output: a string as it is, anything else as JSON.
15
+ * - `wake_agent(payload)`, which asks the host to wake the agent.
16
+ * - `__run(src)`, which runs a script as the body of an async function, so it
17
+ * may `await` at its top level and `return` a value.
18
+ *
19
+ * Nothing here guards a boundary: the guest's whole world is this instance,
20
+ * and every call it makes is checked by the host. Built-ins aren't frozen, so a
21
+ * script that patches one breaks only itself: its calls and its ending are
22
+ * recorded outside the guest.
23
+ *
24
+ * Adapted from pi-codemode's guest prelude (`@earendil-works/pi-codemode`
25
+ * 1.3.0, `dist/runtime/prelude-source.js`): the tools proxy and its
26
+ * close-match error, the output helpers and the error formatting. Its licence,
27
+ * the LICENSE at the root of github.com/earendil-works/pi, which the package's
28
+ * `license: "MIT"` refers to:
29
+ *
30
+ * MIT License. Copyright (c) 2025 Mario Zechner. Permission is hereby granted,
31
+ * free of charge, to any person obtaining a copy of this software and
32
+ * associated documentation files (the "Software"), to deal in the Software
33
+ * without restriction, including without limitation the rights to use, copy,
34
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the
35
+ * Software, and to permit persons to whom the Software is furnished to do so,
36
+ * subject to the following conditions: The above copyright notice and this
37
+ * permission notice shall be included in all copies or substantial portions
38
+ * of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
39
+ * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
41
+ * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
42
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
43
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
44
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
45
+ */
46
+ /** The host call name `wake_agent()` uses. Parentheses can't be in a tool's name, so it never names a tool. */
47
+ export declare const WAKE_CALL_NAME = "(wake_agent)";
48
+ /**
49
+ * How many lines QuickJS's async function constructor puts before a script's
50
+ * first line, and the filename it gives the script's code: a script's frames
51
+ * read `<input>:N:C`, with its own line N less this.
52
+ */
53
+ export declare const SCRIPT_LINE_OFFSET = 2;
54
+ /**
55
+ * A frame of the script's own code, as QuickJS writes one in a stack: " at
56
+ * NAME (PLACE)", or " at PLACE" for a syntax error, its PLACE at the end
57
+ * and the script's, `<input>:LINE:COLUMN`, its LINE of at most ten digits, as
58
+ * QuickJS writes a line (a 32-bit integer). A NAME may hold any character but
59
+ * a line feed, which the stack's lines are split at, so `[^]` rather than
60
+ * `.`, which stops at a carriage return and U+2028 and U+2029 too. The
61
+ * guest's copy of the rule (errorText) is given these two patterns as they
62
+ * are.
63
+ */
64
+ export declare const SCRIPT_FRAME: RegExp;
65
+ /** A script frame's place, at its end: its line is renumbered as the agent wrote it. */
66
+ export declare const SCRIPT_PLACE: RegExp;
67
+ /**
68
+ * A failure's frames as the agent reads them, one per line: the script's own,
69
+ * numbered as the agent wrote its lines, leaving out the prelude's frames and
70
+ * the engine's native ones. QuickJS gives an Error's stack as its frames
71
+ * alone, and nothing here adds the failure's name and message to it, so the
72
+ * script's frames are the lines shaped as its frames are (SCRIPT_FRAME): a
73
+ * line of a stack the script or its Error.prepareStackTrace set is one if it
74
+ * is shaped so, and isn't otherwise. A function's name holding a line feed
75
+ * splits its frame in two, and each half is read on its own, so the frame is
76
+ * lost unless a half is itself shaped as a frame. Code the script compiles at
77
+ * run time is named `<input>` as the script is, so the rule takes its frames
78
+ * for the script's: an eval's read at its string's lines less two, and a
79
+ * Function constructor's at its body's own lines, plus one for each line
80
+ * break in its parameters, since the constructor puts its parameters and two
81
+ * lines before the body, as the prelude's AsyncFunction does. The prelude's
82
+ * errorText applies this rule in the guest, to an Error the script logs,
83
+ * leading with the name and message, while a string the script logs, an
84
+ * Error's `stack` among them, shows as QuickJS or the script wrote it; the
85
+ * child applies the rule here to every failure's stack. The two are one rule:
86
+ * the guest is given the pair of patterns as they are, and the walk here
87
+ * reads SCRIPT_FRAME as SCRIPT_FRAME_IN_STACK and renumbers a place itself,
88
+ * as SCRIPT_PLACE says, so a change to one has to be made to all three, and
89
+ * tests hold them together.
90
+ */
91
+ export declare function scriptFrames(stack: string, max?: number): string;
92
+ /** One tool as the prelude lists it in ALL_TOOLS. */
93
+ export interface PreludeTool {
94
+ name: string;
95
+ description: string;
96
+ /** The tool's input schema, as the agent's own tool list gives it. */
97
+ inputSchema?: unknown;
98
+ }
99
+ /**
100
+ * The prelude, for these tools. The child, not the prelude, refuses a wake
101
+ * past the script's cap (child.ts). The tool list goes in as
102
+ * a JSON string the prelude parses, so a schema's `__proto__` key stays a key,
103
+ * as it would not in an object literal, and the prelude is one string the
104
+ * engine evaluates as global code.
105
+ */
106
+ export declare function preludeSource(tools: readonly PreludeTool[]): string;
107
+ /** The one line `start` evaluates after the prelude: the script, as a string literal, handed to `__run`. */
108
+ export declare function scriptCall(script: string): string;
109
+ //# sourceMappingURL=prelude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prelude.d.ts","sourceRoot":"","sources":["../../../../src/code-execution/isolate/prelude.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAKH,+GAA+G;AAC/G,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,QAAyC,CAAC;AACnE,wFAAwF;AACxF,eAAO,MAAM,YAAY,QAAiC,CAAC;AAS3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,MAAM,CAoClE;AAuCD,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAiNnE;AAED,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}