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): update a saved layout to the arrangement on screen

Bas Milius55181cc8a252
diff --git a/CLAUDE.md b/CLAUDE.md
index 108b78a97..72fa9fcba 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2933,6 +2933,20 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
worst a bad layout can do is move things, which ⌘Z takes back (the debounced history effect
picks up the `setNodes` like any other placement, which is why restore has no confirm and
delete does).
+ - **The two DESTRUCTIVE row actions confirm; restore does not, and the split is the undo stack.**
+ ⌘Z replays node arrays, and a layout lives beside them rather than in them, so delete and
+ "update to the arrangement on screen" are both unrecoverable the moment they run while a restore
+ is one undo away. Update exists because the three-step alternative already worked (save, retype
+ the name you are looking at, confirm the replace) and re-typing a name is friction, not a
+ decision; it reuses `saveLayout`'s replace-by-id path, so `createdAt` survives, `updatedAt`
+ moves, and the window size and camera are re-captured because you are updating FROM this screen.
+ Both dialogs are built from `layoutIsShared` + `deleteLayoutMessage`/`updateLayoutMessage`
+ (`canvasLayoutView.ts`), ONE definition of who else a destructive edit reaches: a folder project
+ and an SSH project both keep their `project.json` where other people read it, and only a
+ cwd-less canvas does not. Gating that on `cwd` alone (the first version) told an SSH project's
+ user their edit was private when it was not. The layout is re-resolved AT CONFIRM TIME, never
+ captured with the dialog: it is open for as long as the user looks at it, and a pull or a peer
+ mutation can retire it underneath.
- **The content half is git-shared, the camera half is machine-local.** `Project.layouts` rides
`.nodeterm/project.json` beside `nodes` and `kanban`, because node geometry is already shared
content in that file and a restore writes exactly those fields. `Project.layoutViewports` (this
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ff0fba812..662aeae7e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -384,7 +384,10 @@ nodes and nothing else: it never creates, deletes, renames, reparents or respawn
touches a tmux session. The snapshot itself (`Project.layouts`) is CONTENT and rides the git-shared
`.nodeterm/project.json`, while this machine's camera per layout (`Project.layoutViewports`) is
machine-local and rides `workspace.json` beside `viewport` and `breadcrumbs`. Restoring applies its
-camera with `setViewport`, per the `fitView` rule below.
+camera with `setViewport`, per the `fitView` rule below. Deleting a layout and updating one to the
+arrangement on screen both confirm first, because layout edits are not in the undo stack; restoring
+does not, because it is. Whether a dialog claims the edit reaches other people comes from
+`layoutIsShared`, which is true for an SSH project as well as a folder one.
**React Flow's `fitView` is queued, not immediate — never use it to frame something automatically.**
Calling it sets `fitViewQueued` and the fit runs from a later `setNodes` (only once every node is
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 6a58947d4..5871f64bf 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -464,10 +464,13 @@ import { uuid } from '../lib/uuid'
import { CANVAS_LAYOUTS_CAP, findLayoutByName, type CanvasLayout } from '@shared/canvas-layout'
import { applyLayout, captureLayout } from '../lib/canvasLayout'
import {
+ deleteLayoutMessage,
layoutFramingViewport,
+ layoutIsShared,
restoreSummary,
saveLayoutRefusal,
- sortedLayouts
+ sortedLayouts,
+ updateLayoutMessage
} from '../lib/canvasLayoutView'
import { planReopen, type ReopenPlan } from '../lib/reopenPlan'
import { oneLine } from '@shared/one-line'
@@ -6783,6 +6786,54 @@ export function Canvas() {
})
}, [alertLayout, setConfirm, getViewport])
+ /**
+ * Overwrite a saved layout with the arrangement now on screen, keeping its name and id.
+ *
+ * The three-step alternative already worked (save, retype the name, confirm the replace), which
+ * is exactly why this exists: re-typing a name you are looking at is not a decision, it is
+ * friction. It reuses `saveLayout`'s replace-by-id path, so `createdAt` survives and `updatedAt`
+ * moves, and it re-captures the window size and camera because you are updating FROM this screen.
+ *
+ * Confirmed, unlike restore: layout edits are not in the undo stack, so the previous rects are
+ * gone the moment this runs.
+ */
+ const updateCanvasLayout = useCallback(
+ (layout: CanvasLayout) => {
+ const projectId = useProjects.getState().activeProjectId
+ if (!projectId) return
+ const shared = layoutIsShared(useProjects.getState().getProject(projectId))
+ setConfirm({
+ message: updateLayoutMessage(layout.name, shared),
+ confirmLabel: 'Update',
+ onConfirm: () => {
+ setConfirm(null)
+ // Re-resolved at confirm time, not captured above: the dialog is open for as long as the
+ // user looks at it, and a pull or a peer mutation can retire the layout underneath it.
+ const live = useProjects.getState().getProject(projectId)?.layouts?.find((l) => l.id === layout.id)
+ if (!live) {
+ alertLayout(`"${layout.name}" is no longer saved on this project, so nothing was updated.`)
+ return
+ }
+ const next = captureLayout(nodesRef.current, {
+ id: live.id,
+ name: live.name,
+ now: Date.now(),
+ window: { width: window.innerWidth, height: window.innerHeight }
+ })
+ const refusal = saveLayoutRefusal(
+ useProjects.getState().saveLayout(projectId, next, getViewport(), Date.now())
+ )
+ if (refusal) {
+ alertLayout(refusal)
+ return
+ }
+ setNotice({ kind: 'info', text: `Updated "${live.name}".` })
+ }
+ })
+ },
+ [alertLayout, setConfirm, getViewport, setNotice]
+ )
+
/**
* Put the canvas back the way a layout recorded it.
*
@@ -6863,16 +6914,9 @@ export function Canvas() {
(layout: CanvasLayout) => {
const projectId = useProjects.getState().activeProjectId
if (!projectId) return
- // A layout is CONTENT, so it lives in the project's own .nodeterm/project.json wherever that
- // file is: in the repo for a folder project, on the host for an SSH one. Both are shared with
- // whoever else opens that project, so both get the sentence. Only a cwd-less canvas keeps its
- // file inside this machine's userData and is genuinely nobody else's.
- const project = useProjects.getState().getProject(projectId)
- const shared = !!(project?.cwd || project?.ssh)
+ const shared = layoutIsShared(useProjects.getState().getProject(projectId))
setConfirm({
- message: shared
- ? `Delete the layout "${layout.name}"? It is shared with the project, so it goes for everyone who opens it. This cannot be undone.`
- : `Delete the layout "${layout.name}"? This cannot be undone.`,
+ message: deleteLayoutMessage(layout.name, shared),
confirmLabel: 'Delete',
danger: true,
onConfirm: () => {
@@ -14430,6 +14474,7 @@ export function Canvas() {
onFitView={fitAll}
onSaveLayout={() => void saveCanvasLayout()}
onRestoreLayout={restoreCanvasLayout}
+ onUpdateLayout={updateCanvasLayout}
onRenameLayout={(layout) => void renameCanvasLayout(layout)}
onDeleteLayout={deleteCanvasLayout}
onZoomIn={() => zoomIn({ duration: ZOOM_STEP_DURATION_MS })}
diff --git a/src/renderer/components/Dock.tsx b/src/renderer/components/Dock.tsx
index ad1bd34a8..83654be9d 100644
--- a/src/renderer/components/Dock.tsx
+++ b/src/renderer/components/Dock.tsx
@@ -51,6 +51,8 @@ interface DockProps {
/** Puts the canvas back the way `layout` recorded it. No confirm: it moves nodes and nothing
* else, and the undo stack picks it up like any other placement. */
onRestoreLayout: (layout: CanvasLayout) => void
+ /** Overwrites `layout` with the arrangement now on screen, keeping its name. */
+ onUpdateLayout: (layout: CanvasLayout) => void
onRenameLayout: (layout: CanvasLayout) => void
onDeleteLayout: (layout: CanvasLayout) => void
onZoomIn: () => void
@@ -94,6 +96,7 @@ export function Dock({
onFitView,
onSaveLayout,
onRestoreLayout,
+ onUpdateLayout,
onRenameLayout,
onDeleteLayout,
onZoomIn,
@@ -419,12 +422,24 @@ export function Dock({
</span>
</button>
<span className="dock-menu__row-actions">
+ <button
+ className="dock-menu__row-act"
+ aria-label={`Update layout ${layout.name} to the current arrangement`}
+ title="Update to the current arrangement"
+ onClick={(e) => {
+ // The row itself restores; these three must not.
+ e.stopPropagation()
+ setLayoutMenuOpen(false)
+ onUpdateLayout(layout)
+ }}
+ >
+ <UpdateIcon />
+ </button>
<button
className="dock-menu__row-act"
aria-label={`Rename layout ${layout.name}`}
title="Rename"
onClick={(e) => {
- // The row itself restores; these two must not.
e.stopPropagation()
setLayoutMenuOpen(false)
onRenameLayout(layout)
@@ -635,6 +650,13 @@ function LayoutsIcon() {
</svg>
)
}
+function UpdateIcon() {
+ return (
+ <svg {...S} width={13} height={13}>
+ <path d="M20 11a8 8 0 1 0-2.3 6.3M20 6v5h-5" />
+ </svg>
+ )
+}
function PencilIcon() {
return (
<svg {...S} width={13} height={13}>
diff --git a/src/renderer/lib/canvasLayoutView.test.ts b/src/renderer/lib/canvasLayoutView.test.ts
index 202af6c17..622fed75e 100644
--- a/src/renderer/lib/canvasLayoutView.test.ts
+++ b/src/renderer/lib/canvasLayoutView.test.ts
@@ -1,11 +1,14 @@
import { describe, expect, it } from 'vitest'
import type { CanvasLayout } from '@shared/canvas-layout'
import {
+ deleteLayoutMessage,
layoutFramingViewport,
+ layoutIsShared,
layoutSubtitle,
restoreSummary,
saveLayoutRefusal,
- sortedLayouts
+ sortedLayouts,
+ updateLayoutMessage
} from './canvasLayoutView'
const layout = (over: Partial<CanvasLayout> = {}): CanvasLayout => ({
@@ -103,3 +106,41 @@ describe('restoreSummary', () => {
)
})
})
+
+describe('layoutIsShared', () => {
+ it('is true for a folder project: its project.json is in the repo', () => {
+ expect(layoutIsShared({ cwd: '/Users/x/repo' })).toBe(true)
+ })
+
+ it('is true for an SSH project: its project.json is on the host', () => {
+ expect(layoutIsShared({ ssh: { server: {}, remoteCwd: '~' } })).toBe(true)
+ })
+
+ // The case the first version got wrong by gating on `cwd` alone.
+ it('is false only for a cwd-less canvas, whose file lives in this machine userData', () => {
+ expect(layoutIsShared({})).toBe(false)
+ expect(layoutIsShared(undefined)).toBe(false)
+ })
+})
+
+describe('deleteLayoutMessage / updateLayoutMessage', () => {
+ it('names who else a shared edit reaches', () => {
+ expect(deleteLayoutMessage('Ultrawide', true)).toContain('shared with the project')
+ expect(updateLayoutMessage('Ultrawide', true)).toContain('shared with the project')
+ })
+
+ it('claims nothing about other people for a cwd-less canvas', () => {
+ expect(deleteLayoutMessage('Scratch', false)).not.toContain('shared')
+ expect(updateLayoutMessage('Scratch', false)).not.toContain('shared')
+ })
+
+ // Both are destructive and neither is in the undo stack, which is why they confirm at all.
+ it('says the edit cannot be undone, in both dialogs', () => {
+ expect(deleteLayoutMessage('A', false)).toContain('cannot be undone')
+ expect(updateLayoutMessage('A', false)).toContain('cannot be undone')
+ })
+
+ it('names what update replaces, since that is what the user is about to lose', () => {
+ expect(updateLayoutMessage('Ultrawide', false)).toContain('saved positions are replaced')
+ })
+})
diff --git a/src/renderer/lib/canvasLayoutView.ts b/src/renderer/lib/canvasLayoutView.ts
index accb9b742..9077748f5 100644
--- a/src/renderer/lib/canvasLayoutView.ts
+++ b/src/renderer/lib/canvasLayoutView.ts
@@ -99,3 +99,41 @@ export function restoreSummary(
if (counts.extra) parts.push(`${counts.extra} not in this layout`)
return `Restored "${name}": ${parts.length ? parts.join(', ') : 'nothing changed'}.`
}
+
+/**
+ * Does this project's `.nodeterm/project.json` live somewhere other people read?
+ *
+ * A layout is CONTENT, so it sits in that file wherever the file is: in the repo for a folder
+ * project, on the host for an SSH one. Both are shared with whoever else opens the project. Only a
+ * cwd-less canvas keeps its file inside this machine's userData and is genuinely nobody else's.
+ *
+ * One definition because two dialogs ask it (delete and update) and a wrong answer is a sentence
+ * that lies about who a destructive edit reaches.
+ */
+export function layoutIsShared(project: { cwd?: string; ssh?: unknown } | undefined): boolean {
+ return !!(project?.cwd || project?.ssh)
+}
+
+/** The shared half of the two destructive-edit dialogs: who else this reaches. */
+const sharedClause = (shared: boolean): string =>
+ shared ? ' It is shared with the project, so it changes for everyone who opens it.' : ''
+
+/**
+ * Deleting a layout. Confirmed because layout edits are NOT in the undo stack: ⌘Z replays node
+ * arrays, and a layout lives beside them rather than in them.
+ */
+export function deleteLayoutMessage(name: string, shared: boolean): string {
+ return `Delete the layout "${name}"?${sharedClause(shared)} This cannot be undone.`
+}
+
+/**
+ * Overwriting a layout with the arrangement now on screen.
+ *
+ * Confirmed for the same reason delete is, and it is the reason this is not a bare one-click
+ * action: the previous rects are gone the moment it runs, and there is no undo to reach for. The
+ * message names what is replaced rather than what is kept, because the saved arrangement is the
+ * thing the user is about to lose.
+ */
+export function updateLayoutMessage(name: string, shared: boolean): string {
+ return `Update "${name}" to the arrangement on screen? Its saved positions are replaced.${sharedClause(shared)} This cannot be undone.`
+}