noracu 0.1.3 → 0.2.0

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/docs/usage.md CHANGED
@@ -8,23 +8,28 @@ Tool schemas (every argument) live in [tools.md](tools.md); this guide is about
8
8
  the *flow*.
9
9
 
10
10
  > If you set `NORACU_READ_ONLY=1`, the action steps below (`mac_click`,
11
- > `mac_type`, `browser_click`, …) are refused — that mode allows only the 12
12
- > observe + browser-lifecycle tools. Unset it to run the full loop.
11
+ > `mac_type`, `browser_click`, …) are refused, along with `mac_clipboard_read`,
12
+ > `mac_notifications`, and `mac_wait` on `condition: "notification"` — that mode
13
+ > allows only the 18 observe + browser-lifecycle tools (and skips toggling
14
+ > `web_accessibility` on apps). Unset it to run the full loop.
13
15
 
14
16
  ## 1. The core pattern: observe, then act by `element_index`
15
17
 
16
18
  Every layer uses the same two-step loop:
17
19
 
18
- 1. **Observe** — `mac_ax_state` (macOS accessibility tree) or `browser_snapshot`
19
- (browser ARIA tree). Both return a compact, **indexed** list of interactive
20
- elements as text — not a screenshot.
20
+ 1. **Observe** — `mac_ax_state` (macOS accessibility tree; `mac_find` when you
21
+ know what you are looking for) or `browser_snapshot` (browser ARIA tree).
22
+ Both return a compact, **indexed** list of elements as text — not a
23
+ screenshot.
21
24
  2. **Act** — `mac_click` / `browser_click` referencing an `element_index` from
22
25
  the latest observation.
23
26
 
24
27
  Three things to internalize:
25
28
 
26
- - An `element_index` is **not** a stable id and **not** a pixel coordinate. It
27
- is a position in the *most recent* snapshot of *that layer*.
29
+ - An `element_index` is **not** a pixel coordinate. On the Mac it is unique for
30
+ the life of the server — every snapshot continues the same counter, so an index
31
+ never names an element of a later snapshot. In the browser it is a position in
32
+ the most recent `browser_snapshot`.
28
33
  - Indices have a **30-second TTL**. After that, acting on one returns
29
34
  `element_no_longer_valid` — re-observe and use a fresh index.
30
35
  - Acting re-verifies the target before firing. A mismatch is reported as a
@@ -36,40 +41,79 @@ the tree doesn't carry what you need (canvas, custom-drawn UI, visual layout).
36
41
 
37
42
  ## 2. Mac layer walkthrough
38
43
 
39
- Bring the target app to the front (here, Finder), then observe:
44
+ Observe the app (the frontmost one when `app` is omitted). `interactive: true`
45
+ keeps only what can be acted on:
40
46
 
41
47
  ```
42
- mac_ax_state {}
48
+ mac_ax_state { "app": "TextEdit", "interactive": true }
43
49
  ```
44
50
 
