"""Browser agent core: observe -> act -> verify -> recover. The agent grounds task targets semantically (role + text/label/name) in a fresh DOM snapshot before every step. When an action or a verification fails it can *recover* (recovery ON): * re-ground the target with fallback strategies (structural match: the submit control of the named form/container, partial-text match), * dismiss a blocking overlay via its dismiss control, * retry within a small budget (MAX_RETRIES). With recovery OFF none of that happens: the first failure ends the task. That ablation is what the eval measures. Every failure and recovery is written to a JSONL run log. """ from __future__ import annotations import json import time from dataclasses import dataclass, field from .snapshot import Snapshot ACTION_TIMEOUT_MS = 3000 VERIFY_TIMEOUT_S = 2.0 MAX_RETRIES = 2 DISMISS_TEXTS = {"×", "x", "close", "accept", "accept all", "dismiss", "got it", "ok", "no thanks"} @dataclass class Target: """Semantic description of the element a step acts on.""" role: str # button | link | textbox | combobox | checkbox | radio text: str = "" # visible text (buttons, links) label: str = "" #