u-foo 4.0.0 → 4.0.2
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 +90 -30
- package/README.zh-CN.md +76 -26
- package/SKILLS/ufoo/SKILL.md +25 -1
- package/SKILLS/ufoo-bus/SKILL.md +25 -2
- package/bin/ucode.js +4 -0
- package/bin/ufoo.js +3 -3
- 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 +6 -6
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/capabilities/agentManagement/service.js +40 -13
- package/src/agents/capabilities/coordination/index.js +1 -1
- package/src/agents/capabilities/taskReports/index.js +1 -1
- package/src/agents/controller/controllerToolExecutor.js +36 -20
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +90 -56
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +38 -29
- package/src/agents/launch/launcherReadiness.js +35 -0
- package/src/agents/launch/notifier.js +2 -2
- package/src/agents/launch/ptyWrapper.js +5 -2
- package/src/agents/launch/readyDetector.js +2 -2
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +23 -7
- package/src/agents/prompts/mainAgent.js +11 -2
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/ufoo.js +11 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +3 -0
- package/src/agents/providers/claudeThreadProvider.js +3 -2
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +23 -2
- package/src/agents/providers/codexThreadProvider.js +15 -6
- 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 +58 -40
- package/src/agents/providers/runtimeConfig.js +10 -8
- package/src/agents/providers/thinkingLevels.js +10 -36
- package/src/agents/providers/transports/responsesProtocol.js +11 -6
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +2 -1
- package/src/agents/runtime/core/agentLoop.js +99 -18
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/createAgentRuntime.js +16 -4
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/app/chat/ChatController.js +26 -53
- package/src/app/chat/agentDirectory.js +1 -16
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +93 -285
- package/src/app/chat/commands.js +32 -45
- package/src/app/chat/daemonMessageRouter.js +0 -45
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +7 -33
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/multiWindow/paneManager.js +10 -3
- package/src/app/chat/streamState.js +0 -4
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/run.js +42 -3
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +18 -13
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/assembler.js +7 -8
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/internalThread.js +10 -3
- 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 +55 -17
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/repl.js +4 -11
- package/src/code/sessionStore.js +3 -3
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/toolBudget.js +1 -17
- package/src/config.js +22 -72
- package/src/coordination/bus/index.js +12 -3
- package/src/coordination/bus/inject.js +2 -2
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +1 -1
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/state/workspaceAccess.js +1 -1
- 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 +11 -2
- package/src/runtime/contracts/uiProtocol.js +18 -19
- package/src/runtime/daemon/agentHost.js +57 -25
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +1 -1
- package/src/runtime/daemon/controlPlaneService.js +1 -1
- package/src/runtime/daemon/groupOrchestrator.js +20 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +19 -44
- package/src/runtime/daemon/mcpHttpServer.js +39 -10
- package/src/runtime/daemon/mcpServer.js +1 -1
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +46 -23
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -589
- package/src/runtime/daemon/status.js +5 -6
- package/src/tools/controllerSchemas.js +6 -2
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/registry.js +4 -0
- package/src/tools/schemaFixtures.js +26 -2
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +1 -1
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +1 -4
- 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/rustChatHost.js +191 -206
- package/src/ui/rustMultiSession.js +77 -36
- package/src/ui/rustUcodeHost.js +6 -1
- package/src/ui/settingsBridge.js +33 -16
- 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 -336
- package/src/agents/controller/ufooAgent.js +0 -830
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/controllerJsonTransport.js +0 -28
- package/src/agents/providers/upstreamTransport.js +0 -698
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/coordination/history/controllerSummary.js +0 -23
- 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/executionPaths.js +0 -30
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
6
|
+
const { updateAgentsData } = require("../../coordination/state/agentsStore");
|
|
7
|
+
const { withFileLock } = require("../../coordination/state/fileLock");
|
|
8
|
+
|
|
9
|
+
const validGroupId = (id) => typeof id === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/.test(id);
|
|
10
|
+
|
|
11
|
+
function loadRecoveryGroups(projectRoot) {
|
|
12
|
+
const dir = getUfooPaths(projectRoot).groupsDir;
|
|
13
|
+
if (!fs.existsSync(dir)) return [];
|
|
14
|
+
const groups = [];
|
|
15
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
16
|
+
if (!entry.isFile() || !entry.name.endsWith(".json")) continue;
|
|
17
|
+
try {
|
|
18
|
+
const runtime = JSON.parse(fs.readFileSync(path.join(dir, entry.name), "utf8"));
|
|
19
|
+
if (validGroupId(runtime.group_id) && entry.name === `${runtime.group_id}.json` && Array.isArray(runtime.members)) groups.push(runtime);
|
|
20
|
+
} catch { /* A damaged group must not hide other recoverable sessions. */ }
|
|
21
|
+
}
|
|
22
|
+
return groups;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resolveRecoveryGroup(groups, subscriberId, meta = {}) {
|
|
26
|
+
const matches = groups.filter((group) => group.members.some((member) => member?.subscriber_id === subscriberId));
|
|
27
|
+
const group = meta.group_id
|
|
28
|
+
? groups.find((item) => item.group_id === meta.group_id)
|
|
29
|
+
: matches.length === 1 ? matches[0] : null;
|
|
30
|
+
const groupId = group?.group_id || (validGroupId(meta.group_id) ? meta.group_id : "");
|
|
31
|
+
const member = group?.members.find((item) => item?.subscriber_id === subscriberId);
|
|
32
|
+
return {
|
|
33
|
+
group_id: groupId,
|
|
34
|
+
group_member_id: member?.id || meta.group_member_id || "",
|
|
35
|
+
group_template_alias: group?.template_alias || meta.group_template_alias || "",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function associateAgentWithGroup(projectRoot, subscriberId, association) {
|
|
40
|
+
if (!subscriberId || !validGroupId(association.group_id)) return;
|
|
41
|
+
updateAgentsData(getUfooPaths(projectRoot).agentsFile, (data) => {
|
|
42
|
+
const meta = data.agents[subscriberId];
|
|
43
|
+
if (!meta) return false;
|
|
44
|
+
Object.assign(meta, association);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function recordGroupMemberResume(projectRoot, association, previousId, subscriberId) {
|
|
49
|
+
if (!validGroupId(association.group_id)) return;
|
|
50
|
+
const file = path.join(getUfooPaths(projectRoot).groupsDir, `${association.group_id}.json`);
|
|
51
|
+
if (!fs.existsSync(file)) return;
|
|
52
|
+
withFileLock(file, () => {
|
|
53
|
+
const runtime = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
54
|
+
const member = runtime.members?.find((item) => item.subscriber_id === previousId);
|
|
55
|
+
if (!member) return;
|
|
56
|
+
const now = new Date().toISOString();
|
|
57
|
+
member.previous_subscriber_id = previousId;
|
|
58
|
+
member.subscriber_id = subscriberId;
|
|
59
|
+
if (member.bootstrapped_subscriber_id === previousId) member.bootstrapped_subscriber_id = subscriberId;
|
|
60
|
+
member.status = "active";
|
|
61
|
+
member.resumed_at = now;
|
|
62
|
+
delete member.stop;
|
|
63
|
+
member.launch = { ...member.launch, mode: "internal", subscriber_ids: [subscriberId], resumed: true };
|
|
64
|
+
runtime.status = runtime.members.every((item) => ["active", "reused"].includes(item.status)) ? "active" : "partial";
|
|
65
|
+
runtime.updated_at = now;
|
|
66
|
+
fs.writeFileSync(file, `${JSON.stringify(runtime, null, 2)}\n`, "utf8");
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { loadRecoveryGroups, resolveRecoveryGroup, associateAgentWithGroup, recordGroupMemberResume };
|
|
@@ -252,7 +252,7 @@ function startBusBridge(
|
|
|
252
252
|
joinInProgress = (async () => {
|
|
253
253
|
try {
|
|
254
254
|
// Determine agent type based on provider configuration
|
|
255
|
-
const agentType = provider === "codex-cli" ? "codex" : (provider === "ucode" ? "
|
|
255
|
+
const agentType = provider === "codex-cli" ? "codex" : (provider === "ucode" ? "ucode" : "claude-code");
|
|
256
256
|
// Use fixed ID "ufoo-agent" for daemon's bus identity with explicit nickname
|
|
257
257
|
const sub = await eventBus.join("ufoo-agent", agentType, "ufoo-agent");
|
|
258
258
|
if (!sub || stopped) return null;
|
|
@@ -40,7 +40,7 @@ function normalizeBusAgentType(agentType = "") {
|
|
|
40
40
|
const value = String(agentType || "").trim().toLowerCase();
|
|
41
41
|
if (!value) return "mcp-agent";
|
|
42
42
|
if (value === "claude") return "claude-code";
|
|
43
|
-
if (value === "ucode"
|
|
43
|
+
if (value === "ucode") return "ucode";
|
|
44
44
|
return value;
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -13,6 +13,9 @@ const {
|
|
|
13
13
|
} = require("../../orchestration/groups/bootstrap");
|
|
14
14
|
const { validateTemplateTarget: validateGroupTemplateTarget } = require("../../orchestration/groups/templateValidation");
|
|
15
15
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
16
|
+
const { associateAgentWithGroup } = require("./agentRecoveryGroups");
|
|
17
|
+
const { reconcileGroupStatus } = require("./groupStatus");
|
|
18
|
+
const { normalizeInternalAgentType } = require("../contracts/agentMode");
|
|
16
19
|
const {
|
|
17
20
|
normalizeNicknameSegment,
|
|
18
21
|
buildProjectNicknamePrefix,
|
|
@@ -308,12 +311,13 @@ function pickRosterMembers(roster = [], nicknames = []) {
|
|
|
308
311
|
return roster.filter((item) => wanted.has(item.nickname));
|
|
309
312
|
}
|
|
310
313
|
|
|
311
|
-
function resolveAutoAgentType(projectRoot, requestedType) {
|
|
314
|
+
function resolveAutoAgentType(projectRoot, requestedType, internalOnly = false) {
|
|
312
315
|
const normalizedRequested = asTrimmedString(requestedType);
|
|
313
316
|
if (normalizedRequested && normalizedRequested !== "auto") return normalizedRequested;
|
|
314
317
|
|
|
315
318
|
const provider = asTrimmedString(loadConfig(projectRoot).agentProvider);
|
|
316
319
|
if (provider === "claude-cli") return "claude";
|
|
320
|
+
if (internalOnly) return provider === "codex-cli" ? "codex" : "ucode";
|
|
317
321
|
if (provider === "ucode") return "ucode";
|
|
318
322
|
if (provider === "agy-cli") return "agy";
|
|
319
323
|
if (provider === "kimi-cli") return "kimi";
|
|
@@ -329,6 +333,7 @@ function buildExecutionPlan({
|
|
|
329
333
|
plan,
|
|
330
334
|
promptRegistry,
|
|
331
335
|
promptProfiles,
|
|
336
|
+
internalOnly = false,
|
|
332
337
|
}) {
|
|
333
338
|
const profileByNickname = new Map();
|
|
334
339
|
for (const item of promptProfiles || []) {
|
|
@@ -339,7 +344,7 @@ function buildExecutionPlan({
|
|
|
339
344
|
const relationships = buildRelationshipMaps(templateDoc, plan);
|
|
340
345
|
|
|
341
346
|
const roster = plan.map((item) => {
|
|
342
|
-
const resolvedType = resolveAutoAgentType(projectRoot, item.requested_type || item.type);
|
|
347
|
+
const resolvedType = resolveAutoAgentType(projectRoot, item.requested_type || item.type, internalOnly);
|
|
343
348
|
const profile = profileByNickname.get(item.nickname) || null;
|
|
344
349
|
const runtimeNickname = buildRuntimeNickname(projectNicknamePrefix, item.nickname);
|
|
345
350
|
return {
|
|
@@ -365,7 +370,7 @@ function buildExecutionPlan({
|
|
|
365
370
|
: {};
|
|
366
371
|
|
|
367
372
|
const executionPlan = plan.map((item) => {
|
|
368
|
-
const resolvedType = resolveAutoAgentType(projectRoot, item.requested_type || item.type);
|
|
373
|
+
const resolvedType = resolveAutoAgentType(projectRoot, item.requested_type || item.type, internalOnly);
|
|
369
374
|
const profile = profileByNickname.get(item.nickname) || null;
|
|
370
375
|
const resolvedProfile = profile ? registryById.get(profile.resolved_profile) || null : null;
|
|
371
376
|
const relation = relationships.get(item.nickname) || { upstream: [], downstream: [] };
|
|
@@ -809,8 +814,12 @@ function createGroupOrchestrator(options = {}) {
|
|
|
809
814
|
plan,
|
|
810
815
|
promptRegistry: validated.promptRegistry,
|
|
811
816
|
promptProfiles: validated.promptProfiles,
|
|
817
|
+
internalOnly: params.internal_only === true,
|
|
812
818
|
});
|
|
813
819
|
|
|
820
|
+
const unsupported = params.internal_only === true && compiled.executionPlan.find((item) => !normalizeInternalAgentType(item.type));
|
|
821
|
+
if (unsupported) return { ok: false, status: "failed", error: `unsupported internal agent type: ${unsupported.type}; use codex, claude or ucode` };
|
|
822
|
+
|
|
814
823
|
if (dryRun) {
|
|
815
824
|
return {
|
|
816
825
|
ok: true,
|
|
@@ -989,6 +998,11 @@ function createGroupOrchestrator(options = {}) {
|
|
|
989
998
|
member.status = reused ? "reused" : "active";
|
|
990
999
|
member.managed = !reused;
|
|
991
1000
|
member.subscriber_id = subscriberId || "";
|
|
1001
|
+
associateAgentWithGroup(projectRoot, subscriberId, {
|
|
1002
|
+
group_id: runtime.group_id,
|
|
1003
|
+
group_member_id: item.id,
|
|
1004
|
+
group_template_alias: runtime.template_alias,
|
|
1005
|
+
});
|
|
992
1006
|
member.launched_at = nowIso();
|
|
993
1007
|
member.launch = launchResult;
|
|
994
1008
|
member.bootstrap_error = "";
|
|
@@ -1212,10 +1226,11 @@ function createGroupOrchestrator(options = {}) {
|
|
|
1212
1226
|
if (!group) {
|
|
1213
1227
|
return { ok: false, error: `group not found: ${groupId}` };
|
|
1214
1228
|
}
|
|
1215
|
-
return { ok: true, group };
|
|
1229
|
+
return { ok: true, group: reconcileGroupStatus(group, readBusAgents(projectRoot)) };
|
|
1216
1230
|
}
|
|
1217
1231
|
|
|
1218
|
-
const
|
|
1232
|
+
const agents = readBusAgents(projectRoot);
|
|
1233
|
+
const groups = listGroupStates(projectRoot).map((runtime) => summarizeGroup(reconcileGroupStatus(runtime, agents)));
|
|
1219
1234
|
groups.sort((a, b) => String(b.updated_at || "").localeCompare(String(a.updated_at || "")));
|
|
1220
1235
|
return { ok: true, count: groups.length, groups };
|
|
1221
1236
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { isMetaActive } = require("../../coordination/bus/utils");
|
|
4
|
+
|
|
5
|
+
/** Group files retain launch history; registrations determine current liveness. */
|
|
6
|
+
function reconcileGroupStatus(runtime = {}, agents = {}) {
|
|
7
|
+
const members = (Array.isArray(runtime.members) ? runtime.members : []).map((member) => {
|
|
8
|
+
if (!member || !["active", "reused"].includes(member.status)) return member;
|
|
9
|
+
const meta = agents[member.subscriber_id];
|
|
10
|
+
return isMetaActive(meta) ? member : { ...member, status: "inactive" };
|
|
11
|
+
});
|
|
12
|
+
let status = runtime.status;
|
|
13
|
+
if (members.length && ["active", "partial", "inactive"].includes(status)) {
|
|
14
|
+
const active = members.filter((member) => member && ["active", "reused"].includes(member.status)).length;
|
|
15
|
+
status = active === members.length ? "active" : active ? "partial" : "inactive";
|
|
16
|
+
}
|
|
17
|
+
return { ...runtime, status, members };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { reconcileGroupStatus };
|
|
@@ -2,7 +2,6 @@ const fs = require("fs");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const net = require("net");
|
|
4
4
|
const { spawn, spawnSync } = require("child_process");
|
|
5
|
-
const { runUfooAgent, runUfooRouteAgent } = require("../../agents/controller/ufooAgent");
|
|
6
5
|
const { launchAgent, closeAgent, getRecoverableAgents, resumeAgents } = require("./ops");
|
|
7
6
|
const { buildStatus } = require("./status");
|
|
8
7
|
const EventBus = require("../../coordination/bus");
|
|
@@ -25,7 +24,6 @@ const { createDaemonCronController } = require("./cronOps");
|
|
|
25
24
|
const { createGroupOrchestrator } = require("./groupOrchestrator");
|
|
26
25
|
const { DeliveryScheduler } = require("./deliveryScheduler");
|
|
27
26
|
const { normalizeFormat, renderGroupDiagramFromTemplate, renderGroupDiagramFromRuntime } = require("../../orchestration/groups/diagram");
|
|
28
|
-
const { runPromptWithAssistant } = require("./promptLoop");
|
|
29
27
|
const { handlePromptRequest } = require("./promptRequest");
|
|
30
28
|
const { recordAgentReport } = require("./reporting");
|
|
31
29
|
const { startBusBridge } = require("./busBridge");
|
|
@@ -77,7 +75,7 @@ function normalizeBusAgentType(agentType = "") {
|
|
|
77
75
|
if (value === "agy" || value === "antigravity") return "agy";
|
|
78
76
|
if (value === "grok" || value === "ugrok" || value === "grok-build" || value === "xai") return "grok";
|
|
79
77
|
if (value === "kimi" || value === "kimi-cli" || value === "kimi-code") return "kimi";
|
|
80
|
-
if (value === "
|
|
78
|
+
if (value === "ucode") return "ucode";
|
|
81
79
|
return value;
|
|
82
80
|
}
|
|
83
81
|
|
|
@@ -88,7 +86,7 @@ function normalizeLaunchAgent(agent = "") {
|
|
|
88
86
|
if (value === "agy" || value === "antigravity") return "agy";
|
|
89
87
|
if (value === "grok" || value === "ugrok" || value === "grok-build" || value === "xai") return "grok";
|
|
90
88
|
if (value === "kimi" || value === "kimi-cli" || value === "kimi-code") return "kimi";
|
|
91
|
-
if (value === "
|
|
89
|
+
if (value === "ucode") return "ucode";
|
|
92
90
|
return "";
|
|
93
91
|
}
|
|
94
92
|
|
|
@@ -856,6 +854,8 @@ async function dispatchMessages(projectRoot, dispatch = [], { strict = false } =
|
|
|
856
854
|
const sendOptions = {
|
|
857
855
|
injectionMode: item.injection_mode,
|
|
858
856
|
source: item.source,
|
|
857
|
+
...(item.task_id ? { taskId: item.task_id } : {}),
|
|
858
|
+
...(item.runtime_context ? { data: { runtime_context: item.runtime_context } } : {}),
|
|
859
859
|
};
|
|
860
860
|
try {
|
|
861
861
|
if (target === "broadcast") {
|
|
@@ -1156,15 +1156,13 @@ function startDaemon({
|
|
|
1156
1156
|
dispatchMessages: (root, messages) => dispatchMessages(root, messages, { strict: true }),
|
|
1157
1157
|
ackBus: async (root, subscriber) => new EventBus(root).ack(subscriber),
|
|
1158
1158
|
markPending: (target) => busBridge.markPending(target), groups: daemonGroupOrchestrator,
|
|
1159
|
-
agentLifecycle: { inspect: (target) => getRecoverableAgents(projectRoot, target), resume: (target) => resumeAgents(projectRoot, target, processManager) } },
|
|
1159
|
+
agentLifecycle: { inspect: (target) => getRecoverableAgents(projectRoot, target, { internalOnly: true }), resume: (target) => resumeAgents(projectRoot, target, processManager, { internalOnly: true }) } },
|
|
1160
1160
|
onEvent: (event) => ipcServer.sendToSockets({ type: IPC_RESPONSE_TYPES.RUNTIME_EVENT, data: event }),
|
|
1161
1161
|
}));
|
|
1162
1162
|
void mainAgentHost.recover().catch((error) => log(`main runtime recovery failed: ${error.message}`));
|
|
1163
1163
|
runtimeServices.workspaceAccess = mainAgentHost.workspaceAccess;
|
|
1164
|
-
const selectExecutionPath = require("./executionPaths").createExecutionPathSelector(projectRoot);
|
|
1165
1164
|
projectRuntime.canSuspendHook = () => !mainAgentHost.snapshot().sessions.some((session) => session.tasks.some((task) => ["queued", "running"].includes(task.status)))
|
|
1166
|
-
&& !mainAgentHost.snapshot().children.some((task) => ["queued", "running"].includes(task.status))
|
|
1167
|
-
&& !mainAgentHost.snapshot().compatibility.active && !mainAgentHost.snapshot().compatibility.queued;
|
|
1165
|
+
&& !mainAgentHost.snapshot().children.some((task) => ["queued", "running"].includes(task.status));
|
|
1168
1166
|
const deliveryScheduler = new DeliveryScheduler(projectRoot, {
|
|
1169
1167
|
log,
|
|
1170
1168
|
emitDelivery: async ({ subscriber, event, status, error, errorCode } = {}) => {
|
|
@@ -1266,6 +1264,7 @@ function startDaemon({
|
|
|
1266
1264
|
}
|
|
1267
1265
|
else if (req.operation === "tasks") result = await mainAgentHost.taskPort.execute(req.arguments || {}, { sessionId: req.session_id || "main-default", requestId: req.request_id });
|
|
1268
1266
|
else if (req.operation === "status") result = mainAgentHost.snapshot();
|
|
1267
|
+
else if (req.operation === "trace") result = require("../../coordination/history/agentTrace").readAgentTrace(projectRoot, req.arguments || {});
|
|
1269
1268
|
else throw new Error("unknown agent_runtime operation");
|
|
1270
1269
|
if (!socket.destroyed) socket.write(`${JSON.stringify({ type: IPC_RESPONSE_TYPES.RUNTIME_RESULT, request_id: req.request_id, data: result })}\n`);
|
|
1271
1270
|
} catch (error) {
|
|
@@ -1317,41 +1316,17 @@ function startDaemon({
|
|
|
1317
1316
|
}
|
|
1318
1317
|
if (req.type === IPC_REQUEST_TYPES.PROMPT) {
|
|
1319
1318
|
req.request_id = req.request_id || require("crypto").randomUUID();
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const result = await mainAgentHost.management.commands.execute({ commandId:
|
|
1323
|
-
if (result?.code === "uncertain_effect") throw Object.assign(new Error("
|
|
1319
|
+
const forwardEffect = async (args, invoke) => {
|
|
1320
|
+
const commandId = `project-forward-${require("crypto").createHash("sha256").update(req.request_id).digest("hex").slice(0, 32)}`;
|
|
1321
|
+
const result = await mainAgentHost.management.commands.execute({ commandId, kind: "project-forward", args }, invoke);
|
|
1322
|
+
if (result?.code === "uncertain_effect") throw Object.assign(new Error("project handoff outcome is unknown; inspect its receipt before retrying"), { code: "uncertain_effect" });
|
|
1324
1323
|
return result;
|
|
1325
1324
|
};
|
|
1326
1325
|
await handlePromptRequest({
|
|
1327
1326
|
projectRoot,
|
|
1328
1327
|
req,
|
|
1329
1328
|
socket,
|
|
1330
|
-
provider,
|
|
1331
|
-
model,
|
|
1332
|
-
processManager,
|
|
1333
|
-
runPromptWithAssistant,
|
|
1334
|
-
runUfooAgent,
|
|
1335
|
-
runUfooRouteAgent,
|
|
1336
|
-
selectExecutionPath,
|
|
1337
1329
|
runMainAgent: ({ originalPrompt, requestId, sessionId, requestMeta }) => mainAgentHost.runPrompt({ prompt: originalPrompt, requestId, sessionId, requestMeta }),
|
|
1338
|
-
runCompatibility: (request, invoke) => mainAgentHost.runCompatibility(request, invoke),
|
|
1339
|
-
dispatchMessages: (root, messages) => effect("prompt-dispatch", { root, messages }, () => dispatchMessages(root, messages, { strict: true })),
|
|
1340
|
-
handleOps: (root, ops, manager) => effect("prompt-ops", { root, ops }, () => handleRuntimeOps(root, ops, manager)),
|
|
1341
|
-
markPending: (target) => busBridge.markPending(target),
|
|
1342
|
-
reportTaskStatus: async (report) => {
|
|
1343
|
-
await recordAgentReport({
|
|
1344
|
-
projectRoot,
|
|
1345
|
-
report,
|
|
1346
|
-
onStatus: (status) => {
|
|
1347
|
-
ipcServer.sendToSockets({
|
|
1348
|
-
type: IPC_RESPONSE_TYPES.STATUS,
|
|
1349
|
-
data: status,
|
|
1350
|
-
});
|
|
1351
|
-
},
|
|
1352
|
-
log,
|
|
1353
|
-
});
|
|
1354
|
-
},
|
|
1355
1330
|
forwardProjectPrompt: async ({
|
|
1356
1331
|
targetProjectRoot,
|
|
1357
1332
|
targetProjectName,
|
|
@@ -1363,7 +1338,7 @@ function startDaemon({
|
|
|
1363
1338
|
if (!root) {
|
|
1364
1339
|
return { ok: false, error: "target project root is required" };
|
|
1365
1340
|
}
|
|
1366
|
-
return
|
|
1341
|
+
return forwardEffect({ root, prompt, requestMeta }, async () => {
|
|
1367
1342
|
if (!fs.existsSync(root)) {
|
|
1368
1343
|
return { ok: false, error: `target project not found: ${root}` };
|
|
1369
1344
|
}
|
|
@@ -1669,9 +1644,9 @@ function startDaemon({
|
|
|
1669
1644
|
: null,
|
|
1670
1645
|
};
|
|
1671
1646
|
let soloLaunchBootstrap = null;
|
|
1672
|
-
if (requestedProfile && (normalizedAgent === "
|
|
1673
|
-
const agentTypeMap = {
|
|
1674
|
-
const defaultNickMap = {
|
|
1647
|
+
if (requestedProfile && (normalizedAgent === "ucode" || normalizedAgent === "claude" || normalizedAgent === "codex" || normalizedAgent === "agy" || normalizedAgent === "grok" || normalizedAgent === "kimi")) {
|
|
1648
|
+
const agentTypeMap = { ucode: "ucode", claude: "claude-code", codex: "codex", agy: "agy", grok: "grok", kimi: "kimi" };
|
|
1649
|
+
const defaultNickMap = { ucode: "ucode", claude: "claude", codex: "codex", agy: "agy", grok: "grok", kimi: "kimi" };
|
|
1675
1650
|
const agentTypeForBootstrap = agentTypeMap[normalizedAgent];
|
|
1676
1651
|
const soloNickname = explicitNickname || defaultNickMap[normalizedAgent];
|
|
1677
1652
|
const profileResult = resolveSoloPromptProfile(projectRoot, requestedProfile);
|
|
@@ -1693,7 +1668,7 @@ function startDaemon({
|
|
|
1693
1668
|
});
|
|
1694
1669
|
if (built.required) {
|
|
1695
1670
|
try {
|
|
1696
|
-
if (normalizedAgent === "
|
|
1671
|
+
if (normalizedAgent === "ucode") {
|
|
1697
1672
|
// ucode: bootstrap via env var pointing to file
|
|
1698
1673
|
const prepared = prepareSoloUcodeBootstrap(projectRoot, soloNickname, built.promptText);
|
|
1699
1674
|
op.extra_env = {
|
|
@@ -2253,7 +2228,7 @@ function startDaemon({
|
|
|
2253
2228
|
if (req.type === IPC_REQUEST_TYPES.RESUME_AGENTS) {
|
|
2254
2229
|
const target = req.target || "";
|
|
2255
2230
|
try {
|
|
2256
|
-
const result = await resumeAgents(projectRoot, target, processManager);
|
|
2231
|
+
const result = await resumeAgents(projectRoot, target, processManager, { internalOnly: req.internal_only === true });
|
|
2257
2232
|
const resumedCount = result.resumed.length;
|
|
2258
2233
|
const skippedCount = result.skipped.length;
|
|
2259
2234
|
const reply = resumedCount > 0
|
|
@@ -2283,7 +2258,7 @@ function startDaemon({
|
|
|
2283
2258
|
if (req.type === IPC_REQUEST_TYPES.LIST_RECOVERABLE_AGENTS) {
|
|
2284
2259
|
const target = req.target || "";
|
|
2285
2260
|
try {
|
|
2286
|
-
const result = getRecoverableAgents(projectRoot, target);
|
|
2261
|
+
const result = getRecoverableAgents(projectRoot, target, { internalOnly: req.internal_only === true });
|
|
2287
2262
|
const count = result.recoverable.length;
|
|
2288
2263
|
const reply = count > 0 ? `Found ${count} recoverable agent(s)` : "No recoverable agents";
|
|
2289
2264
|
socket.write(
|
|
@@ -2488,7 +2463,7 @@ function startDaemon({
|
|
|
2488
2463
|
const runnerProcesses = [];
|
|
2489
2464
|
|
|
2490
2465
|
for (const line of lines) {
|
|
2491
|
-
if (line.includes("agent-
|
|
2466
|
+
if (line.includes("agent-runner")) {
|
|
2492
2467
|
const parts = line.trim().split(/\s+/);
|
|
2493
2468
|
if (parts.length >= 2) {
|
|
2494
2469
|
const pid = parseInt(parts[1], 10);
|
|
@@ -159,6 +159,8 @@ class GlobalMcpHttpServer {
|
|
|
159
159
|
this.activeRequests = new Map();
|
|
160
160
|
this.httpRequestCount = 0;
|
|
161
161
|
this.server = null;
|
|
162
|
+
this.startPromise = null;
|
|
163
|
+
this.stopPromise = null;
|
|
162
164
|
this.startedAt = "";
|
|
163
165
|
this.stopping = false;
|
|
164
166
|
}
|
|
@@ -358,33 +360,46 @@ class GlobalMcpHttpServer {
|
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
async start() {
|
|
363
|
+
if (this.stopPromise) await this.stopPromise;
|
|
361
364
|
if (this.server && this.server.listening) return this.getStatus();
|
|
365
|
+
if (this.startPromise) return this.startPromise;
|
|
366
|
+
const starting = this.startListener();
|
|
367
|
+
this.startPromise = starting;
|
|
368
|
+
try {
|
|
369
|
+
return await starting;
|
|
370
|
+
} finally {
|
|
371
|
+
this.startPromise = null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async startListener() {
|
|
362
376
|
if (this.host !== "127.0.0.1" && this.host !== "::1") {
|
|
363
377
|
const err = new Error(`MCP HTTP host must be loopback, got: ${this.host}`);
|
|
364
378
|
err.code = "UFOO_MCP_NON_LOOPBACK_HOST";
|
|
365
379
|
throw err;
|
|
366
380
|
}
|
|
367
381
|
this.token = this.token || loadOrCreateMcpToken(this.tokenPath);
|
|
368
|
-
|
|
382
|
+
const server = http.createServer((req, res) => {
|
|
369
383
|
void this.handleHttpRequest(req, res);
|
|
370
384
|
});
|
|
371
|
-
this.server
|
|
385
|
+
this.server = server;
|
|
386
|
+
server.on("clientError", (_err, socket) => {
|
|
372
387
|
if (socket.writable) socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
373
388
|
});
|
|
374
389
|
await new Promise((resolve, reject) => {
|
|
375
390
|
const onError = (err) => {
|
|
376
|
-
|
|
391
|
+
server.off("listening", onListening);
|
|
377
392
|
reject(err);
|
|
378
393
|
};
|
|
379
394
|
const onListening = () => {
|
|
380
|
-
|
|
395
|
+
server.off("error", onError);
|
|
381
396
|
resolve();
|
|
382
397
|
};
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
398
|
+
server.once("error", onError);
|
|
399
|
+
server.once("listening", onListening);
|
|
400
|
+
server.listen(this.port, this.host);
|
|
386
401
|
});
|
|
387
|
-
const address =
|
|
402
|
+
const address = server.address();
|
|
388
403
|
if (address && typeof address === "object") this.port = address.port;
|
|
389
404
|
this.startedAt = new Date().toISOString();
|
|
390
405
|
this.writeEndpointFile();
|
|
@@ -393,8 +408,23 @@ class GlobalMcpHttpServer {
|
|
|
393
408
|
}
|
|
394
409
|
|
|
395
410
|
async stop() {
|
|
396
|
-
if (this.
|
|
411
|
+
if (this.stopPromise) return this.stopPromise;
|
|
397
412
|
this.stopping = true;
|
|
413
|
+
const stopping = this.stopListener();
|
|
414
|
+
this.stopPromise = stopping;
|
|
415
|
+
try {
|
|
416
|
+
await stopping;
|
|
417
|
+
} finally {
|
|
418
|
+
this.stopPromise = null;
|
|
419
|
+
this.stopping = false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async stopListener() {
|
|
424
|
+
// Shutdown must wait for the listener and endpoint publication to settle.
|
|
425
|
+
// Otherwise a delayed listening event can access a cleared server or leave
|
|
426
|
+
// a live listener and stale endpoint after shutdown has already completed.
|
|
427
|
+
if (this.startPromise) await this.startPromise.catch(() => {});
|
|
398
428
|
const sessions = Array.from(this.sessions.values());
|
|
399
429
|
this.sessions.clear();
|
|
400
430
|
await Promise.allSettled(sessions.map(async ({ transport, protocolServer }) => {
|
|
@@ -419,7 +449,6 @@ class GlobalMcpHttpServer {
|
|
|
419
449
|
} catch {
|
|
420
450
|
// Best effort; a PID mismatch is still visible in status diagnostics.
|
|
421
451
|
}
|
|
422
|
-
this.stopping = false;
|
|
423
452
|
}
|
|
424
453
|
}
|
|
425
454
|
|
|
@@ -25,7 +25,7 @@ function normalizeAutoNicknamePrefix(agentType = "") {
|
|
|
25
25
|
if (normalized === "agy") return "agy";
|
|
26
26
|
if (normalized === "grok") return "grok";
|
|
27
27
|
if (normalized === "kimi" || normalized === "kimi-cli" || normalized === "kimi-code") return "kimi";
|
|
28
|
-
if (normalized === "
|
|
28
|
+
if (normalized === "ucode") return "ucode";
|
|
29
29
|
return "";
|
|
30
30
|
}
|
|
31
31
|
|