Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(shared): handle conditional literals and adjacent quoted references
DavidShenfa5374ccb1c7
diff --git a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.tsindex 9670120288..5d411d25f7 100644--- a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts@@ -16,6 +16,7 @@ const tool = (toolName = 'Bash', input: unknown = { command: 'echo hello ' + 'x'describe('mobile tool projection', () => {it('keeps large source output as text instead of promoting fixtures to file declarations', () => {const source = "const urls = ['xdt-file://open?path=%2Ftmp%2Ffixture.pdf', 'xdt-file:///tmp/example.html'];\n"+ + "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined\n"+ '// source 中文\n'.repeat(1500);const row = { ...tool('Read'), role: 'tool_result', content: source };const live = projectMobileToolPush('local-db:messages:created', { message: row }) as { message: typeof row };diff --git a/apps/mobile/src/__tests__/pluginResultRendering.test.ts b/apps/mobile/src/__tests__/pluginResultRendering.test.tsindex af77468fd1..e4bb196c56 100644--- a/apps/mobile/src/__tests__/pluginResultRendering.test.ts+++ b/apps/mobile/src/__tests__/pluginResultRendering.test.ts@@ -12,7 +12,8 @@ function messages(content: unknown): RemoteMessage[] {}describe('plugin results are visible outside collapsed tool details', () => {it.each([true, false])('does not render source fixtures as delivered files (streaming=%s)', (isSessionStreaming) => {- const source = "const urls = ['xdt-file://open?path=%2Ftmp%2Ffixture.pdf', 'xdt-file:///tmp/example.html'];";+ const source = "const urls = ['xdt-file://open?path=%2Ftmp%2Ffixture.pdf', 'xdt-file:///tmp/example.html'];\n"+ + "const path = enabled ? 'xdt-file:///tmp/conditional.pdf' : undefined";for (const content of [source, { text: source }]) {const rows = messages(content);rows[0].content = { toolName: 'Read', toolUseId: 'u', input: { file_path: '/tmp/source.ts' } };@@ -31,6 +32,16 @@ describe('plugin results are visible outside collapsed tool details', () => {]);expect(buildMobileMessageRenderItems(rows, { isSessionStreaming: false }).some((row) => row.type === 'tool_media')).toBe(true);});+ it('retains all adjacent quoted file references in the mobile render model', () => {+ const first = 'xdt-file:///tmp/first.pdf';+ const second = 'xdt-file:///tmp/second.pdf';+ for (const quote of ['"', String.fromCharCode(96)]) {+ const rows = messages({ note: 'Saved ' + quote + first + quote + ', ' + quote + second + quote });+ expect(normalizeRemoteMessages(rows).find((row) => row.kind === 'tool')?.files).toEqual([+ { url: first, title: 'first.pdf' }, { url: second, title: 'second.pdf' },+ ]);+ }+ });it.each([true, false])('keeps partner authorization and delivered assets as independent visible rows (streaming=%s)', (isSessionStreaming) => {const rows = messages({ ok: true, result: { xdt_image_url: url, xdt_card_id: 'card', _xdt_model_files: [{ url: url.replace('.png', '.glb') }] } });const user: RemoteMessage = { ...rows[0], id: 'user', clientId: 'user', role: 'user', toolUseId: null, content: 'Draw a cat', createdAt: '2025-12-31T23:59:58Z' };diff --git a/packages/maker-shared/src/__tests__/pluginResults.test.ts b/packages/maker-shared/src/__tests__/pluginResults.test.tsindex 6e3dbd549a..da1a53444e 100644--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts@@ -117,6 +117,35 @@ describe('portable plugin results', () => {]);expect(files('const urls = [' + list + '];')).toEqual([]);});+ it.each(["'", '"', String.fromCharCode(96)])('distinguishes conditional source literals from prose quoted with %s', (quote) => {+ const url = 'xdt-file:///tmp/fixture.pdf';+ const literal = quote + url + quote;+ for (const source of [+ 'const path = enabled ? ' + literal + ' : undefined',+ 'const path = enabled ? undefined : ' + literal,+ 'return enabled ? ' + literal + ' : ' + literal,+ 'const path = enabled\n ? undefined\n : ' + literal,+ ]) {+ expect(files(source)).toEqual([]);+ expect(files(JSON.stringify({ text: source }))).toEqual([]);+ expect(files(source + '\nFile: ' + literal)).toEqual([{ url, title: 'fixture.pdf' }]);+ }+ });+ it('retains adjacent prose references for every quote style without reviving source arrays', () => {+ const a = 'xdt-file:///tmp/first.pdf';+ const b = 'xdt-file:///tmp/second.pdf';+ for (const left of ["'", '"', String.fromCharCode(96)]) {+ for (const right of ["'", '"', String.fromCharCode(96)]) {+ for (const separator of [',', ', ']) {+ const list = left + a + left + separator + right + b + right;+ const expected = [{ url: a, title: 'first.pdf' }, { url: b, title: 'second.pdf' }];+ expect(files('Saved ' + list), list).toEqual(expected);+ expect(files(JSON.stringify({ note: 'Saved ' + list })), list).toEqual(expected);+ expect(files('const paths = [' + list + '];'), list).toEqual([]);+ }+ }+ }+ });it.each(["xdt-file:///tmp/O'Brien.pdf","xdt-file:///C:/reports/O'Brien.pdf",diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.tsindex c6a8186f50..2d0a5a0a08 100644--- a/packages/maker-shared/src/payloadSummary.ts+++ b/packages/maker-shared/src/payloadSummary.ts@@ -487,9 +487,12 @@ function looksLikeQuotedSourceLiteral(text: string, index: number, end: number):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 return).+ // around the literal (assignment, collection entry, argument or conditional).const prefix = text.slice(0, index - 1).trimEnd();- return /(?:[=\[(,]|\breturn)$/.test(prefix)+ 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.+ || (prefix.endsWith(':') && /\?(?:[^;\r\n]|\r?\n[ \t])*:$/.test(prefix))|| /[{,]\s*(?:[\w$]+|["'][^"']+["'])\s*:$/.test(prefix)|| (after === before && /^\s*;/.test(text.slice(end + 1)));}@@ -533,11 +536,11 @@ export function extractPayloadToolResultFiles(text: string): PayloadToolFile[] {// only when it matches the opening wrapper around this reference.const quote = value[start - 1];const closingQuote = quote === "'" || quote === '`'- ? new RegExp(quote + '(?=[,.;:!?\\]}]*(?:' + quote + 'xdt-file://|$))').exec(match[0])+ ? new RegExp(quote + '(?=[,.;:!?\\]}]*(?:["\'`]xdt-file://|$))').exec(match[0]): null;const url = closingQuote ? match[0].slice(0, closingQuote.index) : match[0];urlPattern.lastIndex = start + url.length;- const source = previous && /^(['`])\s*,\s*\1$/.test(value.slice(previous.end, start))+ const source = previous && /^["'`]\s*,\s*["'`]$/.test(value.slice(previous.end, start))? previous.source: looksLikeQuotedSourceLiteral(value, start, start + url.length);if (!source) add(url);