Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(chat): normalize explicit reply file targets and Windows identity
ylliuuu66538e275172a9
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.tsindex 17d08790c7..15acc21d80 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerReplyFiles.test.ts@@ -77,6 +77,38 @@ describe('group reply file delivery', () => {expect((await result.attachments[0]!.readBytes!()).toString()).toBe('percent report');});+ it('leaves ordinary relative navigation targets unchanged without file authority', async () => {+ scope.snapshot = null;+ const text = '[help](about) [guide][nav]\n\n[nav]: getting-started';+ expect(await prepareChatReplyFiles(text, 'lane', () => {})).toEqual({ text, attachments: [] });+ });++ it.each(['image', 'reference', 'image-reference'])('recovers escaped file targets with %s labels', async mode => {+ const image = '';+ const body = mode === 'image' ? `[${image}](<${pdf}>)`+ : `[${mode === 'reference' ? 'report' : image}][r]\n\n[r]: <${pdf}>`;+ const result = await prepareChatReplyFiles(body, 'lane', () => {});+ expect(result.attachments).toHaveLength(1);+ expect((await result.attachments[0]!.readBytes!()).toString()).toContain('%PDF');+ expect(result.text.trim()).toBe(mode === 'reference' ? 'report' : image);+ });++ it('does not recover escaped targets in code or HTML examples', async () => {+ const text = '`[report](<missing file.pdf>)`\n\n```md\n[r]: <missing file.pdf>\n```\n\n<div>\n[report](<missing file.pdf>)\n</div>';+ scope.snapshot = null;+ expect(await prepareChatReplyFiles(text, 'lane', () => {})).toEqual({ text, attachments: [] });+ });++ it('deduplicates case variants according to the host path semantics before applying the count limit', async () => {+ const names = process.platform === 'win32'+ ? Array.from({ length: 32 }, (_, mask) => [...'report'].map((c, i) => mask & (1 << i) ? c.toUpperCase() : c).join('') + '.pdf')+ : ['Report.pdf', 'report.pdf'];+ for (const name of names) await fs.writeFile(path.join(work, name), 'case report');+ const result = await prepareChatReplyFiles(names.map(name => `[report](${name})`).join(' '), 'lane', () => {});+ expect(result.attachments).toHaveLength(process.platform === 'win32' ? 1 : 2);+ for (const attachment of result.attachments) expect((await attachment.readBytes!()).toString()).toBe('case 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 f5cc854e74..d994433160 100644--- a/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts+++ b/apps/desktop/src/main/maker-ipc/chatServerReplyFiles.ts@@ -31,7 +31,10 @@ function isFileTarget(value: string): boolean {if (!value || /^[#?]/.test(value)) return false;value = withoutLineLocator(value);if (/^(?:file|xdt-file|sandbox):/i.test(value) || /^[A-Za-z]:[\\/]/.test(value)) return true;- return !/^[A-Za-z][A-Za-z0-9+.-]*:/.test(value);+ if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(value)) return false;+ // Match the renderer's local-path shape; `about` is navigation, while+ // `./README`, `documents/report.pdf` and `report.pdf` are explicit files.+ return /[\\/]/.test(value) || /\.[a-z0-9]{1,10}(\?.*)?$/i.test(value);}/** Only actual Markdown file links are deliveries; code, images and remote URLs are not. */@@ -43,8 +46,10 @@ export function replyFileLinks(text: string) {const start = node.position?.start.offset, end = node.position?.end.offset;if (start === undefined || end === undefined) return;const raw = text.slice(start, end);- const normalized = raw.replace(/(\[[^\]\n]+\]\()<([^\n]*?)>(\))/g,- (match, before, target, after) => isFileTarget(target) ? `${before}<${target}>${after}` : match);+ // The closing label delimiter can follow a separate image AST node.+ // Definitions with escaped space-containing targets are text until reparsed.+ const normalized = raw.replace(/(\]\(|(?:^|\n)[ \t]{0,3}\[[^\]\n]+\]:[ \t]*)<([^\n]*?)>/g,+ (match, before, target) => isFileTarget(target) ? `${before}<${target}>` : match);if (normalized !== raw) escaped.push({ start, end, text: normalized });});for (const edit of escaped.sort((a, b) => b.start - a.start))@@ -188,9 +193,12 @@ export async function prepareChatReplyFiles(text: string, sessionId: string, assconst lexicalRoot = path.resolve(scope.workingDir!);if (!isPathWithin(lexicalRoot, source) && !isPathWithin(root, source)) throw unavailable();const canonicalSource = isPathWithin(root, source) ? source : path.resolve(root, path.relative(lexicalRoot, source));- if (seen.has(canonicalSource)) continue;+ // Windows path identity ignores case; preserve the original spelling for+ // subsequent realpath, descriptor and workdir checks.+ const identity = process.platform === 'win32' ? canonicalSource.toLowerCase() : canonicalSource;+ if (seen.has(identity)) continue;if (attachments.length >= BOT_GROUP_ATTACHMENTS_MAX) throw unavailable();- seen.add(canonicalSource);+ seen.add(identity);let digest: string | undefined;attachments.push({ id: canonicalSource, name: path.basename(source), category: 'file',mimeType: path.extname(source).toLowerCase() === '.pdf' ? 'application/pdf' : 'application/octet-stream',