From ad2bc462c9495f710a36074d210e667f1bfbd37c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 21:17:35 +0000 Subject: [PATCH 1/2] fix(web): PR description file links resolve in the PR's repository from a No-project thread A repo-relative path in a linked pull request's description gave up when another project held a different file at the same path, and opened a broken tab under the thread's scratch folder. An ambiguous cross-project match now retries among the projects whose repository is the PR's. Fixes #41065 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatMarkdown.tsx | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 2edc4be1febcd..c3610d326b8fd 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -175,6 +175,7 @@ import { workspaceLinkLookupQuery, } from "@t3tools/client-runtime/workspace-basename-lookup"; import { resolvePullRequestPreviewTarget } from "@t3tools/client-runtime/change-request-links"; +import { pullRequestLinkProject } from "@t3tools/client-runtime/pull-request-link-input"; import { mayContainStandaloneIssueLink, resolveIssueLinkTarget, @@ -868,6 +869,26 @@ function useChatMarkdownState( openPreview, }); }; + // A change request's description cites paths in its own repository, whichever project the + // thread is in, so that repository's checkouts settle a path other projects also contain. + const changeRequestRepositoryMatch = ( + relativePath: string, + own: Parameters[1][number], + projectSearches: Parameters[1], + ) => { + const repository = sourceControlMediaRepository?.toLowerCase(); + if (!repository) return null; + const repositoryRoots = new Set( + projects.flatMap((project) => + project.environmentId === environmentId && + pullRequestLinkProject(project.repositoryIdentity)?.repository.toLowerCase() === repository + ? [project.workspaceRoot] + : [], + ), + ); + const searches = projectSearches.filter((search) => repositoryRoots.has(search.root)); + return searches.length === 0 ? null : pickProjectLinkMatch(relativePath, [own, ...searches]); + }; const findWorkspaceFileMatch = async (fileLinkMeta: MarkdownFileLinkMeta) => { const workspaceRelativePath = fileLinkMeta.workspaceLookupPath; if ( @@ -926,7 +947,9 @@ function useChatMarkdownState( if (metadata._tag !== "Success" || metadata.value.entries[0] !== null) return null; } const projectSearches = await Promise.all(otherRoots.map(searchRoot)); - const projectMatch = pickProjectLinkMatch(workspaceRelativePath, [own, ...projectSearches]); + const projectMatch = + pickProjectLinkMatch(workspaceRelativePath, [own, ...projectSearches]) ?? + changeRequestRepositoryMatch(workspaceRelativePath, own, projectSearches); if (projectMatch !== null || agentRoots.length === 0) return projectMatch; // An unresolved project lookup falls back to the agent's working directories. const agentPaths = agentRoots.map((root) => From c3bf1c5ad1b92180b2807268f61d43ca74d1fb7b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 21:59:55 +0000 Subject: [PATCH 2/2] fix(web): PR description file links open in the PR's checkout A pull request body renders with the PR checkout as its cwd, but its file links handed the panel a path relative to that checkout, which the panel reads from the thread's own folder. From a No-project thread that opened a missing file in the scratch folder. Links rendered in another folder now open the absolute path under it. The earlier repository retry is removed: it never ran in that case. Fixes #41065 Co-Authored-By: Claude Opus 5.5 --- .../components/ChatMarkdown.browser.test.tsx | 33 ++++++++++++++ apps/web/src/components/ChatMarkdown.tsx | 43 ++++++++----------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.browser.test.tsx b/apps/web/src/components/ChatMarkdown.browser.test.tsx index faca71b4a101f..b0aa293812d6d 100644 --- a/apps/web/src/components/ChatMarkdown.browser.test.tsx +++ b/apps/web/src/components/ChatMarkdown.browser.test.tsx @@ -90,6 +90,17 @@ vi.mock(import("../state/filesystem"), async (original) => { : actual.useFilesystemReadAccess(environmentId)) as never, }; }); +const threadWorktrees = vi.hoisted(() => new Map()); +vi.mock(import("../state/entities"), async (original) => { + const actual = await original(); + return { + ...actual, + readThreadShell: ((ref: { threadId: string }) => { + const worktreePath = threadWorktrees.get(ref.threadId); + return worktreePath === undefined ? actual.readThreadShell(ref as never) : { worktreePath }; + }) as never, + }; +}); vi.mock(import("../remoteOpen"), async (original) => ({ ...(await original()), useRemoteOpenResolution: () => ({ state: { mode: "local-exec" }, isResolved: true }) as never, @@ -170,6 +181,7 @@ function setup() { parsedSources.length = 0; settingsOverrides.mathRenderingEnabled = false; renderDiagram.mockReset(); + threadWorktrees.clear(); workspaceSearch.mockReset().mockResolvedValue(AsyncResult.success({ entries: [] })); filesystemMetadata.mockReset().mockResolvedValue(AsyncResult.success({ entries: [null] })); } @@ -559,6 +571,27 @@ describe("ChatMarkdown workspace file opens", () => { expect(workspaceSearch).toHaveBeenCalledOnce(); }); + it("opens a path from markdown rendered in another checkout under that checkout", async () => { + setup(); + const scratchThread = { ...threadRef, threadId: ThreadId.make("scratch-thread") }; + threadWorktrees.set(scratchThread.threadId, "/scratch/thread"); + filesystemMetadata.mockResolvedValue(AsyncResult.success({ entries: [{ kind: "file" }] })); + using openFile = vi.spyOn(useRightPanelStore.getState(), "openFile"); + await using screen = await renderText("[State](packages/state/filesystem.ts)", { + cwd: "/repo-a", + threadRef: scratchThread, + }); + await act(async () => screen.container.querySelector("a")!.click()); + + await vi.waitFor(() => + expect(openFile).toHaveBeenCalledExactlyOnceWith( + scratchThread, + "/repo-a/packages/state/filesystem.ts", + undefined, + ), + ); + }); + it.each([ ["its own panel", "thread-own-panel", false], ["its parent's panel from a side chat", "thread-side-chat", true], diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index c3610d326b8fd..f5f69e063a967 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -175,7 +175,6 @@ import { workspaceLinkLookupQuery, } from "@t3tools/client-runtime/workspace-basename-lookup"; import { resolvePullRequestPreviewTarget } from "@t3tools/client-runtime/change-request-links"; -import { pullRequestLinkProject } from "@t3tools/client-runtime/pull-request-link-input"; import { mayContainStandaloneIssueLink, resolveIssueLinkTarget, @@ -869,26 +868,6 @@ function useChatMarkdownState( openPreview, }); }; - // A change request's description cites paths in its own repository, whichever project the - // thread is in, so that repository's checkouts settle a path other projects also contain. - const changeRequestRepositoryMatch = ( - relativePath: string, - own: Parameters[1][number], - projectSearches: Parameters[1], - ) => { - const repository = sourceControlMediaRepository?.toLowerCase(); - if (!repository) return null; - const repositoryRoots = new Set( - projects.flatMap((project) => - project.environmentId === environmentId && - pullRequestLinkProject(project.repositoryIdentity)?.repository.toLowerCase() === repository - ? [project.workspaceRoot] - : [], - ), - ); - const searches = projectSearches.filter((search) => repositoryRoots.has(search.root)); - return searches.length === 0 ? null : pickProjectLinkMatch(relativePath, [own, ...searches]); - }; const findWorkspaceFileMatch = async (fileLinkMeta: MarkdownFileLinkMeta) => { const workspaceRelativePath = fileLinkMeta.workspaceLookupPath; if ( @@ -947,9 +926,7 @@ function useChatMarkdownState( if (metadata._tag !== "Success" || metadata.value.entries[0] !== null) return null; } const projectSearches = await Promise.all(otherRoots.map(searchRoot)); - const projectMatch = - pickProjectLinkMatch(workspaceRelativePath, [own, ...projectSearches]) ?? - changeRequestRepositoryMatch(workspaceRelativePath, own, projectSearches); + const projectMatch = pickProjectLinkMatch(workspaceRelativePath, [own, ...projectSearches]); if (projectMatch !== null || agentRoots.length === 0) return projectMatch; // An unresolved project lookup falls back to the agent's working directories. const agentPaths = agentRoots.map((root) => @@ -965,8 +942,24 @@ function useChatMarkdownState( }; const openFileInPanel = (fileLinkMeta: MarkdownFileLinkMeta, panelPath: string) => { if (!threadRef) return; + // The panel reads relative paths from the thread's folder. A pull request body's `cwd` is the + // checkout of its repository, which can be another folder. + const shell = readThreadShell(threadRef); + const panelRoot = + shell?.worktreePath ?? + projects.find( + (project) => project.environmentId === environmentId && project.id === shell?.projectId, + )?.workspaceRoot; const openAt = (path: string) => - useRightPanelStore.getState().openFile(threadRef, path, fileLinkMeta.line); + useRightPanelStore + .getState() + .openFile( + threadRef, + cwd && panelRoot !== undefined && cwd !== panelRoot + ? resolveWorkspaceFilePath(path, cwd) + : path, + fileLinkMeta.line, + ); if ( fileLinkMeta.workspaceLookupPath === null || !cwd ||