fix(daemon): don't apply truncateAltScreen to serialized snapshots

truncateAltScreen searches for raw \x1b[?1049h transitions in PTY
streams, but checkpoint snapshotAnsi is serialized terminal state from
xterm.js which doesn't contain those sequences. Applying it to
alt-screen checkpoints returned the full TUI buffer content as
scrollbackAnsi, causing stale TUI content to be cold-restored.

For alt-screen checkpoints, return empty scrollbackAnsi instead. The
adapter already skips cold restore when scrollbackAnsi is falsy.
truncateAltScreen remains correct for the scrollback.bin fallback path
which contains raw PTY output.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo-H
2026-04-26 22:23:11 -04:00
co-authored by Orca
parent 01c6067598
commit aeebfe1a2c
+8 -9
View File
@@ -48,16 +48,15 @@ export class HistoryReader {
try {
const checkpoint = JSON.parse(readFileSync(checkpointPath, 'utf-8'))
// Why: HeadlessEmulator.getSnapshot() doesn't populate scrollbackAnsi
// (it's always ''). For alt-screen checkpoints, derive usable scrollback
// by truncating snapshotAnsi at the alt-screen boundary — same logic the
// scrollback.bin fallback uses. This ensures alt-screen cold restores
// recover normal shell output that existed before the TUI launched.
const rawScrollback = checkpoint.scrollbackAnsi ?? ''
// (it's always ''). For non-alt-screen checkpoints, snapshotAnsi IS
// the normal buffer content and is safe to use as scrollback. For
// alt-screen checkpoints, snapshotAnsi is the serialized TUI buffer
// (not raw PTY stream), so truncateAltScreen won't find transition
// sequences and would return stale TUI content. Return empty instead
// — the adapter skips cold restore when scrollbackAnsi is falsy.
const scrollbackAnsi =
rawScrollback ||
(checkpoint.modes?.alternateScreen
? this.truncateAltScreen(checkpoint.snapshotAnsi ?? '')
: (checkpoint.snapshotAnsi ?? ''))
checkpoint.scrollbackAnsi ||
(checkpoint.modes?.alternateScreen ? '' : (checkpoint.snapshotAnsi ?? ''))
return {
snapshotAnsi: checkpoint.snapshotAnsi,
scrollbackAnsi,