From f5c23a4eaf124f2fe3015c3ccbbcf7f978e43525 Mon Sep 17 00:00:00 2001 From: kahme247 <61059522+kahme247@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:35:17 +0000 Subject: [PATCH] fix(chat): keep Windows drive paths intact in tool-row file links ToolCallBlock stripped a trailing : suffix with split(":")[0], which also split the drive-letter colon: every Windows read/edit tool row linked to onOpenFile("C"), opening a file:C tab that can never resolve. The same expression mangled POSIX filenames containing a colon. Strip only a trailing : suffix instead, so C:\...\file.ts, C:/.../file.ts:42, and src/my:file.txt all open correctly. --- components/MessageView.test.mjs | 23 +++++++++++++++++++++++ components/MessageView.tsx | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/components/MessageView.test.mjs b/components/MessageView.test.mjs index 3789df1fd..cb83a1c35 100644 --- a/components/MessageView.test.mjs +++ b/components/MessageView.test.mjs @@ -241,6 +241,29 @@ test("read paths with an internal URL scheme are not file links", () => { assert.match(render("src/foo.ts:10"), /activity-file-link/); }); +test("tool-row file links keep Windows drive paths and colon filenames intact", () => { + const cases = [ + // Drive-letter colon is not a line suffix: splitting on ":" opened "C". + ["C:\\Users\\me\\proj\\src\\file.ts", "C:\\Users\\me\\proj\\src\\file.ts"], + ["C:/Users/me/proj/src/file.ts:42", "C:/Users/me/proj/src/file.ts"], + ["src/my:file.txt", "src/my:file.txt"], + ]; + for (const [path, expected] of cases) { + const openedFiles = []; + const { container } = render(React.createElement(MessageView, { + onOpenFile(file) { openedFiles.push(file); }, + message: { + role: "assistant", + content: [{ type: "toolCall", toolCallId: "call-1", toolName: "read", input: { path } }], + }, + })); + // File links render as a clickable span (role="button"), unlike web URLs. + fireEvent.click(container.querySelector(".activity-file-link")); + assert.deepEqual(openedFiles, [expected], path); + cleanup(); + } +}); + test("read paths with a web URL open the fetched page in a new tab without toggling the row", () => { const opened = []; const originalOpen = window.open; diff --git a/components/MessageView.tsx b/components/MessageView.tsx index 82f65b5a1..c5f882f03 100644 --- a/components/MessageView.tsx +++ b/components/MessageView.tsx @@ -1023,7 +1023,10 @@ const ToolCallBlock = memo(function ToolCallBlock({ // `history://`, `proc://`, `local://`, ... are resolved by omp, not files the viewer can open. const hasUrlScheme = rawFilePath !== null && /^[a-z][a-z0-9+.-]*:\/\//i.test(rawFilePath); const webUrl = hasUrlScheme && /^https?:\/\//i.test(rawFilePath) ? readTargetWebUrl(rawFilePath) : null; - const cleanFilePath = rawFilePath && !hasUrlScheme ? rawFilePath.split(":")[0] : null; + // Strip only a trailing : suffix. Splitting on the first ":" broke + // every Windows absolute path (C:\... -> "C") and POSIX filenames + // containing a colon; a drive-letter colon is never a line suffix. + const cleanFilePath = rawFilePath && !hasUrlScheme ? rawFilePath.replace(/:\d+$/, "") : null; return (