Repository navigation
feat(mcp): 支持替换输入框全文、报告元素截断和等待元素消失 - #159
Conversation
Derrors
left a comment
There was a problem hiding this comment.
感谢实现和真机对照。三个功能的方向都对。replace 在 WDA 通道明确报「需要原生控制」,没有悄悄退回到追加输入;替换后先核对全文再按回车。这两处设计都很好。以下意见基于 5b58753 的代码阅读,第 1 条我已经对着代码逐步确认过,其余几条是从代码推断的,还没上真机复现。
合入前需要修
1. 原值中已包含新文字时,替换一定失败(native.rs · replace_text → native_paste)
replace_text 只把聚焦框一个字段的原值作为 old 传给 native_paste,而等待循环里的 paste_seen 比较的是 elements::field_values(),也就是全屏所有输入框的值。全选之后原文字还留在框里,所以第一次读回就满足「包含 wanted 且 now != old」,直接返回 Typed。这时「允许粘贴」还没点,restore_pasteboard 一还原剪贴板,弹窗就消失了,粘贴并没有进去。最后全文核对失败,报错。
例子:把 iphone 15 pro 替换成 iphone,或把 wifi 替换成 wi。屏幕上另一个输入框恰好包含新文字时也会触发。
建议:替换路径不复用「原值里有没有新文字」这个判断。改为点过「允许粘贴」(或确认粘贴已落下)之后,再核对聚焦框的全文是否等于 text。
2. 替换失败后,原文字仍处于全选状态(replace_text)
Cmd-A 之后的各个出错分支(粘贴报错、弹窗超时、核对失败)都没有取消选中。agent 按错误提示改用默认模式的 iphone_type_text 重试时,会把原内容整个覆盖掉,这和默认模式「不清空原有内容」的承诺相反。第 1 条会让这种情况经常出现。建议出错时先取消选中,比如按一下 → 键,再返回错误。
3. 没设密码的手机,锁屏可能被判成「已消失」(native_wait_for)
锁屏保护用的是 native_locked() → passcode_locked()。从名字看,它只在设了密码的手机上报锁屏。没设密码的手机在等待期间自动锁屏后,读到的是一个完整的锁屏界面,里面没有目标文字,于是返回「已消失」。这正是这个保护本来要防的误报。如果 lockdown 能拿到不依赖密码的锁屏状态,就改用它;拿不到的话,可以看前台是不是 SpringBoard 锁屏。
建议修
4.「树完整」的条件过宽
「不完整的树不能确认消失」这个原则我同意。问题是现在下面任何一种情况都会标成不完整:节点超过 400 个、遍历超时、遍历途中有一个节点消失、WDA 收紧了快照上限。结果是长列表、带动画的页面(例如计时器在走)上,disappeared 等不到成功;replace 也会一直报「无法确认当前聚焦的是可读的普通输入框」。
对 focused_text_value 来说,只要能确认聚焦框是唯一的就够了,不需要整棵树完整。对 disappeared 来说,至少应该把「个别节点在遍历中消失」和「被上限截断」分开处理。
5. 等消失时每轮都查一次锁屏
native_wait_for 每 0.3 秒调一次 native_locked(),每次都新建 lockdown 连接。5 秒的等待大约要握手 15 次,其中任何一次出错整个等待就失败。WDA 路径同样每轮多一次 locked()。建议只在 wait_match 即将判定「已消失」时查一次。
6. 测试场景失败时没有收尾(tests/device/scenarios.py · editing)
前置检查失败后直接 return,Spotlight 和键盘还留在屏幕上,后面的场景会从错误的界面开始,连带失败。建议用 try/finally 保证执行 p.home()。
小问题
- 只有直接调用
iphone_list_elements才会带matched_count/truncated,then=elements和 batch 的结果里都没有,字段不一致。返回了structuredContent的工具也可以考虑声明outputSchema。 - viewer 的
/elements(viewer/api.rs)又写了一遍element_list的序列化,fallback 分支也少了这两个字段。建议复用同一个 helper。 replace的空文本检查在 MCP 的to_request和 daemon 的check_request里各做了一次,两处的报错文案也不一样。只保留 daemon 那一处就够了。
麻烦修完 1–3 后,把「设置」里的 wifi → wi(新文字是原值子串)补进真机对照,同时确认一下之前 run.py 首轮 15/16 的 Spotlight 超时是否还会出现。
…rance on lock screens
An argument a tool doesn't list in its input schema was ignored: a call with a misspelt name, or with an argument from a newer version, ran with the default and reported success. iphone_wait_for with state: "disappeared" answered that the text had appeared (Derrors#158). Each call is now checked against its tool's input schema before anything is done, and the error names the arguments the tool takes. A batch's steps are checked the same way; then in a step is refused (the batch's own then applies), and wait takes only seconds. The developer tools and iphone_confirm are checked against their own schemas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ment list schema - iphone_type_text with replace: true and empty text empties the focused field: select all, then Delete (no paste, no "Allow Paste" prompt), and the original field must read empty. An empty field reads its placeholder as its value natively (Spotlight's reads «搜索»), so a value equal to the placeholder counts as empty. On the phone the first try failed exactly there: "the field isn't empty, it reads 搜索". - iphone_list_elements declares its output schema (the structured content it already returns). - tests/device/run.py waits for «设置» in Spotlight again, as on main. The switch to Clock came from one timeout on one run; on iPhone19,7 / iOS 27.2.1 the original step passed 5 runs out of 5 with this branch (0.24-0.36 s), so it stays a check rather than being worked around. - tests/device/scenarios.py editing: also empties the Spotlight query. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and says why it timed out
- Natively the read is judged first (no extra cost): the lock screen known
by its marks is reported at once; notification center, control center or
SpringBoard in front without app icons or Spotlight (how the lock screen
often reads natively) don't count as gone. Lockdown is asked after that,
at most once a second, instead of first on every confirmation: it is the
only check that says locked before the read shows it, but only on a phone
with a passcode, so it can't stand alone. A lockdown failure leaves the
lock state unknown and the wait goes on; it no longer ends the wait.
- Only a known lock ends the wait at once ("the phone locked while
waiting"). Something else over the screen keeps the wait going until the
text is gone or the timeout.
- Through WDA, a failed or uncertain lock check keeps the wait going
instead of ending it.
- A timeout says why: the text is still there; the screen wasn't read in
full (too many elements, a slow read); or something is over the screen /
the lock state couldn't be found out.
- Docs: a missing full stop in the element list row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
During a sleep focus the lock screen is another process (SleepLockScreen), not SpringBoard, with SpringBoard's flashlight and camera buttons over it (iPhone19,7, iOS 27.2.1). With lockdown not saying locked (as on a phone without a passcode, simulated on the device), a wait for Clock's tab to disappear after the lock button answered "Disappeared" in 1.1 s. The flashlight and camera buttons (flashlight-orb-button, system-orb-button-*) and SleepLockScreen's own elements now mark the screen as covered, whichever process is in front. On the device, with lockdown still left out: the lock button over Clock, and a phone locked for a while, both time out saying the screen is covered; the unlocked home screen still answers "Disappeared" in 0.2 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Julian0197 感谢 新增的提交
真机验证iPhone19,7,iOS 27.2.1,原生通道,
已知、不在这个 PR 里
合并时建议 squash:7 个提交里有你我交替改动、后来被覆盖的内容。 🤖 Generated with Claude Code |
Closes #158
11 月 19 日同机复核(
eb42c0f对上游 0.2.9)使用 iPhone 14、iOS 27.0.1、原生控制,各版本的 MCP 与 daemon 均取自对应的 release 构建。
9a476ebeb42c0fwifi,然后用replace:true替换为wiwifi wi(5.191 秒)wi(4.865 秒)eb42c0f接着传{"text":"","replace":true},1.718 秒后工具返回已清空,独立读回占位文字「搜索」。compare.py的逐步中位数之和为 28.29 → 28.58 秒。首个状态查询慢 0.31 秒、滑动慢 1.39 秒,两项超出脚本阈值,原因尚未定位。eb42c0f的默认scenarios.py52/52 通过,覆盖 Spotlight 的wifi → wi → 蓝牙 → 清空、元素截断和等待消失。锁屏与 URL 两个可选场景未运行。eb42c0f在 Rust 1.99.1 上工作区测试 501 通过、3 项忽略,严格 Clippy、逐包格式检查通过。Viewer 34 项、设备脚本解析 11 项通过,回归索引 0 缺失。GitHub CI本次真机运行期间,Derrors 又补充了等待消失的超时诊断(
5575797)和睡眠专注锁屏识别(a7bd81d)。上表保留实际测试的提交号。本机在
a7bd81d重新执行工作区测试,502 项通过、3 项忽略,严格 Clippy 通过。What and why
在 iPhone「设置」搜索框输入
wifi,接着输入蓝牙。0.2.8 会留下wifi 蓝牙。现在可以调用iphone_type_text {"text":"蓝牙","replace":true},再读搜索框,全文就是蓝牙。省略replace时仍然追加。只有核对全文成功,工具才会执行可选的submit。设置首页这次读到 13 个元素。如果只要第一项,
iphone_list_elements {"limit":1}会同时返回matched_count:13和truncated:true。把上限调到 500,返回 13 项和truncated:false,调用方可以直接读取字段。在设置首页调用
iphone_wait_for {"text":"飞行模式","state":"disappeared","timeout":2},旧版在开关仍可见时就报告「已出现」。新版在该页等满两秒后超时。切到时钟再发同一请求,工具读到完整界面后返回「已消失」。省略state时仍等出现。对 5b58753 的评审回复
修订提交
c2ce06d。wifi、目标wi、另一输入框已含wi,以及焦点移到不同对象。finally返回主屏幕,并增加wifi → wi → 蓝牙的独立读回断言。then:"elements"均带截断元数据。Viewer 复用元素列表转换,缺少数据时计数和截断状态为 null。空文本校验共用于 daemon 和批量预检,避免批量执行到一半才报参数错误。此次保留可选的structuredContent,未声明强制的outputSchema,以兼容旧 daemon 的纯文本响应和操作工具其他then模式。当前提交已通过本机严格 Clippy 和工作区测试(498 通过、3 个既有忽略项)。本轮 USB 尚未枚举到 iPhone,作者要求的「设置」
wifi → wi和用原搜索词「设置」重查 Spotlight 超时,尚无本提交的真机结果。下方真机数据保留原提交号。早期提交的测试记录(
7bdd408至c2ce06d)1. Unit tests
replacing_text_requires_one_readable_focused_field、element_limit_is_reported_in_structured_content和disappearance_requires_a_readable_complete_screen_without_the_target。2. Real-device regression
同一台 USB iPhone 14(iOS 27.0.1,390 × 844 pt),macOS 26.6.2。用各自 release 版 MCP 与 daemon 走原生通道。
9a476eb7bdd408TextField "蓝牙" id="SpotlightSearchField",旧断言只看单列的value=。后续提交5b58753只改两处测试脚本,尚未在手机上重跑。tests/device/run.py --repeat 5 --json,并运行tests/device/compare.py。3. Regression cases
4. Real-device proof
wifi,调用iphone_type_text {"text":"蓝牙","replace":true}wifi 蓝牙蓝牙。替换调用分别用时 7.31 s、7.81 s。无键盘时,带submit:true的替换在场景组中明确返回错误。iphone_list_elements,先取limit:1,再取limit:500matched_count均为 13,分别返回 1 项和 13 项,truncated分别为 true、false。iphone_wait_for {"text":"飞行模式","state":"disappeared","timeout":2},切到时钟后再调用replace的追加行为。逐次真机记录Checklist