@desplega.ai/agent-swarm 2.7.9 → 2.8.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 (355) hide show
  1. package/dist/acp-adapter-t949vbbp.js +15 -0
  2. package/dist/{actions-g563mbn2.js → actions-7e9czc7s.js} +19 -19
  3. package/dist/{amp-adapter-q61w05eb.js → amp-adapter-gv6cbb7d.js} +2 -3
  4. package/dist/app-b9fbkp9v.js +20 -0
  5. package/dist/{assistant-p477rjwj.js → assistant-wjb7v4c7.js} +22 -22
  6. package/dist/{boot-args-schema-h4qj462e.js → boot-args-schema-2t37e0fe.js} +1 -1
  7. package/dist/{boot-reembed-n1ehfbsw.js → boot-reembed-a35nkyr1.js} +1 -1
  8. package/dist/{boot-reembed-qw4mc0pt.js → boot-reembed-gka3zas7.js} +1 -1
  9. package/dist/{boot-scrub-sweep-9w9jp4sm.js → boot-scrub-sweep-65sdnp6c.js} +3 -3
  10. package/dist/{boot-seeds-qdaf3sdy.js → boot-seeds-x42tzytw.js} +4 -5
  11. package/dist/{claude-adapter-348p5hx9.js → claude-adapter-v221b2fd.js} +7 -8
  12. package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-29eq09wd.js} +2 -2
  13. package/dist/{claude-managed-setup-7787fxtp.js → claude-managed-setup-9m6450zk.js} +2 -2
  14. package/dist/{claude-sdk-session-hbszbt8a.js → claude-sdk-session-0q0ptaba.js} +9066 -8818
  15. package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
  16. package/dist/{cli-21159vea.js → cli-0jzra9ad.js} +2 -2
  17. package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
  18. package/dist/{cli-k70e3x9e.js → cli-2wnq8jkz.js} +9 -9
  19. package/dist/{cli-cvs2r2vq.js → cli-2zp0et3v.js} +59 -6
  20. package/dist/{cli-650zv9q9.js → cli-334z18y3.js} +4 -4
  21. package/dist/{cli-12xyjhws.js → cli-3rkdne1h.js} +2 -2
  22. package/dist/{cli-2a8py3sx.js → cli-4txa0ter.js} +5 -7
  23. package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
  24. package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
  25. package/dist/{cli-v3cf1ts9.js → cli-6t09sdhy.js} +3 -3
  26. package/dist/{cli-qzt90yze.js → cli-6wxjceza.js} +8 -8
  27. package/dist/{cli-9aezs55w.js → cli-7b8sbmag.js} +8 -8
  28. package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
  29. package/dist/{cli-jfx48xrj.js → cli-7p1kvkck.js} +6 -6
  30. package/dist/{cli-b932gexn.js → cli-8aes17e4.js} +2 -2
  31. package/dist/{cli-3tqcamp6.js → cli-8fknbnhw.js} +14 -13
  32. package/dist/{cli-587857ys.js → cli-8kzasymh.js} +3 -3
  33. package/dist/{cli-sgs5k6yd.js → cli-a7wvp2km.js} +1 -1
  34. package/dist/{cli-varqt4d1.js → cli-abejgen1.js} +69 -22
  35. package/dist/{cli-rwymrnaz.js → cli-bsywb58a.js} +8 -8
  36. package/dist/{cli-btc9cb4c.js → cli-c55z5chy.js} +4 -6
  37. package/dist/{cli-ms5m5r1y.js → cli-deefvewm.js} +1 -1
  38. package/dist/{cli-p17970qv.js → cli-ee0b971j.js} +3 -3
  39. package/dist/cli-f3vq58d2.js +242 -0
  40. package/dist/{cli-3xcwp3z8.js → cli-ffhtssbp.js} +2 -2
  41. package/dist/{cli-hwprv9e4.js → cli-g70vxtjh.js} +2 -2
  42. package/dist/{cli-4t0fmf3z.js → cli-gxkx0zzp.js} +1 -1
  43. package/dist/{cli-neyag5p6.js → cli-h38x262p.js} +3365 -429
  44. package/dist/{cli-2ccpqyyf.js → cli-j790gp2w.js} +105 -22
  45. package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
  46. package/dist/{cli-vxh6acp7.js → cli-m23zjcy2.js} +10 -10
  47. package/dist/{cli-y8nbefpb.js → cli-m28atx8q.js} +12 -10
  48. package/dist/{cli-serm8zrx.js → cli-m4dqmnbp.js} +1 -1
  49. package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
  50. package/dist/{cli-y5rbvxhc.js → cli-n515ex5z.js} +14 -14
  51. package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
  52. package/dist/{cli-605nn699.js → cli-p1bq50aa.js} +894 -226
  53. package/dist/{cli-qkdmz8c8.js → cli-p1w18yhx.js} +1 -1
  54. package/dist/{cli-xk879m3k.js → cli-p2gfst4m.js} +52 -43
  55. package/dist/{cli-sya22y84.js → cli-pasjcnmj.js} +12 -12
  56. package/dist/{cli-0whpms1z.js → cli-qa4wdgsy.js} +5 -5
  57. package/dist/{cli-ejkvvqbe.js → cli-qfedvmcr.js} +50 -24
  58. package/dist/{cli-tqq0hspb.js → cli-qmqk2yc2.js} +1 -1
  59. package/dist/{cli-qmd3mse0.js → cli-qsnnd04k.js} +1 -1
  60. package/dist/{cli-agyaeef4.js → cli-qwca7s44.js} +3 -3
  61. package/dist/{cli-fayav105.js → cli-rfywm85n.js} +724 -792
  62. package/dist/{cli-zgv8gxgs.js → cli-rmmpt0wm.js} +6 -6
  63. package/dist/{cli-hae9j8sv.js → cli-rzsy6nc6.js} +12 -8
  64. package/dist/{cli-btf6fw39.js → cli-s7t6p9my.js} +1 -1
  65. package/dist/{cli-cseh6f8w.js → cli-sdtt3men.js} +1 -1
  66. package/dist/{cli-9r5gtwjr.js → cli-tk7cjj8h.js} +197 -2
  67. package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
  68. package/dist/{cli-gce09r66.js → cli-tqegb8eq.js} +3 -3
  69. package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
  70. package/dist/{cli-09kmfkmq.js → cli-wcg8x116.js} +1 -1
  71. package/dist/{cli-mnrkgg60.js → cli-wk18cm92.js} +5 -5
  72. package/dist/{cli-p0m0p34z.js → cli-x1wa213s.js} +3 -3
  73. package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
  74. package/dist/{cli-715t1gx6.js → cli-y97qxcfx.js} +9 -9
  75. package/dist/{cli-bc779n4v.js → cli-yq3zak69.js} +1 -1
  76. package/dist/cli.js +17 -17
  77. package/dist/{codex-adapter-ysq6bzha.js → codex-adapter-30j9bpzd.js} +5 -6
  78. package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
  79. package/dist/{codex-session-runner-qakzfx93.js → codex-session-runner-8vp57v8w.js} +5 -6
  80. package/dist/{commands-rs7hkv9r.js → commands-bngnz9g7.js} +3 -3
  81. package/dist/{controller-r5x9bg6e.js → controller-hxx8wwy1.js} +2 -2
  82. package/dist/{controllers-connect-498hrxvk.js → controllers-connect-e2b4gyxc.js} +20 -20
  83. package/dist/{cursor-adapter-d46qszer.js → cursor-adapter-n5nc3mfe.js} +1 -2
  84. package/dist/{db-s13dqhr6.js → db-bgm7vkc0.js} +3 -3
  85. package/dist/{db-pm96nhdb.js → db-c6np41ca.js} +12 -2
  86. package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
  87. package/dist/{dispatcher-j3h81t7m.js → dispatcher-jnybck15.js} +18 -18
  88. package/dist/{dsh-adapter-rw0d5rc4.js → dsh-adapter-nrhbrjz8.js} +1 -2
  89. package/dist/{easter-egg-3d-qtgfxgze.js → easter-egg-3d-533knw22.js} +1 -1
  90. package/dist/{embedding-space-xh8p4q4x.js → embedding-space-crsm2zp0.js} +6 -6
  91. package/dist/{embeddings-wp745m91.js → embeddings-e7z3f27f.js} +1 -1
  92. package/dist/{execute-2fzb9z74.js → execute-b3mrb1mv.js} +1 -1
  93. package/dist/{external-channel-ys21h3sy.js → external-channel-m77wf5z3.js} +2 -2
  94. package/dist/{fx-adapter-vz0b9z3g.js → fx-adapter-b6w0kf56.js} +7 -8
  95. package/dist/{google-generative-ai-ytpgncx9.js → google-generative-ai-h7s3e9kk.js} +1 -1
  96. package/dist/{google-vertex-tqhze5j7.js → google-vertex-fhxaafzw.js} +1 -1
  97. package/dist/{grok-adapter-spea7zkj.js → grok-adapter-4sqtebdk.js} +7 -8
  98. package/dist/handlers-kdjcyzdj.js +32 -0
  99. package/dist/heartbeat-xgb036sx.js +43 -0
  100. package/dist/{hook-amcj4s10.js → hook-5h02c9ga.js} +6 -6
  101. package/dist/{hook-bc6n49qn.js → hook-xsk1jbha.js} +5 -5
  102. package/dist/{http-7374brv5.js → http-txe7qhvn.js} +448 -165
  103. package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
  104. package/dist/{index-5a9jtqde.js → index-0rvk3vd4.js} +46 -46
  105. package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
  106. package/dist/{index-q5cmtbz5.js → index-4a0670yh.js} +15939 -14244
  107. package/dist/index-835xdgnm.js +33 -0
  108. package/dist/index-d469300x.js +37 -0
  109. package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
  110. package/dist/{index-hsad2t3r.js → index-m5gx1xd6.js} +38 -38
  111. package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
  112. package/dist/index-rzqwp11g.js +32 -0
  113. package/dist/{index-w4m9z29z.js → index-tvfafeyy.js} +1 -1
  114. package/dist/{index-c9y31ytf.js → index-vk63emp7.js} +979 -35
  115. package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
  116. package/dist/{index-p4hjwbvw.js → index-ysvbhg5m.js} +1 -1
  117. package/dist/{keepalive-wy29kbrg.js → keepalive-4zsrce78.js} +3 -3
  118. package/dist/lead-yqt47dkr.js +70 -0
  119. package/dist/{maintenance-h2ds9w6c.js → maintenance-86jvartk.js} +1 -1
  120. package/dist/{oauth-refresh-sweep-q7mtbyp3.js → oauth-refresh-sweep-j52kg9pr.js} +2 -2
  121. package/dist/{onboard-vw8r2fdw.js → onboard-c2aj5p8q.js} +3 -3
  122. package/dist/{opencode-adapter-mtb0953j.js → opencode-adapter-dsagkhtw.js} +5 -6
  123. package/dist/{otel-impl-j42czw3r.js → otel-impl-yyy203z8.js} +1 -1
  124. package/dist/{pi-mono-adapter-zk8pg9jr.js → pi-mono-adapter-546cd1cc.js} +9 -9
  125. package/dist/{pricing-refresh-x7nhv23d.js → pricing-refresh-1rgzqyzz.js} +2 -3
  126. package/dist/{rbac-roles-9044425x.js → rbac-roles-e70xfeyj.js} +4 -6
  127. package/dist/{rbac-roles-bzvee6cf.js → rbac-roles-q89qe8er.js} +3 -3
  128. package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
  129. package/dist/{render-v2-t7bn4skz.js → render-v2-k6tt107q.js} +9 -4
  130. package/dist/{resume-x94gemep.js → resume-cnnrjfxa.js} +6 -6
  131. package/dist/{runtime-breq6fmv.js → runtime-1hv06jsn.js} +1 -1
  132. package/dist/{session-access-q7dmqjvt.js → session-access-xkxkjw3n.js} +4 -4
  133. package/dist/{session-source-backfill-440ysamr.js → session-source-backfill-1d5pdwww.js} +2 -2
  134. package/dist/{setup-07n4727s.js → setup-se8q7gkc.js} +1 -1
  135. package/dist/{virtual-modules-z5h6mcyf.js → virtual-modules-gazyapte.js} +3 -3
  136. package/dist/{work-objects-pnq5y534.js → work-objects-1kxnbzy5.js} +22 -22
  137. package/dist/{worker-follow-up-7z1gfkr8.js → worker-follow-up-zqm8apt4.js} +18 -18
  138. package/dist/worker-j6xxtq7p.js +70 -0
  139. package/openapi.json +334 -7
  140. package/package.json +4 -4
  141. package/src/apps/catalog.generated.json +55 -0
  142. package/src/apps/definition.ts +11 -0
  143. package/src/apps/page-validator.ts +19 -0
  144. package/src/apps/store.ts +28 -8
  145. package/src/assets/key.ts +77 -4
  146. package/src/be/db/model-profiles.ts +147 -38
  147. package/src/be/db/session-labels.ts +57 -0
  148. package/src/be/db/session-tree.ts +51 -7
  149. package/src/be/db/slack-trees.ts +146 -0
  150. package/src/be/db/tasks/read.ts +107 -8
  151. package/src/be/db/workflow-run-definitions.ts +117 -0
  152. package/src/be/db-client.ts +8 -2
  153. package/src/be/db.ts +119 -87
  154. package/src/be/event-loop-lag.ts +146 -0
  155. package/src/be/mcp-overflow-sweep.ts +2 -1
  156. package/src/be/memory/constants.ts +14 -1
  157. package/src/be/memory/key-paths.ts +8 -0
  158. package/src/be/memory/providers/sqlite-store.ts +199 -18
  159. package/src/be/memory/task-learning.ts +79 -14
  160. package/src/be/memory/types.ts +24 -1
  161. package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
  162. package/src/be/migrations/279_backfill_learning_expiry.sql +15 -0
  163. package/src/be/migrations/281_model_profiles_pr2.sql +28 -0
  164. package/src/be/migrations/283_workflow_run_definitions.sql +14 -0
  165. package/src/be/model-profile-check.ts +284 -0
  166. package/src/be/model-tier-resolution.ts +112 -12
  167. package/src/be/multi-runtime.ts +27 -0
  168. package/src/be/runtime-pools/routing.ts +52 -4
  169. package/src/be/scripts/typecheck.ts +1 -0
  170. package/src/be/seed-scripts/catalog/dreaming-learnings.ts +552 -0
  171. package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +389 -14
  172. package/src/be/seed-scripts/catalog/dreaming-memtax.ts +6 -3
  173. package/src/be/seed-scripts/index.ts +9 -0
  174. package/src/be/steering.ts +8 -2
  175. package/src/be/swarm-config-guard.ts +2 -0
  176. package/src/commands/context-preamble.ts +258 -0
  177. package/src/commands/onboard/agent-fs-version.ts +1 -1
  178. package/src/commands/runner.ts +32 -1
  179. package/src/extensions/catalog.generated.json +3 -3
  180. package/src/fs/provider.ts +17 -3
  181. package/src/heartbeat/heartbeat.ts +17 -5
  182. package/src/heartbeat/index.ts +1 -0
  183. package/src/http/agents.ts +56 -4
  184. package/src/http/apps.ts +3 -1
  185. package/src/http/config.ts +2 -6
  186. package/src/http/core.ts +9 -3
  187. package/src/http/index.ts +12 -9
  188. package/src/http/memory.ts +9 -4
  189. package/src/http/model-profiles.ts +58 -10
  190. package/src/http/poll.ts +36 -3
  191. package/src/http/schedules.ts +42 -3
  192. package/src/http/sessions.ts +16 -3
  193. package/src/http/tasks.ts +37 -12
  194. package/src/http/utils.ts +18 -0
  195. package/src/http/webhooks.ts +48 -0
  196. package/src/http/workflows.ts +15 -2
  197. package/src/integrations/chat-sdk/commands.ts +167 -31
  198. package/src/integrations/chat-sdk/inbound.ts +10 -8
  199. package/src/integrations/chat-sdk/message-text.ts +117 -0
  200. package/src/prompts/session-templates.ts +1 -1
  201. package/src/providers/acp-targets.ts +11 -6
  202. package/src/providers/amp-adapter.ts +1 -1
  203. package/src/providers/claude-sdk-session.ts +132 -23
  204. package/src/providers/codex-skill-resolver.ts +10 -4
  205. package/src/providers/cursor-adapter.ts +1 -1
  206. package/src/providers/devin-skill-resolver.ts +5 -5
  207. package/src/providers/dsh-adapter.ts +1 -1
  208. package/src/scheduler/schedule-task.ts +1 -0
  209. package/src/scheduler/scheduler.ts +4 -1
  210. package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
  211. package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
  212. package/src/scripts-runtime/quickjs-compat.ts +0 -1
  213. package/src/scripts-runtime/sdk-allowlist.ts +1 -0
  214. package/src/scripts-runtime/swarm-sdk.ts +18 -1
  215. package/src/scripts-runtime/types/stdlib.d.ts +1 -0
  216. package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
  217. package/src/server.ts +2 -0
  218. package/src/slack/app.ts +425 -10
  219. package/src/slack/handlers.ts +9 -2
  220. package/src/slack/inbound-dispatch.ts +18 -1
  221. package/src/slack/index.ts +7 -1
  222. package/src/slack/lifecycle-lock.ts +29 -0
  223. package/src/slack/render-v2.ts +424 -212
  224. package/src/slack/socket-fence.ts +64 -0
  225. package/src/slack/watcher.ts +42 -8
  226. package/src/slack/workspace-guard.ts +345 -0
  227. package/src/tasks/task-terminal-effects.ts +4 -0
  228. package/src/tasks/worker-follow-up.ts +102 -2
  229. package/src/tests/acp-adapter.test.ts +82 -0
  230. package/src/tests/apps-icon.test.ts +120 -0
  231. package/src/tests/apps-schema-form.test.ts +151 -0
  232. package/src/tests/chained-task-follow-up.test.ts +248 -0
  233. package/src/tests/chat-sdk-commands.test.ts +359 -2
  234. package/src/tests/chat-sdk-inbound.test.ts +20 -0
  235. package/src/tests/chat-sdk-slack.test.ts +189 -1
  236. package/src/tests/check-pr-body.test.ts +40 -0
  237. package/src/tests/claude-sdk-lifecycle.test.ts +216 -1
  238. package/src/tests/claude-sdk-process.fixture.ts +57 -0
  239. package/src/tests/codex-skill-resolver.test.ts +31 -0
  240. package/src/tests/credentials-allowlist.test.ts +470 -0
  241. package/src/tests/db-client-busy-retry.test.ts +69 -18
  242. package/src/tests/db-client.test.ts +26 -1
  243. package/src/tests/db-task-read-contract.test.ts +7 -0
  244. package/src/tests/db-task-write-contract.test.ts +6 -0
  245. package/src/tests/deferred-wake-follow-up.test.ts +47 -0
  246. package/src/tests/docs-index-footprint.test.js +3 -3
  247. package/src/tests/dreaming-learnings.test.ts +1395 -0
  248. package/src/tests/dsh-adapter.test.ts +1 -1
  249. package/src/tests/event-loop-lag.test.ts +184 -0
  250. package/src/tests/explicit-model-validation.test.ts +2 -0
  251. package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
  252. package/src/tests/fs-provider.test.ts +42 -0
  253. package/src/tests/github-webhook-early-ack.test.ts +144 -0
  254. package/src/tests/heartbeat.test.ts +28 -1
  255. package/src/tests/http-api-integration.test.ts +2 -0
  256. package/src/tests/http-log-scrubbing.test.ts +68 -2
  257. package/src/tests/human-free-reclassify.test.ts +5 -1
  258. package/src/tests/kv-storage.test.ts +92 -1
  259. package/src/tests/list-endpoint-slimming.test.ts +17 -0
  260. package/src/tests/memory-key-paths.test.ts +57 -0
  261. package/src/tests/memory-retrieval-purge.test.ts +19 -0
  262. package/src/tests/migration-283-workflow-run-definitions.test.ts +69 -0
  263. package/src/tests/model-profile-check.test.ts +387 -0
  264. package/src/tests/model-profiles-api.test.ts +528 -1
  265. package/src/tests/profile-claim.test.ts +415 -3
  266. package/src/tests/profile-tier-alias.test.ts +382 -0
  267. package/src/tests/quickjs-compat.test.ts +1 -1
  268. package/src/tests/runner-context-preamble.test.ts +552 -0
  269. package/src/tests/schedule-profile.test.ts +359 -0
  270. package/src/tests/script-connections.test.ts +9 -0
  271. package/src/tests/script-executor-conformance.test.ts +188 -0
  272. package/src/tests/script-per-script-executor.test.ts +1 -0
  273. package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +141 -0
  274. package/src/tests/seed-scripts.test.ts +2 -2
  275. package/src/tests/sessions-tree.test.ts +133 -2
  276. package/src/tests/slack-app-icon.test.ts +4 -0
  277. package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
  278. package/src/tests/slack-file-tools-attachments.test.ts +1 -0
  279. package/src/tests/slack-inbound-receipts.test.ts +22 -2
  280. package/src/tests/slack-read-boundaries.test.ts +4 -3
  281. package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
  282. package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
  283. package/src/tests/slack-socket-ack.test.ts +16 -1
  284. package/src/tests/slack-socket-watchdog.test.ts +748 -0
  285. package/src/tests/slack-workspace-guard.test.ts +905 -0
  286. package/src/tests/steering-core.test.ts +40 -0
  287. package/src/tests/store-progress-learning.test.ts +605 -20
  288. package/src/tests/tool-annotations.test.ts +1 -1
  289. package/src/tests/vcs-identity-inheritance.test.ts +85 -0
  290. package/src/tests/workflow-convergence.test.ts +46 -40
  291. package/src/tests/workflow-definition-pinning-recovery.test.ts +552 -0
  292. package/src/tests/workflow-definition-pinning.test.ts +645 -0
  293. package/src/tests/workflow-executors.test.ts +16 -7
  294. package/src/tests/workflow-foreach.test.ts +43 -20
  295. package/src/tests/workflow-notify-slack-ready.test.ts +161 -0
  296. package/src/tests/workflow-profile.test.ts +328 -0
  297. package/src/tools/app-upsert.ts +1 -1
  298. package/src/tools/memory-edit.ts +2 -1
  299. package/src/tools/model-profiles/check-model-profile.ts +63 -0
  300. package/src/tools/schedules/create-schedule.ts +45 -4
  301. package/src/tools/schedules/patch-schedule.ts +50 -4
  302. package/src/tools/schedules/update-schedule.ts +50 -4
  303. package/src/tools/send-task.ts +17 -2
  304. package/src/tools/store-progress.ts +15 -3
  305. package/src/tools/task-action.ts +9 -1
  306. package/src/tools/templates.ts +13 -0
  307. package/src/tools/tool-config.ts +2 -1
  308. package/src/tools/utils.ts +77 -11
  309. package/src/tools/workflows/create-workflow.ts +1 -1
  310. package/src/tools/workflows/retry-workflow-run.ts +1 -1
  311. package/src/tools/workflows/update-workflow.ts +10 -1
  312. package/src/types.ts +56 -1
  313. package/src/utils/credentials.ts +89 -12
  314. package/src/workflows/engine.ts +10 -1
  315. package/src/workflows/executors/agent-task.ts +21 -2
  316. package/src/workflows/executors/foreach.ts +4 -1
  317. package/src/workflows/executors/notify.ts +62 -6
  318. package/src/workflows/executors/sub-workflow.ts +1 -1
  319. package/src/workflows/executors/swarm-script.ts +4 -1
  320. package/src/workflows/foreach-driver.ts +8 -5
  321. package/src/workflows/limits.ts +2 -1
  322. package/src/workflows/model-validation.ts +27 -2
  323. package/src/workflows/patch-definition.ts +3 -1
  324. package/src/workflows/recovery.ts +6 -6
  325. package/src/workflows/resume.ts +9 -9
  326. package/src/workflows/retry-poller.ts +2 -2
  327. package/templates/extensions/comms-adherence-gate/README.md +25 -0
  328. package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
  329. package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
  330. package/templates/skills/apps/SKILL.md +9 -0
  331. package/templates/skills/apps/content.md +9 -0
  332. package/templates/skills/code-quality/content.md +12 -0
  333. package/templates/skills/memory/content.md +8 -0
  334. package/templates/skills/scheduling/config.json +1 -1
  335. package/templates/skills/scheduling/content.md +2 -2
  336. package/templates/skills/swarm-docs/content.md +4 -0
  337. package/templates/skills/swarm-extensions/content.md +1 -1
  338. package/templates/skills/swarm-scripts/SKILL.md +1 -1
  339. package/templates/skills/swarm-scripts/content.md +1 -1
  340. package/templates/skills/work-on-task/SKILL.md +2 -0
  341. package/templates/skills/work-on-task/content.md +2 -0
  342. package/templates/workflows/dreaming/content.md +174 -7
  343. package/dist/acp-adapter-dn4gdsgr.js +0 -16
  344. package/dist/app-a66ssc4k.js +0 -17
  345. package/dist/cli-530hkwdy.js +0 -779
  346. package/dist/cli-a0657jmf.js +0 -339
  347. package/dist/cli-cyn9v8zr.js +0 -748
  348. package/dist/handlers-crckt5dq.js +0 -32
  349. package/dist/heartbeat-8phn1kdq.js +0 -41
  350. package/dist/index-4x08sjtk.js +0 -30
  351. package/dist/index-8ybffts4.js +0 -37
  352. package/dist/index-nfy4kkg5.js +0 -33
  353. package/dist/lead-zdqxsvjn.js +0 -71
  354. package/dist/worker-y62rvvq3.js +0 -71
  355. package/dist/{cli-gxy8y1dt.js → cli-8bpgbr8k.js} +3 -3
