@desplega.ai/agent-swarm 2.12.0 → 2.13.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 (327) hide show
  1. package/dist/acp-adapter-cn53011z.js +17 -0
  2. package/dist/{acp-targets-311gcyvw.js → acp-targets-86f0sh6g.js} +9 -8
  3. package/dist/{actions-c4chgxp6.js → actions-zv8vcxvr.js} +24 -23
  4. package/dist/{agent-fs-provision-0b9awm5n.js → agent-fs-provision-jqshb33y.js} +4 -4
  5. package/dist/{amp-adapter-r0veq6x5.js → amp-adapter-gt503ywc.js} +2 -2
  6. package/dist/{app-hn5fftf5.js → app-6t4k5rh1.js} +6 -4
  7. package/dist/{approval-notifications-3g6yc8nv.js → approval-notifications-fcfw063h.js} +7 -6
  8. package/dist/{assistant-cpjgpjvp.js → assistant-9dzybh12.js} +25 -24
  9. package/dist/{boot-args-schema-hce1av1h.js → boot-args-schema-xzfp2feg.js} +1 -1
  10. package/dist/{boot-reembed-d7xcym0j.js → boot-reembed-3jz0p2jk.js} +1 -1
  11. package/dist/{boot-reembed-bztbxc4z.js → boot-reembed-r88wngfg.js} +5 -2
  12. package/dist/{boot-scrub-sweep-mkmm16gk.js → boot-scrub-sweep-scrqhw48.js} +2 -2
  13. package/dist/{boot-seeds-arrkbe8t.js → boot-seeds-vb2dcrrb.js} +4 -4
  14. package/dist/{claude-adapter-ykpyr5p8.js → claude-adapter-h3mp9hgs.js} +7 -6
  15. package/dist/{claude-managed-adapter-ssg6z4bt.js → claude-managed-adapter-kpbyj2vb.js} +3 -3
  16. package/dist/{claude-managed-setup-trd59v7b.js → claude-managed-setup-0efr3wkg.js} +5 -5
  17. package/dist/{claude-sdk-session-yjcze0j1.js → claude-sdk-session-03dw669q.js} +7 -6
  18. package/dist/{cli-e3ahxq5y.js → cli-0b655smz.js} +4 -4
  19. package/dist/{cli-mcymtvwn.js → cli-0dg7ytxm.js} +89 -11
  20. package/dist/cli-0jkenasr.js +148 -0
  21. package/dist/{cli-c7j31hq9.js → cli-0pazkmd4.js} +3 -3
  22. package/dist/{cli-5tg94mdw.js → cli-117g15t4.js} +8 -11
  23. package/dist/{cli-r14ac1y0.js → cli-1dbv9mj9.js} +1 -1
  24. package/dist/{cli-q8tc22bj.js → cli-1v82d2w6.js} +3 -3
  25. package/dist/{cli-pe3yxedk.js → cli-2jk4s7z1.js} +2 -2
  26. package/dist/{cli-0pp1yjg2.js → cli-2skf1mdf.js} +8 -8
  27. package/dist/{cli-2tw284hj.js → cli-48nvk6sb.js} +1 -1
  28. package/dist/{cli-en6dmkxd.js → cli-49f5jyhh.js} +2 -2
  29. package/dist/{cli-2z2c4k6q.js → cli-50w82h6m.js} +21 -0
  30. package/dist/{cli-dd2k2mcd.js → cli-6a40p4kv.js} +1 -1
  31. package/dist/{cli-yegz2g06.js → cli-6h88mn9q.js} +3 -3
  32. package/dist/{cli-52nfye5j.js → cli-7dbhnsj9.js} +23 -15
  33. package/dist/{cli-04zc3f7b.js → cli-9fsagra4.js} +1 -1
  34. package/dist/{cli-nja15knq.js → cli-9m9kyw77.js} +3 -3
  35. package/dist/{cli-k5jx8jya.js → cli-ajjvqhf3.js} +1 -1
  36. package/dist/{cli-hbvgzjq4.js → cli-avqkr20b.js} +2 -2
  37. package/dist/{cli-yfpc6qy9.js → cli-avxh26pd.js} +46 -15
  38. package/dist/{cli-q2dywc8h.js → cli-b2jh3dyb.js} +4 -4
  39. package/dist/{cli-m5qtmrbc.js → cli-c8v2yvej.js} +2 -2
  40. package/dist/{cli-gfy6hbd9.js → cli-ct8sz3np.js} +17 -10
  41. package/dist/{cli-bz97ff9n.js → cli-dka73bak.js} +1 -1
  42. package/dist/{cli-dkvtfgn4.js → cli-dkejt425.js} +75 -16
  43. package/dist/{cli-sv2r3bw8.js → cli-dnh64e8e.js} +2 -2
  44. package/dist/{cli-kwr5qv5g.js → cli-eb279wn3.js} +2 -2
  45. package/dist/{cli-hhc47ack.js → cli-f1952kjy.js} +2 -2
  46. package/dist/{cli-5z0g0e8v.js → cli-f8rcvf2x.js} +49 -13
  47. package/dist/{cli-eq4kew31.js → cli-fhvk2nvp.js} +24 -11
  48. package/dist/{cli-xf4z5bdn.js → cli-fz9pcjsw.js} +2 -2
  49. package/dist/{cli-fxd1mwtr.js → cli-g6j6ac3h.js} +1 -1
  50. package/dist/{cli-ya3kf4gs.js → cli-gfcv679k.js} +1 -1
  51. package/dist/{cli-55tc8cj4.js → cli-hbq0kwxz.js} +4 -4
  52. package/dist/{cli-39qm0rtm.js → cli-hc6e4tac.js} +28 -149
  53. package/dist/{cli-j5gtytvg.js → cli-hgsxnjyg.js} +13 -10
  54. package/dist/{cli-h70a2mxy.js → cli-hpb9x72z.js} +48 -8
  55. package/dist/{cli-7yn42w6m.js → cli-j53hpbsm.js} +1 -1
  56. package/dist/{cli-12vek61e.js → cli-jj3c5nyb.js} +471 -119
  57. package/dist/{cli-fy4gb74g.js → cli-kde4ky90.js} +1 -1
  58. package/dist/{cli-9qe5y107.js → cli-kspxjftk.js} +1 -1
  59. package/dist/{cli-bp6k9acz.js → cli-mh7pdxe0.js} +16 -16
  60. package/dist/{cli-v9ya390t.js → cli-mz34pxbk.js} +8 -8
  61. package/dist/{cli-ma9ys8rt.js → cli-nc6a8b5b.js} +7 -4
  62. package/dist/{cli-1htmtqc2.js → cli-prf7kz78.js} +49 -49
  63. package/dist/{cli-01tvvtad.js → cli-qec9bynj.js} +3 -3
  64. package/dist/{cli-t75xngj1.js → cli-qhhb30e8.js} +7 -7
  65. package/dist/{cli-73q4g5nx.js → cli-qm3ntjqs.js} +12 -12
  66. package/dist/{cli-tm60vtax.js → cli-rfejbpe1.js} +1 -1
  67. package/dist/{cli-agjbj5x0.js → cli-sdh61g52.js} +37 -19
  68. package/dist/{cli-9y4tgrkf.js → cli-skd2c4ej.js} +2 -1
  69. package/dist/{cli-5x03v6en.js → cli-sq913bh1.js} +8 -8
  70. package/dist/{cli-b93d81yg.js → cli-t35hx078.js} +1 -1
  71. package/dist/{cli-r0mz92by.js → cli-tn91wc6e.js} +1 -1
  72. package/dist/{cli-wvjqaqcp.js → cli-tstj6e8e.js} +1113 -227
  73. package/dist/{cli-xm34qj8m.js → cli-w14j2z4k.js} +2 -2
  74. package/dist/{cli-eqq0hwvx.js → cli-wndegmns.js} +1 -1
  75. package/dist/{cli-0k1a0sde.js → cli-wrhbym01.js} +6 -6
  76. package/dist/{cli-fyaq4zdv.js → cli-wv20kbr3.js} +6 -6
  77. package/dist/{cli-mq2fbgva.js → cli-wxwv3t11.js} +2 -2
  78. package/dist/{cli-krbcr00p.js → cli-xfjn2kyq.js} +58 -4
  79. package/dist/{cli-5r95eqbh.js → cli-y260hgep.js} +1 -1
  80. package/dist/{cli-cjqyse9q.js → cli-y4a4458j.js} +3 -3
  81. package/dist/{cli-2amwhyv2.js → cli-y518qkjg.js} +5 -3
  82. package/dist/{cli-0vcqcwfn.js → cli-yfvhvw8m.js} +2 -0
  83. package/dist/cli-yn4kt85g.js +148 -0
  84. package/dist/{cli-n8f0fs3c.js → cli-ytc7fpza.js} +8 -8
  85. package/dist/{cli-e8n0hdzd.js → cli-z64t9pe6.js} +1 -1
  86. package/dist/{cli-72yms3ey.js → cli-zqmmy073.js} +198 -18
  87. package/dist/cli.js +18 -16
  88. package/dist/{codex-adapter-wc6e4wct.js → codex-adapter-f3yp0kaj.js} +5 -5
  89. package/dist/{codex-hook-aqtj17yr.js → codex-hook-262cekfp.js} +73 -2
  90. package/dist/{codex-session-runner-ppfgjd97.js → codex-session-runner-ns4mv70p.js} +5 -5
  91. package/dist/{commands-tsv2vx5b.js → commands-5bzf2tfw.js} +3 -3
  92. package/dist/{controller-ye4sdwsy.js → controller-5xt7kvfm.js} +2 -2
  93. package/dist/{controllers-connect-zn4dg69h.js → controllers-connect-0gg13mzp.js} +24 -23
  94. package/dist/core-0fqtbrxa.js +42 -0
  95. package/dist/{cursor-adapter-q2g9vwts.js → cursor-adapter-p0c5zv6r.js} +1 -1
  96. package/dist/{db-g111qn9j.js → db-2s68ycq7.js} +3 -3
  97. package/dist/{db-3r1fyr2n.js → db-q7q639k5.js} +4 -2
  98. package/dist/{dispatcher-4q8s0mx8.js → dispatcher-j2y1q7ae.js} +24 -21
  99. package/dist/{dsh-adapter-mmcw1z5s.js → dsh-adapter-pgnkf4st.js} +1 -1
  100. package/dist/{easter-egg-3d-04ke6hcp.js → easter-egg-3d-0kea97jf.js} +1 -1
  101. package/dist/{embedding-space-kcdn52vz.js → embedding-space-3n6mhhmy.js} +6 -6
  102. package/dist/{embeddings-jnzcd91a.js → embeddings-jfmj6yme.js} +1 -1
  103. package/dist/{execute-74amghty.js → execute-tjrej979.js} +1 -1
  104. package/dist/{external-channel-v9zgxnxz.js → external-channel-jy8w2gg3.js} +2 -2
  105. package/dist/fx-adapter-k6w3jvz9.js +20 -0
  106. package/dist/grok-adapter-4q5tssw0.js +20 -0
  107. package/dist/handlers-qxgfvvsf.js +41 -0
  108. package/dist/{heartbeat-p8pk1msj.js → heartbeat-6tr2w2da.js} +25 -24
  109. package/dist/{hook-p5reemds.js → hook-bpnncsec.js} +76 -17
  110. package/dist/{hook-k1h73zd7.js → hook-fv1jwrv7.js} +6 -5
  111. package/dist/{http-ms1z5xxy.js → http-bpa26czn.js} +785 -181
  112. package/dist/index-0mcxjdsa.js +44 -0
  113. package/dist/{index-kn63q1gr.js → index-52tgbhrw.js} +29 -28
  114. package/dist/index-dz4q23ag.js +40 -0
  115. package/dist/{index-76zzxtzf.js → index-mpj0z9e0.js} +1 -1
  116. package/dist/index-s175jckx.js +39 -0
  117. package/dist/{index-gjn6qfgn.js → index-s8re7mvq.js} +1 -1
  118. package/dist/{index-fbkqhvvj.js → index-w216g9y9.js} +198 -160
  119. package/dist/{keepalive-031js8jz.js → keepalive-d6z12s04.js} +3 -3
  120. package/dist/lead-p3hx7h35.js +79 -0
  121. package/dist/{maintenance-sq9v3qx9.js → maintenance-7kac6g2g.js} +1 -1
  122. package/dist/{oauth-refresh-sweep-zqmnyvs8.js → oauth-refresh-sweep-t1xjetbh.js} +2 -2
  123. package/dist/{object-webhooks-r24wwb5y.js → object-webhooks-6rdagg0r.js} +7 -7
  124. package/dist/{onboard-p25yhh7t.js → onboard-32y1cfxy.js} +3 -3
  125. package/dist/{opencode-adapter-wcjc4zdk.js → opencode-adapter-enp3v31n.js} +7 -6
  126. package/dist/{otel-impl-ff1gf20m.js → otel-impl-k0tm5ptj.js} +1 -1
  127. package/dist/{pending-hxj5yatb.js → pending-24zebgvs.js} +23 -22
  128. package/dist/{pi-mono-adapter-vkp4zz7p.js → pi-mono-adapter-yj72xxxe.js} +85 -16
  129. package/dist/{pricing-refresh-9w7gx41w.js → pricing-refresh-cf25x38j.js} +2 -2
  130. package/dist/{rbac-roles-84aw10nz.js → rbac-roles-0wydd22m.js} +3 -3
  131. package/dist/{rbac-roles-hz74vckp.js → rbac-roles-at6crb3r.js} +7 -4
  132. package/dist/{registry-eeyx1201.js → registry-zv0zvxsx.js} +1 -1
  133. package/dist/{render-v2-nrdkg9gf.js → render-v2-nvcw0jd7.js} +8 -4
  134. package/dist/{resume-s6ey36rh.js → resume-y4w0k5v3.js} +9 -8
  135. package/dist/{runtime-x0b4pyam.js → runtime-vpe43hx0.js} +1 -1
  136. package/dist/{session-access-xv49tk14.js → session-access-gkyvnfye.js} +5 -4
  137. package/dist/{session-source-backfill-r5j988ah.js → session-source-backfill-3w2st4m2.js} +2 -2
  138. package/dist/{setup-mj0krk1p.js → setup-axxvqtys.js} +1 -1
  139. package/dist/thread-buffer-rwa7d4dx.js +42 -0
  140. package/dist/{tree-visibility-cbrsfaar.js → tree-visibility-y4fqvab5.js} +2 -2
  141. package/dist/{user-merge-jobs-f9d8nwnw.js → user-merge-jobs-kcmwvrc6.js} +3 -3
  142. package/dist/{virtual-modules-ns0ryw05.js → virtual-modules-7d92dct1.js} +3 -3
  143. package/dist/{work-objects-pydhzast.js → work-objects-f708e069.js} +27 -25
  144. package/dist/worker-8rg9gz74.js +79 -0
  145. package/dist/{worker-follow-up-9z2xec5e.js → worker-follow-up-0by8wztc.js} +22 -21
  146. package/dist/xlsx-9acfmxr1.js +31534 -0
  147. package/openapi.json +1385 -204
  148. package/package.json +5 -3
  149. package/src/agentmail/handlers.ts +26 -19
  150. package/src/apps/catalog.generated.json +31 -0
  151. package/src/apps/row-store.ts +37 -14
  152. package/src/azure-devops/handlers.ts +2 -0
  153. package/src/be/audit-user.ts +46 -6
  154. package/src/be/db/kv-windows.ts +22 -0
  155. package/src/be/db/session-moves.ts +3 -3
  156. package/src/be/db/session-tree.ts +52 -5
  157. package/src/be/db/skill-audit.ts +17 -0
  158. package/src/be/db/tasks/write.ts +18 -3
  159. package/src/be/db.ts +114 -23
  160. package/src/be/extensions/assets.ts +11 -7
  161. package/src/be/memory/demotion-evidence.ts +2 -2
  162. package/src/be/memory/providers/sqlite-store.ts +151 -18
  163. package/src/be/memory/search-read-worker.ts +60 -0
  164. package/src/be/memory/search-reader.ts +223 -0
  165. package/src/be/migrations/337_favorites_session_hidden_key.sql +39 -0
  166. package/src/be/migrations/338_audit_agent_columns.sql +30 -0
  167. package/src/be/migrations/339_deferred_event_waits.sql +26 -0
  168. package/src/be/model-tier-resolution.ts +18 -1
  169. package/src/be/multi-runtime.ts +17 -0
  170. package/src/be/primitives/object-embed.ts +250 -0
  171. package/src/be/primitives/objects.ts +29 -9
  172. package/src/be/primitives/sheets/service.ts +138 -6
  173. package/src/be/primitives/sheets/xlsx.ts +367 -0
  174. package/src/be/rbac-roles.ts +3 -0
  175. package/src/be/repo-checked-update.ts +4 -4
  176. package/src/be/repo-merge-policy.ts +26 -9
  177. package/src/be/scripts/boot-reembed.ts +6 -0
  178. package/src/be/scripts/db.ts +17 -5
  179. package/src/be/scripts/embeddings.ts +6 -0
  180. package/src/be/scripts/typecheck.ts +43 -2
  181. package/src/be/seed/schedules-seeder.ts +9 -1
  182. package/src/be/seed/workflows-seeder.ts +9 -1
  183. package/src/be/seed-scripts/index.ts +2 -0
  184. package/src/be/seed-skills/index.ts +12 -0
  185. package/src/be/swarm-config-guard.ts +1 -0
  186. package/src/be/unmapped-identities.ts +95 -1
  187. package/src/bitbucket/handlers.ts +2 -0
  188. package/src/commands/onboard/agent-fs-version.ts +1 -1
  189. package/src/event-waits/github.ts +43 -0
  190. package/src/event-waits/index.ts +29 -0
  191. package/src/event-waits/types.ts +51 -0
  192. package/src/extensions/contract-types.generated.ts +1 -1
  193. package/src/extensions/dispatcher.ts +9 -0
  194. package/src/fs/agent-fs-provider.ts +4 -1
  195. package/src/github/handlers.ts +3 -1
  196. package/src/github/pull-request-state.ts +34 -0
  197. package/src/gitlab/handlers.ts +12 -7
  198. package/src/hooks/codex-hook.ts +99 -1
  199. package/src/hooks/hook.ts +85 -11
  200. package/src/hooks/native-tool-hooks.ts +245 -0
  201. package/src/http/all-routes.ts +1 -0
  202. package/src/http/assets.ts +4 -3
  203. package/src/http/comb.ts +2 -2
  204. package/src/http/favorite-owner.ts +2 -2
  205. package/src/http/favorites.ts +3 -2
  206. package/src/http/fs.ts +13 -4
  207. package/src/http/index.ts +2 -0
  208. package/src/http/mcp-bridge.ts +4 -0
  209. package/src/http/objects.ts +265 -0
  210. package/src/http/pages.ts +3 -3
  211. package/src/http/poll.ts +43 -12
  212. package/src/http/repos.ts +7 -6
  213. package/src/http/schedules.ts +10 -6
  214. package/src/http/script-connections.ts +2 -2
  215. package/src/http/scripts.ts +9 -0
  216. package/src/http/sessions.ts +30 -12
  217. package/src/http/skills.ts +17 -0
  218. package/src/http/task-requester.ts +2 -2
  219. package/src/http/tasks.ts +13 -3
  220. package/src/http/tool-hooks.ts +24 -2
  221. package/src/http/trackers/authorize-gate.ts +2 -2
  222. package/src/http/users.ts +136 -1
  223. package/src/http/workflow-events.ts +13 -0
  224. package/src/http/workflows.ts +21 -11
  225. package/src/linear/sync.ts +3 -1
  226. package/src/prompts/base-prompt.ts +35 -13
  227. package/src/prompts/session-templates.ts +25 -0
  228. package/src/providers/acp-targets.ts +1 -1
  229. package/src/providers/amp-adapter.ts +1 -1
  230. package/src/providers/dsh-adapter.ts +1 -1
  231. package/src/providers/opencode-adapter.ts +1 -0
  232. package/src/providers/opencode-swarm-plugin.ts +50 -1
  233. package/src/providers/pi-mono-adapter.ts +139 -9
  234. package/src/providers/pi-mono-extension.ts +69 -0
  235. package/src/providers/runtime-dependencies.ts +1 -1
  236. package/src/rbac/legacy-policy.ts +3 -0
  237. package/src/rbac/permissions.ts +11 -1
  238. package/src/scheduler/deferred-task-waits.ts +170 -13
  239. package/src/scripts-runtime/executors/types.ts +5 -0
  240. package/src/scripts-runtime/loader.ts +8 -0
  241. package/src/scripts-runtime/mcp-client.ts +4 -0
  242. package/src/scripts-runtime/sdk-allowlist.ts +14 -1
  243. package/src/scripts-runtime/swarm-config.ts +8 -0
  244. package/src/scripts-runtime/swarm-sdk.ts +4 -0
  245. package/src/scripts-runtime/types/stdlib.d.ts +47 -4
  246. package/src/scripts-runtime/types/swarm-extension.d.ts +1 -0
  247. package/src/scripts-runtime/types/swarm-sdk.d.ts +47 -4
  248. package/src/server.ts +4 -0
  249. package/src/slack/enrich.ts +81 -21
  250. package/src/slack/handlers.test.ts +55 -2
  251. package/src/slack/handlers.ts +38 -3
  252. package/src/slack/render-v2.ts +19 -0
  253. package/src/slack/session-mirror.ts +208 -0
  254. package/src/slack/thread-participants.ts +0 -5
  255. package/src/slack/watcher.ts +3 -0
  256. package/src/slack/work-objects.test.ts +2 -1
  257. package/src/slack/work-objects.ts +7 -2
  258. package/src/tests/agentmail-filters.test.ts +4 -3
  259. package/src/tests/audit-agent-person.test.ts +825 -0
  260. package/src/tests/audit-updated-by.test.ts +19 -12
  261. package/src/tests/claude-hook-output.test.ts +107 -2
  262. package/src/tests/claude-managed-setup.test.ts +1 -1
  263. package/src/tests/codex-adapter.test.ts +6 -6
  264. package/src/tests/codex-gpt6-release.test.ts +4 -4
  265. package/src/tests/db-task-read-contract.test.ts +1 -0
  266. package/src/tests/db-task-write-contract.test.ts +1 -0
  267. package/src/tests/dsh-adapter.test.ts +1 -1
  268. package/src/tests/extensions-catalog.test.ts +33 -25
  269. package/src/tests/fixtures/sheets/eocd-count-mismatch.xlsx +0 -0
  270. package/src/tests/fixtures/sheets/rich-budget.xlsx +0 -0
  271. package/src/tests/fixtures/sheets/tracker-export.xlsx +0 -0
  272. package/src/tests/kv-storage.test.ts +3 -0
  273. package/src/tests/memory-search-reader.test.ts +258 -0
  274. package/src/tests/memory-search-stall.test.ts +197 -20
  275. package/src/tests/model-control.test.ts +4 -4
  276. package/src/tests/model-tier-resolution.test.ts +2 -2
  277. package/src/tests/multi-runtime-registration.test.ts +8 -2
  278. package/src/tests/native-tool-hooks.test.ts +188 -0
  279. package/src/tests/opencode-swarm-plugin.test.ts +6 -1
  280. package/src/tests/pi-provider-runtime-keys.test.ts +163 -0
  281. package/src/tests/poll-probe-readonly.test.ts +108 -0
  282. package/src/tests/primitives-sheets-xlsx.test.ts +549 -0
  283. package/src/tests/prompt-template-session.test.ts +3 -2
  284. package/src/tests/rbac-roles.test.ts +3 -0
  285. package/src/tests/script-connections.test.ts +4 -0
  286. package/src/tests/seed-model-profiles.test.ts +1 -1
  287. package/src/tests/sessions-tree.test.ts +10 -2
  288. package/src/tests/slack-thread-participants.test.ts +66 -4
  289. package/src/tests/tool-registrar-no-input.test.ts +1 -0
  290. package/src/tools/defer-task.ts +154 -12
  291. package/src/tools/objects.ts +10 -5
  292. package/src/tools/repos/update-repo.ts +6 -6
  293. package/src/tools/schedules/create-schedule.ts +1 -0
  294. package/src/tools/schedules/list-schedules.ts +3 -0
  295. package/src/tools/schedules/patch-schedule.ts +12 -3
  296. package/src/tools/schedules/update-schedule.ts +12 -3
  297. package/src/tools/sheets.ts +66 -0
  298. package/src/tools/skills/skill-create.ts +6 -0
  299. package/src/tools/skills/skill-install-remote.ts +6 -0
  300. package/src/tools/skills/skill-sync-remote.ts +9 -0
  301. package/src/tools/skills/skill-update.ts +9 -1
  302. package/src/tools/tool-config.ts +3 -1
  303. package/src/tools/utils.ts +15 -0
  304. package/src/tools/workflows/create-workflow.ts +9 -4
  305. package/src/tools/workflows/patch-workflow-node.ts +1 -1
  306. package/src/tools/workflows/patch-workflow.ts +5 -2
  307. package/src/tools/workflows/update-workflow.ts +13 -7
  308. package/src/types.ts +96 -12
  309. package/src/workflows/input.ts +12 -5
  310. package/src/workflows/patch-definition.ts +13 -5
  311. package/src/workflows/triggers.ts +11 -6
  312. package/src/workflows/version.ts +7 -1
  313. package/templates/skills/boards-and-sheets/config.json +14 -0
  314. package/templates/skills/boards-and-sheets/content.md +163 -0
  315. package/templates/skills/swarm-docs/content.md +9 -0
  316. package/dist/acp-adapter-11m13kx4.js +0 -16
  317. package/dist/core-dxcy02sc.js +0 -41
  318. package/dist/fx-adapter-0ar6pqm3.js +0 -19
  319. package/dist/grok-adapter-t6m74fb1.js +0 -19
  320. package/dist/handlers-9kwcrc4k.js +0 -38
  321. package/dist/index-23cdfzr6.js +0 -39
  322. package/dist/index-g7kkjs5b.js +0 -38
  323. package/dist/index-stk36pa5.js +0 -43
  324. package/dist/lead-mfggjtfk.js +0 -77
  325. package/dist/thread-buffer-temgaqsy.js +0 -41
  326. package/dist/worker-efcemc22.js +0 -77
  327. /package/dist/{cli-cah298e5.js → cli-m4ejz4nj.js} +0 -0
