Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
fix: press tab buttons instead of writing AXValue in check (#711)
Chris Tateaf5374cafd80
diff --git a/crates/macos/src/actions/toggle_state.rs b/crates/macos/src/actions/toggle_state.rsindex 61ec34982..7923a3136 100644--- a/crates/macos/src/actions/toggle_state.rs+++ b/crates/macos/src/actions/toggle_state.rs@@ -116,6 +116,9 @@ impl CheckTarget for LiveToggleTarget<'_> {fn value_settable(&mut self) -> Result<bool, AdapterError> {prepare(self.el, self.deadline)?;+ if !radio::value_write_allowed(radio::subrole(self.el, self.deadline)?.as_deref()) {+ return Ok(false);+ }ax_helpers::is_attr_settable(self.el, "AXValue", self.deadline)}diff --git a/crates/macos/src/actions/toggle_state_check_tests.rs b/crates/macos/src/actions/toggle_state_check_tests.rsindex c397f02eb..56469ba67 100644--- a/crates/macos/src/actions/toggle_state_check_tests.rs+++ b/crates/macos/src/actions/toggle_state_check_tests.rs@@ -5,7 +5,7 @@ use agent_desktop_core::{actions::action_step_outcome::ActionStepOutcome,};-use super::{CheckTarget, run_check};+use super::{CheckTarget, radio::value_write_allowed, run_check};struct Scripted {reads: VecDeque<Option<bool>>,@@ -207,3 +207,19 @@ fn a_radio_whose_state_is_unreadable_after_a_refused_write_is_not_called_undelivassert_eq!(error.disposition, DeliverySemantics::delivered_unverified());assert_eq!(target.clicks, 0);}++#[test]+fn tab_buttons_never_take_a_value_write() {+ assert!(!value_write_allowed(Some("AXTabButton")));+ assert!(value_write_allowed(None));+ assert!(value_write_allowed(Some("AXSwitch")));+}++#[test]+fn an_unsettable_tab_button_is_selected_by_press_and_verified() {+ let mut target = Scripted::new(&[Some(false)], &[Some(true)], false);+ let steps = run_check(&mut target, true, true).expect("press selects the tab");+ assert_eq!(target.writes, 0);+ assert_eq!(target.clicks, 1);+ assert_eq!(labels(&steps), vec![("AXPress".to_string(), Some(true))]);+}diff --git a/crates/macos/src/actions/toggle_state_radio.rs b/crates/macos/src/actions/toggle_state_radio.rsindex 0296b1317..e4e247d68 100644--- a/crates/macos/src/actions/toggle_state_radio.rs+++ b/crates/macos/src/actions/toggle_state_radio.rs@@ -1,4 +1,6 @@-use agent_desktop_core::{ActionStep, AdapterError, DeliverySemantics, ErrorCode};+use agent_desktop_core::{ActionStep, AdapterError, Deadline, DeliverySemantics, ErrorCode};++use crate::tree::AXElement;use super::{CheckTarget, after_delivery, value_write_step};@@ -30,3 +32,18 @@ pub(super) fn uncheck_unsupported() -> AdapterError {).with_disposition(DeliverySemantics::not_delivered())}++/// Reports whether check/uncheck may write `AXValue` on an element with this subrole.+///+/// A tab button (`AXRadioButton` with subrole `AXTabButton`) is selected, not checked.+/// Chromium-based browsers report `AXValue` as settable on a web `role="tab"` element,+/// and writing it crashes the browser, so check/uncheck presses tab buttons instead.+pub(super) fn value_write_allowed(subrole: Option<&str>) -> bool {+ subrole != Some("AXTabButton")+}++/// Reads the element's `AXSubrole`.+pub(super) fn subrole(el: &AXElement, deadline: Deadline) -> Result<Option<String>, AdapterError> {+ let instant = crate::tree::locator_deadline::from_operation(deadline)?;+ crate::tree::resolve::resolve_ax_read::read_string(el, "AXSubrole", instant)+}diff --git a/skills/agent-desktop-macos/SKILL.md b/skills/agent-desktop-macos/SKILL.mdindex 3112aa1b3..0a9f75c40 100644--- a/skills/agent-desktop-macos/SKILL.md+++ b/skills/agent-desktop-macos/SKILL.md@@ -42,6 +42,8 @@ The sandbox provider on macOS is `macos`: a macOS VM that needs an Apple Silicon**Judge delivery by observation.** AX return codes do not prove an effect. Finder returns success from an `AXConfirm` that does nothing. Snapshot again or use `get` and `is` to check the result.+**Tab buttons.** A tab (`AXRadioButton` with subrole `AXTabButton`) is selected, not checked. `check` presses a tab button instead of writing `AXValue`, because writing `AXValue` on a web `role="tab"` crashes Chromium-based browsers. Some web tab widgets ignore that semantic press, so `check` reports that the state was not reached; select those with `click --headed`.+**Surfaces.** Use `--surface menubar` for an app's File, Edit, and View menus. Use `--surface menu-bar-extras` for status items: with no `--app` it reads system items such as Wi-Fi, Battery, and Clock; with `--app` it reads that app's own item. Use `--surface dock` for the Dock. These shell surfaces are available headless through `open-system-surface`. A background app with no ordinary window, such as a menu-bar app or Control Center, can be observed through its process with `snapshot --app "Control Center"`. This applies to `window`, `menubar`, and `menu-bar-extras`, not `focused`; a regular app that has not shown its window returns `WINDOW_NOT_FOUND`. While a menu, sheet, alert, or popover is open, refs from the window tree behind it are the wrong target.**Menus.** `right-click` headless uses `AXShowMenu`. If the menu opened but the app returned `APP_UNRESPONSIVE` with `retry: unsafe`, do not retry. Inspect the menu with `--surface menu`. `menu` requires an open menu: if `snapshot --surface menu` returns `surface_absent` with `complete: true`, snapshot `menubar` when it exists, click its item without `--headed`, then snapshot `--surface menu`. An absent `menubar` can mean the app exposes no menu bar. A missing `complete`, `complete: false`, timeout or incomplete read is unknown, not absent. For combo boxes and menu buttons, use `select @ref "Option"`. `select` needs a closed-to-open menu transition, so dismiss any open menu first.