/install agent-desktop-ffi
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-ffi
The 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.
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 — macOS main-thread rule, AXIsProcessTrusted inheritance when Python/Node dlopens the cdylib, and the single-owner handle invariant.
- build-and-link.md — minimum working example for Python ctypes and a C program that links the dylib.
⚠ Core constraints before you integrate
-
Main thread only (macOS). Call every adapter-touching entrypoint (
ad_get_tree,ad_resolve_element,ad_execute_action,ad_screenshot, clipboard, launch/close, window ops, observation, notifications, etc.) from the process's main thread. The FFI enforces this at runtime in every build profile — a worker-thread call returnsAD_RESULT_ERR_INTERNALwith a diagnostic last-error. On non-macOS platforms the check is a compile-time true; there is no runtime cost. -
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. -
Handle release. Every
ad_resolve_elementresult must be released withad_free_handle(adapter, handle)on the same adapter that produced it. On macOS this balances the internalCFRetain; on Windows/Linux the call is a no-op but safe to issue. -
Enum discriminants. Every
#[repr(i32)]enum field is validated at the C boundary — invalid discriminants returnAD_RESULT_ERR_INVALID_ARGSinstead of undefined behavior. -
ABI is unstable before 1.0. The header lists the exact current shapes. Anything added or reordered in a later patch is a breaking change; pin the version of libagent_desktop_ffi you link against.
-
ad_get_treereturns a raw adapter tree, not the CLI snapshot. Ref IDs are always null, no skeleton/drill-down pipeline is wired through, andinteractive_only/compactfollow adapter semantics which may diverge slightly from the CLI's post-processed shape. Usead_find+ad_get/ad_isfor point lookups, or invoke the CLI if you need CLI-parity JSON snapshots.
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install agent-desktop-ffi - After installation, invoke the skill by name or use
/agent-desktop-ffi - Provide required inputs per the skill's parameter spec and get structured output
What is Agent Desktop Ffi?
C-ABI bindings over agent-desktop's PlatformAdapter. Consumers (Python ctypes, Swift, Node ffi-napi, Go cgo, C++, Ruby fiddle) link libagent_desktop_ffi.{dyl... It is an AI Agent Skill for Claude Code / OpenClaw, with 68 downloads so far.
How do I install Agent Desktop Ffi?
Run "/install agent-desktop-ffi" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Agent Desktop Ffi free?
Yes, Agent Desktop Ffi is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Agent Desktop Ffi support?
Agent Desktop Ffi is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Agent Desktop Ffi?
It is built and maintained by lahfir (@lahfir); the current version is v1.0.0.