JSON output
Every command prints exactly one JSON envelope on a single line of standard output. Only --help, --version, and a bare agent-desktop print text instead. The contract version is 2.7. Log output goes to standard error, so a parser can read standard output as one JSON value.
Envelope
| Field | Type | Meaning |
|---|---|---|
version | string | Contract version. Currently "2.7". |
ok | boolean | true when the command returned a result, false when it returned an error. |
command | string | The command name, such as click or session. |
data | object | The result. Present only when ok is true. |
error | object | The failure. Present only when ok is false. Its fields are in Errors and recovery. |
An error envelope has error and no data:
ok: true means the command returned a delivered or already-satisfied result. It does not mean the application effect happened. Read the result, or observe again, to verify. See the observe, act, verify loop.
Omission rules
- A typed field that is
Noneis omitted, and so is an empty array. An error without a suggestion has nosuggestionkey, and a node without children has nochildrenkey. - Snapshot node bounds are omitted unless you pass
--include-bounds. - Some commands build their
databy hand and writenullor[]for an absent value.session listwrites"ended_at": nullfor an open session, andfindmatches write"value": nulland"states": []. Treat a missing key,null, and an empty array the same way. - Ignore keys you do not know. New optional fields can appear without a version change.
- Snapshot
data.windowappears when a window owns the observation. On macOS, application-ownedmenuandmenubarsnapshots omit it.
Application-owned snapshots
On macOS, menu and menubar snapshots belong to the application, so data.app identifies the owner and data.window is absent. This remains true when a --window-id selects which app to observe or when --root drills into a ref from that surface. Window-owned snapshots keep data.window.
Where data lives
ref_count and tree sit inside data, never at the top level. This window-owned snapshot of GNOME Calculator is trimmed to one branch:
A snapshot that runs out of budget still returns ok: true, with "complete": false, "truncated": true, nodes_observed, and "subtree_truncated": true on each cut node. Read data.complete before you treat a tree as whole. Node fields are in Snapshots and refs, and partial observations in Skeleton and drill-down.
Action results and disposition
A ref action such as click, type, or toggle returns data.action and data.disposition, and can add steps (each mechanism tried), post_state, surfaces (surfaces open once the action settled), and details. When the read of surfaces fails, details.surfaces is "not_read": an absent surfaces then does not mean that no overlay opened. disposition has two fields, delivery and retry; on success, delivery is delivered_verified, delivered_unverified, or not_delivered (already satisfied). What each value proves, and when a retry is safe, is in Errors and recovery.
Post-action observation
When a ref action returns delivery_uncertain with a post-action wait selector, error.details.post_action_observation records a read-only observation of the original process. Application-owned refs keep their source surface. Window-owned refs observe their original pinned window, including refs captured from sheet, alert, popover, focused, or a window-owned menu such as a Linux menu. This lets a closed overlay be observed without treating the parent window as absent. The action is never repeated, and its original error and unsafe retry disposition stay unchanged. Even expected_state_observed does not prove that the action caused the state. Observation uses --wait-timeout separately from the action timeout.
| Field | Meaning |
|---|---|
kind | Always post_action_observation. |
selector, expected | Requested selector and present or absent. |
surface | The observed scope: the application-owned source surface, or window for a window-owned ref. |
process_identity | Original pid and process_instance; the instance can be null for identity_unavailable. |
elapsed_ms | Time spent observing after the action returned. |
source_window_id | Original window ID, when the ref has one. |
selector_matches | Observed selector result, when available; absence requires a complete read. |
process_state | Last observed unresponsive, exited, or crashed state. running is never emitted. |
last_observation_error | Last observation error's code and message, when available. |
outcome | One of the outcomes below. |
| Outcome | Meaning |
|---|---|
expected_state_observed | The expected selector state was observed, or the original window or surface was confirmed absent for an absence wait. |
process_exited | The original process exited; this does not establish the action's effect. |
process_crashed | The platform reported that the original process crashed. |
owner_unavailable | The original surface owner remained unavailable without confirmed process exit. |
observation_failed | A terminal read error stopped observation; inspect last_observation_error. |
timed_out | The wait budget expired without observing the expected state, including when transient read errors persisted through the last poll. last_observation_error may hold the last error. |
identity_unavailable | The ref has no usable process generation, so observation was skipped. |
OperationReport
Thirteen commands return the adapter's own report as data: mouse-click, mouse-move, mouse-wheel, hover, drag, clipboard-set, clipboard-clear, close-app, move-window, resize-window, minimize, maximize, and restore. The report is the action result fields (action, disposition, and steps, post_state, surfaces, or details when present) plus a target. The command then adds the echoed request fields, such as from and to for drag, without overwriting any field the report already has.
target.kind | Fields |
|---|---|
window | id, title, process |
app | name, process |
pointer | point |
drag | from, to |
clipboard | none |
The adapter fills in the identity it validated and used. A pointer target is the coordinate it dispatched to and does not prove which application received the input. Request fields such as x, y, count, width, or app echo your request; they are not observed state. Window reports name their readback in details.verification_scope (window_size, window_position, window_minimized_state, or window_maximized_state). There are no clicked, moved, closed, or similar flags, because a flag that every successful call carried proved nothing.
A failed --wait-for after a delivered operation keeps the operation's own delivery in error.disposition and carries the report under error.details.after_action.
Find results
find returns one of three shapes, depending on the result-shaping flag. The flags are in find.
| Flag | data |
|---|---|
none, or --limit N | matches, total_matches, truncated |
--first, --last, --nth N | match (an object, or null when nothing matched) |
--count | count |
Each match carries ref_id, role, name, value, states, interactive, and path (trimmed above). A match that earns a ref has a qualified ref_id, and the response then includes the snapshot_id that holds it. A match with no ref is a context match: its ref_id is null and it carries bounds when the platform reports them, so you can see where it is. An element without an accessible name omits name, and its content stays in value. When a query with --role matches nothing, roles_present lists the roles the search did see.
Exit codes
| Code | Meaning |
|---|---|
0 | Success, and also help or version display. |
1 | A structured error. The envelope is on standard output with ok: false. |
2 | A command-line parse error. The envelope is still printed, with INVALID_ARGS. |
An argument the parser accepts but the command rejects, such as a bare @e1, exits 1. Exit 2 is only for arguments the parser cannot read.
Contract versions
Check version before you parse. Apply the migrations below when your parser supports an older contract version.
| Version | What changed |
|---|---|
| 2.1 | The error.retry_command string is gone, with no alias. Errors carry a structured error.recovery object and an error.disposition. Select a recovery strategy only when disposition.retry is safe, and never run command strings from older envelopes. |
| 2.2 | A snapshot that exhausts its budget returns ok: true with complete: false, the observed tree, truncated, nodes_observed, and subtree_truncated on cut nodes, instead of a TIMEOUT error. Snapshot data always carries complete. A --root drill-down still returns TIMEOUT for an incomplete observation. |
| 2.3 | launch returns app, pid, process_instance, and an optional window instead of a bare window object. An application that shows no window is ok: true with window omitted, not WINDOW_NOT_FOUND. |
| 2.4 | Stateful ref actions (set-value, type, clear, check, uncheck, toggle, expand, collapse) read the state back after one delivery attempt and reject an observed contradiction. A readback failure keeps the adapter's code and adds details.kind: "post_action_verification". Missing evidence stays a successful delivered_unverified with details.verification_scope: "unavailable". |
| 2.5 | Breaking for the thirteen OperationReport commands. The success flags clicked, moved, scrolled, hovered, dragged, resized, minimized, maximized, restored, closed, cleared, requested (close-app), and the inner ok of clipboard-set are removed. data is the adapter's report with disposition, steps, and target. |
| 2.6 | On Windows and Linux, and on macOS for an element without a native address, a ref resolves only when a complete window read proved its role and stable fields unique at capture and exactly one live element matches now. An identity captured from a twin fails with details.kind: "identity_not_unique", and one the snapshot could not prove fails with details.kind: "identity_unproven"; a twin that appears later fails with details.kind: "saved_ref_ambiguous". A snapshot that could not prove identity can include data.identity_unproven. On macOS, application-owned menu and menubar snapshots omit data.window; data.app identifies the owner, and --window-id selects that app. |
| 2.7 | launch, open-system-surface, focus-window, dismiss-notification and dismiss-all-notifications carry data.disposition on success: not_delivered with retry: "safe" when the operation was already satisfied and nothing was sent, delivered_verified when the adapter read back its postcondition, and delivered_unverified otherwise. An incomplete-locator TIMEOUT carries details.cause (deadline, unreadable_elements or traversal_limit). A launch payload written before 2.7 has no disposition; treat its absence as unknown. A key press no longer grants itself focus permission: press without --app or --window-id is refused headless with POLICY_DENIED and details.effect: "focus_steal" before anything is sent. Scope the press, or add --headed when the user asked for headed operation. In the C library, ad_execute_by_ref and ad_execute_by_ref_timeout with AD_ACTION_KIND_PRESS_KEY and AD_POLICY_KIND_HEADLESS return AD_RESULT_ERR_POLICY_DENIED when the element does not advertise a native key press; pass AD_POLICY_KIND_FOCUS_FALLBACK or AD_POLICY_KIND_HEADED to allow the focus fallback. |
The C library returns the same envelope from its JSON functions. See the C library overview.