feat(computer-use): precise AX-geometry element bounds via Swift AX helper - #49880
Closed
nathansmithopenclaw-alt wants to merge 1 commit into
Closed
Conversation
…elper cua-driver's get_window_state returns AX elements whose bounds are often zero or imprecise, so set-of-marks (SOM) coordinates can't be trusted for clicking. This adds a Swift AX-API helper that resolves real element geometry and merges/synthesizes coordinate-backed bounds into the SOM index, falling back gracefully when geometry is unavailable. Includes a geometry contract test and a benchmark script. macOS-only, consistent with the existing cua-driver backend. Also memoizes the backend cache only after a successful start(), and routes clicks through synthesized helper elements.
Contributor
|
Superseded by #50552 — a comprehensive cross-platform cua-driver implementation (macOS/Windows/Linux) now merged to main. It covers the platform this PR targeted. Thanks for the contribution; closing as superseded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
cua-driver'sget_window_statereturns AX elements whoseboundsare frequently zero or imprecise, so the set-of-marks (SOM) index it produces can't be trusted for coordinate clicking. This adds a Swift Accessibility-API helper (ax_geometry_helper.swift) that resolves real on-screen element geometry and merges/synthesizes coordinate-backed bounds into the element list, with graceful fallback when geometry is unavailable. The result is a SOM index whose coordinates are reliable enough to click.Why this approach: the cua-driver text/AX-tree bounds are the wrong source of truth for clicking (they're derived, not measured). Querying the macOS AX API directly for the target window's element rects gives measured geometry, and merging it onto the existing element indices keeps the SOM stable while making its coordinates trustworthy. It degrades cleanly (elements are tagged with a
geometry_status/source, and "bounds unavailable" is surfaced) so nothing breaks when the helper can't run.Related Issue
No prior issue — happy to open one if you'd prefer to track it there.
Type of Change
Changes Made
tools/computer_use/ax_geometry_helper.swift— new Swift helper querying the macOS AX API for element geometry (role, label, bounds), depth/node-capped and timeout-bounded; compiled on demand.tools/computer_use/cua_backend.py— parse structuredelements/ui_elementswith geometry, normalize screen→window bounds, and when bounds are missing/zero run the AX helper to fill (_merge_ax_geometry) or synthesize (_elements_from_ax_payload) coordinate-backed elements; each element is tagged with geometry status/source. Also memoizes the backend cache only after a successfulstart(), and routes clicks through synthesized helper elements.tools/computer_use/tool.py— surface the geometrysourceand a "bounds unavailable" marker in the element summary.tests/tools/test_computer_use_geometry_contract.py— contract tests for the parse / merge / synthesize / fallback paths (no live GUI required; uses fake sessions + unit helpers).scripts/computer_use_geometry_benchmark.py— small benchmark to measure geometry coverage across apps.How to Test
pytest tests/tools/test_computer_use_geometry_contract.py tests/tools/test_computer_use.py -q→ all pass.cua-driverinstalled, run a SOM capture against a GUI app (e.g. TextEdit / iTerm2) and confirm elementboundsare populated (sourcecua_driver.*or the AX helper) instead of(0,0,0,0).python scripts/computer_use_geometry_benchmark.pyreports per-app element/bounds coverage.Platforms tested: macOS (Apple Silicon). The helper is macOS-only, consistent with the existing
cua-driverbackend — no behavior change on Linux/Windows (geometry simply reports unavailable).Checklist
Code
feat(computer-use): …)test_computer_use_geometry_contract.py,test_computer_use.py) and they pass