Skip to content

The agent that grows with you

fix(webapp): redraw the foreground program after a trimmed terminal replay

David Dudok de Wite5ce5600589c
diff --git a/apps/desktop/src/lib/browser-terminal.test.ts b/apps/desktop/src/lib/browser-terminal.test.ts
index 133541485bd..2afbbdeeb81 100644
--- a/apps/desktop/src/lib/browser-terminal.test.ts
+++ b/apps/desktop/src/lib/browser-terminal.test.ts
@@ -129,6 +129,19 @@ describe('persistent browser terminals', () => {
expect(resumed.sent.join('')).not.toContain('\u000c')
})
+ // A trimmed replay can start mid-way through a full-screen program; an unchanged size sends no SIGWINCH.
+ it('forces one redraw by a real size change only when resuming from a trimmed replay', async () => {
+ const api = install()
+ await api.start({ cwd: '/original', restoreKey: 'tab-one' })
+ Socket.instances[0].close(1006)
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(Socket.instances[1].sent).toEqual(['\u001b[RESIZE:80;24]'])
+ Socket.reply = socket => socket.metadata({ truncated: true })
+ Socket.instances[1].close(1006)
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(Socket.instances[2].sent).toEqual(['\u001b[RESIZE:80;23]', '\u001b[RESIZE:80;24]'])
+ })
+
it('closes explicitly with a fresh authenticated request even while disconnected', async () => {
const api = install()
const session = await api.start({ cwd: '/original', restoreKey: 'tab-one' })
diff --git a/apps/desktop/src/lib/browser-terminal.ts b/apps/desktop/src/lib/browser-terminal.ts
index aeb1f72e1eb..0e8df7b695a 100644
--- a/apps/desktop/src/lib/browser-terminal.ts
+++ b/apps/desktop/src/lib/browser-terminal.ts
@@ -68,6 +68,13 @@ function settleOpen(state: TerminalState): void {
state.openedAt = null
}
+/** A trimmed replay can start mid-way through a full-screen program's output, and an
+ * unchanged size sends no SIGWINCH: step one row away first so the program redraws. */
+function sendResumeSize(socket: WebSocket, state: TerminalState, trimmed?: boolean): void {
+ if (trimmed) {socket.send(`\u001b[RESIZE:${state.cols};${state.rows > 1 ? state.rows - 1 : state.rows + 1}]`)}
+ socket.send(`\u001b[RESIZE:${state.cols};${state.rows}]`)
+}
+
async function closeSavedShell(saved: SavedTerminal, websocketUrl: BrowserTerminalOptions['websocketUrl']): Promise<boolean> {
const url = new URL(await websocketUrl(saved.profile))
url.searchParams.set('attach', saved.terminalId)
@@ -210,7 +217,7 @@ async function dialTerminal(state: TerminalState, context: DialContext): Promise
handshakeComplete = true
// Resume query dimensions do not resize an existing server PTY.
- if (resuming) {socket.send(`\u001b[RESIZE:${state.cols};${state.rows}]`)}
+ if (resuming) {sendResumeSize(socket, state, meta.truncated)}
setStatus(state, 'open')
state.openedAt = Date.now()