# arc-cua This repository ships two separate tools in one package: | | **arc-driver** | **arc-cua** | |---|---|---| | What it is | A macOS driver for computer-use agents: your agent reads an app's window and acts on it, in the background | A decision-model action loop: hand off a bounded subtask, a fast decision model clicks through it | | Who decides each action | Your agent (Claude Code, Codex, any MCP client, or your own code) | A decision model (JEV, or your own provider) | | Needs a model or API key | No | Yes | | Use it via | `arc-cua mcp`, or `arc_cua.Driver` in Python | `execute_payload`, `DesktopExecutor`, or `arc-cua run` | | Docs | **[docs/driver.md](https://github.com/shhivv/arc-cua/blob/master/docs/driver.md)** | [this README, from here down](#arc-cua-the-decision-model-loop) | **If you came for the driver, you need nothing below this section.** arc-driver does not use decision models, JEV or TypeSafe; it is a standalone driver. --- ## arc-driver: the macOS driver arc-driver reads an app's window, runs its menu commands and acts on its controls in the background, so the user's pointer, front app and windows stay as they are. It checks each action against the app as it is when the action runs, waits for the app to finish reacting, and works in minimized windows and hidden apps. ```bash claude mcp add arc-cua -- uvx --from 'arc-cua[macos]' arc-cua mcp # as MCP tools in Claude Code ``` ```python from arc_cua import Driver from arc_cua.backends import MacOSApp pid = MacOSApp.from_bundle_id("com.apple.calculator").pid with Driver() as driver: snapshot = driver.observe(pid) seven = next(e for e in snapshot.elements if e.name == "7") driver.act(snapshot, "CLICK", seven.id, settle=True) ``` Setup for Codex and other clients, the MCP tools, and measurements: **[docs/driver.md](https://github.com/shhivv/arc-cua/blob/master/docs/driver.md)**. Benchmarks: [benchmarks/README.md](https://github.com/shhivv/arc-cua/blob/master/benchmarks/README.md). --- # arc-cua: the decision-model loop **Superfast action layer for computer-use agents, powered by decision models.** Everything from here down is about arc-cua, not the driver. `arc-cua` lets a planner or CUA agent hand off bounded desktop subtasks to a fast decision model that executes the UI loop — no frontier model needed for every click. ```python from arc_cua import execute_payload result = execute_payload(executor, { "goal": "Play Get Lucky by Daft Punk in Spotify", "inputs": {"search_query": "Get Lucky Daft Punk"}, "verification": ["Spotify shows Get Lucky as the current track"], "constraints": ["Do not modify the user's library"], "max_actions": 15, }) # result: {"status": "SUBTASK_COMPLETE", "actions_taken": 4} ``` Any GPT, Claude, Gemini, local model, or deterministic planner can generate that payload. The planner deliberately lives outside the package. --- ## Why Computer-use agents should not need a frontier model to reason about every individual click. A typical CUA loop: ```text observe → large model → click → observe → large model → type → observe → large model → click ``` `arc-cua` separates high-level reasoning from low-level execution: ```text planner / LLM ↓ bounded subtask ↓ arc-cua ↓ JEV → action → action → action → action ↓ return to planner ``` The optimization target is **fewer expensive reasoning calls per completed task**, not fewer UI actions. --- ## How it works ```text any planner / CUA | | Subtask(goal, inputs, verification, constraints) v +-----------------------+ | arc-cua | | | | observe desktop | | AX + local OCR | | v | | build legal | | action space | | v | | JEV decision |<------+ | v | | | freshness guard | | | v | | | execute UI | | | v | | | wait for UI settle |-------+ +-----------+-----------+ | v SUBTASK_COMPLETE / BLOCKED / NEEDS_AGENT / NEEDS_INPUT | v planner ``` ### JEV JEV is the decision backend that powers the action loop. Given structured desktop state (elements, roles, values), it selects the next UI operation from a dynamically built action space — it can only pick targets and operations the current desktop actually exposes. JEV is accessed through [TypeSafe](https://typesafe.com). One JEV call can resolve the operation and its parameters in parallel. ### Other decision models The loop is not tied to JEV. `ChoicePolicy` builds the finite-choice questions and validates the answers; a `ChoiceTransport` sends them to a decision model. `TypeSafeJevPolicy` is `ChoicePolicy` with the TypeSafe transport. Any provider that answers typed choice questions with a choice, confidence and probabilities can be plugged in: ```python from arc_cua.policies import ChoicePolicy class MyTransport: name = "MyProvider" def ask(self, state, questions, *, images=()): ... # return {"answers": {name: {"choice", "confidence", "probabilities"}}} policy = ChoicePolicy(MyTransport()) ``` An answer that fails validation, such as a choice outside the offered options, executes nothing. `ChoicePolicy` asks the same questions again (`invalid_retries`, default 1), then raises `InvalidChoiceResponse` naming the question. See [the extension guide](https://github.com/shhivv/arc-cua/blob/master/site/llms-full.txt) for the request and answer shapes. **OpenAI Decisions.** `OpenAIDecisionsTransport` sends the same questions to OpenAI's [Decisions API](https://developers.openai.com/api/docs/guides/decisions) (`gpt-6-luna`). It reads `OPENAI_API_KEY` and accepts screenshots, so `screenshot_checks=True` and `screenshot_steps=True` work with it: ```python from arc_cua.policies import ChoicePolicy, OpenAIDecisionsTransport policy = ChoicePolicy(OpenAIDecisionsTransport()) ``` A refused question executes nothing when the decision needs it, and is ignored otherwise. ### The agent owns intent The upstream agent decides what needs to happen, what literal text may be used, what must not happen, and what counts as success. JEV chooses which element to target and which operation to perform — but never invents arbitrary text. Literal values always originate from the agent via `inputs`. When a field needs a value that none of the `inputs` provides, the run stops with `NEEDS_INPUT` instead of typing something else. The result's `needs_input` describes the field (`element_id`, `role`, `name`, current `value`, and a dropdown's `options`), so the agent can add the value to `inputs` and run the subtask again. Text fields are offered even when no inputs are supplied, only so the model can ask this way. ### Caller-supplied shortcuts Supply extra keyboard shortcuts for an individual subtask, with descriptions that tell JEV what they do: ```python from arc_cua import Subtask task = Subtask( goal="Save the current document", verification=("The document has no unsaved changes",), shortcuts={"MOD+S": "Save the current document in this editor"}, ) ``` The same `shortcuts` map is accepted by `execute_payload`. JEV receives these choices alongside the existing default hotkeys and chooses a chord when it selects `HOTKEY`. A supplied description can also clarify a default shortcut's meaning in the current app. The defaults are unchanged, and supplied shortcuts apply only to that subtask. ```python result = execute_payload(executor, { "goal": "Save the current document", "verification": ["The document has no unsaved changes"], "shortcuts": {"MOD+S": "Save the current document in this editor"}, }) ``` Chords use uppercase key names and one or more `MOD`, `CTRL`, `ALT`, or `SHIFT` modifiers, for example `MOD+S`, `CTRL+ALT+7`, or `SHIFT+F12`. `MOD` means Command on macOS. Supported keys include A-Z, 0-9, F1-F20, navigation keys, and named punctuation keys; see [the keyboard vocabulary](https://github.com/shhivv/arc-cua/blob/master/src/arc_cua/keyboard.py). The macOS backend uses US/ANSI physical key positions. Each shortcut is one chord, not a sequence of actions. Malformed declarations fail when the subtask is created. JEV can choose only offered chords; runtime validation also rejects hotkeys outside the defaults and the current subtask's declarations, including decisions from custom policies. ### JSON field types The JSON API validates the same contract as `Subtask` before calling the policy: | Field | JSON type | |---|---| | `goal` | Non-empty string (required) | | `verification` | Non-empty array of non-empty strings (required) | | `constraints` | Array of non-empty strings; defaults to `[]` | | `inputs` | Object mapping non-empty names to literal strings, finite numbers, or booleans | | `max_actions` | Integer at least 1; defaults to 30 | | `shortcuts` | Object mapping uppercase chords to non-empty descriptions | | `metadata` | Object; defaults to `{}` | | `allowed_risks` | Array of `"delete"`, `"send"`, `"purchase"`, `"close"`; defaults to `[]` | | `secret_inputs` | Array of `inputs` keys whose values the model never sees; defaults to `[]` | For example, use `"verification": ["The folder exists"]`, even for one criterion. A bare string is rejected rather than split into characters. The Python API accepts lists or tuples for criteria and constraints, and copies them into tuples. Input literals are copied into an immutable mapping. Invalid values raise a field-specific `ValueError`; values are not silently converted from strings to numbers or arrays. Supply each folder name, filename, or path to be typed as a literal in `inputs`. Text mentioned only in `goal` cannot be invented as an input by JEV. Use `MOD+SHIFT+N`, not `Command+Shift+N`; an unmodified Return is the built-in `PRESS_KEY` value `ENTER`, not an extra hotkey. ### Risky controls and secrets Controls whose label reads like a consequential action are not offered to the decision model unless the subtask allows that category in `allowed_risks`: | Category | Label words (whole words, any case) | |---|---| | `delete` | delete, remove, erase, trash, discard, clear all, empty trash, permanently | | `send` | send, post, publish, share, reply all, forward, tweet | | `purchase` | buy, purchase, pay, checkout, check out, place order, order now, subscribe, donate, confirm payment | | `close` | close, quit, exit, sign out, log out, logout, shut down, restart, uninstall | This applies to `CLICK` and `DOUBLE_CLICK`. The runtime also refuses such a click from any policy and returns `NEEDS_AGENT` with the reason, without acting. Values named in `secret_inputs` are replaced by `[secret]` everywhere the decision model reads them: the subtask, the input choices, observed element text, and the action history. The runtime still enters the real value. `result_to_dict`, the `arc-cua run` output and the runtime's error log are redacted the same way. Screenshots sent with `screenshot_checks` or `screenshot_steps` are not redacted. ```python Subtask( goal="Sign in to the account", inputs={"email": "sam@example.com", "password": "..."}, secret_inputs=("password",), verification=("The account page is shown",), ) ``` ### Hybrid macOS perception `arc-cua` combines two local perception sources: - **Accessibility (AX)** — semantic controls: buttons, fields, menus, roles, values, native actions - **Apple Vision OCR** — visible screen text with bounding boxes, for apps with incomplete accessibility Both normalize into `DesktopElement`s that JEV reasons over. `MacOSHybridBackend` runs OCR only when needed (`ocr="auto"`, the default): when accessibility exposes no enabled, labelled control of the app itself (title-bar buttons, the window and unlabelled groups do not count), as in Spotify, it adds OCR text; otherwise it takes no screenshot and settles on accessibility notifications. OCR uses Apple Vision's accurate level by default (`ocr_recognition_level="accurate"`); in Spotify it read "Sneaky Snitch" where the fast level read "Sn8aky SNitch", at about 95 ms per observation against 30 ms. `ocr="always"` and `ocr="never"` force either path, and `snapshot.context["perception_sources"]` records which one ran. On a Clock alarm task, `auto` took 2.8–3.0 s against 3.6 s with `always`. JEV receives structured elements and IDs, not screenshots. Providers that accept images can also receive a window screenshot for completion checks; see [Terminal states](#terminal-states). The provider request stores element facts once in a shared table. Target choices refer to those observed IDs, and all questions share the same subtask. This reduces repeated request data without discarding element facts or changing the offered choices. Provider token-limit failures include `max_tokens_exceeded` in the returned error; no UI action is executed for a failed decision request. **Accessibility only.** For apps that describe themselves well to accessibility, `MacOSAXBackend` needs no screenshots, OCR or Screen Recording permission: it settles on the app's accessibility notifications instead of screen thumbnails. The walk reads only what is on screen, meaning the visible rows of lists and tables and elements inside the window and its scroll areas, so a Finder list of 2,000 files observes in about 50 ms. Electron and other Chromium-based apps are asked for their full accessibility tree. `MacOSAXBackend(pid, cache=True)` also keeps elements between observations and re-reads only what the app reports as changed, so repeat observations take a few milliseconds; values an app changes without notifying can be briefly stale, which is why it is opt-in. `MacOSHybridBackend` adds OCR automatically for apps with little accessibility. ### Background control on macOS `MacOSHybridBackend` and `MacOSAXBackend` act on one app, given by its process ID, whether or not it is frontmost. Input reaches that app in the background: clicks, keys, text and scrolling are addressed to its window, so the user's pointer does not move, the window is not raised and the front app does not change. The user can keep working while a subtask runs. ```python from arc_cua import DesktopExecutor from arc_cua.backends import MacOSApp, MacOSHybridBackend from arc_cua.policies import TypeSafeJevPolicy pid = MacOSApp.from_bundle_id("com.apple.TextEdit").pid with MacOSHybridBackend(pid) as backend: result = DesktopExecutor(backend, TypeSafeJevPolicy()).run(subtask) ``` - **Accessibility first.** `AXPress` and `AXValue` need no events at all. Other input is posted to the app's process, with key focus lent to its window for the few milliseconds an event batch takes and then handed back to the user's window. - **Command shortcuts** go through the app's menu when an enabled menu item has them, since menu key equivalents only reach the front app. `MOD+A` in a text field selects its text through accessibility. - **Hidden and minimized windows.** Used as a context manager (or with `open()` and `close()`), `MacOSAXBackend` reads a minimized window or a hidden app as it is and presses and sets its controls through accessibility, so the window stays where it is. An action that needs input events (keys, scrolling, pointer clicks) first moves the window onto an invisible display where the app renders it and takes input; on exit it is minimized or hidden again and moved back. `MacOSHybridBackend` needs pixels for OCR, so it moves the window when it opens. - **If the app activates itself** after an input, which some controls do, the user's app is brought back to the front. - **Clear failures.** Once the app quits, or has no usable window (closed, or on another desktop), observing or acting raises `TargetUnavailable` with the reason. The runtime does not retry it. ### Command line `arc-cua run` executes one subtask against one macOS app and exits. It reads one JSON object from standard input: ```json { "app": {"pid": 4242}, "subtask": { "goal": "Replace the document's text with the supplied text", "inputs": {"text": "Hello"}, "verification": ["The document's text is exactly: Hello"], "max_actions": 10 }, "provider": {"name": "jev", "api_key": "..."} } ``` | Field | Meaning | |---|---| | `app` | `{"pid": ...}`, or `{"bundle_id": "com.apple.TextEdit"}` for the first running instance (required) | | `subtask` | The subtask, with the fields in [JSON field types](#json-field-types) (required) | | `provider` | `name` (`"jev"` or `"openai"`), `api_key`, and optionally `model` (required). `api_key` falls back to `TYPESAFE_API_KEY` or `OPENAI_API_KEY` | | `backend` | `"hybrid"` (AX, with OCR when accessibility exposes no app controls; the default) or `"ax"` | | `timeout_s`, `min_confidence`, `min_margin` | As in `RuntimeConfig` | | `dry_run` | `true` to decide and validate the next action, then stop with `DRY_RUN` without acting | It prints one JSON line to standard output after every action, then a final line, and exits: ```text {"type": "action", "step": 1, "action": "SET_VALUE", "target": "ax_3", "target_name": "", "value": "Hello", "state_changed": true, "confidence": 0.48, ...} {"type": "result", "status": "SUBTASK_COMPLETE", "reason": null, "needs_input": null, "actions_taken": 1, "application": "TextEdit", "window": "Untitled", ...} ``` Action lines carry the same fields as a history record in `result_to_dict`. The exit code is 0 after a result line, whatever its status. When the run cannot produce a result, the last line is `{"type": "error", "error": "..."}` instead: exit code 2 for invalid input, 1 when the app quit or has no usable window, a permission is missing, or the provider failed. Logs go to standard error, never standard output (`-v` for debug detail). `--log FILE` appends one JSON line per decision to `FILE`, including the final one: `step`, `choice`, `target`, `target_name`, `input_key`, `confidence`, `margin`, `decide_ms`, `step_elapsed_ms`, `state_changed`, `candidate_counts` (options per question), `operation_probabilities` and `outcome`. Secret inputs are redacted there too. Runs are stateless: each process runs one subtask. To stop a run, terminate the process (`SIGTERM` or `SIGINT`); it exits after putting back any windows it moved out of sight and returning key focus. ### Browser (Chrome) `ChromeBackend` runs the same loop in a Chrome tab, on macOS, Linux and Windows. It reads the page's DOM in one script call and acts through the Chrome DevTools protocol, so the real pointer and keyboard focus are untouched and the window can stay in the background. ```python from arc_cua import DesktopExecutor, Subtask from arc_cua.backends import ChromeBackend from arc_cua.policies import TypeSafeJevPolicy with ChromeBackend.launch("https://en.wikipedia.org") as backend: result = DesktopExecutor(backend, TypeSafeJevPolicy()).run(Subtask( goal="Open the Wikipedia article about Gödel's incompleteness theorems", inputs={"query": "Gödel's incompleteness theorems"}, verification=("The article titled Gödel's incompleteness theorems is open",), )) ``` - **Elements** are the controls and text visible in the viewport, with roles, accessible names, values and states. Open shadow roots and same-origin iframes are included. `SCROLL` reveals more; `context["more_below"]` says whether there is more. - **Covered controls**, such as a button behind a cookie banner, are listed without actions until they can actually receive a click. A radio button that is already checked offers no click either, since clicking it changes nothing. - **Custom widgets** without semantics are found by their pointer cursor. A wrapper around a real control, such as a styled radio button, is not listed separately; the control inside it is. - **Settling** waits for the document, XHR and fetch requests an action started to finish, as well as for the DOM to go quiet, so results loaded after a click are observed. Requests already open before the action (long polling, streams) do not hold it up. - **Native dropdowns, sliders and date inputs** use `SET_VALUE` with an agent-supplied input. A `