diff --git a/tools/computer_use/cua_backend.py b/tools/computer_use/cua_backend.py index 60c998c87d09..63f1e148f5ba 100644 --- a/tools/computer_use/cua_backend.py +++ b/tools/computer_use/cua_backend.py @@ -1,18 +1,35 @@ -"""Cua-driver backend (macOS only). +"""Cua-driver backend (macOS + Windows). Speaks MCP over stdio to `cua-driver`. The Python `mcp` SDK is async, so we run a dedicated asyncio event loop on a background thread and marshal sync calls through it. -Install: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"` +The same `cua-driver call ` surface (click, type_text, hotkey, drag, +scroll, screenshot, launch_app, list_apps, list_windows, get_window_state, +move_cursor, wait) works identically across macOS + Windows — cua-driver's +PARITY matrix marks every action tool VERIFIED on Windows in the +cross-platform Rust port (`cua-driver-rs`). + +Linux support exists in cua-driver-rs but is alpha today — Linux PARITY +rows are mostly OPEN, not VERIFIED — so it's gated off in +`check_computer_use_requirements` until that flips upstream. The plumbing +in this file is OS-agnostic, so flipping that gate later is one-line. + +Install: + - **macOS**: + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)" + - **Windows** (PowerShell): + irm https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.ps1 | iex After install, `cua-driver` is on $PATH and supports `cua-driver mcp` (stdio transport) which is what we invoke. -The private SkyLight SPIs cua-driver uses (SLEventPostToPid, SLPSPostEvent- -RecordTo, _AXObserverAddNotificationAndCheckRemote) are not Apple-public and -can break on OS updates. Pin the installed version via `HERMES_CUA_DRIVER_ -VERSION` if you want reproducibility across an OS bump. +The macOS path uses private SkyLight SPIs (SLEventPostToPid, +SLPSPostEventRecordTo, _AXObserverAddNotificationAndCheckRemote) that aren't +Apple-public and can break on OS updates. The Windows path in cua-driver-rs +uses stable Win32 APIs (SendInput + UI Automation) — not subject to the +same SPI breakage class. Pin the installed version via +HERMES_CUA_DRIVER_VERSION if you want reproducibility across an OS bump. """ from __future__ import annotations @@ -84,12 +101,22 @@ def cua_driver_binary_available() -> bool: def cua_driver_install_hint() -> str: + if sys.platform == "win32": + installer = ( + ' irm https://raw.githubusercontent.com/trycua/cua/main/' + 'libs/cua-driver/scripts/install.ps1 | iex' + ) + else: + installer = ( + ' /bin/bash -c "$(curl -fsSL ' + 'https://raw.githubusercontent.com/trycua/cua/main/' + 'libs/cua-driver/scripts/install.sh)"' + ) return ( "cua-driver is not installed. Install with one of:\n" " hermes computer-use install\n" "Or run the upstream installer directly:\n" - ' /bin/bash -c "$(curl -fsSL ' - 'https://raw.githubusercontent.com/trycua/cua/main/libs/cua-driver/scripts/install.sh)"\n' + f"{installer}\n" "Or run `hermes tools` and enable the Computer Use toolset to install it automatically." ) @@ -396,7 +423,7 @@ def _extract_tool_result(mcp_result: Any) -> Dict[str, Any]: # --------------------------------------------------------------------------- class CuaDriverBackend(ComputerUseBackend): - """Default computer-use backend. macOS-only via cua-driver MCP.""" + """Default computer-use backend. Cross-platform via cua-driver MCP (macOS + Windows).""" def __init__(self) -> None: self._bridge = _AsyncBridge() @@ -417,7 +444,10 @@ class CuaDriverBackend(ComputerUseBackend): self._bridge.stop() def is_available(self) -> bool: - if not _is_macos(): + # cua-driver itself is cross-platform; we constrain Hermes to + # macOS + Windows because cua-driver-rs Linux is alpha (most rows + # in its PARITY matrix are OPEN). Flip when Linux goes VERIFIED. + if sys.platform not in ("darwin", "win32"): return False return cua_driver_binary_available() diff --git a/tools/computer_use/tool.py b/tools/computer_use/tool.py index dd6b86edb198..fd9e1ce8ddb4 100644 --- a/tools/computer_use/tool.py +++ b/tools/computer_use/tool.py @@ -1,9 +1,12 @@ """Entry point for the `computer_use` tool. -Universal (any-model) macOS desktop control via cua-driver's background -computer-use primitive. Replaces #4562's Anthropic-native `computer_20251124` -approach — the schema here is standard OpenAI function-calling so every -tool-capable model can drive it. +Universal (any-model) desktop control across macOS + Windows via +cua-driver's background computer-use primitive. Replaces #4562's +Anthropic-native `computer_20251124` approach — the schema here is standard +OpenAI function-calling so every tool-capable model can drive it. + +Linux support exists in cua-driver-rs (alpha — PARITY rows are mostly +OPEN today, not VERIFIED) and is gated off here until it flips upstream. Return contract --------------- @@ -693,7 +696,7 @@ def _route_capture_through_aux_vision( temp_image_path.write_bytes(raw) prompt = ( - "Describe what is visible in this macOS application screenshot in " + "Describe what is visible in this desktop application screenshot in " "concise but specific terms. Mention the app name and window " "title if visible, the overall layout, any labelled buttons, " "menus or text fields, and any prominent text content the user " @@ -810,9 +813,13 @@ def _element_to_dict(e: UIElement) -> Dict[str, Any]: def check_computer_use_requirements() -> bool: """Return True iff computer_use can run on this host. - Conditions: macOS + cua-driver binary installed (or override via env). + Conditions: macOS or Windows + cua-driver binary installed (or override + via env). cua-driver-rs (the cross-platform Rust port) has every action + tool marked VERIFIED on Windows in its PARITY matrix. Linux is alpha + today — Linux rows in PARITY are mostly OPEN — so it's gated off until + that flips to VERIFIED upstream. """ - if sys.platform != "darwin": + if sys.platform not in ("darwin", "win32"): return False from tools.computer_use.cua_backend import cua_driver_binary_available return cua_driver_binary_available() diff --git a/tools/computer_use_tool.py b/tools/computer_use_tool.py index 16b0197a4a4b..b3b2f2f06b36 100644 --- a/tools/computer_use_tool.py +++ b/tools/computer_use_tool.py @@ -24,7 +24,7 @@ registry.register( check_fn=check_computer_use_requirements, requires_env=[], description=( - "Universal macOS desktop control via cua-driver. Works with any " + "Universal desktop control via cua-driver (macOS, Windows; Linux alpha). Works with any " "tool-capable model (Anthropic, OpenAI, OpenRouter, local vLLM, " "etc.). Background computer-use: does NOT steal the user's cursor " "or keyboard focus."