sim-use
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese0. Preflight
0. 预检步骤
Before first interaction with a device, run the preflight check:
bash
python3 scripts/preflight.py --device <UDID>This verifies sim-use is installed, the device is reachable, and the daemon is healthy. If you don't have the script, do the checks manually:
- — confirm sim-use is on PATH.
sim-use --version - — confirm the target device is listed and booted/connected.
sim-use devices - — confirm you can read the screen.
sim-use ui --device <UDID>
--devicesim-use android init --device <serial>首次与设备交互前,请运行预检检查:
bash
python3 scripts/preflight.py --device <UDID>此命令会验证sim-use已安装、设备可连接且守护进程运行正常。若没有该脚本,请手动执行以下检查:
- — 确认sim-use已添加至PATH。
sim-use --version - — 确认目标设备已列出且处于启动/连接状态。
sim-use devices - — 确认可读取屏幕内容。
sim-use ui --device <UDID>
当仅启动了一个模拟器或运行了一个守护进程时,参数为可选。对于Android设备,需运行一次来安装桥接APK。
--devicesim-use android init --device <serial>1. The observe-act loop
1. 观察-执行循环
Every interaction follows the same cycle: observe → act → verify.
每次交互都遵循相同的流程:观察 → 执行 → 验证。
Observe
观察
bash
sim-use ui --device <UDID>Read the outline. Each element has an alias and optionally a identifier. List cells carry (dominant list) or (scoped).
@N#<id>#N#N@MFrames in the JSON output (: , ) are in platform-native units — iOS points, Android pixels. Key off the envelope's field before doing math on coordinates across platforms. Always pair with — see Keeping output small below.
--jsonentries[].framescreenplatform--json--no-rawbash
sim-use ui --device <UDID>读取屏幕大纲。每个元素都有一个别名,可选带有标识符。列表单元格带有(主列表)或(范围限定)标记。
@N#<id>#N#N@MJSON输出中的帧信息(模式下的、)采用平台原生单位——iOS为点(points),Android为像素(pixels)。在跨平台进行坐标计算前,请先查看返回结果中的字段。使用时务必搭配参数——详见下方「精简输出内容」部分。
--jsonentries[].framescreenplatform--json--no-rawAct
执行
Pick a selector, in order of preference:
| Selector | When to use |
|---|---|
| Right after |
| Stable across minor layout changes. Paste from the outline. |
| Scripted flows. Combine with |
| Dynamic labels with counters/timestamps. Anchor with |
| Substring match when exact label is unknown. |
| Last resort for elements with no AX data. |
Disambiguate collisions with or (see ).
--element-type--frame minY=0.7rreferences/cheatsheet.md按优先级选择选择器:
| 选择器 | 使用场景 |
|---|---|
| 刚执行完 |
| 适用于小幅度布局变更后的稳定操作。直接从屏幕大纲中复制标识符。 |
| 脚本化流程。可搭配 |
| 带有计数器/时间戳的动态标签。使用 |
| 精确标签未知时,使用子字符串匹配。 |
| 无辅助功能(AX)数据元素的最后选择方案。 |
可通过或参数消除选择器冲突(详见)。
--element-type--frame minY=0.7rreferences/cheatsheet.mdVerify
验证
Always verify after acting — commands are fire-and-forget:
bash
sim-use ui --device <UDID> # read the new screen state
sim-use screenshot --device <UDID> --output after.png执行操作后务必进行验证——命令为“触发即遗忘”模式:
bash
sim-use ui --device <UDID> # 读取新的屏幕状态
sim-use screenshot --device <UDID> --output after.pngKeeping output small
精简输出内容
Every byte of command output you read costs context. Defaults that keep the loop cheap:
- Prefer the default text outline over . The outline carries everything a tap needs (
--json/@Naliases, roles, frames, states); reach for#<id>when you need structured fields for coordinate math (--json,entries[].frame) or full untruncated text (the outline truncates labels at 60 graphemes,screenat 30).value= - When you do use , add
--json.--no-rawis the raw accessibility tree — typically the bulk of the envelope's bytes, and useful only for debugging sim-use itself.data.raw - One per action: the Verify read of step N is the Observe read of step N+1. Don't run a second
uiin between.ui - Verify with the text outline, not a screenshot. Reading a screenshot costs several times more than a typical outline; take one only when the check is genuinely visual (colors, images, layout).
- On iOS, to wait out a transition, prefer (polls for the element) over re-running
tap --label 'X' --wait-timeout 3in a loop. Androiduihas notap; use--wait-timeoutbetween commands instead.sleep - For a known multi-step sequence on iOS, use (see
sim-use ios batch) — one invocation, one output.references/batch-reference.md
读取的命令输出每一字节都会占用上下文资源。以下默认设置可降低循环成本:
- 优先使用默认文本大纲而非模式。文本大纲包含点击操作所需的全部信息(
--json/@N别名、角色、帧信息、状态);仅当需要结构化字段进行坐标计算(#<id>、entries[].frame)或完整未截断文本(文本大纲会将标签截断为60个字符,screen字段截断为30个字符)时,才使用value=模式。--json - 使用模式时,添加
--json参数。--no-raw是原始辅助功能树——通常占返回结果的大部分字节,仅对调试sim-use本身有用。data.raw - 每个操作对应一次命令:第N步的验证读取即为第N+1步的观察读取。不要在中间重复执行
ui命令。ui - 使用文本大纲进行验证,而非截图。读取截图的成本是普通文本大纲的数倍;仅当检查内容为纯视觉元素(颜色、图片、布局)时才进行截图。
- 在iOS上等待页面过渡时,优先使用(轮询元素)而非循环执行
tap --label 'X' --wait-timeout 3命令。Android的ui命令无tap参数;可在命令间使用--wait-timeout命令替代。sleep - 对于iOS上已知的多步骤序列,使用命令(详见
sim-use ios batch)——一次调用即可完成所有步骤并返回结果。references/batch-reference.md
Common moves
常用操作
| Task | Command |
|---|---|
| Scroll down | |
| Type text | |
| Paste unicode | |
| Hardware button | |
| Android back | |
| Wait for animation | |
| Toggle/switch | |
| Swipe | |
| Pinch zoom in | |
| Rotate | |
| Record evidence GIF | |
| 任务 | 命令 |
|---|---|
| 向下滚动 | |
| 输入文本 | |
| 粘贴Unicode文本 | |
| 硬件按键操作 | |
| Android返回键 | |
| 等待动画完成 | 在命令间添加 |
| 切换开关 | |
| 滑动操作 | |
| 捏合放大 | |
| 旋转屏幕 | |
| 录制演示GIF | |
2. Pitfalls
2. 常见问题
Quick symptom index — see for detailed recipes.
references/pitfalls.md| Symptom | Cause | Fix |
|---|---|---|
| Label collision (e.g. header and tab bar share text) | Add |
| Alias cache is stale | Re-run |
| System layer (alert, share sheet) is on top | Dismiss it first, then re-run |
| Several elements share the selector | Use |
| Tap lands but nothing happens | Animation in progress, or element not yet interactive | Add |
iOS: | Soft keyboard only; HID Cmd+V is ignored | Use |
Android: | Background clipboard access blocked | Use |
Outline shows | iOS icon placeholder character | Match with |
| The selector resolved to a near-full-screen wrapper (common on Flutter/canvas UIs) and the tap hit its center, likely missing the intended control | Re-run |
| Device/app is rotated (the | Re-run |
快速症状索引——详细解决方案请见。
references/pitfalls.md| 症状 | 原因 | 修复方案 |
|---|---|---|
| 标签冲突(如标题栏和标签栏使用相同文本) | 添加 |
导航后 | 别名缓存已过期 | 点击前重新执行 |
| 系统层(弹窗、分享面板)处于顶层 | 先关闭系统层元素,再重新执行 |
出现 | 多个元素匹配同一选择器 | 使用 |
| 点击生效但无反应 | 动画正在进行,或元素尚未可交互 | 添加 |
iOS: | 仅使用软键盘;HID Cmd+V被忽略 | 使用 |
Android: | 后台剪贴板访问被阻止 | 使用 |
大纲中标签显示 | iOS图标占位符字符 | 使用 |
出现 | 选择器匹配到近乎全屏的容器(Flutter/画布UI中常见),点击命中容器中心,可能未击中目标控件 | 重新执行 |
出现 | 设备/应用已旋转( | 重新执行 |
3. Crash awareness
3. 崩溃感知
See for the full protocol. Summary:
references/crash-awareness.mdsim-use watches for the target process disappearing between commands. When it detects a crash:
================ PROCESS DISAPPEARED ================
com.example.app (pid 12345) was alive at the previous command and is GONE now.On Android, also detects the AOSP system crash dialog directly from the accessibility tree.
uiMandatory response:
- STOP. Do not silently relaunch or continue.
- Report the crash to the user with the banner text.
- Wait for instructions before proceeding.
After an intentional relaunch, call to clear the signal.
sim-use app-state --reset完整协议请见。摘要:
references/crash-awareness.mdsim-use会监控命令间目标进程是否消失。检测到崩溃时会输出:
================ PROCESS DISAPPEARED ================
com.example.app (pid 12345) was alive at the previous command and is GONE now.在Android上,命令还会直接从辅助功能树中检测AOSP系统崩溃弹窗。
ui强制响应流程:
- 立即停止操作。请勿静默重启或继续执行。
- 将崩溃提示横幅内容告知用户。
- 等待用户指令后再继续。
主动重启应用后,调用命令清除崩溃信号。
sim-use app-state --reset4. Escalation
4. 升级处理
Stop and ask the user when:
- A selector collision cannot be resolved with available disambiguators.
- Preflight fails and autofix does not recover.
- The task requires a destructive action (deleting data, uninstalling an app).
- You've retried the same action 3 times without progress.
出现以下情况时,请停止操作并询问用户:
- 无法通过现有参数解决选择器冲突。
- 预检失败且自动修复无法恢复。
- 任务需要执行破坏性操作(删除数据、卸载应用)。
- 同一操作重试3次仍无进展。
5. Exit checklist
5. 完成检查清单
Before reporting a task as complete:
- Run (or
sim-use ui) to capture the final state.screenshot - Confirm the screen matches the intended outcome.
- If the outcome is ambiguous, show the final output or screenshot to the user.
ui
报告任务完成前,请执行以下操作:
- 运行(或
sim-use ui)命令捕获最终状态。screenshot - 确认屏幕状态与预期结果一致。
- 若结果不明确,将最终的输出或截图展示给用户。
ui