u-foo 3.1.5 → 3.1.7

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.
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u-foo",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
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",
@@ -50,91 +50,84 @@ function expandHome(filePath = "") {
50
50
  return text;
51
51
  }
52
52
 
53
- /**
54
- * Extract image file paths from terminal paste / drag-drop text.
55
- * Supports file://, quoted paths with spaces, and bare absolute paths.
56
- */
57
- function extractImagePathsFromPaste(text = "") {
53
+ // Parse terminal shell quoting without evaluating shell expressions. Keep source
54
+ // spans so the exact pasted spelling (including escapes) can be removed later.
55
+ function imagePathMatches(text = "") {
58
56
  const raw = String(text || "");
59
- if (!raw.trim()) return [];
60
- const found = [];
61
- const seen = new Set();
62
-
63
- function pushPath(candidate) {
64
- let next = decodeFileUrl(String(candidate || "").trim());
65
- next = next.replace(/^['"]|['"]$/g, "");
66
- if (!looksLikeImagePath(next)) return;
67
- next = expandHome(next);
68
- const key = path.resolve(next);
69
- if (seen.has(key)) return;
70
- seen.add(key);
71
- found.push(next);
72
- }
73
-
74
- // Quoted paths (possibly with spaces)
75
- const quoted = /["']([^"']+\.(?:png|jpe?g|gif|webp))["']/gi;
76
- let match;
77
- while ((match = quoted.exec(raw))) {
78
- pushPath(match[1]);
79
- }
80
-
81
- // file:// URLs
82
- const fileUrls = /file:\/\/[^\s"'<>]+/gi;
83
- while ((match = fileUrls.exec(raw))) {
84
- pushPath(match[0]);
85
- }
86
-
87
- // Bare tokens / lines
88
- for (const line of raw.split(/\r?\n/)) {
89
- const trimmed = line.trim();
90
- if (!trimmed) continue;
91
- if (looksLikeImagePath(trimmed)) {
92
- pushPath(trimmed);
93
- continue;
57
+ const matches = [];
58
+ let offset = 0;
59
+ for (const line of raw.split(/\n/)) {
60
+ const tokens = [];
61
+ let i = 0;
62
+ while (i < line.length) {
63
+ if (/\s/.test(line[i])) { i += 1; continue; }
64
+ const start = i;
65
+ let value = "";
66
+ let quote = "";
67
+ const windowsPath = /^[A-Za-z]:[\\/]/.test(line.slice(i).replace(/^["']/, ""));
68
+ while (i < line.length) {
69
+ const ch = line[i];
70
+ if (!quote && /\s/.test(ch)) break;
71
+ if (ch === quote) { quote = ""; i += 1; continue; }
72
+ if (!quote && (ch === "'" || ch === '"')) { quote = ch; i += 1; continue; }
73
+ if (ch === "\\" && quote !== "'" && !windowsPath && i + 1 < line.length
74
+ && (!quote || /[\\"$`]/.test(line[i + 1]))) {
75
+ value += line[i + 1];
76
+ i += 2;
77
+ continue;
78
+ }
79
+ value += ch;
80
+ i += 1;
81
+ }
82
+ tokens.push({ value, start: offset + start, end: offset + i });
94
83
  }
95
- for (const token of trimmed.split(/\s+/)) {
96
- if (looksLikeImagePath(token)) pushPath(token);
84
+ const trimmed = line.trim();
85
+ // Preserve support for a raw, unquoted absolute filename containing spaces.
86
+ // Escaped or quoted terminal input always uses the tokenized path above.
87
+ const rawWholePath = !/[\\"']/.test(trimmed)
88
+ && looksLikeImagePath(trimmed)
89
+ && tokens.filter((token) => looksLikeImagePath(token.value)).length < 2
90
+ && !tokens.slice(1).some((token) => /^(?:\/|file:\/\/|~\/)/.test(token.value));
91
+ const candidates = rawWholePath
92
+ ? [{ value: trimmed, start: offset + line.indexOf(trimmed), end: offset + line.indexOf(trimmed) + trimmed.length }]
93
+ : tokens;
94
+ for (const token of candidates) {
95
+ if (!looksLikeImagePath(token.value)) continue;
96
+ matches.push({ ...token, path: expandHome(decodeFileUrl(token.value)) });
97
97
  }
98
+ offset += line.length + 1;
98
99
  }
100
+ return matches;
101
+ }
99
102
 
100
- return found;
103
+ function extractImagePathsFromPaste(text = "") {
104
+ const seen = new Set();
105
+ return imagePathMatches(text).flatMap((match) => {
106
+ const key = path.resolve(match.path);
107
+ if (seen.has(key)) return [];
108
+ seen.add(key);
109
+ return [match.path];
110
+ });
101
111
  }
102
112
 
103
113
  function stripExtractedPathsFromText(text = "", paths = []) {
104
114
  let out = String(text || "");
105
- for (const p of paths) {
106
- const variants = [
107
- `"${p}"`,
108
- `'${p}'`,
109
- p,
110
- p.startsWith("/") ? `file://${p}` : "",
111
- p.startsWith("/") ? `file://${encodeURI(p)}` : "",
112
- ].filter(Boolean);
113
- for (const v of variants) {
114
- out = out.split(v).join(" ");
115
- }
115
+ const selected = new Set(paths.map((p) => path.resolve(p)));
116
+ const matches = imagePathMatches(out).filter((match) => selected.has(path.resolve(match.path)));
117
+ for (const match of matches.reverse()) {
118
+ out = `${out.slice(0, match.start)} ${out.slice(match.end)}`;
116
119
  }
117
- return out
118
- .replace(/[ \t]+\n/g, "\n")
119
- .replace(/\n{3,}/g, "\n\n")
120
- .replace(/[ \t]{2,}/g, " ")
121
- .replace(/\s+"/g, " ")
122
- .replace(/"\s+/g, " ")
123
- .replace(/\s+'/g, " ")
124
- .replace(/'\s+/g, " ")
125
- .trim();
120
+ return out.replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n")
121
+ .replace(/[ \t]{2,}/g, " ").trim();
126
122
  }
127
123
 
128
- function formatImageLogLabel({ relPath = "", fileName = "", path: pathText = "" } = {}) {
129
- const name = String(fileName || "").trim()
130
- || path.basename(String(relPath || pathText || "").trim())
131
- || "image";
132
- return `[image: ${name}]`;
124
+ function formatImageLogLabel(_attachment = {}, index = 0) {
125
+ return `[Image #${index + 1}]`;
133
126
  }
134
127
 
135
128
  function formatUserLogWithAttachments(userText = "", attachments = []) {
136
129
  const labels = (Array.isArray(attachments) ? attachments : [])
137
- .map((item) => formatImageLogLabel(item))
130
+ .map((item, index) => formatImageLogLabel(item, index))
138
131
  .filter(Boolean);
139
132
  const body = String(userText || "").trim();
140
133
  if (labels.length === 0) return body;
@@ -315,14 +308,18 @@ function handleImagePaste(text = "", {
315
308
  const paths = extractImagePathsFromPaste(raw);
316
309
  const attachments = [];
317
310
  const errors = [];
311
+ const importedPaths = [];
318
312
 
319
313
  for (const sourcePath of paths) {
320
314
  const ingested = ingestImageFile({ sourcePath, workspaceRoot, sessionId });
321
- if (ingested.ok) attachments.push(ingested);
315
+ if (ingested.ok) {
316
+ attachments.push(ingested);
317
+ importedPaths.push(sourcePath);
318
+ }
322
319
  else errors.push(ingested.error || "ingest failed");
323
320
  }
324
321
 
325
- let remaining = stripExtractedPathsFromText(raw, paths);
322
+ let remaining = stripExtractedPathsFromText(raw, importedPaths);
326
323
 
327
324
  // If paste had no usable text/paths, try clipboard PNG (Cmd+V of a screenshot).
328
325
  const trimmedRemaining = remaining.trim();
@@ -330,7 +327,7 @@ function handleImagePaste(text = "", {
330
327
  || /[\x00-\x08\x0e-\x1f]/.test(raw)
331
328
  || (Buffer.byteLength(raw, "utf8") > 200 && paths.length === 0 && !/\s/.test(raw.slice(0, 40)));
332
329
 
333
- if (tryClipboard && attachments.length === 0 && looksEmptyOrBinary) {
330
+ if (tryClipboard && paths.length === 0 && attachments.length === 0 && looksEmptyOrBinary) {
334
331
  const clip = tryIngestClipboardImage({
335
332
  workspaceRoot,
336
333
  sessionId,
@@ -127,11 +127,10 @@ const NATIVE_SSE_DISPATCHER_OPTIONS = Object.freeze({
127
127
  });
128
128
  /** Max text-only auto-continues while a plan is waiting on a task (per user submit). */
129
129
  const DEFAULT_MAX_PLAN_AUTO_CONTINUES = 24;
130
- // Anthropic Messages rejects max_tokens above the model's real cap (64K on
131
- // current models), so the transports use different defaults. Override either
132
- // via UFOO_UCODE_MAX_TOKENS (positive integer).
133
- const DEFAULT_OPENAI_MAX_TOKENS = 131072;
134
- const DEFAULT_ANTHROPIC_MAX_TOKENS = 64000;
130
+ // Reserve 32K output tokens by default across transports. Override via
131
+ // UFOO_UCODE_MAX_TOKENS (positive integer).
132
+ const DEFAULT_OPENAI_MAX_TOKENS = 32768;
133
+ const DEFAULT_ANTHROPIC_MAX_TOKENS = 32768;
135
134
  // Extended thinking defaults live in thinkingLevels.js (medium = 10k).
136
135
  // UFOO_UCODE_THINKING=off|low|medium|high|max selects a preset; numeric
137
136
  // UFOO_UCODE_THINKING_BUDGET_TOKENS still overrides. 0 disables thinking.
@@ -1779,8 +1778,8 @@ async function runAnthropicTurn({
1779
1778
  tools: buildAnthropicToolSpecs(),
1780
1779
  stream: true,
1781
1780
  };
1782
- const thinkingBudget = resolveThinkingBudgetTokens();
1783
- if (thinkingBudget > 0) {
1781
+ const thinkingBudget = Math.min(resolveThinkingBudgetTokens(), payload.max_tokens - 1);
1782
+ if (thinkingBudget >= 1024) {
1784
1783
  payload.thinking = { type: "enabled", budget_tokens: thinkingBudget };
1785
1784
  }
1786
1785
  if (Array.isArray(systemBlocks) && systemBlocks.length > 0) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- const DEFAULT_RESPONSES_MAX_OUTPUT_TOKENS = 131072;
3
+ const DEFAULT_RESPONSES_MAX_OUTPUT_TOKENS = 32768;
4
4
  const RESPONSES_REASONING_ITEMS = Symbol("ufoo.responsesReasoningItems");
5
5
 
6
6
  function cloneJsonValue(value) {
@@ -395,7 +395,7 @@ function redactUserMessageForLog(text = "") {
395
395
  const paths = [...block.matchAll(/^\s*-\s*(.+)$/gm)].map((m) => String(m[1] || "").trim());
396
396
  if (paths.length === 0) return "[image]";
397
397
  return paths
398
- .map((p) => `[image: ${require("path").basename(p)}]`)
398
+ .map((_, index) => `[Image #${index + 1}]`)
399
399
  .join(" ");
400
400
  },
401
401
  );
@@ -481,7 +481,7 @@ async function runUcodeRust(props = {}) {
481
481
  if (Array.isArray(outcome.errors) && outcome.errors.length > 0 && pendingAttachments.length === 0) {
482
482
  appendLog(`Image paste: ${outcome.errors[0]}`, "system");
483
483
  }
484
- const labels = pendingAttachments.map((item) => formatImageLogLabel(item) || "image");
484
+ const labels = pendingAttachments.map((item, index) => formatImageLogLabel(item, index));
485
485
  publish("attachments.set", {
486
486
  count: pendingAttachments.length,
487
487
  labels,