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:28)

Ruben Lütkee957d9c55059
diff --git a/jarvis/platform/monitors.py b/jarvis/platform/monitors.py
index 9e4c1d658d..13c71bc538 100644
--- a/jarvis/platform/monitors.py
+++ b/jarvis/platform/monitors.py
@@ -17,6 +17,8 @@ rather than silently picking a wrong screen.
"""
from __future__ import annotations
+import shutil
+import subprocess
import sys
from typing import Any
@@ -94,6 +96,98 @@ def resolve_primary_monitor(
return physical[0]
+def virtual_desktop_bounds() -> tuple[int, int, int, int] | None:
+ """Bounding box ``(left, top, width, height)`` over ALL monitors, in the
+ platform's input units — or ``None`` when it cannot be determined
+ (headless, Wayland, missing native API).
+
+ This is the correct scope for any "is this UI element on screen?"
+ filter: clipping such a filter to the PRIMARY monitor silently drops
+ every element of a window on a secondary monitor (2026-07-02 incident —
+ the whole accessibility tree of a Chrome window on the left monitor was
+ pruned away, so Computer-Use lost its clickable anchors, field hints and
+ focus evidence there). Never raises.
+ """
+ try:
+ if sys.platform == "win32":
+ return _win_virtual_bounds()
+ if sys.platform == "darwin":
+ return _macos_virtual_bounds()
+ from jarvis.platform.probes import is_wayland # noqa: PLC0415
+
+ if is_wayland():
+ return None
+ return _x11_virtual_bounds()
+ except Exception: # noqa: BLE001 — best-effort probe, callers keep a fallback
+ return None
+
+
+def _win_virtual_bounds() -> tuple[int, int, int, int] | None:
+ """SM_*VIRTUALSCREEN metrics (physical px once the process is declared
+ per-monitor DPI aware — the idempotent declaration runs first so an
+ unaware host process does not read virtualized 96-dpi values)."""
+ import ctypes # noqa: PLC0415
+
+ from jarvis.core.win32_dpi import ensure_dpi_awareness # noqa: PLC0415
+
+ ensure_dpi_awareness()
+ gsm = ctypes.windll.user32.GetSystemMetrics
+ # SM_XVIRTUALSCREEN=76, SM_YVIRTUALSCREEN=77, SM_CX=78, SM_CY=79
+ left, top, width, height = gsm(76), gsm(77), gsm(78), gsm(79)
+ if width <= 0 or height <= 0:
+ return None
+ return (int(left), int(top), int(width), int(height))
+
+
+def _macos_virtual_bounds() -> tuple[int, int, int, int] | None:
+ """Union over ``CGGetActiveDisplayList`` bounds (global points)."""
+ try:
+ from Quartz import ( # noqa: PLC0415
+ CGDisplayBounds,
+ CGGetActiveDisplayList,
+ )
+ except Exception: # noqa: BLE001 — pyobjc not installed
+ return None
+ err, display_ids, count = CGGetActiveDisplayList(16, None, None)
+ if err or not display_ids or not count:
+ return None
+ rects = [CGDisplayBounds(d) for d in list(display_ids)[:count]]
+ left = min(int(r.origin.x) for r in rects)
+ top = min(int(r.origin.y) for r in rects)
+ right = max(int(r.origin.x + r.size.width) for r in rects)
+ bottom = max(int(r.origin.y + r.size.height) for r in rects)
+ if right <= left or bottom <= top:
+ return None
+ return (left, top, right - left, bottom - top)
+
+
+def _x11_virtual_bounds() -> tuple[int, int, int, int] | None:
+ """X11 root-window geometry (the root spans all monitors)."""
+ if shutil.which("xdotool") is None:
+ return None
+ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS # noqa: PLC0415
+
+ proc = subprocess.run(
+ ["xdotool", "getdisplaygeometry"],
+ capture_output=True,
+ text=True,
+ timeout=3.0,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
+ if proc.returncode != 0:
+ return None
+ parts = (proc.stdout or "").split()
+ if len(parts) < 2:
+ return None
+ try:
+ width, height = int(parts[0]), int(parts[1])
+ except ValueError:
+ return None
+ if width <= 0 or height <= 0:
+ return None
+ return (0, 0, width, height)
+
+
def native_primary_origin() -> tuple[int, int] | None:
"""Best-effort virtual-desktop top-left ``(x, y)`` of the OS primary monitor,
or ``None`` when it cannot be determined (headless / Wayland / missing libs).
diff --git a/jarvis/vision/uia_tree.py b/jarvis/vision/uia_tree.py
index e06ef85b36..09b5d3eadb 100644
--- a/jarvis/vision/uia_tree.py
+++ b/jarvis/vision/uia_tree.py
@@ -78,9 +78,21 @@ class UIATreeSource:
if cancel_token is not None and cancel_token.is_cancelled():
raise RuntimeError(f"cancelled: {cancel_token.reason}")
- monitor_bounds = self._monitor_bounds or await asyncio.to_thread(
- self._detect_primary_monitor_bounds
- )
+ # On-screen filter scope: the WHOLE virtual desktop, never one
+ # monitor — a window on a secondary monitor must keep its tree
+ # (2026-07-02 incident). Falls back to the legacy primary-monitor
+ # rect only when the union cannot be determined.
+ monitor_bounds = self._monitor_bounds
+ if monitor_bounds is None:
+ from jarvis.platform import monitors as _monitors # noqa: PLC0415
+
+ monitor_bounds = await asyncio.to_thread(
+ _monitors.virtual_desktop_bounds,
+ )
+ if monitor_bounds is None:
+ monitor_bounds = await asyncio.to_thread(
+ self._detect_primary_monitor_bounds
+ )
# Retry ladder: on node overflow we shorten the depth.
nodes_before = 0
diff --git a/tests/unit/vision/test_screen_bounds_virtual_desktop.py b/tests/unit/vision/test_screen_bounds_virtual_desktop.py
new file mode 100644
index 0000000000..f8ffa2a696
--- /dev/null
+++ b/tests/unit/vision/test_screen_bounds_virtual_desktop.py
@@ -0,0 +1,102 @@
+"""The UI-tree on-screen filter must span the WHOLE virtual desktop.
+
+Root cause of the 2026-07-02 19:06 stall: every tree source clipped its
+on-screen overlap filter to the PRIMARY monitor (Windows: GetSystemMetrics
+0/1; macOS: CGMainDisplayID; Linux: a hardcoded 1920x1080), so a window on
+ANY secondary monitor lost its whole accessibility tree — no clickable
+anchors, no field hints, no focus evidence, and the click-verification had
+nothing to consult. The filter must use the union of ALL monitors
+(:func:`jarvis.platform.monitors.virtual_desktop_bounds`), resolved through
+the one platform seam on every OS.
+"""
+from __future__ import annotations
+
+import subprocess
+import sys
+import types
+
+from jarvis.platform import monitors as monitors_mod
+from jarvis.vision.pruning import RawNode
+from jarvis.vision.uia_tree import UIATreeSource
+
+# A window fully on the LEFT secondary monitor (negative X): the incident
+# geometry, nothing on the primary.
+_SECONDARY_WINDOW = [
+ RawNode(role="Window", name="Chrome (guest)",
+ bounds=(-2000, 100, 1600, 900), depth=0, parent_index=-1),
+ RawNode(role="Edit", name="Address and search bar",
+ bounds=(-1900, 140, 1200, 36), depth=1, parent_index=0,
+ focused=True),
+ RawNode(role="Button", name="Back",
+ bounds=(-1980, 140, 32, 32), depth=1, parent_index=0),
+]
+
+
+def _traverser(depth, window_title_filter=None):
+ return ("Chrome (guest)", 4242, list(_SECONDARY_WINDOW))
+
+
+async def test_uia_source_keeps_nodes_on_a_secondary_monitor(monkeypatch):
+ monkeypatch.setattr(
+ monitors_mod, "virtual_desktop_bounds",
+ lambda: (-2560, 0, 6400, 2160),
+ )
+ src = UIATreeSource(traverser=_traverser) # no injected bounds
+ obs = await src.observe()
+ roles = [(n.role, n.focused) for n in obs.nodes]
+ assert ("Edit", True) in roles, (
+ "the focused address bar on the secondary monitor must survive "
+ "the on-screen filter"
+ )
+ assert any(r == "Button" for r, _ in roles)
+
+
+async def test_uia_source_falls_back_when_virtual_bounds_unknown(monkeypatch):
+ # Headless probe: helper says None -> the source keeps its legacy
+ # primary-monitor fallback instead of crashing or filtering everything.
+ monkeypatch.setattr(
+ monitors_mod, "virtual_desktop_bounds", lambda: None,
+ )
+ src = UIATreeSource(traverser=_traverser)
+ obs = await src.observe()
+ assert obs is not None # never raises
+
+
+# ---------------------------------------------------------------------------
+# The shared platform helper
+# ---------------------------------------------------------------------------
+
+def test_x11_virtual_bounds_reads_root_geometry(monkeypatch):
+ def fake_run(cmd, **kwargs):
+ assert cmd[:2] == ["xdotool", "getdisplaygeometry"]
+ return subprocess.CompletedProcess(cmd, 0, stdout="6400 2160\n",
+ stderr="")
+
+ monkeypatch.setattr(monitors_mod.subprocess, "run", fake_run)
+ monkeypatch.setattr(monitors_mod.shutil, "which",
+ lambda n: f"/usr/bin/{n}")
+ assert monitors_mod._x11_virtual_bounds() == (0, 0, 6400, 2160)
+
+
+def test_x11_virtual_bounds_none_without_xdotool(monkeypatch):
+ monkeypatch.setattr(monitors_mod.shutil, "which", lambda n: None)
+ assert monitors_mod._x11_virtual_bounds() is None
+
+
+def test_macos_virtual_bounds_unions_all_displays(monkeypatch):
+ class _Rect:
+ def __init__(self, x, y, w, h):
+ self.origin = types.SimpleNamespace(x=x, y=y)
+ self.size = types.SimpleNamespace(width=w, height=h)
+
+ rects = {1: _Rect(0, 0, 3456, 2234), 2: _Rect(3456, -200, 1920, 1080)}
+ mod = types.ModuleType("Quartz")
+ mod.CGGetActiveDisplayList = lambda mx, a, b: (0, [1, 2], 2)
+ mod.CGDisplayBounds = lambda did: rects[did]
+ monkeypatch.setitem(sys.modules, "Quartz", mod)
+ assert monitors_mod._macos_virtual_bounds() == (0, -200, 5376, 2434)
+
+
+def test_virtual_desktop_bounds_never_raises_on_this_host():
+ bounds = monitors_mod.virtual_desktop_bounds()
+ assert bounds is None or (len(bounds) == 4 and bounds[2] > 0)