From 88052613d53070b8a05823ed24fb5c8c1d9daec7 Mon Sep 17 00:00:00 2001 From: Renfei Zhou Date: Fri, 20 Nov 2026 00:42:09 +0000 Subject: [PATCH] feat(fork): turn the area right of the thread list into a work area of split panes Everything right of the thread list is one work area of nested panes, and the chat is one kind of tab in it. Dragging a tab onto an edge of a pane splits that pane; closing a pane's last tab closes the pane. Dragging a thread of the same project from the thread list into the area opens its chat as another Chat tab, whose file links open that thread's files. The last Chat tab cannot close. Each thread keeps its own layout in its right-panel record, and the right panel's show, hide and maximize controls are gone. A tab opened from a chat or a linked file shows a tab already open, or splits a lone pane to the right, or else lands in the nearest other pane, preferring one not showing a Chat, looking right, left, down, then up. A whiteboard chip in the composer and a board:// link in a chat show the region on the Whiteboard and never open a file. A pane holding a chat, reply or side-thread box is at least 360 px wide, and automatic opens never cover a reply or side-thread tab. The chat header loses its terminal button and the band above it, and its details toggle sits at the right end of the pane's tab bar. A lone pane has a Split right button that opens a New tab launcher beside it. A thread link of the same project opens that thread as a Chat tab by the same rule; a thread of another project or environment opens on its own page. Subagents and side chats use upstream's side-thread tabs. Each Replies sub-thread opens as its own tab with its own draft. A quote link shows its reply tab; a Find step keeps the Find field and never covers its chat. Both reuse the reply tab the last reveal opened until the user takes it over. Preview: Toggle, picture-in-picture and device Float hide a tab into the floating player and keep its session; a session update no longer brings a hidden browser back, and toggling again or Open in panel docks it. The Diff toggle, and the terminal toggle while the chat is hidden, hide and reopen their tab; the terminal toggle acts on the focused terminal and brings back the one it hid. A tab picked from a pane's + menu lands in that pane, and a browser opened from a link lands beside its source even when the session list adds it first. Reopen Closed View reopens a view whose tab is hidden. Agent-opened browsers float as upstream does. Upstream files carry only small hooks; the preview, device, settings and translation files are upstream's again. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- apps/web/src/browser/BrowserSurfaceSlot.tsx | 3 + apps/web/src/browser/openFileInPreview.ts | 17 +- apps/web/src/browser/useOpenLink.ts | 6 +- apps/web/src/components/ChatMarkdown.tsx | 54 +- .../src/components/ChatView.browser.test.tsx | 24 +- apps/web/src/components/ChatView.tsx | 202 +-- .../web/src/components/CommandPalette.drag.ts | 2 +- .../components/ComposerPromptEditorTiptap.tsx | 23 +- apps/web/src/components/RightPanelTabs.tsx | 120 +- apps/web/src/components/Sidebar.tsx | 2 +- apps/web/src/components/ThreadContextChip.tsx | 4 + apps/web/src/components/chat/ChatComposer.tsx | 5 +- .../chat/ChatHeader.browser.test.tsx | 2 - apps/web/src/components/chat/ChatHeader.tsx | 44 +- .../src/components/chat/ChatMarkdownMedia.tsx | 18 +- .../src/components/chat/ChatRightPanel.tsx | 56 - .../chat/CollapsedComposerPromptPreview.tsx | 12 +- .../components/chat/PanelLayoutControls.tsx | 91 +- .../src/components/chat/SideThreadPane.tsx | 22 +- .../src/components/chat/SkillInlineText.tsx | 11 +- .../components/chat/TimelineWorkGroupRows.tsx | 3 + .../chat/UserMessageContextChips.tsx | 11 +- .../src/components/chat/threadContextDrag.ts | 11 +- .../components/chat/threadFindHighlights.ts | 21 +- .../src/components/chat/useChatShortcuts.ts | 1 + .../components/chat/useChatTerminalActions.ts | 32 +- .../components/chat/useRightPanelActions.ts | 21 +- apps/web/src/components/chat/useSideChat.ts | 4 +- .../components/chat/useThreadLifecycle.tsx | 6 + .../desktop/DesktopWebLinkCoordinator.tsx | 16 +- .../src/components/files/FileBreadcrumbs.tsx | 6 +- .../src/components/files/FilePreviewPanel.tsx | 22 +- .../components/files/fileReadingPosition.ts | 7 +- .../components/preview/addBrowserSurface.ts | 4 +- .../settings/KeybindingsSettings.logic.ts | 4 + .../src/fork/dashboard/dashboardLink.test.ts | 56 + apps/web/src/fork/dashboard/dashboardLink.tsx | 18 +- .../src/fork/dashboard/dashboardSurface.ts | 10 +- apps/web/src/fork/forkCopy.ts | 26 + .../rightPanelMenu/RightPanelMenuSettings.tsx | 12 +- .../web/src/fork/rightPanelMenu/menu.logic.ts | 1 + .../rightPanelSplit/RightPanelDragScope.tsx | 196 --- .../RightPanelSplitView.browser.test.tsx | 332 ----- .../rightPanelSplit/RightPanelSplitView.tsx | 346 ----- .../rightPanelSplit/dropTarget.logic.test.ts | 225 --- .../fork/rightPanelSplit/dropTarget.logic.ts | 238 --- .../src/fork/rightPanelSplit/renderedSplit.ts | 30 - .../rightPanelSplit/splitLayout.logic.test.ts | 366 ----- .../fork/rightPanelSplit/splitLayout.logic.ts | 505 ------- .../fork/rightPanelSplit/splitStore.test.ts | 151 -- .../fork/subThreads/SubThreadReplyLine.tsx | 10 +- .../src/fork/subThreads/SubThreadsPanel.tsx | 238 ++- .../subThreads/subThreadCite.browser.test.tsx | 186 ++- .../src/fork/subThreads/subThreadCite.test.ts | 252 ++-- apps/web/src/fork/subThreads/subThreadCite.ts | 81 +- .../subThreads/subThreadFind.browser.test.tsx | 68 + .../web/src/fork/subThreads/subThreadReply.ts | 11 +- .../src/fork/subThreads/subThreadsState.ts | 48 +- .../src/fork/subThreads/useSubThreadReveal.ts | 54 +- .../src/fork/whiteboard/BoardMentionChip.tsx | 32 + .../WhiteboardPanel.browser.test.tsx | 236 ++- .../whiteboard/markdown-whiteboard.test.ts | 18 +- .../fork/whiteboard/markdown-whiteboard.ts | 13 + apps/web/src/fork/workArea/ChatOpenScope.tsx | 17 + apps/web/src/fork/workArea/LinkedFileBody.tsx | 95 ++ apps/web/src/fork/workArea/SecondaryChat.tsx | 90 ++ .../fork/workArea/WorkArea.browser.test.tsx | 741 ++++++++++ apps/web/src/fork/workArea/WorkArea.tsx | 940 ++++++++++++ .../changeRequestLink.browser.test.tsx | 155 ++ apps/web/src/fork/workArea/chatFileOpener.ts | 277 ++++ .../src/fork/workArea/chatOpenerContext.ts | 92 ++ .../src/fork/workArea/dropPlan.logic.test.ts | 154 ++ apps/web/src/fork/workArea/dropPlan.logic.ts | 165 +++ .../web/src/fork/workArea/miniPlayerFollow.ts | 72 + .../tabPress.browser.test.tsx | 0 .../tabStrip.tsx | 113 +- .../src/fork/workArea/threadDragFallback.ts | 51 + .../fork/workArea/threadLink.logic.test.ts | 85 ++ .../web/src/fork/workArea/threadLink.logic.ts | 54 + .../workArea/threadWorkspace.logic.test.ts | 36 + .../fork/workArea/threadWorkspace.logic.ts | 20 + .../src/fork/workArea/useTabPresentation.ts | 73 + apps/web/src/fork/workArea/useThreadGone.ts | 20 + apps/web/src/fork/workArea/workArea.css | 22 + .../src/fork/workArea/workArea.logic.test.ts | 1284 +++++++++++++++++ apps/web/src/fork/workArea/workArea.logic.ts | 522 +++++++ .../web/src/fork/workArea/workAreaCommands.ts | 171 +++ .../fork/workArea/workAreaGeometry.logic.ts | 437 ++++++ .../workArea/workAreaHidden.logic.test.ts | 307 ++++ .../src/fork/workArea/workAreaHidden.logic.ts | 88 ++ .../fork/workArea/workAreaPlacement.logic.ts | 1022 +++++++++++++ .../workArea/workAreaStorage.logic.test.ts | 344 +++++ .../fork/workArea/workAreaStorage.logic.ts | 290 ++++ .../fork/workArea/workAreaStore.logic.test.ts | 149 ++ .../fork/workArea/workAreaTabs.logic.test.ts | 455 ++++++ apps/web/src/fork/workArea/workAreaTestKit.ts | 68 + apps/web/src/fork/workArea/workAreaView.ts | 154 ++ .../src/hooks/useRightPanelSurfaceClose.ts | 15 +- .../useThreadActions.permissions.test.ts | 2 +- apps/web/src/lib/openPullRequestLink.ts | 18 +- apps/web/src/lib/sideChatPane.ts | 9 +- apps/web/src/lib/workspaceFocus.ts | 6 +- apps/web/src/reopenClosedView.ts | 5 +- apps/web/src/rightPanelStore.test.ts | 168 +-- apps/web/src/rightPanelStore.ts | 152 +- apps/web/test/fakeEnvironment.ts | 3 + 107 files changed, 10115 insertions(+), 3474 deletions(-) delete mode 100644 apps/web/src/components/chat/ChatRightPanel.tsx create mode 100644 apps/web/src/fork/dashboard/dashboardLink.test.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/RightPanelDragScope.tsx delete mode 100644 apps/web/src/fork/rightPanelSplit/RightPanelSplitView.browser.test.tsx delete mode 100644 apps/web/src/fork/rightPanelSplit/RightPanelSplitView.tsx delete mode 100644 apps/web/src/fork/rightPanelSplit/dropTarget.logic.test.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/dropTarget.logic.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/renderedSplit.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/splitLayout.logic.test.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/splitLayout.logic.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/splitStore.test.ts create mode 100644 apps/web/src/fork/subThreads/subThreadFind.browser.test.tsx create mode 100644 apps/web/src/fork/whiteboard/BoardMentionChip.tsx create mode 100644 apps/web/src/fork/workArea/ChatOpenScope.tsx create mode 100644 apps/web/src/fork/workArea/LinkedFileBody.tsx create mode 100644 apps/web/src/fork/workArea/SecondaryChat.tsx create mode 100644 apps/web/src/fork/workArea/WorkArea.browser.test.tsx create mode 100644 apps/web/src/fork/workArea/WorkArea.tsx create mode 100644 apps/web/src/fork/workArea/changeRequestLink.browser.test.tsx create mode 100644 apps/web/src/fork/workArea/chatFileOpener.ts create mode 100644 apps/web/src/fork/workArea/chatOpenerContext.ts create mode 100644 apps/web/src/fork/workArea/dropPlan.logic.test.ts create mode 100644 apps/web/src/fork/workArea/dropPlan.logic.ts create mode 100644 apps/web/src/fork/workArea/miniPlayerFollow.ts rename apps/web/src/fork/{rightPanelSplit => workArea}/tabPress.browser.test.tsx (100%) rename apps/web/src/fork/{rightPanelSplit => workArea}/tabStrip.tsx (57%) create mode 100644 apps/web/src/fork/workArea/threadDragFallback.ts create mode 100644 apps/web/src/fork/workArea/threadLink.logic.test.ts create mode 100644 apps/web/src/fork/workArea/threadLink.logic.ts create mode 100644 apps/web/src/fork/workArea/threadWorkspace.logic.test.ts create mode 100644 apps/web/src/fork/workArea/threadWorkspace.logic.ts create mode 100644 apps/web/src/fork/workArea/useTabPresentation.ts create mode 100644 apps/web/src/fork/workArea/useThreadGone.ts create mode 100644 apps/web/src/fork/workArea/workArea.css create mode 100644 apps/web/src/fork/workArea/workArea.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workArea.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaCommands.ts create mode 100644 apps/web/src/fork/workArea/workAreaGeometry.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaHidden.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workAreaHidden.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaPlacement.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaStorage.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workAreaStorage.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaStore.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workAreaTabs.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workAreaTestKit.ts create mode 100644 apps/web/src/fork/workArea/workAreaView.ts diff --git a/README.md b/README.md index d30eeeb0e6f8d..5812916897edd 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This is a fork of T3 Code that integrates a few additional features, including: - While the agent works, Chat mode shows "Working for" and the time just above the message box, in the sub-thread where you last wrote to it in that run, or else in the main list. - "Enable Dashboard", beside Display mode in the same menu, gives the thread a Dashboard in either mode: a Dashboard tab in the right panel (+ → Dashboard) with six status slots that the agent writes with its `dashboard_set` tool and reads with `dashboard_get`. Each slot shows how long ago it changed, and new text stays highlighted until you click the slot. Select text in a slot to quote it with Cite, as you would in a message. Agents can link to the Dashboard in their messages, and a click on the link opens it. - Settings → Threads → New threads → Display mode picks the mode for threads you start from the message box in the web or desktop app. Threads that agents, scheduled tasks, side chats or the mobile app start open in Normal mode, and existing threads keep their mode. -- **Split the right panel in two:** drag a right-panel tab onto the left or right part of the panel's content and drop it to get two panes side by side, each with its own tabs, as with Windows Snap. Drag tabs between the panes, drag the line between them to resize (double-click resets it), and close or move away a pane's last tab to go back to one pane. The tab menu has Split right, Split left, Move to the other pane and Unsplit. New tabs open in the pane you last used. A narrow window shows all tabs in one strip and keeps the split for when there is room. A press anywhere on a tab now switches to it at once. +- **The work area:** everything right of the thread list is one area of panes, starting as one pane with a Chat tab for the selected thread. Drag a tab onto a pane's tab strip to move it there, onto an edge of a pane's content to split that side, or onto the middle to join that pane. The tab menu also has Split right and Split down, and when there is one pane, a Split right button at the right end of the tab bar splits it and opens a New tab page. Panes split again in either direction. Drag the divider between two panes, or use the arrow keys on it, to resize (double-click resets it); closing a pane's last tab closes the pane. Any pane that holds a message box (a Chat, a reply tab, or a side-thread tab) stays at least 360 px wide. Drag a thread of the same project from the thread list into the area to open its chat as another Chat tab, and clicking a file link in that chat opens that thread's file as a tab beside it; a thread of another project cannot be dropped into the area, though dropping it on a message box still adds it as context. A thread link, chip, or header breadcrumb in a chat opens a same-project thread as a Chat tab beside the chat, while a thread of another project or environment opens on its own page. Subagents and side chats open as side-thread tabs beside the chat, as in upstream T3 Code; a Cmd or Ctrl click, a middle click, or "Open in main view" opens them on their own page. Reply or "N replies" on a message, or a sub-thread in the Replies list, opens that sub-thread as its own tab (next to the list when opened from the Replies list). "Preview: Toggle", picture-in-picture, and a device's Float hide the tab into the floating player and keep the session; toggling again or choosing "Open in panel" brings the tab back. The Diff toggle hides and reopens the Diff tab. Each thread keeps its own layout. The last Chat tab cannot close, and closing the selected thread's Chat hides it until + → Chat brings it back. Files, links, and diffs that open by themselves go beside the chat, never over it. A window 980 px wide or less shows every tab in one strip and keeps the panes for when there is room. The right panel's show, hide, and maximize controls are gone. A press anywhere on a tab switches to it at once. - Copy buttons on pages in the preview browser now put the copied text into your own clipboard. - **Two preview browser modes:** Settings → Browser → Preview browser picks the browser the server runs for preview tabs. **T3 native** (fast) is the default. It runs chrome-headless-shell, Chrome's small build that runs without a window. **Chrome** (slow) runs full Chrome, for pages that don't work in T3 native. On platforms where T3 has no Chrome for Testing build (Google's Chrome build for test automation), both choices run T3 native. Switching closes the open preview tabs. - **Compact when idle for Claude threads:** a choice in Settings → Providers → Advanced → Compact idle threads. Besides compacting before the prompt cache expires, it compacts a large idle Claude thread (default 400K tokens or more) a set time (default 15 minutes) after the last message or answer from a user or a bot, so the compaction runs while no one waits for a reply. The token counts and the wait are set right under the choice. diff --git a/apps/web/src/browser/BrowserSurfaceSlot.tsx b/apps/web/src/browser/BrowserSurfaceSlot.tsx index e00b002ca0036..4639727e5990e 100644 --- a/apps/web/src/browser/BrowserSurfaceSlot.tsx +++ b/apps/web/src/browser/BrowserSurfaceSlot.tsx @@ -2,6 +2,7 @@ import { useLayoutEffect, useRef } from "react"; import { acquireBrowserSurface } from "./browserSurfaceStore"; import { observeResize } from "../lib/observeResize"; +import { WORK_AREA_LAYOUT_EVENT } from "../fork/workArea/workAreaView"; export function BrowserSurfaceSlot(props: { readonly tabId: string; @@ -68,10 +69,12 @@ export function BrowserSurfaceSlot(props: { const stopObserving = observeResize(observed, update); window.addEventListener("resize", update); window.addEventListener("scroll", update, true); + window.addEventListener(WORK_AREA_LAYOUT_EVENT, update); return () => { stopObserving(); window.removeEventListener("resize", update); window.removeEventListener("scroll", update, true); + window.removeEventListener(WORK_AREA_LAYOUT_EVENT, update); if (updateRef.current === update) updateRef.current = null; lease.release(); }; diff --git a/apps/web/src/browser/openFileInPreview.ts b/apps/web/src/browser/openFileInPreview.ts index e93edfeac91c5..6f7fe773d505b 100644 --- a/apps/web/src/browser/openFileInPreview.ts +++ b/apps/web/src/browser/openFileInPreview.ts @@ -16,6 +16,7 @@ import * as Schema from "effect/Schema"; import { AsyncResult } from "effect/reactivity"; import { resolveAssetUrl } from "~/assets/assetUrls"; +import { captureOpenOrigin } from "~/fork/workArea/workAreaView"; import { isPreviewAvailableFor, previewRuntimeFor } from "~/browser/previewRuntime"; import { applyPreviewServerSnapshot, @@ -67,6 +68,7 @@ export async function openUrlInPreview(input: { }): Promise> { // Read before any await: a side chat pane that unmounts meanwhile drops its host mapping. const threadRef = rightPanelHostRef(input.threadRef); + const fromOrigin = captureOpenOrigin(); const defaults = await resolveBrowserDefaults().catch( (cause: unknown) => new BrowserSettingsReadError({ cause }), ); @@ -107,7 +109,7 @@ export async function openUrlInPreview(input: { return; } applyPreviewServerSnapshot(threadRef, snapshot); - useRightPanelStore.getState().openBrowser(threadRef, snapshot.tabId); + fromOrigin(() => useRightPanelStore.getState().openBrowser(threadRef, snapshot.tabId)); }); } @@ -137,6 +139,7 @@ export async function openFileInPreview(input: { ); } const hostRef = rightPanelHostRef(input.threadRef); + const fromOrigin = captureOpenOrigin(); const insideWorkspace = mediaFileReference(input.filePath, input.workspaceRoot).relativePath !== undefined; const assetResult = await input.createAssetUrl({ @@ -158,9 +161,11 @@ export async function openFileInPreview(input: { Cause.die(new Error("The environment returned an invalid asset URL.")), ); } - return openUrlInPreview({ - threadRef: hostRef, - url: assetUrl, - openPreview: input.openPreview, - }); + return fromOrigin(() => + openUrlInPreview({ + threadRef: hostRef, + url: assetUrl, + openPreview: input.openPreview, + }), + ); } diff --git a/apps/web/src/browser/useOpenLink.ts b/apps/web/src/browser/useOpenLink.ts index 9405435e7ebcb..732473a31441b 100644 --- a/apps/web/src/browser/useOpenLink.ts +++ b/apps/web/src/browser/useOpenLink.ts @@ -4,6 +4,7 @@ import { squashAtomCommandFailure, } from "@t3tools/client-runtime/state/runtime"; import { recordVisitForThread } from "~/browserHistoryStore"; +import { captureOpenOrigin } from "~/fork/workArea/workAreaView"; import { readLocalApi } from "~/localApi"; import { previewEnvironment } from "~/state/preview"; import { useAtomCommand } from "~/state/use-atom-command"; @@ -34,6 +35,7 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): ( const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false }); return async (url, options = {}) => { const targetThreadRef = options.threadRef ?? threadRef; + const fromOrigin = captureOpenOrigin(); const target = resolveLinkTarget({ url, event: options.event ?? NO_MODIFIER, @@ -41,7 +43,9 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): ( canOpenInApp: canOpenLinksInApp(targetThreadRef), }); if (target === "app" && targetThreadRef) { - const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview }); + const result = await fromOrigin(() => + openUrlInPreview({ threadRef: targetThreadRef, url, openPreview }), + ); if (isAtomCommandInterrupted(result)) return; if (result._tag === "Success") { recordVisitForThread(targetThreadRef, url); diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index c4074b1ac357e..fcc7e2b1e9ba9 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -177,7 +177,8 @@ import { appAtomRegistry } from "../rpc/atomRegistry"; import { hostEnvironmentIdAtom } from "../state/primaryEnvironment"; import { cn } from "../lib/utils"; import { resolveRemoteOpenState, useRemoteOpenResolution } from "../remoteOpen"; -import { rightPanelHostRef, useRightPanelStore } from "../rightPanelStore"; +import { useRightPanelStore } from "../rightPanelStore"; +import { fromChatOrigin, inChatOrigin, useChatFileOpener } from "../fork/workArea/chatFileOpener"; import { useOpenIssueLink } from "../lib/openIssueLink"; import { issueTrackerEnvironment } from "../state/issueTrackers"; import { useEnvironmentQuery } from "../state/query"; @@ -619,6 +620,7 @@ function useChatMarkdownState({ reportFailure: false, }); const pullRequestLinking = usePullRequestLinking(threadRef?.environmentId); + const fileOpener = useChatFileOpener(threadRef); const environmentId = threadRef?.environmentId ?? explicitEnvironmentId ?? null; const canOperateHost = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope); const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope); @@ -633,6 +635,7 @@ function useChatMarkdownState({ clickedImage?: HTMLImageElement | null, ) => { const requestId = ++mediaRequestId.current; + const fileTarget = fileOpener?.(); void resolveMarkdownMediaPreview({ source, resolvedFilePath, @@ -643,9 +646,7 @@ function useChatMarkdownState({ httpBaseUrl: environmentId === null ? undefined : readPreparedConnection(environmentId)?.httpBaseUrl, createAssetUrl, - onOpenFile: threadRef - ? (path) => useRightPanelStore.getState().openFile(threadRef, path) - : undefined, + onOpenFile: fileTarget ? (path) => fileTarget.openFile(path) : undefined, }).then( (preview) => { if (preview && mediaRequestId.current === requestId) { @@ -806,7 +807,10 @@ function useChatMarkdownState({ ), ); } - return openUrlInPreview({ threadRef, url, openPreview }).then((result) => { + const opened = fromChatOrigin(fileOpener, () => + openUrlInPreview({ threadRef, url, openPreview }), + ); + return opened.then((result) => { if (result._tag === "Success") recordVisitForThread(threadRef, url); else if (!isAtomCommandInterrupted(result)) { const error = squashAtomCommandFailure(result); @@ -823,7 +827,7 @@ function useChatMarkdownState({ return result; }); }; - const openMarkdownFileInPreview = (path: string) => { + const openMarkdownFileInPreview = inChatOrigin(fileOpener, (path: string) => { const preparedConnection = threadRef ? readPreparedConnection(threadRef.environmentId) : null; if (!threadRef || !canOperatePreview || preparedConnection === null) { return Promise.resolve( @@ -844,7 +848,7 @@ function useChatMarkdownState({ createAssetUrl, openPreview, }); - }; + }); const findWorkspaceFileMatch = async (fileLinkMeta: MarkdownFileLinkMeta) => { const workspaceRelativePath = fileLinkMeta.workspaceLookupPath; if ( @@ -919,9 +923,9 @@ function useChatMarkdownState({ return findAgentDirectoryMatch(workspaceRelativePath, agentRoots, searchRoot); }; const openFileInPanel = (fileLinkMeta: MarkdownFileLinkMeta, panelPath: string) => { - if (!threadRef) return; - const openAt = (path: string) => - useRightPanelStore.getState().openFile(threadRef, path, fileLinkMeta.line); + const fileTarget = fileOpener?.(); + if (!threadRef || !fileTarget) return; + const openAt = (path: string) => fileTarget.openFile(path, fileLinkMeta.line); if ( fileLinkMeta.workspaceLookupPath === null || !cwd || @@ -931,13 +935,13 @@ function useChatMarkdownState({ return; } // Anything the user opens in this panel meanwhile, such as a file from the picker, wins. - const panelRef = rightPanelHostRef(threadRef); + const panelRef = fileTarget.panel(); const panelKey = scopedThreadKey(panelRef); const userActionRevision = useRightPanelStore.getState().markUserAction(panelRef); void (async () => { const match = await findWorkspaceFileMatch(fileLinkMeta); if ( - scopedThreadKey(rightPanelHostRef(threadRef)) !== panelKey || + scopedThreadKey(fileTarget.panel()) !== panelKey || useRightPanelStore.getState().getUserActionRevision(panelRef) !== userActionRevision ) return; @@ -1083,6 +1087,7 @@ function useChatMarkdownState({ issuesEnabled, skills, threadRef, + fileOpener, updateThreadPullRequestLink, }; return { @@ -1240,6 +1245,7 @@ const CHAT_MARKDOWN_COMPONENTS = { imageBaseDir, markdownFileLinkMetaByHref, threadRef, + fileOpener, openMarkdownMedia, openChangeRequestLink, openIssueLink, @@ -1363,7 +1369,8 @@ const CHAT_MARKDOWN_COMPONENTS = { onClick?.(event); if (isWhiteboardLink && href) { event.preventDefault(); - showBoardRef(href, threadRef); + if (fileOpener) fileOpener().openBoardRef(href); + else showBoardRef(href, threadRef); return; } if (isSameDocumentLink && href) { @@ -1394,8 +1401,12 @@ const CHAT_MARKDOWN_COMPONENTS = { } if ( !href || - openChangeRequestLink(event, href, undefined, environmentId ?? undefined) || - openIssueLink(event, href, environmentId ?? undefined, issueTrackers) + fromChatOrigin( + fileOpener, + () => + openChangeRequestLink(event, href, undefined, environmentId ?? undefined) || + openIssueLink(event, href, environmentId ?? undefined, issueTrackers), + ) ) { return; } @@ -1512,7 +1523,7 @@ const CHAT_MARKDOWN_COMPONENTS = { originalUrl={href} target={pullRequestPreviewTarget} confirmBeforeOpen={confirmBeforeOpen} - onOpenPullRequest={(targetUrl) => + onOpenPullRequest={inChatOrigin(fileOpener, (targetUrl: string) => openChangeRequestLink( { metaKey: false, @@ -1523,10 +1534,10 @@ const CHAT_MARKDOWN_COMPONENTS = { targetUrl, undefined, environmentId ?? undefined, - ) - } + ), + )} // A reference that is not a pull request may still be an issue this app can show. - onOpenFallback={async (url) => { + onOpenFallback={inChatOrigin(fileOpener, async (url: string) => { const opened = openIssueLink( { metaKey: false, @@ -1539,7 +1550,7 @@ const CHAT_MARKDOWN_COMPONENTS = { issueTrackers, ); if (!opened) await openDeferredMarkdownLink(url); - }} + })} fallback={ issuePreviewTarget === null ? undefined : ( @@ -1628,6 +1639,7 @@ const CHAT_MARKDOWN_COMPONENTS = { sourceControlMediaRepository, imageBaseDir, threadRef, + fileOpener, workspaceMutationId, renderContextReference, fileLinkChip, @@ -1676,7 +1688,7 @@ const CHAT_MARKDOWN_COMPONENTS = { threadId: threadRef.threadId, path: filePath, }, - onOpen: () => useRightPanelStore.getState().openFile(threadRef, filePath), + onOpen: () => fileOpener?.().openFile(filePath), } : imageSource._tag === "Direct" ? { src: resolveProtocolRelativeMediaUrl(imageSource.uri) } diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index ae6628ba6733c..f6b2c3cac49cb 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -117,11 +117,16 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({ trackRpcRequestSent: () => {}, })); -it("opens a linked Linear issue from an inactive thread's sidebar badge", async () => { +/** The app's stylesheet; the work area places tabs by its laid-out size. */ +function appStylesheet(): Disposable { const style = document.createElement("style"); style.textContent = stylesheet; document.head.append(style); - using _style = { [Symbol.dispose]: () => style.remove() }; + return { [Symbol.dispose]: () => style.remove() }; +} + +it("opens a linked Linear issue from an inactive thread's sidebar badge", async () => { + using _style = appStylesheet(); const first = threadWithHistory("issue-first", 1); const linked = threadWithHistory("issue-linked", 1); const issueRef = { @@ -240,7 +245,9 @@ it("opens a linked Linear issue from an inactive thread's sidebar badge", async await userEvent.click(issueRow); expect(router.history.location.pathname).toBe(`/${ENVIRONMENT_ID}/${linked.id}`); await expect.element(page.getByRole("heading", { name: liveTitle })).toBeVisible(); - await act(() => useRightPanelStore.getState().close(scopeThreadRef(ENVIRONMENT_ID, linked.id))); + await act(() => + useRightPanelStore.getState().closeAllSurfaces(scopeThreadRef(ENVIRONMENT_ID, linked.id)), + ); await expect .element( page.getByRole("region", { name: "Thread details" }).getByRole("link", { @@ -724,6 +731,7 @@ it("a mounted thread view lets go of the thread structures it has replaced", asy }); it("a shortcut conditioned on rightPanelOpen sees the thread's open right panel", async () => { + using _style = appStylesheet(); await page.viewport(1280, 800); const thread = threadWithHistory("thread-panel-shortcut", 1); using _environment = installFakeEnvironment([thread], { @@ -747,14 +755,13 @@ it("a shortcut conditioned on rightPanelOpen sees the thread's open right panel" router: false, }); const composer = page.getByTestId("composer-editor"); - const toggle = page.getByRole("button", { name: "Toggle right panel", exact: true }); - await expect.element(toggle).toHaveAttribute("aria-pressed", "false"); - await toggle.click(); - await page.getByRole("button", { name: /^Files/ }).click(); + await act(() => + useRightPanelStore.getState().open(scopeThreadRef(ENVIRONMENT_ID, thread.id), "files"), + ); + await expect.element(page.getByRole("button", { name: "Close Files" })).toBeVisible(); await composer.click(); await userEvent.keyboard("{Control>}t{/Control}"); await expect.element(page.getByRole("menuitem", { name: /Files/ })).toBeVisible(); - await expect.element(toggle).toHaveAttribute("aria-pressed", "true"); }); it("selecting a side-chat tab focuses that side chat's composer", async () => { @@ -842,6 +849,7 @@ it("a subagent tab shows its read-only bar under no header of its own", async () }); it("/side sends the draft's attachments and context, and keeps them when it does not start", async () => { + using _style = appStylesheet(); await page.viewport(1400, 900); const thread = threadWithHistory("side-attachments", 1); let holdFork = false; diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 3a6a895c1ba0a..3f625f2cb5aac 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -231,7 +231,7 @@ import { useEnvironmentSettings, } from "../hooks/useSettings"; import { useNowMinute } from "../hooks/useNowMinute"; -import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations"; +import { usePanelAnimationSettings } from "../panelAnimations"; import { useNewThreadHandler } from "../hooks/useHandleNewThread"; import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl"; import { isPreviewFocused } from "../lib/previewFocus"; @@ -313,13 +313,7 @@ import { useOpenSurfaceInMainView } from "../hooks/useOpenSurfaceInMainView"; import { useRemoteOpenState } from "~/remoteOpen"; import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic"; import { useOpenFavoriteEditorShortcut } from "./chat/OpenInPickerShortcut"; -import { - PanelLayoutControls, - type PanelLayoutControlsProps, - RightPanelMaximizeControl, - ThreadPanelHeaderControl, - WorkspaceTitlebarControls, -} from "./chat/PanelLayoutControls"; +import { PanelLayoutControls, type PanelLayoutControlsProps } from "./chat/PanelLayoutControls"; import type { ExpandedImagePreview } from "./chat/ExpandedImagePreview"; import { ThreadDetailsPanel } from "./chat/ThreadDetailsPanel"; import { NoActiveThreadState } from "./NoActiveThreadState"; @@ -387,9 +381,12 @@ import { useAtomQueryRunner } from "../state/use-atom-query-runner"; import { observeResize } from "~/lib/observeResize"; import { ThreadVisitWatermark } from "./chat/ThreadVisitWatermark"; import { ChatTerminalDrawers } from "./chat/ChatTerminalDrawers"; -import { ChatRightPanel } from "./chat/ChatRightPanel"; -import { useSplitRendered } from "../fork/rightPanelSplit/renderedSplit"; -import { unfocusedPaneSurface } from "../fork/rightPanelSplit/splitLayout.logic"; +import { WorkArea } from "../fork/workArea/WorkArea"; +import { useWorkAreaChat } from "../fork/workArea/workAreaView"; +import { closeFocusedTab, showPrimaryChat } from "../fork/workArea/workAreaCommands"; +import { useChatViewOpener } from "../fork/workArea/chatFileOpener"; +import { ChatOpenScope } from "../fork/workArea/ChatOpenScope"; +import { openThreadTab } from "../fork/workArea/chatOpenerContext"; import { useModeSurfaceActions } from "../fork/dashboard/dashboardSurface"; import { REPLY_BOX_QUEUE_EDIT_BLOCKED, subThreadDraftId } from "../fork/subThreads/subThreadReply"; import { useSubThreadCite } from "../fork/subThreads/subThreadCite"; @@ -469,7 +466,6 @@ export default function ChatView(props: ChatViewProps) { threadId, routeKind, onDiffPanelOpen, - reserveTitleBarControlInset = true, forceExpandedMobileComposer = false, embedded: parentPanel, } = props; @@ -931,6 +927,8 @@ export default function ChatView(props: ChatViewProps) { ? scopeThreadRef(activeThread.environmentId, activeThread.lineage.parentThreadId) : null; const sideChatParent = useQuietThreadShell(sideChatParentRef); + const activeThreadRef = useActiveThreadRef(activeThread); + const { origin: openOrigin, opener: fileOpener } = useChatViewOpener(activeThreadRef, embedded); const parentThreadLink = (() => { if (sideChatParentRef !== null) { const title = sideChatParent?.title ?? gt("Parent thread"); @@ -940,6 +938,7 @@ export default function ChatView(props: ChatViewProps) { title, sideChat: true, open: (): void => { + if (openThreadTab(fileOpener, sideChatParentRef)) return; void navigate({ to: "/$environmentId/$threadId", params: buildThreadRouteParams(sideChatParentRef), @@ -951,7 +950,7 @@ export default function ChatView(props: ChatViewProps) { const title = parentSubagentThread?.title ?? gt("Parent thread"); // Embedded in its parent's panel, the parent is the view around it. if ( - parentPanel !== undefined && + parentPanel?.hostRef !== undefined && scopedThreadKey(parentPanel.hostRef) === scopedThreadKey(parentSubagentThreadRef) ) { return { title }; @@ -959,11 +958,11 @@ export default function ChatView(props: ChatViewProps) { return { title, open: (): void => { + const route = resolveThreadOpenRoute(parentSubagentThreadRef, parentSubagentThread); + if (route === parentSubagentThreadRef && openThreadTab(fileOpener, route)) return; void navigate({ to: "/$environmentId/$threadId", - params: buildThreadRouteParams( - resolveThreadOpenRoute(parentSubagentThreadRef, parentSubagentThread), - ), + params: buildThreadRouteParams(route), }); }, }; @@ -978,6 +977,7 @@ export default function ChatView(props: ChatViewProps) { ? {} : { open: (): void => { + if (openThreadTab(fileOpener, parentRef)) return; void navigate({ to: "/$environmentId/$threadId", params: buildThreadRouteParams(parentRef), @@ -1060,7 +1060,6 @@ export default function ChatView(props: ChatViewProps) { } return labels; })(); - const activeThreadRef = useActiveThreadRef(activeThread); const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null; const activeEnvironmentServerBrowser = useEnvironmentSupportsServerBrowser( activeThreadRef?.environmentId ?? null, @@ -1138,39 +1137,16 @@ export default function ChatView(props: ChatViewProps) { const rightPanelOpen = rightPanelState.isOpen; const { active: panelAnimationsActive, durationMs: panelAnimationDurationMs } = usePanelAnimationSettings(); - const rightPanelPresenceValue = { - activeSurface: activeRightPanelSurface, - surfaces: rightPanelState.surfaces, - split: rightPanelState.split, - }; - const rightPanelPresence = usePanelPresence( - rightPanelOpen && activeThreadRef !== null, - rightPanelPresenceValue, - panelAnimationsActive, - activeThreadKey, - panelAnimationDurationMs, - ); - const rightPanelPresent = rightPanelPresence.present; - const rightPanelControlsInPanel = - shouldUsePlanSidebarSheet && rightPanelPresent && rightPanelOpen; - const rightPanelControlsAtRoot = rightPanelPresent && !shouldUsePlanSidebarSheet; - const renderedRightPanelSurface = rightPanelPresence.value?.activeSurface ?? null; - const renderedRightPanelSurfaces = rightPanelPresence.value?.surfaces ?? []; - const rightPanelSplitRendered = useSplitRendered(activeThreadKey); + const workAreaChat = useWorkAreaChat(rightPanelState, embedded); const previewMiniPlayerVisible = - shouldRenderPreviewMiniPlayer( - activePreviewMiniPlayer?.source ?? null, - renderedRightPanelSurface, - ) && - shouldRenderPreviewMiniPlayer( - activePreviewMiniPlayer?.source ?? null, - rightPanelSplitRendered ? unfocusedPaneSurface(rightPanelState) : null, + shouldRenderPreviewMiniPlayer(activePreviewMiniPlayer?.source ?? null, null) && + workAreaChat.shown.every((surface) => + shouldRenderPreviewMiniPlayer(activePreviewMiniPlayer?.source ?? null, surface), ); const canMaximizeRightPanel = rightPanelOpen; // An embedded side chat has no panel; a stale maximized flag would hide its own column. const rightPanelMaximized = !embedded && canMaximizeRightPanel && rightPanelState.maximized === true; - const inlineRightPanelOwnsTitleBar = rightPanelOpen && !shouldUsePlanSidebarSheet; const [threadPanelPopoverHandle] = useState(PopoverCreateHandle); const [chatCanvasStore] = useState(createChatCanvasStore); @@ -1194,11 +1170,10 @@ export default function ChatView(props: ChatViewProps) { !isServerThread && draftFallback ? draftFallback.selection : activeProjectSettings.settings.defaultModelSelection; - useWhiteboardProject(activeProject?.workspaceRoot, activeThreadKey); + useWhiteboardProject(embedded ? undefined : activeProject?.workspaceRoot, activeThreadKey); const handleNewThreadInActiveProject = () => { startNewThreadForProject(activeProjectRef, handleNewThread); }; - const handleNewThreadInActiveProjectStable = useStableCallback(handleNewThreadInActiveProject); const projectGroupingSettings = selectProjectGroupingSettings(settings); const activeDraftLogicalProjectKey = !isServerThread && activeProject @@ -1600,7 +1575,7 @@ export default function ChatView(props: ChatViewProps) { const downloadFileAttachmentStable = useStableCallback(downloadFileAttachment); const openFileAttachment = (attachment: ChatFileAttachment) => { if (activeThreadRef) { - useRightPanelStore.getState().openAttachment(activeThreadRef, attachment); + fileOpener?.().openAttachment(attachment); return; } }; @@ -2003,6 +1978,7 @@ export default function ChatView(props: ChatViewProps) { panelTerminalIds, canReuseTerminal, gitCwd, + primaryChatShown: !workAreaChat.column.away, setTerminalUiLaunchContext, setThreadError, }); @@ -2109,13 +2085,6 @@ export default function ChatView(props: ChatViewProps) { visiblePullRequestCount, onDiffPanelOpen, }); - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- consumes a pending maximize request from the right panel store once the panel can maximize - useEffect(() => { - if (!canMaximizeRightPanel) return; - if (useRightPanelStore.getState().consumeMaximizeRequest(routeThreadRef)) { - useRightPanelStore.getState().setMaximized(routeThreadRef, true); - } - }, [canMaximizeRightPanel, routeThreadRef]); const { closeSurface: closeRightPanelSurface, closeOtherSurfaces: closeOtherRightPanelSurfacesStable, @@ -2456,17 +2425,14 @@ export default function ChatView(props: ChatViewProps) { addFilesSurfaceStable, addPullRequestSurfaceStable, addPullRequestsSurfaceStable, - closePreviewPanelStable, copyRightPanelFilePathStable, createBrowserSurface, createBrowserSurfaceStable, duplicateBrowserSurfaceStable, - moveRightPanelSurfaceStable, onOpenToolDiffStable, onOpenTurnDiffStable, openChangesFromThreadPanelStable, openFileSurfaceStable, - toggleRightPanelMaximizedStable, toggleRightPanelStable, toggleThreadPanelStable, shortcuts: rightPanelShortcuts, @@ -2515,6 +2481,7 @@ export default function ChatView(props: ChatViewProps) { shortcuts: threadLifecycleShortcuts, } = useThreadLifecycle({ environmentId, + openThreadTabs: fileOpener, routeThreadKey, currentRouteThreadKeyRef, canOperateThread, @@ -2884,26 +2851,18 @@ export default function ChatView(props: ChatViewProps) { }, }); - const closeActiveRightPanelSurfaceStable = useStableCallback(() => { - if (activeRightPanelSurface) closeRightPanelSurface(activeRightPanelSurface); + const closeFocusedTabStable = useStableCallback(() => { + if (activeThreadRef) closeFocusedTab(activeThreadRef, closeRightPanelSurface); }); - // A focused desktop browser page forwards these chords as menu actions. - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to desktop bridge menu actions that toggle or close the right panel + // A focused desktop browser page forwards this chord as a menu action. + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the desktop bridge menu action that closes the focused tab useEffect(() => { if (embedded || backgroundThread) return; return window.desktopBridge?.onMenuAction((action) => { - if (action === "rightPanel.toggle") toggleRightPanelStable(); - else if (action === "rightPanel.toggleMaximized") toggleRightPanelMaximizedStable(); - else if (action === "rightPanel.close") closeActiveRightPanelSurfaceStable(); + if (action === "rightPanel.close") closeFocusedTabStable(); }); - }, [ - embedded, - backgroundThread, - toggleRightPanelStable, - toggleRightPanelMaximizedStable, - closeActiveRightPanelSurfaceStable, - ]); + }, [embedded, backgroundThread, closeFocusedTabStable]); usePasteToFocusComposer(embedded ? null : activeThreadId, composerRef); // A delegated task is a remote thread's subagent. @@ -2930,9 +2889,9 @@ export default function ChatView(props: ChatViewProps) { // An embedded thread's commands run in its host's terminal, which is the host's checkout. const runsOutsideHostCheckout = embedded && (activeThread?.worktreePath ?? null) !== (panelHostShell?.worktreePath ?? null); - // A maximized panel covers the terminal drawer the command runs in. + // A hidden primary chat column hides the terminal drawer the command runs in. const runSideChatShellCommandStable = useStableCallback((command: string) => { - if (activeThreadRef) useRightPanelStore.getState().setMaximized(activeThreadRef, false); + if (activeThreadRef && workAreaChat.column.away) showPrimaryChat(activeThreadRef); runShellCommandStable(command); }); // Main-thread surfaces show this reason; `/side` sent anyway gets it as a toast. @@ -3416,24 +3375,6 @@ export default function ChatView(props: ChatViewProps) { onToggleThreadPanel: toggleThreadPanelStable, onToggleRightPanel: toggleRightPanelStable, } satisfies PanelLayoutControlsProps; - const panelToggleControls = ( - - ); - const threadPanelHeaderControl = ; - const panelLayoutControls = ( - - {panelToggleControls} - - ); const workspaceFileDropHandlers = makeWorkspaceFileDropHandlers({ setDragActive: setIsWorkspaceFileDragActive, addFiles: addDroppedFilesToComposer, @@ -3452,15 +3393,15 @@ export default function ChatView(props: ChatViewProps) { state={deviceState} /> )} - {rightPanelControlsAtRoot && !embedded ? panelLayoutControls : null}
{embedded ? null : ( @@ -3470,24 +3411,11 @@ export default function ChatView(props: ChatViewProps) { className={cn( "relative bg-background [[data-panel-animations=true]_&]:motion-safe:transition-[padding-left] [[data-panel-animations=true]_&]:motion-safe:duration-(--panel-animation-duration) [[data-panel-animations=true]_&]:motion-safe:ease-out", isElectron - ? cn( - "drag-region flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center px-3 sm:px-5", - reserveTitleBarControlInset && - !inlineRightPanelOwnsTitleBar && - "wco:pr-(--workspace-native-controls-inset)", - ) + ? "drag-region flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center px-3 sm:px-5" : "flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center pl-(--workspace-gutter-start) pr-(--workspace-gutter-end)", COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS, )} > - {isElectron && rightPanelControlsAtRoot ? ( - - ) : null} - {!rightPanelControlsAtRoot && !rightPanelControlsInPanel ? panelLayoutControls : null} - {inlineRightPanelOwnsTitleBar ? threadPanelHeaderControl : null} - {rightPanelPresent && activeThreadRef && !embedded ? ( - + } + availableEditors={availableEditors} keybindings={keybindings} getShortcutContext={getShortcutContextStable} - maximized={rightPanelMaximized} - layoutControls={ - rightPanelOpen ? ( -
- - {panelToggleControls} -
- ) : null - } - surfaces={renderedRightPanelSurfaces} environmentId={activeThreadRef.environmentId} - activeSurfaceId={renderedRightPanelSurface?.id ?? null} pendingSurfaceIds={pendingFileSurfaceIds} previewSessions={activePreviewState.sessions} desktopByTabId={activePreviewState.desktopByTabId} @@ -4167,7 +4087,6 @@ export default function ChatView(props: ChatViewProps) { onCloseOtherSurfaces={closeOtherRightPanelSurfacesStable} onCloseSurfacesToRight={closeRightPanelSurfacesToRightStable} onCloseAllSurfaces={closeAllRightPanelSurfacesStable} - onMoveSurface={moveRightPanelSurfaceStable} onCopyFilePath={copyRightPanelFilePathStable} onAddBrowser={() => createBrowserSurface()} onAddBrowserInProfile={createBrowserSurfaceStable} @@ -4189,9 +4108,6 @@ export default function ChatView(props: ChatViewProps) { deviceAvailable={activeThreadRef !== null} sideChatAvailable={sideChat.available} sideChatDisabledReason={sideChatDisabledReason} - threadRef={activeThreadRef} - split={rightPanelPresence.value?.split} - renderSurface={renderRightPanelSurface} /> ) : null} @@ -4214,7 +4130,9 @@ export default function ChatView(props: ChatViewProps) { cwd={activeWorkspaceRoot} checkpoints={serverProjection?.checkpoints} > - {content} + + {content} + ); } diff --git a/apps/web/src/components/CommandPalette.drag.ts b/apps/web/src/components/CommandPalette.drag.ts index 090bab6efbd02..88497ac168231 100644 --- a/apps/web/src/components/CommandPalette.drag.ts +++ b/apps/web/src/components/CommandPalette.drag.ts @@ -27,7 +27,7 @@ export function startPaletteThreadDrag( onStart: () => { flushSync(() => dispatchCommandPalette({ _tag: "SetOpen", open: false })); }, - onMove: (point) => moveThreadContextDrag(point, { title, count: 1 }), + onMove: (point) => moveThreadContextDrag(point, { title, count: 1 }, [{ ...thread, title }]), onPending: () => {}, onAbort: () => {}, onCancel: () => {}, diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index a2ea9a6a6812c..11b365f0d436b 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -125,7 +125,8 @@ import { primaryServerKeybindingsAtom } from "~/state/server"; import { hasCommandForKeyDown } from "~/shortcuts/dispatcher"; import { basenameOfPath } from "~/pierre-icons"; import { WorkspaceEntryTooltip } from "./chat/WorkspaceEntryIcon"; -import { postWhiteboardHover } from "../fork/whiteboard/markdown-whiteboard"; +import { boardMentionParts } from "../fork/whiteboard/markdown-whiteboard"; +import { BoardMentionChip } from "../fork/whiteboard/BoardMentionChip"; import { FileTagChipContent } from "./chat/FileTagChip"; import { SkillChipPopover, skillPopoverDescription } from "./chat/SkillInlineText"; import { AssistantCitationChip } from "./chat/AssistantCitationChip"; @@ -294,33 +295,35 @@ const ComposerMentionExtension = Node.create({ function ComposerMentionNodeView({ node }: NodeViewProps) { const gt = useGT(); const actions = use(ComposerContextActionsContext); - const mentionPath = (node.attrs.path as string) ?? ""; - const boardMatch = /^\[([^\]]+)\]\((board:\/\/[^)]+)\)$/.exec(mentionPath); - const path = boardMatch?.[2] ?? mentionPath; + const path = (node.attrs.path as string) ?? ""; + const board = boardMentionParts(path); const nativeDrag = useNativeFileDrag(actions.environmentId, () => resolvePathLinkTarget(path, actions.cwd ?? ""), ); + if (board) { + return ( + + actions.openMention(path)} /> + + ); + } const chip = ( } - onClick={() => actions.openMention(mentionPath)} + onClick={() => actions.openMention(path)} aria-label={gt("Preview {path}", { path })} contentEditable={false} spellCheck={false} data-composer-mention-chip="true" - onMouseEnter={ - boardMatch ? (event) => postWhiteboardHover(path, event.currentTarget) : undefined - } - onMouseLeave={boardMatch ? () => postWhiteboardHover(null) : undefined} > diff --git a/apps/web/src/components/RightPanelTabs.tsx b/apps/web/src/components/RightPanelTabs.tsx index 48f8da169d4c9..c1c0f9ed06c71 100644 --- a/apps/web/src/components/RightPanelTabs.tsx +++ b/apps/web/src/components/RightPanelTabs.tsx @@ -37,14 +37,20 @@ import { AllMenuItemsHidden, useArrangedSurfaceActions, } from "~/fork/rightPanelMenu/rightPanelMenu"; -import type { SplitMenuAction } from "~/fork/rightPanelSplit/splitLayout.logic"; import { + displayTitle, + isDisplayEntry, + type PaneMenuAction, SplitPaneFrame, + tabDragData, useRightPanelPane, - useTabDragData, useTabDragSensors, + UnclosableTabIcon, useTabPress, -} from "~/fork/rightPanelSplit/tabStrip"; + type WorkAreaEntry, + withChatClosing, +} from "~/fork/workArea/tabStrip"; +import { useTabPresentation } from "~/fork/workArea/useTabPresentation"; import { closestCenter, DndContext, type DragEndEvent } from "@dnd-kit/core"; import { restrictToFirstScrollableAncestor, restrictToHorizontalAxis } from "@dnd-kit/modifiers"; import { horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable"; @@ -126,7 +132,7 @@ import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons"; import { observeResize } from "~/lib/observeResize"; import { surfaceShortcutKey } from "~/lib/surfaceShortcutKey"; -export interface RightPanelTabsProps { +export interface RightPanelTabsProps { mode: PreviewPanelMode; maximized?: boolean; open?: boolean; @@ -136,7 +142,9 @@ export interface RightPanelTabsProps { defaultWidth?: number; inlineSize?: PreviewPanelInlineSize; layoutControls?: ReactNode; - surfaces: readonly RightPanelSurface[]; + /** Draws the launcher as the body; its letter keys act while `shortcuts` holds. */ + launcher?: { readonly shortcuts: boolean }; + surfaces: readonly Entry[]; environmentId: EnvironmentId | null; activeSurfaceId: string | null; pendingSurfaceIds: ReadonlySet; @@ -145,20 +153,21 @@ export interface RightPanelTabsProps { /** Maps server-local session ids to desktop runtime ids; session ids cannot address desktop operations. */ previewRuntimeTabId?: ((tabId: string) => string) | undefined; terminalLabelsById: ReadonlyMap; - onActivate: (surface: RightPanelSurface) => void; + onActivate: (surface: Entry) => void; onRenameDevice?: (surfaceId: string, title: string) => void; - onCloseSurface: (surface: RightPanelSurface) => void; + onCloseSurface: (surface: Entry) => void; /** Moves a subagent, side chat or linked thread tab to the main screen. */ onOpenInMainView?: ( surface: Extract, ) => void; /** `strip` is the strip that opened the menu: one pane of a split, or every tab. */ - onCloseOtherSurfaces: (surface: RightPanelSurface, strip: readonly RightPanelSurface[]) => void; - onCloseSurfacesToRight: (surface: RightPanelSurface, strip: readonly RightPanelSurface[]) => void; - onCloseAllSurfaces: (strip: readonly RightPanelSurface[]) => void; + onCloseOtherSurfaces: (surface: Entry, strip: readonly Entry[]) => void; + onCloseSurfacesToRight: (surface: Entry, strip: readonly Entry[]) => void; + /** `afterClose` runs once the strip is closed, after any confirmation. */ + onCloseAllSurfaces: (strip: readonly Entry[], afterClose?: () => void) => void; onMoveSurface?: (surfaceId: string, toIndex: number) => void; onCopyFilePath: (relativePath: string) => void; - onDuplicateBrowser?: (surface: RightPanelSurface) => void; + onDuplicateBrowser?: (surface: Entry) => void; onAddBrowser: () => void; /** Keep separate from the DOM click handler so a MouseEvent cannot become a profile id. */ onAddBrowserInProfile: (profileId: string) => void; @@ -255,7 +264,7 @@ function tabScrollViewport(root: HTMLDivElement | null): HTMLDivElement | null { } function previewTabIdOf( - surface: RightPanelSurface, + surface: WorkAreaEntry, sessions: Readonly>, ): string | null { if (surface.kind !== "preview" || !surface.resourceId) return null; @@ -368,6 +377,7 @@ function RightPanelEmptyState(props: { deviceAvailable: boolean; sideChatAvailable: boolean; sideChatDisabledReason: string | null; + shortcuts: boolean; }) { const gt = useGT(); const messages = useMessages(); @@ -463,6 +473,7 @@ function RightPanelEmptyState(props: { availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1); const handleShortcut = useEffectEvent((event: KeyboardEvent) => { + if (!props.shortcuts) return; const action = surfaceShortcutActionForKey(availableActions, event); if (!action) return; if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return; @@ -618,11 +629,12 @@ function RightPanelEmptyState(props: { } function surfaceTitle( - surface: RightPanelSurface, + surface: WorkAreaEntry, sessions: Readonly>, terminalLabelsById: ReadonlyMap, resolve: MessageResolver = m, ): string { + if (isDisplayEntry(surface)) return displayTitle(surface); switch (surface.kind) { case "diff": return resolve(msg("Diff")); @@ -691,7 +703,7 @@ function sameOrigin(left: string, right: string): boolean { } function previewFaviconOf( - surface: RightPanelSurface, + surface: WorkAreaEntry, sessions: Readonly>, desktopByTabId: Readonly>, ): { url: string | null; capturedUrl: string | null } { @@ -711,7 +723,7 @@ function SurfaceIcon({ environmentId, pullRequestStatusSeed, }: { - surface: RightPanelSurface; + surface: WorkAreaEntry; previewUrl: string | null; previewCapturedUrl: string | null; theme: "light" | "dark"; @@ -932,7 +944,7 @@ function PullRequestSurfaceIcon({ } function SortableTabList(props: { - surfaces: readonly RightPanelSurface[]; + surfaces: readonly WorkAreaEntry[]; onMove: ((surfaceId: string, toIndex: number) => void) | undefined; children: ReactNode; }) { @@ -963,11 +975,11 @@ function SortableTabList(props: { ); } -interface RightPanelTabHandlers { - onActivate: (surface: RightPanelSurface) => void; - onClose: (surface: RightPanelSurface) => void; - onAuxClick: (event: ReactMouseEvent, surface: RightPanelSurface) => void; - onContextMenu: (event: ReactMouseEvent, surface: RightPanelSurface) => void; +interface RightPanelTabHandlers { + onActivate: (surface: Entry) => void; + onClose: (surface: Entry) => void; + onAuxClick: (event: ReactMouseEvent, surface: Entry) => void; + onContextMenu: (event: ReactMouseEvent, surface: Entry) => void; onStartRename: (surfaceId: string) => void; onFinishRename: (surfaceId: string, title: string) => void; } @@ -979,9 +991,9 @@ function preventTabMiddleButtonDefault(event: ReactMouseEvent) { } // Stable handlers and per-tab values let the compiler reuse tabs across parent renders. -function RightPanelTab( - props: RightPanelTabHandlers & { - surface: RightPanelSurface; +function RightPanelTab( + props: RightPanelTabHandlers & { + surface: Entry; dragDisabled: boolean; active: boolean; pending: boolean; @@ -1013,27 +1025,31 @@ function RightPanelTab( } = props; const press = useTabPress(surface, onActivate); const inDragScope = useRightPanelPane() !== null; - const dragData = useTabDragData(props.title); + const dragData = tabDragData(props.title); const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: surface.id, disabled: props.dragDisabled, data: dragData, }); + const presentation = useTabPresentation(surface, props.active); const sideChatShell = useQuietThreadShell( surface.kind === "thread" && props.environmentId !== null ? scopeThreadRef(props.environmentId, surface.threadId) : null, ); const title = - sideChatShell === null + presentation?.title ?? + (sideChatShell === null ? props.title : sideChatShell.lineage.sideChat === true ? sideChatShell.title - : formatSubagentDisplayTitle(sideChatShell.title); - const sideChatState = sideChatTabState(sideChatShell); + : formatSubagentDisplayTitle(sideChatShell.title)); + const sideChatState = sideChatTabState(presentation?.shell ?? sideChatShell); + const IconSlot = presentation?.closable === false ? UnclosableTabIcon : PanelTabCloseButton; const content = ( <> - onClose(surface)}> + onClose(surface)}> + {presentation?.icon} ) : null} - + {audio === "none" || !audioRuntimeTabId ? null : ( { preventTabMiddleButtonDefault(event); press.onMouseDown(event); @@ -1170,11 +1187,12 @@ function RightPanelTab( ); } -export function RightPanelTabs(props: RightPanelTabsProps) { +export function RightPanelTabs(props: RightPanelTabsProps) { const gt = useGT(); const messages = useMessages(); const focusedSurface = props.surfaces.find((surface) => surface.id === props.activeSurfaceId); - const ownsDesktopTitleBar = isElectron && props.mode === "inline"; + const pane = useRightPanelPane(); + const ownsDesktopTitleBar = isElectron && props.mode === "inline" && pane?.edges.top !== false; const browserProfiles = useBrowserDefaults().profiles; const { resolvedTheme } = useTheme(); const tabListRef = useRef(null); @@ -1212,8 +1230,6 @@ export function RightPanelTabs(props: RightPanelTabsProps) { const onMenuAction = useEffectEvent((action: string) => { if (action === "rightPanel.new" && !addSurfaceMenuBlocked()) setAddSurfaceMenuOpen(true); }); - // Inside ChatView's split view, which owns the shell and the split menu entries. - const pane = useRightPanelPane(); const takesNewSurfaceShortcut = props.open !== false && pane?.focused !== false; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes document keydown and the desktop menu action (forwarded from a focused browser page) for the new surface shortcut while the panel is open useEffect(() => { @@ -1344,7 +1360,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) { action.onClick(); }; - const handleTabContextMenu = async (event: ReactMouseEvent, surface: RightPanelSurface) => { + const handleTabContextMenu = async (event: ReactMouseEvent, surface: Entry) => { event.preventDefault(); event.stopPropagation(); @@ -1354,13 +1370,13 @@ export function RightPanelTabs(props: RightPanelTabsProps) { const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id); if (surfaceIndex < 0) return; - const items: ContextMenuItem[] = []; + const items: ContextMenuItem[] = []; if ((surface.kind === "thread" || surface.kind === "linked-thread") && props.onOpenInMainView) { items.push({ id: "open-in-main-view", label: gt("Open in main view") }); } if (surface.kind === "device" && props.onRenameDevice) items.push({ id: "rename", label: gt("Rename") }); - if (surface.kind === "file" && surface.attachment === undefined) { + if (surface.kind === "file" && surface.attachment === undefined && !isDisplayEntry(surface)) { items.push({ id: "copy-path", label: gt("Copy path") }); } const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions); @@ -1403,7 +1419,10 @@ export function RightPanelTabs(props: RightPanelTabsProps) { ...(pane?.tabMenu.items(surface) ?? []), ); - const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY }); + const action = await api.contextMenu.show(withChatClosing(items, surface, props.surfaces), { + x: event.clientX, + y: event.clientY, + }); switch (action) { case "open-in-main-view": if (surface.kind === "thread" || surface.kind === "linked-thread") { @@ -1449,7 +1468,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) { pane?.tabMenu.select(action, surface); } }; - const handleTabAuxClick = (event: ReactMouseEvent, surface: RightPanelSurface) => { + const handleTabAuxClick = (event: ReactMouseEvent, surface: Entry) => { if (event.button !== 1) return; event.preventDefault(); event.stopPropagation(); @@ -1458,11 +1477,9 @@ export function RightPanelTabs(props: RightPanelTabsProps) { const onActivateTab = useStableCallback(props.onActivate); const onCloseTab = useStableCallback(props.onCloseSurface); const onTabAuxClick = useStableCallback(handleTabAuxClick); - const onTabContextMenu = useStableCallback( - (event: ReactMouseEvent, surface: RightPanelSurface) => { - void handleTabContextMenu(event, surface); - }, - ); + const onTabContextMenu = useStableCallback((event: ReactMouseEvent, surface: Entry) => { + void handleTabContextMenu(event, surface); + }); const onStartRenameTab = useStableCallback((surfaceId: string) => setRenamingDevice(surfaceId)); const onFinishRenameTab = useStableCallback((surfaceId: string, title: string) => { props.onRenameDevice?.(surfaceId, title); @@ -1513,8 +1530,8 @@ export function RightPanelTabs(props: RightPanelTabsProps) { }; const Frame = pane ? SplitPaneFrame : PreviewPanelShell; - const atLeftEdge = pane?.side !== "right"; - const atRightEdge = pane?.side !== "left"; + const atLeftEdge = pane?.edges.left !== false; + const atRightEdge = pane?.edges.right !== false; return ( ) : null} - {ownsDesktopTitleBar && atRightEdge ? ( + {ownsDesktopTitleBar && atRightEdge && !pane ? (
- {props.activeSurfaceId === null ? ( + {props.activeSurfaceId === null || props.launcher ? ( { diff --git a/apps/web/src/components/ThreadContextChip.tsx b/apps/web/src/components/ThreadContextChip.tsx index cc099fc791a8c..060214dc698f8 100644 --- a/apps/web/src/components/ThreadContextChip.tsx +++ b/apps/web/src/components/ThreadContextChip.tsx @@ -3,7 +3,9 @@ import type { ThreadContextRecord, ProjectId } from "@t3tools/contracts"; import { Link, useNavigate } from "@tanstack/react-router"; import { MessagesSquareIcon } from "lucide-react"; import { useGT } from "gt-react"; +import { use } from "react"; +import { ChatOpenerContext, openThreadTabOnClick } from "~/fork/workArea/chatOpenerContext"; import { resolveThreadOpenRoute } from "~/lib/sideChatPane"; import { buildThreadRouteParams } from "~/threadRoutes"; import { useProject, useThreadShell } from "~/state/entities"; @@ -35,6 +37,7 @@ export function ThreadContextChip(props: { const project = useProject(projectId ? scopeProjectRef(environmentId, projectId) : null); const title = shell?.title?.trim() || metadata?.title.trim() || props.record.title; const navigate = useNavigate(); + const opener = use(ChatOpenerContext); return ( { + if (openThreadTabOnClick(event, opener, { environmentId, threadId })) return; if (shell?.lineage.sideChat !== true || event.button !== 0) return; if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; // A side chat opens as a tab beside its parent, not as its own page. diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 4c6502074ca08..62866ca5da306 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -13,7 +13,7 @@ import { } from "./runtimeModeConfig"; import { isLocalEnvironmentDisabled } from "../../localEnvironment"; import { usePrimaryEnvironmentId } from "../../state/environments"; -import { useRightPanelStore } from "~/rightPanelStore"; +import { useChatFileOpener } from "~/fork/workArea/chatFileOpener"; import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste"; import { questionAttachmentDraftId, @@ -727,6 +727,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) const nonPersistedComposerImageIds = attachmentDraft.nonPersistedImageIds; const uploadsByImageId = useAttachmentUploadStore((state) => state.uploadsByImageId); const openPrLink = useOpenPrLink(routeThreadRef); + const mentionFileOpener = useChatFileOpener(routeThreadRef); const [previewFileId, setPreviewFileId] = useState(null); const previewFile = composerFiles.find((file) => file.id === previewFileId); const composerContextActions = { @@ -742,7 +743,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) if (preview) onExpandImage(preview); }, openFile: setPreviewFileId, - openMention: (path: string) => useRightPanelStore.getState().openFile(routeThreadRef, path), + openMention: (path: string) => mentionFileOpener?.().openMention(path), expandVideo: (fileId: string) => { const file = composerFiles.find((candidate) => candidate.id === fileId); if (!file || !isVideoAttachment(file)) return; diff --git a/apps/web/src/components/chat/ChatHeader.browser.test.tsx b/apps/web/src/components/chat/ChatHeader.browser.test.tsx index 2f54eef77c8d3..01375c460bd18 100644 --- a/apps/web/src/components/chat/ChatHeader.browser.test.tsx +++ b/apps/web/src/components/chat/ChatHeader.browser.test.tsx @@ -35,8 +35,6 @@ function header(title: string) { activeProject={null} parentThreadLink={null} onOpenThread={() => {}} - rightPanelOpen={false} - onNewThreadInProject={() => {}} />
Outside rename
diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsx index 133c80f304d0a..b9fc3964bd692 100644 --- a/apps/web/src/components/chat/ChatHeader.tsx +++ b/apps/web/src/components/chat/ChatHeader.tsx @@ -40,7 +40,6 @@ import { WorkspaceBreadcrumbText, } from "../WorkspaceBreadcrumb"; import { observeResize } from "~/lib/observeResize"; -import { cn } from "~/lib/utils"; import { textDirection } from "~/textDirection"; import { useClientSettings } from "../../hooks/useSettings"; import { GuestShareIndicator } from "./GuestShareControls"; @@ -54,8 +53,6 @@ interface ChatHeaderProps { activeProject: EnvironmentProject | null; parentThreadLink: { threadId: ThreadId; title: string } | null; onOpenThread: (threadId: ThreadId) => void; - rightPanelOpen: boolean; - onNewThreadInProject: () => void; onOpenProjectSettings?: (() => void) | undefined; onFindInThread?: ((threadRef: ScopedThreadRef) => void) | undefined; } @@ -79,8 +76,6 @@ export const ChatHeader = memo(function ChatHeader({ activeProject, parentThreadLink, onOpenThread, - rightPanelOpen, - onNewThreadInProject, onOpenProjectSettings, onFindInThread, }: ChatHeaderProps) { @@ -251,10 +246,7 @@ export const ChatHeader = memo(function ChatHeader({ return (
- - - } - > - - - - - - New thread in {activeProjectName} - - - + + + + / diff --git a/apps/web/src/components/chat/ChatMarkdownMedia.tsx b/apps/web/src/components/chat/ChatMarkdownMedia.tsx index ea8f5d224dd1d..b414ddd1b63df 100644 --- a/apps/web/src/components/chat/ChatMarkdownMedia.tsx +++ b/apps/web/src/components/chat/ChatMarkdownMedia.tsx @@ -1,3 +1,4 @@ +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; import { mediaFileReference, mediaUrlReference } from "@t3tools/client-runtime/media-reference"; import type { AssetResource, EnvironmentId, SOURCE_CONTROL_MEDIA_ASSET } from "@t3tools/contracts"; import { msg, useGT, useMessages } from "gt-react"; @@ -17,6 +18,7 @@ import { useAssetUrlRefresh, useAssetUrlState } from "../../assets/assetUrls"; import type { MessageResolver } from "../../i18n/messages"; import { cn } from "../../lib/utils"; import { useRightPanelStore } from "../../rightPanelStore"; +import { type ChatFileOpener, useChatFileOpener } from "../../fork/workArea/chatFileOpener"; import { MediaActions, type MediaActionSource } from "../media/MediaActions"; import { MediaVideoPlayer } from "../media/MediaVideoPlayer"; import type { ExpandedImagePreview } from "./ExpandedImagePreview"; @@ -356,6 +358,7 @@ export function assetMediaActionsSource(input: { readonly workspaceRoot?: string | undefined; readonly originalUrl?: string | undefined; readonly downloadable?: boolean | undefined; + readonly fileOpener?: ChatFileOpener | null | undefined; }): MediaActionSource { const { environmentId, resource } = input; const path = @@ -378,10 +381,11 @@ export function assetMediaActionsSource(input: { ...(reference ? { reference } : {}), ...(relativePath && (resource._tag === "media-file" || resource._tag === "workspace-file") ? { - onOpenFile: () => - useRightPanelStore - .getState() - .openFile({ environmentId, threadId: resource.threadId }, relativePath), + onOpenFile: () => { + const thread = scopeThreadRef(environmentId, resource.threadId); + if (input.fileOpener) input.fileOpener(thread).openFile(relativePath); + else useRightPanelStore.getState().openFile(thread, relativePath); + }, } : {}), }; @@ -410,6 +414,11 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props }) { const gt = useGT(); const resource = props.resource; + const fileOpener = useChatFileOpener( + resource._tag === "media-file" || resource._tag === "workspace-file" + ? scopeThreadRef(props.environmentId, resource.threadId) + : null, + ); const threadWorkspaceMutationId = use(WorkspaceMutationIdContext); const workspaceMutationId = props.workspaceMutationId ?? threadWorkspaceMutationId; const assetUrl = useAssetUrlState( @@ -454,6 +463,7 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props workspaceRoot: props.workspaceRoot, originalUrl: props.originalUrl, downloadable: fallbackSrc === undefined, + fileOpener, }); if (props.kind === "video") { diff --git a/apps/web/src/components/chat/ChatRightPanel.tsx b/apps/web/src/components/chat/ChatRightPanel.tsx deleted file mode 100644 index 90def1a1687cd..0000000000000 --- a/apps/web/src/components/chat/ChatRightPanel.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { usePreviewPanelInlineSize } from "../../hooks/usePreviewPanelInlineSize"; -import { - RightPanelSplitView, - type RightPanelSplitViewProps, -} from "../../fork/rightPanelSplit/RightPanelSplitView"; -import { RightPanelSheet } from "../RightPanelSheet"; - -type ChatRightPanelProps = Omit & { - readonly sheet: boolean; - readonly maximized: boolean; - readonly workspaceLayoutElement: HTMLElement | null; - readonly widthStorageKey: string; - readonly sheetAnimationDurationMs: number; - readonly onCloseSheet: () => void; -}; - -/** - * The right panel, inline beside the chat column or as a sheet on narrow - * layouts. Its width follows a resize drag every frame, so the width state - * lives here rather than in ChatView. - */ -export function ChatRightPanel(props: ChatRightPanelProps) { - const { - sheet, - workspaceLayoutElement, - widthStorageKey, - sheetAnimationDurationMs, - onCloseSheet, - maximized, - layoutControls, - ...tabs - } = props; - const inlineSize = usePreviewPanelInlineSize({ - container: workspaceLayoutElement, - widthStorageKey, - }); - if (!sheet) { - return ( - - ); - } - return ( - - - - ); -} diff --git a/apps/web/src/components/chat/CollapsedComposerPromptPreview.tsx b/apps/web/src/components/chat/CollapsedComposerPromptPreview.tsx index 1c91b3aee387c..547332f0323c6 100644 --- a/apps/web/src/components/chat/CollapsedComposerPromptPreview.tsx +++ b/apps/web/src/components/chat/CollapsedComposerPromptPreview.tsx @@ -25,6 +25,8 @@ import { ContextChip, ContextChipLabel } from "../ContextChip"; import { ContextChipShell } from "../contextChipParts"; import { PierreEntryIcon } from "./PierreEntryIcon"; import { SkillChipIcon } from "./SkillInlineText"; +import { BoardMentionIcon } from "../../fork/whiteboard/BoardMentionChip"; +import { boardMentionParts } from "../../fork/whiteboard/markdown-whiteboard"; type Theme = "light" | "dark"; @@ -88,8 +90,14 @@ export function CollapsedComposerPromptPreview(props: { } - label={fileDisplayName(segment.path)} + icon={ + boardMentionParts(segment.path) ? ( + + ) : ( + + ) + } + label={boardMentionParts(segment.path)?.label ?? fileDisplayName(segment.path)} /> ); case "context-reference": { diff --git a/apps/web/src/components/chat/PanelLayoutControls.tsx b/apps/web/src/components/chat/PanelLayoutControls.tsx index eace277034738..71c5ac641b8fb 100644 --- a/apps/web/src/components/chat/PanelLayoutControls.tsx +++ b/apps/web/src/components/chat/PanelLayoutControls.tsx @@ -6,19 +6,13 @@ import { Minimize2Icon, } from "lucide-react"; import { useGT } from "gt-react"; -import { memo, type ReactNode, useLayoutEffect, useRef } from "react"; - -import { cn } from "~/lib/utils"; +import { memo } from "react"; import type { ThreadPanelPresentation } from "../../rightPanelLayout"; import { PopoverCreateHandle, PopoverTrigger } from "../ui/popover"; -import { useMobileSidebarSheetMounted } from "../ui/sidebar"; import { Toggle } from "../ui/toggle"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; -/** Matches the right inset of `ThreadPanelHeaderControl`. */ -const THREAD_PANEL_HEADER_INSET_PX = 12; - export interface PanelLayoutControlsProps { showThreadPanelControl?: boolean; showTerminalControl?: boolean; @@ -180,86 +174,3 @@ export const RightPanelMaximizeControl = memo(function RightPanelMaximizeControl ); }); - -/** The thread panel toggle on a header whose right side the inline right panel covers. */ -export function ThreadPanelHeaderControl(props: PanelLayoutControlsProps) { - const mobileSidebarSheetMounted = useMobileSidebarSheetMounted(); - return ( -
- -
- ); -} - -/** The window's top-right panel controls, with the maximize toggle while the panel is open. */ -export function WorkspaceTitlebarControls(props: { - readonly showMaximizeControl: boolean; - readonly rightPanelOpen: boolean; - readonly animationsActive: boolean; - readonly maximized: boolean; - readonly onToggleMaximized: () => void; - readonly children: ReactNode; -}) { - const { rightPanelOpen, maximized } = props; - const controlsRef = useRef(null); - const previous = useRef({ rightPanelOpen, maximized }); - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts the toggle's slide before the commit that swapped it in paints; the animation is cancelled on change or unmount. - useLayoutEffect(() => { - const { rightPanelOpen: wasOpen, maximized: wasMaximized } = previous.current; - previous.current = { rightPanelOpen, maximized }; - if (!wasOpen || rightPanelOpen || wasMaximized) return; - const toggle = controlsRef.current?.querySelector("[data-thread-panel-toggle]"); - const panel = toggle?.ownerDocument.querySelector("[data-preview-panel-mode='inline']"); - const timing = panel?.getAnimations()[0]?.effect?.getTiming(); - if (!toggle || !panel || !timing) return; - // The header's toggle was just removed, so slide this one in from where it sat. - const headerRight = panel.getBoundingClientRect().left - THREAD_PANEL_HEADER_INSET_PX; - const offset = headerRight - toggle.getBoundingClientRect().right; - const animation = toggle.animate( - [{ transform: `translateX(${offset}px)` }, { transform: "none" }], - { ...timing, easing: getComputedStyle(panel).transitionTimingFunction }, - ); - return () => animation.cancel(); - }, [rightPanelOpen, maximized]); - - const mobileSidebarSheetMounted = useMobileSidebarSheetMounted(); - return ( -
- {props.showMaximizeControl ? ( - - - - ) : null} -
{props.children}
-
- ); -} diff --git a/apps/web/src/components/chat/SideThreadPane.tsx b/apps/web/src/components/chat/SideThreadPane.tsx index 9f32d90c4f8a7..d327a073ab4ea 100644 --- a/apps/web/src/components/chat/SideThreadPane.tsx +++ b/apps/web/src/components/chat/SideThreadPane.tsx @@ -34,6 +34,8 @@ import { Button } from "../ui/button"; import { toastManager } from "../ui/toast"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { BackgroundThreadContext } from "./backgroundThread"; +import { OpenOriginContext } from "../../fork/workArea/chatFileOpener"; +import { useSideThreadEmbedding } from "../../fork/workArea/chatOpenerContext"; /** * A side chat or a subagent as a tab: the thread's own chat, which decides its bottom, the @@ -78,6 +80,12 @@ export default function SideThreadPane(props: { // A tab opens for side chats and subagents only, so an unloaded one is still one of them. const kind = sideThreadKindOf(thread) ?? "subagent"; const isSideChat = kind === "side-chat"; + const embedding = useSideThreadEmbedding( + threadId, + thread?.lineage.parentThreadId ?? null, + parentRef, + props.parentPanel, + ); const canOperate = useEnvironmentScope(parentRef.environmentId, AuthOrchestrationOperateScope); const deleteThread = useAtomCommand(threadEnvironment.delete, { reportFailure: false }); const confirmThreadDelete = useClientSettings((settings) => settings.confirmThreadDelete); @@ -196,12 +204,14 @@ export default function SideThreadPane(props: { ) : renderState === "loading" && thread === null ? null : ( - + + + )} diff --git a/apps/web/src/components/chat/SkillInlineText.tsx b/apps/web/src/components/chat/SkillInlineText.tsx index 59271a4cb5b54..757a7c13d8459 100644 --- a/apps/web/src/components/chat/SkillInlineText.tsx +++ b/apps/web/src/components/chat/SkillInlineText.tsx @@ -5,7 +5,7 @@ import { T, useGT } from "gt-react"; import { Children, cloneElement, isValidElement, type ReactNode } from "react"; import { matchInlineSkills } from "@t3tools/shared/inlineSkills"; -import { useRightPanelStore } from "~/rightPanelStore"; +import { type ChatFileOpener, useChatFileOpener } from "~/fork/workArea/chatFileOpener"; import { SKILL_CHIP_ICON_SVG } from "../composerInlineChip"; import { ContextChipPopover } from "../contextChipParts"; import { Button } from "../ui/button"; @@ -18,6 +18,7 @@ function SkillInlineText(props: { threadRef: ScopedThreadRef | undefined; environmentId: EnvironmentId | null; }) { + const fileOpener = useChatFileOpener(props.threadRef); const chips: Array<{ start: number; end: number; node: ReactNode }> = []; for (const { start, end, skill, rawText } of matchInlineSkills(props.text, props.skills)) { chips.push({ @@ -29,7 +30,7 @@ function SkillInlineText(props: { label={formatProviderSkillDisplayName(skill)} description={skillPopoverDescription(skill)} copyMarkdown={rawText} - onViewInstructions={skillInstructionsOpener(props.threadRef, skill)} + onViewInstructions={skillInstructionsOpener(fileOpener, skill)} /> ), }); @@ -112,11 +113,11 @@ export function skillPopoverDescription( } export function skillInstructionsOpener( - threadRef: ScopedThreadRef | null | undefined, + fileOpener: ChatFileOpener | null, skill: Pick | undefined, ) { - if (!threadRef || !skill?.path) return undefined; - return () => useRightPanelStore.getState().openFile(threadRef, skill.path); + if (!fileOpener || !skill?.path) return undefined; + return () => fileOpener().openFile(skill.path); } export function SkillChipPopover(props: { diff --git a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx index f3f164b8800db..d77616d293679 100644 --- a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx +++ b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx @@ -18,6 +18,7 @@ import { LegendList, type LegendListRef } from "@legendapp/list/react"; import { workEntryDisplayIndicatesToolFailure } from "../../session-logic"; import ChatMarkdown from "../ChatMarkdown"; import { assetMediaActionsSource } from "./ChatMarkdownMedia"; +import { useChatFileOpener } from "../../fork/workArea/chatFileOpener"; import { Minimize2Icon, XIcon } from "lucide-react"; import { Button } from "../ui/button"; import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area"; @@ -145,6 +146,7 @@ function useWorkGroupViewedImages( groupedEntries: ReadonlyArray, ): ReadonlyArray { const { threadRef, workspaceRoot, activeThreadEnvironmentId } = use(TimelineRowCtx); + const fileOpener = useChatFileOpener(threadRef); const gt = useGT(); const fallbackName = gt("image", { $context: "fallback name of an image without alt text" }); const viewed = threadRef @@ -178,6 +180,7 @@ function useWorkGroupViewedImages( name: asset.alt || fallbackName, src, workspaceRoot, + fileOpener, }), }, }; diff --git a/apps/web/src/components/chat/UserMessageContextChips.tsx b/apps/web/src/components/chat/UserMessageContextChips.tsx index 4836552e3103a..5f21afa0ed5f1 100644 --- a/apps/web/src/components/chat/UserMessageContextChips.tsx +++ b/apps/web/src/components/chat/UserMessageContextChips.tsx @@ -8,7 +8,7 @@ import { CHAT_USER_MARKDOWN_REMARK_PLUGINS } from "@t3tools/shared/markdownPipel import { useRenderedAppearance } from "../../hooks/useTheme"; import { PullRequestGlyph } from "../pullRequest/pullRequestIcons"; import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview"; -import { useRightPanelStore } from "~/rightPanelStore"; +import { useChatFileOpener } from "~/fork/workArea/chatFileOpener"; import { COMPOSER_CONTEXT_KINDS } from "@t3tools/contracts"; import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments"; import { use, type ReactNode } from "react"; @@ -77,6 +77,7 @@ function UserMessageMentionChip(props: { }) { const gt = useGT(); const ctx = use(TimelineRowCtx); + const fileOpener = useChatFileOpener(ctx.threadRef); const nativeDrag = useNativeFileDrag(ctx.activeThreadEnvironmentId, () => resolvePathLinkTarget(props.record.path, ctx.workspaceRoot ?? ""), ); @@ -90,10 +91,7 @@ function UserMessageMentionChip(props: { render={