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.

feat(view): add snap-grid menu mode

Darren Kattan139d1eefc300
diff --git a/src/main/index.ts b/src/main/index.ts
index c7df5c303..acf200d79 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -380,31 +380,49 @@ if (process.platform !== 'win32' && typeof process.setFdLimit === 'function') {
}
/**
- * The native application menu. macOS-idiomatic: the app-name menu (About/Quit) first, then an
- * Edit menu with the standard text-editing roles (Undo/Redo/Cut/Copy/Paste/Select All — these
- * make keyboard shortcuts work in inputs and the webview), then a Window menu, with a
- * "Settings…" item (⌘,) in the app menu that opens the settings page.
+ * Build the native application menu. The View submenu is the home of the Snap-to-Grid mode
+ * toggle (with a real native checkmark — `checked` reflects `settings.autoAlignGrid`), plus Fit
+ * View and the Kanban / Canvas view toggle. Menu clicks send IPC to the renderer, which owns the
+ * canvas state.
*
- * Until now the app shipped with Electron's DEFAULT menu (which has no Settings item, and whose
- * Edit roles only covered the main webContents). The only way to reach Settings was the in-canvas
- * gear button. This adds the menu entry Mac users look for reflexively (⌘, → app menu → Settings).
- *
- * The Settings item sends `IPC.appOpenSettings` to the renderer, which opens the same settings page
- * the gear button and the Cmd+, keydown do — one IPC, the renderer owns the open/close state.
- * `before-input-event` already routes a typed ⌘, to the renderer, so this menu item is what makes
- * the MENU route (clicking the item, or focusing the menu bar and pressing ⌘,) reach the same
- * place: a menu click does NOT fire before-input-event, so without this the menu would be inert.
+ * Rebuilt on every settings change (see the `settingsStore.onChange` hook in `whenReady`) so the
+ * Snap-to-Grid checkmark and the Kanban/Canvas label stay live — the renderer is the sole settings
+ * writer, so a change persists through `settingsStore` and fires this rebuild. No reverse IPC.
*/
-function buildAppMenu(): void {
+function buildAppMenu(win: BrowserWindow): void {
const isMac = process.platform === 'darwin'
- const settingsItem = {
+ const s = settingsStore.get()
+ const send = (channel: string): void => {
+ if (!win.isDestroyed()) win.webContents.send(channel)
+ }
+ const settingsItem: Electron.MenuItemConstructorOptions = {
label: isMac ? 'Settings…' : 'Settings',
accelerator: 'CmdOrCtrl+,',
- click: () => {
- const win = getMainWindow()
- if (win && !win.isDestroyed()) win.webContents.send(IPC.appOpenSettings)
- }
+ click: () => send(IPC.appOpenSettings)
}
+ // The kanban toggle's label depends on which view is active. The renderer owns that state; main
+ // can't read it, so the label is generic and the renderer's handler decides direction. (A live
+ // label would need a reverse-IPC the renderer drives on toggle — out of scope for this change.)
+ const viewSubmenu: Electron.MenuItemConstructorOptions[] = [
+ { role: 'toggleDevTools' },
+ { type: 'separator' },
+ {
+ label: 'Snap to Grid',
+ type: 'checkbox',
+ checked: s.autoAlignGrid === true,
+ click: () => send(IPC.appToggleAutoAlign)
+ },
+ {
+ label: 'Fit View',
+ accelerator: 'CmdOrCtrl+0',
+ click: () => send(IPC.appFitView)
+ },
+ {
+ label: 'Toggle Kanban Board',
+ accelerator: 'CmdOrCtrl+Shift+B',
+ click: () => send(IPC.appToggleKanban)
+ }
+ ]
const template: Electron.MenuItemConstructorOptions[] = isMac
? [
{
@@ -437,25 +455,14 @@ function buildAppMenu(): void {
{ role: 'selectAll' }
]
},
- {
- label: 'View',
- submenu: [{ role: 'toggleDevTools' }]
- },
+ { label: 'View', submenu: viewSubmenu },
{
label: 'Window',
- submenu: [
- { role: 'minimize' },
- { role: 'zoom' },
- { type: 'separator' },
- { role: 'front' }
- ]
+ submenu: [{ role: 'minimize' }, { role: 'zoom' }, { type: 'separator' }, { role: 'front' }]
}
]
: [
- {
- label: 'File',
- submenu: [{ role: 'quit' }]
- },
+ { label: 'File', submenu: [{ role: 'quit' }] },
{
label: 'Edit',
submenu: [
@@ -469,18 +476,9 @@ function buildAppMenu(): void {
{ role: 'selectAll' }
]
},
- {
- label: 'View',
- submenu: [{ role: 'toggleDevTools' }]
- },
- {
- label: 'Settings',
- submenu: [settingsItem]
- },
- {
- label: 'Window',
- submenu: [{ role: 'minimize' }, { role: 'close' }]
- }
+ { label: 'View', submenu: viewSubmenu },
+ { label: 'Settings', submenu: [settingsItem] },
+ { label: 'Window', submenu: [{ role: 'minimize' }, { role: 'close' }] }
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}
@@ -1126,7 +1124,6 @@ app.whenReady().then(async () => {
console.error('[ssh-askpass] script generation failed, relay disabled:', e)
return undefined
})
- buildAppMenu()
const win = createWindow()
// NT_MULTI instances are throwaway dev sandboxes. The dock badge is the one marker that is
// always visible on macOS (the window title is hidden by titleBarStyle: 'hiddenInset', and the
@@ -1187,7 +1184,14 @@ app.whenReady().then(async () => {
initNotchHud({ getNodeTitle: displayTitleFor }, notchTunables())
if (win.isVisible()) startNotchHud()
else win.once('show', startNotchHud)
- settingsStore.onChange(() => applyNotchHudSettings(notchTunables()))
+ buildAppMenu(win)
+ // Rebuild the native menu on every settings change so the View → Snap to Grid checkmark (and
+ // any future live label) tracks the renderer's setting. The renderer is the sole settings
+ // writer; a change persists through `settingsStore`, which fires this hook. No reverse IPC.
+ settingsStore.onChange(() => {
+ applyNotchHudSettings(notchTunables())
+ buildAppMenu(win)
+ })
// Advertise launch settings to the mobile companion through the mirror. The provider is
// consulted at every flush (heartbeat ≤60s), so a settings change propagates without extra
// plumbing. Caps arrive async: re-flush once the memoized probe answers.
diff --git a/src/preload/index.ts b/src/preload/index.ts
index d87976a3b..0b28b46b9 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -566,6 +566,10 @@ const api: NodeTerminalApi = {
onMarkdownToggle: subscribe(IPC.appToggleMarkdown),
onCloseNode: subscribe(IPC.appCloseNode),
onZoomActualSize: subscribe(IPC.appZoomActualSize),
+ // Native View menu → renderer.
+ onToggleAutoAlign: subscribe(IPC.appToggleAutoAlign),
+ onFitView: subscribe(IPC.appFitView),
+ onToggleKanban: subscribe(IPC.appToggleKanban),
onOpenSettings: subscribe(IPC.appOpenSettings),
closeWindow: () => ipcRenderer.send(IPC.appCloseWindow),
focusWindow: () => ipcRenderer.send(IPC.appFocusWindow),
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index 84f2f6f42..416ff2ce9 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -343,6 +343,11 @@ export function buildStubApi(): Omit<
// Deliberate no-op (not a gap): a browser tab has no application menu to steal ⌘0, so the
// renderer's own keydown handler is the whole path there.
onZoomActualSize: noopUnsub,
+ // Native app-menu events (desktop-only — the Server Edition has no native menu). Stubs so the
+ // bridge satisfies NodeTerminalApi; the canvas only wires real listeners on desktop.
+ onToggleAutoAlign: noopUnsub,
+ onFitView: noopUnsub,
+ onToggleKanban: noopUnsub,
onOpenSettings: noopUnsub,
closeWindow: noop,
// Best-effort: a browser tab can't force itself frontmost the way the desktop BrowserWindow
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 52642dc2c..a2b7c1196 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -3984,16 +3984,31 @@ export function Canvas() {
})
}, [deleteNodes])
- // The native app menu's "Settings…" item (⌘,) → open settings, same as the gear button and the
- // Cmd+, keydown. Main sends IPC.appOpenSettings when the menu item is clicked (a menu click does
- // not fire before-input-event, so the typed-⌘, path alone would leave the menu item inert).
+ // Native View menu → renderer. The menu item click sends IPC; these listeners fire the canvas
+ // action. Snap-to-Grid flips the setting (the `autoAlignGrid` effect above runs the arrange on
+ // the false→true edge), and main rebuilds the menu on the settings change so the checkmark moves.
+ useEffect(() => {
+ return window.nodeTerminal.onToggleAutoAlign(() => {
+ useSettings.getState().update({ autoAlignGrid: !useSettings.getState().settings.autoAlignGrid })
+ })
+ }, [])
+ useEffect(() => {
+ return window.nodeTerminal.onFitView(() => fitAll())
+ }, [fitAll])
+ useEffect(() => {
+ return window.nodeTerminal.onToggleKanban(() => {
+ const id = useProjects.getState().activeProjectId
+ if (id) useViewMode.getState().toggle(id)
+ })
+ }, [])
+ // Native app menu → open Settings (⌘,). A menu click does not fire before-input-event, so the
+ // Cmd+, keydown handler alone would leave the menu item inert — main forwards it as IPC.
useEffect(() => {
return window.nodeTerminal.onOpenSettings(() => {
setSettingsSection(undefined)
setSettingsOpen(true)
})
}, [])
-
const groupSelection = useCallback(
(ids: string[]) => {
const groupCount = nodesRef.current.filter((n) => n.type === 'group').length
@@ -4898,6 +4913,25 @@ export function Canvas() {
[setNodes, markDirty]
)
+ // Snap-to-grid MODE (like a desktop "Auto arrange"): when `autoAlignGrid` flips ON, snap EVERY
+ // node to the grid at that moment (not just the selection — the one-shot `alignToGrid` is no
+ // longer exposed in the UI; this is its replacement). `nodesRef.current` holds only the active
+ // project's persistent nodes (subagent/loop ephemeral cards live in a separate array), so this
+ // is safe to run over the whole list. v1: arrange-all-on-enable only — it does not re-snap on
+ // later drags. Turning OFF is a no-op (nodes stay where they were snapped). The transition is
+ // tracked with a ref so a re-render that preserves the ON value doesn't re-arrange.
+ const prevAutoAlignRef = useRef(false)
+ useEffect(() => {
+ const on = settings.autoAlignGrid
+ if (on && !prevAutoAlignRef.current) {
+ const ids = nodesRef.current
+ .filter((n) => n.type !== 'subagent' && n.type !== 'loop')
+ .map((n) => n.id)
+ if (ids.length) alignToGrid(ids)
+ }
+ prevAutoAlignRef.current = on
+ }, [settings.autoAlignGrid, alignToGrid])
+
const selectAll = useCallback(() => {
setNodes((ns) => ns.map((n) => ({ ...n, selected: true })))
}, [setNodes])
@@ -5604,19 +5638,11 @@ export function Canvas() {
},
[
screenToFlowPosition,
- activeProjectId,
- addTerminal,
agentCreationItems,
- addSticky,
- addDino,
- addBrowser,
- openFileDialog,
- newProjectFile,
- openRemotePicker,
- openWorktreeDialog,
- isSshProject,
+ addHandlers,
+ addCtx,
selectAll,
- fitView,
+ fitAll,
hasRestartableAgents,
restartIdleAgents
]
diff --git a/src/renderer/components/settings/sections/BehaviorSection.tsx b/src/renderer/components/settings/sections/BehaviorSection.tsx
index 91e6a5a1e..ac69b686c 100644
--- a/src/renderer/components/settings/sections/BehaviorSection.tsx
+++ b/src/renderer/components/settings/sections/BehaviorSection.tsx
@@ -18,6 +18,10 @@ const ROWS = {
keywords: ['node', 'size', 'width', 'height', 'terminal', 'default']
},
snap: { title: 'Snap to grid', keywords: ['snap', 'grid', 'align'] },
+ autoAlign: {
+ title: 'Snap to grid mode (auto-arrange)',
+ keywords: ['snap', 'grid', 'align', 'arrange', 'auto', 'mode']
+ },
panHover: { title: 'Pan-hover delay (ms)', keywords: ['pan', 'hover', 'delay', 'focus', 'guard'] },
doubleClick: { title: 'Double-click to focus', keywords: ['double', 'click', 'focus'] },
sidebarCollapse: {
@@ -111,6 +115,19 @@ export function BehaviorSection({ isActive }: { isActive: boolean }): React.JSX.
}
/>
</SearchableRow>
+ <SearchableRow {...ROWS.autoAlign}>
+ <FieldRow
+ label="Snap to grid mode"
+ description="Arranges every node to the grid at the moment you turn it on — like a desktop “Auto arrange”. Distinct from the drag-snap toggle above, which only constrains dragging."
+ control={
+ <Switch
+ checked={settings.autoAlignGrid}
+ onChange={(v) => update({ autoAlignGrid: v })}
+ ariaLabel="Snap to grid mode"
+ />
+ }
+ />
+ </SearchableRow>
<SearchableRow {...ROWS.panHover}>
<FieldRow
label="Pan-hover delay (ms)"
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 02e5d6ccf..d82a39d8d 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -65,6 +65,12 @@ export const IPC = {
* renderer opens the settings page — same path as the in-canvas gear button / Cmd+, keydown. */
appOpenSettings: 'app:open-settings',
appFocusWindow: 'app:focus-window',
+ /** Native View menu → renderer: toggle the Snap-to-Grid arrange mode. */
+ appToggleAutoAlign: 'app:toggle-auto-align',
+ /** Native View menu → renderer: fit the canvas to its nodes. */
+ appFitView: 'app:fit-view',
+ /** Native View menu → renderer: toggle the kanban / canvas view. */
+ appToggleKanban: 'app:toggle-kanban',
/** Write text to the system clipboard from the MAIN process. Renderer-side `clipboard` access is
* deprecated in Electron; the renderer sends this instead (fire-and-forget). */
clipboardWrite: 'clipboard:write',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index eefd4bfb2..f80bcccde 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -881,7 +881,16 @@ export interface Settings {
/** Empty string = use the system default shell. */
defaultShell: string
gridSize: number
+ /** Drag-time snap: while ON, dragging a node rounds its position to the grid. A live editor in
+ * BehaviorSection; the canvas reads it for the React Flow `snapToGrid` prop. Distinct from
+ * `autoAlignGrid` (a one-shot arrange-all), which is a mode, not a drag constraint. */
snapToGrid: boolean
+ /** Snap-to-grid MODE (like a desktop "Auto arrange"): while ON, every node is snapped to the
+ * grid at the moment the mode is turned on (the existing one-shot `alignToGrid` run over all
+ * node ids). Toggled from the native View menu (with a checkmark) and Settings → Behavior.
+ * Distinct from `snapToGrid` (drag-time snap) — turning this on arranges once; it does not
+ * constrain future drags. v1: arrange-all-on-enable only. */
+ autoAlignGrid: boolean
/** Default size (px) for NEW terminal/agent nodes on the canvas. Existing nodes keep
* whatever size they were saved with; other node kinds keep their own defaults. */
defaultNodeWidth: number
@@ -1113,6 +1122,7 @@ export const DEFAULT_SETTINGS: Settings = {
defaultShell: '',
gridSize: 24,
snapToGrid: false,
+ autoAlignGrid: false,
defaultNodeWidth: 640,
defaultNodeHeight: 440,
sidebarAutoCollapse: true,
@@ -2311,6 +2321,12 @@ export interface NodeTerminalApi {
* key is intercepted in main because Electron's default View menu owns the accelerator. In the
* Server Edition the renderer's own keydown handler sees the key and this is a no-op stub. */
onZoomActualSize(listener: () => void): () => void
+ /** Native View menu → Snap to Grid toggle. Returns unsubscribe. */
+ onToggleAutoAlign(listener: () => void): () => void
+ /** Native View menu → Fit View. Returns unsubscribe. */
+ onFitView(listener: () => void): () => void
+ /** Native View menu → Toggle Kanban / Canvas view. Returns unsubscribe. */
+ onToggleKanban(listener: () => void): () => void
/** Fires when the native app menu's "Settings…" item (⌘,) is clicked. Returns unsubscribe. */
onOpenSettings(listener: () => void): () => void
/** Close the application window (Cmd/Ctrl+W fallback when no node is selected). */