45
- Returns an indexed tree, roughly:
51
+ ```json
52
+ {"app":"TextEdit","pid":9373,"snapshot_id":"s4","surface":"window",
53
+ "window":{"title":"notes","frame":[309,103,586,488],"window_id":25647},
54
+ "complete":true,"truncated":false,"elements":[
55
+ {"i":1,"d":2,"role":"AXTextArea","value":"line one","states":["focused"],"actions":["showmenu"],"frame":[309,203,586,382]},
56
+ {"i":3,"d":2,"role":"AXCheckBox","subrole":"AXSegment","title":"bold","value":0,"actions":["press"],"frame":[317,144,22,20]},
57
+ {"i":18,"d":2,"role":"AXPopUpButton","title":"line spacing","value":"1.0","actions":["showmenu","press"],"frame":[...]}]}
58
+ ```
59
+
60
+ `i` is the `element_index`, `d` the depth. Act while it is fresh (< 30 s):
61
+
62
+ ```
63
+ mac_click { "element_index": 3 }
64
+ → clicked element_index 3 (AXCheckBox "bold") via semantic AXPress — delivery=delivered_verified, retry=unsafe (changed: value)
65
+ ```
66
+
67
+ The element was pressed through accessibility: no pointer movement, no focus
68
+ change. An element without such an action (a text area) gets a physical click,
69
+ but only after a hit test:
70
+
71
+ ```
72
+ mac_click { "element_index": 1 }
73
+ → clicked left x1 on element_index 1 (AXTextArea) @ 602,394 via physical click — delivery=delivered_verified, retry=unsafe (changed: selection)
74
+ mac_click { "element_index": 1 } # a sheet now covers the text area
75
+ → occluded: something else is on top of the element at 602,394 … — on top: {"role":"AXStaticText","app":"TextEdit"} (delivery=not_delivered, retry=safe)
76
+ ```
77
+
78
+ **Read `delivery` and `retry`.** Every input action (Mac, browser and iPhone)
79
+ states both. `delivered_verified`: a change was observed.
80
+ `delivered_unverified`: the call succeeded but nothing observable changed — read
81
+ the state (`mac_get`, `mac_ax_state`) before acting again. `not_delivered` with
82
+ `retry=safe`: nothing was sent. `unknown` with `retry=unsafe`: the call timed
83
+ out or failed mid-action — inspect the state first. Only repeat an action when
84
+ `retry=safe`.
85
+
86
+ Set values by role instead of clicking around (`AXSecureTextField` returns
87
+ `(secure field — value not shown)` and never echoes the value):
46
88
 
47
89
  ```
48
- [0] AXWindow "Downloads"
49
- [1] AXButton "Back"
50
- [2] AXButton "Forward"
51
- ...
52
- [7] AXButton "New Folder"
53
- [8] AXTextField "Search"
90
+ mac_set_value { "element_index": 3, "value": "true" } # checkbox: nothing is sent if already on
91
+ mac_set_value { "element_index": 18, "value": "1.5" } # pop-up: opens it, picks the one matching option
92
+ mac_type { "element_index": 1, "text": "你好 noracu" } # inserted at the caret, IME-safe, clipboard untouched
93
+ mac_get { "element_index": 1 } # full value, states, settable attributes
54
94
  ```
55
95
 
56
- Act on an index while it is fresh (< 30 s):
96
+ When the window closed or the element changed:
57
97
 
58
98
  ```
59
- mac_click { "element_index": 7 }
60
- → clicked left x1 @ 812,64 (element_index) (frontmost after click: Finder)
99
+ mac_click { "element_index": 3 }
100
+ → element_no_longer_valid: the element's window is gone (STALE_REF/window_absent) — re-run mac_ax_state (delivery=not_delivered, retry=safe)
61
101
  ```
62
102
 
63
- If more than 30 s passed, or the frontmost app changed since the snapshot:
103
+ Dense apps (Electron, Slack, VS Code): map shallowly, then drill into one region —
104
+ the drill extends the same snapshot:
64
105
 
65
106
  ```
66
- mac_click { "element_index": 7 }
67
- → element_no_longer_valid: element_index is from "Finder" but "Safari" is frontmost now — re-run mac_ax_state
107
+ mac_ax_state { "app": "Slack", "skeleton": true, "interactive": true } # branches show children_count
108
+ mac_ax_state { "root": 12 } # only that subtree
109
+ mac_find { "app": "Slack", "role": "button", "title": "Send", "exact": true }
68
110
  ```
69
111
 
70
- Re-run `mac_ax_state` and use the new index. `mac_click` also accepts raw
71
- `{ "x": .., "y": .. }` coordinates when you have them, but prefer indices.
72
- Requires `cliclick` and `NORACU_READ_ONLY` unset.
112
+ Several windows and none focused gives `ambiguous_window` with the list; pass
113
+ `window` (index or title) or `window_id` from `mac_windows`. `surface` reads an
114
+ open `menu`, `menubar`, `sheet`, `alert`, `dialog`, `popover` or the `focused`
115
+ element only. `mac_click` also accepts raw `{ "x": .., "y": .. }`, but prefer
116
+ indices.
73
117
 
