8.7 KiB
b03f:mac 平台群(desktop.rs 283+axread.rs 643+axwrite.rs 418+macapps.rs 419+intents.rs 229)
desktop.rs(agent-desktop 编译进来:三平台读 App 控件树)
adapter()(macOS/Linux/Windows 三 crate 各一 PlatformAdapter)。run(cmd,a) 五动作:apps/windows/snapshot/launch/permissions(agent-desktop_core 命令结构照填;snapshot:max_depth ≤60、interactive_only 默认 true、compact、force_electron_a11y=true)。err 带 code+suggestion。
elements_of(tree, app)→Vec<marks::Element>(编号截图共用元素表):
- 常量:MAX_WALKED_NODES=20000(只挡疯树;屏幕外的也计数——长网页滚下 4000 用完、屏内没编号的真实踩坑)、编号上限 600 控件、VALUE_HEAD=160/VALUE_TAIL=400(终端滚动条保头保尾,「中間省略 N 字」)。
- 规则:无界(bounds 缺)的节点丢;图标钮名从 description 补(存档三角「顯示較多選項」);无名 row/cell/listitem 用内文(words_inside),除非包住有名控件(named_inside→只点名的按钮编号,空 spacer row 不编号);hidden/offscreen 不编号;w,h≥1 且与屏幕相交、active 或有名或有值、role≠window/group 才收;>600 停止编号但仍收带 card/OTP 密码的盒(黑罩用);flags 已勾/已選/停用/游標在這(focused 只给 text/field 角色)。
elements(app)→(名, CGWindowID(w- 前缀解析), 元素),snapshot interactive_only:false max_depth:40。launch(非 macOS;mac 用 LaunchServices 在别处)。- role_name 中文化表 + active 25 角色。
测试锁(4):长页滚下屏内仍编号、hidden/offscreen 不编号+包名 row 只点钮、存档三角编号、控件带位置+终端滚动尾+0 尺寸丢。
axread.rs(macOS 辅助使用「读」:人自己的浏览器/菜单栏/菜单/状态项)
常量:RENDERER_BUNDLE_IDS[2]=com.github.Electron/com.google.Chrome、RENDERER_BUNDLE_PREFIX、ELECTRON_EXE_PIECE、RENDERER_FRAMEWORKS[3](Electron/CEF/Google Chrome Framework)、RENDERER_AX_FLAGS[2]=AXManualAccessibility→AXEnhancedUserInterface(顺序)、MAX_AX_NODES=20000、MAX_AX_DEPTH=80、READ_TRIES=5、RETRY_PAUSE_MS=700、AX_TIMEOUT_SECS=2.0。
is_renderer(bundle_id,exe,has_framework)按原规格;bundle_of;pick_person_pid(ps 行挑人的浏览器主 pid:排除 AnyBot 自己 --user-data-dir 的、--type= 的 helper)。- mac mod:ApplicationServices+CoreFoundation FFI;
trusted(prompt)(AXIsProcessTrustedWithOptions,prompt 弹系统询问);write_flags(renderer 两旗标依序);read(pid,renderer,max_chars)→Page{title,url,text}:Focused/Main 窗→找 AXWebArea→AXStaticText 串成行→AXURL(CFURLGetString);5 试×700ms(Chrome 建树慢)。 status_items(apps):AXExtrasMenuBar,8 家一批并行线程、0.25s timeout 跳过;words_within 3 层(Title/Description/Value/Help→children→AXIdentifier 走 menu_extra_name)。app_menus(pid):AXMenuBar 标题(rect[1]≤60)+ 展开中的菜单项(AXSelected→submenu 递归 depth≤3、≤300 项)+ 右键菜单挂 app 下;shortcut=AXMenuItemCmdChar+AXMenuItemCmdModifiers;同位两项=option 替代件(needs_option 者判为隐藏件,alternate 记录)。shortcut_words(mods: 4=ctrl,2=option,1=shift,8=无⌘;私有字符 F1-F26/方向键/删除转字)。menu_extra_name(com.apple.menuextra.* → 24 对照表 Wi-Fi/電池/…)。read_person_browser(exe,max_chars):trusted 否则computer::ask_permission("Privacy_Accessibility")开系统设定页+指路文案;ps→pid→plutil 读 bundle id→is_renderer→mac::read。非 macOS→「只支援 macOS」。
测试锁(4+live 2 --ignored):renderer 规格全表(Chrome.canary、Chromeish 不中、Safari 不中、framework 抓 Brave/Edge)、人的浏览器≠AnyBot 窗口(pid 205)、快捷键转字(cmd+s、option+shift+cmd+s、f1…)、bundle_of;live_app_menus/live_person_chrome。
axwrite.rs(macOS 辅助使用「写」:按名字/按点/写字段/走菜单/填表单)
动机(注释记载):编号点击踩过 Retina 缩放/遮挡/坐标差一像素的坑 → AX 按不受坐标影响;一切失败回像素路(CGEvent),薄树 App 行为如前。
- 常量:PRESSABLE_ROLES[9](AXButton/CheckBox/RadioButton/MenuItem/PopUpButton/MenuButton/Menu/TabButton/Link)、EDITABLE_ROLES[5]、MAX_NODES=20000、MAX_DEPTH=80、TIMEOUT_SECS=2.0。
name_match(exact=2>contains=1,trim 大小写无关)、merged_text(append 保留旧值)。- mac FFI;
keep=CFRetain 必做(children 列表释放后选中元素成悬垂指针,press 打到已释放内存——注释记载的真实踩坑)。 press_named(最深同名优先,tie 深者胜→按钮不是包它的 group)、press_at(最深含点的可 press;不可 press 的深元素第二选)、press(AXPress/AXPick 依角色试序)、set_focused_text(AXFocusedUIElement 可编辑角色才写)、menu_click(path)(走真菜单列:壓MenuBarItem→350ms→逐段 find_menu_item→250ms——旧版截图三轮才走一层)、fill_form(fields)(collect_editables 全收→name_of(Title/Desc/Placeholder/Help) 匹配→逐栏 AXValue 写,回 per-field 结果)。- 非 mac:五桩全部回「只在 macOS…」文案(调用方落回像素路)。
测试锁(2):exact>contains、append 保旧。
macapps.rs(Mac 自家 App=12 工具,JXA osascript)
常量:MAX_CHARS=20000、CONTACT_BATCH=50、CALL_TIMEOUT_MS=30000、MAIL_SCAN=300;NAMES[11]+SEND_MESSAGE="mac_send_message"。规则照原装置:写类(ios_write_reminders/mobile_write_calendar/mac_write_notes/mac_draft_mail)要同意;发类(mac_send_mail、mac_send_message)逐封批准、绝不「总是」;mac_write_notes id+currentTitle=append(标题变了→报错请重读)否则新建要 title;draft 要 to 或 replyToId+body。
app_of(提醒事項/行事曆/聯絡人/備忘錄/訊息/郵件——自动化授权按 app)、describe(卡片文案)、specs12 条、is_mac_tool/is_write/is_send/label。jxa(osascript -l JavaScript,stdout/stderr 线程读,30s 超时 kill);permission_hint(-1743/not allowed→开 Privacy_Automation 设定页+指路「在 AnyBot 底下打开 {app}」)。- JS_HELPERS(clip/iso/has);12 段 JXA:Reminders list+whose、Calendar 区间查/uid 找/写、Contacts name→email/phone(数字≥4 位比对)、Notes(byId 全文 20000、whose _or、append 验 currentTitle、新建
+
HTML 转义)、Mail(byId 全账号扫、inbox 扫 300 封、unreadOnly/days/query、draft M.reply 接原文/OutgoingMessage 寄出前 visible、send visible:false、accounts)、Messages(iMessage service→buddies.byName→send)。 - 非 mac→「這個工具只支援 macOS」。
测试锁(2+--ignored 1):write/send 分界+specs 数=12、输入规则(needs a title/currentTitle/needs to/body required)、mac_apps_read 实机。
intents.rs(捷徑優先於 GUI,C6)
动机:音量调小 GUI 9 步 2 分钟 vs shell 4 秒。模型只选名字,永不写命令(参数过语法才造脚本;「體積 set 999; rm -rf /」不存在)。
- INTENTS[6]:volume/wifi/lock/dark/trash(Darwin 或有桌面的 Linux)、eject(Darwin only)。headless 无音量(nobody hears);own_box 不登(facts_line 空)。
facts_line(computer 事实行每轮登捷径+语法,提示缓存;进 tools.rs 事实行)。script(name,arg):Windows→拒(C9 有手无捷径);case "$(uname -s)"一脚本两系统(旧版 Mac 命令落 Linux 分支全语法错——注释记载);volume up/down(±15 夹 0-100)/mute toggle/unmute/set(0-100 is_num,裸数字也收)、wifi on/off(networksetup/nmcli/rfkill)、lock(pmset/loginctl/xset)、dark(osascript appearance/gsettings)、trash(Finder empty/~/.local/share/Trash rm)、eject。tool:/bin/sh -c + PATH=cloudbox::tool_path();非零退出→「回来了但没成功」句。
测试锁(3):两系统名单+headless 空+own_box 空+facts 关键词;words_never_reach_the_shell(101/-5/; rm -rf/$(id)/x/999/up; reboot 全拒);every_script_is_a_script_the_shell_can_read(sh -n 只析不跑、两分支各长度、全 INTENTS 覆盖——旧「跑 lock 测试过」是语法错都当成功的假绿)。
迁移:desktop.rs→platform(三平台共用,ad 依赖);axread/axwrite→platform-mac(FFI);macapps→platform-mac;intents→platform(脚本表跨 mac/linux)。ask_permission/spawn_reaped 依赖→platform-mac::ffi;marks::Element/leaks_secret→core::vision;cloudbox::tool_path→platform。