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(dictation): stop deleting content words and manufacturing ellipses
Ruben Lütkec043c30eb927
diff --git a/jarvis/dictation/cleanup.py b/jarvis/dictation/cleanup.pyindex 7aa378d551..a5f57d4ea0 100644--- a/jarvis/dictation/cleanup.py+++ b/jarvis/dictation/cleanup.py@@ -1,4 +1,4 @@-"""Deterministic filler-sound removal for dictated text.+"""Deterministic filler-sound removal and punctuation repair for dictated text.Why deterministic and not a model pass--------------------------------------@@ -25,6 +25,20 @@ Words that carry meaning in ordinary speech are excluded on purpose even whenevery style guide calls them filler — English "like", "actually", "basically";German "also", "halt", "eben"; Spanish "este", "pues". Removing those changeswhat was said.++A filler must also be meaningless in EVERY language this module has rules for,+not only in its own. The language tag arrives from the STT provider and is+regularly wrong, so an English list containing "er" is one bad tag away from+deleting every pronoun in a German sentence — and reporting ``applied=True``+while doing it. See the comment on :data:`FILLER_WORDS`.++The second job of this module is punctuation repair (:func:`tidy_transcript`),+and unlike filler removal it runs on EVERY dictation. The damage it repairs is+manufactured by the SEGMENTING transcriber — each ~8 s segment is punctuated+and capitalised on its own and the pieces are then joined with a bare space —+so it is present in transcripts this module never otherwise touches. It is+regex only for the same reason as everything else here: no LLM call ever+happens in this module."""from __future__ import annotations@@ -38,10 +52,24 @@ from dataclasses import dataclass#: Hesitation sounds per language. Keys are lowercase two-letter codes.#: Multi-word entries are matched as a phrase.+#:+#: DE-MINED on 2026-07-29: "er", "ah" and "eh" were removed from the English+#: table and "eh" from the Spanish one. Every style guide calls them hesitation+#: sounds, and in English they are — but "er" is a top-frequency GERMAN pronoun+#: ("he") and "eh" is ordinary German for "anyway". The tag that selects the+#: table is whatever the provider reported, and cloud Whisper endpoints answer+#: "English" for German speech often enough that it is a documented defect, so+#: those three tokens turned a wrong tag into silent deletion of content words:+#: a 45-word German dictation lost all four occurrences of "er" at+#: ``applied=True removed_words=4``, which is 8.9 % — comfortably under the+#: destruction ceiling, so no guard fired and nothing was reported. A token that+#: is a content word in ANY language this module serves does not belong in a+#: list applied on a provider's word. The longer spellings ("erm", "ahh",+#: "ehh") stay: no language spells a word that way.FILLER_WORDS: dict[str, tuple[str, ...]] = {"en": ("uh", "uhh", "uhhh", "um", "umm", "ummm",- "er", "erm", "ah", "ahh", "eh",+ "erm", "ahh","hm", "hmm", "hmmm", "mhm", "mm", "mmm",),"de": ( # i18n-allow: speech-recognition input vocabulary (§1 list #3)@@ -50,7 +78,7 @@ FILLER_WORDS: dict[str, tuple[str, ...]] = {"hm", "hmm", "hmmm", "mhm", "mmh", "mm",),"es": (- "eh", "ehh", "ehhh", "em", "emm",+ "ehh", "ehhh", "em", "emm","mm", "mmm", "ajá", "aja",),}@@ -186,8 +214,14 @@ def _tidy(text: str, *, raw: str) -> str:filler keeps its capital instead of turning into a lowercase sentence)."""out = text- # A removal can leave " , " or " ." — pull the mark back onto the previous word.- out = re.sub(r"\s+([,.;:!?])", r"\1", out)+ # A removal can leave " , " or " ." — pull the mark back onto the previous+ # word. The ``\.(?!\.)`` is not decoration: the naive ``[,.;:!?]`` version of+ # this rule pulled the space out of "gesprochen. ... ist" and produced+ # "gesprochen.... ist" — a defect this module MANUFACTURED on text it had no+ # business touching, seen verbatim in a live dictation on 2026-07-28. A dot+ # that another dot follows is part of an ellipsis, never a mark to reattach;+ # ``tidy_transcript`` decides what to do with it.+ out = re.sub(r"\s+([,;:!?]|\.(?!\.))", r"\1", out)# Two marks that ended up adjacent ("..,") collapse to the first.out = re.sub(r"([,;:])\s*([,.;:!?])", r"\2", out)out = re.sub(r"[ \t]{2,}", " ", out)@@ -276,6 +310,132 @@ def clean_transcript()+# ---------------------------------------------------------------------------+# Punctuation repair at the segment joins+# ---------------------------------------------------------------------------++#: What a recognizer emits at a pause: a run of two or more dots, or the single+#: "…" glyph. Both spellings occur, sometimes in the same transcript.+_ELLIPSIS = r"(?:\.{2,}|…)"++#: A sentence terminator with a recognizer ellipsis glued to it, either directly+#: ("gesprochen...") or across the space a segment join left ("gesprochen. ...").+#: The ``(?<=\w)`` lookbehind is load-bearing: it demands a WORD before the+#: terminator, so the first dot of a free-standing " ... " can never be mistaken+#: for the terminator and the speaker's own ellipsis survives the rule.+_JOINED_ELLIPSIS_RE = re.compile(r"(?<=\w)([.!?])[ \t]*" + _ELLIPSIS)++#: The same artifact spelled with the "…" glyph, which carries no terminator to+#: keep: "gesprochen… ist". Only repaired when text follows — a trailing "…"+#: ends nothing and may well be what the speaker meant.+_ATTACHED_GLYPH_RE = re.compile(r"(?<=\w)…(?=[ \t]+\S)")++#: A free-standing ellipsis between two segments. Whether it is an artifact or+#: the speaker's own pause is undecidable from the text alone, so the decision+#: is made in :func:`_repair_standalone_ellipsis` on the ONE signal that exists:+#: the recognizer capitalises the start of every segment.+_STANDALONE_ELLIPSIS_RE = re.compile(+ r"(?<=\w)[ \t]+" + _ELLIPSIS + r"[ \t]+(?=(?P<next>\w))"+)++#: EXACTLY two dots, not part of a longer run. ".." is always a join artifact;+#: "..." is an ellipsis and must not be reduced to it one dot at a time.+_DOUBLE_DOT_RE = re.compile(r"(?<!\.)\.[ \t]*\.(?!\.)")++#: ".," / "., " / ".;" — a sentence terminator that a weak mark follows. The+#: terminator wins: it is the stronger claim about where the sentence ended.+_TERMINATOR_THEN_WEAK_RE = re.compile(r"([.!?])[ \t]*[,;:]+")++#: ",." / ",," — a weak mark that any mark follows; the second one wins. The+#: ``(?!\.)`` keeps the rule off an ellipsis that merely stands after a comma.+_WEAK_THEN_MARK_RE = re.compile(r"[,;:][ \t]*([,;:.!?])(?!\.)")++#: A space in front of a full stop. Deliberately period-only: French sets a+#: space before "?", "!", ":" and ";" on purpose, and this function runs on+#: every language.+_SPACE_BEFORE_PERIOD_RE = re.compile(r"[ \t]+(\.(?!\.))")++_DOUBLE_SPACE_RE = re.compile(r"[ \t]{2,}")++#: A sentence start a segment join left lower-case. ``(?<=\w\w)`` requires two+#: word characters in front of the terminator, which keeps the rule off single+#: letter abbreviations ("z. B. das") and off the tail dot of an ellipsis.+_SENTENCE_START_RE = re.compile(r"(?<=\w\w)([.!?])([ \t]+)([^\W\d_])")+++def _repair_standalone_ellipsis(match: re.Match[str]) -> str:+ """A free-standing ellipsis is only a join artifact when a segment follows.++ The recognizer capitalises the first word of every segment it produces, so+ an upper-case continuation after " ... " means a new segment began there and+ the ellipsis is ours to remove. A lower-case continuation is the speaker+ trailing off mid-sentence, and that stays exactly as dictated.+ """+ if not match.group("next").isupper():+ return match.group(0)+ return ". "+++def _upper_sentence_start(match: re.Match[str]) -> str:+ return match.group(1) + match.group(2) + match.group(3).upper()+++def tidy_transcript(text: str) -> str:+ """Repair the punctuation a SEGMENTED transcription leaves behind. Never raises.++ This runs on every dictation, not only on one a filler was removed from.+ The damage is not made here: the lane transcribes in ~8 s segments, the+ recognizer punctuates and capitalises each one as if it were the whole+ utterance, emits its own trailing "..." wherever a segment cut a sentence in+ half, and the pieces are then joined with a bare space. So a transcript no+ rule in this module ever touched still arrives with a stray "..." parked+ between two sentences and the next one starting lower-case — which is why+ gating the repair on "a filler was removed" left the common case broken.++ Four repairs, in this order:++ 1. an ellipsis glued to a sentence terminator collapses into that terminator;+ 2. a free-standing ellipsis before a capitalised word becomes a full stop;+ 3. adjacent terminal marks ("..", ".,", "., ") de-duplicate, stronger wins;+ 4. a lower-case word after a sentence terminator gets its capital back.++ THE TRADE-OFF, stated plainly+ -----------------------------+ Nothing in the text says whether an ellipsis came from the recognizer or+ from the speaker, so the split is drawn where it is cheapest to be wrong:++ * an **attached** ellipsis ("gesprochen... ist") is treated as an artifact+ and collapsed — a speaker who dictated a trailing pause there loses it;+ * a **free-standing** ellipsis ("das war ... schwierig") is kept, unless the+ next word is capitalised, which only a segment boundary produces.++ Rule 4 has a matching cost: it capitalises after an abbreviation that ends+ in a period and is at least two letters long ("etc. and" -> "etc. And").+ Both errors are cosmetic and visible; the errors they prevent — a doubled+ "...." in the middle of a sentence, a paragraph of lower-case sentence+ starts — are the ones users actually report.++ Returns the text unchanged on anything unexpected: a repair that eats a+ dictation is worse than a transcript that reads slightly wrong.+ """+ original = text or ""+ if not original.strip():+ return original+ try:+ out = _JOINED_ELLIPSIS_RE.sub(r"\1", original)+ out = _ATTACHED_GLYPH_RE.sub(".", out)+ out = _STANDALONE_ELLIPSIS_RE.sub(_repair_standalone_ellipsis, out)+ out = _DOUBLE_DOT_RE.sub(".", out)+ out = _TERMINATOR_THEN_WEAK_RE.sub(r"\1", out)+ out = _WEAK_THEN_MARK_RE.sub(r"\1", out)+ out = _SPACE_BEFORE_PERIOD_RE.sub(r"\1", out)+ out = _DOUBLE_SPACE_RE.sub(" ", out)+ out = _SENTENCE_START_RE.sub(_upper_sentence_start, out)+ return out.strip()+ except Exception: # noqa: BLE001 — a broken rule must never eat the dictation+ return original++__all__ = ["FILLER_WORDS","SUPPORTED_LANGUAGES",@@ -283,4 +443,5 @@ __all__ = ["clean_transcript","count_words","normalize_language",+ "tidy_transcript",]diff --git a/tests/unit/dictation/test_cleanup.py b/tests/unit/dictation/test_cleanup.pyindex d1da3014da..3e5ba8ebbe 100644--- a/tests/unit/dictation/test_cleanup.py+++ b/tests/unit/dictation/test_cleanup.py@@ -35,7 +35,9 @@ from jarvis.dictation.cleanup import ("Das ist wirklich gut geworden.", # i18n-allow: German fixture under test (§1 list #4)),(- "Eh, creo que em deberíamos enviarlo.",+ # "ehh", not "eh" — see test_a_filler_must_be_meaningless_in_every+ # _supported_language for why the short spelling is gone.+ "Ehh, creo que em deberíamos enviarlo.","es","Creo que deberíamos enviarlo.",),@@ -86,21 +88,74 @@ def test_filler_inside_a_word_is_not_touched() -> None:assert clean_transcript(text, language="en").text == text+# --------------------------------------------------------------------------+# A wrong language tag must not be able to delete content words+# --------------------------------------------------------------------------+#+# The tag that picks the filler table comes from the STT provider, and cloud+# Whisper endpoints report "English" for German speech often enough that the+# repo treats it as a documented defect. So the tables have to survive being+# applied to the wrong language: a token that means something in one supported+# language may not sit in another one's list.+++def test_german_text_tagged_english_keeps_its_pronouns() -> None:+ """The exact damage that got "er" removed from the English table.++ Measured on the live module before the fix: this shape of sentence came+ back with every "er" deleted at ``applied=True removed_words=4``, which was+ 8.9 % of the words — under the destruction ceiling, so nothing flagged it+ and the user was handed a mutilated sentence reported as a clean success.+ """+ text = "Er hat gesagt, er kommt und er bringt es mit." # i18n-allow: fixture (§1 #4)+ result = clean_transcript(text, language="English")+ assert result.removed_words == 0+ assert result.text == text+++def test_german_eh_survives_a_spanish_tag() -> None:+ """The mirror hole: Spanish "eh" against German "eh" ("anyway")."""+ text = "Das mache ich eh morgen, das ist eh klar." # i18n-allow: fixture (§1 #4)+ result = clean_transcript(text, language="es")+ assert result.removed_words == 0+ assert result.text == text+++ ("token", "language", "why"),+ [+ # i18n-allow: the tokens below are the vocabulary under test (§1 list #4)+ ("er", "en", "a top-frequency German pronoun"),+ ("eh", "en", "ordinary German for 'anyway'"),+ ("eh", "es", "ordinary German for 'anyway'"),+ ("ah", "en", "a spoken interjection that carries meaning of its own"),+ ],+)+def test_a_filler_must_be_meaningless_in_every_supported_language(+ token: str, language: str, why: str+) -> None:+ """Structural guard: re-adding one of these re-opens the hole above."""+ assert token not in FILLER_WORDS[language], (+ f"{token!r} is {why} and must not sit in the {language!r} filler list — "+ f"one wrong provider language tag deletes it silently"+ )++# --------------------------------------------------------------------------# The destruction ceiling# --------------------------------------------------------------------------def test_all_filler_input_is_refused_rather_than_emptied() -> None:- result = clean_transcript("um uh er", language="en")+ result = clean_transcript("um uh umm", language="en")assert result.applied is Falseassert result.reason == "ceiling"- assert result.text == "um uh er"+ assert result.text == "um uh umm"def test_absolute_cap_refuses_a_short_sentence_losing_too_many_words() -> None:# 8 words, 4 of them filler -> past the absolute cap for short texts.- text = "um uh er ah the plan is ready"+ text = "um uh umm uhh the plan is ready"result = clean_transcript(text, language="en")assert result.applied is Falseassert result.reason == "ceiling"diff --git a/tests/unit/dictation/test_tidy_transcript.py b/tests/unit/dictation/test_tidy_transcript.pynew file mode 100644index 0000000000..c0e374825c--- /dev/null+++ b/tests/unit/dictation/test_tidy_transcript.py@@ -0,0 +1,218 @@+"""Punctuation repair at the segment joins — ``cleanup.tidy_transcript``.++The dictation lane transcribes in ~8 s segments and joins them with a bare+space, while the recognizer punctuates and capitalises every segment as if it+were the whole utterance. Everything tested here is damage that arrangement+manufactures: a doubled "....", a lower-case sentence start, a stray ellipsis+where a segment cut a sentence in half.++The negative tests carry the same weight as the positive ones. A repair that+deletes an ellipsis the speaker actually dictated is worse than the artifact it+was written to remove, so "an intentional pause survives" is pinned as hard as+"the artifact is gone".+"""+from __future__ import annotations++import re++import pytest++from jarvis.dictation.cleanup import clean_transcript, tidy_transcript++# The live transcript this whole repair exists for. Recorded on 2026-07-28 at+# 18:50:05: two segments joined, the second one preceded by the ellipsis the+# recognizer emitted when the first segment cut the sentence.+LIVE_JOIN = "Ich habe äh gesprochen. ... ist, ist das gut." # i18n-allow: fixture (§1 #4)+LIVE_JOIN_CLEANED = "Ich habe gesprochen. ... ist, ist das gut." # i18n-allow: fixture+LIVE_JOIN_TIDIED = "Ich habe gesprochen. Ist, ist das gut." # i18n-allow: fixture+++# --------------------------------------------------------------------------+# The doubled "...." — our own bug, pinned in both directions+# --------------------------------------------------------------------------+++def test_the_historical_rule_really_did_manufacture_four_dots() -> None:+ """Reproduce the defect byte-for-byte so the fix cannot be undone silently.++ ``_tidy`` used to pull a space back onto ANY following mark with+ ``\\s+([,.;:!?])``. Against a following ellipsis that ate the space in front+ of the first dot and glued it to the sentence that had already ended.+ """+ historical_rule = re.compile(r"\s+([,.;:!?])")+ assert historical_rule.sub(r"\1", "Ich habe gesprochen. ... ist") == (+ "Ich habe gesprochen.... ist"+ )+++def test_filler_removal_no_longer_glues_the_following_ellipsis() -> None:+ """The same input through the shipped path keeps the dots apart."""+ result = clean_transcript(LIVE_JOIN, language="de")+ assert result.applied is True+ assert "...." not in result.text+ assert result.text == LIVE_JOIN_CLEANED+++def test_a_space_before_a_lone_period_is_still_pulled_back() -> None:+ """The narrowed rule must not stop doing the job it was written for."""+ result = clean_transcript("The meeting is at four um.", language="en")+ assert result.text == "The meeting is at four."+++def test_the_live_join_ends_up_clean_after_the_full_pass() -> None:+ cleaned = clean_transcript(LIVE_JOIN, language="de")+ assert tidy_transcript(cleaned.text) == LIVE_JOIN_TIDIED+++# --------------------------------------------------------------------------+# It runs unconditionally — the untouched transcript is the common case+# --------------------------------------------------------------------------+++def test_a_transcript_no_cleanup_touched_is_still_tidied() -> None:+ """Gating the repair on "a filler was removed" is why this stayed broken.++ Nothing in this text is a filler, in any language, so ``clean_transcript``+ returns it verbatim — and the join damage would have survived all the way to+ the clipboard under the old, cleanup-gated behaviour.+ """+ raw = "Das ist der erste Teil. ... und es geht weiter." # i18n-allow: fixture+ tidied = "Das ist der erste Teil. Und es geht weiter." # i18n-allow: fixture+ assert clean_transcript(raw, language="de").text == raw+ assert tidy_transcript(raw) == tidied+++def test_a_clean_transcript_is_returned_unchanged() -> None:+ text = "Wir treffen uns morgen um zehn. Bring alles mit." # i18n-allow: fixture+ assert tidy_transcript(text) == text++[email protected]("text", ["", " ", "\n"])+def test_blank_input_is_returned_as_is(text: str) -> None:+ assert tidy_transcript(text) == text+++# --------------------------------------------------------------------------+# Ellipsis collapsing+# --------------------------------------------------------------------------+++ ("text", "expected"),+ [+ # The German fixtures below are the vocabulary under test (§1 #4).+ # Terminator plus a free-standing ellipsis: the join artifact proper.+ ("gesprochen. ... ist das gut", "gesprochen. Ist das gut"), # i18n-allow+ # The already-glued form, in case an older transcript carries it.+ ("gesprochen.... ist das gut", "gesprochen. Ist das gut"), # i18n-allow+ # A word-attached ellipsis: the recognizer's mid-sentence cut.+ ("gesprochen... ist das gut", "gesprochen. Ist das gut"), # i18n-allow+ # The single-glyph spelling of the same thing.+ ("gesprochen… ist das gut", "gesprochen. Ist das gut"), # i18n-allow+ # Free-standing, but the next segment starts on a capital.+ ("gesprochen ... Ist das gut", "gesprochen. Ist das gut"), # i18n-allow+ ],+)+def test_a_segment_join_ellipsis_becomes_one_terminator(+ text: str, expected: str+) -> None:+ assert tidy_transcript(text) == expected+++ "text",+ [+ # The German fixtures below are the vocabulary under test (§1 #4).+ # Free-standing, lower-case continuation: the speaker trailing off.+ "das war ... schwierig und dann ging es weiter", # i18n-allow+ "das war … schwierig und dann ging es weiter", # i18n-allow+ # Same, after a comma — the comma must not swallow the dots either.+ "wir gehen, ... aber nicht heute", # i18n-allow+ "I waited ... and nothing happened",+ ],+)+def test_an_intentional_mid_sentence_ellipsis_survives(text: str) -> None:+ """The failure direction that matters: never delete what was dictated."""+ assert tidy_transcript(text) == text+++# --------------------------------------------------------------------------+# Adjacent terminal punctuation+# --------------------------------------------------------------------------+++ ("text", "expected"),+ [+ ("Hello.. world", "Hello. World"),+ ("Hello., world", "Hello. World"),+ ("Hello,. world", "Hello. World"),+ ("Hello. . world", "Hello. World"),+ ("Hello,, world", "Hello, world"),+ ],+)+def test_adjacent_terminal_marks_de_duplicate(text: str, expected: str) -> None:+ assert tidy_transcript(text) == expected+++def test_a_deliberate_double_mark_is_left_alone() -> None:+ """A "?!" is a thing a person writes; a ".." is not."""+ text = "Was denn?! also gut" # i18n-allow: German fixture under test (§1 #4)+ assert tidy_transcript(text) == text+++# --------------------------------------------------------------------------+# Capitalization at the join+# --------------------------------------------------------------------------+++def test_a_lower_case_sentence_start_gets_its_capital_back() -> None:+ joined = "Erste Sache. zweite Sache." # i18n-allow: fixture under test (§1 #4)+ repaired = "Erste Sache. Zweite Sache." # i18n-allow: fixture under test (§1 #4)+ assert tidy_transcript(joined) == repaired+++def test_the_first_word_of_the_dictation_is_not_touched() -> None:+ """Only a JOIN is repaired. What the speaker opened with is their business."""+ text = "ich fange klein an." # i18n-allow: German fixture under test (§1 #4)+ assert tidy_transcript(text) == text+++ "text",+ [+ # The German fixtures below are the vocabulary under test (§1 #4).+ # Single-letter abbreviations: two word characters are required in front+ # of the terminator, which is exactly what these do not have.+ "z. B. das ist so", # i18n-allow+ # Internal dots: the character before the second dot is not a word char.+ "e.g. this is fine",+ # A decimal point never starts a sentence.+ "der Wert 3.5 kommt danach", # i18n-allow+ ],+)+def test_a_dot_that_does_not_end_a_sentence_capitalizes_nothing(text: str) -> None:+ assert tidy_transcript(text) == text+++def test_a_number_can_still_end_a_sentence() -> None:+ joined = "3.14 ist Pi. das war es" # i18n-allow: fixture under test (§1 #4)+ repaired = "3.14 ist Pi. Das war es" # i18n-allow: fixture under test (§1 #4)+ assert tidy_transcript(joined) == repaired+++# --------------------------------------------------------------------------+# Whitespace+# --------------------------------------------------------------------------+++def test_the_double_space_a_join_leaves_collapses() -> None:+ joined = "erster Teil. zweiter Teil" # i18n-allow: fixture under test (§1 #4)+ repaired = "erster Teil. Zweiter Teil" # i18n-allow: fixture under test (§1 #4)+ assert tidy_transcript(joined) == repaired+++def test_a_french_style_space_before_a_question_mark_survives() -> None:+ """The repair runs on all ~100 recognition languages, not only on de/en/es."""+ text = "Est-ce que tu viens ? je ne sais pas"+ assert tidy_transcript(text) == text