refactor(tui): drive Footer and StatusBar from an ordered token array (#451)#482
refactor(tui): drive Footer and StatusBar from an ordered token array (#451)#482mabry1985 wants to merge 2 commits into
Conversation
…#451) Both status surfaces were doing the same thing by hand: join a list of cells with a separator. The Footer's right side interleaved " | " by array index; StatusBar hand-placed a <Sep /> before each conditional badge. Adding a pill meant editing the separator chain, so S5's cost / PR pills and S3's autonomy chip had nowhere clean to land. Introduce one token model both surfaces consume: - `StatusToken` + `tokens(...)` — an ordered array; builders return a falsy value for "not applicable", so omitted cells never reach render. - `firstToken(...)` — first-applicable-wins, for the Footer's left slot. The seven-deep nested ternary is now an ordered list where argument order *is* the priority order. - `<TokenBar />` — owns separator placement, positioning by index in the rendered array rather than the source list. A filtered-out token therefore cannot strand a separator with nothing to its left. Pure refactor: rendered output is byte-identical. The two pre-existing Footer goldens are unchanged, which is the proof. Characterization goldens added first, against unmodified components, since the existing snapshots covered only one UI state and would have stayed green through six broken left-slot branches: - Footer: all nine left-slot priority branches, priority tie-breaks, and right-slot token combinations. - StatusBar: had no snapshot at all; now pins separator placement and badge order. os.hostname() is mocked so goldens are machine-independent. - TokenBar: separator invariants, incl. omitted leading/middle/trailing tokens. Verified live in a pty at 130 cols: all five StatusBar tokens render with real git data, and the left slot correctly shows "Press Ctrl+C again to exit." over "YOLO mode", falling back once the state expires. Refs #451 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016oB3qy8XHsNubMfLFhhqtB
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
String- and number-guarded token builders (`sandboxInfo && {…}`,
`branch && {…}`) evaluate to `""` or `0` when the guard is falsy, but
MaybeToken only permitted `false | null | undefined`, so `tsc --build`
rejected them. The union now covers every falsy scalar a truthy-guard
can leave behind, matching the type's stated "or a falsy value" intent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0163fEuMzHoQwTHpe4r44utN
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Part of #451 (TUI S5). PR 1 of 4 — the load-bearing refactor the issue asks to "pull early", so the remaining S5 slices have somewhere to land.
Why
Both status surfaces were hand-rolling the same operation — join a list of cells with a separator:
Footer.tsxinterleaved" | "by array index (index > 0).StatusBar.tsxhand-placed a<Sep />before each conditional badge.So adding a pill meant editing a separator chain by hand. S5's cost pill and S3's shipped autonomy chip had nowhere clean to go.
What
One token model, consumed by both surfaces:
StatusToken+tokens(...)firstToken(...)<TokenBar />The Footer's left slot was a seven-deep nested ternary. It's now an ordered list where argument order is the priority order — which is also what S6's context-aware key-hint chain will need.
<TokenBar />positions separators by index in the rendered array, not the source list, so a filtered-out token can't strand a separator with nothing to its left. (Note: not a live bug today —VoiceMicButtonalways renders something. It's a fragility designed out, and it's visible in the mocked test render.)This is a pure refactor
Rendered output is byte-identical. The two pre-existing Footer goldens are unchanged — that's the proof. The snapshot diff is insertions only.
Tests
The existing snapshots covered exactly one UI state, so a refactor could have broken six of the nine left-slot branches and stayed green. Characterization goldens were captured first, against unmodified components:
os.hostname()is mocked so goldens are machine-independent (they'd otherwise fail in CI).Full CLI suite: 280 files, 4168 passing, no obsolete snapshots.
Verified live
Driven in a pty at 130 cols (not just mocked renders):
All five StatusBar tokens render with real git data, and the left slot correctly shows
Press Ctrl+C again to exit.overYOLO mode, falling back once the state expires.Draft because
UI-only — CI can't judge how it looks. Worth a human glance in a real terminal before merge.
Next (per #451)
ModelDialog, cost only in/stats)Refs #451
🤖 Generated with Claude Code
https://claude.ai/code/session_016oB3qy8XHsNubMfLFhhqtB