feat(snapshot): carry a presented-surface fact through capture and settle
Summary
Adds the typed presented-surface fact to the iOS capture contract and carries it end to end, so a
consumer of a baseline can ask whether a capture read a modal presentation instead of guessing from
tree shape (#3565). Layer 1 of 3 — the pipe, plus the one positive the runner already had: the
blocking-system-modal snapshot is stamped presented (live excerpts below). No other capture changes its
answer until layer 2 lands.
SnapshotState.presentedSurface?: 'presented' | 'absent' | 'unknown' sits beside the other
producer-stated facts with one wire reader, readPresentedSurfaceFact(payload): a payload with no own
key stays silence, a value under the key the reader cannot name is restated 'unknown', so a
malformed statement can never read as absence. It travels inside SnapshotState through the daemon capture
cache, the snapshot state minter, the digest response views, the Node client reader, and the
interaction and serialization field lists.
The reader takes the payload rather than the value it holds, because reading a wire fact is a property
lookup on data the producer controls and every caller would otherwise have to remember that twice: the
key has to be own, or a payload that carries no fact walks to Object.prototype — where anything
sharing the process could park 'absent', the one state that disarms the confirmation #1831 arms. The
value-level form is removed rather than left exported beside the safe one; nothing in production read
the bare value and the fact is unreleased, so a call site that cannot express the unsafe read beats a
comment warning callers off it.
PresentedSurface is a plain union. The reader validates against a table keyed by it, so a
vocabulary state without a row fails to compile instead of reading as unknown (TS2741), and the
lookup is own-property, so a published value naming constructor is not a state.
The client normalized the fact on the default response path and returned a digest payload unreshaped,
so the same field was read two ways depending on --response-level. A leveled payload now goes
through the same reader; a payload with no key stays byte-identical.
SurfaceScopedNodes baselines are minted by one function, surfaceScopedNodes in
@agent-device/capture-kit/snapshot-baseline: both settle routes, the moving-target gate, and find's
handoff. The one exception is the moving-target rest-proof tree in daemon/core/deferred-interaction-outcome.ts, which builds the same three facts locally: importing the mint there adds a module to the eager closure of most daemon entries (ADR 0027, measured by eager-closure-budgets). On find's handoff, PreresolvedInteractionTarget now carries tree: SurfaceScopedNodes minted from find's
own capture instead of mirroring nodes, surface and presentation field by field. Swift gets the vocabulary type
and payload field, with the blocking-system-modal payload stamped .presented — the one piece of
positive runner evidence that already exists.
45 files, +715/−69.
Validation
9b752cf69, rebased onto main: pnpm typecheck clean; vitest over the touched packages and the
interaction, capture and client suites green. The serialized pnpm check:affected --run result for each
layer is posted on the PR.
Live (iPhone 17 simulator, RN lab app, re-run with the runner built at 105fa6477, after the rebase that moved the stamp into snapshotForBlockingSystemModal; 9b752cf69 changes only the daemon rest-proof baseline since). The microphone permission prompt over the lab app:
{"success":true,"data":{"presentedSurface":"presented","nodes":[{"type":"Alert","label":"Allow “Agent Device Tester” to access your microphone?"}, …]}}
{"success":true,"data":{"presentedSurface":"presented","nodeCount":5}} // --level digest
Home, the lab after the prompt is dismissed, and Home with --level digest publish no presentedSurface
key.
New tests fail on revert: the reader's malformed-vs-missing split, that a key present with no value
reads unknown rather than the silence of no key (the payload helper takes a required argument so a
test cannot accidentally build the missing-key shape it meant to test), that a payload with no own key
is silent while Object.prototype.presentedSurface = 'absent' is installed (both at the reader and at
the client, for digest and full; swapping the own-key check for a plain === undefined guard fails
three of them), that an inherited
Object.prototype member naming a state is not one, the digest reader's normalization (which fails when the digest path returns the
payload untouched), the baseline minter, find's handoff carrying the capture's
presentation to the leaf's tree (find.test.ts), carriage into both the response and the session record
(presented-surface-carriage.test.ts), the client wire reader, and the Swift payload stamp. The two Swift
payload tests need the unit-test condition to compile at all
(AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS=1 pnpm build:xcuitest:ios), which is also how a missing
import AgentDeviceSnapshotPresentation in this layer was caught; the Swift unit tests compile at this head and ran green
on the iPhone 17 simulator at 29aaf3be2. The rebase did not touch the Swift side.