simframe 0.12.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -9
- package/native/simframed/Sources/SimframeCore/Motion.swift +33 -2
- package/native/supervise.swift +63 -4
- package/package.json +1 -1
- package/scripts/article-md.mjs +185 -0
- package/scripts/ci-device-guard.mjs +82 -0
- package/scripts/ci-integration-local.sh +33 -9
- package/scripts/ci-memory.mjs +117 -15
- package/scripts/eval-fingerprint.mjs +145 -3
- package/scripts/replay-rulings.mjs +60 -1
- package/src/actions.js +213 -13
- package/src/analyze.js +56 -0
- package/src/cli.js +205 -15
- package/src/fingerprint.js +10 -1
- package/src/graph.js +15 -2
- package/src/index.js +302 -16
- package/src/input.js +4 -0
- package/src/matching.js +17 -1
- package/src/mcp.js +148 -13
- package/src/metrics.js +49 -6
- package/src/navigate.js +4 -1
- package/src/ollama.js +37 -9
- package/src/platform/android.js +34 -0
- package/src/platform/index.js +7 -0
- package/src/platform/ios.js +128 -5
- package/src/platform/plist.js +156 -0
- package/src/refs.js +12 -1
- package/src/regions.js +54 -0
- package/src/screenmap.js +85 -6
- package/src/storage.js +201 -0
- package/src/store.js +53 -0
- package/src/supervisor.js +20 -2
- package/src/view.js +84 -9
package/src/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
isBlackFrame,
|
|
14
14
|
maxCellDelta,
|
|
15
15
|
CELL_CHANGE,
|
|
16
|
+
describeMotion,
|
|
16
17
|
regionDeltas,
|
|
17
18
|
regionMap,
|
|
18
19
|
signatureDiff,
|
|
@@ -125,6 +126,33 @@ export const READY_TIMEOUT_MS = 20_000;
|
|
|
125
126
|
*/
|
|
126
127
|
export const LIVE_DAEMON_CAP_MS = 60_000;
|
|
127
128
|
|
|
129
|
+
/**
|
|
130
|
+
* How many gestures may land on a motionless screen before that is evidence.
|
|
131
|
+
*
|
|
132
|
+
* **This replaces a duration threshold, and the replacement is the point.** The
|
|
133
|
+
* first version asked "has the screen been still for a long time?" and needed
|
|
134
|
+
* 20 s before it would speak. A field report then caught a frame roughly three
|
|
135
|
+
* hours stale, presented as 130 ms old, on a screen still for **8.2 seconds** —
|
|
136
|
+
* so the check sat silently under its own gate during exactly the failure it
|
|
137
|
+
* was written for. A threshold chosen from one earlier example is not a
|
|
138
|
+
* mechanism.
|
|
139
|
+
*
|
|
140
|
+
* What says "dead surface" is not how long the screen has been quiet. It is
|
|
141
|
+
* that we kept touching it and *nothing moved at all*. One tap that changes
|
|
142
|
+
* nothing is ordinary — a disabled control, a form refusing a submit. Three in
|
|
143
|
+
* a row, with not one pixel of response, is a different claim.
|
|
144
|
+
*/
|
|
145
|
+
export const SURFACE_SUSPECT_INPUTS = 3;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Slack between "input landed" and "the screen should have moved".
|
|
149
|
+
*
|
|
150
|
+
* A gesture only counts against the surface if it landed *inside* the quiet
|
|
151
|
+
* period with room to spare — otherwise the tap that ends the quiet period
|
|
152
|
+
* counts as evidence against it.
|
|
153
|
+
*/
|
|
154
|
+
export const SURFACE_MARGIN_MS = 400;
|
|
155
|
+
|
|
128
156
|
export function daemonStatus(udid) {
|
|
129
157
|
const meta = store.readJson(store.paths(udid).meta);
|
|
130
158
|
const pid = meta?.pid ?? null;
|
|
@@ -149,10 +177,13 @@ export async function ensureDaemon(deviceQuery, options = {}) {
|
|
|
149
177
|
// A dead daemon leaves its last state.json behind. Anything captured before
|
|
150
178
|
// we (re)started the loop is not evidence of a live screen, so ignore it.
|
|
151
179
|
const minCapturedAt = existing.alive ? 0 : Date.now();
|
|
180
|
+
// The pid we spawned, which is the only honest answer to "did a daemon come
|
|
181
|
+
// up" — see the comment on the wait below.
|
|
182
|
+
let spawnedPid = null;
|
|
152
183
|
if (!existing.alive) {
|
|
153
184
|
if (acquireSpawnLock(p.lock)) {
|
|
154
185
|
try {
|
|
155
|
-
await startEngine(device.udid, options);
|
|
186
|
+
spawnedPid = (await startEngine(device.udid, options)).pid;
|
|
156
187
|
} finally {
|
|
157
188
|
// Hold the lock briefly so a burst of callers does not double-spawn.
|
|
158
189
|
setTimeout(() => releaseSpawnLock(p.lock), 1500).unref?.();
|
|
@@ -178,25 +209,64 @@ export async function ensureDaemon(deviceQuery, options = {}) {
|
|
|
178
209
|
// had read identically, which cost a log dive to tell apart.
|
|
179
210
|
const liveDeadline = Date.now() + LIVE_DAEMON_CAP_MS;
|
|
180
211
|
let sawLiveDaemon = false;
|
|
212
|
+
let sawProcess = false;
|
|
181
213
|
for (;;) {
|
|
182
214
|
const state = store.readJson(p.state);
|
|
183
215
|
if (state && state.capturedAt >= minCapturedAt && Date.now() - state.capturedAt < 30_000) {
|
|
184
216
|
return { device, state, started: !existing.alive };
|
|
185
217
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
218
|
+
// Two different questions, and for a long time one file answered both.
|
|
219
|
+
//
|
|
220
|
+
// `daemonStatus` reads meta.json, which the daemon writes in `claim()` —
|
|
221
|
+
// *after* `platform.attach`, its slowest startup step. So a daemon that has
|
|
222
|
+
// spawned and is attaching to CoreSimulator is indistinguishable, from
|
|
223
|
+
// here, from one that never started: both are `alive: false`. That is the
|
|
224
|
+
// condition the live cap below exists for, and it could never be reached in
|
|
225
|
+
// the case that produced it, because reaching it required the very file
|
|
226
|
+
// whose absence was the problem.
|
|
227
|
+
//
|
|
228
|
+
// Measured on a hosted runner, 2026-09-13: `simframe start` gave up after
|
|
229
|
+
// 20 s saying **"no daemon process came up"**, and the next step of the
|
|
230
|
+
// same job printed `● iPhone 16 Pro pid=9573 frame=#5 age=652ms` with a
|
|
231
|
+
// daemon log showing it had been capturing the whole time. The sentence was
|
|
232
|
+
// not merely unhelpful, it named the wrong condition — the fourth time this
|
|
233
|
+
// project has failed that way and the second time in two days.
|
|
234
|
+
//
|
|
235
|
+
// The pid we spawned is the honest signal and it was already in hand;
|
|
236
|
+
// `startEngine` was discarding it.
|
|
237
|
+
const claimed = daemonStatus(device.udid).alive;
|
|
238
|
+
const running = claimed || (spawnedPid != null && store.isProcessAlive(spawnedPid));
|
|
239
|
+
sawLiveDaemon = sawLiveDaemon || claimed;
|
|
240
|
+
sawProcess = sawProcess || running;
|
|
241
|
+
if (Date.now() >= (running ? liveDeadline : deadline)) break;
|
|
189
242
|
await sleep(80);
|
|
190
243
|
}
|
|
191
244
|
const tail = readLogTail(p.log);
|
|
192
|
-
const waited = sawLiveDaemon
|
|
193
|
-
? `the daemon is running and the display produced no frame in ${Math.round(LIVE_DAEMON_CAP_MS / 1000)}s`
|
|
194
|
-
: 'no daemon process came up';
|
|
195
245
|
throw new Error(
|
|
196
|
-
`simframe daemon did not produce a frame for ${device.name} —
|
|
246
|
+
`simframe daemon did not produce a frame for ${device.name} — `
|
|
247
|
+
+ `${readinessFailure({ sawLiveDaemon, sawProcess })}${tail ? `\n${tail}` : ''}`,
|
|
197
248
|
);
|
|
198
249
|
}
|
|
199
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Which of three failures this was.
|
|
253
|
+
*
|
|
254
|
+
* Extracted so it can be tested, for the reason `screenshotFailure` was: the
|
|
255
|
+
* whole defect here is a message naming the wrong condition, and a message is
|
|
256
|
+
* only checkable if something can ask for it without a device. Two of these
|
|
257
|
+
* three sentences did not exist until a runner produced each of them in turn and
|
|
258
|
+
* both arrived reading as the third.
|
|
259
|
+
*/
|
|
260
|
+
export function readinessFailure({ sawLiveDaemon, sawProcess }) {
|
|
261
|
+
const cap = Math.round(LIVE_DAEMON_CAP_MS / 1000);
|
|
262
|
+
if (sawLiveDaemon) return `the daemon is running and the display produced no frame in ${cap}s`;
|
|
263
|
+
if (sawProcess) {
|
|
264
|
+
return `the daemon process started but never claimed the device in ${cap}s`
|
|
265
|
+
+ ' — it is stuck attaching to the simulator rather than failing to launch';
|
|
266
|
+
}
|
|
267
|
+
return 'no daemon process came up';
|
|
268
|
+
}
|
|
269
|
+
|
|
200
270
|
/** Why the daemon was not used, when it was not. Surfaced by doctor. */
|
|
201
271
|
export let engineFallbackReason = null;
|
|
202
272
|
|
|
@@ -252,14 +322,16 @@ async function startEngine(udid, options) {
|
|
|
252
322
|
if (built.ok) {
|
|
253
323
|
engineFallbackReason = null;
|
|
254
324
|
recordFallback(udid, null);
|
|
255
|
-
|
|
256
|
-
|
|
325
|
+
// The pid, not just the name. Whether a daemon came up is a question
|
|
326
|
+
// about a process, and answering it from meta.json — which the daemon
|
|
327
|
+
// writes only after attaching — could not tell "never started" from
|
|
328
|
+
// "still starting". See the wait in `ensureDaemon`.
|
|
329
|
+
return { engine: 'simframed', pid: engine.spawnDaemon(udid, options)?.pid ?? null };
|
|
257
330
|
}
|
|
258
331
|
engineFallbackReason = built.reason ?? 'simframed unavailable';
|
|
259
332
|
recordFallback(udid, engineFallbackReason);
|
|
260
333
|
}
|
|
261
|
-
spawnNodeDaemon(udid, options);
|
|
262
|
-
return 'screenshot';
|
|
334
|
+
return { engine: 'screenshot', pid: spawnNodeDaemon(udid, options)?.pid ?? null };
|
|
263
335
|
}
|
|
264
336
|
|
|
265
337
|
function spawnNodeDaemon(udid, options) {
|
|
@@ -283,6 +355,7 @@ function spawnNodeDaemon(udid, options) {
|
|
|
283
355
|
env: process.env,
|
|
284
356
|
});
|
|
285
357
|
child.unref();
|
|
358
|
+
return child;
|
|
286
359
|
}
|
|
287
360
|
|
|
288
361
|
function acquireSpawnLock(lockFile) {
|
|
@@ -423,6 +496,49 @@ export function liveness(udid, state) {
|
|
|
423
496
|
if (!damageDriven && ageMs > STALE_FRAME_MS) {
|
|
424
497
|
return { ok: false, ageMs, stalled: false, note: `capture loop is stalled: newest frame is ${ageMs}ms old` };
|
|
425
498
|
}
|
|
499
|
+
|
|
500
|
+
// A live loop re-reading a dead surface, which every other signal calls fine.
|
|
501
|
+
//
|
|
502
|
+
// Reported from the field on 0.12.2, and it is the most expensive shape this
|
|
503
|
+
// tool has produced: `sim_look` served the *login screen* for three minutes
|
|
504
|
+
// while the app was four screens deep in a wizard, and announced the frame as
|
|
505
|
+
// 66ms old. The daemon was not lying — the frame really was new. It was a new
|
|
506
|
+
// read of a surface that had stopped updating. Every check above passes: the
|
|
507
|
+
// process is alive, no read failed, the age is tiny.
|
|
508
|
+
//
|
|
509
|
+
// The contradiction is between two numbers we already have. `stableForMs`
|
|
510
|
+
// says the screen has not changed in N ms; `lastInputAt` says we were
|
|
511
|
+
// delivering taps and swipes during that window. A screen that has not moved
|
|
512
|
+
// since *before* we last touched it, for long enough that several gestures
|
|
513
|
+
// landed inside the quiet period, is not a calm screen. The tester's own
|
|
514
|
+
// figures: stable for 159,753 ms across three screen transitions.
|
|
515
|
+
//
|
|
516
|
+
// Deliberately a WARNING and not a failure. A genuinely inert screen is
|
|
517
|
+
// possible — a form that rejects every tap, a disabled control tapped twice —
|
|
518
|
+
// and turning that into a hard error would be a confident wrong answer of
|
|
519
|
+
// exactly the kind this project keeps paying for. It says what it sees and
|
|
520
|
+
// names the arbiter.
|
|
521
|
+
const stableForMs = state?.stableForMs;
|
|
522
|
+
if (Number.isFinite(stableForMs)) {
|
|
523
|
+
// The moment the screen last moved. Every gesture delivered after it landed
|
|
524
|
+
// on a screen that did not react.
|
|
525
|
+
const lastChange = Date.now() - stableForMs + SURFACE_MARGIN_MS;
|
|
526
|
+
const ignored = store.inputTimes(udid).filter((t) => t > lastChange);
|
|
527
|
+
if (ignored.length >= SURFACE_SUSPECT_INPUTS) {
|
|
528
|
+
const quiet = Math.round(stableForMs / 1000);
|
|
529
|
+
return {
|
|
530
|
+
ok: true,
|
|
531
|
+
ageMs,
|
|
532
|
+
stalled: false,
|
|
533
|
+
suspectSurface: true,
|
|
534
|
+
ignoredInputs: ignored.length,
|
|
535
|
+
note: `${ignored.length} gestures have been delivered without the screen moving at all `
|
|
536
|
+
+ `(still for ${quiet < 1 ? `${Math.round(stableForMs)}ms` : `${quiet}s`}), `
|
|
537
|
+
+ 'so the frames are new and the surface behind them may be dead. '
|
|
538
|
+
+ 'The accessibility tree is read separately and is the tiebreaker; `simframe revive` re-attaches capture.',
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
}
|
|
426
542
|
return { ok: true, ageMs, stalled: false, note: null };
|
|
427
543
|
}
|
|
428
544
|
|
|
@@ -748,6 +864,37 @@ function timingOfNow(udid, state) {
|
|
|
748
864
|
* sampled after the fact is the single most common way to wait for a change
|
|
749
865
|
* that has already happened.
|
|
750
866
|
*/
|
|
867
|
+
/**
|
|
868
|
+
* How far back "still moving" looks, in milliseconds.
|
|
869
|
+
*
|
|
870
|
+
* **In time, not in frames**, and that distinction is the whole of it. The
|
|
871
|
+
* first version kept the last eight frame pairs, on the reasoning that at a
|
|
872
|
+
* 60 ms poll floor eight frames is about half a second. Frames are not a clock:
|
|
873
|
+
* capture is damage-driven with a slow idle floor, so on a quiet screen eight
|
|
874
|
+
* frames spanned *sixteen seconds* — and the window still held the transition
|
|
875
|
+
* that had brought us to the screen. A home screen with one animated widget
|
|
876
|
+
* duly reported movement in all thirty-two regions.
|
|
877
|
+
*
|
|
878
|
+
* One second, long enough that a stepping animation is not missed between two
|
|
879
|
+
* frames and short enough that the entry transition is gone by the time a
|
|
880
|
+
* settle gives up.
|
|
881
|
+
*/
|
|
882
|
+
export const MOTION_WINDOW_MS = 1000;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* How young a frame has to be to count as "the screen right now".
|
|
886
|
+
*
|
|
887
|
+
* The daemon's idle floor is 2,000 ms — on a screen with no damage it captures
|
|
888
|
+
* anyway, at that cadence, precisely so state stays fresh enough to reason
|
|
889
|
+
* about. So a frame younger than that floor plus a margin is the current
|
|
890
|
+
* screen; older than it means the loop has missed its own beat, which is what
|
|
891
|
+
* `liveness` is for.
|
|
892
|
+
*
|
|
893
|
+
* Tied to the daemon's floor rather than chosen, because a number chosen here
|
|
894
|
+
* would drift away from it silently the first time the floor moved.
|
|
895
|
+
*/
|
|
896
|
+
export const FRAME_IS_CURRENT_MS = 2500;
|
|
897
|
+
|
|
751
898
|
export async function waitFor(
|
|
752
899
|
deviceQuery,
|
|
753
900
|
{ mode = 'settle', since, stableMs = 600, timeoutMs = 8000, reactionMs = 2500, baselineHash, options } = {},
|
|
@@ -789,6 +936,29 @@ export async function waitFor(
|
|
|
789
936
|
? hexToSignature(resolved.entry.sig)
|
|
790
937
|
: (requested == null ? hexToSignature(currentSig(first) ?? '') : null);
|
|
791
938
|
let smallChange = false;
|
|
939
|
+
/**
|
|
940
|
+
* Where the screen moved while we waited — item 123.
|
|
941
|
+
*
|
|
942
|
+
* The per-region maximum over a trailing window of frame pairs, so a settle
|
|
943
|
+
* that gives up can say *where* rather than only that it did.
|
|
944
|
+
*
|
|
945
|
+
* A window and not a running max over the whole wait, which is what the first
|
|
946
|
+
* version did and it was useless: every wait begins with the transition that
|
|
947
|
+
* brought us here, so a home screen with one animated widget reported
|
|
948
|
+
* movement in all thirty-two regions and "spread across the screen". The
|
|
949
|
+
* question a settle failure asks is *what is still moving*, not what has
|
|
950
|
+
* moved at any point since we started looking.
|
|
951
|
+
*
|
|
952
|
+
* A window rather than the last pair alone, because a blinking or stepping
|
|
953
|
+
* animation is between frames as often as not, and a single pair would
|
|
954
|
+
* report a still screen that is not one.
|
|
955
|
+
*
|
|
956
|
+
* Costs one subtraction per region per frame over a signature that was
|
|
957
|
+
* already read and parsed for `smallChange`.
|
|
958
|
+
*/
|
|
959
|
+
const motionRing = [];
|
|
960
|
+
let motionPrev = null;
|
|
961
|
+
let motionSeq = null;
|
|
792
962
|
/** Frames the display was not rendering at all. See `isBlackFrame`. */
|
|
793
963
|
let blackFrames = 0;
|
|
794
964
|
let blackSinceStart = null;
|
|
@@ -834,6 +1004,46 @@ export async function waitFor(
|
|
|
834
1004
|
sawChange = false;
|
|
835
1005
|
}
|
|
836
1006
|
|
|
1007
|
+
/**
|
|
1008
|
+
* What the daemon says is animating, if anything — and it has always known.
|
|
1009
|
+
*
|
|
1010
|
+
* `Motion.state` in the daemon localises a small persistent animation and
|
|
1011
|
+
* publishes it as `motion.animating`, a bounding box, alongside its own
|
|
1012
|
+
* `settled` flag. Nothing in JavaScript read either. `waitFor` decided
|
|
1013
|
+
* stillness from `stableForMs` alone, which is derived from a *mean* over the
|
|
1014
|
+
* grid, and a spinner does not move a mean.
|
|
1015
|
+
*
|
|
1016
|
+
* Measured on the testbed's Diagnostics screen, which now carries one on
|
|
1017
|
+
* purpose: frames arriving every 85 ms, `motion.animating` boxed at 13x13,
|
|
1018
|
+
* `motion.settled` **false** — and `stableForMs` **79,207**. Seventy-nine
|
|
1019
|
+
* seconds of claimed stillness on a screen that had never once stopped. A
|
|
1020
|
+
* field report had already called this in as `settled after 62ms` on a
|
|
1021
|
+
* still-loading screen.
|
|
1022
|
+
*
|
|
1023
|
+
* Deliberately reported and **not** acted on. Requiring the daemon's `settled`
|
|
1024
|
+
* here would be correct for a spinner and wrong for a text caret, which is
|
|
1025
|
+
* also small, also persistent, and must never stop a screen from settling —
|
|
1026
|
+
* and choosing between them needs a caret measured, not a threshold picked
|
|
1027
|
+
* today. So the disagreement becomes visible instead of being resolved by
|
|
1028
|
+
* guess: the caller is told a part of the screen is still moving and where,
|
|
1029
|
+
* and can decide. The decision is an open item with a number attached to it.
|
|
1030
|
+
*/
|
|
1031
|
+
const animatingNow = () => {
|
|
1032
|
+
const box = last?.motion?.animating;
|
|
1033
|
+
if (!box) return null;
|
|
1034
|
+
return { ...box, daemonSettled: last.motion.settled === true };
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
/** The last second of movement, collapsed to one per-region maximum. */
|
|
1038
|
+
function motionSummary() {
|
|
1039
|
+
const cutoff = Date.now() - MOTION_WINDOW_MS;
|
|
1040
|
+
const recent = motionRing.filter((e) => e.at >= cutoff);
|
|
1041
|
+
if (!recent.length) return null;
|
|
1042
|
+
const max = recent[0].deltas.map((_, i) => Math.max(...recent.map((e) => e.deltas[i] ?? 0)));
|
|
1043
|
+
if (!max.some((d) => d > 0)) return null;
|
|
1044
|
+
return { deltas: max, map: regionMap(max), windowMs: MOTION_WINDOW_MS, ...describeMotion(max) };
|
|
1045
|
+
}
|
|
1046
|
+
|
|
837
1047
|
const done = (satisfied, extra = {}) => ({
|
|
838
1048
|
device,
|
|
839
1049
|
state: last,
|
|
@@ -851,6 +1061,24 @@ export async function waitFor(
|
|
|
851
1061
|
// because the app drew black. What makes it the capture wedge is that it
|
|
852
1062
|
// stays black while input is being delivered, and the caller knows that.
|
|
853
1063
|
blackMs: blackSinceStart ? Date.now() - blackSinceStart : 0,
|
|
1064
|
+
// Only worth carrying when something actually moved; a still screen that
|
|
1065
|
+
// never satisfied the wait has nothing to point at.
|
|
1066
|
+
motion: motionSummary(),
|
|
1067
|
+
animating: animatingNow(),
|
|
1068
|
+
/**
|
|
1069
|
+
* Everything that decided this answer, for the failure message.
|
|
1070
|
+
*
|
|
1071
|
+
* Two CI cycles were spent guessing at a `screen did not settle within
|
|
1072
|
+
* 25008ms` — a sentence that names the one number which is never the
|
|
1073
|
+
* reason. The wait turns on three things and the log carried none of them:
|
|
1074
|
+
* how long the screen had actually been still, how much stillness was
|
|
1075
|
+
* being asked for, and whether any frame arrived at all. "Still for 1,200
|
|
1076
|
+
* of the 1,400 ms required" and "still for 135,000 ms and nothing arrived"
|
|
1077
|
+
* are opposite diagnoses and they had one sentence between them.
|
|
1078
|
+
*/
|
|
1079
|
+
stillForMs: Number.isFinite(last?.stableForMs) ? last.stableForMs : null,
|
|
1080
|
+
stableMsRequired: stableMs,
|
|
1081
|
+
framesSeen: Number.isFinite(last?.seq) ? last.seq - startSeq : null,
|
|
854
1082
|
baselineHash: baselineHashValue,
|
|
855
1083
|
baselineResolved,
|
|
856
1084
|
waitedMs: Date.now() - startedAt,
|
|
@@ -904,6 +1132,23 @@ export async function waitFor(
|
|
|
904
1132
|
}
|
|
905
1133
|
}
|
|
906
1134
|
|
|
1135
|
+
// Track where it is moving, on new frames only — comparing a frame with
|
|
1136
|
+
// itself is a row of zeros that would dilute nothing but waste the work.
|
|
1137
|
+
if (state.seq !== motionSeq) {
|
|
1138
|
+
const sigHex = currentSig(state);
|
|
1139
|
+
const sig = sigHex ? hexToSignature(sigHex) : null;
|
|
1140
|
+
if (sig) {
|
|
1141
|
+
if (motionPrev) {
|
|
1142
|
+
motionRing.push({ at: Date.now(), deltas: regionDeltas(sig, motionPrev) });
|
|
1143
|
+
// Bounded in time by the summary and in length here, so a screen
|
|
1144
|
+
// rendering at 60 fps for ten seconds cannot grow this without end.
|
|
1145
|
+
while (motionRing.length > 240) motionRing.shift();
|
|
1146
|
+
}
|
|
1147
|
+
motionPrev = sig;
|
|
1148
|
+
}
|
|
1149
|
+
motionSeq = state.seq;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
907
1152
|
// A pause that turned out not to be the end of the transition. Only
|
|
908
1153
|
// pauses followed by more movement count: the quiet at the end of a
|
|
909
1154
|
// settle is the answer, not a gap.
|
|
@@ -939,10 +1184,30 @@ export async function waitFor(
|
|
|
939
1184
|
// the caller acted can never satisfy it; once the change is seen,
|
|
940
1185
|
// stableForMs is measured from that change. Plain "stable" has no such
|
|
941
1186
|
// requirement — an already-still screen genuinely is stable.
|
|
942
|
-
//
|
|
943
|
-
//
|
|
1187
|
+
//
|
|
1188
|
+
// The evidence must be *current*, and that used to be spelled "at least
|
|
1189
|
+
// one frame must arrive during the call". The intent is right and the
|
|
1190
|
+
// spelling made the wait unsatisfiable on exactly the screens it is
|
|
1191
|
+
// asked about most. Capture is damage-driven: a screen that is not
|
|
1192
|
+
// moving produces no new frame by design, so on a still screen the
|
|
1193
|
+
// condition asks for evidence the system has deliberately chosen not to
|
|
1194
|
+
// generate, and the wait burns its whole budget and reports *"screen did
|
|
1195
|
+
// not settle"* about a screen that has been motionless throughout.
|
|
1196
|
+
//
|
|
1197
|
+
// Measured here rather than argued: a flow step reported `did not settle
|
|
1198
|
+
// within 1547ms` while its own evidence line read **still for 3548ms of
|
|
1199
|
+
// the 1400ms required; NO frame arrived while waiting**. Three and a half
|
|
1200
|
+
// seconds of stillness, two and a half times what was asked, refused.
|
|
1201
|
+
//
|
|
1202
|
+
// So currency is a question about time, not about a counter — the same
|
|
1203
|
+
// correction the motion window needed. A frame younger than the capture
|
|
1204
|
+
// loop's own idle floor *is* the screen as it is now. `liveness` is
|
|
1205
|
+
// checked at the top of every iteration and already rejects a stale file
|
|
1206
|
+
// from a dead daemon, which is the case the counter was really guarding.
|
|
944
1207
|
const freshFrames = state.seq - startSeq;
|
|
945
|
-
|
|
1208
|
+
const age = Date.now() - (state.capturedAt ?? 0);
|
|
1209
|
+
const current = freshFrames >= 1 || age <= FRAME_IS_CURRENT_MS;
|
|
1210
|
+
if (sawChange && current && state.stableForMs >= stableMs) {
|
|
946
1211
|
return done(true);
|
|
947
1212
|
}
|
|
948
1213
|
}
|
|
@@ -1470,7 +1735,28 @@ async function locateWith(
|
|
|
1470
1735
|
const target = index != null ? candidates[index] : candidates[0];
|
|
1471
1736
|
if (!target) {
|
|
1472
1737
|
const visible = entry.targets.filter((t) => t.label);
|
|
1473
|
-
const
|
|
1738
|
+
const shown = visible.slice(0, 12).map((t) => t.label);
|
|
1739
|
+
// Say when the list is cut. A field report found `"Work Orders" is not on
|
|
1740
|
+
// this screen. Visible: …` on a screen whose own element map, three lines
|
|
1741
|
+
// below in the same reply, listed `#25 text 200,836 Work Orders` — it was
|
|
1742
|
+
// simply past the twelfth entry. A truncated list that does not announce
|
|
1743
|
+
// its truncation reads as an exhaustive one.
|
|
1744
|
+
const sample = shown.join(', ') + (visible.length > shown.length ? `, …and ${visible.length - shown.length} more` : '');
|
|
1745
|
+
// An index past the end is not an absent element, and reporting it as one
|
|
1746
|
+
// sent a tester looking for a control that was on the screen all along.
|
|
1747
|
+
// `{"tap": "Work Orders", "index": 1}` on a screen with exactly one match
|
|
1748
|
+
// said "not on this screen" while the map listed it.
|
|
1749
|
+
if (index != null && candidates.length) {
|
|
1750
|
+
throw metrics.tag(
|
|
1751
|
+
new Error(
|
|
1752
|
+
`"${query}" matches ${candidates.length} thing${candidates.length === 1 ? '' : 's'} on this screen,`
|
|
1753
|
+
+ ` so index ${index} is out of range — valid indices are 0..${candidates.length - 1}.`
|
|
1754
|
+
+ ` Nearest: ${candidates.slice(0, 4).map((c) => `[${candidates.indexOf(c)}] ${JSON.stringify(String(c.label ?? '').slice(0, 28))}`).join(', ')}`,
|
|
1755
|
+
),
|
|
1756
|
+
'ambiguous_intent',
|
|
1757
|
+
{ candidates: candidates.slice(0, 8), intent: query, ambiguous: true },
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1474
1760
|
throw metrics.tag(
|
|
1475
1761
|
new Error(`"${query}" is not on this screen. Visible: ${sample || '(nothing readable)'}`),
|
|
1476
1762
|
from === 'memory' ? 'ambiguous_intent' : 'unknown_screen',
|
package/src/input.js
CHANGED
|
@@ -623,6 +623,10 @@ export function shouldRebuildSession({ stale, bootedAt }, rebuiltFor) {
|
|
|
623
623
|
const rebuiltForBoot = new Map();
|
|
624
624
|
export async function ensureFreshSession(udid) {
|
|
625
625
|
if (!udid) return null;
|
|
626
|
+
// Every input path calls this first, so it is the one place that knows the
|
|
627
|
+
// hands are about to move. `liveness` needs that timestamp to tell a calm
|
|
628
|
+
// screen from a dead surface — see `store.noteInput`.
|
|
629
|
+
store.noteInput(udid);
|
|
626
630
|
const health = await sessionHealth(udid);
|
|
627
631
|
if (!shouldRebuildSession(health, rebuiltForBoot.get(udid))) return null;
|
|
628
632
|
rebuiltForBoot.set(udid, health.bootedAt);
|
package/src/matching.js
CHANGED
|
@@ -170,7 +170,23 @@ export function rank(targets, intent, { screen } = {}) {
|
|
|
170
170
|
// An icon-only control has no readable name, so a synonym is the only way
|
|
171
171
|
// to reach it — this is how "back" finds a bare chevron.
|
|
172
172
|
if (group && base < 0.5 && !t.label && t.rawLabel) base = 0.55;
|
|
173
|
-
|
|
173
|
+
// Genuine synonymy only: the name must be a *different* word in the group.
|
|
174
|
+
//
|
|
175
|
+
// This branch fires only when `base < 0.5`, which means its whole job is to
|
|
176
|
+
// overrule the coverage scaling the two branches in `nameScore` were taught
|
|
177
|
+
// — and when the query already contains the name literally, that scaling was
|
|
178
|
+
// the right answer and this flat 0.9 throws it away. Reported (138): a long
|
|
179
|
+
// descriptive phrase ending "…under Settings" scored a *heading* labelled
|
|
180
|
+
// "Settings" at 0.9 and the row the caller meant at 0.265, tapped the
|
|
181
|
+
// heading, and returned `ok [no visible change]` with an `or` list untried.
|
|
182
|
+
//
|
|
183
|
+
// A name the query spells out has already been scored on how much of the
|
|
184
|
+
// query it covers. What this branch is for is the case that scoring cannot
|
|
185
|
+
// see at all: "back" reaching a control labelled "Previous", "settings"
|
|
186
|
+
// reaching "Preferences". That is synonymy, and it is unaffected.
|
|
187
|
+
const spelledOut = (n) => bare.includes(norm(n)) || norm(intent).includes(norm(n));
|
|
188
|
+
if (group && base < 0.5
|
|
189
|
+
&& names.some((n) => group.words.includes(norm(n)) && !spelledOut(n))) base = 0.9;
|
|
174
190
|
if (base <= 0) continue;
|
|
175
191
|
|
|
176
192
|
const reasons = [matched ? `label "${matched}"` : 'icon-only'];
|