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): clamp maximize and zone snaps to the node's minimum size
Ara Babigianed31e8f4cad2
diff --git a/src/renderer/state/workspace.maximize.test.ts b/src/renderer/state/workspace.maximize.test.tsindex 239a7b897..920c14750 100644--- a/src/renderer/state/workspace.maximize.test.ts+++ b/src/renderer/state/workspace.maximize.test.ts@@ -9,6 +9,7 @@ import {} from './workspace'import type { CanvasNode } from './workspace'import { maximizeTargetRect } from '../lib/nodeMaximize'+import { NODE_MIN_SIZES } from '../lib/nodeSizing'// Maximize-to-viewport (issue #399): the node is RESIZED to the visible canvas and toggles back// to the exact rect it had — the restore is the half users cannot do by hand, so it is the half@@ -271,3 +272,24 @@ describe('placeNodeInRect (zone snap, issue #394 v1)', () => {expect(placeNodeInRect([term('a', { x: 1, y: 2 })], 'nope', RECT)).toEqual([term('a', { x: 1, y: 2 })])})})++describe('NODE_MIN_SIZES clamp (programmatic resizes bypass the NodeResizer)', () => {+ // A third zone of a zoomed-in viewport is narrower than a terminal's 260 floor.+ const TINY = { x: 10, y: 20, width: 200, height: 100 }++ it('zone snap and maximize never shrink a node below its kind minimum', () => {+ const min = NODE_MIN_SIZES.terminal+ for (const place of [placeNodeInRect, maximizeNodeToRect]) {+ const a = place([term('a', { x: 0, y: 0 })], 'a', TINY)[0]+ expect(a.position).toEqual({ x: 10, y: 20 })+ expect(a.width).toBe(min.width)+ expect(a.height).toBe(min.height)+ expect(a.data.expandedHeight).toBe(min.height)+ }+ })++ it('a clamped maximized node refits idempotently', () => {+ const maxed = maximizeNodeToRect([term('a', { x: 0, y: 0 })], 'a', TINY)+ expect(refitMaximizedNode(maxed, 'a', TINY)).toBe(maxed)+ })+})diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 722d9c45a..4c1ac1050 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -22,7 +22,7 @@ import { agentAccountColor } from '@shared/agents/account-color'import { boundAccountId } from '@shared/agents/account-binding'import { agentEnvSnapshot } from '../lib/agentEnv'import { uuid } from '@renderer/lib/uuid'-import { expandRectToGrid, snapNodeToGrid, type Rect } from '../lib/nodeSizing'+import { expandRectToGrid, NODE_MIN_SIZES, snapNodeToGrid, type Rect } from '../lib/nodeSizing'import { claudeCliCapsNow, grokCliCapsNow } from './permissionMode'import { ensureGrokTakenIds, grokTakenIdsNow } from './grokSessionIds'import { mintFreeGrokSessionId } from '@shared/agents/grok-session-mint'@@ -2109,6 +2109,12 @@ export function placeNodeInRect(return withNodeRect(nodes, node, rect, {})}+/** `rect`'s size raised to the node kind's NodeResizer minimum. */+function clampToMinSize(node: CanvasNode, rect: { width: number; height: number }) {+ const min = NODE_MIN_SIZES[node.type ?? 'terminal'] ?? { width: 0, height: 0 }+ return { width: Math.max(rect.width, min.width), height: Math.max(rect.height, min.height) }+}+/*** The shared placement core: put `node` at the ROOT-space `rect` (converted to parent-relative),* patch its data, and re-fit the ancestor frames in the same transform — `extent:'parent'` would@@ -2126,18 +2132,22 @@ function withNodeRect(const root = rootPosition(node, nodes)const originX = root.x - node.position.xconst originY = root.y - node.position.y+ // A programmatic resize bypasses the NodeResizer's minimums (lib/nodeSizing.ts), and a zone+ // of a zoomed-in viewport is routinely smaller than a kind's floor — clamp here, once, for+ // maximize, zones, refit and restore alike.+ const { width, height } = clampToMinSize(node, rect)const next = nodes.map((n) =>n.id === node.id? {...n,position: { x: rect.x - originX, y: rect.y - originY },- width: rect.width,- height: rect.height,- style: { ...n.style, width: rect.width, height: rect.height },+ width,+ height,+ style: { ...n.style, width, height },// Drop the stale measurement in the same tick: flowToNodeStates prefers `measured` over// `width`/`height`, and a commit racing the re-measure would persist the OLD size.measured: undefined,- data: { ...n.data, expandedHeight: rect.height, ...dataPatch }+ data: { ...n.data, expandedHeight: height, ...dataPatch }}: n)@@ -2172,11 +2182,12 @@ export function refitMaximizedNode(// the node already has. Returning the same array keeps the workspace out of the dirty/save path// and lets the caller decide by identity whether anything actually moved.const root = rootPosition(node, nodes)+ const size = clampToMinSize(node, rect)if (samePx(root.x, rect.x) &&samePx(root.y, rect.y) &&- samePx(nodeW(node) || (node.style?.width as number) || 0, rect.width) &&- samePx(nodeH(node) || (node.style?.height as number) || 0, rect.height)+ samePx(nodeW(node) || (node.style?.width as number) || 0, size.width) &&+ samePx(nodeH(node) || (node.style?.height as number) || 0, size.height)) {return nodes}