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.

feat(pty): pty.launchHeadless — desktop-only IPC onto core launchHeadless (#925)

reviewae4111f70e16
diff --git a/src/main/index.ts b/src/main/index.ts
index baa1cb1db..266e9cde5 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -78,9 +78,10 @@ import {
type AgentMessagingDeps
} from '../core/agents/agent-messaging'
import type { RemoteLogExec } from '../core/board-log'
-import type { TranscriptPresence } from '../shared/types'
+import type { PtyCreateOptions, TranscriptPresence } from '../shared/types'
import { boardLogRemotePath } from '../core/board-log'
import { PtyManager } from '../core/pty-manager'
+import { launchHeadless } from '../core/headless-launch'
import { WorkspaceStore } from '../core/workspace-store'
import type { CardLabelEdit } from '../core/project-kanban-write'
import { WorkspaceWatcher } from '../core/workspace-watcher'
@@ -1497,6 +1498,21 @@ app.whenReady().then(async () => {
// block below on the server side too — this one is here beside its sibling.
corePlatform.handle(IPC.ptySessionAge, (persistKey: string) => ptyManager.sessionAgeSeconds(persistKey))
+ // #925: canvas-control `--run-now` / `run`. Registered here rather than in core's shared
+ // `registerIpc` so no browser client can reach it: the Server Edition starts nodes through its
+ // own factory. All logic lives in core/headless-launch. Local-only by construction: the
+ // renderer never sends SSH fields for this, and this strips them anyway.
+ corePlatform.handle(
+ IPC.ptyLaunchHeadless,
+ (req: { ptyOptions: PtyCreateOptions; command: string }) =>
+ launchHeadless(ptyManager, {
+ ptyOptions: { ...req.ptyOptions, sshRemote: undefined, requireRemote: undefined },
+ command: String(req.command ?? ''),
+ release: true,
+ requirePersistent: true
+ })
+ )
+
// Gemini's title read needs the transcript path its own context tail already tracks (nothing
// scans for it). That tail is created ~600 lines below with the rest of the hook plumbing, while
// this deps object is consumed by the ptyReadSessionName handler just under here and by the
diff --git a/src/preload/index.test.ts b/src/preload/index.test.ts
index 8e83ea05f..cc7dfbc46 100644
--- a/src/preload/index.test.ts
+++ b/src/preload/index.test.ts
@@ -41,6 +41,14 @@ describe('preload sshProject passphrase wiring', () => {
expect(h.invoke).toHaveBeenCalledWith(IPC.ptyTerminateForeground, 'node-1', 'claude')
})
+ // #925: the request travels as ONE object, verbatim — main fills release/requirePersistent and
+ // strips the SSH fields itself, so the preload must neither add nor drop anything.
+ it('routes pty.launchHeadless through request IPC with the request object verbatim', async () => {
+ const req = { ptyOptions: { persistKey: 'node-1', cols: 80, rows: 24 }, command: 'claude' }
+ await api.pty.launchHeadless(req)
+ expect(h.invoke).toHaveBeenCalledWith(IPC.ptyLaunchHeadless, req)
+ })
+
it('exposes GitHub issue data and host-control namespaces on their exact channels', async () => {
await api.githubIssues.query({ projectId: 'p1', columnId: null, pageSize: 50 })
await api.githubControl.saveToken('write-only-secret')
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 85d7e3f78..ffb791ffc 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -100,6 +100,7 @@ const api: NodeTerminalApi = {
ipcRenderer.invoke(IPC.ptySendText, persistKey, text, opts?.enter),
tmuxStatus: () => ipcRenderer.invoke(IPC.ptyTmuxStatus),
paneCommand: (persistKey) => ipcRenderer.invoke(IPC.ptyPaneCommand, persistKey),
+ launchHeadless: (req) => ipcRenderer.invoke(IPC.ptyLaunchHeadless, req),
paneOwner: (persistKey) => ipcRenderer.invoke(IPC.ptyPaneOwner, persistKey),
terminateForeground: (persistKey, expectedAgentId) =>
ipcRenderer.invoke(IPC.ptyTerminateForeground, persistKey, expectedAgentId),
diff --git a/src/renderer/bridge/ws-bridge.namespaces.test.ts b/src/renderer/bridge/ws-bridge.namespaces.test.ts
index b1d4e5f18..cd711540c 100644
--- a/src/renderer/bridge/ws-bridge.namespaces.test.ts
+++ b/src/renderer/bridge/ws-bridge.namespaces.test.ts
@@ -108,6 +108,20 @@ describe('buildRealApi: host platform', () => {
})
})
+// #925: the Server Edition starts nodes through its own HeadlessNodeFactory, so the browser build
+// has nothing to call. It must REFUSE with the coded error and never reach the wire — a relay tab
+// spreads this same `pty`, so a request here would ask the HOST's core to spawn a session.
+describe('buildRealApi: pty.launchHeadless', () => {
+ it('rejects E_UNSUPPORTED without a request', async () => {
+ const c = fakeClient()
+ const api = buildRealApi(c as never)
+ await expect(
+ api.pty.launchHeadless({ ptyOptions: { persistKey: 'n1', cols: 80, rows: 24 }, command: 'x' })
+ ).rejects.toMatchObject({ code: E_UNSUPPORTED })
+ expect(c.calls).toEqual([])
+ })
+})
+
describe('buildRealApi: sessionMemory', () => {
// A real WS namespace, not a stub: the same core service (`startSessionMemoryService`) registers
// both channels in the server shell, so the browser gets a genuine per-session breakdown of the
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index a8c3fd96d..2abfb3797 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -66,7 +66,7 @@ import {
} from '../../shared/types'
import type { PeerIdentity } from '../../shared/presence'
import type { PaneOwner } from '../../shared/agents/pane-owner-predicate'
-import { buildStubApi } from './stubs'
+import { buildStubApi, unsupported } from './stubs'
import { mountPickerRoot, openDirectoryPicker } from './dialog-picker'
import { encodePcmForWire } from './speech-encode'
import { type FrameTransport, WebSocketFrameTransport } from './frame-transport'
@@ -273,6 +273,9 @@ export function buildRealApi(
// shell yet" and gives up on its own deadline.
paneCommand: (persistKey) =>
client.request(IPC.ptyPaneCommand, persistKey).catch(() => null) as Promise<string | null>,
+ // Documented degrade (#925): the Server Edition starts nodes through its HeadlessNodeFactory,
+ // never through the browser renderer, so there is nothing for this to call.
+ launchHeadless: () => unsupported('pty.launchHeadless'),
// A REAL implementation, not a stub: core registers the handler, so the server this browser is
// served from answers it. The hibernation exit fails CLOSED on a null, so a stub here would
// have silently switched Eco off for the whole Server Edition rather than degrade it.
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 421fda870..b02a4a326 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -32,6 +32,8 @@ export const IPC = {
/** The foreground command of a node's tmux pane (`#{pane_current_command}`) — how the in-place
* agent restart sees that the CLI has exited and a shell owns the pane again. */
ptyPaneCommand: 'pty:pane-command',
+ /** Desktop-only (#925): start a node's session with no viewer and deliver its held launch. */
+ ptyLaunchHeadless: 'pty:launch-headless',
/** Kernel truth about a node's tmux pane: its root pid, tty, tmux pane id, and the full argv of
* its FOREGROUND process group (`PaneOwner`). The name-only `ptyPaneCommand` above cannot tell
* an agent from anything else — an npm-installed CLI reports as `node`, and an agent reached
diff --git a/src/shared/types.ts b/src/shared/types.ts
index fcd8467f4..e958ec87a 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1056,6 +1056,16 @@ export interface PtyApi {
* node persistKey. null when it is unknown — no session, no tmux, or the query failed — which
* callers must read as "not observed", never as evidence of a particular command. */
paneCommand(persistKey: string): Promise<string | null>
+ /**
+ * Desktop only (#925). Spawn-or-attach a node's session with no viewer and deliver `command`
+ * through the echo-verified writer, then release the synthetic client (the tmux session keeps
+ * running). Refused as `not-persistent` without tmux or the session-host. The Server Edition
+ * starts nodes through its own factory, so the browser build rejects with E_UNSUPPORTED.
+ */
+ launchHeadless(req: {
+ ptyOptions: PtyCreateOptions
+ command: string
+ }): Promise<import('./headless-launch').HeadlessLaunchResult>
/** Kernel truth about a node's pane — its root pid, tty, tmux pane id and the full argv of its
* foreground process group — so a caller can ask WHO owns the pane rather than what tmux calls
* it. `null` is "could not read", never evidence that the pane is free (see `isAgentPane`'s