feat(tui): reland token activity command (#27925)

## Why

[#25345](https://github.com/openai/codex/pull/25345) was approved,
green, and squash-merged into its stacked base branch,
`fcoury/tokenmaxxing-api`. Four minutes later, that base branch was
force-pushed back to an API-only rebased head while preparing
[#25344](https://github.com/openai/codex/pull/25344) for `main`. As a
result, the squash commit from #25345 was orphaned and the TUI command
never reached `main` or a release.

This PR relands the orphaned TUI change from
[`411410b8`](https://github.com/openai/codex/commit/411410b85c2d8eb050d441f17396c5c4048d866f)
on current `main`.

## What changed

- Add `/usage`, `/usage daily`, `/usage weekly`, and `/usage cumulative`
for account token activity.
- Fetch account usage asynchronously through the existing
`account/usage/read` app-server RPC.
- Render daily, weekly, and cumulative activity with theme-aware
terminal palettes and bounded transient cards.
- Preserve transcript ordering while assistant streams, history
consolidations, active cells, and hooks complete.
- Hide `/usage` from completion when backend auth is unavailable while
keeping typed-command guidance.
- Carry current-main behavior forward for cwd-aware Markdown parsing,
Windows Terminal color detection, and personal access token auth.
- Clear pending usage cards on thread rollback and delay completed cards
until live hook output is committed.
- Add focused regression and snapshot coverage for loading, auth errors,
invalid views, rollback, hook ordering, layout, and charts.

## Prior review

The original implementation was approved by Eric Traut in #25345 after
testing multiple themes and light/dark terminals. This PR preserves that
reviewed implementation while adapting it to current `main` and adding
regression coverage for newer rollback and hook lifecycle behavior.

## Validation

- `just test -p codex-tui token_activity palette renderable
usage_command` — 37 passed.
- Focused rollback, hook-ordering, and error snapshot tests — 4 passed.
- `just fix -p codex-tui` — passed.
- `UV_CACHE_DIR=/private/tmp/codex-uv-cache just fmt` — passed.
- `cargo insta pending-snapshots` — no pending snapshots.
- `just test -p codex-tui` — 2,870 passed; two unrelated guardian
feature-flag tests failed because their expected `OverrideTurnContext`
event was absent:
-
`update_feature_flags_disabling_guardian_clears_manual_review_policy_without_history`
-
`update_feature_flags_disabling_guardian_clears_review_policy_and_restores_default`
- `just argument-comment-lint` could not complete because the local
Bazel LLVM `compiler-rt` repository is missing `include/sanitizer/*.h`.
The touched Rust diff was manually inspected and no missing
opaque-literal argument comments were found.
This commit is contained in:
Felipe Coury authored and GitHub committed 2026-06-12 17:33:43 -07:00
1 parent 9e07892253
commit c884536d84
42 files changed
+2296 -57

No files matched your search

+23
View File
@@ -29,6 +29,7 @@ pub(crate) struct TranscriptReflowState {
last_reflow_width: Option<u16>,
pending_reflow_width: Option<u16>,
pending_until: Option<Instant>,
history_cell_refresh_requested: bool,
ran_during_stream: bool,
resize_requested_during_stream: bool,
}
@@ -93,6 +94,12 @@ impl TranscriptReflowState {
self.pending_until = Some(Instant::now());
}
/// Schedule an immediate rebuild because an existing history cell changed its rendered output.
pub(crate) fn schedule_history_cell_refresh(&mut self) {
self.history_cell_refresh_requested = true;
self.schedule_immediate();
}
#[cfg(test)]
pub(crate) fn set_due_for_test(&mut self) {
self.pending_until = Some(Instant::now() - Duration::from_millis(1));
@@ -110,9 +117,14 @@ impl TranscriptReflowState {
self.pending_until.is_some()
}
pub(crate) fn history_cell_refresh_requested(&self) -> bool {
self.history_cell_refresh_requested
}
pub(crate) fn clear_pending_reflow(&mut self) {
self.pending_until = None;
self.pending_reflow_width = None;
self.history_cell_refresh_requested = false;
}
/// Remember the terminal width that actually rebuilt transcript scrollback.
@@ -262,6 +274,17 @@ mod tests {
assert!(state.reflow_needed_for_width(/*width*/ 100));
}
#[test]
fn clear_pending_reflow_clears_history_cell_refresh_request() {
let mut state = TranscriptReflowState::default();
state.schedule_history_cell_refresh();
assert!(state.history_cell_refresh_requested());
state.clear_pending_reflow();
assert!(!state.history_cell_refresh_requested());
}
#[test]
fn mark_reflowed_width_reports_unchanged_width() {
let mut state = TranscriptReflowState::default();