Skip to content

feat(mcp): iphone_tap_element scrolls to find with scroll - #147

Merged
Derrors merged 4 commits into
Derrors:mainfrom
cosinec:feat/scroll-find
Nov 17, 2026
Merged

Derrors merged 4 commits into
Derrors:mainfrom
cosinec:feat/scroll-find

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What and why

iphone_tap_element only looks at the current screen. To reach an item further down a long list (for example 隐私与安全性 on the Settings page), an agent has to swipe, list the elements, and try again, one model round trip each time. Other phone agents have a "scroll until found" for this.

iphone_tap_element gets two optional parameters:

  • scroll: down (look further down, the finger moves up) or up.
  • max_scrolls: at most this many scrolls, default 8, 1–15 (MAX_SEARCH_SCROLLS).

How the daemon searches:

  • Found means a match exists and the one to tap (index) isn't entirely covered. I added the second condition after the first device run: the row scrolled into view right under the Settings search toolbar and was reported as covered instead of scrolling once more.
  • Each scroll is the existing swipe (so WDA or HID, and it waits for the list to stop) from 68% to 33% of the screen height in the middle of the screen over 1 s. A normal fast swipe has too much momentum and can fling the target past. Measured on the Settings page with the same 300 pt finger move, the content moved 618 pt at 0.3 s, 420 pt at 0.6 s and 282 pt at 1 s; a W3C pause before lifting didn't remove the fling (467 pt). Each step moves less than half a screen, so consecutive screens overlap and no row is skipped.
  • End of the list: when the tree no longer changes after a scroll, it stops early and says so (已到尽头 / reached the end).

The result line gives the count: 已点击 … (滑了 4 次后找到) / Tapped … (found after 4 scrolls). When nothing is found it reads 没找到包含 … 的元素(滑了 6 次,已到尽头). Without scroll, a miss now ends with a hint: ;可能在屏幕外,可带 scroll 边滑边找 / ; it may be off screen: pass scroll to look further.

Compatibility:

  • Protocol: Request::TapElement gets scroll: Option<ScrollSearch { down, max }> with skip_serializing_if, so a request without it is byte-for-byte unchanged (asserted). An older daemon ignores it and only looks at the current screen.
  • Batches: reuse_elements in iphone_batch keeps the scroll search.
  • D10: tool names and existing parameters don't change. The default output only gains the off-screen hint on a miss.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo fmt --check (per package) pass (Rust 1.99.1, macOS)
  • New or changed behaviour has a unit test:
    • ictl-mcp: tests::tap_element_scroll_search_is_optional_and_checked covers: no scroll means None; down defaults to 8; up with max_scrolls; left, 0, 16 and a non-string are errors; the scroll survives reuse_elements in a batch.
    • ictl-daemon: tools::tests::a_search_scroll_is_a_short_vertical_stroke_in_the_middle checks the stroke geometry.
    • ictl-protocol: tests::requests_round_trip_as_tagged_json checks the exact JSON without a scroll and round-trips one with it.
  • No existing test removed, ignored or loosened. Existing Request::TapElement { .. } constructions only gained scroll: None.
  • #[ignore] tests of the changed area run by hand: none apply

2. Real-device regression

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini (iPhone13,1), iOS 26.4.1, macOS (Apple silicon); WDA 16.14.0 launched in the background by the daemon
  • tests/device/run.py default steps pass on this branch (exit code 0): 16 calls, 0 failed, 15.6s in all
  • The same steps on the latest release, same device (run earlier the same day for feat(mcp): iphone_swipe holds before moving with hold, to drag icons #144): v0.2.7 release binary, 16 calls, 0 failed, 16.7s in all. No step on the branch is clearly slower.
  • Steps exercising this change: see section 4
  • Longer run: not affected
run.py output
this branch:

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.20s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.33s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕;可能在屏幕外,可带 scroll 边滑边找
=== iphone_press_button {"button": "home"} 1.35s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.89s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.28s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.71s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.8 秒)
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.98s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.28s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.22s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.61s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.64s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.14s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.25s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.2 秒)
=== iphone_screenshot {} 0.39s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.53s
已按 home
=== iphone_status {} 0.19s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 15.6s in all

latest release (v0.2.7):

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.23s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.36s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.27s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.95s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.26s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.63s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.60s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.19s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.15s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.76s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.87s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.69s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.30s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.3 秒)
=== iphone_screenshot {} 0.34s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.53s
已按 home
=== iphone_status {} 0.18s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.7s in all

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini, iOS 26.4.1, macOS
  • Feature: exercised end to end through the MCP server, including the error and edge cases
  • Untested conditions: the HID path (WDA was up throughout; this phone is below iOS 27); landscape; iPad; horizontal lists (only down / up are offered)
Steps and results

Settings app, opened fresh at the top of its main page. The privacy page opened by the second call was left with the back button before the scroll-up test.

