noracu 0.3.2 → 0.3.3
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 +111 -0
- package/README.md +94 -119
- package/SECURITY.md +148 -91
- package/docs/README.zh-CN.md +75 -102
- package/docs/apps.md +4 -6
- package/docs/architecture.md +17 -53
- package/docs/iphone.md +242 -54
- package/docs/known-issues.md +27 -11
- package/docs/tools.md +57 -57
- package/docs/troubleshooting.md +82 -25
- package/docs/usage.md +193 -241
- package/imctl/src/imctl/cli.py +21 -17
- package/imctl/src/imctl/gestures.py +85 -4
- package/imctl/src/imctl/verify.py +1 -2
- package/package.json +12 -8
- package/src/approval.js +28 -23
- package/src/doctor.js +60 -12
- package/src/ios-session.js +15 -14
- package/src/ios-setup.js +15 -6
- package/src/mac-ax.js +17 -3
- package/src/mcpb-entry.js +3 -0
- package/src/server.mjs +360 -235
package/src/ios-session.js
CHANGED
|
@@ -177,15 +177,15 @@ export function createIosSession({
|
|
|
177
177
|
const d = runner?.device;
|
|
178
178
|
if (!d || d.simulated || (!force && now() - lockOkAt <= LOCK_FRESH_MS)) return null;
|
|
179
179
|
const lock = await api.lockState(d.udid);
|
|
180
|
-
if (!lock.ok) return { error: "lock_unknown", message: `could not read the iPhone's lock state (${lock.message}) —
|
|
181
|
-
if (lock.locked) return { error: "device_locked", message: "the iPhone is locked — unlock it" };
|
|
180
|
+
if (!lock.ok) return { error: "lock_unknown", message: `could not read the iPhone's lock state (${String(lock.message).slice(0, 80)}), so it counts as locked — stop and tell the person to check the iPhone; do not retry` };
|
|
181
|
+
if (lock.locked) return { error: "device_locked", message: "the iPhone is locked — stop and tell the person to unlock it" };
|
|
182
182
|
lockOkAt = now();
|
|
183
183
|
return null;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async function startOnce() {
|
|
187
187
|
// observation-only mode never starts the runner: a starting runner puts its own app in front of whatever the iPhone shows
|
|
188
|
-
if (readOnly) return { ok: false, error: "runner_not_started", message: "NORACU_READ_ONLY=1 does not start the runner
|
|
188
|
+
if (readOnly) return { ok: false, error: "runner_not_started", message: "NORACU_READ_ONLY=1 does not start the runner, which would put its own app in front of what the iPhone shows — call ios_status, or stop and tell the person" };
|
|
189
189
|
const g = gen; // read before anything is waited for: a shutdown during any wait below stops this start
|
|
190
190
|
const shut = { ok: false, error: "runner_start_failed", message: "the session was shut down while the runner was starting" };
|
|
191
191
|
// two test sessions on one device at once do not work: a runner that was stopped must be gone first
|
|
@@ -201,12 +201,12 @@ export function createIosSession({
|
|
|
201
201
|
if (!bind.ok) return bind;
|
|
202
202
|
if (!device.simulated) {
|
|
203
203
|
const lock = await api.lockState(device.udid);
|
|
204
|
-
if (!lock.ok) return { ok: false, error: "lock_unknown", message: `could not read the iPhone's lock state (${lock.message})` };
|
|
205
|
-
if (lock.locked) return { ok: false, error: "device_locked", message: "the iPhone is locked — unlock it" };
|
|
204
|
+
if (!lock.ok) return { ok: false, error: "lock_unknown", message: `could not read the iPhone's lock state (${String(lock.message).slice(0, 80)}) — stop and tell the person to check the iPhone; do not retry` };
|
|
205
|
+
if (lock.locked) return { ok: false, error: "device_locked", message: "the iPhone is locked — stop and tell the person to unlock it" };
|
|
206
206
|
lockOkAt = now();
|
|
207
207
|
}
|
|
208
208
|
const xctestrun = await api.findXctestrun(join(dir, device.udid));
|
|
209
|
-
if (!xctestrun) return { ok: false, error: "ios_setup_required", message: `no runner build for this device — run: npx noracu ios-setup ${device.simulated ? "" : "--team <TeamID> "}--udid ${device.udid}` };
|
|
209
|
+
if (!xctestrun) return { ok: false, error: "ios_setup_required", message: `no runner build for this device — stop and tell the person to run: npx noracu ios-setup ${device.simulated ? "" : "--team <TeamID> "}--udid ${device.udid}` };
|
|
210
210
|
if (g !== gen) return shut; // shut down while the device, the lock or the build was looked up: nothing is started
|
|
211
211
|
const start = () => api.startRunner({ udid: device.udid, xctestrun, bind: bind.bind, spawnImpl, env });
|
|
212
212
|
let r = await start();
|
|
@@ -343,7 +343,7 @@ export function createIosSession({
|
|
|
343
343
|
const st = await cur.client.call("app_state", { bundle_id: args.bundle_id }, { timeoutMs: 10000 });
|
|
344
344
|
if (runner !== cur) return { ok: false, error: "runner_unreachable", message: "the runner stopped", delivery: "not_delivered" };
|
|
345
345
|
if (!st.ok) return unread(st);
|
|
346
|
-
if (st.result?.state === 4) return { ok: false, error: "system_overlay", message: "
|
|
346
|
+
if (st.result?.state === 4) return { ok: false, error: "system_overlay", message: "something of the iPhone's own is over the app (Control Center, for example) — call ios_snapshot in a moment; if it stays, ios_home leaves the app and ios_launch brings the app back", delivery: "not_delivered" };
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
// The reads above can take seconds after the queue looked at the stop file and the gate at the lock (SpringBoard
|
|
@@ -361,10 +361,11 @@ export function createIosSession({
|
|
|
361
361
|
const stop = stopCheck();
|
|
362
362
|
if (!stop) return null;
|
|
363
363
|
const m = /^(\w+): ([\s\S]*)$/.exec(stop) || [null, "user_stopped", stop];
|
|
364
|
-
|
|
364
|
+
// the refusal's own delivery marker comes off (the input error adds one); an older wording said "nothing was sent" before it
|
|
365
|
+
return { ok: false, error: m[1], message: m[2].replace(/\s*[—;,]?\s*nothing was sent \((?:fail closed; )?delivery=not_delivered, retry=safe\)/, "").replace(/\s*\(delivery=[a-z_]+, retry=(?:safe|unsafe)\)\s*$/, ""), delivery: "not_delivered" };
|
|
365
366
|
} : undefined;
|
|
366
367
|
let r = await cur.client.call(op, args, { timeoutMs, beforeSend });
|
|
367
|
-
if (homeCovered && !r.ok && r.error === "app_not_foreground") r = { ...r, message: "the Home Screen is not what the iPhone is showing
|
|
368
|
+
if (homeCovered && !r.ok && r.error === "app_not_foreground") r = { ...r, message: "the Home Screen is not what the iPhone is showing — an app or Spotlight is in front; name that app (ios_snapshot shows its bundle_id) or call ios_home", plain: true };
|
|
368
369
|
// An input that got no answer may still be waiting inside the test session: the session ends now, so the
|
|
369
370
|
// gesture cannot go out later (the protocol always said so). Any failure XCTest recorded ends it
|
|
370
371
|
// as well, whichever command was answered with it — an input, a read, or the next command after a late one:
|
|
@@ -398,7 +399,7 @@ export function createIosSession({
|
|
|
398
399
|
app_not_foreground: " — the app is not in front; call ios_launch first",
|
|
399
400
|
app_not_running: " — the app is not running; call ios_launch first",
|
|
400
401
|
// device run 2026-11-15: the refusal did not say which prompt was up, so the agent could not tell the person what to answer
|
|
401
|
-
system_alert: " — a system prompt is up on the iPhone
|
|
402
|
+
system_alert: " — a system prompt is up on the iPhone: look at it with ios_screenshot, then stop and tell the person what it asks; only the person answers it",
|
|
402
403
|
no_keyboard: " — no keyboard is up; tap a text field first (ios_type with element_index does that)",
|
|
403
404
|
ios_timeout: " — look before acting again (ios_snapshot)",
|
|
404
405
|
xctest_issue: " — XCTest reported a failure while the command ran; look before acting again (ios_snapshot)",
|
|
@@ -414,7 +415,7 @@ export function createIosSession({
|
|
|
414
415
|
const sbNever = (bundle) => {
|
|
415
416
|
if (bundle !== SPRINGBOARD || !springboardDenied()) return null;
|
|
416
417
|
const denied = approve(bundle, "input");
|
|
417
|
-
return { error: denied || `input_denied: input that names com.apple.springboard (the Home Screen) is not sent while app rules are
|
|
418
|
+
return { error: denied || `input_denied: input that names com.apple.springboard (the Home Screen) is not sent while app rules are on (NORACU_APPROVAL_FILE or NORACU_DENY_APPS) — open apps with ios_launch, go home with ios_home ${NOT_SENT}` };
|
|
418
419
|
};
|
|
419
420
|
// system_alert comes with two messages: an alert is up, or SpringBoard could not be read so one could not be ruled
|
|
420
421
|
// out — only the first is told "a system prompt is up"
|
|
@@ -425,7 +426,7 @@ export function createIosSession({
|
|
|
425
426
|
const readError = (r) => ({ error: `${r.error}: ${r.message || "the runner refused"}${r.error === "app_not_running" ? HINTS.app_not_running : ""}` });
|
|
426
427
|
function pickBundle(a, input) {
|
|
427
428
|
const b = a.bundle_id ?? current;
|
|
428
|
-
return b ? { bundle: b } : { error: `bundle_id required
|
|
429
|
+
return b ? { bundle: b } : { error: `invalid_args: bundle_id is required — name the app, or call ios_launch first (it sets the app for later calls)${input ? ` ${NOT_SENT}` : ""}` };
|
|
429
430
|
}
|
|
430
431
|
|
|
431
432
|
// ---------- elements ----------
|
|
@@ -611,7 +612,7 @@ export function createIosSession({
|
|
|
611
612
|
// only a text input is tapped to take the text: the index of a button or a row would be tapped as what
|
|
612
613
|
// it is — a real press on it — and the text would then go to whatever holds the keyboard. Before the
|
|
613
614
|
// gate: nothing is asked for an input that is not going to be sent.
|
|
614
|
-
if (!TEXTY.has(it.type) && it.type !== "secureTextField") return { error: `not_a_text_field: element_index ${a.element_index} is a ${it.type}${it.label ? ` (${JSON.stringify(String(it.label).slice(0, 40))})` : ""}, not a text field —
|
|
615
|
+
if (!TEXTY.has(it.type) && it.type !== "secureTextField") return { error: `not_a_text_field: element_index ${a.element_index} is a ${it.type}${it.label ? ` (${JSON.stringify(String(it.label).slice(0, 40))})` : ""}, not a text field — call ios_tap on what brings the keyboard up, then ios_type without element_index (delivery=not_delivered, retry=safe)` };
|
|
615
616
|
const g = await gate(it.bundle);
|
|
616
617
|
if (g) return g;
|
|
617
618
|
if (it.epoch !== epoch) return stale(a.element_index); // the gate started a runner: what was read is gone
|
|
@@ -661,7 +662,7 @@ export function createIosSession({
|
|
|
661
662
|
const after = await textFields(bundle);
|
|
662
663
|
// a failure XCTest recorded once the text had gone out: the "ok" the runner gave for it is in doubt
|
|
663
664
|
if (heldIssue) return issueAt(takeHeld(), true);
|
|
664
|
-
const notConfirmed = { error: `type_not_confirmed: ${n} characters were typed in ${bundle} but ${key ? "the field
|
|
665
|
+
const notConfirmed = { error: `type_not_confirmed: ${n} characters were typed in ${bundle}, but ${key ? "the tapped field did not show" : "no text field showed"} exactly that text (autocorrection, or a hidden value) — check with ios_snapshot before typing again ${UNKNOWN}` };
|
|
665
666
|
// The fields could not be read afterwards (the read failed, or the app has more elements than are read): the
|
|
666
667
|
// text was not seen to be missing, which type_not_confirmed would say — unverified, and the result names the
|
|
667
668
|
// side that could not be read
|
package/src/ios-setup.js
CHANGED
|
@@ -16,16 +16,25 @@ import { fileURLToPath } from "node:url";
|
|
|
16
16
|
import * as iosApi from "./ios-xcuitest.js";
|
|
17
17
|
|
|
18
18
|
const PROJECT = join(dirname(fileURLToPath(import.meta.url)), "..", "ios-runner", "NoracuRunner.xcodeproj");
|
|
19
|
-
export const USAGE = `
|
|
19
|
+
export const USAGE = `noracu ios-setup — build the XCUITest runner for the iPhone layer (experimental and off by default)
|
|
20
|
+
|
|
21
|
+
usage: noracu ios-setup --team <TeamID> [--udid <udid>] [--bundle-prefix <prefix>] [--register-device]
|
|
20
22
|
noracu ios-setup --udid <simulator udid>
|
|
21
23
|
|
|
22
|
-
Builds noracu's
|
|
23
|
-
~/.noracu/ios-runner/<udid
|
|
24
|
+
Builds noracu's runner (a UI-test bundle, source in ios-runner/) for one iPhone or one booted iOS Simulator and leaves
|
|
25
|
+
it in ~/.noracu/ios-runner/<udid> (NORACU_IOS_RUNNER_DIR names another folder). Requires Xcode; an iPhone also needs
|
|
26
|
+
a developer team, Developer Mode, and to be unlocked.
|
|
27
|
+
|
|
28
|
+
This command does not enable the iPhone layer. To use the runner, start the MCP server with both
|
|
29
|
+
NORACU_LAYERS=mac,browser,iphone and NORACU_PHONE_BACKEND=xcuitest.
|
|
24
30
|
|
|
25
31
|
--team <TeamID> your Apple developer team (10 characters); needed for an iPhone, not for a simulator
|
|
26
|
-
--udid <udid> the
|
|
32
|
+
--udid <udid> the iPhone or the booted simulator; may be left out when exactly one iPhone is connected
|
|
27
33
|
--bundle-prefix <p> bundle identifier prefix for the runner (default: dev.noracu.<teamid>)
|
|
28
|
-
--register-device let Xcode register this iPhone in the team if it is not registered yet
|
|
34
|
+
--register-device let Xcode register this iPhone in the team if it is not registered yet
|
|
35
|
+
--help print this text
|
|
36
|
+
|
|
37
|
+
More: https://github.com/sgInnora/noracu/blob/main/docs/iphone.md`;
|
|
29
38
|
|
|
30
39
|
const TEAM_RE = /^[A-Z0-9]{10}$/, PREFIX_RE = /^(?=.{3,101}$)[A-Za-z0-9][A-Za-z0-9-]*(?:\.[A-Za-z0-9-]+)*$/; // parts between single dots: none empty
|
|
31
40
|
|
|
@@ -167,6 +176,6 @@ export async function main(argv, { log = (s) => process.stdout.write(s + "\n"),
|
|
|
167
176
|
}
|
|
168
177
|
}
|
|
169
178
|
try { writeFileSync(stampPath, JSON.stringify({ prefix: want, built: new Date().toISOString() }) + "\n", { mode: 0o600 }); } catch { /* the next build cleans up instead */ }
|
|
170
|
-
log(`Built: ${xctestrun}${unchecked}\nNext: start the MCP server with NORACU_PHONE_BACKEND=xcuitest${o.udid ? ` and NORACU_IOS_UDID=${device.udid}` : ""} in its environment, keep the iPhone unlocked, and call ios_status.`);
|
|
179
|
+
log(`Built: ${xctestrun}${unchecked}\nNext: start the MCP server with NORACU_LAYERS=mac,browser,iphone and NORACU_PHONE_BACKEND=xcuitest${o.udid ? ` and NORACU_IOS_UDID=${device.udid}` : ""} in its environment, keep the iPhone unlocked, and call ios_status.`);
|
|
171
180
|
return 0;
|
|
172
181
|
}
|
package/src/mac-ax.js
CHANGED
|
@@ -258,7 +258,7 @@ function appCandidates(spec) {
|
|
|
258
258
|
function ambiguousApp(spec, hit) {
|
|
259
259
|
const front = frontApp();
|
|
260
260
|
const apps = hit.map(a => ({ pid: a.pid, name: a.name, bundle_id: a.bundle, frontmost: Boolean(front && front.pid === a.pid) }));
|
|
261
|
-
return notDelivered({ code: 'AMBIGUOUS_APP', message: `"${String(spec).slice(0, 80)}" names ${apps.length} running apps (${apps.map(x => `pid ${x.pid}${x.frontmost ? ', frontmost' : ''}`).join('; ')}) — nothing was done; name
|
|
261
|
+
return notDelivered({ code: 'AMBIGUOUS_APP', message: `"${String(spec).slice(0, 80)}" names ${apps.length} running apps (${apps.map(x => `pid ${x.pid}${x.frontmost ? ', frontmost' : ''}`).join('; ')}) — nothing was done; name one of them as "pid:<number>" (mac_apps lists them)`, details: { apps } });
|
|
262
262
|
}
|
|
263
263
|
// One app, none (null), or — thrown, and answered by dispatch — the refusal for a name several apps share.
|
|
264
264
|
function findApp(spec) {
|
|
@@ -1579,6 +1579,9 @@ function ncDrawnRects() {
|
|
|
1579
1579
|
// what is under them. Notification Center's full-display overlay (shown with a banner or alert) is
|
|
1580
1580
|
// skipped the same way except over a banner or alert frame (ncDrawnRects), or everywhere when those
|
|
1581
1581
|
// frames cannot be told.
|
|
1582
|
+
// The pointer: at times the window server draws it as a window of its own ("Cursor", at the cursor level), and then
|
|
1583
|
+
// that window sits on the very point a click goes to. It never takes a click, so it never covers anything.
|
|
1584
|
+
const CURSOR_LAYER = 2147483630; // kCGCursorWindowLevel
|
|
1582
1585
|
function cgTopAt(x, y) {
|
|
1583
1586
|
const list = cast($.CGWindowListCopyWindowInfo((1 << 0) | (1 << 4), 0)); // on screen only, no desktop elements
|
|
1584
1587
|
if (!list) return null;
|
|
@@ -1589,6 +1592,7 @@ function cgTopAt(x, y) {
|
|
|
1589
1592
|
const layer = Number(g('kCGWindowLayer')), alpha = Number(g('kCGWindowAlpha'));
|
|
1590
1593
|
const owner = String(g('kCGWindowOwnerName') || '');
|
|
1591
1594
|
if (!(alpha > 0) || layer < 0) continue;
|
|
1595
|
+
if (owner === 'Window Server' && layer === CURSOR_LAYER) continue;
|
|
1592
1596
|
const b = d.objectForKey(ks('kCGWindowBounds'));
|
|
1593
1597
|
if (!b || b.isNil()) continue;
|
|
1594
1598
|
const [bx, by, bw, bh] = ['X', 'Y', 'Width', 'Height'].map(k => Number(b.objectForKey(ks(k)).js));
|
|
@@ -2805,7 +2809,7 @@ function opNotifications(req) {
|
|
|
2805
2809
|
if (ncCenterOpen(appEl, clock)) {
|
|
2806
2810
|
alreadyOpen = true;
|
|
2807
2811
|
} else {
|
|
2808
|
-
if (!clock) return fail(notDelivered({ code: 'ACTION_NOT_SUPPORTED', message: 'accessibility does not expose the menu-bar clock here, so Notification Center cannot be opened from noracu — open it
|
|
2812
|
+
if (!clock) return fail(notDelivered({ code: 'ACTION_NOT_SUPPORTED', message: 'accessibility does not expose the menu-bar clock here, so Notification Center cannot be opened from noracu — ask the person to open it (click the clock), then list again; banners on screen are listed without it', details: { kind: 'open_center_unavailable' } }));
|
|
2809
2813
|
if (perform(clock, 'AXPress') === 0) { opened = true; sleep(900); }
|
|
2810
2814
|
}
|
|
2811
2815
|
}
|
|
@@ -2986,11 +2990,21 @@ function opMenu(req) {
|
|
|
2986
2990
|
if (d.verified && inputSince(pressedAt)) v.note = 'the focused element changed, but the keyboard or mouse was used meanwhile, so the change is not counted as the command\'s effect';
|
|
2987
2991
|
else if (d.verified) { v.delivery = 'delivered_verified'; v.changed = d.changed; }
|
|
2988
2992
|
}
|
|
2989
|
-
|
|
2993
|
+
const dn = disabledNote(h.enabled, v, app, frontApp());
|
|
2994
|
+
if (dn) v.note = dn;
|
|
2990
2995
|
if (e === -25204) { v.delivery = 'unknown'; v.note = 'the app did not answer in time (a modal menu or dialog may be open)'; }
|
|
2991
2996
|
return v;
|
|
2992
2997
|
}
|
|
2993
2998
|
|
|
2999
|
+
// A menu item that read as disabled and was pressed anyway: the note says so only when nothing else was noted and
|
|
3000
|
+
// nothing observable changed; an app in the background may not act on a menu item at all (TextEdit's View > Zoom Out,
|
|
3001
|
+
// 2026-11-25), so for one the note says to bring it forward.
|
|
3002
|
+
function disabledNote(enabled, v, app, front) {
|
|
3003
|
+
if (enabled || v.delivery === 'delivered_verified' || v.note || (v.changed && v.changed.length)) return null;
|
|
3004
|
+
return 'the item reported disabled (menus refresh that state lazily) and nothing observable changed'
|
|
3005
|
+
+ (front && front.pid !== app.pid ? ` — ${app.name} is in the background, where a menu item may not act; bring it forward (mac_app, action activate) and check before running the command again` : '');
|
|
3006
|
+
}
|
|
3007
|
+
|
|
2994
3008
|
// A named key (return, esc, tab, arrows, F-keys…) with optional modifiers, posted to the frontmost app at
|
|
2995
3009
|
// the HID level from a HID-state event source, the way a hardware keyboard sends it: each modifier pressed
|
|
2996
3010
|
// (a flags-changed event), the key down and up 20 ms apart, the modifiers released last-first. Chrome's
|