@johpaz/hive-agents 0.0.45 → 1.0.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 (298) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -852
  3. package/dist/hive.js +59290 -58797
  4. package/dist/tool-worker.js +220 -925
  5. package/dist/ui/assets/A2UIPage-D4nUFe5q.js +8 -0
  6. package/dist/ui/assets/AgentCreateForm-g1mQnIoJ.js +1 -0
  7. package/dist/ui/assets/AgentDetailPage-C3XkU4Ll.js +1 -0
  8. package/dist/ui/assets/AgentNewPage-CEkLeA79.js +1 -0
  9. package/dist/ui/assets/AgentsPage-CNA778Eo.js +10 -0
  10. package/dist/ui/assets/ApiClientPage-t5DpKhmA.js +3 -0
  11. package/dist/ui/assets/ChannelsPage-yY6t0YTU.js +8 -0
  12. package/dist/ui/assets/DashboardPage-BSeNSYg5.js +6 -0
  13. package/dist/ui/assets/{LoginPage-BTxJdFVG.js → LoginPage-eT5zDRDa.js} +1 -1
  14. package/dist/ui/assets/{LogsPage-DVV2eHbh.js → LogsPage-Gczzzsdh.js} +1 -1
  15. package/dist/ui/assets/MeetingPage-Bu4aMMNR.js +1 -0
  16. package/dist/ui/assets/ModelSelector-nNOrW3te.js +1 -0
  17. package/dist/ui/assets/{NotFound-BIUDlIXU.js → NotFound-Bpr12V51.js} +1 -1
  18. package/dist/ui/assets/Office3DPage-B_iXEbyv.js +4614 -0
  19. package/dist/ui/assets/Office3DPage-C3SIzd2H.css +1 -0
  20. package/dist/ui/assets/ProvidersPage-BupHs5yO.js +1 -0
  21. package/dist/ui/assets/{RecoverPage-7YDQysBL.js → RecoverPage-DMqSasKk.js} +1 -1
  22. package/dist/ui/assets/SettingsPage-B6FTSkOn.js +9 -0
  23. package/dist/ui/assets/SetupPage-DhcRbGgg.js +1 -0
  24. package/dist/ui/assets/WebChatPage-CWXjW4Hn.js +29 -0
  25. package/dist/ui/assets/{activity-c3pNngT_.js → activity-CQuPevhB.js} +1 -1
  26. package/dist/ui/assets/agentCapabilities-CDC6y91E.js +1 -0
  27. package/dist/ui/assets/alert-CQlRq6sv.js +1 -0
  28. package/dist/ui/assets/arrow-left-0EBE7nsF.js +1 -0
  29. package/dist/ui/assets/arrow-right-5QIaph-z.js +1 -0
  30. package/dist/ui/assets/arrow-up-right-DQQCY007.js +1 -0
  31. package/dist/ui/assets/badge-DKGZbVZJ.js +1 -0
  32. package/dist/ui/assets/{calendar-B-KZ9RQO.js → calendar-Be23hQGc.js} +1 -1
  33. package/dist/ui/assets/{card-CNf6BS2e.js → card-D3Nw3kh3.js} +1 -1
  34. package/dist/ui/assets/check-Dp6tzwax.js +1 -0
  35. package/dist/ui/assets/chevron-down-33N886NY.js +1 -0
  36. package/dist/ui/assets/chevron-left-C6itJXh3.js +1 -0
  37. package/dist/ui/assets/chevron-right-CFodBS-b.js +1 -0
  38. package/dist/ui/assets/chevron-up-BvSmyBEs.js +1 -0
  39. package/dist/ui/assets/{circle-alert-KuAm2FWh.js → circle-alert-BDVHxmAz.js} +1 -1
  40. package/dist/ui/assets/circle-check-BJWNbLuF.js +1 -0
  41. package/dist/ui/assets/{circle-x-DjLkFDO8.js → circle-x-Cb2Yer4s.js} +1 -1
  42. package/dist/ui/assets/{copy-Bu5d7C-0.js → copy-33tZrzc9.js} +1 -1
  43. package/dist/ui/assets/{dialog-Jk4bieO4.js → dialog-KOZKWbib.js} +1 -1
  44. package/dist/ui/assets/dist-CD_qfA30.js +1 -0
  45. package/dist/ui/assets/{download-Cjbk4Rek.js → download-CiQqqXyz.js} +1 -1
  46. package/dist/ui/assets/earth-DCvN7ynm.js +1 -0
  47. package/dist/ui/assets/ellipsis-vertical-BybFZDk2.js +1 -0
  48. package/dist/ui/assets/{external-link-6sTlRDUR.js → external-link-0iNNBvZm.js} +1 -1
  49. package/dist/ui/assets/{eye-Df8o0tkC.js → eye-C8sKSSkg.js} +1 -1
  50. package/dist/ui/assets/{file-text-lnxnjBp0.js → file-text-DO8jqiJK.js} +1 -1
  51. package/dist/ui/assets/{gateway-url-DwzPmoc8.js → gateway-url-BlnabM5e.js} +1 -1
  52. package/dist/ui/assets/gauge-BRGwuN8G.js +1 -0
  53. package/dist/ui/assets/{history-CAF_R34_.js → history-BtTD1kDo.js} +1 -1
  54. package/dist/ui/assets/index-Bejlp-R1.js +116 -0
  55. package/dist/ui/assets/index-XoTT41Hr.css +2 -0
  56. package/dist/ui/assets/{info-WjromB4Y.js → info-mpk1tsNC.js} +1 -1
  57. package/dist/ui/assets/key-CoQ0qtXt.js +1 -0
  58. package/dist/ui/assets/label-k0jYxoWW.js +1 -0
  59. package/dist/ui/assets/loader-circle-BhqRN2nO.js +1 -0
  60. package/dist/ui/assets/lock-open-Cd2aqwOd.js +1 -0
  61. package/dist/ui/assets/mail-BG0RYSkL.js +1 -0
  62. package/dist/ui/assets/{pause-VqeUmp2Z.js → pause-Cme88_9s.js} +1 -1
  63. package/dist/ui/assets/pencil-f1nJ1xhs.js +1 -0
  64. package/dist/ui/assets/play-CfYDHD6h.js +1 -0
  65. package/dist/ui/assets/plus-C5BxJeOX.js +1 -0
  66. package/dist/ui/assets/progress-DrI2UDu-.js +1 -0
  67. package/dist/ui/assets/radio-B5SpKJ-J.js +1 -0
  68. package/dist/ui/assets/{refresh-cw-CCzDCAuz.js → refresh-cw-CroGQY62.js} +1 -1
  69. package/dist/ui/assets/scroll-area-CfHn94Vb.js +1 -0
  70. package/dist/ui/assets/search-rfBcmohK.js +1 -0
  71. package/dist/ui/assets/select-BhbW0stK.js +1 -0
  72. package/dist/ui/assets/{send-BPk9XbIq.js → send-D6whYpw-.js} +1 -1
  73. package/dist/ui/assets/{settings-BGfrZ_zM.js → settings-BX6q3MGB.js} +1 -1
  74. package/dist/ui/assets/{shield-CxhcUT39.js → shield-BnGyu1xf.js} +1 -1
  75. package/dist/ui/assets/slider-CmE_z1Ii.js +1 -0
  76. package/dist/ui/assets/{sparkles-BhwlS1pc.js → sparkles-BcaOs_Jk.js} +1 -1
  77. package/dist/ui/assets/{square-DMNWw4Hi.js → square-ju5H8nrT.js} +1 -1
  78. package/dist/ui/assets/switch-DXcELPsM.js +1 -0
  79. package/dist/ui/assets/tabs-CxiybXcw.js +1 -0
  80. package/dist/ui/assets/terminal-Bjfu-TkS.js +1 -0
  81. package/dist/ui/assets/{textarea-B6Z1Zc6W.js → textarea-rp6vsOZl.js} +1 -1
  82. package/dist/ui/assets/{trash-2-xD2o4SgX.js → trash-2-DjQXac_0.js} +1 -1
  83. package/dist/ui/assets/{triangle-alert-pVIJGjga.js → triangle-alert-B04mgMcg.js} +1 -1
  84. package/dist/ui/assets/{useHiveAgentsModelLoad-BnC4jLE-.js → useHiveAgentsModelLoad-DT5-4CCj.js} +1 -1
  85. package/dist/ui/assets/useOfficeModel-Cy7cAyEn.js +1 -0
  86. package/dist/ui/assets/useProviders-DSX7eVsz.js +1 -0
  87. package/dist/ui/assets/utils-Dyb7SC2_.js +1 -0
  88. package/dist/ui/assets/vendor-charts-K3xcRl0X.js +60 -0
  89. package/dist/ui/assets/{vendor-query-DsWPbQdG.js → vendor-query-Dj8xYhQD.js} +1 -1
  90. package/dist/ui/assets/vendor-radix-D0s_k6Gp.js +63 -0
  91. package/dist/ui/assets/vendor-react-CPJEWbIG.js +1 -0
  92. package/dist/ui/assets/{vendor-router-gqiZ7xhx.js → vendor-router-zpB-76nT.js} +1 -1
  93. package/dist/ui/assets/volume-x-qnVxkRSM.js +1 -0
  94. package/dist/ui/assets/wifi-BA1m2dGO.js +1 -0
  95. package/dist/ui/assets/{zap-B4RaNNO5.js → zap-DT7cM7YS.js} +1 -1
  96. package/dist/ui/index.html +10 -9
  97. package/package.json +8 -9
  98. package/packages/cli/src/adapters/config.ts +1 -80
  99. package/packages/cli/src/adapters/factory.ts +0 -45
  100. package/packages/cli/src/adapters/index.ts +0 -8
  101. package/packages/cli/src/commands/doctor.ts +45 -1
  102. package/packages/cli/src/commands/gateway.ts +2 -9
  103. package/packages/cli/src/index.ts +9 -11
  104. package/packages/core/src/agent/acceptance-verifier.ts +300 -0
  105. package/packages/core/src/agent/agent-catalog.ts +384 -0
  106. package/packages/core/src/agent/agent-loop.ts +185 -28
  107. package/packages/core/src/agent/capability-search.ts +5 -5
  108. package/packages/core/src/agent/catalog-selector.ts +104 -0
  109. package/packages/core/src/agent/compaction.ts +36 -41
  110. package/packages/core/src/agent/context-compiler.ts +182 -62
  111. package/packages/core/src/agent/conversation-store.ts +56 -3
  112. package/packages/core/src/agent/curator.ts +129 -34
  113. package/packages/core/src/agent/delegation-runtime.ts +248 -0
  114. package/packages/core/src/agent/index.ts +17 -0
  115. package/packages/core/src/agent/llm-providers/hiveagents.ts +1 -1
  116. package/packages/core/src/agent/llm-providers/interface.ts +3 -3
  117. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
  118. package/packages/core/src/agent/minimal-loadout.ts +46 -0
  119. package/packages/core/src/agent/playbook-selector.ts +1 -1
  120. package/packages/core/src/agent/prompt-builder.ts +4 -0
  121. package/packages/core/src/agent/proof-packet.ts +15 -1
  122. package/packages/core/src/agent/providers/index.ts +8 -3
  123. package/packages/core/src/agent/routing-intent.ts +22 -0
  124. package/packages/core/src/agent/run-store.ts +24 -3
  125. package/packages/core/src/agent/service.ts +2 -2
  126. package/packages/core/src/agent/skill-selector.ts +12 -31
  127. package/packages/core/src/agent/tool-selector.ts +36 -35
  128. package/packages/core/src/agent/tracer.ts +5 -1
  129. package/packages/core/src/artifacts/store.ts +162 -0
  130. package/packages/core/src/canvas/canvas-manager.ts +5 -234
  131. package/packages/core/src/canvas/emitter.ts +165 -69
  132. package/packages/core/src/canvas/index.ts +0 -2
  133. package/packages/core/src/channels/base.ts +3 -1
  134. package/packages/core/src/channels/webchat.ts +4 -8
  135. package/packages/core/src/config/loader.ts +0 -22
  136. package/packages/core/src/events/agent-bus.ts +0 -31
  137. package/packages/core/src/events/narration.ts +82 -0
  138. package/packages/core/src/gateway/channel-notify.ts +34 -5
  139. package/packages/core/src/gateway/delegation-groups.ts +245 -0
  140. package/packages/core/src/gateway/delegation-notify.ts +103 -0
  141. package/packages/core/src/gateway/durable-queue.ts +33 -2
  142. package/packages/core/src/gateway/helpers/index.ts +2 -2
  143. package/packages/core/src/gateway/helpers/narration.ts +12 -7
  144. package/packages/core/src/gateway/helpers/redact.ts +1 -1
  145. package/packages/core/src/gateway/initializer.ts +15 -13
  146. package/packages/core/src/gateway/job-executors.ts +232 -101
  147. package/packages/core/src/gateway/lane-queue.ts +1 -1
  148. package/packages/core/src/gateway/notification-inbox.ts +57 -0
  149. package/packages/core/src/gateway/resolver.ts +1 -23
  150. package/packages/core/src/gateway/routes/agents.ts +91 -1
  151. package/packages/core/src/gateway/routes/auth.ts +21 -42
  152. package/packages/core/src/gateway/routes/chat.ts +6 -6
  153. package/packages/core/src/gateway/routes/cron-api.ts +0 -4
  154. package/packages/core/src/gateway/routes/mcp.ts +0 -63
  155. package/packages/core/src/gateway/routes/meeting.ts +245 -0
  156. package/packages/core/src/gateway/routes/providers.ts +1 -0
  157. package/packages/core/src/gateway/routes/setup.ts +29 -24
  158. package/packages/core/src/gateway/routes/skills.ts +2 -2
  159. package/packages/core/src/gateway/routes/system.ts +23 -5
  160. package/packages/core/src/gateway/routes/users.ts +24 -1
  161. package/packages/core/src/gateway/server.ts +153 -117
  162. package/packages/core/src/gateway/session.ts +6 -4
  163. package/packages/core/src/gateway/slash-commands.ts +7 -6
  164. package/packages/core/src/gateway/webchat-turn.ts +34 -8
  165. package/packages/core/src/index.ts +3 -0
  166. package/packages/core/src/mcp/hot-reload.ts +14 -7
  167. package/packages/core/src/mcp/singleton.ts +0 -3
  168. package/packages/core/src/mcp/tool-sync.ts +2 -2
  169. package/packages/core/src/resilience/retry.ts +1 -1
  170. package/packages/core/src/scheduler/CronScheduler.ts +3 -1
  171. package/packages/core/src/scheduler/integration.ts +1 -1
  172. package/packages/core/src/storage/bootstrap.ts +25 -5
  173. package/packages/core/src/storage/collections.ts +201 -27
  174. package/packages/core/src/storage/onboarding.ts +147 -32
  175. package/packages/core/src/storage/reconcile.ts +2 -5
  176. package/packages/core/src/storage/seed.ts +202 -38
  177. package/packages/core/src/storage/usage.ts +0 -9
  178. package/packages/core/src/storage/user-email.ts +11 -0
  179. package/packages/core/src/tool-runtime/index.ts +69 -23
  180. package/packages/core/src/tool-runtime/worker-tools.ts +4 -2
  181. package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
  182. package/packages/core/src/tools/agents/get-available-models.ts +11 -3
  183. package/packages/core/src/tools/agents/index.ts +404 -86
  184. package/packages/core/src/tools/core/index.ts +28 -10
  185. package/packages/core/src/tools/cron/index.ts +1 -6
  186. package/packages/core/src/tools/index.ts +17 -45
  187. package/packages/core/src/tools/types.ts +1 -1
  188. package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
  189. package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
  190. package/packages/core/src/tools/web/index.ts +3 -0
  191. package/packages/core/src/utils/logger.ts +58 -30
  192. package/packages/core/src/utils/toon.ts +0 -20
  193. package/packages/mcp/src/manager.ts +8 -7
  194. package/packages/mcp/src/transports/sse.ts +0 -4
  195. package/packages/mcp/src/transports/websocket.ts +0 -6
  196. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_dashboard/SKILL.md +4 -4
  197. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_form/SKILL.md +4 -4
  198. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_interactive/SKILL.md +5 -5
  199. package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +26 -0
  200. package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +24 -18
  201. package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +47 -148
  202. package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +9 -10
  203. package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +1 -1
  204. package/packages/skills/src/bundled/cli/software_engineering/SKILL.md +23 -0
  205. package/packages/skills/src/bundled/cron_manager/SKILL.md +2 -2
  206. package/packages/skills/src/bundled/cron_reminder/SKILL.md +7 -7
  207. package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +11 -10
  208. package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +29 -35
  209. package/packages/skills/src/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
  210. package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +5 -4
  211. package/packages/skills/src/bundled-data.generated.ts +155 -720
  212. package/dist/ui/assets/AgentCreateForm-DzaIT-dA.js +0 -1
  213. package/dist/ui/assets/AgentDetailPage-DgqcJceY.js +0 -1
  214. package/dist/ui/assets/AgentNewPage-CNSpoOSA.js +0 -1
  215. package/dist/ui/assets/AgentsPage-BMUJzTD6.js +0 -10
  216. package/dist/ui/assets/ApiClientPage-Cum_a_3j.js +0 -3
  217. package/dist/ui/assets/CanvasPage-o6oCP6uq.js +0 -33
  218. package/dist/ui/assets/ChannelsPage-WrB0zwLq.js +0 -8
  219. package/dist/ui/assets/DashboardPage-BCd6kNw0.js +0 -6
  220. package/dist/ui/assets/MeetingPage-BULIAWzq.js +0 -1
  221. package/dist/ui/assets/ModelSelector-BMYOChYb.js +0 -1
  222. package/dist/ui/assets/ProvidersPage-BVN5UZrI.js +0 -1
  223. package/dist/ui/assets/SettingsPage-CYmpFfDn.js +0 -9
  224. package/dist/ui/assets/SetupPage-Dnmb1Lbv.js +0 -1
  225. package/dist/ui/assets/WebChatPage-DmmdFhIC.js +0 -16
  226. package/dist/ui/assets/accordion-CnLzKNHK.js +0 -1
  227. package/dist/ui/assets/alert-B9J6KHmt.js +0 -1
  228. package/dist/ui/assets/alert-dialog-KcYQWcJ6.js +0 -1
  229. package/dist/ui/assets/arrow-left-CBcbX5EZ.js +0 -1
  230. package/dist/ui/assets/badge-88dRb4M8.js +0 -1
  231. package/dist/ui/assets/bell-8BqRYmzf.js +0 -1
  232. package/dist/ui/assets/chevron-down-DIosfU_U.js +0 -1
  233. package/dist/ui/assets/chevron-left-D4U-5A27.js +0 -1
  234. package/dist/ui/assets/chevron-right-CR4Skrf3.js +0 -1
  235. package/dist/ui/assets/chevron-up-CI-W21Fy.js +0 -1
  236. package/dist/ui/assets/circle-check-6Ard1-2z.js +0 -1
  237. package/dist/ui/assets/dropdown-menu-DDiaHg5y.js +0 -1
  238. package/dist/ui/assets/es-4I-joeZz.js +0 -1
  239. package/dist/ui/assets/folder-open-DJBLDFjv.js +0 -1
  240. package/dist/ui/assets/format-DsLPBxvt.js +0 -1
  241. package/dist/ui/assets/gauge-B8Tj43rC.js +0 -1
  242. package/dist/ui/assets/hexagon-6L79pgVK.js +0 -1
  243. package/dist/ui/assets/index-BmwTAwOF.css +0 -2
  244. package/dist/ui/assets/index-Cyw7L0Li.js +0 -116
  245. package/dist/ui/assets/key-DyKOoQh5.js +0 -1
  246. package/dist/ui/assets/label-B_15zZlR.js +0 -1
  247. package/dist/ui/assets/loader-circle-BmBOgYze.js +0 -1
  248. package/dist/ui/assets/lock-BS6OLXPv.js +0 -1
  249. package/dist/ui/assets/play-zJpWuhrr.js +0 -1
  250. package/dist/ui/assets/plus-BZQX26Dr.js +0 -1
  251. package/dist/ui/assets/progress-D5c-Eilm.js +0 -1
  252. package/dist/ui/assets/scroll-area-CihOx0cb.js +0 -1
  253. package/dist/ui/assets/search-DzDptO9s.js +0 -1
  254. package/dist/ui/assets/select-BQCOjM2j.js +0 -1
  255. package/dist/ui/assets/slider-bcUiUfx0.js +0 -14
  256. package/dist/ui/assets/switch-BR30E4ej.js +0 -1
  257. package/dist/ui/assets/table-B3aGEaVp.js +0 -1
  258. package/dist/ui/assets/tabs-LQidMKRS.js +0 -1
  259. package/dist/ui/assets/terminal--7G943As.js +0 -1
  260. package/dist/ui/assets/useProviders-C1xVKLxB.js +0 -1
  261. package/dist/ui/assets/utils-3pnRFmFe.js +0 -1
  262. package/dist/ui/assets/vendor-charts-Bu2lyBKP.js +0 -65
  263. package/dist/ui/assets/vendor-radix-D6rA7xKY.js +0 -63
  264. package/dist/ui/assets/vendor-react-BU5iQU4f.js +0 -1
  265. package/dist/ui/assets/volume-2-BekVQl6P.js +0 -1
  266. package/packages/core/src/agent/context-guard.ts +0 -91
  267. package/packages/core/src/agent/hooks.ts +0 -166
  268. package/packages/core/src/agent/providers.ts +0 -1
  269. package/packages/core/src/auth/auth.ts +0 -111
  270. package/packages/core/src/auth/index.ts +0 -1
  271. package/packages/core/src/canvas/canvas-tools.ts +0 -448
  272. package/packages/core/src/gateway/router.ts +0 -126
  273. package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
  274. package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
  275. package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
  276. package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
  277. package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
  278. package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
  279. package/packages/core/src/scheduler/dag/errors.ts +0 -37
  280. package/packages/core/src/scheduler/dag/index.ts +0 -26
  281. package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
  282. package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
  283. package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
  284. package/packages/core/src/scheduler/index.ts +0 -22
  285. package/packages/core/src/scheduler/task-driver.ts +0 -216
  286. package/packages/core/src/tools/canvas/index.ts +0 -420
  287. package/packages/core/src/tools/meeting/index.ts +0 -336
  288. package/packages/core/src/tools/projects/index.ts +0 -348
  289. package/packages/core/src/tools/voice/index.ts +0 -104
  290. package/packages/core/src/utils/index.ts +0 -5
  291. package/packages/skills/src/bundled/agents/code_delegator/SKILL.md +0 -156
  292. package/packages/skills/src/bundled/canvas/canvas_dashboard/SKILL.md +0 -146
  293. package/packages/skills/src/bundled/canvas/canvas_interact/SKILL.md +0 -148
  294. package/packages/skills/src/bundled/canvas/canvas_report/SKILL.md +0 -146
  295. package/packages/skills/src/bundled/meeting/meeting_transcription/SKILL.md +0 -213
  296. package/packages/skills/src/bundled/voice/voice_assistant/SKILL.md +0 -174
  297. package/packages/skills/src/bundled/voice/voice_input/SKILL.md +0 -146
  298. package/packages/skills/src/bundled/voice/voice_output/SKILL.md +0 -151