## no scroll (as before): iphone_tap_element {"text":"隐私与安全性"}
[0.509s ok=True] 
没找到包含 "隐私与安全性" 的元素,先用 iphone_list_elements 或截图看看屏幕;可能在屏幕外,可带 scroll 边滑边找
## iphone_tap_element {"text":"隐私与安全性","scroll":"down","then":"elements","then_filter":"定位服务"}
[13.536s ok=True] 
已点击 Button "隐私与安全性" id="com.apple.settings.privacyAndSecurity" @(188,516) 343x54(滑了 4 次后找到)
界面已稳定(1.3 秒);和操作前相比界面有变化

## (Settings, scrolled to the bottom) iphone_tap_element {"text":"通用","scroll":"up","then":"elements","then_filter":"关于本机"}
[10.509s ok=True] 
已点击 Button "通用" id="com.apple.settings.general" @(188,208) 343x53(滑了 3 次后找到)
界面已稳定(1.2 秒);和操作前相比界面有变化
--- 操作后的界面 ---
Cell "关于本机" id="About" @(188,384) 343x54
Button "关于本机" id="About" @(85,384) 110x28
## (back on the Settings page, where 通用 was) iphone_tap_element {"text":"不存在的项xyz","scroll":"up","max_scrolls":3}
[8.942s ok=True] 
没找到包含 "不存在的项xyz" 的元素(滑了 3 次),先用 iphone_list_elements 或截图看看屏幕
## (same place, searching down to the end) iphone_tap_element {"text":"不存在的项xyz","scroll":"down","max_scrolls":15}
[18.061s ok=True] 
没找到包含 "不存在的项xyz" 的元素(滑了 6 次,已到尽头),先用 iphone_list_elements 或截图看看屏幕

## a wrong direction is an error, nothing is tapped
iphone_tap_element {"text":"x","scroll":"left"}
[0.0s ok=False]
参数 scroll 要是 down 或 up

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): two optional parameters added; a miss without scroll gains a short hint at the end
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md: no dependency changes

Docs: docs/tools.md, website/guide/tools.md, website/en/guide/tools.md, CHANGELOG.md, CHANGELOG.zh-CN.md.

🤖 Generated with Claude Code

iphone_tap_element only looks at the current screen, so an item further
down a long list needs the agent to swipe, list the elements and try
again, one round trip at a time.

scroll (down / up) and max_scrolls (default 8, at most 15) make the
daemon do it: while the element isn't on screen, or is entirely
covered (a row resting under the bottom toolbar), it scrolls 35% of the
screen height in the middle of the screen over 1 s and reads the tree
again. A 1 s stroke has almost no momentum: on an iPhone 12 mini a
300 pt finger move scrolled 618 pt at 0.3 s and 282 pt at 1 s, and a
pause before lifting didn't remove the fling. When the tree no longer
changes it is at the end of the list and stops. The answer says how many
scrolls it took. Without scroll nothing changes on the wire, and an
older daemon ignores the field.

Regression case Derrors#151.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflict in docs/dev/regression-cases.md: keep Derrors#146 (from Derrors#139)
and this branch's Derrors#147, in order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit that referenced this pull request Nov 17, 2026
)

Separate taps each wait for the interface to go idle, about 0.5 s apart
(iphone_batch: 5 taps in about 2.8 s), so a double tap, or an entry that
needs several taps in a short time, couldn't be done: double-tapping the
keyboard's Shift only turned it on and off again.

iphone_tap takes count (1-10, default 1). Through WDA the taps go in one
actions gesture, one finger moving once and tapping the same point
MULTI_TAP_GAP_MS (0.1 s) apart; one finger that moves to another point
inside a gesture had each tap registered twice. Through HID they go in
the same session. count travels in Request::Tap only when it isn't 1,
so older daemons see the same requests as before (and ignore it).

Regression case #147.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derrors <33656531+Derrors@users.noreply.github.com>
Derrors and others added 3 commits November 18, 2026 00:23
Resolve the conflicts with Derrors#141, Derrors#143 and Derrors#144: keep both sides (Tap's
count and TapSequence next to TapElement's scroll, the protocol helpers,
the MCP tests, CHANGELOG lines, doc rows with iphone_tap's count and
iphone_tap_element's scroll, regression rows Derrors#146-Derrors#149 then Derrors#151).

The search scroll now builds the Stroke that Derrors#144's swipe takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in Derrors#145; keep both tests in tools/mod.rs and rows Derrors#150 then Derrors#151.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ining it

With scroll, any row that merely contained the text ended the search on
the first screen: looking for "App" on the Settings page tapped
"Apple账户…" without scrolling. Now the search goes on until the exact
label or name is reachable. If none turns up by the end or max_scrolls,
the first row seen that contains the text is tapped (scrolling back to
it when it has gone off screen), and the result says no exact match was
found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 02257ca into Derrors:main Nov 17, 2026
9 checks passed
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflicts with Derrors#141-Derrors#147: keep both sets of client tests, and
rows Derrors#146-Derrors#151 from main. This branch's row becomes Derrors#153 (Derrors#152 goes to the
native floating search bar fix, Derrors#150).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors Derrors mentioned this pull request Nov 17, 2026
12 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants