Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(desktop): universal chat drawer on a shared right-rail shell

Diego Zacarias0f0c817571b6
diff --git a/desktop-app/test/browser/chatDrawerHeaderStacking.browser.test.ts b/desktop-app/test/browser/chatDrawerHeaderStacking.browser.test.ts
index d2011cfed..3105444ec 100644
--- a/desktop-app/test/browser/chatDrawerHeaderStacking.browser.test.ts
+++ b/desktop-app/test/browser/chatDrawerHeaderStacking.browser.test.ts
@@ -34,7 +34,14 @@ async function mountPortalEraShell(page: Page, drawerOpen: boolean): Promise<voi
</header>
<div class="app-root">
<section class="content-panel${drawerOpen ? ' content-panel--chat-drawer-open' : ''}">
- ${drawerOpen ? '<aside class="chat-drawer is-ready">Chat drawer</aside>' : ''}
+ ${
+ drawerOpen
+ ? // Mirror App's real render: the drawer lives inside the fixed
+ // right-rail shell, which owns the z-index that keeps the
+ // portalled titlebar search above it (mini-spec 04a §B).
+ '<div class="right-rail-shell" data-occupant="chat-drawer"><aside class="chat-drawer is-ready">Chat drawer</aside></div>'
+ : ''
+ }
</section>
</div>
</div>
diff --git a/desktop-app/test/browser/newChatComposerGutter.browser.test.ts b/desktop-app/test/browser/newChatComposerGutter.browser.test.ts
index 061b0c8cd..b2e3edec0 100644
--- a/desktop-app/test/browser/newChatComposerGutter.browser.test.ts
+++ b/desktop-app/test/browser/newChatComposerGutter.browser.test.ts
@@ -54,12 +54,17 @@ async function landingGeometry(
`
if (options.drawerWidth) {
- // The drawer mounts the SAME ChatPage landing inside a fixed right rail.
+ // The drawer mounts the SAME ChatPage landing inside the fixed right-rail
+ // shell (mini-spec 04a §B): the shell owns the rail width via `--rail-width`
+ // and the drawer fills it — mirror that structure so the measured geometry
+ // matches App's real render.
await page.setContent(`
- <div class="chat-drawer is-ready" style="--chat-drawer-width: ${options.drawerWidth}px">
- <div class="chat-drawer__resize-handle" role="separator"></div>
- <header class="chat-drawer__header"><div class="chat-drawer__header-main">drawer</div></header>
- <div class="chat-drawer__surface">${landing}</div>
+ <div class="right-rail-shell" data-occupant="chat-drawer" style="--rail-width: ${options.drawerWidth}px">
+ <div class="chat-drawer is-ready">
+ <div class="chat-drawer__resize-handle" role="separator"></div>
+ <header class="chat-drawer__header"><div class="chat-drawer__header-main">drawer</div></header>
+ <div class="chat-drawer__surface">${landing}</div>
+ </div>
</div>
`)
} else {
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 5c7c01749..700ffb9a3 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -21,6 +21,7 @@ import { ConfirmDialog } from '@components/ConfirmDialog'
import { GfsImagePreview } from '@components/GfsImagePreview'
import { PluginConsentModal } from '@components/PluginConsentModal'
import type { PluginConsentRequest } from '@components/PluginConsentModal/types'
+import { RightRailShell } from '@components/RightRailShell'
import { SidebarNav } from '@components/SidebarNav'
import { TitlebarActionsPortal, WindowTitleBar } from '@components/WindowTitleBar'
import { WorkspaceTabStrip } from '@components/WorkspaceTabStrip'
@@ -28,7 +29,11 @@ import { DESKTOP_ROUTES, SIDEBAR_COLLAPSED_KEY } from '@constants/navigation'
import { THEME_STORAGE_KEY } from '@constants/theme'
import { useAgentChatActionsValue } from '@hooks/useAgentChatActionsValue'
import { useAppController } from '@hooks/useAppController'
-import { useChatDrawerResize } from '@hooks/useChatDrawerResize'
+import {
+ CHAT_DRAWER_DOM_FLOOR,
+ CHAT_DRAWER_EMBED_FLOOR,
+ useChatDrawerResize,
+} from '@hooks/useChatDrawerResize'
import { useWindowFocusBridge } from '@hooks/useWindowFocusBridge'
import type { ChatLocalMatch } from '@lib/chatLocalSearch'
import { buildLoadedChatSemanticModels } from '@lib/chatMessageSemantics'
@@ -390,6 +395,13 @@ export function App() {
}
return
}
+ // R4 (mini-spec 04a §D): revealing a chat tab full-screen collapses the
+ // drawer BEFORE the chat shows. Effective visibility already drops this
+ // commit because `drawerAvailable` goes false once a chat tab is active;
+ // clearing the open INTENT here keeps the drawer from silently re-opening
+ // when the user later returns to a non-chat tab (going to a chat is an
+ // explicit focus change; R5's "intact" only spans non-chat ↔ non-chat).
+ setChatDrawerOpen(false)
leaveSandboxForChat()
if (agentRef) {
vm.handleSelectChatAgent(
@@ -616,32 +628,60 @@ export function App() {
const isAgentChatView =
(vm.navItem === DESKTOP_ROUTES.agents && Boolean(vm.selectedAgent)) ||
(vm.navItem === DESKTOP_ROUTES.chat && Boolean(vm.selectedAgent))
- // The chat drawer coexists with the live app only on the `apps` route. It is
- // an orthogonal boolean axis over the universal store's chat sub-slice /
+ // Universal drawer availability (R2, mini-spec 04a §D): the chat drawer is
+ // available over ANY non-chat tab (app, files, settings), never on a chat tab
+ // (the chat is already the tab's content). An empty workspace (no active tab)
+ // maps to the chat home, so it is not available there either. It is an
+ // orthogonal boolean axis over the universal store's chat sub-slice /
// <ChatPage> — never a second tab store, never a foreground/background module.
- const chatDrawerAvailable = vm.navItem === DESKTOP_ROUTES.apps && Boolean(activeSandboxUiApp)
+ const drawerAvailable =
+ vm.activeWorkspaceTab !== undefined && vm.activeWorkspaceTab.kind !== 'chat'
+ // The drawer coexists with a NATIVE app embed only on the live `apps` route.
+ // This narrower predicate keeps the embed-specific machinery (anti-flash
+ // bounds gate, embed-measured top, wider content floor) scoped to app tabs; on
+ // DOM tabs (files/settings/apps-picker) there is no embed to ack or measure.
+ const drawerHasEmbed = vm.navItem === DESKTOP_ROUTES.apps && Boolean(activeSandboxUiApp)
// Intention (what the user asked for) is kept separate from effective
- // visibility. `chatDrawerDesired` is the user's open intent on an app-live
- // route; below the minimum panel width the drawer can't coexist with the embed
+ // visibility. `chatDrawerDesired` is the user's open intent on a drawer-capable
+ // tab; below the minimum panel width the drawer can't coexist with the content
// so it is SUPPRESSED — hidden without clearing the intent — and reappears on
// re-widen. A manual close flips `chatDrawerOpen`, so it stays closed. The
// resize hook measures the panel while the drawer is DESIRED (not only while
// visible) so it can observe the re-widen; `panelTooNarrow` comes from that
// measurement, and visibility derives from it — no dependency cycle with the
// hook's `active` input, which is the desire alone.
- const chatDrawerDesired = chatDrawerAvailable && chatDrawerOpen
- // Session-only drawer sizing (always docked beside the native embed). Width is
+ const chatDrawerDesired = drawerAvailable && chatDrawerOpen
+ // Per-kind content floor (§A3): app tabs reserve the embed's legible floor; DOM
+ // tabs reserve a smaller floor, so a chat+DOM split survives narrower windows.
+ const drawerContentFloor = drawerHasEmbed ? CHAT_DRAWER_EMBED_FLOOR : CHAT_DRAWER_DOM_FLOOR
+ // Session-only drawer sizing (always docked beside the tab content). Width is
// not persisted by design; it resets to the default each launch.
- const chatDrawerResize = useChatDrawerResize(contentPanelRef, chatDrawerDesired)
+ const chatDrawerResize = useChatDrawerResize(
+ contentPanelRef,
+ chatDrawerDesired,
+ drawerContentFloor
+ )
const chatDrawerVisible = chatDrawerDesired && !chatDrawerResize.panelTooNarrow
// Can a gesture be diverted INTO the drawer right now? Only if it is a valid
- // surface: app live AND wide enough to render. Kept SEPARATE from the hook's
- // `active` input on purpose — folding `!panelTooNarrow` into `chatDrawerAvailable`
- // or `chatDrawerDesired` would stop the ResizeObserver from observing the
- // re-widen, turning "suppressed" into "never returns".
- const chatDrawerDivertable = chatDrawerAvailable && !chatDrawerResize.panelTooNarrow
+ // surface: drawer available AND wide enough to render. Kept SEPARATE from the
+ // hook's `active` input on purpose — folding `!panelTooNarrow` into
+ // `drawerAvailable` or `chatDrawerDesired` would stop the ResizeObserver from
+ // observing the re-widen, turning "suppressed" into "never returns".
+ const chatDrawerDivertable = drawerAvailable && !chatDrawerResize.panelTooNarrow
chatDrawerVisibleRef.current = chatDrawerVisible
chatDrawerDivertableRef.current = chatDrawerDivertable
+ // Effective ready gate (§A2): app tabs wait for the embed's bounds ack
+ // (`chatDrawerReady`, flipped by handleSandboxUiBoundsApplied); DOM tabs are
+ // ready the moment they are visible — no native view paints over them and the
+ // drawer + content layout in the same frame. Derived (NOT an effect) so a DOM
+ // tab is ready in the SAME commit as visibility: no post-paint flip, no
+ // flicker, and never the "inert forever" trap where a DOM tab waits for a
+ // bounds ack that never arrives.
+ const drawerReady = drawerHasEmbed ? chatDrawerReady : chatDrawerVisible
+ // The rail follows the embed's measured header top only on app tabs; DOM tabs
+ // pass null so the shell uses its static CSS fallback (§A2 — never consume an
+ // embed measurement that will not arrive on a DOM tab).
+ const drawerRailTop = drawerHasEmbed ? chatDrawerEmbedTop : null
// The notification tray's drawer form occupies the same fixed right-rail rect
// as the chat drawer, so it only takes drawer form when the chat drawer is NOT
// visible; while the chat drawer is up it reverts to its popover/overlay form
@@ -891,11 +931,11 @@ export function App() {
// until the embed acks its shrunk bounds, and a `focus()` fired while inert is a
// silent no-op, so bumping on visibility alone would open the switcher unfocused.
React.useEffect(() => {
- if (chatDrawerVisible && chatDrawerReady && pendingChatSwitcherFocusRef.current) {
+ if (chatDrawerVisible && drawerReady && pendingChatSwitcherFocusRef.current) {
pendingChatSwitcherFocusRef.current = false
setChatSwitcherFocusRequestId(value => value + 1)
}
- }, [chatDrawerVisible, chatDrawerReady])
+ }, [chatDrawerVisible, drawerReady])
const handleSandboxUiBoundsApplied = React.useCallback(() => {
if (appNotificationDrawerOpen) setNotificationDrawerReady(true)
@@ -2155,16 +2195,11 @@ export function App() {
}${chatDrawerVisible ? ' content-panel--chat-drawer-open' : ''}`}
style={
chatDrawerVisible
- ? {
- '--chat-drawer-width': `${chatDrawerResize.width}px`,
- // Only publish the measured top once we have one;
- // when unmeasured (null, pre-measure/tests) the CSS
- // fallback applies. Uses null — not 0 — so a legitimate
- // rect.top of 0/negative still follows the embed.
- ...(chatDrawerEmbedTop !== null
- ? { '--chat-drawer-top': `${chatDrawerEmbedTop}px` }
- : {}),
- }
+ ? // Only `--chat-drawer-width` lives here now: it feeds the
+ // universal tab-area gutter (`--app-header-utilities-width`).
+ // The rail's top/width are published by the RightRailShell
+ // itself (`--rail-*`), not inherited from the panel.
+ { '--chat-drawer-width': `${chatDrawerResize.width}px` }
: undefined
}
>
@@ -2186,6 +2221,9 @@ export function App() {
}
onNotificationTrayOpenChange={setHeaderNotificationTrayOpen}
onShellOverlayOpenChange={setHeaderShellOverlayOpen}
+ drawerAvailable={drawerAvailable}
+ chatDrawerOpen={chatDrawerVisible}
+ onToggleChatDrawer={toggleChatDrawer}
/>
</TitlebarActionsPortal>
<ToastStack items={vm.toasts} />
@@ -2252,63 +2290,30 @@ export function App() {
{vm.navItem === DESKTOP_ROUTES.connectors && <McpServersPage />}
{vm.navItem === DESKTOP_ROUTES.plugins && <WorkflowsPage />}
{vm.navItem === DESKTOP_ROUTES.apps && (
- <>
- <SandboxUiPage
- boundsRefreshKey={sandboxUiBoundsRefreshKey}
- actionRequest={sandboxActionRequest}
- conversationOrigin={sandboxUiConversationOrigin}
- currentTeamId={vm.currentTeamId}
- headerShellOverlayOpen={
- headerShellOverlayOpen || commandPaletteOpen
- }
- sidebarShellOverlayOpen={sidebarSettingsMenuOpen}
- toastShellOverlayOpen={vm.toasts.length > 0}
- deepLinkShellOverlayOpen={sandboxUiDeepLinkDialog !== null}
- shortcutApp={activeSandboxUiApp}
- shortcutOpenRequestId={sandboxUiShortcutOpenRequestId}
- localSearchRequestId={sandboxLocalSearchRequestId}
- chatDrawerOpen={chatDrawerVisible}
- titlebarLeadingContainer={titlebarLeadingRoot}
- onToggleChatDrawer={toggleChatDrawer}
- onEmbeddedAppOpening={handleSandboxUiOpening}
- onEmbeddedAppMounted={handleSandboxUiMounted}
- onEmbeddedAppBack={handleSandboxUiClosed}
- onEmbeddedAppRemoved={handleSandboxUiRemoved}
- onEmbedBoundsApplied={handleSandboxUiBoundsApplied}
- onEmbedSlotTopChange={setChatDrawerEmbedTop}
- onEmbedSlotRightChange={setNotificationTrayLeft}
- onNotify={vm.pushToast}
- onShortcutOpenResult={handleSandboxUiShortcutOpenResult}
- />
- {chatDrawerVisible && (
- <ChatDrawer
- header={
- <ChatSwitcher
- tabs={chatWorkspaceTabs}
- activeTabId={drawerActiveChatTabId}
- onSelect={handleSelectDrawerChatTab}
- onNewChat={handleNewWorkspaceChatTab}
- focusRequestId={chatSwitcherFocusRequestId}
- />
- }
- onNewChat={handleNewWorkspaceChatTab}
- onExpandFullScreen={expandChatDrawerToFullScreen}
- onToggle={toggleChatDrawer}
- containerRef={chatDrawerRef}
- ready={chatDrawerReady}
- onResizeHandleMouseDown={
- chatDrawerResize.onResizeHandleMouseDown
- }
- onResizeHandleKeyDown={
- chatDrawerResize.onResizeHandleKeyDown
- }
- width={chatDrawerResize.width}
- resizing={chatDrawerResize.isResizing}
- >
- <ChatPage scrollContainerRef={chatDrawerRef} />
- </ChatDrawer>
- )}
- </>
+ <SandboxUiPage
+ boundsRefreshKey={sandboxUiBoundsRefreshKey}
+ actionRequest={sandboxActionRequest}
+ currentTeamId={vm.currentTeamId}
+ headerShellOverlayOpen={
+ headerShellOverlayOpen || commandPaletteOpen
+ }
+ sidebarShellOverlayOpen={sidebarSettingsMenuOpen}
+ toastShellOverlayOpen={vm.toasts.length > 0}
+ deepLinkShellOverlayOpen={sandboxUiDeepLinkDialog !== null}
+ shortcutApp={activeSandboxUiApp}
+ shortcutOpenRequestId={sandboxUiShortcutOpenRequestId}
+ localSearchRequestId={sandboxLocalSearchRequestId}
+ titlebarLeadingContainer={titlebarLeadingRoot}
+ onEmbeddedAppOpening={handleSandboxUiOpening}
+ onEmbeddedAppMounted={handleSandboxUiMounted}
+ onEmbeddedAppBack={handleSandboxUiClosed}
+ onEmbeddedAppRemoved={handleSandboxUiRemoved}
+ onEmbedBoundsApplied={handleSandboxUiBoundsApplied}
+ onEmbedSlotTopChange={setChatDrawerEmbedTop}
+ onEmbedSlotRightChange={setNotificationTrayLeft}
+ onNotify={vm.pushToast}
+ onShortcutOpenResult={handleSandboxUiShortcutOpenResult}
+ />
)}
{vm.navItem === DESKTOP_ROUTES.settings && (
<SettingsPage
@@ -2336,6 +2341,47 @@ export function App() {
/>
)}
</section>
+ {/* Universal chat drawer (mini-spec 04a §B/§D):
+ mounted at the workspace-layout level (a sibling
+ of the content panel), not inside the apps block,
+ so it persists across ANY non-chat tab (R5). It
+ fills the shared right-rail shell; the tab area
+ between the sidebar and this rail shrinks via the
+ universal gutter. Single global <ChatPage>/
+ ChatSwitcher — no duplicated tab state or
+ streams. */}
+ {chatDrawerVisible && (
+ <RightRailShell
+ occupant="chat-drawer"
+ width={chatDrawerResize.width}
+ top={drawerRailTop}
+ >
+ <ChatDrawer
+ header={
+ <ChatSwitcher
+ tabs={chatWorkspaceTabs}
+ activeTabId={drawerActiveChatTabId}
+ onSelect={handleSelectDrawerChatTab}
+ onNewChat={handleNewWorkspaceChatTab}
+ focusRequestId={chatSwitcherFocusRequestId}
+ />
+ }
+ onNewChat={handleNewWorkspaceChatTab}
+ onExpandFullScreen={expandChatDrawerToFullScreen}
+ onToggle={toggleChatDrawer}
+ containerRef={chatDrawerRef}
+ ready={drawerReady}
+ onResizeHandleMouseDown={
+ chatDrawerResize.onResizeHandleMouseDown
+ }
+ onResizeHandleKeyDown={chatDrawerResize.onResizeHandleKeyDown}
+ width={chatDrawerResize.width}
+ resizing={chatDrawerResize.isResizing}
+ >
+ <ChatPage scrollContainerRef={chatDrawerRef} />
+ </ChatDrawer>
+ </RightRailShell>
+ )}
</section>
</main>
{commandPaletteOpen ? (
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index c24072010..49b5ee32d 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -68,8 +68,6 @@ const sidebarHarness = vi.hoisted(() => ({
}))
const sandboxUiPageHarness = vi.hoisted(() => ({
props: null as null | {
- chatDrawerOpen?: boolean
- onToggleChatDrawer?: () => void
onEmbeddedAppMounted?: () => void
onEmbedBoundsApplied?: () => void
onEmbedSlotTopChange?: (topPx: number) => void
@@ -80,6 +78,13 @@ const appHeaderHarness = vi.hoisted(() => ({
props: null as null | {
notificationTrayMode?: 'drawer' | 'overlay'
notificationTrayLeft?: number | null
+ // Drawer toggle moved to the app header (mini-spec 04a §C): the drawer's
+ // effective visibility and its toggle are now driven from here, on EVERY
+ // route (the header is portaled into the title bar unconditionally), not from
+ // the apps-only SandboxUiPage.
+ drawerAvailable?: boolean
+ chatDrawerOpen?: boolean
+ onToggleChatDrawer?: () => void
},
// Captured from context so tests can drive the "open conversation" gesture the
// notification tray fires.
@@ -421,7 +426,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('First chat')
// Switch to chat-2 in the drawer switcher.
@@ -430,10 +435,10 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('Second chat')
// Close the drawer, then reopen it.
- act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
- act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
// Reopen must preserve chat-2, not jump back to the chat-1 origin.
expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('Second chat')
@@ -476,7 +481,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
expect(screen.getByRole('button', { name: 'Collapse chat drawer' })).toBeTruthy()
@@ -569,13 +574,13 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
})
})
act(() => sandboxUiPageHarness.props?.onEmbeddedAppMounted?.())
- act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// Fire the shortcut: the drawer reopens but has NOT acked its bounds, so its
// subtree is inert. The switcher must stay CLOSED — no options rendered yet.
act(() => commandCb?.('chat.switcher', 'shortcut-host'))
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(screen.queryByRole('option')).toBeNull()
// Embed acks its bounds → drawer becomes ready (inert lifted) → the deferred
@@ -631,7 +636,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
// Ignore any selection the launch itself performed; assert only on the command.
@@ -665,15 +670,15 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
// Both drawers share the same fixed right-rail rect, so the notification tray
// must NOT use its drawer form while the chat drawer is up — it reverts to the
// overlay/popover form (handled by the existing shell-overlay freeze).
expect(appHeaderHarness.props?.notificationTrayMode).toBe('overlay')
// Closing the chat drawer (app still mounted) restores the tray's drawer form.
- act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(appHeaderHarness.props?.notificationTrayMode).toBe('drawer')
})
@@ -751,7 +756,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('First chat')
// The ChatThread session list picks chat-2: switchToChat moves activeChatId
@@ -785,7 +790,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
// Open the conversation the approval is on (chat-2, a background chat) via the
@@ -803,7 +808,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
// Observable: the drawer now shows the approval's chat AND we did not eject
// to the full-screen chat route.
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(currentController.activeChatId).toBe('chat-2')
expect(currentController.handleOpenNotification).toHaveBeenCalledWith(
expect.objectContaining({ chatId: 'chat-2' }),
@@ -836,7 +841,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
})
})
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// The approval is on a chat in a DIFFERENT team (team-b vs the harness team-a).
await act(async () => {
@@ -852,7 +857,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
// The drawer never opened, and the gesture ran through the plain path WITHOUT
// keepNavItem — the eject the full-screen route needs so a team switch survives.
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(currentController.handleOpenNotification).toHaveBeenCalledWith(
expect.objectContaining({ chatId: 'chat-2' }),
undefined
@@ -882,7 +887,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
})
})
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// sdk_notification navigates to its own target — must NOT open the drawer.
await act(async () => {
@@ -891,7 +896,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
kind: 'sdk_notification',
} as unknown as Parameters<NonNullable<typeof appHeaderHarness.openNotification>>[0])
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// workflow_completed navigates to plugins; returning to apps must NOT find a
// drawer the user never asked for (the "stuck true" symptom).
@@ -905,7 +910,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
currentController.navItem = DESKTOP_ROUTES.apps
rerender(<App />)
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
})
// An agent-conversation notification with an empty agentName has nothing to
@@ -931,7 +936,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
})
})
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// Conversation notification whose agentName is blank → nothing to surface.
await act(async () => {
@@ -946,7 +951,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
// The drawer never opened, and the gesture ran through the plain path WITHOUT
// keepNavItem (the controller itself will then no-op on the empty agent).
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(currentController.handleOpenNotification).toHaveBeenCalledWith(
expect.objectContaining({ agentName: ' ' }),
undefined
@@ -1048,28 +1053,28 @@ describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(screen.queryByRole('button', { name: 'Open chats' })).not.toBeNull()
// Narrow the panel below CHAT_DRAWER_MIN_PANEL_WIDTH (846): the drawer is
// suppressed and the app takes the full width (no gutter class).
resizeTo(800)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(screen.queryByRole('button', { name: 'Open chats' })).toBeNull()
// Re-widen above the threshold: the open intent was never cleared, so the
// drawer reappears on its own.
resizeTo(1200)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
expect(screen.queryByRole('button', { name: 'Open chats' })).not.toBeNull()
// Manual close while visible clears the intent.
- act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
// Widening (or any resize) must NOT bring a manually-closed drawer back.
resizeTo(2000)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(screen.queryByRole('button', { name: 'Open chats' })).toBeNull()
})
@@ -1116,7 +1121,7 @@ describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
})
})
resizeTo(800)
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
// Mod+T: the new chat must land on the full-screen chat route (reachable),
@@ -1126,7 +1131,7 @@ describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
expect(currentController.navItem).toBe(DESKTOP_ROUTES.chat)
})
- it('publishes --chat-drawer-top from the measured embed slot, falling back until measured', () => {
+ it('publishes the rail top from the measured embed slot on app tabs, falling back until measured', () => {
render(<App />)
act(() => {
@@ -1136,17 +1141,194 @@ describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
defaultPath: '/',
})
})
- expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
const panel = document.querySelector('.content-panel') as HTMLElement
expect(panel.className).toContain('content-panel--chat-drawer-open')
- // The width var is always present while docked; the top var stays absent until
- // the embed reports a measured top, so the CSS 64px fallback applies.
+ // The gutter width var is always present on the panel while docked (§A1).
expect(panel.style.getPropertyValue('--chat-drawer-width')).not.toBe('')
- expect(panel.style.getPropertyValue('--chat-drawer-top')).toBe('')
+
+ // The rail's top now lives on the RightRailShell (--rail-top), not the panel.
+ // On an app tab it stays absent until the embed reports a measured top, so the
+ // shell's static CSS fallback applies (§A2).
+ const rail = document.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail).not.toBeNull()
+ expect(rail.getAttribute('data-occupant')).toBe('chat-drawer')
+ expect(rail.style.getPropertyValue('--rail-top')).toBe('')
// The embed reports a wrapped-header top through the real callback path.
act(() => sandboxUiPageHarness.props?.onEmbedSlotTopChange?.(140))
- expect(panel.style.getPropertyValue('--chat-drawer-top')).toBe('140px')
+ expect(
+ (document.querySelector('.right-rail-shell') as HTMLElement).style.getPropertyValue(
+ '--rail-top'
+ )
+ ).toBe('140px')
+ })
+})
+
+// Mini-spec 04a — the drawer is universal (available over any non-chat tab), its
+// toggle lives in the app header, and it mounts once at the workspace level so it
+// survives non-chat tab switches. These drive the real App + real ChatDrawer/
+// ChatSwitcher through the mocked controller's store producers.
+describe('App chat drawer — universal availability (mini-spec 04a)', () => {
+ let currentController: AppController
+
+ beforeEach(() => {
+ vi.clearAllMocks()
+ sidebarHarness.props = null
+ sandboxUiPageHarness.props = null
+ appHeaderHarness.props = null
+ appHeaderHarness.openNotification = null
+ currentController = makeController({
+ selectedAgent: 'alpha',
+ activeChatId: 'chat-1',
+ navItem: DESKTOP_ROUTES.chat,
+ chatList: CHAT_LIST,
+ } as Partial<AppController>)
+ vi.mocked(useAppController).mockImplementation(() => useReactiveController(currentController))
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ shortcuts: { onCommand: vi.fn(() => vi.fn()) },
+ app: { rendererReady: vi.fn().mockResolvedValue(undefined) },
+ sandboxUi: {
+ listApps: vi.fn().mockResolvedValue({ apps: [] }),
+ listPendingDeepLinks: vi.fn().mockResolvedValue({ links: [] }),
+ clearPendingDeepLinks: vi.fn().mockResolvedValue(undefined),
+ onDeepLink: vi.fn(() => vi.fn()),
+ setVisible: vi.fn().mockResolvedValue(undefined),
+ setBounds: vi.fn().mockResolvedValue(undefined),
+ focusActive: vi.fn().mockResolvedValue(true),
+ close: vi.fn().mockResolvedValue(undefined),
+ },
+ } as unknown as Window['clerum'],
+ })
+ })
+
+ afterEach(() => {
+ cleanup()
+ delete (window as { clerum?: unknown }).clerum
+ })
+
+ // R2: available on app/files/settings, never on chat.
+ it('makes the drawer available on non-chat tabs and hides it on chat tabs (R2)', () => {
+ render(<App />)
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(false) // chat tab
+
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.files))
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.settings))
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+
+ act(() =>
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ )
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.chat))
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(false)
+ })
+
+ // §A2 T3: on a DOM tab (no embed) the drawer is ready — interactive, not inert —
+ // the moment it opens, in the same frame. Fails on the committed 2b, where the
+ // drawer is not even available over a DOM tab.
+ it('makes the drawer interactive immediately on a DOM tab, never inert (§A2)', () => {
+ currentController = makeController({
+ selectedAgent: 'alpha',
+ activeChatId: 'chat-1',
+ navItem: DESKTOP_ROUTES.files,
+ chatList: CHAT_LIST,
+ } as Partial<AppController>)
+ const { container } = render(<App />)
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+
+ const drawer = container.querySelector('.chat-drawer') as HTMLElement | null
+ expect(drawer).not.toBeNull()
+ // No native view to ack a shrunk-bounds gate → ready immediately, not inert.
+ expect(drawer!.getAttribute('data-ready')).toBe('true')
+ expect(drawer!.hasAttribute('inert')).toBe(false)
+ })
+
+ // R5 + DEC-2: the drawer is global; switching between non-chat kinds keeps it
+ // open and never lets the chat reconcile steal focus onto a chat tab.
+ it('keeps the drawer intact across non-chat tab switches without stealing focus (R5/DEC-2)', () => {
+ render(<App />)
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.files))
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
+ expect(document.querySelector('.chat-drawer')).not.toBeNull()
+
+ // Switch to a settings tab: drawer stays open AND the reconcile (which runs
+ // while the drawer is visible with a chat active) keeps the settings tab
+ // active — it does not re-home focus to a chat tab.
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.settings))
+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.settings)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
+ expect(document.querySelector('.chat-drawer')).not.toBeNull()
+
+ // Back to files: still open, still not stolen to chat.
+ act(() => currentController.handleNavSelect(DESKTOP_ROUTES.files))
+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.files)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
+ })
+
+ // R4: selecting a chat tab with the drawer open collapses the drawer before the
+ // chat shows, and clears the open intent so returning to a non-chat tab does not
+ // silently re-open it.
+ it('collapses the drawer before the chat and clears the intent when a chat tab is selected (R4)', () => {
+ render(<App />)
+ act(() =>
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ )
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
+ expect(document.querySelector('.chat-drawer')).not.toBeNull()
+
+ // Select the chat tab from the strip (full-screen chat).
+ act(() => fireEvent.click(screen.getByRole('button', { name: 'First chat' })))
+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.chat)
+ expect(document.querySelector('.chat-drawer')).toBeNull()
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(false)
+
+ // Return to the app tab: the drawer stays closed (intent cleared by R4). Were
+ // the intent left set, `drawerAvailable && chatDrawerOpen` would re-open it.
+ act(() => fireEvent.click(screen.getByRole('button', { name: 'App' })))
+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)
+ expect(appHeaderHarness.props?.drawerAvailable).toBe(true)
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
+ expect(document.querySelector('.chat-drawer')).toBeNull()
+ })
+
+ // Right-rail single-occupancy (E): while the chat drawer holds the rail the
+ // notification tray is forced to its overlay/popover form (never the app-drawer
+ // form), so opening the tray can't close the drawer. Collapsing the drawer frees
+ // the rail and the tray reclaims its drawer form — the tray behavior is intact.
+ it('keeps the notification tray out of the rail while the chat drawer occupies it', () => {
+ render(<App />)
+ act(() =>
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ )
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(true)
+ expect(appHeaderHarness.props?.notificationTrayMode).toBe('overlay')
+ expect(document.querySelector('.chat-drawer')).not.toBeNull()
+
+ act(() => appHeaderHarness.props?.onToggleChatDrawer?.())
+ expect(appHeaderHarness.props?.chatDrawerOpen).toBe(false)
+ expect(appHeaderHarness.props?.notificationTrayMode).toBe('drawer')
})
})
diff --git a/desktop-app/ui/src/components/AppHeader/__tests__/chatDrawerToggle.test.tsx b/desktop-app/ui/src/components/AppHeader/__tests__/chatDrawerToggle.test.tsx
new file mode 100644
index 000000000..c11906975
--- /dev/null
+++ b/desktop-app/ui/src/components/AppHeader/__tests__/chatDrawerToggle.test.tsx
@@ -0,0 +1,116 @@
+// @vitest-environment jsdom
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { AppHeader } from '../index'
+
+// Mini-spec 04a §C/R3: the chat-drawer toggle lives in the app header, between
+// the search and the notification bell. It renders only when `drawerAvailable`
+// (never on a chat tab) and drives `onToggleChatDrawer`.
+
+vi.mock('@hooks/domain/useAgentsDataController', () => ({
+ useAgentsDataController: () => ({ accessCatalog: null }),
+}))
+vi.mock('@hooks/domain/useMcpServersDataController', () => ({
+ useMcpServersDataController: () => ({ globalMcpServers: [], mcpServersByAgent: {} }),
+}))
+vi.mock('@hooks/domain/useSearchPluginsAppsController', () => ({
+ useSearchPluginsAppsController: () => ({
+ plugins: [],
+ apps: [],
+ loading: false,
+ error: null,
+ ensureLoaded: vi.fn(async () => undefined),
+ }),
+}))
+vi.mock('@hooks/domain/useTeamsDataController', () => ({
+ useTeamsDataController: () => ({
+ teams: [],
+ teamMembers: [],
+ teamDirectory: {},
+ loading: false,
+ teamDirectoryHydrated: true,
+ currentTeamId: '',
+ ensureHydrated: vi.fn(async () => undefined),
+ }),
+}))
+vi.mock('@contexts/NavigationContext', () => ({
+ useNavigationContext: () => ({ navItem: 'apps', handleNavSelect: vi.fn() }),
+}))
+vi.mock('@contexts/NotificationsContext', () => ({
+ useNotificationsContext: () => ({
+ notifications: [],
+ unreadNotificationCount: 0,
+ notificationActionById: {},
+ pendingApprovals: [],
+ pendingApprovalsLoading: false,
+ pendingApprovalActionId: null,
+ markNotificationsRead: vi.fn(),
+ clearNotifications: vi.fn(),
+ removeNotification: vi.fn(),
+ handleOpenNotification: vi.fn(),
+ handleApproveNotification: vi.fn(),
+ handleDenyNotification: vi.fn(),
+ handleRefreshPendingApprovals: vi.fn(async () => undefined),
+ handleDecidePendingApproval: vi.fn(),
+ }),
+}))
+vi.mock('@hooks/useClickOutside', () => ({ useClickOutside: vi.fn() }))
+
+describe('AppHeader chat-drawer toggle', () => {
+ afterEach(() => {
+ cleanup()
+ vi.clearAllMocks()
+ })
+
+ it('is hidden when the drawer is unavailable (chat tab)', () => {
+ render(<AppHeader placement="titlebar" drawerAvailable={false} onToggleChatDrawer={vi.fn()} />)
+ expect(screen.queryByTestId('chat-drawer-toggle')).toBeNull()
+ expect(screen.queryByRole('button', { name: 'Open chat drawer' })).toBeNull()
+ })
+
+ it('is hidden when no toggle handler is wired', () => {
+ render(<AppHeader placement="titlebar" drawerAvailable={true} />)
+ expect(screen.queryByTestId('chat-drawer-toggle')).toBeNull()
+ })
+
+ it('renders between search and bell on a non-chat tab, reflecting the closed state', () => {
+ const { container } = render(
+ <AppHeader
+ placement="titlebar"
+ drawerAvailable={true}
+ chatDrawerOpen={false}
+ onToggleChatDrawer={vi.fn()}
+ />
+ )
+ const toggle = screen.getByTestId('chat-drawer-toggle')
+ expect(toggle.getAttribute('aria-label')).toBe('Open chat drawer')
+ expect(toggle.getAttribute('aria-pressed')).toBe('false')
+
+ // Positioned in the DOM between the search (.header-left) and the bell
+ // (.header-utilities), as R3 requires.
+ const left = container.querySelector('.header-left')
+ const utilities = container.querySelector('.header-utilities')
+ expect(left).not.toBeNull()
+ expect(utilities).not.toBeNull()
+ expect(left!.compareDocumentPosition(toggle) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
+ expect(
+ toggle.compareDocumentPosition(utilities!) & Node.DOCUMENT_POSITION_FOLLOWING
+ ).toBeTruthy()
+ })
+
+ it('reflects the open state and fires the toggle on click', () => {
+ const onToggleChatDrawer = vi.fn()
+ render(
+ <AppHeader
+ placement="titlebar"
+ drawerAvailable={true}
+ chatDrawerOpen={true}
+ onToggleChatDrawer={onToggleChatDrawer}
+ />
+ )
+ const toggle = screen.getByRole('button', { name: 'Close chat drawer' })
+ expect(toggle.getAttribute('aria-pressed')).toBe('true')
+ fireEvent.click(toggle)
+ expect(onToggleChatDrawer).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/desktop-app/ui/src/components/HeaderActions/index.tsx b/desktop-app/ui/src/components/HeaderActions/index.tsx
index 46dd895f5..26c111c88 100644
--- a/desktop-app/ui/src/components/HeaderActions/index.tsx
+++ b/desktop-app/ui/src/components/HeaderActions/index.tsx
@@ -4,6 +4,7 @@ import { useNotificationsContext } from '@contexts/NotificationsContext'
import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import { Button, IconButton, Pill, SelectableOption, TextInput } from '@components/Common'
+import { IconChat } from '@components/SidebarNav/icons'
import { DESKTOP_ROUTES } from '@constants/navigation'
import { useAgentsDataController } from '@hooks/domain/useAgentsDataController'
import { useMcpServersDataController } from '@hooks/domain/useMcpServersDataController'
@@ -90,6 +91,9 @@ export const HeaderActions = React.memo(function HeaderActions({
notificationTrayLeft = null,
onNotificationTrayOpenChange,
onShellOverlayOpenChange,
+ drawerAvailable = false,
+ chatDrawerOpen = false,
+ onToggleChatDrawer,
}: HeaderActionsProps) {
const { accessCatalog: agentsAccessCatalog, loading: agentsCatalogLoading } =
useAgentsDataController()
@@ -640,6 +644,25 @@ export const HeaderActions = React.memo(function HeaderActions({
</div>
</div>
+ {/* Chat-drawer toggle (mini-spec 04a §C/R3): between the search and the
+ bell. Hidden on chat tabs (`!drawerAvailable`), where the chat IS the
+ content. Ghost style like the bell (`--titlebar` variant). */}
+ {drawerAvailable && onToggleChatDrawer ? (
+ <IconButton
+ className="chat-drawer-toggle"
+ data-testid="chat-drawer-toggle"
+ color="neutral"
+ variant="ghost"
+ aria-label={chatDrawerOpen ? 'Close chat drawer' : 'Open chat drawer'}
+ aria-pressed={chatDrawerOpen}
+ label={chatDrawerOpen ? 'Close chat drawer' : 'Open chat drawer'}
+ title={chatDrawerOpen ? 'Close chat drawer' : 'Open chat drawer'}
+ onClick={onToggleChatDrawer}
+ >
+ <IconChat />
+ </IconButton>
+ ) : null}
+
<div className="header-utilities">
<div className="notification-bell-wrapper" ref={notificationsRef}>
<IconButton
diff --git a/desktop-app/ui/src/components/HeaderActions/types.ts b/desktop-app/ui/src/components/HeaderActions/types.ts
index d34e0f91f..54759817c 100644
--- a/desktop-app/ui/src/components/HeaderActions/types.ts
+++ b/desktop-app/ui/src/components/HeaderActions/types.ts
@@ -7,6 +7,16 @@ export type HeaderActionsProps = {
notificationTrayLeft?: number | null
onNotificationTrayOpenChange?: (open: boolean) => void
onShellOverlayOpenChange?: (open: boolean) => void
+ /**
+ * Chat-drawer toggle (mini-spec 04a §C, R3). The toggle lives between the
+ * search (`.header-left`) and the notification bell (`.header-utilities`). It
+ * renders only when `drawerAvailable` — i.e. never on a chat tab.
+ */
+ drawerAvailable?: boolean
+ /** Whether the chat drawer is currently open (effective visibility). */
+ chatDrawerOpen?: boolean
+ /** Toggles the chat drawer open/closed. */
+ onToggleChatDrawer?: () => void
}
export type SearchEntityResult = {
diff --git a/desktop-app/ui/src/components/RightRailShell/__tests__/RightRailShell.test.tsx b/desktop-app/ui/src/components/RightRailShell/__tests__/RightRailShell.test.tsx
new file mode 100644
index 000000000..774b2b8e7
--- /dev/null
+++ b/desktop-app/ui/src/components/RightRailShell/__tests__/RightRailShell.test.tsx
@@ -0,0 +1,63 @@
+// @vitest-environment jsdom
+import { afterEach, describe, expect, it } from 'vitest'
+import { cleanup, render } from '@testing-library/react'
+import { RightRailShell } from '..'
+
+afterEach(() => cleanup())
+
+describe('RightRailShell', () => {
+ it('renders nothing when no occupant holds the rail', () => {
+ const { container } = render(
+ <RightRailShell occupant={null} width={420}>
+ <div data-testid="occupant" />
+ </RightRailShell>
+ )
+ expect(container.querySelector('.right-rail-shell')).toBeNull()
+ expect(container.querySelector('[data-testid="occupant"]')).toBeNull()
+ })
+
+ it('hosts exactly the single named occupant and publishes the rail width', () => {
+ const { container } = render(
+ <RightRailShell occupant="chat-drawer" width={512}>
+ <div data-testid="occupant">chat</div>
+ </RightRailShell>
+ )
+ const rail = container.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail).not.toBeNull()
+ // Single-occupancy: exactly one occupant is named, and it is the only child.
+ expect(rail.getAttribute('data-occupant')).toBe('chat-drawer')
+ expect(rail.children.length).toBe(1)
+ expect(rail.querySelector('[data-testid="occupant"]')).not.toBeNull()
+ expect(rail.style.getPropertyValue('--rail-width')).toBe('512px')
+ })
+
+ it('publishes the measured rail top when given one', () => {
+ const { container } = render(
+ <RightRailShell occupant="chat-drawer" width={420} top={140}>
+ <div />
+ </RightRailShell>
+ )
+ const rail = container.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail.style.getPropertyValue('--rail-top')).toBe('140px')
+ })
+
+ it('omits the rail top (CSS fallback) when top is null — no embed to align to', () => {
+ const { container } = render(
+ <RightRailShell occupant="chat-drawer" width={420} top={null}>
+ <div />
+ </RightRailShell>
+ )
+ const rail = container.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail.style.getPropertyValue('--rail-top')).toBe('')
+ })
+
+ it('publishes a rail top of 0 (a legitimate measured top, not "unmeasured")', () => {
+ const { container } = render(
+ <RightRailShell occupant="chat-drawer" width={420} top={0}>
+ <div />
+ </RightRailShell>
+ )
+ const rail = container.querySelector('.right-rail-shell') as HTMLElement
+ expect(rail.style.getPropertyValue('--rail-top')).toBe('0px')
+ })
+})
diff --git a/desktop-app/ui/src/components/RightRailShell/index.tsx b/desktop-app/ui/src/components/RightRailShell/index.tsx
new file mode 100644
index 000000000..487b859c5
--- /dev/null
+++ b/desktop-app/ui/src/components/RightRailShell/index.tsx
@@ -0,0 +1,35 @@
+import type { CSSProperties } from 'react'
+import type { RightRailShellProps } from './types'
+
+/**
+ * Generic right-rail shell: the fixed right column (`top`/`right`/`bottom`/
+ * `width`) that a single occupant fills at a time (mini-spec 04a §B, decision
+ * E). It owns ONLY the rail geometry — the shared `--rail-*` tokens and the
+ * fixed positioning — never any occupant chrome or the arbitration of WHICH
+ * occupant is shown. Single-occupant (XOR) is expressed by the `occupant` prop:
+ * the caller passes exactly one occupant (or `null`), so two occupants can never
+ * paint the rail at once.
+ *
+ * The contract is designed for TWO occupants — `chat-drawer | notification-tray`
+ * — but in 04a only the chat drawer enters the rail. The notification tray keeps
+ * its current positioning (popover on DOM tabs, its own app-drawer form on app
+ * tabs, coordinated by App's existing `notificationTrayUsesDrawer` XOR); its
+ * migration into this shell is deferred to
+ * `work-tracker/issues/26-09-17-desktop-notification-tray-right-rail-shell.md`.
+ * Adding it later is a new `data-occupant` value plus its width/top wiring — no
+ * change to this component's geometry contract.
+ */
+export function RightRailShell({ occupant, width, top, children }: RightRailShellProps) {
+ if (!occupant) return null
+ const style = {
+ '--rail-width': `${width}px`,
+ // Publish the measured top only when we have one; otherwise the CSS fallback
+ // applies (null — not 0 — so a legitimate rect.top of 0 still positions).
+ ...(top !== null && top !== undefined ? { '--rail-top': `${top}px` } : {}),
+ } as CSSProperties
+ return (
+ <div className="right-rail-shell" data-occupant={occupant} style={style}>
+ {children}
+ </div>
+ )
+}
diff --git a/desktop-app/ui/src/components/RightRailShell/types.ts b/desktop-app/ui/src/components/RightRailShell/types.ts
new file mode 100644
index 000000000..effc37cbc
--- /dev/null
+++ b/desktop-app/ui/src/components/RightRailShell/types.ts
@@ -0,0 +1,33 @@
+import type { ReactNode } from 'react'
+
+/**
+ * The two things that can occupy the right rail. The rail admits a SINGLE
+ * occupant at a time (XOR): while one holds the rail the other falls back to its
+ * own non-rail form. In 04a only `chat-drawer` ever enters the rail; the
+ * `notification-tray` occupant is part of the contract but its migration is
+ * deferred (see the RightRailShell doc comment / issue
+ * `26-09-17-desktop-notification-tray-right-rail-shell`).
+ */
+export type RightRailOccupant = 'chat-drawer' | 'notification-tray'
+
+export type RightRailShellProps = {
+ /**
+ * Which occupant currently holds the rail, or `null` when the rail is empty.
+ * The caller resolves the XOR/precedence (04a: the chat drawer wins the rail
+ * and the tray falls to its popover form) BEFORE choosing what to render here;
+ * the shell does not arbitrate between occupants.
+ */
+ occupant: RightRailOccupant | null
+ /** Rail width in px (the occupant derives it from its own width token). */
+ width: number
+ /**
+ * Measured top of the rail in px, or `null`/`undefined` to use the static CSS
+ * fallback. App tabs pass the embed-measured top so the rail follows the
+ * embed's header; DOM tabs pass `null` (no native view to align to, so the
+ * static fallback avoids the "waiting for a measurement that never arrives"
+ * trap — mini-spec 04a §A2).
+ */
+ top?: number | null
+ /** The occupant's content (04a: the `<ChatDrawer>`). */
+ children: ReactNode
+}
diff --git a/desktop-app/ui/src/hooks/useChatDrawerResize.ts b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
index e0098b410..4bd656fa5 100644
--- a/desktop-app/ui/src/hooks/useChatDrawerResize.ts
+++ b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
@@ -41,8 +41,15 @@ const CHAT_DRAWER_KEY_STEP = 24
* dynamic max width is capped so at least this much embed remains; once the
* window is too narrow for both this floor AND the drawer's own minimum, the
* embed keeps shrinking and scrolls via its own `overflow-x` (never overlaps
- * the drawer). Reuses the value of the removed overlay threshold. */
-const CHAT_DRAWER_EMBED_FLOOR = 460
+ * the drawer). Reuses the value of the removed overlay threshold. This is the
+ * floor for APP tabs (a native embed shares the panel); DOM tabs use the
+ * smaller `CHAT_DRAWER_DOM_FLOOR` because a reflowing DOM page needs less
+ * reserved width to stay legible beside the drawer (mini-spec 04a §A3). */
+export const CHAT_DRAWER_EMBED_FLOOR = 460
+/** Content floor for DOM tabs (files/settings/etc.): no native embed shares the
+ * panel, so the reserved column can be tighter than the embed floor. Below this
+ * the split is too cramped and the drawer auto-suppresses (mini-spec 04a §A3). */
+export const CHAT_DRAWER_DOM_FLOOR = 360
/** Fixed term added beside `--chat-drawer-width` in the embed gutter, mirroring
* the CSS `--app-header-utilities-width` term `var(--space-2) + 36px`
* (space-2 = 10px). Kept in sync with styles.css by hand. */
@@ -51,14 +58,19 @@ const CHAT_DRAWER_GUTTER_EXTRA = 46
* (`--space-4` = 18px). */
const CHAT_DRAWER_RIGHT_INSET = 18
-/** Minimum content-panel width at which the docked drawer and the app embed can
- * still coexist: the drawer already pinned to its own minimum (340) PLUS the
- * embed at its legible floor (460) PLUS the fixed gutter term (46) = 846. Below
+/** Minimum content-panel width at which the docked drawer and the given content
+ * floor can still coexist: the drawer pinned to its own minimum (340) PLUS the
+ * content floor (embed 460 / DOM 360) PLUS the fixed gutter term (46). Below
* this the two no longer fit side by side, so there is no split to show and the
- * drawer auto-suppresses (the app takes the full width). Derived from its three
- * inputs — never a bare literal — so it always tracks them if any one moves. */
-export const CHAT_DRAWER_MIN_PANEL_WIDTH =
- CHAT_DRAWER_MIN_WIDTH + CHAT_DRAWER_GUTTER_EXTRA + CHAT_DRAWER_EMBED_FLOOR
+ * drawer auto-suppresses (the content takes the full width). Derived from its
+ * three inputs — never a bare literal — so it always tracks them if any moves. */
+export function minPanelWidth(contentFloor: number = CHAT_DRAWER_EMBED_FLOOR): number {
+ return CHAT_DRAWER_MIN_WIDTH + CHAT_DRAWER_GUTTER_EXTRA + contentFloor
+}
+
+/** Back-compat alias for the embed-floor minimum (846). App tabs use this via
+ * `minPanelWidth(CHAT_DRAWER_EMBED_FLOOR)`; kept exported for existing tests. */
+export const CHAT_DRAWER_MIN_PANEL_WIDTH = minPanelWidth(CHAT_DRAWER_EMBED_FLOOR)
/** Clamp a user-requested width to the panel-independent absolute bounds
* [MIN, MAX_ABSOLUTE], rounded to a whole pixel. This is what we persist as the
@@ -75,17 +87,20 @@ function readPanelWidth(ref: RefObject<HTMLElement | null>): number {
}
/** Clamp a requested width to [MIN, dynamicMax], rounded to a whole pixel. The
- * dynamic max reserves `EMBED_FLOOR + GUTTER_EXTRA` for the docked embed so a
- * narrowing window shrinks the drawer instead of collapsing the embed. */
-export function clampWidth(requested: number, panelWidth: number): number {
+ * dynamic max reserves `contentFloor + GUTTER_EXTRA` for the docked content so a
+ * narrowing window shrinks the drawer instead of collapsing the content. The
+ * floor defaults to the embed floor (app tabs); DOM tabs pass the smaller
+ * `CHAT_DRAWER_DOM_FLOOR` (mini-spec 04a §A3). */
+export function clampWidth(
+ requested: number,
+ panelWidth: number,
+ contentFloor: number = CHAT_DRAWER_EMBED_FLOOR
+): number {
const dynamicMax =
panelWidth > 0
? Math.max(
CHAT_DRAWER_MIN_WIDTH,
- Math.min(
- CHAT_DRAWER_MAX_ABSOLUTE,
- panelWidth - CHAT_DRAWER_EMBED_FLOOR - CHAT_DRAWER_GUTTER_EXTRA
- )
+ Math.min(CHAT_DRAWER_MAX_ABSOLUTE, panelWidth - contentFloor - CHAT_DRAWER_GUTTER_EXTRA)
)
: CHAT_DRAWER_MAX_ABSOLUTE
return Math.round(Math.max(CHAT_DRAWER_MIN_WIDTH, Math.min(dynamicMax, requested)))
@@ -111,7 +126,8 @@ export type ChatDrawerResize = {
export function useChatDrawerResize(
contentPanelRef: RefObject<HTMLElement | null>,
- active: boolean
+ active: boolean,
+ contentFloor: number = CHAT_DRAWER_EMBED_FLOOR
): ChatDrawerResize {
// `requestedWidth` is the user's INTENT (drag/keyboard target); the rendered
// width is `clampWidth(requestedWidth, panelWidth)`. Separating them is what
@@ -122,8 +138,8 @@ export function useChatDrawerResize(
const [requestedWidth, setRequestedWidth] = React.useState(CHAT_DRAWER_DEFAULT_WIDTH)
const [panelWidth, setPanelWidth] = React.useState(0)
const [isResizing, setIsResizing] = React.useState(false)
- const width = clampWidth(requestedWidth, panelWidth)
- const panelTooNarrow = panelWidth > 0 && panelWidth < CHAT_DRAWER_MIN_PANEL_WIDTH
+ const width = clampWidth(requestedWidth, panelWidth, contentFloor)
+ const panelTooNarrow = panelWidth > 0 && panelWidth < minPanelWidth(contentFloor)
// Mirrors the rendered width so the pointer/keyboard handlers (stable
// callbacks) can read the current applied value as the base for a relative
// resize without re-subscribing on every width change.
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.tsx b/desktop-app/ui/src/pages/SandboxUiPage.tsx
index 330850e4a..8e4a80335 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.tsx
+++ b/desktop-app/ui/src/pages/SandboxUiPage.tsx
@@ -4,7 +4,7 @@ import { IconButton, StatusBanner } from '@components/Common'
import { joinClasses } from '@lib/classNames'
import SandboxCurrentContentSearch from '../components/SandboxCurrentContentSearch'
import type { AppFindState } from '../components/SandboxCurrentContentSearch/types'
-import { IconChat, IconCopy, IconRefresh, IconSandboxUi } from '../components/SidebarNav/icons'
+import { IconCopy, IconRefresh, IconSandboxUi } from '../components/SidebarNav/icons'
import { clickableRowProps } from '../lib/clickableRowProps'
import type { SandboxUiAppListing } from '../lib/sandboxUiAppSelection.types'
import type {
@@ -204,7 +204,6 @@ function TitlebarLeadingAction({
export function SandboxUiPage({
actionRequest = null,
boundsRefreshKey = 0,
- conversationOrigin = null,
currentTeamId = '',
headerShellOverlayOpen = false,
sidebarShellOverlayOpen = false,
@@ -213,9 +212,7 @@ export function SandboxUiPage({
shortcutApp = null,
shortcutOpenRequestId = 0,
localSearchRequestId = 0,
- chatDrawerOpen = false,
titlebarLeadingContainer = null,
- onToggleChatDrawer,
onEmbeddedAppOpening,
onEmbeddedAppMounted,
onEmbeddedAppBack,
@@ -598,49 +595,24 @@ export function SandboxUiPage({
if (launch.kind === 'mounted' || launch.kind === 'minting') {
const showRefreshBanner =
refreshError && launch.kind === 'mounted' && refreshError.appRef === launch.appRef
- // Every leading control below is gated: the refresh/copy pair only exists
- // while 'mounted', and the conversation/drawer control needs an origin. In
- // the 'minting' state without an origin all of them are absent, so portaling
- // the wrapper unconditionally would inject an empty <div> into the shared
- // title bar. Only portal when at least one control will render.
- const hasLeadingActions =
- launch.kind === 'mounted' || Boolean(conversationOrigin && onToggleChatDrawer)
+ // The refresh/copy pair only exists while 'mounted'. The chat-drawer toggle
+ // moved to the app header (mini-spec 04a §C), so the leading slot carries no
+ // drawer control any more. In the 'minting' state both are absent, so
+ // portaling the wrapper unconditionally would inject an empty <div> into the
+ // shared title bar. Only portal when at least one control will render.
+ const hasLeadingActions = launch.kind === 'mounted'
return (
<section className="page" data-testid="sandbox-ui-mounted">
{/* App actions live in the native title bar's leading slot (icon-only,
label in a hover flyout). They render through a portal only once the
title bar has published its container; there is no inline fallback,
mirroring how the header search/bell portal works. "Back to apps" is
- intentionally gone — the sidebar owns the return to the app picker. */}
+ intentionally gone — the sidebar owns the return to the app picker;
+ the chat-drawer toggle now lives in the app header. */}
{titlebarLeadingContainer &&
hasLeadingActions &&
createPortal(
<div className="window-titlebar__leading-actions">
- {conversationOrigin && onToggleChatDrawer ? (
- // The originating conversation lives in the drawer beside the
- // live embed, so this control opens/closes that drawer (chat
- // icon, open/close label). The conversation-origin variant keeps
- // its own class so the toggle can later move to the app header.
- <TitlebarLeadingAction
- className="sandbox-ui-conversation-btn"
- label={chatDrawerOpen ? 'Close chat drawer' : 'Open chat drawer'}
- pressed={chatDrawerOpen}
- onClick={onToggleChatDrawer}
- >
- <IconChat />
- </TitlebarLeadingAction>
- ) : null}
- {launch.kind === 'mounted' && onToggleChatDrawer && !conversationOrigin && (
- // No originating conversation to return to — a plain drawer toggle.
- <TitlebarLeadingAction
- className="sandbox-ui-chat-drawer-btn"
- label={chatDrawerOpen ? 'Close chat drawer' : 'Open chat drawer'}
- pressed={chatDrawerOpen}
- onClick={onToggleChatDrawer}
- >
- <IconChat />
- </TitlebarLeadingAction>
- )}
{launch.kind === 'mounted' && (
<>
<TitlebarLeadingAction
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.types.ts b/desktop-app/ui/src/pages/SandboxUiPage.types.ts
index 406ffc91f..787b35330 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.types.ts
+++ b/desktop-app/ui/src/pages/SandboxUiPage.types.ts
@@ -21,7 +21,6 @@ export type SandboxUiPageProps = {
action: 'refresh' | 'back-to-apps'
} | null
boundsRefreshKey?: string | number
- conversationOrigin?: SandboxUiConversationOrigin | null
currentTeamId?: string
headerShellOverlayOpen?: boolean
sidebarShellOverlayOpen?: boolean
@@ -30,9 +29,7 @@ export type SandboxUiPageProps = {
shortcutApp?: ActiveSandboxUiApp | null
shortcutOpenRequestId?: number
localSearchRequestId?: number
- chatDrawerOpen?: boolean
titlebarLeadingContainer?: HTMLElement | null
- onToggleChatDrawer?: () => void
onEmbeddedAppOpening?: (app: ActiveSandboxUiApp) => void
onEmbeddedAppMounted?: () => void
onEmbeddedAppBack?: () => void
diff --git a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
index 2febce067..eacfed342 100644
--- a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
@@ -226,48 +226,10 @@ describe('SandboxUiPage', () => {
expect(document.body.querySelector('.window-titlebar__leading-actions')).toBeNull()
})
- it('exposes a chat-drawer toggle in the mounted header that reflects and drives drawer state', async () => {
- sandboxUi.listApps.mockResolvedValueOnce({
- apps: [
- {
- appRef: 'sandbox-recipes/sales-crm',
- title: "Andy's Sales CRM",
- defaultPath: '/',
- ready: true,
- phase: 'active',
- updatedAt: null,
- },
- ],
- })
- sandboxUi.open.mockResolvedValueOnce(undefined)
- const onToggleChatDrawer = vi.fn()
-
- const view = render(
- <SandboxUiPage chatDrawerOpen={false} onToggleChatDrawer={onToggleChatDrawer} />
- )
- fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
-
- // Drawer closed: the toggle invites opening, carries the same native title
- // (the only tooltip that can render over the native app view), and shows the
- // chat icon.
- const toggle = await screen.findByRole('button', { name: 'Open chat drawer' })
- expect(toggle.getAttribute('aria-pressed')).toBe('false')
- expect(toggle.getAttribute('title')).toBe('Open chat drawer')
- expect(toggle.querySelector('svg path')?.getAttribute('d')).toBe(
- 'M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'
- )
-
- fireEvent.click(toggle)
- expect(onToggleChatDrawer).toHaveBeenCalledTimes(1)
-
- // Drawer open: label flips to "Close chat drawer" and pressed state reflects it.
- view.rerender(<SandboxUiPage chatDrawerOpen={true} onToggleChatDrawer={onToggleChatDrawer} />)
- const openToggle = screen.getByRole('button', { name: 'Close chat drawer' })
- expect(openToggle.getAttribute('aria-pressed')).toBe('true')
- expect(openToggle.getAttribute('title')).toBe('Close chat drawer')
- })
-
- it('omits the chat-drawer toggle when no toggle handler is provided', async () => {
+ // Mini-spec 04a §C: the chat-drawer toggle moved to the app header. The leading
+ // slot no longer renders it (or the old conversation-origin variant); only
+ // refresh + copy remain there.
+ it('never renders a chat-drawer toggle in the leading slot, keeping only refresh + copy', async () => {
sandboxUi.listApps.mockResolvedValueOnce({
apps: [
{
@@ -285,8 +247,13 @@ describe('SandboxUiPage', () => {
render(<SandboxUiPage />)
fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
await screen.findByTestId('sandbox-ui-mounted')
+
+ // No drawer toggle in the leading slot, in either label state.
expect(screen.queryByRole('button', { name: 'Open chat drawer' })).toBeNull()
expect(screen.queryByRole('button', { name: 'Close chat drawer' })).toBeNull()
+ // Refresh + copy stay wired.
+ expect(screen.getByRole('button', { name: 'Refresh app content' })).toBeTruthy()
+ expect(screen.getByRole('button', { name: 'Copy current app link' })).toBeTruthy()
})
it('routes controlled refresh and back requests through mounted-app owners', async () => {
@@ -592,53 +559,7 @@ describe('SandboxUiPage', () => {
})
})
- it('shows a chat-drawer toggle when a conversation origin has a drawer toggle wired', async () => {
- sandboxUi.listApps.mockResolvedValueOnce({
- apps: [
- {
- appRef: 'sandbox-recipes/sales-crm',
- title: "Andy's Sales CRM",
- defaultPath: '/',
- ready: true,
- phase: 'active',
- updatedAt: null,
- },
- ],
- })
- sandboxUi.open.mockResolvedValueOnce(undefined)
- const onToggleChatDrawer = vi.fn()
-
- render(
- <SandboxUiPage
- conversationOrigin={{
- agentName: 'sales-agent',
- chatId: 'chat-123',
- title: 'Quarterly planning',
- }}
- chatDrawerOpen={false}
- onToggleChatDrawer={onToggleChatDrawer}
- />
- )
-
- fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
-
- // With a conversation origin the leading control opens/closes the chat drawer
- // where that conversation lives. Chat icon, native title = the open/close
- // label, and it drives the toggle only — never a destroy-and-reconstitute.
- const toggle = await screen.findByRole('button', { name: 'Open chat drawer' })
- expect(screen.queryByRole('button', { name: 'Back to Quarterly planning' })).toBeNull()
- expect(toggle.getAttribute('title')).toBe('Open chat drawer')
- expect(toggle.getAttribute('aria-pressed')).toBe('false')
- expect(toggle.querySelector('svg path')?.getAttribute('d')).toBe(
- 'M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'
- )
-
- fireEvent.click(toggle)
- expect(onToggleChatDrawer).toHaveBeenCalledTimes(1)
- expect(sandboxUi.close).not.toHaveBeenCalled()
- })
-
- it('keeps the conversation origin during Strict Mode effect replay', async () => {
+ it('keeps the embed mounted during Strict Mode effect replay', async () => {
sandboxUi.listApps.mockResolvedValue({
apps: [
{
@@ -652,28 +573,19 @@ describe('SandboxUiPage', () => {
],
})
sandboxUi.open.mockResolvedValueOnce(undefined)
- const onToggleChatDrawer = vi.fn()
const onEmbeddedAppBack = vi.fn()
render(
<React.StrictMode>
- <SandboxUiPage
- conversationOrigin={{
- agentName: 'task-board-agent',
- chatId: 'chat-123',
- title: 'Plan the launch',
- }}
- onToggleChatDrawer={onToggleChatDrawer}
- onEmbeddedAppBack={onEmbeddedAppBack}
- />
+ <SandboxUiPage onEmbeddedAppBack={onEmbeddedAppBack} />
</React.StrictMode>
)
fireEvent.click(await screen.findByRole('button', { name: 'Open Agentic Task Board' }))
- // The conversation-origin leading control survives the double-invoke without
- // tearing the embed down.
- expect(await screen.findByRole('button', { name: 'Open chat drawer' })).toBeTruthy()
+ // The mounted embed survives StrictMode's double-invoke without tearing down;
+ // its leading refresh control is the observable that it stayed mounted.
+ expect(await screen.findByRole('button', { name: 'Refresh app content' })).toBeTruthy()
expect(onEmbeddedAppBack).not.toHaveBeenCalled()
})
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 3ec74088e..30e3658e2 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -13013,35 +13013,61 @@ pre {
--app-header-utilities-width: var(--chat-drawer-width);
}
-.content-panel.content-panel--chat-drawer-open > .page:has(.sandbox-ui-embed-slot) {
+/* Universal tab-area gutter (mini-spec 04a §A1). The chat drawer is available on
+ any non-chat tab, so the "tab area" — the page content between the sidebar and
+ the drawer — must shrink for ANY active tab kind, not only the app embed. The
+ gutter is `padding-right` on the active tab's `.page` child (app embed slot,
+ files, settings, connectors, agents, plugins, the apps picker — all render a
+ direct `.page`), never on the measured content-panel, so opening the drawer
+ (which is `position: fixed`) never changes the panel's `clientWidth` and there
+ is no ResizeObserver feedback loop (confirmed in useChatDrawerResize). */
+.content-panel.content-panel--chat-drawer-open > .page {
padding-right: var(--app-header-utilities-width);
}
-.chat-drawer {
+/* Right-rail shell (mini-spec 04a §B): the fixed right column that a single
+ occupant fills. It owns the rail geometry via one shared token set
+ (`--rail-width`, `--rail-top`); the occupant supplies the values. Flush to the
+ panel's right and bottom edges (VS Code secondary-side-bar style). */
+.right-rail-shell {
position: fixed;
- /* Follow the measured top of the embed slot (`--chat-drawer-top`, published by
- App from useEmbedBounds) so the drawer stays aligned when the sandbox-ui
- header wraps in a narrow window. The fallback keeps the pre-measure/test
- behavior: a single-row header at space-4 + 36px + space-2 = 64px. */
- top: var(--chat-drawer-top, calc(var(--space-4) + 36px + var(--space-2)));
- /* Docked, VS Code secondary-side-bar style: flush to the panel's right and
- bottom edges (no floating inset), square corners, no shadow. The only
- visible edge is the 1px resize seam on the LEFT (see __resize-handle::after),
- which owns the border between the embed and the drawer — the drawer itself
- carries no border. */
+ /* Follow the measured top the occupant publishes (`--rail-top`); when
+ unmeasured (DOM tabs, tests) fall back to a single-row header at
+ space-4 + 36px + space-2 = 64px so the rail never waits on a measurement
+ that never arrives (§A2). */
+ top: var(--rail-top, calc(var(--space-4) + 36px + var(--space-2)));
right: 0;
bottom: 0;
- width: var(--chat-drawer-width);
+ width: var(--rail-width);
z-index: var(--layer-chat-overlay);
display: flex;
flex-direction: column;
min-height: 0;
+}
+
+/* Per-occupant rail width is published inline by RightRailShell from the
+ occupant's runtime width (the chat drawer is resizable), so it lives on the
+ element, not here. A future notification-tray occupant sets its own inline
+ --rail-width the same way. */
+
+.chat-drawer {
+ /* Positioning context for the absolute resize handle; the drawer fills the
+ rail shell (which owns top/right/bottom/width). The only visible edge is the
+ 1px resize seam on the LEFT (see __resize-handle::after), which owns the
+ border between the content and the drawer — the drawer itself carries no
+ border. */
+ position: relative;
+ flex: 1 1 auto;
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
/* Pairs with the sidebar surface so the drawer reads as a secondary side bar,
distinct from the editor/embed zone (which is --surface-0/--panel). */
background: var(--surface-3);
overflow: hidden;
- /* Anti-flash: reveal only after the embed acknowledges its shrunk bounds,
- mirroring the notification drawer's bounds-ack gate. */
+ /* Anti-flash: reveal only after the drawer is ready (app tabs: the embed acks
+ its shrunk bounds; DOM tabs: immediately, same frame — §A2). */
opacity: 0;
pointer-events: none;
}
@@ -13361,6 +13387,37 @@ pre {
stroke: var(--titlebar-action-ink) !important;
}
+/* Chat-drawer toggle (mini-spec 04a §C): a ghost control between the search and
+ the bell, styled like the titlebar bell. `margin-left: auto` collapses the
+ free space to its left so the toggle and the utilities cluster (which also
+ carries margin-left:auto) sit together at the right, the toggle immediately
+ left of the bell with the top-bar gap. */
+.top-bar .chat-drawer-toggle {
+ margin-left: auto;
+}
+
+.window-titlebar__actions .chat-drawer-toggle {
+ width: 30px;
+ height: 30px;
+ min-height: 30px;
+ border-color: transparent;
+ background: transparent;
+ box-shadow: none;
+}
+
+.window-titlebar__actions .chat-drawer-toggle svg {
+ width: 16px;
+ height: 16px;
+ color: var(--titlebar-action-ink) !important;
+ stroke: var(--titlebar-action-ink) !important;
+}
+
+.window-titlebar__actions .chat-drawer-toggle:hover:enabled,
+.window-titlebar__actions .chat-drawer-toggle[aria-pressed='true'] {
+ border-color: rgba(var(--accent-rgb), 0.42);
+ background: var(--surface-hover);
+}
+
:root[data-theme='dark'] .window-titlebar__actions .search-input {
border-color: var(--titlebar-action-border) !important;
background: var(--titlebar-action-surface) !important;