74
118
  ## 3. Browser layer walkthrough
75
119
 
@@ -103,8 +147,9 @@ browser_read {} # page text; optional { "selector": "h1"
103
147
 
104
148
  Notes:
105
149
 
106
- - **One session, no tab API** in v0.1 — `browser_launch` reuses the existing
107
- session if one is open. Close with `browser_close {}`.
150
+ - **One session, no tab API** in v0.2 — `browser_launch` reuses the existing
151
+ session if one is open, and a tab the page opens itself (`window.open`,
152
+ `target=_blank`) is not switched to. Close with `browser_close {}`.
108
153
  - The index re-check compares tag, name, href, and position at click time, and
109
154
  a snapshot is invalidated if the page navigated since. A mismatch returns
110
155
  `element_no_longer_valid` — re-snapshot.
@@ -114,33 +159,78 @@ Notes:
114
159
 
115
160
  ## 4. Menu commands
116
161
 
117
- `mac_menu_command` drives the app's menu bar by name — no index, localization
118
- safe (it walks the live menu):
162
+ `mac_menu_command` presses the item in the app's own menu bar through
163
+ accessibility — no pointer, and the app need not be frontmost. Give the title the
164
+ app shows (it must be unique) or a path (Apple-menu items and items whose
165
+ shortcut is one of the guarded chords require `force: true`; quitting session
166
+ processes or the MCP host is always refused):
119
167
 
120
168
  ```
121
- mac_menu_command { "app": "Finder", "command": "New Finder Window" }
169
+ mac_menu_command { "app": "TextEdit", "command": "Edit > Select All" }
170
+ → ran "Edit > Select All" in TextEdit via semantic AXPress — delivery=delivered_verified, retry=unsafe (changed: selection)
122
171
  ```
123
172
 
124
- Use it for actions that live in menus (New Window, Save, Export) rather than
125
- hunting a toolbar button in the AX tree.
126
-
127
173
  ## 5. Typing, pasting, and the focus guard
128
174
 
129
- - `mac_type { "text": "hello" }` synthesizes keystrokes.
130
- - **CJK / IME gotcha:** with a Chinese/Japanese/Korean input method active,
131
- `mac_type` can produce re-spaced or converted text (e.g. "no ra cu"). Use
132
- `mac_paste { "text": "你好" }` instead — it sets the clipboard and pastes,
133
- then restores the previous clipboard.
134
- - **Focus guard:** add `"app": "TextEdit"` to `mac_type` / `mac_paste` /
135
- `mac_key`. If TextEdit is not frontmost, the input is refused with
136
- `focus_lost` and nothing is sent — cheap insurance against typing into the
137
- wrong window (for example your MCP client). Omit `app` and the guard is off.
175
+ - `mac_type { "text": "hello" }` inserts into the frontmost app's focused
176
+ element through accessibility (`AXSelectedText`): IME-safe, the clipboard is
177
+ untouched, and the value is read back. With `element_index` it targets that
178
+ element (also in a background window); `replace: true` sets the whole value.
179
+ - Keystrokes are the fallback only where accessibility reports no focus or a text
180
+ view it cannot write (a terminal). They are not IME-safe; `mechanism:
181
+ "physical"` forces them.
182
+ - `mac_paste { "text": "你好" }` copies the clipboard aside, writes the text, sends
183
+ ⌘V, and puts every previous item back once the paste shows (else after 1 s) —
184
+ unless something else wrote to the clipboard meanwhile. A concealed
185
+ (password-manager) item is not copied; the clipboard is cleared instead.
186
+ `mac_type` does not touch the clipboard at all.
187
+ - **Focus guard:** add `"app": "TextEdit"` to `mac_paste` / `mac_key` (and to
188
+ `mac_type` when it sends keystrokes). If TextEdit is not frontmost, the input
189
+ is refused with `focus_lost` and nothing is sent.
190
+ - `mac_key` refuses `cmd-q`, `alt-cmd-q`, `cmd-shift-q`, `cmd-alt-esc`,
191
+ `ctrl-cmd-q`, `cmd-alt-delete`, `cmd-shift-delete` and similar unless
192
+ `"force": true`.
193
+
194
+ ```
195
+ mac_type { "text": "你好,世界", "app": "TextEdit" }
196
+ → typed 5 chars into the focused element of "TextEdit" via semantic AXSelectedText — delivery=delivered_verified, retry=unsafe
197
+ ```
198
+
199
+ ## 5b. Waiting, apps, windows, clipboard, notifications
138
200
 
