Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(tmux): let the keyframe say which screen it captured

0xdiego257122c8077901
diff --git a/cli/src/lib/tmuxStream.spec.ts b/cli/src/lib/tmuxStream.spec.ts
index 599a1425c..ff4a769bb 100644
--- a/cli/src/lib/tmuxStream.spec.ts
+++ b/cli/src/lib/tmuxStream.spec.ts
@@ -71,6 +71,34 @@ describe('tmux snapshot row normalization', () => {
expect(snapshot).toContain('\u001b[2;5H\u001b[?7h\u001b[?25h')
})
+ it('says which screen it captured, so the receiver can scroll it', () => {
+ // A pane running a full-screen TUI is on the ALTERNATE screen, and that one fact closes both ways
+ // of scrolling when it goes unsaid: the alternate screen has no scrollback to move through (tmux
+ // reports history_size=0), and the emulator only converts the wheel into escapes for the remote
+ // application while it believes it is on that buffer. `ESC c` resets to the normal one, so a
+ // keyframe that stayed silent actively asserted the wrong screen.
+ const meta = {
+ sessionId: '$1', windowId: '@1', windowPanes: 1,
+ windowWidth: 80, windowHeight: 2, paneWidth: 80, paneHeight: 2,
+ cursorX: 0, cursorY: 0, cursorVisible: true,
+ mouseStandard: false, mouseButton: false, mouseAll: false,
+ mouseUtf8: false, mouseSgr: false,
+ }
+ const onAlt = Buffer.from(synthesizeTmuxSnapshot(
+ Buffer.from('row\n'), { ...meta, alternateOn: true },
+ )).toString()
+ expect(onAlt).toContain('\u001b[?1049h')
+ expect(onAlt).not.toContain('\u001b[?1049l')
+
+ // And said in BOTH directions: a pane that has just come out of a TUI must not be left in it, and
+ // whether RIS alone leaves the alternate buffer is emulator-dependent.
+ const onNormal = Buffer.from(synthesizeTmuxSnapshot(
+ Buffer.from('row\n'), { ...meta, alternateOn: false },
+ )).toString()
+ expect(onNormal).toContain('\u001b[?1049l')
+ expect(onNormal).not.toContain('\u001b[?1049h')
+ })
+
it('preserves a tmux-hidden hardware cursor while restoring its position', () => {
const snapshot = Buffer.from(synthesizeTmuxSnapshot(
Buffer.from('painted input\n'),
diff --git a/cli/src/lib/tmuxStream.ts b/cli/src/lib/tmuxStream.ts
index ca2212671..0c08b2d77 100644
--- a/cli/src/lib/tmuxStream.ts
+++ b/cli/src/lib/tmuxStream.ts
@@ -214,8 +214,21 @@ export function synthesizeTmuxSnapshot(
): Uint8Array {
const cursorRow = Math.max(1, Math.min(meta.paneHeight, meta.cursorY + 1))
const cursorCol = Math.max(1, Math.min(meta.paneWidth, meta.cursorX + 1))
+ // Say WHICH SCREEN this is, right after the reset that would otherwise decide it for us.
+ //
+ // `ESC c` resets to the normal buffer, so a keyframe of a pane running a full-screen TUI used to
+ // arrive describing a normal screen. The receiver believed it, and that one missing fact closed both
+ // ways of scrolling at once: the alternate screen has no scrollback to move through (tmux reports
+ // history_size=0 for it), and the emulator's wheel-to-escape handler only runs while it believes it
+ // is on the alternate buffer — so the wheel reached neither a local scrollback nor the remote
+ // application. Scrolling worked in tmux and did nothing in the window, with no error either side.
+ //
+ // Sent explicitly in both directions rather than leaning on `ESC c` for the normal case: whether RIS
+ // leaves the alternate buffer is emulator-dependent, and a pane that has just come OUT of a TUI must
+ // not be left in it.
+ const screen = meta.alternateOn ? '\u001b[?1049h' : '\u001b[?1049l'
const prefix = Buffer.from(
- '\u001bc\u001b[?25l\u001b[?7l\u001b[H\u001b[2J',
+ `\u001bc${screen}\u001b[?25l\u001b[?7l\u001b[H\u001b[2J`,
'utf8',
)
const normalizedHistory = normalizeTmuxHistoryLines(history)