From 33416f9fd762c8e6e16332af4ae402223018e07b 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. The only tab in no pane is a browser or device tab that floats in the mini player. Preview: Toggle, picture-in-picture and device Float move it there; closing the player, Open in panel or Preview: Toggle again puts it back, and so does any view that stops drawing the Chat that holds the player. Preview: Toggle on an empty browser tab closes it. Diff: Toggle closes the Diff tab when shown and opens it otherwise, so Reopen Closed View sees the close. There is no terminal drawer under the chat. A request to open the drawer becomes a terminal tab in the PTY's own thread record, so scripts, chat code-block Run and the setup banner keep working; server terminals with no tab are adopted as background tabs, and a tab the user closed stays closed while the server still lists it. Terminal: Toggle (Cmd/Ctrl+J) is filtered out of the web client's keybindings and settings, so the key reaches the shell; split, new and close act on the focused terminal tab. Files tree rows and chat links (upstream's drag sources, moved into the work area) drop onto a pane's tab strip, one of its four edges, or its middle, through the same open origin a click uses; a press or key before a slow open lands cancels the drop place. On a subagent's own page its child's side thread is the page's own thread; the composer's pull request chip opens beside its chat; pane ids are not reused after the layout falls back to the default. Upstream files carry only small hooks. Co-Authored-By: Claude Opus 5.5 --- README.md | 3 +- apps/web/src/browser/BrowserSurfaceSlot.tsx | 3 + apps/web/src/browser/openFileInPreview.ts | 20 +- apps/web/src/browser/useOpenLink.ts | 6 +- apps/web/src/components/ChatMarkdown.tsx | 71 +- .../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 | 119 +- .../Sidebar.shortcuts.browser.test.tsx | 3 +- apps/web/src/components/Sidebar.tsx | 2 +- apps/web/src/components/ThreadContextChip.tsx | 5 +- apps/web/src/components/chat/ChatComposer.tsx | 7 +- .../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 +- .../src/components/chat/MarkdownFileLink.tsx | 7 +- .../chat/MarkdownThreadLink.browser.test.tsx | 7 +- .../components/chat/MarkdownThreadLink.tsx | 14 +- .../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 +- .../components/chat/useChatTerminalActions.ts | 71 +- .../components/chat/useRightPanelActions.ts | 25 +- 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/FileBrowserPanel.tsx | 4 +- .../src/components/files/FilePreviewPanel.tsx | 22 +- .../components/files/fileReadingPosition.ts | 7 +- .../components/preview/addBrowserSurface.ts | 4 +- .../KeybindingsSettings.browser.test.tsx | 2 +- .../settings/KeybindingsSettings.logic.ts | 13 +- .../settings/KeybindingsSettings.tsx | 3 +- .../src/components/settings/settingsSearch.ts | 4 +- .../src/fork/dashboard/dashboardLink.test.ts | 56 + apps/web/src/fork/dashboard/dashboardLink.tsx | 33 +- .../src/fork/dashboard/dashboardSurface.ts | 10 +- apps/web/src/fork/forkCopy.ts | 30 + .../rightPanelMenu/RightPanelMenuSettings.tsx | 12 +- .../web/src/fork/rightPanelMenu/menu.logic.ts | 1 + .../rightPanelSplit/PanelLinkDropScope.tsx | 187 --- .../rightPanelSplit/RightPanelDragScope.tsx | 196 --- .../RightPanelSplitView.browser.test.tsx | 627 -------- .../rightPanelSplit/RightPanelSplitView.tsx | 357 ----- .../rightPanelSplit/dropTarget.logic.test.ts | 225 --- .../fork/rightPanelSplit/dropTarget.logic.ts | 270 ---- .../rightPanelSplit/linkDrop.logic.test.ts | 377 ----- .../fork/rightPanelSplit/linkDrop.logic.ts | 192 --- .../fork/rightPanelSplit/panelLinkDrag.css | 16 - .../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 | 214 ++- .../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 | 78 +- .../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 | 98 ++ apps/web/src/fork/workArea/SecondaryChat.tsx | 90 ++ .../fork/workArea/WorkArea.browser.test.tsx | 843 ++++++++++ apps/web/src/fork/workArea/WorkArea.tsx | 988 ++++++++++++ .../changeRequestLink.browser.test.tsx | 155 ++ .../chatAnchorLink.ts | 37 +- apps/web/src/fork/workArea/chatFileOpener.ts | 297 ++++ .../src/fork/workArea/chatOpenerContext.ts | 103 ++ .../workArea/drawerTerminals.logic.test.ts | 60 + .../fork/workArea/drawerTerminals.logic.ts | 38 + .../src/fork/workArea/drawerTerminals.test.ts | 103 ++ apps/web/src/fork/workArea/drawerTerminals.ts | 111 ++ .../src/fork/workArea/dropPlan.logic.test.ts | 154 ++ apps/web/src/fork/workArea/dropPlan.logic.ts | 165 ++ .../src/fork/workArea/linkDrop.logic.test.ts | 18 + apps/web/src/fork/workArea/linkDrop.logic.ts | 18 + .../linkSources.test.ts | 28 +- .../linkSources.ts | 58 +- .../web/src/fork/workArea/miniPlayerFollow.ts | 127 ++ apps/web/src/fork/workArea/panelLinkDrag.css | 11 + .../panelLinkDrag.ts | 7 +- .../src/fork/workArea/retiredCommands.test.ts | 36 + apps/web/src/fork/workArea/retiredCommands.ts | 11 + .../tabPress.browser.test.tsx | 0 .../tabStrip.tsx | 113 +- .../src/fork/workArea/threadDragFallback.ts | 51 + .../fork/workArea/threadLink.logic.test.ts | 88 ++ .../web/src/fork/workArea/threadLink.logic.ts | 57 + .../workArea/threadWorkspace.logic.test.ts | 36 + .../fork/workArea/threadWorkspace.logic.ts | 20 + apps/web/src/fork/workArea/useLinkDrops.ts | 99 ++ .../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 | 1374 +++++++++++++++++ apps/web/src/fork/workArea/workArea.logic.ts | 535 +++++++ .../web/src/fork/workArea/workAreaCommands.ts | 125 ++ .../fork/workArea/workAreaFloat.logic.test.ts | 293 ++++ .../src/fork/workArea/workAreaFloat.logic.ts | 61 + .../fork/workArea/workAreaGeometry.logic.ts | 437 ++++++ .../fork/workArea/workAreaPlacement.logic.ts | 1108 +++++++++++++ .../workArea/workAreaStorage.logic.test.ts | 357 +++++ .../fork/workArea/workAreaStorage.logic.ts | 294 ++++ .../fork/workArea/workAreaStore.logic.test.ts | 287 ++++ .../fork/workArea/workAreaTabs.logic.test.ts | 469 ++++++ apps/web/src/fork/workArea/workAreaTestKit.ts | 68 + apps/web/src/fork/workArea/workAreaView.ts | 205 +++ ...useRightPanelSurfaceClose.browser.test.tsx | 13 +- .../src/hooks/useRightPanelSurfaceClose.ts | 15 +- .../useThreadActions.permissions.test.ts | 16 +- apps/web/src/lib/openPullRequestLink.ts | 18 +- apps/web/src/lib/revealThreadTerminal.ts | 4 +- apps/web/src/lib/sideChatPane.ts | 9 +- apps/web/src/lib/workspaceFocus.ts | 6 +- apps/web/src/reopenClosedView.test.ts | 59 - apps/web/src/rightPanelStore.test.ts | 183 +-- apps/web/src/rightPanelStore.ts | 151 +- apps/web/src/state/server.ts | 3 +- apps/web/test/fakeEnvironment.ts | 3 + 135 files changed, 11329 insertions(+), 4863 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/PanelLinkDropScope.tsx 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/linkDrop.logic.test.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/linkDrop.logic.ts delete mode 100644 apps/web/src/fork/rightPanelSplit/panelLinkDrag.css 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 rename apps/web/src/fork/{rightPanelSplit => workArea}/chatAnchorLink.ts (76%) 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/drawerTerminals.logic.test.ts create mode 100644 apps/web/src/fork/workArea/drawerTerminals.logic.ts create mode 100644 apps/web/src/fork/workArea/drawerTerminals.test.ts create mode 100644 apps/web/src/fork/workArea/drawerTerminals.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/linkDrop.logic.test.ts create mode 100644 apps/web/src/fork/workArea/linkDrop.logic.ts rename apps/web/src/fork/{rightPanelSplit => workArea}/linkSources.test.ts (85%) rename apps/web/src/fork/{rightPanelSplit => workArea}/linkSources.ts (67%) create mode 100644 apps/web/src/fork/workArea/miniPlayerFollow.ts create mode 100644 apps/web/src/fork/workArea/panelLinkDrag.css rename apps/web/src/fork/{rightPanelSplit => workArea}/panelLinkDrag.ts (93%) create mode 100644 apps/web/src/fork/workArea/retiredCommands.test.ts create mode 100644 apps/web/src/fork/workArea/retiredCommands.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/useLinkDrops.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/workAreaFloat.logic.test.ts create mode 100644 apps/web/src/fork/workArea/workAreaFloat.logic.ts create mode 100644 apps/web/src/fork/workArea/workAreaGeometry.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 45a1770d1200c..3b4222b89623e 100644 --- a/README.md +++ b/README.md @@ -13,8 +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. -- **Drag links into the right panel:** drag a file from the Files tree, or a link from a chat message, onto a right-panel pane to open it there. Supported chat links are file, pull request, issue, thread, `board://`, Dashboard, and web links. Drop the item on a tab strip to open it at that spot. Drop the item on the left or right third of a single pane to split the panel on that side when there is room. If the item is already open in the other pane, the drop moves its tab to where you dropped it. A dropped file keeps a standalone Files tab open beside it. A plain click on a file still replaces the Files tab. A full pull request or issue URL opens as a pull request or issue tab when a click opens that kind of tab. Other web links, and pull request or issue links that do not, drag whenever the preview browser is available. Dropping one opens it in the preview browser, even when a plain click opens it in your system browser. Without a preview browser, those links do not drag to the panel. Folder rows in the Files tree, short references like `#42`, commit links, and web image and video URLs do not drag to the panel. A chat file link drags whenever a click opens it in the panel. A dropped file link opens what its click opens, in the pane you chose. It can open a workspace folder or a workspace image or video file. Dragging a Files row to a message box still adds an `@mention`. In the desktop app on Mac and Windows, file links in chat still drag out as files instead of dropping on the panel. +- **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. 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 the divider to reset its size. Closing a pane's last tab closes the pane. Any pane with a message box (a Chat tab, a reply tab, or a side-thread tab) stays at least 360 px wide. Drag a same-project thread from the thread list into the area to open its chat as another Chat tab. File links in that chat open that thread's file as a tab beside it. You cannot drop another project's thread 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, and opens a thread of another project or environment 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, "N replies" on a message, or a sub-thread in the Replies list opens that sub-thread as its own tab. Opening one from the Replies list places it next to the list. Each thread keeps its own layout. The last Chat tab cannot close. Closing the selected thread's Chat removes 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. No tab is ever hidden except a browser or device tab playing in the floating mini player, a small floating window over the chat. "Preview: Toggle", picture-in-picture, and a device's Float move the tab into the mini player and keep the session. Closing the mini player, choosing "Open in panel", or using "Preview: Toggle" again puts the tab back in its pane. If the window or layout stops showing the Chat that holds the mini player, the tab goes back to its pane and the mini player closes. "Preview: Toggle" on an empty browser tab (a New tab page with no page loaded) closes that tab. "Diff: Toggle" closes the Diff tab when it is shown and opens it when it is not. Reopen Closed View can bring back a closed Diff tab. There is no terminal drawer under the Chat. Every terminal is a terminal tab in a pane. Project scripts and the Run button on a chat code block run in an idle terminal tab, or open a new terminal tab. A terminal that the server already runs for the thread (such as a worktree setup shell) shows as a background tab. "Terminal: Toggle" (Cmd+J or Ctrl+J) is gone, including from Settings → Keybindings. Split, new, and close terminal shortcuts act on the focused terminal tab. Drag a file from the Files tree, or a link from a chat message, onto a pane to open it there. Supported chat links are file, pull request, issue, thread, `board://`, Dashboard, and web links. Drop the item on a tab strip to open it at that spot, on one of a pane's four edges to split that side, or on the middle to add it to that pane. If the item is already open in another pane, the drop moves its tab there. If you press a key or click before a slow drop finishes opening, the item opens where a click would instead. A dropped file keeps a standalone Files tab open beside it. A plain click on a file still replaces the Files tab. A full pull request or issue URL opens as a pull request or issue tab when a click opens that kind of tab. Other web links, and pull request or issue links that do not open that kind of tab, drag whenever the preview browser is available. A drop opens those links in the preview browser even when a click opens them in the system browser. Without a preview browser, those links do not drag. Folder rows in the Files tree, short references like `#42`, commit links, and web image and video URLs do not drag. A chat file link drags whenever a click opens it in the work area. A dropped file link opens what its click opens, in the pane you chose, so it can open a workspace folder or a workspace image or video file. Dragging a Files row to a message box still adds an `@mention`. In the desktop app on Mac and Windows, file links in chat still drag out as files instead of dropping on a pane. - 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 571338c027b94..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, @@ -64,11 +65,10 @@ export async function openUrlInPreview(input: { readonly openPreview: OpenPreviewMutation; readonly profileId?: PreviewOpenInput["profileId"]; readonly background?: boolean; - /** Runs right after the panel opens the tab, in the same task as that write. */ - readonly onOpened?: () => void; }): 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 }), ); @@ -109,8 +109,7 @@ export async function openUrlInPreview(input: { return; } applyPreviewServerSnapshot(threadRef, snapshot); - useRightPanelStore.getState().openBrowser(threadRef, snapshot.tabId); - input.onOpened?.(); + fromOrigin(() => useRightPanelStore.getState().openBrowser(threadRef, snapshot.tabId)); }); } @@ -140,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({ @@ -161,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 9931a29eaad91..70266cdffb28d 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -103,9 +103,8 @@ import type { } from "react-markdown"; import { createIncrementalMarkdownPlugin } from "../markdown-incremental"; import { postWhiteboardHover, remarkWhiteboardLinks } from "../fork/whiteboard/markdown-whiteboard"; -import { chatAnchorPanelLinks } from "../fork/rightPanelSplit/chatAnchorLink"; -import { openedSync } from "../fork/rightPanelSplit/linkSources"; -import { type OpenedSurface, startPanelLinkDrag } from "../fork/rightPanelSplit/panelLinkDrag"; +import { chatAnchorPanelLinks } from "../fork/workArea/chatAnchorLink"; +import { startPanelLinkDrag } from "../fork/workArea/panelLinkDrag"; import { showBoardRef } from "../fork/whiteboard/boardChannel"; import { remarkEndLinksAtCjkPunctuation } from "../fork/cjkLinkEnd"; import { DashboardLinkChip, parseDashboardHref } from "../fork/dashboard/dashboardLink"; @@ -180,7 +179,8 @@ import { appAtomRegistry } from "../rpc/atomRegistry"; import { hostEnvironmentIdAtom } from "../state/primaryEnvironment"; import { cn } from "../lib/utils"; import { resolveRemoteOpenState, useRemoteOpenResolution } from "../remoteOpen"; -import { type OpenFileOptions, rightPanelHostRef, useRightPanelStore } from "../rightPanelStore"; +import { type OpenFileOptions, 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"; @@ -622,6 +622,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); @@ -636,6 +637,7 @@ function useChatMarkdownState({ clickedImage?: HTMLImageElement | null, ) => { const requestId = ++mediaRequestId.current; + const fileTarget = fileOpener?.(); void resolveMarkdownMediaPreview({ source, resolvedFilePath, @@ -646,9 +648,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) { @@ -797,7 +797,7 @@ function useChatMarkdownState({ if (!readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope)) return; await pullRequestLinking.changeLink(threadRef, href, linked); }; - const openExternalLinkInPreview = (url: string, onOpened?: () => void) => { + const openExternalLinkInPreview = (url: string) => { if (!threadRef || !canOperatePreview) { return Promise.resolve( AsyncResult.failure( @@ -809,8 +809,10 @@ function useChatMarkdownState({ ), ); } - const opened = onOpened ? { onOpened } : {}; - return openUrlInPreview({ threadRef, url, openPreview, ...opened }).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); @@ -829,13 +831,14 @@ function useChatMarkdownState({ }; const anchorPanelLink = chatAnchorPanelLinks({ threadRef, + opener: fileOpener, canOperatePreview, issueTrackers, openChangeRequestLink, openIssueLink, openExternalLinkInPreview, }); - 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( @@ -856,7 +859,7 @@ function useChatMarkdownState({ createAssetUrl, openPreview, }); - }; + }); const findWorkspaceFileMatch = async (fileLinkMeta: MarkdownFileLinkMeta) => { const workspaceRelativePath = fileLinkMeta.workspaceLookupPath; if ( @@ -934,12 +937,10 @@ function useChatMarkdownState({ fileLinkMeta: MarkdownFileLinkMeta, panelPath: string, ...options: [OpenFileOptions?] - ): OpenedSurface | Promise => { - if (!threadRef) return null; - const openAt = (path: string) => - openedSync(rightPanelHostRef(threadRef), () => - useRightPanelStore.getState().openFile(threadRef, path, fileLinkMeta.line, ...options), - ); + ) => { + const fileTarget = fileOpener?.(); + if (!threadRef || !fileTarget) return; + const openAt = (path: string) => fileTarget.openFile(path, fileLinkMeta.line, ...options); if ( fileLinkMeta.workspaceLookupPath === null || !cwd || @@ -948,17 +949,17 @@ function useChatMarkdownState({ return openAt(panelPath); } // 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); return (async () => { const match = await findWorkspaceFileMatch(fileLinkMeta); if ( - scopedThreadKey(rightPanelHostRef(threadRef)) !== panelKey || + scopedThreadKey(fileTarget.panel()) !== panelKey || useRightPanelStore.getState().getUserActionRevision(panelRef) !== userActionRevision ) - return null; - return openAt(match ?? panelPath); + return; + openAt(match ?? panelPath); })(); }; const fileLinkChip = ( @@ -1101,6 +1102,7 @@ function useChatMarkdownState({ issuesEnabled, skills, threadRef, + fileOpener, updateThreadPullRequestLink, }; return { @@ -1258,6 +1260,7 @@ const CHAT_MARKDOWN_COMPONENTS = { imageBaseDir, markdownFileLinkMetaByHref, threadRef, + fileOpener, openMarkdownMedia, openChangeRequestLink, openIssueLink, @@ -1385,7 +1388,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) { @@ -1416,8 +1420,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; } @@ -1534,7 +1542,7 @@ const CHAT_MARKDOWN_COMPONENTS = { originalUrl={href} target={pullRequestPreviewTarget} confirmBeforeOpen={confirmBeforeOpen} - onOpenPullRequest={(targetUrl) => + onOpenPullRequest={inChatOrigin(fileOpener, (targetUrl: string) => openChangeRequestLink( { metaKey: false, @@ -1545,10 +1553,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, @@ -1561,7 +1569,7 @@ const CHAT_MARKDOWN_COMPONENTS = { issueTrackers, ); if (!opened) await openDeferredMarkdownLink(url); - }} + })} fallback={ issuePreviewTarget === null ? undefined : ( @@ -1650,6 +1658,7 @@ const CHAT_MARKDOWN_COMPONENTS = { sourceControlMediaRepository, imageBaseDir, threadRef, + fileOpener, workspaceMutationId, renderContextReference, fileLinkChip, @@ -1698,7 +1707,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 acde0756bdb72..1c0a8286875d7 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -232,7 +232,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 { useWorktreeRepositoryChoices } from "../hooks/useWorktreeRepositoryChoices"; import { useRememberedWorktreeRepositories } from "../worktreeRepositoryChoiceStore"; @@ -318,13 +318,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"; @@ -392,9 +386,13 @@ 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 { openInFileTab } from "../fork/workArea/workArea.logic"; +import { useWorkAreaChat } from "../fork/workArea/workAreaView"; +import { closeFocusedTab } 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"; @@ -474,7 +472,6 @@ export default function ChatView(props: ChatViewProps) { threadId, routeKind, onDiffPanelOpen, - reserveTitleBarControlInset = true, forceExpandedMobileComposer = false, embedded: parentPanel, } = props; @@ -938,6 +935,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"); @@ -947,6 +946,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), @@ -958,7 +958,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 }; @@ -966,11 +966,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), }); }, }; @@ -985,6 +985,7 @@ export default function ChatView(props: ChatViewProps) { ? {} : { open: (): void => { + if (openThreadTab(fileOpener, parentRef)) return; void navigate({ to: "/$environmentId/$threadId", params: buildThreadRouteParams(parentRef), @@ -1068,7 +1069,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, @@ -1146,39 +1146,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, activeThreadRef); 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); @@ -1202,11 +1179,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 @@ -1608,7 +1584,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; } }; @@ -2142,13 +2118,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, @@ -2499,17 +2468,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, @@ -2558,6 +2524,7 @@ export default function ChatView(props: ChatViewProps) { shortcuts: threadLifecycleShortcuts, } = useThreadLifecycle({ environmentId, + openThreadTabs: fileOpener, routeThreadKey, currentRouteThreadKeyRef, canOperateThread, @@ -2927,26 +2894,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. @@ -3461,24 +3420,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, @@ -3497,15 +3438,15 @@ export default function ChatView(props: ChatViewProps) { state={deviceState} /> )} - {rightPanelControlsAtRoot && !embedded ? panelLayoutControls : null}
{embedded ? null : ( @@ -3515,24 +3456,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} @@ -4216,7 +4130,6 @@ export default function ChatView(props: ChatViewProps) { onCloseOtherSurfaces={closeOtherRightPanelSurfacesStable} onCloseSurfacesToRight={closeRightPanelSurfacesToRightStable} onCloseAllSurfaces={closeAllRightPanelSurfacesStable} - onMoveSurface={moveRightPanelSurfaceStable} onCopyFilePath={copyRightPanelFilePathStable} onAddBrowser={() => createBrowserSurface()} onAddBrowserInProfile={createBrowserSurfaceStable} @@ -4238,9 +4151,6 @@ export default function ChatView(props: ChatViewProps) { deviceAvailable={activeThreadRef !== null} sideChatAvailable={sideChat.available} sideChatDisabledReason={sideChatDisabledReason} - threadRef={activeThreadRef} - split={rightPanelPresence.value?.split} - renderSurface={renderRightPanelSurface} /> ) : null} @@ -4266,7 +4176,9 @@ export default function ChatView(props: ChatViewProps) { checkpoints={serverProjection?.checkpoints} checkpointScopes={serverProjection?.checkpointScopes} > - {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 146035011f07e..3184ecbb574cb 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -126,7 +126,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"; @@ -295,33 +296,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 45db35ed3494d..34963cd73af99 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 : ( (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); @@ -1213,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(() => { @@ -1345,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(); @@ -1355,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); @@ -1404,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") { @@ -1450,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(); @@ -1459,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); @@ -1514,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 ? ( useRightPanelStore.getState().close(firstRef)); + // The work area hides no tab on close, so the browser tab itself goes. + await act(() => useRightPanelStore.getState().closeSurface(firstRef, "browser:new")); await press(); await vi.waitFor(() => expect(router.history.location.pathname).toBe(`/${ENVIRONMENT_ID}/${second.id}`), diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index d01651f04e2b3..681c6189fa57e 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -1806,7 +1806,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threads = contextDragThreads(); const threadRef = parseScopedThreadKey(contextDragKeyRef.current ?? ""); const title = (threadRef && readThreadShell(threadRef)?.title.trim()) || gt("Thread"); - moveThreadContextDragGhost(point, { title, count: threads.length }); + moveThreadContextDragGhost(point, { title, count: threads.length }, threads); return true; }; const dropThreadContextDrag = (point: { x: number; y: number }) => { diff --git a/apps/web/src/components/ThreadContextChip.tsx b/apps/web/src/components/ThreadContextChip.tsx index adb0008a07530..c9d426c958fda 100644 --- a/apps/web/src/components/ThreadContextChip.tsx +++ b/apps/web/src/components/ThreadContextChip.tsx @@ -3,8 +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 type { DragEventHandler } from "react"; +import { type DragEventHandler, 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"; @@ -40,6 +41,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 1e3ffb8357a15..5042bf45ed673 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 { fromChatOrigin, useChatFileOpener } from "~/fork/workArea/chatFileOpener"; import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste"; import { questionAttachmentDraftId, @@ -741,6 +741,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) const nonPersistedComposerImageIds = attachmentDraft.nonPersistedImageIds; const uploadsByImageId = useAttachmentUploadStore((state) => state.uploadsByImageId); const openPrLink = useOpenPrLink(routeThreadRef); + const chatOpener = useChatFileOpener(routeThreadRef); const [previewFileId, setPreviewFileId] = useState(null); const previewFile = composerFiles.find((file) => file.id === previewFileId); const composerContextActions = { @@ -756,7 +757,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) => chatOpener?.().openMention(path), expandVideo: (fileId: string) => { const file = composerFiles.find((candidate) => candidate.id === fileId); if (!file || !isVideoAttachment(file)) return; @@ -778,7 +779,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) if (persistedPreview) onExpandImage(persistedPreview); }, openPullRequest: (event: React.MouseEvent, url: string) => { - openPrLink(event, url); + fromChatOrigin(chatOpener, () => openPrLink(event, url)); }, }; const composerContextRecords = composerContextRecordsFromDraft({ 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/MarkdownFileLink.tsx b/apps/web/src/components/chat/MarkdownFileLink.tsx index b4e514e1fea23..a2e0e581ffbd7 100644 --- a/apps/web/src/components/chat/MarkdownFileLink.tsx +++ b/apps/web/src/components/chat/MarkdownFileLink.tsx @@ -17,8 +17,8 @@ import { leavesFileChipClickToBrowser, runHostFileLinkMenuItem, } from "../../fork/hostFileLinks"; -import { fileChipPanelLink } from "../../fork/rightPanelSplit/linkSources"; -import { type OpenedSurface, startPanelLinkDrag } from "../../fork/rightPanelSplit/panelLinkDrag"; +import { fileChipPanelLink } from "../../fork/workArea/linkSources"; +import { startPanelLinkDrag } from "../../fork/workArea/panelLinkDrag"; import { readLocalApi } from "../../localApi"; import { cn } from "../../lib/utils"; import { shouldOpenMarkdownFileLinkInEditor } from "../../markdown-links"; @@ -52,12 +52,11 @@ interface MarkdownFileLinkProps { theme: "light" | "dark"; threadRef?: ScopedThreadRef | undefined; onOpen?: (() => Promise>) | undefined; - /** The surface it opened in the panel, or null. */ onOpenInPanel: ( panelPath: string, line: number | undefined, options?: OpenFileOptions, - ) => OpenedSurface | Promise; + ) => void | Promise; resolveDragPath: () => Promise; resolveCopyPaths: () => Promise>; openInEditorMenuLabel: string; diff --git a/apps/web/src/components/chat/MarkdownThreadLink.browser.test.tsx b/apps/web/src/components/chat/MarkdownThreadLink.browser.test.tsx index b44f72bea0e90..c8e195973f765 100644 --- a/apps/web/src/components/chat/MarkdownThreadLink.browser.test.tsx +++ b/apps/web/src/components/chat/MarkdownThreadLink.browser.test.tsx @@ -21,7 +21,9 @@ const state = vi.hoisted(() => ({ linked: new Map(), connected: [] as Array, })); -vi.mock(import("../../state/entities"), () => ({ +// The work area's chat openers read the rest of these modules. +vi.mock(import("../../state/entities"), async (importOriginal) => ({ + ...(await importOriginal()), useThreadShell: ((ref: { environmentId: string } | null) => ref?.environmentId === "remote" ? state.remote @@ -35,7 +37,8 @@ vi.mock(import("../../state/entities"), () => ({ useProject: (ref: { projectId: string } | null) => ref?.projectId === "essay-project" ? ({ title: "Essays" } as never) : null, })); -vi.mock(import("../../state/environments"), () => ({ +vi.mock(import("../../state/environments"), async (importOriginal) => ({ + ...(await importOriginal()), // The click rule reads the client setting, whose module asks for these. useEnvironments: (() => []) as never, usePrimaryEnvironment: (() => null) as never, diff --git a/apps/web/src/components/chat/MarkdownThreadLink.tsx b/apps/web/src/components/chat/MarkdownThreadLink.tsx index 8209a36c9a482..bc81bcb831a56 100644 --- a/apps/web/src/components/chat/MarkdownThreadLink.tsx +++ b/apps/web/src/components/chat/MarkdownThreadLink.tsx @@ -1,5 +1,6 @@ import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts"; import { useNavigate } from "@tanstack/react-router"; +import { use } from "react"; import { useGT, useMessages } from "gt-react"; import { MessagesSquareIcon } from "lucide-react"; import { @@ -11,8 +12,9 @@ import { import { unknownThreadLinkLabel } from "@t3tools/shared/threadLinksCopy"; import { resolveLinkedThreadOpen } from "@t3tools/client-runtime/linked-thread"; -import { threadChipPanelLink } from "../../fork/rightPanelSplit/linkSources"; -import { startPanelOnlyDrag } from "../../fork/rightPanelSplit/panelLinkDrag"; +import { ChatOpenerContext } from "../../fork/workArea/chatOpenerContext"; +import { threadChipPanelLink } from "../../fork/workArea/linkSources"; +import { startPanelOnlyDrag } from "../../fork/workArea/panelLinkDrag"; import { configuredHostedAppUrl } from "../../hostedPairing"; import { useThreadRefs, useThreadShell } from "../../state/entities"; import { useConnectedEnvironmentIds, useEnvironmentIdentities } from "../../state/environments"; @@ -38,6 +40,7 @@ export function MarkdownThreadLink(props: { const messages = useMessages(); const navigate = useNavigate(); const trigger = useSideThreadTrigger(); + const opener = use(ChatOpenerContext); const panelRef = props.threadRef ?? null; const candidates = threadLinkCandidates(props.link, props.environmentId); const writtenRef = candidates[0]!; @@ -111,6 +114,7 @@ export function MarkdownThreadLink(props: { threadChipPanelLink({ threadRef: props.threadRef, target: { kind: "linked", target: linkedTarget }, + opener, }), ) } @@ -156,7 +160,11 @@ export function MarkdownThreadLink(props: { ? (event) => startPanelOnlyDrag( event, - threadChipPanelLink({ threadRef: props.threadRef, target: { kind: "local", ref } }), + threadChipPanelLink({ + threadRef: props.threadRef, + target: { kind: "local", ref }, + opener, + }), ) : undefined } 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={