Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(dial): follow the window when it moves without opening anything

0xdiego25a7e7dc6e2480
diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.ts
index 2c59540f7..680d01473 100644
--- a/cli/src/localWsServer.spec.ts
+++ b/cli/src/localWsServer.spec.ts
@@ -105,6 +105,41 @@ describe('local CLI WebSocket', () => {
ws.close()
})
+ it('follows an explicit app_focus, and keeps it off the wire', async () => {
+ const backend = new FakeBackend()
+ const moves: Array<{ machineId: string; agentId: string }> = []
+ server = http.createServer((_req, res) => { res.statusCode = 404; res.end() })
+ local = attachLocalWsServer(server, {
+ machineId,
+ backend,
+ onAppFocus: (m, a) => moves.push({ machineId: m, agentId: a }),
+ })
+ await new Promise<void>((resolve) => server!.listen(0, '127.0.0.1', resolve))
+ const url = `ws://127.0.0.1:${(server.address() as AddressInfo).port}/api/local-ws`
+
+ const ws = new WebSocket(url)
+ await onceOpen(ws)
+ const connected = onceMessage(ws)
+ ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId, localProtocolVersion: 1 } }))
+ await connected
+
+ // Opening a terminal still counts: that is all an older app build sends.
+ ws.send(JSON.stringify({ type: 'terminal_open', payload: { agentId: 'agent-opened' } }))
+ // And a window that MOVED without opening anything now says so — which is every click on a pane
+ // that already holds a live session, the case the dial used to miss entirely.
+ ws.send(JSON.stringify({ type: 'app_focus', payload: { agentId: 'agent-focused' } }))
+ await new Promise((resolve) => setTimeout(resolve, 20))
+
+ expect(moves).toEqual([
+ { machineId, agentId: 'agent-opened' },
+ { machineId, agentId: 'agent-focused' },
+ ])
+ // Consumed locally: it describes a hand at this desk, and the machine has no use for an unknown
+ // frame type arriving on every pane click.
+ expect(backend.frames.map((frame) => frame.type)).toEqual(['terminal_open'])
+ ws.close()
+ })
+
it('does not require a credential on the loopback transport', async () => {
const url = await start(new FakeBackend())
const ws = new WebSocket(url, ['legacy-client-label'])
diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.ts
index e0b09e59a..a650066f0 100644
--- a/cli/src/localWsServer.ts
+++ b/cli/src/localWsServer.ts
@@ -189,10 +189,23 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerO
// frames: those are forwarded upstream a few lines below and would be invisible, which is exactly
// the case that matters — the dial has to follow the window onto ANOTHER machine too.
if (!isBinary && options.onAppFocus && boundMachineId) {
- const opened = jsonFrame(raw)
- const agentId = (opened?.payload as Record<string, unknown> | undefined)?.agentId
- if (opened?.type === 'terminal_open' && typeof agentId === 'string' && agentId) {
- options.onAppFocus(boundMachineId, agentId)
+ const moved = jsonFrame(raw)
+ const agentId = (moved?.payload as Record<string, unknown> | undefined)?.agentId
+ if (typeof agentId === 'string' && agentId) {
+ // `app_focus` is the window SAYING where it is looking. `terminal_open` is it being
+ // inferred from a side effect, which is all there was when a window could only show one
+ // terminal: every move opened a stream, so opening one meant it had moved.
+ //
+ // A pane grid breaks that equivalence. Clicking a tile that already holds a live session
+ // opens nothing at all, so the dial never heard about it and stayed on the agent the last
+ // rail click had opened. Both are still read: an older app build only sends the second.
+ if (moved?.type === 'app_focus') {
+ options.onAppFocus(boundMachineId, agentId)
+ // Consumed here. It describes a hand at THIS desk and the machine has no use for it —
+ // forwarding it would put an unknown frame type on the wire for every pane click.
+ return
+ }
+ if (moved?.type === 'terminal_open') options.onAppFocus(boundMachineId, agentId)
}
}