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 legacy file boundaries with projection regressions
DavidShenaf031af2dab4
diff --git a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.tsindex 088d50946d..9670120288 100644--- a/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/mobileToolProjection.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest';-import { extractPayloadToolResultMedia } from '@cindy/maker-shared/payload-summary';+import { extractPayloadToolResultMedia, extractPayloadToolResultFiles } from '@cindy/maker-shared/payload-summary';import {MOBILE_HISTORY_PAGE_BYTES, MOBILE_TOOL_RESULT_BYTES,projectMobileMessagePage, projectMobileToolMessage, projectMobileToolPush, projectMobileToolResult,@@ -14,6 +14,31 @@ 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"+ + '// 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 };+ const history = projectMobileMessagePage([row], {}) as typeof row[];+ expect(live.message).toEqual(history[0]);+ expect(live.message.content).toContain('const urls =');+ expect(live.message.content).toContain('[remote content truncated');+ expect(live.message.content).not.toContain('_xdt_model_files');+ expect(extractPayloadToolResultFiles(live.message.content)).toEqual([]);+ expect(new TextEncoder().encode(live.message.content).byteLength).toBeLessThanOrEqual(MOBILE_TOOL_RESULT_BYTES);+ expect(row.content).toBe(source);+ });+ it('preserves declared real files next to source fixtures during compaction', () => {+ const url = 'xdt-file:///tmp/report;final}.pdf';+ const content = JSON.stringify({+ text: "const fixture = 'xdt-file:///tmp/example.pdf';\n" + '// source\n'.repeat(1500),+ _xdt_model_files: [{ url, name: 'Report' }],+ });+ const projected = projectMobileToolResult(content) as string;+ expect(JSON.parse(projected)._xdt_model_files).toEqual([{ url, name: 'Report' }]);+ expect(extractPayloadToolResultFiles(projected)).toEqual([{ url, title: 'Report' }]);+ expect(new TextEncoder().encode(projected).byteLength).toBeLessThanOrEqual(MOBILE_TOOL_RESULT_BYTES);+ });it('retains bounded plugin call identity while compacting large arguments', () => {const projected = projectMobileToolMessage(tool('mcp__cindy__ghost_call', { ghost_id: 'art', tool: 'generate', grant_only: false, args: { data: 'x'.repeat(40_000) } })) as ReturnType<typeof tool>;expect(projected.content.input).toEqual({ ghost_id: 'art', tool: 'generate', grant_only: false });diff --git a/apps/mobile/src/__tests__/pluginResultRendering.test.ts b/apps/mobile/src/__tests__/pluginResultRendering.test.tsindex 3877bd9af6..af77468fd1 100644--- a/apps/mobile/src/__tests__/pluginResultRendering.test.ts+++ b/apps/mobile/src/__tests__/pluginResultRendering.test.ts@@ -11,6 +11,26 @@ 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'];";+ for (const content of [source, { text: source }]) {+ const rows = messages(content);+ rows[0].content = { toolName: 'Read', toolUseId: 'u', input: { file_path: '/tmp/source.ts' } };+ if (typeof content === 'string') rows[1].content = content;+ const normalized = normalizeRemoteMessages(rows).find((row) => row.kind === 'tool');+ expect(normalized?.files).toEqual([]);+ expect(normalized?.secondaryBody).toContain('const urls');+ expect(buildMobileMessageRenderItems(rows, { isSessionStreaming }).some((row) => row.type === 'tool_media')).toBe(false);+ }+ });+ it('retains a real file with legacy punctuation as a standalone delivery', () => {+ const file = "xdt-file:///tmp/O'Brien;[final]}.pdf";+ const rows = messages({ note: '[report](' + file + ')' });+ expect(normalizeRemoteMessages(rows).find((row) => row.kind === 'tool')?.files).toEqual([+ { url: file, title: "O'Brien;[final]}.pdf" },+ ]);+ expect(buildMobileMessageRenderItems(rows, { isSessionStreaming: false }).some((row) => row.type === 'tool_media')).toBe(true);+ });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 cc4da8bed5..6e3dbd549a 100644--- a/packages/maker-shared/src/__tests__/pluginResults.test.ts+++ b/packages/maker-shared/src/__tests__/pluginResults.test.ts@@ -4,6 +4,19 @@ import { hasVisibleHistoryResult } from '../historyViewProjection.js';const blob = (ext: string) => `cindy-media://blobs/${'a'.repeat(64)}.${ext}`;describe('portable plugin results', () => {+ it('preserves the legacy direct-path punctuation alphabet in real references', () => {+ // #4692 accepted these filename characters. Source filtering must not+ // redefine the URL alphabet and silently point to a different file.+ for (const punctuation of "!#$&'(*+,-.:;=?@[]^_{}~" + String.fromCharCode(96)) {+ const title = 'report' + punctuation + 'final.pdf';+ const url = 'xdt-file:///tmp/' + title;+ const expected = [{ url, title }];+ expect(files('[report](' + url + ')'), title).toEqual(expected);+ expect(files(JSON.stringify({ note: url })), title).toEqual(expected);+ expect(files(JSON.stringify([url])), title).toEqual(expected);+ expect(files(JSON.stringify({ _xdt_model_files: [{ url, name: title }] })), title).toEqual(expected);+ }+ });it('reads host ledger images, video and audio and deduplicates declarations', () => {const result = JSON.stringify({ xdt_image_urls: [blob('png')], xdt_media_produced: [blob('png'), blob('mp4'), blob('mp3'), blob('glb'), 'file:///secret.png', 'https://external/p.png', 'cindy-media://other/p.png'] });expect(media(result).map(({ kind, url }) => [kind, url])).toEqual([['image', blob('png')], ['video', blob('mp4')], ['audio', blob('mp3')]]);diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.tsindex 8e5864d75c..c6a8186f50 100644--- a/packages/maker-shared/src/payloadSummary.ts+++ b/packages/maker-shared/src/payloadSummary.ts@@ -466,7 +466,9 @@ export function extractPayloadToolCardIds(text: string): string[] {export interface PayloadToolFile { url: string; title: string }-const TOOL_FILE_URL_RE = /xdt-file:\/\/[^\s"<>\\)`};]+/g;+// Preserve the legacy URL alphabet. Source delimiters are contextual; adding+// filename punctuation here silently turns a valid reference into another path.+const TOOL_FILE_URL_RE = /xdt-file:\/\/[^\s"<>\\)]+/g;function absoluteToolFilePath(url: string): string | null {try {@@ -527,15 +529,15 @@ export function extractPayloadToolResultFiles(text: string): PayloadToolFile[] {let previous: { end: number; source: boolean } | undefined;for (let match; (match = urlPattern.exec(value));) {const start = match.index;- // An apostrophe is valid inside a file name. Only strip a closing quote- // when the URL has an opening quote. Keep adjacent quoted references- // separate, and leave apostrophes within each file name untouched.- const closingQuote = value[start - 1] === "'"- ? /'(?=[,.:!?\]]*(?:'xdt-file:\/\/|$))/.exec(match[0])+ // Quotes/backticks may be filename characters. Treat one as a delimiter+ // 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]): null;const url = closingQuote ? match[0].slice(0, closingQuote.index) : match[0];urlPattern.lastIndex = start + url.length;- const source = previous && /^'\s*,\s*'$/.test(value.slice(previous.end, start))+ const source = previous && /^(['`])\s*,\s*\1$/.test(value.slice(previous.end, start))? previous.source: looksLikeQuotedSourceLiteral(value, start, start + url.length);if (!source) add(url);