Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 完善复制产物路径解析
david1c5e5c93a869
diff --git a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts b/apps/desktop/src/renderer/__tests__/generatedFiles.test.tsindex a10074731f..7ed1ca5be1 100644--- a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts+++ b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts@@ -212,10 +212,16 @@ describe('extractCommandOutputPathCandidates', () => {expect(extractCommandOutputPathCandidates("Path('out/data.bin').write_bytes(payload)"),).toEqual(['out/data.bin']);- expect(extractCommandOutputPathCandidates('cp source.txt output/')).toEqual(['output/']);- expect(extractCommandOutputPathCandidates('copy source.txt output\\')).toEqual(['output\\']);+ expect(extractCommandOutputPathCandidates('cp source.txt output/')).toEqual(['output/source.txt']);+ expect(extractCommandOutputPathCandidates('copy source.txt output\\')).toEqual(['output\\source.txt']);expect(extractCommandOutputPathCandidates('cp inputs/a.txt inputs/b.txt output/'),+ ).toEqual(['output/a.txt', 'output/b.txt']);+ expect(+ extractCommandOutputPathCandidates('Get-ChildItem inputs/source.txt | Copy-Item -Destination output/'),+ ).toEqual(['output/source.txt']);+ expect(+ extractCommandOutputPathCandidates('Get-ChildItem inputs/ | Copy-Item -Destination output/'),).toEqual(['output/']);});diff --git a/apps/desktop/src/renderer/lib/generatedFiles.ts b/apps/desktop/src/renderer/lib/generatedFiles.tsindex d2a85a2f1a..bf4f720bd8 100644--- a/apps/desktop/src/renderer/lib/generatedFiles.ts+++ b/apps/desktop/src/renderer/lib/generatedFiles.ts@@ -234,10 +234,48 @@ function isExplicitOutputPath(return (lastPath?.start === token.start &&lastPath.end === token.end &&- /^(?:cp|copy|Copy-Item)\s+/i.test(segment.trim())+ /(?:^|\|\s*)(?:cp|copy|Copy-Item)\s+/i.test(segment.trim()));}+function copyDirectoryOutputs(+ command: string,+ destination: CommandPathToken,+ tokens: readonly CommandPathToken[],+): string[] {+ if (!/[\\/]$/.test(destination.path)) return [destination.path];+ const previousSeparators = [+ { index: command.lastIndexOf(';', destination.start - 1), length: 1 },+ { index: command.lastIndexOf('\n', destination.start - 1), length: 1 },+ { index: command.lastIndexOf('&&', destination.start - 1), length: 2 },+ { index: command.lastIndexOf('||', destination.start - 1), length: 2 },+ ];+ const previousSeparator = previousSeparators.reduce((latest, candidate) =>+ candidate.index > latest.index ? candidate : latest,+ );+ const segmentStart = previousSeparator.index + previousSeparator.length;+ const nextSeparators = [+ command.indexOf(';', destination.end),+ command.indexOf('\n', destination.end),+ command.indexOf('&&', destination.end),+ command.indexOf('||', destination.end),+ ].filter((index) => index >= 0);+ const segmentEnd = nextSeparators.length > 0 ? Math.min(...nextSeparators) : command.length;+ const sourcePaths = tokens+ .filter((token) => token.start >= segmentStart && token.end <= destination.start)+ .filter((token) => token.start !== destination.start && !/[\\/]$/.test(token.path))+ .map((token) => token.path);+ const beforeDestination = command.slice(segmentStart, destination.start);+ for (const match of beforeDestination.matchAll(/(?:^|[\s'"])([^\s'"]+\.[A-Za-z][A-Za-z0-9]{0,7})(?=$|[\s'"])/g)) {+ if (!sourcePaths.includes(match[1])) sourcePaths.push(match[1]);+ }+ const outputs = sourcePaths.map((source) => {+ const sourceName = source.replace(/[\\/]$/, '').split(/[\\/]/).at(-1);+ return sourceName ? `${destination.path}${sourceName}` : null;+ }).filter((path): path is string => Boolean(path));+ return outputs.length > 0 ? outputs : [destination.path];+}+/*** 命令文本 → 明确写出位置里的产物路径候选。*@@ -250,9 +288,12 @@ export function extractCommandOutputPathCandidates(command: string): string[] {const seen = new Set<string>();const out: string[] = [];for (const token of tokens) {- if (!isExplicitOutputPath(command, token, tokens) || seen.has(token.path)) continue;- seen.add(token.path);- out.push(token.path);+ if (!isExplicitOutputPath(command, token, tokens)) continue;+ for (const output of copyDirectoryOutputs(command, token, tokens)) {+ if (seen.has(output)) continue;+ seen.add(output);+ out.push(output);+ }}return out;}