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
|
@@ -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", "read_agent_trace", "read_agent_metrics", "accept_task"] }),
|
|
5
|
+
requires: { ports: ["coordination"], capabilities: ["agent-management"] },
|
|
6
|
+
}) };
|
|
@@ -4,6 +4,8 @@ const EventBus = require("../../coordination/bus");
|
|
|
4
4
|
const { getToolDefinition, CALLER_TIERS } = require("../../tools");
|
|
5
5
|
const { dispatchMessageHandler } = require("../../tools/handlers/dispatchMessage");
|
|
6
6
|
const { ackBusHandler } = require("../../tools/handlers/ackBus");
|
|
7
|
+
const { isMetaActive } = require("../../coordination/bus/utils");
|
|
8
|
+
const { isInternalAgentMeta, normalizeInternalAgentType } = require("../../runtime/contracts/agentMode");
|
|
7
9
|
|
|
8
10
|
function normalizeObjectArgs(value) {
|
|
9
11
|
if (!value) return {};
|
|
@@ -33,6 +35,17 @@ function buildStructuredError(code, message, extra = {}) {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
function resolveDispatchTargets(ctx, target) {
|
|
38
|
+
if (ctx.internalAgentsOnly) {
|
|
39
|
+
const eventBus = ctx.eventBus || new EventBus(ctx.projectRoot);
|
|
40
|
+
eventBus.loadBusData();
|
|
41
|
+
const agents = eventBus.busData.agents || {};
|
|
42
|
+
const targets = target === "broadcast"
|
|
43
|
+
? Object.keys(agents)
|
|
44
|
+
: eventBus.messageManager.resolveTarget(target);
|
|
45
|
+
const active = targets.filter((id) => id !== "ufoo-agent" && isInternalAgentMeta(agents[id]) && isMetaActive(agents[id]));
|
|
46
|
+
if (active.length) return active;
|
|
47
|
+
throw buildStructuredError("invalid_target", `dispatch_message target not found among active internal agents: ${target}`);
|
|
48
|
+
}
|
|
36
49
|
if (typeof ctx.resolveDispatchTargets === "function") {
|
|
37
50
|
const resolved = ctx.resolveDispatchTargets(target);
|
|
38
51
|
if (Array.isArray(resolved) && resolved.length > 0) return resolved;
|
|
@@ -56,29 +69,31 @@ function resolveDispatchTargets(ctx, target) {
|
|
|
56
69
|
}
|
|
57
70
|
|
|
58
71
|
async function handleDispatchMessage(ctx, args) {
|
|
72
|
+
const dispatch = async (target, message, publisher, options = {}) => {
|
|
73
|
+
const targets = resolveDispatchTargets(ctx, target);
|
|
74
|
+
const receipts = await ctx.dispatchMessages(ctx.projectRoot, (ctx.internalAgentsOnly ? targets : [target]).map((recipient) => ({
|
|
75
|
+
target: recipient,
|
|
76
|
+
message,
|
|
77
|
+
injection_mode: options.injectionMode || "immediate",
|
|
78
|
+
source: options.source || publisher,
|
|
79
|
+
})));
|
|
80
|
+
if (typeof ctx.markPending === "function" && target !== "broadcast") {
|
|
81
|
+
for (const recipient of ctx.internalAgentsOnly ? targets : [target]) ctx.markPending(recipient);
|
|
82
|
+
}
|
|
83
|
+
return { ...(receipts?.[0] || { seq: 0 }), targets: receipts?.length ? receipts.flatMap((receipt) => receipt.targets || []) : targets };
|
|
84
|
+
};
|
|
59
85
|
const eventBus = typeof ctx.dispatchMessages === "function"
|
|
60
86
|
? {
|
|
61
|
-
send:
|
|
62
|
-
resolveDispatchTargets(ctx, target);
|
|
63
|
-
if (target !== "broadcast" && typeof ctx.markPending === "function") {
|
|
64
|
-
ctx.markPending(target);
|
|
65
|
-
}
|
|
66
|
-
await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
67
|
-
target,
|
|
68
|
-
message,
|
|
69
|
-
injection_mode: options.injectionMode || "immediate",
|
|
70
|
-
source: options.source || publisher,
|
|
71
|
-
}]);
|
|
72
|
-
return { seq: 0, targets: [target] };
|
|
73
|
-
},
|
|
87
|
+
send: dispatch,
|
|
74
88
|
broadcast: async (message, publisher, options = {}) => {
|
|
75
|
-
|
|
89
|
+
if (ctx.internalAgentsOnly) return dispatch("broadcast", message, publisher, options);
|
|
90
|
+
const receipts = await ctx.dispatchMessages(ctx.projectRoot, [{
|
|
76
91
|
target: "broadcast",
|
|
77
92
|
message,
|
|
78
93
|
injection_mode: options.injectionMode || "immediate",
|
|
79
94
|
source: options.source || publisher,
|
|
80
95
|
}]);
|
|
81
|
-
return { seq: 0, targets: ["broadcast"] };
|
|
96
|
+
return receipts?.[0] || { seq: 0, targets: ["broadcast"] };
|
|
82
97
|
},
|
|
83
98
|
}
|
|
84
99
|
: new EventBus(ctx.projectRoot);
|
|
@@ -90,6 +105,7 @@ async function handleDispatchMessage(ctx, args) {
|
|
|
90
105
|
}, args);
|
|
91
106
|
|
|
92
107
|
return {
|
|
108
|
+
...result,
|
|
93
109
|
dispatched: 1,
|
|
94
110
|
target: result.target,
|
|
95
111
|
injection_mode: result.mode,
|
|
@@ -124,20 +140,19 @@ async function handleLaunchAgent(ctx, args) {
|
|
|
124
140
|
throw buildStructuredError("tool_unavailable", "launch_agent hook is unavailable");
|
|
125
141
|
}
|
|
126
142
|
|
|
127
|
-
const agent =
|
|
143
|
+
const agent = normalizeInternalAgentType(args.agent);
|
|
128
144
|
if (!agent) {
|
|
129
|
-
throw buildStructuredError("invalid_arguments", "launch_agent requires
|
|
145
|
+
throw buildStructuredError("invalid_arguments", "launch_agent requires internal codex, claude or ucode");
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
const op = {
|
|
133
149
|
action: "launch",
|
|
150
|
+
internal_only: true,
|
|
134
151
|
agent,
|
|
135
152
|
count: normalizePositiveInt(args.count, 1),
|
|
136
153
|
};
|
|
137
154
|
if (args.nickname) op.nickname = String(args.nickname).trim();
|
|
138
155
|
if (args.prompt_profile) op.prompt_profile = String(args.prompt_profile).trim();
|
|
139
|
-
if (args.launch_scope) op.launch_scope = String(args.launch_scope).trim();
|
|
140
|
-
if (args.terminal_app) op.terminal_app = String(args.terminal_app).trim();
|
|
141
156
|
|
|
142
157
|
const opsResults = await ctx.handleOps(ctx.projectRoot, [op], ctx.processManager || null);
|
|
143
158
|
return {
|
|
@@ -156,6 +171,7 @@ async function handleSharedRegistryTool(ctx, name, args, audit = {}) {
|
|
|
156
171
|
}
|
|
157
172
|
const eventBus = ctx.eventBus || new EventBus(ctx.projectRoot);
|
|
158
173
|
return definition.handler({
|
|
174
|
+
...ctx,
|
|
159
175
|
projectRoot: ctx.projectRoot,
|
|
160
176
|
subscriber: ctx.subscriber || "ufoo-agent",
|
|
161
177
|
caller_tier: CALLER_TIERS.CONTROLLER,
|
|
@@ -197,11 +213,12 @@ async function executeControllerTool(ctx, toolCall = {}) {
|
|
|
197
213
|
});
|
|
198
214
|
}
|
|
199
215
|
|
|
216
|
+
const ok = result?.ok !== false;
|
|
200
217
|
observer.emit("tool_call_finished", {
|
|
201
218
|
tool_name: name,
|
|
202
219
|
tool_call_id: toolCallId,
|
|
203
220
|
turn_id: turnId,
|
|
204
|
-
ok
|
|
221
|
+
ok,
|
|
205
222
|
});
|
|
206
223
|
observer.audit({
|
|
207
224
|
source: "controller_loop",
|
|
@@ -209,16 +226,17 @@ async function executeControllerTool(ctx, toolCall = {}) {
|
|
|
209
226
|
tool_name: name,
|
|
210
227
|
tool_call_id: toolCallId,
|
|
211
228
|
turn_id: turnId,
|
|
212
|
-
ok
|
|
229
|
+
ok,
|
|
213
230
|
result,
|
|
214
231
|
});
|
|
215
232
|
|
|
216
233
|
return {
|
|
217
|
-
ok
|
|
234
|
+
ok,
|
|
218
235
|
name,
|
|
219
236
|
tool_call_id: toolCallId,
|
|
220
237
|
turn_id: turnId,
|
|
221
238
|
result,
|
|
239
|
+
...(!ok ? { error: buildStructuredError(result.code || "tool_rejected", typeof result.error === "string" ? result.error : result.error?.message || "tool rejected the request") } : {}),
|
|
222
240
|
};
|
|
223
241
|
} catch (err) {
|
|
224
242
|
const error = err && typeof err === "object" && err.code
|