Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(speech): press-to-talk pill — record on press, insert on stop (press-to-talk Task 2)

enesf3ba1c7ac230
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index b4a1862da..6e531b4de 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -464,6 +464,10 @@ export function Canvas() {
// overlay is up — the design explicitly freezes it so a stray click elsewhere mid-dictation
// can't retarget an in-progress recording).
const [dictationTarget, setDictationTarget] = useState<DictationTarget | null>(null)
+ // Bumped (never toggled) on a second shortcut/Dock-mic press while the overlay is already
+ // open — DictationOverlay watches this to decide STOP-vs-CANCEL from its own current phase
+ // instead of Canvas guessing; see the `stopSignal` prop doc on DictationOverlayProps.
+ const [dictationStopSignal, setDictationStopSignal] = useState(0)
const [bugReportOpen, setBugReportOpen] = useState(false)
const [appVersion, setAppVersion] = useState<string | null>(null)
@@ -982,12 +986,19 @@ export function Canvas() {
}
}, [sessionsPinned])
- // ⌘⇧D / Dock mic button: opens the dictation overlay targeting the first selected
- // terminal/chat node (agent nodes are `type: 'terminal'` with `data.agentId` set — no separate
- // case needed). Closing and reopening re-resolves the target from the CURRENT selection.
+ // ⌘⇧D / Dock mic button: press-to-talk toggle. Closed → opens the dictation pill targeting the
+ // first selected terminal/chat node (agent nodes are `type: 'terminal'` with `data.agentId`
+ // set — no separate case needed) and starts recording immediately (or, with no such node
+ // selected, shows a brief warning pill — see DictationOverlay's mount effect). Already open →
+ // does NOT close the overlay itself; it bumps `dictationStopSignal` so DictationOverlay can
+ // decide what "press again" means from its own current phase (stop-and-transcribe while
+ // recording, dismiss otherwise) — see the `stopSignal` prop doc.
const toggleDictation = useCallback(() => {
setDictationOpen((open) => {
- if (open) return false
+ if (open) {
+ setDictationStopSignal((n) => n + 1)
+ return true
+ }
const sel = nodesRef.current.find(
(n) => n.selected && (n.type === 'terminal' || n.type === 'chat')
)
@@ -5923,6 +5934,7 @@ export function Canvas() {
{dictationOpen && (
<DictationOverlay
target={dictationTarget}
+ stopSignal={dictationStopSignal}
onClose={() => setDictationOpen(false)}
onOpenLicense={() => {
setDictationOpen(false)
diff --git a/src/renderer/components/DictationOverlay.test.ts b/src/renderer/components/DictationOverlay.test.ts
index cd1643e9e..28ab23ae0 100644
--- a/src/renderer/components/DictationOverlay.test.ts
+++ b/src/renderer/components/DictationOverlay.test.ts
@@ -1,5 +1,36 @@
import { describe, expect, it } from 'vitest'
-import { isAtRecordingCap, isProGateError } from './DictationOverlay'
+import { dictationMode, isAtRecordingCap, isProGateError, type DictationTarget } from './DictationOverlay'
+
+const terminalTarget: DictationTarget = { kind: 'terminal', nodeId: 'n1', title: 'shell' }
+const chatTarget: DictationTarget = { kind: 'chat', nodeId: 'n2', title: 'chat' }
+
+// Press-to-talk: the pill is the default surface for both target kinds while a take is in
+// flight; only a chat target's *transcribed* text ever reaches the editable card (a terminal
+// target inserts directly and never has a 'text' phase at all — see DictationOverlay.stopRecording).
+describe('dictationMode', () => {
+ it('is "warning" whenever there is no target, regardless of phase', () => {
+ expect(dictationMode(null, 'idle')).toBe('warning')
+ expect(dictationMode(null, 'recording')).toBe('warning')
+ expect(dictationMode(null, 'text')).toBe('warning')
+ })
+
+ it('is "pill" for a terminal target in every phase, including "text"', () => {
+ expect(dictationMode(terminalTarget, 'idle')).toBe('pill')
+ expect(dictationMode(terminalTarget, 'recording')).toBe('pill')
+ expect(dictationMode(terminalTarget, 'transcribing')).toBe('pill')
+ expect(dictationMode(terminalTarget, 'text')).toBe('pill')
+ })
+
+ it('is "pill" for a chat target until phase reaches "text"', () => {
+ expect(dictationMode(chatTarget, 'idle')).toBe('pill')
+ expect(dictationMode(chatTarget, 'recording')).toBe('pill')
+ expect(dictationMode(chatTarget, 'transcribing')).toBe('pill')
+ })
+
+ it('is "card" only for a chat target once transcribed ("text" phase)', () => {
+ expect(dictationMode(chatTarget, 'text')).toBe('card')
+ })
+})
// Base64 int16 PCM runs ~2.6 MB/min; WS_MAX_PAYLOAD (src/server/ws.ts) is 8 MiB, so an unbounded
// take would eventually blow the ws frame budget and drop the whole bridge. The 2:30 hard cap
diff --git a/src/renderer/components/DictationOverlay.tsx b/src/renderer/components/DictationOverlay.tsx
index 11153f126..e52ba1b51 100644
--- a/src/renderer/components/DictationOverlay.tsx
+++ b/src/renderer/components/DictationOverlay.tsx
@@ -1,20 +1,21 @@
-// Desktop dictation overlay: record → transcribe → editable text → Send/Insert/Copy.
-// A bottom-center floating card (portal to document.body, like CommandPalette/ShortcutsPanel)
-// rather than a full-screen modal — see styles.css `.dictation` for the "above the Dock" placement.
+// Desktop press-to-talk: shortcut/Dock-mic press starts recording IMMEDIATELY into a compact
+// bottom-center pill (stop icon + live equalizer + elapsed mm:ss); pressing again (or the pill's
+// own stop icon) stops → transcribes → for a terminal target inserts the text directly
+// (`pty.sendText(id, text, { enter: false })`, no Enter — nothing here ever auto-submits) and the
+// pill closes; for a chat target (no external draft field to insert into) the transcript opens
+// in the v1 editable CARD instead, where the user still presses Send themselves.
//
-// NOTHING here auto-submits: only the explicit Send button ever pushes text into a session.
+// Two different ways to dismiss, not interchangeable:
+// - STOP (shortcut second-press / the pill's stop icon) — ends the recording and PROCESSES it
+// (transcribe → insert/card).
+// - CANCEL (Esc, or the ×/close affordances) — DISCARDS whatever was being recorded and closes
+// the whole overlay. Esc mid-recording is cancel, not stop, even though both are triggered by
+// a "press" — see handleClose vs the stopSignal branch below.
//
-// Insert (terminal): `pty.sendText(persistKey, text, { enter: false })` writes the literal text
-// into the node's tmux session without the trailing Enter, so the user can edit/append before
-// running it themselves (Task 10b — `enter` defaults to true everywhere else, so every other
-// caller of sendText is untouched).
-//
-// Insert (chat): ChatNode's compose box is local component state with no externally settable
-// draft, so there's no seam to write into without submitting — Insert stays disabled for chat
-// targets, with a tooltip explaining why. Send (which already has an explicit-submission story)
-// is the working action there.
+// No target selected at press time never records at all — see the warning-pill render branch.
import { useCallback, useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
+import { equalizerBars } from '../lib/dictation-equalizer'
import { PcmCapture } from '../lib/pcm-capture'
import { useSession } from '../session/session'
import { useChatSessions } from '../state/chatSessions'
@@ -27,6 +28,11 @@ export interface DictationTarget {
interface DictationOverlayProps {
target: DictationTarget | null
+ /** Bumped by Canvas's toggleDictation on a second shortcut/Dock-mic press while the overlay is
+ * already open. A no-op prop change is the signal (any new value ≠ close-then-reopen — the
+ * overlay itself decides what a "press again" means from its own current phase: STOP while
+ * recording, CANCEL/close otherwise). */
+ stopSignal: number
onClose: () => void
/** Routes to Settings → License (same section SpeechSection's own Pro upsells use) — invoked
* from the "See nodeterm Pro" action shown beside a Pro-model transcribe error. */
@@ -40,6 +46,19 @@ export function isProGateError(message: string): boolean {
}
type Phase = 'idle' | 'recording' | 'transcribing' | 'text'
+/** 'warning' = no target at press time (never records). 'pill' = the compact recording/
+ * transcribing/error capsule — used for BOTH targets while a take is in flight, and for a
+ * terminal target start to finish (it never reaches 'card'). 'card' = the v1 editable text
+ * card, reached only once a chat target's take has transcribed successfully (and again if the
+ * user re-records another take from there — the re-record trip goes back out through 'pill'). */
+export type DictationMode = 'warning' | 'pill' | 'card'
+
+/** Pure — no side effects. Exported for its own unit coverage. */
+export function dictationMode(target: DictationTarget | null, phase: Phase): DictationMode {
+ if (!target) return 'warning'
+ if (target.kind === 'chat' && phase === 'text') return 'card'
+ return 'pill'
+}
/** mm:ss, floored to whole seconds. Pure — no side effects. */
export function formatElapsed(ms: number): string {
@@ -71,7 +90,10 @@ export function isAtRecordingCap(elapsedMs: number): boolean {
return elapsedMs >= MAX_RECORDING_MS
}
-export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOverlayProps) {
+/** How long the "no target selected" warning pill stays up before it auto-dismisses. */
+const NO_TARGET_DISMISS_MS = 2500
+
+export function DictationOverlay({ target, stopSignal, onClose, onOpenLicense }: DictationOverlayProps) {
const { api } = useSession()
const addLocalUser = useChatSessions((s) => s.addLocalUser)
const chatWorking = useChatSessions((s) =>
@@ -82,7 +104,7 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
const [text, setText] = useState('')
const [error, setError] = useState<string | null>(null)
const [elapsedMs, setElapsedMs] = useState(0)
- const [level, setLevel] = useState(0)
+ const [levelHistory, setLevelHistory] = useState<number[]>([])
const [sending, setSending] = useState(false)
const [capped, setCapped] = useState(false)
@@ -90,6 +112,8 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
const consentAskedRef = useRef(false)
const startedAtRef = useRef(0)
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null)
+ const onCloseRef = useRef(onClose)
+ onCloseRef.current = onClose
const clearTimer = useCallback(() => {
if (timerRef.current) {
@@ -98,17 +122,6 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
}
}, [])
- // A fresh target (or the overlay reopening on the same one) starts clean — no leftover text/error
- // from a previous take.
- useEffect(() => {
- setPhase('idle')
- setText('')
- setError(null)
- setElapsedMs(0)
- setLevel(0)
- setCapped(false)
- }, [target?.nodeId])
-
// Belt-and-braces: if this component unmounts mid-recording (parent flips `open` without going
// through handleClose — e.g. a project switch), the mic must not stay live.
useEffect(() => {
@@ -128,17 +141,37 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
setPhase('transcribing')
try {
const { text: transcribed } = await window.nodeTerminal.speech.transcribe(pcm)
+ if (!target) {
+ // Defensive only — recording never starts without a target (see the mount effect below).
+ onClose()
+ return
+ }
+ if (target.kind === 'terminal') {
+ const ok = await api.pty.sendText(target.nodeId, transcribed, { enter: false })
+ if (!ok) {
+ setError('Could not insert — the terminal session is not available.')
+ setPhase('idle')
+ return
+ }
+ onClose()
+ return
+ }
+ // Chat: no external draft field to insert into (see the file header) — open the editable
+ // card so the user can review/edit and press Send themselves. Appends onto any earlier take
+ // (re-record from the card).
setText((prev) => appendTake(prev, transcribed))
setPhase('text')
} catch (err) {
setError(err instanceof Error ? err.message : 'Transcription failed.')
- // Fall back to the text state (editable) if a prior take already produced some, else back
- // to idle so the mic button reappears.
+ // A chat target with an earlier successful take falls back to the card (keeping that text,
+ // now alongside the error); everything else (terminal, or no prior text yet) falls back to
+ // the pill so the user can retry.
setPhase(text.trim() ? 'text' : 'idle')
}
- }, [clearTimer, text])
+ }, [clearTimer, target, api, onClose, text])
const startRecording = useCallback(async () => {
+ if (!target) return
setError(null)
setCapped(false)
if (!consentAskedRef.current) {
@@ -168,12 +201,13 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
startedAtRef.current = Date.now()
setElapsedMs(0)
- setLevel(0)
+ setLevelHistory([])
setPhase('recording')
timerRef.current = setInterval(() => {
const elapsed = Date.now() - startedAtRef.current
setElapsedMs(elapsed)
- setLevel(captureRef.current?.level() ?? 0)
+ const level = captureRef.current?.level() ?? 0
+ setLevelHistory((prev) => [...prev, level])
if (isAtRecordingCap(elapsed)) {
// clearTimer() inside stopRecording fires synchronously before any await, so this can't
// re-enter on the next tick.
@@ -181,7 +215,20 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
void stopRecording()
}
}, LEVEL_POLL_MS)
- }, [stopRecording])
+ }, [target, stopRecording])
+
+ // Press-to-talk: a target means "start recording now" (this instance is a fresh mount each
+ // time Canvas opens the overlay, and the target is frozen for its lifetime — see
+ // DictationOverlayProps — so this is correctly mount-only). No target means the warning pill;
+ // it never records, and auto-dismisses on its own.
+ useEffect(() => {
+ if (!target) {
+ const t = setTimeout(() => onCloseRef.current(), NO_TARGET_DISMISS_MS)
+ return () => clearTimeout(t)
+ }
+ void startRecording()
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [])
const handleClose = useCallback(() => {
if (phase === 'recording') {
@@ -193,7 +240,8 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
}, [phase, clearTimer, onClose])
// Esc closes (own listener, same pattern as ShortcutsPanel — only active while mounted, so it
- // never competes with Canvas's own Esc handling elsewhere).
+ // never competes with Canvas's own Esc handling elsewhere). This is CANCEL, not stop — see the
+ // file header.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
@@ -205,6 +253,21 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
return () => window.removeEventListener('keydown', onKey)
}, [handleClose])
+ // A second shortcut/Dock-mic press while this overlay is already open (Canvas bumps
+ // `stopSignal` rather than unmounting us — see DictationOverlayProps). While actively
+ // recording that means STOP (transcribe → insert/card); in every other phase (warning,
+ // transcribing, the editable card, an error pill) it means dismiss, same as Esc/×.
+ const prevStopSignalRef = useRef(stopSignal)
+ useEffect(() => {
+ if (stopSignal === prevStopSignalRef.current) return
+ prevStopSignalRef.current = stopSignal
+ if (phase === 'recording') {
+ void stopRecording()
+ } else {
+ handleClose()
+ }
+ }, [stopSignal, phase, stopRecording, handleClose])
+
const send = useCallback(async () => {
if (!target) return
const value = text.trim()
@@ -236,72 +299,52 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
window.nodeTerminal.clipboard.writeText(value)
}, [text])
- const insert = useCallback(async () => {
- if (!target || target.kind !== 'terminal') return
- const value = text.trim()
- if (!value) return
- setSending(true)
- setError(null)
- try {
- const ok = await api.pty.sendText(target.nodeId, value, { enter: false })
- if (!ok) {
- setError('Could not insert — the terminal session is not available.')
- return
- }
- onClose()
- } catch (err) {
- setError(err instanceof Error ? err.message : 'Failed to insert.')
- } finally {
- setSending(false)
- }
- }, [target, text, api, onClose])
-
- // Chat has no external draft field to write into without submitting (see the header comment) —
- // Insert stays disabled there. A terminal target is always insertable once there's text.
- const insertDisabledReason = !target
- ? 'Select a terminal or chat node first.'
- : target.kind === 'chat'
- ? 'Chat has no external draft field — use Send.'
- : null
-
const hasText = !!text.trim()
- const insertDisabled = !target || !hasText || sending || insertDisabledReason !== null
+ const mode = dictationMode(target, phase)
+
+ const errorBlock = error && (
+ <div className="dictation__error">
+ <span>{error}</span>
+ {isProGateError(error) && (
+ <button type="button" className="dictation__error-action" onClick={onOpenLicense}>
+ See nodeterm Pro
+ </button>
+ )}
+ <button type="button" className="dictation__close" title="Dismiss" onClick={handleClose}>
+ ×
+ </button>
+ </div>
+ )
- return createPortal(
- <div className="dictation nodrag nowheel" onMouseDown={(e) => e.stopPropagation()}>
- <div className="dictation__head">
- <span className="dictation__title">Dictate</span>
- <span className="dictation__target">{target ? `→ ${target.title}` : 'No target selected'}</span>
- <button type="button" className="dictation__close" title="Close (Esc)" onClick={handleClose}>
+ if (mode === 'warning') {
+ return createPortal(
+ <div className="dictation dictation--warning nodrag nowheel" onMouseDown={(e) => e.stopPropagation()}>
+ <span className="dictation__warning-text">Select a terminal or chat node first.</span>
+ <button type="button" className="dictation__close" title="Dismiss" onClick={handleClose}>
×
</button>
- </div>
-
- <div className="dictation__body">
- {phase === 'idle' && (
- <button
- type="button"
- className="dictation__mic dictation__mic--idle"
- onClick={() => void startRecording()}
- title="Start recording"
- >
- <MicIcon />
- <span>Click to record</span>
- </button>
- )}
-
+ </div>,
+ document.body
+ )
+ }
+
+ if (mode === 'pill') {
+ return createPortal(
+ <div className="dictation dictation--pill nodrag nowheel" onMouseDown={(e) => e.stopPropagation()}>
{phase === 'recording' && (
- <div className="dictation__recording">
+ <div className="dictation__pill">
<button
type="button"
- className="dictation__mic dictation__mic--active"
+ className="dictation__stop"
onClick={() => void stopRecording()}
- title="Stop recording"
+ title="Stop recording — transcribes & inserts"
>
- <MicIcon />
+ <StopIcon />
</button>
- <div className="dictation__meter">
- <div className="dictation__meter-fill" style={{ width: `${Math.round(level * 100)}%` }} />
+ <div className="dictation__bars" aria-hidden="true">
+ {equalizerBars(levelHistory).map((h, i) => (
+ <span key={i} className="dictation__bar" style={{ height: `${Math.round(h * 100)}%` }} />
+ ))}
</div>
<span className="dictation__elapsed">{formatElapsed(elapsedMs)}</span>
</div>
@@ -310,63 +353,63 @@ export function DictationOverlay({ target, onClose, onOpenLicense }: DictationOv
{phase === 'transcribing' && (
<div className="dictation__transcribing">
<span className="dictation__spinner" />
- <span>{capped ? 'Recording capped at 2:30 — transcribing.' : 'Transcribing…'}</span>
+ <span>{capped ? 'Recording capped at 2:30 — transcribing…' : 'Transcribing…'}</span>
</div>
)}
- {phase === 'text' && (
- <div className="dictation__text-row">
- <textarea
- className="dictation__textarea"
- value={text}
- onChange={(e) => setText(e.target.value)}
- placeholder="Transcribed text…"
- autoFocus
- spellCheck
- />
- <button
- type="button"
- className="dictation__mic dictation__mic--small"
- onClick={() => void startRecording()}
- title="Record another take (appends)"
- >
- <MicIcon />
- </button>
+ {phase === 'idle' && !error && (
+ <div className="dictation__transcribing">
+ <span className="dictation__spinner" />
+ <span>Starting…</span>
</div>
)}
+
+ {errorBlock}
+ </div>,
+ document.body
+ )
+ }
+
+ // mode === 'card' — chat only, reached once a take has transcribed. v1 editable card, minus
+ // Insert (chat has no external draft field — see the file header; the quick pill flow above is
+ // how a terminal target ever gets text inserted, so Insert has no reachable case here at all).
+ return createPortal(
+ <div className="dictation dictation--card nodrag nowheel" onMouseDown={(e) => e.stopPropagation()}>
+ <div className="dictation__head">
+ <span className="dictation__title">Dictate</span>
+ <span className="dictation__target">→ {target?.title}</span>
+ <button type="button" className="dictation__close" title="Close (Esc)" onClick={handleClose}>
+ ×
+ </button>
</div>
- {error && (
- <div className="dictation__error">
- <span>{error}</span>
- {isProGateError(error) && (
- <button type="button" className="dictation__error-action" onClick={onOpenLicense}>
- See nodeterm Pro
- </button>
- )}
+ <div className="dictation__body">
+ <div className="dictation__text-row">
+ <textarea
+ className="dictation__textarea"
+ value={text}
+ onChange={(e) => setText(e.target.value)}
+ placeholder="Transcribed text…"
+ autoFocus
+ spellCheck
+ />
+ <button
+ type="button"
+ className="dictation__mic dictation__mic--small"
+ onClick={() => void startRecording()}
+ title="Record another take (appends)"
+ >
+ <MicIcon />
+ </button>
</div>
- )}
+ </div>
+
+ {errorBlock}
<div className="dictation__actions">
<button type="button" className="dictation__btn" onClick={copy} disabled={!hasText}>
Copy
</button>
- {insertDisabledReason ? (
- <span title={insertDisabledReason}>
- <button type="button" className="dictation__btn" disabled>
- Insert
- </button>
- </span>
- ) : (
- <button
- type="button"
- className="dictation__btn"
- onClick={() => void insert()}
- disabled={insertDisabled}
- >
- Insert
- </button>
- )}
<button
type="button"
className="dictation__btn dictation__btn--primary"
@@ -389,3 +432,11 @@ function MicIcon() {
</svg>
)
}
+
+function StopIcon() {
+ return (
+ <svg width={14} height={14} viewBox="0 0 24 24" fill="currentColor">
+ <rect x="5" y="5" width="14" height="14" rx="2" />
+ </svg>
+ )
+}
diff --git a/src/renderer/lib/dictation-equalizer.test.ts b/src/renderer/lib/dictation-equalizer.test.ts
new file mode 100644
index 000000000..bb85c0746
--- /dev/null
+++ b/src/renderer/lib/dictation-equalizer.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest'
+import { EQUALIZER_BAR_COUNT, EQUALIZER_IDLE_FLOOR, equalizerBars } from './dictation-equalizer'
+
+describe('equalizerBars', () => {
+ it('pads an empty history with the idle floor, at the default bar count', () => {
+ const bars = equalizerBars([])
+ expect(bars).toHaveLength(EQUALIZER_BAR_COUNT)
+ expect(bars.every((h) => h === EQUALIZER_IDLE_FLOOR)).toBe(true)
+ })
+
+ it('left-pads a short history and keeps sample order (most-recent last)', () => {
+ const bars = equalizerBars([0.5, 0.9], 5, 0.1)
+ expect(bars).toEqual([0.1, 0.1, 0.1, 0.5, 0.9])
+ })
+
+ it('keeps only the most recent barCount samples when history overflows', () => {
+ const history = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
+ expect(equalizerBars(history, 3, 0)).toEqual([0.4, 0.5, 0.6])
+ })
+
+ it('clamps out-of-range samples into [0,1]', () => {
+ expect(equalizerBars([-5, 5], 2, 0)).toEqual([0, 1])
+ })
+
+ it('floors every bar (including clamped/def NaN samples) at idleFloor', () => {
+ expect(equalizerBars([0, 0.02, Number.NaN], 3, 0.08)).toEqual([0.08, 0.08, 0.08])
+ })
+
+ it('treats non-finite samples as 0 before flooring', () => {
+ expect(equalizerBars([Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY], 2, 0.1)).toEqual([
+ 0.1, 0.1
+ ])
+ })
+
+ it('is a no-op passthrough (modulo floor/clamp) when history already equals barCount', () => {
+ const history = [0.1, 0.2, 0.3]
+ expect(equalizerBars(history, 3, 0)).toEqual(history)
+ })
+})
diff --git a/src/renderer/lib/dictation-equalizer.ts b/src/renderer/lib/dictation-equalizer.ts
new file mode 100644
index 000000000..19fc267b5
--- /dev/null
+++ b/src/renderer/lib/dictation-equalizer.ts
@@ -0,0 +1,30 @@
+// Press-to-talk recording pill: turns a rolling window of raw amplitude samples
+// (`PcmCapture.level()`, 0..1, oldest→newest, one per LEVEL_POLL_MS tick in DictationOverlay)
+// into a fixed-length array of bar heights (0..1) for the ~12-bar equalizer. Pure — no side
+// effects, no DOM; the component re-renders every poll tick and lets a CSS `transition` on each
+// bar's height smooth the visual change between calls, so this only needs to pick the numbers.
+export const EQUALIZER_BAR_COUNT = 12
+// A recording that's just starting (or briefly silent) shouldn't render as 12 flat-zero bars —
+// a small floor keeps the pill visibly "alive" instead of looking frozen/broken.
+export const EQUALIZER_IDLE_FLOOR = 0.08
+
+/**
+ * Maps `history` (oldest→newest amplitude samples) to exactly `barCount` heights, most-recent
+ * last. Fewer samples than `barCount` (the first ~1.2s of a take) are left-padded with
+ * `idleFloor`; more samples keep only the most recent `barCount`. Each height is clamped to
+ * [0,1] and floored at `idleFloor` (NaN/negative samples — a defensive case, `PcmCapture.level()`
+ * shouldn't produce them — count as 0 and floor the same way).
+ */
+export function equalizerBars(
+ history: readonly number[],
+ barCount: number = EQUALIZER_BAR_COUNT,
+ idleFloor: number = EQUALIZER_IDLE_FLOOR
+): number[] {
+ const recent = history.slice(Math.max(0, history.length - barCount))
+ const bars: number[] = new Array(Math.max(0, barCount - recent.length)).fill(idleFloor)
+ for (const raw of recent) {
+ const clamped = Number.isFinite(raw) ? Math.min(1, Math.max(0, raw)) : 0
+ bars.push(Math.max(idleFloor, clamped))
+ }
+ return bars
+}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 8f591d45c..5cd7c503c 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -706,6 +706,75 @@ body,
background: var(--accent-hover);
}
+/* ---- Press-to-talk recording pill (warning / recording / transcribing / error) ----
+ Compact capsule variants of the `.dictation` shell above — used instead of the rectangular
+ card for every phase except the chat-only editable card (`.dictation--card` keeps the
+ rectangular sizing, i.e. the plain `.dictation` defaults above). */
+.dictation--pill,
+.dictation--warning {
+ width: auto;
+ min-width: 220px;
+ max-width: min(92vw, 420px);
+ flex-direction: row;
+ align-items: center;
+ border-radius: 999px;
+ padding: 10px 18px;
+}
+
+.dictation--pill {
+ min-width: 260px;
+}
+
+.dictation__warning-text {
+ flex: 1 1 auto;
+ color: var(--text);
+ font-size: 13px;
+}
+
+.dictation__pill {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ width: 100%;
+}
+
+.dictation__stop {
+ flex-shrink: 0;
+ width: 30px;
+ height: 30px;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ background: rgba(255, 69, 58, 0.18);
+ border: 1px solid rgba(255, 69, 58, 0.5);
+ border-radius: 50%;
+ color: #ff453a;
+ cursor: pointer;
+ animation: dictation-pulse 1.4s ease-in-out infinite;
+}
+
+.dictation__stop:hover {
+ background: rgba(255, 69, 58, 0.28);
+}
+
+.dictation__bars {
+ flex: 1 1 auto;
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ gap: 3px;
+ height: 22px;
+}
+
+.dictation__bar {
+ flex: 1 1 0;
+ max-width: 4px;
+ min-height: 2px;
+ border-radius: 2px;
+ background: #ff453a;
+ transition: height 90ms ease-out;
+}
+
/* ---- Terminal node ---- */
.term-node {
width: 100%;