Перейти к содержанию
Skillpedia
API и серверы (бэкенд)15k · #10913

agent-desktop-ffi

Что он делает

Даёт программистам C-интерфейс библиотеки автоматизации рабочего стола с шагами сборки и правилами владения памятью. Он нужен разработчикам, которые хотят управлять приложениями на компьютере из собственного кода.

Когда использовать

  • ✓Когда вы хотите вызывать автоматизацию рабочего стола из своей программы на Python, Go или Swift.
  • ✓Когда нужно собрать библиотеку agent-desktop и подключить её к приложению.
  • ✓Когда вы хотите не запускать командную утилиту для каждого действия.

Ссылка на скилл

https://github.com/NanmiCoder/cc-haha/blob/main/native/agent-desktop/skills/agent-desktop-ffi/SKILL.md

Скопируйте и вставьте её в ваш ИИ (Claude, ChatGPT или Cursor) с просьбой следовать инструкциям.

Как использовать

Самый простой способ: скопируйте сообщение и вставьте его в свой ИИ. Он прочитает скилл и выполнит инструкции.

Готовое сообщение для вставки

Используй этот скилл, чтобы помочь мне: https://github.com/NanmiCoder/cc-haha/blob/main/native/agent-desktop/skills/agent-desktop-ffi/SKILL.md Прочитай файл SKILL.md по этой ссылке и следуй его инструкциям в моей задаче.
Хотите, чтобы ваш ИИ сам находил такие скиллы?Установите бесплатный MCP Skillpedia: одна строка, и перед каждой задачей он ищет среди 15 000+ скиллов.Установить за 1 минуту →

Пример запроса к вашему ИИ

“Покажи, как вызвать библиотеку автоматизации рабочего стола из моего скрипта на Python, чтобы снять снимок Finder.”

5 новых скиллов в неделю. 1 минута чтения.

Как это работает

Скилл объясняет, как собрать общую библиотеку и вызывать её функции в фиксированном порядке: инициализация, создание адаптера, снимок, затем действия по ссылкам. Он также описывает владение памятью и ошибки.

Технический текст (оригинальный SKILL.md)

Оригинальный текст автора на английском, прямо с 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 returns AD_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; new ad_* symbols and error codes are additive. Pin the exact libagent_desktop_ffi version 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 like ad_adapter_create(). An invalid ID returns null (read ad_last_error_*).

  • Ref actions. ad_execute_by_ref is the primary action entrypoint. It loads the RefStore, resolves the ref strictly (STALE_REF when the snapshot has no such ref or the element changed, AMBIGUOUS_TARGET on 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; on AD_RESULT_ERR_ACTION_FAILED the check report is JSON in ad_last_error_details(). It auto-waits 5000 ms before the preflight; ad_execute_by_ref_timeout takes timeout_ms (-1 = 5000 ms default, 0 = single-shot). PressKey defaults to focus_fallback; every other action, including TypeText, defaults to headless. Pass AD_POLICY_KIND_FOCUS_FALLBACK (1) to allow focus without cursor movement, or AD_POLICY_KIND_HEADED (2) to allow physical cursor and keyboard delivery. ad_execute_ref_action_exact_with_policy runs the same preflight from an AdExactRefEntry.

  • 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 *_exact symbols. AdRefEntry, AdWindowInfo, and AdSurfaceInfo exist only as fields embedded in the exact structs. ad_list_surfaces_exact keeps the surface id. From AD_EXACT_SURFACE_INFO_VERSION 2, AdExactSurfaceInfo.unclassified names the surface kinds its probe could not read (for example sheet,menu), or is null. A missi

Частые вопросы

Какие платформы поддерживаются?

Руководство охватывает сборку библиотеки на macOS, Linux и Windows, которые создают разные типы файлов библиотек.

Зачем нужен особый профиль сборки?

Стандартный профиль релиза при сбое останавливает всю программу-хост, поэтому отдельный профиль позволяет перехватывать ошибки.

Какой шаг должен идти первым?

Перед созданием адаптера проверьте, что версии заголовочного файла и библиотеки совпадают.

Подробности

Оригинальное описание автора

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

Популярность

Звёзды на GitHub
15k
Место в рейтинге
#10913
Лицензия
—
Обновлён
02.11.2026

Полезен ли этот скилл?

0

Войдите , чтобы голосовать.

Комментарии

  • …

Другие скиллы из этого репозитория

Похожие скиллы