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): 补全命令写出路径识别

davida8f7bd8ac7ca
diff --git a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
index d6d2f71564..8f4cabcc5f 100644
--- a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
+++ b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
@@ -222,6 +222,12 @@ describe('extractCommandOutputPathCandidates', () => {
expect(extractCommandOutputPathCandidates("plt.savefig(fname='out/chart.pdf', bbox_inches='tight')")).toEqual([
'out/chart.pdf',
]);
+ expect(
+ extractCommandOutputPathCandidates("printf 'report' | tee 'out/report.md'"),
+ ).toEqual(['out/report.md']);
+ expect(extractCommandOutputPathCandidates('tee /work/out/report.txt')).toEqual([
+ '/work/out/report.txt',
+ ]);
expect(extractCommandOutputPathCandidates('cp source.txt output/')).toEqual(['output/source.txt']);
expect(extractCommandOutputPathCandidates('copy source.txt output\\')).toEqual(['output\\source.txt']);
expect(
@@ -236,6 +242,12 @@ describe('extractCommandOutputPathCandidates', () => {
expect(
extractCommandOutputPathCandidates('Copy-Item -Destination output/ -Path inputs/source.txt'),
).toEqual(['output/source.txt']);
+ expect(
+ extractCommandOutputPathCandidates("Copy-Item 'inputs/source.txt' 'artifacts/report.txt'"),
+ ).toEqual(['artifacts/report.txt']);
+ expect(extractCommandOutputPathCandidates('Copy-Item inputs/source.txt output/')).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 1a0198c6c5..adedeca21c 100644
--- a/apps/desktop/src/renderer/lib/generatedFiles.ts
+++ b/apps/desktop/src/renderer/lib/generatedFiles.ts
@@ -172,6 +172,7 @@ const POWERSHELL_WRITE_COMMANDS = new Set([
const OUTPUT_OPTION_PREFIX_RE = /(?:^|\s)(?:-o|--output(?:-file)?|--outfile)(?:\s+|=)['"]?$/i;
const REDIRECT_PREFIX_RE = /(?:^|[^>])>{1,2}\s*['"]?$/;
const SAVE_COMMAND_PREFIX_RE = /(?:^|[;&|]\s*|\s)save\s+['"]?$/i;
+const TEE_COMMAND_PREFIX_RE = /(?:^|[|;&]\s*)tee(?:\.exe)?\b[^|;&\r\n]*['"]?$/i;
function isPowerShellOutputPosition(before: string): boolean {
let lastCmdlet: RegExpMatchArray | null = null;
@@ -196,7 +197,8 @@ function isExplicitOutputPath(
isPowerShellOutputPosition(before) ||
OUTPUT_OPTION_PREFIX_RE.test(before) ||
REDIRECT_PREFIX_RE.test(before) ||
- SAVE_COMMAND_PREFIX_RE.test(before)
+ SAVE_COMMAND_PREFIX_RE.test(before) ||
+ TEE_COMMAND_PREFIX_RE.test(before)
) {
return true;
}
@@ -232,7 +234,12 @@ function isExplicitOutputPath(
.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);
+ const beforeInSegment = command.slice(segmentStart, token.start);
+ const hasExplicitDestination = /-(?:Destination|LiteralDestination|Target)\s+/i.test(segment);
+ if (hasExplicitDestination) {
+ return /-(?:Destination|LiteralDestination|Target)\s+['"]?$/i.test(beforeInSegment);
+ }
+ return lastPath?.start === token.start && lastPath.end === token.end;
}
return (
lastPath?.start === token.start &&