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(macos): give the screen recorder its Screen Recording gate
rubenluetke10-beep395ebd2ce0a0
diff --git a/jarvis/platform/screen_access.py b/jarvis/platform/screen_access.pynew file mode 100644index 0000000000..b99fb21dd6--- /dev/null+++ b/jarvis/platform/screen_access.py@@ -0,0 +1,106 @@+"""Screen Recording access for the appshot recorder, backed by the permission port.++The screen recorder (``jarvis.appshot.recording`` and its worker) asks this+module, on macOS only, whether the Screen Recording permission lets a capture+run. macOS fails that gate SILENTLY: without the grant a capture returns the+desktop wallpaper and no error, so the recorder checks first and refuses with a+sentence that names the permission.++Two rules:++* **Status reads never ask.** :func:`screen_recording_state` and+ :func:`state_allows_capture` are silent probes for status routes and the+ recorder's once-a-second revoke check.+* **Only a user gesture asks.** :func:`require_screen_recording_async` runs+ when the person starts a recording: it asks macOS once through+ :meth:`SystemPermissionPort.request` and raises :class:`ScreenCaptureRefused`+ unless the grant is live afterwards.++The state comes from :func:`jarvis.platform.permissions.get_system_permission_port`,+the same port Screen Context's capture gate uses. Nothing initialises at import+time (AP-26).+"""++from __future__ import annotations++import asyncio+import logging++from jarvis.platform.permissions import PermissionId, PermissionState++log = logging.getLogger(__name__)++#: States in which a capture may run: granted, or no permission exists here.+_READY = frozenset({PermissionState.GRANTED, PermissionState.NOT_REQUIRED})++_USER_DETAIL = (+ "Allow Screen Recording for Personal Jarvis in System Settings > Privacy & "+ "Security > Screen Recording, then start the recording again."+)+_AGENT_DETAIL = (+ "[permission_needed:screen_recording] Screen Recording is not granted, so no "+ "screen capture may run. Ask the user to allow it in System Settings."+)+++class ScreenCaptureRefused(RuntimeError):+ """A screen capture macOS does not allow, with honest permission text.++ ``str(exc)`` is the agent sentence; ``user_detail`` the people-facing one.+ Neither carries exception text, paths or window titles.+ """++ permission = PermissionId.SCREEN_RECORDING.value++ def __init__(+ self, agent_detail: str = _AGENT_DETAIL, user_detail: str = _USER_DETAIL+ ) -> None:+ super().__init__(agent_detail)+ self.agent_detail = agent_detail+ self.user_detail = user_detail+++def screen_recording_state() -> PermissionState:+ """The live Screen Recording state. Silent: it never shows a dialog."""+ from jarvis.platform.permissions import get_system_permission_port # noqa: PLC0415++ return get_system_permission_port().state(PermissionId.SCREEN_RECORDING)+++def state_allows_capture(state: PermissionState) -> bool:+ """Whether a state lets a capture proceed: GRANTED, or not required off macOS."""+ return state in _READY+++def _request_and_check() -> bool:+ from jarvis.platform.permissions import get_system_permission_port # noqa: PLC0415++ port = get_system_permission_port()+ if port.runtime_access_granted(PermissionId.SCREEN_RECORDING):+ return True+ operation = port.request(PermissionId.SCREEN_RECORDING)+ if not operation.ok:+ log.info("screen-access: Screen Recording request not performed (%s)", operation.message)+ return port.runtime_access_granted(PermissionId.SCREEN_RECORDING)+++async def require_screen_recording_async(feature: str) -> None:+ """Ask macOS for Screen Recording once, for a capture the user started.++ Raises :class:`ScreenCaptureRefused` unless the grant is live afterwards.+ ``feature`` names the caller in the log only.+ """+ if state_allows_capture(await asyncio.to_thread(screen_recording_state)):+ return+ if await asyncio.to_thread(_request_and_check):+ return+ log.info("screen-access: %s refused, Screen Recording is not granted", feature)+ raise ScreenCaptureRefused()+++__all__ = [+ "ScreenCaptureRefused",+ "require_screen_recording_async",+ "screen_recording_state",+ "state_allows_capture",+]diff --git a/tests/unit/appshot/test_recording_permission.py b/tests/unit/appshot/test_recording_permission.pynew file mode 100644index 0000000000..c8d0e9baa1--- /dev/null+++ b/tests/unit/appshot/test_recording_permission.py@@ -0,0 +1,95 @@+"""The screen recorder's macOS Screen Recording gate (jarvis.platform.screen_access)."""++from __future__ import annotations++import sys+from types import SimpleNamespace++import pytest++from jarvis.platform import permissions, screen_access+from jarvis.platform.permissions import PermissionId, PermissionState+++class FakePort:+ def __init__(self, state: PermissionState, *, grant_on_request: bool = False) -> None:+ self._state = state+ self.grant_on_request = grant_on_request+ self.requested: list[PermissionId] = []++ def state(self, permission_id: PermissionId) -> PermissionState:+ assert permission_id is PermissionId.SCREEN_RECORDING+ return self._state++ def runtime_access_granted(self, _permission_id: PermissionId) -> bool:+ return self._state is PermissionState.GRANTED++ def request(self, permission_id: PermissionId) -> SimpleNamespace:+ self.requested.append(permission_id)+ if self.grant_on_request:+ self._state = PermissionState.GRANTED+ return SimpleNamespace(ok=True, message="asked")+++def port(monkeypatch: pytest.MonkeyPatch):+ def use(state: PermissionState, **kwargs) -> FakePort:+ fake = FakePort(state, **kwargs)+ monkeypatch.setattr(permissions, "get_system_permission_port", lambda: fake)+ return fake++ return use+++ ("state", "allowed"),+ [+ (PermissionState.GRANTED, True),+ (PermissionState.NOT_REQUIRED, True),+ (PermissionState.DENIED, False),+ (PermissionState.NOT_DETERMINED, False),+ (PermissionState.UNAVAILABLE, False),+ ],+)+def test_only_a_live_grant_lets_a_capture_run(port, state: PermissionState, allowed: bool) -> None:+ port(state)+ assert screen_access.state_allows_capture(screen_access.screen_recording_state()) is allowed+++async def test_a_granted_recording_starts_without_asking(port) -> None:+ fake = port(PermissionState.GRANTED)+ await screen_access.require_screen_recording_async("appshot")+ assert fake.requested == []+++async def test_starting_a_recording_asks_macos_once(port) -> None:+ fake = port(PermissionState.NOT_DETERMINED, grant_on_request=True)+ await screen_access.require_screen_recording_async("appshot")+ assert fake.requested == [PermissionId.SCREEN_RECORDING]+++async def test_a_refused_grant_names_the_permission(port) -> None:+ port(PermissionState.DENIED)+ with pytest.raises(screen_access.ScreenCaptureRefused) as refused:+ await screen_access.require_screen_recording_async("appshot")+ assert "Screen Recording" in refused.value.user_detail+ assert str(refused.value).startswith("[permission_needed:screen_recording]")+++def test_the_recording_status_on_a_mac_without_the_grant(+ monkeypatch: pytest.MonkeyPatch, port+) -> None:+ """The status route on macOS: an honest refusal, never an import error."""+ pytest.importorskip("PySide6.QtMultimedia")+ pytest.importorskip("av")+ from jarvis.appshot import recording++ port(PermissionState.DENIED)+ monkeypatch.setattr(sys, "platform", "darwin")+ monkeypatch.setattr("jarvis.platform.probes.display_present", lambda: True)++ status = recording.capability()++ assert status["available"] is False+ assert status["permission_required"] is True+ assert "Screen Recording" in status["detail"]