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(md-view): review round 1 — desktop repeat parity, dispatch-owner doc, focus test
review363d6f91640e
diff --git a/CLAUDE.md b/CLAUDE.mdindex d570a2812..015ec6a3f 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4140,11 +4140,17 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meainstead of watching it vanish on the next launch. The write path is raw and the gates read thesanitized map, so a dropped hand-edit is invisible in the UI but still on disk until a UI writeor Reset replaces the map.-- **Dispatch has exactly two owners.** The renderer's is ONE window `keydown` listener in- `Canvas.tsx`, on the **bubble** phase — the Settings recorder's `stopPropagation` on an armed+- **Dispatch has exactly two owners per shell.** The renderer's is ONE window `keydown` listener+ in `Canvas.tsx`, on the **bubble** phase — the Settings recorder's `stopPropagation` on an armedcapture depends on that, and moving it to capture would let a recorded chord fire the command it- is being bound to. The main process's is `src/main/keydown-intercept.ts`, a **closed allowlist**- of chords it must steal back from the application menu before the page ever sees them.+ is being bound to. On the desktop the other is `src/main/keydown-intercept.ts`, a **closed+ allowlist** of chords it must steal back from the application menu before the page ever sees+ them. The **Server Edition** has no main process, so for `node.toggleMarkdown` ONLY the bridge's+ `renderer/bridge/markdown-toggle-key.ts` stands in for that intercept — still one owner per+ shell, never both — and it runs on the bubble phase for the same recorder reason. **The Canvas+ dispatcher must never gain a `node.toggleMarkdown` handler**: in the browser it would toggle+ every hovered node twice, and on the desktop it would duplicate main's forward. (`node.close`+ has no browser owner at all: the browser keeps ⌘W.)- **Invariants**- **Never read `settings.speech.shortcut`.** The dictation chord is `dictationBinding()` (thefirst effective `speech.dictation` binding); the legacy field is a **downgrade mirror only**,@@ -4193,7 +4199,8 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meaowner is a WINDOW keydown listener in the bridge (`bridge/markdown-toggle-key.ts`, below), whichxterm would otherwise starve by writing `\r` and cancelling the event. It changes nothing on thedesktop — under app-first main claims the chord above the page, under terminal-first the- resolver already refuses it, and main has no terminal-focus stand-down for it. One predicate, two main-process consumers are pinned in `keydown-intercept.test.ts`+ resolver already refuses it, and main has no terminal-focus stand-down for it. One predicate,+ two main-process consumers are pinned in `keydown-intercept.test.ts`(including a source-level wiring pin, since the menu leg lives against a real Menu in index.ts),and `keybindingOverrides.test.ts` pins the renderer-to-xterm hand-off through`terminalKeyAction`.@@ -4203,8 +4210,11 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meanothing there. It mirrors the intercept — effective `node.toggleMarkdown` bindings read perkeystroke, `policyStandsDown` (now in `shared/keybindings.ts`, re-exported by`keydown-intercept.ts`, so both shells run ONE predicate) with focus read from the DOM via- `isTerminalTarget` — plus two refusals: auto-repeat is swallowed without re-toggling, and a- `defaultPrevented` event is left alone. Bubble phase for the recorder's sake, installed only+ `isTerminalTarget` — plus a `defaultPrevented` event is left alone. **A held-key auto-repeat+ is claimed but never re-toggles, in BOTH shells**: the browser listener preventDefaults it and+ forwards nothing, and `keydownIntercept` answers `{action: null}` for a repeated toggle-markdown+ chord (still swallowed, so the repeat cannot fall through to the menu's Minimize) — the same+ shape as the held ⌘0. Bubble phase for the recorder's sake, installed onlywhile subscribed. It cannot double-fire on desktop (only `buildStubApi` reaches it; the relaytab takes `onMarkdownToggle` from the local preload). macOS Chrome reserves ⌘M for minimize,so the default chord only reaches a Mac browser tab after a remap (docs/SERVER.md).diff --git a/src/main/keydown-intercept.test.ts b/src/main/keydown-intercept.test.tsindex 0f6778cfa..8b964252b 100644--- a/src/main/keydown-intercept.test.ts+++ b/src/main/keydown-intercept.test.ts@@ -218,11 +218,21 @@ describe('⌘M → markdown view, stolen back from Window ▸ Minimize', () => {expect(press({ control: true, key: 'm', code: 'KeyM' })).toEqual(UNTOUCHED)})- it('repeats keep toggling (no auto-repeat rule here, unlike ⌘0)', () => {+ // A held chord used to forward a toggle on every OS repeat, strobing the view; the Server+ // Edition's browser listener never did. Both shells now agree: the repeat is still CLAIMED (so+ // it cannot fall through to Window ▸ Minimize, whose accelerator this is) but forwards nothing —+ // the held-⌘0 shape.+ it('drops OS auto-repeat while still swallowing the key', () => {expect(press({ meta: true, key: 'm', code: 'KeyM', isAutoRepeat: true })).toEqual({prevented: true,- sent: [IPC.appToggleMarkdown]+ sent: []})+ expect(+ press({ control: true, key: 'm', code: 'KeyM', isAutoRepeat: true }, { isMac: false })+ ).toEqual({ prevented: true, sent: [] })+ expect(+ keydownIntercept(input({ meta: true, key: 'm', code: 'KeyM', isAutoRepeat: true }), DEFAULTS, true)+ ).toEqual({ action: null })})})diff --git a/src/main/keydown-intercept.ts b/src/main/keydown-intercept.tsindex 249c55a9e..910f9d538 100644--- a/src/main/keydown-intercept.ts+++ b/src/main/keydown-intercept.ts@@ -151,7 +151,11 @@ export function keydownIntercept(// stays cheap on main's input path.const ev = toShortcutEvent(input)if (bindings.toggleMarkdown.some((s) => matchesShortcut(ev, s, isMac))) {- return { action: 'toggle-markdown' }+ // A held chord is still CLAIMED (the menu's Minimize owns this accelerator, so letting a+ // repeat through would minimize the window mid-hold) but forwards nothing: one press, one+ // toggle — the rule the Server Edition's browser listener (`markdown-toggle-key.ts`) applies+ // too, and the same shape as the held ⌘0 below.+ return { action: input.isAutoRepeat ? null : 'toggle-markdown' }}// Repurpose Cmd/Ctrl+W: the renderer closes the selected node(s); if none are selected it asks// us to close the window (the standard behavior). ⇧ is left to the menu's Close All Windows —diff --git a/src/renderer/bridge/markdown-toggle-key.ts b/src/renderer/bridge/markdown-toggle-key.tsindex 44bf51918..1de687052 100644--- a/src/renderer/bridge/markdown-toggle-key.ts+++ b/src/renderer/bridge/markdown-toggle-key.ts@@ -15,15 +15,17 @@// surface but takes `onMarkdownToggle` from the LOCAL preload (`...local`), and the lazy install// means merely building the stub registers nothing.//-// Semantics mirror the desktop intercept, with three deliberate additions:+// Semantics mirror the desktop intercept:// - **terminal-first** stands it down while a terminal has focus (`policyStandsDown`, the SAME// predicate main uses). Focus comes from the DOM exactly as the renderer's dispatcher decides// it (`isTerminalTarget` — xterm's helper textarea), not from a mirror: there is nothing to// mirror to in a browser, and the live answer is the only honest one.// - **auto-repeat is swallowed, never re-toggled**: a held chord would otherwise strobe the view.-// Still `preventDefault`ed so the held key keeps being ours (the ⌘0 intercept's shape).-// - An event a child handler already claimed (`defaultPrevented`) is left alone, the same first-// rule `dispatchGlobalKeydown` applies.+// Still `preventDefault`ed so the held key keeps being ours — exactly what `keydownIntercept`+// does for a repeated toggle-markdown chord on the desktop (the held-⌘0 shape).+// - One addition with no desktop counterpart: an event a child handler already claimed+// (`defaultPrevented`) is left alone, the same first rule `dispatchGlobalKeydown` applies (main+// sees the key before any page handler, so it has nothing to defer to).//// Bubble phase on purpose, like the window dispatcher: the Settings shortcut recorder's// `stopPropagation` on an armed capture is what keeps a chord being RECORDED from firing thediff --git a/src/renderer/bridge/stubs.dom.test.ts b/src/renderer/bridge/stubs.dom.test.tsindex f243c648e..549dfd453 100644--- a/src/renderer/bridge/stubs.dom.test.ts+++ b/src/renderer/bridge/stubs.dom.test.ts@@ -44,3 +44,38 @@ describe('bridge onMarkdownToggle (browser)', () => {un()})})++describe('bridge onMarkdownToggle (browser) — terminal-first', () => {+ it('stands down for a focused xterm textarea, read live from document.activeElement', () => {+ useSettings.setState({+ settings: { ...DEFAULT_SETTINGS, terminalShortcutPolicy: 'terminal-first' }+ })+ const ta = document.createElement('textarea')+ ta.className = 'xterm-helper-textarea'+ document.body.appendChild(ta)+ const s = buildStubApi()+ const cb = vi.fn()+ const un = s.onMarkdownToggle(cb)+ try {+ ta.focus()+ expect(document.activeElement).toBe(ta)+ // Dispatched on the focused textarea so it bubbles to window like a real keystroke.+ const e = new KeyboardEvent('keydown', {+ key: 'm',+ ctrlKey: true,+ bubbles: true,+ cancelable: true+ })+ ta.dispatchEvent(e)+ expect(cb).not.toHaveBeenCalled()+ expect(e.defaultPrevented).toBe(false) // the chord stays with the shell+ // Focus leaves the terminal: the same policy no longer stands it down.+ ta.blur()+ press({ key: 'm', ctrlKey: true })+ expect(cb).toHaveBeenCalledTimes(1)+ } finally {+ un()+ ta.remove()+ }+ })+})diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.tsindex e69aca274..818befa23 100644--- a/src/shared/keybindings.ts+++ b/src/shared/keybindings.ts@@ -534,10 +534,12 @@ export function normalizeTerminalShortcutPolicy(v: unknown): TerminalShortcutPol* **Both halves are refusals and both matter.** `app-first` is the shipped default, so it must be* false whatever the mirror reports — that is the byte-identical guarantee of this feature: a user* who never touched the setting sees exactly the pre-feature intercepts, even though their- * renderer is reporting terminal focus all day. And `terminalFocused` is a MIRROR of the- * renderer's `document.activeElement`, which is why `false` is its reset value everywhere: a page- * that died mid-report, a window that never had one, a reload — all resolve to "intercepts on",- * never to "intercepts off with nothing alive to turn them back on".+ * renderer is reporting terminal focus all day. And in MAIN, `terminalFocused` is a MIRROR of the+ * renderer's `document.activeElement`, which is why `false` is its reset value everywhere main+ * keeps it: a page that died mid-report, a window that never had one, a reload — all resolve to+ * "intercepts on", never to "intercepts off with nothing alive to turn them back on". That+ * fail-safe reasoning is about main's mirror only: the browser consumer has no mirror and passes+ * LIVE DOM focus (`isTerminalTarget(document.activeElement)`) read on the very keystroke.** Why the policy is read here rather than the intercepts simply being uninstalled under* `terminal-first`: the policy is a live setting and the focus changes per keystroke, so there is