Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.

refactor(tui): unify scoped empty-view presentation - #189

Merged
makoMakoGo merged 4 commits into
personal/local-clientsfrom
codex/unify-tui-empty-states
Jul 23, 2026
Merged

refactor(tui): unify scoped empty-view presentation#189
makoMakoGo merged 4 commits into
personal/local-clientsfrom
codex/unify-tui-empty-states

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jul 22, 2026

Copy link
Copy Markdown
Owner

变更概述

统一本地 TUI 的 generation、projection、presentation 与 action 边界,使真实可达的空视图共享一套状态语义、页面模板和交互能力。

主要变更

  • 新增唯一的 Presentation 分类入口:Loading | Failed | Empty(subject) | Ready,页面不再各自猜测数据状态。
  • 新增轻量 ActionSet,由同一 presentation 结果约束 footer、上下文键盘、滚轮和排序点击区域。
  • Models、Monthly、Weekly、Daily、Hourly、Stats、Agents 与 Sessions 复用统一空态模板;Overview 保留 Snapshot,只替换空图表;Sessions 保留 warm-refresh degraded 诊断。
  • 空态 scope 使用与当前投影原子配对的 data_clients:单选显示客户端名,多客户端全集显示 All clients,其余只显示数量;窄终端按显示宽度逐级降级和截断。
  • 空视图只展示 [s:clients][r:rescan] 与视图导航,不再泄漏排序、详情等无效提示;合法的全局导出仍可执行。
  • Session 零会话行不再进入空详情,投影后失效的详情会显式关闭。
  • UsageData.graph 改为总值,空图唯一表示为 weeks: [];缓存中的 graph 仍为必填对象,缺失或 null 直接成为 cache miss,不增加兼容或迁移分支。

文档清理

  • 全量重写 ADR 0028,使其成为当前 TUI generation / projection / presentation / action 契约;没有新增 ADR。
  • 直接修正 ADR 0008、ADR 0026 与 CLI 文档中的旧语义,包括远程 Subscription Usage 边界、Sessions/UsageData 归属、picker * 反选及 sessions tab 列表。

验证

  • cargo check -p tokscale-cli --all-targets
  • cargo clippy -p tokscale-cli --all-targets -- -D warnings
  • cargo test -p tokscale-cli:927 passed,1 ignored
  • cargo test -p tokscale-core:1485 passed,4 ignored
  • cargo fmt --all -- --check
  • git diff --check

Summary by CodeRabbit

  • 新功能
    • TUI 新增统一的加载、失败、空数据与就绪状态展示。
    • 空视图会显示作用范围、可用恢复操作及适配终端宽度的提示。
    • 快捷键、鼠标滚动、排序、复制、导出和刷新操作将根据当前视图动态启用。
    • 页脚帮助与排序控件会随可用操作自动更新。
  • 问题修复
    • 图表数据缺失时显示更稳定;按 Esc 或 Backspace 均可取消图表选择。
    • 无会话的选中客户端会自动退出详情状态。
  • 文档
    • 补充客户端筛选、分组、刷新及会话视图行为说明。

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@makoMakoGo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d65435ec-153d-47ed-aa8b-2e8732fa252b

📥 Commits

Reviewing files that changed from the base of the PR and between 9f8ba97 and 2771ebd.

📒 Files selected for processing (2)
  • crates/tokscale-cli/src/tui/actions.rs
  • crates/tokscale-cli/src/tui/view_state.rs

Walkthrough

新增 TUI 的统一 Presentation 与 ActionSet 状态契约,集中处理空视图、快捷键、滚轮、页脚帮助和排序能力;各报表渲染器接入共享空状态模板。同时将 UsageData.graph 改为必填结构并强化 schema-44 缓存校验。

Changes

TUI 状态与交互契约