@@ -21,15 +21,21 @@ const ACTOR = { kind: "system", id: "test" } as const;
21
21
  // Slack fixtures the fake client serves; each test sets what it needs.
22
22
  let threadMessages: Array<Record<string, unknown>> = [];
23
23
  const emails = new Map<string, string>();
24
+ const userTeams = new Map<string, { team_id: string; enterprise_user?: object }>();
25
+ const ourTeam = { ok: true, team_id: "T0OURS" } as Record<string, unknown>;
26
+ let authTest = async (): Promise<Record<string, unknown>> => ourTeam;
24
27
  const fakeClient = {
25
28
  conversations: { replies: async () => ({ ok: true, messages: threadMessages }) },
26
29
  users: {
27
30
  info: async ({ user }: { user: string }) => ({
28
31
  ok: true,
29
- user: { profile: emails.has(user) ? { email: emails.get(user), real_name: user } : {} },
32
+ user: {
33
+ ...userTeams.get(user),
34
+ profile: emails.has(user) ? { email: emails.get(user), real_name: user } : {},
35
+ },
30
36
  }),
31
37
  },
32
- auth: { test: async () => ({ ok: true, team_id: "T0OURS" }) },
38
+ auth: { test: () => authTest() },
33
39
  chat: { postMessage: async () => ({ ok: true, ts: "9999.0099" }) },
34
40
  };
