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
fix(whiteboards): a board edited in app data follows the canvas back into its folder
review87afb5c288ae
diff --git a/src/core/whiteboards.test.ts b/src/core/whiteboards.test.tsindex fb77f8cc1..43e8513c8 100644--- a/src/core/whiteboards.test.ts+++ b/src/core/whiteboards.test.ts@@ -6,6 +6,7 @@ import { join } from 'path'import {WHITEBOARD_SCENE_MAX_BYTES,appWhiteboardsDir,+ carryWhiteboards,projectWhiteboardsDir,readWhiteboard,saveWhiteboard@@ -305,3 +306,59 @@ describe('a folder project kept in app data', () => {expect((await readWhiteboard(loc, 'whiteboard-1'))?.scene).toBe(edited)})})++// The move of a folder project's canvas from app data back into its folder (issue #1145) takes the+// boards drawn or edited in app data along: the folder is read first afterwards, and its older file+// of the same board would otherwise hide the newer one.+describe('carryWhiteboards', () => {+ let appRoot: string+ beforeEach(() => {+ appRoot = join(userDataDir, 'project-files', 'project-p1')+ })+ const inFolder = (name: string) => join(projectWhiteboardsDir(projectCwd), name)++ it("copies every board into the folder, replacing the folder's older file, picture byte-exact", async () => {+ const edited = JSON.stringify({ type: 'excalidraw', elements: [{ id: 'edited' }] })+ await saveWhiteboard({ projectCwd, userDataDir }, 'whiteboard-1', scene)+ await saveWhiteboard({ projectCwd: appRoot, createRoot: true, userDataDir }, 'whiteboard-1', edited, png)+ await saveWhiteboard({ projectCwd: appRoot, createRoot: true, userDataDir }, 'whiteboard-2', scene)++ await carryWhiteboards(appRoot, projectCwd)++ expect(await fs.readFile(inFolder('whiteboard-1.excalidraw'), 'utf8')).toBe(edited)+ expect((await fs.readFile(inFolder('whiteboard-1.png'))).equals(pngBytes)).toBe(true)+ expect(await fs.readFile(inFolder('whiteboard-2.excalidraw'), 'utf8')).toBe(scene)+ // The app-data copies stay: nothing is deleted on either side.+ expect(await fs.readFile(join(projectWhiteboardsDir(appRoot), 'whiteboard-1.excalidraw'), 'utf8')).toBe(edited)+ })++ it("a carried board with no picture drops the folder's old picture rather than show it", async () => {+ await saveWhiteboard({ projectCwd, userDataDir }, 'whiteboard-1', scene, png)+ await saveWhiteboard({ projectCwd: appRoot, createRoot: true, userDataDir }, 'whiteboard-1', scene, '')+ await carryWhiteboards(appRoot, projectCwd)+ await expect(fs.stat(inFolder('whiteboard-1.png'))).rejects.toThrow()+ })++ it('does nothing, and creates nothing in the folder, when there is no board to carry', async () => {+ await carryWhiteboards(appRoot, projectCwd)+ expect(await fs.readdir(projectCwd)).toEqual([])+ })++ it.skipIf(process.platform === 'win32')('never carries a symlink, and never writes through one', async () => {+ const secret = join(root, 'secret.txt')+ await fs.writeFile(secret, 'private key material')+ const from = projectWhiteboardsDir(appRoot)+ await fs.mkdir(from, { recursive: true })+ await fs.symlink(secret, join(from, 'whiteboard-evil.excalidraw'))+ await carryWhiteboards(appRoot, projectCwd)+ await expect(fs.stat(inFolder('whiteboard-evil.excalidraw'))).rejects.toThrow()++ const outside = join(root, 'outside')+ await fs.mkdir(outside)+ await saveWhiteboard({ projectCwd: appRoot, createRoot: true, userDataDir }, 'whiteboard-1', scene)+ await fs.mkdir(join(projectCwd, '.nodeterm'), { recursive: true })+ await fs.symlink(outside, projectWhiteboardsDir(projectCwd))+ await carryWhiteboards(appRoot, projectCwd)+ expect(await fs.readdir(outside)).toEqual([])+ })+})diff --git a/src/core/whiteboards.ts b/src/core/whiteboards.tsindex dcb4f4edf..a2ab027c4 100644--- a/src/core/whiteboards.ts+++ b/src/core/whiteboards.ts@@ -256,6 +256,40 @@ async function readIn(return null}+/**+ * Copy the boards under `fromRoot`'s `.nodeterm/whiteboards/` into `toRoot`'s, replacing a file of the+ * same name. Run when a folder project's canvas moves from app data back into its folder (issue+ * #1145): the folder is read first afterwards, and its older file of a board edited in app data+ * would hide the edit. Nothing is deleted on either side. A board is read with symlinks refused and+ * the folder is bound by its real path, like every other board read and write, and the folder's+ * whiteboards directory is made only once there is a board to put in it. One that cannot be read or+ * written stays where it is. Never throws.+ */+export async function carryWhiteboards(fromRoot: string, toRoot: string): Promise<void> {+ const from = await projectBoardsDir(fromRoot, false).catch(() => null)+ if (!from) return+ const ids = (await fs.readdir(from).catch((): string[] => []))+ .filter((name) => name.endsWith('.excalidraw'))+ .map((name) => name.slice(0, -'.excalidraw'.length))+ .filter(safeId)+ let to: string | null | undefined+ for (const id of ids) {+ const board = await readRegularFileBytesNoFollow(join(from, `${id}.excalidraw`), WHITEBOARD_SCENE_MAX_BYTES)+ if (!board?.bytes) continue+ const picture = await readRegularFileBytesNoFollow(join(from, `${id}.png`), WHITEBOARD_THUMB_MAX_BYTES)+ if (to === undefined) to = await projectBoardsDir(toRoot, true).catch(() => null)+ if (!to) return+ try {+ await writeBytesAtomic(join(to, `${id}.excalidraw`), board.bytes)+ // A board with no picture is an empty one: the folder's old picture must not stand in for it.+ if (picture?.bytes) await writeBytesAtomic(join(to, `${id}.png`), picture.bytes)+ else await fs.rm(join(to, `${id}.png`), { force: true })+ } catch {+ // this board stays in app data, where a read still reaches it when the folder has none+ }+ }+}+/*** Read a board. `sourceId` is the board a duplicated or reopened node was copied from: until the* node saves its own file, it shows (and starts editing from) the source's — so a copy neverdiff --git a/src/core/workspace-store.folder-data.test.ts b/src/core/workspace-store.folder-data.test.tsindex 7a979e1c7..ce16e26a5 100644--- a/src/core/workspace-store.folder-data.test.ts+++ b/src/core/workspace-store.folder-data.test.ts@@ -448,6 +448,29 @@ describe('the move steps', () => {expect((await store.readProjectSettings('project-p1'))?.shared?.terminal?.shell).toBe('/bin/fish')})+ it('a round trip with a board edited in app data opens the edited board, not the folder copy', async () => {+ const store = new WorkspaceStore()+ const board = () => ({ ...store.whiteboardLocationForProject('project-p1'), userDataDir: userData })+ const sceneOf = (tag: string) => JSON.stringify({ type: 'excalidraw', elements: [{ id: tag }] })+ // Drawn while the canvas was in the folder, then moved into app data and edited there…+ await store.save(ws([project({ storeInAppData: undefined })]))+ await saveWhiteboard(board(), 'whiteboard-1', sceneOf('before'))+ await store.save(ws([project()]))+ await store.releaseFolderFiles('project-p1', false)+ const opened = await readWhiteboard(board(), 'whiteboard-1')+ expect(opened?.scene).toBe(sceneOf('before'))+ expect(await saveWhiteboard(board(), 'whiteboard-1', sceneOf('edited'), undefined, opened!.rev)).toMatchObject({ ok: true })+ // The folder still holds the board as it was before the move.+ const inFolder = path.join(folder, '.nodeterm', 'whiteboards', 'whiteboard-1.excalidraw')+ expect(await fs.readFile(inFolder, 'utf-8')).toBe(sceneOf('before'))++ // …and moved back: the edit comes with it.+ expect(await store.prepareFolderStorage('project-p1')).toEqual({ ok: true })+ await store.save(ws([project({ storeInAppData: undefined })]))+ expect((await readWhiteboard(board(), 'whiteboard-1'))?.scene).toBe(sceneOf('edited'))+ expect(await fs.readFile(inFolder, 'utf-8')).toBe(sceneOf('edited'))+ })+it('a move back that skipped prepare keeps the app-data settings', async () => {const store = new WorkspaceStore()await store.save(ws([project()]))diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex f02e1c698..3018bae25 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -23,7 +23,7 @@ import {} from './workspace-files'import { projectSettingsPath, readProjectSettingsFile, writeProjectSettingsFile } from './project-settings-files'import { gitTracksFile } from './git-tracked'-import type { WhiteboardLocation } from './whiteboards'+import { carryWhiteboards, type WhiteboardLocation } from './whiteboards'import type { PrepareFolderStorageResult, ProjectStorageKind, ReleaseFolderFilesResult } from '../shared/project-storage'import {parseProjectSettingsFile, sameProjectSettingsContent, sanitizeProjectLocalSettings,@@ -1937,7 +1937,9 @@ export class WorkspaceStore {* folder already holds a project.json (the save would overwrite that canvas — the same* probe-before-bind rule as "Set folder…") or a settings.json (this project's own would be lost),* and an unreadable file is never taken for an absent one. Otherwise carry the project's- * app-data settings into the folder, so they are there the moment the canvas is.+ * app-data settings into the folder, so they are there the moment the canvas is, and its+ * whiteboards (`carryWhiteboards`), so a board edited in app data is not hidden by the folder's+ * older copy once the folder is read first again.*//*** Where this store has a project's canvas, answered after any save in flight (queued on@@ -1973,6 +1975,7 @@ export class WorkspaceStore {return { ok: false, reason: 'settings-unreadable' }}}+ await carryWhiteboards(appDataProjectRoot(e.id), e.cwd)}return { ok: true }}