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): stop six filters from destroying correct answers

Harald5688e56f2df2
diff --git a/jarvis/brain/output_filter.py b/jarvis/brain/output_filter.py
index 15568d07d1..1c03ece4fd 100644
--- a/jarvis/brain/output_filter.py
+++ b/jarvis/brain/output_filter.py
@@ -46,8 +46,18 @@ WHITELIST_WORDS: tuple[str, ...] = (
# Mandate: engineering jargon — standalone words are scrubbed, but not
# inside hyphen-compounds ("Browser-Provider" is anchored to "Browser",
# a user-concept word, so the compound is preserved).
+#
+# 2026-08-18 audit OF-04: "Provider" and "MCP" are REMOVED from this list.
+# Both became ordinary user-facing vocabulary — the app's own UI names brain
+# providers and the MCP connector store — and the excision left a broken clause
+# behind instead of a cleaner sentence ("Der Provider war nicht erreichbar." ->
+# "Der war nicht erreichbar."; a bare "Provider." even fell through to the
+# residue fallback and was spoken as an error). A noun cannot be deleted out of
+# the middle of a sentence by regex; scrubbing it produces worse output than
+# saying it. "Harness" and "Subprocess" stay — they name internals the user has
+# no concept for and never appear as the subject of a user-facing sentence.
JARGON_WORDS: tuple[str, ...] = (
- "Harness", "MCP", "Subprocess", "Provider",
+ "Harness", "Subprocess",
)
# Phase 1 extension 2026-04-28: engineering jargon compounds that, as a whole
@@ -131,6 +141,30 @@ SHELL_COMMAND_RE = re.compile(
re.IGNORECASE,
)
+# 2026-08-18 audit OF-03: a SINGLE signature hit used to replace the WHOLE answer
+# with the generic error phrase, which destroyed every shell how-to the user
+# asked for ("In PowerShell liest du eine Variable mit $env:PATH aus." -> "Es
+# trat ein Fehler auf."). The maintainer is a developer; "$env:", "[System.X]::Y",
+# "Add-Type" and "bash -c" are normal parts of a CORRECT spoken answer. The guard
+# now asks a second question before firing: is this text a COMMAND, or a SENTENCE
+# that mentions one? The distinction is token shape, not token count — a command
+# line is dominated by code tokens (flags, brackets, quotes, paths, ``::``),
+# while an explanation is dominated by plain words.
+#
+# A token counts as CODE when it carries a character that spoken prose never
+# has (brace/bracket/angle/pipe/backslash/dollar/equals/semicolon/quote/backtick,
+# a ``::`` scope operator, a ``/`` path-or-flag separator) or when it is a
+# ``-Flag`` / ``--flag``. A token counts as PROSE when it is nothing but letters
+# plus optional trailing punctuation. Everything else (numbers, dotted
+# identifiers, hyphenated names like "Add-Type") counts as neither, so it can
+# neither rescue a command nor condemn a sentence.
+_SHELL_CODE_TOKEN_RE = re.compile(r"[{}\[\]<>|\\$=;\"'`]|::|/|^-{1,2}[A-Za-z]")
+_SHELL_PROSE_TOKEN_RE = re.compile(r"^[^\W\d_]{2,}[.,!?;:)\]\"']*$")
+# A sentence needs a real clause worth of plain words before it earns the
+# exemption, and the plain words must clearly outweigh the code tokens.
+MIN_PROSE_TOKENS_FOR_SHELL_EXEMPTION = 4
+PROSE_TO_CODE_RATIO_FOR_SHELL_EXEMPTION = 2
+
# Tool-call patterns:
# 1) tool_name({"...": "..."}) — function-call form (OpenAI)
# 2) tool_name{"...": "..."} — Anthropic tool-use inline
@@ -152,8 +186,14 @@ TOOL_NAMES: tuple[str, ...] = (
"verify_via_curl", "verify_localhost", "start_preview_server",
)
+# 2026-08-18 audit OF-06: this used to be ``\b\w+\s*\(\s*\{…\}\s*\)`` — ANY word
+# followed by parentheses with braces, despite the comment above promising a
+# conservative, tool-name-anchored set. It deleted ordinary sentences that named
+# a function ("Rufe berechne({\"a\": 1}) auf, dann bist du fertig." -> "Rufe auf,
+# dann bist du fertig."). Now anchored on TOOL_NAMES like patterns 4 and 5, so
+# the promise in the comment is the actual behaviour.
TOOL_CALL_FN_RE = re.compile(
- r"\b\w+\s*\(\s*\{[^{}]*\}\s*\)",
+ r"\b(?:" + "|".join(TOOL_NAMES) + r")\s*\(\s*\{[^{}]*\}\s*\)",
)
TOOL_CALL_INLINE_RE = re.compile(
r"\b\w+\{\"[^\"]+\"\s*:[^}]*\}",
@@ -226,14 +266,35 @@ TOOL_CALL_PROSE_RE = re.compile(
)
# Fallback: individual "<key> is <value>" phrases with tool-arg keys,
# even without a tool-name prefix (the brain may have omitted the tool name).
+#
+# 2026-08-18 audit OF-05: the key list is SPLIT by ambiguity. "utterance",
+# "context_hints", "tool_hint" and "step_id" are tool vocabulary that never
+# occurs in a spoken sentence, so one occurrence still identifies a leak. But
+# "action" and "target" are ordinary English words, and a single one of them
+# swallowed up to 400 characters of a correct answer ("Status: action is delayed
+# until tomorrow because the server is down." -> "Status:."). They now only
+# count inside a CHAIN — an "<key> is <value>" phrase directly followed by
+# another one — which is the shape the F-AUDIT-4 leak actually had and which an
+# ordinary sentence does not have.
TOOL_ARGS_PROSE_KEYS: tuple[str, ...] = (
"utterance", "context_hints", "context hints",
- "action", "target", "tool_hint", "tool hint",
- "step_id", "step id",
+ "tool_hint", "tool hint", "step_id", "step id",
)
+TOOL_ARGS_PROSE_AMBIGUOUS_KEYS: tuple[str, ...] = (
+ "action", "target",
+)
+_UNAMBIGUOUS_ARG_KEYS = "|".join(re.escape(k) for k in TOOL_ARGS_PROSE_KEYS)
+_AMBIGUOUS_ARG_KEYS = "|".join(re.escape(k) for k in TOOL_ARGS_PROSE_AMBIGUOUS_KEYS)
+_ANY_ARG_KEY = _UNAMBIGUOUS_ARG_KEYS + "|" + _AMBIGUOUS_ARG_KEYS
TOOL_ARGS_PROSE_RE = re.compile(
- r"\b(?:" + "|".join(re.escape(k) for k in TOOL_ARGS_PROSE_KEYS) + r")"
- r"\s+is\s+[^.\n]{1,400}",
+ r"\b(?:"
+ # tool-only vocabulary — a single "<key> is <value>" is already a leak
+ r"(?:" + _UNAMBIGUOUS_ARG_KEYS + r")\s+is\s+[^.\n]{1,400}"
+ r"|"
+ # ordinary words — only as the head of a chain of >= 2 arg phrases
+ r"(?:" + _AMBIGUOUS_ARG_KEYS + r")\s+is\s+[^.\n]{1,400}?"
+ r"\b(?:" + _ANY_ARG_KEY + r")\s+is\s+[^.\n]{1,400}"
+ r")",
re.IGNORECASE,
)
LONG_BASE64_RE = re.compile(
@@ -263,6 +324,20 @@ MORE_RESULTS_RE = re.compile(
# plain word that happens to contain a dot).
BARE_WWW_RE = re.compile(r"\bwww\.\S+", re.IGNORECASE)
+# 2026-08-18 audit OF-07: the URL/domain passes used to DELETE the token, which
+# left the preposition in front of it dangling ("Die Doku steht auf https://…
+# und erklaert alles." -> "Die Doku steht auf und erklaert alles."). A spoken
+# sentence needs an object where the link stood, so the link is REPLACED by a
+# spoken placeholder instead of cut out. The source itself still never reaches
+# TTS — the 2026-06-28 forensic was about the scheme, path and domain being read
+# out character by character, and none of that survives. Runtime-output-language
+# doctrine: all supported locales, no German default for a Spanish-pinned user.
+SOURCE_LINK_PLACEHOLDER: dict[str, str] = {
+ "de": "der Website", # i18n-allow: spoken German placeholder (runtime voice output)
+ "en": "the website",
+ "es": "el sitio web",
+}
+
# Markdown
MARKDOWN_BOLD_RE = re.compile(r"\*\*")
MARKDOWN_HEADER_RE = re.compile(r"^\s*#{1,6}\s+", re.MULTILINE)
@@ -440,6 +515,35 @@ class ScrubResult:
fallback_used: bool = False
+def _has_meaningful_content(text: str) -> bool:
+ """``True`` when ``text`` still carries something worth speaking.
+
+ Same threshold the post-scrub residue guard uses. Prose-shaping passes call
+ it BEFORE committing their substitution, so a filter can never be the reason
+ the whole answer disappears (2026-08-18 audit OF-02).
+ """
+ return sum(1 for c in text if c.isalnum()) >= MIN_MEANINGFUL_CHARS
+
+
+def _is_prose_mentioning_code(text: str) -> bool:
+ """``True`` when ``text`` is a SENTENCE that mentions a command, not a command.
+
+ Token-shape heuristic behind the shell guard's prose exemption — see the
+ comment at ``_SHELL_CODE_TOKEN_RE``. Regex-only, no LLM (mandate § "DO NOT").
+ """
+ prose = 0
+ code = 0
+ for token in text.split():
+ if _SHELL_CODE_TOKEN_RE.search(token):
+ code += 1
+ elif _SHELL_PROSE_TOKEN_RE.match(token):
+ prose += 1
+ return (
+ prose >= MIN_PROSE_TOKENS_FOR_SHELL_EXEMPTION
+ and prose > PROSE_TO_CODE_RATIO_FOR_SHELL_EXEMPTION * code
+ )
+
+
def scrub_for_voice(
text: str, *, language: str = "de", ack_mode: bool = False
) -> ScrubResult:
@@ -495,7 +599,10 @@ def scrub_for_voice(
# sentence, so the whole text is replaced rather than partially stripped
# (a half-spoken command is worse than the generic phrase). Live bug
# 2026-06-28: TTS read a SendKeys PowerShell command aloud verbatim.
- if SHELL_COMMAND_RE.search(text):
+ # Exemption (audit OF-03, 2026-08-18): a text whose tokens are dominated
+ # by plain words is an ANSWER that mentions a command, not a command —
+ # the developer asked how to read $env:PATH and must get the answer.
+ if SHELL_COMMAND_RE.search(text) and not _is_prose_mentioning_code(text):
fallback = FALLBACK_PHRASES.get(language, FALLBACK_PHRASES["de"])
return ScrubResult(
cleaned=fallback,
@@ -556,13 +663,20 @@ def scrub_for_voice(
# 3b. Web-search source artefacts — URLs, bare www-domains, and the
# "Weitere Ergebnisse von <domain>" / "more results from <domain>" SERP
# footer. The brain may read a raw search hit aloud instead of answering
- # (live forensic 2026-06-28, Turn 4). The footer is cut BEFORE the bare
- # www-domain so "von www.x.de" goes as one unit. Fail-closed defense; the
- # real fix is the search_web answer_instruction that tells the brain to
- # synthesize. Real spoken prose carries no http:// or www. token.
- new = URL_RE.sub("", out)
- new = MORE_RESULTS_RE.sub("", new)
- new = BARE_WWW_RE.sub("", new)
+ # (live forensic 2026-06-28, Turn 4). The footer is cut FIRST, whole, so
+ # "von www.x.de" / "from https://x.de" goes as one unit — it is a SERP
+ # artefact, not a link the sentence refers to. A link the sentence DOES
+ # refer to is replaced by a spoken placeholder rather than deleted, so
+ # the preposition in front of it keeps its object (audit OF-07). Neither
+ # the scheme, the path nor the domain ever reaches TTS. Fail-closed
+ # defense; the real fix is the search_web answer_instruction that tells
+ # the brain to synthesize.
+ placeholder = SOURCE_LINK_PLACEHOLDER.get(
+ language, SOURCE_LINK_PLACEHOLDER["de"]
+ )
+ new = MORE_RESULTS_RE.sub("", out)
+ new = URL_RE.sub(placeholder, new)
+ new = BARE_WWW_RE.sub(placeholder, new)
if new != out:
actions.append("removed_source_artifacts")
out = new
@@ -577,8 +691,14 @@ def scrub_for_voice(
# is noting/saving something or reviewing the last transcription/answer; it
# happens silently in the background (maintainer mandate 2026-06-28). Cut the
# whole narration clause (DE/EN/ES). Runs in both normal + ack mode.
+ #
+ # 2026-08-18 audit OF-02: the strip only commits when OTHER content survives
+ # in the same text. "Ich merke mir das." IS the whole answer — a confirmation
+ # the user asked for — and stripping it emptied the text, which then hit the
+ # residue guard and came back as "Es trat ein Fehler auf.". The mandate is
+ # "don't ANNOUNCE bookkeeping alongside the answer", not "never confirm".
new = BACKGROUND_ACTION_RE.sub("", out)
- if new != out:
+ if new != out and _has_meaningful_content(new):
actions.append("removed_background_action_narration")
out = new
@@ -699,4 +819,5 @@ __all__ = [
"JARGON_WORDS",
"OPENER_BUDGET",
"FALLBACK_PHRASES",
+ "SOURCE_LINK_PLACEHOLDER",
]
diff --git a/tests/unit/brain/test_output_filter.py b/tests/unit/brain/test_output_filter.py
index 2277af3cb3..f29eea50d8 100644
--- a/tests/unit/brain/test_output_filter.py
+++ b/tests/unit/brain/test_output_filter.py
@@ -970,3 +970,209 @@ def test_shell_guard_does_not_destroy_normal_prose(clean: str) -> None:
# Hyphen compounds, ranges and ordinary speech must NOT trip the guard.
result = scrub_for_voice(clean, language="de")
assert result.fallback_used is False
+
+
+# ---------------------------------------------------------------------------
+# Audit 2026-08-18 — over-broad filters that destroyed CORRECT answers.
+#
+# Every case below was measured against the real function before the fix. Each
+# pattern keeps its protection (the guard tests above still pass); what changed
+# is that a single ambiguous token no longer condemns the whole answer.
+# ---------------------------------------------------------------------------
+
+
+# --- OF-03: one shell signature nuked the entire answer --------------------
+
+
+ "text",
+ [
+ # The measured failure: became "Es trat ein Fehler auf." in full.
+ "In PowerShell liest du eine Variable mit $env:PATH aus.", # i18n-allow
+ "Mit Add-Type laedst du eine .NET-Assembly nach, dann geht das.", # i18n-allow
+ "Du kannst das mit cmd /c start discord jederzeit selbst starten.", # i18n-allow
+ "Read the variable with $env:PATH and the shell prints the value.",
+ "The static call [System.Math]::Round rounds the number for you.",
+ ],
+)
+def test_shell_guard_exempts_prose_that_mentions_a_command(text: str) -> None:
+ """OF-03: an ANSWER about a command is not a command.
+
+ The maintainer is a developer — ``$env:``, ``[System.X]::Y``, ``Add-Type``
+ and ``cmd /c`` are normal parts of a correct spoken how-to. The guard now
+ weighs token shape: plain words must clearly outweigh code tokens.
+ """
+ result = scrub_for_voice(text, language="de")
+ assert result.fallback_used is False
+ assert "Es trat ein Fehler auf" not in result.cleaned # i18n-allow
+ assert "replaced_shell_command" not in result.actions
+
+
+ "text",
+ [
+ # A command line stays fail-closed even with a few word-shaped tokens.
+ "cmd /c start discord",
+ "powershell -Command \"Start-Process notepad -ArgumentList 'C:\\tmp\\f.txt'\"",
+ 'bash -c "echo hallo"',
+ ],
+)
+def test_shell_guard_still_refuses_a_bare_command_line(text: str) -> None:
+ """OF-03 regression floor: the protection must not have been traded away."""
+ result = scrub_for_voice(text, language="de")
+ assert result.fallback_used is True
+ assert "replaced_shell_command" in result.actions
+
+
+# --- OF-02: a legitimate confirmation came back as an error ----------------
+
+
+def test_background_narration_alone_is_spoken_not_turned_into_an_error() -> None:
+ """OF-02: "Ich merke mir das." was replaced by "Es trat ein Fehler auf.".
+
+ The mandate is "do not ANNOUNCE bookkeeping alongside the answer", not
+ "never confirm". When the narration IS the whole text, the user explicitly
+ asked for that confirmation — the strip only commits when other content
+ survives.
+ """
+ for text in (
+ "Ich merke mir das.", # i18n-allow
+ "Ich notiere mir das.", # i18n-allow
+ "I am noting that down.",
+ "Tomo nota.",
+ ):
+ result = scrub_for_voice(text, language="de")
+ assert result.fallback_used is False, text
+ assert result.cleaned == text, text
+ assert "removed_background_action_narration" not in result.actions, text
+
+
+# --- OF-05: two ordinary English words ate 400 characters ------------------
+
+
+ "text",
+ [
+ # The measured failure: everything after the colon was deleted.
+ "Status: action is delayed until tomorrow because the server is down.",
+ "The target is the second shelf on the left side of the room.",
+ "Your action is required before Friday, otherwise the booking expires.",
+ ],
+)
+def test_ambiguous_arg_word_alone_is_not_a_tool_leak(text: str) -> None:
+ """OF-05: 'action'/'target' are ordinary words — one alone is not a leak."""
+ result = scrub_for_voice(text, language="en")
+ assert "removed_tool_json" not in result.actions
+ assert result.cleaned == text
+
+
+def test_ambiguous_arg_words_in_a_chain_are_still_removed() -> None:
+ """OF-05 regression floor: the F-AUDIT-4 shape is a CHAIN of arg phrases,
+ and that is exactly what still gets cut — even without a tool-name prefix."""
+ text = ( # i18n-allow
+ "Ich versuche es. action is das Projekt analysiert "
+ "target is Arbeitsordner. Fertig."
+ )
+ result = scrub_for_voice(text, language="de")
+ assert "action is" not in result.cleaned
+ assert "target is" not in result.cleaned
+ assert "removed_tool_json" in result.actions
+ assert "Fertig" in result.cleaned # i18n-allow
+
+
+# --- OF-06: any word followed by (braces) was deleted ----------------------
+
+
+def test_ordinary_function_call_in_prose_survives() -> None:
+ """OF-06: 'berechne({"a": 1})' is not a tool call — the sentence stays."""
+ text = 'Rufe berechne({"a": 1}) auf, dann bist du fertig.' # i18n-allow
+ result = scrub_for_voice(text, language="de")
+ assert "berechne(" in result.cleaned
+ assert "auf, dann bist du fertig" in result.cleaned # i18n-allow
+
+
+def test_tool_name_fn_call_with_nested_paren_is_still_removed() -> None:
+ """OF-06 regression floor: the fn-call form still fires for a REAL tool
+ name, including the nested-paren body that the keyword-args pattern alone
+ would only half-cut."""
+ text = 'Ich starte das: spawn_worker({"utterance": "sag :)"}) und melde mich.' # i18n-allow
+ result = scrub_for_voice(text, language="de")
+ assert "spawn_worker" not in result.cleaned
+ assert "utterance" not in result.cleaned
+ assert "removed_tool_json" in result.actions
+ assert "melde mich" in result.cleaned # i18n-allow
+
+
+# --- OF-04: 'Provider' / 'MCP' are ordinary user-facing words now ----------
+
+
+ "text",
+ [
+ "Der Provider war nicht erreichbar.", # i18n-allow
+ "Provider.",
+ "Der MCP Store zeigt alle Verbindungen.", # i18n-allow
+ "Ich habe den Provider gewechselt.", # i18n-allow
+ ],
+)
+def test_provider_and_mcp_are_no_longer_scrubbed_as_jargon(text: str) -> None:
+ """OF-04: excising the noun left a broken clause ("Der war nicht
+ erreichbar.") and a bare "Provider." even fell through to the error phrase.
+ Both words name things the app's own UI shows the user."""
+ result = scrub_for_voice(text, language="de")
+ assert result.cleaned == text
+ assert result.fallback_used is False
+ assert "removed_engineering_jargon" not in result.actions
+
+
+def test_remaining_jargon_words_are_still_scrubbed() -> None:
+ """OF-04 regression floor: 'Subprocess' / 'Harness' name internals the user
+ has no concept for and stay on the list."""
+ for text in ("Der Subprocess ist fertig.", "Das Harness ist gestartet."): # i18n-allow
+ result = scrub_for_voice(text, language="de")
+ assert "removed_engineering_jargon" in result.actions, text
+ assert "subprocess" not in result.cleaned.lower(), text
+ assert "harness" not in result.cleaned.lower(), text
+
+
+# --- OF-07: deleting a URL left the preposition dangling -------------------
+
+
+def test_url_is_replaced_by_a_spoken_placeholder_not_deleted() -> None:
+ """OF-07: "Die Doku steht auf <url> und erklaert alles." lost its object
+ and became "Die Doku steht auf und erklaert alles.". The link is now
+ replaced by a placeholder, so the sentence still parses when spoken."""
+ text = "Die Doku steht auf https://docs.python.org und erklaert alles." # i18n-allow
+ result = scrub_for_voice(text, language="de")
+ assert "http" not in result.cleaned.lower()
+ assert "docs.python.org" not in result.cleaned.lower()
+ assert "auf der Website und erklaert alles" in result.cleaned # i18n-allow
+ assert "removed_source_artifacts" in result.actions
+
+
+ ("language", "expected"),
+ [("de", "der Website"), ("en", "the website"), ("es", "el sitio web")],
+)
+def test_url_placeholder_is_localized(language: str, expected: str) -> None:
+ """Runtime-output-language doctrine: the placeholder table carries every
+ supported locale — a Spanish-pinned user never hears the German one."""
+ from jarvis.brain.output_filter import SOURCE_LINK_PLACEHOLDER
+
+ assert set(SOURCE_LINK_PLACEHOLDER) >= {"de", "en", "es"}
+ result = scrub_for_voice("Mehr dazu auf https://example.org heute.", language=language)
+ assert expected in result.cleaned
+ assert "example.org" not in result.cleaned
+
+
+def test_serp_footer_is_still_deleted_whole_not_placeholdered() -> None:
+ """OF-07 regression floor: the "Weitere Ergebnisse von <domain>" footer is a
+ SERP artefact, not a link the sentence refers to — it goes as one unit, with
+ no placeholder left behind."""
+ text = "Note 2 gibt es ab 34,5 Punkten. Weitere Ergebnisse von www.gutefrage.net"
+ result = scrub_for_voice(text, language="de")
+ low = result.cleaned.lower()
+ assert "gutefrage" not in low
+ assert "weitere ergebnisse" not in low
+ assert "website" not in low
+ assert "removed_source_artifacts" in result.actions