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(voice): keep heard text stable as captions grow

rubenluetke10-beepb9e1c006cb34
diff --git a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts
index 77526db434..17f7893963 100644
--- a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts
+++ b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.test.ts
@@ -13,6 +13,25 @@ afterEach(() => {
});
describe("playback-confirmed spoken cursor", () => {
+ it("preserves heard prefixes when captions grow ahead of metadata or are truncated", () => {
+ setTimedSpeechSession("growing");
+ publishTimedSpeechPlayback("live:growing:answer", "One two", 3);
+ const { result, rerender } = renderHook(({ text }) => useSpokenCursor(text, true, "live:growing:answer"), {
+ initialProps: { text: "One two" },
+ });
+ expect(result.current).toBe(3);
+ rerender({ text: "One two three" });
+ expect(result.current).toBe(3);
+ act(() => publishTimedSpeechPlayback("live:growing:answer", "One two three", 7));
+ expect(result.current).toBe(7);
+ rerender({ text: "One two" });
+ expect(result.current).toBe(7);
+ rerender({ text: "Different words" });
+ expect(result.current).toBe(0);
+ act(() => publishTimedSpeechPlayback("live:growing:unicode", "A😀", 3));
+ const unicode = renderHook(() => useSpokenCursor("A😎", true, "live:growing:unicode"));
+ expect(unicode.result.current).toBe(1);
+ });
it("keeps a new bus caption grey before the audio socket's metadata arrives", () => {
setTimedSpeechSession("current");
const { result } = renderHook(() => useSpokenCursor("New caption", true, "live:current:new"));
diff --git a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts
index da009849ae..48e855db20 100644
--- a/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts
+++ b/jarvis/ui/web/frontend/src/components/home/useSpokenCursor.ts
@@ -14,7 +14,18 @@ export function useSpokenCursor(text: string, eligible: boolean, lineId = ""): n
const session = useSyncExternalStore(subscribeSpeechPlayback, readTimedSpeechSession);
const bound = useRef<{ id: number; text: string; chars: number } | null>(null);
if (bound.current && bound.current.text !== text) bound.current = null;
- if (timed?.text === text) bound.current = { id: -1, text, chars: timed.chars };
+ if (timed) {
+ // Caption snapshots can grow or be truncated before their timing frame
+ // arrives. Preserve the confirmed common prefix instead of flashing grey.
+ let chars = timed.text === text ? timed.chars : 0;
+ if (timed.text !== text) {
+ const limit = Math.min(timed.chars, text.length);
+ while (chars < limit && timed.text[chars] === text[chars]) chars++;
+ const last = text.charCodeAt(chars - 1);
+ if (last >= 0xd800 && last <= 0xdbff) chars--; // Never split a surrogate pair.
+ }
+ bound.current = { id: -1, text, chars };
+ }
else if (!bound.current && eligible && session && lineId.startsWith(`live:${session}:`)) {
// The bus caption and audio-control socket can arrive in either order.
// A fresh caption stays grey until its playback metadata catches up.