u-foo 3.1.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -13
- package/README.zh-CN.md +108 -13
- package/SKILLS/ufoo/SKILL.md +15 -3
- package/SKILLS/ufoo-bus/SKILL.md +21 -1
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +3 -1
- 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 +10 -3
- 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/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +113 -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 +6 -4
- package/src/agents/controller/loopRuntime.js +85 -221
- package/src/agents/controller/ufooAgent.js +1 -0
- package/src/agents/internal/internalRunner.js +103 -32
- package/src/agents/launch/launcher.js +88 -6
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +13 -18
- package/src/agents/launch/readyDetector.js +26 -12
- 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/groupBootstrap.js +10 -0
- package/src/agents/prompts/mainAgent.js +39 -0
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +3 -0
- package/src/agents/providers/claudeEventTranslator.js +6 -1
- package/src/agents/providers/claudeThreadProvider.js +44 -2
- package/src/agents/providers/codexEventTranslator.js +47 -7
- package/src/agents/providers/codexThreadProvider.js +3 -2
- package/src/agents/providers/controllerJsonTransport.js +28 -0
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/nativeTransport.js +1135 -0
- package/src/agents/providers/runtimeConfig.js +186 -0
- package/src/agents/providers/thinkingLevels.js +132 -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 +499 -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/upstreamTransport.js +13 -4
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/runtimeStore.js +126 -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 +270 -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 +247 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -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 +14 -3
- package/src/app/chat/agentDirectory.js +8 -2
- package/src/app/chat/commandExecutor.js +36 -46
- package/src/app/chat/commands.js +14 -7
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -3
- package/src/app/chat/inputSubmitHandler.js +14 -2
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +85 -165
- package/src/app/chat/streamState.js +3 -3
- 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/skills.js +16 -4
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +40 -39
- package/src/code/agent.js +16 -4
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +2 -1
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +100 -0
- package/src/code/nativeRunner.js +36 -2668
- 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/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/sessionStore.js +24 -96
- package/src/code/thinkingLevels.js +1 -130
- 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 +81 -67
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +2 -6
- package/src/coordination/bus/inject.js +13 -5
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/utils.js +7 -3
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/controllerSummary.js +23 -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/runtime/contracts/agentMode.js +17 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +4 -0
- package/src/runtime/daemon/agentHost.js +375 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +27 -17
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/executionPaths.js +30 -0
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +1 -0
- package/src/runtime/daemon/index.js +114 -344
- 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 +7 -4
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/ops.js +22 -17
- package/src/runtime/daemon/promptRequest.js +23 -4
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +4 -0
- 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 +24 -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/index.js +1 -0
- package/src/tools/registry.js +2 -0
- package/src/tools/schemaFixtures.js +16 -3
- 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/agentSurface.js +270 -0
- package/src/ui/format/banner.js +8 -11
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +170 -438
- package/src/ui/rustMultiSession.js +225 -51
- package/src/ui/rustUcodeHost.js +20 -87
- package/src/ui/settingsBridge.js +7 -4
- package/src/app/chat/agentEnter.js +0 -70
- 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/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { listToolsForCallerTier } = require("../../../tools/registry");
|
|
4
|
+
const { CALLER_TIERS } = require("../../../tools/types");
|
|
5
|
+
const { executeControllerTool } = require("../../controller/controllerToolExecutor");
|
|
6
|
+
|
|
7
|
+
const TOOL_PERMISSIONS = Object.freeze({
|
|
8
|
+
launch_agent: "agents.manage", rename_agent: "agents.manage", close_agent: "agents.manage",
|
|
9
|
+
manage_cron: "schedules.manage", dispatch_message: "coordination.write", ack_bus: "coordination.write",
|
|
10
|
+
delegate_task: "agents.manage", resume_agents: "agents.manage", accept_task: "tasks.accept",
|
|
11
|
+
manage_tasks: "tasks.execute", manage_group: "groups.manage",
|
|
12
|
+
remember: "memory.write", edit_memory: "memory.write", forget: "memory.write",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** Shared definitions retain the same schemas and tier checks used by MCP. */
|
|
16
|
+
function createCoordinationCapability({ host, id = "coordination", toolNames = null, policy = null } = {}) {
|
|
17
|
+
const definitions = listToolsForCallerTier(CALLER_TIERS.CONTROLLER)
|
|
18
|
+
.filter((tool) => (!toolNames || toolNames.includes(tool.name)) && (tool.requiredPorts || []).every((port) => host.coordination[port]));
|
|
19
|
+
const requestedPermissions = [...new Set(definitions.map((tool) => TOOL_PERMISSIONS[tool.name] || "coordination.read"))];
|
|
20
|
+
return {
|
|
21
|
+
id, version: 1, requires: { ports: ["coordination"] }, requestedPermissions, policy,
|
|
22
|
+
tools: definitions.map((tool) => ({
|
|
23
|
+
name: tool.name, description: tool.description, inputSchema: tool.input_schema,
|
|
24
|
+
permissions: [TOOL_PERMISSIONS[tool.name] || "coordination.read"],
|
|
25
|
+
async handler(args, context) {
|
|
26
|
+
const ports = host.coordination;
|
|
27
|
+
const invoke = ports.execute || executeControllerTool;
|
|
28
|
+
return invoke({ ...ports, projectRoot: context.workspaceRoot || ports.projectRoot,
|
|
29
|
+
subscriber: "ufoo-agent", turnId: context.turnId, taskId: context.taskId,
|
|
30
|
+
requestId: context.requestId, taskRunId: context.taskRunId, sessionId: context.sessionId },
|
|
31
|
+
{ name: tool.name, arguments: args, id: context.toolCallId });
|
|
32
|
+
},
|
|
33
|
+
})),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { createCoordinationCapability, TOOL_PERMISSIONS };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = { createGlobalRoutingCapability: () => ({ id: "global-routing", version: "1", requires: { ports: ["projectRouting"] }, tools: [],
|
|
3
|
+
promptSections: ["You are the global ufoo project router. Select only a registered project. Return a final JSON object with reply and optional project_route={project_root,project_name,prompt,reason}. The project host executes the handoff. You have no coding, agent launch, or project mutation tools."],
|
|
4
|
+
contextSources: [(_input, host) => host.projectRouting.list()],
|
|
5
|
+
}) };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createCodingCapability } = require("./coding");
|
|
4
|
+
const { createMainPlanningCapability } = require("./planning/main");
|
|
5
|
+
const { createSkillsCapability } = require("./skills");
|
|
6
|
+
const { createAgentManagementCapability } = require("./agentManagement");
|
|
7
|
+
const { createAgentRoutingCapability } = require("./agentRouting");
|
|
8
|
+
const { createProjectDiscoveryCapability } = require("./projectDiscovery");
|
|
9
|
+
const { createSharedMemoryCapability } = require("./sharedMemory");
|
|
10
|
+
const { createTaskReportsCapability } = require("./taskReports");
|
|
11
|
+
const { createTaskExecutionCapability } = require("./taskExecution");
|
|
12
|
+
const { createGroupsCapability } = require("./groups");
|
|
13
|
+
const { createSchedulingCapability } = require("./scheduling");
|
|
14
|
+
const { createGlobalRoutingCapability } = require("./globalRouting");
|
|
15
|
+
|
|
16
|
+
function createMainCapabilities(host) {
|
|
17
|
+
return [createCodingCapability({ workspaceAccess: host.workspaceAccess }), createMainPlanningCapability(), createSkillsCapability(),
|
|
18
|
+
createAgentManagementCapability(host), createAgentRoutingCapability(host), createProjectDiscoveryCapability(host),
|
|
19
|
+
createSharedMemoryCapability(host), createTaskReportsCapability(host), createTaskExecutionCapability(host), createGroupsCapability(host), createSchedulingCapability(host)];
|
|
20
|
+
}
|
|
21
|
+
function createGlobalCapabilities(host) {
|
|
22
|
+
return [createProjectDiscoveryCapability(host), createGlobalRoutingCapability()];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { createMainCapabilities, createGlobalCapabilities };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { buildCoreToolSpecs } = require("../../../code/tools/specs");
|
|
4
|
+
const { runCoreToolAsync } = require("../../../code/tools/executor");
|
|
5
|
+
const { emptyExecutionState } = require("../../../code/context/executionSegment");
|
|
6
|
+
const { parseStructuredSideEffects } = require("../../../code/context/stateCommit");
|
|
7
|
+
const { normalizePlanGraphCommand, activePlanRequiresExpansion } = require("../../../code/context/planGraphService");
|
|
8
|
+
const { planModeBlocksDirectTool } = require("../../../code/context/planMode");
|
|
9
|
+
const { drainUserPrompts, formatUserReminderMessage, ensurePendingUserPrompts, shouldAutoContinuePlan, buildPlanAutoContinueReminder } = require("../../../code/context/userNudge");
|
|
10
|
+
const { drainAgentMailboxForTurn, shouldAutoContinueForTaskWake, listTaskRunsAwaitingModel } = require("../../../code/runtime/agentWakeup");
|
|
11
|
+
const { shouldIsolateTaskFocusTurn, buildIsolatedTaskFocusTurn, sanitizeToolResultForModel } = require("../../../code/runtime/taskFocusContext");
|
|
12
|
+
const { hasPendingUserInteraction, getPendingUserInteraction } = require("../../../code/context/userInteraction");
|
|
13
|
+
const { checkWriteAllowed } = require("../../../code/runtime/workspaceLease");
|
|
14
|
+
|
|
15
|
+
const DATA_TOOLS = new Set(["read", "read_image", "write", "edit", "bash", "artifact_read"]);
|
|
16
|
+
const CONTROL_TOOLS = new Set(["plan_graph", "task_run"]);
|
|
17
|
+
|
|
18
|
+
function createPlanningPolicy() {
|
|
19
|
+
function userReminder(state, guard) {
|
|
20
|
+
const nudges = drainUserPrompts(state);
|
|
21
|
+
if (!nudges.length) return "";
|
|
22
|
+
guard.reset();
|
|
23
|
+
return formatUserReminderMessage(nudges, { waitingFor: state.planGraph && state.planGraph.waitingFor || null }) || "";
|
|
24
|
+
}
|
|
25
|
+
function mailbox(state, messages, guard) {
|
|
26
|
+
const drained = drainAgentMailboxForTurn(state);
|
|
27
|
+
if (!drained.text) return false;
|
|
28
|
+
guard.reset();
|
|
29
|
+
messages.push({ role: "user", content: drained.text });
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
function continuationKey(state) {
|
|
33
|
+
const waitingId = String(state.planGraph && state.planGraph.waitingFor && state.planGraph.waitingFor.id || "");
|
|
34
|
+
if (waitingId) return `plan:${waitingId}`;
|
|
35
|
+
const runs = listTaskRunsAwaitingModel(state);
|
|
36
|
+
return runs.length ? `task:${runs.map((run) => run.id).sort().join(",")}` : "mailbox";
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
initializeState(state) {
|
|
40
|
+
const next = state && typeof state === "object" ? state : emptyExecutionState();
|
|
41
|
+
if (typeof next.planMode !== "boolean") next.planMode = false;
|
|
42
|
+
ensurePendingUserPrompts(next);
|
|
43
|
+
return next;
|
|
44
|
+
},
|
|
45
|
+
prepareTurn({ executionState: state, messages, loopGuard }) {
|
|
46
|
+
if (shouldIsolateTaskFocusTurn(state)) {
|
|
47
|
+
const drained = drainAgentMailboxForTurn(state);
|
|
48
|
+
const nudge = userReminder(state, loopGuard);
|
|
49
|
+
if (drained.events && drained.events.length) loopGuard.reset();
|
|
50
|
+
return buildIsolatedTaskFocusTurn(state, { mailboxEvents: drained.events || [], userNudge: nudge }).messages;
|
|
51
|
+
}
|
|
52
|
+
const nudge = userReminder(state, loopGuard);
|
|
53
|
+
if (nudge) messages.push({ role: "user", content: nudge });
|
|
54
|
+
mailbox(state, messages, loopGuard);
|
|
55
|
+
return messages;
|
|
56
|
+
},
|
|
57
|
+
continuationKey: ({ executionState }) => continuationKey(executionState),
|
|
58
|
+
continueAfterFinal({ executionState: state, messages, loopGuard }) {
|
|
59
|
+
if (shouldIsolateTaskFocusTurn(state) || shouldAutoContinueForTaskWake(state)) return true;
|
|
60
|
+
if (mailbox(state, messages, loopGuard)) return true;
|
|
61
|
+
if (shouldAutoContinuePlan(state)) {
|
|
62
|
+
const reminder = buildPlanAutoContinueReminder(state);
|
|
63
|
+
if (reminder) {
|
|
64
|
+
messages.push({ role: "user", content: reminder });
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
},
|
|
70
|
+
legacyCommand(text) {
|
|
71
|
+
const sideEffects = parseStructuredSideEffects(text);
|
|
72
|
+
const args = sideEffects ? normalizePlanGraphCommand(sideEffects) : null;
|
|
73
|
+
return args ? {
|
|
74
|
+
tool: "plan_graph", args, resultType: "plan_graph_result",
|
|
75
|
+
origin: { kind: "legacy_side_effect", source: args.source || "legacy" },
|
|
76
|
+
} : null;
|
|
77
|
+
},
|
|
78
|
+
validateBatch(calls) {
|
|
79
|
+
const names = calls.map((call) => String(call.name || "").toLowerCase());
|
|
80
|
+
if (names.some((name) => CONTROL_TOOLS.has(name)) && names.some((name) => DATA_TOOLS.has(name))) {
|
|
81
|
+
return { ok: false, status: "rejected", code: "MIXED_PLAN_AND_DATA_TOOLS", error: "Do not mix plan_graph/task_run with data-plane tools in the same turn" };
|
|
82
|
+
}
|
|
83
|
+
if (names.includes("ask_user") && calls.length > 1) {
|
|
84
|
+
return { ok: false, status: "rejected", code: "ASK_USER_MUST_BE_ALONE", error: "ask_user must be the only tool call in the turn" };
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
},
|
|
88
|
+
validateTool(name, state) {
|
|
89
|
+
if (DATA_TOOLS.has(name) && activePlanRequiresExpansion(state.planGraph)) {
|
|
90
|
+
return { ok: false, status: "rejected", errors: [{ code: "ACTIVE_PLAN_REQUIRES_EXPANSION", message: "Active plan is waiting on a task; use plan_graph expand_node or control.complete_task instead of direct tools" }] };
|
|
91
|
+
}
|
|
92
|
+
if (planModeBlocksDirectTool(name, state)) {
|
|
93
|
+
return { ok: false, status: "rejected", errors: [{ code: "PLAN_MODE_BLOCKS_SIDE_EFFECT", message: "Plan mode is on; use plan_graph for write/edit/bash, or ask the user to /plan off" }] };
|
|
94
|
+
}
|
|
95
|
+
const lease = checkWriteAllowed(state, { tool: name, originKind: "agent_loop" });
|
|
96
|
+
return lease.ok ? null : { ok: false, status: "rejected", errors: [{ code: lease.code || "WORKSPACE_WRITE_LEASE_HELD", message: lease.message || "Workspace write lease held by an active TaskRun", owner: lease.owner || null }] };
|
|
97
|
+
},
|
|
98
|
+
onDeferred({ executionState, resume, provider }) {
|
|
99
|
+
const interaction = getPendingUserInteraction(executionState);
|
|
100
|
+
if (interaction) interaction.resume = {
|
|
101
|
+
...(interaction.resume || {}), ...resume, mode: "ask_user",
|
|
102
|
+
transport: provider === "anthropic" ? "anthropic-messages" : "openai-chat",
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
pendingInteraction: (state) => hasPendingUserInteraction(state) ? getPendingUserInteraction(state) : null,
|
|
106
|
+
sanitizeResult: sanitizeToolResultForModel,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function createPlanningCapability() {
|
|
111
|
+
return {
|
|
112
|
+
id: "planning", version: "1.0", requires: { capabilities: ["coding"] },
|
|
113
|
+
tools: buildCoreToolSpecs().filter((spec) => CONTROL_TOOLS.has(spec.function.name) || spec.function.name === "ask_user").map(({ function: tool }) => ({
|
|
114
|
+
name: tool.name, description: tool.description, inputSchema: tool.parameters,
|
|
115
|
+
permissions: [tool.name === "ask_user" ? "interaction.request" : "execution.control"],
|
|
116
|
+
deferable: tool.name === "ask_user", tight: tool.name === "plan_graph",
|
|
117
|
+
handler: (args, context) => runCoreToolAsync({ ...context, tool: tool.name, args }),
|
|
118
|
+
})),
|
|
119
|
+
policy: createPlanningPolicy(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { createPlanningCapability, createPlanningPolicy };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { buildCoreToolSpecs } = require("../../../code/tools/specs");
|
|
4
|
+
const { runCoreToolAsync } = require("../../../code/tools/executor");
|
|
5
|
+
const { getPendingUserInteraction } = require("../../../code/context/userInteraction");
|
|
6
|
+
|
|
7
|
+
/** Main planning delegates durable execution; it never adopts a child's model focus. */
|
|
8
|
+
function createMainPlanningCapability() {
|
|
9
|
+
const { function: tool } = buildCoreToolSpecs().find((spec) => spec.function.name === "ask_user");
|
|
10
|
+
return { id: "planning", version: "1", requires: { providerFeatures: ["deferred_tools"] }, requestedPermissions: ["interaction.request"],
|
|
11
|
+
promptSections: ["Decompose complex objectives into independently verifiable tasks. Record explicit objectives and acceptance criteria. Keep dependent tasks queued until their inputs have been verified; use manage_tasks and delegate_task for execution."],
|
|
12
|
+
tools: [{ name: tool.name, description: tool.description, inputSchema: tool.parameters,
|
|
13
|
+
permissions: ["interaction.request"], deferable: true,
|
|
14
|
+
handler: (args, context) => runCoreToolAsync({ ...context, tool: tool.name, args }) }],
|
|
15
|
+
policy: {
|
|
16
|
+
validateBatch(calls) { return calls.some((call) => call.name === "ask_user") && calls.length > 1
|
|
17
|
+
? { ok: false, code: "ASK_USER_MUST_BE_ALONE", error: "ask_user must be alone" } : null; },
|
|
18
|
+
pendingInteraction: getPendingUserInteraction,
|
|
19
|
+
onDeferred({ executionState, resume, provider }) {
|
|
20
|
+
const pending = getPendingUserInteraction(executionState);
|
|
21
|
+
if (pending) pending.resume = { ...resume, mode: "ask_user", transport: provider === "anthropic" ? "anthropic-messages" : "openai-chat" };
|
|
22
|
+
},
|
|
23
|
+
sanitizeResult(result) { if (!result || typeof result !== "object") return result; const { executionState, ...rest } = result; return rest; },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { createMainPlanningCapability };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { createCoordinationCapability } = require("../coordination");
|
|
3
|
+
module.exports = { createSharedMemoryCapability: (host) => createCoordinationCapability({ host, id: "shared-memory",
|
|
4
|
+
toolNames: ["remember", "recall", "search_memory", "search_history", "edit_memory", "forget"] }) };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { buildSkillInjections } = require("../../../code/skills");
|
|
4
|
+
|
|
5
|
+
function createSkillsCapability() {
|
|
6
|
+
return {
|
|
7
|
+
id: "skills", version: "1.0", tools: [],
|
|
8
|
+
contextSources: [(input) => buildSkillInjections(input)],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { createSkillsCapability };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { createCoordinationCapability } = require("../coordination");
|
|
3
|
+
module.exports = { createTaskReportsCapability: (host) => ({
|
|
4
|
+
...createCoordinationCapability({ host, id: "task-reports", toolNames: ["read_task_reports", "accept_task"] }),
|
|
5
|
+
requires: { ports: ["coordination"], capabilities: ["agent-management"] },
|
|
6
|
+
}) };
|
|
@@ -63,22 +63,22 @@ async function handleDispatchMessage(ctx, args) {
|
|
|
63
63
|
if (target !== "broadcast" && typeof ctx.markPending === "function") {
|
|
64
64
|
ctx.markPending(target);
|
|
65
65
|
}
|
|
66
|
-
await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
66
|
+
const receipts = await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
67
67
|
target,
|
|
68
68
|
message,
|
|
69
69
|
injection_mode: options.injectionMode || "immediate",
|
|
70
70
|
source: options.source || publisher,
|
|
71
71
|
}]);
|
|
72
|
-
return { seq: 0, targets: [target] };
|
|
72
|
+
return receipts?.[0] || { seq: 0, targets: [target] };
|
|
73
73
|
},
|
|
74
74
|
broadcast: async (message, publisher, options = {}) => {
|
|
75
|
-
await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
75
|
+
const receipts = await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
76
76
|
target: "broadcast",
|
|
77
77
|
message,
|
|
78
78
|
injection_mode: options.injectionMode || "immediate",
|
|
79
79
|
source: options.source || publisher,
|
|
80
80
|
}]);
|
|
81
|
-
return { seq: 0, targets: ["broadcast"] };
|
|
81
|
+
return receipts?.[0] || { seq: 0, targets: ["broadcast"] };
|
|
82
82
|
},
|
|
83
83
|
}
|
|
84
84
|
: new EventBus(ctx.projectRoot);
|
|
@@ -90,6 +90,7 @@ async function handleDispatchMessage(ctx, args) {
|
|
|
90
90
|
}, args);
|
|
91
91
|
|
|
92
92
|
return {
|
|
93
|
+
...result,
|
|
93
94
|
dispatched: 1,
|
|
94
95
|
target: result.target,
|
|
95
96
|
injection_mode: result.mode,
|
|
@@ -156,6 +157,7 @@ async function handleSharedRegistryTool(ctx, name, args, audit = {}) {
|
|
|
156
157
|
}
|
|
157
158
|
const eventBus = ctx.eventBus || new EventBus(ctx.projectRoot);
|
|
158
159
|
return definition.handler({
|
|
160
|
+
...ctx,
|
|
159
161
|
projectRoot: ctx.projectRoot,
|
|
160
162
|
subscriber: ctx.subscriber || "ufoo-agent",
|
|
161
163
|
caller_tier: CALLER_TIERS.CONTROLLER,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { executeControllerTool } = require("./controllerToolExecutor");
|
|
4
|
+
const { createAgentRuntime } = require("../runtime");
|
|
5
|
+
const { createControllerJsonTransport } = require("../providers/controllerJsonTransport");
|
|
6
|
+
const { createCoordinationCapability } = require("../capabilities/coordination");
|
|
4
7
|
const { createLoopObserver } = require("./loopObservability");
|
|
5
8
|
const { finalizeRouterPayload } = require("../../orchestration/controller/routerFinalize");
|
|
6
9
|
|
|
@@ -232,232 +235,93 @@ async function runPromptWithControllerLoop({
|
|
|
232
235
|
return finalPayload;
|
|
233
236
|
};
|
|
234
237
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
238
|
+
let rounds = 0;
|
|
239
|
+
const host = {
|
|
240
|
+
grantedPermissions: ["coordination.read", "coordination.write", "agents.manage", "schedules.manage", "memory.write"],
|
|
241
|
+
coordination: {
|
|
242
|
+
projectRoot, processManager, dispatchMessages, handleOps, ackBus, markPending, observer,
|
|
243
|
+
async execute(ctx, call) {
|
|
244
|
+
const started = now();
|
|
245
|
+
const result = await executeControllerTool({ ...ctx, turnId: `loop-round-${rounds}` }, call);
|
|
246
|
+
let size = 0;
|
|
247
|
+
let memory = 0;
|
|
248
|
+
try {
|
|
249
|
+
size = result.result === undefined ? 0 : JSON.stringify(result.result).length;
|
|
250
|
+
memory = toNonNegativeInt(result.result && result.result.dynamic_memory_tokens);
|
|
251
|
+
} catch { /* diagnostic metadata only */ }
|
|
252
|
+
dynamicMemoryTokens += memory;
|
|
253
|
+
observer.emit("tool_call", {
|
|
254
|
+
round: rounds, tool_name: result.name || call.name,
|
|
255
|
+
tool_call_id: result.tool_call_id || "", turn_id: result.turn_id || `loop-round-${rounds}`,
|
|
256
|
+
duration_ms: Math.max(0, now() - started), result_size: size,
|
|
257
|
+
dynamic_memory_tokens: memory, retry_count: 0, final_status: result.ok ? "ok" : "error",
|
|
258
|
+
});
|
|
259
|
+
return result;
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
const policy = {
|
|
264
|
+
beforeTurn() {
|
|
265
|
+
if (checkCancellation()) return TERMINAL_REASONS.USER_CANCEL;
|
|
266
|
+
if (rounds >= options.maxRounds || currentPrompt.length > options.maxPromptChars) return TERMINAL_REASONS.BUDGET_EXCEEDED;
|
|
267
|
+
return null;
|
|
268
|
+
},
|
|
269
|
+
beforeTool() {
|
|
270
|
+
return toolCalls >= options.maxToolCalls ? TERMINAL_REASONS.BUDGET_EXCEEDED : null;
|
|
271
|
+
},
|
|
272
|
+
afterTool({ call, result }) {
|
|
273
|
+
toolCalls += 1;
|
|
274
|
+
if (!result || !result.ok) toolErrors += 1;
|
|
275
|
+
toolResults.push(result && result.name ? result : {
|
|
276
|
+
...result, name: call.name, tool_call_id: call.source.id, turn_id: `loop-round-${rounds}`,
|
|
247
277
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
projectRoot,
|
|
254
|
-
payload,
|
|
255
|
-
prompt: currentPrompt,
|
|
256
|
-
processManager,
|
|
257
|
-
dispatchMessages,
|
|
258
|
-
handleOps,
|
|
259
|
-
markPending,
|
|
260
|
-
finalizeLocally,
|
|
278
|
+
if (toolErrors >= options.maxToolErrors) return TERMINAL_REASONS.TOOL_FAILURE;
|
|
279
|
+
currentPrompt = buildLoopContinuationPrompt({
|
|
280
|
+
originalPrompt: prompt, toolResults, lastReply: lastPayload.reply,
|
|
281
|
+
loopState: { round: rounds, max_rounds: options.maxRounds, tool_calls_used: toolCalls,
|
|
282
|
+
tool_calls_remaining: Math.max(options.maxToolCalls - toolCalls, 0), tool_errors: toolErrors },
|
|
261
283
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
prompt_chars: currentPrompt.length
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
projectRoot,
|
|
274
|
-
prompt: currentPrompt,
|
|
275
|
-
provider,
|
|
276
|
-
model,
|
|
277
|
-
...ufooAgentOptions,
|
|
278
|
-
loopRuntime: {
|
|
279
|
-
enabled: true,
|
|
280
|
-
round,
|
|
281
|
-
maxRounds: options.maxRounds,
|
|
282
|
-
maxToolCalls: options.maxToolCalls,
|
|
283
|
-
remainingToolCalls: Math.max(options.maxToolCalls - toolCalls, 0),
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
|
|
284
|
+
return null;
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
const transport = createControllerJsonTransport({ async invoke() {
|
|
288
|
+
rounds += 1;
|
|
289
|
+
const started = now();
|
|
290
|
+
observer.emit("model_call_started", { round: rounds, provider: String(provider || ""),
|
|
291
|
+
model: String(model || ""), prompt_chars: currentPrompt.length });
|
|
292
|
+
const result = await runUfooAgent({ projectRoot, prompt: currentPrompt, provider, model,
|
|
293
|
+
...ufooAgentOptions, loopRuntime: { enabled: true, round: rounds, maxRounds: options.maxRounds,
|
|
294
|
+
maxToolCalls: options.maxToolCalls, remainingToolCalls: Math.max(options.maxToolCalls - toolCalls, 0) } });
|
|
287
295
|
const metrics = extractModelMetrics(result);
|
|
288
|
-
const
|
|
296
|
+
const latency = metrics.latency_ms || Math.max(0, now() - started);
|
|
289
297
|
totalTokens += metrics.input_tokens + metrics.output_tokens;
|
|
290
|
-
totalLatencyMs +=
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
&& result.payload
|
|
294
|
-
? result.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
dynamic_memory_tokens: metrics.dynamic_memory_tokens,
|
|
310
|
-
latency_ms: modelLatency,
|
|
311
|
-
first_token_ms: metrics.first_token_ms,
|
|
312
|
-
tool_call_count: toolCall ? 1 : 0,
|
|
313
|
-
stop_reason: metrics.stop_reason,
|
|
314
|
-
error: result && result.ok === false ? String(result.error || "") : "",
|
|
315
|
-
});
|
|
316
|
-
observer.emit("model_call_finished", {
|
|
317
|
-
round,
|
|
318
|
-
ok: result && result.ok === true,
|
|
319
|
-
error: result && result.ok === false ? String(result.error || "") : "",
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
if (!result || result.ok !== true) {
|
|
323
|
-
const payload = terminate(TERMINAL_REASONS.PROVIDER_ERROR, lastPayload, round);
|
|
324
|
-
return {
|
|
325
|
-
ok: false,
|
|
326
|
-
error: result && result.error ? result.error : "ufoo-agent loop failed",
|
|
327
|
-
payload,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const payload = normalizePayload(result.payload);
|
|
332
|
-
lastPayload = payload;
|
|
333
|
-
|
|
334
|
-
if (!toolCall) {
|
|
335
|
-
const finalPayload = {
|
|
336
|
-
...payload,
|
|
337
|
-
loop: {
|
|
338
|
-
terminal_reason: TERMINAL_REASONS.FINAL_ANSWER,
|
|
339
|
-
rounds: round,
|
|
340
|
-
tool_calls: toolCalls,
|
|
341
|
-
tool_errors: toolErrors,
|
|
342
|
-
fallback_used: FALLBACK_USED_VALUES.NONE,
|
|
343
|
-
total_tokens: totalTokens,
|
|
344
|
-
total_latency_ms: totalLatencyMs,
|
|
345
|
-
dynamic_memory_tokens: dynamicMemoryTokens,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
observer.emit("loop_terminal", finalPayload.loop);
|
|
349
|
-
return finalizeLoopRun({
|
|
350
|
-
projectRoot,
|
|
351
|
-
payload: finalPayload,
|
|
352
|
-
prompt: currentPrompt,
|
|
353
|
-
processManager,
|
|
354
|
-
dispatchMessages,
|
|
355
|
-
handleOps,
|
|
356
|
-
markPending,
|
|
357
|
-
finalizeLocally,
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (toolCalls >= options.maxToolCalls) {
|
|
362
|
-
const finalPayload = terminate(TERMINAL_REASONS.BUDGET_EXCEEDED, payload, round);
|
|
363
|
-
return finalizeLoopRun({
|
|
364
|
-
projectRoot,
|
|
365
|
-
payload: finalPayload,
|
|
366
|
-
prompt: currentPrompt,
|
|
367
|
-
processManager,
|
|
368
|
-
dispatchMessages,
|
|
369
|
-
handleOps,
|
|
370
|
-
markPending,
|
|
371
|
-
finalizeLocally,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
toolCalls += 1;
|
|
376
|
-
const toolStartedAt = now();
|
|
377
|
-
const toolResult = await executeControllerTool({
|
|
378
|
-
projectRoot,
|
|
379
|
-
subscriber: "ufoo-agent",
|
|
380
|
-
processManager,
|
|
381
|
-
dispatchMessages,
|
|
382
|
-
handleOps,
|
|
383
|
-
ackBus,
|
|
384
|
-
markPending,
|
|
385
|
-
observer,
|
|
386
|
-
turnId: `loop-round-${round}`,
|
|
387
|
-
}, toolCall);
|
|
388
|
-
const toolDuration = Math.max(0, now() - toolStartedAt);
|
|
389
|
-
|
|
390
|
-
let toolResultSize = 0;
|
|
391
|
-
let toolDynamicMemoryTokens = 0;
|
|
392
|
-
try {
|
|
393
|
-
toolResultSize = toolResult && toolResult.result !== undefined
|
|
394
|
-
? JSON.stringify(toolResult.result).length
|
|
395
|
-
: 0;
|
|
396
|
-
toolDynamicMemoryTokens = toolResult && toolResult.result && Number.isFinite(Number(toolResult.result.dynamic_memory_tokens))
|
|
397
|
-
? Math.max(0, Math.floor(Number(toolResult.result.dynamic_memory_tokens)))
|
|
398
|
-
: 0;
|
|
399
|
-
} catch {
|
|
400
|
-
toolResultSize = 0;
|
|
401
|
-
toolDynamicMemoryTokens = 0;
|
|
402
|
-
}
|
|
403
|
-
dynamicMemoryTokens += toolDynamicMemoryTokens;
|
|
404
|
-
|
|
405
|
-
observer.emit("tool_call", {
|
|
406
|
-
round,
|
|
407
|
-
tool_name: String(toolResult && toolResult.name ? toolResult.name : toolCall.name || ""),
|
|
408
|
-
tool_call_id: String(toolResult && toolResult.tool_call_id ? toolResult.tool_call_id : ""),
|
|
409
|
-
turn_id: toolResult && toolResult.turn_id ? String(toolResult.turn_id) : `loop-round-${round}`,
|
|
410
|
-
duration_ms: toolDuration,
|
|
411
|
-
result_size: toolResultSize,
|
|
412
|
-
dynamic_memory_tokens: toolDynamicMemoryTokens,
|
|
413
|
-
retry_count: 0,
|
|
414
|
-
final_status: toolResult && toolResult.ok === true ? "ok" : "error",
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
if (!toolResult.ok) {
|
|
418
|
-
toolErrors += 1;
|
|
419
|
-
}
|
|
420
|
-
toolResults.push(toolResult);
|
|
421
|
-
|
|
422
|
-
if (toolErrors >= options.maxToolErrors) {
|
|
423
|
-
const finalPayload = terminate(TERMINAL_REASONS.TOOL_FAILURE, payload, round);
|
|
424
|
-
return finalizeLoopRun({
|
|
425
|
-
projectRoot,
|
|
426
|
-
payload: finalPayload,
|
|
427
|
-
prompt: currentPrompt,
|
|
428
|
-
processManager,
|
|
429
|
-
dispatchMessages,
|
|
430
|
-
handleOps,
|
|
431
|
-
markPending,
|
|
432
|
-
finalizeLocally,
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
currentPrompt = buildLoopContinuationPrompt({
|
|
437
|
-
originalPrompt: prompt,
|
|
438
|
-
toolResults,
|
|
439
|
-
lastReply: payload.reply,
|
|
440
|
-
loopState: {
|
|
441
|
-
round,
|
|
442
|
-
max_rounds: options.maxRounds,
|
|
443
|
-
tool_calls_used: toolCalls,
|
|
444
|
-
tool_calls_remaining: Math.max(options.maxToolCalls - toolCalls, 0),
|
|
445
|
-
tool_errors: toolErrors,
|
|
446
|
-
},
|
|
447
|
-
});
|
|
298
|
+
totalLatencyMs += latency;
|
|
299
|
+
observer.emit("model_call", { round: rounds, provider: String(provider || ""), model: String(model || ""),
|
|
300
|
+
...metrics, latency_ms: latency, ok: result && result.ok === true,
|
|
301
|
+
tool_call_count: result && result.payload && result.payload.tool_call ? 1 : 0,
|
|
302
|
+
error: result && result.ok === false ? String(result.error || "") : "" });
|
|
303
|
+
observer.emit("model_call_finished", { round: rounds, ok: result && result.ok === true,
|
|
304
|
+
error: result && result.ok === false ? String(result.error || "") : "" });
|
|
305
|
+
if (result && result.ok) lastPayload = normalizePayload(result.payload);
|
|
306
|
+
return result;
|
|
307
|
+
} });
|
|
308
|
+
const runtime = createAgentRuntime({ profile: { capabilities: ["controller"] }, transport, host,
|
|
309
|
+
capabilities: [createCoordinationCapability({ host, id: "controller", policy })] });
|
|
310
|
+
let run;
|
|
311
|
+
try {
|
|
312
|
+
run = await runtime.run({ workspaceRoot: projectRoot, prompt, model: model || "controller",
|
|
313
|
+
toolBudget: { maxToolErrors: Infinity } });
|
|
314
|
+
} catch (error) {
|
|
315
|
+
const payload = terminate(TERMINAL_REASONS.PROVIDER_ERROR, lastPayload, rounds);
|
|
316
|
+
return { ok: false, error: error.message, payload };
|
|
448
317
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
dispatchMessages,
|
|
457
|
-
handleOps,
|
|
458
|
-
markPending,
|
|
459
|
-
finalizeLocally,
|
|
460
|
-
});
|
|
318
|
+
const payload = run.stopReason
|
|
319
|
+
? terminate(run.stopReason, lastPayload, rounds)
|
|
320
|
+
: { ...lastPayload, loop: { terminal_reason: TERMINAL_REASONS.FINAL_ANSWER, rounds,
|
|
321
|
+
tool_calls: toolCalls, tool_errors: toolErrors, ...totals() } };
|
|
322
|
+
if (!run.stopReason) observer.emit("loop_terminal", payload.loop);
|
|
323
|
+
return finalizeLoopRun({ projectRoot, payload, prompt: currentPrompt, processManager,
|
|
324
|
+
dispatchMessages, handleOps, markPending, finalizeLocally });
|
|
461
325
|
}
|
|
462
326
|
|
|
463
327
|
module.exports = {
|
|
@@ -432,6 +432,7 @@ function renderUntrustedTextContext(label = "", value = "", options = {}) {
|
|
|
432
432
|
|
|
433
433
|
function listControllerLoopToolNames() {
|
|
434
434
|
const names = listToolsForCallerTier(CALLER_TIERS.CONTROLLER)
|
|
435
|
+
.filter((tool) => !(tool.requiredPorts || []).length)
|
|
435
436
|
.map((tool) => String(tool && tool.name ? tool.name : "").trim())
|
|
436
437
|
.filter(Boolean);
|
|
437
438
|
return Array.from(new Set(names)).sort();
|