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/imctl/src/imctl/cli.py
CHANGED
|
@@ -50,7 +50,7 @@ _MIRROR_NOT_RUNNING_LINE = (
|
|
|
50
50
|
)
|
|
51
51
|
_MIRROR_STATE_UNKNOWN_LINE = (
|
|
52
52
|
"mirror_state_unknown: could not tell whether iPhone Mirroring is live — "
|
|
53
|
-
"nothing was sent;
|
|
53
|
+
"nothing was sent; call phone_status, and if it stays unknown, stop and tell the person"
|
|
54
54
|
)
|
|
55
55
|
|
|
56
56
|
# One line, one exit code for every capture failure. The pixels a check
|
|
@@ -179,8 +179,8 @@ def _refuse_off_screen(x: float, y: float, *, measure: bool) -> int | None:
|
|
|
179
179
|
x0, y0, x1, y1 = rect
|
|
180
180
|
print(
|
|
181
181
|
f"out_of_screen: ({_num(x)},{_num(y)}) is on the iPhone Mirroring window's margin, not on the "
|
|
182
|
-
f"phone screen (x {x0:.3f}-{x1:.3f}, y {y0:.3f}-{y1:.3f})
|
|
183
|
-
f"
|
|
182
|
+
f"phone screen (x {x0:.3f}-{x1:.3f}, y {y0:.3f}-{y1:.3f}) — call phone_screenshot and pass 0-1 "
|
|
183
|
+
f"coordinates inside the screen; nothing was sent",
|
|
184
184
|
file=sys.stderr,
|
|
185
185
|
)
|
|
186
186
|
return 2
|
|
@@ -200,8 +200,7 @@ def _refuse_off_screen(x: float, y: float, *, measure: bool) -> int | None:
|
|
|
200
200
|
print(
|
|
201
201
|
f"out_of_screen: ({_num(x)},{_num(y)}) may be on the iPhone Mirroring window's margin: the phone "
|
|
202
202
|
f"screen's edges are not known ({_EDGES_UNTRUSTED}), and while they are not, a point outside x {x0:.3f}-{x1:.3f}, "
|
|
203
|
-
f"y {y0:.3f}-{y1:.3f} is not sent —
|
|
204
|
-
f"nothing was sent. Move the pointer off the top of the mirror window and try again, or aim further inside",
|
|
203
|
+
f"y {y0:.3f}-{y1:.3f} is not sent — call phone_screenshot and aim further inside; nothing was sent",
|
|
205
204
|
file=sys.stderr,
|
|
206
205
|
)
|
|
207
206
|
return 2
|
|
@@ -210,7 +209,7 @@ def _refuse_off_screen(x: float, y: float, *, measure: bool) -> int | None:
|
|
|
210
209
|
def _mirror_not_live(overlay: dict) -> int:
|
|
211
210
|
label = overlay.get("overlay") or "overlay shown"
|
|
212
211
|
print(
|
|
213
|
-
f"mirror_not_live: {label} — call phone_launch
|
|
212
|
+
f"mirror_not_live: {label} — call phone_launch first",
|
|
214
213
|
file=sys.stderr,
|
|
215
214
|
)
|
|
216
215
|
return 3
|
|
@@ -481,8 +480,8 @@ def _refuse_collapsed(asked) -> int:
|
|
|
481
480
|
print(
|
|
482
481
|
f"out_of_screen: the swipe from ({_num(asked[0])},{_num(asked[1])}) to ({_num(asked[2])},{_num(asked[3])}) "
|
|
483
482
|
f"starts or ends on the iPhone Mirroring window's margin, or where it may be: with its points moved "
|
|
484
|
-
f"onto the phone screen it would be shorter than a swipe (under about {_MIN_MOVED_SWIPE_PT:g} pt)
|
|
485
|
-
f"not a swipe; nothing was sent",
|
|
483
|
+
f"onto the phone screen it would be shorter than a swipe (under about {_MIN_MOVED_SWIPE_PT:g} pt): a press, "
|
|
484
|
+
f"not a swipe — call phone_screenshot and start and end it inside the screen; nothing was sent",
|
|
486
485
|
file=sys.stderr,
|
|
487
486
|
)
|
|
488
487
|
return 2
|
|
@@ -672,7 +671,7 @@ def _cmd_type(args) -> int:
|
|
|
672
671
|
print(
|
|
673
672
|
"type_not_confirmed: the paste did not show on screen within the 2.5s "
|
|
674
673
|
f"confirmation window{watched} — {advice}; the clipboard still holds the "
|
|
675
|
-
"typed text and
|
|
674
|
+
"typed text and the person's previous clipboard was not restored",
|
|
676
675
|
file=sys.stderr,
|
|
677
676
|
)
|
|
678
677
|
return 4
|
|
@@ -870,7 +869,7 @@ def _open_and_report(args) -> int:
|
|
|
870
869
|
if os.environ.get("NORACU_TOPHIT_LABELS", "").strip():
|
|
871
870
|
print(f"app not found: {args.app!r} (Spotlight showed no Top Hit labelled "
|
|
872
871
|
f"{', '.join(repr(x) for x in gestures.TOP_HIT_LABELS)} — no app by that "
|
|
873
|
-
f"name, or NORACU_TOPHIT_LABELS does not match
|
|
872
|
+
f"name, or NORACU_TOPHIT_LABELS does not match the iPhone's label){stuck}")
|
|
874
873
|
else:
|
|
875
874
|
# 2026-11-08: the top-field Spotlight shows no Top Hit header at all; there the
|
|
876
875
|
# evidence is the field completing the name with "— Open"
|
|
@@ -926,6 +925,12 @@ def _open_and_report(args) -> int:
|
|
|
926
925
|
else "the clipboard was put back unless something else had copied meanwhile")
|
|
927
926
|
+ "; retry phone_open", file=sys.stderr)
|
|
928
927
|
return 6
|
|
928
|
+
if result == "not_cleared":
|
|
929
|
+
print(f"open_not_confirmed: Spotlight's search field still showed earlier text after it was "
|
|
930
|
+
f"cleared twice (empty, it reads \"Search or Ask\" or \"Search\" — in English only), so {args.app!r} "
|
|
931
|
+
f"was not typed after that text and nothing was tapped; {home_note}; retry phone_open",
|
|
932
|
+
file=sys.stderr)
|
|
933
|
+
return 4
|
|
929
934
|
if result == "clipboard_changed":
|
|
930
935
|
print(f"open_not_confirmed: another app or device changed the clipboard before ⌘V, so "
|
|
931
936
|
f"{args.app!r} was not pasted or tapped and the new clipboard was left as it is; "
|
|
@@ -971,17 +976,16 @@ def _cmd_launch(_args) -> int:
|
|
|
971
976
|
if is_setup_screen():
|
|
972
977
|
# A welcome / setup screen is the user's to finish; nothing was clicked.
|
|
973
978
|
print(
|
|
974
|
-
"mirror_setup_required: iPhone Mirroring
|
|
975
|
-
"
|
|
976
|
-
"Mirroring window yourself (noracu never clicks through setup screens), "
|
|
979
|
+
"mirror_setup_required: iPhone Mirroring shows a setup or welcome screen — stop "
|
|
980
|
+
"and tell the person to finish it (noracu never clicks through setup screens), "
|
|
977
981
|
"then call phone_launch again",
|
|
978
982
|
file=sys.stderr,
|
|
979
983
|
)
|
|
980
984
|
return 3
|
|
981
985
|
print(
|
|
982
|
-
"mirror_not_live: iPhone Mirroring is not live yet —
|
|
983
|
-
"
|
|
984
|
-
"
|
|
986
|
+
"mirror_not_live: iPhone Mirroring is not live yet — paused: tell the person to lock "
|
|
987
|
+
"the iPhone and keep it near the Mac; reconnecting: call phone_status in a few "
|
|
988
|
+
"seconds; then phone_launch again",
|
|
985
989
|
file=sys.stderr,
|
|
986
990
|
)
|
|
987
991
|
return 3
|
|
@@ -1130,7 +1134,7 @@ def _run(args) -> int:
|
|
|
1130
1134
|
return args.func(args)
|
|
1131
1135
|
except input.KeyboardLayoutMismatch as exc:
|
|
1132
1136
|
# raised before any event was posted or the clipboard was written
|
|
1133
|
-
print(f"keyboard_layout: {exc}", file=sys.stderr)
|
|
1137
|
+
print(f"keyboard_layout: {exc} — stop and tell the person; do not retry", file=sys.stderr)
|
|
1134
1138
|
return 2
|
|
1135
1139
|
except input.FocusLost as exc:
|
|
1136
1140
|
# The frontmost check failed right before an event — either
|
|
@@ -698,6 +698,71 @@ def _top_field_lines(hits):
|
|
|
698
698
|
return lines
|
|
699
699
|
|
|
700
700
|
|
|
701
|
+
# The search field's own line in the top-field layout: read at ny 0.12–0.13 on the device (2026-11-08,
|
|
702
|
+
# 2026-11-21). After a clear only a line at that height is taken for the field, and its placeholder for
|
|
703
|
+
# an empty one; lines higher up in the zone are not the field.
|
|
704
|
+
FIELD_LINE_MIN_NY = 0.09
|
|
705
|
+
# The empty field's placeholder, English as the "Open" completion is: "Search or Ask" in the top-field
|
|
706
|
+
# layout, "Search" in the bottom-field one (read there as "Q Search": the magnifier glyph in front taken
|
|
707
|
+
# for a Q, as in the field echo above). "Search" counts in either.
|
|
708
|
+
FIELD_PLACEHOLDERS = ("search or ask", "search")
|
|
709
|
+
_MAGNIFIER_Q = re.compile(r"^q[\s.,:;·•]*")
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def _placeholder(text):
|
|
713
|
+
"""``text`` (_norm_label'ed) is the empty field's placeholder, with or without the magnifier glyph
|
|
714
|
+
read as "Q" in front of it."""
|
|
715
|
+
return text in FIELD_PLACEHOLDERS or _MAGNIFIER_Q.sub("", text, count=1) in FIELD_PLACEHOLDERS
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
def _field_left(hits):
|
|
719
|
+
"""What Spotlight's search field still shows after a clear: [] when the placeholder is read in
|
|
720
|
+
the field of either layout — at the top field's height, or in the bottom field
|
|
721
|
+
(ny >= SEARCH_FIELD_NY) — or when no line is at the top field's height (no evidence either way);
|
|
722
|
+
otherwise the queries of the lines there. The bottom-field layout can have a section header at
|
|
723
|
+
that height (its Top Hit header was measured at ny ≈ 0.14), so its own field decides there."""
|
|
724
|
+
if any(h.ny >= SEARCH_FIELD_NY and _placeholder(_norm_label(h.text)) for h in hits):
|
|
725
|
+
return []
|
|
726
|
+
lines = [query for ny, query, _a in _top_field_lines(hits) if ny >= FIELD_LINE_MIN_NY]
|
|
727
|
+
if any(_placeholder(q) for q in lines):
|
|
728
|
+
return []
|
|
729
|
+
return [q for q in lines if q]
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
def clear_search_field(*, clear=None, read_screen=None, sleep=time.sleep, settle_s: float = 0.3) -> bool:
|
|
733
|
+
"""Empty Spotlight's search field, and check that it is empty.
|
|
734
|
+
|
|
735
|
+
Cmd+A + Delete (``clear``, default inp.clear_text) does not always empty it: on the device
|
|
736
|
+
(2026-11-21, once in eight tries) the previous query stayed, and the name typed next went in
|
|
737
|
+
after it. So the field is read after the clear. Its placeholder ("Search or Ask", or "Search"), or
|
|
738
|
+
no line at the field's height, counts as empty; any other text there gets one more clear, and text still
|
|
739
|
+
there after that one means the field could not be emptied: False. A read that fails is no
|
|
740
|
+
evidence (True, as before this check). The caller has made sure Spotlight is open
|
|
741
|
+
(open_spotlight_checked), so the clear can only land in its field — a second one as well.
|
|
742
|
+
``read_screen`` defaults to vision.read_screen.
|
|
743
|
+
"""
|
|
744
|
+
if clear is None:
|
|
745
|
+
clear = inp.clear_text
|
|
746
|
+
if read_screen is None:
|
|
747
|
+
read_screen = vision.read_screen
|
|
748
|
+
|
|
749
|
+
def left():
|
|
750
|
+
try:
|
|
751
|
+
return _field_left(read_screen())
|
|
752
|
+
except Exception as exc:
|
|
753
|
+
if not verify.is_capture_error(exc):
|
|
754
|
+
raise
|
|
755
|
+
return []
|
|
756
|
+
|
|
757
|
+
clear()
|
|
758
|
+
sleep(settle_s)
|
|
759
|
+
if not left():
|
|
760
|
+
return True
|
|
761
|
+
clear()
|
|
762
|
+
sleep(settle_s)
|
|
763
|
+
return not left()
|
|
764
|
+
|
|
765
|
+
|
|
701
766
|
def _top_field_for(hits, name):
|
|
702
767
|
"""(ny, action) of the top search field when it shows ``name`` (exactly, after _norm_label),
|
|
703
768
|
with or without a completion; None otherwise."""
|
|
@@ -810,7 +875,9 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
810
875
|
|
|
811
876
|
The search field is cleared (Cmd+A + Delete) before typing: iOS
|
|
812
877
|
keeps the previous Spotlight query, so the new name would be
|
|
813
|
-
appended to it and no result row would match.
|
|
878
|
+
appended to it and no result row would match. The field is read
|
|
879
|
+
back after the clear (clear_search_field): text that two clears
|
|
880
|
+
leave in it ends the open before typing (not_cleared). Results are
|
|
814
881
|
then read up to twice (find_app_hit) because they can lag the
|
|
815
882
|
keystrokes — or, when type_text did not see the paste arrive, once a
|
|
816
883
|
second for up to OPEN_LATE_PASTE_S: once the search field shows
|
|
@@ -865,7 +932,10 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
865
932
|
off and nothing was tapped; Spotlight is left as it is — going Home
|
|
866
933
|
would pull the mirror forward again); "clipboard_changed" (another app or
|
|
867
934
|
device wrote the clipboard before ⌘V: nothing was pasted or tapped, the
|
|
868
|
-
new clipboard is left alone; back on the Home Screen);
|
|
935
|
+
new clipboard is left alone; back on the Home Screen); "not_cleared"
|
|
936
|
+
(the search field still showed text after two clears, so the name
|
|
937
|
+
was not typed after it and nothing was tapped; back on the Home
|
|
938
|
+
Screen); or
|
|
869
939
|
"spotlight_unavailable" (Spotlight could not be opened; nothing was
|
|
870
940
|
typed or tapped).
|
|
871
941
|
|
|
@@ -893,7 +963,10 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
893
963
|
return ok
|
|
894
964
|
|
|
895
965
|
if clear_text is None:
|
|
896
|
-
|
|
966
|
+
# the field is read after the clear (clear_search_field), with the screen reader as it is
|
|
967
|
+
# here — not the wrapper below, whose reads count as evidence that the paste arrived
|
|
968
|
+
def clear_text(_read=read_screen):
|
|
969
|
+
return clear_search_field(read_screen=_read, sleep=sleep)
|
|
897
970
|
pending: list = []
|
|
898
971
|
if type_text is None:
|
|
899
972
|
def type_text(text):
|
|
@@ -942,7 +1015,15 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
942
1015
|
# NORACU_PHONE_TIMEOUT_MS, or a slow start) — do not clear or type at all
|
|
943
1016
|
tidy()
|
|
944
1017
|
return "deadline"
|
|
945
|
-
|
|
1018
|
+
# iOS kept the last query; new input would append. A clear that leaves text in the field (False)
|
|
1019
|
+
# stops here: the name typed after that text would not be found
|
|
1020
|
+
if clear_text() is False:
|
|
1021
|
+
tidy()
|
|
1022
|
+
return "not_cleared"
|
|
1023
|
+
if out_of_time():
|
|
1024
|
+
# reading the field after the clear can take the rest of the budget: nothing is typed then either
|
|
1025
|
+
tidy()
|
|
1026
|
+
return "deadline"
|
|
946
1027
|
sleep(0.3)
|
|
947
1028
|
try:
|
|
948
1029
|
typed = type_text(name)
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
Each gesture is followed by a screenshot hash comparison to confirm the
|
|
4
4
|
screen actually changed. This closes the loop: an action that reports
|
|
5
5
|
success but leaves the screen identical is a dropped event, and callers
|
|
6
|
-
should retry or re-observe
|
|
7
|
-
that OpenAI's Computer Use enforces with its revision mechanism.
|
|
6
|
+
should retry or re-observe.
|
|
8
7
|
"""
|
|
9
8
|
|
|
10
9
|
from __future__ import annotations
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "noracu",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"mcpName": "io.github.sgInnora/noracu",
|
|
5
|
-
"description": "Local MCP server:
|
|
5
|
+
"description": "Local MCP server: operates Mac apps and a browser, sends no Mac input while you use the keyboard or mouse, and reports whether each input was delivered; iPhone layers are experimental and off by default.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "src/server.mjs",
|
|
8
8
|
"bin": {
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "node src/server.mjs",
|
|
13
|
-
"
|
|
14
|
-
"test
|
|
13
|
+
"build:mcpb": "node scripts/build-mcpb.mjs",
|
|
14
|
+
"test": "node test/engine-unit.mjs && node test/bg-inject-unit.mjs && node test/release-gate-unit.mjs && node test/gen-tools-unit.mjs && node test/cli-unit.mjs && node test/cli-no-cliclick.mjs && node test/check-pack-unit.mjs && node test/mcpb-unit.mjs && node test/docs-codes-unit.mjs && node test/error-texts.mjs && node test/error-literals-unit.mjs && node test/ios-xcuitest-unit.mjs && node test/ios-session-unit.mjs && node test/ios-setup-unit.mjs && node test/ios-runner-rules.mjs && node test/ios-e2e.mjs && node test/e2e.mjs && node test/browser-scroll-slow.mjs",
|
|
15
|
+
"test:ci": "node test/engine-unit.mjs && node test/bg-inject-unit.mjs && node test/release-gate-unit.mjs && node test/gen-tools-unit.mjs && node test/cli-unit.mjs && node test/cli-no-cliclick.mjs && node test/check-pack-unit.mjs && node test/mcpb-unit.mjs && node test/docs-codes-unit.mjs && node test/error-texts.mjs && node test/error-literals-unit.mjs && node test/ios-xcuitest-unit.mjs && node test/ios-session-unit.mjs && node test/ios-setup-unit.mjs && node test/ios-runner-rules.mjs && node test/ios-e2e.mjs && NORACU_CI=1 node test/e2e.mjs && node test/browser-scroll-slow.mjs",
|
|
15
16
|
"test:imctl": "cd imctl && ${NORACU_PYTHON:-python3} tests/test_smoke.py",
|
|
16
|
-
"check": "node --check src/server.mjs && node --check src/mac-ax.js && node --check src/approval.js && node --check src/bg-inject.js && node --check src/ios-xcuitest.js && node --check src/ios-session.js && node --check src/ios-setup.js && node --check src/doctor.js && node --check scripts/gen-tools.mjs && node --check scripts/release-gate.mjs && node --check scripts/check-pack.mjs && node --check scripts/pack-rules.mjs && node --check scripts/check-public.mjs && node scripts/check-public.mjs && python3 -c \"import ast,sys; [ast.parse(open(f).read(), f) for f in sys.argv[1:]]\" imctl/src/imctl/*.py",
|
|
17
|
+
"check": "node --check src/server.mjs && node --check src/mcpb-entry.js && node --check src/mac-ax.js && node --check src/approval.js && node --check src/bg-inject.js && node --check src/ios-xcuitest.js && node --check src/ios-session.js && node --check src/ios-setup.js && node --check src/doctor.js && node --check scripts/gen-tools.mjs && node --check scripts/release-gate.mjs && node --check scripts/check-pack.mjs && node --check scripts/pack-rules.mjs && node --check scripts/check-public.mjs && node --check scripts/mcpb-manifest.mjs && node --check scripts/build-mcpb.mjs && node scripts/check-public.mjs && node --check scripts/check-copy.mjs && node scripts/check-copy.mjs && python3 -c \"import ast,sys; [ast.parse(open(f).read(), f) for f in sys.argv[1:]]\" imctl/src/imctl/*.py",
|
|
17
18
|
"prepublishOnly": "npm run check && node scripts/release-gate.mjs && node scripts/check-pack.mjs && node scripts/gen-tools.mjs && git diff --exit-code docs/tools.md"
|
|
18
19
|
},
|
|
19
20
|
"engines": {
|
|
@@ -24,18 +25,21 @@
|
|
|
24
25
|
"mcp-server",
|
|
25
26
|
"model-context-protocol",
|
|
26
27
|
"computer-use",
|
|
27
|
-
"
|
|
28
|
+
"mac",
|
|
28
29
|
"macos",
|
|
29
30
|
"macos-automation",
|
|
31
|
+
"accessibility",
|
|
32
|
+
"desktop-automation",
|
|
33
|
+
"ui-automation",
|
|
30
34
|
"browser-automation",
|
|
35
|
+
"playwright",
|
|
31
36
|
"claude",
|
|
32
37
|
"claude-desktop",
|
|
33
38
|
"claude-code",
|
|
34
39
|
"cursor",
|
|
40
|
+
"ai-agent",
|
|
35
41
|
"iphone",
|
|
36
42
|
"iphone-mirroring",
|
|
37
|
-
"accessibility",
|
|
38
|
-
"desktop-automation",
|
|
39
43
|
"xcuitest"
|
|
40
44
|
],
|
|
41
45
|
"license": "MIT",
|
package/src/approval.js
CHANGED
|
@@ -118,13 +118,14 @@ export function gateActive() {
|
|
|
118
118
|
export function stopFileBlocked() {
|
|
119
119
|
const p = process.env.NORACU_STOP_FILE;
|
|
120
120
|
if (p === undefined) return null;
|
|
121
|
-
if (!p.trim()) return "stop_check_error: NORACU_STOP_FILE is set but blank —
|
|
121
|
+
if (!p.trim()) return "stop_check_error: NORACU_STOP_FILE is set but blank — stop and tell the person to give it a path or unset it; do not retry or work around it (delivery=not_delivered, retry=safe)";
|
|
122
122
|
try {
|
|
123
123
|
statSync(p);
|
|
124
|
-
|
|
124
|
+
// the file is the person's brake: the agent stops, says so, and leaves the file alone
|
|
125
|
+
return `user_stopped: the person at the Mac stopped noracu's input (${p.slice(0, 80)} exists) — stop and tell the person; do not remove that file, retry or work around it (delivery=not_delivered, retry=safe)`;
|
|
125
126
|
} catch (e) {
|
|
126
127
|
if (e && e.code === "ENOENT") return null;
|
|
127
|
-
return `stop_check_error: could not check ${p} (${e && e.code ? e.code : "unknown"}) —
|
|
128
|
+
return `stop_check_error: could not check ${p.slice(0, 80)} (${e && e.code ? e.code : "unknown"}) — stop and tell the person; do not retry or work around it (delivery=not_delivered, retry=safe)`;
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -139,7 +140,11 @@ function matches(pattern, bundleId, appName) {
|
|
|
139
140
|
|
|
140
141
|
// a rule written as a bundle id ("com.apple.Terminal", "com.example.*"); anything else names apps by their name
|
|
141
142
|
const byBundle = (p) => /^[\w*?-]+(\.[\w*?-]+)+$/.test(String(p).trim());
|
|
142
|
-
|
|
143
|
+
// A refusal only the person can lift: what is wrong, then what the agent does.
|
|
144
|
+
const PERSON = "stop and tell the person; do not retry or work around it (delivery=not_delivered, retry=safe)";
|
|
145
|
+
const unnamed = (what) => ({ error: `input_denied: the name of the app that would receive the input could not be read, so ${what} cannot check it — ${PERSON}` });
|
|
146
|
+
// a broken approval file: its path (cut to 80 characters) and what is wrong with it
|
|
147
|
+
const broken = (code, file, what) => ({ error: `${code}: ${String(file).slice(0, 80)} ${what} — stop and tell the person to fix NORACU_APPROVAL_FILE; do not retry or work around it (delivery=not_delivered, retry=safe)` });
|
|
143
148
|
|
|
144
149
|
// --- approval file (opt-in). Returns { verdict: "allow"|"ask"|"deny", reason } or { error } (fail closed). ---
|
|
145
150
|
// needName: the app has a name to read (a Mac app). Without one, a rule that names apps cannot rule it out, so the
|
|
@@ -150,7 +155,7 @@ export function evaluateApproval({ bundleId, appName, needName = false } = {}) {
|
|
|
150
155
|
// both; this keeps the module safe on its own)
|
|
151
156
|
const bid = String(bundleId ?? "").trim(), name = String(appName ?? "").trim();
|
|
152
157
|
if (!bid && (!name || gateActive())) {
|
|
153
|
-
return { error: `input_denied: the app that would receive the input ${name ? `("${name}") has no readable bundle id, so
|
|
158
|
+
return { error: `input_denied: the app that would receive the input ${name ? `("${name}") has no readable bundle id, so app rules cannot check it` : "could not be identified"} — ${PERSON}` };
|
|
154
159
|
}
|
|
155
160
|
const deny = denyList();
|
|
156
161
|
// how many entries at the head of the list the user wrote (NORACU_DENY_APPS): those always win. The rest is the
|
|
@@ -159,18 +164,18 @@ export function evaluateApproval({ bundleId, appName, needName = false } = {}) {
|
|
|
159
164
|
let byDefault = null;
|
|
160
165
|
// the trimmed bundle id and name are what every rule is matched against, as they are what was checked above
|
|
161
166
|
// (" com.apple.Terminal" was checked as known and then missed the deny list)
|
|
167
|
+
// the reason is read after the app's name ("Terminal" is …): which list named it, and for the default list what
|
|
168
|
+
// the person can do about it
|
|
162
169
|
for (const [i, d] of deny.list.entries()) if (matches(d, bid, name)) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (i < userCount) return { verdict: "deny", reason: `denied by ${src} ("${d}")` };
|
|
166
|
-
byDefault = { verdict: "deny", reason: `denied by ${src} ("${d}") — the person at the Mac can let this one app through by naming it exactly (no * or ?) under "allow" in an approval file (NORACU_APPROVAL_FILE)` };
|
|
170
|
+
if (i < userCount) return { verdict: "deny", reason: `on NORACU_DENY_APPS ("${d}")` };
|
|
171
|
+
byDefault = { verdict: "deny", reason: `on the default deny list of terminals and IDEs ("${d}"); the person can allow it by naming it exactly in an approval file` };
|
|
167
172
|
break;
|
|
168
173
|
}
|
|
169
174
|
// the default list names some apps by name (editions and forks whose bundle id differs)
|
|
170
175
|
if (needName && !name && !byDefault && deny.list.some((d) => !byBundle(d))) return unnamed("the deny list's entries that name apps");
|
|
171
176
|
const file = process.env.NORACU_APPROVAL_FILE;
|
|
172
177
|
if (file === undefined) return byDefault || { verdict: "allow" };
|
|
173
|
-
if (!file.trim()) return { error:
|
|
178
|
+
if (!file.trim()) return { error: `approval_file_error: NORACU_APPROVAL_FILE is set but blank — stop and tell the person to give it a path or unset it; do not retry or work around it (delivery=not_delivered, retry=safe)` };
|
|
174
179
|
let conf;
|
|
175
180
|
let fd = null;
|
|
176
181
|
try {
|
|
@@ -179,30 +184,30 @@ export function evaluateApproval({ bundleId, appName, needName = false } = {}) {
|
|
|
179
184
|
// to it; the open descriptor is then refused as not a regular file
|
|
180
185
|
fd = openSync(file, fsc.O_RDONLY | fsc.O_NOFOLLOW | fsc.O_NONBLOCK);
|
|
181
186
|
const st = fstatSync(fd);
|
|
182
|
-
if (!st.isFile()) return
|
|
183
|
-
if (st.mode & 0o077) return
|
|
184
|
-
if (st.uid !== process.getuid?.()) return
|
|
187
|
+
if (!st.isFile()) return broken("approval_file_error", file, "is not a regular file");
|
|
188
|
+
if (st.mode & 0o077) return broken("approval_file_insecure", file, `must be mode 0600 (it is 0${(st.mode & 0o777).toString(8)})`);
|
|
189
|
+
if (st.uid !== process.getuid?.()) return broken("approval_file_owner", file, "is not owned by this user");
|
|
185
190
|
// a list of apps is small: a file over 64 KB is not read at all (it is read again before every input)
|
|
186
|
-
if (st.size > 65536) return
|
|
191
|
+
if (st.size > 65536) return broken("approval_file_error", file, "is larger than 64 KB");
|
|
187
192
|
const text = readFileSync(fd, "utf8");
|
|
188
193
|
// JSON.parse's message quotes a piece of the file, and this answer goes to the agent: it is not passed on
|
|
189
194
|
try { conf = JSON.parse(text); } catch {
|
|
190
|
-
return
|
|
195
|
+
return broken("approval_file_error", file, "is not valid JSON");
|
|
191
196
|
}
|
|
192
197
|
} catch (e) {
|
|
193
198
|
const why = e && e.code === "ENOENT" ? "does not exist" : e && e.code === "ELOOP" ? "is a symlink" : `is unreadable or not JSON (${e && e.code ? e.code : String(e).slice(0, 80)})`;
|
|
194
|
-
return
|
|
199
|
+
return broken("approval_file_error", file, why);
|
|
195
200
|
} finally {
|
|
196
201
|
if (fd !== null) try { closeSync(fd); } catch { /* already closed */ }
|
|
197
202
|
}
|
|
198
|
-
if (!conf || typeof conf !== "object" || Array.isArray(conf)) return
|
|
203
|
+
if (!conf || typeof conf !== "object" || Array.isArray(conf)) return broken("approval_file_error", file, "must hold a JSON object");
|
|
199
204
|
const unknown = Object.keys(conf).filter((k) => !["allow", "ask", "deny"].includes(k));
|
|
200
|
-
if (unknown.length) return
|
|
201
|
-
for (const key of ["allow", "ask", "deny"]) if (conf[key] !== undefined && !Array.isArray(conf[key])) return
|
|
205
|
+
if (unknown.length) return broken("approval_file_error", file, `has unknown key(s) ${unknown.slice(0, 3).map((k) => JSON.stringify(k).slice(0, 30)).join(", ")} (only "allow", "ask" and "deny")`);
|
|
206
|
+
for (const key of ["allow", "ask", "deny"]) if (conf[key] !== undefined && !Array.isArray(conf[key])) return broken("approval_file_error", file, `has "${key}" that is not an array`);
|
|
202
207
|
// an empty or non-string pattern is a broken file, not a pattern
|
|
203
|
-
for (const key of ["allow", "ask", "deny"]) for (const p of conf[key] || []) if (typeof p !== "string" || !p.trim() || p.length > 200) return
|
|
208
|
+
for (const key of ["allow", "ask", "deny"]) for (const p of conf[key] || []) if (typeof p !== "string" || !p.trim() || p.length > 200) return broken("approval_file_error", file, `has an empty or non-string pattern in "${key}" (${JSON.stringify(p)?.slice(0, 40)})`);
|
|
204
209
|
if (needName && !name && [...(conf.deny || []), ...(conf.ask || [])].some((p) => !byBundle(p))) return unnamed(`the entries of ${file} that name apps`);
|
|
205
|
-
for (const d of conf.deny || []) if (matches(d, bid, name)) return { verdict: "deny", reason: `denied by approval file ("${d}")` };
|
|
210
|
+
for (const d of conf.deny || []) if (matches(d, bid, name)) return { verdict: "deny", reason: `denied by the approval file ("${d}")` };
|
|
206
211
|
// on the default deny list: only an "allow" entry that names this app — its bundle id or its name, without a
|
|
207
212
|
// wildcard — lets it through; "*" or "com.example.*" in "allow" does not open a terminal
|
|
208
213
|
if (byDefault) {
|
|
@@ -210,9 +215,9 @@ export function evaluateApproval({ bundleId, appName, needName = false } = {}) {
|
|
|
210
215
|
return byDefault;
|
|
211
216
|
}
|
|
212
217
|
for (const a of conf.ask || []) if (matches(a, bid, name)) {
|
|
213
|
-
return { verdict: "ask", reason: `approval_required: "${bundleId || appName}" is listed under "ask" in
|
|
218
|
+
return { verdict: "ask", reason: `approval_required: "${bundleId || appName}" is listed under "ask" in the approval file — stop and tell the person, who decides by moving it to "allow"; do not edit the file, retry or work around it (delivery=not_delivered, retry=safe)` };
|
|
214
219
|
}
|
|
215
220
|
for (const a of conf.allow || []) if (matches(a, bid, name)) return { verdict: "allow", reason: `allowed by approval file ("${a}")` };
|
|
216
221
|
// nothing matched: ask (an approval file that lists apps but not this one means "ask")
|
|
217
|
-
return { verdict: "ask", reason: `approval_required:
|
|
222
|
+
return { verdict: "ask", reason: `approval_required: "${bundleId || appName}" is not listed in the approval file — stop and tell the person, who decides by adding it to "allow" or "deny"; do not edit the file, retry or work around it (delivery=not_delivered, retry=safe)` };
|
|
218
223
|
}
|
package/src/doctor.js
CHANGED
|
@@ -18,6 +18,41 @@ const VERSION = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")).ver
|
|
|
18
18
|
// "not found" answer names.
|
|
19
19
|
export const CLICLICK_PLACES = ["/opt/homebrew/bin/cliclick", "/usr/local/bin/cliclick"];
|
|
20
20
|
export function defaultCliclick(exists = existsSync) { return CLICLICK_PLACES.find((p) => exists(p)) || CLICLICK_PLACES[0]; }
|
|
21
|
+
// What macOS counts when noracu reads the screen or acts on an app. Claude Desktop starts each local server as a
|
|
22
|
+
// process of its own, through a launcher in Claude.app/Contents/Helpers: what that launcher started (the node of a
|
|
23
|
+
// configuration, or npx, a shell or a version manager's shim in front of it) counts, for itself and for everything it
|
|
24
|
+
// starts in turn, noracu included; an extension counts as Claude Desktop's helper process. Under Cursor, or a
|
|
25
|
+
// terminal running Claude Code, the app counts. execPath: the server's process.execPath; ancestors: the executables
|
|
26
|
+
// of its parent, its parent's parent and on up, as far as they were read (one path is taken as the parent's).
|
|
27
|
+
export function grantTarget(execPath = "", ancestors = []) {
|
|
28
|
+
const chain = (Array.isArray(ancestors) ? ancestors : [ancestors]).map(String);
|
|
29
|
+
const helper = String(execPath).match(/\/Claude\.app\/Contents\/Frameworks\/(Claude Helper[^/]*)\.app\//);
|
|
30
|
+
if (helper) return { kind: "extension", name: `"${helper[1]}"`, why: "the process Claude Desktop runs this extension in; turning on Claude is not enough", reopen: "Claude Desktop" };
|
|
31
|
+
const at = chain.findIndex((p) => /\/Claude\.app\/Contents\/Helpers\//.test(p));
|
|
32
|
+
if (at >= 0) {
|
|
33
|
+
// the launcher's own child: noracu itself, or what stands between them
|
|
34
|
+
const exe = at === 0 ? String(execPath) : chain[at - 1];
|
|
35
|
+
const shown = exe.length > 60 ? `…${exe.slice(-59)}` : exe;
|
|
36
|
+
const program = exe.split("/").pop() || "node";
|
|
37
|
+
return { kind: "node", program, name: `${program} (${shown})`, why: "Claude Desktop starts noracu with it as a process of its own; turning on Claude is not enough", reopen: "Claude Desktop" };
|
|
38
|
+
}
|
|
39
|
+
return { kind: "host", name: "the MCP host app (Claude Desktop, Cursor or the terminal, not node)", why: "", reopen: "the host" };
|
|
40
|
+
}
|
|
41
|
+
// mac_status's hint when a permission is off: off names the permissions ("Accessibility", "Screen Recording"), t is
|
|
42
|
+
// grantTarget's answer
|
|
43
|
+
export function permissionHint(off, t) {
|
|
44
|
+
const what = off.join(" and ");
|
|
45
|
+
return t.kind === "host" ? `the person grants ${what} to the MCP host app (Claude Desktop, Cursor or the terminal — not to node), then quits and reopens the host`
|
|
46
|
+
: `the person turns on ${what} for ${t.name} (${t.why}), then quits and reopens ${t.reopen}`;
|
|
47
|
+
}
|
|
48
|
+
// permission_denied's text after its code when Accessibility is off under Claude Desktop (t: grantTarget's node or
|
|
49
|
+
// extension answer; the host's case keeps the engine's text). The program by name, mac_status for its path and the
|
|
50
|
+
// pane: with the code and the delivery marker it stays within 240 characters (a name over 32 characters is cut).
|
|
51
|
+
export function permissionDenied(t) {
|
|
52
|
+
const name = t.program || t.name;
|
|
53
|
+
const who = name.length > 32 ? `${name.slice(0, 31)}…` : name;
|
|
54
|
+
return `Accessibility is off for ${who} — stop and tell the person to turn it on (mac_status says which and where) and reopen ${t.reopen}; do not retry until then`;
|
|
55
|
+
}
|
|
21
56
|
const ISSUES = "https://github.com/sgInnora/noracu/issues/new/choose";
|
|
22
57
|
// the settings the server accepts (server.mjs LAYERS, PHONE_BACKEND); a value it would refuse or replace is not copied
|
|
23
58
|
// into a configuration
|
|
@@ -42,16 +77,18 @@ function stableNodePath() {
|
|
|
42
77
|
return real;
|
|
43
78
|
}
|
|
44
79
|
|
|
45
|
-
export const HELP = `noracu ${VERSION} —
|
|
80
|
+
export const HELP = `noracu ${VERSION} — local MCP server: operates Mac apps and a browser, yields to keyboard/mouse, and reports delivery.
|
|
81
|
+
The iPhone layers (Mirroring and XCUITest) are experimental and off by default.
|
|
46
82
|
|
|
47
83
|
It is started by an MCP client (Claude Desktop, Claude Code, Cursor), not by hand: it speaks JSON-RPC on stdin / stdout.
|
|
48
84
|
|
|
49
85
|
noracu the MCP server on stdio (what a client runs)
|
|
50
|
-
noracu doctor check this machine and print the client configuration with absolute paths
|
|
51
|
-
|
|
86
|
+
noracu doctor check this machine and print the client configuration with absolute paths;
|
|
87
|
+
exits 1 when something the server needs is missing
|
|
52
88
|
noracu doctor --json the same as JSON
|
|
53
|
-
noracu ios-setup … build the
|
|
89
|
+
noracu ios-setup … build the runner for the experimental XCUITest backend (see noracu ios-setup --help)
|
|
54
90
|
noracu --version print the version
|
|
91
|
+
noracu --help print this text
|
|
55
92
|
|
|
56
93
|
Documentation: https://github.com/sgInnora/noracu#readme
|
|
57
94
|
`;
|
|
@@ -98,6 +135,8 @@ export async function collect(env = process.env, sys = {}) {
|
|
|
98
135
|
...(cliclickUse || !needsCliclick ? [] : ["cliclick: not found — brew install cliclick"]),
|
|
99
136
|
...(layersOk ? [] : [`NORACU_LAYERS=${JSON.stringify(env.NORACU_LAYERS.slice(0, 40))}: not a comma-separated list of mac, browser, iphone — the server would not start; left out of the configuration`]),
|
|
100
137
|
...(backendOk ? [] : [`NORACU_PHONE_BACKEND=${JSON.stringify(env.NORACU_PHONE_BACKEND.slice(0, 20))}: not mirror or xcuitest — left out of the configuration`]),
|
|
138
|
+
// with downloads turned off, a missing Chromium is missing: browser_launch would refuse instead of fetching it
|
|
139
|
+
...(env.NORACU_DISABLE_AUTO_INSTALL === "1" && layers.includes("browser") && !browser.installed ? ["Chromium: not installed, and NORACU_DISABLE_AUTO_INSTALL=1 keeps browser_launch from downloading it — npx playwright install chromium"] : []),
|
|
101
140
|
];
|
|
102
141
|
// a line for a bug report: versions and what was found, no path and no user name
|
|
103
142
|
const report = `noracu ${VERSION} · node ${process.version} · ${platform === "darwin" ? `macOS ${macos || "?"}` : platform} ${process.arch} · cliclick ${cliclickUse ? "found" : "missing"} · Chromium ${browser.installed ? "installed" : "not installed"} · layers ${layersSet && layersOk ? env.NORACU_LAYERS.trim() : "mac,browser (default)"}${backendSet && backendOk ? ` · iPhone backend ${env.NORACU_PHONE_BACKEND.trim().toLowerCase()}` : ""}`;
|
|
@@ -125,17 +164,26 @@ export function render(d) {
|
|
|
125
164
|
d.platform.ok ? "" : d.platform.needed === false ? "NORACU_LAYERS=browser: the browser layer does not need macOS" : "the Mac and iPhone layers need macOS; start the server with NORACU_LAYERS=browser to use the browser layer alone"));
|
|
126
165
|
out.push(row("cliclick", d.cliclick.found ? d.cliclick.path : `not at ${d.cliclick.path}`,
|
|
127
166
|
d.cliclick.found ? (d.cliclick.path !== d.cliclick.default ? "not where the server looks by default — the configuration below passes it as NORACU_CLICLICK" : "") : d.cliclick.elsewhere ? (d.cliclick.elsewhere === d.cliclick.default ? `found at ${d.cliclick.elsewhere}, where the server looks by default — the configuration below leaves NORACU_CLICLICK out` : `found at ${d.cliclick.elsewhere} — the configuration below passes it as NORACU_CLICLICK`) : d.cliclick.needed === false ? "not needed: NORACU_LAYERS leaves the Mac layer out" : "physical Mac input needs it (mac_key, mac_drag, physical clicks and typing): brew install cliclick. Reading and semantic actions work without it."));
|
|
167
|
+
const noFetch = d.problems.some((p) => p.startsWith("Chromium:"));
|
|
128
168
|
out.push(row("browser", d.browser.installed ? "Playwright's Chromium is installed" : "Playwright's Chromium is not installed yet",
|
|
129
|
-
d.browser.installed ? "" : d.browser.error ? `playwright could not be loaded: ${d.browser.error}` : "
|
|
130
|
-
out.push(row("layers", d.layers, d.config.mcpServers.noracu.env?.NORACU_LAYERS ? "set in this shell — the configuration below passes it as NORACU_LAYERS" : d.problems.some((p) => p.startsWith("NORACU_LAYERS")) ? "not valid — the server would not start with it; the configuration below leaves it out" : "
|
|
169
|
+
d.browser.installed ? "" : d.browser.error ? `playwright could not be loaded: ${d.browser.error}` : noFetch ? "NORACU_DISABLE_AUTO_INSTALL=1 keeps browser_launch from downloading it: run npx playwright install chromium" : "the first browser_launch downloads it (or run npx playwright install chromium)"));
|
|
170
|
+
out.push(row("layers", d.layers === "mac,browser (default)" ? "mac,browser (default; the iPhone layers are experimental and off by default)" : d.layers, d.config.mcpServers.noracu.env?.NORACU_LAYERS ? "set in this shell — the configuration below passes it as NORACU_LAYERS" : d.problems.some((p) => p.startsWith("NORACU_LAYERS")) ? "not valid — the server would not start with it; the configuration below leaves it out" : ""));
|
|
131
171
|
out.push(row("server", d.server.path, d.server.in_npx_cache ? "this copy is in npx's cache, which npm may clear: for a client configuration that keeps working, install it in a folder you keep (npm install noracu) and run doctor from there" : ""));
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
|
|
172
|
+
// the verdict right under the checks: what is missing, each with the command that fixes it
|
|
173
|
+
const human = (p) => (p.startsWith("cliclick:") ? "cliclick — run brew install cliclick (or set NORACU_CLICLICK)"
|
|
174
|
+
: p.startsWith("Chromium:") ? "Chromium — run npx playwright install chromium (NORACU_DISABLE_AUTO_INSTALL=1 keeps browser_launch from downloading it)"
|
|
175
|
+
: p.startsWith("node:") ? "Node 20 or later"
|
|
176
|
+
: p.startsWith("system:") ? "macOS — the Mac and iPhone layers need it (NORACU_LAYERS=browser runs the browser layer alone)" : p);
|
|
177
|
+
const head = d.problems.every((p) => !p.startsWith("NORACU_")) ? "Missing" : "Missing or not valid";
|
|
178
|
+
out.push("", d.ok ? "Nothing is missing." : d.problems.length === 1 ? `${head}: ${human(d.problems[0])}` : `${head}:\n${d.problems.map((p) => ` - ${human(p)}`).join("\n")}`);
|
|
179
|
+
out.push("", "macOS permissions (Accessibility, Screen & System Audio Recording) go to what macOS sees running noracu:",
|
|
180
|
+
"with Claude Desktop, the node in its configuration (Claude Desktop starts each server as a process of its own);",
|
|
181
|
+
"with Cursor, Cursor; with Claude Code, the terminal. They apply after the client is quit and reopened. This check",
|
|
182
|
+
"cannot see them from here: once the client is set up, ask it to call mac_status.", "",
|
|
183
|
+
"Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json) and Cursor (~/.cursor/mcp.json):",
|
|
184
|
+
"add this entry under \"mcpServers\", then quit and reopen the client.", "",
|
|
136
185
|
JSON.stringify(d.config, null, 2), "", "Claude Code (for every project of yours; drop `-s user` to add it to the current project only):", "", ` ${d.claude_code}`, "");
|
|
137
|
-
out.push(
|
|
138
|
-
`Something does not work? Open an issue at ${ISSUES} with the tool, the steps, and this line (it holds no path or user name):`, "", ` ${d.report}`, "");
|
|
186
|
+
out.push(`Something does not work? Open an issue at ${ISSUES} with the tool, the steps, and this line (it holds no path or user name):`, "", ` ${d.report}`, "");
|
|
139
187
|
return out.join("\n");
|
|
140
188
|
}
|
|
141
189
|
|