u-foo 3.1.7 → 4.0.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/OBSERVABILITY.md +65 -0
- package/README.md +238 -21
- package/README.zh-CN.md +165 -20
- package/SKILLS/ufoo/SKILL.md +40 -4
- package/SKILLS/ufoo-bus/SKILL.md +46 -3
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +6 -4
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +14 -7
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +140 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +40 -22
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +181 -76
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +96 -14
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +15 -20
- package/src/agents/launch/readyDetector.js +28 -14
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +32 -6
- package/src/agents/prompts/mainAgent.js +48 -0
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +14 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +9 -1
- package/src/agents/providers/claudeThreadProvider.js +47 -4
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +68 -7
- package/src/agents/providers/codexThreadProvider.js +18 -8
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +1146 -0
- package/src/agents/providers/runtimeConfig.js +188 -0
- package/src/agents/providers/thinkingLevels.js +106 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +504 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +127 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +351 -0
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +259 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +29 -45
- package/src/app/chat/agentDirectory.js +9 -18
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +111 -313
- package/src/app/chat/commands.js +39 -45
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -48
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +21 -35
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +91 -164
- package/src/app/chat/streamState.js +3 -7
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +82 -42
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +34 -17
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +9 -9
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +107 -0
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +104 -2697
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +27 -99
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolBudget.js +1 -17
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +95 -131
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +14 -9
- package/src/coordination/bus/inject.js +15 -7
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +8 -4
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +26 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +20 -17
- package/src/runtime/daemon/agentHost.js +407 -0
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +28 -18
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +21 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +120 -375
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +8 -5
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +68 -40
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -570
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +9 -6
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +28 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +6 -0
- package/src/tools/schemaFixtures.js +42 -5
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +9 -15
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +316 -599
- package/src/ui/rustMultiSession.js +288 -73
- package/src/ui/rustUcodeHost.js +21 -88
- package/src/ui/settingsBridge.js +34 -14
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -472
- package/src/agents/controller/ufooAgent.js +0 -829
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/upstreamTransport.js +0 -689
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { canonicalProjectRoot } = require("../../runtime/projects/projectId");
|
|
3
|
+
const { listProjectRuntimes, projectPathExists } = require("../../runtime/projects/registry");
|
|
4
|
+
const { buildToolError } = require("./common");
|
|
2
5
|
|
|
3
6
|
function readProjectRegistryHandler(_ctx = {}, args = {}) {
|
|
4
7
|
const validate = args.validate !== false;
|
|
5
8
|
const cleanupTmp = args.cleanup_tmp !== false;
|
|
6
|
-
const
|
|
9
|
+
const limit = args.limit === undefined ? 100 : args.limit;
|
|
10
|
+
const offset = args.offset === undefined ? 0 : args.offset;
|
|
11
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1000
|
|
12
|
+
|| !Number.isInteger(offset) || offset < 0) {
|
|
13
|
+
throw buildToolError("invalid_arguments", "registry limit must be 1..1000 and offset must be nonnegative integers");
|
|
14
|
+
}
|
|
15
|
+
const rows = listProjectRuntimes({
|
|
7
16
|
validate,
|
|
8
17
|
cleanupTmp,
|
|
9
18
|
runtimeDir: args.runtimeDir,
|
|
10
19
|
});
|
|
20
|
+
let root = "";
|
|
21
|
+
if (args.project_root) {
|
|
22
|
+
try { root = canonicalProjectRoot(args.project_root); }
|
|
23
|
+
catch { root = path.resolve(args.project_root); }
|
|
24
|
+
}
|
|
25
|
+
let omittedMissing = 0;
|
|
26
|
+
const filtered = rows.filter((row) => {
|
|
27
|
+
if (root && path.resolve(row.project_root) !== root) return false;
|
|
28
|
+
if (args.include_missing !== true && !projectPathExists(row.project_root)) {
|
|
29
|
+
omittedMissing += 1;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
const projects = filtered.slice(offset, offset + limit);
|
|
11
35
|
|
|
12
36
|
return {
|
|
13
37
|
count: projects.length,
|
|
38
|
+
total: filtered.length,
|
|
39
|
+
next_offset: offset + projects.length < filtered.length ? offset + projects.length : null,
|
|
40
|
+
omitted_missing: omittedMissing,
|
|
14
41
|
projects,
|
|
15
42
|
};
|
|
16
43
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
5
|
+
const { isMetaActive } = require("../../coordination/bus/utils");
|
|
6
|
+
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
7
|
+
const { buildToolError } = require("./common");
|
|
8
|
+
|
|
9
|
+
/** Read-only routing preview. Selection never launches or dispatches work. */
|
|
10
|
+
function routeAgentHandler(ctx = {}, args = {}) {
|
|
11
|
+
if (typeof args.request !== "string" || !args.request.trim()) throw buildToolError("invalid_arguments", "route_agent requires request");
|
|
12
|
+
const file = getUfooPaths(ctx.projectRoot).agentsFile;
|
|
13
|
+
const bus = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : { agents: {} };
|
|
14
|
+
const hint = String(args.context_hint || "").toLowerCase();
|
|
15
|
+
const text = `${args.request} ${hint}`.toLowerCase();
|
|
16
|
+
const tokens = new Set(text.match(/[a-z0-9_-]{3,}/g) || []);
|
|
17
|
+
const candidates = Object.entries(bus.agents || {}).filter(([id, meta]) => (
|
|
18
|
+
id !== "ufoo-agent" && meta.agent_type !== "ufoo-agent" && isMetaActive(meta)
|
|
19
|
+
&& (!ctx.internalAgentsOnly || isInternalAgentMeta(meta))
|
|
20
|
+
)).map(([id, meta]) => {
|
|
21
|
+
const nickname = String(meta.nickname || "");
|
|
22
|
+
const role = String(meta.role || meta.solo_role || meta.prompt_profile || "").toLowerCase();
|
|
23
|
+
const explicit = [id, nickname].some((name) => name && (hint === name.toLowerCase() || text.includes(`@${name.toLowerCase()}`)));
|
|
24
|
+
const matches = [...tokens].filter((token) => role.includes(token)).length;
|
|
25
|
+
const idle = ["idle", "waiting", ""].includes(meta.activity_state || "");
|
|
26
|
+
return { id, nickname, explicit, matches, idle, score: (explicit ? 100 : 0) + matches * 10 + (idle ? 1 : 0) };
|
|
27
|
+
}).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
|
|
28
|
+
const selected = candidates[0];
|
|
29
|
+
if (!selected) return { target: "", nickname: "", reason: "No active worker in this project; choose direct execution or launch explicitly.", confidence: 0 };
|
|
30
|
+
return { target: selected.id, nickname: selected.nickname,
|
|
31
|
+
reason: selected.explicit ? "Explicit worker reference" : selected.matches ? "Matching role/profile" : selected.idle ? "Available project worker" : "Active project worker; currently busy",
|
|
32
|
+
confidence: selected.explicit ? 1 : selected.matches ? 0.8 : 0.4 };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { routeAgentHandler };
|
|
@@ -3,6 +3,7 @@ const {
|
|
|
3
3
|
assertControllerTier,
|
|
4
4
|
extractAuditFields,
|
|
5
5
|
} = require("./common");
|
|
6
|
+
const { normalizeInternalAgentType } = require("../../runtime/contracts/agentMode");
|
|
6
7
|
|
|
7
8
|
function normalizePositiveInt(value, fallback) {
|
|
8
9
|
const num = Number.parseInt(value, 10);
|
|
@@ -38,11 +39,12 @@ async function runSingleOp(ctx, op, toolName) {
|
|
|
38
39
|
async function launchAgentHandler(ctx = {}, args = {}) {
|
|
39
40
|
assertControllerTier(ctx, "launch_agent");
|
|
40
41
|
const audit = extractAuditFields(ctx);
|
|
41
|
-
const agent =
|
|
42
|
-
if (!agent) guardInvalidArgs(ctx, "launch_agent", "requires
|
|
42
|
+
const agent = normalizeInternalAgentType(args.agent);
|
|
43
|
+
if (!agent) guardInvalidArgs(ctx, "launch_agent", "requires internal codex, claude or ucode");
|
|
43
44
|
|
|
44
45
|
const op = {
|
|
45
46
|
action: "launch",
|
|
47
|
+
internal_only: true,
|
|
46
48
|
agent,
|
|
47
49
|
count: normalizePositiveInt(args.count, 1),
|
|
48
50
|
};
|
package/src/tools/index.js
CHANGED
package/src/tools/registry.js
CHANGED
|
@@ -3,6 +3,8 @@ const readBusSummary = require("./tier0/readBusSummary");
|
|
|
3
3
|
const readOpenDecisions = require("./tier0/readOpenDecisions");
|
|
4
4
|
const readProjectRegistry = require("./tier0/readProjectRegistry");
|
|
5
5
|
const readPromptHistory = require("./tier0/readPromptHistory");
|
|
6
|
+
const readAgentTrace = require("./tier0/readAgentTrace");
|
|
7
|
+
const readAgentMetrics = require("./tier0/readAgentMetrics");
|
|
6
8
|
const ackBus = require("./tier1/ackBus");
|
|
7
9
|
const dispatchMessage = require("./tier1/dispatchMessage");
|
|
8
10
|
const editMemory = require("./tier1/editMemory");
|
|
@@ -16,6 +18,7 @@ const closeAgent = require("./tier2/closeAgent");
|
|
|
16
18
|
const launchAgent = require("./tier2/launchAgent");
|
|
17
19
|
const manageCron = require("./tier2/manageCron");
|
|
18
20
|
const renameAgent = require("./tier2/renameAgent");
|
|
21
|
+
const runtimeCoordination = require("./tier2/runtimeCoordination");
|
|
19
22
|
const {
|
|
20
23
|
CALLER_TIERS,
|
|
21
24
|
assertCallerTierAllowed,
|
|
@@ -24,6 +27,8 @@ const {
|
|
|
24
27
|
} = require("./types");
|
|
25
28
|
|
|
26
29
|
const SHARED_TOOL_REGISTRY = Object.freeze([
|
|
30
|
+
readAgentMetrics,
|
|
31
|
+
readAgentTrace,
|
|
27
32
|
readBusSummary,
|
|
28
33
|
readPromptHistory,
|
|
29
34
|
readOpenDecisions,
|
|
@@ -42,6 +47,7 @@ const SHARED_TOOL_REGISTRY = Object.freeze([
|
|
|
42
47
|
renameAgent,
|
|
43
48
|
closeAgent,
|
|
44
49
|
manageCron,
|
|
50
|
+
...runtimeCoordination,
|
|
45
51
|
]);
|
|
46
52
|
|
|
47
53
|
function getSharedToolRegistry() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { INTERNAL_AGENT_TYPES } = require("../runtime/contracts/agentMode");
|
|
1
2
|
const SCHEMA_VERSION = "1.0";
|
|
2
3
|
|
|
3
4
|
const CALLER_TIERS_READ_COORD = Object.freeze(["controller", "worker"]);
|
|
@@ -131,12 +132,16 @@ const READ_PROJECT_REGISTRY_SCHEMA = Object.freeze({
|
|
|
131
132
|
name: "read_project_registry",
|
|
132
133
|
tier: "tier0-read",
|
|
133
134
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
134
|
-
description: "Read the cross-project runtime registry.",
|
|
135
|
+
description: "Read a page of the cross-project runtime registry. Deleted project paths are hidden by default; use next_offset to read more.",
|
|
135
136
|
input_schema: Object.freeze({
|
|
136
137
|
type: "object",
|
|
137
138
|
properties: Object.freeze({
|
|
138
139
|
validate: Object.freeze({ type: "boolean" }),
|
|
139
140
|
cleanup_tmp: Object.freeze({ type: "boolean" }),
|
|
141
|
+
include_missing: Object.freeze({ type: "boolean", default: false }),
|
|
142
|
+
limit: Object.freeze({ type: "integer", minimum: 1, maximum: 1000, default: 100 }),
|
|
143
|
+
offset: Object.freeze({ type: "integer", minimum: 0, default: 0 }),
|
|
144
|
+
project_root: Object.freeze({ type: "string", description: "Filter to this exact project root." }),
|
|
140
145
|
}),
|
|
141
146
|
additionalProperties: false,
|
|
142
147
|
}),
|
|
@@ -145,6 +150,9 @@ const READ_PROJECT_REGISTRY_SCHEMA = Object.freeze({
|
|
|
145
150
|
required: ["count", "projects"],
|
|
146
151
|
properties: Object.freeze({
|
|
147
152
|
count: Object.freeze({ type: "integer" }),
|
|
153
|
+
total: Object.freeze({ type: "integer" }),
|
|
154
|
+
next_offset: Object.freeze({ type: Object.freeze(["integer", "null"]) }),
|
|
155
|
+
omitted_missing: Object.freeze({ type: "integer" }),
|
|
148
156
|
projects: Object.freeze({
|
|
149
157
|
type: "array",
|
|
150
158
|
items: Object.freeze({ type: "object", additionalProperties: true }),
|
|
@@ -159,7 +167,7 @@ const ROUTE_AGENT_SCHEMA = Object.freeze({
|
|
|
159
167
|
name: "route_agent",
|
|
160
168
|
tier: "tier1-coordination",
|
|
161
169
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
162
|
-
description: "
|
|
170
|
+
description: "Preview an active worker in the current project using explicit references, roles, and availability. Returns an empty target when none is available. Does not launch or dispatch; the main agent decides the next action.",
|
|
163
171
|
input_schema: Object.freeze({
|
|
164
172
|
type: "object",
|
|
165
173
|
required: ["request"],
|
|
@@ -187,7 +195,7 @@ const DISPATCH_MESSAGE_SCHEMA = Object.freeze({
|
|
|
187
195
|
name: "dispatch_message",
|
|
188
196
|
tier: "tier1-coordination",
|
|
189
197
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
190
|
-
description: "
|
|
198
|
+
description: "Enqueue a message for a target agent, nickname, or broadcast queue. Success confirms queue persistence, not delivery or processing.",
|
|
191
199
|
input_schema: Object.freeze({
|
|
192
200
|
type: "object",
|
|
193
201
|
required: ["target", "message"],
|
|
@@ -209,6 +217,11 @@ const DISPATCH_MESSAGE_SCHEMA = Object.freeze({
|
|
|
209
217
|
ok: Object.freeze({ type: "boolean" }),
|
|
210
218
|
delivered: Object.freeze({ type: "integer" }),
|
|
211
219
|
queued: Object.freeze({ type: "integer" }),
|
|
220
|
+
delivery_status: Object.freeze({ type: "string", enum: Object.freeze(["queued"]) }),
|
|
221
|
+
target: Object.freeze({ type: "string" }),
|
|
222
|
+
source: Object.freeze({ type: "string" }),
|
|
223
|
+
mode: Object.freeze({ type: "string", enum: Object.freeze(["immediate", "queued"]) }),
|
|
224
|
+
seq: Object.freeze({ type: "integer" }),
|
|
212
225
|
targets: Object.freeze({
|
|
213
226
|
type: "array",
|
|
214
227
|
items: Object.freeze({ type: "string" }),
|
|
@@ -223,7 +236,7 @@ const ACK_BUS_SCHEMA = Object.freeze({
|
|
|
223
236
|
name: "ack_bus",
|
|
224
237
|
tier: "tier1-coordination",
|
|
225
238
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
226
|
-
description: "Acknowledge pending bus messages for the caller-owned queue only.",
|
|
239
|
+
description: "Acknowledge pending bus messages for the caller-owned queue only. Internal runners confirm completed tasks automatically; calls for internal agents acknowledge zero messages and preserve queued work.",
|
|
227
240
|
input_schema: Object.freeze({
|
|
228
241
|
type: "object",
|
|
229
242
|
properties: Object.freeze({
|
|
@@ -462,7 +475,7 @@ const LAUNCH_AGENT_SCHEMA = Object.freeze({
|
|
|
462
475
|
properties: Object.freeze({
|
|
463
476
|
agent: Object.freeze({
|
|
464
477
|
type: "string",
|
|
465
|
-
enum:
|
|
478
|
+
enum: INTERNAL_AGENT_TYPES,
|
|
466
479
|
}),
|
|
467
480
|
count: Object.freeze({ type: "integer", minimum: 1 }),
|
|
468
481
|
nickname: Object.freeze({ type: "string" }),
|
|
@@ -589,7 +602,28 @@ const MANAGE_CRON_SCHEMA = Object.freeze({
|
|
|
589
602
|
}),
|
|
590
603
|
});
|
|
591
604
|
|
|
605
|
+
const READ_AGENT_TRACE_SCHEMA = Object.freeze({ name: "read_agent_trace", schema_version: SCHEMA_VERSION,
|
|
606
|
+
tier: "tier0-read", allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
607
|
+
description: "Read a task timeline across main/worker model and tool events, reports, queue state and context compaction, with an observed performance summary. Default shows the latest events with concise summaries; details includes redacted parameters/results. This is observation only, not acceptance or delivery acknowledgement.",
|
|
608
|
+
input_schema: { type: "object", properties: {
|
|
609
|
+
task_id: { type: "string", description: "Exact delegated task ID or parent taskRunId; includes related descendants." },
|
|
610
|
+
agent_id: { type: "string", description: "Worker subscriber ID or registered nickname." }, session_id: { type: "string" },
|
|
611
|
+
since: { type: "string", description: "ISO timestamp lower bound." }, limit: { type: "integer", minimum: 1, maximum: 2000 },
|
|
612
|
+
offset: { type: "integer", minimum: 0, description: "Explicit oldest-first pagination offset. Omit for the newest page." }, details: { type: "boolean" },
|
|
613
|
+
}, additionalProperties: false }, output_schema: { type: "object" } });
|
|
614
|
+
|
|
615
|
+
const READ_AGENT_METRICS_SCHEMA = Object.freeze({ name: "read_agent_metrics", schema_version: SCHEMA_VERSION,
|
|
616
|
+
tier: "tier0-read", allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
617
|
+
description: "Read observed agent execution outcomes, latency, usage, tool errors/repetition, report size and delegation acceptance, grouped by provider/model/configuration. Time filters select run starts and retain full observed lifecycles. Missing evidence is unknown; execution completion is not acceptance or a quality score. No model calls or state mutations.",
|
|
618
|
+
input_schema: { type: "object", properties: {
|
|
619
|
+
task_id: { type: "string" }, agent_id: { type: "string" }, session_id: { type: "string" },
|
|
620
|
+
since: { type: "string", description: "ISO inclusive run-start lower bound." }, until: { type: "string", description: "ISO exclusive run-start upper bound." },
|
|
621
|
+
provider: { type: "string" }, model: { type: "string" }, limit: { type: "integer", minimum: 1, maximum: 100 },
|
|
622
|
+
}, additionalProperties: false }, output_schema: { type: "object" } });
|
|
623
|
+
|
|
592
624
|
const PHASE0_TOOL_SCHEMAS = Object.freeze({
|
|
625
|
+
read_agent_metrics: READ_AGENT_METRICS_SCHEMA,
|
|
626
|
+
read_agent_trace: READ_AGENT_TRACE_SCHEMA,
|
|
593
627
|
read_bus_summary: READ_BUS_SUMMARY_SCHEMA,
|
|
594
628
|
read_prompt_history: READ_PROMPT_HISTORY_SCHEMA,
|
|
595
629
|
read_open_decisions: READ_OPEN_DECISIONS_SCHEMA,
|
|
@@ -611,6 +645,9 @@ const PHASE0_TOOL_SCHEMAS = Object.freeze({
|
|
|
611
645
|
});
|
|
612
646
|
|
|
613
647
|
module.exports = {
|
|
648
|
+
READ_AGENT_METRICS_SCHEMA,
|
|
649
|
+
READ_AGENT_TRACE_SCHEMA,
|
|
650
|
+
...require("./controllerSchemas"),
|
|
614
651
|
SCHEMA_VERSION,
|
|
615
652
|
READ_BUS_SUMMARY_SCHEMA,
|
|
616
653
|
READ_PROMPT_HISTORY_SCHEMA,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
4
|
+
const { READ_AGENT_METRICS_SCHEMA } = require("../schemaFixtures");
|
|
5
|
+
const { readAgentPerformance } = require("../../coordination/history/agentTrace");
|
|
6
|
+
|
|
7
|
+
module.exports = createToolDefinition({ name: READ_AGENT_METRICS_SCHEMA.name, description: READ_AGENT_METRICS_SCHEMA.description,
|
|
8
|
+
inputSchema: READ_AGENT_METRICS_SCHEMA.input_schema, outputSchema: READ_AGENT_METRICS_SCHEMA.output_schema,
|
|
9
|
+
schemaVersion: READ_AGENT_METRICS_SCHEMA.schema_version, tier: TOOL_TIERS.TIER_0,
|
|
10
|
+
allowedCallerTiers: [CALLER_TIERS.CONTROLLER, CALLER_TIERS.WORKER],
|
|
11
|
+
handler: (ctx, args) => {
|
|
12
|
+
try { return readAgentPerformance(ctx.projectRoot, args); }
|
|
13
|
+
catch (error) { return { ok: false, code: "invalid_arguments", error: error.message }; }
|
|
14
|
+
} });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
3
|
+
const { READ_AGENT_TRACE_SCHEMA } = require("../schemaFixtures");
|
|
4
|
+
const { readAgentTrace } = require("../../coordination/history/agentTrace");
|
|
5
|
+
module.exports = createToolDefinition({ name: READ_AGENT_TRACE_SCHEMA.name, description: READ_AGENT_TRACE_SCHEMA.description,
|
|
6
|
+
inputSchema: READ_AGENT_TRACE_SCHEMA.input_schema, outputSchema: READ_AGENT_TRACE_SCHEMA.output_schema,
|
|
7
|
+
schemaVersion: READ_AGENT_TRACE_SCHEMA.schema_version, tier: TOOL_TIERS.TIER_0,
|
|
8
|
+
allowedCallerTiers: [CALLER_TIERS.CONTROLLER, CALLER_TIERS.WORKER],
|
|
9
|
+
handler: (ctx, args) => {
|
|
10
|
+
if (args.since && !Number.isFinite(Date.parse(args.since))) return { ok: false, code: "invalid_arguments", error: "since must be an ISO timestamp" };
|
|
11
|
+
return readAgentTrace(ctx.projectRoot, args);
|
|
12
|
+
} });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { ROUTE_AGENT_SCHEMA } = require("../schemaFixtures");
|
|
2
2
|
const { CALLER_TIERS, TOOL_TIERS, createToolDefinition } = require("../types");
|
|
3
|
-
const {
|
|
3
|
+
const { routeAgentHandler } = require("../handlers/routeAgent");
|
|
4
4
|
|
|
5
5
|
module.exports = createToolDefinition({
|
|
6
6
|
name: ROUTE_AGENT_SCHEMA.name,
|
|
@@ -10,5 +10,5 @@ module.exports = createToolDefinition({
|
|
|
10
10
|
inputSchema: ROUTE_AGENT_SCHEMA.input_schema,
|
|
11
11
|
outputSchema: ROUTE_AGENT_SCHEMA.output_schema,
|
|
12
12
|
schemaVersion: ROUTE_AGENT_SCHEMA.schema_version,
|
|
13
|
-
handler:
|
|
13
|
+
handler: routeAgentHandler,
|
|
14
14
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { CONTROLLER_TOOL_SCHEMAS } = require("../controllerSchemas");
|
|
4
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
5
|
+
const { assertControllerTier, buildToolError } = require("../handlers/common");
|
|
6
|
+
|
|
7
|
+
const ports = {
|
|
8
|
+
delegate_task: "agentManagement", read_task_reports: "agentManagement", accept_task: "agentManagement",
|
|
9
|
+
manage_tasks: "taskScheduler", resume_agents: "agentLifecycle", manage_group: "groups",
|
|
10
|
+
};
|
|
11
|
+
async function execute(name, ctx, args) {
|
|
12
|
+
assertControllerTier(ctx, name);
|
|
13
|
+
const port = ctx[ports[name]];
|
|
14
|
+
if (!port) throw buildToolError("tool_unavailable", `${name} requires a project host port`);
|
|
15
|
+
if (name === "delegate_task") return port.delegate(args, ctx);
|
|
16
|
+
if (name === "read_task_reports") {
|
|
17
|
+
const tasks = Object.values(port.snapshot().tasks);
|
|
18
|
+
return { ok: true, tasks: (args.task_id ? tasks.filter((task) => task.taskId === args.task_id) : tasks).slice(-100) };
|
|
19
|
+
}
|
|
20
|
+
if (name === "accept_task") return port.accept(args, ctx);
|
|
21
|
+
if (name === "manage_tasks") return port.execute(args, ctx);
|
|
22
|
+
const commandId = ctx.requestId ? `coord-${require("crypto").createHash("sha256").update(`${ctx.requestId}:${args.command_id}`).digest("hex").slice(0, 32)}` : args.command_id;
|
|
23
|
+
if (name === "resume_agents") {
|
|
24
|
+
if (args.operation === "inspect") return port.inspect(args.target || "");
|
|
25
|
+
return ctx.agentManagement.commands.execute({ commandId, kind: name, args }, () => port.resume(args.target || ""));
|
|
26
|
+
}
|
|
27
|
+
if (args.operation === "validate") return port.validateTemplateTarget(args.target || "");
|
|
28
|
+
if (args.operation === "status") return port.getStatus({ group_id: args.group_id || "" });
|
|
29
|
+
return ctx.agentManagement.commands.execute({ commandId, kind: name, args }, () => args.operation === "start"
|
|
30
|
+
? port.runGroup({ alias: args.target, ...(ctx.internalAgentsOnly ? { internal_only: true } : {}), instance: args.group_id || `group-${require("crypto").createHash("sha256").update(commandId).digest("hex").slice(0, 16)}` }) : port.stopGroup({ group_id: args.group_id }));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = Object.values(CONTROLLER_TOOL_SCHEMAS).map((schema) => createToolDefinition({
|
|
34
|
+
name: schema.name, description: schema.description, inputSchema: schema.input_schema, outputSchema: schema.output_schema,
|
|
35
|
+
schemaVersion: schema.schema_version, tier: TOOL_TIERS.TIER_2, allowedCallerTiers: [CALLER_TIERS.CONTROLLER],
|
|
36
|
+
requiredPorts: [ports[schema.name], ...(["resume_agents", "manage_group"].includes(schema.name) ? ["agentManagement"] : [])],
|
|
37
|
+
handler: (ctx, args) => execute(schema.name, ctx, args),
|
|
38
|
+
}));
|
package/src/tools/types.js
CHANGED
|
@@ -24,6 +24,7 @@ function createToolDefinition({
|
|
|
24
24
|
outputSchema,
|
|
25
25
|
handler,
|
|
26
26
|
schemaVersion,
|
|
27
|
+
requiredPorts = [],
|
|
27
28
|
}) {
|
|
28
29
|
const allowed = Object.freeze([...(allowedCallerTiers || [])]);
|
|
29
30
|
return Object.freeze({
|
|
@@ -36,6 +37,7 @@ function createToolDefinition({
|
|
|
36
37
|
input_schema: Object.freeze(inputSchema),
|
|
37
38
|
output_schema: outputSchema ? Object.freeze(outputSchema) : null,
|
|
38
39
|
handler,
|
|
40
|
+
requiredPorts: Object.freeze(requiredPorts.slice()),
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Shared presentation adapters: standalone ucode and embedded SDK/native agents.
|
|
4
|
+
const fmt = require("./format");
|
|
5
|
+
const { buildContextMeter } = require("../agents/runtime/context/contextWindow");
|
|
6
|
+
|
|
7
|
+
function toolStatus(name = "tool") {
|
|
8
|
+
const aliases = { Read: "read", Write: "write", Edit: "edit", Bash: "bash", TodoWrite: "plan_graph", plan: "plan_graph" };
|
|
9
|
+
const key = aliases[name] || String(name).toLowerCase();
|
|
10
|
+
return `${fmt.TOOL_LABELS[key] || `Calling ${name}`}…`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function statusForAgentPhase(event = {}) {
|
|
14
|
+
switch (event.type) {
|
|
15
|
+
case "request_start": case "requesting": return "Waiting for model…";
|
|
16
|
+
case "thinking": return "Thinking…";
|
|
17
|
+
case "text_delta": return "Generating response…";
|
|
18
|
+
case "tool_request": return toolStatus(event.name || "tool");
|
|
19
|
+
case "compacting": return "Compacting context…";
|
|
20
|
+
case "retry": return `Retrying request${event.attempt ? ` (${event.attempt}/${event.max_retries || "?"})` : ""}…`;
|
|
21
|
+
case "authenticating": return "Authenticating…";
|
|
22
|
+
case "cancelling": return "cancelling…";
|
|
23
|
+
case "applying_reply": return "applying reply…";
|
|
24
|
+
default: return "";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function contextMeterForUsage(usage = {}, model = "", provider = "") {
|
|
29
|
+
if (usage.contextMeter?.label) return usage.contextMeter;
|
|
30
|
+
return buildContextMeter({ model, usage: {
|
|
31
|
+
input: usage.input_tokens ?? usage.prompt_tokens ?? usage.input ?? 0,
|
|
32
|
+
cacheRead: usage.cache_read_tokens ?? usage.cache_read_input_tokens ?? usage.cached_input_tokens ?? usage.cacheRead ?? 0,
|
|
33
|
+
cacheCreation: usage.cache_creation_tokens ?? usage.cache_creation_input_tokens ?? usage.cacheCreation ?? 0,
|
|
34
|
+
inputIncludesCache: provider === "claude-cli" || provider === "anthropic" ? false : true,
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function planLinesFromItems(items = []) {
|
|
39
|
+
return (Array.isArray(items) ? items : []).filter(Boolean).map((item) => {
|
|
40
|
+
const status = String(item.status || "");
|
|
41
|
+
const mark = item.completed || ["completed", "succeeded"].includes(status) ? "✓"
|
|
42
|
+
: ["in_progress", "running"].includes(status) ? "→"
|
|
43
|
+
: ["failed", "blocked"].includes(status) ? "✗" : "○";
|
|
44
|
+
return `${mark} ${item.text || item.content || item.title || item.step || ""}`;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function buildPlanSetPayload(executionState, options = {}) {
|
|
49
|
+
try {
|
|
50
|
+
const { buildPlanUiProjection } = require("../code/context/planProjection");
|
|
51
|
+
const projection = buildPlanUiProjection(executionState, {
|
|
52
|
+
cols: Number(options.cols) > 0 ? Number(options.cols) : 80,
|
|
53
|
+
activityMessage: String(options.activityMessage || ""),
|
|
54
|
+
});
|
|
55
|
+
if (!projection || !projection.visible) {
|
|
56
|
+
return {
|
|
57
|
+
summary: "",
|
|
58
|
+
lines: [],
|
|
59
|
+
hash: projection && projection.hash || "",
|
|
60
|
+
visible: false,
|
|
61
|
+
idle_hint: String((projection && projection.idleHint) || ""),
|
|
62
|
+
status_line: "",
|
|
63
|
+
band_mode: String((projection && projection.bandMode) || ""),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
let lines = Array.isArray(projection.bandLines) ? projection.bandLines.slice() : [];
|
|
67
|
+
const md = String(projection.roadmapMarkdown || "").trim();
|
|
68
|
+
if (md) {
|
|
69
|
+
try {
|
|
70
|
+
const rendered = fmt.renderLogLinesWithMarkdownAnsi(md, { inCodeBlock: false });
|
|
71
|
+
if (Array.isArray(rendered) && rendered.length > 0) {
|
|
72
|
+
lines = rendered.map((line) => String(line || ""));
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// keep bandLines
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const summary = String(
|
|
79
|
+
projection.statusLine
|
|
80
|
+
|| projection.activityStatusLine
|
|
81
|
+
|| lines[0]
|
|
82
|
+
|| ""
|
|
83
|
+
).trim();
|
|
84
|
+
return {
|
|
85
|
+
summary,
|
|
86
|
+
text: summary,
|
|
87
|
+
lines,
|
|
88
|
+
hash: projection.hash || "",
|
|
89
|
+
visible: true,
|
|
90
|
+
idle_hint: String(projection.idleHint || ""),
|
|
91
|
+
status_line: String(projection.statusLine || projection.activityStatusLine || ""),
|
|
92
|
+
activity_status_line: String(projection.activityStatusLine || ""),
|
|
93
|
+
band_mode: String(projection.bandMode || ""),
|
|
94
|
+
};
|
|
95
|
+
} catch {
|
|
96
|
+
return {
|
|
97
|
+
summary: "",
|
|
98
|
+
lines: [],
|
|
99
|
+
hash: "",
|
|
100
|
+
visible: false,
|
|
101
|
+
idle_hint: "",
|
|
102
|
+
status_line: "",
|
|
103
|
+
band_mode: "",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
module.exports = { toolStatus, statusForAgentPhase, contextMeterForUsage, planLinesFromItems, buildPlanSetPayload };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { loadConfig } = require("../config");
|
|
4
|
+
const { listAgentModels, confirmAgentModel } = require("../agents/providers/modelSettings");
|
|
5
|
+
const { suggestThinkingLevels, normalizeThinkingLevel } = require("../agents/providers/thinkingLevels");
|
|
6
|
+
|
|
7
|
+
const MODEL_COMMAND = "/settings agent model";
|
|
8
|
+
const THINKING_COMMAND = "/settings agent thinking";
|
|
9
|
+
|
|
10
|
+
function createAgentSettingsController({ getProjectRoot, applyPatch, publish, focusMain = () => {}, logMessage = () => {},
|
|
11
|
+
listModels = listAgentModels, confirmModel = confirmAgentModel } = {}) {
|
|
12
|
+
let draft = null;
|
|
13
|
+
function ask(stage) {
|
|
14
|
+
draft.stage = stage;
|
|
15
|
+
const config = loadConfig(draft.root);
|
|
16
|
+
const prompts = {
|
|
17
|
+
url: `Custom API URL${config.agentBaseUrl ? ` (Enter keeps ${config.agentBaseUrl})` : ""}`,
|
|
18
|
+
key: "Custom API key (hidden; Enter keeps the saved key, '-' clears it)",
|
|
19
|
+
model: "Model ID for the current provider",
|
|
20
|
+
};
|
|
21
|
+
publish("interaction.request", { id: `settings-${stage}`, kind: "settings", prompt: prompts[stage],
|
|
22
|
+
secret: stage === "key", lines: [prompts[stage], "Enter save · Esc cancel"] });
|
|
23
|
+
}
|
|
24
|
+
function open(section) {
|
|
25
|
+
focusMain();
|
|
26
|
+
if (section === "custom" || section === "manual") {
|
|
27
|
+
draft = { root: getProjectRoot(), values: {} };
|
|
28
|
+
ask(section === "custom" ? "url" : "model");
|
|
29
|
+
} else {
|
|
30
|
+
publish("prompt.set_text", { text: `${section === "thinking" ? THINKING_COMMAND : MODEL_COMMAND} `, preserve_draft: true });
|
|
31
|
+
}
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
async function applyModel(model, thinking = "") {
|
|
35
|
+
if (!model) return { ok: false, error: "Model ID is required" };
|
|
36
|
+
if (model === "<manual>") return open("manual");
|
|
37
|
+
if (thinking && !normalizeThinkingLevel(thinking)) return { ok: false, error: "Unknown thinking level" };
|
|
38
|
+
let confirmation;
|
|
39
|
+
try { confirmation = await confirmModel(getProjectRoot(), model); }
|
|
40
|
+
catch (error) { return { ok: false, error: error.message }; }
|
|
41
|
+
if (!confirmation.allowed) return { ok: false, error: confirmation.error };
|
|
42
|
+
const result = await applyPatch({ agent_model: model, ...(thinking ? { agent_thinking: thinking } : {}) });
|
|
43
|
+
if (result.ok) {
|
|
44
|
+
if (confirmation.warning) logMessage("system", "Model catalog unavailable; saved the supplied model ID.");
|
|
45
|
+
publish("prompt.restore", {});
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async function respond(payload) {
|
|
50
|
+
if (!draft) return null;
|
|
51
|
+
if (draft.root !== getProjectRoot() || payload.cancelled) {
|
|
52
|
+
draft = null;
|
|
53
|
+
publish("interaction.clear", {});
|
|
54
|
+
return { ok: true, cancelled: true };
|
|
55
|
+
}
|
|
56
|
+
if (payload.id !== `settings-${draft.stage}`) return { ok: false, error: "Stale settings input" };
|
|
57
|
+
const text = String(payload.text || "").trim();
|
|
58
|
+
if (draft.stage === "url") {
|
|
59
|
+
const urlText = text || loadConfig(draft.root).agentBaseUrl;
|
|
60
|
+
try {
|
|
61
|
+
const url = new URL(urlText);
|
|
62
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error();
|
|
63
|
+
} catch {
|
|
64
|
+
logMessage("error", "Enter an http(s) API URL without embedded credentials.");
|
|
65
|
+
ask("url");
|
|
66
|
+
return { ok: false, error: "Invalid API URL" };
|
|
67
|
+
}
|
|
68
|
+
draft.values.agent_base_url = urlText;
|
|
69
|
+
ask("key");
|
|
70
|
+
return { ok: true };
|
|
71
|
+
}
|
|
72
|
+
if (draft.stage === "key") {
|
|
73
|
+
const patch = { ...draft.values, agent_provider: "custom" };
|
|
74
|
+
if (text) patch.agent_api_key = text === "-" ? "" : text;
|
|
75
|
+
const result = await applyPatch(patch);
|
|
76
|
+
if (!result.ok) { ask("key"); return result; }
|
|
77
|
+
draft = null;
|
|
78
|
+
publish("interaction.clear", {});
|
|
79
|
+
return open("model");
|
|
80
|
+
}
|
|
81
|
+
const result = await applyModel(text);
|
|
82
|
+
if (!result.ok) { logMessage("error", result.error); ask("model"); return result; }
|
|
83
|
+
draft = null;
|
|
84
|
+
publish("interaction.clear", {});
|
|
85
|
+
return open("thinking");
|
|
86
|
+
}
|
|
87
|
+
async function completions(text) {
|
|
88
|
+
const root = getProjectRoot();
|
|
89
|
+
const config = loadConfig(root);
|
|
90
|
+
const thinking = suggestThinkingLevels({ current: config.agentThinking });
|
|
91
|
+
const lists = { [THINKING_COMMAND]: thinking, [`${MODEL_COMMAND}/thinking`]: thinking };
|
|
92
|
+
if (text.trimStart().startsWith(`${MODEL_COMMAND} `)) {
|
|
93
|
+
const listed = await listModels(root).catch((error) => ({ ok: false, error: error.message }));
|
|
94
|
+
const ids = listed.ok ? listed.models.slice() : [];
|
|
95
|
+
if (config.agentModel && (!listed.ok || listed.allowUnlistedModels) && !ids.includes(config.agentModel)) {
|
|
96
|
+
ids.unshift(config.agentModel);
|
|
97
|
+
}
|
|
98
|
+
lists[MODEL_COMMAND] = ids.map((id) => ({ id, hasChildren: true, desc: id === config.agentModel ? "current · choose thinking" : "choose thinking" }));
|
|
99
|
+
lists[MODEL_COMMAND].push({ id: "<manual>", label: "Enter model ID", hasChildren: false,
|
|
100
|
+
desc: listed.ok ? "Configure a model by ID" : "Catalog unavailable · enter model ID" });
|
|
101
|
+
}
|
|
102
|
+
return lists;
|
|
103
|
+
}
|
|
104
|
+
return { open, respond, completions, applyModel };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = { createAgentSettingsController, MODEL_COMMAND, THINKING_COMMAND };
|