@@ -6,9 +6,19 @@
6
6
 
7
7
  import type { Tool } from "../types.ts";
8
8
  import { col, toIndexable, fromIndexable, BROADCAST } from "../../storage/hive.ts";
9
- import type { MemoryDoc, AgentDoc, ProviderDoc, ModelDoc, TaskDoc, AgentBusMessageDoc } from "../../storage/collections.ts";
9
+ import type { MemoryDoc, AgentDoc, ProviderDoc, ModelDoc, McpServerDoc, TaskDoc, AgentBusMessageDoc, AgentAcceptanceCriterion } from "../../storage/collections.ts";
10
+ import type { AcceptanceCriterion } from "../../agent/run-store.ts";
11
+ import type { PreparedDelegation } from "../../agent/delegation-runtime.ts";
10
12
  import { logger } from "../../utils/logger.ts";
11
13
  import { agentBus } from "../../events/agent-bus.ts";
14
+ import {
15
+ emitDelegationStarted,
16
+ emitDelegationFinished,
17
+ emitVerificationStarted,
18
+ emitVerificationFinished,
19
+ emitWorkEvent,
20
+ } from "../../canvas/emitter.ts";
21
+ import { VERIFIER_AGENT_ID } from "../../agent/acceptance-verifier.ts";
12
22
 
