Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 完善生成文件写出识别

davidd3b5336d02ff
diff --git a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
index 7f8ce71bc5..d6d2f71564 100644
--- a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
+++ b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
@@ -218,6 +218,10 @@ describe('extractCommandOutputPathCandidates', () => {
expect(
extractCommandOutputPathCandidates("workbook.to_excel(excel_writer=\"out/report.xlsx\")"),
).toEqual(['out/report.xlsx']);
+ expect(extractCommandOutputPathCandidates("plt.savefig('out/chart.png')")).toEqual(['out/chart.png']);
+ expect(extractCommandOutputPathCandidates("plt.savefig(fname='out/chart.pdf', bbox_inches='tight')")).toEqual([
+ 'out/chart.pdf',
+ ]);
expect(extractCommandOutputPathCandidates('cp source.txt output/')).toEqual(['output/source.txt']);
expect(extractCommandOutputPathCandidates('copy source.txt output\\')).toEqual(['output\\source.txt']);
expect(
@@ -229,6 +233,9 @@ describe('extractCommandOutputPathCandidates', () => {
expect(
extractCommandOutputPathCandidates('Get-ChildItem inputs/ | Copy-Item -Destination output/'),
).toEqual(['output/']);
+ expect(
+ extractCommandOutputPathCandidates('Copy-Item -Destination output/ -Path inputs/source.txt'),
+ ).toEqual(['output/source.txt']);
});
it('skips temp dirs, extension-less tokens, plain filenames and URLs', () => {
diff --git a/apps/desktop/src/renderer/lib/generatedFiles.ts b/apps/desktop/src/renderer/lib/generatedFiles.ts
index ceef76ddef..1a0198c6c5 100644
--- a/apps/desktop/src/renderer/lib/generatedFiles.ts
+++ b/apps/desktop/src/renderer/lib/generatedFiles.ts
@@ -159,7 +159,7 @@ function extractCommandPathTokens(command: string): CommandPathToken[] {
}
const WRITE_CALL_PREFIX_RE =
- /(?:\.|\b)(?:save|writeFileSync|writeFile|writeAllText|writeAllBytes|createWriteStream|write_text|write_bytes|to_csv|to_excel|to_json|to_parquet|imwrite|imsave|dump)\s*\(\s*(?:(?:path_or_buf|excel_writer|path|filename|fname|fp|file)\s*=\s*)?(?:[rubf]{0,2})?['"]$/i;
+ /(?:\.|\b)(?:save|savefig|writeFileSync|writeFile|writeAllText|writeAllBytes|createWriteStream|write_text|write_bytes|to_csv|to_excel|to_json|to_parquet|imwrite|imsave|dump)\s*\(\s*(?:(?:path_or_buf|excel_writer|path|filename|fname|fp|file)\s*=\s*)?(?:[rubf]{0,2})?['"]$/i;
const POWERSHELL_CMDLET_RE = /\b[A-Za-z][A-Za-z0-9]*-[A-Za-z][A-Za-z0-9-]*\b/g;
const POWERSHELL_WRITE_COMMANDS = new Set([
'out-file',
@@ -231,6 +231,9 @@ function isExplicitOutputPath(
.filter((candidate) => candidate.start >= segmentStart && candidate.end <= segmentEnd)
.sort((a, b) => a.start - b.start || a.end - b.end)
.at(-1);
+ if (/(?:^|\|\s*)Copy-Item\b/i.test(segment.trim())) {
+ return /-(?:Destination|LiteralDestination|Target)\s+['"]?$/i.test(before);
+ }
return (
lastPath?.start === token.start &&
lastPath.end === token.end &&
@@ -262,13 +265,18 @@ function copyDirectoryOutputs(
].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))
+ .filter((token) => token.start >= segmentStart && token.end <= segmentEnd)
+ .filter((token) => token.start !== destination.start)
+ .filter((token) => !/[\\/]$/.test(token.path))
.map((token) => token.path);
const beforeDestination = command.slice(segmentStart, destination.start);
+ const afterDestination = command.slice(destination.end, segmentEnd);
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]);
}
+ for (const match of afterDestination.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;