Repository navigation
feat: add quota analysis with multi-tier support #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||
| use anyhow::Result; | ||||||||
| use crate::tracking::Tracker; | ||||||||
|
|
||||||||
| pub fn run(graph: bool, history: bool, verbose: u8) -> Result<()> { | ||||||||
| pub fn run(graph: bool, history: bool, quota: bool, tier: &str, _verbose: u8) -> Result<()> { | ||||||||
| let tracker = Tracker::new()?; | ||||||||
| let summary = tracker.get_summary()?; | ||||||||
|
|
||||||||
|
|
@@ -68,6 +68,29 @@ pub fn run(graph: bool, history: bool, verbose: u8) -> Result<()> { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| if quota { | ||||||||
| const ESTIMATED_PRO_MONTHLY: usize = 6_000_000; // ~6M tokens/month (heuristic: ~44K/5h × 6 periods/day × 30 days) | ||||||||
|
|
||||||||
| let (quota_tokens, tier_name) = match tier { | ||||||||
| "pro" => (ESTIMATED_PRO_MONTHLY, "Pro ($20/mo)"), | ||||||||
| "5x" => (ESTIMATED_PRO_MONTHLY * 5, "Max 5x ($100/mo)"), | ||||||||
| "20x" => (ESTIMATED_PRO_MONTHLY * 20, "Max 20x ($200/mo)"), | ||||||||
| _ => (ESTIMATED_PRO_MONTHLY, "Pro ($20/mo)"), // default fallback | ||||||||
| }; | ||||||||
|
|
||||||||
| let quota_pct = (summary.total_saved as f64 / quota_tokens as f64) * 100.0; | ||||||||
|
|
||||||||
|
||||||||
| println!(); |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new quota calculation logic lacks test coverage. The repository has comprehensive test coverage (tests found in filter.rs, git.rs, grep_cmd.rs, json_cmd.rs, local_llm.rs, log_cmd.rs, ls.rs, pnpm_cmd.rs, read.rs, runner.rs, vitest_cmd.rs), but gain.rs has no tests. Consider adding unit tests to verify: 1) correct quota calculations for each tier (pro, 5x, 20x), 2) the format_tokens function works correctly with the quota values, 3) percentage calculations are accurate, and 4) edge cases like zero total_saved.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -232,6 +232,12 @@ enum Commands { | |||||||||||||||||
| /// Show recent command history | ||||||||||||||||||
| #[arg(short = 'H', long)] | ||||||||||||||||||
| history: bool, | ||||||||||||||||||
| /// Show monthly quota savings estimate | ||||||||||||||||||
| #[arg(short, long)] | ||||||||||||||||||
| quota: bool, | ||||||||||||||||||
| /// Subscription tier for quota calculation: pro, 5x, 20x | ||||||||||||||||||
| #[arg(short, long, default_value = "20x", requires = "quota")] | ||||||||||||||||||
|
||||||||||||||||||
| #[arg(short, long, default_value = "20x", requires = "quota")] | |
| #[arg( | |
| short, | |
| long, | |
| default_value = "20x", | |
| requires = "quota", | |
| value_parser = ["pro", "5x", "20x"] | |
| )] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment states "~44K/5h × 6 periods/day × 30 days" but this calculation yields approximately 7.9M tokens, not 6M. Additionally, 24 hours divided by 5-hour periods equals 4.8 periods per day, not 6. The constant value of 6M appears to be based on different assumptions than what the comment describes. Consider either: 1) updating the comment to accurately reflect the calculation (e.g., "~44K/5h × 4.5 periods/day × 30 days"), or 2) clarifying that this is a conservative estimate with different assumptions.