feat(cli): make TUI the canonical local report surface - #190
Conversation
Walkthrough该 PR 将本地报告统一到 TUI-backed ChangesCanonical usage surface
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant User
participant ModelsCLI
participant Core
participant TUIProjection
participant Renderer
User->>ModelsCLI: models --json or table
ModelsCLI->>Core: get_usage_data(ReportOptions)
Core->>TUIProjection: aggregate with ViewSet::TUI
TUIProjection-->>Core: UsageData and health
Core-->>ModelsCLI: UsageData
ModelsCLI->>Renderer: build JSON or render table
Renderer-->>User: models projection
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20291d6c86
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/tokscale-cli/src/tui/export.rs (1)
60-76: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winagents/daily 导出的 tokens 明细缺少 reasoning,与新 models 块不一致。
models块本次新增了reasoning/displayedOutput字段,但agents/daily的tokens对象仍只暴露input/output/cacheRead/cacheWrite/total。由于total()内部包含reasoning,当 reasoning tokens 非零时,total会大于展示字段之和,容易让消费该导出 JSON 的脚本/用户产生对账困惑。♻️ 建议为 agents/daily 补充 reasoning 字段
"tokens": { "input": a.tokens.input, "output": a.tokens.output, + "reasoning": a.tokens.reasoning, "cacheRead": a.tokens.cache_read, "cacheWrite": a.tokens.cache_write, "total": a.tokens.total() },同理为
daily块的 tokens 对象补充。Also applies to: 82-96
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/tokscale-cli/src/tui/export.rs` around lines 60 - 76, 在 agents 导出映射的 tokens 对象中补充 reasoning 字段,并在对应的 daily 导出映射中同步补充相同字段,使用现有的 reasoning token 属性;保持 input、output、缓存字段及 total 的现有行为不变,使明细字段与 models 块保持一致。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/tokscale-core/src/lib_tests.rs`:
- Around line 25-43: Remove the derived Default implementation from
TestClientCounts and provide an explicit default initialization using
std::array::from_fn (or an equivalent closure-based approach) so [i32;
ClientId::COUNT] works for any length. Keep from_messages and get behavior
unchanged.
---
Nitpick comments:
In `@crates/tokscale-cli/src/tui/export.rs`:
- Around line 60-76: 在 agents 导出映射的 tokens 对象中补充 reasoning 字段,并在对应的 daily
导出映射中同步补充相同字段,使用现有的 reasoning token 属性;保持 input、output、缓存字段及 total
的现有行为不变,使明细字段与 models 块保持一致。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 89b99ffa-7f52-41b2-b08b-32ea90e98e6f
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (56)
README.mdcrates/tokscale-cli/Cargo.tomlcrates/tokscale-cli/src/claude_diagnostics.rscrates/tokscale-cli/src/cli.rscrates/tokscale-cli/src/commands/clients.rscrates/tokscale-cli/src/commands/graph.rscrates/tokscale-cli/src/commands/hourly.rscrates/tokscale-cli/src/commands/integrations.rscrates/tokscale-cli/src/commands/mod.rscrates/tokscale-cli/src/commands/models.rscrates/tokscale-cli/src/commands/monthly.rscrates/tokscale-cli/src/commands/render.rscrates/tokscale-cli/src/commands/shared.rscrates/tokscale-cli/src/commands/time_metrics.rscrates/tokscale-cli/src/commands/usage/mod.rscrates/tokscale-cli/src/commands/usage/warp.rscrates/tokscale-cli/src/commands/wrapped.rscrates/tokscale-cli/src/main.rscrates/tokscale-cli/src/main_tests.rscrates/tokscale-cli/src/tui/app.rscrates/tokscale-cli/src/tui/cache.rscrates/tokscale-cli/src/tui/export.rscrates/tokscale-cli/src/tui/mod.rscrates/tokscale-cli/src/tui/ui/dialog/group_by_picker.rscrates/tokscale-cli/src/warp.rscrates/tokscale-cli/tests/cli_tests.rscrates/tokscale-core/benches/aggregation.rscrates/tokscale-core/src/aggregate/accumulators.rscrates/tokscale-core/src/aggregate/config.rscrates/tokscale-core/src/aggregate/engine.rscrates/tokscale-core/src/aggregate/graph_result.rscrates/tokscale-core/src/aggregate/keys.rscrates/tokscale-core/src/aggregate/mod.rscrates/tokscale-core/src/aggregate/parity_tests.rscrates/tokscale-core/src/aggregate/tui.rscrates/tokscale-core/src/aggregate/views.rscrates/tokscale-core/src/clients.rscrates/tokscale-core/src/lib.rscrates/tokscale-core/src/lib_tests.rscrates/tokscale-core/src/sessionize.rscrates/tokscale-core/src/usage_views.rsdocs/adr/0007-client-identity-catalog.mddocs/adr/0014-explicit-subscription-usage-boundary.mddocs/adr/0022-deterministic-cli-command-semantics.mddocs/adr/0024-subscription-usage-redesign.mddocs/adr/0025-antigravity-cli-only-local-input.mddocs/adr/0026-group-by-view-scope-contract.mddocs/adr/0027-current-input-discovery-and-graph-semantics.mddocs/adr/0033-tui-canonical-local-report-surface.mddocs/cli.mddocs/clients.mddocs/configuration.mddocs/performance/2026-07-10-scan-rss-optimization.mddocs/performance/2026-07-21-public-surface-cleanup.mdscripts/measure-scan-performance.shscripts/test-measure-scan-performance.sh
💤 Files with no reviewable changes (20)
- crates/tokscale-core/src/aggregate/accumulators.rs
- crates/tokscale-cli/src/commands/usage/warp.rs
- crates/tokscale-core/src/aggregate/parity_tests.rs
- crates/tokscale-cli/src/commands/integrations.rs
- crates/tokscale-cli/src/commands/monthly.rs
- crates/tokscale-cli/src/commands/mod.rs
- crates/tokscale-cli/src/commands/hourly.rs
- crates/tokscale-cli/src/commands/clients.rs
- crates/tokscale-core/src/aggregate/graph_result.rs
- crates/tokscale-cli/src/commands/time_metrics.rs
- crates/tokscale-cli/src/commands/graph.rs
- crates/tokscale-cli/src/commands/shared.rs
- crates/tokscale-cli/Cargo.toml
- crates/tokscale-cli/src/warp.rs
- crates/tokscale-cli/src/tui/cache.rs
- crates/tokscale-core/src/sessionize.rs
- crates/tokscale-core/src/clients.rs
- crates/tokscale-cli/src/commands/render.rs
- crates/tokscale-cli/src/commands/usage/mod.rs
- crates/tokscale-cli/src/main.rs
|
Review follow-up pushed in
Local validation:
@codex review |
|
✅ Action performedReview finished.
|
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
The pull ref is now synchronized at @codex review |
There was a problem hiding this comment.
💡 Codex Review
tokscale/crates/tokscale-cli/src/tui/cache.rs
Lines 2272 to 2275 in be52290
Startup always loads the model projection, so this visitor merely skips the contents of the other three projections while treating the bundle as fresh. If, for example, clientModel is malformed or has Common-incompatible rows, the TUI installs the cache successfully; switching Group By later fails in ProjectionStore::project, restores the old selection, and does not rebuild the invalid generation. Validate every persisted projection when accepting the schema-45 bundle so a corrupted inactive projection becomes the intended cache miss.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/tokscale-core/src/aggregate/tui.rs`:
- Around line 229-237: Update build_common_contribution_graph and
calculate_common_streaks so they use an explicit shared today value instead of
independently calling Local::now(). In project_common_selected, capture the date
once per projection and pass it to both calculations, preserving consistent
graph and streak results across midnight and repeated projections.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5369412e-2946-4da6-9b23-3ae780699332
📒 Files selected for processing (33)
crates/tokscale-cli/src/cli.rscrates/tokscale-cli/src/commands/wrapped.rscrates/tokscale-cli/src/main.rscrates/tokscale-cli/src/main_tests.rscrates/tokscale-cli/src/tui/app.rscrates/tokscale-cli/src/tui/cache.rscrates/tokscale-cli/src/tui/data/mod.rscrates/tokscale-cli/src/tui/export.rscrates/tokscale-cli/src/tui/ui/agents.rscrates/tokscale-cli/tests/cli_tests.rscrates/tokscale-core/src/adapters/file.rscrates/tokscale-core/src/adapters/junie.rscrates/tokscale-core/src/adapters/kilo.rscrates/tokscale-core/src/adapters/mod.rscrates/tokscale-core/src/adapters/omp.rscrates/tokscale-core/src/adapters/roocode.rscrates/tokscale-core/src/aggregate/keys.rscrates/tokscale-core/src/aggregate/tui.rscrates/tokscale-core/src/lib_tests.rscrates/tokscale-core/src/sessions/junie.rscrates/tokscale-core/src/sessions/kilo.rscrates/tokscale-core/src/sessions/mod.rscrates/tokscale-core/src/sessions/opencode.rscrates/tokscale-core/src/sessions/roocode.rscrates/tokscale-core/src/usage_views.rsdocs/adr/0006-agent-identity-for-agents-tab.mddocs/adr/0008-single-copy-memory-pipeline.mddocs/adr/0026-group-by-view-scope-contract.mddocs/adr/0028-tui-client-universe-and-view-selection.mddocs/adr/0029-keep-claude-discovery-catalog-scoped.mddocs/adr/0030-client-input-and-data-health-terminology.mddocs/adr/0033-tui-canonical-local-report-surface.mddocs/cli.md
💤 Files with no reviewable changes (4)
- crates/tokscale-cli/src/main.rs
- crates/tokscale-cli/src/cli.rs
- crates/tokscale-core/src/aggregate/keys.rs
- crates/tokscale-cli/tests/cli_tests.rs
🚧 Files skipped from review as they are similar to previous changes (4)
- crates/tokscale-cli/src/tui/export.rs
- crates/tokscale-cli/src/main_tests.rs
- docs/cli.md
- crates/tokscale-core/src/lib_tests.rs
|
Follow-up pushed in
Validation on the current head:
Please review the current head @codex review |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 412286007d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
The current head is now This fixes the valid Client-universe review finding:
Current-head local validation:
Please review the current head. @codex review |
|
✅ Action performedReview finished.
|
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
tokscale tui --tabtokscale modelsconsume the TUI Models projection, default tomodel, and accept only the four TUI Group By valueswarp.sqliteClient parsingusage --jsonfor automation(Client, Agent)and keep parser-specific normalization at parser boundariesArchitecture
TuiAcc.TuiAcckeeps a low-cardinalityusage_totals_by_clientfold so full and Client-subset report totals do not re-sort the fine-grained model map.Breaking changes
monthly,hourly,time-metrics,graph,clients, andwarp--rankingand--disable-pinnedclientsto singularclientReview follow-up
std::array::from_fnand do not depend on a catalog-size limitValidation
cargo test -p tokscale-core --lib— 1404 passed, 2 ignoredcargo test -p tokscale-cli— 757 unit tests, 87 CLI integration tests, 1 Copilot memory test, and 2 TUI exit tests passed; 1 ignoredcargo clippy --workspace --all-targets -- -D warningscargo fmt --all -- --checkgit diff --check