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.
Files changed (158) hide show
  1. package/OBSERVABILITY.md +65 -0
  2. package/README.md +90 -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/ucode.js +4 -0
  7. package/bin/ufoo.js +3 -3
  8. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  9. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  10. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  11. package/dist/tui/linux-x64/ufoo-tui +0 -0
  12. package/package.json +6 -6
  13. package/src/agents/activity/activityDetector.js +1 -1
  14. package/src/agents/capabilities/agentManagement/service.js +40 -13
  15. package/src/agents/capabilities/coordination/index.js +1 -1
  16. package/src/agents/capabilities/taskReports/index.js +1 -1
  17. package/src/agents/controller/controllerToolExecutor.js +36 -20
  18. package/src/agents/controller/index.js +1 -6
  19. package/src/agents/internal/internalRunner.js +90 -56
  20. package/src/agents/launch/index.js +0 -1
  21. package/src/agents/launch/launcher.js +38 -29
  22. package/src/agents/launch/launcherReadiness.js +35 -0
  23. package/src/agents/launch/notifier.js +2 -2
  24. package/src/agents/launch/ptyWrapper.js +5 -2
  25. package/src/agents/launch/readyDetector.js +2 -2
  26. package/src/agents/profiles/main.js +1 -1
  27. package/src/agents/prompts/cooperation.js +14 -0
  28. package/src/agents/prompts/defaultBootstrap.js +1 -1
  29. package/src/agents/prompts/groupBootstrap.js +23 -7
  30. package/src/agents/prompts/mainAgent.js +11 -2
  31. package/src/agents/prompts/native/system.js +4 -1
  32. package/src/agents/prompts/native/ufoo.js +11 -3
  33. package/src/agents/prompts/promptProfiles.js +2 -0
  34. package/src/agents/prompts/reporting.js +16 -0
  35. package/src/agents/providers/claudeEventTranslator.js +3 -0
  36. package/src/agents/providers/claudeThreadProvider.js +3 -2
  37. package/src/agents/providers/clientIdentity.js +75 -0
  38. package/src/agents/providers/codexEventTranslator.js +23 -2
  39. package/src/agents/providers/codexThreadProvider.js +15 -6
  40. package/src/agents/providers/credentials/index.js +2 -0
  41. package/src/agents/providers/directAuthStatus.js +1 -1
  42. package/src/agents/providers/index.js +1 -1
  43. package/src/agents/providers/modelSettings.js +34 -0
  44. package/src/agents/providers/modelsCatalog.js +379 -0
  45. package/src/agents/providers/nativeTransport.js +58 -40
  46. package/src/agents/providers/runtimeConfig.js +10 -8
  47. package/src/agents/providers/thinkingLevels.js +10 -36
  48. package/src/agents/providers/transports/responsesProtocol.js +11 -6
  49. package/src/agents/providers/upstreamRuntime.js +135 -0
  50. package/src/agents/runtime/context/checkpointStore.js +38 -0
  51. package/src/agents/runtime/context/compaction.js +151 -0
  52. package/src/agents/runtime/context/contextBudget.js +93 -0
  53. package/src/agents/runtime/context/replayHistory.js +28 -0
  54. package/src/agents/runtime/context/runtimeStore.js +2 -1
  55. package/src/agents/runtime/core/agentLoop.js +99 -18
  56. package/src/agents/runtime/core/executionBudget.js +36 -0
  57. package/src/agents/runtime/createAgentRuntime.js +16 -4
  58. package/src/agents/runtime/prompts/responseLanguage.js +12 -0
  59. package/src/agents/runtime/protocol/runObservation.js +24 -0
  60. package/src/agents/runtime/protocol/traceContext.js +9 -0
  61. package/src/app/chat/ChatController.js +26 -53
  62. package/src/app/chat/agentDirectory.js +1 -16
  63. package/src/app/chat/bootstrap.js +1 -2
  64. package/src/app/chat/commandExecutor.js +93 -285
  65. package/src/app/chat/commands.js +32 -45
  66. package/src/app/chat/daemonMessageRouter.js +0 -45
  67. package/src/app/chat/historyStore.js +12 -48
  68. package/src/app/chat/inputSubmitHandler.js +7 -33
  69. package/src/app/chat/internalAgentLogHistory.js +19 -60
  70. package/src/app/chat/multiWindow/paneManager.js +10 -3
  71. package/src/app/chat/streamState.js +0 -4
  72. package/src/app/cli/features/init.js +5 -5
  73. package/src/app/cli/metricsCommands.js +68 -0
  74. package/src/app/cli/run.js +42 -3
  75. package/src/app/cli/traceCommands.js +36 -0
  76. package/src/code/agent.js +18 -13
  77. package/src/code/busConsumer.js +1 -3
  78. package/src/code/commands.js +1 -1
  79. package/src/code/context/assembler.js +7 -8
  80. package/src/code/context/stateCommit.js +2 -1
  81. package/src/code/internalThread.js +10 -3
  82. package/src/code/launcher/ucode.js +1 -1
  83. package/src/code/launcher/ucodeBootstrap.js +1 -1
  84. package/src/code/modelCommand.js +11 -35
  85. package/src/code/nativeRunner.js +55 -17
  86. package/src/code/providers/modelsCatalog.js +1 -317
  87. package/src/code/repl.js +4 -11
  88. package/src/code/sessionStore.js +3 -3
  89. package/src/code/taskDecomposer.js +18 -0
  90. package/src/code/toolBudget.js +1 -17
  91. package/src/config.js +22 -72
  92. package/src/coordination/bus/index.js +12 -3
  93. package/src/coordination/bus/inject.js +2 -2
  94. package/src/coordination/bus/message.js +15 -1
  95. package/src/coordination/bus/nickname.js +1 -1
  96. package/src/coordination/bus/subscriber.js +3 -2
  97. package/src/coordination/bus/utils.js +1 -1
  98. package/src/coordination/history/agentPerformance.js +279 -0
  99. package/src/coordination/history/agentTrace.js +249 -0
  100. package/src/coordination/state/workspaceAccess.js +1 -1
  101. package/src/orchestration/controller/index.js +1 -8
  102. package/src/orchestration/controller/launchRouting.js +1 -1
  103. package/src/orchestration/solo/commands.js +3 -1
  104. package/src/runtime/contracts/agentMode.js +11 -2
  105. package/src/runtime/contracts/uiProtocol.js +18 -19
  106. package/src/runtime/daemon/agentHost.js +57 -25
  107. package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
  108. package/src/runtime/daemon/busBridge.js +1 -1
  109. package/src/runtime/daemon/controlPlaneService.js +1 -1
  110. package/src/runtime/daemon/groupOrchestrator.js +20 -5
  111. package/src/runtime/daemon/groupStatus.js +20 -0
  112. package/src/runtime/daemon/index.js +19 -44
  113. package/src/runtime/daemon/mcpHttpServer.js +39 -10
  114. package/src/runtime/daemon/mcpServer.js +1 -1
  115. package/src/runtime/daemon/nicknameScope.js +1 -1
  116. package/src/runtime/daemon/ops.js +46 -23
  117. package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
  118. package/src/runtime/daemon/promptRequest.js +92 -589
  119. package/src/runtime/daemon/status.js +5 -6
  120. package/src/tools/controllerSchemas.js +6 -2
  121. package/src/tools/handlers/tier2.js +4 -2
  122. package/src/tools/registry.js +4 -0
  123. package/src/tools/schemaFixtures.js +26 -2
  124. package/src/tools/tier0/readAgentMetrics.js +14 -0
  125. package/src/tools/tier0/readAgentTrace.js +12 -0
  126. package/src/ui/agentSettingsController.js +107 -0
  127. package/src/ui/agentSurface.js +1 -1
  128. package/src/ui/dashboardBridge.js +1 -1
  129. package/src/ui/format/banner.js +1 -4
  130. package/src/ui/format/index.js +14 -10
  131. package/src/ui/format/loopSummary.js +50 -0
  132. package/src/ui/format/markdownRenderer.js +3 -4
  133. package/src/ui/rustChatHost.js +191 -206
  134. package/src/ui/rustMultiSession.js +77 -36
  135. package/src/ui/rustUcodeHost.js +6 -1
  136. package/src/ui/settingsBridge.js +33 -16
  137. package/src/ui/toolMergeBridge.js +0 -4
  138. package/src/ui/uiHostServer.js +5 -8
  139. package/src/agents/controller/loopObservability.js +0 -200
  140. package/src/agents/controller/loopRuntime.js +0 -336
  141. package/src/agents/controller/ufooAgent.js +0 -830
  142. package/src/agents/launch/ptyRunner.js +0 -1135
  143. package/src/agents/providers/controllerJsonTransport.js +0 -28
  144. package/src/agents/providers/upstreamTransport.js +0 -698
  145. package/src/app/chat/agentBar.js +0 -135
  146. package/src/app/chat/agentSockets.js +0 -225
  147. package/src/app/chat/dashboardView.js +0 -405
  148. package/src/app/chat/rawKeyMap.js +0 -42
  149. package/src/app/chat/settingsController.js +0 -111
  150. package/src/coordination/history/controllerSummary.js +0 -23
  151. package/src/orchestration/controller/flags.js +0 -167
  152. package/src/orchestration/controller/gateRouter.js +0 -211
  153. package/src/orchestration/controller/routerFastPath.js +0 -22
  154. package/src/orchestration/controller/routerFinalize.js +0 -222
  155. package/src/orchestration/controller/shadowGuard.js +0 -280
  156. package/src/runtime/daemon/executionPaths.js +0 -30
  157. package/src/runtime/daemon/promptLoop.js +0 -136
  158. package/src/runtime/privacy/shadowDiff.js +0 -174
