noracu 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +409 -0
- package/README.md +34 -22
- package/README.zh-CN.md +36 -24
- package/SECURITY.md +15 -8
- package/docs/architecture.md +58 -27
- package/docs/tools.md +45 -34
- package/docs/usage.md +180 -64
- package/imctl/README.md +16 -13
- package/imctl/pyproject.toml +1 -1
- package/imctl/src/imctl/__init__.py +1 -1
- package/imctl/src/imctl/cli.py +152 -38
- package/imctl/src/imctl/gestures.py +21 -25
- package/imctl/src/imctl/input.py +187 -50
- package/imctl/src/imctl/window.py +10 -3
- package/package.json +5 -4
- package/src/mac-ax.js +2397 -0
- package/src/server.mjs +1645 -483
package/README.zh-CN.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
For English, see [README.md](README.md).
|
|
11
11
|
|
|
12
|
-
一个 stdio MCP server。agent 对界面做一次快照、拿到带索引的元素列表,然后按 `element_index` 点击或输入,而不是用原始像素坐标——Mac 层和 Browser 层是同一套 observe/act
|
|
12
|
+
一个 stdio MCP server。agent 对界面做一次快照、拿到带索引的元素列表,然后按 `element_index` 点击或输入,而不是用原始像素坐标——Mac 层和 Browser 层是同一套 observe/act 协议。实验性的 iPhone 层在 OCR 文本和归一化坐标上跑同一个 observe → act 循环。
|
|
13
13
|
|
|
14
14
|

