Skip to content

Commit d575923

Browse files
authored
Merge pull request #6 from Ghvstcode/fix-budget-daily-mode
fix(tauri,ui): switch budget to daily mode and increase default
2 parents 3c2a744 + 028a65a commit d575923

5 files changed

Lines changed: 27 additions & 14 deletions

File tree

src-tauri/src/engine/budget.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct BudgetConfig {
5656
impl Default for BudgetConfig {
5757
fn default() -> Self {
5858
Self {
59-
weekly_token_budget: 700_000,
59+
weekly_token_budget: 5_000_000,
6060
max_usage_percent: 80,
6161
reserve_percent: 10,
6262
billing_mode: "subscription".to_string(),
@@ -143,14 +143,19 @@ pub fn get_weekly_usage() -> Result<(i64, String), String> {
143143
}
144144

145145
/// Calculate the full budget status given a budget config.
146+
///
147+
/// Uses **daily mode**: compares today's usage against a daily budget (weekly / 7)
148+
/// instead of comparing weekly totals against the weekly budget. This prevents heavy
149+
/// usage earlier in the week from falsely exhausting the budget for remaining days —
150+
/// the actual subscription resets on rolling windows, not as a rigid weekly lump sum.
146151
pub fn calculate_budget_status(config: &BudgetConfig) -> BudgetStatus {
147152
let (tokens_today, _) = get_today_usage().unwrap_or((0, "unavailable".to_string()));
148153
let (tokens_week, source) = get_weekly_usage().unwrap_or((0, "unavailable".to_string()));
149154

150-
let max_for_sustn =
151-
config.weekly_token_budget * (config.max_usage_percent as i64) / 100;
152-
let reserve = config.weekly_token_budget * (config.reserve_percent as i64) / 100;
153-
let available = (max_for_sustn - tokens_week - reserve).max(0);
155+
let daily_budget = config.weekly_token_budget / 7;
156+
let max_for_sustn = daily_budget * (config.max_usage_percent as i64) / 100;
157+
let reserve = daily_budget * (config.reserve_percent as i64) / 100;
158+
let available = (max_for_sustn - tokens_today - reserve).max(0);
154159

155160
BudgetStatus {
156161
weekly_token_budget: config.weekly_token_budget,

src-tauri/src/migrations.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,15 @@ pub fn migrations() -> Vec<Migration> {
292292
"#,
293293
kind: MigrationKind::Up,
294294
},
295+
Migration {
296+
version: 15,
297+
description: "increase default weekly_token_budget from 700k to 5M",
298+
sql: r#"
299+
UPDATE budget_config
300+
SET weekly_token_budget = 5000000
301+
WHERE weekly_token_budget = 700000;
302+
"#,
303+
kind: MigrationKind::Up,
304+
},
295305
]
296306
}

src/core/db/agent-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export async function getBudgetConfig(): Promise<BudgetConfig> {
165165
}
166166

167167
return {
168-
weeklyTokenBudget: 700_000,
168+
weeklyTokenBudget: 5_000_000,
169169
maxUsagePercent: 80,
170170
reservePercent: 10,
171171
billingMode: "subscription",

src/ui/components/settings/sections/BudgetSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function BudgetSection() {
5656
/>
5757
<div className="flex items-center justify-between">
5858
<p className="text-sm font-medium text-foreground">
59-
Use up to {ceiling}% of weekly budget
59+
Use up to {ceiling}% of daily budget
6060
</p>
6161
<p className="text-[13px] text-muted-foreground">
6262
{reserved}% reserved for manual use

src/ui/components/sidebar/AiStatusCard.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ export function AiStatusCard() {
2222
const isEnabled = agentConfig?.enabled ?? true;
2323
const isExhausted = budget?.budgetExhausted ?? false;
2424

25-
// Budget bar calculation
26-
const budgetCeiling = budget
27-
? (budget.weeklyTokenBudget * budget.maxUsagePercent) / 100
25+
// Budget bar — uses daily budget (weekly / 7) to match backend calculation
26+
const dailyBudget = budget
27+
? ((budget.weeklyTokenBudget / 7) * budget.maxUsagePercent) / 100
2828
: 0;
2929
const available = budget?.tokensAvailableForSustn ?? 0;
3030
const usedPercent =
31-
budgetCeiling > 0
32-
? ((budgetCeiling - available) / budgetCeiling) * 100
33-
: 0;
31+
dailyBudget > 0 ? ((dailyBudget - available) / dailyBudget) * 100 : 0;
3432
const remainingPercent = 100 - usedPercent;
3533

3634
// Bar color
@@ -46,7 +44,7 @@ export function AiStatusCard() {
4644
if (isExhausted) {
4745
icon = <AlertTriangle className="h-3 w-3 shrink-0 text-amber-500" />;
4846
line1 = "Budget limit";
49-
line2 = "Resets Monday";
47+
line2 = "Resets tomorrow";
5048
} else if (!isEnabled) {
5149
icon = (
5250
<svg

0 commit comments

Comments
 (0)