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(canvas): focus mode — one node fills the window, chrome yields (⌘⇧F)

enesa8e737258069
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 9b4a284c6..bc2cd655e 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -327,6 +327,8 @@ import { isHidden } from '../lib/ui-visibility'
import { boardLogEvents } from '../lib/boardLogDiff'
import { useBoardLog } from '../state/boardLog'
import { isKanbanOpen, useViewMode, viewFor } from '../state/viewMode'
+import { useFocusNode, FOCUS_SURFACE_ID } from '../state/focusNode'
+import { focusTargetId } from '../lib/focusTarget'
import {
createCanvasPublisher,
isEphemeralNodeId,
@@ -470,6 +472,7 @@ interface PendingPeerState {
*/
const WORKTREE_SSH_HINT = 'Not supported in SSH projects yet'
const WORKTREE_SSH_NOTICE = 'Worktrees are not supported in SSH projects yet.'
+const FOCUS_NO_TARGET_NOTICE = 'Select a terminal or agent node to focus.'
// The webview's file loader renders off the LOCAL disk and has no remote counterpart, so a host
// path from a remote agent could only resolve to a same-named local file — or nothing. Refuse and
@@ -1901,6 +1904,26 @@ export function Canvas() {
useEffect(() => registerWorkspaceDirty(markDirty), [markDirty])
const kanbanOpen = useViewMode((s) => !!activeProjectId && viewFor(s, activeProjectId) === 'kanban')
+ // Focus mode (issue #78): one terminal fills the window (reparented into the always-mounted
+ // focus surface below); the chrome hides behind it and reveals on pointer proximity.
+ const focusedId = useFocusNode((s) => s.focusedId)
+ useEffect(() => {
+ document.body.classList.toggle('focus-mode', !!focusedId)
+ return () => document.body.classList.remove('focus-mode')
+ }, [focusedId])
+ useEffect(() => {
+ if (!focusedId) return
+ // Proximity reveal instead of an invisible hover band: a band over the terminal's bottom
+ // edge would eat clicks on the very row a shell keeps its prompt on.
+ const onMove = (e: MouseEvent): void => {
+ document.body.classList.toggle('focus-reveal-bottom', window.innerHeight - e.clientY < 90)
+ }
+ window.addEventListener('mousemove', onMove)
+ return () => {
+ window.removeEventListener('mousemove', onMove)
+ document.body.classList.remove('focus-reveal-bottom')
+ }
+ }, [focusedId])
const projectKanban = useProjects((s) => s.projects.find((p) => p.id === s.activeProjectId)?.kanban)
// Fresh default per project — ids must not be shared across projects; NOT persisted
// until the first edit writes it (spec lazy-default rule).
@@ -5101,6 +5124,28 @@ export function Canvas() {
[fitView, setViewport, getInternalNode]
)
+ const toggleFocusMode = useCallback(() => {
+ const store = useFocusNode.getState()
+ if (store.focusedId) {
+ const id = store.focusedId
+ store.clear()
+ // Land framed on what was just being looked at — goToNode owns the measured/unmeasured
+ // doctrine, so no bare fitView here.
+ const node = nodesRef.current.find((n) => n.id === id)
+ if (node) goToNode(node)
+ return
+ }
+ // The kanban board is an opaque overlay and its card modal already IS a focused view of a
+ // session — engaging under it would just hide the canvas twice.
+ if (isKanbanOpen(useProjects.getState().activeProjectId)) return
+ const target = focusTargetId(nodesRef.current)
+ if (!target) {
+ setNotice({ kind: 'error', text: FOCUS_NO_TARGET_NOTICE })
+ return
+ }
+ store.focus(target)
+ }, [goToNode])
+
const onNodeDoubleClick = useCallback(
(_e: React.MouseEvent, node: Node) => {
if (useSettings.getState().settings.doubleClickFocus) goToNode(node)
@@ -5147,6 +5192,9 @@ export function Canvas() {
} else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'l') {
e.preventDefault()
toggleSessionsPin()
+ } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'f') {
+ e.preventDefault()
+ toggleFocusMode()
} else if ((e.metaKey || e.ctrlKey) && e.key === '/') {
e.preventDefault()
setShortcutsOpen((v) => !v)
@@ -5218,7 +5266,7 @@ export function Canvas() {
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
- }, [toggleSessionsPin, switchProject, fitAll, zoomTo100])
+ }, [toggleSessionsPin, switchProject, fitAll, zoomTo100, toggleFocusMode])
// ⌘/Ctrl+0 on the DESKTOP never reaches the keydown handler above: Electron's default View menu
// binds the accelerator to `resetZoom`, and a menu accelerator is handled before the page sees
@@ -5942,6 +5990,11 @@ export function Canvas() {
// and the batch that ENDS the gesture recomputes properly.
const glyphSettledOpaqueRef = useRef<string[]>(EMPTY_OPAQUE)
const glyphOpaqueSig = useMemo(() => {
+ // The focused node rides the set too (issue #78): it is reparented out of the viewport, so
+ // the shared layer must not consider it paintable — same commit, not one pass later, which
+ // is why it joins here rather than in a separate effect.
+ const withFocus = (ids: string[]): string[] =>
+ focusedId && !ids.includes(focusedId) ? [...ids, focusedId] : ids
if (!glyphLayerActive) {
glyphSettledOpaqueRef.current = EMPTY_OPAQUE
return primeOpaqueNodeIds(EMPTY_OPAQUE)
@@ -5950,13 +6003,13 @@ export function Canvas() {
const settled = glyphSettledOpaqueRef.current
const gesture = gestureTerminalIds(nodes)
return primeOpaqueNodeIds(
- gesture.length === 0 ? settled : [...new Set([...settled, ...gesture])]
+ withFocus(gesture.length === 0 ? settled : [...new Set([...settled, ...gesture])])
)
}
const next = opaqueNodeIds(nodes)
glyphSettledOpaqueRef.current = next
- return primeOpaqueNodeIds(next)
- }, [glyphLayerActive, nodes])
+ return primeOpaqueNodeIds(withFocus(next))
+ }, [glyphLayerActive, nodes, focusedId])
// The notification the render above could not send. It reaches the ONE case a render-time read
// cannot: a terminal whose own node object did not change (so it never re-rendered) but which
// something else slid underneath. Keyed on the signature, so it fires only on a real change.
@@ -8863,6 +8916,14 @@ export function Canvas() {
icon: <IconRemote />,
run: () => void connectRemote()
},
+ {
+ id: 'focus-node',
+ label: 'Focus node',
+ hint: 'zen fullscreen fill distraction',
+ section: 'View',
+ icon: <IconFit />,
+ run: toggleFocusMode
+ },
{ id: 'fit', label: 'Fit view', icon: <IconFit />, run: fitAll },
{ id: 'zoom-100', label: 'Zoom to 100%', icon: <IconFit />, run: zoomTo100 },
{ id: 'save', label: 'Save', icon: <IconSave />, run: () => void persist() },
@@ -8969,7 +9030,8 @@ export function Canvas() {
addSshTerminal,
hasRestartableAgents,
restartIdleAgents,
- zoomTo100
+ zoomTo100,
+ toggleFocusMode
])
// Build the palette's command list only when its inputs change — the inline `buildCommands()`
@@ -9807,6 +9869,19 @@ export function Canvas() {
onDictate={toggleDictation}
dictateActive={dictationOpen}
/>
+
+ {/* Focus mode surface (issue #78). ALWAYS mounted so the reparent target exists before the
+ commit that moves a node into it, and OUTSIDE <ReactFlow> on purpose — the flow wrapper
+ is one z-0 stacking context, so nothing inside it could ever rise above the sidebar. The
+ focused node's root is appended here imperatively by TerminalNode; the exit pill stays
+ above it. Esc is deliberately NOT an exit key — it must reach the CLI in the pane. */}
+ <div id={FOCUS_SURFACE_ID} className={`focus-surface${focusedId ? ' is-active' : ''}`}>
+ {focusedId && (
+ <button className="focus-exit" title="Exit focus (⌘⇧F)" onClick={toggleFocusMode}>
+ Exit focus
+ </button>
+ )}
+ </div>
</div>
)
}
diff --git a/src/renderer/components/ShortcutsPanel.tsx b/src/renderer/components/ShortcutsPanel.tsx
index 7c799af05..264ed1cba 100644
--- a/src/renderer/components/ShortcutsPanel.tsx
+++ b/src/renderer/components/ShortcutsPanel.tsx
@@ -45,6 +45,7 @@ function buildSections(dictationKeys: string[], dictationLabel: string): { title
{ keys: ['Left-drag'], label: 'Box-select (touch to select)' },
{ keys: ['Middle / Right-drag'], label: 'Pan the canvas' },
{ keys: ['Double-click'], label: 'Center & focus a node' },
+ { keys: ['⌘', '⇧', 'F'], label: 'Focus mode (selected node fills the window)' },
{ keys: ['⌘', 'wheel'], label: 'Zoom in / out' },
// Advertised on BOTH surfaces, unlike "Jump to project" above. ⌘1-9 is dropped there
// because the browser RESERVES it (tab switching, un-preventable) for something unrelated;
diff --git a/src/renderer/lib/focusTarget.test.ts b/src/renderer/lib/focusTarget.test.ts
new file mode 100644
index 000000000..552c0f50b
--- /dev/null
+++ b/src/renderer/lib/focusTarget.test.ts
@@ -0,0 +1,29 @@
+import { describe, it, expect } from 'vitest'
+import { focusTargetId } from './focusTarget'
+
+describe('focusTargetId', () => {
+ it('picks the selected terminal node', () => {
+ expect(
+ focusTargetId([
+ { id: 'a', type: 'sticky', selected: true },
+ { id: 'b', type: 'terminal', selected: true },
+ { id: 'c', type: 'terminal' }
+ ])
+ ).toBe('b')
+ })
+
+ it('returns null when nothing focusable is selected — never falls back to an arbitrary node', () => {
+ expect(focusTargetId([{ id: 'a', type: 'terminal' }])).toBeNull()
+ expect(focusTargetId([{ id: 'a', type: 'group', selected: true }])).toBeNull()
+ expect(focusTargetId([])).toBeNull()
+ })
+
+ it('first selected terminal wins on multi-selection', () => {
+ expect(
+ focusTargetId([
+ { id: 'x', type: 'terminal', selected: true },
+ { id: 'y', type: 'terminal', selected: true }
+ ])
+ ).toBe('x')
+ })
+})
diff --git a/src/renderer/lib/focusTarget.ts b/src/renderer/lib/focusTarget.ts
new file mode 100644
index 000000000..cad0c3593
--- /dev/null
+++ b/src/renderer/lib/focusTarget.ts
@@ -0,0 +1,9 @@
+/** Which node ⌘⇧F / the "Focus node" palette entry acts on (issue #78): the selected terminal
+ * node. Only terminals — focus mode reparents the node's xterm host, which is meaningless for
+ * stickies/groups/editors. With several selected, the first wins (a deliberate, boring rule —
+ * matching how single-node actions elsewhere resolve multi-selection). */
+export function focusTargetId(
+ nodes: readonly { id: string; type?: string; selected?: boolean }[]
+): string | null {
+ return nodes.find((n) => n.selected && n.type === 'terminal')?.id ?? null
+}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index c1059e0c3..6efc6adc7 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1,4 +1,4 @@
-import { Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import { Suspense, lazy, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { NODE_MIN_SIZES } from '../lib/nodeSizing'
import {
Handle,
@@ -22,6 +22,7 @@ import { clipboardImages, droppedPaths, pasteHasText, pastedFiles } from '../ter
import type { TerminalTransport } from '../terminal/transport'
import { guardMiddleClickPaste } from '../terminal/middle-click'
import { patchTerminalScale } from '../terminal/scale-fix'
+import { focusedNodeId, subscribeFocusedNode, focusSurfaceEl } from '../state/focusNode'
import { parseOsc52 } from '../terminal/osc52'
import { activateUnicode11 } from '../terminal/unicode-width'
import {
@@ -1087,6 +1088,46 @@ export function TerminalNode({
read()
return subscribeOpaqueSet(read)
}, [id])
+ // Focus mode (issue #78) — same render-time read + subscription shape as `glyphOpaque` above,
+ // for the same ordering reason: the `glyphOff` term computed this render must agree with the
+ // reparent this same commit performs, or the shared-glyph teardown runs a pass behind the DOM.
+ const [, bumpFocused] = useState(0)
+ const focused = focusedNodeId() === id
+ const focusedRef = useRef(focused)
+ focusedRef.current = focused
+ useEffect(() => {
+ const read = (): void => {
+ const now = focusedNodeId() === id
+ if (now === focusedRef.current) return
+ focusedRef.current = now
+ bumpFocused((n) => n + 1)
+ }
+ read()
+ return subscribeFocusedNode(read)
+ }, [id])
+ // The reparent itself: move the WHOLE node root into the focus surface, imperatively. Not a
+ // React portal — switching a portal container unmounts/remounts the subtree, which recreates
+ // the xterm host div while the lifecycle effect (keyed on respawnNonce) never re-runs; the
+ // terminal would go blank. Moving the host element is the operation park/adopt already proved
+ // safe: every listener the terminal owns is bound to `term.element` or the host, not to a
+ // position in the tree. useLayoutEffect + cleanup, so the node is back under React's recorded
+ // parent BEFORE React ever detaches it (the commit-phase removeChild would throw otherwise) —
+ // the cleanup runs on unfocus AND ahead of unmount (project switch while focused).
+ useLayoutEffect(() => {
+ if (!focused) return
+ const root = rootRef.current
+ const surface = focusSurfaceEl()
+ if (!root || !surface) return
+ const home = root.parentElement
+ surface.appendChild(root)
+ return () => {
+ try {
+ home?.appendChild(root)
+ } catch {
+ /* home unmounted with the project — React already gave up on this subtree */
+ }
+ }
+ }, [focused])
const [mdHtml, setMdHtml] = useState('')
const [editingTitle, setEditingTitle] = useState(false)
const hoveredRef = useRef(false)
@@ -1176,7 +1217,11 @@ export function TerminalNode({
// Mirrored into a ref for the lifecycle effect's closures (which cannot see fresh props), and
// read by `setupGlyph` itself — the mount-time setup runs from that effect, not from the
// participation effect below, so the gate has to live where every caller passes through it.
- const glyphOff = collapsed || mdMode || glyphOpaque || dragging
+ // `focused` is a MUST-BE-OPAQUE reason (issue #78): a focus-mode node is reparented out of the
+ // React Flow viewport, so the shared layer's glyphs — positioned from on-canvas geometry —
+ // would paint somewhere the node no longer is. Routes through the same setup/teardown the
+ // collapse/⌘M/stacking/drag reasons always used; v1 deliberately forces the DOM/WebGL path.
+ const glyphOff = collapsed || mdMode || glyphOpaque || dragging || focused
const glyphOffRef = useRef(glyphOff)
glyphOffRef.current = glyphOff
// The NOT-ON-SCREEN half on its own. `setupGlyph`'s gate needs to tell the two reasons apart:
@@ -2289,7 +2334,10 @@ export function TerminalNode({
// grant/release swaps renderers without the text visibly reflowing (see the helper).
quantizeCharSize(term)
applyFit()
- patchTerminalScale(term, getZoom)
+ // Reads the STORE, not the component's focusedRef: a parked terminal keeps the closure
+ // from the instance that created it, and a ref from a dead instance never updates — the
+ // store keyed by the stable node id is current across park/adopt (issue #78).
+ patchTerminalScale(term, () => (focusedNodeId() === id ? 1 : getZoom()))
// OSC 52 clipboard write: route the decoded text to the local clipboard. This is the PRIMARY
// copy path: tmux's mouse is ON, so a drag-select in copy-mode emits OSC 52 to us on the
// user's behalf (`set-clipboard on` + `terminal-features ",*:clipboard"`), and this handler is
@@ -4159,7 +4207,7 @@ export function TerminalNode({
isUnread ? ' unread' : ''
}${status?.state === 'working' ? ' working' : ''}${
status?.state === 'waiting' || status?.state === 'blocked' ? ' attention' : ''
- }${glyphMounted ? ' term-node--glyphgrid' : ''}`}
+ }${glyphMounted ? ' term-node--glyphgrid' : ''}${focused ? ' term-node--focused' : ''}`}
ref={rootRef}
style={{ borderTopColor: data.color }}
onMouseEnter={() => (hoveredRef.current = true)}
diff --git a/src/renderer/state/focusNode.ts b/src/renderer/state/focusNode.ts
new file mode 100644
index 000000000..56e30691a
--- /dev/null
+++ b/src/renderer/state/focusNode.ts
@@ -0,0 +1,45 @@
+import { create } from 'zustand'
+
+// Focus mode (issue #78): ONE terminal/agent node fills the window; the canvas chrome gets out
+// of the way and reappears on hover. Session-only on purpose — no localStorage: restoring into
+// focus mode after a relaunch would hide the whole canvas behind a node the user may not
+// remember focusing, and unlike the canvas/kanban choice there is no affordance that explains
+// the state on sight.
+
+interface FocusNodeState {
+ focusedId: string | null
+ focus(id: string): void
+ clear(): void
+ toggle(id: string): void
+}
+
+export const useFocusNode = create<FocusNodeState>((set) => ({
+ focusedId: null,
+ focus: (id) => set({ focusedId: id }),
+ clear: () => set({ focusedId: null }),
+ toggle: (id) => set((s) => ({ focusedId: s.focusedId === id ? null : id }))
+}))
+
+/**
+ * Imperative pair for render-time reads (the `nodeIsOpaque`/`subscribeOpaqueSet` shape from
+ * SharedGlyphLayer, for the same reason): TerminalNode must read this DURING render so the
+ * `glyphOff` term it computes agrees with the DOM it is about to commit — mirrored into state it
+ * lags by a commit, and the shared-glyph teardown then runs one pass behind the reparent.
+ */
+export function focusedNodeId(): string | null {
+ return useFocusNode.getState().focusedId
+}
+
+export function subscribeFocusedNode(cb: () => void): () => void {
+ return useFocusNode.subscribe(cb)
+}
+
+/**
+ * The element the focused node reparents into. Looked up live (never cached): the surface is a
+ * stable always-mounted child of `.canvas-root`, but Canvas can remount across project switches.
+ */
+export const FOCUS_SURFACE_ID = 'focus-surface'
+
+export function focusSurfaceEl(): HTMLElement | null {
+ return document.getElementById(FOCUS_SURFACE_ID)
+}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index ce53cbbd4..18705114b 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -10619,3 +10619,72 @@ body,
text-overflow: ellipsis;
white-space: nowrap;
}
+
+/* ================================= Focus mode (issue #78) ==================================
+ One terminal fills the window. The surface is a fixed opaque layer ABOVE the canvas (z 40 —
+ over the sidebar's 12 and the dock's 20, under menus at 46 and dialogs at 55/70), and the
+ focused `.term-node` is REPARENTED into it (TerminalNode's layout effect) — same element,
+ same xterm, no respawn. Chrome is not "hidden": it simply sits under the opaque surface, and
+ the dock is lifted above it (z 41) on pointer proximity / hover. */
+.focus-surface {
+ position: fixed;
+ inset: 0;
+ z-index: 40;
+ display: none;
+}
+.focus-surface.is-active {
+ display: block;
+ background: var(--canvas-bg);
+}
+/* The reparented node root: fill the surface edge to edge. width/height 100% still resolve
+ against the surface; the absolute inset pins it regardless of the flow-node sizing props. */
+.focus-surface .term-node {
+ position: absolute;
+ inset: 0;
+ width: auto;
+ height: auto;
+ border-radius: 0;
+}
+/* Canvas-only affordances are meaningless off-canvas: resize grips, link handles, flow ports. */
+.focus-surface .react-flow__resize-control,
+.focus-surface .bridge-handle,
+.focus-surface .react-flow__handle {
+ display: none;
+}
+.focus-exit {
+ position: absolute;
+ top: 10px;
+ right: 14px;
+ z-index: 2;
+ border: 1px solid var(--border);
+ background: rgba(var(--menu-rgb), 0.92);
+ color: var(--text);
+ border-radius: 999px;
+ font-size: 11px;
+ padding: 4px 12px;
+ cursor: pointer;
+ opacity: 0.4;
+ transition: opacity 0.16s ease-out;
+}
+.focus-exit:hover {
+ opacity: 1;
+}
+/* Dock reveal: proximity (Canvas toggles `focus-reveal-bottom` on mousemove) or direct hover
+ keeps it up once revealed. Lifted above the surface, faded via opacity only. */
+body.focus-mode .dock {
+ z-index: 41;
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 0.16s ease-out;
+}
+body.focus-mode.focus-reveal-bottom .dock,
+body.focus-mode .dock:hover {
+ opacity: 1;
+ pointer-events: auto;
+}
+@media (prefers-reduced-motion: reduce) {
+ .focus-exit,
+ body.focus-mode .dock {
+ transition: none;
+ }
+}