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
feat(accounts): account-aware node factories, persistence + branch/fork inheritance
enes96ab248e124e
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex f61c54e29..011c64070 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -1304,9 +1304,15 @@ export function Canvas() {| undefinedif (!detail?.sessionId) returnconst source = nodesRef.current.find((n) => n.id === detail.nodeId)- const node = createChatNode(nodesRef.current.length, detail.cwd, undefined, {- forkFrom: detail.sessionId- })+ // Inherit the source terminal's Claude account so the fork resumes its transcript,+ // which lives in that account's config dir.+ const node = createChatNode(+ nodesRef.current.length,+ detail.cwd,+ undefined,+ { forkFrom: detail.sessionId },+ source?.data.accountId+ )if (source) {node.position = {x: source.position.x + ((source.width as number) ?? 600) + 40,@@ -1774,7 +1780,11 @@ export function Canvas() {nodesRef.current.length,source.data.cwd,undefined,- prompt+ prompt,+ undefined,+ // Inherit the source's Claude account (dropped by the factory unless the target is claude),+ // so a claude→claude transfer resumes the transcript from the right account dir.+ source.data.accountId)node.position = {x: source.position.x + ((source.width as number) ?? 600) + 32,diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 3ed22ac4a..fc93cfbb0 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -359,7 +359,7 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasNcwd: sshRemoteTmux && !sshRemote ? undefined : data.cwd,persistKey: id,agentId: data.agentId,- accountId: data.accountId as string | undefined,+ accountId: data.accountId,sshRemote}).then(async ({ sessionId: sid, fresh }) => {diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.tsindex b6dc76f6d..3cfde835b 100644--- a/src/renderer/state/workspace.test.ts+++ b/src/renderer/state/workspace.test.ts@@ -1,10 +1,13 @@import { describe, it, expect } from 'vitest'import {+ createAgentNode,+ createChatNode,createDinoNode,flowToNodeStates,nodeStatesToFlow,reorderNodeBefore,- reparentNode+ reparentNode,+ resolveNewNodeAccount} from './workspace'import type { CanvasNode } from './workspace'@@ -142,6 +145,63 @@ describe('group worktree serialization', () => {})})+describe('resolveNewNodeAccount', () => {+ const accounts = [{ id: 'a1', label: 'work', createdAt: 0 }]+ it('prefers the explicit pick', () =>+ expect(resolveNewNodeAccount('a1', { defaultAccountId: 'a2' }, accounts)).toBe('a1'))+ it('falls back to the project default', () =>+ expect(resolveNewNodeAccount(undefined, { defaultAccountId: 'a1' }, accounts)).toBe('a1'))+ it('drops ids that no longer exist', () =>+ expect(resolveNewNodeAccount('gone', { defaultAccountId: 'gone' }, accounts)).toBeUndefined())+ it('undefined when nothing set', () =>+ expect(resolveNewNodeAccount(undefined, {}, accounts)).toBeUndefined())+ it('undefined when the project is undefined', () =>+ expect(resolveNewNodeAccount(undefined, undefined, accounts)).toBeUndefined())+})++describe('accountId on Claude node factories', () => {+ it('stamps accountId onto a Claude agent node', () => {+ const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, 'a1')+ expect(node.data.accountId).toBe('a1')+ })+ it('does not stamp accountId onto a non-Claude agent node', () => {+ const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'a1')+ expect(node.data.accountId).toBeUndefined()+ })+ it('omits accountId when none is given', () => {+ const node = createAgentNode('claude', 0)+ expect(node.data.accountId).toBeUndefined()+ })+ it('stamps accountId onto a chat node', () => {+ const node = createChatNode(0, undefined, undefined, undefined, 'a1')+ expect(node.data.accountId).toBe('a1')+ })+})++describe('accountId serialization', () => {+ it('round-trips data.accountId on a terminal node', () => {+ const node = {+ id: 'term-1',+ type: 'terminal',+ position: { x: 0, y: 0 },+ width: 600,+ height: 400,+ data: { title: 'T', color: '#888', group: null, agentId: 'claude', accountId: 'a1' }+ } as unknown as CanvasNode+ const states = flowToNodeStates([node])+ expect(states[0].accountId).toBe('a1')+ const back = nodeStatesToFlow(states)+ expect(back[0].data.accountId).toBe('a1')+ })+ it('leaves accountId undefined when unset', () => {+ const node = {+ id: 'term-2', type: 'terminal', position: { x: 0, y: 0 }, width: 1, height: 1,+ data: { title: 'T', color: '#888', group: null }+ } as unknown as CanvasNode+ expect(flowToNodeStates([node])[0].accountId).toBeUndefined()+ })+})+describe('dino node serialization', () => {it('round-trips a dino node and its highScore', () => {const dino = {diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 1a78507d7..e2b8aef67 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -1,5 +1,5 @@import type { Node } from '@xyflow/react'-import type { CanvasMutation, CanvasNodeState, NodeKind, Project } from '@shared/types'+import type { CanvasMutation, CanvasNodeState, ClaudeAccount, NodeKind, Project } from '@shared/types'import type { AgentId } from '@shared/agents/config'import { agentConfig } from '@shared/agents/config'import { useSettings } from './settings'@@ -64,6 +64,11 @@ export interface NodeData {highScore?: number/** Which agent runs in this terminal node (claude/codex/gemini/custom). */agentId?: AgentId+ /**+ * Claude nodes only: the managed Claude account (config-dir isolated) this node runs under.+ * Persisted so cold-restore resume reads the transcript from the right account dir.+ */+ accountId?: string/** group-only: the git worktree this group is bound to (single source of truth). */worktree?: import('@shared/worktree').GroupWorktree/**@@ -240,6 +245,17 @@ function resolveAgent(agentId: AgentId): { label: string; color: string; launchCreturn { label: agentId, color: FALLBACK_AGENT_COLOR, launchCmd: agentId }}+/** Account for a NEW Claude node: explicit pick, else the project default, else system. */+export function resolveNewNodeAccount(+ explicit: string | undefined,+ project: { defaultAccountId?: string } | undefined,+ accounts: ClaudeAccount[]+): string | undefined {+ const id = explicit ?? project?.defaultAccountId+ // A stale default (account since removed) must not stamp dead ids onto new nodes.+ return id && accounts.some((a) => a.id === id) ? id : undefined+}+/*** Creates a terminal node that launches the given agent on open. Title, color, and the* launch command come from the resolved agent config (builtin or custom); the node carries@@ -252,7 +268,8 @@ export function createAgentNode(cwd?: string,center?: { x: number; y: number },initialPrompt?: string,- ssh?: Project['ssh']+ ssh?: Project['ssh'],+ accountId?: string): CanvasNode {const { label, color, launchCmd } = resolveAgent(agentId)const baseCmd = agentId === 'claude' ? claudeLaunchCommand() : launchCmd@@ -274,6 +291,8 @@ export function createAgentNode(group: null,tags: [],agentId,+ // Accounts are inherently Claude-only — never stamp one onto another agent's node.+ ...(accountId && agentId === 'claude' ? { accountId } : {}),cwd: ssh ? ssh.remoteCwd : cwd,initialCommand,...(ssh ? { ssh: ssh.server, sshRemoteTmux: true } : {})@@ -405,7 +424,8 @@ export function createChatNode(index: number,cwd?: string,center?: { x: number; y: number },- init?: { chatSessionId?: string; forkFrom?: string }+ init?: { chatSessionId?: string; forkFrom?: string },+ accountId?: string): CanvasNode {return {id: nextId('chat'),@@ -418,6 +438,8 @@ export function createChatNode(title: 'Chat',color: '#d97757', // clay, matches agent nodesgroup: null,+ // Chat nodes are always Claude — stamp the account when one was resolved/inherited.+ ...(accountId ? { accountId } : {}),...(cwd ? { cwd } : {}),...(init?.chatSessionId ? { chatSessionId: init.chatSessionId } : {}),...(init?.forkFrom ? { forkFrom: init.forkFrom } : {})@@ -750,6 +772,7 @@ export function nodeStatesToFlow(states: CanvasNodeState[]): CanvasNode[] {commitOid: n.commitOid,highScore: n.highScore,agentId,+ accountId: n.accountId,ssh: n.ssh,sshRemoteTmux: n.sshRemoteTmux,sshFs: n.sshFs,@@ -816,6 +839,7 @@ export function flowToNodeStates(nodes: CanvasNode[]): CanvasNodeState[] {commitOid: n.data.commitOid,highScore: n.data.highScore,agentId: n.data.agentId,+ accountId: n.data.accountId,ssh: n.data.ssh,sshRemoteTmux: n.data.sshRemoteTmux,sshFs: n.data.sshFs,