@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.
- package/README.md +178 -36
- package/dist/hive.js +315124 -0
- package/package.json +11 -3
- package/packages/core/src/index.ts +0 -1
- package/.dockerignore +0 -9
- package/CONTRIBUTING.md +0 -44
- package/Dockerfile +0 -67
- package/docker-compose.yml +0 -19
- package/packages/cli/package.json +0 -28
- package/packages/cli/src/commands/agent-run.ts +0 -168
- package/packages/cli/src/commands/agents.ts +0 -398
- package/packages/cli/src/commands/chat.ts +0 -142
- package/packages/cli/src/commands/config.ts +0 -50
- package/packages/cli/src/commands/cron.ts +0 -161
- package/packages/cli/src/commands/dev.ts +0 -95
- package/packages/cli/src/commands/doctor.ts +0 -133
- package/packages/cli/src/commands/gateway.ts +0 -422
- package/packages/cli/src/commands/logs.ts +0 -57
- package/packages/cli/src/commands/mcp.ts +0 -175
- package/packages/cli/src/commands/message.ts +0 -77
- package/packages/cli/src/commands/onboard.ts +0 -1696
- package/packages/cli/src/commands/security.ts +0 -144
- package/packages/cli/src/commands/service.ts +0 -50
- package/packages/cli/src/commands/sessions.ts +0 -116
- package/packages/cli/src/commands/skills.ts +0 -187
- package/packages/cli/src/commands/update.ts +0 -25
- package/packages/cli/src/index.ts +0 -190
- package/packages/cli/src/utils/token.ts +0 -6
- package/packages/code-bridge/README.md +0 -78
- package/packages/code-bridge/package.json +0 -18
- package/packages/code-bridge/src/index.ts +0 -95
- package/packages/code-bridge/src/process-manager.ts +0 -212
- package/packages/code-bridge/src/schemas.ts +0 -133
- package/packages/core/package.json +0 -55
- package/packages/core/src/agent/agent-loop.ts +0 -520
- package/packages/core/src/agent/compaction.ts +0 -183
- package/packages/core/src/agent/context-compiler.ts +0 -544
- package/packages/core/src/agent/context-guard.ts +0 -91
- package/packages/core/src/agent/conversation-store.ts +0 -193
- package/packages/core/src/agent/curator.ts +0 -158
- package/packages/core/src/agent/hooks.ts +0 -166
- package/packages/core/src/agent/llm-client.ts +0 -503
- package/packages/core/src/agent/native-tools.ts +0 -31
- package/packages/core/src/agent/playbook-selector.ts +0 -143
- package/packages/core/src/agent/prompt-builder.ts +0 -167
- package/packages/core/src/agent/providers/index.ts +0 -186
- package/packages/core/src/agent/providers.ts +0 -1
- package/packages/core/src/agent/reflector.ts +0 -200
- package/packages/core/src/agent/service.ts +0 -266
- package/packages/core/src/agent/skill-selector.ts +0 -413
- package/packages/core/src/agent/stuck-loop.ts +0 -133
- package/packages/core/src/agent/tool-selector.ts +0 -623
- package/packages/core/src/agent/tracer.ts +0 -102
- package/packages/core/src/canvas/canvas-manager.ts +0 -319
- package/packages/core/src/canvas/canvas-tools.ts +0 -420
- package/packages/core/src/canvas/emitter.ts +0 -119
- package/packages/core/src/canvas/index.ts +0 -2
- package/packages/core/src/channels/base.ts +0 -140
- package/packages/core/src/channels/discord.ts +0 -260
- package/packages/core/src/channels/index.ts +0 -7
- package/packages/core/src/channels/manager.ts +0 -383
- package/packages/core/src/channels/slack.ts +0 -287
- package/packages/core/src/channels/telegram.ts +0 -552
- package/packages/core/src/channels/webchat.ts +0 -139
- package/packages/core/src/channels/whatsapp.ts +0 -375
- package/packages/core/src/config/index.ts +0 -12
- package/packages/core/src/config/loader.ts +0 -529
- package/packages/core/src/events/agent-bus.ts +0 -460
- package/packages/core/src/events/event-bus.ts +0 -169
- package/packages/core/src/gateway/helpers/cors.ts +0 -32
- package/packages/core/src/gateway/helpers/index.ts +0 -4
- package/packages/core/src/gateway/helpers/narration.ts +0 -60
- package/packages/core/src/gateway/helpers/path.ts +0 -13
- package/packages/core/src/gateway/helpers/redact.ts +0 -61
- package/packages/core/src/gateway/index.ts +0 -5
- package/packages/core/src/gateway/initializer.ts +0 -332
- package/packages/core/src/gateway/lane-queue.ts +0 -169
- package/packages/core/src/gateway/resolver.ts +0 -108
- package/packages/core/src/gateway/router.ts +0 -124
- package/packages/core/src/gateway/routes/agents.ts +0 -187
- package/packages/core/src/gateway/routes/channels.ts +0 -203
- package/packages/core/src/gateway/routes/chat.ts +0 -241
- package/packages/core/src/gateway/routes/config.ts +0 -12
- package/packages/core/src/gateway/routes/cron.ts +0 -42
- package/packages/core/src/gateway/routes/ethics.ts +0 -46
- package/packages/core/src/gateway/routes/mcp.ts +0 -346
- package/packages/core/src/gateway/routes/models.ts +0 -93
- package/packages/core/src/gateway/routes/projects.ts +0 -179
- package/packages/core/src/gateway/routes/providers.ts +0 -192
- package/packages/core/src/gateway/routes/setup.ts +0 -267
- package/packages/core/src/gateway/routes/skills.ts +0 -70
- package/packages/core/src/gateway/routes/system.ts +0 -165
- package/packages/core/src/gateway/routes/tasks.ts +0 -44
- package/packages/core/src/gateway/routes/tools.ts +0 -35
- package/packages/core/src/gateway/routes/users.ts +0 -118
- package/packages/core/src/gateway/routes/voice.ts +0 -73
- package/packages/core/src/gateway/routes/workspace.ts +0 -281
- package/packages/core/src/gateway/server.ts +0 -1978
- package/packages/core/src/gateway/session.ts +0 -95
- package/packages/core/src/gateway/slash-commands.ts +0 -193
- package/packages/core/src/heartbeat/index.ts +0 -157
- package/packages/core/src/mcp/hot-reload.ts +0 -213
- package/packages/core/src/mcp/singleton.ts +0 -21
- package/packages/core/src/memory/index.ts +0 -1
- package/packages/core/src/memory/notes.ts +0 -68
- package/packages/core/src/plugins/api.ts +0 -128
- package/packages/core/src/plugins/index.ts +0 -2
- package/packages/core/src/plugins/loader.ts +0 -365
- package/packages/core/src/resilience/circuit-breaker.ts +0 -225
- package/packages/core/src/security/google-chat.ts +0 -269
- package/packages/core/src/security/index.ts +0 -192
- package/packages/core/src/security/pairing.ts +0 -250
- package/packages/core/src/security/rate-limit.ts +0 -270
- package/packages/core/src/security/signal.ts +0 -321
- package/packages/core/src/state/store.ts +0 -312
- package/packages/core/src/storage/crypto.ts +0 -101
- package/packages/core/src/storage/onboarding.ts +0 -1609
- package/packages/core/src/storage/schema.ts +0 -567
- package/packages/core/src/storage/seed.ts +0 -608
- package/packages/core/src/storage/sqlite.ts +0 -363
- package/packages/core/src/storage/usage.ts +0 -270
- package/packages/core/src/tools/agents/index.ts +0 -607
- package/packages/core/src/tools/bridge-events.ts +0 -26
- package/packages/core/src/tools/canvas/index.ts +0 -281
- package/packages/core/src/tools/cli/index.ts +0 -142
- package/packages/core/src/tools/codebridge/index.ts +0 -179
- package/packages/core/src/tools/core/index.ts +0 -257
- package/packages/core/src/tools/cron/index.ts +0 -373
- package/packages/core/src/tools/filesystem/fs-delete.ts +0 -78
- package/packages/core/src/tools/filesystem/fs-edit.ts +0 -106
- package/packages/core/src/tools/filesystem/fs-exists.ts +0 -63
- package/packages/core/src/tools/filesystem/fs-glob.ts +0 -108
- package/packages/core/src/tools/filesystem/fs-list.ts +0 -129
- package/packages/core/src/tools/filesystem/fs-read.ts +0 -72
- package/packages/core/src/tools/filesystem/fs-write.ts +0 -67
- package/packages/core/src/tools/filesystem/index.ts +0 -34
- package/packages/core/src/tools/filesystem/workspace-guard.ts +0 -62
- package/packages/core/src/tools/index.ts +0 -197
- package/packages/core/src/tools/projects/index.ts +0 -37
- package/packages/core/src/tools/projects/project-create.ts +0 -94
- package/packages/core/src/tools/projects/project-done.ts +0 -66
- package/packages/core/src/tools/projects/project-fail.ts +0 -66
- package/packages/core/src/tools/projects/project-list.ts +0 -96
- package/packages/core/src/tools/projects/project-update.ts +0 -72
- package/packages/core/src/tools/projects/task-create.ts +0 -68
- package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
- package/packages/core/src/tools/projects/task-update.ts +0 -93
- package/packages/core/src/tools/search-knowledge/search-knowledge.ts +0 -155
- package/packages/core/src/tools/types.ts +0 -39
- package/packages/core/src/tools/voice/index.ts +0 -104
- package/packages/core/src/tools/web/browser-click.ts +0 -54
- package/packages/core/src/tools/web/browser-navigate.ts +0 -84
- package/packages/core/src/tools/web/browser-screenshot.ts +0 -54
- package/packages/core/src/tools/web/browser-type.ts +0 -60
- package/packages/core/src/tools/web/index.ts +0 -31
- package/packages/core/src/tools/web/web-fetch.ts +0 -78
- package/packages/core/src/tools/web/web-search.ts +0 -123
- package/packages/core/src/utils/benchmark.ts +0 -80
- package/packages/core/src/utils/crypto.ts +0 -73
- package/packages/core/src/utils/date.ts +0 -42
- package/packages/core/src/utils/index.ts +0 -5
- package/packages/core/src/utils/logger.ts +0 -389
- package/packages/core/src/utils/retry.ts +0 -70
- package/packages/core/src/utils/toon.ts +0 -356
- package/packages/core/src/voice/index.ts +0 -583
- package/packages/hive-ui/README.md +0 -52
- package/packages/hive-ui/components.json +0 -20
- package/packages/hive-ui/index.html +0 -30
- package/packages/hive-ui/package.json +0 -90
- package/packages/hive-ui/public/favicon.ico +0 -0
- package/packages/hive-ui/public/placeholder.svg +0 -1
- package/packages/hive-ui/src/App.tsx +0 -115
- package/packages/hive-ui/src/components/CronJobsPanel.tsx +0 -200
- package/packages/hive-ui/src/components/NavLink.tsx +0 -34
- package/packages/hive-ui/src/components/NotesPanel.tsx +0 -79
- package/packages/hive-ui/src/components/SystemMonitor.tsx +0 -270
- package/packages/hive-ui/src/components/UsageStatsPanel.tsx +0 -334
- package/packages/hive-ui/src/components/WelcomeDialog.tsx +0 -279
- package/packages/hive-ui/src/components/ui/accordion.tsx +0 -52
- package/packages/hive-ui/src/components/ui/alert-dialog.tsx +0 -104
- package/packages/hive-ui/src/components/ui/alert.tsx +0 -45
- package/packages/hive-ui/src/components/ui/aspect-ratio.tsx +0 -5
- package/packages/hive-ui/src/components/ui/avatar.tsx +0 -38
- package/packages/hive-ui/src/components/ui/badge.tsx +0 -29
- package/packages/hive-ui/src/components/ui/bee-loader.tsx +0 -68
- package/packages/hive-ui/src/components/ui/breadcrumb.tsx +0 -90
- package/packages/hive-ui/src/components/ui/button.tsx +0 -47
- package/packages/hive-ui/src/components/ui/calendar.tsx +0 -54
- package/packages/hive-ui/src/components/ui/card.tsx +0 -45
- package/packages/hive-ui/src/components/ui/carousel.tsx +0 -224
- package/packages/hive-ui/src/components/ui/chart.tsx +0 -303
- package/packages/hive-ui/src/components/ui/checkbox.tsx +0 -26
- package/packages/hive-ui/src/components/ui/collapsible.tsx +0 -9
- package/packages/hive-ui/src/components/ui/command.tsx +0 -133
- package/packages/hive-ui/src/components/ui/context-menu.tsx +0 -178
- package/packages/hive-ui/src/components/ui/dialog.tsx +0 -95
- package/packages/hive-ui/src/components/ui/drawer.tsx +0 -87
- package/packages/hive-ui/src/components/ui/dropdown-menu.tsx +0 -179
- package/packages/hive-ui/src/components/ui/form.tsx +0 -129
- package/packages/hive-ui/src/components/ui/hover-card.tsx +0 -27
- package/packages/hive-ui/src/components/ui/input-otp.tsx +0 -61
- package/packages/hive-ui/src/components/ui/input.tsx +0 -22
- package/packages/hive-ui/src/components/ui/label.tsx +0 -17
- package/packages/hive-ui/src/components/ui/menubar.tsx +0 -207
- package/packages/hive-ui/src/components/ui/navigation-menu.tsx +0 -120
- package/packages/hive-ui/src/components/ui/pagination.tsx +0 -80
- package/packages/hive-ui/src/components/ui/popover.tsx +0 -29
- package/packages/hive-ui/src/components/ui/progress.tsx +0 -23
- package/packages/hive-ui/src/components/ui/radio-group.tsx +0 -36
- package/packages/hive-ui/src/components/ui/resizable.tsx +0 -37
- package/packages/hive-ui/src/components/ui/scroll-area.tsx +0 -38
- package/packages/hive-ui/src/components/ui/select.tsx +0 -143
- package/packages/hive-ui/src/components/ui/separator.tsx +0 -20
- package/packages/hive-ui/src/components/ui/sheet.tsx +0 -107
- package/packages/hive-ui/src/components/ui/sidebar.tsx +0 -636
- package/packages/hive-ui/src/components/ui/skeleton.tsx +0 -7
- package/packages/hive-ui/src/components/ui/slider.tsx +0 -23
- package/packages/hive-ui/src/components/ui/sonner.tsx +0 -27
- package/packages/hive-ui/src/components/ui/switch.tsx +0 -27
- package/packages/hive-ui/src/components/ui/table.tsx +0 -72
- package/packages/hive-ui/src/components/ui/tabs.tsx +0 -53
- package/packages/hive-ui/src/components/ui/textarea.tsx +0 -21
- package/packages/hive-ui/src/components/ui/toast.tsx +0 -111
- package/packages/hive-ui/src/components/ui/toaster.tsx +0 -24
- package/packages/hive-ui/src/components/ui/toggle-group.tsx +0 -49
- package/packages/hive-ui/src/components/ui/toggle.tsx +0 -37
- package/packages/hive-ui/src/components/ui/tooltip.tsx +0 -28
- package/packages/hive-ui/src/components/ui/use-toast.ts +0 -3
- package/packages/hive-ui/src/hooks/use-mobile.tsx +0 -19
- package/packages/hive-ui/src/hooks/use-toast.ts +0 -186
- package/packages/hive-ui/src/hooks/useAgentConfig.ts +0 -25
- package/packages/hive-ui/src/hooks/useAgents.ts +0 -38
- package/packages/hive-ui/src/hooks/useBridge.ts +0 -38
- package/packages/hive-ui/src/hooks/useCanvas.ts +0 -24
- package/packages/hive-ui/src/hooks/useChannels.ts +0 -2
- package/packages/hive-ui/src/hooks/useEthics.ts +0 -51
- package/packages/hive-ui/src/hooks/useProviders.ts +0 -14
- package/packages/hive-ui/src/hooks/useTheme.ts +0 -29
- package/packages/hive-ui/src/hooks/useUserConfig.ts +0 -17
- package/packages/hive-ui/src/hooks/useWebSocket.ts +0 -12
- package/packages/hive-ui/src/index.css +0 -620
- package/packages/hive-ui/src/lib/api.ts +0 -100
- package/packages/hive-ui/src/lib/constants.ts +0 -6
- package/packages/hive-ui/src/lib/models.ts +0 -64
- package/packages/hive-ui/src/lib/swal.ts +0 -30
- package/packages/hive-ui/src/lib/utils.ts +0 -6
- package/packages/hive-ui/src/lib/websocket.ts +0 -7
- package/packages/hive-ui/src/main.tsx +0 -5
- package/packages/hive-ui/src/modules/agent-config/details/AgentDetailsEditor.tsx +0 -524
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsConflictDetector.tsx +0 -18
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsEditor.tsx +0 -19
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsRulesList.tsx +0 -36
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsTemplateGallery.tsx +0 -361
- package/packages/hive-ui/src/modules/agent-config/ethics/index.ts +0 -4
- package/packages/hive-ui/src/modules/agent-config/index.ts +0 -6
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerAdd.tsx +0 -322
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerCard.tsx +0 -93
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerConfig.tsx +0 -427
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerList.tsx +0 -85
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPToolExplorer.tsx +0 -79
- package/packages/hive-ui/src/modules/agent-config/mcp/index.ts +0 -5
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigEditorLayout.tsx +0 -30
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigExporter.tsx +0 -26
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigImporter.tsx +0 -25
- package/packages/hive-ui/src/modules/agent-config/shared/DiffViewer.tsx +0 -31
- package/packages/hive-ui/src/modules/agent-config/shared/MarkdownEditor.tsx +0 -32
- package/packages/hive-ui/src/modules/agent-config/shared/SaveStatusIndicator.tsx +0 -23
- package/packages/hive-ui/src/modules/agent-config/shared/ValidationPanel.tsx +0 -36
- package/packages/hive-ui/src/modules/agent-config/shared/index.ts +0 -7
- package/packages/hive-ui/src/modules/agent-config/skills/SkillCard.tsx +0 -81
- package/packages/hive-ui/src/modules/agent-config/skills/SkillConfigEditor.tsx +0 -22
- package/packages/hive-ui/src/modules/agent-config/skills/SkillCreator.tsx +0 -60
- package/packages/hive-ui/src/modules/agent-config/skills/SkillInstaller.tsx +0 -23
- package/packages/hive-ui/src/modules/agent-config/skills/SkillList.tsx +0 -72
- package/packages/hive-ui/src/modules/agent-config/skills/SkillsTab.tsx +0 -202
- package/packages/hive-ui/src/modules/agent-config/skills/index.ts +0 -5
- package/packages/hive-ui/src/modules/agent-config/tools/ToolCard.tsx +0 -27
- package/packages/hive-ui/src/modules/agent-config/tools/ToolConfigPanel.tsx +0 -22
- package/packages/hive-ui/src/modules/agent-config/tools/ToolManager.tsx +0 -266
- package/packages/hive-ui/src/modules/agent-config/tools/ToolPermissions.tsx +0 -287
- package/packages/hive-ui/src/modules/agent-config/tools/ToolRegistry.tsx +0 -84
- package/packages/hive-ui/src/modules/agent-config/tools/ToolUsageStats.tsx +0 -52
- package/packages/hive-ui/src/modules/agent-config/tools/index.ts +0 -4
- package/packages/hive-ui/src/modules/agent-config/user/ActiveAgentsList.tsx +0 -109
- package/packages/hive-ui/src/modules/agent-config/user/GlobalConfigOverview.tsx +0 -119
- package/packages/hive-ui/src/modules/agent-config/user/UserMemoryManager.tsx +0 -54
- package/packages/hive-ui/src/modules/agent-config/user/UserPreferencesForm.tsx +0 -163
- package/packages/hive-ui/src/modules/agent-config/user/UserProfileEditor.tsx +0 -261
- package/packages/hive-ui/src/modules/agent-config/user/index.ts +0 -3
- package/packages/hive-ui/src/modules/agents/AgentActivityLog.tsx +0 -25
- package/packages/hive-ui/src/modules/agents/AgentCard.tsx +0 -305
- package/packages/hive-ui/src/modules/agents/AgentCreateForm.tsx +0 -446
- package/packages/hive-ui/src/modules/agents/AgentDetail.tsx +0 -28
- package/packages/hive-ui/src/modules/agents/AgentInternalCard.tsx +0 -162
- package/packages/hive-ui/src/modules/agents/AgentList.tsx +0 -29
- package/packages/hive-ui/src/modules/agents/AgentStatusBadge.tsx +0 -34
- package/packages/hive-ui/src/modules/agents/ModelSelector.tsx +0 -151
- package/packages/hive-ui/src/modules/bridge/BridgeLogViewer.tsx +0 -61
- package/packages/hive-ui/src/modules/bridge/BridgeProcessList.tsx +0 -77
- package/packages/hive-ui/src/modules/bridge/BridgeStatus.tsx +0 -23
- package/packages/hive-ui/src/modules/bridge/BridgeTerminal.tsx +0 -7
- package/packages/hive-ui/src/modules/canvas/CanvasButton.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasChart.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasComponentMap.tsx +0 -605
- package/packages/hive-ui/src/modules/canvas/CanvasContainer.tsx +0 -360
- package/packages/hive-ui/src/modules/canvas/CanvasForm.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasMarkdown.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasTable.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/ComponentRenderer.tsx +0 -30
- package/packages/hive-ui/src/modules/canvas/DynamicRenderer.tsx +0 -3
- package/packages/hive-ui/src/modules/channels/available/AvailableChannelsGrid.tsx +0 -89
- package/packages/hive-ui/src/modules/channels/available/ChannelAuthForm.tsx +0 -33
- package/packages/hive-ui/src/modules/channels/available/ChannelSetupWizard.tsx +0 -48
- package/packages/hive-ui/src/modules/channels/available/ChannelTestConnection.tsx +0 -37
- package/packages/hive-ui/src/modules/channels/available/ChannelTypeCard.tsx +0 -30
- package/packages/hive-ui/src/modules/channels/available/ChannelWebhookConfig.tsx +0 -30
- package/packages/hive-ui/src/modules/channels/available/index.ts +0 -6
- package/packages/hive-ui/src/modules/channels/connected/ChannelCard.tsx +0 -95
- package/packages/hive-ui/src/modules/channels/connected/ChannelConfigPanel.tsx +0 -260
- package/packages/hive-ui/src/modules/channels/connected/ChannelDisconnectButton.tsx +0 -21
- package/packages/hive-ui/src/modules/channels/connected/ChannelLogsViewer.tsx +0 -42
- package/packages/hive-ui/src/modules/channels/connected/ChannelQRCode.tsx +0 -32
- package/packages/hive-ui/src/modules/channels/connected/ChannelReconnectButton.tsx +0 -16
- package/packages/hive-ui/src/modules/channels/connected/ChannelStatusBadge.tsx +0 -26
- package/packages/hive-ui/src/modules/channels/connected/ConnectedChannelsList.tsx +0 -40
- package/packages/hive-ui/src/modules/channels/connected/index.ts +0 -8
- package/packages/hive-ui/src/modules/channels/shared/ChannelCard.tsx +0 -84
- package/packages/hive-ui/src/modules/channels/shared/ChannelConfigDialog.tsx +0 -279
- package/packages/hive-ui/src/modules/channels/shared/ChannelIcon.tsx +0 -40
- package/packages/hive-ui/src/modules/channels/shared/ChannelStats.tsx +0 -37
- package/packages/hive-ui/src/modules/channels/shared/ChannelTypeBadge.tsx +0 -23
- package/packages/hive-ui/src/modules/channels/shared/ConnectionHealthIndicator.tsx +0 -20
- package/packages/hive-ui/src/modules/channels/shared/MessagePreview.tsx +0 -19
- package/packages/hive-ui/src/modules/channels/shared/index.ts +0 -5
- package/packages/hive-ui/src/modules/chat/ChatContainer.tsx +0 -268
- package/packages/hive-ui/src/modules/chat/ChatHistory.tsx +0 -101
- package/packages/hive-ui/src/modules/chat/ChatInput.tsx +0 -108
- package/packages/hive-ui/src/modules/chat/ChatMessage.tsx +0 -137
- package/packages/hive-ui/src/modules/chat/ThinkingIndicator.tsx +0 -10
- package/packages/hive-ui/src/modules/layout/AppLayout.tsx +0 -45
- package/packages/hive-ui/src/modules/layout/ConnectionStatus.tsx +0 -19
- package/packages/hive-ui/src/modules/layout/Header.tsx +0 -20
- package/packages/hive-ui/src/modules/layout/HiveSidebar.tsx +0 -173
- package/packages/hive-ui/src/modules/layout/ThemeToggle.tsx +0 -18
- package/packages/hive-ui/src/modules/providers/ProviderCard.tsx +0 -319
- package/packages/hive-ui/src/modules/providers/ProviderConfigForm.tsx +0 -146
- package/packages/hive-ui/src/modules/providers/ProviderFailoverConfig.tsx +0 -110
- package/packages/hive-ui/src/modules/providers/ProviderList.tsx +0 -33
- package/packages/hive-ui/src/modules/providers/ProviderStatusIndicator.tsx +0 -23
- package/packages/hive-ui/src/modules/providers/configs/ProviderAPIKeyManager.tsx +0 -39
- package/packages/hive-ui/src/modules/providers/configs/ProviderEndpointConfig.tsx +0 -27
- package/packages/hive-ui/src/modules/providers/configs/ProviderRateLimits.tsx +0 -37
- package/packages/hive-ui/src/modules/providers/configs/ProviderRetryPolicy.tsx +0 -46
- package/packages/hive-ui/src/modules/providers/configs/index.ts +0 -4
- package/packages/hive-ui/src/modules/providers/index.ts +0 -5
- package/packages/hive-ui/src/modules/providers/models/ModelBenchmarkBadge.tsx +0 -21
- package/packages/hive-ui/src/modules/providers/models/ModelCapabilities.tsx +0 -44
- package/packages/hive-ui/src/modules/providers/models/ModelCard.tsx +0 -36
- package/packages/hive-ui/src/modules/providers/models/ModelComparisonTable.tsx +0 -47
- package/packages/hive-ui/src/modules/providers/models/ModelList.tsx +0 -51
- package/packages/hive-ui/src/modules/providers/models/ModelPricingInfo.tsx +0 -17
- package/packages/hive-ui/src/modules/providers/models/ModelSelector.tsx +0 -32
- package/packages/hive-ui/src/modules/providers/models/index.ts +0 -7
- package/packages/hive-ui/src/pages/AgentDetailPage.tsx +0 -74
- package/packages/hive-ui/src/pages/AgentNewPage.tsx +0 -5
- package/packages/hive-ui/src/pages/AgentsPage.tsx +0 -147
- package/packages/hive-ui/src/pages/BridgePage.tsx +0 -83
- package/packages/hive-ui/src/pages/CanvasPage.tsx +0 -32
- package/packages/hive-ui/src/pages/ChannelsPage.tsx +0 -176
- package/packages/hive-ui/src/pages/DashboardPage.tsx +0 -321
- package/packages/hive-ui/src/pages/Index.tsx +0 -14
- package/packages/hive-ui/src/pages/LogsPage.tsx +0 -252
- package/packages/hive-ui/src/pages/NotFound.tsx +0 -24
- package/packages/hive-ui/src/pages/ProjectsPage.tsx +0 -241
- package/packages/hive-ui/src/pages/ProvidersPage.tsx +0 -111
- package/packages/hive-ui/src/pages/SettingsPage.tsx +0 -147
- package/packages/hive-ui/src/pages/SetupPage.tsx +0 -1177
- package/packages/hive-ui/src/pages/WebChatPage.tsx +0 -15
- package/packages/hive-ui/src/stores/agentConfigStore.ts +0 -32
- package/packages/hive-ui/src/stores/agentStore.ts +0 -5
- package/packages/hive-ui/src/stores/bridgeStore.ts +0 -237
- package/packages/hive-ui/src/stores/canvasStore.ts +0 -250
- package/packages/hive-ui/src/stores/channelStore.ts +0 -5
- package/packages/hive-ui/src/stores/chatStore.ts +0 -42
- package/packages/hive-ui/src/stores/ethicsStore.ts +0 -141
- package/packages/hive-ui/src/stores/mcpStore.ts +0 -5
- package/packages/hive-ui/src/stores/modelStore.ts +0 -2
- package/packages/hive-ui/src/stores/projectsStore.ts +0 -141
- package/packages/hive-ui/src/stores/providerStore.ts +0 -2
- package/packages/hive-ui/src/stores/skillStore.ts +0 -5
- package/packages/hive-ui/src/stores/toolStore.ts +0 -5
- package/packages/hive-ui/src/stores/useGlobalConfigStore.ts +0 -937
- package/packages/hive-ui/src/stores/useLoaderStore.ts +0 -21
- package/packages/hive-ui/src/stores/useNotesAndCronsStore.ts +0 -144
- package/packages/hive-ui/src/stores/useWebSocketStore.ts +0 -152
- package/packages/hive-ui/src/stores/useWelcomeStore.ts +0 -37
- package/packages/hive-ui/src/stores/userConfigStore.ts +0 -23
- package/packages/hive-ui/src/stores/userStore.ts +0 -82
- package/packages/hive-ui/src/test/setup.ts +0 -15
- package/packages/hive-ui/src/types/agent-config.ts +0 -33
- package/packages/hive-ui/src/types/agent.ts +0 -65
- package/packages/hive-ui/src/types/bridge.ts +0 -27
- package/packages/hive-ui/src/types/canvas.ts +0 -76
- package/packages/hive-ui/src/types/channels.ts +0 -109
- package/packages/hive-ui/src/types/chat.ts +0 -25
- package/packages/hive-ui/src/types/connections.ts +0 -17
- package/packages/hive-ui/src/types/ethics.ts +0 -41
- package/packages/hive-ui/src/types/index.ts +0 -15
- package/packages/hive-ui/src/types/mcp.ts +0 -36
- package/packages/hive-ui/src/types/notes-crons.ts +0 -31
- package/packages/hive-ui/src/types/providers.ts +0 -145
- package/packages/hive-ui/src/types/skill.ts +0 -12
- package/packages/hive-ui/src/types/tool.ts +0 -44
- package/packages/hive-ui/src/types/user.ts +0 -26
- package/packages/hive-ui/src/types/websocket.ts +0 -14
- package/packages/hive-ui/src/vite-env.d.ts +0 -1
- package/packages/mcp/package.json +0 -26
- package/packages/mcp/src/config.ts +0 -13
- package/packages/mcp/src/index.ts +0 -1
- package/packages/mcp/src/logger.ts +0 -42
- package/packages/mcp/src/manager.ts +0 -439
- package/packages/mcp/src/transports/index.ts +0 -67
- package/packages/mcp/src/transports/sse.ts +0 -241
- package/packages/mcp/src/transports/websocket.ts +0 -159
- package/packages/skills/package.json +0 -21
- package/packages/skills/src/index.ts +0 -1
- package/packages/skills/src/loader.ts +0 -346
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentService — Wrapper del nuevo agent-loop nativo.
|
|
3
|
-
*
|
|
4
|
-
* Reemplaza la clase Agent legacy.
|
|
5
|
-
* Mantiene compatibilidad con server.ts pero usa el agent-loop nativo por debajo.
|
|
6
|
-
*
|
|
7
|
-
* Responsabilidades:
|
|
8
|
-
* - Cargar agente desde DB
|
|
9
|
-
* - Cargar ética desde DB
|
|
10
|
-
* - Obtener MCP Manager
|
|
11
|
-
* - Hot reload (MCP, skills, ethics)
|
|
12
|
-
* - Eventos (cron, etc.)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { getDb } from "../storage/sqlite"
|
|
16
|
-
import { logger } from "../utils/logger"
|
|
17
|
-
import { buildSystemPromptWithProjects } from "./prompt-builder"
|
|
18
|
-
import { getAgentLoop, rebuildAgentLoop } from "./agent-loop"
|
|
19
|
-
import type { MCPClientManager } from "@johpaz/hive-mcp"
|
|
20
|
-
import { resolveAgentId, resolveUserId } from "../storage/onboarding"
|
|
21
|
-
import { getMCPManager as getSingletonMCPManager } from "../mcp/singleton"
|
|
22
|
-
|
|
23
|
-
const log = logger.child("agent-service")
|
|
24
|
-
|
|
25
|
-
// Event handler types
|
|
26
|
-
type CronHandler = (sessionId: string, task: string, jobId?: string, context?: any) => Promise<void>
|
|
27
|
-
|
|
28
|
-
export interface AgentServiceConfig {
|
|
29
|
-
agentId?: string
|
|
30
|
-
workspacePath?: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface AgentDBRecord {
|
|
34
|
-
id: string
|
|
35
|
-
user_id: string
|
|
36
|
-
name: string
|
|
37
|
-
description: string | null
|
|
38
|
-
system_prompt: string | null
|
|
39
|
-
tone: string | null
|
|
40
|
-
role: string
|
|
41
|
-
status: string
|
|
42
|
-
enabled: number
|
|
43
|
-
provider_id: string
|
|
44
|
-
model_id: string
|
|
45
|
-
tools_json: string | null
|
|
46
|
-
skills_json: string | null
|
|
47
|
-
parent_id: string | null
|
|
48
|
-
max_iterations: number
|
|
49
|
-
headers_encrypted: string | null
|
|
50
|
-
headers_iv: string | null
|
|
51
|
-
created_at: number
|
|
52
|
-
updated_at: number
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export class AgentService {
|
|
56
|
-
private agentId: string
|
|
57
|
-
private workspacePath: string
|
|
58
|
-
private mcpManager: MCPClientManager | null = null
|
|
59
|
-
private cronHandlers: CronHandler[] = []
|
|
60
|
-
private initialized: boolean = false
|
|
61
|
-
|
|
62
|
-
constructor(config?: AgentServiceConfig) {
|
|
63
|
-
// Resolve agentId from database if not provided
|
|
64
|
-
this.agentId = config?.agentId || resolveAgentId(null) || "main"
|
|
65
|
-
this.workspacePath = config?.workspacePath || ""
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Inicializa el servicio del agente
|
|
70
|
-
* - Carga el MCP Manager
|
|
71
|
-
* - Configura el supervisor graph
|
|
72
|
-
*/
|
|
73
|
-
async initialize(): Promise<void> {
|
|
74
|
-
if (this.initialized) {
|
|
75
|
-
log.debug("AgentService already initialized")
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
// Obtener MCP Manager del agent loop
|
|
81
|
-
const agentLoop = getAgentLoop()
|
|
82
|
-
if (agentLoop) {
|
|
83
|
-
// MCP Manager se inicializa en el agent-loop
|
|
84
|
-
log.info("AgentService: MCP Manager available from agent-loop")
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.initialized = true
|
|
88
|
-
log.info(`AgentService initialized for agent=${this.agentId}`)
|
|
89
|
-
} catch (error) {
|
|
90
|
-
log.error(`Failed to initialize AgentService: ${(error as Error).message}`)
|
|
91
|
-
throw error
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Obtiene el registro del agente desde la DB
|
|
97
|
-
*/
|
|
98
|
-
async getAgent(agentId?: string): Promise<AgentDBRecord | null> {
|
|
99
|
-
const db = getDb()
|
|
100
|
-
const id = agentId || this.agentId
|
|
101
|
-
|
|
102
|
-
const agent = db.query<any, [string]>(
|
|
103
|
-
"SELECT * FROM agents WHERE id = ? LIMIT 1"
|
|
104
|
-
).get(id) as AgentDBRecord | undefined
|
|
105
|
-
|
|
106
|
-
return agent || null
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Obtiene la ética desde la DB
|
|
111
|
-
*/
|
|
112
|
-
async getEthics(): Promise<string> {
|
|
113
|
-
const db = getDb()
|
|
114
|
-
const ethics = db.query<any, []>(
|
|
115
|
-
"SELECT content FROM ethics WHERE active = 1 LIMIT 1"
|
|
116
|
-
).get() as { content: string } | undefined
|
|
117
|
-
|
|
118
|
-
return ethics?.content || ""
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Obtiene el MCP Manager
|
|
123
|
-
*/
|
|
124
|
-
getMCPManager(): MCPClientManager | null {
|
|
125
|
-
const agentLoop = getAgentLoop()
|
|
126
|
-
if (agentLoop && (agentLoop as any).mcpManager) {
|
|
127
|
-
return (agentLoop as any).mcpManager as MCPClientManager
|
|
128
|
-
}
|
|
129
|
-
// Fallback to singleton
|
|
130
|
-
return getSingletonMCPManager()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Recarga la configuración del MCP
|
|
135
|
-
*/
|
|
136
|
-
async reloadMCP(): Promise<void> {
|
|
137
|
-
log.info("Reloading MCP configuration...")
|
|
138
|
-
const mcp = this.getMCPManager()
|
|
139
|
-
if (mcp) {
|
|
140
|
-
await mcp.reconnectAll().catch(err => {
|
|
141
|
-
log.warn(`Failed to reconnect MCP: ${(err as Error).message}`)
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
log.info("MCP reloaded")
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Recarga los skills desde la DB
|
|
149
|
-
*/
|
|
150
|
-
async reloadSkills(): Promise<void> {
|
|
151
|
-
log.info("Reloading skills...")
|
|
152
|
-
const { syncSkillsToFTS } = await import("./context-compiler")
|
|
153
|
-
syncSkillsToFTS()
|
|
154
|
-
log.info("Skills reloaded")
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Recarga la ética desde la DB
|
|
159
|
-
*/
|
|
160
|
-
async reloadEthics(): Promise<void> {
|
|
161
|
-
log.info("Reloading ethics...")
|
|
162
|
-
// La ética se carga automáticamente en buildSystemPrompt()
|
|
163
|
-
// No hay acción necesaria aquí
|
|
164
|
-
log.info("Ethics reloaded (will be picked up on next agent call)")
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Recarga el soul (system prompt del agente)
|
|
169
|
-
*/
|
|
170
|
-
async reloadSoul(): Promise<void> {
|
|
171
|
-
log.info("Reloading soul...")
|
|
172
|
-
// El soul se carga automáticamente desde DB en buildSystemPrompt()
|
|
173
|
-
log.info("Soul reloaded (will be picked up on next agent call)")
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Recarga la configuración del usuario
|
|
178
|
-
*/
|
|
179
|
-
async reloadUser(): Promise<void> {
|
|
180
|
-
log.info("Reloading user configuration...")
|
|
181
|
-
// La configuración del usuario se carga desde DB en buildSystemPrompt()
|
|
182
|
-
log.info("User configuration reloaded (will be picked up on next agent call)")
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Actualiza la configuración del agente
|
|
187
|
-
*/
|
|
188
|
-
async updateConfig(config: any): Promise<void> {
|
|
189
|
-
log.info("Updating agent configuration...")
|
|
190
|
-
// La configuración ahora se carga desde DB dinámicamente
|
|
191
|
-
// No hay acción necesaria aquí
|
|
192
|
-
log.info("Configuration updated (will be picked up from DB)")
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Recarga el agente (hot reload)
|
|
197
|
-
*/
|
|
198
|
-
async reload(): Promise<void> {
|
|
199
|
-
log.info("Reloading agent...")
|
|
200
|
-
await this.reloadMCP()
|
|
201
|
-
await this.reloadSkills()
|
|
202
|
-
await this.reloadEthics()
|
|
203
|
-
log.info("Agent reloaded")
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Registra un handler para eventos cron
|
|
208
|
-
*/
|
|
209
|
-
on(event: 'cron', handler: CronHandler): void {
|
|
210
|
-
if (event === 'cron') {
|
|
211
|
-
this.cronHandlers.push(handler)
|
|
212
|
-
log.debug(`Registered cron handler, total=${this.cronHandlers.length}`)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Emite un evento cron
|
|
218
|
-
*/
|
|
219
|
-
emit(event: 'cron', sessionId: string, task: string, jobId?: string, context?: any): void {
|
|
220
|
-
if (event === 'cron') {
|
|
221
|
-
log.debug(`Emitting cron event: task=${task}, sessionId=${sessionId}, jobId=${jobId}`)
|
|
222
|
-
for (const handler of this.cronHandlers) {
|
|
223
|
-
handler(sessionId, task, jobId, context).catch(err => {
|
|
224
|
-
log.error(`Cron handler error: ${(err as Error).message}`)
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Obtiene el system prompt para un agente
|
|
232
|
-
*/
|
|
233
|
-
async getSystemPrompt(agentId?: string, userId?: string): Promise<string> {
|
|
234
|
-
const id = agentId || this.agentId
|
|
235
|
-
const uid = userId || resolveUserId({}) || "default"
|
|
236
|
-
return buildSystemPromptWithProjects({ agentId: id, userId: uid })
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Ejecuta un agente con un mensaje
|
|
241
|
-
*/
|
|
242
|
-
async runAgent(message: string, threadId: string, userId?: string): Promise<string> {
|
|
243
|
-
const { runAgentIsolated } = await import("./agent-loop")
|
|
244
|
-
const result = await runAgentIsolated({
|
|
245
|
-
agentId: this.agentId,
|
|
246
|
-
taskDescription: message,
|
|
247
|
-
threadId,
|
|
248
|
-
})
|
|
249
|
-
return result
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Singleton para compatibilidad
|
|
254
|
-
let _agentService: AgentService | null = null
|
|
255
|
-
|
|
256
|
-
export function getAgentService(): AgentService {
|
|
257
|
-
if (!_agentService) {
|
|
258
|
-
_agentService = new AgentService()
|
|
259
|
-
}
|
|
260
|
-
return _agentService
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function createAgentService(config?: AgentServiceConfig): AgentService {
|
|
264
|
-
_agentService = new AgentService(config)
|
|
265
|
-
return _agentService
|
|
266
|
-
}
|
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FTS5-based Dynamic Skill Selector Module
|
|
3
|
-
*
|
|
4
|
-
* Context Compiler Level 4 - Intelligent Skill Selection
|
|
5
|
-
*
|
|
6
|
-
* This module uses SQLite FTS5 bm25() scoring to select the most relevant
|
|
7
|
-
* skills (0-5) based on the user message, similar to tool selection.
|
|
8
|
-
*
|
|
9
|
-
* DESIGN DECISIONS:
|
|
10
|
-
*
|
|
11
|
-
* 1. Reads from skills table in database (not hardcoded catalog)
|
|
12
|
-
* 2. Maximum 5 skills per turn for balanced context injection
|
|
13
|
-
* 3. Relevance threshold for conversational messages
|
|
14
|
-
* 4. Uses skill descriptions for FTS5 matching
|
|
15
|
-
* 5. Returns skill content for injection into system prompt
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { getDb } from "../storage/sqlite"
|
|
19
|
-
import { logger } from "../utils/logger"
|
|
20
|
-
|
|
21
|
-
const log = logger.child("skill-selector")
|
|
22
|
-
|
|
23
|
-
// ─── Types ───────────────────────────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
export interface SkillDescriptor {
|
|
26
|
-
id: string
|
|
27
|
-
name: string
|
|
28
|
-
category: string
|
|
29
|
-
tools: string
|
|
30
|
-
triggers: string
|
|
31
|
-
body: string
|
|
32
|
-
version: number
|
|
33
|
-
active: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface SelectedSkill {
|
|
37
|
-
id: string
|
|
38
|
-
name: string
|
|
39
|
-
score: number
|
|
40
|
-
category: string
|
|
41
|
-
body: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface SkillSelectorResult {
|
|
45
|
-
skills: SkillDescriptor[]
|
|
46
|
-
selected: SelectedSkill[]
|
|
47
|
-
reasoning: string
|
|
48
|
-
timingMs: number
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ─── Configuration ─────────────────────────────────────────────────────────
|
|
52
|
-
|
|
53
|
-
/** Maximum skills to return per message */
|
|
54
|
-
const MAX_SKILLS_PER_TURN = 5
|
|
55
|
-
|
|
56
|
-
/** Minimum bm25 score threshold. Below this = conversational, no skills needed. */
|
|
57
|
-
const MIN_RELEVANCE_THRESHOLD = -10
|
|
58
|
-
|
|
59
|
-
/** Stopwords to filter out before FTS5 query construction */
|
|
60
|
-
const STOPWORDS = new Set([
|
|
61
|
-
"que", "con", "para", "por", "una", "uno", "los", "las", "del",
|
|
62
|
-
"como", "esta", "esto", "ese", "eso", "the", "and", "for",
|
|
63
|
-
"with", "this", "that", "have", "will", "also", "de", "en",
|
|
64
|
-
"el", "la", "se", "su", "sus", "al", "es", "son", "pero",
|
|
65
|
-
"más", "mas", "ya", "yo", "tu", "te", "ti", "mi", "me",
|
|
66
|
-
"hola", "hi", "hello", "hey", "gracias", "thank", "please",
|
|
67
|
-
"ok", "okay", "yes", "si", "no", "bien", "good", "great",
|
|
68
|
-
])
|
|
69
|
-
|
|
70
|
-
/** Conversational patterns that should return empty skill list */
|
|
71
|
-
const CONVERSATIONAL_PATTERNS = [
|
|
72
|
-
/^(hola|hi|hello|hey|buenos? días?|buenas? noches?|qué tal|howdy)/i,
|
|
73
|
-
/^(gracias|thank you|thanks|muchas gracias|muchas thanks)/i,
|
|
74
|
-
/^(cómo estás?|how are you?|qué流水|you doing|qué cuentas)/i,
|
|
75
|
-
/^(sí|yes|ok|okay|de acuerdo|perfecto|claro|por supuesto)/i,
|
|
76
|
-
/^(adiós|bye|nos vemos|see you|later|chau)/i,
|
|
77
|
-
/^(entiendo|understand|i see|ya veo|got it)/i,
|
|
78
|
-
/^(bien|good|great|excelente|awesome|perfect)/i,
|
|
79
|
-
/^(?:\?|¿)$/, // Just a question mark
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
// ─── Helper Functions ───────────────────────────────────────────────────────
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Check if message is purely conversational (no skills needed)
|
|
86
|
-
*/
|
|
87
|
-
function isConversational(message: string): boolean {
|
|
88
|
-
const trimmed = message.trim()
|
|
89
|
-
|
|
90
|
-
// Empty or very short messages
|
|
91
|
-
if (trimmed.length < 2) return true
|
|
92
|
-
|
|
93
|
-
// Check conversational patterns
|
|
94
|
-
for (const pattern of CONVERSATIONAL_PATTERNS) {
|
|
95
|
-
if (pattern.test(trimmed)) {
|
|
96
|
-
log.debug(`[skill-selector] Message matched conversational pattern: ${pattern}`)
|
|
97
|
-
return true
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Check if all words are stopwords (likely conversational)
|
|
102
|
-
const words = trimmed.toLowerCase().split(/\s+/)
|
|
103
|
-
const meaningfulWords = words.filter(w => w.length > 2 && !STOPWORDS.has(w))
|
|
104
|
-
if (meaningfulWords.length === 0) {
|
|
105
|
-
log.debug(`[skill-selector] All words are stopwords - conversational`)
|
|
106
|
-
return true
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return false
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Build FTS5 query from user message
|
|
114
|
-
*/
|
|
115
|
-
function buildFTSQuery(message: string): string {
|
|
116
|
-
const words = message
|
|
117
|
-
.toLowerCase()
|
|
118
|
-
.replace(/[^\p{L}\p{N}\s]/gu, " ")
|
|
119
|
-
.split(/\s+/)
|
|
120
|
-
.filter((w) => w.length > 2 && !STOPWORDS.has(w))
|
|
121
|
-
.slice(0, 8)
|
|
122
|
-
|
|
123
|
-
if (words.length === 0) return ""
|
|
124
|
-
|
|
125
|
-
return words.join(" OR ")
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Check if message matches explicit triggers from a skill
|
|
130
|
-
*/
|
|
131
|
-
function matchTriggers(message: string, triggersJson: string | null): boolean {
|
|
132
|
-
if (!triggersJson) return false
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
// Triggers are stored as comma-separated string in DB (e.g., "trigger1,trigger2")
|
|
136
|
-
const triggers: string[] = triggersJson.split(",").map(t => t.trim()).filter(t => t.length > 0)
|
|
137
|
-
if (triggers.length === 0) return false
|
|
138
|
-
|
|
139
|
-
const lowerMessage = message.toLowerCase()
|
|
140
|
-
return triggers.some(trigger =>
|
|
141
|
-
lowerMessage.includes(trigger.toLowerCase())
|
|
142
|
-
)
|
|
143
|
-
} catch (err) {
|
|
144
|
-
log.warn(`[skill-selector] Failed to parse triggers: ${(err as Error).message}`)
|
|
145
|
-
return false
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ─── Main Selection Function ─────────────────────────────────────────────────
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Select skills for a given user message using hybrid matching:
|
|
153
|
-
* 1. First check explicit triggers (high confidence match)
|
|
154
|
-
* 2. Fallback to FTS5 bm25() scoring for semantic matching
|
|
155
|
-
*
|
|
156
|
-
* @param userMessage - The raw user message
|
|
157
|
-
* @returns Array of 0-5 selected skills with scores
|
|
158
|
-
*
|
|
159
|
-
* ALGORITHM:
|
|
160
|
-
* 1. If conversational → return []
|
|
161
|
-
* 2. Check explicit triggers from all enabled skills
|
|
162
|
-
* 3. If trigger match found → return matching skill immediately
|
|
163
|
-
* 4. Build FTS5 query from message keywords
|
|
164
|
-
* 5. Query skills_fts with bm25() scoring
|
|
165
|
-
* 6. Filter results below MIN_RELEVANCE_THRESHOLD
|
|
166
|
-
* 7. Return top MAX_SKILLS_PER_TURN results
|
|
167
|
-
*/
|
|
168
|
-
export function selectSkills(userMessage: string): SkillDescriptor[] {
|
|
169
|
-
const startTime = performance.now()
|
|
170
|
-
|
|
171
|
-
log.debug(`[skill-selector] Processing user message: "${userMessage.substring(0, 100)}"`)
|
|
172
|
-
|
|
173
|
-
// Step 1: Check if conversational
|
|
174
|
-
if (isConversational(userMessage)) {
|
|
175
|
-
log.debug(`[skill-selector] Conversational message, returning empty array`)
|
|
176
|
-
return []
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Step 2: Check explicit triggers first (high priority)
|
|
180
|
-
const db = getDb()
|
|
181
|
-
const allSkills = db.query(`
|
|
182
|
-
SELECT id, name, category, tools, triggers, body, version, active
|
|
183
|
-
FROM skills
|
|
184
|
-
WHERE active = 1
|
|
185
|
-
`).all() as SkillDescriptor[]
|
|
186
|
-
|
|
187
|
-
// Check trigger match - if found, return immediately with high confidence
|
|
188
|
-
for (const skill of allSkills) {
|
|
189
|
-
if (skill.triggers && matchTriggers(userMessage, skill.triggers)) {
|
|
190
|
-
log.info(`[skill-selector] Trigger match found: ${skill.name}`)
|
|
191
|
-
return [skill]
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Step 3: Build FTS5 query for semantic matching
|
|
196
|
-
const ftsQuery = buildFTSQuery(userMessage)
|
|
197
|
-
if (!ftsQuery) {
|
|
198
|
-
log.debug(`[skill-selector] No valid FTS query terms, returning empty array`)
|
|
199
|
-
return []
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
log.debug(`[skill-selector] FTS query: "${ftsQuery}"`)
|
|
203
|
-
|
|
204
|
-
// Step 4: Execute FTS5 query with bm25 scoring
|
|
205
|
-
// Use bm25() for relevance scoring (FTS5 table is populated in gateway/initializer.ts)
|
|
206
|
-
const ftsResults = db.query(`
|
|
207
|
-
SELECT id, bm25(skills_fts) as bm25_score
|
|
208
|
-
FROM skills_fts
|
|
209
|
-
WHERE skills_fts MATCH ?
|
|
210
|
-
ORDER BY bm25_score ASC
|
|
211
|
-
LIMIT 20
|
|
212
|
-
`).all(ftsQuery) as { id: string; bm25_score: number }[]
|
|
213
|
-
|
|
214
|
-
if (ftsResults.length === 0) {
|
|
215
|
-
log.debug(`[skill-selector] No FTS matches, returning empty array`)
|
|
216
|
-
return []
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
log.debug(`[skill-selector] Raw FTS results:`, ftsResults.slice(0, 5))
|
|
220
|
-
|
|
221
|
-
// Step 5: Apply relevance threshold filter
|
|
222
|
-
const relevantResults = ftsResults.filter(r => r.bm25_score >= MIN_RELEVANCE_THRESHOLD)
|
|
223
|
-
|
|
224
|
-
if (relevantResults.length === 0) {
|
|
225
|
-
log.debug(`[skill-selector] All results below threshold ${MIN_RELEVANCE_THRESHOLD}, returning empty`)
|
|
226
|
-
return []
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Step 6: Fetch full skill details from database
|
|
230
|
-
const skillIds = relevantResults.map(r => r.id)
|
|
231
|
-
|
|
232
|
-
let dbSkills: SkillDescriptor[] = []
|
|
233
|
-
try {
|
|
234
|
-
const db = getDb()
|
|
235
|
-
dbSkills = db.query(`
|
|
236
|
-
SELECT id, name, category, tools, triggers, body, version, active
|
|
237
|
-
FROM skills
|
|
238
|
-
WHERE id IN (${skillIds.map(() => '?').join(',')})
|
|
239
|
-
AND active = 1
|
|
240
|
-
`).all(...skillIds) as SkillDescriptor[]
|
|
241
|
-
} catch (err) {
|
|
242
|
-
log.warn(`[skill-selector] Failed to fetch skills from DB:`, err)
|
|
243
|
-
return []
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Map scores to skills
|
|
247
|
-
const skillMap = new Map(dbSkills.map(s => [s.id, s]))
|
|
248
|
-
const scoredSkills: SelectedSkill[] = []
|
|
249
|
-
|
|
250
|
-
for (const result of relevantResults) {
|
|
251
|
-
const skill = skillMap.get(result.id)
|
|
252
|
-
if (skill) {
|
|
253
|
-
scoredSkills.push({
|
|
254
|
-
id: skill.id,
|
|
255
|
-
name: skill.name,
|
|
256
|
-
score: result.bm25_score,
|
|
257
|
-
category: skill.category,
|
|
258
|
-
body: skill.body,
|
|
259
|
-
})
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Step 7: Take top N skills
|
|
264
|
-
const topSkills = scoredSkills.slice(0, MAX_SKILLS_PER_TURN)
|
|
265
|
-
|
|
266
|
-
// Step 8: Return as SkillDescriptor array
|
|
267
|
-
const result = topSkills.map(t => skillMap.get(t.id)!).filter(Boolean)
|
|
268
|
-
|
|
269
|
-
const timing = performance.now() - startTime
|
|
270
|
-
|
|
271
|
-
if (result.length > 0) {
|
|
272
|
-
log.info(`[skill-selector] Selected ${result.length} skills in ${timing.toFixed(2)}ms:`,
|
|
273
|
-
result.map(s => ({ name: s.name, category: s.category })))
|
|
274
|
-
} else {
|
|
275
|
-
log.debug(`[skill-selector] No skills selected, returning empty array in ${timing.toFixed(2)}ms`)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return result
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// ─── Sync Skills to FTS5 ───────────────────────────────────────────────────
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Sync all enabled skills from database to FTS5
|
|
285
|
-
* Should be called on initialization from gateway/initializer.ts
|
|
286
|
-
* The skills_fts table is created by seed.ts
|
|
287
|
-
*/
|
|
288
|
-
export async function syncSkillsToFTS(): Promise<void> {
|
|
289
|
-
const db = getDb()
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
// Step 1: Get all enabled skills from database (simplified schema)
|
|
293
|
-
const dbSkills = db.query(`
|
|
294
|
-
SELECT id, name, category, tools, triggers, body
|
|
295
|
-
FROM skills
|
|
296
|
-
WHERE active = 1
|
|
297
|
-
`).all() as Array<{
|
|
298
|
-
id: string
|
|
299
|
-
name: string
|
|
300
|
-
category: string
|
|
301
|
-
tools: string
|
|
302
|
-
triggers: string
|
|
303
|
-
body: string
|
|
304
|
-
}>
|
|
305
|
-
|
|
306
|
-
if (dbSkills.length === 0) {
|
|
307
|
-
log.debug(`[skill-selector] No skills found in DB to sync`)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Step 2: Atomic transaction for FTS5 sync
|
|
311
|
-
const syncTransaction = db.transaction(() => {
|
|
312
|
-
// Verify table exists
|
|
313
|
-
const tableCheck = db.query("SELECT name FROM sqlite_master WHERE type='table' AND name='skills_fts'").get()
|
|
314
|
-
if (!tableCheck) {
|
|
315
|
-
throw new Error("skills_fts table does not exist!")
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// A: Clear existing data
|
|
319
|
-
db.run("DELETE FROM skills_fts")
|
|
320
|
-
|
|
321
|
-
// B: Prepare insertion (simplified schema matching new skills table)
|
|
322
|
-
const insert = db.prepare(`
|
|
323
|
-
INSERT INTO skills_fts(id, name, category, tools, triggers, body)
|
|
324
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
325
|
-
`)
|
|
326
|
-
|
|
327
|
-
// C: Re-populate
|
|
328
|
-
for (const skill of dbSkills) {
|
|
329
|
-
insert.run(
|
|
330
|
-
skill.id,
|
|
331
|
-
skill.name,
|
|
332
|
-
skill.category,
|
|
333
|
-
skill.tools,
|
|
334
|
-
skill.triggers,
|
|
335
|
-
skill.body
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
// Execute transaction
|
|
341
|
-
syncTransaction()
|
|
342
|
-
|
|
343
|
-
log.info(`[skill-selector] Atomic sync complete: ${dbSkills.length} skills indexed in FTS5`)
|
|
344
|
-
|
|
345
|
-
} catch (err) {
|
|
346
|
-
log.error(`[skill-selector] Transactional sync failed:`, err)
|
|
347
|
-
throw err // Re-throw to inform initializer
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
// ─── Initialization ───────────────────────────────────────────────────────
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Initialize the skill selector
|
|
354
|
-
* DEPRECATED: syncSkillsToFTS() is now called from gateway/initializer.ts
|
|
355
|
-
* This function is kept for backward compatibility but is no longer needed
|
|
356
|
-
*/
|
|
357
|
-
export function initializeSkillSelector(): void {
|
|
358
|
-
log.info(`[skill-selector] Initializing skill selector (deprecated - sync is done in gateway/initializer.ts)`)
|
|
359
|
-
// syncSkillsToFTS() - No longer needed here, done in gateway/initializer.ts
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// ─── Debug/Test Helpers ─────────────────────────────────────────────────────
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Get all enabled skills from database (for debugging/testing)
|
|
366
|
-
*/
|
|
367
|
-
export function getAllSkillsFromDB(): SkillDescriptor[] {
|
|
368
|
-
try {
|
|
369
|
-
const db = getDb()
|
|
370
|
-
return db.query(`
|
|
371
|
-
SELECT id, name, category, tools, triggers, body, version, active
|
|
372
|
-
FROM skills
|
|
373
|
-
WHERE active = 1
|
|
374
|
-
`).all() as SkillDescriptor[]
|
|
375
|
-
} catch (err) {
|
|
376
|
-
log.error(`[skill-selector] Failed to fetch skills:`, err)
|
|
377
|
-
return []
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Get skill by name
|
|
383
|
-
*/
|
|
384
|
-
export function getSkillByName(name: string): SkillDescriptor | undefined {
|
|
385
|
-
try {
|
|
386
|
-
const db = getDb()
|
|
387
|
-
return db.query(`
|
|
388
|
-
SELECT id, name, category, tools, triggers, body, version, active
|
|
389
|
-
FROM skills
|
|
390
|
-
WHERE name = ? AND active = 1
|
|
391
|
-
`).get(name) as SkillDescriptor | undefined
|
|
392
|
-
} catch (err) {
|
|
393
|
-
log.error(`[skill-selector] Failed to fetch skill by name:`, err)
|
|
394
|
-
return undefined
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Get skills by category
|
|
400
|
-
*/
|
|
401
|
-
export function getSkillsByCategory(category: string): SkillDescriptor[] {
|
|
402
|
-
try {
|
|
403
|
-
const db = getDb()
|
|
404
|
-
return db.query(`
|
|
405
|
-
SELECT id, name, category, tools, triggers, body, version, active
|
|
406
|
-
FROM skills
|
|
407
|
-
WHERE category = ? AND active = 1
|
|
408
|
-
`).all(category) as SkillDescriptor[]
|
|
409
|
-
} catch (err) {
|
|
410
|
-
log.error(`[skill-selector] Failed to fetch skills by category:`, err)
|
|
411
|
-
return []
|
|
412
|
-
}
|
|
413
|
-
}
|