The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(computer-use): normalize Windows manifest paths in WSL
motoblurr7bc995666040
diff --git a/tests/computer_use/test_cua_wsl_manifest_path.py b/tests/computer_use/test_cua_wsl_manifest_path.pynew file mode 100644index 00000000000..a3c5da472b6--- /dev/null+++ b/tests/computer_use/test_cua_wsl_manifest_path.py@@ -0,0 +1,45 @@+from __future__ import annotations++import json+from types import SimpleNamespace+from unittest.mock import patch++from tools.computer_use import cua_backend+++def test_wsl_windows_manifest_path_translates_to_drvfs():+ with patch("hermes_constants.is_wsl", return_value=True):+ assert cua_backend._wsl_windows_path_to_posix(+ r"C:\Users\Fernando\AppData\Local\cua-driver\cua-driver.exe"+ ) == "/mnt/c/Users/Fernando/AppData/Local/cua-driver/cua-driver.exe"+++def test_non_windows_path_is_unchanged_in_wsl():+ with patch("hermes_constants.is_wsl", return_value=True):+ assert cua_backend._wsl_windows_path_to_posix(+ "/usr/local/bin/cua-driver"+ ) == "/usr/local/bin/cua-driver"+++def test_windows_manifest_path_is_unchanged_outside_wsl():+ path = r"D:\Tools\cua-driver.exe"+ with patch("hermes_constants.is_wsl", return_value=False):+ assert cua_backend._wsl_windows_path_to_posix(path) == path+++def test_resolve_mcp_invocation_normalizes_windows_manifest_command_in_wsl():+ manifest = {+ "mcp_invocation": {+ "command": r"C:\Users\Fernando\AppData\Local\cua-driver\cua-driver.exe",+ "args": ["mcp"],+ }+ }+ proc = SimpleNamespace(returncode=0, stdout=json.dumps(manifest))+ with (+ patch.object(cua_backend.subprocess, "run", return_value=proc),+ patch("hermes_constants.is_wsl", return_value=True),+ ):+ command, args = cua_backend._resolve_mcp_invocation("cua-driver")++ assert command == "/mnt/c/Users/Fernando/AppData/Local/cua-driver/cua-driver.exe"+ assert args == ["mcp"]diff --git a/tools/computer_use/cua_backend.py b/tools/computer_use/cua_backend.pyindex b029071f4b5..868dbeaa522 100644--- a/tools/computer_use/cua_backend.py+++ b/tools/computer_use/cua_backend.py@@ -48,6 +48,7 @@ import subprocessimport sysimport threadingimport uuid+from pathlib import PureWindowsPathfrom typing import Any, Dict, List, Optional, Tuplefrom hermes_cli._subprocess_compat import windows_hide_flags@@ -351,6 +352,30 @@ def _select_capture_target(return windows[0]+def _wsl_windows_path_to_posix(path: str) -> str:+ """Translate a Windows absolute manifest command when Hermes runs in WSL.++ Windows cua-driver manifests can report ``C:\\Users\\...\\cua-driver.exe``+ even though the Hermes process uses POSIX subprocess spawning inside WSL.+ The same file is reachable through DrvFS as ``/mnt/c/Users/...``.+ Non-Windows paths and non-WSL hosts are returned unchanged.+ """+ if not re.match(r"^[A-Za-z]:[\\/]", path):+ return path+ try:+ from hermes_constants import is_wsl++ if not is_wsl():+ return path+ except Exception:+ return path+ win = PureWindowsPath(path)+ drive = (win.drive or "").rstrip(":").lower()+ if not drive:+ return path+ return os.path.join("/mnt", drive, *(str(part) for part in win.parts[1:]))++def _resolve_mcp_invocation(driver_cmd: str,*,@@ -410,6 +435,11 @@ def _resolve_mcp_invocation(# The driver knows the subcommand but didn't surface its own path.# Keep our resolved driver_cmd; the args are still authoritative.return driver_cmd, _mcp_args_with_overlay_flag(args, driver_cmd=driver_cmd)+ # A Windows-installed cua-driver can hand a WSL-hosted Hermes an absolute+ # ``C:\...`` command; translate it to its DrvFS ``/mnt/<drive>/...`` form+ # BEFORE the path-separator check (backslash is not a separator on POSIX,+ # so the raw Windows string would otherwise be discarded here).+ command = _wsl_windows_path_to_posix(command)if not _has_path_separator(command):# A manifest may legitimately retain the generic ``cua-driver`` name.# Under a GUI's thin PATH that would lose the resolved user-local path