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.

fix(chat): no mic types into the hidden pane while the chat view is up

reviewf7e0d00d4cf3
diff --git a/CLAUDE.md b/CLAUDE.md
index 4c9b7a38e..0e50da0d3 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2601,7 +2601,15 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile
"Revise…" textarea and the question "Other" input share that class and sit outside the box. With
focus anywhere else inside `.term-chat` (those fields, the answer buttons) BOTH shortcut paths
refuse (`shortcutDictationFocus` → `refuse`): their fallback, the selected terminal, is the hidden
- pane showing the very plan/question dialog, and a take sent there would answer it.
+ pane showing the very plan/question dialog, and typed characters landing there would move its
+ highlight or fill its "Other" field (the overlay types with `enter: false`, so nothing submits).
+ **Every mic that names only a NODE** — the terminal header mic, the card modal's header mic, the
+ Dock mic and the shortcut fallback (selected terminal / open card) — goes through
+ `dictationTargetForNode`: while that node's chat view is up (`.term-chat[data-chat-node-id]`) the
+ take goes to its mounted composer (the card modal's own when the modal is open for that node, so
+ a modal showing the LIVE terminal still targets it), a chat view with no composer refuses, and
+ otherwise it is the terminal as before. Every refusal says so in one `nodeterm:toast`
+ (`announceChatDictationRefusal`, naming the composer mic) instead of a silent dead key.
- **Subagent visualization** (agents in `SUBAGENT_CAPABLE`) — `subagent-start`/`subagent-end`
normalized events (from Claude's `PreToolUse`/`PostToolUse` on tool `Agent`/`Task`, correlated
by `tool_use_id`) drive a transient `state/agentNodes.ts` store. Claude launches subagents
@@ -4434,7 +4442,8 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
swallows its chord app-wide with the recorder reporting no conflict.
- **Dictation has its own conflict bucket** (`conflictBucket` — `speech.dictation` is never in
`global`), because it never competes at dispatch: the resolver skips it and its own keyed
- listener claims the chord FIRST **in plain app focus only**, which is precedence, not ambiguity.
+ listener claims the chord FIRST **in plain app focus or the ⌘M composer box** (`isChatComposerTarget`),
+ which is precedence, not ambiguity.
Overlap policy is deliberately asymmetric — the LOAD path PERMITS a shared chord (legacy
settings.json files contain them and `sanitizeKeybindingOverrides` would otherwise strip the
user's own binding with the migrated one), while the Settings UI REFUSES to create one
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 774dab821..237a224c6 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -157,7 +157,13 @@ import { WelcomeScreen } from '../components/WelcomeScreen'
import { CloneRepoDialog } from '../components/CloneRepoDialog'
import { markMobileLaunchSeen, shouldShowMobileLaunch } from '../lib/mobileLaunch'
import type { DictationTarget } from '../components/DictationOverlay'
-import { composerFromElement, dictationTargetFromRequest, shortcutDictationFocus } from '../lib/chatComposerDictation'
+import {
+ announceChatDictationRefusal,
+ composerFromElement,
+ dictationTargetForNode,
+ dictationTargetFromRequest,
+ shortcutDictationFocus
+} from '../lib/chatComposerDictation'
import { describeOs, REPO_URL } from '../lib/bugReport'
import { shouldReleasePaneFocus } from '../lib/paneFocus'
import {
@@ -2392,6 +2398,10 @@ export function Canvas() {
const n = nodesRef.current.find((x) => x.id === c.nodeId)
return dictationTargetFromRequest(c, (n?.data.title as string) || 'Untitled')
}
+ // A take for a NODE (a mic that names one, or a shortcut's fallback): its composer while its ⌘M
+ // chat view is up, 'refuse' for a chat view with no composer, else its terminal as before.
+ const nodeDictationTarget = (nodeId: string, title: string): DictationTarget | 'refuse' =>
+ dictationTargetForNode(nodeId, title, { inCardModal: kanbanModalNodeRef.current === nodeId }) ?? 'refuse'
const toggleDictation = useCallback(() => {
setDictationOpen((open) => {
if (open) {
@@ -2400,7 +2410,10 @@ export function Canvas() {
}
// Focus in a ⌘M chat view but outside its composer: the fallback below would target the
// hidden pane showing the dialog those controls answer (shortcutDictationFocus).
- if (shortcutDictationFocus(document.activeElement) === 'refuse') return false
+ if (shortcutDictationFocus(document.activeElement) === 'refuse') {
+ announceChatDictationRefusal()
+ return false
+ }
const composer = focusedComposerDictationTarget()
if (composer) {
setDictationTarget(composer)
@@ -2408,16 +2421,18 @@ export function Canvas() {
return true
}
// A kanban card modal open over the board wins (nothing on the canvas is selected then);
- // otherwise fall back to the selected canvas terminal.
+ // otherwise fall back to the selected canvas terminal — through `nodeDictationTarget`, which
+ // sends the take to that node's composer (or refuses) while its chat view hides the pane.
const modalId = kanbanModalNodeRef.current
- const target = modalId
+ const node = modalId
? nodesRef.current.find((n) => n.id === modalId && n.type === 'terminal')
: nodesRef.current.find((n) => n.selected && n.type === 'terminal')
- setDictationTarget(
- target
- ? { kind: 'terminal', nodeId: target.id, title: (target.data.title as string) || 'Untitled' }
- : null
- )
+ const target = node ? nodeDictationTarget(node.id, (node.data.title as string) || 'Untitled') : null
+ if (target === 'refuse') {
+ announceChatDictationRefusal()
+ return false
+ }
+ setDictationTarget(target)
setDictationNonce((n) => n + 1)
return true
})
@@ -4482,9 +4497,17 @@ export function Canvas() {
if (!d?.nodeId) return
const n = nodesRef.current.find((x) => x.id === d.nodeId)
if (!n) return
- setDictationTarget(
- dictationTargetFromRequest({ nodeId: n.id, composerId: d.composerId }, (n.data.title as string) || 'Untitled')
- )
+ const title = (n.data.title as string) || 'Untitled'
+ // A bare `{nodeId}` (the terminal header mic, the card modal's header mic) while that node's
+ // chat view is up must not type into the hidden pane: its composer takes it, or it is refused.
+ const target = d.composerId
+ ? dictationTargetFromRequest({ nodeId: n.id, composerId: d.composerId }, title)
+ : nodeDictationTarget(n.id, title)
+ if (target === 'refuse') {
+ announceChatDictationRefusal()
+ return
+ }
+ setDictationTarget(target)
setDictationOpen(true)
setDictationNonce((prev) => prev + 1)
}
@@ -5071,22 +5094,20 @@ export function Canvas() {
if (!chordHeld(e, combo, isMac)) return
// Same refusal as the keyed path: hold-to-talk has no typing guard, so with focus on a
// plan/question answer control it would otherwise dictate into the hidden dialog pane.
- if (shortcutDictationFocus(document.activeElement) === 'refuse') return
- armed = true
- heldSince = Date.now()
+ if (shortcutDictationFocus(document.activeElement) === 'refuse') {
+ announceChatDictationRefusal()
+ return
+ }
const sel = nodesRef.current.find((n) => n.selected && n.type === 'terminal')
const composer = focusedComposerDictationTarget()
- setDictationTarget(
- composer
- ? composer
- : sel
- ? {
- kind: 'terminal',
- nodeId: sel.id,
- title: (sel.data.title as string) || 'Untitled'
- }
- : null
- )
+ const target = composer ?? (sel ? nodeDictationTarget(sel.id, (sel.data.title as string) || 'Untitled') : null)
+ if (target === 'refuse') {
+ announceChatDictationRefusal()
+ return
+ }
+ armed = true
+ heldSince = Date.now()
+ setDictationTarget(target)
setDictationNonce((n) => n + 1)
setDictationOpen(true)
return
diff --git a/src/renderer/lib/chatComposerDictation.test.ts b/src/renderer/lib/chatComposerDictation.test.ts
index d8546699c..3e6c13f99 100644
--- a/src/renderer/lib/chatComposerDictation.test.ts
+++ b/src/renderer/lib/chatComposerDictation.test.ts
@@ -3,8 +3,10 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import {
+ announceChatDictationRefusal,
composerFromElement,
deliverToComposer,
+ dictationTargetForNode,
dictationTargetFromRequest,
requestComposerDictation,
subscribeComposerDictation
@@ -94,8 +96,74 @@ describe('composerFromElement (shortcut dictation with the caret in a composer)'
const toggle = src.slice(src.indexOf('const toggleDictation = useCallback'))
expect(toggle.indexOf('focusedComposerDictationTarget()')).toBeGreaterThan(-1)
expect(toggle.indexOf('focusedComposerDictationTarget()')).toBeLessThan(toggle.indexOf('kanbanModalNodeRef.current'))
- const hold = src.slice(src.indexOf('armed = true\n heldSince = Date.now()'))
+ const hold = src.slice(src.indexOf('if (!chordHeld(e, combo, isMac)) return'))
expect(hold.indexOf('focusedComposerDictationTarget()')).toBeGreaterThan(-1)
expect(hold.indexOf('focusedComposerDictationTarget()')).toBeLessThan(hold.indexOf('setDictationNonce'))
})
})
+
+describe('dictationTargetForNode (every mic that names a node: header, card modal, Dock, shortcut fallback)', () => {
+ const mk = (html: string): HTMLDivElement => {
+ const root = document.createElement('div')
+ root.innerHTML = html
+ document.body.append(root)
+ return root
+ }
+ const composerBox = (node: string, id: string) =>
+ `<div class="term-chat" data-chat-node-id="${node}"><div data-chat-composer-id="${id}" data-chat-node-id="${node}"><textarea></textarea></div></div>`
+
+ it('targets the terminal when no chat view is up for the node (unchanged behavior)', () => {
+ const root = mk('<div class="term-node"></div>')
+ expect(dictationTargetForNode('n1', 'T', { root })).toEqual({ kind: 'terminal', nodeId: 'n1', title: 'T' })
+ root.remove()
+ })
+
+ it('targets the node\'s mounted COMPOSER while its chat view is up — never the hidden pane', () => {
+ const root = mk(composerBox('n1', 'c1') + composerBox('n2', 'c2'))
+ expect(dictationTargetForNode('n1', 'T', { root })).toEqual({ kind: 'chat-composer', nodeId: 'n1', composerId: 'c1', title: 'T' })
+ root.remove()
+ })
+
+ it('prefers the composer inside the card modal when the modal is open for that node', () => {
+ const root = mk(composerBox('n1', 'canvas') + `<div class="kanban-modal">${composerBox('n1', 'modal')}</div>`)
+ expect(dictationTargetForNode('n1', 'T', { root, inCardModal: true })).toMatchObject({ composerId: 'modal' })
+ expect(dictationTargetForNode('n1', 'T', { root })).toMatchObject({ composerId: 'canvas' })
+ root.remove()
+ })
+
+ it('with the card modal open and SHOWING its live terminal, the modal terminal is the target even if the canvas node is in chat view', () => {
+ const root = mk(composerBox('n1', 'canvas') + '<div class="kanban-modal"><div class="kanban-modal__pane"></div></div>')
+ expect(dictationTargetForNode('n1', 'T', { root, inCardModal: true })).toEqual({ kind: 'terminal', nodeId: 'n1', title: 'T' })
+ root.remove()
+ })
+
+ it('REFUSES (null) a chat view with no composer (read-only): the pane under it is hidden', () => {
+ const root = mk('<div class="term-chat" data-chat-node-id="n1"></div>')
+ expect(dictationTargetForNode('n1', 'T', { root })).toBeNull()
+ root.remove()
+ })
+
+ it('matches the node id literally (quotes/backslashes cannot break out of the selector)', () => {
+ const root = document.createElement('div')
+ const box = document.createElement('div')
+ box.setAttribute('data-chat-composer-id', 'c1')
+ box.setAttribute('data-chat-node-id', 'a"b\\c')
+ root.append(box)
+ document.body.append(root)
+ expect(dictationTargetForNode('a"b\\c', 'T', { root })).toMatchObject({ kind: 'chat-composer', composerId: 'c1' })
+ expect(dictationTargetForNode('a"b', 'T', { root })).toMatchObject({ kind: 'terminal' })
+ root.remove()
+ })
+
+ it('announces a refusal once, naming the composer mic (a silent refusal reads as a dead key)', () => {
+ const seen: Array<{ kind: string; message: string }> = []
+ const h = (e: Event) => seen.push((e as CustomEvent).detail)
+ window.addEventListener('nodeterm:toast', h)
+ announceChatDictationRefusal()
+ window.removeEventListener('nodeterm:toast', h)
+ expect(seen).toHaveLength(1)
+ expect(seen[0].kind).toBe('error')
+ expect(seen[0].message).toMatch(/composer/i)
+ expect(seen[0].message).toMatch(/mic/i)
+ })
+})
diff --git a/src/renderer/lib/chatComposerDictation.ts b/src/renderer/lib/chatComposerDictation.ts
index 17498ef33..5079e5c63 100644
--- a/src/renderer/lib/chatComposerDictation.ts
+++ b/src/renderer/lib/chatComposerDictation.ts
@@ -80,11 +80,53 @@ export function composerFromElement(el: Element | null | undefined): { nodeId: s
* `composer`: fill that composer's draft. `refuse`: focus is inside a ⌘M chat view but not in its
* composer — the plan "Revise…" textarea, a question's "Other" input, an answer button — and the
* shortcut's fallback target, the selected terminal, is the HIDDEN pane under the view, which at
- * that moment is showing the very plan/question dialog those controls answer; a take sent there
- * (text + Enter) would answer it. `default`: the ordinary rule (card modal, selected terminal).
+ * that moment may be showing the very plan/question/permission dialog those controls answer. The
+ * overlay types a take with `enter: false`, so nothing is submitted — the risk is the typed
+ * characters themselves landing in a select dialog (moving its highlight) or in its "Other" field.
+ * `default`: the ordinary rule (card modal, selected terminal) — which then asks
+ * `dictationTargetForNode` whether THAT node's chat view is up.
*/
export function shortcutDictationFocus(el: Element | null | undefined): 'composer' | 'refuse' | 'default' {
if (composerFromElement(el)) return 'composer'
if (el?.closest?.('.term-chat')) return 'refuse'
return 'default'
}
+
+/** A node-id attribute value, escaped for a double-quoted selector (only `"` and `\` matter). */
+const attrValue = (v: string): string => v.replace(/["\\]/g, '\\$&')
+
+/**
+ * Where a take for NODE `nodeId` goes when the request names only the node — the terminal header
+ * mic, the card modal's header mic, the Dock mic and the shortcut fallback (the selected terminal
+ * or the open card's node). While that node's ⌘M chat view is up its pane is HIDDEN and may hold a
+ * select dialog, so:
+ * - a mounted composer for the node → that composer's draft;
+ * - the chat view up with no composer (read-only) → null = refuse;
+ * - otherwise → the terminal, exactly as before.
+ * `inCardModal`: the card modal is open for this node — only its own view counts, so a modal showing
+ * the LIVE terminal targets it even while the canvas node underneath is in chat view, and a modal in
+ * chat view targets the modal's composer rather than the canvas one.
+ */
+export function dictationTargetForNode(
+ nodeId: string,
+ title: string,
+ opts: { root?: ParentNode; inCardModal?: boolean } = {}
+): DictationTarget | null {
+ const root = opts.root ?? document
+ const scope: ParentNode = (opts.inCardModal && root.querySelector('.kanban-modal')) || root
+ const id = attrValue(nodeId)
+ const box = scope.querySelector(`[data-chat-composer-id][data-chat-node-id="${id}"]`)
+ const composerId = box?.getAttribute('data-chat-composer-id')
+ if (composerId) return { kind: 'chat-composer', nodeId, composerId, title }
+ if (scope.querySelector(`.term-chat[data-chat-node-id="${id}"]`)) return null
+ return { kind: 'terminal', nodeId, title }
+}
+
+/** The one sentence a refused dictation says (shortcut, Dock or header mic, inside a chat view). */
+export const CHAT_DICTATION_REFUSED =
+ "Dictation can't go to the terminal while its chat view is open — use the mic in the chat composer."
+
+/** Say so — a refused chord or mic click with nothing on screen reads as a dead key. */
+export function announceChatDictationRefusal(): void {
+ window.dispatchEvent(new CustomEvent('nodeterm:toast', { detail: { kind: 'error', message: CHAT_DICTATION_REFUSED } }))
+}
diff --git a/src/renderer/lib/chatDictationFocus.test.tsx b/src/renderer/lib/chatDictationFocus.test.tsx
index 6c9f338e9..d6f447a5b 100644
--- a/src/renderer/lib/chatDictationFocus.test.tsx
+++ b/src/renderer/lib/chatDictationFocus.test.tsx
@@ -146,4 +146,25 @@ describe('shortcutDictationFocus (both shortcut paths decide with it)', () => {
expect(refuseHold).toBeGreaterThan(-1)
expect(refuseHold).toBeLessThan(hold.indexOf('armed = true'))
})
+
+ it('every mic that names only a node goes through nodeDictationTarget and says so on refusal (source pin)', () => {
+ const src = readFileSync(resolve(__dirname, '../canvas/Canvas.tsx'), 'utf8').replace(/\r\n/g, '\n')
+ // The header / card-modal mic: a bare `{nodeId}` request.
+ const onDictate = src.slice(src.indexOf('const onDictate = (e: Event): void => {'))
+ expect(onDictate.indexOf('nodeDictationTarget(n.id, title)')).toBeGreaterThan(-1)
+ expect(onDictate.indexOf('announceChatDictationRefusal()')).toBeLessThan(onDictate.indexOf('setDictationOpen(true)'))
+ // The shortcut / Dock fallback.
+ const toggle = src.slice(src.indexOf('const toggleDictation = useCallback'))
+ expect(toggle.indexOf('nodeDictationTarget(node.id')).toBeGreaterThan(-1)
+ expect(toggle.indexOf('nodeDictationTarget(node.id')).toBeLessThan(toggle.indexOf('setDictationTarget(target)'))
+ // Hold-to-talk: the target is decided BEFORE it arms, so a refusal never opens the overlay.
+ const hold = src.slice(src.indexOf('if (!chordHeld(e, combo, isMac)) return'))
+ expect(hold.indexOf('nodeDictationTarget(sel.id')).toBeGreaterThan(-1)
+ expect(hold.indexOf('nodeDictationTarget(sel.id')).toBeLessThan(hold.indexOf('armed = true'))
+ })
+
+ it('the chat panel marks its node, so a node-named mic can find its chat view', async () => {
+ const src = readFileSync(resolve(__dirname, '../nodes/ChatPanel.tsx'), 'utf8').replace(/\r\n/g, '\n')
+ expect(src).toMatch(/className="term-chat nodrag nowheel" data-chat-node-id=\{nodeId\}/)
+ })
})
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index 1baf63025..f6eaef03f 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -561,7 +561,9 @@ export function ChatPanel({
const showEmpty = messages.length === 0 && loadState !== 'loading' && !(loadState === 'ok' && historyPending)
return (
- <div className="term-chat nodrag nowheel">
+ // `data-chat-node-id`: which node's chat view this is — the mics that name only a node ask it
+ // (lib/chatComposerDictation.ts `dictationTargetForNode`) so a take never reaches the hidden pane.
+ <div className="term-chat nodrag nowheel" data-chat-node-id={nodeId}>
<div className="term-chat__bar">
<span>{title ?? 'Chat'}</span>
<span className="term-chat__bar-end">