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(keybinds): route the collision + mouse checks through their real gates
Ruben Lütke020771a2f3e2
diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.pyindex 568992f254..ee8f1a27aa 100644--- a/jarvis/ui/web/settings_routes.py+++ b/jarvis/ui/web/settings_routes.py@@ -1263,27 +1263,25 @@ _KEYBIND_SUGGESTIONS = []-def _combo_keys(combo: str) -> set[str]:- """The key SET of a combo — the unit the collision rule compares."""- return {p.strip() for p in str(combo or "").strip().lower().split("+") if p.strip()}--def _available_suggestions(bound: dict[str, str]) -> list[str]:"""Quick-picks minus everything that would be rejected on save.- The collision rule refuses a combo whose key set is a subset or superset of- another action's. Offering such a chord as a one-click suggestion is a- guaranteed 400 the moment the user clicks it, so it is filtered out here- instead — the server owns the rule, so the server owns the list.+ The collision rule lives in ONE place —+ ``jarvis.trigger.hotkey.combos_collide`` — and this list must be filtered+ by exactly that function, never by a hand-rolled token comparison. A raw+ token comparison here would leave a quick-pick in the list that the save+ route then refuses (``ctrl+left_alt+…`` and ``ctrl+right_alt+…`` are the+ same registration), which is a guaranteed 400 the moment the user clicks+ it. The server owns the rule, so the server owns the list."""- taken = [_combo_keys(c) for c in bound.values() if c and c.strip()]- out: list[str] = []- for suggestion in _KEYBIND_SUGGESTIONS:- keys = _combo_keys(suggestion)- if any(keys <= other or other <= keys for other in taken):- continue- out.append(suggestion)- return out+ from jarvis.trigger.hotkey import combos_collide++ taken = [c for c in bound.values() if c and c.strip()]+ return [+ suggestion+ for suggestion in _KEYBIND_SUGGESTIONS+ if not any(combos_collide(suggestion, other) for other in taken)+ ]# ---------------------------------------------------------------------------@@ -1326,6 +1324,7 @@ class KeybindBody(BaseModel):async def get_keybinds(request: Request) -> dict[str, object]:from jarvis.core.config import TriggerConfigfrom jarvis.core.config_writer import KEYBIND_TOML_KEY+ from jarvis.trigger.hotkey import mouse_hotkeys_availablecfg = _config(request)trig = getattr(cfg, "trigger", None) if cfg is not None else None@@ -1335,6 +1334,13 @@ async def get_keybinds(request: Request) -> dict[str, object]:pipeline = getattr(request.app.state, "speech_pipeline", None)restart_required = pipeline is None or not hasattr(pipeline, "set_keybinds")current = _keybind_values(trig)+ # Can THIS host fire a mouse-button shortcut at all? Asked of the one+ # capability probe, never of a platform name (AP-21/AP-23): it is false on+ # Wayland, on macOS without pyobjc Quartz and on Linux without the opt-in+ # pynput extra. Without this field the picker offered mouse buttons+ # everywhere and they silently never fired on those hosts; with it the UI+ # hides the cluster and prints the probe's own English sentence.+ mouse_ok, mouse_reason = mouse_hotkeys_available()return {"keybinds": current,# DERIVED, never a hand-written dict. A literal map here is the AP-4@@ -1345,6 +1351,7 @@ async def get_keybinds(request: Request) -> dict[str, object]:action: str(getattr(d, field, "")) for action, field in KEYBIND_TOML_KEY.items()},"suggestions": _available_suggestions(current),+ "mouse_buttons": {"supported": mouse_ok, "reason": mouse_reason},"restart_required": restart_required,}@@ -1352,7 +1359,13 @@ async def get_keybinds(request: Request) -> dict[str, object]:@router.put("/keybinds")async def put_keybind(body: KeybindBody, request: Request) -> dict[str, object]:from jarvis.core.config_writer import KEYBIND_ACTIONS, KEYBIND_TOML_KEY- from jarvis.trigger.hotkey import validate_hotkey+ from jarvis.trigger.hotkey import (+ MOUSE_BUTTON_TOKENS,+ combos_collide,+ mouse_hotkeys_available,+ normalized_combo_tokens,+ validate_hotkey,+ )action = body.action.strip().lower()if action not in KEYBIND_ACTIONS:@@ -1370,32 +1383,40 @@ async def put_keybind(body: KeybindBody, request: Request) -> dict[str, object]:if not ok:raise HTTPException(status_code=400, detail=reason)- # Collision check: one chord can't both answer and hang up. Exact- # equality is not enough — the polling hotkey backend matches a combo- # as soon as its keys are down, so a key-set SUBSET of another- # action's combo fires both (call=f1 + hangup=f1+f2 → F1+F2 triggers- # call AND hangup). Reject any subset/superset relation between the- # key sets, in both directions.- new_keys = {p.strip() for p in hotkey.split("+") if p.strip()}+ # A mouse button is only offerable where the host can actually watch+ # the buttons globally. Asked of the ONE capability probe, never of a+ # platform name (AP-21/AP-23): accepting a shortcut that can never+ # fire here — Wayland, macOS without pyobjc Quartz, Linux without the+ # pynput extra — is the silent dishonesty this project refuses. The+ # tokens are read from the NORMALIZED combo so the alias spellings+ # (``mouse_back`` → ``mouse_x1``) are caught too.+ if normalized_combo_tokens(hotkey) & MOUSE_BUTTON_TOKENS:+ mouse_ok, mouse_reason = mouse_hotkeys_available()+ if not mouse_ok:+ raise HTTPException(status_code=400, detail=mouse_reason)++ # Collision check: one chord can't both answer and hang up. Delegated+ # to ``combos_collide`` — the ONE place that knows two shortcuts are+ # the same registration. Comparing RAW tokens here (what this route+ # used to do) accepted ``ctrl+left_alt+j`` alongside+ # ``ctrl+right_alt+j``: both normalize to the same chord, so the+ # second registration lost the race and that action silently never+ # fired. The rule itself is unchanged — identical sets collide, and so+ # does any subset/superset pair, because the polling backend matches a+ # combo as soon as its keys are down (call=f1 + hangup=f1+f2 → F1+F2+ # triggers both). An unbound other action never collides.for other_action, other_combo in _keybind_values(trig).items():if other_action == action:continue- other_keys = {- p.strip() for p in other_combo.strip().lower().split("+") if p.strip()- }- if not other_keys:- # The other action is itself unbound (Clear button) — an- # empty key-set is a subset of every combo, so without this- # guard EVERY save would be rejected as "overlapping" the- # moment any one action is cleared.- continue- if new_keys <= other_keys or other_keys <= new_keys:+ if combos_collide(hotkey, other_combo):raise HTTPException(status_code=400,detail=(f"'{hotkey}' overlaps with '{other_action}' "- f"('{other_combo.strip().lower()}') — pressing one would "- "trigger both. Pick keys that don't contain each other."+ f"('{other_combo.strip().lower()}') — the two end up as "+ "the same shortcut, so pressing it would trigger both "+ "(or one of them would never fire). Pick keys that "+ "don't contain each other."),)# else: hotkey == "" is an explicit "unbind this action" request (Settings@@ -1920,13 +1941,13 @@ async def restart_app(request: Request, force: bool = False) -> dict[str, objectasync def get_input_isolation() -> dict[str, object]:"""Report whether outside input software can reach this app's window.- Dictation apps (a dictation app, Voice Access, a dictation app, ...), text expanders,- clipboard managers, and password-manager auto-type all inject synthetic- keystrokes into the focused window and locate the field through the OS- accessibility tree. Windows blocks BOTH for any window owned by a- higher-integrity process — so while this app runs elevated they appear to do- nothing here while still working in every other app, with no error anywhere- (Windows does not report a UIPI drop to the sender).+ Third-party dictation and speech-to-text tools, text expanders, clipboard+ managers, and password-manager auto-type all inject synthetic keystrokes+ into the focused window and locate the field through the OS accessibility+ tree. Windows blocks BOTH for any window owned by a higher-integrity+ process — so while this app runs elevated they appear to do nothing here+ while still working in every other app, with no error anywhere (Windows+ does not report a UIPI drop to the sender).Deliberately cheap, uncached, and unauthenticated-safe: it reads only thisprocess's own privilege state, so the desktop UI can poll it on mount.diff --git a/tests/unit/ui/test_keybinds_route.py b/tests/unit/ui/test_keybinds_route.pyindex da9c533fd5..90f8e0679f 100644--- a/tests/unit/ui/test_keybinds_route.py+++ b/tests/unit/ui/test_keybinds_route.py@@ -228,6 +228,142 @@ def test_the_route_serves_every_action_even_though_settings_shows_two() -> None:assert action in body["defaults"], action+def test_put_rejects_a_left_alt_spelling_of_a_bound_right_alt_shortcut() -> None:+ """THE collision bug: the route compared RAW tokens, so two spellings of+ ONE registration both passed. ``ctrl+left_alt+k`` and ``ctrl+right_alt+k``+ normalize to the same chord (Windows cannot tell the Alt keys apart), so+ saving both left the user with two bound-looking rows, one of them silently+ dead. The route must delegate to ``combos_collide`` and refuse with a+ reason that names the other action."""+ client = _client()+ assert (+ client.put(+ "/api/settings/keybinds",+ json={"action": "hangup", "hotkey": "ctrl+right_alt+k", "persist": False},+ ).status_code+ == 200+ )++ resp = client.put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "ctrl+left_alt+k", "persist": False},+ )+ assert resp.status_code == 400+ detail = resp.json()["detail"]+ assert "hangup" in detail+ assert "ctrl+right_alt+k" in detail+++def test_put_rejects_a_super_spelling_of_a_bound_win_shortcut() -> None:+ """Same root cause, other fold: win / super / meta are one key."""+ client = _client()+ assert (+ client.put(+ "/api/settings/keybinds",+ json={"action": "hangup", "hotkey": "ctrl+win+k", "persist": False},+ ).status_code+ == 200+ )+ resp = client.put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "ctrl+super+k", "persist": False},+ )+ assert resp.status_code == 400+ assert "hangup" in resp.json()["detail"]+++def test_suggestions_are_filtered_on_the_normalized_collision_rule(monkeypatch) -> None:+ """A quick-pick that merely SPELLS a bound chord differently is still a+ guaranteed 400 on click, so it must not be offered."""+ from jarvis.ui.web import settings_routes++ monkeypatch.setattr(+ settings_routes, "_KEYBIND_SUGGESTIONS", ["ctrl+left_alt+j", "ctrl+shift+j"]+ )+ body = _client().get("/api/settings/keybinds").json()+ # dictate ships as ctrl+right_alt+j — the same registration.+ assert body["suggestions"] == ["ctrl+shift+j"]+++# ----------------------------------------------------------------------+# Mouse-button shortcuts: offered only where the host can actually fire one.+# ----------------------------------------------------------------------+++def _patch_mouse_probe(monkeypatch, supported: bool, reason: str = "") -> None:+ """Pin the capability probe so the assertions do not depend on the host."""+ from jarvis.trigger import hotkey as hotkey_mod++ monkeypatch.setattr(hotkey_mod, "mouse_hotkeys_available", lambda *a, **k: (supported, reason))+++def test_get_reports_mouse_button_support_from_the_capability_probe(monkeypatch) -> None:+ """The UI hides the mouse cluster on a host that cannot fire one; it can+ only do that if the route SERVES the probe's verdict."""+ _patch_mouse_probe(monkeypatch, True)+ body = _client().get("/api/settings/keybinds").json()+ assert body["mouse_buttons"] == {"supported": True, "reason": ""}+++def test_get_reports_an_honest_english_reason_when_mouse_is_unsupported(+ monkeypatch,+) -> None:+ _patch_mouse_probe(+ monkeypatch,+ False,+ "Wayland does not let an application watch the mouse buttons globally.",+ )+ body = _client().get("/api/settings/keybinds").json()+ assert body["mouse_buttons"]["supported"] is False+ assert "Wayland" in body["mouse_buttons"]["reason"]+++def test_put_refuses_a_mouse_shortcut_the_host_can_never_fire(monkeypatch) -> None:+ """Accepting it would leave the user with a shortcut that looks bound and+ does nothing — the exact silent dishonesty the probe exists to prevent."""+ _patch_mouse_probe(monkeypatch, False, "Mouse-button shortcuts need the pynput package.")+ resp = _client().put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "ctrl+alt+mouse_x1", "persist": False},+ )+ assert resp.status_code == 400+ assert "pynput" in resp.json()["detail"]+++def test_put_refuses_an_ALIAS_spelling_of_an_unsupported_mouse_button(+ monkeypatch,+) -> None:+ """``mouse_back`` is ``mouse_x1`` — the check reads the NORMALIZED tokens,+ so a friendlier spelling cannot walk around the probe."""+ _patch_mouse_probe(monkeypatch, False, "This system cannot watch mouse buttons.")+ resp = _client().put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "ctrl+alt+mouse_back", "persist": False},+ )+ assert resp.status_code == 400+++def test_put_accepts_a_mouse_shortcut_where_the_probe_says_it_works(monkeypatch) -> None:+ _patch_mouse_probe(monkeypatch, True)+ resp = _client().put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "ctrl+alt+mouse_x1", "persist": False},+ )+ assert resp.status_code == 200+ assert resp.json()["hotkey"] == "ctrl+alt+mouse_x1"+++def test_put_does_not_consult_the_mouse_probe_for_a_key_only_combo(monkeypatch) -> None:+ """A keyboard shortcut must stay saveable on a host without mouse support —+ the probe gates the mouse cluster, never the whole route."""+ _patch_mouse_probe(monkeypatch, False, "No global mouse buttons here.")+ resp = _client().put(+ "/api/settings/keybinds",+ json={"action": "call", "hotkey": "f7+f8", "persist": False},+ )+ assert resp.status_code == 200++def test_retired_ptt_hotkey_route_is_not_mounted() -> None:assert _client().get("/api/settings/ptt-hotkey").status_code == 404