@@ -0,0 +1,359 @@
1
+ // `profile` on schedules (plan phase 6): create, update and patch validate it
2
+ // with the profile check when the target agent is known, profile and
3
+ // model/modelTier are exclusive (setting one clears the other), and a fired
4
+ // task carries the schedule's profile. HTTP and the MCP tools agree.
5
+
6
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7
+ import { unlink } from "node:fs/promises";
8
+ import { createServer, type Server } from "node:http";
9
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
11
+ import {
12
+ closeDb,
13
+ createAgent,
14
+ createScheduledTask,
15
+ getDbClient,
16
+ getScheduledTaskById,
17
+ initDb,
18
+ } from "../be/db";
19
+ import { updateAgentCredStatus } from "../be/db/agents";
20
+ import { createModelProfile, deleteModelProfile } from "../be/db/model-profiles";
21
+ import { reloadModelsCatalog } from "../be/model-catalog-store";
22
+ import { handleSchedules } from "../http/schedules";
23
+ import { registerCreateScheduleTool } from "../tools/schedules/create-schedule";
24
+ import { registerPatchScheduleTool } from "../tools/schedules/patch-schedule";
25
+ import { registerUpdateScheduleTool } from "../tools/schedules/update-schedule";
26
+ import type { AgentCredStatus } from "../types";
27
+ import { setRequestAuth } from "../utils/request-auth-context";
28
+ import { listenOnFreePort } from "./test-net";
29
+
30
+ const TEST_DB_PATH = "./test-schedule-profile.sqlite";
31
+
32
+ async function removeDbFiles(path: string): Promise<void> {
33
+ for (const suffix of ["", "-wal", "-shm"]) {
34
+ await unlink(path + suffix).catch(() => undefined);
35
+ }
36
+ }
37
+
38
+ const READY: AgentCredStatus = {
39
+ ready: true,
40
+ missing: [],
41
+ satisfiedBy: "env",
42
+ hint: null,
43
+ liveTest: null,
44
+ latestModel: null,
45
+ reportedAt: Date.now(),
46
+ reportKind: "boot",
47
+ bedrock: null,
48
+ acp: null,
49
+ };
50
+
51
+ let server: Server;
52
+ let baseUrl = "";
53
+ let claudeId = "";
54
+ let codexId = "";
55
+ let mcp: McpServer;
56
+
57
+ beforeAll(async () => {
58
+ await removeDbFiles(TEST_DB_PATH);
59
+ initDb(TEST_DB_PATH);
60
+ await reloadModelsCatalog();
61
+ claudeId = (
62
+ await createAgent({
63
+ name: "sp-claude",
64
+ isLead: false,
65
+ status: "idle",
66
+ harnessProvider: "claude",
67
+ })
68
+ ).id;
69
+ await updateAgentCredStatus(claudeId, READY);
70
+ codexId = (
71
+ await createAgent({ name: "sp-codex", isLead: false, status: "idle", harnessProvider: "codex" })
72
+ ).id;
73
+ await updateAgentCredStatus(codexId, READY);
74
+ await createModelProfile({ name: "sp-claude-opus", harness: "claude", model: "opus" });
75
+ await createModelProfile({ name: "sp-claude-held", harness: "claude", model: "sonnet" });
76
+
77
+ server = createServer((req, res) => {
78
+ setRequestAuth(req, { kind: "operator", fingerprint: "schedule-profile-test" });
79
+ const url = new URL(req.url ?? "/", "http://localhost");
80
+ const segments = url.pathname.split("/").filter(Boolean);
81
+ void (async () => {
82
+ res.setHeader("Content-Type", "application/json");
83
+ if (await handleSchedules(req, res, segments, url.searchParams, undefined)) return;
84
+ res.writeHead(404);
85
+ res.end("{}");
86
+ })();
87
+ });
88
+ baseUrl = `http://localhost:${await listenOnFreePort(server)}`;
89
+
90
+ mcp = new McpServer({ name: "schedule-profile-test", version: "1.0.0" });
91
+ registerCreateScheduleTool(mcp);
92
+ registerUpdateScheduleTool(mcp);
93
+ registerPatchScheduleTool(mcp);
94
+ });
95
+
96
+ afterAll(async () => {
97
+ server.close();
98
+ closeDb();
99
+ await removeDbFiles(TEST_DB_PATH);
100
+ });
101
+
102
+ async function api(method: string, path: string, body?: unknown) {
103
+ const res = await fetch(`${baseUrl}${path}`, {
104
+ method,
105
+ headers: { "content-type": "application/json" },
106
+ body: body === undefined ? undefined : JSON.stringify(body),
107
+ });
108
+ const text = await res.text();
109
+ return { status: res.status, body: text ? (JSON.parse(text) as Record<string, any>) : {} };
110
+ }
111
+
112
+ type ToolOutput = { success: boolean; message: string; schedule?: Record<string, any> };
113
+
114
+ async function tool(name: string, args: Record<string, unknown>): Promise<ToolOutput> {
115
+ const tools = (
116
+ mcp as unknown as {
117
+ _registeredTools: Record<
118
+ string,
119
+ { handler: (a: unknown, e: unknown) => Promise<CallToolResult> }
120
+ >;
121
+ }
122
+ )._registeredTools;
123
+ const result = await tools[name]!.handler(args, {
124
+ sessionId: "schedule-profile-test",
125
+ requestInfo: { headers: { "x-agent-id": claudeId } },
126
+ });
127
+ return result.structuredContent as ToolOutput;
128
+ }
129
+
130
+ let counter = 0;
131
+ function scheduleName(): string {
132
+ counter++;
133
+ return `sp-${counter}-${Date.now()}`;
134
+ }
135
+
136
+ function base(extra: Record<string, unknown> = {}) {
137
+ return { name: scheduleName(), taskTemplate: "tick", intervalMs: 3_600_000, ...extra };
138
+ }
139
+
140
+ describe("HTTP create", () => {
141
+ test("a profile on a passing agent saves, and the fired task carries it", async () => {
142
+ const created = await api(
143
+ "POST",
144
+ "/api/schedules",
145
+ base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
146
+ );
147
+ expect(created.status).toBe(201);
148
+ expect(created.body.profile).toBe("sp-claude-opus");
149
+
150
+ const fired = await api("POST", `/api/schedules/${created.body.id}/run`);
151
+ expect(fired.status).toBe(200);
152
+ expect(fired.body.task.profile).toBe("sp-claude-opus");
153
+ const row = await getDbClient().get<{ profile: string | null }>(
154
+ "SELECT profile FROM agent_tasks WHERE id = ?",
155
+ [fired.body.task.id],
156
+ );
157
+ expect(row?.profile).toBe("sp-claude-opus");
158
+ });
159
+
160
+ test("a pool schedule takes a profile without an agent check", async () => {
161
+ const created = await api("POST", "/api/schedules", base({ profile: "sp-claude-opus" }));
162
+ expect(created.status).toBe(201);
163
+ expect(created.body.profile).toBe("sp-claude-opus");
164
+ });
165
+
166
+ test("an agent that fails the check is a 400", async () => {
167
+ const res = await api(
168
+ "POST",
169
+ "/api/schedules",
170
+ base({ targetAgentId: codexId, profile: "sp-claude-opus" }),
171
+ );
172
+ expect(res.status).toBe(400);
173
+ expect(String(res.body.error)).toContain('Model profile "sp-claude-opus" fails harness');
174
+ });
175
+
176
+ test("an unknown profile is a 400", async () => {
177
+ const res = await api("POST", "/api/schedules", base({ profile: "sp-no-such-profile" }));
178
+ expect(res.status).toBe(400);
179
+ expect(String(res.body.error)).toContain('Unknown model profile "sp-no-such-profile"');
180
+ });
181
+
182
+ test("profile together with model or modelTier is a 400", async () => {
183
+ for (const extra of [{ model: "opus" }, { modelTier: "smart" }]) {
184
+ const res = await api(
185
+ "POST",
186
+ "/api/schedules",
187
+ base({ targetAgentId: claudeId, profile: "sp-claude-opus", ...extra }),
188
+ );
189
+ expect(res.status).toBe(400);
190
+ expect(String(res.body.error)).toContain("not both");
191
+ }
192
+ });
193
+ });
194
+
195
+ describe("HTTP update and patch", () => {
196
+ test("setting profile clears model and modelTier; setting modelTier clears profile", async () => {
197
+ for (const method of ["PUT", "PATCH"]) {
198
+ const created = await api(
199
+ "POST",
200
+ "/api/schedules",
201
+ base({ targetAgentId: claudeId, modelTier: "smart" }),
202
+ );
203
+ expect(created.status).toBe(201);
204
+ const id = created.body.id as string;
205
+
206
+ const set = await api(method, `/api/schedules/${id}`, { profile: "sp-claude-opus" });
207
+ expect(set.status).toBe(200);
208
+ expect(set.body.profile).toBe("sp-claude-opus");
209
+ expect(set.body.modelTier).toBeUndefined();
210
+ expect(set.body.model).toBeUndefined();
211
+
212
+ const back = await api(method, `/api/schedules/${id}`, { modelTier: "regular" });
213
+ expect(back.status).toBe(200);
214
+ expect(back.body.modelTier).toBe("regular");
215
+ expect(back.body.profile).toBeUndefined();
216
+ }
217
+ });
218
+
219
+ test("setting model clears profile, and null clears it", async () => {
220
+ const created = await api(
221
+ "POST",
222
+ "/api/schedules",
223
+ base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
224
+ );
225
+ const id = created.body.id as string;
226
+ const model = await api("PATCH", `/api/schedules/${id}`, { model: "sonnet" });
227
+ expect(model.status).toBe(200);
228
+ expect(model.body.profile).toBeUndefined();
229
+
230
+ const reset = await api("PATCH", `/api/schedules/${id}`, {
231
+ model: null,
232
+ profile: "sp-claude-opus",
233
+ });
234
+ expect(reset.body.profile).toBe("sp-claude-opus");
235
+ expect((await getScheduledTaskById(id))?.profile).toBe("sp-claude-opus");
236
+ const cleared = await api("PATCH", `/api/schedules/${id}`, { profile: null });
237
+ expect(cleared.status).toBe(200);
238
+ expect(cleared.body.profile).toBeUndefined();
239
+ // The stored row, not just the response: PATCH null clears the column.
240
+ expect((await getScheduledTaskById(id))?.profile ?? null).toBeNull();
241
+ });
242
+
243
+ test("profile and model in one body is a 400", async () => {
244
+ const created = await api("POST", "/api/schedules", base({ targetAgentId: claudeId }));
245
+ const id = created.body.id as string;
246
+ for (const method of ["PUT", "PATCH"]) {
247
+ const res = await api(method, `/api/schedules/${id}`, {
248
+ profile: "sp-claude-opus",
249
+ modelTier: "smart",
250
+ });
251
+ expect(res.status).toBe(400);
252
+ expect(String(res.body.error)).toContain("not both");
253
+ }
254
+ });
255
+
256
+ test("a new profile, or a move to an agent that fails it, is re-checked", async () => {
257
+ const created = await api("POST", "/api/schedules", base({ targetAgentId: codexId }));
258
+ const codexSchedule = created.body.id as string;
259
+ const refused = await api("PUT", `/api/schedules/${codexSchedule}`, {
260
+ profile: "sp-claude-opus",
261
+ });
262
+ expect(refused.status).toBe(400);
263
+ expect(String(refused.body.error)).toContain("fails harness");
264
+
265
+ const profiled = await api(
266
+ "POST",
267
+ "/api/schedules",
268
+ base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
269
+ );
270
+ const id = profiled.body.id as string;
271
+ for (const method of ["PUT", "PATCH"]) {
272
+ const moved = await api(method, `/api/schedules/${id}`, { targetAgentId: codexId });
273
+ expect(moved.status).toBe(400);
274
+ expect(String(moved.body.error)).toContain("fails harness");
275
+ }
276
+ const unrelated = await api("PATCH", `/api/schedules/${id}`, { description: "still claude" });
277
+ expect(unrelated.status).toBe(200);
278
+ expect(unrelated.body.profile).toBe("sp-claude-opus");
279
+ });
280
+
281
+ test("an unknown profile on update is a 400", async () => {
282
+ const created = await api("POST", "/api/schedules", base());
283
+ const res = await api("PATCH", `/api/schedules/${created.body.id}`, {
284
+ profile: "sp-no-such-profile",
285
+ });
286
+ expect(res.status).toBe(400);
287
+ expect(String(res.body.error)).toContain("Unknown model profile");
288
+ });
289
+ });
290
+
291
+ describe("schedule reference guard", () => {
292
+ test("a profile a schedule names cannot be deleted", async () => {
293
+ await createScheduledTask({
294
+ name: scheduleName(),
295
+ intervalMs: 3_600_000,
296
+ taskTemplate: "tick",
297
+ profile: "sp-claude-held",
298
+ });
299
+ expect(await deleteModelProfile("sp-claude-held")).toBe("in-use");
300
+ });
301
+ });
302
+
303
+ describe("MCP tool parity", () => {
304
+ test("create-schedule: passing agent saves, failing agent and profile+model refuse", async () => {
305
+ const ok = await tool("create-schedule", {
306
+ ...base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
307
+ });
308
+ expect(ok.success).toBe(true);
309
+ expect(ok.schedule?.profile).toBe("sp-claude-opus");
310
+
311
+ const failing = await tool("create-schedule", {
312
+ ...base({ targetAgentId: codexId, profile: "sp-claude-opus" }),
313
+ });
314
+ expect(failing.success).toBe(false);
315
+ expect(failing.message).toContain("fails harness");
316
+
317
+ const both = await tool("create-schedule", {
318
+ ...base({ targetAgentId: claudeId, profile: "sp-claude-opus", modelTier: "smart" }),
319
+ });
320
+ expect(both.success).toBe(false);
321
+ expect(both.message).toContain("not both");
322
+ });
323
+
324
+ for (const name of ["update-schedule", "patch-schedule"]) {
325
+ test(`${name}: setting profile clears modelTier, the reverse clears profile, a fail refuses`, async () => {
326
+ const schedule = await createScheduledTask({
327
+ name: scheduleName(),
328
+ intervalMs: 3_600_000,
329
+ taskTemplate: "tick",
330
+ targetAgentId: claudeId,
331
+ modelTier: "smart",
332
+ createdByAgentId: claudeId,
333
+ });
334
+ const set = await tool(name, { scheduleId: schedule.id, profile: "sp-claude-opus" });
335
+ expect(set.success).toBe(true);
336
+ let row = await getScheduledTaskById(schedule.id);
337
+ expect(row?.profile).toBe("sp-claude-opus");
338
+ expect(row?.modelTier).toBeUndefined();
339
+
340
+ const both = await tool(name, {
341
+ scheduleId: schedule.id,
342
+ profile: "sp-claude-opus",
343
+ model: "opus",
344
+ });
345
+ expect(both.success).toBe(false);
346
+ expect(both.message).toContain("not both");
347
+
348
+ const moved = await tool(name, { scheduleId: schedule.id, targetAgentId: codexId });
349
+ expect(moved.success).toBe(false);
350
+ expect(moved.message).toContain("fails harness");
351
+
352
+ const back = await tool(name, { scheduleId: schedule.id, modelTier: "regular" });
353
+ expect(back.success).toBe(true);
354
+ row = await getScheduledTaskById(schedule.id);
355
+ expect(row?.modelTier).toBe("regular");
356
+ expect(row?.profile).toBeUndefined();
357
+ });
358
+ }
359
+ });
@@ -682,6 +682,15 @@ describe("script connections", () => {
682
682
  markMigrationApplied(database, "269_pages_design_system.sql");
683
683
  // 271 normalizes session_costs, which this migration-112-only fixture lacks.
684
684
  markMigrationApplied(database, "271_subscription_usage_model.sql");
685
+ // 278 indexes agent_tasks columns and alters slack_messages, neither of
686
+ // which this fixture's partial schema has.
687
+ markMigrationApplied(database, "278_slack_render_v2_reconcile.sql");
688
+ // 279 backfills agent_memory, which this migration-112-only fixture does not create.
689
+ markMigrationApplied(database, "279_backfill_learning_expiry.sql");
690
+ // 281 alters model_profiles (made by the skipped 220) and scheduled_tasks.
691
+ markMigrationApplied(database, "281_model_profiles_pr2.sql");
692
+ // 283 alters workflow_runs, which this fixture does not create.
693
+ markMigrationApplied(database, "283_workflow_run_definitions.sql");
685
694
 
686
695
  const id = crypto.randomUUID();
687
696
  const now = new Date().toISOString();
@@ -151,6 +151,102 @@ const echoServer = Bun.serve({
151
151
  afterAll(() => echoServer.stop(true));
152
152
 
153
153
  const PARITY_PROBES: Record<string, string> = {
154
+ "structuredClone graphs and built-ins": `async () => {
155
+ class Model { constructor() { this.value = 7; } }
156
+ const shared = { value: 1 };
157
+ const original = { shared, again: shared, model: new Model(), array: [, undefined, -0, NaN, Infinity, 12n] };
158
+ original.self = original;
159
+ const copy = structuredClone(original);
160
+ copy.shared.value = 2;
161
+ const date = structuredClone(new Date(123));
162
+ const regexp = /hello/gi;
163
+ regexp.lastIndex = 4;
164
+ const clonedRegexp = structuredClone(regexp);
165
+ const map = new Map([[shared, shared]]);
166
+ map.set(map, new Set([shared, map]));
167
+ const clonedMap = structuredClone(map);
168
+ const key = [...clonedMap.keys()][0];
169
+ const boxed = [new Boolean(false), new Number(NaN), new String('text'), Object(12n)].map(value => {
170
+ const cloned = structuredClone(value);
171
+ return [typeof cloned, typeof cloned.valueOf(), String(cloned.valueOf()), cloned !== value];
172
+ });
173
+ return {
174
+ cycle: copy.self === copy, shared: copy.shared === copy.again, independent: shared.value === 1,
175
+ model: [Object.getPrototypeOf(copy.model) === Object.prototype, copy.model.value],
176
+ array: [copy.array.length, 0 in copy.array, 1 in copy.array, Object.is(copy.array[2], -0), Number.isNaN(copy.array[3]), copy.array[4] === Infinity, String(copy.array[5])],
177
+ date: [date instanceof Date, date.getTime()],
178
+ regexp: [clonedRegexp instanceof RegExp, clonedRegexp.source, clonedRegexp.flags, clonedRegexp.lastIndex],
179
+ map: [clonedMap instanceof Map, key !== shared, clonedMap.get(key) === key, clonedMap.get(clonedMap) instanceof Set, clonedMap.get(clonedMap).has(key), clonedMap.get(clonedMap).has(clonedMap)],
180
+ boxed,
181
+ };
182
+ }`,
183
+ "structuredClone error subtypes": `async () => {
184
+ const types = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError];
185
+ const errors = types.map(Type => {
186
+ const error = new Type('bad');
187
+ error.extra = 'ignored';
188
+ const cloned = structuredClone(error);
189
+ return [cloned instanceof Type, cloned.name, cloned.message, Object.hasOwn(cloned, 'extra')];
190
+ });
191
+ return errors;
192
+ }`,
193
+ "structuredClone ignores overridden binary accessors": `async () => {
194
+ const buffer = new ArrayBuffer(16);
195
+ new Uint8Array(buffer).set([1, 2, 3, 4]);
196
+ buffer.slice = () => buffer;
197
+ Object.defineProperty(buffer, 'byteLength', { get() { throw Error('byteLength'); } });
198
+ const view = new Uint16Array(buffer, 2, 3);
199
+ view.constructor = Array;
200
+ for (const name of ['buffer', 'byteOffset', 'byteLength', 'length']) {
201
+ Object.defineProperty(view, name, { get() { throw Error(name); } });
202
+ }
203
+ Object.defineProperty(view, Symbol.toStringTag, { get() { throw Error('tag'); } });
204
+ const data = new DataView(buffer, 1, 4);
205
+ const copy = structuredClone({ buffer, view, data });
206
+ new Uint8Array(copy.buffer)[0] = 9;
207
+ const typed = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array].map(Type => {
208
+ const value = new Type(2);
209
+ const cloned = structuredClone(value);
210
+ return [cloned instanceof Type, cloned.length, cloned.buffer !== value.buffer];
211
+ });
212
+ return {
213
+ independent: copy.buffer !== buffer && new Uint8Array(buffer)[0] === 1,
214
+ bytes: Array.from(new Uint8Array(copy.buffer)),
215
+ view: [copy.view instanceof Uint16Array, copy.view.buffer === copy.buffer, copy.view.byteOffset, copy.view.length],
216
+ data: [copy.data instanceof DataView, copy.data.buffer === copy.buffer, copy.data.byteOffset, copy.data.byteLength],
217
+ typed,
218
+ };
219
+ }`,
220
+ "structuredClone property snapshots and symbols": `async () => {
221
+ const original = {
222
+ get a() { delete this.b; this.c = 3; return 1; }, b: 2,
223
+ get [Symbol.toStringTag]() { throw Error('symbol getter ran'); },
224
+ };
225
+ Object.defineProperty(original, '__proto__', { value: { marker: true }, enumerable: true });
226
+ Object.defineProperty(original, 'hidden', { get() { throw Error('hidden getter ran'); } });
227
+ const copy = structuredClone(original);
228
+ return {
229
+ keys: Object.keys(copy), a: copy.a, hasB: Object.hasOwn(copy, 'b'), hasC: Object.hasOwn(copy, 'c'),
230
+ proto: [Object.getPrototypeOf(copy) === Object.prototype, Object.hasOwn(copy, '__proto__'), copy.__proto__.marker],
231
+ symbols: Object.getOwnPropertySymbols(copy).length,
232
+ };
233
+ }`,
234
+ "structuredClone rejects uncloneable values": `async () => {
235
+ const failures = [Symbol('x'), Object(Symbol('x')), () => {}, new WeakMap(), new WeakSet(), Promise.resolve(1), { nested: () => {} }];
236
+ return failures.map(value => {
237
+ try { structuredClone(value); return 'accepted'; } catch(error) { return error.name; }
238
+ });
239
+ }`,
240
+ "structuredClone argument and getter behavior": `async () => {
241
+ const thrown = new RangeError('getter');
242
+ const getter = { get value() { throw thrown; } };
243
+ const copy = structuredClone({ value: 1 }, { transfer: [] });
244
+ let missing;
245
+ try { structuredClone(); } catch (error) { missing = error.name; }
246
+ let sameError;
247
+ try { structuredClone(getter); } catch (error) { sameError = error === thrown; }
248
+ return { copy, missing, sameError };
249
+ }`,
154
250
  URL: `async () => {
155
251
  const cases = [
156
252
  ["https://user:pa ss@Example.COM:443/a/./b/../c d?q=1 2&x='y'#frag ment"],
@@ -383,6 +479,98 @@ describe("quickjs parity shims match native and Bun", () => {
383
479
  }
384
480
  });
385
481
 
482
+ describe("quickjs structuredClone boundaries", () => {
483
+ test("snapshots Map and Set entries before getters can mutate them", async () => {
484
+ // StructuredSerializeInternal snapshots collections before recursing. Bun's
485
+ // current live traversal differs, so use the standard's result as the oracle.
486
+ const output = await new QuickJSScriptExecutor().run(
487
+ input({
488
+ source: `export default async () => {
489
+ const map = new Map();
490
+ map.set('first', { get value() { map.delete('second'); map.set('third', 3); return 1; } });
491
+ map.set('second', 2);
492
+ const set = new Set();
493
+ set.add({ get value() { set.delete(2); set.add(3); return 1; } });
494
+ set.add(2);
495
+ return { map: [...structuredClone(map)], set: [...structuredClone(set)] };
496
+ };`,
497
+ }),
498
+ );
499
+ expect(output.error).toBeUndefined();
500
+ expect(output.result).toEqual({
501
+ map: [
502
+ ["first", { value: 1 }],
503
+ ["second", 2],
504
+ ],
505
+ set: [{ value: 1 }, 2],
506
+ });
507
+ });
508
+
509
+ test("rejects transfers without detaching the source buffer", async () => {
510
+ const output = await new QuickJSScriptExecutor().run(
511
+ input({
512
+ source: `export default async () => {
513
+ const buffer = new ArrayBuffer(8);
514
+ try { structuredClone(buffer, { transfer: [buffer] }); }
515
+ catch (error) { return { name: error.name, message: error.message, byteLength: buffer.byteLength }; }
516
+ };`,
517
+ }),
518
+ );
519
+ expect(output.error).toBeUndefined();
520
+ expect(output.result).toEqual({
521
+ name: "DataCloneError",
522
+ message: "quickjs structuredClone does not support transfers",
523
+ byteLength: 8,
524
+ });
525
+ });
526
+
527
+ test("rejects shared, resizable and detached buffers instead of changing their semantics", async () => {
528
+ const output = await new QuickJSScriptExecutor().run(
529
+ input({
530
+ source: `export default async () => {
531
+ const resizable = new ArrayBuffer(8, { maxByteLength: 16 });
532
+ const detached = new ArrayBuffer(8);
533
+ const view = new Uint8Array(detached);
534
+ detached.transfer();
535
+ return [new SharedArrayBuffer(8), resizable, new Uint8Array(resizable), detached, view].map(value => {
536
+ try { structuredClone(value); return 'accepted'; }
537
+ catch (error) { return error.name; }
538
+ });
539
+ };`,
540
+ }),
541
+ );
542
+ expect(output.error).toBeUndefined();
543
+ expect(output.result).toEqual(Array(5).fill("DataCloneError"));
544
+ });
545
+
546
+ test("uses captured intrinsics and a fresh clone function on the next run", async () => {
547
+ const executor = new QuickJSScriptExecutor();
548
+ const output = await executor.run(
549
+ input({
550
+ source: `export default async () => {
551
+ const value = { map: new Map([['x', 7]]), bytes: new Uint8Array([1, 2]), error: new TypeError('bad') };
552
+ const Type = TypeError;
553
+ const broken = () => { throw Error('replaced intrinsic'); };
554
+ Map.prototype.set = broken;
555
+ Uint8Array.prototype.set = broken;
556
+ Error.isError = broken;
557
+ globalThis.TypeError = broken;
558
+ const copy = structuredClone(value);
559
+ globalThis.structuredClone = broken;
560
+ return [copy.map.get('x'), copy.bytes[1], copy.error instanceof Type];
561
+ };`,
562
+ }),
563
+ );
564
+ expect(output.error).toBeUndefined();
565
+ expect(output.result).toEqual([7, 2, true]);
566
+ const next = await executor.run(
567
+ input({ source: "export default async () => structuredClone({ value: 7 });" }),
568
+ );
569
+ expect(next.error).toBeUndefined();
570
+ expect(next.result).toEqual({ value: 7 });
571
+ });
572
+ });
573
+
386
574
  describe("native-only executor behavior", () => {
387
575
  test.skipIf(SKIP_SANDBOX_SPAWN_TESTS)("timeout maps to timeout", async () => {
388
576
  const output = await new NativeScriptExecutor().run(
@@ -347,6 +347,7 @@ describe("scripts DB & runSavedScriptAsAgent executor persistence (#2013)", () =
347
347
  const wfExecutor = new SwarmScriptExecutor({
348
348
  db: {
349
349
  getWorkflow: async () => null,
350
+ getRunWorkflow: async () => null,
350
351
  } as never,
351
352
  eventBus: { emit: () => {} } as never,
352
353
  });