139
201
  ```
140
- mac_paste { "text": "你好,世界", "app": "TextEdit" }
141
- → pasted 5 chars (clipboard restored: true) (frontmost: TextEdit)
202
+ mac_wait { "condition": "sheet", "app": "TextEdit", "timeout_ms": 5000 } # instead of sleeping
203
+ mac_wait { "condition": "element", "element_index": 7, "predicate": "enabled" }
204
+ mac_app { "action": "launch", "app": "Calculator" } # background unless "activate": true
205
+ mac_app { "action": "quit", "app": "Calculator" } # verified by the process ending
206
+ mac_windows { "app": "TextEdit" } # ids, titles, bounds, displays
207
+ mac_window { "action": "resize", "window_id": 25647, "width": 800, "height": 600 }
208
+ mac_screenshot { "window_id": 25647 } # one window, also when covered
209
+ mac_clipboard_read {} # text, file paths, or an image
210
+ mac_notifications {} # banners/alerts on screen; open_center:true reports center_opened / center_was_open
211
+ mac_notifications { "action": "dismiss", "id": "BC2BF929-…" } # notification_not_found if gone
142
212
  ```
143
213
 
214
+ ## 5c. Electron and Chromium apps: web contents through Playwright
215
+
216
+ With `NORACU_ALLOW_CDP=1` on the server, start the app fresh with a DevTools
217
+ port on 127.0.0.1 and attach the browser layer to it (`NORACU_ALLOW_CDP=any` is
218
+ needed to attach to a loopback port this `noracu` process did not open itself;
219
+ always refused under `NORACU_READ_ONLY=1`):
220
+
221
+ ```
222
+ mac_app { "action": "launch", "app": "Obsidian", "cdp_port": 0 }
223
+ → {"launched":"Obsidian","pid":4821,"cdp":{"port":51774,…}}
224
+ browser_launch { "cdp_port": 51774 }
225
+ browser_snapshot {} # the app's web contents
226
+ browser_close {} # disconnects; the app keeps running
227
+ ```
228
+
229
+ Menus, file dialogs and windows stay on `mac_*`. An app that is already
230
+ running is refused (`cdp_requires_fresh_launch`): quit it first. While the port
231
+ is open, any local process can control the app (127.0.0.1 has no per-user
232
+ isolation) — quit it when done.
233
+
144
234
  ## 6. Screenshots (visual fallback)
145
235
 
146
236
  ```
@@ -156,26 +246,45 @@ model — don't let it override the task.
156
246
 
157
247
  | Variable | Default | Effect |
158
248
  |---|---|---|
159
- | `NORACU_READ_ONLY` | unset | `=1` observation-only (allowlist of 12); all input-synthesis tools refused |
249
+ | `NORACU_READ_ONLY` | unset | `=1` observation-only (allowlist of 18); 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`) |
160
250
  | `NORACU_DISABLE_EVAL` | unset | `=1` makes `browser_evaluate` return an error when called (stays listed) |
161
251
  | `NORACU_ALLOW_FILE_URL` | unset | `=1` allows `browser_navigate` to open `file://` |
