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(workspace): app-data projects keep settings, board log and images out of the folder

Brandon Bridges1921cc2311c9
diff --git a/src/core/workspace-store.folder-data.test.ts b/src/core/workspace-store.folder-data.test.ts
index 830f0900f..04945da04 100644
--- a/src/core/workspace-store.folder-data.test.ts
+++ b/src/core/workspace-store.folder-data.test.ts
@@ -142,6 +142,52 @@ describe('a folder project stored in app data', () => {
expect(ref.storeInAppData).toBeUndefined()
expect(ids(data.nodes)).toEqual(['term-1'])
expect(data.storeInAppData).toBe(true)
+
+ // The folder's file belongs to the ref: an outside edit to it reaches the ref, whichever of
+ // the two entries comes first in the index.
+ const watched = new WorkspaceStore()
+ await watched.save(ws([project(), project({ id: 'project-ref', storeInAppData: undefined, nodes: [node('term-ref')] })]))
+ expect((await watched.readLocalRefByPath(folderFile()))?.id).toBe('project-ref')
+ })
+})
+
+describe('its side files', () => {
+ it('canvas images take the app-data fallback; the board log gets a userData root', async () => {
+ const store = new WorkspaceStore()
+ await store.save(ws([project(), project({ id: 'project-ref', storeInAppData: undefined, cwd: folder + '-b' })]))
+
+ // Terminals still run in the folder…
+ expect(store.localCwdForProject('project-p1')).toBe(folder)
+ // …but nodeterm writes nothing there.
+ expect(store.sideFilesFolderForProject('project-p1')).toBeUndefined()
+ expect(store.boardLogRootForProject('project-p1')).toBe(path.join(userData, 'project-files', 'project-p1'))
+
+ // A folder ref is unchanged: both answer its folder.
+ expect(store.sideFilesFolderForProject('project-ref')).toBe(folder + '-b')
+ expect(store.boardLogRootForProject('project-ref')).toBe(folder + '-b')
+ await fs.rm(folder + '-b', { recursive: true, force: true })
+ })
+})
+
+describe('its project settings', () => {
+ it('live in its app-data root, still as the shared document', async () => {
+ const store = new WorkspaceStore()
+ await store.save(ws([project()]))
+ // A settings.json committed in the folder is not this project's.
+ await fs.mkdir(path.join(folder, '.nodeterm'))
+ await fs.writeFile(path.join(folder, '.nodeterm', 'settings.json'), JSON.stringify({ version: 1, rev: 5, savedAt: '', terminal: { shell: '/bin/evil' } }))
+
+ expect((await store.readProjectSettings('project-p1'))?.shared).toBeNull()
+ expect(await store.writeProjectSettings('project-p1', { terminal: { shell: '/bin/zsh' } })).toBe(true)
+
+ const own = path.join(userData, 'project-files', 'project-p1', '.nodeterm', 'settings.json')
+ expect(JSON.parse(await fs.readFile(own, 'utf-8')).terminal.shell).toBe('/bin/zsh')
+ expect(JSON.parse(await fs.readFile(path.join(folder, '.nodeterm', 'settings.json'), 'utf-8')).terminal.shell).toBe('/bin/evil')
+ // Read back as `shared` (never folded into the machine-local overlay), so every consent rule
+ // that guards a shared value still applies.
+ const read = await new WorkspaceStore().load().then(async () => store.readProjectSettings('project-p1'))
+ expect(read?.shared?.terminal?.shell).toBe('/bin/zsh')
+ expect(read?.local).toBeUndefined()
})
})
@@ -172,6 +218,11 @@ describe('moving a folder project between the two locations', () => {
const loaded = (await new WorkspaceStore().load()).projects[0]
expect(loaded.storeInAppData).toBeUndefined()
expect(loaded.nodes[0].cwd).toBe(path.join(folder, 'sub'))
+
+ // The rev continues across the move: the project's counter was not reset with the sweep.
+ const rev = file.rev
+ await store.save(ws([project({ storeInAppData: undefined, nodes: [node('term-1'), node('term-2')] })]))
+ expect(JSON.parse(await fs.readFile(folderFile(), 'utf-8')).rev).toBe(rev + 1)
})
it('to the folder: keeps the data file while the folder write cannot land', async () => {
diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.ts
index 03210129f..709345985 100644
--- a/src/core/workspace-store.ts
+++ b/src/core/workspace-store.ts
@@ -102,6 +102,24 @@ const projectFilePath = (cwd: string): string => {
/** The data file of one cwd-less ("inline") project: `userData/inline-projects/<id>.json`. Only
* ever called with an id `isInlineProjectFileId` has already accepted — workspace.json is
* hand-editable, so an id read back out of it is input and may not reach a path unchecked. */
+/** Per-project side files (the board log) of a folder project kept in app data, under userData. */
+const PROJECT_SIDE_FILES_DIR = 'project-files'
+
+/**
+ * The directory whose `.nodeterm/` holds a local project's own files — settings.json and the board
+ * log: the folder of a folder ref, the per-project app-data root of a folder-data-ref (the folder's
+ * `.nodeterm/` layout, moved under userData), and none for ssh (routed separately) or a cwd-less
+ * canvas.
+ */
+export const appDataProjectRoot = (projectId: string): string =>
+ path.join(platform().userDataDir, PROJECT_SIDE_FILES_DIR, projectId)
+
+function settingsRootFor(e: IndexEntryV3): string | undefined {
+ if (e.ssh) return undefined
+ if (isFolderDataRef(e)) return isInlineProjectFileId(e.id) ? appDataProjectRoot(e.id) : undefined
+ return folderFileCwd(e)
+}
+
const inlineFilePath = (projectId: string): string =>
path.join(platform().userDataDir, inlineProjectFileRelPath(projectId))
@@ -840,9 +858,12 @@ export class WorkspaceStore {
if (!e) return null
const local = this.localSettingsByProject.get(projectId)
if (e.ssh) return this.readSshSettings(projectId, e.ssh, local)
- // An inline canvas has no folder, so there is no shared document to have.
- if (!folderFileCwd(e) || !e.cwd) return { shared: null, local }
- const read = await readProjectSettingsFile(e.cwd)
+ // An inline canvas has no folder, so there is no shared document to have. A folder project
+ // kept in app data has one, in its app-data root rather than the folder (issue #1145) — read
+ // exactly like the folder's, so its values still resolve as 'shared' and keep every consent.
+ const root = settingsRootFor(e)
+ if (!root) return { shared: null, local }
+ const read = await readProjectSettingsFile(root)
if (read.status === 'ok') {
// The rev source for the next write — a write that skipped the read would restart at rev 1
// and lose the counter a remote/offline comparison depends on.
@@ -1037,8 +1058,9 @@ export class WorkspaceStore {
const e = this.index?.entries.find((x) => x.id === projectId)
if (!e) return false
if (e.ssh) return this.writeSshSettings(projectId, e.ssh, doc)
- if (!folderFileCwd(e) || !e.cwd) return false
- const read = await readProjectSettingsFile(e.cwd)
+ const root = settingsRootFor(e)
+ if (!root) return false
+ const read = await readProjectSettingsFile(root)
// absent → nothing to lose, start at rev 1. invalid → the read already sidelined the only
// copy to `.corrupt-<ts>`, so this write destroys nothing either.
if (read.status === 'conflict' || read.status === 'error') return false
@@ -1049,7 +1071,7 @@ export class WorkspaceStore {
}
try {
const written = await writeProjectSettingsFile(
- e.cwd, doc, prev, new Date().toISOString()
+ root, doc, prev, new Date().toISOString()
)
this.lastSharedSettings.set(projectId, written)
return true
@@ -1750,7 +1772,9 @@ export class WorkspaceStore {
await fs.rm(file, { force: true }).catch(() => undefined)
this.lastWritten.delete(file)
this.lastWrittenParsed.delete(file)
- this.revs.delete(e.id)
+ // A project that only moved its canvas keeps its rev: it continues in the new location, and
+ // resetting it would send the folder's next write out as rev 1 over the rev N just written.
+ if (!nextById.has(e.id)) this.revs.delete(e.id)
}
}
@@ -1938,7 +1962,12 @@ export class WorkspaceStore {
/** Maps a watched file path back to its project and re-reads it. */
async readLocalRefByPath(filePath: string): Promise<Project | null> {
- const e = this.index?.entries.find((x) => x.cwd && projectFilePath(x.cwd) === filePath)
+ // `folderFileCwd`, not `cwd`: a folder-data-ref on the same folder as a folder ref must not
+ // answer for the ref's file, or the ref misses its outside edit.
+ const e = this.index?.entries.find((x) => {
+ const cwd = folderFileCwd(x)
+ return cwd !== undefined && projectFilePath(cwd) === filePath
+ })
return e ? this.readLocalRef(e.id) : null
}
@@ -2024,11 +2053,35 @@ export class WorkspaceStore {
}
/** The local folder cwd of a project by id (index lookup), or undefined for ssh/inline/unknown
- * projects. Sync (reads the in-memory index): the board-log router's local-vs-unsupported call. */
+ * projects. Sync (reads the in-memory index). Where the project's terminals RUN — which is
+ * also a relay seat's folder jail. Not where nodeterm may write its own files: see
+ * `sideFilesFolderForProject` and `boardLogRootForProject`. */
localCwdForProject(projectId: string): string | undefined {
return this.index?.entries.find((e) => e.id === projectId && e.cwd)?.cwd
}
+ /**
+ * The folder whose `.nodeterm/` may hold this project's side files (canvas images), or undefined
+ * — the caller's app-data fallback. A folder-data-ref has a cwd and still answers undefined: the
+ * whole point of keeping its canvas in app data is that nothing is written into the folder
+ * (issue #1145).
+ */
+ sideFilesFolderForProject(projectId: string): string | undefined {
+ const e = this.index?.entries.find((x) => x.id === projectId)
+ return e ? folderFileCwd(e) : undefined
+ }
+
+ /**
+ * The root a project's board log lives under (`<root>/.nodeterm/board-log.jsonl`), or undefined
+ * when it has none (ssh — routed separately — and cwd-less canvases). A folder ref's is its
+ * folder, beside project.json; a folder-data-ref's is a per-project directory in userData, so the
+ * log — and the cookie trace that reads it — keeps working without touching the folder.
+ */
+ boardLogRootForProject(projectId: string): string | undefined {
+ const e = this.index?.entries.find((x) => x.id === projectId)
+ return e ? settingsRootFor(e) : undefined
+ }
+
/** Minimal per-project target info for the setup/archive runner (project-setup-runner-local.ts's
* `resolveProjectSetupTarget`) — cwd/ssh/name straight off the loaded index. Sync, like
* `localCwdForProject`: this is what closes the Task 1 review finding that a run's rootPath/
diff --git a/src/main/index.ts b/src/main/index.ts
index d8348a63c..3ea7eeec9 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -2118,7 +2118,7 @@ app.whenReady().then(async () => {
// answers undefined for an SSH project (its cwd is on the host, and the image node reads
// locally) and for a relay tab (not in this index at all) — both take the app-local fallback.
registerFsHandlers(corePlatform, {
- localProjectCwd: (projectId: string) => workspaceStore.localCwdForProject(projectId)
+ localProjectCwd: (projectId: string) => workspaceStore.sideFilesFolderForProject(projectId)
})
const githubSecret = new ElectronGitHubSecretStore(app.getPath('userData'), safeStorage)
@@ -2211,7 +2211,7 @@ app.whenReady().then(async () => {
}
return { kind: 'remote', remoteCwd: ref.remoteCwd, exec, fingerprint }
}
- const cwd = workspaceStore.localCwdForProject(projectId)
+ const cwd = workspaceStore.boardLogRootForProject(projectId)
if (cwd) return { kind: 'local', cwd }
return { kind: 'unsupported' }
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 3e732ebfe..4f46c441a 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -377,7 +377,7 @@ export async function startServer(
getSettings: () => settingsStore.get(),
onSettingsChange: (cb) => settingsStore.onChange(cb),
downloadTickets,
- localProjectCwd: (projectId: string) => workspaceStore.localCwdForProject(projectId)
+ localProjectCwd: (projectId: string) => workspaceStore.sideFilesFolderForProject(projectId)
})
// Project setup/archive runner — same construction as src/main/index.ts, and the SAME
// `registerProjectSetupHandlers` trust boundary (project-setup-handlers.ts): it derives rootPath/
@@ -445,7 +445,7 @@ export async function startServer(
// an SSH-ref project answers `{ entries: [], unsupported: true }` (v1: no remote board log here).
const boardLog = registerBoardLogHandlers(platform, {
route: (projectId: string): BoardLogRoute => {
- const cwd = workspaceStore.localCwdForProject(projectId)
+ const cwd = workspaceStore.boardLogRootForProject(projectId)
return cwd ? { kind: 'local', cwd } : { kind: 'unsupported' }
}
})