Permission Issues
PERM_DENIED Error
Symptom: Commands return:Add your terminal app
Click the + button and add:
- Terminal.app
- iTerm.app
- VS Code (if running from integrated terminal)
- Any other terminal you’re using
Request Permission Programmatically
Trigger the system permission dialog:This will show a system prompt to grant Accessibility access. You still need to manually approve it in System Settings.
Check Permission Status
Stale Reference Errors
STALE_REF Error
Symptom:Why Refs Go Stale
UI Changed
Window was resized, elements added/removed, or content scrolled
App Closed
The application was closed or crashed
Window Changed
Switched to a different window or tab
Long Delay
Too much time passed between snapshot and action (state drift)
Best Practices
- Re-snapshot after UI changes (button clicks, menu selections, page loads)
- Use
waitcommands before snapshots to let UI settle - Keep snapshot → action cycles tight (minimize time between them)
- Handle STALE_REF in agent logic (auto-retry with new snapshot)
Element Not Found
ELEMENT_NOT_FOUND Error
Symptom:Element doesn't exist
Element doesn't exist
The element you’re looking for isn’t in the UI.Solution: Take a snapshot and inspect the tree:
Wrong role or name
Wrong role or name
You’re searching for the wrong role or name.Solution: Use
find with different criteria:Element not interactive
Element not interactive
Static text, labels, and containers don’t get refs.Solution: Look for nearby interactive elements (buttons, textfields) or use
snapshot without -i to see static elements:Element in different surface
Element in different surface
The element is in a menu, sheet, popover, or alert that isn’t focused.Solution: Use
--surface to capture the right surface:Application Issues
APP_NOT_FOUND Error
Symptom:- Launch app first
- Check app name
- Use bundle ID
App Has No Windows
Some apps launch without windows (e.g., background apps, menu bar apps). Solution: Check if app actually has windows:Action Failures
ACTION_FAILED Error
Symptom:- Element is disabled: Check element state in snapshot (
"states": ["enabled": false]) - Element is not visible: Element may be off-screen or hidden
- Action not supported: Some elements don’t support certain actions (e.g., can’t click static text)
- Timing issue: UI wasn’t ready. Add
waitbefore action:
ACTION_NOT_SUPPORTED Error
The platform doesn’t support the requested action. Example:Timeout Errors
TIMEOUT Error
Symptom:Performance Issues
Snapshot Takes Too Long
Symptom:snapshot takes >2 seconds
Solutions:
Use -i flag
Reduce max-depth
Use compact mode
Target specific window
Large JSON Output
For apps with deep trees (Xcode, Chrome with many tabs):Build & Development Issues
Clippy Warnings
Symptom:cargo clippy reports warnings
Solution: Fix all warnings. CI requires zero warnings:
Binary Size >15MB
Symptom: Release binary exceeds 15MB Solution: Check release profile inCargo.toml:
Core Depends on Platform Crate
Symptom: CI fails with “core depends on platform crate” Solution: Core must never importmacos, windows, or linux crates. Verify:
agent-desktop-macos, agent-desktop-windows, or agent-desktop-linux.
Tests Fail Without Permission
Symptom:cargo test fails on macOS
Solution: Grant Accessibility permission to your Rust test runner:
- Run
cargo testonce to trigger permission dialog - Go to System Settings > Privacy & Security > Accessibility
- Add the test runner (usually
rust-analyzerorcargo) - Re-run tests
Error Code Reference
| Code | Meaning | Common Causes | Recovery |
|---|---|---|---|
PERM_DENIED | Accessibility permission not granted | macOS permission not set | Grant in System Settings |
ELEMENT_NOT_FOUND | No element matched ref/query | Wrong role, name, or element doesn’t exist | Use snapshot to inspect tree |
APP_NOT_FOUND | Application not running or no windows | App not launched or wrong name | Launch app or check name with list-apps |
STALE_REF | Ref is from previous snapshot | UI changed since snapshot | Run snapshot again to refresh refs |
ACTION_FAILED | OS rejected the action | Element disabled, hidden, or invalid | Check element state, add wait |
ACTION_NOT_SUPPORTED | Platform doesn’t support action | Windows/Linux in Phase 1 | Check platform support |
WINDOW_NOT_FOUND | Window doesn’t exist | Window closed or wrong ID | Use list-windows to verify |
TIMEOUT | Wait condition not met | Condition never became true | Increase timeout or change condition |
INVALID_ARGS | Invalid argument values | Wrong flag format or value | Check --help for correct syntax |
PLATFORM_NOT_SUPPORTED | Operation not available on this OS | Running on unsupported platform | Use supported platform (macOS for Phase 1) |
INTERNAL | Unexpected internal error | Bug or OS API failure | Report issue with full error details |
Exit Codes
- 0 — Success (check JSON
"ok": true) - 1 — Structured error (JSON with error code on stdout)
- 2 — Argument parse error (invalid command/flags)
Logging & Debugging
Enable Debug Logs
error, warn, info, debug, trace
Inspect RefMap
Refs are stored at~/.agent-desktop/last_refmap.json:
Check JSON Output
Pipe tojq for pretty-printing:
Getting Help
Built-in Help
GitHub Issues
Report bugs or request features at github.com/lahfir/agent-desktop
Status Command
Common Patterns
Reliable Click
Wait for Window
Handle Menu Interaction
Next Steps
Architecture
Deep dive into workspace structure and design patterns
Development
Build, test, and contribute to agent-desktop