The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): let a Bot Mode chat be dragged into a split pane (#109684)
Luna25dc2d3440ba
diff --git a/apps/desktop/e2e/bot-chat-split-drag.spec.ts b/apps/desktop/e2e/bot-chat-split-drag.spec.tsnew file mode 100644index 00000000000..1c21a248af8--- /dev/null+++ b/apps/desktop/e2e/bot-chat-split-drag.spec.ts@@ -0,0 +1,230 @@+import fs from 'node:fs'+import path from 'node:path'++import {+ buildAppEnv,+ createSandbox,+ launchDesktop,+ waitForAppReady,+ writeEnvFile,+ writeMockProviderConfig,+ type MockBackendFixture+} from './fixtures'+import { startMockServer } from '../../../tests-js/scripts/mock-server'+import { RealSessionBuilder } from './real-session-builder'+import { expect, test } from './test'++// Regression for upstream #109684 (Desktop Bot Mode):+//+// 1. a bot chat is an ordinary tab in the main strip, so dragging its tab+// onto the workspace edge must produce a usable, visible split pane --+// never a hole in the pane tree, never a chat that silently vanishes;+// 2. closing that tab and reopening the bot from the BOTS roster must bring+// the same chat back.+//+// A `+` side thread is opened first (Control+t, same trick as+// bot-mode-tab-shows-bot-name.spec.ts) so the main zone has a tab strip: with a+// single lone pane the strip is hidden and there is nothing to drag.++type Page = MockBackendFixture['page']++type ZoneDump = {+ group: string+ rect: [number, number, number, number]+ tabs: { id: string; label: string }[]+ hasStrip: boolean+ stripId: string | null+ hasContent: boolean+}++let fixture: MockBackendFixture | null = null++async function openBots(page: Page): Promise<void> {+ const tab = page+ .getByRole('button', { name: 'Bots', exact: true })+ .or(page.getByRole('tab', { name: 'Bots', exact: true }))+ .first()++ await tab.click()+ await expect(page.getByRole('button', { name: 'New bot or group chat' })).toBeVisible({ timeout: 60_000 })+}++async function openUntil(action: () => Promise<void>, expected: () => Promise<void>, attempts = 3): Promise<void> {+ for (let attempt = 1; ; attempt += 1) {+ await action()++ try {+ await expected()++ return+ } catch (error) {+ if (attempt >= attempts) {+ throw error+ }+ }+ }+}++async function seedBot(hermesHome: string, mockUrl: string, name: string): Promise<void> {+ const dir = path.join(hermesHome, 'profiles', name)+ fs.mkdirSync(dir, { recursive: true })+ writeMockProviderConfig(dir, mockUrl)+ writeEnvFile(dir)++ const builder = await RealSessionBuilder.start(dir)++ try {+ await builder.createSession({ title: 'Bot Chat', turns: [`Hello ${name}`] })+ } finally {+ await builder.close()+ }+}++const ZONES = `(() => {+ return [...document.querySelectorAll('[data-tree-group]')].map(el => {+ const r = el.getBoundingClientRect()+ return {+ group: el.getAttribute('data-tree-group'),+ rect: [Math.round(r.left), Math.round(r.top), Math.round(r.width), Math.round(r.height)],+ tabs: [...el.querySelectorAll('[data-tree-tab]')].map(t => ({+ id: t.getAttribute('data-tree-tab'),+ label: (t.textContent || '').trim().slice(0, 30)+ })),+ hasStrip: Boolean(el.querySelector('[data-zone-tabstrip]')),+ stripId: el.querySelector('[data-zone-tabstrip]')?.getAttribute('data-zone-tabstrip') ?? null,+ hasContent: Boolean(el.querySelector('textarea, [contenteditable="true"], [data-pane-self-label]'))+ }+ })+})()`++const zones = (page: Page) => page.evaluate(ZONES) as Promise<ZoneDump[]>++/** A zone with real estate but nothing in it: the pane tree grew a hole. */+const deadZones = (zs: ZoneDump[]) =>+ zs.filter(z => z.rect[2] > 40 && z.rect[3] > 40 && z.tabs.length === 0 && !z.hasStrip && !z.hasContent)++const liveZones = (zs: ZoneDump[]) => zs.filter(z => z.rect[2] > 40 && z.rect[3] > 40)++const visibleTabs = (page: Page) => page.locator('[data-zone-tabstrip] [data-tree-tab]').filter({ visible: true })++const chatVisible = (page: Page, text: string) =>+ page.getByText(text, { exact: true }).filter({ visible: true }).first()++/** Open the bot's chat from the BOTS roster. */+async function openBotChatFromRoster(page: Page, name: string): Promise<void> {+ await openBots(page)++ const row = page.getByRole('button', { name: new RegExp(`^${name}\\b`, 'i') }).filter({ visible: true }).first()+ await expect(row).toBeVisible({ timeout: 30_000 })++ await openUntil(+ () => row.click(),+ () => expect(chatVisible(page, `Hello ${name}`)).toBeVisible({ timeout: 45_000 })+ )+}++/** Same, plus a `+` side thread: with a single lone pane the strip is hidden+ * and there is nothing to drag. */+async function openBotChatWithStrip(page: Page, name: string): Promise<void> {+ await openBotChatFromRoster(page, name)++ await openUntil(+ () => page.keyboard.press('Control+t'),+ async () => {+ await expect.poll(() => visibleTabs(page).count(), { timeout: 15_000 }).toBeGreaterThanOrEqual(2)+ }+ )+}++/** Slow, stepped pointer drag: the pane drag tracks pointermove. */+async function dragTo(page: Page, from: { x: number; y: number }, to: { x: number; y: number }): Promise<void> {+ 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)+}++test.beforeEach(async () => {+ const mock = await startMockServer()+ const sandbox = createSandbox('bot-chat-split')+ writeMockProviderConfig(sandbox.hermesHome, mock.url)+ writeEnvFile(sandbox.hermesHome)+ await seedBot(sandbox.hermesHome, mock.url, 'alpha')++ const { app, page } = await launchDesktop(buildAppEnv(sandbox))++ fixture = {+ app,+ page,+ mock,+ mockUrl: mock.url,+ sandbox,+ cleanup: async () => {+ await app.close().catch(() => undefined)+ await mock.close()+ sandbox.cleanup()+ }+ }+ await waitForAppReady(fixture, 120_000)+})++test.afterEach(async () => {+ await fixture?.cleanup()+ fixture = null+})++test('dragging a bot chat tab to the workspace edge yields a usable split pane', async () => {+ test.setTimeout(600_000)+ const page = fixture!.page++ await openBotChatWithStrip(page, 'alpha')+ expect(deadZones(await zones(page))).toEqual([])++ const tab = visibleTabs(page).filter({ hasText: /alpha/i }).first()+ await expect(tab).toBeVisible({ timeout: 30_000 })+ const box = (await tab.boundingBox())!+ const win = await page.evaluate(() => ({ w: window.innerWidth, h: window.innerHeight }))++ await dragTo(+ page,+ { x: box.x + box.width / 2, y: box.y + box.height / 2 },+ { 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 })++ const after = await zones(page)+ // No hole where the pane was dropped...+ 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' })+})++test('closing the bot tab and reopening it from the BOTS roster brings the chat back', async () => {+ test.setTimeout(600_000)+ const page = fixture!.page++ await openBotChatWithStrip(page, 'alpha')++ // Close the bot chat's own tab...+ const tab = visibleTabs(page).filter({ hasText: /alpha/i }).first()+ await expect(tab).toBeVisible({ timeout: 30_000 })+ await tab.locator('button[aria-label*="lose" i]').first().click({ force: true })+ await page.waitForTimeout(1500)++ // ...reopening it from the roster must bring the very same chat back, and+ // leave no hole behind in the pane tree.+ await openBotChatFromRoster(page, 'alpha')+ expect(deadZones(await zones(page))).toEqual([])+})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.tsnew file mode 100644index 00000000000..9e62c44a326--- /dev/null+++ b/apps/desktop/src/components/pane-shell/tree/renderer/bot-chat-split-drop.test.ts@@ -0,0 +1,176 @@+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')+ })+})diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.tsindex c2828a661a4..680f228fad0 100644--- a/apps/desktop/src/store/session-states.test.ts+++ b/apps/desktop/src/store/session-states.test.ts@@ -339,6 +339,30 @@ describe('SessionTile workspace scope', () => {expect(focusOpenSession('bot-chat', scope)).toBe('tile')})+ it('splits a Bot chat loaded in MAIN instead of silently no-oping the drop', () => {+ const scope = { workspaceMode: 'bots' as const, workspaceOwnerKey: 'bot:connection-a::alpha' }++ $selectedStoredSessionId.set('bot-chat')+ // A real open records the bot scope on the MAIN chat (which has no tile+ // to carry it). The drag handler then commits the drop with NO explicit+ // scope — the tab it drags is the workspace pane itself.+ setSessionTileWorkspaceScope('bot-chat', scope)+ openSessionTile('bot-chat', 'right', 'workspace', undefined)++ // The minted tile registers its pane (watchSessionTiles) and the drop+ // hint's reveal adopts it — here, the tree that adoption produces.+ $layoutTree.set(group(['workspace', tilePane('bot-chat')], { id: 'workspace-group' }))++ expect(focusOpenSession('bot-chat', scope)).toBe('tile')+ expect($sessionTiles.get()).toEqual([+ expect.objectContaining({+ storedSessionId: 'bot-chat',+ workspaceMode: 'bots',+ workspaceOwnerKey: 'bot:connection-a::alpha'+ })+ ])+ })+it('fronts the existing tab when compaction rotated the tip id — never a duplicate', () => {// The tile was opened when seg-2 was the tip; the conversation has since// rotated to seg-3 (projected row carries the full chain). Opening thediff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex 41c8967abe1..7f6ff71adc2 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -1568,9 +1568,17 @@ export function openSessionTile(// No scope on an already-open tile is a MOVE (a split drag re-docking a tab),// not a re-scope: keep the workspace it lives in instead of re-bucketing it// into Sessions — a Bot tab used to vanish from the Bot workspace on drop.- const workspaceScope: SessionTileWorkspaceScope = explicitScope ?? {- workspaceMode: existing?.workspaceMode ?? 'sessions'- }+ // A bot chat dragged out of MAIN has no tile (Bot Mode has no main/tile+ // distinction) and no explicit scope — the tab it rides on is the bot+ // workspace itself. Left on the sessions fallback, the "loaded in MAIN never+ // opens as a tile" guard below swallowed the drop silently. The remembered+ // bot-chat scope is the discriminator: restore it so the drop mints a real+ // tile, which the drop hint's reveal then adopts and fronts. An existing-tile+ // move keeps the tile's own scope.+ const rememberedBotScope = !explicitScope && !existing ? $botChatScopes.get()[storedSessionId] : undefined++ const workspaceScope: SessionTileWorkspaceScope = explicitScope ??+ rememberedBotScope ?? { workspaceMode: existing?.workspaceMode ?? 'sessions' }// Opening a session in a tab/tile is "reading" it — clear its unread dot// exactly like main-thread resume does. Previously only