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
@@ -15,75 +15,232 @@ function createUcodeController({
15
15
  setStatus: typeof ports.setStatus === "function" ? ports.setStatus : () => {},
16
16
  appendLog: typeof ports.appendLog === "function" ? ports.appendLog : () => {},
17
17
  };
18
+ const onQueueChange = typeof ports.onQueueChange === "function"
19
+ ? ports.onQueueChange
20
+ : () => {};
18
21
 
19
22
  let started = false;
20
- let abortController = null;
21
- let chain = Promise.resolve();
22
- let queueDepth = 0;
23
+ let activeTask = null;
24
+ let pendingTasks = [];
25
+ let taskSeq = 0;
26
+ let draining = false;
27
+ let legacyAbortController = null;
28
+ let pauseReason = "";
29
+
30
+ function taskLabel(meta = {}, id = 0) {
31
+ const label = String(meta.label || "").trim();
32
+ if (label) return label;
33
+ const kind = String(meta.kind || "task").trim();
34
+ return `${kind} #${id}`;
35
+ }
36
+
37
+ function taskView(task, position = 0) {
38
+ if (!task) return null;
39
+ return {
40
+ id: task.id,
41
+ kind: task.kind,
42
+ label: task.label,
43
+ status: task.status,
44
+ enqueuedAt: task.enqueuedAt,
45
+ startedAt: task.startedAt || 0,
46
+ position,
47
+ };
48
+ }
49
+
50
+ function queueSnapshot(event = "") {
51
+ const queued = pendingTasks.map((task, index) => taskView(task, index + 1));
52
+ return {
53
+ event: String(event || ""),
54
+ busy: Boolean(activeTask || queued.length),
55
+ activeBusy: Boolean(activeTask),
56
+ queueDepth: (activeTask ? 1 : 0) + queued.length,
57
+ queuedCount: queued.length,
58
+ active: taskView(activeTask, 0),
59
+ queued,
60
+ cancelRequested: Boolean(activeTask && activeTask.cancelRequested),
61
+ paused: Boolean(pauseReason),
62
+ pausedReason: pauseReason,
63
+ };
64
+ }
65
+
66
+ function notifyQueueChange(event = "") {
67
+ try {
68
+ onQueueChange(queueSnapshot(event));
69
+ } catch {
70
+ // Queue telemetry must never affect task execution.
71
+ }
72
+ }
73
+
74
+ function settleCancelled(task, reason = "cancelled") {
75
+ if (!task || task.settled) return;
76
+ task.settled = true;
77
+ // A task that never entered the executor has no partial work to report.
78
+ // Resolve it as a no-op so callers do not create unhandled cancellation
79
+ // rejections while the active task continues to drain the queue.
80
+ task.resolve(null);
81
+ task.status = "cancelled";
82
+ task.cancelReason = String(reason || "cancelled");
83
+ }
84
+
85
+ function clearPending(reason = "cleared") {
86
+ const cleared = pendingTasks.splice(0);
87
+ for (const task of cleared) settleCancelled(task, reason);
88
+ if (cleared.length > 0) notifyQueueChange("cleared");
89
+ return cleared.length;
90
+ }
91
+
92
+ async function drain() {
93
+ if (draining) return;
94
+ draining = true;
95
+ try {
96
+ while (started && !pauseReason && !activeTask && pendingTasks.length > 0) {
97
+ const task = pendingTasks.shift();
98
+ if (!task) continue;
99
+ if (task.controller.signal.aborted) {
100
+ settleCancelled(task, task.cancelReason || "cancelled");
101
+ notifyQueueChange("cancelled");
102
+ continue;
103
+ }
104
+
105
+ activeTask = task;
106
+ task.status = "running";
107
+ task.startedAt = Date.now();
108
+ notifyQueueChange("started");
109
+ try {
110
+ const value = await task.fn(task.controller, task);
111
+ if (!task.settled) {
112
+ task.settled = true;
113
+ task.resolve(value);
114
+ }
115
+ } catch (err) {
116
+ if (!task.settled) {
117
+ task.settled = true;
118
+ task.reject(err);
119
+ }
120
+ } finally {
121
+ activeTask = null;
122
+ notifyQueueChange(task.controller.signal.aborted ? "cancelled" : "completed");
123
+ }
124
+ }
125
+ } finally {
126
+ draining = false;
127
+ notifyQueueChange("idle");
128
+ }
129
+ }
23
130
 
24
131
  function start() {
25
132
  started = true;
133
+ void drain();
134
+ notifyQueueChange("started");
26
135
  }
27
136
 
28
137
  function stop() {
29
- if (abortController) {
138
+ started = false;
139
+ pauseReason = "";
140
+ if (activeTask) {
141
+ activeTask.cancelRequested = true;
30
142
  try {
31
- abortController.abort();
143
+ activeTask.controller.abort();
32
144
  } catch {
33
145
  // ignore
34
146
  }
35
- abortController = null;
36
147
  }
37
- queueDepth = 0;
38
- started = false;
148
+ clearPending("stopped");
149
+ if (legacyAbortController) {
150
+ try {
151
+ legacyAbortController.abort();
152
+ } catch {
153
+ // ignore
154
+ }
155
+ legacyAbortController = null;
156
+ }
157
+ notifyQueueChange("stopped");
39
158
  }
40
159
 
41
160
  function beginTask() {
42
- abortController = new AbortController();
43
- queueDepth = Math.max(1, queueDepth);
44
- return abortController;
161
+ legacyAbortController = new AbortController();
162
+ return legacyAbortController;
45
163
  }
46
164
 
47
165
  function endTask() {
48
- if (queueDepth > 0) queueDepth -= 1;
49
- if (queueDepth === 0) abortController = null;
166
+ legacyAbortController = null;
50
167
  }
51
168
 
52
- function cancelTask() {
53
- if (abortController) abortController.abort();
169
+ function cancelTask(reason = "user") {
170
+ if (activeTask) {
171
+ activeTask.cancelRequested = true;
172
+ activeTask.cancelReason = String(reason || "user");
173
+ try {
174
+ activeTask.controller.abort();
175
+ } catch {
176
+ // ignore
177
+ }
178
+ notifyQueueChange("cancel_requested");
179
+ return true;
180
+ }
181
+ if (legacyAbortController) {
182
+ legacyAbortController.abort();
183
+ return true;
184
+ }
185
+ return false;
54
186
  }
55
187
 
56
188
  function isBusy() {
57
- return queueDepth > 0;
189
+ return Boolean(activeTask || pendingTasks.length > 0);
190
+ }
191
+
192
+ function pauseQueue(reason = "paused") {
193
+ pauseReason = String(reason || "paused");
194
+ notifyQueueChange("paused");
195
+ }
196
+
197
+ function resumeQueue() {
198
+ if (!pauseReason) return;
199
+ pauseReason = "";
200
+ notifyQueueChange("resumed");
201
+ void drain();
58
202
  }
59
203
 
60
204
  /**
61
205
  * Serialize async work so NL / auto-bus / resume never overlap.
62
- * AbortController is allocated synchronously so cancel works before the slot starts.
206
+ * The active controller is kept separate from queued controllers so Esc
207
+ * always targets the request that is actually executing.
63
208
  */
64
- function runExclusive(fn) {
65
- const abort = new AbortController();
66
- queueDepth += 1;
67
- abortController = abort;
68
- const run = chain.then(async () => {
69
- if (!started) {
70
- return null;
71
- }
72
- abortController = abort;
73
- try {
74
- if (abort.signal.aborted) {
75
- const err = new Error("aborted");
76
- err.name = "AbortError";
77
- throw err;
78
- }
79
- return await fn(abort);
80
- } finally {
81
- queueDepth = Math.max(0, queueDepth - 1);
82
- if (abortController === abort) abortController = null;
83
- }
209
+ function runExclusive(fn, meta = {}) {
210
+ if (typeof fn !== "function") {
211
+ return Promise.reject(new TypeError("exclusive task must be a function"));
212
+ }
213
+ const taskMeta = meta && typeof meta === "object" ? meta : {};
214
+ const id = ++taskSeq;
215
+ const controller = new AbortController();
216
+ let resolveTask;
217
+ let rejectTask;
218
+ const promise = new Promise((resolve, reject) => {
219
+ resolveTask = resolve;
220
+ rejectTask = reject;
84
221
  });
85
- chain = run.catch(() => {});
86
- return run;
222
+ const task = {
223
+ id,
224
+ kind: String(taskMeta.kind || "task").trim() || "task",
225
+ label: taskLabel(taskMeta, id),
226
+ enqueuedAt: Date.now(),
227
+ startedAt: 0,
228
+ status: "queued",
229
+ cancelRequested: false,
230
+ cancelReason: "",
231
+ controller,
232
+ fn,
233
+ resolve: resolveTask,
234
+ reject: rejectTask,
235
+ settled: false,
236
+ };
237
+ // Expose the id without changing the promise's value contract.
238
+ promise.taskId = id;
239
+ if (taskMeta.priority === true) pendingTasks.unshift(task);
240
+ else pendingTasks.push(task);
241
+ notifyQueueChange("enqueued");
242
+ void drain();
243
+ return promise;
87
244
  }
88
245
 
89
246
  return {
@@ -97,7 +254,11 @@ function createUcodeController({
97
254
  endTask,
98
255
  cancelTask,
99
256
  runExclusive,
100
- getAbortSignal: () => (abortController ? abortController.signal : null),
257
+ clearQueue: () => clearPending("cleared"),
258
+ pauseQueue,
259
+ resumeQueue,
260
+ getQueueSnapshot: () => queueSnapshot("snapshot"),
261
+ getAbortSignal: () => (activeTask ? activeTask.controller.signal : null),
101
262
  };
102
263
  }
103
264
 
package/src/code/agent.js CHANGED
@@ -280,7 +280,10 @@ function resolvePlannerProvider(value = "") {
280
280
  const text = String(value || "").trim().toLowerCase();
281
281
  if (!text) return "";
282
282
  if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") return "anthropic";
283
- if (text === "codex" || text === "codex-cli" || text === "codex-code" || text === "openai") return "openai";
283
+ if (text === "codex" || text === "codex-cli" || text === "codex-code") return "codex";
284
+ if (text === "grok" || text === "grok-cli" || text === "grok-build" || text === "grok-shell" || text === "grok-api") return "grok-build";
285
+ if (text === "xai") return "xai";
286
+ if (text === "openai") return "openai";
284
287
  return text;
285
288
  }
286
289
 
@@ -320,7 +323,11 @@ function isCliTimeoutError(message = "") {
320
323
 
321
324
  function isCliCancelledError(message = "") {
322
325
  const text = String(message || "").toLowerCase();
323
- return text.includes("cli cancelled") || text.includes("canceled");
326
+ return text.includes("cli cancelled")
327
+ || text.includes("cancelled")
328
+ || text.includes("canceled")
329
+ || text.includes("aborted")
330
+ || text.includes("cancellation");
324
331
  }
325
332
 
326
333
  function computeExtendedTimeout(baseTimeoutMs) {
@@ -7,6 +7,7 @@
7
7
  const UCODE_COMMAND_REGISTRY = [
8
8
  { cmd: "/help", desc: "Show available commands", order: 10 },
9
9
  { cmd: "/status", desc: "Show session / usage status", order: 20 },
10
+ { cmd: "/queue", desc: "Inspect or control the task queue", order: 22 },
10
11
  { cmd: "/model", desc: "Show or switch model (+ thinking intensity)", order: 25 },
11
12
  { cmd: "/plan", desc: "Show plan progress or set plan mode", order: 27 },
12
13
  { cmd: "/ubus", desc: "Check pending bus messages", order: 30 },
@@ -19,6 +20,17 @@ const UCODE_COMMAND_REGISTRY = [
19
20
  const UCODE_COMMAND_TREE = {
20
21
  "/help": { desc: "Show available commands" },
21
22
  "/status": { desc: "Show session / usage status" },
23
+ "/queue": {
24
+ desc: "Inspect or control the task queue",
25
+ hasArguments: true,
26
+ optionalArguments: true,
27
+ children: {
28
+ status: { desc: "Show active and queued tasks", order: 1 },
29
+ clear: { desc: "Clear pending tasks", order: 2 },
30
+ cancel: { desc: "Cancel the active task", order: 3 },
31
+ stop: { desc: "Cancel active and clear pending tasks", order: 4 },
32
+ },
33
+ },
22
34
  "/model": {
23
35
  desc: "Show or switch model, then pick thinking intensity",
24
36
  hasArguments: true,
@@ -59,6 +71,7 @@ function listUcodeCommandsForHelp() {
59
71
  " /exit|/quit",
60
72
  " /ubus",
61
73
  " /status",
74
+ " /queue [status|clear|cancel|stop]",
62
75
  " /model [model-id] [off|low|medium|high|max]",
63
76
  " /plan [on|off|show|hide|focus|debug|clear]",
64
77
  " /skills [list]",
@@ -24,6 +24,8 @@ function contextTokensFromUsage(usage = null) {
24
24
  const input = toTokenCount(usage.input);
25
25
  const cacheRead = toTokenCount(usage.cacheRead);
26
26
  const cacheCreation = toTokenCount(usage.cacheCreation);
27
+ if (usage.inputIncludesCache === true) return input;
28
+ if (usage.inputIncludesCache === false) return input + cacheRead + cacheCreation;
27
29
  if (cacheCreation > 0) return input + cacheRead + cacheCreation;
28
30
  // Anthropic exclusive split: input can be smaller than cache_read alone.
29
31
  if (cacheRead > 0 && input < cacheRead) return input + cacheRead + cacheCreation;
@@ -4,7 +4,7 @@ const { runReadTool } = require("./tools/read");
4
4
  const { runReadImageTool } = require("./tools/readImage");
5
5
  const { runWriteTool } = require("./tools/write");
6
6
  const { runEditTool } = require("./tools/edit");
7
- const { runBashTool } = require("./tools/bash");
7
+ const { runBashTool, runBashToolAsync } = require("./tools/bash");
8
8
  const { runArtifactReadTool } = require("./tools/artifactRead");
9
9
  const { runPlanGraphTool } = require("./tools/planGraph");
10
10
  const { runTaskRunTool } = require("./tools/taskRun");
@@ -57,8 +57,16 @@ function runToolCall(input = {}, options = {}) {
57
57
  return runBashTool(args, options);
58
58
  }
59
59
 
60
+ async function runToolCallAsync(input = {}, options = {}) {
61
+ const tool = normalizeToolName(input.tool || input.name);
62
+ const args = input.args && typeof input.args === "object" ? input.args : {};
63
+ if (tool === "bash") return runBashToolAsync(args, options);
64
+ return runToolCall(input, options);
65
+ }
66
+
60
67
  module.exports = {
61
68
  TOOL_NAMES,
62
69
  normalizeToolName,
63
70
  runToolCall,
71
+ runToolCallAsync,
64
72
  };
package/src/code/index.js CHANGED
@@ -1,8 +1,13 @@
1
- const { TOOL_NAMES, normalizeToolName, runToolCall } = require("./dispatch");
1
+ const {
2
+ TOOL_NAMES,
3
+ normalizeToolName,
4
+ runToolCall,
5
+ runToolCallAsync,
6
+ } = require("./dispatch");
2
7
  const { runReadTool } = require("./tools/read");
3
8
  const { runWriteTool } = require("./tools/write");
4
9
  const { runEditTool } = require("./tools/edit");
5
- const { runBashTool } = require("./tools/bash");
10
+ const { runBashTool, runBashToolAsync } = require("./tools/bash");
6
11
  const {
7
12
  getRuntimePaths,
8
13
  ensureRuntimeDir,
@@ -43,10 +48,12 @@ module.exports = {
43
48
  TOOL_NAMES,
44
49
  normalizeToolName,
45
50
  runToolCall,
51
+ runToolCallAsync,
46
52
  runReadTool,
47
53
  runWriteTool,
48
54
  runEditTool,
49
55
  runBashTool,
56
+ runBashToolAsync,
50
57
  getRuntimePaths,
51
58
  ensureRuntimeDir,
52
59
  parseJsonLines,