@johpaz/hive-agents 0.0.47 → 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 (297) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -902
  3. package/dist/hive.js +68840 -68355
  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 +196 -34
  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/index.ts +392 -83
  183. package/packages/core/src/tools/core/index.ts +28 -10
  184. package/packages/core/src/tools/cron/index.ts +1 -6
  185. package/packages/core/src/tools/index.ts +17 -45
  186. package/packages/core/src/tools/types.ts +1 -1
  187. package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
  188. package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
  189. package/packages/core/src/tools/web/index.ts +3 -0
  190. package/packages/core/src/utils/logger.ts +58 -30
  191. package/packages/core/src/utils/toon.ts +0 -20
  192. package/packages/mcp/src/manager.ts +8 -7
  193. package/packages/mcp/src/transports/sse.ts +0 -4
  194. package/packages/mcp/src/transports/websocket.ts +0 -6
  195. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_dashboard/SKILL.md +4 -4
  196. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_form/SKILL.md +4 -4
  197. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_interactive/SKILL.md +5 -5
  198. package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +26 -0
  199. package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +24 -18
  200. package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +47 -148
  201. package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +9 -10
  202. package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +1 -1
  203. package/packages/skills/src/bundled/cli/software_engineering/SKILL.md +23 -0
  204. package/packages/skills/src/bundled/cron_manager/SKILL.md +2 -2
  205. package/packages/skills/src/bundled/cron_reminder/SKILL.md +7 -7
  206. package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +11 -10
  207. package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +29 -35
  208. package/packages/skills/src/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
  209. package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +5 -4
  210. package/packages/skills/src/bundled-data.generated.ts +690 -1255
  211. package/dist/ui/assets/AgentCreateForm-DzaIT-dA.js +0 -1
  212. package/dist/ui/assets/AgentDetailPage-DgqcJceY.js +0 -1
  213. package/dist/ui/assets/AgentNewPage-CNSpoOSA.js +0 -1
  214. package/dist/ui/assets/AgentsPage-BMUJzTD6.js +0 -10
  215. package/dist/ui/assets/ApiClientPage-Cum_a_3j.js +0 -3
  216. package/dist/ui/assets/CanvasPage-o6oCP6uq.js +0 -33
  217. package/dist/ui/assets/ChannelsPage-WrB0zwLq.js +0 -8
  218. package/dist/ui/assets/DashboardPage-BCd6kNw0.js +0 -6
  219. package/dist/ui/assets/MeetingPage-BULIAWzq.js +0 -1
  220. package/dist/ui/assets/ModelSelector-BMYOChYb.js +0 -1
  221. package/dist/ui/assets/ProvidersPage-BVN5UZrI.js +0 -1
  222. package/dist/ui/assets/SettingsPage-CYmpFfDn.js +0 -9
  223. package/dist/ui/assets/SetupPage-Dnmb1Lbv.js +0 -1
  224. package/dist/ui/assets/WebChatPage-DmmdFhIC.js +0 -16
  225. package/dist/ui/assets/accordion-CnLzKNHK.js +0 -1
  226. package/dist/ui/assets/alert-B9J6KHmt.js +0 -1
  227. package/dist/ui/assets/alert-dialog-KcYQWcJ6.js +0 -1
  228. package/dist/ui/assets/arrow-left-CBcbX5EZ.js +0 -1
  229. package/dist/ui/assets/badge-88dRb4M8.js +0 -1
  230. package/dist/ui/assets/bell-8BqRYmzf.js +0 -1
  231. package/dist/ui/assets/chevron-down-DIosfU_U.js +0 -1
  232. package/dist/ui/assets/chevron-left-D4U-5A27.js +0 -1
  233. package/dist/ui/assets/chevron-right-CR4Skrf3.js +0 -1
  234. package/dist/ui/assets/chevron-up-CI-W21Fy.js +0 -1
  235. package/dist/ui/assets/circle-check-6Ard1-2z.js +0 -1
  236. package/dist/ui/assets/dropdown-menu-DDiaHg5y.js +0 -1
  237. package/dist/ui/assets/es-4I-joeZz.js +0 -1
  238. package/dist/ui/assets/folder-open-DJBLDFjv.js +0 -1
  239. package/dist/ui/assets/format-DsLPBxvt.js +0 -1
  240. package/dist/ui/assets/gauge-B8Tj43rC.js +0 -1
  241. package/dist/ui/assets/hexagon-6L79pgVK.js +0 -1
  242. package/dist/ui/assets/index-BmwTAwOF.css +0 -2
  243. package/dist/ui/assets/index-Cyw7L0Li.js +0 -116
  244. package/dist/ui/assets/key-DyKOoQh5.js +0 -1
  245. package/dist/ui/assets/label-B_15zZlR.js +0 -1
  246. package/dist/ui/assets/loader-circle-BmBOgYze.js +0 -1
  247. package/dist/ui/assets/lock-BS6OLXPv.js +0 -1
  248. package/dist/ui/assets/play-zJpWuhrr.js +0 -1
  249. package/dist/ui/assets/plus-BZQX26Dr.js +0 -1
  250. package/dist/ui/assets/progress-D5c-Eilm.js +0 -1
  251. package/dist/ui/assets/scroll-area-CihOx0cb.js +0 -1
  252. package/dist/ui/assets/search-DzDptO9s.js +0 -1
  253. package/dist/ui/assets/select-BQCOjM2j.js +0 -1
  254. package/dist/ui/assets/slider-bcUiUfx0.js +0 -14
  255. package/dist/ui/assets/switch-BR30E4ej.js +0 -1
  256. package/dist/ui/assets/table-B3aGEaVp.js +0 -1
  257. package/dist/ui/assets/tabs-LQidMKRS.js +0 -1
  258. package/dist/ui/assets/terminal--7G943As.js +0 -1
  259. package/dist/ui/assets/useProviders-C1xVKLxB.js +0 -1
  260. package/dist/ui/assets/utils-3pnRFmFe.js +0 -1
  261. package/dist/ui/assets/vendor-charts-Bu2lyBKP.js +0 -65
  262. package/dist/ui/assets/vendor-radix-D6rA7xKY.js +0 -63
  263. package/dist/ui/assets/vendor-react-BU5iQU4f.js +0 -1
  264. package/dist/ui/assets/volume-2-BekVQl6P.js +0 -1
  265. package/packages/core/src/agent/context-guard.ts +0 -91
  266. package/packages/core/src/agent/hooks.ts +0 -166
  267. package/packages/core/src/agent/providers.ts +0 -1
  268. package/packages/core/src/auth/auth.ts +0 -111
  269. package/packages/core/src/auth/index.ts +0 -1
  270. package/packages/core/src/canvas/canvas-tools.ts +0 -448
  271. package/packages/core/src/gateway/router.ts +0 -126
  272. package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
  273. package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
  274. package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
  275. package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
  276. package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
  277. package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
  278. package/packages/core/src/scheduler/dag/errors.ts +0 -37
  279. package/packages/core/src/scheduler/dag/index.ts +0 -26
  280. package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
  281. package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
  282. package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
  283. package/packages/core/src/scheduler/index.ts +0 -22
  284. package/packages/core/src/scheduler/task-driver.ts +0 -216
  285. package/packages/core/src/tools/canvas/index.ts +0 -420
  286. package/packages/core/src/tools/meeting/index.ts +0 -336
  287. package/packages/core/src/tools/projects/index.ts +0 -348
  288. package/packages/core/src/tools/voice/index.ts +0 -104
  289. package/packages/core/src/utils/index.ts +0 -5
  290. package/packages/skills/src/bundled/agents/code_delegator/SKILL.md +0 -156
  291. package/packages/skills/src/bundled/canvas/canvas_dashboard/SKILL.md +0 -146
  292. package/packages/skills/src/bundled/canvas/canvas_interact/SKILL.md +0 -148
  293. package/packages/skills/src/bundled/canvas/canvas_report/SKILL.md +0 -146
  294. package/packages/skills/src/bundled/meeting/meeting_transcription/SKILL.md +0 -213
  295. package/packages/skills/src/bundled/voice/voice_assistant/SKILL.md +0 -174
  296. package/packages/skills/src/bundled/voice/voice_input/SKILL.md +0 -146
  297. 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;
