Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools
Rust ai-agentautomationclaudeclaude-codedockeriosiphonelinuxmcpmcp-servermodel-context-protocolrustwebdriveragent
docs: match the code after 0.2.4 and the review fixes (#91)
Qinghe Lic1768a58ca39
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1d7a8f9..7d9c35d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,26 @@ All notable changes to this project are documented here. The format is based on## [Unreleased]+### Changed++- The daemon is ready about 10 s sooner after it restarts or restarts WDA (1.4 s instead of 11 s on an iPhone): the outcome of starting WDA is taken as soon as it is there, not at the next check.+- Waiting for the "Enable UI Automation" passcode, WDA is launched again every half minute instead of every three minutes. The prompt only comes up while WDA is being launched (for about 45 s, and not on every launch), so it is now on the phone most of the time instead of a quarter of it.+- A stuck WDA is noticed after one unanswered request and a 5 s check, so a tool call waits about 35 s for the restart instead of 90 s.+- Commands, MCP calls and the viewer wait (up to 10 s) for a daemon that is restarting instead of failing; a daemon that isn't running is still reported at once.+- Too many wrong login tokens (20 in a minute) no longer lock out the right ones: a right token always gets in, and only wrong ones get 429. Before, anyone who could reach the page could cut off `mcp --url`, remote `task` commands and a remote task's agent.+- `--url` takes `http://` only for this machine: tokens aren't sent in the clear to another one (use `https://`), and redirects aren't followed.++### Fixed++- A confirmation (`iphone_confirm`, or a step outside a task's apps) no longer cancels the user's pause or takeover: it is asked once the task runs again. Two at once are asked in turn; before, the first was counted as rejected and the second couldn't be answered.+- A step the agent sent just before the user paused or took over no longer runs after it; a tap of the user's sent just before handing back no longer runs after that.+- After the user handed back, the agent has to have actually seen the screen (a screenshot that worked) before acting.+- A read-only token no longer makes the daemon unlock the phone (reading the elements of a locked phone now says it is locked).+- Removing or replacing a login token now also ends the picture, task events, `/mcp` streams and task leases opened with it, within 5 s.+- The control page's agent works in a private directory (under `$XDG_RUNTIME_DIR`, 0700) instead of one in `/tmp` that another user could make first and fill.+- The viewer no longer stops accepting connections after an error such as running out of file descriptors; connections that never finish their request are dropped after 10 s (a machine on the network has at most 8 of them at a time); `GET /api/agent/tasks/events` no longer crashes the connection.+- Task logs cut short by a power failure are removed instead of piling up.+## [0.2.4] - 2026-11-14### Upgrade notes@@ -19,14 +39,14 @@ All notable changes to this project are documented here. The format is based on- Every `task` subcommand takes `--url` (or `IPHONE_CONTROL_URL`): `list`, `events`, `pause`, `resume`, `takeover`, `handback`, `stop`, `approve` and `reject` work through another machine's viewer, with the login token in `IPHONE_CONTROL_VIEWER_TOKEN`.- Named login tokens, read-only ones among them: `iphone-control viewer token add <name> [--read-only]`, `list`, `show <name> [--new]`, `remove <name>`. A read-only token can watch the picture, the device's state and tasks; every action (taps, typing, starting, pausing or confirming tasks, switching devices, `/mcp`) is refused, and the page hides them. The task log records which token controlled it (`viewer:<name>`). Tokens moved to `viewer-tokens.json` and the earlier one became `owner`, so nobody logs in again after upgrading; adding, replacing and removing tokens takes effect at once, without restarting the viewer.- Tasks opened from another machine: `iphone-control task run --url https://<that machine>:8200 -- <command>` (the login token in `IPHONE_CONTROL_VIEWER_TOKEN`), or `POST /api/agent/tasks/open` directly, whose event stream is the lease. The agent on the other machine gets only the task's token: `/mcp` takes the token of an active task (header `Iphone-Control-Task-Token`), so it can act on the phone for that task but can't reach pausing or confirming, and can't approve itself.-- The viewer and its `/mcp` need a login, from this machine too (the viewer can't tell a local browser from a visit forwarded by frp, cloudflared or another reverse proxy). The token is made on the first start and kept in `viewer-token` in the data directory (0600); `iphone-control viewer token` shows it with links that log in here and on the local network and the command to connect to the HTTP MCP, and `--new` replaces it. A browser stays logged in for 30 days; programs and MCP clients send `Authorization: Bearer <token>`. After too many wrong tokens (20 in a minute) tokens aren't checked for a minute. The CLI, `iphone-control mcp` (stdio) and `task run` use the local Unix socket and are unaffected.-- MCP over HTTP: `/mcp` (Streamable HTTP) on the viewer's port serves the same tools as `iphone-control mcp`, for clients that only take a URL and for agents on another computer on the local network (`--lan`, over HTTPS), e.g. `claude mcp add --transport http iphone http://127.0.0.1:8200/mcp`. A task's agent sends the task's token in the `Iphone-Control-Task-Token` header. No login, as for the viewer; `--mcp off` (`IPHONE_CONTROL_VIEWER_MCP=off`) turns it off.-- The viewer opened to the local network (`--lan`) now speaks HTTPS, on the same port: opened from another machine the picture can be H.264 or the phone's own HEVC instead of MJPEG, and traffic is encrypted. It uses a self-signed certificate made on this machine (kept in `viewer-tls/` in the data directory and reused); the browser warns the first time, so check the SHA-256 fingerprint shown at startup or by `service status` and go on. `--tls-cert`/`--tls-key` (`IPHONE_CONTROL_VIEWER_TLS_CERT`/`_KEY`) use a certificate of your own. `http://` from the network is redirected to `https://`; `http://127.0.0.1` on this machine works as before. `--tls off` (`IPHONE_CONTROL_VIEWER_TLS=off`) goes back to HTTP. It isn't a login: anyone on the network who can reach the page can still control the phone.+- The viewer and its `/mcp` need a login, from this machine too (the viewer can't tell a local browser from a visit forwarded by frp, cloudflared or another reverse proxy). The token is made on the first start and kept in `viewer-tokens.json` in the data directory (0600); `iphone-control viewer token` shows it with links that log in here and on the local network and the command to connect to the HTTP MCP, and `--new` replaces it. A browser stays logged in for 30 days; programs and MCP clients send `Authorization: Bearer <token>`. After too many wrong tokens (20 in a minute) wrong ones are answered with 429 for a minute. The CLI, `iphone-control mcp` (stdio) and `task run` use the local Unix socket and are unaffected.+- MCP over HTTP: `/mcp` (Streamable HTTP) on the viewer's port serves the same tools as `iphone-control mcp`, for clients that only take a URL and for agents on another computer on the local network (`--lan`, over HTTPS), e.g. `claude mcp add --transport http iphone http://127.0.0.1:8200/mcp`. A task's agent sends the task's token in the `Iphone-Control-Task-Token` header. It needs the viewer's login, like the page; `--mcp off` (`IPHONE_CONTROL_VIEWER_MCP=off`) turns it off.+- The viewer opened to the local network (`--lan`) now speaks HTTPS, on the same port: opened from another machine the picture can be H.264 or the phone's own HEVC instead of MJPEG, and traffic is encrypted. It uses a self-signed certificate made on this machine (kept in `viewer-tls/` in the data directory and reused); the browser warns the first time, so check the SHA-256 fingerprint shown at startup or by `service status` and go on. `--tls-cert`/`--tls-key` (`IPHONE_CONTROL_VIEWER_TLS_CERT`/`_KEY`) use a certificate of your own. `http://` from the network is redirected to `https://`; `http://127.0.0.1` on this machine works as before. `--tls off` (`IPHONE_CONTROL_VIEWER_TLS=off`) goes back to HTTP.- `iphone-control service viewer install` runs the viewer as a background service of its own that starts at login (`uninstall`, `start`, `stop`, `restart` too). It reads its port and whether it is open to the local network from the settings file (`IPHONE_CONTROL_VIEWER_PORT`, new; `IPHONE_CONTROL_VIEWER_LAN`; `IPHONE_CONTROL_VIEWER_LAN_HOSTS`, new) and keeps the installing shell's `PATH` to find `claude` and `codex`. Updates stop it and start it again; an automatic update waits while an AI task runs.- An AI task's agent can no longer pause, resume, take over, hand back or confirm its own task, so only a person answers out-of-scope steps and `iphone_confirm`. Control requests carrying the task's token (`IPHONE_CONTROL_TASK_TOKEN`) are refused, and so are those from an agent the control page or `task run` started, or any process it starts, even without the token or through the page's API. On macOS, calls through the page's API can't be traced to a process yet. Stopping a task is always allowed. The task's log records who controlled it (the page, the command line, the task's opener).- Navigate setup menus with arrow keys, confirm with Enter, or cancel with Esc. Number selection remains available, and basic terminals keep the line-by-line prompts.- Generate Bash, Zsh and Fish completion scripts with `iphone-control completions <shell>`, without starting the daemon or accessing a device.-- `iphone-control viewer --lan` (or `IPHONE_CONTROL_VIEWER_LAN=1`) also opens the control page to the local network, on the same port. There is no login yet: anyone on the network who can reach the machine can control the phone, so only use it on a trusted network. It only accepts connections from local-network addresses and only answers to this machine's own names; `--lan-host` adds another name. Opened at a network address the picture is MJPEG, since browsers only offer WebCodecs on localhost or HTTPS.+- `iphone-control viewer --lan` (or `IPHONE_CONTROL_VIEWER_LAN=1`) also opens the control page to the local network, on the same port, over HTTPS and behind the login (see above). It only accepts connections from local-network addresses and only answers to this machine's own names; `--lan-host` adds another name.- On the control page, a task can be limited to some apps before it starts (the App button next to the agent): in any other app each step waits for you, as with `task run --app`. The task card shows the scope, and running a task again keeps it.- AI tasks for any agent platform: `iphone-control task run -- <command>` runs a command in a task, and an `iphone-control mcp` it starts takes part (the control page shows its steps and can pause, take over, stop and confirm). `task list`, `task events`, `task pause`/`resume`/`takeover`/`handback`/`stop` and `task approve`/`reject` follow and steer tasks from the command line.- The control page picks up a task in progress: after a reload, and for tasks started elsewhere.diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.mdindex 8bd2b4c..ada66b2 100644--- a/CHANGELOG.zh-CN.md+++ b/CHANGELOG.zh-CN.md@@ -6,6 +6,26 @@## [Unreleased]+### 变更++- 守护进程重启、或重启 WDA 后就绪快了约 10 秒(iPhone 上从 11 秒降到 1.4 秒):WDA 启动的结果一出来就收,不再等下一轮巡检。+- 等「Enable UI Automation」密码时,每半分钟重新启动一次 WDA,原来是约 3 分钟一次。密码框只在启动 WDA 时出现(约 45 秒,且不是每次都出现),现在手机上大部分时间都有框可输,原来只有约四分之一的时间。+- WDA 卡死后,一个请求没应答、再用 5 秒确认一次就判定卡死,工具调用等重启约 35 秒,原来要 90 秒。+- 守护进程重启时,命令、MCP 调用和控制台会等它回来(最多 10 秒),不再直接失败;守护进程没在运行时照样马上报错。+- 输错登录令牌太多次(一分钟 20 次)后不再连正确的令牌也拒绝:正确的令牌总能进,只有错的返回 429。原来谁能连上页面,就能借此让 `mcp --url`、远端的 `task` 命令和远端任务的 agent 都连不上。+- `--url` 只有指向本机时才接受 `http://`:令牌不会明文发到另一台机器(请用 `https://`),也不再跟随跳转。++### 修复++- 确认(`iphone_confirm`,或任务范围外的一步)不再冲掉你的暂停或接管:等任务恢复运行后才问。同时出现两个确认时依次问;原来第一个会被记成拒绝,第二个无法回答。+- 你暂停或接管前 agent 刚发出的一步,不会在暂停或接管之后才执行;你交还前刚发出的点按,也不会在交还之后才执行。+- 你交还控制后,agent 必须真的看过屏幕(截图成功)才能操作。+- 只读令牌不会再让守护进程解锁手机(手机锁着时读元素会说明已锁屏)。+- 删除或更换登录令牌后,用它打开的画面、任务事件、`/mcp` 流和任务租约 5 秒内断开。+- 控制台启动的 agent 改在私有目录里工作(`$XDG_RUNTIME_DIR` 下,0700),不再用 `/tmp` 里别的用户能抢先建好、往里放文件的目录。+- 控制台遇到文件描述符用完这类错误后不会再停止接受连接;一直不发完请求的连接 10 秒后断开(局域网里每台机器同时最多 8 个);`GET /api/agent/tasks/events` 不再让连接崩溃。+- 断电时写了一半的任务记录会被删掉,不再越积越多。+## [0.2.4] - 2026-11-14### 升级注意事项@@ -19,14 +39,14 @@- `task` 的所有子命令都能加 `--url`(或设 `IPHONE_CONTROL_URL`):`list`、`events`、`pause`、`resume`、`takeover`、`handback`、`stop`、`approve`、`reject` 经另一台机器的控制台操作,登录令牌放在 `IPHONE_CONTROL_VIEWER_TOKEN`。- 有名字的登录令牌,可以是只读的:`iphone-control viewer token add <名字> [--read-only]`、`list`、`show <名字> [--new]`、`remove <名字>`。只读令牌能看画面、设备状态和任务,所有操作(点按、输入、开任务、暂停、确认、切换设备、`/mcp`)都被拒绝,页面上也不显示操作入口。任务记录里写下是哪个令牌做的控制(`viewer:<名字>`)。令牌改存在 `viewer-tokens.json`,原来的令牌成了 `owner`,升级后不用重新登录;增删、换令牌马上生效,不用重启控制台。- 从另一台机器开任务:`iphone-control task run --url https://<那台机器>:8200 -- <命令>`(登录令牌放在 `IPHONE_CONTROL_VIEWER_TOKEN`),或者直接调 `POST /api/agent/tasks/open`,返回的事件流就是租约。另一台机器上的 agent 只拿任务口令:`/mcp` 认进行中任务的口令(请求头 `Iphone-Control-Task-Token`),它能为这个任务操作手机,但碰不到暂停、确认这些控制接口,不能批准自己。-- 控制台和它的 `/mcp` 要登录了,本机也一样(控制台分不清本机的浏览器和经 frp、cloudflared 等反向代理转发进来的访问)。令牌第一次启动时生成,存在数据目录的 `viewer-token`(0600);`iphone-control viewer token` 显示令牌、本机和局域网的登录链接以及接入 HTTP MCP 的命令,`--new` 换一个新令牌。浏览器登录一次后记住 30 天;程序和 MCP 客户端用 `Authorization: Bearer <令牌>`。输错太多次(一分钟 20 次)会暂停校验一分钟。命令行、`iphone-control mcp`(stdio)和 `task run` 走本机的 Unix socket,不受影响。-- MCP over HTTP:控制台同一个端口上的 `/mcp`(Streamable HTTP)提供和 `iphone-control mcp` 一样的工具,只能填 URL 的客户端、局域网里另一台电脑上的 agent(`--lan`,走 HTTPS)都能接入,例如 `claude mcp add --transport http iphone http://127.0.0.1:8200/mcp`。任务里的 agent 在请求头 `Iphone-Control-Task-Token` 里带上任务口令。和控制台一样没有登录,`--mcp off`(`IPHONE_CONTROL_VIEWER_MCP=off`)关掉。-- 控制台对局域网开放(`--lan`)时改用 HTTPS,还是同一个端口:局域网里打开时画面也能用 H.264 或手机自己的 HEVC,不再退回 MJPEG,传输也加了密。默认用本机生成的自签证书(存在数据目录的 `viewer-tls/`,一直沿用),浏览器第一次打开会提示不受信任,核对启动时或 `service status` 显示的 SHA-256 指纹后继续;也可以用 `--tls-cert`/`--tls-key`(`IPHONE_CONTROL_VIEWER_TLS_CERT`/`_KEY`)换成自己的证书。局域网来的 `http://` 跳转到 `https://`,本机的 `http://127.0.0.1` 照旧。`--tls off`(`IPHONE_CONTROL_VIEWER_TLS=off`)恢复成 HTTP。这不是登录:局域网里能连上的人照样能操作手机。+- 控制台和它的 `/mcp` 要登录了,本机也一样(控制台分不清本机的浏览器和经 frp、cloudflared 等反向代理转发进来的访问)。令牌第一次启动时生成,存在数据目录的 `viewer-tokens.json`(0600);`iphone-control viewer token` 显示令牌、本机和局域网的登录链接以及接入 HTTP MCP 的命令,`--new` 换一个新令牌。浏览器登录一次后记住 30 天;程序和 MCP 客户端用 `Authorization: Bearer <令牌>`。输错太多次(一分钟 20 次)后,一分钟内错的令牌一律返回 429。命令行、`iphone-control mcp`(stdio)和 `task run` 走本机的 Unix socket,不受影响。+- MCP over HTTP:控制台同一个端口上的 `/mcp`(Streamable HTTP)提供和 `iphone-control mcp` 一样的工具,只能填 URL 的客户端、局域网里另一台电脑上的 agent(`--lan`,走 HTTPS)都能接入,例如 `claude mcp add --transport http iphone http://127.0.0.1:8200/mcp`。任务里的 agent 在请求头 `Iphone-Control-Task-Token` 里带上任务口令。和页面一样要登录;`--mcp off`(`IPHONE_CONTROL_VIEWER_MCP=off`)关掉。+- 控制台对局域网开放(`--lan`)时改用 HTTPS,还是同一个端口:局域网里打开时画面也能用 H.264 或手机自己的 HEVC,不再退回 MJPEG,传输也加了密。默认用本机生成的自签证书(存在数据目录的 `viewer-tls/`,一直沿用),浏览器第一次打开会提示不受信任,核对启动时或 `service status` 显示的 SHA-256 指纹后继续;也可以用 `--tls-cert`/`--tls-key`(`IPHONE_CONTROL_VIEWER_TLS_CERT`/`_KEY`)换成自己的证书。局域网来的 `http://` 跳转到 `https://`,本机的 `http://127.0.0.1` 照旧。`--tls off`(`IPHONE_CONTROL_VIEWER_TLS=off`)恢复成 HTTP。- `iphone-control service viewer install` 把控制台装成登录后自动启动的后台服务(还有 `uninstall`、`start`、`stop`、`restart`)。端口和是否对局域网开放读设置文件(新增 `IPHONE_CONTROL_VIEWER_PORT`;`IPHONE_CONTROL_VIEWER_LAN`;新增 `IPHONE_CONTROL_VIEWER_LAN_HOSTS`),并记下安装时终端的 `PATH` 以找到 `claude` 和 `codex`。升级时先停下它、升级完再启动;有 AI 任务在跑时自动升级会推迟。- AI 任务的 Agent 不能再自己暂停、继续、接管、交还或确认,越界确认和 `iphone_confirm` 只能由人回答。带任务口令(`IPHONE_CONTROL_TASK_TOKEN`)的控制请求会被拒绝;控制台和 `task run` 启动的 Agent,连同它再启动的进程,也会被拒绝,即使去掉了口令,或者调用控制台的接口。在 macOS 上,调用控制台接口的这条路还查不出是哪个进程。停止任务不受限制。任务记录里会写下谁做了控制(控制台、命令行、任务的发起方)。- 设置菜单支持方向键选择、Enter 确认和 Esc 取消,保留数字选择;基础终端继续使用逐行提示。- `iphone-control completions <shell>` 可生成 Bash、Zsh 和 Fish 补全脚本,不启动守护进程、不访问设备。-- `iphone-control viewer --lan`(或 `IPHONE_CONTROL_VIEWER_LAN=1`)让控制台也对局域网开放,还是同一个端口。还没有登录:局域网里任何能连上这台机器的人都能操作手机,只在可信的网络里开。只接受局域网地址来的连接,只认本机自己的名字和地址;`--lan-host` 可以再加名字。从局域网地址打开时画面是 MJPEG,因为浏览器只在 localhost 或 HTTPS 上提供 WebCodecs。+- `iphone-control viewer --lan`(或 `IPHONE_CONTROL_VIEWER_LAN=1`)让控制台也对局域网开放,还是同一个端口,走 HTTPS、要登录(见上文)。只接受局域网地址来的连接,只认本机自己的名字和地址;`--lan-host` 可以再加名字。- 控制台上开任务前可以限定 App 范围(Agent 旁边的 App 按钮):到了别的 App,每一步都先等你确认,和 `task run --app` 一样。任务卡片上显示范围,重新执行时沿用。- 任何 agent 平台都能用 AI 任务:`iphone-control task run -- <命令>` 在任务里运行命令,它启动的 `iphone-control mcp` 自动加入任务(控制台能看到每一步,可以暂停、接管、停止、确认)。`task list`、`task events`、`task pause`/`resume`/`takeover`/`handback`/`stop`、`task approve`/`reject` 在命令行里查看和控制任务。- 控制台会接上正在进行的任务:页面刷新后,以及在别处开的任务。diff --git a/README.md b/README.mdindex c0223f2..c418b86 100644--- a/README.md+++ b/README.md@@ -134,7 +134,7 @@ Tool texts, results, CLI output and logs are in Simplified Chinese by default; s| `setup [--reconfigure]` | Run the setup guide again; `--reconfigure` redoes one part (language, proxy, service, Apple ID, phone, auto-unlock, notifications, MCP registration) || `service install\|uninstall\|start\|stop\|restart\|status` | The background service (launchd on macOS, systemd user unit on Linux) || `daemon` | The long-running daemon; the service runs it, or start it by hand |-| `mcp` | The MCP server; your AI client starts it |+| `mcp [--url <viewer>]` | The MCP server; your AI client starts it. With `--url` it bridges to another machine's viewer || `status` | Daemon state, time left on the signing profile, recent log || `doctor` | Layer-by-layer health check with a fix for each failure || `login` | Sign in to the Apple ID again when the session expires |@@ -148,6 +148,10 @@ Tool texts, results, CLI output and logs are in Simplified Chinese by default; s| `wda-bridge [--port]` | Expose WebDriverAgent on 127.0.0.1 for other tools; stop it when done || `viewer [--port] [--lan]` | Control page on 127.0.0.1:8200, behind a login (`viewer token` shows the token and a link; read-only tokens too): live screen you can tap, swipe and type on, device panel, and AI tasks run by a local Claude Code or Codex. `--lan` opens it to the local network (HTTPS), and MCP over HTTP is on the same port (`/mcp`) || `task run [--url <viewer>] -- <command>` | AI tasks for other agent platforms; with `--url` the phone is on another machine. `task list`, `pause`, `approve`… follow and control tasks |+| `viewer token [add <name> [--read-only]\|list\|show <name>\|remove <name>]` | The viewer's login tokens: show the owner's, or add named and read-only ones |+| `service viewer install\|uninstall\|start\|stop\|restart` | Run the viewer as a background service of its own |+| `update check\|apply\|policy` | Check for, install, or set the policy for updates |+| `completions <shell>` | Bash, Zsh or Fish completion script |All commands and options: [CLI reference](https://derrors.github.io/iphone-control/en/guide/cli).diff --git a/README.zh-CN.md b/README.zh-CN.mdindex a970146..ff2769d 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -136,7 +136,7 @@ iphone-control| `setup [--reconfigure]` | 重新走一遍设置引导;`--reconfigure` 只改其中一项(语言、代理、后台服务、Apple ID、手机、自动解锁、通知、注册 MCP) || `service install\|uninstall\|start\|stop\|restart\|status` | 后台服务(macOS 是 launchd,Linux 是 systemd 用户服务) || `daemon` | 常驻守护进程;由后台服务运行,也可以手动启动 |-| `mcp` | MCP 服务,由 AI 客户端拉起 |+| `mcp [--url <控制台>]` | MCP 服务,由 AI 客户端拉起;加 `--url` 时转接到另一台机器的控制台 || `status` | 守护进程状态、描述文件还剩多久、最近日志 || `doctor` | 逐层诊断,每项失败都给出修复办法 || `login` | Apple ID 会话失效时重新登录 |@@ -150,6 +150,10 @@ iphone-control| `wda-bridge [--port]` | 把 WebDriverAgent 桥接到 127.0.0.1 给别的工具用,用完就停 || `viewer [--port] [--lan]` | 控制台页面,地址 127.0.0.1:8200,要登录(`viewer token` 显示令牌和登录链接,可以加只读令牌):实时画面可直接点击、滑动、输入,设备面板,还能把任务交给本机的 Claude Code 或 Codex 执行。`--lan` 对局域网开放(HTTPS),同一个端口上还有 MCP over HTTP(`/mcp`) || `task run [--url <控制台>] -- <命令>` | 给别的 agent 平台用的 AI 任务;`--url` 时手机在另一台机器上。`task list`、`pause`、`approve` 等查看和控制任务 |+| `viewer token [add <名字> [--read-only]\|list\|show <名字>\|remove <名字>]` | 控制台的登录令牌:显示 owner 的令牌,或者加有名字的、只读的令牌 |+| `service viewer install\|uninstall\|start\|stop\|restart` | 把控制台装成单独的后台服务 |+| `update check\|apply\|policy` | 检查、安装更新,或设置更新策略 |+| `completions <shell>` | 生成 Bash、Zsh 或 Fish 的补全脚本 |全部命令和参数见[命令行](https://derrors.github.io/iphone-control/guide/cli)。diff --git a/SECURITY.md b/SECURITY.mdindex 24497c4..ed9c3f8 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -24,7 +24,7 @@ The data directory is `~/.local/share/iphone-control`. Everything runs as your r## Design choices that limit exposure-- No network listener by default. WebDriverAgent is reached through usbmuxd. `wda-bridge` and `viewer` are opt-in and bind 127.0.0.1 only (`viewer --lan` also listens on the local network, over HTTPS); `wda-bridge` is meant to be stopped after use. `wda-bridge` only forwards requests whose Host header is a loopback name. `viewer` requires a login token for every HTTP request and checks the Host header the same way (its own names and addresses with `--lan`); its actions also need an `Origin` of the viewer page itself and a JSON body, so other web pages can't act through it, reads a browser marks as coming from another site (`Sec-Fetch-Site`) are refused, and each action carries the UDID of the device the page follows, so the daemon refuses it once another device is controlled.+- No network listener by default. WebDriverAgent is reached through usbmuxd. `wda-bridge` and `viewer` are opt-in and bind 127.0.0.1 by default (`viewer --lan` also listens on the local network, over HTTPS); `wda-bridge` is meant to be stopped after use. `wda-bridge` only forwards requests whose Host header is a loopback name. `viewer` requires a login token for every HTTP request and checks the Host header the same way (its own names and addresses with `--lan`); its actions also need an `Origin` of the viewer page itself and a JSON body, so other web pages can't act through it, reads a browser marks as coming from another site (`Sec-Fetch-Site`) are refused, and each action carries the UDID of the device the page follows, so the daemon refuses it once another device is controlled.- The control socket is a Unix socket with mode 0600, not TCP.- The tunnel to the phone uses a user-space TCP stack, so no network interface or routing changes on the host, and the daemon needs no root.- Auto-unlock is off by default. When enabled, it stops for good after a single wrong attempt (it writes a stop marker, `logs/UNLOCK-DISABLED`, before entering the second digit) and sends a notification; it never retries a passcode that might be wrong. The marker is global: a failure on one device stops auto-unlock on all of them until you run `unlock-reset`. It does not work before the first unlock after a reboot (BFU) — that always needs a person.diff --git a/apps/iphone-control/src/main.rs b/apps/iphone-control/src/main.rsindex 08d6449..d61e8e1 100644--- a/apps/iphone-control/src/main.rs+++ b/apps/iphone-control/src/main.rs@@ -114,7 +114,7 @@ enum Command {#[arg(long, default_value_t = 8100)]port: u16,},- #[command(about = ictl_l10n::tr!("浏览器里的控制台:实时画面上直接操作手机、看设备状态,把任务交给本机的 Claude Code 或 Codex 执行。只开在 127.0.0.1,操作都经守护进程(默认不监听任何端口)", "Control page in a browser: act on the live screen, see the device's state, and hand tasks to a local Claude Code or Codex. Serves 127.0.0.1 only, every action goes through the daemon (by default no port is opened)"))]+ #[command(about = ictl_l10n::tr!("浏览器里的控制台:实时画面上直接操作手机、看设备状态,把任务交给本机的 Claude Code 或 Codex 执行。默认只开在 127.0.0.1(--lan 也对局域网开放,走 HTTPS),要用令牌登录(iphone-control viewer token),操作都经守护进程(不开控制台时不监听任何端口)", "Control page in a browser: act on the live screen, see the device's state, and hand tasks to a local Claude Code or Codex. Serves 127.0.0.1 by default (--lan opens it to the local network too, over HTTPS), behind a login token (iphone-control viewer token); every action goes through the daemon (without the viewer no port is opened)"))]Viewer {#[arg(long, env = "IPHONE_CONTROL_VIEWER_PORT", default_value_t = 8200)]port: u16,diff --git a/docs/architecture.md b/docs/architecture.mdindex 70286b4..c03aeca 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -36,7 +36,9 @@| 进程 | 生命周期 | 职责 ||---|---|---|| `iphone-control daemon` | 常驻,作为用户服务运行(macOS 是 launchd,Linux 是 systemd 用户服务;由 `install.sh`、`iphone-control service install`、`brew services` 或 .deb 的 unit 装好),也可以在终端里前台运行 | 唯一和设备通信的进程。维护设备状态机,对外提供本地控制接口 |-| `iphone-control mcp` | 每个 agent 会话一个 | MCP stdio 服务,把工具调用翻译成对守护进程的请求 |+| `iphone-control mcp` | 每个 agent 会话一个 | MCP stdio 服务,把工具调用翻译成对守护进程的请求;`--url` 时改为把 stdio 转接到另一台机器控制台的 `/mcp`(`mcp_bridge.rs`) |+| `iphone-control viewer` | 显式开启,可作为单独的后台服务(`service viewer install`) | 浏览器里的控制台和同一个端口上的 HTTP MCP(`/mcp`);要令牌登录,`--lan` 时对局域网开放、走 HTTPS(`viewer/`:`auth.rs` 登录、`lan.rs` 地址检查、`tls.rs` 按首字节分 TLS 和明文、`mcp.rs` 接 rmcp、`peer.rs` 查本机调用方进程) |+| `iphone-control task run` | 一个外部 AI 任务一个 | 开任务、持有租约、在任务里运行命令(`task.rs`);`--url` 时经另一台机器的控制台(`remote.rs`) || `usbmuxd` | 系统的服务:Linux 上是发行版的包(.deb 依赖它,udev 在插上手机时启动),macOS 自带;守护进程不启动也不重启它 | Linux 上是系统包,GPL-3.0,独立进程运行,不链接 || `iphone-control`(不带命令)、`setup`、`service`、`doctor`、`sign` 等 | 一次性 | 首次运行引导(`guide.rs`)、后台服务管理(`service.rs`)和运维命令,通过控制接口或直接调用库。启动时先把 `~/.config/iphone-control/env` 读进环境(`envfile.rs`,已有的环境变量优先) |@@ -113,18 +115,18 @@| `ictl-wda` | `WdaRunner`(XCUITestService 启动/停止)、`WdaClient`(会话、点击、W3C actions、keys、source、screenshot、appium settings、锁屏核对)、经 usbmuxd 直连设备 8100 端口的 HTTP 传输(区分连不上和请求超时)、元素树解析(纯函数,可单测) | `idevice`(`xctest`)、`quick-xml` || `ictl-webinspector` | Web Inspector 服务(`com.apple.webinspector`,经 lockdown)的客户端:列出可检查的网页和 WebView、在页面里执行 JavaScript(`Target` 域和旧版直接收命令两种都支持,Promise 用 `Runtime.awaitPromise` 等待)。纯协议,消息解析可单测 | `idevice`、`plist` || `ictl-l10n` | 界面文字的语言:取当前语言,`tr!` / `trf!` / `log_tr!` / `log_trf!` 宏(每条文字在代码里原地写成中英一对,见 D12) | 无 |-| `ictl-protocol` | 控制接口的 `Request`/`Response` 类型和客户端 `call(socket, req, timeout)` | `serde`、`tokio` |+| `ictl-protocol` | 控制接口的 `Request`/`Response` 类型和客户端 `call(socket, req, timeout)`、任务的流式请求;默认的数据目录、socket 路径和 root 判断 | `serde`、`serde_json`、`tokio`、`libc`、`ictl-l10n` || `ictl-sign` | Apple ID 登录(含双重认证交互)、会话持久化、注册设备、App ID、描述文件、签名 `.app`/`.ipa`(**包括 `.xctest`**;bundle 逻辑改写自 plume_utils)、签后自检 | vendored 的 `plume_core`/`plume_store`(MPL-2.0/MIT;经 plume_core 用 vendored 的 `omnisette` 和打过补丁的 `apple-codesign`) || `ictl-unlock` | 锁屏密码键盘定位、逐位输入并核对密码栏、从第 2 位起先写停用标记 | `ictl-wda` || `ictl-daemon` | `core`(共享状态、请求分发、快照)、`supervise`(巡检、后台启动 WDA、重签、会话检查)、`tools`(工具的实现、HID 后备)、`devtools`(日志采集、崩溃报告、安装、卸载)、`web`(Web Inspector 工具,保留一条连接复用)、`devices`(列出、选择设备)、`doctor`;通知(Bark/Telegram)、截图缩放/裁剪、控制接口服务端 | 以上全部、`tokio`、`reqwest`、`image` |-| `ictl-mcp` | MCP stdio 服务,`iphone_*` 工具 17 个,开启开发者工具后 23 个:toolkit 的 13 个 + `iphone_wait_for`、`iphone_batch`、`iphone_list_devices`、`iphone_select_device`,以及 6 个可选的开发者工具(D13);操作类工具可带 `then` 顺带返回操作后的界面;经控制接口调用守护进程 | `ictl-protocol`、`ictl-l10n`、`rmcp`(`server`、`transport-io`) |-| `apps/iphone-control` | CLI 入口:不带命令时是首次运行引导或状态(`guide.rs`)、`daemon`、`mcp`、`mcp-config`、`status`、`doctor`、`setup [--reconfigure]`、`service`(`service.rs`:launchd / systemd 用户服务)、`login`、`sign`、`resign`、`passcode`、`unlock-reset`、`devices`、`select`、`wda-bridge`、`viewer`(`viewer.rs`:本机控制台网页,实时画面、设备面板;`video/`:画面的 H.264 编码(外部 ffmpeg)和 MJPEG 去重;`agent.rs`:页面上的 AI 任务,`viewer.html` 是页面)、`notify-test`;隐藏的 `debug <ddi\|hid\|screenshot\|soak\|wda\|e2e>` 真机诊断(原第 0 步 spike,不经守护进程;feature `debug-cmds`,默认不编译) | `clap` |+| `ictl-mcp` | MCP stdio 服务,`iphone_*` 工具 17 个,开启开发者工具后 23 个:toolkit 的 13 个 + `iphone_wait_for`、`iphone_batch`、`iphone_list_devices`、`iphone_select_device`,以及 6 个可选的开发者工具(D13);操作类工具可带 `then` 顺带返回操作后的界面;任务里另有 `iphone_confirm`;经控制接口调用守护进程。同一套工具也给控制台的 `/mcp` 用(`http_service`,Streamable HTTP) | `ictl-protocol`、`ictl-l10n`、`rmcp`(`server`、`transport-io`、`transport-streamable-http-server`)、`http` |+| `apps/iphone-control` | CLI 入口:不带命令时是首次运行引导或状态(`guide.rs`)、`daemon`、`mcp`、`mcp-config`、`status`、`doctor`、`setup [--reconfigure]`、`service`(`service.rs`:launchd / systemd 用户服务)、`login`、`sign`、`resign`、`passcode`、`unlock-reset`、`devices`、`select`、`wda-bridge`、`viewer`(`viewer.rs`:本机控制台网页,实时画面、设备面板;`video/`:画面的 H.264 编码(外部 ffmpeg)和 MJPEG 去重;`agent.rs`:页面上的 AI 任务,`viewer.html` 是页面)、`viewer token …`(命名令牌、只读令牌)、`task …`(`task.rs`、`remote.rs`)、`mcp --url`(`mcp_bridge.rs`)、`update …`(`update.rs`、`update/`:签名清单、事务式替换)、`completions`、`notify-test`;隐藏的 `debug <ddi\|hid\|screenshot\|soak\|wda\|e2e>` 真机诊断(原第 0 步 spike,不经守护进程;feature `debug-cmds`,默认不编译) | `clap` |依赖方向:`apps` → `ictl-daemon` / `ictl-mcp`,还直接依赖 `ictl-device`、`ictl-sign`;`ictl-daemon` → `ictl-unlock` → `ictl-wda` → `ictl-device`;`ictl-daemon` 还直接依赖 `ictl-webinspector`、`ictl-sign` 和 `ictl-protocol`。`ictl-device` 也依赖 `ictl-webinspector`(打开连接)。`ictl-mcp` 只依赖 `ictl-protocol` 和 `ictl-l10n`,不依赖守护进程和设备层。`ictl-l10n` 不依赖其他 crate,除 `ictl-webinspector` 外都用它。`apps` 的 `debug`(feature `debug-cmds`)直接调用 `ictl-device`、`ictl-wda`。## 5. 截图与坐标-- 坐标单位统一用**点(pt)**,与 WDA 一致,随界面方向变化;屏幕点尺寸从 WDA `/wda/screen` 读取。WDA 就绪时把竖放尺寸和设备 UDID 记到 `state.json`(只记最近一台)。WDA 不可用时:记录是这台的就用记录,否则用设置里的 `SCREEN_W`/`SCREEN_H`(不分设备),都没有就报错(不写死 430×932)。+- 坐标单位统一用**点(pt)**,与 WDA 一致,随界面方向变化;屏幕点尺寸从 WDA `/wda/screen` 读取。WDA 就绪时把竖放尺寸按设备 UDID 记到 `state.json`(每台设备各一份)。WDA 不可用时:记录是这台的就用记录,否则用设置里的 `SCREEN_W`/`SCREEN_H`(不分设备),都没有就报错(不写死 430×932)。- HID 坐标是 0~65535 归一化:先按界面方向转回竖放(`Rotation::to_portrait`),再换算 `x / w * 65535`。每次 HID 触摸前重新截图核对横竖;横屏要有 30 秒内且匹配的 WDA 旋转角,否则拒绝触摸。- 截图优先走 WDA(toolkit 实测约 0.4 秒);WDA 不可用时走 CoreDevice `screencaptureservice`(不需要签名)。- 区域放大:从原始像素截图裁剪,长边 < 600 放大到 600,> 1200 缩到 1200,返回倍数和坐标换算式(三位有效数字)。@@ -141,7 +143,10 @@| `wda/` | 当前签好的包 `WDA-signed.ipa`,和未签名包 `WDA-unsigned.ipa`:第一次签名前下载 Appium 官方的未签名真机包(`WebDriverAgentRunner-Runner.zip` v16.15.3,校验 sha256)重新打包(`crates/ictl-daemon/src/wda_pkg.rs`);计划改为本项目 macOS CI 编译。描述文件只嵌在签好的包里,到期时间记在 `state.json` | 默认 | 否(在本机下载) || `secrets/passcodes/<UDID>` | 各设备的锁屏密码(仅启用自动解锁时);旧版本的 `secrets/passcode` 在只接着一台时归到那台名下 | 0600 | 否 || `logs/` | 事件日志 `daemon.log`(超过 5 MB 轮转成 `.1`);自动解锁停用标记 `UNLOCK-DISABLED`(与 toolkit 一致,便于人工发现;全局,不分设备) | 默认 | 否 |-| `state.json` | 最近一次签名的 Team ID、WDA Bundle ID、描述文件到期时间;选定的设备;最近一台就绪设备的竖放屏幕尺寸和 UDID;上次重签结果 | 默认 | 否 |+| `state.json` | 最近一次签名的 Team ID、WDA Bundle ID、描述文件到期时间;选定的设备;每台设备的竖放屏幕尺寸(按 UDID);上次重签结果 | 默认 | 否 |+| `viewer-tokens.json` | 控制台的登录令牌(名字、权限、令牌) | 0600 | 否 |+| `viewer-tls/` | 控制台局域网 HTTPS 的自签证书和私钥 | 0700 | 否 |+| `tasks/` | 最近 50 个 AI 任务的事件记录,每个任务一个 `<id>.jsonl` | 默认 | 否 |守护进程的配置全部来自环境变量(`crates/ictl-daemon/src/config.rs`),都有默认值。设置文件 `~/.config/iphone-control/env`(`KEY=value`,0600,模板 `packaging/env.example`)由首次运行引导和 `setup --reconfigure` 写(`envfile.rs`:改一项就地替换,注释和其他项保留);后台服务(launchd、systemd、`brew services`)把它读进守护进程的环境,其他命令启动时也读一遍,已有的环境变量优先。通知渠道的密钥也在这个文件里;其余秘密只放数据目录里的文件。@@ -150,5 +155,5 @@- 守护进程每 `RESIGN_CHECK_HOURS`(默认 6 小时)检查一次:描述文件剩余 < `RESIGN_MIN_DAYS`(默认 2 天)才重签;另外**每天验证一次 Apple ID 会话**(toolkit 的教训:只在要重签时才发现登录过期,只剩 2 天处理)。两者都在后台跑,不持设备锁。只检查正在控制的那台;手机重新连上或切换设备后 1 分钟内也查一次。- 重签流程:`plume_core` 取新描述文件 → `ictl-sign` 签名(含 `.xctest`)→ `installation_proxy` 安装 → 下一轮巡检重启 WDA。安装成功后才替换旧文件。整个重签有总时限,超时按失败处理并推送通知。没装过当前 Apple ID 签的 WDA 的设备不自动重签(注册设备占 Apple ID 的名额,交给用户决定)。- **签名证书**:每个账号目录有自己的私钥(`account/keys/<团队>/key.pem`)和对应的开发证书;免费团队同时最多两张,新建时满了 plume 会吊销一张,不挑是谁的,用它签的 App 在所有设备上都起不来,描述文件却仍有效。所以:读设备上的 WDA 描述文件时顺带离线判断里面有没有本机公钥的证书(`foreign_wda`);每天的会话检查顺带联网查本机证书还在不在团队里(`own_cert`)。设备拒绝启动 WDA(只报 `unexpected response`)时,两者任一有问题就自动重签这台,同一台 6 小时内最多一次;都没问题就多半是还没信任开发者,留给用户。签名新建或吊销证书时写日志、推送。`doctor` 显示这两项。-- 通知事件:重签失败、Apple ID 会话失效、需要输入自动化密码、WDA 恢复、自动解锁失败已停用、手机离线超过 10 分钟、恢复在线、签名证书换了。通知文字不带设备名。去重:重签失败、会话失效 20 小时内不重复;等密码、离线、自动解锁停用推一次,直到恢复或 `unlock-reset`;只有等密码和离线有恢复推送;签名证书换了每次都推。去重记录只在内存里,守护进程重启后清空。+- 通知事件:重签失败、Apple ID 会话失效、需要输入自动化密码、WDA 恢复、自动解锁失败已停用、手机离线超过 10 分钟、恢复在线、签名证书换了。通知标题带上是哪台设备(设备名和型号,离线时用离线前记下的)。去重:重签失败、会话失效 20 小时内不重复;等密码、离线、自动解锁停用推一次,直到恢复或 `unlock-reset`;只有等密码和离线有恢复推送;签名证书换了每次都推。去重记录只在内存里,守护进程重启后清空。- 守护进程整个挂掉时发不了通知,这部分仍需宿主机侧的监控,本项目还没有提供。后台服务(`iphone-control service install` 装的 launchd 或 systemd 服务)只负责崩溃后重启,同样不报警。diff --git a/docs/decisions.md b/docs/decisions.mdindex 9b85523..d08acaf 100644--- a/docs/decisions.md+++ b/docs/decisions.md@@ -19,8 +19,8 @@- **决定**:用 idevice 的 provider 直连设备端口访问 WDA;外部工具需要时显式开 bridge,只绑 127.0.0.1。- **理由**:WDA 没有认证;toolkit 早期用 `ios forward` 监听了所有网卡,局域网内任何人都能控制手机。-- **补充**:`iphone-control viewer` 用同样的保护模型(显式开启、只绑 127.0.0.1、检查 `Host`),另加操作的 `Origin` 和 JSON 内容类型检查、读接口的 `Sec-Fetch-Site` 检查,并只作用于页面跟着的那台设备。它的 AI 任务不开新端口:agent 的 MCP 服务经控制接口旁边的 Unix socket(0600,每个任务一个口令)回报 viewer。-- **补充(2026-11-13)**:`viewer --lan` 让控制台也对局域网开放:同一个端口,仍是 HTTP,**还没有登录**(用户决定先这样,登录以后再加,见 task-control.md 7.2)。没有登录时能做的防护都做了:显式开启、只接受回环和局域网地址(私有网段、链路本地、100.64/10)来的连接、`Host` 只认本机的名字和地址、操作的 `Origin` 必须是页面自己。代价是局域网里能连上这台机器的人都能操作手机、用本机的 Claude Code / Codex 开任务;从局域网地址打开时浏览器不提供 WebCodecs,画面退回 MJPEG。默认仍只绑 127.0.0.1。+- **补充**:`iphone-control viewer` 用同样的保护模型(显式开启、只绑 127.0.0.1、检查 `Host`),另加操作的 `Origin` 和 JSON 内容类型检查、读接口的 `Sec-Fetch-Site` 检查,并只作用于页面跟着的那台设备。它的 AI 任务不开新端口:agent 的 MCP 服务经控制接口旁边的 Unix socket(0600,每个任务一个口令)回报 viewer(后来任务放进了守护进程,改经控制接口回报,见 D17)。+- **补充(2026-11-13,已被下一条取代)**:`viewer --lan` 让控制台也对局域网开放:同一个端口,仍是 HTTP,**还没有登录**(用户决定先这样,登录以后再加,见 task-control.md 7.2)。没有登录时能做的防护都做了:显式开启、只接受回环和局域网地址(私有网段、链路本地、100.64/10)来的连接、`Host` 只认本机的名字和地址、操作的 `Origin` 必须是页面自己。代价是局域网里能连上这台机器的人都能操作手机、用本机的 Claude Code / Codex 开任务;从局域网地址打开时浏览器不提供 WebCodecs,画面退回 MJPEG。默认仍只绑 127.0.0.1。- **补充(2026-11-13,后来)**:上一条的两个代价都去掉了。`--lan` 时同一个端口也讲 HTTPS(按连接的第一个字节分辨,默认自签证书、显示指纹,task-control.md 7.3);所有 HTTP 访问都要登录令牌,**本机也一样**,因为本机上的反向代理(frp、cloudflared 等)会让外来的访问看起来就是 `127.0.0.1`(7.5)。令牌有名字,可以只读(7.6)。默认仍只绑 127.0.0.1,局域网仍要显式开启。## D4:WDA 仍然是 Objective-C,在 macOS CI 上编译diff --git a/docs/task-control.md b/docs/task-control.mdindex a67d285..272b713 100644--- a/docs/task-control.md+++ b/docs/task-control.md@@ -165,6 +165,8 @@ Running → Waiting(等确认)→ Running- **不带口令的请求**:查看类(截图、读元素、状态、列 App 等)照常执行。动作类只在 takeover(人接管)时接受,接受后给任务记上「需要重新观察」;其他状态下一律拒绝并说明原因(抬起手指除外)。切换设备、手动重签同样拒绝。- **带的口令属于已结束或不存在的任务**:任何请求都拒绝,提示「任务已结束,停下来」。+请求放行之后,还要排队拿设备锁(可能排在 `wait_for`、巡检后面),这期间人可能暂停、接管或交还了。所以拿到锁之后再按上面的规则查一次(`Tasks::still`):任务的请求遇到暂停、接管、等待确认就放下锁接着等,用户的请求在交还之后就拒绝。「需要重新观察」只有观察成功(截图、读元素、等文字没有出错)才清掉。+没有任务在进行时,和以前完全一样。### 5.3 落盘@@ -193,6 +195,7 @@ Running → Waiting(等确认)→ Running- 超出范围时任务进入 waiting,和 `iphone_confirm` 用同一套确认:页面和 `task approve`/`reject` 都能回答。同意后这个 App 加入本任务的范围,之后不再问;拒绝只拒这一步,Agent 收到「回到范围内的 App 再继续」,任务不会因此记成 rejected。- 看不出前台是哪个 App(WDA 不可用、读失败)时不操作,返回错误让 Agent 稍后再试,不在不知道是哪个 App 的界面上盲点。- 查前台只短暂拿设备锁,等人回答时不持锁(人可以先接管);调用方中途断开,问题从页面上撤掉。+- 问人(越界确认和 `iphone_confirm`)和一个步骤一样,只在任务运行时开始:暂停、接管时先等着,不会把人的暂停或接管改成「等待确认」;同时只有一个问题,第二个等第一个答完。回答之后只有任务还在「等待确认」时才回到运行。- 局限:检查的是动作之前的前台。在范围内的 App 里点一下跳进了别的 App,这一下本身不会被拦,进去之后的下一步才会。### 5.6 执行方不能控制自己的任务(2.5 的落地版)@@ -227,7 +230,7 @@ Running → Waiting(等确认)→ Running**场景**:守护进程和手机在一台机器上(比如 NAS),人在局域网里另一台电脑的浏览器上看控制台、操作手机、开 AI 任务,不想每次先建 SSH 隧道。-**现状**:控制台只绑 `127.0.0.1`,没有改的参数;请求的 `Host` 必须是 `127.0.0.1`/`localhost`/`[::1]`(防 DNS rebinding),操作的 `Origin` 必须是页面自己的这几个地址;没有登录(D3)。局域网里用 SSH 隧道:`ssh -L 8202:127.0.0.1:8202 <用户>@<主机>`,浏览器开 `http://127.0.0.1:8202/`。在做之前,这是推荐的办法。+**现状(7.2 之前)**:控制台只绑 `127.0.0.1`,没有改的参数;请求的 `Host` 必须是 `127.0.0.1`/`localhost`/`[::1]`(防 DNS rebinding),操作的 `Origin` 必须是页面自己的这几个地址;没有登录(D3)。局域网里用 SSH 隧道:`ssh -L 8202:127.0.0.1:8202 <用户>@<主机>`,浏览器开 `http://127.0.0.1:8202/`。在做之前,这是推荐的办法。**要求**:@@ -254,14 +257,14 @@ Running → Waiting(等确认)→ Running- **只接受局域网来的连接**:对端地址必须是回环、私有网段(10/8、172.16/12、192.168/16)、链路本地(169.254/16)或 CGNAT(100.64/10,Tailscale 用它)。别的一律直接断开,机器万一暴露在公网也不会被外网操作。- **Host 检查保留**(防 DNS rebinding):认可的是回环名、本机主机名和 `<主机名>.local`、启动时各网卡的 IPv4 地址,以及 `--lan-host` 额外写的名字(可写多次,给 DNS 名用)。- **Origin 检查保留**(防别的网页借浏览器操作):操作的 Origin 必须是 `http://<认可的 Host>:<端口>`。`Sec-Fetch-Site` 检查照旧。-- **启动时提醒**:打印每个局域网地址,并说明「局域网里任何人都能打开它操作手机、让 AI 执行任务,没有登录,只在可信的网络里开」。+- **启动时提醒**:打印每个局域网地址,并说明「局域网里任何人都能打开它操作手机、让 AI 执行任务,没有登录,只在可信的网络里开」(7.5 加了登录以后,这句提醒去掉了)。- **画面**:浏览器只在 HTTPS 或 `localhost` 上提供 WebCodecs,从局域网 IP 打开时,页面自动退回 MJPEG(每秒 4~10 MB)。手机自己的 HEVC 画面也用不了,所以系统弹窗直接在 MJPEG 画面里看得到。- **代价**:局域网里能连上这台机器的人都能操作手机、用本机登录的 Claude Code / Codex 开任务。这是有意的权衡,等加了登录再收紧。决策记录见 D3 的补充。之后:1. 控制台做成后台服务(`iphone-control service viewer install`,开机自启,跟着设置文件里的 `IPHONE_CONTROL_VIEWER_*`):已完成(2026-11-13)。升级时先停下它(它是常驻客户端,会让升级一直 busy),升级完再启动;有 AI 任务在跑时自动升级推迟。-2. 登录:一个令牌,存在数据目录,登录后用 `HttpOnly; SameSite=Strict; Secure` 的 cookie,程序用 `Authorization: Bearer`,失败限速;局域网口子开了登录才放行。HTTP MCP 届时再定。+2. 登录:一个令牌,存在数据目录,登录后用 `HttpOnly; SameSite=Strict; Secure` 的 cookie,程序用 `Authorization: Bearer`,失败限速;局域网口子开了登录才放行。HTTP MCP 届时再定。(已在 7.5 做完;cookie 最后用的是 `SameSite=Lax`,见 7.5。)3. HTTPS:已完成(2026-11-13),见 7.3。### 7.3 HTTPS(2026-11-13)@@ -286,7 +289,7 @@ Running → Waiting(等确认)→ Running- **任务**:stdio 靠进程的环境变量 `IPHONE_CONTROL_TASK_TOKEN` 加入任务;HTTP 是一个进程服务许多客户端,所以口令放在每个请求的头 `Iphone-Control-Task-Token` 里,`McpServer` 按请求读取,用 `as_task` 让这次调用发出的所有请求都带上它。「是否在任务里」也改成按请求判断(`protocol::in_task`)。带了口令就列出 `iphone_confirm`、每次调用报告步骤,和 stdio 一样。- **访问**:和控制台页面一样,对端地址、`Host`、`Sec-Fetch-Site` 先查;带 `Origin` 的请求(浏览器)必须来自控制台自己,命令行客户端不带 `Origin`。rmcp 自己的 Host 白名单设为不检查,免得两套名单不一致。`--lan` 时局域网的明文请求 307 到 HTTPS。- **开关**:`--mcp on|off`(`IPHONE_CONTROL_VIEWER_MCP`),默认开:它能做的事控制台的接口本来就能做,没有多开口子。-- **还没有的**:从别的机器**开**任务(任务的租约还是本机 socket 上的连接,外部平台目前在本机用 `task run` 开任务、把口令交给远端的 agent)。+- **还没有的**:从别的机器**开**任务(任务的租约还是本机 socket 上的连接,外部平台目前在本机用 `task run` 开任务、把口令交给远端的 agent)。已在 7.6 做完。### 7.5 登录(2026-11-13)@@ -294,10 +297,10 @@ Running → Waiting(等确认)→ Running7.1 第 2 条的落地,按用户的决定做了一个令牌(只读和可操作分开留到以后)。和 7.1 不同的一点:**本机也要登录**。frp、nginx、cloudflared、`tailscale serve` 这类反向代理或隧道跑在本机时,公网上每个访问者的连接都来自 `127.0.0.1`,控制台分不清是用户本人还是别人,所以不能「本机免登录」。- **范围**:经 HTTP 的一切(页面、接口、画面、任务事件、`/mcp`)。Unix socket 上的命令行、stdio 的 `iphone-control mcp`、`task run` 不受影响(socket 是 0600,本来就只有这个用户能连)。-- **令牌**:第一次启动时用系统随机数生成 256 位,十六进制存在 `<数据目录>/viewer-token`(0600,先写临时文件再改名)。`iphone-control viewer token` 显示令牌、本机和局域网的登录链接(`/?token=…`)、`claude mcp add … --header "Authorization: Bearer …"`;`--new` 换新令牌,控制台服务在运行就重启它。令牌不写进启动输出和日志(journal 可能有别人能读)。+- **令牌**:第一次启动时用系统随机数生成 256 位,十六进制存在 `<数据目录>/viewer-token`(0600,先写临时文件再改名;7.6 起改为 `viewer-tokens.json`)。`iphone-control viewer token` 显示令牌、本机和局域网的登录链接(`/?token=…`)、`claude mcp add … --header "Authorization: Bearer …"`;`--new` 换新令牌,控制台服务在运行就重启它。令牌不写进启动输出和日志(journal 可能有别人能读)。- **浏览器**:没登录时 `/` 返回登录页(401);登录页的表单 `POST /login`(带 `Origin` 时必须是控制台自己),或者点开 `/?token=…` 的链接,成功后 303 回 `/`,地址栏里不留令牌。会话 cookie `ictl_viewer_<端口>`:值是令牌对固定文本的 HMAC-SHA256,看不出令牌,换令牌后自动失效;`HttpOnly`、`SameSite=Lax`(从别处点链接进来也认得,CSRF 靠原有的 `Origin` 和 `Sec-Fetch-Site` 检查)、HTTPS 时加 `Secure`、30 天。页面上的请求遇到 401 就刷新,回到登录页。- **程序**:`Authorization: Bearer <令牌>`。`/mcp` 的 401 带 `WWW-Authenticate: Bearer`(RFC 6750)。-- **限速**:按全局算,不按地址(经反向代理时地址都是 `127.0.0.1`)。一分钟里错 20 次后,这一分钟内不再校验令牌,一律 429;已经登录的会话不受影响。令牌是 256 位随机数,限速只是多一层保险。+- **限速**:按全局算,不按地址(经反向代理时地址都是 `127.0.0.1`)。一分钟里错 20 次后,这一分钟内错的令牌一律 429;已经登录的会话不受影响。令牌是 256 位随机数,限速只是多一层保险。(最初这一分钟内连正确的令牌也不校验,结果谁能连上页面,就能靠刷错令牌让 `mcp --url`、远端任务都连不上;0.2.4 之后改成正确的令牌总能进。)- **比较**:令牌和 cookie 都用与内容无关的时间比较。- **还没有的**:页面上的退出登录。只读令牌和记下是哪个令牌见 7.6。diff --git a/website/deploy/backup.md b/website/deploy/backup.mdindex ad94346..9924ac4 100644--- a/website/deploy/backup.md+++ b/website/deploy/backup.md@@ -8,7 +8,10 @@| `wda/` | 签好的 WebDriverAgent | 自动重签 || `ddi/` | 开发者镜像缓存 | 自动重新下载 || `secrets/passcodes/` | 各设备的锁屏密码(仅开启自动解锁时) | 要重新 `passcode set` |-| `state.json` | 签好的 WDA 包信息(Team ID、Bundle ID、描述文件到期时间)、选定的设备、最近一台设备的屏幕尺寸、上次重签结果 | 守护进程按「WDA 还没签名」启动:要重新 `sign` 或 `setup`,选过设备的要重新 `select` |+| `viewer-tokens.json` | 控制台的登录令牌(像密码一样保管,别放进会同步到别处的备份) | 控制台第一次启动时生成新的 `owner`;之前的令牌、登录过的浏览器和 MCP 客户端都要换新的 |+| `viewer-tls/` | 控制台局域网 HTTPS 用的自签证书和私钥(同样要保密) | 重新生成,证书指纹变了:浏览器会再提示一次,`--ca` 要换新证书 |+| `tasks/` | 最近 50 个 AI 任务的记录 | 控制台上看不到以前的任务,不影响使用 |+| `state.json` | 签好的 WDA 包信息(Team ID、Bundle ID、描述文件到期时间)、选定的设备、每台设备的屏幕尺寸、上次重签结果 | 守护进程按「WDA 还没签名」启动:要重新 `sign` 或 `setup`,选过设备的要重新 `select` || `logs/` | 日志、自动解锁的停用标记 `UNLOCK-DISABLED` | 日志没了不要紧。但停用标记没了就撤销了这层保护:之前输错过的话,可能再用同一个错误密码输一遍 |位置:`~/.local/share/iphone-control`(权限 0700),Linux 和 macOS 一样,不管是一行命令、Homebrew、deb 还是从源码装的。配对记录不在这里,由系统的 usbmuxd 保存:Linux 上在 `/var/lib/lockdown`,macOS 上在 `/var/db/lockdown`(和 Finder 共用)。设置在 `~/.config/iphone-control/env`,里面有通知密钥,同样别外传。diff --git a/website/en/deploy/backup.md b/website/en/deploy/backup.mdindex c6a0ea1..357c7d6 100644--- a/website/en/deploy/backup.md+++ b/website/en/deploy/backup.md@@ -8,7 +8,10 @@| `wda/` | Signed WebDriverAgent | Re-signed automatically || `ddi/` | Developer Disk Image cache | Downloaded again || `secrets/passcodes/` | Per-device passcodes (only with auto-unlock) | Run `passcode set` again |-| `state.json` | Signed WDA details (Team ID, bundle id, profile expiry), selected device, screen size of the most recent device, last signing result | The daemon starts as if WDA isn't signed: run `sign` or `setup` again, and `select` again if you had selected a device |+| `viewer-tokens.json` | The viewer's login tokens (keep them like passwords, out of backups that sync elsewhere) | The viewer makes a new `owner` on its next start; browsers and MCP clients that logged in need the new one |+| `viewer-tls/` | The self-signed certificate and key for the viewer's HTTPS on the local network (secret too) | Made again with a new fingerprint: browsers warn once more, and `--ca` needs the new certificate |+| `tasks/` | The last 50 AI tasks | The page no longer shows earlier tasks; nothing else |+| `state.json` | Signed WDA details (Team ID, bundle id, profile expiry), selected device, each device's screen size, last signing result | The daemon starts as if WDA isn't signed: run `sign` or `setup` again, and `select` again if you had selected a device || `logs/` | Logs, auto-unlock's stop marker `UNLOCK-DISABLED` | The logs don't matter. Losing the marker removes a safeguard: after a wrong passcode, the same one could be entered again |Location: `~/.local/share/iphone-control` (mode 0700), on Linux and macOS alike, whether installed with the one command, Homebrew, the .deb or from source. Pairing records aren't in it; the system usbmuxd keeps them, in `/var/lib/lockdown` on Linux and `/var/db/lockdown` on macOS (shared with Finder). Settings are in `~/.config/iphone-control/env`, which holds notification secrets: don't share it either.diff --git a/website/en/guide/cli.md b/website/en/guide/cli.mdindex 3e4c224..0945a51 100644--- a/website/en/guide/cli.md+++ b/website/en/guide/cli.md@@ -57,7 +57,7 @@ Restarting the background service interrupts running AI tasks and the control paUse `iphone-control update check` for a version check only, or `iphone-control update check --json` for machine-readable output. This check and **About & updates** in Viewer share the local release cache. If the network check fails, the previous successful record is kept. A red dot on the ⓘ button beside **Settings** indicates a newer release. Open the panel to read the release notes and copy the update command for the current executable into a local terminal.-Viewer listens on loopback. Other users on the same host can read installation information and request a version check. Upgrades and policy changes are performed from a local terminal.+Viewer needs a login token (see `viewer` below). Anyone with a token, a read-only one too, can read installation information and request a version check; upgrades and policy changes are only done from a terminal on this machine.Managed services check in the background by default. `update apply` installs without asking (managed services), and `update recover` finishes an interrupted replacement. There is no command to go back to the previous version: to run an older one, uninstall with the release's install script and `--uninstall` (settings and device data are kept), then install that version with `--version vX.Y.Z`. If you currently run the 0.2.2 CLI, use `iphone-control update check` and follow the command it shows to upgrade to a version with the new `iphone-control update` command.@@ -130,12 +130,12 @@ See [Auto-unlock](./auto-unlock). `--device` takes a UDID or name, and the devic|---|---|| `notify-test [event]` | Send test notifications: one per event type, or one type (`resign`, `session`, `pin`, `pin-recovered`, `unlock`, `offline`, `online`) || `wda-bridge [--port <port>]` | Expose WDA on `127.0.0.1` (default port 8100) for other tools. WDA has no authentication and every local user can reach it, so stop it when done |-| `viewer [--port <port>] [--lan] [--lan-host <name>…] [--tls auto\|on\|off] [--tls-cert <PEM> --tls-key <PEM>] [--mcp on\|off]` | Control page in the browser, **behind a login**: every HTTP visit (from this machine too; one forwarded by frp or another reverse proxy looks just like it) needs the token, and `viewer token` shows it with links that log in; a browser stays logged in for 30 days, programs and MCP clients send `Authorization: Bearer <token>`. (and MCP over HTTP at `/mcp` on the same port, see [Connect an AI Client](./mcp-clients#connect-by-url-http); `--mcp off` turns it off) at `http://127.0.0.1:8200/` (default port); with `--lan` also at `https://<this machine's address>:8200/` on the local network (same port; `http://` from the network is sent to `https://`). The certificate is a self-signed one made on this machine (kept in `viewer-tls/` in the data directory and reused), so the first time the browser warns that it isn't trusted: check that the SHA-256 fingerprint matches the one printed at startup or by `service status`, then go on. With a certificate of your own (`--tls-cert`/`--tls-key`: mkcert, `tailscale cert`…) there is no warning. With `--tls off` the network gets plain HTTP and the picture falls back to MJPEG (browsers only offer WebCodecs on localhost or HTTPS), in English or Chinese (follows `IPHONE_CONTROL_LANG`, switchable on the page). **Screen:** the live picture works like a touchscreen: click to tap, drag to swipe, hold to long-press, scroll with the mouse wheel or trackpad, plus a text field and the hardware buttons. On iOS 27 and later the finger follows the pointer as it moves (over CoreDevice HID, which keeps the phone awake until 30 seconds after the last touch); older versions get the whole gesture on release. Everything goes through the daemon like an MCP call, so it queues with the agent and unlocks the phone first. On iOS 27 and later the picture is the phone's own video; otherwise it comes from WDA (none until WDA is ready), as H.264 or MJPEG; see [Picture](#viewer-picture) below. Touch is available when the frame matches the measured size and orientation. After rotating or switching devices, start a new gesture on the updated picture. Settings at the bottom of the sidebar controls the theme and text size. The picture has its own zoom controls, the − and + above it (pinching doesn't zoom, so a drag can't turn into one). **Device panel:** state and readiness checks, installed apps, on-screen elements. The page follows the device the daemon controls: switch on the page or anywhere else, and the picture and panels move over; see [Several Devices](./multi-device#control-page). **AI tasks:** type a task and a local agent carries it out (Claude Code or Codex, whichever is on `PATH`; picked on the page). Before it starts you can limit it to some apps with the App button next to the agent; in any other app each step waits for you. You can pause, take over and hand back, or stop it, and it asks on the page before paying, deleting or sending messages. The token is the key: keep it to yourself. See [Viewer and Remote Use](./remote) |+| `viewer [--port <port>] [--lan] [--lan-host <name>…] [--tls auto\|on\|off] [--tls-cert <PEM> --tls-key <PEM>] [--mcp on\|off]` | Control page in the browser, **behind a login**: every HTTP visit (from this machine too; one forwarded by frp or another reverse proxy looks just like it) needs the token, and `viewer token` shows it with links that log in; a browser stays logged in for 30 days, programs and MCP clients send `Authorization: Bearer <token>`. The same port also serves MCP over HTTP at `/mcp` (see [Connect an AI Client](./mcp-clients#connect-by-url-http); `--mcp off` turns it off). The page is at `http://127.0.0.1:8200/` (default port); with `--lan` also at `https://<this machine's address>:8200/` on the local network (same port; `http://` from the network is sent to `https://`). The certificate is a self-signed one made on this machine (kept in `viewer-tls/` in the data directory and reused), so the first time the browser warns that it isn't trusted: check that the SHA-256 fingerprint matches the one printed at startup or by `service status`, then go on. With a certificate of your own (`--tls-cert`/`--tls-key`: mkcert, `tailscale cert`…) there is no warning. With `--tls off` the network gets plain HTTP and the picture falls back to MJPEG (browsers only offer WebCodecs on localhost or HTTPS). The page is in English or Chinese (follows `IPHONE_CONTROL_LANG`, switchable on the page). **Screen:** the live picture works like a touchscreen: click to tap, drag to swipe, hold to long-press, scroll with the mouse wheel or trackpad, plus a text field and the hardware buttons. On iOS 27 and later the finger follows the pointer as it moves (over CoreDevice HID, which keeps the phone awake until 30 seconds after the last touch); older versions get the whole gesture on release. Everything goes through the daemon like an MCP call, so it queues with the agent and unlocks the phone first. On iOS 27 and later the picture is the phone's own video; otherwise it comes from WDA (none until WDA is ready), as H.264 or MJPEG; see [Picture](#viewer-picture) below. Touch is available when the frame matches the measured size and orientation. After rotating or switching devices, start a new gesture on the updated picture. Settings at the bottom of the sidebar controls the theme and text size. The picture has its own zoom controls, the − and + above it (pinching doesn't zoom, so a drag can't turn into one). **Device panel:** state and readiness checks, installed apps, on-screen elements. The page follows the device the daemon controls: switch on the page or anywhere else, and the picture and panels move over; see [Several Devices](./multi-device#control-page). **AI tasks:** type a task and a local agent carries it out (Claude Code or Codex, whichever is on `PATH`; picked on the page). Before it starts you can limit it to some apps with the App button next to the agent; in any other app each step waits for you. You can pause, take over and hand back, or stop it, and it asks on the page before paying, deleting or sending messages. The token is the key: keep it to yourself. See [Viewer and Remote Use](./remote) || `viewer token [--new]` | Show the viewer's `owner` login token, links that log in on this machine and the local network, and the command to connect to its HTTP MCP; `--new` replaces it: browsers and MCP clients that used the old one need the new one. Tokens are kept in `viewer-tokens.json` in the data directory (0600); changes take effect at once, without restarting the viewer || `viewer token add <name> [--read-only]`, `list`, `show <name> [--new]`, `remove <name>` | Named tokens, one per person or device, say; the page's task log records which token paused, took over or confirmed. A `--read-only` token can watch the picture, the device's state and tasks; every action is refused and the page hides them. `list` doesn't show the tokens themselves; the last token that may operate stays |-| `task run [--title <title>] [--app <app>…] -- <command>` | AI tasks for other agent platforms: opens a task on the controlled device and runs the command in it. An `iphone-control mcp` the command starts takes part (through `IPHONE_CONTROL_TASK_TOKEN`): the control page shows every step and can pause, take over and stop it, and it waits for you before paying or sending a message. The task ends when the command does; when the task is stopped elsewhere, so is the command; Ctrl-C stops the task. While a task runs, other clients can look but not act on the phone. `--app` (repeatable, name or bundle ID) limits the task to those apps: in any other app, or to open a link that isn't a web page, each step waits for you first. **With the phone on another machine**, add `--url https://<that machine>:8200` (and `--ca cert.pem` for a self-signed certificate) and put the login token in `IPHONE_CONTROL_VIEWER_TOKEN`: the task is opened through that machine's viewer, and the command gets the task's token and `IPHONE_CONTROL_MCP_URL`, for its agent to connect to MCP over HTTP (see [Connect an AI Client](./mcp-clients#connect-by-url-http)). The login token isn't passed to the command, so the agent can't pause or confirm its own task; `task finish` in the command works as usual |+| `task run [--title <title>] [--owner <name>] [--app <app>…] -- <command>` | AI tasks for other agent platforms: opens a task on the controlled device and runs the command in it. An `iphone-control mcp` the command starts takes part (through `IPHONE_CONTROL_TASK_TOKEN`): the control page shows every step and can pause, take over and stop it, and it waits for you before paying or sending a message. The task ends when the command does, with the command's exit code as its result; to write its own summary the command runs `task finish [--failed] <summary>`. When the task is stopped elsewhere, so is the command; Ctrl-C stops the task. `--owner` is who the page shows as carrying it out (default `external`). While a task runs, other clients can look but not act on the phone. `--app` (repeatable, name or bundle ID) limits the task to those apps: in any other app, or to open a link that isn't a web page, each step waits for you first. **With the phone on another machine**, add `--url https://<that machine>:8200` (and `--ca cert.pem` for a self-signed certificate) and put the login token in `IPHONE_CONTROL_VIEWER_TOKEN`: the task is opened through that machine's viewer, and the command gets the task's token and `IPHONE_CONTROL_MCP_URL`, for its agent to connect to MCP over HTTP (see [Connect an AI Client](./mcp-clients#connect-by-url-http)). The login token isn't passed to the command, so the agent can't pause or confirm its own task; `task finish` in the command works as usual || `task list` / `task events <id>` | Recent tasks (`--json` for programs); follow a task's events, one JSON per line |-| `task pause\|resume\|takeover\|handback\|stop <id>`, `task approve\|reject <id>` | Control a task from the command line, like the buttons on the control page. Only for a person: from inside the task (the agent's environment or a process it started) they are refused, except `stop`. Every `task` subcommand (`list` and `events` too) takes `--url <viewer> [--ca <PEM>]` (or `IPHONE_CONTROL_URL`) to work on another machine's phone through its viewer, with the login token in `IPHONE_CONTROL_VIEWER_TOKEN`; a command under `task run --url` has no login, so an agent is refused there as well |+| `task pause\|resume\|takeover\|handback\|stop <id>`, `task approve\|reject <id> [--step <n>]` | Control a task from the command line, like the buttons on the control page; `--step` answers only that step's confirmation. Only for a person: from inside the task (the agent's environment or a process it started) they are refused, except `stop`. Every `task` subcommand (`list` and `events` too) takes `--url <viewer> [--ca <PEM>]` (or `IPHONE_CONTROL_URL`) to work on another machine's phone through its viewer, with the login token in `IPHONE_CONTROL_VIEWER_TOKEN`; a command under `task run --url` has no login, so an agent is refused there as well |The `debug` subcommand for diagnostics isn't compiled by default; see the [contributing guide](https://github.com/Derrors/iphone-control/blob/main/CONTRIBUTING.md#testing-on-a-real-phone).diff --git a/website/en/guide/configuration.md b/website/en/guide/configuration.mdindex 172bb33..1196dbf 100644--- a/website/en/guide/configuration.md+++ b/website/en/guide/configuration.md@@ -33,7 +33,9 @@ iphone-control service restart| `IPHONE_CONTROL_VIEWER_TLS` | `auto` | The viewer's HTTPS, like `--tls`: `auto` turns it on when open to the network or given a certificate; `on`, `off`. `http://127.0.0.1` on this machine always works || `IPHONE_CONTROL_VIEWER_TLS_CERT`, `IPHONE_CONTROL_VIEWER_TLS_KEY` | empty | The viewer's own certificate and key (PEM), like `--tls-cert`, `--tls-key`; without them a self-signed one made on this machine || `IPHONE_CONTROL_VIEWER_MCP` | `on` | MCP over HTTP on the viewer's port (`/mcp`), like `--mcp`; `off` turns it off |-| `IPHONE_CONTROL_VIEWER_TOKEN` | empty | Only on another machine: the token `task run --url` logs in to that machine's viewer with (shown there by `iphone-control viewer token`). It isn't passed to the command `task run` starts |+| `IPHONE_CONTROL_VIEWER_TOKEN` | empty | Only on another machine: the token `mcp --url` and `task … --url` (`run`, `list`, `pause` and every other subcommand) log in to that machine's viewer with (shown there by `iphone-control viewer token`). It isn't passed to the command `task run` starts |+| `IPHONE_CONTROL_URL` | empty | Like `--url`: another machine's viewer (`mcp`, `task`). `task run --url` sets it for its command; to another machine only `https://` is taken |+| `IPHONE_CONTROL_CA` | empty | Like `--ca`: trust this certificate (the other machine's self-signed `viewer-tls/cert.pem`) || `IPHONE_UDID` | automatic | Pin the device to control. Unset: the controlled device is kept until it disconnects, and you can switch with the `select` command or the `iphone_select_device` tool. When set, switching is refused || `RESIGN_MIN_DAYS` | `2` | Re-sign when fewer days than this remain || `RESIGN_CHECK_HOURS` | `6` | How often to check; it is also checked within a minute after the phone reconnects or you switch devices |diff --git a/website/en/guide/remote.md b/website/en/guide/remote.mdindex 9c71ab7..2176aae 100644--- a/website/en/guide/remote.md+++ b/website/en/guide/remote.md@@ -29,9 +29,9 @@ iphone-control viewer token show alex --new # replace itiphone-control viewer token remove living-room-tv # browsers that used it are out at once```-- A **read-only token** can watch the picture, the device's state, apps, elements, and tasks with their steps; taps, typing, starting, pausing or confirming tasks, switching devices and `/mcp` are refused. The page shows "Read-only" in its header and hides the text field and buttons.+- A **read-only token** can watch the picture, the device's state, apps, elements, and tasks with their steps; taps, typing, starting, pausing or confirming tasks, switching devices and `/mcp` are refused, and a locked phone isn't unlocked for it (reading the elements says it is locked). The page shows "Read-only" in its header and hides the text field and buttons.- The task log records which token controlled a task, e.g. `viewer:alex`.-- Adding, replacing and removing tokens **takes effect at once**, without restarting the viewer; a browser that used a removed or replaced token is back at the login page on its next request.+- Adding, replacing and removing tokens **takes effect at once**, without restarting the viewer; a browser that used a removed or replaced token is back at the login page on its next request, and the picture, task events, `/mcp` streams and task leases opened with it end within 5 s.- The last token that may operate can't be removed; replace it with `show <name> --new`.## The local network and HTTPS@@ -110,7 +110,7 @@ The command gets the task's token, `IPHONE_CONTROL_URL` and `IPHONE_CONTROL_MCP_When frp, nginx or cloudflared forwards the viewer to the internet:-- The login still applies; a token is 256 random bits, and after 20 wrong tokens in a minute none are checked for the rest of it.+- The login still applies; a token is 256 random bits, and after 20 wrong tokens in a minute wrong ones get 429 for the rest of it (a right token still gets in, so someone trying tokens can't lock you out).- Use HTTPS (a real certificate on the proxy), or the token and cookie cross the internet in the clear.- Something like Tailscale, which only lets your own devices in, is much safer than exposing the port to the internet.diff --git a/website/en/guide/security.md b/website/en/guide/security.mdindex b56ce60..91c5745 100644--- a/website/en/guide/security.md+++ b/website/en/guide/security.md@@ -12,7 +12,7 @@ This page has the essentials. What is stored, who can reach it and the details o## Built-in protections-- **No network ports.** WDA is reached through usbmuxd. `wda-bridge` and the live `viewer` are explicit opt-ins that bind 127.0.0.1 only, and other web pages in your browser can't act through them. `wda-bridge` has no login: every local user can use it, so stop it when done. The `viewer` and the MCP on its port (`/mcp`) need the login token, from this machine too, since the viewer can't tell a local browser from a visit forwarded by frp, cloudflared or another reverse proxy. Tokens are kept in the data directory (0600); `viewer token` shows the owner's and `--new` replaces it, and named read-only tokens (`viewer token add <name> --read-only`) can watch but not act. An agent on another machine gets only its task's token: it acts for that task and can't pause or confirm it. `viewer --lan` opens the viewer to the local network, only to local-network addresses and over HTTPS there.+- **No network ports.** WDA is reached through usbmuxd. `wda-bridge` and the live `viewer` are explicit opt-ins that bind 127.0.0.1 by default (`viewer --lan` also opens to the local network, over HTTPS), and other web pages in your browser can't act through them. `wda-bridge` has no login: every local user can use it, so stop it when done. The `viewer` and the MCP on its port (`/mcp`) need the login token, from this machine too, since the viewer can't tell a local browser from a visit forwarded by frp, cloudflared or another reverse proxy. Tokens are kept in the data directory (0600); `viewer token` shows the owner's and `--new` replaces it, and named read-only tokens (`viewer token add <name> --read-only`) can watch but not act. An agent on another machine gets only its task's token: it acts for that task and can't pause or confirm it. `viewer --lan` opens the viewer to the local network, only to local-network addresses and over HTTPS there.- **No root.** The daemon runs as your regular user, as a per-user service; the install script refuses to run as root.- **Auto-unlock is off by default** and disables itself after one wrong attempt.- **Developer tools are off by default.**diff --git a/website/guide/cli.md b/website/guide/cli.mdindex 7cdd351..2bac8c6 100644--- a/website/guide/cli.md+++ b/website/guide/cli.md@@ -57,7 +57,7 @@ Zsh 在 `~/.zshrc` 的 `compinit` 之前添加 `fpath=(~/.zsh/completions $fpath只想查看版本可运行 `iphone-control update check`,脚本可用 `iphone-control update check --json` 读取结果。该检查与 Viewer「关于与更新」共用本地缓存,网络失败时保留上次成功的记录。Viewer 在「设置」旁的 ⓘ 上用红点提示新版本。打开面板可查看发行说明,并复制针对当前程序路径的更新命令,在本机终端执行。-Viewer 只监听本机回环地址。同机其他用户也能查看安装信息、触发版本检查。安装和更改策略都通过本机 CLI 执行。+Viewer 要用令牌登录(见下面的 `viewer`)。持有令牌的人(只读令牌也一样)能查看安装信息、触发版本检查;安装和更改策略只能在本机终端里执行。受管服务默认只做后台检查。`update apply` 不询问直接安装(受管服务),替换意外中断后用 `update recover`。没有回退到上一版的命令:要换回旧版本,先用发行页的安装脚本加 `--uninstall` 卸载(设置和设备数据保留),再加 `--version vX.Y.Z` 安装那个版本。如果正在使用 0.2.2 的 CLI,先运行 `iphone-control update check` 并按该版本显示的命令升级。新版 CLI 才支持直接运行 `iphone-control update`。@@ -130,12 +130,12 @@ Viewer 只监听本机回环地址。同机其他用户也能查看安装信息|---|---|| `notify-test [事件]` | 发测试通知:每类事件各一条,或只发一类(`resign`、`session`、`pin`、`pin-recovered`、`unlock`、`offline`、`online`) || `wda-bridge [--port <端口>]` | 把 WDA 桥接到 `127.0.0.1`,端口默认 8100,给别的工具用。WDA 没有认证,本机任何用户都能连上,用完就停 |-| `viewer [--port <端口>] [--lan] [--lan-host <名字>…] [--tls auto\|on\|off] [--tls-cert <PEM> --tls-key <PEM>] [--mcp on\|off]` | 浏览器里的控制台,**要先登录**:所有经 HTTP 的访问(本机也一样,经 frp 等反向代理转发进来的访问看起来就是本机)都要令牌,`viewer token` 显示令牌和点开就能登录的链接;浏览器登录一次后记住 30 天,程序和 MCP 客户端用 `Authorization: Bearer <令牌>`。同一个端口的 `/mcp` 还提供 MCP over HTTP(见[接入 AI 客户端](./mcp-clients#通过-url-接入-http),`--mcp off` 关掉),地址 `http://127.0.0.1:8200/`(默认端口);加 `--lan` 时局域网里也能用 `https://<这台机器的 IP>:8200/` 打开(同一个端口;局域网来的 `http://` 会跳到 `https://`)。证书默认是本机生成的自签证书(存在数据目录的 `viewer-tls/`,一直沿用),浏览器第一次打开会提示不受信任:核对启动时或 `service status` 显示的 SHA-256 指纹一致后继续。用 `--tls-cert`/`--tls-key` 换成自己的证书(mkcert、`tailscale cert` 等)就没有这个提示。`--tls off` 时局域网里是 HTTP,画面退回 MJPEG(浏览器只在 localhost 或 HTTPS 上提供 WebCodecs)。中英文(默认跟着 `IPHONE_CONTROL_LANG`,页面上可切换)。**画面:** 实时画面像触摸屏一样用:点一下是点击,拖动是滑动,按住是长按,滚动鼠标滚轮或触控板也能滚动页面,另有输入框和硬件键。iOS 27 起手指跟着鼠标实时移动(经 CoreDevice HID,最后一次触摸后 30 秒内手机保持亮屏);更低的版本在松开后发整段手势。操作都和 MCP 调用一样经守护进程,和 agent 的操作排队,并先自动解锁。iOS 27 及以上画面直接用手机自己的视频;其余来自 WDA(WDA 没就绪时没有画面),是 H.264 或 MJPEG,见下面的[画面编码](#viewer-picture)。画面与设备实测的尺寸、方向一致时可以点按。转屏或换机后,请在新画面上重新操作。侧栏底部的「设置」可调整主题和字号,画面缩放用画面上方的加减号调整(双指捏合不缩放,免得拖动时误触)。**设备面板:** 状态和就绪检查、已安装的 App、屏幕上的元素。页面跟着守护进程控制的设备走,在页面上或别处切换设备,画面和面板都会跟过去,见[多台设备](./multi-device#control-page)。**AI 任务:** 写下任务,交给本机的 agent 执行(PATH 里有的 Claude Code 或 Codex,在页面上选)。开任务前可以用 Agent 旁边的 App 按钮限定范围,到了别的 App 每一步都先等你确认。可以暂停、接管后交还、停止;付款、删除、发消息之前它会在页面上请你确认。令牌就是钥匙,别外传。详见[控制台与远程使用](./remote) |+| `viewer [--port <端口>] [--lan] [--lan-host <名字>…] [--tls auto\|on\|off] [--tls-cert <PEM> --tls-key <PEM>] [--mcp on\|off]` | 浏览器里的控制台,**要先登录**:所有经 HTTP 的访问(本机也一样,经 frp 等反向代理转发进来的访问看起来就是本机)都要令牌,`viewer token` 显示令牌和点开就能登录的链接;浏览器登录一次后记住 30 天,程序和 MCP 客户端用 `Authorization: Bearer <令牌>`。同一个端口的 `/mcp` 还提供 MCP over HTTP(见[接入 AI 客户端](./mcp-clients#通过-url-接入-http),`--mcp off` 关掉),地址 `http://127.0.0.1:8200/`(默认端口);加 `--lan` 时局域网里也能用 `https://<这台机器的 IP>:8200/` 打开(同一个端口;局域网来的 `http://` 会跳到 `https://`)。证书默认是本机生成的自签证书(存在数据目录的 `viewer-tls/`,一直沿用),浏览器第一次打开会提示不受信任:核对启动时或 `service status` 显示的 SHA-256 指纹一致后继续。用 `--tls-cert`/`--tls-key` 换成自己的证书(mkcert、`tailscale cert` 等)就没有这个提示。`--tls off` 时局域网里是 HTTP,画面退回 MJPEG(浏览器只在 localhost 或 HTTPS 上提供 WebCodecs)。页面有中英文两种(默认跟着 `IPHONE_CONTROL_LANG`,页面上可切换)。**画面:** 实时画面像触摸屏一样用:点一下是点击,拖动是滑动,按住是长按,滚动鼠标滚轮或触控板也能滚动页面,另有输入框和硬件键。iOS 27 起手指跟着鼠标实时移动(经 CoreDevice HID,最后一次触摸后 30 秒内手机保持亮屏);更低的版本在松开后发整段手势。操作都和 MCP 调用一样经守护进程,和 agent 的操作排队,并先自动解锁。iOS 27 及以上画面直接用手机自己的视频;其余来自 WDA(WDA 没就绪时没有画面),是 H.264 或 MJPEG,见下面的[画面编码](#viewer-picture)。画面与设备实测的尺寸、方向一致时可以点按。转屏或换机后,请在新画面上重新操作。侧栏底部的「设置」可调整主题和字号,画面缩放用画面上方的加减号调整(双指捏合不缩放,免得拖动时误触)。**设备面板:** 状态和就绪检查、已安装的 App、屏幕上的元素。页面跟着守护进程控制的设备走,在页面上或别处切换设备,画面和面板都会跟过去,见[多台设备](./multi-device#control-page)。**AI 任务:** 写下任务,交给本机的 agent 执行(PATH 里有的 Claude Code 或 Codex,在页面上选)。开任务前可以用 Agent 旁边的 App 按钮限定范围,到了别的 App 每一步都先等你确认。可以暂停、接管后交还、停止;付款、删除、发消息之前它会在页面上请你确认。令牌就是钥匙,别外传。详见[控制台与远程使用](./remote) || `viewer token [--new]` | 显示控制台的 `owner` 登录令牌、本机和局域网的登录链接,以及接入 HTTP MCP 的命令;`--new` 换一个新的,用旧令牌登录的浏览器和 MCP 客户端都要用新的。令牌存在数据目录的 `viewer-tokens.json`(0600),改动马上生效,不用重启控制台 || `viewer token add <名字> [--read-only]`、`list`、`show <名字> [--new]`、`remove <名字>` | 有名字的令牌,比如每人一个、每台设备一个;控制台的任务记录里记下是哪个令牌暂停、接管、确认的。`--read-only` 的令牌只能看画面、设备状态和任务,所有操作都被拒绝,页面上也不显示操作入口。`list` 不显示令牌本身;最后一个能操作的令牌不能删 |-| `task run [--title <标题>] [--app <App>…] -- <命令>` | 给别的 agent 平台用的 AI 任务:在当前控制的设备上开一个任务,再运行这条命令。命令启动的 `iphone-control mcp` 自动加入任务(经环境变量 `IPHONE_CONTROL_TASK_TOKEN`),控制台上能看到每一步,可以暂停、接管、停止,付款、发消息之前会等你确认。命令结束,任务就结束;任务在别处被停止,命令也会被停止;按 Ctrl-C 等于停止任务。任务进行中,其他客户端只能看,不能操作手机。`--app`(可写多次,App 名或 Bundle ID)把任务限定在这些 App 里:到了别的 App、或者要打开网页以外的链接,每一步都先等你确认。**手机接在另一台机器上**时加 `--url https://<那台机器>:8200`(自签证书再加 `--ca cert.pem`),登录令牌放在环境变量 `IPHONE_CONTROL_VIEWER_TOKEN` 里:任务经那台机器的控制台开,命令拿到的是任务口令和 `IPHONE_CONTROL_MCP_URL`,它的 agent 用 HTTP 方式的 MCP 接入(见[接入 AI 客户端](./mcp-clients#通过-url-接入-http))。登录令牌不会传给命令,所以 agent 不能暂停、确认自己的任务;命令里的 `task finish` 照样能用 |+| `task run [--title <标题>] [--owner <名字>] [--app <App>…] -- <命令>` | 给别的 agent 平台用的 AI 任务:在当前控制的设备上开一个任务,再运行这条命令。命令启动的 `iphone-control mcp` 自动加入任务(经环境变量 `IPHONE_CONTROL_TASK_TOKEN`),控制台上能看到每一步,可以暂停、接管、停止,付款、发消息之前会等你确认。命令结束,任务就结束,结果取命令的退出码;命令想自己写总结,就在里面运行 `task finish [--failed] <总结>`。任务在别处被停止,命令也会被停止;按 Ctrl-C 等于停止任务。`--owner` 是控制台上显示的执行方(默认 `external`)。任务进行中,其他客户端只能看,不能操作手机。`--app`(可写多次,App 名或 Bundle ID)把任务限定在这些 App 里:到了别的 App、或者要打开网页以外的链接,每一步都先等你确认。**手机接在另一台机器上**时加 `--url https://<那台机器>:8200`(自签证书再加 `--ca cert.pem`),登录令牌放在环境变量 `IPHONE_CONTROL_VIEWER_TOKEN` 里:任务经那台机器的控制台开,命令拿到的是任务口令和 `IPHONE_CONTROL_MCP_URL`,它的 agent 用 HTTP 方式的 MCP 接入(见[接入 AI 客户端](./mcp-clients#通过-url-接入-http))。登录令牌不会传给命令,所以 agent 不能暂停、确认自己的任务;命令里的 `task finish` 照样能用 || `task list` / `task events <id>` | 最近的任务(`--json` 给程序读);跟着一个任务的事件,每行一个 JSON |-| `task pause\|resume\|takeover\|handback\|stop <id>`、`task approve\|reject <id>` | 在命令行里控制任务,和控制台上的按钮一样。只能由人来做:在任务里面(Agent 的环境或它启动的进程)执行会被拒绝,`stop` 除外。`task` 的所有子命令(`list`、`events` 也是)都可以加 `--url <控制台> [--ca <PEM>]`(或设 `IPHONE_CONTROL_URL`),经另一台机器的控制台操作那里的手机,登录令牌放在 `IPHONE_CONTROL_VIEWER_TOKEN`;`task run --url` 启动的命令没有登录令牌,所以 Agent 在里面执行这些也会被拒绝 |+| `task pause\|resume\|takeover\|handback\|stop <id>`、`task approve\|reject <id> [--step <n>]` | 在命令行里控制任务,和控制台上的按钮一样;`--step` 只回答这一步的确认。只能由人来做:在任务里面(Agent 的环境或它启动的进程)执行会被拒绝,`stop` 除外。`task` 的所有子命令(`list`、`events` 也是)都可以加 `--url <控制台> [--ca <PEM>]`(或设 `IPHONE_CONTROL_URL`),经另一台机器的控制台操作那里的手机,登录令牌放在 `IPHONE_CONTROL_VIEWER_TOKEN`;`task run --url` 启动的命令没有登录令牌,所以 Agent 在里面执行这些也会被拒绝 |调试用的 `debug` 子命令默认不编译,见[贡献指南](https://github.com/Derrors/iphone-control/blob/main/CONTRIBUTING.md#testing-on-a-real-phone)。diff --git a/website/guide/configuration.md b/website/guide/configuration.mdindex 01c3c37..8a0a9c8 100644--- a/website/guide/configuration.md+++ b/website/guide/configuration.md@@ -33,7 +33,9 @@ iphone-control service restart| `IPHONE_CONTROL_VIEWER_TLS` | `auto` | 控制台的 HTTPS,同 `--tls`:`auto` 在对局域网开放或给了证书时开启,`on`、`off`。本机的 `http://127.0.0.1` 一直能用 || `IPHONE_CONTROL_VIEWER_TLS_CERT`、`IPHONE_CONTROL_VIEWER_TLS_KEY` | 空 | 控制台用自己的证书和私钥(PEM),同 `--tls-cert`、`--tls-key`;不设就用本机生成的自签证书 || `IPHONE_CONTROL_VIEWER_MCP` | `on` | 控制台同一个端口上的 MCP over HTTP(`/mcp`),同 `--mcp`;`off` 关掉 |-| `IPHONE_CONTROL_VIEWER_TOKEN` | 空 | 只在另一台机器上用:`task run --url` 登录那台机器的控制台用的令牌(那台机器上 `iphone-control viewer token` 显示的)。不会传给 `task run` 启动的命令 |+| `IPHONE_CONTROL_VIEWER_TOKEN` | 空 | 只在另一台机器上用:`mcp --url` 和 `task … --url`(`run`、`list`、`pause` 等所有子命令)登录那台机器的控制台用的令牌(那台机器上 `iphone-control viewer token` 显示的)。不会传给 `task run` 启动的命令 |+| `IPHONE_CONTROL_URL` | 空 | 同 `--url`:另一台机器的控制台地址(`mcp`、`task`)。`task run --url` 给它启动的命令设好这一项;指向另一台机器时只接受 `https://` |+| `IPHONE_CONTROL_CA` | 空 | 同 `--ca`:信任这张证书(另一台机器 `viewer-tls/cert.pem` 的自签证书) || `IPHONE_UDID` | 自动选 | 固定控制哪台设备。不设时自动选:正在控制的那台一直用到它断开;运行中可以用 `select` 命令或 `iphone_select_device` 工具切换。设了就不能切换 || `RESIGN_MIN_DAYS` | `2` | 描述文件剩余不到几天时重签 || `RESIGN_CHECK_HOURS` | `6` | 每隔几小时检查一次;手机重新连上或切换设备后 1 分钟内也查一次 |diff --git a/website/guide/remote.md b/website/guide/remote.mdindex 7c95eb7..5fc7aef 100644--- a/website/guide/remote.md+++ b/website/guide/remote.md@@ -29,9 +29,9 @@ iphone-control viewer token show 小王 --new # 换一个新的iphone-control viewer token remove 客厅电视 # 用它登录的浏览器马上进不来```-- **只读令牌**能看画面、设备状态、App 列表、元素、任务和它的每一步;点按、输入、开任务、暂停、确认、切换设备、`/mcp` 都会被拒绝。页面上顶栏会显示「只读」,输入框和按键都不显示。+- **只读令牌**能看画面、设备状态、App 列表、元素、任务和它的每一步;点按、输入、开任务、暂停、确认、切换设备、`/mcp` 都会被拒绝;手机锁着时也不会替它解锁(读元素会说明已锁屏)。页面上顶栏会显示「只读」,输入框和按键都不显示。- 任务记录里写下是哪个令牌做的控制,比如 `viewer:小王`。-- 增删、换令牌**马上生效**,不用重启控制台;被删或被换掉的令牌,用它登录的浏览器下一次请求就回到登录页。+- 增删、换令牌**马上生效**,不用重启控制台;被删或被换掉的令牌,用它登录的浏览器下一次请求就回到登录页,用它打开的画面、任务事件、`/mcp` 和任务租约 5 秒内断开。- 最后一个能操作的令牌不能删;要换掉它用 `show <名字> --new`。## 局域网访问和 HTTPS@@ -110,7 +110,7 @@ iphone-control task run --url https://<那台机器>:8200 --ca cert.pem -- <启用 frp、nginx、cloudflared 把控制台转发到公网时:-- 登录照样起作用,令牌是 256 位随机数;一分钟里错 20 次后,这一分钟内不再校验令牌。+- 登录照样起作用,令牌是 256 位随机数;一分钟里错 20 次后,这一分钟内错的令牌一律返回 429(正确的令牌照样能进,别人乱试挡不住你)。- 用 HTTPS(反向代理那一侧配正式证书),否则令牌和 cookie 在公网上明文传输。- 更推荐 Tailscale 这类只有你自己的设备连得进来的方式,比直接暴露在公网安全得多。diff --git a/website/guide/security.md b/website/guide/security.mdindex 780555b..5238e16 100644--- a/website/guide/security.md+++ b/website/guide/security.md@@ -12,7 +12,7 @@ iphone-control 本质上是一个手机遥控器:能访问它的人,就能## 默认的保护-- **不开网络端口。** WDA 经 usbmuxd 直连手机。`wda-bridge` 和实时画面 `viewer` 都要显式开启,只绑 127.0.0.1,浏览器里的其他网页借不了它们操作手机。`wda-bridge` 没有登录,本机任何用户都能用,用完就停。`viewer` 和它同一个端口上的 MCP(`/mcp`)要令牌登录,本机也一样:控制台分不清本机的浏览器和经 frp、cloudflared 等反向代理转发进来的访问。令牌存在数据目录(0600),`viewer token` 显示、`--new` 换掉;可以加有名字的只读令牌(`viewer token add <名字> --read-only`),只能看不能操作。另一台机器上的 agent 只拿任务口令,只能为它的任务操作手机,不能暂停或确认自己的任务。`viewer --lan` 会把控制台开放给局域网,只接受局域网地址来的连接,局域网里走 HTTPS。+- **不开网络端口。** WDA 经 usbmuxd 直连手机。`wda-bridge` 和实时画面 `viewer` 都要显式开启,默认只绑 127.0.0.1(`viewer --lan` 也对局域网开放,走 HTTPS),浏览器里的其他网页借不了它们操作手机。`wda-bridge` 没有登录,本机任何用户都能用,用完就停。`viewer` 和它同一个端口上的 MCP(`/mcp`)要令牌登录,本机也一样:控制台分不清本机的浏览器和经 frp、cloudflared 等反向代理转发进来的访问。令牌存在数据目录(0600),`viewer token` 显示、`--new` 换掉;可以加有名字的只读令牌(`viewer token add <名字> --read-only`),只能看不能操作。另一台机器上的 agent 只拿任务口令,只能为它的任务操作手机,不能暂停或确认自己的任务。`viewer --lan` 会把控制台开放给局域网,只接受局域网地址来的连接,局域网里走 HTTPS。- **不用 root。** 守护进程以你的普通用户身份作为用户服务运行,安装脚本拒绝以 root 运行。- **自动解锁默认关闭**,输错一次即停用。- **开发者工具默认关闭**。