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(worktree): new terminals inherit group worktree cwd + header chip + unbind
enese51f8c163183
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 4b671d80a..0a7139fac 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -17,7 +17,7 @@ import {import type { Edge, Node } from '@xyflow/react'import { TerminalNode } from '../nodes/TerminalNode'import { StickyNode } from '../nodes/StickyNode'-import { GroupNode } from '../nodes/GroupNode'+import { GroupNode, setWorktreeActionHandler } from '../nodes/GroupNode'import { EditorNode } from '../nodes/EditorNode'import { DiffNode } from '../nodes/DiffNode'import { withNodeBoundary } from '../components/NodeBoundary'@@ -672,16 +672,37 @@ export function Canvas() {return screenToFlowPosition({ x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 })}, [screenToFlowPosition])+ // cwd for a node being created INTO a group: prefer the group's bound worktree path,+ // then its default cwd, else undefined (caller falls back to the project cwd).+ const cwdForNewNodeIn = useCallback((parentId: string | undefined): string | undefined => {+ if (!parentId) return undefined+ const parent = nodesRef.current.find((n) => n.id === parentId)+ return parent?.data.worktree?.path || parent?.data.cwd || undefined+ }, [])++ // Reparent a freshly-created node into a group (parentId + extent 'parent', position made+ // relative to the group frame). Mirrors how `groupSelectedNodes` parents its children.+ const parentInto = useCallback((node: CanvasNode, groupId: string): CanvasNode => {+ const group = nodesRef.current.find((n) => n.id === groupId)+ if (!group) return node+ return {+ ...node,+ parentId: groupId,+ extent: 'parent' as const,+ position: { x: node.position.x - group.position.x, y: node.position.y - group.position.y }+ }+ }, [])+const addTerminal = useCallback(- (center?: { x: number; y: number }, initialCommand?: string) => {- const cwd = useProjects.getState().getProject(activeProjectId)?.cwd- setNodes((ns) => [- ...ns,- createTerminalNode(ns.length, cwd, center ?? viewCenter(), initialCommand)- ])+ (center?: { x: number; y: number }, initialCommand?: string, groupId?: string) => {+ const cwd = cwdForNewNodeIn(groupId) ?? useProjects.getState().getProject(activeProjectId)?.cwd+ setNodes((ns) => {+ const node = createTerminalNode(ns.length, cwd, center ?? viewCenter(), initialCommand)+ return [...ns, groupId ? parentInto(node, groupId) : node]+ })markDirty()},- [setNodes, markDirty, activeProjectId, viewCenter]+ [setNodes, markDirty, activeProjectId, viewCenter, cwdForNewNodeIn, parentInto])/** Open a new terminal that runs a command on start (e.g. gh auth login). */@@ -793,12 +814,15 @@ export function Canvas() {)const addAgentNode = useCallback(- (agentId: AgentId, center?: { x: number; y: number }) => {- const cwd = useProjects.getState().getProject(activeProjectId)?.cwd- setNodes((ns) => [...ns, createAgentNode(agentId, ns.length, cwd, center ?? viewCenter())])+ (agentId: AgentId, center?: { x: number; y: number }, groupId?: string) => {+ const cwd = cwdForNewNodeIn(groupId) ?? useProjects.getState().getProject(activeProjectId)?.cwd+ setNodes((ns) => {+ const node = createAgentNode(agentId, ns.length, cwd, center ?? viewCenter())+ return [...ns, groupId ? parentInto(node, groupId) : node]+ })markDirty()},- [setNodes, markDirty, activeProjectId, viewCenter]+ [setNodes, markDirty, activeProjectId, viewCenter, cwdForNewNodeIn, parentInto])// ⌘T = new terminal, ⌘⇧C = new default agent (ignored while typing in a field/terminal).@@ -986,6 +1010,34 @@ export function Canvas() {[bindTarget, setNodes, markDirty])+ // Worktree action dispatcher for GroupNode's header chip. Structured as a switch so the+ // merge / remove teardown actions (Tasks 8 & 9) slot in as new cases. For now only+ // `unbind` is handled: forget the worktree binding without touching the on-disk worktree.+ const onWorktreeAction = useCallback(+ (groupId: string, action: 'merge' | 'remove' | 'unbind') => {+ switch (action) {+ case 'unbind':+ setNodes((ns) =>+ ns.map((n) =>+ n.id === groupId ? { ...n, data: { ...n.data, worktree: undefined } } : n+ )+ )+ markDirty()+ break+ // 'merge' (Task 8) and 'remove' (Task 9) are wired separately.+ default:+ break+ }+ },+ [setNodes, markDirty]+ )++ // Bridge the worktree-action handler to GroupNode (which React Flow instantiates itself).+ useEffect(() => {+ setWorktreeActionHandler(onWorktreeAction)+ return () => setWorktreeActionHandler(null)+ }, [onWorktreeAction])+const toggleMarkdown = useCallback((ids: string[]) => {const set = new Set(ids)@@ -1293,6 +1345,11 @@ export function Canvas() {const groupItems = useCallback((groupId: string): MenuItem[] => [{ type: 'label', label: 'Group' },+ {+ label: 'New terminal in group',+ icon: <IconTerminal />,+ onClick: () => addTerminal(undefined, undefined, groupId)+ },{ type: 'colors', onPick: (c) => setNodesColor([groupId], c) },{ type: 'separator' },...(groupHasWorktree(groupId)@@ -1307,7 +1364,7 @@ export function Canvas() {{ label: 'Ungroup', icon: <IconUngroup />, onClick: () => ungroup(groupId) },{ label: 'Delete (keeps nodes)', icon: <IconTrash />, danger: true, onClick: () => ungroup(groupId) }],- [setNodesColor, ungroup, groupHasWorktree, bindGroupToWorktree]+ [setNodesColor, ungroup, groupHasWorktree, bindGroupToWorktree, addTerminal])const onPaneContextMenu = useCallback(diff --git a/src/renderer/nodes/GroupNode.tsx b/src/renderer/nodes/GroupNode.tsxindex 47425acbe..58af83a14 100644--- a/src/renderer/nodes/GroupNode.tsx+++ b/src/renderer/nodes/GroupNode.tsx@@ -2,6 +2,21 @@ import { useState } from 'react'import { NodeResizer, useReactFlow, type NodeProps } from '@xyflow/react'import { NODE_COLORS, ungroupNodes, type CanvasNode } from '../state/workspace'+export type WorktreeAction = 'merge' | 'remove' | 'unbind'++/**+ * Worktree-action handler bridge. React Flow instantiates custom nodes itself, so we can't+ * pass Canvas callbacks through props; Canvas registers its handler here (the same indirection+ * the file already relies on — GroupNode reaches React Flow state via `useReactFlow`). Set by+ * Canvas on mount; called by the header chip's action buttons.+ */+let worktreeActionHandler: ((groupId: string, action: WorktreeAction) => void) | null = null+export function setWorktreeActionHandler(+ fn: ((groupId: string, action: WorktreeAction) => void) | null+): void {+ worktreeActionHandler = fn+}+/*** A group frame: a dashed, rounded, translucent box that contains child nodes. A floating* label pill (color dot + name) sits on the top border; ungroup/× appear top-right on hover.@@ -59,6 +74,20 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {spellCheck={false}onChange={(e) => updateNodeData(id, { title: e.target.value })}/>+ {data.worktree && (+ <div className="group-node__wt nodrag">+ <span className="group-node__branch" title={data.worktree.path}>+ ⎇ {data.worktree.branch}+ </span>+ <button+ className="group-node__wt-btn"+ title="Unbind worktree (keeps the worktree on disk)"+ onClick={() => worktreeActionHandler?.(id, 'unbind')}+ >+ Unbind+ </button>+ </div>+ )}</div><div className="group-node__actions nodrag">diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 732d0634f..74162117f 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -2963,7 +2963,7 @@ body,display: inline-flex;align-items: center;gap: 7px;- max-width: 70%;+ max-width: 90%;padding: 3px 11px;background: #141416;border: 1px solid var(--border);@@ -2992,6 +2992,39 @@ body,cursor: text;}+/* Worktree binding chip — branch name + Unbind, shown in the label pill when bound. */+.group-node__wt {+ display: inline-flex;+ align-items: center;+ gap: 6px;+ flex: none;+}++.group-node__branch {+ max-width: 140px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ font-size: 11px;+ font-weight: 600;+ color: var(--accent);+}++.group-node__wt-btn {+ background: #141416;+ border: 1px solid var(--border);+ color: var(--muted);+ border-radius: 7px;+ font-size: 11px;+ padding: 2px 7px;+ cursor: pointer;+}++.group-node__wt-btn:hover {+ background: var(--panel-header);+ color: var(--text);+}+/* ungroup / × — top-right, revealed on hover or when selected. */.group-node__actions {position: absolute;