fix(core): canonicalize grouped model variants - #14
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Walkthrough核心为模型分组归一化升级:新增 free 尾标记清理工具和 Claude 版本规范化逻辑,调整归一化流程顺序;升级缓存 schema 版本强制刷新,同步更新测试夹具和断言;扩展 provider 别名映射覆盖编码/计划类变体。 Changes模型分组与缓存更新
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
Code Review
This pull request updates the model normalization logic to handle 'free' markers and refines the canonicalization of Claude models, specifically mapping Sonnet and Haiku version 4 models to a base version while maintaining minor versions for Opus. It also increments the cache schema version to 8 and updates relevant test cases. Feedback suggests expanding the FREE_MARKER_TRAILING_SUFFIXES list to include missing noise suffixes like -thinking and -sub2api-pro, and updating colorKey values in test data to maintain consistency with the new model IDs.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/tokscale-core/src/lib.rs (2)
149-179: ⚡ Quick win建议为复杂的嵌套循环逻辑添加注释说明。
strip_trailing_free_marker函数实现了一个多层嵌套的剥离算法:外层循环持续处理直到稳定,内部探测循环通过逐步剥离后缀来寻找被遮蔽的 free 标记。这个算法逻辑正确但较为复杂,建议在以下关键位置添加注释:
- 外层 loop 开始处说明"重复剥离直到无变化"的意图
- Lines 164-172 探测循环前说明"通过剥离尾缀来暴露隐藏的 free 标记"
- 说明为什么需要
trim_end()和空值检查这将显著提升代码可读性与可维护性。
📝 建议添加的注释示例
fn strip_trailing_free_marker(mut name: &str) -> &str { + // 重复剥离 free 标记及其关联后缀,直到字符串稳定 loop { let trimmed = name.trim_end(); if trimmed.len() != name.len() { name = trimmed; continue; } + // 尝试直接剥离 free 标记(-free, :free, (free) 等) if let Some(value) = strip_direct_free_marker(name) { if !value.is_empty() { name = value.trim_end(); continue; } } + // 探测:逐步剥离尾缀以暴露被遮蔽的 free 标记 + // 例如 "model-free-high" -> 剥离 "-high" -> 发现 "-free" let mut probe = name; let mut exposed_free = None; while let Some(stripped_probe) = strip_suffix_once(probe, FREE_MARKER_TRAILING_SUFFIXES) { probe = stripped_probe.trim_end(); if let Some(value) = strip_direct_free_marker(probe) { exposed_free = Some(value.trim_end()); break; } }🤖 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-core/src/lib.rs` around lines 149 - 179, Add explanatory comments inside the strip_trailing_free_marker function: at the start of the outer loop describe the intent "repeat stripping until stable/no-change", before the inner probe loop (the while let Some(stripped_probe) = strip_suffix_once(...)) explain "strip trailing suffixes iteratively to expose a hidden direct free marker", and add a brief note near uses of trim_end() and the empty checks to explain they remove trailing whitespace and guard against empty results so we don't loop forever or return misleading empty names; reference the function name strip_trailing_free_marker and the inner probe loop that uses strip_suffix_once and strip_direct_free_marker when placing these comments.
265-267: 💤 Low valueClaude 版本 4 的特殊处理规则已硬编码。
Lines 265-267 对
claude-sonnet-4.x和claude-haiku-4.x强制归一化为claude-{family}-4,但claude-opus-4.x保留次版本号。这符合当前 PR 目标和测试预期。然而,这个规则是硬编码的版本号判断。若未来发布 Claude 5.x 或其他主版本,需要重新评估是否需要类似的特殊处理逻辑。建议在代码注释中记录这个设计决策的背景。
💡 建议添加的注释
+ // 特殊规则:Sonnet 4.x 和 Haiku 4.x 归一化为版本 4(无次版本号) + // 但 Opus 4.x 保留次版本号以区分不同变体 + // 此规则基于 Anthropic 的官方命名约定(截至 2025 年) if major == "4" && matches!(family, "sonnet" | "haiku") { return Some(format!("claude-{family}-4")); }🤖 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-core/src/lib.rs` around lines 265 - 267, Add a brief explanatory comment above the special-case block that checks major == "4" and matches!(family, "sonnet" | "haiku") (the clause that returns Some(format!("claude-{family}-4"))) describing why Claude 4.x sonnet/haiku are being normalized to `claude-{family}-4`, that `claude-opus-4.x` intentionally preserves the minor version, and note this is a deliberate, version-specific decision that may need reevaluation for future major releases (e.g., Claude 5.x); include guidance to revisit the rule if new major versions are released.
🤖 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-core/src/lib.rs`:
- Around line 149-179: Add explanatory comments inside the
strip_trailing_free_marker function: at the start of the outer loop describe the
intent "repeat stripping until stable/no-change", before the inner probe loop
(the while let Some(stripped_probe) = strip_suffix_once(...)) explain "strip
trailing suffixes iteratively to expose a hidden direct free marker", and add a
brief note near uses of trim_end() and the empty checks to explain they remove
trailing whitespace and guard against empty results so we don't loop forever or
return misleading empty names; reference the function name
strip_trailing_free_marker and the inner probe loop that uses strip_suffix_once
and strip_direct_free_marker when placing these comments.
- Around line 265-267: Add a brief explanatory comment above the special-case
block that checks major == "4" and matches!(family, "sonnet" | "haiku") (the
clause that returns Some(format!("claude-{family}-4"))) describing why Claude
4.x sonnet/haiku are being normalized to `claude-{family}-4`, that
`claude-opus-4.x` intentionally preserves the minor version, and note this is a
deliberate, version-specific decision that may need reevaluation for future
major releases (e.g., Claude 5.x); include guidance to revisit the rule if new
major versions are released.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e0334f54-1283-4689-ad7f-61b036d354ed
📒 Files selected for processing (3)
crates/tokscale-cli/src/tui/cache.rscrates/tokscale-cli/src/tui/data/mod.rscrates/tokscale-core/src/lib.rs
|
Added the requested provider display aliases after checking OMP/OpenCode provider IDs:
Validation: |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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/lib.rs`:
- Around line 66-78: The Claude-specific normalization misses a common suffix
and the date-strip pass happens only once before the Claude branch; update the
CLAUDE_GROUPING_NOISE_SUFFIXES constant to include "-sub2api-pro" and change the
Claude normalization flow so date/provider/tier normalization runs after suffix
removal (or perform the date-strip / normalization iteratively until stable) in
the Claude branch handling code (the block that currently uses
CLAUDE_GROUPING_NOISE_SUFFIXES and the provider/tier/date normalization around
the Claude branch).
🪄 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: 45d88f7d-3a28-40f8-aaf9-0680bd8dc7da
📒 Files selected for processing (2)
crates/tokscale-cli/src/tui/ui/widgets.rscrates/tokscale-core/src/lib.rs
Summary
claude-opus-4.6andclaude-sonnet-4.-free,(free),:free, and variants followed by tier suffixes.Fixes #13.
Validation
cargo fmt --checkcargo testSummary by CodeRabbit
发布说明
新特性
改进