|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ For English, see [README.md](README.md).
|
|
|
21
21
|
|
|
22
22
|
| 层 | 工具 | 底层 | 状态 |
|
|
23
23
|
|---|---|---|---|
|
|
24
|
-
| **Mac** |
|
|
24
|
+
| **Mac** | 20 个(`mac_*`) | macOS 辅助功能 API(`src/mac-ax.js`,JXA)、cliclick、screencapture | stable |
|
|
25
25
|
| **Browser** | 12 个(`browser_*`) | Playwright(持久化 profile) | stable |
|
|
26
26
|
| **iPhone** | 14 个(`phone_*`) | 经随包附带的 imctl 驱动 iPhone Mirroring(Python + pyobjc) | experimental |
|
|
27
27
|
|
|
@@ -31,14 +31,15 @@ iPhone 层是实验性的,驱动 imctl 随包附带(在 `imctl/`)。它需
|
|
|
31
31
|
|
|
32
32
|
noracu 是本地的"手",不是"脑"。决策由你的 MCP client(Claude Desktop、Claude Code、Cursor)做;本 server 只在这台机器上观察与动作。
|
|
33
33
|
|
|
34
|
-
- **server 完全在本机运行。** 无云服务、无 API key、无遥测、无 postinstall 脚本。唯一运行期依赖是 Playwright。noracu 自身不发任何网络请求;唯一的自动网络行为是首次 `browser_launch` 时一次性下载 Chromium(`NORACU_DISABLE_AUTO_INSTALL=1`
|
|
35
|
-
- **按语义动作,而非像素。** 观察返回 accessibility 树(Mac
|
|
34
|
+
- **server 完全在本机运行。** 无云服务、无 API key、无遥测、无 postinstall 脚本。唯一运行期依赖是 Playwright。noracu 自身不发任何网络请求;唯一的自动网络行为是首次 `browser_launch` 时一次性下载 Chromium(`NORACU_DISABLE_AUTO_INSTALL=1` 可关闭)。设置 `NORACU_ALLOW_CDP=1` 后,它还会访问自己在 127.0.0.1 上打开的 DevTools 端口(连接其他本地回环端口需 `NORACU_ALLOW_CDP=any`)。你让浏览器打开的页面当然会被抓取,你的 MCP client 也仍会把工具结果(截图、OCR 文本)发给它所用的模型。
|
|
35
|
+
- **按语义动作,而非像素。** 观察返回 accessibility 树(Mac 直接经 macOS 辅助功能 API 读取——在我们的测试机上,500 个元素的窗口约 0.15 秒)或 ARIA 树(browser)的带索引列表——是文本,不是截图。动作引用 `element_index`;索引 30 秒后过期。Mac 上每个索引背后都有身份证据(窗口 ID、子节点路径、角色、标识符、名称),每次动作前先重新识别元素;browser 则重校验 tag/name/href/位置。元素已消失或已变化时返回 `element_no_longer_valid`,而不是点错位置。树不够用时才用截图。
|
|
36
|
+
- **如实报告结果。** Mac 动作优先用元素自己的辅助功能动作(按下、选中、设值、插入文本——不移动指针、不抢焦点,文字输入不受输入法影响);只有命中检测确认该点确实落在元素上,才会发送物理点击。每个输入动作(Mac、浏览器和 iPhone)的结果都写明是否送达(观察到变化为 `delivered_verified`,另有 `delivered_unverified`、`not_delivered`,以及超时或中途失败时的 `unknown`)以及能否安全重试;Mac 动作还会列出它打开的 sheet、对话框或菜单。
|
|
36
37
|
- **一个循环,三个面。** Mac 原生应用和持久化 profile 的浏览器共用 `element_index` 协议(观察一棵树、按索引动作)。实验性的 iPhone 层在 Apple 的 iPhone Mirroring 上跑同一个 observe → act 循环,用的是 OCR 文本和归一化坐标——因为手机不向 Mac 暴露 accessibility 树。
|
|
37
38
|
- **用你真实的会话。** 你已登录的浏览器 profile、你的 Mac 应用——不是托管的 VM。与云端 computer-use 相比:两者没有谁普遍更可靠,只是失败方式不同。noracu 把屏幕留在你本机。
|
|
38
39
|
- **真正能关掉的开关。** `NORACU_READ_ONLY=1`(只观察,默认拒绝)、`NORACU_DISABLE_EVAL=1`、以及默认封禁 `file://`。见 [安全](#安全)。
|
|
39
|
-
- **可验证。**
|
|
40
|
+
- **可验证。** 端到端测试(`npm test`;不依赖硬件的部分在 macos-latest 上跑 CI)、MIT 许可;server 由 `src/server.mjs` 和 Mac 辅助功能引擎 `src/mac-ax.js` 组成。
|
|
40
41
|
|
|
41
|
-
**不适合的场景:** 你需要多个浏览器标签页或会话(当前仅单会话)、你不在 macOS 上(Mac 与 iPhone 层仅限 macOS;Browser 层跨平台)、或你现在就需要一个成品级的 iPhone 层(它已随包附带,但仍是实验性——而且 Apple 在欧盟不提供 iPhone Mirroring)。如果你只需要浏览器自动化,playwright-mcp 有 noracu
|
|
42
|
+
**不适合的场景:** 你需要多个浏览器标签页或会话(当前仅单会话)、你不在 macOS 上(Mac 与 iPhone 层仅限 macOS;Browser 层跨平台)、或你现在就需要一个成品级的 iPhone 层(它已随包附带,但仍是实验性——而且 Apple 在欧盟不提供 iPhone Mirroring)。如果你只需要浏览器自动化,playwright-mcp 有 noracu 还没有的 tab 管理和 selector API。如果你要在 Windows 或 Linux 上操作桌面应用,agent-desktop(Vercel Labs)经各系统的辅助功能 API 覆盖 macOS、Windows 和 Linux;noracu 的桌面层只支持 macOS。noracu 的价值在于:一个 agent 通过同一个 server 操作 Mac 应用、浏览器和 iPhone。
|
|
42
43
|
|
|
43
44
|
## 快速开始
|
|
44
45
|
|
|
@@ -48,7 +49,7 @@ noracu 是本地的"手",不是"脑"。决策由你的 MCP client(Claude Des
|
|
|
48
49
|
|
|
49
50
|
```bash
|
|
50
51
|
npm install noracu # server 位于 node_modules/noracu/src/server.mjs
|
|
51
|
-
brew install cliclick # Mac 输入所需(mac_click/
|
|
52
|
+
brew install cliclick # 物理 Mac 输入所需(mac_key、mac_paste、mac_drag 及物理路径的 mac_click/mac_type)
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
或从源码:`git clone https://github.com/sgInnora/noracu.git && cd noracu && npm install && npm test`(加 `NORACU_CI=1` 可跳过依赖硬件的检查)。
|
|
@@ -68,7 +69,7 @@ Claude Desktop(`~/Library/Application Support/Claude/claude_desktop_config.jso
|
|
|
68
69
|
}
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
Claude Code:`claude mcp add noracu -- /绝对路径/TO/node /绝对路径/noracu/src/server.mjs`
|
|
72
|
+
Claude Code:`claude mcp add noracu -- /绝对路径/TO/node /绝对路径/TO/noracu/src/server.mjs`
|
|
72
73
|
|
|
73
74
|
用 `which node` 找到你的 node 路径(Apple Silicon:`/opt/homebrew/bin/node`;Intel:`/usr/local/bin/node`;nvm:对应版本路径)。便捷写法,仅当 Node 已在 GUI `PATH` 上时:`"command": "npx", "args": ["-y", "noracu"]`。
|
|
74
75
|
|
|
@@ -76,25 +77,28 @@ Claude Code:`claude mcp add noracu -- /绝对路径/TO/node /绝对路径/nora
|
|
|
76
77
|
|
|
77
78
|
**3. 把 macOS 权限授给宿主应用,而不是 `node`。** 系统设置 → 隐私与安全性 → **辅助功能(Accessibility)** 和 **屏幕录制(Screen Recording)**(macOS 15 为"屏幕与系统音频录制")→ 勾选宿主(Claude Desktop / Cursor / 你的终端)。noracu 不会出现在这里。授权后退出并重开宿主。
|
|
78
79
|
|
|
79
|
-
**4. 验证。**
|
|
80
|
+
**4. 验证。** 先调用 `mac_status`——它会报告宿主是否有辅助功能和屏幕录制权限、能否找到 cliclick。然后让 Finder 在最前,调用 `mac_ax_state`(无参数)——它返回带索引的 accessibility 树;索引有效 30 秒。浏览器冒烟测试(不需要 Accessibility):`browser_launch`(首次运行会下载 Chromium,除非 `NORACU_DISABLE_AUTO_INSTALL=1`)→ `browser_navigate` → `browser_snapshot` → 按索引 `browser_click`。
|
|
80
81
|
|
|
81
82
|
### 排障
|
|
82
83
|
|
|
83
84
|
| 现象 | 原因 / 解决 |
|
|
84
85
|
|---|---|
|
|
85
|
-
| `mac_*`
|
|
86
|
+
| `mac_*` 报 `permission_denied: Accessibility permission is missing…`(0.2 之前为错误 **-1719**) | Accessibility 没授给**宿主**应用——授权后退出并重开宿主;`mac_status` 可查看状态 |
|
|
86
87
|
| 截图全黑 | Screen Recording 没授给宿主——授权后退出并重开 |
|
|
87
88
|
| `ENOENT` 提到 cliclick | `brew install cliclick`(或设 `NORACU_CLICLICK`) |
|
|
88
89
|
| GUI 宿主报 `spawn node` / `npx` `ENOENT` | 配置里改用绝对 `node` 路径——nvm/volta/homebrew 的 shim 不在 GUI `PATH` 上 |
|
|
89
90
|
| 首次 `browser_launch` 卡住 | 一次性 Chromium 下载;或自动安装被关闭(`NORACU_DISABLE_AUTO_INSTALL=1`)→ 执行 `npx playwright install chromium` |
|
|
90
91
|
| `phone_*` 报 `imctl unavailable: no python3 with pyobjc found` | 给某个 python3 装 pyobjc(`python3 -m pip install pyobjc-framework-Quartz pyobjc-framework-Vision pyobjc-framework-AppKit`,通常选 Homebrew 的 python3)或设 `NORACU_PYTHON`——见[iPhone 层](#iphone-层实验性) |
|
|
91
|
-
| `phone_*` 被拒并报 `mirror_not_live: …`("Connection Paused"、"iPhone in Use"
|
|
92
|
+
| `phone_*` 被拒并报 `mirror_not_live: …`("Connection Paused"、"iPhone in Use"、"not running")或 `mirror_state_unknown: …` | 镜像未运行、已暂停或状态无法读取——锁上 iPhone、放在 Mac 旁,检查 `phone_status`,再调用 `phone_launch`(会启动镜像并点击 Resume) |
|
|
92
93
|
| `phone_launch` 报 `mirror_setup_required` | iPhone Mirroring 正显示设置或欢迎页(例如升级 macOS 后首次启动)——请在 iPhone Mirroring 窗口里自己完成;noracu 从不替你点击这类页面 |
|
|
93
94
|
| `imctl_timeout: phone … did not finish within …s` | Mac 负载过高或系统卡住——操作可能已部分执行,重试前先看 `phone_status` / `phone_screenshot`(`phone_open` 超时后 noracu 会回到主屏幕);在此期间 server 仍会响应其他调用 |
|
|
94
|
-
| `input_busy: …` | 前一个手机或 Mac 操作占用输入队列超过 60
|
|
95
|
+
| `input_busy: …` | 前一个手机或 Mac 操作占用输入队列超过 60 秒(或 `NORACU_PHONE_TIMEOUT_MS` + 15 秒);本次调用什么都没做——重试即可 |
|
|
95
96
|
| 已安装的 App,`phone_open` 却报 app not found | 它只点 Spotlight「Top Hit」卡片里的标签——名字要和手机图标下显示的一致(例如 `拼多多`,而不是 `Pinduoduo`)。已安装却报 "Spotlight showed no Top Hit",通常说明 iPhone 系统语言不是英文:`phone_open` 读的是 Spotlight 的 "Top Hit" 标签——把 `NORACU_TOPHIT_LABELS` 设成手机上显示的标签。报 `open_not_confirmed: … never showed up on the phone` 则是粘贴的名字没有到达手机(粘贴到 iPhone 可能要好几秒)——重试即可。`phone_open` 之后剪贴板里是 App 名字 |
|
|
96
|
-
| 输入的文本被重新空格化(如 "no ra cu") |
|
|
97
|
-
| `element_no_longer_valid` | 快照超过 30
|
|
97
|
+
| 输入的文本被重新空格化(如 "no ra cu") | 文字是以按键方式送出的(`mac_type` 用了 `mechanism: "physical"`,或焦点元素不接受辅助功能写入),同时 CJK 输入法在激活——用 `mac_type` 的默认方式,或用 `mac_paste` |
|
|
98
|
+
| `element_no_longer_valid` | 快照超过 30 秒,或元素已消失、已变化、所在窗口已关闭——重跑 `mac_ax_state` / `browser_snapshot` 并用新索引 |
|
|
99
|
+
| `occluded: … — on top: {…}` | 物理点击会落在别的东西上(另一个窗口、一个 sheet)——把目标窗口置前或关掉遮挡物;本次什么都没发送 |
|
|
100
|
+
| `ambiguous_window: … windows: […]` | 该应用有多个窗口且没有一个处于焦点——传 `window`(序号或标题)或 `mac_windows` 给出的 `window_id` |
|
|
101
|
+
| `policy_denied: "cmd-q" …` | `mac_key` 拒绝退出 / 注销 / 锁屏 / 强制退出 / 立即删除 / 清空废纸篓类组合键,除非传 `force: true`;要退出应用请用 `mac_app` |
|
|
98
102
|
|
|
99
103
|
启动时拒绝 Node 18——请用 Node ≥ 20。Claude Desktop 可能为每个使用面各起一个 noracu 进程;它们共享浏览器 profile,所以同一时间只从一个面启动浏览器。
|
|
100
104
|
|
|
@@ -102,7 +106,7 @@ Claude Code:`claude mcp add noracu -- /绝对路径/TO/node /绝对路径/nora
|
|
|
102
106
|
|
|
103
107
|
## iPhone 层(实验性)
|
|
104
108
|
|
|
105
|
-
noracu 可以经 Apple 的 **iPhone Mirroring** 操作真实 iPhone。agent 在 Mac 上用 OCR 观察(`phone_screenshot`、`phone_ocr`、`phone_find`),按 0–1 归一化坐标动作(`phone_tap`、`phone_swipe`、`phone_scroll`),用粘贴输入文字(`phone_type`),按名字打开 App(`phone_open`)。这不是 `element_index`:手机不向 Mac 暴露 accessibility 树,所以点击落在 OCR 识别出文字的位置。驱动(imctl,Python,MIT,约
|
|
109
|
+
noracu 可以经 Apple 的 **iPhone Mirroring** 操作真实 iPhone。agent 在 Mac 上用 OCR 观察(`phone_screenshot`、`phone_ocr`、`phone_find`),按 0–1 归一化坐标动作(`phone_tap`、`phone_swipe`、`phone_scroll`),用粘贴输入文字(`phone_type`),按名字打开 App(`phone_open`)。这不是 `element_index`:手机不向 Mac 暴露 accessibility 树,所以点击落在 OCR 识别出文字的位置。驱动(imctl,Python,MIT,约 3,500 行)随包附带在 `imctl/`。
|
|
106
110
|
|
|
107
111
|
**Apple 的要求**([support.apple.com/120421](https://support.apple.com/120421)):搭载 Apple 芯片或 T2 芯片、运行 macOS 15 或更高版本的 Mac;运行 iOS 18 或更高版本并设置了密码的 iPhone;两台设备登录同一个开启双重认证的 Apple 账户;蓝牙和 Wi-Fi 打开;Mac 没有共享互联网连接、没有使用 AirPlay 或随航(Sidecar)。**iPhone 必须锁定并靠近 Mac**——解锁 iPhone 或退出 iPhone Mirroring 都会结束会话。iPhone Mirroring 目前在欧盟不可用。一次只能一台 Mac 和一台 iPhone;摄像头和麦克风不会被镜像。
|
|
108
112
|
|
|
@@ -110,22 +114,24 @@ noracu 可以经 Apple 的 **iPhone Mirroring** 操作真实 iPhone。agent 在
|
|
|
110
114
|
|
|
111
115
|
**Python:** 驱动需要一个能导入 pyobjc(Quartz、Vision、AppKit)的 python3。设置 `NORACU_PYTHON`,或由 noracu 在首次调用 `phone_*` 时依次探测一次 `/opt/homebrew/bin/python3`、`/usr/local/bin/python3`、`python3`、`/usr/bin/python3`。Apple 自带的 `/usr/bin/python3` 通常没有 pyobjc;常见可用配置是 Homebrew 的 python3 加 `python3 -m pip install pyobjc-framework-Quartz pyobjc-framework-Vision pyobjc-framework-AppKit`。
|
|
112
116
|
|
|
113
|
-
**镜像状态:** `phone_status` 返回 `live`(手机画面正在推流)、`overlay`(iPhone Mirroring 显示的替代文字,如 "Connection Paused"、"iPhone in Use")、`paused`(该覆盖层带 Resume 按钮)和 `setup`(需要用户自己完成的设置或欢迎页——noracu
|
|
117
|
+
**镜像状态:** `phone_status` 返回 `live`(手机画面正在推流)、`overlay`(iPhone Mirroring 显示的替代文字,如 "Connection Paused"、"iPhone in Use")、`paused`(该覆盖层带 Resume 按钮)和 `setup`(需要用户自己完成的设置或欢迎页——noracu 从不点击)。判定依据是窗口结构和形状(镜像窗口是竖长或横长的手机形状,设置页接近正方形),不是文字。镜像不在线时,所有手机输入工具(`phone_tap`、`phone_longpress`、`phone_swipe`、`phone_scroll`、`phone_type`、`phone_key`、`phone_open`、`phone_home` 和 `phone_app_switcher`)都会以 `mirror_not_live` 拒绝——在镜像已暂停或未开启时不会先抢焦点——而不是点到覆盖层上;状态仍无法判定时以 `mirror_state_unknown` 拒绝(`phone_ocr` / `phone_find` 的输出首行会给出警告)。镜像闲置一段时间后会暂停;`phone_launch` 会把它置前并点击 Resume。
|
|
114
118
|
|
|
115
119
|
**隐私:** 手机上显示的一切——通知、短信、邮件、一次性验证码——都会变成工具输出,由你的 MCP client 发给它所用的模型。开始前打开专注模式、打开一个无关紧要的 App,并先用 `NORACU_READ_ONLY=1`(`phone_status`、`phone_screenshot`、`phone_ocr`、`phone_find` 仍可用;所有手机输入都会被拒绝)。iPhone Mirroring 设置好后,iPhone 的通知也会出现在 Mac 上。
|
|
116
120
|
|
|
117
121
|
**首次成功路径:** `phone_status` → 若 `live` 不是 `true` 先 `phone_launch` → `phone_screenshot` → `phone_ocr` → `phone_find` + `phone_tap`。
|
|
118
122
|
|
|
119
|
-
**已知限制:** 点击落在 OCR 识别到文字的位置,重复或识别错的标签可能点错(若 Spotlight 的「Top Hit」里是同名的联系人或网站,`phone_open` 分辨不出它不是 App);`phone_scroll` 用触控板式的滚动事件移动列表(竖向的 `phone_swipe` 拖拽不会滚动列表——它用于主屏翻页这类手势);在一套实测环境(iPhone 17 Pro Max 运行 iOS 27.0.1,Mac 运行 macOS 26.6.2)上,iPhone Mirroring 在所有 View 尺寸下都把手机画面画得比窗口大约 17%,右列和最底行被裁掉、无法点到;在显示器之间移动窗口、切换主屏、重开 App 都无效,主要怀疑是 iOS 27 与 macOS 26 版本错位——边缘附近点不中时先看 `phone_screenshot`;`phone_open` 把 App 名输入 Spotlight,只有当 Spotlight 的「Top Hit」卡片显示的正是这个名字时才点击(同名的网页建议、网站和设置行一律不点),否则回到主屏——它读的是 Spotlight 的英文 "Top Hit" 标签,iPhone 设为其他语言时找不到任何 App,除非用 `NORACU_TOPHIT_LABELS` 指定那个标签;`phone_home` / `phone_app_switcher`
|
|
123
|
+
**已知限制:** 点击落在 OCR 识别到文字的位置,重复或识别错的标签可能点错(若 Spotlight 的「Top Hit」里是同名的联系人或网站,`phone_open` 分辨不出它不是 App);`phone_scroll` 用触控板式的滚动事件移动列表(竖向的 `phone_swipe` 拖拽不会滚动列表——它用于主屏翻页这类手势);在一套实测环境(iPhone 17 Pro Max 运行 iOS 27.0.1,Mac 运行 macOS 26.6.2)上,iPhone Mirroring 在所有 View 尺寸下都把手机画面画得比窗口大约 17%,右列和最底行被裁掉、无法点到;在显示器之间移动窗口、切换主屏、重开 App 都无效,主要怀疑是 iOS 27 与 macOS 26 版本错位——边缘附近点不中时先看 `phone_screenshot`;`phone_open` 把 App 名输入 Spotlight,只有当 Spotlight 的「Top Hit」卡片显示的正是这个名字时才点击(同名的网页建议、网站和设置行一律不点),否则回到主屏——它读的是 Spotlight 的英文 "Top Hit" 标签,iPhone 设为其他语言时找不到任何 App,除非用 `NORACU_TOPHIT_LABELS` 指定那个标签;`phone_home` / `phone_app_switcher` 在镜像在线时走 iPhone Mirroring 菜单(英文 macOS 下无需 python,仅在菜单项不存在时回退 `imctl` 手势,菜单超时返回 `menu_unknown` 而不补发第二次手势),且只报告指令已发送(`screen not verified`)。
|
|
120
124
|
|
|
121
125
|
## 环境变量
|
|
122
126
|
|
|
123
127
|
| 变量 | 默认 | 作用 |
|
|
124
128
|
|---|---|---|
|
|
125
|
-
| `NORACU_READ_ONLY` | 未设 | `=1` 只观察模式:默认拒绝的白名单仅
|
|
129
|
+
| `NORACU_READ_ONLY` | 未设 | `=1` 只观察模式:默认拒绝的白名单仅 18 个观察 + 浏览器生命周期工具;所有 click/type/paste/key/eval 类工具被拒(`mac_clipboard_read`、`mac_notifications` 以及 `condition: "notification"` 的 `mac_wait` 也被拒;`mac_ax_state` / `mac_find` 也不开启 `web_accessibility`) |
|
|
126
130
|
| `NORACU_DISABLE_EVAL` | 未设 | `=1` 让 `browser_evaluate`(任意 JS)被调用时报错(仍在列表中) |
|
|
127
131
|
| `NORACU_ALLOW_FILE_URL` | 未设 | `=1` 允许 `browser_navigate` 打开 `file://` URL(默认封禁) |
|
|
128
132
|
| `NORACU_DISABLE_AUTO_INSTALL` | 未设 | `=1` 跳过首次 `browser_launch` 的 Chromium 自动安装 |
|
|
133
|
+
| `NORACU_ALLOW_CDP` | 未设 | `=1` 允许 `mac_app` 带 `cdp_port` 启动,并允许 `browser_launch` 连接由本 `noracu` 进程打开的 `cdp_port`(需对应 PID 存活且 `webSocketDebuggerUrl` 一致);`=any` 还允许 `browser_launch` 连接 127.0.0.1 上的任意外部 DevTools 端口(在 `NORACU_READ_ONLY=1` 下始终拒绝) |
|
|
134
|
+
| `NORACU_TRACE` | 未设 | 一个文件路径:每次工具调用写一行 JSON(`{ts, tool, args, ms, error, code}`——仅记录参数名与长度及错误码前缀,从不记录参数文本、结果文本或错误详情;以 `0600` 和 `O_NOFOLLOW` 打开,拒绝符号链接) |
|
|
129
135
|
| `NORACU_CLICLICK` | `/opt/homebrew/bin/cliclick` | cliclick 二进制路径 |
|
|
130
136
|
| `NORACU_PYTHON` | 自动探测 | 运行随包 iPhone 驱动的 python3;须能导入 pyobjc(Quartz、Vision、AppKit)。未设置时依次尝试 `/opt/homebrew/bin/python3`、`/usr/local/bin/python3`、`python3`、`/usr/bin/python3` |
|
|
131
137
|
| `NORACU_IMCTL_DIR` | 包内 `imctl/` | 覆盖驱动位置(仅开发用) |
|
|
@@ -141,13 +147,18 @@ noracu 以你 MCP client 的权限运行。它会在本机点击、输入、粘
|
|
|
141
147
|
"env": { "NORACU_READ_ONLY": "1", "NORACU_DISABLE_EVAL": "1" }
|
|
142
148
|
```
|
|
143
149
|
|
|
144
|
-
- **`NORACU_READ_ONLY=1`** 是安全的首次运行模式。它拒绝不在
|
|
150
|
+
- **`NORACU_READ_ONLY=1`** 是安全的首次运行模式。它拒绝不在 18 项白名单内的一切工具(观察类 + 独立的 `browser_launch`/`browser_navigate`/`browser_close`;即使设了 `NORACU_ALLOW_CDP`,带 `cdp_port` 的 `browser_launch` 也会被拒);所有 click/type/paste/eval 被拒,`mac_clipboard_read`、`mac_notifications` 和 `condition: "notification"` 的 `mac_wait` 也被拒,且 `mac_ax_state` 与 `mac_find` 不会在目标应用上开启 `web_accessibility`。`browser_navigate` 在白名单内,仍会加载 URL。
|
|
145
151
|
- **`NORACU_DISABLE_EVAL=1`** 让 `browser_evaluate` 被调用时报错(仍列在 `tools/list` 中)。snapshot、click、type 保留。
|
|
146
152
|
- **`file://` 被拒**,除非 `NORACU_ALLOW_FILE_URL=1`,这样浏览器 agent 无法通过导航到 `~/Documents` 来读本地文件。(仅校验初始导航 URL;重定向不校验——见 SECURITY.md。)
|
|
147
|
-
- **焦点守卫:** 给 `
|
|
148
|
-
- **失效元素保护:** `element_index` 不是坐标。它 30
|
|
149
|
-
-
|
|
150
|
-
-
|
|
153
|
+
- **焦点守卫:** 给 `mac_paste` / `mac_key`(以及以按键方式输入时的 `mac_type`)传 `app`,当该应用不在最前时输入被拒。不传 `app` 则守卫关闭。`mac_type` 默认走辅助功能写入指定元素或该应用的焦点元素,根本不发按键;焦点是按钮、列表或 sheet 时,它也不会退回到发按键。
|
|
154
|
+
- **失效元素保护:** `element_index` 不是坐标。它 30 秒后过期;Mac 上的索引不会被之后的快照复用。Mac 元素只在它被看到的那个窗口或打开的菜单里重新识别(按窗口 ID),并且要在窗口里的同一位置、同样的有名祖先之下、同一表格行中;没有名称也没有标识符的元素必须仍在原处。browser 点击重校验 tag/name/href/位置。否则返回 `element_no_longer_valid`。
|
|
155
|
+
- **物理点击前做命中检测:** 必须用指针的 Mac 点击或拖动,只有该点上的元素就是目标时才发送——辅助功能无法判断时,要求该点最上层的屏幕窗口正是元素所在的同一个窗口(按窗口 ID,未被同一应用的另一个窗口遮挡);否则返回 `occluded` 并说明上面是什么。这样的点击之后再敲的键,只在元素所在应用确实位于前台时才发送。
|
|
156
|
+
- **后台窗口:** 语义 Mac 动作对你没在看的窗口同样有效。这正是目的(不抢焦点),但也意味着 agent 可能在你看不到的地方动作——留意结果里的 `delivery`,高风险应用请先关掉。
|
|
157
|
+
- **危险按键、菜单与退出受保护:** `mac_key` 拒绝退出 / 注销 / 锁屏 / 强制退出 / 立即删除 / 清空废纸篓类组合键,除非 `force: true`;`mac_menu_command` 对菜单快捷键应用同一列表,且拒绝苹果菜单项,除非 `force: true`。`mac_app` 和 `mac_menu_command` 都从不退出 Finder、Dock、loginwindow 等会话进程和 MCP 宿主本身;`mac_app` 强制退出需要 `force: true`。
|
|
158
|
+
- **DevTools 端口需显式开启:** `mac_app` / `browser_launch` 带 `cdp_port` 需要 `NORACU_ALLOW_CDP=1`(连接非 `noracu` 自己打开的端口需 `NORACU_ALLOW_CDP=any`;`NORACU_READ_ONLY=1` 下始终拒绝),只绑定 127.0.0.1,规范化 `.app` 路径并拒绝已在运行的应用,且在 `~/.noracu/cdp-profiles` 下给 Chrome 系浏览器单独的 `0700` profile。端口打开期间,任何本地进程都能控制该应用(127.0.0.1 没有按用户隔离)。
|
|
159
|
+
- **剪贴板、密码框和通知属于隐私:** `mac_paste` 会把用户原来的剪贴板(所有条目和类型)放回去,且从不复制密码管理器标记为隐藏的内容——粘贴后改为清空剪贴板;`mac_clipboard_read` 从不返回隐藏内容;`mac_set_value` 作用于安全密码框(`AXSecureTextField`)时从不回显值;`mac_notifications` 原样返回通知文字。`mac_clipboard_read`、`mac_notifications` 以及等待通知的 `mac_wait` 在只读模式下均被拒绝。
|
|
160
|
+
- **iPhone 画面就是模型输入:** `phone_screenshot` / `phone_ocr` / `phone_find` 会返回手机上显示的一切——通知、短信、一次性验证码。请用专注模式和无关紧要的 App,并先用 `NORACU_READ_ONLY=1`(允许观察手机、拒绝手机输入)。镜像不在线(`mirror_not_live`)或状态无法读取(`mirror_state_unknown`)时,手机输入同样会被拒绝。
|
|
161
|
+
- **防注入 JXA 与 stdin 传参:** 辅助功能引擎(`src/mac-ax.js`)是静态脚本,整条请求以 JSON 从 stdin 传入——参数只是数据,从不成为脚本源码——且 `mac_type`(默认路径)、`mac_set_value`、`mac_paste` 以及 `phone_type` / `phone_find` / `phone_open` 都经 stdin 传入文字,不会出现在进程列表里(`imctl type` 也不回显文字)。有回归测试覆盖。
|
|
151
162
|
|
|
152
163
|
这些开关不会让被观察的内容变得可信。截图文字、accessibility 名称、页面内容都是喂给你模型的**不可信输入**——别让它们覆盖任务指令。完整威胁模型与逐条状态见 [SECURITY.md](SECURITY.md)(英文)。
|
|
153
164
|
|
|
@@ -161,7 +172,8 @@ noracu 以你 MCP client 的权限运行。它会在本机点击、输入、粘
|
|
|
161
172
|
|
|
162
173
|
- Browser:tab 管理(list / select / close)
|
|
163
174
|
- 动作词汇(browser):`hover`、`set_value`、`wait_for`
|
|
164
|
-
-
|
|
175
|
+
- 测量 `skeleton` + `root` 下钻相对完整快照的 token 消耗
|
|
176
|
+
- 菜单栏时钟不对辅助功能可见时,也能打开通知中心的历史列表
|
|
165
177
|
- iPhone:在 OCR 区域上提供 `element_index`,点击前重新校验文字
|
|
166
178
|
|
|
167
179
|
## 维护
|
package/SECURITY.md
CHANGED
|
@@ -8,22 +8,29 @@ Treat every tool call as privileged.
|
|
|
8
8
|
|
|
9
9
|
| # | Threat | Vector | Status | Mitigation / notes |
|
|
10
10
|
|---|---|---|---|---|
|
|
11
|
-
| 1 | **Prompt injection → arbitrary code execution** | Observed content (web page text, AX tree titles, OCR output) contains instructions that trick the agent into calling tools with malicious arguments | **Mitigated
|
|
12
|
-
| 2 | **Arbitrary local control** | `mac_click` / `mac_type` / `mac_paste` can operate password managers, banking pages, terminals | **Inherent** | Use client-side confirmation gates for high-stakes targets; see recommendations below. Optional `app` focus guard on `
|
|
13
|
-
| 3 | **Arbitrary JS in browser** | `browser_evaluate` executes any JavaScript in the page context | **
|
|
14
|
-
| 4 | **Input validation gaps** | Malformed arguments (NaN coordinates, oversized strings, `javascript:` URLs) | **Mitigated** | `validateArgs`
|
|
15
|
-
| 5 | **Screenshot privacy** | `mac_screenshot` / `phone_screenshot` capture the full screen / phone display | **Inherent** | Run in a dedicated macOS user account or virtual display for untrusted automation |
|
|
16
|
-
| 6 | **iPhone operations** | `phone_tap` / `phone_type` can interact with payment and SMS-verification UIs; taps go to OCR coordinates with no element re-check | **Inherent** | Keep Mirroring off for untrusted sessions; `NORACU_READ_ONLY=1` refuses all phone input; input
|
|
11
|
+
| 1 | **Prompt injection → arbitrary code execution** | Observed content (web page text, AX tree titles, OCR output) contains instructions that trick the agent into calling tools with malicious arguments | **Mitigated** | The Mac accessibility engine `src/mac-ax.js` is a static script that takes its whole request as JSON on stdin — parameters are data, never script source (regression-tested in `test/e2e.mjs`); the remaining inline JXA (scroll wheel) takes clamped numbers through argv |
|
|
12
|
+
| 2 | **Arbitrary local control** | `mac_click` / `mac_type` / `mac_paste` can operate password managers, banking pages, terminals | **Inherent** | Use client-side confirmation gates for high-stakes targets; see recommendations below. Optional `app` focus guard on `mac_paste` / `mac_key` (and `mac_type` keystrokes) refuses input unless that app — compared by process, not by name — is frontmost; `mac_type` keystrokes after a click on an `element_index` go out only if the element's app is then frontmost. An `element_index` is re-identified inside the window it came from (by CGWindowID) before any action, and a physical click or drag (both ends) is sent only when a hit test shows the point reaches the element, or — when the hit test is inconclusive — when the topmost on-screen window at the point is that same window (by CGWindowID, not covered by another window of the same app; `occluded` otherwise). `mac_key` refuses quit / log-out / lock / force-quit / delete-immediately / empty-Trash chords without `force`; `mac_menu_command` applies the same chord list, refuses Apple-menu items without `force`, and never quits the MCP host or a session process. |
|
|
13
|
+
| 3 | **Arbitrary JS in browser** | `browser_evaluate` executes any JavaScript in the page context | **Partially mitigated** | Set `NORACU_DISABLE_EVAL=1`; `browser_evaluate` then returns an error on every call (it stays listed in `tools/list`) |
|
|
14
|
+
| 4 | **Input validation gaps** | Malformed arguments (NaN coordinates, oversized strings, `javascript:` URLs) | **Mitigated** | `validateArgs` validates every tool's arguments (types, ranges, enums, string lengths, URL schemes) before any subprocess runs; `tools/list` emits `required` arrays derived from non-optional arguments |
|
|
15
|
+
| 5 | **Screenshot privacy** | `mac_screenshot` / `phone_screenshot` capture the full screen / phone display | **Inherent** | Run in a dedicated macOS user account or virtual display for untrusted automation. `NORACU_READ_ONLY=1` prevents side effects (and skips `enableWebAccessibility` on apps), not screen secrecy: `mac_screenshot` still shows visible notification banners on screen, and Notification Center accessibility reads via `mac_ax_state` / `mac_find` are not blocked by bundle id |
|
|
16
|
+
| 6 | **iPhone operations** | `phone_tap` / `phone_type` can interact with payment and SMS-verification UIs; taps go to OCR coordinates with no element re-check | **Inherent** | Keep Mirroring off for untrusted sessions; `NORACU_READ_ONLY=1` refuses all phone input; all phone input (including `phone_home` / `phone_app_switcher`, via `require_enabled` on the menu item or `imctl`'s `_require_live`) fails closed with `mirror_not_live` when not live — without stealing focus when paused or closed — or `mirror_state_unknown` when the state cannot be read, checks that iPhone Mirroring is frontmost before synthesized events, and never falls back to a second gesture after an uncertain menu timeout (`menu_unknown`); optional `expect` OCR anchor gates coordinate/key/type actions; "Authenticate automatically" lets anyone at the unlocked Mac start mirroring |
|
|
17
17
|
| 12 | **Phone screen as model input** | `phone_screenshot` / `phone_ocr` / `phone_find` return notifications, messages, mail and one-time codes visible on the phone | **Inherent** | Use a Focus mode and a neutral app; the MCP client sends tool results to its model; iPhone notifications also reach the Mac once Mirroring is set up |
|
|
18
18
|
| 7 | **Supply chain** | malicious PRs / dependency poisoning after open-sourcing | **Partially mitigated** | Review all PRs touching `src/server.mjs` argument handling; lockfile committed; no `postinstall` scripts; the only runtime download is the one-time Playwright `chromium` install triggered by `browser_launch`, which can be disabled with `NORACU_DISABLE_AUTO_INSTALL=1` |
|
|
19
|
-
| 8 | **Local file read via browser** | `browser_navigate` to a `file://` URL, then `browser_read` exfiltrates local files | **Mitigated
|
|
19
|
+
| 8 | **Local file read via browser** | `browser_navigate` to a `file://` URL, then `browser_read` exfiltrates local files | **Mitigated** | `file://` blocked at the `browser_navigate` argument unless `NORACU_ALLOW_FILE_URL=1` (initial URL only; redirects fall under threat 9) |
|
|
20
20
|
| 9 | **HTTP GET side effects** | navigation triggers logout links, one-time tokens, private-network / cloud-metadata endpoints | **Not mitigated** | No URL blocklist (redirects and DNS rebinding defeat pre-navigation checks); client-side policy |
|
|
21
|
-
| 10 | **Clipboard clobbering by mac_paste** | `mac_paste` overwrites the clipboard with the pasted text | **Partially mitigated** |
|
|
21
|
+
| 10 | **Clipboard clobbering by mac_paste** | `mac_paste` overwrites the clipboard with the pasted text | **Partially mitigated** | One engine call copies every clipboard item and type aside (inside that process), writes the text marked `org.nspasteboard.TransientType`, sends ⌘V only if the clipboard and the frontmost app are unchanged, and puts the user's items back after the paste shows in the same focused element (held at least 0.3 s; else after a 1 s hold) and only if nothing else wrote to the clipboard meanwhile; when the keystroke may not have completed it is not put back. An item marked concealed (on any clipboard item) is never copied: the clipboard is cleared after the paste. Universal Clipboard content and clipboards over 64 MB are refused unless `force`. Remaining: for up to about a second the clipboard holds the pasted text (a clipboard manager that ignores the transient marker can record it); an app that reads the clipboard after the hold receives the restored content; when the app stops answering the pasted text is left on the clipboard |
|
|
22
|
+
| 13 | **Actions on windows the user cannot see** | Semantic Mac actions (press, set value, insert text) work on background windows without moving the pointer or taking focus | **Inherent** | Results report `delivery` and `retry`; review the client's tool log; close high-stakes apps during unattended runs |
|
|
23
|
+
| 14 | **Quitting apps** | `mac_app` quit can close apps; force-quit loses unsaved work | **Mitigated** | Graceful quit by default and verified by the process ending; `force: true` required to force-quit; session processes (Finder, Dock, loginwindow, SystemUIServer, Control Center, Notification Center, …) and the MCP host process are never quit |
|
|
24
|
+
| 15 | **DevTools port exposure** | `mac_app` launch with `cdp_port` opens a Chromium/Electron app's remote-debugging port on `127.0.0.1` (no per-user isolation); any local process can then control that app | **Partially mitigated** | Off unless `NORACU_ALLOW_CDP=1` (or `=any`); `browser_launch` with `cdp_port` is refused under `NORACU_READ_ONLY=1` even with `NORACU_ALLOW_CDP` set; bound to `127.0.0.1`; only for a fresh launch after canonicalizing `.app` paths (`realpath`, trailing slash stripped — a running app is refused, never quit for you); with `NORACU_ALLOW_CDP=1`, `browser_launch` attaches only when the port was recorded by this `noracu` process, its PID is still alive, and `/json/version`'s `webSocketDebuggerUrl` matches (attaching to any other loopback port requires `NORACU_ALLOW_CDP=any`); `~/.noracu` and `cdp-profiles` are created `0700`; Chrome-family browsers get a separate profile under `~/.noracu/cdp-profiles`; standalone `browser_launch` is refused while a CDP session is open; the port closes when the app quits |
|
|
25
|
+
| 16 | **Clipboard and notification content** | `mac_clipboard_read` / `mac_notifications` return clipboard text, images, file paths and notification text to the model | **Partially mitigated** | Items marked `org.nspasteboard.ConcealedType` (password managers) are never returned; `mac_clipboard_read`, `mac_notifications`, and `mac_wait` with `condition: "notification"` are refused under `NORACU_READ_ONLY=1` (`NORACU_READ_ONLY=1` prevents side effects, not screen secrecy: `mac_screenshot` still shows visible notification banners and Notification Center AX reads are not blocked by bundle id); notification actions reject empty `id` / `expected_app` / `expected_title`, return `notification_not_found` when absent, and require an id or an index plus a re-checked app/title fingerprint; `mac_set_value` on `AXSecureTextField` never echoes the value |
|
|
26
|
+
| 17 | **Text in process arguments** | Text sent as keystrokes (`mac_type` physical path: `cliclick t:…`) is visible in the process list while it runs | **Partially mitigated** | The accessibility path (`mac_type` default, `mac_set_value`), `mac_paste`, and `phone_type` / `phone_find` / `phone_open` (imctl reads the text from stdin) pass text on stdin, and `mac_set_value` on `AXSecureTextField` and `imctl type` never echo typed text; only the keystroke fallback uses argv. A phone call's `expect` text is still an argument |
|
|
22
27
|
| 11 | **Untrusted observation content** | ARIA snapshots, AX trees, OCR, page text contain attacker-controlled text | **Not mitigated** | The MCP client must treat tool results as data, never as instructions |
|
|
23
28
|
|
|
24
29
|
## Hardening recommendations
|
|
25
30
|
|
|
26
31
|
- Set `NORACU_DISABLE_EVAL=1` unless you actively need `browser_evaluate`.
|
|
32
|
+
- Leave `NORACU_ALLOW_CDP` unset unless you drive an Electron app's web contents; quit the app when done so its DevTools port closes.
|
|
33
|
+
- `NORACU_TRACE` writes only `{ ts, tool, args, ms, error, code }` — argument names and sizes, error code prefix, never argument text, result text, or error messages — and opens the file `0600` with `O_NOFOLLOW` (refusing symlinks).
|
|
27
34
|
- Before an agent touches the iPhone layer: turn on a Focus, open a neutral app,
|
|
28
35
|
and start with `NORACU_READ_ONLY=1`. Prefer "Ask every time" in iPhone
|
|
29
36
|
Mirroring settings unless you need unattended sessions.
|
package/docs/architecture.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
## Design principles
|
|
6
6
|
|
|
7
7
|
1. **Observe/act separation**:
|
|
8
|
-
- Observe: `ax_state` (Accessibility/ARIA tree
|
|
9
|
-
- Act: click / drag / scroll / key / type / paste / evaluate, by
|
|
8
|
+
- Observe: `ax_state` (Accessibility/ARIA tree) or `screenshot` (visual), chosen per step
|
|
9
|
+
- Act: click / drag / scroll / key / type / paste / evaluate, by element reference (or coordinates where supported; `mac_drag` takes `from_index` / `to_index` only)
|
|
10
10
|
2. **Local-first**: no cloud, no API key — every capability comes from local tools
|
|
11
11
|
3. **Layer autonomy**: each layer is largely independent; a missing dependency (e.g. imctl) disables only that layer. The one deliberate cross-layer path is the iPhone layer's Home / App Switcher, which prefer the iPhone Mirroring menu (driven through the Mac layer) and fall back to imctl gestures.
|
|
12
12
|
|
|
@@ -14,19 +14,35 @@ The observe/act vocabulary follows the action/observation split popularized by C
|
|
|
14
14
|
|
|
15
15
|
## Layer implementations
|
|
16
16
|
|
|
17
|
-
### Mac layer (
|
|
17
|
+
### Mac layer (20 tools)
|
|
18
|
+
|
|
19
|
+
Accessibility goes through `src/mac-ax.js`, a static JXA script run as `osascript -l JavaScript src/mac-ax.js` with one JSON request on stdin and one JSON reply on stdout. It calls the Accessibility C API (`AXUIElementCopyMultipleAttributeValues`, `AXUIElementPerformAction`, `AXUIElementSetAttributeValue`, `AXUIElementCopyElementAtPosition`, …) through the Objective-C bridge instead of System Events: a Finder window of about 500 elements reads in about 0.15 s on our test Mac. Each call is a short-lived process run asynchronously under a timer, like the iPhone driver, so a hung app cannot freeze the server.
|
|
18
20
|
|
|
19
21
|
| Tool | Implementation |
|
|
20
22
|
|---|---|
|
|
21
|
-
| `
|
|
22
|
-
| `
|
|
23
|
-
| `mac_click
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
|
|
29
|
-
`
|
|
23
|
+
| `mac_ax_state` | engine `snapshot`: walks a window (or `surface`: menu bar, open menu, sheet, alert, dialog, popover, focused element, whole app) to a logical depth (layout wrappers without content do not count and are hidden by `compact`); `interactive` keeps actionable elements; `skeleton` maps 3 levels with `children_count`, `root` drills into one element and extends the same snapshot. Chromium/Electron apps get `AXManualAccessibility` switched on when read unless `web_accessibility: false` or `NORACU_READ_ONLY=1` (never `AXEnhancedUserInterface`, which alters window behaviour) |
|
|
24
|
+
| `mac_find` / `mac_get` | engine `find` (role / title / value / text / AXIdentifier, substring or exact; honours `web_accessibility` like `mac_ax_state`) / `get` (one element, live: full value, states, actions, settable attributes) |
|
|
25
|
+
| `mac_click` | element_index: the element's own action (`AXPress` / `AXConfirm` / `AXPick` / `AXOpen`, `AXShowMenu` for right-click, or selecting a row) when it has one; otherwise `cliclick` at its center after a system-wide hit test — or, when inconclusive, confirming the topmost on-screen window there is that same window by CGWindowID (`occluded` otherwise). Raw x,y: `cliclick` |
|
|
26
|
+
| `mac_type` | `AXSelectedText` (insert at the caret) or `AXValue` (`replace`) on element_index or the focused element; keystrokes (`cliclick t:`) only when accessibility reports no focus or a text view it cannot write |
|
|
27
|
+
| `mac_set_value` | by role: `AXValue` for text (never read back or echoed on `AXSecureTextField`), sliders, combo boxes; `AXPress` for toggles (only when the state differs); `AXExpanded` / `AXDisclosing`; `AXSelected`; pop-up and menu buttons open their menu, press the one matching option, or close it again |
|
|
28
|
+
| `mac_scroll` | no index: wheel event at the frontmost window; scroll area: wheel event at its center (hit-tested); other element: `AXScrollToVisible` |
|
|
29
|
+
| `mac_drag` | `cliclick` dd/dm/du between `from_index` and `to_index` (no raw coordinates); both ends are re-identified and hit-tested |
|
|
30
|
+
| `mac_key` | `cliclick` key sequence; quit / log-out / lock / force-quit / delete-immediately / empty-Trash chords need `force` |
|
|
31
|
+
| `mac_paste` | one engine call (`opPaste`): focus guard, clipboard items copied aside in-process, text written (transient), ⌘V via `cliclick` (NSTask, argv), restore after evidence or a 1 s hold, guarded by the change count |
|
|
32
|
+
| `mac_menu_command` | engine `menu`: `AXPress` on the item found by title or `Menu > Item` path in the app's own menu bar; Apple-menu items and refused shortcut chords need `force`, and session processes or the MCP host are never quit |
|
|
33
|
+
| `mac_wait` | engine `wait`: polls a window / text / element / menu / sheet / app / notification condition (`notification` refused under `NORACU_READ_ONLY=1`) every 250 ms inside one process |
|
|
34
|
+
| `mac_app` | `open` for launch / activate; `NSRunningApplication` hide / unhide / terminate / forceTerminate; quit is verified by the pid ending. `cdp_port`: `open -n -a … --args --remote-debugging-port=… --remote-debugging-address=127.0.0.1` |
|
|
35
|
+
| `mac_window` | `AXRaise` / `AXMain` / `AXMinimized` / `AXPosition` / `AXSize` / `AXFullScreen` on the window found by CGWindowID or app + index/title |
|
|
36
|
+
| `mac_status` / `mac_apps` / `mac_windows` | `AXIsProcessTrusted`, `NSWorkspace`, `NSScreen`, `CGWindowListCopyWindowInfo` (titles from accessibility when Screen Recording is missing) |
|
|
37
|
+
| `mac_screenshot` | `screencapture -x` (main display, `-D` display, `-l` one window by CGWindowID, `-R` region) |
|
|
38
|
+
| `mac_clipboard_read` | `NSPasteboard`: file URLs, PNG/TIFF image, or text; `org.nspasteboard.ConcealedType` items are withheld |
|
|
39
|
+
| `mac_notifications` | the Notification Center process's `AXNotificationCenter*` groups: id (`AXIdentifier`), app, title, subtitle, body, named actions, `center_opened` / `center_was_open` (`open_center: true` skips clicking the clock when positive panel evidence shows it is already open; absent or invalidated `-25202` targets return `notification_not_found`) |
|
|
40
|
+
|
|
41
|
+
**Element identity.** An AXUIElement cannot outlive the engine process, so each `element_index` stores evidence: pid, the container (a window by its CGWindowID from `_AXUIElementGetWindow`, an open menu by its frame, the menu bar, or the app), the child-index path, a fingerprint (role, subrole, AXIdentifier, stable name — a label, never the value), the frame relative to the container, the labels of its ancestors (window-level titles such as a web page's are left out because they change with content; digits are ignored), the child count at every level of its path (shape), and an item key — the first texts under the element itself or its nearest ancestor that has any, never the container nor a web area, toolbar, scroll area or split group (static text, link labels, and a text field's value only when a cell or row lies between that ancestor and the field, i.e. table content such as Finder's name column — a form field's value is what gets typed, not identity; never button titles). An item key that two look-alikes would share (rows that only climb to the same section heading) is not recorded: it tells nothing apart. Uniqueness is counted over every element the walk visited, also those a filtered or interactive-only snapshot does not show; a walk that stopped early or was drilled into part of the container cannot know it, so its elements count as duplicated. An action follows the path and checks all of it; the shape may differ only when the element's own item (itself or its parent) vouches for it, and digits in a unique element's item are ignored (counters, relative times). A labelled element whose path no longer leads to it may be found by search: a unique one only near where it was (64 px), under the same ancestors and in the same item; a duplicated one only by its item key (so a re-sorted list resolves to the same item, and a look-alike that arrived after the snapshot is not taken for it); an unlabelled element is never searched for. Path steps fetch one child by index instead of whole child lists. No container, no match or several matches is `element_no_longer_valid` — never a look-alike. A search never enters the menu bar unless the element was seen there (a closed menu's items can still be pressed). Indexes are unique for the life of the server (one counter across snapshots) and last 30 s; `snapshot_id` is optional and must match the index. Known limits: in an open context menu, an identical menu opened at the same place for another row cannot be told apart; a status word that changes inside an element's item ("Saving…" → "Saved", a validation message) makes the index stale — take a new snapshot; a unique element whose whole item is replaced in place by one that differs only in digits ("Invoice 12" → "Invoice 13") is not told apart.
|
|
42
|
+
|
|
43
|
+
**Delivery.** Accessibility return codes do not prove an effect (Finder returns success for an action that does not exist), so actions read the element and its app before and after: value, selection, state, focus, windows, sheets, open menus, frontmost app. A change is `delivered_verified`; none is `delivered_unverified`; refusals before anything was sent are `not_delivered` with `retry=safe`; an app that did not answer is `unknown` with `retry=unsafe`.
|
|
44
|
+
|
|
45
|
+
`mac_key` / `mac_paste` (and `mac_type` when it sends keystrokes) accept an optional `app`: when set, the tool verifies that app is frontmost before synthesizing input and returns `focus_lost` (sending nothing) if it is not.
|
|
30
46
|
|
|
31
47
|
### Browser layer (12 tools)
|
|
32
48
|
|
|
@@ -39,12 +55,19 @@ A single persistent Playwright 1.58 session (one browser, one context), held in
|
|
|
39
55
|
|
|
40
56
|
### iPhone layer (14 tools)
|
|
41
57
|
|
|
42
|
-
The bundled imctl driver (`imctl/`, Python) runs as a subprocess (`<python3> -m imctl.cli`, PYTHONPATH = `imctl/src`, no bytecode written). The interpreter is `NORACU_PYTHON` or the first of `/opt/homebrew/bin/python3`, `/usr/local/bin/python3`, `python3`, `/usr/bin/python3` that imports pyobjc (Quartz, Vision, AppKit); probed once, lazily, on the first `phone_*` call. **Experimental**: when no such python exists, tools return a structured one-line `imctl unavailable` error with the install command rather than crashing the server (`phone_home`/`phone_app_switcher` still work via the iPhone Mirroring menu).
|
|
58
|
+
The bundled imctl driver (`imctl/`, Python) runs as a subprocess (`<python3> -m imctl.cli`, PYTHONPATH = `imctl/src`, no bytecode written). The interpreter is `NORACU_PYTHON` or the first of `/opt/homebrew/bin/python3`, `/usr/local/bin/python3`, `python3`, `/usr/bin/python3` that imports pyobjc (Quartz, Vision, AppKit); probed once, lazily, on the first `phone_*` call. **Experimental**: when no such python exists, tools return a structured one-line `imctl unavailable` error with the install command rather than crashing the server (`phone_home`/`phone_app_switcher` still work via the iPhone Mirroring menu on English macOS while the mirror is live; non-English macOS falls back to `imctl`).
|
|
59
|
+
|
|
60
|
+
- Observe: `phone_ocr` (coordinates + text), `phone_screenshot` (captures the Mirroring window by CGWindow id, so a covered window still yields its own pixels; never a screen-region capture — `capture_failed` instead), `phone_find` (locates text; text passed on stdin)
|
|
61
|
+
- Act: `phone_tap/longpress/swipe` (normalized 0-1 coordinates), `phone_home` / `phone_app_switcher` (iPhone Mirroring menu by bundle id first, imctl gesture fallback when the English menu item is absent), `phone_scroll`, `phone_type` (clipboard-based via stdin, IME-safe, never echoes typed text), `phone_key`
|
|
62
|
+
- Session: `phone_status` (running, window, window_id, onscreen, frontmost, live, overlay, paused, setup — read from the window's AX structure and shape: a live mirror is one empty AXHostingView group; an overlay such as "Connection Paused" or "iPhone in Use" adds static text and a button; a setup screen sits in a nearly square window), `phone_launch` (ensure running + frontmost, clicks the single Resume button of a paused overlay, refuses setup screens with `mirror_setup_required`), `phone_open` (Spotlight via the iPhone Mirroring shortcut, paste the name via stdin, tap only an exact OCR label inside Spotlight's "Top Hit" card, reading `NORACU_TOPHIT_LABELS`; otherwise back to the Home Screen)
|
|
63
|
+
- Safety: while the mirror is not live or its state cannot be confirmed, every phone input tool (`phone_tap`, `phone_longpress`, `phone_swipe`, `phone_scroll`, `phone_type`, `phone_key`, `phone_open`, `phone_home`, `phone_app_switcher`, plus CLI `imctl page`) fails closed with `mirror_not_live` or `mirror_state_unknown` without stealing focus when paused or closed; `phone_ocr` / `phone_find` prefix a warning. The phone layer has no `element_index`: OCR coordinates are normalized to the window, and nothing re-verifies the target before a tap (optional `expect` checks pre-action OCR text).
|
|
43
64
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
65
|
+
## Concurrency and lifecycle
|
|
66
|
+
|
|
67
|
+
- **Child processes.** Every subprocess (the accessibility engine, imctl, cliclick, screencapture, `open`, `ps`, the Chromium installer) runs asynchronously under its own timer and in its own process group; on expiry the group gets SIGTERM, then SIGKILL after 1.5 s. Nothing blocks the event loop, so `ping` and `tools/list` are answered while a call runs.
|
|
68
|
+
- **Input queue.** `phone_*` and Mac input tools go through one FIFO queue (they share the real mouse, keyboard, clipboard and windows). A queued call that the client cancelled, or that waited longer than 60 s (or `NORACU_PHONE_TIMEOUT_MS` + 15 s), is dropped without acting (`input_busy`). `mac_clipboard_read`, `mac_notifications` and every `phone_*` tool (reads included: they capture the mirroring window) stay in the queue.
|
|
69
|
+
- **Observations.** `mac_ax_state`, `mac_find`, `mac_get`, `mac_windows`, `mac_apps`, `mac_screenshot`, `mac_status` and `mac_wait` do not join the queue: each waits for the inputs queued before it to finish (or returns `input_busy` past the queue limit), then runs, so it sees their effect and later inputs are not held up behind it.
|
|
70
|
+
- **Shutdown.** When the client closes stdin, or on SIGTERM / SIGINT / SIGHUP: no new calls, queued calls are dropped, no new child process starts, children get SIGTERM then SIGKILL, browsers (also one still starting) are closed (a CDP attachment only disconnects), and the process exits within 3 s.
|
|
48
71
|
|
|
49
72
|
## Configuration
|
|
50
73
|
|
|
@@ -53,24 +76,32 @@ The bundled imctl driver (`imctl/`, Python) runs as a subprocess (`<python3> -m
|
|
|
53
76
|
| `NORACU_PYTHON` | auto-probe (see iPhone layer) | python3 that runs the bundled driver; must import pyobjc |
|
|
54
77
|
| `NORACU_IMCTL_DIR` | bundled `imctl/` (`src/../imctl`) | override the driver location (development only) |
|
|
55
78
|
| `NORACU_CLICLICK` | `/opt/homebrew/bin/cliclick` | path to cliclick |
|
|
56
|
-
| `NORACU_READ_ONLY` | unset (full control) | `=1` observation-only mode: a default-deny allowlist of
|
|
79
|
+
| `NORACU_READ_ONLY` | unset (full control) | `=1` observation-only mode: a default-deny allowlist of 18 tools — the observe tools (`mac_screenshot`, `mac_ax_state`, `mac_find`, `mac_get`, `mac_status`, `mac_apps`, `mac_windows`, `mac_wait` except `condition: "notification"`, `browser_snapshot`, `browser_screenshot`, `browser_read`, `phone_status`, `phone_screenshot`, `phone_ocr`, `phone_find`) plus standalone browser session lifecycle (`browser_launch`, `browser_navigate`, `browser_close`; `mac_ax_state` / `mac_find` skip `web_accessibility`). `browser_navigate` still issues a page-load request. All input-synthesis tools (click/drag/type/key/paste/tap/swipe/evaluate/…) plus `mac_clipboard_read` and `mac_notifications` are rejected |
|
|
57
80
|
| `NORACU_DISABLE_EVAL` | unset (enabled) | `=1` makes `browser_evaluate` return an error on every call (kill switch for arbitrary JS execution; it stays listed) |
|
|
58
81
|
| `NORACU_DISABLE_AUTO_INSTALL` | unset (auto-install) | `=1` stops `browser_launch` from auto-running `playwright install chromium` on a clean machine; returns an error prompting a manual install instead |
|
|
59
82
|
| `NORACU_ALLOW_FILE_URL` | unset (blocked) | `=1` permits `browser_navigate` to open `file://` URLs (blocked by default to avoid local-file exfiltration via the browser layer) |
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
| `NORACU_ALLOW_CDP` | unset (blocked) | `=1` permits `mac_app` launch with `cdp_port` and `browser_launch` with `cdp_port` for a port this process opened (live PID, matching `webSocketDebuggerUrl`; Playwright `connectOverCDP` to 127.0.0.1); `=any` also lets `browser_launch` attach to any loopback DevTools port; refused under `NORACU_READ_ONLY=1`; `browser_close` then only disconnects |
|
|
84
|
+
| `NORACU_PHONE_TIMEOUT_MS` | 30000 (45000 for `phone_open` / `phone_type`) | time limit for each iPhone-layer step, 1000–600000 ms (`imctl_timeout` on expiry) |
|
|
85
|
+
| `NORACU_OCR_LANGUAGES` | `zh-Hans,en-US` | comma-separated Vision OCR language codes for the iPhone screen, in priority order |
|
|
86
|
+
| `NORACU_TOPHIT_LABELS` | `Top Hit` | comma-separated Spotlight Top Hit section label(s) that `phone_open` looks for |
|
|
87
|
+
| `NORACU_TRACE` | unset | file path for a JSON-lines call log (`{ts, tool, args, ms, error, code}` — argument names/sizes and error code prefix only, never argument text, result text, or error messages; opened `0600` with `O_NOFOLLOW`, refusing symlinks) |
|
|
88
|
+
|
|
89
|
+
## Known limitations (v0.2)
|
|
90
|
+
|
|
91
|
+
- Every Mac-layer call starts a short-lived `osascript` (and `cliclick` for physical input); reads take roughly 0.1–0.2 s on our test Mac, an action with its before/after check 0.3–0.8 s. A resident engine process could keep elements alive between calls and cut this further
|
|
92
|
+
- Notification Center's history is listed only while it is open; opening it needs the menu-bar clock, which accessibility does not expose on every macOS version
|
|
93
|
+
- No snapshot diffing; `skeleton` + `root` drill-down and `interactive` keep observations small instead
|
|
94
|
+
- Single browser session with one active tab and no tab switching: a tab the page opens itself (`window.open`, `target=_blank`) is not followed; another tab becomes active only after the active one closes
|
|
95
|
+
- The iPhone layer requires iPhone Mirroring to be online, with the iPhone locked and near the Mac (unlocking ends mirroring; Apple: unavailable in the EU); OCR accuracy depends on screen content; `phone_open` reads Spotlight's English "Top Hit" label unless `NORACU_TOPHIT_LABELS` is set
|
|
67
96
|
- macOS-only (Mac/iPhone layers); the Browser layer is cross-platform
|
|
68
97
|
|
|
69
98
|
## Roadmap (v2 candidates)
|
|
70
99
|
|
|
71
|
-
- ~~element_index coordinate system~~ (
|
|
100
|
+
- ~~element_index coordinate system~~ (v0.1.0) and ~~one index counter across snapshots~~ (v0.2.0); next: snapshot diffing
|
|
101
|
+
- Physical clicks performed inside the engine process right after the hit test (closes the short gap between the check and the click)
|
|
102
|
+
- A simpler identity model to compare against the current one on the same tests (no digit folding in item keys)
|
|
72
103
|
- axState diffing (incremental observation, saves tokens)
|
|
73
104
|
- Browser tool gaps (select_text/set_value/hover/wait_for…) + tab management
|
|
74
|
-
-
|
|
105
|
+
- A resident accessibility engine (one long-lived process instead of one per call; true element handles between calls)
|
|
75
106
|
- Multi-session architecture (browser_id + tab_id)
|
|
76
107
|
- Security hardening: sensitive-app foreground detection, action audit log
|