@@ -265,6 +280,42 @@ export const agentCreateTool: Tool = {
265
280
  };
266
281
  }
267
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
+
268
319
  try {
269
320
  const agentId = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
270
321
  const now = Date.now();
@@ -272,7 +323,7 @@ export const agentCreateTool: Tool = {
272
323
  const agentsCol = await col<AgentDoc>("agents");
273
324
  await agentsCol.put(agentId, {
274
325
  id: agentId,
275
- user_id: userId,
326
+ user_id: userId ?? "",
276
327
  name,
277
328
  description,
278
329
  system_prompt: systemPrompt,
@@ -284,12 +335,15 @@ export const agentCreateTool: Tool = {
284
335
  model_id: toIndexable(modelId),
285
336
  tools_json: toolsJson,
286
337
  skills_json: null,
338
+ active_mcp_json: null,
287
339
  parent_id: toIndexable(parentId),
288
340
  max_iterations: maxIterations,
289
341
  workspace: parentWorkspace,
290
342
  lastTraceAt: null,
291
343
  created_at: now,
292
344
  updated_at: now,
345
+ source: "user",
346
+ mcp_server_ids_json: mcpServerId ? JSON.stringify([mcpServerId]) : null,
293
347
  }, { expectedVersion: 0 });
294
348
 
295
349
  return {
@@ -298,6 +352,7 @@ export const agentCreateTool: Tool = {
298
352
  name,
299
353
  providerId,
300
354
  modelId,
355
+ mcpServerId: mcpServerId ?? null,
301
356
  workspace: parentWorkspace,
302
357
  message: "Agente creado exitosamente."
303
358
  };
@@ -311,46 +366,81 @@ export const agentCreateTool: Tool = {
311
366
 
312
367
  export const agentFindTool: Tool = {
313
368
  name: "agent_find",
314
- 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",
315
370
  parameters: {
316
371
  type: "object",
317
372
  properties: {
318
373
  search: { type: "string", description: "Search term for agent name or description" },
319
- 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." },
320
376
  },
321
377
  },
322
378
  execute: async (params: Record<string, unknown>, config?: any) => {
323
379
  const userId = config?.configurable?.user_id;
324
380
  const search = params.search as string | undefined;
325
- 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");
326
384
 
327
385
  try {
328
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
+ );
329
391
  let agents = (await agentsCol.scan({}))
330
392
  .map(e => e.doc)
331
- .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
+ );
332
397
 
333
398
  if (search) {
334
399
  const needle = search.toLowerCase();
335
- agents = agents.filter(a =>
336
- a.name.toLowerCase().includes(needle) || (a.description ?? "").toLowerCase().includes(needle)
337
- );
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
+ });
338
414
  }
339
415
 
340
- if (status && status !== "any") {
341
- agents = agents.filter(a => a.status === status);
416
+ if (availability !== "any") {
417
+ agents = agents.filter(a => availability === "enabled" ? a.enabled : !a.enabled);
342
418
  }
343
419
 
344
420
  return {
345
421
  ok: true,
346
422
  count: agents.length,
347
- agents: agents.map((a) => ({
348
- id: a.id,
349
- name: a.name,
350
- description: a.description,
351
- role: a.role,
352
- status: a.status,
353
- })),
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
+ }),
354
444
  };
355
445
  } catch (error) {
356
446
  return { ok: false, error: `Failed to find agents: ${(error as Error).message}` };
@@ -362,11 +452,11 @@ export const agentFindTool: Tool = {
362
452
 
363
453
  export const agentArchiveTool: Tool = {
364
454
  name: "agent_archive",
365
- 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",
366
456
  parameters: {
367
457
  type: "object",
368
458
  properties: {
369
- 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)" },
370
460
  },
371
461
  required: ["agentId"],
372
462
  },
@@ -381,7 +471,16 @@ export const agentArchiveTool: Tool = {
381
471
  return { ok: false, error: `Agent not found: ${agentId}` };
382
472
  }
383
473
 
384
- 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 });
385
484
 
386
485
  return { ok: true, agentId, message: "Agent archived." };
387
486
  } catch (error) {
@@ -394,38 +493,70 @@ export const agentArchiveTool: Tool = {
394
493
 
395
494
  export const taskDelegateTool: Tool = {
396
495
  name: "task_delegate",
397
- 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.",
398
497
  parameters: {
399
498
  type: "object",
400
499
  properties: {
401
- 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." },
402
501
  task_description: { type: "string", description: "Clear, detailed instructions for the worker" },
403
- 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." },
404
516
  },
405
- required: ["worker_id", "task_description"],
517
+ required: ["task_description"],
406
518
  },
407
519
  execute: async (params: Record<string, unknown>, config?: any) => {
408
- const workerId = params.worker_id as string;
520
+ const agentId = params.worker_id as string | undefined;
409
521
  const taskDescription = params.task_description as string;
410
522
  const mode = (params.mode as string) ?? "sync";
523
+ const turnId = config?.configurable?.turn_id as string | undefined;
411
524
 
412
- const agentsCol = await col<AgentDoc>("agents");
413
- const workerEntry = await agentsCol.get(workerId);
525
+ if (!agentId) return { ok: false, error: "Provide worker_id." };
414
526
 
415
- if (!workerEntry) {
416
- 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." };
417
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}` };
418
541
  const worker = workerEntry.doc;
419
- if (!worker.enabled) {
420
- return { ok: false, error: `Worker is disabled: ${worker.name}` };
421
- }
542
+ if (!worker.enabled) return { ok: false, error: `Agent is disabled: ${worker.name}` };
422
543
 
423
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 }]);
424
555
 
425
556
  // ── Async mode: create TaskDoc + enqueue worker_task in durable queue ──
426
557
  if (mode === "async") {
427
558
  try {
428
- const { nextId, toIndexable } = await import("../../storage/hive.ts");
559
+ const { nextId, toIndexable, updateDoc } = await import("../../storage/hive.ts");
429
560
  const { createRun } = await import("../../agent/run-store.ts");
430
561
  const { getDurableQueue } = await import("../../gateway/durable-queue.ts");
431
562
 
@@ -434,21 +565,19 @@ export const taskDelegateTool: Tool = {
434
565
  const tasksCol = await col<TaskDoc>("tasks");
435
566
  await tasksCol.put(taskId, {
436
567
  id: taskId,
437
- project_id: toIndexable(null),
438
- agent_id: toIndexable(workerId),
439
- parent_task_id: null,
568
+ agent_id: toIndexable(agentId),
440
569
  name: taskName,
441
570
  description: taskDescription,
442
571
  status: "pending",
443
572
  progress: 0,
444
- priority: 0,
445
- depends_on: null,
446
573
  result: null,
447
574
  error: null,
448
575
  metadata: null,
449
576
  job_id: null,
450
577
  run_id: null,
451
578
  thread_id: null,
579
+ delegation_group_id: turnId ?? null,
580
+ catalog_agent_id: toIndexable(worker.source === "catalog" ? agentId : null),
452
581
  started_at: null,
453
582
  attempts: 0,
454
583
  created_at: now,
@@ -456,14 +585,29 @@ export const taskDelegateTool: Tool = {
456
585
  completed_at: null,
457
586
  }, { expectedVersion: 0 });
458
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
+
459
601
  const run = await createRun({
460
- thread_id: `task-${taskId}-${workerId}`,
461
- agent_id: workerId,
602
+ thread_id: `task-${taskId}-${agentId}`,
603
+ agent_id: agentId,
462
604
  user_id: config?.configurable?.user_id ?? "",
463
605
  channel: config?.configurable?.channel ?? null,
464
606
  kind: "worker",
465
607
  max_iterations: worker.max_iterations || 10,
466
608
  resume_policy: "resume",
609
+ acceptance,
610
+ catalog_agent_id: worker.source === "catalog" ? agentId : undefined,
467
611
  });
468
612
 
469
613
  const queue = getDurableQueue();
@@ -472,101 +616,266 @@ export const taskDelegateTool: Tool = {
472
616
  type: "worker_task",
473
617
  run_id: run.id,
474
618
  payload: {
475
- workerId,
619
+ workerId: agentId,
476
620
  taskDescription,
477
621
  taskName,
478
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,
479
635
  },
480
636
  });
481
637
 
482
- await import("../../storage/hive.ts").then(({ updateDoc }) =>
483
- updateDoc<TaskDoc>("tasks", taskId, {
484
- job_id: job.id,
485
- run_id: run.id,
486
- thread_id: `task-${taskId}-${workerId}`,
487
- updated_at: Date.now(),
488
- } as Partial<TaskDoc>)
489
- );
490
-
491
- 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
+ }
492
662
 
493
663
  return {
494
664
  ok: true,
495
665
  task_id: taskId,
496
666
  job_id: job.id,
497
667
  run_id: run.id,
498
- worker_id: workerId,
668
+ worker_id: agentId,
499
669
  worker_name: worker.name,
500
670
  status: "queued",
501
- 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.`,
502
672
  };
503
673
  } catch (err) {
504
674
  return { ok: false, error: `Async delegation failed: ${(err as Error).message}` };
505
675
  }
506
676
  }
507
677
 
508
- // ── Sync mode: blocking execution with 2min timeout (existing behavior) ──
509
- 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();
510
682
 
511
- log.info(`[task_delegate] Delegating (sync) to ${worker.name} (${workerId})`);
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
+ }
694
+
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 });
512
699
 
513
700
  try {
514
- const { runAgentIsolated } = await import("../../agent/agent-loop.ts");
701
+ const { runAgentIsolated, withTimeout } = await import("../../agent/agent-loop.ts");
515
702
 
516
- const threadId = `task-${Date.now()}-${workerId}`;
703
+ const threadId = `task-${Date.now()}-${agentId}`;
517
704
  const SYNC_TIMEOUT_MS = 2 * 60 * 1000;
518
705
 
519
- 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;
520
711
  const result = await withTimeout(
521
712
  () => runAgentIsolated({
522
- agentId: workerId,
713
+ agentId,
523
714
  taskDescription,
524
715
  threadId,
716
+ mcpManager,
717
+ signal,
525
718
  }),
526
719
  SYNC_TIMEOUT_MS,
527
720
  );
528
721
 
529
- agentBus.notifyTaskCompleted(workerId, worker.name, 0, taskName, "", result);
530
-
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
+ });
531
770
  return {
532
771
  ok: true,
533
- worker_id: workerId,
772
+ worker_id: agentId,
534
773
  worker_name: worker.name,
774
+ verification_id: verification.id,
535
775
  result,
536
776
  };
537
777
  } catch (err) {
538
- 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
+ });
539
789
 
540
790
  return {
541
791
  ok: false,
542
- worker_id: workerId,
543
- error: (err as Error).message,
792
+ worker_id: agentId,
793
+ error: errorMessage,
544
794
  };
795
+ } finally {
796
+ emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: syncDelegationRef });
797
+ emitDelegationFinished({ workerId: agentId, taskRef: syncDelegationRef });
798
+ await prepared.release();
545
799
  }
546
800
  },
547
801
  };
548
802
 
549
- // ─── task_delegate_code ──────────────────────────────────────────────────────
803
+ // ─── task_list ──────────────────────────────────────────────────────────────
550
804
 
551
- export const taskDelegateCodeTool: Tool = {
552
- name: "task_delegate_code",
553
- 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.",
554
808
  parameters: {
555
809
  type: "object",
556
810
  properties: {
557
- cli: { type: "string", enum: ["qwen", "claude", "opencode", "gemini"], description: "CLI tool to use" },
558
- 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)" },
559
818
  },
560
- required: ["cli", "task_instructions"],
561
819
  },
562
- execute: async (params: Record<string, unknown>) => {
563
- const cli = params.cli as string;
564
- 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));
827
+
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
+ }
565
874
 
566
- return {
567
- ok: false,
568
- error: `Code Bridge not implemented yet. CLI "${cli}" delegation is a stub. The task was not executed: "${taskInstructions.substring(0, 100)}..."`,
569
- };
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
+ }
570
879
  },
571
880
  };
572
881
 
@@ -735,7 +1044,7 @@ export function createTools(): Tool[] {
735
1044
  agentFindTool,
736
1045
  agentArchiveTool,
737
1046
  taskDelegateTool,
738
- taskDelegateCodeTool,
1047
+ taskListTool,
739
1048
  taskStatusTool,
740
1049
  busPublishTool,
741
1050
  busReadTool,