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.

chore: auto-save WIP via Claude stop-hook safety net (2026-07-02 19:20)

Ruben Lütkec206610ef8cd
diff --git a/jarvis/cu/engine.py b/jarvis/cu/engine.py
index da057e0dd1..98dba48f39 100644
--- a/jarvis/cu/engine.py
+++ b/jarvis/cu/engine.py
@@ -66,6 +66,7 @@ from jarvis.cu.verify import (
foreground_ui_snapshot,
regions_equal,
snap_point_to_element,
+ verify_click_focus_point,
verify_typed_text,
)
@@ -937,6 +938,21 @@ async def run_cu_loop(
if pre is not None and post is not None and frames_differ(pre, post):
detail = (detail + " — screen reacted elsewhere").strip()
+ elif await verify_click_focus_point(*resolved_xy) is True:
+ # Zero pixel change because the target was
+ # ALREADY in the desired state: the click point
+ # sits inside the control that holds keyboard
+ # focus (a default-focused address bar changes
+ # nothing when clicked). Failing this click
+ # beheads the batched type behind it and stalls
+ # the mission AT its goal (live incident
+ # 2026-07-02 19:06).
+ detail = (
+ detail
+ + " — no visible change, but the click "
+ "landed in the focused control (already in "
+ "the desired state)"
+ ).strip(" —")
else:
ok = False
detail = (
@@ -1015,6 +1031,14 @@ async def run_cu_loop(
ledger.record(action, frame.thumb)
if strict_verify:
landed = await verify_typed_text(action["text"])
+ if landed is False:
+ # One settle + re-check before failing: async UI
+ # surfaces (UWP flyouts, start menu) commit the
+ # typed value AFTER the injection returns, so an
+ # immediate read-back sees stale state (live
+ # incident 2026-07-02 18:00).
+ await asyncio.sleep(0.3 * settle_scale)
+ landed = await verify_typed_text(action["text"])
if landed is False:
ok = False
detail = (
diff --git a/jarvis/cu/verify.py b/jarvis/cu/verify.py
index 65ffcb281d..937fe0f9c4 100644
--- a/jarvis/cu/verify.py
+++ b/jarvis/cu/verify.py
@@ -79,21 +79,64 @@ def typed_text_landed(nodes: tuple, typed: str) -> bool | None:
"""Tri-state type read-back (conservative):
``True`` — an editable field's value contains the typed text.
- ``False`` — editable fields ARE readable and none holds it (confirmed miss).
- ``None`` — nothing editable readable / text too short (cannot tell).
+ ``False`` — a FOCUSED editable field is readable and no editable holds
+ the text (confirmed miss: we positively looked at the surface
+ that would have received the input).
+ ``None`` — nothing editable readable, text too short, or editables are
+ readable but NONE holds focus — then the enumeration likely
+ covered the WRONG surface (a start-menu/UWP flyout outside
+ the foreground tree, live incident 2026-07-02 18:00) and a
+ confident ``False`` would stall the mission on a lie.
"""
t = normalize_for_value_match(typed)
if len(t) < TYPE_VERIFY_MIN_CHARS:
return None
- editable_seen = False
+ focused_editable_seen = False
for node in nodes or ():
if getattr(node, "role", "") not in EDITABLE_UIA_ROLES:
continue
- editable_seen = True
+ if getattr(node, "focused", False):
+ focused_editable_seen = True
val = normalize_for_value_match(getattr(node, "value", "") or "")
if t in val:
return True
- return False if editable_seen else None
+ return False if focused_editable_seen else None
+
+
+def click_point_in_focused_element(
+ nodes: tuple, x: int, y: int,
+) -> bool | None:
+ """Did the click point land inside the element HOLDING keyboard focus?
+
+ The rescue evidence for the "click produced no visible change" false
+ miss: clicking a control that is ALREADY in the desired state (e.g. an
+ address bar that is focused by default on a new tab) changes zero
+ pixels, so the pixel effect-check alone fails the click, truncates the
+ batched type behind it, and stalls the mission right at its goal (live
+ incident 2026-07-02 19:06, Chrome guest new-tab). Focus + containment
+ from the accessibility tree proves the click hit its target even though
+ nothing visibly changed. Works on all three platforms (UIA / AX /
+ AT-SPI bounds are screen input units).
+
+ ``True`` — a focused element's bounds contain the point.
+ ``False`` — nodes are readable, no focused element contains the point.
+ ``None`` — no nodes readable (cannot tell).
+ """
+ if not nodes:
+ return None
+ for node in nodes:
+ if not getattr(node, "focused", False):
+ continue
+ bounds = getattr(node, "bounds", None)
+ if not bounds:
+ continue
+ try:
+ bx, by, bw, bh = (int(v) for v in bounds)
+ except (TypeError, ValueError):
+ continue
+ if bw > 0 and bh > 0 and bx <= x < bx + bw and by <= y < by + bh:
+ return True
+ return False
def element_is_focused(nodes: tuple, name: str) -> bool | None:
@@ -310,6 +353,23 @@ async def verify_click_focus(name: str) -> bool | None:
return element_is_focused(tuple(getattr(obs, "nodes", ()) or ()), name)
+async def verify_click_focus_point(x: int, y: int) -> bool | None:
+ """Fresh tree → :func:`click_point_in_focused_element`. Error → ``None``.
+
+ Runs ONLY on the click-miss path (no happy-path latency): the engine
+ consults it before declaring a zero-pixel-change click a miss.
+ """
+ try:
+ obs = await asyncio.wait_for(
+ _get_ui_tree_source().observe(), timeout=UIA_TIMEOUT_S,
+ )
+ except Exception: # noqa: BLE001
+ return None
+ return click_point_in_focused_element(
+ tuple(getattr(obs, "nodes", ()) or ()), int(x), int(y),
+ )
+
+
# ---------------------------------------------------------------------------
# Pixel-effect primitives
# ---------------------------------------------------------------------------
diff --git a/tests/unit/cu/test_conventions_ledger_verify.py b/tests/unit/cu/test_conventions_ledger_verify.py
index 75e98becd7..61d61a5a84 100644
--- a/tests/unit/cu/test_conventions_ledger_verify.py
+++ b/tests/unit/cu/test_conventions_ledger_verify.py
@@ -9,6 +9,7 @@ import pytest
from jarvis.cu import conventions as conv
from jarvis.cu.ledger import ActionLedger, action_key
from jarvis.cu.verify import (
+ click_point_in_focused_element,
clickable_labels,
crop_raw,
element_is_focused,
@@ -18,7 +19,6 @@ from jarvis.cu.verify import (
typed_text_landed,
)
-
# ---------------------------------------------------------------------------
# Coordinate convention resolution
# ---------------------------------------------------------------------------
@@ -177,19 +177,43 @@ def _node(**kw):
def test_typed_text_landed_tristate():
+ # A value match is positive evidence regardless of focus.
nodes = (_node(value="https://example.com"),)
assert typed_text_landed(nodes, "example.com") is True
- assert typed_text_landed(nodes, "other.org") is False
assert typed_text_landed((), "example.com") is None # nothing editable
assert typed_text_landed(nodes, "ab") is None # too short
+def test_typed_text_landed_false_needs_focused_editable_evidence():
+ # A confirmed MISS requires having looked at the RECEIVING surface: a
+ # focused editable that does not hold the text. Editables without focus
+ # mean the enumeration covered the wrong surface (start-menu flyout,
+ # live incident 2026-07-02 18:00) — that is "cannot tell", never False.
+ unfocused = (_node(value="something else"),)
+ assert typed_text_landed(unfocused, "spotify") is None
+ focused = (_node(value="something else", focused=True),)
+ assert typed_text_landed(focused, "spotify") is False
+
+
def test_element_is_focused_positive_only():
nodes = (_node(role="Button", name="Save", focused=True),)
assert element_is_focused(nodes, "Save") is True
assert element_is_focused(nodes, "Cancel") is None # never False
+def test_click_point_in_focused_element_tristate():
+ focused_bar = _node(role="Edit", name="Address",
+ focused=True, bounds=(100, 40, 800, 36))
+ other = _node(role="Button", name="Go", bounds=(950, 40, 60, 36))
+ nodes = (other, focused_bar)
+ assert click_point_in_focused_element(nodes, 400, 58) is True
+ assert click_point_in_focused_element(nodes, 970, 58) is False
+ assert click_point_in_focused_element((), 400, 58) is None
+ # Broken bounds never crash and never count as a hit.
+ broken = (_node(focused=True, bounds=None),)
+ assert click_point_in_focused_element(broken, 400, 58) is False
+
+
def test_field_values_hint_lists_filled_fields_only():
nodes = (
_node(name="Address", value="https://example.com"),