u-foo 3.0.2 → 3.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u-foo",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Multi-Agent Workspace Protocol. Just add u. claude → uclaude, codex → ucodex.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://ufoo.dev",
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Tool description for read_image (workspace vision).
5
+ */
6
+
7
+ const READ_IMAGE_TOOL_NAME = "read_image";
8
+
9
+ function getReadImageToolDescription() {
10
+ return `Read an image file from the workspace so the model can see it.
11
+
12
+ Usage notes:
13
+ - The path parameter is relative to the workspace root.
14
+ - Supports png, jpeg, gif, and webp. Max size ~5MB.
15
+ - Use this instead of read for screenshots, UI mocks, diagrams, and other binary images.
16
+ - Text files still use read. Do not call read_image on non-image files.
17
+ - Vision is attached for the current model call only; call read_image again if you need the image later.`;
18
+ }
19
+
20
+ module.exports = {
21
+ READ_IMAGE_TOOL_NAME,
22
+ getReadImageToolDescription,
23
+ };
@@ -34,6 +34,7 @@ const {
34
34
  const { renderExecutionSegmentContext } = require("./executionSegment");
35
35
  const { renderPlanModeContext } = require("./planMode");
36
36
  const { drainAgentMailboxForTurn } = require("../runtime/agentWakeup");
37
+ const { stripVisionBase64, degradeVisionContent } = require("../providers/visionBlocks");
37
38
 
38
39
  const DEFAULT_TRANSCRIPT_WINDOW = 12;
39
40
  const DEFAULT_RECENT_TOOL_EVENTS = 4;
@@ -291,6 +292,19 @@ function sanitizeModelMessages(messages = []) {
291
292
  continue;
292
293
  }
293
294
 
295
+ // Drop ephemeral OpenAI vision companion user messages (image_url data URIs)
296
+ // when rebuilding history so base64 does not re-enter later turns.
297
+ if (role === "user" && Array.isArray(message.content)) {
298
+ const hasImageUrl = message.content.some((block) => (
299
+ block && String(block.type || "").trim().toLowerCase() === "image_url"
300
+ ));
301
+ if (hasImageUrl) {
302
+ const degraded = degradeVisionContent(message.content);
303
+ out.push({ role: "user", content: degraded });
304
+ continue;
305
+ }
306
+ }
307
+
294
308
  out.push(message);
295
309
  }
296
310
  return out;
