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.

feat(platform): probe whether a native webview backend is available

rubenluetke10-beep07a688f8b2ae
diff --git a/jarvis/platform/capabilities.py b/jarvis/platform/capabilities.py
index 88861eec4e..1fd0c30234 100644
--- a/jarvis/platform/capabilities.py
+++ b/jarvis/platform/capabilities.py
@@ -31,6 +31,7 @@ class Capabilities:
has_cursor: bool
display_present: bool
is_wayland: bool
+ has_webview: bool
ax_permission_granted: bool | None
@@ -47,6 +48,7 @@ def detect_capabilities() -> Capabilities:
has_cursor=probes.has_cursor(),
display_present=probes.display_present(),
is_wayland=probes.is_wayland(),
+ has_webview=probes.webview_backend_available(),
ax_permission_granted=probes.ax_permission_granted(),
)
diff --git a/jarvis/platform/probes.py b/jarvis/platform/probes.py
index 6f4662f1f1..5bda08e3a8 100644
--- a/jarvis/platform/probes.py
+++ b/jarvis/platform/probes.py
@@ -154,6 +154,24 @@ def has_overlay() -> bool:
return display_present() and _has_module("tkinter")
+def webview_backend_available() -> bool:
+ """Can this host draw a native pywebview window (main or detached)?
+
+ Answers the capability question BEFORE the UI offers a window-spawning
+ control (the P-27/P-30 rule): ``pywebview`` ships in the ``[desktop]``
+ extra, so a headless install simply lacks the module. On Linux the module
+ alone is not enough — pywebview needs a display plus the distro-packaged
+ GTK/WebKit introspection bindings (``gi``), which pip cannot install; a
+ module-only claim would fail later inside ``webview.start()``.
+ """
+ if not _has_module("webview"):
+ return False
+ plat = detect_platform()
+ if plat in ("win32", "darwin"):
+ return True
+ return display_present() and _has_module("gi")
+
+
def has_elevation() -> bool:
"""Is a privilege-escalation mechanism present (AD-12)?"""
plat = detect_platform()
@@ -176,4 +194,5 @@ __all__ = [
"has_cursor",
"has_overlay",
"has_elevation",
+ "webview_backend_available",
]
diff --git a/tests/fakes/fake_capabilities.py b/tests/fakes/fake_capabilities.py
index b927c7271f..ebbade36dc 100644
--- a/tests/fakes/fake_capabilities.py
+++ b/tests/fakes/fake_capabilities.py
@@ -22,6 +22,7 @@ def fake_windows_capabilities(**overrides) -> Capabilities:
has_cursor=True,
display_present=True,
is_wayland=False,
+ has_webview=True,
ax_permission_granted=True,
)
base.update(overrides)
@@ -40,6 +41,7 @@ def fake_macos_capabilities(**overrides) -> Capabilities:
has_cursor=True,
display_present=True,
is_wayland=False,
+ has_webview=True,
ax_permission_granted=None,
)
base.update(overrides)
@@ -58,6 +60,7 @@ def fake_linux_capabilities(**overrides) -> Capabilities:
has_cursor=True,
display_present=True,
is_wayland=False,
+ has_webview=True,
ax_permission_granted=False,
)
base.update(overrides)
@@ -76,6 +79,7 @@ def fake_headless_capabilities(**overrides) -> Capabilities:
has_cursor=False,
display_present=False,
is_wayland=False,
+ has_webview=False,
ax_permission_granted=False,
)
base.update(overrides)
diff --git a/tests/integration/test_autostart_route.py b/tests/integration/test_autostart_route.py
index 9162abbaa7..317a4c490f 100644
--- a/tests/integration/test_autostart_route.py
+++ b/tests/integration/test_autostart_route.py
@@ -33,6 +33,7 @@ def _caps(*, display_present: bool = True) -> Capabilities:
has_cursor=False,
display_present=display_present,
is_wayland=False,
+ has_webview=False,
ax_permission_granted=None,
)
diff --git a/tests/unit/admin/test_elevator.py b/tests/unit/admin/test_elevator.py
index c902a6993b..006f7c6de9 100644
--- a/tests/unit/admin/test_elevator.py
+++ b/tests/unit/admin/test_elevator.py
@@ -46,7 +46,8 @@ def test_factory_returns_null_when_no_elevation_capability(monkeypatch):
fake_caps = Capabilities(
platform="linux", has_hotkey=False, has_ax_tree=False,
has_overlay=False, has_pty=False, has_elevation=False,
- display_present=False, is_wayland=False, ax_permission_granted=None, has_cursor=False,
+ display_present=False, is_wayland=False, has_webview=False,
+ ax_permission_granted=None, has_cursor=False,
)
monkeypatch.setattr(elevator_mod, "detect_capabilities", lambda: fake_caps)
assert isinstance(make_elevator(), NullElevator)
@@ -58,7 +59,8 @@ def test_factory_selects_polkit_when_pkexec_present(monkeypatch):
caps = Capabilities(
platform="linux", has_hotkey=False, has_ax_tree=False,
has_overlay=False, has_pty=False, has_elevation=True,
- display_present=False, is_wayland=False, ax_permission_granted=None, has_cursor=False,
+ display_present=False, is_wayland=False, has_webview=False,
+ ax_permission_granted=None, has_cursor=False,
)
monkeypatch.setattr(elevator_mod, "detect_capabilities", lambda: caps)
monkeypatch.setattr(elevator_mod, "detect_platform", lambda: "linux")
@@ -75,7 +77,8 @@ def test_factory_falls_back_to_sudo_when_no_pkexec(monkeypatch):
caps = Capabilities(
platform="linux", has_hotkey=False, has_ax_tree=False,
has_overlay=False, has_pty=False, has_elevation=True,
- display_present=False, is_wayland=False, ax_permission_granted=None, has_cursor=False,
+ display_present=False, is_wayland=False, has_webview=False,
+ ax_permission_granted=None, has_cursor=False,
)
monkeypatch.setattr(elevator_mod, "detect_capabilities", lambda: caps)
monkeypatch.setattr(elevator_mod, "detect_platform", lambda: "linux")
@@ -92,7 +95,8 @@ def test_factory_returns_null_on_linux_with_neither(monkeypatch):
caps = Capabilities(
platform="linux", has_hotkey=False, has_ax_tree=False,
has_overlay=False, has_pty=False, has_elevation=True,
- display_present=False, is_wayland=False, ax_permission_granted=None, has_cursor=False,
+ display_present=False, is_wayland=False, has_webview=False,
+ ax_permission_granted=None, has_cursor=False,
)
monkeypatch.setattr(elevator_mod, "detect_capabilities", lambda: caps)
monkeypatch.setattr(elevator_mod, "detect_platform", lambda: "linux")
@@ -106,7 +110,8 @@ def test_factory_selects_macauth_on_darwin(monkeypatch):
caps = Capabilities(
platform="darwin", has_hotkey=False, has_ax_tree=False,
has_overlay=False, has_pty=False, has_elevation=True,
- display_present=True, is_wayland=False, ax_permission_granted=None, has_cursor=False,
+ display_present=True, is_wayland=False, has_webview=True,
+ ax_permission_granted=None, has_cursor=False,
)
monkeypatch.setattr(elevator_mod, "detect_capabilities", lambda: caps)
monkeypatch.setattr(elevator_mod, "detect_platform", lambda: "darwin")
diff --git a/tests/unit/autostart/conftest.py b/tests/unit/autostart/conftest.py
index 90f816fa1a..bec802ab78 100644
--- a/tests/unit/autostart/conftest.py
+++ b/tests/unit/autostart/conftest.py
@@ -25,6 +25,7 @@ def make_caps(
has_cursor=False,
display_present=display_present,
is_wayland=False,
+ has_webview=False,
ax_permission_granted=None,
)
diff --git a/tests/unit/platform/test_capabilities.py b/tests/unit/platform/test_capabilities.py
index a552eee8fc..7a0d6b1163 100644
--- a/tests/unit/platform/test_capabilities.py
+++ b/tests/unit/platform/test_capabilities.py
@@ -80,6 +80,7 @@ def test_real_host_capabilities_have_correct_types():
"has_elevation",
"display_present",
"is_wayland",
+ "has_webview",
):
assert isinstance(getattr(caps, field), bool), field
assert caps.ax_permission_granted in (True, False, None)
@@ -112,4 +113,5 @@ def test_headless_fake_has_no_gui_features():
assert caps.display_present is False
assert caps.has_overlay is False
assert caps.has_hotkey is False
+ assert caps.has_webview is False # no native window backend headless
assert caps.has_pty is True # a VPS still has a PTY
diff --git a/tests/unit/platform/test_open_path.py b/tests/unit/platform/test_open_path.py
index 6ee25001b1..3ba378271a 100644
--- a/tests/unit/platform/test_open_path.py
+++ b/tests/unit/platform/test_open_path.py
@@ -25,6 +25,7 @@ def _caps(display: bool = True) -> Capabilities:
has_cursor=False,
display_present=display,
is_wayland=False,
+ has_webview=False,
ax_permission_granted=None,
)
diff --git a/tests/unit/platform/test_probes.py b/tests/unit/platform/test_probes.py
index c640c85ff9..0dfc66e3fb 100644
--- a/tests/unit/platform/test_probes.py
+++ b/tests/unit/platform/test_probes.py
@@ -213,6 +213,39 @@ def test_has_overlay_requires_display_and_tkinter(monkeypatch):
assert probes.has_overlay() is False
+# --- webview_backend_available ---------------------------------------------
+
+
+def test_webview_false_without_module_everywhere(monkeypatch):
+ for plat in ("win32", "darwin", "linux"):
+ _force_platform(monkeypatch, plat)
+ monkeypatch.setattr(probes, "_has_module", lambda n: False)
+ assert probes.webview_backend_available() is False
+
+
+def test_webview_module_suffices_on_windows_and_macos(monkeypatch):
+ for plat in ("win32", "darwin"):
+ _force_platform(monkeypatch, plat)
+ monkeypatch.setattr(probes, "_has_module", lambda n: n == "webview")
+ assert probes.webview_backend_available() is True
+
+
+def test_webview_linux_needs_display_and_gi(monkeypatch):
+ _force_platform(monkeypatch, "linux")
+ monkeypatch.setattr(probes, "_has_module", lambda n: n in ("webview", "gi"))
+ monkeypatch.setenv("DISPLAY", ":0")
+ assert probes.webview_backend_available() is True
+ # Headless: module present but no display → honest False.
+ monkeypatch.delenv("DISPLAY", raising=False)
+ monkeypatch.delenv("WAYLAND_DISPLAY", raising=False)
+ assert probes.webview_backend_available() is False
+ # Display but the distro GTK/WebKit bindings (gi) are missing → False,
+ # because webview.start() would raise WebViewException later.
+ monkeypatch.setenv("DISPLAY", ":0")
+ monkeypatch.setattr(probes, "_has_module", lambda n: n == "webview")
+ assert probes.webview_backend_available() is False
+
+
def test_all_probes_run_without_raising_on_host():
# Smoke: every probe returns a bool/None on the real host.
assert isinstance(probes.display_present(), bool)
@@ -223,3 +256,4 @@ def test_all_probes_run_without_raising_on_host():
assert isinstance(probes.has_elevation(), bool)
assert probes.ax_permission_granted() in (True, False, None)
assert probes.screen_recording_granted() in (True, False, None)
+ assert isinstance(probes.webview_backend_available(), bool)
diff --git a/tests/unit/trigger/test_hotkey_backends.py b/tests/unit/trigger/test_hotkey_backends.py
index 3e857484bc..0eb78dba0c 100644
--- a/tests/unit/trigger/test_hotkey_backends.py
+++ b/tests/unit/trigger/test_hotkey_backends.py
@@ -56,6 +56,7 @@ def patch_platform(monkeypatch):
has_elevation=False,
display_present=True,
is_wayland=not has_hotkey,
+ has_webview=False,
ax_permission_granted=None,
has_cursor=False,
)