Skip to content

Commit 6632e52

Browse files
Jo2234claude
andcommitted
fix(web): open files from Claude and ACP tool-call diffs
Claude and ACP providers record tool-call edits with absolute file paths. resolveDiffPathForWorkspace rejected every absolute path, so clicking a file name in a tool-call diff did nothing and its context menu was empty. Absolute paths inside the workspace now resolve to workspace-relative paths; paths outside it are still rejected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 47f2c8d commit 6632e52

2 files changed

Lines changed: 51 additions & 17 deletions

File tree

‎apps/web/src/diffFileActions.test.ts‎

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,45 @@ describe("openDiffFilePrimaryAction", () => {
6969
).toBe("index.ts");
7070
});
7171

72-
it.each(["backend/server.ts", "frontend2/app.ts", "frontend/../secret.ts", "C:secret.ts"])(
73-
"does not open an out-of-project diff path: %s",
74-
(filePath) => {
75-
const openInEditor = vi.fn();
76-
77-
openDiffFilePrimaryAction({
78-
threadRef: THREAD_REF,
79-
filePath,
80-
activeCwd: "/repo/frontend",
81-
repositoryRoot: "/repo",
82-
openInEditor,
83-
});
84-
72+
it.each([
73+
{
74+
filePath: "/repo/frontend/src/index.ts",
75+
workspaceRoot: "/repo/frontend",
76+
expected: "src/index.ts",
77+
},
78+
{ filePath: "c:\\Repo\\src\\index.ts", workspaceRoot: "C:\\repo", expected: "src/index.ts" },
79+
])(
80+
"opens absolute diff paths inside the workspace: $filePath",
81+
({ filePath, workspaceRoot, expected }) => {
8582
expect(
86-
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
87-
).toMatchObject({ isOpen: false });
88-
expect(openInEditor).not.toHaveBeenCalled();
83+
resolveDiffPathForWorkspace({ filePath, workspaceRoot, repositoryRoot: workspaceRoot }),
84+
).toBe(expected);
8985
},
9086
);
87+
88+
it.each([
89+
"backend/server.ts",
90+
"frontend2/app.ts",
91+
"frontend/../secret.ts",
92+
"C:secret.ts",
93+
"/repo/backend/server.ts",
94+
"/repo/frontend/../backend/server.ts",
95+
"/repo/frontend",
96+
"/etc/passwd",
97+
])("does not open an out-of-project diff path: %s", (filePath) => {
98+
const openInEditor = vi.fn();
99+
100+
openDiffFilePrimaryAction({
101+
threadRef: THREAD_REF,
102+
filePath,
103+
activeCwd: "/repo/frontend",
104+
repositoryRoot: "/repo",
105+
openInEditor,
106+
});
107+
108+
expect(
109+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
110+
).toMatchObject({ isOpen: false });
111+
expect(openInEditor).not.toHaveBeenCalled();
112+
});
91113
});

‎apps/web/src/diffFileActions.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { ScopedThreadRef } from "@t3tools/contracts";
2-
import { isWindowsAbsolutePath, normalizeProjectPathForComparison } from "@t3tools/shared/path";
2+
import {
3+
isAbsolutePath,
4+
isWindowsAbsolutePath,
5+
normalizeProjectPathForComparison,
6+
workspaceRelativeFilePath,
7+
} from "@t3tools/shared/path";
38

49
import { useRightPanelStore } from "./rightPanelStore";
510
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
@@ -52,6 +57,13 @@ export function resolveDiffPathForWorkspace(input: {
5257
readonly workspaceRoot: string | undefined;
5358
readonly repositoryRoot: string | undefined;
5459
}): string | null {
60+
// Claude and ACP tool-call diffs name files by absolute path.
61+
if (isAbsolutePath(input.filePath)) {
62+
const relativePath = workspaceRelativeFilePath(input.filePath, input.workspaceRoot);
63+
const segments = relativePath === null ? null : normalizedRelativePathSegments(relativePath);
64+
return segments ? segments.join("/") : null;
65+
}
66+
5567
const fileSegments = normalizedRelativePathSegments(input.filePath);
5668
if (!fileSegments) return null;
5769

0 commit comments

Comments
 (0)