Layer / File(s) Summary
Presentation 与 ActionSet
crates/tokscale-cli/src/tui/actions.rs, crates/tokscale-cli/src/tui/presentation.rs, crates/tokscale-cli/src/tui/mod.rs, crates/tokscale-cli/src/tui/view_state.rs
统一推导 Loading、Failed、Empty、Ready 状态及当前视图可用动作,并约束键盘、滚轮和会话详情状态。
统一空状态渲染
crates/tokscale-cli/src/tui/ui/{mod,empty_state,agents,daily,daily_profile,hourly,hourly_profile,models,overview,overview_snapshot,period,sessions,stats}.rs
各视图接收 EmptySubjectActionSet,通过共享模板渲染空状态并移除局部占位文本分支。
页脚与帮助行为
crates/tokscale-cli/src/tui/ui/{footer,view_footer}.rs
页脚摘要、排序控件、快捷键帮助和空视图作用域改由 ActionSet 驱动。

Usage graph 数据契约

Layer / File(s) Summary
必填 graph 模型与缓存
crates/tokscale-core/src/usage_views.rs, crates/tokscale-core/src/aggregate/tui.rs, crates/tokscale-cli/src/tui/cache.rs
UsageData.graph 改为必填值,缓存写入始终包含 graph,缺失或 null graph 返回 cache miss。
图表访问与验证
crates/tokscale-cli/src/tui/app.rs, crates/tokscale-cli/src/tui/ui/stats.rs, crates/tokscale-core/src/aggregate/parity_tests.rs, crates/tokscale-core/benches/aggregation.rs
图表读取、聚合统计和测试改为直接使用 graph,并验证 weeks 数据。

文档契约

