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.

feat(dictation): carry the resolved delivery target on the transcript event

Ruben Lütke7ee43572ec98
diff --git a/jarvis/core/events.py b/jarvis/core/events.py
index f75cdb019c..15a987f761 100644
--- a/jarvis/core/events.py
+++ b/jarvis/core/events.py
@@ -108,20 +108,31 @@ class TranscriptionUpdate(Event):
@dataclass(frozen=True, slots=True)
class DictationTranscript(Event):
- """Live transcript from the chat composer's mic-dictation button.
+ """Live transcript of a dictation, as it is recognized.
Deliberately a SEPARATE event from ``TranscriptionUpdate`` (which rides the
- live voice critical path). Dictation only fills the chat text input — it
- never reaches the brain — so keeping it on its own event name means the
- frontend can route it straight to the textarea without ever confusing it
- with a real voice turn, and the voice hot-path event stays untouched.
+ live voice critical path). Dictation never reaches the brain, so keeping it
+ on its own event name means the frontend can route it straight to a text
+ field without ever confusing it with a real voice turn, and the voice
+ hot-path event stays untouched.
``is_final=False`` interim hypotheses overwrite the live tail; the single
- ``is_final=True`` is appended to the input box and ends the dictation.
+ ``is_final=True`` ends the dictation.
"""
text: str = ""
is_final: bool = False
+ #: Where the pipeline has decided this transcript belongs, already resolved
+ #: (never ``auto``): ``insert`` = typed into the foreign application in
+ #: front, ``chat`` = handed to Jarvis's own window.
+ #:
+ #: The UI needs this, and needs it on the event rather than by asking: the
+ #: event fires on BOTH routes, so a UI that inserted on every final
+ #: transcript would write a dictation meant for another program into
+ #: whatever Jarvis field last had focus — invisibly, in a section the user
+ #: is not even looking at. Empty on an older backend, which reads as "do not
+ #: insert in-app" and leaves that install exactly as it behaved before.
+ target: str = ""
@dataclass(frozen=True, slots=True)
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
new file mode 100644
index 0000000000..e4fbe1ae84
--- /dev/null
+++ b/tests/unit/conftest.py
@@ -0,0 +1,45 @@
+"""Keep every unit test away from the developer's real polish credentials.
+
+``[dictation].polish`` ships ON, and the pass resolves its provider chain from
+whatever keys the HOST holds. That combination is fine in production and
+poisonous in a test suite: the moment the dictation delivery path grew a polish
+hook, every test that finishes a dictation with a default ``DictationConfig``
+started making a live model call on a machine that happens to have a Groq or
+Gemini key — billing the developer, taking up to the full latency ceiling per
+test, and returning text that is legitimately different every run. On CI, which
+holds no keys at all, the same tests take the empty-chain path and pass
+instantly. A suite whose behaviour depends on who is running it is the AP-23
+inversion in miniature.
+
+So the CONSUMER's view of the chain is emptied for every unit test: the pass
+resolves no family, reports ``unavailable``, and hands back the raw transcript —
+byte-identical to the behaviour before the feature existed, which is exactly
+what the vast majority of these tests are asserting about.
+
+Two things this deliberately does NOT do:
+
+* It does not touch ``jarvis.dictation.polish_client.resolve_polish_chain``.
+ That function is itself under test (key-aware ordering, one entry per family,
+ the pin), and neutralising it would make those tests assert against this
+ fixture instead of against the code.
+* It does not stop a test from polishing. A test that wants the pass to run
+ patches the same attribute in its own body, which happens after this fixture
+ and therefore wins — the pattern the polish-pipeline tests already use.
+
+This lives at the ``tests/unit`` level rather than in the dictation folder on
+purpose: the delivery path is reached from the speech suite and from the REST
+route suite as well, and a guarantee that only covers the tests somebody
+remembered is not a guarantee (the same reasoning as the root conftest's
+history redirect).
+"""
+from __future__ import annotations
+
+import pytest
+
+
[email protected](autouse=True)
+def _polish_pass_holds_no_credentials(monkeypatch: pytest.MonkeyPatch) -> None:
+ """Make the polish pass see an empty provider chain, as a keyless host does."""
+ from jarvis.dictation import polish
+
+ monkeypatch.setattr(polish, "resolve_polish_chain", lambda cfg: ())
diff --git a/tests/unit/dictation/test_delivery_and_bar.py b/tests/unit/dictation/test_delivery_and_bar.py
index 162be74319..e335fc153d 100644
--- a/tests/unit/dictation/test_delivery_and_bar.py
+++ b/tests/unit/dictation/test_delivery_and_bar.py
@@ -166,6 +166,45 @@ async def test_auto_target_is_resolved_at_DELIVERY_time(
assert events[-1].outcome == "chat"
+async def test_final_transcript_says_which_route_it_took(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The UI cannot work this out for itself, and gets it wrong if it guesses.
+
+ The same event fires on BOTH routes. A UI that inserted on every final
+ transcript would take a dictation the backend is already pasting into
+ another program and write it into whatever Jarvis field last had focus —
+ invisibly, in a section nobody is looking at. So the resolved target rides
+ along, and "auto" must never be what arrives: the UI cannot read a
+ foreground window.
+ """
+ import jarvis.dictation.insert as insert_mod
+
+ def _final(events: list[object]) -> DictationTranscript:
+ return [
+ e
+ for e in events
+ if isinstance(e, DictationTranscript) and e.is_final
+ ][-1]
+
+ monkeypatch.setattr(insert_mod, "foreground_is_this_app", lambda: False)
+ pipe, events = _pipeline()
+ await pipe._finish_dictation(
+ raw_text="into the other app", language="en", duration_s=1.0,
+ target="auto", hung_up=False,
+ )
+ assert _final(events).target == "insert"
+
+ monkeypatch.setattr(insert_mod, "foreground_is_this_app", lambda: True)
+ pipe, events = _pipeline()
+ await pipe._finish_dictation(
+ raw_text="into our own window", language="en", duration_s=1.0,
+ target="auto", hung_up=False,
+ )
+ assert _final(events).target == "chat"
+
+
# --------------------------------------------------------------------------
# The failure signal — "the provider refused us" vs "you said nothing"
# --------------------------------------------------------------------------