C library
The C library exposes agent-desktop as a shared library: libagent_desktop_ffi.dylib on macOS, libagent_desktop_ffi.so on Linux, and agent_desktop_ffi.dll on Windows. Your program calls ad_* functions instead of starting the CLI for each command. Any language with a C FFI can load it; tests/ffi-python/smoke.py is the tested reference. The header is crates/ffi/include/agent_desktop.h.
Relationship to the CLI
The library and the CLI run the same core and the same platform adapter; the agent-desktop binary and the agent-desktop-ffi crate are the only two places that connect a platform adapter to core.
- Same envelope. The command-backed functions return the CLI's JSON envelope as an owned string. See JSON output.
- Same refs.
ad_snapshotwrites a refmap under the same state root and returns qualified refs, whichad_execute_by_refresolves strictly. A bare@e5returnsAD_RESULT_ERR_INVALID_ARGS. - Same safety rules. Ref actions run the same resolution, actionability checks, and interaction policy as the CLI, and mutations take the same cross-process input lock, so CLI and library calls from one user serialize.
- Same sessions.
ad_adapter_create_with_sessionscopes refmaps to a session like--session.
Two layers
| Layer | Functions | Use when |
|---|---|---|
| JSON entrypoints | ad_snapshot, ad_execute_by_ref, ad_execute_by_ref_timeout, ad_wait, ad_status, ad_version, ad_trace_show, ad_trace_export | You run the observe, act, and verify loop: parse the envelope and pass refs back. |
| Struct-based exact APIs | ad_list_windows_exact, ad_launch_app_exact, ad_find_exact, ad_get_tree_exact, and the rest of the *_exact family, plus clipboard, mouse, display, notification, and screenshot calls | You need typed results without JSON. These carry process-generation evidence in versioned, size-pinned structs. |
What the library does not expose
ad_snapshotreads the owner selected bysurface. On macOS,menuandmenubarare application-owned and need no document window; window-owned snapshots includedata.window. The ABI has no window id, skeleton mode, or--rootdrill-down; use the CLI for those.ad_waitdoes not exposewait --eventor--window-id.- The library carries no skills. Read the FFI guide with
agent-desktop skills get ffifrom the CLI.
ABI version
AD_ABI_VERSION_MAJOR is 7 in this header. The major increments when a symbol is removed or changes incompatibly: a struct layout change, or a call that now fails where it used to succeed. ABI 7 makes ad_execute_ref_action_exact_with_policy and ad_resolve_element_exact fail closed with AD_RESULT_ERR_ACTION_NOT_SUPPORTED. New functions and new result codes are additive. Call ad_init(AD_ABI_VERSION_MAJOR) once after loading the library: a mismatch returns AD_RESULT_ERR_INVALID_ARGS, and you should call nothing else.
Next steps
- Build and link: build the library, link it, and run a minimal program.
- API: every function, struct, and enum, grouped by area.
- Ownership, threading, errors: who frees what, which threads may call, and how to read failures.