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(relay): go to a shared node on its team tab; keep team tabs out of Recently closed
review209f69dc9469
diff --git a/CLAUDE.md b/CLAUDE.mdindex 77d599373..1db23dd9d 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -8502,7 +8502,19 @@ invariants:as a call, always passed by `VIEW_EVENTS`), because `workspace:server-change` ignores unknown idsand viewers never receive `canvas:authority-changed`. A tab the user closes is dismissed untilthe project is unshared; nothing shared keeps one placeholder tab. A hosted tab never cold-resumes- an agent (`canColdRestore` excludes `source === 'relay'`).+ an agent (`canColdRestore` excludes `source === 'relay'`). A CLOSED team tab (any `remote`+ project) is never offered by "Recently closed" (`isReopenableClosedProject`) or ⇧⌘T (`planReopen`+ skips it, `performCloseProject` does not push it): its nodes are the host's sessions, and a reopen+ from here mounts them on the LOCAL core.+- **One node id, two projects: owner lookups go through `nodeOwner`** (`lib/nodeOwner.ts`). After a+ share the closed, handed-off SSH project and the team tab hold the same node ids, and the SSH+ project comes FIRST in the list (a team tab is appended), so a bare+ `projects.find(p => p.nodes.some(...))` sent every "go to node" to the reopen warning. `nodeOwner`+ prefers an open project, then one without `handedOffTo`, then any; `focusNodeById`, the agent+ rename-node handler, `presenceTravel.nodeTravel` and the Omni board's rename use it. Deleting a+ project keeps the agent status of node ids another project still holds (`nodeIdsHeldElsewhere`).+ Deliberately NOT moved to it: `routeControlSource` (a control request comes from a LOCAL agent, so+ preferring an open relay tab would route it to another machine).- **Admin errors are stable codes, and a `--json` refusal goes to STDOUT.** `E_BAD_KEY`,`E_BAD_CWD`, `E_HOSTING_OFF`, `E_ADOPT_FAILED`, `E_BAD_REQUEST`, `E_UNSUPPORTED`(`core/relay/admin-error.ts`); a remote caller branches on the code, never the sentence, anddiff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex 8024ef895..ff781f28d 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -364,6 +364,14 @@ or, for a handover that did not finish:**Open here anyway** takes the project back: the mark is cleared, and this desktop writes the fileagain.+After a share, the closed SSH project and the team's tab hold the **same node ids** (they are the+tmux session names, and the server keeps them). Every "go to node" (a notification, the sessions+sidebar, ⌘K, a teammate's face, a rename from the board) goes to the project that owns the node in+this order: an open project before a closed one, and one not handed off before one that was+(`lib/nodeOwner.ts`). So it lands on the team's tab, never on the reopen warning. Deleting the closed+SSH project from "Recently closed" keeps the agent status of every node id another project still+holds.+### The owner's own join skips the SASA pasted code makes you read a SAS to an owner ([The first connect](#the-first-connect)). Share with@@ -600,7 +608,9 @@ project of yours that holds the id is skipped, never renamed.no new approval, and closes the tab of an unshared one; nothing is deleted on the host. A tab thata share event opens is added at the end of the tab bar.- **A tab you close stays closed** while its project stays shared, for the rest of the app run. Once- the host unshares it the dismissal is forgotten, so sharing it again opens it again.+ the host unshares it the dismissal is forgotten, so sharing it again opens it again. A closed team+ tab is not offered under "Recently closed", nor by ⇧⌘T: its nodes are the host's sessions, and+ reopening it from there would mount them on this computer's core. It comes back through the team.- **A team with nothing shared keeps one placeholder tab**, named after the team, so the team staysvisible and reconnectable. The first shared project replaces it.- **One connection, all tabs.** A dropped connection greys all of a team's tabs together. A reconnectdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 223a0b62a..d07ec05cc 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -300,6 +300,7 @@ import { PresenceLayer } from '../components/PresenceLayer'import { Facepile } from '../components/Facepile'import { PresenceNamePrompt } from '../components/PresenceNamePrompt'import { nodeTravel, projectTravel } from '../lib/presenceTravel'+import { nodeIdsHeldElsewhere, nodeOwner } from '../lib/nodeOwner'import {closeConfirmCopy,closedSessionCounts,@@ -11056,9 +11057,9 @@ export function Canvas() {useAgentStatus.getState().clearUnread(nodeId)return}- const owner = useProjects- .getState()- .projects.find((p) => p.nodes.some((n) => n.id === nodeId))+ // `nodeOwner`, not the first project holding the id: a closed, handed-off SSH project shares+ // its node ids with the team tab now serving them, and the tab is where the node lives.+ const owner = nodeOwner(useProjects.getState().projects, nodeId)if (owner && owner.id !== useProjects.getState().activeProjectId) {pendingFocusRef.current = nodeIdif (owner.closed) {@@ -15713,7 +15714,7 @@ export function Canvas() {if (!nodeId || !title) returnconst projectId = nodesRef.current.some((n) => n.id === nodeId)? activeProjectId- : useProjects.getState().projects.find((p) => p.nodes.some((n) => n.id === nodeId))?.id+ : nodeOwner(useProjects.getState().projects, nodeId)?.idif (!projectId) returnrenameSession(projectId, nodeId, title)})@@ -16905,7 +16906,11 @@ export function Canvas() {const store = useProjects.getState()if (id === store.activeProjectId) commitActiveToStore()if (endSessions) endProjectSessions(id)- useReopenHistory.getState().push({ kind: 'project', projectId: id, closedAt: Date.now() })+ // A relay tab is never reopened from the history (`planReopen` skips it too): its nodes are+ // the host's sessions.+ if (!store.getProject(id)?.remote) {+ useReopenHistory.getState().push({ kind: 'project', projectId: id, closedAt: Date.now() })+ }disposeRelayTabForProject(id)store.closeProject(id)void writeDisk()@@ -17467,6 +17472,9 @@ export function Canvas() {// End the tmux sessions of every terminal in the deleted project, and drop their// persisted agent status and subagent fan-out (node unmount removes neither — issue #402).const project = store.getProject(id)+ // A handed-off SSH project shares its node ids with the team tab now serving them: that tab+ // still needs their agent status.+ const heldElsewhere = nodeIdsHeldElsewhere(store.projects, id)project?.nodes.forEach((n) => {if ((n.kind ?? 'terminal') === 'terminal') {disposeTerminalOnUnmount(sessionForProject(id).id, n.id) // may be parked from a recent switch away@@ -17476,7 +17484,7 @@ export function Canvas() {// outlives the project entry (it is a file in the project's folder), so the run does not// stay open in the issue's history forever.if (n.issueRef) logIssueRunEnded(id, n)- useAgentStatus.getState().remove(n.id)+ if (!heldElsewhere.has(n.id)) useAgentStatus.getState().remove(n.id)useAgentNodes.getState().clearForParent(n.id)})// SSH project: the per-node `transport.destroy` above only ends the REMOTE session fordiff --git a/src/renderer/components/kanban/GlobalKanbanView.tsx b/src/renderer/components/kanban/GlobalKanbanView.tsxindex c250363cd..fb575a738 100644--- a/src/renderer/components/kanban/GlobalKanbanView.tsx+++ b/src/renderer/components/kanban/GlobalKanbanView.tsx@@ -31,6 +31,7 @@ import type { NodeIcon } from '@shared/node-icon'import { columnCategory } from '@shared/kanban-category'import { NO_STATIONS, stationsByOpener, type TeamStation } from '../../lib/teamProgress'import { stationNodeFromState } from '../../state/teamStations'+import { nodeOwner } from '../../lib/nodeOwner'/*** Global (Omni) Kanban overview — one swimlane per open project.@@ -430,7 +431,9 @@ export const GlobalKanbanView = memo(function GlobalKanbanView({ live = null, on}, [])const onRenameNode = useCallback((nodeId: string, title: string) => {- const proj = useProjects.getState().projects.find(p => p.nodes.some(n => n.id === nodeId))+ // The board lists open projects, and `nodeOwner` prefers an open one over a closed, handed-off+ // SSH project holding the same node id.+ const proj = nodeOwner(useProjects.getState().projects, nodeId)if (!proj) returnwindow.dispatchEvent(new CustomEvent('nodeterm:global-rename', { detail: { projectId: proj.id, nodeId, title } }))}, [])diff --git a/src/renderer/lib/closedHistory.test.ts b/src/renderer/lib/closedHistory.test.tsindex a4c40e730..c851c6a6d 100644--- a/src/renderer/lib/closedHistory.test.ts+++ b/src/renderer/lib/closedHistory.test.ts@@ -164,6 +164,11 @@ describe('mergeClosedHistory', () => {const rows = mergeClosedHistory([proj({ id: 'a', closed: true, unavailable: true, closedAt: 5 })])expect(rows).toHaveLength(0)})++ it('excludes a closed relay (team) tab: reopening it here would mount the host nodes on this core', () => {+ const rows = mergeClosedHistory([proj({ id: 'team', closed: true, remote: true, closedAt: 5 })])+ expect(rows).toHaveLength(0)+ })})// Issue #531: closing a node used to destroy the ONLY pointer to its transcript (the live session@@ -261,7 +266,7 @@ describe('closedTranscriptTarget', () => {})describe('recentlyClosedProjects — the heading promises recency (issue #506)', () => {- type Probe = { id: string; name: string; closed?: boolean; unavailable?: boolean; closedAt?: number }+ type Probe = { id: string; name: string; closed?: boolean; unavailable?: boolean; closedAt?: number; remote?: boolean }const p = (id: string, over: Partial<Probe> = {}): Probe => ({ id, name: id, ...over })it('orders newest-closed first, NOT tab order', () => {@@ -283,6 +288,11 @@ describe('recentlyClosedProjects — the heading promises recency (issue #506)',expect(rows.map((r) => r.id)).toEqual(['kept'])})+ it('drops a closed relay (team) tab: its nodes belong to the host, not to this core', () => {+ const rows = recentlyClosedProjects([p('team', { closed: true, remote: true, closedAt: 999 }), p('kept', { closed: true, closedAt: 1 })])+ expect(rows.map((r) => r.id)).toEqual(['kept'])+ })+it('sorts a project closed before the field existed last, never as NaN', () => {const rows = recentlyClosedProjects([p('legacy', { closed: true }), p('known', { closed: true, closedAt: 5 })])expect(rows.map((r) => r.id)).toEqual(['known', 'legacy'])diff --git a/src/renderer/lib/closedHistory.ts b/src/renderer/lib/closedHistory.tsindex 7316153fd..65bbb2744 100644--- a/src/renderer/lib/closedHistory.ts+++ b/src/renderer/lib/closedHistory.ts@@ -175,7 +175,7 @@ export type ClosedHistoryRow =* sentinel — never `NaN` from subtracting `undefined`.*//**- * The start screen's "Recently closed" list: closed, AVAILABLE projects, newest-closed first+ * The start screen's "Recently closed" list: closed, AVAILABLE, local projects, newest-closed first* (issue #506).** The heading promises recency and the list did not deliver it — it was@@ -190,13 +190,22 @@ export type ClosedHistoryRow =* those sort last rather than becoming `NaN`.*/export function recentlyClosedProjects<- T extends { closed?: boolean; unavailable?: boolean; closedAt?: number }+ T extends { closed?: boolean; unavailable?: boolean; closedAt?: number; remote?: boolean }>(projects: readonly T[]): T[] {return projects- .filter((p) => p.closed && !p.unavailable)+ .filter(isReopenableClosedProject).sort((a, b) => (b.closedAt ?? -1) - (a.closedAt ?? -1))}+/**+ * A closed project that "Recently closed" may offer. Not an `unavailable` one (see above), and not a+ * relay tab (`remote`, a hosted team's project): its nodes are the HOST's sessions, and reopening it+ * from here would mount them on this machine's core. A team tab comes back through the team.+ */+export function isReopenableClosedProject(p: { closed?: boolean; unavailable?: boolean; remote?: boolean }): boolean {+ return !!p.closed && !p.unavailable && !p.remote+}+/*** Narrows the "Recently closed" list by name or folder — both already rendered on the row, and* `cwd` is the row's `title`. Empty/whitespace query = everything, unchanged.@@ -213,7 +222,7 @@ export function filterClosedProjects<T extends { name: string; cwd?: string }>(export function mergeClosedHistory(projects: readonly Project[]): ClosedHistoryRow[] {const rows: ClosedHistoryRow[] = []for (const p of projects) {- if (p.closed && !p.unavailable) {+ if (isReopenableClosedProject(p)) {rows.push({ kind: 'project', projectId: p.id, closedAt: p.closedAt ?? -1, project: p })}for (const entry of p.closedSessions ?? []) {diff --git a/src/renderer/lib/nodeOwner.test.ts b/src/renderer/lib/nodeOwner.test.tsnew file mode 100644index 000000000..65a1f4f68--- /dev/null+++ b/src/renderer/lib/nodeOwner.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest'+import { nodeIdsHeldElsewhere, nodeOwner } from './nodeOwner'++// The shape Share with team leaves behind: the closed, handed-off SSH project first (a hosted tab is+// appended), and the team's tab holding the same node ids.+const sshProject = { id: 'ssh-1', closed: true, handedOffTo: { hostId: 'H', projectId: 'p-9', at: 1 }, nodes: [{ id: 'n1' }, { id: 'n2' }] }+const teamTab = { id: 'p-9', nodes: [{ id: 'n1' }, { id: 'n2' }] }++describe('nodeOwner', () => {+ it('prefers the open team tab over the closed, handed-off SSH project listed before it', () => {+ expect(nodeOwner([sshProject, teamTab], 'n1')?.id).toBe('p-9')+ })++ it('an open project wins over a closed one; among open (or closed) ones, the one not handed off wins', () => {+ const openMarked = { id: 'a', handedOffTo: { at: 1 }, nodes: [{ id: 'x' }] }+ const openPlain = { id: 'b', nodes: [{ id: 'x' }] }+ const closedPlain = { id: 'c', closed: true, nodes: [{ id: 'x' }] }+ const closedMarked = { id: 'd', closed: true, handedOffTo: { at: 1 }, nodes: [{ id: 'x' }] }+ expect(nodeOwner([closedMarked, closedPlain, openMarked, openPlain], 'x')?.id).toBe('b')+ expect(nodeOwner([closedMarked, closedPlain, openMarked], 'x')?.id).toBe('a')+ expect(nodeOwner([closedMarked, closedPlain], 'x')?.id).toBe('c')+ expect(nodeOwner([closedMarked], 'x')?.id).toBe('d')+ })++ it('ties go to the first in the list; an unknown node has no owner', () => {+ expect(nodeOwner([{ id: 'a', nodes: [{ id: 'x' }] }, { id: 'b', nodes: [{ id: 'x' }] }], 'x')?.id).toBe('a')+ expect(nodeOwner([teamTab], 'nope')).toBeUndefined()+ })+})++describe('nodeIdsHeldElsewhere', () => {+ it('lists the node ids another project still holds', () => {+ const other = { id: 'o', nodes: [{ id: 'z' }] }+ expect([...nodeIdsHeldElsewhere([sshProject, teamTab, other], 'ssh-1')].sort()).toEqual(['n1', 'n2', 'z'])+ expect([...nodeIdsHeldElsewhere([sshProject], 'ssh-1')]).toEqual([])+ })+})diff --git a/src/renderer/lib/nodeOwner.ts b/src/renderer/lib/nodeOwner.tsnew file mode 100644index 000000000..b8800d9ea--- /dev/null+++ b/src/renderer/lib/nodeOwner.ts@@ -0,0 +1,47 @@+// Which project owns a node id, when more than one holds it.+//+// A node id is normally in exactly one project, but "Share with team" breaks that on purpose: the+// SSH project it handed off stays in "Recently closed" (closed, `handedOffTo` set) holding the same+// node ids as the hosted team's tab that now serves them (the ids are the tmux session names, and+// the server keeps them). A plain `projects.find(...)` returns whichever comes first, which is the+// closed SSH project, so every "go to node" landed on the reopen warning instead of the live tab.++/** The little the lookup needs to know about a project. */+export interface OwnerProject {+ closed?: boolean+ handedOffTo?: unknown+ nodes: readonly { id: string }[]+}++/**+ * The project that owns `nodeId`: an open project before a closed one, and, among those, one not+ * handed off to a hosted team before one that was; ties go to the first in the list. `undefined`+ * when no project holds the node.+ */+export function nodeOwner<T extends OwnerProject>(projects: readonly T[], nodeId: string): T | undefined {+ let best: T | undefined+ let bestRank = Number.POSITIVE_INFINITY+ for (const p of projects) {+ if (!p.nodes.some((n) => n.id === nodeId)) continue+ const rank = (p.closed ? 2 : 0) + (p.handedOffTo ? 1 : 0)+ if (rank < bestRank) {+ best = p+ bestRank = rank+ }+ }+ return best+}++/** The node ids that some project other than `projectId` also holds. Deleting `projectId` must not+ * drop what those nodes still need (their agent status). */+export function nodeIdsHeldElsewhere(+ projects: readonly (OwnerProject & { id: string })[],+ projectId: string+): Set<string> {+ const out = new Set<string>()+ for (const p of projects) {+ if (p.id === projectId) continue+ for (const n of p.nodes) out.add(n.id)+ }+ return out+}diff --git a/src/renderer/lib/presenceTravel.test.ts b/src/renderer/lib/presenceTravel.test.tsindex 58cbbca98..17b1c071a 100644--- a/src/renderer/lib/presenceTravel.test.ts+++ b/src/renderer/lib/presenceTravel.test.ts@@ -57,6 +57,15 @@ describe('nodeTravel', () => {expect(nodeTravel(projects, 'active', 'n-gone')).toEqual({ kind: 'blocked' })})+ it('a node a closed, handed-off SSH project shares with its open team tab travels to the tab', () => {+ const shared: TravelProject[] = [+ { id: 'ssh-1', closed: true, handedOffTo: { at: 1 }, nodes: [{ id: 'n-team' }] },+ { id: 'team-tab', nodes: [{ id: 'n-team' }] },+ { id: 'active', nodes: [] }+ ]+ expect(nodeTravel(shared, 'active', 'n-team')).toEqual({ kind: 'switch', projectId: 'team-tab' })+ })+it('does nothing for an unknown node', () => {expect(nodeTravel(projects, 'active', 'n-ghost')).toEqual({ kind: 'none' })})diff --git a/src/renderer/lib/presenceTravel.ts b/src/renderer/lib/presenceTravel.tsindex 71ff3a965..d31c7aab6 100644--- a/src/renderer/lib/presenceTravel.ts+++ b/src/renderer/lib/presenceTravel.ts@@ -10,11 +10,15 @@// or unmounted) must not be travelled to at all: reopening it would load an empty canvas, exactly// the case Canvas already excludes from the welcome screen's "Recently closed" list.+import { nodeOwner } from './nodeOwner'+/** The little the routing needs to know about a project. */export interface TravelProject {id: stringclosed?: booleanunavailable?: boolean+ /** Set on an SSH project handed to a hosted team; that team's tab holds the same node ids. */+ handedOffTo?: unknownnodes: { id: string }[]}@@ -48,13 +52,14 @@ export function projectTravel(/** How to get to the project that owns `nodeId` — the travel half of "jump to the node my teammate* is working in". `none` also covers "the node is on the canvas we are already on": there is no- * travel to do, only a focus. */+ * travel to do, only a focus. The owner is `nodeOwner`'s: a node id a closed, handed-off SSH project+ * shares with its open team tab travels to the tab. */export function nodeTravel(projects: readonly TravelProject[],activeProjectId: string,nodeId: string): Travel {- const owner = projects.find((p) => p.nodes.some((n) => n.id === nodeId))+ const owner = nodeOwner(projects, nodeId)if (!owner) return { kind: 'none' }return projectTravel(projects, activeProjectId, owner.id)}diff --git a/src/renderer/lib/reopenPlan.test.ts b/src/renderer/lib/reopenPlan.test.tsindex b5f1289dd..3997d0e1a 100644--- a/src/renderer/lib/reopenPlan.test.ts+++ b/src/renderer/lib/reopenPlan.test.ts@@ -53,6 +53,12 @@ describe('planReopen', () => {expect(plan).toEqual({ action: 'skip' })})+ it('skips a closed relay (team) tab: a reopen would mount the host nodes on this core', () => {+ const projects: PlanReopenProject[] = [{ id: 'team', closed: true, remote: true, nodes: [] }]+ const plan = planReopen({ kind: 'project', projectId: 'team', closedAt: 1 }, projects, 'p2', new Set(), neverRecreates)+ expect(plan).toEqual({ action: 'skip' })+ })+it('skips a project entry whose project was permanently deleted since', () => {const plan = planReopen({ kind: 'project', projectId: 'gone', closedAt: 1 }, [], 'p2', new Set(), neverRecreates)expect(plan).toEqual({ action: 'skip' })diff --git a/src/renderer/lib/reopenPlan.ts b/src/renderer/lib/reopenPlan.tsindex fa1bc7b0a..7f016a836 100644--- a/src/renderer/lib/reopenPlan.ts+++ b/src/renderer/lib/reopenPlan.ts@@ -18,6 +18,8 @@ export type ReopenPlan =export interface PlanReopenProject {id: stringclosed?: boolean+ /** A relay tab (a hosted team's project): never reopened from the history. */+ remote?: booleannodes: readonly { id: string }[]}@@ -41,8 +43,10 @@ export function planReopen(): ReopenPlan {if (entry.kind === 'project') {const project = projects.find((p) => p.id === entry.projectId)- // Only stale if it isn't sitting closed right now — already reopened another way, or gone.- return project?.closed ? { action: 'reopenProject', projectId: entry.projectId } : { action: 'skip' }+ // Only stale if it isn't sitting closed right now — already reopened another way, or gone. A+ // relay tab is never reopened from here: its nodes are the host's sessions, and a reopen would+ // mount them on this machine's core (the team brings its own tabs back).+ return project?.closed && !project.remote ? { action: 'reopenProject', projectId: entry.projectId } : { action: 'skip' }}const project = projects.find((p) => p.id === entry.projectId)