u-foo 3.0.29 → 3.0.31

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 (44) 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/ptyRunner.js +34 -12
  13. package/src/agents/launch/readyDetector.js +27 -0
  14. package/src/agents/prompts/defaultBootstrap.js +126 -1
  15. package/src/agents/providers/directAuthStatus.js +79 -0
  16. package/src/agents/providers/upstreamTransport.js +234 -85
  17. package/src/app/chat/commandExecutor.js +18 -10
  18. package/src/app/chat/commands.js +4 -2
  19. package/src/app/cli/run.js +7 -5
  20. package/src/code/UcodeController.js +201 -40
  21. package/src/code/agent.js +9 -2
  22. package/src/code/commands.js +13 -0
  23. package/src/code/dispatch.js +9 -1
  24. package/src/code/index.js +9 -2
  25. package/src/code/nativeRunner.js +398 -16
  26. package/src/code/providers/index.js +1 -0
  27. package/src/code/providers/modelsCatalog.js +21 -6
  28. package/src/code/providers/openaiResponsesTransport.js +119 -0
  29. package/src/code/providers/responsesProtocol.js +499 -0
  30. package/src/code/providers/transportContract.js +5 -1
  31. package/src/code/repl.js +95 -2
  32. package/src/code/tools/bash.js +159 -6
  33. package/src/code/ucodeSlashDispatch.js +13 -0
  34. package/src/config.js +6 -0
  35. package/src/coordination/bus/inject.js +2 -2
  36. package/src/coordination/bus/utils.js +4 -1
  37. package/src/orchestration/controller/gateRouter.js +2 -2
  38. package/src/orchestration/controller/launchRouting.js +2 -1
  39. package/src/orchestration/groups/validateTemplate.js +1 -1
  40. package/src/orchestration/solo/commands.js +1 -0
  41. package/src/runtime/daemon/index.js +12 -4
  42. package/src/runtime/daemon/nicknameScope.js +4 -1
  43. package/src/runtime/daemon/ops.js +8 -2
  44. package/src/ui/rustUcodeHost.js +86 -10
@@ -60,7 +60,9 @@ function buildDefaultStartupBootstrapPrompt({ agentType = "", projectRoot = "" }
60
60
  ? "ucode"
61
61
  : (normalizedAgent === "agy"
62
62
  ? "Agy"
63
- : (normalizedAgent === "kimi" ? "Kimi" : "agent"))));
63
+ : (normalizedAgent === "grok"
64
+ ? "Grok"
65
+ : (normalizedAgent === "kimi" ? "Kimi" : "agent")))));
64
66
 
65
67
  const segments = [
66
68
  `Session bootstrap for ${displayAgent}.`,
@@ -246,6 +248,112 @@ function mergeAgyPromptArgs({ args = [], bootstrapText = "" } = {}) {
246
248
  return null;
247
249
  }
248
250
 
251
+ function mergeGrokRulesArgs({ args = [], bootstrapText = "" } = {}) {
252
+ const currentArgs = Array.isArray(args) ? args.slice() : [];
253
+ for (let index = 0; index < currentArgs.length; index += 1) {
254
+ const item = asTrimmedString(currentArgs[index]);
255
+ if (!item) continue;
256
+ if (item === "--rules") {
257
+ const existing = String(currentArgs[index + 1] || "");
258
+ currentArgs[index + 1] = mergePromptSegments(existing, bootstrapText);
259
+ return { args: currentArgs, promptText: String(currentArgs[index + 1] || "") };
260
+ }
261
+ if (item.startsWith("--rules=")) {
262
+ const existing = item.slice("--rules=".length);
263
+ const merged = mergePromptSegments(existing, bootstrapText);
264
+ currentArgs[index] = `--rules=${merged}`;
265
+ return { args: currentArgs, promptText: merged };
266
+ }
267
+ }
268
+ return {
269
+ args: ["--rules", bootstrapText, ...currentArgs],
270
+ promptText: bootstrapText,
271
+ };
272
+ }
273
+
274
+ const GROK_OPTIONS_WITH_VALUE = new Set([
275
+ "--agent",
276
+ "--agents",
277
+ "--allow",
278
+ "--allowedTools",
279
+ "--cwd",
280
+ "--debug-file",
281
+ "--deny",
282
+ "--disallowed-tools",
283
+ "--json-schema",
284
+ "--leader-socket",
285
+ "-m",
286
+ "--model",
287
+ "--max-turns",
288
+ "--output-format",
289
+ "-p",
290
+ "--single",
291
+ "--permission-mode",
292
+ "--prompt-file",
293
+ "--prompt-json",
294
+ "-r",
295
+ "--resume",
296
+ "--reasoning-effort",
297
+ "--effort",
298
+ "--rules",
299
+ "-s",
300
+ "--session-id",
301
+ "--sandbox",
302
+ "--system-prompt-override",
303
+ "--system-prompt",
304
+ "--tools",
305
+ "-w",
306
+ "--worktree",
307
+ "--worktree-ref",
308
+ "--ref",
309
+ ]);
310
+
311
+ const GROK_META_COMMANDS = new Set([
312
+ "agent",
313
+ "completions",
314
+ "dashboard",
315
+ "doctor",
316
+ "du",
317
+ "disk-usage",
318
+ "export",
319
+ "help",
320
+ "inspect",
321
+ "leader",
322
+ "login",
323
+ "logout",
324
+ "mcp",
325
+ "memory",
326
+ "models",
327
+ "plugin",
328
+ "sessions",
329
+ "setup",
330
+ "trace",
331
+ "update",
332
+ "version",
333
+ "v",
334
+ "worktree",
335
+ "wrap",
336
+ ]);
337
+
338
+ function hasGrokMetaCommandArgs(args = []) {
339
+ if (!Array.isArray(args) || args.length === 0) return false;
340
+ for (let index = 0; index < args.length; index += 1) {
341
+ const item = asTrimmedString(args[index]);
342
+ if (!item) continue;
343
+ if (GROK_OPTIONS_WITH_VALUE.has(item)) {
344
+ index += 1;
345
+ continue;
346
+ }
347
+ const eqIndex = item.indexOf("=");
348
+ if (eqIndex > 0 && GROK_OPTIONS_WITH_VALUE.has(item.slice(0, eqIndex))) {
349
+ continue;
350
+ }
351
+ if (item.startsWith("-")) continue;
352
+ return GROK_META_COMMANDS.has(item);
353
+ }
354
+ return false;
355
+ }
356
+
249
357
  function resolveDefaultManualBootstrap({
250
358
  projectRoot,
251
359
  agentType = "",
@@ -261,6 +369,7 @@ function resolveDefaultManualBootstrap({
261
369
  currentEnv.UFOO_SKIP_DEFAULT_BOOTSTRAP === "1"
262
370
  || hasStartupBootstrap
263
371
  || hasMetaCommandArgs(currentArgs)
372
+ || (normalizedAgent === "grok" && hasGrokMetaCommandArgs(currentArgs))
264
373
  ) {
265
374
  return { args: currentArgs, env: {}, mode: "skip" };
266
375
  }
@@ -370,6 +479,20 @@ function resolveDefaultManualBootstrap({
370
479
  };
371
480
  }
372
481
 
482
+ if (normalizedAgent === "grok") {
483
+ const promptText = buildDefaultStartupBootstrapPrompt({ agentType: normalizedAgent, projectRoot });
484
+ const merged = mergeGrokRulesArgs({
485
+ args: currentArgs,
486
+ bootstrapText: promptText,
487
+ });
488
+ return {
489
+ args: merged.args,
490
+ env: {},
491
+ mode: "rules-arg",
492
+ promptText: merged.promptText,
493
+ };
494
+ }
495
+
373
496
  return { args: currentArgs, env: {}, mode: "skip" };
374
497
  }
375
498
 
@@ -382,4 +505,6 @@ module.exports = {
382
505
  prepareDefaultBootstrapFile,
383
506
  resolveDefaultManualBootstrap,
384
507
  mergeAgyPromptArgs,
508
+ mergeGrokRulesArgs,
509
+ hasGrokMetaCommandArgs,
385
510
  };
@@ -32,6 +32,7 @@ function normalizeDirectAuthProvider(value = "") {
32
32
  if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") return "claude";
33
33
  if (text === "agy" || text === "agy-cli" || text === "antigravity") return "agy";
34
34
  if (text === "kimi" || text === "kimi-code" || text === "moonshot") return "kimi";
35
+ if (text === "grok" || text === "grok-cli" || text === "grok-build" || text === "grok-shell" || text === "xai") return "grok";
35
36
  return "codex";
36
37
  }
37
38
 
@@ -312,6 +313,52 @@ async function inspectKimiDirectAuth({
312
313
  }
313
314
  }
314
315
 
316
+ async function inspectGrokDirectAuth({
317
+ projectRoot,
318
+ env = process.env,
319
+ loadConfigImpl = loadConfig,
320
+ } = {}) {
321
+ const config = loadConfigImpl(projectRoot) || {};
322
+ const apiKey = String(
323
+ env.GROK_BUILD_API_KEY
324
+ || env.XAI_API_KEY
325
+ || config.ucodeApiKey
326
+ || ""
327
+ ).trim();
328
+ const baseUrl = String(
329
+ env.UFOO_GROK_BUILD_BASE_URL
330
+ || env.GROK_BUILD_BASE_URL
331
+ || config.ucodeBaseUrl
332
+ || "https://api.x.ai/v1"
333
+ ).trim();
334
+ if (!apiKey) {
335
+ return {
336
+ ok: false,
337
+ provider: "grok",
338
+ transport: "openai-responses",
339
+ baseUrl,
340
+ error: "Grok Build/xAI API key is unavailable",
341
+ errorCode: "GROK_AUTH_MISSING",
342
+ hint: "Set XAI_API_KEY (or GROK_BUILD_API_KEY), or configure a CLIProxyAPI base URL with its credential.",
343
+ };
344
+ }
345
+ return {
346
+ ok: true,
347
+ provider: "grok",
348
+ transport: "openai-responses",
349
+ credentialKind: "api-key",
350
+ source: env.GROK_BUILD_API_KEY ? "env:GROK_BUILD_API_KEY" : "env:XAI_API_KEY",
351
+ state: "present",
352
+ refreshable: false,
353
+ baseUrl,
354
+ account: "",
355
+ accountId: "",
356
+ accountEmail: "",
357
+ expiresAt: "",
358
+ credentialPath: "",
359
+ };
360
+ }
361
+
315
362
  async function inspectDirectAuthStatus(options = {}) {
316
363
  const { projectRoot, loadConfigImpl = loadConfig, provider = "" } = options;
317
364
  const config = loadConfigImpl(projectRoot) || {};
@@ -329,6 +376,9 @@ async function inspectDirectAuthStatus(options = {}) {
329
376
  if (selected === "kimi") {
330
377
  return inspectKimiDirectAuth(nextOptions);
331
378
  }
379
+ if (selected === "grok") {
380
+ return inspectGrokDirectAuth(nextOptions);
381
+ }
332
382
  return inspectCodexDirectAuth(nextOptions);
333
383
  }
334
384
 
@@ -512,6 +562,30 @@ function formatKimiDirectAuthStatus(status = {}, options = {}) {
512
562
  return lines;
513
563
  }
514
564
 
565
+ function formatGrokDirectAuthStatus(status = {}, options = {}) {
566
+ if (options.compact === true) {
567
+ if (status.ok) {
568
+ return [`Grok API: OK · ${status.credentialKind || "credential"}/${status.transport || "openai-responses"} · ${status.state || "present"}`];
569
+ }
570
+ return [
571
+ `Grok API: FAIL · ${status.errorCode || "GROK_AUTH_STATUS_FAILED"}`,
572
+ ` ${status.error || "Grok Build/xAI API credentials are unavailable"} · ${status.hint || "Set XAI_API_KEY."}`,
573
+ ];
574
+ }
575
+ if (status.ok) {
576
+ return [
577
+ `Grok Build direct API: OK (${status.transport || "openai-responses"}, ${status.credentialKind || "credential"})`,
578
+ ` - source: ${status.source || "(unknown)"}`,
579
+ ` - base url: ${status.baseUrl || "(default)"}`,
580
+ ];
581
+ }
582
+ return [
583
+ `Grok Build direct API: FAIL (${status.errorCode || "GROK_AUTH_STATUS_FAILED"})`,
584
+ ` - ${status.error || "Grok Build/xAI API credentials are unavailable"}`,
585
+ ` - ${status.hint || "Set XAI_API_KEY."}`,
586
+ ];
587
+ }
588
+
515
589
  function formatDirectAuthStatus(status = {}, options = {}) {
516
590
  if (status.provider === "claude") {
517
591
  return formatClaudeDirectAuthStatus(status, options);
@@ -522,6 +596,9 @@ function formatDirectAuthStatus(status = {}, options = {}) {
522
596
  if (status.provider === "kimi") {
523
597
  return formatKimiDirectAuthStatus(status, options);
524
598
  }
599
+ if (status.provider === "grok") {
600
+ return formatGrokDirectAuthStatus(status, options);
601
+ }
525
602
  return formatCodexDirectAuthStatus(status, options);
526
603
  }
527
604
 
@@ -531,11 +608,13 @@ module.exports = {
531
608
  inspectClaudeDirectAuth,
532
609
  inspectAgyDirectAuth,
533
610
  inspectKimiDirectAuth,
611
+ inspectGrokDirectAuth,
534
612
  formatDirectAuthStatus,
535
613
  formatCodexDirectAuthStatus,
536
614
  formatClaudeDirectAuthStatus,
537
615
  formatAgyDirectAuthStatus,
538
616
  formatKimiDirectAuthStatus,
617
+ formatGrokDirectAuthStatus,
539
618
  normalizeDirectAuthProvider,
540
619
  classifyAgyLogTail,
541
620
  };