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(pty): smallest-subscriber size math + pty:size / pty:closed channels
enes2914fb8ebc45
diff --git a/src/core/pty-size.test.ts b/src/core/pty-size.test.tsnew file mode 100644index 000000000..b52f9d1eb--- /dev/null+++ b/src/core/pty-size.test.ts@@ -0,0 +1,38 @@+import { describe, it, expect } from 'vitest'+import { effectiveSize } from './pty-size'+import { IPC } from '../shared/ipc'++describe('effectiveSize', () => {+ it('is the subscriber s own size when there is exactly one (single-user path)', () => {+ expect(effectiveSize([{ cols: 120, rows: 40 }])).toEqual({ cols: 120, rows: 40 })+ })++ it('takes the smallest cols and the smallest rows independently', () => {+ // The narrow client and the short client can be different people.+ expect(+ effectiveSize([+ { cols: 120, rows: 24 },+ { cols: 80, rows: 60 }+ ])+ ).toEqual({ cols: 80, rows: 24 })+ })++ it('floors at 1 (node-pty throws on 0) and ignores non-finite sizes', () => {+ expect(effectiveSize([{ cols: 0, rows: 0 }])).toEqual({ cols: 1, rows: 1 })+ expect(effectiveSize([{ cols: 80, rows: 24 }, { cols: NaN, rows: 10 }])).toEqual({+ cols: 80,+ rows: 10+ })+ })++ it('returns null for an empty subscriber set', () => {+ expect(effectiveSize([])).toBeNull()+ })+})++describe('per-session channels', () => {+ it('exposes the authoritative-size and closed channels', () => {+ expect(IPC.ptySize('pty-1')).toBe('pty:size:pty-1')+ expect(IPC.ptyClosed('pty-1')).toBe('pty:closed:pty-1')+ })+})diff --git a/src/core/pty-size.ts b/src/core/pty-size.tsnew file mode 100644index 000000000..34bb08e71--- /dev/null+++ b/src/core/pty-size.ts@@ -0,0 +1,32 @@+/**+ * Size negotiation for a co-attached PTY: several subscribers watch ONE tmux client, each with+ * its own zoom/DPI/window size, so they compute different cols/rows. The pty runs at the+ * SMALLEST of them — a subscriber that renders fewer columns than the pty emits would wrap and+ * corrupt its screen, while a subscriber with room to spare can simply letterbox the remainder.+ *+ * Deliberately pure (no node-pty, no platform): with exactly ONE subscriber the min of a+ * one-element set is that subscriber's own size, which is what keeps the single-user path+ * bit-for-bit identical to the pre-co-attach behavior.+ */+export interface PtySize {+ cols: number+ rows: number+}++/** Smallest cols × smallest rows across all subscribers; null when there are none. */+export function effectiveSize(sizes: Iterable<PtySize>): PtySize | null {+ let cols = Infinity+ let rows = Infinity+ let any = false+ for (const s of sizes) {+ if (Number.isFinite(s.cols)) cols = Math.min(cols, s.cols)+ if (Number.isFinite(s.rows)) rows = Math.min(rows, s.rows)+ any = true+ }+ if (!any) return null+ // node-pty throws on a 0 dimension, and a not-yet-measured subscriber can report 0.+ return {+ cols: Number.isFinite(cols) ? Math.max(1, cols) : 1,+ rows: Number.isFinite(rows) ? Math.max(1, rows) : 1+ }+}diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex 3e4966408..94e46b57b 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -76,6 +76,12 @@ export const IPC = {// Events broadcast from main to the renderer (sessionId is appended to the channel name).ptyData: (sessionId: string) => `pty:data:${sessionId}`,ptyExit: (sessionId: string) => `pty:exit:${sessionId}`,+ /** Authoritative size of a co-attached session: min(cols) × min(rows) over all subscribers.+ * Broadcast to every subscriber whenever the subscriber set or any reported size changes. */+ ptySize: (sessionId: string) => `pty:size:${sessionId}`,+ /** The node was permanently destroyed by another client (payload: { by: ClientId }). The+ * remaining subscribers show a "closed by <name>" state instead of respawning the session. */+ ptyClosed: (sessionId: string) => `pty:closed:${sessionId}`,workspaceLoad: 'workspace:load',workspaceSave: 'workspace:save',workspaceProbeFolder: 'workspace:probe-folder',