@johpaz/hive-agents 0.0.47 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +119 -902
- package/dist/hive.js +68840 -68355
- package/dist/tool-worker.js +220 -925
- package/dist/ui/assets/A2UIPage-D4nUFe5q.js +8 -0
- package/dist/ui/assets/AgentCreateForm-g1mQnIoJ.js +1 -0
- package/dist/ui/assets/AgentDetailPage-C3XkU4Ll.js +1 -0
- package/dist/ui/assets/AgentNewPage-CEkLeA79.js +1 -0
- package/dist/ui/assets/AgentsPage-CNA778Eo.js +10 -0
- package/dist/ui/assets/ApiClientPage-t5DpKhmA.js +3 -0
- package/dist/ui/assets/ChannelsPage-yY6t0YTU.js +8 -0
- package/dist/ui/assets/DashboardPage-BSeNSYg5.js +6 -0
- package/dist/ui/assets/{LoginPage-BTxJdFVG.js → LoginPage-eT5zDRDa.js} +1 -1
- package/dist/ui/assets/{LogsPage-DVV2eHbh.js → LogsPage-Gczzzsdh.js} +1 -1
- package/dist/ui/assets/MeetingPage-Bu4aMMNR.js +1 -0
- package/dist/ui/assets/ModelSelector-nNOrW3te.js +1 -0
- package/dist/ui/assets/{NotFound-BIUDlIXU.js → NotFound-Bpr12V51.js} +1 -1
- package/dist/ui/assets/Office3DPage-B_iXEbyv.js +4614 -0
- package/dist/ui/assets/Office3DPage-C3SIzd2H.css +1 -0
- package/dist/ui/assets/ProvidersPage-BupHs5yO.js +1 -0
- package/dist/ui/assets/{RecoverPage-7YDQysBL.js → RecoverPage-DMqSasKk.js} +1 -1
- package/dist/ui/assets/SettingsPage-B6FTSkOn.js +9 -0
- package/dist/ui/assets/SetupPage-DhcRbGgg.js +1 -0
- package/dist/ui/assets/WebChatPage-CWXjW4Hn.js +29 -0
- package/dist/ui/assets/{activity-c3pNngT_.js → activity-CQuPevhB.js} +1 -1
- package/dist/ui/assets/agentCapabilities-CDC6y91E.js +1 -0
- package/dist/ui/assets/alert-CQlRq6sv.js +1 -0
- package/dist/ui/assets/arrow-left-0EBE7nsF.js +1 -0
- package/dist/ui/assets/arrow-right-5QIaph-z.js +1 -0
- package/dist/ui/assets/arrow-up-right-DQQCY007.js +1 -0
- package/dist/ui/assets/badge-DKGZbVZJ.js +1 -0
- package/dist/ui/assets/{calendar-B-KZ9RQO.js → calendar-Be23hQGc.js} +1 -1
- package/dist/ui/assets/{card-CNf6BS2e.js → card-D3Nw3kh3.js} +1 -1
- package/dist/ui/assets/check-Dp6tzwax.js +1 -0
- package/dist/ui/assets/chevron-down-33N886NY.js +1 -0
- package/dist/ui/assets/chevron-left-C6itJXh3.js +1 -0
- package/dist/ui/assets/chevron-right-CFodBS-b.js +1 -0
- package/dist/ui/assets/chevron-up-BvSmyBEs.js +1 -0
- package/dist/ui/assets/{circle-alert-KuAm2FWh.js → circle-alert-BDVHxmAz.js} +1 -1
- package/dist/ui/assets/circle-check-BJWNbLuF.js +1 -0
- package/dist/ui/assets/{circle-x-DjLkFDO8.js → circle-x-Cb2Yer4s.js} +1 -1
- package/dist/ui/assets/{copy-Bu5d7C-0.js → copy-33tZrzc9.js} +1 -1
- package/dist/ui/assets/{dialog-Jk4bieO4.js → dialog-KOZKWbib.js} +1 -1
- package/dist/ui/assets/dist-CD_qfA30.js +1 -0
- package/dist/ui/assets/{download-Cjbk4Rek.js → download-CiQqqXyz.js} +1 -1
- package/dist/ui/assets/earth-DCvN7ynm.js +1 -0
- package/dist/ui/assets/ellipsis-vertical-BybFZDk2.js +1 -0
- package/dist/ui/assets/{external-link-6sTlRDUR.js → external-link-0iNNBvZm.js} +1 -1
- package/dist/ui/assets/{eye-Df8o0tkC.js → eye-C8sKSSkg.js} +1 -1
- package/dist/ui/assets/{file-text-lnxnjBp0.js → file-text-DO8jqiJK.js} +1 -1
- package/dist/ui/assets/{gateway-url-DwzPmoc8.js → gateway-url-BlnabM5e.js} +1 -1
- package/dist/ui/assets/gauge-BRGwuN8G.js +1 -0
- package/dist/ui/assets/{history-CAF_R34_.js → history-BtTD1kDo.js} +1 -1
- package/dist/ui/assets/index-Bejlp-R1.js +116 -0
- package/dist/ui/assets/index-XoTT41Hr.css +2 -0
- package/dist/ui/assets/{info-WjromB4Y.js → info-mpk1tsNC.js} +1 -1
- package/dist/ui/assets/key-CoQ0qtXt.js +1 -0
- package/dist/ui/assets/label-k0jYxoWW.js +1 -0
- package/dist/ui/assets/loader-circle-BhqRN2nO.js +1 -0
- package/dist/ui/assets/lock-open-Cd2aqwOd.js +1 -0
- package/dist/ui/assets/mail-BG0RYSkL.js +1 -0
- package/dist/ui/assets/{pause-VqeUmp2Z.js → pause-Cme88_9s.js} +1 -1
- package/dist/ui/assets/pencil-f1nJ1xhs.js +1 -0
- package/dist/ui/assets/play-CfYDHD6h.js +1 -0
- package/dist/ui/assets/plus-C5BxJeOX.js +1 -0
- package/dist/ui/assets/progress-DrI2UDu-.js +1 -0
- package/dist/ui/assets/radio-B5SpKJ-J.js +1 -0
- package/dist/ui/assets/{refresh-cw-CCzDCAuz.js → refresh-cw-CroGQY62.js} +1 -1
- package/dist/ui/assets/scroll-area-CfHn94Vb.js +1 -0
- package/dist/ui/assets/search-rfBcmohK.js +1 -0
- package/dist/ui/assets/select-BhbW0stK.js +1 -0
- package/dist/ui/assets/{send-BPk9XbIq.js → send-D6whYpw-.js} +1 -1
- package/dist/ui/assets/{settings-BGfrZ_zM.js → settings-BX6q3MGB.js} +1 -1
- package/dist/ui/assets/{shield-CxhcUT39.js → shield-BnGyu1xf.js} +1 -1
- package/dist/ui/assets/slider-CmE_z1Ii.js +1 -0
- package/dist/ui/assets/{sparkles-BhwlS1pc.js → sparkles-BcaOs_Jk.js} +1 -1
- package/dist/ui/assets/{square-DMNWw4Hi.js → square-ju5H8nrT.js} +1 -1
- package/dist/ui/assets/switch-DXcELPsM.js +1 -0
- package/dist/ui/assets/tabs-CxiybXcw.js +1 -0
- package/dist/ui/assets/terminal-Bjfu-TkS.js +1 -0
- package/dist/ui/assets/{textarea-B6Z1Zc6W.js → textarea-rp6vsOZl.js} +1 -1
- package/dist/ui/assets/{trash-2-xD2o4SgX.js → trash-2-DjQXac_0.js} +1 -1
- package/dist/ui/assets/{triangle-alert-pVIJGjga.js → triangle-alert-B04mgMcg.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-BnC4jLE-.js → useHiveAgentsModelLoad-DT5-4CCj.js} +1 -1
- package/dist/ui/assets/useOfficeModel-Cy7cAyEn.js +1 -0
- package/dist/ui/assets/useProviders-DSX7eVsz.js +1 -0
- package/dist/ui/assets/utils-Dyb7SC2_.js +1 -0
- package/dist/ui/assets/vendor-charts-K3xcRl0X.js +60 -0
- package/dist/ui/assets/{vendor-query-DsWPbQdG.js → vendor-query-Dj8xYhQD.js} +1 -1
- package/dist/ui/assets/vendor-radix-D0s_k6Gp.js +63 -0
- package/dist/ui/assets/vendor-react-CPJEWbIG.js +1 -0
- package/dist/ui/assets/{vendor-router-gqiZ7xhx.js → vendor-router-zpB-76nT.js} +1 -1
- package/dist/ui/assets/volume-x-qnVxkRSM.js +1 -0
- package/dist/ui/assets/wifi-BA1m2dGO.js +1 -0
- package/dist/ui/assets/{zap-B4RaNNO5.js → zap-DT7cM7YS.js} +1 -1
- package/dist/ui/index.html +10 -9
- package/package.json +8 -9
- package/packages/cli/src/adapters/config.ts +1 -80
- package/packages/cli/src/adapters/factory.ts +0 -45
- package/packages/cli/src/adapters/index.ts +0 -8
- package/packages/cli/src/commands/doctor.ts +45 -1
- package/packages/cli/src/commands/gateway.ts +2 -9
- package/packages/cli/src/index.ts +9 -11
- package/packages/core/src/agent/acceptance-verifier.ts +300 -0
- package/packages/core/src/agent/agent-catalog.ts +384 -0
- package/packages/core/src/agent/agent-loop.ts +185 -28
- package/packages/core/src/agent/capability-search.ts +5 -5
- package/packages/core/src/agent/catalog-selector.ts +104 -0
- package/packages/core/src/agent/compaction.ts +36 -41
- package/packages/core/src/agent/context-compiler.ts +182 -62
- package/packages/core/src/agent/conversation-store.ts +56 -3
- package/packages/core/src/agent/curator.ts +129 -34
- package/packages/core/src/agent/delegation-runtime.ts +248 -0
- package/packages/core/src/agent/index.ts +17 -0
- package/packages/core/src/agent/llm-providers/hiveagents.ts +1 -1
- package/packages/core/src/agent/llm-providers/interface.ts +3 -3
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
- package/packages/core/src/agent/minimal-loadout.ts +46 -0
- package/packages/core/src/agent/playbook-selector.ts +1 -1
- package/packages/core/src/agent/prompt-builder.ts +4 -0
- package/packages/core/src/agent/proof-packet.ts +15 -1
- package/packages/core/src/agent/providers/index.ts +8 -3
- package/packages/core/src/agent/routing-intent.ts +22 -0
- package/packages/core/src/agent/run-store.ts +24 -3
- package/packages/core/src/agent/service.ts +2 -2
- package/packages/core/src/agent/skill-selector.ts +12 -31
- package/packages/core/src/agent/tool-selector.ts +36 -35
- package/packages/core/src/agent/tracer.ts +5 -1
- package/packages/core/src/artifacts/store.ts +162 -0
- package/packages/core/src/canvas/canvas-manager.ts +5 -234
- package/packages/core/src/canvas/emitter.ts +165 -69
- package/packages/core/src/canvas/index.ts +0 -2
- package/packages/core/src/channels/base.ts +3 -1
- package/packages/core/src/channels/webchat.ts +4 -8
- package/packages/core/src/config/loader.ts +0 -22
- package/packages/core/src/events/agent-bus.ts +0 -31
- package/packages/core/src/events/narration.ts +82 -0
- package/packages/core/src/gateway/channel-notify.ts +34 -5
- package/packages/core/src/gateway/delegation-groups.ts +245 -0
- package/packages/core/src/gateway/delegation-notify.ts +103 -0
- package/packages/core/src/gateway/durable-queue.ts +33 -2
- package/packages/core/src/gateway/helpers/index.ts +2 -2
- package/packages/core/src/gateway/helpers/narration.ts +12 -7
- package/packages/core/src/gateway/helpers/redact.ts +1 -1
- package/packages/core/src/gateway/initializer.ts +15 -13
- package/packages/core/src/gateway/job-executors.ts +232 -101
- package/packages/core/src/gateway/lane-queue.ts +1 -1
- package/packages/core/src/gateway/notification-inbox.ts +57 -0
- package/packages/core/src/gateway/resolver.ts +1 -23
- package/packages/core/src/gateway/routes/agents.ts +91 -1
- package/packages/core/src/gateway/routes/auth.ts +21 -42
- package/packages/core/src/gateway/routes/chat.ts +6 -6
- package/packages/core/src/gateway/routes/cron-api.ts +0 -4
- package/packages/core/src/gateway/routes/mcp.ts +0 -63
- package/packages/core/src/gateway/routes/meeting.ts +245 -0
- package/packages/core/src/gateway/routes/providers.ts +1 -0
- package/packages/core/src/gateway/routes/setup.ts +29 -24
- package/packages/core/src/gateway/routes/skills.ts +2 -2
- package/packages/core/src/gateway/routes/system.ts +23 -5
- package/packages/core/src/gateway/routes/users.ts +24 -1
- package/packages/core/src/gateway/server.ts +153 -117
- package/packages/core/src/gateway/session.ts +6 -4
- package/packages/core/src/gateway/slash-commands.ts +7 -6
- package/packages/core/src/gateway/webchat-turn.ts +34 -8
- package/packages/core/src/index.ts +3 -0
- package/packages/core/src/mcp/hot-reload.ts +14 -7
- package/packages/core/src/mcp/singleton.ts +0 -3
- package/packages/core/src/mcp/tool-sync.ts +2 -2
- package/packages/core/src/resilience/retry.ts +1 -1
- package/packages/core/src/scheduler/CronScheduler.ts +3 -1
- package/packages/core/src/scheduler/integration.ts +1 -1
- package/packages/core/src/storage/bootstrap.ts +25 -5
- package/packages/core/src/storage/collections.ts +201 -27
- package/packages/core/src/storage/onboarding.ts +147 -32
- package/packages/core/src/storage/reconcile.ts +2 -5
- package/packages/core/src/storage/seed.ts +196 -34
- package/packages/core/src/storage/usage.ts +0 -9
- package/packages/core/src/storage/user-email.ts +11 -0
- package/packages/core/src/tool-runtime/index.ts +69 -23
- package/packages/core/src/tool-runtime/worker-tools.ts +4 -2
- package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
- package/packages/core/src/tools/agents/index.ts +392 -83
- package/packages/core/src/tools/core/index.ts +28 -10
- package/packages/core/src/tools/cron/index.ts +1 -6
- package/packages/core/src/tools/index.ts +17 -45
- package/packages/core/src/tools/types.ts +1 -1
- package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
- package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
- package/packages/core/src/tools/web/index.ts +3 -0
- package/packages/core/src/utils/logger.ts +58 -30
- package/packages/core/src/utils/toon.ts +0 -20
- package/packages/mcp/src/manager.ts +8 -7
- package/packages/mcp/src/transports/sse.ts +0 -4
- package/packages/mcp/src/transports/websocket.ts +0 -6
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_dashboard/SKILL.md +4 -4
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_form/SKILL.md +4 -4
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_interactive/SKILL.md +5 -5
- package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +26 -0
- package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +24 -18
- package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +47 -148
- package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +9 -10
- package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +1 -1
- package/packages/skills/src/bundled/cli/software_engineering/SKILL.md +23 -0
- package/packages/skills/src/bundled/cron_manager/SKILL.md +2 -2
- package/packages/skills/src/bundled/cron_reminder/SKILL.md +7 -7
- package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +11 -10
- package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +29 -35
- package/packages/skills/src/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
- package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +5 -4
- package/packages/skills/src/bundled-data.generated.ts +690 -1255
- package/dist/ui/assets/AgentCreateForm-DzaIT-dA.js +0 -1
- package/dist/ui/assets/AgentDetailPage-DgqcJceY.js +0 -1
- package/dist/ui/assets/AgentNewPage-CNSpoOSA.js +0 -1
- package/dist/ui/assets/AgentsPage-BMUJzTD6.js +0 -10
- package/dist/ui/assets/ApiClientPage-Cum_a_3j.js +0 -3
- package/dist/ui/assets/CanvasPage-o6oCP6uq.js +0 -33
- package/dist/ui/assets/ChannelsPage-WrB0zwLq.js +0 -8
- package/dist/ui/assets/DashboardPage-BCd6kNw0.js +0 -6
- package/dist/ui/assets/MeetingPage-BULIAWzq.js +0 -1
- package/dist/ui/assets/ModelSelector-BMYOChYb.js +0 -1
- package/dist/ui/assets/ProvidersPage-BVN5UZrI.js +0 -1
- package/dist/ui/assets/SettingsPage-CYmpFfDn.js +0 -9
- package/dist/ui/assets/SetupPage-Dnmb1Lbv.js +0 -1
- package/dist/ui/assets/WebChatPage-DmmdFhIC.js +0 -16
- package/dist/ui/assets/accordion-CnLzKNHK.js +0 -1
- package/dist/ui/assets/alert-B9J6KHmt.js +0 -1
- package/dist/ui/assets/alert-dialog-KcYQWcJ6.js +0 -1
- package/dist/ui/assets/arrow-left-CBcbX5EZ.js +0 -1
- package/dist/ui/assets/badge-88dRb4M8.js +0 -1
- package/dist/ui/assets/bell-8BqRYmzf.js +0 -1
- package/dist/ui/assets/chevron-down-DIosfU_U.js +0 -1
- package/dist/ui/assets/chevron-left-D4U-5A27.js +0 -1
- package/dist/ui/assets/chevron-right-CR4Skrf3.js +0 -1
- package/dist/ui/assets/chevron-up-CI-W21Fy.js +0 -1
- package/dist/ui/assets/circle-check-6Ard1-2z.js +0 -1
- package/dist/ui/assets/dropdown-menu-DDiaHg5y.js +0 -1
- package/dist/ui/assets/es-4I-joeZz.js +0 -1
- package/dist/ui/assets/folder-open-DJBLDFjv.js +0 -1
- package/dist/ui/assets/format-DsLPBxvt.js +0 -1
- package/dist/ui/assets/gauge-B8Tj43rC.js +0 -1
- package/dist/ui/assets/hexagon-6L79pgVK.js +0 -1
- package/dist/ui/assets/index-BmwTAwOF.css +0 -2
- package/dist/ui/assets/index-Cyw7L0Li.js +0 -116
- package/dist/ui/assets/key-DyKOoQh5.js +0 -1
- package/dist/ui/assets/label-B_15zZlR.js +0 -1
- package/dist/ui/assets/loader-circle-BmBOgYze.js +0 -1
- package/dist/ui/assets/lock-BS6OLXPv.js +0 -1
- package/dist/ui/assets/play-zJpWuhrr.js +0 -1
- package/dist/ui/assets/plus-BZQX26Dr.js +0 -1
- package/dist/ui/assets/progress-D5c-Eilm.js +0 -1
- package/dist/ui/assets/scroll-area-CihOx0cb.js +0 -1
- package/dist/ui/assets/search-DzDptO9s.js +0 -1
- package/dist/ui/assets/select-BQCOjM2j.js +0 -1
- package/dist/ui/assets/slider-bcUiUfx0.js +0 -14
- package/dist/ui/assets/switch-BR30E4ej.js +0 -1
- package/dist/ui/assets/table-B3aGEaVp.js +0 -1
- package/dist/ui/assets/tabs-LQidMKRS.js +0 -1
- package/dist/ui/assets/terminal--7G943As.js +0 -1
- package/dist/ui/assets/useProviders-C1xVKLxB.js +0 -1
- package/dist/ui/assets/utils-3pnRFmFe.js +0 -1
- package/dist/ui/assets/vendor-charts-Bu2lyBKP.js +0 -65
- package/dist/ui/assets/vendor-radix-D6rA7xKY.js +0 -63
- package/dist/ui/assets/vendor-react-BU5iQU4f.js +0 -1
- package/dist/ui/assets/volume-2-BekVQl6P.js +0 -1
- package/packages/core/src/agent/context-guard.ts +0 -91
- package/packages/core/src/agent/hooks.ts +0 -166
- package/packages/core/src/agent/providers.ts +0 -1
- package/packages/core/src/auth/auth.ts +0 -111
- package/packages/core/src/auth/index.ts +0 -1
- package/packages/core/src/canvas/canvas-tools.ts +0 -448
- package/packages/core/src/gateway/router.ts +0 -126
- package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
- package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
- package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
- package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
- package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
- package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
- package/packages/core/src/scheduler/dag/errors.ts +0 -37
- package/packages/core/src/scheduler/dag/index.ts +0 -26
- package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
- package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
- package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
- package/packages/core/src/scheduler/index.ts +0 -22
- package/packages/core/src/scheduler/task-driver.ts +0 -216
- package/packages/core/src/tools/canvas/index.ts +0 -420
- package/packages/core/src/tools/meeting/index.ts +0 -336
- package/packages/core/src/tools/projects/index.ts +0 -348
- package/packages/core/src/tools/voice/index.ts +0 -104
- package/packages/core/src/utils/index.ts +0 -5
- package/packages/skills/src/bundled/agents/code_delegator/SKILL.md +0 -156
- package/packages/skills/src/bundled/canvas/canvas_dashboard/SKILL.md +0 -146
- package/packages/skills/src/bundled/canvas/canvas_interact/SKILL.md +0 -148
- package/packages/skills/src/bundled/canvas/canvas_report/SKILL.md +0 -146
- package/packages/skills/src/bundled/meeting/meeting_transcription/SKILL.md +0 -213
- package/packages/skills/src/bundled/voice/voice_assistant/SKILL.md +0 -174
- package/packages/skills/src/bundled/voice/voice_input/SKILL.md +0 -146
- package/packages/skills/src/bundled/voice/voice_output/SKILL.md +0 -151
|
@@ -6,23 +6,26 @@
|
|
|
6
6
|
* - Repeated patterns → increment helpful_count
|
|
7
7
|
* - Contradicted rules → increment harmful_count or deactivate
|
|
8
8
|
* - Deactivate rules where harmful_count > helpful_count
|
|
9
|
-
* - Archive unused workers
|
|
10
9
|
*
|
|
11
10
|
* Never rewrites the whole playbook — only incremental edits.
|
|
12
11
|
*
|
|
13
12
|
* "Last processed reflection" is tracked via a `cursors` collection doc
|
|
14
13
|
* (id="curator:lastReflection") instead of SQL's MAX(source_reflection_id).
|
|
15
|
-
* Stale-worker detection uses the denormalized `agents.lastTraceAt` field
|
|
16
|
-
* (set by tracer.ts) instead of a correlated MAX(t.created_at) subquery.
|
|
17
14
|
*/
|
|
18
15
|
|
|
19
16
|
import { logger } from "../utils/logger"
|
|
20
17
|
import { col, nextId, toIndexable, fromIndexable } from "../storage/hive"
|
|
21
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
ReflectionDoc,
|
|
20
|
+
PlaybookDoc,
|
|
21
|
+
AgentDoc,
|
|
22
|
+
CursorDoc,
|
|
23
|
+
AgentProposalDoc,
|
|
24
|
+
TraceDoc,
|
|
25
|
+
} from "../storage/collections"
|
|
22
26
|
|
|
23
27
|
const log = logger.child("curator")
|
|
24
28
|
|
|
25
|
-
const DAYS_BEFORE_ARCHIVE = 14 // archive workers not used in N days
|
|
26
29
|
const MAX_HARMFUL_BEFORE_PRUNE = 3
|
|
27
30
|
const CURSOR_ID = "curator:lastReflection"
|
|
28
31
|
|
|
@@ -32,8 +35,6 @@ export async function runCurator(): Promise<void> {
|
|
|
32
35
|
const cursorsCol = await col<CursorDoc>("cursors")
|
|
33
36
|
const playbookCol = await col<PlaybookDoc>("playbook")
|
|
34
37
|
const reflectionsCol = await col<ReflectionDoc>("reflections")
|
|
35
|
-
const agentsCol = await col<AgentDoc>("agents")
|
|
36
|
-
|
|
37
38
|
// Process unprocessed reflections (those newer than last run)
|
|
38
39
|
const cursorEntry = await cursorsCol.get(CURSOR_ID)
|
|
39
40
|
const lastProcessed = cursorEntry?.doc.value ?? null
|
|
@@ -63,31 +64,7 @@ export async function runCurator(): Promise<void> {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
// (set by tracer.ts) instead of a correlated MAX(created_at) subquery.
|
|
68
|
-
const cutoff = Date.now() - (DAYS_BEFORE_ARCHIVE * 86400 * 1000)
|
|
69
|
-
const allAgents = await agentsCol.scan({})
|
|
70
|
-
const staleWorkers = allAgents.filter(e =>
|
|
71
|
-
e.doc.role === "worker" &&
|
|
72
|
-
e.doc.status !== "archived" &&
|
|
73
|
-
e.doc.enabled &&
|
|
74
|
-
(e.doc.lastTraceAt ?? 0) < cutoff
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
for (const worker of staleWorkers) {
|
|
78
|
-
await agentsCol.put(worker.id, { ...worker.doc, status: "archived", updated_at: Date.now() }, { expectedVersion: worker.version })
|
|
79
|
-
|
|
80
|
-
// Add playbook note about archival
|
|
81
|
-
const currentPlaybook = await playbookCol.scan({})
|
|
82
|
-
await addOrUpdateRule(playbookCol, currentPlaybook, {
|
|
83
|
-
rule: `Worker '${worker.doc.name}' was archived due to inactivity (>${DAYS_BEFORE_ARCHIVE} days unused).`,
|
|
84
|
-
category: "agent_creation",
|
|
85
|
-
applicable_to: null,
|
|
86
|
-
sourceReflectionId: null,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
log.info(`[curator] Archived inactive worker: ${worker.doc.name} (${worker.id})`)
|
|
90
|
-
}
|
|
67
|
+
await curateAgentStructure()
|
|
91
68
|
|
|
92
69
|
log.info("[curator] Playbook updated")
|
|
93
70
|
} catch (err) {
|
|
@@ -95,6 +72,115 @@ export async function runCurator(): Promise<void> {
|
|
|
95
72
|
}
|
|
96
73
|
}
|
|
97
74
|
|
|
75
|
+
async function curateAgentStructure(): Promise<void> {
|
|
76
|
+
const agentsCol = await col<AgentDoc>("agents")
|
|
77
|
+
const proposalsCol = await col<AgentProposalDoc>("agentProposals")
|
|
78
|
+
const tracesCol = await col<TraceDoc>("traces")
|
|
79
|
+
const now = Date.now()
|
|
80
|
+
|
|
81
|
+
// A catalog agent is a capability, not a disposable worker: disabling
|
|
82
|
+
// `workspace_file_operator` takes filesystem work away from the whole hive
|
|
83
|
+
// and nothing replaces it, so a bad streak can never switch one off by
|
|
84
|
+
// itself. It raises a proposal for a human to decide instead — and the ACE
|
|
85
|
+
// counters keep accumulating either way, so routing still sees the signal.
|
|
86
|
+
for (const entry of await agentsCol.findBy("source", "catalog")) {
|
|
87
|
+
if (!entry.doc.enabled) continue
|
|
88
|
+
const helpful = entry.doc.helpful_count ?? 0
|
|
89
|
+
const harmful = entry.doc.harmful_count ?? 0
|
|
90
|
+
if (harmful > helpful && harmful >= MAX_HARMFUL_BEFORE_PRUNE) {
|
|
91
|
+
await ensureAgentProposal(proposalsCol, {
|
|
92
|
+
type: "disable_agent",
|
|
93
|
+
agentId: entry.id,
|
|
94
|
+
change: { active: false, reason: "harmful_count exceeded helpful_count" },
|
|
95
|
+
evidence: [],
|
|
96
|
+
confidence: 1,
|
|
97
|
+
})
|
|
98
|
+
log.warn(`[curator] Catalog agent '${entry.doc.name}' (${entry.id}) is failing verification (helpful=${helpful}, harmful=${harmful}) — proposed for review, left enabled`)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const traces = (await tracesCol.scan({})).map((entry) => entry.doc)
|
|
103
|
+
const agents = new Map((await agentsCol.scan({})).map((entry) => [entry.id, entry.doc]))
|
|
104
|
+
|
|
105
|
+
// Recurrent successful free workers are candidates for a learned template.
|
|
106
|
+
const freeSuccess = new Map<string, TraceDoc[]>()
|
|
107
|
+
for (const trace of traces) {
|
|
108
|
+
const agent = agents.get(trace.agent_id)
|
|
109
|
+
if (!trace.success || trace.tool_used || trace.catalog_agent_id || agent?.role !== "worker" || agent.source === "catalog") continue
|
|
110
|
+
const bucket = freeSuccess.get(trace.agent_id) ?? []
|
|
111
|
+
bucket.push(trace)
|
|
112
|
+
freeSuccess.set(trace.agent_id, bucket)
|
|
113
|
+
}
|
|
114
|
+
for (const [agentId, evidence] of freeSuccess) {
|
|
115
|
+
if (evidence.length < 5) continue
|
|
116
|
+
const agent = agents.get(agentId)!
|
|
117
|
+
await ensureAgentProposal(proposalsCol, {
|
|
118
|
+
type: "create_agent",
|
|
119
|
+
agentId: `candidate:${agentId}`,
|
|
120
|
+
change: {
|
|
121
|
+
suggested_name: agent.name,
|
|
122
|
+
suggested_description: agent.description,
|
|
123
|
+
observed_tasks: evidence.slice(-5).map((trace) => trace.input_summary),
|
|
124
|
+
},
|
|
125
|
+
evidence: evidence.slice(-5).map((trace) => trace.id),
|
|
126
|
+
confidence: Math.min(0.95, 0.5 + evidence.length * 0.05),
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Repeated failures identify a loadout mismatch. This remains a proposal;
|
|
131
|
+
// permissions are never changed automatically.
|
|
132
|
+
const failures = new Map<string, TraceDoc[]>()
|
|
133
|
+
for (const trace of traces) {
|
|
134
|
+
if (trace.success || !trace.catalog_agent_id || !trace.tool_used) continue
|
|
135
|
+
const key = `${trace.catalog_agent_id}\0${trace.tool_used}`
|
|
136
|
+
const bucket = failures.get(key) ?? []
|
|
137
|
+
bucket.push(trace)
|
|
138
|
+
failures.set(key, bucket)
|
|
139
|
+
}
|
|
140
|
+
for (const [key, evidence] of failures) {
|
|
141
|
+
if (evidence.length < 3) continue
|
|
142
|
+
const [agentId, tool] = key.split("\0")
|
|
143
|
+
await ensureAgentProposal(proposalsCol, {
|
|
144
|
+
type: "move_tool",
|
|
145
|
+
agentId,
|
|
146
|
+
change: { tool, reason: "repeated failures; review ownership or remove from loadout" },
|
|
147
|
+
evidence: evidence.slice(-10).map((trace) => trace.id),
|
|
148
|
+
confidence: Math.min(0.95, 0.55 + evidence.length * 0.05),
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const { syncCatalogAgentsToIndex } = await import("./catalog-selector")
|
|
153
|
+
await syncCatalogAgentsToIndex()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function ensureAgentProposal(
|
|
157
|
+
proposalsCol: Awaited<ReturnType<typeof col<AgentProposalDoc>>>,
|
|
158
|
+
input: {
|
|
159
|
+
type: AgentProposalDoc["type"]
|
|
160
|
+
agentId: string
|
|
161
|
+
change: unknown
|
|
162
|
+
evidence: string[]
|
|
163
|
+
confidence: number
|
|
164
|
+
},
|
|
165
|
+
): Promise<void> {
|
|
166
|
+
const existing = (await proposalsCol.findBy("agent_id", input.agentId))
|
|
167
|
+
.find((entry) => entry.doc.type === input.type && entry.doc.status === "proposed")
|
|
168
|
+
if (existing) return
|
|
169
|
+
const id = await nextId("agentProposals")
|
|
170
|
+
const now = Date.now()
|
|
171
|
+
await proposalsCol.put(id, {
|
|
172
|
+
id,
|
|
173
|
+
type: input.type,
|
|
174
|
+
agent_id: input.agentId,
|
|
175
|
+
proposed_change_json: JSON.stringify(input.change),
|
|
176
|
+
evidence_trace_ids_json: JSON.stringify(input.evidence),
|
|
177
|
+
confidence: input.confidence,
|
|
178
|
+
status: "proposed",
|
|
179
|
+
created_at: now,
|
|
180
|
+
updated_at: now,
|
|
181
|
+
}, { expectedVersion: 0 })
|
|
182
|
+
}
|
|
183
|
+
|
|
98
184
|
// ─── Process a single reflection ─────────────────────────────────────────────
|
|
99
185
|
|
|
100
186
|
async function processReflection(
|
|
@@ -103,6 +189,15 @@ async function processReflection(
|
|
|
103
189
|
reflection: ReflectionDoc
|
|
104
190
|
): Promise<void> {
|
|
105
191
|
const category = mapInsightTypeToCategory(reflection.insight_type)
|
|
192
|
+
const applicable: string[] = reflection.affected_tools ? JSON.parse(reflection.affected_tools) : []
|
|
193
|
+
if (reflection.affected_agents) {
|
|
194
|
+
const agentsCol = await col<AgentDoc>("agents")
|
|
195
|
+
for (const agentId of JSON.parse(reflection.affected_agents) as string[]) {
|
|
196
|
+
const agent = await agentsCol.get(agentId)
|
|
197
|
+
if (agent?.doc.source === "catalog") applicable.push(`agent:${agent.doc.id}`)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const applicableTo = applicable.length ? JSON.stringify([...new Set(applicable)]) : null
|
|
106
201
|
|
|
107
202
|
// Check if a similar rule already exists (fuzzy check by first 60 chars)
|
|
108
203
|
const prefix = reflection.description.substring(0, 60)
|
|
@@ -121,7 +216,7 @@ async function processReflection(
|
|
|
121
216
|
id,
|
|
122
217
|
rule: reflection.description,
|
|
123
218
|
category,
|
|
124
|
-
applicable_to:
|
|
219
|
+
applicable_to: applicableTo,
|
|
125
220
|
helpful_count: 1,
|
|
126
221
|
harmful_count: 0,
|
|
127
222
|
active: true,
|
|
@@ -129,7 +224,7 @@ async function processReflection(
|
|
|
129
224
|
created_at: now,
|
|
130
225
|
updated_at: now,
|
|
131
226
|
}, { expectedVersion: 0 })
|
|
132
|
-
allPlaybook.push({ id, version: 1, doc: { id, rule: reflection.description, category, applicable_to:
|
|
227
|
+
allPlaybook.push({ id, version: 1, doc: { id, rule: reflection.description, category, applicable_to: applicableTo, helpful_count: 1, harmful_count: 0, active: true, source_reflection_id: toIndexable(reflection.id), created_at: now, updated_at: now } })
|
|
133
228
|
}
|
|
134
229
|
|
|
135
230
|
function mapInsightTypeToCategory(
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { col, toIndexable, fromIndexable, updateDoc } from "../storage/hive";
|
|
2
|
+
import type {
|
|
3
|
+
AgentDoc,
|
|
4
|
+
McpServerDoc,
|
|
5
|
+
ModelDoc,
|
|
6
|
+
ProviderDoc,
|
|
7
|
+
SkillDoc,
|
|
8
|
+
AgentModelOverride,
|
|
9
|
+
} from "../storage/collections";
|
|
10
|
+
import { createAllTools } from "../tools";
|
|
11
|
+
import { loadConfig } from "../config/loader";
|
|
12
|
+
import type { MCPClientManager } from "@johpaz/hive-agents-mcp";
|
|
13
|
+
import { logger } from "../utils/logger";
|
|
14
|
+
|
|
15
|
+
const log = logger.child("delegation-runtime");
|
|
16
|
+
const MCP_IDLE_TTL_MS = 2 * 60_000;
|
|
17
|
+
|
|
18
|
+
export interface PrepareDelegationOptions {
|
|
19
|
+
workspace: string | null;
|
|
20
|
+
/** Internal-only transient scope used by the independent verifier for readback. */
|
|
21
|
+
taskScopedMcpServerIds?: string[];
|
|
22
|
+
/** Fallback provider/model when the target row has none of its own (catalog agents are seeded without one — inherits the parent/coordinator's). */
|
|
23
|
+
parentProviderId?: string | null;
|
|
24
|
+
parentModelId?: string | null;
|
|
25
|
+
/** Model to avoid only during capability-based DB fallback resolution. Explicit agent/parent configuration always wins. */
|
|
26
|
+
executorModelId?: string | null;
|
|
27
|
+
mcpManager?: MCPClientManager | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface PreparedDelegation {
|
|
31
|
+
agent: AgentDoc;
|
|
32
|
+
toolNames: string[];
|
|
33
|
+
skillIds: string[];
|
|
34
|
+
mcpServerIds: string[];
|
|
35
|
+
providerId: string;
|
|
36
|
+
modelId: string;
|
|
37
|
+
release(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface McpLease {
|
|
41
|
+
refs: number;
|
|
42
|
+
serverName: string;
|
|
43
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const mcpLeases = new Map<string, McpLease>();
|
|
47
|
+
|
|
48
|
+
function matchesPattern(name: string, pattern: string): boolean {
|
|
49
|
+
if (!pattern.includes("*")) return name === pattern;
|
|
50
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
51
|
+
return new RegExp(`^${escaped}$`).test(name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function expandToolAllowlist(patterns: string[], availableNames?: string[]): string[] {
|
|
55
|
+
const names = availableNames ?? createAllTools(loadConfig()).map((tool) => tool.name);
|
|
56
|
+
const selected = names.filter((name) => patterns.some((pattern) => matchesPattern(name, pattern)));
|
|
57
|
+
return [...new Set(selected)].sort();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function parseCapabilities(model: ModelDoc): string[] {
|
|
61
|
+
try {
|
|
62
|
+
return model.capabilities ? JSON.parse(model.capabilities) : [];
|
|
63
|
+
} catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Resolves the effective provider/model for a delegation. Persisted database
|
|
70
|
+
* configuration is authoritative: the agent's complete provider/model pair
|
|
71
|
+
* wins, otherwise the parent's complete pair is inherited. Capability metadata
|
|
72
|
+
* is consulted only when neither row supplies a complete pair, and candidates
|
|
73
|
+
* are selected exclusively from active database rows.
|
|
74
|
+
*/
|
|
75
|
+
export async function resolveAgentModel(
|
|
76
|
+
modelOverride: AgentModelOverride | null,
|
|
77
|
+
rowProviderId: string | null,
|
|
78
|
+
rowModelId: string | null,
|
|
79
|
+
parentProviderId: string | null,
|
|
80
|
+
parentModelId: string | null,
|
|
81
|
+
executorModelId?: string | null,
|
|
82
|
+
): Promise<{ providerId: string; modelId: string }> {
|
|
83
|
+
if (rowProviderId && rowModelId) {
|
|
84
|
+
return { providerId: rowProviderId, modelId: rowModelId };
|
|
85
|
+
}
|
|
86
|
+
if (parentProviderId && parentModelId) {
|
|
87
|
+
return { providerId: parentProviderId, modelId: parentModelId };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fallback = {
|
|
91
|
+
providerId: rowProviderId ?? parentProviderId ?? "",
|
|
92
|
+
modelId: rowModelId ?? parentModelId ?? "",
|
|
93
|
+
};
|
|
94
|
+
if (!modelOverride) return fallback;
|
|
95
|
+
|
|
96
|
+
const models = (await (await col<ModelDoc>("models")).scan({})).map((entry) => entry.doc);
|
|
97
|
+
const providers = new Map(
|
|
98
|
+
(await (await col<ProviderDoc>("providers")).scan({}))
|
|
99
|
+
.map((entry) => entry.doc)
|
|
100
|
+
.filter((provider) => provider.enabled && provider.active)
|
|
101
|
+
.map((provider) => [provider.id, provider]),
|
|
102
|
+
);
|
|
103
|
+
const compatible = (model: ModelDoc) => {
|
|
104
|
+
if (!model.enabled || !providers.has(model.provider_id)) return false;
|
|
105
|
+
const caps = parseCapabilities(model);
|
|
106
|
+
if (!modelOverride.required_capabilities.every((cap) => caps.includes(cap))) return false;
|
|
107
|
+
if (modelOverride.prefer_different_family && executorModelId) {
|
|
108
|
+
const currentFamily = executorModelId.split(/[/:]/)[0];
|
|
109
|
+
const candidateFamily = model.id.split(/[/:]/)[0];
|
|
110
|
+
if (currentFamily === candidateFamily) return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const candidate = models.find(compatible);
|
|
116
|
+
return candidate ? { providerId: candidate.provider_id, modelId: candidate.id } : fallback;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function validateSkillIds(skillIds: string[]): Promise<string[]> {
|
|
120
|
+
const skills = await col<SkillDoc>("skills");
|
|
121
|
+
const valid: string[] = [];
|
|
122
|
+
for (const id of skillIds) {
|
|
123
|
+
const entry = await skills.get(id);
|
|
124
|
+
if (!entry?.doc.active) throw new Error(`Agent references missing or inactive skill: ${id}`);
|
|
125
|
+
valid.push(id);
|
|
126
|
+
}
|
|
127
|
+
return valid;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function acquireMcpLease(
|
|
131
|
+
serverId: string,
|
|
132
|
+
manager: MCPClientManager,
|
|
133
|
+
): Promise<{ serverId: string; serverName: string }> {
|
|
134
|
+
const entry = await (await col<McpServerDoc>("mcpServers")).get(serverId);
|
|
135
|
+
if (!entry?.doc.enabled) throw new Error(`MCP server is missing or disabled: ${serverId}`);
|
|
136
|
+
// Gateway initialization registers DB-backed MCP servers under their stable
|
|
137
|
+
// document id. The display name is only used in UI/tool labels.
|
|
138
|
+
const serverName = entry.doc.id;
|
|
139
|
+
const existing = mcpLeases.get(serverId);
|
|
140
|
+
if (existing) {
|
|
141
|
+
if (existing.timer) clearTimeout(existing.timer);
|
|
142
|
+
existing.timer = undefined;
|
|
143
|
+
existing.refs++;
|
|
144
|
+
return { serverId, serverName: existing.serverName };
|
|
145
|
+
}
|
|
146
|
+
await manager.connectServer(serverName);
|
|
147
|
+
mcpLeases.set(serverId, { refs: 1, serverName });
|
|
148
|
+
return { serverId, serverName };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function releaseMcpLease(serverId: string, manager: MCPClientManager): Promise<void> {
|
|
152
|
+
const lease = mcpLeases.get(serverId);
|
|
153
|
+
if (!lease) return;
|
|
154
|
+
lease.refs = Math.max(0, lease.refs - 1);
|
|
155
|
+
if (lease.refs > 0) return;
|
|
156
|
+
lease.timer = setTimeout(() => {
|
|
157
|
+
const current = mcpLeases.get(serverId);
|
|
158
|
+
if (!current || current.refs > 0) return;
|
|
159
|
+
void manager.disconnectServer(current.serverName)
|
|
160
|
+
.catch((err) => log.warn(`[delegation-runtime] MCP disconnect failed: ${(err as Error).message}`))
|
|
161
|
+
.finally(() => mcpLeases.delete(serverId));
|
|
162
|
+
}, MCP_IDLE_TTL_MS);
|
|
163
|
+
lease.timer.unref?.();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Prepares a delegation target for execution: expands its tool allowlist
|
|
168
|
+
* (when it has one — catalog agents do, plain agent_create workers use their
|
|
169
|
+
* stored tools_json as-is), validates skills, resolves the effective
|
|
170
|
+
* provider/model, and acquires any requested MCP leases.
|
|
171
|
+
*
|
|
172
|
+
* This never creates a new AgentDoc — the row already exists (seeded from
|
|
173
|
+
* the catalog, or created via agent_create).
|
|
174
|
+
* It does persist the resolved workspace/model back onto that row (same as
|
|
175
|
+
* the old materialization did) so agent-loop.ts picks them up when it loads
|
|
176
|
+
* the agent — which reintroduces a narrow, accepted race for the rare case
|
|
177
|
+
* of two concurrent delegations to the *same* catalog agent with different
|
|
178
|
+
* workspaces (catalog agents are global rows, not one-per-workspace anymore).
|
|
179
|
+
* `updateDoc`'s OCC retry keeps this safe (last-write-wins), never corrupt.
|
|
180
|
+
*/
|
|
181
|
+
export async function prepareDelegation(agentId: string, opts: PrepareDelegationOptions): Promise<PreparedDelegation> {
|
|
182
|
+
const agents = await col<AgentDoc>("agents");
|
|
183
|
+
const entry = await agents.get(agentId);
|
|
184
|
+
if (!entry?.doc.enabled) throw new Error(`Agent not found or disabled: ${agentId}`);
|
|
185
|
+
const agentDoc = entry.doc;
|
|
186
|
+
|
|
187
|
+
const toolNames = agentDoc.tool_allowlist_json
|
|
188
|
+
? expandToolAllowlist(JSON.parse(agentDoc.tool_allowlist_json))
|
|
189
|
+
: (agentDoc.tools_json ? JSON.parse(agentDoc.tools_json) : []);
|
|
190
|
+
|
|
191
|
+
const skillIds = agentDoc.skills_json ? await validateSkillIds(JSON.parse(agentDoc.skills_json)) : [];
|
|
192
|
+
|
|
193
|
+
const taskScopedMcpIds = opts.taskScopedMcpServerIds ?? [];
|
|
194
|
+
if (taskScopedMcpIds.length > 0 && agentId !== "acceptance_verifier") {
|
|
195
|
+
throw new Error(`Agent ${agentId} does not allow transient MCP servers`);
|
|
196
|
+
}
|
|
197
|
+
const fixedMcpIds: string[] = agentDoc.mcp_server_ids_json ? JSON.parse(agentDoc.mcp_server_ids_json) : [];
|
|
198
|
+
const requestedMcp = [...new Set([...fixedMcpIds, ...taskScopedMcpIds])];
|
|
199
|
+
if (requestedMcp.length > 0 && !opts.mcpManager) throw new Error("MCP servers requested but MCP manager is unavailable");
|
|
200
|
+
|
|
201
|
+
const acquired: string[] = [];
|
|
202
|
+
try {
|
|
203
|
+
for (const serverId of requestedMcp) {
|
|
204
|
+
await acquireMcpLease(serverId, opts.mcpManager!);
|
|
205
|
+
acquired.push(serverId);
|
|
206
|
+
}
|
|
207
|
+
} catch (err) {
|
|
208
|
+
await Promise.all(acquired.map((id) => releaseMcpLease(id, opts.mcpManager!)));
|
|
209
|
+
throw err;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const modelOverride: AgentModelOverride | null = agentDoc.model_override_json
|
|
213
|
+
? JSON.parse(agentDoc.model_override_json)
|
|
214
|
+
: null;
|
|
215
|
+
const resolved = await resolveAgentModel(
|
|
216
|
+
modelOverride,
|
|
217
|
+
fromIndexable(agentDoc.provider_id),
|
|
218
|
+
fromIndexable(agentDoc.model_id),
|
|
219
|
+
opts.parentProviderId ?? null,
|
|
220
|
+
opts.parentModelId ?? null,
|
|
221
|
+
opts.executorModelId ?? opts.parentModelId ?? null,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
await updateDoc<AgentDoc>("agents", agentId, {
|
|
225
|
+
workspace: opts.workspace,
|
|
226
|
+
provider_id: toIndexable(resolved.providerId || null),
|
|
227
|
+
model_id: toIndexable(resolved.modelId || null),
|
|
228
|
+
active_mcp_json: JSON.stringify(requestedMcp),
|
|
229
|
+
updated_at: Date.now(),
|
|
230
|
+
}).catch((err) => log.warn(`[prepareDelegation] Failed to persist delegation context for ${agentId}: ${(err as Error).message}`));
|
|
231
|
+
|
|
232
|
+
let released = false;
|
|
233
|
+
return {
|
|
234
|
+
agent: agentDoc,
|
|
235
|
+
toolNames,
|
|
236
|
+
skillIds,
|
|
237
|
+
mcpServerIds: requestedMcp,
|
|
238
|
+
providerId: resolved.providerId,
|
|
239
|
+
modelId: resolved.modelId,
|
|
240
|
+
release: async () => {
|
|
241
|
+
if (released) return;
|
|
242
|
+
released = true;
|
|
243
|
+
if (opts.mcpManager) {
|
|
244
|
+
await Promise.all(requestedMcp.map((id) => releaseMcpLease(id, opts.mcpManager!)));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./acceptance-verifier.ts";
|
|
2
|
+
export * from "./agent-catalog.ts";
|
|
3
|
+
export * from "./agent-loop.ts";
|
|
4
|
+
export * from "./capability-search.ts";
|
|
5
|
+
export * from "./catalog-selector.ts";
|
|
6
|
+
export * from "./context-compiler.ts";
|
|
7
|
+
export * from "./conversation-store.ts";
|
|
8
|
+
export * from "./delegation-runtime.ts";
|
|
9
|
+
export * from "./llm-client.ts";
|
|
10
|
+
export * from "./minimal-loadout.ts";
|
|
11
|
+
export * from "./playbook-selector.ts";
|
|
12
|
+
export * from "./prompt-builder.ts";
|
|
13
|
+
export * from "./proof-packet.ts";
|
|
14
|
+
export * from "./run-store.ts";
|
|
15
|
+
export * from "./service.ts";
|
|
16
|
+
export * from "./skill-selector.ts";
|
|
17
|
+
export * from "./tool-selector.ts";
|
|
@@ -7,7 +7,7 @@ const log = logger.child("llm-client")
|
|
|
7
7
|
const DEFAULT_BASE = "https://llm.hiveagents.io"
|
|
8
8
|
|
|
9
9
|
/** Contexto por defecto que se solicita al backend de HiveAgents al cargar un modelo. */
|
|
10
|
-
|
|
10
|
+
const HIVEAGENTS_DEFAULT_LOAD_CTX = 50000
|
|
11
11
|
|
|
12
12
|
// Cloudflare blocks requests with the OpenAI SDK User-Agent and x-stainless-* fingerprint headers.
|
|
13
13
|
const BLOCKED_HEADERS = [
|
|
@@ -17,7 +17,7 @@ export interface LLMProvider {
|
|
|
17
17
|
// ─── Shared constants ─────────────────────────────────────────────────────────
|
|
18
18
|
|
|
19
19
|
// Models that only accept temperature=1 (reasoning/thinking models).
|
|
20
|
-
|
|
20
|
+
const FIXED_TEMPERATURE_1_MODELS = new Set(["kimi-k2.5", "kimi-k2", "kimi-k2-5"])
|
|
21
21
|
|
|
22
22
|
export const OPENAI_COMPAT_BASE_URLS: Record<string, string> = {
|
|
23
23
|
groq: "https://api.groq.com/openai/v1",
|
|
@@ -58,7 +58,7 @@ const DEFAULT_PROFILE: ProviderProfile = {
|
|
|
58
58
|
retryWithoutToolsOnCodes: [],
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
const PROVIDER_PROFILES: Record<string, ProviderProfile> = {
|
|
62
62
|
openai: { ...DEFAULT_PROFILE, normalizeToolNames: true },
|
|
63
63
|
kimi: { ...DEFAULT_PROFILE, normalizeToolNames: true, disableParallelToolCalls: true, retryWithoutToolsOnCodes: [422] },
|
|
64
64
|
deepseek: { ...DEFAULT_PROFILE, normalizeToolNames: true },
|
|
@@ -78,7 +78,7 @@ export function getProviderProfile(provider: string): ProviderProfile {
|
|
|
78
78
|
|
|
79
79
|
// ─── Models that don't support tool calling ───────────────────────────────────
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
const NO_TOOL_MODELS = new Set([
|
|
82
82
|
"deepseek-reasoner",
|
|
83
83
|
"deepseek/deepseek-r1:free",
|
|
84
84
|
])
|
|
@@ -339,7 +339,7 @@ export abstract class OpenAICompatBase implements LLMProvider {
|
|
|
339
339
|
* Extracts tool_calls from text when the model fails to emit native tool_calls.
|
|
340
340
|
* Supports common formats used by Gemma, Qwen, and other local models.
|
|
341
341
|
*/
|
|
342
|
-
|
|
342
|
+
function extractToolCallsFromText(
|
|
343
343
|
content: string,
|
|
344
344
|
toolNameMap: Map<string, string>,
|
|
345
345
|
knownToolNames?: Set<string>,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal loadout — the single source of truth for what the coordinator starts
|
|
3
|
+
* a turn with, and the rule that derives which skills ride along with it.
|
|
4
|
+
*
|
|
5
|
+
* Everything else is discovered at runtime through `search_knowledge`, which
|
|
6
|
+
* injects both the tool and its associated skill into the loadout
|
|
7
|
+
* (agent-loop.ts). So a skill that documents tools outside this set has nothing
|
|
8
|
+
* to teach a turn that hasn't discovered them yet — it only spends context.
|
|
9
|
+
*
|
|
10
|
+
* These used to be two hand-maintained lists (one here, one in skill-selector)
|
|
11
|
+
* and they drifted: 3 of the 4 "minimal" skills documented tools the agent did
|
|
12
|
+
* not have. The skill set is now derived from the tool set so it cannot.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Tools always present in the coordinator's loadout, without discovery. */
|
|
16
|
+
export const MINIMAL_TOOLS = new Set([
|
|
17
|
+
// Discovery — the entry point to everything else
|
|
18
|
+
"search_knowledge",
|
|
19
|
+
// Communication with the user
|
|
20
|
+
"notify",
|
|
21
|
+
"report_progress",
|
|
22
|
+
// Notes that survive context compaction
|
|
23
|
+
"save_note",
|
|
24
|
+
// Orchestration: the coordinator's own competency, not an optional capability
|
|
25
|
+
"task_delegate",
|
|
26
|
+
"agent_find",
|
|
27
|
+
"task_status",
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
/** Splits a SkillDoc's comma-separated `tools` column into tool names. */
|
|
31
|
+
export function parseSkillTools(toolsCsv: string | null | undefined): string[] {
|
|
32
|
+
return (toolsCsv ?? "")
|
|
33
|
+
.split(",")
|
|
34
|
+
.map((name) => name.trim())
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A skill is minimal when every tool it documents is already in the loadout.
|
|
40
|
+
* A skill that declares no tools is not minimal: it has no anchor to the
|
|
41
|
+
* always-available set, so it belongs to discovery like any other.
|
|
42
|
+
*/
|
|
43
|
+
export function isMinimalSkill(toolsCsv: string | null | undefined): boolean {
|
|
44
|
+
const tools = parseSkillTools(toolsCsv)
|
|
45
|
+
return tools.length > 0 && tools.every((name) => MINIMAL_TOOLS.has(name))
|
|
46
|
+
}
|
|
@@ -90,7 +90,7 @@ export async function selectPlaybookRules(message: string): Promise<PlaybookRule
|
|
|
90
90
|
* Sync active playbook rules to the HiveDB capability index.
|
|
91
91
|
* Replaces all `type=playbook` documents atomically.
|
|
92
92
|
*/
|
|
93
|
-
export async function
|
|
93
|
+
export async function syncPlaybookToIndex(): Promise<void> {
|
|
94
94
|
try {
|
|
95
95
|
// Step 1: Get active rules
|
|
96
96
|
const playbookCol = await col<PlaybookDoc>("playbook")
|
|
@@ -126,6 +126,7 @@ export async function buildSystemPrompt(opts: BuildSystemPromptOpts): Promise<st
|
|
|
126
126
|
const userData: Record<string, string | null> = {}
|
|
127
127
|
|
|
128
128
|
if (user.name) userData.Nombre = user.name
|
|
129
|
+
if (agent.role === "coordinator" && user.email) userData.CorreoPropio = user.email
|
|
129
130
|
if (user.language) userData.Idioma = user.language
|
|
130
131
|
if (user.timezone) userData.ZonaHoraria = user.timezone
|
|
131
132
|
if (user.occupation) userData.Ocupación = user.occupation
|
|
@@ -134,6 +135,9 @@ export async function buildSystemPrompt(opts: BuildSystemPromptOpts): Promise<st
|
|
|
134
135
|
// Usar TOON para comprimir datos del usuario
|
|
135
136
|
if (Object.keys(userData).length > 0) {
|
|
136
137
|
userSection += formatContext(userData) + "\n\n"
|
|
138
|
+
if (agent.role === "coordinator" && user.email) {
|
|
139
|
+
userSection += `Cuando el usuario diga "envíame", "mándame" o "a mi correo" sin indicar otro destinatario, usá CorreoPropio. Para terceras personas, resolvé su dirección por separado.\n\n`
|
|
140
|
+
}
|
|
137
141
|
} else {
|
|
138
142
|
userSection += `Usuario ID: ${userId}\n\n`
|
|
139
143
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* reviewer doesn't have to replay the whole run to trust its outcome.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { col, nextId } from "../storage/hive";
|
|
9
|
+
import { col, nextId, toIndexable } from "../storage/hive";
|
|
10
10
|
import type { ProofPacketDoc } from "../storage/collections";
|
|
11
11
|
import type { AcceptanceResult } from "./goal-runner";
|
|
12
12
|
import type { RunEpoch } from "./run-epoch";
|
|
@@ -25,9 +25,21 @@ export interface BuildProofPacketInput {
|
|
|
25
25
|
evidence: string[];
|
|
26
26
|
knownLimits?: string | null;
|
|
27
27
|
epoch?: RunEpoch | null;
|
|
28
|
+
/** Mandatory for met=true: independent acceptance_verifier verdict id. */
|
|
29
|
+
verificationId?: string | null;
|
|
30
|
+
catalogAgentId?: string | null;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export async function buildProofPacket(input: BuildProofPacketInput): Promise<ProofPacketDoc> {
|
|
34
|
+
if (input.met) {
|
|
35
|
+
if (!input.verificationId) {
|
|
36
|
+
throw new Error("A successful proof packet requires an independent verification_id");
|
|
37
|
+
}
|
|
38
|
+
const { getVerifiedVerification } = await import("./acceptance-verifier");
|
|
39
|
+
if (!(await getVerifiedVerification(input.verificationId, input.runId))) {
|
|
40
|
+
throw new Error(`Verification ${input.verificationId} is missing, rejected, or belongs to another run`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
31
43
|
const id = await nextId("proofPackets");
|
|
32
44
|
const acceptanceResults: AcceptanceResult[] =
|
|
33
45
|
input.acceptanceResults ?? [{ id: "goal", description: input.intendedOutcome, met: input.met, evidence: input.evidence.join("; ") || "n/a" }];
|
|
@@ -42,6 +54,8 @@ export async function buildProofPacket(input: BuildProofPacketInput): Promise<Pr
|
|
|
42
54
|
evidence_json: JSON.stringify(input.evidence),
|
|
43
55
|
known_limits: input.knownLimits ?? null,
|
|
44
56
|
epoch_json: input.epoch ? JSON.stringify(input.epoch) : null,
|
|
57
|
+
verification_id: toIndexable(input.verificationId),
|
|
58
|
+
catalog_agent_id: toIndexable(input.catalogAgentId),
|
|
45
59
|
met: input.met,
|
|
46
60
|
created_at: Date.now(),
|
|
47
61
|
};
|