Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ menu-bar layout.

### Fixed
- Kimi: when the Kimi Code CLI credential is stale or rejected and web auth has no token to try, direct the user to run `kimi` or add a Kimi Code API key in Settings, keeping the web fallback and leaving CLI-owned credentials read-only. A rejected web token still reports the web error, and a Kimi Code API 403 reports a permission or quota denial instead of a sign-in problem.
- Kimi Code: while the monthly membership pool is exhausted, show the shorter Code windows as “Blocked by monthly limit” without their own usage bar, reset, or pace forecast, keeping the raw usage in the CLI, tray icon, and float bar; the block lifts at the pool's reset even before the next refresh.
- Claude: when Hide Personal Info is enabled, keep saved account rows distinguishable with stable localized `Account N` labels and matching redacted tooltips.

---
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/auto_resume_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}
}

Expand Down
42 changes: 30 additions & 12 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
pub(crate) mod pace;
mod quota_block;
mod status;
pub use quota_block::MonthlyLimitBlockSnapshot;
pub(crate) use status::{compact_tray_status_label, friendly_provider_error};

use super::*;
use codexbar::core::BlockedWindows;

// ── Bridge snapshot types ────────────────────────────────────────────

Expand Down Expand Up @@ -31,6 +34,10 @@ pub struct RateWindowSnapshot {
pub reserve_will_last_to_reset: bool,
#[serde(default)]
pub reserve_eta_seconds: Option<f64>,
/// Set while a longer exhausted pool (Kimi's monthly membership) blocks
/// this window; presentation only, the raw percentages above stay as is.
#[serde(default)]
pub monthly_limit_block: Option<MonthlyLimitBlockSnapshot>,
}

/// Serde default for [`RateWindowSnapshot::remaining_percent`] — the common
Expand All @@ -53,6 +60,7 @@ impl RateWindowSnapshot {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}
}

Expand Down Expand Up @@ -159,6 +167,9 @@ pub struct PaceSnapshot {
pub expected_used_percent: f64,
#[serde(default)]
pub actual_used_percent: f64,
/// Block of the window this pace comes from (upstream hides its pace).
#[serde(default)]
pub monthly_limit_block: Option<MonthlyLimitBlockSnapshot>,
}

/// Session-equivalent weekly forecast for Claude/Codex menu secondary line.
Expand Down Expand Up @@ -337,13 +348,15 @@ impl ProviderUsageSnapshot {
});
let primary_pace = primary_pace.flatten();

let blocked = BlockedWindows::evaluate(id, usage, chrono::Utc::now());
let pace = primary_pace.as_ref().map(|p| PaceSnapshot {
stage: pace::stage_str(p.stage).to_string(),
delta_percent: p.delta_percent,
will_last_to_reset: p.will_last_to_reset,
eta_seconds: p.eta_seconds,
expected_used_percent: p.expected_used_percent,
actual_used_percent: p.actual_used_percent,
monthly_limit_block: MonthlyLimitBlockSnapshot::for_pace(usage, &blocked),
});

// Compute pace for secondary window (weekly) to derive reserve info
Expand All @@ -355,10 +368,12 @@ impl ProviderUsageSnapshot {
});
let secondary_pace = secondary_pace.flatten();

let primary_snap = RateWindowSnapshot::from_rate_window(&usage.primary);
let primary_snap = RateWindowSnapshot::from_rate_window(&usage.primary)
.with_quota_block(blocked.primary, &blocked);

let secondary_snap = usage.secondary.as_ref().map(|sw| {
let mut s = RateWindowSnapshot::from_rate_window(sw);
let mut s = RateWindowSnapshot::from_rate_window(sw)
.with_quota_block(blocked.secondary, &blocked);
if let Some(ref p) = secondary_pace {
s = s.with_pace_reserve(p);
}
Expand Down Expand Up @@ -394,14 +409,13 @@ impl ProviderUsageSnapshot {
.clone()
.unwrap_or_else(|| metadata.weekly_label.to_string())
}),
model_specific: usage
.model_specific
.as_ref()
.map(RateWindowSnapshot::from_rate_window),
tertiary: usage
.tertiary
.as_ref()
.map(RateWindowSnapshot::from_rate_window),
model_specific: usage.model_specific.as_ref().map(|w| {
RateWindowSnapshot::from_rate_window(w)
.with_quota_block(blocked.model_specific, &blocked)
}),
tertiary: usage.tertiary.as_ref().map(|w| {
RateWindowSnapshot::from_rate_window(w).with_quota_block(blocked.tertiary, &blocked)
}),
// F5 (upstream 0.48.0): label the tertiary lane by its duration cadence
// so surfaces (MenuCard, CLI, tray) can show "Monthly" instead of the
// generic "DetailWindowTertiary" slot key.
Expand All @@ -416,10 +430,12 @@ impl ProviderUsageSnapshot {
extra_rate_windows: usage
.extra_rate_windows
.iter()
.map(|extra| NamedRateWindowSnapshot {
.zip(&blocked.extra)
.map(|(extra, &is_blocked)| NamedRateWindowSnapshot {
id: extra.id.clone(),
title: extra.title.clone(),
window: RateWindowSnapshot::from_rate_window(&extra.window),
window: RateWindowSnapshot::from_rate_window(&extra.window)
.with_quota_block(is_blocked, &blocked),
fallback_lane: extra.fallback_lane,
})
.collect(),
Expand Down Expand Up @@ -518,6 +534,7 @@ impl ProviderUsageSnapshot {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
},
primary_label: Some(metadata.session_label.to_string()),
secondary: None,
Expand Down Expand Up @@ -985,6 +1002,7 @@ mod tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}
}

Expand Down
155 changes: 155 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/bridge/quota_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//! Bridge shape of a longer exhausted quota that blocks a shorter window
//! (upstream 0.69.0 #4091, Kimi's monthly membership pool).
//!
//! Upstream evaluates `menuCard.blockingQuota` whenever it builds the menu
//! card, so a blocked row recovers as soon as the pool resets. Bridge
//! snapshots outlive their fetch (the provider cache keeps the last good
//! snapshot through failed refreshes), so each blocked window carries the
//! pool's reset and the frontend re-checks it at render time.

use super::*;

/// Set on a window while a longer exhausted pool blocks it. Presentation only:
/// the window's raw percentages stay the provider's data.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MonthlyLimitBlockSnapshot {
/// RFC 3339 reset of the exhausted pool; the block lifts then. `None` when
/// the pool's reset is unknown, so the block holds until a refresh.
#[serde(default)]
pub resets_at: Option<String>,
}

impl MonthlyLimitBlockSnapshot {
pub(super) fn for_window(blocked: bool, blocks: &BlockedWindows) -> Option<Self> {
blocked.then(|| Self {
resets_at: blocks.resets_at.map(|reset| reset.to_rfc3339()),
})
}

/// Block of the window the provider-level pace derives from: the weekly
/// lane when the primary is an informational stand-in, else the primary.
pub(super) fn for_pace(
usage: &codexbar::core::UsageSnapshot,
blocks: &BlockedWindows,
) -> Option<Self> {
let blocked = if usage.primary.is_informational {
blocks.secondary
} else {
blocks.primary
};
Self::for_window(blocked, blocks)
}
}

impl RateWindowSnapshot {
pub(super) fn with_quota_block(mut self, blocked: bool, blocks: &BlockedWindows) -> Self {
self.monthly_limit_block = MonthlyLimitBlockSnapshot::for_window(blocked, blocks);
self
}
}

#[cfg(test)]
mod tests {
use super::*;
use chrono::{Duration, Utc};
use codexbar::core::UsageSnapshot;

fn monthly_pool(reset: Option<chrono::DateTime<Utc>>) -> RateWindow {
RateWindow::with_details(100.0, Some(43_200), reset, None)
}

fn bridge_snapshot(id: ProviderId, usage: UsageSnapshot) -> ProviderUsageSnapshot {
let result = ProviderFetchResult::new(usage, "web");
let metadata = instantiate_provider(id).metadata().clone();
ProviderUsageSnapshot::from_fetch_result(id, &metadata, &result, None)
}

#[test]
fn exhausted_kimi_monthly_pool_marks_shorter_windows_without_changing_raw_usage() {
let reset = Utc::now() + Duration::days(20);
let primary = RateWindow::with_details(
0.0,
Some(10_080),
Some(Utc::now() + Duration::days(3)),
None,
);
let usage = UsageSnapshot::new(primary).with_extra_rate_window(
"kimi-monthly",
"Total usage",
monthly_pool(Some(reset)),
);

let snapshot = bridge_snapshot(ProviderId::Kimi, usage.clone());
let block = MonthlyLimitBlockSnapshot {
resets_at: Some(reset.to_rfc3339()),
};
assert_eq!(snapshot.primary.monthly_limit_block, Some(block.clone()));
assert_eq!(snapshot.primary.used_percent, 0.0);
assert_eq!(
snapshot.extra_rate_windows[0].window.monthly_limit_block,
None
);
// Upstream drops the blocked metric's pace forecast; the provider-level
// pace comes from the primary here, so it carries the same block.
let pace = snapshot.pace.as_ref().expect("primary pace");
assert_eq!(pace.monthly_limit_block, Some(block));

let json = serde_json::to_value(&snapshot).unwrap();
assert_eq!(
json["primary"]["monthlyLimitBlock"]["resetsAt"],
reset.to_rfc3339()
);
assert!(json["extraRateWindows"][0]["window"]["monthlyLimitBlock"].is_null());
assert!(json["pace"]["monthlyLimitBlock"].is_object());

// Other providers never derive a blocker from a same-named window.
let snapshot = bridge_snapshot(ProviderId::Codex, usage);
assert_eq!(snapshot.primary.monthly_limit_block, None);
assert_eq!(snapshot.pace.as_ref().unwrap().monthly_limit_block, None);
}

#[test]
fn unknown_monthly_reset_blocks_without_a_lift_time() {
let usage = UsageSnapshot::new(RateWindow::with_details(0.0, Some(10_080), None, None))
.with_extra_rate_window("kimi-monthly", "Total usage", monthly_pool(None));

let snapshot = bridge_snapshot(ProviderId::Kimi, usage);
assert_eq!(
snapshot.primary.monthly_limit_block,
Some(MonthlyLimitBlockSnapshot { resets_at: None })
);
let json = serde_json::to_value(&snapshot).unwrap();
assert!(json["primary"]["monthlyLimitBlock"].is_object());
assert!(json["primary"]["monthlyLimitBlock"]["resetsAt"].is_null());
}

#[test]
fn informational_primary_takes_the_pace_block_from_the_weekly_lane() {
let reset = Utc::now() + Duration::days(20);
let mut usage = UsageSnapshot::new(RateWindow::informational("No active session"))
.with_extra_rate_window("kimi-monthly", "Total usage", monthly_pool(Some(reset)));
usage.secondary = Some(RateWindow::with_details(
10.0,
Some(10_080),
Some(Utc::now() + Duration::days(3)),
None,
));

let snapshot = bridge_snapshot(ProviderId::Kimi, usage);
assert_eq!(snapshot.primary.monthly_limit_block, None);
assert!(snapshot.secondary.unwrap().monthly_limit_block.is_some());
assert!(snapshot.pace.unwrap().monthly_limit_block.is_some());
}

#[test]
fn snapshots_without_the_field_deserialize_unblocked() {
let window: RateWindowSnapshot =
serde_json::from_value(serde_json::json!({ "usedPercent": 40.0 })).unwrap();
assert_eq!(window.monthly_limit_block, None);
let pace: PaceSnapshot =
serde_json::from_value(serde_json::json!({ "stage": "on_track", "deltaPercent": 0.0 }))
.unwrap();
assert_eq!(pace.monthly_limit_block, None);
}
}
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/commands/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ mod reset_backfill_tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/powertoys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mod tests {
reserve_percent: None,
reserve_description: None,
reserve_eta_seconds: None,
monthly_limit_block: None,
reserve_will_last_to_reset: false,
}
}
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-tauri/src-tauri/src/tray_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ mod tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
},
primary_label: None,
secondary: secondary_percent.map(|pct| crate::commands::RateWindowSnapshot {
Expand All @@ -688,6 +689,7 @@ mod tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}),
secondary_label: None,
model_specific: None,
Expand All @@ -703,6 +705,7 @@ mod tests {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}),
tertiary_label: None,
extra_rate_windows: Vec::new(),
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop-tauri/src-tauri/src/tray_presentation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn fake_snapshot_with(
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
};

ProviderUsageSnapshot {
Expand Down Expand Up @@ -375,6 +376,7 @@ fn fake_extra_window(percent: f64) -> crate::commands::NamedRateWindowSnapshot {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
},
}
}
Expand Down Expand Up @@ -596,6 +598,7 @@ fn claude_automatic_prefers_weekly_when_model_exhausted() {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
});

let (primary, _) = selected_tray_percents(&snapshot, &settings);
Expand Down Expand Up @@ -639,6 +642,7 @@ fn automatic_picks_highest_among_model_and_extra_windows() {
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
});
snapshot.extra_rate_windows.push(fake_extra_window(90.0));

Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/usage_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ fn derived_window(used_percent: f64, resets_at: Option<String>) -> RateWindowSna
reserve_description: None,
reserve_will_last_to_reset: false,
reserve_eta_seconds: None,
monthly_limit_block: None,
}
}

Expand Down
Loading