Skip to content

Answer OSC 10/11 terminal-color queries from the live PTY emulator - #861

Open
drn wants to merge 1 commit into
masterfrom
argus/tui-codex-agent-view
Open

Answer OSC 10/11 terminal-color queries from the live PTY emulator#861
drn wants to merge 1 commit into
masterfrom
argus/tui-codex-agent-view

Conversation

@drn

@drn drn commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Codex's composer/history highlight background wasn't rendering inside Argus's TUI ("codex agent view text input background is missing"), even though it renders fine when Codex runs directly in a real terminal.
  • The live x/vt emulator that backs each agent pane discards any response it generates to terminal capability queries (NewDrainedEmulator drains to io.Discard — a deliberate fix for a hang bug where the emulator's internal pipe blocks forever if nobody reads it). That means an agent CLI's OSC 10/OSC 11 ("what's your foreground/background color?") queries never get an answer.
  • The pane's live emulator (newTrackedEmulatorWithCallback) now uses a new NewLiveEmulator constructor: it reports an assumed dark-terminal background/foreground color via SetBackgroundColor/SetForegroundColor, and forwards the emulator's generated query responses into the agent process's stdin via the existing TerminalAdapter.WriteInput, instead of discarding them. Responses are still drained asynchronously (same hang-avoidance guarantee), just routed to the real PTY instead of /dev/null.
  • Replay and preview emulators (scrollback browsing, task-list preview) are unchanged — they reconstruct historical output for a process that may not be live, so forwarding into them would be meaningless or cross-wired.

Root cause

Confirmed via a real Codex v0.144.5 session log captured from a live Argus task in ~/.argus/sessions/: Codex sends OSC 10/OSC 11 queries at every session start, and across every occurrence of its idle composer/placeholder text in that session, it draws zero background/reverse-video styling — it only ever colors the submitted-prompt history box unconditionally (bare \x1b[7m). That's consistent with Codex conservatively skipping a background-dependent highlight it can't safely draw without knowing the terminal's background, which lines up with the reported symptom: a real terminal (which answers OSC 11) shows the highlight; Argus (which didn't) doesn't. internal/tui/terminal/terminalpane.go:35-54 (NewDrainedEmulator) already documents the hang-avoidance drain but there was no path forwarding the emulator's auto-generated replies back into the PTY — this PR adds one for the live emulator only.

Test plan

  • New unit tests in internal/tui/terminal/terminalpane_test.go: NewLiveEmulator answers OSC 11/OSC 10 queries via the forward callback with the expected response bytes; forwardEmulatorResponse no-ops with no session and forwards via WriteInput when one is attached; the pane's live-emulator constructor end-to-end forwards a query response to an attached mock session; the replay-emulator constructor is confirmed to remain discard-only even with a live session attached.
  • make pre-pr is green (build, vet, fmt-check, lint-pr, test-cover-gate at 89.2% filtered coverage — above the 88% floor). govulncheck reports only pre-existing Go-stdlib-toolchain CVEs, confirmed identical on a clean origin/master checkout (continue-on-error in CI per gotchas/ci-gates.md).
  • OpenSpec change fix-codex-terminal-query-response authored, implemented, and archived into openspec/specs/terminal-rendering/spec.md in this same branch.

🤖 Generated with Claude Code

Argus's live x/vt emulator discards any response to terminal capability
queries (a deliberate hang-avoidance drain), which means an agent CLI's
OSC 10/11 background/foreground queries never get an answer. Codex sends
this at every session start and, per a captured session, never draws its
composer/history highlight background when it goes unanswered — matching
the reported "codex agent view text input background is missing" bug.

The live emulator now reports an assumed dark-terminal fg/bg and forwards
its generated query responses into the agent process's stdin via the
existing TerminalAdapter.WriteInput, instead of discarding them. Replay
and preview emulators are unchanged (still discard-only), since they
reconstruct historical output for a process that may not be live.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/drn/argus/internal/tui/terminal 95.43% (-0.03%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/drn/argus/internal/tui/terminal/terminalpane.go 95.56% (-0.03%) 766 (+17) 732 (+16) 34 (+1) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/drn/argus/internal/tui/terminal/terminalpane_test.go

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.

1 participant