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(menus): add session transfer menu
Darren Kattane44a36f0bbfc
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 7c7d74767..52642dc2c 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -259,7 +259,6 @@ import {hasHooks,canBranch,canRename,- canTransferFrom,canContextLink,createdAgentId,resumeCommand,@@ -5216,40 +5215,14 @@ export function Canvas() {}] as MenuItem[]): []),- ...(ids.length === 1 &&- (() => {- const a = agentIdOf(ids[0])- return !!a && canTransferFrom(a) && !!useAgentStatus.getState().byId[ids[0]]?.sessionId- })()- ? (() => {- const src = agentIdOf(ids[0]) as AgentId- const disabled = useSettings.getState().settings.disabledAgents- const settings = useSettings.getState().settings- const targets: { id: AgentId; label: string }[] = [- ...BUILTIN_AGENT_IDS.filter((aid) => aid !== src && !disabled.includes(aid)).map(- (aid) => ({ id: aid as AgentId, label: AGENT_CONFIG[aid].label })- ),- ...settings.customAgents- .filter((c) => c.id !== src && !disabled.includes(c.id))- .map((c) => ({ id: c.id, label: c.label }))- ]- return [- { type: 'label', label: 'Transfer conversation to' },- ...targets.map(- (tg): MenuItem => ({- label: tg.label,- icon: <AgentIcon agentId={tg.id} />,- onClick: () => void transferConversation(ids[0], tg.id, at)- })- )- ] as MenuItem[]- })()+ ...(ids.length === 1+ ? transferConversationItems(ids[0], at, {+ sourceAgentId: agentIdOf(ids[0]),+ sessionId: useAgentStatus.getState().byId[ids[0]]?.sessionId,+ disabledAgents: useSettings.getState().settings.disabledAgents,+ customAgents: useSettings.getState().settings.customAgents+ }, transferConversation): []),- ...(isHidden('align-grid', hidden)- ? []- : ([- { label: 'Align to grid', icon: <IconGrid />, onClick: () => alignToGrid(ids) }- ] as MenuItem[])),...(isHidden('collapse', hidden)? []: ([@@ -5550,44 +5523,66 @@ export function Canvas() {]}, [])+ // The shared bag of creation callbacks + project context that every "add" menu derives its+ // CONTENT items from (see lib/addMenuSpec.ts). Built once here so the pane menu, the sidebar+ // project-header "+", and any other ContextMenu-based surface pass the same handlers and can no+ // longer drift on which kinds are addable. Agent entries are layered on by each surface from+ // `agentCreationItems` (already shared) — the spec owns the content list only.+ const addCtx = useMemo(+ () => ({+ hasCwd: !!(useProjects.getState().getProject(activeProjectId)?.ssh?.remoteCwd ??+ useProjects.getState().getProject(activeProjectId)?.cwd),+ isSshProject+ }),+ [activeProjectId, isSshProject]+ )+ const addHandlers = useMemo<AddHandlers>(+ () => ({+ terminal: (at) => addTerminal(at),+ remote: (screenPos) => openRemotePicker(screenPos),+ browser: (at) => addBrowser(at),+ web: (at) => void addWebView(at),+ sticky: (at) => addSticky(at),+ dino: (at) => addDino(at),+ openFile: (at) => void openFileDialog(at),+ newFile: (at) => void newProjectFile(at),+ worktree: (at) => openWorktreeDialog(null, at)+ }),+ [+ addTerminal,+ openRemotePicker,+ addBrowser,+ addWebView,+ addSticky,+ addDino,+ openFileDialog,+ newProjectFile,+ openWorktreeDialog+ ]+ )+const onPaneContextMenu = useCallback((e: MouseEvent | React.MouseEvent) => {e.preventDefault()const at = screenToFlowPosition({ x: e.clientX, y: e.clientY })- // "New file…" needs a project folder to create into — hidden when the project has no cwd.- const project = useProjects.getState().getProject(activeProjectId)- const hasCwd = !!(project?.ssh?.remoteCwd ?? project?.cwd)+ const screenPos = { x: e.clientX, y: e.clientY }+ // Split the canonical content list around the agent block: the pane menu shows terminal,+ // THEN agents, THEN the rest (remote, browser, …, worktree). The spec is still the single+ // source for WHICH kinds appear and in what order — only the agent interleaving is local.+ const [terminalItem, ...restContent] = contentAddItemsToMenuItems(+ CONTENT_ADD_ITEMS,+ addHandlers,+ addCtx,+ at,+ screenPos+ )setMenu({x: e.clientX,y: e.clientY,items: [- // Sessions: local terminal, agent CLIs, remote host.- { label: 'New terminal', icon: <IconTerminal />, onClick: () => addTerminal(at) },+ terminalItem,...agentCreationItems(at),- {- label: 'New remote…',- icon: <IconTerminal />,- onClick: () => openRemotePicker({ x: e.clientX, y: e.clientY })- },- { type: 'separator' },- // Content nodes.- { label: 'New browser', icon: <IconRemote />, onClick: () => addBrowser(at) },- { label: 'New sticky note', icon: <IconNote />, onClick: () => addSticky(at) },- { label: 'New dino game', icon: <IconDino />, onClick: () => addDino(at) },- { label: 'Open file…', icon: <IconEditor />, onClick: () => void openFileDialog(at) },- ...(hasCwd- ? [{ label: 'New file…', icon: <IconEditor />, onClick: () => void newProjectFile(at) }]- : []),- { type: 'separator' },- // A worktree lands as a group frame bound to it; nodes created inside inherit its path.- // Disabled (with the reason) on an SSH project — see WORKTREE_SSH_HINT.- {- label: 'New worktree…',- icon: <IconBranch />,- disabled: isSshProject,- hint: isSshProject ? WORKTREE_SSH_HINT : undefined,- onClick: () => openWorktreeDialog(null, at)- },+ ...restContent,{ type: 'separator' },// Canvas actions.{ label: 'Select all', icon: <IconSelectAll />, onClick: selectAll },@@ -7602,6 +7597,19 @@ export function Canvas() {}}},+ // Transfer conversation to another agent — the SAME submenu the canvas node right-click+ // has. Only valid for the ACTIVE project's canvas: transferConversation reads the source+ // node out of `nodesRef.current` (the live React Flow nodes), which only holds the active+ // project. For a non-active project the block is empty (no submenu appears), matching the+ // Duplicate guard's active-project branch.+ ...(projectId === activeProjectId+ ? transferConversationItems(id, undefined, {+ sourceAgentId: agentIdOf(id),+ sessionId: useAgentStatus.getState().byId[id]?.sessionId,+ disabledAgents: useSettings.getState().settings.disabledAgents,+ customAgents: useSettings.getState().settings.customAgents+ }, transferConversation)+ : []),{label: 'Close',icon: <IconTrash />,@@ -7611,7 +7619,16 @@ export function Canvas() {]})},- [activeProjectId, focusNodeById, renameSession, duplicateNodes, closeSession, writeDisk]+ [+ activeProjectId,+ focusNodeById,+ renameSession,+ duplicateNodes,+ closeSession,+ writeDisk,+ agentIdOf,+ transferConversation+ ])// Stream live subagent transcript chunks into the agent-nodes store.diff --git a/src/renderer/lib/transferItems.test.tsx b/src/renderer/lib/transferItems.test.tsxnew file mode 100644index 000000000..5e621ae79--- /dev/null+++ b/src/renderer/lib/transferItems.test.tsx@@ -0,0 +1,90 @@+import { describe, it, expect } from 'vitest'+import { transferTargets, transferConversationItems } from './transferItems'+import type { AgentId } from '@shared/agents/config'+import type { CustomAgent } from '@shared/types'++const customs: CustomAgent[] = [+ { id: 'custom:a', label: 'Agent A', launchCmd: 'a', promptInjectionMode: 'argv' },+ { id: 'custom:b', label: 'Agent B', launchCmd: 'b', promptInjectionMode: 'argv' }+]++describe('transferTargets', () => {+ it('excludes the source agent and disabled agents', () => {+ const targets = transferTargets('claude' as AgentId, ['gemini'], customs)+ const ids = targets.map((t) => t.id)+ expect(ids).not.toContain('claude') // source excluded+ expect(ids).not.toContain('gemini') // disabled excluded+ expect(ids).toContain('codex')+ expect(ids).toContain('grok')+ expect(ids).toContain('opencode')+ // customs both present (neither is the source nor disabled)+ expect(ids).toContain('custom:a')+ expect(ids).toContain('custom:b')+ })++ it('excludes a custom agent that is the source', () => {+ const targets = transferTargets('custom:a' as AgentId, [], customs)+ const ids = targets.map((t) => t.id)+ expect(ids).not.toContain('custom:a')+ expect(ids).toContain('custom:b')+ // builtins still present+ expect(ids).toContain('claude')+ })++ it('excludes disabled custom agents', () => {+ const targets = transferTargets('claude' as AgentId, ['custom:b'], customs)+ const ids = targets.map((t) => t.id)+ expect(ids).not.toContain('custom:b')+ expect(ids).toContain('custom:a')+ })+})++describe('transferConversationItems', () => {+ const handler = () => {}++ it('returns the label + one item per target for a transfer-capable agent with a session', () => {+ const items = transferConversationItems(+ 'node-1',+ undefined,+ {+ sourceAgentId: 'claude' as AgentId,+ sessionId: 'sess-1',+ disabledAgents: [],+ customAgents: customs+ },+ handler+ )+ expect(items.length).toBeGreaterThan(1)+ expect(items[0]).toMatchObject({ type: 'label', label: 'Transfer conversation to' })+ })++ it('returns [] when the agent is not transfer-capable', () => {+ const items = transferConversationItems(+ 'node-1',+ undefined,+ { sourceAgentId: 'grok' as AgentId, sessionId: 'sess-1', disabledAgents: [], customAgents: [] },+ handler+ )+ expect(items).toEqual([])+ })++ it('returns [] when there is no session id yet', () => {+ const items = transferConversationItems(+ 'node-1',+ undefined,+ { sourceAgentId: 'claude' as AgentId, sessionId: undefined, disabledAgents: [], customAgents: [] },+ handler+ )+ expect(items).toEqual([])+ })++ it('returns [] when sourceAgentId is undefined (not an agent node)', () => {+ const items = transferConversationItems(+ 'node-1',+ undefined,+ { sourceAgentId: undefined, sessionId: 'sess-1', disabledAgents: [], customAgents: [] },+ handler+ )+ expect(items).toEqual([])+ })+})diff --git a/src/renderer/lib/transferItems.tsx b/src/renderer/lib/transferItems.tsxnew file mode 100644index 000000000..e465bf505--- /dev/null+++ b/src/renderer/lib/transferItems.tsx@@ -0,0 +1,86 @@+/**+ * Shared "Transfer conversation to" menu builder.+ *+ * Previously the transfer-target list was built inline inside `selectionItems` in Canvas.tsx (the+ * canvas node right-click menu). The sessions-sidebar row right-click wanted the SAME submenu, so+ * the list-building is extracted here and consumed by both — one definition, two surfaces.+ *+ * `transferTargets` is pure (no React, no stores) so it unit-tests cleanly; the caller reads the+ * live settings/agent-status stores and passes the values in.+ */+import type { AgentId } from '@shared/agents/config'+import { AGENT_CONFIG, BUILTIN_AGENT_IDS, canTransferFrom } from '@shared/agents/config'+import type { CustomAgent } from '@shared/types'+import type { MenuItem } from '../components/ContextMenu'+import { AgentIcon } from './agentIcons'++/** A transfer target: every enabled agent EXCEPT the source (you can't transfer a session to its+ * own agent kind — the handoff is cross-agent). */+export interface TransferTarget {+ id: AgentId+ label: string+}++/**+ * The list of agents a conversation from `sourceAgentId` can be transferred to: every enabled+ * builtin except the source, plus every enabled custom agent except the source. Pure — the caller+ * supplies the live `disabledAgents` list and `customAgents` from settings.+ */+export function transferTargets(+ sourceAgentId: AgentId,+ disabledAgents: readonly AgentId[],+ customAgents: readonly CustomAgent[]+): TransferTarget[] {+ return [+ ...BUILTIN_AGENT_IDS.filter((aid) => aid !== sourceAgentId && !disabledAgents.includes(aid)).map(+ (aid) => ({ id: aid as AgentId, label: AGENT_CONFIG[aid].label })+ ),+ ...customAgents+ .filter((c) => c.id !== sourceAgentId && !disabledAgents.includes(c.id))+ .map((c) => ({ id: c.id, label: c.label }))+ ]+}++/** The args a caller has already resolved for a node; the builder does no store reads itself. */+export interface TransferConversationArgs {+ /** The node's agent (`agentIdOf(nodeId)`), or `undefined` if it isn't an agent node. */+ sourceAgentId: AgentId | undefined+ /** The node's live session id from the agent-status store, or `undefined` if not yet known. */+ sessionId: string | undefined+ /** Live settings lists. */+ disabledAgents: readonly AgentId[]+ customAgents: readonly CustomAgent[]+}++/**+ * Build the "Transfer conversation to" menu block (a label + one item per target), or `[]` when+ * the node can't be a transfer source (not a transfer-capable agent, or no session id yet).+ *+ * @param nodeId the source node — passed to `handler` as the first arg.+ * @param at cursor position (passed through to the handler, which places the new node).+ * @param args the resolved gate values (see {@link TransferConversationArgs}).+ * @param handler Canvas's `transferConversation(sourceNodeId, targetAgentId, at?)`.+ */+export function transferConversationItems(+ nodeId: string,+ at: { x: number; y: number } | undefined,+ args: TransferConversationArgs,+ handler: (sourceNodeId: string, targetAgentId: AgentId, at?: { x: number; y: number }) => void+): MenuItem[] {+ const { sourceAgentId, sessionId, disabledAgents, customAgents } = args+ // Gate: single node, a transfer-capable agent, and a live session id (the handoff reads the+ // transcript by session id — no id means the conversation isn't ready to hand off yet).+ if (!sourceAgentId || !sessionId || !canTransferFrom(sourceAgentId)) return []+ const targets = transferTargets(sourceAgentId, disabledAgents, customAgents)+ if (targets.length === 0) return []+ return [+ { type: 'label', label: 'Transfer conversation to' },+ ...targets.map(+ (tg): MenuItem => ({+ label: tg.label,+ icon: <AgentIcon agentId={tg.id} />,+ onClick: () => void handler(nodeId, tg.id, at)+ })+ )+ ]+}