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(society): keep voice history on the voice surface
rubenluetke10-beep46febdedcaf4
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsxindex 824243a3f0..a84adc03d1 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.switch.test.tsx@@ -1,4 +1,4 @@-import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";+import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";import { afterEach, beforeEach, expect, it, vi } from "vitest";import { EMPTY_TIMELINE, type Timeline, type UserItem } from "@/components/agentchat/reduce";@@ -12,10 +12,16 @@ import {import { useAgentChatStore } from "@/store/agentChat";import { useEventStore } from "@/store/events";import type { AgentChatSession } from "@/lib/agentChatApi";+import { useHomeStore } from "@/store/home";+import { JarvisHistoryRail } from "./JarvisHistoryRail";-vi.mock("@/i18n", () => ({ useT: () => (key: string) => key }));+vi.mock("@/i18n", () => ({ useT: () => (key: string) => key, fill: (text: string) => text }));vi.mock("./AgentModelPicker", () => ({ AgentModelPicker: () => null }));-vi.mock("@/components/home/VoiceStage", () => ({ VoiceStage: () => <div data-testid="voice-stage" /> }));+vi.mock("@/components/home/JarvisBar", () => ({ JarvisBar: () => <div data-testid="jarvis-bar" /> }));+vi.mock("@/components/home/Greeting", () => ({ Greeting: () => <div>Greeting</div> }));+vi.mock("@/components/agentic/useVoiceCall", () => ({ useVoiceCall: () => ({ connecting: false }) }));+vi.mock("@/hooks/useVoiceReadiness", () => ({ useVoiceReadiness: () => ({ connected: true, warming: false }) }));+vi.mock("@/hooks/useWakeWord", () => ({ useWakeWord: () => ({ config: { phrase: "Hey Jarvis" } }) }));vi.mock("../data", async (original) => ({...(await original<typeof import("../data")>()),useSocietyCapabilities: () => ({ isLoading: false, data: [] }),@@ -85,6 +91,9 @@ const visual = agent({ agentId: "visual-qa", name: "Visual QA" });const gmail = agent({ agentId: "gmail-agent", name: "Gmail Agent" });beforeEach(() => {+ useHomeStore.setState({ transcript: [], liveReply: "", jarvisCardMode: "voice", freshVoicePending: false });+ useEventStore.setState({ activeKind: "text", activeThreadId: null, messages: [], voiceState: "idle" });+ vi.stubGlobal("ResizeObserver", class { observe() {} unobserve() {} disconnect() {} });Element.prototype.scrollIntoView = vi.fn();vi.stubGlobal("WebSocket", FakeSocket);vi.stubGlobal(@@ -159,3 +168,37 @@ it("keeps Jarvis on a fresh chat when history refreshes or the card is reopened"render(<AgentChatPanel agent={jarvis} roster={[jarvis]} />);expect(useAgentChatStore.getState().activeSessionId).toBeNull();});++it("reads archived calls on the actual voice stage and returns there fresh after hangup while closed", async () => {+ const jarvis = agent({ agentId: "jarvis", name: "Jarvis", tier: "lead" });+ const voice = { kind: "voice", id: "voice-archive", title: "Archived call", preview: "", created_ms: 1, updated_ms: 2, message_count: 2 };+ vi.mocked(fetch).mockImplementation(async (url) => {+ const path = String(url);+ if (path.includes("/api/chats?")) return new Response(JSON.stringify([voice]));+ if (path.includes("/voice/voice-archive/resume")) return new Response(JSON.stringify({ ...voice, messages: [+ { role: "user", text: "Archived question", ts_ms: 1 },+ { role: "assistant", text: "Archived answer", ts_ms: 2 },+ ] }));+ return new Response(JSON.stringify({ providers: [], sessions: [], mapping: [] }));+ });+ const view = render(<><AgentChatPanel agent={jarvis} roster={[jarvis]} /><JarvisHistoryRail /></>);+ fireEvent.click(await screen.findByTestId("jarvis-history-voice-row"));+ expect(await screen.findByText("Archived question")).toBeTruthy();+ expect(screen.getByText("Archived answer")).toBeTruthy();+ expect(screen.getByTestId("society-chat").getAttribute("data-mode")).toBe("voice");+ expect(screen.getByTestId("jarvis-bar")).toBeTruthy();+ expect(screen.queryByTestId("voice-thread-stage")).toBeNull();+ fireEvent.click(screen.getByTestId("society-jarvis-mode-chat"));+ fireEvent.click(screen.getByTestId("society-jarvis-mode-voice"));+ expect(screen.getByText("Archived question")).toBeTruthy();+ view.unmount();+ act(() => {+ setJarvisCardMode("chat");+ useHomeStore.getState().ingest("VoiceSessionEnded", { hangup_reason: "hotkey" }, 3);+ });+ render(<AgentChatPanel agent={jarvis} roster={[jarvis]} />);+ expect(screen.getByTestId("society-chat").getAttribute("data-mode")).toBe("voice");+ expect(screen.getByTestId("voice-stage").getAttribute("data-empty")).toBe("true");+ expect(screen.queryByText("Archived question")).toBeNull();+ await waitFor(() => expect(fetch).toHaveBeenCalledWith("/api/chats/voice/new", { method: "POST" }));+});diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsxindex 9b976f57d7..a593b0b02d 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx@@ -20,7 +20,7 @@ import { InternalMessageBubble } from "@/components/agentchat/InternalMessageBub* the voice runs on the realtime tier (`[brain.realtime]`), which no text* runner can drive. The header says so while voice is showing.*/-import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import { MessageSquare, Mic, Paperclip, Plus, RotateCcw, Send, Square } from "lucide-react";import { ChatMarkdown, MediaPreview, mediaKind } from "@/components/agentchat/ChatMarkdown";@@ -36,8 +36,7 @@ import { DictationStatus } from "@/components/agentchat/DictationStatus";import { useComposerDictation } from "@/components/agentchat/useComposerDictation";import { useEventStore } from "@/store/events";import { useHomeStore } from "@/store/home";-import { VoiceThreadStage } from "@/components/home/VoiceThreadStage";-import { transcriptFromMessages } from "@/lib/homeTranscript";+import { startNewVoiceRun } from "@/lib/chatsApi";import type {NoticeItem,TimelineItem,@@ -104,38 +103,18 @@ export const useSocietyChatStore = createAgentChatStore("society");type JarvisCardMode = "chat" | "voice";-/** Remembered for the app session, so a card reopened stays on the half you last used. */-let lastJarvisCardMode: JarvisCardMode = "chat";-const modeListeners = new Set<() => void>();-+/** The lead card and its history share the voice lifecycle, even while closed. */export function getJarvisCardMode(): JarvisCardMode {- return lastJarvisCardMode;+ return useHomeStore.getState().jarvisCardMode;}-/**- * Switch the lead card's Voice | Chat half from anywhere — the column's own- * switch and the history rail in the Options column share this, so opening a- * row there lands on the half that shows it.- */export function setJarvisCardMode(next: JarvisCardMode): void {- if (lastJarvisCardMode === next) return;- lastJarvisCardMode = next;- for (const notify of [...modeListeners]) notify();+ useHomeStore.getState().setJarvisCardMode(next);}-/** The lead card's Voice | Chat half. */export function useJarvisCardMode(): JarvisCardMode {- return useSyncExternalStore(- (notify) => {- modeListeners.add(notify);- return () => {- modeListeners.delete(notify);- };- },- getJarvisCardMode,- );+ return useHomeStore((s) => s.jarvisCardMode);}-/*** The transcript a specialist column may paint. One store serves every* specialist, so the chrome (name, rail, composer) can already show the@@ -307,14 +286,20 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {.catch(() => undefined);}, [loadSessions]);- // A spoken thread opened from the history rail: read here, in the column- // the composer would otherwise own — the same sharing the front page's- // chat stage does (components/home/ChatStage).- const voiceThreadId = useEventStore((s) => (s.activeKind === "voice" ? s.activeThreadId : null));- const voiceMessages = useEventStore((s) => s.messages);const setActiveConversation = useEventStore((s) => s.setActiveConversation);const setMessages = useEventStore((s) => s.setMessages);- const seedTranscript = useHomeStore((s) => s.seedTranscript);+ const voiceState = useEventStore((s) => s.voiceState);+ const freshVoicePending = useHomeStore((s) => s.freshVoicePending);++ useEffect(() => {+ if (!freshVoicePending || voiceState !== "idle" || !useHomeStore.getState().freshVoicePending) return;+ useHomeStore.setState({ freshVoicePending: false });+ // Use the existing reset contract once after hangup, including re-entry+ // after the card was closed. Never interrupt a call started elsewhere.+ void startNewVoiceRun().catch(() => {+ useEventStore.getState().pushToast("error", `${t("sidebar.new_voice_chat")}: ${t("voice_state.error")}`);+ });+ }, [freshVoicePending, voiceState, t]);// A null session is an intentional fresh chat. Only an explicit history// selection may open an older session; polling must not undo New chat.@@ -333,10 +318,6 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {newChat();}, [newChat, setActiveConversation, setMessages]);- const continueByVoice = useCallback(() => {- seedTranscript(transcriptFromMessages(voiceMessages));- pickMode("voice");- }, [seedTranscript, voiceMessages]);if (mode === "voice") {return (@@ -374,22 +355,6 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {</div>);- // A spoken thread from the history rail, read in place — no composer, like- // the front page: a recording is continued by speaking.- if (voiceThreadId && !activeSessionId) {- return (- <div- className="flex h-full min-h-0 flex-col"- data-testid="society-chat"- data-mode="chat"- data-thread={voiceThreadId}- >- {header}- <VoiceThreadStage onContinueByVoice={continueByVoice} />- </div>- );- }-return (<div className="flex h-full min-h-0 flex-col" data-testid="society-chat" data-mode="chat">{header}diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsxindex 83091695b4..0d5a449026 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.test.tsx@@ -2,7 +2,7 @@* The lead card's history rail: typed chats and voice sessions as two lists,* opening in place — never navigating away from the card.*/-import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";+import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { JarvisHistoryRail } from "@/components/society/chat/JarvisHistoryRail";@@ -75,7 +75,10 @@ describe("JarvisHistoryRail", () => {vi.fn(async (url: string, init?: RequestInit) => {const path = String(url);if (path.includes("/api/chats/voice/")) {- return json({ kind: "voice", id: "voice-1", title: "Evening call", messages: [] });+ return json({ kind: "voice", id: "voice-1", title: "Evening call", messages: [+ { role: "user", text: "Previous spoken question", ts_ms: 1 },+ { role: "assistant", text: "Previous spoken answer", ts_ms: 2 },+ ] });}if (path.includes("/api/chats?")) {return json([voiceSummary()]);@@ -130,6 +133,25 @@ describe("JarvisHistoryRail", () => {fireEvent.click(await screen.findByTestId("jarvis-history-voice-row"));expect(useAgentChatStore.getState().activeSessionId).toBeNull();expect(useEventStore.getState().activeThreadId).toBe("voice-1");+ await waitFor(() => expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual([+ "Previous spoken question", "Previous spoken answer",+ ]));+ expect(setJarvisCardMode).toHaveBeenCalledWith("voice");+ });++ test("a late archive response cannot restore the previous call after hangup", async () => {+ let finish!: (response: Response) => void;+ render(<JarvisHistoryRail />);+ await screen.findByTestId("jarvis-history-voice-row");+ vi.mocked(fetch).mockImplementationOnce(() => new Promise<Response>((resolve) => { finish = resolve; }));+ fireEvent.click(screen.getByTestId("jarvis-history-voice-row"));+ await act(async () => {+ useHomeStore.getState().ingest("VoiceSessionEnded", { hangup_reason: "hotkey" }, 5);+ finish(json({ kind: "voice", id: "voice-1", messages: [{ role: "user", text: "Stale archive", ts_ms: 1 }] }));+ });+ await waitFor(() => expect((screen.getByTestId("jarvis-history-voice-row")).getAttribute("data-active")).toBeNull());+ expect(useHomeStore.getState().transcript).toEqual([]);+ expect(useEventStore.getState().messages).toEqual([]);});test("the new button clears whatever is open", async () => {diff --git a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsxindex e9c456cc2b..2e9fbdc152 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/JarvisHistoryRail.tsx@@ -7,6 +7,7 @@ import { useAgentChatStore } from "@/store/agentChat";import { useEventStore } from "@/store/events";import { useHomeStore } from "@/store/home";import { startNewVoiceRun } from "@/lib/chatsApi";+import { transcriptFromMessages } from "@/lib/homeTranscript";import { CONVERSATIONS_REFRESH_MS, useConversations } from "@/hooks/useConversations";import { formatChatWhen } from "@/components/home/chatRows";import { setJarvisCardMode } from "./AgentChatPanel";@@ -55,10 +56,14 @@ export function JarvisHistoryRail() {setJarvisCardMode("chat");};- const openVoice = (voiceId: string) => {+ const openVoice = async (voiceId: string) => {useAgentChatStore.getState().newChat();- setJarvisCardMode("chat");- void openConversation("voice", voiceId);+ useHomeStore.getState().seedTranscript([]);+ setJarvisCardMode("voice");+ const messages = await openConversation("voice", voiceId);+ const active = useEventStore.getState();+ if (active.activeKind !== "voice" || active.activeThreadId !== voiceId) return;+ useHomeStore.getState().seedTranscript(transcriptFromMessages(messages));};const startNew = () => {@@ -85,6 +90,7 @@ export function JarvisHistoryRail() {useEventStore.getState().seedThinkingTraces({});useEventStore.getState().setTranscription("", true);useHomeStore.getState().resetTranscript();+ useHomeStore.setState({ freshVoicePending: false });setJarvisCardMode("voice");void refresh();} catch {@@ -173,7 +179,7 @@ export function JarvisHistoryRail() {title={c.title || c.preview || t("society.chat.new_chat")}when={formatChatWhen(c.updated_ms)}active={c.id === voiceThreadId}- onOpen={() => openVoice(c.id)}+ onOpen={() => void openVoice(c.id)}testId="jarvis-history-voice-row"/>))}diff --git a/jarvis/ui/web/frontend/src/hooks/useConversations.ts b/jarvis/ui/web/frontend/src/hooks/useConversations.tsindex d061b8570e..347e83f27a 100644--- a/jarvis/ui/web/frontend/src/hooks/useConversations.ts+++ b/jarvis/ui/web/frontend/src/hooks/useConversations.ts@@ -68,6 +68,8 @@ export function useConversations({ poll = false }: { poll?: boolean } = {}) {}// The stored traces replace the previous conversation's, so a reply// in the new thread never wears the steps of an old one.+ const active = useEventStore.getState();+ if (active.activeKind !== kind || active.activeThreadId !== id) return [];seedThinkingTraces(traces);setMessages(messages);return messages;diff --git a/jarvis/ui/web/frontend/src/store/home.test.ts b/jarvis/ui/web/frontend/src/store/home.test.tsindex bfa736b944..23ae35a75d 100644--- a/jarvis/ui/web/frontend/src/store/home.test.ts+++ b/jarvis/ui/web/frontend/src/store/home.test.ts@@ -1,19 +1,27 @@import { beforeEach, describe, expect, it } from "vitest";import { reduceLiveReply, useHomeStore } from "@/store/home";+import { useEventStore } from "@/store/events";describe("voice conversation boundaries", () => {beforeEach(() => useHomeStore.getState().resetTranscript());it.each(["hotkey", "voice_pattern", "client_stop", "idle_timeout"])("starts a fresh lane after %s", (hangup_reason) => {const home = useHomeStore.getState();+ home.setJarvisCardMode("chat");+ useEventStore.setState({ activeKind: "voice", activeThreadId: "first", transcription: "stale preview", transcriptionFinal: false });home.ingest("TranscriptFinal", { transcript: { text: "Old conversation" } }, 1);home.ingest("AssistantTextDelta", { channel: "voice", text: "Partial reply" }, 2);expect(useHomeStore.getState().transcript.length).toBeGreaterThan(0);home.ingest("VoiceSessionEnded", { session_id: "first", hangup_reason }, 3);expect(useHomeStore.getState().transcript).toEqual([]);expect(useHomeStore.getState().liveReply).toBe("");+ expect(useHomeStore.getState().jarvisCardMode).toBe("voice");+ expect(useHomeStore.getState().freshVoicePending).toBe(true);+ expect(useEventStore.getState().activeThreadId).toBeNull();+ expect(useEventStore.getState().transcription).toBe("");home.ingest("VoiceSessionStarted", { session_id: "second" }, 4);+ expect(useHomeStore.getState().freshVoicePending).toBe(false);home.ingest("TranscriptFinal", { transcript: { text: "New conversation" } }, 5);expect(useHomeStore.getState().transcript.map((line) => line.text)).toEqual(["New conversation"]);});diff --git a/jarvis/ui/web/frontend/src/store/home.ts b/jarvis/ui/web/frontend/src/store/home.tsindex 824a64ecf6..13fb942f9e 100644--- a/jarvis/ui/web/frontend/src/store/home.ts+++ b/jarvis/ui/web/frontend/src/store/home.ts@@ -2,6 +2,7 @@ import { create } from "zustand";import { readHomeSurface, writeHomeSurface, type HomeSurface } from "@/lib/homeSurface";import { reduceTranscript, type TranscriptLine } from "@/lib/homeTranscript";+import { useEventStore } from "@/store/events";/*** The front page's own store: which surface (voice / chat) is on screen, and@@ -15,6 +16,9 @@ import { reduceTranscript, type TranscriptLine } from "@/lib/homeTranscript";* `set` turns into a no-op without waking a single subscriber.*/interface HomeStore {+ jarvisCardMode: "voice" | "chat";+ setJarvisCardMode: (mode: "voice" | "chat") => void;+ freshVoicePending: boolean;surface: HomeSurface;setSurface: (surface: HomeSurface) => void;/** What was said and answered, oldest first (lib/homeTranscript.ts). */@@ -72,6 +76,9 @@ export function reduceLiveReply(current: string, name: string, payload: unknown)}export const useHomeStore = create<HomeStore>((set, get) => ({+ jarvisCardMode: "voice",+ setJarvisCardMode: (jarvisCardMode) => set({ jarvisCardMode }),+ freshVoicePending: false,surface: readHomeSurface(),setSurface: (surface) => {writeHomeSurface(surface);@@ -85,10 +92,23 @@ export const useHomeStore = create<HomeStore>((set, get) => ({// A provider handover continues the same call. A real hangup opens an// empty lane; the completed conversation remains in the history rail.if (reason !== "realtime_fallback" && reason !== "desktop_fallback") {- set({ transcript: [], liveReply: "" });+ const events = useEventStore.getState();+ if (events.activeKind === "voice") {+ events.setActiveConversation("voice", null);+ events.setMessages([]);+ events.seedThinkingTraces({});+ }+ events.setTranscription("", true);+ // Remember this even while the card is closed. Returning to Jarvis+ // must not restore the last archive selection or the typed surface.+ set({ transcript: [], liveReply: "", jarvisCardMode: "voice", freshVoicePending: true });return;}}+ if (name === "VoiceSessionStarted") {+ // A call already started elsewhere must not be ended on card re-entry.+ set({ freshVoicePending: false });+ }const before = get().transcript;const after = reduceTranscript(before, name, payload, tsMs);const live = reduceLiveReply(get().liveReply, name, payload);@@ -96,6 +116,6 @@ export const useHomeStore = create<HomeStore>((set, get) => ({set({ transcript: after, liveReply: live });}},- seedTranscript: (lines) => set({ transcript: lines, liveReply: "" }),+ seedTranscript: (lines) => set({ transcript: lines, liveReply: "", freshVoicePending: false }),resetTranscript: () => set({ transcript: [], liveReply: "" }),}));