Skip to content

fix(cli): preserve terminal contrast across light and dark themes - #729

Merged
mergify[bot] merged 12 commits into
matrixorigin:mainfrom
loveRhythm1990:investigate/issue-728-light-terminal
Sep 9, 2026
Merged

mergify[bot] merged 12 commits into
matrixorigin:mainfrom
loveRhythm1990:investigate/issue-728-light-terminal

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixed light foregrounds and dark panels made parts of Astra unreadable on light terminals. Use terminal-default body text, paired foreground/background surfaces, and a shared light/dark palette for welcome text, conversation input, syntax highlighting, and the exit resume hint. Keep colorful ANSI accents when the background is unknown.

Interactive startup now queries OSC 10/11 and DA1 through the existing crossterm reader before choosing the theme. This includes a vendored crossterm 0.29 patch and the follow-up fixes for startup cancellation, Esc delivery, malformed replies, initialization order, and late Sixel capability replies.

Rust CI linker setup now limits APT to the runner’s Ubuntu sources, so an unrelated Chrome repository hash mismatch cannot block all Rust jobs. Ubuntu source failures and package verification remain enforced.

Related issue

Closes #728

Change type

  • Feature
  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test
  • Build, CI, or maintenance

User and compatibility impact

  • astra defaults to automatic theme selection; ordinary users need no environment configuration. Interactive Unix terminals share a 300 ms startup response budget for colors and DA1. Missing colors fall back per channel to environment hints and terminal defaults. Explicit profiles and NO_COLOR remain supported.
  • Light/dark conversation surfaces pair foregrounds with backgrounds. Welcome-panel body text is no longer bold; section headings retain emphasis. Syntax keywords, types, punctuation and comments remain distinguishable. Stderr output uses stderr color capabilities, including the resume hint.
  • The welcome message omits the Memoria login placeholder and missing usernames instead of treating a provider/profile name as a personal name.
  • Startup Ctrl-C is registered before raw mode and consumed during asynchronous initialization; terminal restoration precedes error output. The same listener transfers to the TUI shutdown monitor. Normal-session bare Esc is immediate. Startup-only Esc lookahead is bounded to 40 ms.
  • Oversized or unterminated recognized OSC responses are quarantined; BEL, ST or Esc recovers input. Query timeouts do not become permanent negative Sixel results. Late DA1 replies use the same reader, and an active TUI never starts a competing /dev/tty probe.
  • Limits: theme selection is startup-only. A late reply split immediately after its first Esc, after the query has ended, is inherently ambiguous with keyboard input; normal-session Esc responsiveness takes precedence. If a malformed response has no terminator, Esc recovers input. See vendor/crossterm/ASTRA-PATCH.md and the configuration reference.

Architecture and complexity delta

  • Canonical owner changed or extended: existing TUI theme/palette, CLI Markdown/rendering owners, StartupTerminal, and the crossterm input reader. Signal cancellation uses the existing TUI shutdown monitor. Session, provider, policy, and database semantics are unchanged.
  • Existing implementations and callers searched: welcome/login/Markdown rendering, conversation surfaces, syntax highlighting, cleanup output, startup/session guards, both Unix input backends, filtered reads, terminal modes, and Sixel detection/rendering.
  • Superseded code, states, tables, shims, or self-only tests removed: forced-white styles, duplicate highlighting palettes, profile-name greeting fallback, global Esc delay, unconditional blocking drain reads, silent palette initialization fallback, and timeout-as-unsupported Sixel caching. Real PTY tests cover the guard, query API, poll and EventStream.
  • If parallel implementations remain, their boundary and retirement condition: the two upstream Unix backends share framing/readiness logic. The legacy Sixel probe remains only for non-TUI use. Crossterm 0.29 is a tracked, MIT-licensed local dependency patch; it adds maintenance and dependency-audit costs and should retire when a released upstream API provides equivalent input-preserving queries. Patch provenance, changed files, and re-export instructions are documented in ASTRA-PATCH.md.

