Skip to content
Closed
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
28 changes: 27 additions & 1 deletion bin/omarchy-agent-usage-agy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +395 to +396

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Older installs miss Gemini windows

If the installed agy reports a version below 1.2.0, client_user_agent() replaces the working fallback with that version. Google then omits Gemini windows, as the new comment explains. Omarchy supports user-managed CLI installs without requiring a minimum version, so the fix remains incomplete for those users.

Keep the fallback when the reported version is below 1.2.0, and cover that case in the test.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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)

Expand Down
33 changes: 33 additions & 0 deletions test/shell.d/agent-usage-agy-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ agent_sandbox

python3 - <<'PY'
from agent_usage_fixtures import *
import re
import shutil

TIER = "v1internal:loadCodeAssist"
SUMMARY = "v1internal:retrieveUserQuotaSummary"
Expand Down Expand Up @@ -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