u-foo 3.1.5 → 3.1.6

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.6",
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,
@@ -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,