Skip to content

feat(snapshot): add --wait-for flag for polling until element appears #929

Description

@fuleinist

Summary

Add a --wait-for flag to agent-device snapshot that polls the accessibility tree until a target element appears, with configurable timeout.

Motivation

AI agents frequently need to wait for UI state changes: a modal to appear, a loading spinner to disappear, a specific button to become available. Today agents must implement their own polling loop: snapshot, check, sleep, retry. This burns tokens, adds latency, and duplicates logic across every agent workflow.

Proposed shape

agent-device snapshot --wait-for "button:contains('Submit')" --timeout 15
agent-device snapshot --wait-for "window:contains('Settings')" --timeout 10
agent-device tap "button:contains('Save')" --wait-for "text:contains('Saved!')" --timeout 5

Key design points

  • Polls the accessibility tree at a reasonable interval (e.g. 500ms)
  • Returns the snapshot as soon as the target element appears
  • Returns exit code 1 + last snapshot if timeout expires
  • Reuses existing selector/filter infrastructure
  • Works with any command that produces a snapshot: snapshot, tap, type, etc.
  • Compact output: only the final snapshot (not intermediate polls)

Why small

The polling loop is straightforward, the selector infrastructure already exists, and this is purely a CLI orchestration feature - no new platform APIs or accessibility tree changes needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions