u-foo 3.0.29 → 3.0.32

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 (48) hide show
  1. package/README.md +13 -8
  2. package/bin/ufoo.js +7 -2
  3. package/bin/ugrok.js +68 -0
  4. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  5. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  6. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  7. package/dist/tui/linux-x64/ufoo-tui +0 -0
  8. package/package.json +2 -1
  9. package/src/agents/activity/activityDetector.js +95 -0
  10. package/src/agents/controller/ufooAgent.js +3 -3
  11. package/src/agents/launch/launcher.js +17 -11
  12. package/src/agents/launch/notifier.js +25 -3
  13. package/src/agents/launch/ptyRunner.js +34 -12
  14. package/src/agents/launch/readyDetector.js +27 -0
  15. package/src/agents/prompts/defaultBootstrap.js +126 -1
  16. package/src/agents/providers/directAuthStatus.js +79 -0
  17. package/src/agents/providers/upstreamTransport.js +234 -85
  18. package/src/app/chat/commandExecutor.js +18 -10
  19. package/src/app/chat/commands.js +4 -2
  20. package/src/app/cli/run.js +7 -5
  21. package/src/code/UcodeController.js +201 -40
  22. package/src/code/agent.js +9 -2
  23. package/src/code/commands.js +13 -0
  24. package/src/code/dispatch.js +9 -1
  25. package/src/code/index.js +9 -2
  26. package/src/code/nativeRunner.js +398 -16
  27. package/src/code/providers/index.js +1 -0
  28. package/src/code/providers/modelsCatalog.js +21 -6
  29. package/src/code/providers/openaiResponsesTransport.js +119 -0
  30. package/src/code/providers/responsesProtocol.js +499 -0
  31. package/src/code/providers/transportContract.js +5 -1
  32. package/src/code/repl.js +95 -2
  33. package/src/code/tools/bash.js +159 -6
  34. package/src/code/ucodeSlashDispatch.js +13 -0
  35. package/src/config.js +6 -0
  36. package/src/coordination/bus/deliveryQueue.js +30 -9
  37. package/src/coordination/bus/inject.js +2 -2
  38. package/src/coordination/bus/message.js +1 -1
  39. package/src/coordination/bus/utils.js +4 -1
  40. package/src/orchestration/controller/gateRouter.js +2 -2
  41. package/src/orchestration/controller/launchRouting.js +2 -1
  42. package/src/orchestration/groups/validateTemplate.js +1 -1
  43. package/src/orchestration/solo/commands.js +1 -0
  44. package/src/runtime/daemon/deliveryScheduler.js +53 -7
  45. package/src/runtime/daemon/index.js +12 -4
  46. package/src/runtime/daemon/nicknameScope.js +4 -1
  47. package/src/runtime/daemon/ops.js +8 -2
  48. package/src/ui/rustUcodeHost.js +86 -10
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ const os = require("os");
3
4
  const { randomUUID } = require("crypto");
