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): tell the window whether a dial is on the desk

0xdiego2593d01d1bf6d4
diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.ts
index 63b9a6684..263249191 100644
--- a/cli/src/cable/cableHost.ts
+++ b/cli/src/cable/cableHost.ts
@@ -17,11 +17,12 @@ import { fetchRelease, loadImage, shouldOffer } from './fwPush.js'
import { routeVoiceTask, type RouterAgent, type RouterContinuity } from '../lib/voiceRouter.js'
import { env } from '../config/env.js'
-import type { CableAgent, CableHost, CableMachine, CableMachineSource, RouteDecision } from './cableSession.js'
+import type { CableAgent, CableHost, CableMachine, CableMachineSource, DialStatus, RouteDecision } from './cableSession.js'
import type { WindowRoute } from './windowRoute.js'
import { FleetError, type FleetMachine, type MachineFleet } from './machineFleet.js'
/** One completed turn's recap, as the mirror keeps them. */
+
export interface RecentTurn {
recap?: string
text?: string
@@ -54,6 +55,8 @@ export interface CableHostWiring {
opened?: (machineId: string, 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
+ /** The dial came, went, or started taking an update — see CableSession's onDialStatus. */
+ dialStatus?: (status: DialStatus) => void
/** Offer a spoken task to the desktop window's palette. Omitted when there is no window plumbing. */
routeInWindow?: (text: string, cmd?: string) => Promise<WindowRoute>
log: (line: string) => void
@@ -241,6 +244,21 @@ export class DaemonCableHost implements CableHost {
this.fleet?.release(true)
}
+ /**
+ * The last status the session reported, kept so a window that connects AFTER the dial was plugged
+ * in can be told at once. Without this the row would say "no device" until the next unplug.
+ */
+ private dialStatusNow: DialStatus = { attached: false }
+
+ onDialStatus(status: DialStatus): void {
+ this.dialStatusNow = status
+ this.wiring.dialStatus?.(status)
+ }
+
+ currentDialStatus(): DialStatus {
+ return this.dialStatusNow
+ }
+
machineName(): string {
return this.wiring.machineName()
}
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index e821456da..8f98f0a97 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -149,6 +149,23 @@ describe('cable session', () => {
await session.stop()
})
+ it('tells the host the dial is there, on which firmware, and when it leaves — never on a keepalive', async () => {
+ // What a window draws in its rail. Attach and detach are the two facts; a repeat greeting is
+ // neither, and a rail that redraws four times a minute to say "still here" is noise.
+ const seen: unknown[] = []
+ const { session, port } = await connect(makeHost({ onDialStatus: (status) => seen.push(status) }))
+ port.say({ t: 'hello', product: 'harness', fw: '0.0.58', proto: 1, mac: 'aa:bb' })
+ await vi.waitFor(() => expect(seen).toEqual([{ attached: true, fw: '0.0.58' }]))
+
+ port.say({ t: 'hello', product: 'harness', fw: '0.0.58', proto: 1, mac: 'aa:bb' })
+ await settle()
+ expect(seen).toHaveLength(1)
+
+ await port.close('unplugged')
+ await vi.waitFor(() => expect(seen.at(-1)).toEqual({ attached: false }))
+ await session.stop()
+ })
+
it('re-attaches for a DIFFERENT dial', async () => {
const { session, port } = await connect()
port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' })
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index db2dbeb40..a678ee89f 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -262,9 +262,23 @@ export interface CableHost {
*/
onDialAttached?(): void
onDialGone?(): void
+ /**
+ * The dial as a window would draw it: there or not, on which firmware, and whether an update is
+ * going over the cable right now. Fired on every change and never on a keepalive — the window
+ * shows this in its rail, and a rail that redraws four times a minute to say "still here" is a rail
+ * nobody can afford. What is NOT here: anything a hand did (that is `focused`/`opened`/`scrolled`).
+ */
+ onDialStatus?(status: DialStatus): void
log(line: string): void
}
+/** What a window needs to draw the device row. `updating` names the version on its way over. */
+export interface DialStatus {
+ attached: boolean
+ fw?: string
+ updating?: string
+}
+
interface Message {
t: string
[key: string]: unknown
@@ -458,6 +472,14 @@ export class CableSession {
private openAt = 0
private opening = false
+ /**
+ * The version an OTA is moving TO, or '' when none is in flight.
+ *
+ * Read by the device row the window draws — see onDialStatus. A dial that is
+ * taking an update is neither simply present nor absent, and the row says so.
+ */
+ private offeringTo = ''
+
private lastPing = 0
/**
@@ -555,6 +577,7 @@ export class CableSession {
private onClosed(why: string): void {
this.host.log(`cable: closed (${why})`)
this.host.onDialGone?.()
+ this.host.onDialStatus?.({ attached: false })
this.link = null
this.greetedMac = null
this.greetedFw = null
@@ -652,6 +675,7 @@ export class CableSession {
this.greetedMac = mac
this.greetedFw = fw
this.host.log(`cable: dial ${mac} ${returning ? 'back ' : ''}on fw ${fw} proto ${msg.proto}`)
+ this.host.onDialStatus?.({ attached: true, fw })
// BEFORE the state push, not after: the push reads the selected machine, and for a remote one
// that means an RPC over a lane this is what re-opens.
this.host.onDialAttached?.()
@@ -797,6 +821,9 @@ export class CableSession {
return
case 'fw.accept':
// The dial has erased its slot and is expecting bytes. Nothing was sent before this.
+ // The window is told NOW rather than at the offer: an offer the dial refuses is nothing to
+ // show, and the minute that matters — do not unplug it — starts here.
+ this.host.onDialStatus?.({ attached: true, fw: this.greetedFw ?? undefined, updating: this.offeringTo })
await this.transfer?.pump()
return
case 'fw.progress':
@@ -804,12 +831,23 @@ export class CableSession {
if (typeof msg.written === 'number') await this.transfer?.onProgress(msg.written)
return
case 'fw.done':
+ // WHETHER AN UPDATE LANDS is not something the release process can see:
+ // a version is published, and after that the only evidence is the next
+ // `hello` from a dial that may never have taken it.
this.transfer?.finish('installed — the dial is rebooting')
this.transfer = null
+ this.offeringTo = ''
+ // Still attached from the window's side: the reboot re-greets within seconds and the fw
+ // field corrects itself then. Clearing `updating` is what matters.
+ this.host.onDialStatus?.({ attached: true, fw: this.greetedFw ?? undefined })
return
case 'fw.error':
+ // The outcome is `refused`, not the dial's message: that string is the
+ // firmware's own text and this stream carries short codes.
this.transfer?.finish(`refused: ${str('message') ?? 'no reason given'}`)
this.transfer = null
+ this.offeringTo = ''
+ this.host.onDialStatus?.({ attached: true, fw: this.greetedFw ?? undefined })
return
default:
this.host.log(`cable: unhandled message '${msg.t}'`)
@@ -862,6 +900,7 @@ export class CableSession {
this.offered.add(offerKey)
this.host.log(`cable: offering firmware ${candidate.version} (${candidate.image.length} B)`)
+ this.offeringTo = candidate.version
this.transfer = new FirmwareTransfer(
candidate.image,
candidate.version,
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 58762727e..b792e9e71 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -3036,6 +3036,8 @@ async function runForeground(session: AuthSession): Promise<void> {
// that is alive and answering on another machine. sendTurn is the fork that already knows the
// difference (local → the same door the web and the hooks use, remote → the fleet), and it is the
// one the dial has been using for every voice turn.
+ // A window that connects after the dial did has missed the `dial_status` that announced it.
+ dialStatus: () => cableHostRef?.currentDialStatus() ?? { attached: false },
onRouteSend: (agentId, text) => {
const sent = cableHostRef?.sendTurn(agentId, text) ?? { ok: false as const, machine: '', reason: 'no agent list yet' }
console.log(`[route] ⌘K → ${sid(agentId)} · bytes=${Buffer.byteLength(text, 'utf8')}`
@@ -4048,6 +4050,8 @@ async function runForeground(session: AuthSession): Promise<void> {
focused: (machineId, agentId) =>
backend.sendLocal({ type: 'dial_focus', payload: { machineId, agentId } }),
scrolled: (phase, dy, velocity) => backend.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity } }),
+ // Local-only like the three above: which desk has a dial on it is a fact about THIS computer.
+ dialStatus: (status) => backend.sendLocal({ type: 'dial_status', payload: status }),
// Words spoken on the overview belong to whichever agent the window's palette picks.
routeInWindow: (text, cmd) => windowRouter.ask(text, cmd),
log: (line) => console.log(`[cable] ${line}`),
diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.ts
index 0076a9562..1e73325ac 100644
--- a/cli/src/localWsServer.ts
+++ b/cli/src/localWsServer.ts
@@ -59,6 +59,8 @@ export interface LocalWsServerOptions {
* on a confident route, that is a spoken instruction that vanishes with no mark anywhere.
*/
onRouteSend?: (agentId: string, text: string) => { ok: true } | { ok: false; machine: string; reason: string }
+ /** The dial right now, sent to a window the moment it connects — it may have missed the announcement. */
+ dialStatus?: () => { attached: boolean; fw?: string; updating?: string }
/**
* The window answering a `voice_route_request` — words spoken into the dial that IT was asked to route.
*
@@ -240,6 +242,9 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerO
e2ee: false,
},
})
+ // Right after, not inside `connected`: the window's handshake parser is shared with the
+ // relay path, and a field it does not expect is a field it has to learn to ignore.
+ if (options.dialStatus) sink.sendFrame({ type: 'dial_status', payload: options.dialStatus() })
return
}
// Not this daemon's own machine — relay to backend for the other machines this same