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

fix(tui): use client catalog metadata - #85

Merged
makoMakoGo merged 1 commit into
personal/local-clientsfrom
codex/remove-openclaw-emoji
Jun 30, 2026
Merged

fix(tui): use client catalog metadata#85
makoMakoGo merged 1 commit into
personal/local-clientsfrom
codex/remove-openclaw-emoji

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Remove the OpenClaw-only emoji display override from the TUI client display helper.
  • Add ClientId::color() so TUI code can read client catalog color metadata directly.
  • Make tui::colors the owner for TUI color parsing, provider shades, model colors, and client colors.
  • Keep user-configured client/provider colors as explicit overrides, while known client colors come from the catalog and unknown clients use a named UI color.
  • Leave widgets.rs focused on non-color formatting/display helpers instead of color policy.

Root Cause

TUI client metadata was split across the generated client catalog and local helper hardcodes. Display names mostly used the catalog, but OpenClaw had a special emoji branch. Client colors used a separate TUI match table even though the catalog already stores validated #RRGGBB colors. Color policy also lived in widgets.rs, which made colors.rs depend back on widgets for provider shade behavior.

User Impact

Known client names and colors now share the client catalog as their source of truth. Some TUI client colors intentionally switch to catalog values where the old TUI table disagreed, including OpenCode and Droid.

Structure

The TUI color seam now points one way: app/stats/model shade code call tui::colors, tui::colors reads raw config values and catalog metadata, and widgets.rs no longer owns color policy. Config remains a raw settings module and no longer parses ratatui colors itself.

Validation

  • cargo clippy --locked --workspace --all-features -- -D warnings
  • cargo test -p tokscale-cli client_color_uses_catalog_for_known_clients
  • cargo test -p tokscale-cli parse_hex_color_rejects_non_ascii_hex_without_panicking
  • cargo test -p tokscale-cli every_catalog_client_color_is_parseable
  • cargo test -p tokscale-cli
  • cargo test -p tokscale-core
  • rg -n "🦞 OpenClaw|🦞|"(opencode|claude|codex|cursor|gemini|amp|droid|openclaw|hermes|goose|codebuff|antigravity|zed|warp)" => Color::Rgb" crates packages docs README.md

Summary by CodeRabbit

  • New Features

    • 支持为提供商和客户端配置自定义颜色,并更稳定地应用到界面显示。
    • 提供商颜色会按层级生成渐变效果,超出范围时自动保持一致。
    • 客户端名称显示更统一,修复了个别名称带特殊符号的问题。
  • Bug Fixes

    • 改进了颜色匹配与回退逻辑,避免未知项显示异常颜色。
    • 修正了部分名称和配色在列表与统计视图中的不一致问题。

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 67e2a7e6-ec9c-4da8-a2d8-d5e53a1c29cd

📥 Commits

Reviewing files that changed from the base of the PR and between 6d05df1 and 9624519.

📒 Files selected for processing (6)
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/colors.rs
  • crates/tokscale-cli/src/tui/config.rs
  • crates/tokscale-cli/src/tui/ui/stats.rs
  • crates/tokscale-cli/src/tui/ui/widgets.rs
  • crates/tokscale-core/build.rs

代码审查摘要

将颜色解析与分配逻辑从 widgetsconfig 中提取到独立的 colors.rs 模块,TokscaleConfig 颜色查询方法由返回 Option<Color> 改为返回 Option<&str>(原始 hex 字符串),build.rs 生成代码中新增 ClientId::color() 访问器,并移除 get_single_client_display_name 中 OpenClaw 的 emoji 硬编码分支。

变更详情

颜色逻辑提取与重构

Layer / File(s) 摘要
TokscaleConfig 颜色方法替换
crates/tokscale-cli/src/tui/config.rs
移除 get_provider_color/get_client_color(返回 Option<Color>)及 parse_hex_color 私有函数,新增 get_provider_color_hex/get_client_color_hex 直接返回 hex 字符串切片,不再对 key 做 to_lowercase() 归一化。
build.rs 生成 ClientId::color() 访问器
crates/tokscale-core/build.rs
在代码生成逻辑中插入 pub fn color(self) -> &'static str,使外部可通过 ClientId::color() 取得 catalog 颜色字段。
colors.rs 核心实现与测试
crates/tokscale-cli/src/tui/colors.rs
新增 parse_hex_color(严格 ASCII hex 校验)、shade_from_base(7 档渐变)、get_provider_shade(配置覆盖/名称匹配/rank 钳制)、get_client_color(覆盖/catalog/回退)、provider_color_key(逗号拆分取首段);扩展大量单元测试覆盖各分支与边界条件。
调用方导入路径更新
crates/tokscale-cli/src/tui/app.rs, crates/tokscale-cli/src/tui/ui/stats.rs, crates/tokscale-cli/src/tui/ui/widgets.rs
app.rsstats.rs 将颜色函数导入来源从 ui::widgets 改为 colorswidgets.rs 移除 ratatui::prelude::* 全量导入。
移除 OpenClaw emoji 硬编码分支与测试更新
crates/tokscale-cli/src/tui/ui/widgets.rs
删除 get_single_client_display_nameClientId::OpenClaw 的特殊返回分支(原 "🦞 OpenClaw"),改走通用 client_ui::display_name 路径;新增断言验证 get_client_display_name("openclaw") == "OpenClaw"

预估代码审查难度

🎯 3 (Moderate) | ⏱️ ~25 minutes

可能相关的 PR

  • makoMakoGo/tokscale#5:同样涉及 widgets.rs 中的客户端/提供商显示名格式化逻辑与 merged/逗号列表测试,与本次 OpenClaw 显示名修改存在直接代码重叠。

小诗

🐇 小兔轻敲键盘声,
龙虾 emoji 悄悄退场,
色板模块独立而生,
hex 字符串清晰又亮,
七档渐变向白光,
OpenClaw 素颜登场! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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
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.
Title check ✅ Passed 标题准确概括了这次改动:TUI 改为使用客户端目录元数据来渲染显示名。
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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 codex/remove-openclaw-emoji

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 Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing codex/remove-openclaw-emoji (9624519) with personal/local-clients (f91d3e9)

Open in CodSpeed

@makoMakoGo

Copy link
Copy Markdown
Owner Author

/juya review

@juya-review-bot

Copy link
Copy Markdown

OpenCodeReview: No comments generated. Looks good to me.

@makoMakoGo
makoMakoGo force-pushed the codex/remove-openclaw-emoji branch from 6d05df1 to 3cc5e75 Compare June 30, 2026 12:44
@makoMakoGo makoMakoGo changed the title fix(tui): use catalog display name for OpenClaw fix(tui): use client catalog metadata Jun 30, 2026
@makoMakoGo
makoMakoGo force-pushed the codex/remove-openclaw-emoji branch 2 times, most recently from 14115c9 to d2cef6e Compare June 30, 2026 13:24
@makoMakoGo
makoMakoGo force-pushed the codex/remove-openclaw-emoji branch from d2cef6e to 9624519 Compare June 30, 2026 15:24
@makoMakoGo
makoMakoGo marked this pull request as ready for review June 30, 2026 15:36
@makoMakoGo
makoMakoGo merged commit 8605498 into personal/local-clients Jun 30, 2026
9 checks passed
@makoMakoGo
makoMakoGo deleted the codex/remove-openclaw-emoji branch June 30, 2026 15:37

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 6 files

Re-trigger cubic

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