@buoy-gg/highlight-updates 7.0.30 → 7.0.32

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.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The one guarded require for React Native's RawEventEmitter.
5
+ *
6
+ * `RawEventEmitter` mirrors every event React Native dispatches BEFORE React's
7
+ * plugins or components see it, which makes it the only way to observe what a
8
+ * HUMAN is touching without instrumenting the app: Buoy mounts as a sibling of
9
+ * the app tree, not a parent, so there is no root View to put a capture
10
+ * responder on.
11
+ *
12
+ * Two things this file is careful about, both learned the hard way in
13
+ * focus-inspector's copy:
14
+ *
15
+ * 1. It is a DEEP import that RN's export map warns about and could move in any
16
+ * release. The failure has to degrade to "capture unavailable" rather than
17
+ * taking the host app's bundle down — and Metro only treats a require as
18
+ * optional when it sits LEXICALLY inside a try statement, so wrapping it in
19
+ * a helper or an arrow makes Metro hard-fail the bundle instead.
20
+ * 2. Keeping it in its own module gives the unit suite a seam: Node's `require`
21
+ * ignores Vitest's module mocks, so the emitter can only be faked by mocking
22
+ * a module reached with a real `import`.
23
+ */
24
+
25
+ export function resolveRawEventEmitter() {
26
+ let mod;
27
+ try {
28
+ mod = require("react-native/Libraries/Core/RawEventEmitter");
29
+ } catch (e) {
30
+ return {
31
+ emitter: null,
32
+ reason: e?.message ?? "RawEventEmitter is unavailable"
33
+ };
34
+ }
35
+ const candidate = mod?.default ?? mod;
36
+ if (typeof candidate?.addListener !== "function") {
37
+ return {
38
+ emitter: null,
39
+ reason: "RawEventEmitter has no addListener"
40
+ };
41
+ }
42
+ return {
43
+ emitter: candidate,
44
+ reason: null
45
+ };
46
+ }
@@ -769,4 +769,272 @@ export async function tapElement(params) {
769
769
  }
770
770
  };
771
771
  }
