Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): preserve source context across string concatenation
DavidShen25ddd389920a
diff --git a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.tsindex e9bf81bebe..80e25e10af 100644--- a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts@@ -32,6 +32,7 @@ describe('mobile tool projection', () => {+ "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined\n"+ "const fallback = candidate || 'xdt-file:///tmp/logical.pdf'\n"+ "const paths = names.map(() => 'Open xdt-file:///tmp/callback.pdf')\n"+ + 'const combined = "prefix" + "xdt-file:///tmp/combined.pdf"\n'+ 'path = r"xdt-file:///tmp/python.pdf"\nvar path = @"Open xdt-file:///tmp/csharp.pdf"\n'+ '// fixture: xdt-file:///tmp/comment.pdf\n/* example: xdt-file:///tmp/block.pdf */\n'+ "const list = [/* first */ 'xdt-file:///tmp/a.pdf', // next\n 'xdt-file:///tmp/b.pdf']\n"diff --git a/apps/mobile/src/__tests__/pluginResultRendering.test.ts b/apps/mobile/src/__tests__/pluginResultRendering.test.tsindex a16d9c93cb..f2fb2de93b 100644--- a/apps/mobile/src/__tests__/pluginResultRendering.test.ts+++ b/apps/mobile/src/__tests__/pluginResultRendering.test.ts@@ -28,6 +28,7 @@ describe('plugin results are visible outside collapsed tool details', () => {+ "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined\n"+ "const fallback = candidate || 'xdt-file:///tmp/logical.pdf'\n"+ "const paths = names.map(() => 'Open xdt-file:///tmp/callback.pdf')\n"+ + 'const combined = "prefix" + "xdt-file:///tmp/combined.pdf"\n'+ 'path = r"xdt-file:///tmp/python.pdf"\nvar path = @"Open xdt-file:///tmp/csharp.pdf"\n'+ '// fixture: xdt-file:///tmp/comment.pdf\n/* example: xdt-file:///tmp/block.pdf */\n'+ "const list = [/* first */ 'xdt-file:///tmp/a.pdf', // next\n 'xdt-file:///tmp/b.pdf']";diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.tsindex d5b619a9ea..d0510aa736 100644--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts@@ -4,12 +4,33 @@ import { hasVisibleHistoryResult } from '../historyViewProjection.js';const blob = (ext: string) => `cindy-media://blobs/${'a'.repeat(64)}.${ext}`;describe('portable plugin results', () => {+ it.each(["'", '"', String.fromCharCode(96)])('keeps concatenated source literals out of delivered files: %s', (quote) => {+ const url = 'xdt-file:///tmp/concatenated.pdf';+ const literal = quote + url + quote;+ for (const source of [+ 'const path = "prefix" + ' + literal,+ 'const path = "prefix" + /* continuation */\n ' + literal,+ 'return "prefix" + " middle " + ' + literal,+ 'const path = "prefix"+' + quote + 'Open ' + url + quote,+ ]) {+ expect(files(source), source).toEqual([]);+ expect(files(JSON.stringify({ text: source })), source).toEqual([]);+ expect(files(source + '\nSaved ' + literal)).toEqual([{ url, title: 'concatenated.pdf' }]);+ expect(files(JSON.stringify({ text: source, _xdt_model_files: [{ url, name: 'Concatenated' }] })))+ .toEqual([{ url, title: 'Concatenated' }]);+ }+ const next = 'xdt-file:///tmp/next.pdf';+ expect(files('Saved ' + literal + ' + ' + quote + next + quote)).toEqual([+ { url, title: 'concatenated.pdf' }, { url: next, title: 'next.pdf' },+ ]);+ expect(files('Saved "prefix" + ' + literal)).toEqual([{ url, title: 'concatenated.pdf' }]);+ });it.each(['r', 'R', 'f', 'F', 'b', 'u', 'br', 'rb', 'fr', 'rf', '@', '$', '@$', '$@'])('recognizes source literals with prefix %s', (prefix) => {const url = 'xdt-file:///tmp/prefixed.pdf';for (const quote of (prefix.includes('@') || prefix.includes('$') ? ['"'] : ["'", '"'])) {for (const content of [url, 'Open ' + url]) {const literal = prefix + quote + content + quote;- for (const source of ['path = ' + literal, 'return ' + literal, 'open(' + literal + ')', 'paths = [' + literal + ']']) {+ for (const source of ['path = ' + literal, 'return ' + literal, 'open(' + literal + ')', 'paths = [' + literal + ']', 'path = "prefix" + ' + literal]) {expect(files(source), source).toEqual([]);expect(files(JSON.stringify({ text: source })), source).toEqual([]);expect(files(source + '\nSaved "' + url + '"')).toEqual([{ url, title: 'prefixed.pdf' }]);diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.tsindex c5beacd028..f5eae147bc 100644--- a/packages/maker-shared/src/payloadSummary.ts+++ b/packages/maker-shared/src/payloadSummary.ts@@ -547,18 +547,22 @@ function withoutSourceComments(text: string): string {return parts.join('');}+function sourceLiteralPrefix(text: string, quoteIndex: number): string {+ const rawPrefix = text.slice(0, quoteIndex);+ // Python/C# literal markers sit between the source operator and quote.+ // Only unwrap a recognized, adjacent marker; still require source syntax+ // before it, and never strip a suffix from an identifier such as "offer".+ const marker = text[quoteIndex] === '`' ? null : /(?:\b(?:br|rb|fr|rf|[rubf])|\$@|@\$|[$@])$/i.exec(rawPrefix);+ return (marker ? rawPrefix.slice(0, marker.index) : rawPrefix).trimEnd();+}+function looksLikeQuotedSourceLiteral(text: string, index: number, end: number): boolean {const before = text[index - 1];const after = text[end];if (before !== '`' && before !== '\'' && before !== '"') return false;// Quotes alone also occur in prose and inline Markdown. Require source syntax// around the literal (assignment, collection entry, argument or conditional).- const rawPrefix = text.slice(0, index - 1);- // Python/C# literal markers sit between the source operator and quote.- // Only unwrap a recognized, adjacent marker; still require source syntax- // before it, and never strip a suffix from an identifier such as "offer".- const marker = before === '`' ? null : /(?:\b(?:br|rb|fr|rf|[rubf])|\$@|@\$|[$@])$/i.exec(rawPrefix);- const prefix = (marker ? rawPrefix.slice(0, marker.index) : rawPrefix).trimEnd();+ const prefix = sourceLiteralPrefix(text, index - 1);return /(?:[=\[(,?]|=>|&&|\|\||\breturn)$/.test(prefix)// A colon alone is also a prose label ("File:"). Require a preceding// conditional, allowing indented continuation lines but not new prose.@@ -576,9 +580,12 @@ function* quotedSourceRanges(text: string): Generator<{ start: number; end: numbconst start = token.start;// Tool output may end mid-literal after the Host applies its byte budget.const end = token.end - (token.closed ? 1 : 0);- const continuesList = previous- && withoutSourceComments(text.slice(previous.end + 1, start)).trim() === ',';- const source: boolean = previous && continuesList+ // Comments are already masked. Carry the established context across a list+ // or concatenation, including prefixed literals, without treating prose ++ // as source syntax by itself.+ const separator = previous ? sourceLiteralPrefix(text, start).slice(previous.end + 1).trim() : '';+ const continuesExpression = separator === ',' || separator === '+';+ const source: boolean = previous && continuesExpression? previous.source: looksLikeQuotedSourceLiteral(text, start + 1, end);if (source) yield { start, end };