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(codex): prefer npm shim over Store alias

Ruben Lütkef1e92fd31536
diff --git a/jarvis/codex_auth.py b/jarvis/codex_auth.py
index d6e2a80852..603ccf405c 100644
--- a/jarvis/codex_auth.py
+++ b/jarvis/codex_auth.py
@@ -46,9 +46,9 @@ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS
log = logging.getLogger(__name__)
-# A binary name with a Windows shim variant. ``shutil.which`` honors PATHEXT, so
-# the bare "codex" usually resolves, but the explicit variants are belt-and-
-# suspenders for installs where only ``codex.cmd`` is on PATH.
+# Windows exposes Store app aliases as bare ``codex.exe`` entries. The official
+# npm shim is ``codex.cmd``, so it must win when a generic ``codex`` selection
+# could resolve to either installation. Explicit absolute paths still win.
_BINARY_CANDIDATES: tuple[str, ...] = ("codex", "codex.cmd", "codex.exe")
# Process-lifetime cache of ``codex --version`` keyed by resolved binary path.
@@ -473,10 +473,22 @@ class CodexAuthService:
except Exception: # noqa: BLE001 — a probe helper must never break status
log.debug("Codex CLI path augmentation failed", exc_info=True)
- candidates = (self._binary_path, *_BINARY_CANDIDATES)
+ generic_candidates = (
+ ("codex.cmd", "codex", "codex.exe")
+ if sys.platform == "win32"
+ else _BINARY_CANDIDATES
+ )
+ candidates = (
+ generic_candidates
+ if self._binary_path == "codex"
+ else (self._binary_path, *generic_candidates)
+ )
+ seen: set[str] = set()
for name in candidates:
- if not name:
+ normalized = os.path.normcase(str(name or "").strip())
+ if not normalized or normalized in seen:
continue
+ seen.add(normalized)
resolved = shutil.which(name)
if resolved:
return resolved
diff --git a/tests/unit/test_codex_auth.py b/tests/unit/test_codex_auth.py
index 740ce4328d..94e78ce181 100644
--- a/tests/unit/test_codex_auth.py
+++ b/tests/unit/test_codex_auth.py
@@ -20,6 +20,7 @@ from pathlib import Path
import pytest
+import jarvis.codex_auth as codex_auth_module
from jarvis.codex_auth import CodexAuthService, CodexAuthStatus, _derive_auth
@@ -86,6 +87,26 @@ def test_status_to_dict_contains_frontend_contract_fields() -> None:
# ----------------------------------------------------------------------
+def test_windows_generic_binary_prefers_the_official_npm_shim(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ calls: list[str] = []
+
+ def which(name: str) -> str | None:
+ calls.append(name)
+ return {
+ "codex.cmd": r"C:\npm\codex.cmd",
+ "codex": r"C:\WindowsApps\codex.exe",
+ }.get(name)
+
+ monkeypatch.setattr(codex_auth_module.sys, "platform", "win32")
+ monkeypatch.setattr(codex_auth_module.shutil, "which", which)
+ monkeypatch.setattr("jarvis.core.path_augment.ensure_cli_paths", lambda: [])
+
+ assert CodexAuthService()._resolve_binary() == r"C:\npm\codex.cmd"
+ assert calls == ["codex.cmd"]
+
+
def test_status_not_installed_when_binary_missing(monkeypatch: pytest.MonkeyPatch) -> None:
svc = CodexAuthService()
monkeypatch.setattr(svc, "_resolve_binary", lambda: None)