u-foo 4.0.3 → 4.0.10

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 (160) hide show
  1. package/README.md +239 -19
  2. package/README.zh-CN.md +3 -3
  3. package/bin/ucode.js +10 -2
  4. package/bin/ufoo.js +3 -0
  5. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  6. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  7. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  8. package/dist/tui/linux-x64/ufoo-tui +0 -0
  9. package/{OBSERVABILITY.md → docs/OBSERVABILITY.md} +3 -3
  10. package/docs/README.md +27 -0
  11. package/extensions/ufoo-browser/LICENSE +152 -0
  12. package/extensions/ufoo-browser/NOTICE +10 -0
  13. package/extensions/ufoo-browser/README.md +30 -0
  14. package/extensions/ufoo-browser/background.js +409 -0
  15. package/extensions/ufoo-browser/icons/icon-128.png +0 -0
  16. package/extensions/ufoo-browser/icons/icon-16.png +0 -0
  17. package/extensions/ufoo-browser/icons/icon-256.png +0 -0
  18. package/extensions/ufoo-browser/icons/icon-32.png +0 -0
  19. package/extensions/ufoo-browser/icons/icon-48.png +0 -0
  20. package/extensions/ufoo-browser/icons/logo.png +0 -0
  21. package/extensions/ufoo-browser/icons/toolbar-16.png +0 -0
  22. package/extensions/ufoo-browser/icons/toolbar-32.png +0 -0
  23. package/extensions/ufoo-browser/icons/toolbar-logo.png +0 -0
  24. package/extensions/ufoo-browser/manifest.json +30 -0
  25. package/extensions/ufoo-browser/popup.css +71 -0
  26. package/extensions/ufoo-browser/popup.html +44 -0
  27. package/extensions/ufoo-browser/popup.js +153 -0
  28. package/package.json +7 -5
  29. package/scripts/postinstall.js +6 -0
  30. package/src/agents/capabilities/browser/index.js +49 -0
  31. package/src/agents/capabilities/coding/backgroundHooks.js +94 -0
  32. package/src/agents/capabilities/coding/index.js +30 -1
  33. package/src/agents/capabilities/index.js +5 -2
  34. package/src/agents/capabilities/planning/index.js +44 -5
  35. package/src/agents/capabilities/turnRecall/index.js +341 -0
  36. package/src/agents/controller/controllerToolExecutor.js +2 -2
  37. package/src/agents/internal/internalRunner.js +30 -8
  38. package/src/agents/internal/taskControl.js +107 -0
  39. package/src/agents/profiles/coding.js +1 -1
  40. package/src/agents/profiles/main.js +1 -1
  41. package/src/agents/prompts/mainAgent.js +1 -0
  42. package/src/agents/prompts/native/toolDescriptions/bash.js +7 -1
  43. package/src/agents/providers/claudeSessionFiles.js +1 -1
  44. package/src/agents/providers/codexThreadProvider.js +6 -1
  45. package/src/agents/providers/credentials/agy.js +171 -0
  46. package/src/agents/providers/directAuthStatus.js +20 -2
  47. package/src/agents/providers/modelsCatalog.js +26 -5
  48. package/src/agents/providers/nativeTransport.js +145 -73
  49. package/src/agents/providers/providerId.js +17 -0
  50. package/src/agents/providers/runtimeConfig.js +67 -20
  51. package/src/agents/providers/transports/antigravityTransport.js +242 -0
  52. package/src/agents/providers/transports/index.js +1 -0
  53. package/src/agents/providers/transports/openaiChatTransport.js +3 -2
  54. package/src/agents/providers/transports/openaiResponsesTransport.js +2 -1
  55. package/src/agents/providers/transports/responsesProtocol.js +119 -18
  56. package/src/agents/providers/transports/transportContract.js +1 -0
  57. package/src/agents/providers/upstreamRuntime.js +3 -1
  58. package/src/agents/runtime/context/contextBudget.js +1 -19
  59. package/src/agents/runtime/context/contextWindow.js +5 -0
  60. package/src/agents/runtime/context/replayHistory.js +16 -10
  61. package/src/agents/runtime/context/runtimeStore.js +0 -1
  62. package/src/agents/runtime/context/sessionJournal.js +1 -1
  63. package/src/agents/runtime/context/slidingWindowManager.js +792 -0
  64. package/src/agents/runtime/context/topicSelector.js +338 -0
  65. package/src/agents/runtime/context/turnAnalyzer.js +767 -0
  66. package/src/agents/runtime/context/turnIndexStore.js +515 -0
  67. package/src/agents/runtime/core/agentLoop.js +140 -35
  68. package/src/agents/runtime/core/executionBudget.js +2 -1
  69. package/src/agents/runtime/core/toolErrorGuard.js +39 -0
  70. package/src/agents/runtime/createAgentRuntime.js +80 -7
  71. package/src/agents/runtime/index.js +5 -0
  72. package/src/agents/runtime/protocol/materialize.js +1 -1
  73. package/src/agents/runtime/tasks/hooks.js +137 -0
  74. package/src/app/chat/ChatController.js +8 -4
  75. package/src/app/chat/daemonMessageRouter.js +3 -1
  76. package/src/app/chat/inputSubmitHandler.js +2 -2
  77. package/src/app/chat/transport.js +1 -1
  78. package/src/app/cli/browserCommands.js +340 -0
  79. package/src/app/cli/busCoreCommands.js +63 -3
  80. package/src/app/cli/features/doctor.js +21 -0
  81. package/src/app/cli/metricsCommands.js +1 -1
  82. package/src/app/cli/run.js +81 -1
  83. package/src/app/cli/setupCommands.js +200 -0
  84. package/src/code/UcodeController.js +31 -1
  85. package/src/code/agent.js +76 -25
  86. package/src/code/busConsumer.js +13 -12
  87. package/src/code/commands.js +0 -1
  88. package/src/code/context/assembler.js +11 -88
  89. package/src/code/context/planGraphService.js +121 -6
  90. package/src/code/context/planProjection.js +10 -2
  91. package/src/code/context/reducers.js +172 -4
  92. package/src/code/context/stateCommit.js +0 -32
  93. package/src/code/context/transcript.js +7 -4
  94. package/src/code/internalThread.js +9 -1
  95. package/src/code/launcher/ucode.js +4 -2
  96. package/src/code/modelCommand.js +6 -5
  97. package/src/code/nativeRunner.js +232 -62
  98. package/src/code/repl.js +27 -1
  99. package/src/code/runtime/agentWakeup.js +20 -3
  100. package/src/code/runtime/backgroundWakeHost.js +45 -0
  101. package/src/code/runtime/taskFocusContext.js +7 -0
  102. package/src/code/runtime/taskLoop.js +24 -1
  103. package/src/code/sessionStore.js +14 -10
  104. package/src/code/taskDecomposer.js +16 -7
  105. package/src/code/tools/backgroundProcess.js +23 -0
  106. package/src/code/tools/bash.js +764 -12
  107. package/src/code/tools/executor.js +13 -4
  108. package/src/code/tools/planGraph.js +1 -0
  109. package/src/code/tools/specs.js +62 -4
  110. package/src/code/tools/taskRun.js +38 -0
  111. package/src/config.js +92 -6
  112. package/src/coordination/bus/index.js +2 -2
  113. package/src/coordination/bus/message.js +10 -1
  114. package/src/coordination/bus/nickname.js +3 -1
  115. package/src/coordination/bus/subscriber.js +25 -10
  116. package/src/coordination/bus/utils.js +4 -0
  117. package/src/coordination/bus/wakeEndpoint.js +198 -0
  118. package/src/coordination/history/agentPerformance.js +18 -18
  119. package/src/coordination/history/agentTrace.js +7 -3
  120. package/src/coordination/state/paths.js +4 -0
  121. package/src/coordination/state/workspaceAccess.js +3 -1
  122. package/src/orchestration/groups/modelConfig.js +66 -0
  123. package/src/orchestration/groups/validateTemplate.js +2 -0
  124. package/src/runtime/browser/broker.js +1027 -0
  125. package/src/runtime/browser/brokerClient.js +108 -0
  126. package/src/runtime/browser/componentInstaller.js +275 -0
  127. package/src/runtime/browser/installState.js +329 -0
  128. package/src/runtime/browser/manifest.js +145 -0
  129. package/src/runtime/browser/native-host-runner.js +198 -0
  130. package/src/runtime/browser/nativeHost.js +213 -0
  131. package/src/runtime/browser/nativeMessagingProtocol.js +50 -0
  132. package/src/runtime/browser/paths.js +134 -0
  133. package/src/runtime/browser/playwrightSession.js +614 -0
  134. package/src/runtime/daemon/agentHost.js +175 -28
  135. package/src/runtime/daemon/busBridge.js +2 -1
  136. package/src/runtime/daemon/deliveryScheduler.js +70 -2
  137. package/src/runtime/daemon/globalDaemon.js +20 -0
  138. package/src/runtime/daemon/groupOrchestrator.js +20 -1
  139. package/src/runtime/daemon/index.js +6 -4
  140. package/src/runtime/daemon/ops.js +14 -8
  141. package/src/tools/handlers/listAgents.js +1 -1
  142. package/src/tools/handlers/readBusSummary.js +1 -1
  143. package/src/tools/handlers/routeAgent.js +122 -5
  144. package/src/tools/schemaFixtures.js +1 -1
  145. package/src/ui/agentSurface.js +60 -6
  146. package/src/ui/format/index.js +34 -2
  147. package/src/ui/format/markdownRenderer.js +4 -2
  148. package/src/ui/rustChatHost.js +22 -7
  149. package/src/ui/rustMultiSession.js +14 -2
  150. package/src/ui/rustUcodeHost.js +249 -80
  151. package/src/ui/ucodeAgentSession.js +88 -0
  152. package/templates/groups/build-lane.json +57 -3
  153. package/templates/groups/build-ultra.json +114 -6
  154. package/templates/groups/design-system.json +57 -3
  155. package/templates/groups/product-discovery.json +57 -3
  156. package/templates/groups/ui-plan-review.json +57 -3
  157. package/templates/groups/ui-polish.json +57 -3
  158. package/templates/groups/verify-ship.json +57 -3
  159. package/src/agents/runtime/context/checkpointStore.js +0 -38
  160. package/src/agents/runtime/context/compaction.js +0 -151
