@johpaz/hive-agents 0.0.47 → 1.0.1

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 (322) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -897
  3. package/dist/hive.js +222237 -206295
  4. package/dist/tool-worker.js +226 -927
  5. package/dist/ui/assets/A2UIPage-D4nzp5NV.js +8 -0
  6. package/dist/ui/assets/AgentCreateForm-M2RhjeA1.js +1 -0
  7. package/dist/ui/assets/AgentDetailPage-DkFRtj8g.js +1 -0
  8. package/dist/ui/assets/AgentNewPage-CfBU7puz.js +1 -0
  9. package/dist/ui/assets/AgentsPage-Ctzq2LWx.js +10 -0
  10. package/dist/ui/assets/ApiClientPage-DKbGO1QW.js +3 -0
  11. package/dist/ui/assets/ChannelsPage-H6rgr8DQ.js +8 -0
  12. package/dist/ui/assets/DashboardPage-BIjYGf4m.js +6 -0
  13. package/dist/ui/assets/{LoginPage-BTxJdFVG.js → LoginPage-DazoxtBJ.js} +1 -1
  14. package/dist/ui/assets/{LogsPage-DVV2eHbh.js → LogsPage-DMZ6KtQ3.js} +1 -1
  15. package/dist/ui/assets/MeetingPage-CSLFvHL7.js +1 -0
  16. package/dist/ui/assets/ModelSelector-BCfvugHB.js +1 -0
  17. package/dist/ui/assets/{NotFound-BIUDlIXU.js → NotFound-Bpr12V51.js} +1 -1
  18. package/dist/ui/assets/Office3DPage-BE6Epe0d.js +4614 -0
  19. package/dist/ui/assets/Office3DPage-C3SIzd2H.css +1 -0
  20. package/dist/ui/assets/ProvidersPage-D0cApfM1.js +1 -0
  21. package/dist/ui/assets/{RecoverPage-7YDQysBL.js → RecoverPage-BVUPHG9z.js} +1 -1
  22. package/dist/ui/assets/SettingsPage-DCZ4nql4.js +9 -0
  23. package/dist/ui/assets/SetupPage-In19p30M.js +1 -0
  24. package/dist/ui/assets/WebChatPage-ByVBSzxL.js +29 -0
  25. package/dist/ui/assets/{activity-c3pNngT_.js → activity-BIIli7ET.js} +1 -1
  26. package/dist/ui/assets/agentCapabilities-D1PD9yFH.js +1 -0
  27. package/dist/ui/assets/alert-CQlRq6sv.js +1 -0
  28. package/dist/ui/assets/arrow-left-BfcnX8Er.js +1 -0
  29. package/dist/ui/assets/arrow-right-Q-dzAn8k.js +1 -0
  30. package/dist/ui/assets/arrow-up-right-Bf-8wrUQ.js +1 -0
  31. package/dist/ui/assets/badge-DKGZbVZJ.js +1 -0
  32. package/dist/ui/assets/{calendar-B-KZ9RQO.js → calendar-S9-_Q6QR.js} +1 -1
  33. package/dist/ui/assets/{card-CNf6BS2e.js → card-D3Nw3kh3.js} +1 -1
  34. package/dist/ui/assets/check-CryV78SQ.js +1 -0
  35. package/dist/ui/assets/chevron-down-QCtMs-Af.js +1 -0
  36. package/dist/ui/assets/chevron-left-dTGbyl5G.js +1 -0
  37. package/dist/ui/assets/chevron-right-D0GjXbnO.js +1 -0
  38. package/dist/ui/assets/chevron-up-Cg0jO8uT.js +1 -0
  39. package/dist/ui/assets/{circle-alert-KuAm2FWh.js → circle-alert-DTVW4R94.js} +1 -1
  40. package/dist/ui/assets/circle-check-BAolxswA.js +1 -0
  41. package/dist/ui/assets/{circle-x-DjLkFDO8.js → circle-x-CJXbXzRh.js} +1 -1
  42. package/dist/ui/assets/{copy-Bu5d7C-0.js → copy-X_TPpA-A.js} +1 -1
  43. package/dist/ui/assets/{dialog-Jk4bieO4.js → dialog-uUBz_NIB.js} +1 -1
  44. package/dist/ui/assets/dist-CD_qfA30.js +1 -0
  45. package/dist/ui/assets/{download-Cjbk4Rek.js → download-C-fXu08w.js} +1 -1
  46. package/dist/ui/assets/earth-CTsVjCmp.js +1 -0
  47. package/dist/ui/assets/ellipsis-vertical-5zBh5yzc.js +1 -0
  48. package/dist/ui/assets/{external-link-6sTlRDUR.js → external-link-CvpRhwC_.js} +1 -1
  49. package/dist/ui/assets/{eye-Df8o0tkC.js → eye-CM-HQEWU.js} +1 -1
  50. package/dist/ui/assets/{file-text-lnxnjBp0.js → file-text-lwkvYGtA.js} +1 -1
  51. package/dist/ui/assets/{gateway-url-DwzPmoc8.js → gateway-url-BlnabM5e.js} +1 -1
  52. package/dist/ui/assets/gauge-CB-cas-h.js +1 -0
  53. package/dist/ui/assets/{history-CAF_R34_.js → history-eSHspWRr.js} +1 -1
  54. package/dist/ui/assets/index-D489S18g.css +2 -0
  55. package/dist/ui/assets/index-ZjAc-KQS.js +116 -0
  56. package/dist/ui/assets/{info-WjromB4Y.js → info-DTgFQ_jA.js} +1 -1
  57. package/dist/ui/assets/key-CeM9JJkq.js +1 -0
  58. package/dist/ui/assets/label-k0jYxoWW.js +1 -0
  59. package/dist/ui/assets/loader-circle-Dtfz4FWw.js +1 -0
  60. package/dist/ui/assets/lock-open-B089GUAJ.js +1 -0
  61. package/dist/ui/assets/mail--gNFIe4M.js +1 -0
  62. package/dist/ui/assets/{pause-VqeUmp2Z.js → pause-DjT1nwQM.js} +1 -1
  63. package/dist/ui/assets/pencil-6PRgdjiU.js +1 -0
  64. package/dist/ui/assets/play-tOrP0xUJ.js +1 -0
  65. package/dist/ui/assets/plus-Cnom3j47.js +1 -0
  66. package/dist/ui/assets/progress-DrI2UDu-.js +1 -0
  67. package/dist/ui/assets/radio-D-joO9J0.js +1 -0
  68. package/dist/ui/assets/{refresh-cw-CCzDCAuz.js → refresh-cw-BRrzoHQW.js} +1 -1
  69. package/dist/ui/assets/scroll-area-CfHn94Vb.js +1 -0
  70. package/dist/ui/assets/search-D277MUP0.js +1 -0
  71. package/dist/ui/assets/select-BOR8MsSL.js +1 -0
  72. package/dist/ui/assets/{send-BPk9XbIq.js → send-DIlj81PT.js} +1 -1
  73. package/dist/ui/assets/{settings-BGfrZ_zM.js → settings-CkBjgAEm.js} +1 -1
  74. package/dist/ui/assets/{shield-CxhcUT39.js → shield-U0hIjGzm.js} +1 -1
  75. package/dist/ui/assets/slider-CmE_z1Ii.js +1 -0
  76. package/dist/ui/assets/{sparkles-BhwlS1pc.js → sparkles-VXHGDbNh.js} +1 -1
  77. package/dist/ui/assets/{square-DMNWw4Hi.js → square-OHeetvN3.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-C6YPcJl_.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-DQxm7DUM.js} +1 -1
  83. package/dist/ui/assets/{triangle-alert-pVIJGjga.js → triangle-alert-Dj8ZhmWj.js} +1 -1
  84. package/dist/ui/assets/{useHiveAgentsModelLoad-BnC4jLE-.js → useHiveAgentsModelLoad-COLvs-Ho.js} +1 -1
  85. package/dist/ui/assets/useOfficeModel-Cy7cAyEn.js +1 -0
  86. package/dist/ui/assets/useProviders-q6iROeWE.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-Bm735CXN.js +1 -0
  94. package/dist/ui/assets/wifi-DklBfOZ6.js +1 -0
  95. package/dist/ui/assets/{zap-B4RaNNO5.js → zap-BEZNJ0i0.js} +1 -1
  96. package/dist/ui/index.html +16 -13
  97. package/dist/ui/logoblack.png +0 -0
  98. package/dist/ui/logocolor-dark.png +0 -0
  99. package/dist/ui/logocolorbg.png +0 -0
  100. package/dist/ui/logodoradobg.png +0 -0
  101. package/package.json +18 -15
  102. package/packages/cli/src/adapters/config.ts +1 -80
  103. package/packages/cli/src/adapters/factory.ts +0 -45
  104. package/packages/cli/src/adapters/index.ts +0 -8
  105. package/packages/cli/src/commands/doctor.ts +156 -1
  106. package/packages/cli/src/commands/gateway.ts +2 -9
  107. package/packages/cli/src/commands/onboard.ts +126 -59
  108. package/packages/cli/src/index.ts +9 -11
  109. package/packages/cli/src/ui-bundle.generated.ts +9 -92
  110. package/packages/core/src/agent/acceptance-checks.ts +172 -0
  111. package/packages/core/src/agent/agent-catalog.ts +348 -0
  112. package/packages/core/src/agent/agent-loop.ts +204 -28
  113. package/packages/core/src/agent/capability-search.ts +5 -5
  114. package/packages/core/src/agent/catalog-selector.ts +103 -0
  115. package/packages/core/src/agent/compaction.ts +52 -42
  116. package/packages/core/src/agent/context-compiler.ts +185 -63
  117. package/packages/core/src/agent/conversation-store.ts +56 -3
  118. package/packages/core/src/agent/curator.ts +129 -34
  119. package/packages/core/src/agent/delegation-runtime.ts +241 -0
  120. package/packages/core/src/agent/goal-runner.ts +111 -32
  121. package/packages/core/src/agent/index.ts +17 -0
  122. package/packages/core/src/agent/llm-client.ts +34 -2
  123. package/packages/core/src/agent/llm-providers/anthropic.ts +10 -7
  124. package/packages/core/src/agent/llm-providers/hiveagents.ts +1 -1
  125. package/packages/core/src/agent/llm-providers/interface.ts +16 -5
  126. package/packages/core/src/agent/llm-providers/modelscope.ts +5 -0
  127. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
  128. package/packages/core/src/agent/llm-providers/z-ai.ts +5 -0
  129. package/packages/core/src/agent/minimal-loadout.ts +47 -0
  130. package/packages/core/src/agent/playbook-selector.ts +1 -1
  131. package/packages/core/src/agent/prompt-builder.ts +4 -0
  132. package/packages/core/src/agent/proof-packet.ts +6 -1
  133. package/packages/core/src/agent/providers/index.ts +9 -4
  134. package/packages/core/src/agent/routing-intent.ts +22 -0
  135. package/packages/core/src/agent/run-store.ts +24 -3
  136. package/packages/core/src/agent/service.ts +2 -2
  137. package/packages/core/src/agent/skill-selector.ts +12 -31
  138. package/packages/core/src/agent/tool-selector.ts +61 -36
  139. package/packages/core/src/agent/tracer.ts +5 -1
  140. package/packages/core/src/artifacts/store.ts +162 -0
  141. package/packages/core/src/canvas/canvas-manager.ts +5 -234
  142. package/packages/core/src/canvas/emitter.ts +121 -69
  143. package/packages/core/src/canvas/index.ts +0 -2
  144. package/packages/core/src/channels/base.ts +3 -1
  145. package/packages/core/src/channels/manager.ts +117 -25
  146. package/packages/core/src/channels/webchat.ts +4 -8
  147. package/packages/core/src/channels/whatsapp.ts +6 -1
  148. package/packages/core/src/config/loader.ts +13 -23
  149. package/packages/core/src/events/agent-bus.ts +0 -31
  150. package/packages/core/src/events/channel-narration.ts +150 -0
  151. package/packages/core/src/events/narration.ts +82 -0
  152. package/packages/core/src/events/tool-narration.ts +62 -0
  153. package/packages/core/src/gateway/channel-notify.ts +43 -10
  154. package/packages/core/src/gateway/delegation-groups.ts +258 -0
  155. package/packages/core/src/gateway/delegation-notify.ts +103 -0
  156. package/packages/core/src/gateway/durable-queue.ts +33 -2
  157. package/packages/core/src/gateway/helpers/index.ts +2 -2
  158. package/packages/core/src/gateway/helpers/narration.ts +4 -57
  159. package/packages/core/src/gateway/helpers/redact.ts +1 -1
  160. package/packages/core/src/gateway/helpers/ui-source.ts +67 -0
  161. package/packages/core/src/gateway/initializer.ts +15 -13
  162. package/packages/core/src/gateway/job-executors.ts +197 -104
  163. package/packages/core/src/gateway/lane-queue.ts +1 -1
  164. package/packages/core/src/gateway/notification-inbox.ts +57 -0
  165. package/packages/core/src/gateway/resolver.ts +11 -25
  166. package/packages/core/src/gateway/routes/agents.ts +91 -1
  167. package/packages/core/src/gateway/routes/auth.ts +21 -42
  168. package/packages/core/src/gateway/routes/channels.ts +15 -1
  169. package/packages/core/src/gateway/routes/chat.ts +6 -6
  170. package/packages/core/src/gateway/routes/cron-api.ts +0 -4
  171. package/packages/core/src/gateway/routes/mcp.ts +0 -63
  172. package/packages/core/src/gateway/routes/meeting.ts +245 -0
  173. package/packages/core/src/gateway/routes/models.ts +69 -12
  174. package/packages/core/src/gateway/routes/providers.ts +111 -28
  175. package/packages/core/src/gateway/routes/setup.ts +92 -35
  176. package/packages/core/src/gateway/routes/skills.ts +2 -2
  177. package/packages/core/src/gateway/routes/system.ts +31 -10
  178. package/packages/core/src/gateway/routes/users.ts +24 -1
  179. package/packages/core/src/gateway/routes/voice.ts +3 -0
  180. package/packages/core/src/gateway/server.ts +207 -141
  181. package/packages/core/src/gateway/session.ts +6 -4
  182. package/packages/core/src/gateway/slash-commands.ts +7 -6
  183. package/packages/core/src/gateway/webchat-turn.ts +63 -13
  184. package/packages/core/src/index.ts +3 -0
  185. package/packages/core/src/mcp/hot-reload.ts +14 -7
  186. package/packages/core/src/mcp/singleton.ts +0 -3
  187. package/packages/core/src/mcp/tool-sync.ts +2 -2
  188. package/packages/core/src/resilience/retry.ts +1 -1
  189. package/packages/core/src/scheduler/CronScheduler.ts +3 -1
  190. package/packages/core/src/scheduler/integration.ts +1 -1
  191. package/packages/core/src/storage/bootstrap.ts +34 -10
  192. package/packages/core/src/storage/collections.ts +167 -27
  193. package/packages/core/src/storage/crypto.ts +147 -58
  194. package/packages/core/src/storage/hivedb.ts +9 -0
  195. package/packages/core/src/storage/model-id.ts +53 -0
  196. package/packages/core/src/storage/onboarding.ts +160 -34
  197. package/packages/core/src/storage/reconcile.ts +2 -5
  198. package/packages/core/src/storage/seed.ts +436 -158
  199. package/packages/core/src/storage/usage.ts +61 -132
  200. package/packages/core/src/storage/user-email.ts +11 -0
  201. package/packages/core/src/tool-runtime/index.ts +69 -23
  202. package/packages/core/src/tool-runtime/worker-tools.ts +4 -2
  203. package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
  204. package/packages/core/src/tools/agents/index.ts +566 -85
  205. package/packages/core/src/tools/core/index.ts +28 -10
  206. package/packages/core/src/tools/cron/index.ts +1 -6
  207. package/packages/core/src/tools/index.ts +19 -46
  208. package/packages/core/src/tools/types.ts +1 -1
  209. package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
  210. package/packages/core/src/tools/web/browser-backend.ts +129 -0
  211. package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
  212. package/packages/core/src/tools/web/browser-service.ts +75 -35
  213. package/packages/core/src/tools/web/index.ts +3 -0
  214. package/packages/core/src/tools/web/webview-backend.ts +412 -0
  215. package/packages/core/src/utils/logger.ts +58 -30
  216. package/packages/core/src/utils/toon.ts +0 -20
  217. package/packages/core/src/voice/index.ts +108 -17
  218. package/packages/mcp/src/manager.ts +8 -7
  219. package/packages/mcp/src/transports/sse.ts +0 -4
  220. package/packages/mcp/src/transports/websocket.ts +0 -6
  221. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_dashboard/SKILL.md +4 -4
  222. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_form/SKILL.md +4 -4
  223. package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_interactive/SKILL.md +5 -5
  224. package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +24 -18
  225. package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +48 -148
  226. package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +9 -10
  227. package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +1 -1
  228. package/packages/skills/src/bundled/cli/software_engineering/SKILL.md +23 -0
  229. package/packages/skills/src/bundled/cron_manager/SKILL.md +2 -2
  230. package/packages/skills/src/bundled/cron_reminder/SKILL.md +7 -7
  231. package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +11 -10
  232. package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +29 -35
  233. package/packages/skills/src/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
  234. package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +5 -4
  235. package/packages/skills/src/bundled-data.generated.ts +640 -1226
  236. package/dist/ui/assets/AgentCreateForm-DzaIT-dA.js +0 -1
  237. package/dist/ui/assets/AgentDetailPage-DgqcJceY.js +0 -1
  238. package/dist/ui/assets/AgentNewPage-CNSpoOSA.js +0 -1
  239. package/dist/ui/assets/AgentsPage-BMUJzTD6.js +0 -10
  240. package/dist/ui/assets/ApiClientPage-Cum_a_3j.js +0 -3
  241. package/dist/ui/assets/CanvasPage-o6oCP6uq.js +0 -33
  242. package/dist/ui/assets/ChannelsPage-WrB0zwLq.js +0 -8
  243. package/dist/ui/assets/DashboardPage-BCd6kNw0.js +0 -6
  244. package/dist/ui/assets/MeetingPage-BULIAWzq.js +0 -1
  245. package/dist/ui/assets/ModelSelector-BMYOChYb.js +0 -1
  246. package/dist/ui/assets/ProvidersPage-BVN5UZrI.js +0 -1
  247. package/dist/ui/assets/SettingsPage-CYmpFfDn.js +0 -9
  248. package/dist/ui/assets/SetupPage-Dnmb1Lbv.js +0 -1
  249. package/dist/ui/assets/WebChatPage-DmmdFhIC.js +0 -16
  250. package/dist/ui/assets/accordion-CnLzKNHK.js +0 -1
  251. package/dist/ui/assets/alert-B9J6KHmt.js +0 -1
  252. package/dist/ui/assets/alert-dialog-KcYQWcJ6.js +0 -1
  253. package/dist/ui/assets/arrow-left-CBcbX5EZ.js +0 -1
  254. package/dist/ui/assets/badge-88dRb4M8.js +0 -1
  255. package/dist/ui/assets/bell-8BqRYmzf.js +0 -1
  256. package/dist/ui/assets/chevron-down-DIosfU_U.js +0 -1
  257. package/dist/ui/assets/chevron-left-D4U-5A27.js +0 -1
  258. package/dist/ui/assets/chevron-right-CR4Skrf3.js +0 -1
  259. package/dist/ui/assets/chevron-up-CI-W21Fy.js +0 -1
  260. package/dist/ui/assets/circle-check-6Ard1-2z.js +0 -1
  261. package/dist/ui/assets/dropdown-menu-DDiaHg5y.js +0 -1
  262. package/dist/ui/assets/es-4I-joeZz.js +0 -1
  263. package/dist/ui/assets/folder-open-DJBLDFjv.js +0 -1
  264. package/dist/ui/assets/format-DsLPBxvt.js +0 -1
  265. package/dist/ui/assets/gauge-B8Tj43rC.js +0 -1
  266. package/dist/ui/assets/hexagon-6L79pgVK.js +0 -1
  267. package/dist/ui/assets/index-BmwTAwOF.css +0 -2
  268. package/dist/ui/assets/index-Cyw7L0Li.js +0 -116
  269. package/dist/ui/assets/key-DyKOoQh5.js +0 -1
  270. package/dist/ui/assets/label-B_15zZlR.js +0 -1
  271. package/dist/ui/assets/loader-circle-BmBOgYze.js +0 -1
  272. package/dist/ui/assets/lock-BS6OLXPv.js +0 -1
  273. package/dist/ui/assets/play-zJpWuhrr.js +0 -1
  274. package/dist/ui/assets/plus-BZQX26Dr.js +0 -1
  275. package/dist/ui/assets/progress-D5c-Eilm.js +0 -1
  276. package/dist/ui/assets/scroll-area-CihOx0cb.js +0 -1
  277. package/dist/ui/assets/search-DzDptO9s.js +0 -1
  278. package/dist/ui/assets/select-BQCOjM2j.js +0 -1
  279. package/dist/ui/assets/slider-bcUiUfx0.js +0 -14
  280. package/dist/ui/assets/switch-BR30E4ej.js +0 -1
  281. package/dist/ui/assets/table-B3aGEaVp.js +0 -1
  282. package/dist/ui/assets/tabs-LQidMKRS.js +0 -1
  283. package/dist/ui/assets/terminal--7G943As.js +0 -1
  284. package/dist/ui/assets/useProviders-C1xVKLxB.js +0 -1
  285. package/dist/ui/assets/utils-3pnRFmFe.js +0 -1
  286. package/dist/ui/assets/vendor-charts-Bu2lyBKP.js +0 -65
  287. package/dist/ui/assets/vendor-radix-D6rA7xKY.js +0 -63
  288. package/dist/ui/assets/vendor-react-BU5iQU4f.js +0 -1
  289. package/dist/ui/assets/volume-2-BekVQl6P.js +0 -1
  290. package/packages/core/src/agent/context-guard.ts +0 -91
  291. package/packages/core/src/agent/hooks.ts +0 -166
  292. package/packages/core/src/agent/providers.ts +0 -1
  293. package/packages/core/src/auth/auth.ts +0 -111
  294. package/packages/core/src/auth/index.ts +0 -1
  295. package/packages/core/src/canvas/canvas-tools.ts +0 -448
  296. package/packages/core/src/gateway/router.ts +0 -126
  297. package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
  298. package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
  299. package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
  300. package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
  301. package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
  302. package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
  303. package/packages/core/src/scheduler/dag/errors.ts +0 -37
  304. package/packages/core/src/scheduler/dag/index.ts +0 -26
  305. package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
  306. package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
  307. package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
  308. package/packages/core/src/scheduler/index.ts +0 -22
  309. package/packages/core/src/scheduler/task-driver.ts +0 -216
  310. package/packages/core/src/tools/canvas/index.ts +0 -420
  311. package/packages/core/src/tools/meeting/index.ts +0 -336
  312. package/packages/core/src/tools/projects/index.ts +0 -348
  313. package/packages/core/src/tools/voice/index.ts +0 -104
  314. package/packages/core/src/utils/index.ts +0 -5
  315. package/packages/skills/src/bundled/agents/code_delegator/SKILL.md +0 -156
  316. package/packages/skills/src/bundled/canvas/canvas_dashboard/SKILL.md +0 -146
  317. package/packages/skills/src/bundled/canvas/canvas_interact/SKILL.md +0 -148
  318. package/packages/skills/src/bundled/canvas/canvas_report/SKILL.md +0 -146
  319. package/packages/skills/src/bundled/meeting/meeting_transcription/SKILL.md +0 -213
  320. package/packages/skills/src/bundled/voice/voice_assistant/SKILL.md +0 -174
  321. package/packages/skills/src/bundled/voice/voice_input/SKILL.md +0 -146
  322. package/packages/skills/src/bundled/voice/voice_output/SKILL.md +0 -151
