noracu 0.2.4 → 0.2.6
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 +130 -0
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/SECURITY.md +35 -2
- package/docs/architecture.md +3 -3
- package/docs/tools.md +11 -11
- package/docs/usage.md +17 -8
- package/imctl/pyproject.toml +1 -1
- package/imctl/src/imctl/__init__.py +1 -1
- package/imctl/src/imctl/cli.py +40 -5
- package/imctl/src/imctl/gestures.py +46 -15
- package/imctl/src/imctl/input.py +109 -39
- package/imctl/src/imctl/verify.py +51 -0
- package/package.json +1 -1
- package/src/mac-ax.js +138 -24
- package/src/server.mjs +95 -36
|
@@ -433,7 +433,11 @@ def _norm_label(s: str) -> str:
|
|
|
433
433
|
return "".join(_LABEL_LOOKALIKES.get(ch, ch) for ch in s)
|
|
434
434
|
|
|
435
435
|
|
|
436
|
-
|
|
436
|
+
# Two matching labels closer than this in both axes are one label read twice (choose_app_hit, Y6).
|
|
437
|
+
SAME_SPOT_EPS = 0.03
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def choose_app_hit(hits: list, name: str, ambiguous: list | None = None) -> vision.OCRHit | None:
|
|
437
441
|
"""Pick the Spotlight result row for ``name`` from OCR hits.
|
|
438
442
|
|
|
439
443
|
iOS 26 draws the Spotlight search field at the BOTTOM of the screen
|
|
@@ -445,9 +449,15 @@ def choose_app_hit(hits: list, name: str) -> vision.OCRHit | None:
|
|
|
445
449
|
"x", "×", "X." or full-width "X"), and
|
|
446
450
|
- lie above the bottom search-field zone (ny < 0.88).
|
|
447
451
|
The comparison stays EXACT — substring/prefix matching is
|
|
448
|
-
forbidden: "X" must never hit "Xcode" or "X Corp".
|
|
449
|
-
|
|
450
|
-
|
|
452
|
+
forbidden: "X" must never hit "Xcode" or "X Corp". Returns None
|
|
453
|
+
when nothing qualifies.
|
|
454
|
+
|
|
455
|
+
Y6 (review R37, 2026-11-07): when labels that match sit at two or
|
|
456
|
+
more different spots inside the card (more than SAME_SPOT_EPS apart
|
|
457
|
+
in either axis), nothing says which one is the app, so none is
|
|
458
|
+
chosen: the result is None and, when the caller passes a list as
|
|
459
|
+
``ambiguous``, True is appended to it. Matches at one spot (the same
|
|
460
|
+
label read twice) are one label; the topmost of them is returned.
|
|
451
461
|
|
|
452
462
|
F35 (2026-11-05 real-device): an exact label is not an app. The
|
|
453
463
|
query "Pinduoduo" matched a Chrome *suggestion* row of that name
|
|
@@ -464,7 +474,7 @@ def choose_app_hit(hits: list, name: str) -> vision.OCRHit | None:
|
|
|
464
474
|
header = _tophit_header(hits)
|
|
465
475
|
if header is None:
|
|
466
476
|
return None
|
|
467
|
-
|
|
477
|
+
found = []
|
|
468
478
|
for hit in hits:
|
|
469
479
|
if _norm_label(hit.text) != want:
|
|
470
480
|
continue
|
|
@@ -472,13 +482,19 @@ def choose_app_hit(hits: list, name: str) -> vision.OCRHit | None:
|
|
|
472
482
|
continue # the search field echoing the query
|
|
473
483
|
if not header.ny < hit.ny <= header.ny + TOP_HIT_CARD_SPAN:
|
|
474
484
|
continue # outside the Top Hit card (F35)
|
|
475
|
-
|
|
476
|
-
|
|
485
|
+
found.append(hit)
|
|
486
|
+
if not found:
|
|
487
|
+
return None
|
|
488
|
+
best = min(found, key=lambda h: h.ny)
|
|
489
|
+
if any(abs(h.nx - best.nx) > SAME_SPOT_EPS or abs(h.ny - best.ny) > SAME_SPOT_EPS for h in found):
|
|
490
|
+
if ambiguous is not None:
|
|
491
|
+
ambiguous.append(True)
|
|
492
|
+
return None # Y6: several labels of the same name are never tapped
|
|
477
493
|
return best
|
|
478
494
|
|
|
479
495
|
|
|
480
496
|
def find_app_hit(read_screen, name, attempts=2, delay_s=1.0, sleep=time.sleep,
|
|
481
|
-
deadline=None, clock=time.monotonic):
|
|
497
|
+
deadline=None, clock=time.monotonic, ambiguous=None):
|
|
482
498
|
"""Read the screen up to ``attempts`` times for a Spotlight result row.
|
|
483
499
|
|
|
484
500
|
Each pass calls ``read_screen()`` for OCR hits and hands them to
|
|
@@ -501,6 +517,7 @@ def find_app_hit(read_screen, name, attempts=2, delay_s=1.0, sleep=time.sleep,
|
|
|
501
517
|
stays exact either way. Long names keep the exact original
|
|
502
518
|
read/sleep sequence. ``deadline`` (a ``clock()`` value) is checked
|
|
503
519
|
before every read; once reached, no further read happens.
|
|
520
|
+
``ambiguous`` is handed to every choose_app_hit() call (Y6).
|
|
504
521
|
"""
|
|
505
522
|
short = len(_norm_label(name)) <= 2
|
|
506
523
|
|
|
@@ -522,7 +539,7 @@ def find_app_hit(read_screen, name, attempts=2, delay_s=1.0, sleep=time.sleep,
|
|
|
522
539
|
for kwargs in reads:
|
|
523
540
|
if expired():
|
|
524
541
|
return None # out of time before this read (open_app reports it)
|
|
525
|
-
hit = choose_app_hit(read_screen(**kwargs), name)
|
|
542
|
+
hit = choose_app_hit(read_screen(**kwargs), name, ambiguous)
|
|
526
543
|
if hit is not None:
|
|
527
544
|
return hit
|
|
528
545
|
return None
|
|
@@ -712,8 +729,10 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
712
729
|
Top Hit card and the search field alike, so whether it was typed or
|
|
713
730
|
the app exists is unknown — nothing was tapped; back on the Home Screen);
|
|
714
731
|
"deadline" (the OPEN_DEADLINE_S budget ran out before a tap; back on
|
|
715
|
-
the Home Screen);
|
|
716
|
-
|
|
732
|
+
the Home Screen); "ambiguous" (Y6: the Top Hit card showed the name at
|
|
733
|
+
two or more spots and no read showed it at one — nothing was tapped;
|
|
734
|
+
back on the Home Screen); or "spotlight_unavailable" (Spotlight could
|
|
735
|
+
not be opened; nothing was typed or tapped).
|
|
717
736
|
|
|
718
737
|
``read_screen`` (default vision.read_screen), ``luma`` (default
|
|
719
738
|
verify.window_luma), ``sleep``, ``tap`` (default inp.tap),
|
|
@@ -751,6 +770,7 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
751
770
|
deadline = None if deadline_s is None else clock() + deadline_s
|
|
752
771
|
saw_top_hit = [False]
|
|
753
772
|
saw_echo = [False]
|
|
773
|
+
ambiguous: list = [] # Y6: a read showed the name at two or more spots in the card
|
|
754
774
|
|
|
755
775
|
def read_screen(**kwargs):
|
|
756
776
|
# F33: every later read is also evidence for a clipboard restore an
|
|
@@ -794,7 +814,7 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
794
814
|
hit = None
|
|
795
815
|
if typed is not False:
|
|
796
816
|
hit = find_app_hit(read_screen, name, attempts=2, sleep=sleep,
|
|
797
|
-
deadline=deadline, clock=clock)
|
|
817
|
+
deadline=deadline, clock=clock, ambiguous=ambiguous)
|
|
798
818
|
if hit is None and not saw_echo[0]:
|
|
799
819
|
# F33/F42: the name is not in the search field yet — the paste may still be on its
|
|
800
820
|
# way, whether type_text missed it or took another change for it (a clear that
|
|
@@ -813,7 +833,8 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
813
833
|
break
|
|
814
834
|
sleep(1.0)
|
|
815
835
|
hit = find_app_hit(read_screen, name, attempts=1, sleep=sleep,
|
|
816
|
-
deadline=deadline if confirming else limit, clock=clock
|
|
836
|
+
deadline=deadline if confirming else limit, clock=clock,
|
|
837
|
+
ambiguous=ambiguous)
|
|
817
838
|
if hit is not None:
|
|
818
839
|
break
|
|
819
840
|
# only the search field showing the name proves the paste arrived — a Top Hit
|
|
@@ -827,6 +848,8 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
827
848
|
tidy()
|
|
828
849
|
if out_of_time():
|
|
829
850
|
return "deadline"
|
|
851
|
+
if ambiguous:
|
|
852
|
+
return "ambiguous" # Y6: the card showed the name at more than one spot
|
|
830
853
|
if short:
|
|
831
854
|
# OCR misses one- and two-letter text in the card and in the field alike: neither
|
|
832
855
|
# "not typed" nor "not found" is known — say that instead (2026-11-06 device run)
|
|
@@ -842,13 +865,21 @@ def open_app(name: str, *, spotlight_open: bool = False,
|
|
|
842
865
|
# ① the Spotlight results can still be reflowing when
|
|
843
866
|
# find_app_hit returns; re-read after 0.5s and re-pick.
|
|
844
867
|
sleep(0.5)
|
|
845
|
-
|
|
868
|
+
split: list = []
|
|
869
|
+
again = choose_app_hit(reread(), name, split)
|
|
870
|
+
if split:
|
|
871
|
+
# Y6: this read shows the name at two or more spots — tap none of them
|
|
872
|
+
tidy()
|
|
873
|
+
return "ambiguous"
|
|
846
874
|
if again is not None:
|
|
847
875
|
if math.hypot(again.nx - hit.nx, again.ny - hit.ny) > 0.02:
|
|
848
876
|
# the row moved: the second read wins, with at most
|
|
849
877
|
# one more read — still moving → the last one wins
|
|
850
878
|
hit = again
|
|
851
|
-
once_more = choose_app_hit(reread(), name)
|
|
879
|
+
once_more = choose_app_hit(reread(), name, split)
|
|
880
|
+
if split:
|
|
881
|
+
tidy()
|
|
882
|
+
return "ambiguous"
|
|
852
883
|
if (once_more is not None
|
|
853
884
|
and math.hypot(once_more.nx - hit.nx,
|
|
854
885
|
once_more.ny - hit.ny) > 0.02):
|
package/imctl/src/imctl/input.py
CHANGED
|
@@ -302,6 +302,9 @@ _ANSI_KEYCODES = {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
|
|
305
|
+
_ANSI_CHARS = {code: char for char, code in _ANSI_KEYCODES.items()}
|
|
306
|
+
|
|
307
|
+
|
|
305
308
|
def keycode_for_char(char: str) -> int | None:
|
|
306
309
|
"""ANSI virtual keycode for a single digit/letter, else None."""
|
|
307
310
|
if len(char) != 1:
|
|
@@ -309,6 +312,55 @@ def keycode_for_char(char: str) -> int | None:
|
|
|
309
312
|
return _ANSI_KEYCODES.get(char.lower())
|
|
310
313
|
|
|
311
314
|
|
|
315
|
+
class KeyboardLayoutMismatch(InputError):
|
|
316
|
+
"""The Mac's keyboard layout does not put the chord's character on its key.
|
|
317
|
+
|
|
318
|
+
Command chords are sent from ANSI key codes; iPhone Mirroring (a Mac
|
|
319
|
+
app) reads its own key equivalents through the Mac's layout first. On
|
|
320
|
+
French AZERTY key code 0 is "q": a ⌘A select-all would arrive as ⌘Q.
|
|
321
|
+
Raised before anything is posted (review 0.2.6 #5).
|
|
322
|
+
"""
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def _layout_char(keycode: int) -> str | None:
|
|
326
|
+
"""What the Mac's current keyboard layout types on ``keycode`` with ⌘ held.
|
|
327
|
+
|
|
328
|
+
The event is created, never posted; AppKit translates it through the
|
|
329
|
+
current input source. None when it cannot be read — the chord then goes
|
|
330
|
+
out as it did before this check.
|
|
331
|
+
"""
|
|
332
|
+
try:
|
|
333
|
+
from AppKit import NSEvent
|
|
334
|
+
|
|
335
|
+
event = CGEventCreateKeyboardEvent(_source(), keycode, True)
|
|
336
|
+
if event is None:
|
|
337
|
+
return None
|
|
338
|
+
CGEventSetFlags(event, kCGEventFlagMaskCommand)
|
|
339
|
+
ns = NSEvent.eventWithCGEvent_(event)
|
|
340
|
+
chars = ns.charactersIgnoringModifiers() if ns is not None else None
|
|
341
|
+
return str(chars) if chars else None
|
|
342
|
+
except Exception:
|
|
343
|
+
return None
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
# Module-level so tests can swap it (like _focus_check).
|
|
347
|
+
_layout_check = _layout_char
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def check_chord_layout(keycode: int) -> None:
|
|
351
|
+
"""Refuse a ⌘ chord whose ANSI key types another character in the Mac's layout."""
|
|
352
|
+
expect = _ANSI_CHARS.get(keycode)
|
|
353
|
+
if expect is None:
|
|
354
|
+
return
|
|
355
|
+
got = _layout_check(keycode)
|
|
356
|
+
if got is None or got.lower() == expect:
|
|
357
|
+
return
|
|
358
|
+
raise KeyboardLayoutMismatch(
|
|
359
|
+
f'the Mac keyboard layout types "{got}" on the key that ⌘{expect.upper()} is sent from '
|
|
360
|
+
f"(key code {keycode}), so iPhone Mirroring would get ⌘{got.upper()} — nothing was sent; "
|
|
361
|
+
"switch the Mac to a QWERTY-style input source (U.S., ABC, Pinyin) and retry")
|
|
362
|
+
|
|
363
|
+
|
|
312
364
|
def _cmd_chord(keycode: int, before_key=None) -> None:
|
|
313
365
|
"""Send a real Command chord: ⌘ down → key down → key up → ⌘ up.
|
|
314
366
|
|
|
@@ -324,6 +376,7 @@ def _cmd_chord(keycode: int, before_key=None) -> None:
|
|
|
324
376
|
event: the caller's last chance to call the chord off by raising —
|
|
325
377
|
nothing is posted then (F35).
|
|
326
378
|
"""
|
|
379
|
+
check_chord_layout(keycode) # review 0.2.6 #5: before anything is sent
|
|
327
380
|
ensure_frontmost()
|
|
328
381
|
_require_focus() # F26: before the chord's first event
|
|
329
382
|
if before_key is not None:
|
|
@@ -473,6 +526,11 @@ class PendingRestore:
|
|
|
473
526
|
against the still pre-paste baseline); once it confirms, the user's
|
|
474
527
|
clipboard goes back, under the same changeCount rule as type_text().
|
|
475
528
|
Nothing else restores it.
|
|
529
|
+
|
|
530
|
+
Since review R38 (Andy's call, 2026-11-07) type_text() creates none: a
|
|
531
|
+
one-character paste never puts the clipboard back. The class stays for
|
|
532
|
+
its own tests and for open_app's offer loop, which still takes any
|
|
533
|
+
PendingRestore an injected type_text hands over.
|
|
476
534
|
"""
|
|
477
535
|
|
|
478
536
|
def __init__(self, pasteboard, saved, saved_change, confirm, *, sent_at,
|
|
@@ -539,7 +597,8 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
539
597
|
the typed text over any chance of the user's original clipboard
|
|
540
598
|
being pasted into the phone.
|
|
541
599
|
|
|
542
|
-
The restore therefore happens only when the
|
|
600
|
+
The restore therefore happens only when the text has four or more
|
|
601
|
+
characters (spaces and case aside), the paste landed, OCR
|
|
543
602
|
saw the text, at least ``min_hold_s`` has passed since Cmd+V
|
|
544
603
|
(the phone's asynchronous read must see the paste first), and
|
|
545
604
|
the changeCount shows nothing else touched the pasteboard.
|
|
@@ -604,14 +663,12 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
604
663
|
this one or an earlier one, is still on its way and could fetch the
|
|
605
664
|
restored clipboard — and the box's own words never count as the text.
|
|
606
665
|
|
|
607
|
-
``pending`` (F33):
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
never get one: without a pre-paste read, text already on screen could
|
|
614
|
-
pose as the paste.
|
|
666
|
+
``pending`` (F33): kept for callers that pass one, but nothing is
|
|
667
|
+
appended to it any more. A one-character paste used to hand over a
|
|
668
|
+
PendingRestore for a later restore on evidence; since Andy's call
|
|
669
|
+
(2026-11-07, review R38) a one-character paste never puts the user's
|
|
670
|
+
clipboard back, here or later — like a text of two or three
|
|
671
|
+
characters, it leaves the clipboard holding ``text``.
|
|
615
672
|
|
|
616
673
|
Requires the calling terminal to have Accessibility permission
|
|
617
674
|
(same as every other imctl input).
|
|
@@ -620,6 +677,11 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
620
677
|
|
|
621
678
|
from . import verify, vision
|
|
622
679
|
|
|
680
|
+
# review 0.2.6 #5: both chords are checked against the Mac's keyboard layout before anything is
|
|
681
|
+
# sent, the mirror is brought forward or the clipboard is touched (the chord checks again itself)
|
|
682
|
+
if replace:
|
|
683
|
+
check_chord_layout(_VK_A)
|
|
684
|
+
check_chord_layout(_VK_V)
|
|
623
685
|
ensure_frontmost()
|
|
624
686
|
if chord is None:
|
|
625
687
|
chord = _cmd_chord
|
|
@@ -628,38 +690,31 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
628
690
|
# F27: a single character is invisible to the default OCR probe
|
|
629
691
|
# (screen_shows_text never matches it) and may already be on screen, so
|
|
630
692
|
# the default checks wait for a still screen, read it with the
|
|
631
|
-
# minimumTextHeight sweep before Cmd+V, and
|
|
693
|
+
# minimumTextHeight sweep before Cmd+V, and confirm the paste only when
|
|
632
694
|
# the character shows up at the same NEW position in two separate
|
|
633
695
|
# reads, looking for up to 4 s (the paste can land while Spotlight
|
|
634
696
|
# redraws its results; the field echo blinks with the cursor). A screen
|
|
635
|
-
# that never holds still gets no baseline and so no
|
|
636
|
-
#
|
|
697
|
+
# that never holds still gets no baseline and so no such sighting. Since
|
|
698
|
+
# review R38 the sighting never licenses a restore: the clipboard keeps
|
|
699
|
+
# holding ``text``.
|
|
637
700
|
single = verify.is_short_text(text, limit=1)
|
|
638
701
|
sweep_before = [None]
|
|
639
702
|
# F41: the probe count of a 2+ character text before the paste (None = unknown)
|
|
640
703
|
multi = not single and verify.text_probe(text) is not None
|
|
641
704
|
count_before = [None]
|
|
705
|
+
# 0.2.5: where the probe showed before the paste (None = unknown → no confirmation)
|
|
706
|
+
spots_before = [None]
|
|
707
|
+
strip_before = [[]] # and inside the banner strip (review 0.2.6 #7: explains, never confirms)
|
|
708
|
+
# review 0.2.6 #7: why OCR could not confirm a paste the frame diff saw — "too_short" (fewer
|
|
709
|
+
# than VERIFY_MIN_PROBE characters, never confirmed) or "strip_only" (the text appeared only in
|
|
710
|
+
# the banner strip at the top, where a field cannot be told from a banner)
|
|
711
|
+
unverifiable = [None]
|
|
712
|
+
if multi and len(verify.text_probe(text)) < verify.VERIFY_MIN_PROBE:
|
|
713
|
+
unverifiable[0] = "too_short"
|
|
642
714
|
|
|
643
715
|
def sweep_read():
|
|
644
716
|
return vision.read_screen(language_correction=False, sweep=True)
|
|
645
717
|
|
|
646
|
-
def defer_restore():
|
|
647
|
-
# F33: hand the caller what it needs to restore later, on evidence.
|
|
648
|
-
before = sweep_before[0]
|
|
649
|
-
if pending is None or not single or before is None or not restore:
|
|
650
|
-
return
|
|
651
|
-
|
|
652
|
-
sighting = verify.RepeatedSighting(text, before)
|
|
653
|
-
|
|
654
|
-
def confirm(hits):
|
|
655
|
-
# F44: as in ocr_check — a read showing the paste-progress box is
|
|
656
|
-
# no evidence (a paste is still on its way)
|
|
657
|
-
return not verify.shows_paste_hud(hits) and sighting.add(hits)
|
|
658
|
-
|
|
659
|
-
pending.append(PendingRestore(pasteboard, saved, saved_change, confirm,
|
|
660
|
-
sent_at=t0, clock=clock,
|
|
661
|
-
min_hold_s=min_hold_s))
|
|
662
|
-
|
|
663
718
|
pre_read = single and before_check is None
|
|
664
719
|
pre_count = multi and ocr_check is None
|
|
665
720
|
if hud_check is None:
|
|
@@ -714,7 +769,13 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
714
769
|
# F44: no license while the paste-progress box shows — a paste
|
|
715
770
|
# (this one or an earlier one) is still on its way
|
|
716
771
|
if (verify.shows_paste_hud(hits)
|
|
717
|
-
or verify.probe_count(text, hits) <= count_before[0]
|
|
772
|
+
or verify.probe_count(text, hits) <= count_before[0]
|
|
773
|
+
or spots_before[0] is None
|
|
774
|
+
or not verify.has_new_spot(spots_before[0], verify.probe_spots(text, hits))):
|
|
775
|
+
if (unverifiable[0] is None and not verify.shows_paste_hud(hits)
|
|
776
|
+
and verify.probe_count(text, hits) > count_before[0]
|
|
777
|
+
and verify.has_new_spot(strip_before[0], verify.strip_spots(text, hits))):
|
|
778
|
+
unverifiable[0] = "strip_only"
|
|
718
779
|
return False
|
|
719
780
|
return True
|
|
720
781
|
return verify.screen_shows_text(text, vision.read_screen)
|
|
@@ -747,13 +808,19 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
747
808
|
# occurrence from one read). A capture failure in either leaves it
|
|
748
809
|
# unknown: then OCR can never license a restore for this paste.
|
|
749
810
|
try:
|
|
750
|
-
|
|
811
|
+
r1 = vision.read_screen()
|
|
812
|
+
first = verify.probe_count(text, r1)
|
|
751
813
|
sleep(0.3)
|
|
752
|
-
|
|
814
|
+
r2 = vision.read_screen()
|
|
815
|
+
count_before[0] = max(first, verify.probe_count(text, r2))
|
|
816
|
+
# both reads: a spot either one saw is not new after the paste
|
|
817
|
+
spots_before[0] = verify.probe_spots(text, r1) + verify.probe_spots(text, r2)
|
|
818
|
+
strip_before[0] = verify.strip_spots(text, r1) + verify.strip_spots(text, r2)
|
|
753
819
|
except Exception as exc:
|
|
754
820
|
if not verify.is_capture_error(exc):
|
|
755
821
|
raise
|
|
756
822
|
count_before[0] = None
|
|
823
|
+
spots_before[0] = None
|
|
757
824
|
if report is not None:
|
|
758
825
|
report["count_before"] = count_before[0]
|
|
759
826
|
|
|
@@ -837,14 +904,18 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
837
904
|
# confirmed a paste that never reached the field — the caller must
|
|
838
905
|
# not report such a paste as verified
|
|
839
906
|
report["seen"] = bool(restore_ok)
|
|
907
|
+
if not restore_ok and unverifiable[0] is not None:
|
|
908
|
+
report["unverifiable"] = unverifiable[0]
|
|
840
909
|
|
|
841
910
|
if not landed:
|
|
842
911
|
# F18 invariant: never restore unconfirmed — a late paste
|
|
843
912
|
# must at worst repeat `text`, never the user's own clipboard.
|
|
844
|
-
defer_restore()
|
|
845
913
|
return False
|
|
846
914
|
|
|
847
|
-
|
|
915
|
+
# Andy's call (2026-11-07, review R38): one character seen on screen
|
|
916
|
+
# confirms the paste but never licenses a restore — like a text of two or
|
|
917
|
+
# three characters (VERIFY_MIN_PROBE), it keeps the clipboard holding `text`.
|
|
918
|
+
if restore_ok and restore and not single:
|
|
848
919
|
# Hold the paste long enough for the asynchronous
|
|
849
920
|
# pasteboard read before putting the user's data back.
|
|
850
921
|
elapsed = clock() - t0
|
|
@@ -853,11 +924,9 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
853
924
|
# Restore the user's clipboard only if nothing else changed it.
|
|
854
925
|
if pasteboard.changeCount() == saved_change + 1:
|
|
855
926
|
restore_pasteboard(pasteboard, saved)
|
|
856
|
-
else:
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
# clipboard keeps `text` — see the docstring's tradeoff.
|
|
860
|
-
defer_restore()
|
|
927
|
+
# else: landed but OCR is blind to it (short/cropped text), a single
|
|
928
|
+
# character, or the caller keeps the clipboard (restore=False): success,
|
|
929
|
+
# but the clipboard keeps `text` — see the docstring's tradeoff.
|
|
861
930
|
return True
|
|
862
931
|
except BaseException:
|
|
863
932
|
# Before Cmd+V the phone never got a paste command, so the
|
|
@@ -872,6 +941,7 @@ def type_text(text: str, *, replace: bool = False, pasteboard=None,
|
|
|
872
941
|
|
|
873
942
|
def clear_text() -> None:
|
|
874
943
|
"""Select-all and delete in the focused field."""
|
|
944
|
+
check_chord_layout(_VK_A) # review 0.2.6 #5: before the mirror is brought forward
|
|
875
945
|
ensure_frontmost()
|
|
876
946
|
_cmd_chord(_VK_A) # Cmd+A — real chord, same reason as type_text
|
|
877
947
|
time.sleep(0.05)
|
|
@@ -187,6 +187,57 @@ def text_probe(text: str) -> str | None:
|
|
|
187
187
|
return probe if len(probe) >= 2 else None
|
|
188
188
|
|
|
189
189
|
|
|
190
|
+
# 0.2.5 (Andy's call, 2026-11-07): a typed text is confirmed only by a sighting where a field can be —
|
|
191
|
+
# a spot where the text's probe was not seen before the paste, below the strip at the top where the
|
|
192
|
+
# status bar and notification banners are drawn. A rise in the whole-screen count alone (a banner that
|
|
193
|
+
# carries the same words, a label somewhere else) no longer confirms a paste.
|
|
194
|
+
BANNER_STRIP_NY = 0.15
|
|
195
|
+
# Andy's call (2026-11-07, review R37): a text shorter than this (after the probe's compaction) is never
|
|
196
|
+
# confirmed by a sighting — "in" is part of "Sign in", "ok" of "Book" — so it never licenses a restore either
|
|
197
|
+
VERIFY_MIN_PROBE = 4
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def probe_spots(text: str, hits) -> list[tuple[float, float]] | None:
|
|
201
|
+
"""Where ``text``'s probe shows in ``hits`` (one spot per OCR line that holds it), leaving out the
|
|
202
|
+
paste-progress box (F44) and the banner strip at the top; None when the text is too short for a
|
|
203
|
+
probe. Hits without a position never count."""
|
|
204
|
+
probe = text_probe(text)
|
|
205
|
+
if probe is None:
|
|
206
|
+
return None
|
|
207
|
+
if len(probe) < VERIFY_MIN_PROBE:
|
|
208
|
+
return []
|
|
209
|
+
spots = []
|
|
210
|
+
for hit in hits:
|
|
211
|
+
nx, ny = getattr(hit, "nx", None), getattr(hit, "ny", None)
|
|
212
|
+
if nx is None or ny is None or ny < BANNER_STRIP_NY or _is_paste_hud(hit):
|
|
213
|
+
continue
|
|
214
|
+
if probe in _compact(getattr(hit, "text", hit)):
|
|
215
|
+
spots.append((nx, ny))
|
|
216
|
+
return spots
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def strip_spots(text: str, hits) -> list[tuple[float, float]]:
|
|
220
|
+
"""Where ``text``'s probe shows inside the banner strip at the top (the spots probe_spots leaves
|
|
221
|
+
out), the paste-progress box aside; [] when the text is too short to be confirmed at all. Only
|
|
222
|
+
explains an unconfirmed paste (review 0.2.6 #7) — never confirms one."""
|
|
223
|
+
probe = text_probe(text)
|
|
224
|
+
if probe is None or len(probe) < VERIFY_MIN_PROBE:
|
|
225
|
+
return []
|
|
226
|
+
spots = []
|
|
227
|
+
for hit in hits:
|
|
228
|
+
nx, ny = getattr(hit, "nx", None), getattr(hit, "ny", None)
|
|
229
|
+
if nx is None or ny is None or ny >= BANNER_STRIP_NY or _is_paste_hud(hit):
|
|
230
|
+
continue
|
|
231
|
+
if probe in _compact(getattr(hit, "text", hit)):
|
|
232
|
+
spots.append((nx, ny))
|
|
233
|
+
return spots
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def has_new_spot(before, after, eps: float = 0.03) -> bool:
|
|
237
|
+
"""True when some spot in ``after`` has no spot of ``before`` within ``eps`` in both axes."""
|
|
238
|
+
return any(all(abs(ax - bx) > eps or abs(ay - by) > eps for bx, by in before) for ax, ay in after)
|
|
239
|
+
|
|
240
|
+
|
|
190
241
|
def probe_count(text: str, hits) -> int | None:
|
|
191
242
|
"""How many times ``text``'s probe occurs in the joined OCR ``hits``;
|
|
192
243
|
None when the text is too short for a probe. The phone's "Pasting from …"
|
package/package.json
CHANGED