Repository navigation
refactor: review phase 2 (split large files, exhaustive Route, page sources, MJPEG through the daemon) - #192
Merged
Merged
Conversation
ictl-mcp's lib.rs had grown to 2,200 lines: tool definitions, argument checking, batch steps, results and the server in one file. It is now schema.rs (instructions and tool definitions), args.rs (checking and turning arguments into requests), batch.rs (iphone_batch steps), result.rs (answers to tool results, input delivery), server.rs (McpServer over stdio and HTTP) and tests.rs. lib.rs re-exports them, so the crate's interface is unchanged. A pure move: concatenated and with whitespace ignored the modules are the old file; only `pub(crate)` was added where one module uses another's items, and rustfmt dropped a few trailing commas in the tests. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
client.rs was 2,100 lines, most of it one 900-line impl block and its tests. The methods now sit in client/ by what they do: session.rs (the transport, the XCTest session, stall detection, idle-wait settings), screen.rs (size, rotation, lock state, the element tree, screenshots, alerts, the keyboard, the passcode field), actions.rs (gestures, buttons, IOHID events, apps, links) and typing.rs (the focused field). The free functions and types stay in client.rs; the tests move to client/tests.rs. A pure move: each of the 68 methods is the same as before with whitespace ignored; methods that were private are `pub(super)` so the sibling modules can call them, and the tests' fixture paths gained a `../` for the deeper directory. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
viewer.html was one 3,700-line file: 860 lines of CSS, the markup and a 2,560-line script. Its sources are now apps/iphone-control/web/: index.html with `@include` lines for viewer.css and the scripts in the order they run (js/i18n, ui, state, demo, screen, info, video, device, tasks, alert, scope, layout). build.rs replaces each include with its file and writes the page to OUT_DIR, which viewer.rs embeds as before; no Node or other tool is needed to build. The scripts are plain scripts in one scope, as the single file was, so nothing about how the page runs changes: the page build.rs puts together is byte for byte the old viewer.html. Turning them into ES modules would mean giving every shared global (S, T, W, D…) an import, a rewrite of its own; inline modules couldn't import each other anyway. The page tests read the assembled page through tests/viewer/page.mjs, which expands the includes the same way. A unit test checks that the embedded page has every include expanded and stays strict. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ilable
Actions that have a way per backend were written as
`match self.wda(g) { Some(w) => …, None if native => …, None => … }`
or `if self.wda(g).is_none() && self.native(g) { … }` followed by
`self.require_wda(g)?`, in seven files. A new action could leave out a
branch without the compiler noticing.
`Daemon::route(g)` now decides once: `Route::Wda(&mut WdaClient)`,
`Native`, `Hid` (WDA down, iOS 27+ set to use WDA) or `Unavailable`
(WDA down below iOS 27), and the fifteen dispatch sites match it in full:
the element tree, the lock check of a read-only viewer, settling, alerts,
waiting for text, launching, terminating, opening links, unlocking, raw
screenshots, taps at a point, long presses, locking, status and the
display sample. Each arm does what the old code did, including the
error kind (`preflight` where it was); `require_wda` has no callers left
and is removed.
Fallback chains stay as they were: taps, swipes, typing, buttons and
screenshots try WDA first and go on over HID when it turns out
unreachable, which a route decided up front can't express. So do the
questions only WDA answers.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…tream) On iOS 17-26 the viewer connected to the phone's port 9100 itself (Device::find + connect_port), the one place besides wda-bridge where something other than the daemon reached for the phone (D2), and one that could only work over USB (docs/dev/wifi.md, second version). The viewer's MJPEG hub now asks the daemon (`open_mjpeg_stream`, the page's UDID as expect_udid). The daemon checks it against the controlled device (from the published snapshot: no device lock, a page shouldn't wait behind a long action to see the screen), asks WDA for the stream and passes its answer on byte for byte until either side closes, so the viewer's reader is unchanged. Like ScreenStream, the maintenance lease is checked when it opens and not held while it runs. Also from the review: the LocalSet evaluation is written down in docs/architecture.md (the supervision tick is already Send; the rest is rustc's higher-ranked Send inference, not worth it without a measured problem). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Phase 2 of the architecture review of 0.2.14, five commits:
schema.rs(instructions, tool definitions),args.rs(checking, arguments to requests),batch.rs,result.rs(answers to results, input delivery),server.rs(McpServer, stdio and HTTP) andtests.rs.lib.rsre-exports them: the crate's interface is unchanged. A pure move: with whitespace ignored the modules are the old file; onlypub(crate)was added where modules use each other's items.client/{session,screen,actions,typing}.rs, tests intoclient/tests.rs. A pure move: each of the 68 methods is unchanged; private ones arepub(super)for the sibling modules.web/.viewer.html(3,689 lines) is nowweb/index.htmlwith@includelines forviewer.cssand twelve scripts in the order they run;build.rsassembles it intoOUT_DIRandviewer.rsembeds that, no Node needed. The page built is byte for byte the oldviewer.html. The page tests read it throughtests/viewer/page.mjs.Route.Daemon::route(g)decides once betweenWda(&mut client),Native,Hid(WDA down, iOS 27+ on WDA) andUnavailable(WDA down below iOS 27); fifteen dispatch sites match it in full, so a new action has to say what it does on each. Each arm does what the old code did (including the error kinds);require_wdais gone. Fallback chains (taps, swipes, typing, buttons and screenshots try WDA and go on over HID when it turns out unreachable) stay as they were, which the doc comment onRoutesays.Request::MjpegStream). On iOS 17–26 the viewer connected to the phone's port 9100 itself, the one place besideswda-bridgethat bypassed the daemon (D2) and could only work over USB (docs/dev/wifi.md, second version). The viewer's MJPEG hub now asks the daemon, which checks the page's UDID against the controlled device (from the snapshot, no device lock), asks WDA for the stream and passes it on byte for byte until either side closes.Decided against, with reasons:
ControlBackendtrait: the backends don't share one shape (the fallback chains above), so a trait would mean rewriting about 4,000 lines of tool code. The exhaustiveRoutecovers the stated risk, a forgotten branch.S,T,W,D…), and inline modules can't import each other; it would be a rewrite of the front end.LocalSet: evaluated. The supervision tick is alreadySend, and the connection handler has one real gap. The rest is rustc's higher-rankedSendinference ("not general enough"), reaching intoictl-axandictl-devicewithout locations, and no stutter was measured. Written down indocs/architecture.md.reqwest0.12,thiserror1,tungstenite0.24…) come from vendored upstream crates (apple-codesign,plume_core,omnisette).Tests
1. Unit tests
cargo test --workspace --all-features --locked: 551 passed;cargo clippy --workspace --all-targets --all-features --locked -- -D warnings;cargo fmt --checkper package;node --test tests/viewer/*.test.mjs: 34 passedthe_route_without_wda_follows_the_ios_version_and_backend,the_embedded_page_is_assembled,the_phone_s_bytes_pass_through_until_the_page_goes,another_device_than_the_controlled_one_is_refused../)#[ignore]tests of the changed area: none run2. Real-device regression
docs/dev/regression-cases.md(release: 0.2.14 #183, filled in with the results below)run.py: iPhone 3 rounds, 48 calls, 0 failed; iPad 5 rounds, 80 calls, 0 failedscenarios.py: iPhone everything (tools typing delivery collect editing fresh batch menu idle url lock) 75/75; iPad everything butidle60/60,lock3 runs 39/39 (see below)main: iPhone 17.73 s → 17.78 s total (mainat 460f0c1, same hour);type_textflagged on medians of 3, but across four sets of runs today it ranges 2.76–4.55 s,mainincluded. iPad 122.3 s → 115.0 s for 5 rounds (mainat 25a0333, this morning);compare.pyrefused a step-by-step comparison because the Clock tabs picked differ, and per-tool medians are within noiseOn the iPad,
lockfails a lock now and then: the IOHID power press takes 5.4 s instead of 0.4 s and the screen stays on. It comes in stretches and onmaintoo (also seen while testing #187–#191). Here this branch failed 3 locks in 4 runs at first,mainpassed 6 in the same stretch, then this branch passed 9 of 9. Nothing this PR changes runs differently in that scenario.run.py output
3. Regression cases (docs/dev/regression-cases.md)
scenarios.pyas above4. Real-device proof of the fix or feature
GET /stream?udid=…at once: the viewer process had no connection to usbmuxd (before: one per phone stream), only one more to the daemon; the daemon had two more (the viewer, the phone's 9100); each stream got about 150 JPEG parts in 12 s; once they closed, the daemon's connection to the phone closed too.GET /videothrough the same source gave VAAPI-encoded H.264?udid=the viewer asks for the device it last knew (here the iPhone, selected when it started) and the daemon refuses: "the controlled device changed". Pages always send their deviceChecklist
Request::MjpegStreamis new and only the viewer sends it🤖 Generated with Claude Code