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(renderer): LRU count cap (12) on parked terminals
enes7eab76792fdf
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex fcf0a3b76..8ecf5dea7 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -59,6 +59,7 @@ import {} from '../terminal/terminal-config'import { useXtermVisualSettings } from '../terminal/useXtermVisualSettings'import { loseWebglContexts, registerWebglClient, type WebglClientHandle } from '../terminal/webgl-budget'+import { PARK_MAX, planParkEviction } from '../terminal/park-budget'import { attachGlyphGrid, type GlyphGridAttachment } from '../terminal/glyphgrid-attach'import type { GridHandle } from '../glyphgrid/engine'import {@@ -2606,6 +2607,11 @@ export function TerminalNode({}disposeParkedTerminal(termKey) // defensive: never stack two entries for one nodeparkedTerminals.set(termKey, entry)+ // Enforce the park count cap: evict the OLDEST parks (their next remount becomes a warm+ // tmux reattach — the post-window behavior, just earlier). Never the entry just parked.+ for (const k of planParkEviction([...parkedTerminals.keys()], PARK_MAX)) {+ if (k !== termKey) disposeParkedTerminal(k)+ }// A spawn continuation still awaiting its history seed reads this to know the session// survived this unmount (parked, or adopted by a remount) and must be finished, not killed.handedOff = entrydiff --git a/src/renderer/terminal/park-budget.test.ts b/src/renderer/terminal/park-budget.test.tsnew file mode 100644index 000000000..0eebc5b16--- /dev/null+++ b/src/renderer/terminal/park-budget.test.ts@@ -0,0 +1,17 @@+import { describe, it, expect } from 'vitest'+import { PARK_MAX, planParkEviction } from './park-budget'++describe('planParkEviction', () => {+ it('returns nothing at or under the cap', () => {+ expect(planParkEviction(['a', 'b'], 2)).toEqual([])+ expect(planParkEviction([], 2)).toEqual([])+ })+ it('evicts the oldest entries beyond the cap, oldest first', () => {+ expect(planParkEviction(['a', 'b', 'c', 'd'], 2)).toEqual(['a', 'b'])+ })+ it('default cap is 12', () => {+ expect(PARK_MAX).toBe(12)+ const keys = Array.from({ length: 13 }, (_, i) => `k${i}`)+ expect(planParkEviction(keys, PARK_MAX)).toEqual(['k0'])+ })+})diff --git a/src/renderer/terminal/park-budget.ts b/src/renderer/terminal/park-budget.tsnew file mode 100644index 000000000..1d8a0c34f--- /dev/null+++ b/src/renderer/terminal/park-budget.ts@@ -0,0 +1,18 @@+/**+ * Count cap for parked terminals (see TerminalNode's parkedTerminals). The park window+ * (TERM_PARK_MS) bounds each entry in TIME but nothing bounded the COUNT: switching through N+ * projects inside the window parked every terminal of each — each holding a full xterm buffer+ * with a live PTY subscription. Evicting the oldest park is invisible to the user: a disposed+ * park just means the next remount is a warm tmux reattach (tmux redraws), the same path every+ * remount after the 5-minute window already takes.+ *+ * 12 ≈ one busy project's worth of terminals; the same order of magnitude as WEBGL_BUDGET.+ */+export const PARK_MAX = 12++/** Keys to dispose so the park stays within `max`, oldest first. Caller passes keys in park+ * order (Map insertion order — TerminalNode always deletes before re-inserting on re-park). */+export function planParkEviction(keysInParkOrder: string[], max: number): string[] {+ if (keysInParkOrder.length <= max) return []+ return keysInParkOrder.slice(0, keysInParkOrder.length - max)+}