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
fix(overlay): switch between the bar, the pet and the orb looks live
rubenluetke10-beepe6e7fd59ae70
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 635a3af118..a6faa116cf 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -2527,6 +2527,17 @@ unifying both overlays under a SINGLE long-lived Tk root and swapping renderedcontent (canvas / widgets) instead of the root — a larger refactor, never theper-style-root approach.+**Update 2026-10-06:** waiting for a restart left the old surface on screen+(the pet stayed beside a freshly picked bar until the app restarted). A style+the app has not built yet now starts in its own host process+(`DesktopApp._build_hosted_surface`, the `jarvis.ui.jarvisbar.host` used on+macOS since BUG-057), so the switch applies live on every OS without a second+in-process root; the surface being left is hidden (in-process) or stopped+(hosted) at once. `restart_required` remains only for a host that fails to+start. The same change reads "what is on screen" from the app instead of+`cfg.ui.orb_style`, which the settings route had already overwritten — an idle+pet switched to the mascot now leaves the screen as it should.+### Regression test`tests/unit/ui/test_desktop_swap_overlay.py` pins the contract: `none` +diff --git a/docs/architecture-overview.md b/docs/architecture-overview.mdindex 5d13b23b67..a0312fbfd7 100644--- a/docs/architecture-overview.md+++ b/docs/architecture-overview.md@@ -270,7 +270,7 @@ The six desktop power-user features that were historically Windows-only are now- **Dependency reality (AD-14 — do not "fix" this):** `pynput` + `ptyprocess` live in the `[desktop]` extra (`ptyprocess` gated `sys_platform != 'win32'`); `pyobjc-framework-{Quartz,ApplicationServices,Accessibility}` in `[desktop-macos]` (`sys_platform == 'darwin'`). **Linux `pyatspi` is NOT on PyPI — never add it as a pip dependency.** It is GObject-Introspection, distro-packaged (`apt install python3-pyatspi gir1.2-atspi-2.0`), surfaced via the `capabilities.has_ax_tree` runtime probe.- **Doctrine intact:** the headless €5-VPS base install ships **none** of these desktop extras and still boots on a fresh `python:3.11-slim` Linux container — every port is extras-gated and degrades to a logged no-op (AD-6) when its capability is absent.-- **Overlay display styles:** `[ui] orb_style` picks the on-screen surface — the slim Jarvis bar, or one of three looks of the floating orb window (`mascot`, `voice_orb`, `pet`), or none. The vocabulary lives in `jarvis/ui/overlay_styles.py`; `ui/orb/bus_bridge.py` drives every surface from bus events. Orb-window looks swap live; bar ↔ orb window needs a restart (BUG-031). The desktop pet (animated pixel-art sprites, control strip, status bubble) is specified in [`docs/pets.md`](pets.md).+- **Overlay display styles:** `[ui] orb_style` picks the on-screen surface — the slim Jarvis bar, or one of three looks of the floating orb window (`mascot`, `voice_orb`, `pet`), or none. The vocabulary lives in `jarvis/ui/overlay_styles.py`; `ui/orb/bus_bridge.py` drives every surface from bus events. Every switch applies live: orb-window looks re-style one window, and a surface the app has not built yet starts in its own host process (`jarvis/ui/jarvisbar/host.py`), because a second in-process Tk root aborts the app (BUG-031). The desktop pet (animated pixel-art sprites, control strip, status bubble) is specified in [`docs/pets.md`](pets.md).- **Computer-Use screen indicator (ADR-0028):** while a CU mission drives thelocal mouse/keyboard, a breathing Jarvis-gold border glows on every monitoredge with a localized "Esc to cancel" pill. It is a minimaldiff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 0297842825..33abc2dd63 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -177,6 +177,24 @@ def _pet_toggle_hotkey(cfg: Any) -> str:return str(value or "").strip()++def _cached_orb_window(cache: dict[str, Any]) -> Any | None:+ """The orb window among the cached overlay surfaces, if one was built."""+ from jarvis.ui.overlay_styles import ORB_STYLES++ for key, surface in cache.items():+ if key in ORB_STYLES and hasattr(surface, "set_style"):+ return surface+ return None+++def _recache_surface(cache: dict[str, Any], surface: Any, style: str) -> None:+ """Key ``surface`` under ``style`` only — one window, one cache entry."""+ for key in [k for k, v in cache.items() if v is surface]:+ cache.pop(key, None)+ cache[style] = surface++def boot_overlay_style(configured: str | None, *, instance: Any | None = None) -> str:"""The on-screen overlay style this process boots with.@@ -3630,54 +3648,12 @@ class DesktopApp:# companion process whose MAIN thread owns the Tk mainloop# (jarvis.ui.jarvisbar.host), remote-driven over stdio; the init# line's "surface" key selects bar vs. mascot.- from loguru import logger-- if style == "jarvis_bar":- try:- from jarvis.ui.jarvisbar.subprocess_overlay import (- SubprocessBarOverlay,- )-- surface = SubprocessBarOverlay(- persistent=self.cfg.ui.bar_persistent,- accent=self.cfg.ui.bar_accent,- startup_gated=gate_until_voice_ready,- size_scale=getattr(self.cfg.ui, "bar_size_scale", 1.0),- follow_cursor_monitor=getattr(- self.cfg.ui, "bar_follow_cursor_monitor", True- ),- )- surface.start_in_thread()- logger.info(- "JarvisBar hosted out-of-process on macOS (jarvis.ui.jarvisbar.host)."- )- return surface- except Exception: # noqa: BLE001 — cosmetic; never block boot- logger.opt(exception=True).warning(- "macOS JarvisBar host failed to start — falling back to the no-op surface."- )- elif style != "none":- try:- from jarvis.ui.jarvisbar.subprocess_overlay import (- SubprocessMascotOverlay,- )-- surface = SubprocessMascotOverlay(- mascot_path=self.cfg.ui.orb_mascot_path or None,- style=style,- **self._pet_surface_kwargs(),- )- surface.start_in_thread()- logger.info(- "Orb window hosted out-of-process on macOS "- "(jarvis.ui.jarvisbar.host, style={}).",- style,- )- return surface- except Exception: # noqa: BLE001 — cosmetic; never block boot- logger.opt(exception=True).warning(- "macOS orb host failed to start — falling back to the no-op surface."- )+ if style != "none":+ hosted = self._build_hosted_surface(+ style, gate_until_voice_ready=gate_until_voice_ready+ )+ if hosted is not None:+ return hostedfrom jarvis.ui.jarvisbar import NullOverlayreturn NullOverlay()@@ -3710,6 +3686,54 @@ class DesktopApp:surface.start_in_thread()return surface+ def _build_hosted_surface(self, style: str, *, gate_until_voice_ready: bool = False):+ """Start the bar or the orb window in its own companion process.++ ``jarvis.ui.jarvisbar.host`` owns the Tk (or Qt) root on its own MAIN+ thread, so nothing in this process ever creates or destroys a root.+ That makes it the macOS boot surface (BUG-057) and, on every OS, the+ surface a live style switch builds: a second in-process root aborts+ the whole app (BUG-031), while a host process can be started and+ stopped any number of times. Returns ``None`` when the host could not+ be started; the caller decides how to degrade.+ """+ from loguru import logger++ from jarvis.ui.overlay_styles import BAR_STYLE, ORB_STYLES++ try:+ if style == BAR_STYLE:+ from jarvis.ui.jarvisbar.subprocess_overlay import SubprocessBarOverlay++ surface = SubprocessBarOverlay(+ persistent=self.cfg.ui.bar_persistent,+ accent=self.cfg.ui.bar_accent,+ startup_gated=gate_until_voice_ready,+ size_scale=getattr(self.cfg.ui, "bar_size_scale", 1.0),+ follow_cursor_monitor=getattr(self.cfg.ui, "bar_follow_cursor_monitor", True),+ )+ elif style in ORB_STYLES:+ from jarvis.ui.jarvisbar.subprocess_overlay import SubprocessMascotOverlay++ surface = SubprocessMascotOverlay(+ mascot_path=self.cfg.ui.orb_mascot_path or None,+ style=style,+ **self._pet_surface_kwargs(),+ )+ else:+ return None+ # The host imports its renderer before it reports ready; give a+ # cold interpreter more room than the 3 s default.+ surface.start_in_thread(timeout=10.0)+ except Exception: # noqa: BLE001 — cosmetic; the caller degrades+ logger.opt(exception=True).warning("Overlay host for style={} failed to start.", style)+ return None+ if getattr(surface, "_proc", None) is None:+ logger.warning("Overlay host for style={} did not start.", style)+ return None+ logger.info("Overlay hosted out-of-process (jarvis.ui.jarvisbar.host, style={}).", style)+ return surface+def _pet_surface_kwargs(self) -> dict[str, object]:"""The pet's ``[ui]`` settings for the orb window (``docs/pets.md``).@@ -3909,31 +3933,31 @@ class DesktopApp:return {"ok": True, "applied_live": False, "enabled": enabled}def swap_overlay(self, style: str) -> dict[str, object]:- """Apply an overlay style change at runtime *as far as is Tk-safe*.-- Hard constraint: this NEVER creates a new ``tk.Tk()`` root at runtime.- Tkinter cannot create per-style Tk roots on short-lived threads and tear- them down: when a destroyed root's Python wrapper is later garbage-- collected on a different thread, Tcl aborts the WHOLE PROCESS with- ``Tcl_AsyncDelete: async handler deleted by the wrong thread`` (proven- live — ``screenshots/live_swap_three_cycles.py``, BUG-031). The "park +- join + rebuild" approach looked safe in a 2-root throwaway test only- because that test called ``os._exit()`` before GC ran. So the only live- transitions we allow are the ones that touch no new root:-- - ``"none"`` → hide the current surface (NullOverlay no-op).- - an already-built style (cached, e.g. the boot surface re-selected)- → show it again (same root, never destroyed).-- Any transition that would need a brand-new real surface (e.g. boot was- the mascot and the user picks the bar for the first time) returns- ``applied_live=False``; the choice is persisted and the route reports- ``restart_required``. The frontend turns that into a one-click- self-restart so the user never has to close + reopen by hand. Guarded.+ """Switch the on-screen overlay style live.++ Hard constraint: this NEVER creates a ``tk.Tk()`` root in THIS process+ at runtime. Building a second in-process root and tearing one down+ aborts the whole app with ``Tcl_AsyncDelete: async handler deleted by+ the wrong thread`` (BUG-031). The transitions therefore are:++ - ``"none"`` → the rootless ``NullOverlay``.+ - one orb look to another → re-style the live orb window (same root).+ - an already-built style → show it again (same root, never destroyed).+ - anything else → start the surface in its own host process+ (``_build_hosted_surface``), whose root+ lives on that process's main thread.++ The surface being left is taken off the screen at once, so the old look+ never lingers beside the new one (the 2026-10-06 "the pet stays next to+ the bar" report). A hosted surface is stopped — its process ends — and+ an in-process one is only hidden, never destroyed. ``applied_live`` is+ False only when a host fails to start; the route then reports+ ``restart_required`` and the frontend offers a one-click restart."""from loguru import loggerfrom jarvis.ui.overlay_styles import (+ HIDDEN_STYLE,ORB_STYLES,OVERLAY_STYLES,PERSISTENT_ORB_STYLES,@@ -3946,23 +3970,25 @@ class DesktopApp:if bridge is None:# No live bridge (headless / overlay unavailable) — persisted only.return {"ok": True, "applied_live": False, "style": style}+ # What is on screen right now. Not cfg.ui.orb_style: the settings route+ # stores the NEW style there before it calls this method.+ previous = str(+ getattr(self, "_live_overlay_style", None)+ or getattr(self.cfg.ui, "orb_style", "")+ or ""+ )try:cache = getattr(self, "_surfaces", None)if cache is None:cache = self._surfaces = {}old = getattr(self, "_orb", None)- # Mascot <-> voice orb is a RENDERER swap inside one window, not a- # new surface: the orb window stays, only what it paints changes. So- # this transition applies live even though every other first-time- # transition needs a restart (a second tk.Tk() root would abort the- # process — BUG-031).+ # Mascot <-> voice orb <-> pet is a RENDERER swap inside one window,+ # not a new surface: the orb window stays, only what it paints+ # changes.if style in ORB_STYLES and old is not None and hasattr(old, "set_style"):- previous = str(getattr(self.cfg.ui, "orb_style", "") or "")old.set_style(style)- for key in [k for k, v in cache.items() if v is old]:- cache.pop(key, None)- cache[style] = old+ _recache_surface(cache, old, style)# The idle regime travels with the look: the pet stays up# while idle, the mascot and the voice orb pop up per session.bridge._hide_on_idle = self._hide_on_idle_for(style)@@ -3971,40 +3997,38 @@ class DesktopApp:old.show(mode)elif previous in PERSISTENT_ORB_STYLES and mode == "idle":old.hide()- try:- self.cfg.ui.orb_style = style # best-effort in-memory- except Exception: # noqa: BLE001- logger.debug("in-memory orb_style update skipped", exc_info=True)+ self._note_live_overlay_style(style)logger.info("Orb window re-styled live to {}.", style)return {"ok": True, "applied_live": True, "style": style}- if style == "none":- new = cache.get("none")+ if style == HIDDEN_STYLE:+ new = cache.get(HIDDEN_STYLE)if new is None:from jarvis.ui.jarvisbar import NullOverlay # no Tk rootnew = NullOverlay()- cache["none"] = new+ cache[HIDDEN_STYLE] = new+ elif style in ORB_STYLES and (window := _cached_orb_window(cache)) is not None:+ # The orb window built earlier (e.g. at boot) wears any orb+ # look, so it is reused rather than built a second time.+ window.set_style(style)+ _recache_surface(cache, window, style)+ new = windowelse:new = cache.get(style)if new is None:- # A new tk.Tk() root at runtime would cross-thread-abort the- # process (Tcl_AsyncDelete, BUG-031). Persist only; the route- # surfaces restart_required (frontend = one-click restart).- logger.info(- "Overlay style '{}' needs a restart (no live Tk root yet).",- style,- )- return {"ok": True, "applied_live": False, "style": style}+ new = self._build_hosted_surface(style)+ if new is None:+ # The host would not start. Persisted only; the route+ # reports restart_required (one-click restart).+ return {"ok": True, "applied_live": False, "style": style}+ cache[style] = newbridge.set_surface(new)self._orb = newbridge._hide_on_idle = self._hide_on_idle_for(style)if old is not None and old is not new:- try:- old.hide()- except Exception: # noqa: BLE001- logger.debug("old overlay hide failed", exc_info=True)+ self._retire_overlay_surface(old, cache)try:if (style == "jarvis_bar" and self.cfg.ui.bar_persistent@@ -4012,10 +4036,7 @@ class DesktopApp:new.show("idle")except Exception: # noqa: BLE001logger.debug("post-swap show failed", exc_info=True)- try:- self.cfg.ui.orb_style = style # best-effort in-memory- except Exception: # noqa: BLE001- logger.debug("in-memory orb_style update skipped", exc_info=True)+ self._note_live_overlay_style(style)logger.info("Overlay swapped live to style={}.", style)return {"ok": True, "applied_live": True, "style": style}except Exception as exc: # noqa: BLE001@@ -4024,6 +4045,38 @@ class DesktopApp:)return {"ok": True, "applied_live": False, "style": style}+ def _note_live_overlay_style(self, style: str) -> None:+ """Remember which style is on screen (in memory and in the config)."""+ self._live_overlay_style = style+ try:+ self.cfg.ui.orb_style = style # best-effort in-memory+ except Exception: # noqa: BLE001 — a frozen model is not an error+ from loguru import logger++ logger.debug("in-memory orb_style update skipped", exc_info=True)++ def _retire_overlay_surface(self, surface: Any, cache: dict[str, Any]) -> None:+ """Take a surface that is no longer selected off the screen.++ A surface in a host process is stopped and forgotten: its process ends,+ and a later switch back simply starts a fresh one. A surface in this+ process keeps its Tk root (destroying it aborts the app, BUG-031), so it+ is only hidden and stays cached for reuse.+ """+ from loguru import logger++ from jarvis.ui.jarvisbar.subprocess_overlay import SubprocessBarOverlay++ try:+ if isinstance(surface, SubprocessBarOverlay):+ for key in [k for k, v in cache.items() if v is surface]:+ cache.pop(key, None)+ surface.stop()+ else:+ surface.hide()+ except Exception: # noqa: BLE001 — cosmetic; the new surface is already live+ logger.debug("retiring the previous overlay failed", exc_info=True)+def request_restart(self) -> bool:"""Cleanly self-restart the app to deliver a pending overlay change.@@ -4418,6 +4471,7 @@ class DesktopApp:# Cache the boot surface so a later swap back to it reuses the# same Tk root instead of building a second one.self._surfaces = {orb_style: surface}+ self._live_overlay_style = orb_stylelogger.info("On-screen overlay active: style={} (persistent={}, accent={}).",orb_style,diff --git a/tests/unit/ui/test_desktop_swap_overlay.py b/tests/unit/ui/test_desktop_swap_overlay.pyindex b244daf608..cca7d86ac7 100644--- a/tests/unit/ui/test_desktop_swap_overlay.py+++ b/tests/unit/ui/test_desktop_swap_overlay.py@@ -1,10 +1,11 @@-"""DesktopApp.swap_overlay live-swap logic (the 'none' path needs no Tk).--A per-style Tk-root live swap is impossible: tearing a ``tk.Tk()`` root down and-building a new one cross-thread-aborts the process with ``Tcl_AsyncDelete``-(BUG-031, ``screenshots/live_swap_three_cycles.py``). So a swap to a real style-the boot did not build is persisted only and reports ``restart_required`` — the-frontend turns that into a one-click self-restart.+"""DesktopApp.swap_overlay live-swap logic.++A second in-process Tk root at runtime is impossible: tearing a ``tk.Tk()`` root+down and building a new one cross-thread-aborts the process with+``Tcl_AsyncDelete`` (BUG-031). So a style the app has not built yet starts in+its own host process (``_build_hosted_surface``), the surface being left goes+off the screen at once, and only a host that fails to start falls back to+``restart_required``."""from __future__ import annotations@@ -68,16 +69,91 @@ def test_swap_reuses_cached_surface():assert bridge.surface is sentinel # reused, not rebuilt-def test_swap_to_uncached_real_style_needs_restart():- # boot built only the mascot; selecting the bar for the first time would- # require a new tk.Tk() root at runtime (Tcl_AsyncDelete cross-thread abort)- # → persist + restart (one-click self-restart in the UI).- bridge = FakeBridge()- app = _app(orb_style="mascot", bridge=bridge, orb=FakeOld())- app._surfaces = {} # nothing cached for the bar+class FakeHosted(FakeOld):+ """Stands in for a surface in its own host process."""++ def __init__(self, style):+ super().__init__()+ self.style = style+ self.shown = []++ def show(self, mode="listen"):+ self.shown.append(mode)+++def _host(app, built):+ def build(style, **_):+ surface = FakeHosted(style)+ built.append(surface)+ return surface++ app._build_hosted_surface = build+++def test_swap_to_an_unbuilt_style_starts_it_hosted_and_hides_the_old():+ # Boot built only the pet; picking the bar must show the bar NOW and take+ # the pet off the screen — not leave the pet up until a restart.+ bridge, old, built = FakeBridge(), FakeOrbWindow("pet"), []+ app = _app(orb_style="jarvis_bar", bridge=bridge, orb=old) # route pre-wrote cfg+ app._surfaces = {"pet": old}+ _host(app, built)++ result = app.swap_overlay("jarvis_bar")++ assert result == {"ok": True, "applied_live": True, "style": "jarvis_bar"}+ assert [s.style for s in built] == ["jarvis_bar"]+ assert bridge.surface is built[0] and app._orb is built[0]+ assert old.hidden is True # in-process surface hidden, never destroyed+ assert built[0].shown == ["idle"] # bar_persistent=True+ assert app._surfaces["jarvis_bar"] is built[0]+++def test_swap_falls_back_to_restart_when_the_host_will_not_start():+ bridge, old = FakeBridge(), FakeOld()+ app = _app(orb_style="mascot", bridge=bridge, orb=old)+ app._surfaces = {}+ app._build_hosted_surface = lambda style, **_: Noneresult = app.swap_overlay("jarvis_bar")assert result == {"ok": True, "applied_live": False, "style": "jarvis_bar"}- assert bridge.surface is None # bridge NOT repointed (no live apply)+ assert bridge.surface is None # bridge NOT repointed+ assert old.hidden is False # nothing replaces it, so it stays+++def test_leaving_a_hosted_surface_stops_its_process(monkeypatch):+ from jarvis.ui.jarvisbar import subprocess_overlay++ class FakeHostProc(subprocess_overlay.SubprocessBarOverlay):+ def __init__(self):+ super().__init__()+ self.stopped = False++ def stop(self):+ self.stopped = True++ hosted = FakeHostProc()+ bridge = FakeBridge()+ app = _app(orb_style="none", bridge=bridge, orb=hosted)+ app._surfaces = {"jarvis_bar": hosted}+ assert app.swap_overlay("none")["applied_live"] is True+ assert hosted.stopped is True+ assert "jarvis_bar" not in app._surfaces # a later switch starts a fresh host+++def test_bar_back_to_a_cached_orb_window_restyles_it():+ # Boot was the pet, the bar was started hosted; picking the mascot reuses+ # the boot orb window instead of starting a second one.+ bridge, window, built = FakeBridge(), FakeOrbWindow("pet"), []+ bar = FakeOld()+ app = _app(orb_style="mascot", bridge=bridge, orb=bar)+ app._surfaces = {"pet": window, "jarvis_bar": bar}+ _host(app, built)++ assert app.swap_overlay("mascot")["applied_live"] is True+ assert built == []+ assert window.style == "mascot"+ assert bridge.surface is window+ assert bar.hidden is True+ assert app._surfaces["mascot"] is window and "pet" not in app._surfacesdef test_swap_without_bridge_is_persisted_only():@@ -131,16 +207,31 @@ def test_voice_orb_back_to_mascot_also_applies_live():assert orb.style == "mascot"-def test_bar_to_voice_orb_still_needs_a_restart():- # The bar surface has no orb window behind it, so this one really does need- # a fresh root — the restart path must stay intact.- bridge = FakeBridge()+def test_bar_to_voice_orb_starts_the_orb_window_hosted():+ bridge, built = FakeBridge(), []app = _app(orb_style="jarvis_bar", bridge=bridge, orb=FakeOld())app._surfaces = {}+ _host(app, built)- assert app.swap_overlay("voice_orb") == {- "ok": True,- "applied_live": False,- "style": "voice_orb",- }- assert bridge.surface is None+ assert app.swap_overlay("voice_orb")["applied_live"] is True+ assert [s.style for s in built] == ["voice_orb"]+ assert bridge.surface is built[0]+++def test_pet_to_mascot_hides_the_idle_window_although_the_route_prewrote_cfg():+ # The settings route stores the NEW style in cfg before calling+ # swap_overlay, so "what was on screen" must not be read from cfg: an idle+ # pet turned mascot has to go off the screen (the mascot pops per session).+ class Window(FakeOrbWindow):+ _mode = "idle"++ def show(self, mode="listen"):+ self.hidden = False++ bridge, window = FakeBridge(), Window("pet")+ app = _app(orb_style="mascot", bridge=bridge, orb=window)+ app._surfaces = {"pet": window}+ app._live_overlay_style = "pet"++ assert app.swap_overlay("mascot")["applied_live"] is True+ assert window.hidden is True