Verification

  • CI setup follow-up (e9b8c71e1): executed the actual workflow shell block in an Ubuntu 24.04 amd64 Docker container. The original command failed with an injected broken third-party repository; the updated block installed mold 2.30.0 successfully. Verified both deb822 and legacy sources.list layouts, preservation of source files and existing RUSTFLAGS, and fatal failure with no RUSTFLAGS update when the selected Ubuntu source is broken. This tests repository failure isolation, not a byte-for-byte reproduction of the remote Chrome hash mismatch. python3 scripts/ci/validate_repository.py and git diff --check passed. Full Rust CI results remain pending.

  • Commands and results (local macOS arm64, offline; no live provider or credentials):

    • cargo test -p astra-cli --lib tui::terminal_startup --locked --offline -- --test-threads=2 — 14 passed.
    • cargo test -p astra-cli --lib --features crossterm/use-dev-tty tui::terminal_startup --locked --offline -- --test-threads=2 — 14 passed. Terminal restoration compares all settings except Darwin's transient kernel PENDIN bit; a plain raw/restore pair independently reproduced that bit change.
    • Compiled Astra library-test executable with the tui::terminal_palette::, tui::theme::, tui::render::highlight::, tui::event::, banner_ and shutdown-label test filters — 40 passed.
    • cargo test --manifest-path vendor/crossterm/Cargo.toml --lib --features event-stream --offline — 105 passed, 7 upstream interactive tests ignored.
    • cargo clippy -p astra-cli -p astra-tools --lib --locked --offline -- -D warnings — passed.
    • cargo clippy --manifest-path vendor/crossterm/Cargo.toml --lib --features event-stream --locked --offline -- -D warnings — passed; also passed with event-stream,use-dev-tty.
    • make format-check and git diff --check — passed.
    • cargo build -p astra-cli --bin astra --locked --offline — passed from the working tree used for this update. macOS emitted the compact-unwind size warning for the debug link.
  • Public entrypoint exercised: the real startup guard, terminal query API, poll, TUI EventStream, theme/render owners, Sixel tool's unknown-capability path, and local CLI build. Synthetic PTY replies avoid model/network dependencies. Full workspace tests and Linux CI were not run locally; real-terminal visual acceptance of this latest binary remains pending.

  • Unhappy paths exercised: no response, fragmented/late/malformed/oversized OSC replies, standalone Esc and Esc-then-character, arrows/Alt, CJK and bracketed paste, Ctrl-C during query/asynchronous startup and after handoff, early palette/theme access, delayed/negative/missing DA1, manual profiles/backgrounds, NO_COLOR, and redirected input/output.

  • Database verification: N/A; no database changes or migrations.

Final checklist

  • I added or updated tests at the layer that owns the behavior, or
    explained why no test is needed.
  • I updated public or design documentation for contract changes, or the
    change needs no documentation update.
  • I checked the diff for credentials, private URLs, customer data,
    generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of 9653874. No blocking correctness or regression findings.

The fix addresses the cause described in #728 at the shared rendering boundary. Removing the forced foreground colors lets the terminal choose readable text colors while retaining bold, italic, and heading emphasis. I inspected the locked termimad 0.23.2 implementation: its default skin provides those attributes without foreground overrides for these elements, and no_style removes the code/table styling as well. I also verified the separate crossterm versions: the renderer's 0.23.2 dependency does not implement the NO_COLOR handling present in the CLI's 0.29 dependency, so handling this explicitly in the renderer is justified.

I traced chat --no-color through process-environment initialization and checked both incremental rendering and the server-admission final-text caller. The presence-based NO_COLOR behavior, including an empty value, is consistent with the existing CLI theme/rendering checks. The change stays in the canonical renderer and does not introduce a terminal-specific theme detector or another rendering path.

The tests exercise useful observable behavior: vt100 cell foreground/background and emphasis for ordinary text, list labels, and headings; content preservation and absence of style escapes across code, quotes, lists, and tables; and subprocess-isolated environment cases that verify the selected test actually ran. Streaming cursor control remains outside the documented no-style contract.

Independent validation:

  • Compiled the actual streaming_md, terminal_region, and output_sink modules in an isolated Cargo test harness, using the repository's test stdout macro and pinned direct dependencies: all 47 tests passed.
  • git diff --check against the PR base passed.
  • Reviewed both changed files and the relevant callers/dependency implementation.

Limits: this was focused module validation, not a full Astra Cargo/workspace build or a live CLI/model session. I did not visually validate Ghostty or other native terminal applications. The combined-status API returned no status entries, so this review does not claim that all CI checks are green.

@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 09:48 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 10:06 UTC · at c0222dd8bbcb2853fd7e695737d96f0ac2a8016d

This pull request spent 18 minutes 4 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
    • check-success = Test: astra-cli (edge-fs-tools)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
    • check-success = Test: astra-cli (edge-git-gix)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
    • check-success = Test: astra-cli (non-edge)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
    • check-success = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
    • check-success = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
    • check-success = Test: astra-cli (non-edge)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-success = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-success = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-success = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)

Reason

Pull request #729 has been dequeued

