Skip to content

The agent that grows with you

fix(desktop): keep sidebar navigation stable beside page titles

brooklyn!444c75c10aba
diff --git a/apps/desktop/src/app/contrib/controller.tsx b/apps/desktop/src/app/contrib/controller.tsx
index 0b7b39215ad..684c22d916a 100644
--- a/apps/desktop/src/app/contrib/controller.tsx
+++ b/apps/desktop/src/app/contrib/controller.tsx
@@ -39,6 +39,7 @@ import {
import { $workspaceOwnerLabels, workspaceOwnerTitle } from '@/components/pane-shell/workspace-scope'
import { SidebarProvider } from '@/components/ui/sidebar'
import { discoverBundledPlugins } from '@/contrib/plugins'
+import { Slot } from '@/contrib/react/slot'
import { registry } from '@/contrib/registry'
import { discoverRuntimePlugins } from '@/contrib/runtime-loader'
import { translateNow } from '@/i18n'
@@ -474,6 +475,10 @@ const syncWorkspaceTitle = () => {
tabTitle: stored ? undefined : () => <SessionDraftTitle scope={selected} />,
// Pages aren't tab-able: the main zone's bar stands down while one shows.
headerVeto: $workspaceIsPage.get(),
+ headerContent:
+ $workspaceIsPage.get() && registry.getArea('titleBar.center').length
+ ? () => <Slot area="titleBar.center" />
+ : undefined,
placement: 'main',
minWidth: '22vw',
tabDrag: workspaceTabDrag,
@@ -489,6 +494,7 @@ $sessions.listen(syncWorkspaceTitle)
$botChatScopes.listen(syncWorkspaceTitle)
$workspaceOwnerLabels.listen(syncWorkspaceTitle)
$workspaceIsPage.listen(syncWorkspaceTitle)
+registry.subscribeArea('titleBar.center', syncWorkspaceTitle)
// Layout reset collapses every session tile into main as a tab (after the
// workspace) instead of re-scattering them — pre-placed before adoption.
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index f576b0368f0..a738e1ad7a6 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -142,6 +142,7 @@ import { PluginInstallModal } from '../settings/plugin-install-modal'
import { useOverlayRouting } from '../shell/hooks/use-overlay-routing'
import { useWindowControlsOverlayWidth } from '../shell/hooks/use-window-controls-overlay-width'
import {
+ TITLEBAR_CHROME_CHANGED_EVENT,
titlebarControlsPosition,
titlebarControlsYNudge,
titlebarToolsRightCss,
@@ -1282,6 +1283,11 @@ export function ContribWiring({ children }: { children: ReactNode }) {
const leftToolsWidth = titlebarToolsWidthCss(clusters.left)
+ // Native caption reservations can translate chrome without resizing it.
+ useEffect(() => {
+ window.dispatchEvent(new CustomEvent(TITLEBAR_CHROME_CHANGED_EVENT))
+ }, [controlsPos.left, controlsPos.top, titlebarToolsRight])
+
return (
<ContribWiringContext.Provider value={api}>
<div
diff --git a/apps/desktop/src/app/routes.ts b/apps/desktop/src/app/routes.ts
index c2563a7523d..0e5998c810a 100644
--- a/apps/desktop/src/app/routes.ts
+++ b/apps/desktop/src/app/routes.ts
@@ -229,7 +229,7 @@ export function appViewForPath(pathname: string): AppView {
/** Does `to` land on a full page rendered INSIDE the workspace pane
* (skills/messaging/artifacts/contributed routes)? Overlays don't count —
* they float over whatever the workspace is already showing. */
-function isWorkspacePageRoute(to: string): boolean {
+export function isWorkspacePageRoute(to: string): boolean {
const view = appViewForPath(to)
return view !== 'chat' && !isOverlayView(view)
diff --git a/apps/desktop/src/app/shell/titlebar-controls.test.tsx b/apps/desktop/src/app/shell/titlebar-controls.test.tsx
index 6dbda5030d2..ecf57bdc127 100644
--- a/apps/desktop/src/app/shell/titlebar-controls.test.tsx
+++ b/apps/desktop/src/app/shell/titlebar-controls.test.tsx
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import { act, cleanup, render, screen, within } from '@testing-library/react'
import { MemoryRouter } from 'react-router'
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { registry } from '@/contrib/registry'
import { I18nProvider } from '@/i18n'
@@ -9,6 +9,7 @@ import { setTitlebarAppActionsSide } from '@/store/titlebar-app-actions'
import { ROUTES_AREA } from '../routes'
+import { TITLEBAR_CHROME_CHANGED_EVENT } from './titlebar'
import { TitlebarControls, type TitlebarTool } from './titlebar-controls'
const PLUGIN_TOOL: TitlebarTool = { icon: <span />, id: 'plugin-tool', label: 'plugin tool' }
@@ -88,12 +89,29 @@ describe('TitlebarControls fixed clusters', () => {
expect(pluginTool()).not.toBeNull()
})
+ it('leaves page titles to the workspace header without hiding window controls', () => {
+ const disposeTitle = registry.register({
+ area: 'titleBar.center',
+ id: 'test-page-title',
+ render: () => <span>Board picker</span>
+ })
+
+ try {
+ renderControls('/kanban')
+ expect(screen.queryByText('Board picker')).toBeNull()
+ expect(windowControls()).not.toBeNull()
+ expect(appControls()).not.toBeNull()
+ } finally {
+ act(disposeTitle)
+ }
+ })
+
describe('when the page projects titlebar chrome', () => {
let disposeChrome: () => void
beforeEach(() => {
disposeChrome = registry.register({
- area: 'titleBar.center',
+ area: 'titleBar.left',
id: 'test-plugin-chrome',
render: () => <span>plugin-chrome</span>
})
@@ -131,6 +149,29 @@ describe('TitlebarControls fixed clusters', () => {
expect(pluginChrome()).toBeNull()
})
+
+ it('keeps measurable titlebar clusters on a chrome-owning contributed page', () => {
+ // usePanelTitlebar positions the sessions tab strip from these hooks;
+ // without them the tabs keep their stale chat-view offset and slide
+ // under the page's switcher (kanban's board switcher).
+ const { container } = renderControls('/kanban')
+
+ expect(container.querySelector('[data-titlebar-cluster="left"]')).not.toBeNull()
+ expect(container.querySelector('[data-titlebar-cluster="right"]')).not.toBeNull()
+ })
+
+ it('announces its chrome so the sessions tab reservation re-measures', () => {
+ const listener = vi.fn()
+ window.addEventListener(TITLEBAR_CHROME_CHANGED_EVENT, listener)
+
+ try {
+ renderControls('/kanban')
+
+ expect(listener).toHaveBeenCalled()
+ } finally {
+ window.removeEventListener(TITLEBAR_CHROME_CHANGED_EVENT, listener)
+ }
+ })
})
})
diff --git a/apps/desktop/src/app/shell/titlebar-controls.tsx b/apps/desktop/src/app/shell/titlebar-controls.tsx
index df19bd0607b..52bdf793661 100644
--- a/apps/desktop/src/app/shell/titlebar-controls.tsx
+++ b/apps/desktop/src/app/shell/titlebar-controls.tsx
@@ -27,9 +27,10 @@ import {
import { $unreadSessionCount } from '@/store/session-dot-state'
import { $titlebarAppActionsSide } from '@/store/titlebar-app-actions'
-import { appViewForPath, hidesFixedTitlebarClusters, isOverlayView } from '../routes'
+import { appViewForPath, hidesFixedTitlebarClusters, isOverlayView, isWorkspacePageRoute } from '../routes'
import {
+ TITLEBAR_CHROME_CHANGED_EVENT,
TITLEBAR_ICON_BADGE_SCALE,
titlebarButtonClass,
titlebarIconSizeCss,
@@ -148,9 +149,9 @@ export function TitlebarControls({ leftTools = [], tools = [], onOpenSettings }:
// only while that surface is up — so a non-empty area means a page is
// actively projecting chrome into the band right now.
const titleBarLeft = useContributions('titleBar.left')
- const titleBarCenter = useContributions('titleBar.center')
const titleBarRight = useContributions('titleBar.right')
- const pageOwnsTitlebar = titleBarLeft.length + titleBarCenter.length + titleBarRight.length > 0
+ const workspacePage = isWorkspacePageRoute(location.pathname)
+ const pageOwnsTitlebar = titleBarLeft.length + titleBarRight.length > 0
// POSITIONAL toggles: each button shows/hides everything on its physical
// side of the main zone (the layout tree collapses the whole side), so they
@@ -249,6 +250,11 @@ export function TitlebarControls({ leftTools = [], tools = [], onOpenSettings }:
const view = appViewForPath(location.pathname)
+ // Route changes can replace measured clusters without resizing the panels.
+ useEffect(() => {
+ window.dispatchEvent(new CustomEvent(TITLEBAR_CHROME_CHANGED_EVENT))
+ }, [location.pathname, pageOwnsTitlebar])
+
// Overlays own the window. These clusters are `fixed` at a higher z-index
// than the overlay card, so they'd otherwise bleed over it — hide them (and
// the nested titleBar slots) and let the overlay's own chrome take over.
@@ -256,14 +262,6 @@ export function TitlebarControls({ leftTools = [], tools = [], onOpenSettings }:
return null
}
- const titlebarSlots = (
- <>
- <Slot area="titleBar.left" />
- <Slot area="titleBar.center" />
- <Slot area="titleBar.right" />
- </>
- )
-
const leftClusterClass = cn(
titlebarToolClusterClass,
'left-(--titlebar-controls-left) top-(--titlebar-controls-top) translate-y-(--titlebar-controls-y-nudge)'
@@ -278,13 +276,22 @@ export function TitlebarControls({ leftTools = [], tools = [], onOpenSettings }:
if (hidesFixedTitlebarClusters(view) && pageOwnsTitlebar) {
const pageTools = [...leftTools, ...tools].filter(tool => !tool.hidden)
+ // Both markers are required even when a page contributes to only one side.
return (
- <div className={leftClusterClass}>
- {pageTools.map(tool => (
- <TitlebarToolButton key={tool.id} navigate={navigate} tool={tool} />
- ))}
- {titlebarSlots}
- </div>
+ <>
+ <div className={leftClusterClass} data-titlebar-cluster="left">
+ {pageTools.map(tool => (
+ <TitlebarToolButton key={tool.id} navigate={navigate} tool={tool} />
+ ))}
+ <Slot area="titleBar.left" />
+ </div>
+ <div
+ className={cn(titlebarToolClusterClass, 'right-(--titlebar-tools-right) top-(--titlebar-controls-top)')}
+ data-titlebar-cluster="right"
+ >
+ <Slot area="titleBar.right" />
+ </div>
+ </>
)
}
@@ -302,7 +309,7 @@ export function TitlebarControls({ leftTools = [], tools = [], onOpenSettings }:
<TitlebarToolButton key={tool.id} navigate={navigate} tool={tool} />
))}
<Slot area="titleBar.left" />
- <Slot area="titleBar.center" />
+ {!workspacePage && <Slot area="titleBar.center" />}
</div>
{visiblePaneTools.length > 0 && (
diff --git a/apps/desktop/src/app/shell/titlebar.ts b/apps/desktop/src/app/shell/titlebar.ts
index 1d58896d59c..83201088c6d 100644
--- a/apps/desktop/src/app/shell/titlebar.ts
+++ b/apps/desktop/src/app/shell/titlebar.ts
@@ -109,3 +109,6 @@ export function titlebarControlsPosition(
top
}
}
+
+/** Rebind panel measurements after titlebar nodes or their positions change. */
+export const TITLEBAR_CHROME_CHANGED_EVENT = 'hermes:titlebar-chrome-changed'
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/panel-titlebar.ts b/apps/desktop/src/components/pane-shell/tree/renderer/panel-titlebar.ts
index f06ce0c60b3..401f172b6d3 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/panel-titlebar.ts
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/panel-titlebar.ts
@@ -1,5 +1,6 @@
import { type RefObject, useCallback, useLayoutEffect, useState } from 'react'
+import { TITLEBAR_CHROME_CHANGED_EVENT } from '@/app/shell/titlebar'
import { useResizeObserver } from '@/hooks/use-resize-observer'
import { $connection } from '@/store/session'
@@ -54,14 +55,28 @@ export function usePanelTitlebar(ref: RefObject<HTMLElement | null>, enabled: bo
return
}
- measure()
const observer = new ResizeObserver(measure)
- for (const element of document.querySelectorAll('[data-titlebar-cluster], [data-tree-group]')) {
- observer.observe(element)
+ const observe = () => {
+ // Re-query on every chrome change: route switches mount a different
+ // cluster set (app clusters vs a page-owned band), and observing the
+ // unmounted set would measure nothing.
+ observer.disconnect()
+
+ for (const element of document.querySelectorAll('[data-titlebar-cluster], [data-tree-group]')) {
+ observer.observe(element)
+ }
+ }
+
+ const onChromeChanged = () => {
+ observe()
+ measure()
}
+ observe()
+ measure()
window.addEventListener('resize', measure)
+ window.addEventListener(TITLEBAR_CHROME_CHANGED_EVENT, onChromeChanged)
// A fullscreen transition first fires `resize` (measured against the
// pre-transition cluster) and only then lands the window-state IPC that
@@ -70,6 +85,7 @@ export function usePanelTitlebar(ref: RefObject<HTMLElement | null>, enabled: bo
// repaints the clusters from the new chrome vars.
let lastChrome = chromeKey()
let frame = 0
+
const unsubscribeChrome = $connection.subscribe(() => {
const nextChrome = chromeKey()
@@ -87,6 +103,7 @@ export function usePanelTitlebar(ref: RefObject<HTMLElement | null>, enabled: bo
return () => {
observer.disconnect()
window.removeEventListener('resize', measure)
+ window.removeEventListener(TITLEBAR_CHROME_CHANGED_EVENT, onChromeChanged)
unsubscribeChrome()
cancelAnimationFrame(frame)
}
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/track-model.ts b/apps/desktop/src/components/pane-shell/tree/renderer/track-model.ts
index a6be611dd85..8b03ddecb48 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/track-model.ts
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/track-model.ts
@@ -95,6 +95,8 @@ interface PaneChrome extends PaneSizing {
* (artifacts/skills/plugin pages) are not tab-able surfaces. The flag is
* live: the workspace contribution re-registers it on route changes. */
headerVeto?: boolean
+ /** Page-owned controls in the panel's normal tab-header space. */
+ headerContent?: () => React.ReactNode
/** A lead NODE for this pane's TAB, rendered before the label. A session
* pane (main workspace + tiles) passes its live `SessionStatusDot` here so
* the tab and the sidebar row render status/color from the ONE primitive
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
index 5ba031eea24..e2e7142f9e8 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx
@@ -3,6 +3,7 @@ import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { registry } from '@/contrib/registry'
+import { $tabStripDefault, setTabStripDefault } from '@/store/tabstrip-prefs'
import type { GroupNode } from '../model'
import { $treeDragging, NEW_SESSION_DRAG, SESSION_TILE_DRAG } from '../store'
@@ -67,11 +68,11 @@ describe('TreeGroup', () => {
describe('top-edge window drag handle', () => {
const paneIds = ['terminal', 'terminal-2', 'terminal-3', 'terminal-4', 'terminal-5']
- function mountCrowdedStrip(titlebarWidth: number) {
+ function mountCrowdedStrip(titlebarWidth: number, placement = 'main') {
const disposers = paneIds.map(id =>
registry.register({
area: 'panes',
- data: { placement: 'main' },
+ data: { placement },
id,
render: () => <div>{id}</div>,
title: id
@@ -118,6 +119,60 @@ describe('TreeGroup', () => {
}
}
+ it.each([300, 800])('keeps sidebar tabs below the native band at width %s', width => {
+ const { strip } = mountCrowdedStrip(width, 'left')
+ expect(strip.className).toContain('bottom-0')
+ expect(container!.querySelector<HTMLElement>('[data-panel-header]')!.style.height).toBe('62px')
+ })
+
+ it.each(['zone', 'default'] as const)('preserves the saved %s hide-tabs preference', source => {
+ mountCrowdedStrip(800, 'left')
+ const originalDefault = $tabStripDefault.get()
+
+ const node: GroupNode = {
+ ...terminalGroup(false),
+ panes: paneIds,
+ tabStrip: source === 'zone' ? 'never' : undefined
+ }
+
+ try {
+ if (source === 'default') {
+ act(() => setTabStripDefault('never'))
+ }
+
+ const savedDefault = localStorage.getItem('hermes.desktop.tabStripDefault')
+ render(<TreeGroup leftEdge node={node} rightEdge topEdge />)
+ expect(container!.querySelector('[data-zone-tabstrip]')).toBeNull()
+ expect(container!.querySelector<HTMLElement>('[data-panel-header]')!.style.height).toBe('34px')
+ expect(node.tabStrip).toBe(source === 'zone' ? 'never' : undefined)
+ expect(localStorage.getItem('hermes.desktop.tabStripDefault')).toBe(savedDefault)
+ } finally {
+ act(() => setTabStripDefault(originalDefault))
+ }
+ })
+
+ it('renders page controls inside their own panel in the normal tab space', () => {
+ mountCrowdedStrip(800)
+ act(() => {
+ registry.register({
+ area: 'panes',
+ id: 'terminal',
+ title: 'Kanban',
+ data: {
+ placement: 'main',
+ headerVeto: true,
+ headerContent: () => <button type="button">Board picker</button>
+ },
+ render: () => <div>Board content</div>
+ })
+ })
+ const header = container!.querySelector<HTMLElement>('[data-panel-page-header]')!
+ expect(header.textContent).toBe('Board picker')
+ expect(header.closest('[data-tree-group]')?.getAttribute('data-tree-group')).toBe('terminal-zone')
+ expect(header.querySelector('[data-slot="pane-tab"]')).not.toBeNull()
+ expect(container!.querySelector('[data-zone-tabstrip]')).toBeNull()
+ })
+
it('keeps a fixed drag handle outside the tablist when tabs share the titlebar', () => {
const { handles, strip } = mountCrowdedStrip(800)
const fixed = handles.filter(handle => !handle.closest('[role="tablist"]') && handle.style.width !== '')
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
index 0fe36b7dc08..9067ee12bdd 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
@@ -239,8 +239,7 @@ export function TreeGroup({
// The scrolling tab list inside the header (the strip also holds the
// minimize chevron, which must not scroll away).
const tabsRef = useRef<HTMLDivElement>(null)
- const tabsBelowControls = usePanelTitlebar(ref, topEdge, Boolean(node.minimized))
- const tabsInTitlebar = topEdge && !tabsBelowControls
+ const measuredBelowControls = usePanelTitlebar(ref, topEdge, Boolean(node.minimized))
// The chip under the last right-click — the pane the zone menu's Split
// actions carry into the new zone (header background = the active pane).
// STATE, not a ref: the menu items (incl. Close's visibility) are JSX
@@ -292,6 +291,10 @@ export function TreeGroup({
const active = paneFor(activeId)
const isEmpty = shown.length === 0
+ const sidebarGroup = !node.panes.some(id => id === 'workspace' || paneChrome(paneFor(id)).placement === 'main')
+ const tabsBelowControls = topEdge && (sidebarGroup || measuredBelowControls)
+ const tabsInTitlebar = topEdge && !tabsBelowControls
+ const pageHeader = paneChrome(active).headerContent
// What the strip's "+" makes. The pane you are LOOKING AT answers first (a
// Browser tab makes another Browser, even stacked into the chat strip), then
@@ -359,8 +362,10 @@ export function TreeGroup({
// Every minimized row group becomes a vertical restore rail. A horizontal
// multi-tab strip cannot fit in the collapsed 28px track.
const verticalCollapse = Boolean(node.minimized) && parentAxis === 'row' && !isEmpty
+
// A minimized group IS its header, so it shows one regardless.
- const headerVisible = !isEmpty && !verticalCollapse && (Boolean(node.minimized) || stripVisible)
+ const headerVisible =
+ !isEmpty && !verticalCollapse && (Boolean(node.minimized) || stripVisible || Boolean(pageHeader))
// Keep the activated tab — and, on the last one, the trailing "+" — inside
// the strip's scroll window. Opening a tab past the right edge otherwise
@@ -517,7 +522,17 @@ export function TreeGroup({
{topEdge && (
<div aria-hidden="true" className="shrink-0" style={{ width: 'var(--panel-titlebar-left, 100%)' }} />
)}
- {headerVisible ? (
+ {pageHeader && headerVisible ? (
+ <div
+ className={cn(
+ 'flex min-w-0 flex-1 items-stretch overflow-hidden',
+ tabsBelowControls && 'absolute inset-x-0 bottom-0 h-7'
+ )}
+ data-panel-page-header=""
+ >
+ <PaneTab active>{pageHeader()}</PaneTab>
+ </div>
+ ) : headerVisible ? (
<ZoneMenu {...zoneMenu}>
<PaneTabStrip
className={cn('flex-1', tabsBelowControls && 'absolute inset-x-0 bottom-0')}
diff --git a/apps/desktop/src/plugins/kanban/board-switcher.tsx b/apps/desktop/src/plugins/kanban/board-switcher.tsx
index b7196283522..cbc18f69e20 100644
--- a/apps/desktop/src/plugins/kanban/board-switcher.tsx
+++ b/apps/desktop/src/plugins/kanban/board-switcher.tsx
@@ -1,8 +1,6 @@
/**
- * Titlebar board switcher — the board page projects this into `titleBar.center`
- * (where chat shows the session-title dropdown) via `<Contribute>`, so it
- * exists exactly while the page is mounted — no route sniffing. Same chrome as
- * the session title: quiet label + chevron, menu on click.
+ * Board switcher projected through `titleBar.center` into the workspace
+ * panel's tab-header space while the board page is mounted.
*/
import {
@@ -338,7 +336,7 @@ export function BoardSwitcher() {
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
- <Button className="h-7 max-w-56 gap-1.5 px-2" size="sm" variant="ghost">
+ <Button className="h-full min-w-0 max-w-full gap-1.5 px-2" size="sm" variant="ghost">
<span className="min-w-0 flex-1 truncate text-[0.75rem] font-medium leading-none">{label}</span>
{typeof current?.total === 'number' && (
<span className="text-[0.6875rem] tabular-nums text-(--ui-text-quaternary)">{current.total}</span>