@johpaz/hive-agents 1.0.5 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -11
- package/dist/hive.js +87295 -101789
- package/dist/tool-worker.js +13241 -17001
- package/dist/ui/assets/A2UIPage-F1sUdZV7.js +8 -0
- package/dist/ui/assets/{AgentCreateForm-Bcp3HN8D.js → AgentCreateForm-CN5Gb9UN.js} +1 -1
- package/dist/ui/assets/AgentDetailPage-CzBnoKtH.js +1 -0
- package/dist/ui/assets/AgentNewPage-AGDjfAVf.js +1 -0
- package/dist/ui/assets/AgentsPage-BgKr7pAZ.js +10 -0
- package/dist/ui/assets/{ApiClientPage-DHfIlSAg.js → ApiClientPage-Dq4nPse4.js} +2 -2
- package/dist/ui/assets/ChannelsPage-BuWItmp-.js +8 -0
- package/dist/ui/assets/DashboardPage-CB1aM87o.js +6 -0
- package/dist/ui/assets/{LoginPage-BaX6cAPa.js → LoginPage-DBvwBCG6.js} +1 -1
- package/dist/ui/assets/LogsPage-Bc-oTBwY.js +1 -0
- package/dist/ui/assets/MeetingPage-C2H5SxaQ.js +1 -0
- package/dist/ui/assets/ModelSelector-D0aJvoD9.js +1 -0
- package/dist/ui/assets/NotFound-PUg3gEO0.js +1 -0
- package/dist/ui/assets/{Office3DPage-C3SIzd2H.css → Office3DPage-31AMJ-LN.css} +1 -1
- package/dist/ui/assets/Office3DPage-D5vwZkJa.js +727 -0
- package/dist/ui/assets/ProvidersPage-BBBt4Hcz.js +1 -0
- package/dist/ui/assets/{RecoverPage-C_Id9WM-.js → RecoverPage-nq901JiE.js} +1 -1
- package/dist/ui/assets/SettingsPage-DQ5KZPAd.js +9 -0
- package/dist/ui/assets/SetupPage-DeIGn-Uf.js +1 -0
- package/dist/ui/assets/{Vignette-Cyi27LQH.js → Vignette-BcPWkNhm.js} +17 -17
- package/dist/ui/assets/VoicePage-DJYsOsaU.js +307 -0
- package/dist/ui/assets/WebChatPage-CRDN4OlP.js +29 -0
- package/dist/ui/assets/agentCapabilities-PfTEVxG1.js +1 -0
- package/dist/ui/assets/alert-CjiX20jI.js +1 -0
- package/dist/ui/assets/badge-B5AKge1b.js +1 -0
- package/dist/ui/assets/card-mTJ4oZbL.js +1 -0
- package/dist/ui/assets/conversationsStore-BIs0iMhp.js +1 -0
- package/dist/ui/assets/dialog-DdbsUCv9.js +1 -0
- package/dist/ui/assets/dist-js-Dh18rcg9.js +1 -0
- package/dist/ui/assets/{dist-js-Bg0g3vPS.js → dist-js-q7C_AB0j.js} +1 -1
- package/dist/ui/assets/index-BD7hBA1d.css +2 -0
- package/dist/ui/assets/index-CpzwBwPg.js +116 -0
- package/dist/ui/assets/label-D_fvqJyD.js +1 -0
- package/dist/ui/assets/lock-3IApZyVy.js +1 -0
- package/dist/ui/assets/pencil-L3Li7_pz.js +1 -0
- package/dist/ui/assets/scroll-area-CbH8FOo8.js +1 -0
- package/dist/ui/assets/select-v_3QBYrD.js +1 -0
- package/dist/ui/assets/slider-DXS4h1LB.js +1 -0
- package/dist/ui/assets/switch-ndx8VCpm.js +1 -0
- package/dist/ui/assets/tabs-epu-3Tl4.js +1 -0
- package/dist/ui/assets/textarea-BgZJFZTX.js +1 -0
- package/dist/ui/assets/useAudioDevices-yU-wu-kt.js +41 -0
- package/dist/ui/assets/{useHiveAgentsModelLoad-CHmtvNp4.js → useHiveAgentsModelLoad-29pOYRd9.js} +1 -1
- package/dist/ui/assets/useOfficeModel-BaDn7U-X.js +1 -0
- package/dist/ui/assets/{useProviders-C7FA6z4M.js → useProviders-CiBi4Dt6.js} +1 -1
- package/dist/ui/assets/vendor-react-kUOwxn0g.js +1 -0
- package/dist/ui/index.html +6 -6
- package/package.json +10 -6
- package/packages/cli/src/adapters/config.ts +11 -3
- package/packages/cli/src/commands/causal.ts +1 -1
- package/packages/cli/src/commands/doctor.ts +2 -2
- package/packages/cli/src/commands/onboard.ts +1 -1
- package/packages/core/src/agent/acceptance-checks.ts +25 -0
- package/packages/core/src/agent/agent-catalog.ts +53 -33
- package/packages/core/src/agent/agent-loop.ts +67 -14
- package/packages/core/src/agent/capability-search.ts +2 -1
- package/packages/core/src/agent/compaction.ts +19 -7
- package/packages/core/src/agent/context-compiler.ts +165 -27
- package/packages/core/src/agent/conversation-store.ts +12 -1
- package/packages/core/src/agent/goal-runner.ts +2 -2
- package/packages/core/src/agent/jev-decisions.ts +242 -0
- package/packages/core/src/agent/jev-planner.ts +293 -0
- package/packages/core/src/agent/llm-client.ts +27 -5
- package/packages/core/src/agent/llm-providers/ollama.ts +17 -4
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +27 -12
- package/packages/core/src/agent/llm-providers/opencode-go.ts +37 -0
- package/packages/core/src/agent/realtime-providers/gemini-live.ts +5 -2
- package/packages/core/src/agent/skill-selector.ts +4 -2
- package/packages/core/src/agent/thread-id.ts +71 -0
- package/packages/core/src/agent/thread-store.ts +230 -0
- package/packages/core/src/agent/tool-selector.ts +42 -0
- package/packages/core/src/agent/tracer.ts +2 -0
- package/packages/core/src/canvas/canvas-manager.ts +17 -1
- package/packages/core/src/canvas/emitter.ts +24 -0
- package/packages/core/src/channels/telegram.ts +19 -1
- package/packages/core/src/channels/webchat.ts +47 -45
- package/packages/core/src/config/loader.ts +3 -2
- package/packages/core/src/gateway/channel-notify.ts +24 -5
- package/packages/core/src/gateway/delegation-groups.ts +3 -3
- package/packages/core/src/gateway/delegation-notify.ts +34 -5
- package/packages/core/src/gateway/durable-queue.ts +22 -0
- package/packages/core/src/gateway/failure-notify.ts +8 -2
- package/packages/core/src/gateway/job-executors.ts +3 -3
- package/packages/core/src/gateway/realtime/bridge-tools.ts +106 -28
- package/packages/core/src/gateway/realtime/index.ts +63 -7
- package/packages/core/src/gateway/realtime/prompt.ts +45 -0
- package/packages/core/src/gateway/realtime/voice-session.ts +1 -0
- package/packages/core/src/gateway/resolver.ts +31 -4
- package/packages/core/src/gateway/routes/artifacts.ts +13 -0
- package/packages/core/src/gateway/routes/chat.ts +20 -4
- package/packages/core/src/gateway/routes/conversations.ts +121 -0
- package/packages/core/src/gateway/routes/providers.ts +15 -0
- package/packages/core/src/gateway/routes/setup.ts +22 -11
- package/packages/core/src/gateway/routes/system.ts +4 -2
- package/packages/core/src/gateway/routes/tts-local.ts +2 -1
- package/packages/core/src/gateway/server.ts +85 -12
- package/packages/core/src/gateway/slash-commands.ts +46 -10
- package/packages/core/src/gateway/tts/src/server.ts +2 -1
- package/packages/core/src/gateway/webchat-turn.ts +68 -10
- package/packages/core/src/index.ts +2 -0
- package/packages/core/src/scheduler/CronScheduler.ts +20 -8
- package/packages/core/src/scheduler/cron/cron-engine.test.ts +295 -0
- package/packages/core/src/scheduler/cron/expression.ts +165 -0
- package/packages/core/src/scheduler/cron/index.ts +10 -0
- package/packages/core/src/scheduler/cron/job.ts +340 -0
- package/packages/core/src/scheduler/cron/next-run.ts +121 -0
- package/packages/core/src/scheduler/cron/zoned-time.ts +139 -0
- package/packages/core/src/scheduler/integration.ts +16 -5
- package/packages/core/src/scheduler/types.ts +3 -18
- package/packages/core/src/storage/bootstrap.ts +24 -1
- package/packages/core/src/storage/collections.ts +29 -1
- package/packages/core/src/storage/crypto.ts +133 -40
- package/packages/core/src/storage/reconcile.ts +6 -1
- package/packages/core/src/storage/seed.ts +101 -7
- package/packages/core/src/storage/usage.ts +53 -1
- package/packages/core/src/tool-runtime/index.ts +19 -1
- package/packages/core/src/tools/a2ui/index.ts +65 -1
- package/packages/core/src/tools/agents/get-available-models.ts +3 -1
- package/packages/core/src/tools/code-agent/adapters.ts +110 -0
- package/packages/core/src/tools/code-agent/index.ts +193 -0
- package/packages/core/src/tools/core/index.ts +39 -4
- package/packages/core/src/tools/cron/index.ts +4 -4
- package/packages/core/src/tools/index.ts +9 -1
- package/packages/core/src/tools/office/office-escribir-xlsx.ts +2 -1
- package/packages/core/src/tools/office/office-leer-xlsx.ts +2 -1
- package/packages/core/src/tools/office/xlsx-loader.ts +19 -0
- package/packages/core/src/tools/web/browser-backend.ts +22 -2
- package/packages/core/src/tools/web/index.ts +4 -0
- package/packages/core/src/tools/web/obscura.ts +860 -0
- package/packages/core/src/tools/web/webview-backend.ts +168 -26
- package/packages/core/src/utils/port.ts +33 -0
- package/packages/core/src/voice/index.ts +2 -1
- package/packages/mcp/src/config.ts +2 -1
- package/packages/mcp/src/manager.ts +9 -0
- package/packages/mcp/src/transports/index.ts +42 -1
- package/packages/mcp/src/transports/sse.ts +11 -5
- package/packages/skills/src/bundled/a2ui/a2ui_dashboard/SKILL.md +2 -2
- package/packages/skills/src/bundled/a2ui/a2ui_form/SKILL.md +2 -2
- package/packages/skills/src/bundled/a2ui/a2ui_interactive/SKILL.md +4 -4
- package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +7 -7
- package/packages/skills/src/bundled/agents/memory_manager/SKILL.md +9 -9
- package/packages/skills/src/bundled/agents/research_and_remember/SKILL.md +8 -8
- package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +8 -8
- package/packages/skills/src/bundled/artifacts/artifact_reader/SKILL.md +104 -0
- package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +6 -6
- package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +5 -5
- package/packages/skills/src/bundled/cli/external_code_agent/SKILL.md +69 -0
- package/packages/skills/src/bundled/cron_manager/SKILL.md +29 -19
- package/packages/skills/src/bundled/cron_reminder/SKILL.md +5 -5
- package/packages/skills/src/bundled/filesystem/file_manager/SKILL.md +4 -4
- package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +7 -7
- package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +10 -10
- package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +8 -8
- package/packages/skills/src/bundled/web/browser_automate/SKILL.md +21 -12
- package/packages/skills/src/bundled/web/browser_scrape/SKILL.md +28 -13
- package/packages/skills/src/bundled/web/obscura_browser/SKILL.md +69 -0
- package/packages/skills/src/bundled/web/web_monitor/SKILL.md +6 -6
- package/packages/skills/src/bundled/web/web_research/SKILL.md +5 -5
- package/packages/skills/src/bundled-data.generated.ts +845 -773
- package/dist/ui/assets/A2UIPage-DTW79pyL.js +0 -8
- package/dist/ui/assets/AgentDetailPage-10XptMde.js +0 -1
- package/dist/ui/assets/AgentNewPage-CUt49rVS.js +0 -1
- package/dist/ui/assets/AgentsPage-1_e1a9xa.js +0 -10
- package/dist/ui/assets/ChannelsPage-BnCQAGZL.js +0 -8
- package/dist/ui/assets/DashboardPage-BsCCKHgg.js +0 -6
- package/dist/ui/assets/LogsPage-DiFBQt7o.js +0 -1
- package/dist/ui/assets/MeetingPage-Bpv5zVXf.js +0 -1
- package/dist/ui/assets/ModelSelector-DfExlPzx.js +0 -1
- package/dist/ui/assets/NotFound-C8HBdF73.js +0 -1
- package/dist/ui/assets/Office3DPage-ChsGMapf.js +0 -319
- package/dist/ui/assets/ProvidersPage-B39pfWHf.js +0 -1
- package/dist/ui/assets/SettingsPage-BgFqasyg.js +0 -9
- package/dist/ui/assets/SetupPage-YeJFfgbt.js +0 -1
- package/dist/ui/assets/VoicePage-Cp63Abj4.js +0 -307
- package/dist/ui/assets/WebChatPage-DxFLWgtM.js +0 -29
- package/dist/ui/assets/agentCapabilities-DOeepCty.js +0 -1
- package/dist/ui/assets/alert-Cj4DpKv6.js +0 -1
- package/dist/ui/assets/badge-DKpeVCpY.js +0 -1
- package/dist/ui/assets/card-Cag15G4h.js +0 -1
- package/dist/ui/assets/dialog-7E3EoEt3.js +0 -1
- package/dist/ui/assets/dist-js-DwLn9F4C.js +0 -1
- package/dist/ui/assets/index-Bi8qEmrK.js +0 -116
- package/dist/ui/assets/index-D2UhaSb0.css +0 -2
- package/dist/ui/assets/label-C6atPuIh.js +0 -1
- package/dist/ui/assets/pencil-CUbpCfeG.js +0 -1
- package/dist/ui/assets/scroll-area-CSoG2z53.js +0 -1
- package/dist/ui/assets/select-DlCT21_r.js +0 -1
- package/dist/ui/assets/slider-Bb_PHFJT.js +0 -1
- package/dist/ui/assets/switch-CUsGuBNi.js +0 -1
- package/dist/ui/assets/tabs-Ckfc7DGG.js +0 -1
- package/dist/ui/assets/textarea-BH6pI9Ax.js +0 -1
- package/dist/ui/assets/useAudioDevices-Dpr_hn6i.js +0 -41
- package/dist/ui/assets/useOfficeModel-Cc5VkReZ.js +0 -1
- package/dist/ui/assets/vendor-react-DYyYpuMy.js +0 -1
- /package/dist/ui/assets/{core-Dz04EE_8.js → core-B_5cyOSV.js} +0 -0
- /package/dist/ui/assets/{download-D0aDV8Y_.js → download-BQXrpH0m.js} +0 -0
- /package/dist/ui/assets/{ellipsis-vertical-BOW_iEOO.js → ellipsis-vertical-D7uFJLGh.js} +0 -0
- /package/dist/ui/assets/{external-link-5cujQzfV.js → external-link-6oTH9pUM.js} +0 -0
- /package/dist/ui/assets/{eye-sRPY5qOa.js → eye-CxvxtQT5.js} +0 -0
- /package/dist/ui/assets/{file-text-DNSyNLUh.js → file-text-D5ZJEx3E.js} +0 -0
- /package/dist/ui/assets/{gateway-url-BzQV75Ig.js → gateway-url-BALS_wVh.js} +0 -0
- /package/dist/ui/assets/{gauge-C__zxC3_.js → gauge-CEu7PhTW.js} +0 -0
- /package/dist/ui/assets/{history-BHQWfE-7.js → history-DLK5rTlP.js} +0 -0
- /package/dist/ui/assets/{info-CG1VohyH.js → info-8ReWzubE.js} +0 -0
- /package/dist/ui/assets/{key-BC28VCjO.js → key-DPkOY-J0.js} +0 -0
- /package/dist/ui/assets/{lock-open-Bhp0UJlL.js → lock-open-v0EphssG.js} +0 -0
- /package/dist/ui/assets/{mail-Biwn8WrV.js → mail-vwCEHyhQ.js} +0 -0
- /package/dist/ui/assets/{mic-Rq4BxU1R.js → mic-CpDU_2as.js} +0 -0
- /package/dist/ui/assets/{pause-C2l5G2Py.js → pause-Cm9LzIZK.js} +0 -0
- /package/dist/ui/assets/{play-CMAscR3a.js → play-zqogwA2l.js} +0 -0
- /package/dist/ui/assets/{plus-DzvRxH4U.js → plus-Bm08ABhc.js} +0 -0
- /package/dist/ui/assets/{radio-DfGzov4y.js → radio-Cii1BjMt.js} +0 -0
- /package/dist/ui/assets/{refresh-cw-DZXu5FrG.js → refresh-cw-DXv3XgEt.js} +0 -0
- /package/dist/ui/assets/{rotate-ccw-Dx92orJM.js → rotate-ccw-LoM1AuqK.js} +0 -0
- /package/dist/ui/assets/{search-DB4w9YHW.js → search-BMwCI-pX.js} +0 -0
- /package/dist/ui/assets/{send-xi8HzUdc.js → send-D6fgWV7m.js} +0 -0
- /package/dist/ui/assets/{settings-pV0cF8Kf.js → settings-qV3kVkeG.js} +0 -0
- /package/dist/ui/assets/{shield-nLNsomh_.js → shield-CIarwBvx.js} +0 -0
- /package/dist/ui/assets/{sparkles-CerRDYxk.js → sparkles-DVvY6jDT.js} +0 -0
- /package/dist/ui/assets/{square-CcWzRWyG.js → square-D5zdNkAY.js} +0 -0
- /package/dist/ui/assets/{terminal-C2SUZUAD.js → terminal-BEcTK780.js} +0 -0
- /package/dist/ui/assets/{trash-2-BZsMCfso.js → trash-2-D6oziYAK.js} +0 -0
- /package/dist/ui/assets/{utils-lc8H6VGT.js → utils-DEmd_M8c.js} +0 -0
- /package/dist/ui/assets/{vendor-router-DCsSv_I7.js → vendor-router-DP84b3LQ.js} +0 -0
- /package/dist/ui/assets/{volume-2-CBMYsuF3.js → volume-2-EaA0JRvD.js} +0 -0
- /package/dist/ui/assets/{volume-x-vNFf2e4-.js → volume-x-CROXNMGT.js} +0 -0
- /package/dist/ui/assets/{wifi-DNv53AfN.js → wifi-BUJuOcgP.js} +0 -0
- /package/dist/ui/assets/{zap-Yed86Sh8.js → zap-DSoX9NDk.js} +0 -0
|
@@ -57,7 +57,7 @@ export async function calculateCost(
|
|
|
57
57
|
const key = `${provider}/${model}`;
|
|
58
58
|
if (!unpricedModels.has(key)) {
|
|
59
59
|
unpricedModels.add(key);
|
|
60
|
-
log.warn(`[usage] Sin tarifa para ${key} — su costo se contará como $0.
|
|
60
|
+
log.warn(`[usage] Sin tarifa para ${key} — su costo se contará como $0. Agrega inputPer1M/outputPer1M en SEED_DATA.models (storage/seed.ts).`);
|
|
61
61
|
}
|
|
62
62
|
return 0;
|
|
63
63
|
}
|
|
@@ -154,6 +154,15 @@ export interface UsageRecord {
|
|
|
154
154
|
created_at: number;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
export interface JevUsageSummary {
|
|
158
|
+
decisions: number;
|
|
159
|
+
costUsd: number;
|
|
160
|
+
/** Estimated main-model input tokens avoided; negative when Jev added more than it removed. */
|
|
161
|
+
savedTokens: number;
|
|
162
|
+
savedCostUsd: number;
|
|
163
|
+
byAgent: Record<string, { decisions: number; costUsd: number; savedTokens: number; savedCostUsd: number }>;
|
|
164
|
+
}
|
|
165
|
+
|
|
157
166
|
export interface UsageSummary {
|
|
158
167
|
totalTokens: number;
|
|
159
168
|
totalInputTokens: number;
|
|
@@ -168,6 +177,7 @@ export interface UsageSummary {
|
|
|
168
177
|
toonSavingsPercent: number;
|
|
169
178
|
byProvider: Record<string, { tokens: number; costUsd: number; inputTokens: number; outputTokens: number }>;
|
|
170
179
|
byModel: Record<string, { tokens: number; costUsd: number; provider: string; inputTokens: number; outputTokens: number }>;
|
|
180
|
+
jev: JevUsageSummary;
|
|
171
181
|
recentRecords: UsageRecord[];
|
|
172
182
|
}
|
|
173
183
|
|
|
@@ -240,6 +250,7 @@ export async function getUsageStats(hours: number = 24): Promise<UsageSummary> {
|
|
|
240
250
|
let totalInput = 0, totalOutput = 0, totalCost = 0;
|
|
241
251
|
let toonSavedTokens = 0, toonSavedCost = 0, toonSavedBytes = 0;
|
|
242
252
|
let toonJsonTokens = 0, toonToonTokens = 0, toonJsonBytes = 0;
|
|
253
|
+
const jev: JevUsageSummary = { decisions: 0, costUsd: 0, savedTokens: 0, savedCostUsd: 0, byAgent: {} };
|
|
243
254
|
|
|
244
255
|
for (const r of rollups) {
|
|
245
256
|
totalInput += r.inputTokens;
|
|
@@ -251,6 +262,18 @@ export async function getUsageStats(hours: number = 24): Promise<UsageSummary> {
|
|
|
251
262
|
toonJsonTokens += r.toonJsonTokens;
|
|
252
263
|
toonToonTokens += r.toonToonTokens;
|
|
253
264
|
toonJsonBytes += r.toonJsonBytes;
|
|
265
|
+
jev.decisions += r.jevDecisions ?? 0;
|
|
266
|
+
jev.costUsd += r.jevCostUsd ?? 0;
|
|
267
|
+
jev.savedTokens += r.jevSavedTokens ?? 0;
|
|
268
|
+
jev.savedCostUsd += r.jevSavedCostUsd ?? 0;
|
|
269
|
+
for (const [agentId, a] of Object.entries(r.jevByAgent ?? {})) {
|
|
270
|
+
const cur = jev.byAgent[agentId] ?? { decisions: 0, costUsd: 0, savedTokens: 0, savedCostUsd: 0 };
|
|
271
|
+
cur.decisions += a.jevDecisions ?? 0;
|
|
272
|
+
cur.costUsd += a.jevCostUsd ?? 0;
|
|
273
|
+
cur.savedTokens += a.jevSavedTokens ?? 0;
|
|
274
|
+
cur.savedCostUsd += a.jevSavedCostUsd ?? 0;
|
|
275
|
+
jev.byAgent[agentId] = cur;
|
|
276
|
+
}
|
|
254
277
|
|
|
255
278
|
for (const [provider, p] of Object.entries(r.byProvider ?? {})) {
|
|
256
279
|
const cur = providerMap[provider] ?? { tokens: 0, costUsd: 0, inputTokens: 0, outputTokens: 0 };
|
|
@@ -301,10 +324,39 @@ export async function getUsageStats(hours: number = 24): Promise<UsageSummary> {
|
|
|
301
324
|
toonSavingsPercent,
|
|
302
325
|
byProvider: providerMap,
|
|
303
326
|
byModel: modelMap,
|
|
327
|
+
jev,
|
|
304
328
|
recentRecords
|
|
305
329
|
};
|
|
306
330
|
}
|
|
307
331
|
|
|
332
|
+
/**
|
|
333
|
+
* Persists one Jev decision into the hourly rollup. The avoided tokens are
|
|
334
|
+
* priced with the advised agent's own model (input rate), through the same
|
|
335
|
+
* catalog lookup as real usage, so "saved" and "spent" are comparable.
|
|
336
|
+
*/
|
|
337
|
+
export function recordJevDecision(options: {
|
|
338
|
+
agentId: string;
|
|
339
|
+
provider: string;
|
|
340
|
+
model: string;
|
|
341
|
+
savedTokens: number;
|
|
342
|
+
costUsd: number;
|
|
343
|
+
}): void {
|
|
344
|
+
Promise.resolve().then(async () => {
|
|
345
|
+
try {
|
|
346
|
+
const unitCost = await calculateCost(options.provider, options.model, Math.abs(options.savedTokens), 0);
|
|
347
|
+
const savedCostUsd = Math.sign(options.savedTokens) * unitCost;
|
|
348
|
+
await bumpRollup("usageRollups", hourBucket(Date.now()), {
|
|
349
|
+
jevDecisions: 1,
|
|
350
|
+
jevCostUsd: options.costUsd,
|
|
351
|
+
jevSavedTokens: options.savedTokens,
|
|
352
|
+
jevSavedCostUsd: savedCostUsd,
|
|
353
|
+
}, { field: "jevByAgent", key: options.agentId });
|
|
354
|
+
} catch (error) {
|
|
355
|
+
log.warn(`[JEV] Failed to record decision:`, error);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
308
360
|
/**
|
|
309
361
|
* Record TOON savings for metrics tracking
|
|
310
362
|
* This updates the usage_records table with complete TOON compression metrics
|
|
@@ -46,6 +46,8 @@ export type ExecuteToolBatchOptions = {
|
|
|
46
46
|
}
|
|
47
47
|
hiveConfig?: Config
|
|
48
48
|
workerPool?: ToolRuntimeConfig
|
|
49
|
+
/** Per-batch decision. Undefined preserves the configured legacy behavior. */
|
|
50
|
+
parallelToolCalls?: boolean
|
|
49
51
|
mainThreadToolNames?: string[]
|
|
50
52
|
signal?: AbortSignal
|
|
51
53
|
}
|
|
@@ -198,6 +200,7 @@ const DEFAULT_MAIN_THREAD_TOOL_NAMES = new Set([
|
|
|
198
200
|
// These tools depend on process-local singleton state (HiveDB handle, live
|
|
199
201
|
// channel senders, schedulers, browser sessions, or in-memory services).
|
|
200
202
|
"search_knowledge",
|
|
203
|
+
"conversation_read",
|
|
201
204
|
"save_note",
|
|
202
205
|
"memory_write",
|
|
203
206
|
"memory_read",
|
|
@@ -597,6 +600,7 @@ function getPool(maxWorkers: number): ToolWorkerPool | null {
|
|
|
597
600
|
|
|
598
601
|
export async function executeToolBatch(options: ExecuteToolBatchOptions): Promise<ToolBatchResult[]> {
|
|
599
602
|
const runtimeConfig = resolveRuntimeConfig(options.workerPool)
|
|
603
|
+
const parallelToolCalls = options.parallelToolCalls ?? runtimeConfig.parallelToolCalls
|
|
600
604
|
const hiveConfig = options.hiveConfig ?? loadConfig()
|
|
601
605
|
const mainThreadToolNames = [
|
|
602
606
|
...DEFAULT_MAIN_THREAD_TOOL_NAMES,
|
|
@@ -617,11 +621,25 @@ export async function executeToolBatch(options: ExecuteToolBatchOptions): Promis
|
|
|
617
621
|
|
|
618
622
|
// A null pool means workers are disabled, unnecessary (single call), or
|
|
619
623
|
// unavailable in this build — all three degrade to the main thread.
|
|
620
|
-
const pool = runtimeConfig.enabled &&
|
|
624
|
+
const pool = runtimeConfig.enabled && parallelToolCalls && options.toolCalls.length > 1
|
|
621
625
|
? getPool(runtimeConfig.maxWorkers)
|
|
622
626
|
: null
|
|
623
627
|
|
|
624
628
|
if (!pool) {
|
|
629
|
+
if (options.parallelToolCalls === true && options.toolCalls.length > 1) {
|
|
630
|
+
return Promise.all(options.toolCalls.map(async (toolCall) => {
|
|
631
|
+
const startedAt = performance.now()
|
|
632
|
+
const effectiveTimeout = resolveToolTimeout(toolCall.function.name, options.allTools, hiveConfig, runtimeConfig.toolTimeoutMs)
|
|
633
|
+
const result = await executeInMainThreadWithTimeout({
|
|
634
|
+
toolCall, allTools: options.allTools, toolConfig: options.toolConfig, signal: options.signal,
|
|
635
|
+
}, effectiveTimeout)
|
|
636
|
+
return {
|
|
637
|
+
toolCall, toolName: toolCall.function.name, result,
|
|
638
|
+
ok: !(result && typeof result === "object" && (result as any).error === true),
|
|
639
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
640
|
+
}
|
|
641
|
+
}))
|
|
642
|
+
}
|
|
625
643
|
const results: ToolBatchResult[] = []
|
|
626
644
|
for (const toolCall of options.toolCalls) {
|
|
627
645
|
const startedAt = performance.now()
|
|
@@ -1,8 +1,62 @@
|
|
|
1
1
|
import type { Tool } from "../types.ts";
|
|
2
2
|
import type { Config } from "../../config/loader.ts";
|
|
3
|
-
import { canvasManager } from "../../canvas/canvas-manager.ts";
|
|
3
|
+
import { canvasManager, mergeComponentsById } from "../../canvas/canvas-manager.ts";
|
|
4
4
|
import { logger } from "../../utils/logger.ts";
|
|
5
5
|
|
|
6
|
+
/** Ids a component renders, in both the flat and the nested (`{ Card: {...} }`) forms. */
|
|
7
|
+
function childIds(component: Record<string, unknown>): string[] {
|
|
8
|
+
const nested = component.component && typeof component.component === "object" && !Array.isArray(component.component)
|
|
9
|
+
? Object.values(component.component as Record<string, unknown>)[0]
|
|
10
|
+
: undefined
|
|
11
|
+
const c = nested && typeof nested === "object" ? { ...component, ...(nested as Record<string, unknown>) } : component
|
|
12
|
+
const ids: unknown[] = []
|
|
13
|
+
const children = c.children
|
|
14
|
+
if (typeof children === "string") ids.push(children)
|
|
15
|
+
else if (Array.isArray(children)) ids.push(...children)
|
|
16
|
+
else if (children && typeof children === "object") {
|
|
17
|
+
const ch = children as Record<string, unknown>
|
|
18
|
+
if (Array.isArray(ch.explicitList)) ids.push(...ch.explicitList)
|
|
19
|
+
if (Array.isArray(ch.array)) ids.push(...ch.array)
|
|
20
|
+
ids.push(ch.componentId, (ch.template as Record<string, unknown> | undefined)?.componentId)
|
|
21
|
+
}
|
|
22
|
+
ids.push(c.child, c.trigger, c.content, c.entryPointChild, c.contentChild)
|
|
23
|
+
for (const tab of [...(Array.isArray(c.tabItems) ? c.tabItems : []), ...(Array.isArray(c.tabs) ? c.tabs : [])]) {
|
|
24
|
+
ids.push((tab as Record<string, unknown> | null)?.child)
|
|
25
|
+
}
|
|
26
|
+
return ids.filter((id): id is string => typeof id === "string" && id.length > 0)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* First cycle in the component tree ("card -> card"), or null. A component
|
|
31
|
+
* that contains itself or an ancestor made the panel recurse until the
|
|
32
|
+
* browser killed the tab.
|
|
33
|
+
*/
|
|
34
|
+
export function findComponentCycle(components: unknown[]): string[] | null {
|
|
35
|
+
const graph = new Map<string, string[]>()
|
|
36
|
+
for (const c of components) {
|
|
37
|
+
if (c && typeof c === "object" && typeof (c as { id?: unknown }).id === "string") {
|
|
38
|
+
graph.set((c as { id: string }).id, childIds(c as Record<string, unknown>))
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const done = new Set<string>()
|
|
42
|
+
const visit = (id: string, path: string[]): string[] | null => {
|
|
43
|
+
const loop = path.indexOf(id)
|
|
44
|
+
if (loop >= 0) return [...path.slice(loop), id]
|
|
45
|
+
if (done.has(id) || !graph.has(id)) return null
|
|
46
|
+
for (const child of graph.get(id)!) {
|
|
47
|
+
const cycle = visit(child, [...path, id])
|
|
48
|
+
if (cycle) return cycle
|
|
49
|
+
}
|
|
50
|
+
done.add(id)
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
for (const id of graph.keys()) {
|
|
54
|
+
const cycle = visit(id, [])
|
|
55
|
+
if (cycle) return cycle
|
|
56
|
+
}
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
6
60
|
export function createA2UISurfaceTool(_config: Config): Tool {
|
|
7
61
|
const log = logger.child("a2ui-surface");
|
|
8
62
|
|
|
@@ -148,6 +202,16 @@ Root component: usar id="root" explícito.`,
|
|
|
148
202
|
? (rawSessionId.startsWith("canvas:") ? rawSessionId : `canvas:${rawSessionId}`)
|
|
149
203
|
: (userId ? `canvas:${userId}` : (() => { throw new Error("No session or user ID provided"); })());
|
|
150
204
|
|
|
205
|
+
if (!Array.isArray(params.components)) throw new Error("components must be an array")
|
|
206
|
+
// Checked on the merged tree the client will render, not only this batch.
|
|
207
|
+
const cycle = findComponentCycle(mergeComponentsById(
|
|
208
|
+
canvasManager.getCachedComponents(sessionId, params.surfaceId as string),
|
|
209
|
+
params.components,
|
|
210
|
+
))
|
|
211
|
+
if (cycle) {
|
|
212
|
+
throw new Error(`Ciclo en los componentes: ${cycle.join(" -> ")}. Un componente no puede contenerse a sí mismo ni a un ancestro. Dale al hijo un id propio (por ejemplo "${cycle[0]}_contenido") y vuelve a enviar. No se publicó nada.`)
|
|
213
|
+
}
|
|
214
|
+
|
|
151
215
|
await canvasManager.sendA2UIMessage(sessionId, "a2ui:updateComponents", {
|
|
152
216
|
surfaceId: params.surfaceId as string,
|
|
153
217
|
components: params.components,
|
|
@@ -60,7 +60,9 @@ export const getAvailableModelsTool: Tool = {
|
|
|
60
60
|
.filter(m => m.enabled && providersById.has(m.provider_id));
|
|
61
61
|
|
|
62
62
|
if (providerId) models = models.filter(m => m.provider_id === providerId);
|
|
63
|
-
|
|
63
|
+
// Decision models (Jev) only answer the Decisions API, never chat: an
|
|
64
|
+
// agent assigned one would fail every turn.
|
|
65
|
+
models = modelType ? models.filter(m => m.model_type === modelType) : models.filter(m => m.model_type !== "decision");
|
|
64
66
|
if (capabilities) models = models.filter(m => (m.capabilities ?? "").includes(capabilities));
|
|
65
67
|
|
|
66
68
|
// Transformar a formato amigable
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapters for external coding-agent CLIs. Each one knows how to run its CLI
|
|
3
|
+
* non-interactively and how to pull a human-readable summary out of the output.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type CodeAgentId = "claude" | "codex" | "opencode" | "kimi";
|
|
7
|
+
|
|
8
|
+
export interface AdapterInvocation {
|
|
9
|
+
argv: string[];
|
|
10
|
+
/** Files the CLI writes its final message to (codex), read after exit. */
|
|
11
|
+
lastMessageFile?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AdapterInput {
|
|
15
|
+
prompt: string;
|
|
16
|
+
cwd: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
/** True when cwd is a throwaway worktree, so full auto-approval is safe. */
|
|
19
|
+
isolated: boolean;
|
|
20
|
+
tmpDir: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CodeAgentAdapter {
|
|
24
|
+
id: CodeAgentId;
|
|
25
|
+
binary: string;
|
|
26
|
+
build(input: AdapterInput): AdapterInvocation;
|
|
27
|
+
summarize(stdout: string, lastMessage?: string): { summary: string; sessionId?: string; costUsd?: number };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tail(text: string, max = 4000): string {
|
|
31
|
+
const t = text.trim();
|
|
32
|
+
return t.length > max ? `…${t.slice(-max)}` : t;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const claude: CodeAgentAdapter = {
|
|
36
|
+
id: "claude",
|
|
37
|
+
binary: "claude",
|
|
38
|
+
build({ prompt, model, isolated }) {
|
|
39
|
+
const argv = [
|
|
40
|
+
"claude", "-p", prompt,
|
|
41
|
+
"--output-format", "json",
|
|
42
|
+
"--permission-mode", isolated ? "bypassPermissions" : "acceptEdits",
|
|
43
|
+
];
|
|
44
|
+
if (model) argv.push("--model", model);
|
|
45
|
+
return { argv };
|
|
46
|
+
},
|
|
47
|
+
summarize(stdout) {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(stdout.trim());
|
|
50
|
+
return {
|
|
51
|
+
summary: String(parsed.result ?? ""),
|
|
52
|
+
sessionId: parsed.session_id,
|
|
53
|
+
costUsd: typeof parsed.total_cost_usd === "number" ? parsed.total_cost_usd : undefined,
|
|
54
|
+
};
|
|
55
|
+
} catch {
|
|
56
|
+
return { summary: tail(stdout) };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const codex: CodeAgentAdapter = {
|
|
62
|
+
id: "codex",
|
|
63
|
+
binary: "codex",
|
|
64
|
+
build({ prompt, cwd, model, tmpDir }) {
|
|
65
|
+
const lastMessageFile = `${tmpDir}/codex-last-message.txt`;
|
|
66
|
+
const argv = [
|
|
67
|
+
"codex", "exec",
|
|
68
|
+
"-s", "workspace-write",
|
|
69
|
+
"-C", cwd,
|
|
70
|
+
"--skip-git-repo-check",
|
|
71
|
+
"-o", lastMessageFile,
|
|
72
|
+
];
|
|
73
|
+
if (model) argv.push("-m", model);
|
|
74
|
+
argv.push(prompt);
|
|
75
|
+
return { argv, lastMessageFile };
|
|
76
|
+
},
|
|
77
|
+
summarize(stdout, lastMessage) {
|
|
78
|
+
return { summary: lastMessage?.trim() || tail(stdout) };
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const opencode: CodeAgentAdapter = {
|
|
83
|
+
id: "opencode",
|
|
84
|
+
binary: "opencode",
|
|
85
|
+
build({ prompt, model }) {
|
|
86
|
+
const argv = ["opencode", "run", "--auto"];
|
|
87
|
+
if (model) argv.push("-m", model);
|
|
88
|
+
argv.push(prompt);
|
|
89
|
+
return { argv };
|
|
90
|
+
},
|
|
91
|
+
summarize(stdout) {
|
|
92
|
+
return { summary: tail(stdout) };
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const kimi: CodeAgentAdapter = {
|
|
97
|
+
id: "kimi",
|
|
98
|
+
binary: "kimi",
|
|
99
|
+
// --prompt cannot be combined with --auto/--yolo: prompt mode runs unattended on its own.
|
|
100
|
+
build({ prompt, model }) {
|
|
101
|
+
const argv = ["kimi", "-p", prompt];
|
|
102
|
+
if (model) argv.push("-m", model);
|
|
103
|
+
return { argv };
|
|
104
|
+
},
|
|
105
|
+
summarize(stdout) {
|
|
106
|
+
return { summary: tail(stdout) };
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const ADAPTERS: Record<CodeAgentId, CodeAgentAdapter> = { claude, codex, opencode, kimi };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code_agent_run - Delegate a coding task to an external coding-agent CLI
|
|
3
|
+
* (Claude Code, Codex, OpenCode, Kimi).
|
|
4
|
+
*
|
|
5
|
+
* The CLI runs inside a throwaway git worktree when the workspace is a git
|
|
6
|
+
* repo, so it can be auto-approved safely. Nothing is merged: the result
|
|
7
|
+
* carries the diff and a patch file for the caller to review and apply.
|
|
8
|
+
*
|
|
9
|
+
* @category cli
|
|
10
|
+
* @seedId code_agent_run
|
|
11
|
+
* @spanish agente de código, delegar código, codex, claude code, opencode, kimi
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as os from "node:os";
|
|
16
|
+
import * as path from "node:path";
|
|
17
|
+
import type { Tool } from "../types.ts";
|
|
18
|
+
import { logger } from "../../utils/logger.ts";
|
|
19
|
+
import { resolveInWorkspace, getWorkspace, expandPath } from "../filesystem/workspace-guard.ts";
|
|
20
|
+
import { ADAPTERS, type CodeAgentId } from "./adapters.ts";
|
|
21
|
+
|
|
22
|
+
const log = logger.child("code-agent");
|
|
23
|
+
|
|
24
|
+
const DEFAULT_TIMEOUT_SECS = 600;
|
|
25
|
+
const MAX_TIMEOUT_SECS = 3600;
|
|
26
|
+
const MAX_DIFF_CHARS = 20000;
|
|
27
|
+
|
|
28
|
+
/** Env vars that must never reach an external CLI. */
|
|
29
|
+
const SECRET_ENV = /(^|_)(TOKEN|SECRET|PASSWORD|KEY)(_|$)/i;
|
|
30
|
+
const KEEP_ENV = new Set(["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "MOONSHOT_API_KEY", "KIMI_API_KEY", "OPENROUTER_API_KEY"]);
|
|
31
|
+
|
|
32
|
+
function cleanEnv(): Record<string, string> {
|
|
33
|
+
const env: Record<string, string> = {};
|
|
34
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
35
|
+
if (v === undefined) continue;
|
|
36
|
+
if (SECRET_ENV.test(k) && !KEEP_ENV.has(k)) continue;
|
|
37
|
+
env[k] = v;
|
|
38
|
+
}
|
|
39
|
+
return env;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function run(argv: string[], cwd: string, opts: { signal?: AbortSignal; env?: Record<string, string> } = {}) {
|
|
43
|
+
const proc = Bun.spawn(argv, { cwd, stdout: "pipe", stderr: "pipe", signal: opts.signal, env: opts.env });
|
|
44
|
+
const [stdout, stderr] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text()]);
|
|
45
|
+
const exitCode = await proc.exited;
|
|
46
|
+
return { stdout, stderr, exitCode };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function gitRoot(cwd: string): Promise<string | null> {
|
|
50
|
+
try {
|
|
51
|
+
const r = await run(["git", "rev-parse", "--show-toplevel"], cwd);
|
|
52
|
+
return r.exitCode === 0 ? r.stdout.trim() : null;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const codeAgentRunTool: Tool = {
|
|
59
|
+
name: "code_agent_run",
|
|
60
|
+
// Coding agents are slow; the harness ceiling must exceed the per-call timeout.
|
|
61
|
+
timeoutMs: (MAX_TIMEOUT_SECS + 60) * 1000,
|
|
62
|
+
description:
|
|
63
|
+
"Delegate a coding task to an external coding-agent CLI (claude, codex, opencode, kimi). " +
|
|
64
|
+
"Runs in an isolated git worktree when possible and returns the summary, changed files and diff; " +
|
|
65
|
+
"it never merges into the workspace. Spanish: agente de código externo, delegar programación",
|
|
66
|
+
parameters: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
agent: { type: "string", enum: ["claude", "codex", "opencode", "kimi"], description: "Which coding-agent CLI to use" },
|
|
70
|
+
prompt: { type: "string", description: "Complete, self-contained task instructions for the coding agent" },
|
|
71
|
+
cwd: { type: "string", description: "Repository directory (default: agent workspace)" },
|
|
72
|
+
model: { type: "string", description: "Optional model override understood by that CLI" },
|
|
73
|
+
timeout: { type: "number", description: `Timeout in seconds (default ${DEFAULT_TIMEOUT_SECS}, max ${MAX_TIMEOUT_SECS})` },
|
|
74
|
+
},
|
|
75
|
+
required: ["agent", "prompt"],
|
|
76
|
+
},
|
|
77
|
+
execute: async (params, config) => {
|
|
78
|
+
const agentId = params.agent as CodeAgentId;
|
|
79
|
+
const adapter = ADAPTERS[agentId];
|
|
80
|
+
if (!adapter) return { ok: false, error: `Unknown agent '${String(params.agent)}'. Use: ${Object.keys(ADAPTERS).join(", ")}` };
|
|
81
|
+
const prompt = String(params.prompt ?? "").trim();
|
|
82
|
+
if (!prompt) return { ok: false, error: "prompt is required" };
|
|
83
|
+
|
|
84
|
+
// Bun.which looks at the PATH the process started with; pass the live one so
|
|
85
|
+
// a PATH changed at runtime (a user shell hook, a test double) is honoured.
|
|
86
|
+
if (!Bun.which(adapter.binary, { PATH: process.env.PATH })) {
|
|
87
|
+
return { ok: false, error: `'${adapter.binary}' is not installed or not in PATH`, hint: "Install that CLI or choose another agent." };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const workspace = getWorkspace(config);
|
|
91
|
+
let cwd: string;
|
|
92
|
+
try {
|
|
93
|
+
const raw = (params.cwd as string) ?? (workspace ? expandPath(workspace) : process.cwd());
|
|
94
|
+
cwd = resolveInWorkspace(raw, workspace);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return { ok: false, error: (e as Error).message };
|
|
97
|
+
}
|
|
98
|
+
if (!fs.existsSync(cwd)) return { ok: false, error: `Working directory not found: ${cwd}` };
|
|
99
|
+
|
|
100
|
+
const timeoutSecs = Math.min(Math.max((params.timeout as number) ?? DEFAULT_TIMEOUT_SECS, 10), MAX_TIMEOUT_SECS);
|
|
101
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "hive-code-agent-"));
|
|
102
|
+
const root = await gitRoot(cwd);
|
|
103
|
+
let runDir = cwd;
|
|
104
|
+
let worktree: string | null = null;
|
|
105
|
+
|
|
106
|
+
if (root) {
|
|
107
|
+
const wt = path.join(tmpDir, "worktree");
|
|
108
|
+
const add = await run(["git", "worktree", "add", "--detach", wt, "HEAD"], root);
|
|
109
|
+
if (add.exitCode === 0) {
|
|
110
|
+
worktree = wt;
|
|
111
|
+
runDir = path.join(wt, path.relative(root, cwd));
|
|
112
|
+
} else {
|
|
113
|
+
log.warn(`worktree failed, running in place with reduced permissions: ${add.stderr.trim()}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const invocation = adapter.build({
|
|
118
|
+
prompt,
|
|
119
|
+
cwd: runDir,
|
|
120
|
+
model: params.model as string | undefined,
|
|
121
|
+
isolated: worktree !== null,
|
|
122
|
+
tmpDir,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
log.info(`code_agent_run ${agentId} (cwd=${runDir}, isolated=${worktree !== null})`);
|
|
126
|
+
const t0 = performance.now();
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const timer = setTimeout(() => controller.abort(), timeoutSecs * 1000);
|
|
129
|
+
let result: { stdout: string; stderr: string; exitCode: number } | null = null;
|
|
130
|
+
let timedOut = false;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
result = await run(invocation.argv, runDir, { signal: controller.signal, env: cleanEnv() });
|
|
134
|
+
} catch {
|
|
135
|
+
timedOut = controller.signal.aborted;
|
|
136
|
+
} finally {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let diff = "";
|
|
141
|
+
let files: string[] = [];
|
|
142
|
+
let patchPath: string | undefined;
|
|
143
|
+
if (worktree) {
|
|
144
|
+
await run(["git", "add", "-A"], worktree);
|
|
145
|
+
diff = (await run(["git", "diff", "--cached", "HEAD"], worktree)).stdout;
|
|
146
|
+
files = (await run(["git", "diff", "--cached", "--name-only", "HEAD"], worktree)).stdout.split("\n").filter(Boolean);
|
|
147
|
+
if (diff) {
|
|
148
|
+
patchPath = path.join(os.tmpdir(), `hive-code-agent-${Date.now()}.patch`);
|
|
149
|
+
fs.writeFileSync(patchPath, diff);
|
|
150
|
+
}
|
|
151
|
+
await run(["git", "worktree", "remove", "--force", worktree], root!);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let lastMessage: string | undefined;
|
|
155
|
+
if (invocation.lastMessageFile && fs.existsSync(invocation.lastMessageFile)) {
|
|
156
|
+
lastMessage = fs.readFileSync(invocation.lastMessageFile, "utf8");
|
|
157
|
+
}
|
|
158
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
159
|
+
|
|
160
|
+
const elapsedMs = Math.round(performance.now() - t0);
|
|
161
|
+
if (!result) {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
agent: agentId,
|
|
165
|
+
error: timedOut ? `${agentId} killed after ${timeoutSecs}s timeout` : `${agentId} failed to run`,
|
|
166
|
+
files_changed: files,
|
|
167
|
+
patch_path: patchPath,
|
|
168
|
+
executionTimeMs: elapsedMs,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const parsed = adapter.summarize(result.stdout, lastMessage);
|
|
173
|
+
return {
|
|
174
|
+
ok: result.exitCode === 0,
|
|
175
|
+
agent: agentId,
|
|
176
|
+
exitCode: result.exitCode,
|
|
177
|
+
isolated: worktree !== null,
|
|
178
|
+
summary: parsed.summary,
|
|
179
|
+
session_id: parsed.sessionId,
|
|
180
|
+
cost_usd: parsed.costUsd,
|
|
181
|
+
files_changed: files,
|
|
182
|
+
diff: diff.length > MAX_DIFF_CHARS ? `${diff.slice(0, MAX_DIFF_CHARS)}\n…(truncated, see patch_path)` : diff,
|
|
183
|
+
patch_path: patchPath,
|
|
184
|
+
stderr: result.exitCode === 0 ? undefined : result.stderr.trim().slice(-2000),
|
|
185
|
+
executionTimeMs: elapsedMs,
|
|
186
|
+
apply_hint: patchPath ? `git apply ${patchPath}` : undefined,
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export function createTools(): Tool[] {
|
|
192
|
+
return [codeAgentRunTool];
|
|
193
|
+
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type CapabilityType,
|
|
15
15
|
} from "../../agent/capability-search.ts";
|
|
16
16
|
import { CORE_TOOL_CATALOG } from "../../agent/tool-selector.ts";
|
|
17
|
-
import { saveScratchpadNote } from "../../agent/conversation-store.ts";
|
|
17
|
+
import { saveScratchpadNote, getRecentMessages, getScratchpad } from "../../agent/conversation-store.ts";
|
|
18
18
|
|
|
19
19
|
const log = logger.child("core");
|
|
20
20
|
|
|
@@ -353,7 +353,9 @@ export const notifyTool: Tool = {
|
|
|
353
353
|
|
|
354
354
|
log.info(`[notify] Sending to ${channel}/${userId}: ${message.substring(0, 80)}`);
|
|
355
355
|
|
|
356
|
-
const
|
|
356
|
+
const threadId = config?.configurable?.thread_id as string | undefined;
|
|
357
|
+
|
|
358
|
+
const result = await sendToUserChannel(channel, userId, message, { threadId })
|
|
357
359
|
if (!result.ok) throw new Error(`Channel send failed: ${result.error}`)
|
|
358
360
|
return result
|
|
359
361
|
},
|
|
@@ -448,13 +450,46 @@ export const reportProgressTool: Tool = {
|
|
|
448
450
|
|
|
449
451
|
// Send real-time update to the user's channel
|
|
450
452
|
const progressEmoji = progress >= 100 ? "✅" : progress >= 50 ? "⚙️" : "🔄";
|
|
451
|
-
const result = await sendToUserChannel(channel, userId, `${progressEmoji} ${progress}% — ${message}
|
|
453
|
+
const result = await sendToUserChannel(channel, userId, `${progressEmoji} ${progress}% — ${message}`, {
|
|
454
|
+
threadId: config?.configurable?.thread_id as string | undefined,
|
|
455
|
+
})
|
|
452
456
|
if (!result.ok) throw new Error(`Channel send failed: ${result.error}`)
|
|
453
457
|
|
|
454
458
|
return { ok: true, progress, message, task_id: taskId };
|
|
455
459
|
},
|
|
456
460
|
};
|
|
457
461
|
|
|
462
|
+
/** Recover a small, scoped slice of conversation omitted by Jev's context plan. */
|
|
463
|
+
export const conversationReadTool: Tool = {
|
|
464
|
+
name: "conversation_read",
|
|
465
|
+
description: "Read earlier messages from the current conversation by message IDs or text query when selected context is insufficient.",
|
|
466
|
+
parameters: {
|
|
467
|
+
type: "object",
|
|
468
|
+
properties: {
|
|
469
|
+
message_ids: { type: "array", description: "Message IDs shown in the context plan", items: { type: "number" } },
|
|
470
|
+
note_keys: { type: "array", description: "Scratchpad note keys shown in the context plan", items: { type: "string" } },
|
|
471
|
+
query: { type: "string", description: "Optional case-insensitive text to search in earlier messages" },
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
execute: async (params, config) => {
|
|
475
|
+
const threadId = config?.configurable?.thread_id as string | undefined
|
|
476
|
+
if (!threadId) return { ok: false, error: "Conversation scope unavailable" }
|
|
477
|
+
const ids = new Set(Array.isArray(params.message_ids) ? params.message_ids.map(Number).filter(Number.isFinite) : [])
|
|
478
|
+
const noteKeys = new Set(Array.isArray(params.note_keys) ? params.note_keys.map(String) : [])
|
|
479
|
+
const query = String(params.query ?? "").trim().toLocaleLowerCase()
|
|
480
|
+
if (!ids.size && !noteKeys.size && !query) return { ok: false, error: "Provide message_ids, note_keys or query" }
|
|
481
|
+
const rows = await getRecentMessages(threadId, 200)
|
|
482
|
+
const notes = await getScratchpad(threadId)
|
|
483
|
+
return {
|
|
484
|
+
ok: true,
|
|
485
|
+
messages: rows.filter(row => (ids.size && ids.has(row.id)) || (query && row.content.toLocaleLowerCase().includes(query)))
|
|
486
|
+
.slice(-8).map(row => ({ id: row.id, role: row.role, source: row.source, content: row.content.slice(0, 2000) })),
|
|
487
|
+
notes: notes.filter(note => noteKeys.has(note.key) || (query && `${note.key} ${note.value}`.toLocaleLowerCase().includes(query)))
|
|
488
|
+
.slice(0, 8).map(note => ({ key: note.key, value: note.value.slice(0, 2000) })),
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
|
|
458
493
|
export function createTools(): Tool[] {
|
|
459
|
-
return [searchKnowledgeTool, notifyTool, saveNoteTool, reportProgressTool];
|
|
494
|
+
return [searchKnowledgeTool, notifyTool, saveNoteTool, reportProgressTool, conversationReadTool];
|
|
460
495
|
}
|
|
@@ -12,7 +12,7 @@ import type { Tool } from "../types";
|
|
|
12
12
|
import { col, toIndexable } from "../../storage/hive";
|
|
13
13
|
import type { UserDoc, UserIdentityDoc, ChannelDoc, CronJobDoc, TaskRunDoc } from "../../storage/collections";
|
|
14
14
|
import { logger } from "../../utils/logger";
|
|
15
|
-
import { Cron } from "
|
|
15
|
+
import { Cron } from "../../scheduler/cron";
|
|
16
16
|
|
|
17
17
|
const log = logger.child("CronTools");
|
|
18
18
|
|
|
@@ -114,9 +114,9 @@ export const cronCreateTool: Tool = {
|
|
|
114
114
|
tool_name: { type: "string", description: "Specific tool to execute (optional)" },
|
|
115
115
|
max_runs: { type: "number", description: "Maximum executions (optional, null = unlimited)" },
|
|
116
116
|
channel: { type: "string", description: "Notification channel (system, telegram, discord, whatsapp, cli)" },
|
|
117
|
-
start_at: { type: "string", description: "ISO 8601 datetime: start of execution window
|
|
118
|
-
stop_at: { type: "string", description: "ISO 8601 datetime: end of execution window
|
|
119
|
-
dom_and_dow: { type: "boolean", description: "If true, both day-of-month AND day-of-week must match
|
|
117
|
+
start_at: { type: "string", description: "ISO 8601 datetime: start of execution window. Optional." },
|
|
118
|
+
stop_at: { type: "string", description: "ISO 8601 datetime: end of execution window. Optional." },
|
|
119
|
+
dom_and_dow: { type: "boolean", description: "If true, both day-of-month AND day-of-week must match. Default: false (OR logic)" },
|
|
120
120
|
},
|
|
121
121
|
required: ["name", "task", "task_type"],
|
|
122
122
|
},
|
|
@@ -14,12 +14,15 @@ import * as filesystem from "./filesystem/index.ts";
|
|
|
14
14
|
// Web (11)
|
|
15
15
|
import * as web from "./web/index.ts";
|
|
16
16
|
|
|
17
|
-
// Cron (8) -
|
|
17
|
+
// Cron (8) - scheduler tools
|
|
18
18
|
import * as cron from "./cron/index.ts";
|
|
19
19
|
|
|
20
20
|
// CLI (1)
|
|
21
21
|
import * as cli from "./cli/index.ts";
|
|
22
22
|
|
|
23
|
+
// Code agents (1) - external coding-agent CLIs
|
|
24
|
+
import * as codeAgent from "./code-agent/index.ts";
|
|
25
|
+
|
|
23
26
|
// Agents (15)
|
|
24
27
|
import * as agents from "./agents/index.ts";
|
|
25
28
|
|
|
@@ -52,6 +55,9 @@ export function createAllTools(config: Config): Tool[] {
|
|
|
52
55
|
// CLI (1)
|
|
53
56
|
...cli.createTools(),
|
|
54
57
|
|
|
58
|
+
// CODE AGENTS (1)
|
|
59
|
+
...codeAgent.createTools(),
|
|
60
|
+
|
|
55
61
|
// AGENTS (14)
|
|
56
62
|
...agents.createTools(),
|
|
57
63
|
|
|
@@ -83,6 +89,8 @@ export function createToolsByCategory(category: string, config: Config): Tool[]
|
|
|
83
89
|
return cron.createTools();
|
|
84
90
|
case "cli":
|
|
85
91
|
return cli.createTools();
|
|
92
|
+
case "code-agent":
|
|
93
|
+
return codeAgent.createTools();
|
|
86
94
|
case "agents":
|
|
87
95
|
return agents.createTools();
|
|
88
96
|
case "a2ui":
|