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

fix(tui): order merged sources and balance model columns - #8

Merged
makoMakoGo merged 3 commits into
personal/local-clientsfrom
fix/source-contribution-order
May 16, 2026
Merged

fix(tui): order merged sources and balance model columns#8
makoMakoGo merged 3 commits into
personal/local-clientsfrom
fix/source-contribution-order

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Order merged model sources by total token contribution in GroupBy::Model and GroupBy::WorkspaceModel reports.
  • Balance wide Models table text columns so Model no longer consumes all extra space while Provider / Source remain truncated.
  • Cap text columns by visible content needs so Source stops growing after it fits and leftover width is not forced into text columns.

Closes #6.
Closes #7.

Verification

  • cargo test --package tokscale-core test_model_grouping_orders_merged_clients_by_total_tokens
  • cargo test --package tokscale-cli test_aggregate_messages_orders_model_clients_by_total_tokens
  • cargo test --package tokscale-cli tui::ui::models::tests
  • cargo check --package tokscale-cli
  • cargo build --release -p tokscale-cli

Local binary

Installed to /home/travis/.local/bin/tokscale.

tokscale 2.1.1
sha256: 68528ee5baa619f5e912d09e169c26d1b7ae0cb74ce36c88057c1fbb53ac9f87

Summary by CodeRabbit

版本更新说明

  • 功能优化
    • 模型客户端列表现按令牌贡献总量排序,便于快速识别主要贡献者
    • 模型表格支持自适应列宽分配,优化不同显示宽度下的视图效果

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cea73888-a13f-43a0-a949-b345633ae1fc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/source-contribution-order

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 and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a dynamic table layout system for the TUI and implements a token-based sorting mechanism for client contributions. The review feedback suggests enhancing the robustness of token calculations using saturating arithmetic, improving TUI visual stability by calculating column widths across the entire dataset rather than just visible rows, and addressing code duplication between the CLI and core crates. Additionally, it recommends using specialized crates for accurate character width calculation and simplifying the layout distribution logic.

Comment thread crates/tokscale-core/src/lib.rs Outdated
Comment thread crates/tokscale-cli/src/tui/ui/models.rs Outdated
Comment thread crates/tokscale-cli/src/tui/ui/models.rs Outdated
Comment thread crates/tokscale-cli/src/tui/ui/models.rs Outdated
Comment thread crates/tokscale-core/src/lib.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.

Actionable comments posted: 2

🤖 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-cli/src/tui/ui/models.rs`:
- Around line 65-67: The display_width() function uses chars().count() which
measures codepoints not terminal column width; update
crates/tokscale-cli/Cargo.toml to add the unicode-width crate and in
src/tui/ui/models.rs replace uses of chars().count() with
UnicodeWidthStr::width() (e.g., call s.width()) in display_width() and similarly
update truncate() to compute widths via UnicodeWidthStr::width(), then
clamp/convert the resulting usize to u16 (min(u16::MAX as usize)) to preserve
the previous bounds.

In `@crates/tokscale-core/src/lib.rs`:
- Line 1413: 在累加 token 时不要直接使用可能为负的 msg.tokens.total(),应与 TUI 保持一致先将负值截为 0
再累加;在对 totals.total_tokens 做更新的地方(当前使用 totals.total_tokens += msg.tokens.total()
的位置)改为使用非负值(例如对 msg.tokens.total() 应用 max(0) 或等效的零下限判断)再加到
totals.total_tokens,以确保 core 报表与 TUI 的 merged clients 排序一致。
🪄 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

Run ID: c19f911f-9e6e-45e2-b223-9b2270c9e0fc

📥 Commits

Reviewing files that changed from the base of the PR and between 28d7e8a and 4208943.

📒 Files selected for processing (3)
  • crates/tokscale-cli/src/tui/data/mod.rs
  • crates/tokscale-cli/src/tui/ui/models.rs
  • crates/tokscale-core/src/lib.rs

Comment thread crates/tokscale-cli/src/tui/ui/models.rs
Comment thread crates/tokscale-core/src/lib.rs Outdated
@makoMakoGo
makoMakoGo merged commit 730c88f into personal/local-clients May 16, 2026
3 checks passed
@makoMakoGo
makoMakoGo deleted the fix/source-contribution-order branch May 17, 2026 04:13
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