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(core): a rebuilt index pauses only live links' node-gone, not the mirror's pruning
review0a8cefed8f73
diff --git a/src/core/watch-link/service.test.ts b/src/core/watch-link/service.test.tsindex a04000639..4dd184893 100644--- a/src/core/watch-link/service.test.ts+++ b/src/core/watch-link/service.test.ts@@ -852,7 +852,7 @@ describe('registerWatchLinkIpc / sendToOwners', () => {describe('workspaceNodeState', () => {const store = (held: Record<string, string[]>, known: Set<string> | undefined) => ({projectIdsForNode: (id: string) => held[id] ?? [],- knownNodeIds: () => known+ knownNodeIdsStrict: () => known})it('present when a project holds it', () => {expect(workspaceNodeState(store({ n1: ['p1'] }, undefined), 'n1')).toBe('present')diff --git a/src/core/watch-link/service.ts b/src/core/watch-link/service.tsindex ae4eb828b..41f0a3983 100644--- a/src/core/watch-link/service.ts+++ b/src/core/watch-link/service.ts@@ -130,16 +130,17 @@ export interface WatchLinkService {/*** The node-gone rule over the workspace store, shared by both shells: present when some project- * holds the node; absent only when the store has a COMPLETE read of every project (`knownNodeIds`)- * and the node is not in it; unknown otherwise (the index not loaded yet, a project file not read- * this run, an SSH project with no cache).+ * holds the node; absent only when the store has a COMPLETE read of every project+ * (`knownNodeIdsStrict`) and the node is not in it; unknown otherwise (the index not loaded yet, a+ * project file not read this run, an SSH project with no cache, an index rebuilt from nothing this+ * run). The STRICT accessor, never the mirror's `knownNodeIds`: absent here revokes a link for good.*/export function workspaceNodeState(- store: Pick<WorkspaceStore, 'projectIdsForNode' | 'knownNodeIds'>,+ store: Pick<WorkspaceStore, 'projectIdsForNode' | 'knownNodeIdsStrict'>,nodeId: string): WatchLinkNodeState {if (store.projectIdsForNode(nodeId).length > 0) return 'present'- const known = store.knownNodeIds()+ const known = store.knownNodeIdsStrict()if (!known) return 'unknown'return known.has(nodeId) ? 'present' : 'absent'}diff --git a/src/core/watch-link/service.workspace.test.ts b/src/core/watch-link/service.workspace.test.tsindex 0301ea568..aa132858b 100644--- a/src/core/watch-link/service.workspace.test.ts+++ b/src/core/watch-link/service.workspace.test.ts@@ -109,7 +109,7 @@ describe('an index rebuilt from nothing is never a complete read (R44)', () => {await store.save(ws([])) // the renderer's unconditional boot save: an EMPTY indexexpect(JSON.parse(await fs.readFile(m.index, 'utf8')).entries).toEqual([])expect(workspaceNodeState(store, 'term-1')).toBe('unknown')- expect(store.knownNodeIds()).toBeUndefined()+ expect(store.knownNodeIdsStrict()).toBeUndefined()await settle()expect(links.calls).toEqual([])expect(links.stopped).toEqual([])@@ -141,7 +141,7 @@ describe('an index rebuilt from nothing is never a complete read (R44)', () => {await fs.mkdir(m.index) // readFile answers EISDIR: the store falls back to an empty workspaceconst store = new WorkspaceStore()await store.load({ sideline: false })- expect(store.knownNodeIds()).toBeUndefined()+ expect(store.knownNodeIdsStrict()).toBeUndefined()await fs.rmdir(m.index)await store.save(ws([]))expect(workspaceNodeState(store, 'term-1')).toBe('unknown')@@ -185,7 +185,7 @@ describe('an index rebuilt from nothing is never a complete read (R44)', () => {const store = new WorkspaceStore()await store.load()await store.save(ws([]))- expect(store.knownNodeIds()).toEqual(new Set())+ expect(store.knownNodeIdsStrict()).toEqual(new Set())expect(workspaceNodeState(store, 'term-1')).toBe('absent')})}diff --git a/src/core/workspace-store.test.ts b/src/core/workspace-store.test.tsindex 628958729..84d4fc0a0 100644--- a/src/core/workspace-store.test.ts+++ b/src/core/workspace-store.test.ts@@ -2349,8 +2349,9 @@ describe('knownNodeIds — every node id in every project, or undefined when it})// R44: a lost workspace.json is rebuilt from nothing — the renderer's boot save writes an EMPTY// index while every project.json still holds its nodes. Read as complete, it said every node was- // gone (a live link revoked a second after launch).- it('stays undefined for the rest of a run whose index was lost or corrupt, whatever is saved after', async () => {+ // gone (a live link revoked a second after launch). The STRICT accessor (live links) answers unknown+ // for the rest of such a run…+ it('the strict accessor stays undefined for the rest of a run whose index was lost or corrupt, whatever is saved after', async () => {await new WorkspaceStore().save(ws([project({ id: 'p-local', cwd: projRoot })]))for (const lose of ['corrupt', 'deleted'] as const) {const index = path.join(userData, 'workspace.json')@@ -2359,22 +2360,48 @@ describe('knownNodeIds — every node id in every project, or undefined when itconst store = new WorkspaceStore()await store.load()await store.save(ws([]))- expect(store.knownNodeIds()).toBeUndefined()+ expect(store.knownNodeIdsStrict()).toBeUndefined()await store.save(ws([project({ id: 'p-local', cwd: projRoot })]))- expect(store.knownNodeIds()).toBeUndefined()+ expect(store.knownNodeIdsStrict()).toBeUndefined()// The next run reads a readable index again, and answers.const next = new WorkspaceStore()await next.load()- expect([...(next.knownNodeIds() ?? [])]).toEqual(['term-1'])+ expect([...(next.knownNodeIdsStrict() ?? [])]).toEqual(['term-1'])+ }+ })+ // …while the agent-status MIRROR's accessor keeps its behaviour from before live links (R64/M2):+ // pruning an identity against a rebuilt index costs one hook event, and the flag lasts the whole+ // process — a Server Edition started on a fresh data dir runs for weeks.+ it("the mirror's accessor answers in such a run, exactly as before (it never reads the rebuild flag)", async () => {+ await new WorkspaceStore().save(ws([project({ id: 'p-local', cwd: projRoot })]))+ for (const lose of ['corrupt', 'deleted'] as const) {+ const index = path.join(userData, 'workspace.json')+ if (lose === 'corrupt') await fs.writeFile(index, '{nope')+ else await fs.rm(index, { force: true })+ const store = new WorkspaceStore()+ await store.load()+ // Before any save there is no index in memory: unknown, as it always was.+ expect(store.knownNodeIds()).toBeUndefined()+ await store.save(ws([]))+ expect(store.knownNodeIds()).toEqual(new Set())+ await store.save(ws([project({ id: 'p-local', cwd: projRoot })]))+ expect([...(store.knownNodeIds() ?? [])]).toEqual(['term-1'])}})// Re-review NEW-1: an index of the right version that cannot be BUILT (loadV3 throws: a `cwd` that// is not a string) keeps rejecting as before, and marks the run like any other unreadable index.- it('a v3 index whose build throws still rejects the load, and marks the run', async () => {+ it('a v3 index whose build throws still rejects the load, and marks the run (strict only)', async () => {await fs.writeFile(path.join(userData, 'workspace.json'), JSON.stringify({ version: 3, entries: [{ id: 'p1', name: 'x', color: '#fff', cwd: 5 }] }))const store = new WorkspaceStore()await expect(store.load()).rejects.toThrow()await store.save(ws([]))- expect(store.knownNodeIds()).toBeUndefined()+ expect(store.knownNodeIdsStrict()).toBeUndefined()+ expect(store.knownNodeIds()).toEqual(new Set())+ })+ it('a readable index: the two accessors agree', async () => {+ const store = new WorkspaceStore()+ await store.save(ws([project({ id: 'p-local', cwd: projRoot })]))+ expect(store.knownNodeIdsStrict()).toEqual(store.knownNodeIds())+ expect(new WorkspaceStore().knownNodeIdsStrict()).toBeUndefined() // not loaded: unknown to both})})diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex 8518b09fe..fa7a8b8d6 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -331,10 +331,16 @@ export class WorkspaceStore {* index this build recognises (`{}`, a v3 without entries, a newer build's version) — so whatever* index this run holds afterwards may have been rebuilt from NOTHING: the renderer's unconditional* boot save writes an EMPTY index over the set-aside file while every project's own- * `.nodeterm/project.json` still holds its nodes. `knownNodeIds` then answers undefined for the rest- * of the run (controller ruling R44): a live link would otherwise read every node as gone and be- * revoked server-side a second after launch — irreversibly. The cost: node-gone and the mirror's- * existence pruning wait for the next launch with a readable index (links still end at their expiry).+ * `.nodeterm/project.json` still holds its nodes. `knownNodeIdsStrict` then answers undefined for+ * the rest of the run (controller ruling R44): a live link would otherwise read every node as gone+ * and be revoked server-side a second after launch — irreversibly. The cost: a live link's node-gone+ * waits for the next launch with a readable index (links still end at their expiry).+ *+ * Live links ONLY (R64/M2): `knownNodeIds`, which the agent-status mirror prunes identities with,+ * does not read this flag. A mirror entry pruned against an index rebuilt from nothing costs one+ * hook event to restore; the flag lasts for the whole PROCESS, and a Server Edition started on a+ * fresh data dir runs for weeks — R54's first version switched the mirror's pruning off for all of+ * them, so the phone kept listing deleted sessions for up to the 30-day identity TTL.*/private indexRebuiltThisRun = false/** The content authority, when this process runs one (Server Edition hosting a team). */@@ -1918,12 +1924,13 @@ export class WorkspaceStore {* the entry by its identity TTL alone. Same three-entry-kind scan as `findNode`.* Consequence: ONE permanently unavailable local ref or one never-cached SSH project turns* existence pruning off for EVERY project, leaving only the 30-day identity TTL.- * Also undefined for the rest of a run whose index was rebuilt from nothing (`indexRebuiltThisRun`,- * R44): an empty index written over a lost workspace.json is not a read of the projects it lost.+ * It does NOT read `indexRebuiltThisRun` (R64/M2): for the mirror an index rebuilt from nothing is+ * an answer, because a wrongly pruned identity costs one hook event to restore. Live links, whose+ * "gone" is an irreversible revoke, ask `knownNodeIdsStrict`.* Parses through `parsedLastWritten`, so a mirror flush re-parses no unchanged project.json.*/knownNodeIds(): Set<string> | undefined {- if (!this.index || this.indexRebuiltThisRun) return undefined+ if (!this.index) return undefinedconst ids = new Set<string>()for (const e of this.index.entries) {let nodes: CanvasNodeState[] | undefined@@ -1942,6 +1949,17 @@ export class WorkspaceStore {return ids}+ /**+ * `knownNodeIds`, for a caller whose "not in any project" is IRREVERSIBLE — a live link, which a node+ * gone ends and revokes server-side (R40). Also undefined for the rest of a run whose index was+ * rebuilt from nothing (`indexRebuiltThisRun`, R44): an empty index written over a lost+ * workspace.json is not a read of the projects it lost.+ */+ knownNodeIdsStrict(): Set<string> | undefined {+ if (this.indexRebuiltThisRun) return undefined+ return this.knownNodeIds()+ }+/*** Every persisted canvas as {id, nodes, bridges} — the raw material the Server Edition derives* its context-link map from (src/server/context-link.ts). Same three-entry-kind scan as