Skip to content

Commit e67b761

Browse files
committed
refactor(kernel): widen snapshotRefBodies to any ref-carrying record
The touch-point competitor disclosure and the MCP ref-pin merge each restated the filter over their own shape. Typed over the field rather than over SnapshotNode, both call it. Also states on the ref field why the geometry-requiring paths print it bare: a ref-less node carries no rect, so no acting path can reach one.
1 parent 7ca220e commit e67b761

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎packages/kernel/src/snapshot.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ export type SnapshotNode = RawSnapshotNode & {
398398
*
399399
* Every consumer that offers a node as an address must read this as an absence rather than print
400400
* one: a ref-less node is selectable by text and by `find`/`wait`/`get`, and refused as a target.
401+
*
402+
* A ref-less node also carries no `rect`. Producers that mint refs measure geometry for the refs
403+
* they issued (see `RawSnapshotNode.ref`), and producers that mint none get dense numbering, so
404+
* every node a geometry-requiring path can reach — promotion, the touch point, the covered and
405+
* keyboard refusals — has a ref. That is why those paths print `node.ref` without a guard.
401406
*/
402407
ref?: string;
403408
/**
@@ -815,9 +820,14 @@ export function hasSnapshotRef(node: SnapshotNode): node is SnapshotNode & { ref
815820
return node.ref !== undefined;
816821
}
817822

818-
/** The refs a node set can be re-addressed by; ref-less nodes contribute no ref evidence. */
819-
export function snapshotRefBodies(nodes: readonly SnapshotNode[]): string[] {
820-
return nodes.flatMap((node) => (node.ref === undefined ? [] : [node.ref]));
823+
/**
824+
* The refs a set of ref-carrying records can be re-addressed by; a record with no ref contributes no
825+
* evidence. Typed over the field rather than over `SnapshotNode` so every site holding an optional
826+
* ref (a node, a competitor rect, a published match) answers the same question here instead of
827+
* restating the filter.
828+
*/
829+
export function snapshotRefBodies(refCarriers: readonly { ref?: string }[]): string[] {
830+
return refCarriers.flatMap((carrier) => (carrier.ref === undefined ? [] : [carrier.ref]));
821831
}
822832

823833
/**

‎packages/selectors/src/interaction-touch-point.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { Point, Rect, SnapshotNode } from '@agent-device/kernel/snapshot';
1+
import {
2+
snapshotRefBodies,
3+
type Point,
4+
type Rect,
5+
type SnapshotNode,
6+
} from '@agent-device/kernel/snapshot';
27
import { containsPoint } from '@agent-device/kernel/rect';
38
import {
49
areRectsApproximatelyEqual,
@@ -47,9 +52,7 @@ export function resolveInteractionTouchPoint(
4752
if (!point) {
4853
return {
4954
kind: 'blocked',
50-
competitorRefs: competitors.flatMap((competitor) =>
51-
competitor.ref === undefined ? [] : [competitor.ref],
52-
),
55+
competitorRefs: snapshotRefBodies(competitors),
5356
competitorCount: competitors.length,
5457
};
5558
}

‎src/mcp/tool-ref-pins.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function mergeSnapshotRefPins(
178178
// Ref-less nodes (the web backend's on-screen-but-unaddressable content) mint no pin: there is
179179
// no ref to pin, and an empty body would poison the scope's pin map.
180180
const bodies = [
181-
...(result.refs ?? []).flatMap(({ ref }) => (ref === undefined ? [] : [ref])),
181+
...snapshotRefBodies(result.refs ?? []),
182182
...snapshotRefBodies(result.nodes ?? []),
183183
];
184184
mergeIntoScopedPins(refPinsByScope, scopeKey, bodies, refsGeneration);

0 commit comments

Comments
 (0)