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 10:06)

Ruben Lütke8a86d383a848
diff --git a/jarvis/cu/engine.py b/jarvis/cu/engine.py
index 713b33fbb9..d831bf4cb6 100644
--- a/jarvis/cu/engine.py
+++ b/jarvis/cu/engine.py
@@ -48,7 +48,13 @@ from jarvis.cu.brain_call import (
CUNoVisionProviderError,
call_vision_brain,
)
-from jarvis.cu.capture import Frame, capture_stable_frame, grab_region, select_monitor
+from jarvis.cu.capture import (
+ Frame,
+ capture_stable_frame,
+ grab_region,
+ select_monitor,
+ thumbs_similar,
+)
from jarvis.cu.geometry import CoordinateConvention, MonitorInfo
from jarvis.cu.ledger import ActionLedger
from jarvis.cu.verify import (
@@ -425,7 +431,7 @@ async def run_cu_loop(
done_rejects = 0
guard_hits = 0
observe_failures = 0
- prev_sha: str | None = None
+ prev_thumb: bytes | None = None
fruitless_steps = 0 # steps with zero successful actions on an unchanged screen
last_step_had_success = False
@@ -484,14 +490,14 @@ async def run_cu_loop(
# successful action while the screen never changed means we are
# circling — judge once (the goal may in fact be met), then stop.
if (
- prev_sha is not None
- and frame.phash == prev_sha
+ prev_thumb is not None
+ and thumbs_similar(prev_thumb, frame.thumb)
and not last_step_had_success
):
fruitless_steps += 1
else:
fruitless_steps = 0
- prev_sha = frame.phash
+ prev_thumb = frame.thumb
last_step_had_success = False
if fruitless_steps >= _STUCK_FRAMES:
done, proof = await _judge_done(
@@ -692,7 +698,7 @@ async def run_cu_loop(
action = {**action, "x": sx, "y": sy}
# -- idempotency ledger -----------------------------------------
- if ledger.is_duplicate(action, frame.phash, resolved_xy=resolved_xy):
+ if ledger.is_duplicate(action, frame.thumb, resolved_xy=resolved_xy):
guard_hits += 1
history.append(
f"step {step_idx}: {_summarize_action(action)} REFUSED — "
@@ -729,7 +735,7 @@ async def run_cu_loop(
profiler.add("act", t0, step_idx)
t0 = time.monotonic()
if ok:
- ledger.record(action, frame.phash, resolved_xy=resolved_xy)
+ ledger.record(action, frame.thumb, resolved_xy=resolved_xy)
await asyncio.sleep(_EFFECT_SETTLE_S * settle_scale)
post = await asyncio.to_thread(grab_region, monitor.bbox)
rect = monitor.bbox
@@ -767,7 +773,7 @@ async def run_cu_loop(
profiler.add("act", t0, step_idx)
t0 = time.monotonic()
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
if strict_verify:
landed = await verify_typed_text(action["text"])
if landed is False:
@@ -790,7 +796,7 @@ async def run_cu_loop(
ctx, "hotkey", {"keys": action["keys"]}, trace_id,
)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
profiler.add("act", t0, step_idx)
elif kind == "scroll":
@@ -802,7 +808,7 @@ async def run_cu_loop(
args["x"], args["y"] = int(action["x"]), int(action["y"])
ok, detail = await _dispatch_tool(ctx, "scroll", args, trace_id)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
profiler.add("act", t0, step_idx)
elif kind == "drag":
@@ -821,7 +827,7 @@ async def run_cu_loop(
trace_id,
)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
profiler.add("act", t0, step_idx)
elif kind == "open_app":
@@ -829,7 +835,7 @@ async def run_cu_loop(
ctx, "open_app", {"app_name": action["name"]}, trace_id,
)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
# Let the app paint its first window; the next perception's
# stability probe covers the rest.
await asyncio.sleep(1.0 * settle_scale)
@@ -841,7 +847,7 @@ async def run_cu_loop(
trace_id,
)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
profiler.add("act", t0, step_idx)
elif kind == "click_element":
@@ -850,7 +856,7 @@ async def run_cu_loop(
ctx, "click_element", {"name": action["name"]}, trace_id,
)
if ok:
- ledger.record(action, frame.phash)
+ ledger.record(action, frame.thumb)
profiler.add("act", t0, step_idx)
elif kind == "wait":
diff --git a/jarvis/cu/ledger.py b/jarvis/cu/ledger.py
index fb6ee62e39..602b82b490 100644
--- a/jarvis/cu/ledger.py
+++ b/jarvis/cu/ledger.py
@@ -68,15 +68,21 @@ def action_key(action: dict[str, Any]) -> str | None:
@dataclass
class ActionLedger:
- """Mission-scoped record of executed actions, keyed by frame hash."""
+ """Mission-scoped record of executed actions, keyed by frame identity.
- _entries: list[tuple[str, str]] = field(default_factory=list)
- _clicks: list[tuple[str, int, int, str]] = field(default_factory=list)
+ ``frame_key`` is the frame's perceptual thumbnail (``Frame.thumb``);
+ identities are compared with :func:`thumbs_similar`, so a caret blink or
+ antialiasing noise between two captures does not re-legitimize a
+ duplicate. Opaque string keys (tests) compare by equality.
+ """
+
+ _entries: list[tuple[str, bytes | str]] = field(default_factory=list)
+ _clicks: list[tuple[str, int, int, bytes | str]] = field(default_factory=list)
def is_duplicate(
self,
action: dict[str, Any],
- frame_sha: str,
+ frame_key: bytes | str,
*,
resolved_xy: tuple[int, int] | None = None,
) -> bool:
@@ -88,17 +94,21 @@ class ActionLedger:
if action.get("action") == "click" and resolved_xy is not None:
x, y = resolved_xy
return any(
- k == key and sha == frame_sha
+ k == key
and abs(px - x) <= CLICK_SAME_TOLERANCE
and abs(py - y) <= CLICK_SAME_TOLERANCE
- for (k, px, py, sha) in self._clicks
+ and thumbs_similar(stored, frame_key)
+ for (k, px, py, stored) in self._clicks
)
- return (key, frame_sha) in self._entries
+ return any(
+ k == key and thumbs_similar(stored, frame_key)
+ for (k, stored) in self._entries
+ )
def record(
self,
action: dict[str, Any],
- frame_sha: str,
+ frame_key: bytes | str,
*,
resolved_xy: tuple[int, int] | None = None,
) -> None:
@@ -107,6 +117,6 @@ class ActionLedger:
if key is None:
return
if action.get("action") == "click" and resolved_xy is not None:
- self._clicks.append((key, resolved_xy[0], resolved_xy[1], frame_sha))
+ self._clicks.append((key, resolved_xy[0], resolved_xy[1], frame_key))
return
- self._entries.append((key, frame_sha))
+ self._entries.append((key, frame_key))
diff --git a/scripts/cu_rig_results_engine_v2.json b/scripts/cu_rig_results_engine_v2.json
index 868098d004..aedbebe9db 100644
--- a/scripts/cu_rig_results_engine_v2.json
+++ b/scripts/cu_rig_results_engine_v2.json
@@ -2,17 +2,17 @@
{
"scenario": "engine-click-targets",
"intended_clicks": 4,
- "received_first_hits": 4,
- "hit_rate": 1.0,
- "mean_distance_px": 0.0,
- "max_distance_px": 0.0,
+ "received_first_hits": 0,
+ "hit_rate": 0.0,
+ "mean_distance_px": null,
+ "max_distance_px": null,
"duplicate_clicks": 0,
- "step_latency_s_p50": 1.57,
- "step_latency_s_max": 1.57,
+ "step_latency_s_p50": 2.605,
+ "step_latency_s_max": 2.605,
"provoked_duplicates_executed": 0,
"engine": "v2",
- "mission_wall_s": 6.28,
- "final_chunk": "[cu] done (verified: all rig targets were activated)\n[cu] mission profile: steps=5 total=6.3s act=1.2s observe=2.6s think=0.0s verify=2.0s"
+ "mission_wall_s": 10.42,
+ "final_chunk": "[cu] fail at step-4: no progress \u2014 the screen has not changed despite my actions.\n[cu] mission profile: steps=4 total=10.4s act=1.7s observe=5.0s think=0.0s ver"
},
{
"scenario": "engine-type-once",
@@ -20,7 +20,7 @@
"typed_expected": "example.com",
"typed_received": "",
"typed_exactly_once": false,
- "mission_wall_s": 3.12
+ "mission_wall_s": 5.78
},
{
"scenario": "engine-duplicate-type-provocation",
@@ -29,14 +29,14 @@
"typed_received": "",
"duplicates_executed": 0,
"typed_exactly_once": false,
- "mission_wall_s": 4.72
+ "mission_wall_s": 8.24
},
{
"scenario": "engine-misaim-provocation",
"engine": "v2",
- "dead_space_clicks_executed": 3,
- "blind_repeats_after_first": 2,
- "mission_wall_s": 4.97,
- "final_chunk": "[cu] done (verified: all rig targets were activated)\n[cu] mission profile: steps=4 total=5.0s act=0.9s observe=2.0s think=0.0s verify=1.6s"
+ "dead_space_clicks_executed": 0,
+ "blind_repeats_after_first": 0,
+ "mission_wall_s": 5.25,
+ "final_chunk": "[cu] done (verified: all rig targets were activated)\n[cu] mission profile: steps=4 total=5.2s act=0.4s observe=3.3s think=0.0s verify=0.7s"
}
]
\ No newline at end of file
diff --git a/scripts/cu_test_rig.py b/scripts/cu_test_rig.py
index ba6ec09826..4d5b900084 100644
--- a/scripts/cu_test_rig.py
+++ b/scripts/cu_test_rig.py
@@ -236,6 +236,19 @@ def _capture_monitor(rig: RigWindow):
raise RuntimeError("no display detected")
+def _virtual_rect():
+ """The whole virtual desktop as a rect-like object. The ENGINE scenarios
+ run with [computer_use].monitor='all' so a human focusing another window
+ mid-measurement cannot flip the captured monitor under the mission
+ (observed live: foreground-follow made runs land on the wrong screen)."""
+ from jarvis.cu.geometry import list_monitors, virtual_screen_bounds
+
+ left, top, width, height = virtual_screen_bounds(list_monitors())
+ if width <= 0:
+ raise RuntimeError("no display detected")
+ return SimpleNamespace(left=left, top=top, width=width, height=height)
+
+
def _activate_rig(rig: RigWindow) -> None:
"""Bring the rig window to the FOREGROUND with a real activation click
on dead canvas space — the engines' capture follows the foreground
@@ -465,7 +478,7 @@ class LegacyVisionShim:
from jarvis.cu.capture import mss_grab, select_monitor
from PIL import Image
- monitor = await asyncio.to_thread(select_monitor, "foreground")
+ monitor = await asyncio.to_thread(select_monitor, "all")
(w, h), rgb = await asyncio.to_thread(mss_grab, monitor.bbox)
img = Image.frombytes("RGB", (w, h), rgb)
blob_dir = REPO_ROOT / "data" / "flight_recorder" / "blobs"
@@ -504,7 +517,7 @@ async def _run_engine_mission(
if engine == "v2":
ctx: Any = SimpleNamespace(
brain_manager=brain, tool_executor=executor, tools=tools,
- bus=None, step_budget=30, monitor="foreground",
+ bus=None, step_budget=30, monitor="all",
main_monitor="primary", settle_scale=1.0, strict_verify=True,
image_max_dimension=1366, coordinate_space="auto",
)
@@ -518,7 +531,7 @@ async def _run_engine_mission(
tool_executor=executor,
tools=tools,
bus=None,
- monitor="foreground",
+ monitor="all",
)
if engine == "stable":
from jarvis.harness.screenshot_only_loop_stable import run_cu_loop
@@ -539,7 +552,7 @@ async def _run_engine_mission(
def run_engine_mode(rig: RigWindow, engine: str) -> list[dict[str, Any]]:
_activate_rig(rig)
- monitor = _capture_monitor(rig)
+ monitor = _virtual_rect()
results: list[dict[str, Any]] = []
# -- scenario 1: click all four targets (accuracy + latency) ----------
diff --git a/tests/unit/cu/test_capture.py b/tests/unit/cu/test_capture.py
index 2ca63febd4..fe3a485a63 100644
--- a/tests/unit/cu/test_capture.py
+++ b/tests/unit/cu/test_capture.py
@@ -154,31 +154,34 @@ def test_blob_written_when_dir_given(tmp_path):
assert (tmp_path / f"{frame.sha256}.jpg").exists()
-def test_perceptual_hash_ignores_caret_noise_but_sees_real_change():
- from jarvis.cu.capture import perceptual_hash
+def test_thumb_identity_ignores_caret_noise_but_sees_real_change():
+ from jarvis.cu.capture import screen_thumb, thumbs_similar
base = _solid((192, 108), (30, 30, 30))
- # A tiny caret-sized change (2x12 slightly-brighter block).
+ # A caret-sized change: a small bright block on the dark frame.
pixels = bytearray(base[1])
for row in range(12):
for col in range(2):
idx = ((20 + row) * 192 + (50 + col)) * 3
- pixels[idx:idx + 3] = bytes((36, 36, 36))
+ pixels[idx:idx + 3] = b"\xff\xff\xff"
caret = ((192, 108), bytes(pixels))
changed = _solid((192, 108), (200, 200, 200))
- assert perceptual_hash(base) == perceptual_hash(base)
- assert perceptual_hash(base) == perceptual_hash(caret)
- assert perceptual_hash(base) != perceptual_hash(changed)
+ assert thumbs_similar(screen_thumb(base), screen_thumb(base))
+ assert thumbs_similar(screen_thumb(base), screen_thumb(caret))
+ assert not thumbs_similar(screen_thumb(base), screen_thumb(changed))
+ # Opaque string keys (tests / foreign callers) compare by equality.
+ assert thumbs_similar("sha1", "sha1")
+ assert not thumbs_similar("sha1", "sha2")
-def test_frame_carries_both_hashes():
+def test_frame_carries_exact_and_perceptual_identity():
frame = capture_stable_frame(
_monitor(),
grab=lambda bbox: _solid((192, 108), (1, 2, 3)),
sleep=lambda s: None,
)
- assert len(frame.sha256) == 64 and len(frame.phash) == 64
- assert frame.sha256 != frame.phash
+ assert len(frame.sha256) == 64
+ assert len(frame.thumb) == 96 * 54
def test_grab_region_swallows_failures():