35
41
  const client = fakeClient as unknown as WebClient;
@@ -40,7 +46,8 @@ mock.module("../slack/app", () => ({
40
46
  getSlackApp: () => ({ client: fakeClient }),
41
47
  }));
42
48
 
43
- const { resolveSlackParticipant, resolveSlackUserId } = await import("../slack/enrich");
49
+ const { resolveSlackParticipant, resolveSlackUserId, resetSlackTeamIdCacheForTesting } =
50
+ await import("../slack/enrich");
44
51
  const { buildSlackThreadSnapshot } = await import("../slack/thread-participants");
45
52
  const { instantFlush, bufferThreadMessage } = await import("../slack/thread-buffer");
46
53
  const { buildTaskThreadParticipants } = await import("../http/requested-by");
@@ -130,7 +137,6 @@ describe("resolveSlackParticipant", () => {
130
137
  const result = await resolveSlackParticipant(client, "U0GUEST", {
131
138
  ...ctx,
132
139
  userTeam: "T0OTHER",
133
- ourTeamId: "T0OURS",
134
140
  });
135
141
  expect(result.trust).toBe("external");
136
142
  expect(await findUserByExternalId("slack", "U0GUEST")).toBeNull();
@@ -148,6 +154,62 @@ describe("resolveSlackParticipant", () => {
148
154
  (await findUserByExternalId("slack", "U0OURS2"))?.id,
149
155
  );
150
156
  expect(await findUserByExternalId("slack", "U0OURS2")).not.toBeNull();
157
+
158
+ // auth.test failed: a sender carrying a team cannot be shown to be ours, so the
159
+ // email links nothing, even an existing user. Trust still follows the email.
160
+ resetSlackTeamIdCacheForTesting();
161
+ authTest = async () => {
162
+ throw new Error("auth.test failed");
163
+ };
164
+ try {
165
+ const { user: owner } = await findOrCreateUserByEmail(
166
+ "owner@desplega.test",
167
+ { name: "Owner" },
168
+ ACTOR,
169
+ );
170
+ emails.set("U0NOAUTH", "owner@desplega.test");
171
+ expect(
172
+ await resolveSlackUserId(client, "U0NOAUTH", { ...ctx, userTeam: "T0OTHER" }),
173
+ ).toBeUndefined();
174
+ expect(await findUserByExternalId("slack", "U0NOAUTH")).toBeNull();
175
+ expect(
176
+ await resolveSlackParticipant(client, "U0NOAUTH", { ...ctx, userTeam: "T0OTHER" }),
177
+ ).toEqual({ userId: undefined, trust: "internal" });
178
+ // Positive control: with no team on the event, the same email still links.
179
+ expect((await resolveSlackParticipant(client, "U0NOAUTH", ctx)).userId).toBe(owner.id);
180
+ } finally {
181
+ authTest = async () => ourTeam;
182
+ resetSlackTeamIdCacheForTesting();
183
+ }
184
+
185
+ // Org-wide install: auth.test may name the org while senders carry a workspace id,
186
+ // so the sender's Enterprise Grid org decides.
187
+ resetSlackTeamIdCacheForTesting();
188
+ authTest = async () => ({
189
+ ok: true,
190
+ team_id: "E0ORG",
191
+ enterprise_id: "E0ORG",
192
+ is_enterprise_install: true,
193
+ });
194
+ try {
195
+ emails.set("U0GRID", "grid@desplega.test");
196
+ userTeams.set("U0GRID", { team_id: "T0WS2", enterprise_user: { enterprise_id: "E0ORG" } });
197
+ emails.set("U0GRIDGUEST", "gridguest@desplega.test");
198
+ userTeams.set("U0GRIDGUEST", {
199
+ team_id: "T0GUEST",
200
+ enterprise_user: { enterprise_id: "E0GUEST" },
201
+ });
202
+ const gridUser = await resolveSlackUserId(client, "U0GRID", { ...ctx, userTeam: "T0WS2" });
203
+ expect(gridUser).toBe((await findUserByExternalId("slack", "U0GRID"))?.id);
204
+ expect(gridUser).toBeDefined();
205
+ expect(
206
+ await resolveSlackUserId(client, "U0GRIDGUEST", { ...ctx, userTeam: "T0GUEST" }),
207
+ ).toBeUndefined();
208
+ expect(await findUserByExternalId("slack", "U0GRIDGUEST")).toBeNull();
209
+ } finally {
210
+ authTest = async () => ourTeam;
211
+ resetSlackTeamIdCacheForTesting();
212
+ }
151
213
  });
152
214
  });
