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(chat): redesign composer dictation as an in-place recording pill

rubenluetke10-beep630fdd78914b
diff --git a/jarvis/ui/web/frontend/src/components/ChatInput.tsx b/jarvis/ui/web/frontend/src/components/ChatInput.tsx
index 234e57e998..3681d375b1 100644
--- a/jarvis/ui/web/frontend/src/components/ChatInput.tsx
+++ b/jarvis/ui/web/frontend/src/components/ChatInput.tsx
@@ -1,12 +1,12 @@
import { useEffect, useRef, useState, type KeyboardEvent } from "react";
-import { ArrowUp, Mic, Square } from "lucide-react";
+import { ArrowUp } from "lucide-react";
import { getWSClient } from "@/hooks/useWebSocket";
import { useVoiceEngineDisplay } from "@/hooks/useVoiceEngineDisplay";
import { useAutoGrowTextarea } from "@/hooks/useAutoGrowTextarea";
import { useEventStore } from "@/store/events";
import { cn } from "@/lib/utils";
import { useT } from "@/i18n";
-import { DictationStatus } from "@/components/agentchat/DictationStatus";
+import { DictationButton } from "@/components/agentchat/DictationButton";
// Safety net: if the brain doesn't respond within 60s (no reply, no error event),
// we revert the indicator. A backend hang must not leave the UI stuck in the
@@ -177,9 +177,6 @@ export function ChatInput() {
"transition-[box-shadow] focus-within:ring-2 focus-within:ring-border-strong",
)}
>
- {/* Listening is a live state, and life is green — the shared strip owns
- that rule now, plus the clock and its own way out. */}
- <DictationStatus onStop={stopDictation} />
<textarea
// Marks the composer as the app's fallback dictation sink. The
// delivery path needs to know whether it is on screen at all before
@@ -191,7 +188,9 @@ export function ChatInput() {
onChange={(e) => setValue(e.target.value)}
onKeyDown={onKeyDown}
placeholder={
- connected
+ dictating
+ ? t("chats_view.dictation_listening")
+ : connected
? t("chats_view.input_placeholder")
: wsWarming
? t("voice_state.booting")
@@ -204,22 +203,13 @@ export function ChatInput() {
className="max-h-[50vh] w-full resize-none bg-transparent px-1 py-1 text-reading text-foreground scrollbar-jarvis placeholder:text-faint-foreground focus-visible:outline-none disabled:opacity-50"
/>
<div className="flex items-center gap-row">
- <button
- type="button"
- data-jarvis-dictation-trigger
- onClick={toggleDictation}
+ <DictationButton
+ dictating={dictating}
+ onToggle={toggleDictation}
disabled={!connected}
- aria-label={dictating ? t("chats_view.dictation_stop") : t("chats_view.dictation_start")}
- title={dictating ? t("chats_view.dictation_stop") : t("chats_view.dictation_start")}
- className={cn(
- "inline-flex h-8 w-8 items-center justify-center rounded-md transition-colors disabled:opacity-50",
- dictating
- ? "animate-jarvis-pulse bg-secondary text-success"
- : "text-muted-foreground hover:bg-secondary hover:text-foreground",
- )}
- >
- {dictating ? <Square className="h-4 w-4" /> : <Mic className="h-4 w-4" />}
- </button>
+ startLabel={t("chats_view.dictation_start")}
+ stopLabel={t("chats_view.dictation_stop")}
+ />
<span className="flex-1" />
<button
type="button"
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index a6f162858c..d74c52d8c4 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -8,7 +8,6 @@ import {
FolderOpen,
Gauge,
Hammer,
- Mic,
NotebookPen,
Paperclip,
ShieldCheck,
@@ -31,7 +30,7 @@ import { usePasteRescue } from "@/components/agentchat/usePasteRescue";
import { useComposerTypeahead } from "@/components/agentchat/useComposerTypeahead";
import { ComposerTypeahead } from "@/components/agentchat/ComposerTypeahead";
import { ChatAttachmentStrip } from "@/components/agentchat/ChatAttachmentStrip";
-import { DictationStatus } from "@/components/agentchat/DictationStatus";
+import { DictationButton } from "@/components/agentchat/DictationButton";
import { ComposerAddMenu } from "@/components/agentchat/ComposerAddMenu";
import { ComposerChipField, type ComposerChipFieldHandle } from "@/components/agentchat/ComposerChipField";
import type { ToolChoice } from "@/components/agentchat/toolChoices";
@@ -439,7 +438,9 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
(!running || commands.canSteer) &&
(!busy || commands.canSteer) &&
Boolean(provider?.connected);
- const placeholder = connected
+ const placeholder = dictating
+ ? t("chats_view.dictation_listening")
+ : connected
? t("agent_chat.placeholder")
: wsWarming
? t("voice_state.booting")
@@ -469,9 +470,6 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
{t("agent_chat.attach_drop_hint")}
</div>
)}
- {/* The blue variant of this strip lived here; a running microphone is a
- live state, not the accent, so it now shares the one green strip. */}
- <DictationStatus onStop={stopDictation} />
<ChatCommandPanel control={commands} anchorRef={cardRef} />
<ChatAttachmentStrip
attachments={files.attachments}
@@ -693,22 +691,13 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
>
<Paperclip className="h-4 w-4" />
</button>
- <button
- type="button"
- data-jarvis-dictation-trigger
- onClick={toggleDictation}
+ <DictationButton
+ dictating={dictating}
+ onToggle={toggleDictation}
disabled={!connected}
- aria-label={dictating ? t("chats_view.dictation_stop") : t("chats_view.dictation_start")}
- title={dictating ? t("chats_view.dictation_stop") : t("chats_view.dictation_start")}
- className={cn(
- "inline-flex h-8 w-8 items-center justify-center rounded-lg border transition-colors disabled:opacity-50",
- dictating
- ? "border-success/40 bg-success/10 text-success motion-safe:animate-jarvis-pulse"
- : "border-transparent text-muted-foreground hover:bg-secondary hover:text-foreground",
- )}
- >
- {dictating ? <Square className="h-4 w-4" /> : <Mic className="h-4 w-4" />}
- </button>
+ startLabel={t("chats_view.dictation_start")}
+ stopLabel={t("chats_view.dictation_stop")}
+ />
{live && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
<button
type="button"
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.test.tsx
new file mode 100644
index 0000000000..56a19a9173
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.test.tsx
@@ -0,0 +1,74 @@
+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import { DictationButton, formatElapsed } from "@/components/agentchat/DictationButton";
+
+function renderButton(dictating: boolean, onToggle = vi.fn()) {
+ return render(
+ <DictationButton
+ dictating={dictating}
+ onToggle={onToggle}
+ startLabel="Dictate"
+ stopLabel="Stop dictation"
+ />,
+ );
+}
+
+describe("DictationButton", () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ });
+ afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ });
+
+ test("idle, it is only the microphone and starts a dictation", () => {
+ const onToggle = vi.fn();
+ renderButton(false, onToggle);
+ expect(screen.queryByTestId("dictation-status")).toBeNull();
+ const mic = screen.getByTestId("dictation-button");
+ expect(mic.getAttribute("aria-label")).toBe("Dictate");
+ expect(mic.hasAttribute("data-jarvis-dictation-trigger")).toBe(true);
+ fireEvent.click(mic);
+ expect(onToggle).toHaveBeenCalledTimes(1);
+ });
+
+ test("live, it announces itself, shows the waveform and counts up", () => {
+ renderButton(true);
+ const pill = screen.getByTestId("dictation-status");
+ expect(pill.getAttribute("role")).toBe("status");
+ expect(pill.textContent).toContain("Listening");
+ expect(pill.textContent).toContain("0:00");
+ expect(screen.getByTestId("dictation-waveform").children.length).toBeGreaterThan(0);
+ act(() => {
+ vi.advanceTimersByTime(7_000);
+ });
+ expect(screen.getByTestId("dictation-status").textContent).toContain("0:07");
+ });
+
+ test("the stop sits inside the pill and ends the dictation", () => {
+ const onToggle = vi.fn();
+ renderButton(true, onToggle);
+ const stop = screen.getByTestId("dictation-stop");
+ expect(stop.getAttribute("aria-label")).toBe("Stop dictation");
+ fireEvent.click(stop);
+ expect(onToggle).toHaveBeenCalledTimes(1);
+ });
+
+ test("the clock restarts with the next dictation instead of carrying over", () => {
+ const view = renderButton(true);
+ act(() => {
+ vi.advanceTimersByTime(65_000);
+ });
+ expect(screen.getByTestId("dictation-status").textContent).toContain("1:05");
+ view.rerender(<DictationButton dictating={false} onToggle={vi.fn()} startLabel="Dictate" stopLabel="Stop dictation" />);
+ view.rerender(<DictationButton dictating onToggle={vi.fn()} startLabel="Dictate" stopLabel="Stop dictation" />);
+ expect(screen.getByTestId("dictation-status").textContent).toContain("0:00");
+ });
+
+ test("formats elapsed time as m:ss", () => {
+ expect(formatElapsed(0)).toBe("0:00");
+ expect(formatElapsed(102_400)).toBe("1:42");
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.tsx b/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.tsx
new file mode 100644
index 0000000000..dbdd203b3f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentchat/DictationButton.tsx
@@ -0,0 +1,196 @@
+/**
+ * The composer's microphone — one control that IS the recording state.
+ *
+ * Idle it is a plain mic icon. Pressed, it grows in place into a pill that
+ * shows everything a live dictation owes the user: a waveform driven by the
+ * real microphone level, the elapsed time, and the Stop right where the
+ * finger already is. It replaces the separate "Listening…" strip that used to
+ * float above the composer (a second, full-width bar the eye had to find, with
+ * its Stop far away from the button that started it) and the pulsing square
+ * that read as a glitch rather than as "recording".
+ *
+ * Everything it shows is real. `dictating` is the live session flag from the
+ * event bus; the clock counts from the moment that flag went true; the bars
+ * read `readVoiceInputLevel()`, the level the backend streams from the very
+ * microphone the dictation transcribes (`audio.level` frames). With no fresh
+ * sample — an older backend, a muted device — the bars rest flat instead of
+ * inventing motion.
+ *
+ * Green, not red: a live microphone is a state, not a fault, and the palette
+ * keeps `--destructive` for faults (see components/VoiceIndicator.tsx).
+ */
+import { useEffect, useRef, useState } from "react";
+import { Mic, Square } from "lucide-react";
+
+import { useT } from "@/i18n";
+import { readVoiceInputLevel } from "@/lib/voiceInputLevel";
+import { cn } from "@/lib/utils";
+
+/** Bars in the waveform; the newest sample enters on the right. */
+const BAR_COUNT = 18;
+/** How often the waveform scrolls one bar, in ms. */
+const STEP_MS = 60;
+/** Resting height of a silent bar, as a fraction of the full height. */
+const REST = 0.14;
+
+/** "0:07", "1:42" — mm:ss with no leading hour nobody dictates for. */
+export function formatElapsed(ms: number): string {
+ const total = Math.max(0, Math.floor(ms / 1000));
+ const minutes = Math.floor(total / 60);
+ const seconds = total % 60;
+ return `${minutes}:${String(seconds).padStart(2, "0")}`;
+}
+
+/**
+ * The live waveform. Written straight to the DOM from one animation frame
+ * loop: the level arrives ~30 times a second, and routing that through React
+ * state would re-render the whole composer on every sample.
+ */
+function Waveform() {
+ const barsRef = useRef<HTMLSpanElement>(null);
+
+ useEffect(() => {
+ const host = barsRef.current;
+ if (!host) return;
+ const bars = Array.from(host.children) as HTMLElement[];
+ const history = new Array<number>(bars.length).fill(0);
+ let frame = 0;
+ let last = 0;
+ let peak = 0;
+ const tick = (now: number) => {
+ // Hold the loudest sample of each step so a short syllable between two
+ // steps still shows up as a bar instead of being skipped.
+ peak = Math.max(peak, readVoiceInputLevel(now));
+ if (now - last >= STEP_MS) {
+ last = now;
+ history.shift();
+ history.push(peak);
+ peak = 0;
+ for (let i = 0; i < bars.length; i += 1) {
+ const bar = bars[i];
+ if (bar) bar.style.transform = `scaleY(${REST + (1 - REST) * (history[i] ?? 0)})`;
+ }
+ }
+ frame = window.requestAnimationFrame(tick);
+ };
+ frame = window.requestAnimationFrame(tick);
+ return () => window.cancelAnimationFrame(frame);
+ }, []);
+
+ return (
+ <span
+ ref={barsRef}
+ aria-hidden
+ data-testid="dictation-waveform"
+ className="flex h-4 items-center gap-[2px]"
+ >
+ {Array.from({ length: BAR_COUNT }, (_, i) => (
+ <span
+ key={i}
+ className="h-full w-[2px] origin-center rounded-full bg-success transition-transform duration-75 ease-out"
+ style={{ transform: `scaleY(${REST})` }}
+ />
+ ))}
+ </span>
+ );
+}
+
+export interface DictationButtonProps {
+ dictating: boolean;
+ onToggle: () => void;
+ disabled?: boolean;
+ /** Label of the idle button (differs per surface: "Dictate" / "Record"). */
+ startLabel: string;
+ stopLabel: string;
+ /** Corner shape of the idle button, to match its neighbours. */
+ shape?: "round" | "square";
+ className?: string;
+}
+
+export function DictationButton({
+ dictating,
+ onToggle,
+ disabled,
+ startLabel,
+ stopLabel,
+ shape = "square",
+ className,
+}: DictationButtonProps) {
+ const t = useT();
+ const startedRef = useRef(0);
+ const [elapsed, setElapsed] = useState(0);
+
+ useEffect(() => {
+ if (!dictating) {
+ startedRef.current = 0;
+ setElapsed(0);
+ return;
+ }
+ startedRef.current = Date.now();
+ setElapsed(0);
+ const id = window.setInterval(() => setElapsed(Date.now() - startedRef.current), 500);
+ return () => window.clearInterval(id);
+ }, [dictating]);
+
+ if (!dictating) {
+ return (
+ <button
+ type="button"
+ // Focus leaving a text field for THIS button still dictates into
+ // that field (lib/dictationTarget.ts).
+ data-jarvis-dictation-trigger
+ data-testid="dictation-button"
+ onClick={onToggle}
+ disabled={disabled}
+ aria-label={startLabel}
+ title={startLabel}
+ className={cn(
+ "inline-flex h-8 w-8 shrink-0 items-center justify-center text-muted-foreground transition-colors",
+ "hover:bg-secondary hover:text-foreground disabled:opacity-50",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-strong",
+ shape === "round" ? "rounded-full" : "rounded-lg",
+ className,
+ )}
+ >
+ <Mic className="h-4 w-4" aria-hidden />
+ </button>
+ );
+ }
+
+ return (
+ <div
+ role="status"
+ aria-live="polite"
+ data-testid="dictation-status"
+ className={cn(
+ "inline-flex h-8 shrink-0 items-center gap-2 rounded-full border border-success/35 bg-success/10 pl-3 pr-1",
+ "motion-safe:animate-in motion-safe:fade-in-0 motion-safe:zoom-in-95 motion-safe:duration-150",
+ className,
+ )}
+ >
+ <span className="sr-only">{t("chats_view.dictation_listening")}</span>
+ <span className="relative flex h-2 w-2 shrink-0" aria-hidden>
+ <span className="absolute inline-flex h-full w-full rounded-full bg-success/60 motion-safe:animate-ping" />
+ <span className="relative inline-flex h-2 w-2 rounded-full bg-success" />
+ </span>
+ <Waveform />
+ <span className="w-8 shrink-0 text-right font-mono text-micro tabular-nums text-muted-foreground">
+ {formatElapsed(elapsed)}
+ </span>
+ <button
+ type="button"
+ data-jarvis-dictation-trigger
+ data-testid="dictation-stop"
+ onClick={onToggle}
+ aria-label={stopLabel}
+ title={stopLabel}
+ className={cn(
+ "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-success text-background transition-opacity",
+ "hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-success/50",
+ )}
+ >
+ <Square className="h-2.5 w-2.5 fill-current" aria-hidden />
+ </button>
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.test.tsx
deleted file mode 100644
index fb8787e6d1..0000000000
--- a/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.test.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
-
-import { DictationStatus } from "@/components/agentchat/DictationStatus";
-import { useEventStore } from "@/store/events";
-
-describe("DictationStatus", () => {
- beforeEach(() => {
- vi.useFakeTimers();
- useEventStore.setState({ dictating: false });
- });
- afterEach(() => {
- cleanup();
- vi.useRealTimers();
- });
-
- test("stays out of the way until the microphone is actually open", () => {
- render(<DictationStatus />);
- expect(screen.queryByTestId("dictation-status")).toBeNull();
- });
-
- test("announces the live session and counts from the moment it started", () => {
- render(<DictationStatus />);
- act(() => {
- useEventStore.setState({ dictating: true });
- });
-
- const strip = screen.getByTestId("dictation-status");
- expect(strip.getAttribute("role")).toBe("status");
- expect(strip.textContent).toContain("Listening");
- expect(strip.textContent).toContain("0:00");
-
- act(() => {
- vi.advanceTimersByTime(7_000);
- });
- expect(screen.getByTestId("dictation-status").textContent).toContain("0:07");
- });
-
- test("the clock restarts with the next dictation instead of carrying over", () => {
- render(<DictationStatus />);
- act(() => {
- useEventStore.setState({ dictating: true });
- });
- act(() => {
- vi.advanceTimersByTime(65_000);
- });
- expect(screen.getByTestId("dictation-status").textContent).toContain("1:05");
-
- act(() => {
- useEventStore.setState({ dictating: false });
- });
- act(() => {
- useEventStore.setState({ dictating: true });
- });
- expect(screen.getByTestId("dictation-status").textContent).toContain("0:00");
- });
-
- test("carries its own way out when the composer hands one over", () => {
- const onStop = vi.fn();
- render(<DictationStatus onStop={onStop} />);
- act(() => {
- useEventStore.setState({ dictating: true });
- });
-
- fireEvent.click(screen.getByText("Stop dictation"));
- expect(onStop).toHaveBeenCalledTimes(1);
- });
-});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.tsx b/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.tsx
deleted file mode 100644
index 2d1a02caab..0000000000
--- a/jarvis/ui/web/frontend/src/components/agentchat/DictationStatus.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * "The microphone is on" — the one recording strip every composer shows while
- * dictation runs.
- *
- * Three composers grew three different answers to the same question: the front
- * page drew a grey strip with a green dot, the agent composer a blue one, and
- * the society chat nothing at all beyond a faint tint on a 32px button. Someone
- * who pressed the mic and said nothing yet had no way to tell whether the app
- * was listening. This is that one answer, shared.
- *
- * Everything it shows is real. `dictating` is the live session flag from the
- * event bus, and the clock counts from the moment that flag went true — there
- * is no audio level in the frontend, so nothing here pretends to be a level
- * meter. The pulse means "running", not "loud".
- *
- * Green, not red: a live microphone is a state, not a fault, and the palette
- * keeps `--destructive` for faults (see components/VoiceIndicator.tsx).
- */
-import { useEffect, useRef, useState } from "react";
-
-import { useEventStore } from "@/store/events";
-import { useT } from "@/i18n";
-import { cn } from "@/lib/utils";
-
-/** "0:07", "1:42" — mm:ss with no leading hour nobody dictates for. */
-function formatElapsed(ms: number): string {
- const total = Math.max(0, Math.floor(ms / 1000));
- const minutes = Math.floor(total / 60);
- const seconds = total % 60;
- return `${minutes}:${String(seconds).padStart(2, "0")}`;
-}
-
-export interface DictationStatusProps {
- /**
- * Ends the dictation. Given one, the strip carries its own Stop — the
- * fastest way out is then the thing that just appeared, not the small icon
- * the user has to find again.
- */
- onStop?: () => void;
- className?: string;
-}
-
-export function DictationStatus({ onStop, className }: DictationStatusProps) {
- const t = useT();
- const dictating = useEventStore((s) => s.dictating);
- const startedRef = useRef(0);
- const [elapsed, setElapsed] = useState(0);
-
- useEffect(() => {
- if (!dictating) {
- startedRef.current = 0;
- setElapsed(0);
- return;
- }
- startedRef.current = Date.now();
- setElapsed(0);
- const id = window.setInterval(() => setElapsed(Date.now() - startedRef.current), 500);
- return () => window.clearInterval(id);
- }, [dictating]);
-
- if (!dictating) return null;
-
- return (
- <div
- role="status"
- aria-live="polite"
- data-testid="dictation-status"
- className={cn(
- "flex items-center gap-2 rounded-md border border-success/30 bg-success/10 px-3 py-1.5 text-meta text-foreground",
- className,
- )}
- >
- <span className="relative flex h-2 w-2 shrink-0" aria-hidden>
- <span className="absolute inline-flex h-full w-full rounded-full bg-success/70 motion-safe:animate-ping" />
- <span className="relative inline-flex h-2 w-2 rounded-full bg-success" />
- </span>
- <span className="min-w-0 truncate">{t("chats_view.dictation_listening")}</span>
- <span className="ml-auto shrink-0 font-mono tabular-nums text-muted-foreground">
- {formatElapsed(elapsed)}
- </span>
- {onStop ? (
- <button
- type="button"
- onClick={onStop}
- className="shrink-0 rounded px-1.5 py-0.5 font-medium text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-strong"
- >
- {t("chats_view.dictation_stop")}
- </button>
- ) : null}
- </div>
- );
-}
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
index cec9be8426..5dce67f599 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
+++ b/jarvis/ui/web/frontend/src/components/agentchat/useComposerDictation.ts
@@ -16,6 +16,11 @@ import { useEventStore } from "@/store/events";
* started by the keyboard shortcut never calls `start`, so its final text
* appends to whatever the box holds at that moment (the functional update
* reads it without dragging `value` into a dependency array).
+ *
+ * The setter is read through a ref: callers pass an inline wrapper (the
+ * society composer mirrors into its chip field), and with that wrapper in the
+ * effect deps the mirror re-ran — and re-wrote the field, jumping the caret —
+ * on every render of the composer, not only when the transcript changed.
*/
export function useComposerDictation(
value: string,
@@ -28,25 +33,27 @@ export function useComposerDictation(
const baseRef = useRef("");
const mirroringRef = useRef(false);
const lastCommitSeqRef = useRef(dictationCommitSeq);
+ const setValueRef = useRef(setValue);
+ setValueRef.current = setValue;
useEffect(() => {
if (!dictating) return;
const base = baseRef.current;
const sep = base && dictationText ? " " : "";
- setValue(base + sep + dictationText);
- }, [dictating, dictationText, setValue]);
+ setValueRef.current(base + sep + dictationText);
+ }, [dictating, dictationText]);
useEffect(() => {
if (dictationCommitSeq === lastCommitSeqRef.current) return;
lastCommitSeqRef.current = dictationCommitSeq;
const finalText = useEventStore.getState().dictationCommitText;
- setValue((current) => {
+ setValueRef.current((current) => {
const base = mirroringRef.current ? baseRef.current : current;
const sep = base && finalText ? " " : "";
return base + sep + finalText;
});
mirroringRef.current = false;
- }, [dictationCommitSeq, setValue]);
+ }, [dictationCommitSeq]);
const start = useCallback(() => {
baseRef.current = value;
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.tsx
index 8ed2f1102c..de5bc5df47 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
@@ -33,7 +33,7 @@ vi.mock("../data", async (original) => ({
vi.mock("@/components/agentchat/useComposerDictation", () => ({
useComposerDictation: () => ({ dictating: false, stop() {}, toggle() {} }),
}));
-vi.mock("@/components/agentchat/DictationStatus", () => ({ DictationStatus: () => null }));
+vi.mock("@/components/agentchat/DictationButton", () => ({ DictationButton: () => null }));
vi.mock("@/components/agentchat/useChatAttachments", () => ({
useChatAttachments: () => ({
attachments: [],
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
index bfbc90c0f2..1c9b78c024 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -38,7 +38,7 @@ import { ComposerChipField, type ComposerChipFieldHandle } from "@/components/ag
import { MessageWithChips } from "@/components/agentchat/ToolChoiceChips";
import { choiceToken } from "@/components/agentchat/composerChips";
import { useChatAttachments } from "@/components/agentchat/useChatAttachments";
-import { DictationStatus } from "@/components/agentchat/DictationStatus";
+import { DictationButton } from "@/components/agentchat/DictationButton";
import { useComposerDictation } from "@/components/agentchat/useComposerDictation";
import { useEventStore } from "@/store/events";
import { useHomeStore } from "@/store/home";
@@ -1162,7 +1162,6 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
<div className={CHAT_MEASURE}>
<ChatAttachmentStrip attachments={attachments.attachments} analyzing={attachments.analyzing} onRemove={attachments.remove} />
</div>
- <DictationStatus onStop={dictation.stop} className={cn(CHAT_MEASURE, "mb-1.5")} />
<MentionPicker
anchorRef={composerRef}
open={pickerOpen}
@@ -1181,7 +1180,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
attachments.dragging && "border-border-strong",
// The whole composer reads as armed while the mic is open, not just
// the 32px button someone has to go looking for.
- dictation.dictating && "border-success/40 ring-1 ring-success/25",
+ dictation.dictating && "border-success/35 focus-within:border-success/50",
)}
{...attachments.dragHandlers}
>
@@ -1249,7 +1248,11 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
</div>
<ComposerChipField
ref={fieldRef}
- placeholder={t("society.chat.placeholder").replace("{0}", agent.name)}
+ placeholder={
+ dictation.dictating
+ ? t("chats_view.dictation_listening")
+ : t("society.chat.placeholder").replace("{0}", agent.name)
+ }
disabled={false}
onSubmit={() => void submit()}
onDraftChange={onDraftChange}
@@ -1285,23 +1288,18 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
}}
className="max-h-[180px]"
/>
- {surface === "society" ? <div className="flex h-8 min-w-0 max-w-[40%] shrink-0 items-center">
+ {/* Hidden, not unmounted, while recording: the pill needs the room,
+ and a save in flight must still report back. */}
+ {surface === "society" ? <div className={cn("h-8 min-w-0 max-w-[40%] shrink-0 items-center", dictation.dictating ? "hidden" : "flex")}>
<AgentModelPicker key={agent.agentId} agent={agent} busy={busy} onSavingChange={setModelSaving} />
</div> : null}
- <button
- type="button"
- onClick={dictation.toggle}
- aria-label={dictation.dictating ? t("society.chat.stop_recording") : t("society.chat.record")}
- aria-pressed={dictation.dictating}
- className={cn(
- "flex h-8 w-8 items-center justify-center rounded-full transition-colors",
- dictation.dictating
- ? "bg-secondary text-success motion-safe:animate-jarvis-pulse"
- : "text-muted-foreground hover:bg-secondary hover:text-foreground",
- )}
- >
- {dictation.dictating ? <Square className="h-4 w-4" aria-hidden /> : <Mic className="h-4 w-4" aria-hidden />}
- </button>
+ <DictationButton
+ dictating={dictation.dictating}
+ onToggle={dictation.toggle}
+ startLabel={t("society.chat.record")}
+ stopLabel={t("society.chat.stop_recording")}
+ shape="round"
+ />
{live && !commands.isCommand && !(commands.canSteer && value.trim()) ? (
<button
type="button"
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
index f536ad7d77..3145dd2b8f 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
@@ -54,7 +54,7 @@ vi.mock("../data", async (original) => ({
vi.mock("@/components/agentchat/useComposerDictation", () => ({
useComposerDictation: () => ({ dictating: false, stop() {}, toggle() {} }),
}));
-vi.mock("@/components/agentchat/DictationStatus", () => ({ DictationStatus: () => null }));
+vi.mock("@/components/agentchat/DictationButton", () => ({ DictationButton: () => null }));
vi.mock("@/components/agentchat/useChatAttachments", () => ({
useChatAttachments: () => ({
attachments: [],