Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/desktop/src/renderer/__tests__/generatedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,40 @@ describe('collectGeneratedFiles', () => {
expect(files[0].source).toBe('tool');
});

it('collapses doubled backslashes so escaped wrapper commands do not duplicate chips', () => {
// 实测场景(pr-watch session):powershell 包一层 node -e,落库命令文本里的
// 路径带转义残留(`C:\\Users\\...`);同轮另一条命令用正斜杠形态。fs 层它们
// 是同一文件(Windows 归并重复分隔符),不折叠会出两个同名 chip。
const files = collectGeneratedFiles(
[
toolUse('Bash', {
command: "powershell -Command '$p = 'C:\\\\Users\\\\U\\\\pr-watch\\\\registry.json'; Get-Content $p'",
}),
toolUse('Bash', {
command: "node -e \"const p='C:/Users/U/pr-watch/registry.json'; console.log(p);\"",
}),
],
'C:\\Users\\U\\pr-watch',
);
const registry = files.filter((f) => f.name === 'registry.json');
expect(registry).toHaveLength(1);
// 画布路径本身也折叠成单反斜杠本机形态,不带转义残留。
expect(registry[0].path).toBe('C:\\Users\\U\\pr-watch\\registry.json');
});

it('keeps the UNC leading double backslash while collapsing inner separator runs', () => {
const files = collectGeneratedFiles(
[
toolUse('Bash', { command: "copy out '\\\\server\\share\\\\dir\\report.csv'" }),
toolUse('Bash', { command: "open '\\\\server\\share\\dir\\report.csv'" }),
],
'C:\\work',
);
const reports = files.filter((f) => f.name === 'report.csv');
expect(reports).toHaveLength(1);
expect(reports[0].path.startsWith('\\\\server\\')).toBe(true);
});
Comment on lines +154 to +157

it('excludes command mentions of files edited by file tools this turn', () => {
// 编码会话形态:Edit 改了源码文件,随后命令引用它(跑测试)。它是编辑不是
// 新建,不能因 mtime 落在本轮窗口就被当成产物。
Expand Down
17 changes: 14 additions & 3 deletions apps/desktop/src/renderer/lib/generatedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ interface ToolUseLike {
*/
function dedupeKeyForPath(abs: string): string {
const isWindowsShape = /^[a-zA-Z]:[\\/]/.test(abs) || abs.includes('\\');
if (!isWindowsShape) return abs;
// 斜杠也归一:`C:/x/a.md`(命令文本常见形态)与 `C:\x\a.md`(Write 记录)是
// 同一文件,不折叠会重复出 chip。
return isWindowsShape ? abs.replace(/\//g, '\\').toLowerCase() : abs;
// 同一文件,不折叠会重复出 chip。连续分隔符同理折叠:命令文本常是二次转义的
// 包装串(如 powershell 包一层 node -e),提取出的 `C:\\x\\a.md` 与 `C:\x\a.md`
// 在 fs 层等价(Windows 归并重复分隔符),不折叠会对同一文件出两个 chip。
// UNC 头部的 `\\` 是路径语义的一部分,保留。
return abs
.replace(/\//g, '\\')
.replace(/(?<!^)\\{2,}/g, '\\')
Comment on lines +59 to +62

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 POSIX 路径被错误折叠

当 Linux 或 macOS 的合法路径包含字面反斜杠时,abs.includes('\\') 会将其当作 Windows 路径,进而折叠反斜杠并转为小写;两个仅在反斜杠数量或大小写上不同的文件会得到相同去重 key,导致后出现的生成文件 chip 被静默丢弃。

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/lib/generatedFiles.ts
Line: 59-62

Comment:
**POSIX 路径被错误折叠**

当 Linux 或 macOS 的合法路径包含字面反斜杠时,`abs.includes('\\')` 会将其当作 Windows 路径,进而折叠反斜杠并转为小写;两个仅在反斜杠数量或大小写上不同的文件会得到相同去重 key,导致后出现的生成文件 chip 被静默丢弃。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

.toLowerCase();
Comment on lines +60 to +63
}

/**
Expand All @@ -63,7 +70,11 @@ function dedupeKeyForPath(abs: string): string {
* 路径原样保留。
*/
function canonicalizeWindowsShape(abs: string): string {
return /^[a-zA-Z]:[\\/]/.test(abs) ? abs.replace(/\//g, '\\') : abs;
// 连续分隔符折叠进画布路径本身(不只 dedupe key):stat 虽能容忍 `C:\\x`,但
// Explorer `/select` 与 chip 展示不该带转义残留。盘符形态不存在 UNC 头,可整段折叠。
return /^[a-zA-Z]:[\\/]/.test(abs)
? abs.replace(/\//g, '\\').replace(/\\{2,}/g, '\\')
: abs;
Comment on lines +74 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 UNC 输出路径未规范化

当首个 UNC 候选包含内部重复反斜杠时,去重 key 虽会折叠这些分隔符,但 canonicalizeWindowsShape 会原样保留该路径;去重后 chip tooltip、文件打开和 Explorer 定位仍会收到带转义残留的 UNC 路径。

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/lib/generatedFiles.ts
Line: 74-77

Comment:
**UNC 输出路径未规范化**

当首个 UNC 候选包含内部重复反斜杠时,去重 key 虽会折叠这些分隔符,但 `canonicalizeWindowsShape` 会原样保留该路径;去重后 chip tooltip、文件打开和 Explorer 定位仍会收到带转义残留的 UNC 路径。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}

/** 单条 tool_use 消息 → 它新建的文件原始路径列表(可能为空)。 */
Expand Down
Loading