Skip to content

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.

fix(canvas): restore the live height when a collapsed node expands

Ara Babigian801fddeac021
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 830742bef..0291a1794 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -832,7 +832,7 @@ import {
applyMutationToFlow,
agentLaunchOverride,
claudeLaunchCommand,
- COLLAPSED_HEIGHT,
+ toggleCollapsed,
alignNodes,
arrangeByLineage,
arrangeGroupChildren,
@@ -9308,22 +9308,7 @@ export function Canvas() {
const toggleCollapseNodes = useCallback(
(ids: string[]) => {
- const set = new Set(ids)
- setNodes((ns) =>
- ns.map((n) => {
- if (!set.has(n.id)) return n
- const next = !n.data.collapsed
- const expandedHeight =
- (n.data.expandedHeight as number) ?? n.measured?.height ?? (n.height as number) ?? 300
- const height = next ? COLLAPSED_HEIGHT : expandedHeight
- return {
- ...n,
- height,
- style: { ...n.style, height },
- data: { ...n.data, collapsed: next, expandedHeight }
- }
- })
- )
+ setNodes((ns) => toggleCollapsed(ns, ids))
markDirty()
},
[setNodes, markDirty]
diff --git a/src/renderer/nodes/FilesNode.tsx b/src/renderer/nodes/FilesNode.tsx
index 0ccb64a40..9af2101f8 100644
--- a/src/renderer/nodes/FilesNode.tsx
+++ b/src/renderer/nodes/FilesNode.tsx
@@ -29,7 +29,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { NodeResizer, useReactFlow, type NodeProps } from '@xyflow/react'
import type { DirEntry } from '@shared/types'
import { NODE_MIN_SIZES } from '../lib/nodeSizing'
-import { COLLAPSED_HEIGHT, type CanvasNode } from '../state/workspace'
+import { toggleCollapsed, type CanvasNode } from '../state/workspace'
import { NodeColorSwatches } from '../components/NodeColorSwatches'
import {
breadcrumbs,
@@ -374,22 +374,7 @@ export function FilesNode({ id, data, selected }: NodeProps<CanvasNode>) {
[cwd, open, create, api, localShell, source, route, rowDl, download, downloadTo]
)
- const toggleCollapse = () =>
- setNodes((ns) =>
- ns.map((n) => {
- if (n.id !== id) return n
- const next = !n.data.collapsed
- const expandedHeight =
- (n.data.expandedHeight as number) ?? n.measured?.height ?? (n.height as number) ?? 460
- const height = next ? COLLAPSED_HEIGHT : expandedHeight
- return {
- ...n,
- height,
- style: { ...n.style, height },
- data: { ...n.data, collapsed: next, expandedHeight }
- }
- })
- )
+ const toggleCollapse = () => setNodes((ns) => toggleCollapsed(ns as CanvasNode[], [id]))
const shown = useMemo(() => filterEntries(entries ?? [], query), [entries, query])
const selectedName = sel && sel.cwd === cwd ? sel.name : null
diff --git a/src/renderer/nodes/StickyNode.tsx b/src/renderer/nodes/StickyNode.tsx
index 090ae9221..430e977c2 100644
--- a/src/renderer/nodes/StickyNode.tsx
+++ b/src/renderer/nodes/StickyNode.tsx
@@ -3,7 +3,7 @@ import { Tooltip } from '../components/Tooltip'
import { IconChevronDown, IconChevronRight, IconClose } from '../components/icons'
import { Handle, NodeResizer, Position, useReactFlow, type NodeProps } from '@xyflow/react'
import { NODE_MIN_SIZES } from '../lib/nodeSizing'
-import { COLLAPSED_HEIGHT, type CanvasNode } from '../state/workspace'
+import { toggleCollapsed, type CanvasNode } from '../state/workspace'
import { NodeColorSwatches } from '../components/NodeColorSwatches'
import { ColumnPill } from '../components/kanban/ColumnPill'
import { NoteMarkdown } from '../components/NoteMarkdown'
@@ -47,22 +47,7 @@ export function StickyNode({ id, data, selected }: NodeProps<CanvasNode>) {
return () => clearInterval(t)
}, [stampAt])
- const toggleCollapse = () =>
- setNodes((ns) =>
- ns.map((n) => {
- if (n.id !== id) return n
- const next = !n.data.collapsed
- const expandedHeight =
- (n.data.expandedHeight as number) ?? n.measured?.height ?? (n.height as number) ?? 200
- const height = next ? COLLAPSED_HEIGHT : expandedHeight
- return {
- ...n,
- height,
- style: { ...n.style, height },
- data: { ...n.data, collapsed: next, expandedHeight }
- }
- })
- )
+ const toggleCollapse = () => setNodes((ns) => toggleCollapsed(ns as CanvasNode[], [id]))
return (
<>
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index b28cbd501..84ac94dce 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -280,7 +280,7 @@ import { isHostedReadOnly, useHostedReadOnly } from '../state/hostedTeams'
import { isBrowserRuntime } from '../bridge/runtime'
import { liveLinkUnavailable } from '../lib/liveLinkEntry'
import { useWatchLinks } from '../state/watchLinks'
-import { agentLaunchOverride, COLLAPSED_HEIGHT, type CanvasNode } from '../state/workspace'
+import { agentLaunchOverride, toggleCollapsed, type CanvasNode } from '../state/workspace'
import { NodeColorSwatches } from '../components/NodeColorSwatches'
import { AccountChip, useAccountChip } from '../components/AccountChip'
import { IssueRefChip } from '../components/IssueRefChip'
@@ -5544,22 +5544,7 @@ export function TerminalNode({
// the node whose own membership flipped, and every OTHER terminal is the one being covered.
useEffect(() => subscribeFocusedNode(() => applyFitRef.current?.()), [])
- const toggleCollapse = () =>
- setNodes((ns) =>
- ns.map((n) => {
- if (n.id !== id) return n
- const next = !n.data.collapsed
- const expandedHeight =
- (n.data.expandedHeight as number) ?? n.measured?.height ?? (n.height as number) ?? 300
- const height = next ? COLLAPSED_HEIGHT : expandedHeight
- return {
- ...n,
- height,
- style: { ...n.style, height },
- data: { ...n.data, collapsed: next, expandedHeight }
- }
- })
- )
+ const toggleCollapse = () => setNodes((ns) => toggleCollapsed(ns as CanvasNode[], [id]))
// ---- hover guard: dwell before entering the terminal ----
/**
diff --git a/src/renderer/state/workspace.collapse.test.ts b/src/renderer/state/workspace.collapse.test.ts
new file mode 100644
index 000000000..c45479430
--- /dev/null
+++ b/src/renderer/state/workspace.collapse.test.ts
@@ -0,0 +1,44 @@
+import { describe, it, expect } from 'vitest'
+import { COLLAPSED_HEIGHT, toggleCollapsed } from './workspace'
+import type { CanvasNode } from './workspace'
+
+const node = (type: string, height: number, extra: Partial<CanvasNode['data']> = {}): CanvasNode =>
+ ({
+ id: 'a',
+ type,
+ position: { x: 0, y: 0 },
+ width: 320,
+ height,
+ measured: { width: 320, height },
+ style: { width: 320, height },
+ data: { title: 'a', color: '#fff', group: null, ...extra }
+ }) as CanvasNode
+
+describe('toggleCollapsed', () => {
+ it('records the LIVE height on collapse, not the stale load-time expandedHeight', () => {
+ // Hydration stamps expandedHeight at load; the user then resized 440 -> 800.
+ const resized = node('terminal', 800, { expandedHeight: 440 })
+ const collapsed = toggleCollapsed([resized], ['a'])[0]
+ expect(collapsed.data.collapsed).toBe(true)
+ expect(collapsed.height).toBe(COLLAPSED_HEIGHT)
+ expect(collapsed.data.expandedHeight).toBe(800)
+ // React Flow re-measures the collapsed bar; expand must still restore the recorded size.
+ const measuredBar = { ...collapsed, measured: { width: 320, height: COLLAPSED_HEIGHT } }
+ const expanded = toggleCollapsed([measuredBar], ['a'])[0]
+ expect(expanded.data.collapsed).toBe(false)
+ expect(expanded.height).toBe(800)
+ expect(expanded.style).toMatchObject({ height: 800 })
+ })
+
+ 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 CanvasNode
+ expect(toggleCollapsed([bare], ['a'])[0].data.expandedHeight).toBe(h)
+ }
+ })
+
+ it('leaves nodes outside ids untouched', () => {
+ const n = node('terminal', 300)
+ expect(toggleCollapsed([n], ['other'])[0]).toBe(n)
+ })
+})
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 4b4fa3641..7189e2f41 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -75,6 +75,33 @@ const FILES_SIZE = { width: 340, height: 460 }
/** Height of a node when collapsed (header only). */
export const COLLAPSED_HEIGHT = 40
+/**
+ * Flip `collapsed` on every node in `ids`. 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
+ const next = !n.data.collapsed
+ const live = n.measured?.height ?? (n.height as number | undefined)
+ const stored = n.data.expandedHeight as number | undefined
+ const expandedHeight =
+ (next ? live ?? stored : stored ?? live) ?? COLLAPSED_FALLBACK_HEIGHT[n.type ?? 'terminal'] ?? 300
+ const height = next ? COLLAPSED_HEIGHT : expandedHeight
+ return {
+ ...n,
+ height,
+ style: { ...n.style, height },
+ data: { ...n.data, collapsed: next, expandedHeight }
+ }
+ })
+}
+/** Height when a node has neither a measurement nor a recorded size — the per-kind values the four
+ * toggles this replaced each used. */
+const COLLAPSED_FALLBACK_HEIGHT: Partial<Record<string, number>> = { terminal: 300, sticky: 200, files: 460 }
+
/** User data carried in the React Flow node's data field. */
export interface NodeData {
title: string