Queue conditions are not satisfied:

  • -draft [📌 queue requirement]
  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue rule main]
      • any of: [🛡 GitHub branch protection]
        • check-neutral = Test: astra-cli (edge-fs-tools)
        • check-skipped = Test: astra-cli (edge-fs-tools)
        • check-success = Test: astra-cli (edge-fs-tools)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = Test: astra-cli (edge-git-gix)
        • check-skipped = Test: astra-cli (edge-git-gix)
        • check-success = Test: astra-cli (edge-git-gix)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = Test: astra-cli (non-edge)
        • check-skipped = Test: astra-cli (non-edge)
        • check-success = Test: astra-cli (non-edge)

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@loveRhythm1990
loveRhythm1990 marked this pull request as draft September 7, 2026 10:06
@mergify mergify Bot added dequeued and removed queued labels Sep 7, 2026
@loveRhythm1990 loveRhythm1990 changed the title fix(cli): preserve terminal foreground in markdown output fix(cli): preserve terminal contrast across light and dark themes Sep 7, 2026
@mergify mergify Bot removed the dequeued label Sep 7, 2026
@loveRhythm1990
loveRhythm1990 marked this pull request as ready for review September 7, 2026 10:52
@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 11:00 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-09-07 11:03 UTC · at aad3ab680151bfe4297b71e2efcf8f074fad1bd4

This pull request spent 2 minutes 46 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/build_push_to_idc.yml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added dequeued and removed queued labels Sep 7, 2026
@loveRhythm1990
loveRhythm1990 marked this pull request as draft September 9, 2026 11:07
@loveRhythm1990
loveRhythm1990 force-pushed the investigate/issue-728-light-terminal branch from aad3ab6 to eed5ab8 Compare September 9, 2026 11:13
@mergify mergify Bot removed the dequeued label Sep 9, 2026
@loveRhythm1990
loveRhythm1990 marked this pull request as ready for review September 9, 2026 17:39
@loveRhythm1990
loveRhythm1990 marked this pull request as draft September 9, 2026 17:43
@loveRhythm1990
loveRhythm1990 marked this pull request as ready for review September 9, 2026 17:52

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of e9b8c71 against 9db5806. This is substantially broader than the small rendering patch I previously approved. I found no confirmed blocking defect in the reviewed code.

The presentation changes use terminal-default body foregrounds, pair opaque surfaces with explicit foregrounds, and share the selected palette with syntax highlighting. Stderr rendering uses its own capability selection. Explicit profiles, unknown-background fallback, and NO_COLOR remain deliberate choices rather than assuming every terminal is dark.

I traced StartupTerminal through asynchronous initialization, terminal ownership handoff, and the shutdown monitor; inspected the shared OSC framing, filtered-event queue, both Unix reader backends, and late DA1/Sixel handling. The query shares the existing input reader, limits its response wait, and does not start a competing TUI Sixel probe. The explicit normal-session Esc tradeoff and malformed-response recovery behavior are documented. Vendoring crossterm creates an ongoing maintenance obligation, but the patch documents provenance, modified files, and a retirement condition.

The PTY tests meaningfully exercise the real guard/query/poll/EventStream boundary, including fragmented replies, keyboard/paste preservation, cancellation, terminal restoration and late capabilities. The surface/highlighting tests check rendered properties rather than only selecting an enum. I also inspected the Ubuntu-source isolation change: it retains repository verification and failure propagation rather than ignoring apt errors.

Validation: current-head Static Checks jobs passed, as did PR Title and several Test Suite shards. CLI non-edge, runtime and other tests were still running at the latest check: https://github.com/matrixorigin/Astra/actions/runs/34384931626 . Local git diff --check passed when excluding vendor; the full base-to-head check reports trailing whitespace in vendored Markdown documentation. That is not a correctness blocker, but the PR description's clean full-diff claim does not match my check. This environment has no available Rust/Cargo toolchain, so I did not independently execute the Rust/PTY suites, either Unix backend, a complete CLI session, or native-terminal visual acceptance. The author's local test counts are not my execution results. Approval is a source-review conclusion; outstanding CI still needs to pass.

Rechecked the live head before submission; it remains e9b8c71.

@mergify mergify Bot added the queued label Sep 9, 2026
@mergify

mergify Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-09 18:02 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-09 18:02 UTC · at b23242b10e155e245f220d8f39781cadf3bdc15c · squash

This pull request spent 18 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-skipped = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-success = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-skipped = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-success = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-skipped = Astra SDK (typecheck, test+coverage, build)

@mergify
mergify Bot merged commit b23242b into matrixorigin:main Sep 9, 2026
21 of 22 checks passed
@mergify mergify Bot removed the queued label Sep 9, 2026
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.

[Bug]: CLI Markdown bold text is nearly invisible on light terminal backgrounds

2 participants