@johpaz/hive 1.7.2 → 1.7.3

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 (427) hide show
  1. package/README.md +178 -36
  2. package/dist/hive.js +315124 -0
  3. package/package.json +11 -3
  4. package/packages/core/src/index.ts +0 -1
  5. package/.dockerignore +0 -9
  6. package/CONTRIBUTING.md +0 -44
  7. package/Dockerfile +0 -67
  8. package/docker-compose.yml +0 -19
  9. package/packages/cli/package.json +0 -28
  10. package/packages/cli/src/commands/agent-run.ts +0 -168
  11. package/packages/cli/src/commands/agents.ts +0 -398
  12. package/packages/cli/src/commands/chat.ts +0 -142
  13. package/packages/cli/src/commands/config.ts +0 -50
  14. package/packages/cli/src/commands/cron.ts +0 -161
  15. package/packages/cli/src/commands/dev.ts +0 -95
  16. package/packages/cli/src/commands/doctor.ts +0 -133
  17. package/packages/cli/src/commands/gateway.ts +0 -422
  18. package/packages/cli/src/commands/logs.ts +0 -57
  19. package/packages/cli/src/commands/mcp.ts +0 -175
  20. package/packages/cli/src/commands/message.ts +0 -77
  21. package/packages/cli/src/commands/onboard.ts +0 -1696
  22. package/packages/cli/src/commands/security.ts +0 -144
  23. package/packages/cli/src/commands/service.ts +0 -50
  24. package/packages/cli/src/commands/sessions.ts +0 -116
  25. package/packages/cli/src/commands/skills.ts +0 -187
  26. package/packages/cli/src/commands/update.ts +0 -25
  27. package/packages/cli/src/index.ts +0 -190
  28. package/packages/cli/src/utils/token.ts +0 -6
  29. package/packages/code-bridge/README.md +0 -78
  30. package/packages/code-bridge/package.json +0 -18
  31. package/packages/code-bridge/src/index.ts +0 -95
  32. package/packages/code-bridge/src/process-manager.ts +0 -212
  33. package/packages/code-bridge/src/schemas.ts +0 -133
  34. package/packages/core/package.json +0 -55
  35. package/packages/core/src/agent/agent-loop.ts +0 -520
  36. package/packages/core/src/agent/compaction.ts +0 -183
  37. package/packages/core/src/agent/context-compiler.ts +0 -544
  38. package/packages/core/src/agent/context-guard.ts +0 -91
  39. package/packages/core/src/agent/conversation-store.ts +0 -193
  40. package/packages/core/src/agent/curator.ts +0 -158
  41. package/packages/core/src/agent/hooks.ts +0 -166
  42. package/packages/core/src/agent/llm-client.ts +0 -503
  43. package/packages/core/src/agent/native-tools.ts +0 -31
  44. package/packages/core/src/agent/playbook-selector.ts +0 -143
  45. package/packages/core/src/agent/prompt-builder.ts +0 -167
  46. package/packages/core/src/agent/providers/index.ts +0 -186
  47. package/packages/core/src/agent/providers.ts +0 -1
  48. package/packages/core/src/agent/reflector.ts +0 -200
  49. package/packages/core/src/agent/service.ts +0 -266
  50. package/packages/core/src/agent/skill-selector.ts +0 -413
  51. package/packages/core/src/agent/stuck-loop.ts +0 -133
  52. package/packages/core/src/agent/tool-selector.ts +0 -623
  53. package/packages/core/src/agent/tracer.ts +0 -102
  54. package/packages/core/src/canvas/canvas-manager.ts +0 -319
  55. package/packages/core/src/canvas/canvas-tools.ts +0 -420
  56. package/packages/core/src/canvas/emitter.ts +0 -119
  57. package/packages/core/src/canvas/index.ts +0 -2
  58. package/packages/core/src/channels/base.ts +0 -140
  59. package/packages/core/src/channels/discord.ts +0 -260
  60. package/packages/core/src/channels/index.ts +0 -7
  61. package/packages/core/src/channels/manager.ts +0 -383
  62. package/packages/core/src/channels/slack.ts +0 -287
  63. package/packages/core/src/channels/telegram.ts +0 -552
  64. package/packages/core/src/channels/webchat.ts +0 -139
  65. package/packages/core/src/channels/whatsapp.ts +0 -375
  66. package/packages/core/src/config/index.ts +0 -12
  67. package/packages/core/src/config/loader.ts +0 -529
  68. package/packages/core/src/events/agent-bus.ts +0 -460
  69. package/packages/core/src/events/event-bus.ts +0 -169
  70. package/packages/core/src/gateway/helpers/cors.ts +0 -32
  71. package/packages/core/src/gateway/helpers/index.ts +0 -4
  72. package/packages/core/src/gateway/helpers/narration.ts +0 -60
  73. package/packages/core/src/gateway/helpers/path.ts +0 -13
  74. package/packages/core/src/gateway/helpers/redact.ts +0 -61
  75. package/packages/core/src/gateway/index.ts +0 -5
  76. package/packages/core/src/gateway/initializer.ts +0 -332
  77. package/packages/core/src/gateway/lane-queue.ts +0 -169
  78. package/packages/core/src/gateway/resolver.ts +0 -108
  79. package/packages/core/src/gateway/router.ts +0 -124
  80. package/packages/core/src/gateway/routes/agents.ts +0 -187
  81. package/packages/core/src/gateway/routes/channels.ts +0 -203
  82. package/packages/core/src/gateway/routes/chat.ts +0 -241
  83. package/packages/core/src/gateway/routes/config.ts +0 -12
  84. package/packages/core/src/gateway/routes/cron.ts +0 -42
  85. package/packages/core/src/gateway/routes/ethics.ts +0 -46
  86. package/packages/core/src/gateway/routes/mcp.ts +0 -346
  87. package/packages/core/src/gateway/routes/models.ts +0 -93
  88. package/packages/core/src/gateway/routes/projects.ts +0 -179
  89. package/packages/core/src/gateway/routes/providers.ts +0 -192
  90. package/packages/core/src/gateway/routes/setup.ts +0 -267
  91. package/packages/core/src/gateway/routes/skills.ts +0 -70
  92. package/packages/core/src/gateway/routes/system.ts +0 -165
  93. package/packages/core/src/gateway/routes/tasks.ts +0 -44
  94. package/packages/core/src/gateway/routes/tools.ts +0 -35
  95. package/packages/core/src/gateway/routes/users.ts +0 -118
  96. package/packages/core/src/gateway/routes/voice.ts +0 -73
  97. package/packages/core/src/gateway/routes/workspace.ts +0 -281
  98. package/packages/core/src/gateway/server.ts +0 -1978
  99. package/packages/core/src/gateway/session.ts +0 -95
  100. package/packages/core/src/gateway/slash-commands.ts +0 -193
  101. package/packages/core/src/heartbeat/index.ts +0 -157
  102. package/packages/core/src/mcp/hot-reload.ts +0 -213
  103. package/packages/core/src/mcp/singleton.ts +0 -21
  104. package/packages/core/src/memory/index.ts +0 -1
  105. package/packages/core/src/memory/notes.ts +0 -68
  106. package/packages/core/src/plugins/api.ts +0 -128
  107. package/packages/core/src/plugins/index.ts +0 -2
  108. package/packages/core/src/plugins/loader.ts +0 -365
  109. package/packages/core/src/resilience/circuit-breaker.ts +0 -225
  110. package/packages/core/src/security/google-chat.ts +0 -269
  111. package/packages/core/src/security/index.ts +0 -192
  112. package/packages/core/src/security/pairing.ts +0 -250
  113. package/packages/core/src/security/rate-limit.ts +0 -270
  114. package/packages/core/src/security/signal.ts +0 -321
  115. package/packages/core/src/state/store.ts +0 -312
  116. package/packages/core/src/storage/crypto.ts +0 -101
  117. package/packages/core/src/storage/onboarding.ts +0 -1609
  118. package/packages/core/src/storage/schema.ts +0 -567
  119. package/packages/core/src/storage/seed.ts +0 -608
  120. package/packages/core/src/storage/sqlite.ts +0 -363
  121. package/packages/core/src/storage/usage.ts +0 -270
  122. package/packages/core/src/tools/agents/index.ts +0 -607
  123. package/packages/core/src/tools/bridge-events.ts +0 -26
  124. package/packages/core/src/tools/canvas/index.ts +0 -281
  125. package/packages/core/src/tools/cli/index.ts +0 -142
  126. package/packages/core/src/tools/codebridge/index.ts +0 -179
  127. package/packages/core/src/tools/core/index.ts +0 -257
  128. package/packages/core/src/tools/cron/index.ts +0 -373
  129. package/packages/core/src/tools/filesystem/fs-delete.ts +0 -78
  130. package/packages/core/src/tools/filesystem/fs-edit.ts +0 -106
  131. package/packages/core/src/tools/filesystem/fs-exists.ts +0 -63
  132. package/packages/core/src/tools/filesystem/fs-glob.ts +0 -108
  133. package/packages/core/src/tools/filesystem/fs-list.ts +0 -129
  134. package/packages/core/src/tools/filesystem/fs-read.ts +0 -72
  135. package/packages/core/src/tools/filesystem/fs-write.ts +0 -67
  136. package/packages/core/src/tools/filesystem/index.ts +0 -34
  137. package/packages/core/src/tools/filesystem/workspace-guard.ts +0 -62
  138. package/packages/core/src/tools/index.ts +0 -197
  139. package/packages/core/src/tools/projects/index.ts +0 -37
  140. package/packages/core/src/tools/projects/project-create.ts +0 -94
  141. package/packages/core/src/tools/projects/project-done.ts +0 -66
  142. package/packages/core/src/tools/projects/project-fail.ts +0 -66
  143. package/packages/core/src/tools/projects/project-list.ts +0 -96
  144. package/packages/core/src/tools/projects/project-update.ts +0 -72
  145. package/packages/core/src/tools/projects/task-create.ts +0 -68
  146. package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
  147. package/packages/core/src/tools/projects/task-update.ts +0 -93
  148. package/packages/core/src/tools/search-knowledge/search-knowledge.ts +0 -155
  149. package/packages/core/src/tools/types.ts +0 -39
  150. package/packages/core/src/tools/voice/index.ts +0 -104
  151. package/packages/core/src/tools/web/browser-click.ts +0 -54
  152. package/packages/core/src/tools/web/browser-navigate.ts +0 -84
  153. package/packages/core/src/tools/web/browser-screenshot.ts +0 -54
  154. package/packages/core/src/tools/web/browser-type.ts +0 -60
  155. package/packages/core/src/tools/web/index.ts +0 -31
  156. package/packages/core/src/tools/web/web-fetch.ts +0 -78
  157. package/packages/core/src/tools/web/web-search.ts +0 -123
  158. package/packages/core/src/utils/benchmark.ts +0 -80
  159. package/packages/core/src/utils/crypto.ts +0 -73
  160. package/packages/core/src/utils/date.ts +0 -42
  161. package/packages/core/src/utils/index.ts +0 -5
  162. package/packages/core/src/utils/logger.ts +0 -389
  163. package/packages/core/src/utils/retry.ts +0 -70
  164. package/packages/core/src/utils/toon.ts +0 -356
  165. package/packages/core/src/voice/index.ts +0 -583
  166. package/packages/hive-ui/README.md +0 -52
  167. package/packages/hive-ui/components.json +0 -20
  168. package/packages/hive-ui/index.html +0 -30
  169. package/packages/hive-ui/package.json +0 -90
  170. package/packages/hive-ui/public/favicon.ico +0 -0
  171. package/packages/hive-ui/public/placeholder.svg +0 -1
  172. package/packages/hive-ui/src/App.tsx +0 -115
  173. package/packages/hive-ui/src/components/CronJobsPanel.tsx +0 -200
  174. package/packages/hive-ui/src/components/NavLink.tsx +0 -34
  175. package/packages/hive-ui/src/components/NotesPanel.tsx +0 -79
  176. package/packages/hive-ui/src/components/SystemMonitor.tsx +0 -270
  177. package/packages/hive-ui/src/components/UsageStatsPanel.tsx +0 -334
  178. package/packages/hive-ui/src/components/WelcomeDialog.tsx +0 -279
  179. package/packages/hive-ui/src/components/ui/accordion.tsx +0 -52
  180. package/packages/hive-ui/src/components/ui/alert-dialog.tsx +0 -104
  181. package/packages/hive-ui/src/components/ui/alert.tsx +0 -45
  182. package/packages/hive-ui/src/components/ui/aspect-ratio.tsx +0 -5
  183. package/packages/hive-ui/src/components/ui/avatar.tsx +0 -38
  184. package/packages/hive-ui/src/components/ui/badge.tsx +0 -29
  185. package/packages/hive-ui/src/components/ui/bee-loader.tsx +0 -68
  186. package/packages/hive-ui/src/components/ui/breadcrumb.tsx +0 -90
  187. package/packages/hive-ui/src/components/ui/button.tsx +0 -47
  188. package/packages/hive-ui/src/components/ui/calendar.tsx +0 -54
  189. package/packages/hive-ui/src/components/ui/card.tsx +0 -45
  190. package/packages/hive-ui/src/components/ui/carousel.tsx +0 -224
  191. package/packages/hive-ui/src/components/ui/chart.tsx +0 -303
  192. package/packages/hive-ui/src/components/ui/checkbox.tsx +0 -26
  193. package/packages/hive-ui/src/components/ui/collapsible.tsx +0 -9
  194. package/packages/hive-ui/src/components/ui/command.tsx +0 -133
  195. package/packages/hive-ui/src/components/ui/context-menu.tsx +0 -178
  196. package/packages/hive-ui/src/components/ui/dialog.tsx +0 -95
  197. package/packages/hive-ui/src/components/ui/drawer.tsx +0 -87
  198. package/packages/hive-ui/src/components/ui/dropdown-menu.tsx +0 -179
  199. package/packages/hive-ui/src/components/ui/form.tsx +0 -129
  200. package/packages/hive-ui/src/components/ui/hover-card.tsx +0 -27
  201. package/packages/hive-ui/src/components/ui/input-otp.tsx +0 -61
  202. package/packages/hive-ui/src/components/ui/input.tsx +0 -22
  203. package/packages/hive-ui/src/components/ui/label.tsx +0 -17
  204. package/packages/hive-ui/src/components/ui/menubar.tsx +0 -207
  205. package/packages/hive-ui/src/components/ui/navigation-menu.tsx +0 -120
  206. package/packages/hive-ui/src/components/ui/pagination.tsx +0 -80
  207. package/packages/hive-ui/src/components/ui/popover.tsx +0 -29
  208. package/packages/hive-ui/src/components/ui/progress.tsx +0 -23
  209. package/packages/hive-ui/src/components/ui/radio-group.tsx +0 -36
  210. package/packages/hive-ui/src/components/ui/resizable.tsx +0 -37
  211. package/packages/hive-ui/src/components/ui/scroll-area.tsx +0 -38
  212. package/packages/hive-ui/src/components/ui/select.tsx +0 -143
  213. package/packages/hive-ui/src/components/ui/separator.tsx +0 -20
  214. package/packages/hive-ui/src/components/ui/sheet.tsx +0 -107
  215. package/packages/hive-ui/src/components/ui/sidebar.tsx +0 -636
  216. package/packages/hive-ui/src/components/ui/skeleton.tsx +0 -7
  217. package/packages/hive-ui/src/components/ui/slider.tsx +0 -23
  218. package/packages/hive-ui/src/components/ui/sonner.tsx +0 -27
  219. package/packages/hive-ui/src/components/ui/switch.tsx +0 -27
  220. package/packages/hive-ui/src/components/ui/table.tsx +0 -72
  221. package/packages/hive-ui/src/components/ui/tabs.tsx +0 -53
  222. package/packages/hive-ui/src/components/ui/textarea.tsx +0 -21
  223. package/packages/hive-ui/src/components/ui/toast.tsx +0 -111
  224. package/packages/hive-ui/src/components/ui/toaster.tsx +0 -24
  225. package/packages/hive-ui/src/components/ui/toggle-group.tsx +0 -49
  226. package/packages/hive-ui/src/components/ui/toggle.tsx +0 -37
  227. package/packages/hive-ui/src/components/ui/tooltip.tsx +0 -28
  228. package/packages/hive-ui/src/components/ui/use-toast.ts +0 -3
  229. package/packages/hive-ui/src/hooks/use-mobile.tsx +0 -19
  230. package/packages/hive-ui/src/hooks/use-toast.ts +0 -186
  231. package/packages/hive-ui/src/hooks/useAgentConfig.ts +0 -25
  232. package/packages/hive-ui/src/hooks/useAgents.ts +0 -38
  233. package/packages/hive-ui/src/hooks/useBridge.ts +0 -38
  234. package/packages/hive-ui/src/hooks/useCanvas.ts +0 -24
  235. package/packages/hive-ui/src/hooks/useChannels.ts +0 -2
  236. package/packages/hive-ui/src/hooks/useEthics.ts +0 -51
  237. package/packages/hive-ui/src/hooks/useProviders.ts +0 -14
  238. package/packages/hive-ui/src/hooks/useTheme.ts +0 -29
  239. package/packages/hive-ui/src/hooks/useUserConfig.ts +0 -17
  240. package/packages/hive-ui/src/hooks/useWebSocket.ts +0 -12
  241. package/packages/hive-ui/src/index.css +0 -620
  242. package/packages/hive-ui/src/lib/api.ts +0 -100
  243. package/packages/hive-ui/src/lib/constants.ts +0 -6
  244. package/packages/hive-ui/src/lib/models.ts +0 -64
  245. package/packages/hive-ui/src/lib/swal.ts +0 -30
  246. package/packages/hive-ui/src/lib/utils.ts +0 -6
  247. package/packages/hive-ui/src/lib/websocket.ts +0 -7
  248. package/packages/hive-ui/src/main.tsx +0 -5
  249. package/packages/hive-ui/src/modules/agent-config/details/AgentDetailsEditor.tsx +0 -524
  250. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsConflictDetector.tsx +0 -18
  251. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsEditor.tsx +0 -19
  252. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsRulesList.tsx +0 -36
  253. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsTemplateGallery.tsx +0 -361
  254. package/packages/hive-ui/src/modules/agent-config/ethics/index.ts +0 -4
  255. package/packages/hive-ui/src/modules/agent-config/index.ts +0 -6
  256. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerAdd.tsx +0 -322
  257. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerCard.tsx +0 -93
  258. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerConfig.tsx +0 -427
  259. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerList.tsx +0 -85
  260. package/packages/hive-ui/src/modules/agent-config/mcp/MCPToolExplorer.tsx +0 -79
  261. package/packages/hive-ui/src/modules/agent-config/mcp/index.ts +0 -5
  262. package/packages/hive-ui/src/modules/agent-config/shared/ConfigEditorLayout.tsx +0 -30
  263. package/packages/hive-ui/src/modules/agent-config/shared/ConfigExporter.tsx +0 -26
  264. package/packages/hive-ui/src/modules/agent-config/shared/ConfigImporter.tsx +0 -25
  265. package/packages/hive-ui/src/modules/agent-config/shared/DiffViewer.tsx +0 -31
  266. package/packages/hive-ui/src/modules/agent-config/shared/MarkdownEditor.tsx +0 -32
  267. package/packages/hive-ui/src/modules/agent-config/shared/SaveStatusIndicator.tsx +0 -23
  268. package/packages/hive-ui/src/modules/agent-config/shared/ValidationPanel.tsx +0 -36
  269. package/packages/hive-ui/src/modules/agent-config/shared/index.ts +0 -7
  270. package/packages/hive-ui/src/modules/agent-config/skills/SkillCard.tsx +0 -81
  271. package/packages/hive-ui/src/modules/agent-config/skills/SkillConfigEditor.tsx +0 -22
  272. package/packages/hive-ui/src/modules/agent-config/skills/SkillCreator.tsx +0 -60
  273. package/packages/hive-ui/src/modules/agent-config/skills/SkillInstaller.tsx +0 -23
  274. package/packages/hive-ui/src/modules/agent-config/skills/SkillList.tsx +0 -72
  275. package/packages/hive-ui/src/modules/agent-config/skills/SkillsTab.tsx +0 -202
  276. package/packages/hive-ui/src/modules/agent-config/skills/index.ts +0 -5
  277. package/packages/hive-ui/src/modules/agent-config/tools/ToolCard.tsx +0 -27
  278. package/packages/hive-ui/src/modules/agent-config/tools/ToolConfigPanel.tsx +0 -22
  279. package/packages/hive-ui/src/modules/agent-config/tools/ToolManager.tsx +0 -266
  280. package/packages/hive-ui/src/modules/agent-config/tools/ToolPermissions.tsx +0 -287
  281. package/packages/hive-ui/src/modules/agent-config/tools/ToolRegistry.tsx +0 -84
  282. package/packages/hive-ui/src/modules/agent-config/tools/ToolUsageStats.tsx +0 -52
  283. package/packages/hive-ui/src/modules/agent-config/tools/index.ts +0 -4
  284. package/packages/hive-ui/src/modules/agent-config/user/ActiveAgentsList.tsx +0 -109
  285. package/packages/hive-ui/src/modules/agent-config/user/GlobalConfigOverview.tsx +0 -119
  286. package/packages/hive-ui/src/modules/agent-config/user/UserMemoryManager.tsx +0 -54
  287. package/packages/hive-ui/src/modules/agent-config/user/UserPreferencesForm.tsx +0 -163
  288. package/packages/hive-ui/src/modules/agent-config/user/UserProfileEditor.tsx +0 -261
  289. package/packages/hive-ui/src/modules/agent-config/user/index.ts +0 -3
  290. package/packages/hive-ui/src/modules/agents/AgentActivityLog.tsx +0 -25
  291. package/packages/hive-ui/src/modules/agents/AgentCard.tsx +0 -305
  292. package/packages/hive-ui/src/modules/agents/AgentCreateForm.tsx +0 -446
  293. package/packages/hive-ui/src/modules/agents/AgentDetail.tsx +0 -28
  294. package/packages/hive-ui/src/modules/agents/AgentInternalCard.tsx +0 -162
  295. package/packages/hive-ui/src/modules/agents/AgentList.tsx +0 -29
  296. package/packages/hive-ui/src/modules/agents/AgentStatusBadge.tsx +0 -34
  297. package/packages/hive-ui/src/modules/agents/ModelSelector.tsx +0 -151
  298. package/packages/hive-ui/src/modules/bridge/BridgeLogViewer.tsx +0 -61
  299. package/packages/hive-ui/src/modules/bridge/BridgeProcessList.tsx +0 -77
  300. package/packages/hive-ui/src/modules/bridge/BridgeStatus.tsx +0 -23
  301. package/packages/hive-ui/src/modules/bridge/BridgeTerminal.tsx +0 -7
  302. package/packages/hive-ui/src/modules/canvas/CanvasButton.tsx +0 -3
  303. package/packages/hive-ui/src/modules/canvas/CanvasChart.tsx +0 -3
  304. package/packages/hive-ui/src/modules/canvas/CanvasComponentMap.tsx +0 -605
  305. package/packages/hive-ui/src/modules/canvas/CanvasContainer.tsx +0 -360
  306. package/packages/hive-ui/src/modules/canvas/CanvasForm.tsx +0 -3
  307. package/packages/hive-ui/src/modules/canvas/CanvasMarkdown.tsx +0 -3
  308. package/packages/hive-ui/src/modules/canvas/CanvasTable.tsx +0 -3
  309. package/packages/hive-ui/src/modules/canvas/ComponentRenderer.tsx +0 -30
  310. package/packages/hive-ui/src/modules/canvas/DynamicRenderer.tsx +0 -3
  311. package/packages/hive-ui/src/modules/channels/available/AvailableChannelsGrid.tsx +0 -89
  312. package/packages/hive-ui/src/modules/channels/available/ChannelAuthForm.tsx +0 -33
  313. package/packages/hive-ui/src/modules/channels/available/ChannelSetupWizard.tsx +0 -48
  314. package/packages/hive-ui/src/modules/channels/available/ChannelTestConnection.tsx +0 -37
  315. package/packages/hive-ui/src/modules/channels/available/ChannelTypeCard.tsx +0 -30
  316. package/packages/hive-ui/src/modules/channels/available/ChannelWebhookConfig.tsx +0 -30
  317. package/packages/hive-ui/src/modules/channels/available/index.ts +0 -6
  318. package/packages/hive-ui/src/modules/channels/connected/ChannelCard.tsx +0 -95
  319. package/packages/hive-ui/src/modules/channels/connected/ChannelConfigPanel.tsx +0 -260
  320. package/packages/hive-ui/src/modules/channels/connected/ChannelDisconnectButton.tsx +0 -21
  321. package/packages/hive-ui/src/modules/channels/connected/ChannelLogsViewer.tsx +0 -42
  322. package/packages/hive-ui/src/modules/channels/connected/ChannelQRCode.tsx +0 -32
  323. package/packages/hive-ui/src/modules/channels/connected/ChannelReconnectButton.tsx +0 -16
  324. package/packages/hive-ui/src/modules/channels/connected/ChannelStatusBadge.tsx +0 -26
  325. package/packages/hive-ui/src/modules/channels/connected/ConnectedChannelsList.tsx +0 -40
  326. package/packages/hive-ui/src/modules/channels/connected/index.ts +0 -8
  327. package/packages/hive-ui/src/modules/channels/shared/ChannelCard.tsx +0 -84
  328. package/packages/hive-ui/src/modules/channels/shared/ChannelConfigDialog.tsx +0 -279
  329. package/packages/hive-ui/src/modules/channels/shared/ChannelIcon.tsx +0 -40
  330. package/packages/hive-ui/src/modules/channels/shared/ChannelStats.tsx +0 -37
  331. package/packages/hive-ui/src/modules/channels/shared/ChannelTypeBadge.tsx +0 -23
  332. package/packages/hive-ui/src/modules/channels/shared/ConnectionHealthIndicator.tsx +0 -20
  333. package/packages/hive-ui/src/modules/channels/shared/MessagePreview.tsx +0 -19
  334. package/packages/hive-ui/src/modules/channels/shared/index.ts +0 -5
  335. package/packages/hive-ui/src/modules/chat/ChatContainer.tsx +0 -268
  336. package/packages/hive-ui/src/modules/chat/ChatHistory.tsx +0 -101
  337. package/packages/hive-ui/src/modules/chat/ChatInput.tsx +0 -108
  338. package/packages/hive-ui/src/modules/chat/ChatMessage.tsx +0 -137
  339. package/packages/hive-ui/src/modules/chat/ThinkingIndicator.tsx +0 -10
  340. package/packages/hive-ui/src/modules/layout/AppLayout.tsx +0 -45
  341. package/packages/hive-ui/src/modules/layout/ConnectionStatus.tsx +0 -19
  342. package/packages/hive-ui/src/modules/layout/Header.tsx +0 -20
  343. package/packages/hive-ui/src/modules/layout/HiveSidebar.tsx +0 -173
  344. package/packages/hive-ui/src/modules/layout/ThemeToggle.tsx +0 -18
  345. package/packages/hive-ui/src/modules/providers/ProviderCard.tsx +0 -319
  346. package/packages/hive-ui/src/modules/providers/ProviderConfigForm.tsx +0 -146
  347. package/packages/hive-ui/src/modules/providers/ProviderFailoverConfig.tsx +0 -110
  348. package/packages/hive-ui/src/modules/providers/ProviderList.tsx +0 -33
  349. package/packages/hive-ui/src/modules/providers/ProviderStatusIndicator.tsx +0 -23
  350. package/packages/hive-ui/src/modules/providers/configs/ProviderAPIKeyManager.tsx +0 -39
  351. package/packages/hive-ui/src/modules/providers/configs/ProviderEndpointConfig.tsx +0 -27
  352. package/packages/hive-ui/src/modules/providers/configs/ProviderRateLimits.tsx +0 -37
  353. package/packages/hive-ui/src/modules/providers/configs/ProviderRetryPolicy.tsx +0 -46
  354. package/packages/hive-ui/src/modules/providers/configs/index.ts +0 -4
  355. package/packages/hive-ui/src/modules/providers/index.ts +0 -5
  356. package/packages/hive-ui/src/modules/providers/models/ModelBenchmarkBadge.tsx +0 -21
  357. package/packages/hive-ui/src/modules/providers/models/ModelCapabilities.tsx +0 -44
  358. package/packages/hive-ui/src/modules/providers/models/ModelCard.tsx +0 -36
  359. package/packages/hive-ui/src/modules/providers/models/ModelComparisonTable.tsx +0 -47
  360. package/packages/hive-ui/src/modules/providers/models/ModelList.tsx +0 -51
  361. package/packages/hive-ui/src/modules/providers/models/ModelPricingInfo.tsx +0 -17
  362. package/packages/hive-ui/src/modules/providers/models/ModelSelector.tsx +0 -32
  363. package/packages/hive-ui/src/modules/providers/models/index.ts +0 -7
  364. package/packages/hive-ui/src/pages/AgentDetailPage.tsx +0 -74
  365. package/packages/hive-ui/src/pages/AgentNewPage.tsx +0 -5
  366. package/packages/hive-ui/src/pages/AgentsPage.tsx +0 -147
  367. package/packages/hive-ui/src/pages/BridgePage.tsx +0 -83
  368. package/packages/hive-ui/src/pages/CanvasPage.tsx +0 -32
  369. package/packages/hive-ui/src/pages/ChannelsPage.tsx +0 -176
  370. package/packages/hive-ui/src/pages/DashboardPage.tsx +0 -321
  371. package/packages/hive-ui/src/pages/Index.tsx +0 -14
  372. package/packages/hive-ui/src/pages/LogsPage.tsx +0 -252
  373. package/packages/hive-ui/src/pages/NotFound.tsx +0 -24
  374. package/packages/hive-ui/src/pages/ProjectsPage.tsx +0 -241
  375. package/packages/hive-ui/src/pages/ProvidersPage.tsx +0 -111
  376. package/packages/hive-ui/src/pages/SettingsPage.tsx +0 -147
  377. package/packages/hive-ui/src/pages/SetupPage.tsx +0 -1177
  378. package/packages/hive-ui/src/pages/WebChatPage.tsx +0 -15
  379. package/packages/hive-ui/src/stores/agentConfigStore.ts +0 -32
  380. package/packages/hive-ui/src/stores/agentStore.ts +0 -5
  381. package/packages/hive-ui/src/stores/bridgeStore.ts +0 -237
  382. package/packages/hive-ui/src/stores/canvasStore.ts +0 -250
  383. package/packages/hive-ui/src/stores/channelStore.ts +0 -5
  384. package/packages/hive-ui/src/stores/chatStore.ts +0 -42
  385. package/packages/hive-ui/src/stores/ethicsStore.ts +0 -141
  386. package/packages/hive-ui/src/stores/mcpStore.ts +0 -5
  387. package/packages/hive-ui/src/stores/modelStore.ts +0 -2
  388. package/packages/hive-ui/src/stores/projectsStore.ts +0 -141
  389. package/packages/hive-ui/src/stores/providerStore.ts +0 -2
  390. package/packages/hive-ui/src/stores/skillStore.ts +0 -5
  391. package/packages/hive-ui/src/stores/toolStore.ts +0 -5
  392. package/packages/hive-ui/src/stores/useGlobalConfigStore.ts +0 -937
  393. package/packages/hive-ui/src/stores/useLoaderStore.ts +0 -21
  394. package/packages/hive-ui/src/stores/useNotesAndCronsStore.ts +0 -144
  395. package/packages/hive-ui/src/stores/useWebSocketStore.ts +0 -152
  396. package/packages/hive-ui/src/stores/useWelcomeStore.ts +0 -37
  397. package/packages/hive-ui/src/stores/userConfigStore.ts +0 -23
  398. package/packages/hive-ui/src/stores/userStore.ts +0 -82
  399. package/packages/hive-ui/src/test/setup.ts +0 -15
  400. package/packages/hive-ui/src/types/agent-config.ts +0 -33
  401. package/packages/hive-ui/src/types/agent.ts +0 -65
  402. package/packages/hive-ui/src/types/bridge.ts +0 -27
  403. package/packages/hive-ui/src/types/canvas.ts +0 -76
  404. package/packages/hive-ui/src/types/channels.ts +0 -109
  405. package/packages/hive-ui/src/types/chat.ts +0 -25
  406. package/packages/hive-ui/src/types/connections.ts +0 -17
  407. package/packages/hive-ui/src/types/ethics.ts +0 -41
  408. package/packages/hive-ui/src/types/index.ts +0 -15
  409. package/packages/hive-ui/src/types/mcp.ts +0 -36
  410. package/packages/hive-ui/src/types/notes-crons.ts +0 -31
  411. package/packages/hive-ui/src/types/providers.ts +0 -145
  412. package/packages/hive-ui/src/types/skill.ts +0 -12
  413. package/packages/hive-ui/src/types/tool.ts +0 -44
  414. package/packages/hive-ui/src/types/user.ts +0 -26
  415. package/packages/hive-ui/src/types/websocket.ts +0 -14
  416. package/packages/hive-ui/src/vite-env.d.ts +0 -1
  417. package/packages/mcp/package.json +0 -26
  418. package/packages/mcp/src/config.ts +0 -13
  419. package/packages/mcp/src/index.ts +0 -1
  420. package/packages/mcp/src/logger.ts +0 -42
  421. package/packages/mcp/src/manager.ts +0 -439
  422. package/packages/mcp/src/transports/index.ts +0 -67
  423. package/packages/mcp/src/transports/sse.ts +0 -241
  424. package/packages/mcp/src/transports/websocket.ts +0 -159
  425. package/packages/skills/package.json +0 -21
  426. package/packages/skills/src/index.ts +0 -1
  427. package/packages/skills/src/loader.ts +0 -346
