Skip to content

The agent that grows with you

fix(desktop): dragging MAIN's tab into a split moves the chat instead of copying it

teknium1c6a59c20f5c3
diff --git a/apps/desktop/e2e/bot-chat-split-drag.spec.ts b/apps/desktop/e2e/bot-chat-split-drag.spec.ts
index 1c21a248af8..1ab1c265b5a 100644
--- a/apps/desktop/e2e/bot-chat-split-drag.spec.ts
+++ b/apps/desktop/e2e/bot-chat-split-drag.spec.ts
@@ -1,18 +1,19 @@
import fs from 'node:fs'
import path from 'node:path'
+import { startMockServer } from '../../../tests-js/scripts/mock-server'
+
import {
buildAppEnv,
createSandbox,
launchDesktop,
+ type MockBackendFixture,
waitForAppReady,
writeEnvFile,
- writeMockProviderConfig,
- type MockBackendFixture
+ writeMockProviderConfig
} from './fixtures'
-import { startMockServer } from '../../../tests-js/scripts/mock-server'
import { RealSessionBuilder } from './real-session-builder'
-import { expect, test } from './test'
+import { allowErrorBanners, expect, test } from './test'
// Regression for upstream #109684 (Desktop Bot Mode):
//
@@ -141,10 +142,12 @@ async function dragTo(page: Page, from: { x: number; y: number }, to: { x: numbe
await page.mouse.move(from.x, from.y)
await page.mouse.down()
const steps = 16
+
for (let i = 1; i <= steps; i += 1) {
await page.mouse.move(from.x + ((to.x - from.x) * i) / steps, from.y + ((to.y - from.y) * i) / steps)
await page.waitForTimeout(40)
}
+
await page.waitForTimeout(400)
await page.mouse.up()
await page.waitForTimeout(1500)
@@ -181,6 +184,10 @@ test.afterEach(async () => {
test('dragging a bot chat tab to the workspace edge yields a usable split pane', async () => {
test.setTimeout(600_000)
+ // Main hands over to the stacked `+` draft once the chat moves out. That
+ // draft is minted without owner metadata (#108369), so its promotion raises
+ // the pre-existing "Session controls unavailable" banner on main too.
+ allowErrorBanners()
const page = fixture!.page
await openBotChatWithStrip(page, 'alpha')
@@ -197,8 +204,6 @@ test('dragging a bot chat tab to the workspace edge yields a usable split pane',
{ x: win.w - 16, y: Math.round(win.h / 3) }
)
- console.log('AFTER DRAG:', JSON.stringify(await zones(page), null, 1))
-
// Split view means BOTH surfaces on screen at the same time: the bot chat in
// its own pane, the side thread still in the other.
await expect(chatVisible(page, 'Hello alpha')).toBeVisible({ timeout: 30_000 })
@@ -208,7 +213,14 @@ test('dragging a bot chat tab to the workspace edge yields a usable split pane',
expect(deadZones(after)).toEqual([])
// ...and the drop really split the workspace in two.
expect(liveZones(after).length).toBeGreaterThanOrEqual(2)
- await page.screenshot({ path: '/tmp/e2e-bot-drag-split.png' })
+
+ // The drag is a MOVE: a session lives in exactly one surface. Main let the
+ // chat go, so its strip carries ONE Alpha tab (the tile's) and clicking every
+ // Alpha tab never paints the transcript twice.
+ const alphaTabs = visibleTabs(page).filter({ hasText: /alpha/i })
+ await expect.poll(() => alphaTabs.count(), { timeout: 15_000 }).toBe(1)
+ await alphaTabs.first().click()
+ await expect.poll(() => page.getByText('Hello alpha', { exact: true }).filter({ visible: true }).count()).toBe(1)
})
test('closing the bot tab and reopening it from the BOTS roster brings the chat back', async () => {
diff --git a/apps/desktop/src/app/chat/session-drag.test.ts b/apps/desktop/src/app/chat/session-drag.test.ts
index c0a642b2799..2b76487df83 100644
--- a/apps/desktop/src/app/chat/session-drag.test.ts
+++ b/apps/desktop/src/app/chat/session-drag.test.ts
@@ -2,8 +2,10 @@ import type { PointerEvent as ReactPointerEvent } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { group } from '@/components/pane-shell/tree/model'
-import { $layoutTree } from '@/components/pane-shell/tree/store'
-import { openSessionTile } from '@/store/session-states'
+import { $layoutTree, closeTreePane } from '@/components/pane-shell/tree/store'
+import { requestFreshSession } from '@/store/profile'
+import { $selectedStoredSessionId } from '@/store/session'
+import { $sessionTiles, nextSessionTileForWorkspace, openSessionTile } from '@/store/session-states'
import { requestComposerInsertRefs } from './composer/focus'
import { startSessionDrag } from './session-drag'
@@ -15,7 +17,19 @@ import { startSessionDrag } from './session-drag'
* the drop has to land on the tab the user can actually see.
*/
-vi.mock('@/store/session-states', () => ({ openSessionTile: vi.fn() }))
+vi.mock('@/store/session-states', async () => {
+ const { atom } = await import('nanostores')
+
+ return { $sessionTiles: atom([]), nextSessionTileForWorkspace: vi.fn(() => null), openSessionTile: vi.fn() }
+})
+vi.mock('@/store/profile', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ requestFreshSession: vi.fn()
+}))
+vi.mock('@/components/pane-shell/tree/store', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ closeTreePane: vi.fn()
+}))
vi.mock('./composer/focus', () => ({ requestComposerInsertRefs: vi.fn() }))
const ZONE = { left: 0, top: 0, right: 1000, bottom: 800 }
@@ -81,6 +95,8 @@ beforeEach(() => {
afterEach(() => {
document.body.innerHTML = ''
$layoutTree.set(null)
+ $selectedStoredSessionId.set(null)
+ $sessionTiles.set([])
})
describe('session drop targeting across stacked tabs', () => {
@@ -125,4 +141,34 @@ describe('session drop targeting across stacked tabs', () => {
expect(requestComposerInsertRefs).not.toHaveBeenCalled()
expect(openSessionTile).not.toHaveBeenCalled()
})
+
+ // Dragging MAIN's own tab is a move: once the tile exists, main hands the
+ // chat over instead of keeping a second copy of the same transcript.
+ it('vacates main after its own tab is dropped as a split', () => {
+ const row = mountStackedTabs()
+ $selectedStoredSessionId.set('dragged')
+ vi.mocked(openSessionTile).mockImplementation(id => {
+ $sessionTiles.set([{ dir: 'right', storedSessionId: id, workspaceMode: 'bots' }] as never)
+ })
+ vi.mocked(nextSessionTileForWorkspace).mockReturnValue('visible')
+
+ dragTo(row, 980, 400)
+
+ expect(closeTreePane).toHaveBeenCalledWith('workspace')
+ expect(requestFreshSession).not.toHaveBeenCalled()
+ })
+
+ it('drops main to a fresh draft when nothing else can shift in', () => {
+ const row = mountStackedTabs()
+ $selectedStoredSessionId.set('dragged')
+ vi.mocked(openSessionTile).mockImplementation(id => {
+ $sessionTiles.set([{ dir: 'right', storedSessionId: id, workspaceMode: 'bots' }] as never)
+ })
+ vi.mocked(nextSessionTileForWorkspace).mockReturnValue('dragged')
+
+ dragTo(row, 980, 400)
+
+ expect(requestFreshSession).toHaveBeenCalled()
+ expect(closeTreePane).not.toHaveBeenCalled()
+ })
})
diff --git a/apps/desktop/src/app/chat/session-drag.ts b/apps/desktop/src/app/chat/session-drag.ts
index ae610d0c553..0b83e60ffa1 100644
--- a/apps/desktop/src/app/chat/session-drag.ts
+++ b/apps/desktop/src/app/chat/session-drag.ts
@@ -37,9 +37,17 @@ import {
type StripSnapshot,
subZonePosition
} from '@/components/pane-shell/tree/renderer/drag-session'
-import { $treeDragging, type DropHint, revealTreePane, SESSION_TILE_DRAG } from '@/components/pane-shell/tree/store'
+import {
+ $treeDragging,
+ closeTreePane,
+ type DropHint,
+ revealTreePane,
+ SESSION_TILE_DRAG
+} from '@/components/pane-shell/tree/store'
import type { EngineZone, ZoneRect } from '@/components/pane-shell/tree/zones-engine'
-import { openSessionTile, type TileDock } from '@/store/session-states'
+import { requestFreshSession } from '@/store/profile'
+import { $selectedStoredSessionId } from '@/store/session'
+import { $sessionTiles, nextSessionTileForWorkspace, openSessionTile, type TileDock } from '@/store/session-states'
import { requestComposerInsertRefs } from './composer/focus'
import { type SessionDragPayload, sessionInlineRef, sessionLabel } from './composer/inline-refs'
@@ -176,11 +184,29 @@ export function startSessionDrag(
onCommit() {
if (split) {
+ const fromMain = payload.id === $selectedStoredSessionId.get()
+
openSessionTile(payload.id, split.pos, split.anchor, split.before)
// A tile for this session may already exist (openSessionTile is
// idempotent — e.g. persisted from an earlier run): a drop must never
// feel dead, so front/unhide/un-dismiss it either way.
revealTreePane(`session-tile:${payload.id}`)
+
+ // Dragging MAIN's own tab out is a MOVE. A session lives in exactly one
+ // surface (two panes on one runtime would fight over it), so once the
+ // tile exists main lets go the way its Close does: the next stacked
+ // tab shifts in, else a fresh draft. Never promote the tile just
+ // minted — that would pull the chat straight back and read as a dead
+ // drop.
+ if (fromMain && $sessionTiles.get().some(t => t.storedSessionId === payload.id)) {
+ const next = nextSessionTileForWorkspace()
+
+ if (next && next !== payload.id) {
+ closeTreePane('workspace')
+ } else {
+ requestFreshSession()
+ }
+ }
} else if (link) {
// The "link to chat" drop: an @session chip in that surface's composer.
requestComposerInsertRefs([sessionInlineRef(payload)], { target: link })
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/bot-chat-split-drop.test.ts b/apps/desktop/src/components/pane-shell/tree/renderer/bot-chat-split-drop.test.ts
deleted file mode 100644
index 9e62c44a326..00000000000
--- a/apps/desktop/src/components/pane-shell/tree/renderer/bot-chat-split-drop.test.ts
+++ /dev/null
@@ -1,176 +0,0 @@
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
-
-import { registry } from '@/contrib/registry'
-
-import { findGroupOfPane, group, split, type LayoutNode } from '../model'
-import {
- $layoutTree,
- adoptContributedPanes,
- isPaneVisible,
- removeTreePane,
- revealTreePane
-} from '../store'
-
-interface Zone {
- active: string | undefined
- id: string
- panes: readonly string[]
-}
-
-const visibleZones = (tree: LayoutNode): Zone[] => {
- const zones: Zone[] = []
-
- const walk = (node: LayoutNode): void => {
- if (node.type === 'group') {
- const shown = node.panes.filter(id => isPaneVisible(id))
-
- if (shown.length > 0) {
- zones.push({ active: shown.includes(node.active ?? '') ? node.active : shown[0], id: node.id, panes: shown })
- }
-
- return
- }
-
- node.children.forEach(walk)
- }
-
- walk(tree)
-
- return zones
-}
-
-describe('tile-less bot chat split drop', () => {
- let disposePane: (() => void) | null = null
-
- beforeEach(() => {
- $layoutTree.set(null)
- disposePane = null
- })
-
- afterEach(() => {
- disposePane?.()
- removeTreePane('session-tile:bot-chat')
- $layoutTree.set(null)
- })
-
- it('adopts a revealed tile pane and fronts it in a real split zone', () => {
- // The tree a Bot Mode main chat + a ⌃T side thread produces: one zone,
- // two tabs. The bot chat rides the uncloseable `workspace` pane itself —
- // it has NO tile pane yet, which is what a drag out of MAIN has to fix.
- $layoutTree.set(
- group(['workspace', 'session-tile:side-thread'], {
- active: 'workspace',
- id: 'grp-main',
- tabStrip: 'auto'
- })
- )
-
- // What openSessionTile mints when the remembered bot-chat scope rescues
- // the drop: a real tile contribution with a `dock` hint naming the
- // anchor + edge. The registry/adoption pass — the same machinery
- // watchSessionTiles drives — turns the contribution into a pane.
- disposePane = registry.register({
- area: 'panes',
- data: {
- dock: { pane: 'workspace', pos: 'right' },
- minWidth: '20rem',
- placement: 'main'
- },
- id: 'session-tile:bot-chat',
- render: () => null,
- title: 'Alpha'
- })
-
- // The commit path's reveal: un-dismiss + adopt + front.
- revealTreePane('session-tile:bot-chat')
-
- const after = visibleZones($layoutTree.get()!)
-
- // BOTH surfaces stay on screen: the workspace (still holding the side
- // thread) and the new tile pane — and the drop fronted the tile.
- expect(after.length).toBeGreaterThanOrEqual(2)
-
- const chat = after.find(zone => zone.panes.includes('session-tile:bot-chat'))
-
- expect(chat).toBeDefined()
- expect(chat!.active).toBe('session-tile:bot-chat')
-
- // The dragged tab lands in its own split, not stacked into the source
- // strip (a stack would leave the side thread without a visible pane).
- expect(chat!.panes).toEqual(['session-tile:bot-chat'])
-
- // The side thread stays stacked in the workspace zone (mounted behind
- // its active tab) — the split ADDED a pane, it never dropped one.
- const workspaceGroup = findGroupOfPane($layoutTree.get()!, 'workspace')
-
- expect(workspaceGroup?.panes).toContain('session-tile:side-thread')
- })
-
- it('leaves no empty zone behind after the bot chat moves out of MAIN', () => {
- $layoutTree.set(group(['workspace', 'session-tile:side-thread'], { active: 'workspace', id: 'grp-main' }))
-
- disposePane = registry.register({
- area: 'panes',
- data: { dock: { pane: 'workspace', pos: 'right' }, placement: 'main' },
- id: 'session-tile:bot-chat',
- render: () => null,
- title: 'Alpha'
- })
-
- revealTreePane('session-tile:bot-chat')
-
- const tree = $layoutTree.get()!
-
- // Every zone on screen keeps a visible tab; nothing is stranded with
- // zero tabs and no content.
- const leaves: LayoutNode[] = []
-
- const walk = (node: LayoutNode): void => {
- if (node.type === 'group') {
- if (node.panes.length === 0) {
- leaves.push(node)
- }
-
- return
- }
-
- node.children.forEach(walk)
- }
-
- walk(tree)
-
- expect(leaves).toEqual([])
-
- const workspaceGroup = findGroupOfPane(tree, 'workspace')
-
- // The workspace never leaves the tree (it is uncloseable): the side
- // thread keeps it occupied even though the chat moved out.
- expect(workspaceGroup?.panes).toContain('session-tile:side-thread')
- })
-
- it('splits beside the dropped edge without displacing the sibling zone', () => {
- $layoutTree.set(
- split('row', [group(['workspace', 'session-tile:side-thread'], { active: 'workspace', id: 'grp-main' })])
- )
-
- disposePane = registry.register({
- area: 'panes',
- data: { dock: { pane: 'workspace', pos: 'right' }, placement: 'main' },
- id: 'session-tile:bot-chat',
- render: () => null,
- title: 'Alpha'
- })
-
- adoptContributedPanes()
- revealTreePane('session-tile:bot-chat')
-
- const tree = $layoutTree.get()!
- const chatGroup = findGroupOfPane(tree, 'session-tile:bot-chat')
- const mainGroup = findGroupOfPane(tree, 'workspace')
-
- expect(chatGroup).toBeDefined()
- expect(mainGroup).toBeDefined()
- expect(chatGroup!.id).not.toBe(mainGroup!.id)
- expect(mainGroup!.panes).toContain('session-tile:side-thread')
- })
-})