feat(snapshot)!: make a node's ref optional and mint it per producer
Summary
SnapshotNode.ref was declared always present, which was already a lie the moment a capture's producer resolved actions against refs of its own: a node the producer issued no ref for has one missing, and every surface that prints a ref printed @undefined for it.
ref becomes optional and attachRefs takes the capture's minting mode:
snapshotRefMinting({ backend: 'web', producer: 'agent-browser' }) // 'backend-issued' — keeps the producer's refs, mints none
snapshotRefMinting({ backend: 'android', producer: 'appium-source' }) // 'dense' — numbers the tree exactly as before
snapshotRefMinting keys on the capture's producer, not its platform channel, and takes the whole provenance pair rather than a partial one. A channel is not a producer — the provenance table's own rule is that several producers can feed one channel with different guarantees, and only agent-browser resolves actions against refs of its own. A second adapter that lands on the web channel mints no refs, and a channel-keyed check would have moved it to backend-issued and silently stripped the refs its whole tree depends on (see the review-round comment below).
hasSnapshotRef and snapshotRefBodies are the one way to read the absence, and every surface that offers a node as an address now reads it: overlay labels, the printed snapshot line, settle tails, MCP ref pins, the touch-point competitor disclosure, keyboard occlusion, find/get reads, and the record- and replay-time target classifiers, whose ref evidence a ref-less node cannot contribute. No producer emits a ref-less node in this PR, so behavior is unchanged for every backend; the contract and its consumers land first so the capture that needs it (#3515) lands on top. 27 files, 582 gross lines.
Breaking for TypeScript consumers, source-level. SnapshotNode.ref is in the shipped declarations (dist/src/sdk-contracts.d.ts, re-exported as type SnapshotNode from dist/src/index.d.ts, and reached through SnapshotState.nodes / CaptureSnapshotResult.nodes / agent-device/contracts). Code that reads it as always present — const r: string = node.ref, a SnapshotNode passed where ref is required, node.ref.length — typechecks today and fails here; examples/sdk/client-session.ts:68 is that exact case, now guarded with target?.ref !== undefined before press({ ref: target.ref }). The repo has no changeset and no CHANGELOG (release.yml:203 generates notes from the commits since the last tag), so the record is the ! in the subject — feat(snapshot)!: … — the way dbf113a55 refactor(platform-android)!: … (#3023) carried one. Runtime behavior for every existing backend is unchanged; the version bump stays with the release owner.
Review round 2: the minting mode keys on the producer, not the channel
A cold review asked what snapshotRefMinting's provenance?.backend === 'web' does to a non-agent-browser web adapter (a webdriver- or Playwright-backed one) that publishes backend: 'web': it would flip to backend-issued and every node it publishes would lose the ref its actions resolve against. The axis was wrong and is fixed; the silent-stripping half has no live victim. Full evidence in the review-round comment.
- Wrong axis, now at the owning type. This file's own provenance table says one channel is fed by several producers with different guarantees and that presentation/geometry logic must key on the producer, never the channel —
xctestalone has four.REF_NAMESPACE_OWNERSnow names the producers that own their ref namespace, and the parameter is the whole pair (SnapshotCaptureProvenance) instead ofPartial<SnapshotProvenance>, so a caller cannot hand over a channel and leave this to guess who acquired the tree. That is pinned with@ts-expect-error, which failspnpm typecheckif the parameter widens back. - No second web producer exists.
src/core/interactors/web.tsis the only publisher ofbackend: 'web'and it stampsproducer: 'agent-browser'.provider-webdriveris typedExtract<SnapshotResult['backend'], 'android' | 'xctest'>,provider-limrunpublishes'xctest'/'limrun-ios-tree',provider-testmuhas no snapshot producer, and there is no Playwright/Puppeteer/webdriverio dependency in the workspace.{ backend: 'web', producer: <other> }is already a compile error (snapshot-provenance.test.ts). - Behavior for every existing producer is unchanged, and is
main's behavior: dense numbering. What changes is that the next adapter on the web channel gets dense numbering by default instead of having its refs stripped. - Tests: one case per entry in the provenance table (all nine non-
agent-browserpairs assertdense), typedsatisfies readonly SnapshotProvenance[]so a producer added to the table arrives with a case, plus a case pinning that a second web producer staysdense. Mutation-checked: reverting to the channel check fails exactly that one test.
Validation
Tested at e67b761af, rebased on origin/main (stack: #3515 → #3533 restacked on this head). pnpm check:affected --run --base origin/main on that commit under the machine-wide gate lock: all runnable checks passed; pnpm vitest run over kernel/selectors/capture-kit/replay-port/interaction/mcp/platform-web green; provider-integration green. Kernel tests cover both minting modes, the per-producer decision, and the addressability helpers. 28 files, 586 gross lines.
Unchanged-behavior proof: git diff --name-only origin/main...HEAD | grep -c '^packages/platform-' → 0, so no backend's capture path changes; the two test/integration/provider-scenarios/ files are the emulated page the contract is asserted against. "Every address surface reads the absence" is a completeness claim, so it carries its grep. grep -rn '@${.*.ref}' src packages --exclude-dir=dist-types leaves three families that print without a guard, and each is closed by a fact rather than by luck: the **acting** sites (find.ts:200and:426, target-visibility-stages.ts:45, resolution-disclosure.ts:87) take a node from a row declaring requireRect: true, and a ref-less node carries no rect— the invariant now stated on thereffield, and proven end to end by #3515's router case whereclick text=refuses withselector_not_found; the **ref-lookup** sites (ref-target-resolution.ts:124and:130, selector-read.ts:172) receive the ref as input; the two **collapsed-leaf warnings** (capture/runtime/snapshot.ts:381, quality-warnings.ts:101) require a label, and the web projection publishes ref-less text on value. The remaining prints (snapshot-lines.ts:66, settle-output.ts:111) are guarded, and the settle tail filters on hasSnapshotRef`.
That acting-site safety is a producer fact stated in the ref JSDoc, not yet a type fact: the pipeline rows declaring requireRect: true still carry a plain SnapshotNode. Typing them as SnapshotNode & { ref: string } needs a narrowing entry at the pipeline boundary rather than at the resolver, and I measured that separately rather than bundling it here — tracked as #3576, which records the attempt's error census (28 across 5 files) and why the guards relocate inward.
Risk: this widens a type every backend reads, so a consumer merged into main before this lands could assume a non-optional ref; typecheck catches it. The rebase onto main after #3482 landed is the evidence: its own new keyboard-chrome assertion (packages/capture-kit/src/snapshot-chrome.test.ts) read node.ref as required and went red at TS2345, fixed here by the file's existing guard idiom — assert the ref is there, then use it.