From 9e30ef224d497bd1be8f5cf19b7a8151757b9716 Mon Sep 17 00:00:00 2001 From: brooklyn! Date: Thu, 21 May 2026 21:01:04 -0500 Subject: [PATCH] fix(tui): preserve scrollback when branching sessions (#30162) Keep the visible transcript mounted after /branch switches to the new session, since the backend already carries the copied history forward. --- ui-tui/src/__tests__/createSlashHandler.test.ts | 15 +++++++++++++++ ui-tui/src/app/slash/commands/session.ts | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ui-tui/src/__tests__/createSlashHandler.test.ts b/ui-tui/src/__tests__/createSlashHandler.test.ts index 952f34fc38b..e1251a4af9f 100644 --- a/ui-tui/src/__tests__/createSlashHandler.test.ts +++ b/ui-tui/src/__tests__/createSlashHandler.test.ts @@ -222,6 +222,21 @@ describe('createSlashHandler', () => { expect(ctx.gateway.rpc).not.toHaveBeenCalled() }) + it('keeps visible scrollback when branching a TUI session', async () => { + patchUiState({ sid: 'sid-parent' }) + const rpc = vi.fn(() => Promise.resolve({ session_id: 'sid-branch', title: 'branch title' })) + const ctx = buildCtx({ gateway: { ...buildGateway(), rpc } }) + + expect(createSlashHandler(ctx)('/branch branch title')).toBe(true) + + expect(rpc).toHaveBeenCalledWith('session.branch', { name: 'branch title', session_id: 'sid-parent' }) + await vi.waitFor(() => { + expect(getUiState().sid).toBe('sid-branch') + expect(ctx.transcript.sys).toHaveBeenCalledWith('branched → branch title') + }) + expect(ctx.transcript.setHistoryItems).not.toHaveBeenCalled() + }) + it('reloads skills in the live gateway and refreshes the catalog', async () => { const rpc = vi.fn((method: string) => { if (method === 'skills.reload') { diff --git a/ui-tui/src/app/slash/commands/session.ts b/ui-tui/src/app/slash/commands/session.ts index 466505d8ceb..30ae7d8204e 100644 --- a/ui-tui/src/app/slash/commands/session.ts +++ b/ui-tui/src/app/slash/commands/session.ts @@ -212,7 +212,6 @@ export const sessionCommands: SlashCommand[] = [ void ctx.session.closeSession(prevSid) patchUiState({ sid: r.session_id }) ctx.session.setSessionStartedAt(Date.now()) - ctx.transcript.setHistoryItems([]) ctx.transcript.sys(`branched → ${r.title ?? ''}`) }) )