Surface targetHittable/hint for non-hittable press/fill targets (#1037)

Merged
TH
5mo ago
+135-0

Summary

Fixes the observability half of #1037: press/fill/click reported plain success even when the resolved target's underlying AX node was hittable: false, so a tap could silently land on inert UI with no signal back to the agent.

The Maps pin case from #1037: press 'text="Anthropic - Headquarters"' on the Apple Maps home screen exact-matched a 30x30 map-pin annotation (hittable: false) instead of the recents row a human means ("Anthropic - Headquarters, 548 Market St…", a separate, longer-labeled node). The selector was unique, so no ambiguity machinery ever ran — the command proceeded, tapped inert map area, and reported success. A follow-up wait text for the place card then failed, but by then the agent had already moved on assuming the press worked.

What is surfaced now

When resolveSelectorInteractionTarget/resolveRefInteractionTarget (src/commands/interaction/runtime/resolution.ts) settle on a final node — after any hittable-ancestor promotion — whose hittable === false, the success payload for press/fill/click/longpress now includes:

  • targetHittable: false
  • hint: e.g. "The resolved element reports hittable: false, so this press may have had no visible effect. Verify with a snapshot, or prefer a @ref or a longer/more specific selector to target the intended element."

This flows through the existing ResolvedInteractionTarget contract (src/contracts/interaction.ts), the daemon's interactionResultExtra allowlist (src/daemon/handlers/interaction-touch-targets.ts — this is an explicit field allowlist, not a spread, so new fields had to be added there deliberately), and the MCP output schema (src/mcp/command-output-schemas.ts).

Also documents the selector disambiguation policy in agent-device help workflow (src/cli/parser/cli-help.ts): ambiguous matches on interactive commands resolve automatically — deepest node first, then smallest on-screen area, only an exact tie fails with "Selector did not resolve uniquely" — and replay/replay-heal apply the same policy for touch/fill/get-text. At least two contributors believed ambiguous selectors always failed; this closes that folklore gap.

What was deliberately NOT changed

  • No stricter resolution. No strict-unique requirement, no hittable filtering in resolveSelectorChain/resolveInteractionTarget. react-navigation's maestro suite has 185 tapOns on short/duplicated labels ('Albums' x9, 'Go back' x16) that exist as tab + header + button simultaneously — filtering or failing on non-hittable/ambiguous matches would break that suite. This PR is informational-only, per the issue's explicit ask.
  • The native iOS direct-selector fast path is untouched. fill/click with a single-term id=/label=/text=/value= selector on iOS take a separate fast path (readSimpleIosSelectorTarget → dispatchDirectIosSelectorInteraction in src/daemon/handlers/interaction-touch.ts) that calls straight into the native XCTest runner (interactor.fillElementSelector/pressElementSelector) and never builds a SnapshotNode, so there is no local hittable value to check. Extending that would mean changing the runner protocol itself — out of scope here. Note the exact repro in the issue (press 'text="..."') is not affected by this gap: press's direct-selector path is click-only (readDirectIosSelectorTapTarget returns null unless commandLabel === 'click'), so the reported scenario goes through resolution.ts and is covered by this fix. Only fill/click with simple selectors on iOS retain the gap.
  • The native-ref fast paths (maybeTapRefTarget/maybeFillRefTarget in src/commands/interaction/runtime/interactions.ts, used by backends exposing tapTarget/fillTarget, e.g. web) don't capture a snapshot at all, so there's no hittable value available to surface there either.

Testing

  • Unit tests added in src/commands/interaction/runtime/interactions.test.ts (press/fill non-hittable hint path, plus a negative case confirming hittable targets get no hint) and src/daemon/handlers/__tests__/interaction.test.ts (daemon-level payload assertions on an existing non-hittable-promotion fixture).
  • Doc test added in src/__tests__/cli-help.test.ts asserting the new disambiguation paragraph.
  • pnpm format && pnpm check:quick clean.
  • pnpm exec vitest run — full suite, 341 files / 3125 tests passed.
  • pnpm exec vitest run test/integration/provider-scenarios — 26 files / 87 tests passed (no response-shape regressions; these tests use partial-key matching so additive fields don't break them).

Closes #1037