Skip to content

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.

fix(voice): reply-language switch picks the first language in the utterance

Ruben Lütke83e066ebb3e4
diff --git a/jarvis/brain/voice_command_gate.py b/jarvis/brain/voice_command_gate.py
index cc6748784a..f7514a280d 100644
--- a/jarvis/brain/voice_command_gate.py
+++ b/jarvis/brain/voice_command_gate.py
@@ -114,13 +114,18 @@ _LANG_PREP = re.compile(r"\b(?:auf|zu|to|in|on)\b", re.IGNORECASE)
def _match_language_switch(t: str) -> str | None:
- code: str | None = None
+ # Pick the language that appears EARLIEST in the utterance, not the first
+ # one in alias-dict order. "antworte auf deutsch und englisch" must resolve
+ # to de (the first spoken language), not en just because "englisch" happens
+ # to sit earlier in _LANG_ALIASES (forensic 2026-06-27).
+ best: tuple[int, str] | None = None
for word, c in _LANG_ALIASES.items():
- if re.search(rf"\b{re.escape(word)}\b", t):
- code = c
- break
- if code is None:
+ m = re.search(rf"\b{re.escape(word)}\b", t)
+ if m is not None and (best is None or m.start() < best[0]):
+ best = (m.start(), c)
+ if best is None:
return None
+ code = best[1]
if _LANG_CHANGE_VERB.search(t):
return code
if _LANG_IMPERATIVE_SPEAK.search(t):
diff --git a/tests/unit/brain/test_voice_command_gate.py b/tests/unit/brain/test_voice_command_gate.py
index 3b75a16718..a0d9930bc2 100644
--- a/tests/unit/brain/test_voice_command_gate.py
+++ b/tests/unit/brain/test_voice_command_gate.py
@@ -145,3 +145,18 @@ def test_main_provider_switch_recognizes_anthropic_alias() -> None:
m = match_voice_command("switch to anthropic")
assert m is not None and m.kind == "provider_switch"
assert m.target == "anthropic"
+
+
+def test_language_switch_picks_first_language_in_text_not_dict_order() -> None:
+ # "deutsch" appears before "englisch" in the sentence, so the reply language
+ # must be German — not English just because "englisch" sits earlier in the
+ # alias dict (forensic 2026-06-27).
+ m = match_voice_command("antworte auf deutsch und englisch")
+ assert m is not None and m.kind == "language_switch"
+ assert m.target == "de"
+
+
+def test_language_switch_single_language_unaffected() -> None:
+ m = match_voice_command("antworte auf englisch")
+ assert m is not None and m.kind == "language_switch"
+ assert m.target == "en"