13
23
  const log = logger.child("agents");
14
24
 
@@ -184,7 +194,7 @@ export const memoryDeleteTool: Tool = {
184
194
 
185
195
  export const agentCreateTool: Tool = {
186
196
  name: "agent_create",
187
- description: "Crear un nuevo agente worker especializado. Requiere consultar get_available_models primero para seleccionar provider/model óptimos. Sinónimos: crear agente, nuevo worker, nuevo trabajador",
197
+ description: "Crear un nuevo agente worker especializado. Requiere consultar get_available_models; para un especialista MCP confirmado por el usuario, acepta mcp_server_id. Sinónimos: crear agente, nuevo worker, nuevo trabajador",
188
198
  parameters: {
189
199
  type: "object",
190
200
  properties: {
@@ -194,6 +204,10 @@ export const agentCreateTool: Tool = {
194
204
  tools_json: { type: "array", description: "Lista de IDs de herramientas", items: { type: "string" } },
195
205
  providerId: { type: "string", description: "ID del provider (openai, anthropic, ollama, etc.) - Obtener de get_available_models" },
196
206
  modelId: { type: "string", description: "ID del modelo (gpt-4o, claude-sonnet, etc.) - Obtener de get_available_models" },
207
+ mcp_server_id: {
208
+ type: "string",
209
+ description: "Servidor MCP persistente para un especialista. Requiere confirmación previa del usuario y asigna todas las tools actuales y futuras de ese servidor.",
210
+ },
197
211
  tone: { type: "string", description: "Tono del agente (friendly, professional, direct, etc.)" },
198
212
  max_iterations: { type: "number", description: "Límite de iteraciones del agente (default: 10)" },
199
213
  },
@@ -208,6 +222,7 @@ export const agentCreateTool: Tool = {
208
222
  const toolsJson = params.tools_json ? JSON.stringify(params.tools_json) : null;
209
223
  const providerId = params.providerId as string;
210
224
  const modelId = params.modelId as string;
225
+ const mcpServerId = params.mcp_server_id as string | undefined;
211
226
  const tone = (params.tone as string) ?? "friendly";
212
227
  const maxIterations = (params.max_iterations as number) ?? 10;
213
228
  const parentWorkspace = config?.configurable?.workspace ?? null;
@@ -238,7 +253,9 @@ export const agentCreateTool: Tool = {
238
253
  };
239
254
  }
240
255
 
241
- // Validar que el modelo existe y está activo
256
+ // Validar que el modelo existe y pertenece al provider ya validado. `active` en un
257
+ // ModelDoc solo marca el modelo por defecto del usuario (elegido en onboarding), no
258
+ // si el modelo es utilizable — cualquier modelo del provider configurado sirve.
242
259
  const modelsCol = await col<ModelDoc>("models");
243
260
  const modelEntry = await modelsCol.get(modelId);
244
261
 
@@ -249,13 +266,56 @@ export const agentCreateTool: Tool = {
249
266
  };
250
267
  }
251
268
 
252
- if (!modelEntry.doc.enabled || !modelEntry.doc.active) {
269
+ if (!modelEntry.doc.enabled) {
253
270
  return {
254
271
  ok: false,
255
- error: `Modelo '${modelId}' no está activo. Usá get_available_models para ver modelos activos.`
272
+ error: `Modelo '${modelId}' no está habilitado. Usá get_available_models para ver modelos disponibles.`
256
273
  };
257
274
  }
258
275
 
276
+ if (modelEntry.doc.provider_id !== providerId) {
277
+ return {
278
+ ok: false,
279
+ error: `Modelo '${modelId}' pertenece al provider '${modelEntry.doc.provider_id}', no a '${providerId}'.`
280
+ };
281
+ }
282
+
283
+ if (mcpServerId) {
284
+ if (!userId) {
285
+ return { ok: false, error: "No se puede asignar un servidor MCP sin contexto de usuario." };
286
+ }
287
+ const serverEntry = await (await col<McpServerDoc>("mcpServers")).get(mcpServerId);
288
+ if (!serverEntry?.doc.enabled) {
289
+ return { ok: false, error: `El servidor MCP '${mcpServerId}' no existe o está deshabilitado.` };
290
+ }
291
+ if (serverEntry.doc.user_id && serverEntry.doc.user_id !== userId) {
292
+ return { ok: false, error: `El servidor MCP '${mcpServerId}' pertenece a otro usuario.` };
293
+ }
294
+
295
+ const existingSpecialist = (await (await col<AgentDoc>("agents")).scan({}))
296
+ .map((entry) => entry.doc)
297
+ .find((agent) => {
298
+ if (agent.role !== "worker" || agent.user_id !== userId) return false;
299
+ try {
300
+ return agent.mcp_server_ids_json
301
+ ? (JSON.parse(agent.mcp_server_ids_json) as string[]).includes(mcpServerId)
302
+ : false;
303
+ } catch {
304
+ return false;
305
+ }
306
+ });
307
+ if (existingSpecialist) {
308
+ const action = existingSpecialist.enabled
309
+ ? "Reutilizalo con task_delegate."
310
+ : "Está deshabilitado; el usuario debe reactivarlo desde Agentes.";
311
+ return {
312
+ ok: false,
313
+ existingAgentId: existingSpecialist.id,
314
+ error: `Ya existe el especialista '${existingSpecialist.name}' para ese servidor. ${action}`,
315
+ };
316
+ }
317
+ }
318
+
259
319
  try {
260
320
  const agentId = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
261
321
  const now = Date.now();
@@ -263,7 +323,7 @@ export const agentCreateTool: Tool = {
263
323
  const agentsCol = await col<AgentDoc>("agents");
264
324
  await agentsCol.put(agentId, {
265
325
  id: agentId,
266
- user_id: userId,
326
+ user_id: userId ?? "",
267
327
  name,
268
328
  description,
269
329
  system_prompt: systemPrompt,
@@ -275,12 +335,15 @@ export const agentCreateTool: Tool = {
275
335
  model_id: toIndexable(modelId),
276
336
  tools_json: toolsJson,
277
337
  skills_json: null,
338
+ active_mcp_json: null,
278
339
  parent_id: toIndexable(parentId),
279
340
  max_iterations: maxIterations,
280
341
  workspace: parentWorkspace,
281
342
  lastTraceAt: null,
282
343
  created_at: now,
283
344
  updated_at: now,
345
+ source: "user",
346
+ mcp_server_ids_json: mcpServerId ? JSON.stringify([mcpServerId]) : null,
284
347
  }, { expectedVersion: 0 });
285
348
 
286
349
  return {
@@ -289,6 +352,7 @@ export const agentCreateTool: Tool = {
289
352
  name,
290
353
  providerId,
291
354
  modelId,
355
+ mcpServerId: mcpServerId ?? null,
292
356
  workspace: parentWorkspace,
293
357
  message: "Agente creado exitosamente."
294
358
  };
@@ -302,46 +366,81 @@ export const agentCreateTool: Tool = {
302
366
 
303
367
  export const agentFindTool: Tool = {
304
368
  name: "agent_find",
305
- description: "Find existing running or idle worker agents. Spanish: buscar agente, encontrar worker, localizar agente",
369
+ description: "Discover available worker agents. Includes global system catalog agents plus private workers owned by the current user. This tool does not report task execution; use task_list/task_status for that. Spanish: buscar agente, encontrar worker, localizar agente",
306
370
  parameters: {
307
371
  type: "object",
308
372
  properties: {
309
373
  search: { type: "string", description: "Search term for agent name or description" },
310
- status: { type: "string", enum: ["idle", "active", "any"], description: "Filter by status" },
374
+ availability: { type: "string", enum: ["enabled", "disabled", "any"], description: "Filter by whether the worker can accept tasks" },
375
+ status: { type: "string", enum: ["idle", "active", "any"], description: "Deprecated compatibility alias. It does not represent task execution; use task_list." },
311
376
  },
312
377
  },
313
378
  execute: async (params: Record<string, unknown>, config?: any) => {
314
379
  const userId = config?.configurable?.user_id;
315
380
  const search = params.search as string | undefined;
316
- const status = params.status as string | undefined;
381
+ const legacyStatus = params.status as string | undefined;
382
+ const availability = (params.availability as string | undefined)
383
+ ?? (legacyStatus === "any" ? "any" : legacyStatus ? "enabled" : "any");
317
384
 
318
385
  try {
319
386
  const agentsCol = await col<AgentDoc>("agents");
387
+ const mcpServersCol = await col<McpServerDoc>("mcpServers");
388
+ const serverNames = new Map(
389
+ (await mcpServersCol.scan({})).map((entry) => [entry.doc.id, entry.doc.name]),
390
+ );
320
391
  let agents = (await agentsCol.scan({}))
321
392
  .map(e => e.doc)
322
- .filter(a => a.user_id === userId && a.role === "worker");
393
+ .filter(a =>
394
+ a.role === "worker"
395
+ && (a.source === "catalog" || (!!userId && a.user_id === userId))
396
+ );
323
397
 
324
398
  if (search) {
325
399
  const needle = search.toLowerCase();
326
- agents = agents.filter(a =>
327
- a.name.toLowerCase().includes(needle) || (a.description ?? "").toLowerCase().includes(needle)
328
- );
400
+ agents = agents.filter((a) => {
401
+ let assignedServerIds: string[] = [];
402
+ try {
403
+ assignedServerIds = a.mcp_server_ids_json ? JSON.parse(a.mcp_server_ids_json) : [];
404
+ } catch {
405
+ assignedServerIds = [];
406
+ }
407
+ return a.name.toLowerCase().includes(needle)
408
+ || (a.description ?? "").toLowerCase().includes(needle)
409
+ || assignedServerIds.some((id) =>
410
+ id.toLowerCase().includes(needle)
411
+ || (serverNames.get(id) ?? "").toLowerCase().includes(needle),
412
+ );
413
+ });
329
414
  }
330
415
 
331
- if (status && status !== "any") {
332
- agents = agents.filter(a => a.status === status);
416
+ if (availability !== "any") {
417
+ agents = agents.filter(a => availability === "enabled" ? a.enabled : !a.enabled);
333
418
  }
334
419
 
335
420
  return {
336
421
  ok: true,
337
422
  count: agents.length,
338
- agents: agents.map((a) => ({
339
- id: a.id,
340
- name: a.name,
341
- description: a.description,
342
- role: a.role,
343
- status: a.status,
344
- })),
423
+ execution_source: "Use task_list or task_status for real execution state.",
424
+ ...(legacyStatus ? { warning: "The status filter is deprecated and cannot prove whether a task is running." } : {}),
425
+ agents: agents.map((a) => {
426
+ let mcpServerIds: string[] = [];
427
+ try {
428
+ mcpServerIds = a.mcp_server_ids_json ? JSON.parse(a.mcp_server_ids_json) : [];
429
+ } catch {
430
+ mcpServerIds = [];
431
+ }
432
+ return {
433
+ id: a.id,
434
+ name: a.name,
435
+ description: a.description,
436
+ role: a.role,
437
+ source: a.source ?? "user",
438
+ enabled: a.enabled,
439
+ availability: a.enabled ? "enabled" : "disabled",
440
+ mcpServerIds,
441
+ mcpServers: mcpServerIds.map((id) => ({ id, name: serverNames.get(id) ?? id })),
442
+ };
443
+ }),
345
444
  };
346
445
  } catch (error) {
347
446
  return { ok: false, error: `Failed to find agents: ${(error as Error).message}` };
@@ -353,11 +452,11 @@ export const agentFindTool: Tool = {
353
452
 
354
453
  export const agentArchiveTool: Tool = {
355
454
  name: "agent_archive",
356
- description: "Archive or terminate a worker agent. Spanish: archivar agente, terminar worker, desactivar agente",
455
+ description: "Archive or terminate a worker you created. Catalog agents cannot be archived — only the user can disable those from the UI. Spanish: archivar agente, terminar worker",
357
456
  parameters: {
358
457
  type: "object",
359
458
  properties: {
360
- agentId: { type: "string", description: "ID of the agent to archive" },
459
+ agentId: { type: "string", description: "ID of the worker to archive (not a catalog agent)" },
361
460
  },
362
461
  required: ["agentId"],
363
462
  },
@@ -372,7 +471,16 @@ export const agentArchiveTool: Tool = {
372
471
  return { ok: false, error: `Agent not found: ${agentId}` };
373
472
  }
374
473
 
375
- await agentsCol.put(agentId, { ...existing.doc, enabled: false, updated_at: Date.now() }, { expectedVersion: existing.version });
474
+ // Catalog personas are shared capabilities of the whole hive — turning
475
+ // one off is the user's call, from the UI, never an agent's.
476
+ if (existing.doc.source === "catalog") {
477
+ return {
478
+ ok: false,
479
+ error: `'${existing.doc.name}' is a catalog agent and stays available. Only the user can disable it from the Agents UI.`,
480
+ };
481
+ }
482
+
483
+ await agentsCol.put(agentId, { ...existing.doc, enabled: false, status: "archived", updated_at: Date.now() }, { expectedVersion: existing.version });
376
484
 
377
485
  return { ok: true, agentId, message: "Agent archived." };
378
486
  } catch (error) {
@@ -385,38 +493,70 @@ export const agentArchiveTool: Tool = {
385
493
 
386
494
  export const taskDelegateTool: Tool = {
387
495
  name: "task_delegate",
388
- description: "Delegate a task to a worker agent. mode=sync (default) blocks until done; mode=async enqueues and returns immediately. Spanish: delegar tarea, asignar worker, ejecutar por agente, delegate_task",
496
+ description: "Delegate a bounded task to an existing worker_id (any `agents` row: catalog-seeded or agent_create-made). The delivery is independently verified before success is returned. mode=sync blocks the conversation until done; mode=async enqueues and frees the conversation immediately — the user is notified automatically in this same chat when the worker finishes. Prefer async unless you expect the result in a few seconds.",
389
497
  parameters: {
390
498
  type: "object",
391
499
  properties: {
392
- worker_id: { type: "string", description: "ID of the worker agent" },
500
+ worker_id: { type: "string", description: "Target agent ID — from agent_find or the catalog agent list in the system prompt." },
393
501
  task_description: { type: "string", description: "Clear, detailed instructions for the worker" },
394
- mode: { type: "string", enum: ["sync", "async"], description: "sync (default, blocking 2min timeout) or async (enqueued, non-blocking)" },
502
+ acceptance: {
503
+ type: "array",
504
+ description: "Verifiable acceptance criteria. The worker's default criteria are used when omitted.",
505
+ items: {
506
+ type: "object",
507
+ properties: {
508
+ id: { type: "string" },
509
+ description: { type: "string" },
510
+ checkTool: { type: "string" },
511
+ },
512
+ required: ["id", "description"],
513
+ },
514
+ },
515
+ mode: { type: "string", enum: ["sync", "async"], description: "sync (default, blocking, 2min timeout — only for very short delegations) or async (enqueued, frees the conversation instantly; outcome is relayed back to the user automatically). Prefer async for anything non-trivial." },
395
516
  },
396
- required: ["worker_id", "task_description"],
517
+ required: ["task_description"],
397
518
  },
398
519
  execute: async (params: Record<string, unknown>, config?: any) => {
399
- const workerId = params.worker_id as string;
520
+ const agentId = params.worker_id as string | undefined;
400
521
  const taskDescription = params.task_description as string;
401
522
  const mode = (params.mode as string) ?? "sync";
523
+ const turnId = config?.configurable?.turn_id as string | undefined;
402
524
 
403
- const agentsCol = await col<AgentDoc>("agents");
404
- const workerEntry = await agentsCol.get(workerId);
525
+ if (!agentId) return { ok: false, error: "Provide worker_id." };
405
526
 
406
- if (!workerEntry) {
407
- return { ok: false, error: `Worker not found: ${workerId}` };
527
+ const agentsCol = await col<AgentDoc>("agents");
528
+ const parentAgentId = config?.configurable?.agent_id ?? "";
529
+ if (!parentAgentId) {
530
+ return { ok: false, error: "Delegation caller identity is missing (config.configurable.agent_id). The coordinator may exist, but its ID was not propagated to task_delegate." };
408
531
  }
532
+ const parentEntry = await agentsCol.get(parentAgentId);
533
+ if (!parentEntry) return { ok: false, error: `Delegation caller agent not found: ${parentAgentId}` };
534
+ if (!parentEntry.doc.enabled) return { ok: false, error: `Delegation caller agent is disabled: ${parentAgentId}` };
535
+ const parent = parentEntry.doc;
536
+ const parentProviderId = fromIndexable(parent.provider_id);
537
+ const parentModelId = fromIndexable(parent.model_id);
538
+
539
+ const workerEntry = await agentsCol.get(agentId);
540
+ if (!workerEntry) return { ok: false, error: `Agent not found: ${agentId}` };
409
541
  const worker = workerEntry.doc;
410
- if (!worker.enabled) {
411
- return { ok: false, error: `Worker is disabled: ${worker.name}` };
412
- }
542
+ if (!worker.enabled) return { ok: false, error: `Agent is disabled: ${worker.name}` };
413
543
 
414
544
  const taskName = taskDescription.slice(0, 60);
545
+ const defaultAcceptance: AgentAcceptanceCriterion[] | null = worker.default_acceptance_json
546
+ ? JSON.parse(worker.default_acceptance_json)
547
+ : null;
548
+ const acceptance = ((params.acceptance as AcceptanceCriterion[] | undefined)
549
+ ?? defaultAcceptance?.map((criterion) => ({
550
+ id: criterion.id,
551
+ description: criterion.description,
552
+ checkTool: criterion.check_tool,
553
+ }))
554
+ ?? [{ id: "objective", description: taskDescription }]);
415
555
 
416
556
  // ── Async mode: create TaskDoc + enqueue worker_task in durable queue ──
417
557
  if (mode === "async") {
418
558
  try {
419
- const { nextId, toIndexable } = await import("../../storage/hive.ts");
559
+ const { nextId, toIndexable, updateDoc } = await import("../../storage/hive.ts");
420
560
  const { createRun } = await import("../../agent/run-store.ts");
421
561
  const { getDurableQueue } = await import("../../gateway/durable-queue.ts");
422
562
 
@@ -425,21 +565,19 @@ export const taskDelegateTool: Tool = {
425
565
  const tasksCol = await col<TaskDoc>("tasks");
426
566
  await tasksCol.put(taskId, {
427
567
  id: taskId,
428
- project_id: toIndexable(null),
429
- agent_id: toIndexable(workerId),
430
- parent_task_id: null,
568
+ agent_id: toIndexable(agentId),
431
569
  name: taskName,
432
570
  description: taskDescription,
433
571
  status: "pending",
434
572
  progress: 0,
435
- priority: 0,
436
- depends_on: null,
437
573
  result: null,
438
574
  error: null,
439
575
  metadata: null,
440
576
  job_id: null,
441
577
  run_id: null,
442
578
  thread_id: null,
579
+ delegation_group_id: turnId ?? null,
580
+ catalog_agent_id: toIndexable(worker.source === "catalog" ? agentId : null),
443
581
  started_at: null,
444
582
  attempts: 0,
445
583
  created_at: now,
@@ -447,14 +585,29 @@ export const taskDelegateTool: Tool = {
447
585
  completed_at: null,
448
586
  }, { expectedVersion: 0 });
449
587
 
588
+ if (turnId) {
589
+ const { registerDelegatedTask } = await import("../../gateway/delegation-groups.ts");
590
+ await registerDelegatedTask({
591
+ turnId,
592
+ taskId,
593
+ threadId: config?.configurable?.thread_id ?? "",
594
+ channel: config?.configurable?.channel,
595
+ userId: config?.configurable?.user_id,
596
+ sessionId: config?.configurable?.session_id,
597
+ coordinatorAgentId: parentAgentId,
598
+ });
599
+ }
600
+
450
601
  const run = await createRun({
451
- thread_id: `task-${taskId}-${workerId}`,
452
- agent_id: workerId,
602
+ thread_id: `task-${taskId}-${agentId}`,
603
+ agent_id: agentId,
453
604
  user_id: config?.configurable?.user_id ?? "",
454
605
  channel: config?.configurable?.channel ?? null,
455
606
  kind: "worker",
456
607
  max_iterations: worker.max_iterations || 10,
457
608
  resume_policy: "resume",
609
+ acceptance,
610
+ catalog_agent_id: worker.source === "catalog" ? agentId : undefined,
458
611
  });
459
612
 
460
613
  const queue = getDurableQueue();
@@ -463,101 +616,266 @@ export const taskDelegateTool: Tool = {
463
616
  type: "worker_task",
464
617
  run_id: run.id,
465
618
  payload: {
466
- workerId,
619
+ workerId: agentId,
467
620
  taskDescription,
468
621
  taskName,
469
622
  taskId,
623
+ acceptance,
624
+ parentAgentId,
625
+ parentProviderId,
626
+ parentModelId,
627
+ userId: config?.configurable?.user_id ?? "",
628
+ workspace: config?.configurable?.workspace ?? null,
629
+ // Delegating conversation's thread — lets delegation-notify.ts relay
630
+ // the outcome back to the user once this job reaches a terminal state.
631
+ originThreadId: config?.configurable?.thread_id ?? null,
632
+ originChannel: config?.configurable?.channel ?? null,
633
+ originSessionId: config?.configurable?.session_id ?? null,
634
+ turnId: turnId ?? null,
470
635
  },
471
636
  });
472
637
 
473
- await import("../../storage/hive.ts").then(({ updateDoc }) =>
474
- updateDoc<TaskDoc>("tasks", taskId, {
475
- job_id: job.id,
476
- run_id: run.id,
477
- thread_id: `task-${taskId}-${workerId}`,
478
- updated_at: Date.now(),
479
- } as Partial<TaskDoc>)
480
- );
481
-
482
- agentBus.notifyTaskStarted(workerId, worker.name, 0, taskName, "");
638
+ await updateDoc<TaskDoc>("tasks", taskId, {
639
+ job_id: job.id,
640
+ run_id: run.id,
641
+ thread_id: `task-${taskId}-${agentId}`,
642
+ updated_at: Date.now(),
643
+ } as Partial<TaskDoc>);
644
+
645
+ agentBus.notifyTaskStarted(agentId, worker.name, 0, taskName, "");
646
+ if (turnId) {
647
+ const { publishNarration } = await import("../../events/narration.ts");
648
+ await publishNarration({
649
+ turnId,
650
+ threadId: config?.configurable?.thread_id ?? "",
651
+ channel: config?.configurable?.channel,
652
+ userId: config?.configurable?.user_id,
653
+ sessionId: config?.configurable?.session_id,
654
+ agentId,
655
+ agentName: worker.name,
656
+ kind: "delegated",
657
+ status: "queued",
658
+ label: `Delegué “${taskName}” a ${worker.name}`,
659
+ dedupeKey: `delegated:${taskId}`,
660
+ });
661
+ }
483
662
 
484
663
  return {
485
664
  ok: true,
486
665
  task_id: taskId,
487
666
  job_id: job.id,
488
667
  run_id: run.id,
489
- worker_id: workerId,
668
+ worker_id: agentId,
490
669
  worker_name: worker.name,
491
670
  status: "queued",
492
- message: `Task enqueued (async). Use task_status with task_id="${taskId}" to check progress.`,
671
+ message: `Task enqueued (async). Use task_list for the queue or task_status with task_id="${taskId}" for this task.`,
493
672
  };
494
673
  } catch (err) {
495
674
  return { ok: false, error: `Async delegation failed: ${(err as Error).message}` };
496
675
  }
497
676
  }
498
677
 
499
- // ── Sync mode: blocking execution with 2min timeout (existing behavior) ──
500
- agentBus.notifyTaskStarted(workerId, worker.name, 0, taskName, "");
678
+ // ── Sync mode: blocking execution with 2min timeout ──
679
+ const { prepareDelegation } = await import("../../agent/delegation-runtime.ts");
680
+ const { getMCPManager } = await import("../../mcp/singleton.ts");
681
+ const mcpManager = getMCPManager();
682
+
683
+ let prepared: PreparedDelegation;
684
+ try {
685
+ prepared = await prepareDelegation(agentId, {
686
+ workspace: config?.configurable?.workspace ?? null,
687
+ parentProviderId,
688
+ parentModelId,
689
+ mcpManager,
690
+ });
691
+ } catch (err) {
692
+ return { ok: false, error: (err as Error).message };
693
+ }
501
694
 
502
- log.info(`[task_delegate] Delegating (sync) to ${worker.name} (${workerId})`);
695
+ agentBus.notifyTaskStarted(agentId, worker.name, 0, taskName, "");
696
+ log.info(`[task_delegate] Delegating (sync) to ${worker.name} (${agentId})`);
697
+ const syncDelegationRef = `sync-${Date.now()}-${agentId}`;
698
+ emitDelegationStarted({ workerId: agentId, parentAgentId, taskRef: syncDelegationRef, taskName });
503
699
 
504
700
  try {
505
- const { runAgentIsolated } = await import("../../agent/agent-loop.ts");
701
+ const { runAgentIsolated, withTimeout } = await import("../../agent/agent-loop.ts");
506
702
 
507
- const threadId = `task-${Date.now()}-${workerId}`;
703
+ const threadId = `task-${Date.now()}-${agentId}`;
508
704
  const SYNC_TIMEOUT_MS = 2 * 60 * 1000;
509
705
 
510
- const { withTimeout } = await import("../../agent/agent-loop.ts");
706
+ // Real cancellation (e.g. the user's "stop" button): the job's AbortSignal
707
+ // reaches us via config.signal (tool-runtime/index.ts's executeToolBatch),
708
+ // and runAgentIsolated/runAgent already honor it mid-run. withTimeout stays
709
+ // as a hard ceiling in case the signal path doesn't stop things in time.
710
+ const signal = config?.signal as AbortSignal | undefined;
511
711
  const result = await withTimeout(
512
712
  () => runAgentIsolated({
513
- agentId: workerId,
713
+ agentId,
514
714
  taskDescription,
515
715
  threadId,
716
+ mcpManager,
717
+ signal,
516
718
  }),
517
719
  SYNC_TIMEOUT_MS,
518
720
  );
519
721
 
520
- agentBus.notifyTaskCompleted(workerId, worker.name, 0, taskName, "", result);
521
-
722
+ agentBus.notifyTaskCompleted(agentId, worker.name, 0, taskName, "", result);
723
+
724
+ // Verification now always runs, closing the old gap where a plain
725
+ // worker_id delegation (agent_create) skipped it entirely in sync mode.
726
+ const { verifyAgentDelivery } = await import("../../agent/acceptance-verifier.ts");
727
+ emitVerificationStarted({ verifierId: VERIFIER_AGENT_ID, workerId: agentId, taskRef: syncDelegationRef, taskName });
728
+ const verification = await verifyAgentDelivery({
729
+ runId: `sync-${crypto.randomUUID()}`,
730
+ executorAgentId: agentId,
731
+ objective: taskDescription,
732
+ acceptance,
733
+ delivery: result,
734
+ mcpServerIds: prepared.mcpServerIds,
735
+ mcpManager,
736
+ });
737
+ const verdict = JSON.parse(verification.verdict_json);
738
+ emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: syncDelegationRef });
739
+ if (verification.status !== "verified") {
740
+ emitWorkEvent({
741
+ phase: "review_failed",
742
+ taskRef: syncDelegationRef,
743
+ taskName,
744
+ actorId: VERIFIER_AGENT_ID,
745
+ targetId: agentId,
746
+ detail: verdict.summary || "La entrega no superó la verificación",
747
+ });
748
+ return {
749
+ ok: false,
750
+ status: verification.status,
751
+ verification_id: verification.id,
752
+ error: verdict.summary || "Independent verification did not authorize success.",
753
+ retry_guidance: verdict.retry_guidance,
754
+ };
755
+ }
756
+ emitWorkEvent({
757
+ phase: "review_passed",
758
+ taskRef: syncDelegationRef,
759
+ taskName,
760
+ actorId: VERIFIER_AGENT_ID,
761
+ targetId: agentId,
762
+ });
763
+ emitWorkEvent({
764
+ phase: "completed",
765
+ taskRef: syncDelegationRef,
766
+ taskName,
767
+ actorId: agentId,
768
+ targetId: parentAgentId || null,
769
+ });
522
770
  return {
523
771
  ok: true,
524
- worker_id: workerId,
772
+ worker_id: agentId,
525
773
  worker_name: worker.name,
774
+ verification_id: verification.id,
526
775
  result,
527
776
  };
528
777
  } catch (err) {
529
- agentBus.notifyTaskFailed(workerId, worker.name, 0, taskName, "", (err as Error).message);
778
+ const errorMessage = (err as Error).message;
779
+ const wasAborted = (config?.signal as AbortSignal | undefined)?.aborted === true;
780
+ agentBus.notifyTaskFailed(agentId, worker.name, 0, taskName, "", errorMessage);
781
+ emitWorkEvent({
782
+ phase: wasAborted ? "aborted" : "failed",
783
+ taskRef: syncDelegationRef,
784
+ taskName,
785
+ actorId: agentId,
786
+ targetId: parentAgentId || null,
787
+ detail: wasAborted ? "Trabajo interrumpido" : errorMessage,
788
+ });
530
789
 
531
790
  return {
532
791
  ok: false,
533
- worker_id: workerId,
534
- error: (err as Error).message,
792
+ worker_id: agentId,
793
+ error: errorMessage,
535
794
  };
795
+ } finally {
796
+ emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: syncDelegationRef });
797
+ emitDelegationFinished({ workerId: agentId, taskRef: syncDelegationRef });
798
+ await prepared.release();
536
799
  }
537
800
  },
538
801
  };
539
802
 
540
- // ─── task_delegate_code ──────────────────────────────────────────────────────
803
+ // ─── task_list ──────────────────────────────────────────────────────────────
541
804
 
542
- export const taskDelegateCodeTool: Tool = {
543
- name: "task_delegate_code",
544
- description: "Delegate a coding task to a CLI subagent (Qwen, Claude, etc.) via Code Bridge. Spanish: delegar código, subagente CLI, programación, Qwen",
805
+ export const taskListTool: Tool = {
806
+ name: "task_list",
807
+ description: "List real delegated task executions for the current user. TaskDoc and JobDoc are the source of truth. Use this instead of agent_find to determine whether work is pending, running, completed, failed, or blocked.",
545
808
  parameters: {
546
809
  type: "object",
547
810
  properties: {
548
- cli: { type: "string", enum: ["qwen", "claude", "opencode", "gemini"], description: "CLI tool to use" },
549
- task_instructions: { type: "string", description: "Coding task instructions" },
811
+ status: {
812
+ type: "string",
813
+ enum: ["pending", "running", "completed", "failed", "blocked", "all"],
814
+ description: "Execution-state filter (default: all)",
815
+ },
816
+ worker_id: { type: "string", description: "Optional worker agent ID" },
817
+ limit: { type: "number", description: "Maximum tasks to return (default 20, maximum 100)" },
550
818
  },
551
- required: ["cli", "task_instructions"],
552
819
  },
553
- execute: async (params: Record<string, unknown>) => {
554
- const cli = params.cli as string;
555
- const taskInstructions = params.task_instructions as string;
820
+ execute: async (params: Record<string, unknown>, config?: any) => {
821
+ const userId = config?.configurable?.user_id as string | undefined;
822
+ if (!userId) return { ok: false, error: "Missing user context for task_list." };
823
+
824
+ const status = (params.status as string | undefined) ?? "all";
825
+ const workerId = params.worker_id as string | undefined;
826
+ const limit = Math.max(1, Math.min(100, Number(params.limit) || 20));
556
827
 
557
- return {
558
- ok: false,
559
- error: `Code Bridge not implemented yet. CLI "${cli}" delegation is a stub. The task was not executed: "${taskInstructions.substring(0, 100)}..."`,
560
- };
828
+ try {
829
+ const tasksCol = await col<TaskDoc>("tasks");
830
+ const runsCol = await col<import("../../storage/collections.ts").AgentRunDoc>("agentRuns");
831
+ const { getJob } = await import("../../gateway/job-store.ts");
832
+ const allTasks = (await tasksCol.scan({}))
833
+ .map((entry) => entry.doc)
834
+ .sort((a, b) => b.updated_at - a.updated_at);
835
+
836
+ const result: Array<Record<string, unknown>> = [];
837
+ for (const task of allTasks) {
838
+ if (result.length >= limit) break;
839
+ if (workerId && fromIndexable(task.agent_id) !== workerId) continue;
840
+
841
+ const run = task.run_id ? await runsCol.get(task.run_id) : null;
842
+ if (!run || run.doc.user_id !== userId) continue;
843
+
844
+ const job = task.job_id ? await getJob(task.job_id) : null;
845
+ const executionState =
846
+ task.status === "pending"
847
+ ? "pending"
848
+ : task.status === "in_progress"
849
+ ? "running"
850
+ : task.status;
851
+ if (status !== "all" && executionState !== status) continue;
852
+
853
+ result.push({
854
+ id: task.id,
855
+ name: task.name,
856
+ description: task.description,
857
+ worker_id: fromIndexable(task.agent_id),
858
+ status: task.status,
859
+ execution_state: executionState,
860
+ progress: task.progress,
861
+ result: task.result,
862
+ error: task.error,
863
+ job_id: task.job_id,
864
+ job_status: job?.status ?? null,
865
+ run_id: task.run_id,
866
+ run_status: run.doc.status,
867
+ attempts: task.attempts ?? 0,
868
+ created_at: task.created_at,
869
+ started_at: task.started_at,
870
+ updated_at: task.updated_at,
871
+ completed_at: task.completed_at,
872
+ });
873
+ }
874
+
875
+ return { ok: true, task_count: result.length, tasks: result };
876
+ } catch (error) {
877
+ return { ok: false, error: `Failed to list delegated tasks: ${(error as Error).message}` };
878
+ }
561
879
  },
562
880
  };
563
881
 
@@ -726,7 +1044,7 @@ export function createTools(): Tool[] {
726
1044
  agentFindTool,
727
1045
  agentArchiveTool,
728
1046
  taskDelegateTool,
729
- taskDelegateCodeTool,
1047
+ taskListTool,
730
1048
  taskStatusTool,
731
1049
  busPublishTool,
732
1050
  busReadTool,