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(appshot): name the missing macOS permission instead of arming or freezing
rubenluetke10-beep83372d181ca8
diff --git a/jarvis/appshot/gesture.py b/jarvis/appshot/gesture.pyindex 234ff1c320..5581d57722 100644--- a/jarvis/appshot/gesture.py+++ b/jarvis/appshot/gesture.py@@ -10,7 +10,9 @@ every 50 ms, no hook, no tap:``VK_RMENU`` too, so the Alt gesture works on AltGr layouts).* macOS: ``CGEventSourceKeyState`` on the left/right key codes (Option, Shift,Control). Needs the same Input Monitoring grant as every other global- shortcut; without it the read stays false and nothing fires.+ shortcut; without it the read stays false and nothing fires, so+ :func:`make_probe` reports the shortcut unavailable and names the grant+ instead of arming a watcher that can never fire.* Linux/X11: ``XQueryKeymap`` through python-xlib (pynput's own dependency).* Wayland, headless, missing packages: :func:`make_probe` returns ``None``with the reason, and the caller reports the shortcut as unavailable.@@ -104,6 +106,25 @@ def _x11_probe(family: str) -> Probe | None:return probe+def _macos_input_monitoring_missing() -> str:+ """Why macOS would read every key as up, or ``""`` when the grant is live."""+ try:+ from jarvis.platform.permissions import ( # noqa: PLC0415+ PermissionId,+ get_system_permission_port,+ )++ if get_system_permission_port().runtime_access_granted(PermissionId.INPUT_MONITORING):+ return ""+ except Exception: # noqa: BLE001 - an unanswerable probe arms; the read decides+ log.debug("appshot: Input Monitoring probe failed", exc_info=True)+ return ""+ return (+ "Allow Input Monitoring for Personal Jarvis in System Settings > Privacy & "+ "Security > Input Monitoring, then restart Personal Jarvis."+ )++def make_probe(family: str = "alt") -> tuple[Probe | None, str]:"""The key-state reader for ``family`` on this host, or ``None`` and why not."""from jarvis.platform import detect_platform # noqa: PLC0415@@ -116,6 +137,9 @@ def make_probe(family: str = "alt") -> tuple[Probe | None, str]:if not display_present():return None, "No display on this computer, so there is no keyboard to watch."if platform == "darwin":+ missing = _macos_input_monitoring_missing()+ if missing:+ return None, missingreturn _macos_probe(family), ""if is_wayland():return None, (diff --git a/jarvis/appshot/service.py b/jarvis/appshot/service.pyindex 77d8733a13..d1dad2cca3 100644--- a/jarvis/appshot/service.py+++ b/jarvis/appshot/service.py@@ -112,6 +112,13 @@ async def take_appshot()service = get_service(bus=bus)if scope == "region":+ # Refuse BEFORE the screens freeze: without the grant the frozen+ # frame is wallpaper only (macOS) and the refusal would come after+ # the user had marked up a fake screen.+ check = getattr(service, "capture_permission_issue", None)+ issue = await check() if check is not None else None+ if issue is not None:+ return AppshotResult(status="refused", reason_code=issue[0], message=issue[1])picked = await _pick_area(service, _language(config))if isinstance(picked, AppshotResult):return pickeddiff --git a/jarvis/screen_context/service.py b/jarvis/screen_context/service.pyindex 5e994483ef..3de3ee99b2 100644--- a/jarvis/screen_context/service.py+++ b/jarvis/screen_context/service.py@@ -342,6 +342,23 @@ class ScreenContextService:return await self.capture(verdict=verdict, trace_id=trace_id)+ async def capture_permission_issue(self) -> tuple[str, str] | None:+ """``(reason_code, message)`` when the OS would refuse a capture now.++ Silent (it never asks the OS for a grant). The area picker asks this+ before it freezes the screen: without Screen Recording on macOS the+ frozen frame is wallpaper only, and the refusal would come only after+ the user had selected and marked up a fake screen.+ """+ issue = await asyncio.to_thread(self._permission_probe)+ if not issue:+ return None+ if isinstance(issue, CapturePermissionIssue):+ return issue.code, issue.message+ # Compatibility for injected third-party/test probes that still+ # implement the original ``str | None`` port contract.+ return "capture_permission", str(issue)+async def capture(self,*,@@ -369,16 +386,9 @@ class ScreenContextService:message="Screen Context settings changed before capture could start.",)- permission_issue = await asyncio.to_thread(self._permission_probe)- if permission_issue:- if isinstance(permission_issue, CapturePermissionIssue):- reason_code = permission_issue.code- permission_message = permission_issue.message- else:- # Compatibility for injected third-party/test probes that still- # implement the original ``str | None`` port contract.- reason_code = "capture_permission"- permission_message = str(permission_issue)+ permission_issue = await self.capture_permission_issue()+ if permission_issue is not None:+ reason_code, permission_message = permission_issuelog.info("screen_context: capture refused — %s", permission_message)return CaptureOutcome(status="refused",diff --git a/tests/unit/appshot/test_appshot_permissions.py b/tests/unit/appshot/test_appshot_permissions.pynew file mode 100644index 0000000000..0ae4020443--- /dev/null+++ b/tests/unit/appshot/test_appshot_permissions.py@@ -0,0 +1,76 @@+"""Appshots say which OS permission is missing instead of arming or freezing for nothing."""++from __future__ import annotations++from types import SimpleNamespace++import pytest++from jarvis.appshot import gesture, service+from jarvis.platform import permissions+++class FakePort:+ def __init__(self, granted: bool) -> None:+ self.granted = granted++ def runtime_access_granted(self, permission_id) -> bool:+ assert permission_id is permissions.PermissionId.INPUT_MONITORING+ return self.granted+++def mac(monkeypatch: pytest.MonkeyPatch):+ monkeypatch.setattr("jarvis.platform.detect_platform", lambda: "darwin")+ monkeypatch.setattr("jarvis.platform.probes.display_present", lambda: True)+ monkeypatch.setattr(gesture, "_macos_probe", lambda family: f"probe:{family}")++ def use(granted: bool) -> None:+ monkeypatch.setattr(permissions, "get_system_permission_port", lambda: FakePort(granted))++ return use+++def test_a_mac_without_input_monitoring_does_not_arm_the_gesture(mac) -> None:+ mac(False)+ probe, reason = gesture.make_probe("alt")+ assert probe is None+ assert "Input Monitoring" in reason+++def test_a_mac_with_input_monitoring_arms_it(mac) -> None:+ mac(True)+ assert gesture.make_probe("shift") == ("probe:shift", "")+++class RefusingService:+ async def capture_permission_issue(self):+ return "capture_permission", "Grant Screen Recording first."+++async def test_the_area_picker_never_opens_without_capture_permission(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ opened: list[bool] = []++ async def pick_area(*_args, **_kwargs):+ opened.append(True)+ raise AssertionError("the screens must not freeze for a capture that will be refused")++ config = SimpleNamespace(+ screen_context=SimpleNamespace(enabled=True),+ ui=SimpleNamespace(language="en"),+ appshot=SimpleNamespace(),+ )+ monkeypatch.setattr(service, "_load_config", lambda: config)+ monkeypatch.setattr(service, "_pick_area", pick_area)+ monkeypatch.setattr(+ "jarvis.screen_context.turn.get_service", lambda bus=None: RefusingService()+ )++ result = await service.take_appshot(trigger="hotkey", scope="region")++ assert result.status == "refused"+ assert result.reason_code == "capture_permission"+ assert result.message == "Grant Screen Recording first."+ assert opened == []