162
252
  | `NORACU_DISABLE_AUTO_INSTALL` | unset | `=1` skips Chromium auto-install on first `browser_launch` |
163
253
  | `NORACU_CLICLICK` | `/opt/homebrew/bin/cliclick` | cliclick binary path |
164
254
  | `NORACU_PYTHON` | auto-probe | python3 for the bundled iPhone driver (must import pyobjc: Quartz, Vision, AppKit) |
165
255
  | `NORACU_IMCTL_DIR` | bundled `imctl/` | override the driver location (development only) |
256
+ | `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) |
257
+ | `NORACU_OCR_LANGUAGES` | `zh-Hans,en-US` | comma-separated Vision OCR language codes for the iPhone screen, in priority order |
258
+ | `NORACU_TOPHIT_LABELS` | `Top Hit` | comma-separated Spotlight Top Hit section label(s) that `phone_open` looks for |
259
+ | `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`) |
260
+ | `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`) |
166
261
  | `NORACU_CI` | unset | `=1` only affects `npm test` (skips hardware-gated checks) |
167
262
 
168
263
  ## 8. Error reference
169
264
 
170
265
  | Error | Meaning / fix |
171
266
  |---|---|
172
- | `element_no_longer_valid` | index older than 30 s, frontmost app changed, or page navigated — re-observe |
173
- | `mac_* … -1719` | Accessibility not granted to the host app |
267
+ | `element_no_longer_valid` | index older than 30 s, the element is gone or changed, its window closed, or the page navigated — re-observe |
268
+ | `permission_denied: Accessibility permission is missing…` | Accessibility not granted to the host app (`mac_status` shows it) |
269
+ | `occluded: … on top: {…}` | a physical click would land on something else (including another window of the same app); nothing was sent |
270
+ | `ambiguous_window: …` | several windows, none focused — pass `window` or `window_id` |
271
+ | `not_actionable: …` | the element is disabled, off screen, or its window is minimized |
272
+ | `not_confirmed: …` | the action ran but the read-back does not show the expected result — check `delivery` / `retry` before repeating |
273
+ | `focus_lost: …` / `focus_unknown: …` | the focus guard (`app`) could not confirm that app is frontmost — bring it forward before sending keystrokes or paste |
274
+ | `policy_denied: …` | a guarded key chord or menu item without `force`, a protected process, or a DevTools port without `NORACU_ALLOW_CDP=1` |
275
+ | `clipboard_remote: …` / `clipboard_too_large: …` | `mac_paste` refused Universal Clipboard content or a clipboard over 64 MB unless `force: true` |
276
+ | `notification_not_found: …` | `mac_notifications` dismiss/act target id or index is no longer on screen or no longer matches `expected_app` / `expected_title` |
277
+ | `input_busy: …` | an earlier phone or Mac action held the input queue past its wait limit; nothing was sent — retry |
278
+ | `ax_timeout: …` | the target app did not answer accessibility calls in time (busy or hung) |
174
279
  | black `mac_screenshot` | Screen Recording not granted to the host app |
175
280
  | `ENOENT` cliclick | `brew install cliclick` or set `NORACU_CLICLICK` |
176
281
  | `… blocked by NORACU_READ_ONLY=1` | you're in observation-only mode — unset it to act |
177
282
  | `browser_evaluate disabled by NORACU_DISABLE_EVAL=1` | eval kill-switch is on |
178
- | `mirror_not_live: …` | iPhone Mirroring shows an overlay (paused, "iPhone in Use") — lock the iPhone, keep it near the Mac, call `phone_launch` |
283
+ | `mirror_not_live: …` | iPhone Mirroring is closed or shows an overlay (paused, "iPhone in Use") — lock the iPhone, keep it near the Mac, call `phone_launch` |
284
+ | `mirror_state_unknown: …` | iPhone Mirroring's state could not be confirmed even after bringing it forward — check `phone_status` before acting |
285
+ | `mirror_setup_required: …` | iPhone Mirroring shows a setup or welcome screen — finish it yourself in its window, then call `phone_launch` |
286
+ | `menu_unknown: …` | `phone_home` or `phone_app_switcher` menu command timed out (`delivery=unknown, retry=unsafe`) — inspect `phone_screenshot` before retrying |
287
+ | `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 |
179
288
  | `imctl unavailable: no python3 with pyobjc found …` | install pyobjc for a python3 (`python3 -m pip install pyobjc-framework-Quartz pyobjc-framework-Vision pyobjc-framework-AppKit`) or set `NORACU_PYTHON` |