@@ -1,319 +1,3 @@
1
1
  "use strict";
2
2
 
3
- /**
4
- * Live provider model catalog via the OpenAI-compatible / Anthropic models route.
5
- *
6
- * Used by /model suggestions and settings validation so ucode only offers
7
- * (and preferably accepts) models the configured endpoint actually lists.
8
- */
9
-
10
- const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com/v1";
11
- const DEFAULT_TIMEOUT_MS = 8000;
12
- const CACHE_TTL_MS = 60_000;
13
- const DEFAULT_GROK_CLIENT_VERSION = "0.2.120";
14
-
15
- /** @type {Map<string, { at: number, result: object }>} */
16
- const modelsCache = new Map();
17
-
18
- function clipText(value = "", maxChars = 400) {
19
- const text = String(value || "");
20
- if (text.length <= maxChars) return text;
21
- return `${text.slice(0, maxChars)}…`;
22
- }
23
-
24
- function resolveOpenAiModelsUrl(baseUrl = "") {
25
- const raw = String(baseUrl || "").trim();
26
- if (!raw) return "";
27
- const normalized = raw.replace(/\/+$/, "");
28
- if (/\/models$/i.test(normalized)) return normalized;
29
- if (/\/chat\/completions$/i.test(normalized)) {
30
- return normalized.replace(/\/chat\/completions$/i, "/models");
31
- }
32
- if (/\/v1$/i.test(normalized)) return `${normalized}/models`;
33
- if (/\/api$/i.test(normalized)) return `${normalized}/v1/models`;
34
- return `${normalized}/models`;
35
- }
36
-
37
- function resolveAnthropicModelsUrl(baseUrl = "") {
38
- const raw = String(baseUrl || "").trim() || DEFAULT_ANTHROPIC_BASE_URL;
39
- const normalized = raw.replace(/\/+$/, "");
40
- if (/\/models$/i.test(normalized)) return normalized;
41
- if (/\/messages$/i.test(normalized)) {
42
- return normalized.replace(/\/messages$/i, "/models");
43
- }
44
- if (/\/v1$/i.test(normalized)) return `${normalized}/models`;
45
- if (/\/api$/i.test(normalized)) return `${normalized}/v1/models`;
46
- return `${normalized}/models`;
47
- }
48
-
49
- function resolveModelsUrl({ transport = "", baseUrl = "", provider = "" } = {}) {
50
- let url;
51
- if (String(transport || "") === "anthropic-messages") {
52
- url = resolveAnthropicModelsUrl(baseUrl);
53
- } else {
54
- url = resolveOpenAiModelsUrl(baseUrl);
55
- }
56
- const normalizedProvider = String(provider || "").trim().toLowerCase();
57
- if (normalizedProvider === "grok" || normalizedProvider === "grok-build" || normalizedProvider === "grok-shell") {
58
- const separator = url.includes("?") ? "&" : "?";
59
- const version = String(process.env.UFOO_GROK_CLIENT_VERSION || DEFAULT_GROK_CLIENT_VERSION).trim();
60
- return `${url}${separator}client_version=${encodeURIComponent(version || DEFAULT_GROK_CLIENT_VERSION)}`;
61
- }
62
- return url;
63
- }
64
-
65
- function cacheKey({ transport = "", baseUrl = "", apiKey = "", provider = "" } = {}) {
66
- const keyTail = apiKey ? String(apiKey).slice(-8) : "";
67
- return `${provider}|${transport}|${baseUrl}|${keyTail}`;
68
- }
69
-
70
- function extractModelIds(payload) {
71
- const ids = [];
72
- const seen = new Set();
73
- const push = (value) => {
74
- const id = String(value || "").trim();
75
- if (!id || seen.has(id)) return;
76
- seen.add(id);
77
- ids.push(id);
78
- };
79
-
80
- if (!payload || typeof payload !== "object") return ids;
81
-
82
- if (Array.isArray(payload.data)) {
83
- for (const item of payload.data) {
84
- if (!item) continue;
85
- if (typeof item === "string") push(item);
86
- else push(item.id || item.model || item.name);
87
- }
88
- }
89
-
90
- if (Array.isArray(payload.models)) {
91
- for (const item of payload.models) {
92
- if (!item) continue;
93
- if (typeof item === "string") push(item);
94
- else push(item.id || item.model || item.name);
95
- }
96
- }
97
-
98
- return ids;
99
- }
100
-
101
- function buildListHeaders({ transport = "", apiKey = "", provider = "" } = {}) {
102
- const headers = {
103
- Accept: "application/json",
104
- };
105
- const normalizedProvider = String(provider || "").trim().toLowerCase();
106
- if (normalizedProvider === "grok" || normalizedProvider === "grok-build" || normalizedProvider === "grok-shell") {
107
- const version = String(process.env.UFOO_GROK_CLIENT_VERSION || DEFAULT_GROK_CLIENT_VERSION).trim();
108
- headers["User-Agent"] = `grok-shell/${version || DEFAULT_GROK_CLIENT_VERSION}`;
109
- }
110
- const key = String(apiKey || "").trim();
111
- if (!key) return headers;
112
-
113
- if (String(transport || "") === "anthropic-messages") {
114
- headers["x-api-key"] = key;
115
- headers["anthropic-version"] = "2023-06-01";
116
- } else {
117
- headers.Authorization = `Bearer ${key}`;
118
- }
119
- return headers;
120
- }
121
-
122
- /**
123
- * Fetch the provider's models catalog.
124
- * @returns {Promise<{
125
- * ok: boolean,
126
- * models: string[],
127
- * url: string,
128
- * error: string,
129
- * status: number,
130
- * cached: boolean,
131
- * }>}
132
- */
133
- async function listProviderModels(options = {}) {
134
- const transport = String(options.transport || "openai-chat").trim() || "openai-chat";
135
- const baseUrl = String(options.baseUrl || "").trim();
136
- const apiKey = String(options.apiKey || "").trim();
137
- const provider = String(options.provider || "").trim();
138
- const timeoutMs = Math.max(1000, Number(options.timeoutMs) || DEFAULT_TIMEOUT_MS);
139
- const fetchImpl = typeof options.fetchImpl === "function" ? options.fetchImpl : fetch;
140
- const skipCache = options.skipCache === true;
141
- const url = resolveModelsUrl({ transport, baseUrl, provider });
142
-
143
- if (!url) {
144
- return {
145
- ok: false,
146
- models: [],
147
- url: "",
148
- error: "models url unavailable (set ucode base url)",
149
- status: 0,
150
- cached: false,
151
- };
152
- }
153
-
154
- const key = cacheKey({ transport, baseUrl, apiKey, provider });
155
- if (!skipCache) {
156
- const hit = modelsCache.get(key);
157
- if (hit && (Date.now() - hit.at) < CACHE_TTL_MS) {
158
- return { ...hit.result, cached: true };
159
- }
160
- }
161
-
162
- const controller = typeof AbortController === "function" ? new AbortController() : null;
163
- const timer = controller
164
- ? setTimeout(() => {
165
- try { controller.abort(); } catch { /* ignore */ }
166
- }, timeoutMs)
167
- : null;
168
- if (timer && typeof timer.unref === "function") timer.unref();
169
-
170
- try {
171
- const response = await fetchImpl(url, {
172
- method: "GET",
173
- headers: buildListHeaders({ transport, apiKey, provider }),
174
- signal: controller ? controller.signal : undefined,
175
- });
176
- const status = Number(response && response.status) || 0;
177
- const bodyText = await response.text().catch(() => "");
178
- let payload = null;
179
- try {
180
- payload = bodyText ? JSON.parse(bodyText) : null;
181
- } catch {
182
- payload = null;
183
- }
184
-
185
- if (!response.ok) {
186
- const result = {
187
- ok: false,
188
- models: [],
189
- url,
190
- error: `models route failed (${status}): ${clipText(bodyText || response.statusText || "unknown")}`,
191
- status,
192
- cached: false,
193
- };
194
- return result;
195
- }
196
-
197
- const models = extractModelIds(payload);
198
- const result = {
199
- ok: true,
200
- models,
201
- url,
202
- error: models.length === 0 ? "models route returned an empty catalog" : "",
203
- status,
204
- cached: false,
205
- };
206
- // Cache successful responses even when empty — avoids hammering a broken gateway.
207
- modelsCache.set(key, { at: Date.now(), result: { ...result, cached: false } });
208
- return result;
209
- } catch (err) {
210
- const message = err && err.name === "AbortError"
211
- ? `models route timed out after ${timeoutMs}ms`
212
- : (err && err.message ? err.message : String(err || "models route failed"));
213
- return {
214
- ok: false,
215
- models: [],
216
- url,
217
- error: message,
218
- status: 0,
219
- cached: false,
220
- };
221
- } finally {
222
- if (timer) clearTimeout(timer);
223
- }
224
- }
225
-
226
- function modelSupported(model = "", models = []) {
227
- const needle = String(model || "").trim();
228
- if (!needle) return false;
229
- const list = Array.isArray(models) ? models : [];
230
- return list.some((id) => String(id || "").trim() === needle);
231
- }
232
-
233
- /**
234
- * Validate a model id against the live catalog.
235
- * Soft mode: when the catalog cannot be fetched, allow with a warning.
236
- */
237
- async function confirmModelSupported(options = {}) {
238
- const model = String(options.model || "").trim();
239
- if (!model) {
240
- return {
241
- ok: false,
242
- allowed: false,
243
- model: "",
244
- models: [],
245
- error: "model id is empty",
246
- warning: "",
247
- catalog: null,
248
- };
249
- }
250
-
251
- const catalog = await listProviderModels(options);
252
- if (!catalog.ok) {
253
- return {
254
- ok: false,
255
- allowed: options.strict === true ? false : true,
256
- model,
257
- models: [],
258
- error: catalog.error || "models route unavailable",
259
- warning: options.strict === true
260
- ? ""
261
- : `could not confirm model via models route (${catalog.error || "unavailable"}); accepting ${model}`,
262
- catalog,
263
- };
264
- }
265
-
266
- if (catalog.models.length === 0) {
267
- return {
268
- ok: false,
269
- allowed: options.strict === true ? false : true,
270
- model,
271
- models: [],
272
- error: catalog.error || "empty models catalog",
273
- warning: options.strict === true
274
- ? ""
275
- : `models route returned no models; accepting ${model}`,
276
- catalog,
277
- };
278
- }
279
-
280
- if (!modelSupported(model, catalog.models)) {
281
- const sample = catalog.models.slice(0, 8).join(", ");
282
- const more = catalog.models.length > 8 ? ` (+${catalog.models.length - 8} more)` : "";
283
- return {
284
- ok: false,
285
- allowed: false,
286
- model,
287
- models: catalog.models,
288
- error: `model "${model}" is not in the provider catalog${sample ? ` (available: ${sample}${more})` : ""}`,
289
- warning: "",
290
- catalog,
291
- };
292
- }
293
-
294
- return {
295
- ok: true,
296
- allowed: true,
297
- model,
298
- models: catalog.models,
299
- error: "",
300
- warning: "",
301
- catalog,
302
- };
303
- }
304
-
305
- function clearModelsCache() {
306
- modelsCache.clear();
307
- }
308
-
309
- module.exports = {
310
- resolveOpenAiModelsUrl,
311
- resolveAnthropicModelsUrl,
312
- resolveModelsUrl,
313
- listProviderModels,
314
- confirmModelSupported,
315
- modelSupported,
316
- extractModelIds,
317
- clearModelsCache,
318
- CACHE_TTL_MS,
319
- };
3
+ module.exports = require("../../agents/providers/modelsCatalog");
package/src/code/repl.js CHANGED
@@ -26,6 +26,7 @@ const { summarizeSessionUsage, formatSessionUsageStatus } = require("./usageStor
26
26
  const { listUcodeCommandsForHelp } = require("./commands");
27
27
  const { applyUcodeModelCommand, suggestUcodeModels } = require("./modelCommand");
28
28
  const { applyUcodePlanCommand } = require("./context/planMode");
29
+ const { setLauncherReady } = require("../agents/launch/launcherReadiness");
29
30
 
30
31
  function printPrompt(stdout = process.stdout) {
31
32
  stdout.write("> ");
@@ -79,7 +80,6 @@ function extractAgentNickname(agentId = "") {
79
80
  // Common agent nickname mappings
80
81
  if (base === "ufoo-agent") return "ufoo";
81
82
  if (base === "claude-code") return "claude";
82
- if (base === "ufoo-code") return "ucode";
83
83
 
84
84
  // Return base name as-is for others
85
85
  return base;
@@ -142,7 +142,7 @@ function runSingleCommand(line = "", workspaceRoot = process.cwd()) {
142
142
  if (!modelId || parts.length > 2) {
143
143
  return {
144
144
  kind: "error",
145
- output: "usage: /model [model-id] [off|low|medium|high|max]",
145
+ output: "usage: /model [model-id] [off|low|medium|high|xhigh|max]",
146
146
  };
147
147
  }
148
148
  return {
@@ -318,7 +318,6 @@ async function runUcodeCoreAgent({
318
318
  currentThinkingLevel,
319
319
  } = require("./modelCommand");
320
320
  const {
321
- resolveThinkingFromEnvAndConfig,
322
321
  applyThinkingLevelToEnv,
323
322
  } = require("./thinkingLevels");
324
323
  const { loadGlobalUcodeConfig } = require("../config");
@@ -328,10 +327,6 @@ async function runUcodeCoreAgent({
328
327
  } catch {
329
328
  initialThinking = "";
330
329
  }
331
- const thinkingResolved = resolveThinkingFromEnvAndConfig({
332
- env: process.env,
333
- configLevel: initialThinking,
334
- });
335
330
  const state = {
336
331
  workspaceRoot: resolvedWorkspaceRoot,
337
332
  provider: resolvedUcode.provider,
@@ -351,10 +346,7 @@ async function runUcodeCoreAgent({
351
346
  maxToolCalls,
352
347
  jsonOutput,
353
348
  };
354
- // Named levels sync into env; leave an explicit numeric budget override alone.
355
- if (thinkingResolved.source !== "env-budget") {
356
- applyThinkingLevelToEnv(state.thinking, process.env);
357
- }
349
+ applyThinkingLevelToEnv(state.thinking, process.env);
358
350
  persistSessionState(state);
359
351
 
360
352
  if (shouldUseUcodeTui({
@@ -367,6 +359,7 @@ async function runUcodeCoreAgent({
367
359
  return runUcodeTui({
368
360
  stdin,
369
361
  stdout,
362
+ onReady: () => setLauncherReady(workspaceRoot, process.env.UFOO_SUBSCRIBER_ID || "", true),
370
363
  runSingleCommand,
371
364
  runNaturalLanguageTask,
372
365
  runUbusCommand,
@@ -74,9 +74,8 @@ function normalizeContextPolicy(value = {}) {
74
74
  return {
75
75
  ...defaults,
76
76
  ...source,
77
- transcriptWindow: Number.isFinite(source.transcriptWindow)
78
- ? Math.max(1, Math.floor(source.transcriptWindow))
79
- : defaults.transcriptWindow,
77
+ maxMessages: Number.isFinite(source.maxMessages) ? Math.max(1, Math.floor(source.maxMessages)) : defaults.maxMessages,
78
+ keepRecentUnits: Number.isFinite(source.keepRecentUnits) ? Math.max(1, Math.floor(source.keepRecentUnits)) : defaults.keepRecentUnits,
80
79
  };
81
80
  }
82
81
 
@@ -268,6 +267,7 @@ function deleteSessionData(workspaceRoot = process.cwd(), sessionId = "") {
268
267
  deleteTranscript(workspaceRoot, normalizedId);
269
268
  deleteSessionArtifacts(workspaceRoot, normalizedId);
270
269
  deleteSessionCommitLog(workspaceRoot, normalizedId);
270
+ require("../agents/runtime/context/checkpointStore").createCheckpointStore({ workspaceRoot, namespace: "ucode", sessionId: normalizedId }).remove();
271
271
  return { ok: true, error: "" };
272
272
  } catch (err) {
273
273
  return {
@@ -11,6 +11,8 @@ const {
11
11
  renderActiveSkillBlock,
12
12
  } = require("./skills");
13
13
  const { sanitizeSkillContent } = require("./skills/injection");
14
+ const { randomUUID } = require("crypto");
15
+ const { normalizeTraceContext } = require("../agents/runtime/protocol/traceContext");
14
16
 
15
17
  function renderActiveSkillBodiesFromState(state = {}) {
16
18
  const skills = Array.isArray(state.activeSkills) ? state.activeSkills : [];
@@ -162,6 +164,13 @@ async function runDecomposedTask({
162
164
  sessionId = "",
163
165
  state = null,
164
166
  systemBlocks = null,
167
+ runtimeContext = {},
168
+ onRuntimeEvent = null,
169
+ onStreamDelta = null,
170
+ onThinkingDelta = null,
171
+ onPhase = null,
172
+ onContextUsage = null,
173
+ contextPolicy = {},
165
174
  }) {
166
175
  const steps = decomposeBugFixTask(task);
167
176
  const results = [];
@@ -211,6 +220,7 @@ async function runDecomposedTask({
211
220
  stepSystemPrompt = assembled.systemPrompt;
212
221
  stepSystemBlocks = assembled.systemBlocks;
213
222
  }
223
+ const inherited = normalizeTraceContext(runtimeContext);
214
224
  const stepResult = await runNativeAgentTask({
215
225
  workspaceRoot,
216
226
  provider,
@@ -223,6 +233,14 @@ async function runDecomposedTask({
223
233
  timeoutMs: step.timeoutMs,
224
234
  maxToolCalls: state ? state.maxToolCalls : undefined,
225
235
  onToolEvent,
236
+ runtimeContext: inherited.taskRunId ? { ...inherited, parentTaskRunId: inherited.taskRunId,
237
+ taskRunId: `segment-${randomUUID()}`, requestId: `${inherited.requestId || "step"}:${step.id}`, attemptId: `attempt-${randomUUID()}` } : inherited,
238
+ onRuntimeEvent,
239
+ onStreamDelta,
240
+ onThinkingDelta,
241
+ onPhase,
242
+ onContextUsage,
243
+ contextPolicy,
226
244
  signal,
227
245
  onArtifactPersisted: state
228
246
  ? (persisted) => recordToolCallInSession(state, persisted, workspaceRoot)
@@ -1,21 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function parseMaxToolCalls(value) {
4
- if (value == null || String(value).trim().toLowerCase() === "none") return null;
5
- const text = String(value).trim();
6
- const count = Number(text);
7
- if (!/^\d+$/.test(text) || !Number.isSafeInteger(count) || count <= 0) {
8
- throw new Error("max tool calls must be a positive integer or none");
9
- }
10
- return count;
11
- }
12
-
13
- function resolveMaxToolCalls(value, env = process.env) {
14
- if (value !== undefined) return parseMaxToolCalls(value);
15
- const configured = env.UFOO_UCODE_MAX_TOOL_CALLS;
16
- return configured == null || String(configured).trim() === ""
17
- ? null
18
- : parseMaxToolCalls(configured);
19
- }
3
+ const { parseMaxToolCalls, resolveMaxToolCalls } = require("../agents/runtime/core/executionBudget");
20
4
 
21
5
  module.exports = { parseMaxToolCalls, resolveMaxToolCalls };
package/src/config.js CHANGED
@@ -15,8 +15,8 @@ const UCODE_FIELDS = [
15
15
 
16
16
  const SETTINGS_MODEL_DEFAULTS = Object.freeze({
17
17
  agent: Object.freeze({
18
- codex: "gpt-5.5",
19
- claude: "opus-4.7",
18
+ codex: "gpt-6.1-sol",
19
+ claude: "claude-opus-5-5",
20
20
  // agy (Antigravity CLI) only supports model selection via in-REPL
21
21
  // `/model` slash command, which persists across launches. There is no
22
22
  // command-line flag for model, so the value here is a placeholder for
@@ -27,30 +27,23 @@ const SETTINGS_MODEL_DEFAULTS = Object.freeze({
27
27
  kimi: "",
28
28
  "grok-build": "grok-4.6",
29
29
  }),
30
- router: Object.freeze({
31
- codex: "gpt-5.3-codex-spark",
32
- claude: "sonnet-4.7",
33
- agy: "",
34
- kimi: "",
35
- "grok-build": "grok-4.6",
36
- }),
37
30
  });
38
31
 
39
32
  const DEFAULT_CONFIG = {
40
33
  launchMode: "auto",
41
34
  daemonTopology: "global",
42
35
  agentProvider: "codex-cli",
43
- controllerMode: "main",
44
36
  mcpPort: 47631,
45
- codexInternalThreadMode: "api",
46
37
  codexAuthPath: "",
47
38
  codexOauthRefreshWindowSec: 300,
48
39
  claudeOauthProfile: "",
49
40
  claudeOauthTokenPath: "",
50
41
  claudeOauthRefreshWindowSec: 300,
51
42
  agentModel: "",
52
- routerProvider: "",
53
- routerModel: "",
43
+ agentBaseUrl: "",
44
+ agentApiKey: "",
45
+ agentThinking: "medium",
46
+ agentModelRevision: 0,
54
47
  autoResume: false,
55
48
  };
56
49
 
@@ -81,6 +74,7 @@ function normalizeDaemonTopology(value) {
81
74
  }
82
75
 
83
76
  function normalizeAgentProvider(value) {
77
+ if (value === "custom") return "custom";
84
78
  if (value === "claude-cli") return "claude-cli";
85
79
  if (value === "agy-cli" || value === "agy" || value === "antigravity") return "agy-cli";
86
80
  if (value === "kimi-cli" || value === "kimi") return "kimi-cli";
@@ -90,6 +84,7 @@ function normalizeAgentProvider(value) {
90
84
 
91
85
  function providerKey(value = "") {
92
86
  const text = String(value || "").trim().toLowerCase();
87
+ if (text === "custom" || text === "openai") return "openai";
93
88
  if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") return "claude";
94
89
  if (text === "agy" || text === "agy-cli" || text === "antigravity") return "agy";
95
90
  if (text === "kimi" || text === "kimi-cli" || text === "kimi-code") return "kimi";
@@ -104,45 +99,15 @@ function sameModelProvider(left = "", right = "") {
104
99
  }
105
100
 
106
101
  function defaultAgentModelForProvider(value = "") {
102
+ if (value === "custom") return "";
107
103
  return SETTINGS_MODEL_DEFAULTS.agent[providerKey(value)] || SETTINGS_MODEL_DEFAULTS.agent.codex;
108
104
  }
109
105
 
110
- function defaultRouterProviderForAgentProvider(value = "") {
111
- const key = providerKey(value);
112
- if (key === "claude") return "claude";
113
- // agy has no router-model API; fall back to codex (the controller still
114
- // routes via codex/claude regardless of which agent provider runs).
115
- if (key === "agy") return "codex";
116
- // kimi likewise manages its own models; router falls back to codex.
117
- if (key === "kimi") return "codex";
118
- return "codex";
119
- }
120
-
121
- function defaultRouterModelForProvider(value = "") {
122
- return SETTINGS_MODEL_DEFAULTS.router[providerKey(value)] || SETTINGS_MODEL_DEFAULTS.router.codex;
123
- }
124
-
125
106
  function normalizeModel(value, fallback = "") {
126
107
  const text = typeof value === "string" ? value.trim() : "";
127
108
  return text || fallback;
128
109
  }
129
110
 
130
- function normalizeControllerMode(value) {
131
- const raw = String(value || "").trim().toLowerCase();
132
- if (raw === "shadow") return "shadow";
133
- if (raw === "router-api") return "main";
134
- if (raw === "main") return "main";
135
- if (raw === "loop") return "loop";
136
- return "legacy";
137
- }
138
-
139
- function normalizeCodexInternalThreadMode(value) {
140
- const raw = String(value || "").trim().toLowerCase();
141
- if (raw === "api" || raw === "direct" || raw === "direct-api" || raw === "upstream") return "api";
142
- if (raw === "sdk") return "api";
143
- return "legacy";
144
- }
145
-
146
111
  function normalizeMcpPort(value) {
147
112
  const parsed = Number.parseInt(value, 10);
148
113
  if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535) return DEFAULT_CONFIG.mcpPort;
@@ -200,15 +165,19 @@ function loadJsonForUpdate(filePath) {
200
165
  }
201
166
  }
202
167
 
168
+ function withoutRemovedSettings(config) {
169
+ const next = { ...config };
170
+ for (const key of ["controllerMode", "routerProvider", "routerModel", "routerTimeoutMs", "routerConfidenceThreshold", "codexInternalThreadMode"]) {
171
+ delete next[key];
172
+ }
173
+ return next;
174
+ }
175
+
203
176
  function loadConfig(projectRoot) {
204
177
  try {
205
- const raw = loadJsonSafe(configPath(projectRoot));
178
+ const raw = withoutRemovedSettings(loadJsonSafe(configPath(projectRoot)));
206
179
  const globalRaw = loadJsonSafe(globalConfigPath());
207
180
  const agentProvider = normalizeAgentProvider(raw.agentProvider);
208
- const routerProvider = normalizeModel(
209
- raw.routerProvider,
210
- defaultRouterProviderForAgentProvider(agentProvider)
211
- );
212
181
  return {
213
182
  ...DEFAULT_CONFIG,
214
183
  ...raw,
@@ -220,15 +189,7 @@ function loadConfig(projectRoot) {
220
189
  ),
221
190
  agentProvider,
222
191
  agentModel: normalizeModel(raw.agentModel, defaultAgentModelForProvider(agentProvider)),
223
- routerProvider,
224
- routerModel: normalizeModel(raw.routerModel, defaultRouterModelForProvider(routerProvider)),
225
- controllerMode: Object.prototype.hasOwnProperty.call(raw, "controllerMode")
226
- ? normalizeControllerMode(raw.controllerMode)
227
- : DEFAULT_CONFIG.controllerMode,
228
192
  mcpPort: normalizeMcpPort(raw.mcpPort),
229
- codexInternalThreadMode: Object.prototype.hasOwnProperty.call(raw, "codexInternalThreadMode")
230
- ? normalizeCodexInternalThreadMode(raw.codexInternalThreadMode)
231
- : DEFAULT_CONFIG.codexInternalThreadMode,
232
193
  codexAuthPath: normalizeCodexAuthPath(raw.codexAuthPath),
233
194
  codexOauthRefreshWindowSec: normalizeCodexOauthRefreshWindowSec(raw.codexOauthRefreshWindowSec),
234
195
  claudeOauthProfile: normalizeClaudeOauthProfile(raw.claudeOauthProfile),
@@ -240,12 +201,9 @@ function loadConfig(projectRoot) {
240
201
  };
241
202
  } catch {
242
203
  const agentProvider = DEFAULT_CONFIG.agentProvider;
243
- const routerProvider = defaultRouterProviderForAgentProvider(agentProvider);
244
204
  return {
245
205
  ...DEFAULT_CONFIG,
246
206
  agentModel: defaultAgentModelForProvider(agentProvider),
247
- routerProvider,
248
- routerModel: defaultRouterModelForProvider(routerProvider),
249
207
  ...DEFAULT_UCODE_CONFIG,
250
208
  };
251
209
  }
@@ -263,11 +221,11 @@ function saveConfig(projectRoot, config) {
263
221
  projectUpdates[k] = v;
264
222
  }
265
223
  }
266
- const merged = {
224
+ const merged = withoutRemovedSettings({
267
225
  ...DEFAULT_CONFIG,
268
226
  ...existing,
269
227
  ...projectUpdates,
270
- };
228
+ });
271
229
  const hasProjectDaemonTopology =
272
230
  Object.prototype.hasOwnProperty.call(existing, "daemonTopology")
273
231
  || Object.prototype.hasOwnProperty.call(projectUpdates, "daemonTopology");
@@ -286,11 +244,7 @@ function saveConfig(projectRoot, config) {
286
244
  }
287
245
  merged.agentProvider = normalizeAgentProvider(merged.agentProvider);
288
246
  merged.agentModel = typeof merged.agentModel === "string" ? merged.agentModel.trim() : "";
289
- merged.routerProvider = typeof merged.routerProvider === "string" ? merged.routerProvider.trim() : "";
290
- merged.routerModel = typeof merged.routerModel === "string" ? merged.routerModel.trim() : "";
291
- merged.controllerMode = normalizeControllerMode(merged.controllerMode);
292
247
  merged.mcpPort = normalizeMcpPort(merged.mcpPort);
293
- merged.codexInternalThreadMode = normalizeCodexInternalThreadMode(merged.codexInternalThreadMode);
294
248
  merged.codexAuthPath = normalizeCodexAuthPath(merged.codexAuthPath);
295
249
  merged.codexOauthRefreshWindowSec = normalizeCodexOauthRefreshWindowSec(merged.codexOauthRefreshWindowSec);
296
250
  merged.claudeOauthProfile = normalizeClaudeOauthProfile(merged.claudeOauthProfile);
@@ -319,7 +273,7 @@ function saveGlobalUcodeConfig(updates = {}) {
319
273
  return withFileLock(target, () => {
320
274
  fs.mkdirSync(path.dirname(target), { recursive: true });
321
275
  const existing = loadJsonForUpdate(target);
322
- const merged = { ...existing };
276
+ const merged = withoutRemovedSettings(existing);
323
277
  for (const [k, v] of Object.entries(updates)) {
324
278
  if (UCODE_FIELDS.includes(k)) {
325
279
  merged[k] = typeof v === "string" ? v : "";
@@ -342,7 +296,7 @@ function saveGlobalDaemonConfig(updates = {}) {
342
296
  return withFileLock(target, () => {
343
297
  fs.mkdirSync(path.dirname(target), { recursive: true });
344
298
  const existing = loadJsonForUpdate(target);
345
- const merged = { ...existing };
299
+ const merged = withoutRemovedSettings(existing);
346
300
  if (Object.prototype.hasOwnProperty.call(updates, "daemonTopology")) {
347
301
  merged.daemonTopology = normalizeDaemonTopology(updates.daemonTopology);
348
302
  }
@@ -365,11 +319,7 @@ module.exports = {
365
319
  providerKey,
366
320
  sameModelProvider,
367
321
  defaultAgentModelForProvider,
368
- defaultRouterProviderForAgentProvider,
369
- defaultRouterModelForProvider,
370
- normalizeControllerMode,
371
322
  normalizeMcpPort,
372
- normalizeCodexInternalThreadMode,
373
323
  normalizeCodexAuthPath,
374
324
  normalizeCodexOauthRefreshWindowSec,
375
325
  normalizeClaudeOauthProfile,