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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
chore: auto-save WIP via Claude stop-hook safety net (2026-07-08 07:48)
Ruben Lütke255d7cc83bc3
diff --git a/jarvis/plugins/tts/__init__.py b/jarvis/plugins/tts/__init__.pyindex fd1565b14b..7b0589c522 100644--- a/jarvis/plugins/tts/__init__.py+++ b/jarvis/plugins/tts/__init__.py@@ -187,6 +187,48 @@ def _resolve_keyed_tts_provider(primary_name: str, tts_cfg: Any) -> tuple[str, Areturn primary_name, tts_cfg+def resolve_keyed_fallback(+ exclude_family: str,+ *,+ allow_sapi5: bool = False,+ language_code: str | None = None,+) -> Any | None:+ """Build the first cross-family TTS provider (≠ ``exclude_family``) that has+ a usable key on this host — so a plugin's INTERNAL runtime fallback never+ lands on a keyless (mute) provider (AP-22).++ The old plugins hardcoded ``GeminiFlashTTS`` as their stage-1 fallback, so a+ user whose ONLY key is Cartesia/ElevenLabs/Grok fell, on a mid-session+ quota/outage, onto a keyless Gemini → silence. This resolves the fallback+ through the SAME key-aware cross-family order the factory uses (native+ premium first, OpenRouter last), skipping the failed family and any keyless+ one. Returns a built provider, or ``None`` when NO other family has a key+ (the caller then degrades to the opt-in SAPI5 exit or an honest mute).+ """+ from jarvis.core.config import TTSConfig++ exclude = _canonical_tts_name(exclude_family)+ for cand in _TTS_CROSS_FAMILY_ORDER:+ if cand == exclude:+ continue+ cfg_view = TTSConfig(+ provider=cand,+ language_code=language_code or "auto",+ allow_sapi5_fallback=allow_sapi5,+ )+ if not _tts_has_credential(cand, cfg_view):+ continue+ try:+ return _build_provider(cfg_view, cand)+ except Exception as exc: # noqa: BLE001 — a bad candidate must not abort the chain+ log.warning(+ "Keyed fallback candidate %r not buildable (%s) — trying next.",+ cand, exc.__class__.__name__,+ )+ continue+ return None++def _resolve_voice_for_provider(requested: str, provider: str, default: str, allowed: frozenset[str]) -> str:diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex ac19a506d7..d515b2f92d 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -343,6 +343,93 @@ def _bring_window_to_front_by_title(title: str) -> bool:return False+# ---------------------------------------------------------------------------+# Accidental-console suppression (Windows)+# ---------------------------------------------------------------------------+++def _console_owned_exclusively(console_hwnd: int, attached_process_count: int) -> bool:+ """Pure decision: should we hide this console window?++ Hide it ONLY when a console window exists (``console_hwnd`` is non-zero) and+ this process is the *sole* process attached to it+ (``attached_process_count == 1``).++ A sole-owner console was allocated *for this app*: a scheduled task, an+ Explorer double-click, or a shortcut whose target resolved to the+ console-subsystem ``python.exe`` instead of the windowless ``pythonw.exe``.+ That is the black terminal that fills with loguru's stderr output and+ confuses users (forensic 2026-07-08: a test laptop's autostart launched+ ``python.exe``).++ A console shared with another process (count >= 2) belongs to the *user* — a+ developer who ran us from their terminal, or ``run.bat --debug`` where+ ``cmd.exe`` stays attached — and must never be hidden.+ """+ return bool(console_hwnd) and attached_process_count == 1+++def _win32_get_console_window() -> int:+ import ctypes++ return int(ctypes.windll.kernel32.GetConsoleWindow())+++def _win32_count_attached_processes() -> int:+ import ctypes++ # GetConsoleProcessList fills the buffer with the attached PIDs and returns+ # their TOTAL count (even when it exceeds the buffer), so a small fixed+ # buffer is enough to answer "is it just us?".+ buf = (ctypes.c_uint * 8)()+ return int(ctypes.windll.kernel32.GetConsoleProcessList(buf, 8))+++def _win32_hide_window(hwnd: int) -> None:+ import ctypes++ SW_HIDE = 0+ ctypes.windll.user32.ShowWindow(hwnd, SW_HIDE)+++def hide_accidental_console(+ *,+ _get_console_window: Callable[[], int] | None = None,+ _count_attached_processes: Callable[[], int] | None = None,+ _hide_window: Callable[[int], None] | None = None,+) -> bool:+ """Hide a console window this GUI app accidentally, exclusively owns.++ Returns ``True`` iff a console was hidden. Windows-only; a clean no-op on+ macOS/Linux (no console-subsystem split exists there — a GUI app launched+ from Finder/dock has no controlling terminal, and one launched from a real+ terminal is *meant* to log there) and whenever the app already runs+ windowless under ``pythonw.exe`` (``GetConsoleWindow`` returns 0).++ ``SW_HIDE`` (not ``FreeConsole``) is deliberate: it hides the window while+ keeping ``stdout``/``stderr`` valid, so nothing that later writes to them+ raises. The rotating file sink (``jarvis_desktop.log``) keeps every log line+ regardless. The win32 probes are injectable so the orchestration is+ unit-testable off-Windows.+ """+ if sys.platform != "win32":+ return False+ try:+ get_console_window = _get_console_window or _win32_get_console_window+ count_attached = _count_attached_processes or _win32_count_attached_processes+ hide_window = _hide_window or _win32_hide_window++ hwnd = get_console_window()+ if not hwnd:+ return False # pythonw / no console — nothing to hide+ if not _console_owned_exclusively(hwnd, count_attached()):+ return False # a shell shares it (dev terminal / --debug) — leave it+ hide_window(hwnd)+ return True+ except Exception: # noqa: BLE001 — console cosmetics must never break boot+ return False++def _is_brain_diagnostic(text: str) -> bool:"""True for backend diagnostics that don't count as a Jarvis reply."""t = text.lower()@@ -2789,6 +2876,23 @@ class DesktopApp:def run_window_only(self) -> int:"""The main-thread pywebview window. Assumes the backend thread isalready running (started by :meth:`run` or the fast-boot launcher)."""+ # Hide an *accidental* console. When the app is launched by the+ # console-subsystem ``python.exe`` (a scheduled task / shortcut / double+ # click that resolved to python.exe instead of the windowless+ # pythonw.exe), Windows hands us a black terminal that fills with+ # loguru's stderr output and confuses users. If we EXCLUSIVELY own that+ # console we hide it here — the sole-owner check leaves a developer's own+ # terminal and ``run.bat --debug`` (cmd.exe still attached) visible.+ # This is the single chokepoint every window path (classic + fast-boot)+ # funnels through, so it fixes every launch path at once. No-op under+ # pythonw and on macOS/Linux.+ if hide_accidental_console():+ from loguru import logger as _console_logger++ _console_logger.debug(+ "Hid an accidentally-attached console window (the app was "+ "launched via python.exe instead of pythonw.exe)."+ )# Claim PER_MONITOR_AWARE before pywebview can downgrade the process to# SYSTEM-aware (webview.start does at runtime) — the downgrade# virtualizes window rects on mixed-DPI monitors and made Computer-Usediff --git a/tests/unit/ui/test_desktop_console_hide.py b/tests/unit/ui/test_desktop_console_hide.pynew file mode 100644index 0000000000..2b5870a19a--- /dev/null+++ b/tests/unit/ui/test_desktop_console_hide.py@@ -0,0 +1,130 @@+"""Accidental-console suppression for the desktop window.++When the desktop app is launched by the console-subsystem ``python.exe`` (a+scheduled task / shortcut / double-click that resolved to ``python.exe`` instead+of the windowless ``pythonw.exe``), Windows hands it a black terminal that fills+with loguru's stderr output and confuses users (forensic 2026-07-08: a test+laptop's autostart launched ``python.exe``). ``run_window_only`` hides that+console — but ONLY when the app exclusively owns it, so a developer's own+terminal and ``run.bat --debug`` (where ``cmd.exe`` stays attached) are left+visible.++These tests pin the pure decision (the sole-owner rule) and the orchestration+(probe → decide → hide) without needing a real Windows console — the win32+probes are injectable.+"""+from __future__ import annotations++from jarvis.ui import desktop_app+from jarvis.ui.desktop_app import _console_owned_exclusively, hide_accidental_console+++# --- the pure sole-owner decision (cross-platform) -------------------------+++def test_sole_owner_console_is_hidden() -> None:+ # A real console window (non-zero HWND) attached to exactly one process —+ # us — was allocated for this app alone → hide it.+ assert _console_owned_exclusively(console_hwnd=4242, attached_process_count=1) is True+++def test_shared_console_is_left_alone() -> None:+ # A shell (cmd.exe / powershell) or run.bat --debug shares the console →+ # it belongs to the user → never hide it.+ assert _console_owned_exclusively(console_hwnd=4242, attached_process_count=2) is False+++def test_no_console_window_is_a_noop() -> None:+ # pythonw.exe / genuinely windowless: GetConsoleWindow() == 0 → nothing to do.+ assert _console_owned_exclusively(console_hwnd=0, attached_process_count=1) is False+++# --- the orchestration, with injected win32 probes -------------------------+++def _force_win32(monkeypatch) -> None:+ """Make ``hide_accidental_console`` take the Windows branch off-Windows.++ Only the injected probes are exercised — no ``ctypes.windll`` is ever+ touched, so this is safe on the Linux CI runner too.+ """+ monkeypatch.setattr(desktop_app.sys, "platform", "win32")+++def test_hides_console_when_sole_owner(monkeypatch) -> None:+ _force_win32(monkeypatch)+ hidden: list[int] = []++ result = hide_accidental_console(+ _get_console_window=lambda: 777,+ _count_attached_processes=lambda: 1,+ _hide_window=hidden.append,+ )++ assert result is True+ assert hidden == [777] # the exact HWND was hidden+++def test_does_not_hide_a_shared_console(monkeypatch) -> None:+ _force_win32(monkeypatch)+ hidden: list[int] = []++ result = hide_accidental_console(+ _get_console_window=lambda: 777,+ _count_attached_processes=lambda: 3, # a shell shares it+ _hide_window=hidden.append,+ )++ assert result is False+ assert hidden == []+++def test_does_not_probe_process_count_without_a_console(monkeypatch) -> None:+ _force_win32(monkeypatch)+ hidden: list[int] = []+ counted: list[bool] = []++ def _count() -> int:+ counted.append(True)+ return 1++ result = hide_accidental_console(+ _get_console_window=lambda: 0, # no console at all+ _count_attached_processes=_count,+ _hide_window=hidden.append,+ )++ assert result is False+ assert hidden == []+ assert counted == [] # short-circuits before probing the process list+++def test_noop_on_non_windows(monkeypatch) -> None:+ monkeypatch.setattr(desktop_app.sys, "platform", "linux")+ hidden: list[int] = []++ result = hide_accidental_console(+ _get_console_window=lambda: 777,+ _count_attached_processes=lambda: 1,+ _hide_window=hidden.append,+ )++ assert result is False+ assert hidden == [] # never touches the window on macOS/Linux+++def test_probe_failure_never_raises(monkeypatch) -> None:+ _force_win32(monkeypatch)++ def _boom() -> int:+ raise OSError("console probe blew up")++ # A failing probe must degrade to "did nothing", never crash the window boot.+ assert (+ hide_accidental_console(+ _get_console_window=_boom,+ _count_attached_processes=lambda: 1,+ _hide_window=lambda _hwnd: None,+ )+ is False+ )