Skip to content

feat(computer-use): accessibility-tree tools GetUIElements and PressUIElement - #1085

Closed
edenreich wants to merge 2 commits into
mainfrom
feat/998-accessibility-tree
Closed

edenreich wants to merge 2 commits into
mainfrom
feat/998-accessibility-tree

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Closes #998 (macOS phase).

What

Two new computer-use tools backed by the platform accessibility tree, behind a new display.AXProvider interface that mirrors the existing internal/display provider-registry pattern:

  • GetUIElements — walks the accessibility tree of frontmost (default), dock, or menubar and returns pressable elements (role, title, bbox) rendered through the same domain.AnnotationText shape as annotated frames. Coordinates are mapped into the GetLatestFrame frame space via FitDims, so an element center feeds straight into MouseClick. Read-only: no cursor movement and no screen lock, so background sessions can use it for non-invasive inspection.
  • PressUIElement — presses an element by its title via its AX default action, without moving the cursor (no physical-mouse-interference race, no coordinate risk). Takes the screen lock like the other input tools and requires approval under computer_use.approval: destructive.

macOS backend

internal/display/macos/ax_darwin.go (cgo/ObjC, following the client_darwin.go conventions): AXUIElementCreateApplication + recursive AXChildren walk, keeping elements that support kAXPressAction and have a title (AXTitle, fallback AXDescription). Dock resolves via the com.apple.dock app (AXList → AXDockItems); menubar walks the frontmost app's AXMenuBar one level deep (menu titles only — pressing one opens the menu, then GetUIElements(frontmost) sees the items; documented in the tool description). Caps: depth 8, 200 elements.

Degradation

Never a hard failure: no registered provider (Linux/Windows today), missing Accessibility (TCC) permission, or an app exposing an empty tree all return a clear message steering the model to the GetLatestFrame + region-zoom vision pipeline. Linux AT-SPI2 and Windows UIA backends can register behind the same interface in follow-ups.

Verified

  • task precommit:run green; full go test ./... green.
  • Live on this Mac: GetUIElements(dock) returned 31 dock items in frame space (1024x665), GetUIElements(menubar) the frontmost app's menu titles, GetUIElements(frontmost) Chrome's buttons; PressUIElement("Finder", dock) opened Finder with zero cursor movement.
  • Gated smoke test (TestAXProviderListDock) skips cleanly when the permission is absent (CI-safe); parse/scale/validate logic is covered cross-platform.

…IElement

Adds an AXProvider interface to internal/display (mirroring the existing
provider registry pattern) with a macOS AXUIElement backend, and two new
computer-use tools:

- GetUIElements walks the accessibility tree of the frontmost app, the
  Dock, or the menu bar and returns pressable elements (role, title,
  bbox) mapped into the GetLatestFrame frame space, so centers feed
  straight into MouseClick. Read-only: no cursor movement, no screen
  lock, usable by background sessions.
- PressUIElement invokes an element's default press action by title
  without moving the cursor; it takes the screen lock and requires
  approval under computer_use.approval: destructive.

No provider registered (non-macOS), missing TCC permission, or an empty
tree degrade to a message steering the model to the GetLatestFrame
vision pipeline - never a hard failure. Linux AT-SPI2 and Windows UIA
backends can register behind the same interface later.

Closes #998
@edenreich
edenreich requested a review from a team as a code owner August 20, 2026 11:57
…use.yaml files

computer_use.yaml was decoded into a zero struct, so tool sections added
after a user's file was seeded loaded as enabled: false - GetUIElements
and PressUIElement were silently absent from the toolset. LoadComputerUse
now decodes the file over the in-code defaults (LoadYAMLMerged), so
missing sections keep their defaults.

Also steer the model to the accessibility tree first: MouseMove,
MouseClick, and GetLatestFrame descriptions now name GetUIElements as
the preferred way to locate elements, with GetLatestFrame as fallback.
@edenreich

Copy link
Copy Markdown
Contributor Author

Superseded by #1086 — same GetUIElements/PressUIElement tools, rewritten fully cgo-free (purego + robotgo cgo-free backend). Closing to avoid duplicates.

@edenreich edenreich closed this Aug 20, 2026
@edenreich
edenreich deleted the feat/998-accessibility-tree branch August 20, 2026 16:03
edenreich added a commit that referenced this pull request Aug 20, 2026
Supersedes #1085 — delivers the same accessibility-tree tools, rewritten
to be **fully cgo-free**.

## What

The macOS computer-use layer no longer needs cgo. The whole CLI now
cross-compiles with `CGO_ENABLED=0` on darwin, linux and windows from a
single host.

### Tools (unchanged public surface)
- `GetUIElements` — lists pressable accessibility elements (`frontmost`,
`dock`, `menubar`).
- `PressUIElement` — presses an element by title without moving the
cursor.

### cgo → cgo-free

| Area | Before | After |
|------|--------|-------|
| AX tree | cgo / Objective-C | purego (`dlopen` + `purego/objc`)
walking AXUIElement |
| App focus (list / frontmost / activate) | NSWorkspace via cgo |
robotgo cgo-free backend (`-tags mac`) |
| Screen capture + input | robotgo (cgo) | robotgo cgo-free backend |
| Accessibility permission | `AXIsProcessTrusted` (cgo) | purego
`AXIsProcessTrusted` |
| Clipboard | `golang.design/x/clipboard` (cgo, text + image) | robotgo
clipboard subpackage (exec, text only) |

### Dependencies
- robotgo pinned to a cgo-free `main` pseudo-version.
- Removed `golang.design/x/clipboard` and `golang.design/x/x11`.

## Build / CI reconciliation

One mechanism across Taskfile, CI and the flake:

- `CGO_ENABLED=0` everywhere.
- `-tags mac` **only** where a darwin binary is produced — robotgo is
imported on darwin only, so the tag is unnecessary for linux/windows.
Taskfile `GOTAGS`, CI `build-macos`, the release darwin step, and the
flake all follow this.
- No global `GOFLAGS`, no cross-build tag clearing.

## Behavior changes

- Application IDs are now `pid:<N>` on every platform (was the bundle ID
on macOS). `ActivateApp` accepts `pid:<N>` or a name substring.
- Image clipboard is dropped — text copy/paste only.

## Verification

- `CGO_ENABLED=0` build + cross-compile for linux/amd64, windows/amd64,
darwin/arm64 — all green.
- `task build`, `task test` (`-tags mac`), `task precommit:run` (lint: 0
issues) — green on darwin.
- Linux X11/Wayland runtime paths are compile-verified only (no Linux
host available).

## Docs

Public-surface change (new tools + cgo-free build); a `[DOCS]` follow-up
for `inference-gateway/docs` is warranted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Accessibility-tree integration for computer use tools (macOS AX, Linux AT-SPI, Windows UIA)

1 participant