Skip to content

Port upstream 0.65.0: replay Claude CLI cursor redraws onto a virtual screen - #633

Open
Finesssee wants to merge 1 commit into
port/upstream-0.65.0from
port/micro-0.65.0-claude-cli-screen-replay
Open

Finesssee wants to merge 1 commit into
port/upstream-0.65.0from
port/micro-0.65.0-claude-cli-screen-replay

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Claude CLI /usage panels redraw differentially: the CLI moves the cursor and rewrites only changed cells. The local parse_cli_output used strip_ansi, which drops every cursor jump, so the fixture frame yields 51%usd and the model-specific weekly row is lost. The capture is now replayed onto a 160x50 virtual screen (the same geometry as the PTY in tty_runner.rs) before parsing, so unchanged cells of earlier frames are kept and erased content is never reused. Plain and color-only reports come back unchanged (preservePlainReports mode), so CR-delimited legacy output is not clipped or wrapped.

The replay is used in parse_cli_output, in the workspace-trust-prompt check, and for the CLI error-marker check in fetch_via_cli (rendered once, then passed on; rendering is idempotent on rendered text).

Upstream reference

Ported / Deferred

Ported:

  • New rust/src/providers/claude/cli_screen.rs (697 lines, no new dependencies): tokenizer equivalent to upstream's ESC(?:\[...|\]...|.)|[^ESC]+ pattern (OSC consumed whole, BEL/ST/end terminators), CSI A B C D G H f K J with parameters capped to two and clamped, K/J modes 0-2 only, CR/LF/CRLF/BS/tab, wide-glyph cells with trail cells, combining marks attached to the previous cell, wrap at column 160, scroll after row 50.
  • Wide-glyph width: the crate has no width/grapheme dependency (unicode-segmentation is only transitive), so upstream's width rule is ported directly (wide ranges, emoji presentation, U+FE0F emoji, zero-width marks). Grapheme clustering is a small approximation of UAX fix: resolve clippy warnings #29 (marks, ZWJ sequences, emoji modifiers, regional-indicator pairs, CRLF) rather than full segmentation.
  • Fixtures: usage-pty-differential-redraw.ansi and status-pty-differential-redraw.ansi, byte-exact from v0.65.0 (verified with cmp), under rust/src/providers/fixtures/claude/. .gitattributes marks them -text so the CR bytes survive EOL conversion.
  • All vectors from ClaudeCLIScreenTests.swift, plus the plain-report cases from ClaudeCLIScreenProbeTests.swift.
  • Local adjustment required by the fixture: current /usage panels print a "Session" summary (Total duration, Usage: ... cache read) above the plan limits. is_cli_activity_stats_response matched it and rejected the whole capture. It now yields to a current session / current week section (has_plan_limit_section); stats-only captures are still rejected (existing tests unchanged).

Deferred / not applicable:

Validation

Run with the pinned toolchain and a process-local CARGO_TARGET_DIR (the pwsh wrapper was refused in this worktree):

  • cargo +1.98.0 fmt --all clean.
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass, no warnings.
  • cargo +1.98.0 test -p codexbar providers::claude: 180 passed, 0 failed, 1 ignored (pre-existing native-Claude test).
  • cargo +1.98.0 test -p codexbar (full): 2176 passed, 0 failed, 1 ignored; bin test 1 passed.
  • New tests (claude::cli_screen::tests, 16): 33 upstream vectors, joiner/flag width, OSC edge cases, synthetic differential frame vs golden, backspace, clear-screen no-resurrect, overflow parameters bounded to 50x160, wrap/scroll, range-table sortedness, plain-report preservation (CR delimiters, OSC contents, no clipping past 50 rows or 160 columns), fixture: session 97% left, weekly 73% left, reset "Resets Sep 23 at 3pm (Europe/Stockholm)", scoped Fable 51% used, and strip_ansi alone yielding 51%usd.

Affected areas

  • Rust backend (rust/src/providers/claude)
  • Tauri shell
  • React UI / tray / settings / float bar
  • Fixtures / .gitattributes
  • CLI

UI proof

Not applicable.

… screen

Differential redraws of the /usage panel move the cursor instead of rewriting whole lines, so stripping escapes fused fragments such as 51%usd and lost scoped weekly rows. Replay the capture on a 160x50 screen (upstream ClaudeCLIScreen, steipete#3822) before parsing and in the trust-prompt check, keeping plain reports unchanged.
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 66f96b9b-6d97-46c1-9009-0bf954f0f45f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation (lane-A) at 200f610

Review verdict: the branch at its published head matches the 0.65.0 audit PR-2 spec; local HEAD equals the remote head (200f6107), so no re-merge or fix commit was needed. The replay (cli_screen.rs, 160×50 virtual screen, CSI A/B/C/D/G/H/f/K/J + CR/BS/tab/OSC, wide-glyph/combining handling, preserve_plain_reports) is wired before Claude CLI parsing, so cursor-positioned differential redraws keep unchanged cells; tests include the upstream synthetic vectors and the two differential-redraw ANSI fixtures.

Checks at 200f610 (CARGO_TARGET_DIR=W:\cargo-target\lane-a, jobs=4, RUST_TEST_THREADS=4):

  • cargo fmt --all --check: pass.
  • cargo clippy both manifests --all-targets -- -D warnings: only the 3 documented pre-existing main-drift findings; 0 in this PR's diff.
  • cargo test rust manifest: 2176 passed / 0 failed / 1 ignored (claude focused: 223/0).
  • cargo test desktop manifest: only the documented Isolate bootstrap payload test from real settings #684 bootstrap_payload_exposes_every_provider_variant failure (env-dependent baseline on branches without Make the bootstrap catalog test hermetic (#684) #711; expected, hermetic fix lives on release/v0.70.0).

No new code was required; validation-only item.

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