@@ -17,8 +17,15 @@ function writerLease(options) {
17
17
  return { lease: createResourceLease({ file: path.join(workspaceRoot, ".ufoo", "agent", "runtime", "workspace-leases.json") }),
18
18
  key: workspaceRoot, ownerId: options.taskRunId || options.sessionId || `process-${process.pid}` };
19
19
  }
20
+ function isReadOnlyBashCall(tool, args) {
21
+ if (normalizeToolName(tool) !== "bash") return false;
22
+ const action = String((args && args.action) || "").trim().toLowerCase();
23
+ return action === "logs" || action === "status" || action === "list";
24
+ }
20
25
  function runCoreTool(options = {}) {
21
- if (!["write", "edit", "bash"].includes(normalizeToolName(options.tool))) return runCoreToolUnlocked(options);
26
+ if (!["write", "edit", "bash"].includes(normalizeToolName(options.tool)) || isReadOnlyBashCall(options.tool, options.args)) {
27
+ return runCoreToolUnlocked(options);
28
+ }
22
29
  const { lease, key, ownerId } = writerLease(options);
23
30
  const acquired = lease.acquire({ key, ownerId });
24
31
  if (!acquired.ok) return { ...acquired, error: "workspace writer is active" };
@@ -109,6 +116,7 @@ function runCoreToolUnlocked({
109
116
  const result = runPlanGraphCommand(safeArgs, {
110
117
  executionState: state,
111
118
  autoAdvance: true,
119
+ validateToolArgs: true,
112
120
  parallel: true,
113
121
  runTool: ({ node, args: nestedArgs, tool: nestedTool, stepId }) => {
114
122
  const nested = runCoreTool({
@@ -228,7 +236,7 @@ function runCoreToolUnlocked({
228
236
 
229
237
  const toolOptions = { workspaceRoot, cwd: workspaceRoot };
230
238
  if (artifactNamespace !== "ucode") toolOptions.artifactNamespace = artifactNamespace;
231
- if (normalizedTool === "artifact_read" && sessionId) {
239
+ if ((normalizedTool === "artifact_read" || (normalizedTool === "bash" && safeArgs.background)) && sessionId) {
232
240
  toolOptions.sessionId = sessionId;
233
241
  }
234
242
  const result = runToolCall(
@@ -282,7 +290,7 @@ function runCoreToolUnlocked({
282
290
  * dispatcher so bash can terminate on the caller's AbortSignal.
283
291
  */
284
292
  async function runCoreToolAsync(options = {}) {
285
- if (["write", "edit", "bash"].includes(normalizeToolName(options.tool))) {
293
+ if (["write", "edit", "bash"].includes(normalizeToolName(options.tool)) && !isReadOnlyBashCall(options.tool, options.args)) {
286
294
  const { lease, key, ownerId } = writerLease(options);
287
295
  return lease.run({ key, ownerId, signal: options.signal }, () => runCoreToolAsyncUnlocked(options));
288
296
  }
@@ -319,10 +327,11 @@ async function runCoreToolAsyncUnlocked(options = {}) {
319
327
  const toolOptions = {
320
328
  workspaceRoot,
321
329
  cwd: workspaceRoot,
330
+ ...(options.backgroundId ? { backgroundId: options.backgroundId } : {}),
322
331
  };
323
332
  if (artifactNamespace !== "ucode") toolOptions.artifactNamespace = artifactNamespace;
324
333
  if (signal) toolOptions.signal = signal;
325
- if (normalizedTool === "artifact_read" && sessionId) {
334
+ if ((normalizedTool === "artifact_read" || (normalizedTool === "bash" && safeArgs.background)) && sessionId) {
326
335
  toolOptions.sessionId = sessionId;
327
336
  }
328
337
  const result = await runToolCallAsync(
@@ -14,6 +14,7 @@ function runPlanGraphTool(args = {}, options = {}) {
14
14
  parallel: options.parallel !== false,
15
15
  knownTools: options.knownTools,
16
16
  maxNodeRuns: options.maxNodeRuns,
17
+ validateToolArgs: true,
17
18
  });
18
19
 
19
20
  const payload = result.modelPayload || result;
@@ -88,10 +88,67 @@ function buildCoreToolSpecs() {
88
88
  parameters: {
89
89
  type: "object",
90
90
  properties: {
91
- command: { type: "string" },
92
- timeoutMs: { type: "integer" },
91
+ command: {
92
+ type: "string",
93
+ description: "Shell command to execute when action is \"run\" (default).",
94
+ },
95
+ timeoutMs: {
96
+ type: "integer",
97
+ description: "Foreground command timeout in milliseconds (default 60000, max 600000).",
98
+ },
99
+ background: {
100
+ type: "boolean",
101
+ description: "Set true to start a long-running background process (dev server, watcher) detached from the foreground turn.",
102
+ },
103
+ startupWaitMs: {
104
+ type: "integer",
105
+ description: "When background=true, milliseconds to wait for initial startup logs or early exit (default 2500, max 15000).",
106
+ },
107
+ wake: {
108
+ type: "object",
109
+ description: "Background runtime notifications. Exit notification defaults to true on supported native hosts. Each condition fires once, without model polling. Only valid when starting a background command.",
110
+ additionalProperties: false,
111
+ properties: {
112
+ onExit: { type: "boolean", description: "Notify once on command exit (default true)." },
113
+ timeoutMs: { type: "integer", minimum: 100, maximum: 43200000, description: "Subscription lifetime; default 12 hours. Expiry notifies once without killing the process." },
114
+ conditions: { type: "array", maxItems: 8, items: {
115
+ type: "object", additionalProperties: false, required: ["type"],
116
+ properties: {
117
+ type: { type: "string", enum: ["log_contains", "file_exists", "port_open"] },
118
+ text: { type: "string", description: "Literal log substring for log_contains; at most 1024 bytes." },
119
+ path: { type: "string", description: "Workspace path for file_exists." },
120
+ port: { type: "integer", minimum: 1, maximum: 65535, description: "Local IPv4 loopback port for port_open." },
121
+ },
122
+ } },
123
+ },
124
+ },
125
+ action: {
126
+ type: "string",
127
+ enum: ["run", "logs", "status", "list", "stop"],
128
+ description: "Operation mode: \"run\" (default) executes command; \"logs\" reads background output; \"status\" checks process state; \"list\" lists background processes; \"stop\" terminates a background process.",
129
+ },
130
+ backgroundId: {
131
+ type: "string",
132
+ description: "Background process ID returned when starting with background=true. Required for logs, status, and stop.",
133
+ },
134
+ offset: {
135
+ type: "integer",
136
+ description: "Byte offset for incremental log reads with action=\"logs\" (pass previous nextOffset to read only newly appended output).",
137
+ },
138
+ tailLines: {
139
+ type: "integer",
140
+ description: "Number of recent log lines to return when offset is omitted (default 80, max 500).",
141
+ },
142
+ maxBytes: {
143
+ type: "integer",
144
+ description: "Maximum log bytes to read in one call (default 32768, max 200000).",
145
+ },
146
+ waitMs: {
147
+ type: "integer",
148
+ description: "Optional milliseconds to wait for new log output when action=\"logs\" and process is running (default 0, max 10000).",
149
+ },
93
150
  },
94
- required: ["command"],
151
+ required: [],
95
152
  },
96
153
  },
97
154
  },
@@ -152,13 +209,14 @@ function buildCoreToolSpecs() {
152
209
  },
153
210
  graph: {
154
211
  type: "object",
155
- description: "Full graph for create (objective + nodes). group is input sugar only.",
212
+ description: 'Full graph for create (objective + nodes). Tool nodes use {id,type:"tool",tool,args:{...}}; tool parameters belong in args. group is input sugar only.',
156
213
  },
157
214
  operations: {
158
215
  type: "array",
159
216
  description: [
160
217
  "Patch ops only: add_node, expand_node, add_dependency, remove_dependency.",
161
218
  "Status actions (complete_task, skip_node, cancel_subtree) belong under control.actions.",
219
+ 'Tool children use {id,type:"tool",tool:"read",args:{path:"AGENTS.md"}}. Use args, not arguments.',
162
220
  ].join(" "),
163
221
  items: { type: "object" },
164
222
  },
@@ -105,6 +105,44 @@ function runTaskRunTool(args = {}, options = {}) {
105
105
  }
106
106
 
107
107
  const ok = payload && payload.ok !== false && payload.status !== "rejected";
108
+ if (
109
+ ok
110
+ && (operation === "complete" || operation === "cancel" || operation === "fail")
111
+ && options.autoAdvance !== false
112
+ && typeof runTool === "function"
113
+ && executionState.planGraph
114
+ && executionState.planGraph.graphId
115
+ ) {
116
+ const {
117
+ advanceStoredGraph,
118
+ finalizeTerminalPrimaryPlan,
119
+ } = require("../context/planGraphService");
120
+ const advanced = advanceStoredGraph(executionState.planGraph, {
121
+ knownTools,
122
+ runTool,
123
+ parallel: options.parallel !== false,
124
+ maxNodeRuns: options.maxNodeRuns,
125
+ });
126
+ if (advanced && advanced.planGraph) {
127
+ executionState.planGraph = {
128
+ ...advanced.planGraph,
129
+ commandLog: executionState.planGraph.commandLog || {},
130
+ };
131
+ }
132
+ const terminal = finalizeTerminalPrimaryPlan(
133
+ executionState,
134
+ executionState.planGraph,
135
+ advanced ? advanced.advance : null,
136
+ );
137
+ if (terminal) {
138
+ payload = {
139
+ ...payload,
140
+ planCompleted: true,
141
+ archivedGraphId: terminal.archivedGraphId,
142
+ completionSummary: terminal.completionSummary,
143
+ };
144
+ }
145
+ }
108
146
  return {
109
147
  ok,
110
148
  ...payload,
package/src/config.js CHANGED
@@ -7,6 +7,7 @@ const { writeFileAtomic } = require("./coordination/bus/utils");
7
7
  const UCODE_FIELDS = [
8
8
  "ucodeProvider",
9
9
  "ucodeModel",
10
+ "ucodeAuxModel",
10
11
  "ucodeBaseUrl",
11
12
  "ucodeApiKey",
12
13
  "ucodeAgentDir",
@@ -17,16 +18,19 @@ const SETTINGS_MODEL_DEFAULTS = Object.freeze({
17
18
  agent: Object.freeze({
18
19
  codex: "gpt-6.1-sol",
19
20
  claude: "claude-opus-5-5",
20
- // agy (Antigravity CLI) only supports model selection via in-REPL
21
- // `/model` slash command, which persists across launches. There is no
22
- // command-line flag for model, so the value here is a placeholder for
23
- // display; we never pass it on the agy command line.
24
- agy: "",
21
+ agy: "gemini-4-carbon-high",
25
22
  // kimi reads its model from its own config.toml (default_model); ufoo
26
- // never injects -m/--model, so keep the placeholder empty like agy.
23
+ // never injects -m/--model.
27
24
  kimi: "",
28
25
  "grok-build": "grok-4.6",
29
26
  }),
27
+ aux: Object.freeze({
28
+ codex: "gpt-6-luna",
29
+ claude: "claude-haiku-5-5",
30
+ agy: "gemini-4-hydrogen-high",
31
+ kimi: "",
32
+ "grok-build": "",
33
+ }),
30
34
  });
31
35
 
32
36
  const DEFAULT_CONFIG = {
@@ -40,6 +44,7 @@ const DEFAULT_CONFIG = {
40
44
  claudeOauthTokenPath: "",
41
45
  claudeOauthRefreshWindowSec: 300,
42
46
  agentModel: "",
47
+ agentAuxModel: "",
43
48
  agentBaseUrl: "",
44
49
  agentApiKey: "",
45
50
  agentThinking: "medium",
@@ -50,12 +55,25 @@ const DEFAULT_CONFIG = {
50
55
  const DEFAULT_UCODE_CONFIG = {
51
56
  ucodeProvider: "",
52
57
  ucodeModel: "",
58
+ ucodeAuxModel: "",
53
59
  ucodeBaseUrl: "",
54
60
  ucodeApiKey: "",
55
61
  ucodeAgentDir: "",
56
62
  ucodeThinking: "",
57
63
  };
58
64
 
65
+ const DEFAULT_BROWSER_CONFIG = Object.freeze({
66
+ enabled: false,
67
+ backend: "ufoo-extension",
68
+ setupChoice: "unset",
69
+ schemaVersion: 1,
70
+ profile: "",
71
+ });
72
+
73
+ function normalizeAuxModel(value) {
74
+ return typeof value === "string" ? value.trim() : "";
75
+ }
76
+
59
77
  function normalizeLaunchMode(value) {
60
78
  if (value === "auto") return "auto";
61
79
  if (value === "internal") return "internal";
@@ -103,6 +121,12 @@ function defaultAgentModelForProvider(value = "") {
103
121
  return SETTINGS_MODEL_DEFAULTS.agent[providerKey(value)] || SETTINGS_MODEL_DEFAULTS.agent.codex;
104
122
  }
105
123
 
124
+ function defaultAuxModelForProvider(value = "") {
125
+ const raw = String(value || "").trim().toLowerCase();
126
+ if (!raw || raw === "custom" || raw === "openai") return "";
127
+ return SETTINGS_MODEL_DEFAULTS.aux[providerKey(raw)] || "";
128
+ }
129
+
106
130
  function normalizeModel(value, fallback = "") {
107
131
  const text = typeof value === "string" ? value.trim() : "";
108
132
  return text || fallback;
@@ -138,7 +162,36 @@ function normalizeClaudeOauthRefreshWindowSec(value) {
138
162
  return Math.floor(num);
139
163
  }
140
164
 
165
+ function normalizeBrowserBackend(value) {
166
+ const raw = String(value || "").trim().toLowerCase();
167
+ if (raw === "playwright-extension" || raw === "extension") return "playwright-extension";
168
+ if (raw === "cdp") return "cdp";
169
+ return DEFAULT_BROWSER_CONFIG.backend;
170
+ }
171
+
172
+ function normalizeBrowserSetupChoice(value) {
173
+ const raw = String(value || "").trim().toLowerCase();
174
+ if (raw === "install") return "install";
175
+ if (raw === "skip") return "skip";
176
+ return DEFAULT_BROWSER_CONFIG.setupChoice;
177
+ }
178
+
179
+ function normalizeBrowserConfig(raw = {}) {
180
+ const source = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
181
+ const profile = typeof source.profile === "string" ? source.profile.trim() : "";
182
+ const normalized = {
183
+ enabled: source.enabled === true,
184
+ backend: normalizeBrowserBackend(source.backend),
185
+ setupChoice: normalizeBrowserSetupChoice(source.setupChoice),
186
+ schemaVersion: 1,
187
+ };
188
+ if (profile) normalized.profile = profile;
189
+ return normalized;
190
+ }
191
+
141
192
  function globalConfigPath() {
193
+ const override = String(process.env.UFOO_GLOBAL_CONFIG_PATH || "").trim();
194
+ if (override) return override;
142
195
  return path.join(os.homedir(), ".ufoo", "config.json");
143
196
  }
144
197
 
@@ -189,6 +242,7 @@ function loadConfig(projectRoot) {
189
242
  ),
190
243
  agentProvider,
191
244
  agentModel: normalizeModel(raw.agentModel, defaultAgentModelForProvider(agentProvider)),
245
+ agentAuxModel: normalizeAuxModel(raw.agentAuxModel),
192
246
  mcpPort: normalizeMcpPort(raw.mcpPort),
193
247
  codexAuthPath: normalizeCodexAuthPath(raw.codexAuthPath),
194
248
  codexOauthRefreshWindowSec: normalizeCodexOauthRefreshWindowSec(raw.codexOauthRefreshWindowSec),
@@ -244,6 +298,7 @@ function saveConfig(projectRoot, config) {
244
298
  }
245
299
  merged.agentProvider = normalizeAgentProvider(merged.agentProvider);
246
300
  merged.agentModel = typeof merged.agentModel === "string" ? merged.agentModel.trim() : "";
301
+ merged.agentAuxModel = normalizeAuxModel(merged.agentAuxModel);
247
302
  merged.mcpPort = normalizeMcpPort(merged.mcpPort);
248
303
  merged.codexAuthPath = normalizeCodexAuthPath(merged.codexAuthPath);
249
304
  merged.codexOauthRefreshWindowSec = normalizeCodexOauthRefreshWindowSec(merged.codexOauthRefreshWindowSec);
@@ -261,6 +316,7 @@ function loadGlobalUcodeConfig() {
261
316
  return {
262
317
  ucodeProvider: typeof raw.ucodeProvider === "string" ? raw.ucodeProvider : "",
263
318
  ucodeModel: typeof raw.ucodeModel === "string" ? raw.ucodeModel : "",
319
+ ucodeAuxModel: normalizeAuxModel(raw.ucodeAuxModel),
264
320
  ucodeBaseUrl: typeof raw.ucodeBaseUrl === "string" ? raw.ucodeBaseUrl : "",
265
321
  ucodeApiKey: typeof raw.ucodeApiKey === "string" ? raw.ucodeApiKey : "",
266
322
  ucodeAgentDir: typeof raw.ucodeAgentDir === "string" ? raw.ucodeAgentDir : "",
@@ -305,20 +361,50 @@ function saveGlobalDaemonConfig(updates = {}) {
305
361
  });
306
362
  }
307
363
 
364
+ function loadGlobalBrowserConfig() {
365
+ const raw = loadJsonSafe(globalConfigPath());
366
+ return normalizeBrowserConfig(raw.browser);
367
+ }
368
+
369
+ function saveGlobalBrowserConfig(updates = {}) {
370
+ const target = globalConfigPath();
371
+ return withFileLock(target, () => {
372
+ fs.mkdirSync(path.dirname(target), { recursive: true });
373
+ const existing = loadJsonForUpdate(target);
374
+ const merged = withoutRemovedSettings(existing);
375
+ const nextBrowser = normalizeBrowserConfig({
376
+ ...(existing.browser && typeof existing.browser === "object" ? existing.browser : {}),
377
+ ...(updates && typeof updates === "object" ? updates : {}),
378
+ });
379
+ merged.browser = nextBrowser;
380
+ writeFileAtomic(target, JSON.stringify(merged, null, 2), { mode: 0o600 });
381
+ return nextBrowser;
382
+ });
383
+ }
384
+
308
385
  module.exports = {
309
386
  SETTINGS_MODEL_DEFAULTS,
387
+ DEFAULT_BROWSER_CONFIG,
388
+ globalConfigPath,
310
389
  loadConfig,
311
390
  saveConfig,
312
391
  loadGlobalUcodeConfig,
313
392
  saveGlobalUcodeConfig,
314
393
  loadGlobalDaemonConfig,
315
394
  saveGlobalDaemonConfig,
395
+ loadGlobalBrowserConfig,
396
+ saveGlobalBrowserConfig,
397
+ normalizeBrowserBackend,
398
+ normalizeBrowserSetupChoice,
399
+ normalizeBrowserConfig,
316
400
  normalizeLaunchMode,
317
401
  normalizeDaemonTopology,
318
402
  normalizeAgentProvider,
403
+ normalizeAuxModel,
319
404
  providerKey,
320
405
  sameModelProvider,
321
406
  defaultAgentModelForProvider,
407
+ defaultAuxModelForProvider,
322
408
  normalizeMcpPort,
323
409
  normalizeCodexAuthPath,
324
410
  normalizeCodexOauthRefreshWindowSec,
@@ -179,7 +179,7 @@ class EventBus {
179
179
  sessionId,
180
180
  agentType,
181
181
  nickname,
182
- options
182
+ { ...options, projectRoot: options.projectRoot || this.projectRoot }
183
183
  );
184
184
 
185
185
  this.saveBusData();
@@ -197,7 +197,7 @@ class EventBus {
197
197
  this.ensureBus();
198
198
  this.loadBusData();
199
199
 
200
- const success = await this.subscriberManager.leave(subscriber);
200
+ const success = await this.subscriberManager.leave(subscriber, { projectRoot: this.projectRoot });
201
201
 
202
202
  if (success) {
203
203
  this.saveBusData();
@@ -16,6 +16,7 @@ const { getUfooPaths } = require("../state/paths");
16
16
  const { applyProjectNicknamePrefix } = require("../../runtime/daemon/nicknameScope");
17
17
  const { QUEUE_TYPES, normalizeQueueEnvelope } = require("./deliveryQueue");
18
18
  const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
19
+ const { isWakeMeta } = require("./wakeEndpoint");
19
20
 
20
21
  const SEQ_LOCK_TIMEOUT_MS = 5000;
21
22
  const SEQ_LOCK_POLL_MS = 25;
@@ -463,7 +464,15 @@ class MessageManager {
463
464
  // 检查订阅者的 offset,如果已经消费过这个 seq,不再添加
464
465
  const offset = await this.queueManager.getOffset(targetSubscriber);
465
466
  if (seq > offset) {
466
- await this.queueManager.appendPending(targetSubscriber, queueEvent);
467
+ const wakeTarget = isWakeMeta(this.busData.agents?.[targetSubscriber]);
468
+ const queued = wakeTarget
469
+ ? normalizeQueueEnvelope(event, {
470
+ queueType: QUEUE_TYPES.AGENT_MESSAGE,
471
+ delivery: { mode: "wake", gate: "none", max_inflight: 1 },
472
+ ack: { policy: "on_consume" },
473
+ })
474
+ : queueEvent;
475
+ await this.queueManager.appendPending(targetSubscriber, queued);
467
476
  }
468
477
  }
469
478
 
@@ -7,6 +7,7 @@ const AUTO_NICKNAME_PREFIXES = new Set([
7
7
  "cursor",
8
8
  "agy",
9
9
  "grok",
10
+ "grok-bot",
10
11
  "kimi",
11
12
  "ucode",
12
13
  ]);
@@ -74,11 +75,12 @@ class NicknameManager {
74
75
  const prefix = resolveAutoNicknamePrefix(agentType);
75
76
 
76
77
  // 找出所有相同前缀的昵称
78
+ const numberPattern = new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-(\\d+)$`);
77
79
  const existing = Object.values(subscribers)
78
80
  .map((meta) => meta.nickname)
79
81
  .filter((nick) => nick && nick.startsWith(`${prefix}-`))
80
82
  .map((nick) => {
81
- const match = nick.match(/^[^-]+-(\d+)$/);
83
+ const match = String(nick).match(numberPattern);
82
84
  return match ? parseInt(match[1], 10) : 0;
83
85
  })
84
86
  .filter((n) => !isNaN(n));
@@ -1,6 +1,7 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
  const { getTimestamp, isAgentPidAlive, isMetaActive, isValidTty, getTtyProcessInfo, normalizeAgentTypeAlias } = require("./utils");
4
+ const { isWakeMeta, removeWakeEndpoint, writeWakeEndpoint } = require("./wakeEndpoint");
4
5
  const NicknameManager = require("./nickname");
5
6
  const { isMismatchedAutoNickname } = require("./nickname");
6
7
  const { spawnSync } = require("child_process");
@@ -280,9 +281,10 @@ class SubscriberManager {
280
281
  : (existingMeta?.scoped_nickname || finalNickname);
281
282
  }
282
283
 
283
- const explicitLaunchMode = typeof options.launchMode === "string"
284
- ? options.launchMode.trim()
285
- : "";
284
+ const wakeJoin = options.wake && typeof options.wake === "object";
285
+ const explicitLaunchMode = wakeJoin
286
+ ? "wake"
287
+ : (typeof options.launchMode === "string" ? options.launchMode.trim() : "");
286
288
  const envLaunchMode = typeof process.env.UFOO_LAUNCH_MODE === "string"
287
289
  ? process.env.UFOO_LAUNCH_MODE.trim()
288
290
  : "";
@@ -296,18 +298,18 @@ class SubscriberManager {
296
298
  const overrideTty = (typeof options.tty === "string" && isValidTty(options.tty.trim()))
297
299
  ? options.tty.trim()
298
300
  : "";
299
- const detectedTty = hasOverrideTty ? overrideTty : getTtyPath();
301
+ const detectedTty = (wakeJoin || launchMode === "internal") ? "" : (hasOverrideTty ? overrideTty : getTtyPath());
300
302
  const tty = overrideTty || (isValidTty(detectedTty) ? detectedTty : "");
301
303
  const preservedTty = !tty && launchMode !== "internal" && isValidTty(existingMeta?.tty)
302
304
  ? existingMeta.tty
303
305
  : "";
304
- const finalTty = tty || preservedTty;
306
+ const finalTty = wakeJoin ? "" : (tty || preservedTty);
305
307
  const ttyInfo = finalTty ? getTtyProcessInfo(finalTty) : null;
306
308
 
307
309
  // 清理同一 tty 的旧订阅者(避免重复启动污染)
308
310
  // Inherit nickname from displaced entry when this is a new subscriber
309
311
  // with no explicit nickname (e.g. session restart on same TTY)
310
- const inheritedNickname = await this.cleanupDuplicateTty(subscriber, finalTty, { agentType });
312
+ const inheritedNickname = wakeJoin ? null : await this.cleanupDuplicateTty(subscriber, finalTty, { agentType });
311
313
  if (inheritedNickname && !nickname && !existingMeta) {
312
314
  finalNickname = inheritedNickname;
313
315
  if (!finalScopedNickname) finalScopedNickname = inheritedNickname;
@@ -320,7 +322,7 @@ class SubscriberManager {
320
322
  const explicitTmuxPane = typeof options.tmuxPane === "string" ? options.tmuxPane.trim() : "";
321
323
  const envTmuxPane = typeof process.env.TMUX_PANE === "string" ? process.env.TMUX_PANE.trim() : "";
322
324
  const preservedTmuxPane = typeof existingMeta?.tmux_pane === "string" ? existingMeta.tmux_pane.trim() : "";
323
- const tmuxPane = explicitTmuxPane || envTmuxPane || preservedTmuxPane;
325
+ const tmuxPane = wakeJoin ? "" : (explicitTmuxPane || envTmuxPane || preservedTmuxPane);
324
326
 
325
327
  const hostInjectSock = typeof options.hostInjectSock === "string"
326
328
  ? options.hostInjectSock.trim()
@@ -348,12 +350,23 @@ class SubscriberManager {
348
350
  activity_since: getTimestamp(),
349
351
  joined_at: existingMeta?.joined_at || getTimestamp(),
350
352
  last_seen: getTimestamp(),
351
- pid: overridePid || getJoinedPid(),
352
- tty: finalTty,
353
+ pid: wakeJoin ? 0 : (overridePid || getJoinedPid()),
354
+ tty: wakeJoin ? "" : finalTty,
353
355
  tty_shell_pid: ttyInfo?.shellPid || 0,
354
356
  tmux_pane: tmuxPane,
355
357
  launch_mode: launchMode,
358
+ ...(wakeJoin ? { activity_state: "idle" } : {}),
356
359
  };
360
+ if (wakeJoin) {
361
+ try {
362
+ const saved = writeWakeEndpoint(options.projectRoot, subscriber, options.wake);
363
+ this.busData.agents[subscriber].wake_adapter = saved.adapter;
364
+ } catch (error) {
365
+ if (existingMeta) this.busData.agents[subscriber] = existingMeta;
366
+ else delete this.busData.agents[subscriber];
367
+ throw error;
368
+ }
369
+ }
357
370
 
358
371
  if (hostInjectSock) {
359
372
  this.busData.agents[subscriber].host_inject_sock = hostInjectSock;
@@ -412,7 +425,7 @@ class SubscriberManager {
412
425
  /**
413
426
  * 离开总线
414
427
  */
415
- async leave(subscriber) {
428
+ async leave(subscriber, options = {}) {
416
429
  if (!this.busData.agents || !this.busData.agents[subscriber]) {
417
430
  return false;
418
431
  }
@@ -420,6 +433,7 @@ class SubscriberManager {
420
433
  this.busData.agents[subscriber].status = "inactive";
421
434
  this.busData.agents[subscriber].activity_state = "";
422
435
  this.busData.agents[subscriber].last_seen = getTimestamp();
436
+ if (options.projectRoot) removeWakeEndpoint(options.projectRoot, subscriber);
423
437
  this.cleanupSubscriberArtifacts(subscriber);
424
438
 
425
439
  return true;
@@ -485,6 +499,7 @@ class SubscriberManager {
485
499
  if (!this.busData.agents) return;
486
500
 
487
501
  for (const [id, meta] of Object.entries(this.busData.agents)) {
502
+ if (isWakeMeta(meta)) continue;
488
503
  if (isManagedMcpRegistration(meta)) {
489
504
  const expiresAtMs = Date.parse(String(meta.mcp_lease_expires_at || ""));
490
505
  const expired = !Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now();
@@ -318,6 +318,10 @@ function isMetaActive(meta) {
318
318
  // 1. 显式标记为 inactive
319
319
  if (meta.status === "inactive") return false;
320
320
 
321
+ // A wake registration has no local process. Liveness is the saved adapter,
322
+ // not a pid or a 30s heartbeat.
323
+ if (meta.launch_mode === "wake" && meta.wake_adapter) return true;
324
+
321
325
  // 2. PID 存活(最可靠)
322
326
  if (meta.pid && isAgentPidAlive(meta.pid)) return true;
323
327