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
feat(dictation): deliver paragraphs and lists from the polish pass
rubenluetke10-beep9a20dbadb915
diff --git a/jarvis/dictation/polish_guards.py b/jarvis/dictation/polish_guards.pyindex 456c1b6d72..6a0e6d7bbb 100644--- a/jarvis/dictation/polish_guards.py+++ b/jarvis/dictation/polish_guards.py@@ -172,7 +172,12 @@ _CROSS_SCRIPT_MAX_CHAR_GROWTH = 6.0_TOKEN_RE = re.compile(r"[^\W\d_]+", re.UNICODE)_WORDLIKE_RE = re.compile(r"[\w']+", re.UNICODE)-_WHITESPACE_RE = re.compile(r"\s+", re.UNICODE)+# The two halves of "did anything change at all": a whitespace run CONTAINING a+# line break collapses to one "\n", and every other run collapses to one space.+# Kept apart on purpose — see ``normalize_for_compare`` for why a line break is+# content here and not noise.+_LINE_BREAK_RUN_RE = re.compile(r"\s*\n\s*", re.UNICODE)+_INLINE_SPACE_RE = re.compile(r"[^\S\n]+", re.UNICODE)_DIGIT_RUN_RE = re.compile(r"\d+")# A separator BETWEEN two digits is formatting, not content: "1,000" and "1000"# are the same number, and a formatter is allowed to add or drop the grouping@@ -306,6 +311,13 @@ _COMMON_WORDS_BASE: Final[dict[str, frozenset[str]]] = {# Spoken number words are common vocabulary AND explicitly licensed to vanish:# the prompt asks for "seven" -> "7", so a rarity guard that mourns the missing# word would reject the single transformation the feature was built to make.+#+# The ordinals and enumeration adverbs ("firstly", "erstens", "quinto") are+# here for the same reason: the prompt turns a counted enumeration into a+# numbered list, so the spoken ordinal vanishes into the "1." marker that+# replaces it. A German speaker who counts says "erstens, zweitens, drittens"+# — adverb forms no table here carried, so every counted list was rejected as+# ``lost_term`` and the licensed transformation never survived the guard._NUMBER_WORDS: Final[dict[str, frozenset[str]]] = {"en": frozenset({"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",@@ -313,7 +325,9 @@ _NUMBER_WORDS: Final[dict[str, frozenset[str]]] = {"sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty","forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred","thousand", "million", "billion", "first", "second", "third", "fourth",- "fifth", "half", "quarter", "dozen",+ "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "firstly",+ "secondly", "thirdly", "fourthly", "fifthly", "half", "quarter",+ "dozen",}),"de": frozenset({ # i18n-allow: German number words (§1 list #3)"null", "eins", "zwei", "drei", "vier", "f\u00fcnf", "sechs", "sieben", # i18n-allow@@ -321,8 +335,11 @@ _NUMBER_WORDS: Final[dict[str, frozenset[str]]] = {"f\u00fcnfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn", # i18n-allow"zwanzig", "drei\u00dfig", "dreissig", "vierzig", "f\u00fcnfzig", # i18n-allow"sechzig", "siebzig", "achtzig", "neunzig", "hundert", "tausend", # i18n-allow- "million", "millionen", "erste", "zweite", "dritte", "halb", "viertel", # i18n-allow- "dutzend", # i18n-allow+ "million", "millionen", "erste", "zweite", "dritte", "vierte", # i18n-allow+ "fünfte", "sechste", "siebte", "achte", "neunte", "zehnte", # i18n-allow+ "erstens", "zweitens", "drittens", "viertens", "fünftens", # i18n-allow+ "sechstens", "siebtens", "siebentens", "achtens", "neuntens", # i18n-allow+ "zehntens", "halb", "viertel", "dutzend", # i18n-allow}),"es": frozenset({ # i18n-allow: Spanish number words (§1 list #3)"cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", # i18n-allow@@ -330,7 +347,8 @@ _NUMBER_WORDS: Final[dict[str, frozenset[str]]] = {"diecis\u00e9is", "diecisiete", "dieciocho", "diecinueve", "veinte", # i18n-allow"treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", # i18n-allow"noventa", "cien", "ciento", "mil", "mill\u00f3n", "millones", # i18n-allow- "primero", "segundo", "tercero", "medio", "cuarto", "docena", # i18n-allow+ "primero", "segundo", "tercero", "quinto", "sexto", "séptimo", # i18n-allow+ "octavo", "noveno", "décimo", "medio", "cuarto", "docena", # i18n-allow}),}@@ -387,13 +405,24 @@ _QUANTITY_WORDS: Final[dict[str, frozenset[str]]] = {def normalize_for_compare(text: str) -> str:"""Collapse *text* to the form used to decide "did anything change at all".- Unicode-normalised (NFKC) and whitespace-collapsed, and nothing else:- punctuation and capitalization are exactly what the polish pass is FOR, so- normalising them away would report a successful repunctuation as- ``unchanged`` and throw the result away.+ Unicode-normalised (NFKC), with runs of INLINE whitespace collapsed to one+ space — and nothing else: punctuation, capitalization and line structure are+ exactly what the polish pass is FOR, so normalising them away would report a+ successful repunctuation as ``unchanged`` and throw the result away.++ Line breaks survive as a single ``"\\n"`` on purpose. The pass's paragraph+ and list work is made ENTIRELY of line breaks — a transcript split into+ paragraphs, or an enumeration laid out one item per line, is often the same+ words with only ``"\\n"`` added — and the first version of this function+ collapsed those into spaces, reported the answer as ``unchanged``, and threw+ the only formatting the user asked for on the floor. How a break is spelled+ (``"\\n"``, ``"\\r\\n"``, a blank line) still normalises to one form: the+ comparison cares that the text was split, not which convention split it."""flat = unicodedata.normalize("NFKC", str(text or ""))- return _WHITESPACE_RE.sub(" ", flat).strip()+ flat = flat.replace("\r\n", "\n").replace("\r", "\n")+ flat = _LINE_BREAK_RUN_RE.sub("\n", flat)+ return _INLINE_SPACE_RE.sub(" ", flat).strip()def _compare_tokens(text: str) -> list[str]:diff --git a/jarvis/dictation/polish_prompt.py b/jarvis/dictation/polish_prompt.pyindex b400d5bd63..89efade00c 100644--- a/jarvis/dictation/polish_prompt.py+++ b/jarvis/dictation/polish_prompt.py@@ -38,7 +38,12 @@ from typing import Final#: Bumped whenever the wording below changes in a way that could change model#: behaviour. Stored alongside a polished transcript so a later quality#: regression can be attributed to a prompt revision rather than a provider.-POLISH_PROMPT_VERSION: Final[int] = 3+#:+#: v4: the paragraph and enumeration clauses grew a concrete target format+#: (blank line between paragraphs; one list item per line, "1." when the+#: speaker counted, "-" when they did not). The v3 wording licensed both+#: transformations without describing them, and the model answered with prose.+POLISH_PROMPT_VERSION: Final[int] = 4#: The delimiters that fence the untrusted transcript inside the user message.#: Deliberately ugly and unlikely to be dictated by accident; deliberately@@ -96,11 +101,20 @@ WHAT YOU MAY DO:- Remove filler sounds and repeated words that carry no meaning.- Remove false starts and self-corrections: keep the corrected version, dropthe abandoned one. ("at 2, actually 3" -> "at 3")-- Apply sentence-final punctuation, commas, capitalization and paragraph- breaks. Repair capitalization broken by transcription segment boundaries.+- Apply sentence-final punctuation, commas and capitalization. Repair+ capitalization broken by transcription segment boundaries.+- Break the text into paragraphs where the speaker clearly moved to a new+ thought or topic, and wherever they dictated a break ("new paragraph" and+ its equivalents). Separate paragraphs with ONE blank line.- Turn spoken punctuation commands into the mark ("period", "comma","question mark", "new line", and their equivalents in the input language).-- Turn a spoken enumeration into a list when the speaker clearly enumerated.+- Turn a spoken enumeration into a list when the speaker clearly enumerated:+ one item per line. When the speaker counted ("first", "second", "third" and+ their equivalents in the input language), number the lines "1.", "2.", "3."+ — the number replaces the spoken ordinal. When they listed without+ counting, start each line with "- ". Every item keeps the speaker's own+ words; a running sentence that merely mentions items in passing stays a+ sentence.- Normalize spoken numbers to numerals where a writer would ("seven" -> "7"),but never invent a number that was not spoken.- Remove stray ellipses left by the recognizer at a pause.diff --git a/jarvis/dictation/translate_prompt.py b/jarvis/dictation/translate_prompt.pyindex 3aace9a6e7..d93f480c0f 100644--- a/jarvis/dictation/translate_prompt.py+++ b/jarvis/dictation/translate_prompt.py@@ -45,7 +45,11 @@ from jarvis.dictation.polish_prompt import (#: Bumped whenever the wording below changes in a way that could change model#: behaviour, exactly like ``POLISH_PROMPT_VERSION``.-TRANSLATE_PROMPT_VERSION: Final[int] = 2+#:+#: v3: the paragraph and enumeration clauses carry the same concrete target+#: format the polish prompt's v4 gained — the two passes must lay text out the+#: same way, or the translate switch would silently change list formatting.+TRANSLATE_PROMPT_VERSION: Final[int] = 3#: English names for every code ``[dictation].translate_target`` accepts.#:@@ -137,8 +141,14 @@ CLEAN IT UP AS YOU GO — this is dictated speech, not written prose:only. ("at 2, actually 3" -> "at 3")- Punctuate and capitalize the {target} text properly. Sentence boundaries inthe input may have been broken by the recognizer mid-thought; repair them.+- Break the text into paragraphs where the speaker clearly moved to a new+ thought or topic, and wherever they dictated a break. Separate paragraphs+ with ONE blank line.- Turn spoken punctuation commands into the mark itself, in {target}.-- Turn a spoken enumeration into a list when the speaker clearly enumerated.+- Turn a spoken enumeration into a list when the speaker clearly enumerated:+ one item per line, numbered "1.", "2.", "3." when the speaker counted (the+ number replaces the spoken ordinal), "- " bullets when they did not. A+ running sentence that merely mentions items in passing stays a sentence.- Normalize spoken numbers to numerals where a writer would, but never inventa number that was not spoken.- Drop stray ellipses the recognizer left at a pause.diff --git a/tests/unit/dictation/test_polish_guards.py b/tests/unit/dictation/test_polish_guards.pyindex 5d482664f8..b13443b070 100644--- a/tests/unit/dictation/test_polish_guards.py+++ b/tests/unit/dictation/test_polish_guards.py@@ -254,18 +254,103 @@ def test_a_language_the_detector_cannot_classify_is_never_vetoed() -> None:assert verdict(raw, polished, language="pl") == ""+def test_a_paragraph_split_alone_survives_every_guard() -> None:+ """A transcript split into paragraphs is the same words with "\\n\\n" added.+ No token vanishes, no count moves — nothing here is the guards' business."""+ raw = (+ "the offer went out this morning and I already got a reply next week "+ "we should talk about the invoice and the timeline"+ )+ polished = (+ "The offer went out this morning, and I already got a reply.\n\n"+ "Next week we should talk about the invoice and the timeline."+ )+ assert verdict(raw, polished) == ""+++def test_a_counted_enumeration_may_become_a_numbered_list() -> None:+ """"erstens, zweitens, drittens" -> "1. 2. 3." is the transformation the+ prompt licenses. The spoken ordinal is a number word that may vanish into+ the marker replacing it — the same one-directional trade as "seven" -> "7"+ — and the added digits are legal by the same asymmetry. Before the adverb+ forms joined the German number table, every counted list was rejected as+ ``lost_term`` and the feature looked permanently inert in German."""+ # The German source below is the content UNDER TEST (§1 list #4).+ raw = (+ "wir machen erstens das Angebot fertig zweitens schicken wir die " # i18n-allow+ "Rechnung und drittens bestätigen wir den Termin" # i18n-allow+ )+ polished = (+ "1. Wir machen das Angebot fertig.\n" # i18n-allow+ "2. Wir schicken die Rechnung.\n" # i18n-allow+ "3. Wir bestätigen den Termin." # i18n-allow+ )+ assert detect_text_language(raw) == "de"+ assert verdict(raw, polished, language="de") == ""++ # The same trade in the other two table languages.+ raw_en = (+ "firstly prepare the offer secondly send the invoice thirdly "+ "confirm the appointment"+ )+ polished_en = (+ "1. Prepare the offer.\n2. Send the invoice.\n3. Confirm the appointment."+ )+ assert verdict(raw_en, polished_en) == ""++ # The Spanish source below is the content UNDER TEST (§1 list #4).+ raw_es = (+ "primero revisamos la oferta segundo mandamos la factura tercero " # i18n-allow+ "confirmamos la cita" # i18n-allow+ )+ polished_es = (+ "1. Revisamos la oferta.\n" # i18n-allow+ "2. Mandamos la factura.\n" # i18n-allow+ "3. Confirmamos la cita." # i18n-allow+ )+ assert verdict(raw_es, polished_es, language="es") == ""+++def test_an_uncounted_enumeration_may_become_a_bulleted_list() -> None:+ """A plain spoken listing may come back one item per line with "-" bullets;+ the bullet mark is punctuation, not a token, so no guard has an opinion."""+ # The German source below is the content UNDER TEST (§1 list #4).+ raw = "wir brauchen dafür noch Milch Eier und Butter vom Markt" # i18n-allow+ polished = (+ "Wir brauchen dafür noch vom Markt:\n" # i18n-allow+ "- Milch\n" # i18n-allow+ "- Eier\n" # i18n-allow+ "- Butter" # i18n-allow+ )+ assert verdict(raw, polished, language="de") == ""++# --------------------------------------------------------------------------- ## The helpers the guards are built out of# --------------------------------------------------------------------------- #-def test_normalize_for_compare_collapses_whitespace_but_keeps_punctuation() -> None:+def test_normalize_for_compare_collapses_spaces_but_keeps_punctuation() -> None:"""Punctuation is what the pass ADDS, so normalising it away would report asuccessful repunctuation as "unchanged" and throw the result on the floor."""- assert normalize_for_compare(" a b\n c ") == "a b c"+ assert normalize_for_compare(" a b \t c ") == "a b c"assert normalize_for_compare("hello there") != normalize_for_compare("Hello there.")+def test_normalize_for_compare_keeps_line_breaks() -> None:+ """Line structure is ALSO what the pass adds — paragraphs and list items are+ often the same words with only "\\n" inserted. The first version collapsed+ those into spaces, reported the answer as "unchanged", and threw the only+ formatting the user asked for on the floor. How a break is spelled still+ normalises to one form: the comparison cares that the text was split, not+ which convention split it."""+ flat = "the offer is ready next we send the invoice"+ split = "The offer is ready.\n\nNext we send the invoice."+ assert normalize_for_compare(flat) != normalize_for_compare(split)+ assert normalize_for_compare("a\r\nb") == normalize_for_compare("a\nb")+ assert normalize_for_compare("a \n\n b") == normalize_for_compare("a\nb")++def test_rare_tokens_keeps_names_and_ignores_ordinary_words() -> None:tokens = rare_tokens("deploy the Kubernetes cluster on Tuesday", language="en")assert "kubernetes" in tokensdiff --git a/tests/unit/dictation/test_polish_pipeline.py b/tests/unit/dictation/test_polish_pipeline.pyindex 5c89cf9dd5..a768bfc4b1 100644--- a/tests/unit/dictation/test_polish_pipeline.py+++ b/tests/unit/dictation/test_polish_pipeline.py@@ -164,6 +164,25 @@ async def test_a_model_that_changed_nothing_reports_unchanged(assert outcome.text == RAW+async def test_a_paragraph_break_alone_is_a_change_worth_delivering(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The one formatting job whose entire output is whitespace: the same words+ split into paragraphs. It must be delivered as "applied" — while the+ comparison collapsed line breaks, this exact answer was reported+ "unchanged" and the split was thrown away."""+ split = (+ "So we should probably move the meeting to the morning.\n\n"+ "And tell the team."+ )+ _wire(monkeypatch, chain=(GROQ,), clients=[_FakeClient(reply=split)])++ outcome = await polish_transcript(RAW, language="en", cfg=_Cfg())++ assert outcome.status == "applied"+ assert outcome.text == split++async def test_the_user_pinned_model_is_used_for_the_primary_family(monkeypatch: pytest.MonkeyPatch,) -> None:diff --git a/tests/unit/dictation/test_translate.py b/tests/unit/dictation/test_translate.pyindex ac3ddb59cb..473ef8505a 100644--- a/tests/unit/dictation/test_translate.py+++ b/tests/unit/dictation/test_translate.py@@ -520,6 +520,31 @@ def test_numbers_and_names_must_survive_a_translation() -> None:)+def test_a_counted_enumeration_may_cross_as_a_numbered_list() -> None:+ """The polish prompt's list layout and the translate prompt's are ONE+ format (the v4/v3 parity): a German "erstens, zweitens" that comes back as+ English "1.", "2." lines must survive the translate guard. The spoken+ ordinal vanished into the marker that replaced it, and the added digits+ are legal by the same one-directional number rule the polish guard has."""+ # The German source below is the content UNDER TEST (§1 list #4).+ raw = (+ "wir machen erstens das Angebot fertig und zweitens schicken wir " # i18n-allow+ "die Rechnung raus" # i18n-allow+ )+ translated = "1. We finish the offer.\n2. We send out the invoice."+ assert (+ translate_drift_reason(+ raw,+ translated,+ target_language="en",+ protected=(),+ max_shrink=0.40,+ max_growth=2.50,+ )+ == ""+ )++def test_a_model_that_answered_instead_of_translating_is_caught() -> None:assert (translate_drift_reason(