Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

docs(cua-driver): document jev-use native accessibility candidates (#4299)

Francesco Bonaccid6901198497b
diff --git a/docs/content/docs/how-to-guides/driver/jev-use.mdx b/docs/content/docs/how-to-guides/driver/jev-use.mdx
index 556eac4cbd..4972f50e0c 100644
--- a/docs/content/docs/how-to-guides/driver/jev-use.mdx
+++ b/docs/content/docs/how-to-guides/driver/jev-use.mdx
@@ -265,6 +265,11 @@ shell call until it finishes. The command manages the test server itself.
| Output directory already exists | Choose another `--output-dir` to keep the previous result. |
| Run fails or reports `"complete": false` | Read the action log before retrying. Failure does not prove that nothing happened; an action may already have landed. |
+## Native desktop apps
+
+To choose from a desktop app's accessibility tree instead of a web page, see
+[Use jev-use with native apps](/how-to-guides/driver/use-jev-use-with-native-apps).
+
## Adapt the example
To automate a different task, change three parts of the agent:
diff --git a/docs/content/docs/how-to-guides/driver/meta.json b/docs/content/docs/how-to-guides/driver/meta.json
index d87c0fdc84..2982f51d4e 100644
--- a/docs/content/docs/how-to-guides/driver/meta.json
+++ b/docs/content/docs/how-to-guides/driver/meta.json
@@ -15,6 +15,7 @@
"run-with-local-model",
"parse-visual-regions",
"use-jev-use-with-visual-regions",
+ "use-jev-use-with-native-apps",
"drive-a-web-page",
"record-and-render-a-trajectory",
"keep-running",
diff --git a/docs/content/docs/how-to-guides/driver/use-jev-use-with-native-apps.mdx b/docs/content/docs/how-to-guides/driver/use-jev-use-with-native-apps.mdx
new file mode 100644
index 0000000000..3ab56af934
--- /dev/null
+++ b/docs/content/docs/how-to-guides/driver/use-jev-use-with-native-apps.mdx
@@ -0,0 +1,191 @@
+---
+title: 'Use jev-use with native apps'
+description: 'Let TypeSafe Jev choose from accessibility-tree candidates in a macOS, Windows, or Linux desktop app while Cua Driver acts and verifies.'
+---
+
+import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
+
+The [jev-use browser guide](/how-to-guides/driver/jev-use) builds candidates
+from a web page. The same loop also works in native desktop apps. Candidates
+come from the accessibility tree that Cua Driver reports through macOS
+Accessibility, Windows UI Automation, or Linux AT-SPI.
+
+You'll run three small tasks against a test app included in the repository:
+set a counter to 3, type and save a note, and choose a size and tick a
+checkbox. The example checks each result against a state file the app writes
+itself, not against what the model or Driver reports.
+
+## How native candidates work
+
+On each step the agent makes one `get_window_state` call, which returns the
+element tree and the screenshot together. From that single observation it
+builds a closed list of candidates:
+
+- **Only usable controls.** An element becomes a candidate only when it is
+ enabled, on screen, labeled, and part of the native app rather than
+ embedded web content. Window chrome such as the Windows title bar buttons
+ is skipped.
+- **One vocabulary across platforms.** Raw platform roles map to a small set
+ of role classes: `button`, `toggle`, `checkbox`, `radio`, `popup`,
+ `menu_item`, `link`, and `text_input`. The same task produces the same
+ candidate IDs on macOS, Windows, and Linux.
+- **Stable IDs.** Candidate IDs come from the role class, the label, and the
+ path of actionable ancestors, not from element indexes that change between
+ observations.
+- **Bounded and safe.** At most 24 actions are offered, plus `reobserve` and
+ `abstain`. Controls whose labels suggest deleting, sending, purchasing, or
+ closing are left out unless the task allows that risk. Typed text comes
+ only from the task's parameters.
+
+Jev receives the goal, compact element descriptions without their values, and
+the candidate IDs. It returns one ID. The agent resolves that ID to an
+element-bound `click`, `set_value`, or `type_text` call, runs it with
+background delivery, and observes again. If an element token has gone stale,
+the next step observes afresh instead of guessing.
+
+Some apps draw their own controls and expose little or nothing to
+accessibility. When the tree offers nothing to act through, the agent falls
+back to [visual regions](/how-to-guides/driver/parse-visual-regions) parsed by
+the cua-perception extension from the same capture. This happens when Driver
+reports an empty tree, when a complete tree lacks a control the task declares,
+or when the tree holds only the window itself and its title bar or menu bar.
+A partial tree that has any app control never falls back. A visual target
+needs an exact, unique text match with an OCR confidence of at least 0.8,
+unless the task sets a lower bar. Visual clicks are bound to the capture and
+try background delivery first. If Driver refuses that, the next step offers a
+separate foreground click when the task allows it.
+
+Native requests use the `cua.jev_choice_request_v2` contract, which adds a
+`source` to each candidate (`page`, `ax`, or `visual`). Browser tasks keep
+sending `cua.jev_choice_request_v1`.
+
+## Before you start
+
+You need a logged-in graphical desktop and:
+
+- [Cua Driver](/how-to-guides/driver/install), version 0.30.1 or later, with
+ the permissions its install guide describes.
+- [uv](https://docs.astral.sh/uv/getting-started/installation/) and Git.
+- For the TypeScript runner, Node.js 22 or later and npm.
+- For live runs, an API key from the [TypeSafe console](https://console.typesafe.ai/).
+ The mock run needs no key.
+
+Download the example as in the browser guide:
+
+```bash
+git clone --depth 1 https://github.com/trycua/cua.git cua-jev-use
+cd cua-jev-use/libs/cua-driver/examples/jev-use
+uv sync --frozen --python 3.12
+npm ci # in PowerShell, use npm.cmd ci
+```
+
+## 1. Build the test app and run the mock proof
+
+The mock provider returns fixed choices, so this step checks the Driver
+connection, candidate building, and the oracle without calling Jev.
+
+<Tabs items={['macOS', 'Windows', 'Linux']}>
+ <Tab value="macOS">
+
+The test app is an AppKit harness:
+
+```bash
+bash ../../tests/fixtures/build/macos.sh --only appkit
+uv run --frozen python verify_native.py --harness appkit --typescript --output-dir runs/native-mock
+```
+
+ </Tab>
+ <Tab value="Windows">
+
+The test app is a WPF harness. Run from PowerShell in the interactive desktop
+session:
+
+```powershell
+..\..\tests\fixtures\build\windows.ps1 -Targets wpf
+uv run --frozen python verify_native.py --harness wpf --typescript --output-dir runs/native-mock
+```
+
+ </Tab>
+ <Tab value="Linux">
+
+The test app is a GTK3 harness. Use an X11 session with the accessibility bus
+running; the harness uses the system `python3` with PyGObject:
+
+```bash
+bash ../../tests/fixtures/build/linux.sh --only gtk3
+.venv/bin/python verify_native.py --harness gtk3 --typescript --output-dir runs/native-mock
+```
+
+With Cua Driver 0.30.2 or earlier, Linux reports no value for a named text
+field ([#4291](https://github.com/trycua/cua/issues/4291)). The save-note task
+then can't see its own write and runs out of steps. Update Driver to fix this.
+
+ </Tab>
+</Tabs>
+
+To prove the fallback, run the `canvas` harness. It is a custom-painted
+window with no accessibility tree, so its `canvas-cancel` task succeeds only by
+clicking the **Cancel** label through visual regions. It needs the
+[cua-perception extension](/concepts/how-the-perception-extension-works)
+installed and a Python with Tk. It needs no build step and works on all three platforms:
+
+```bash
+uv run --frozen python verify_native.py --harness canvas --output-dir runs/native-canvas
+```
+
+The command launches the harness, runs each task in Python and TypeScript, and
+closes the harness when done. Results are in `runs/native-mock/summary.json`.
+Each task passes only when the harness state file shows the expected result.
+
+## 2. Run with Jev
+
+Add `--live` to the same command and use a new output directory. For example,
+on macOS:
+
+```bash
+uv run --frozen python verify_native.py --harness appkit --typescript --live --output-dir runs/native-live
+```
+
+At an interactive terminal, the command asks for your TypeSafe API key without
+showing or saving it. If `TYPESAFE_API_KEY` is already set in the process
+environment, it uses that instead. Never put the key in a command argument or
+file. Use `--task` to run a single task, for example `--task counter`.
+
+## 3. Run with Cua-S1 (optional)
+
+The native runners can also choose with the local Cua-S1-4B model. Loading the
+model takes 10 to 35 seconds, longer than a step can wait before its capture
+expires, so the runners send each request to a model that is already loaded
+behind a loopback HTTP endpoint. The example doesn't ship that service. The
+[jev-use README](https://github.com/trycua/cua/blob/main/libs/cua-driver/examples/jev-use/README.md#choose-with-cua-s1)
+describes the request and response it must accept, and
+[Closed-candidate decision models](https://github.com/trycua/cua/blob/main/libs/cua-driver/examples/jev-use/decision-models.md)
+covers getting the weights.
+
+With the service running, point the example at it and add `--s1`:
+
+```bash
+export CUA_S1_DECISION_URL=http://127.0.0.1:8791/decide
+uv run --frozen python verify_native.py --harness appkit --typescript --s1 --output-dir runs/native-s1
+```
+
+The URL must use `127.0.0.1`, `localhost`, or `::1`. Reach a model on another
+computer through an SSH tunnel. The runner rejects a response that doesn't match
+its request, and it resolves the chosen ID against its own candidate list, the
+same as for Jev.
+
+## Adapt the example to your app
+
+A native task spec in `python/native_tasks.py` (and `typescript/native_tasks.ts`)
+defines:
+
+| Part | Purpose |
+| --- | --- |
+| Goal and parameters | What to accomplish, and any text to type. Secret parameters are redacted from logs. |
+| Allowed actions and risk | Which Driver actions the task may use, and whether risky labels are allowed. |
+| Oracle | How to confirm success from the app's own state, independent of the accessibility tree. |
+
+Keep candidate building in the example layer. Don't add model logic to Cua
+Driver, and don't let the model supply element tokens, coordinates, or text.
+The design and its trade-offs are recorded in
+[RFC 4268](https://github.com/trycua/cua/blob/main/rfcs/4268-jev-use-native-candidates.md).
diff --git a/rfcs/4268-jev-use-native-candidates.md b/rfcs/4268-jev-use-native-candidates.md
index fc3cd929d5..5c3bf8807e 100644
--- a/rfcs/4268-jev-use-native-candidates.md
+++ b/rfcs/4268-jev-use-native-candidates.md
@@ -11,6 +11,11 @@ implementation:
- https://github.com/trycua/cua/issues/4268
- https://github.com/trycua/cua/pull/4270
- https://github.com/trycua/cua/pull/4288
+ - https://github.com/trycua/cua/pull/4290
+ - https://github.com/trycua/cua/pull/4295
+ - https://github.com/trycua/cua/pull/4298
+ - https://github.com/trycua/cua/pull/4301
+ - https://github.com/trycua/cua/pull/4299
supersedes:
superseded_by:
---
@@ -828,3 +833,39 @@ Implementation:
unchanged. The Phase 1 tasks use radio buttons in place of a pop-up
button, because an open AppKit menu runs a modal tracking loop that is not
deterministic for background CI.
+- Phase 2, [#4290](https://github.com/trycua/cua/pull/4290): the same tasks
+ on the WPF (UIA) and GTK3 (AT-SPI) harnesses, with mock E2E jobs on all
+ three platforms. Linux named text fields reported no `value` on Driver
+ 0.30.2 and earlier ([#4291](https://github.com/trycua/cua/issues/4291),
+ fixed by [#4292](https://github.com/trycua/cua/pull/4292)).
+- Phase 3: [#4295](https://github.com/trycua/cua/pull/4295) adds the Cua-S1
+ provider to the native runners through a loopback decision service;
+ [#4298](https://github.com/trycua/cua/pull/4298) adds the
+ `no_application_elements` fallback and the canvas task;
+ [#4301](https://github.com/trycua/cua/pull/4301) retargets the canvas task
+ to Cancel.
+- Phase 4, [#4299](https://github.com/trycua/cua/pull/4299): the native
+ apps guide and the `skills/jev-use` update.
+
+Phase 3 live evidence (released Driver 0.30.2, cua-perception 0.2.1,
+`cua-s1-4b-0.2@16818868`; each run verified by the harness's own state file):
+
+- Live Jev passed 5/5 in every native row (AppKit, WPF, GTK3 × three tasks
+ × Python and TypeScript) except GTK3 `save-note`, blocked by #4291 until
+ Driver 0.30.3 ships.
+- S1 missed six of 82 native runs: three `counter` runs where it abstained
+ after two increments (the value-free request makes it count from history),
+ two macOS `save-note` runs where it pressed Save before typing, and one
+ service error.
+- The canvas task, reachable only through OmniParser, passed 15/15 per
+ provider and language across the three platforms. The browser regression
+ passed on both the page and visual paths.
+- Median decide time was about 0.25 s for Jev and 2.0–2.2 s for S1. The
+ median OmniParser parse was 2.1 s on macOS, 4.7 s on Linux, and 8.1 s on
+ Windows.
+- The tasks produce 3–7 candidates. Jev chose correctly in 220/220 decisions
+ and S1 in 211/216.
+
+Acceptance criteria not yet met, which keep this RFC `accepted`: S1 5/5 in
+every native row, GTK3 `save-note` on a released Driver, WinUI3 coverage,
+and accuracy at about 12 and 24 candidates.
diff --git a/skills/jev-use/SKILL.md b/skills/jev-use/SKILL.md
index a8f2b1a922..f848cff89d 100644
--- a/skills/jev-use/SKILL.md
+++ b/skills/jev-use/SKILL.md
@@ -20,6 +20,9 @@ compact regions, bounded history, and candidate IDs with descriptions; the
response contains only the selected ID, model identity, confidence, and
probabilities. Invoke the Python interpreter and absolute chooser path directly
without a shell.
+For native desktop applications, use `NativeAccessibilitySource` and
+`cua.jev_choice_request_v2`, which adds a per-candidate `source` (`page`, `ax`,
+or `visual`) and compact value-free `elements`. Browser tasks keep sending v1.
Prefer browser DOM and semantic evidence. The optional visual adapter consumes
the public `cua.visual_regions_v1` result only when Driver advertises both
`parse_visual_regions` and the capture-bound `click.capture_id` input.
@@ -64,6 +67,26 @@ extension artifact, or Driver implementation detail to the recipe.
- Use semantic evidence as authority when it is available. A visual label does
not prove editability or interactivity.
+## Native accessibility candidates
+
+- Build native candidates from one `get_window_state` call that returns the
+ tree and the screenshot together, so element tokens and `capture_id`
+ describe the same moment.
+- Map raw AX, UIA, and AT-SPI roles through the role-class table in
+ `native_roles.py` / `native_roles.ts`, keyed by Driver's `normalized_role`.
+ Do not normalize roles in Driver.
+- Offer only enabled, on-screen, labeled, native elements; exclude
+ `in_web_content` elements, window chrome, and labels equal to the value.
+- Derive candidate IDs from role class, label, and actionable-ancestor path,
+ never `element_index`. Cap at 24 action candidates plus `reobserve` and
+ `abstain`, and log how many were dropped.
+- Exclude delete, send, purchase, and close actions unless the task spec
+ allows that risk. Text comes only from task parameters.
+- A stale token or truncated tree leads to a reobserve, never to an
+ unbound coordinate action.
+- Verify completion through the task's independent oracle, such as the
+ harness task-state file, not the accessibility tree the model saw.
+
## Credentials and proof
The deterministic mock path must work without `TYPESAFE_API_KEY`. For live Jev,