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(control): main<->renderer round-trip with pending-request map + 120s timeout

enes69c4ef1c1280
diff --git a/src/main/index.ts b/src/main/index.ts
index 155ca3060..63edbdb3c 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1,5 +1,6 @@
import { join, resolve, sep, posix } from 'path'
import { homedir } from 'os'
+import { randomUUID } from 'crypto'
import { app, BrowserWindow, dialog, ipcMain, Notification, shell } from 'electron'
import { IPC } from '../shared/ipc'
import * as fsOps from './fs-ops'
@@ -556,6 +557,41 @@ app.whenReady().then(async () => {
nodeSubagents.delete(nodeId)
}
})
+ // Agent canvas control: the spawned agent's `nodeterm` CLI POSTs a verb to the hook server,
+ // which we forward to the renderer and await a reply. A pending-request map (keyed by a random
+ // requestId) bridges the two async hops; both the reply and the 120s timeout clear the entry.
+ const pendingControl = new Map<
+ string,
+ {
+ resolve: (r: { ok: boolean; message?: string; result?: unknown; error?: string }) => void
+ timer: NodeJS.Timeout
+ }
+ >()
+ ipcMain.on(
+ IPC.agentControlResult,
+ (
+ _e,
+ payload: { requestId: string; ok: boolean; message?: string; result?: unknown; error?: string }
+ ) => {
+ const pending = pendingControl.get(payload.requestId)
+ if (!pending) return
+ clearTimeout(pending.timer)
+ pendingControl.delete(payload.requestId)
+ pending.resolve(payload)
+ }
+ )
+ hookServer.setControlHandler(async ({ verb, nodeId, args }) => {
+ if (!mainWin || mainWin.isDestroyed()) return { ok: false, error: 'window unavailable' }
+ const requestId = randomUUID()
+ return await new Promise((resolve) => {
+ const timer = setTimeout(() => {
+ pendingControl.delete(requestId)
+ resolve({ ok: false, error: 'timed out (no response / not confirmed)' })
+ }, 120_000)
+ pendingControl.set(requestId, { resolve, timer })
+ mainWin!.webContents.send(IPC.agentControl, { requestId, sourceNodeId: nodeId, verb, args })
+ })
+ })
await hookServer.start()
initMediaProtocol()
diff --git a/src/preload/index.ts b/src/preload/index.ts
index fb72b0ac1..1de1196a3 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -338,7 +338,13 @@ const api: NodeTerminalApi = {
const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)
ipcRenderer.on(IPC.agentSubagentActivity, handler)
return () => ipcRenderer.removeListener(IPC.agentSubagentActivity, handler)
- }
+ },
+ onAgentControl: (listener) => {
+ const handler = (_e: unknown, cmd: unknown) => listener(cmd as never)
+ ipcRenderer.on(IPC.agentControl, handler)
+ return () => ipcRenderer.removeListener(IPC.agentControl, handler)
+ },
+ sendAgentControlResult: (payload) => ipcRenderer.send(IPC.agentControlResult, payload)
}
contextBridge.exposeInMainWorld('nodeTerminal', api)
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 97f5c58cd..df0d30934 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -24,6 +24,8 @@ export const IPC = {
appSetBadge: 'app:set-badge',
agentStatus: 'agent:status',
agentSubagentActivity: 'agent:subagent-activity',
+ agentControl: 'agent:control',
+ agentControlResult: 'agent:control-result',
contextLinkSetLinks: 'context-link:set-links',
appUpdateAvailable: 'app:update-available',
appUpdateDownloaded: 'app:update-downloaded',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index a3b87d9d3..b179fba10 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -859,4 +859,21 @@ export interface NodeTerminalApi {
onAgentStatus(listener: (e: NormalizedAgentEvent) => void): () => void
/** Fires with live subagent transcript chunks while a subagent runs. Returns unsubscribe. */
onSubagentActivity(listener: (e: SubagentActivity) => void): () => void
+ /** Fires when an agent's `nodeterm` CLI requests a canvas action. Returns unsubscribe. */
+ onAgentControl(
+ listener: (cmd: {
+ requestId: string
+ sourceNodeId: string
+ verb: string
+ args: Record<string, string>
+ }) => void
+ ): () => void
+ /** Reply to an agent control request (resolves the awaiting CLI call in main). */
+ sendAgentControlResult(payload: {
+ requestId: string
+ ok: boolean
+ message?: string
+ result?: unknown
+ error?: string
+ }): void
}