Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(chat): deliver preview-linked files and legacy percent paths
ylliuuu6644c73c7b0297
diff --git a/apps/desktop/src/main/__tests__/rewindNativeBoundarySqlite.test.ts b/apps/desktop/src/main/__tests__/rewindNativeBoundarySqlite.test.tsindex 6a3c3e1214..46d792b8f1 100644--- a/apps/desktop/src/main/__tests__/rewindNativeBoundarySqlite.test.ts+++ b/apps/desktop/src/main/__tests__/rewindNativeBoundarySqlite.test.ts@@ -15,6 +15,13 @@ import type { DbClient } from '../localDb/client/DbClient';import { clearCurrentDbClient, setCurrentDbClient } from '../localDb/client/current';import { messages, sessions } from '../localDb/schema';+// Rewind imports fork's local history helpers, which also import the unrelated+// device-link host. Keep that host out of this real-SQL fixture; a remote call+// here is a test error, not a mocked successful rewind.+vi.mock('../device-link/index.js', () => ({+ remoteBackgroundInvoke: () => { throw new Error('unexpected remote invocation in local rewind'); },+}));+const commitRewindFilesMock = vi.fn();const isTurnRunningMock = vi.fn(() => false);const recomputePrRefsForSessionMock = vi.fn();diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.tsindex cf84467c21..17d08790c7 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts@@ -52,6 +52,31 @@ describe('group reply file delivery', () => {expect((await escaped.attachments[0]!.readBytes!()).toString()).toBe('%PDF-1.4\nreport');});+ // #6773 review: the outer link delivers a file even when its visible label is+ // an image. Keep that image markup for the existing image-delivery pass.+ it.each(['inline', 'reference', 'shared-reference'])('delivers a file with an image label (%s)', async mode => {+ const image = mode === 'inline' ? '' : '![preview][image]';+ const target = mode === 'shared-reference' ? 'image' : 'report';+ const body = mode === 'inline' ? `[${image}](<${pdf}>)`+ : `[${image}][${target}]\n\n[report]: <${pdf}>\n[image]: <${mode === 'shared-reference' ? pdf : './preview.png'}>`;+ const result = await prepareChatReplyFiles(body, 'lane', () => {});+ expect(result.attachments).toHaveLength(1);+ expect((await result.attachments[0]!.readBytes!()).toString()).toContain('%PDF');+ expect(result.text).toContain(image);+ expect(result.text).not.toContain(`[${image}]`);+ if (mode === 'shared-reference') expect(result.text).toContain(`[image]: <${pdf}>`);+ });++ it.each(['100% done.pdf', 'encoded%20.pdf'])('preserves legacy literal or once-encoded percent paths: %s', async name => {+ const file = path.join(work, name);+ await fs.writeFile(file, 'percent report');+ // A direct legacy URL is a URI with forward slashes on every platform.+ const direct = `xdt-file://${file.startsWith('/') ? '' : '/'}${file.replaceAll('\\', '/')}`;+ const encoded = pathToFileURL(file).href.replace(/^file:/, 'xdt-file:');+ const result = await prepareChatReplyFiles(`[file](<${name.startsWith('100') ? direct : encoded}>)`, 'lane', () => {});+ expect((await result.attachments[0]!.readBytes!()).toString()).toBe('percent report');+ });+it('preserves persisted Markdown for an empty SDK result without changing ordinary text replies', async () => {scope.reply = { content: JSON.stringify({ text: `[报告][r]\n\n[r]: <${pdf}>` }) };const result = await prepareChatReplyFiles(`[报告][r] [r]: <${pdf}>`, 'lane', () => {}, 'reply-client');diff --git a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.tsindex 1043b4d9ca..f5cc854e74 100644--- a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts+++ b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts@@ -64,8 +64,8 @@ export function replyFileLinks(text: string) {if (!target || !isFileTarget(target.url)) return;const start = node.position?.start.offset, end = node.position?.end.offset;const first = node.children[0]?.position?.start.offset, last = node.children.at(-1)?.position?.end.offset;- // A linked image belongs to image delivery, not this file path.- if (node.children.some(child => child.type === 'image' || child.type === 'imageReference')) return;+ // Keep nested image markup as the label for the later image-delivery pass;+ // the outer explicit file target still needs its own attachment.if (start === undefined || end === undefined || first === undefined || last === undefined) return;links.push({ url: target.url, start, end, label: text.slice(first, last) });if (node.type === 'linkReference') usedDefinitions.add(node.identifier);@@ -98,7 +98,17 @@ function localPath(url: string, workDir: string): string {if (!['', 'local', 'open'].includes(parsed.hostname)) throw unavailable();value = parsed.searchParams.get('path')!;if (!path.isAbsolute(value) && !/^[A-Za-z]:[\\/]/.test(value)) throw unavailable();- } else value = fileURLToPath(url.replace(/^xdt-file:/i, 'file:'));+ } else {+ try { value = fileURLToPath(url.replace(/^xdt-file:/i, 'file:')); }+ catch (error) {+ // Legacy hostless direct paths may contain an unencoded percent sign.+ // Match the existing decode-once-or-literal contract, without turning+ // a rejected host/network URL into a local path.+ if (!(error instanceof URIError) || !/^xdt-file:\/\/\//i.test(url)) throw error;+ value = url.slice('xdt-file://'.length).split(/[?#]/, 1)[0]!;+ if (process.platform === 'win32' && /^\/[A-Za-z]:[\\/]/.test(value)) value = value.slice(1);+ }+ }} else if (/^file:/i.test(url)) value = fileURLToPath(url);} catch { throw unavailable(); }// Never resolve a network/device path, including on another host platform.