mirror of
https://github.com/rtk-ai/rtk.git
synced 2026-09-19 07:33:17 +08:00
5b840cca49
Apply systematic quality fixes identified in code audit: Phase 1: Remove dead code (4 warnings → 0) - Remove unused run_compact() function in gain.rs - Remove unused track_tokens() function in tracking.rs - Remove unused TRACKER singleton (Mutex) - Clean up CommandRecord struct (remove unused fields) Phase 2: Add error context and quality fixes - Add .context() to all ? operators in cc_economics.rs (15+ callsites) - Add .context() to all ? operators in gain.rs (10+ callsites) - Fix bounds check panic risk in gain.rs:252 (week_start slice) - Reduce visibility: estimate_tokens pub → private - Replace 6 manual loops with idiomatic .collect::<Result<Vec<_>, _>>()? - Remove residual dev comment (// psk:) - Remove unnecessary .clone() in main.rs Phase 3: Refactor duplication (132 lines eliminated) - Create display_helpers.rs module with PeriodStats trait - Unify print_daily_full/weekly/monthly in gain.rs (152 lines → 9 lines) - Implement trait for DayStats, WeekStats, MonthStats - Zero-overhead compile-time dispatch (monomorphization) - Output bit-identical, all tests passing Impact: - Dead code: -20 lines - Error context: Errors now actionable instead of opaque - Duplication: -132 lines of pure duplication - Safety: Bounds check prevents potential panic - Idiomaticity: .collect() over manual loops Metrics: - Build: 0 errors, 1 warning (pre-existing cache_* fields) - Tests: 79/82 passing (3 pre-existing failures) - Clippy: 13 warnings (all pre-existing) - Functional: rtk gain --daily, rtk cc-economics validated Addresses code audit feedback from parallel session Detailed report: claudedocs/refactoring-report.md Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>