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): the folder's settings win when a move into app data finds a leftover
Brandon Bridgescf3f864eef29
diff --git a/src/core/git-tracked.test.ts b/src/core/git-tracked.test.tsnew file mode 100644index 000000000..8109581c6--- /dev/null+++ b/src/core/git-tracked.test.ts@@ -0,0 +1,44 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest'+import { execFileSync } from 'child_process'+import { promises as fs } from 'fs'+import os from 'os'+import path from 'path'+import { gitTracksFile } from './git-tracked'++// The answer decides whether a file in the user's repo is deleted without asking, so the case that+// matters most is the one that is NOT a clean yes/no: it must come back 'unknown' (= ask first).+let dir: string+beforeEach(async () => {+ dir = await fs.mkdtemp(path.join(os.tmpdir(), 'nt-git-tracked-'))+})+afterEach(async () => {+ await fs.rm(dir, { recursive: true, force: true })+})++describe('gitTracksFile', () => {+ it('true for a tracked file, false for an untracked one in the same repository', async () => {+ execFileSync('git', ['init', '-q'], { cwd: dir })+ await fs.writeFile(path.join(dir, 'tracked.json'), '{}')+ await fs.writeFile(path.join(dir, 'loose.json'), '{}')+ execFileSync('git', ['add', 'tracked.json'], { cwd: dir })+ expect(await gitTracksFile(dir, path.join(dir, 'tracked.json'))).toBe(true)+ expect(await gitTracksFile(dir, path.join(dir, 'loose.json'))).toBe(false)+ })++ it('false in a folder that is not a repository at all', async () => {+ await fs.writeFile(path.join(dir, 'a.json'), '{}')+ // GIT_CEILING_DIRECTORIES keeps git from finding a repository ABOVE the temp dir.+ const prev = process.env.GIT_CEILING_DIRECTORIES+ process.env.GIT_CEILING_DIRECTORIES = path.dirname(dir)+ try {+ expect(await gitTracksFile(dir, path.join(dir, 'a.json'))).toBe(false)+ } finally {+ if (prev === undefined) delete process.env.GIT_CEILING_DIRECTORIES+ else process.env.GIT_CEILING_DIRECTORIES = prev+ }+ })++ it("'unknown' when git could not be asked (here: the folder does not exist)", async () => {+ expect(await gitTracksFile(path.join(dir, 'gone'), path.join(dir, 'gone', 'a.json'))).toBe('unknown')+ })+})diff --git a/src/core/workspace-store.folder-data.test.ts b/src/core/workspace-store.folder-data.test.tsindex bba3b97d5..6a6996102 100644--- a/src/core/workspace-store.folder-data.test.ts+++ b/src/core/workspace-store.folder-data.test.ts@@ -312,6 +312,20 @@ describe('the move steps', () => {expect((await store.readProjectSettings('project-p1'))?.shared?.terminal?.shell).toBe('/bin/zsh')})+ it("release: the folder's current settings win over a leftover app-data copy", async () => {+ const store = new WorkspaceStore()+ await seedFolder()+ await fs.mkdir(path.dirname(settingsIn(appRoot())), { recursive: true })+ await fs.writeFile(settingsIn(appRoot()), JSON.stringify({ version: 1, rev: 9, savedAt: '', terminal: { shell: '/bin/stale' } }))+ await store.save(ws([project({ storeInAppData: undefined })]))+ await store.save(ws([project()]))++ expect((await store.releaseFolderFiles('project-p1', false)).ok).toBe(true)+ const own = JSON.parse(await fs.readFile(settingsIn(appRoot()), 'utf-8'))+ expect(own.terminal.shell).toBe('/bin/zsh')+ expect(own.rev).toBe(10)+ })+it('release: keeps files git tracks unless told to remove them', async () => {execFileSync('git', ['init', '-q'], { cwd: folder })const store = new WorkspaceStore()diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex fbdb0b2eb..5b3ff675d 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -1857,17 +1857,20 @@ export class WorkspaceStore {const folderSettings = await readProjectSettingsFile(cwd)if (folderSettings.status === 'ok') {+ // The folder's copy is the current one: this project read its settings from there until the+ // move. An app-data file already present is a leftover (a sweep that did not finish), so it is+ // overwritten rather than allowed to win, with its rev continued.const root = appDataProjectRoot(e.id)const own = await readProjectSettingsFile(root)- let carried = own.status === 'ok'- if (own.status === 'absent') {+ if (own.status === 'ok' || own.status === 'absent' || own.status === 'invalid') {try {- const written = await writeProjectSettingsFile(root, folderSettings.file, null, new Date().toISOString())+ const written = await writeProjectSettingsFile(+ root, folderSettings.file, own.status === 'ok' ? own.file : null, new Date().toISOString()+ )this.lastSharedSettings.set(e.id, written)- carried = true- } catch { /* not carried: the folder's copy stays below */ }+ candidates.push(projectSettingsPath(cwd))+ } catch { /* not carried: the folder's copy stays */ }}- if (carried) candidates.push(projectSettingsPath(cwd))}const removed: string[] = []@@ -1909,14 +1912,14 @@ export class WorkspaceStore {if (state === 'unreadable') return { ok: false, reason: 'unreadable' }const folderSettings = await readProjectSettingsFile(e.cwd)if (folderSettings.status === 'ok' || folderSettings.status === 'conflict') return { ok: false, reason: 'settings-occupied' }- if (folderSettings.status === 'error') return { ok: false, reason: 'unreadable' }+ if (folderSettings.status === 'error') return { ok: false, reason: 'settings-unreadable' }if (isInlineProjectFileId(e.id)) {const own = await readProjectSettingsFile(appDataProjectRoot(e.id))if (own.status === 'ok') {try {await writeProjectSettingsFile(e.cwd, own.file, null, new Date().toISOString())} catch {- return { ok: false, reason: 'unreadable' }+ return { ok: false, reason: 'settings-unreadable' }}}}diff --git a/src/shared/project-storage.ts b/src/shared/project-storage.tsindex 18695909d..bab78d74e 100644--- a/src/shared/project-storage.ts+++ b/src/shared/project-storage.ts@@ -28,7 +28,7 @@ export type ReleaseFolderFilesResult =*/export type PrepareFolderStorageResult =| { ok: true }- | { ok: false; reason: 'not-app-data' | 'occupied' | 'unreadable' | 'settings-occupied' }+ | { ok: false; reason: 'not-app-data' | 'occupied' | 'unreadable' | 'settings-occupied' | 'settings-unreadable' }export const PREPARE_FOLDER_STORAGE_REFUSALS: Record<Exclude<PrepareFolderStorageResult, { ok: true }>['reason'], string> = {'not-app-data': 'This project already stores its canvas in its folder.',@@ -36,5 +36,6 @@ export const PREPARE_FOLDER_STORAGE_REFUSALS: Record<Exclude<PrepareFolderStorag'The folder already has a .nodeterm/project.json. Delete it first, or use “Open folder…” to open that canvas instead.',unreadable: 'The folder’s .nodeterm/project.json could not be read, so nothing was changed.','settings-occupied':- 'The folder already has a .nodeterm/settings.json. Delete it first so this project’s own settings are not lost.'+ 'The folder already has a .nodeterm/settings.json. Delete it first so this project’s own settings are not lost.',+ 'settings-unreadable': 'The folder’s .nodeterm/settings.json could not be read or written, so nothing was changed.'}