agent-desktop-ffi
Skill này làm gì
Cung cấp cho lập trình viên giao diện C của thư viện tự động hóa máy tính, kèm các bước build và quy tắc sở hữu bộ nhớ. Dành cho lập trình viên muốn điều khiển ứng dụng trên máy tính từ chính code của họ.
Khi nào nên dùng
- ✓Khi bạn muốn gọi tự động hóa máy tính từ chương trình Python, Go hoặc Swift của mình.
- ✓Khi bạn cần build thư viện agent-desktop và liên kết nó vào một ứng dụng.
- ✓Khi bạn muốn tránh khởi động công cụ dòng lệnh cho mỗi thao tác.
Liên kết skill
https://github.com/NanmiCoder/cc-haha/blob/main/native/agent-desktop/skills/agent-desktop-ffi/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Cho tôi xem cách gọi thư viện tự động hóa máy tính từ script Python để chụp ảnh trạng thái Finder.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích cách build thư viện dùng chung và gọi các hàm của nó theo thứ tự cố định: khởi tạo, tạo adapter, chụp ảnh trạng thái, rồi thao tác trên các tham chiếu. Nó cũng bao gồm quyền sở hữu bộ nhớ và lỗi.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Những nền tảng nào được hỗ trợ?
Hướng dẫn bao gồm build thư viện trên macOS, Linux và Windows, mỗi nền tảng tạo ra loại tệp thư viện khác nhau.
Vì sao cần một profile build đặc biệt?
Profile phát hành tiêu chuẩn sẽ làm dừng toàn bộ chương trình chủ khi gặp crash, nên profile riêng giữ các lỗi có thể bắt được.
Bước nào phải làm trước?
Kiểm tra phiên bản header và thư viện khớp nhau trước khi tạo adapter.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 15k
- Vị trí xếp hạng
- #10913
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agent-desktop-linux
15kDạy agent cách điều khiển ứng dụng desktop Linux bằng agent-desktop, gồm những gì chạy trên X11 và Wayland và cách sửa lỗi chạy lần đầu thường gặp.
agent-desktop-macos
15kChỉ cho agent cách tự động hóa ứng dụng Mac, gồm cấp quyền cần thiết và làm việc với menu, hộp thoại cùng ứng dụng Chromium hoặc Electron.
agent-desktop-windows
15kChỉ cho agent cách tự động hóa ứng dụng Windows: những gì hoạt động, trích dẫn trong PowerShell, cửa sổ thu nhỏ và giới hạn với ứng dụng nâng quyền.
agent-desktop
15kCho phép agent nhìn và điều khiển ứng dụng desktop trên Mac, Windows hoặc Linux bằng cách đọc cây trợ năng, nhấp, gõ và kiểm tra kết quả.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.