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-07 16:31)

Ruben Lütke64c7f2bcebe1
diff --git a/jarvis/platform/window_state.py b/jarvis/platform/window_state.py
index 03cd2d4767..5a44086e4e 100644
--- a/jarvis/platform/window_state.py
+++ b/jarvis/platform/window_state.py
@@ -291,6 +291,8 @@ def _find_and_focus_macos(title_contains: str) -> tuple[bool, str]:
["osascript", "-e", script],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -327,6 +329,8 @@ def _list_windows_macos() -> list[WindowInfo]:
["osascript", "-e", script],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -356,6 +360,8 @@ def _foreground_title_macos() -> str:
["osascript", "-e", script],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -384,6 +390,8 @@ def _find_and_focus_linux(title_contains: str) -> tuple[bool, str]:
["wmctrl", "-l"],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -407,6 +415,8 @@ def _find_and_focus_linux(title_contains: str) -> tuple[bool, str]:
["wmctrl", "-i", "-a", win_id],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -423,6 +433,8 @@ def _list_windows_linux() -> list[WindowInfo]:
["wmctrl", "-l"],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -444,6 +456,8 @@ def _foreground_title_linux() -> str:
["xdotool", "getactivewindow", "getwindowname"],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -767,6 +781,8 @@ def _foreground_window_linux() -> WindowInfo | None:
["xdotool", "getactivewindow"],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -782,6 +798,8 @@ def _foreground_window_linux() -> WindowInfo | None:
["xdotool", "getwindowname", str(win_id)],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -1017,6 +1035,8 @@ def _window_frame_rect_linux(win: WindowInfo) -> tuple[int, int, int, int] | Non
["xdotool", "getwindowgeometry", "--shell", str(int(win.handle))],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
@@ -1111,7 +1131,9 @@ def maximize_window(win: WindowInfo) -> tuple[bool, str]:
)
proc = subprocess.run(
["osascript", "-e", script],
- capture_output=True, text=True, timeout=10,
+ capture_output=True, text=True,
+ encoding="utf-8", errors="replace",
+ timeout=10,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
if proc.returncode != 0:
diff --git a/tests/unit/platform/test_window_state.py b/tests/unit/platform/test_window_state.py
index 6c9a38dc0d..7bdfde93d4 100644
--- a/tests/unit/platform/test_window_state.py
+++ b/tests/unit/platform/test_window_state.py
@@ -162,6 +162,42 @@ def test_list_windows_macos_parses_osascript(monkeypatch):
assert "Safari — Apple" in titles
+def test_list_windows_linux_decodes_non_utf8_locale_titles(monkeypatch):
+ # AP-23 wave-2 finding 8: wmctrl output is parsed with text=True; without a
+ # pinned encoding="utf-8", errors="replace", a title byte sequence that the
+ # ambient locale can't decode raises UnicodeDecodeError instead of just
+ # degrading the one unparsable character. The fake below mimics that
+ # contract: it only returns cleanly when both kwargs are set exactly as the
+ # fix requires, so this test is RED on the pre-fix code and GREEN after.
+ monkeypatch.setattr(ws, "detect_platform", lambda: "linux")
+ monkeypatch.setattr(ws, "is_wayland", lambda: False)
+ monkeypatch.setattr(ws, "display_present", lambda: True)
+ monkeypatch.setattr("shutil.which", lambda n: f"/usr/bin/{n}")
+
+ def _fake_run(*args, **kwargs):
+ if kwargs.get("encoding") != "utf-8" or kwargs.get("errors") != "replace":
+ raise UnicodeDecodeError("cp1252", b"\xff\xfe", 0, 1, "invalid byte")
+ return _cp(0, stdout="0x01 0 host café — 日本語.txt\n")
+
+ monkeypatch.setattr(subprocess, "run", _fake_run)
+ titles = [w.title for w in ws.list_windows()]
+ assert any("café" in t for t in titles)
+
+
+def test_list_windows_macos_decodes_non_utf8_locale_titles(monkeypatch):
+ monkeypatch.setattr(ws, "detect_platform", lambda: "darwin")
+ monkeypatch.setattr("shutil.which", lambda n: f"/usr/bin/{n}")
+
+ def _fake_run(*args, **kwargs):
+ if kwargs.get("encoding") != "utf-8" or kwargs.get("errors") != "replace":
+ raise UnicodeDecodeError("cp1252", b"\xff\xfe", 0, 1, "invalid byte")
+ return _cp(0, stdout="Safäri — 日本語\n")
+
+ monkeypatch.setattr(subprocess, "run", _fake_run)
+ titles = [w.title for w in ws.list_windows()]
+ assert any("Safäri" in t for t in titles)
+
+
def test_list_windows_headless_linux_is_empty(monkeypatch):
monkeypatch.setattr(ws, "detect_platform", lambda: "linux")
monkeypatch.setattr(ws, "is_wayland", lambda: False)
@@ -198,6 +234,36 @@ def test_get_foreground_title_macos_empty_without_tool(monkeypatch):
assert ws.get_foreground_title() == ""
+def test_get_foreground_title_macos_decodes_non_utf8_locale_title(monkeypatch):
+ # Same finding-8 contract as the list_windows tests above, for the
+ # single-title foreground read path.
+ monkeypatch.setattr(ws, "detect_platform", lambda: "darwin")
+ monkeypatch.setattr("shutil.which", lambda n: f"/usr/bin/{n}")
+
+ def _fake_run(*args, **kwargs):
+ if kwargs.get("encoding") != "utf-8" or kwargs.get("errors") != "replace":
+ raise UnicodeDecodeError("cp1252", b"\xff\xfe", 0, 1, "invalid byte")
+ return _cp(0, stdout="Übersicht — Müller.txt")
+
+ monkeypatch.setattr(subprocess, "run", _fake_run)
+ assert ws.get_foreground_title() == "Übersicht — Müller.txt"
+
+
+def test_get_foreground_title_linux_decodes_non_utf8_locale_title(monkeypatch):
+ monkeypatch.setattr(ws, "detect_platform", lambda: "linux")
+ monkeypatch.setattr(ws, "is_wayland", lambda: False)
+ monkeypatch.setattr(ws, "display_present", lambda: True)
+ monkeypatch.setattr("shutil.which", lambda n: f"/usr/bin/{n}")
+
+ def _fake_run(*args, **kwargs):
+ if kwargs.get("encoding") != "utf-8" or kwargs.get("errors") != "replace":
+ raise UnicodeDecodeError("cp1252", b"\xff\xfe", 0, 1, "invalid byte")
+ return _cp(0, stdout="Übersicht — Müller.txt")
+
+ monkeypatch.setattr(subprocess, "run", _fake_run)
+ assert ws.get_foreground_title() == "Übersicht — Müller.txt"
+
+
# --- raise_window (raise a known window via the hardened path) ---------------