Skip to content

Computer use CLI for AI agents

fix: stabilize empty accessibility identity refs

Lahfir1fb5a7d51eb7
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
new file mode 100644
index 000000000..687d76e38
--- /dev/null
+++ b/.github/workflows/codeql.yml
@@ -0,0 +1,59 @@
+name: CodeQL
+
+on:
+ pull_request:
+ push:
+ branches: [main, master]
+ schedule:
+ - cron: '22 8 * * 1'
+ workflow_dispatch:
+
+concurrency:
+ group: codeql-${{ github.ref }}
+ cancel-in-progress: true
+
+permissions: {}
+
+jobs:
+ analyze-interpreted:
+ name: Analyze (${{ matrix.language }})
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ actions: read
+ contents: read
+ security-events: write
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [actions, javascript-typescript]
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4.36.0
+ with:
+ languages: ${{ matrix.language }}
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4.36.0
+
+ analyze-rust:
+ name: Analyze (rust)
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ actions: read
+ contents: read
+ security-events: write
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4.36.0
+ with:
+ languages: rust
+ build-mode: none
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4.36.0
diff --git a/README.md b/README.md
index a1dc9df66..56164f986 100644
--- a/README.md
+++ b/README.md
@@ -265,8 +265,8 @@ agent-desktop wait --menu --timeout 3000 # wait for menu
```bash
agent-desktop batch '[
- {"command": "click", "args": {"ref_id": "@e2", "snapshot": "s8f3k2p9"}},
- {"command": "type", "args": {"ref_id": "@e5", "snapshot": "s8f3k2p9", "text": "hello"}},
+ {"command": "click", "args": {"ref_id": "@e2", "snapshot": "<snapshot_id>"}},
+ {"command": "type", "args": {"ref_id": "@e5", "snapshot": "<snapshot_id>", "text": "hello"}},
{"command": "press", "args": {"combo": "return"}}
]' --stop-on-error
```
@@ -296,7 +296,7 @@ agent-desktop snapshot [OPTIONS]
| `--max-depth <N>` | 10 | Maximum tree depth |
| `--skeleton` | off | Shallow 3-level overview; truncated containers show `children_count` and get refs as drill targets |
| `--root <REF>` | - | Start traversal from this ref; merges into existing refmap with scoped invalidation |
-| `--snapshot <ID>` | latest | Snapshot ID to use when resolving `--root` |
+| `--snapshot <snapshot_id>` | latest | Snapshot ID to use when resolving `--root` |
| `--surface <TYPE>` | window | `window`, `focused`, `menu`, `menubar`, `sheet`, `popover`, `alert` |
## JSON Output
diff --git a/crates/core/src/commands/helpers_tests.rs b/crates/core/src/commands/helpers_tests.rs
index 96facc61c..6fb569260 100644
--- a/crates/core/src/commands/helpers_tests.rs
+++ b/crates/core/src/commands/helpers_tests.rs
@@ -76,6 +76,7 @@ fn entry() -> RefEntry {
role: "button".into(),
name: Some("OK".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
diff --git a/crates/core/src/commands/is_check_tests.rs b/crates/core/src/commands/is_check_tests.rs
index 99fe7c550..042f18396 100644
--- a/crates/core/src/commands/is_check_tests.rs
+++ b/crates/core/src/commands/is_check_tests.rs
@@ -31,6 +31,7 @@ fn entry(states: Vec<String>, value: Option<&str>, actions: Vec<&str>) -> RefEnt
role: "checkbox".into(),
name: Some("Target".into()),
value: value.map(str::to_string),
+ description: None,
states,
bounds: None,
bounds_hash: None,
@@ -156,6 +157,7 @@ fn action_availability_makes_toggle_and_expand_applicable() {
role: "cell".into(),
name: Some("Disclosure".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
diff --git a/crates/core/src/commands/ref_policy_tests.rs b/crates/core/src/commands/ref_policy_tests.rs
index a96bdab32..131ab98fe 100644
--- a/crates/core/src/commands/ref_policy_tests.rs
+++ b/crates/core/src/commands/ref_policy_tests.rs
@@ -50,6 +50,7 @@ fn snapshot_id() -> String {
role: "textfield".into(),
name: Some("Target".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
diff --git a/crates/core/src/commands/right_click_tests.rs b/crates/core/src/commands/right_click_tests.rs
index feb828f0b..d4aa1b8f7 100644
--- a/crates/core/src/commands/right_click_tests.rs
+++ b/crates/core/src/commands/right_click_tests.rs
@@ -80,6 +80,7 @@ fn save_refmap(source_app: Option<String>) -> String {
role: "button".into(),
name: Some("Open".into()),
value: None,
+ description: None,
states: Vec::new(),
bounds: None,
bounds_hash: None,
diff --git a/crates/core/src/commands/wait_tests.rs b/crates/core/src/commands/wait_tests.rs
index 8a76f08e9..4b9b19c8d 100644
--- a/crates/core/src/commands/wait_tests.rs
+++ b/crates/core/src/commands/wait_tests.rs
@@ -33,6 +33,7 @@ fn snapshot_with_one_ref() -> String {
role: "button".into(),
name: Some("Run".into()),
value: None,
+ description: None,
states: Vec::new(),
bounds: None,
bounds_hash: None,
@@ -138,6 +139,7 @@ fn latest_ref_cache_picks_up_newer_snapshot_after_refresh() {
role: "button".into(),
name: Some("Second".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
@@ -177,6 +179,7 @@ fn latest_ref_cache_debounces_consecutive_refreshes() {
role: "button".into(),
name: None,
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
diff --git a/crates/core/src/ref_alloc.rs b/crates/core/src/ref_alloc.rs
index 294820e87..84f2f29eb 100644
--- a/crates/core/src/ref_alloc.rs
+++ b/crates/core/src/ref_alloc.rs
@@ -29,8 +29,9 @@ pub(crate) fn ref_entry_from_node(
RefEntry {
pid,
role: node.role.clone(),
- name: node.name.clone(),
- value: node.value.clone(),
+ name: meaningful_string(node.name.clone()),
+ value: meaningful_string(node.value.clone()),
+ description: meaningful_string(node.description.clone()),
states: node.states.clone(),
bounds: node.bounds,
bounds_hash: node.bounds.as_ref().map(|b| b.bounds_hash()),
@@ -209,6 +210,10 @@ fn strip_ref_bounds_when_hidden(entry: &mut RefEntry, include_bounds: bool) {
}
}
+fn meaningful_string(value: Option<String>) -> Option<String> {
+ value.filter(|text| !text.is_empty())
+}
+
#[cfg(test)]
#[path = "ref_alloc_tests.rs"]
mod tests;
diff --git a/crates/core/src/ref_alloc_tests.rs b/crates/core/src/ref_alloc_tests.rs
index 19c41e94b..c1e7b5a0b 100644
--- a/crates/core/src/ref_alloc_tests.rs
+++ b/crates/core/src/ref_alloc_tests.rs
@@ -91,6 +91,30 @@ fn ref_entry_prefers_platform_actions() {
assert_eq!(entry.available_actions, vec!["SetFocus"]);
}
+#[test]
+fn ref_entry_drops_empty_identity_text() {
+ let mut button = node("button", Some(""));
+ button.value = Some(String::new());
+
+ let entry = ref_entry_from_node(&button, 7, None, None, None, None, &[0]);
+
+ assert!(entry.name.is_none());
+ assert!(entry.value.is_none());
+}
+
+#[test]
+fn ref_entry_preserves_meaningful_identity_text() {
+ let mut button = node("button", Some("Save"));
+ button.value = Some("Primary".into());
+ button.description = Some("Commits changes".into());
+
+ let entry = ref_entry_from_node(&button, 7, None, None, None, None, &[0]);
+
+ assert_eq!(entry.name.as_deref(), Some("Save"));
+ assert_eq!(entry.value.as_deref(), Some("Primary"));
+ assert_eq!(entry.description.as_deref(), Some("Commits changes"));
+}
+
#[test]
fn allocate_refs_records_structural_paths() {
let mut root = node("window", Some("w"));
diff --git a/crates/core/src/refs.rs b/crates/core/src/refs.rs
index d51b48d53..97e903c35 100644
--- a/crates/core/src/refs.rs
+++ b/crates/core/src/refs.rs
@@ -26,6 +26,8 @@ pub struct RefEntry {
pub name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub description: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub states: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
diff --git a/crates/core/src/refs_tests.rs b/crates/core/src/refs_tests.rs
index 073a3f8bf..d32b906a5 100644
--- a/crates/core/src/refs_tests.rs
+++ b/crates/core/src/refs_tests.rs
@@ -7,6 +7,7 @@ fn entry(role: &str, name: Option<&str>) -> RefEntry {
role: role.into(),
name: name.map(String::from),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: None,
@@ -39,6 +40,7 @@ fn test_get_existing() {
role: "textfield".into(),
name: None,
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: Some(12345),
@@ -184,6 +186,7 @@ fn test_save_load_roundtrip_with_home_override() {
role: "button".into(),
name: Some("Send".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: Some(42),
@@ -215,6 +218,7 @@ fn test_refstore_snapshot_roundtrip_and_latest_pointer() {
role: "button".into(),
name: Some("Send".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash: Some(42),
diff --git a/crates/ffi/include/agent_desktop.h b/crates/ffi/include/agent_desktop.h
index 201f67538..dd3416033 100644
--- a/crates/ffi/include/agent_desktop.h
+++ b/crates/ffi/include/agent_desktop.h
@@ -233,6 +233,7 @@ typedef struct AdRefEntry {
int32_t pid;
const char *role;
const char *name;
+ const char *description;
uint64_t bounds_hash;
bool has_bounds_hash;
} AdRefEntry;
diff --git a/crates/ffi/src/actions/resolve.rs b/crates/ffi/src/actions/resolve.rs
index be7b03a6b..295358c03 100644
--- a/crates/ffi/src/actions/resolve.rs
+++ b/crates/ffi/src/actions/resolve.rs
@@ -20,60 +20,20 @@ pub unsafe extern "C" fn ad_resolve_element(
trap_panic(|| unsafe {
crate::pointer_guard::guard_non_null!(out, c"out is null");
(*out).ptr = std::ptr::null();
- if let Err(rc) = crate::main_thread::require_main_thread() {
- return rc;
- }
crate::pointer_guard::guard_non_null!(adapter, c"adapter is null");
crate::pointer_guard::guard_non_null!(entry, c"entry is null");
let adapter = &*adapter;
let entry = &*entry;
- let role = match c_to_string(entry.role) {
- Some(s) => s,
- None => {
- error::set_last_error(&agent_desktop_core::error::AdapterError::new(
- agent_desktop_core::error::ErrorCode::InvalidArgs,
- "role is null or invalid UTF-8",
- ));
- return AdResult::ErrInvalidArgs;
- }
- };
- // Fail closed on invalid UTF-8 for `name`: conflating "null" with
- // "bad bytes" would widen a caller-specified filter into an
- // unfiltered re-resolution. try_c_to_string keeps null → None and
- // promotes invalid UTF-8 to an explicit InvalidArgs, matching the
- // optional-filter contract used by ad_list_* entrypoints.
- let name = match try_c_to_string(entry.name) {
- Ok(value) => value,
- Err(()) => {
- error::set_last_error(&agent_desktop_core::error::AdapterError::new(
- agent_desktop_core::error::ErrorCode::InvalidArgs,
- "name is not valid UTF-8",
- ));
- return AdResult::ErrInvalidArgs;
+ let core_entry = match core_ref_entry_from_ffi(entry) {
+ Ok(entry) => entry,
+ Err(err) => {
+ error::set_last_error(&err);
+ return error::last_error_code();
}
};
- let bounds_hash = if entry.has_bounds_hash {
- Some(entry.bounds_hash)
- } else {
- None
- };
- let core_entry = CoreRefEntry {
- pid: entry.pid,
- role,
- name,
- value: None,
- states: vec![],
- bounds: None,
- bounds_hash,
- available_actions: vec![],
- source_app: None,
- source_window_id: None,
- source_window_title: None,
- source_surface: agent_desktop_core::adapter::SnapshotSurface::Window,
- root_ref: None,
- path_is_absolute: false,
- path: smallvec::SmallVec::new(),
- };
+ if let Err(rc) = crate::main_thread::require_main_thread() {
+ return rc;
+ }
match adapter.inner.resolve_element(&core_entry) {
Ok(handle) => {
let handle = ManuallyDrop::new(handle);
@@ -87,3 +47,56 @@ pub unsafe extern "C" fn ad_resolve_element(
}
})
}
+
+unsafe fn core_ref_entry_from_ffi(
+ entry: &AdRefEntry,
+) -> Result<CoreRefEntry, agent_desktop_core::error::AdapterError> {
+ let role = unsafe { c_to_string(entry.role) }.ok_or_else(|| {
+ agent_desktop_core::error::AdapterError::new(
+ agent_desktop_core::error::ErrorCode::InvalidArgs,
+ "role is null or invalid UTF-8",
+ )
+ })?;
+ let name = unsafe { optional_string(entry.name, "name") }?;
+ let description = unsafe { optional_string(entry.description, "description") }?;
+ let bounds_hash = if entry.has_bounds_hash {
+ Some(entry.bounds_hash)
+ } else {
+ None
+ };
+
+ Ok(CoreRefEntry {
+ pid: entry.pid,
+ role,
+ name,
+ value: None,
+ description,
+ states: vec![],
+ bounds: None,
+ bounds_hash,
+ available_actions: vec![],
+ source_app: None,
+ source_window_id: None,
+ source_window_title: None,
+ source_surface: agent_desktop_core::adapter::SnapshotSurface::Window,
+ root_ref: None,
+ path_is_absolute: false,
+ path: smallvec::SmallVec::new(),
+ })
+}
+
+unsafe fn optional_string(
+ ptr: *const std::os::raw::c_char,
+ field: &str,
+) -> Result<Option<String>, agent_desktop_core::error::AdapterError> {
+ unsafe { try_c_to_string(ptr) }.map_err(|()| {
+ agent_desktop_core::error::AdapterError::new(
+ agent_desktop_core::error::ErrorCode::InvalidArgs,
+ format!("{field} is not valid UTF-8"),
+ )
+ })
+}
+
+#[cfg(test)]
+#[path = "resolve_tests.rs"]
+mod tests;
diff --git a/crates/ffi/src/actions/resolve_tests.rs b/crates/ffi/src/actions/resolve_tests.rs
new file mode 100644
index 000000000..ef981ccc0
--- /dev/null
+++ b/crates/ffi/src/actions/resolve_tests.rs
@@ -0,0 +1,45 @@
+use super::*;
+use agent_desktop_core::error::ErrorCode;
+use std::ffi::CString;
+
+#[test]
+fn ffi_ref_entry_preserves_description_identity() {
+ let role = CString::new("button").unwrap();
+ let name = CString::new("Primary").unwrap();
+ let description = CString::new("Insert Shape").unwrap();
+ let entry = AdRefEntry {
+ pid: 42,
+ role: role.as_ptr(),
+ name: name.as_ptr(),
+ description: description.as_ptr(),
+ bounds_hash: 123,
+ has_bounds_hash: true,
+ };
+
+ let core_entry = unsafe { core_ref_entry_from_ffi(&entry) }.unwrap();
+
+ assert_eq!(core_entry.pid, 42);
+ assert_eq!(core_entry.role, "button");
+ assert_eq!(core_entry.name.as_deref(), Some("Primary"));
+ assert_eq!(core_entry.description.as_deref(), Some("Insert Shape"));
+ assert_eq!(core_entry.bounds_hash, Some(123));
+}
+
+#[test]
+fn ffi_ref_entry_rejects_invalid_description_identity() {
+ let role = CString::new("button").unwrap();
+ let bad_description: [u8; 2] = [0xC3, 0x00];
+ let entry = AdRefEntry {
+ pid: 42,
+ role: role.as_ptr(),
+ name: std::ptr::null(),
+ description: bad_description.as_ptr().cast(),
+ bounds_hash: 0,
+ has_bounds_hash: false,
+ };
+
+ let err = unsafe { core_ref_entry_from_ffi(&entry) }.unwrap_err();
+
+ assert_eq!(err.code, ErrorCode::InvalidArgs);
+ assert_eq!(err.message, "description is not valid UTF-8");
+}
diff --git a/crates/ffi/src/observation/find.rs b/crates/ffi/src/observation/find.rs
index 05a6a1478..61c9e5cc0 100644
--- a/crates/ffi/src/observation/find.rs
+++ b/crates/ffi/src/observation/find.rs
@@ -96,6 +96,7 @@ pub unsafe extern "C" fn ad_find(
role: matched.role.clone(),
name: matched.name.clone(),
value: matched.value.clone(),
+ description: matched.description.clone(),
states: matched.states.clone(),
bounds: matched.bounds,
bounds_hash,
diff --git a/crates/ffi/src/types/ref_entry.rs b/crates/ffi/src/types/ref_entry.rs
index fdbcbbb0a..dd4d3be50 100644
--- a/crates/ffi/src/types/ref_entry.rs
+++ b/crates/ffi/src/types/ref_entry.rs
@@ -5,6 +5,7 @@ pub struct AdRefEntry {
pub pid: i32,
pub role: *const c_char,
pub name: *const c_char,
+ pub description: *const c_char,
pub bounds_hash: u64,
pub has_bounds_hash: bool,
}
diff --git a/crates/ffi/tests/c_abi_inputs.rs b/crates/ffi/tests/c_abi_inputs.rs
index a364f9255..aa8179187 100644
--- a/crates/ffi/tests/c_abi_inputs.rs
+++ b/crates/ffi/tests/c_abi_inputs.rs
@@ -42,6 +42,7 @@ fn resolve_element_rejects_invalid_utf8_name() {
pid: 0,
role: role.as_ptr(),
name: bad_name.as_ptr() as *const c_char,
+ description: std::ptr::null(),
bounds_hash: 0,
has_bounds_hash: false,
};
@@ -49,11 +50,29 @@ fn resolve_element_rejects_invalid_utf8_name() {
ptr: std::ptr::null(),
};
let rc = ad_resolve_element(adapter, &entry, &mut out);
- assert!(
- matches!(rc, AdResult::ErrInvalidArgs | AdResult::ErrInternal),
- "must reject without UB, got {:?}",
- rc
- );
+ assert_eq!(rc, AdResult::ErrInvalidArgs);
+ assert!(out.ptr.is_null());
+ });
+}
+
+#[test]
+fn resolve_element_rejects_invalid_utf8_description() {
+ with_adapter(|adapter| unsafe {
+ let role = std::ffi::CString::new("button").unwrap();
+ let bad_description: [u8; 2] = [0xC3, 0x00];
+ let entry = AdRefEntry {
+ pid: 0,
+ role: role.as_ptr(),
+ name: std::ptr::null(),
+ description: bad_description.as_ptr() as *const c_char,
+ bounds_hash: 0,
+ has_bounds_hash: false,
+ };
+ let mut out = AdNativeHandle {
+ ptr: std::ptr::null(),
+ };
+ let rc = ad_resolve_element(adapter, &entry, &mut out);
+ assert_eq!(rc, AdResult::ErrInvalidArgs);
assert!(out.ptr.is_null());
});
}
diff --git a/crates/macos/src/tree/mod.rs b/crates/macos/src/tree/mod.rs
index c49476405..9560060a0 100644
--- a/crates/macos/src/tree/mod.rs
+++ b/crates/macos/src/tree/mod.rs
@@ -6,6 +6,8 @@ pub mod capabilities;
pub mod element;
pub mod element_bounds;
pub mod resolve;
+mod resolve_bounds;
+mod resolve_identity;
pub mod roles;
pub mod surfaces;
diff --git a/crates/macos/src/tree/resolve.rs b/crates/macos/src/tree/resolve.rs
index 6e99dcc22..7f4bb539b 100644
--- a/crates/macos/src/tree/resolve.rs
+++ b/crates/macos/src/tree/resolve.rs
@@ -11,14 +11,17 @@ use super::element::{
child_attributes, copy_ax_array, copy_element_attr, copy_i64_attr, copy_string_attr,
element_for_pid, resolve_element_name,
};
+use super::resolve_bounds::{bounds_match, should_prune_by_bounds};
+use super::resolve_identity::{has_meaningful_identity, identity_matches};
#[cfg(target_os = "macos")]
pub fn resolve_element_impl(entry: &RefEntry) -> Result<NativeHandle, AdapterError> {
tracing::debug!(
- "resolve: searching pid={} role={} name={:?} bounds_hash={:?}",
+ "resolve: searching pid={} role={} name={:?} description={:?} bounds_hash={:?}",
entry.pid,
entry.role,
entry.name.as_deref().unwrap_or("(none)"),
+ entry.description.as_deref().unwrap_or("(none)"),
entry.bounds_hash
);
let resolve_depth: u8 = 50;
@@ -31,13 +34,19 @@ pub fn resolve_element_impl(entry: &RefEntry) -> Result<NativeHandle, AdapterErr
tracing::debug!("resolve: found path match");
return Ok(handle);
}
- if requires_scoped_path_resolution(entry) {
+ if should_retry_scoped_path_resolution(entry) {
if attempt + 1 < attempts && std::time::Instant::now() < deadline {
std::thread::sleep(std::time::Duration::from_millis(75));
}
continue;
}
}
+ if !can_use_broad_search(entry) {
+ if attempt + 1 < attempts && std::time::Instant::now() < deadline {
+ std::thread::sleep(std::time::Duration::from_millis(75));
+ }
+ continue;
+ }
let roots = candidate_roots(entry);
if let Ok(handle) = find_entry_in_roots(&roots, entry, resolve_depth, deadline) {
tracing::debug!("resolve: found exact match");
@@ -53,9 +62,10 @@ pub fn resolve_element_impl(entry: &RefEntry) -> Result<NativeHandle, AdapterErr
Err(AdapterError::new(
ErrorCode::StaleRef,
format!(
- "Element not found: role={}, name={:?}",
+ "Element not found: role={}, name={:?}, description={:?}",
entry.role,
- entry.name.as_deref().unwrap_or("(none)")
+ entry.name.as_deref().unwrap_or("(none)"),
+ entry.description.as_deref().unwrap_or("(none)")
),
)
.with_suggestion("Run 'snapshot' to refresh, then retry with the updated ref."))
@@ -78,6 +88,16 @@ fn requires_scoped_path_resolution(entry: &RefEntry) -> bool {
&& (entry.source_window_id.is_some() || entry.source_window_title.is_some())
}
+#[cfg(target_os = "macos")]
+fn should_retry_scoped_path_resolution(entry: &RefEntry) -> bool {
+ requires_scoped_path_resolution(entry)
+}
+
+#[cfg(target_os = "macos")]
+fn can_use_broad_search(entry: &RefEntry) -> bool {
+ entry.bounds_hash.is_some() || has_meaningful_identity(entry)
+}
+
#[cfg(target_os = "macos")]
fn path_candidate_roots(entry: &RefEntry) -> Vec<AXElement> {
if entry.bounds_hash.is_some() {
@@ -265,19 +285,6 @@ pub fn find_element_recursive(
Err(AdapterError::element_not_found("element"))
}
-#[cfg(target_os = "macos")]
-fn identity_matches(
- entry: &RefEntry,
- actual_name: Option<&str>,
- actual_value: Option<&str>,
-) -> bool {
- match (entry.name.as_deref(), entry.value.as_deref()) {
- (Some(expected), _) => Some(expected) == actual_name || Some(expected) == actual_value,
- (None, Some(expected)) => Some(expected) == actual_value || Some(expected) == actual_name,
- (None, None) => actual_name.is_none() && actual_value.is_none(),
- }
-}
-
#[cfg(target_os = "macos")]
fn element_matches_entry(el: &AXElement, entry: &RefEntry) -> bool {
element_matches_path_entry(el, entry) && bounds_match(el, entry)
@@ -294,47 +301,13 @@ fn element_matches_path_entry(el: &AXElement, entry: &RefEntry) -> bool {
let elem_name = promoted_label.or_else(|| resolve_element_name(el));
let elem_value = crate::tree::copy_value_typed(el);
- identity_matches(entry, elem_name.as_deref(), elem_value.as_deref())
-}
-
-#[cfg(target_os = "macos")]
-fn bounds_match(el: &AXElement, entry: &RefEntry) -> bool {
- match entry.bounds_hash {
- Some(expected) => {
- let actual = crate::tree::read_bounds(el).map(|b| b.bounds_hash());
- actual.map(|h| h == expected).unwrap_or(false)
- }
- None => true,
- }
-}
-
-#[cfg(target_os = "macos")]
-fn should_prune_by_bounds(el: &AXElement, entry: &RefEntry, depth: u8) -> bool {
- if depth == 0 || entry.bounds.is_none() || entry.bounds_hash.is_none() {
- return false;
- }
- let Some(candidate) = crate::tree::read_bounds(el) else {
- return false;
- };
- let Some(target) = entry.bounds.as_ref() else {
- return false;
- };
- !rects_overlap(&candidate, target)
-}
-
-#[cfg(target_os = "macos")]
-fn rects_overlap(
- candidate: &agent_desktop_core::node::Rect,
- target: &agent_desktop_core::node::Rect,
-) -> bool {
- let candidate_right = candidate.x + candidate.width;
- let candidate_bottom = candidate.y + candidate.height;
- let target_right = target.x + target.width;
- let target_bottom = target.y + target.height;
- candidate.x <= target_right
- && candidate_right >= target.x
- && candidate.y <= target_bottom
- && candidate_bottom >= target.y
+ let elem_description = copy_string_attr(el, accessibility_sys::kAXDescriptionAttribute);
+ identity_matches(
+ entry,
+ elem_name.as_deref(),
+ elem_value.as_deref(),
+ elem_description.as_deref(),
+ )
}
#[cfg(target_os = "macos")]
diff --git a/crates/macos/src/tree/resolve_bounds.rs b/crates/macos/src/tree/resolve_bounds.rs
new file mode 100644
index 000000000..658e61a62
--- /dev/null
+++ b/crates/macos/src/tree/resolve_bounds.rs
@@ -0,0 +1,37 @@
+use agent_desktop_core::{node::Rect, refs::RefEntry};
+
+use super::AXElement;
+
+pub(super) fn bounds_match(el: &AXElement, entry: &RefEntry) -> bool {
+ match entry.bounds_hash {
+ Some(expected) => {
+ let actual = crate::tree::read_bounds(el).map(|b| b.bounds_hash());
+ actual.map(|h| h == expected).unwrap_or(false)
+ }
+ None => true,
+ }
+}
+
+pub(super) fn should_prune_by_bounds(el: &AXElement, entry: &RefEntry, depth: u8) -> bool {
+ if depth == 0 || entry.bounds.is_none() || entry.bounds_hash.is_none() {
+ return false;
+ }
+ let Some(candidate) = crate::tree::read_bounds(el) else {
+ return false;
+ };
+ let Some(target) = entry.bounds.as_ref() else {
+ return false;
+ };
+ !rects_overlap(&candidate, target)
+}
+
+fn rects_overlap(candidate: &Rect, target: &Rect) -> bool {
+ let candidate_right = candidate.x + candidate.width;
+ let candidate_bottom = candidate.y + candidate.height;
+ let target_right = target.x + target.width;
+ let target_bottom = target.y + target.height;
+ candidate.x <= target_right
+ && candidate_right >= target.x
+ && candidate.y <= target_bottom
+ && candidate_bottom >= target.y
+}
diff --git a/crates/macos/src/tree/resolve_identity.rs b/crates/macos/src/tree/resolve_identity.rs
new file mode 100644
index 000000000..ed7fbfa42
--- /dev/null
+++ b/crates/macos/src/tree/resolve_identity.rs
@@ -0,0 +1,52 @@
+use agent_desktop_core::refs::RefEntry;
+
+pub(super) fn has_meaningful_identity(entry: &RefEntry) -> bool {
+ meaningful_text(entry.name.as_deref()).is_some()
+ || meaningful_text(entry.value.as_deref()).is_some()
+ || meaningful_text(entry.description.as_deref()).is_some()
+}
+
+pub(super) fn identity_matches(
+ entry: &RefEntry,
+ actual_name: Option<&str>,
+ actual_value: Option<&str>,
+ actual_description: Option<&str>,
+) -> bool {
+ let expected_name = meaningful_text(entry.name.as_deref());
+ let expected_value = meaningful_text(entry.value.as_deref());
+ let expected_description = meaningful_text(entry.description.as_deref());
+ let actual_name = meaningful_text(actual_name);
+ let actual_value = meaningful_text(actual_value);
+ let actual_description = meaningful_text(actual_description);
+
+ if let Some(expected) = expected_name {
+ return match_primary_identity(expected, actual_name, actual_value);
+ }
+ if let Some(expected) = expected_value {
+ return match_primary_identity(expected, actual_value, actual_name);
+ }
+ if let Some(expected) = expected_description {
+ return match_primary_identity(expected, actual_description, actual_name);
+ }
+
+ actual_name.is_none() && actual_value.is_none() && actual_description.is_none()
+}
+
+fn match_primary_identity(
+ expected: &str,
+ actual_primary: Option<&str>,
+ actual_fallback: Option<&str>,
+) -> bool {
+ match actual_primary {
+ Some(actual) => actual == expected,
+ None => actual_fallback == Some(expected),
+ }
+}
+
+fn meaningful_text(value: Option<&str>) -> Option<&str> {
+ value.filter(|text| !text.is_empty())
+}
+
+#[cfg(test)]
+#[path = "resolve_identity_tests.rs"]
+mod tests;
diff --git a/crates/macos/src/tree/resolve_identity_tests.rs b/crates/macos/src/tree/resolve_identity_tests.rs
new file mode 100644
index 000000000..d9b58ccb7
--- /dev/null
+++ b/crates/macos/src/tree/resolve_identity_tests.rs
@@ -0,0 +1,89 @@
+use super::*;
+
+fn entry() -> RefEntry {
+ RefEntry {
+ pid: 1,
+ role: "button".into(),
+ name: None,
+ value: None,
+ description: None,
+ states: vec![],
+ bounds: None,
+ bounds_hash: None,
+ available_actions: vec![],
+ source_app: None,
+ source_window_id: None,
+ source_window_title: None,
+ source_surface: agent_desktop_core::adapter::SnapshotSurface::Window,
+ root_ref: None,
+ path_is_absolute: false,
+ path: smallvec::SmallVec::new(),
+ }
+}
+
+#[test]
+fn empty_identity_matches_missing_or_empty_ax_text() {
+ let mut entry = entry();
+ entry.role = "menubutton".into();
+ entry.name = Some(String::new());
+
+ assert!(!has_meaningful_identity(&entry));
+ assert!(identity_matches(&entry, None, None, None));
+ assert!(identity_matches(&entry, Some(""), None, None));
+ assert!(identity_matches(&entry, None, Some(""), None));
+ assert!(!identity_matches(&entry, Some("Insert Shape"), None, None));
+}
+
+#[test]
+fn description_identity_matches_blank_title_controls() {
+ let mut entry = entry();
+ entry.description = Some("Insert Text Box".into());
+
+ assert!(has_meaningful_identity(&entry));
+ assert!(identity_matches(
+ &entry,
+ Some(""),
+ None,
+ Some("Insert Text Box")
+ ));
+ assert!(identity_matches(
+ &entry,
+ Some("Insert Text Box"),
+ None,
+ None
+ ));
+ assert!(!identity_matches(&entry, Some(""), None, None));
+ assert!(!identity_matches(
+ &entry,
+ Some(""),
+ None,
+ Some("Insert Shape")
+ ));
+}
+
+#[test]
+fn name_identity_cannot_be_rescued_by_matching_description() {
+ let mut entry = entry();
+ entry.name = Some("Primary".into());
+ entry.description = Some("Generic".into());
+
+ assert!(identity_matches(&entry, Some("Primary"), None, None));
+ assert!(identity_matches(&entry, None, Some("Primary"), None));
+ assert!(!identity_matches(
+ &entry,
+ Some("Other"),
+ None,
+ Some("Primary")
+ ));
+ assert!(!identity_matches(&entry, Some("Generic"), None, None));
+}
+
+#[test]
+fn value_identity_cannot_be_rescued_by_matching_name_when_value_mismatches() {
+ let mut entry = entry();
+ entry.value = Some("On".into());
+
+ assert!(identity_matches(&entry, None, Some("On"), None));
+ assert!(identity_matches(&entry, Some("On"), None, None));
+ assert!(!identity_matches(&entry, Some("On"), Some("Off"), None));
+}
diff --git a/crates/macos/src/tree/resolve_tests.rs b/crates/macos/src/tree/resolve_tests.rs
index d4db21c4e..b120328b5 100644
--- a/crates/macos/src/tree/resolve_tests.rs
+++ b/crates/macos/src/tree/resolve_tests.rs
@@ -11,6 +11,7 @@ fn entry(
role: "cell".into(),
name: Some("Investors".into()),
value: None,
+ description: None,
states: vec![],
bounds: None,
bounds_hash,
@@ -86,6 +87,38 @@ fn no_bounds_source_window_refs_require_scoped_path_resolution() {
assert!(requires_scoped_path_resolution(&absolute_drill));
}
+#[test]
+fn scoped_path_retry_fails_closed_when_scope_is_unresolved() {
+ let no_bounds_entry = entry(None, Some("w-10"), Some("Freeform"), None);
+
+ assert!(should_retry_scoped_path_resolution(&no_bounds_entry));
+ assert!(should_retry_scoped_path_resolution(&description_entry()));
+ assert!(!should_retry_scoped_path_resolution(&entry(
+ Some(42),
+ Some("w-10"),
+ Some("Freeform"),
+ None
+ )));
+}
+
+#[test]
+fn scoped_path_retry_fails_closed_for_blank_identity_without_bounds() {
+ let mut blank = entry(None, Some("w-10"), Some("Freeform"), None);
+ blank.name = None;
+
+ assert!(should_retry_scoped_path_resolution(&blank));
+}
+
+#[test]
+fn broad_search_requires_bounds_or_meaningful_identity() {
+ let mut blank = entry(None, None, None, None);
+ blank.name = None;
+
+ assert!(!can_use_broad_search(&blank));
+ assert!(can_use_broad_search(&description_entry()));
+ assert!(can_use_broad_search(&entry(Some(42), None, None, None)));
+}
+
#[test]
fn source_window_number_parses_window_ids_only() {
assert_eq!(
@@ -101,3 +134,11 @@ fn source_window_number_parses_window_ids_only() {
None
);
}
+
+fn description_entry() -> RefEntry {
+ let mut entry = entry(None, Some("w-10"), Some("Freeform"), None);
+ entry.role = "button".into();
+ entry.name = None;
+ entry.description = Some("Insert Text Box".into());
+ entry
+}
diff --git a/docs/phases.md b/docs/phases.md
index 3ffa12985..64356ab71 100644
--- a/docs/phases.md
+++ b/docs/phases.md
@@ -308,7 +308,7 @@ Snapshot refs persist through `RefStore` under `~/.agent-desktop/snapshots/{snap
**Progressive Skeleton Traversal:**
- `--skeleton` flag clamps depth to `min(max_depth, 3)`, annotates truncated containers with `children_count` for agent discovery
-- `--root <REF>` flag starts traversal from a previously-discovered ref instead of window root; `--snapshot <id>` selects the ref namespace
+- `--root <REF>` flag starts traversal from a previously-discovered ref instead of window root; `--snapshot <snapshot_id>` selects the ref namespace
- Named or described containers at skeleton boundary receive refs as drill-down targets (with empty `available_actions`)
- Scoped invalidation: re-drilling a ref replaces only that ref's subtree refs, preserving all others
- Core modules: `ref_alloc.rs` (canonical `allocate_refs` + `RefAllocConfig`), `snapshot_ref.rs` (drill-down flow that delegates allocation to `ref_alloc`)
diff --git a/skills/agent-desktop/SKILL.md b/skills/agent-desktop/SKILL.md
index 22be01543..8427a3c0d 100644
--- a/skills/agent-desktop/SKILL.md
+++ b/skills/agent-desktop/SKILL.md
@@ -87,7 +87,7 @@ Use **progressive skeleton traversal** as the default approach. It reduces token
- In skeleton mode, named/described containers at truncation boundary also get refs (drill-down targets with empty `available_actions`)
- Static text, groups, containers remain in tree for context but have no ref
- Refs are deterministic within a snapshot but NOT stable across snapshots if UI changed
-- Every snapshot returns `snapshot_id`; ref-consuming commands accept `--snapshot <id>`
+- Every snapshot returns `snapshot_id`; ref-consuming commands accept `--snapshot <snapshot_id>`
- `last_refmap.json` is only a latest-snapshot inspection artifact. The command path uses snapshot-scoped storage.
- After any action that changes UI, re-drill the affected region or re-snapshot
- **Scoped invalidation:** re-drilling `--root @e3` only replaces refs from @e3's previous drill — refs from other regions and the skeleton itself are preserved
@@ -129,18 +129,18 @@ agent-desktop snapshot --app "App" -i # Full tree (simple
agent-desktop snapshot --app "App" --surface menu -i # Surface snapshot
agent-desktop screenshot --app "App" out.png # PNG screenshot
agent-desktop find --app "App" --role button # Search elements
-agent-desktop get @e1 --snapshot s... --property text # Read element property
-agent-desktop is @e1 --snapshot s... --property enabled # Check element state
+agent-desktop get @e1 --snapshot <snapshot_id> --property text # Read element property
+agent-desktop is @e1 --snapshot <snapshot_id> --property enabled # Check element state
agent-desktop list-surfaces --app "App" # Available surfaces
```
### Interaction
```
-agent-desktop click @e5 --snapshot s... # AX-first click, no cursor move by default
+agent-desktop click @e5 --snapshot <snapshot_id> # AX-first click, no cursor move by default
agent-desktop double-click @e3 # AXOpen; physical double-click uses mouse-click --count 2
agent-desktop triple-click @e2 # Physical triple-click uses mouse-click --count 3
agent-desktop right-click @e5 # Right-click; menu returned when verified
-agent-desktop type @e2 --snapshot s... "hello" # Headless AX text insertion when supported
+agent-desktop type @e2 --snapshot <snapshot_id> "hello" # Headless AX text insertion when supported
agent-desktop set-value @e2 "new value" # Set value directly
agent-desktop clear @e2 # Clear element value
agent-desktop focus @e2 # Set keyboard focus
@@ -205,7 +205,7 @@ agent-desktop clipboard-clear # Clear clipboard
### Wait
```
agent-desktop wait 1000 # Pause 1 second
-agent-desktop wait --element @e5 --snapshot s... --timeout 5000 # Wait for element
+agent-desktop wait --element @e5 --snapshot <snapshot_id> --timeout 5000 # Wait for element
agent-desktop wait --window "Title" # Wait for window
agent-desktop wait --text "Done" --app "App" # Wait for text
agent-desktop wait --menu --app "App" # Wait for menu surface
diff --git a/skills/agent-desktop/references/commands-interaction.md b/skills/agent-desktop/references/commands-interaction.md
index 3673ec774..3bc268f41 100644
--- a/skills/agent-desktop/references/commands-interaction.md
+++ b/skills/agent-desktop/references/commands-interaction.md
@@ -4,7 +4,7 @@ Commands for modifying UI state — clicking, typing, selecting, scrolling, and
Ref-based actions are headless by default. They try semantic accessibility operations and do not silently steal focus, move the cursor, synthesize keyboard input, or use the pasteboard. Physical/headed interaction is reserved for explicit `focus`, `press`, `hover`, `drag`, and `mouse-*` commands or an explicit FFI policy. The `type` command has an explicit focus-fallback tier for callers that opt into focus changes while still forbidding cursor movement; the default CLI path remains AX-value-first and headless.
-All ref-based interaction commands accept `--snapshot <id>`. Omit it for the latest saved snapshot, or pass the `snapshot_id` returned by `snapshot` to keep scripts pinned to the exact ref map they observed.
+All ref-based interaction commands accept `--snapshot <snapshot_id>`. Omit it for the latest saved snapshot, or pass the `snapshot_id` returned by `snapshot` to keep scripts pinned to the exact ref map they observed.
## Click Actions
@@ -13,7 +13,7 @@ Click commands use semantic AX activation first. In the default headless policy,
### click
```bash
agent-desktop click @e5
-agent-desktop click @e5 --snapshot s...
+agent-desktop click @e5 --snapshot <snapshot_id>
```
Primary activation. Tries verified AXPress > AXConfirm > AXOpen > AXPick > child activation > selection/value relays > custom actions > ancestor activation. Focus-stealing and coordinate fallback steps are not used by the default ref command path.
diff --git a/skills/agent-desktop/references/commands-observation.md b/skills/agent-desktop/references/commands-observation.md
index 6e59c4177..3a23f033a 100644
--- a/skills/agent-desktop/references/commands-observation.md
+++ b/skills/agent-desktop/references/commands-observation.md
@@ -13,7 +13,7 @@ agent-desktop snapshot --app "App" --surface menu
agent-desktop snapshot --app "App" --window-id "w-1234"
agent-desktop snapshot --app "App" -i --compact
agent-desktop snapshot --app "App" --skeleton -i
-agent-desktop snapshot --root @e12 --snapshot s8f3k2p9 -i
+agent-desktop snapshot --root @e12 --snapshot <snapshot_id> -i
```
| Flag | Default | Description |
@@ -27,7 +27,7 @@ agent-desktop snapshot --root @e12 --snapshot s8f3k2p9 -i
| `--surface` | window | Target surface: `window`, `focused`, `menu`, `menubar`, `sheet`, `popover`, `alert` |
| `--skeleton` | false | Clamp traversal to depth 3 and add `children_count` to truncated containers |
| `--root <REF>` | | Drill down from a ref discovered in a previous snapshot. Cannot be combined with `--surface` |
-| `--snapshot <ID>` | latest | Snapshot ID to use when resolving `--root` |
+| `--snapshot <snapshot_id>` | latest | Snapshot ID to use when resolving `--root` |
**Output structure:**
```json
@@ -78,7 +78,7 @@ agent-desktop snapshot --root @e12 --snapshot s8f3k2p9 -i
- Starts tree traversal from the given ref instead of the window root
- Merges new refs into the existing refmap with scoped invalidation: only refs from the previous drill of the same root are replaced, leaving all other refs intact
- Cannot be combined with `--surface`
-- Use `--snapshot <ID>` when drilling from a specific snapshot rather than the latest snapshot pointer
+- Use `--snapshot <snapshot_id>` when drilling from a specific snapshot rather than the latest snapshot pointer
**Progressive drill-down workflow:**
```bash
@@ -86,10 +86,10 @@ agent-desktop snapshot --root @e12 --snapshot s8f3k2p9 -i
agent-desktop snapshot --skeleton --app Slack -i
# Step 2: Drill into a discovered region
-agent-desktop snapshot --root @e3 --snapshot s8f3k2p9 -i
+agent-desktop snapshot --root @e3 --snapshot <snapshot_id> -i
# Step 3: Re-drill same region (scoped invalidation replaces @e3's refs)
-agent-desktop snapshot --root @e3 --snapshot s8f3k2p9 -i
+agent-desktop snapshot --root @e3 --snapshot <snapshot_id> -i
```
**Tips:**
@@ -146,7 +146,7 @@ Read a specific property from an element.
```bash
agent-desktop get @e1 --property text
-agent-desktop get @e1 --snapshot s8f3k2p9 --property text
+agent-desktop get @e1 --snapshot <snapshot_id> --property text
agent-desktop get @e2 --property value
agent-desktop get @e3 --property bounds
agent-desktop get @e4 --property role
@@ -169,7 +169,7 @@ Check a boolean state on an element.
```bash
agent-desktop is @e1 --property visible
-agent-desktop is @e1 --snapshot s8f3k2p9 --property visible
+agent-desktop is @e1 --snapshot <snapshot_id> --property visible
agent-desktop is @e2 --property enabled
agent-desktop is @e3 --property checked
agent-desktop is @e4 --property focused
diff --git a/skills/agent-desktop/references/commands-system.md b/skills/agent-desktop/references/commands-system.md
index 5b50fb68f..35577d0d9 100644
--- a/skills/agent-desktop/references/commands-system.md
+++ b/skills/agent-desktop/references/commands-system.md
@@ -168,7 +168,7 @@ Pauses for N milliseconds. Use between actions that need time to settle.
### wait (element)
```bash
-agent-desktop wait --element @e5 --snapshot s... --timeout 5000 --app "App"
+agent-desktop wait --element @e5 --snapshot <snapshot_id> --timeout 5000 --app "App"
```
Blocks until the element ref appears in the accessibility tree. Useful after triggering UI changes.
@@ -213,10 +213,10 @@ Blocks until the menu surface is dismissed.
### batch
```bash
-agent-desktop batch '[{"command":"click","args":{"ref_id":"@e1"}},{"command":"wait","args":{"ms":500}},{"command":"click","args":{"ref_id":"@e2"}}]'
+agent-desktop batch '[{"command":"click","args":{"ref_id":"@e1","snapshot":"<snapshot_id>"}},{"command":"wait","args":{"ms":500}},{"command":"click","args":{"ref_id":"@e2","snapshot":"<snapshot_id>"}}]'
agent-desktop batch '[...]' --stop-on-error
```
-Execute multiple commands in sequence from a JSON array. Each entry has `command` (string) and `args` (object).
+Execute multiple commands in sequence from a JSON array. Each entry has `command` (string) and `args` (object). Use `args`, not `params`. For ref-consuming commands, pass the output `snapshot_id` as the `snapshot` field.
Batch uses the same typed `Commands` enum, command policy preflight, permission report, and dispatch path as the CLI. Unknown fields are rejected instead of being silently ignored. Nested `batch` is rejected.
@@ -227,9 +227,9 @@ Batch uses the same typed `Commands` enum, command policy preflight, permission
**Batch format:**
```json
[
- { "command": "click", "args": { "ref_id": "@e1", "snapshot": "s8f3k2p9" } },
+ { "command": "click", "args": { "ref_id": "@e1", "snapshot": "<snapshot_id>" } },
{ "command": "wait", "args": { "ms": 500 } },
- { "command": "type", "args": { "ref_id": "@e2", "snapshot": "s8f3k2p9", "text": "hello" } }
+ { "command": "type", "args": { "ref_id": "@e2", "snapshot": "<snapshot_id>", "text": "hello" } }
]
```
@@ -251,7 +251,7 @@ Batch uses the same typed `Commands` enum, command policy preflight, permission
```json
[
{ "command": "snapshot", "args": { "app": "Slack", "skeleton": true, "interactive_only": true } },
- { "command": "snapshot", "args": { "app": "Slack", "root": "@e3", "snapshot": "s8f3k2p9", "interactive_only": true } }
+ { "command": "snapshot", "args": { "app": "Slack", "root": "@e3", "snapshot": "<snapshot_id>", "interactive_only": true } }
]
```
diff --git a/skills/agent-desktop/references/macos.md b/skills/agent-desktop/references/macos.md
index 951ce5d7c..986c1e64f 100644
--- a/skills/agent-desktop/references/macos.md
+++ b/skills/agent-desktop/references/macos.md
@@ -231,7 +231,7 @@ Large apps (Xcode, Safari with many tabs) can have deep trees.
- Use `-i` to filter to interactive elements only
- Use `--max-depth 5` to limit depth
- Use `--compact` to remove empty structural nodes
-- Use `--skeleton` for dense apps, then `snapshot --root @ref --snapshot <id>` to drill down
+- Use `--skeleton` for dense apps, then `snapshot --root @ref --snapshot <snapshot_id>` to drill down
- Target a specific window with `--window-id`
- Use `find` instead of full snapshot when you know what you're looking for
diff --git a/skills/agent-desktop/references/workflows.md b/skills/agent-desktop/references/workflows.md
index e9439813d..9b920add2 100644
--- a/skills/agent-desktop/references/workflows.md
+++ b/skills/agent-desktop/references/workflows.md
@@ -22,7 +22,7 @@ The recommended approach for Electron apps (Slack, VS Code, Discord) and any app
```bash
# 1. Get skeleton overview — shallow 3-level map with children_count hints
agent-desktop snapshot --skeleton --app "Slack" -i --compact
-# Keep snapshot_id = s8f...
+# Keep snapshot_id = <snapshot_id>
# Output shows regions like:
# @e1 = group "Workspaces" (children_count: 4)
# @e2 = group "Channels" (children_count: 42)
@@ -30,19 +30,19 @@ agent-desktop snapshot --skeleton --app "Slack" -i --compact
# @e4 = button "New Message" ← interactive elements at top levels still get refs
# 2. Identify the region you need and drill into it
-agent-desktop snapshot --root @e2 --snapshot s8f... -i --compact
+agent-desktop snapshot --root @e2 --snapshot <snapshot_id> -i --compact
# Now you see all 42 children inside "Channels" with full refs
# 3. Act on an element found in the drill-down
-agent-desktop click @e18 --snapshot s8f... # Click "general" channel
+agent-desktop click @e18 --snapshot <snapshot_id> # Click "general" channel
# 4. Re-drill the same or a different region to verify / continue
-agent-desktop snapshot --root @e3 --snapshot s8f... -i --compact
+agent-desktop snapshot --root @e3 --snapshot <snapshot_id> -i --compact
# Scoped invalidation: only @e3's previous refs are replaced
# @e2's drill-down refs and the skeleton refs are preserved
# 5. Drill into another region as needed — refs accumulate
-agent-desktop snapshot --root @e1 --snapshot s8f... -i --compact
+agent-desktop snapshot --root @e1 --snapshot <snapshot_id> -i --compact
# Now you have refs from skeleton + @e2 drill + @e3 drill + @e1 drill
```
@@ -58,22 +58,22 @@ agent-desktop snapshot --root @e1 --snapshot s8f... -i --compact
```bash
# For simple apps, full snapshot is fine
agent-desktop snapshot --app "System Settings" -i
-# Keep snapshot_id = s8f...
+# Keep snapshot_id = <snapshot_id>
# For dense apps, use skeleton first to find the form region, then drill
# agent-desktop snapshot --skeleton --app "System Settings" -i --compact
-# agent-desktop snapshot --root @e5 --snapshot s8f... -i --compact
+# agent-desktop snapshot --root @e5 --snapshot <snapshot_id> -i --compact
# Found: @e3 = "Computer Name" textfield, @e5 = "Local Hostname" textfield
# Clear and fill each field
-agent-desktop clear @e3 --snapshot s8f...
-agent-desktop type @e3 --snapshot s8f... "My MacBook Pro"
-agent-desktop clear @e5 --snapshot s8f...
-agent-desktop type @e5 --snapshot s8f... "my-macbook-pro"
+agent-desktop clear @e3 --snapshot <snapshot_id>
+agent-desktop type @e3 --snapshot <snapshot_id> "My MacBook Pro"
+agent-desktop clear @e5 --snapshot <snapshot_id>
+agent-desktop type @e5 --snapshot <snapshot_id> "my-macbook-pro"
# Click the save/apply button
-agent-desktop click @e8 --snapshot s8f...
+agent-desktop click @e8 --snapshot <snapshot_id>
# Verify success — re-snapshot or re-drill
agent-desktop snapshot --app "System Settings" -i
@@ -86,12 +86,12 @@ agent-desktop snapshot --app "System Settings" -i
agent-desktop snapshot --app "TextEdit" --surface menubar -i
# Found: @e1 = "File" menuitem
-agent-desktop click @e1 --snapshot s8f...
+agent-desktop click @e1 --snapshot <snapshot_id>
agent-desktop wait --menu --app "TextEdit"
agent-desktop snapshot --app "TextEdit" --surface menu -i
# Found: @e5 = "Save As..." menuitem
-agent-desktop click @e5 --snapshot s9a...
+agent-desktop click @e5 --snapshot <snapshot_id>
# 2. Wait for the dialog, then snapshot the SHEET surface (not the full window)
agent-desktop wait --window "Save"
@@ -108,7 +108,7 @@ agent-desktop right-click @e3
agent-desktop snapshot --app "Finder" --surface menu -i
# 3. Click the desired menu item
-agent-desktop click @e7 --snapshot s8f...
+agent-desktop click @e7 --snapshot <snapshot_id>
# 4. Wait for menu to close
agent-desktop wait --menu-closed --app "Finder" --timeout 2000
@@ -125,10 +125,10 @@ agent-desktop snapshot --app "TextEdit" --surface sheet -i
# For alerts: --surface alert | For popovers: --surface popover
# Fill dialog fields
-agent-desktop type @e2 --snapshot s8f... "my-document.txt"
+agent-desktop type @e2 --snapshot <snapshot_id> "my-document.txt"
# Click OK/Save
-agent-desktop click @e5 --snapshot s8f...
+agent-desktop click @e5 --snapshot <snapshot_id>
# After dialog closes, snapshot the window again for fresh refs
agent-desktop snapshot --app "TextEdit" -i
@@ -144,17 +144,17 @@ agent-desktop snapshot --skeleton --app "App" -i --compact
# Found: @e2 = group "Content" (children_count: 200)
# 2. Drill into the region to get a scroll area ref
-agent-desktop snapshot --root @e2 --snapshot s8f... -i --compact
+agent-desktop snapshot --root @e2 --snapshot <snapshot_id> -i --compact
# Found: @e8 = scroll area
# 3. Scroll and search in a loop
-agent-desktop scroll @e8 --snapshot s8f... --direction down --amount 5
+agent-desktop scroll @e8 --snapshot <snapshot_id> --direction down --amount 5
agent-desktop find --app "App" --name "Target Item"
# If no matches, scroll again
-agent-desktop scroll @e8 --snapshot s8f... --direction down --amount 5
+agent-desktop scroll @e8 --snapshot <snapshot_id> --direction down --amount 5
agent-desktop find --app "App" --name "Target Item"
# Found: @e14 = "Target Item"
-agent-desktop click @e14 --snapshot s9a...
+agent-desktop click @e14 --snapshot <snapshot_id>
```
## Pattern: Tab Through Fields
@@ -199,7 +199,7 @@ agent-desktop drag --from @e3 --to-xy 500,400 --duration 500
```bash
# After triggering a long operation:
-agent-desktop click @e5 --snapshot s8f... # "Download" button
+agent-desktop click @e5 --snapshot <snapshot_id> # "Download" button
# Wait for completion text
agent-desktop wait --text "Download complete" --app "App" --timeout 30000
@@ -219,7 +219,7 @@ agent-desktop snapshot --app "Calculator" -i
# Dense app → skeleton first
# agent-desktop launch "Slack"
# agent-desktop snapshot --skeleton --app "Slack" -i --compact
-# agent-desktop snapshot --root @e2 --snapshot s8f... -i --compact
+# agent-desktop snapshot --root @e2 --snapshot <snapshot_id> -i --compact
# ... perform automation ...
@@ -258,9 +258,9 @@ agent-desktop uncheck @e6 # No-op if already unchecked
```bash
# Run multiple commands atomically
agent-desktop batch '[
- {"command":"click","args":{"ref_id":"@e1","snapshot":"s8f..."}},
+ {"command":"click","args":{"ref_id":"@e1","snapshot":"<snapshot_id>"}},
{"command":"wait","args":{"ms":200}},
- {"command":"type","args":{"ref_id":"@e2","snapshot":"s8f...","text":"hello"}},
+ {"command":"type","args":{"ref_id":"@e2","snapshot":"<snapshot_id>","text":"hello"}},
{"command":"press","args":{"combo":"return"}}
]' --stop-on-error
```
diff --git a/src/cli_args.rs b/src/cli_args.rs
index 9f5dd7f91..2fcf1e10e 100644
--- a/src/cli_args.rs
+++ b/src/cli_args.rs
@@ -83,7 +83,11 @@ pub(crate) struct SnapshotArgs {
pub skeleton: bool,
#[arg(long, help = "Start traversal from this ref instead of window root")]
pub root: Option<String>,
- #[arg(long, help = "Snapshot ID to use when resolving --root")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID to use when resolving --root"
+ )]
pub snapshot: Option<String>,
}
@@ -158,7 +162,11 @@ pub(crate) struct ScreenshotArgs {
pub(crate) struct GetArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(
long,
@@ -174,7 +182,11 @@ pub(crate) struct GetArgs {
pub(crate) struct IsArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(
long,
@@ -192,6 +204,7 @@ pub(crate) struct RefArgs {
pub ref_id: String,
#[arg(
long = "snapshot",
+ value_name = "SNAPSHOT_ID",
help = "Snapshot ID returned by snapshot; omit to use latest"
)]
#[serde(rename = "snapshot", alias = "snapshot_id")]
diff --git a/src/cli_args_actions.rs b/src/cli_args_actions.rs
index 7cf99906e..c2f38b324 100644
--- a/src/cli_args_actions.rs
+++ b/src/cli_args_actions.rs
@@ -22,7 +22,11 @@ fn default_scroll_direction() -> String {
pub(crate) struct TypeArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(value_name = "TEXT", allow_hyphen_values = true, help = "Text to type")]
pub text: String,
@@ -33,7 +37,11 @@ pub(crate) struct TypeArgs {
pub(crate) struct SetValueArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(
value_name = "VALUE",
@@ -48,7 +56,11 @@ pub(crate) struct SetValueArgs {
pub(crate) struct SelectArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(value_name = "VALUE", help = "Option to select")]
pub value: String,
@@ -59,7 +71,11 @@ pub(crate) struct SelectArgs {
pub(crate) struct ScrollArgs {
#[arg(value_name = "REF", help = "Element ref from snapshot (@e1, @e2 ...)")]
pub ref_id: String,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(
long,
@@ -100,7 +116,11 @@ pub(crate) struct KeyComboArgs {
pub(crate) struct HoverArgs {
#[arg(value_name = "REF", help = "Element ref to hover over")]
pub ref_id: Option<String>,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(long, help = "Absolute coordinates as x,y")]
pub xy: Option<String>,
@@ -119,7 +139,11 @@ pub(crate) struct DragCliArgs {
pub to: Option<String>,
#[arg(long, name = "to-xy", help = "Destination coordinates as x,y")]
pub to_xy: Option<String>,
- #[arg(long, help = "Snapshot ID returned by snapshot; omit to use latest")]
+ #[arg(
+ long,
+ value_name = "SNAPSHOT_ID",
+ help = "Snapshot ID returned by snapshot; omit to use latest"
+ )]
pub snapshot: Option<String>,
#[arg(long, help = "Drag duration in milliseconds")]
pub duration: Option<u64>,
diff --git a/src/cli_args_system.rs b/src/cli_args_system.rs
index b1e38bea2..5e195821c 100644
--- a/src/cli_args_system.rs
+++ b/src/cli_args_system.rs
@@ -103,6 +103,7 @@ pub(crate) struct WaitArgs {
pub element: Option<String>,
#[arg(
long,
+ value_name = "SNAPSHOT_ID",
help = "Snapshot ID returned by snapshot for --element waits; omit to use latest"
)]
pub snapshot: Option<String>,
diff --git a/src/help_after.txt b/src/help_after.txt
index 016ae3d6c..73b6c8d74 100644
--- a/src/help_after.txt
+++ b/src/help_after.txt
@@ -63,7 +63,7 @@ CLIPBOARD
WAIT
wait [ms] Pause for N milliseconds
wait --element <ref> Block until element appears (--timeout ms)
- wait --element <ref> --snapshot <id> Wait against a specific snapshot refmap
+ wait --element <ref> --snapshot <snapshot_id> Wait against a specific snapshot refmap
wait --window <title> Block until window appears
wait --text <text> Block until text appears in app
wait --menu --app <app> Block until a menu surface is open
@@ -82,7 +82,7 @@ BATCH
REF IDs
snapshot assigns @e1, @e2, ... to interactive elements in depth-first order.
Use a ref wherever <ref> appears. Refs are snapshot-scoped. Pass
- --snapshot <id> to pin a command to a known snapshot; when omitted,
+ --snapshot <snapshot_id> to pin a command to a known snapshot; when omitted,
ref commands use the latest saved snapshot. Run snapshot again after UI changes.
KEY COMBOS
@@ -106,4 +106,4 @@ EXAMPLES
agent-desktop resize-window --app TextEdit --width 800 --height 600
agent-desktop mouse-click --xy 500,300
agent-desktop wait --text "Loading complete" --app Safari --timeout 5000
- agent-desktop batch '[{"command":"click","args":{"ref_id":"@e1"}}]'
+ agent-desktop batch '[{"command":"click","args":{"ref_id":"@e1","snapshot":"<snapshot_id>"}}]'