Skip to content

Computer use CLI for AI agents

fix: report unread expand state as unverified rather than failed

Lahfira7131c241cce
diff --git a/.github/workflows/inspector.yml b/.github/workflows/inspector.yml
index ee3eea774..4a25ac9d6 100644
--- a/.github/workflows/inspector.yml
+++ b/.github/workflows/inspector.yml
@@ -16,8 +16,9 @@ jobs:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- - name: Check Node runtime
- run: node -e 'if (Number(process.versions.node.split(".")[0]) < 22) throw new Error("Node 22 or newer required")'
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: '22'
- name: Inspector contract and lifecycle tests
run: npm --prefix tools/inspector test
- name: Embedded visual viewer tests
diff --git a/CLAUDE.md b/CLAUDE.md
index 144d4af12..1cb39f109 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -286,7 +286,7 @@ Every command produces a response envelope:
```json
{
- "version": "2.3",
+ "version": "2.4",
"ok": true,
"command": "snapshot",
"data": {
@@ -302,7 +302,7 @@ Error responses:
```json
{
- "version": "2.3",
+ "version": "2.4",
"ok": false,
"command": "click",
"error": {
@@ -400,10 +400,10 @@ contact with Windows and was deleted. See
## Commands
-58 commands spanning App/Window, Observation, Interaction, Scroll, Keyboard,
+59 commands spanning App/Window, Observation, Interaction, Scroll, Keyboard,
Mouse, Notifications (macOS), Clipboard, Wait, System (including `session`), and
Batch. The full surface and per-command reference live in `skills/agent-desktop/`.
-All 58 are implemented on macOS (Phase 1); Windows/Linux (Phase 2/3) target the
+All 59 are implemented on macOS (Phase 1); Windows/Linux (Phase 2/3) target the
same surface. Adding a command: see the Extensibility Pattern above.
## Non-Goals
diff --git a/crates/macos/src/actions/post_state.rs b/crates/macos/src/actions/post_state.rs
index 247e8c111..aa9903016 100644
--- a/crates/macos/src/actions/post_state.rs
+++ b/crates/macos/src/actions/post_state.rs
@@ -35,16 +35,17 @@ pub(crate) fn read_live_element(
let available_actions = known_actions(read.evidence.ref_evidence.available_actions)?;
let attrs = read.attrs;
let bounds = attrs.bounds;
+ let expanded_observed = attrs
+ .states
+ .control
+ .expanded
+ .or(attrs.states.control.disclosing)
+ .is_some();
let window_bounds = owning_window_bounds(element, deadline)?;
let state = element_state_from_attrs(element, attrs, role, window_bounds)?;
Ok(LiveElement {
identity,
- states_complete: !crate::tree::roles::is_toggleable_role(&state.role)
- || state
- .value
- .as_deref()
- .and_then(crate::tree::state_reader::parse_checked_value)
- .is_some(),
+ states_complete: states_are_complete(&state, expanded_observed),
state,
bounds,
available_actions,
@@ -164,6 +165,21 @@ fn incomplete_live_evidence() -> AdapterError {
}))
}
+/// Reports whether the control-state evidence the post-action verifier reads was
+/// actually observed. A toggleable role needs a parsable checked value; an
+/// expandable role needs an observed expanded or disclosing attribute, because an
+/// unread attribute is otherwise indistinguishable from a collapsed control.
+pub(crate) fn states_are_complete(state: &ElementState, expanded_observed: bool) -> bool {
+ let toggle_ready = !crate::tree::roles::is_toggleable_role(&state.role)
+ || state
+ .value
+ .as_deref()
+ .and_then(crate::tree::state_reader::parse_checked_value)
+ .is_some();
+ let expand_ready = !crate::tree::roles::is_expandable_role(&state.role) || expanded_observed;
+ toggle_ready && expand_ready
+}
+
fn element_state_from_attrs(
element: &AXElement,
attrs: crate::tree::NodeAttrs,
diff --git a/crates/macos/src/actions/post_state_tests.rs b/crates/macos/src/actions/post_state_tests.rs
index 767971078..0bf93d72e 100644
--- a/crates/macos/src/actions/post_state_tests.rs
+++ b/crates/macos/src/actions/post_state_tests.rs
@@ -154,3 +154,20 @@ fn optional_identity_gaps_do_not_poison_complete_actionability_evidence() {
evidence.states = LocatorField::Unknown;
assert!(!essential_live_evidence_complete(&evidence));
}
+
+#[test]
+fn an_unread_expanded_attribute_is_not_complete_state_evidence() {
+ let element = |role: &str| agent_desktop_core::ElementState {
+ role: role.into(),
+ states: Vec::new(),
+ value: None,
+ enabled: Some(true),
+ hidden: Some(false),
+ offscreen: Some(false),
+ };
+
+ assert!(!states_are_complete(&element("disclosure"), false));
+ assert!(states_are_complete(&element("disclosure"), true));
+ assert!(states_are_complete(&element("button"), false));
+ assert!(!states_are_complete(&element("checkbox"), true));
+}
diff --git a/crates/macos/src/tree/roles.rs b/crates/macos/src/tree/roles.rs
index 764325bcb..678ab9b2a 100644
--- a/crates/macos/src/tree/roles.rs
+++ b/crates/macos/src/tree/roles.rs
@@ -106,7 +106,7 @@ pub(crate) fn ax_role_and_subrole_to_str(ax_role: &str, ax_subrole: Option<&str>
}
}
-pub(crate) use agent_desktop_core::roles::is_toggleable_role;
+pub(crate) use agent_desktop_core::roles::{is_expandable_role, is_toggleable_role};
pub(crate) fn accessible_name_from_subrole(subrole: Option<&str>) -> Option<&'static str> {
match subrole {
diff --git a/docs/json-output.md b/docs/json-output.md
index 72d18a7a2..2bb670102 100644
--- a/docs/json-output.md
+++ b/docs/json-output.md
@@ -68,7 +68,7 @@ Inspect `disposition.retry` before retrying or choosing an alternative action, r
| `AMBIGUOUS_TARGET` | Ref recovery matched multiple plausible targets |
| `SNAPSHOT_NOT_FOUND` | Snapshot ID is missing or expired |
| `POLICY_DENIED` | Physical/headed path blocked by policy |
-| `ACTION_FAILED` | The OS rejected the action |
+| `ACTION_FAILED` | Action rejected, or its observed result contradicted the request |
| `ACTION_NOT_SUPPORTED` | The target does not expose the requested action |
| `APP_UNRESPONSIVE` | The matching application stopped responding |
| `PLATFORM_NOT_SUPPORTED` | Adapter method not implemented on this platform |
diff --git a/skills/agent-desktop/SKILL.md b/skills/agent-desktop/SKILL.md
index 850c90be2..c4fd095be 100644
--- a/skills/agent-desktop/SKILL.md
+++ b/skills/agent-desktop/SKILL.md
@@ -45,7 +45,7 @@ Detailed documentation is split into focused reference files. Read them as neede
| `references/commands-observation.md` | snapshot, find, get, is, screenshot, list-surfaces — all flags, output examples |
| `references/commands-interaction.md` | click, type, set-value, select, toggle, scroll, drag, keyboard, mouse — choosing the right command |
| `references/commands-system.md` | launch (including `--cdp` for Chromium web contents), close, windows, clipboard, wait, batch, session, status, permissions, version |
-| `references/workflows.md` | 16 common patterns: forms, menus, dialogs, scroll-find, drag-drop, async wait, anti-patterns |
+| `references/workflows.md` | 17 common patterns: forms, menus, dialogs, scroll-find, drag-drop, async wait, anti-patterns |
| `references/macos.md` | macOS permissions/TCC, AX API internals, smart activation chain, surfaces, Notification Center, troubleshooting |
## The Observe-Act Loop (Progressive Skeleton Traversal)
@@ -107,6 +107,15 @@ Every command returns a JSON envelope on stdout:
The `error` object may also carry an optional `details` object (e.g. the actionability report on an actionability failure, candidate summaries on `AMBIGUOUS_TARGET`, or the last observed state on a `wait` `TIMEOUT`). Parse errors leniently — `details` and future fields are additive, so do not reject responses with unknown keys.
+An error also carries `disposition`, and that object decides whether a retry is safe:
+
+| Field | Values |
+|-------|--------|
+| `disposition.delivery` | `not_delivered`, `delivery_uncertain`, `delivered_unverified`, `delivered_verified`, `unknown` |
+| `disposition.retry` | `safe`, `unsafe`, `unknown` |
+
+**Retry or substitute an action only when `disposition.retry` is `safe`, and follow `recovery.strategy` only in that same case.** Only `not_delivered` is `safe`. Every other delivery value is `unsafe`, because the action may already have landed — repeating it would click, type, or submit twice. On an `unsafe` result, read `details.post_state` and `details.postcondition_satisfied` to decide what actually happened, then act on the observed state instead of repeating the command. A failure after preparatory scrolling carries `details.preparatory_scroll` and never authorizes an automatic retry.
+
An actionability failure on a hit-test action (`click`, `double-click`, `right-click`, `triple-click`, `hover`, `drag`) can carry a `receives_events` check with `reason: "occluded by <role>"` plus a structured `occluder: { "role", "name", "bounds" }` — another element is on top of the target. Bring the target window/element to the front (or dismiss the occluder) rather than blind-retrying; see `references/commands-interaction.md` for the full check list.
Exit codes: `0` success, `1` structured error, `2` argument error.
diff --git a/skills/agent-desktop/references/commands-observation.md b/skills/agent-desktop/references/commands-observation.md
index dae7b81cd..cb7b0e8fe 100644
--- a/skills/agent-desktop/references/commands-observation.md
+++ b/skills/agent-desktop/references/commands-observation.md
@@ -137,19 +137,6 @@ agent-desktop click @s8f3k2p9:e5 --debug --screenshot /tmp/click-visual.html
- Screenshots and labels are sensitive. No session is needed. Debug snapshots retain full bounds in their persisted refmap for the viewer; JSON still omits bounds unless `--include-bounds` was requested. Debug capture is opt-in, not a byte-identical persistence mode.
- Rebuild after viewer changes and generate a new artifact; saved HTML does not update automatically.
-### Live inspector (source checkout)
-
-For an interactive tree and screenshot, run from the repository root with Node 22+:
-
-```bash
-cargo build --release -p agent-desktop
-npm --prefix tools/inspector run dev
-```
-
-Choose an app and select **Inspect app**. Tree arrows load children through the CLI; selecting a row isolates its highlight. **Show all** restores the overview. The right panel provides root-scoped find and property/state reads, with a progress toast while commands run.
-
-No npm dependencies or global tools are needed. The bridge opens a localhost URL, retries busy ports, and keeps separate temporary snapshot state. Use the full launch URL: its fragment carries the capability token, which is not served in public HTML. Accessibility permission is required; without Screen Recording permission the inspector falls back to the accessibility tree and shows a warning. It is read-only and uses the same screenshot styling as saved debug HTML. Keep one active view per server and refresh after app changes or a failed drill, which may already have replaced stored refs. Normal shutdown removes private state; `SIGKILL` or a system crash can leave temporary files. Run tests with `npm --prefix tools/inspector test`.
-
## find
Search elements by role, name, value, or text content.
@@ -207,6 +194,8 @@ menu-bar dump.
Every non-count `find` response returns the `snapshot_id` that owns its refs. Pass that exact ID to later ref actions instead of relying on the mutable latest-snapshot pointer, especially when interleaving automation across apps or windows. Count-only responses create no ref namespace and omit `snapshot_id`.
+A match with no `ref_id` is a context match: readable text that carries no action target. A context match also carries a `bounds` object (`{ x, y, width, height }`) whenever the platform reports one, so it can still be located on screen. A match that has a `ref_id` never carries `bounds`; read those with `get --property bounds`.
+
**Output (no match — `roles_present` hint):** when a `--role` filter matches nothing, `roles_present` lists the roles actually in the searched tree so you can tell a wrong role name from "none on screen"; this applies to all non-count selection modes — an empty match list, or a `--first`/`--last`/`--nth` miss — whenever a role filter was active, making it a role-vocabulary hint for retries.
```json
{
diff --git a/tools/inspector/README.md b/tools/inspector/README.md
new file mode 100644
index 000000000..7564f72f4
--- /dev/null
+++ b/tools/inspector/README.md
@@ -0,0 +1,17 @@
+# agent-desktop inspector
+
+For an interactive tree and screenshot, run from the repository root with Node 22+:
+
+```bash
+cargo build --release -p agent-desktop
+npm --prefix tools/inspector run dev
+```
+
+Choose an app and select **Inspect app**. Tree arrows load children through the CLI; selecting a row isolates its highlight. **Show all** restores the overview. The right panel provides root-scoped find and property/state reads, with a progress toast while commands run.
+
+No npm dependencies or global tools are needed. The bridge opens a localhost URL, retries busy ports, and keeps separate temporary snapshot state. Use the full launch URL: its fragment carries the capability token, which is not served in public HTML. Accessibility permission is required; without Screen Recording permission the inspector falls back to the accessibility tree and shows a warning. It is read-only and uses the same screenshot styling as saved debug HTML. Keep one active view per server and refresh after app changes or a failed drill, which may already have replaced stored refs. Normal shutdown removes private state; `SIGKILL` or a system crash can leave temporary files. Run tests with `npm --prefix tools/inspector test`.
+
+This is a tool for human developers working on agent-desktop. It is not part of
+the agent-facing command surface, and an AI agent driving the CLI has no use for
+it. The agent-invocable equivalent is `snapshot --debug --screenshot PATH.html`,
+documented in `skills/agent-desktop/references/commands-observation.md`.