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): remember the canvas lock across restarts, opt-in

Shogun23c16bd84654
diff --git a/CLAUDE.md b/CLAUDE.md
index 420fcd56d..ca6cc0198 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -359,7 +359,22 @@ project's nodes only.** The contract:
`liveCollapseKeys`), because settings.json is forever and a canvas churns through group ids.
- The bottom-left **canvas lock** freezes the CAMERA only (pan/zoom): nodes stay draggable,
resizable and connectable while locked — the point is "stop the map sliding", not "freeze
- the work".
+ the work". It is **transient by default and opt-in to remember**: a lock that survives a
+ restart reads as "the app is frozen" to whoever opens the app next, and the lit button is a
+ small thing to spot, so `settings.rememberCanvasLock` (Behavior, default OFF) is what turns it
+ into a preference. The bit itself lives in localStorage (`nodeterm.canvasLocked`,
+ `renderer/lib/canvasLock.ts`) beside the view mode and the explorer pin, never in settings.json
+ and never in the git-shared `project.json`: the SETTING says whether to remember, the lock is
+ one person's view state. Note the two tiers differ per surface: on Desktop both are
+ machine-local, but in the **Server Edition** the setting rides that server's settings.json
+ (shared by every browser hitting it) while the bit is per browser PROFILE, so two profiles can
+ legitimately disagree about the lock. Desktop + Server Edition; **Mobile: N/A** (no canvas).
+ It is one GLOBAL bit rather than per-project
+ because `<Canvas />` is mounted once and is not keyed by project, so the lock always carried
+ across project switches within a session. Restore is gated on settings HYDRATION (Canvas mounts
+ first, so a `useState` initializer would read the default and the opt-in would silently never
+ work) and latched to the first run, so switching the setting on mid-session never reaches into
+ storage and locks a canvas somebody is working on.
- Before any project switch / add / delete, `commitActiveToStore()` serializes the live
React Flow nodes back into the store, so nothing is lost. Then disk is written.
- Switching away unmounts the old project's `TerminalNode`s → their tmux clients detach but
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0323b48ae..621089898 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -363,6 +363,15 @@ yourself and apply it with `setViewport` (`renderer/lib/nodeFocus.ts`, `canvas/f
lands now and against the canvas you meant. `fitAll` is the one deliberate exception: an explicit
user gesture on a settled canvas.
+**A setting read at mount reads the DEFAULT, not the user's.** `useSettings` starts on
+`DEFAULT_SETTINGS` and hydrates from disk asynchronously, while `<Canvas />` is mounted before that
+lands. A `useState(() => settings.foo ? ...)` initializer therefore reads the shipped default and
+never looks again, so an opt-in feature ships inert with a green suite and no error anywhere. Gate
+on `hydrated` (the first-launch consent dialog and `settings.rememberCanvasLock` are the worked
+examples). If the same effect also WRITES, latch its first run: otherwise switching the setting on
+mid-session applies stored state to whatever the user is doing right then, which is a different
+feature from the one they asked for.
+
## Testing
`npm test` must pass, and `npm run typecheck` is the fastest gate.
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index ca4761b7d..f75092c99 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -172,6 +172,7 @@ import { containerOrigin, snapPointInRootSpace } from '../lib/gridSnap'
import { zoomFromPct } from '../lib/zoomPresets'
import { CANVAS_MAX_ZOOM, CANVAS_MIN_ZOOM } from './zoom-limits'
import { isSpaceRelease, spacePanKeydown } from '../lib/spacePan'
+import { readCanvasLocked, writeCanvasLocked } from '../lib/canvasLock'
import {
FLOW_NODE_CLASS,
isFocusTarget,
@@ -946,11 +947,16 @@ export function Canvas() {
return () => clearTimeout(t)
}, [notice])
const [zoomPct, setZoomPct] = useState(100)
- // Canvas lock (bottom-left Controls): freezes the viewport against GESTURES — pan (drag +
- // scroll), zoom (pinch / Cmd+wheel / double-click), node dragging and edge connecting.
+ // Canvas lock (bottom-left Controls): freezes the CAMERA against gestures, namely pan (drag +
+ // scroll) and zoom (pinch / Cmd+wheel / double-click). Nodes stay draggable and connectable:
+ // the point is "stop the map sliding", not "freeze the work". One camera move still gets
+ // through, because `autoPanOnNodeDrag` / `autoPanOnConnect` are never passed and so keep React
+ // Flow's `true` default: dragging a node or a connection to the viewport edge scrolls the
+ // canvas after it.
// Deliberate button clicks (Controls +/−/fit, dock zoom, ⌘K fit) still work, matching React
- // Flow's own lock convention. Transient by design: a lock that survives restart reads as
- // "the app is frozen" to whoever opens it next.
+ // Flow's own lock convention. Transient unless `settings.rememberCanvasLock` says otherwise: a
+ // lock that survives restart reads as "the app is frozen" to whoever opens it next, so it stays
+ // opt-in, and an untouched install opens unlocked exactly as it always has.
const [canvasLocked, setCanvasLocked] = useState(false)
/** SPACE is held: a left-drag pans instead of box-selecting, Figma-style (issue #86). */
const [spacePan, setSpacePan] = useState(false)
@@ -12115,6 +12121,29 @@ export function Canvas() {
setConsentOpen(true)
}, [settingsHydrated, seenOnboarding])
+ // The canvas lock, when the user has asked us to remember it (`rememberCanvasLock`, default
+ // off). Gated on hydration for the same reason as the consent dialog above: the store starts on
+ // DEFAULT_SETTINGS and <Canvas /> mounts before settings load, so a `useState` initializer would
+ // read the default (off) and never look again.
+ //
+ // One effect, two jobs, and the order is what makes it safe. The FIRST run after hydration
+ // restores, and latches, so a lock only ever comes back at launch: flipping the setting on
+ // mid-session must not reach into storage and lock a canvas the user is working on. Every run
+ // after that persists, which covers both the button and the setting being switched on later
+ // (from where the canvas is now). While the setting is off nothing is written, so a user who
+ // never opts in leaves no trace of a lock to be restored the day they do.
+ const rememberCanvasLock = useSettings((s) => s.settings.rememberCanvasLock)
+ const canvasLockRestored = useRef(false)
+ useEffect(() => {
+ if (!settingsHydrated) return
+ if (!canvasLockRestored.current) {
+ canvasLockRestored.current = true
+ if (rememberCanvasLock) setCanvasLocked(readCanvasLocked())
+ return
+ }
+ if (rememberCanvasLock) writeCanvasLocked(canvasLocked)
+ }, [settingsHydrated, rememberCanvasLock, canvasLocked])
+
// Load saved SSH servers once so the RemotePicker / palette have them available.
useEffect(() => {
void useSshServers.getState().hydrate()
diff --git a/src/renderer/canvas/canvas-wiring.test.tsx b/src/renderer/canvas/canvas-wiring.test.tsx
index dad80a0d5..527a280bd 100644
--- a/src/renderer/canvas/canvas-wiring.test.tsx
+++ b/src/renderer/canvas/canvas-wiring.test.tsx
@@ -484,3 +484,46 @@ describe('navigating from the sidebar dismisses the start screen', () => {
)
})
})
+
+describe('the canvas lock is remembered only when the user opted in', () => {
+ // The whole feature is three lines inside a 13k-line file, and every one of them can be deleted
+ // without reddening a test: the helper's own suite passes whether or not Canvas ever calls it.
+ // Same reasoning as the frameNode pin above.
+ const effect = CANVAS_SRC.slice(
+ CANVAS_SRC.indexOf('const rememberCanvasLock = useSettings('),
+ CANVAS_SRC.indexOf('// Load saved SSH servers once')
+ )
+
+ it('starts unlocked, so an install that never opts in is unchanged', () => {
+ expect(CANVAS_SRC).toContain('const [canvasLocked, setCanvasLocked] = useState(false)')
+ })
+
+ it('restores and persists behind settings.rememberCanvasLock', () => {
+ expect(effect).toContain('useSettings((s) => s.settings.rememberCanvasLock)')
+ expect(effect).toContain('if (rememberCanvasLock) setCanvasLocked(readCanvasLocked())')
+ expect(effect).toContain('if (rememberCanvasLock) writeCanvasLocked(canvasLocked)')
+ // The deps are the one line here that a deletion leaves green: without `canvasLocked` the
+ // effect stops re-running on a toggle, so only a settings flip would ever write and a lock
+ // engaged with the BUTTON would never survive a restart. There is no ESLint in this repo, so
+ // exhaustive-deps cannot catch it either.
+ expect(effect).toContain('}, [settingsHydrated, rememberCanvasLock, canvasLocked])')
+ })
+
+ it('waits for settings to hydrate before deciding either way', () => {
+ // Canvas mounts before settings load, so an ungated read sees DEFAULT_SETTINGS (off) and the
+ // opt-in silently never takes effect.
+ expect(effect).toContain('if (!settingsHydrated) return')
+ expect(indexOfPresent(effect, 'if (!settingsHydrated) return')).toBeLessThan(
+ indexOfPresent(effect, 'canvasLockRestored.current = true')
+ )
+ })
+
+ it('restores only on the first run after hydration, never on a later opt-in', () => {
+ // Flipping the setting on mid-session must not reach into storage and lock a canvas somebody
+ // is working on: the latch is what keeps a restore a launch-time event.
+ expect(indexOfPresent(effect, 'canvasLockRestored.current = true')).toBeLessThan(
+ indexOfPresent(effect, 'if (rememberCanvasLock) setCanvasLocked(readCanvasLocked())')
+ )
+ expect(effect).toContain('if (!canvasLockRestored.current) {')
+ })
+})
diff --git a/src/renderer/components/settings/sections/BehaviorSection.tsx b/src/renderer/components/settings/sections/BehaviorSection.tsx
index 026b9c5a5..88de51467 100644
--- a/src/renderer/components/settings/sections/BehaviorSection.tsx
+++ b/src/renderer/components/settings/sections/BehaviorSection.tsx
@@ -40,6 +40,10 @@ const ROWS = {
title: 'Zoom when going to a node',
keywords: ['zoom', 'focus', 'go to', 'node', 'jump', 'camera', 'session', 'sidebar']
},
+ rememberLock: {
+ title: 'Remember the canvas lock',
+ keywords: ['lock', 'canvas', 'view', 'pan', 'zoom', 'freeze', 'remember', 'restart', 'persist']
+ },
mdPreview: {
title: 'Open Markdown in preview',
keywords: ['markdown', 'md', 'preview', 'render', 'editor', 'docs', 'readme', 'file']
@@ -233,6 +237,19 @@ export function BehaviorSection({ isActive }: { isActive: boolean }): React.JSX.
}
/>
</SearchableRow>
+ <SearchableRow {...ROWS.rememberLock}>
+ <FieldRow
+ label="Remember the canvas lock"
+ description="The bottom-left lock stays on across restarts until you turn it off. Off: every launch starts unlocked."
+ control={
+ <Switch
+ checked={settings.rememberCanvasLock}
+ onChange={(v) => update({ rememberCanvasLock: v })}
+ ariaLabel="Remember the canvas lock"
+ />
+ }
+ />
+ </SearchableRow>
<SearchableRow {...ROWS.mdPreview}>
<FieldRow
label="Open Markdown in preview"
diff --git a/src/renderer/lib/canvasLock.test.ts b/src/renderer/lib/canvasLock.test.ts
new file mode 100644
index 000000000..01aa932e0
--- /dev/null
+++ b/src/renderer/lib/canvasLock.test.ts
@@ -0,0 +1,80 @@
+import { afterEach, describe, expect, it } from 'vitest'
+import {
+ CANVAS_LOCK_KEY,
+ parseCanvasLocked,
+ readCanvasLocked,
+ writeCanvasLocked
+} from './canvasLock'
+
+const real = Object.getOwnPropertyDescriptor(globalThis, 'localStorage')
+
+function installStorage(impl: Partial<Storage>): void {
+ Object.defineProperty(globalThis, 'localStorage', { value: impl, configurable: true })
+}
+
+function memoryStorage(seed: Record<string, string> = {}): { store: Record<string, string> } {
+ const store = { ...seed }
+ installStorage({
+ getItem: (k: string) => store[k] ?? null,
+ setItem: (k: string, v: string) => {
+ store[k] = v
+ }
+ } as Partial<Storage>)
+ return { store }
+}
+
+afterEach(() => {
+ if (real) Object.defineProperty(globalThis, 'localStorage', real)
+ else delete (globalThis as { localStorage?: unknown }).localStorage
+})
+
+describe('parseCanvasLocked', () => {
+ it('is off unless the flag is exactly 1', () => {
+ expect(parseCanvasLocked(null)).toBe(false)
+ expect(parseCanvasLocked('')).toBe(false)
+ expect(parseCanvasLocked('0')).toBe(false)
+ expect(parseCanvasLocked('true')).toBe(false)
+ expect(parseCanvasLocked('1')).toBe(true)
+ })
+})
+
+describe('readCanvasLocked / writeCanvasLocked', () => {
+ it('round-trips the lock through the namespaced key', () => {
+ const { store } = memoryStorage()
+ expect(readCanvasLocked()).toBe(false)
+
+ writeCanvasLocked(true)
+ expect(store[CANVAS_LOCK_KEY]).toBe('1')
+ expect(readCanvasLocked()).toBe(true)
+
+ // Unlocking must persist too, or a lock could never be cleared for the next launch.
+ writeCanvasLocked(false)
+ expect(store[CANVAS_LOCK_KEY]).toBe('0')
+ expect(readCanvasLocked()).toBe(false)
+ })
+
+ it('restores a lock written by a previous launch', () => {
+ memoryStorage({ [CANVAS_LOCK_KEY]: '1' })
+ expect(readCanvasLocked()).toBe(true)
+ })
+
+ it('reads unlocked when storage throws, and a failed write never throws', () => {
+ installStorage({
+ getItem: () => {
+ throw new Error('private mode')
+ },
+ setItem: () => {
+ throw new Error('quota')
+ }
+ } as Partial<Storage>)
+
+ expect(readCanvasLocked()).toBe(false)
+ expect(() => writeCanvasLocked(true)).not.toThrow()
+ })
+
+ it('reads unlocked when localStorage exists but has no methods (Node global, #412)', () => {
+ installStorage({} as Partial<Storage>)
+ expect(readCanvasLocked()).toBe(false)
+ expect(() => writeCanvasLocked(true)).not.toThrow()
+ })
+})
diff --git a/src/renderer/lib/canvasLock.ts b/src/renderer/lib/canvasLock.ts
new file mode 100644
index 000000000..6af7d71c4
--- /dev/null
+++ b/src/renderer/lib/canvasLock.ts
@@ -0,0 +1,37 @@
+import { readLocal, writeLocal } from './localStore'
+
+// Whether the bottom-left canvas lock was left engaged. Written and read ONLY while
+// `settings.rememberCanvasLock` is on (default off): the lock is transient by design, because a
+// canvas that will not pan on the next launch reads as "the app is frozen" to whoever opens it.
+// The setting is the opt-in for people who lock deliberately; Canvas owns that gate, this leaf
+// just stores the bit.
+//
+// PERSONAL: localStorage, never settings.json and never the git-shared .nodeterm/project.json
+// (same rule as the view mode and the card comments panel). The SETTING says whether to remember;
+// the lock itself is one person's view state, not a property of the canvas everyone clones.
+// Machine-local on Desktop. In the Server Edition the renderer is shared, so the setting lives in
+// that server's settings.json while this bit is per browser PROFILE: two profiles on one machine
+// can have the setting on and still disagree about the lock, which is correct for view state.
+//
+// GLOBAL rather than per-project, because that is what the lock already did: <Canvas /> is mounted
+// once and is not keyed by project, so the flag has always carried across project switches within
+// a session. Remembering one global bit extends the status quo instead of introducing a second
+// rule; a per-project map would also owe the dead-id pruning `sidebarCollapsedItems` does.
+//
+// Default OFF, and an unreadable store reads as OFF: a lock that cannot be cleared because the
+// read failed is the bad direction, and a canvas that opens unlocked costs one click.
+
+export const CANVAS_LOCK_KEY = 'nodeterm.canvasLocked'
+
+/** `'1'` is locked; missing, `'0'`, or anything else is unlocked. */
+export function parseCanvasLocked(raw: string | null): boolean {
+ return raw === '1'
+}
+
+export function readCanvasLocked(): boolean {
+ return parseCanvasLocked(readLocal(CANVAS_LOCK_KEY))
+}
+
+export function writeCanvasLocked(locked: boolean): void {
+ writeLocal(CANVAS_LOCK_KEY, locked ? '1' : '0')
+}
diff --git a/src/renderer/state/viewMode.ts b/src/renderer/state/viewMode.ts
index 8a41a1d82..058bc5537 100644
--- a/src/renderer/state/viewMode.ts
+++ b/src/renderer/state/viewMode.ts
@@ -129,9 +129,10 @@ export function isKanbanOpen(projectId: string): boolean {
* Gated by the feature flag `omniKanbanEnabled` — when the feature is off, the view flag is
* ignored and per-project tabs remain. `globalKanban` itself is persisted in localStorage
* (`nodeterm.globalKanban`) so an explicit "open overview" survives a restart; this is
- * intentional (like `viewByProject`), not transient — a lock that survives restart would read
- * as "frozen", but a board that survives restart reads as "you left it open". If that proves
- * surprising, make this transient; the call site is this one helper.
+ * intentional (like `viewByProject`), not transient: a canvas lock that survives restart would
+ * read as "frozen" (which is why `lib/canvasLock.ts` keeps it opt-in and default off), but a
+ * board that survives restart reads as "you left it open". If that proves surprising, make this
+ * transient; the call site is this one helper.
*/
export function isGlobalKanbanOpen(): boolean {
try {
diff --git a/src/shared/types.ts b/src/shared/types.ts
index a84a89a55..fba51fc0e 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1365,6 +1365,15 @@ export interface Settings {
* costs them the sense of where they were. Either way the node is centred and kept clear of the
* floating chrome (renderer/lib/nodeFocus). */
focusZoomToNode: boolean
+ /** Whether the bottom-left canvas lock survives a restart. OFF by default, and deliberately so:
+ * the lock was transient by design, because a canvas that will not pan on the next launch reads
+ * as "the app is frozen" to whoever opens it, and the lit button is a small thing to spot. Users
+ * who lock on purpose and want it to stay locked opt in here; everyone else opens unlocked
+ * exactly as before. The lock itself is persisted in localStorage (renderer/lib/canvasLock),
+ * never in settings.json or the git-shared project.json: this flag says whether to remember,
+ * the lock is one person's view state. Machine-local on Desktop; in the Server Edition this
+ * setting is the server's while the lock is per browser profile. */
+ rememberCanvasLock: boolean
/** Open Markdown files (.md, .markdown, …) in rendered preview instead of the code editor.
* Only picks the view an editor node OPENS in — the node's Preview/Edit toggle (and the
* markdown-toggle chord) still switches either way. Default ON since the release after
@@ -1676,6 +1685,7 @@ export const DEFAULT_SETTINGS: Settings = {
panHoverDelay: 600,
doubleClickFocus: true,
focusZoomToNode: true,
+ rememberCanvasLock: false,
openMarkdownPreview: true,
openMarkdownPreviewMigrated: true,
terminalMiddleClickPaste: false,