From 87caa1b78f509c8c2105a1856d14210fe04c77a3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 24 Mar 2026 17:02:14 +0000 Subject: [PATCH] Fix three-byte escape sequences leaking final byte into history Handle ECMA-48 escape sequences with intermediate bytes (0x20-0x2F) such as ESC ( B (select ASCII for G0), ESC ) 0 (select DEC Special Graphics for G1), and ESC # 8 (DECALN). These are commonly emitted by ncurses programs (vim, less, htop) on exit. Previously only 2 bytes were consumed, causing the final byte to leak into visibleText. --- apps/server/src/terminal/Layers/Manager.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/server/src/terminal/Layers/Manager.ts b/apps/server/src/terminal/Layers/Manager.ts index c24e451b1b..ff056669e7 100644 --- a/apps/server/src/terminal/Layers/Manager.ts +++ b/apps/server/src/terminal/Layers/Manager.ts @@ -321,6 +321,22 @@ function sanitizeTerminalHistoryChunk( continue; } + if (nextCodePoint >= 0x20 && nextCodePoint <= 0x2f) { + let cursor = index + 2; + while ( + cursor < input.length && + input.charCodeAt(cursor) >= 0x20 && + input.charCodeAt(cursor) <= 0x2f + ) { + cursor++; + } + if (cursor >= input.length) { + return { visibleText, pendingControlSequence: input.slice(index) }; + } + index = cursor + 1; + continue; + } + index += 2; continue; }