180
289
 
181
290
  ## 9. iPhone layer
@@ -190,16 +299,16 @@ it observes with OCR on the Mac and acts at normalized 0–1 coordinates.
190
299
  ```
191
300
  phone_status
192
301
  → {"running": true, "window": {...}, "window_id": 278508, "onscreen": true,
193
- "frontmost": false, "live": false, "overlay": "Connection Paused", "paused": true}
302
+ "frontmost": false, "live": false, "overlay": "Connection Paused", "paused": true, "setup": false}
194
303
 
195
304
  phone_tap {"x": 0.5, "y": 0.5} # refused while the mirror is not live
196
- → ERROR: mirror_not_live: Connection Paused — call phone_launch (or imctl resume) first
305
+ → ERROR: mirror_not_live: Connection Paused — call phone_launch (or imctl resume) first (delivery=not_delivered, retry=safe)
197
306
 
198
307
  phone_launch # brings the mirror to the front and clicks Resume
199
- → iPhone Mirroring ready
308
+ → iPhone Mirroring ready (delivery=delivered_unverified, retry=safe)
200
309
 
201
310
  phone_status
202
- → {... "live": true, "overlay": null, "paused": false ...}
311
+ → {... "live": true, "overlay": null, "paused": false, "setup": false ...}
203
312
 
204
313
  phone_ocr # OCR of the Mirroring window (captured by window id)
205
314
  → (0.50,0.06) 'Settings' [1.00]
@@ -210,30 +319,50 @@ phone_find {"text": "Settings"}
210
319
  → (0.50,0.06) 'Settings' [1.00]
211
320
 
212
321
  phone_tap {"x": 0.50, "y": 0.06}
213
- → tapped (0.5, 0.06)
322
+ → tapped (0.5, 0.06) (delivery=delivered_unverified, retry=unsafe)
214
323
  ```
215
324
 
216
- `live` / `overlay` / `paused` come from the window's structure, not its
217
- language: a live mirror is a single empty hosting view; "Connection Paused",
218
- "iPhone in Use" and similar states add text and a button. While the mirror is
219
- not live, `phone_tap`, `phone_longpress`, `phone_swipe`, `phone_scroll`,
220
- `phone_type`, `phone_key` and `phone_open` refuse with `mirror_not_live`, and
221
- `phone_ocr` / `phone_find` start with a `warning: mirror not live …` line.
325
+ `live` / `overlay` / `paused` / `setup` come from the window's structure and
326
+ shape, not its language: a live mirror is a single empty hosting view;
327
+ "Connection Paused", "iPhone in Use" and similar states add text and a button;
328
+ a setup or welcome screen (`setup: true`) sits in a window that is not
329
+ phone-shaped, and `phone_launch` never clicks it. While the mirror is
330
+ not live, every phone input tool (`phone_tap`, `phone_longpress`, `phone_swipe`,
331
+ `phone_scroll`, `phone_type`, `phone_key`, `phone_open`, `phone_home` and
332
+ `phone_app_switcher`) refuses with `mirror_not_live` (or `mirror_state_unknown`
333
+ when the state cannot be read), and `phone_ocr` / `phone_find` start with a
334
+ `warning: mirror not live …` line.
222
335
 
223
336
  `phone_scroll {"direction": "down", "distance": 0.5}` moves the list under the
224
337
  mirror by about half a window, with trackpad-style scroll events; a vertical
