u-foo 4.0.0 → 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.
Files changed (154) hide show
  1. package/OBSERVABILITY.md +65 -0
  2. package/README.md +88 -30
  3. package/README.zh-CN.md +76 -26
  4. package/SKILLS/ufoo/SKILL.md +25 -1
  5. package/SKILLS/ufoo-bus/SKILL.md +25 -2
  6. package/bin/ufoo.js +3 -3
  7. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  8. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  9. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  10. package/dist/tui/linux-x64/ufoo-tui +0 -0
  11. package/package.json +6 -6
  12. package/src/agents/activity/activityDetector.js +1 -1
  13. package/src/agents/capabilities/agentManagement/service.js +40 -13
  14. package/src/agents/capabilities/coordination/index.js +1 -1
  15. package/src/agents/capabilities/taskReports/index.js +1 -1
  16. package/src/agents/controller/controllerToolExecutor.js +36 -20
  17. package/src/agents/controller/index.js +1 -6
  18. package/src/agents/internal/internalRunner.js +90 -56
  19. package/src/agents/launch/index.js +0 -1
  20. package/src/agents/launch/launcher.js +8 -8
  21. package/src/agents/launch/notifier.js +2 -2
  22. package/src/agents/launch/readyDetector.js +2 -2
  23. package/src/agents/profiles/main.js +1 -1
  24. package/src/agents/prompts/cooperation.js +14 -0
  25. package/src/agents/prompts/defaultBootstrap.js +1 -1
  26. package/src/agents/prompts/groupBootstrap.js +23 -7
  27. package/src/agents/prompts/mainAgent.js +11 -2
  28. package/src/agents/prompts/native/system.js +4 -1
  29. package/src/agents/prompts/native/ufoo.js +11 -3
  30. package/src/agents/prompts/promptProfiles.js +2 -0
  31. package/src/agents/prompts/reporting.js +16 -0
  32. package/src/agents/providers/claudeEventTranslator.js +3 -0
  33. package/src/agents/providers/claudeThreadProvider.js +3 -2
  34. package/src/agents/providers/clientIdentity.js +75 -0
  35. package/src/agents/providers/codexEventTranslator.js +23 -2
  36. package/src/agents/providers/codexThreadProvider.js +15 -6
  37. package/src/agents/providers/credentials/index.js +2 -0
  38. package/src/agents/providers/directAuthStatus.js +1 -1
  39. package/src/agents/providers/index.js +1 -1
  40. package/src/agents/providers/modelSettings.js +34 -0
  41. package/src/agents/providers/modelsCatalog.js +379 -0
  42. package/src/agents/providers/nativeTransport.js +50 -39
  43. package/src/agents/providers/runtimeConfig.js +10 -8
  44. package/src/agents/providers/thinkingLevels.js +10 -36
  45. package/src/agents/providers/transports/responsesProtocol.js +11 -6
  46. package/src/agents/providers/upstreamRuntime.js +135 -0
  47. package/src/agents/runtime/context/checkpointStore.js +38 -0
  48. package/src/agents/runtime/context/compaction.js +151 -0
  49. package/src/agents/runtime/context/contextBudget.js +93 -0
  50. package/src/agents/runtime/context/replayHistory.js +28 -0
  51. package/src/agents/runtime/context/runtimeStore.js +2 -1
  52. package/src/agents/runtime/core/agentLoop.js +99 -18
  53. package/src/agents/runtime/core/executionBudget.js +36 -0
  54. package/src/agents/runtime/createAgentRuntime.js +16 -4
  55. package/src/agents/runtime/prompts/responseLanguage.js +12 -0
  56. package/src/agents/runtime/protocol/runObservation.js +24 -0
  57. package/src/agents/runtime/protocol/traceContext.js +9 -0
  58. package/src/app/chat/ChatController.js +26 -53
  59. package/src/app/chat/agentDirectory.js +1 -16
  60. package/src/app/chat/bootstrap.js +1 -2
  61. package/src/app/chat/commandExecutor.js +93 -285
  62. package/src/app/chat/commands.js +32 -45
  63. package/src/app/chat/daemonMessageRouter.js +0 -45
  64. package/src/app/chat/historyStore.js +12 -48
  65. package/src/app/chat/inputSubmitHandler.js +7 -33
  66. package/src/app/chat/internalAgentLogHistory.js +19 -60
  67. package/src/app/chat/multiWindow/paneManager.js +10 -3
  68. package/src/app/chat/streamState.js +0 -4
  69. package/src/app/cli/features/init.js +5 -5
  70. package/src/app/cli/metricsCommands.js +68 -0
  71. package/src/app/cli/run.js +42 -3
  72. package/src/app/cli/traceCommands.js +36 -0
  73. package/src/code/agent.js +18 -13
  74. package/src/code/busConsumer.js +1 -3
  75. package/src/code/commands.js +1 -1
  76. package/src/code/context/assembler.js +7 -8
  77. package/src/code/context/stateCommit.js +2 -1
  78. package/src/code/internalThread.js +10 -3
  79. package/src/code/launcher/ucode.js +1 -1
  80. package/src/code/launcher/ucodeBootstrap.js +1 -1
  81. package/src/code/modelCommand.js +11 -35
  82. package/src/code/nativeRunner.js +55 -17
  83. package/src/code/providers/modelsCatalog.js +1 -317
  84. package/src/code/repl.js +2 -11
  85. package/src/code/sessionStore.js +3 -3
  86. package/src/code/taskDecomposer.js +18 -0
  87. package/src/code/toolBudget.js +1 -17
  88. package/src/config.js +22 -72
  89. package/src/coordination/bus/index.js +12 -3
  90. package/src/coordination/bus/inject.js +2 -2
  91. package/src/coordination/bus/message.js +15 -1
  92. package/src/coordination/bus/nickname.js +1 -1
  93. package/src/coordination/bus/subscriber.js +3 -2
  94. package/src/coordination/bus/utils.js +1 -1
  95. package/src/coordination/history/agentPerformance.js +279 -0
  96. package/src/coordination/history/agentTrace.js +249 -0
  97. package/src/coordination/state/workspaceAccess.js +1 -1
  98. package/src/orchestration/controller/index.js +1 -8
  99. package/src/orchestration/controller/launchRouting.js +1 -1
  100. package/src/orchestration/solo/commands.js +3 -1
  101. package/src/runtime/contracts/agentMode.js +11 -2
  102. package/src/runtime/contracts/uiProtocol.js +18 -19
  103. package/src/runtime/daemon/agentHost.js +57 -25
  104. package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
  105. package/src/runtime/daemon/busBridge.js +1 -1
  106. package/src/runtime/daemon/controlPlaneService.js +1 -1
  107. package/src/runtime/daemon/groupOrchestrator.js +20 -5
  108. package/src/runtime/daemon/groupStatus.js +20 -0
  109. package/src/runtime/daemon/index.js +19 -44
  110. package/src/runtime/daemon/mcpServer.js +1 -1
  111. package/src/runtime/daemon/nicknameScope.js +1 -1
  112. package/src/runtime/daemon/ops.js +46 -23
  113. package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
  114. package/src/runtime/daemon/promptRequest.js +92 -589
  115. package/src/runtime/daemon/status.js +5 -6
  116. package/src/tools/controllerSchemas.js +6 -2
  117. package/src/tools/handlers/tier2.js +4 -2
  118. package/src/tools/registry.js +4 -0
  119. package/src/tools/schemaFixtures.js +26 -2
  120. package/src/tools/tier0/readAgentMetrics.js +14 -0
  121. package/src/tools/tier0/readAgentTrace.js +12 -0
  122. package/src/ui/agentSettingsController.js +107 -0
  123. package/src/ui/agentSurface.js +1 -1
  124. package/src/ui/dashboardBridge.js +1 -1
  125. package/src/ui/format/banner.js +1 -4
  126. package/src/ui/format/index.js +14 -10
  127. package/src/ui/format/loopSummary.js +50 -0
  128. package/src/ui/format/markdownRenderer.js +3 -4
  129. package/src/ui/rustChatHost.js +191 -206
  130. package/src/ui/rustMultiSession.js +77 -36
  131. package/src/ui/rustUcodeHost.js +1 -1
  132. package/src/ui/settingsBridge.js +33 -16
  133. package/src/ui/toolMergeBridge.js +0 -4
  134. package/src/ui/uiHostServer.js +5 -8
  135. package/src/agents/controller/loopObservability.js +0 -200
  136. package/src/agents/controller/loopRuntime.js +0 -336
  137. package/src/agents/controller/ufooAgent.js +0 -830
  138. package/src/agents/launch/ptyRunner.js +0 -1135
  139. package/src/agents/providers/controllerJsonTransport.js +0 -28
  140. package/src/agents/providers/upstreamTransport.js +0 -698
  141. package/src/app/chat/agentBar.js +0 -135
  142. package/src/app/chat/agentSockets.js +0 -225
  143. package/src/app/chat/dashboardView.js +0 -405
  144. package/src/app/chat/rawKeyMap.js +0 -42
  145. package/src/app/chat/settingsController.js +0 -111
  146. package/src/coordination/history/controllerSummary.js +0 -23
  147. package/src/orchestration/controller/flags.js +0 -167
  148. package/src/orchestration/controller/gateRouter.js +0 -211
  149. package/src/orchestration/controller/routerFastPath.js +0 -22
  150. package/src/orchestration/controller/routerFinalize.js +0 -222
  151. package/src/orchestration/controller/shadowGuard.js +0 -280
  152. package/src/runtime/daemon/executionPaths.js +0 -30
  153. package/src/runtime/daemon/promptLoop.js +0 -136
  154. 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" ? "ufoo-code" : "claude-code");
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" || value === "ufoo") return "ufoo-code";
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 groups = listGroupStates(projectRoot).map((runtime) => summarizeGroup(runtime));
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 === "ufoo" || value === "ucode" || value === "ufoo-code") return "ufoo-code";
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 === "ufoo" || value === "ucode" || value === "ufoo-code") return "ufoo";
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
- let effectIndex = 0;
1321
- const effect = async (kind, args, invoke) => {
1322
- const result = await mainAgentHost.management.commands.execute({ commandId: `prompt-${require("crypto").createHash("sha256").update(`${req.request_id}:${effectIndex++}`).digest("hex").slice(0, 32)}`, kind, args }, invoke);
1323
- if (result?.code === "uncertain_effect") throw Object.assign(new Error("effect outcome is unknown; inspect its receipt before retrying"), { code: "uncertain_effect" });
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 effect("project-forward", { root, prompt, requestMeta }, async () => {
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 === "ufoo" || normalizedAgent === "claude" || normalizedAgent === "codex" || normalizedAgent === "agy" || normalizedAgent === "grok" || normalizedAgent === "kimi")) {
1673
- const agentTypeMap = { ufoo: "ufoo-code", claude: "claude-code", codex: "codex", agy: "agy", grok: "grok", kimi: "kimi" };
1674
- const defaultNickMap = { ufoo: "ucode", claude: "claude", codex: "codex", agy: "agy", grok: "grok", kimi: "kimi" };
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 === "ufoo") {
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-pty-runner") || line.includes("agent-runner")) {
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);
@@ -408,7 +408,7 @@ async function ensureGlobalControllerDaemon(options = {}) {
408
408
  await suppressConsoleToStderr(() => init.init({
409
409
  targets: "context,bus",
410
410
  project: root,
411
- controllerMode: true,
411
+ globalController: true,
412
412
  }));
413
413
  }
414
414
 
@@ -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 === "ufoo" || normalized === "ucode" || normalized === "ufoo-code") return "ucode";
28
+ if (normalized === "ucode") return "ucode";
29
29
  return "";
