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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Dial: a machine switch is a tick of the wheel, not a re-stream
0xdiego25248036adc061
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.tsindex 047984cba..e34ec254a 100644--- a/cli/src/cable/cableSession.spec.ts+++ b/cli/src/cable/cableSession.spec.ts@@ -1046,10 +1046,12 @@ describe('cable session', () => {await session.stop()})- it('sends the new list even when it hashes identically to the old one', async () => {- // Two machines whose agents share names and engines produce an EQUAL agentsKey. Without resetting it- // on a switch, the dial would keep the previous machine's tiles and nothing would ever correct it.- const twin: CableAgent[] = [...AGENTS]+ it('re-sends neither the list nor the history when a select changes neither', async () => {+ // The carousel spans every machine: `listAgentsFlat` reads the same agents whichever row wears the ✓,+ // so moving the ✓ changes the machine wheel and nothing else. This used to force both pushes anyway —+ // 55 frames of a list and a history the dial already had, down a cable the `focus` the person just+ // clicked has to share. Measured on the desk: the focus was written in 20 ms and landed 1.7 s later.+ const everywhere: CableAgent[] = [...AGENTS]let selected = 'mac-local'const host = makeHost({listMachines: async () => ({@@ -1058,16 +1060,46 @@ describe('cable session', () => {}),selectedMachine: () => selected,selectMachine: async (id: string) => { selected = id; return { ok: true as const } },- listAgents: async () => twin,+ listAgents: async () => everywhere,+ recentSummaries: async () => [{ recap: 'shipped it', text: 'shipped it' }],})const { session, port } = await connect(host)port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' })await vi.waitFor(() => expect(port.types()).toContain('agents.end'))+ await vi.waitFor(() => expect(port.types()).toContain('summary')) // the attach DOES restoreport.sent.length = 0port.say({ t: 'machine.select', machineId: 'm2' })- await vi.waitFor(() => expect(port.types()).toContain('agents.end'))- expect(port.sent.filter((m) => m.t === 'agent')).toHaveLength(2)+ await vi.waitFor(() => expect(port.types()).toContain('machine.selected'))+ await settle()++ expect(port.types()).toContain('machines.end') // the ✓ moved, so the wheel is re-sent+ expect(port.types()).not.toContain('agent') // the tiles did not+ expect(port.types()).not.toContain('summary') // nor the history behind them+ await session.stop()+ })++ it('restores a tile that appears after the attach, and only that one', async () => {+ // A remote machine's agents reach the cache seconds after the greeting, so the attach's restore ran+ // before they existed. They must still arrive with their history — without dragging every tile that+ // already has one back down the cable behind them.+ let agents: CableAgent[] = [{ id: 'a1', name: 'one' }]+ const asked: string[] = []+ const { session, port } = await connect(makeHost({+ listAgents: async () => agents,+ recentSummaries: async (agentId: string) => { asked.push(agentId); return [{ recap: 'shipped it', text: '' }] },+ }))+ port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' })+ await vi.waitFor(() => expect(port.types()).toContain('summary'))+ port.sent.length = 0+ asked.length = 0++ agents = [...agents, { id: 'r1', name: 'the remote one' }] // that machine's list just landed+ await session.syncAgents()+ await vi.waitFor(() => expect(port.types()).toContain('summary'))++ expect(asked).toEqual(['r1'])+ expect(port.sent.filter((m) => m.t === 'summary').map((m) => m.agentId)).toEqual(['r1'])await session.stop()})diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.tsindex be0f3ed63..378c86c2e 100644--- a/cli/src/cable/cableSession.ts+++ b/cli/src/cable/cableSession.ts@@ -1139,6 +1139,11 @@ export class CableSession {this.expectedAppFocusEchoUntil = Date.now() + APP_FOCUS_SETTLE_MSawait this.focusAgent(this.desiredFocus)}++ // A tile that has just appeared has no history on the dial. The usual case is a remote machine: its+ // agents reach the cache seconds after the greeting, long after the attach pushed everyone else's.+ // Cheap to say on every change — [restored] makes it a no-op for every tile already carrying one.+ this.restoreInBackground()}/**@@ -1154,6 +1159,20 @@ export class CableSession {* Sent on attach only. The list is re-sent whenever it changes; the history behind it does not, or every* rename would replay a week of recaps.*/+ /**+ * Agents whose history the dial has already been given.+ *+ * THE DIAL KEEPS WHAT IT IS TOLD. Re-sending a tile's recaps buys nothing and costs 55 frames down a+ * cable that the `focus` somebody just clicked has to share — measured: a switch every second kept the+ * link saturated, and the focus, written in 20 ms, reached the glass 1.7 s later.+ *+ * Cleared on attach, which is the one moment the dial genuinely has nothing: a replug, a reboot, an OTA.+ */+ private readonly restored = new Set<string>()++ /** A background restore already walking the list, so a second trigger joins it rather than racing it. */+ private restoring = false+async pushRestores(): Promise<void> {// READ FIRST, QUEUE SECOND, and the split is the whole point. A remote agent's history is a cloud// round trip and there is one per agent; asking for them from INSIDE the push chain holds every frame@@ -1162,8 +1181,13 @@ export class CableSession {// on the first `agent_recent` while the dial sat on the old tile.const rows: Array<{ id: string; past: Array<{ recap: string; text: string }> }> = []for (const a of await this.host.listAgents()) {+ // Marked as it is ASKED FOR, not as it is sent: the answer is a cloud round trip, and a tick+ // arriving mid-loop would otherwise start a second walk over the same agents.+ if (this.restored.has(a.id)) continue+ this.restored.add(a.id)rows.push({ id: a.id, past: await this.host.recentSummaries(a.id) })}+ if (!rows.length) returnreturn this.queued(async () => {for (const row of rows) {// Oldest first, so the newest ends up on top of the tile's stack.@@ -1183,14 +1207,28 @@ export class CableSession {* no beep, no notification — so nothing about it is worth a second of staring at the old tile.*/private restoreInBackground(): void {- void this.pushRestores().catch((err) => this.log(`cable: restores failed (${(err as Error).message})`))+ if (this.restoring) return+ this.restoring = true+ void this.pushRestores()+ .catch((err) => this.log(`cable: restores failed (${(err as Error).message})`))+ .finally(() => { this.restoring = false })}/** Attach: tell the dial everything, whether or not any of it looks unchanged from here. */async pushAgents(): Promise<void> {- await this.syncMachines(true)- await this.syncSwarms(true)- await this.syncAgents(true)+ // A dial that has just greeted us has no history at all — it rebooted, or the cable was out. This is+ // the one place that says so; everywhere else, [restored] is what keeps the link quiet.+ this.restored.clear()+ // Attach owns this walk. Held across the list push so the trigger inside it does not start the same+ // one from the other end and leave the caller awaiting a restore that has nothing left to send.+ this.restoring = true+ try {+ await this.syncMachines(true)+ await this.syncSwarms(true)+ await this.syncAgents(true)+ } finally {+ this.restoring = false+ }await this.pushRestores()}@@ -1263,7 +1301,7 @@ export class CableSession {if (!machineId) returnif (machineId === this.host.selectedMachine()) {await this.send({ t: 'machine.selected', machineId })- await this.syncAgents(true)+ await this.syncAgents()this.restoreInBackground()return}@@ -1274,14 +1312,19 @@ export class CableSession {return}this.log(`cable: machine.select → ${machineId}`)- // REQUIRED, not hygiene: two machines whose agents happen to share names and engines produce an equal- // agentsKey, and the new machine's list would then never be sent at all.- this.lastAgentsKey = ''await this.send({ t: 'machine.selected', machineId })- await this.syncAgents(true)- await this.syncMachines(true) // the ✓ moved, and the agent counts with it- // LAST, AND NOT AWAITED. This is what the caller is blocked on: `followApp` selects the machine and- // only then commands the focus, so anything awaited here is time the dial spends on the old tile.+ // NOT FORCED, and that is the fix for a switch that felt slow at random.+ //+ // Forcing both was right when the carousel showed ONE machine at a time: selecting another machine+ // replaced every tile, so the list and its history had to be re-streamed. The carousel now spans every+ // machine — `listAgentsFlat` reads the same 22 agents whichever row wears the ✓ — so a forced push+ // re-sends a list and a history the dial already has, 55 frames of it, and the `focus` the person is+ // waiting on queues behind them on the wire. Measured: 20 ms to write the focus, 1.7 s to land it.+ //+ // The diff still sends anything that GENUINELY changed, including a machine whose agents have only+ // just arrived in the cache — and [restored] means those, and only those, bring their history along.+ await this.syncAgents()+ await this.syncMachines() // the ✓ moved: `machinesKey` carries the selection, so this pushesthis.restoreInBackground()}