agent-desktop-ffi
Fungsinya
Memberikan programmer antarmuka C untuk pustaka otomasi desktop, dengan langkah build dan aturan kepemilikan memori. Cocok untuk pengembang yang ingin mengendalikan aplikasi di komputer dari kode mereka sendiri.
Kapan dipakai
- βSaat Anda ingin memanggil otomasi desktop dari skrip Python, program Go, atau Swift Anda sendiri.
- βSaat Anda perlu membangun pustaka agent-desktop dan menautkannya ke sebuah aplikasi.
- βSaat Anda ingin menghindari memulai alat baris perintah untuk setiap tindakan.
Link skill
https://github.com/NanmiCoder/cc-haha/blob/main/native/agent-desktop/skills/agent-desktop-ffi/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTunjukkan cara memanggil pustaka otomasi desktop dari skrip Python saya untuk mengambil snapshot Finder.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill ini menjelaskan cara membangun pustaka bersama dan memanggil fungsinya dalam urutan tetap: inisialisasi, membuat adapter, mengambil snapshot, lalu bertindak pada referensi. Ia juga mencakup kepemilikan memori dan kesalahan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Platform apa saja yang didukung?
Panduannya mencakup pembangunan pustaka di macOS, Linux, dan Windows, yang menghasilkan jenis berkas pustaka yang berbeda.
Mengapa diperlukan profil build khusus?
Profil rilis standar akan menghentikan seluruh program host saat terjadi crash, jadi profil terpisah membuat kesalahannya bisa ditangkap.
Langkah mana yang harus dilakukan pertama?
Pastikan versi header dan pustaka cocok sebelum membuat adapter.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 15k
- Peringkat
- #10913
- Lisensi
- β
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
agent-desktop-linux
15kMengajarkan agent Anda cara mengendalikan aplikasi desktop Linux dengan agent-desktop, termasuk apa yang berfungsi di X11 dan Wayland serta perbaikan umum saat pertama kali dijalankan.
agent-desktop-macos
15kMenunjukkan kepada agent Anda cara mengotomatisasi aplikasi Mac, termasuk memberikan izin yang diperlukan dan bekerja dengan menu, dialog, serta aplikasi Chromium atau Electron.
agent-desktop-windows
15kMenunjukkan kepada agent Anda cara mengotomatisasi aplikasi Windows, mencakup apa yang berfungsi, tanda kutip PowerShell, jendela yang diminimalkan, dan batasan aplikasi yang ditinggikan.
agent-desktop
15kMemungkinkan agent Anda melihat dan mengoperasikan aplikasi desktop di Mac, Windows, atau Linux dengan membaca pohon aksesibilitas, mengklik, mengetik, dan memeriksa hasilnya.
Skill serupa
api-connector-builder
280kMembuat agent Anda membangun koneksi API baru mengikuti pola yang sudah ada. Gunakan saat ingin menambah integrasi lagi tanpa membuat cara baru.
api-design
280kMembantu agent Anda merancang REST API sesuai praktik terbaik. Berguna untuk mengatur cara API berkomunikasi, menampilkan error, dan mengorganisasi data.
backend-patterns
280kMembantu agent Anda dengan pola arsitektur sisi server dan optimasi database. Berguna untuk membangun atau meninjau kode yang berjalan di server.