Skip to content
Merged
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
83 changes: 74 additions & 9 deletions src/poller/antigravity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::HashMap;
use std::fs;
use std::hash::{Hash, Hasher};
use std::path::PathBuf;
use std::sync::Mutex;
use std::time::{Duration, SystemTime};

use serde::Deserialize;
Expand Down Expand Up @@ -142,22 +143,46 @@ where
}
}

fn installed_oauth_clients() -> Vec<(String, String)> {
static CACHED_OAUTH_CLIENTS: Mutex<Option<Vec<(String, String)>>> = Mutex::new(None);

fn oauth_client_candidate_paths(
home: Option<PathBuf>,
local: Option<PathBuf>,
program_files: Option<PathBuf>,
) -> Vec<PathBuf> {
let mut paths = Vec::new();
if let Some(local) = std::env::var_os("LOCALAPPDATA") {
let local = PathBuf::from(local);
if let Some(home) = home {
paths.push(home.join(".gemini/bin/agy.exe"));
}
if let Some(local) = local {
paths.push(local.join("Programs/Antigravity/resources/bin/language_server.exe"));
paths.push(local.join("Programs/Antigravity IDE/resources/bin/language_server.exe"));
paths.push(local.join("agy/bin/agy.exe"));
}
if let Some(program_files) = std::env::var_os("ProgramFiles") {
paths.push(
PathBuf::from(program_files).join("Antigravity/resources/bin/language_server.exe"),
);
if let Some(program_files) = program_files {
paths.push(program_files.join("Antigravity/resources/bin/language_server.exe"));
}
paths
}

fn installed_oauth_clients() -> Vec<(String, String)> {
if let Ok(guard) = CACHED_OAUTH_CLIENTS.lock() {
if let Some(cached) = guard.as_ref() {
return cached.clone();
}
}
for path in paths {
if let Ok(bytes) = fs::read(path) {
let home = crate::known_folders::home_dir()
.or_else(|| std::env::var_os("USERPROFILE").map(PathBuf::from));
let local = crate::known_folders::local_app_data_dir()
.or_else(|| std::env::var_os("LOCALAPPDATA").map(PathBuf::from));
let program_files = std::env::var_os("ProgramFiles").map(PathBuf::from);
for path in oauth_client_candidate_paths(home, local, program_files) {
if let Ok(bytes) = fs::read(&path) {
let clients = oauth_clients_from_binary(&bytes);
if !clients.is_empty() {
if let Ok(mut guard) = CACHED_OAUTH_CLIENTS.lock() {
*guard = Some(clients.clone());
}
return clients;
}
}
Expand Down Expand Up @@ -251,6 +276,10 @@ fn refresh_from_clients(
clients: Vec<(String, String)>,
mut exchange: impl FnMut(&str, &str) -> Result<String, PollError>,
) -> Result<String, PollError> {
if clients.is_empty() {
diagnose::log("Antigravity OAuth refresh failed: no installed OAuth client found");
return Err(PollError::AuthRequired);
}
for (client_id, client_secret) in clients {
match exchange(&client_id, &client_secret) {
// A rejected client pairing may not be the one that issued this token.
Expand Down Expand Up @@ -602,6 +631,9 @@ pub(super) fn antigravity_usage_from_summary(
let mut external_usage = None;
let mut has_named_pool = false;
let mut other_groups = Vec::new();
// Only a stand-in: when Google folds Argon into the main pool, the sole Gemini group can
// mention Argon, and skipping it would leave the Gemini pool empty.
let mut argon_usage = None;

// A summary that returns a group list (even an empty one) answered
// authoritatively: no recognised window means "no limit data", not a
Expand All @@ -615,6 +647,9 @@ pub(super) fn antigravity_usage_from_summary(
// Its presence also rules out assigning an unrelated sole group
// through the unnamed-pool fallback below.
has_named_pool = true;
if argon_usage.is_none() && has_generic_gemini_buckets(&group) {
argon_usage = antigravity_usage_from_summary_group(group);
}
continue;
}
let is_gemini = is_antigravity_gemini_summary_group(&group);
Expand Down Expand Up @@ -642,6 +677,10 @@ pub(super) fn antigravity_usage_from_summary(
gemini_usage = other_groups.pop();
}

if gemini_usage.is_none() {
gemini_usage = argon_usage;
}

let mut usage = if let Some(mut gemini) = gemini_usage {
if let Some(external) = external_usage {
gemini.external_pool = Some(Box::new(external));
Expand All @@ -662,6 +701,18 @@ pub(super) fn antigravity_usage_from_summary(
Some(usage)
}

// The merged pool's buckets are `gemini-5h` / `gemini-weekly`; a real Argon pool names Argon there.
fn has_generic_gemini_buckets(group: &AntigravityQuotaSummaryGroup) -> bool {
group.buckets.as_ref().is_some_and(|buckets| {
buckets.iter().any(|bucket| {
bucket.bucket_id.as_deref().is_some_and(|id| {
let id = id.to_ascii_lowercase();
id.starts_with("gemini-") && !id.contains("argon")
})
})
})
}

pub(super) fn is_antigravity_separate_gemini_group(group: &AntigravityQuotaSummaryGroup) -> bool {
let is_argon = |value: Option<&str>| {
value.is_some_and(|value| value.to_ascii_lowercase().contains("argon"))
Expand Down Expand Up @@ -1011,6 +1062,20 @@ mod auth_tests {
assert_eq!(oauth_clients_from_binary(&bytes).len(), 1);
}

#[test]
fn oauth_client_candidate_paths_include_user_gemini_agy_binary() {
let paths = oauth_client_candidate_paths(
Some(PathBuf::from(r"C:\Users\dev")),
Some(PathBuf::from(r"C:\Users\dev\AppData\Local")),
Some(PathBuf::from(r"C:\Program Files")),
);
assert!(paths.contains(&PathBuf::from(r"C:\Users\dev").join(".gemini/bin/agy.exe")));
assert!(paths.contains(
&PathBuf::from(r"C:\Users\dev\AppData\Local")
.join("Programs/Antigravity IDE/resources/bin/language_server.exe")
));
}

#[test]
fn existing_credential_json_remains_supported() {
let old: AntigravityAuthFile =
Expand Down
21 changes: 21 additions & 0 deletions src/poller/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,27 @@ fn antigravity_limits_skip_unusable_buckets_and_preserve_reported_windows() {
assert_eq!(usage.limits[1].usage.percentage, 100.0);
}

#[test]
fn antigravity_merged_gemini_pool_that_mentions_argon_still_shows() {
// Since late Nov 2026 Gemini is one pool ("Gemini Models", gemini-5h / gemini-weekly)
// whose text names Argon among its models. With no other Gemini group it is the pool.
let response: antigravity::AntigravityQuotaSummaryResponse = serde_json::from_str(
r#"{"groups":[
{"displayName":"Gemini Models","description":"Gemini 4 Argon, Gemini 4 Neon and Gemini 3.8 Flash","buckets":[
{"bucketId":"gemini-weekly","window":"weekly","remainingFraction":0.94},
{"bucketId":"gemini-5h","window":"5h","remainingFraction":0.76}]},
{"displayName":"Claude and GPT models","buckets":[
{"bucketId":"3p-weekly","window":"weekly","remainingFraction":1},
{"bucketId":"3p-5h","window":"5h","remainingFraction":1}]}
]}"#,
)
.unwrap();
let usage = antigravity::antigravity_usage_from_summary(response).expect("usage");
assert!((usage.session.percentage - 24.0).abs() < 0.001);
assert!((usage.weekly.percentage - 6.0).abs() < 0.001);
assert!(usage.external_pool.is_some());
}

// Provider contract. Every provider in `ProviderId::ALL` needs a redacted
// response in `src/poller/fixtures/<key>.json` that its own parser reads into
// usable data that survives a save and load of the usage cache, translated
Expand Down