fix(tui): restore terminal capability detection over ssh#31947
Open
hsn8086 wants to merge 1 commit into
Open
Conversation
opentui 0.3.0 auto-detects ssh/mosh sessions as remote and skips env-based terminal capability detection unless the host env is forwarded explicitly. Since 1.16.0 bumped opentui past that change, ssh sessions ignore TERM, COLORTERM, TMUX, and OPENTUI_FORCE_* and fall back to a 16-color floor, breaking TUI rendering. Forward the env keys opentui reads locally so capability detection matches pre-1.16 behavior while keeping remote mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #31284
Type of change
What does this PR do?
Since 1.16.0 the TUI renders broken over ssh (16-color output, wrong theme colors, no tmux awareness). 1.15.13 was fine. #31284 bisected the regression to 1.16.0.
Root cause: 1.16.0 bumped
@opentui/core0.2.16 -> 0.3.x, which includes anomalyco/opentui#1116. opentui now auto-detects ssh/mosh sessions (SSH_CONNECTION/SSH_CLIENT/SSH_TTY/MOSH_CONNECTION) as "remote" and then skips all env-based capability detection unless the embedder forwards the environment explicitly (checkEnvironmentOverridesreturns early whenremoteis set and no env map was forwarded). opencode never setsforwardEnvKeys, so over sshTERM,COLORTERM,TMUX, and even theOPENTUI_FORCE_*escape hatches are ignored:ansi256/rgbstay false and the renderer only recovers on terminals that answer XTVERSION/DECRQM probes. sshd does forwardTERM, so that information is trustworthy and dropping it is what broke rendering.Fix: pass
forwardEnvKeysto bothcreateCliRenderercall sites (main TUI andopencode runsplit-footer), using the same key list opentui reads for local sessions (opentui does not export it, so it is mirrored inpackages/tui/src/terminal-env.ts). This restores pre-1.16 capability detection over ssh while keeping remote mode and its OSC52 clipboard behavior. Local sessions resolve the identical key set, so behavior there is unchanged.How did you verify your code works?
packages/tui/test/terminal-env.test.tsspawns renderers against the pinned@opentui/corebuild with a controlled environment. WithSSH_CONNECTIONset and no forwarding:remote=true ansi256=false rgb=false(the bug, kept as a canary so the workaround can be dropped when upstream changes). With forwarding:remote=true ansi256=true rgb=true, andTMUXis detected again (unicode=wcwidth). Local sessions unchanged.bun run typecheckpasses inpackages/tuiandpackages/opencode.TERM=xterm-256color) and confirmed forwarding restores the 1.15.13 values.Screenshots / recordings
Capability probe against
@opentui/core0.3.4 withTERM=xterm-256color COLORTERM=truecolor:Checklist