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(dictation): count the words a history already holds

Ruben Lütkeb1f6528edfc9
diff --git a/jarvis/dictation/stats.py b/jarvis/dictation/stats.py
index df9a4e711b..46e44d13ef 100644
--- a/jarvis/dictation/stats.py
+++ b/jarvis/dictation/stats.py
@@ -379,6 +379,14 @@ def summarize_entries(
days: dict[str, DayStat] = {}
for entry in entries or ():
words = _as_int(getattr(entry, "word_count", 0))
+ if words <= 0:
+ # Entries recorded before ``word_count`` existed carry a zero they
+ # never earned, and skipping them made a full history read as "you
+ # have never dictated anything" — the one number this panel exists
+ # to show. Counting the stored transcript recovers them; an entry
+ # that genuinely holds no text (failed, cancelled, empty) still
+ # counts as nothing and is skipped below.
+ words = _words_in_text(entry)
if words <= 0:
continue
day = local_day(getattr(entry, "created_at", "")) or today_key()
@@ -398,6 +406,28 @@ def summarize_entries(
)
+def _words_in_text(entry: Any) -> int:
+ """Word count of an entry's transcript, for rows that never stored one.
+
+ Uses the SAME counter the cleanup and the sidecar use, so a back-filled
+ number is comparable with a recorded one rather than merely similar.
+ Imported lazily: this module is read by REST handlers, and the cleanup
+ module carries the per-language filler tables.
+ """
+ text = str(getattr(entry, "text", "") or "") or str(
+ getattr(entry, "raw_text", "") or ""
+ )
+ if not text.strip():
+ return 0
+ try:
+ from jarvis.dictation.cleanup import count_words
+
+ return max(0, int(count_words(text)))
+ except Exception: # noqa: BLE001 — a missing counter is "no words", never a 500
+ log.debug("word back-fill failed for a history entry", exc_info=True)
+ return 0
+
+
def _as_int(value: Any) -> int:
try:
return max(0, int(value or 0))
diff --git a/tests/unit/dictation/test_dictation_stats.py b/tests/unit/dictation/test_dictation_stats.py
index a518b4d69d..426b76dbf6 100644
--- a/tests/unit/dictation/test_dictation_stats.py
+++ b/tests/unit/dictation/test_dictation_stats.py
@@ -280,3 +280,37 @@ def test_concurrent_recording_loses_no_count(tmp_path: Path) -> None:
totals = DictationStats(path).summary()["totals"]
assert totals["dictations"] == workers * rounds
assert totals["words"] == workers * rounds * 3
+
+
+def test_entries_written_before_word_count_existed_still_count() -> None:
+ """A history from before the stats feature must not read as "never dictated".
+
+ Field report 2026-07-28: every row already on disk carried ``word_count=0``
+ because the field did not exist when it was written, and the derived
+ summary skipped anything with no words. The panel therefore showed 0 words,
+ 0 dictations and a 0-day streak while the list right below it displayed
+ seven real dictations — the single most visible number in the section,
+ wrong for every existing install.
+ """
+ from jarvis.dictation.stats import summarize_entries
+
+ class _Row:
+ def __init__(self, text: str, word_count: int, created_at: str) -> None:
+ self.text = text
+ self.raw_text = text
+ self.word_count = word_count
+ self.created_at = created_at
+ self.duration_s = 2.0
+
+ now = datetime.now(UTC).isoformat()
+ summary = summarize_entries(
+ [
+ _Row("hello there friend", 0, now), # pre-upgrade row
+ _Row("counted already", 2, now), # post-upgrade row
+ _Row("", 0, now), # genuinely empty: still nothing
+ ]
+ )
+
+ assert summary["totals"]["dictations"] == 2
+ assert summary["totals"]["words"] == 5
+ assert summary["today"]["words"] == 5