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.

feat(cable): forward the dial's scroll and focus to the desktop window

0xdiego254c8bf5fb20c1
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index b40102259..78b705541 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -542,6 +542,19 @@ export class BackendSocket {
this.enqueue({ t: 'up', frame: this.e2ee.wrapUp(frame) })
}
+ /** Send an up-frame to the LOOPBACK clients only — never to the cloud.
+ *
+ * For things that describe what is happening at THIS desk rather than what the machine is doing: the
+ * dial is a physical object on one table, and a finger moving on its glass is meaningful to the window
+ * in front of it and to nothing else. `send()` fans out to the web audience as well, which would scroll
+ * a window on a computer the user is not sitting at. */
+ sendLocal(frame: Frame): void {
+ if (env.LOG_FRAMES) logFrame('→', 'local', frame)
+ for (const [connId, sink] of this.localClients) {
+ if (!sink.sendFrame(frame)) void this.unregisterLocalClient(connId)
+ }
+ }
+
/** Send an up-frame to exactly ONE web connection (E2EE pairing/welcome + targeted RPC replies). */
sendTo(connId: string, frame: Frame): void {
const local = this.localClients.get(connId)
diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.ts
index 5feed0738..15b3cb7a7 100644
--- a/cli/src/cable/cableHost.ts
+++ b/cli/src/cable/cableHost.ts
@@ -37,6 +37,10 @@ export interface CableHostWiring {
updateAgent?: (agentId: string, model?: string, effort?: string) => void
/** The runtime catalog, from the same provider the web and the WiFi device read. */
listModels?: (agentId: string) => Promise<Array<{ id: string }>>
+ /** The dial moved to another agent — the desktop window should show that one. */
+ focused?: (agentId: string) => void
+ /** A finger on the dial's glass, in pieces, while it is down. */
+ scrolled?: (phase: 'down' | 'move' | 'up', dy: number, velocity: number) => void
log: (line: string) => void
}
@@ -93,9 +97,23 @@ export class DaemonCableHost implements CableHost {
}
focus(agentId: string): void {
- // A statement about where the user is looking. Nothing on this machine has to move for it yet — the
- // daemon has no window of its own — so it is recorded and logged rather than acted on.
+ // A statement about where the user is looking, and the desktop window follows it: turning the dial to
+ // an agent switches the terminal on screen to the same one. The daemon still has no window of its own
+ // — it forwards, and the app decides what following means for it.
this.wiring.log(`cable: focus ${agentId}`)
+ this.wiring.focused?.(agentId)
+ }
+
+ scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number): void {
+ // THE ENDS ARE LOGGED, THE MIDDLE IS NOT. A stroke is a `down`, a dozen `move`s and an `up`, several
+ // times a second: logging the middle buries every other line in the file. But the failure this
+ // protocol is most exposed to is a stroke that never CLOSES — the far side then holds a drag forever
+ // and its list stops answering the mouse — and that failure is invisible without a matching pair to
+ // look for. Two lines per swipe buys the one thing worth seeing.
+ if (phase !== 'move') {
+ this.wiring.log(phase === 'down' ? 'cable: scroll ↓' : `cable: scroll ↑ (v=${velocity})`)
+ }
+ this.wiring.scrolled?.(phase, dy, velocity)
}
updateAgent(agentId: string, model?: string, effort?: string): void {
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index dcdde1777..32defb548 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -72,6 +72,7 @@ function makeHost(over: Partial<CableHost> = {}) {
listAgents: async () => AGENTS,
sendTurn: vi.fn(),
stopTurn: vi.fn(),
+ scrolled: vi.fn(),
answer: vi.fn(),
focus: vi.fn(),
updateAgent: vi.fn(),
@@ -152,6 +153,42 @@ describe('cable session', () => {
await session.stop()
})
+ it('forwards a whole stroke, including the reports that carry no travel', async () => {
+ // The ends of a stroke are the point of the message, not padding around it: a `down` with nothing in
+ // it is what stops a fling still running on the far side, and an `up` with nothing in it is a finger
+ // that came to rest before it lifted and must land as a stop rather than a throw. A forwarder that
+ // "optimised away" the empty ones would leave the window holding a drag forever.
+ const host = makeHost()
+ const { session, port } = await connect(host)
+ port.say({ t: 'hello', mac: 'aa:bb' })
+ await settle()
+
+ port.say({ t: 'scroll', phase: 'down', dy: 0 })
+ port.say({ t: 'scroll', phase: 'move', dy: 12 })
+ port.say({ t: 'scroll', phase: 'up', dy: 3, v: -1800 })
+ await settle()
+
+ expect(host.scrolled).toHaveBeenNthCalledWith(1, 'down', 0, 0)
+ expect(host.scrolled).toHaveBeenNthCalledWith(2, 'move', 12, 0)
+ expect(host.scrolled).toHaveBeenNthCalledWith(3, 'up', 3, -1800)
+ await session.stop()
+ })
+
+ it('drops a stroke whose phase is not one of the three', async () => {
+ // The dial is the only thing that speaks this today, but the decoder hands up whatever arrives, and a
+ // phase nobody understands must not reach the window as a drag it can never close.
+ const host = makeHost()
+ const { session, port } = await connect(host)
+ port.say({ t: 'hello', mac: 'aa:bb' })
+ await settle()
+
+ port.say({ t: 'scroll', phase: 'sideways', dy: 40 })
+ await settle()
+
+ expect(host.scrolled).not.toHaveBeenCalled()
+ await session.stop()
+ })
+
it('routes a voice turn that names no agent', async () => {
const host = makeHost()
const { session, port } = await connect(host)
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index d9b5368b3..93c3cc5db 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -70,6 +70,8 @@ export interface CableHost {
stopTurn(agentId: string): void
answer(agentId: string, id: string, optionId: string): void
focus(agentId: string): void
+ /** A finger moving on the dial's glass, on its way to whatever window is open on this computer. */
+ scrolled(phase: 'down' | 'move' | 'up', dy: number, velocity: number): void
updateAgent(agentId: string, model?: string, effort?: string): void
/** PCM is 16-bit mono at `sampleRate`; the daemon owns the credential this needs. */
transcribe(pcm: Buffer, sampleRate: number, lang: string): Promise<string>
@@ -352,6 +354,17 @@ export class CableSession {
case 'focus':
if (str('agentId')) this.host.focus(str('agentId')!)
return
+ case 'scroll': {
+ // Forwarded verbatim, including the reports carrying no travel: the two ends of a stroke are the
+ // whole point of the message. A `down` with nothing in it stops a fling still running, and an `up`
+ // with nothing in it is a finger that came to rest before it lifted and must not be thrown.
+ const phase = str('phase')
+ if (phase !== 'down' && phase !== 'move' && phase !== 'up') return
+ const dy = typeof msg.dy === 'number' ? msg.dy : 0
+ const v = typeof msg.v === 'number' ? msg.v : 0
+ this.host.scrolled(phase, dy, v)
+ return
+ }
case 'turn.send':
if (str('agentId') && str('text')) this.host.sendTurn(str('agentId')!, str('text')!)
return
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 482a58745..75af4add6 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -2816,6 +2816,11 @@ async function runForeground(session: AuthSession): Promise<void> {
// The same provider the web and the WiFi device read, so the dial's picker cannot show a different
// catalog from the one the machine will actually honour.
listModels: async (agentId) => (await backend.runtimeModelsProvider?.(agentId)) ?? [],
+ // Both of these are LOCAL-ONLY on purpose (backend.sendLocal, not backend.send): they describe a hand
+ // at this desk, not a change in what the machine is doing, and the cloud web audience may be sitting
+ // at another computer entirely.
+ focused: (agentId) => backend.sendLocal({ type: 'dial_focus', payload: { agentId } }),
+ scrolled: (phase, dy, velocity) => backend.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity } }),
log: (line) => console.log(`[cable] ${line}`),
})
const cable = new CableSession(cableHost, join(env.ADAPTER_DATA_DIR, 'dial.log'))