225
338
  `phone_swipe` drag does not scroll lists in iPhone Mirroring, so keep swipes
226
339
  for gestures such as Home Screen paging.
227
340
 
228
- `phone_type` pastes through the clipboard with a real Command-V chord (the
229
- previous text clipboard is restored). `phone_open {"app": "Calculator"}` opens
230
- Spotlight through iPhone Mirroring's own shortcut, pastes the name, and taps a
231
- result whose OCR text matches the name exactly; with no match it returns to the
232
- Home Screen and reports `app not found`.
341
+ `phone_type` pastes through the clipboard with a real Command-V chord (never
342
+ echoing the typed text), saving every clipboard item and type, clearing
343
+ concealed or transient items instead of copying, and restoring the clipboard
344
+ once OCR sees the pasted text appear on the phone (more often than before the
345
+ paste — text already on screen does not count). Universal Clipboard or >64 MB
346
+ items are not copied and leave the typed text on the clipboard; if the paste
347
+ only shows up a few seconds late (still reported as typed — do not type it
348
+ again) or ends in `type_not_confirmed`, the clipboard also keeps the typed text.
349
+ `phone_open {"app": "Calculator"}` opens Spotlight through iPhone Mirroring's
350
+ own shortcut, pastes the name, and taps it only when Spotlight's Top Hit card
351
+ shows exactly that name (a web suggestion or Settings row with the same name
352
+ is never tapped); otherwise it returns to the Home Screen and reports
353
+ `app not found` (`delivery=delivered_unverified, retry=safe`). A paste can take
354
+ several seconds to reach the iPhone: when the
355
+ name never shows up, `phone_open` waits up to 15 s and then reports
356
+ `open_not_confirmed` (retry) rather than `app not found`. Use the name the phone shows under the icon (`拼多多`, not
357
+ `Pinduoduo`); it reads Spotlight's English "Top Hit" label, so on an iPhone
358
+ set to another language set `NORACU_TOPHIT_LABELS` to the label the phone shows.
233
359
 
234
360
  Privacy: everything the phone shows — notifications, messages, one-time
235
361
  codes — becomes tool output that your MCP client sends to its model. Use a
236
362
  Focus, open a neutral app first, and start with `NORACU_READ_ONLY=1`
237
363
  (phone observation allowed, phone input refused). `phone_home` /
238
- `phone_app_switcher` go through the iPhone Mirroring menu and work without
239
- python when the mirror is connected.
364
+ `phone_app_switcher` go through the iPhone Mirroring menu while the mirror is
365
+ live — working without python/pyobjc on English macOS, refusing when paused or
366
+ closed, returning `menu_unknown` without a fallback swipe on timeout, and
367
+ falling back to `imctl` when the English menu item is absent on non-English
368
+ macOS.
package/imctl/README.md CHANGED
@@ -39,8 +39,11 @@ $ imctl open Photos
39
39
  - **Vision** — the macOS Vision framework runs OCR locally on a
40
40
  window screenshot (captured by CGWindow id, so it is the window's own
41
41
  pixels even when covered) and returns text with normalized coordinates.
42
- - **Verification** — every gesture can be followed by a downsampled
43
- pixel-hash comparison to confirm the screen actually changed.
42
+ - **Verification** — `imctl verify` compares downsampled pixel hashes
43
+ (`capture_hash`) before and after a gesture; `scroll`, `type` and `open`
44
+ verify using luma frame diffs (`mean_abs_diff`) and/or Vision OCR; `tap`,
45
+ `longpress`, `swipe`, `home` and `app-switcher` do not verify post-action
46
+ screen changes (optional `--expect` checks on-screen OCR text before acting).
44
47
 
45
48
  ## Why these specific parameters
46
49
 
@@ -53,7 +56,7 @@ the mirroring gesture recognizer:
53
56
  | swipe steps | 20 | single-shot drags are **not** recognized as swipes |
