agent-desktop-ffi
Was er macht
Gibt Programmierern die C-Schnittstelle der Desktop-Automatisierungsbibliothek mit Bau-Schritten und Regeln zur Speicherverwaltung. Er ist für Entwickler gedacht, die Apps auf einem Rechner aus ihrem eigenen Code steuern wollen.
Wann du ihn nutzt
- ✓Wenn du Desktop-Automatisierung aus deinem eigenen Python-, Go- oder Swift-Programm aufrufen willst.
- ✓Wenn du die Bibliothek agent-desktop bauen und in eine App einbinden musst.
- ✓Wenn du vermeiden willst, das Kommandozeilenwerkzeug für jede Aktion zu starten.
Link zum Skill
https://github.com/NanmiCoder/cc-haha/blob/main/native/agent-desktop/skills/agent-desktop-ffi/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Zeig mir, wie ich die Desktop-Automatisierungsbibliothek aus meinem Python-Skript aufrufe, um einen Schnappschuss des Finders zu machen.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Skill erklärt, wie du die gemeinsame Bibliothek baust und ihre Funktionen in fester Reihenfolge aufrufst: initialisieren, einen Adapter erstellen, einen Schnappschuss machen und dann auf Referenzen handeln. Er behandelt auch Speicherbesitz und Fehler.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
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 missi
Häufige Fragen
Welche Plattformen werden unterstützt?
Der Leitfaden deckt das Bauen der Bibliothek unter macOS, Linux und Windows ab, die jeweils unterschiedliche Bibliotheksdateien erzeugen.
Warum braucht es ein besonderes Build-Profil?
Das Standard-Release-Profil würde das ganze Host-Programm bei einem Absturz anhalten. Das separate Profil hält Fehler abfangbar.
Welcher Schritt muss zuerst kommen?
Prüfe, dass Header- und Bibliotheksversionen zusammenpassen, bevor du einen Adapter erstellst.
Details
Originalbeschreibung des Autors
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 → read qualified refs (@s8f3k2p9:e5) → ad_execute_by_ref → ad_free_string → ad_adapter_destroy.
repo: NanmiCoder/cc-haha
Beliebtheit
- GitHub-Sterne
- 15k
- Platz im Ranking
- #10913
- Lizenz
- —
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
agent-desktop-linux
15kZeigt deinem Agenten, wie er Linux-Desktop-Apps mit agent-desktop steuert, einschließlich dessen, was unter X11 und Wayland funktioniert, und typischer Korrekturen beim ersten Start.
agent-desktop-macos
15kZeigt deinem Agenten, wie er Mac-Apps automatisiert, einschließlich der nötigen Berechtigungen und der Arbeit mit Menüs, Dialogen sowie Chromium- oder Electron-Apps.
agent-desktop-windows
15kZeigt deinem Agenten, wie er Windows-Apps automatisiert, mit Angaben zu dem, was funktioniert, PowerShell-Anführungszeichen, minimierten Fenstern und Grenzen bei erhöhten Apps.
agent-desktop
15kLässt deinen Agenten Desktop-Apps auf Mac, Windows oder Linux sehen und bedienen, indem er den Accessibility-Baum liest, klickt, tippt und die Ergebnisse prüft.
Ähnliche Skills
api-connector-builder
280kLässt deinen Agenten neue API-Anbindungen nach dem bestehenden Muster bauen. Nutze es, wenn du eine weitere Integration ergänzen willst, ohne neue Wege einzuführen.
api-design
280kHilft deinem Agenten, REST-APIs nach Best Practices zu entwerfen. Nützlich für die Kommunikation, die Fehlerausgabe und die Organisation von Daten.
backend-patterns
280kHilft deinem Agenten bei Architekturmustern für die Serverseite und bei der Datenbankoptimierung. Nützlich zum Bauen und Prüfen von Server-Code.