Skip to content
TypeScript

fix(web): open files from Claude and ACP tool-call diffs (#29309)

Johan Vaz300101f7e511
diff --git a/apps/web/src/diffFileActions.test.ts b/apps/web/src/diffFileActions.test.ts
index b4fdb71f8d8..f7faf72ef8b 100644
--- a/apps/web/src/diffFileActions.test.ts
+++ b/apps/web/src/diffFileActions.test.ts
@@ -69,23 +69,45 @@ describe("openDiffFilePrimaryAction", () => {
).toBe("index.ts");
});
- it.each(["backend/server.ts", "frontend2/app.ts", "frontend/../secret.ts", "C:secret.ts"])(
- "does not open an out-of-project diff path: %s",
- (filePath) => {
- const openInEditor = vi.fn();
-
- openDiffFilePrimaryAction({
- threadRef: THREAD_REF,
- filePath,
- activeCwd: "/repo/frontend",
- repositoryRoot: "/repo",
- openInEditor,
- });
-
+ it.each([
+ {
+ filePath: "/repo/frontend/src/index.ts",
+ workspaceRoot: "/repo/frontend",
+ expected: "src/index.ts",
+ },
+ { filePath: "c:\\Repo\\src\\index.ts", workspaceRoot: "C:\\repo", expected: "src/index.ts" },
+ ])(
+ "opens absolute diff paths inside the workspace: $filePath",
+ ({ filePath, workspaceRoot, expected }) => {
expect(
- selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
- ).toMatchObject({ isOpen: false });
- expect(openInEditor).not.toHaveBeenCalled();
+ resolveDiffPathForWorkspace({ filePath, workspaceRoot, repositoryRoot: workspaceRoot }),
+ ).toBe(expected);
},
);
+
+ it.each([
+ "backend/server.ts",
+ "frontend2/app.ts",
+ "frontend/../secret.ts",
+ "C:secret.ts",
+ "/repo/backend/server.ts",
+ "/repo/frontend/../backend/server.ts",
+ "/repo/frontend",
+ "/etc/passwd",
+ ])("does not open an out-of-project diff path: %s", (filePath) => {
+ const openInEditor = vi.fn();
+
+ openDiffFilePrimaryAction({
+ threadRef: THREAD_REF,
+ filePath,
+ activeCwd: "/repo/frontend",
+ repositoryRoot: "/repo",
+ openInEditor,
+ });
+
+ expect(
+ selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
+ ).toMatchObject({ isOpen: false });
+ expect(openInEditor).not.toHaveBeenCalled();
+ });
});
diff --git a/apps/web/src/diffFileActions.ts b/apps/web/src/diffFileActions.ts
index 99baf13c941..c6a3fa3d436 100644
--- a/apps/web/src/diffFileActions.ts
+++ b/apps/web/src/diffFileActions.ts
@@ -1,5 +1,10 @@
import type { ScopedThreadRef } from "@t3tools/contracts";
-import { isWindowsAbsolutePath, normalizeProjectPathForComparison } from "@t3tools/shared/path";
+import {
+ isAbsolutePath,
+ isWindowsAbsolutePath,
+ normalizeProjectPathForComparison,
+ workspaceRelativeFilePath,
+} from "@t3tools/shared/path";
import { useRightPanelStore } from "./rightPanelStore";
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
@@ -52,6 +57,13 @@ export function resolveDiffPathForWorkspace(input: {
readonly workspaceRoot: string | undefined;
readonly repositoryRoot: string | undefined;
}): string | null {
+ // Claude and ACP tool-call diffs name files by absolute path.
+ if (isAbsolutePath(input.filePath)) {
+ const relativePath = workspaceRelativeFilePath(input.filePath, input.workspaceRoot);
+ const segments = relativePath === null ? null : normalizedRelativePathSegments(relativePath);
+ return segments ? segments.join("/") : null;
+ }
+
const fileSegments = normalizedRelativePathSegments(input.filePath);
if (!fileSegments) return null;