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(settings): terminal shortcut policy control
enesa33c1071be89
diff --git a/CLAUDE.md b/CLAUDE.mdindex d5f904f67..707933322 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1623,6 +1623,22 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meawarning reads that list and cannot derive it — main is not importable from the renderer. Notewhat the pin cannot cover: a HARDCODED intercept (the `Digit0` branch) has no command id, so itswallows its chord app-wide with the recorder reporting no conflict.+ - **The terminal-first stand-down is `policyStandsDown(policy, terminalFocused)`, and both halves+ are refusals.** `settings.terminalShortcutPolicy` (`app-first` default, Settings → Keyboard+ Shortcuts, read everywhere through `normalizeTerminalShortcutPolicy` because it is+ hand-editable) never stands anything down under `app-first`, whatever the mirror reports — that+ is the byte-identical guarantee for a user who never touched it. Under `terminal-first` with a+ focused terminal, main stops claiming its chords AND disables the menu's Minimize/Close items+ (see **Window chrome**): not calling `preventDefault` alone would hand ⌘M straight to+ `{role:'minimize'}`, which is strictly worse than having no policy.+ - **`terminalFocused` is a MIRROR, and its fail-safe direction is `false` = not focused =+ intercepts ON.** `renderer/lib/terminalFocusMirror.ts` reports focus changes to main and is+ change-deduped (it never re-asserts), so a page that died mid-report, a reload, or a window that+ never had one all resolve to intercepts on — never to "off with nothing alive to turn them back+ on". Consequence: clear the bit ONLY where the renderer's DOCUMENT is ending (window `closed`,+ `render-process-gone`, main-frame navigation). Clearing it under a live page that is still+ focused on its terminal strands mirror and main out of sync with no event that can reconcile+ them, and the policy is dead until the user clicks away and back.## Canvas interaction & panels (`Canvas.tsx` is the hub)@@ -1897,12 +1913,20 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea- **Welcome** (`WelcomeScreen.tsx`): shown when no projects exist.- **Window chrome**: macOS integrated title bar (`titleBarStyle: 'hiddenInset'`); the tabbar (`TabBar.tsx`) is the drag region with the `nodeterm` logo + a rounded pill of project- tabs. Cmd+M is intercepted in `main/index.ts` `before-input-event` (else macOS minimizes)- and forwarded to the renderer via `app:toggle-markdown`; Cmd+W (`app:close-node`) and Cmd+0- (`app:zoom-actual-size`) are taken back from the same default menu the same way. We never call- `Menu.setApplicationMenu`, so Electron's DEFAULT menu is live and owns every accelerator in it —- a chord that collides with one never reaches the renderer at all- (`main/menu-accelerator-intercepts.test.ts` pins the three we steal).+ tabs. Cmd+M is intercepted in `main/keydown-intercept.ts` (`before-input-event`, installed from+ `main/index.ts` — else macOS minimizes) and forwarded to the renderer via `app:toggle-markdown`;+ Cmd+W (`app:close-node`) and Cmd+0 (`app:zoom-actual-size`) are taken back the same way. **The+ application menu is OURS**: `buildAppMenu` (`main/index.ts`) calls `Menu.setApplicationMenu` and+ re-runs on every settings change. (This bullet used to claim we never call it — false since that+ function landed; check the template, not Electron's defaults.) Menu accelerators are handled+ ABOVE the page on every platform, so a chord one of them owns never reaches the renderer at all —+ which is why those three are stolen in `before-input-event`, and why the **terminal-first+ stand-down has a menu leg**: while a terminal owns the keys under `terminal-first`,+ `syncMenuForStandDown` disables the menu's Minimize (`MENU_ITEM_ID_MINIMIZE`, every platform)+ and, on Windows/Linux, Close (`MENU_ITEM_ID_CLOSE`), because a disabled item suppresses its+ accelerator and only then do ⌘M / Ctrl+W fall through to the terminal. `keydown-intercept.test.ts`+ pins both the stolen chords and those item ids — `getMenuItemById` answers `null` for a typo and+ the fail-safe is to do nothing, which is indistinguishable from the feature working.- **Theme**: macOS dark palette as CSS tokens in `styles.css` `:root` (`--accent` = systemBlue,label/separator opacities, SF font stack). Canvas background is black with dot grid.diff --git a/src/renderer/components/settings/sections/ShortcutsSection.test.tsx b/src/renderer/components/settings/sections/ShortcutsSection.test.tsxindex e591ce07a..df0aa6160 100644--- a/src/renderer/components/settings/sections/ShortcutsSection.test.tsx+++ b/src/renderer/components/settings/sections/ShortcutsSection.test.tsx@@ -50,6 +50,12 @@ const setRecording = (): ReturnType<typeof vi.fn> =>const body = (): Element => host.querySelector<HTMLElement>('#shortcuts')!.lastElementChild!const row = (id: string): HTMLElement => host.querySelector<HTMLElement>(`[data-command="${id}"]`)!+/** The policy row's SegmentedPill, found by the `ariaLabel` it is given (it carries no command id+ * — it is a setting, not a registry command). */+const pill = (): HTMLElement | null =>+ host.querySelector<HTMLElement>('[role="radiogroup"][aria-label="While a terminal has focus"]')+const pillOption = (label: string): HTMLButtonElement =>+ [...pill()!.querySelectorAll('button')].find((b) => b.textContent === label)!const button = (id: string, label: string): HTMLButtonElement | null =>row(id).querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`)/** The recorder button carries no per-command aria-label (it is a shared component), so it is@@ -128,8 +134,10 @@ describe('ShortcutsSection rows', () => {expect([...host.querySelectorAll('[data-command]')].map((el) =>el.getAttribute('data-command'))).toEqual(['node.close'])- // Exactly the heading and the one row — no empty siblings.- expect(body().children).toHaveLength(2)+ // Exactly the policy row (its description names Close), the heading and the one command row —+ // no empty siblings.+ expect(pill()).toBeTruthy()+ expect(body().children).toHaveLength(3)expect([...body().children].every((c) => (c.textContent ?? '').trim() !== '')).toBe(true)})@@ -146,7 +154,8 @@ describe('ShortcutsSection rows', () => {it('renders every group and row unfiltered, each as its own divided block', () => {render()expect(host.querySelectorAll('h3')).toHaveLength(6)- expect(body().children).toHaveLength(6 + COMMAND_DEFINITIONS.length)+ // + 1 for the terminal-policy row, which sits above the groups as its own block.+ expect(body().children).toHaveLength(1 + 6 + COMMAND_DEFINITIONS.length)})// The dictation row must not promise a second chord: every consumer reads@@ -206,6 +215,32 @@ describe('ShortcutsSection rows', () => {})})+describe('terminal shortcut policy row', () => {+ // `app-first` is the shipped default and the byte-identical-behavior guarantee of the whole+ // policy: a user who never opens this row must see the pre-feature app.+ it('shows app-first checked by default', () => {+ render()+ expect(pillOption('App shortcuts first').getAttribute('aria-checked')).toBe('true')+ expect(pillOption('Terminal first').getAttribute('aria-checked')).toBe('false')+ })++ it('writes the setting when Terminal first is picked', () => {+ render()+ click(pillOption('Terminal first'))+ expect(useSettings.getState().settings.terminalShortcutPolicy).toBe('terminal-first')+ expect(pillOption('Terminal first').getAttribute('aria-checked')).toBe('true')+ })++ // The row is its OWN searchable unit, not part of a group Fragment: a query that matches only+ // its keywords must keep it and drop every command group, heading included.+ it('survives a query that drops every command group', () => {+ render('tui')+ expect(pill()).toBeTruthy()+ expect(host.querySelectorAll('h3')).toHaveLength(0)+ expect(host.querySelectorAll('[data-command]')).toHaveLength(0)+ })+})+describe('commitCandidate', () => {it('refuses a conflicting candidate, naming the other command, and writes nothing', () => {setKb({ 'canvas.fitAll': [] })diff --git a/src/renderer/components/settings/sections/ShortcutsSection.tsx b/src/renderer/components/settings/sections/ShortcutsSection.tsxindex 00a901c4c..537013a90 100644--- a/src/renderer/components/settings/sections/ShortcutsSection.tsx+++ b/src/renderer/components/settings/sections/ShortcutsSection.tsx@@ -28,9 +28,11 @@ import {findKeybindingConflicts,findMainInterceptShadowing,MAIN_INTERCEPTED_COMMAND_IDS,+ normalizeTerminalShortcutPolicy,type CommandDefinition,type CommandGroup,- type CommandId+ type CommandId,+ type TerminalShortcutPolicy} from '@shared/keybindings'import { formatShortcut } from '@shared/shortcut'import { isMacPlatform, keyLabel } from '@shared/platform-utils'@@ -46,6 +48,7 @@ import { SearchableRow } from '../SearchableRow'import { FieldRow } from '../FieldRow'import { ShortcutRecorderButton } from '../ShortcutRecorderButton'import { Button } from '@renderer/ui/Button'+import { SegmentedPill } from '@renderer/ui/SegmentedPill'import { useSettingsSearch } from '../context'import { matchesQuery, type SettingsSearchEntry } from '../search'@@ -60,6 +63,18 @@ const NOTES: Partial<Record<CommandId, string>> = {'terminal.copySelection': 'Applies to a selection xterm owns — a tmux drag copies through OSC 52.'}+/** The policy row is NOT a registry command, so it carries its own search entry and its own+ * `SearchableRow` — putting it inside a group Fragment would make `groupVisible` (which only+ * knows about commands) decide whether a *setting* is on screen. */+const POLICY_LABEL = 'While a terminal has focus'+const POLICY_DESCRIPTION =+ "App shortcuts first (the default): shared shortcuts like ⌘K keep working over a focused terminal, and the first time one is captured that way the terminal says so — once per chord, ever. Terminal first: every chord but the terminal's own reaches the shell or TUI, including Close (⌘W / Ctrl+W), Minimize (⌘M / Ctrl+M), actual size (⌘0) and the ⌘1–9 project jumps — the application menu's Minimize and Close entries grey out while a terminal is focused, so those chords can reach it."+const POLICY_ROW: SettingsSearchEntry = {+ title: POLICY_LABEL,+ description: POLICY_DESCRIPTION,+ keywords: ['shortcut', 'terminal', 'tui', 'shell', 'policy', 'first', 'capture', 'minimize']+}+function rowEntry(def: CommandDefinition): SettingsSearchEntry {return {title: def.title,@@ -184,6 +199,14 @@ export function ShortcutsSection({ isActive }: { isActive: boolean }): React.JSX// Any remap re-renders every row: chips, and the Add/Disable/Reset visibility, are all derived// from the override map.const overrides = useSettings((s) => s.settings.keybindings)+ // Read through the normalizer, never as the raw field: settings.json is hand-editable, so the+ // compile-time type is not a runtime guarantee and an unknown value must render as `app-first`+ // — the same degrade `terminalShortcutPolicy()` applies at dispatch, so the pill cannot show a+ // policy the dispatcher is not using.+ const policy = normalizeTerminalShortcutPolicy(+ useSettings((s) => s.settings.terminalShortcutPolicy)+ )+ const update = useSettings((s) => s.update)const query = useSettingsSearch()const [errors, setErrors] = useState<Partial<Record<CommandId, string>>>({})@@ -197,6 +220,7 @@ export function ShortcutsSection({ isActive }: { isActive: boolean }): React.JSXconst entries = useMemo(() => [+ POLICY_ROW,...groups.map(([group, defs]) => groupEntry(group, defs)),...COMMAND_DEFINITIONS.map(rowEntry)],@@ -224,6 +248,26 @@ export function ShortcutsSection({ isActive }: { isActive: boolean }): React.JSXisActive={isActive}searchEntries={entries}>+ <SearchableRow {...POLICY_ROW}>+ <div data-setting="terminal-shortcut-policy">+ <FieldRow+ label={POLICY_LABEL}+ description={POLICY_DESCRIPTION}+ control={+ <SegmentedPill<TerminalShortcutPolicy>+ value={policy}+ ariaLabel={POLICY_LABEL}+ options={[+ { value: 'app-first', label: 'App shortcuts first' },+ { value: 'terminal-first', label: 'Terminal first' }+ ]}+ onChange={(v) => update({ terminalShortcutPolicy: v })}+ />+ }+ />+ </div>+ </SearchableRow>+{groups.map(([group, defs]) => {// A group whose header AND every row are filtered out must not render at all. The shell's// body is `divide-y [&>*]:py-5`, so an empty wrapper is not invisible — it draws a padded