Skip to content

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.

refactor(transport): LocalTransport takes an injected api

enes7b5d81a41886
diff --git a/src/renderer/terminal/local-transport.test.ts b/src/renderer/terminal/local-transport.test.ts
index e9ea1ecb2..622958790 100644
--- a/src/renderer/terminal/local-transport.test.ts
+++ b/src/renderer/terminal/local-transport.test.ts
@@ -1,6 +1,33 @@
import { describe, it, expect, vi } from 'vitest'
+import type { NodeTerminalApi } from '@shared/types'
import { LocalTransport } from './local-transport'
+describe('LocalTransport injected api', () => {
+ it('delegates to the injected api, not the global', () => {
+ const create = vi.fn(async () => ({ sessionId: 's', fresh: true }) as never)
+ const api = {
+ pty: {
+ create,
+ write: vi.fn(),
+ resize: vi.fn(),
+ setFlow: vi.fn(),
+ kill: vi.fn(),
+ destroy: vi.fn(),
+ recycle: vi.fn(),
+ onData: vi.fn(),
+ onExit: vi.fn(),
+ onSize: vi.fn(),
+ onClosed: vi.fn(),
+ onRecycled: vi.fn(),
+ onResync: vi.fn()
+ }
+ } as unknown as NodeTerminalApi
+ const t = new LocalTransport(api)
+ void t.create({ persistKey: 'k' } as never)
+ expect(create).toHaveBeenCalledWith({ persistKey: 'k' })
+ })
+})
+
describe('LocalTransport co-attach members', () => {
it('subscribes to the authoritative size, the closed-by-peer event and the redraw', () => {
const unsubSize = vi.fn()
diff --git a/src/renderer/terminal/local-transport.ts b/src/renderer/terminal/local-transport.ts
index b2e448fe2..4af07027b 100644
--- a/src/renderer/terminal/local-transport.ts
+++ b/src/renderer/terminal/local-transport.ts
@@ -1,15 +1,25 @@
-import type { PtyCreateOptions, PtyCreateResult, RecycledInfo } from '@shared/types'
+import type { NodeTerminalApi, PtyCreateOptions, PtyCreateResult, RecycledInfo } from '@shared/types'
import type { ClientId } from '@shared/presence'
import type { TerminalTransport } from './transport'
/**
- * Local transport: binds the IPC API exposed via preload (window.nodeTerminal.pty)
- * to the TerminalTransport interface. All real work happens in node-pty in the main
- * process.
+ * Local transport: binds a core's api (`api.pty`) to the TerminalTransport interface.
+ * The api is injected — for the local session it IS `window.nodeTerminal` (the preload
+ * IPC surface; all real work happens in node-pty in the main process), so behavior is
+ * identical to the pre-injection global reads.
*/
export class LocalTransport implements TerminalTransport {
+ /** Lazy `window.nodeTerminal` fallback (not an eager default parameter): the module-scope
+ * `transport` singleton below is constructed at import time, and under node (vitest, no
+ * jsdom) `window` doesn't exist yet — it must only be touched on first use. */
+ constructor(private readonly injectedApi?: NodeTerminalApi) {}
+
+ private get api(): NodeTerminalApi {
+ return this.injectedApi ?? window.nodeTerminal
+ }
+
private get pty() {
- return window.nodeTerminal.pty
+ return this.api.pty
}
create(options: PtyCreateOptions): Promise<PtyCreateResult> {