30
30
  }
31
31
 
@@ -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 === "ufoo" || value === "ucode" || value === "ufoo-code") return "ufoo";
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 === "ufoo") return "ufoo-code";
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 === "ufoo") return "ucode";
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 === "ufoo") return "ucode";
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 === "ufoo-code") {
65
+ if (!agentType || agentType === "ucode") {
64
66
  return {
65
67
  args: Array.isArray(args) ? args.slice() : [],
66
68
  extraEnv: extraEnv && typeof extraEnv === "object" ? { ...extraEnv } : {},
@@ -606,7 +608,7 @@ async function spawnManagedHostAgent(
606
608
  if (bus.subscriberManager) {
607
609
  const sessionToken = crypto.randomBytes(4).toString("hex");
608
610
  subscriberId = `${agentType}:${sessionToken}`;
609
- const defaultNickname = agentType === "ufoo-code" ? "ucode" : normalizedAgent;
611
+ const defaultNickname = normalizedAgent;
610
612
  const finalNickname = nickname || defaultNickname;
611
613
  const registration = await require("./controlPlaneService").registerAgentFull(projectRoot, {
612
614
  sessionId: sessionToken, agentType, nickname: finalNickname, launchMode: "host",
@@ -686,6 +688,7 @@ async function spawnInternalAgent(
686
688
  extraArgs = [],
687
689
  options = {}
688
690
  ) {
691
+ if (!normalizeInternalAgentType(agent)) throw new Error(`unsupported internal agent type: ${agent}; use codex, claude or ucode`);
689
692
  const runner = resolveUfooRunnerPath();
690
693
  const logDir = getUfooPaths(projectRoot).runDir;
691
694
  fs.mkdirSync(logDir, { recursive: true });
@@ -989,6 +992,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
989
992
  }
990
993
 
991
994
  if (mode === "internal") {
995
+ if (!normalizeInternalAgentType(normalizedAgent)) throw new Error(`unsupported internal agent type: ${agent}; use codex, claude or ucode`);
992
996
  const result = await spawnInternalAgent(
993
997
  projectRoot,
994
998
  normalizedAgent,
@@ -1038,8 +1042,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
1038
1042
  && tmuxLayoutContext
1039
1043
  && tmuxLayoutContext.mode === "group-right-column";
1040
1044
  for (let i = 0; i < count; i += 1) {
1041
- // Use "ucode" as default nickname for ufoo/ucode agents
1042
- const defaultNick = normalizedAgent === "ufoo" ? "ucode" : normalizedAgent;
1045
+ const defaultNick = normalizedAgent;
1043
1046
  const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
1044
1047
  if (useSeparateWindow) {
1045
1048
  // eslint-disable-next-line no-await-in-loop
@@ -1086,7 +1089,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
1086
1089
  const subscriberIds = [];
1087
1090
  const hostContext = resolveHostLaunchContext(options);
1088
1091
  for (let i = 0; i < count; i += 1) {
1089
- const defaultNick = normalizedAgent === "ufoo" ? "ucode" : normalizedAgent;
1092
+ const defaultNick = normalizedAgent;
1090
1093
  const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
1091
1094
  // eslint-disable-next-line no-await-in-loop
1092
1095
  const result = await spawnManagedHostAgent(
@@ -1109,8 +1112,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
1109
1112
 
1110
1113
  const subscriberIds = [];
1111
1114
  for (let i = 0; i < count; i += 1) {
1112
- // Use "ucode" as default nickname for ufoo/ucode agents
1113
- const defaultNick = normalizedAgent === "ufoo" ? "ucode" : normalizedAgent;
1115
+ const defaultNick = normalizedAgent;
1114
1116
  const nick = count > 1 ? `${nickname || defaultNick}-${i + 1}` : (nickname || "");
1115
1117
  // eslint-disable-next-line no-await-in-loop
1116
1118
  const result = await spawnManagedTerminalAgent(
@@ -1133,7 +1135,7 @@ function normalizeAgentType(agentType) {
1133
1135
  if (agentType === "claude-code") return "claude";
1134
1136
  if (agentType === "codex") return "codex";
1135
1137
  if (agentType === "grok") return "grok";
1136
- if (agentType === "ufoo-code") return "ufoo";
1138
+ if (agentType === "ucode") return "ucode";
1137
1139
  return agentType;
1138
1140
  }
1139
1141
 
@@ -1147,6 +1149,7 @@ function buildResumeArgs(agent, sessionId) {
1147
1149
  if (agent === "grok") return ["--resume", sessionId];
1148
1150
  // kimi resumes a session by id via `-S, --session <id>`.
1149
1151
  if (agent === "kimi") return ["--session", sessionId];
1152
+ if (agent === "ucode") return ["--session-id", sessionId];
1150
1153
  return [];
1151
1154
  }
1152
1155
 
@@ -1156,17 +1159,23 @@ function isActiveAgent(meta) {
1156
1159
  return true;
1157
1160
  }
1158
1161
 
1159
- function collectRecoverableAgents(projectRoot, target = "") {
1162
+ function collectRecoverableAgents(projectRoot, target = "", options = {}) {
1160
1163
  const config = loadConfig(projectRoot);
1161
1164
  const mode = config.launchMode || "terminal";
1162
1165
  const filePath = getUfooPaths(projectRoot).agentsFile;
1163
1166
  const data = loadAgentsData(filePath);
1164
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)]));
1165
1170
 
1166
1171
  let targets = entries;
1167
1172
  if (target) {
1168
1173
  const scopedTarget = applyProjectNicknamePrefix(projectRoot, target);
1169
- if (target.includes(":")) {
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(":")) {
1170
1179
  targets = entries.filter(([id]) => id === target);
1171
1180
  } else {
1172
1181
  targets = entries.filter(([id, meta]) =>
@@ -1190,6 +1199,10 @@ function collectRecoverableAgents(projectRoot, target = "") {
1190
1199
  }
1191
1200
 
1192
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
+ }
1193
1206
  if (!meta || !meta.provider_session_id) {
1194
1207
  skipped.push({ id, reason: "no provider session" });
1195
1208
  continue;
@@ -1199,12 +1212,12 @@ function collectRecoverableAgents(projectRoot, target = "") {
1199
1212
  continue;
1200
1213
  }
1201
1214
  const agent = normalizeAgentType(meta.agent_type);
1202
- 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") {
1203
1216
  skipped.push({ id, reason: "unsupported agent type" });
1204
1217
  continue;
1205
1218
  }
1206
1219
 
1207
- recoverableEntries.push({ id, meta, agent });
1220
+ recoverableEntries.push({ id, meta, agent, association: associations.get(id) });
1208
1221
  }
1209
1222
 
1210
1223
  return {
@@ -1215,8 +1228,8 @@ function collectRecoverableAgents(projectRoot, target = "") {
1215
1228
  };
1216
1229
  }
1217
1230
 
1218
- function getRecoverableAgents(projectRoot, target = "") {
1219
- const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target);
1231
+ function getRecoverableAgents(projectRoot, target = "", options = {}) {
1232
+ const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target, options);
1220
1233
  const recoverable = recoverableEntries.map((item) => ({
1221
1234
  id: item.id,
1222
1235
  nickname: resolveDisplayNickname(projectRoot, item.meta),
@@ -1225,12 +1238,19 @@ function getRecoverableAgents(projectRoot, target = "") {
1225
1238
  sessionId: item.meta.provider_session_id || "",
1226
1239
  launchMode: item.meta.launch_mode || "",
1227
1240
  lastSeen: item.meta.last_seen || "",
1241
+ ...item.association,
1228
1242
  }));
1229
- return { ok: true, mode, recoverable, skipped };
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 };
1230
1250
  }
1231
1251
 
1232
- async function resumeAgents(projectRoot, target = "", processManager = null) {
1233
- const { mode, data, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target);
1252
+ async function resumeAgents(projectRoot, target = "", processManager = null, options = {}) {
1253
+ const { mode, recoverableEntries, skipped } = collectRecoverableAgents(projectRoot, target, options);
1234
1254
 
1235
1255
  if (recoverableEntries.length === 0) {
1236
1256
  return { ok: true, resumed: [], skipped };
@@ -1243,7 +1263,7 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
1243
1263
  const args = buildResumeArgs(item.agent, sessionId);
1244
1264
  let reused = false;
1245
1265
  let resumedId = item.id;
1246
- if (mode === "internal") {
1266
+ if (options.internalOnly || isInternalAgentMeta(item.meta) || mode === "internal") {
1247
1267
  // Internal agents have no terminal/pane to reattach. Start a fresh
1248
1268
  // daemon-managed runner and replace the old recoverable registration.
1249
1269
  // The provider session is still reused via the normal provider args.
@@ -1254,13 +1274,15 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
1254
1274
  1,
1255
1275
  nickname,
1256
1276
  processManager,
1257
- { UFOO_SKIP_SESSION_RESOLVE: "1" },
1277
+ { UFOO_SKIP_SESSION_RESOLVE: "1", UFOO_SCOPED_NICKNAME: item.meta.scoped_nickname || "" },
1258
1278
  args,
1259
1279
  { replaceAgentId: item.id, providerSessionId: sessionId }
1260
1280
  );
1261
1281
  resumedId = launchResult.subscriberIds && launchResult.subscriberIds[0]
1262
1282
  ? launchResult.subscriberIds[0]
1263
1283
  : item.id;
1284
+ associateAgentWithGroup(projectRoot, resumedId, item.association);
1285
+ recordGroupMemberResume(projectRoot, item.association, item.id, resumedId);
1264
1286
  } else {
1265
1287
  reused = await tryReuseTerminal(projectRoot, item.id, item.meta, item.agent, sessionId);
1266
1288
  if (!reused) {
@@ -1281,6 +1303,7 @@ async function resumeAgents(projectRoot, target = "", processManager = null) {
1281
1303
  agent: item.agent,
1282
1304
  sessionId,
1283
1305
  reused,
1306
+ ...item.association,
1284
1307
  });
1285
1308
  }
1286
1309
 
@@ -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",