Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(antigravity): binary resolver (agy > gemini > npm bundle)

Ruben Lütke718ec1f12905
diff --git a/jarvis/google_cli/__init__.py b/jarvis/google_cli/__init__.py
new file mode 100644
index 0000000000..78b926343f
--- /dev/null
+++ b/jarvis/google_cli/__init__.py
@@ -0,0 +1,2 @@
+"""Drive the official Google agent CLI (Antigravity ``agy`` / Gemini CLI) over the
+user's Google subscription login. See ``resolver`` and ``auth_service``."""
diff --git a/jarvis/google_cli/resolver.py b/jarvis/google_cli/resolver.py
new file mode 100644
index 0000000000..343cd7fa41
--- /dev/null
+++ b/jarvis/google_cli/resolver.py
@@ -0,0 +1,80 @@
+"""Resolve which official Google agent CLI to drive, and how to invoke it.
+
+Order: Antigravity ``agy`` (the official successor, 2026-06) > the Gemini CLI on
+PATH > the npm-global Gemini bundle via ``node`` (covers a broken PATH shim).
+Returns ``None`` when no official binary is present — the caller then reports the
+provider as not installed.
+
+Cross-platform (CLOUD.md Rule #1): pure stdlib, capability-probed via
+``shutil.which``, never raises on a probe. Only the official binary is ever
+invoked — the stored OAuth token is never read to make our own HTTP request
+(Google ToS).
+"""
+from __future__ import annotations
+
+import os
+import shutil
+import subprocess
+from collections.abc import Callable
+from dataclasses import dataclass, field
+
+from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS
+
+# Binary name + platform shim variants. ``shutil.which`` honors PATHEXT, so the
+# bare name usually resolves; the explicit variants are belt-and-suspenders.
+_AGY: tuple[str, ...] = ("agy", "agy.exe")
+_GEMINI: tuple[str, ...] = ("gemini", "gemini.cmd", "gemini.exe")
+
+
+@dataclass(frozen=True)
+class GoogleCli:
+ """A resolved official Google CLI and the argv prefix used to invoke it."""
+
+ kind: str # "agy" | "gemini"
+ argv_prefix: list[str] = field(default_factory=list)
+ version: str | None = None
+
+
+def _default_npm_bundle() -> str | None:
+ """Path to the npm-global Gemini bundle, or ``None``. Best-effort, never raises.
+
+ Covers this machine's broken-shim case: ``@google/gemini-cli`` is installed
+ but its ``gemini``/``gemini.cmd`` PATH shims are stale npm temp files, so
+ ``shutil.which`` misses it. We can still drive ``node <bundle>/gemini.js``.
+ """
+ try:
+ root = subprocess.run(
+ ["npm", "root", "-g"],
+ capture_output=True,
+ text=True,
+ timeout=5.0,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ ).stdout.strip()
+ except (OSError, subprocess.SubprocessError):
+ return None
+ if not root:
+ return None
+ bundle = os.path.join(root, "@google", "gemini-cli", "bundle", "gemini.js")
+ return bundle if os.path.isfile(bundle) else None
+
+
+def resolve_google_cli(
+ *,
+ which: Callable[[str], str | None] = shutil.which,
+ npm_bundle: Callable[[], str | None] = _default_npm_bundle,
+) -> GoogleCli | None:
+ """Resolve the preferred official Google CLI. ``which``/``npm_bundle`` are
+ injectable seams for tests."""
+ for name in _AGY:
+ path = which(name)
+ if path:
+ return GoogleCli(kind="agy", argv_prefix=[path])
+ for name in _GEMINI:
+ path = which(name)
+ if path:
+ return GoogleCli(kind="gemini", argv_prefix=[path])
+ bundle = npm_bundle()
+ if bundle:
+ node = which("node") or "node"
+ return GoogleCli(kind="gemini", argv_prefix=[node, bundle])
+ return None
diff --git a/tests/unit/google_cli/__init__.py b/tests/unit/google_cli/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/unit/google_cli/test_resolver.py b/tests/unit/google_cli/test_resolver.py
new file mode 100644
index 0000000000..6e9cfe4b11
--- /dev/null
+++ b/tests/unit/google_cli/test_resolver.py
@@ -0,0 +1,41 @@
+"""Resolver order + fallback for the official Google agent CLI."""
+from __future__ import annotations
+
+from jarvis.google_cli.resolver import GoogleCli, resolve_google_cli
+
+
+def test_prefers_agy_when_on_path():
+ def which(name: str) -> str | None:
+ return f"/usr/bin/{name}" if name in ("agy", "agy.exe") else None
+
+ cli = resolve_google_cli(which=which, npm_bundle=lambda: None)
+ assert isinstance(cli, GoogleCli)
+ assert cli.kind == "agy"
+ assert cli.argv_prefix == ["/usr/bin/agy"]
+
+
+def test_falls_back_to_gemini_on_path():
+ def which(name: str) -> str | None:
+ return f"/usr/bin/{name}" if name in ("gemini", "gemini.cmd") else None
+
+ cli = resolve_google_cli(which=which, npm_bundle=lambda: None)
+ assert cli is not None
+ assert cli.kind == "gemini"
+ assert cli.argv_prefix == ["/usr/bin/gemini"]
+
+
+def test_falls_back_to_npm_bundle(tmp_path):
+ bundle = tmp_path / "gemini.js"
+ bundle.write_text("// stub")
+
+ def which(name: str) -> str | None:
+ return "/usr/bin/node" if name == "node" else None
+
+ cli = resolve_google_cli(which=which, npm_bundle=lambda: str(bundle))
+ assert cli is not None
+ assert cli.kind == "gemini"
+ assert cli.argv_prefix == ["/usr/bin/node", str(bundle)]
+
+
+def test_none_when_nothing_available():
+ assert resolve_google_cli(which=lambda name: None, npm_bundle=lambda: None) is None