@@ -1,167 +0,0 @@
1
- /**
2
- * Prompt Builder — Construye el system prompt con la jerarquía constitucional.
3
- *
4
- * Orden de ensamblaje:
5
- * 1. ÉTICA (capa constitucional, siempre completa, inmutable)
6
- * 2. IDENTIDAD DEL AGENTE (de la tabla agents)
7
- * 3. HIVE ECOSYSTEM (system prompt directo para el coordinador)
8
- * 4. IDENTIDAD DEL USUARIO (de la tabla users)
9
- *
10
- * El Context Compiler agrega después:
11
- * - Playbook rules (ACE)
12
- * - Scratchpad notes
13
- * - Skills activos
14
- */
15
-
16
- import { getDb } from "../storage/sqlite"
17
- import { logger } from "../utils/logger"
18
- import { formatContext } from "../utils/toon"
19
- import { resolveUserId } from "../storage/onboarding"
20
-
21
- const log = logger.child("prompt-builder")
22
-
23
- export interface BuildSystemPromptOpts {
24
- agentId: string
25
- userId: string
26
- }
27
-
28
- /**
29
- * Construye el system prompt completo para un agente.
30
- *
31
- * Jerarquía:
32
- * 1. Ética (siempre completa, no se filtra, no se comprime)
33
- * 2. Identidad del agente (role, description, system_prompt)
34
- * 3. Hive Ecosystem (ya incluido en agents.system_prompt desde onboarding.ts)
35
- * 4. Identidad del usuario (nombre, preferencias, contexto)
36
- */
37
- export async function buildSystemPrompt(opts: BuildSystemPromptOpts): Promise<string> {
38
- const db = getDb()
39
- const { agentId, userId } = opts
40
-
41
- // ──────────────────────────────────────────────────────────────────────────
42
- // 1. ÉTICA — Capa constitucional (siempre completa)
43
- // ──────────────────────────────────────────────────────────────────────────
44
- const ethicsRules = db.query<any, []>(`
45
- SELECT name, content, description
46
- FROM ethics
47
- WHERE enabled = 1 AND active = 1
48
- ORDER BY is_default DESC, id ASC
49
- `).all()
50
-
51
- let ethicsSection = ""
52
- if (ethicsRules.length > 0) {
53
- const ethicsContent = ethicsRules.map((rule: any) => {
54
- return `## ${rule.name}\n${rule.content}`
55
- }).join("\n\n")
56
-
57
- ethicsSection = `# ÉTICA Y REGLAS CONSTITUCIONALES\n\n${ethicsContent}\n\n`
58
- log.info(`[prompt-builder] Loaded ${ethicsRules.length} ethics rules`)
59
- } else {
60
- // Ética por defecto si no hay reglas configuradas
61
- ethicsSection = `# ÉTICA Y REGLAS CONSTITUCIONALES\n\n` +
62
- `- Sé útil, inofensivo y honesto\n` +
63
- `- No generes contenido dañino, ilegal o peligroso\n` +
64
- `- Respeta la privacidad y seguridad del usuario\n` +
65
- `- Si no sabes algo, admítelo\n\n`
66
- }
67
-
68
- // ──────────────────────────────────────────────────────────────────────────
69
- // 2. IDENTIDAD DEL AGENTE
70
- // ──────────────────────────────────────────────────────────────────────────
71
- const agent = db.query<any, [string]>(`
72
- SELECT id, name, role, description, system_prompt, tone, max_iterations, workspace
73
- FROM agents
74
- WHERE id = ?
75
- `).get(agentId)
76
-
77
- if (!agent) {
78
- throw new Error(`Agent not found: ${agentId}`)
79
- }
80
-
81
- let agentSection = `# IDENTIDAD DEL AGENTE\n\n`
82
- agentSection += `**Nombre**: ${agent.name}\n`
83
- agentSection += `**Rol**: ${agent.role}\n`
84
-
85
- if (agent.description) {
86
- agentSection += `**Descripción**: ${agent.description}\n`
87
- }
88
-
89
- if (agent.tone) {
90
- agentSection += `**Tono**: ${agent.tone}\n`
91
- }
92
-
93
- agentSection += `**Iteraciones máximas**: ${agent.max_iterations}\n\n`
94
-
95
- // Workspace configuration
96
- const workspacePath = agent.workspace || null
97
- if (workspacePath) {
98
- agentSection += `# WORKSPACE — ESPACIO DE TRABAJO EXCLUSIVO\n\n`
99
- agentSection += `**Tu directorio de trabajo es**: \`${workspacePath}\`\n\n`
100
- agentSection += `## REGLAS OBLIGATORIAS (no negociables)\n\n`
101
- agentSection += `1. **TODAS** tus operaciones de archivos y comandos ocurren DENTRO de \`${workspacePath}\`. Sin excepciones.\n`
102
- agentSection += `2. Cuando el sistema te pida listar archivos, explorar, leer o escribir — hazlo SIEMPRE dentro de \`${workspacePath}\`.\n`
103
- agentSection += `3. Nunca uses \`ls\`, \`find\`, \`cat\` u otras herramientas apuntando a directorios del sistema (\`/\`, \`~\`, \`/home\`, \`/etc\`, etc.).\n`
104
- agentSection += `4. Cuando uses \`cli_exec\`, el directorio de trabajo ya es \`${workspacePath}\` por defecto — NO necesitas especificar \`cwd\`.\n`
105
- agentSection += `5. Para rutas relativas, son relativas a \`${workspacePath}\` — no al directorio del proceso.\n`
106
- agentSection += `6. Si el usuario pide explorar "el proyecto" o "los archivos", asume que se refiere a \`${workspacePath}\`.\n`
107
- agentSection += `7. Las tools de filesystem (\`fs_read\`, \`fs_write\`, \`fs_list\`, etc.) ya tienen tu workspace configurado — úsalas directamente con rutas relativas.\n\n`
108
- agentSection += `> IMPORTANTE: Cualquier intento de acceder fuera de \`${workspacePath}\` será bloqueado automáticamente por el sistema.\n\n`
109
- }
110
-
111
- // System prompt específico del agente (su "personalidad" especializada)
112
- if (agent.system_prompt) {
113
- agentSection += `## System Prompt\n\n${agent.system_prompt}\n\n`
114
- }
115
-
116
-
117
- // ──────────────────────────────────────────────────────────────────────────
118
- // 3. IDENTIDAD DEL USUARIO
119
- // ──────────────────────────────────────────────────────────────────────────
120
- const user = db.query<any, [string]>(`
121
- SELECT id, name, language, timezone, occupation, notes
122
- FROM users
123
- WHERE id = ?
124
- `).get(userId)
125
-
126
- let userSection = `# IDENTIDAD DEL USUARIO\n\n`
127
-
128
- if (user) {
129
- const userData: Record<string, string | null> = {}
130
-
131
- if (user.name) userData.Nombre = user.name
132
- if (user.language) userData.Idioma = user.language
133
- if (user.timezone) userData.ZonaHoraria = user.timezone
134
- if (user.occupation) userData.Ocupación = user.occupation
135
- if (user.notes) userData.Notes = user.notes
136
-
137
- // Usar TOON para comprimir datos del usuario
138
- if (Object.keys(userData).length > 0) {
139
- userSection += formatContext(userData) + "\n\n"
140
- } else {
141
- userSection += `Usuario ID: ${userId}\n\n`
142
- }
143
- } else {
144
- userSection += `Usuario ID: ${userId}\n\n`
145
- }
146
-
147
- // ──────────────────────────────────────────────────────────────────────────
148
- // Ensamblar secciones en orden
149
- // ──────────────────────────────────────────────────────────────────────────
150
- const systemPrompt = `${ethicsSection}${agentSection}${userSection}`.trim()
151
-
152
- log.info(`[prompt-builder] Built system prompt for agent=${agent.name} role=${agent.role}`)
153
-
154
- return systemPrompt
155
- }
156
-
157
- /**
158
- * Versión simplificada para cuando solo se necesita el agentId
159
- * (usa userId por defecto de env o threadId)
160
- */
161
- export async function buildSystemPromptWithProjects(opts: {
162
- agentId: string
163
- userId?: string
164
- }): Promise<string> {
165
- const userId = opts.userId || resolveUserId({}) || "default"
166
- return buildSystemPrompt({ agentId: opts.agentId, userId })
167
- }
@@ -1,186 +0,0 @@
1
- /**
2
- * AgentRunner — thin wrapper over the native AgentLoop.
3
- *
4
- * Keeps the same public API (generate()) so server.ts doesn't need changes.
5
- * Internally uses agent-loop.ts instead of LangGraph.
6
- */
7
-
8
- import type { Config } from "../../config/loader.ts"
9
- import { logger } from "../../utils/logger.ts"
10
- import { getDb } from "../../storage/sqlite.ts"
11
- import { getAgentLoop } from "../agent-loop"
12
- import { resolveUserId, resolveAgentId } from "../../storage/onboarding"
13
-
14
- export type Provider = "openai" | "anthropic" | "gemini" | "mistral" | "kimi" | "ollama" | "openrouter" | "deepseek"
15
-
16
- export interface StepEvent {
17
- type: "text" | "plan" | "tool_call" | "tool_result"
18
- message: string
19
- toolName?: string
20
- isError?: boolean
21
- }
22
-
23
- export interface ModelOptions {
24
- provider?: Provider
25
- model?: string
26
- maxTokens?: number
27
- temperature?: number
28
- system?: string
29
- messages: Array<{ role: string; content: string }>
30
- tools?: Record<string, any>
31
- maxSteps?: number
32
- onToken?: (token: string) => void
33
- onStep?: (step: StepEvent) => Promise<void>
34
- threadId?: string
35
- userId?: string
36
- channel?: string
37
- rawUserMessage?: string
38
- }
39
-
40
- export interface ModelResponse {
41
- content: string
42
- toolCalls?: Array<{
43
- id: string
44
- name: string
45
- args: Record<string, unknown>
46
- }>
47
- usage?: {
48
- promptTokens: number
49
- completionTokens: number
50
- totalTokens: number
51
- }
52
- finishReason?: string
53
- }
54
-
55
- export class AgentRunner {
56
- private config: Config
57
-
58
- constructor(config: Config) {
59
- this.config = config
60
- }
61
-
62
- async generate(options: ModelOptions): Promise<ModelResponse> {
63
- const db = getDb()
64
- // Resolve agentId from database (coordinator or first enabled)
65
- const agentId = resolveAgentId(null) || "main"
66
-
67
- // Resolve userId from database
68
- const userId = options.userId || resolveUserId({})
69
- if (!userId) {
70
- throw new Error("No userId provided. Please complete onboarding first.")
71
- }
72
- const threadId = options.threadId || userId
73
-
74
- const agentLoop = getAgentLoop()
75
- if (!agentLoop) {
76
- throw new Error("AgentLoop not initialized")
77
- }
78
-
79
- let lastAgentContent = ""
80
- let accumulatedAgentContent = "" // Accumulate content from all agent chunks
81
- let toolCalls: ModelResponse["toolCalls"] = []
82
-
83
- try {
84
- const stream = agentLoop.stream(
85
- { messages: options.messages },
86
- {
87
- configurable: {
88
- thread_id: threadId,
89
- agent_id: agentId,
90
- user_id: userId,
91
- // system_prompt intentionally omitted — context-compiler builds it
92
- channel: options.channel,
93
- raw_user_message: options.rawUserMessage,
94
- },
95
- }
96
- )
97
-
98
- let chunkCount = 0
99
- for await (const chunk of stream) {
100
- chunkCount++
101
-
102
- if (chunk.agent?.messages) {
103
- const lastMsg = chunk.agent.messages[chunk.agent.messages.length - 1]
104
- const hasToolCalls = (lastMsg as any)?.tool_calls?.length > 0
105
- const contentLen = lastMsg?.content?.length ?? 0
106
- const contentType = typeof lastMsg?.content
107
- logger.info(
108
- `[STREAM] chunk#${chunkCount} agent: contentLen=${contentLen} hasToolCalls=${hasToolCalls} contentType=${contentType}`
109
- )
110
-
111
- if (lastMsg?.content) {
112
- const content = typeof lastMsg.content === "string" ? lastMsg.content : ""
113
- lastAgentContent = content
114
- // Accumulate non-empty content that's not just whitespace
115
- if (content && content.trim().length > 0) {
116
- accumulatedAgentContent += (accumulatedAgentContent ? "\n" : "") + content
117
- logger.debug(`[STREAM] Accumulated content: total length=${accumulatedAgentContent.length}`)
118
- } else {
119
- logger.debug(`[STREAM] Content empty or whitespace only, skipping accumulation`)
120
- }
121
- if (options.onToken) options.onToken(content)
122
- } else {
123
- logger.debug(`[STREAM] No content in chunk, lastMsg.content is falsy`)
124
- }
125
-
126
- if (hasToolCalls) {
127
- toolCalls = (lastMsg as any).tool_calls.map((tc: any) => ({
128
- id: tc.id || tc.function?.name,
129
- name: tc.function?.name || tc.name,
130
- args: tc.function?.arguments
131
- ? (typeof tc.function.arguments === "string"
132
- ? JSON.parse(tc.function.arguments)
133
- : tc.function.arguments)
134
- : {},
135
- }))
136
-
137
- const narration = lastMsg?.content || ""
138
- if (options.onStep && narration) {
139
- await options.onStep({ type: "text", message: narration })
140
- }
141
- if (options.onStep) {
142
- for (const tc of toolCalls) {
143
- await options.onStep({
144
- type: "tool_call",
145
- toolName: tc.name,
146
- message: `Calling tool: \`${tc.name}\``,
147
- })
148
- }
149
- }
150
- }
151
- }
152
-
153
- if (chunk.tools?.messages) {
154
- const lastMsg = chunk.tools.messages[chunk.tools.messages.length - 1]
155
- if (lastMsg?.content && options.onStep) {
156
- await options.onStep({
157
- type: "tool_result",
158
- message: typeof lastMsg.content === "string" ? lastMsg.content : "",
159
- })
160
- }
161
- }
162
- }
163
-
164
- logger.debug(`[STREAM] done. totalChunks=${chunkCount} lastAgentContent length=${lastAgentContent.length}, accumulated length=${accumulatedAgentContent.length}`)
165
-
166
- // Use accumulated content if lastAgentContent is empty (handles case where final chunk has no text)
167
- const finalContent = lastAgentContent || accumulatedAgentContent
168
-
169
- logger.info(`[STREAM] Returning response: finalContent length=${finalContent.length}, lastAgentContent length=${lastAgentContent.length}, accumulated length=${accumulatedAgentContent.length}`)
170
-
171
- return {
172
- content: finalContent,
173
- toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
174
- usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
175
- finishReason: "stop",
176
- }
177
- } catch (error) {
178
- logger.error("AgentRunner error:", error)
179
- throw error
180
- }
181
- }
182
- }
183
-
184
- export function createAgentRunner(config: Config): AgentRunner {
185
- return new AgentRunner(config)
186
- }
@@ -1 +0,0 @@
1
- export * from "./providers/index.ts";
@@ -1,200 +0,0 @@
1
- /**
2
- * ACE Reflector — analyzes recent traces and produces insights.
3
- *
4
- * Runs in the background (never blocks the main agent loop).
5
- * Triggered by the tracer after N new traces.
6
- *
7
- * Output → `reflections` table → picked up by Curator.
8
- */
9
-
10
- import { logger } from "../utils/logger"
11
-
12
- const log = logger.child("reflector")
13
-
14
- const MAX_TRACES_TO_ANALYZE = 30
15
- const MIN_TRACES_TO_RUN = 10
16
-
17
- /** Main entry point — called from tracer.ts */
18
- export async function runReflector(): Promise<void> {
19
- try {
20
- const { getDb } = await import("../storage/sqlite")
21
- const db = getDb()
22
-
23
- log.info(`[reflector] Starting reflection cycle...`)
24
-
25
- // Fetch traces not yet covered by any reflection
26
- log.debug(`[reflector] Querying last reflection ID...`)
27
- const lastReflectionId = (db.query<any, []>(
28
- "SELECT MAX(id) as mid FROM reflections"
29
- ).get() as any)?.mid ?? 0
30
- log.debug(`[reflector] Last reflection ID: ${lastReflectionId}`)
31
-
32
- // Get last processed trace ID from reflections
33
- log.debug(`[reflector] Querying last processed trace ID with json_each...`)
34
- let lastProcessedTrace = 0
35
- try {
36
- const result = (db.query<any, []>(
37
- `SELECT MAX(CAST(json_each.value AS INTEGER)) as max_id
38
- FROM reflections, json_each(reflections.trace_ids)
39
- WHERE reflections.id = (SELECT MAX(id) FROM reflections)`
40
- ).get() as any)?.max_id ?? 0
41
- lastProcessedTrace = result
42
- log.debug(`[reflector] Last processed trace ID: ${lastProcessedTrace}`)
43
- } catch (jsonErr) {
44
- log.error(`[reflector] json_each query failed:`, jsonErr)
45
- log.error(`[reflector] Full error details:`, {
46
- message: (jsonErr as Error).message,
47
- stack: (jsonErr as Error).stack,
48
- errno: (jsonErr as any).errno,
49
- byteOffset: (jsonErr as any).byteOffset,
50
- })
51
- throw jsonErr // Re-throw to see full stack trace in main catch
52
- }
53
-
54
- log.debug(`[reflector] Fetching traces from DB, lastProcessedTrace=${lastProcessedTrace}, limit=${MAX_TRACES_TO_ANALYZE}`)
55
- const traces = db.query<any, [number, number]>(`
56
- SELECT id, agent_id, agent_name, tool_used, input_summary,
57
- output_summary, success, error_message, duration_ms, tokens_used, created_at
58
- FROM traces
59
- WHERE id > ?
60
- ORDER BY id ASC
61
- LIMIT ?
62
- `).all(lastProcessedTrace, MAX_TRACES_TO_ANALYZE)
63
-
64
- log.debug(`[reflector] Fetched ${traces.length} traces from DB`)
65
-
66
- if (traces.length < MIN_TRACES_TO_RUN) {
67
- log.debug(`[reflector] Not enough traces (${traces.length}/${MIN_TRACES_TO_RUN}), skipping`)
68
- return
69
- }
70
-
71
- log.info(`[reflector] Analyzing ${traces.length} traces...`)
72
-
73
- const insights = analyzeTracesLocally(traces)
74
-
75
- if (insights.length === 0) {
76
- log.debug("[reflector] No insights generated")
77
- return
78
- }
79
-
80
- const traceIds = JSON.stringify(traces.map((t: any) => t.id))
81
-
82
- for (const insight of insights) {
83
- db.query(`
84
- INSERT INTO reflections (trace_ids, insight_type, description, affected_tools, affected_agents, confidence)
85
- VALUES (?, ?, ?, ?, ?, ?)
86
- `).run(
87
- traceIds,
88
- insight.type,
89
- insight.description,
90
- insight.affectedTools ? JSON.stringify(insight.affectedTools) : null,
91
- insight.affectedAgents ? JSON.stringify(insight.affectedAgents) : null,
92
- insight.confidence,
93
- )
94
- }
95
-
96
- log.info(`[reflector] Generated ${insights.length} insights`)
97
-
98
- // Trigger curator
99
- const { runCurator } = await import("./curator")
100
- await runCurator()
101
-
102
- log.info(`[reflector] Reflection cycle completed successfully`)
103
- } catch (err) {
104
- log.error(`[reflector] Error during reflection:`, {
105
- message: (err as Error).message,
106
- stack: (err as Error).stack,
107
- errno: (err as any).errno,
108
- byteOffset: (err as any).byteOffset,
109
- code: (err as any).code,
110
- })
111
- }
112
- }
113
-
114
- // ─── Local analysis (heuristic, no LLM call needed for basic patterns) ────────
115
-
116
- interface Insight {
117
- type: "success_pattern" | "failure_pattern" | "optimization" | "ethics_violation"
118
- description: string
119
- affectedTools?: string[]
120
- affectedAgents?: string[]
121
- confidence: number
122
- }
123
-
124
- function analyzeTracesLocally(traces: any[]): Insight[] {
125
- const insights: Insight[] = []
126
-
127
- // ── Failure patterns ─────────────────────────────────────────────────────
128
- const failures = traces.filter((t: any) => !t.success)
129
- if (failures.length > 3) {
130
- // Group by tool
131
- const toolFailures: Record<string, number> = {}
132
- for (const f of failures) {
133
- if (f.tool_used) {
134
- toolFailures[f.tool_used] = (toolFailures[f.tool_used] || 0) + 1
135
- }
136
- }
137
- for (const [tool, count] of Object.entries(toolFailures)) {
138
- if (count >= 3) {
139
- insights.push({
140
- type: "failure_pattern",
141
- description: `Tool '${tool}' failed ${count} times recently. Consider verifying its configuration or avoiding it for this type of task.`,
142
- affectedTools: [tool],
143
- confidence: Math.min(0.9, count / 10),
144
- })
145
- }
146
- }
147
- }
148
-
149
- // ── Slow tools ───────────────────────────────────────────────────────────
150
- const slowThresholdMs = 5000
151
- const slowTools: Record<string, number[]> = {}
152
- for (const t of traces) {
153
- if (t.tool_used && t.duration_ms > slowThresholdMs) {
154
- if (!slowTools[t.tool_used]) slowTools[t.tool_used] = []
155
- slowTools[t.tool_used].push(t.duration_ms)
156
- }
157
- }
158
- for (const [tool, durations] of Object.entries(slowTools)) {
159
- if (durations.length >= 3) {
160
- const avg = Math.round(durations.reduce((a, b) => a + b, 0) / durations.length)
161
- insights.push({
162
- type: "optimization",
163
- description: `Tool '${tool}' is consistently slow (avg ${avg}ms). Cache results when possible or use a faster alternative.`,
164
- affectedTools: [tool],
165
- confidence: 0.6,
166
- })
167
- }
168
- }
169
-
170
- // ── High success pattern ─────────────────────────────────────────────────
171
- const successByTool: Record<string, { ok: number; total: number }> = {}
172
- for (const t of traces) {
173
- if (!t.tool_used) continue
174
- if (!successByTool[t.tool_used]) successByTool[t.tool_used] = { ok: 0, total: 0 }
175
- successByTool[t.tool_used].total++
176
- if (t.success) successByTool[t.tool_used].ok++
177
- }
178
- for (const [tool, stats] of Object.entries(successByTool)) {
179
- if (stats.total >= 5 && stats.ok / stats.total >= 0.9) {
180
- insights.push({
181
- type: "success_pattern",
182
- description: `Tool '${tool}' has a high success rate (${stats.ok}/${stats.total}). Prefer it for related tasks.`,
183
- affectedTools: [tool],
184
- confidence: stats.ok / stats.total,
185
- })
186
- }
187
- }
188
-
189
- // ── High token usage ─────────────────────────────────────────────────────
190
- const highTokenTraces = traces.filter((t: any) => t.tokens_used > 4000)
191
- if (highTokenTraces.length > 3) {
192
- insights.push({
193
- type: "optimization",
194
- description: `${highTokenTraces.length} recent calls used >4000 tokens. Be more concise and use tool results as summaries, not raw dumps.`,
195
- confidence: 0.7,
196
- })
197
- }
198
-
199
- return insights
200
- }