4
5
  const {
5
6
  loadConfig,
@@ -12,6 +13,11 @@ const {
12
13
  resolveCompletionUrl,
13
14
  resolveAnthropicMessagesUrl,
14
15
  } = require("../../code/nativeRunner");
16
+ const {
17
+ buildResponsesPayload,
18
+ parseResponsesEvents,
19
+ resolveResponsesUrl,
20
+ } = require("../../code/providers/responsesProtocol");
15
21
  const { resolveClaudeUpstreamCredentials } = require("./credentials/claude");
16
22
  const { resolveCodexUpstreamCredentials } = require("./credentials/codex");
17
23
  const { buildUpstreamAuthFromCredential } = require("./credentials");
@@ -21,6 +27,7 @@ function normalizeProvider(value = "") {
21
27
  if (!text) return "ucode";
22
28
  if (text === "codex-cli" || text === "codex-code" || text === "codex" || text === "openai") return "codex";
23
29
  if (text === "claude-cli" || text === "claude-code" || text === "claude" || text === "anthropic") return "claude";
30
+ if (text === "grok" || text === "grok-cli" || text === "grok-build" || text === "grok-shell" || text === "grok-api" || text === "xai") return "grok";
24
31
  if (text === "ucode" || text === "ufoo" || text === "ufoo-code") return "ucode";
25
32
  return text;
26
33
  }
@@ -34,6 +41,71 @@ function clipText(value = "", maxChars = 500) {
34
41
  const CODEX_DEFAULT_BASE_URL = "https://chatgpt.com/backend-api/codex";
35
42
  const CODEX_DEFAULT_USER_AGENT = "codex-tui/0.118.0 (Mac OS 26.3.1; arm64) iTerm.app/3.6.9 (codex-tui; 0.118.0)";
36
43
  const CODEX_DEFAULT_ORIGINATOR = "codex-tui";
44
+ const GROK_DEFAULT_CLIENT_VERSION = "0.2.120";
45
+ const KIMI_DEFAULT_CLIENT_VERSION = (() => {
46
+ try {
47
+ return String(require("../../../package.json").version || "dev").trim() || "dev";
48
+ } catch {
49
+ return "dev";
50
+ }
51
+ })();
52
+
53
+ function normalizeKimiUpstreamModel(value = "") {
54
+ const raw = String(value || "").trim();
55
+ if (!raw) return "";
56
+ const suffix = raw.match(/^(.*?)(\([^)]*\))$/);
57
+ const base = String(suffix ? suffix[1] : raw).trim().replace(/\[1m\]$/i, "");
58
+ const lower = base.toLowerCase();
59
+ let normalized = lower;
60
+ if (["kimi-k2.7-code", "k2.7-code", "kimi-for-coding", "for-coding"].includes(lower)) {
61
+ normalized = "kimi-for-coding";
62
+ } else if (["kimi-k2.7-code-highspeed", "k2.7-code-highspeed", "kimi-for-coding-highspeed", "for-coding-highspeed"].includes(lower)) {
63
+ normalized = "kimi-for-coding-highspeed";
64
+ } else if (normalized.startsWith("kimi-")) {
65
+ normalized = normalized.slice("kimi-".length);
66
+ }
67
+ return `${normalized}${suffix ? suffix[2] : ""}`;
68
+ }
69
+
70
+ function applyKimiHeaders(headers, { apiKey = "", stream = false } = {}) {
71
+ const version = String(process.env.UFOO_KIMI_CLIENT_VERSION || KIMI_DEFAULT_CLIENT_VERSION).trim()
72
+ || KIMI_DEFAULT_CLIENT_VERSION;
73
+ if (apiKey) headers.authorization = `Bearer ${apiKey}`;
74
+ headers["User-Agent"] = `ufoo/${version}`;
75
+ headers["X-Msh-Platform"] = "ufoo";
76
+ headers["X-Msh-Version"] = version;
77
+ headers["X-Msh-Device-Name"] = os.hostname();
78
+ headers["X-Msh-Device-Model"] = `${process.platform} ${process.arch}`;
79
+ headers["X-Msh-Device-Id"] = String(process.env.KIMI_DEVICE_ID || "ufoo-kimi-device").trim() || "ufoo-kimi-device";
80
+ headers.Accept = stream ? "text/event-stream" : "application/json";
81
+ return headers;
82
+ }
83
+
84
+ function isGrokCliProxyUrl(url = "") {
85
+ try {
86
+ return new URL(String(url || "")).hostname.toLowerCase() === "cli-chat-proxy.grok.com";
87
+ } catch {
88
+ return false;
89
+ }
90
+ }
91
+
92
+ function applyGrokResponsesHeaders(headers, { provider = "", baseUrl = "", sessionId = "" } = {}) {
93
+ const normalizedProvider = normalizeProvider(provider);
94
+ if (normalizedProvider !== "grok" && normalizedProvider !== "xai") return headers;
95
+ const version = String(process.env.UFOO_GROK_CLIENT_VERSION || GROK_DEFAULT_CLIENT_VERSION).trim()
96
+ || GROK_DEFAULT_CLIENT_VERSION;
97
+ if (sessionId) headers["x-grok-conv-id"] = String(sessionId);
98
+ if (isGrokCliProxyUrl(baseUrl)) {
99
+ headers["X-XAI-Token-Auth"] = "xai-grok-cli";
100
+ headers["x-grok-client-version"] = version;
101
+ headers["x-grok-client-identifier"] = "grok-shell";
102
+ headers["x-authenticateresponse"] = "authenticate-response";
103
+ headers["User-Agent"] = `xai-grok-workspace/${version}`;
104
+ } else if (normalizedProvider === "grok") {
105
+ headers["User-Agent"] = `grok-shell/${version}`;
106
+ }
107
+ return headers;
108
+ }
37
109
 
38
110
  function resolveConfiguredModelForProvider(config = {}, provider = "") {
39
111
  if (config.routerProvider && sameModelProvider(config.routerProvider, provider)) {
@@ -145,38 +217,23 @@ function buildCodexResponsesRequest({
145
217
  systemPrompt = "",
146
218
  prompt = "",
147
219
  messages = [],
220
+ tools = [],
221
+ maxTokens = 131072,
222
+ reasoningEffort = "",
148
223
  } = {}) {
149
- const input = [];
150
- const history = Array.isArray(messages) ? messages : [];
151
- for (const message of history) {
152
- if (!message || typeof message !== "object") continue;
153
- const role = String(message.role || "user").trim() || "user";
154
- let content = message.content;
155
- if (Array.isArray(content)) {
156
- content = content
157
- .map((item) => {
158
- if (!item || typeof item !== "object") return "";
159
- return String(item.text || item.content || "");
160
- })
161
- .join("");
162
- }
163
- input.push(normalizeCodexMessage(role, content));
224
+ const inputMessages = Array.isArray(messages) ? messages.slice() : [];
225
+ if (String(prompt || "").trim()) {
226
+ inputMessages.push({ role: "user", content: String(prompt || "") });
164
227
  }
165
- input.push(normalizeCodexMessage("user", prompt));
166
-
167
- return {
168
- model: String(model || "").trim(),
169
- instructions: String(systemPrompt || ""),
170
- stream: true,
171
- store: false,
172
- parallel_tool_calls: true,
173
- include: ["reasoning.encrypted_content"],
174
- reasoning: {
175
- effort: "medium",
176
- summary: "auto",
177
- },
178
- input,
179
- };
228
+ return buildResponsesPayload({
229
+ model,
230
+ instructions: systemPrompt,
231
+ messages: inputMessages,
232
+ tools,
233
+ maxOutputTokens: maxTokens,
234
+ reasoningEffort,
235
+ provider: "codex",
236
+ });
180
237
  }
181
238
 
182
239
  function resolveCodexResponseOutput(response = {}) {
@@ -191,52 +248,55 @@ function resolveCodexResponseOutput(response = {}) {
191
248
 
192
249
  function parseCodexSsePayload(payload = "") {
193
250
  const lines = String(payload || "").split(/\r?\n/);
194
- const chunks = [];
195
- let text = "";
196
- let responseObject = null;
197
- let usage = null;
198
-
251
+ const frames = [];
252
+ let currentEvent = "";
199
253
  for (const line of lines) {
200
254
  const trimmed = line.trim();
255
+ if (trimmed.startsWith("event:")) {
256
+ currentEvent = trimmed.slice(6).trim();
257
+ continue;
258
+ }
201
259
  if (!trimmed.startsWith("data:")) continue;
202
260
  const dataText = trimmed.slice(5).trim();
203
261
  if (!dataText || dataText === "[DONE]") continue;
204
- let event;
205
262
  try {
206
- event = JSON.parse(dataText);
263
+ const data = JSON.parse(dataText);
264
+ frames.push({ event: currentEvent || data.type || "", data });
265
+ currentEvent = "";
207
266
  } catch {
208
267
  continue;
209
268
  }
210
- chunks.push(event);
211
- const type = String(event.type || "");
212
- if (type === "response.output_text.delta" && typeof event.delta === "string") {
213
- text += event.delta;
214
- continue;
215
- }
216
- if (type === "response.output_item.done" && event.item && event.item.type === "message" && !text) {
217
- const content = Array.isArray(event.item.content) ? event.item.content : [];
218
- text += content
219
- .filter((part) => part && part.type === "output_text")
220
- .map((part) => String(part.text || ""))
221
- .join("");
222
- continue;
223
- }
224
- if (type === "response.completed" && event.response && typeof event.response === "object") {
225
- responseObject = event.response;
226
- usage = event.response.usage && typeof event.response.usage === "object"
227
- ? event.response.usage
228
- : null;
229
- if (!text) {
230
- text = resolveCodexResponseOutput(event.response);
231
- }
232
- }
233
269
  }
234
270
 
271
+ const parsed = parseResponsesEvents(frames);
272
+ const rawUsage = parsed.response && parsed.response.usage && typeof parsed.response.usage === "object"
273
+ ? parsed.response.usage
274
+ : null;
275
+
235
276
  return {
236
- text: String(text || "").trim(),
237
- response: responseObject,
238
- usage,
239
- events: chunks,
277
+ text: String(parsed.text || "").trim(),
278
+ response: parsed.response,
279
+ usage: rawUsage,
280
+ normalizedUsage: parsed.usage,
281
+ toolCalls: parsed.toolCalls,
282
+ terminal: parsed.terminal,
283
+ incompleteDetails: parsed.incompleteDetails,
284
+ events: parsed.events,
285
+ };
286
+ }
287
+
288
+ function resolveUpstreamResponsesUsage(parsed = {}) {
289
+ const raw = parsed.response && parsed.response.usage && typeof parsed.response.usage === "object"
290
+ ? parsed.response.usage
291
+ : null;
292
+ if (raw) return raw;
293
+ const normalized = parsed.usage && typeof parsed.usage === "object" ? parsed.usage : null;
294
+ if (!normalized) return null;
295
+ return {
296
+ input_tokens: Number(normalized.input || 0) || 0,
297
+ output_tokens: Number(normalized.output || 0) || 0,
298
+ cache_read_input_tokens: Number(normalized.cacheRead || 0) || 0,
299
+ cache_creation_input_tokens: Number(normalized.cacheCreation || 0) || 0,
240
300
  };
241
301
  }
242
302
 
@@ -258,8 +318,8 @@ async function resolveUpstreamRuntime({
258
318
  fetchImpl,
259
319
  env,
260
320
  });
261
- const useCodexResponses = credential.credentialKind === "oauth" && Boolean(credential.accessToken);
262
- const baseUrl = useCodexResponses
321
+ const useCodexOAuth = credential.credentialKind === "oauth" && Boolean(credential.accessToken);
322
+ const baseUrl = useCodexOAuth
263
323
  ? String(env.UFOO_CODEX_BASE_URL || "").trim() || CODEX_DEFAULT_BASE_URL
264
324
  : String(env.OPENAI_BASE_URL || "").trim() || "https://api.openai.com/v1";
265
325
  const resolvedModel = String(
@@ -269,7 +329,7 @@ async function resolveUpstreamRuntime({
269
329
  ).trim();
270
330
  return {
271
331
  provider: "codex",
272
- transport: useCodexResponses ? "codex-responses" : "openai-chat",
332
+ transport: "codex-responses",
273
333
  model: resolvedModel,
274
334
  baseUrl,
275
335
  credential,
@@ -302,6 +362,24 @@ async function resolveUpstreamRuntime({
302
362
  };
303
363
  }
304
364
 
365
+ if (normalizedProvider === "grok") {
366
+ const runtime = resolveRuntimeConfig({
367
+ workspaceRoot: projectRoot,
368
+ provider: "grok-build",
369
+ model: model || resolveConfiguredModelForProvider(config, "grok-build") || defaultRouterModelForProvider("grok-build"),
370
+ });
371
+ const auth = runtime.apiKey ? { apiKey: String(runtime.apiKey).trim() } : { headers: {} };
372
+ return {
373
+ provider: "grok-build",
374
+ transport: "openai-responses",
375
+ model: String(runtime.model || model || "").trim(),
376
+ baseUrl: String(runtime.baseUrl || "").trim(),
377
+ credential: null,
378
+ auth,
379
+ credentialSource: runtime.apiKey ? "runtime-api-key" : "",
380
+ };
381
+ }
382
+
305
383
  const runtime = resolveRuntimeConfig({
306
384
  workspaceRoot: projectRoot,
307
385
  provider: normalizedProvider === "ucode" ? "" : normalizedProvider,
@@ -322,6 +400,7 @@ async function resolveUpstreamRuntime({
322
400
  async function sendUpstreamRequest({
323
401
  runtime,
324
402
  request,
403
+ sessionId = "",
325
404
  timeoutMs = 120000,
326
405
  fetchImpl = global.fetch,
327
406
  } = {}) {
@@ -329,17 +408,20 @@ async function sendUpstreamRequest({
329
408
  return { ok: false, error: "fetch is unavailable" };
330
409
  }
331
410
  const resolvedRuntime = runtime && typeof runtime === "object" ? runtime : {};
332
- const requestModel = String((request && request.model) || resolvedRuntime.model || "").trim();
411
+ const rawRequestModel = String((request && request.model) || resolvedRuntime.model || "").trim();
412
+ const isKimi = normalizeProvider(resolvedRuntime.provider) === "kimi";
413
+ const requestModel = isKimi ? normalizeKimiUpstreamModel(rawRequestModel) : rawRequestModel;
333
414
  if (!requestModel) {
334
415
  return { ok: false, error: `${resolvedRuntime.provider || "provider"} model is not configured` };
335
416
  }
336
417
 
337
418
  const isAnthropic = resolvedRuntime.transport === "anthropic-messages";
338
419
  const isCodexResponses = resolvedRuntime.transport === "codex-responses";
420
+ const isResponses = isCodexResponses || resolvedRuntime.transport === "openai-responses";
339
421
  const url = isAnthropic
340
422
  ? resolveAnthropicMessagesUrl(resolvedRuntime.baseUrl)
341
- : isCodexResponses
342
- ? `${String(resolvedRuntime.baseUrl || "").replace(/\/+$/, "")}/responses`
423
+ : isResponses
424
+ ? resolveResponsesUrl(resolvedRuntime.baseUrl)
343
425
  : resolveCompletionUrl(resolvedRuntime.baseUrl);
344
426
 
345
427
  if (!url) {
@@ -353,19 +435,45 @@ async function sendUpstreamRequest({
353
435
  if (isAnthropic) {
354
436
  headers["anthropic-version"] = "2023-06-01";
355
437
  if (resolvedRuntime.auth && resolvedRuntime.auth.apiKey) headers["x-api-key"] = resolvedRuntime.auth.apiKey;
356
- } else if (isCodexResponses) {
438
+ } else if (isResponses) {
357
439
  headers.Accept = "text/event-stream";
358
440
  headers.Connection = "Keep-Alive";
359
- headers["User-Agent"] = CODEX_DEFAULT_USER_AGENT;
360
- headers.Originator = CODEX_DEFAULT_ORIGINATOR;
361
- if (resolvedRuntime.credential && resolvedRuntime.credential.accountId) {
362
- headers["Chatgpt-Account-Id"] = String(resolvedRuntime.credential.accountId);
441
+ if (resolvedRuntime.auth && resolvedRuntime.auth.apiKey) {
442
+ headers.authorization = `Bearer ${resolvedRuntime.auth.apiKey}`;
443
+ }
444
+ const resolvedSessionId = String(
445
+ sessionId
446
+ || (request && (request.sessionId || request.session_id))
447
+ || resolvedRuntime.sessionId
448
+ || ""
449
+ ).trim() || randomUUID();
450
+ if (isCodexResponses) {
451
+ headers["User-Agent"] = CODEX_DEFAULT_USER_AGENT;
452
+ headers.Originator = CODEX_DEFAULT_ORIGINATOR;
453
+ if (resolvedRuntime.credential && resolvedRuntime.credential.accountId) {
454
+ headers["Chatgpt-Account-Id"] = String(resolvedRuntime.credential.accountId);
455
+ }
456
+ headers["Session-Id"] = resolvedSessionId;
457
+ } else {
458
+ applyGrokResponsesHeaders(headers, {
459
+ provider: resolvedRuntime.provider,
460
+ baseUrl: resolvedRuntime.baseUrl,
461
+ sessionId: resolvedSessionId,
462
+ });
363
463
  }
364
- headers.Session_id = randomUUID();
365
464
  } else {
366
- if (resolvedRuntime.auth && resolvedRuntime.auth.apiKey) headers.authorization = `Bearer ${resolvedRuntime.auth.apiKey}`;
465
+ if (isKimi) {
466
+ applyKimiHeaders(headers, {
467
+ apiKey: resolvedRuntime.auth && resolvedRuntime.auth.apiKey,
468
+ stream: Boolean(request && request.stream),
469
+ });
470
+ } else if (resolvedRuntime.auth && resolvedRuntime.auth.apiKey) {
471
+ headers.authorization = `Bearer ${resolvedRuntime.auth.apiKey}`;
472
+ }
367
473
  }
368
- const body = JSON.stringify(request || {});
474
+ const requestBody = request && typeof request === "object" ? { ...request } : {};
475
+ if (isKimi) requestBody.model = requestModel;
476
+ const body = JSON.stringify(requestBody);
369
477
 
370
478
  const controller = new AbortController();
371
479
  const timer = setTimeout(() => {
@@ -392,9 +500,34 @@ async function sendUpstreamRequest({
392
500
  };
393
501
  }
394
502
 
395
- if (isCodexResponses) {
396
- const raw = await response.text();
397
- const parsed = parseCodexSsePayload(raw);
503
+ if (isResponses) {
504
+ // Responses supports both the normal streaming form and a complete JSON
505
+ // response. The provider contract is still Responses-only here; the
506
+ // JSON branch is useful for non-streaming gateways and test doubles.
507
+ let parsed;
508
+ let rawData = null;
509
+ if (typeof response.text === "function") {
510
+ const raw = await response.text();
511
+ parsed = parseCodexSsePayload(raw);
512
+ if (!parsed.response && !parsed.text && parsed.toolCalls.length === 0) {
513
+ try {
514
+ rawData = JSON.parse(raw);
515
+ parsed = parseResponsesEvents([
516
+ { event: rawData && rawData.type ? rawData.type : "response", data: rawData },
517
+ ], { assumeCompleted: true });
518
+ } catch {
519
+ // Keep the SSE parse result; the caller will receive an empty
520
+ // completed response rather than falling back to Chat Completions.
521
+ }
522
+ }
523
+ } else if (typeof response.json === "function") {
524
+ rawData = await response.json();
525
+ parsed = parseResponsesEvents([
526
+ { event: rawData && rawData.type ? rawData.type : "response", data: rawData },
527
+ ], { assumeCompleted: true });
528
+ } else {
529
+ parsed = parseResponsesEvents([], { assumeCompleted: true });
530
+ }
398
531
  return {
399
532
  ok: true,
400
533
  output: parsed.text,
@@ -402,8 +535,10 @@ async function sendUpstreamRequest({
402
535
  model: requestModel,
403
536
  transport: resolvedRuntime.transport,
404
537
  credentialSource: resolvedRuntime.credentialSource,
405
- data: parsed.response,
406
- usage: parsed.usage,
538
+ data: parsed.response || rawData,
539
+ usage: resolveUpstreamResponsesUsage(parsed),
540
+ toolCalls: parsed.toolCalls,
541
+ incompleteDetails: parsed.incompleteDetails,
407
542
  };
408
543
  }
409
544
 
@@ -459,6 +594,7 @@ async function sendUpstreamPrompt({
459
594
  tools = [],
460
595
  maxTokens = 4096,
461
596
  temperature = 0,
597
+ sessionId = "",
462
598
  timeoutMs = 120000,
463
599
  fetchImpl = global.fetch,
464
600
  env = process.env,
@@ -501,8 +637,19 @@ async function sendUpstreamPrompt({
501
637
  systemPrompt,
502
638
  prompt,
503
639
  messages,
504
- })
505
- : buildOpenAiChatRequest({
640
+ tools,
641
+ maxTokens,
642
+ })
643
+ : runtime.transport === "openai-responses"
644
+ ? buildCodexResponsesRequest({
645
+ model: requestModel,
646
+ systemPrompt,
647
+ prompt,
648
+ messages,
649
+ tools,
650
+ maxTokens,
651
+ })
652
+ : buildOpenAiChatRequest({
506
653
  model: requestModel,
507
654
  systemPrompt,
508
655
  prompt,
@@ -514,6 +661,7 @@ async function sendUpstreamPrompt({
514
661
  return sendUpstreamRequest({
515
662
  runtime,
516
663
  request,
664
+ sessionId,
517
665
  timeoutMs,
518
666
  fetchImpl,
519
667
  });
@@ -524,6 +672,7 @@ module.exports = {
524
672
  buildCodexResponsesRequest,
525
673
  buildOpenAiChatRequest,
526
674
  normalizeProvider,
675
+ normalizeKimiUpstreamModel,
527
676
  parseCodexSsePayload,
528
677
  resolveCodexResponseOutput,
529
678
  resolveUpstreamRuntime,
@@ -21,6 +21,7 @@ const AGENT_PROVIDER_OPTIONS = Object.freeze([
21
21
  { label: "claude", value: "claude-cli" },
22
22
  { label: "agy", value: "agy-cli" },
23
23
  { label: "kimi", value: "kimi-cli" },
24
+ { label: "grok", value: "grok-cli" },
24
25
  ]);
25
26
  const { resolveTransport } = require("../../code/nativeRunner");
26
27
  const { resolveDisplayNickname } = require("../../runtime/daemon/nicknameScope");
@@ -71,6 +72,9 @@ function normalizeSettingsProvider(value = "", fallback = "codex-cli") {
71
72
  if (text === "kimi" || text === "kimi-cli" || text === "kimi-code" || text === "ukimi") {
72
73
  return "kimi-cli";
73
74
  }
75
+ if (text === "grok" || text === "grok-cli" || text === "grok-build" || text === "grok-shell" || text === "xai") {
76
+ return "grok-cli";
77
+ }
74
78
  if (text === "codex" || text === "codex-cli" || text === "codex-code" || text === "openai") {
75
79
  return "codex-cli";
76
80
  }
@@ -82,6 +86,7 @@ function agentProviderKey(value = "") {
82
86
  if (provider === "claude-cli") return "claude";
83
87
  if (provider === "agy-cli") return "agy";
84
88
  if (provider === "kimi-cli") return "kimi";
89
+ if (provider === "grok-cli") return "grok";
85
90
  return "codex";
86
91
  }
87
92
 
@@ -629,7 +634,7 @@ function createCommandExecutor(options = {}) {
629
634
  if (args.length === 0) {
630
635
  logMessage(
631
636
  "error",
632
- "{white-fg}✗{/white-fg} Usage: /launch <claude|codex|agy|kimi|ucode> [nickname=<name>] [profile=<id>] [count=<n>] [scope=inplace|window]"
637
+ "{white-fg}✗{/white-fg} Usage: /launch <claude|codex|agy|grok|kimi|ucode> [nickname=<name>] [profile=<id>] [count=<n>] [scope=inplace|window]"
633
638
  );
634
639
  return;
635
640
  }
@@ -638,9 +643,10 @@ function createCommandExecutor(options = {}) {
638
643
  // Accept friendly aliases the same way `ufoo launch` does in cli.js.
639
644
  let agentType = agentTypeInput;
640
645
  if (agentTypeInput === "antigravity" || agentTypeInput === "uagy") agentType = "agy";
646
+ if (agentTypeInput === "grok-build" || agentTypeInput === "ugrok" || agentTypeInput === "xai") agentType = "grok";
641
647
  if (agentTypeInput === "kimi-cli" || agentTypeInput === "kimi-code" || agentTypeInput === "ukimi") agentType = "kimi";
642
- if (agentType !== "claude" && agentType !== "codex" && agentType !== "agy" && agentType !== "kimi" && agentType !== "ucode") {
643
- logMessage("error", "{white-fg}✗{/white-fg} Unknown agent type. Use: claude, codex, agy, kimi, or ucode");
648
+ if (agentType !== "claude" && agentType !== "codex" && agentType !== "agy" && agentType !== "grok" && agentType !== "kimi" && agentType !== "ucode") {
649
+ logMessage("error", "{white-fg}✗{/white-fg} Unknown agent type. Use: claude, codex, agy, grok, kimi, or ucode");
644
650
  return;
645
651
  }
646
652
  const normalizedAgent = agentType === "ucode" ? "ufoo" : agentType;
@@ -816,7 +822,7 @@ function createCommandExecutor(options = {}) {
816
822
 
817
823
  const profile = String(args[1] || "").trim();
818
824
  if (!profile) {
819
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /solo run <prompt-profile> [agent=codex|claude|agy|ucode] [nickname=<name>] [scope=inplace|window]");
825
+ logMessage("error", "{white-fg}✗{/white-fg} Usage: /solo run <prompt-profile> [agent=codex|claude|agy|grok|ucode] [nickname=<name>] [scope=inplace|window]");
820
826
  return;
821
827
  }
822
828
 
@@ -1091,7 +1097,7 @@ function createCommandExecutor(options = {}) {
1091
1097
  logMessage("system", "{cyan-fg}ufoo-agent provider:{/cyan-fg}");
1092
1098
  logMessage("system", ` • current: ${agentProviderKey(current)}`);
1093
1099
  logMessage("system", ` • options: ${labels}`);
1094
- logMessage("system", " • use: /provider <codex|claude|agy|kimi>");
1100
+ logMessage("system", " • use: /provider <codex|claude|agy|kimi|grok>");
1095
1101
  return;
1096
1102
  }
1097
1103
 
@@ -1506,11 +1512,13 @@ function createCommandExecutor(options = {}) {
1506
1512
  return;
1507
1513
  }
1508
1514
 
1509
- if (action === "codex" || action === "claude" || action === "agy" || action === "kimi") {
1515
+ if (action === "codex" || action === "claude" || action === "agy" || action === "kimi" || action === "grok") {
1510
1516
  const kv = parseKeyValueArgs(args.slice(1));
1511
1517
  const provider = action === "claude"
1512
1518
  ? "claude-cli"
1513
- : (action === "agy" ? "agy-cli" : (action === "kimi" ? "kimi-cli" : "codex-cli"));
1519
+ : (action === "agy"
1520
+ ? "agy-cli"
1521
+ : (action === "kimi" ? "kimi-cli" : (action === "grok" ? "grok-cli" : "codex-cli")));
1514
1522
  const model = String(kv.model || defaultAgentModelForProvider(provider)).trim();
1515
1523
  saveConfig(projectRoot, {
1516
1524
  agentProvider: provider,
@@ -1532,7 +1540,7 @@ function createCommandExecutor(options = {}) {
1532
1540
  if (Object.prototype.hasOwnProperty.call(kv, "provider")) {
1533
1541
  nextProvider = normalizeSettingsProvider(kv.provider, "");
1534
1542
  if (!nextProvider) {
1535
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings agent set provider=<codex|claude> model=<id>");
1543
+ logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings agent set provider=<codex|claude|agy|kimi|grok> model=<id>");
1536
1544
  return;
1537
1545
  }
1538
1546
  updates.agentProvider = nextProvider;
@@ -1544,7 +1552,7 @@ function createCommandExecutor(options = {}) {
1544
1552
  }
1545
1553
 
1546
1554
  if (Object.keys(updates).length === 0) {
1547
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings agent set provider=<codex|claude> model=<id>");
1555
+ logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings agent set provider=<codex|claude|agy|kimi|grok> model=<id>");
1548
1556
  return;
1549
1557
  }
1550
1558
 
@@ -1577,7 +1585,7 @@ function createCommandExecutor(options = {}) {
1577
1585
  return;
1578
1586
  }
1579
1587
 
1580
- logMessage("error", "{white-fg}✗{/white-fg} Unknown settings agent action. Use: show, set, clear, codex, claude");
1588
+ logMessage("error", "{white-fg}✗{/white-fg} Unknown settings agent action. Use: show, set, clear, codex, claude, agy, kimi, grok");
1581
1589
  }
1582
1590
 
1583
1591
  async function handleRouterSettingsCommand(args = []) {
@@ -85,8 +85,9 @@ const COMMAND_TREE = {
85
85
  claude: { desc: "Launch Claude agent", order: 1 },
86
86
  codex: { desc: "Launch Codex agent", order: 2 },
87
87
  agy: { desc: "Launch Antigravity (agy) agent", order: 3 },
88
- ucode: { desc: "Launch ucode core agent", order: 4 },
89
- kimi: { desc: "Launch Kimi Code agent", order: 5 },
88
+ grok: { desc: "Launch Grok Build agent", order: 4 },
89
+ ucode: { desc: "Launch ucode core agent", order: 5 },
90
+ kimi: { desc: "Launch Kimi Code agent", order: 6 },
90
91
  },
91
92
  },
92
93
  "/project": {
@@ -257,6 +258,7 @@ function normalizeAgentLabel(value = "") {
257
258
  if (raw === "claude" || raw === "uclaude") return "claude";
258
259
  if (raw === "codex" || raw === "ucodex") return "codex";
259
260
  if (raw === "agy" || raw === "antigravity" || raw === "uagy") return "agy";
261
+ if (raw === "grok" || raw === "ugrok" || raw === "grok-build" || raw === "xai") return "grok";
260
262
  if (raw === "kimi" || raw === "kimi-cli" || raw === "kimi-code" || raw === "ukimi") return "kimi";
261
263
  if (raw === "ucode" || raw === "ufoo") return "ufoo";
262
264
  return raw || "agent";
@@ -765,8 +765,8 @@ async function runCli(argv) {
765
765
 
766
766
  program
767
767
  .command("launch")
768
- .description("Launch an agent (uclaude, ucodex, uagy, ukimi, ucode)")
769
- .argument("<agent>", "Agent type: uclaude|ucodex|uagy|ukimi|ucode|claude|codex|agy|kimi")
768
+ .description("Launch an agent (uclaude, ucodex, uagy, ugrok, ukimi, ucode)")
769
+ .argument("<agent>", "Agent type: uclaude|ucodex|uagy|ugrok|ukimi|ucode|claude|codex|agy|grok|kimi")
770
770
  .argument("[nickname]", "Optional nickname for the agent")
771
771
  .option("--profile <id>", "Prompt profile to assign after launch")
772
772
  .action(async (agent, nickname, opts) => {
@@ -783,13 +783,15 @@ async function runCli(argv) {
783
783
  normalizedAgent = "codex";
784
784
  } else if (agentLower === "uagy" || agentLower === "agy" || agentLower === "antigravity") {
785
785
  normalizedAgent = "agy";
786
+ } else if (agentLower === "ugrok" || agentLower === "grok" || agentLower === "grok-build" || agentLower === "xai") {
787
+ normalizedAgent = "grok";
786
788
  } else if (agentLower === "ukimi" || agentLower === "kimi" || agentLower === "kimi-cli" || agentLower === "kimi-code") {
787
789
  normalizedAgent = "kimi";
788
790
  } else if (agentLower === "ucode" || agentLower === "ufoo-code" || agentLower === "ufoo") {
789
791
  normalizedAgent = "ucode";
790
792
  } else {
791
793
  console.error(`Unknown agent type: ${agent}`);
792
- console.error("Valid types: uclaude, ucodex, uagy, ukimi, ucode, claude, codex, agy, kimi");
794
+ console.error("Valid types: uclaude, ucodex, uagy, ugrok, ukimi, ucode, claude, codex, agy, grok, kimi");
793
795
  process.exitCode = 1;
794
796
  return;
795
797
  }
@@ -815,7 +817,7 @@ async function runCli(argv) {
815
817
  .description("Solo role agent operations")
816
818
  .argument("<action>", "run|list")
817
819
  .argument("[profile]", "Prompt profile id or alias")
818
- .option("--agent <type>", "Agent type: codex|claude|ucode|agy")
820
+ .option("--agent <type>", "Agent type: codex|claude|ucode|agy|grok")
819
821
  .option("--nickname <name>", "Optional nickname")
820
822
  .option("--scope <scope>", "Launch scope: inplace|window", "inplace")
821
823
  .option("--json", "Output role list as JSON")
@@ -1783,7 +1785,7 @@ async function runCli(argv) {
1783
1785
  console.log(" ufoo group diagram <alias|groupId> [--ascii|--mermaid] [--json]");
1784
1786
  console.log(" ufoo group stop <groupId> [--json]");
1785
1787
  console.log(" ufoo solo list [--json]");
1786
- console.log(" ufoo solo run <profile> [--agent <codex|claude|ucode|agy>] [--nickname <name>] [--scope <inplace|window>]");
1788
+ console.log(" ufoo solo run <profile> [--agent <codex|claude|ucode|agy|grok>] [--nickname <name>] [--scope <inplace|window>]");
1787
1789
  console.log(" ufoo online server [--port 8787] [--host 127.0.0.1] [--token-file <path>]");
1788
1790
  console.log(" ufoo online token <subscriber> [--nickname <name>] [--server <url>] [--file <path>]");
1789
1791
  console.log(" ufoo online room create [--name <room>] --type public|private [--password <pwd>] [--created-by <name>] [--server <url>]");