fix(cost): derive local costs from token pricing

Merged
MA
5mo ago
+603-1997

Summary

  • Add ADR 0011 for token-derived local report cost semantics.
  • Ignore app/vendor cost fields in local parsers and always derive UnifiedMessage.cost through Tokscale pricing.
  • Drop cost-only rows and disable both Crush and Warp usage rows until token-level sources exist.
  • Bump source-message cache schema to rebuild cached app-reported costs.

Verification

  • cargo test -p tokscale-core
  • cargo test -p tokscale-cli
  • cargo run -p tokscale-cli -- --no-spinner --json --client crush
  • cargo run -p tokscale-cli -- --no-spinner --json --client opencode

Summary by cubic

Local report costs now derive only from token pricing. Parsers ignore app/vendor spend, rows without positive tokens are dropped, and cost-only clients (Crush, Warp) are fully disabled and removed from scanning.

  • Refactors

    • Token-only pricing: compute UnifiedMessage.cost from tokens via crate::finalize_token_priced_messages; strip embedded costs in parsers; normalize token buckets; skip zero-token rows; clean totals (including -0.0) in reports/TUI; offline totals are 0.0 without pricing.
    • Remove cost-only clients: delete crush/warp adapters and session parsers, drop their local scan paths, mark them as not locally parsed, update the scanner to ignore them, remove Warp cache checks and leftover scan/submit paths, and trim related CLI/tests.
  • Migration

    • Bump source-message cache schema to 26; cache rebuilds on first run.

Summary by CodeRabbit

发布说明

  • Bug Fixes

    • 统一成本口径:本地报告的费用仅从 token 使用量派生计算;当缺少正 token 时会丢弃/归零仅费用类信息,且聚合总成本会进行净化。
    • 相关会话/适配流程不再依赖供应商上报的费用字段;改进集成结果一致性。
    • 命令行离线模式下的成本输出断言更严格(缺少定价缓存场景 totalCost 现在精确为 0.0)。
    • 报表中对无 token 的 Warp/Crush 数据不再纳入,并更新本地告警文案。
  • Chores

    • 更新缓存架构版本,触发缓存重建以适配新的定价语义。