Layer / File(s) Summary
架构与 CLI 文档
docs/adr/*.md, docs/cli.md
文档描述 generation、projection、presentation、actions、空状态、graph 数据形状及客户端选择器行为。

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant Presentation
  participant ActionSet
  participant ViewRenderer
  participant Footer
  App->>Presentation: classify current view
  Presentation->>ActionSet: derive available actions
  ActionSet->>ViewRenderer: provide empty state and action context
  ViewRenderer->>Footer: render action-aware footer
Loading

Possibly related PRs

Poem

小兔挥键,空页开花,
Actions 排好快捷话。
Graph 不再躲猫猫,
Footer 唱起刷新调。
TUI 轻跳,状态清澈,
胡萝卜也赞这变革!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次 PR 的核心:统一 TUI 的作用域空视图呈现。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/unify-tui-empty-states

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.

@codspeed-hq

codspeed-hq Bot commented Jul 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 43 untouched benchmarks


Comparing codex/unify-tui-empty-states (2771ebd) with personal/local-clients (0ec95a2)

Open in CodSpeed

@makoMakoGo
makoMakoGo merged commit 07c6f34 into personal/local-clients Jul 23, 2026
7 of 8 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/tokscale-cli/src/tui/ui/daily.rs (1)

1009-1030: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

多个文件的测试辅助函数重复构造 ViewState/Presentation/ActionSet 样板代码。

为适配新的 render(..., empty, &actions) 签名,六个文件的测试模块都各自重复了同一段三行样板:ViewState::default()Presentation::for_view(app, &state)ActionSet::for_view(app, &state, presentation)。建议在共享测试工具模块中抽取一个辅助函数(如返回 (ViewState, ActionSet) 或直接返回 ActionSet),供以下位置复用:

  • crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030render_body 中的三行样板改为调用共享辅助。
  • crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189render_buffer 中的三行样板改为调用共享辅助。
  • crates/tokscale-cli/src/tui/ui/models.rs#L703-L724render_body 中的三行样板改为调用共享辅助。
  • crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476:测试内联的三行样板改为调用共享辅助。
  • crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836render_snapshot 中的三行样板改为调用共享辅助(该函数已很好地做到文件内复用,可作为跨文件抽取的模板)。
  • crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877actions_for 中的三行样板改为调用共享辅助(该实现已是较干净的独立函数,可直接作为共享辅助的起点)。

若未来 Presentation::for_view/ActionSet::for_view 的签名或调用方式变化,当前需要同步修改六处以上位置;抽取共享辅助后只需改一处。

🤖 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/ui/daily.rs` around lines 1009 - 1030, Extract
the repeated ViewState::default → Presentation::for_view → ActionSet::for_view
setup into a shared test helper, preferably based on the existing actions_for
pattern in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877. Update render_body
in crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030, render_buffer in
crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189, render_body in
crates/tokscale-cli/src/tui/ui/models.rs#L703-L724, the inline setup in
crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476, render_snapshot in
crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836, and actions_for
in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877 to call the shared helper
while preserving each caller’s existing rendering behavior.
🤖 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 `@docs/adr/0028-tui-client-universe-and-view-selection.md`:
- Around line 121-125: 更新 ADR
中空视图动作契约的描述,使其明确移除排序、明细、复制和行点击等行级动作,同时保留适用的全局动作,包括主题、自动刷新、刷新间隔、导出和退出;不要再表述为空视图“只广告恢复与导航动作”,以与
ActionSet::for_view 的实际行为一致。

---

Nitpick comments:
In `@crates/tokscale-cli/src/tui/ui/daily.rs`:
- Around line 1009-1030: Extract the repeated ViewState::default →
Presentation::for_view → ActionSet::for_view setup into a shared test helper,
preferably based on the existing actions_for pattern in
crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877. Update render_body in
crates/tokscale-cli/src/tui/ui/daily.rs#L1009-L1030, render_buffer in
crates/tokscale-cli/src/tui/ui/hourly_profile.rs#L179-L189, render_body in
crates/tokscale-cli/src/tui/ui/models.rs#L703-L724, the inline setup in
crates/tokscale-cli/src/tui/ui/overview.rs#L456-L476, render_snapshot in
crates/tokscale-cli/src/tui/ui/overview_snapshot.rs#L831-L836, and actions_for
in crates/tokscale-cli/src/tui/ui/stats.rs#L873-L877 to call the shared helper
while preserving each caller’s existing rendering behavior.
🪄 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: 690d5d36-3883-406b-9647-1a8b405bb1cc

📥 Commits

Reviewing files that changed from the base of the PR and between a3afc6d and 9f8ba97.

📒 Files selected for processing (30)
  • crates/tokscale-cli/src/tui/actions.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/cache.rs
  • crates/tokscale-cli/src/tui/mod.rs
  • crates/tokscale-cli/src/tui/presentation.rs
  • crates/tokscale-cli/src/tui/ui/agents.rs
  • crates/tokscale-cli/src/tui/ui/daily.rs
  • crates/tokscale-cli/src/tui/ui/daily_profile.rs
  • crates/tokscale-cli/src/tui/ui/empty_state.rs
  • crates/tokscale-cli/src/tui/ui/footer.rs
  • crates/tokscale-cli/src/tui/ui/hourly.rs
  • crates/tokscale-cli/src/tui/ui/hourly_profile.rs
  • crates/tokscale-cli/src/tui/ui/mod.rs
  • crates/tokscale-cli/src/tui/ui/models.rs
  • crates/tokscale-cli/src/tui/ui/overview.rs
  • crates/tokscale-cli/src/tui/ui/overview_snapshot.rs
  • crates/tokscale-cli/src/tui/ui/period.rs
  • crates/tokscale-cli/src/tui/ui/sessions.rs
  • crates/tokscale-cli/src/tui/ui/stats.rs
  • crates/tokscale-cli/src/tui/ui/view_footer.rs
  • crates/tokscale-cli/src/tui/view_state.rs
  • crates/tokscale-core/benches/aggregation.rs
  • crates/tokscale-core/src/aggregate/parity_tests.rs
  • crates/tokscale-core/src/aggregate/tui.rs
  • crates/tokscale-core/src/usage_views.rs
  • docs/adr/0008-single-copy-memory-pipeline.md
  • docs/adr/0010-period-views-derive-from-daily.md
  • docs/adr/0026-group-by-view-scope-contract.md
  • docs/adr/0028-tui-client-universe-and-view-selection.md
  • docs/cli.md

Comment thread docs/adr/0028-tui-client-universe-and-view-selection.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant