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: bypass Windows cmd shim for Codex

Ruben Lütkedf07d7985491
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 1ef189715c..02f69fdbab 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -30,8 +30,10 @@ Platform notes: the PTY layer itself is already cross-platform behind
``jarvis.terminal.backend`` (ConPTY on Windows, ptyprocess on POSIX, a clearly
messaged no-op where no PTY exists). What this module adds per platform is
resolving the agent binary: npm installs it as a ``.cmd``/``.ps1`` shim on
-Windows, which ConPTY cannot execute directly, so it is wrapped in a
-one-shot ``cmd /c`` (one-shot, so rule 1 above still holds).
+Windows. Codex is launched through absolute ``node.exe`` + ``codex.js`` paths
+there: ``cmd.exe`` drops inherited environment variables longer than 8,191
+characters, so an npm batch shim cannot find Node when the app has a large
+PATH. Other batch shims use a one-shot ``cmd /c`` (so rule 1 above still holds).
"""
from __future__ import annotations
@@ -166,6 +168,20 @@ def agent_argv(agent: str) -> tuple[str, ...] | None:
if sys.platform == "win32":
lowered = exe.lower()
if lowered.endswith((".cmd", ".bat")):
+ if agent == "codex":
+ from jarvis.core.path_augment import resolve_node_executable
+
+ node = resolve_node_executable()
+ codex_js = (
+ Path(exe).resolve().parent
+ / "node_modules"
+ / "@openai"
+ / "codex"
+ / "bin"
+ / "codex.js"
+ )
+ if node and codex_js.is_file():
+ return (node, str(codex_js))
# ConPTY cannot exec a batch shim. `cmd /c` (never /k) exits with
# the agent, so no shell survives it.
comspec = os.environ.get("COMSPEC") or "cmd.exe"
diff --git a/jarvis/core/path_augment.py b/jarvis/core/path_augment.py
index cb55d37430..ce289f742b 100644
--- a/jarvis/core/path_augment.py
+++ b/jarvis/core/path_augment.py
@@ -24,6 +24,7 @@ from __future__ import annotations
import glob
import logging
import os
+import shutil
import sys
from pathlib import Path
@@ -68,8 +69,25 @@ def _posix_candidates() -> list[str]:
def _windows_candidates() -> list[str]:
home = Path.home()
dirs: list[str] = []
+ node_dirs: set[str] = set()
+ for var in ("ProgramFiles", "ProgramW6432", "ProgramFiles(x86)"):
+ program_files = os.environ.get(var)
+ if not program_files:
+ continue
+ # The official Node.js Windows installer writes this directory to the
+ # machine PATH. A running desktop process keeps its old PATH, though,
+ # so a freshly installed npm Codex shim is found while its `node.exe`
+ # runtime is not. ProgramW6432 keeps the 64-bit install visible even
+ # when Jarvis itself runs as a 32-bit process.
+ candidate = os.path.join(program_files, "nodejs")
+ key = os.path.normcase(os.path.normpath(candidate))
+ if key not in node_dirs:
+ node_dirs.add(key)
+ dirs.append(candidate)
local = os.environ.get("LOCALAPPDATA")
if local:
+ # User-scoped Node installers commonly use this UAC-free location.
+ dirs.append(os.path.join(local, "Programs", "nodejs"))
# The official Antigravity PowerShell/CMD installer uses this directory.
dirs.append(os.path.join(local, "agy", "bin"))
# winget's shim dir lands on the *registry* PATH only — a running
@@ -125,4 +143,21 @@ def ensure_cli_paths() -> list[str]:
return added
-__all__ = ["candidate_dirs", "ensure_cli_paths"]
+def resolve_node_executable() -> str | None:
+ """Return an absolute Node.js executable, including stale-GUI-PATH hosts."""
+ ensure_cli_paths()
+ found = shutil.which("node") or shutil.which("node.exe")
+ if found:
+ return found
+ if sys.platform == "win32":
+ for directory in _windows_candidates():
+ candidate = Path(directory) / "node.exe"
+ try:
+ if candidate.is_file():
+ return str(candidate)
+ except OSError:
+ continue
+ return None
+
+
+__all__ = ["candidate_dirs", "ensure_cli_paths", "resolve_node_executable"]
diff --git a/tests/unit/agentic_ide/test_session.py b/tests/unit/agentic_ide/test_session.py
index 9f13e64c93..ba812ee55a 100644
--- a/tests/unit/agentic_ide/test_session.py
+++ b/tests/unit/agentic_ide/test_session.py
@@ -7,6 +7,8 @@ could interrupt, kill, or drive the keyboard shortcuts of a coding agent.
"""
from __future__ import annotations
+import os
+import sys
from pathlib import Path
import pytest
@@ -54,6 +56,39 @@ def test_prompt_is_length_capped() -> None:
assert len(sanitize_prompt("x" * 10_000)) == session_mod.MAX_PROMPT_CHARS
[email protected](sys.platform != "win32", reason="Windows npm shim regression")
+def test_codex_npm_shim_is_bypassed_with_absolute_node(tmp_path, monkeypatch) -> None:
+ """An overlong PATH launches npm Codex without the cmd.exe shim."""
+ npm_dir = tmp_path / "npm"
+ node_dir = tmp_path / "Program Files" / "nodejs"
+ npm_dir.mkdir()
+ node_dir.mkdir(parents=True)
+ codex_shim = npm_dir / "codex.cmd"
+ node_exe = node_dir / "node.exe"
+ codex_js = npm_dir / "node_modules" / "@openai" / "codex" / "bin" / "codex.js"
+ codex_js.parent.mkdir(parents=True)
+ codex_shim.write_text("@echo off\r\nnode --version\r\n", encoding="utf-8")
+ node_exe.write_bytes(b"MZ")
+ codex_js.write_text("#!/usr/bin/env node\n", encoding="utf-8")
+
+ oversized_path = os.pathsep.join(
+ [rf"C:\missing\{index:04d}" for index in range(600)] + [str(npm_dir)]
+ )
+ assert len(oversized_path) > 8191
+ monkeypatch.setenv("PATH", oversized_path)
+ monkeypatch.setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD")
+ monkeypatch.setenv("ProgramFiles", str(tmp_path / "Program Files"))
+ monkeypatch.delenv("ProgramW6432", raising=False)
+ monkeypatch.delenv("ProgramFiles(x86)", raising=False)
+
+ argv = session_mod.agent_argv("codex")
+
+ assert tuple(os.path.normcase(part) for part in argv) == tuple(
+ os.path.normcase(str(path)) for path in (node_exe, codex_js)
+ )
+ assert not any(part.lower().endswith((".cmd", ".bat")) for part in argv)
+
+
# ----------------------------------------------------------------- lifecycle
async def test_start_creates_named_terminals(registry: Registry, tmp_path: Path) -> None:
session = await _open(
diff --git a/tests/unit/core/test_path_augment.py b/tests/unit/core/test_path_augment.py
index 55cb6ca6bb..f7067d4445 100644
--- a/tests/unit/core/test_path_augment.py
+++ b/tests/unit/core/test_path_augment.py
@@ -65,6 +65,7 @@ def test_candidates_are_platform_appropriate():
if sys.platform == "win32":
assert any("WinGet" in d for d in dirs)
assert any(d.endswith("npm") for d in dirs)
+ assert any(d.endswith("nodejs") for d in dirs)
# Claude Code's native installer (install.ps1 -> ~/.local/bin) and the
# `claude install` migration dir (~/.claude/local) — a working terminal
# `claude` was reported "not installed" without them (2026-07-18
@@ -88,6 +89,60 @@ def test_windows_candidates_cover_official_antigravity_installer(
assert str(local / "agy" / "bin") in dirs
+def test_windows_candidates_refresh_node_installer_paths(tmp_path, monkeypatch):
+ """A GUI already running during Node installation must find the runtime.
+
+ npm puts the Codex shim in APPDATA, but that shim still invokes node.exe.
+ The official machine-wide and user-scoped Node install locations therefore
+ both belong in the refreshed GUI PATH.
+ """
+ program_files = tmp_path / "Program Files"
+ local = tmp_path / "LocalAppData"
+ monkeypatch.setenv("ProgramFiles", str(program_files))
+ monkeypatch.setenv("LOCALAPPDATA", str(local))
+
+ dirs = path_augment._windows_candidates()
+
+ assert str(program_files / "nodejs") in dirs
+ assert str(local / "Programs" / "nodejs") in dirs
+
+
+def test_windows_candidates_keep_64_bit_node_visible_to_32_bit_process(
+ tmp_path, monkeypatch
+):
+ program_files_x86 = tmp_path / "Program Files (x86)"
+ program_files_64 = tmp_path / "Program Files"
+ monkeypatch.setenv("ProgramFiles", str(program_files_x86))
+ monkeypatch.setenv("ProgramFiles(x86)", str(program_files_x86))
+ monkeypatch.setenv("ProgramW6432", str(program_files_64))
+
+ dirs = path_augment._windows_candidates()
+
+ assert str(program_files_64 / "nodejs") in dirs
+ assert dirs.count(str(program_files_x86 / "nodejs")) == 1
+
+
+def test_resolve_node_executable_finds_well_known_windows_install(
+ tmp_path, monkeypatch
+):
+ program_files = tmp_path / "Program Files"
+ node_exe = program_files / "nodejs" / "node.exe"
+ node_exe.parent.mkdir(parents=True)
+ node_exe.write_bytes(b"MZ")
+
+ monkeypatch.setattr(path_augment.sys, "platform", "win32")
+ monkeypatch.setenv("PATH", "")
+ monkeypatch.setenv("ProgramFiles", str(program_files))
+ monkeypatch.delenv("ProgramW6432", raising=False)
+ monkeypatch.delenv("ProgramFiles(x86)", raising=False)
+ monkeypatch.delenv("LOCALAPPDATA", raising=False)
+ monkeypatch.delenv("APPDATA", raising=False)
+
+ assert os.path.normcase(path_augment.resolve_node_executable() or "") == (
+ os.path.normcase(str(node_exe))
+ )
+
+
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX candidate shape")
def test_posix_candidates_cover_the_mac_report(monkeypatch):
"""The 2026-07-18 Mac symptom: claude installed via npm/native installer,