Skip to content

fix(tui): restore terminal capability detection over ssh#31947

Open
hsn8086 wants to merge 1 commit into
anomalyco:devfrom
hsn8086:ssh-env-forward
Open

fix(tui): restore terminal capability detection over ssh#31947
hsn8086 wants to merge 1 commit into
anomalyco:devfrom
hsn8086:ssh-env-forward

Conversation

@hsn8086

@hsn8086 hsn8086 commented Jun 11, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #31284

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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/core 0.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 (checkEnvironmentOverrides returns early when remote is set and no env map was forwarded). opencode never sets forwardEnvKeys, so over ssh TERM, COLORTERM, TMUX, and even the OPENTUI_FORCE_* escape hatches are ignored: ansi256/rgb stay false and the renderer only recovers on terminals that answer XTVERSION/DECRQM probes. sshd does forward TERM, so that information is trustworthy and dropping it is what broke rendering.

Fix: pass forwardEnvKeys to both createCliRenderer call sites (main TUI and opencode run split-footer), using the same key list opentui reads for local sessions (opentui does not export it, so it is mirrored in packages/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?

  • New test packages/tui/test/terminal-env.test.ts spawns renderers against the pinned @opentui/core build with a controlled environment. With SSH_CONNECTION set 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, and TMUX is detected again (unicode=wcwidth). Local sessions unchanged.
  • bun run typecheck passes in packages/tui and packages/opencode.
  • Reproduced the broken capability set on a real ssh session to a linux host (TERM=xterm-256color) and confirmed forwarding restores the 1.15.13 values.

Screenshots / recordings

Capability probe against @opentui/core 0.3.4 with TERM=xterm-256color COLORTERM=truecolor:

scenario remote ansi256 rgb multiplexer
local false true true none
ssh, no forwarding (current) true false false none
ssh + forwardEnvKeys (this PR) true true true none
ssh + tmux + forwardEnvKeys true true true tmux

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode terminal UI broken in DGX Spark environment

1 participant