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
fix(chat): gate composer dictation on the composer box, refuse in answer controls
review3090bf089283
diff --git a/CLAUDE.md b/CLAUDE.mdindex 6f623375e..44248f2b6 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2585,7 +2585,12 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilethere would type into it — the pane is not observable from here. Shortcut dictation (keyed chordand hold-to-talk) targets the composer holding the caret before the selected terminal (the paneunder the view is hidden) via `composerFromElement`; the dispatcher offers keyed dictation in- that one text field (`isChatComposerTarget`).+ that one text field (`isChatComposerTarget`). Both are keyed on the composer BOX+ (`[data-chat-composer-id]`), never on the textarea's `term-chat__input` class — the plan+ "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.- **Subagent visualization** (agents in `SUBAGENT_CAPABLE`) — `subagent-start`/`subagent-end`normalized events (from Claude's `PreToolUse`/`PostToolUse` on tool `Agent`/`Task`, correlatedby `tool_use_id`) drive a transient `state/agentNodes.ts` store. Claude launches subagentsdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex d0b4c8a01..774dab821 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -157,7 +157,7 @@ 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 } from '../lib/chatComposerDictation'+import { composerFromElement, dictationTargetFromRequest, shortcutDictationFocus } from '../lib/chatComposerDictation'import { describeOs, REPO_URL } from '../lib/bugReport'import { shouldReleasePaneFocus } from '../lib/paneFocus'import {@@ -2398,6 +2398,9 @@ export function Canvas() {setDictationStopSignal((n) => n + 1)return true}+ // 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 falseconst composer = focusedComposerDictationTarget()if (composer) {setDictationTarget(composer)@@ -5066,6 +5069,9 @@ export function Canvas() {if (e.repeat) returnif (!isModifierEventKey(e.key)) returnif (!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') returnarmed = trueheldSince = Date.now()const sel = nodesRef.current.find((n) => n.selected && n.type === 'terminal')diff --git a/src/renderer/lib/chatComposerDictation.ts b/src/renderer/lib/chatComposerDictation.tsindex deb487faa..17498ef33 100644--- a/src/renderer/lib/chatComposerDictation.ts+++ b/src/renderer/lib/chatComposerDictation.ts@@ -7,6 +7,7 @@// once (the canvas node's ⌘M face and the kanban card modal's), and a take must land in the one// whose mic was clicked, exactly once.import type { DictationTarget } from '../components/DictationOverlay'+import { CHAT_COMPOSER_BOX_SELECTOR } from './keyContext'interface ComposerDictationDetail {composerId: string@@ -67,9 +68,23 @@ export function subscribeComposerDictation(composerId: string, onText: (text: st* live in Canvas and know nothing of which panel is mounted.*/export function composerFromElement(el: Element | null | undefined): { nodeId: string; composerId: string } | null {- const box = el?.closest?.('[data-chat-composer-id]')+ const box = el?.closest?.(CHAT_COMPOSER_BOX_SELECTOR)if (!box) return nullconst composerId = box.getAttribute('data-chat-composer-id')const nodeId = box.getAttribute('data-chat-node-id')return composerId && nodeId ? { nodeId, composerId } : null}++/**+ * What a SHORTCUT dictation press (keyed chord or hold-to-talk) may do given where focus is.+ * `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).+ */+export function shortcutDictationFocus(el: Element | null | undefined): 'composer' | 'refuse' | 'default' {+ if (composerFromElement(el)) return 'composer'+ if (el?.closest?.('.term-chat')) return 'refuse'+ return 'default'+}diff --git a/src/renderer/lib/chatDictationFocus.test.tsx b/src/renderer/lib/chatDictationFocus.test.tsxnew file mode 100644index 000000000..6c9f338e9--- /dev/null+++ b/src/renderer/lib/chatDictationFocus.test.tsx@@ -0,0 +1,149 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot, type Root } from 'react-dom/client'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { dispatchGlobalKeydown, type GlobalKeydownDeps, type GlobalKeyEvent } from './globalKeybindings'+import { shortcutDictationFocus } from './chatComposerDictation'++/**+ * Shortcut dictation (keyed chord, hold-to-talk) around the ⌘M chat view, against the REAL+ * elements: the composer (ChatComposer) and the plan / question answer controls+ * (ChatAnswerControls), whose "Revise…" textarea and "Other" input share the composer textarea's+ * `term-chat__input` class. A class-keyed rule offered the chord in those fields, and with no+ * composer to target the shortcut fell back to the selected terminal — the HIDDEN pane showing the+ * very plan / question dialog they answer.+ */++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++const { session } = vi.hoisted(() => ({+ session: { api: { pty: { sendText: async () => true as const } } }+}))+vi.mock('../session/session', () => ({ useSession: () => session }))++import { ChatComposer } from '../nodes/ChatComposer'+import { PlanAnswerControls, QuestionAnswerControls } from '../nodes/ChatAnswerControls'++let host: HTMLDivElement+let root: Root++beforeEach(() => {+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+})+afterEach(async () => {+ await act(async () => root.unmount())+ host.remove()+})++async function renderChatView(): Promise<void> {+ const noop = () => {}+ await act(async () => {+ root.render(+ <div className="term-chat">+ <div className="term-chat__msgs">+ <PlanAnswerControls onSubmit={async () => true} agentLabel="Claude Code" chip="⌘M" />+ <QuestionAnswerControls+ onSubmit={async () => true}+ agentLabel="Claude Code"+ chip="⌘M"+ questions={[{ question: 'Which one?', multiSelect: false, options: [{ label: 'A' }, { label: 'B' }] }]}+ />+ </div>+ <ChatComposer+ nodeId="n1"+ agentId="claude"+ agentLabel="Claude Code"+ value=""+ onChange={noop}+ onSend={noop}+ placeholder="Message"+ disabled={false}+ onWriteRefused={noop}+ />+ </div>+ )+ })+ // The plan's feedback textarea exists only after "Revise…".+ const revise = [...host.querySelectorAll('button')].find((b) => b.textContent === 'Revise…')!+ await act(async () => revise.click())+}++const reviseTextarea = () => host.querySelector('.term-chat__answer-revise textarea') as HTMLTextAreaElement+const otherInput = () => host.querySelector('input.term-chat__answer-text') as HTMLInputElement+const composerTextarea = () => host.querySelector('.term-chat__compose textarea') as HTMLTextAreaElement++const ev = (): GlobalKeyEvent => ({+ metaKey: true, ctrlKey: false, shiftKey: true, altKey: false, key: 'd',+ defaultPrevented: false,+ preventDefault() { this.defaultPrevented = true }+})+const no = () => false+function deps(active: Element, keyedDictation: GlobalKeydownDeps['gestures']['keyedDictation']): GlobalKeydownDeps {+ return {+ activeElement: () => active,+ kanbanOpen: () => false,+ overrides: () => ({}),+ isMac: true,+ terminalFirst: () => false,+ handlers: {},+ gestures: { keyedDictation, zoom: no, projectJump: no, copy: no }+ }+}++describe('keyed dictation in the ⌘M chat view (dispatcher)', () => {+ it('is offered in the composer textarea', async () => {+ await renderChatView()+ const dictation = vi.fn(() => true)+ expect(dispatchGlobalKeydown(ev(), deps(composerTextarea(), dictation))).toBe(true)+ expect(dictation).toHaveBeenCalledTimes(1)+ })++ it('is NOT offered in the plan "Revise…" textarea or the question "Other" input (same class, outside the composer)', async () => {+ await renderChatView()+ expect(reviseTextarea().classList.contains('term-chat__input')).toBe(true)+ expect(otherInput().classList.contains('term-chat__input')).toBe(true)+ const dictation = vi.fn(() => true)+ expect(dispatchGlobalKeydown(ev(), deps(reviseTextarea(), dictation))).toBe(false)+ expect(dispatchGlobalKeydown(ev(), deps(otherInput(), dictation))).toBe(false)+ expect(dictation).not.toHaveBeenCalled()+ })+})++describe('shortcutDictationFocus (both shortcut paths decide with it)', () => {+ it('fills the composer when the caret is in it', async () => {+ await renderChatView()+ expect(shortcutDictationFocus(composerTextarea())).toBe('composer')+ })++ it('REFUSES anywhere else in a chat view: answer fields, answer buttons', async () => {+ await renderChatView()+ expect(shortcutDictationFocus(reviseTextarea())).toBe('refuse')+ expect(shortcutDictationFocus(otherInput())).toBe('refuse')+ expect(shortcutDictationFocus(host.querySelector('.term-chat__answer-btn'))).toBe('refuse')+ })++ it('leaves everything outside a chat view to the ordinary rule', () => {+ const el = document.createElement('input')+ document.body.append(el)+ expect(shortcutDictationFocus(el)).toBe('default')+ expect(shortcutDictationFocus(null)).toBe('default')+ el.remove()+ })++ it('Canvas asks it on BOTH paths before any target is chosen (source pin)', () => {+ const src = readFileSync(resolve(__dirname, '../canvas/Canvas.tsx'), 'utf8').replace(/\r\n/g, '\n')+ const toggle = src.slice(src.indexOf('const toggleDictation = useCallback'))+ const refuseKeyed = toggle.indexOf("shortcutDictationFocus(document.activeElement) === 'refuse'")+ expect(refuseKeyed).toBeGreaterThan(-1)+ expect(refuseKeyed).toBeLessThan(toggle.indexOf('setDictationTarget('))+ // Hold-to-talk: refused BEFORE it arms, so the chord never opens the overlay there.+ const hold = src.slice(src.indexOf('if (!chordHeld(e, combo, isMac)) return'))+ const refuseHold = hold.indexOf("shortcutDictationFocus(document.activeElement) === 'refuse'")+ expect(refuseHold).toBeGreaterThan(-1)+ expect(refuseHold).toBeLessThan(hold.indexOf('armed = true'))+ })+})diff --git a/src/renderer/lib/globalKeybindings.test.ts b/src/renderer/lib/globalKeybindings.test.tsindex 90acebf44..3079e50d3 100644--- a/src/renderer/lib/globalKeybindings.test.ts+++ b/src/renderer/lib/globalKeybindings.test.ts@@ -1,7 +1,7 @@import { describe, it, expect, vi } from 'vitest'import type { CommandId } from '@shared/keybindings'import { dispatchGlobalKeydown, type GlobalKeydownDeps, type GlobalKeyEvent } from './globalKeybindings'-import { CHAT_COMPOSER_INPUT_CLASS, XTERM_INPUT_CLASS, type ContextElement } from './keyContext'+import { XTERM_INPUT_CLASS, type ContextElement } from './keyContext'const ev = (over: Partial<GlobalKeyEvent>): GlobalKeyEvent => ({metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, key: '',@@ -65,24 +65,6 @@ describe('dispatchGlobalKeydown', () => {dispatchGlobalKeydown(ev({ metaKey: true, key: 't' }), terminal)expect(dictation).toHaveBeenCalledTimes(1)})- it('keyed dictation IS offered in the ⌘M chat composer (the one text field it fills), and nowhere else that types', () => {- const dictation = vi.fn((e: GlobalKeyEvent) => { e.preventDefault(); return true })- const g = { keyedDictation: dictation, zoom: noGesture, projectJump: noGesture, copy: noGesture }- const composer = deps({- gestures: g,- activeElement: () => ({ tagName: 'TEXTAREA', classList: { contains: (n: string) => n === CHAT_COMPOSER_INPUT_CLASS } })- })- expect(dispatchGlobalKeydown(ev({ metaKey: true, key: 'd', shiftKey: true }), composer)).toBe(true)- const otherTextarea = deps({ gestures: g, activeElement: () => ({ tagName: 'TEXTAREA', classList: { contains: () => false } }) })- expect(dispatchGlobalKeydown(ev({ metaKey: true, key: 'd', shiftKey: true }), otherTextarea)).toBe(false)- const onBoard = deps({- gestures: g,- kanbanOpen: () => true,- activeElement: () => ({ tagName: 'TEXTAREA', classList: { contains: (n: string) => n === CHAT_COMPOSER_INPUT_CLASS } })- })- expect(dispatchGlobalKeydown(ev({ metaKey: true, key: 'd', shiftKey: true }), onBoard)).toBe(false)- expect(dictation).toHaveBeenCalledTimes(1)- })it('typing blocks canvas AND app commands (the announced D-typing guard fix)', () => {const palette = vi.fn(() => true)const undo = vi.fn(() => true)diff --git a/src/renderer/lib/keyContext.ts b/src/renderer/lib/keyContext.tsindex 1e014f50e..9cda9779a 100644--- a/src/renderer/lib/keyContext.ts+++ b/src/renderer/lib/keyContext.ts@@ -24,15 +24,21 @@ export interface ContextElement {tagName: stringisContentEditable?: booleanclassList?: { contains(name: string): boolean }+ /** DOM ancestry, when the element has it (a real Element does); absent = no ancestry answer. */+ closest?(selector: string): unknown}-/** The ⌘M chat composer's textarea (nodes/ChatComposer.tsx). A TYPING target like any other, with- * one exception the dispatcher makes: keyed dictation is allowed there, because the composer is- * the one text field dictation can fill (lib/chatComposerDictation.ts). */-export const CHAT_COMPOSER_INPUT_CLASS = 'term-chat__input'+/** The ⌘M chat composer's box (nodes/ChatComposer.tsx carries this attribute). Matched+ * STRUCTURALLY, never by the textarea's class: `term-chat__input` is shared with the plan+ * "Revise…" textarea and the question "Other" input (ChatAnswerControls), which sit OUTSIDE the+ * box — and dictation fired there typed into the hidden pane showing that very dialog. */+export const CHAT_COMPOSER_BOX_SELECTOR = '[data-chat-composer-id]'+/** Focus inside the ⌘M composer box: a TYPING target like any other, with one exception the+ * dispatcher makes — keyed dictation is allowed there, because the composer is the one text+ * field dictation fills (lib/chatComposerDictation.ts). */export function isChatComposerTarget(el: ContextElement | null): boolean {- return el?.classList?.contains(CHAT_COMPOSER_INPUT_CLASS) === true+ return !!el?.closest?.(CHAT_COMPOSER_BOX_SELECTOR)}export function isTerminalTarget(el: ContextElement | null): boolean {