Skip to content

The agent that grows with you

fix(desktop): stop the main zone vanishing behind Bot Mode

Brooklyn Nicholson35b53af10d61
diff --git a/apps/desktop/src/app/chat/pane-mirror.test.ts b/apps/desktop/src/app/chat/pane-mirror.test.ts
deleted file mode 100644
index eeceb089948..00000000000
--- a/apps/desktop/src/app/chat/pane-mirror.test.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import { atom } from 'nanostores'
-import { afterEach, describe, expect, it } from 'vitest'
-
-import { contributesToWorkspace } from '@/components/pane-shell/workspace-scope'
-import { registry } from '@/contrib/registry'
-
-import { paneMirror } from './pane-mirror'
-
-interface Tile {
- id: string
- owner?: string
-}
-
-const cleanupSources: Array<ReturnType<typeof atom<Tile[]>>> = []
-let sequence = 0
-
-function setup(options: {
- workspaceMode?: 'sessions' | 'bots' | ((tile: Tile) => 'sessions' | 'bots' | undefined)
- workspaceOwnerKey?: string | ((tile: Tile) => string | undefined)
-}) {
- const source = atom<Tile[]>([])
- const prefix = `pane-mirror-scope-${sequence++}`
- cleanupSources.push(source)
-
- paneMirror<Tile>({
- source,
- key: tile => tile.id,
- prefix,
- minWidth: '10rem',
- title: key => key,
- render: () => null,
- close: () => undefined,
- ...options
- })()
-
- return {
- source,
- contribution: (id: string) => registry.getArea('panes').find(entry => entry.id === `${prefix}:${id}`)
- }
-}
-
-afterEach(() => {
- for (const source of cleanupSources.splice(0)) {
- source.set([])
- }
-})
-
-describe('paneMirror workspace scope', () => {
- it('forwards a static workspace mode', () => {
- const mirror = setup({ workspaceMode: 'sessions' })
- mirror.source.set([{ id: 'one' }])
-
- expect(mirror.contribution('one')).toMatchObject({
- workspaceMode: 'sessions',
- workspaceOwnerKey: undefined
- })
- })
-
- it('resolves owner callbacks per tile and refreshes an unchanged title', () => {
- const mirror = setup({
- workspaceMode: 'bots',
- workspaceOwnerKey: tile => tile.owner
- })
-
- mirror.source.set([{ id: 'one', owner: 'connection-a::default' }])
- expect(mirror.contribution('one')?.workspaceOwnerKey).toBe('connection-a::default')
-
- mirror.source.set([{ id: 'one', owner: 'connection-b::default' }])
- expect(mirror.contribution('one')?.workspaceOwnerKey).toBe('connection-b::default')
- })
-
- it('leaves existing callers unscoped when options are omitted', () => {
- const mirror = setup({})
- mirror.source.set([{ id: 'one' }])
-
- expect(mirror.contribution('one')).toMatchObject({
- workspaceMode: undefined,
- workspaceOwnerKey: undefined
- })
- })
-
- it('keeps an unscoped Browser tile visible in Bot Mode', () => {
- const mirror = setup({})
- mirror.source.set([{ id: 'url:browser' }])
-
- const pane = mirror.contribution('url:browser')
-
- expect(contributesToWorkspace(pane, 'sessions')).toBe(true)
- expect(contributesToWorkspace(pane, 'bots', 'bot:connection-a::default')).toBe(true)
- })
-
- it('hides a Sessions-only Browser tile from Bot Mode', () => {
- const mirror = setup({ workspaceMode: 'sessions' })
- mirror.source.set([{ id: 'url:browser' }])
-
- const pane = mirror.contribution('url:browser')
-
- expect(contributesToWorkspace(pane, 'sessions')).toBe(true)
- expect(contributesToWorkspace(pane, 'bots', 'bot:connection-a::default')).toBe(false)
- })
-})
diff --git a/apps/desktop/src/app/chat/pane-mirror.ts b/apps/desktop/src/app/chat/pane-mirror.ts
index c0886ff7711..96657794ee3 100644
--- a/apps/desktop/src/app/chat/pane-mirror.ts
+++ b/apps/desktop/src/app/chat/pane-mirror.ts
@@ -12,23 +12,13 @@ import type { ReactElement, ReactNode, PointerEvent as ReactPointerEvent } from
import { registerPaneCloser, removeTreePane, treePanesWithPrefix } from '@/components/pane-shell/tree/store'
import type { MenuKit } from '@/components/ui/actions-menu'
import { registry } from '@/contrib/registry'
-import type { WorkspaceMode } from '@/contrib/types'
import type { TileDock } from '@/store/session-states'
-type WorkspaceValue<T, V> = V | ((tile: T) => V | undefined)
-
-const workspaceValue = <T, V>(value: WorkspaceValue<T, V> | undefined, tile: T): V | undefined =>
- typeof value === 'function' ? (value as (tile: T) => V | undefined)(tile) : value
-
export interface PaneMirror<T> {
/** Reactive source list. */
source: ReadableAtom<T[]>
/** Extra atoms whose changes should re-sync (e.g. titles living elsewhere). */
also?: ReadableAtom<unknown>[]
- /** Workspace surface this tile belongs to. Omit for a global pane. */
- workspaceMode?: WorkspaceValue<T, WorkspaceMode>
- /** Exact opaque owner inside Bot Mode. Omit outside an owner-scoped pane. */
- workspaceOwnerKey?: WorkspaceValue<T, string>
/** Stable key + pane-id seed for a tile. */
key: (tile: T) => string
/** Pane-id namespace — the id is `${prefix}:${key}`. */
@@ -67,10 +57,7 @@ export interface PaneMirror<T> {
/** Build a `watch*` fn: syncs once, then re-syncs on every source/also change.
* Module-level state lives in the returned closure, so call it once per app. */
export function paneMirror<T>(cfg: PaneMirror<T>): () => void {
- const registered = new Map<
- string,
- { dispose: () => void; title: string; workspaceMode?: WorkspaceMode; workspaceOwnerKey?: string }
- >()
+ const registered = new Map<string, { dispose: () => void; title: string }>()
const paneId = (key: string) => `${cfg.prefix}:${key}`
@@ -81,17 +68,10 @@ export function paneMirror<T>(cfg: PaneMirror<T>): () => void {
for (const tile of tiles) {
const key = cfg.key(tile)
const title = cfg.title(key)
- const workspaceMode = workspaceValue(cfg.workspaceMode, tile)
- const workspaceOwnerKey = workspaceValue(cfg.workspaceOwnerKey, tile)
const current = registered.get(key)
// register() replaces same-id in place — safe for live title refreshes.
- if (
- current &&
- current.title === title &&
- current.workspaceMode === workspaceMode &&
- current.workspaceOwnerKey === workspaceOwnerKey
- ) {
+ if (current && current.title === title) {
continue
}
@@ -119,12 +99,10 @@ export function paneMirror<T>(cfg: PaneMirror<T>): () => void {
tabMenuPrefix: cfg.tabMenuPrefix?.(key),
tabWrap: cfg.tabWrap ? (tab: ReactElement) => cfg.tabWrap!(key, tab) : undefined
},
- render: () => cfg.render(key),
- workspaceMode,
- workspaceOwnerKey
+ render: () => cfg.render(key)
})
- registered.set(key, { dispose, title, workspaceMode, workspaceOwnerKey })
+ registered.set(key, { dispose, title })
if (!current) {
registerPaneCloser(paneId(key), () => cfg.close(key))
diff --git a/apps/desktop/src/app/chat/preview-tile.test.ts b/apps/desktop/src/app/chat/preview-tile.test.ts
index 51073def256..d5cea44709f 100644
--- a/apps/desktop/src/app/chat/preview-tile.test.ts
+++ b/apps/desktop/src/app/chat/preview-tile.test.ts
@@ -8,7 +8,6 @@ vi.mock('./right-rail/preview-console-store', () => ({
forgetPreviewConsole: () => undefined
}))
-import { contributesToWorkspace } from '@/components/pane-shell/workspace-scope'
import { registry } from '@/contrib/registry'
import { $previewTabs, closeRightRail, noteBrowserPage, openPreview } from '@/store/preview'
@@ -22,28 +21,6 @@ afterEach(() => {
closeRightRail()
})
-// By prefix, not by a literal id: a Browser tab's id is minted per tab now
-// that there can be more than one of them.
-function browserPane() {
- return registry.getArea('panes').find(entry => entry.id.startsWith('preview-tile:url:'))
-}
-
-describe('preview tiles in Bot Mode', () => {
- it('registers the in-app Browser as a global pane so Bot Mode can show it', () => {
- openPreview(
- { kind: 'url', label: 'example.com', source: 'https://example.com', url: 'https://example.com' },
- 'explicit-link'
- )
-
- const pane = browserPane()
-
- expect(pane).toBeTruthy()
- expect(pane?.workspaceMode).toBeUndefined()
- expect(contributesToWorkspace(pane, 'sessions')).toBe(true)
- expect(contributesToWorkspace(pane, 'bots', 'bot:connection-a::default')).toBe(true)
- })
-})
-
describe('browserTabLabel', () => {
const target = { kind: 'url', label: 'Browser', source: 'about:blank', url: 'about:blank' } as const
diff --git a/apps/desktop/src/app/chat/route-tile.tsx b/apps/desktop/src/app/chat/route-tile.tsx
index f2af03527a2..1388f48c042 100644
--- a/apps/desktop/src/app/chat/route-tile.tsx
+++ b/apps/desktop/src/app/chat/route-tile.tsx
@@ -86,7 +86,6 @@ function RouteTilePane({ path }: { path: string }) {
/** Keep pane contributions mirroring `$routeTiles`. Call once from the root. */
export const watchRouteTiles = paneMirror<RouteTile>({
source: $routeTiles,
- workspaceMode: 'sessions',
key: t => t.path,
prefix: 'route-tile',
dir: t => t.dir,
diff --git a/apps/desktop/src/app/chat/session-tile.tsx b/apps/desktop/src/app/chat/session-tile.tsx
index 7678cd13b9d..d58c4584fe9 100644
--- a/apps/desktop/src/app/chat/session-tile.tsx
+++ b/apps/desktop/src/app/chat/session-tile.tsx
@@ -646,8 +646,6 @@ export function WorkspaceTabMenu({ children }: { children: React.ReactElement })
* `$sessions`). Tiles dock against main on the chosen edge, flex width. */
export const watchSessionTiles = paneMirror<SessionTile>({
source: $sessionTiles,
- workspaceMode: tile => tile.workspaceMode ?? 'sessions',
- workspaceOwnerKey: tile => tile.workspaceOwnerKey,
// $projectTree: a tile whose session is older than the recents page resolves
// its title through the tree, which loads after the tiles register. (The tab's
// status dot subscribes to color/state itself, so it needs no `also` entry.)
diff --git a/apps/desktop/src/app/contrib/controller.tsx b/apps/desktop/src/app/contrib/controller.tsx
index 30fd949c5ea..8c19c58eccf 100644
--- a/apps/desktop/src/app/contrib/controller.tsx
+++ b/apps/desktop/src/app/contrib/controller.tsx
@@ -177,7 +177,6 @@ registry.registerMany([
{
id: 'workspace',
area: 'panes',
- workspaceMode: 'sessions',
// Live-retitled to the loaded session by syncWorkspaceTitle below.
title: NEW_SESSION_TITLE,
data: {
@@ -488,7 +487,6 @@ const syncWorkspaceTitle = () => {
registry.register({
id: 'workspace',
area: 'panes',
- workspaceMode: 'sessions',
// The placeholder, not the draft's live name — `tabTitle` below renders
// that. Keeping it here would re-register the pane on every keystroke.
title: stored ? storedSessionTitle(stored) : NEW_SESSION_TITLE,
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index 723fabe8995..b51b680838e 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -45,7 +45,7 @@ import { requestVoiceConversationStart } from '@/store/composer'
import { $activeConnectionId } from '@/store/connections'
import { $cronReviewRequest, setCronFocusJobId } from '@/store/cron'
import { $pinnedSessionIds, pinSession, restoreWorktree, unpinSession } from '@/store/layout'
-import { notify, notifyError } from '@/store/notifications'
+import { notifyError } from '@/store/notifications'
import { $previewTarget } from '@/store/preview'
import {
$activeGatewayProfile,
@@ -874,24 +874,17 @@ export function ContribWiring({ children }: { children: ReactNode }) {
// the sidebar until its first message persists a turn and a refresh surfaces
// it — Cursor-style. Every click opens a fresh "New session" tab (multiple
// empty tabs are fine since none touch the session list).
+ //
+ // Bot Mode aims the "+" at the selected bot's own profile. Anything short of
+ // an exact route — a group chat's `blocked` target, an orphaned roster row —
+ // falls THROUGH to the ordinary session rather than refusing: the main strip
+ // carries plain session tabs alongside bot chats, so a "+" there must never
+ // be dead just because the sidebar's current selection has nowhere to route.
const openNewSessionTab = useCallback(() => {
- const workspaceMode = $workspaceMode.get()
const workspaceOwnerKey = $workspaceOwnerKey.get()
const workspaceNewSessionTarget = $workspaceNewSessionTarget.get()
- if (workspaceMode === 'bots') {
- if (workspaceNewSessionTarget?.kind !== 'route' || !workspaceOwnerKey) {
- notify({
- kind: 'info',
- message:
- workspaceNewSessionTarget?.kind === 'blocked'
- ? workspaceNewSessionTarget.message
- : 'Select a Bot or group first.'
- })
-
- return
- }
-
+ if ($workspaceMode.get() === 'bots' && workspaceNewSessionTarget?.kind === 'route' && workspaceOwnerKey) {
void openNewSessionTile('center', {
listed: false,
route: workspaceNewSessionTarget.route,
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/main-placement-floor.test.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/main-placement-floor.test.tsx
new file mode 100644
index 00000000000..a23e3244c4f
--- /dev/null
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/main-placement-floor.test.tsx
@@ -0,0 +1,98 @@
+import { cleanup, render } from '@testing-library/react'
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { registry } from '@/contrib/registry'
+import { stubResizeObserver } from '@/test/jsdom'
+
+import { group, split } from '../model'
+import { $hiddenTreePanes, $layoutTree } from '../store'
+
+import { subtreeGone, type TrackContext } from './track-model'
+import { TreeSplit } from './tree-split'
+
+// Ground truth for "the main pane always shows, no matter what". Emptying the
+// main strip must never let a sibling absorb the center — the failure Bot Mode
+// shipped, where closing the last bot chat left the roster sidebar stretched
+// across the whole window. Chrome toggles over a tool panel must still collapse.
+
+beforeAll(() => {
+ stubResizeObserver()
+ // jsdom lacks CSS.escape, which tab-strip-scroll uses in a layout effect.
+ vi.stubGlobal('CSS', { ...globalThis.CSS, escape: (value: string) => value })
+})
+
+const disposers: (() => void)[] = []
+
+beforeEach(() => {
+ window.localStorage.clear()
+ $hiddenTreePanes.set(new Set())
+
+ for (const [id, data] of [
+ ['sessions', { placement: 'left', width: '237px' }],
+ ['workspace', { placement: 'main', uncloseable: true }],
+ ['session-tile:a', { placement: 'main' }],
+ ['terminal', { placement: 'bottom', height: '38vh' }]
+ ] as const) {
+ disposers.push(registry.register({ area: 'panes', data, id, render: () => null, title: id }))
+ }
+})
+
+afterEach(() => {
+ cleanup()
+ $hiddenTreePanes.set(new Set())
+ $layoutTree.set(null)
+ disposers.splice(0).forEach(dispose => dispose())
+})
+
+/** The split-child WRAPPER the renderer sizes — `display:none` on it is what
+ * hands a zone's space to its siblings. */
+const zoneWrapper = (groupId: string) =>
+ document.querySelector<HTMLElement>(`[data-tree-group="${groupId}"]`)?.closest<HTMLElement>('[style]')
+
+const ctx = (gone: string[]): TrackContext => ({
+ overrides: {},
+ paneFor: id => registry.getArea('panes').find(pane => pane.id === id),
+ paneGone: id => gone.includes(id)
+})
+
+describe('subtreeGone', () => {
+ it('keeps a main-bearing subtree even when every one of its panes is gone', () => {
+ const main = group(['workspace', 'session-tile:a'], { id: 'grp-main' })
+
+ expect(subtreeGone(main, ctx(['workspace', 'session-tile:a']))).toBe(false)
+ })
+
+ it('still collapses a tool zone whose panes a chrome toggle hid', () => {
+ expect(subtreeGone(group(['terminal'], { id: 'grp-tools' }), ctx(['terminal']))).toBe(true)
+ })
+
+ it('still collapses a main pane whose plugin has not registered yet', () => {
+ // No contribution means no placement to read — the zone stays folded until
+ // the plugin loads rather than flashing an empty placeholder.
+ expect(subtreeGone(group(['plugin-workspace:late'], { id: 'grp-late' }), ctx(['plugin-workspace:late']))).toBe(true)
+ })
+})
+
+describe('the main placement floor in the renderer', () => {
+ it('renders the main zone with every main tab hidden, and leaves tool zones absorbable', () => {
+ const tree = split('row', [
+ group(['sessions'], { id: 'grp-sessions' }),
+ split('column', [
+ group(['workspace', 'session-tile:a'], { id: 'grp-main' }),
+ group(['terminal'], { id: 'grp-tools' })
+ ])
+ ])
+
+ $layoutTree.set(tree)
+ $hiddenTreePanes.set(new Set(['workspace', 'session-tile:a', 'terminal']))
+
+ render(<TreeSplit node={tree} root rootRow />)
+
+ const main = zoneWrapper('grp-main')
+
+ expect(main).toBeTruthy()
+ expect(main!.style.display).not.toBe('none')
+ expect(zoneWrapper('grp-sessions')?.style.display).not.toBe('none')
+ expect(zoneWrapper('grp-tools')?.style.display).toBe('none')
+ })
+})
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 1a0dacc0230..a6be611dd85 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
@@ -47,6 +47,11 @@ export interface PaneSizing {
interface PaneChrome extends PaneSizing {
/** Leaves the grid on narrow viewports; revealed as an edge overlay. */
collapsible?: boolean
+ /** Arrive minimized — a rail tab rather than an open zone. For a pane that
+ * docks to an edge this is the vertical strip; the user's first expand is
+ * persisted on the zone and wins from then on. Applied when the pane ENTERS
+ * the tree, not on every boot, so it is a default and not an invariant. */
+ defaultCollapsed?: boolean
/** Extra ids accepted from PANE_TOGGLE_REVEAL_EVENT (the real app's pane
* ids, e.g. `chat-sidebar` for `sessions`). */
revealAliases?: string[]
@@ -283,11 +288,27 @@ export function fixedTrackSize(node: LayoutNode, axis: 'row' | 'column', ctx: Tr
return cssMax(sizes) ?? null
}
-/** True when every pane in the subtree is hidden/narrow-collapsed. */
+/**
+ * True when every pane in the subtree is hidden/narrow-collapsed — the zone
+ * renders `display:none` and its siblings absorb the space.
+ *
+ * MAIN IS THE FLOOR. A subtree that hosts a registered `placement: 'main'`
+ * pane never goes, however many of its tabs are gone: absorbing the main zone
+ * leaves the window with nothing but chrome, and the sidebar stretched across
+ * where the app used to be. (Bot Mode reached exactly that state by filtering
+ * every sessions-scoped tile out of the center and then closing its last bot
+ * chat.) An emptied main zone renders its own placeholder instead. Chrome
+ * toggles over a terminal, a review rail or an unregistered plugin pane still
+ * collapse and still hand their space to their neighbors.
+ */
export function subtreeGone(node: LayoutNode, ctx: TrackContext): boolean {
const ids = allPaneIds(node)
- return ids.length > 0 && ids.every(ctx.paneGone)
+ if (ids.length === 0 || !ids.every(ctx.paneGone)) {
+ return false
+ }
+
+ return !ids.some(id => paneChrome(ctx.paneFor(id)).placement === 'main')
}
/**
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 354ab456232..d5f9428a4ca 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
@@ -39,7 +39,6 @@ import { hiddenPaneProps, PaneGroupContext, PaneLifecycleContext, PaneVisibleCon
import {
$workspaceMode,
$workspaceOwnerKey,
- contributesToWorkspace,
rememberActivePane,
resolveRememberedActivePane,
workspaceScopeKey
@@ -268,10 +267,7 @@ export function TreeGroup({
// Edit mode forces toggle-hidden panes visible so they can be rearranged
// (mirrors tree-split's paneGone) — restores itself on exit.
const paneShown = (id: string) =>
- Boolean(paneFor(id)) &&
- contributesToWorkspace(paneFor(id), workspaceMode, workspaceOwnerKey) &&
- (editMode || !hiddenPanes.has(id)) &&
- !(narrow && paneChrome(paneFor(id)).collapsible)
+ Boolean(paneFor(id)) && (editMode || !hiddenPanes.has(id)) && !(narrow && paneChrome(paneFor(id)).collapsible)
const shown = node.panes.filter(paneShown)
const memoryKey = workspaceScopeKey(workspaceMode, workspaceOwnerKey)
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx
index c72faa80f85..15b44edf02c 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-split.tsx
@@ -17,7 +17,6 @@ import { cn } from '@/lib/utils'
import { $paneStates, type PaneStateSnapshot, setPaneHeightOverride, setPaneWidthOverride } from '@/store/panes'
import { $layoutEditMode } from '../../edit-mode'
-import { $workspaceMode, $workspaceOwnerKey, contributesToWorkspace } from '../../workspace-scope'
import type { LayoutNode, SplitNode } from '../model'
import { allPaneIds } from '../model'
import {
@@ -92,8 +91,6 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: boo
const panes = useContributions('panes')
const hiddenPanes = useStore($hiddenTreePanes)
const narrow = useStore($narrowViewport)
- const workspaceMode = useStore($workspaceMode)
- const workspaceOwnerKey = useStore($workspaceOwnerKey)
// Scoped to THIS subtree's panes: a sash drag writes size overrides on every
// pointermove, but only the splits whose subtree actually resized should
// re-render — not every split in the tree.
@@ -128,10 +125,7 @@ export function TreeSplit({ node, root, rootRow }: { node: SplitNode; root?: boo
// closed) visible so they're rearrangeable — only truly-absent (unregistered)
// or narrow-collapsed panes stay gone. Restores itself on exit (render-only).
const paneGone = (id: string) =>
- !paneFor(id) ||
- !contributesToWorkspace(paneFor(id), workspaceMode, workspaceOwnerKey) ||
- (!editMode && hiddenPanes.has(id)) ||
- (narrow && Boolean(paneChrome(paneFor(id)).collapsible))
+ !paneFor(id) || (!editMode && hiddenPanes.has(id)) || (narrow && Boolean(paneChrome(paneFor(id)).collapsible))
const trackCtx: TrackContext = { paneFor, paneGone, overrides }
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/workspace-scope.test.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/workspace-scope.test.tsx
deleted file mode 100644
index 1f88eb5628c..00000000000
--- a/apps/desktop/src/components/pane-shell/tree/renderer/workspace-scope.test.tsx
+++ /dev/null
@@ -1,139 +0,0 @@
-import { act, type ReactNode } from 'react'
-import { createRoot, type Root } from 'react-dom/client'
-import { afterEach, describe, expect, it, vi } from 'vitest'
-
-import { setWorkspaceScope } from '@/components/pane-shell/workspace-scope'
-import { registry } from '@/contrib/registry'
-
-import type { GroupNode } from '../model'
-
-import { TreeGroup } from './tree-group'
-
-let root: null | Root = null
-let container: HTMLDivElement | null = null
-const disposers: Array<() => void> = []
-
-function render(ui: ReactNode) {
- if (!container) {
- container = globalThis.document.createElement('div')
- globalThis.document.body.append(container)
- root = createRoot(container)
- }
-
- act(() => root!.render(ui))
-}
-
-function register(
- id: string,
- title: string,
- scope: { workspaceMode?: 'sessions' | 'bots'; workspaceOwnerKey?: string } = {}
-) {
- disposers.push(
- registry.register({
- area: 'panes',
- data: { placement: 'main' },
- id,
- render: () => <div>{title} content</div>,
- title,
- ...scope
- })
- )
-}
-
-const group = (active: string): GroupNode => ({
- active,
- id: 'workspace-scope-zone',
- panes: ['session-a', 'bot-a', 'bot-b'],
- tabStrip: 'always',
- type: 'group'
-})
-
-const visibleTabs = () =>
- [...globalThis.document.querySelectorAll<HTMLElement>('[data-tree-tab]')].map(tab => tab.dataset.treeTab)
-
-afterEach(() => {
- if (root) {
- act(() => root!.unmount())
- }
-
- container?.remove()
- disposers.splice(0).forEach(dispose => dispose())
- act(() => {
- setWorkspaceScope('sessions')
- })
- root = null
- container = null
- vi.unstubAllGlobals()
-})
-
-describe('TreeGroup workspace scope', () => {
- it('renders only the current workspace owner and restores owner activity', () => {
- vi.stubGlobal('CSS', { escape: (value: string) => value })
- register('session-a', 'Session A', { workspaceMode: 'sessions' })
- register('bot-a', 'Bot A', { workspaceMode: 'bots', workspaceOwnerKey: 'connection-a::default' })
- register('bot-b', 'Bot B', { workspaceMode: 'bots', workspaceOwnerKey: 'connection-b::default' })
-
- render(<TreeGroup node={group('session-a')} parentAxis="column" />)
- expect(visibleTabs()).toEqual(['session-a'])
- expect(container?.textContent).toContain('Session A content')
-
- act(() => setWorkspaceScope('bots', 'connection-a::default'))
- render(<TreeGroup node={group('bot-a')} parentAxis="column" />)
- expect(visibleTabs()).toEqual(['bot-a'])
- expect(container?.textContent).toContain('Bot A content')
-
- act(() => setWorkspaceScope('bots', 'connection-b::default'))
- render(<TreeGroup node={group('bot-b')} parentAxis="column" />)
- expect(visibleTabs()).toEqual(['bot-b'])
- expect(container?.textContent).toContain('Bot B content')
-
- act(() => setWorkspaceScope('bots', 'connection-a::default'))
- render(<TreeGroup node={group('bot-b')} parentAxis="column" />)
- expect(visibleTabs()).toEqual(['bot-a'])
- expect(container?.textContent).toContain('Bot A content')
-
- act(() => setWorkspaceScope('sessions'))
- render(<TreeGroup node={group('bot-b')} parentAxis="column" />)
- expect(visibleTabs()).toEqual(['session-a'])
- expect(container?.textContent).toContain('Session A content')
- })
-
- it('keeps a global Browser pane visible in Bot Mode', () => {
- vi.stubGlobal('CSS', { escape: (value: string) => value })
- register('bot-a', 'Bot A', { workspaceMode: 'bots', workspaceOwnerKey: 'connection-a::default' })
- register('preview-tile:url:browser', 'Browser')
-
- const node: GroupNode = {
- active: 'bot-a',
- id: 'workspace-scope-zone',
- panes: ['bot-a', 'preview-tile:url:browser'],
- tabStrip: 'always',
- type: 'group'
- }
-
- act(() => setWorkspaceScope('bots', 'connection-a::default'))
- render(<TreeGroup node={node} parentAxis="column" />)
-
- expect(visibleTabs()).toEqual(['bot-a', 'preview-tile:url:browser'])
- })
-
- it('hides a Sessions-only Browser pane in Bot Mode', () => {
- vi.stubGlobal('CSS', { escape: (value: string) => value })
- register('bot-a', 'Bot A', { workspaceMode: 'bots', workspaceOwnerKey: 'connection-a::default' })
- register('preview-tile:url:browser', 'Browser', { workspaceMode: 'sessions' })
-
- const node: GroupNode = {
- active: 'bot-a',
- id: 'workspace-scope-zone',
- panes: ['bot-a', 'preview-tile:url:browser'],
- tabStrip: 'always',
- type: 'group'
- }
-
- act(() => setWorkspaceScope('bots', 'connection-a::default'))
- render(<TreeGroup node={node} parentAxis="column" />)
-
- expect(visibleTabs()).toEqual(['bot-a'])
- expect(container?.textContent).not.toContain('Browser content')
- })
-})
diff --git a/apps/desktop/src/components/pane-shell/tree/store.ts b/apps/desktop/src/components/pane-shell/tree/store.ts
index 931d712003f..881ee3f34c1 100644
--- a/apps/desktop/src/components/pane-shell/tree/store.ts
+++ b/apps/desktop/src/components/pane-shell/tree/store.ts
@@ -1326,7 +1326,9 @@ function adoptContributedPanes(): void {
const panes = registry.getArea('panes')
const dataOf = (paneId: string) =>
- panes.find(c => c.id === paneId)?.data as { placement?: string; dock?: PaneDockHint } | undefined
+ panes.find(c => c.id === paneId)?.data as
+ | { defaultCollapsed?: boolean; dock?: PaneDockHint; placement?: string }
+ | undefined
const placementOf = (paneId: string) => dataOf(paneId)?.placement
const mainId = panes.find(c => placementOf(c.id) === 'main')?.id
@@ -1392,6 +1394,17 @@ function adoptContributedPanes(): void {
if (next !== tree) {
commit(next)
}
+
+ // After the commit, so the zone exists to minimize. `defaultCollapsed` is the
+ // pane's arrival state, not a standing invariant: it runs on the adoption
+ // that put the pane in the tree, and a pane already in the tree is never
+ // re-adopted — so a user's expand persists with the layout and is never
+ // overruled on a later boot.
+ for (const pane of missing) {
+ if (dataOf(pane.id)?.defaultCollapsed) {
+ setPaneCollapsed(pane.id, true)
+ }
+ }
}
/** Adopt now + on every registry change (call once from the app root). */
diff --git a/apps/desktop/src/components/pane-shell/workspace-scope.test.ts b/apps/desktop/src/components/pane-shell/workspace-scope.test.ts
index 49686f0f7bd..e90d5cb02a8 100644
--- a/apps/desktop/src/components/pane-shell/workspace-scope.test.ts
+++ b/apps/desktop/src/components/pane-shell/workspace-scope.test.ts
@@ -4,8 +4,6 @@ import {
$workspaceMode,
$workspaceNewSessionTarget,
$workspaceOwnerKey,
- contributesToWorkspace,
- filterContributionsForWorkspace,
forgetActivePane,
forgetRememberedPane,
rememberActivePane,
@@ -14,23 +12,6 @@ import {
setWorkspaceScope
} from './workspace-scope'
-interface ScopedContribution {
- id: string
- workspaceMode?: 'sessions' | 'bots'
- workspaceOwnerKey?: string
-}
-
-const contribution = (
- id: string,
- scope?: Pick<ScopedContribution, 'workspaceMode' | 'workspaceOwnerKey'>
-): ScopedContribution => ({ id, ...scope })
-
-const bot = (ownerKey: string, suffix: string) =>
- contribution(`bot:${suffix}`, {
- workspaceMode: 'bots',
- workspaceOwnerKey: ownerKey
- })
-
afterEach(() => {
setWorkspaceScope('sessions')
})
@@ -76,7 +57,7 @@ describe('workspace scope', () => {
expect($workspaceNewSessionTarget.get()).toBeNull()
})
- it('keeps a group owner explicit while blocking generic session creation', () => {
+ it('keeps a group owner explicit while publishing why it has no generic route', () => {
const target = { kind: 'blocked' as const, message: 'New group conversations start in the group composer.' }
setWorkspaceScope('bots', 'group:room-1', target)
@@ -84,73 +65,6 @@ describe('workspace scope', () => {
expect($workspaceOwnerKey.get()).toBe('group:room-1')
expect($workspaceNewSessionTarget.get()).toEqual(target)
})
-
- it('keeps global contributions visible in both modes', () => {
- expect(contributesToWorkspace(undefined, 'sessions', null)).toBe(true)
- expect(contributesToWorkspace(undefined, 'bots', 'bot-a')).toBe(true)
- })
-
- it('separates sessions and bots contributions by mode', () => {
- const sessionsOnly = contribution('sessions-pane', { workspaceMode: 'sessions' })
- const botsOnly = bot('bot-a', 'pane')
-
- expect(contributesToWorkspace(sessionsOnly, 'sessions')).toBe(true)
- expect(contributesToWorkspace(sessionsOnly, 'bots', 'bot-a')).toBe(false)
- expect(contributesToWorkspace(botsOnly, 'sessions')).toBe(false)
- expect(contributesToWorkspace(botsOnly, 'bots', 'bot-a')).toBe(true)
- })
-
- it('requires an exact non-empty owner match for bots contributions', () => {
- const scoped = bot('bot-a', 'pane')
-
- expect(contributesToWorkspace(scoped, 'bots', 'bot-b')).toBe(false)
- expect(contributesToWorkspace(scoped, 'bots', null)).toBe(false)
- expect(contributesToWorkspace(scoped, 'bots', '')).toBe(false)
- expect(contributesToWorkspace(scoped, 'bots', 'bot-a')).toBe(true)
-
- // A bots-scoped contribution with an empty owner key never participates.
- const noOwner = contribution('no-owner', { workspaceMode: 'bots' })
- expect(contributesToWorkspace(noOwner, 'bots', 'bot-a')).toBe(false)
- })
-
- it('does not collide on shared profile suffixes across connection-qualified keys', () => {
- // Same profile suffix, different connections — opaque exact strings only.
- const localProfile = bot('local:main', 'main')
- const remoteProfile = bot('ssh:server:main', 'main')
-
- expect(contributesToWorkspace(localProfile, 'bots', 'ssh:server:main')).toBe(false)
- expect(contributesToWorkspace(remoteProfile, 'bots', 'local:main')).toBe(false)
- expect(contributesToWorkspace(localProfile, 'bots', 'local:main')).toBe(true)
- expect(contributesToWorkspace(remoteProfile, 'bots', 'ssh:server:main')).toBe(true)
- })
-})
-
-describe('filterContributionsForWorkspace', () => {
- it('filters to the current mode and preserves input order', () => {
- const contributions = [
- bot('bot-a', 'zeta'),
- contribution('global-1'),
- contribution('sessions-only', { workspaceMode: 'sessions' }),
- bot('bot-a', 'alpha')
- ]
-
- expect(filterContributionsForWorkspace(contributions, 'bots', 'bot-a').map(c => c.id)).toEqual([
- 'bot:zeta',
- 'global-1',
- 'bot:alpha'
- ])
- expect(filterContributionsForWorkspace(contributions, 'sessions', null).map(c => c.id)).toEqual([
- 'global-1',
- 'sessions-only'
- ])
- })
-
- it('returns the original array reference on a no-op', () => {
- const contributions: ScopedContribution[] = [contribution('a'), contribution('b')]
-
- expect(filterContributionsForWorkspace(contributions, 'sessions', null)).toBe(contributions)
- expect(filterContributionsForWorkspace(contributions, 'bots', 'anything').length).toBe(2)
- })
})
describe('remembered active panes', () => {
diff --git a/apps/desktop/src/components/pane-shell/workspace-scope.ts b/apps/desktop/src/components/pane-shell/workspace-scope.ts
index c9770d8977c..7b62390908a 100644
--- a/apps/desktop/src/components/pane-shell/workspace-scope.ts
+++ b/apps/desktop/src/components/pane-shell/workspace-scope.ts
@@ -1,11 +1,14 @@
/**
- * Workspace scoping for contributions.
- *
- * Pure presentation-ownership helpers: which workspace surface (sessions vs
- * bots) a contribution belongs to, and — within the bots surface — which exact
- * bot it belongs to. Owner keys are opaque exact strings supplied by callers;
+ * Which workspace surface the window is looking at — sessions, or one exact
+ * bot inside Bot Mode. Owner keys are opaque exact strings supplied by callers;
* this module never parses profile names or infers connections.
*
+ * This is a SIGNAL, not a filter: consumers adapt to it — the `+` routes a new
+ * session at the selected bot's profile — but nothing here decides whether a
+ * pane renders. Scoping panes by workspace is how the main zone came to vanish
+ * when Bot Mode's last chat closed; bot chats are ordinary tabs in the main
+ * strip, beside session tabs.
+ *
* No persistence here by design: the remembered active-pane map is window-local
* memory so a switch away and back can restore where the user was, without any
* of it surviving the window.
@@ -33,12 +36,14 @@ export interface WorkspaceSessionRoute {
targetProfile?: string
}
-/** What the shared `+` / session.newTab command means in this workspace. */
+/** Where the shared `+` / session.newTab command should aim in this workspace.
+ * `blocked` states why this owner has no route of its own (a group chat, an
+ * orphaned roster row) — it never disables the `+`, which falls back to an
+ * ordinary session: bot chats and session tabs share the one main strip. */
export type WorkspaceNewSessionTarget =
{ kind: 'blocked'; message: string } | { kind: 'route'; route: WorkspaceSessionRoute }
-/** Sessions uses its established ambient behavior (`null`). Bots publishes an
- * exact route or a concise reason that a generic session is unavailable. */
+/** Sessions uses its established ambient behavior (`null`). */
export const $workspaceNewSessionTarget = atom<WorkspaceNewSessionTarget | null>(null)
/** One key for window-local active-pane memory. Owner keys stay opaque. */
@@ -71,9 +76,9 @@ function sameNewSessionTarget(a: WorkspaceNewSessionTarget | null, b: WorkspaceN
return false
}
-/** Publish one coherent presentation and creation scope without an
- * intermediate mixed frame. Sessions always retains its existing ambient
- * new-session behavior; alternate workspaces must state their intent. */
+/** Publish one coherent surface and creation scope without an intermediate
+ * mixed frame. Sessions always retains its existing ambient new-session
+ * behavior; alternate workspaces must state their intent. */
export function setWorkspaceScope(
mode: WorkspaceMode,
ownerKey: string | null = null,
@@ -99,78 +104,6 @@ export function setWorkspaceScope(
return true
}
-/**
- * The slice of {@link Contribution} metadata that scopes it to a workspace.
- * A contribution with neither field set is global: it participates in every
- * workspace, preserving pre-existing behavior.
- */
-export interface WorkspaceScope {
- /** Surface this contribution belongs to. Omit for global visibility. */
- workspaceMode?: WorkspaceMode
- /** Exact opaque owner key within the `'bots'` surface. Ignored otherwise. */
- workspaceOwnerKey?: string
-}
-
-/**
- * Whether a contribution participates in the given workspace.
- *
- * - Unscoped/global (no `workspaceMode`) => always participates.
- * - Scoped with a mode mismatch => does not participate.
- * - Sessions match => participates.
- * - Bots match => participates only when the owner key is non-empty and equals
- * the current owner key (exact string equality).
- *
- * Defaults reflect the un-switched window state when omitted.
- */
-export function contributesToWorkspace(
- scope: WorkspaceScope | undefined,
- mode: WorkspaceMode = $workspaceMode.get(),
- ownerKey: string | null = $workspaceOwnerKey.get()
-): boolean {
- const { workspaceMode, workspaceOwnerKey } = scope ?? {}
-
- if (workspaceMode == null) {
- return true
- }
-
- if (workspaceMode !== mode) {
- return false
- }
-
- if (workspaceMode === 'sessions') {
- return true
- }
-
- return Boolean(workspaceOwnerKey) && workspaceOwnerKey === ownerKey
-}
-
-/**
- * Filter contributions down to those participating in the given workspace,
- * preserving input order.
- *
- * Preserves reference identity on a no-op (every contribution participates),
- * so callers can hand the result straight to React without a wasted re-render.
- */
-export function filterContributionsForWorkspace<T extends WorkspaceScope>(
- contributions: readonly T[],
- mode: WorkspaceMode,
- ownerKey: string | null
-): readonly T[] {
- let filtered: T[] | null = null
-
- for (let i = 0; i < contributions.length; i += 1) {
- if (contributesToWorkspace(contributions[i], mode, ownerKey)) {
- filtered?.push(contributions[i])
-
- continue
- }
-
- filtered ??= contributions.slice(0, i)
- }
-
- return filtered ?? contributions
-}
-
/**
* Window-local memory of the active pane per exact workspace owner key.
* Keys are opaque exact strings; similar-looking keys never collide because
diff --git a/apps/desktop/src/contrib/types.ts b/apps/desktop/src/contrib/types.ts
index 0958073bfab..2cd87dc3d19 100644
--- a/apps/desktop/src/contrib/types.ts
+++ b/apps/desktop/src/contrib/types.ts
@@ -10,9 +10,10 @@ import type { ReactNode } from 'react'
export type ContributionSource = 'core' | (string & {})
/**
- * Which workspace surface a contribution targets. `'sessions'` is the classic
- * session workspace; `'bots'` scopes content to an individual bot identified
- * by an opaque owner key.
+ * Which workspace surface the window is looking at. `'sessions'` is the classic
+ * session workspace; `'bots'` means Bot Mode has one exact bot selected,
+ * identified by an opaque owner key. Consumers ADAPT to this — it steers where
+ * the `+` routes — but it never decides whether a pane renders.
*/
export type WorkspaceMode = 'sessions' | 'bots'
@@ -47,16 +48,4 @@ export interface Contribution {
* themes, commands — anything consumed by an engine rather than rendered.
*/
data?: unknown
- /**
- * Which workspace surface this contribution belongs to. Omit for a global
- * contribution that participates in every workspace (pre-existing behavior).
- * Presentation ownership hint only.
- */
- workspaceMode?: WorkspaceMode
- /**
- * Exact opaque owner key within the `'bots'` surface (e.g. a
- * connection-qualified profile id). Never parsed here; compared exactly.
- * Presentation ownership hint only.
- */
- workspaceOwnerKey?: string
}