Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(cu): proactively zoom-refine before the first click when opted in

Ruben Lütkeb64b8a607591
diff --git a/jarvis/harness/screenshot_only_loop.py b/jarvis/harness/screenshot_only_loop.py
index 4b869c1f57..1242a74951 100644
--- a/jarvis/harness/screenshot_only_loop.py
+++ b/jarvis/harness/screenshot_only_loop.py
@@ -2832,14 +2832,27 @@ async def _click_with_refine(
retry_note = ""
snapped = False # Phase 2: UIA snap is tried at most once per click action
for _attempt in range(_CLICK_MAX_ATTEMPTS):
+ # Proactive zoom-before-click ([computer_use].zoom_before_click, opt-in,
+ # default off): run the zoom-refine BEFORE the first click too, not only
+ # after a verified miss. Needs a named target to confirm against;
+ # without one it would only add a round-trip, so it falls through to the
+ # coarse click. Internal screenshot crop only — nothing renders on
+ # screen; on a not-found verdict the loop re-plans instead of clicking
+ # the wrong element (handled below).
+ proactive_zoom = (
+ not clicked
+ and bool(target)
+ and getattr(ctx, "zoom_before_click", False)
+ )
refined = None
- if clicked:
+ if clicked or proactive_zoom:
# Trust-first (2026-06-10 latency plan Task 3): the refine pass is
# a full LLM round-trip, and on the FIRST attempt it corrected the
# model's point by <=5 px in live runs — pure cost (the executor
# and the refiner see the same frame). Reserve it for retries
- # after a verified miss, where the zoomed live crop genuinely
- # re-locates the target.
+ # after a verified miss UNLESS the operator opted into proactive
+ # zoom above, where the zoomed live crop re-locates the target and
+ # guards against a wrong-element click.
refined = await _refine_click_point(
ctx, observation, x, y, monitor_geom,
user_goal=user_goal, target=target, retry_note=retry_note,
diff --git a/tests/unit/harness/test_cu_click_refine.py b/tests/unit/harness/test_cu_click_refine.py
index b701a79e59..1b6cb150fb 100644
--- a/tests/unit/harness/test_cu_click_refine.py
+++ b/tests/unit/harness/test_cu_click_refine.py
@@ -161,13 +161,15 @@ class FakeExecutor:
class FakeCtx:
def __init__(self, brain: FakeBrain, executor: FakeExecutor, *,
- verify: bool = True) -> None:
+ verify: bool = True, zoom: bool = False) -> None:
self.brain_manager = brain
self.tool_executor = executor
self.tools = {"click": FakeTool()}
self.bus = None
self.per_step_timeout_s = 5.0
self.verify_after_each_step = verify
+ # Opt-in proactive zoom-before-click (default off mirrors production).
+ self.zoom_before_click = zoom
# These tests isolate the LLM refine path; the Phase-2 UIA snap (which
# would otherwise fire first on a verified miss and query the real host
# accessibility tree) is turned off so the refine behaviour is tested in
@@ -427,3 +429,107 @@ async def test_unknown_monitor_geometry_keeps_legacy_click_path(
assert executor.clicks == [(500, 500)]
assert brain.requests == []
assert grab.calls == 0
+
+
+# ---------------------------------------------------------------------------
+# Opt-in proactive zoom-before-click ([computer_use].zoom_before_click)
+# ---------------------------------------------------------------------------
+
+
+async def test_zoom_off_first_click_uses_coarse_point(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # Default (flag off): the first attempt clicks the model's coarse point with
+ # no proactive refine call — the trust-first default is preserved.
+ brain = FakeBrain()
+ executor = FakeExecutor()
+ _patch(monkeypatch, GrabQueue([b"pre", b"post-different"]))
+
+ ok, _msg = await _click(
+ FakeCtx(brain, executor, zoom=False),
+ {"action": "click", "x": 500, "y": 500, "target": "skip button"},
+ )
+
+ assert ok is True
+ assert executor.clicks == [(500, 500)]
+ assert brain.requests == [] # no proactive refine on the default path
+
+
+async def test_zoom_on_relocates_target_before_first_click(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # Flag on + target: a proactive refine round runs BEFORE the first click and
+ # re-locates the target at crop-norm (250,250) inside the 360px crop at
+ # (320,320) -> abs (410,410). The FIRST click lands on the refined point.
+ brain = FakeBrain(['{"found": true, "x": 250, "y": 250}'])
+ executor = FakeExecutor()
+ # grab order: refine crop, then verify pre, then verify post.
+ _patch(monkeypatch, GrabQueue([b"refine-crop", b"pre", b"post-different"]))
+
+ ok, _msg = await _click(
+ FakeCtx(brain, executor, zoom=True),
+ {"action": "click", "x": 500, "y": 500, "target": "skip button"},
+ )
+
+ assert ok is True
+ assert executor.clicks == [(410, 410)]
+ assert len(brain.requests) == 1 # exactly the proactive refine call
+
+
+async def test_zoom_on_target_not_in_crop_refuses_to_click(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # Flag on + target NOT visible in the zoom crop: the loop must NOT click
+ # (the coarse estimate was so far off the named target is not even in the
+ # crop) and returns a re-plan signal — the wrong-element guard.
+ brain = FakeBrain(['{"found": false}'])
+ executor = FakeExecutor()
+ _patch(monkeypatch, GrabQueue([b"refine-crop"]))
+
+ ok, msg = await _click(
+ FakeCtx(brain, executor, zoom=True),
+ {"action": "click", "x": 500, "y": 500, "target": "skip button"},
+ )
+
+ assert ok is False
+ assert executor.clicks == []
+ assert "re-plan" in msg
+
+
+async def test_zoom_on_without_target_uses_coarse_point(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # Flag on but the action carries NO target — nothing to confirm against, so
+ # the proactive refine is skipped and the coarse point is clicked directly.
+ brain = FakeBrain()
+ executor = FakeExecutor()
+ _patch(monkeypatch, GrabQueue([b"pre", b"post-different"]))
+
+ ok, _msg = await _click(
+ FakeCtx(brain, executor, zoom=True),
+ {"action": "click", "x": 500, "y": 500}, # no "target"
+ )
+
+ assert ok is True
+ assert executor.clicks == [(500, 500)]
+ assert brain.requests == []
+
+
+async def test_zoom_on_crop_grab_fails_falls_back_to_coarse(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # Flag on + target, but the live crop grab fails (None): the proactive
+ # refine degrades to None and the loop clicks the coarse point. Fail-safe.
+ brain = FakeBrain()
+ executor = FakeExecutor()
+ # grab 1 (refine crop) -> None; grab 2 pre, grab 3 post.
+ _patch(monkeypatch, GrabQueue([None, b"pre", b"post-different"]))
+
+ ok, _msg = await _click(
+ FakeCtx(brain, executor, zoom=True),
+ {"action": "click", "x": 500, "y": 500, "target": "skip button"},
+ )
+
+ assert ok is True
+ assert executor.clicks == [(500, 500)]
+ assert brain.requests == [] # grab failed before any brain call