diff --git a/bin/omarchy-agent-usage-agy b/bin/omarchy-agent-usage-agy index dc4b5c6e6741..c15226457f5c 100755 --- a/bin/omarchy-agent-usage-agy +++ b/bin/omarchy-agent-usage-agy @@ -374,13 +374,39 @@ def extract_model_limits(data): # The bearer token goes wherever CLOUD_CODE_URL points, so a destination # named there is taken only over https, and anything else is Google's own. +# Google answers only the quota groups the client asking may see: asked as a +# bare "antigravity" it leaves the Gemini group out, so a plan's own windows +# never appear and only the Claude and GPT allowance does. This names the CLI +# and its version, as agy does; Google answers a version below 1.2, or one +# without a patch level, the same way it answers no client at all. +CLIENT_USER_AGENT_FALLBACK = "1.5.18" +_client_user_agent = "" + + +def client_user_agent(): + global _client_user_agent + if not _client_user_agent: + version = CLIENT_USER_AGENT_FALLBACK + agy = shutil.which("agy") + if agy: + try: + printed = subprocess.run([agy, "--version"], stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=5).stdout + named = re.search(r"\d+\.\d+\.\d+", printed) + if named: + version = named.group(0) + except (OSError, subprocess.SubprocessError): + pass + _client_user_agent = f"antigravity/cli/{version} (aidev_client; auth_method=consumer)" + return _client_user_agent + + def post(endpoint, token, body=None): base = (os.environ.get("CLOUD_CODE_URL") or DEFAULT_CLOUD_CODE_URL).rstrip("/") if not base.startswith("https://"): base = DEFAULT_CLOUD_CODE_URL request = urllib.request.Request( f"{base}/v1internal:{endpoint}", data=json.dumps(body or {}).encode(), - headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json", "User-Agent": "antigravity"}, + headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json", "User-Agent": client_user_agent()}, ) return open_json(request, timeout=8) diff --git a/test/shell.d/agent-usage-agy-test.sh b/test/shell.d/agent-usage-agy-test.sh index e3e4503c9393..9e81163500aa 100755 --- a/test/shell.d/agent-usage-agy-test.sh +++ b/test/shell.d/agent-usage-agy-test.sh @@ -12,6 +12,8 @@ agent_sandbox python3 - <<'PY' from agent_usage_fixtures import * +import re +import shutil TIER = "v1internal:loadCodeAssist" SUMMARY = "v1internal:retrieveUserQuotaSummary" @@ -110,4 +112,35 @@ record, _ = agy({ expect("404 on retrieveUserQuota degrades cleanly to summary limits", [record["tierLabel"], record["limits"], record["usageStatusText"]], ["Ultra", [], ""], record) +# The client named in the User-Agent decides which groups Google answers with: +# a bare "antigravity" gets the Claude and GPT allowance alone, so the plan's +# own Gemini windows never appear. Name the CLI and the version it reports. +machine() +stub = home() / "bin" / "agy" +stub.write_text('#!/bin/bash\necho "1.5.20"\n') +stub.chmod(0o755) +record, http = agy({ + TIER: {"paidTier": {"id": "g1-pro-tier", "name": "Google AI Pro"}}, + SUMMARY: {"groups": [{"displayName": "Gemini Models", "buckets": [{"window": "5h", "remainingFraction": 0.9, "resetTime": reset_late}]}]}, +}) +expect("User-Agent names the Antigravity CLI and the version it reports", + [r["headers"].get("user-agent") for r in http.requests if r["url"].endswith(SUMMARY)], + ["antigravity/cli/1.5.20 (aidev_client; auth_method=consumer)"], http.requests) + +# Without the CLI to ask, the version is still a full one: Google answers no +# client at all, or one below 1.2, by hiding the Gemini group the same way. +machine() +real_which = shutil.which +shutil.which = lambda name, *args, **kwargs: None if name == "agy" else real_which(name, *args, **kwargs) +try: + record, http = agy({ + TIER: {"paidTier": {"id": "g1-pro-tier", "name": "Google AI Pro"}}, + SUMMARY: {"groups": [{"displayName": "Gemini Models", "buckets": [{"window": "5h", "remainingFraction": 0.9, "resetTime": reset_late}]}]}, + }) +finally: + shutil.which = real_which +expect("User-Agent names a full version with no CLI to ask", + [re.fullmatch(r"antigravity/cli/\d+\.\d+\.\d+ \(aidev_client; auth_method=consumer\)", r["headers"].get("user-agent") or "") is not None + for r in http.requests if r["url"].endswith(SUMMARY)], + [True], http.requests) PY