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
|
@@ -16,6 +16,8 @@ const {
|
|
|
16
16
|
} = require("../terminal/adapters/hostAdapter");
|
|
17
17
|
const { resolveDefaultManualBootstrap } = require("../../agents/prompts/defaultBootstrap");
|
|
18
18
|
const { detectLaunchEnvironment } = require("../../agents/launch/launchEnvironment");
|
|
19
|
+
const { isInternalAgentMeta, normalizeInternalAgentType } = require("../contracts/agentMode");
|
|
20
|
+
const { loadRecoveryGroups, resolveRecoveryGroup, associateAgentWithGroup, recordGroupMemberResume } = require("./agentRecoveryGroups");
|
|
19
21
|
|
|
20
22
|
function normalizeLaunchAgent(agent = "") {
|
|
21
23
|
const value = String(agent || "").trim().toLowerCase();
|
|
@@ -24,7 +26,7 @@ function normalizeLaunchAgent(agent = "") {
|
|
|
24
26
|
if (value === "agy" || value === "antigravity") return "agy";
|
|
25
27
|
if (value === "grok" || value === "ugrok" || value === "grok-build" || value === "xai") return "grok";
|
|
26
28
|
if (value === "kimi" || value === "kimi-cli" || value === "kimi-code") return "kimi";
|
|
27
|
-
if (value === "
|
|
29
|
+
if (value === "ucode") return "ucode";
|
|
28
30
|
return "";
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -34,7 +36,7 @@ function toBusAgentType(agent = "") {
|
|
|
34
36
|
if (agent === "agy") return "agy";
|
|
35
37
|
if (agent === "grok") return "grok";
|
|
36
38
|
if (agent === "kimi") return "kimi";
|
|
37
|
-
if (agent === "
|
|
39
|
+
if (agent === "ucode") return "ucode";
|
|
38
40
|
return "";
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -44,7 +46,7 @@ function toTerminalBinary(agent = "") {
|
|
|
44
46
|
if (agent === "agy") return "uagy";
|
|
45
47
|
if (agent === "grok") return "ugrok";
|
|
46
48
|
if (agent === "kimi") return "ukimi";
|
|
47
|
-
if (agent === "
|
|
49
|
+
if (agent === "ucode") return "ucode";
|
|
48
50
|
return "";
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -54,13 +56,13 @@ function toTmuxBinary(agent = "") {
|
|
|
54
56
|
if (agent === "agy") return "uagy";
|
|
55
57
|
if (agent === "grok") return "ugrok";
|
|
56
58
|
if (agent === "kimi") return "ukimi";
|
|
57
|
-
if (agent === "
|
|
59
|
+
if (agent === "ucode") return "ucode";
|
|
58
60
|
return "";
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function applyDefaultManagedBootstrap(projectRoot, normalizedAgent, args = [], extraEnv = {}) {
|
|
62
64
|
const agentType = toBusAgentType(normalizedAgent);
|
|
63
|
-
if (!agentType || agentType === "
|
|
65
|
+
if (!agentType || agentType === "ucode") {
|
|
64
66
|
return {
|
|
65
67
|
args: Array.isArray(args) ? args.slice() : [],
|
|
66
68
|
extraEnv: extraEnv && typeof extraEnv === "object" ? { ...extraEnv } : {},
|
|
@@ -302,23 +304,23 @@ function buildShellEnvPrefix(extraEnv = {}) {
|
|
|
302
304
|
// would stay blocked until restart.
|
|
303
305
|
const APPLESCRIPT_TIMEOUT_MS = 10000;
|
|
304
306
|
|
|
305
|
-
function killAfterTimeout(proc, cmd, onTimeout) {
|
|
307
|
+
function killAfterTimeout(proc, cmd, onTimeout, timeoutMs = APPLESCRIPT_TIMEOUT_MS) {
|
|
306
308
|
return setTimeout(() => {
|
|
307
309
|
try {
|
|
308
310
|
proc.kill("SIGKILL");
|
|
309
311
|
} catch {
|
|
310
312
|
// process already exited, nothing to kill
|
|
311
313
|
}
|
|
312
|
-
onTimeout(new Error(`${cmd} timeout after ${
|
|
313
|
-
},
|
|
314
|
+
onTimeout(new Error(`${cmd} timeout after ${timeoutMs}ms`));
|
|
315
|
+
}, timeoutMs);
|
|
314
316
|
}
|
|
315
317
|
|
|
316
|
-
function runAppleScript(lines) {
|
|
318
|
+
function runAppleScript(lines, options = {}) {
|
|
317
319
|
return new Promise((resolve, reject) => {
|
|
318
320
|
const proc = spawn("osascript", lines.flatMap((l) => ["-e", l]));
|
|
319
321
|
let stderr = "";
|
|
320
322
|
let stdout = "";
|
|
321
|
-
const timeout = killAfterTimeout(proc, "osascript", reject);
|
|
323
|
+
const timeout = killAfterTimeout(proc, "osascript", reject, options.timeoutMs);
|
|
322
324
|
proc.stderr.on("data", (d) => {
|
|
323
325
|
stderr += d.toString("utf8");
|
|
324
326
|
});
|
|
@@ -451,7 +453,7 @@ async function closeTerminalWindowByTty(ttyPath, preferApp = "") {
|
|
|
451
453
|
"end tell",
|
|
452
454
|
'return "not found"',
|
|
453
455
|
];
|
|
454
|
-
const res = await runAppleScript(script);
|
|
456
|
+
const res = await runAppleScript(script, { timeoutMs: 1000 });
|
|
455
457
|
return res === "ok";
|
|
456
458
|
};
|
|
457
459
|
|
|
@@ -470,7 +472,7 @@ async function closeTerminalWindowByTty(ttyPath, preferApp = "") {
|
|
|
470
472
|
"end tell",
|
|
471
473
|
'return "not found"',
|
|
472
474
|
];
|
|
473
|
-
const res = await runAppleScript(script);
|
|
475
|
+
const res = await runAppleScript(script, { timeoutMs: 1000 });
|
|
474
476
|
return res === "ok";
|
|
475
477
|
};
|
|
476
478
|
|
|
@@ -598,6 +600,7 @@ async function spawnManagedHostAgent(
|
|
|
598
600
|
const EventBus = require("../../coordination/bus");
|
|
599
601
|
const existing = listSubscribers(projectRoot, agentType);
|
|
600
602
|
let subscriberId = "";
|
|
603
|
+
let agentHandle = "";
|
|
601
604
|
let preRegistrationError = null;
|
|
602
605
|
try {
|
|
603
606
|
const bus = new EventBus(projectRoot);
|
|
@@ -605,13 +608,13 @@ async function spawnManagedHostAgent(
|
|
|
605
608
|
if (bus.subscriberManager) {
|
|
606
609
|
const sessionToken = crypto.randomBytes(4).toString("hex");
|
|
607
610
|
subscriberId = `${agentType}:${sessionToken}`;
|
|
608
|
-
const defaultNickname =
|
|
611
|
+
const defaultNickname = normalizedAgent;
|
|
609
612
|
const finalNickname = nickname || defaultNickname;
|
|
610
|
-
await
|
|
611
|
-
launchMode: "host",
|
|
613
|
+
const registration = await require("./controlPlaneService").registerAgentFull(projectRoot, {
|
|
614
|
+
sessionId: sessionToken, agentType, nickname: finalNickname, launchMode: "host",
|
|
612
615
|
parentPid: process.pid,
|
|
613
|
-
});
|
|
614
|
-
|
|
616
|
+
}, { validateParentPid: true, notifyDaemon: false });
|
|
617
|
+
agentHandle = registration.agent_handle;
|
|
615
618
|
}
|
|
616
619
|
} catch (err) {
|
|
617
620
|
preRegistrationError = err;
|
|
@@ -629,6 +632,7 @@ async function spawnManagedHostAgent(
|
|
|
629
632
|
};
|
|
630
633
|
if (subscriberId) {
|
|
631
634
|
env.UFOO_SUBSCRIBER_ID = subscriberId;
|
|
635
|
+
env.UFOO_AGENT_HANDLE = agentHandle;
|
|
632
636
|
}
|
|
633
637
|
if (nickname) {
|
|
634
638
|
env.UFOO_NICKNAME = nickname;
|
|
@@ -684,6 +688,7 @@ async function spawnInternalAgent(
|
|
|
684
688
|
extraArgs = [],
|
|
685
689
|
options = {}
|
|
686
690
|
) {
|
|
691
|
+
if (!normalizeInternalAgentType(agent)) throw new Error(`unsupported internal agent type: ${agent}; use codex, claude or ucode`);
|
|
687
692
|
const runner = resolveUfooRunnerPath();
|
|
688
693
|
const logDir = getUfooPaths(projectRoot).runDir;
|
|
689
694
|
fs.mkdirSync(logDir, { recursive: true });
|
|
@@ -718,6 +723,7 @@ async function spawnInternalAgent(
|
|
|
718
723
|
const replaceAgentId = typeof options.replaceAgentId === "string" ? options.replaceAgentId.trim() : "";
|
|
719
724
|
if (replaceAgentId && bus.busData.agents && bus.busData.agents[replaceAgentId]) {
|
|
720
725
|
delete bus.busData.agents[replaceAgentId];
|
|
726
|
+
bus.saveBusData();
|
|
721
727
|
}
|
|
722
728
|
|
|
723
729
|
const requestedNickname = nickname
|
|
@@ -727,14 +733,14 @@ async function spawnInternalAgent(
|
|
|
727
733
|
const launchMode = "internal";
|
|
728
734
|
|
|
729
735
|
// 传递 launch_mode 和 parent PID 到 join
|
|
730
|
-
const joinResult = await
|
|
736
|
+
const joinResult = await require("./controlPlaneService").registerAgentFull(projectRoot, {
|
|
737
|
+
sessionId, agentType, nickname: requestedNickname,
|
|
731
738
|
launchMode,
|
|
732
739
|
parentPid: originalPid,
|
|
733
740
|
providerSessionId,
|
|
734
741
|
scopedNickname: String(extraEnv.UFOO_SCOPED_NICKNAME || "").trim(),
|
|
735
|
-
});
|
|
742
|
+
}, { validateParentPid: true, notifyDaemon: false });
|
|
736
743
|
const finalNickname = joinResult.nickname || requestedNickname || "";
|
|
737
|
-
bus.saveBusData();
|
|
738
744
|
|
|
739
745
|
const managedBootstrap = applyDefaultManagedBootstrap(projectRoot, normalizedAgent, extraArgs, extraEnv);
|
|
740
746
|
const runnerCmd = "agent-runner";
|
|
@@ -748,6 +754,7 @@ async function spawnInternalAgent(
|
|
|
748
754
|
...(managedBootstrap.extraEnv && typeof managedBootstrap.extraEnv === "object" ? managedBootstrap.extraEnv : {}),
|
|
749
755
|
UFOO_INTERNAL_AGENT: "1",
|
|
750
756
|
UFOO_SUBSCRIBER_ID: subscriberId,
|
|
757
|
+
UFOO_AGENT_HANDLE: joinResult.agent_handle,
|
|
751
758
|
UFOO_NICKNAME: finalNickname,
|
|
752
759
|
UFOO_LAUNCH_MODE: "internal",
|
|
753
760
|
UFOO_PARENT_PID: String(originalPid),
|
|
@@ -969,7 +976,7 @@ function spawnTmuxPane(
|
|
|
969
976
|
|
|
970
977
|
async function launchAgent(projectRoot, agent, count = 1, nickname = "", processManager = null, options = {}) {
|
|
971
978
|
const config = loadConfig(projectRoot);
|
|
972
|
-
const mode = resolveConfiguredLaunchMode(config.launchMode, options);
|
|
979
|
+
const mode = options.internalOnly ? "internal" : resolveConfiguredLaunchMode(config.launchMode, options);
|
|
973
980
|
const launchScope = normalizeLaunchScope(options.launchScope, "inplace");
|
|
974
981
|
const terminalApp = normalizeTerminalAppPreference(options.terminalApp);
|
|
975
982
|
const extraEnvObject = options.extraEnv && typeof options.extraEnv === "object" ? options.extraEnv : {};
|
|
@@ -985,6 +992,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
|
|
|
985
992
|
}
|
|
986
993
|
|
|
987
994
|
if (mode === "internal") {
|
|
995
|
+
if (!normalizeInternalAgentType(normalizedAgent)) throw new Error(`unsupported internal agent type: ${agent}; use codex, claude or ucode`);
|
|
988
996
|
const result = await spawnInternalAgent(
|
|
989
997
|
projectRoot,
|
|
990
998
|
normalizedAgent,
|
|
@@ -1034,8 +1042,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
|
|
|
1034
1042
|
&& tmuxLayoutContext
|
|
1035
1043
|
&& tmuxLayoutContext.mode === "group-right-column";
|
|
1036
1044
|
for (let i = 0; i < count; i += 1) {
|
|
1037
|
-
|
|
1038
|
-
const defaultNick = normalizedAgent === "ufoo" ? "ucode" : normalizedAgent;
|
|
1045
|
+
const defaultNick = normalizedAgent;
|
|
1039
1046
|
const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
|
|
1040
1047
|
if (useSeparateWindow) {
|
|
1041
1048
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -1082,7 +1089,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
|
|
|
1082
1089
|
const subscriberIds = [];
|
|
1083
1090
|
const hostContext = resolveHostLaunchContext(options);
|
|
1084
1091
|
for (let i = 0; i < count; i += 1) {
|
|
1085
|
-
const defaultNick = normalizedAgent
|
|
1092
|
+
const defaultNick = normalizedAgent;
|
|
1086
1093
|
const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
|
|
1087
1094
|
// eslint-disable-next-line no-await-in-loop
|
|
1088
1095
|
const result = await spawnManagedHostAgent(
|
|
@@ -1105,8 +1112,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
|
|
|
1105
1112
|
|
|
1106
1113
|
const subscriberIds = [];
|
|
1107
1114
|
for (let i = 0; i < count; i += 1) {
|
|
1108
|
-
|
|
1109
|
-
const defaultNick = normalizedAgent === "ufoo" ? "ucode" : normalizedAgent;
|
|
1115
|
+
const defaultNick = normalizedAgent;
|
|
1110
1116
|
const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
|
|
1111
1117
|
// eslint-disable-next-line no-await-in-loop
|
|
1112
1118
|
const result = await spawnManagedTerminalAgent(
|
|
@@ -1129,7 +1135,7 @@ function normalizeAgentType(agentType) {
|
|
|
1129
1135
|
if (agentType === "claude-code") return "claude";
|
|
1130
1136
|
if (agentType === "codex") return "codex";
|
|
1131
1137
|
if (agentType === "grok") return "grok";
|
|
1132
|
-
if (agentType === "
|
|
1138
|
+
if (agentType === "ucode") return "ucode";
|
|
1133
1139
|
return agentType;
|
|
1134
1140
|
}
|
|
1135
1141
|
|
|
@@ -1143,6 +1149,7 @@ function buildResumeArgs(agent, sessionId) {
|
|
|
1143
1149
|
if (agent === "grok") return ["--resume", sessionId];
|
|
1144
1150
|
// kimi resumes a session by id via `-S, --session <id>`.
|
|
1145
1151
|
if (agent === "kimi") return ["--session", sessionId];
|
|
1152
|
+
if (agent === "ucode") return ["--session-id", sessionId];
|
|
1146
1153
|
return [];
|
|
1147
1154
|
}
|
|
1148
1155
|
|
|
@@ -1152,17 +1159,23 @@ function isActiveAgent(meta) {
|
|
|
1152
1159
|
return true;
|
|
1153
1160
|
}
|
|
1154
1161
|
|
|
1155
|
-
function collectRecoverableAgents(projectRoot, target = "") {
|
|
1162
|
+
function collectRecoverableAgents(projectRoot, target = "", options = {}) {
|
|
1156
1163
|
const config = loadConfig(projectRoot);
|
|
1157
1164
|
const mode = config.launchMode || "terminal";
|
|
1158
1165
|
const filePath = getUfooPaths(projectRoot).agentsFile;
|
|
1159
1166
|
const data = loadAgentsData(filePath);
|
|
1160
1167
|
const entries = Object.entries(data.agents || {});
|
|
1168
|
+
const groups = loadRecoveryGroups(projectRoot);
|
|
1169
|
+
const associations = new Map(entries.map(([id, meta]) => [id, resolveRecoveryGroup(groups, id, meta)]));
|
|
1161
1170
|
|
|
1162
1171
|
let targets = entries;
|
|
1163
1172
|
if (target) {
|
|
1164
1173
|
const scopedTarget = applyProjectNicknamePrefix(projectRoot, target);
|
|
1165
|
-
if (target.
|
|
1174
|
+
if (target.startsWith("group:")) {
|
|
1175
|
+
targets = entries.filter(([id]) => associations.get(id).group_id === target.slice(6));
|
|
1176
|
+
const group = groups.find((item) => item.group_id === target.slice(6));
|
|
1177
|
+
if (group) targets.sort(([a], [b]) => group.members.findIndex((item) => item?.subscriber_id === a) - group.members.findIndex((item) => item?.subscriber_id === b));
|
|
1178
|
+
} else if (target.includes(":")) {
|
|
1166
1179
|
targets = entries.filter(([id]) => id === target);
|
|
1167
1180
|
} else {
|
|
1168
1181
|
targets = entries.filter(([id, meta]) =>
|
|
@@ -1186,6 +1199,10 @@ function collectRecoverableAgents(projectRoot, target = "") {
|
|
|
1186
1199
|
}
|
|
1187
1200
|
|
|
1188
1201
|
for (const [id, meta] of targets) {
|
|
1202
|
+
if (options.internalOnly && !isInternalAgentMeta(meta)) {
|
|
1203
|
+
if (target) skipped.push({ id, reason: "non-internal agent" });
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1189
1206
|
if (!meta || !meta.provider_session_id) {
|
|
1190
1207
|
skipped.push({ id, reason: "no provider session" });
|
|
1191
1208
|
continue;
|
|
@@ -1195,12 +1212,12 @@ function collectRecoverableAgents(projectRoot, target = "") {
|
|
|
1195
1212
|
continue;
|
|
1196
1213
|
}
|
|
1197
1214
|
const agent = normalizeAgentType(meta.agent_type);
|
|
1198
|
-
if (agent !== "codex" && agent !== "claude" && agent !== "agy" && agent !== "grok" && agent !== "kimi") {
|
|
1215
|
+
if (agent !== "codex" && agent !== "claude" && agent !== "agy" && agent !== "grok" && agent !== "kimi" && agent !== "ucode") {
|
|
1199
1216
|
skipped.push({ id, reason: "unsupported agent type" });
|
|
1200
1217
|
continue;
|
|
1201
1218
|
}
|
|
1202
1219
|
|
|
1203
|
-
recoverableEntries.push({ id, meta, agent });
|
|
1220
|
+
recoverableEntries.push({ id, meta, agent, association: associations.get(id) });
|
|
1204
1221
|
}
|
|
1205
1222
|
|
|
1206
1223
|
return {
|
|
@@ -1211,8 +1228,8 @@ function collectRecoverableAgents(projectRoot, target = "") {
|
|
|
1211
1228
|
};
|
|
1212
1229
|
}
|
|
1213
1230
|
|
|
1214
|
-
function getRecoverableAgents(projectRoot, target = "") {
|
|
1215
|
-
const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target);
|
|
1231
|
+
function getRecoverableAgents(projectRoot, target = "", options = {}) {
|
|
1232
|
+
const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target, options);
|
|
1216
1233
|
const recoverable = recoverableEntries.map((item) => ({
|
|
1217
1234
|
id: item.id,
|
|
1218
1235
|
nickname: resolveDisplayNickname(projectRoot, item.meta),
|
|
@@ -1221,12 +1238,19 @@ function getRecoverableAgents(projectRoot, target = "") {
|
|
|
1221
1238
|
sessionId: item.meta.provider_session_id || "",
|
|
1222
1239
|
launchMode: item.meta.launch_mode || "",
|
|
1223
1240
|
lastSeen: item.meta.last_seen || "",
|
|
1241
|
+
...item.association,
|
|
1224
1242
|
}));
|
|
1225
|
-
|
|
1243
|
+
const groups = new Map();
|
|
1244
|
+
for (const item of recoverable) {
|
|
1245
|
+
if (!item.group_id) continue;
|
|
1246
|
+
if (!groups.has(item.group_id)) groups.set(item.group_id, { group_id: item.group_id, template_alias: item.group_template_alias, members: [] });
|
|
1247
|
+
groups.get(item.group_id).members.push(item);
|
|
1248
|
+
}
|
|
1249
|
+
return { ok: true, mode, recoverable, groups: [...groups.values()], skipped };
|
|
1226
1250
|
}
|
|
1227
1251
|
|
|
1228
|
-
async function resumeAgents(projectRoot, target = "", processManager = null) {
|
|
1229
|
-
const { mode,
|
|
1252
|
+
async function resumeAgents(projectRoot, target = "", processManager = null, options = {}) {
|
|
1253
|
+
const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target, options);
|
|
1230
1254
|
|
|
1231
1255
|
if (recoverableEntries.length === 0) {
|
|
1232
1256
|
return { ok: true, resumed: [], skipped };
|
|
@@ -1239,7 +1263,7 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
|
|
|
1239
1263
|
const args = buildResumeArgs(item.agent, sessionId);
|
|
1240
1264
|
let reused = false;
|
|
1241
1265
|
let resumedId = item.id;
|
|
1242
|
-
if (mode === "internal") {
|
|
1266
|
+
if (options.internalOnly || isInternalAgentMeta(item.meta) || mode === "internal") {
|
|
1243
1267
|
// Internal agents have no terminal/pane to reattach. Start a fresh
|
|
1244
1268
|
// daemon-managed runner and replace the old recoverable registration.
|
|
1245
1269
|
// The provider session is still reused via the normal provider args.
|
|
@@ -1250,13 +1274,15 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
|
|
|
1250
1274
|
1,
|
|
1251
1275
|
nickname,
|
|
1252
1276
|
processManager,
|
|
1253
|
-
{ UFOO_SKIP_SESSION_RESOLVE: "1" },
|
|
1277
|
+
{ UFOO_SKIP_SESSION_RESOLVE: "1", UFOO_SCOPED_NICKNAME: item.meta.scoped_nickname || "" },
|
|
1254
1278
|
args,
|
|
1255
1279
|
{ replaceAgentId: item.id, providerSessionId: sessionId }
|
|
1256
1280
|
);
|
|
1257
1281
|
resumedId = launchResult.subscriberIds && launchResult.subscriberIds[0]
|
|
1258
1282
|
? launchResult.subscriberIds[0]
|
|
1259
1283
|
: item.id;
|
|
1284
|
+
associateAgentWithGroup(projectRoot, resumedId, item.association);
|
|
1285
|
+
recordGroupMemberResume(projectRoot, item.association, item.id, resumedId);
|
|
1260
1286
|
} else {
|
|
1261
1287
|
reused = await tryReuseTerminal(projectRoot, item.id, item.meta, item.agent, sessionId);
|
|
1262
1288
|
if (!reused) {
|
|
@@ -1277,6 +1303,7 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
|
|
|
1277
1303
|
agent: item.agent,
|
|
1278
1304
|
sessionId,
|
|
1279
1305
|
reused,
|
|
1306
|
+
...item.association,
|
|
1280
1307
|
});
|
|
1281
1308
|
}
|
|
1282
1309
|
|
|
@@ -1339,8 +1366,9 @@ async function closeAgent(projectRoot, agentId) {
|
|
|
1339
1366
|
}
|
|
1340
1367
|
|
|
1341
1368
|
if (canCloseWindow) {
|
|
1342
|
-
//
|
|
1343
|
-
|
|
1369
|
+
// Complete the bounded cleanup before returning; detached attempts can
|
|
1370
|
+
// outlive their project runtime and use stale terminal/agent metadata.
|
|
1371
|
+
await closeTerminalWindowByTty(tty, terminalApp).catch(() => false);
|
|
1344
1372
|
}
|
|
1345
1373
|
|
|
1346
1374
|
// Tmux pane cleanup: kill the pane after sending SIGTERM to the process.
|
|
@@ -17,6 +17,8 @@ const { CALLER_TIERS } = require("../../tools/types");
|
|
|
17
17
|
const { ProjectRuntimeManager } = require("./projectRuntimeManager");
|
|
18
18
|
|
|
19
19
|
const MCP_EXPOSED_SHARED_TOOLS = Object.freeze([
|
|
20
|
+
"read_agent_metrics",
|
|
21
|
+
"read_agent_trace",
|
|
20
22
|
"read_project_registry",
|
|
21
23
|
"read_bus_summary",
|
|
22
24
|
"read_prompt_history",
|