@devries-cameron20 / t3code-1 / commits / 9a79883979
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): a file opened from a diff in a project folder inside a repository opens that file (#32684)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Entrpi committed Nov 15, 2026 at 17:26 UTC 9a79883979e962b6befb45bd4817a2129a55bf28
2 files changed +54 -4
apps/web/src/components/DiffPanel.browser.test.tsx
+49 -2
@@ -6,6 +6,7 @@ import {
6 ProjectId,
7 RunId,
8 ThreadId,
9 + TurnItemId,
10 type ClientSettings,
11 type ReviewBranchCommitsResult,
12 type ReviewDiffPreviewResult,
@@ -31,6 +32,11 @@ const state = vi.hoisted(() => ({
32 previews: new Map<string | null, ResultAtom<ReviewDiffPreviewResult>>(),
33 patch: null as unknown as ResultAtom<ReviewDiffPreviewSource>,
34 diffFilesCollapsed: false,
35 + project: {
36 + workspaceRoot: "/project",
37 + repositoryIdentity: null as { rootPath: string } | null,
38 + },
39 + toolCallItem: null as unknown,
40 config: null as unknown as Atom.Atom<null>,
41 status: null as unknown as ResultAtom<VcsStatusResult>,
42 localRefs: null as unknown as ResultAtom<VcsListRefsResult>,
@@ -61,7 +67,7 @@ vi.mock("~/state/vcs", () => ({
67 }));
68 vi.mock("~/state/entities", () => ({
69 useQuietThreadShell: () => state.thread,
64 - useProject: () => ({ workspaceRoot: "/project", repositoryIdentity: null }),
70 + useProject: () => state.project,
71 useThreadCheckpointSummaries: () => state.checkpoints,
72 useQuietThreadVisibleTurnItems: () => [],
73 }));
@@ -81,7 +87,11 @@ vi.mock("~/hooks/useTheme", () => ({
87 }));
88 vi.mock("~/state/queries", () => ({
89 useCheckpointDiff: () => ({ data: state.checkpointDiff, error: null, isPending: false }),
84 - useTurnItemDetail: () => ({ data: null, error: null, isPending: false }),
90 + useTurnItemDetail: () => ({
91 + data: state.toolCallItem ? { item: state.toolCallItem } : null,
92 + error: null,
93 + isPending: false,
94 + }),
95 useDebouncedValue: <A,>(value: A) => value,
96 }));
97 vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => async () => {} }));
@@ -131,6 +141,8 @@ function setup(failedBaseRef: string | null) {
141 };
142 reset();
143 state.diffFilesCollapsed = false;
144 + state.project = { workspaceRoot: "/project", repositoryIdentity: null };
145 + state.toolCallItem = null;
146 state.checkpoints = [];
147 state.checkpointDiff = null;
148 const patch = Atom.make<AsyncResult.AsyncResult<ReviewDiffPreviewSource, Error>>(
@@ -368,3 +380,38 @@ it.each([
380 .element(screen.getByRole("button", { name: `Collapse ${name}`, exact: true }))
381 .toHaveAttribute("aria-expanded", "true");
382 });
383 +
384 +it("opens a file from a tool call's diff by the path its agent recorded", async () => {
385 + using context = setup("origin/orphan");
386 + // A local thread in a project that is the repository's apps/web folder.
387 + state.thread = { ...state.thread!, worktreePath: null };
388 + state.project = { workspaceRoot: "/repo/apps/web", repositoryIdentity: { rootPath: "/repo" } };
389 + const status = AsyncResult.getOrThrow(context.registry.get(state.status));
390 + state.status = Atom.make(
391 + AsyncResult.success({ ...status, workingTree: { ...status.workingTree, rootPath: "/repo" } }),
392 + );
393 + // Claude's Edit can record a path relative to the workspace, unlike the repository's diffs.
394 + state.toolCallItem = {
395 + type: "file_change",
396 + fileName: "src/a.ts",
397 + diffStr: "--- src/a.ts\n+++ src/a.ts\n@@ -1 +1 @@\n-before\n+after\n",
398 + };
399 + useDiffPanelStore.getState().selectToolCall(context.threadRef, {
400 + threadId: context.threadRef.threadId,
401 + itemId: TurnItemId.make("edit"),
402 + revision: "1",
403 + });
404 + await using screen = await render(
405 + <RegistryContext.Provider value={context.registry}>
406 + <div className="flex h-[600px] flex-col">
407 + <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
408 + </div>
409 + </RegistryContext.Provider>,
410 + );
411 + await userEvent.click(screen.getByText("src/a.ts", { exact: true }));
412 + await vi.waitFor(() =>
413 + expect(
414 + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, context.threadRef),
415 + ).toMatchObject({ activeSurfaceId: "file:src/a.ts" }),
416 + );
417 +});
apps/web/src/components/DiffPanel.tsx
+5 -2
@@ -280,6 +280,9 @@ export default function DiffPanel({
280 selectThreadBranchBaseRef(state, routeThreadRef),
281 );
282 const toolCallSelection = diffSelection.kind === "tool-call" ? diffSelection : null;
283 + // Turn and git diffs name files from the repository root; a tool call's diff names them as
284 + // its provider recorded them, absolute or relative to the workspace.
285 + const diffPathRepositoryRoot = toolCallSelection ? undefined : activeRepositoryRoot;
286 const isGitSelection =
287 diffSelection.kind === "branch" ||
288 diffSelection.kind === "unstaged" ||
@@ -743,7 +746,7 @@ export default function DiffPanel({
746 threadRef: routeThreadRef,
747 filePath,
748 activeCwd,
746 - repositoryRoot: activeRepositoryRoot,
749 + repositoryRoot: diffPathRepositoryRoot,
750 openInEditor: (targetPath) => {
751 void (async () => {
752 const result = await openInPreferredEditor(targetPath);
@@ -1410,7 +1413,7 @@ export default function DiffPanel({
1413 environmentId: activeThread?.environmentId ?? null,
1414 filePath,
1415 workspaceRoot: activeCwd,
1413 - repositoryRoot: activeRepositoryRoot,
1416 + repositoryRoot: diffPathRepositoryRoot,
1417 },
1418 event,
1419 );