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(home): the voice stage reads a transcript of its own
rubenluetke10-beepd5d54d6522f1
diff --git a/jarvis/ui/web/frontend/src/components/home/VoiceStage.test.tsx b/jarvis/ui/web/frontend/src/components/home/VoiceStage.test.tsxindex 31274e5bb6..db903474d8 100644--- a/jarvis/ui/web/frontend/src/components/home/VoiceStage.test.tsx+++ b/jarvis/ui/web/frontend/src/components/home/VoiceStage.test.tsx@@ -2,26 +2,19 @@ import { describe, expect, it } from "vitest";import { hintFor, recentLines, waveformPhase } from "@/components/home/VoiceStage";import { greetingKey } from "@/components/home/Greeting";-import type { ChatMessage } from "@/store/events";+import { reduceTranscript, type TranscriptLine } from "@/lib/homeTranscript";const t = (key: string) => key;-function msg(role: ChatMessage["role"], content: string, i: number): ChatMessage {- return { id: `m${i}`, role, content, ts: i };+function line(who: TranscriptLine["who"], text: string, i: number): TranscriptLine {+ return { id: `m${i}`, who, text, ts: i };}describe("VoiceStage helpers", () => {- it("keeps only the last spoken/typed lines, in order", () => {- const all: ChatMessage[] = [- msg("system", "boot", 0),- msg("user", "one", 1),- msg("preamble", "pre", 2),- msg("assistant", "two", 3),- msg("user", "three", 4),- msg("assistant", "four", 5),- ];- expect(recentLines(all, 3).map((m) => m.content)).toEqual(["two", "three", "four"]);- expect(recentLines(all, 10).map((m) => m.content)).toEqual(["one", "two", "three", "four"]);+ it("keeps only the last lines, in order", () => {+ const all = [line("user", "one", 1), line("assistant", "two", 2), line("user", "three", 3)];+ expect(recentLines(all, 2).map((m) => m.text)).toEqual(["two", "three"]);+ expect(recentLines(all, 10).map((m) => m.text)).toEqual(["one", "two", "three"]);});it("maps the voice state onto the waveform phases, idle when offline", () => {@@ -56,3 +49,35 @@ describe("VoiceStage helpers", () => {expect(greetingKey(21)).toBe("home.greeting_evening");});});++describe("homeTranscript reducer", () => {+ it("turns heard words and spoken answers into lines, joining the answer's pieces", () => {+ let lines: TranscriptLine[] = [];+ lines = reduceTranscript(lines, "TranscriptFinal", { transcript: { text: " what time is it " } }, 1000);+ // The final TranscriptionUpdate of the same utterance is not a second line.+ lines = reduceTranscript(lines, "TranscriptionUpdate", { text: "what time is it", is_final: true }, 1200);+ lines = reduceTranscript(lines, "TranscriptionUpdate", { text: "what time", is_final: false }, 1300);+ lines = reduceTranscript(lines, "SpeechSpoken", { text: "It is ten past nine." }, 2000);+ lines = reduceTranscript(lines, "SpeechSpoken", { text: "Shall I set a timer?" }, 3000);+ expect(lines.map((l) => [l.who, l.text])).toEqual([+ ["user", "what time is it"],+ ["assistant", "It is ten past nine. Shall I set a timer?"],+ ]);+ });++ it("takes typed turns from MessageSent and ignores everything else", () => {+ let lines: TranscriptLine[] = [];+ const same = lines;+ lines = reduceTranscript(lines, "BrainTurnCompleted", { tokens_in: 1 }, 1);+ expect(lines).toBe(same);+ lines = reduceTranscript(lines, "MessageSent", { role: "user", text: "hello" }, 10);+ lines = reduceTranscript(lines, "MessageSent", { role: "system", text: "note" }, 11);+ lines = reduceTranscript(lines, "MessageSent", { role: "assistant", text: "hi there" }, 12);+ // A reply that is also spoken is one line, not two.+ lines = reduceTranscript(lines, "SpeechSpoken", { text: "hi there" }, 13);+ expect(lines.map((l) => [l.who, l.text])).toEqual([+ ["user", "hello"],+ ["assistant", "hi there"],+ ]);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx b/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsxindex dac66faa60..e2d5550481 100644--- a/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx+++ b/jarvis/ui/web/frontend/src/components/home/VoiceStage.tsx@@ -1,6 +1,8 @@import { useEffect, useMemo, useRef } from "react";-import { useEventStore, type ChatMessage, type VoiceState } from "@/store/events";+import { useEventStore, type VoiceState } from "@/store/events";+import { useHomeStore } from "@/store/home";+import type { TranscriptLine as TranscriptEntry } from "@/lib/homeTranscript";import { VoiceWaveform, type WaveformPhase } from "@/components/overlay/VoiceWaveform";import { voiceInputLevelRef } from "@/lib/voiceInputLevel";import { useVoiceCall } from "@/components/agentic/useVoiceCall";@@ -23,17 +25,17 @@ const TRANSCRIPT_LINES = 6;* you say the wake word. The bar IS the control — the same start/stop path* the IDE's voice bubble uses, so there is exactly one way voice begins.*- * The transcript lane reads the same `messages` the chat stage shows (a- * spoken turn lands there as MessageSent, like a typed one) plus the live,- * not-yet-final transcription, so what you are saying appears while you say- * it. Older lines scroll away; this is the live turn, not an archive — the- * archive is one click away in the sidebar's recent chats.+ * The transcript lane reads the home store's transcript (lib/homeTranscript:+ * heard words, spoken answers and typed turns merged into one list) plus the+ * live, not-yet-final transcription, so what you are saying appears while+ * you say it. Older lines scroll away; this is the live turn, not an archive+ * — the archive is one click away in the sidebar's recent chats.*/export function VoiceStage() {const t = useT();const assistantName = useEventStore((s) => s.assistantName);const voiceState = useEventStore((s) => s.voiceState);- const messages = useEventStore((s) => s.messages);+ const transcript = useHomeStore((s) => s.transcript);const transcription = useEventStore((s) => s.transcription);const transcriptionFinal = useEventStore((s) => s.transcriptionFinal);const { connected, warming } = useVoiceReadiness();@@ -42,7 +44,7 @@ export function VoiceStage() {const { config: wakeConfig } = useWakeWord();const wakePhrase = wakeConfig?.phrase.trim() || "";- const lines = useMemo(() => recentLines(messages, TRANSCRIPT_LINES), [messages]);+ const lines = useMemo(() => recentLines(transcript, TRANSCRIPT_LINES), [transcript]);const liveLine = transcription && !transcriptionFinal ? transcription : "";const laneEnd = useRef<HTMLDivElement | null>(null);@@ -68,9 +70,9 @@ export function VoiceStage() {{lines.map((m) => (<TranscriptLinekey={m.id}- who={m.role === "user" ? t("home.transcript_you") : assistantName}- text={m.content}- user={m.role === "user"}+ who={m.who === "user" ? t("home.transcript_you") : assistantName}+ text={m.text}+ user={m.who === "user"}/>))}{liveLine && (@@ -113,9 +115,9 @@ export function VoiceStage() {<VoiceWaveformlevelRef={voiceInputLevelRef}phase={phase}- count={28}+ count={32}frame={false}- className="h-12 min-w-0 flex-1"+ className="h-14 min-w-0 flex-1"/><span className="hidden shrink-0 items-center gap-1.5 rounded-full border border-border bg-secondary/60 px-2.5 py-1 font-mono text-[10px] uppercase tracking-[0.12em] text-muted-foreground sm:flex">{engine.providerLabel}@@ -168,14 +170,9 @@ function TranscriptLine({);}-/** The last N spoken/typed lines worth showing: user and assistant only. */-export function recentLines(messages: ChatMessage[], limit: number): ChatMessage[] {- const out: ChatMessage[] = [];- for (let i = messages.length - 1; i >= 0 && out.length < limit; i--) {- const m = messages[i];- if (m.role === "user" || m.role === "assistant") out.push(m);- }- return out.reverse();+/** The last N lines of the transcript, oldest first. */+export function recentLines(lines: TranscriptEntry[], limit: number): TranscriptEntry[] {+ return lines.length > limit ? lines.slice(lines.length - limit) : lines;}export function waveformPhase(state: VoiceState, connected: boolean): WaveformPhase {diff --git a/jarvis/ui/web/frontend/src/components/overlay/VoiceWaveform.tsx b/jarvis/ui/web/frontend/src/components/overlay/VoiceWaveform.tsxindex 48ed4f5c3b..ec974fa55a 100644--- a/jarvis/ui/web/frontend/src/components/overlay/VoiceWaveform.tsx+++ b/jarvis/ui/web/frontend/src/components/overlay/VoiceWaveform.tsx@@ -243,7 +243,10 @@ function VoiceWaveformImpl({return (<svg- viewBox={`0 0 ${VIEW_W} ${VIEW_H}`}+ // Without its frame the drawing is just the row of bars, so the view+ // box tightens to the pill band: the same height then buys a wider,+ // more legible row instead of empty margin above and below it.+ viewBox={frame ? `0 0 ${VIEW_W} ${VIEW_H}` : `0 ${PILL_Y} ${VIEW_W} ${PILL_H}`}className={cn("h-14 w-full", className)}data-testid="voice-waveform"data-phase={phase}diff --git a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts b/jarvis/ui/web/frontend/src/hooks/useWebSocket.tsindex 10291eb0a5..9305e79cb3 100644--- a/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts+++ b/jarvis/ui/web/frontend/src/hooks/useWebSocket.ts@@ -22,6 +22,7 @@ import {COMMAND_ACTIVITY_EVENTS,} from "@/store/commandActivity";import { useDeckStore } from "@/store/deck";+import { useHomeStore } from "@/store/home";import { WSAudioLevel, WSEventEnvelope, WSWelcome } from "@/schema/ws";import { useI18nStore, hydrateUiLanguage, hydrateReplyLanguage, translate } from "@/i18n";import { hydrateUiTheme } from "@/hooks/useTheme";@@ -187,6 +188,13 @@ export function useWebSocket(): void {.getState().ingest(env.event_name, env.payload, Math.floor(env.timestamp_ns / 1_000_000));+ // Front page: the live transcript (heard words, spoken answers,+ // typed turns) the voice stage shows. Same shape of call; the+ // reducer ignores everything but the four text events.+ useHomeStore+ .getState()+ .ingest(env.event_name, env.payload, Math.floor(env.timestamp_ns / 1_000_000));+// Jarvis-Agents dashboard: build the live tree from the Phase-5.5 events.if (SUB_AGENT_EVENT_NAMES.has(env.event_name)) {useSubAgentStorediff --git a/jarvis/ui/web/frontend/src/lib/homeTranscript.ts b/jarvis/ui/web/frontend/src/lib/homeTranscript.tsnew file mode 100644index 0000000000..784839ff41--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/homeTranscript.ts@@ -0,0 +1,99 @@+/**+ * The live transcript the voice stage shows: what was said to the assistant+ * and what it answered, as lines, newest last.+ *+ * Why its own reducer and not `messages`: a SPOKEN turn does not travel as+ * `MessageSent`. The pipeline publishes the heard words as `TranscriptFinal`+ * (and the last `TranscriptionUpdate` with `is_final`), and the answer as+ * `SpeechSpoken` — the authoritative "this was actually said out loud" track,+ * usually in sentence-sized pieces. Typed turns DO come as `MessageSent`.+ * The lane merges the two so it reads the same whether you spoke or typed.+ *+ * Pure: (lines, event) → lines, and the same array back for every event it+ * does not read, so the store can skip the update.+ */++export type TranscriptWho = "user" | "assistant";++export interface TranscriptLine {+ id: string;+ ts: number;+ who: TranscriptWho;+ text: string;+}++/** How many lines are kept. The lane shows the tail; this bounds memory. */+export const TRANSCRIPT_MAX = 40;+/** Consecutive spoken pieces of one answer are joined when this close. */+const JOIN_WITHIN_MS = 6_000;+/** A repeat of the same words within this window is the same utterance. */+const DUPLICATE_WITHIN_MS = 12_000;++let counter = 0;+function nextId(ts: number): string {+ counter = (counter + 1) % 1_000_000;+ return `t${ts}-${counter}`;+}++function clean(text: unknown): string {+ return typeof text === "string" ? text.replace(/\s+/g, " ").trim() : "";+}++function isDuplicate(lines: TranscriptLine[], who: TranscriptWho, text: string, ts: number): boolean {+ for (let i = lines.length - 1; i >= 0; i--) {+ const line = lines[i];+ if (ts - line.ts > DUPLICATE_WITHIN_MS) return false;+ if (line.who === who && (line.text === text || line.text.endsWith(text))) return true;+ }+ return false;+}++function push(lines: TranscriptLine[], who: TranscriptWho, text: string, ts: number): TranscriptLine[] {+ const next = [...lines, { id: nextId(ts), ts, who, text }];+ return next.length > TRANSCRIPT_MAX ? next.slice(next.length - TRANSCRIPT_MAX) : next;+}++export function reduceTranscript(+ lines: TranscriptLine[],+ name: string,+ payload: unknown,+ tsMs: number,+): TranscriptLine[] {+ const p = (payload ?? {}) as Record<string, unknown>;++ switch (name) {+ case "TranscriptFinal": {+ const transcript = (p.transcript ?? {}) as Record<string, unknown>;+ const text = clean(transcript.text);+ if (!text || isDuplicate(lines, "user", text, tsMs)) return lines;+ return push(lines, "user", text, tsMs);+ }+ case "TranscriptionUpdate": {+ if (p.is_final !== true) return lines;+ const text = clean(p.text);+ if (!text || isDuplicate(lines, "user", text, tsMs)) return lines;+ return push(lines, "user", text, tsMs);+ }+ case "SpeechSpoken": {+ const text = clean(p.text);+ if (!text || isDuplicate(lines, "assistant", text, tsMs)) return lines;+ const last = lines[lines.length - 1];+ if (last && last.who === "assistant" && tsMs - last.ts < JOIN_WITHIN_MS) {+ // One answer, said in pieces: grow the line instead of stacking pieces.+ const joined = [...lines];+ joined[joined.length - 1] = { ...last, ts: tsMs, text: `${last.text} ${text}` };+ return joined;+ }+ return push(lines, "assistant", text, tsMs);+ }+ case "MessageSent": {+ const role = p.role;+ if (role !== "user" && role !== "assistant") return lines;+ const text = clean(p.text);+ if (!text || isDuplicate(lines, role, text, tsMs)) return lines;+ return push(lines, role, text, tsMs);+ }+ default:+ return lines;+ }+}diff --git a/jarvis/ui/web/frontend/src/store/home.ts b/jarvis/ui/web/frontend/src/store/home.tsindex c1c8a44426..c44427f84a 100644--- a/jarvis/ui/web/frontend/src/store/home.ts+++ b/jarvis/ui/web/frontend/src/store/home.ts@@ -1,23 +1,40 @@import { create } from "zustand";import { readHomeSurface, writeHomeSurface, type HomeSurface } from "@/lib/homeSurface";+import { reduceTranscript, type TranscriptLine } from "@/lib/homeTranscript";/**- * The front page's own store: which surface (voice / chat) is on screen.+ * The front page's own store: which surface (voice / chat) is on screen, and+ * the live transcript the voice stage shows.** Lives apart from the big event store because it is read by exactly two* places — the sidebar switch that sets it and the home view that renders- * it — and because nothing about it comes over the WebSocket.+ * it. The transcript is fed from the WebSocket hook with one `ingest` call+ * per event, the same way the deck and command-activity stores are; the+ * reducer returns the same array for the (vast) majority of events, which+ * `set` turns into a no-op without waking a single subscriber.*/interface HomeStore {surface: HomeSurface;setSurface: (surface: HomeSurface) => void;+ /** What was said and answered, oldest first (lib/homeTranscript.ts). */+ transcript: TranscriptLine[];+ ingest: (name: string, payload: unknown, tsMs: number) => void;+ /** Tests and a fresh session. */+ resetTranscript: () => void;}-export const useHomeStore = create<HomeStore>((set) => ({+export const useHomeStore = create<HomeStore>((set, get) => ({surface: readHomeSurface(),setSurface: (surface) => {writeHomeSurface(surface);set({ surface });},+ transcript: [],+ ingest: (name, payload, tsMs) => {+ const before = get().transcript;+ const after = reduceTranscript(before, name, payload, tsMs);+ if (after !== before) set({ transcript: after });+ },+ resetTranscript: () => set({ transcript: [] }),}));