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.

fix(permissions): dead macOS Allow buttons for Input Monitoring and Input Control

Ruben Lütke73122c25aced
diff --git a/jarvis/platform/permissions.py b/jarvis/platform/permissions.py
index 59260872ca..add8d311a2 100644
--- a/jarvis/platform/permissions.py
+++ b/jarvis/platform/permissions.py
@@ -87,6 +87,37 @@ _SETTINGS_URLS: dict[PermissionId, str] = {
),
}
+# IOKit HID access constants (IOHIDCheckAccess, macOS 10.15+). The header
+# declares both enums as CF_ENUM(uint64_t); the raw values are stable ABI.
+_IOHID_REQUEST_POST_EVENT = 0 # kIOHIDRequestTypePostEvent
+_IOHID_REQUEST_LISTEN_EVENT = 1 # kIOHIDRequestTypeListenEvent
+_IOHID_ACCESS_STATES: dict[int, PermissionState] = {
+ 0: PermissionState.GRANTED, # kIOHIDAccessTypeGranted
+ 1: PermissionState.DENIED, # kIOHIDAccessTypeDenied
+ 2: PermissionState.NOT_DETERMINED, # kIOHIDAccessTypeUnknown
+}
+
+
+def _default_iohid_check(request_type: int) -> int | None:
+ """Query IOKit's tri-state HID access check; ``None`` when unavailable.
+
+ macOS shows the Input Monitoring / event-posting prompt only while the
+ TCC state is still undetermined. The boolean ``CGPreflight*`` calls fold
+ "never asked" and "denied" into one value, so only this tri-state probe
+ lets the UI know when a request would silently do nothing.
+ """
+ try:
+ import ctypes
+
+ iokit = ctypes.CDLL("/System/Library/Frameworks/IOKit.framework/IOKit")
+ check = iokit.IOHIDCheckAccess
+ check.restype = ctypes.c_uint64
+ check.argtypes = [ctypes.c_uint64]
+ return int(check(request_type))
+ except Exception: # noqa: BLE001 - a missing native bridge falls back
+ return None
+
+
_READY_STATES = frozenset({PermissionState.GRANTED, PermissionState.NOT_REQUIRED})
_RESTART_AFTER_CHANGE = frozenset(
{
@@ -151,9 +182,11 @@ class SystemPermissionPort:
*,
platform_name: PlatformName | None = None,
module_loader: Callable[[str], Any] = importlib.import_module,
+ iohid_check: Callable[[int], int | None] = _default_iohid_check,
) -> None:
self._platform_name = platform_name
self._module_loader = module_loader
+ self._iohid_check = iohid_check
# This is operation state, not a cached permission probe. The set lives
# only for the current process and therefore clears exactly when the
# required app restart has happened.
@@ -208,11 +241,7 @@ class SystemPermissionPort:
canonical_path = Path(bundle_path).resolve() == expected_path.resolve()
except (OSError, ValueError):
canonical_path = False
- stable = (
- bundle_id == EXPECTED_BUNDLE_ID
- and launched_as_bundle
- and canonical_path
- )
+ stable = bundle_id == EXPECTED_BUNDLE_ID and launched_as_bundle and canonical_path
foreground = False
headless = True
appkit = self._load("AppKit")
@@ -271,6 +300,16 @@ class SystemPermissionPort:
except Exception: # noqa: BLE001 - native probes never crash callers
return PermissionState.UNAVAILABLE
+ def _iohid_state(self, request_type: int) -> PermissionState | None:
+ """Tri-state TCC probe that separates "denied" from "not asked yet"."""
+ try:
+ raw = self._iohid_check(request_type)
+ except Exception: # noqa: BLE001 - native probes never crash callers
+ return None
+ if raw is None:
+ return None
+ return _IOHID_ACCESS_STATES.get(int(raw))
+
def _state(self, permission_id: PermissionId) -> PermissionState:
if self.platform != "darwin":
return PermissionState.NOT_REQUIRED
@@ -281,13 +320,30 @@ class SystemPermissionPort:
if permission_id is PermissionId.ACCESSIBILITY:
return self._boolean_state("ApplicationServices", "AXIsProcessTrusted")
if permission_id is PermissionId.INPUT_MONITORING:
+ # macOS shows the Input Monitoring prompt only while the state is
+ # still undetermined (an app that ever created an event listener
+ # is auto-registered as denied). Without the tri-state the UI
+ # offers a request that would silently do nothing.
+ state = self._iohid_state(_IOHID_REQUEST_LISTEN_EVENT)
+ if state is not None:
+ return state
return self._boolean_state("Quartz", "CGPreflightListenEventAccess")
+ # Event posting: the Accessibility grant authorizes posting input
+ # events on macOS and there is no second prompt for it. AX reads the
+ # live TCC value, unlike the CGPreflight result that is frozen per
+ # process, so a mid-session Accessibility grant flips this row too.
+ ax_state = self._boolean_state("ApplicationServices", "AXIsProcessTrusted")
+ if ax_state is PermissionState.GRANTED:
+ return PermissionState.GRANTED
+ state = self._iohid_state(_IOHID_REQUEST_POST_EVENT)
+ if state is not None:
+ return state
quartz = self._load("Quartz")
if callable(getattr(quartz, "CGPreflightPostEventAccess", None)):
return self._boolean_state("Quartz", "CGPreflightPostEventAccess")
# Older supported macOS releases protect CGEvent posting through the
# Accessibility grant and do not expose the separate PostEvent API.
- return self._boolean_state("ApplicationServices", "AXIsProcessTrusted")
+ return ax_state
def state(self, permission_id: PermissionId | str) -> PermissionState:
"""Probe one permission directly without constructing a full snapshot."""
@@ -312,8 +368,7 @@ class SystemPermissionPort:
return all(self._state(item) in _READY_STATES for item in requirements)
identity, _headless = self._app_identity()
return identity.stable and all(
- item not in self._restart_required
- and self._state(item) is PermissionState.GRANTED
+ item not in self._restart_required and self._state(item) is PermissionState.GRANTED
for item in requirements
)
@@ -403,8 +458,7 @@ class SystemPermissionPort:
]
identity_ready = self.platform != "darwin" or identity.stable
restart_required = any(
- permission_id in self._restart_required
- for permission_id in requirements
+ permission_id in self._restart_required for permission_id in requirements
)
features[feature] = {
"ready": not missing and identity_ready and not restart_required,
@@ -541,6 +595,7 @@ class SystemPermissionPort:
),
after,
)
+
def _open_settings(self, permission_id: PermissionId) -> bool:
appkit = self._load("AppKit")
foundation = self._load("Foundation")
@@ -596,9 +651,7 @@ class SystemPermissionPort:
"System Settings opened. Restart Personal Jarvis after changing access."
if restart
else (
- "System Settings opened."
- if opened
- else "System Settings could not be opened."
+ "System Settings opened." if opened else "System Settings could not be opened."
)
),
after,
diff --git a/jarvis/ui/web/frontend/src/components/ToastLayer.tsx b/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
index 56f93392b5..92c74d3ed1 100644
--- a/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
+++ b/jarvis/ui/web/frontend/src/components/ToastLayer.tsx
@@ -41,7 +41,10 @@ export function ToastLayer() {
const dismiss = useEventStore((s) => s.dismissToast);
return (
- <div className="pointer-events-none fixed right-4 top-4 z-50 flex w-[320px] flex-col gap-2">
+ // z-[60]: the onboarding gate overlays the whole app at z-50 and renders
+ // later in the DOM; toasts (e.g. failed permission requests during
+ // first-run setup) must stay visible above it.
+ <div className="pointer-events-none fixed right-4 top-4 z-[60] flex w-[320px] flex-col gap-2">
{toasts.map((toast) => {
const Icon = ICON_FOR_KIND[toast.kind];
// A saved-file toast in the desktop shell is a native drag handle: press
diff --git a/tests/unit/platform/test_permissions.py b/tests/unit/platform/test_permissions.py
index e87f9fb659..57af4a8f9e 100644
--- a/tests/unit/platform/test_permissions.py
+++ b/tests/unit/platform/test_permissions.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+from collections.abc import Callable
from pathlib import Path
from types import SimpleNamespace
@@ -128,13 +129,18 @@ def _native_modules(
return modules, screen, workspace
-def _port(modules: dict[str, object]) -> SystemPermissionPort:
+def _port(
+ modules: dict[str, object],
+ iohid_check: Callable[[int], int | None] = lambda _type: None,
+) -> SystemPermissionPort:
def load(name: str) -> object:
if name not in modules:
raise ModuleNotFoundError(name)
return modules[name]
- return SystemPermissionPort(platform_name="darwin", module_loader=load)
+ # iohid_check defaults to "unavailable" so unit runs stay hermetic even on
+ # a real Mac, where the default probe would read the machine's TCC state.
+ return SystemPermissionPort(platform_name="darwin", module_loader=load, iohid_check=iohid_check)
def _permission(snapshot: dict, permission_id: PermissionId) -> dict:
@@ -151,9 +157,7 @@ def test_matching_bundle_id_at_noncanonical_path_is_not_stable(tmp_path: Path) -
bundleIdentifier=lambda: EXPECTED_BUNDLE_ID,
bundlePath=lambda: str(tmp_path / "Personal Jarvis.app"),
)
- modules["Foundation"].NSBundle = SimpleNamespace(
- mainBundle=lambda: copied_bundle
- )
+ modules["Foundation"].NSBundle = SimpleNamespace(mainBundle=lambda: copied_bundle)
assert _port(modules).snapshot()["app_identity"]["stable"] is False
@@ -188,9 +192,11 @@ def test_snapshot_maps_native_states_and_feature_readiness() -> None:
"identity_ready": True,
"restart_required": False,
}
+ # event_posting is granted through the trusted Accessibility fixture, so
+ # only the screen-recording grant is still missing for Computer-Use.
assert snapshot["features"]["computer_use"] == {
"ready": False,
- "missing": ["screen_recording", "event_posting"],
+ "missing": ["screen_recording"],
"identity_ready": True,
"restart_required": False,
}
@@ -227,10 +233,7 @@ def test_runtime_access_requires_stable_identity_and_fresh_grant() -> None:
unstable_modules, _, _ = _native_modules(bundle_id="org.python.python")
assert stable.runtime_access_granted(PermissionId.MICROPHONE) is True
- assert (
- _port(unstable_modules).runtime_access_granted(PermissionId.MICROPHONE)
- is False
- )
+ assert _port(unstable_modules).runtime_access_granted(PermissionId.MICROPHONE) is False
_CaptureDevice.status = 2
assert stable.runtime_access_granted(PermissionId.MICROPHONE) is False
@@ -330,6 +333,13 @@ def test_request_event_permissions_use_coregraphics(
modules, _, _ = _native_modules()
calls: list[str] = []
setattr(modules["Quartz"], request_name, lambda: calls.append(request_name))
+ # Untrusted Accessibility keeps event_posting requestable: a trusted AX
+ # grant already implies event posting and would short-circuit to granted.
+ modules["ApplicationServices"] = SimpleNamespace(
+ AXIsProcessTrusted=lambda: False,
+ AXIsProcessTrustedWithOptions=lambda _options: False,
+ kAXTrustedCheckOptionPrompt="prompt",
+ )
result = _port(modules).request(permission_id)
@@ -338,6 +348,68 @@ def test_request_event_permissions_use_coregraphics(
assert calls == [request_name]
+_IOHID_POST = 0 # kIOHIDRequestTypePostEvent
+_IOHID_LISTEN = 1 # kIOHIDRequestTypeListenEvent
+
+
+def test_input_monitoring_denied_hides_request_and_keeps_settings() -> None:
+ # macOS never re-prompts once the TCC state is determined; a visible
+ # "request" button would silently do nothing (the dead Allow button).
+ modules, _, _ = _native_modules()
+
+ snapshot = _port(modules, iohid_check=lambda t: 1 if t == _IOHID_LISTEN else None).snapshot()
+
+ item = _permission(snapshot, PermissionId.INPUT_MONITORING)
+ assert item["status"] == "denied"
+ assert item["can_request"] is False
+ assert item["can_open_settings"] is True
+
+
+def test_input_monitoring_not_determined_still_offers_the_prompt() -> None:
+ modules, _, _ = _native_modules()
+
+ snapshot = _port(modules, iohid_check=lambda t: 2 if t == _IOHID_LISTEN else None).snapshot()
+
+ item = _permission(snapshot, PermissionId.INPUT_MONITORING)
+ assert item["status"] == "not_determined"
+ assert item["can_request"] is True
+
+
+def test_input_monitoring_falls_back_to_boolean_preflight_without_iohid() -> None:
+ modules, _, _ = _native_modules()
+
+ item = _permission(_port(modules).snapshot(), PermissionId.INPUT_MONITORING)
+
+ assert item["status"] == "not_granted"
+
+
+def test_event_posting_follows_live_accessibility_grant() -> None:
+ # The Accessibility grant authorizes event posting and updates live; it
+ # must win over a stale per-process HID verdict so the row flips as soon
+ # as the user grants Accessibility.
+ modules, _, _ = _native_modules()
+
+ snapshot = _port(modules, iohid_check=lambda _t: 1).snapshot()
+
+ assert _permission(snapshot, PermissionId.EVENT_POSTING)["status"] == "granted"
+
+
+def test_event_posting_tristate_when_accessibility_untrusted() -> None:
+ modules, _, _ = _native_modules()
+ modules["ApplicationServices"] = SimpleNamespace(
+ AXIsProcessTrusted=lambda: False,
+ AXIsProcessTrustedWithOptions=lambda _options: False,
+ kAXTrustedCheckOptionPrompt="prompt",
+ )
+
+ snapshot = _port(modules, iohid_check=lambda t: 1 if t == _IOHID_POST else None).snapshot()
+
+ item = _permission(snapshot, PermissionId.EVENT_POSTING)
+ assert item["status"] == "denied"
+ assert item["can_request"] is False
+ assert item["can_open_settings"] is True
+
+
def test_legacy_macos_event_posting_falls_back_to_accessibility_prompt() -> None:
modules, _, _ = _native_modules()
delattr(modules["Quartz"], "CGPreflightPostEventAccess")
@@ -406,7 +478,11 @@ def test_broken_native_bridge_import_fails_closed() -> None:
def broken_loader(_name: str) -> object:
raise OSError("incompatible native framework")
- port = SystemPermissionPort(platform_name="darwin", module_loader=broken_loader)
+ port = SystemPermissionPort(
+ platform_name="darwin",
+ module_loader=broken_loader,
+ iohid_check=lambda _type: None,
+ )
snapshot = port.snapshot()