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: route one-shot screen context consistently
Ruben Lütke7cb6304f8d2e
diff --git a/jarvis/brain/turn_planner.py b/jarvis/brain/turn_planner.pyindex 27aa47b09e..12b0869e07 100644--- a/jarvis/brain/turn_planner.py+++ b/jarvis/brain/turn_planner.py@@ -15,6 +15,9 @@ from dataclasses import dataclassfrom enum import StrEnumfrom typing import Any+from jarvis.screen_context.intent import classify as classify_screen_context+from jarvis.screen_context.models import VisualIntent+class TurnPath(StrEnum):"""Execution surface selected for one user turn."""@@ -33,6 +36,7 @@ class TurnReason(StrEnum):LOCAL_STATE = "local_state"MISSION = "mission"PRIVATE_DATA = "private_data"+ SCREEN_CONTEXT = "screen_context"SKILL = "skill"UNCERTAIN = "uncertain"WORKSPACE = "workspace"@@ -76,7 +80,8 @@ _INSTRUCTIONAL_RE = re.compile(r"wie (?:kann|koennte|wuerde) (?:ich|man)|" # i18n-allow: speech inputr"wie (?:kannst|koenntest|wuerdest) du|" # i18n-allow: speech inputr"wie (?:koennen|koennten|wuerden) sie|" # i18n-allow: speech input- r"como (?:puedo|se puede)|como hacer)\b" # i18n-allow: multilingual speech-input matching data+ r"como (?:puedo|puedes|podria|podrias|se puede)|como hacer)\b"+ # i18n-allow: multilingual speech-input matching data)_OWNERSHIP_RE = re.compile(r"\b(?:my|mine|our|we|about me|remember me|"@@ -516,6 +521,12 @@ def plan_turn(return TurnPlan(path=TurnPath.NATIVE_REALTIME)reasons: set[TurnReason] = set()+ screen_context_intent = classify_screen_context(text).intent+ if screen_context_intent is not VisualIntent.NONE:+ # The native realtime model cannot see a one-shot image that only the+ # supervisor can capture and attach. Ambiguity also belongs here: the+ # supervisor owns the privacy-preserving clarification state.+ reasons.add(TurnReason.SCREEN_CONTEXT)# Checked before the suppressors and never dampened by them: a named pane# is as strong as evidence gets, and the reason it must not be weakened is# that its most ordinary phrasings are exactly the shapes the suppressors@@ -745,6 +756,7 @@ def plan_turn(TurnReason.CURRENT_DATA,TurnReason.LOCAL_STATE,TurnReason.PRIVATE_DATA,+ TurnReason.SCREEN_CONTEXT,# What the pane actually printed is evidence the live model# never holds; answering "what has Dana done" without it is# exactly the guess this whole path exists to prevent.diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.pyindex 363a1c2054..354531fbd4 100644--- a/jarvis/realtime/session.py+++ b/jarvis/realtime/session.py@@ -35,7 +35,7 @@ from jarvis.brain.provider_test import (UNREACHABLE,classify_provider_error,)-from jarvis.brain.turn_planner import TurnPath, TurnPlan, plan_turn+from jarvis.brain.turn_planner import TurnPath, TurnPlan, TurnReason, plan_turnfrom jarvis.core.protocols import AudioChunk, BrainMessagefrom jarvis.core.redact import safe_previewfrom jarvis.core.turn_language import normalize_language_tag, resolve_output_language@@ -2152,7 +2152,15 @@ class RealtimeVoiceSession:f"path={turn_plan.path.value};reasons={reasons}"),)- if self._delegate_enabled and self._last_user_text:+ screen_context_turn = (+ TurnReason.SCREEN_CONTEXT in turn_plan.reasons+ )+ deterministic_delegate_available = callable(self._brain)+ if (+ self._last_user_text+ and deterministic_delegate_available+ and (self._delegate_enabled or screen_context_turn)+ ):self._delegate_required_for_turn = (self._delegate_required_for_turnor turn_plan.requires_orchestratordiff --git a/jarvis/screen_context/intent.py b/jarvis/screen_context/intent.pyindex b5830912ee..3ba7c7cb00 100644--- a/jarvis/screen_context/intent.py+++ b/jarvis/screen_context/intent.py@@ -34,6 +34,35 @@ log = logging.getLogger(__name__)_MAX_EVIDENCE = 3+# Questions *about* Screen Context are not consent to use it. This guard is+# deliberately evaluated before the positive matcher: all of these sentences+# contain the same screen/look words as a real request, but their grammatical+# shape asks for instructions or product behaviour rather than a look now.+_SCREEN_CONTEXT_META_RE: re.Pattern[str] = re.compile(+ r"(?:"+ # --- English ---+ r"\bhow\s+(?:do|can|could|would)\s+(?:i|you)\b[^.?!]{0,96}"+ r"\b(?:look|see|view|inspect|screen|screenshot|capture)\b"+ r"|\bhow\s+to\b[^.?!]{0,96}\b(?:screen|screenshot|capture)\b"+ r"|\bwhat\s+(?:happens|would\s+happen)\s+(?:if|when)\b[^.?!]{0,96}"+ r"\b(?:screen|screenshot|capture)\b"+ # --- German --- i18n-allow: German speech-input matching data+ r"|\bwie\s+(?:kann|koennte|wuerde)\s+(?:ich|man)\b[^.?!]{0,96}" # i18n-allow+ r"\b(?:bildschirm|screen|screenshot|bildschirmfoto|ansehen|zeigen)\b"+ r"|\bwie\s+(?:kannst|koenntest|wuerdest)\s+du\b[^.?!]{0,96}"+ r"\b(?:bildschirm|screen|screenshot|bildschirmfoto|sehen|ansehen)\b"+ r"|\bwas\s+passiert\s+(?:wenn|falls)\b[^.?!]{0,96}"+ r"\b(?:bildschirm|screen|screenshot|bildschirmfoto)\b"+ # --- Spanish --- i18n-allow: Spanish speech-input matching data+ r"|\bcomo\s+(?:puedo|podria|puedes|podrias|se\s+puede)\b[^.?!]{0,96}"+ r"\b(?:pantalla|captura|ver|mirar)\b"+ r"|\bque\s+pasa\s+(?:si|cuando)\b[^.?!]{0,96}"+ r"\b(?:pantalla|captura)\b"+ r")",+ re.IGNORECASE,+)++# --------------------------------------------------------------------------# Normalization# --------------------------------------------------------------------------@@ -151,6 +180,11 @@ _SCREEN_INTENT_RE: re.Pattern[str] = re.compile(# screen nouns with a possessive/demonstrativer"|\b(?:on|at)\s+(?:my|the|this)\s+screen\b|\bmy\s+screen\b"r"|\bwhat(?:'|)s\s+on\s+(?:my|the)\s+screen\b"+ r"|\bwhat\s+can\s+you\s+see\s+on\s+(?:my|the)\s+(?:screen|monitor)\b"+ r"|\banaly[sz]e\s+(?:(?:this|that|the|my)\s+)?"+ r"(?:screenshot|screen\s+capture)\b"+ r"|\b(?:inspect|review|analy[sz]e)\s+(?:this|that|the\s+current)\s+"+ r"(?:window|screen|monitor|dialog|tab)\b"r"|\b(?:take|make|capture|grab)\s+(?:a\s+)?screen(?:shot|\s+capture)\b"r"|\bscreen(?:shot|\s+capture)\s+(?:this|that|my\s+screen|the\s+screen)\b"r"|\b(?:this|that)\s+(?:error|error\s+message|message|button|menu|popup)\b"@@ -165,14 +199,19 @@ _SCREEN_INTENT_RE: re.Pattern[str] = re.compile(# phrasing, and a bare ``dies\b`` would only match the rarer "schau dir# dies an" — costing the common case to save nothing.r"|\bschau(?:e|st)?\s+(?:dir\s+)?(?:das|dies\w*|es|mal\s+das|hier)\b"+ r"|\b(?:schau|schaue|sieh|guck)\s+(?:dir\s+)?(?:bitte\s+)?"+ r"(?:meinen|den|diesen)\s+(?:bildschirm|monitor)\s+an\b"r"|\bschau\s+mal\b|\bschau\s+her\b|\bguck\s+mal\b|\bguck\s+(?:dir\s+)?das\b"r"|\bsieh\s+(?:dir\s+)?(?:das|dies\w*)\b|\bsieh\s+mal\b"r"|\bkannst\s+du\s+(?:mal\s+)?(?:kurz\s+)?(?:sehen|schauen|gucken|draufschauen)\b"r"|\bkannst\s+du\s+(?:das|dies|es|meinen\s+bildschirm)\s+sehen\b"+ r"|\bkannst\s+du\s+(?:bitte\s+)?meinen\s+(?:bildschirm|monitor)\s+"+ r"(?:anschauen|ansehen|pruefen)\b"r"|\bsiehst\s+du\s+(?:das|dies|meinen\s+bildschirm|den\s+fehler)\b" # i18n-allow: DE inputr"|\bwas\s+siehst\s+du\b"# screen nounsr"|\bauf\s+(?:dem|meinem)\s+bildschirm\b|\bam\s+bildschirm\b|\bmein\s+bildschirm\b"+ r"|\bauf\s+(?:dem|meinem|diesem)\s+monitor\b|\bmein\s+monitor\b"# i18n-allow: German speech-input matching datar"|\b(?:mach|mache|erstelle|nimm)\s+(?:bitte\s+)?(?:einen\s+)?screenshot\b"r"|\bbildschirmfoto\s+(?:machen|aufnehmen|erstellen)\b" # i18n-allow: DE input@@ -182,7 +221,13 @@ _SCREEN_INTENT_RE: re.Pattern[str] = re.compile(r"|\b(?:dieser|der)\s+knopf\b|\b(?:dieses|das)\s+menue\b" # i18n-allow: DE input# read-out requestsr"|\bwas\s+steht\s+(?:da|hier|dort|drin)\b|\bda\s+steht\b"+ r"|\bwas\s+steht\s+(?:in|auf)\s+dies\w*\s+"+ r"(?:fenster|dialog|tab|dokument)\b"r"|\blies\s+(?:mir\s+)?(?:das|dies|es|die\s+\w+)\b|\bvorlesen\b" # i18n-allow: DE input+ r"|\blies\s+(?:mir\s+)?(?:bitte\s+)?(?:dies\w*|das)\s+"+ r"(?:fenster|dialog|tab|dokument)\b" # i18n-allow: DE input+ r"|\bpruef\w*\s+(?:bitte\s+)?[^.?!]{0,72}\b"+ r"(?:bildschirm|monitor|fenster)\b" # i18n-allow: DE inputr"|\bwas\s+ist\s+das\s+(?:hier|da\s+auf)\b" # i18n-allow: DE input# ---------------- Spanish ---------------- i18n-allow: Spanish speech-input matching data@@ -190,8 +235,10 @@ _SCREEN_INTENT_RE: re.Pattern[str] = re.compile(r"|\bmirar\s+(?:esto|eso)\b|\becha(?:le)?\s+un\s+vistazo\b"r"|\bpuedes\s+ver\s+(?:esto|eso|mi\s+pantalla|la\s+pantalla)\b"r"|\bves\s+(?:esto|eso|mi\s+pantalla)\b|\bque\s+ves\b"+ r"|\bque\s+ves\s+en\s+mi\s+(?:pantalla|monitor)\b"r"|\ben\s+(?:mi|la)\s+pantalla\b|\bmi\s+pantalla\b"r"|\b(?:haz|toma|captura)\s+(?:una\s+)?captura\s+de\s+pantalla\b"+ r"|\banaliza\s+(?:esta\s+|esa\s+|la\s+)?captura\s+de\s+pantalla\b"r"|\bque\s+dice\s+(?:ahi|aqui|esto|eso)\b"r"|\blee\s+(?:esto|eso|el\s+\w+)\b"r"|\beste\s+error\b|\besta\s+ventana\s+de\s+error\b"@@ -364,6 +411,9 @@ def classify(text: str, *, locale: str = "") -> IntentVerdict:if not normalized:return IntentVerdict(intent=VisualIntent.NONE, locale=locale)+ if _SCREEN_CONTEXT_META_RE.search(normalized):+ return IntentVerdict(intent=VisualIntent.NONE, locale=locale)+# Operating the desktop is Computer-Use's job. This check precedes every# visual noun match so phrases such as "click the button on my screen" do# not take a one-shot screenshot and then disable the very tools requested.diff --git a/tests/unit/brain/test_turn_planner.py b/tests/unit/brain/test_turn_planner.pyindex 358d3127e7..35b7210d44 100644--- a/tests/unit/brain/test_turn_planner.py+++ b/tests/unit/brain/test_turn_planner.py@@ -133,6 +133,34 @@ def test_empty_turn_stays_native() -> None:assert plan_turn(" ").path is TurnPath.NATIVE_REALTIME+ "utterance",+ [+ "Take a screenshot.",+ "What is that?",+ "Schau dir bitte meinen Bildschirm an.", # i18n-allow: DE input+ "Analiza esta captura de pantalla.", # i18n-allow: ES input+ ],+)+def test_screen_context_turns_use_the_orchestrator(utterance: str) -> None:+ plan = plan_turn(utterance)+ assert plan.path is TurnPath.ORCHESTRATOR+ assert TurnReason.SCREEN_CONTEXT in plan.reasons+ assert plan.requires_evidence is True+++ "utterance",+ [+ "How can you look at my screen?",+ "Wie kann ich dir meinen Bildschirm zeigen?", # i18n-allow: DE input+ "Como puedes ver mi pantalla?", # i18n-allow: ES input+ ],+)+def test_screen_context_how_to_questions_stay_native(utterance: str) -> None:+ assert plan_turn(utterance).path is TurnPath.NATIVE_REALTIME++@pytest.mark.parametrize(("utterance", "context"),[diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.pyindex eaeded9a4a..900a1edcb6 100644--- a/tests/unit/realtime/test_session.py+++ b/tests/unit/realtime/test_session.py@@ -3875,6 +3875,30 @@ async def test_garbled_wiki_follow_up_inherits_session_context_and_delegates():await sess.end(reason="test")[email protected]("tool_mode", ["delegate", "direct"])+async def test_screen_context_always_uses_deterministic_brain_turn(tool_mode: str):+ """The realtime model never answers a visual turn without the image."""+ utterance = "Schau dir bitte meinen Bildschirm an." # i18n-allow: DE input+ brain = FakeBrain(replies=("The current screen shows the settings view.",))+ provider = FakeProvider(+ [+ RealtimeEvent(type="input_transcript", text=utterance, is_final=True),+ RealtimeEvent(type="turn_complete"),+ ]+ )+ sess = _session(provider, brain=brain, tool_mode=tool_mode)++ await sess.handle_control({"type": "audio_start", "sample_rate": 16_000})+ await sess.wait_finished()+ await asyncio.sleep(0.02)++ assert provider.session.response_requests == 0+ assert brain.calls[0][0] == utterance+ assert "<trusted_action_result>" in provider.session.text_inputs[-1]+ await sess.end(reason="test")++@pytest.mark.asyncioasync def test_native_realtime_promise_without_tool_recovers_via_orchestrator():"""A provider violation starts the action instead of ending on a promise."""diff --git a/tests/unit/screen_context/test_intent.py b/tests/unit/screen_context/test_intent.pyindex a6069a0531..a5beca2b3a 100644--- a/tests/unit/screen_context/test_intent.py+++ b/tests/unit/screen_context/test_intent.py@@ -35,6 +35,10 @@ from jarvis.screen_context.models import VisualIntent"what's on my screen?","check this out","take a screenshot",+ "look at my screen",+ "analyze the screenshot",+ "what can you see on my monitor?",+ "inspect the current window",# -- German (the two phrasings the feature is specified around)"Kannst du mal sehen?","Schau dir das an",@@ -46,12 +50,19 @@ from jarvis.screen_context.models import VisualIntent"auf dem Bildschirm ist eine Fehlermeldung", # i18n-allow: DE input"Wenn sowas auf meinem Bildschirm ist, was bedeutet das?", # i18n-allow: DE input"mach einen Screenshot", # i18n-allow: DE input+ "Schau dir bitte meinen Bildschirm an", # i18n-allow: DE input+ "Pruef bitte, was auf meinem Monitor steht", # i18n-allow: DE input+ "Lies bitte dieses Fenster", # i18n-allow: DE input+ "Kannst du meinen Bildschirm anschauen?", # i18n-allow: DE input+ "Was steht in diesem Fenster?", # i18n-allow: DE input# -- Spanish"mira esto","puedes ver esto?","que dice ahi?","echa un vistazo","haz una captura de pantalla",+ "analiza esta captura de pantalla",+ "que ves en mi monitor",],)def test_unambiguous_requests_capture(utterance: str) -> None:@@ -181,6 +192,22 @@ def test_non_visual_turns_are_left_alone(utterance: str) -> None:assert verdict.intent is VisualIntent.NONE, f"{utterance!r} -> {verdict.intent}"+ "utterance",+ [+ "How can you look at my screen?",+ "How do I let you take a screenshot?",+ "What happens when I ask for a screenshot?",+ "Wie kannst du meinen Bildschirm sehen?", # i18n-allow: DE input+ "Wie kann ich dir meinen Bildschirm zeigen?", # i18n-allow: DE input+ "Was passiert, wenn ich Screenshot sage?", # i18n-allow: DE input+ "Como puedes ver mi pantalla?", # i18n-allow: ES input+ ],+)+def test_product_questions_are_not_capture_consent(utterance: str) -> None:+ assert classify(utterance).intent is VisualIntent.NONE++def test_idiom_masking_does_not_veto_a_real_request() -> None:"""An idiom and a real request in one sentence must still capture.