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(computer-use): size SendInput INPUT struct correctly so typing works on every site
Ruben Lütkef5564bb05b73
diff --git a/jarvis/plugins/tool/type_text.py b/jarvis/plugins/tool/type_text.pyindex e7d4e68b28..66433b325d 100644--- a/jarvis/plugins/tool/type_text.py+++ b/jarvis/plugins/tool/type_text.py@@ -20,17 +20,23 @@ from jarvis.core.protocols import ExecutionContext, ToolResultlog = logging.getLogger(__name__)-def _send_text_windows(text: str, delay_s: float) -> None:- """Sendet Unicode-Text an das aktive Windows-Fenster via SendInput."""- if os.name != "nt":- raise RuntimeError("Native Text-Eingabe ohne pyautogui ist nur auf Windows verfuegbar")-+def _build_windows_input_types() -> Any:+ """Build the ctypes structs for SendInput keyboard injection.++ The ``INPUT`` union MUST be sized to its LARGEST member (``MOUSEINPUT``) so+ that ``sizeof(INPUT)`` matches the size Windows expects for ``cbSize``. A+ union that declares only ``ki`` (``KEYBDINPUT``) is too small (32 vs 40 bytes+ on x64), which makes ``SendInput`` reject every call with+ ``ERROR_INVALID_PARAMETER`` ("Falscher Parameter"); every keystroke then+ silently falls back to pyautogui's layout-dependent path, which does not+ register in web inputs (Google-Flights typing bug, 2026-06-22).++ Lazily imported so the module still imports on non-Windows hosts.+ """import ctypesfrom ctypes import wintypes+ from types import SimpleNamespace- INPUT_KEYBOARD = 1- KEYEVENTF_KEYUP = 0x0002- KEYEVENTF_UNICODE = 0x0004ULONG_PTR = wintypes.WPARAMclass KEYBDINPUT(ctypes.Structure):@@ -42,34 +48,72 @@ def _send_text_windows(text: str, delay_s: float) -> None:("dwExtraInfo", ULONG_PTR),)+ class MOUSEINPUT(ctypes.Structure):+ _fields_ = (+ ("dx", wintypes.LONG),+ ("dy", wintypes.LONG),+ ("mouseData", wintypes.DWORD),+ ("dwFlags", wintypes.DWORD),+ ("time", wintypes.DWORD),+ ("dwExtraInfo", ULONG_PTR),+ )+class INPUT_UNION(ctypes.Union):- _fields_ = (("ki", KEYBDINPUT),)+ # MOUSEINPUT is the LARGEST member and MUST be present: it sizes the+ # union (and therefore INPUT.cbSize) to what Windows expects. Omitting+ # it undersizes INPUT and SendInput rejects every call (see docstring).+ _fields_ = (("mi", MOUSEINPUT), ("ki", KEYBDINPUT))class INPUT(ctypes.Structure):_fields_ = (("type", wintypes.DWORD), ("union", INPUT_UNION))- send_input = ctypes.windll.user32.SendInput- send_input.argtypes = (wintypes.UINT, ctypes.POINTER(INPUT), ctypes.c_int)- send_input.restype = wintypes.UINT+ return SimpleNamespace(+ KEYBDINPUT=KEYBDINPUT,+ MOUSEINPUT=MOUSEINPUT,+ INPUT_UNION=INPUT_UNION,+ INPUT=INPUT,+ INPUT_KEYBOARD=1,+ KEYEVENTF_KEYUP=0x0002,+ KEYEVENTF_UNICODE=0x0004,+ ULONG_PTR=ULONG_PTR,+ )+++def _send_text_windows(text: str, delay_s: float) -> None:+ """Sendet Unicode-Text an das aktive Windows-Fenster via SendInput."""+ if os.name != "nt":+ raise RuntimeError("Native Text-Eingabe ohne pyautogui ist nur auf Windows verfuegbar")++ import ctypes++ t = _build_windows_input_types()+ INPUT, KEYBDINPUT, INPUT_UNION = t.INPUT, t.KEYBDINPUT, t.INPUT_UNION++ # use_last_error=True so ``ctypes.get_last_error()`` reflects SendInput's real+ # Win32 error (ctypes.windll does NOT track it -> misleading error codes).+ user32 = ctypes.WinDLL("user32", use_last_error=True)+ send_input = user32.SendInput+ send_input.argtypes = (ctypes.c_uint, ctypes.POINTER(INPUT), ctypes.c_int)+ send_input.restype = ctypes.c_uintfor char in text:code = ord(char)events = (INPUT * 2)(INPUT(- type=INPUT_KEYBOARD,+ type=t.INPUT_KEYBOARD,union=INPUT_UNION(- ki=KEYBDINPUT(0, code, KEYEVENTF_UNICODE, 0, ULONG_PTR(0)),+ ki=KEYBDINPUT(0, code, t.KEYEVENTF_UNICODE, 0, t.ULONG_PTR(0)),),),INPUT(- type=INPUT_KEYBOARD,+ type=t.INPUT_KEYBOARD,union=INPUT_UNION(ki=KEYBDINPUT(0,code,- KEYEVENTF_UNICODE | KEYEVENTF_KEYUP,+ t.KEYEVENTF_UNICODE | t.KEYEVENTF_KEYUP,0,- ULONG_PTR(0),+ t.ULONG_PTR(0),),),),diff --git a/tests/unit/plugins/tool/test_type_text.py b/tests/unit/plugins/tool/test_type_text.pyindex 93564eaa18..6f07def9e1 100644--- a/tests/unit/plugins/tool/test_type_text.py+++ b/tests/unit/plugins/tool/test_type_text.py@@ -8,12 +8,22 @@ fallback when the native path fails (and the primary on non-Windows)."""from __future__ import annotations+import ctypesimport sysimport types+import pytest+from jarvis.plugins.tool import type_text as ttfrom jarvis.plugins.tool.type_text import TypeTextTool+try: # ``ctypes.wintypes`` is importable cross-platform, but guard for safety.+ from ctypes import wintypes as _wt # noqa: F401++ _HAS_WINTYPES = True+except Exception: # pragma: no cover - exotic builds without wintypes+ _HAS_WINTYPES = False+class _Ctx:user_utterance = "type hello"@@ -66,3 +76,30 @@ async def test_windows_falls_back_to_pyautogui_when_native_fails(monkeypatch):async def test_empty_text_is_rejected(monkeypatch):res = await TypeTextTool().execute({"text": ""}, _Ctx())assert res.success is False+++# ---------------------------------------------------------------------------+# RC#1 regression (Google-Flights typing bug, 2026-06-22): the SendInput INPUT+# union must be sized to its LARGEST member (MOUSEINPUT). If it only carries+# ``ki`` (KEYBDINPUT) the struct is too small (32 vs 40 bytes on x64), Windows+# rejects every keystroke with ERROR_INVALID_PARAMETER ("Falscher Parameter"),+# and typing silently degrades to the layout-dependent pyautogui fallback that+# does not register in web inputs ("typed into the right field, nothing+# appeared").+# ---------------------------------------------------------------------------++[email protected](not _HAS_WINTYPES, reason="ctypes.wintypes unavailable")+def test_input_union_is_sized_to_largest_member():+ t = tt._build_windows_input_types()+ # MOUSEINPUT is larger than KEYBDINPUT, so a union that omits it is undersized.+ assert ctypes.sizeof(t.MOUSEINPUT) > ctypes.sizeof(t.KEYBDINPUT)+ # The union (and therefore INPUT.cbSize) must match the largest member.+ assert ctypes.sizeof(t.INPUT_UNION) == ctypes.sizeof(t.MOUSEINPUT)++[email protected](not _HAS_WINTYPES, reason="ctypes.wintypes unavailable")+def test_input_struct_size_matches_windows_cbsize():+ t = tt._build_windows_input_types()+ expected = 40 if ctypes.sizeof(ctypes.c_void_p) == 8 else 28+ assert ctypes.sizeof(t.INPUT) == expected