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(canvas): offer Collapse / Expand only on nodes that can collapse
Ara Babigiand2b8768688e7
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 0291a1794..a5ba5ca39 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -833,6 +833,7 @@ import {agentLaunchOverride,claudeLaunchCommand,toggleCollapsed,+ canToggleCollapse,alignNodes,arrangeByLineage,arrangeGroupChildren,@@ -10514,7 +10515,11 @@ export function Canvas() {}] as MenuItem[]): []),- ...(isHidden('collapse', hidden)+ ...(isHidden('collapse', hidden) ||+ !ids.some((nid) => {+ const n = nodesRef.current.find((nd) => nd.id === nid)+ return !!n && canToggleCollapse(n)+ })? []: ([{diff --git a/src/renderer/canvas/collapse-menu-wiring.test.ts b/src/renderer/canvas/collapse-menu-wiring.test.tsnew file mode 100644index 000000000..c3fa690bd--- /dev/null+++ b/src/renderer/canvas/collapse-menu-wiring.test.ts@@ -0,0 +1,23 @@+// Canvas has no render harness, so the Collapse / Expand menu gate is pinned at its call site: the+// row must be offered only for nodes the toggle may act on (canToggleCollapse — collapsible kinds,+// plus any node already collapsed so a legacy one can still expand), and the toggle must go+// through the shared toggleCollapsed. Without the gate, a group frame or editor in a+// multi-selection is squashed to the 40px collapsed bar with its content crushed.+import fs from 'node:fs'+import path from 'node:path'+import { describe, expect, it } from 'vitest'++const SRC = fs.readFileSync(path.join(__dirname, 'Canvas.tsx'), 'utf8').replace(/\r\n/g, '\n')++describe('Collapse / Expand menu wiring', () => {+ it('gates the row on canToggleCollapse over the targets', () => {+ const row = SRC.indexOf("label: 'Collapse / Expand'")+ expect(row).toBeGreaterThan(-1)+ const gate = SRC.slice(SRC.lastIndexOf("isHidden('collapse', hidden)", row), row)+ expect(gate).toMatch(/!ids\.some\(\(nid\) => \{[\s\S]*canToggleCollapse\(n\)/)+ })++ it('toggles through the shared helper', () => {+ expect(SRC).toMatch(/const toggleCollapseNodes = useCallback\(\s*\(ids: string\[\]\) => \{\s*setNodes\(\(ns\) => toggleCollapsed\(ns, ids\)\)/)+ })+})diff --git a/src/renderer/state/workspace.collapse.test.ts b/src/renderer/state/workspace.collapse.test.tsindex c45479430..bcc0a762c 100644--- a/src/renderer/state/workspace.collapse.test.ts+++ b/src/renderer/state/workspace.collapse.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { COLLAPSED_HEIGHT, toggleCollapsed } from './workspace'+import { canToggleCollapse, COLLAPSED_HEIGHT, isCollapsible, toggleCollapsed } from './workspace'import type { CanvasNode } from './workspace'const node = (type: string, height: number, extra: Partial<CanvasNode['data']> = {}): CanvasNode =>@@ -30,6 +30,25 @@ describe('toggleCollapsed', () => {expect(expanded.style).toMatchObject({ height: 800 })})+ it('only collapses kinds that render a collapsed state', () => {+ for (const kind of ['terminal', 'sticky', 'files'] as const) expect(isCollapsible({ type: kind })).toBe(true)+ for (const kind of ['group', 'editor', 'diff', 'browser', 'web', 'video', 'dino', 'trigger'] as const) {+ expect(isCollapsible({ type: kind })).toBe(false)+ const n = node(kind, 300)+ expect(toggleCollapsed([n], ['a'])[0]).toBe(n)+ }+ })++ it('still EXPANDS a non-collapsible kind an older build saved collapsed, and never re-collapses it', () => {+ const legacy = { ...node('editor', COLLAPSED_HEIGHT, { collapsed: true, expandedHeight: 460 }) }+ expect(canToggleCollapse(legacy)).toBe(true)+ const expanded = toggleCollapsed([legacy], ['a'])[0]+ expect(expanded.data.collapsed).toBe(false)+ expect(expanded.height).toBe(460)+ expect(canToggleCollapse(expanded)).toBe(false)+ expect(toggleCollapsed([expanded], ['a'])[0]).toBe(expanded)+ })+it('falls back to the per-kind height when a node has no size at all', () => {for (const [kind, h] of [['terminal', 300], ['sticky', 200], ['files', 460]] as const) {const bare = { ...node(kind, 0), height: undefined, measured: undefined } as CanvasNodediff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 7189e2f41..722d9c45a 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -75,15 +75,27 @@ const FILES_SIZE = { width: 340, height: 460 }/** Height of a node when collapsed (header only). */export const COLLAPSED_HEIGHT = 40+/** The node kinds that render a header-only collapsed state. Any other kind squashed to+ * COLLAPSED_HEIGHT crushes its content (a group frame strands its children outside it), so+ * neither the menu nor the toggle offers collapse to them. */+export const COLLAPSIBLE_KINDS: ReadonlySet<string> = new Set(['terminal', 'sticky', 'files'])+export const isCollapsible = (n: Pick<CanvasNode, 'type'>): boolean =>+ COLLAPSIBLE_KINDS.has(n.type ?? 'terminal')+/** Whether the collapse toggle may act on `n`: a collapsible kind either way, or ANY node that is+ * already collapsed — an older build collapsed every kind, and such a node must still expand. */+export const canToggleCollapse = (n: Pick<CanvasNode, 'type' | 'data'>): boolean =>+ isCollapsible(n) || !!n.data.collapsed+/**- * Flip `collapsed` on every node in `ids`. Collapsing records the LIVE height (a user+ * Flip `collapsed` on every node in `ids` the toggle may act on (`canToggleCollapse`): a+ * non-collapsible kind is only ever EXPANDED. Collapsing records the LIVE height (a user* resize never writes `expandedHeight`, so the stored value can be the load-time size); expanding* gives back what was recorded.*/export function toggleCollapsed(nodes: CanvasNode[], ids: Iterable<string>): CanvasNode[] {const set = new Set(ids)return nodes.map((n) => {- if (!set.has(n.id)) return n+ if (!set.has(n.id) || !canToggleCollapse(n)) return nconst next = !n.data.collapsedconst live = n.measured?.height ?? (n.height as number | undefined)const stored = n.data.expandedHeight as number | undefined