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(cu): address the numpad on macOS and Linux
rubenluetke10-beepd3c750124c54
diff --git a/jarvis/cu/actuate/posix.py b/jarvis/cu/actuate/posix.pyindex 4f518f91e1..86846f4dba 100644--- a/jarvis/cu/actuate/posix.py+++ b/jarvis/cu/actuate/posix.py@@ -34,6 +34,35 @@ _NO_BACKEND_MSG = ()+# The numpad, which pynput's ``Key`` enum does not model at all — it has no+# member for a keypad digit or operator on any platform. They are addressed by+# raw virtual key instead, which pynput passes straight to the OS+# (``CGEventCreateKeyboardEvent`` on macOS, an XTest keysym on X11).+#+# Why this exists: ``base._NAMED_KEYS`` — the ONE vocabulary the tool boundary+# validates against — accepts ``numpad0``-``numpad9`` plus the five operators,+# and the Windows backend maps every one of them (``windows.py`` VK 0x60-0x6F).+# Without this table the identical Computer-Use action that works on Windows+# died on macOS and Linux with ``ValueError: Unknown key: 'numpad5'``.+#+# macOS: Carbon ``kVK_ANSI_Keypad*`` codes. Linux/X11: the ``XK_KP_*`` keysyms.+_MACOS_NUMPAD_VK: dict[str, int] = {+ "numpad0": 0x52, "numpad1": 0x53, "numpad2": 0x54, "numpad3": 0x55,+ "numpad4": 0x56, "numpad5": 0x57, "numpad6": 0x58, "numpad7": 0x59,+ "numpad8": 0x5B, "numpad9": 0x5C,+ "multiply": 0x43, "add": 0x45, "subtract": 0x4E,+ "decimal": 0x41, "divide": 0x4B,+}++_X11_NUMPAD_KEYSYM: dict[str, int] = {+ "numpad0": 0xFFB0, "numpad1": 0xFFB1, "numpad2": 0xFFB2, "numpad3": 0xFFB3,+ "numpad4": 0xFFB4, "numpad5": 0xFFB5, "numpad6": 0xFFB6, "numpad7": 0xFFB7,+ "numpad8": 0xFFB8, "numpad9": 0xFFB9,+ "multiply": 0xFFAA, "add": 0xFFAB, "subtract": 0xFFAD,+ "decimal": 0xFFAE, "divide": 0xFFAF,+}++def _pynput_key_table(keyboard: Any) -> dict[str, Any]:"""Map the CU key vocabulary onto pynput ``Key`` members.@@ -68,6 +97,19 @@ def _pynput_key_table(keyboard: Any) -> dict[str, Any]:target = getattr(key, member, None)if target is not None:table[alias] = target++ # The numpad, by raw virtual key (see the tables above). Guarded on+ # ``from_vk`` rather than assumed: an old pynput without it must drop the+ # numpad from the table and produce the clean "Unknown key" error, never an+ # AttributeError from inside an actuation.+ from_vk = getattr(getattr(keyboard, "KeyCode", None), "from_vk", None)+ if callable(from_vk):+ numpad = _MACOS_NUMPAD_VK if sys.platform == "darwin" else _X11_NUMPAD_KEYSYM+ for alias, vk in numpad.items():+ try:+ table[alias] = from_vk(vk)+ except Exception: # noqa: BLE001 — one unsupported key, not the table+ logger.debug("pynput cannot address %s by vk", alias, exc_info=True)return table@@ -300,6 +342,11 @@ class PosixActuator(Actuator):mapped.append("command" if sys.platform == "darwin" else "winleft")elif normalized == "option":mapped.append("alt")+ elif normalized in _MACOS_NUMPAD_VK and normalized.startswith("numpad"):+ # pyautogui spells the keypad digits "num0".."num9"; its+ # operator names (add/subtract/multiply/divide/decimal)+ # already match ours.+ mapped.append("num" + normalized[6:])else:mapped.append(normalized)self._pyautogui.hotkey(*mapped)diff --git a/tests/unit/cu/test_actuate.py b/tests/unit/cu/test_actuate.pyindex 26d6fd0bed..59e7a8653d 100644--- a/tests/unit/cu/test_actuate.py+++ b/tests/unit/cu/test_actuate.py@@ -487,6 +487,65 @@ def test_pynput_key_table_maps_core_vocabulary():assert "win" in table+class _FakePynputKeyboard:+ """Stand-in for ``pynput.keyboard`` — the ``Key`` members plus ``from_vk``.++ Deliberately NOT ``importorskip``: this asserts a cross-OS vocabulary+ contract, so it has to run on the machines that break it. pynput is a+ desktop extra and is absent on this dev box and on headless CI, which is+ exactly where a macOS/Linux gap would otherwise sail through unchecked.+ Only the surface ``_pynput_key_table`` touches is modelled.+ """++ class Key:+ pass++ class KeyCode:+ def __init__(self, vk: int) -> None:+ self.vk = vk++ @classmethod+ def from_vk(cls, vk: int) -> _FakePynputKeyboard.KeyCode:+ return cls(vk)++ def __init__(self) -> None:+ # Every ``Key`` member the real pynput exposes on macOS/X11 and that+ # `_pynput_key_table` looks up by name.+ for member in (+ "ctrl", "shift", "alt", "cmd", "esc", "enter", "tab", "space",+ "backspace", "delete", "insert", "home", "end", "page_up",+ "page_down", "left", "up", "right", "down", "caps_lock",+ *(f"f{i}" for i in range(1, 21)),+ ):+ setattr(self.Key, member, f"<Key.{member}>")+++def test_pynput_key_table_covers_the_shared_key_vocabulary(monkeypatch):+ """macOS/Linux must address every key the tool boundary accepts.++ ``base._NAMED_KEYS`` is the ONE vocabulary a Computer-Use action is+ validated against, and the Windows backend maps all of it (VK 0x60-0x6F+ for the numpad alone). The POSIX table had no entry for a single numpad+ key, so an action that ran on Windows failed on a Mac with+ ``ValueError: Unknown key: 'numpad5'`` — the same "offered everywhere,+ works on one OS" defect the keybind picker had.+ """+ from jarvis.cu.actuate.base import _NAMED_KEYS+ from jarvis.cu.actuate.posix import _pynput_key_table++ # Modifier side-variants are Windows spellings of keys the table already+ # carries generically; pynput models no separate member for them.+ windows_only = {"lwin", "rwin", "windows", "menu"}++ for platform in ("darwin", "linux"):+ monkeypatch.setattr(sys, "platform", platform)+ table = _pynput_key_table(_FakePynputKeyboard())+ missing = sorted(_NAMED_KEYS - windows_only - set(table))+ assert not missing, (+ f"on {platform}: accepted by the tool boundary, unusable: {missing}"+ )++def test_macos_cursor_readback_uses_quartz_global_coordinates(monkeypatch):from jarvis.cu.actuate.posix import PosixActuator