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
test: pty suites ask tmux with exact targets; the new-only refusal spawns no client
review2ba6594395ad
diff --git a/src/core/pty-background-write.test.ts b/src/core/pty-background-write.test.tsindex 819f07974..ef58e1b38 100644--- a/src/core/pty-background-write.test.ts+++ b/src/core/pty-background-write.test.ts@@ -68,7 +68,9 @@ vi.mock('child_process', () => {const cb = (typeof a === 'function' ? a : b) as Cb | undefinedconst ok = (stdout: string): void => cb?.(null, { stdout, stderr: '' })if (args.includes('has-session')) {- const target = args[args.indexOf('-t') + 1]+ // Production asks with the EXACT form (`=nt-…` / `=nt-…:`); tmux matches it against the name.+ const raw = args[args.indexOf('-t') + 1]+ const target = raw.startsWith('=') ? raw.slice(1).replace(/:$/, '') : rawif (liveTmuxSessions.has(target)) ok('')else cb?.(Object.assign(new Error('no such session'), { code: 1 }))} else if (args[0] === '-ilc') {@@ -146,7 +148,7 @@ const ALICE = 1const BOB = 2/** `ls\n` as the wire sees it: hex bytes, because a control-mode command is one text line. */-const LS_KEYS = (target: string): string => `send-keys -t ${target} -H 6c 73 0a\n`+const LS_KEYS = (target: string): string => `send-keys -t =${target}: -H 6c 73 0a\n`/*** A machine with pty devices to spare, always.@@ -226,7 +228,7 @@ describe('background writes into released sessions', () => {'-C','attach-session','-t',- sessionName(key)+ `=${sessionName(key)}`]it('types into a released session over a control client — no pty, exact send-keys line', async () => {diff --git a/src/core/pty-exact-target.realtmux.test.ts b/src/core/pty-exact-target.realtmux.test.tsindex 3207da79a..27a2a8675 100644--- a/src/core/pty-exact-target.realtmux.test.ts+++ b/src/core/pty-exact-target.realtmux.test.ts@@ -35,17 +35,22 @@ const TMUX =['/opt/homebrew/bin/tmux', '/usr/local/bin/tmux', '/usr/bin/tmux'].find((p) => existsSync(p)) ?? nullvi.mock('./session-host-backend', async () => (await import('./__fixtures__/no-session-host')).noSessionHost())+/** Every pty the manager spawns (its tmux client): a refused NEW-ONLY create must spawn none. */+const spawns = vi.hoisted(() => [] as Array<{ file: string; args: string[] }>)vi.mock('node-pty', () => ({- spawn: () => ({- onData: () => {},- onExit: () => {},- write: () => {},- resize: () => {},- pause: () => {},- resume: () => {},- kill: () => {},- pid: 4321- })+ spawn: (file: string, args: string[]) => {+ spawns.push({ file, args })+ return {+ onData: () => {},+ onExit: () => {},+ write: () => {},+ resize: () => {},+ pause: () => {},+ resume: () => {},+ kill: () => {},+ pid: 4321+ }+ }}))vi.mock('./pty-devices', async (importOriginal) => ({...(await importOriginal<typeof import('./pty-devices')>()),@@ -166,8 +171,12 @@ describe.skipIf(!TMUX || process.platform === 'win32')('node-keyed tmux verbs re})it('a NEW-ONLY create never joins or reattaches a session that already runs under the name', async () => {+ spawns.length = 0const r = await manager.createHeadless({ persistKey: victimKey, cols: 80, rows: 24, newOnly: true })expect(r).toEqual({ sessionId: '', fresh: false, unavailable: 'new-only' })+ // Refused BEFORE any tmux client is spawned: `new-session -A -D` would attach to the victim and+ // detach its other clients even if the result were thrown away afterwards.+ expect(spawns).toEqual([])// The victim is untouched (still alive, nothing typed).await expect(tmux(['has-session', '-t', `=${sessionName(victimKey)}`])).resolves.toBeTruthy()// Where nothing runs under the EXACT name (a prefix of a live one included), it spawns fresh.@@ -175,6 +184,7 @@ describe.skipIf(!TMUX || process.platform === 'win32')('node-keyed tmux verbs reexpect(fresh.unavailable).toBeUndefined()expect(fresh.fresh).toBe(true)expect(fresh.sessionId).not.toBe('')+ expect(spawns.map((c) => c.args.includes('new-session'))).toEqual([true])manager.releaseHeadless(prefixKey)})})diff --git a/src/core/pty-idle-reap.test.ts b/src/core/pty-idle-reap.test.tsindex 4c0407099..c096f5b27 100644--- a/src/core/pty-idle-reap.test.ts+++ b/src/core/pty-idle-reap.test.ts@@ -76,7 +76,9 @@ vi.mock('child_process', () => {execCalls.push({ file, args })const ok = (stdout: string): void => cb?.(null, { stdout, stderr: '' })if (args.includes('has-session')) {- const target = args[args.indexOf('-t') + 1]+ // Production asks with the EXACT form (`=nt-…` / `=nt-…:`); tmux matches it against the name.+ const raw = args[args.indexOf('-t') + 1]+ const target = raw.startsWith('=') ? raw.slice(1).replace(/:$/, '') : rawif (liveTmuxSessions.has(target)) ok('')else cb?.(Object.assign(new Error('no such session'), { code: 1 }))} else if (args[0] === '-ilc') {diff --git a/src/core/pty-manager.pane-owner.test.ts b/src/core/pty-manager.pane-owner.test.tsindex dacb6460f..272419397 100644--- a/src/core/pty-manager.pane-owner.test.ts+++ b/src/core/pty-manager.pane-owner.test.ts@@ -221,7 +221,8 @@ describe('PtyManager.paneOwner', () => {expect(calls).toHaveLength(2)expect(calls[0]).toEqual({file: '/usr/bin/tmux',- args: ['-L', TMUX_SOCKET, 'display-message', '-p', '-t', TARGET, PANE_OWNER_FMT]+ // Exact (`=name:`): a bare target prefix-matches a longer session on a miss.+ args: ['-L', TMUX_SOCKET, 'display-message', '-p', '-t', `=${TARGET}:`, PANE_OWNER_FMT]})expect(calls[1]).toEqual({file: 'ps',@@ -285,7 +286,7 @@ describe('PtyManager.paneOwner', () => {}const mgr = await manager()expect(await mgr.paneOwner('some-other-node')).toBeNull()- expect(calls[0].args).toContain(sessionName('some-other-node'))+ expect(calls[0].args).toContain(`=${sessionName('some-other-node')}:`)})it('answers null — not a partial owner — when tmux is unavailable', async () => {diff --git a/src/core/pty-manager.snapshot-cadence.test.ts b/src/core/pty-manager.snapshot-cadence.test.tsindex 468638feb..25179e8c6 100644--- a/src/core/pty-manager.snapshot-cadence.test.ts+++ b/src/core/pty-manager.snapshot-cadence.test.ts@@ -26,7 +26,10 @@ vi.mock('child_process', () => {const execFile = (file: string, args: string[], a?: unknown, b?: unknown): unknown => {const cb = (typeof a === 'function' ? a : b) as Cb | undefinedif (args.includes('capture-pane')) {- const target = args[args.indexOf('-t') + 1]+ // Recorded as the session NAME; production passes the exact form (`=name:`).+ const raw = args[args.indexOf('-t') + 1]+ if (!/^=nt-.*:$/.test(raw)) throw new Error(`capture without an exact target: ${raw}`)+ const target = raw.slice(1, -1)tmux.captures.push(target)if (tmux.hold) tmux.held.push({ target, cb: cb! })else if (tmux.fail) cb?.(new Error('tmux busy'))diff --git a/src/core/pty-single-user.test.ts b/src/core/pty-single-user.test.tsindex 2be80ef14..7e4f13f54 100644--- a/src/core/pty-single-user.test.ts+++ b/src/core/pty-single-user.test.ts@@ -102,7 +102,9 @@ vi.mock('child_process', () => {execCalls.push({ file, args })const ok = (stdout: string): void => cb?.(null, { stdout, stderr: '' })if (args.includes('has-session')) {- const target = args[args.indexOf('-t') + 1]+ // Production asks with the EXACT form (`=nt-…` / `=nt-…:`); tmux matches it against the name.+ const raw = args[args.indexOf('-t') + 1]+ const target = raw.startsWith('=') ? raw.slice(1).replace(/:$/, '') : rawif (liveTmuxSessions.has(target)) ok('')// Real execFile carries tmux's exit status on err.code — 1 is what probeSaysAbsent// reads as genuine absence (vs a spawn failure, which has a string/no code).@@ -796,7 +798,8 @@ describe('SINGLE-USER REGRESSION: co-attach must not change the solo path', () =kill(sessionId)const captures = tmuxCalls('capture-pane')expect(captures).toHaveLength(1)- expect(captures[0].args[captures[0].args.indexOf('-t') + 1]).toBe(sessionName('solo-1'))+ // Exact (`=name:`): a bare target prefix-matches a longer session (tmux-naming `exactPaneTarget`).+ expect(captures[0].args[captures[0].args.indexOf('-t') + 1]).toBe(`=${sessionName('solo-1')}:`)})it('killAll (app quit) detaches the client but never kills the tmux session', async () => {