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(bridge): real onAgentStatus / onSubagentActivity subscriptions over the WS client

enesf92338af89f7
diff --git a/src/renderer/bridge/stubs.test.ts b/src/renderer/bridge/stubs.test.ts
index 9b374c49e..da73dd20a 100644
--- a/src/renderer/bridge/stubs.test.ts
+++ b/src/renderer/bridge/stubs.test.ts
@@ -16,8 +16,6 @@ describe('bridge stubs', () => {
s.browser.onBrowserNewWindow(() => {}),
s.onAgentControl(() => {}),
s.sshProject.onStatus(() => {}),
- s.onSubagentActivity(() => {}),
- s.onAgentStatus(() => {}),
s.usage.onUpdate(() => {}),
s.updates.onAvailable(() => {}),
s.updates.onProgress(() => {}),
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index ec4b522be..c8b2086d8 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -39,7 +39,16 @@ const pnoop = (): Promise<void> => Promise.resolve()
export function buildStubApi(): Omit<
NodeTerminalApi,
- 'pty' | 'workspace' | 'settings' | 'fs' | 'git' | 'files' | 'context' | 'dialog'
+ | 'pty'
+ | 'workspace'
+ | 'settings'
+ | 'fs'
+ | 'git'
+ | 'files'
+ | 'context'
+ | 'dialog'
+ | 'onAgentStatus'
+ | 'onSubagentActivity'
> {
const api = {
ssh: {
@@ -202,13 +211,20 @@ export function buildStubApi(): Omit<
},
openNotificationSettings: pnoop,
onFocusNode: noopUnsub,
- onAgentStatus: noopUnsub,
- onSubagentActivity: noopUnsub,
onAgentControl: noopUnsub,
sendAgentControlResult: noop
} satisfies Omit<
NodeTerminalApi,
- 'pty' | 'workspace' | 'settings' | 'fs' | 'git' | 'files' | 'context' | 'dialog'
+ | 'pty'
+ | 'workspace'
+ | 'settings'
+ | 'fs'
+ | 'git'
+ | 'files'
+ | 'context'
+ | 'dialog'
+ | 'onAgentStatus'
+ | 'onSubagentActivity'
>
return api
diff --git a/src/renderer/bridge/ws-bridge.agent.test.ts b/src/renderer/bridge/ws-bridge.agent.test.ts
new file mode 100644
index 000000000..913104aa9
--- /dev/null
+++ b/src/renderer/bridge/ws-bridge.agent.test.ts
@@ -0,0 +1,29 @@
+import { describe, it, expect } from 'vitest'
+import { buildAgentApi } from './ws-bridge'
+import { IPC } from '../../shared/ipc'
+
+function fakeClient() {
+ const subs: Array<{ channel: string }> = []
+ return {
+ subs,
+ subscribe: (channel: string, _fn: (...a: unknown[]) => void) => {
+ subs.push({ channel })
+ return () => {}
+ }
+ }
+}
+
+describe('buildAgentApi', () => {
+ it('onAgentStatus / onSubagentActivity subscribe to the right channels and return an unsub', () => {
+ const c = fakeClient()
+ const api = buildAgentApi(c as never)
+ const un1 = api.onAgentStatus(() => {})
+ const un2 = api.onSubagentActivity(() => {})
+ expect(c.subs).toEqual([
+ { channel: IPC.agentStatus },
+ { channel: IPC.agentSubagentActivity }
+ ])
+ expect(typeof un1).toBe('function')
+ expect(typeof un2).toBe('function')
+ })
+})
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index bedf28e6d..135edf374 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -308,6 +308,22 @@ export function buildFilesApi(
return { fs, git, files, context }
}
+/**
+ * Build the top-level agent-event subscriptions (`onAgentStatus` / `onSubagentActivity`) over an
+ * RpcClient. These mirror the preload's `.on(channel, …)` → `client.subscribe(channel, …)` split:
+ * each takes a listener and returns an unsubscribe. Declared against its `NodeTerminalApi` slice so
+ * `satisfies` keeps the compiler as the completeness gate.
+ */
+export function buildAgentApi(
+ client: RpcClient
+): Pick<NodeTerminalApi, 'onAgentStatus' | 'onSubagentActivity'> {
+ return {
+ onAgentStatus: (listener) => client.subscribe(IPC.agentStatus, listener as Listener),
+ onSubagentActivity: (listener) =>
+ client.subscribe(IPC.agentSubagentActivity, listener as Listener)
+ }
+}
+
/** WS URL for the current page: same host, `/ws`, ws→http / wss→https. */
function wsUrl(): string {
const scheme = location.protocol === 'https:' ? 'wss' : 'ws'
@@ -412,6 +428,7 @@ export async function installWsBridge(): Promise<void> {
...buildStubApi(),
...buildRealApi(client),
...buildFilesApi(client),
+ ...buildAgentApi(client),
// Web replacement for the Electron native dialog: an in-app server-directory browser over
// fs.list (the stub's E_UNSUPPORTED reject is dropped in favor of this real picker).
dialog: (() => {