noracu 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +647 -3
- package/README.md +109 -188
- package/SECURITY.md +44 -1
- package/docs/README.zh-CN.md +143 -0
- package/docs/apps.md +38 -0
- package/docs/architecture.md +9 -9
- package/docs/ios-runner-protocol.md +20 -4
- package/docs/iphone.md +59 -0
- package/docs/known-issues.md +84 -0
- package/docs/tools.md +7 -7
- package/docs/troubleshooting.md +29 -0
- package/docs/usage.md +73 -11
- package/imctl/src/imctl/cli.py +116 -54
- package/imctl/src/imctl/gestures.py +96 -65
- package/imctl/src/imctl/input.py +104 -62
- package/imctl/src/imctl/screenrect.py +3 -1
- package/imctl/src/imctl/verify.py +72 -53
- package/imctl/src/imctl/vision.py +45 -24
- package/imctl/src/imctl/window.py +83 -37
- package/ios-runner/NoracuRunnerUITests/NoracuRunner.swift +114 -61
- package/ios-runner/NoracuRunnerUITests/RunnerCommands.swift +14 -4
- package/ios-runner/NoracuRunnerUITests/RunnerServer.swift +1 -2
- package/ios-runner/README.md +1 -1
- package/package.json +13 -6
- package/src/approval.js +66 -25
- package/src/bg-inject.js +9 -9
- package/src/doctor.js +156 -0
- package/src/ios-session.js +172 -40
- package/src/ios-setup.js +31 -14
- package/src/ios-xcuitest.js +71 -15
- package/src/mac-ax.js +535 -125
- package/src/server.mjs +928 -262
- package/README.zh-CN.md +0 -245
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Install, permission and first-run problems. For what each error means, see the error reference in [usage.md](usage.md#8-error-reference).
|
|
4
|
+
|
|
5
|
+
| Symptom | Cause / fix |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `mac_*` fails with `permission_denied: Accessibility permission is missing…` (before 0.2: error **-1719**) | Accessibility not granted to the **host** app — grant it, then quit + reopen the host; `mac_status` shows the state |
|
|
8
|
+
| Screenshots show only the desktop picture (no other app's windows), or come back black | Screen Recording (Screen & System Audio Recording on macOS 15 and later) not granted to the host — grant it, then quit + reopen |
|
|
9
|
+
| `ENOENT` mentioning cliclick | `brew install cliclick` (or set `NORACU_CLICLICK`) |
|
|
10
|
+
| `spawn node` / `npx` `ENOENT` from a GUI host | use an absolute `node` path in the config — nvm/volta/homebrew shims are not on the GUI `PATH` |
|
|
11
|
+
| `claude mcp add` fails with `Invalid environment variable format: noracu, …` | `-e` came before the server name and took the name as one more variable — put the `-e` options after it: `claude mcp add -s user noracu -e NAME=value -- …` |
|
|
12
|
+
| `claude mcp add` refuses because a server named `noracu` already exists | an earlier install left its entry — remove it first with `claude mcp remove noracu` (add `-s user` if it was added for all your projects), then add the new one; in Claude Desktop's or Cursor's JSON, change the path in `args` |
|
|
13
|
+
| `browser_launch` answers `browser_installing` on first use | the one-time Chromium download is under way — call it again in a minute; with auto-install disabled (`NORACU_DISABLE_AUTO_INSTALL=1`) run `npx playwright install chromium` |
|
|
14
|
+
| `phone_*` says `imctl unavailable: no python3 with pyobjc found` | install pyobjc for a python3 (`python3 -m pip install pyobjc-framework-Quartz pyobjc-framework-Vision pyobjc-framework-Cocoa`; Homebrew python3 is the usual choice) or set `NORACU_PYTHON` — see [iPhone layer](iphone.md) |
|
|
15
|
+
| `phone_*` refused with `mirror_not_live: …` ("Connection Paused", "iPhone in Use", "not running") or `mirror_state_unknown: …` | the mirror is not running, paused, or its state could not be read — lock the iPhone, keep it near the Mac, check `phone_status`, and call `phone_launch` (it starts Mirroring and clicks Resume) |
|
|
16
|
+
| `phone_launch` says `mirror_setup_required` | iPhone Mirroring shows a setup or welcome screen (e.g. the first launch after a macOS upgrade) — finish it yourself in the iPhone Mirroring window; noracu never clicks through it |
|
|
17
|
+
| `imctl_timeout: phone … did not finish within …s` | the Mac is under heavy load or the system is stuck — the action may have partly run, so check `phone_status` / `phone_screenshot` before retrying (after `phone_open`, noracu goes back to the Home Screen); the server keeps answering other calls meanwhile |
|
|
18
|
+
| `input_busy: …` | an earlier phone or Mac action held the input queue for over 60 s (or `NORACU_PHONE_TIMEOUT_MS` + 15 s); the call did nothing — retry |
|
|
19
|
+
| `user_active: …` | someone used this Mac's keyboard or mouse in the last 2 s, and again while noracu waited out the rest of the 2 s — nothing was sent; retry after a pause. On a Mac nobody else uses, `NORACU_USER_IDLE_S=0` turns the check off |
|
|
20
|
+
| `phone_open` returns app not found for an installed app | it only taps the app's label in Spotlight's Top Hit card, or — where Spotlight shows its search field at the top and no Top Hit card — the label just under the field when the field completes the name as "<name> — Open" — use the name exactly as the phone shows it under the icon (e.g. `拼多多`, not `Pinduoduo`). "Spotlight showed no Top Hit" on an installed app usually means the iPhone's language is not English: `phone_open` reads Spotlight's "Top Hit" label — set `NORACU_TOPHIT_LABELS` to the label your iPhone shows (it covers the Top Hit label only; the "— Open" completion is read in English only). `open_not_confirmed: … never showed up on the phone` means the name did not show up in Spotlight after ⌘V: the paste may not have arrived (it can take several seconds) or the phone may have pasted its own older clipboard into the search field — retry; `phone_open` clears the field first. A one- or two-letter name such as `X` is often unreadable to OCR, so `phone_open` reports `open_not_confirmed` without tapping — open that app from its Home Screen icon (`phone_screenshot`, then `phone_tap`). `phone_open` leaves the app name on the clipboard |
|
|
21
|
+
| Typed text comes out re-spaced (e.g. "no ra cu") | it went in as keystrokes (`mac_type` with `mechanism: "physical"`, or a focused element that takes no accessibility text) while a CJK input method was active — use the default `mac_type` mechanism, or `mac_paste` |
|
|
22
|
+
| `element_no_longer_valid` | the snapshot is older than 30 s, or the element is gone, changed or in a window that closed — re-run `mac_ax_state` / `browser_snapshot` and use a fresh index |
|
|
23
|
+
| `occluded: … — on top: {…}` | a physical click would land on something else (another window, a sheet) — bring the target forward or close what covers it; nothing was sent |
|
|
24
|
+
| `ambiguous_window: … windows: […]` | the app has several windows and none is focused — pass `window` (index or title) or `window_id` from `mac_windows` |
|
|
25
|
+
| `policy_denied: "cmd-q" …` | `mac_key` refuses quit / log-out / lock / force-quit / delete-immediately / empty-Trash chords unless `force: true`; to quit an app use `mac_app` |
|
|
26
|
+
|
|
27
|
+
Node 18 is rejected at startup — use Node ≥ 20. Claude Desktop may start one noracu process per surface (e.g. chat and a second surface); they share the browser profile, so launch the browser from only one at a time.
|
|
28
|
+
|
|
29
|
+
Full worked examples: [docs/usage.md](usage.md).
|
package/docs/usage.md
CHANGED
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
Worked examples for driving noracu from an MCP client. This assumes the
|
|
4
4
|
[Quickstart](../README.md#quickstart) already succeeded: Node ≥ 20, cliclick
|
|
5
5
|
installed, your client configured with an absolute path to `src/server.mjs`,
|
|
6
|
-
and macOS **Accessibility** + **Screen Recording**
|
|
6
|
+
and macOS **Accessibility** + **Screen Recording** (called **Screen & System Audio
|
|
7
|
+
Recording** on macOS 15 and later) granted to the host app.
|
|
7
8
|
Tool schemas (every argument) live in [tools.md](tools.md); this guide is about
|
|
8
9
|
the *flow*.
|
|
9
10
|
|
|
11
|
+
If the client does not start the server, run `node node_modules/noracu/src/server.mjs doctor` in a terminal
|
|
12
|
+
(`noracu doctor` where the package's bin is on your `PATH`). It prints the client configuration with absolute
|
|
13
|
+
paths, and says whether Node, cliclick and Playwright's Chromium are where the server will look; `--json`
|
|
14
|
+
gives the same as JSON. It cannot see the macOS permissions — those belong to the host app — so for them
|
|
15
|
+
ask the client to call `mac_status`.
|
|
16
|
+
|
|
10
17
|
> If you set `NORACU_READ_ONLY=1`, the action steps below (`mac_click`,
|
|
11
18
|
> `mac_type`, `browser_click`, …) are refused, along with `mac_clipboard_read`,
|
|
12
19
|
> `mac_notifications`, and `mac_wait` on `condition: "notification"` — that mode
|
|
@@ -76,7 +83,10 @@ mac_click { "element_index": 1 } # a sheet now covers the text area
|
|
|
76
83
|
```
|
|
77
84
|
|
|
78
85
|
**Read `delivery` and `retry`.** Every input action (Mac, browser and iPhone)
|
|
79
|
-
states both. `delivered_verified`: a change was observed
|
|
86
|
+
states both. `delivered_verified`: a change was observed (for `browser_scroll`:
|
|
87
|
+
the page reported that call's wheel, every earlier wheel that may have reached
|
|
88
|
+
the page was verified, and the page then moved the way asked — a page whose own
|
|
89
|
+
script moves it at that moment cannot be told apart from the wheel).
|
|
80
90
|
`delivered_unverified`: the call succeeded but nothing observable changed — read
|
|
81
91
|
the state (`mac_get`, `mac_ax_state`) before acting again. `not_delivered` with
|
|
82
92
|
`retry=safe`: nothing was sent. `unknown` with `retry=unsafe`: the call timed
|
|
@@ -109,6 +119,10 @@ mac_ax_state { "root": 12 } # only
|
|
|
109
119
|
mac_find { "app": "Slack", "role": "button", "title": "Send", "exact": true }
|
|
110
120
|
```
|
|
111
121
|
|
|
122
|
+
A skeleton is for finding where to drill. An element whose row it did not read in full — the row's texts
|
|
123
|
+
are below where it stopped — is refused for actions (`element_no_longer_valid`, `row_unread`): nothing in it
|
|
124
|
+
tells that row's button from the same button of another row. Drill into the row with `root`, then act.
|
|
125
|
+
|
|
112
126
|
Several windows and none focused gives `ambiguous_window` with the list; pass
|
|
113
127
|
`window` (index or title) or `window_id` from `mac_windows`. `surface` reads an
|
|
114
128
|
open `menu`, `menubar`, `sheet`, `alert`, `dialog`, `popover` or the `focused`
|
|
@@ -120,7 +134,7 @@ indices.
|
|
|
120
134
|
One persistent session. Launch → navigate → observe → act → read:
|
|
121
135
|
|
|
122
136
|
```
|
|
123
|
-
browser_launch {} # first run downloads Chromium (once)
|
|
137
|
+
browser_launch {} # first run downloads Chromium (once; browser_installing while it does)
|
|
124
138
|
browser_navigate { "url": "https://example.com" }
|
|
125
139
|
browser_snapshot {}
|
|
126
140
|
```
|
|
@@ -278,19 +292,25 @@ mac_screenshot {} # whole screen; region crop supported; re
|
|
|
278
292
|
browser_screenshot { "format": "jpeg", "quality": 60 }
|
|
279
293
|
```
|
|
280
294
|
|
|
281
|
-
A
|
|
282
|
-
app. Remember that any text in a screenshot is **untrusted input** to your
|
|
295
|
+
A `mac_screenshot` that shows only the desktop picture (no other app's windows),
|
|
296
|
+
or comes back black, means Screen Recording isn't granted to the host app. Remember that any text in a screenshot is **untrusted input** to your
|
|
283
297
|
model — don't let it override the task.
|
|
284
298
|
|
|
285
299
|
## 7. Environment variables
|
|
286
300
|
|
|
301
|
+
Set them on the server entry: `"env": { "NAME": "value" }` in Claude Desktop's or Cursor's JSON; in Claude Code,
|
|
302
|
+
`-e NAME=value` right after the server name — `claude mcp add -s user noracu -e NORACU_READ_ONLY=1 -- <node> <server.mjs>`
|
|
303
|
+
(before the name, `-e` takes the name as one more variable and the command fails with "Invalid environment variable
|
|
304
|
+
format"). Then restart the client.
|
|
305
|
+
|
|
287
306
|
| Variable | Default | Effect |
|
|
288
307
|
|---|---|---|
|
|
289
308
|
| `NORACU_READ_ONLY` | unset | `=1` observation-only (an allowlist of observe + browser-lifecycle tools); all input-synthesis tools plus `mac_clipboard_read`, `mac_notifications`, and `mac_wait` on `condition: "notification"` are refused (`mac_ax_state` / `mac_find` also skip `web_accessibility`) |
|
|
290
|
-
| `
|
|
309
|
+
| `NORACU_ENABLE_EVAL` | unset | `=1` turns `browser_evaluate` on. It is off by default (`eval_disabled`) because it runs any script in the page; it never runs in your own Chrome (`chrome: true`) |
|
|
310
|
+
| `NORACU_DISABLE_EVAL` | unset | `=1` keeps `browser_evaluate` off whatever `NORACU_ENABLE_EVAL` says (stays listed) |
|
|
291
311
|
| `NORACU_ALLOW_FILE_URL` | unset | `=1` allows `browser_navigate` to open `file://` |
|
|
292
312
|
| `NORACU_DISABLE_AUTO_INSTALL` | unset | `=1` skips Chromium auto-install on first `browser_launch` |
|
|
293
|
-
| `NORACU_CLICLICK` | `/opt/homebrew/bin/cliclick` | cliclick binary path |
|
|
313
|
+
| `NORACU_CLICLICK` | the first of `/opt/homebrew/bin/cliclick` and `/usr/local/bin/cliclick` that exists | cliclick binary path |
|
|
294
314
|
| `NORACU_PYTHON` | auto-probe | python3 for the bundled iPhone driver (must import pyobjc: Quartz, Vision, AppKit) |
|
|
295
315
|
| `NORACU_IMCTL_DIR` | bundled `imctl/` | override the driver location (development only) |
|
|
296
316
|
| `NORACU_PHONE_TIMEOUT_MS` | 30000 (45000 for `phone_open` / `phone_type`) | time limit for each iPhone-layer step, 1000–600000 ms (`imctl_timeout` on expiry) |
|
|
@@ -301,13 +321,16 @@ model — don't let it override the task.
|
|
|
301
321
|
| `NORACU_CHROME_TABS` | unset | `all`: with `chrome: true`, your other tabs are listed and can be selected, read and acted on (never closed) |
|
|
302
322
|
| `NORACU_CHROME_DIR` | `~/Library/Application Support/Google/Chrome` | profile folder whose `DevToolsActivePort` `chrome: true` reads |
|
|
303
323
|
| `NORACU_ALLOW_CDP` | unset | `=1` allows `mac_app` launch with `cdp_port` and `browser_launch` with `cdp_port` for ports opened by this `noracu` process (`=any` for external loopback ports; refused under `NORACU_READ_ONLY=1`) |
|
|
304
|
-
| `NORACU_TRACE` | unset | file path for a JSON-lines call log (`{ts, tool, args, ms, error, code}` — argument names/sizes and error code prefix only, never result or error text; opened `0600` with `O_NOFOLLOW`) |
|
|
305
|
-
| `NORACU_USER_IDLE_S` | `2` | seconds without the person's keyboard or mouse input before a Mac or iPhone Mirroring (`phone_*`) input tool acts (the `ios_*` tools do not wait: they do not use this Mac's keyboard or mouse)
|
|
324
|
+
| `NORACU_TRACE` | unset | file path for a JSON-lines call log (`{ts, tool, args, ms, error, code}` — argument names/sizes and error code prefix only, never result or error text; opened `0600` with `O_NOFOLLOW`; a call the client cancelled is logged with code `cancelled`, or `cancelled_queued` if it was still waiting in the input queue) |
|
|
325
|
+
| `NORACU_USER_IDLE_S` | `2` | seconds without the person's keyboard or mouse input before a Mac or iPhone Mirroring (`phone_*`) input tool acts (the `ios_*` tools do not wait: they do not use this Mac's keyboard or mouse); a call that comes sooner waits out the rest once and answers `user_active` if they are still using it; also puts the pointer back after pointer actions; `0` turns both off |
|
|
306
326
|
| `NORACU_NO_BGPOST` | unset | `=1` turns off background input (physical clicks and named keys use the real pointer and the HID key path) |
|
|
307
327
|
| `NORACU_STOP_FILE` | unset | file path: while it exists, every input tool — Mac, iPhone and the browser's input tools (navigate, click, type, fill, press_key, scroll, evaluate, `browser_tabs` new/close) — returns `user_stopped` and sends nothing; set but blank, it refuses all input |
|
|
308
328
|
| `NORACU_DENY_APPS` | the common terminal apps and IDEs with a built-in terminal | comma-separated bundle ids / app names (`*`, `?`) that never get input; a list of your own adds to the default, blank keeps the default, a list starting with `none` drops it |
|
|
309
|
-
| `NORACU_APPROVAL_FILE` | unset | `0600` JSON `{allow, ask, deny}` of bundle-id / app-name patterns, judged on the app that receives the input; `ask` or unlisted → `approval_required`; a broken file refuses all Mac and iPhone input (app rules do not judge the browser layer) |
|
|
329
|
+
| `NORACU_APPROVAL_FILE` | unset | `0600` JSON `{allow, ask, deny}` of bundle-id / app-name patterns, judged on the app that receives the input; `ask` or unlisted → `approval_required`; an `allow` entry that names an app exactly (its bundle id or name, no `*` or `?`) lets that app through the default deny list — `NORACU_DENY_APPS` entries still win; a broken file refuses all Mac and iPhone input (app rules do not judge the browser layer) |
|
|
310
330
|
| `NORACU_LAYERS` | unset (`mac,browser`) | comma-separated `mac`, `browser`, `iphone`: only those layers' tools are listed and callable (the experimental iPhone layer only when `iphone` is named); a call to a tool of a layer that is off says how to turn it on; a name that is not one of the three stops the server at start |
|
|
331
|
+
| `NORACU_PHONE_BACKEND` | `mirror` | with the iPhone layer on: `xcuitest` lists the nine `ios_*` tools (section 10) in place of `phone_*`; any other value falls back to `mirror` with a warning on stderr |
|
|
332
|
+
| `NORACU_IOS_UDID` | unset | XCUITest backend: the device (or booted simulator) to use; needed when several iPhones are connected (`device_ambiguous` lists them) |
|
|
333
|
+
| `NORACU_IOS_RUNNER_DIR` | `~/.noracu/ios-runner` | XCUITest backend: where `npx noracu ios-setup` builds the runner and where the server looks for it |
|
|
311
334
|
| `NORACU_CI` | unset | `=1` only affects `npm test` (skips hardware-gated checks) |
|
|
312
335
|
|
|
313
336
|
## 8. Error reference
|
|
@@ -327,7 +350,7 @@ model — don't let it override the task.
|
|
|
327
350
|
| `notification_not_found: …` | `mac_notifications` dismiss/act target id or index is no longer on screen or no longer matches `expected_app` / `expected_title` |
|
|
328
351
|
| `input_busy: …` | an earlier phone or Mac action held the input queue past its wait limit; nothing was sent — retry |
|
|
329
352
|
| `ax_timeout: …` | the target app did not answer accessibility calls in time (busy or hung) |
|
|
330
|
-
|
|
|
353
|
+
| `mac_screenshot` shows only the desktop picture, or is black | Screen Recording not granted to the host app |
|
|
331
354
|
| `ENOENT` cliclick | `brew install cliclick` or set `NORACU_CLICLICK` |
|
|
332
355
|
| `… blocked by NORACU_READ_ONLY=1` | you're in observation-only mode — unset it to act |
|
|
333
356
|
| `browser_evaluate disabled by NORACU_DISABLE_EVAL=1` | eval kill-switch is on |
|
|
@@ -337,6 +360,39 @@ model — don't let it override the task.
|
|
|
337
360
|
| `menu_unknown: …` | `phone_home` or `phone_app_switcher` menu command timed out (`delivery=unknown, retry=unsafe`) — inspect `phone_screenshot` before retrying |
|
|
338
361
|
| `imctl_timeout: …` | a phone step ran past its time limit and was stopped — check `phone_status` / `phone_screenshot` before retrying (after `phone_open`, noracu goes back to the Home Screen); raise `NORACU_PHONE_TIMEOUT_MS` on a slow Mac |
|
|
339
362
|
| `imctl unavailable: no python3 with pyobjc found …` | install pyobjc for a python3 (`python3 -m pip install pyobjc-framework-Quartz pyobjc-framework-Vision pyobjc-framework-Cocoa`) or set `NORACU_PYTHON` |
|
|
363
|
+
| `ax_empty: …` | the app has no window that accessibility can read from the desktop in view. The message says which case it is: the window server lists windows of the app off screen — on another Space, minimized, or the app is hidden (`mac_windows` with `include_offscreen: true` lists them; `mac_app` `activate` brings the app forward and may switch the person's desktop to it) — or the app has no window open. A window on another Space cannot be read |
|
|
364
|
+
| `ambiguous_app: …` | two or more running apps share that name or bundle id; nothing was done — name the one you mean as `pid:<number>` (the message and `mac_apps` list the pids) |
|
|
365
|
+
| `app_not_found: …` | no running app has that name or bundle id — `mac_apps` lists what runs; `mac_app` with `launch` starts one |
|
|
366
|
+
| `app_unresponsive: …` | the app did not answer accessibility in time (busy or hung) |
|
|
367
|
+
| `surface_absent: …` | the `surface` asked for is not there: no menu is open, or the app exposes no menu bar |
|
|
368
|
+
| `invalid_args: …` | an argument is missing, of the wrong type or out of range, or two that exclude each other were given; nothing was sent — the message names the argument |
|
|
369
|
+
| `action_not_supported: …` | the element does not support that action — for text: it takes text only by rewriting its whole value, or no key of the keyboard layout types a character; nothing was sent |
|
|
370
|
+
| `action_failed: …` | accessibility or cliclick reported an error for an action that may already have gone out — read `delivery` / `retry`, and observe before repeating |
|
|
371
|
+
| `activate_failed: …` | macOS did not bring the app forward |
|
|
372
|
+
| `ax_error: …` | the accessibility engine gave no readable answer — call again; if it stays, report it with the message |
|
|
373
|
+
| `display_unknown: …` | `mac_screenshot` named a display that is not there (`mac_windows` lists the displays), or the displays could not be read; nothing was captured |
|
|
374
|
+
| `no_window: …` | `mac_scroll` without `element_index`: the frontmost app has no window on screen — pass an `element_index` |
|
|
375
|
+
| `user_active: …` | the person used the keyboard or mouse in the last `NORACU_USER_IDLE_S` seconds (2 by default), and again while noracu waited out the rest of that time once; nothing was sent — call again once they have stopped |
|
|
376
|
+
| `user_stopped: …` | the file named by `NORACU_STOP_FILE` exists; no input is sent until the person removes it |
|
|
377
|
+
| `approval_required: …` | `NORACU_APPROVAL_FILE` lists the app under `ask` or not at all; nothing was sent, and it stays so until the person adds the app to `allow` |
|
|
378
|
+
| `approval_file_error` / `approval_file_insecure` / `approval_file_owner` / `stop_check_error` | `NORACU_APPROVAL_FILE` or `NORACU_STOP_FILE` is set but blank, cannot be read, is not mode `0600` or is not owned by this user — Mac and iPhone input is refused until the person fixes it (fail closed) |
|
|
379
|
+
| `internal_error: …` | an input tool failed in a way noracu did not plan for; what it had sent by then is not known (`delivery=unknown, retry=unsafe`) — observe before acting again, and report it with the message |
|
|
380
|
+
| `server_shutting_down: …` | the server is closing; nothing was done |
|
|
381
|
+
| `eval_disabled: …` | `browser_evaluate` is off by default — start the server with `NORACU_ENABLE_EVAL=1`; it never runs in your own Chrome (`chrome: true`) |
|
|
382
|
+
| `browser_installing: …` | the first `browser_launch` on this Mac: Playwright's Chromium is being downloaded, which can take minutes, so the call answered after 20 s while the download goes on — call `browser_launch` again in a minute (a download that failed is reported by that call) |
|
|
383
|
+
| `invalid_element_index: …` | the `element_index` is not in the last `browser_snapshot` — take a new one |
|
|
384
|
+
| `navigate_failed: …` | the navigation ended in an error after it had started (`delivery=unknown`) — `browser_snapshot` shows where the page is now |
|
|
385
|
+
| `tab_not_found` / `tab_is_last` / `tab_not_owned` / `tab_not_selectable` | `browser_tabs`: no open tab has that `tab_id` (list them again); the only open tab is not closed (`browser_close` ends the session); only a tab opened with `browser_tabs` is closed; only a tab on an http(s) page can be selected |
|
|
386
|
+
| `cdp_port_in_use` / `cdp_connect_failed` | the DevTools port is taken (pass another, or `0` for a free one), or nothing answers DevTools on it |
|
|
387
|
+
| `cdp_session_active` / `chrome_session_active` | a session attached to a DevTools port, or to your own Chrome, is open — `browser_close` it before launching the standalone browser |
|
|
388
|
+
| `chrome_disconnected: …` | the connection to your own Chrome ended; tabs noracu opened there may still be open, and noracu did not quit Chrome |
|
|
389
|
+
| `imctl_error: …` / `imctl_output_overflow: …` | the bundled iPhone driver failed, or printed more than 10 MB and was stopped — the step may have partly run; check `phone_status` / `phone_screenshot` before retrying |
|
|
390
|
+
| `expect_not_found: …` | the text given as `expect` is not on the phone's screen; nothing was sent |
|
|
391
|
+
| `out_of_screen: …` | the point is on the iPhone Mirroring window's margin, not on the phone's screen — or the screen's edges could not be told; nothing was sent |
|
|
392
|
+
| `spotlight_unavailable: …` | `phone_open` could not open Spotlight (the Home Screen was not reached, the menu command failed, or the screen did not change); the Home Screen command or the Spotlight gesture may have gone out — `phone_screenshot` before retrying |
|
|
393
|
+
| `scroll_no_effect: …` | the phone's screen did not change after the scroll (the end of the list, or nothing there scrolls) |
|
|
394
|
+
| `keyboard_layout: …` | no key of the Mac's keyboard layout types a character the step needs; nothing was sent |
|
|
395
|
+
| `capture_failed: …` | the iPhone Mirroring window (or, on the XCUITest backend, the phone) gave no image — no other kind of capture is used in its place |
|
|
340
396
|
|
|
341
397
|
## 9. iPhone layer
|
|
342
398
|
|
|
@@ -469,9 +525,15 @@ ios_home → Home Screen; earlier indexes end
|
|
|
469
525
|
| `runner_not_started` | `NORACU_READ_ONLY=1` is set: observation-only mode does not start the runner (starting it puts the runner's app in front on the iPhone) — unset it to read the screen |
|
|
470
526
|
| `xctest_issue` | XCTest reported a failure while the command ran, or after an earlier one had answered. The test session is ended either way and the next call starts a new one. For an input that may have gone out the delivery is unknown; a command that was not run says `delivery=not_delivered`. Look with `ios_snapshot` before acting again |
|
|
471
527
|
| `app_not_running` / `app_not_foreground` | the app is not in front — `ios_launch` it first; nothing was sent |
|
|
528
|
+
| `system_overlay` | the iPhone is showing something of its own over the app (Control Center pulled down, or the Home Screen while an app is still coming forward) while the app still reports that it is in front, so a tap would land on that instead — nothing was sent. Look again with `ios_snapshot` in a moment; if it is still there, `ios_home` closes it but leaves the app for the Home Screen (`ios_launch` brings the app back) |
|
|
472
529
|
| `no_keyboard` | no keyboard is up — tap a text field, or give `ios_type` an `element_index` |
|
|
473
530
|
| `type_not_confirmed` | the text was typed but the field that took it does not hold its old value with the text put in at one place (autocorrection or completion changed it, the field hides its value, part of the text was lost, or the text went to another field) — read the field before typing again |
|
|
474
531
|
| `launch_not_confirmed` | the app was started but is not in front after 10 s (a system prompt may cover it), or its state could not be read to the end of that wait — the result says which; `ios_screenshot` |
|
|
475
532
|
| `launch_failed` | `devicectl` / `simctl` refused (not installed, wrong bundle id) — nothing was sent |
|
|
476
533
|
| `ios_timeout` | the phone did not answer in time — delivery unknown, never re-sent; look before acting again |
|
|
477
534
|
| `runner_start_failed` / `runner_start_timeout` / `runner_version_mismatch` | the runner did not start (the message says why) — a version mismatch means the runner on the device was built by another noracu version (it names its build, and so does the message): run `ios-setup` again; `the runner that was stopped has not exited yet` means the last test session is still ending: try again in a moment |
|
|
535
|
+
| `runner_restarted` | the runner started during this call, which puts its own app in front — the screen the points or the focus were meant for is gone; nothing was sent, look again (`ios_snapshot`) before acting |
|
|
536
|
+
| `runner_unreachable` / `runner_busy` | the runner stopped or its connection closed (the next call that asks for the iPhone starts it), or another runner call is still in flight; nothing was sent |
|
|
537
|
+
| `device_not_ready` | the simulator is not booted, or the iPhone is not paired, has Developer Mode off, or has no tunnel to this Mac — the message says which |
|
|
538
|
+
| `devicectl_failed` / `devicectl_timeout` / `simctl_failed` / `simctl_timeout` | Xcode's device tool (`devicectl` for an iPhone, `simctl` for a simulator) failed or gave no answer in time — the message quotes it |
|
|
539
|
+
| `not_a_text_field` | `ios_type` was given an `element_index` that is not a text field; nothing was typed |
|
package/imctl/src/imctl/cli.py
CHANGED
|
@@ -34,7 +34,7 @@ import subprocess
|
|
|
34
34
|
|
|
35
35
|
from .window import WindowError, ensure_frontmost, get_overlay, get_window_info, is_frontmost
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
# Every phone input command starts in _require_live(), which probes
|
|
38
38
|
# get_overlay() first so a paused or stopped mirror refuses without stealing focus,
|
|
39
39
|
# then brings the mirror to the front (switching Spaces if needed and waiting for a
|
|
40
40
|
# real frame) before any capture or input. Module-level callables so tests can swap them.
|
|
@@ -53,7 +53,7 @@ _MIRROR_STATE_UNKNOWN_LINE = (
|
|
|
53
53
|
"nothing was sent; retry, or call phone_status"
|
|
54
54
|
)
|
|
55
55
|
|
|
56
|
-
#
|
|
56
|
+
# One line, one exit code for every capture failure. The pixels a check
|
|
57
57
|
# needed are not the phone's — report that, never guess from whatever
|
|
58
58
|
# another window happened to show inside the region.
|
|
59
59
|
_CAPTURE_FAILED_LINE = (
|
|
@@ -62,7 +62,7 @@ _CAPTURE_FAILED_LINE = (
|
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
#
|
|
65
|
+
# The same failure while checking --expect, before the first event
|
|
66
66
|
_CAPTURE_FAILED_EXPECT_LINE = (
|
|
67
67
|
"capture_failed: could not capture the iPhone Mirroring window to check --expect "
|
|
68
68
|
"(it may be hidden, minimized or on another Space); no image was returned, so nothing was sent"
|
|
@@ -76,8 +76,33 @@ _CAPTURE_FAILED_EDGES_LINE = (
|
|
|
76
76
|
)
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
# The Mac's clipboard was not put back to what it held before the paste. input.restore_failure() says which
|
|
80
|
+
# case it was: the clipboard was cleared and refused the write, or it was never touched because what it held
|
|
81
|
+
# could not be saved (another device's clipboard, or too large) — then it still holds the typed text.
|
|
82
|
+
def _clipboard_not_back(reason) -> str:
|
|
83
|
+
if reason == "kept_text":
|
|
84
|
+
return ("the Mac's clipboard was not put back: what it held before could not be saved (it came from "
|
|
85
|
+
"another device, or was too large), so it still holds the typed text")
|
|
86
|
+
return "the Mac's clipboard could not be put back to what it held before — it may be empty now"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _restore_note(exc) -> str:
|
|
90
|
+
"""'; <what the clipboard holds>' when an error carries a restore that failed, else ''."""
|
|
91
|
+
reason = getattr(exc, "restore_failed", None)
|
|
92
|
+
return f"; {_clipboard_not_back(reason)}" if reason else ""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# phone_open's capture failed after it had started: the Home Screen command and Spotlight (and maybe the name and a tap)
|
|
96
|
+
# had gone out before it, and Spotlight may still be open — the bare capture line said none of that
|
|
97
|
+
_OPEN_CAPTURE_FAILED_LINE = (
|
|
98
|
+
"capture_failed: could not capture the iPhone Mirroring window partway through phone_open (it may be hidden, "
|
|
99
|
+
"minimized or on another Space) — the steps before it may have gone out (the Home Screen command, Spotlight, "
|
|
100
|
+
"the name, a tap), and Spotlight may still be open; check phone_screenshot before retrying"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
79
104
|
def _capture_failed() -> int:
|
|
80
|
-
"""Print the
|
|
105
|
+
"""Print the capture-failure line; exit code 7."""
|
|
81
106
|
print(_CAPTURE_FAILED_LINE, file=sys.stderr)
|
|
82
107
|
return 7
|
|
83
108
|
|
|
@@ -133,7 +158,7 @@ def _refuse_off_screen(x: float, y: float, *, measure: bool) -> int | None:
|
|
|
133
158
|
return None # nothing remembered: decided once the mirror is live and in front
|
|
134
159
|
elif not wi:
|
|
135
160
|
# the live check has just seen the window and now there is no record of it: nothing says where the
|
|
136
|
-
# phone screen is, and without the window's size the bands cannot be measured
|
|
161
|
+
# phone screen is, and without the window's size the bands cannot be measured
|
|
137
162
|
raise WindowError("iPhone Mirroring window not found")
|
|
138
163
|
else:
|
|
139
164
|
rect, how = _phone_screen(retry_untrusted=False)
|
|
@@ -197,7 +222,7 @@ def _require_live() -> int | None:
|
|
|
197
222
|
Probes get_overlay() first to avoid stealing focus when the mirror is paused or off:
|
|
198
223
|
- reason in ("not_running", "no_window") -> mirror_not_live (exit 3), no _bring_front
|
|
199
224
|
- live is False -> mirror_not_live (exit 3), no _bring_front
|
|
200
|
-
- live is True -> _bring_front()
|
|
225
|
+
- live is True -> _bring_front(), then allow (None)
|
|
201
226
|
- live is None -> _bring_front(), sleep(0.4), probe again:
|
|
202
227
|
True -> allow; False -> mirror_not_live; still None -> mirror_state_unknown (exit 3).
|
|
203
228
|
"""
|
|
@@ -208,7 +233,7 @@ def _require_live() -> int | None:
|
|
|
208
233
|
if overlay["live"] is False:
|
|
209
234
|
return _mirror_not_live(overlay)
|
|
210
235
|
if overlay["live"] is True:
|
|
211
|
-
#
|
|
236
|
+
# Bringing it forward can take a Space switch; the mirror may stop being live meanwhile
|
|
212
237
|
# (the iPhone was picked up) — so when it was not in front, look again afterwards
|
|
213
238
|
try:
|
|
214
239
|
was_front = _is_front()
|
|
@@ -222,6 +247,10 @@ def _require_live() -> int | None:
|
|
|
222
247
|
if was_front:
|
|
223
248
|
return None
|
|
224
249
|
overlay = get_overlay()
|
|
250
|
+
# it quit meanwhile (or its window went): say that, as when it was not running to begin with
|
|
251
|
+
if overlay.get("reason") in ("not_running", "no_window"):
|
|
252
|
+
print(_MIRROR_NOT_RUNNING_LINE, file=sys.stderr)
|
|
253
|
+
return 3
|
|
225
254
|
if overlay["live"] is True:
|
|
226
255
|
return None
|
|
227
256
|
if overlay["live"] is False:
|
|
@@ -275,12 +304,12 @@ def _require_expect(args, read_screen=None, read_sweep=None) -> int | None:
|
|
|
275
304
|
hits = read_screen()
|
|
276
305
|
if (read_sweep is not None and verify.is_short_text(expect)
|
|
277
306
|
and not verify.screen_contains(expect, hits)):
|
|
278
|
-
#
|
|
307
|
+
# A one- or two-character anchor (the app "X") can be invisible
|
|
279
308
|
# to the default OCR pass; read again with the sweep before refusing.
|
|
280
309
|
hits = read_sweep()
|
|
281
310
|
except (WindowError, CaptureError):
|
|
282
|
-
#
|
|
283
|
-
# expect_not_found; nothing is sent (
|
|
311
|
+
# An unreadable screen is not a match — refuse exactly like
|
|
312
|
+
# expect_not_found; nothing is sent (and the line says so).
|
|
284
313
|
print(_CAPTURE_FAILED_EXPECT_LINE, file=sys.stderr)
|
|
285
314
|
return 7
|
|
286
315
|
if verify.screen_contains(expect, hits):
|
|
@@ -334,7 +363,7 @@ def _invalid_duration(exc: ValueError) -> int:
|
|
|
334
363
|
|
|
335
364
|
|
|
336
365
|
def _cmd_longpress(args) -> int:
|
|
337
|
-
#
|
|
366
|
+
# A bad duration is refused before the mirror is brought forward
|
|
338
367
|
try:
|
|
339
368
|
input._check_duration(_longpress_duration(args), 0.01, 10, "long-press duration (s)")
|
|
340
369
|
except ValueError as exc:
|
|
@@ -389,7 +418,7 @@ def _cmd_swipe(args) -> int:
|
|
|
389
418
|
except (WindowError, CaptureError):
|
|
390
419
|
wi = None
|
|
391
420
|
if not wi:
|
|
392
|
-
# the window was there for the measurement and has no record now: nothing is sent
|
|
421
|
+
# the window was there for the measurement and has no record now: nothing is sent
|
|
393
422
|
print(_CAPTURE_FAILED_EDGES_LINE, file=sys.stderr)
|
|
394
423
|
return 7
|
|
395
424
|
safe = screenrect.fallback(wi["w"], wi["h"])
|
|
@@ -399,14 +428,14 @@ def _cmd_swipe(args) -> int:
|
|
|
399
428
|
return 2
|
|
400
429
|
fx, fy = input.clamp_to_rect(args.fx, args.fy, safe, inset=0.0)
|
|
401
430
|
tx, ty = input.clamp_to_rect(args.tx, args.ty, safe, inset=0.0)
|
|
402
|
-
if _collapsed(asked, (fx, fy, tx, ty)):
|
|
431
|
+
if _collapsed(asked, (fx, fy, tx, ty), (float(wi["w"]), float(wi["h"]))):
|
|
403
432
|
return _refuse_collapsed(asked)
|
|
404
433
|
input.swipe(fx, fy, tx, ty, args.ms)
|
|
405
434
|
print(_swipe_line(asked, (fx, fy, tx, ty), safe, known=False))
|
|
406
435
|
return 0
|
|
407
436
|
fx, fy = input.clamp_to_rect(args.fx, args.fy, rect)
|
|
408
437
|
tx, ty = input.clamp_to_rect(args.tx, args.ty, rect)
|
|
409
|
-
if _collapsed(asked, (fx, fy, tx, ty)):
|
|
438
|
+
if _collapsed(asked, (fx, fy, tx, ty), _window_size_pt()):
|
|
410
439
|
return _refuse_collapsed(asked)
|
|
411
440
|
input.swipe(fx, fy, tx, ty, args.ms)
|
|
412
441
|
print(_swipe_line(asked, (fx, fy, tx, ty), rect))
|
|
@@ -418,13 +447,14 @@ def _num(v: float) -> str:
|
|
|
418
447
|
|
|
419
448
|
|
|
420
449
|
# A swipe whose points were moved clear of the margin and that is left shorter than this (in points of the
|
|
421
|
-
#
|
|
422
|
-
#
|
|
450
|
+
# mirror window as it is now) is refused: iOS starts a pan only after about 10 pt, so a shorter drag lands as a
|
|
451
|
+
# tap or press on whatever is under it. _REF_WINDOW_PT (the 280x620 pt window measured on 2026-11-10) stands in
|
|
452
|
+
# only when the window's size cannot be read.
|
|
423
453
|
_MIN_MOVED_SWIPE_PT = 10.0
|
|
424
454
|
_REF_WINDOW_PT = (280.0, 620.0)
|
|
425
455
|
|
|
426
456
|
|
|
427
|
-
def _collapsed(asked, sent) -> bool:
|
|
457
|
+
def _collapsed(asked, sent, size_pt=None) -> bool:
|
|
428
458
|
"""True when moving a point clear of the margin left the swipe too short to be a swipe: a press, not a
|
|
429
459
|
swipe — whatever length it was asked for with (a pull-down from the margin that ends just inside the
|
|
430
460
|
screen would otherwise go out as a tap at the top of the app). That covers a swipe whose two ends read
|
|
@@ -434,10 +464,19 @@ def _collapsed(asked, sent) -> bool:
|
|
|
434
464
|
return False
|
|
435
465
|
if (_num(sent[0]), _num(sent[1])) == (_num(sent[2]), _num(sent[3])):
|
|
436
466
|
return True
|
|
437
|
-
w, h = _REF_WINDOW_PT
|
|
467
|
+
w, h = size_pt if size_pt and size_pt[0] > 0 and size_pt[1] > 0 else _REF_WINDOW_PT
|
|
438
468
|
return math.hypot((sent[2] - sent[0]) * w, (sent[3] - sent[1]) * h) < _MIN_MOVED_SWIPE_PT
|
|
439
469
|
|
|
440
470
|
|
|
471
|
+
def _window_size_pt():
|
|
472
|
+
"""The mirror window's size in points as it is now, or None when it cannot be read."""
|
|
473
|
+
try:
|
|
474
|
+
wi = _window_info()
|
|
475
|
+
except (WindowError, CaptureError):
|
|
476
|
+
return None
|
|
477
|
+
return (float(wi["w"]), float(wi["h"])) if wi and wi.get("w") and wi.get("h") else None
|
|
478
|
+
|
|
479
|
+
|
|
441
480
|
def _refuse_collapsed(asked) -> int:
|
|
442
481
|
print(
|
|
443
482
|
f"out_of_screen: the swipe from ({_num(asked[0])},{_num(asked[1])}) to ({_num(asked[2])},{_num(asked[3])}) "
|
|
@@ -545,25 +584,29 @@ def _cmd_type(args) -> int:
|
|
|
545
584
|
report = {}
|
|
546
585
|
try:
|
|
547
586
|
typed_ok = input.type_text(args.text, replace=args.replace, report=report)
|
|
548
|
-
except input.PasteFocusLost:
|
|
587
|
+
except input.PasteFocusLost as exc:
|
|
549
588
|
# 0.2.7: another app came to the front during the wait after the clipboard write;
|
|
550
589
|
# ⌘V was called off rather than pulling iPhone Mirroring back to the front
|
|
590
|
+
clip = (_clipboard_not_back(exc.restore_failed) if getattr(exc, "restore_failed", False)
|
|
591
|
+
else "the clipboard was put back unless something else had copied meanwhile")
|
|
551
592
|
sent = ("the select-all (⌘A) for replace was sent, but nothing was pasted" if args.replace
|
|
552
593
|
else "nothing was sent")
|
|
553
594
|
print("focus_lost: another app came to the front before ⌘V, so iPhone Mirroring was not "
|
|
554
|
-
f"brought back and the paste was called off — {sent};
|
|
555
|
-
"unless something else had copied meanwhile", file=sys.stderr)
|
|
595
|
+
f"brought back and the paste was called off — {sent}; {clip}", file=sys.stderr)
|
|
556
596
|
return 6
|
|
557
597
|
if typed_ok:
|
|
558
598
|
if report.get("seen", True):
|
|
559
599
|
if _late_paste_probe(args.text) is None:
|
|
560
|
-
# 0.2.5
|
|
561
|
-
# and
|
|
600
|
+
# 0.2.5: one character that OCR saw appear is no proof of where it went,
|
|
601
|
+
# and no license to put the clipboard back
|
|
562
602
|
print(f"typed {len(args.text)} chars (one character: OCR saw it appear, which is no "
|
|
563
603
|
"proof of where it landed — check the field, which may hold the phone's own older "
|
|
564
604
|
"clipboard instead; the clipboard still holds the typed text)")
|
|
565
605
|
return 0
|
|
566
606
|
print(f"typed {len(args.text)} chars")
|
|
607
|
+
if report.get("restore_failed"):
|
|
608
|
+
# a line of its own: the first line stays the confirmed result
|
|
609
|
+
print(f"note: {_clipboard_not_back(report['restore_failed'])}")
|
|
567
610
|
return 0
|
|
568
611
|
if _late_paste_probe(args.text) is None:
|
|
569
612
|
# one character: OCR cannot read it back, only the picture changed
|
|
@@ -571,7 +614,7 @@ def _cmd_type(args) -> int:
|
|
|
571
614
|
"OCR cannot read this text back — check the field, which may hold the phone's own "
|
|
572
615
|
"older clipboard instead; the clipboard still holds the typed text)")
|
|
573
616
|
return 0
|
|
574
|
-
#
|
|
617
|
+
# the screen changed and OCR could not confirm the text for a reason
|
|
575
618
|
# known now — say that one, instead of watching for a late paste that would only
|
|
576
619
|
# report a rise it cannot attribute
|
|
577
620
|
cause = report.get("unverifiable")
|
|
@@ -593,26 +636,28 @@ def _cmd_type(args) -> int:
|
|
|
593
636
|
count_before = report.get("count_before")
|
|
594
637
|
late = _watch_late_paste(args.text, baseline=count_before)
|
|
595
638
|
if late is not None:
|
|
596
|
-
#
|
|
639
|
+
# The text showed up late — report it so the caller reads the field before
|
|
597
640
|
# retyping. The clipboard is deliberately NOT restored here: type_text()
|
|
598
641
|
# restores only under its own checks (a rise seen inside its window, the
|
|
599
642
|
# minimum hold, an untouched changeCount); after the fact, leaving the
|
|
600
643
|
# typed text on the clipboard is the choice that can never hand the phone
|
|
601
644
|
# the user's original clipboard (possibly a password).
|
|
602
|
-
#
|
|
645
|
+
# Device run 2026-11-07: a second paste of the same text into the Settings search
|
|
603
646
|
# field was "seen late" while the field still showed the text once — a line repeating
|
|
604
647
|
# the query can rise too — so the wording claims no landing (the server reports it
|
|
605
|
-
# delivered_unverified
|
|
648
|
+
# delivered_unverified).
|
|
606
649
|
print(f"typed {len(args.text)} chars (the text showed up late, during an extra "
|
|
607
650
|
f"{late:.0f}s check after the 2.5s confirmation window — OCR cannot tell whether "
|
|
608
651
|
"that is the paste or a line repeating it, such as a search result: check the "
|
|
609
652
|
"field before typing again; the clipboard still holds the typed text)")
|
|
610
653
|
return 0
|
|
654
|
+
probe = _late_paste_probe(args.text)
|
|
611
655
|
watched = (f" or a further {LATE_PASTE_WATCH_S:.0f}s check"
|
|
612
|
-
if
|
|
613
|
-
" (
|
|
656
|
+
if probe and len(probe) >= verify.VERIFY_MIN_PROBE else
|
|
657
|
+
" (a text of fewer than four characters, spaces and case aside, cannot be confirmed by OCR "
|
|
658
|
+
"afterwards)")
|
|
614
659
|
if args.replace and count_before:
|
|
615
|
-
#
|
|
660
|
+
# The text was on screen before the paste, and a field replaced with
|
|
616
661
|
# the same text shows no change at all
|
|
617
662
|
advice = ("the text was already on screen before this paste, and replacing a "
|
|
618
663
|
"field with the same text shows no change — read the screen "
|
|
@@ -633,11 +678,11 @@ def _cmd_type(args) -> int:
|
|
|
633
678
|
return 4
|
|
634
679
|
|
|
635
680
|
|
|
636
|
-
#
|
|
681
|
+
# 2026-11-05 real-device: a paste reported unconfirmed after 2.5 s showed up a
|
|
637
682
|
# few seconds later, and the caller's retry typed the text twice ("… case … case").
|
|
638
683
|
# Before type_not_confirmed, keep watching — read-only, no second Cmd+V — for up to
|
|
639
684
|
# this long.
|
|
640
|
-
#
|
|
685
|
+
# On the device a paste reached the phone up to more than 10 s after Cmd+V.
|
|
641
686
|
LATE_PASTE_WATCH_S = 15.0 # needs two consecutive sightings ~1 s apart
|
|
642
687
|
|
|
643
688
|
|
|
@@ -651,19 +696,21 @@ def _watch_late_paste(text, *, baseline=None, read_screen=None, sleep=time.sleep
|
|
|
651
696
|
"""Seconds into the watch until ``text`` showed up on screen, or None.
|
|
652
697
|
|
|
653
698
|
Read-only: it never pastes again. ``baseline`` is type_text()'s pre-paste
|
|
654
|
-
count of the text's probe
|
|
699
|
+
count of the text's probe; the paste counts as arrived once the count
|
|
655
700
|
is above it in TWO consecutive readable frames (one OCR misread is not
|
|
656
701
|
enough). Without a baseline (type_text() could not read the screen before
|
|
657
702
|
the paste) the watch's own first two readable frames set it — the higher
|
|
658
703
|
count, as in type_text(): text already on screen elsewhere is then never
|
|
659
704
|
taken for the paste, at the price of missing a paste that landed before
|
|
660
705
|
those frames (reported unconfirmed — the caller is told to read the
|
|
661
|
-
screen before typing again). Text too short for a probe
|
|
662
|
-
|
|
663
|
-
|
|
706
|
+
screen before typing again). Text too short for a probe, or of fewer
|
|
707
|
+
than verify.VERIFY_MIN_PROBE characters (never confirmed by a sighting:
|
|
708
|
+
"in" is part of "Sign in"), is not watched at all (None at once). A capture failure breaks the run of
|
|
709
|
+
sightings, never counts as one. ``read_screen``, ``sleep`` and
|
|
664
710
|
``clock`` are injectable for tests.
|
|
665
711
|
"""
|
|
666
|
-
|
|
712
|
+
probe = _late_paste_probe(text)
|
|
713
|
+
if probe is None or len(probe) < verify.VERIFY_MIN_PROBE:
|
|
667
714
|
return None
|
|
668
715
|
if read_screen is None:
|
|
669
716
|
read_screen = vision.read_screen
|
|
@@ -786,9 +833,9 @@ def _confidence_note(report: dict) -> str:
|
|
|
786
833
|
def _open_and_report(args) -> int:
|
|
787
834
|
tidy = {} # open_app records whether its trip back to the Home Screen worked
|
|
788
835
|
try:
|
|
789
|
-
#
|
|
836
|
+
# One retry — on the device the Spotlight command was once
|
|
790
837
|
# ignored right after an app closed. Each try goes Home first; when Home
|
|
791
|
-
# lands back in Spotlight (iOS 27
|
|
838
|
+
# lands back in Spotlight (iOS 27) the gate reports it open instead
|
|
792
839
|
# of toggling it shut.
|
|
793
840
|
if not (gestures.open_spotlight_checked()
|
|
794
841
|
or gestures.open_spotlight_checked()):
|
|
@@ -797,10 +844,15 @@ def _open_and_report(args) -> int:
|
|
|
797
844
|
result = gestures.open_app(args.app, spotlight_open=True, report=tidy,
|
|
798
845
|
**_open_deadline_kwargs())
|
|
799
846
|
except (WindowError, CaptureError):
|
|
800
|
-
#
|
|
847
|
+
# The Spotlight gate and the result matching both read the
|
|
801
848
|
# mirroring window's pixels; without them nothing about the
|
|
802
|
-
# phone is known — refuse rather than guess.
|
|
803
|
-
|
|
849
|
+
# phone is known — refuse rather than guess. A paste called off by it put the clipboard back, or says
|
|
850
|
+
# that it could not.
|
|
851
|
+
if tidy.get("restore_failed"):
|
|
852
|
+
print(f"{_OPEN_CAPTURE_FAILED_LINE}; {_clipboard_not_back(tidy['restore_failed'])}", file=sys.stderr)
|
|
853
|
+
return 7
|
|
854
|
+
print(_OPEN_CAPTURE_FAILED_LINE, file=sys.stderr)
|
|
855
|
+
return 7
|
|
804
856
|
if result == "opened":
|
|
805
857
|
print(f"opened {args.app!r}{_confidence_note(tidy)}")
|
|
806
858
|
return 0
|
|
@@ -838,6 +890,10 @@ def _open_and_report(args) -> int:
|
|
|
838
890
|
f"spot, so nothing was tapped; {home_note} — open it from its Home Screen icon "
|
|
839
891
|
"instead (phone_screenshot, then phone_tap)", file=sys.stderr)
|
|
840
892
|
return 4
|
|
893
|
+
if result == "gone":
|
|
894
|
+
print(f"open_not_confirmed: Spotlight's Top Hit card showed {args.app!r}, then no longer did "
|
|
895
|
+
f"when it was read again, so nothing was tapped; {home_note} — try again", file=sys.stderr)
|
|
896
|
+
return 4
|
|
841
897
|
if result == "low_confidence":
|
|
842
898
|
print(f"open_not_confirmed: Spotlight showed {args.app!r} but the label was read with "
|
|
843
899
|
f"confidence {_fmt_confidence(tidy.get('confidence'))}, below "
|
|
@@ -865,8 +921,10 @@ def _open_and_report(args) -> int:
|
|
|
865
921
|
# Home either — that would pull iPhone Mirroring forward again
|
|
866
922
|
print(f"focus_lost: another app came to the front before ⌘V, so iPhone Mirroring was not "
|
|
867
923
|
f"brought back and {args.app!r} was not pasted or tapped — Spotlight was opened and "
|
|
868
|
-
"cleared on the phone and may still be open;
|
|
869
|
-
"
|
|
924
|
+
"cleared on the phone and may still be open; "
|
|
925
|
+
+ (_clipboard_not_back(tidy["restore_failed"]) if tidy.get("restore_failed")
|
|
926
|
+
else "the clipboard was put back unless something else had copied meanwhile")
|
|
927
|
+
+ "; retry phone_open", file=sys.stderr)
|
|
870
928
|
return 6
|
|
871
929
|
if result == "clipboard_changed":
|
|
872
930
|
print(f"open_not_confirmed: another app or device changed the clipboard before ⌘V, so "
|
|
@@ -874,9 +932,12 @@ def _open_and_report(args) -> int:
|
|
|
874
932
|
f"{home_note}; retry phone_open", file=sys.stderr)
|
|
875
933
|
return 4
|
|
876
934
|
if result == "spotlight_unavailable":
|
|
877
|
-
|
|
935
|
+
# on stderr with its code, like every other refusal: on stdout it was lost when stderr held a warning
|
|
936
|
+
print("spotlight_unavailable: could not open Spotlight on the phone (could not reach the Home Screen, the menu "
|
|
937
|
+
"command failed, or the screen did not change) — the Home Screen command or the Spotlight gesture may "
|
|
938
|
+
"have gone out; check phone_screenshot before retrying", file=sys.stderr)
|
|
878
939
|
return 1
|
|
879
|
-
# "not_confirmed"
|
|
940
|
+
# "not_confirmed": the row — and possibly the Top Hit icon —
|
|
880
941
|
# was tapped but the app never verifiably opened; the phone is
|
|
881
942
|
# back on the Home Screen.
|
|
882
943
|
print(f"open_not_confirmed: tapped {args.app!r} in Spotlight{_confidence_note(tidy)} but the app did not open; {home_note}", file=sys.stderr)
|
|
@@ -904,11 +965,11 @@ def _cmd_verify(args) -> int:
|
|
|
904
965
|
def _cmd_launch(_args) -> int:
|
|
905
966
|
live = gestures.launch()
|
|
906
967
|
if live is False:
|
|
907
|
-
#
|
|
968
|
+
# Never report "ready" while the overlay is still up.
|
|
908
969
|
from .window import is_setup_screen
|
|
909
970
|
|
|
910
971
|
if is_setup_screen():
|
|
911
|
-
#
|
|
972
|
+
# A welcome / setup screen is the user's to finish; nothing was clicked.
|
|
912
973
|
print(
|
|
913
974
|
"mirror_setup_required: iPhone Mirroring is showing a setup or welcome "
|
|
914
975
|
"screen (its window is not phone-shaped) — finish it in the iPhone "
|
|
@@ -1068,23 +1129,24 @@ def _run(args) -> int:
|
|
|
1068
1129
|
try:
|
|
1069
1130
|
return args.func(args)
|
|
1070
1131
|
except input.KeyboardLayoutMismatch as exc:
|
|
1071
|
-
#
|
|
1132
|
+
# raised before any event was posted or the clipboard was written
|
|
1072
1133
|
print(f"keyboard_layout: {exc}", file=sys.stderr)
|
|
1073
1134
|
return 2
|
|
1074
|
-
except input.FocusLost:
|
|
1075
|
-
#
|
|
1135
|
+
except input.FocusLost as exc:
|
|
1136
|
+
# The frontmost check failed right before an event — either
|
|
1076
1137
|
# nothing was sent at all, or (mid-scroll) nothing further was.
|
|
1077
1138
|
print(
|
|
1078
1139
|
"focus_lost: iPhone Mirroring is not the frontmost app; "
|
|
1079
|
-
"nothing (or nothing further) was sent",
|
|
1140
|
+
f"nothing (or nothing further) was sent{_restore_note(exc)}",
|
|
1080
1141
|
file=sys.stderr,
|
|
1081
1142
|
)
|
|
1082
1143
|
return 6
|
|
1083
1144
|
except WindowError as exc:
|
|
1084
|
-
|
|
1145
|
+
# a paste called off before ⌘V put the clipboard back — or says here that it could not
|
|
1146
|
+
print(f"window error: {exc}{_restore_note(exc)}", file=sys.stderr)
|
|
1085
1147
|
return 3
|
|
1086
1148
|
except input.InputError as exc:
|
|
1087
|
-
print(f"input error: {exc}", file=sys.stderr)
|
|
1149
|
+
print(f"input error: {exc}{_restore_note(exc)}", file=sys.stderr)
|
|
1088
1150
|
return 4
|
|
1089
1151
|
|
|
1090
1152
|
|