@@ -45,6 +45,22 @@ export interface ModelDoc {
45
45
  capabilities: string | null
46
46
  enabled: boolean
47
47
  active: boolean
48
+ /**
49
+ * "catalog" for rows that come from SEED_DATA, "discovered" for rows
50
+ * inserted at runtime by querying a provider (Ollama tags, /v1/models).
51
+ * The boot reseed only purges catalog rows — a discovered model has no
52
+ * canonical source to be re-created from, so wiping it would orphan every
53
+ * agent pointing at it. Legacy rows (undefined) are treated as discovered.
54
+ */
55
+ source?: "catalog" | "discovered"
56
+ /**
57
+ * Precio en USD por millón de tokens. Única fuente de verdad para el costo
58
+ * del dashboard: `calculateCost` (storage/usage.ts) lee de acá, no de una
59
+ * tabla aparte. `null` = precio desconocido (modelo agregado a mano o
60
+ * descubierto en runtime), que se reporta como $0 con un warning.
61
+ */
62
+ input_per_1m?: number | null
63
+ output_per_1m?: number | null
48
64
  }
49
65
 
50
66
  export interface AgentDoc {
@@ -63,6 +79,8 @@ export interface AgentDoc {
63
79
  model_id: string
64
80
  tools_json: string | null
65
81
  skills_json: string | null
82
+ /** MCP server ids currently leased for this execution. */
83
+ active_mcp_json?: string | null
66
84
  /** `toIndexable`-encoded — `NO_PARENT` for the coordinator. */
67
85
  parent_id: string
68
86
  max_iterations: number
@@ -71,6 +89,24 @@ export interface AgentDoc {
71
89
  lastTraceAt: number | null
72
90
  created_at: number
73
91
  updated_at: number
92
+
93
+ // ─── Catalog fields (only populated for source:"catalog" seeded agents) ────
94
+ /** "catalog" = seeded persona from agent-catalog.ts (insert-only, survives reseed). Absent/"user" for everything else (coordinator, agent_create workers). */
95
+ source?: "user" | "catalog"
96
+ /** BM25 routing metadata (capability-search.ts) — `description` itself is already routing-friendly (one line, suitable for small local models) and doubles as the catalog line shown to the coordinator. */
97
+ routing_examples_json?: string | null
98
+ routing_exclusions_json?: string | null
99
+ /** Glob patterns. When present, task_delegate re-expands against the live tool registry at delegation time instead of trusting a possibly-stale tools_json. */
100
+ tool_allowlist_json?: string | null
101
+ /** Persistent MCP server assignments. User specialists normally contain exactly one server id. */
102
+ mcp_server_ids_json?: string | null
103
+ workspace_scope_json?: string | null
104
+ model_override_json?: string | null
105
+ default_acceptance_json?: string | null
106
+ /** ACE learning counters — updated by deterministic acceptance checks and the coordinator's own accept/revise judgment (acceptance-checks.ts), not by loop completion. */
107
+ helpful_count?: number
108
+ harmful_count?: number
109
+ seed_version?: number
74
110
  }
75
111
 
76
112
  // ─── Stage 2: catalog ─────────────────────────────────────────────────────────
@@ -143,6 +179,26 @@ export interface ToolDoc {
143
179
  updated_at: number
144
180
  }
145
181
 
182
+ // Sub-types for AgentDoc's catalog fields (workspace_scope_json, model_override_json,
183
+ // default_acceptance_json) — kept as named types for readability even though they're
184
+ // stored as JSON strings on the shared agents table, not a separate collection.
185
+ export type AgentWorkspaceScope =
186
+ | { kind: "none" }
187
+ | { kind: "workspace"; read_globs: string[]; write_globs: string[] }
188
+ | { kind: "resource"; resource_types: string[] }
189
+
190
+ export interface AgentModelOverride {
191
+ required_capabilities: string[]
192
+ fallback: "general"
193
+ prefer_different_family?: boolean
194
+ }
195
+
196
+ export interface AgentAcceptanceCriterion {
197
+ id: string
198
+ description: string
199
+ check_tool?: string | null
200
+ }
201
+
146
202
  export interface EthicsDoc {
147
203
  id: string
148
204
  name: string
@@ -169,9 +225,21 @@ export interface UserIdentityDoc {
169
225
  user_id: string
170
226
  channel: string
171
227
  channel_user_id: string
228
+ /** Account that owns this session — replies must go back out through it. Absent on legacy rows. */
229
+ account_id?: string
172
230
  linked_at: number
173
231
  }
174
232
 
233
+ export interface NotificationDoc {
234
+ id: string
235
+ user_id: string
236
+ channel: string
237
+ message: string
238
+ created_at: number
239
+ delivered_at: number | null
240
+ read_at: number | null
241
+ }
242
+
175
243
  export interface UserChannelDoc {
176
244
  id: string
177
245
  user_id: string
@@ -197,16 +265,27 @@ export interface RefreshTokenDoc {
197
265
 
198
266
  // ─── Stage 4: chat/ACE ────────────────────────────────────────────────────────
199
267
 
268
+ /** Where an incoming turn's content came from. */
269
+ export type TurnSource =
270
+ | "message" | "audio" | "a2ui" | "canvas" | "api"
271
+ | "task_complete" | "delegation_summary"
272
+
273
+ /** What gets persisted — adds the synthetic marker for rows written before `source` existed. */
274
+ export type MessageSource = TurnSource | "legacy_internal"
275
+
200
276
  export interface ConversationDoc {
201
277
  id: string
202
278
  thread_id: string
203
279
  channel: string
280
+ /** @deprecated "system" only appears in rows written before `source` existed — never written going forward. */
204
281
  role: "user" | "assistant" | "tool" | "system"
205
282
  content: string
206
283
  content_multimodal: string | null
207
284
  tool_calls_json: string | null
208
285
  tool_call_id: string | null
209
286
  reasoning_content: string | null
287
+ /** null on rows written before this field existed (legacy). */
288
+ source: MessageSource | null
210
289
  token_count: number
211
290
  created_at: number
212
291
  updated_at: number
@@ -234,6 +313,8 @@ export interface TraceDoc {
234
313
  created_at: number
235
314
  /** G9 causal stream id for this run (agent-loop.ts's causalStreamId), when the causal log is enabled. */
236
315
  causal_stream_id?: string | null
316
+ /** Catalog agent id when this trace belongs to a source:"catalog" agent. */
317
+ catalog_agent_id?: string
237
318
  }
238
319
 
239
320
  export interface ReflectionDoc {
@@ -300,6 +381,8 @@ export interface AgentRunDoc {
300
381
  acceptance_json: string | null
301
382
  /** Fixed-worker epoch recorded at run creation: {provider, model, app_version, tool_catalog_hash}. */
302
383
  epoch_json: string | null
384
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT` for ordinary agents. */
385
+ catalog_agent_id?: string
303
386
 
304
387
  error: string | null
305
388
  created_at: number
@@ -310,7 +393,7 @@ export interface AgentRunDoc {
310
393
  export interface JobDoc {
311
394
  id: string
312
395
  lane: string
313
- type: "chat_turn" | "worker_task" | "project_task" | "goal_run"
396
+ type: "chat_turn" | "worker_task" | "goal_run"
314
397
  status: "pending" | "running" | "completed" | "failed" | "cancelled" | "interrupted"
315
398
  priority: number
316
399
  payload_json: string
@@ -386,10 +469,43 @@ export interface ProofPacketDoc {
386
469
  known_limits: string | null
387
470
  /** Fixed-worker epoch this run executed under — copied from AgentRunDoc.epoch_json. */
388
471
  epoch_json: string | null
472
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT`. */
473
+ catalog_agent_id: string
389
474
  met: boolean
390
475
  created_at: number
391
476
  }
392
477
 
478
+ /** Durable metadata for binary evidence managed under HIVE_HOME/artifacts. */
479
+ export interface ArtifactDoc {
480
+ id: string
481
+ run_id: string | null
482
+ task_id: string | null
483
+ user_id: string
484
+ kind: string
485
+ path: string
486
+ mime_type: string
487
+ size: number
488
+ sha256: string
489
+ width: number | null
490
+ height: number | null
491
+ status: "active" | "expired"
492
+ created_at: number
493
+ expires_at: number
494
+ expired_at: number | null
495
+ }
496
+
497
+ export interface AgentProposalDoc {
498
+ id: string
499
+ type: "move_tool" | "create_agent" | "disable_agent"
500
+ agent_id: string
501
+ proposed_change_json: string
502
+ evidence_trace_ids_json: string
503
+ confidence: number
504
+ status: "proposed" | "approved" | "rejected" | "applied"
505
+ created_at: number
506
+ updated_at: number
507
+ }
508
+
393
509
  export interface TaskRunDoc {
394
510
  id: string
395
511
  task_id: string
@@ -413,45 +529,23 @@ export interface MemoryDoc {
413
529
  updated_at: number
414
530
  }
415
531
 
416
- export interface ProjectDoc {
417
- id: string
418
- user_id: string
419
- /** `toIndexable`-encoded — `NO_PARENT` when unset. */
420
- agent_id: string
421
- name: string
422
- description: string | null
423
- type: string
424
- task: string | null
425
- progress: number
426
- status: "pending" | "active" | "paused" | "done" | "failed"
427
- context: string | null
428
- /** `toIndexable`-encoded — `NO_PARENT` for a top-level project. */
429
- parent_id: string
430
- created_at: number
431
- updated_at: number
432
- started_at: number | null
433
- completed_at: number | null
434
- }
435
-
436
532
  export interface TaskDoc {
437
533
  id: string
438
- project_id: string
439
534
  /** `toIndexable`-encoded — `NO_PARENT` when unset. */
440
535
  agent_id: string
441
- parent_task_id: string | null
442
536
  name: string
443
537
  description: string | null
444
- /** "queued" = claimed by the TaskDriver and enqueued, awaiting execution. */
445
- status: "pending" | "queued" | "in_progress" | "completed" | "failed" | "blocked"
538
+ status: "pending" | "in_progress" | "completed" | "failed" | "blocked"
446
539
  progress: number
447
- priority: number
448
- depends_on: string | null
449
540
  result: string | null
450
541
  error: string | null
451
542
  metadata: string | null
452
543
  job_id: string | null
453
544
  run_id: string | null
454
545
  thread_id: string | null
546
+ delegation_group_id?: string | null
547
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT`. */
548
+ catalog_agent_id?: string
455
549
  started_at: number | null
456
550
  attempts: number
457
551
  created_at: number
@@ -459,6 +553,35 @@ export interface TaskDoc {
459
553
  completed_at: number | null
460
554
  }
461
555
 
556
+ export interface DelegationGroupOutcome {
557
+ task_id: string
558
+ job_id: string
559
+ worker_id: string
560
+ task_name: string
561
+ ok: boolean
562
+ result: unknown | null
563
+ error: string | null
564
+ finished_at: number
565
+ }
566
+
567
+ export interface DelegationGroupDoc {
568
+ id: string
569
+ turn_id: string
570
+ thread_id: string
571
+ channel: string
572
+ user_id: string
573
+ session_id: string
574
+ coordinator_agent_id: string
575
+ status: "open" | "sealed" | "ready" | "notified"
576
+ task_ids_json: string
577
+ outcomes_json: string
578
+ summary_job_id: string | null
579
+ created_at: number
580
+ sealed_at: number | null
581
+ ready_at: number | null
582
+ notified_at: number | null
583
+ }
584
+
462
585
  export interface AgentBusMessageDoc {
463
586
  id: string
464
587
  event_type: string
@@ -473,6 +596,23 @@ export interface AgentBusMessageDoc {
473
596
  created_at: number
474
597
  }
475
598
 
599
+ export interface NarrationEventDoc {
600
+ id: string
601
+ turn_id: string
602
+ thread_id: string
603
+ channel: string
604
+ user_id: string
605
+ session_id: string
606
+ agent_id: string
607
+ agent_name: string
608
+ kind: "delegated" | "worker_started" | "tool_call" | "tool_result" | "verified" | "failed" | "group_ready"
609
+ status: "queued" | "running" | "done" | "error"
610
+ label: string
611
+ detail: string | null
612
+ dedupe_key: string
613
+ created_at: number
614
+ }
615
+
476
616
  // ─── Stage 7: meeting ─────────────────────────────────────────────────────────
477
617
 
478
618
  export interface MeetingSessionDoc {
@@ -1,3 +1,7 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto"
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
3
+ import * as path from "node:path"
4
+ import { getHiveDir } from "../config/loader.ts"
1
5
  import { logger } from "../utils/logger"
2
6
  import { col } from "./hive"
3
7
 
@@ -9,49 +13,70 @@ interface SecretDoc {
9
13
  iv: string
10
14
  }
11
15
 
12
- // ─── Keychain with in-memory fallback ────────────────────────────────────────
13
- // On Linux headless (no GNOME Keyring / libsecret) Bun.secrets throws.
14
- // Fall back to in-memory storage so the server stays functional, but log a
15
- // warning so operators know secrets won't survive a restart in that mode.
16
+ // ─── Durable secret store ────────────────────────────────────────────────────
17
+ // The `secrets` collection is the source of truth: AES-256-GCM ciphertext in
18
+ // the database, keyed by <HIVE_HOME>/.master.key. It lives inside the data
19
+ // directory, so whatever persists the database (a Docker volume, a backup)
20
+ // persists the secrets with it.
21
+ //
22
+ // The OS keychain (Bun.secrets) is only a best-effort mirror. It throws on
23
+ // headless Linux/Docker (no libsecret/D-Bus), and on desktops it can be a
24
+ // session keyring that is discarded when the session ends — so a secret
25
+ // written *only* there does not survive a server restart. That is exactly
26
+ // what was wiping every provider API key, channel token and MCP header on
27
+ // restart in production.
16
28
 
17
29
  const _mem = new Map<string, string>()
18
30
  let _keychainOk: boolean | null = null // null = untested
31
+ let _keychainApi: unknown = undefined
19
32
 
20
- async function _get(name: string): Promise<string | null> {
21
- if (_keychainOk === false) {
22
- return _mem.get(name) ?? (await _readCollectionSecret(name))
23
- }
24
- try {
25
- const val = await (Bun as any).secrets.get({ service: SERVICE, name })
26
- _keychainOk = true
27
- return val ?? _mem.get(name) ?? (await _readCollectionSecret(name))
28
- } catch {
29
- _keychainOk = false
30
- return _mem.get(name) ?? (await _readCollectionSecret(name))
33
+ /**
34
+ * A test double or a recovered runtime may replace Bun.secrets. Reset the
35
+ * cached availability result when that API object changes so a previous
36
+ * headless failure cannot poison the replacement backend forever.
37
+ */
38
+ function _getKeychainApi(): any {
39
+ const api = (Bun as any).secrets
40
+ if (api !== _keychainApi) {
41
+ _keychainApi = api
42
+ _keychainOk = null
31
43
  }
44
+ return api
32
45
  }
33
46
 
47
+ async function _get(name: string): Promise<string | null> {
48
+ const cached = _mem.get(name)
49
+ if (cached !== undefined) return cached
50
+
51
+ // Durable store first — it is the one every write goes to.
52
+ const stored = await _readCollectionSecret(name)
53
+ if (stored) return stored
54
+
55
+ // Legacy/desktop installs may only have the value in the OS keychain.
56
+ const fromKeychain = await _keychainGet(name)
57
+ if (fromKeychain) _mem.set(name, fromKeychain)
58
+ return fromKeychain
59
+ }
60
+
61
+ /**
62
+ * Persist a secret. Always writes the durable store; the keychain is
63
+ * mirrored on top when available. Returns false only when the value ended up
64
+ * nowhere but this process's memory — callers can use that to warn instead of
65
+ * silently accepting a secret that dies with the process.
66
+ */
34
67
  async function _set(name: string, value: string): Promise<boolean> {
35
- if (_keychainOk === false) {
36
- _mem.set(name, value)
37
- return persistSecretToCollection(name, value)
38
- }
39
- try {
40
- await (Bun as any).secrets.set({ service: SERVICE, name, value })
41
- _keychainOk = true
42
- return true
43
- } catch {
44
- _keychainOk = false
45
- _mem.set(name, value)
46
- return persistSecretToCollection(name, value)
68
+ _mem.set(name, value)
69
+ const durable = await persistSecretToCollection(name, value)
70
+ const mirrored = await _keychainSet(name, value)
71
+ if (!durable && !mirrored) {
72
+ log.error(`[secrets] ${name} could not be persisted — it will be lost on restart`)
47
73
  }
74
+ return durable || mirrored
48
75
  }
49
76
 
50
77
  /**
51
- * Read a secret from the `secrets` HiveDB collection as a last-resort
52
- * fallback when the keychain and in-memory map are both empty. Used to
53
- * survive process restarts when the OS keychain is unavailable (Docker,
54
- * headless).
78
+ * Read a secret from the `secrets` HiveDB collection — the durable store.
79
+ * Decrypted values are cached in memory for the rest of the process.
55
80
  */
56
81
  async function _readCollectionSecret(name: string): Promise<string | null> {
57
82
  try {
@@ -69,6 +94,32 @@ async function _readCollectionSecret(name: string): Promise<string | null> {
69
94
  }
70
95
  }
71
96
 
97
+ async function _keychainGet(name: string): Promise<string | null> {
98
+ const keychain = _getKeychainApi()
99
+ if (_keychainOk === false) return null
100
+ try {
101
+ const val = await keychain.get({ service: SERVICE, name })
102
+ _keychainOk = true
103
+ return val ?? null
104
+ } catch {
105
+ _keychainOk = false
106
+ return null
107
+ }
108
+ }
109
+
110
+ async function _keychainSet(name: string, value: string): Promise<boolean> {
111
+ const keychain = _getKeychainApi()
112
+ if (_keychainOk === false) return false
113
+ try {
114
+ await keychain.set({ service: SERVICE, name, value })
115
+ _keychainOk = true
116
+ return true
117
+ } catch {
118
+ _keychainOk = false
119
+ return false
120
+ }
121
+ }
122
+
72
123
  async function _del(name: string): Promise<void> {
73
124
  _mem.delete(name)
74
125
  try {
@@ -84,6 +135,22 @@ async function _del(name: string): Promise<void> {
84
135
  }
85
136
  }
86
137
 
138
+ /**
139
+ * Mint the master key (if this is a fresh install) and report where secrets
140
+ * will be stored. Called once at boot so an operator sees the answer before
141
+ * typing an API key, not after a restart lost it.
142
+ */
143
+ export function ensureSecretsBackend(): { durable: boolean } {
144
+ const durable = getMasterKey() !== null
145
+ if (!durable) {
146
+ log.error(
147
+ `[secrets] No master key available — API keys and channel tokens will NOT survive a restart. ` +
148
+ `Set HIVE_MASTER_KEY or make ${getHiveDir()} writable.`
149
+ )
150
+ }
151
+ return { durable }
152
+ }
153
+
87
154
  // ─── Primitive API ────────────────────────────────────────────────────────────
88
155
 
89
156
  export async function storeSecret(name: string, value: string): Promise<void> {
@@ -209,13 +276,12 @@ export function verifyPassword(password: string, hash: string): boolean {
209
276
  // ─── AES-256-GCM for the collection-backed secret fallback ──────────────────
210
277
 
211
278
  export function decryptSecret(encrypted: string, iv: string): string {
212
- const nodeCrypto = require("node:crypto")
213
279
  const key = getMasterKey()
214
280
  if (!key) return ""
215
281
  try {
216
282
  const ivBuf = Buffer.from(iv, "hex")
217
283
  const [encData, authTag] = encrypted.split(":")
218
- const decipher = nodeCrypto.createDecipheriv("aes-256-gcm", key, ivBuf)
284
+ const decipher = createDecipheriv("aes-256-gcm", key, ivBuf)
219
285
  decipher.setAuthTag(Buffer.from(authTag, "hex"))
220
286
  return decipher.update(encData, "hex", "utf8") + decipher.final("utf8")
221
287
  } catch {
@@ -223,38 +289,63 @@ export function decryptSecret(encrypted: string, iv: string): string {
223
289
  }
224
290
  }
225
291
 
292
+ let _masterKey: Buffer | null = null
293
+
294
+ /**
295
+ * The AES key protecting the `secrets` collection.
296
+ *
297
+ * `HIVE_MASTER_KEY` wins when set (the recommended way to run in production:
298
+ * the key never touches the data volume). Otherwise the key is minted on
299
+ * first use and written 0600 to `<HIVE_HOME>/.master.key`, next to the
300
+ * database — a fresh install becomes durable without the user configuring
301
+ * anything, and restoring the data directory restores the ability to read
302
+ * the secrets inside it.
303
+ */
226
304
  function getMasterKey(): Buffer | null {
227
- const nodeCrypto = require("node:crypto")
228
- const nodeFs = require("node:fs")
229
- const nodePath = require("node:path")
230
- const nodeOs = require("node:os")
231
-
232
- const masterKey = process.env.HIVE_MASTER_KEY
233
- if (masterKey) {
234
- return Buffer.from(masterKey.slice(0, 32).padEnd(32, "0"), "utf8")
305
+ if (_masterKey) return _masterKey
306
+
307
+ const fromEnv = process.env.HIVE_MASTER_KEY
308
+ if (fromEnv) {
309
+ _masterKey = Buffer.from(fromEnv.slice(0, 32).padEnd(32, "0"), "utf8")
310
+ return _masterKey
235
311
  }
236
- const hiveDir = process.env.HIVE_HOME || nodePath.join(nodeOs.homedir(), ".hive")
237
- const keyPath = nodePath.join(hiveDir, ".master.key")
238
- if (!nodeFs.existsSync(keyPath)) return null
312
+
313
+ const keyPath = path.join(getHiveDir(), ".master.key")
239
314
  try {
240
- return Buffer.from(nodeFs.readFileSync(keyPath, "utf8").trim(), "hex")
241
- } catch {
315
+ if (!existsSync(keyPath)) {
316
+ mkdirSync(path.dirname(keyPath), { recursive: true })
317
+ try {
318
+ // "wx" so two processes starting at once can't overwrite each other's key
319
+ writeFileSync(keyPath, randomBytes(32).toString("hex"), { mode: 0o600, flag: "wx" })
320
+ log.info(`[secrets] Master key generated at ${keyPath}`)
321
+ } catch (err) {
322
+ if ((err as NodeJS.ErrnoException).code !== "EEXIST") throw err
323
+ }
324
+ }
325
+ const key = Buffer.from(readFileSync(keyPath, "utf8").trim(), "hex")
326
+ if (key.length !== 32) {
327
+ log.error(`[secrets] ${keyPath} is not a 32-byte hex key — secrets cannot be read or written`)
328
+ return null
329
+ }
330
+ _masterKey = key
331
+ return _masterKey
332
+ } catch (err) {
333
+ log.error(`[secrets] Could not read or create ${keyPath}: ${(err as Error).message}`)
242
334
  return null
243
335
  }
244
336
  }
245
337
 
246
338
  /**
247
339
  * Encrypt a plaintext string with AES-256-GCM. Format:
248
- * `<encDataHex>:<authTagHex>`. Used as the `secrets` collection fallback
249
- * when the OS keychain is unavailable (headless Linux, Docker, etc.).
340
+ * `<encDataHex>:<authTagHex>`. Used for every document in the `secrets`
341
+ * collection.
250
342
  */
251
343
  export function encryptSecret(plain: string, ivHex: string): string {
252
- const nodeCrypto = require("node:crypto")
253
344
  const key = getMasterKey()
254
345
  if (!key) return ""
255
346
  try {
256
347
  const iv = Buffer.from(ivHex, "hex")
257
- const cipher = nodeCrypto.createCipheriv("aes-256-gcm", key, iv)
348
+ const cipher = createCipheriv("aes-256-gcm", key, iv)
258
349
  const encData = cipher.update(plain, "utf8", "hex") + cipher.final("hex")
259
350
  const authTag = cipher.getAuthTag().toString("hex")
260
351
  return `${encData}:${authTag}`
@@ -264,20 +355,18 @@ export function encryptSecret(plain: string, ivHex: string): string {
264
355
  }
265
356
 
266
357
  /**
267
- * Persist a secret to the `secrets` collection as a last-resort fallback
268
- * (keyed directly by the canonical secret name, e.g.
269
- * `provider:openai:api_key`). Returns true if the document was written.
358
+ * Persist a secret to the `secrets` collection — the durable store — keyed by
359
+ * the canonical secret name (e.g. `provider:openai:api_key`). Returns true if
360
+ * the document was written.
270
361
  */
271
362
  async function persistSecretToCollection(name: string, value: string): Promise<boolean> {
272
- const nodeCrypto = require("node:crypto")
273
-
274
363
  const key = getMasterKey()
275
364
  if (!key) {
276
- log.warn(`[secrets] No master key in ${process.env.HIVE_HOME || "~/.hive"}/.master.key — cannot persist ${name} to collection fallback`)
365
+ log.warn(`[secrets] No master key — cannot persist ${name} durably`)
277
366
  return false
278
367
  }
279
368
 
280
- const iv = nodeCrypto.randomBytes(12).toString("hex")
369
+ const iv = randomBytes(12).toString("hex")
281
370
  const ciphertext = encryptSecret(value, iv)
282
371
  if (!ciphertext) return false
283
372
 
@@ -286,7 +375,7 @@ async function persistSecretToCollection(name: string, value: string): Promise<b
286
375
  await secrets.put(name, { ciphertext, iv })
287
376
  return true
288
377
  } catch (err) {
289
- log.warn(`[secrets] Collection fallback failed for ${name}: ${(err as Error).message}`)
378
+ log.warn(`[secrets] Durable write failed for ${name}: ${(err as Error).message}`)
290
379
  return false
291
380
  }
292
381
  }
@@ -48,6 +48,15 @@ export async function getHiveDb(): Promise<HiveDB> {
48
48
  return opening;
49
49
  }
50
50
 
51
+ /**
52
+ * Return the currently open database without opening one.
53
+ * Used by lifecycle-aware consumers that need to invalidate state after a
54
+ * close/reopen cycle.
55
+ */
56
+ export function getOpenHiveDb(): HiveDB | null {
57
+ return db;
58
+ }
59
+
51
60
  export function closeHiveDb(): void {
52
61
  if (db) {
53
62
  try {
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Claves de la colección `models`.
3
+ *
4
+ * La colección se indexa sólo por el id del modelo, así que dos providers que
5
+ * sirvan el mismo modelo colisionan y uno pisa al otro (pasó de verdad con
6
+ * `z-ai/glm-5.2`, presente a la vez en NVIDIA NIM y en OpenRouter).
7
+ *
8
+ * Regla: el id conserva el nombre que le da el propietario del modelo, y los
9
+ * servicios revendedores lo prefijan con su propio id de provider.
10
+ *
11
+ * nvidia + z-ai/glm-5.2 → nvidia/z-ai/glm-5.2
12
+ * openrouter + z-ai/glm-5.2 → openrouter/z-ai/glm-5.2
13
+ * anthropic + claude-opus-5 → claude-opus-5
14
+ *
15
+ * El prefijo no llega al cable: `OpenAICompatBase.call()` quita
16
+ * `^<providerName>/` antes de armar el request, así que el provider recibe el
17
+ * nombre del propietario tal cual. Por eso todos los revendedores de esta lista
18
+ * deben ser OpenAI-compatibles.
19
+ */
20
+
21
+ const RESELLER_PROVIDERS = new Set(["nvidia", "openrouter", "opencode-go", "groq", "modelscope"])
22
+
23
+ /**
24
+ * Id de fila en `models` para el modelo `wireId` servido por `providerId`.
25
+ *
26
+ * `wireId` es siempre el nombre del cable, nunca una clave ya prefijada. No hay
27
+ * atajo de idempotencia a propósito: "ya lleva el prefijo" es indistinguible de
28
+ * "el namespace del propietario coincide con el id del provider". NVIDIA sirve
29
+ * `nvidia/nemotron-3-super-120b-a12b` y Groq sirve `groq/compound`, así que
30
+ * saltarse el prefijo por un `startsWith` recortaba de más al volver al cable y
31
+ * mandaba `nemotron-…` / `compound`.
32
+ */
33
+ export function catalogModelKey(providerId: string, wireId: string): string {
34
+ return RESELLER_PROVIDERS.has(providerId) ? `${providerId}/${wireId}` : wireId
35
+ }
36
+
37
+ /**
38
+ * Inversa de `catalogModelKey`: el nombre que el provider espera en el cable.
39
+ *
40
+ * Los adapters OpenAI-compatibles ya hacen este strip solos al armar el request,
41
+ * así que esto es para los caminos que mandan el modelo a mano — por ejemplo la
42
+ * verificación de API key en `gateway/routes/setup.ts`, que arma su propio fetch.
43
+ */
44
+ export function wireModelId(providerId: string, key: string): string {
45
+ const prefix = `${providerId}/`
46
+ if (!RESELLER_PROVIDERS.has(providerId) || !key.startsWith(prefix)) return key
47
+ return key.slice(prefix.length)
48
+ }
49
+
50
+ /** True cuando el provider revende modelos de terceros y por eso prefija sus ids. */
51
+ export function isResellerProvider(providerId: string): boolean {
52
+ return RESELLER_PROVIDERS.has(providerId)
53
+ }