Skip to content

Detect agy CLI in Antigravity provider on Windows (#282) - #333

Merged
Finesssee merged 2 commits into
mainfrom
fix/antigravity-agy-cli-detection-282
Aug 16, 2026
Merged

Finesssee merged 2 commits into
mainfrom
fix/antigravity-agy-cli-detection-282

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

The Antigravity provider on Windows never detected the agy.exe CLI, even when it was running and listening. detect_process_info() only matched processes named *language_server_windows* / language_server.exe (the desktop IDE's child) and required --csrf_token on the command line. agy.exe serves the same local language server in-process with no CSRF flag, so it could never match — and --source cli / oauth still logged "Fetching Antigravity usage via local probe".

This ports the upstream agy CLI source so quota renders when only the CLI is running.

Behavior changes

  • Process discovery now matches agy / agy.exe / antigravity-cli (PowerShell Get-CimInstance query and parse_process_info), reusing the existing listening_ports_for_pid() / find_api_port() plumbing unchanged.
  • Empty CSRF for CLI matches: when the matched process is the agy CLI, the quota request is sent without the X-Codeium-Csrf-Token header; the desktop IDE/app server keeps requiring it. This matches the reporter's evidence that agy's quota endpoint answers with no CSRF token.
  • --source cli now routes to the local probe with an accurate log line ("via CLI (agy) probe"); --source oauth is surfaced as UnsupportedSource instead of silently probing locally (no remote OAuth path is ported yet).
  • Desktop IDE detection preserved: language_server.exe / *language_server_windows* matching is unchanged, and IDE matches are preferred over the tokenless CLI when both are running, mirroring upstream's process-kind precedence.

How it works

  • New ProcessSource enum (Ide | Cli) on ProcessInfo records which kind of process was matched.
  • New is_agy_cli_command() classifies a command line as the agy CLI (bare agy, agy.exe, or antigravity-cli/antigravity_cli), with a leading path separator so unrelated names like notantigravity-cli don't match.
  • parse_process_info() returns the first IDE match (CSRF-protected) or, if none, the first CLI match (empty CSRF). The request builder conditionally attaches the CSRF header based on source.

Commands run

cargo fmt --all
cargo test --manifest-path rust/Cargo.toml            # 1218 lib + 1 main tests pass
cargo test --manifest-path rust/Cargo.toml -p codexbar --lib providers::antigravity  # 18/18 (8 new)
cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings           # clean

Tests added (8)

  • detects_agy_exe_cli_process_with_empty_csrf — agy.exe with no --csrf_token → source=Cli, empty token.
  • detects_bare_agy_command — bare agy name.
  • detects_antigravity_cli_command — antigravity-cli package name.
  • ide_match_preferred_over_agy_cli_when_both_running — IDE wins when both run.
  • agy_cli_matches_when_only_cli_running — CLI matches when it's the only match.
  • non_antigravity_process_without_csrf_is_not_matched — unrelated tokenless process rejected.
  • is_agy_cli_command_matches_known_names / is_agy_cli_command_rejects_unrelated_names.

Notes

  • Provider-specific logic stays inside rust/src/providers/antigravity/mod.rs — no cross-provider branching (per AGENTS.md).
  • Logging uses tracing; no secrets/tokens logged. The CSRF token value is only used to build the header, never logged.
  • The "launch agy on poll when no session is open" behavior mentioned in the issue is out of scope for this change (the existing ambient-probe model doesn't spawn processes); this PR covers detection + empty-CSRF + --source cli routing, which unblocks quota rendering when an agy session is already open.

Fixes #282

The Antigravity provider never matched the agy.exe CLI because
detect_process_info only matched language_server.exe / *language_server_windows*
and required --csrf_token on the command line. agy.exe hosts the same local
language server in-process with no CSRF flag, so it could never match and
--source cli fell through to the same local-probe log line.

- Match agy / agy.exe / antigravity-cli in process discovery (PowerShell query
  and parse_process_info), reusing the existing listening_ports_for_pid /
  find_api_port plumbing.
- Allow an empty CSRF token for CLI matches: send the quota request without
  the X-Codeium-Csrf-Token header when the matched process is the agy CLI,
  and keep requiring the header for the desktop IDE/app server.
- Make --source cli actually route to the local probe (it was already the
  only path, but now the log line reflects the CLI source); --source oauth
  is surfaced as UnsupportedSource instead of silently probing locally.
- Preserve desktop IDE detection (language_server.exe path unchanged); IDE
  matches are preferred over the tokenless CLI when both run, mirroring
  upstream process-kind precedence.
- Add unit tests for agy.exe process matching, empty CSRF behavior, IDE-vs-CLI
  precedence, and is_agy_cli_command accept/reject cases.

Fixes #282
…g, extract tests

Thermo-nuclear review fixes for PR #333:

1. Cache is_agy_cli_command regexes with LazyLock instead of recompiling
   on every call. Matches the canonical pattern in redactor.rs/curl_capture.rs
   and the project rs-lazylock rule.

2. Simplify fetch_usage SourceMode logging: the match-on-source-mode with a
   catch-all arm was redundant branching since auto and cli both resolve to
   the same local probe. Replaced with a single debug log.

3. Extract the test module to tests.rs, bringing mod.rs from 1033 to 758
   lines (under the 1k threshold). Matches the cost_pricing.rs #[path]
   pattern already used in the codebase.
@Finesssee
Finesssee merged commit 09cd9be into main Aug 16, 2026
1 check failed
@Finesssee
Finesssee deleted the fix/antigravity-agy-cli-detection-282 branch August 16, 2026 11:51
Finesssee pushed a commit that referenced this pull request Aug 24, 2026
Follow-up to #282 and #333. Windows CIM can return a quoted executable path, so the closing quote after agy.exe was rejected by the CLI process matcher. Keeps Antigravity language-server requests on 127.0.0.1 out of the app-wide outbound proxy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Antigravity provider never detects the agy CLI on Windows (upstream CLI source not ported)

1 participant