Skip to content

feat(mcp): iphone_batch taps a run of keys in one gesture with one_gesture - #143

Merged
Derrors merged 2 commits into
Derrors:mainfrom
cosinec:feat/batch-one-gesture
Nov 17, 2026
Merged

Derrors merged 2 commits into
Derrors:mainfrom
cosinec:feat/batch-one-gesture

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Closes #142. Some text fields (inside in-app web views) don't take iphone_type_text at any speed, so the only way in is tapping keyboard keys one by one. In iphone_batch each iphone_tap waits for the interface to go idle, about 0.5 s per key: 7 digits take 3.6 s, 20 take 9.6 s.

iphone_batch gets an optional one_gesture (boolean, default false):

  • MCP: allowed only when every step is iphone_tap (by coordinates). The steps become one Request::TapSequence { points }. A batch that mixes in any other step (iphone_tap_element, wait, iphone_type_text, …) is an error before anything runs. The result is one line: 在一个手势里依次点了 N 个点:(x,y) … / Tapped N points in one gesture: ….
  • WDA: WdaClient::tap_sequence sends one /actions request with one touch pointer per point (tap_sequence_body). Pointer k pauses through the earlier points' ticks (move, down, 50 ms press, up, SEQUENCE_GAP_MS = 40 ms), then taps its own point, so the presses come strictly in turn and never overlap. It uses the same no-cool-off idle settings as iphone_tap (quick_gesture now delegates to a quick_actions that takes a raw body). One pointer per point is deliberate: a single pointer that moves between points inside one gesture registered every key twice.
  • HID (native on iOS 27, or the fallback when WDA is unreachable): the points are tapped in one HID session, one rotation check, 40 ms apart.
  • Protocol: new Request::TapSequence, at most MAX_SEQUENCE_POINTS (20, same as a batch) points, counted as mutating and foreground like Tap. An older daemon doesn't know the op and returns an error instead of tapping part of it. An older MCP server ignores one_gesture and runs the taps one by one (checked with 0.2.7, below), so the parameter is safe either way.

Tool names, existing parameters and default output don't change (D10).

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-wda: client::tests::a_sequence_is_one_finger_per_point_in_turn. One pointer per point, distinct ids, pointer k pauses for exactly 5 ticks per earlier point, then move/down/press/up at its own point.
    • ictl-mcp: tests::one_gesture_turns_taps_into_one_sequence. Taps become one TapSequence; a batch with iphone_tap_element, wait or iphone_type_text is an error; without the flag the batch stays step by step.
    • ictl-protocol: tests::requests_round_trip_as_tagged_json now also round-trips tap_sequence.
  • No existing test removed, ignored or loosened
  • #[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): 14 calls, 0 failed, 13.1s in all
  • The same steps on the latest release, same device: v0.2.7 release binary, 14 calls, 0 failed, 14.3s 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:

=== iphone_status {} 0.22s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.29s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.29s
已按 home
=== iphone_launch_app {"app": "时钟"} 1.32s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 12} 0.24s
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.60s
已点击 Button "秒表" value="1" @(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>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 430, "height": 60} 0.16s
<image shots/shot2.jpg>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.63s
已按 home
=== iphone_swipe {"from_x": 215, "from_y": 400, "to_x": 215, "to_y": 700} 1.63s
已滑动 (215,400) → (215,700)
=== iphone_type_text {"text": "设置"} 1.07s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.27s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.3 秒)
=== iphone_screenshot {} 0.37s
<image shots/shot3.jpg>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.54s
已按 home
--- 14 calls, 0 failed, 13.1s in all

latest release (v0.2.7):

=== iphone_status {} 0.91s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.26s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.20s
已按 home
=== iphone_launch_app {"app": "时钟"} 1.15s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 12} 0.25s
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.57s
已点击 Button "秒表" value="1" @(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.17s
<image shots/shot1.jpg>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 430, "height": 60} 0.16s
<image shots/shot2.jpg>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.78s
已按 home
=== iphone_swipe {"from_x": 215, "from_y": 400, "to_x": 215, "to_y": 700} 1.91s
已滑动 (215,400) → (215,700)
=== iphone_type_text {"text": "设置"} 1.70s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.26s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.2 秒)
=== iphone_screenshot {} 0.34s
<image shots/shot3.jpg>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.49s
已按 home
--- 14 calls, 0 failed, 14.3s 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 case
  • Untested conditions: the HID path (WDA was up throughout; this phone is below iOS 27); landscape; iPad
Steps and results

Spotlight search field focused, number keyboard (digit keys at y=548). Before each run the field was cleared through WDA, and afterwards its value was read back. Times are the iphone_batch call as seen by the MCP client; one is one_gesture: true, steps is the same taps without it.

one 1.91s '5839146'
one 1.84s '5839146'
one 1.92s '5839146'
one 1.89s '5839146'
one 1.88s '5839146'
== 5839146 one: 5/5 avg 1.89s
steps 3.58s '5839146'
steps 3.59s '5839146'
steps 3.55s '5839146'
steps 4.06s '5839146'
steps 3.53s '5839146'
== 5839146 steps: 5/5 avg 3.66s
== 1234567890123456 one: 3/3 avg 3.76s
== 1234567890123456 steps: 3/3 avg 7.70s
== 11223344556677889900 one: 3/3 avg 4.63s
== 11223344556677889900 steps: 3/3 avg 9.61s

letters (Pinyin keyboard, h e l l o w o r l d, one_gesture):
2.556 s    'hello\u2006world'
2.57 s    'hello\u2006world'
2.574 s    'hello\u2006world'
(the keyboard inserts a U+2006 between the two pinyin syllables)

mixed batch, one_gesture: [tap (23,548), wait 0.1]
-> one_gesture 只能用于步骤全是 iphone_tap(按坐标点)的批量   (0.0 s, field unchanged)

v0.2.7 MCP server, iphone_batch {"one_gesture":true,"steps":[{"tool":"iphone_tap","x":188,"y":400}]}
-> 1. iphone_tap → 已点击 (188,400)   (flag ignored, taps run step by step)

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): one optional parameter added, nothing else changes
  • 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

…sture

A batch of iphone_tap steps waits for the interface to go idle after each
tap, so pressing keys one by one (for fields that don't take
iphone_type_text) costs about 0.5 s per key. With one_gesture: true the
points go out as one W3C actions gesture, one touch pointer per point,
each pausing through the earlier points' ticks so the presses come one
after another. Any other kind of step makes the batch an error before
anything runs; without WDA the points are tapped one by one over HID.

On an iPhone 12 mini, 7 digit keys take 1.9 s instead of 3.6 s and 20
take 4.6 s instead of 9.6 s, all read back correctly.

Closes Derrors#142

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts with Derrors#139 and Derrors#141: keep both sides (TapSequence
next to Tap's new count, both constants, both client methods and their
tests, CHANGELOG lines, regression rows Derrors#146-Derrors#148 in order).

iphone_tap now carries count: a step with count under one_gesture is an
error instead of being tapped once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit b6dbe9d 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#139, Derrors#141 and Derrors#143 by keeping both sides:
drag_steps next to tap_sequence_body, the exports of both, the protocol
helpers, the MCP tests, CHANGELOG lines and regression rows Derrors#146-Derrors#149 in
order.

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 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>
@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.

iphone_batch: tap a sequence of keys in one gesture (one_gesture)

2 participants