u-foo 3.0.28 → 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 (46) 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/contextWindow.js +2 -0
  24. package/src/code/dispatch.js +9 -1
  25. package/src/code/index.js +9 -2
  26. package/src/code/nativeRunner.js +427 -18
  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/code/usageStore.js +19 -2
  36. package/src/config.js +6 -0
  37. package/src/coordination/bus/inject.js +2 -2
  38. package/src/coordination/bus/utils.js +4 -1
  39. package/src/orchestration/controller/gateRouter.js +2 -2
  40. package/src/orchestration/controller/launchRouting.js +2 -1
  41. package/src/orchestration/groups/validateTemplate.js +1 -1
  42. package/src/orchestration/solo/commands.js +1 -0
  43. package/src/runtime/daemon/index.js +12 -4
  44. package/src/runtime/daemon/nicknameScope.js +4 -1
  45. package/src/runtime/daemon/ops.js +8 -2
  46. package/src/ui/rustUcodeHost.js +123 -18
@@ -22,6 +22,7 @@ function normalizeLaunchAgent(agent = "") {
22
22
  if (value === "codex") return "codex";
23
23
  if (value === "claude" || value === "claude-code") return "claude";
24
24
  if (value === "agy" || value === "antigravity") return "agy";
25
+ if (value === "grok" || value === "ugrok" || value === "grok-build" || value === "xai") return "grok";
25
26
  if (value === "kimi" || value === "kimi-cli" || value === "kimi-code") return "kimi";
26
27
  if (value === "ufoo" || value === "ucode" || value === "ufoo-code") return "ufoo";
27
28
  return "";
@@ -31,6 +32,7 @@ function toBusAgentType(agent = "") {
31
32
  if (agent === "codex") return "codex";
32
33
  if (agent === "claude") return "claude-code";
33
34
  if (agent === "agy") return "agy";
35
+ if (agent === "grok") return "grok";
34
36
  if (agent === "kimi") return "kimi";
35
37
  if (agent === "ufoo") return "ufoo-code";
36
38
  return "";
@@ -40,6 +42,7 @@ function toTerminalBinary(agent = "") {
40
42
  if (agent === "codex") return "ucodex";
41
43
  if (agent === "claude") return "uclaude";
42
44
  if (agent === "agy") return "uagy";
45
+ if (agent === "grok") return "ugrok";
43
46
  if (agent === "kimi") return "ukimi";
44
47
  if (agent === "ufoo") return "ucode";
45
48
  return "";
@@ -49,6 +52,7 @@ function toTmuxBinary(agent = "") {
49
52
  if (agent === "codex") return "ucodex";
50
53
  if (agent === "claude") return "uclaude";
51
54
  if (agent === "agy") return "uagy";
55
+ if (agent === "grok") return "ugrok";
52
56
  if (agent === "kimi") return "ukimi";
53
57
  if (agent === "ufoo") return "ucode";
54
58
  return "";
@@ -1110,7 +1114,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
1110
1114
  normalizedAgent,
1111
1115
  nick,
1112
1116
  processManager,
1113
- [],
1117
+ extraArgs,
1114
1118
  extraEnvPrefix,
1115
1119
  launchScope,
1116
1120
  terminalApp
@@ -1124,6 +1128,7 @@ async function launchAgent(projectRoot, agent, count = 1, nickname = "", process
1124
1128
  function normalizeAgentType(agentType) {
1125
1129
  if (agentType === "claude-code") return "claude";
1126
1130
  if (agentType === "codex") return "codex";
1131
+ if (agentType === "grok") return "grok";
1127
1132
  if (agentType === "ufoo-code") return "ufoo";
1128
1133
  return agentType;
1129
1134
  }
@@ -1135,6 +1140,7 @@ function buildResumeArgs(agent, sessionId) {
1135
1140
  // Agy resumes by conversation UUID; bin/uagy.js de-duplicates if the same
1136
1141
  // flag is already injected via provider_session_id readback.
1137
1142
  if (agent === "agy") return [`--conversation=${sessionId}`];
1143
+ if (agent === "grok") return ["--resume", sessionId];
1138
1144
  // kimi resumes a session by id via `-S, --session <id>`.
1139
1145
  if (agent === "kimi") return ["--session", sessionId];
1140
1146
  return [];
@@ -1189,7 +1195,7 @@ function collectRecoverableAgents(projectRoot, target = "") {
1189
1195
  continue;
1190
1196
  }
1191
1197
  const agent = normalizeAgentType(meta.agent_type);
1192
- if (agent !== "codex" && agent !== "claude" && agent !== "agy" && agent !== "kimi") {
1198
+ if (agent !== "codex" && agent !== "claude" && agent !== "agy" && agent !== "grok" && agent !== "kimi") {
1193
1199
  skipped.push({ id, reason: "unsupported agent type" });
1194
1200
  continue;
1195
1201
  }
@@ -203,6 +203,31 @@ function createThinkingLogPublisher(publish, thinkingStatus, streamId) {
203
203
  return { id, onThinkingDelta, stop };
204
204
  }
205
205
 
206
+ function createLeadingWhitespaceNormalizer() {
207
+ let hasVisibleText = false;
208
+ return (delta) => {
209
+ const text = String(delta || "");
210
+ if (hasVisibleText || !text) return text;
211
+ const visible = text.replace(/^\s+/u, "");
212
+ if (!visible) return "";
213
+ hasVisibleText = true;
214
+ return visible;
215
+ };
216
+ }
217
+
218
+ function appendNaturalLanguageResult(nlResult, formatNlResult, appendLog) {
219
+ if (typeof formatNlResult !== "function" || typeof appendLog !== "function" || !nlResult) {
220
+ return false;
221
+ }
222
+ // Successful streamed text is already present in the mutable stream entry.
223
+ // Appending summary + formatted summary here duplicated the same answer.
224
+ if (nlResult.ok !== false && nlResult.streamed) return false;
225
+ const formatted = String(formatNlResult(nlResult) || "").trim();
226
+ if (!formatted) return false;
227
+ appendLog(formatted, nlResult.ok === false ? "error" : "assistant");
228
+ return true;
229
+ }
230
+
206
231
  async function runUcodeRust(props = {}) {
207
232
  const plan = resolveTuiLaunchPlan({
208
233
  mode: props.tuiMode || process.env.UFOO_TUI || "rust",
@@ -241,7 +266,12 @@ async function runUcodeRust(props = {}) {
241
266
  let backgroundSeq = 0;
242
267
  let requestExit = false;
243
268
  const MARKDOWN_LOG_KINDS = new Set(["assistant", "error"]);
244
- const controller = createUcodeController({ projectRoot: workspaceRoot });
269
+ const controller = createUcodeController({
270
+ projectRoot: workspaceRoot,
271
+ ports: {
272
+ onQueueChange: (snapshot) => publish("task.queue", snapshot),
273
+ },
274
+ });
245
275
 
246
276
  function publish(name, payload) {
247
277
  if (!hostRef) return;
@@ -326,6 +356,20 @@ async function runUcodeRust(props = {}) {
326
356
  });
327
357
  }
328
358
 
359
+ function formatQueueSnapshot(snapshot = controller.getQueueSnapshot()) {
360
+ const active = snapshot && snapshot.active;
361
+ const queued = Array.isArray(snapshot && snapshot.queued) ? snapshot.queued : [];
362
+ const activeText = active
363
+ ? `active #${active.id} ${active.label || active.kind || "task"}`
364
+ : "active none";
365
+ const lines = [`Queue: ${activeText} · pending ${queued.length}`];
366
+ for (const task of queued.slice(0, 8)) {
367
+ lines.push(` ${task.position}. #${task.id} ${task.label || task.kind || "task"}`);
368
+ }
369
+ if (queued.length > 8) lines.push(` … ${queued.length - 8} more`);
370
+ return lines.join("\n");
371
+ }
372
+
329
373
  function publishPlan(activityMessage = "") {
330
374
  const payload = buildPlanSetPayload(props.state && props.state.executionState, {
331
375
  activityMessage,
@@ -524,6 +568,7 @@ async function runUcodeRust(props = {}) {
524
568
  agents: agentsSnap.agents,
525
569
  attachment_count: pendingAttachments.length,
526
570
  usage: String((meter && meter.label) || ""),
571
+ task_queue: controller.getQueueSnapshot(),
527
572
  };
528
573
  }
529
574
 
@@ -552,7 +597,7 @@ async function runUcodeRust(props = {}) {
552
597
  }
553
598
  }
554
599
 
555
- async function resumeInteraction(answerText) {
600
+ async function resumeInteraction(answerText, meta = {}) {
556
601
  return controller.runExclusive(async (abort) => {
557
602
  const submit = typeof props.submitUserInteractionAnswer === "function"
558
603
  ? props.submitUserInteractionAnswer
@@ -562,6 +607,7 @@ async function runUcodeRust(props = {}) {
562
607
  thinking.reset();
563
608
  publish("stream.start", { id: streamId });
564
609
  const thinkingLog = createThinkingLogPublisher(publish, thinking, streamId);
610
+ const normalizeStreamDelta = createLeadingWhitespaceNormalizer();
565
611
  let responseStarted = false;
566
612
  const beginResponse = () => {
567
613
  if (responseStarted) return;
@@ -573,8 +619,10 @@ async function runUcodeRust(props = {}) {
573
619
  const result = await submit(answerText, props.state, {
574
620
  signal: abort.signal,
575
621
  onDelta: (delta) => {
622
+ const visibleDelta = normalizeStreamDelta(delta);
623
+ if (!visibleDelta) return;
576
624
  beginResponse();
577
- publish("stream.delta", { id: streamId, text: String(delta || "") });
625
+ publish("stream.delta", { id: streamId, text: visibleDelta });
578
626
  },
579
627
  onThinkingDelta: (delta) => {
580
628
  if (!responseStarted) thinkingLog.onThinkingDelta(delta);
@@ -593,8 +641,10 @@ async function runUcodeRust(props = {}) {
593
641
  publishPlan();
594
642
  publishUsageFromResult(result);
595
643
  if (publishPendingInteraction()) {
644
+ controller.pauseQueue("waiting for reply");
596
645
  return { ok: true, waiting: true };
597
646
  }
647
+ controller.resumeQueue();
598
648
  return { ok: true, waiting: false };
599
649
  } catch (err) {
600
650
  tools.flush();
@@ -607,10 +657,15 @@ async function runUcodeRust(props = {}) {
607
657
  appendLog(`Error: ${err && err.message ? err.message : err}`, "error");
608
658
  return { ok: false };
609
659
  }
660
+ }, {
661
+ kind: "interaction",
662
+ label: "reply",
663
+ priority: meta.priority === true,
610
664
  });
611
665
  }
612
666
 
613
- async function runNaturalLanguage(text) {
667
+ async function runNaturalLanguage(text, meta = {}) {
668
+ const label = String(meta.label || text || "prompt").trim().replace(/\s+/g, " ");
614
669
  return controller.runExclusive(async (abort) => {
615
670
  if (typeof props.runNaturalLanguageTask !== "function") {
616
671
  appendLog("runNaturalLanguageTask unavailable", "error");
@@ -621,6 +676,7 @@ async function runUcodeRust(props = {}) {
621
676
  thinking.reset();
622
677
  publish("stream.start", { id: streamId });
623
678
  const thinkingLog = createThinkingLogPublisher(publish, thinking, streamId);
679
+ const normalizeStreamDelta = createLeadingWhitespaceNormalizer();
624
680
  let responseStarted = false;
625
681
  const beginResponse = () => {
626
682
  if (responseStarted) return;
@@ -632,8 +688,10 @@ async function runUcodeRust(props = {}) {
632
688
  const nlResult = await props.runNaturalLanguageTask(text, props.state, {
633
689
  signal: abort.signal,
634
690
  onDelta: (delta) => {
691
+ const visibleDelta = normalizeStreamDelta(delta);
692
+ if (!visibleDelta) return;
635
693
  beginResponse();
636
- publish("stream.delta", { id: streamId, text: String(delta || "") });
694
+ publish("stream.delta", { id: streamId, text: visibleDelta });
637
695
  },
638
696
  onThinkingDelta: (delta) => {
639
697
  if (!responseStarted) thinkingLog.onThinkingDelta(delta);
@@ -656,17 +714,15 @@ async function runUcodeRust(props = {}) {
656
714
  tools.flush();
657
715
  thinkingLog.stop();
658
716
  publish("stream.done", { id: streamId });
659
- if (nlResult && nlResult.summary) appendLog(nlResult.summary, "system");
660
- if (typeof props.formatNlResult === "function" && nlResult) {
661
- const formatted = props.formatNlResult(nlResult);
662
- if (formatted) appendLog(formatted, "assistant");
663
- }
717
+ appendNaturalLanguageResult(nlResult, props.formatNlResult, appendLog);
664
718
  persistIfNeeded();
665
719
  publishPlan();
666
720
  publishUsageFromResult(nlResult);
667
721
  if (publishPendingInteraction()) {
722
+ controller.pauseQueue("waiting for reply");
668
723
  return { ok: true, waiting: true };
669
724
  }
725
+ controller.resumeQueue();
670
726
  return { ok: true, waiting: false, result: nlResult };
671
727
  } catch (err) {
672
728
  tools.flush();
@@ -679,6 +735,9 @@ async function runUcodeRust(props = {}) {
679
735
  appendLog(`Error: ${err && err.message ? err.message : err}`, "error");
680
736
  return { ok: false };
681
737
  }
738
+ }, {
739
+ kind: String(meta.kind || "prompt").trim() || "prompt",
740
+ label: label.length > 80 ? `${label.slice(0, 77)}…` : label,
682
741
  });
683
742
  }
684
743
 
@@ -733,7 +792,7 @@ async function runUcodeRust(props = {}) {
733
792
  publish("status.set", { text: "ready", busy: false });
734
793
  }
735
794
  }
736
- });
795
+ }, { kind: "bus", label: "bus messages" });
737
796
  }
738
797
 
739
798
  function scheduleAutoBus() {
@@ -776,13 +835,13 @@ async function runUcodeRust(props = {}) {
776
835
 
777
836
  if (name === "app.exit") {
778
837
  closing = true;
779
- controller.cancelTask();
838
+ controller.stop();
780
839
  return { ok: true };
781
840
  }
782
841
  if (name === "task.cancel") {
783
- controller.cancelTask();
842
+ controller.cancelTask("user");
784
843
  publish("status.set", { text: "cancelling…", busy: true });
785
- appendLog("⚙ Cancellation requested. Stopping the current task...", "system");
844
+ appendLog("• Cancellation requested. Stopping the current task...", "system");
786
845
  return { ok: true };
787
846
  }
788
847
  if (name === "completion.request") {
@@ -834,12 +893,15 @@ async function runUcodeRust(props = {}) {
834
893
  if (payload.cancelled) {
835
894
  appendLog("interaction cancelled", "system");
836
895
  publish("interaction.clear", {});
896
+ controller.resumeQueue();
837
897
  publish("status.set", { text: "ready", busy: false });
838
898
  return { ok: true, cancelled: true };
839
899
  }
840
900
  publish("interaction.clear", {});
841
901
  publish("status.set", { text: "applying reply…", busy: true });
842
- const result = await resumeInteraction(String(payload.text || ""));
902
+ const resume = resumeInteraction(String(payload.text || ""), { priority: true });
903
+ controller.resumeQueue();
904
+ const result = await resume;
843
905
  if (!result.waiting) {
844
906
  publish("status.set", { text: "ready", busy: false });
845
907
  }
@@ -850,14 +912,15 @@ async function runUcodeRust(props = {}) {
850
912
  const { modelText, logText, attachments } = composeSubmitText(rawText);
851
913
  if (!modelText && attachments.length === 0) return { ok: true, empty: true };
852
914
  clearAttachments();
853
- tools.beginScope();
854
915
 
855
916
  try {
856
917
  const { hasPendingUserInteraction } = require("../code/context/userInteraction");
857
918
  if (props.state && hasPendingUserInteraction(props.state.executionState)) {
858
919
  appendLog(`› ${logText || rawText}`, "user");
859
920
  publishStatus("applying reply…", true);
860
- const result = await resumeInteraction(modelText || rawText);
921
+ const resume = resumeInteraction(modelText || rawText, { priority: true });
922
+ controller.resumeQueue();
923
+ const result = await resume;
861
924
  if (!result.waiting) publishStatus("ready", false);
862
925
  return { ok: true, routed: "interaction" };
863
926
  }
@@ -883,6 +946,7 @@ async function runUcodeRust(props = {}) {
883
946
  parsed = null;
884
947
  }
885
948
  if (parsed) {
949
+ if (parsed.kind === "tool") tools.beginScope();
886
950
  const dispatched = await dispatchUcodeSlashCommand(parsed, {
887
951
  state: props.state,
888
952
  workspaceRoot,
@@ -977,6 +1041,42 @@ async function runUcodeRust(props = {}) {
977
1041
  });
978
1042
  },
979
1043
  onNaturalLanguage: async (task) => runNaturalLanguage(task),
1044
+ onQueueCommand: (action) => {
1045
+ const normalized = String(action || "status").trim().toLowerCase();
1046
+ if (normalized === "status") {
1047
+ return { ok: true, output: formatQueueSnapshot() };
1048
+ }
1049
+ if (normalized === "cancel") {
1050
+ const snapshot = controller.getQueueSnapshot();
1051
+ if (!snapshot.active) {
1052
+ return { ok: true, output: "Queue: no active task." };
1053
+ }
1054
+ controller.cancelTask("queue cancel");
1055
+ publishStatus("cancelling…", true);
1056
+ return { ok: true, output: `Cancellation requested for #${snapshot.active.id}.` };
1057
+ }
1058
+ if (normalized === "clear") {
1059
+ const count = controller.clearQueue();
1060
+ if (!controller.isBusy()) publishStatus("ready", false);
1061
+ return { ok: true, output: count
1062
+ ? `Cleared ${count} pending task${count === 1 ? "" : "s"}.`
1063
+ : "Queue: no pending tasks." };
1064
+ }
1065
+ if (normalized === "stop") {
1066
+ const snapshot = controller.getQueueSnapshot();
1067
+ const cancelled = controller.cancelTask("queue stop");
1068
+ const cleared = controller.clearQueue();
1069
+ if (cancelled) publishStatus("cancelling…", true);
1070
+ else if (!controller.isBusy()) publishStatus("ready", false);
1071
+ return {
1072
+ ok: true,
1073
+ output: `Queue stopped: ${cancelled ? "active cancellation requested" : "no active task"}; cleared ${cleared} pending.`,
1074
+ active: snapshot.active,
1075
+ cleared,
1076
+ };
1077
+ }
1078
+ return { ok: false, output: "usage: /queue [status|clear|cancel|stop]" };
1079
+ },
980
1080
  runUbus: typeof props.runUbusCommand === "function"
981
1081
  ? (state, opts) => props.runUbusCommand(state, opts)
982
1082
  : null,
@@ -1000,7 +1100,10 @@ async function runUcodeRust(props = {}) {
1000
1100
  } finally {
1001
1101
  try {
1002
1102
  const { hasPendingUserInteraction } = require("../code/context/userInteraction");
1003
- if (!(props.state && hasPendingUserInteraction(props.state.executionState))) {
1103
+ if (
1104
+ !(props.state && hasPendingUserInteraction(props.state.executionState))
1105
+ && !controller.isBusy()
1106
+ ) {
1004
1107
  publishStatus("ready", false);
1005
1108
  }
1006
1109
  } catch {
@@ -1070,6 +1173,8 @@ module.exports = {
1070
1173
  normalizeToolLogEntry,
1071
1174
  splitUcodeBannerRow,
1072
1175
  createThinkingLogPublisher,
1176
+ createLeadingWhitespaceNormalizer,
1177
+ appendNaturalLanguageResult,
1073
1178
  buildUcodeAgentsSnapshot,
1074
1179
  buildUcodeCompletionItems,
1075
1180
  };