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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(speech): dictation overlay + dock mic + shortcut (desktop-dictation Task 10)
enes91fee5afaeae
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex ae38f74d7..67b09eebb 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -75,6 +75,7 @@ import { SourceControlPanel } from '../components/SourceControlPanel'import { WelcomeScreen } from '../components/WelcomeScreen'import { CloneRepoDialog } from '../components/CloneRepoDialog'import { ShortcutsPanel } from '../components/ShortcutsPanel'+import { DictationOverlay, type DictationTarget } from '../components/DictationOverlay'import { BugReportDialog } from '../components/BugReportDialog'import { describeOs, REPO_URL } from '../lib/bugReport'import { UpdateCard } from '../components/UpdateCard'@@ -454,6 +455,11 @@ export function Canvas() {const [settingsSection, setSettingsSection] = useState<SettingsSectionId | undefined>(undefined)const [scOpen, setScOpen] = useState(false)const [shortcutsOpen, setShortcutsOpen] = useState(false)+ const [dictationOpen, setDictationOpen] = useState(false)+ // Target = the first selected terminal/chat node AT OPEN TIME (not live-tracked while the+ // 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)const [bugReportOpen, setBugReportOpen] = useState(false)const [appVersion, setAppVersion] = useState<string | null>(null)@@ -972,6 +978,24 @@ 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.+ const toggleDictation = useCallback(() => {+ setDictationOpen((open) => {+ if (open) return false+ const sel = nodesRef.current.find(+ (n) => n.selected && (n.type === 'terminal' || n.type === 'chat')+ )+ setDictationTarget(+ sel+ ? { kind: sel.type === 'chat' ? 'chat' : 'terminal', nodeId: sel.id, title: (sel.data.title as string) || 'Untitled' }+ : null+ )+ return true+ })+ }, [])+// Hover-peek: the sidebar overlaps its trigger icon, so leaving the icon (mouseleave)// must not close the peek while the cursor moves onto the sidebar body. A single shared// timer lets entering either surface cancel a pending close from the other.@@ -2418,7 +2442,8 @@ export function Canvas() {requireProOr('Remote SSH terminals', () => setRemotePicker(screenPos))}, [])- // ⌘T = new terminal, ⌘⇧C = new default agent (ignored while typing in a field/terminal).+ // ⌘T = new terminal, ⌘⇧C = new default agent, ⌘⇧D = toggle dictation (ignored while typing in+ // a field/terminal).useEffect(() => {const onKey = (e: KeyboardEvent) => {if (!(e.metaKey || e.ctrlKey)) return@@ -2431,11 +2456,14 @@ export function Canvas() {} else if (k === 'c' && e.shiftKey) {e.preventDefault()addAgentNode(useSettings.getState().settings.defaultAgent)+ } else if (k === 'd' && e.shiftKey) {+ e.preventDefault()+ toggleDictation()}}window.addEventListener('keydown', onKey)return () => window.removeEventListener('keydown', onKey)- }, [addTerminal, addAgentNode])+ }, [addTerminal, addAgentNode, toggleDictation])// "Connect to a host" from the Settings section / tab-menu dialog: they collect the pairing offer// and dispatch it here (a window event, so they need no Canvas reference), and this runs the SAME@@ -5879,6 +5907,10 @@ export function Canvas() {{shortcutsOpen && <ShortcutsPanel onClose={() => setShortcutsOpen(false)} />}+ {dictationOpen && (+ <DictationOverlay target={dictationTarget} onClose={() => setDictationOpen(false)} />+ )}+{bugReportOpen && (<BugReportDialogenv={{ appVersion, userAgent: navigator.userAgent }}@@ -6122,6 +6154,8 @@ export function Canvas() {onFitView={() => fitView({ padding: 0.2, duration: 300 })}onZoomIn={() => zoomIn({ duration: 150 })}onZoomOut={() => zoomOut({ duration: 150 })}+ onDictate={toggleDictation}+ dictateActive={dictationOpen}/></div>)diff --git a/src/renderer/components/DictationOverlay.tsx b/src/renderer/components/DictationOverlay.tsxnew file mode 100644index 000000000..e39fbd541--- /dev/null+++ b/src/renderer/components/DictationOverlay.tsx@@ -0,0 +1,317 @@+// 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.+//+// NOTHING here auto-submits: only the explicit Send button ever pushes text into a session.+//+// Insert-without-Enter gap (read before "fixing" this): the design wants Insert to write into a+// terminal WITHOUT the trailing Enter that `pty.sendText` always appends (it runs two separate+// `tmux send-keys` calls server-side — literal text, then a separate Enter — with no way to skip+// the second one). The only primitive that writes without an Enter is `pty.write(sessionId, data)`,+// but that takes the PTY's own ephemeral session id (`pty-<n>`, assigned in PtyManager.spawnSession),+// which is NOT the node id and is only ever known inside the mounted TerminalNode component (its+// `sessionId` local variable, set from `pty.create()`'s result) — nothing outside that component+// exposes it. Reaching it from here would mean either a new IPC channel keyed by persistKey (out of+// scope for this task) or modifying TerminalNode.tsx to publish a lookup (also out of this task's+// file list). Chat has the same shape of gap: ChatNode's compose box is local component state with+// no externally settable draft. So Insert is disabled for both target kinds, with a tooltip+// explaining why — Send (which already has an explicit-submission story) is the one working action.+import { useCallback, useEffect, useRef, useState } from 'react'+import { createPortal } from 'react-dom'+import { PcmCapture } from '../lib/pcm-capture'+import { useSession } from '../session/session'+import { useChatSessions } from '../state/chatSessions'++export interface DictationTarget {+ kind: 'terminal' | 'chat'+ nodeId: string+ title: string+}++interface DictationOverlayProps {+ target: DictationTarget | null+ onClose: () => void+}++type Phase = 'idle' | 'recording' | 'transcribing' | 'text'++/** mm:ss, floored to whole seconds. Pure — no side effects. */+export function formatElapsed(ms: number): string {+ const total = Math.max(0, Math.floor(ms / 1000))+ const m = Math.floor(total / 60)+ const s = total % 60+ return `${m}:${s.toString().padStart(2, '0')}`+}++/** Appends a new take's text after any existing text, space-separated; trims both sides. */+export function appendTake(existing: string, take: string): string {+ const a = existing.trim()+ const b = take.trim()+ if (!a) return b+ if (!b) return a+ return `${a} ${b}`+}++const LEVEL_POLL_MS = 100 // ~10Hz++export function DictationOverlay({ target, onClose }: DictationOverlayProps) {+ const { api } = useSession()+ const addLocalUser = useChatSessions((s) => s.addLocalUser)+ const chatWorking = useChatSessions((s) =>+ target?.kind === 'chat' ? s.byId[target.nodeId]?.working : undefined+ )++ const [phase, setPhase] = useState<Phase>('idle')+ const [text, setText] = useState('')+ const [error, setError] = useState<string | null>(null)+ const [elapsedMs, setElapsedMs] = useState(0)+ const [level, setLevel] = useState(0)+ const [sending, setSending] = useState(false)++ const captureRef = useRef<PcmCapture | null>(null)+ const consentAskedRef = useRef(false)+ const startedAtRef = useRef(0)+ const timerRef = useRef<ReturnType<typeof setInterval> | null>(null)++ const clearTimer = useCallback(() => {+ if (timerRef.current) {+ clearInterval(timerRef.current)+ timerRef.current = null+ }+ }, [])++ // 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)+ }, [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(() => {+ return () => {+ clearTimer()+ captureRef.current?.cancel()+ captureRef.current = null+ }+ }, [clearTimer])++ const startRecording = useCallback(async () => {+ setError(null)+ if (!consentAskedRef.current) {+ consentAskedRef.current = true+ try {+ const ok = await window.nodeTerminal.speech.micConsent()+ if (!ok) {+ setError('Microphone access was not granted.')+ return+ }+ } catch (err) {+ setError(err instanceof Error ? err.message : 'Could not request microphone access.')+ return+ }+ }++ const capture = new PcmCapture()+ try {+ await capture.start()+ } catch (err) {+ setError(err instanceof Error ? err.message : 'Could not start recording.')+ return+ }+ captureRef.current = capture++ startedAtRef.current = Date.now()+ setElapsedMs(0)+ setLevel(0)+ setPhase('recording')+ timerRef.current = setInterval(() => {+ setElapsedMs(Date.now() - startedAtRef.current)+ setLevel(captureRef.current?.level() ?? 0)+ }, LEVEL_POLL_MS)+ }, [])++ const stopRecording = useCallback(async () => {+ clearTimer()+ const capture = captureRef.current+ captureRef.current = null+ if (!capture) return+ const pcm = capture.stop()+ setPhase('transcribing')+ try {+ const { text: transcribed } = await window.nodeTerminal.speech.transcribe(pcm)+ 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.+ setPhase(text.trim() ? 'text' : 'idle')+ }+ }, [clearTimer, text])++ const handleClose = useCallback(() => {+ if (phase === 'recording') {+ clearTimer()+ captureRef.current?.cancel()+ captureRef.current = null+ }+ onClose()+ }, [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).+ useEffect(() => {+ const onKey = (e: KeyboardEvent) => {+ if (e.key === 'Escape') {+ e.preventDefault()+ handleClose()+ }+ }+ window.addEventListener('keydown', onKey)+ return () => window.removeEventListener('keydown', onKey)+ }, [handleClose])++ const send = useCallback(async () => {+ if (!target) return+ const value = text.trim()+ if (!value) return+ setSending(true)+ setError(null)+ try {+ if (target.kind === 'terminal') {+ const ok = await api.pty.sendText(target.nodeId, value)+ if (!ok) {+ setError('Could not send — the terminal session is not available.')+ return+ }+ } else {+ api.chat.send(target.nodeId, value)+ if (!chatWorking) addLocalUser(target.nodeId, value)+ }+ onClose()+ } catch (err) {+ setError(err instanceof Error ? err.message : 'Failed to send.')+ } finally {+ setSending(false)+ }+ }, [target, text, api, chatWorking, addLocalUser, onClose])++ const copy = useCallback(() => {+ const value = text.trim()+ if (!value) return+ window.nodeTerminal.clipboard.writeText(value)+ }, [text])++ const insertDisabledReason = !target+ ? 'Select a terminal or chat node first.'+ : target.kind === 'chat'+ ? "Chat has no external draft field — use Send."+ : "Inserting without submitting isn't available yet (needs the terminal's live session) — use Send."++ const hasText = !!text.trim()++ 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}>+ ×+ </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>+ )}++ {phase === 'recording' && (+ <div className="dictation__recording">+ <button+ type="button"+ className="dictation__mic dictation__mic--active"+ onClick={() => void stopRecording()}+ title="Stop recording"+ >+ <MicIcon />+ </button>+ <div className="dictation__meter">+ <div className="dictation__meter-fill" style={{ width: `${Math.round(level * 100)}%` }} />+ </div>+ <span className="dictation__elapsed">{formatElapsed(elapsedMs)}</span>+ </div>+ )}++ {phase === 'transcribing' && (+ <div className="dictation__transcribing">+ <span className="dictation__spinner" />+ <span>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>+ </div>+ )}+ </div>++ {error && <div className="dictation__error">{error}</div>}++ <div className="dictation__actions">+ <button type="button" className="dictation__btn" onClick={copy} disabled={!hasText}>+ Copy+ </button>+ <button type="button" className="dictation__btn" disabled title={insertDisabledReason}>+ Insert+ </button>+ <button+ type="button"+ className="dictation__btn dictation__btn--primary"+ onClick={() => void send()}+ disabled={!target || !hasText || sending}+ >+ Send+ </button>+ </div>+ </div>,+ document.body+ )+}++function MicIcon() {+ return (+ <svg width={18} height={18} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.8} strokeLinecap="round" strokeLinejoin="round">+ <rect x="9" y="2" width="6" height="12" rx="3" />+ <path d="M5 11a7 7 0 0 0 14 0M12 18v4M8 22h8" />+ </svg>+ )+}diff --git a/src/renderer/components/Dock.tsx b/src/renderer/components/Dock.tsxindex 2dc9af6f1..b005b801e 100644--- a/src/renderer/components/Dock.tsx+++ b/src/renderer/components/Dock.tsx@@ -24,6 +24,8 @@ interface DockProps {onFitView: () => voidonZoomIn: () => voidonZoomOut: () => void+ onDictate: () => void+ dictateActive: boolean}/**@@ -48,7 +50,9 @@ export function Dock({onSave,onFitView,onZoomIn,- onZoomOut+ onZoomOut,+ onDictate,+ dictateActive}: DockProps) {const [menuOpen, setMenuOpen] = useState(false)const customAgents = useSettings((s) => s.settings.customAgents)@@ -177,6 +181,13 @@ export function Dock({<button className="dock-btn" title="Fit view" onClick={onFitView}><FrameIcon /></button>+ <button+ className={`dock-btn${dictateActive ? ' active' : ''}`}+ title="Dictate (⌘⇧D)"+ onClick={onDictate}+ >+ <MicIcon />+ </button><span className="dock-sep" />@@ -289,6 +300,14 @@ function EditorIcon() {</svg>)}+function MicIcon() {+ return (+ <svg {...S}>+ <rect x="9" y="2" width="6" height="12" rx="3" />+ <path d="M5 11a7 7 0 0 0 14 0M12 18v4M8 22h8" />+ </svg>+ )+}function RemoteIcon() {return (<svg {...S}>diff --git a/src/renderer/components/ShortcutsPanel.tsx b/src/renderer/components/ShortcutsPanel.tsxindex 8d8fc0eb8..2d4a20c17 100644--- a/src/renderer/components/ShortcutsPanel.tsx+++ b/src/renderer/components/ShortcutsPanel.tsx@@ -17,6 +17,7 @@ const SECTIONS: { title: string; rows: Row[] }[] = [{ keys: ['⌘', 'K'], label: 'Command palette' },{ keys: ['⌘', ','], label: 'Settings' },{ keys: ['⌘', '/'], label: 'This shortcuts panel' },+ { keys: ['⌘', '⇧', 'D'], label: 'Dictate' },{ keys: ['⌘', 'Z'], label: 'Undo' },{ keys: ['⌘', '⇧', 'Z'], label: 'Redo' }]diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 793310db4..e2f5f2459 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -372,6 +372,11 @@ body,color: #fff;}+.dock-btn.active {+ background: rgba(10, 132, 255, 0.22);+ color: var(--accent-hover);+}+.dock-sep {width: 1px;height: 22px;@@ -452,6 +457,239 @@ body,flex-shrink: 0;}+/* ---- Dictation overlay: bottom-center floating card above the Dock ---- */+.dictation {+ position: fixed;+ bottom: 88px;+ left: 50%;+ transform: translateX(-50%);+ z-index: 21;+ width: 420px;+ max-width: 92vw;+ display: flex;+ flex-direction: column;+ gap: 10px;+ padding: 12px 14px;+ background: rgba(40, 40, 42, 0.98);+ backdrop-filter: blur(10px);+ border: 1px solid var(--border);+ border-radius: 14px;+ box-shadow: 0 20px 56px rgba(0, 0, 0, 0.55);+}++.dictation__head {+ display: flex;+ align-items: center;+ gap: 8px;+}++.dictation__title {+ font-size: 13px;+ font-weight: 600;+}++.dictation__target {+ flex: 1 1 auto;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ color: var(--muted);+ font-size: 12px;+}++.dictation__close {+ flex-shrink: 0;+ width: 22px;+ height: 22px;+ display: inline-flex;+ align-items: center;+ justify-content: center;+ background: transparent;+ border: none;+ border-radius: 6px;+ color: var(--muted);+ font-size: 16px;+ line-height: 1;+ cursor: pointer;+}++.dictation__close:hover {+ background: var(--panel-header);+ color: var(--text);+}++.dictation__body {+ display: flex;+ align-items: center;+ justify-content: center;+ min-height: 56px;+}++.dictation__mic {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ gap: 8px;+ padding: 10px 16px;+ background: var(--panel-header);+ border: 1px solid var(--border);+ border-radius: 999px;+ color: var(--text);+ font-size: 13px;+ cursor: pointer;+}++.dictation__mic:hover {+ border-color: rgba(255, 255, 255, 0.25);+}++.dictation__mic--active {+ background: rgba(255, 69, 58, 0.18);+ border-color: rgba(255, 69, 58, 0.5);+ color: #ff453a;+ animation: dictation-pulse 1.4s ease-in-out infinite;+}++.dictation__mic--small {+ flex-shrink: 0;+ padding: 8px;+}++@keyframes dictation-pulse {+ 0%,+ 100% {+ box-shadow: 0 0 0 0 rgba(255, 69, 58, 0.4);+ }+ 50% {+ box-shadow: 0 0 0 6px rgba(255, 69, 58, 0);+ }+}++.dictation__recording {+ display: flex;+ align-items: center;+ gap: 10px;+ width: 100%;+}++.dictation__meter {+ flex: 1 1 auto;+ height: 6px;+ border-radius: 3px;+ background: rgba(255, 255, 255, 0.1);+ overflow: hidden;+}++.dictation__meter-fill {+ height: 100%;+ background: #ff453a;+ border-radius: 3px;+ transition: width 80ms linear;+}++.dictation__elapsed {+ flex-shrink: 0;+ min-width: 40px;+ text-align: right;+ font-variant-numeric: tabular-nums;+ color: var(--muted);+ font-size: 12px;+}++.dictation__transcribing {+ display: flex;+ align-items: center;+ gap: 8px;+ color: var(--muted);+ font-size: 13px;+}++.dictation__spinner {+ width: 14px;+ height: 14px;+ border-radius: 50%;+ border: 2px solid var(--border);+ border-top-color: var(--accent);+ animation: dictation-spin 0.8s linear infinite;+}++@keyframes dictation-spin {+ to {+ transform: rotate(360deg);+ }+}++.dictation__text-row {+ display: flex;+ align-items: flex-end;+ gap: 8px;+ width: 100%;+}++.dictation__textarea {+ flex: 1 1 auto;+ min-height: 60px;+ max-height: 180px;+ resize: vertical;+ background: var(--panel-header);+ border: 1px solid var(--border);+ border-radius: 8px;+ color: var(--text);+ font-size: 13px;+ font-family: inherit;+ padding: 8px 10px;+}++.dictation__textarea:focus {+ outline: none;+ border-color: var(--accent);+}++.dictation__error {+ padding: 7px 10px;+ border-radius: 8px;+ font-size: 12px;+ color: #ff453a;+ background: rgba(255, 69, 58, 0.12);+ border: 1px solid rgba(255, 69, 58, 0.35);+}++.dictation__actions {+ display: flex;+ justify-content: flex-end;+ gap: 8px;+}++.dictation__btn {+ background: var(--panel-header);+ border: 1px solid var(--border);+ border-radius: 8px;+ color: var(--text);+ font-size: 13px;+ padding: 7px 14px;+ cursor: pointer;+}++.dictation__btn:hover:not(:disabled) {+ background: rgba(255, 255, 255, 0.1);+}++.dictation__btn:disabled {+ opacity: 0.4;+ cursor: not-allowed;+}++.dictation__btn--primary {+ background: var(--accent);+ border-color: transparent;+ color: #fff;+ font-weight: 600;+}++.dictation__btn--primary:hover:not(:disabled) {+ background: var(--accent-hover);+}+/* ---- Terminal node ---- */.term-node {width: 100%;@@ -2377,7 +2615,8 @@ body,.ctx-backdrop,.tab-menu,.controls-cluster,-.dock {+.dock,+.dictation {-webkit-app-region: no-drag;}