@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,544 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Compiler — Implementa las 4 estrategias de Context Engineering:
|
|
3
|
-
*
|
|
4
|
-
* 1. ESCRIBIR (Write) — Guardar información fuera del contexto:
|
|
5
|
-
* - Scratchpad: notas persistentes por conversación
|
|
6
|
-
* - Trazas de ejecución: registro en traces table
|
|
7
|
-
*
|
|
8
|
-
* 2. SELECCIONAR (Select) — Traer solo lo relevante:
|
|
9
|
-
* - Tool Loadout: máx 3-5 tools relevantes por turno
|
|
10
|
-
* - Playbook filtering: reglas ACE aplicables a esta tarea
|
|
11
|
-
* - Historial selectivo: resumen + mensajes recientes
|
|
12
|
-
*
|
|
13
|
-
* 3. COMPRIMIR (Compress) — Reducir tokens manteniendo información:
|
|
14
|
-
* - Compaction: resumir mensajes viejos
|
|
15
|
-
* - Tool result clearing: reemplazar resultados antiguos por resúmenes
|
|
16
|
-
*
|
|
17
|
-
* 4. AISLAR (Isolate) — Separar contextos por agente:
|
|
18
|
-
* - Cada worker recibe su propio contexto mínimo
|
|
19
|
-
* - El Coordinador ve el panorama completo
|
|
20
|
-
*
|
|
21
|
-
* TODOS los datos se formatean en TOON para ahorro de tokens.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { getDb } from "../storage/sqlite"
|
|
25
|
-
import { logger } from "../utils/logger"
|
|
26
|
-
import type { LLMMessage, LLMToolDef } from "./llm-client"
|
|
27
|
-
import type { MCPClientManager } from "@johpaz/hive-mcp"
|
|
28
|
-
import { selectTools, type ToolDescriptor, syncToolCatalogToFTS, syncMCPToolsToFTS, removeMCPToolsFromFTS, mcpToolFullName } from "./tool-selector"
|
|
29
|
-
import { selectSkills, type SkillDescriptor, syncSkillsToFTS } from "./skill-selector"
|
|
30
|
-
import { selectPlaybookRules, syncPlaybookToFTS } from "./playbook-selector"
|
|
31
|
-
import { getRecentMessages, getSummary, getScratchpad, toAPIMessages } from "./conversation-store"
|
|
32
|
-
import { formatContext, estimateTokens } from "../utils/toon"
|
|
33
|
-
import { buildSystemPromptWithProjects } from "./prompt-builder"
|
|
34
|
-
import { createAllTools } from "../tools/index.ts"
|
|
35
|
-
import { resolveUserId } from "../storage/onboarding"
|
|
36
|
-
import { getMCPManager as getSingletonMCPManager } from "../mcp/singleton"
|
|
37
|
-
import { getUserDate, getUserTime } from "../utils/date"
|
|
38
|
-
|
|
39
|
-
const log = logger.child("context-compiler")
|
|
40
|
-
|
|
41
|
-
// Configuration constants
|
|
42
|
-
const MAX_TOOL_LOADOUT = 5 // Max tools per turn (Strategy: SELECT)
|
|
43
|
-
const MAX_PLAYBOOK_RULES = 5 // Max ACE rules to inject
|
|
44
|
-
const KEEP_LAST_N_MESSAGES = 10 // Always keep last N messages (Strategy: SELECT)
|
|
45
|
-
const TOKEN_COMPACT_THRESHOLD = 6000 // Compact when exceeds this (Strategy: COMPRESS)
|
|
46
|
-
|
|
47
|
-
// ─── Tool Expansion ────────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Expand selected tools by adding related tools from the same category.
|
|
51
|
-
* This enables multi-step workflows where the LLM needs multiple tools
|
|
52
|
-
* to complete a complex task (e.g., web_search + web_fetch, or browser_navigate + browser_click).
|
|
53
|
-
*/
|
|
54
|
-
function expandToolCategories(
|
|
55
|
-
selected: ToolDescriptor[],
|
|
56
|
-
allTools: ToolDescriptor[]
|
|
57
|
-
): ToolDescriptor[] {
|
|
58
|
-
const selectedNames = new Set(selected.map(t => t.name))
|
|
59
|
-
const expanded = [...selected]
|
|
60
|
-
|
|
61
|
-
// Helper to safely add a tool if it exists and isn't already selected
|
|
62
|
-
const addTool = (name: string) => {
|
|
63
|
-
if (!selectedNames.has(name)) {
|
|
64
|
-
const tool = allTools.find(t => t.name === name)
|
|
65
|
-
if (tool) {
|
|
66
|
-
expanded.push(tool)
|
|
67
|
-
selectedNames.add(name)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Check for scheduling category → add all cron tools
|
|
73
|
-
const hasScheduling = selected.some(t => t.category === 'scheduling')
|
|
74
|
-
if (hasScheduling) {
|
|
75
|
-
addTool('cron_add')
|
|
76
|
-
addTool('cron_list')
|
|
77
|
-
addTool('cron_remove')
|
|
78
|
-
addTool('cron_edit')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Check for web search → add web_fetch for downloading content
|
|
82
|
-
const hasWebSearch = selected.some(t => t.name === 'web_search')
|
|
83
|
-
if (hasWebSearch) {
|
|
84
|
-
addTool('web_fetch')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Check for browser automation → add all browser tools
|
|
88
|
-
const hasBrowser = selected.some(t => t.name.startsWith('browser_'))
|
|
89
|
-
if (hasBrowser) {
|
|
90
|
-
addTool('browser_navigate')
|
|
91
|
-
addTool('browser_fetch')
|
|
92
|
-
addTool('browser_click')
|
|
93
|
-
addTool('browser_type')
|
|
94
|
-
addTool('browser_screenshot')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Check for project management → add all project + delegation tools
|
|
98
|
-
const hasProject = selected.some(t => t.name.startsWith('project_') || t.name.startsWith('task_'))
|
|
99
|
-
if (hasProject) {
|
|
100
|
-
addTool('project_create')
|
|
101
|
-
addTool('project_update')
|
|
102
|
-
addTool('project_done')
|
|
103
|
-
addTool('project_fail')
|
|
104
|
-
addTool('task_create')
|
|
105
|
-
addTool('task_update')
|
|
106
|
-
addTool('task_delegate') // delegation is always paired with project management
|
|
107
|
-
addTool('agent_find') // need to find workers before delegating
|
|
108
|
-
addTool('task_status')
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Check for memory operations → add all memory tools
|
|
112
|
-
const hasMemory = selected.some(t => t.name.startsWith('memory_'))
|
|
113
|
-
if (hasMemory) {
|
|
114
|
-
addTool('memory_write')
|
|
115
|
-
addTool('memory_read')
|
|
116
|
-
addTool('memory_list')
|
|
117
|
-
addTool('memory_search')
|
|
118
|
-
addTool('memory_delete')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Check for agent management → add all agent tools (correct names)
|
|
122
|
-
const hasAgents = selected.some(t => t.name.startsWith('agent_') || t.name === 'task_delegate')
|
|
123
|
-
if (hasAgents) {
|
|
124
|
-
addTool('agent_create')
|
|
125
|
-
addTool('agent_find')
|
|
126
|
-
addTool('agent_archive')
|
|
127
|
-
addTool('task_delegate')
|
|
128
|
-
addTool('task_status')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Check for canvas → add all canvas tools
|
|
132
|
-
const hasCanvas = selected.some(t => t.name.startsWith('canvas_'))
|
|
133
|
-
if (hasCanvas) {
|
|
134
|
-
addTool('canvas_render')
|
|
135
|
-
addTool('canvas_ask')
|
|
136
|
-
addTool('canvas_clear')
|
|
137
|
-
addTool('canvas_show_card')
|
|
138
|
-
addTool('canvas_show_progress')
|
|
139
|
-
addTool('canvas_show_list')
|
|
140
|
-
addTool('canvas_confirm')
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Limit to reasonable number (allow some overflow for multi-step tasks)
|
|
144
|
-
return expanded.slice(0, MAX_TOOL_LOADOUT + 5)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
148
|
-
|
|
149
|
-
// Simple tool interface for context compilation
|
|
150
|
-
export interface ContextTool {
|
|
151
|
-
name: string
|
|
152
|
-
description: string
|
|
153
|
-
parameters: Record<string, unknown>
|
|
154
|
-
execute?: (params: Record<string, unknown>) => Promise<unknown>
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface CompiledContext {
|
|
158
|
-
systemPrompt: string
|
|
159
|
-
messages: LLMMessage[]
|
|
160
|
-
tools: LLMToolDef[]
|
|
161
|
-
allTools: ContextTool[]
|
|
162
|
-
selectedSkills: SkillDescriptor[]
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ─── Main compiler ─────────────────────────────────────────────────────────
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Compile context for agent execution implementing 4 strategies:
|
|
169
|
-
* 1. WRITE - Load scratchpad notes
|
|
170
|
-
* 2. SELECT - Tool loadout, playbook rules, selective history
|
|
171
|
-
* 3. COMPRESS - Use summaries, clear old tool results
|
|
172
|
-
* 4. ISOLATE - Worker gets minimal context
|
|
173
|
-
*/
|
|
174
|
-
export async function compileContext(opts: {
|
|
175
|
-
agentId: string
|
|
176
|
-
threadId: string
|
|
177
|
-
userId?: string
|
|
178
|
-
userMessage: string
|
|
179
|
-
channel?: string
|
|
180
|
-
isolated?: boolean
|
|
181
|
-
taskContext?: string
|
|
182
|
-
mcpManager?: MCPClientManager | null
|
|
183
|
-
}): Promise<CompiledContext> {
|
|
184
|
-
const db = getDb()
|
|
185
|
-
const { agentId, threadId, mcpManager, userMessage, isolated } = opts
|
|
186
|
-
|
|
187
|
-
// Fallback: Get MCP Manager from singleton if not provided
|
|
188
|
-
const effectiveMcpManager = mcpManager ?? (() => {
|
|
189
|
-
const singletonMcp = getSingletonMCPManager()
|
|
190
|
-
if (singletonMcp) {
|
|
191
|
-
log.info(`[context-compiler] Using MCP Manager from singleton`)
|
|
192
|
-
return singletonMcp
|
|
193
|
-
}
|
|
194
|
-
return null
|
|
195
|
-
})()
|
|
196
|
-
|
|
197
|
-
// Resolve userId from database with priority: explicit param → channel identity → single user
|
|
198
|
-
const userId = opts.userId || resolveUserId({
|
|
199
|
-
threadId,
|
|
200
|
-
channel: opts.channel,
|
|
201
|
-
channelUserId: threadId
|
|
202
|
-
}) || threadId || ""
|
|
203
|
-
|
|
204
|
-
// [STEP-1] Load agent config
|
|
205
|
-
log.info(`[context-compiler] [STEP-1] Loading agent config for id=${agentId}`)
|
|
206
|
-
let agent: any
|
|
207
|
-
try {
|
|
208
|
-
agent = db.query<any, [string]>(
|
|
209
|
-
"SELECT * FROM agents WHERE id = ?"
|
|
210
|
-
).get(agentId)
|
|
211
|
-
} catch (err) {
|
|
212
|
-
log.error(`[context-compiler] [STEP-1] ❌ FAILED loading agent: ${JSON.stringify(err)}`)
|
|
213
|
-
throw err
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (!agent) {
|
|
217
|
-
throw new Error(`Agent not found: ${agentId}`)
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const isWorker = agent.role === 'worker' || isolated
|
|
221
|
-
log.info(`[context-compiler] [STEP-1] ✅ Compiling for ${isWorker ? 'worker' : 'coordinator'} agent=${agent.name}`)
|
|
222
|
-
|
|
223
|
-
// [STEP-2] STRATEGY 1: WRITE — Load scratchpad (persistent notes)
|
|
224
|
-
log.info(`[context-compiler] [STEP-2] Loading scratchpad...`)
|
|
225
|
-
let scratchpadNotes: ReturnType<typeof getScratchpad> = []
|
|
226
|
-
try {
|
|
227
|
-
scratchpadNotes = getScratchpad(threadId)
|
|
228
|
-
log.info(`[context-compiler] [STEP-2] ✅ Loaded ${scratchpadNotes.length} scratchpad notes`)
|
|
229
|
-
} catch (err) {
|
|
230
|
-
log.error(`[context-compiler] [STEP-2] ❌ FAILED loading scratchpad: ${JSON.stringify(err)}`)
|
|
231
|
-
throw err
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// [STEP-3] STRATEGY 2: SELECT — Tool Loadout
|
|
235
|
-
log.info(`[context-compiler] [STEP-3] Loading tools from DB...`)
|
|
236
|
-
let dbTools: Array<{ name: string; description: string; category: string; enabled: number; active: number }> = []
|
|
237
|
-
try {
|
|
238
|
-
dbTools = db.query<any, []>(`
|
|
239
|
-
SELECT name, description, category, enabled, active
|
|
240
|
-
FROM tools
|
|
241
|
-
WHERE enabled = 1 AND active = 1
|
|
242
|
-
`).all() as typeof dbTools
|
|
243
|
-
log.info(`[context-compiler] [STEP-3] ✅ Loaded ${dbTools.length} tools from DB`)
|
|
244
|
-
} catch (err) {
|
|
245
|
-
log.error(`[context-compiler] [STEP-3] ❌ FAILED loading tools: ${JSON.stringify(err)}`)
|
|
246
|
-
throw err
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// [STEP-3b] Filter by agent assignment (if tools_json is set)
|
|
250
|
-
let allowedTools = dbTools
|
|
251
|
-
if (agent.tools_json) {
|
|
252
|
-
try {
|
|
253
|
-
const allowedIds = JSON.parse(agent.tools_json) as string[]
|
|
254
|
-
if (Array.isArray(allowedIds) && allowedIds.length > 0) {
|
|
255
|
-
allowedTools = dbTools.filter(t => allowedIds.includes(t.name))
|
|
256
|
-
log.info(`[context-compiler] [STEP-3b] Filtered to ${allowedTools.length} tools assigned to agent`)
|
|
257
|
-
}
|
|
258
|
-
} catch (e) {
|
|
259
|
-
log.warn(`[context-compiler] [STEP-3b] Failed to parse tools_json:`, e)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Convert native DB tools to ToolDescriptor for FTS5
|
|
264
|
-
const nativeToolDescriptors: ToolDescriptor[] = allowedTools.map(t => ({
|
|
265
|
-
name: t.name,
|
|
266
|
-
description: t.description || "",
|
|
267
|
-
category: t.category || "core",
|
|
268
|
-
}))
|
|
269
|
-
|
|
270
|
-
// [STEP-3c] Load MCP tools BEFORE FTS selection so they participate in search
|
|
271
|
-
// MCP tools are dynamic — loaded from the live manager, not from a static catalog.
|
|
272
|
-
log.info(`[context-compiler] [STEP-3c] Loading MCP tools for FTS selection...`)
|
|
273
|
-
const mcpToolExecutors: ContextTool[] = [] // full executors (passed to agent)
|
|
274
|
-
const mcpToolDescriptors: ToolDescriptor[] = [] // lightweight descriptors (for FTS)
|
|
275
|
-
|
|
276
|
-
if (effectiveMcpManager) {
|
|
277
|
-
try {
|
|
278
|
-
const dbServers = db.query<any, []>(
|
|
279
|
-
"SELECT id, name, status FROM mcp_servers WHERE enabled = 1"
|
|
280
|
-
).all()
|
|
281
|
-
|
|
282
|
-
for (const server of dbServers) {
|
|
283
|
-
// Try ID first (normalized), then name
|
|
284
|
-
let serverTools = effectiveMcpManager.getServerTools(server.id)
|
|
285
|
-
if (!serverTools || serverTools.length === 0) {
|
|
286
|
-
serverTools = effectiveMcpManager.getServerTools(server.name)
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (serverTools && serverTools.length > 0) {
|
|
290
|
-
log.info(`[context-compiler] [STEP-3c] Server ${server.name}: ${serverTools.length} tools`)
|
|
291
|
-
|
|
292
|
-
// Sync to FTS5 on every compilation (idempotent — hot-reload keeps FTS fresh)
|
|
293
|
-
try {
|
|
294
|
-
await syncMCPToolsToFTS(server.id, server.name, serverTools)
|
|
295
|
-
} catch (e) {
|
|
296
|
-
log.warn(`[context-compiler] [STEP-3c] FTS sync failed for ${server.name}: ${(e as Error).message}`)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
for (const mcpTool of serverTools) {
|
|
300
|
-
// Sanitized name valid for all LLM providers (no spaces, max 64 chars)
|
|
301
|
-
const fullName = mcpToolFullName(server.name, mcpTool.name)
|
|
302
|
-
|
|
303
|
-
// Executor for agent-loop (has the real call)
|
|
304
|
-
mcpToolExecutors.push({
|
|
305
|
-
name: fullName,
|
|
306
|
-
description: mcpTool.description || `Tool from ${server.name}`,
|
|
307
|
-
parameters: mcpTool.inputSchema || { type: "object", properties: {} },
|
|
308
|
-
execute: async (params: Record<string, unknown>) => {
|
|
309
|
-
const result = await effectiveMcpManager.callTool(server.id, mcpTool.name, params)
|
|
310
|
-
return typeof result === "string" ? result : JSON.stringify(result)
|
|
311
|
-
},
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
// Descriptor for FTS selection — uses the same fullName as the executor
|
|
315
|
-
mcpToolDescriptors.push({
|
|
316
|
-
name: fullName,
|
|
317
|
-
description: mcpTool.description || `Tool from ${server.name}`,
|
|
318
|
-
category: `mcp:${server.id}`,
|
|
319
|
-
})
|
|
320
|
-
}
|
|
321
|
-
} else {
|
|
322
|
-
log.warn(`[context-compiler] [STEP-3c] Server ${server.name} has no tools (not connected yet)`)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
log.info(`[context-compiler] [STEP-3c] ✅ Loaded ${mcpToolExecutors.length} MCP tools`)
|
|
327
|
-
} catch (err) {
|
|
328
|
-
log.error(`[context-compiler] [STEP-3c] ❌ Failed: ${(err as Error).message}`)
|
|
329
|
-
}
|
|
330
|
-
} else {
|
|
331
|
-
log.info(`[context-compiler] [STEP-3c] ⚠️ No MCP manager, skipping MCP tools`)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Combined descriptor list: native + MCP — this is what FTS searches
|
|
335
|
-
const toolDescriptors: ToolDescriptor[] = [...nativeToolDescriptors, ...mcpToolDescriptors]
|
|
336
|
-
|
|
337
|
-
// [STEP-4] Level 3: Tool Loadout — select top relevant tools via FTS5
|
|
338
|
-
// Both native and MCP tools are now searchable
|
|
339
|
-
log.info(`[context-compiler] [STEP-4] Selecting tools via FTS5 for message: "${userMessage.substring(0, 60)}"`)
|
|
340
|
-
let selectedToolDescriptors: ToolDescriptor[] = []
|
|
341
|
-
try {
|
|
342
|
-
selectedToolDescriptors = selectTools(userMessage, toolDescriptors, MAX_TOOL_LOADOUT)
|
|
343
|
-
log.info(`[context-compiler] [STEP-4] ✅ Selected ${selectedToolDescriptors.length} tools`)
|
|
344
|
-
} catch (err) {
|
|
345
|
-
log.error(`[context-compiler] [STEP-4] ❌ FAILED selectTools (FTS5): ${JSON.stringify(err)}`)
|
|
346
|
-
throw err
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// [STEP-4b] Tool Expansion: Auto-add related tools by category
|
|
350
|
-
selectedToolDescriptors = expandToolCategories(selectedToolDescriptors, toolDescriptors)
|
|
351
|
-
log.info(`[context-compiler] [STEP-4b] ✅ Expanded to ${selectedToolDescriptors.length} tools`)
|
|
352
|
-
|
|
353
|
-
// [STEP-5] STRATEGY 2: SELECT — Playbook rules (ACE)
|
|
354
|
-
log.info(`[context-compiler] [STEP-5] Selecting playbook rules...`)
|
|
355
|
-
let playbookRules: ReturnType<typeof selectPlaybookRules> = []
|
|
356
|
-
try {
|
|
357
|
-
playbookRules = selectPlaybookRules(userMessage)
|
|
358
|
-
log.info(`[context-compiler] [STEP-5] ✅ Selected ${playbookRules.length} playbook rules`)
|
|
359
|
-
} catch (err) {
|
|
360
|
-
log.error(`[context-compiler] [STEP-5] ❌ FAILED selectPlaybookRules (FTS5): ${JSON.stringify(err)}`)
|
|
361
|
-
throw err
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// [STEP-6] STRATEGY 2: SELECT — Skills (dynamic selection)
|
|
365
|
-
log.info(`[context-compiler] [STEP-6] Selecting skills...`)
|
|
366
|
-
let selectedSkills: SkillDescriptor[] = []
|
|
367
|
-
try {
|
|
368
|
-
selectedSkills = selectSkills(userMessage)
|
|
369
|
-
log.info(`[context-compiler] [STEP-6] ✅ Selected ${selectedSkills.length} skills`)
|
|
370
|
-
} catch (err) {
|
|
371
|
-
log.error(`[context-compiler] [STEP-6] ❌ FAILED selectSkills (FTS5): ${JSON.stringify(err)}`)
|
|
372
|
-
throw err
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// [STEP-8] Combine native tools + MCP executors loaded in STEP-3c
|
|
376
|
-
const config = { tools: {} }
|
|
377
|
-
const allNativeTools = createAllTools(config)
|
|
378
|
-
const nativeTools: ContextTool[] = allNativeTools.map(t => ({
|
|
379
|
-
name: t.name,
|
|
380
|
-
description: t.description || "",
|
|
381
|
-
parameters: t.parameters as any,
|
|
382
|
-
execute: t.execute,
|
|
383
|
-
}))
|
|
384
|
-
|
|
385
|
-
const allTools = [...nativeTools, ...mcpToolExecutors]
|
|
386
|
-
|
|
387
|
-
// Filter to only selected tools for this turn
|
|
388
|
-
const selectedToolNames = new Set(selectedToolDescriptors.map(t => t.name))
|
|
389
|
-
const filteredTools: ContextTool[] = selectedToolNames.size > 0
|
|
390
|
-
? allTools.filter(t => selectedToolNames.has(t.name))
|
|
391
|
-
: []
|
|
392
|
-
|
|
393
|
-
// CRITICAL: search_knowledge is ALWAYS available for coordinator
|
|
394
|
-
// This tool must never be filtered out
|
|
395
|
-
const hasSearchKnowledge = allTools.some(t => t.name === "search_knowledge")
|
|
396
|
-
if (hasSearchKnowledge && !selectedToolNames.has("search_knowledge")) {
|
|
397
|
-
const searchTool = allTools.find(t => t.name === "search_knowledge")
|
|
398
|
-
if (searchTool) {
|
|
399
|
-
filteredTools.push(searchTool)
|
|
400
|
-
log.info("[context-compiler] ✅ search_knowledge added (critical tool)")
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// Convert to LLMToolDef format
|
|
405
|
-
const toolsForLLM: LLMToolDef[] = filteredTools.map(t => ({
|
|
406
|
-
type: "function" as const,
|
|
407
|
-
function: {
|
|
408
|
-
name: t.name,
|
|
409
|
-
description: t.description,
|
|
410
|
-
parameters: t.parameters,
|
|
411
|
-
},
|
|
412
|
-
}))
|
|
413
|
-
log.info(`[context-compiler] [STEP-8] ✅ Combined tools: ${allTools.length} total, ${toolsForLLM.length} selected`)
|
|
414
|
-
|
|
415
|
-
// [STEP-9] STRATEGY 3: COMPRESS — Load history with compaction
|
|
416
|
-
log.info(`[context-compiler] [STEP-9] Loading conversation history...`)
|
|
417
|
-
let recentMessages: ReturnType<typeof getRecentMessages> = []
|
|
418
|
-
try {
|
|
419
|
-
recentMessages = getRecentMessages(threadId, KEEP_LAST_N_MESSAGES)
|
|
420
|
-
log.info(`[context-compiler] [STEP-9] ✅ Loaded ${recentMessages.length} recent messages`)
|
|
421
|
-
} catch (err) {
|
|
422
|
-
log.error(`[context-compiler] [STEP-9] ❌ FAILED loading history: ${JSON.stringify(err)}`)
|
|
423
|
-
throw err
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Check if we need to use summary (conversation is long)
|
|
427
|
-
let summary: ReturnType<typeof getSummary> = null
|
|
428
|
-
try {
|
|
429
|
-
summary = getSummary(threadId)
|
|
430
|
-
} catch (err) {
|
|
431
|
-
log.error(`[context-compiler] [STEP-9b] ❌ FAILED loading summary: ${JSON.stringify(err)}`)
|
|
432
|
-
throw err
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const totalTokens = recentMessages.reduce((sum, m) => sum + estimateTokens(m.content), 0)
|
|
436
|
-
|
|
437
|
-
let messages: LLMMessage[]
|
|
438
|
-
|
|
439
|
-
if (summary && totalTokens > TOKEN_COMPACT_THRESHOLD) {
|
|
440
|
-
// Use summary + recent messages (Strategy: COMPRESS)
|
|
441
|
-
messages = [
|
|
442
|
-
{ role: "system", content: `[Conversation Summary]: ${summary.summary}` },
|
|
443
|
-
...toAPIMessages(recentMessages),
|
|
444
|
-
]
|
|
445
|
-
log.info(`[context-compiler] [STEP-9c] Using summary (${summary.messages_covered} messages compressed)`)
|
|
446
|
-
} else {
|
|
447
|
-
// Conversation is short enough, use all recent messages
|
|
448
|
-
messages = toAPIMessages(recentMessages)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// [STEP-10] STRATEGY 4: ISOLATE — Build context based on agent role
|
|
452
|
-
log.info(`[context-compiler] [STEP-10] Building system prompt...`)
|
|
453
|
-
let systemPrompt: string
|
|
454
|
-
try {
|
|
455
|
-
systemPrompt = await buildSystemPromptWithProjects({ agentId, userId })
|
|
456
|
-
log.info(`[context-compiler] [STEP-10] ✅ System prompt built (${systemPrompt.length} chars)`)
|
|
457
|
-
} catch (err) {
|
|
458
|
-
log.error(`[context-compiler] [STEP-10] ❌ FAILED building system prompt: ${JSON.stringify(err)}`)
|
|
459
|
-
throw err
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// [STEP-10b] Inject current date/time (ENTORNO ACTUAL)
|
|
463
|
-
const userRow = db.query<any, [string]>(
|
|
464
|
-
"SELECT timezone FROM users WHERE id = ?"
|
|
465
|
-
).get(userId)
|
|
466
|
-
const userTimezone = userRow?.timezone || "UTC"
|
|
467
|
-
const now = new Date()
|
|
468
|
-
const fecha = getUserDate(userTimezone, now)
|
|
469
|
-
const hora = getUserTime(userTimezone, now)
|
|
470
|
-
systemPrompt += `\n\n# ENTORNO ACTUAL\n**Fecha**: ${fecha}\n**Hora**: ${hora}\n**Zona horaria**: ${userTimezone}\n`
|
|
471
|
-
log.info(`[context-compiler] [STEP-10b] ✅ Injected current date/time: ${fecha} ${hora} (${userTimezone})`)
|
|
472
|
-
|
|
473
|
-
// Inject scratchpad (Strategy: WRITE) — usando TOON para ahorro de tokens
|
|
474
|
-
if (scratchpadNotes.length > 0) {
|
|
475
|
-
const scratchpadData: Record<string, string> = {}
|
|
476
|
-
for (const n of scratchpadNotes) {
|
|
477
|
-
scratchpadData[n.key] = n.value
|
|
478
|
-
}
|
|
479
|
-
// TOON comprime el formato clave-valor
|
|
480
|
-
const scratchpadContent = formatContext(scratchpadData)
|
|
481
|
-
systemPrompt += `\n\n# SCRATCHPAD (Persistent Notes)\n${scratchpadContent}\n`
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// Inject playbook rules (Strategy: SELECT - ACE) — usando TOON
|
|
485
|
-
if (playbookRules.length > 0) {
|
|
486
|
-
const rulesByCategory: Record<string, string[]> = {}
|
|
487
|
-
for (const rule of playbookRules) {
|
|
488
|
-
const cat = rule.category || "general"
|
|
489
|
-
if (!rulesByCategory[cat]) rulesByCategory[cat] = []
|
|
490
|
-
rulesByCategory[cat].push(rule.rule)
|
|
491
|
-
}
|
|
492
|
-
// TOON comprime la estructura de categorías y reglas
|
|
493
|
-
const playbookContent = formatContext(rulesByCategory)
|
|
494
|
-
systemPrompt += `\n\n# LEARNED PLAYBOOK (ACE)\n${playbookContent}\n`
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// Inject selected skills — usando TOON
|
|
498
|
-
if (selectedSkills.length > 0) {
|
|
499
|
-
const skillsData: Record<string, string> = {}
|
|
500
|
-
for (const s of selectedSkills) {
|
|
501
|
-
skillsData[s.name] = s.body || ""
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Log skills being injected into context
|
|
505
|
-
for (const s of selectedSkills) {
|
|
506
|
-
const bodyPreview = (s.body || "").length > 300
|
|
507
|
-
? s.body!.substring(0, 300) + `… (+${s.body!.length - 300} chars)`
|
|
508
|
-
: (s.body || "(empty)")
|
|
509
|
-
log.info(`[context-compiler] Skill injected [${s.name}] category=${s.category}: ${bodyPreview}`)
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// TOON comprime la lista de skills
|
|
513
|
-
const skillsContent = formatContext(skillsData)
|
|
514
|
-
systemPrompt += `\n\n## ACTIVE SKILLS\n${skillsContent}\n`
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// For isolated workers, add task context
|
|
518
|
-
if (isWorker && opts.taskContext) {
|
|
519
|
-
systemPrompt += `\n\n# CURRENT TASK\n${opts.taskContext}\n\nFocus ONLY on this task. Do not deviate.`
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
log.info(
|
|
523
|
-
`[context-compiler] ✅ DONE: ${allTools.length} total, ` +
|
|
524
|
-
`${toolsForLLM.length} selected tools, ${messages.length} messages, ` +
|
|
525
|
-
`isolated=${isWorker}`
|
|
526
|
-
)
|
|
527
|
-
|
|
528
|
-
return {
|
|
529
|
-
systemPrompt,
|
|
530
|
-
messages,
|
|
531
|
-
tools: toolsForLLM,
|
|
532
|
-
allTools,
|
|
533
|
-
selectedSkills,
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// Re-export sync functions for gateway/initializer
|
|
538
|
-
export {
|
|
539
|
-
syncToolCatalogToFTS as syncToolsToFTS,
|
|
540
|
-
syncSkillsToFTS,
|
|
541
|
-
syncPlaybookToFTS,
|
|
542
|
-
syncMCPToolsToFTS,
|
|
543
|
-
removeMCPToolsFromFTS,
|
|
544
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../config/loader.ts";
|
|
2
|
-
import { logger } from "../utils/logger.ts";
|
|
3
|
-
import type { LLMMessage as Message } from "../agent/llm-client";
|
|
4
|
-
|
|
5
|
-
export interface ContextGuardResult {
|
|
6
|
-
canProceed: boolean;
|
|
7
|
-
currentTokens: number;
|
|
8
|
-
maxTokens: number;
|
|
9
|
-
utilizationPercent: number;
|
|
10
|
-
needsCompaction: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class ContextGuard {
|
|
14
|
-
private config: Config;
|
|
15
|
-
private log = logger.child("context-guard");
|
|
16
|
-
|
|
17
|
-
constructor(config: Config) {
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
estimateTokens(messages: Message[]): number {
|
|
22
|
-
let total = 0;
|
|
23
|
-
|
|
24
|
-
for (const msg of messages) {
|
|
25
|
-
total += Math.ceil(msg.content.length / 4);
|
|
26
|
-
|
|
27
|
-
if (msg.name) {
|
|
28
|
-
total += Math.ceil(msg.name.length / 4);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (msg.tool_calls) {
|
|
32
|
-
for (const tc of msg.tool_calls) {
|
|
33
|
-
total += Math.ceil(tc.function.name.length / 4);
|
|
34
|
-
total += Math.ceil(tc.function.arguments.length / 4);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return total;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
check(messages: Message[], systemPrompt?: string): ContextGuardResult {
|
|
43
|
-
const maxTokens = this.config.agent?.context?.maxTokens || 128000;
|
|
44
|
-
const threshold = this.config.agent?.context?.compactionThreshold || 0.8;
|
|
45
|
-
|
|
46
|
-
let currentTokens = this.estimateTokens(messages);
|
|
47
|
-
|
|
48
|
-
if (systemPrompt) {
|
|
49
|
-
currentTokens += Math.ceil(systemPrompt.length / 4);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
currentTokens += 500;
|
|
53
|
-
|
|
54
|
-
const utilizationPercent = currentTokens / maxTokens;
|
|
55
|
-
const needsCompaction = utilizationPercent >= threshold;
|
|
56
|
-
const canProceed = currentTokens < maxTokens * 0.95;
|
|
57
|
-
|
|
58
|
-
this.log.debug(`Context check: ${currentTokens}/${maxTokens} tokens (${(utilizationPercent * 100).toFixed(1)}%)`);
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
canProceed,
|
|
62
|
-
currentTokens,
|
|
63
|
-
maxTokens,
|
|
64
|
-
utilizationPercent,
|
|
65
|
-
needsCompaction,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
shouldCompact(messages: Message[], systemPrompt?: string): boolean {
|
|
70
|
-
const result = this.check(messages, systemPrompt);
|
|
71
|
-
return result.needsCompaction;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getRecommendedAction(messages: Message[], systemPrompt?: string): "proceed" | "compact" | "error" {
|
|
75
|
-
const result = this.check(messages, systemPrompt);
|
|
76
|
-
|
|
77
|
-
if (result.utilizationPercent >= 0.95) {
|
|
78
|
-
return "error";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (result.needsCompaction) {
|
|
82
|
-
return "compact";
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return "proceed";
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function createContextGuard(config: Config): ContextGuard {
|
|
90
|
-
return new ContextGuard(config);
|
|
91
|
-
}
|