Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

公开发布准备:面向用户的文档、社区文件、发布流水线

Derrorsb47e62a1a1cb
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000..b079fc7
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,50 @@
+name: Bug report / 问题反馈
+description: Something doesn't work as expected. 英文或中文都可以。
+labels: [bug]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Security problems: please don't file them here — see SECURITY.md.
+ Remove private data (UDID, Apple ID, notification keys, phone numbers) from everything you paste.
+ 安全问题请不要在这里提,见 SECURITY.md。粘贴前请去掉 UDID、Apple ID、通知密钥、手机号等隐私信息。
+ - type: textarea
+ id: what
+ attributes:
+ label: What happened / 发生了什么
+ description: What you did, what you expected, what happened instead.
+ validations:
+ required: true
+ - type: input
+ id: device
+ attributes:
+ label: Phone model and iOS version / 机型和 iOS 版本
+ placeholder: iPhone 15 Pro Max, iOS 27.0.1
+ validations:
+ required: true
+ - type: dropdown
+ id: deploy
+ attributes:
+ label: How do you run it / 运行方式
+ options:
+ - Docker (compose)
+ - From source (systemd user service or manual)
+ - From source as root
+ validations:
+ required: true
+ - type: input
+ id: version
+ attributes:
+ label: Version or commit / 版本或提交
+ placeholder: v0.1.0, or the output of `git rev-parse --short HEAD`
+ - type: textarea
+ id: doctor
+ attributes:
+ label: Output of `iphone-control doctor`
+ render: text
+ - type: textarea
+ id: logs
+ attributes:
+ label: Relevant logs / 相关日志
+ description: "`docker logs iphone-control`, `data/logs/daemon.log`, or `journalctl --user -u iphone-control`; for MCP problems, the tool call and its result."
+ render: text
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..dd1dbbf
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,8 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Security vulnerability / 安全漏洞
+ url: https://github.com/Derrors/iphone-control/security/advisories/new
+ about: Report privately, please don't open a public issue. 请私下报告,不要公开提 issue。
+ - name: Troubleshooting guide / 排错指南
+ url: https://github.com/Derrors/iphone-control/blob/main/docs/troubleshooting.md
+ about: What each state means and how to fix common problems.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
new file mode 100644
index 0000000..29cc066
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -0,0 +1,19 @@
+name: Feature request / 功能建议
+description: Suggest an improvement. 英文或中文都可以。
+labels: [enhancement]
+body:
+ - type: textarea
+ id: problem
+ attributes:
+ label: What are you trying to do / 想做什么
+ description: The task or workflow, and what gets in the way today.
+ validations:
+ required: true
+ - type: textarea
+ id: idea
+ attributes:
+ label: Proposed solution / 建议的做法
+ - type: textarea
+ id: alternatives
+ attributes:
+ label: Alternatives considered / 考虑过的其他办法
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..514c55b
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,16 @@
+## What and why
+
+<!-- What this changes and why. Link the issue if there is one. 英文或中文都可以。 -->
+
+## How it was tested
+
+- [ ] `cargo test --workspace`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --check` (per package)
+- [ ] On a real phone (model, iOS version, what you ran — e.g. `tests/device/run.py`):
+- [ ] Not needed (docs only, or no device-facing change)
+
+## Checklist
+
+- [ ] MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10)
+- [ ] New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md
+- [ ] User-visible changes noted in CHANGELOG.md under *Unreleased*
+- [ ] No private data in fixtures, screenshots or logs
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..3c377cb
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,20 @@
+# Dependencies are pinned to exact versions on purpose (docs/decisions.md D9): every upgrade arrives as its
+# own pull request and has to pass CI; device-facing ones (idevice, rmcp, tokio) also need a real-phone test.
+version: 2
+updates:
+ - package-ecosystem: cargo
+ directory: /
+ schedule:
+ interval: weekly
+ open-pull-requests-limit: 5
+ ignore:
+ # git dependency pinned to an upstream commit until the next release (docs/decisions.md D1)
+ - dependency-name: idevice
+ groups:
+ minor-and-patch:
+ update-types: [minor, patch]
+ exclude-patterns: [rmcp, tokio, quick-xml]
+ - package-ecosystem: github-actions
+ directory: /
+ schedule:
+ interval: weekly
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..06a74ec
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,174 @@
+name: Release
+
+# 推送 v* tag 时:多架构镜像推到 ghcr(各架构在原生 runner 上构建,不用 QEMU 模拟),
+# 附 SBOM 和构建来源证明;Linux 二进制和 sha256 附在 GitHub Release 上,发布说明取自 CHANGELOG.md。
+on:
+ push:
+ tags: ["v*"]
+
+permissions:
+ contents: read
+
+env:
+ IMAGE: ghcr.io/derrors/iphone-control
+
+jobs:
+ # 从源码运行(不用 Docker)的用户直接下载。在 Ubuntu 22.04 上编译(glibc 2.35),
+ # 所以 Debian 12、Ubuntu 22.04 及更新的发行版都能运行
+ binaries:
+ strategy:
+ matrix:
+ include:
+ - runner: ubuntu-22.04
+ target: x86_64-unknown-linux-gnu
+ - runner: ubuntu-22.04-arm
+ target: aarch64-unknown-linux-gnu
+ runs-on: ${{ matrix.runner }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: dtolnay/[email protected]
+ - uses: Swatinem/rust-cache@v2
+ with:
+ key: release-${{ matrix.target }}
+ - run: cargo build --release --locked -p iphone-control
+ - name: Package
+ run: |
+ name="iphone-control-${GITHUB_REF_NAME}-${{ matrix.target }}"
+ mkdir -p "dist/$name"
+ cp target/release/iphone-control LICENSE THIRD_PARTY.md README.md README.zh-CN.md CHANGELOG.md "dist/$name/"
+ cp -r deploy "dist/$name/"
+ cp .env.example "dist/$name/env.example"
+ tar -C dist -czf "dist/$name.tar.gz" "$name"
+ (cd dist && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256")
+ - uses: actions/upload-artifact@v4
+ with:
+ name: bin-${{ matrix.target }}
+ path: dist/*.tar.gz*
+ if-no-files-found: error
+
+ image:
+ strategy:
+ matrix:
+ include:
+ - runner: ubuntu-24.04
+ platform: linux/amd64
+ - runner: ubuntu-24.04-arm
+ platform: linux/arm64
+ runs-on: ${{ matrix.runner }}
+ permissions:
+ contents: read
+ packages: write
+ steps:
+ - uses: actions/checkout@v4
+ - name: Platform name
+ run: echo "PAIR=${PLATFORM//\//-}" >> "$GITHUB_ENV"
+ env:
+ PLATFORM: ${{ matrix.platform }}
+ - id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.IMAGE }}
+ - uses: docker/setup-buildx-action@v3
+ - uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ # 按 digest 推送,最后一步再合成一个多架构清单打标签
+ - id: build
+ uses: docker/build-push-action@v6
+ with:
+ context: .
+ file: docker/Dockerfile
+ platforms: ${{ matrix.platform }}
+ labels: ${{ steps.meta.outputs.labels }}
+ outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
+ cache-from: type=gha,scope=${{ env.PAIR }}
+ cache-to: type=gha,mode=max,scope=${{ env.PAIR }}
+ sbom: true
+ provenance: mode=max
+ - name: Export digest
+ run: |
+ mkdir -p /tmp/digests
+ touch "/tmp/digests/${DIGEST#sha256:}"
+ env:
+ DIGEST: ${{ steps.build.outputs.digest }}
+ - uses: actions/upload-artifact@v4
+ with:
+ name: digests-${{ env.PAIR }}
+ path: /tmp/digests/*
+ if-no-files-found: error
+
+ publish-image:
+ needs: image
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: read
+ packages: write
+ steps:
+ - uses: actions/download-artifact@v4
+ with:
+ path: /tmp/digests
+ pattern: digests-*
+ merge-multiple: true
+ - id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.IMAGE }}
+ # v1.2.3 → 1.2.3、1.2、latest(预发布版本如 v1.2.3-rc.1 只打自己的版本号,不动 latest)
+ tags: |
+ type=semver,pattern={{version}}
+ type=semver,pattern={{major}}.{{minor}}
+ - uses: docker/setup-buildx-action@v3
+ - uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Create multi-arch manifest
+ working-directory: /tmp/digests
+ run: |
+ # shellcheck disable=SC2046
+ docker buildx imagetools create \
+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
+ $(printf "$IMAGE@sha256:%s " *)
+ - name: Inspect
+ run: docker buildx imagetools inspect "$IMAGE:$VERSION"
+ env:
+ VERSION: ${{ steps.meta.outputs.version }}
+
+ release:
+ needs: [binaries, publish-image]
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/download-artifact@v4
+ with:
+ path: dist
+ pattern: bin-*
+ merge-multiple: true
+ - name: Release notes from CHANGELOG.md
+ run: |
+ version="${GITHUB_REF_NAME#v}"
+ # 「## [1.2.3]」到下一个「## [」之间
+ awk -v v="$version" '
+ /^## \[/ { if (found) exit; if (index($0, "## [" v "]") == 1) { found = 1; next } }
+ found { print }
+ ' CHANGELOG.md > notes.md
+ if [ ! -s notes.md ]; then
+ echo "CHANGELOG.md 里没有 ## [$version] 一节" >&2
+ exit 1
+ fi
+ {
+ echo
+ echo "**Docker image:** \`${IMAGE}:${version}\` (linux/amd64, linux/arm64)"
+ } >> notes.md
+ - name: Create release
+ run: |
+ flags=()
+ case "$GITHUB_REF_NAME" in *-*) flags+=(--prerelease) ;; esac
+ gh release create "$GITHUB_REF_NAME" dist/* --title "$GITHUB_REF_NAME" --notes-file notes.md "${flags[@]}"
+ env:
+ GH_TOKEN: ${{ github.token }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..d4b7aea
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,27 @@
+# Changelog
+
+All notable changes to this project are documented here. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/) (while at 0.x, minor versions may contain breaking changes).
+
+## [Unreleased]
+
+## [0.1.0] - unreleased
+
+First public release.
+
+### Added
+
+- `iphone-control daemon`: one long-running process owns the phone — usbmuxd supervision (with a sysfs fallback for containers without udev), pairing and Developer Mode checks, Developer Disk Image download and mounting, a CoreDevice tunnel with a user-space TCP stack, WebDriverAgent launch and health checks, and a state machine that recovers from unplugging, usbmuxd restarts and phone reboots.
+- MCP server with 15 tools: status, screenshots with zoom-in regions, element lists, tap / tap by text, long press, swipe, typing (including Chinese), hardware buttons, app launch / terminate / list, URLs, `iphone_wait_for` and `iphone_batch`. Action tools accept `then` to return the screen after the action.
+- HID fallback for taps, swipes, buttons, ASCII typing and screenshots while WebDriverAgent is unavailable.
+- Signing of WebDriverAgent with a free Apple ID (two-factor and SMS login), including the `.xctest` bundle, a post-signing check, automatic re-signing before the 7-day profile expires, and a daily Apple ID session check.
+- Notifications through Bark and Telegram, with de-duplication.
+- Optional auto-unlock with strict safeguards (stops after one wrong attempt).
+- `setup` wizard, `doctor` diagnostics, `status`, `mcp-config`, `wda-bridge`, `notify-test`.
+- Docker image (single binary plus Debian's usbmuxd, not privileged) with a generated third-party license list, and a systemd user service for running from source.
+
+### Fixed
+
+- A custom anisette server (`ICTL_ANISETTE_URL`) was silently ignored; the default third-party server was always used.
+
+[Unreleased]: https://github.com/Derrors/iphone-control/compare/v0.1.0...HEAD
+[0.1.0]: https://github.com/Derrors/iphone-control/releases/tag/v0.1.0
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..4b49b66
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,83 @@
+# Contributing
+
+Thanks for helping! Issues and pull requests are welcome in **English or Chinese** (欢迎用中文提 issue 和 PR).
+
+Most of the code comments, design documents and commit messages in this repository are written in Chinese. Follow the language of the code you are editing; English is fine for new files and for commit messages.
+
+## Before you start
+
+- **Bugs:** include the phone model, iOS version, how you run it (container or source), and the output of `iphone-control doctor`, with private data removed. The [issue template](.github/ISSUE_TEMPLATE/bug_report.yml) asks for these.
+- **Larger changes:** open an issue first. The key design decisions and their reasons are in [docs/decisions.md](docs/decisions.md); the regression cases every change must keep passing are in [docs/dev/roadmap.md](docs/dev/roadmap.md#必须覆盖的回归用例).
+- **Security problems:** don't open an issue — see [SECURITY.md](SECURITY.md).
+
+## Building and testing without a phone
+
+You need Rust 1.88 or later (CI pins 1.99.1) and a C compiler. Everything except the device tests runs offline:
+
+```bash
+cargo test --workspace --locked
+cargo clippy --workspace --all-targets --locked -- -D warnings
+# vendor/ is upstream code and isn't formatted; check only this repository's packages:
+for p in ictl-device ictl-wda ictl-sign ictl-unlock ictl-daemon ictl-mcp ictl-protocol iphone-control; do cargo fmt -p $p -- --check; done
+```
+
+Or, without Rust installed:
+
+```bash
+docker run --rm -v "$PWD":/src -w /src rust:1-trixie sh -c \
+ 'rustup component add clippy && cargo test --workspace --locked && cargo clippy --workspace --all-targets --locked -- -D warnings'
+```
+
+Behind a firewall add `--network host -e HTTP_PROXY -e HTTPS_PROXY` (`idevice` is a git dependency). `cargo test -p <one crate>` can fail to compile `plume_store` because of feature unification; test the whole workspace instead.
+
+The pure logic — element-tree parsing, occlusion, the auto-unlock rules (against a fake WebDriverAgent), the daemon state machine, MCP argument handling — is covered by unit tests. Real iOS 27 element trees used as fixtures are in [crates/ictl-wda/tests/fixtures](crates/ictl-wda/tests/fixtures).
+
+## Testing on a real phone
+
+Anything that touches the device, timing or WebDriverAgent behaviour needs a real phone. With the daemon running (container or source):
+
+```bash
+python3 -m venv .venv && .venv/bin/pip install -r tests/device/requirements.txt
+.venv/bin/python tests/device/run.py # default steps: harmless (Home, Clock tabs, Spotlight search)
+.venv/bin/python tests/device/run.py '[["iphone_launch_app", {"app": "设置"}], ["iphone_screenshot", {}]]'
+```
+
+It prints every result with its wall time and saves screenshots to `./shots`. Set `MCP_CMD` for a source install (for example `MCP_CMD="iphone-control mcp"`). Please mention in the pull request what you ran on which device and iOS version.
+
+Notes:
+
+- Wait until `iphone-control status` says 就绪 (ready) before calling tools after a restart. Restarting the daemon several times in quick succession can make the phone ask for the passcode to enable UI automation again.
+- Never run two daemons, or the hidden `iphone-control debug …` diagnostics, against the same phone at once: only one usbmuxd and one XCTest session can own it.
+- Don't automate anything that sends messages, pays, deletes data or changes account or privacy settings in tests.
+
+### Adding an element-tree fixture
+
+1. `iphone-control wda-bridge --port 18100` (stop it afterwards — WebDriverAgent has no authentication).
+2. ```bash
+ curl -s "127.0.0.1:18100/source?format=xml&excluded_attributes=visible,accessible,focused,enabled,selected,index,traits,placeholderValue,hittable,customActions,nativeFrame" \
+ | python3 -c 'import sys, json; print(json.load(sys.stdin)["value"])' > fixture.xml
+ ```
+3. **Scrub it:** names, phone numbers, email addresses, locations, notification contents, the device name. Check with `grep -o 'label="[^"]*"' fixture.xml | sort -u`.
+
+## Rules of thumb
+
+- **Pin exact versions** (`=x.y.z`) and keep `Cargo.lock` committed; upgrade dependencies in separate commits ([D9](docs/decisions.md)).
+- **Don't break the MCP interface:** tool names, parameters and default outputs stay compatible; add optional parameters instead ([D10](docs/decisions.md)).
+- **Vendored code** (`vendor/`) keeps its license. Record any change in [THIRD_PARTY.md](THIRD_PARTY.md); changed MPL-2.0 files stay MPL-2.0.
+- **Never commit** `data/`, `.env`, certificates, provisioning profiles, pairing records or anything Apple ships (Developer Disk Images, frameworks).
+- Comments explain *why*, especially device quirks; put measured numbers next to timeouts and thresholds.
+
+## Pull requests
+
+- Keep them focused; describe what changed and how you tested it (offline and/or which device).
+- CI must pass: format, clippy with `-D warnings`, tests, the MSRV check, gitleaks and the image build.
+- User-visible changes get a line in [CHANGELOG.md](CHANGELOG.md) under *Unreleased*.
+
+## Releasing (maintainers)
+
+1. Move the *Unreleased* entries in [CHANGELOG.md](CHANGELOG.md) under `## [x.y.z] - YYYY-MM-DD` and update the compare links at the bottom.
+2. Set `version` in the root `Cargo.toml` (`[workspace.package]`) and run `cargo check --workspace` to update `Cargo.lock`.
+3. Commit, tag `vx.y.z`, push the tag. [`release.yml`](.github/workflows/release.yml) builds the amd64/arm64 images on native runners and pushes them to `ghcr.io/derrors/iphone-control` (tags `x.y.z`, `x.y`, `latest`; pre-releases such as `v0.2.0-rc.1` only get their own tag), builds the Linux binaries, and creates the GitHub release from the changelog section.
+4. First release only: make the ghcr package public (*Package settings → Change visibility*) — new packages start private.
+
+By contributing you agree that your contributions are licensed under the MIT license, except for changes to vendored files, which stay under their original licenses.
diff --git a/Cargo.toml b/Cargo.toml
index cf825bd..b583d2e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,6 +21,8 @@ edition = "2024"
rust-version = "1.88"
license = "MIT"
publish = false
+repository = "https://github.com/Derrors/iphone-control"
+homepage = "https://github.com/Derrors/iphone-control"
# 全部锁精确版本:idevice 0.2.0 之前每个小版本都可能有破坏性变更(见 docs/decisions.md D9)
[workspace.dependencies]
diff --git a/README.md b/README.md
index 87c2f3c..6be4193 100644
--- a/README.md
+++ b/README.md
@@ -1,130 +1,179 @@
# iphone-control
-在 Linux 上(不需要 Mac、不需要付费开发者账号)控制一台通过 USB 连接的真实 iPhone,并把能力以 MCP 工具的形式提供给 AI agent。用 Rust 写成,产物是**一个二进制**,外加系统自带的 `usbmuxd`。
+**English** | [简体中文](README.zh-CN.md)
-> **状态:阶段 0~6 已在真机(iPhone 15 Pro Max,iOS 27.0.1)通过**:设备层、守护进程、MCP、签名重签、通知、自动解锁。
-> 97 个离线单测和 `clippy -D warnings` 都通过;阶段 7(打包发布)还有几项没做。
-> 保底方案是前身项目 iphone-control-toolkit。各阶段的真机结果和剩余项见 [roadmap 的完成情况](docs/roadmap.md#完成情况)。
+[![CI](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml/badge.svg)](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml)
+[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
-## 与 iphone-control-toolkit 的关系
+Control a real, USB-connected iPhone from Linux — no Mac, no paid Apple developer account — and hand it to AI agents as [MCP](https://modelcontextprotocol.io) tools. One Rust binary plus the system `usbmuxd`.
-| | iphone-control-toolkit(B 方案,保底) | iphone-control(本仓库,D 方案) |
-|---|---|---|
-| 做法 | 容器里装 go-ios、pymobiledevice3、plumesign 的命令行,由 Python MCP 和 shell 脚本调用 | 基于 Rust 库 [idevice](https://github.com/jkcoxson/idevice) 和 [Impactor](https://github.com/claration/impactor) 的组件,一个进程完成全部工作 |
-| 语言 | Go + Python + Rust + Shell | Rust(手机端 WDA 仍是 Objective-C) |
-| 进程 | supervisor.sh + 多个命令行进程,每条 HID 命令重建隧道 | 一个守护进程独占设备,隧道、HID 会话、WDA 会话常驻复用 |
-| WDA 端口 | 转发到 127.0.0.1:8100 | 经 usbmuxd 直连手机,**本机不监听任何端口** |
-| 许可证 | MIT(自己的代码) | MIT(自己的代码);vendor 的签名组件是 MPL-2.0,见 [licensing](docs/licensing.md) |
-| iOS 27 实测 | 全部通过 | 阶段 0~6 全部通过 |
+> **Status: early (0.x).** Everything below works end to end on one device: iPhone 15 Pro Max, iOS 27.0.1. Other models and iOS 17+ should work but are untested — reports are welcome.
+>
+> The CLI, `doctor` output and MCP tool results are currently in **Simplified Chinese**. Agents handle this fine; a human reading the logs may need a translator.
+
+## What it does
+
+- **Agent tools** — screenshots (with zoom-in regions), on-screen element lists, tap by coordinates or by text, swipe, long press, typing (including Chinese), hardware buttons, launch/terminate apps, open URLs, wait for text to appear, and batches of steps. Any action can also return the resulting screen, saving the agent a round trip. See [docs/tools.md](docs/tools.md).
+- **Keeps itself running** — pairs with the phone, mounts the Developer Disk Image, signs WebDriverAgent with your free Apple ID and re-signs it before the 7-day profile expires, restarts WDA when it dies, and recovers after the phone is unplugged or rebooted.
+- **Fallback path** — when WDA is down, taps, swipes, key presses and screenshots still work through CoreDevice HID.
+- **Tells you when it needs you** — Bark or Telegram notifications for a failed re-sign, an expired Apple ID session, a reboot that needs the passcode, or the phone going offline.
+- **Optional auto-unlock** — off by default; read [SECURITY.md](SECURITY.md) before turning it on.
+- **No open ports** — WDA is reached through usbmuxd; nothing listens on the network.
+
+```
+AI agent ──stdio──▶ iphone-control mcp ──unix socket──▶ iphone-control daemon ──usbmuxd/USB──▶ iPhone (WebDriverAgent)
+```
+
+One long-running daemon owns the device (tunnel, HID session, WDA session); each agent session gets a thin MCP client. Details: [docs/architecture.md](docs/architecture.md) (Chinese).
-两者的 MCP 工具名、参数、返回文字保持一致,切换时 agent 侧不用改。
+## Requirements
-## 快速开始
+- A Linux host (x86_64 or arm64) with a USB port.
+- Docker with Compose v2 — or, without Docker, Rust 1.88+, a C compiler and `usbmuxd` ([install from source](#install-from-source-without-docker)).
+- An iPhone on iOS 17 or later with a data cable. Setup walks you through Developer Mode.
+- A free Apple ID. Using a dedicated one is recommended (see [Security](#security-and-privacy)).
+- Internet access to Apple, to the anisette server, and to GitHub (the Developer Disk Image and WebDriverAgent are downloaded on first use).
+
+## Quick start (Docker)
```bash
-cp .env.example .env # 按需改代理、通知
-docker compose up -d --build # 首次构建要编译 Rust,约 2 分钟(依赖和编译产物走构建缓存)
-docker exec -it iphone-control iphone-control setup # 配对 → 开发者模式 → 登录 Apple ID → 签名安装 WDA
-docker exec -it iphone-control iphone-control mcp-config # 打印注册到 Claude Code 的命令
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cp .env.example .env # optional: proxy, notifications, auto-unlock settings
+docker compose up -d --build # the first build compiles Rust and takes a few minutes
+docker exec -it iphone-control iphone-control setup
+docker exec -it iphone-control iphone-control mcp-config # prints the command to register the MCP server
```
-> 不要和 toolkit 同时连着同一部手机:两边都会拉起 usbmuxd、各自持有 XCTest 会话。
->
-> 容器不用 `privileged`:只开放 USB 字符设备(`device_cgroup_rules: "c 189:* rmw"`),`/dev/bus/usb` 绑定挂载。这套设置下的 USB 拔插恢复已在真机上确认。
+Once a release is published you can skip the build: set `IMAGE=ghcr.io/derrors/iphone-control:latest` in `.env`, then run `docker compose pull && docker compose up -d --no-build`.
-## 从源码运行(不用 Docker)
+`setup` can be re-run at any time. It walks through:
-需要 Rust 1.88 以上([rustup](https://rustup.rs))、C 编译器(编译 bzip2/xz 的捆绑源码)和系统的 usbmuxd。以 Debian/Ubuntu 为例:
+1. **Connect** the phone and unlock it.
+2. **Pair** — tap *Trust* on the phone and enter the passcode.
+3. **Developer Mode** — *Settings → Privacy & Security → Developer Mode → On*, restart, then confirm after unlocking.
+4. **Apple ID login** — the password and two-factor code are typed into this terminal only.
+5. **Sign and install WebDriverAgent** — keep the phone unlocked.
+6. **Start WebDriverAgent** — the first time, trust your Apple ID under *Settings → General → VPN & Device Management*. If the phone asks you to *enter the iPhone passcode for "XCTest"* (Enable UI Automation), enter it.
+
+The container is not `privileged`: it only gets USB character devices (`device_cgroup_rules: "c 189:* rmw"`) plus a bind mount of `/dev/bus/usb`. Don't run two copies (or another usbmuxd-based tool) against the same phone.
+
+## Connect an MCP client
+
+Claude Code (this is what `mcp-config` prints for the container):
```bash
-sudo apt install build-essential git usbmuxd # usbmuxd 由 udev 在插上手机时拉起
-git clone <本仓库地址> iphone-control && cd iphone-control
-cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control
-iphone-control daemon # 前台运行;常驻用下面的 systemd 用户服务
-iphone-control setup # 另开一个终端:配对 → 开发者模式 → 登录 Apple ID → 签名安装 WDA
-iphone-control mcp-config # 打印 claude mcp add iphone -s user -- ~/.cargo/bin/iphone-control --socket … mcp
+claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mcp
```
-以普通用户运行,和容器部署的区别:
+Other clients (Claude Desktop, Cursor, …) take the same command in their JSON config:
-| | 容器 | 从源码(普通用户) |
-|---|---|---|
-| 数据目录 | `./data`(容器内 `/var/lib/iphone-control`) | `~/.local/share/iphone-control` |
-| 控制接口 | 容器内 `/run/iphone-control/ctl.sock` | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` |
-| usbmuxd | 守护进程拉起并看护;容器没有 udev,靠 sysfs 发现漏掉的设备 | 系统服务,udev 处理插拔;守护进程不拉起 |
-| 配对记录 | 数据目录的 `lockdown/` | 系统的 `/var/lib/lockdown`(usbmuxd 管理) |
-| 未签名的 WDA | 镜像自带 | 第一次签名前下载同一版本(核对 sha256),存到数据目录的 `wda/` |
-| 配置 | `.env` | 环境变量:shell 里 `set -a; . ~/.config/iphone-control/env; set +a`,或 systemd 的环境文件 |
-| MCP | `docker exec -i iphone-control iphone-control mcp` | 直接调用二进制 |
+```json
+{
+ "mcpServers": {
+ "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] }
+ }
+}
+```
-常驻运行用 [deploy/iphone-control.service](deploy/iphone-control.service)(systemd 用户服务):
+For a source install, use `iphone-control --socket <path> mcp` instead; `iphone-control mcp-config` prints the exact command.
+
+## Install from source (without Docker)
+
+Debian/Ubuntu example:
+
+```bash
+sudo apt install build-essential git usbmuxd # udev starts usbmuxd when the phone is plugged in
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cargo install --path apps/iphone-control --locked # installs ~/.cargo/bin/iphone-control
+iphone-control daemon # foreground; see below for a systemd user service
+iphone-control setup # in a second terminal
+iphone-control mcp-config
+```
+
+To keep it running, use the systemd user service in [deploy/iphone-control.service](deploy/iphone-control.service):
```bash
mkdir -p ~/.config/systemd/user ~/.config/iphone-control
cp deploy/iphone-control.service ~/.config/systemd/user/
-cp .env.example ~/.config/iphone-control/env # 按需改代理、通知;CONTAINER_NAME、IMAGE、DATA_DIR 只给 compose 用
+cp .env.example ~/.config/iphone-control/env # CONTAINER_NAME, IMAGE and DATA_DIR are compose-only
systemctl --user daemon-reload && systemctl --user enable --now iphone-control
-loginctl enable-linger "$USER" # 不登录也随开机启动
+loginctl enable-linger "$USER" # start at boot without logging in
```
-> - 守护进程、`setup` 等命令和 MCP 要用同一个用户运行:路径按用户算,别的用户要用 `--socket`、`--data-dir`(或 `ICTL_SOCKET`、`ICTL_DATA_DIR`)指过去。
-> - 以 root 运行时默认路径和容器里一样(`/var/lib/iphone-control`、`/run/iphone-control/ctl.sock`),守护进程会自己拉起 usbmuxd;宿主机已有 usbmuxd 服务时设 `ICTL_MANAGE_USBMUXD=0`。
-> - 不要和容器版同时连同一部手机。装了系统 usbmuxd 后,一插手机 udev 就会拉起它,和容器里的 usbmuxd 抢设备;还要用容器版时先 `sudo systemctl mask usbmuxd`。
+| | Container | Source install (regular user) |
+|---|---|---|
+| Data directory | `./data` (`/var/lib/iphone-control` inside) | `~/.local/share/iphone-control` |
+| Control socket | `/run/iphone-control/ctl.sock` inside the container | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` |
+| usbmuxd | started and supervised by the daemon (no udev in the container) | the system service; the daemon does not start it |
+| Pairing records | `lockdown/` in the data directory | the system's `/var/lib/lockdown` |
+| Unsigned WDA | shipped in the image | downloaded (sha256-checked) before the first signing |
+| Configuration | `.env` | environment variables, e.g. the systemd `EnvironmentFile` |
-## 命令
+Run the daemon, the CLI and the MCP server as the same user. With a host `usbmuxd` installed, `sudo systemctl mask usbmuxd` before going back to the container, or the two will fight over the phone.
-| 命令 | 作用 |
+## Commands
+
+| Command | Purpose |
|---|---|
-| `daemon` | 常驻守护进程(容器入口):状态机、usbmuxd 看护、重签调度、通知、控制接口 |
-| `mcp` | MCP stdio 服务,经控制接口调用守护进程 |
-| `status` / `doctor` | 状态快照、最近日志 / 逐层诊断 |
-| `setup` | 首次安装向导,可重复运行 |
-| `login` | 登录 Apple ID(密码不回显,支持双重认证和短信) |
-| `sign` / `resign [--force]` | 签名安装 WDA / 快过期才重签 |
-| `passcode set\|clear` / `unlock-reset` | 自动解锁(默认关闭) |
-| `wda-bridge --port 8100` | 显式把 WDA 桥接到 127.0.0.1,供外部工具使用(见下方注意) |
-| `notify-test` | 按已配置的渠道给每类事件发一条测试通知 |
-
-> `wda-bridge`:WDA 没有认证。bridge 只转发 Host 头是 `localhost`/`127.0.0.1`/`[::1]` 的请求,挡住网页借 DNS rebinding 访问;
-> 但容器用 host 网络,**本机的任何用户都能连上这个端口**,用完就停。
->
-> 隐藏命令 `debug <ddi|hid|screenshot|soak|wda|e2e>` 是真机诊断(原第 0 步 spike,结果见 [spike-results](docs/spike-results.md)),直接操作设备,运行前先停掉守护进程。
+| `daemon` | The long-running daemon (container entry point) |
+| `mcp` | MCP stdio server; talks to the daemon over the control socket |
+| `mcp-config` | Print the command that registers the MCP server with Claude Code |
+| `status` / `doctor` | State snapshot and recent log / layer-by-layer diagnosis with fixes |
+| `setup` | First-run wizard (re-runnable) |
+| `login` | Log in to an Apple ID (no echo; two-factor and SMS supported) |
+| `sign` / `resign [--force]` | Sign and install WDA now / re-sign only if the profile is close to expiring |
+| `passcode set\|clear`, `unlock-reset` | Auto-unlock (off by default) |
+| `wda-bridge --port 8100` | Expose WDA on 127.0.0.1 for other tools — unauthenticated, stop it when done |
+| `notify-test` | Send one test notification per event type |
+
+## Configuration
+
+Everything is configured through environment variables; all of them are optional. See [.env.example](.env.example) for the full list. The common ones:
+
+| Variable | Meaning |
+|---|---|
+| `HTTP_PROXY`, `HTTPS_PROXY` | Proxy for Apple, anisette, Developer Disk Image and notification traffic |
+| `IPHONE_UDID` | Which phone to use when several are connected |
+| `BARK_KEY`, `BARK_SERVER`, `TG_BOT_TOKEN`, `TG_CHAT_ID` | Notifications |
+| `RESIGN_MIN_DAYS`, `RESIGN_CHECK_HOURS` | When to re-sign WebDriverAgent |
+| `ICTL_ANISETTE_URL` | Your own anisette server instead of the default third-party one |
+| `ICTL_DDI_URL`, `ICTL_DDI_DIR` | Where the Developer Disk Image comes from |
-## 文档
+## Security and privacy
-| 文档 | 内容 |
-|---|---|
-| [architecture.md](docs/architecture.md) | 架构图、单进程守护状态机、模块划分、数据和秘密目录 |
-| [capability-matrix.md](docs/capability-matrix.md) | toolkit 的每项能力在本项目里由哪个 crate 实现 |
-| [spike-plan.md](docs/spike-plan.md) / [spike-results.md](docs/spike-results.md) | 第 0 步真机验证 5 项的计划和结果(已完成,留作记录) |
-| [roadmap.md](docs/roadmap.md) | 分阶段计划、**完成情况**、必测的回归用例 |
-| [licensing.md](docs/licensing.md) | 许可证分析、不能分发的苹果文件 |
-| [decisions.md](docs/decisions.md) | 关键取舍记录 |
+Read [SECURITY.md](SECURITY.md) before deploying. In short:
-## 目录
+- The data directory holds your Apple ID session, the development signing key, pairing records and — only if you enable auto-unlock — the phone passcode in plain text. Back it up, and never commit or share it.
+- The container runs as root, because it needs the USB device nodes and must be able to restart `usbmuxd` after the phone is unplugged.
+- Apple ID logins use an anisette server. The default is a public third-party server; set `ICTL_ANISETTE_URL` to use your own.
+- Anyone who can reach the control socket, or a running `wda-bridge`, can control the phone.
-```
-crates/
- ictl-device/ 设备层:usbmuxd 发现、配对、隧道、开发者镜像(含下载)、HID(含媒体流)、截图、App
- ictl-wda/ WDA:启动 XCTest runner、直连设备端口的 HTTP 客户端、元素树解析
- ictl-protocol/ 控制接口的请求/响应类型和客户端(MCP、CLI 共用)
- ictl-sign/ Apple ID 登录、注册设备、描述文件、签名(修复 .xctest 漏签)、签后自检
- ictl-unlock/ 锁屏自动解锁(默认关闭)
- ictl-daemon/ 守护进程:状态机、usbmuxd 看护、重签调度、通知、控制接口服务端
- ictl-mcp/ MCP 服务(stdio),toolkit 的 13 个工具 + iphone_wait_for、iphone_batch
-apps/
- iphone-control/ 唯一的可执行程序(含隐藏的 debug 真机诊断)
-vendor/ Impactor 的 plume_core / plume_store / omnisette 与打过补丁的 apple-codesign(见 THIRD_PARTY.md)
-docker/ Dockerfile(编译 → debian:trixie-slim + usbmuxd)、cargo-about 许可证清单配置
-deploy/ 从源码运行时的 systemd 用户服务
-```
+## Disclaimer
-## 构建与测试
+This project is not affiliated with, endorsed by, or sponsored by Apple Inc. iPhone, iOS and Xcode are trademarks of Apple Inc.
-```bash
-docker run --rm -v "$PWD":/src -w /src rust:1-trixie sh -c \
- 'rustup component add clippy && cargo test --workspace && cargo clippy --workspace --all-targets -- -D warnings'
-```
+Use it only with devices and accounts you own or are authorized to control. Automating third-party apps may violate their terms of service, and Apple may limit or suspend developer accounts — consider a dedicated Apple ID. The software is provided "as is", without warranty of any kind (see [LICENSE](LICENSE)).
+
+Nothing here bypasses iOS security: trusting the computer, enabling Developer Mode, trusting the developer certificate and enabling UI automation all require the owner on the phone.
+
+## Documentation
+
+| Document | Contents |
+|---|---|
+| [docs/tools.md](docs/tools.md) | MCP tools and their parameters |
+| [docs/troubleshooting.md](docs/troubleshooting.md) | What each state means and how to fix common problems |
+| [SECURITY.md](SECURITY.md) | Threat model, hardening, reporting vulnerabilities |
+| [CONTRIBUTING.md](CONTRIBUTING.md) | Building, testing (with and without a phone), pull requests |
+| [CHANGELOG.md](CHANGELOG.md) | Release notes |
+| [docs/architecture.md](docs/architecture.md) | Architecture, daemon state machine, modules, data layout (Chinese) |
+| [docs/decisions.md](docs/decisions.md) | Key design decisions (Chinese) |
+| [docs/licensing.md](docs/licensing.md), [THIRD_PARTY.md](THIRD_PARTY.md) | License analysis and third-party components (Chinese) |
+| [docs/dev/](docs/dev/) | Development history: spike results, roadmap, regression cases (Chinese) |
+
+## Acknowledgements
+
+Built on [idevice](https://github.com/jkcoxson/idevice) (device protocols), [Impactor](https://github.com/claration/impactor) (Apple ID and signing), [apple-codesign](https://github.com/indygreg/apple-platform-rs), [WebDriverAgent](https://github.com/appium/WebDriverAgent) (on-device automation), [usbmuxd](https://github.com/libimobiledevice/usbmuxd) and the [Rust MCP SDK](https://github.com/modelcontextprotocol/rust-sdk).
+
+## License
-国内网络需要 `--network host` 和 `HTTP_PROXY`/`HTTPS_PROXY`。不需要 nightly;最低 Rust 1.88(由 rmcp 决定,CI 单独检查),开发和 CI 用 1.99.1。
-`vendor/` 不是 workspace 成员,不对它跑 clippy;它自带的编译警告属于上游。
+The code in this repository is [MIT](LICENSE). Vendored components keep their own licenses (MPL-2.0 and MIT); see [THIRD_PARTY.md](THIRD_PARTY.md). Apple files such as the Developer Disk Image are downloaded at runtime and never distributed.
diff --git a/README.zh-CN.md b/README.zh-CN.md
new file mode 100644
index 0000000..03b001f
--- /dev/null
+++ b/README.zh-CN.md
@@ -0,0 +1,177 @@
+# iphone-control
+
+[English](README.md) | **简体中文**
+
+[![CI](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml/badge.svg)](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml)
+[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
+
+在 Linux 上控制一台通过 USB 连接的真实 iPhone(不需要 Mac,不需要付费开发者账号),并把能力以 [MCP](https://modelcontextprotocol.io) 工具的形式交给 AI agent。用 Rust 写成,产物是一个二进制,外加系统的 `usbmuxd`。
+
+> **状态:早期版本(0.x)。** 下面的功能都在一台真机上完整跑通:iPhone 15 Pro Max,iOS 27.0.1。其他机型和 iOS 17 以上应该也能用,但没测过,欢迎反馈。
+
+## 能做什么
+
+- **给 agent 的工具**:截图(可放大某块区域)、列出屏幕上的元素、按坐标或按文字点击、滑动、长按、输入文字(支持中文)、硬件按键、启动/结束 App、打开链接、等某段文字出现、一次执行多步。任何操作都可以顺带返回操作后的界面,省一次往返。见 [docs/tools.md](docs/tools.md)。
+- **自己维持运行**:配对、挂载开发者镜像、用免费 Apple ID 给 WebDriverAgent 签名,并在 7 天描述文件过期前自动重签;WDA 挂了自动重启;拔插、手机重启后自动恢复。
+- **后备路线**:WDA 不可用时,点击、滑动、按键、截图仍可经 CoreDevice HID 完成。
+- **需要你时会通知**:重签失败、Apple ID 会话失效、手机重启后要输密码、手机离线时,经 Bark 或 Telegram 推送。
+- **可选的自动解锁**:默认关闭;开启前先读 [SECURITY.md](SECURITY.md)。
+- **不开端口**:WDA 经 usbmuxd 直连,本机不监听任何网络端口。
+
+```
+AI agent ──stdio──▶ iphone-control mcp ──unix socket──▶ iphone-control daemon ──usbmuxd/USB──▶ iPhone(WebDriverAgent)
+```
+
+一个常驻守护进程独占设备(隧道、HID 会话、WDA 会话常驻复用);每个 agent 会话是一个薄的 MCP 客户端。详见 [docs/architecture.md](docs/architecture.md)。
+
+## 需要什么
+
+- 一台有 USB 口的 Linux 主机(x86_64 或 arm64)。
+- Docker(Compose v2);不用 Docker 时需要 Rust 1.88 以上、C 编译器和 `usbmuxd`(见[从源码运行](#从源码运行不用-docker))。
+- iOS 17 以上的 iPhone 和数据线;开发者模式由 `setup` 引导打开。
+- 一个免费 Apple ID,建议专门注册一个(见[安全与隐私](#安全与隐私))。
+- 能访问苹果服务器、anisette 服务和 GitHub(首次使用时下载开发者镜像和 WebDriverAgent)。国内网络一般要在 `.env` 里配代理。
+
+## 快速开始(Docker)
+
+```bash
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cp .env.example .env # 可选:代理、通知、自动解锁
+docker compose up -d --build # 首次构建要编译 Rust,需要几分钟
+docker exec -it iphone-control iphone-control setup
+docker exec -it iphone-control iphone-control mcp-config # 打印注册 MCP 的命令
+```
+
+发布版本后可以不自己构建:在 `.env` 里设 `IMAGE=ghcr.io/derrors/iphone-control:latest`,然后 `docker compose pull && docker compose up -d --no-build`。
+
+`setup` 可以重复运行,依次是:
+
+1. **连接**:用数据线接好手机并解锁。
+2. **配对**:手机上点「信任」,输入锁屏密码。
+3. **开发者模式**:设置 → 隐私与安全性 → 开发者模式 → 打开 → 重新启动;重启解锁后在弹窗里确认。
+4. **登录 Apple ID**:密码和双重认证验证码只在这个终端里输入。
+5. **签名并安装 WebDriverAgent**:期间手机保持解锁。
+6. **启动 WebDriverAgent**:首次要在 设置 → 通用 → VPN 与设备管理 里信任你的 Apple ID;如果弹出「为 XCTest 输入 iPhone 密码」(Enable UI Automation),输入锁屏密码。
+
+容器不用 `privileged`:只开放 USB 字符设备(`device_cgroup_rules: "c 189:* rmw"`),`/dev/bus/usb` 绑定挂载。不要同时运行两份(或其他基于 usbmuxd 的工具)连同一部手机。
+
+## 接入 MCP 客户端
+
+Claude Code(容器部署时 `mcp-config` 打印的就是这条):
+
+```bash
+claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mcp
+```
+
+其他客户端(Claude Desktop、Cursor 等)在 JSON 配置里写同一条命令:
+
+```json
+{
+ "mcpServers": {
+ "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] }
+ }
+}
+```
+
+从源码运行时改为 `iphone-control --socket <路径> mcp`,具体命令用 `iphone-control mcp-config` 打印。
+
+## 从源码运行(不用 Docker)
+
+以 Debian/Ubuntu 为例:
+
+```bash
+sudo apt install build-essential git usbmuxd # usbmuxd 由 udev 在插上手机时拉起
+git clone https://github.com/Derrors/iphone-control && cd iphone-control
+cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control
+iphone-control daemon # 前台运行;常驻用下面的 systemd 用户服务
+iphone-control setup # 另开一个终端
+iphone-control mcp-config
+```
+
+常驻运行用 [deploy/iphone-control.service](deploy/iphone-control.service)(systemd 用户服务):
+
+```bash
+mkdir -p ~/.config/systemd/user ~/.config/iphone-control
+cp deploy/iphone-control.service ~/.config/systemd/user/
+cp .env.example ~/.config/iphone-control/env # CONTAINER_NAME、IMAGE、DATA_DIR 只给 compose 用
+systemctl --user daemon-reload && systemctl --user enable --now iphone-control
+loginctl enable-linger "$USER" # 不登录也随开机启动
+```
+
+| | 容器 | 从源码(普通用户) |
+|---|---|---|
+| 数据目录 | `./data`(容器内 `/var/lib/iphone-control`) | `~/.local/share/iphone-control` |
+| 控制接口 | 容器内 `/run/iphone-control/ctl.sock` | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` |
+| usbmuxd | 守护进程拉起并看护(容器里没有 udev) | 系统服务,守护进程不拉起 |
+| 配对记录 | 数据目录的 `lockdown/` | 系统的 `/var/lib/lockdown` |
+| 未签名的 WDA | 镜像自带 | 第一次签名前下载同一版本(核对 sha256) |
+| 配置 | `.env` | 环境变量,例如 systemd 的 `EnvironmentFile` |
+
+守护进程、命令行和 MCP 要用同一个用户运行;别的用户要用 `--socket`、`--data-dir`(或 `ICTL_SOCKET`、`ICTL_DATA_DIR`)指过去。以 root 运行时默认路径和容器里一样,守护进程会自己拉起 usbmuxd;宿主机已有 usbmuxd 服务时设 `ICTL_MANAGE_USBMUXD=0`。装了系统 usbmuxd 又要用回容器版时,先 `sudo systemctl mask usbmuxd`,否则两边会抢设备。
+
+## 命令
+
+| 命令 | 作用 |
+|---|---|
+| `daemon` | 常驻守护进程(容器入口) |
+| `mcp` | MCP stdio 服务,经控制接口调用守护进程 |
+| `mcp-config` | 打印把 MCP 注册到 Claude Code 的命令 |
+| `status` / `doctor` | 状态快照和最近日志 / 逐层诊断,每项失败都给出修复办法 |
+| `setup` | 首次安装向导(可重复运行) |
+| `login` | 登录 Apple ID(密码不回显,支持双重认证和短信) |
+| `sign` / `resign [--force]` | 立即签名安装 WDA / 描述文件快过期才重签 |
+| `passcode set\|clear`、`unlock-reset` | 自动解锁(默认关闭) |
+| `wda-bridge --port 8100` | 把 WDA 桥接到 127.0.0.1 给别的工具用:没有认证,用完就停 |
+| `notify-test` | 每类事件发一条测试通知 |
+
+## 配置
+
+全部通过环境变量配置,都可以不填。完整列表见 [.env.example](.env.example),常用的:
+
+| 变量 | 含义 |
+|---|---|
+| `HTTP_PROXY`、`HTTPS_PROXY` | 访问苹果、anisette、开发者镜像和推送通知时用的代理 |
+| `IPHONE_UDID` | 接了多台手机时指定用哪台 |
+| `BARK_KEY`、`BARK_SERVER`、`TG_BOT_TOKEN`、`TG_CHAT_ID` | 通知 |
+| `RESIGN_MIN_DAYS`、`RESIGN_CHECK_HOURS` | 什么时候重签 WebDriverAgent |
+| `ICTL_ANISETTE_URL` | 用自建 anisette 服务代替默认的第三方服务 |
+| `ICTL_DDI_URL`、`ICTL_DDI_DIR` | 开发者镜像从哪里来 |
+
+## 安全与隐私
+
+部署前请读 [SECURITY.md](SECURITY.md)。要点:
+
+- 数据目录里有 Apple ID 会话、开发签名私钥、配对记录;开启自动解锁时还有明文的锁屏密码。要备份,不要提交或分享。
+- 容器以 root 运行:要访问 USB 设备节点,拔插后还要能重启 `usbmuxd`。
+- 登录 Apple ID 要用 anisette 服务,默认是公共的第三方服务;可用 `ICTL_ANISETTE_URL` 换成自建服务。
+- 能访问控制接口(Unix socket)或正在运行的 `wda-bridge` 的人,都能操控手机。
+
+## 免责声明
+
+本项目与 Apple Inc. 没有任何关联,也未获其认可或赞助。iPhone、iOS、Xcode 是 Apple Inc. 的商标。
+
+只在你自己拥有或获得授权的设备和账号上使用。自动操作第三方 App 可能违反其服务条款;苹果可能限制或停用开发者账号,建议使用专门的 Apple ID。本软件按「原样」提供,不提供任何担保(见 [LICENSE](LICENSE))。
+
+本项目不绕过任何 iOS 安全机制:信任电脑、开启开发者模式、信任开发者证书、启用 UI 自动化都需要机主本人在手机上操作。
+
+## 文档
+
+| 文档 | 内容 |
+|---|---|
+| [docs/tools.md](docs/tools.md) | MCP 工具和参数(英文) |
+| [docs/troubleshooting.md](docs/troubleshooting.md) | 各状态的含义和常见问题的处理(英文,附中文状态原文) |
+| [SECURITY.md](SECURITY.md) | 威胁模型、加固建议、漏洞报告(英文) |
+| [CONTRIBUTING.md](CONTRIBUTING.md) | 构建、测试(有无手机两种)、提交 PR(英文,PR 和 issue 可以用中文) |
+| [CHANGELOG.md](CHANGELOG.md) | 版本记录 |
+| [docs/architecture.md](docs/architecture.md) | 架构、守护进程状态机、模块划分、数据目录 |
+| [docs/decisions.md](docs/decisions.md) | 关键取舍记录 |
+| [docs/licensing.md](docs/licensing.md)、[THIRD_PARTY.md](THIRD_PARTY.md) | 许可证分析、第三方组件 |
+| [docs/dev/](docs/dev/) | 开发过程:spike 结果、路线图、回归用例 |
+
+## 致谢
+
+基于 [idevice](https://github.com/jkcoxson/idevice)(设备协议)、[Impactor](https://github.com/claration/impactor)(Apple ID 与签名)、[apple-codesign](https://github.com/indygreg/apple-platform-rs)、[WebDriverAgent](https://github.com/appium/WebDriverAgent)(手机端自动化)、[usbmuxd](https://github.com/libimobiledevice/usbmuxd) 和 [Rust MCP SDK](https://github.com/modelcontextprotocol/rust-sdk)。
+
+## 许可证
+
+本仓库的代码使用 [MIT](LICENSE)。vendor 进来的组件保留各自的许可证(MPL-2.0 和 MIT),见 [THIRD_PARTY.md](THIRD_PARTY.md)。开发者镜像等苹果文件在运行时下载,从不分发。
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..620d11a
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,44 @@
+# Security
+
+## Reporting a vulnerability
+
+Please report vulnerabilities privately through GitHub: **[Report a vulnerability](https://github.com/Derrors/iphone-control/security/advisories/new)** (Security tab → *Report a vulnerability*). Do not open a public issue for security problems. Reports in English or Chinese are both fine.
+
+You can expect an acknowledgement within a week. Fixes go into the latest release; older versions are not patched while the project is at 0.x.
+
+## What this software has access to
+
+iphone-control is, by design, a remote control for a phone. Anyone who can talk to it can see the screen and do anything the phone's owner can do while it is unlocked. Treat the machine that runs it like the phone itself.
+
+| Asset | Where | Who can reach it |
+|---|---|---|
+| Phone control (taps, typing, screenshots, apps) | Control socket: `/run/iphone-control/ctl.sock` inside the container, `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` for a source install; mode 0600 | Root on the host; anyone who can `docker exec` into the container; the user running a source install |
+| WebDriverAgent (no authentication) | On the phone, reached through usbmuxd; nothing listens on the network unless you run `wda-bridge` | With `wda-bridge`: **every local user** on the host, because the container uses host networking. Browsers are blocked by a Host-header check (DNS rebinding), other local processes are not |
+| Apple ID session tokens, development signing key and certificate | `account/` in the data directory (0700, key 0600) | Whoever can read the data directory. The Apple ID password itself is never stored |
+| Pairing records | `lockdown/` in the data directory (container) or the system's `/var/lib/lockdown` | Root on the host. A pairing record lets its holder talk to the phone over USB without another *Trust* prompt |
+| Lock-screen passcode | `secrets/passcode` in the data directory (0600), **plain text**, only if you ran `passcode set` | Whoever can read the data directory |
+| Notification credentials (Bark key, Telegram token) | `.env` or the systemd environment file | Whoever can read that file |
+
+The data directory is `./data` next to `compose.yaml` for the container (root-owned, mode 0700) and `~/.local/share/iphone-control` for a source install.
+
+## Design choices that limit exposure
+
+- No network listener by default. WebDriverAgent is reached through usbmuxd; `wda-bridge` only binds 127.0.0.1, only forwards requests whose Host header is a loopback name, and is meant to be stopped after use.
+- The control socket is a Unix socket with mode 0600, not TCP.
+- The container is not `privileged`: it is only allowed USB character devices (major 189), and the tunnel to the phone uses a user-space TCP stack, so no network interface or routing changes on the host.
+- Auto-unlock is off by default. When enabled, it stops for good after a single wrong attempt (it writes a stop marker before entering the second digit) and sends a notification; it never retries a passcode that might be wrong. It does not work before the first unlock after a reboot (BFU) — that always needs a person.
+- Dependencies are pinned to exact versions, `Cargo.lock` is committed, base images are pinned by digest, and the WebDriverAgent download is checked against a sha256. CI runs gitleaks on every push.
+
+## Known risks and recommendations
+
+- **The container runs as root.** It needs read-write access to the USB device nodes and must restart `usbmuxd` after the phone is re-plugged (the container has no udev). Running it unprivileged would need host udev rules and is not supported yet. Keep the host itself locked down.
+- **Third-party anisette server.** Apple ID logins need "anisette" data that normally only Apple hardware produces. By default it comes from a public server (`https://mac-ani.jkcoxson.com`, the default of the Impactor/omnisette libraries). The server does not receive your Apple ID password, but your logins depend on an identity it provisions, and it sees when you log in. Set `ICTL_ANISETTE_URL` to an [anisette-v3 server](https://github.com/Dadoum/anisette-v3-server) you run yourself to avoid this.
+- **Use a dedicated Apple ID.** The session token and signing key on disk are enough to manage that account's development certificates and devices. A separate free account limits the damage if the host is compromised and keeps your main account clear of developer-account restrictions.
+- **Auto-unlock stores your passcode in plain text.** Anyone with root on the host, or access to backups of the data directory, can read it — and the passcode is also what protects the phone's data and Apple ID. Only enable it on a host you fully control, and prefer leaving Auto-Lock off on a phone dedicated to automation.
+- **Agents act with your hands.** An agent with these tools can send messages, make purchases and change settings. The MCP server tells agents to ask before paying, deleting, sending messages or changing account or privacy settings, but that is an instruction, not an enforcement mechanism. Use a phone and accounts you are comfortable automating.
+- **Back up the data directory securely**, and never commit it. `.gitignore` and `.dockerignore` exclude `data/`, `.env` and key material, so they don't end up in git or in image layers.
+
+## Developer Disk Image and WebDriverAgent sources
+
+- The Developer Disk Image is downloaded at runtime from a community-maintained mirror (the same source pymobiledevice3 uses) unless you set `ICTL_DDI_URL` or `ICTL_DDI_DIR`. The phone verifies Apple's signature through personalization (TSS), so a tampered image will not mount.
+- The unsigned WebDriverAgent comes from Appium's official release (pinned version, sha256-checked) and is signed locally with your Apple ID.
diff --git a/apps/iphone-control/Cargo.toml b/apps/iphone-control/Cargo.toml
index 8a2c7b9..e8ef47e 100644
--- a/apps/iphone-control/Cargo.toml
+++ b/apps/iphone-control/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "iphone-control 命令行入口"
[dependencies]
diff --git a/apps/iphone-control/src/debug.rs b/apps/iphone-control/src/debug.rs
index b593681..78503c0 100644
--- a/apps/iphone-control/src/debug.rs
+++ b/apps/iphone-control/src/debug.rs
@@ -1,4 +1,4 @@
-//! `iphone-control debug …`:真机诊断(原第 0 步 spike,结果见 docs/spike-results.md)。直接调用设备层和 WDA 客户端,
+//! `iphone-control debug …`:真机诊断(原第 0 步 spike,结果见 docs/dev/spike-results.md)。直接调用设备层和 WDA 客户端,
//! 不经守护进程。`wda`、`e2e` 会启动 XCTest、`hid` 会开屏幕媒体流,和守护进程同时跑会互相干扰:
//! 先停掉守护进程(例如在另一个只跑 usbmuxd 的容器里运行)。
diff --git a/crates/ictl-daemon/Cargo.toml b/crates/ictl-daemon/Cargo.toml
index d55c408..f168160 100644
--- a/crates/ictl-daemon/Cargo.toml
+++ b/crates/ictl-daemon/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "守护进程:状态机、usbmuxd 看护、重签、通知、控制接口"
[dependencies]
diff --git a/crates/ictl-device/Cargo.toml b/crates/ictl-device/Cargo.toml
index 3372e16..b089ff5 100644
--- a/crates/ictl-device/Cargo.toml
+++ b/crates/ictl-device/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "设备层:发现、配对、隧道、开发者镜像、HID、截图、App"
[dependencies]
diff --git a/crates/ictl-mcp/Cargo.toml b/crates/ictl-mcp/Cargo.toml
index fae706d..01471d8 100644
--- a/crates/ictl-mcp/Cargo.toml
+++ b/crates/ictl-mcp/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "MCP stdio 服务(13 个 iphone_* 工具)"
[dependencies]
diff --git a/crates/ictl-protocol/Cargo.toml b/crates/ictl-protocol/Cargo.toml
index bbcf430..c743168 100644
--- a/crates/ictl-protocol/Cargo.toml
+++ b/crates/ictl-protocol/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "守护进程控制接口的请求/响应类型和客户端(MCP、CLI 共用,不依赖设备栈)"
[dependencies]
diff --git a/crates/ictl-sign/Cargo.toml b/crates/ictl-sign/Cargo.toml
index 1af2e1c..93a317b 100644
--- a/crates/ictl-sign/Cargo.toml
+++ b/crates/ictl-sign/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "Apple ID、描述文件、签名(含 .xctest)"
[dependencies]
diff --git a/crates/ictl-unlock/Cargo.toml b/crates/ictl-unlock/Cargo.toml
index d109060..8f0e9ba 100644
--- a/crates/ictl-unlock/Cargo.toml
+++ b/crates/ictl-unlock/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "锁屏自动解锁(默认关闭)"
[dependencies]
diff --git a/crates/ictl-unlock/src/lib.rs b/crates/ictl-unlock/src/lib.rs
index 00e4123..bc96498 100644
--- a/crates/ictl-unlock/src/lib.rs
+++ b/crates/ictl-unlock/src/lib.rs
@@ -1,6 +1,6 @@
//! 锁屏自动解锁(默认关闭,需显式配置密码文件)。
//!
-//! 规则全部来自 toolkit 实测(docs/capability-matrix.md §5):
+//! 规则全部来自 toolkit 实测(docs/dev/capability-matrix.md §5):
//! 1. 先读 `/wda/locked`,没锁直接返回;WDA 不可用也直接返回(交给后面的调用去报错)
//! 2. 每轮固定:按 Home → 等 1.0s → 底部上滑 → 等 1.5s。不以「树里有键盘」判断:键盘收起时按键元素也常驻树中
//! 3. 读密码栏「共N位数,已输入M位」:总位数和配置不符一位都不输;有残留输入先用右下角删除键逐位删到 0
diff --git a/crates/ictl-wda/Cargo.toml b/crates/ictl-wda/Cargo.toml
index f1075d0..66fd3ca 100644
--- a/crates/ictl-wda/Cargo.toml
+++ b/crates/ictl-wda/Cargo.toml
@@ -5,6 +5,8 @@ edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
+repository.workspace = true
+homepage.workspace = true
description = "WDA:启动 XCTest runner、HTTP 客户端、元素树解析"
[dependencies]
diff --git a/crates/ictl-wda/src/elements.rs b/crates/ictl-wda/src/elements.rs
index bfb876a..32e501e 100644
--- a/crates/ictl-wda/src/elements.rs
+++ b/crates/ictl-wda/src/elements.rs
@@ -710,7 +710,7 @@ mod tests {
#[test]
fn widget_contents_are_moved_to_screen_coordinates() {
let els = parse(HOME_WIDGETS_IOS27, SCREEN);
- let city = els.iter().find(|e| e.label == "上海市").unwrap();
+ let city = els.iter().find(|e| e.label == "示例市").unwrap();
// 小组件内容区在 (29,84),文字在其中 (19,19) 起 52x13
assert_eq!(city.center, (74, 110));
// 主屏图标本来就是屏幕坐标,不受影响
diff --git a/crates/ictl-wda/tests/fixtures/home-widgets-ios27.xml b/crates/ictl-wda/tests/fixtures/home-widgets-ios27.xml
index 999a7b9..79e465d 100644
--- a/crates/ictl-wda/tests/fixtures/home-widgets-ios27.xml
+++ b/crates/ictl-wda/tests/fixtures/home-widgets-ios27.xml
@@ -28,8 +28,8 @@
<XCUIElementTypeOther type="XCUIElementTypeOther" x="0" y="0" width="175" height="175">
<XCUIElementTypeOther type="XCUIElementTypeOther" x="0" y="0" width="175" height="175">
<XCUIElementTypeOther type="XCUIElementTypeOther" x="19" y="19" width="135" height="137">
- <XCUIElementTypeOther type="XCUIElementTypeOther" name="上海市,20°摄氏度,多云,明天气温降低,最高气温21°,最高气温26°摄氏度,最低气温17°摄氏度" label="上海市,20°摄氏度,多云,明天气温降低,最高气温21°,最高气温26°摄氏度,最低气温17°摄氏度" x="19" y="19" width="135" height="137">
- <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="上海市" name="上海市" label="上海市" x="19" y="19" width="52" height="13"/>
+ <XCUIElementTypeOther type="XCUIElementTypeOther" name="示例市,20°摄氏度,多云,明天气温降低,最高气温21°,最高气温26°摄氏度,最低气温17°摄氏度" label="示例市,20°摄氏度,多云,明天气温降低,最高气温21°,最高气温26°摄氏度,最低气温17°摄氏度" x="19" y="19" width="135" height="137">
+ <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="示例市" name="示例市" label="示例市" x="19" y="19" width="52" height="13"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="20°" name="20°" label="20°" x="19" y="30" width="69" height="54"/>
<XCUIElementTypeImage type="XCUIElementTypeImage" name="温度计" label="温度计" x="19" y="96" width="14" height="23"/>
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="明天气温降低,最高气温21°" name="明天气温降低,最高气温21°" label="明天气温降低,最高气温21°" x="19" y="123" width="135" height="33"/>
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 0af5a2c..824dffe 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -29,7 +29,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
-o /THIRD_PARTY_LICENSES.html
# ---- WebDriverAgent:Appium 官方构建的未签名真机包,重新打成 IPA ----
-# 计划改为本项目在 macOS CI 上自己编译(docs/roadmap.md 阶段 7)
+# 计划改为本项目在 macOS CI 上自己编译(docs/dev/roadmap.md 阶段 7)
FROM ${DEBIAN_IMAGE} AS wda
ARG WDA_VERSION=v16.15.3
ARG WDA_SHA256=2176793538d902f6b1e61291e9997f68d306541f222ea715d256a7c6ce9d4fc5
@@ -66,6 +66,7 @@ ENV ICTL_DATA_DIR=/var/lib/iphone-control
ENV MALLOC_ARENA_MAX=2
LABEL org.opencontainers.image.title="iphone-control" \
org.opencontainers.image.description="Drive a real iPhone from Linux: WebDriverAgent + CoreDevice HID + MCP, single Rust binary" \
- org.opencontainers.image.licenses="MIT AND MPL-2.0"
+ org.opencontainers.image.licenses="MIT AND MPL-2.0" \
+ org.opencontainers.image.source="https://github.com/Derrors/iphone-control"
ENTRYPOINT ["iphone-control"]
CMD ["daemon"]
diff --git a/docs/decisions.md b/docs/decisions.md
index 38e5fa3..aa9c723 100644
--- a/docs/decisions.md
+++ b/docs/decisions.md
@@ -7,7 +7,7 @@
- **决定**:设备通讯全部基于 `idevice`。版本用 `[patch.crates-io]` 锁在上游 master 的 git 提交 `89702099`(0.1.68 发版代码的 cryptexd install 会挂住,修复已在 master、未发版);发版后换回 crates.io。
- **理由**:它已覆盖我们需要的全部能力:usbmuxd、lockdown、CoreDeviceProxy 用户态隧道、RSD、cryptexd 个性化镜像安装、universalhidservice/indigo HID、screencaptureservice、XCTest 启动 WDA、WDA 客户端;MIT;StikDebug、CrossCode 等在生产中使用;Impactor 也依赖它,和签名部分同源。
- **代价**:0.2.0 之前每个小版本都可能有破坏性变更;主要一人维护;`tss` 自述部分支持、TCP 栈自述 "naive"。
-- **重新评估**:spike 第 4、5 项不过时(已全部通过,见 [spike-results](spike-results.md))。
+- **重新评估**:spike 第 4、5 项不过时(已全部通过,见 [spike-results](dev/spike-results.md))。
## D2:守护进程独占设备,MCP 是薄客户端
@@ -48,7 +48,7 @@
## D8:自动解锁默认关闭
- **决定**:需要显式开启并配置密码文件。
-- **理由**:存储锁屏密码意味着能访问主机的人就能解锁手机;输错累计还可能触发设备抹除。保护规则见 capability-matrix §5。
+- **理由**:存储锁屏密码意味着能访问主机的人就能解锁手机;输错累计还可能触发设备抹除。保护规则见 [capability-matrix §5](dev/capability-matrix.md)。
## D9:所有依赖锁定精确版本
diff --git a/docs/capability-matrix.md b/docs/dev/capability-matrix.md
similarity index 100%
rename from docs/capability-matrix.md
rename to docs/dev/capability-matrix.md
diff --git a/docs/roadmap.md b/docs/dev/roadmap.md
similarity index 96%
rename from docs/roadmap.md
rename to docs/dev/roadmap.md
index 5d6eaa3..bd404a3 100644
--- a/docs/roadmap.md
+++ b/docs/dev/roadmap.md
@@ -15,7 +15,7 @@
| 4 签名与重签 | vendor plume_core/plume_store/omnisette/apple-codesign(plume_utils 未 vendor,bundle 逻辑改写进 `ictl-sign`);登录(2FA、短信)、注册设备、App ID、描述文件、深度优先签名(XCTest 无 entitlements)、签后自检、定期重签(每 6 小时检查)、每日会话验证。真机已验证:登录(2FA)→ 签名 → 安装 → WDA 启动(XCTest 不带 entitlements 可以) | 强制重签后 WDA 自动恢复;会话失效通知;修复提交 Impactor 上游未做 |
| 5 通知 | Bark、Telegram,事件去重(重签/会话失效 20 小时冷却);`iphone-control notify-test` 每类事件各发一条。Bark 实测 7 类全部收到;守护进程实际触发的「需要输入密码」「已恢复」也已在手机重启测试中走通 | Telegram 未实测(没有配置) |
| 6 自动解锁 | 规则全部实现,用假锁屏验证(键盘常驻树中、首位不生效重来、中间位被吞即停、输错一次即停用、残留输入用删除键清)。真机 6 种场景各 5 次全部成功、全程无输错:锁屏后 0 秒 15.3~16.0 秒(含有意等的 3 秒)、3/30/70 秒约 12.3 秒、键盘留 2 位残留 13.8~14.6 秒、自然自动锁屏(30 秒)11.8~12.4 秒;配置错误密码只输错一次即停用并推送,恢复密码 + unlock-reset 后正常 | 无 |
-| 7 打包 | 多阶段 Dockerfile(单二进制 + Debian usbmuxd;构建缓存挂载,首次构建约 2 分钟;release 二进制 strip)、镜像带 cargo-about 生成的第三方许可证清单(`docker/about.toml` 白名单以外的许可证让构建失败)、compose(去掉 `privileged`:`/dev/bus/usb` 绑定挂载 + `device_cgroup_rules: "c 189:* rmw"`,`init: true`,`stop_grace_period: 30s`)、.env.example、setup/doctor、GitHub Actions(fmt/clippy/test 锁 1.99.1、MSRV 1.88 检查、gitleaks、镜像构建用 GHA 缓存);从源码运行(普通用户默认 XDG 数据目录和控制接口、用系统的 usbmuxd 服务、第一次签名前下载并转换未签名 WDA、`mcp-config` 直接调用二进制、`deploy/iphone-control.service` 用户服务) | 从源码运行已真机验证(2026-11-01,Rust 1.88 在 Debian 12 编译,普通用户运行:就绪、doctor、MCP 截图/按键/元素、WDA 下载转换后与镜像里的包逐项一致、systemd 用户服务启停;Debian 12 的系统 usbmuxd:udev 插线拉起、经它配对、拔线后 usbmuxd 自行退出且守护进程判为离线、插回约 10 秒就绪);新 compose 设置下的 USB 拔插已真机复测(拔线后离线、插回 sysfs 兜底重启 usbmuxd,约 50 秒内就绪);macOS CI 编译 WDA、多架构镜像、SBOM、镜像发布未做;数据目录归属(PUID/PGID)未做,容器内以 root 运行 |
+| 7 打包 | 多阶段 Dockerfile(单二进制 + Debian usbmuxd;构建缓存挂载,首次构建约 2 分钟;release 二进制 strip)、镜像带 cargo-about 生成的第三方许可证清单(`docker/about.toml` 白名单以外的许可证让构建失败)、compose(去掉 `privileged`:`/dev/bus/usb` 绑定挂载 + `device_cgroup_rules: "c 189:* rmw"`,`init: true`,`stop_grace_period: 30s`)、.env.example、setup/doctor、GitHub Actions(fmt/clippy/test 锁 1.99.1、MSRV 1.88 检查、gitleaks、镜像构建用 GHA 缓存);从源码运行(普通用户默认 XDG 数据目录和控制接口、用系统的 usbmuxd 服务、第一次签名前下载并转换未签名 WDA、`mcp-config` 直接调用二进制、`deploy/iphone-control.service` 用户服务) | 从源码运行已真机验证(2026-11-01,Rust 1.88 在 Debian 12 编译,普通用户运行:就绪、doctor、MCP 截图/按键/元素、WDA 下载转换后与镜像里的包逐项一致、systemd 用户服务启停;Debian 12 的系统 usbmuxd:udev 插线拉起、经它配对、拔线后 usbmuxd 自行退出且守护进程判为离线、插回约 10 秒就绪);新 compose 设置下的 USB 拔插已真机复测(拔线后离线、插回 sysfs 兜底重启 usbmuxd,约 50 秒内就绪)。发布流水线已写(`.github/workflows/release.yml`:推 v* tag 时在原生 runner 上构建 amd64/arm64 镜像推到 ghcr,附 SBOM 和来源证明;在 Ubuntu 22.04 上编译两种架构的二进制附在 Release 上),还没在 GitHub 上实际跑过。面向用户的文档已补(英文 README + 中文版、SECURITY、CONTRIBUTING、CHANGELOG、docs/tools.md、docs/troubleshooting.md、issue/PR 模板、Dependabot)。未做:macOS CI 编译 WDA;容器非 root(要宿主机 udev 规则,拔插后还要能重启 usbmuxd,暂不做,原因写在 SECURITY.md) |
已知简化:
- `iphone_status` 在 toolkit 的输出后多一行「守护进程: …」。
diff --git a/docs/spike-plan.md b/docs/dev/spike-plan.md
similarity index 100%
rename from docs/spike-plan.md
rename to docs/dev/spike-plan.md
diff --git a/docs/spike-results.md b/docs/dev/spike-results.md
similarity index 100%
rename from docs/spike-results.md
rename to docs/dev/spike-results.md
diff --git a/docs/tools.md b/docs/tools.md
new file mode 100644
index 0000000..1305984
--- /dev/null
+++ b/docs/tools.md
@@ -0,0 +1,69 @@
+# MCP tools
+
+The MCP server (`iphone-control mcp`) exposes 15 tools. The tool descriptions the agent sees, and every result text, are in Simplified Chinese; this page is the English reference. The definitions live in [`crates/ictl-mcp/src/lib.rs`](../crates/ictl-mcp/src/lib.rs).
+
+Coordinates are in **points**, the same unit as the pixels of a full-screen `iphone_screenshot` (for example 430×932 on an iPhone 15 Pro Max), so an agent can read a position off a screenshot and tap it directly.
+
+## Looking at the screen
+
+| Tool | Parameters | Notes |
+|---|---|---|
+| `iphone_status` | — | WDA ready, locked or not, foreground app, screen size, daemon state |
+| `iphone_screenshot` | `x`, `y`, `width`, `height` (all optional, points) | Full screen scaled to points. With a region: cropped from the full-resolution capture and enlarged; the result says the zoom factor and how to convert back to screen points |
+| `iphone_list_elements` | `filter` (default `""`), `limit` (default 150) | Elements that carry text: type, label, id, value, center point and size. `filter` matches type, label, name or value, case-insensitive (for example `SearchField`). Visibility is judged by position, so something hidden behind a dialog can still be listed |
+| `iphone_wait_for` | `text`, `timeout` (seconds, default 5, max 30) | Returns as soon as an element containing `text` appears; text typed into input fields does not count. Use this instead of polling with screenshots |
+
+## Acting
+
+| Tool | Parameters | Notes |
+|---|---|---|
+| `iphone_tap` | `x`, `y` | |
+| `iphone_tap_element` | `text`, `index` (default 0) | Exact label or name first, then substring. If the element's center is covered (floating toolbar, keyboard, overlay), taps an uncovered part of it; if it is fully covered, does not tap and says so |
+| `iphone_long_press` | `x`, `y`, `seconds` (default 1) | |
+| `iphone_swipe` | `from_x`, `from_y`, `to_x`, `to_y`, `seconds` (default 0.3) | Returns after the list has stopped scrolling (up to 2.5 s). Swipe up (`from_y` > `to_y`) to see content further down |
+| `iphone_type_text` | `text`, `submit` (default false) | Types into the focused field (Chinese supported); fails if no keyboard is shown. Reads the field back afterwards: dropped trailing characters are typed again; if the field still doesn't match, it reports an error and does not press Return |
+| `iphone_press_button` | `button`: `home`, `volume_up`, `volume_down`, `lock` | `home` refuses to act while a system alert is on screen (it would have no effect) |
+| `iphone_launch_app` | `app` (bundle id or display name, e.g. `设置`) | Waits until the app is in the foreground; returns early and says so if a system alert is blocking it |
+| `iphone_terminate_app` | `app` | |
+| `iphone_open_url` | `url` | Web pages open in Safari; URL schemes open their app |
+| `iphone_list_apps` | `include_system` (default false) | Name and bundle id of installed apps |
+
+When auto-unlock is configured, action tools unlock the phone first.
+
+### Returning the screen after an action: `then`
+
+Every action tool accepts:
+
+| Parameter | Meaning |
+|---|---|
+| `then` | `none` (default), `elements` (up to 80 elements) or `screenshot` |
+| `then_filter` | With `elements`: only elements matching this text or type |
+| `then_region` | With `screenshot`: `[x, y, width, height]` to return only an enlarged region (for example a game board) |
+| `then_settle` | Seconds to wait for the screen to settle first (default 1.5, max 10) |
+
+"Settled" means two consecutive element trees match and no loading spinner is shown. On screens with few elements (games, maps) it compares screenshots instead. The result says how long it waited, whether something is probably still loading, and whether a dialog is in the way.
+
+Without `then`, the result still warns when a system alert covers the screen, because taps and swipes would land on the alert.
+
+## Batches: `iphone_batch`
+
+`steps` is a list of up to 20 objects, each `{"tool": <name>, ...parameters}`. Allowed tools: `iphone_tap`, `iphone_tap_element`, `iphone_long_press`, `iphone_swipe`, `iphone_type_text`, `iphone_press_button`, `iphone_launch_app`, `iphone_terminate_app`, `iphone_open_url`, `iphone_wait_for`, and `{"tool": "wait", "seconds": n}` (n ≤ 5).
+
+Steps run in order. The batch stops at the first error or the first `iphone_tap_element` that finds nothing, and reports which step it stopped at. `then` applies once, after the last step. `reuse_elements: true` lets `iphone_tap_element` reuse the element tree from the last 10 seconds; use it only when the steps don't change the layout (for example pressing keys on the same keypad).
+
+```json
+{
+ "steps": [
+ {"tool": "iphone_launch_app", "app": "设置"},
+ {"tool": "iphone_tap_element", "text": "通用"},
+ {"tool": "iphone_tap_element", "text": "关于本机"}
+ ],
+ "then": "screenshot"
+}
+```
+
+## Tips for agents
+
+- Prefer `iphone_tap_element` over coordinates when the element has text.
+- Games, maps and video have no useful element tree: work from screenshots and zoom into small icons with a region.
+- Ask the user before anything that pays, deletes, sends a message, or changes account or privacy settings (the server's instructions say the same).
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
new file mode 100644
index 0000000..5c04afd
--- /dev/null
+++ b/docs/troubleshooting.md
@@ -0,0 +1,67 @@
+# Troubleshooting
+
+Start with these two commands (prefix them with `docker exec -it iphone-control` for the container):
+
+```bash
+iphone-control status # current state, signing info, last log lines
+iphone-control doctor # checks each layer in order and prints a fix for every failure
+```
+
+The program's own messages are in Simplified Chinese; the Chinese text is quoted below so you can match it.
+
+## States
+
+`status` shows one of these on its first line. The daemon re-checks every 10 seconds and moves on by itself once the cause is fixed.
+
+| State (Chinese text) | Meaning | What to do |
+|---|---|---|
+| 手机未连接 | usbmuxd sees no phone | Check the cable and unlock the phone. Container: make sure no host `usbmuxd` is running (`sudo systemctl mask usbmuxd`). See [Phone not detected](#phone-not-detected) |
+| 未配对 | No pairing record | Run `setup` and tap *Trust* on the phone |
+| 开发者模式未打开 | Developer Mode is off | *Settings → Privacy & Security → Developer Mode*. The toggle only appears after the phone has been seen by a developer tool; running `setup` takes care of that |
+| 手机锁屏,隧道建不起来 | The phone has not been unlocked since it restarted (BFU) | Unlock it once by hand. Auto-unlock cannot do this step |
+| WDA 还没签名安装 | WebDriverAgent is not installed | Run `sign` (or `setup`) |
+| 正在启动 WDA | Starting WebDriverAgent (up to about 2 minutes) | Wait. Tools that only need coordinates (tap, swipe, screenshot, buttons) already work through the HID fallback |
+| WDA 卡在手机上的「Enable UI Automation」密码框 | The phone is showing *Enter iPhone passcode for "XCTest"* | Enter the passcode on the phone. This happens after a reboot, and sometimes after the daemon is restarted several times in a row. The daemon retries every 60 seconds and notifies you once |
+| WDA 启动失败,稍后重试:… | WebDriverAgent failed for another reason | Read the error after the colon and run `doctor`. Retries back off up to 5 minutes |
+| 就绪 | Everything works | — |
+
+## Phone not detected
+
+- **Container, after unplugging:** the container has no udev, so the daemon notices the phone through sysfs and restarts its own usbmuxd; recovery takes up to about a minute.
+- **Two usbmuxd instances:** a host `usbmuxd` (installed by many distributions, started by udev on plug-in) takes the phone away from the container. Mask it with `sudo systemctl mask usbmuxd`, or, for a source install, use the system one and don't run the container.
+- **Another tool holds the phone:** Xcode-less tools such as go-ios or pymobiledevice3 running at the same time can conflict. Stop them.
+- **Cable:** some cables only charge. If `lsusb` doesn't show an Apple device (vendor `05ac`), try another cable or port.
+
+## WebDriverAgent won't start
+
+- **"Untrusted developer":** after the first install, trust your Apple ID under *Settings → General → VPN & Device Management* (needs internet on the phone).
+- **Expired signature:** free provisioning profiles last 7 days. The daemon re-signs when fewer than `RESIGN_MIN_DAYS` (default 2) remain. `status` shows the remaining time; `resign --force` re-signs now.
+- **Apple ID session expired:** you get a notification, and `resign` fails with a login error. Run `login` again.
+- **Developer Disk Image:** `doctor` reports whether it is mounted. Downloading needs access to GitHub; behind a firewall set `HTTP_PROXY`/`HTTPS_PROXY`, or point `ICTL_DDI_DIR` at an image extracted from Xcode.
+
+## Login and signing
+
+- **Two-factor code:** `login` and `setup` ask for it in the terminal. Run them with `-it` (`docker exec -it …`), otherwise there is no terminal to type into.
+- **Anisette errors:** the default public anisette server may be slow or down. Retry later, or run your own and set `ICTL_ANISETTE_URL` (see [SECURITY.md](../SECURITY.md)).
+- **Account limits:** free accounts can only have a limited number of app IDs and devices. Use a dedicated Apple ID if your main one is already used with other sideloading tools.
+
+## MCP
+
+- **The client can't connect** ("connection closed", "failed to reconnect"): restarting the container ends the MCP process; reconnect from the client (in Claude Code, run `/mcp`). Check the registered command with `iphone-control mcp-config`.
+- **"守护进程正忙…已放弃执行":** an action waited more than 30 seconds for the device, so it was dropped instead of tapping a screen that has changed. Take a screenshot and try again.
+- **Taps do nothing:** a system alert may be covering the screen; the tool result says so (「屏幕上有系统弹窗…」). Dismiss it with `iphone_tap_element`. Taps right after launching an app are delayed until the launch animation is over.
+- **Typed text is incomplete:** `iphone_type_text` reads the field back and types missing characters again. If it still reports a mismatch, the app is rewriting the field while you type; type shorter pieces.
+
+## The phone shows a "paired computer" icon and won't auto-lock
+
+The HID fallback keeps a screen-mirroring session open while it is in use (the Dynamic Island shows a computer icon) and closes it after 30 seconds of inactivity. If the icon stays, restart the daemon; stopping it closes the session.
+
+## Logs
+
+- Container: `docker logs iphone-control`, and the event log at `/var/lib/iphone-control/logs/daemon.log` inside the container (`./data/logs/` on the host).
+- Source install: `journalctl --user -u iphone-control` and `~/.local/share/iphone-control/logs/`.
+- More detail: set `ICTL_LOG=info,ictl_wda::http=debug` to log every WebDriverAgent request with its duration. Remove it afterwards; it is verbose.
+
+## Reporting a bug
+
+Please include the phone model, iOS version, how you run it (container or source), and the output of `iphone-control doctor`. Remove anything private (UDID, Apple ID, notification keys) first.
diff --git a/tests/device/requirements.txt b/tests/device/requirements.txt
new file mode 100644
index 0000000..b6deb10
--- /dev/null
+++ b/tests/device/requirements.txt
@@ -0,0 +1 @@
+mcp==2.3.0
diff --git a/tests/device/run.py b/tests/device/run.py
new file mode 100644
index 0000000..30274b3
--- /dev/null
+++ b/tests/device/run.py
@@ -0,0 +1,77 @@
+"""Real-device regression runner: start the MCP server over stdio, call tools in order, print each
+result with its wall time, and save screenshots.
+
+ pip install -r tests/device/requirements.txt
+ python tests/device/run.py # default steps (harmless: Home, Clock tabs, Spotlight search)
+ python tests/device/run.py '[["iphone_status", {}], ["sleep", 1], ["iphone_screenshot", {}]]'
+
+The MCP server command comes from MCP_CMD (default: `docker exec -i iphone-control iphone-control mcp`;
+for a source install use e.g. `iphone-control mcp`). Screenshots go to SHOTS_DIR (default: ./shots).
+A step `["sleep", seconds]` waits without calling a tool. Exit code is 1 if any tool returned an error.
+"""
+
+import asyncio
+import base64
+import json
+import os
+import shlex
+import sys
+import time
+
+from mcp import ClientSession
+from mcp.client.stdio import StdioServerParameters, stdio_client
+
+# Harmless by design: no messages, purchases, deletions or settings changes.
+DEFAULT_STEPS = [
+ ["iphone_status", {}],
+ ["iphone_tap_element", {"text": "不存在的按钮xyz"}], # must report "not found", not tap anything
+ ["iphone_press_button", {"button": "home"}],
+ ["iphone_launch_app", {"app": "时钟"}],
+ ["iphone_list_elements", {"limit": 12}],
+ ["iphone_tap_element", {"text": "秒表", "then": "elements", "then_filter": "Button"}],
+ ["iphone_screenshot", {}],
+ ["iphone_screenshot", {"x": 0, "y": 0, "width": 430, "height": 60}],
+ ["iphone_press_button", {"button": "home"}],
+ ["iphone_swipe", {"from_x": 215, "from_y": 400, "to_x": 215, "to_y": 700}],
+ ["iphone_type_text", {"text": "设置"}],
+ ["iphone_wait_for", {"text": "设置", "timeout": 5}],
+ ["iphone_screenshot", {}],
+ ["iphone_press_button", {"button": "home"}],
+]
+
+
+async def main() -> int:
+ steps = json.loads(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_STEPS
+ cmd = shlex.split(os.environ.get("MCP_CMD", "docker exec -i iphone-control iphone-control mcp"))
+ shots = os.environ.get("SHOTS_DIR", "shots")
+ os.makedirs(shots, exist_ok=True)
+ failed = 0
+ params = StdioServerParameters(command=cmd[0], args=cmd[1:])
+ async with stdio_client(params) as (r, w), ClientSession(r, w) as session:
+ await session.initialize()
+ n = 0
+ for name, args in steps:
+ if name == "sleep":
+ await asyncio.sleep(float(args))
+ continue
+ t = time.time()
+ res = await session.call_tool(name, args)
+ dt = time.time() - t
+ out = []
+ for c in res.content:
+ if c.type == "image":
+ n += 1
+ path = os.path.join(shots, f"shot{n}.jpg")
+ with open(path, "wb") as f:
+ f.write(base64.b64decode(c.data))
+ out.append(f"<image {path}>")
+ else:
+ out.append(c.text)
+ failed += bool(res.is_error)
+ flag = " ERROR" if res.is_error else ""
+ print(f"=== {name} {json.dumps(args, ensure_ascii=False)} {dt:.2f}s{flag}\n" + "\n".join(out), flush=True)
+ return 1 if failed else 0
+
+
+if __name__ == "__main__":
+ sys.exit(asyncio.run(main()))