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

{
  "version": "2.7",
  "ok": true,
  "command": "click",
  "data": {
    "action": "click",
    "disposition": { "delivery": "delivered_unverified", "retry": "unsafe" }
  }
}
FieldTypeMeaning
versionstringContract version. Currently "2.7".
okbooleantrue when the command returned a result, false when it returned an error.
commandstringThe command name, such as click or session.
dataobjectThe result. Present only when ok is true.
errorobjectThe failure. Present only when ok is false. Its fields are in Errors and recovery.

An error envelope has error and no data:

{
  "version": "2.7",
  "ok": false,
  "command": "click",
  "error": {
    "code": "INVALID_ARGS",
    "message": "Invalid ref_id '@e1': expected @<snapshot_id>:e<N>",
    "suggestion": "Use the snapshot-qualified ref that snapshot prints, for example @s8f3k2p9:e1. A bare @eN ref is not accepted. Pass ref_id as printed: it already holds the snapshot id. In zsh write \"@${SID}:e1\", because an unbraced @$SID:e1 reads :e as a modifier.",
    "disposition": { "delivery": "not_delivered", "retry": "safe" }
  }
}

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 None is omitted, and so is an empty array. An error without a suggestion has no suggestion key, and a node without children has no children key.
  • Snapshot node bounds are omitted unless you pass --include-bounds.
  • Some commands build their data by hand and write null or [] for an absent value. session list writes "ended_at": null for an open session, and find matches write "value": null and "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.window appears when a window owns the observation. On macOS, application-owned menu and menubar snapshots 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:

{
  "version": "2.7",
  "ok": true,
  "command": "snapshot",
  "data": {
    "app": "gnome-calculator",
    "complete": true,
    "ref_count": 7,
    "snapshot_id": "s1vylk49fulgx4",
    "window": { "id": "w-calculator", "title": "Calculator" },
    "tree": {
      "role": "window",
      "name": "Calculator",
      "children": [
        {
          "available_actions": ["Click", "SetFocus"],
          "name": "Undo",
          "native_id": { "kind": "ax_identifier", "value": "undo_button" },
          "ref_id": "@s1vylk49fulgx4:e3",
          "role": "button",
          "states": ["disabled"]
        }
      ]
    }
  }
}

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.

FieldMeaning
kindAlways post_action_observation.
selector, expectedRequested selector and present or absent.
surfaceThe observed scope: the application-owned source surface, or window for a window-owned ref.
process_identityOriginal pid and process_instance; the instance can be null for identity_unavailable.
elapsed_msTime spent observing after the action returned.
source_window_idOriginal window ID, when the ref has one.
selector_matchesObserved selector result, when available; absence requires a complete read.
process_stateLast observed unresponsive, exited, or crashed state. running is never emitted.
last_observation_errorLast observation error's code and message, when available.
outcomeOne of the outcomes below.
OutcomeMeaning
expected_state_observedThe expected selector state was observed, or the original window or surface was confirmed absent for an absence wait.
process_exitedThe original process exited; this does not establish the action's effect.
process_crashedThe platform reported that the original process crashed.
owner_unavailableThe original surface owner remained unavailable without confirmed process exit.
observation_failedA terminal read error stopped observation; inspect last_observation_error.
timed_outThe 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_unavailableThe 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.

{
  "action": "drag",
  "disposition": { "delivery": "delivered_unverified", "retry": "unsafe" },
  "steps": [ { "label": "pointer_drag", "outcome": "succeeded", "mechanism": "physical_synthetic" } ],
  "target": { "kind": "drag", "from": { "x": 10, "y": 20 }, "to": { "x": 80, "y": 20 } },
  "from": { "x": 10, "y": 20 },
  "to": { "x": 80, "y": 20 }
}
target.kindFields
windowid, title, process
appname, process
pointerpoint
dragfrom, to
clipboardnone

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.

Flagdata
none, or --limit Nmatches, total_matches, truncated
--first, --last, --nth Nmatch (an object, or null when nothing matched)
--countcount
{
  "version": "2.7",
  "ok": true,
  "command": "find",
  "data": {
    "match": {
      "interactive": true,
      "name": "7",
      "path": ["window:Calculator", "group", "group", "group"],
      "ref_id": "@s3jjre8xzrvo2l:e1",
      "role": "button",
      "states": [],
      "value": null
    },
    "snapshot_id": "s3jjre8xzrvo2l"
  }
}

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

CodeMeaning
0Success, and also help or version display.
1A structured error. The envelope is on standard output with ok: false.
2A command-line parse error. The envelope is still printed, with INVALID_ARGS.
agent-desktop click @e1   # bare ref: INVALID_ARGS envelope
echo $?                   # 1
agent-desktop click       # missing argument: INVALID_ARGS envelope
echo $?                   # 2

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.

VersionWhat changed
2.1The 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.2A 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.3launch 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.4Stateful 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.5Breaking 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.6On 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.7launch, 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.