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

feat(tui): redesign Stats day insights and usage windows - #162

Merged
makoMakoGo merged 9 commits into
personal/local-clientsfrom
port-kimi-ui/ux-desgin
Jul 18, 2026
Merged

feat(tui): redesign Stats day insights and usage windows#162
makoMakoGo merged 9 commits into
personal/local-clientsfrom
port-kimi-ui/ux-desgin

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • normalize Kimi Code and Z.ai rolling five-hour quota labels to 5 Hour
  • add a mouse-only contribution graph crosshair for the selected day, weekday, and month
  • replace the scrollable Stats breakdown with compact Day Insights, including Top Model, Top Harness, a 24-hour activity strip, and a Top 3 + Others radar
  • select today's real contribution cell when entering Stats, while preserving Esc deselection and remapping selections by date after graph rebuilds

Why

The Usage tab rendered equivalent five-hour windows with inconsistent labels, and the old Stats breakdown made day-level comparisons cumbersome. This adapts the selected Kimi branch UI changes to the fork's current Stats architecture without restoring the removed Stats Summary panel.

Design decisions

  • Day Insights ranks models by the bare canonical model ID stored in DailyModelInfo.color_key, aggregating across provider, source, and workspace projections.
  • Global Workspace Group By does not change Top Model or radar identity; broader Group By scope auditing remains tracked in 规范 TUI Group By 的作用范围与跨视图语义 #161.
  • Contribution day selection remains mouse-only. No keyboard date navigation is added, and only real graph cells are clickable.
  • Missing model detail is reported as No detailed usage breakdown is available for this day. without inventing a ranking or radar.
  • Entering Stats selects local today, not the latest day with usage.

Validation

  • cargo fmt --all -- --check
  • cargo clippy --locked -p tokscale-cli --all-features -- -D warnings
  • cargo test -p tokscale-cli --bin tokscale — 666 passed, 1 ignored
  • bun run build:core

Summary by CodeRabbit

  • 新功能
    • Stats 页面进入时自动选中“今日”图表,并在刷新后保持同日期选中;手动取消后不再自动覆盖。
    • Day Insights 增加模型排行、活跃时段与四轴雷达图,可按选中日期查看对应详情并高亮周/月。
  • 改进
    • 配额展示改为更直观的小时/天/秒等单位格式,并在未知单位场景避免误导性标签。
    • 更准确显示预计重置时间与相关标签(如周/会话等)。
  • 测试
    • 更新并新增用例覆盖上述渲染、标签与边界情况。

…Z.ai

Kimi Code's usages endpoint sends window.timeUnit as TIME_UNIT_MINUTE,
which fell through the unit match into the seconds fallback and rendered
as "300s limit". Z.ai hardcoded "Session" for its (unit 3, number 5)
tokens limit. Both now derive the label from the window and show
"5 Hour"; Z.ai also surfaces each limit's nextResetTime as reset times.
Labels and shapes verified against the live endpoints.
Adapted from Kimi branch aff3212; the behavior was retained by 74cc20a.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Changes

用量解析与 Stats 界面

Layer / File(s) Summary
用量标签与重置时间输出
crates/tokscale-cli/src/commands/usage/kimi.rs, crates/tokscale-cli/src/commands/usage/zai.rs
Kimi 统一时间单位和小时标签;Zai 解析 API 重置时间、更新指标标签及相关测试。
Stats 今日日期自动选择
crates/tokscale-cli/src/tui/app.rs
Stats 页按日期自动选择今日图表单元格,并处理数据延迟、刷新重映射、ESC 取消和手动选择。
Day Insights 与雷达图渲染
crates/tokscale-cli/src/tui/ui/stats.rs, crates/tokscale-cli/src/tui/ui/radar.rs, crates/tokscale-cli/src/tui/ui/mod.rs
重构图表高度、日期高亮和 Day Insights,新增 canonical 模型聚合、活跃小时统计及四轴雷达图。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant App
  participant UsageData
  participant Stats
  participant Radar
  User->>App: open Stats tab
  App->>UsageData: refresh or load graph data
  UsageData-->>App: graph dates and daily usage
  App->>Stats: select today's graph cell
  Stats->>UsageData: read selected day's details
  UsageData-->>Stats: models, harnesses, and hourly activity
  Stats->>Radar: render model share axes
  Radar-->>User: display Day Insights and radar chart
Loading

Possibly related PRs

Suggested reviewers: junhoyeo

Poem

我是兔子,蹦进 Stats 小径,
今日格子亮晶晶。
雷达图张开四只耳,
模型排行随风鸣。
用量标签换新衣,
重置时间也准时归。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% 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 Stats 的 Day Insights,并规范 usage window 标签。
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch port-kimi-ui/ux-desgin

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c84e0cd8f

ℹ️ 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".

Comment thread crates/tokscale-cli/src/tui/ui/stats.rs Outdated
Comment thread crates/tokscale-cli/src/tui/app.rs

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/tokscale-cli/src/tui/ui/stats.rs (1)

35-61: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

避免在默认终端尺寸下截断 Day Insights 核心内容。

80×24 终端扣除 header/footer 后仅剩 16 行;这里分配 11 行给图表、5 行给面板,边框后 Day Insights 仅能显示日期、分隔线和 Top Model。Top Harness、活动小时数及 24 小时条均被静默丢弃,且已无滚动入口。

