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 17:32)

Ruben Lütkecab0f5674fff
diff --git a/jarvis/brain/factory.py b/jarvis/brain/factory.py
index bf28135b7f..58a8390a25 100644
--- a/jarvis/brain/factory.py
+++ b/jarvis/brain/factory.py
@@ -1113,6 +1113,8 @@ def _phase2_full_brain(
monitor=getattr(cu_cfg, "monitor", "primary"),
main_monitor=getattr(cu_cfg, "main_monitor", "primary"),
coordinate_space=getattr(cu_cfg, "coordinate_space", "auto"),
+ capture_scope=getattr(cu_cfg, "capture_scope", "window"),
+ normalize_window=getattr(cu_cfg, "normalize_window", True),
))
# Hot-reload: refresh the live context's step_budget / timeout /
# replan knobs on ConfigReloaded so a voice-tunable change
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index 13a0b26a39..4a207fd8a0 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -1479,6 +1479,21 @@ class ComputerUseConfig(BaseModel):
# or an explicit id (a monitor-name substring, or a 1-based index "1"/"2").
# An unknown id falls back to the OS primary (never a silent wrong screen).
main_monitor: str = "primary"
+ # CU v2: what the vision model SEES and acts on. "window" (default) crops
+ # every capture to the foreground TARGET WINDOW — the industry-standard
+ # framing for pixel-grounded GUI agents (OpenAI CUA: fixed viewport;
+ # Anthropic reference: one small display the app fills; Microsoft UFO:
+ # per-application screenshots). It also structurally prevents clicks from
+ # landing outside the app: coordinates are clamped into the capture rect.
+ # "monitor" restores the previous whole-monitor framing (rollback knob).
+ capture_scope: Literal["window", "monitor"] = "window"
+ # CU v2: maximize the target window on ITS OWN monitor before acting (and
+ # again after each open_app/switch_window). A small floating window on a
+ # large screen shrinks to stamp size in the model's downscaled frame —
+ # grounding errors then click the wallpaper next to it (live incident
+ # 2026-07-02). Never moves a window across monitors (mixed-DPI resize
+ # trap); fixed-size dialogs and the desktop shell are left untouched.
+ normalize_window: bool = True
# Master switch for the per-action read-back verification suite (claude-in-
# chrome parity): after a type, confirm the text landed in the field; after a
# click_element, confirm the intended state changed; don't blind-batch a
diff --git a/jarvis/harness/computer_use_context.py b/jarvis/harness/computer_use_context.py
index b528da0d04..cc2f10c616 100644
--- a/jarvis/harness/computer_use_context.py
+++ b/jarvis/harness/computer_use_context.py
@@ -81,6 +81,14 @@ class ComputerUseContext:
# "image_pixels". "auto" resolves per provider (capability first, family
# metadata second) — see jarvis/cu/conventions.py.
coordinate_space: str = "auto"
+ # CU v2: capture framing ([computer_use].capture_scope): "window" (default)
+ # crops every capture to the foreground target window; "monitor" restores
+ # the whole-monitor framing. See jarvis/cu/capture.py::select_capture_target.
+ capture_scope: str = "window"
+ # CU v2: maximize the target window on its own monitor before acting
+ # ([computer_use].normalize_window). See
+ # jarvis/platform/window_state.py::normalize_foreground_window.
+ normalize_window: bool = True
_CONTEXT: ComputerUseContext | None = None
@@ -231,6 +239,8 @@ _RELOADABLE_FIELDS: tuple[str, ...] = (
"zoom_before_click",
"uia_click_fallback",
"announce_progress",
+ "capture_scope",
+ "normalize_window",
)
_subscribed_bus_id: int | None = None
diff --git a/scripts/config-soll.json b/scripts/config-soll.json
index 49fdef3601..8800155a20 100644
--- a/scripts/config-soll.json
+++ b/scripts/config-soll.json
@@ -8,8 +8,8 @@
"tts": {
"provider": "grok-voice",
"fallback": "grok-voice",
- "voice_de": "leo",
- "voice_en": "leo",
+ "voice_de": "Kore",
+ "voice_en": "Kore",
"language_code": "auto",
"chunk_by_sentence": false,
"seed": 7,
@@ -18,7 +18,7 @@
"vertex_project": "",
"vertex_location": "us-central1",
"service_account_path": "~/.config/jarvis/vertex-sa.json",
- "model": "eleven_flash_v2_5"
+ "model": "sonic-2"
},
"tts.cartesia": {
"model_id": "sonic-3.5",
diff --git a/tests/unit/cu/test_capture_target.py b/tests/unit/cu/test_capture_target.py
new file mode 100644
index 0000000000..745e3b1561
--- /dev/null
+++ b/tests/unit/cu/test_capture_target.py
@@ -0,0 +1,171 @@
+"""Window-scoped capture target tests (no real display needed).
+
+Guards the fix for the 2026-07-02 multi-monitor incident: a restored Chrome
+floating on a 4K secondary monitor turned stamp-sized in the model's frame,
+every grounding miss clicked the wallpaper next to it and stole the window's
+focus. ``select_capture_target`` crops the capture to the foreground window
+(industry framing: OpenAI CUA fixed viewport / Anthropic single small display
+/ Microsoft UFO per-application screenshots), which also structurally clamps
+every mapped click into the window rect.
+"""
+from __future__ import annotations
+
+import pytest
+
+from jarvis.cu import capture as capture_mod
+from jarvis.cu.capture import select_capture_target
+from jarvis.cu.geometry import MonitorInfo
+from jarvis.platform import window_state as ws
+from jarvis.platform.window_state import WindowInfo
+
+MONITOR = MonitorInfo(left=-3840, top=0, width=3840, height=2160, name="left-4k")
+
+
+def fake_monitor(monkeypatch: pytest.MonkeyPatch) -> MonitorInfo:
+ monkeypatch.setattr(
+ capture_mod, "select_monitor", lambda policy, main_monitor: MONITOR,
+ )
+ return MONITOR
+
+
+def _wire_window(
+ monkeypatch: pytest.MonkeyPatch,
+ *,
+ win: WindowInfo | None,
+ rect: tuple[int, int, int, int] | None,
+ shell: bool = False,
+) -> None:
+ monkeypatch.setattr(ws, "foreground_window", lambda: win)
+ monkeypatch.setattr(ws, "is_shell_window", lambda w: shell)
+ monkeypatch.setattr(ws, "window_frame_rect", lambda w: rect)
+
+
+def test_monitor_scope_keeps_previous_behaviour(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="App", handle=7),
+ rect=(-2000, 100, 800, 600))
+ got = select_capture_target("foreground", scope="monitor")
+ assert got == fake_monitor
+
+
+def test_policy_all_never_crops(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="App", handle=7),
+ rect=(-2000, 100, 800, 600))
+ got = select_capture_target("all", scope="window")
+ assert got == fake_monitor
+
+
+def test_window_scope_crops_to_foreground_window(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="Google Chrome", handle=7),
+ rect=(-2000, 100, 1890, 1040))
+ got = select_capture_target("foreground", scope="window")
+ assert (got.left, got.top, got.width, got.height) == (-2000, 100, 1890, 1040)
+ assert got.name.startswith("window:")
+
+
+def test_shell_window_falls_back_to_monitor(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="Program Manager", handle=7),
+ rect=(-3840, 0, 3840, 2160), shell=True)
+ assert select_capture_target("foreground", scope="window") == fake_monitor
+
+
+def test_no_foreground_window_falls_back(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=None, rect=None)
+ assert select_capture_target("foreground", scope="window") == fake_monitor
+
+
+def test_unreadable_rect_falls_back(fake_monitor, monkeypatch):
+ # macOS/Linux today: no per-window rect -> keep the monitor framing.
+ _wire_window(monkeypatch, win=WindowInfo(title="App"), rect=None)
+ assert select_capture_target("foreground", scope="window") == fake_monitor
+
+
+def test_tiny_window_falls_back(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="Tooltip", handle=7),
+ rect=(-1000, 500, 120, 80))
+ assert select_capture_target("foreground", scope="window") == fake_monitor
+
+
+def test_window_overhanging_monitor_edge_is_clamped(fake_monitor, monkeypatch):
+ # Window straddles the mixed-DPI boundary at x=0: the grab must never
+ # cross coordinate spaces, so it is clamped to the selected monitor.
+ _wire_window(monkeypatch, win=WindowInfo(title="App", handle=7),
+ rect=(-800, -50, 1600, 1200))
+ got = select_capture_target("foreground", scope="window")
+ assert (got.left, got.top) == (-800, 0)
+ assert got.left + got.width <= MONITOR.left + MONITOR.width
+ assert (got.width, got.height) == (800, 1150)
+
+
+def test_window_fully_outside_monitor_falls_back(fake_monitor, monkeypatch):
+ _wire_window(monkeypatch, win=WindowInfo(title="App", handle=7),
+ rect=(100, 100, 800, 600)) # on the primary, not the left 4k
+ assert select_capture_target("foreground", scope="window") == fake_monitor
+
+
+# ---------------------------------------------------------------------------
+# normalize_foreground_window decision logic
+# ---------------------------------------------------------------------------
+
+def _wire_normalize(
+ monkeypatch: pytest.MonkeyPatch,
+ *,
+ win: WindowInfo | None,
+ shell: bool = False,
+ maximized: bool | None = False,
+) -> list[WindowInfo]:
+ calls: list[WindowInfo] = []
+ monkeypatch.setattr(ws, "foreground_window", lambda: win)
+ monkeypatch.setattr(ws, "is_shell_window", lambda w: shell)
+ monkeypatch.setattr(ws, "window_is_maximized", lambda w: maximized)
+ monkeypatch.setattr(
+ ws, "maximize_window",
+ lambda w: (calls.append(w) or (True, "maximized")),
+ )
+ return calls
+
+
+def test_normalize_maximizes_a_restored_window(monkeypatch):
+ win = WindowInfo(title="Google Chrome", handle=7)
+ calls = _wire_normalize(monkeypatch, win=win, maximized=False)
+ ok, _ = ws.normalize_foreground_window()
+ assert ok is True
+ assert calls == [win]
+
+
+def test_normalize_leaves_maximized_window_alone(monkeypatch):
+ calls = _wire_normalize(
+ monkeypatch, win=WindowInfo(title="App", handle=7), maximized=True,
+ )
+ ok, _ = ws.normalize_foreground_window()
+ assert ok is False
+ assert calls == []
+
+
+def test_normalize_leaves_unknown_state_alone(monkeypatch):
+ # macOS/Linux today: maximized state unreadable (None) -> do not touch.
+ calls = _wire_normalize(
+ monkeypatch, win=WindowInfo(title="App"), maximized=None,
+ )
+ ok, _ = ws.normalize_foreground_window()
+ assert ok is False
+ assert calls == []
+
+
+def test_normalize_never_touches_the_shell(monkeypatch):
+ calls = _wire_normalize(
+ monkeypatch,
+ win=WindowInfo(title="Program Manager", handle=7),
+ shell=True,
+ maximized=False,
+ )
+ ok, _ = ws.normalize_foreground_window()
+ assert ok is False
+ assert calls == []
+
+
+def test_normalize_without_foreground_window(monkeypatch):
+ calls = _wire_normalize(monkeypatch, win=None)
+ ok, _ = ws.normalize_foreground_window()
+ assert ok is False
+ assert calls == []
diff --git a/tests/unit/cu/test_engine_loop.py b/tests/unit/cu/test_engine_loop.py
index 5fcff06ce1..4f928360fd 100644
--- a/tests/unit/cu/test_engine_loop.py
+++ b/tests/unit/cu/test_engine_loop.py
@@ -91,7 +91,9 @@ def patched(monkeypatch, tmp_path):
clicks_seen=0,
)
- def fake_select_monitor(policy, *, main_monitor="primary"):
+ def fake_select_capture_target(
+ policy, *, main_monitor="primary", scope="window",
+ ):
return MONITOR
def fake_capture(monitor, *, max_dimension, blob_dir=None, **kw):
@@ -117,12 +119,21 @@ def patched(monkeypatch, tmp_path):
async def fake_verify_typed(text):
return state.typed_lands
- monkeypatch.setattr(engine_mod, "select_monitor", fake_select_monitor)
+ monkeypatch.setattr(
+ engine_mod, "select_capture_target", fake_select_capture_target,
+ )
monkeypatch.setattr(engine_mod, "capture_stable_frame", fake_capture)
monkeypatch.setattr(engine_mod, "grab_region", fake_grab_region)
monkeypatch.setattr(engine_mod, "foreground_ui_snapshot", fake_snapshot)
monkeypatch.setattr(engine_mod, "verify_typed_text", fake_verify_typed)
monkeypatch.setattr(engine_mod, "_foreground_title", lambda: "Test Window")
+ # The engine normalizes the target window via jarvis.platform.window_state;
+ # tests must never maximize a real window on the dev machine.
+ from jarvis.platform import window_state as ws
+
+ monkeypatch.setattr(
+ ws, "normalize_foreground_window", lambda: (False, "test"),
+ )
return state