153
215
 
@@ -62,6 +62,7 @@ describe("createToolRegistrar with no inputSchema", () => {
62
62
  sessionId: "test-session-123",
63
63
  agentId: "agent-abc",
64
64
  sourceTaskId: "task-xyz",
65
+ auditSourceTaskId: "task-xyz",
65
66
  contextKey: undefined,
66
67
  // External headers cannot forge the server-private script origin.
67
68
  callOrigin: "mcp",
@@ -11,13 +11,83 @@ import {
11
11
  getUserById,
12
12
  updateAgentStatusFromCapacity,
13
13
  } from "@/be/db";
14
- import { reconcileDeferredTaskWaits } from "@/scheduler/deferred-task-waits";
14
+ import {
15
+ describeEventWait,
16
+ type EventMatch,
17
+ EXTERNAL_EVENT_ADAPTERS,
18
+ EXTERNAL_EVENT_NAMES,
19
+ EXTERNAL_EVENTS_DOC,
20
+ type ExternalEventAdapter,
21
+ getExternalEventAdapter,
22
+ matchKeyOf,
23
+ } from "@/event-waits";
24
+ import {
25
+ MAX_PENDING_EVENT_WAITS_PER_AGENT,
26
+ reconcileDeferredEventWaits,
27
+ reconcileDeferredTaskWaits,
28
+ } from "@/scheduler/deferred-task-waits";
15
29
  import { runTaskTerminalEffects } from "@/tasks/task-terminal-effects";
16
30
  import { getTaskOutputValidationError } from "@/tasks/terminal-result-guard";
17
31
  import { assertOwnsTask, ownerCtx } from "@/tools/task-tool-ctx";
18
32
  import { createToolRegistrar, swarmToolOutputSchema, toolErr, toolOk } from "@/tools/utils";
19
33
  import { isTerminalTaskStatus } from "@/types";
20
34
  import { ensure } from "../utils/business-use";
35
+ import { getCurrentRequestAuth } from "../utils/request-auth-context";
36
+
37
+ const isExternalEvent = (event: string) => EXTERNAL_EVENT_NAMES.includes(event);
38
+
39
+ /**
40
+ * Resolve and vet an external-event wait before any write: the adapter exists and
41
+ * serves the event, its integration is on, the match parses, and the event has not
42
+ * already happened (a read, when the adapter can confirm). Returns a user-facing error otherwise.
43
+ */
44
+ async function admitExternalWait(
45
+ event: string,
46
+ source: string,
47
+ rawMatch: unknown,
48
+ ): Promise<{ adapter: ExternalEventAdapter; match: EventMatch } | { error: string }> {
49
+ const adapter = getExternalEventAdapter(source);
50
+ if (!adapter?.events.includes(event)) {
51
+ const served = EXTERNAL_EVENT_ADAPTERS.filter((a) => a.events.includes(event)).map(
52
+ (a) => a.source,
53
+ );
54
+ return {
55
+ error: `Source "${source}" does not serve ${event}; use one of: ${served.join(", ")}.`,
56
+ };
57
+ }
58
+ let match: EventMatch;
59
+ try {
60
+ match = adapter.parseMatch(event, rawMatch);
61
+ } catch (error) {
62
+ return { error: error instanceof Error ? error.message : "Invalid match." };
63
+ }
64
+ const target = describeEventWait(source, event, match);
65
+ // A confirm read may use server-held credentials: refuse the ACP task tokens that
66
+ // /api/github/installation-token also refuses.
67
+ const auth = getCurrentRequestAuth();
68
+ if (adapter.readsWithServerCredentials && auth?.kind === "agent" && auth.tokenKind === "task") {
69
+ return {
70
+ error: "A task-scoped token cannot defer on an external event; defer on a timer instead.",
71
+ };
72
+ }
73
+ if (!adapter.isEnabled()) {
74
+ return {
75
+ error: `The ${source} integration is off, so no event can wake you; defer on a timer instead.`,
76
+ };
77
+ }
78
+ if (adapter.confirm) {
79
+ try {
80
+ if (await adapter.confirm(event, match)) {
81
+ return { error: `${target} already happened; read its result instead of deferring.` };
82
+ }
83
+ } catch (error) {
84
+ return {
85
+ error: `Could not read ${target} from ${source} (${error instanceof Error ? error.message : "unknown error"}); defer on a timer instead.`,
86
+ };
87
+ }
88
+ }
89
+ return { adapter, match };
90
+ }
21
91
 
22
92
  /** Thrown inside the transaction to abort and roll back the schedule INSERT. */
23
93
  class DeferAbortedError extends Error {}
@@ -161,7 +231,7 @@ export const registerDeferTaskTool = (server: McpServer) => {
161
231
  title: "Defer Task",
162
232
  annotations: { destructiveHint: false, idempotentHint: false },
163
233
  description:
164
- "Completes this task now with status `completed` and books a wake-up for you. Use when the result needs time: a build, a deploy, a reply. The task reaches its final state on this call; the lead sees your summary as its output unless the task has an outputSchema. For a task with an outputSchema, provide output as a JSON string matching that schema; it is stored verbatim as terminal output, while deferral details remain visible in the task log. A one-off schedule wakes you up later with a child task that carries this task as its parent. Optionally provide wakeOn with taskId or taskIds to wake early on task outcomes; mode defaults to all, or use any for the first match. delayMs or runAt remains required as the ceiling for the whole set. Provide delayMs or runAt, a summary of what you did, and a note that says what is pending and what to check.",
234
+ 'Completes this task now with status `completed` and books a wake-up for you. Use when the result needs time: a build, a deploy, a reply. The task reaches its final state on this call; the lead sees your summary as its output unless the task has an outputSchema. For a task with an outputSchema, provide output as a JSON string matching that schema; it is stored verbatim as terminal output, while deferral details remain visible in the task log. A one-off schedule wakes you up later with a child task that carries this task as its parent. Optionally provide wakeOn with taskId or taskIds to wake early on task outcomes; mode defaults to all, or use any for the first match. Or provide wakeOn {event, source, match} to wake on an external event, e.g. {event: "vcs.pr.merged", source: "github", match: {repo, number}}. delayMs or runAt remains required as the ceiling for the whole set. Provide delayMs or runAt, a summary of what you did, and a note that says what is pending and what to check.',
165
235
  inputSchema: z.object({
166
236
  taskId: z.string().describe("The ID of the task you are working on."),
167
237
  delayMs: z
@@ -177,21 +247,40 @@ export const registerDeferTaskTool = (server: McpServer) => {
177
247
  .describe("Wake up at this ISO datetime (e.g. '2026-03-06T15:00:00Z'). Must be future."),
178
248
  wakeOn: z
179
249
  .object({
180
- event: z.enum(["task.completed", "task.failed", "settled"]),
250
+ event: z.enum(["task.completed", "task.failed", "settled", ...EXTERNAL_EVENT_NAMES]),
181
251
  taskId: z.string().min(1).optional(),
182
252
  taskIds: z.array(z.string().min(1)).min(1).optional(),
183
253
  mode: z.enum(["all", "any"]).optional(),
254
+ source: z.string().min(1).optional(),
255
+ match: z.record(z.string(), z.union([z.string(), z.number()])).optional(),
184
256
  })
185
257
  .strict()
186
- .refine((wake) => (wake.taskId !== undefined) !== (wake.taskIds !== undefined), {
187
- message: "Provide exactly one of wakeOn.taskId or wakeOn.taskIds.",
188
- })
258
+ .refine(
259
+ (wake) =>
260
+ isExternalEvent(wake.event) ||
261
+ (wake.taskId !== undefined) !== (wake.taskIds !== undefined),
262
+ { message: "Provide exactly one of wakeOn.taskId or wakeOn.taskIds." },
263
+ )
264
+ .refine(
265
+ (wake) =>
266
+ isExternalEvent(wake.event)
267
+ ? wake.source !== undefined &&
268
+ wake.match !== undefined &&
269
+ wake.taskId === undefined &&
270
+ wake.taskIds === undefined &&
271
+ wake.mode === undefined
272
+ : wake.source === undefined && wake.match === undefined,
273
+ {
274
+ message:
275
+ "External events (e.g. vcs.pr.merged) take source and match only; task events take no source or match.",
276
+ },
277
+ )
189
278
  .refine((wake) => !wake.taskIds || new Set(wake.taskIds).size === wake.taskIds.length, {
190
279
  message: "wakeOn.taskIds must not contain duplicates.",
191
280
  })
192
281
  .optional()
193
282
  .describe(
194
- "Wake early on a task event. Provide taskId or nonempty, unique taskIds. mode defaults to all (every member must match); any wakes on the first match. settled covers completed, failed, cancelled, or skipped. Deferred and superseded members follow their continuations; a superseded member without a resume child holds to the ceiling, except a workflow step superseded by its queued retry, which counts as failed. Any already-terminal member rejects the request; one delayMs/runAt ceiling is still required for the whole set. The member whose settlement wakes you creates no separate lead follow-up for your agent unless its followUpConfig sets onCompleted/onFailed; an all-mode member that settles while others are pending still does.",
283
+ `Wake early on a task event. Provide taskId or nonempty, unique taskIds. mode defaults to all (every member must match); any wakes on the first match. settled covers completed, failed, cancelled, or skipped. Deferred and superseded members follow their continuations; a superseded member without a resume child holds to the ceiling, except a workflow step superseded by its queued retry, which counts as failed. Any already-terminal member rejects the request; one delayMs/runAt ceiling is still required for the whole set. External events: ${EXTERNAL_EVENTS_DOC}. They are rejected when the event already happened, the provider cannot be read, or its integration is off; an agent holds at most ${MAX_PENDING_EVENT_WAITS_PER_AGENT} pending external waits. The member whose settlement wakes you creates no separate lead follow-up for your agent unless its followUpConfig sets onCompleted/onFailed; an all-mode member that settles while others are pending still does.`,
195
284
  ),
196
285
  summary: z
197
286
  .string()
@@ -281,11 +370,15 @@ export const registerDeferTaskTool = (server: McpServer) => {
281
370
 
282
371
  const watchedTaskIds = wakeOn?.taskIds ?? (wakeOn?.taskId ? [wakeOn.taskId] : []);
283
372
  const wakeMode = wakeOn?.mode ?? "all";
284
- const wakeDescription = wakeOn
285
- ? `on ${wakeOn.event} for ${wakeMode} of tasks ${watchedTaskIds.join(", ")}, or by ${nextRunAt}`
286
- : `at ${nextRunAt}`;
373
+ const eventWait = wakeOn && isExternalEvent(wakeOn.event) ? wakeOn : undefined;
374
+ const wakeDescription = eventWait
375
+ ? `on ${eventWait.event} from ${eventWait.source}, or by ${nextRunAt}`
376
+ : wakeOn
377
+ ? `on ${wakeOn.event} for ${wakeMode} of tasks ${watchedTaskIds.join(", ")}, or by ${nextRunAt}`
378
+ : `at ${nextRunAt}`;
287
379
  const checksBlock = renderChecks(checks);
288
380
  const taskTemplate = `Resume task ${taskId}: ${note}${checksBlock}`;
381
+ // Not the audit task: the wake-up task is requested by the schedule's created_by.
289
382
  const createdBy =
290
383
  (await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId)) ?? undefined;
291
384
 
@@ -304,8 +397,29 @@ export const registerDeferTaskTool = (server: McpServer) => {
304
397
  task.requestedByUserId,
305
398
  );
306
399
 
400
+ // Read the provider before the transaction: no network call under the write lock.
401
+ let admitted: { adapter: ExternalEventAdapter; match: EventMatch } | undefined;
402
+ if (eventWait) {
403
+ const result = await admitExternalWait(eventWait.event, eventWait.source!, eventWait.match);
404
+ if ("error" in result) return toolErr(result.error);
405
+ admitted = result;
406
+ }
407
+
307
408
  try {
308
409
  const committed = await getDbClient().transaction(async () => {
410
+ if (admitted) {
411
+ const pending = await getDbClient().get<{ n: number }>(
412
+ `SELECT COUNT(*) AS n FROM deferred_event_waits w
413
+ JOIN scheduled_tasks s ON s.id = w.scheduleId
414
+ WHERE w.status = 'pending' AND s.enabled = 1 AND s.targetAgentId = ?`,
415
+ [agent.id],
416
+ );
417
+ if ((pending?.n ?? 0) >= MAX_PENDING_EVENT_WAITS_PER_AGENT) {
418
+ throw new DeferAbortedError(
419
+ `You already hold ${MAX_PENDING_EVENT_WAITS_PER_AGENT} pending external event waits; wait for one to fire.`,
420
+ );
421
+ }
422
+ }
309
423
  // The transaction's write lock makes admission atomic with the INSERT.
310
424
  if (watchedTaskIds.length) {
311
425
  const existing = await getDbClient().get<{ scheduleId: string; parentTaskId: string }>(
@@ -366,7 +480,31 @@ export const registerDeferTaskTool = (server: McpServer) => {
366
480
  createdBy,
367
481
  });
368
482
 
369
- if (wakeOn) {
483
+ if (admitted && eventWait) {
484
+ const matchKey = matchKeyOf(admitted.match);
485
+ await getDbClient().run(
486
+ "INSERT INTO deferred_event_waits (scheduleId, source, event, matchKey, matchJson, created_by, updated_by) VALUES (?, ?, ?, ?, ?, ?, ?)",
487
+ [
488
+ schedule.id,
489
+ admitted.adapter.source,
490
+ eventWait.event,
491
+ matchKey,
492
+ JSON.stringify(admitted.match),
493
+ createdBy ?? null,
494
+ createdBy ?? null,
495
+ ],
496
+ );
497
+ // The event may land between the read above and this commit; recheck after it.
498
+ getDbClient().afterCommit(() => {
499
+ void reconcileDeferredEventWaits({
500
+ source: admitted.adapter.source,
501
+ event: eventWait.event,
502
+ matchKey,
503
+ }).catch((err) => {
504
+ console.error("[defer-task] external event wake reconciliation failed:", err);
505
+ });
506
+ });
507
+ } else if (wakeOn) {
370
508
  await getDbClient().run(
371
509
  "INSERT INTO deferred_task_waits (scheduleId, eventName, mode, created_by, updated_by) VALUES (?, ?, ?, ?, ?)",
372
510
  [schedule.id, wakeOn.event, wakeMode, createdBy ?? null, createdBy ?? null],
@@ -397,7 +535,11 @@ export const registerDeferTaskTool = (server: McpServer) => {
397
535
  nextRunAt,
398
536
  requesterTz,
399
537
  isFallbackTz,
400
- wakeOn ? renderWaitingOn(watchedAgentNames, watchedTaskIds.length) : undefined,
538
+ admitted && eventWait
539
+ ? describeEventWait(admitted.adapter.source, eventWait.event, admitted.match)
540
+ : wakeOn
541
+ ? renderWaitingOn(watchedAgentNames, watchedTaskIds.length)
542
+ : undefined,
401
543
  );
402
544
  const completed = await completeTask(taskId, terminalOutput, {
403
545
  addTags: ["deferred"],
@@ -162,8 +162,12 @@ export const registerObjectReindexTool = (server: McpServer) => {
162
162
  title: "Reindex primitive objects",
163
163
  annotations: { readOnlyHint: false, idempotentHint: true },
164
164
  description:
165
- "Rebuild the object index from the files on your default agent-fs drive. Keeps each file's embedded id; a file with no id (for example a stock Excalidraw save) keeps the id of the row at its path, else gets a new one written back. Rows whose file is gone are reported as `missing`, never deleted. Files whose version matches the index are checked, not re-read (`unchanged`); one call reads at most 50 changed files, 16 MiB, or 20 seconds of work, so run it again while `truncated` is true (`cutBy` names the limit). agent-fs file.changed webhooks keep the index current between runs when the swarm can register them.",
166
- inputSchema: z.object({ kind: KindSchema.optional() }),
165
+ "Rebuild the object index from the files on your default agent-fs drive. Keeps each file's embedded id; a file with no id (for example a stock Excalidraw save) keeps the id of the row at its path, else gets a new one written back. Rows whose file is gone are reported as `missing`, never deleted. Without `prefix` it touches every id-less file of the kind on the drive, including files other people put there: pass `prefix` (same path-prefix match as object-list; end it with `/` for one folder, or give one file's path) to limit it, and `dryRun: true` to get the same report with nothing written. Files whose version matches the index are checked, not re-read (`unchanged`); one call reads at most 50 changed files, 16 MiB, or 20 seconds of work, so run it again while `truncated` is true (`cutBy` names the limit). agent-fs file.changed webhooks keep the index current between runs when the swarm can register them.",
166
+ inputSchema: z.object({
167
+ kind: KindSchema.optional(),
168
+ prefix: z.string().optional(),
169
+ dryRun: z.boolean().optional(),
170
+ }),
167
171
  outputSchema: swarmToolOutputSchema({
168
172
  yourAgentId: z.string().optional(),
169
173
  scanned: z.number().optional(),
@@ -174,16 +178,17 @@ export const registerObjectReindexTool = (server: McpServer) => {
174
178
  conflicts: z.array(z.looseObject({ path: z.string(), reason: z.string() })).optional(),
175
179
  truncated: z.boolean().optional(),
176
180
  cutBy: z.enum(["files", "reads", "time", "bytes"]).nullable().optional(),
181
+ dryRun: z.boolean().optional(),
177
182
  }),
178
183
  },
179
- async ({ kind }, requestInfo) => {
184
+ async ({ kind, prefix, dryRun }, requestInfo) => {
180
185
  const result = await refusing(requestInfo.agentId, () =>
181
- reindexObjects({ agentId: requestInfo.agentId, kind }),
186
+ reindexObjects({ agentId: requestInfo.agentId, kind, prefix, dryRun }),
182
187
  );
183
188
  if ("error" in result) return result.error;
184
189
  const report = result.value;
185
190
  return toolOk(
186
- `Scanned ${report.scanned} files: ${report.unchanged} unchanged, ${report.adopted.length} adopted, ${report.restored.length} restored, ${report.missing.length} missing, ${report.conflicts.length} skipped${report.truncated ? ` (truncated: ${report.cutBy} limit)` : ""}.`,
191
+ `${report.dryRun ? "Dry run, nothing written. " : ""}Scanned ${report.scanned} files: ${report.unchanged} unchanged, ${report.adopted.length} adopted, ${report.restored.length} restored, ${report.missing.length} missing, ${report.conflicts.length} skipped${report.truncated ? ` (truncated: ${report.cutBy} limit)` : ""}.`,
187
192
  { data: { yourAgentId: requestInfo.agentId, ...report } },
188
193
  );
189
194
  },
@@ -4,7 +4,7 @@ import { getAgentById } from "@/be/db";
4
4
  import { updateSwarmRepoChecked } from "@/be/repo-checked-update";
5
5
  import { can } from "@/rbac";
6
6
  import { createToolRegistrar, swarmToolOutputSchema, toolErr, toolOk } from "@/tools/utils";
7
- import { RepoGuidelinesInputSchema, RepoHooksSchema } from "@/types";
7
+ import { agentsMayMerge, RepoGuidelinesInputSchema, RepoHooksSchema } from "@/types";
8
8
 
9
9
  const swarmRepoOutputShape = z.looseObject({
10
10
  id: z.string().optional(),
@@ -33,7 +33,7 @@ export const registerUpdateRepoTool = (server: McpServer) => {
33
33
  {
34
34
  title: "Update Repo",
35
35
  description:
36
- "Update a repo's configuration including guidelines (PR checks, merge policy, review guidance). The lead uses this to set guidelines after asking the user. Pass null for guidelines to clear them. Only the lead can change allowMerge: resend its current value to edit other guidelines.",
36
+ "Update a repo's configuration including guidelines (PR checks, merge policy, review guidance). The lead uses this to set guidelines after asking the user. Pass null for guidelines to clear them. Only the lead can change allowMerge or mergePolicy: resend their current values to edit other guidelines.",
37
37
  annotations: { readOnlyHint: false },
38
38
 
39
39
  inputSchema: z.object({
@@ -51,7 +51,7 @@ export const registerUpdateRepoTool = (server: McpServer) => {
51
51
  guidelines: RepoGuidelinesInputSchema.nullable()
52
52
  .optional()
53
53
  .describe(
54
- "Repository guidelines: prChecks (commands before PR), mergeChecks (conditions before merge), allowMerge (default false), review (guidance for reviewers). Pass null to clear.",
54
+ "Repository guidelines: prChecks (commands before PR), mergeChecks (conditions before merge), allowMerge (default false), review (guidance for reviewers), mergePolicy (per-repo merge policy record: autoMerge, agentsMayMerge, notify). Pass null to clear.",
55
55
  ),
56
56
  }),
57
57
  outputSchema: swarmToolOutputSchema({
@@ -59,7 +59,7 @@ export const registerUpdateRepoTool = (server: McpServer) => {
59
59
  }),
60
60
  },
61
61
  async ({ id, ...updates }, requestInfo) => {
62
- // The comparison with the stored allowMerge, the decision and the write share one
62
+ // The comparison with the stored merge policy, the decision and the write share one
63
63
  // transaction, so a stale edit cannot overwrite a merge-policy change committed after it.
64
64
  const result = await updateSwarmRepoChecked(id, updates, async (existing) => {
65
65
  const agent = requestInfo.agentId ? await getAgentById(requestInfo.agentId) : null;
@@ -72,8 +72,8 @@ export const registerUpdateRepoTool = (server: McpServer) => {
72
72
  source: "mcp",
73
73
  });
74
74
  if (decision.allow) return null;
75
- const current = existing.guidelines?.allowMerge === true;
76
- return `Only lead agents can change allowMerge (it is currently ${current}). Resend ${current} to keep it while you edit the other guidelines.`;
75
+ const current = agentsMayMerge(existing.guidelines);
76
+ return `Only lead agents can change allowMerge or mergePolicy (agents may merge: ${current}). Resend the current allowMerge and mergePolicy to keep them while you edit the other guidelines.`;
77
77
  });
78
78
 
79
79
  if (result.kind === "refused") {
@@ -326,6 +326,7 @@ export const registerCreateScheduleTool = (server: McpServer) => {
326
326
  nextRunAt = calculateNextRun(tempSchedule, new Date());
327
327
  }
328
328
 
329
+ // Not the audit task: a schedule fires its tasks as requested by created_by.
329
330
  const createdBy =
330
331
  (await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId)) ??
331
332
  undefined;
@@ -22,6 +22,9 @@ const scheduleRowShape = {
22
22
  lastRunAt: z.string().optional(),
23
23
  nextRunAt: z.string().optional(),
24
24
  createdByAgentId: z.string().optional(),
25
+ updatedByAgentId: z.string().optional(),
26
+ createdBy: z.string().optional(),
27
+ updatedBy: z.string().optional(),
25
28
  parentTaskId: z.string().optional(),
26
29
  timezone: z.string().optional(),
27
30
  consecutiveErrors: z.number().optional(),
@@ -378,10 +378,19 @@ export const registerPatchScheduleTool = (server: McpServer) => {
378
378
  }
379
379
 
380
380
  const updatedBy =
381
- (await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId)) ??
381
+ (await resolveTaskAuditUserId(requestInfo.auditSourceTaskId, requestInfo.agentId)) ??
382
382
  undefined;
383
- if (key !== undefined) updateData.key = await authorizeAssetKeyWrite(key, updatedBy);
384
- const updated = await updateScheduledTask(schedule.id, { ...updateData, updatedBy });
383
+ if (key !== undefined) {
384
+ updateData.key = await authorizeAssetKeyWrite(
385
+ key,
386
+ await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId),
387
+ );
388
+ }
389
+ const updated = await updateScheduledTask(schedule.id, {
390
+ ...updateData,
391
+ updatedBy: updatedBy ?? null,
392
+ updatedByAgentId: requestInfo.agentId ?? null,
393
+ });
385
394
 
386
395
  if (!updated) {
387
396
  return toolErr("Failed to update schedule.");
@@ -377,10 +377,19 @@ export const registerUpdateScheduleTool = (server: McpServer) => {
377
377
  }
378
378
 
379
379
  const updatedBy =
380
- (await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId)) ??
380
+ (await resolveTaskAuditUserId(requestInfo.auditSourceTaskId, requestInfo.agentId)) ??
381
381
  undefined;
382
- if (key !== undefined) updateData.key = await authorizeAssetKeyWrite(key, updatedBy);
383
- const updated = await updateScheduledTask(schedule.id, { ...updateData, updatedBy });
382
+ if (key !== undefined) {
383
+ updateData.key = await authorizeAssetKeyWrite(
384
+ key,
385
+ await resolveTaskAuditUserId(requestInfo.sourceTaskId, requestInfo.agentId),
386
+ );
387
+ }
388
+ const updated = await updateScheduledTask(schedule.id, {
389
+ ...updateData,
390
+ updatedBy: updatedBy ?? null,
391
+ updatedByAgentId: requestInfo.agentId ?? null,
392
+ });
384
393
 
385
394
  if (!updated) {
386
395
  return toolErr("Failed to update schedule.");
@@ -6,8 +6,10 @@ import {
6
6
  appendSheetRows,
7
7
  clearSheetRange,
8
8
  createSheet,
9
+ exportSheetXlsx,
9
10
  getSheet,
10
11
  getSheetRange,
12
+ importSheetXlsx,
11
13
  listSheets,
12
14
  setSheetRange,
13
15
  } from "@/be/primitives/sheets/service";
@@ -59,6 +61,8 @@ const dataShape = {
59
61
  changed: z.number().optional(),
60
62
  recalculated: z.number().optional(),
61
63
  cleared: z.number().optional(),
64
+ path: z.string().optional(),
65
+ dropped: z.array(z.string()).optional(),
62
66
  };
63
67
 
64
68
  const outputSchema = swarmToolOutputSchema(dataShape);
@@ -310,3 +314,65 @@ export const registerSheetAddTabTool = (server: McpServer) => {
310
314
  },
311
315
  );
312
316
  };
317
+
318
+ const dropMessage = (dropped: string[]) =>
319
+ dropped.length ? `Dropped: ${dropped.join(", ")}.` : "Nothing dropped.";
320
+
321
+ export const registerSheetImportXlsxTool = (server: McpServer) => {
322
+ createToolRegistrar(server)(
323
+ "sheet-import-xlsx",
324
+ {
325
+ title: "Import xlsx as sheet",
326
+ annotations: WRITE,
327
+ description:
328
+ "Import an `.xlsx` file from your default agent-fs drive as a new sheet, as your own agent-fs identity. Create-only: refuses when the sheet path exists. Keeps tabs, values, formulas (recomputed), number formats, column widths and merges. `dropped` lists what the file had that a sheet cannot hold (styles, charts, comments, frozen panes, and so on). Limits: 5 MiB file, 20 tabs, 50,000 cells; nothing is created when a limit refuses.",
329
+ inputSchema: z.object({
330
+ sourcePath: z.string().min(1).describe("Drive path of the `.xlsx` file to import."),
331
+ path: z.string().min(1).describe("Drive path for the new sheet, ending in `.sheet.json`."),
332
+ title: z.string().max(200).optional(),
333
+ }),
334
+ outputSchema,
335
+ },
336
+ async ({ sourcePath, path, title }, requestInfo) => {
337
+ const result = await refusing(requestInfo.agentId, () =>
338
+ importSheetXlsx({ agentId: requestInfo.agentId, sourcePath, path, title }),
339
+ );
340
+ if ("error" in result) return result.error;
341
+ const { object, link, dropped } = result.value;
342
+ return toolOk(
343
+ `Imported ${sourcePath} as sheet ${object.id} at ${object.path}${link ? ` (${link})` : ""}. ${dropMessage(dropped)}`,
344
+ { data: { yourAgentId: requestInfo.agentId, ...result.value } },
345
+ );
346
+ },
347
+ );
348
+ };
349
+
350
+ export const registerSheetExportXlsxTool = (server: McpServer) => {
351
+ createToolRegistrar(server)(
352
+ "sheet-export-xlsx",
353
+ {
354
+ title: "Export sheet as xlsx",
355
+ annotations: WRITE,
356
+ description:
357
+ "Export a sheet to an `.xlsx` file on your default agent-fs drive. Writes formulas with their cached values, number formats, column widths and merges. `dropped` lists what the file cannot carry (frozen panes, spilled array cells). Create-only: refuses when `targetPath` exists unless `overwrite` is true.",
358
+ inputSchema: z.object({
359
+ id: z.string().min(1).optional().describe(ID),
360
+ path: z.string().min(1).optional().describe(PATH),
361
+ targetPath: z.string().min(1).describe("Drive path for the new file, ending in `.xlsx`."),
362
+ overwrite: z.boolean().optional().describe("Replace `targetPath` when it exists."),
363
+ }),
364
+ outputSchema,
365
+ },
366
+ async ({ id, path, targetPath, overwrite }, requestInfo) => {
367
+ const result = await refusing(requestInfo.agentId, () =>
368
+ exportSheetXlsx({ agentId: requestInfo.agentId, id, path, targetPath, overwrite }),
369
+ );
370
+ if ("error" in result) return result.error;
371
+ const r = result.value;
372
+ return toolOk(
373
+ `Exported to ${r.path}${r.link ? ` (${r.link})` : ""}. ${dropMessage(r.dropped)}`,
374
+ { data: { yourAgentId: requestInfo.agentId, ...r } },
375
+ );
376
+ },
377
+ );
378
+ };
@@ -1,5 +1,6 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import * as z from "zod";
3
+ import { resolveTaskAuditUserId } from "@/be/audit-user";
3
4
  import { createSkill, getAgentById, installSkill } from "@/be/db";
4
5
  import { parseSkillContent } from "@/be/skill-parser";
5
6
  import { can } from "@/rbac";
@@ -72,6 +73,11 @@ export const registerSkillCreateTool = (server: McpServer) => {
72
73
  agent: parsed.agent,
73
74
  disableModelInvocation: parsed.disableModelInvocation,
74
75
  userInvocable: parsed.userInvocable,
76
+ createdByAgentId: requestInfo.agentId,
77
+ createdBy: await resolveTaskAuditUserId(
78
+ requestInfo.auditSourceTaskId,
79
+ requestInfo.agentId,
80
+ ),
75
81
  });
76
82
 
77
83
  // Auto-install for the creating agent
@@ -1,5 +1,6 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import * as z from "zod";
3
+ import { resolveTaskAuditUserId } from "@/be/audit-user";
3
4
  import { createSkill, getAgentById } from "@/be/db";
4
5
  import { parseSkillContent } from "@/be/skill-parser";
5
6
  import { can } from "@/rbac";
@@ -112,6 +113,11 @@ export const registerSkillInstallRemoteTool = (server: McpServer) => {
112
113
  agent: parsedMeta.agent,
113
114
  disableModelInvocation: parsedMeta.disableModelInvocation,
114
115
  userInvocable: parsedMeta.userInvocable,
116
+ createdByAgentId: requestInfo.agentId,
117
+ createdBy: await resolveTaskAuditUserId(
118
+ requestInfo.auditSourceTaskId,
119
+ requestInfo.agentId,
120
+ ),
115
121
  });
116
122
 
117
123
  return toolOk(`Installed remote skill "${skill.name}".`, {
@@ -1,5 +1,6 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import * as z from "zod";
3
+ import { resolveTaskAuditUserId } from "@/be/audit-user";
3
4
  import { getSkillById, listSkills, updateSkill } from "@/be/db";
4
5
  import { parseSkillContent } from "@/be/skill-parser";
5
6
  import { createToolRegistrar, swarmToolOutputSchema, toolErr, toolOk } from "@/tools/utils";
@@ -46,6 +47,12 @@ export const registerSkillSyncRemoteTool = (server: McpServer) => {
46
47
 
47
48
  let updated = 0;
48
49
  const errors: string[] = [];
50
+ // A content change is attributed to the caller; a lastFetchedAt-only
51
+ // touch is a fetch, not an edit, and leaves the audit pair alone.
52
+ const updatedBy = await resolveTaskAuditUserId(
53
+ requestInfo.auditSourceTaskId,
54
+ requestInfo.agentId,
55
+ );
49
56
 
50
57
  for (const skill of skills) {
51
58
  if (skill.isComplex) continue; // Skip complex skills (handled by npx)
@@ -80,6 +87,8 @@ export const registerSkillSyncRemoteTool = (server: McpServer) => {
80
87
  userInvocable: parsed.userInvocable,
81
88
  sourceHash: newHash,
82
89
  lastFetchedAt: now,
90
+ updatedByAgentId: requestInfo.agentId ?? null,
91
+ updatedBy,
83
92
  });
84
93
  updated++;
85
94
  } else {