The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): don't trust DEC 2026 synchronized output under Zellij
Brian Sweattd509e6df2fe2
diff --git a/ui-tui/packages/hermes-ink/src/ink/terminal.test.ts b/ui-tui/packages/hermes-ink/src/ink/terminal.test.tsindex 6c4f117f921..577e42b898e 100644--- a/ui-tui/packages/hermes-ink/src/ink/terminal.test.ts+++ b/ui-tui/packages/hermes-ink/src/ink/terminal.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest'-import { needsAltScreenResizeScrollbackClear } from './terminal.js'+import { isSynchronizedOutputSupported, needsAltScreenResizeScrollbackClear } from './terminal.js'describe('terminal resize quirks', () => {it('uses a deeper alt-screen resize clear for Apple Terminal', () => {@@ -13,3 +13,26 @@ describe('terminal resize quirks', () => {expect(needsAltScreenResizeScrollbackClear({ TERM_PROGRAM: 'iTerm.app' })).toBe(false)})})++describe('synchronized output detection', () => {+ it('does not trust an outer terminal DEC 2026 capability under Zellij', () => {+ // Zellij (like tmux) proxies/chunks the stream, so the outer WezTerm's+ // DEC 2026 support must not be trusted. Zellij sets ZELLIJ to the session+ // index — "0" for the first session — so the guard keys on presence.+ expect(isSynchronizedOutputSupported({ TERM_PROGRAM: 'WezTerm', ZELLIJ: '0' })).toBe(false)+ expect(isSynchronizedOutputSupported({ TERM_PROGRAM: 'WezTerm', ZELLIJ: '1' })).toBe(false)+ })++ it('does not trust an outer terminal DEC 2026 capability under tmux', () => {+ expect(isSynchronizedOutputSupported({ TERM_PROGRAM: 'WezTerm', TMUX: '/tmp/tmux-1/default,1,0' })).toBe(false)+ })++ it('still reports support for a DEC 2026 terminal with no multiplexer', () => {+ expect(isSynchronizedOutputSupported({ TERM_PROGRAM: 'WezTerm' })).toBe(true)+ expect(isSynchronizedOutputSupported({ TERM_PROGRAM: 'iTerm.app' })).toBe(true)+ })++ it('reports no support for an unknown terminal', () => {+ expect(isSynchronizedOutputSupported({ TERM: 'xterm-256color' })).toBe(false)+ })+})diff --git a/ui-tui/packages/hermes-ink/src/ink/terminal.ts b/ui-tui/packages/hermes-ink/src/ink/terminal.tsindex 5a3ae3906d0..1f709c4e5b2 100644--- a/ui-tui/packages/hermes-ink/src/ink/terminal.ts+++ b/ui-tui/packages/hermes-ink/src/ink/terminal.ts@@ -67,16 +67,26 @@ export function isProgressReportingAvailable(): boolean {* Checks if the terminal supports DEC mode 2026 (synchronized output).* When supported, BSU/ESU sequences prevent visible flicker during redraws.*/-export function isSynchronizedOutputSupported(): boolean {+export function isSynchronizedOutputSupported(env: NodeJS.ProcessEnv = process.env): boolean {// tmux parses and proxies every byte but doesn't implement DEC 2026.// BSU/ESU pass through to the outer terminal but tmux has already// broken atomicity by chunking. Skip to save 16 bytes/frame + parser work.- if (process.env.TMUX) {+ if (env.TMUX) {return false}- const termProgram = process.env.TERM_PROGRAM- const term = process.env.TERM+ // Zellij is the same class of hazard as tmux: it sits between us and the+ // outer terminal, parsing/proxying (and chunking) the stream, so we can't+ // trust the outer terminal's DEC 2026 support advertised via TERM_PROGRAM+ // (e.g. WezTerm). Trusting it wraps frames in BSU/ESU that Zellij has+ // already broken atomicity on, repeating old frames into scrollback.+ // Zellij sets ZELLIJ to the session index (e.g. "0"), so guard on presence.+ if (env.ZELLIJ) {+ return false+ }++ const termProgram = env.TERM_PROGRAM+ const term = env.TERM// Modern terminals with known DEC 2026 supportif (@@ -92,7 +102,7 @@ export function isSynchronizedOutputSupported(): boolean {}// kitty sets TERM=xterm-kitty or KITTY_WINDOW_ID- if (term?.includes('kitty') || process.env.KITTY_WINDOW_ID) {+ if (term?.includes('kitty') || env.KITTY_WINDOW_ID) {return true}@@ -112,17 +122,17 @@ export function isSynchronizedOutputSupported(): boolean {}// Zed uses the alacritty_terminal crate which supports DEC 2026- if (process.env.ZED_TERM) {+ if (env.ZED_TERM) {return true}// Windows Terminal- if (process.env.WT_SESSION) {+ if (env.WT_SESSION) {return true}// VTE-based terminals (GNOME Terminal, Tilix, etc.) since VTE 0.68- const vteVersion = process.env.VTE_VERSION+ const vteVersion = env.VTE_VERSIONif (vteVersion) {const version = parseInt(vteVersion, 10)