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(canvas): floating edge — route every edge between nearest node borders
enes48197b186aa9
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 50ff0f590..0fff52220 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -37,6 +37,7 @@ import {subscribeSessionReady} from '../nodes/TerminalNode'import { solveFitPadding } from './fit-view'+import { FloatingEdge } from './FloatingEdge'import { MacWheelGestureRouter, trackpadRoutingEnabled } from './wheel-gesture'import { isBrowserRuntime } from '@renderer/bridge/runtime'import { WheelZoomBurstLimiter, clampWheelZoomSpeed, nextWheelZoom } from './wheel-zoom'@@ -747,6 +748,9 @@ const ropeEdge = (id: string, source: string, target: string, color: string): EdmarkerEnd: { type: MarkerType.ArrowClosed, color, width: 14, height: 14 }})+/** The one edge renderer — every family routes between nearest borders (see FloatingEdge). */+const edgeTypes = { floating: FloatingEdge }+const minimapNodeColor = (n: Node): string =>(n.data as { color?: string })?.color ?? '#0a84ff'@@ -12492,6 +12496,7 @@ export function Canvas() {nodes={allNodes}edges={displayEdges}nodeTypes={nodeTypes}+ edgeTypes={edgeTypes}onNodesChange={handleNodesChange}onEdgesChange={handleEdgesChange}onConnect={onConnect}diff --git a/src/renderer/canvas/FloatingEdge.tsx b/src/renderer/canvas/FloatingEdge.tsxnew file mode 100644index 000000000..9013a7ee3--- /dev/null+++ b/src/renderer/canvas/FloatingEdge.tsx@@ -0,0 +1,63 @@+// The canvas's ONE edge type. Reads both nodes' absolute rectangles from React Flow's internals+// (so nodes inside group frames resolve correctly) and draws a bezier between their nearest+// borders — see lib/floatingEdge.ts. An UNMEASURED node draws nothing this frame: React Flow's+// internals report a 0×0 rectangle for the first tick after mount, and a path drawn from it would+// point at the node's top-left corner, or at the origin.+import { BaseEdge, getBezierPath, useInternalNode, type EdgeProps } from '@xyflow/react'+import { floatingEdgeParams, type Rect } from '../lib/floatingEdge'++function rectOf(n: ReturnType<typeof useInternalNode>): Rect | null {+ if (!n) return null+ const width = n.measured?.width ?? 0+ const height = n.measured?.height ?? 0+ if (!(width > 0) || !(height > 0)) return null+ return { x: n.internals.positionAbsolute.x, y: n.internals.positionAbsolute.y, width, height }+}++export function FloatingEdge(props: EdgeProps) {+ const {+ id,+ source,+ target,+ style,+ markerEnd,+ markerStart,+ label,+ labelStyle,+ labelShowBg,+ labelBgStyle,+ labelBgPadding,+ labelBgBorderRadius,+ interactionWidth+ } = props+ const a = rectOf(useInternalNode(source))+ const b = rectOf(useInternalNode(target))+ if (!a || !b) return null+ const p = floatingEdgeParams(a, b)+ const [path, labelX, labelY] = getBezierPath({+ sourceX: p.sx,+ sourceY: p.sy,+ sourcePosition: p.sourcePosition,+ targetX: p.tx,+ targetY: p.ty,+ targetPosition: p.targetPosition+ })+ return (+ <BaseEdge+ id={id}+ path={path}+ style={style}+ markerEnd={markerEnd}+ markerStart={markerStart}+ label={label}+ labelX={labelX}+ labelY={labelY}+ labelStyle={labelStyle}+ labelShowBg={labelShowBg}+ labelBgStyle={labelBgStyle}+ labelBgPadding={labelBgPadding}+ labelBgBorderRadius={labelBgBorderRadius}+ interactionWidth={interactionWidth}+ />+ )+}diff --git a/src/renderer/lib/floatingEdge.test.ts b/src/renderer/lib/floatingEdge.test.tsnew file mode 100644index 000000000..7c468abbd--- /dev/null+++ b/src/renderer/lib/floatingEdge.test.ts@@ -0,0 +1,52 @@+import { describe, it, expect } from 'vitest'+import { Position } from '@xyflow/react'+import { borderExit, floatingEdgeParams, type Rect } from './floatingEdge'++const box = (x: number, y: number, width = 100, height = 50): Rect => ({ x, y, width, height })++describe('borderExit — where the centre-to-centre line leaves a rectangle', () => {+ it('exits the RIGHT side toward a point to the right', () => {+ expect(borderExit(box(0, 0), { x: 500, y: 25 })).toEqual({ x: 100, y: 25, position: Position.Right })+ })+ it('exits the LEFT side toward a point to the left', () => {+ expect(borderExit(box(0, 0), { x: -500, y: 25 })).toEqual({ x: 0, y: 25, position: Position.Left })+ })+ it('exits the BOTTOM toward a point below', () => {+ expect(borderExit(box(0, 0), { x: 50, y: 500 })).toEqual({ x: 50, y: 50, position: Position.Bottom })+ })+ it('exits the TOP toward a point above', () => {+ expect(borderExit(box(0, 0), { x: 50, y: -500 })).toEqual({ x: 50, y: 0, position: Position.Top })+ })+ it('a diagonal target exits the side the line actually crosses (wide box → left/right)', () => {+ // centre (50,25); toward (250,125): dx=200, dy=100 → |dx|/w=4 > |dy|/h=4? equal → right wins.+ const e = borderExit(box(0, 0), { x: 250, y: 125 })+ expect(e.position).toBe(Position.Right)+ expect(e.x).toBe(100)+ expect(e.y).toBeCloseTo(50)+ })+ it('a coincident centre (overlapping nodes) degrades to the right side, never NaN', () => {+ const e = borderExit(box(0, 0), { x: 50, y: 25 })+ expect(Number.isFinite(e.x) && Number.isFinite(e.y)).toBe(true)+ expect(e.position).toBe(Position.Right)+ })+ it('a zero-size rectangle answers its own origin', () => {+ expect(borderExit({ x: 10, y: 20, width: 0, height: 0 }, { x: 99, y: 99 })).toEqual({ x: 10, y: 20, position: Position.Right })+ })+})++describe('floatingEdgeParams — both ends, facing each other', () => {+ it('a node left of another: source exits right, target enters left', () => {+ const p = floatingEdgeParams(box(0, 0), box(400, 0))+ expect(p).toEqual({ sx: 100, sy: 25, sourcePosition: Position.Right, tx: 400, ty: 25, targetPosition: Position.Left })+ })+ it('a node ABOVE another (the case the fixed handles got wrong): bottom → top, no loop', () => {+ const p = floatingEdgeParams(box(0, 0), box(0, 300))+ expect(p.sourcePosition).toBe(Position.Bottom)+ expect(p.targetPosition).toBe(Position.Top)+ })+ it('a target to the upper-left exits the source on its left/top side, not its right', () => {+ const p = floatingEdgeParams(box(1000, 1000), box(0, 0))+ expect([Position.Left, Position.Top]).toContain(p.sourcePosition)+ expect([Position.Right, Position.Bottom]).toContain(p.targetPosition)+ })+})diff --git a/src/renderer/lib/floatingEdge.ts b/src/renderer/lib/floatingEdge.tsnew file mode 100644index 000000000..f9ecad2ad--- /dev/null+++ b/src/renderer/lib/floatingEdge.ts@@ -0,0 +1,57 @@+// Pure geometry for the canvas's one edge type. An edge is drawn between the two points where the+// centre-to-centre line leaves each node's rectangle, so it always takes the short way round — the+// fixed-side handles it replaces sent an edge to a node placed left of (or above) its source on a+// loop across the whole canvas, with its label drifting into empty space.+import { Position } from '@xyflow/react'++export interface Rect {+ x: number+ y: number+ width: number+ height: number+}++export interface EdgeEnd {+ x: number+ y: number+ position: Position+}++/**+ * The point on `from`'s border where the line from its centre toward `toward` exits, and the side+ * it exits on. A degenerate rectangle (unmeasured) or a coincident centre answers deterministically+ * (its own point, `Right`) — never NaN, so a path is always drawable.+ */+export function borderExit(from: Rect, toward: { x: number; y: number }): EdgeEnd {+ const hw = from.width / 2+ const hh = from.height / 2+ const cx = from.x + hw+ const cy = from.y + hh+ if (!(hw > 0) || !(hh > 0)) return { x: from.x, y: from.y, position: Position.Right }+ const dx = toward.x - cx+ const dy = toward.y - cy+ if (dx === 0 && dy === 0) return { x: cx + hw, y: cy, position: Position.Right }+ // Compare the slopes against the corner: |dx|/hw vs |dy|/hh decides which side the line crosses.+ if (Math.abs(dx) * hh >= Math.abs(dy) * hw) {+ const sx = dx >= 0 ? 1 : -1+ return { x: cx + sx * hw, y: cy + dy * (hw / Math.abs(dx)), position: sx > 0 ? Position.Right : Position.Left }+ }+ const sy = dy >= 0 ? 1 : -1+ return { x: cx + dx * (hh / Math.abs(dy)), y: cy + sy * hh, position: sy > 0 ? Position.Bottom : Position.Top }+}++export interface FloatingParams {+ sx: number+ sy: number+ sourcePosition: Position+ tx: number+ ty: number+ targetPosition: Position+}++export function floatingEdgeParams(a: Rect, b: Rect): FloatingParams {+ const centre = (r: Rect) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 })+ const s = borderExit(a, centre(b))+ const t = borderExit(b, centre(a))+ return { sx: s.x, sy: s.y, sourcePosition: s.position, tx: t.x, ty: t.y, targetPosition: t.position }+}