请增加 80×24 的完整渲染回归测试,并为低高度提供紧凑布局或可滚动内容。基于 PR 目标中 Day Insights 必须包含 Top Model、Top Harness 和 24 小时活动条的说明。

🤖 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/stats.rs` around lines 35 - 61, Update the
stats layout around split_graph_height and render_day_insights so the default
80×24 terminal preserves Top Model, Top Harness, and the 24-hour activity bar
instead of clipping them; use a compact layout or scrolling for low heights. Add
a regression test covering the full 80×24 rendering and asserting these Day
Insights elements remain available.
🤖 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.

Outside diff comments:
In `@crates/tokscale-cli/src/tui/ui/stats.rs`:
- Around line 35-61: Update the stats layout around split_graph_height and
render_day_insights so the default 80×24 terminal preserves Top Model, Top
Harness, and the 24-hour activity bar instead of clipping them; use a compact
layout or scrolling for low heights. Add a regression test covering the full
80×24 rendering and asserting these Day Insights elements remain available.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ea22340-6e98-407a-823a-bacff0c9ecf3

📥 Commits

Reviewing files that changed from the base of the PR and between 1d52068 and 9c84e0c.

📒 Files selected for processing (6)
  • crates/tokscale-cli/src/commands/usage/kimi.rs
  • crates/tokscale-cli/src/commands/usage/zai.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/ui/mod.rs
  • crates/tokscale-cli/src/tui/ui/radar.rs
  • crates/tokscale-cli/src/tui/ui/stats.rs

@codspeed-hq

codspeed-hq Bot commented Jul 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 27 untouched benchmarks


Comparing port-kimi-ui/ux-desgin (b6be4d0) with personal/local-clients (1d52068)

Open in CodSpeed

… axis

The chart height stayed at the full area height when the caption flanks
bound the width, stretching the cross vertically and making the shape
drift with model-name length. The chart is now height-capped to stay
square in braille dots and vertically centered. The Others axis is
hidden when no models fold into it.
…labels

Kimi Code rows now render remaining as a percentage like the other
providers. Unknown window units no longer fall through to a misleading
seconds label, and non-positive Z.ai reset timestamps are treated as
no reset instead of resetting in 1970.
Canonical ids aggregate usage across providers, so there is no provider
color to look up and the name always fell back to gray. The top model is
now colored by the family provider inferred from the model id itself
(e.g. gpt-* -> openai, claude-* -> anthropic), keeping neutral gray for
unrecognized ids.

@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.

🧹 Nitpick comments (1)
crates/tokscale-cli/src/commands/usage/kimi.rs (1)

291-300: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

避免在缺少前缀时发生双重分配(Double Allocation)

当前实现中,unwrap_or(&normalized).to_string() 会将借用的 &str 转换并分配为一个全新的 String。由于 normalized 本身已经是通过 to_ascii_uppercase() 分配的 String,当字符串不包含 TIME_UNIT_ 前缀时,这种写法会导致无意义的二次内存分配并丢弃原字符串。

建议通过 if let 绑定来复用已有的 String 分配:

♻️ 建议的代码重构
     let unit = time_unit.map(|unit| {
         let normalized = unit.trim().to_ascii_uppercase();
-        normalized
-            .strip_prefix("TIME_UNIT_")
-            .unwrap_or(&normalized)
-            .to_string()
+        if let Some(stripped) = normalized.strip_prefix("TIME_UNIT_") {
+            stripped.to_string()
+        } else {
+            normalized
+        }
     });
🤖 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/commands/usage/kimi.rs` around lines 291 - 300,
Update the unit normalization closure in the time_unit mapping to reuse the
existing normalized String when the TIME_UNIT_ prefix is absent, and only create
a new String when stripping that prefix requires it. Replace the
unwrap_or(...).to_string() flow while preserving the current uppercase
normalization and resulting unit values.
🤖 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.

Nitpick comments:
In `@crates/tokscale-cli/src/commands/usage/kimi.rs`:
- Around line 291-300: Update the unit normalization closure in the time_unit
mapping to reuse the existing normalized String when the TIME_UNIT_ prefix is
absent, and only create a new String when stripping that prefix requires it.
Replace the unwrap_or(...).to_string() flow while preserving the current
uppercase normalization and resulting unit values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7bc8e3f-e53a-4527-8311-d9594cf54ba6

📥 Commits

Reviewing files that changed from the base of the PR and between 9c84e0c and b6be4d0.

📒 Files selected for processing (5)
  • crates/tokscale-cli/src/commands/usage/kimi.rs
  • crates/tokscale-cli/src/commands/usage/zai.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/ui/radar.rs
  • crates/tokscale-cli/src/tui/ui/stats.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/tokscale-cli/src/tui/ui/radar.rs
  • crates/tokscale-cli/src/commands/usage/zai.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/ui/stats.rs

@makoMakoGo
makoMakoGo merged commit bf6f7d4 into personal/local-clients Jul 18, 2026
9 checks passed
@makoMakoGo
makoMakoGo deleted the port-kimi-ui/ux-desgin branch July 19, 2026 10:05
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