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(brain): a knowledge question can no longer launch Computer Use — deterministic explicit-desktop gate (BUG-107)
Personal Jarvis Maintainerb3bfa9c331bf
diff --git a/jarvis/brain/cu_gate.py b/jarvis/brain/cu_gate.pynew file mode 100644index 0000000000..4ae988c75e--- /dev/null+++ b/jarvis/brain/cu_gate.py@@ -0,0 +1,161 @@+"""Deterministic explicit-desktop gate for LLM-chosen computer_use calls.++Live incident 2026-07-21 11:36 (voice session 06a65611): the user asked a pure+knowledge question — "braucht die Golf 100 Start- und # i18n-allow: forensic quote+Landebahn" (what runway does the Gulfstream G100 need) # i18n-allow: quote cont.+— the realtime layer correctly delegated the turn to the router brain, and the+router brain then called ``computer_use``: it physically opened Safari on the+user's screen and typed "Gulfstream G100 runway requirements" into Google.+A web lookup the tool model can do invisibly (own knowledge or ``search_web``)+hijacked the user's live desktop for ~35 seconds.++This is the spawn-gate lesson applied to the desktop (see+``jarvis/brain/spawn_gate.py``, maintainer mandate 2026-07-18): a tool+description is advice, not enforcement. This module is the enforcement. An+LLM-initiated ``computer_use`` call executes ONLY when one of these holds:++1. The CURRENT user turn explicitly names the desktop vehicle — an on-screen+ action verb ("open", "click", "type", "scroll", ...) or a screen/app/+ browser noun ("Chrome", "terminal", "Bildschirm", # i18n-allow: vocab token+ ...), in any supported language. Matching *input vocabulary*, not prose —+ deliberately word-based, mirroring the spawn gate.+2. The conversation is still inside a desktop episode: a Computer-Use mission+ is active or finished within the follow-up window+ (``cu_run_registry.has_recent_run``). This keeps the BUG-105 corrective+ follow-ups alive ("try again", "do it in my Chrome browser" — the latter+ also matches rule 1) without letting a cold research question start one.++Everything else is blocked and fed back to the model as a tool error telling+it to answer inline (or via ``search_web`` for fresh facts). Over-ALLOWING is+safe by construction — a match only means the MODEL MAY drive the desktop, it+never forces it. The deterministic local-action fast path+(``jarvis/brain/local_action_gate.py``) does NOT run through this gate — it+already fires only on explicit action grammar.++Consumers: ``jarvis.brain.tool_use_loop`` (classic pipeline + realtime+delegate mode) and ``jarvis.realtime.tools`` (realtime direct tool mode).+"""+from __future__ import annotations++import logging+import re++log = logging.getLogger(__name__)+++#: Registered names of every router tool that drives the live desktop.+#: Kept tiny and explicit — mirrors ``SPAWN_VEHICLE_TOOL_NAMES`` in+#: ``jarvis.brain.spawn_gate``.+CU_VEHICLE_TOOL_NAMES: frozenset[str] = frozenset({"computer_use"})+++#: How long after a Computer-Use mission a vehicle-free follow-up may still+#: re-drive the desktop. Matches the registry's "recently finished" context+#: bound — the same window BUG-105 uses to describe prior missions.+FOLLOW_UP_WINDOW_S: float = 15 * 60.0+++# German umlauts are transliterated to their digraphs before matching, exactly+# like jarvis/brain/turn_planner.py, so the vocabulary below is written in+# digraph form ("oeffn", "drueck").+_UMLAUT_TRANSLITERATION = str.maketrans(+ {"ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"} # i18n-allow: umlaut mapping data+)+++# Explicit desktop-vehicle vocabulary (DE/EN/ES) — speech-input matching data.+#+# Deliberate exclusions (each one is a live trap):+# * bare "start": the incident utterance itself contains the German NOUN+# "Start- und Landebahn" (runway) — # i18n-allow: names the German noun under exclusion+# only the conjugated imperatives ("starte", "startet", "starten") count.+# * bare "type": "what type of runway ..." is a question form; "type" counts+# only when not preceded by a question/genitive word.+# * "google"/"search"/"such": search intent belongs to search_web, never to+# the desktop — "google das im Browser" still passes via "browser".+_DESKTOP_VEHICLE_RE: re.Pattern[str] = re.compile(+ r"(?:"+ # --- action verbs (en) ---+ r"\bopen\w*\b|\blaunch\w*\b|\bclick\w*\b|\bdouble-?click\w*\b|\btap\b"+ r"|\bscroll\w*\b|\bdrag\w*\b|\bhover\b|\bpress\w*\b|\bpaste\b"+ r"|\bminimi[sz]e\b|\bmaximi[sz]e\b|\bnavigate\b|\bbrowse\b"+ r"|\blog\s?in\b|\bsign\s?in\b|\bgo\s+to\b"+ r"|(?<!what )(?<!which )(?<!of )\btype\b"+ r"|\bstart(?:s|ed|ing)?\s+(?:up\s+)?(?:the|a|an|my)\b"+ # --- action verbs (de) --- # i18n-allow: German speech-input matching data+ r"|\boeffn\w*|\baufmach\w*|\bklick\w*|\btipp\w*|\bscroll\w*"+ r"|\bzieh\w*\b|\bdrueck\w*|\bschliess\w*|\bnavigier\w*|\beinfueg\w*"+ r"|\bstart(?:e|et|en)\b"+ r"|\bmach\w*\b[^.?!]{0,40}\b(?:auf|zu)\b"+ r"|\bgeh\w*\s+(?:auf|zu|in)\b"+ r"|\blogg\w*\b"+ # --- action verbs (es) --- # i18n-allow: Spanish speech-input matching data+ r"|\babr(?:e|a|as|ir)\b|\bcli(?:c|ca|quea)\b|\bpincha\w*|\bpulsa\w*"+ r"|\btecle\w*|\bdesplaz\w*|\barrastr\w*|\bpega\b|\bcierr\w*|\bnaveg\w*"+ # --- screen/app/browser nouns (en/de/es share most brand tokens) ---+ r"|\bscreen\w*|\bdesktop\b|\bbrowser\w*|\bchrome\b|\bsafari\b"+ r"|\bfirefox\b|\bedge\b|\btabs?\b|\bwindows?\b|\bmouse\b|\bcursor\w*"+ r"|\bkeyboard\b|\bterminal\w*|\bapps?\b|\bapplications?\b"+ r"|\bprogram(?:me?s?)?\b|\bwebsites?\b|\bwebpages?\b|\burls?\b"+ r"|\bbuttons?\b|\bmenus?\b|\btaskbar\b|\bdock\b|\bfinder\b"+ r"|\bexplorer\b|\bnotepad\b|\baddress\s+bar\b"+ # i18n-allow: German speech-input matching data (nouns)+ r"|\bbildschirm\w*|\bfenster\b|\bmaus\b|\bmauszeiger\w*|\btastatur\w*"+ r"|\banwendung\w*|\bprogramm\w*|\bwebseite\w*|\bschaltflaech\w*"+ r"|\bmenue\w*|\btaskleiste\w*|\badresszeile\w*"+ # i18n-allow: Spanish speech-input matching data (nouns)+ r"|\bpantalla\w*|\bescritorio\b|\bnavegador\w*|\bpestan\w*"+ r"|\bventana\w*|\braton\b|\bteclado\b|\baplicacion\w*|\bboton\w*"+ r")",+ re.IGNORECASE,+)+++def _normalized(text: str) -> str:+ return (text or "").casefold().translate(_UMLAUT_TRANSLITERATION)+++def llm_computer_use_allowed(user_text: str) -> bool:+ """May an LLM-chosen ``computer_use`` call execute for this user turn?++ True when the turn names the desktop vehicle, or when the conversation is+ still inside a recent desktop episode (BUG-105 corrective follow-ups).+ An EMPTY turn fails OPEN: this gate exists to stop question-shaped voice+ turns from hijacking the screen, and non-conversational launch routes+ (scheduled missions, REST) may reach the loop without a user utterance —+ blocking those would brick legitimate desktop automation.+ """+ normalized = _normalized(user_text).strip()+ if not normalized:+ return True+ if _DESKTOP_VEHICLE_RE.search(normalized):+ return True+ try:+ from jarvis.harness.cu_run_registry import has_recent_run # noqa: PLC0415+ if has_recent_run(FOLLOW_UP_WINDOW_S):+ return True+ except Exception: # noqa: BLE001 — the gate must never crash a tool turn+ log.debug("cu_gate: recent-run probe failed", exc_info=True)+ return False+++#: Structured tool error the model receives instead of a mission. English —+#: internal steering text, never spoken verbatim (suppress_response tools+#: aside, the model rephrases in the conversation language).+CU_BLOCKED_MODEL_FEEDBACK: str = (+ "computer_use was NOT executed: the user did not ask you to operate the "+ "screen, an app, or the browser — this turn is an information request. "+ "Never drive the user's live desktop to look something up. Answer the "+ "question directly from your own knowledge now, or call search_web first "+ "if it genuinely needs current/volatile facts. computer_use is only for "+ "turns where the user explicitly wants an on-screen action performed "+ "(open/click/type/scroll, a named app, the browser)."+)+++__all__ = [+ "CU_BLOCKED_MODEL_FEEDBACK",+ "CU_VEHICLE_TOOL_NAMES",+ "FOLLOW_UP_WINDOW_S",+ "llm_computer_use_allowed",+]diff --git a/jarvis/brain/router.py b/jarvis/brain/router.pyindex d6d05eaec3..acb67ffcc8 100644--- a/jarvis/brain/router.py+++ b/jarvis/brain/router.py@@ -322,6 +322,15 @@ Du sortierst jede Ruben-Nachricht in genau eine von drei Kategorien:and its constraints from the conversation — the underlying objective,the target app/browser/site, and what the previous attempt got wrong.An unexpanded "do it in Chrome" just opens Chrome and stops.+ NEVER FOR RESEARCH (live incident 2026-07-21): an information or+ knowledge QUESTION ("braucht die G100 eine lange Landebahn?", "wie+ lang ist X?", "what does Y cost?") is NEVER a computer_use case, no+ matter how it reached you. Driving the user's live browser to google+ an answer hijacks their screen for something you can do invisibly:+ answer from your own knowledge, or call search_web for fresh facts.+ computer_use only when Ruben explicitly wants the screen, an app, or+ the browser OPERATED ("oeffne...", "klick...", "geh im Browser+ auf..."). A deterministic gate enforces this and will reject the call.- Shell-Kommando: "ls im Desktop", "starte notepad" (run_shell)- Bildschirm beschreiben: "was siehst du auf meinem Screen" (screenshot)- "merk dir X": KEIN Tool — beginne deine Antwort mit "Notiert" (siehediff --git a/jarvis/brain/tool_use_loop.py b/jarvis/brain/tool_use_loop.pyindex 5de3b49727..b9e8072e35 100644--- a/jarvis/brain/tool_use_loop.py+++ b/jarvis/brain/tool_use_loop.py@@ -20,6 +20,11 @@ from collections.abc import Awaitable, Callablefrom typing import Any, Literalfrom uuid import UUID, uuid4+from jarvis.brain.cu_gate import (+ CU_BLOCKED_MODEL_FEEDBACK,+ CU_VEHICLE_TOOL_NAMES,+ llm_computer_use_allowed,+)from jarvis.brain.spawn_gate import (SPAWN_BLOCKED_MODEL_FEEDBACK,SPAWN_VEHICLE_TOOL_NAMES,@@ -924,6 +929,33 @@ class ToolUseLoop:"output": None,"error": SPAWN_BLOCKED_MODEL_FEEDBACK,}+ elif (+ tool_name in CU_VEHICLE_TOOL_NAMES+ and not llm_computer_use_allowed(user_utterance)+ ):+ # Explicit-desktop gate (live incident 2026-07-21 11:36):+ # a pure knowledge question delegated by realtime was+ # answered by physically googling in the user's browser.+ # An LLM-chosen computer_use runs ONLY when the user's own+ # turn asks for an on-screen action (or the conversation is+ # still inside a recent desktop episode). Deterministic —+ # the tool description alone is advice, not enforcement+ # (spawn-gate lesson). See jarvis/brain/cu_gate.py.+ log.info(+ "tool_use_loop: computer_use blocked — no explicit "+ "desktop request in the user turn"+ )+ await self._publish_guard_denied(+ tool_name,+ "guard: no explicit desktop request — "+ "computer_use not executed",+ tid,+ )+ tool_result_payload = {+ "success": False,+ "output": None,+ "error": CU_BLOCKED_MODEL_FEEDBACK,+ }elif stt_blocked:# Arg sanity guard: the tool args look like a Whisper# hallucination (ad outro, copyright string, overly long app name).diff --git a/jarvis/harness/cu_run_registry.py b/jarvis/harness/cu_run_registry.pyindex 430ce5cbd0..32fd9711ae 100644--- a/jarvis/harness/cu_run_registry.py+++ b/jarvis/harness/cu_run_registry.py@@ -208,6 +208,24 @@ def recent_runs_context(now: float | None = None) -> str:return "\n".join(recent)+def has_recent_run(max_age_s: float = _CONTEXT_MAX_AGE_S, now: float | None = None) -> bool:+ """True when a mission is active or ended within ``max_age_s``.++ Consumed by the research-turn computer-use gate (``jarvis.brain.cu_gate``):+ a vehicle-free corrective follow-up ("try again", "nochmal") may re-drive+ the desktop only while the conversation is demonstrably still *in* a+ desktop episode. Registration covers every launch route (voice fast path,+ LLM tool, REST, scheduled), so this is the one honest signal for that.+ """ # i18n-allow: quoted German follow-up token the gate matches+ now_s = time.time() if now is None else float(now)+ for run in _RUNS.values():+ if run.status in ACTIVE_STATUSES:+ return True+ if run.ended_at is not None and 0 <= now_s - run.ended_at <= max_age_s:+ return True+ return False++def clear_runs() -> None:"""Test/teardown helper — wipes the registry."""_RUNS.clear()diff --git a/jarvis/plugins/tool/computer_use_tool.py b/jarvis/plugins/tool/computer_use_tool.pyindex 468820bb28..d38c2de2a9 100644--- a/jarvis/plugins/tool/computer_use_tool.py+++ b/jarvis/plugins/tool/computer_use_tool.py@@ -120,7 +120,11 @@ class ComputerUseTool:"and what the previous attempt got wrong. An unexpanded 'do it in ""Chrome' just opens Chrome and stops. This drives the real machine — ""unlike spawn_worker, which only works in an isolated code workspace "- "and cannot touch the desktop."+ "and cannot touch the desktop. NOT a research tool: NEVER use it to "+ "search the web, google something, or look up facts/information — "+ "answer from your own knowledge or call search_web instead. Only the "+ "user's explicit wish to see it happen on their screen ('open the "+ "browser and search for X') makes a web lookup a computer_use task.")schema: dict[str, Any] = {"type": "object",diff --git a/jarvis/realtime/tools.py b/jarvis/realtime/tools.pyindex 154d26da60..cb322e7bf4 100644--- a/jarvis/realtime/tools.py+++ b/jarvis/realtime/tools.py@@ -9,6 +9,11 @@ from dataclasses import dataclassfrom typing import Any, castfrom uuid import UUID, uuid4+from jarvis.brain.cu_gate import (+ CU_BLOCKED_MODEL_FEEDBACK,+ CU_VEHICLE_TOOL_NAMES,+ llm_computer_use_allowed,+)from jarvis.brain.spawn_gate import (SPAWN_BLOCKED_MODEL_FEEDBACK,SPAWN_VEHICLE_TOOL_NAMES,@@ -406,6 +411,15 @@ class RealtimeToolBridge:# Deterministic — prompt-side discouragement failed repeatedly.# See jarvis/brain/spawn_gate.py.message = SPAWN_BLOCKED_MODEL_FEEDBACK+ elif name in CU_VEHICLE_TOOL_NAMES and not llm_computer_use_allowed(+ user_text+ ):+ # Explicit-desktop gate (live incident 2026-07-21 11:36): a pure+ # knowledge question must never be answered by driving the user's+ # browser. computer_use runs ONLY when the spoken turn asks for an+ # on-screen action or a desktop episode is already in progress.+ # See jarvis/brain/cu_gate.py.+ message = CU_BLOCKED_MODEL_FEEDBACKelif _should_block_action_as_research(descriptor,name,diff --git a/tests/unit/brain/test_cu_gate.py b/tests/unit/brain/test_cu_gate.pynew file mode 100644index 0000000000..3e45667e10--- /dev/null+++ b/tests/unit/brain/test_cu_gate.py@@ -0,0 +1,119 @@+"""Explicit-desktop gate for LLM-chosen computer_use calls (cu_gate.py).++Live incident 2026-07-21 11:36 (voice session 06a65611): a pure knowledge+question about the Gulfstream G100's runway requirement was delegated to the+router brain, which called computer_use — Safari opened on the user's screen+and googled the answer. The gate pins that a question-shaped turn without any+explicit on-screen vocabulary can never start a desktop mission, while every+explicit desktop ask (and the BUG-105 corrective follow-ups inside a recent+desktop episode) still passes.+"""+from __future__ import annotations++import pytest++from jarvis.brain.cu_gate import (+ CU_BLOCKED_MODEL_FEEDBACK,+ CU_VEHICLE_TOOL_NAMES,+ llm_computer_use_allowed,+)+from jarvis.harness import cu_run_registry++[email protected](autouse=True)+def _fresh_run_registry():+ cu_run_registry.clear_runs()+ yield+ cu_run_registry.clear_runs()+++# ── live regression: knowledge questions must NEVER drive the desktop ─────+++ "utterance",+ [+ # voice-session 2026-07-21 11:36 — googled in Safari before the gate.+ # Also pins that the German NOUN "Start- und Landebahn" (runway) never+ # counts as the action verb "start".+ "braucht die Golf braucht die Golf 100 Start- und Landebahn.", # i18n-allow: live utterance+ "Kann eine Gulfstream 800 in St. Moritz landen?", # i18n-allow: live utterance+ "Wie lang ist die Landebahn in St. Moritz?", # i18n-allow: DE turn fixture+ "What runway length does a Gulfstream G100 need?",+ "What type of runway does it need?",+ "Was kostet eine Gulfstream 800?", # i18n-allow: DE turn fixture+ # Search intent without a named vehicle belongs to search_web.+ "Such im Internet nach den aktuellsten News.", # i18n-allow: DE turn fixture+ "Google mal, wie hoch der Bitcoin gerade steht.", # i18n-allow: DE turn fixture+ ],+)+def test_knowledge_question_blocks_computer_use(utterance: str) -> None:+ assert llm_computer_use_allowed(utterance) is False+++# ── explicit desktop asks keep passing ────────────────────────────────────+++ "utterance",+ [+ "Öffne ein Terminal.", # i18n-allow: DE trigger+ "Öffne Chrome und geh auf gmail.com.", # i18n-allow: DE trigger+ "Mach Notepad auf.", # i18n-allow: DE trigger+ "Klick den blauen Button.", # i18n-allow: DE trigger+ "Scroll mal runter.", # i18n-allow: DE trigger+ "Starte Spotify.", # i18n-allow: DE trigger+ "Open the browser and search for Gulfstream G100 runway length.",+ "Click the settings icon.",+ "Type hello into the search field.",+ "Abre el navegador.",+ "Haz clic en el botón azul.",+ # Naming the vehicle makes even a web lookup a desktop task.+ "Google das mal im Browser.", # i18n-allow: DE trigger+ ],+)+def test_explicit_desktop_ask_allows_computer_use(utterance: str) -> None:+ assert llm_computer_use_allowed(utterance) is True+++# ── BUG-105 corrective follow-ups inside a desktop episode ────────────────+++def test_vehicle_free_follow_up_passes_only_inside_a_recent_episode() -> None:+ follow_up = "Versuch es nochmal." # i18n-allow: DE follow-up fixture+ assert llm_computer_use_allowed(follow_up) is False++ cu_run_registry.register_run("m1", "open the browser", token=None)+ assert llm_computer_use_allowed(follow_up) is True++ cu_run_registry.finish_run("m1", "finished", exit_code=0)+ assert llm_computer_use_allowed(follow_up) is True++ cu_run_registry.clear_runs()+ assert llm_computer_use_allowed(follow_up) is False+++def test_recent_run_window_expires() -> None:+ cu_run_registry.register_run("m2", "open chrome", token=None)+ cu_run_registry.finish_run("m2", "finished", exit_code=0)+ assert cu_run_registry.has_recent_run(60.0) is True+ run = cu_run_registry._RUNS["m2"]+ run.ended_at = run.ended_at - 3600.0+ assert cu_run_registry.has_recent_run(60.0) is False+++# ── plumbing contracts ────────────────────────────────────────────────────+++def test_empty_turn_fails_open_for_non_conversational_routes() -> None:+ assert llm_computer_use_allowed("") is True+ assert llm_computer_use_allowed(" ") is True+++def test_gate_covers_exactly_the_computer_use_tool() -> None:+ assert CU_VEHICLE_TOOL_NAMES == frozenset({"computer_use"})+++def test_feedback_redirects_to_inline_answer_and_search_web() -> None:+ assert "search_web" in CU_BLOCKED_MODEL_FEEDBACK+ assert "NOT executed" in CU_BLOCKED_MODEL_FEEDBACK