feat(interaction): readiness wait for replay and the Node client on a shared observation engine
Summary
Part of #3069. Merge after #3070 and #3071. The post-gesture and scroll migrations moved to a stacked PR, so this PR is the engine plus its one consumer, the readiness wait, and can be dropped whole if the #3077 soak says so.
press, click, and longpress take an operator-only readinessTimeoutMs. With it, a target that is not on screen yet is looked for every 200 ms, up to the value (capped at 2 s), then the requested interaction runs once. A covered, off-screen, or ambiguous target still fails at once; only an unreadable capture is waited out (and if every capture is unreadable, that typed error surfaces, not selector_not_found); a sparse capture ends the wait with reason: capture_sparse. Which commands take the budget is one registry trait, targetReadiness: 'budgeted'; a command without it refuses the key; the envelope widens by the capped budget only for those commands; replay reads the trait.
Replay: recorded steps carry targetEvidence and are verified before dispatch, so the pre-dispatch gate now polls under the same schedule, then hands the remaining budget to the dispatch (one 2 s budget per step, not two). A gate that waited emits the same interaction_target_readiness diagnostic as the daemon, and a selector-miss divergence carries error.details.readiness.
await client.interactions.press({ selector: 'label="Continue"', readinessTimeoutMs: 2_000 });
The wait runs on observeUntil in capture-kit: one cadence, one deadline rule (the budget bounds when a poll starts), a declared per-capture deadline mode (captureDeadline: 'cancel' | 'none'; a capture that cannot honor the signal is judged late, never stalled), ride-out with lastError, and a per-poll timeline with a failed outcome. The verdict stays with the caller. ADR 0011 gains the targetReadiness cell. resolution.ts (1411 lines on main) is split by domain question into ten modules, the largest 323 (refactor(move), bodies unchanged). captureDeadline defaults to 'none'; readiness opts into 'cancel'; the schedule has one owner in the selectors policy; the replay gate polls under it and hands the remainder to the dispatch.
Over the 1,000-line budget by maintainer decision; the split is most of the churn. Docs: replay-e2e.md, client-api.md.
Validation
Tested commit d476097d60 (rebased on main after #3070): all 19 CI checks pass; local pnpm check:affected --run: 1591 of 1592 files green, scripts/fuzz/harness.test.ts (untouched here) timed out once and passes alone.
- Engine: 14 tests (deadline modes, ride-out
lastError,minPollspast the budget,failedoutcome). Readiness: all-unreadable surfaces the typed reason; scenarios for target on the third capture, never appears, first capture hits, option absent, sparse. - Replay: target renders on the second capture → dispatched with its guard and one diagnostic; renders at 1.6 s → dispatch gets 400 ms; never →
selector-misswithreadiness;fillgets no wait..adround-trip of annotations attarget-annotation-serde.ts:169/249. - Registry: the trait set equals the budgeted
targetReadinesscells;fillrefusesreadinessTimeoutMs;999_000widens by 2000. - Live: 46 interleaved A/B runs on a private iPhone 17 Pro simulator under host load, 46/46 both ways, the wait never engaged; cost parity on the hit path only. Keep-or-drop follows the nightly soak (#3077). The annotated-replay live run with an engaged wait is still open.