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.

fix(antigravity): resolve npm-global bundle without calling npm on Windows

Ruben Lütke0ee0e7f46f5c
diff --git a/jarvis/google_cli/resolver.py b/jarvis/google_cli/resolver.py
index 343cd7fa41..58e765e537 100644
--- a/jarvis/google_cli/resolver.py
+++ b/jarvis/google_cli/resolver.py
@@ -15,6 +15,7 @@ from __future__ import annotations
import os
import shutil
import subprocess
+import sys
from collections.abc import Callable
from dataclasses import dataclass, field
@@ -25,6 +26,9 @@ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS
_AGY: tuple[str, ...] = ("agy", "agy.exe")
_GEMINI: tuple[str, ...] = ("gemini", "gemini.cmd", "gemini.exe")
+# The bundle path inside any npm-global node_modules root.
+_BUNDLE_REL = os.path.join("@google", "gemini-cli", "bundle", "gemini.js")
+
@dataclass(frozen=True)
class GoogleCli:
@@ -35,27 +39,65 @@ class GoogleCli:
version: str | None = None
-def _default_npm_bundle() -> str | None:
+def _npm_global_roots() -> list[str]:
+ """Well-known npm-global ``node_modules`` roots, platform-aware (no subprocess).
+
+ On Windows the global root is ``%APPDATA%\\npm\\node_modules``; on POSIX it is
+ one of the standard prefixes. Probing these directly avoids calling ``npm``,
+ which on Windows is a ``.cmd`` shim that ``subprocess`` cannot launch without
+ a shell (it would raise ``FileNotFoundError`` and we'd find nothing).
+ """
+ roots: list[str] = []
+ if sys.platform == "win32":
+ appdata = os.environ.get("APPDATA")
+ if appdata:
+ roots.append(os.path.join(appdata, "npm", "node_modules"))
+ else:
+ home = os.path.expanduser("~")
+ roots += [
+ "/usr/local/lib/node_modules",
+ "/usr/lib/node_modules",
+ os.path.join(home, ".npm-global", "lib", "node_modules"),
+ ]
+ return roots
+
+
+def _default_npm_bundle(
+ *,
+ roots: list[str] | None = None,
+ which: Callable[[str], str | None] = shutil.which,
+ isfile: Callable[[str], bool] = os.path.isfile,
+) -> 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``.
+
+ Probes the well-known roots directly; additionally consults ``npm root -g``
+ only where ``npm`` resolves to a *real* executable (POSIX), never a Windows
+ ``.cmd``/``.ps1`` shim that ``subprocess`` cannot run without a shell.
"""
- 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
+ candidates = list(roots) if roots is not None else _npm_global_roots()
+ npm = which("npm")
+ if npm and not npm.lower().endswith((".cmd", ".ps1", ".bat")):
+ try:
+ out = subprocess.run(
+ [npm, "root", "-g"],
+ capture_output=True,
+ text=True,
+ timeout=5.0,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ ).stdout.strip()
+ if out:
+ candidates.append(out)
+ except (OSError, subprocess.SubprocessError):
+ pass
+ for root in candidates:
+ bundle = os.path.join(root, _BUNDLE_REL)
+ if isfile(bundle):
+ return bundle
+ return None
def resolve_google_cli(
diff --git a/tests/unit/google_cli/test_resolver.py b/tests/unit/google_cli/test_resolver.py
index 6e9cfe4b11..2f7f4e8c7b 100644
--- a/tests/unit/google_cli/test_resolver.py
+++ b/tests/unit/google_cli/test_resolver.py
@@ -39,3 +39,22 @@ def test_falls_back_to_npm_bundle(tmp_path):
def test_none_when_nothing_available():
assert resolve_google_cli(which=lambda name: None, npm_bundle=lambda: None) is None
+
+
+def test_default_npm_bundle_finds_known_root(tmp_path):
+ """The default bundle finder probes known npm-global roots WITHOUT calling
+ npm (on Windows ``npm`` is a .cmd that subprocess can't run directly)."""
+ from jarvis.google_cli.resolver import _default_npm_bundle
+
+ root = tmp_path / "node_modules"
+ bundle = root / "@google" / "gemini-cli" / "bundle" / "gemini.js"
+ bundle.parent.mkdir(parents=True)
+ bundle.write_text("// stub")
+ found = _default_npm_bundle(roots=[str(root)], which=lambda n: None)
+ assert found == str(bundle)
+
+
+def test_default_npm_bundle_none_when_absent(tmp_path):
+ from jarvis.google_cli.resolver import _default_npm_bundle
+
+ assert _default_npm_bundle(roots=[str(tmp_path)], which=lambda n: None) is None