agent-desktop-ffi
Skill1.8k starsChanged 5 months agoApache-2.0View on GitHub
C-ABI bindings over agent-desktop's PlatformAdapter. Consumers (Python ctypes, Swift, Node ffi-napi, Go cgo, C++, Ruby fiddle) link libagent_desktop_ffi.{dylib,so,dll} and call `ad_*` functions directly instead of spawning the CLI binary per call. The canonical observe-act workflow is: ad_init → ad_adapter_create[_with_session] → ad_snapshot → parse @e refs → ad_execute_by_ref → ad_free_string → ad_adapter_destroy.
Trending
Less talk lately.about the whole repository
Who's talking about lahfir/agent-desktop
- A Hacker News story“Show HN: Agent-desktop – Native desktop automation CLI for AI agents”Hacker News · May 2, 2026 · 99 points
- A Hacker News story“Show HN: I spent 3 months making desktop automation stop lying to AI agents”Hacker News · Aug 15, 2026 · 6 points
- @camilleroux.com“Fini les screenshots pour piloter le bureau — agent-desktop expose les arbres d'accessibilité OS en JSON …”Bluesky · May 21, 2026 · 4 likes
- A Hacker News story“I might have solved computer use”Hacker News · Aug 14, 2026 · 2 points
- @hackernewsbot.bsky.social“I built the Playwright for desktop apps. 80% token savings | Discussion”Bluesky · May 2, 2026 · 2 likes
The biggest 5 of 26 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 26
Talked about on GitHub, Hacker News and Bluesky (26 times).
On GitHub · 20
- Jun 11, 2026feat(agent-desktop): add agent-desktop — mvanhorn/printing-press-library1 reaction · 2 comments
- Oct 4, 2026Scout pitch: Take a shallow overview of an app's UI first, then open only the area needed (skeleton-first snapshot) — 8gi-foundation/8gent-code0 reactions
- Sep 29, 2026agent-skills.github.lahfir.agent-desktop: init at 0.9.4 — sudosubin/agents.nix0 reactions
- Sep 22, 2026feat(omp): add opt-in Jev-guided compaction and vendored jev-review setup — danielkuykendall23-boop/firstmate0 reactions
- Aug 15, 2026[News Bot] 6 article(s) need review — chobrien99-svg/AMI-Labs0 reactions
15 more on GitHub
- Jul 1, 2026deps: bump the bun-dependencies group across 1 directory with 20 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- Jun 24, 2026deps: bump the bun-dependencies group across 1 directory with 18 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- Jun 17, 2026deps: bump the bun-dependencies group across 1 directory with 20 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- Jun 10, 2026deps: bump the bun-dependencies group across 1 directory with 18 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- Jun 4, 2026deps: bump the bun-dependencies group across 1 directory with 15 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- May 27, 2026deps: bump the bun-dependencies group with 8 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- May 26, 2026Add SKILL.md for agent-desktop automation — Cogni-AI-OU/cogni-ai-agentic-collections0 reactions · 5 comments
- May 22, 2026deps: bump the bun-dependencies group across 1 directory with 8 updates — AmeerJ97/grok-cli-vertex0 reactions
- May 20, 2026Bump the bun-dependencies group with 6 updates — AmeerJ97/grok-cli-vertex0 reactions · 1 comment
- May 20, 2026Bump the bun-dependencies group with 22 updates — AmeerJ97/grok-cli-vertex0 reactions
- May 8, 2026Add a Pi skill for agent-desktop usage — amfaro/duckdb-idea-plugin0 reactions
- May 4, 2026🔍 Weekly Discovery: 50 new tools found (2026-05-04) — heylabs-co/dev-tools-portal0 reactions
- May 3, 2026[claude-hackernews] Reply draft: agent-desktop Show HN, snapshot-allowlist guardrail (id=47982708) — FailproofAI/claude-hackernews0 reactions · 1 comment
- May 2, 2026📱 SNS 콘텐츠 - 2026-05-02 14:38 KST — leaf468/autothreads0 reactions
- May 2, 2026🤖 AI 트렌드 리포트 - 2026-05-02 14:38 KST — leaf468/autothreads0 reactions
On Hacker News · 3
- May 2, 2026Show HN: Agent-desktop – Native desktop automation CLI for AI agents99 points · 44 comments
- Aug 15, 2026Show HN: I spent 3 months making desktop automation stop lying to AI agents6 points
- Aug 14, 2026I might have solved computer use2 points · 1 comment
On Bluesky · 3
- May 21, 2026Fini les screenshots pour piloter le bureau — agent-desktop expose les arbres d'accessibilité OS en JSON avec des refs déterministes. Un… — @camilleroux.com4 likes and reposts · 3 replies
- May 2, 2026I built the Playwright for desktop apps. 80% token savings | Discussion — @hackernewsbot.bsky.socialsays it tested it2 likes and reposts
- May 2, 2026📰 I built Playwright for desktop apps, achieving 80% token savings in development time and cost efficiency. 🔗… — @sagalinked.bsky.socialsays it tested it1 likes and repost
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- agent-desktopSkill
- jev-desktopSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 71
ABI handshake: Call ad_init(AD_ABI_VERSION_MAJOR) once after loading the dylib.
- Very specific: line 88
not: create trace files. When tracing is active, command_context()-backed commands append to one segment per OS process under …
- Distinctive: line 108
Only the next failing call rotates them.
- Very specific: line 118
Handle release: Every ad_resolve_element_exact / ad_find_exact result must be released with ad_free_handle(adapter, &handle) on the same …
- Very specific: line 140
Display discovery: Call ad_list_displays before using AdScreenshotTarget.screen_index.
- Very specific: line 193
Enum discriminants: Every #[repr(i32)] enum field is validated at the C boundary — invalid discriminants return AD_RESULT_ERR_INVALID_ARGS …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
agent-desktop-ffi
Direct C-ABI access to every PlatformAdapter operation. Build the
cdylib with the workspace's release-ffi profile:
cargo build --profile release-ffi -p agent-desktop-ffiThe output is target/release-ffi/libagent_desktop_ffi.dylib
(.so on Linux, .dll on Windows) plus a committed C header at
crates/ffi/include/agent_desktop.h.
A Python ctypes smoke harness lives at tests/ffi-python/smoke.py and
serves as a worked end-to-end example covering the ABI handshake, struct
size validation, ad_version, and the snapshot pipeline leg. See
tests/ffi-python/README.md for usage.
Four reference topics, loaded as needed:
- ownership.md — who allocates / who frees,
for every
*mut Tthe FFI hands back to the caller. - error-handling.md — errno-style last-error contract, enum validation, panic boundary.
- threading.md — host-thread contract, cross-process mutation serialization, AXIsProcessTrusted inheritance, and adapter-bound native handles.
- build-and-link.md — ABI handshake, struct size validation, minimal C and Python examples, observe-act workflow, and prebuilt archive locations.
Observe-act workflow (canonical path)
ad_init(AD_ABI_VERSION_MAJOR) // verify header ↔ dylib match
adapter = ad_adapter_create_with_session("s1") // or ad_adapter_create()
rc = ad_snapshot(adapter, "Finder", 0, 10, false, false, &json_out)
// parse json_out: locate snapshot-qualified refs in data.tree
ad_free_string(json_out)
// build action:
AdAction act = {0}; act.kind = AD_ACTION_KIND_CLICK;
rc = ad_execute_by_ref(adapter, "@s8f3k2p9:e5", NULL, &act, 0, &result_out)
ad_free_string(result_out)
ad_adapter_destroy(adapter)ad_snapshot returns a {version, ok, command, data} JSON envelope
identical to the CLI output. The data.tree field contains snapshot-qualified
ref IDs for interactive elements. Pass a qualified ref, or a legacy bare ref
plus its explicit snapshot_id, to ad_execute_by_ref to drive the pipeline
(RefStore load → strict resolution → actionability preflight → dispatch).
Core constraints
- ABI handshake. Call
ad_init(AD_ABI_VERSION_MAJOR)once after loading the dylib. A mismatch between the compiled-in constant and the loaded dylib returnsAD_RESULT_ERR_INVALID_ARGS— abort rather than proceed. You can also read the raw dylib major viaad_abi_version()for diagnostic display. Newad_*symbols and new error codes are additive (no bump required); removed or layout-changed symbols increment the major. - Session adapters.
ad_adapter_create_with_session("session-id")associates the adapter with a session namespace for refmap persistence — the same as CLI--session <id>. A nullsnapshot_idis valid only for a qualified ref; legacy bare@eNrefs require an explicit snapshot ID. Session IDs: 1–64 chars, ASCII alphanumeric /-/_. Invalid IDs return null (checkad_last_error_*). - Structured session trace (no ABI change). File-based JSONL tracing activates
only when the session has a manifest with
trace: onfromsession start(CLI) or equivalent on-disk setup.ad_adapter_create_with_sessionalone does not create trace files. When tracing is active,command_context()-backed commands append to one segment per OS process under~/.agent-desktop/sessions/<id>/trace/<pid>-<procTs>.jsonl. A long-lived host reuses the same segment filename for all calls in that process. For unstructured diagnostics regardless of session manifest, usead_set_log_callback(below). - Threading and mutation leases. Adapter entrypoints may be called from any host thread. Native handles remain bound to their creating adapter and thread. Desktop mutations acquire the same canonical cross-process interaction lease as the CLI; reads carry finite deadlines without taking the mutation lock. See threading.md for the Apple documentation basis and the read/read, read/mutation, and mutation/mutation ordering matrix.
- Release profile.
cargo build --releaseproducespanic = "abort"— any Rust panic inside anextern "C"fn willSIGABRTthe host. Use--profile release-ffito get the correctpanic = "unwind"profile. CI enforces this. - Last-error lifetime. Pointers returned by
ad_last_error_*remain valid across any number of subsequent successful FFI calls on the same thread. Only the next failing call rotates them. Cache the pointer once, read it as many times as you need. - ad_last_error_details. A fourth accessor,
ad_last_error_details(), returns a borrowed JSON string carrying structured details (e.g. the actionability check report onACTION_FAILED, candidate summaries onAMBIGUOUS_TARGET). The details may contain element names, values, and window titles from the user's screen — treat as sensitive diagnostics and avoid routing to shared log surfaces. - Handle release. Every
ad_resolve_element_exact/ad_find_exactresult must be released withad_free_handle(adapter, &handle)on the same adapter that produced it, before that adapter is destroyed. On macOS this balances the internalCFRetain; on Windows/Linux the call is a no-op but safe to issue.ad_free_handlezeroeshandle.ptrso a follow-up call is a safe no-op. - Primary ref-action path.
ad_execute_by_refis the recommended entrypoint for the observe-act loop: it loads the RefStore, looks up the ref in the refmap (STALE_REF on miss), runs strict element re-identification (STALE_REF / AMBIGUOUS_TARGET), runs the live actionability preflight, then dispatches. TypeText and PressKey default tofocus_fallbackpolicy (matching CLItype/press-key); all other actions default toheadless. PassAD_POLICY_KIND_HEADED(2) to opt in to cursor-based fallbacks. - Generation-safe direct APIs. Legacy
AdRefEntryandAdWindowInfolayouts remain available for binary compatibility, but they do not carry process-generation evidence and direct targeting functions fail closed. UseAdExactRefEntry,AdExactWindowInfo,ad_list_windows_exact, and the*_exacttargeting symbols. Likewise,ad_list_surfaces_exactpreservesSurfaceInfo.id; the legacy surface list is an observation-only projection that omits it. - Display discovery. Call
ad_list_displaysbefore usingAdScreenshotTarget.screen_index. List order is the screenshot index order; inspect eachAdDisplayInfofor its stable display ID, bounds, primary flag, and scale, then release the handle withad_display_list_free. - Low-level action paths.
ad_execute_action(headless, no preflight) andad_execute_action_with_policyare raw escape hatches for callers holding a liveAdNativeHandlefromad_resolve_element_exact/ad_find_exact. Use them when you need to bypass the ref-action pipeline. - Ref-action preflight.
ad_execute_by_refandad_execute_ref_action_exact_with_policyboth resolve the element strictly and run the live actionability preflight (visible, stable, enabled, supported action, policy, editable) before dispatching — a disabled or unsupported target fails before any platform call. OnAD_RESULT_ERR_ACTION_FAILED, the structured check report is available as JSON viaad_last_error_details(). - Action result steps.
AdActionResult.stepsmirrors the CLIstepsarray for activation-chain actions. Each entry haslabelandoutcomestrings and is owned by the result; release withad_free_action_result(&out). Tracing / log callback. Two tracing surfaces coexist:
- Structured file trace — same JSONL contract as CLI
--trace, gated by atrace: onsession manifest. Segments includeevent,ts_ms,seq, and redacted fields. Requiressession start(or equivalent manifest on disk) before creating the adapter; plain session-id adapters write nothing to disk. ad_set_log_callback(cb)— installs atracingsubscriber layer that delivers events as JSON to your callback.cbreceives an int32_t level (1=ERROR … 5=TRACE) and aconst char *msgvalid only for the duration of the call. PassNULLto unregister. The layer is installed on the first non-null call; if a foreign global subscriber already owns the process at that point, the install fails withAD_RESULT_ERR_INTERNALand no events are ever delivered. Sensitive field values (password, token, text, …) are replaced with{"redacted":true}before formatting. A panicking callback is caught and silently discarded. The callback may fire from threads other than the registering thread, and may still fire briefly after aNULLunregister — keep the callback and any data it captures valid for the process lifetime.
- Structured file trace — same JSONL contract as CLI
- Wait.
ad_wait(adapter, args, &out)runs the full CLIwaitcommand (element-appear, window-appear, text-appear, menu-open/close, notification, element predicates). Zero-initializeAdWaitArgs, set the fields you need, and validate the struct size againstAD_WAIT_ARGS_SIZE/ad_wait_args_size()before calling. The output is a{version, ok, command, data}JSON envelope freed withad_free_string.ad_waitblocks the calling thread up totimeout_msms — ensure the adapter is not destroyed from another thread while it is running. - Text input privacy. On macOS, focus-fallback or headed text insertion may
briefly use the clipboard for non-ASCII text. For sensitive text, prefer
AD_ACTION_KIND_SET_VALUEwithAD_POLICY_KIND_HEADLESSwhen the target supports settable values. - Enum discriminants. Every
#[repr(i32)]enum field is validated at the C boundary — invalid discriminants returnAD_RESULT_ERR_INVALID_ARGSinstead of undefined behavior. - ABI stability. The major version in
AD_ABI_VERSION_MAJORincrements on any breaking change (removed symbol, incompatible layout). Additive changes (new symbols, new error codes) do not bump it. Before 1.0, pin the exact version of libagent_desktop_ffi you link against. ad_get_tree_exactvsad_snapshot.ad_get_tree_exactreturns a raw flat BFS tree without@erefs, no refmap persistence, and no JSON envelope — use it for custom traversal or UI inspection. For observe-act agents that drive actions viaad_execute_by_ref, always start withad_snapshot.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