54
57
  | initial nudge | 3 px | disambiguates swipe from icon long-press-drag |
55
58
  | swipe curve | quadratic ease-in-out | stays inside the recognizer's velocity window |
56
- | home gesture start | 0.95 height | higher start points are treated as in-app scrolls |
59
+ | home gesture start | 0.90 height | higher start points are treated as in-app scrolls; the bottom ~7% (0.95) is macOS window chrome where events do not reach the phone |
57
60
  | text input | clipboard + Cmd+V | direct keystroke synthesis breaks under CJK IMEs |
58
61
 
59
62
  ## Requirements
@@ -77,22 +80,22 @@ imctl status
77
80
 
78
81
  | Command | Description |
79
82
  |---------|-------------|
80
- | `status` | session + window info (JSON: running, window, window_id, onscreen, frontmost, live, overlay, paused) |
83
+ | `status` | session + window info (JSON: running, window, window_id, onscreen, frontmost, live, overlay, paused, setup) |
81
84
  | `screenshot [PATH]` | capture the mirroring window to PNG by window id (works when covered) |
82
- | `resume` | click Resume when the window shows Connection Paused |
83
- | `launch` | ensure mirroring is running and frontmost |
84
- | `tap X Y` | tap at normalized coords (0-1) |
85
- | `longpress X Y [D]` | long-press (default 0.8s) |
86
- | `swipe FX FY TX TY [--ms]` | eased swipe between two points |
87
- | `home` | home gesture (bottom-edge swipe up) |
88
- | `app-switcher` | swipe up and hold |
89
- | `scroll up/down [D]` | scroll by normalized distance |
85
+ | `resume` | click Resume when the window shows Connection Paused (never on a setup or welcome screen) |
86
+ | `launch` | ensure mirroring is running and frontmost; resumes a paused session, never clicks a setup screen (`mirror_setup_required`) |
87
+ | `tap X Y [--expect TEXT]` | tap at normalized coords (0-1) |
88
+ | `longpress X Y [D] [--duration D] [--expect TEXT]` | long-press (default 0.8s) |
89
+ | `swipe FX FY TX TY [--ms MS] [--expect TEXT]` | eased swipe between two points |
90
+ | `home` | send home gesture (bottom-edge swipe up; requires live mirror; screen not verified) |
91
+ | `app-switcher` | send app-switcher gesture (swipe up and hold; requires live mirror; screen not verified) |
92
+ | `scroll up/down [D] [--expect TEXT]` | scroll by normalized distance |
90
93
  | `page left/right` | home-screen paging |
91
- | `type TEXT` | type text (clipboard-based, IME-safe) |
92
- | `key K` | return / delete / up / down / left / right |
94
+ | `type [--replace] [--expect TEXT] TEXT\|-` | type text via clipboard (IME-safe; `-` reads stdin; never echoes typed text) |
95
+ | `key [--expect TEXT] K` | return / delete / up / down / left / right |
93
96
  | `ocr` | OCR the screen with coordinates |
94
- | `find TEXT` | locate text on screen |
95
- | `open APP` | open an app via Spotlight + OCR + tap |
97
+ | `find [--exact] TEXT\|-` | locate text on screen (`-` reads stdin) |
98
+ | `open APP\|-` | open an app via Spotlight + OCR + tap (`-` reads stdin; only an exact label inside the Top Hit card) |
96
99
  | `verify ACTION` | run a gesture and verify the screen changed |
97
100
 
98
101
  ## Python API
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "imctl"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Control iPhone Mirroring on macOS from the CLI — CGEvent input, Vision OCR, pixel verification"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -27,5 +27,5 @@ Key design decisions (each backed by empirical testing):
27
27
  between actions, so we re-resolve bounds before each gesture.
28
28
  """
29
29
 
30
- __version__ = "0.1.0"
30
+ __version__ = "0.2.0"
31
31
  __all__ = ["cli", "window", "input", "vision", "verify", "gestures"]