@@ -435,16 +449,18 @@ function persistToolResultToContext({
435
449
  rawResult = {},
436
450
  segmentId = "",
437
451
  } = {}) {
452
+ const rawForStorage = stripVisionBase64(rawResult);
438
453
  const saved = saveArtifact(workspaceRoot, sessionId, {
439
454
  type: "tool_result",
440
455
  tool,
441
456
  args,
442
- raw: rawResult,
457
+ raw: rawForStorage,
443
458
  createdBy: tool,
444
459
  });
445
460
  const artifactId = saved.artifact && saved.artifact.artifactId
446
461
  ? saved.artifact.artifactId
447
462
  : "";
463
+ // Reduce from the live result so vision base64 stays available for this turn.
448
464
  const reduced = reduceToolResult(tool, rawResult, artifactId, args);
449
465
  return {
450
466
  artifactId,
@@ -181,7 +181,7 @@ function formatPlanModeStatus(executionState = null) {
181
181
  lines.push("Rules while ON:");
182
182
  lines.push(" - Use plan_graph to create/expand/complete the plan");
183
183
  lines.push(" - write / edit / bash are blocked as direct tools");
184
- lines.push(" - read / artifact_read allowed for exploration");
184
+ lines.push(" - read / read_image / artifact_read allowed for exploration");
185
185
  lines.push(" - Runtime auto-advances ready tool nodes after plan_graph");
186
186
  lines.push(" - User leaves with /plan off (agents cannot toggle Plan Mode)");
187
187
  } else {
@@ -223,7 +223,7 @@ function renderPlanModeContext(executionState = null) {
223
223
  }
224
224
 
225
225
  lines.push(
226
- "Allowed direct tools: read, artifact_read, plan_graph, ask_user.",
226
+ "Allowed direct tools: read, read_image, artifact_read, plan_graph, ask_user.",
227
227
  "Blocked direct tools: write, edit, bash (route them as plan_graph tool nodes or task_loop).",
228
228
  "Plan Mode constrains the Agent Loop only; running TaskLoops are not paused or reconfigured by /plan off.",
229
229
  "Only the user can leave Plan Mode (/plan off). That does not cancel the graph or TaskRuns — use cancel_graph / control.cancel_task.",
@@ -232,6 +232,7 @@ function renderPlanModeContext(executionState = null) {
232
232
  " 2) expand_node on the current ready/waiting task when needed",
233
233
  " 3) Runtime executes ready tools / TaskLoops; continue from results",
234
234
  " 4) control.complete_task (inline) or control.start_task (task_loop)",
235
+ "Do not end the turn with text only while a task is waiting — advance it.",
235
236
  "Do not mix plan_graph with data-plane tools in the same turn.",
236
237
  );
237
238
 
@@ -31,7 +31,7 @@ const {
31
31
  } = require("../skills");
32
32
  const { hashContent } = require("./artifacts");
33
33
 
34
- const PROMPT_VERSION = "native-v6";
34
+ const PROMPT_VERSION = "native-v7";
35
35
 
36
36
  function buildImmutablePrefix() {
37
37
  return [
@@ -44,23 +44,25 @@ function buildImmutablePrefix() {
44
44
  getOutputEfficiencySection(),
45
45
  [
46
46
  "Tool calling grammar:",
47
- "- Use read, write, edit, bash, and artifact_read for direct, single-goal work, even when it takes several tool calls.",
47
+ "- Use read, write, edit, bash, and artifact_read for direct, single-goal text work, even when it takes several tool calls.",
48
+ "- Use read_image to load workspace png/jpeg/gif/webp images for vision. Do not use read on binary images. Vision is attached for the active model call only; call read_image again if you need the image later.",
48
49
  "- TaskRuns are orthogonal to Plan Mode. A TaskRun does not require Plan Mode or a plan_graph. Use task_run operation=start with an objective for a standalone single-point TaskRun; it starts asynchronously and returns immediately.",
49
50
  "- On complex or multi-goal requests, automatically decompose into concrete sub-objectives and start TaskRun(s) via task_run. Prefer task_run for independent or loosely coupled tracks; use plan_graph only when you need durable dependencies, checkpoints, or a shared executable plan.",
50
51
  "- Use plan_graph for durable graph structure: create, patch, inspect, cancel_graph, and control. Graph-bound TaskRuns use plan_graph control.start_task on execution.kind=task_loop nodes.",
51
- "- Plan Mode is a runtime posture for the Agent Loop, not an agent tool. While Plan Mode is ON, direct write, edit, and bash calls from the Agent Loop are blocked; read and artifact_read remain available. TaskRuns still run independently of Plan Mode.",
52
+ "- Plan Mode is a runtime posture for the Agent Loop, not an agent tool. While Plan Mode is ON, direct write, edit, and bash calls from the Agent Loop are blocked; read, read_image, and artifact_read remain available. TaskRuns still run independently of Plan Mode.",
52
53
  "- In the Agent Loop, plan_graph operation=create automatically enables Plan Mode. The user may also use /plan on or /plan off.",
53
54
  "- Turning Plan Mode off does not cancel an existing graph or running TaskRuns. Cancel with task_run (standalone) or plan_graph operation=cancel_graph / control.cancel_task (graph-bound).",
54
55
  "- When the user enables Plan Mode and no active graph exists, create a plan_graph before performing side effects.",
55
56
  "- After an accepted plan_graph create or patch, Runtime automatically advances ready tool nodes. Never invent or request an execute_graph tool.",
56
- "- Do not call plan_graph or task_run together with read, write, edit, bash, or artifact_read in the same assistant turn.",
57
+ "- Do not call plan_graph or task_run together with read, read_image, write, edit, bash, or artifact_read in the same assistant turn.",
57
58
  "- When an active graph is waiting on a task, advance that node through plan_graph instead of bypassing it with direct workspace tools: use patch.expand_node for execution.kind=expand, control.complete_task (nodeId) for execution.kind=inline_llm, or control.start_task for execution.kind=task_loop.",
59
+ "- Do not end a turn with text only while the plan is still waiting on a task; expand, start, or complete that node. Runtime will auto-continue if you stop early, but prefer advancing in the same turn.",
58
60
  "- control.complete_task with nodeId completes a waiting_llm inline_llm task for the current Graph owner. control.complete_task with taskRunId (or task_run complete) is reserved for the owning TaskLoop. Do not directly complete expand or aggregate tasks.",
59
61
  "- While Plan Mode is ON, workspace mutations must be represented as plan_graph tool nodes or performed inside a running TaskRun/task_loop.",
60
62
  "- Treat a User reminder as the latest user instruction. Reconcile it before continuing from tool results. If it is compatible with the active plan, resume the waiting plan node; otherwise patch, cancel, or replan first.",
61
63
  "- TaskLoops do not consume User reminders. The Agent Loop is woken by runtime task_started, task_succeeded, task_failed, and task_cancelled events.",
62
64
  "- Runtime enforces TaskRun concurrency limits and workspace write leases. Direct Agent write, edit, or bash calls may be rejected while writing TaskRuns are active.",
63
- "- Tool results may contain an artifactId. Use artifact_read to hydrate raw stored output or a slice of it; use read for workspace file paths.",
65
+ "- Tool results may contain an artifactId. Use artifact_read to hydrate raw stored output or a slice of it; use read for workspace text paths; use read_image for workspace images.",
64
66
  "- Use ask_user only when user input is required to proceed. It must be the only tool call in the turn. Use kind=approval for yes/no confirmation, kind=choice for numbered options, and kind=chat for free text.",
65
67
  "- The answer to ask_user is returned only as that tool's result, not as a separate user message or pending User reminder. Continue from the returned answer and do not repeat the question.",
66
68
  "- ask_user is available only to the Agent Loop. It pauses the Agent Loop, but running TaskRuns continue unless explicitly cancelled.",
@@ -287,9 +287,43 @@ function reduceArtifactReadResult(raw = {}, artifactId = "") {
287
287
  };
288
288
  }
289
289
 
290
+ function reduceReadImageResult(raw = {}, artifactId = "") {
291
+ const source = raw && typeof raw === "object" ? raw : {};
292
+ const pathText = String(source.path || "").trim();
293
+ const mediaType = String(source.mediaType || "").trim();
294
+ const bytes = Number.isFinite(source.bytes) ? source.bytes : null;
295
+ const preview = source.ok === false
296
+ ? clipText(String(source.error || "read_image failed"), PREVIEW_MAX_CHARS)
297
+ : clipText(
298
+ `image ${pathText || "file"} (${mediaType || "unknown"}, ${bytes != null ? `${bytes} bytes` : "size?"})`,
299
+ PREVIEW_MAX_CHARS,
300
+ );
301
+ const modelPayload = {
302
+ ok: source.ok !== false,
303
+ kind: "image",
304
+ artifactId,
305
+ path: pathText,
306
+ mediaType,
307
+ bytes,
308
+ preview,
309
+ };
310
+ if (source.error) modelPayload.error = String(source.error);
311
+ // Keep base64 in the in-memory model payload for the current turn only.
312
+ // Artifacts / transcript strip it via stripVisionBase64 before persistence.
313
+ if (modelPayload.ok && source.base64) {
314
+ modelPayload.base64 = String(source.base64);
315
+ }
316
+ return {
317
+ preview,
318
+ summary: `read_image ${pathText || "file"} (${mediaType || "image"})`,
319
+ modelPayload,
320
+ };
321
+ }
322
+
290
323
  function reduceToolResult(tool = "", raw = {}, artifactId = "", args = {}) {
291
324
  const name = String(tool || "").trim().toLowerCase();
292
325
  if (name === "read") return reduceReadResult(raw, artifactId);
326
+ if (name === "read_image") return reduceReadImageResult(raw, artifactId);
293
327
  if (name === "bash") return reduceBashResult(raw, artifactId, args);
294
328
  if (name === "write") return reduceWriteResult(raw, artifactId);
295
329
  if (name === "edit") return reduceEditResult(raw, artifactId);
@@ -318,6 +352,7 @@ module.exports = {
318
352
  parseSearchMatches,
319
353
  reduceToolResult,
320
354
  reduceReadResult,
355
+ reduceReadImageResult,
321
356
  reduceBashResult,
322
357
  reduceTestResult,
323
358
  reduceGitDiffResult,
@@ -5,6 +5,7 @@ const {
5
5
  createTranscriptEventId,
6
6
  appendTranscriptEvent,
7
7
  } = require("./transcript");
8
+ const { stripVisionBase64, degradeVisionContent } = require("../providers/visionBlocks");
8
9
 
9
10
  function messageRole(message = {}) {
10
11
  return String(message && message.role || "").trim().toLowerCase();
@@ -35,6 +36,24 @@ function parseToolArtifactContent(content = "") {
35
36
  }
36
37
  }
37
38
 
39
+ function contentForStorage(content) {
40
+ if (typeof content === "string") return content;
41
+ if (Array.isArray(content)) {
42
+ const hasVision = content.some((block) => {
43
+ if (!block || typeof block !== "object") return false;
44
+ const type = String(block.type || "").trim().toLowerCase();
45
+ return type === "image" || type === "image_url"
46
+ || (type === "tool_result" && Array.isArray(block.content));
47
+ });
48
+ if (hasVision) return degradeVisionContent(stripVisionBase64(content));
49
+ return stripVisionBase64(content);
50
+ }
51
+ if (content && typeof content === "object") {
52
+ return stripVisionBase64(content);
53
+ }
54
+ return content;
55
+ }
56
+
38
57
  function messageToTranscriptEventForStorage(message = {}, extra = {}) {
39
58
  if (!message || typeof message !== "object") return null;
40
59
  const role = messageRole(message);
@@ -60,9 +79,10 @@ function messageToTranscriptEventForStorage(message = {}, extra = {}) {
60
79
  toolCallId: message.tool_call_id ? String(message.tool_call_id) : undefined,
61
80
  });
62
81
  }
63
- const preview = typeof message.content === "string"
64
- ? message.content.slice(0, 600)
65
- : JSON.stringify(message.content).slice(0, 600);
82
+ const stored = contentForStorage(message.content);
83
+ const preview = typeof stored === "string"
84
+ ? stored.slice(0, 600)
85
+ : JSON.stringify(stored).slice(0, 600);
66
86
  return normalizeTranscriptEvent({
67
87
  ...base,
68
88
  role: "tool",
@@ -75,14 +95,14 @@ function messageToTranscriptEventForStorage(message = {}, extra = {}) {
75
95
  if (role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.length > 0) {
76
96
  return normalizeTranscriptEvent({
77
97
  ...base,
78
- content: message.content,
98
+ content: contentForStorage(message.content),
79
99
  toolCalls: message.tool_calls,
80
100
  });
81
101
  }
82
102
 
83
103
  return normalizeTranscriptEvent({
84
104
  ...base,
85
- content: message.content,
105
+ content: contentForStorage(message.content),
86
106
  });
87
107
  }
88
108
 
@@ -104,6 +104,52 @@ function buildContinuationUserPrompt(userText = "", executionState = null) {
104
104
  return formatUserReminderMessage([text], { waitingFor: waiting });
105
105
  }
106
106
 
107
+ const PLAN_AUTO_CONTINUE_STOP_REASONS = new Set([
108
+ "approval_required",
109
+ "graph_terminal",
110
+ "scheduler_deadlock",
111
+ ]);
112
+
113
+ /**
114
+ * Whether the Agent Loop should keep going after a text-only model turn
115
+ * because the plan graph is still waiting on an agent-actionable task.
116
+ */
117
+ function shouldAutoContinuePlan(executionState = null) {
118
+ if (!executionState || typeof executionState !== "object") return false;
119
+ if (executionState.pendingUserInteraction) return false;
120
+ const pg = executionState.planGraph && typeof executionState.planGraph === "object"
121
+ ? executionState.planGraph
122
+ : null;
123
+ if (!pg) return false;
124
+ const waiting = pg.waitingFor && typeof pg.waitingFor === "object" ? pg.waitingFor : null;
125
+ if (!waiting || !waiting.id) return false;
126
+ if (String(waiting.type || "").trim().toLowerCase() !== "task") return false;
127
+ const yieldReason = String(pg.lastYieldReason || "").trim().toLowerCase();
128
+ if (yieldReason && PLAN_AUTO_CONTINUE_STOP_REASONS.has(yieldReason)) return false;
129
+ return true;
130
+ }
131
+
132
+ /**
133
+ * Internal reminder injected by runtime when the model ends a turn while the
134
+ * plan is still waiting on a task. Same shape as user nudges.
135
+ */
136
+ function buildPlanAutoContinueReminder(executionState = null) {
137
+ const waiting = executionState
138
+ && executionState.planGraph
139
+ && executionState.planGraph.waitingFor
140
+ ? executionState.planGraph.waitingFor
141
+ : null;
142
+ if (!waiting || !waiting.id) return "";
143
+ return formatUserReminderMessage(
144
+ [
145
+ "Continue the active plan. Serve the waiting task now via plan_graph "
146
+ + "(expand_node, control.start_task, or control.complete_task as appropriate). "
147
+ + "Do not end the turn with text only while this node is waiting.",
148
+ ],
149
+ { waitingFor: waiting },
150
+ );
151
+ }
152
+
107
153
  module.exports = {
108
154
  ensurePendingUserPrompts,
109
155
  enqueueUserPrompt,
@@ -113,4 +159,7 @@ module.exports = {
113
159
  shouldFrameAsUserReminder,
114
160
  formatUserReminderMessage,
115
161
  buildContinuationUserPrompt,
162
+ shouldAutoContinuePlan,
163
+ buildPlanAutoContinueReminder,
164
+ PLAN_AUTO_CONTINUE_STOP_REASONS,
116
165
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { runReadTool } = require("./tools/read");
4
+ const { runReadImageTool } = require("./tools/readImage");
4
5
  const { runWriteTool } = require("./tools/write");
5
6
  const { runEditTool } = require("./tools/edit");
6
7
  const { runBashTool } = require("./tools/bash");
@@ -11,6 +12,7 @@ const { runAskUserTool } = require("./tools/askUser");
11
12
 
12
13
  const TOOL_NAMES = [
13
14
  "read",
15
+ "read_image",
14
16
  "write",
15
17
  "edit",
16
18
  "bash",
@@ -23,6 +25,7 @@ const TOOL_NAMES = [
23
25
  function normalizeToolName(value = "") {
24
26
  const text = String(value || "").trim().toLowerCase();
25
27
  if (text === "read") return "read";
28
+ if (text === "read_image" || text === "read-image" || text === "readimage") return "read_image";
26
29
  if (text === "write") return "write";
27
30
  if (text === "edit") return "edit";
28
31
  if (text === "bash") return "bash";
@@ -44,6 +47,7 @@ function runToolCall(input = {}, options = {}) {
44
47
  };
45
48
  }
46
49
  if (tool === "read") return runReadTool(args, options);
50
+ if (tool === "read_image") return runReadImageTool(args, options);
47
51
  if (tool === "write") return runWriteTool(args, options);
48
52
  if (tool === "edit") return runEditTool(args, options);
49
53
  if (tool === "artifact_read") return runArtifactReadTool(args, options);