
agent-desktop-ffi
C-ABI bindings over agent-desktop's PlatformAdapter. Consumers (Python ctypes, Swift, Node ffi-napi, Go cgo, C++, Ruby fiddle) link libagentdesktopffi.{dylib,so,dll} and call ad functions directly instead of spawning the CLI binary per call. The canonical observe-act workflow is: adinit → adadaptercreate[withsession] → adsnapshot → read qualified refs (@s8f3k2p9:e5) → adexecutebyref → adfreestring → adadapterdestroy.
- Installs
- 646
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/vercel-labs/agent-desktop --skill agent-desktop-ffi- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads agent-desktop-ffi automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
agent-desktop-ffi
Direct C-ABI access to PlatformAdapter operations. Build the cdylib with the
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,
agent_desktop_ffi.dll on Windows) plus a committed C header at
crates/ffi/include/agent_desktop.h. The default release profile uses
panic = "abort": a Rust panic inside an extern "C" function would SIGABRT
the host. release-ffi keeps panic = "unwind", which the panic traps need.
Four reference topics, loaded as needed:
- ownership.md: who allocates and who frees every pointer the FFI hands back.
- error-handling.md: errno-style last-error contract, error codes, enum validation, panic boundary.
- threading.md: host-thread contract, mutation ordering across threads and processes, adapter-bound native handles, AXIsProcessTrusted inheritance.
- build-and-link.md: prebuilt archives, ABI handshake, struct size validation, C and Python examples.
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", &act, 0, &result_out)
ad_free_string(result_out)
ad_adapter_destroy(adapter)
ad_snapshot returns the CLI envelope {version, ok, command, data}.
data.tree carries snapshot-qualified refs for interactive elements. Read
data.complete before trusting a tree: false means the observation budget ran
out and the tree is partial, not an error. ad_snapshot always targets the
focused window of app; window targeting, skeleton mode and --root drill-down
are not exposed over the ABI. A bare @eN ref returns
AD_RESULT_ERR_INVALID_ARGS.
Core constraints
-
ABI handshake. Call
ad_init(AD_ABI_VERSION_MAJOR)once after loading the library. A mismatch returnsAD_RESULT_ERR_INVALID_ARGS: abort.ad_abi_version()returns the library's major for display. The major increments on a removed symbol or a layout change; newad_*symbols and error codes are additive. Pin the exactlibagent_desktop_ffiversion you link against. -
Session adapters.
ad_adapter_create_with_session("session-id")scopes refmap persistence to a session namespace, like CLI--session <id>. IDs are 1 to 64 ASCII alphanumeric,-, or_characters. A null ID behaves likead_adapter_create(). An invalid ID returns null (readad_last_error_*). -
Ref actions.
ad_execute_by_refis the primary action entrypoint. It loads the RefStore, resolves the ref strictly (STALE_REFwhen the snapshot has no such ref or the element changed,AMBIGUOUS_TARGETon several candidates), runs the live actionability preflight (visible, stable, enabled, supported action, policy, editable), then dispatches. A disabled or unsupported target fails before any platform call; onAD_RESULT_ERR_ACTION_FAILEDthe check report is JSON inad_last_error_details(). It auto-waits 5000 ms before the preflight;ad_execute_by_ref_timeouttakestimeout_ms(-1= 5000 ms default,0= single-shot).PressKeydefaults tofocus_fallback; every other action, includingTypeText, defaults toheadless. PassAD_POLICY_KIND_FOCUS_FALLBACK(1) to allow focus without cursor movement, orAD_POLICY_KIND_HEADED(2) to allow physical cursor and keyboard delivery.ad_execute_ref_action_exact_with_policyruns the same preflight from anAdExactRefEntry. -
Generation-safe direct APIs. Every direct targeting function takes process-generation evidence:
AdExactRefEntry,AdExactWindowInfo,ad_list_windows_exact,ad_launch_app_exact, and the other*_exactsymbols.AdRefEntry,AdWindowInfo, andAdSurfaceInfoexist only as fields embedded in the exact structs.ad_list_surfaces_exactkeeps the surfaceid. FromAD_EXACT_SURFACE_INFO_VERSION2,AdExactSurfaceInfo.unclassifiednames the surface kinds its probe could not read (for examplesheet,menu), or is null. A missingsheetormenunext to a listed kind is unknown, not absent. Only the Windows adapter fills it; macOS and Linux return null. -
Native handles.
ad_resolve_element_exactandad_find_exactreturn anAdNativeHandle.ad_execute_action(headless, no preflight) andad_execute_action_with_policyact on it directly, bypassing the ref-action pipeline. Release every handle withad_free_handle(adapter, &handle)on the same adapter and thread, beforead_adapter_destroy, on every platform. It zeroeshandle.ptr, so a second call is a no-op. -
Action results.
AdActionResult.stepsmirrors the CLIstepsarray for activation-chain actions. EachAdActionStephaslabelandoutcomestrings,mechanism(AD_STEP_MECHANISM_SEMANTIC_API= 1 orAD_STEP_MECHANISM_PHYSICAL_SYNTHETIC= 2, valid only whenhas_mechanism), andverified(valid only whenhas_verified).AdActionResult.dispositioncarries the same delivery/retry pair asad_last_error_delivery_semantics. Release the result withad_free_action_result(&out). -
Display discovery. Call
ad_list_displaysbefore usingAdScreenshotTarget.screen_index. List order is the screenshot index order. EachAdDisplayInfocarries a stable display ID, bounds, primary flag, and scale. Release the list withad_display_list_free. -
Errors. A failing call sets thread-local last-error state; read it with the
ad_last_error_*accessors before the next failing call.ad_last_error_details()returns structured JSON (the actionability report onACTION_FAILED, candidate summaries onAMBIGUOUS_TARGET) that can contain element names, values, and window titles from the user's screen: keep it out of shared logs.ad_last_error_delivery_semanticsreports whether the failed action was delivered and whether a retry is safe. Invalid enum discriminants returnAD_RESULT_ERR_INVALID_ARGS. See error-handling.md. -
Threading. Entrypoints may be called from any host thread. Native handles stay on the adapter and thread that created them; pass qualified refs across threads. Desktop mutations take the same cross-process interaction lease as the CLI; reads take no lease and carry finite deadlines. See threading.md for the read/read, read/mutation, and mutation/mutation matrix.
-
Tracing. File tracing (same JSONL contract as CLI
--trace; segments carryevent,ts_ms,seq, and redacted fields) is active only when the session has a manifest withtrace: on, created bysession start(or an equivalent manifest on disk) before the adapter is created.ad_adapter_create_with_sessionalone writes nothing. Each OS process appends to one segment,~/.agent-desktop/sessions/<id>/trace/<pid>-<procTs>.jsonl, and a long-lived host reuses it.ad_trace_show(JSON envelope) andad_trace_export(self-contained HTML file) read the adapter session's merged timeline;limit-1= CLI default. -
Log callback.
ad_set_log_callback(cb)registers one process-wide callback for diagnostics regardless of session manifest. It receives, as JSON, thetracingevents emitted inside laterad_*calls on the same thread; the FFI never installs or replaces the host process's global tracing subscriber.cbreceives anint32_tlevel (1=ERROR ... 5=TRACE) and aconst char *msgvalid only for the duration of the call. PassNULLto unregister. Sensitive field values (password, token, text, ...) are replaced with{"redacted":true}. The callback must not unwind across the C ABI: catch C++ exceptions and Rust panics inside it, because a violation may abort the host. It may fire from several host threads at once and briefly after aNULLunregister: keep the callback and any data it captures valid for the process lifetime. -
Wait.
ad_wait(adapter, args, &out)runs the CLIwaitcommand. Setmode.pause(AdOptionalU64, ms),mode.element,mode.window(waits for a window with that title),mode.text, or one ofmode.surfaces.menu,.menu_closed,.notification; add thepredicategroup (predicate,value,action,count) andscope.timeout_ms/scope.app. The CLI event wait (--event,--window-id) is not exposed. Zero-initializeAdWaitArgsand validate the struct size againstAD_WAIT_ARGS_SIZE/ad_wait_args_size()before calling. The output is a{version, ok, command, data}envelope freed withad_free_string.ad_waitblocks the calling thread up toscope.timeout_msms. A concurrentad_adapter_destroydoes not invalidate an in-flight wait. -
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. -
ad_get_tree_exactvsad_snapshot.ad_get_tree_exactreturns a raw flat breadth-first tree: no refs, no refmap persistence, no JSON envelope (free it withad_free_tree). Use it for custom traversal or UI inspection. For observe-act agents that drive actions viaad_execute_by_ref, start withad_snapshot.
FAQ
What does the agent-desktop-ffi skill do?
C-ABI bindings over agent-desktop's PlatformAdapter. Consumers (Python ctypes, Swift, Node ffi-napi, Go cgo, C++, Ruby fiddle) link libagentdesktopffi.{dylib,so,dll} and call ad functions directly instead of spawning the CLI binary per call. The canonical observe-act workflow is: adinit → adadaptercreate[withsession] → adsnapshot → read qualified refs (@s8f3k2p9:e5) → adexecutebyref → adfreestring → adadapterdestroy.
How do I install agent-desktop-ffi?
Run npx skills add https://github.com/vercel-labs/agent-desktop --skill agent-desktop-ffi in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/agent-desktop-ffi/ (personal) or .claude/skills/agent-desktop-ffi/ (project).
Which AI agents can use agent-desktop-ffi?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is agent-desktop-ffi safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains agent-desktop-ffi?
It is published by vercel-labs in vercel-labs/agent-desktop. It has 646 recorded installs.
More from vercel-labs/agent-desktop
agent-desktop
vercel-labs/agent-desktop
Operate desktop applications on macOS, Windows and Linux through native accessibility trees, using the agent-desktop CLI. Use when an AI agent must see or act on a desktop GUI: click buttons, fill forms, read UI state, navigate menus, toggle checkboxes, scroll, drag, type text, press shortcuts, take screenshots, manage windows, use the clipboard, launch or close apps, read notifications. Triggers on: "click button", "fill form", "open app", "read UI", "computer use", "operate desktop", "accessibility tree", "snapshot app", "type into field", "navigate menu", "toggle checkbox", "take screenshot", "desktop automation", "agent-desktop", or any desktop GUI task on macOS, Windows or Linux.
agent-desktop-windows
vercel-labs/agent-desktop
Windows platform guide for the agent-desktop CLI. Lists per command group what works on Windows and what refuses, the first-contact gotchas (PowerShell ref quoting, minimized windows, headed-only input), and where to find shell surfaces, notifications, the cursor overlay, UIPI elevation, Chromium/Electron settle behavior and troubleshooting. Triggers on: "windows desktop automation", "UIA tree", "automate Windows app", "agent-desktop on Windows", "elevated window input blocked", "EACCESSDENIED", or any Windows GUI interaction task.
agent-desktop-macos
vercel-labs/agent-desktop
macOS platform guide for the agent-desktop CLI. Use for desktop automation on macOS: granting Accessibility and Screen Recording permission (TCC), what headed mode does on macOS (physical-first click, type and scroll), surfaces (menu, menubar, sheet, popover, alert), Notification Center, Chromium and Electron apps including launch --cdp, and fixing PERMDENIED, empty accessibility trees, ACTIONFAILED and APPUNRESPONSIVE.
agent-desktop-linux
vercel-labs/agent-desktop
Linux platform guide for the agent-desktop CLI. Lists per command group what works on X11 and on Wayland, how to check the AT-SPI accessibility bus, the first-contact gotchas (app names, Chromium and Electron flags, headed focus, blocked key combos), and where to find lifecycle, screenshot, clipboard, tray, notification and troubleshooting details. Triggers on: "linux desktop automation", "AT-SPI tree", "automate GNOME app", "agent-desktop on Linux", "accessibility bus not available", "empty supportedsurfaces", "wayland screenshot consent", or any Linux GUI interaction task.
jev-desktop
vercel-labs/agent-desktop
Drive a desktop application from one plain-language goal, or resolve one intent at a time, without ever reading the accessibility tree. Use when automating a desktop app and you want to keep a 150-element JSON tree out of your context. Hand run.mjs a whole goal and it observes, decides and acts until the goal is met; hand act.mjs a single step when you want to keep the plan yourself. Covers which element, which operation, when to look deeper, and when to stop. Needs a clone of the agent-desktop repository and a TYPESAFEAPIKEY.
Popular devops & cloud skills
microsoft-foundry
microsoft/azure-skills
Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent create, managed harness agent create, GitHub Copilot harness agent, create agent, update agent, add tool to agent, invoke agent, agent insights, evaluate agent, batch eval, continuous eval, continuous monitoring, agent CI/CD, optimize prompt, improve prompt, optimize agent instructions, Agent Optimizer scaffold, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure
azure-diagnostics
microsoft/azure-skills
Debug Azure production issues on Azure using AppLens, Azure Monitor, resource health, and safe triage. WHEN: debug production issues, troubleshoot app service, app service high CPU, app service deployment failure, troubleshoot container apps, container app 503 or target port mismatch, troubleshoot functions, function telemetry missing or stopped after a config/connection-string change, troubleshoot AKS, VM RDP, Linux SSH, VM black screen, can't connect to VM, reset VM password, NSG or firewall blocking, kubectl cannot connect, kube-system/CoreDNS failures, pod pending, crashloop, node not ready, upgrade failures, analyze logs, KQL, insights, image pull failures, cold start issues, health probe failures, resource health, root cause of errors, troubleshoot event hubs, troubleshoot service bus, messaging SDK error, AMQP connection failure, message lock lost, lock renewal during long-running processing, service bus dead letter.
azure-prepare
microsoft/azure-skills
Prepare azd-based Azure projects for deployment: generates azure.yaml, infrastructure (Bicep/Terraform), and Dockerfiles for the Azure Developer CLI (azd) workflow. USE ONLY when the user explicitly wants to use azd as the deployment tool, or the project already has an azure.yaml file. DO NOT USE FOR: non-azd deployments, Python App Service code-only deploys (use python-appservice-deploy), or cross-cloud migration (use azure-cloud-migrate). WHEN: prepare app for azd, create azure.yaml, set up azd infrastructure, modernize app for Azure with azd, deploy with azd, function app, timer trigger, service bus trigger, event-driven function, managed identity, generate Bicep, generate Terraform, create and deploy to Azure.
azure-ai
microsoft/azure-skills
Use for Azure AI: Search, Speech, OpenAI, Document Intelligence. Helps with search, vector/hybrid search, speech-to-text, text-to-speech, transcription, OCR. WHEN: AI Search, query search, vector search, hybrid search, semantic search, speech-to-text, text-to-speech, transcribe, OCR, convert text to speech.
azure-deploy
microsoft/azure-skills
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: "run azd up", "run azd deploy", "execute deployment", "push to production", "push to cloud", "go live", "ship it", "bicep deploy", "terraform apply", "publish to Azure", "launch on Azure". DO NOT USE WHEN: "create and deploy", "build and deploy", "create a new app", "set up infrastructure", "create and deploy to Azure using Terraform" — use azure-prepare for these.
azure-validate
microsoft/azure-skills
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure (Bicep or Terraform), RBAC role assignments, managed identity permissions, and prerequisites before deploying. WHEN: validate my app, check deployment readiness, run preflight checks, verify configuration, check if ready to deploy, validate azure.yaml, validate Bicep, test before deploying, troubleshoot deployment errors, validate Azure Functions, validate function app, validate serverless deployment, verify RBAC roles, check role assignments, review managed identity permissions, what-if analysis, validate Container Apps deployment.