772
+ }
773
+
774
+ // --- waitFor --------------------------------------------------------------
775
+
776
+ const WAIT_DEFAULT_MS = 5_000;
777
+ const WAIT_MAX_MS = 30_000;
778
+ const WAIT_MIN_POLL_MS = 50;
779
+ const WAIT_DEFAULT_POLL_MS = 150;
780
+
781
+ /**
782
+ * Block until an element appears (or disappears), then report how long it took.
783
+ *
784
+ * WHY THIS EXISTS. `navigate` returns the moment the route is pushed, not when
785
+ * the new screen has data on it, so "go to /shop then tap Fire Grill" reliably
786
+ * tapped a loading skeleton. A remote driver solves that with a wait step
787
+ * (MCP's `run_flow` has `waitFor`/`waitMs`); anything driving the tools from
788
+ * INSIDE the app had nothing, and its only option was to re-run
789
+ * `describeScreen` in a loop — which for an agent means burning turns against a
790
+ * step budget, and for a Scenario means a fixed sleep that is either flaky or
791
+ * slow.
792
+ *
793
+ * MATCHING IS `tapElement`'S, EXACTLY. Same `scoreTapMatch`, same fields, so
794
+ * "wait for X" and "tap X" can never disagree about what X is. A wait that
795
+ * resolves on an element the tap then cannot find is worse than no wait.
796
+ *
797
+ * PRESENCE MEANS ON SCREEN. An identity scan alone would resolve against a
798
+ * previous Expo Router screen still mounted behind the current one — the exact
799
+ * false positive `describeScreen` drops by rect. So a candidate that matches by
800
+ * name is measured before it counts, and only the matches are measured: the
801
+ * per-poll cost stays one fiber walk plus a handful of `measureInWindow`
802
+ * calls, not a full `describeScreen`.
803
+ *
804
+ * The poll floor is deliberate. This runs on the JS thread the app is drawing
805
+ * on, and a caller asking for `pollMs: 0` would starve the very render it is
806
+ * waiting for.
807
+ */
808
+ export async function waitFor(params) {
809
+ const hasTarget = params.nativeTag != null || !!params.testID?.trim() || !!params.query?.trim();
810
+ if (!hasTarget) {
811
+ return {
812
+ ok: false,
813
+ waitedMs: 0,
814
+ polls: 0,
815
+ reason: "Nothing to wait for — pass nativeTag, testID or query."
816
+ };
817
+ }
818
+ const timeoutMs = Math.min(Math.max(params.timeoutMs ?? WAIT_DEFAULT_MS, 0), WAIT_MAX_MS);
819
+ const pollMs = Math.max(params.pollMs ?? WAIT_DEFAULT_POLL_MS, WAIT_MIN_POLL_MS);
820
+ const wantGone = params.gone === true;
821
+ const started = Date.now();
822
+ let polls = 0;
823
+ for (;;) {
824
+ polls += 1;
825
+ const hit = await findOnScreen(params);
826
+ if (wantGone ? !hit : !!hit) {
827
+ return {
828
+ ok: true,
829
+ waitedMs: Date.now() - started,
830
+ polls,
831
+ matched: hit ?? undefined
832
+ };
833
+ }
834
+ if (Date.now() - started >= timeoutMs) {
835
+ return {
836
+ ok: false,
837
+ waitedMs: Date.now() - started,
838
+ polls,
839
+ reason: wantGone ? `Still on screen after ${timeoutMs}ms.` : `Not on screen after ${timeoutMs}ms. Call describeScreen to see what is.`,
840
+ matched: hit ?? undefined
841
+ };
842
+ }
843
+ await new Promise(resolve => setTimeout(resolve, pollMs));
844
+ }
845
+ }
846
+
847
+ /** One scan: rank by identity, then confirm the best match is really visible. */
848
+ async function findOnScreen(params) {
849
+ const ranked = collectCandidates().map(c => ({
850
+ c,
851
+ score: matchScore(c, params)
852
+ })).filter(r => r.score > 0).sort((a, b) => b.score - a.score)
853
+ // Only the plausible few get measured; a broad query can match dozens.
854
+ .slice(0, 8);
855
+ if (ranked.length === 0) return null;
856
+ await measureCandidates(ranked.map(r => r.c));
857
+ const win = Dimensions.get("window");
858
+ const screenW = Math.round(win.width) || 1;
859
+ const screenH = Math.round(win.height) || 1;
860
+ for (const {
861
+ c
862
+ } of ranked) {
863
+ if (!isRectCenterOnScreen(c.rect, screenW, screenH)) continue;
864
+ return {
865
+ nativeTag: c.nativeTag,
866
+ name: c.name,
867
+ testID: c.testID,
868
+ label: c.label,
869
+ text: c.text,
870
+ interactive: !!(c.press || c.valueControl || c.textControl)
871
+ };
872
+ }
873
+ return null;
874
+ }
875
+
876
+ // --- resolveTouchTarget ---------------------------------------------------
877
+
878
+ /**
879
+ * What a recorded touch landed on, in the vocabulary `tapElement` searches by.
880
+ *
881
+ * Deliberately the SAME fields `describeScreen` emits: a macro recorded from a
882
+ * human's finger has to replay through `tapElement`, and the only way to
883
+ * guarantee that is for the recorder to name the element exactly the way the
884
+ * matcher will look for it. Anything richer here is a selector that records
885
+ * fine and then can't be found again.
886
+ */
887
+
888
+ /**
889
+ * Resolve the native tag from a raw touch event to the element a HUMAN would
890
+ * say they tapped.
891
+ *
892
+ * Synchronous on purpose. The tag arrives on `topTouchStart`, and by the time
893
+ * an async resolve came back the press handler may already have navigated —
894
+ * leaving the recorder to name the element on the screen it moved TO. Everything
895
+ * here is a fiber walk (no measure), which is what makes that affordable.
896
+ *
897
+ * Returns null when the tag belongs to nothing interesting (the background, a
898
+ * scroll surface): the recorder treats that as "not a step", which is exactly
899
+ * right — a tap on empty space is not something to replay.
900
+ */
901
+ /**
902
+ * Is this fiber inside Buoy's own overlay?
903
+ *
904
+ * `FloatingDevTools` marks its single root View with `__buoyDevToolsRoot`, and
905
+ * everything the tool draws — the bubble, the dial, every modal, every tool
906
+ * overlay — is under it. Walking the whole chain (rather than a fixed depth) is
907
+ * the point: a control deep inside a tool's modal is still the tool.
908
+ */
909
+ function isBuoyChrome(fiber) {
910
+ let cur = fiber;
911
+ let depth = 0;
912
+ while (cur && depth < 400) {
913
+ if (getProps(cur)?.__buoyDevToolsRoot) return true;
914
+ cur = cur.return;
915
+ depth++;
916
+ }
917
+ return false;
918
+ }
919
+
920
+ /**
921
+ * Climb from the node that was touched to the element that OWNS the press.
922
+ *
923
+ * A finger lands on the deepest host view, which for a button is the `<Text>`
924
+ * inside it. That Text is a legitimate candidate — `findPressHandler` walks up
925
+ * and finds the button's `onPress`, so it looks drivable — but it carries the
926
+ * TEXT's identity: no testID, and "visible text" that is whatever string
927
+ * happens to be in that node.
928
+ *
929
+ * Left alone, every recorded step is named after a fragment of copy and
930
+ * replayed by fuzzy-matching that fragment. In the Poké Mart flow, all six
931
+ * steps came back as `Text` with no testID at all, so "tap the Charizard row"
932
+ * was recorded as "The signature. Flame-broiled, wings on, worth the wait." —
933
+ * the brittlest possible selector, chosen when `shop-item-charizard` was one
934
+ * fiber up.
935
+ *
936
+ * So we walk to the fiber that DECLARES `onPress` and take the candidate there.
937
+ * Stopping at the declaring fiber matters: keep climbing and a row inside a
938
+ * pressable list resolves to the list.
939
+ */
940
+ function preferHandlerOwner(match, byFiber) {
941
+ // Already the owner (or a Switch/TextInput, whose handler is its own).
942
+ const own = getProps(match.fiber);
943
+ if (typeof own?.onPress === "function" || typeof own?.onValueChange === "function" || typeof own?.onChangeText === "function") {
944
+ return match;
945
+ }
946
+
947
+ // 1. Find the fiber that actually declares the handler.
948
+ let declaring = null;
949
+ let cur = match.fiber?.return;
950
+ let depth = 0;
951
+ while (cur && depth < 25) {
952
+ if (typeof getProps(cur)?.onPress === "function") {
953
+ declaring = cur;
954
+ break;
955
+ }
956
+ cur = cur.return;
957
+ depth++;
958
+ }
959
+ if (!declaring) return match;
960
+
961
+ // 2. Take the candidate AT that fiber, or the first one above it.
962
+ //
963
+ // Stopping exactly at the declaring fiber isn't enough: a `<Pressable>`
964
+ // declares onPress but is de-duped into the component that renders it
965
+ // (`PrimaryButton`), and de-duping keeps the OUTERMOST fiber of everything
966
+ // sharing a host instance — which is where the testID ends up. Climbing a
967
+ // few levels past the handler is what turns "Text: Add to bag" into
968
+ // "PrimaryButton [testID=shop-add-to-bag]". The bound keeps a row inside a
969
+ // pressable list from resolving to the list.
970
+ let probe = declaring;
971
+ for (let i = 0; i < 6 && probe; i++) {
972
+ const candidate = byFiber.get(probe);
973
+ if (candidate) return candidate;
974
+ probe = probe.return;
975
+ }
976
+ return match;
977
+ }
978
+ export function resolveTouchTarget(nativeTag) {
979
+ const candidates = collectCandidates();
980
+ if (candidates.length === 0) return null;
981
+ const byFiber = new Map();
982
+ for (const c of candidates) byFiber.set(c.fiber, c);
983
+
984
+ // Fast path: the touched host IS a candidate's host.
985
+ const direct = candidates.find(c => c.nativeTag === nativeTag);
986
+
987
+ // Otherwise find the touched fiber and walk up to the nearest candidate. The
988
+ // touch lands on the deepest host view (the <Text> inside the button), so the
989
+ // interesting element is almost always an ancestor.
990
+ let touched = null;
991
+ if (!direct) {
992
+ for (const root of getAllFiberRoots()) {
993
+ traverseFiberTree(root.current, fiber => {
994
+ if (touched) return;
995
+ if (fiber.stateNode && getNativeTag(fiber.stateNode) === nativeTag) {
996
+ touched = fiber;
997
+ }
998
+ });
999
+ if (touched) break;
1000
+ }
1001
+ }
1002
+ let match = direct ?? null;
1003
+ if (!match && touched) {
1004
+ let cur = touched;
1005
+ let depth = 0;
1006
+ // Prefer an ancestor that is actually drivable; fall back to the nearest
1007
+ // named one so an unlabeled tap still records something a human can read.
1008
+ let named = null;
1009
+ while (cur && depth < 25) {
1010
+ const c = byFiber.get(cur);
1011
+ if (c) {
1012
+ if (c.press || c.valueControl || c.textControl) {
1013
+ match = c;
1014
+ break;
1015
+ }
1016
+ if (!named) named = c;
1017
+ }
1018
+ cur = cur.return;
1019
+ depth++;
1020
+ }
1021
+ if (!match) match = named;
1022
+ }
1023
+ if (!match) return null;
1024
+ match = preferHandlerOwner(match, byFiber);
1025
+ if (!match.press && !match.valueControl && !match.textControl) return null;
1026
+ // Buoy's own chrome is not part of the app under test. Without this, the tap
1027
+ // that stops a recording is recorded as its final step.
1028
+ if (isBuoyChrome(match.fiber)) return null;
1029
+ const control = match.valueControl ? match.valueControl.kind : match.textControl ? "text" : "press";
1030
+ return {
1031
+ nativeTag: match.nativeTag,
1032
+ name: match.name,
1033
+ role: match.role,
1034
+ testID: match.testID,
1035
+ label: match.label,
1036
+ text: match.text,
1037
+ control,
1038
+ value: match.valueControl ? match.valueControl.current : match.textControl ? match.textControl.current : undefined
1039
+ };
772
1040
  }
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * touchCapture — what a HUMAN is doing to the app, as replayable intents.
5
+ *
6
+ * This is the recording half of the pair whose playback half is `tapElement`:
7
+ * it watches real finger input and names each interaction in exactly the
8
+ * vocabulary `tapElement` searches by, so a recorded macro can be replayed
9
+ * without a second guess about what "that button" meant.
10
+ *
11
+ * Why RawEventEmitter and not the obvious alternatives:
12
+ * - A capture-phase responder on a root View would be the textbook answer, but
13
+ * Buoy mounts as a SIBLING of the app tree, not a parent. There is no root to
14
+ * wrap without changing every host app's integration.
15
+ * - Patching `Pressability`, or rewriting `onPress` props on the fly, breaks the
16
+ * moment a component re-renders (props are rebuilt every render) and misses
17
+ * everything driven by react-native-gesture-handler anyway.
18
+ * - RawEventEmitter mirrors every dispatched event before React's plugins see
19
+ * it, needs zero app instrumentation, and is already proven in-tree by
20
+ * focus-inspector's TV focus observer.
21
+ *
22
+ * Three rules the recorder above depends on:
23
+ *
24
+ * THE TARGET IS RESOLVED AT touchStart, NOT touchEnd. A press handler can
25
+ * navigate synchronously, so resolving after the fact names an element on the
26
+ * screen the app moved TO. We resolve while the finger is still down and emit
27
+ * when it lifts.
28
+ *
29
+ * A DRAG IS NOT A TAP. Scrolling a list produces the same touchStart the
30
+ * button above it does. Movement past a threshold, or an explicit
31
+ * touchCancel when a ScrollView steals the responder, drops the record —
32
+ * otherwise every recording is half scroll noise.
33
+ *
34
+ * KEYSTROKES ARE NOT INTENTS. Typing "SAVE10" fires six change events; a
35
+ * macro step wants the finished string. Consecutive edits to the same input
36
+ * collapse into the latest value as they arrive.
37
+ */
38
+
39
+ import { resolveTouchTarget } from "./screenElements";
40
+ import { resolveRawEventEmitter } from "./rawEventEmitter";
41
+
42
+ /** Points of finger travel past which the gesture stops being a tap. */
43
+ const TAP_SLOP_PT = 14;
44
+ /** Hold time at or past which a tap is recorded as a long-press. */
45
+ const LONG_PRESS_MS = 550;
46
+ /** A tap that outlasts this was a gesture we don't model — drop it. */
47
+ const MAX_TAP_MS = 4_000;
48
+ /** Consecutive edits to the same input within this window are one intent. */
49
+ const TEXT_COALESCE_MS = 8_000;
50
+ /** Ring buffer size. A recording longer than this is not a macro anyway. */
51
+ const MAX_RECORDS = 600;
52
+ let emitter = null;
53
+ let emitterResolved = false;
54
+ let unavailableReason = null;
55
+ let subscriptions = [];
56
+ let status = "idle";
57
+ let records = [];
58
+ let seq = 0;
59
+ let pending = null;
60
+ function getEmitter() {
61
+ if (emitterResolved) return emitter;
62
+ emitterResolved = true;
63
+ const resolution = resolveRawEventEmitter();
64
+ emitter = resolution.emitter;
65
+ unavailableReason = resolution.reason;
66
+ return emitter;
67
+ }
68
+ function num(v) {
69
+ return typeof v === "number" && Number.isFinite(v) ? v : null;
70
+ }
71
+
72
+ /** Fabric puts the touched view on `target`; `tag` is the older shape. */
73
+ function tagOf(event) {
74
+ const native = event?.nativeEvent;
75
+ if (!native) return null;
76
+ return num(native.target) ?? num(native.tag);
77
+ }
78
+
79
+ /**
80
+ * Touch coordinates. A touch event carries them at the top level on the
81
+ * synthesized event and inside `touches`/`changedTouches` on the raw one, and
82
+ * which of those is populated differs by platform and architecture — so read
83
+ * whichever answers rather than betting on one.
84
+ */
85
+ function pointOf(event) {
86
+ const native = event?.nativeEvent;
87
+ if (!native) return null;
88
+ const direct = {
89
+ x: num(native.pageX),
90
+ y: num(native.pageY)
91
+ };
92
+ if (direct.x !== null && direct.y !== null) return {
93
+ x: direct.x,
94
+ y: direct.y
95
+ };
96
+ for (const key of ["changedTouches", "touches"]) {
97
+ const list = native[key];
98
+ if (Array.isArray(list) && list.length) {
99
+ const first = list[0];
100
+ const x = num(first?.pageX);
101
+ const y = num(first?.pageY);
102
+ if (x !== null && y !== null) return {
103
+ x,
104
+ y
105
+ };
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ function push(record) {
111
+ records.push({
112
+ ...record,
113
+ seq: ++seq
114
+ });
115
+ if (records.length > MAX_RECORDS) records = records.slice(-MAX_RECORDS);
116
+ }
117
+ function onTouchStart(event) {
118
+ const tag = tagOf(event);
119
+ if (tag === null) return;
120
+ const point = pointOf(event);
121
+ let target = null;
122
+ try {
123
+ target = resolveTouchTarget(tag);
124
+ } catch {
125
+ // A fiber walk that throws must never break the app's touch handling.
126
+ }
127
+ pending = {
128
+ tag,
129
+ x: point?.x ?? 0,
130
+ y: point?.y ?? 0,
131
+ t: Date.now(),
132
+ drift: 0,
133
+ target
134
+ };
135
+ }
136
+ function onTouchMove(event) {
137
+ if (!pending) return;
138
+ const point = pointOf(event);
139
+ if (!point) return;
140
+ const dx = point.x - pending.x;
141
+ const dy = point.y - pending.y;
142
+ pending.drift = Math.max(pending.drift, Math.sqrt(dx * dx + dy * dy));
143
+ }
144
+ function onTouchEnd(event) {
145
+ const p = pending;
146
+ pending = null;
147
+ if (!p || !p.target) return;
148
+ const point = pointOf(event);
149
+ if (point) {
150
+ const dx = point.x - p.x;
151
+ const dy = point.y - p.y;
152
+ p.drift = Math.max(p.drift, Math.sqrt(dx * dx + dy * dy));
153
+ }
154
+ if (p.drift > TAP_SLOP_PT) return; // a drag, a scroll, a swipe — not a step
155
+
156
+ const held = Date.now() - p.t;
157
+ if (held > MAX_TAP_MS) return;
158
+
159
+ // A text input's tap is just "focus this field"; the intent is the text it
160
+ // ends up with, which arrives separately as a change event. Recording the
161
+ // focus tap too would put a step in every macro that does nothing on replay.
162
+ if (p.target.control === "text") return;
163
+ // Same for a toggle/slider: the tap and the value change are one intent, and
164
+ // the change event is the half that carries what it became.
165
+ if (p.target.control === "toggle" || p.target.control === "slider") return;
166
+ push({
167
+ t: Date.now(),
168
+ kind: held >= LONG_PRESS_MS ? "longPress" : "press",
169
+ target: p.target
170
+ });
171
+ }
172
+ function onTouchCancel() {
173
+ // A ScrollView (or any ancestor) taking the responder terminates the touch.
174
+ pending = null;
175
+ }
176
+
177
+ /**
178
+ * `topChange` is the shared channel for "this control's value became X" —
179
+ * TextInput sends `text`, Switch sends `value`. Sliders arrive on their own
180
+ * channel. All three are the same idea: a control the user set.
181
+ */
182
+ function onChange(event) {
183
+ const tag = tagOf(event);
184
+ if (tag === null) return;
185
+ const native = event.nativeEvent;
186
+ let kind;
187
+ let value;
188
+ if (typeof native.text === "string") {
189
+ kind = "text";
190
+ value = native.text;
191
+ } else if (typeof native.value === "boolean") {
192
+ kind = "toggle";
193
+ value = native.value;
194
+ } else if (typeof native.value === "number") {
195
+ kind = "slider";
196
+ value = native.value;
197
+ } else {
198
+ return;
199
+ }
200
+ const last = records[records.length - 1];
201
+ if (last && last.kind === kind && last.target.nativeTag === tag && Date.now() - last.t < TEXT_COALESCE_MS) {
202
+ // Same control, still typing/dragging: this IS the previous intent, further
203
+ // along. Replace rather than append, or "SAVE10" becomes six macro steps.
204
+ last.value = value;
205
+ last.t = Date.now();
206
+ return;
207
+ }
208
+ let target = null;
209
+ try {
210
+ target = resolveTouchTarget(tag);
211
+ } catch {
212
+ /* see onTouchStart */
213
+ }
214
+ if (!target) return;
215
+ push({
216
+ t: Date.now(),
217
+ kind,
218
+ target,
219
+ value
220
+ });
221
+ }
222
+ export function startTouchCapture() {
223
+ if (status === "capturing") return getTouchCaptureStatus();
224
+ const raw = getEmitter();
225
+ if (!raw) {
226
+ status = "unavailable";
227
+ return getTouchCaptureStatus();
228
+ }
229
+ try {
230
+ subscriptions = [raw.addListener("topTouchStart", onTouchStart), raw.addListener("topTouchMove", onTouchMove), raw.addListener("topTouchEnd", onTouchEnd), raw.addListener("topTouchCancel", onTouchCancel), raw.addListener("topChange", onChange), raw.addListener("topValueChange", onChange), raw.addListener("topSlidingComplete", onChange)];
231
+ pending = null;
232
+ status = "capturing";
233
+ } catch (e) {
234
+ subscriptions = [];
235
+ status = "unavailable";
236
+ unavailableReason = e?.message ?? "addListener failed";
237
+ }
238
+ return getTouchCaptureStatus();
239
+ }
240
+ export function stopTouchCapture() {
241
+ subscriptions.forEach(s => {
242
+ try {
243
+ s.remove();
244
+ } catch {
245
+ /* already gone is fine */
246
+ }
247
+ });
248
+ subscriptions = [];
249
+ pending = null;
250
+ if (status === "capturing") status = "idle";
251
+ }
252
+ export function clearTouchCapture() {
253
+ records = [];
254
+ seq = 0;
255
+ }
256
+ export function getTouchCaptureStatus() {
257
+ return {
258
+ status,
259
+ reason: status === "unavailable" ? unavailableReason : null
260
+ };
261
+ }
262
+
263
+ /** Everything recorded after `sinceSeq`, plus where the caller now is. */
264
+ export function readTouchCapture(sinceSeq = 0) {
265
+ return {
266
+ ...getTouchCaptureStatus(),
267
+ records: records.filter(r => r.seq > sinceSeq),
268
+ seq
269
+ };
270
+ }
@@ -2,7 +2,8 @@
2
2
 
3
3
  import HighlightUpdatesController from "../highlight-updates/utils/HighlightUpdatesController";
4
4
  import { RenderTracker } from "../highlight-updates/utils/RenderTracker";
5
- import { describeScreen, tapElement } from "../highlight-updates/utils/screenElements";
5
+ import { describeScreen, tapElement, waitFor } from "../highlight-updates/utils/screenElements";
6
+ import { clearTouchCapture, getTouchCaptureStatus, readTouchCapture, startTouchCapture, stopTouchCapture } from "../highlight-updates/utils/touchCapture";
6
7
  import { CommitProfiler } from "../highlight-updates/utils/CommitProfiler";
7
8
  function ensureInitialized() {
8
9
  if (!HighlightUpdatesController.isInitialized()) {
@@ -203,6 +204,27 @@ export const highlightUpdatesSyncAdapter = {
203
204
  // Tap an element purely in JS: resolve it (by nativeTag / testID / query),
204
205
  // find the nearest onPress up its fiber chain, and invoke it with a
205
206
  // synthetic press event. Powers the MCP `tap_element` action.
206
- tapElement: params => tapElement(params ?? {})
207
+ tapElement: params => tapElement(params ?? {}),
208
+ // Block until an element is on screen (or gone), so a driver can act on a
209
+ // screen that has finished loading instead of the skeleton that was there
210
+ // when `navigate` returned. Same matcher `tapElement` ranks by.
211
+ waitFor: params => waitFor(params ?? {}),
212
+ // ── Touch capture: the recording half of tapElement ──────────────────
213
+ // Observe what a HUMAN taps, named in the same vocabulary tapElement
214
+ // searches by, so the Scenarios recorder can turn a real session into a
215
+ // replayable macro. Lives here because this tool already owns the fiber
216
+ // walk both halves need.
217
+ startTouchCapture: () => startTouchCapture(),
218
+ stopTouchCapture: () => {
219
+ stopTouchCapture();
220
+ return getTouchCaptureStatus();
221
+ },
222
+ clearTouchCapture: () => {
223
+ clearTouchCapture();
224
+ return {
225
+ ok: true
226
+ };
227
+ },
228
+ readTouchCapture: params => readTouchCapture(params?.sinceSeq ?? 0)
207
229
  }
208
230
  };
@@ -1 +1 @@
1
- {"version":3,"file":"HighlightUpdatesModal.d.ts","sourceRoot":"","sources":["../../../../src/highlight-updates/components/HighlightUpdatesModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAmD,MAAM,OAAO,CAAC;AAiBxE,OAAO,EAAiB,KAAK,aAAa,EAAqE,MAAM,wBAAwB,CAAC;AAe9I,UAAU,0BAA0B;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,CAAC;IACvC,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,IAAI,CAAC;IACvC;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAClD;AAcD,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,OAAO,EACP,MAAM,EACN,UAAU,EACV,2BAAmC,EACnC,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,MAAc,GACf,EAAE,0BAA0B,4BAsmB5B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,GAAE,IAAI,CAAC,0BAA0B,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAM,qBAK/E;AA2CD,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"HighlightUpdatesModal.d.ts","sourceRoot":"","sources":["../../../../src/highlight-updates/components/HighlightUpdatesModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAmD,MAAM,OAAO,CAAC;AAmBxE,OAAO,EAAiB,KAAK,aAAa,EAAqE,MAAM,wBAAwB,CAAC;AAe9I,UAAU,0BAA0B;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,CAAC;IACvC,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,IAAI,CAAC;IACvC;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAClD;AAcD,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,OAAO,EACP,MAAM,EACN,UAAU,EACV,2BAAmC,EACnC,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,MAAc,GACf,EAAE,0BAA0B,4BAsmB5B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,GAAE,IAAI,CAAC,0BAA0B,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAM,qBAK/E;AA2CD,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The one guarded require for React Native's RawEventEmitter.
3
+ *
4
+ * `RawEventEmitter` mirrors every event React Native dispatches BEFORE React's
5
+ * plugins or components see it, which makes it the only way to observe what a
6
+ * HUMAN is touching without instrumenting the app: Buoy mounts as a sibling of
7
+ * the app tree, not a parent, so there is no root View to put a capture
8
+ * responder on.
9
+ *
10
+ * Two things this file is careful about, both learned the hard way in
11
+ * focus-inspector's copy:
12
+ *
13
+ * 1. It is a DEEP import that RN's export map warns about and could move in any
14
+ * release. The failure has to degrade to "capture unavailable" rather than
15
+ * taking the host app's bundle down — and Metro only treats a require as
16
+ * optional when it sits LEXICALLY inside a try statement, so wrapping it in
17
+ * a helper or an arrow makes Metro hard-fail the bundle instead.
18
+ * 2. Keeping it in its own module gives the unit suite a seam: Node's `require`
19
+ * ignores Vitest's module mocks, so the emitter can only be faked by mocking
20
+ * a module reached with a real `import`.
21
+ */
22
+ export interface RawEventSubscription {
23
+ remove: () => void;
24
+ }
25
+ export interface RawEvent {
26
+ eventName?: string;
27
+ nativeEvent?: Record<string, unknown>;
28
+ }
29
+ export interface RawEventEmitterLike {
30
+ addListener: (eventType: string, listener: (event: RawEvent) => void) => RawEventSubscription;
31
+ }
32
+ export interface RawEmitterResolution {
33
+ emitter: RawEventEmitterLike | null;
34
+ reason: string | null;
35
+ }
36
+ export declare function resolveRawEventEmitter(): RawEmitterResolution;
37
+ //# sourceMappingURL=rawEventEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawEventEmitter.d.ts","sourceRoot":"","sources":["../../../../src/highlight-updates/utils/rawEventEmitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,CACX,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,KAChC,oBAAoB,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,wBAAgB,sBAAsB,IAAI,oBAAoB,CAiB7D"}