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): add shared CLI-brain reply-language directive extractor
Ruben Lütkee96c6991b628
diff --git a/jarvis/plugins/brain/cli_prompt_context.py b/jarvis/plugins/brain/cli_prompt_context.pynew file mode 100644index 0000000000..6dc64f5085--- /dev/null+++ b/jarvis/plugins/brain/cli_prompt_context.py@@ -0,0 +1,71 @@+"""Shared context extraction for subscription-CLI brain prompts.++Codex and Antigravity flatten a Jarvis turn into one plain prompt for an+official CLI. They intentionally do not forward the full router system prompt:+that prompt is large, tool-heavy, and misleading for read-only conversational+CLI calls. User standing instructions are different: they are the Jarvis.md+equivalent and must still reach the answering model.+"""+from __future__ import annotations++_PREF_START = "USER PREFERENCES & STANDING INSTRUCTIONS"+_PREF_END = "END USER PREFERENCES & STANDING INSTRUCTIONS"+_LEGACY_MAX_CHARS = 6000++# The BrainManager appends the authoritative reply-language directive LAST to+# the system prompt (manager._reply_language_directive). Both forms — the hard+# "REPLY LANGUAGE — MANDATORY: ..." pin and the soft "REPLY LANGUAGE: mirror the+# user ..." auto line — start with this marker.+_REPLY_LANG_MARKER = "REPLY LANGUAGE"+++def extract_standing_instructions_block(system_prompt: str | None) -> str:+ """Return only the user standing-instructions block from a system prompt."""+ if not system_prompt:+ return ""+ start = system_prompt.find(_PREF_START)+ if start == -1:+ return ""+ end = system_prompt.find(_PREF_END, start)+ if end != -1:+ end += len(_PREF_END)+ return system_prompt[start:end].strip()+ # Legacy prompts did not have an end marker. Keep the fallback bounded so a+ # stale process never drags the whole router/tool prompt into a CLI turn.+ return system_prompt[start : start + _LEGACY_MAX_CHARS].strip()+++def extract_reply_language_directive(system_prompt: str | None) -> str:+ """Return the trailing reply-language directive from a system prompt.++ The single authoritative output-language decision for a turn is rendered by+ ``BrainManager._reply_language_directive`` and appended LAST to the system+ prompt (so it overrides the otherwise German prompt above it). The CLI+ brains rebuild their own flattened prompt and would otherwise DROP this+ directive entirely — the subscription model (Gemini via agy, GPT via codex)+ then never learns which language to answer in and anchors to the German+ persona (live bug 2026-06-21: an English voice request answered in German,+ spoken with an English TTS voice). Re-extract it here so the directive still+ reaches the CLI model. ``rfind`` so an earlier incidental mention never wins+ over the real, last-appended directive.+ """+ if not system_prompt:+ return ""+ idx = system_prompt.rfind(_REPLY_LANG_MARKER)+ if idx == -1:+ return ""+ return system_prompt[idx:].strip()+++def render_cli_standing_instructions(system_prompt: str | None) -> str:+ """Render a compact system-like block for flattened CLI prompts."""+ block = extract_standing_instructions_block(system_prompt)+ if not block:+ return ""+ return (+ "USER STANDING INSTRUCTIONS FROM JARVIS.MD:\n"+ "Apply these as binding output-style preferences for this answer. "+ "If they conflict with the light CLI style above, the user's instructions "+ "win. They do not authorise tools, file access, commands, or safety bypasses.\n\n"+ f"{block}"+ )diff --git a/tests/unit/plugins/brain/test_cli_prompt_context.py b/tests/unit/plugins/brain/test_cli_prompt_context.pynew file mode 100644index 0000000000..c8f8fe2858--- /dev/null+++ b/tests/unit/plugins/brain/test_cli_prompt_context.py@@ -0,0 +1,59 @@+"""Shared CLI-brain prompt context extraction.++Regression guard for the live bug 2026-06-21: an English voice request was+answered in German (and spoken with an English TTS voice). Root cause — the+subscription-CLI brains (antigravity/agy, codex) rebuild their own flattened+prompt and dropped the authoritative reply-language directive that the+BrainManager appends LAST to the system prompt. The model then never learned+which language to answer in and anchored to the German persona ("Schef ...").+``extract_reply_language_directive`` re-surfaces that trailing directive so the+single authoritative output-language decision still reaches the CLI model.+"""+from __future__ import annotations++from jarvis.plugins.brain.cli_prompt_context import (+ extract_reply_language_directive,+)++_MANDATORY = (+ "REPLY LANGUAGE — MANDATORY: Always reply in English, no matter which "+ "language the user writes or speaks in. This overrides any other language "+ "cue anywhere in this prompt."+)+++def _system_with_directive() -> str:+ return (+ "STATIC PERSONA BLOCK\n\n"+ "USER PREFERENCES & STANDING INSTRUCTIONS (from Jarvis.md):\n"+ "Always start every sentence with schef.\n\n"+ "END USER PREFERENCES & STANDING INSTRUCTIONS\n\n"+ f"{_MANDATORY}"+ )+++def test_extracts_trailing_mandatory_directive() -> None:+ assert extract_reply_language_directive(_system_with_directive()) == _MANDATORY+++def test_extracts_soft_mirror_directive() -> None:+ soft = (+ "REPLY LANGUAGE: Reply in the SAME language as the user's latest "+ "message — detect it fresh each turn and mirror it."+ )+ assert extract_reply_language_directive("PERSONA BLOCK\n\n" + soft) == soft+++def test_returns_empty_when_absent() -> None:+ assert extract_reply_language_directive("just a persona, no directive") == ""+++def test_returns_empty_for_none() -> None:+ assert extract_reply_language_directive(None) == ""+++def test_takes_last_occurrence() -> None:+ # The phrase may surface in an explanatory sentence earlier in the prompt;+ # the real directive is the one BrainManager appends last.+ text = "Some text mentioning REPLY LANGUAGE in passing.\n\n" + _MANDATORY+ assert extract_reply_language_directive(text) == _MANDATORY