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
fix(cable): words spoken to a Swarm Lead on a Pro post in the Swarm chat (#1618)
0xdiego2566d1c09109a0
diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.tsindex 7251d8ada..6be7d79f1 100644--- a/cli/src/cable/cableHost.ts+++ b/cli/src/cable/cableHost.ts@@ -111,6 +111,8 @@ export interface CableHostWiring {swarmCardRecap?: (tabId: string, leadId: string) => Promise<LeadRecap | null>/** The recap a device (one cable `session`) has open, or null once closed. */swarmCardOpen?: (session: string, tabId: string, leadId: string | null) => void+ /** Words for a Lead that runs here, posted as the person in its Swarm chat; false when the harness leads no project. */+ swarmSay?: (harnessId: string, text: string) => Promise<boolean>/** A device picked a Lead: the window opens that Swarm tab and project. */superTabSelected?: (superTabId: string, projectId: string) => void/** A finger on the dial's glass, in pieces, while it is down. */@@ -429,6 +431,10 @@ export class DaemonCableHost implements CableHost {this.wiring.swarmCardOpen?.(session, tabId, leadId)}+ swarmSay(harnessId: string, text: string): Promise<boolean> {+ return this.wiring.swarmSay?.(harnessId, text) ?? Promise.resolve(false)+ }+superTabSelected(superTabId: string, projectId: string): void {this.wiring.superTabSelected?.(superTabId, projectId)}diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.tsindex 09c20301c..27cb825ee 100644--- a/cli/src/cable/cableSession.spec.ts+++ b/cli/src/cable/cableSession.spec.ts@@ -797,6 +797,23 @@ describe('cable session', () => {await session.stop()})+ it('posts words spoken to a Swarm Lead in its Swarm chat, and types them for any other harness', async () => {+ const swarmSay = vi.fn(async (id: string) => id === 'a1')+ const host = makeHost({ transcribe: vi.fn(async () => 'ship it'), route: vi.fn(), swarmSay })+ const { session, port } = await connect(host)+ try {+ port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' }); await settle()+ port.say({ t: 'voice.begin', uploadId: 'lead', agentId: 'a1' })+ port.pcm(Buffer.alloc(3200)); port.say({ t: 'voice.end' })+ await vi.waitFor(() => expect(port.sent.find(x => x.t === 'voice.transcript')).toMatchObject({ agentId: 'a1', text: 'ship it' }))+ expect(swarmSay).toHaveBeenCalledWith('a1', 'ship it')+ expect(host.sendTurn).not.toHaveBeenCalled()+ port.say({ t: 'voice.begin', uploadId: 'tile', agentId: 'a2' })+ port.pcm(Buffer.alloc(3200)); port.say({ t: 'voice.end' })+ await vi.waitFor(() => expect(host.sendTurn).toHaveBeenCalledWith('a2', 'ship it'))+ } finally { await session.stop() }+ })+it('delivers a turn through the host, not through the protocol', async () => {const host = makeHost()const { session, port } = await connect(host)diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.tsindex e8a928ed0..9006829e6 100644--- a/cli/src/cable/cableSession.ts+++ b/cli/src/cable/cableSession.ts@@ -343,6 +343,8 @@ export interface CableHost {swarmCardRecap?(tabId: string, leadId: string): Promise<LeadRecap | null>/** The recap a device has open (its Lead), or null once it closes: the only one pushed when its text changes. */swarmCardOpen?(session: string, tabId: string, leadId: string | null): void+ /** Words for a Lead that runs here: posted as the person in its Swarm chat. False: not a Lead, send the turn as before. */+ swarmSay?(harnessId: string, text: string): Promise<boolean>/** A device picked a Lead: the window opens that Swarm tab and project. */superTabSelected?(superTabId: string, projectId: string): void/** The Swarm tab the window has on screen and the project open in it; null when the active tab is not a Swarm or there is no window. */@@ -2256,6 +2258,14 @@ export class CableSession {this.voiceDraftCreation = { uploadId, id: state.id }await reply({ t: 'voice.draft', ...state }); return}+ // Spoken to a Swarm Lead (its card or its tile): the words go to the Swarm chat as the person's, where everyone in the+ // tab sees them, not typed into the Lead's terminal. Any other harness, or a failed post, gets the turn as before.+ if (turn.agentId && !carried && !selection?.ok && await this.host.swarmSay?.(agentId, instruction).catch(() => false)) {+ if (!current()) return+ this.log(`cable: voice → Swarm chat of ${agentId.slice(0, 8)}`)+ await reply({ t: 'voice.transcript', routeId: '', text: transcript, agentId, agentName, needsConfirm: false })+ return+ }const text = carried ? withCarriedPassage(instruction, carried): selection?.ok && selection.text ? withSelectedPassage(instruction, selection.text) : instructiontry {diff --git a/cli/src/core/devicesLink.ts b/cli/src/core/devicesLink.tsindex ccdbd4401..e7224ef4d 100644--- a/cli/src/core/devicesLink.ts+++ b/cli/src/core/devicesLink.ts@@ -122,11 +122,12 @@ export function createDevicesLink(deps: DevicesLinkDeps) {models: async ({ agentId }) => ({ models: await core.agents.runtimeModels(text(agentId)) }),fork: async ({ agentId }) => ({ ...await core.agents.fork(text(agentId)) }),machines: () => core.account.machines(),- // The Swarm cards' three requests (core/main.ts `superTabRequest` allows those and no other action of the Super Tab service).+ // The Swarm cards' requests (core/main.ts `superTabRequest` allows those and no other action of the Super Tab service).super_tabs: async (payload) => {if (!core.superTabRequest) return { error: 'SERVICE_UNAVAILABLE' }- const { action, tabId, leadId, on, include, session } = payload- return core.superTabRequest(action === 'cardsWanted' ? { action, on: on === true, include } : { action, tabId, leadId, session })+ const { action, tabId, leadId, on, include, session, harnessId, text } = payload+ return core.superTabRequest(action === 'cardsWanted' ? { action, on: on === true, include }+ : action === 'cardSay' ? { action, harnessId, text } : { action, tabId, leadId, session })},// The transcriber's and the fleet's lane's sign-in, and the lane's sealing, asked of the core at every// use as every service in its own process asks them (core/accountQueries.ts): the devices hold nodiff --git a/cli/src/core/superTabCards.ts b/cli/src/core/superTabCards.tsindex ac9742b9d..f39c2a9fa 100644--- a/cli/src/core/superTabCards.ts+++ b/cli/src/core/superTabCards.ts@@ -134,11 +134,12 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =if (!recap) { log('[super-tabs] a Lead recap was not sound; it is dropped'); return }swarmCardRecap(recap)},- /** What the devices may ask of the Super Tab service, and nothing else of it: `cardsWanted` is kept here, `cardRecap` and- * `cardOpen` go to the service; any other action is refused. */+ /** What the devices may ask of the Super Tab service, and nothing else of it: `cardsWanted` is kept here, `cardRecap`,+ * `cardOpen` and `cardSay` go to the service; any other action is refused. */ask(payload: Record<string, unknown>): Promise<Record<string, unknown>> {if (payload.action === 'cardsWanted') { api.want(payload.on === true, payload.include); return Promise.resolve({ ok: true }) }if (payload.action === 'cardRecap') return route({ action: 'cardRecap', tabId: payload.tabId, leadId: payload.leadId })+ if (payload.action === 'cardSay') return route({ action: 'cardSay', harnessId: payload.harnessId, text: payload.text })if (payload.action === 'cardOpen') return route({ action: 'cardOpen', session: payload.session, tabId: payload.tabId, leadId: payload.leadId })return Promise.resolve({ error: 'INVALID_REQUEST' })},diff --git a/cli/src/services/devices.ts b/cli/src/services/devices.tsindex a0331c1e0..866bd6f4a 100644--- a/cli/src/services/devices.ts+++ b/cli/src/services/devices.ts@@ -159,7 +159,7 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)const pets = new PetStore(deps.petsDir ?? join(env.HARNESS_DEVICES_DIR, 'pets'))// The assistant's latest paragraph per agent, as the processing cards carry it; gone when the turn ends.const latestUpdate = new Map<string, string>()- // The Swarm cards' three requests to the Super Tab service, through the core (core/devicesLink.ts). An error is an answer too.+ // The Swarm cards' requests to the Super Tab service, through the core (core/devicesLink.ts). An error is an answer too.const askCards = async (payload: Record<string, unknown>): Promise<Record<string, unknown>> => {try { return await core.superTabRequest!(payload) } catch { return { error: 'SERVICE_UNAVAILABLE' } }}@@ -229,6 +229,8 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)return { tabId, leadId, text: truncateUtf8(r.text, 1500), at: r.at, none: r.none }},swarmCardOpen: (session, tabId, leadId) => { void askCards({ action: 'cardOpen', session, tabId, leadId }) },+ // An error (no service, a refused post) is not `said`: the words go to the harness instead, never lost.+ swarmSay: async (harnessId, text) => (await askCards({ action: 'cardSay', harnessId, text })).said === true,// The Pro picked a Lead: the window opens that Swarm tab and project. Harmless with no window.superTabSelected: (superTabId, projectId) => core.clients.sendLocal({ type: 'dial_super_tab', payload: { superTabId, projectId } }),scrolled: (phase, dy, velocity) => core.clients.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity } }),diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.tsindex 08d982b80..28eb8761c 100644--- a/cli/src/superTabs/cards.spec.ts+++ b/cli/src/superTabs/cards.spec.ts@@ -97,7 +97,7 @@ function setup(tabs: Record<string, { revision: number; state: Record<string, unlet listFails = falselet pages: Record<string, { next: string | null }> = {}let pageSize = 0- const call = vi.fn(async (method: string, path: string) => {+ const call = vi.fn(async (method: string, path: string, _body?: unknown) => {calls.push(`${method} ${path}`)const [route, query] = path.split('?')if (route === '/api/super-tabs') {@@ -286,6 +286,22 @@ describe('SwarmCards.recap', () => {})})+describe('SwarmCards.say', () => {+ it('posts the words as the person in the Lead\'s conversation of a harness here, and is false for any other harness', async () => {+ const t = setup({ t1: { revision: 1, state: swarm({ agents: [agent('a1', { machineId: 'm2' }), agent('a2')] }) } })+ await t.cards.tick()+ expect(await t.cards.say('h-a2', 'ship it')).toBe(true)+ const post = t.call.mock.calls.find(c => c[0] === 'POST')!+ expect(post[1]).toBe('/api/super-tabs/t1/commands')+ expect(post[2]).toMatchObject({ operationId: expect.stringMatching(/^pro-voice-/),+ command: { type: 'message.send', conversationId: 'lead-mobile', text: 'ship it', replyTo: null, recipientIds: [] } })+ expect(post[2]).not.toHaveProperty('asAgentId')+ expect(await t.cards.say('h-a1', 'x')).toBe(false) // that Lead runs on another machine+ expect(await t.cards.say('h-zz', 'x')).toBe(false)+ expect(t.call.mock.calls.filter(c => c[0] === 'POST')).toHaveLength(1)+ })+})+describe('SwarmCards.want', () => {it('polls every interval while wanted and not at all after want(false)', async () => {vi.useFakeTimers()diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.tsindex 3201e880c..e8cc223ae 100644--- a/cli/src/superTabs/cards.ts+++ b/cli/src/superTabs/cards.ts@@ -8,6 +8,7 @@* `stuck` (`blocked`), `work` (the Lead runs here and is in a turn, or an assignment works or is in review), else `done`.* A paused Swarm keeps its card and every Lead reads `done`.*/+import { randomUUID } from 'node:crypto'import type { CoreApi } from '../core/api.js'import { backend, SuperTabHostError } from './host.js'import { identifier, object } from './wire.js'@@ -284,6 +285,20 @@ export class SwarmCards {} finally { this.recapsRunning-- }}+ /** Words spoken on a Pro to a Lead that runs here (its harness): posted as the person in that Lead's conversation, as typed in+ * the Swarm chat. False when that harness leads no project in the Swarms as last read, so the caller sends the turn as before. */+ async say(harnessId: string, text: string): Promise<boolean> {+ for (const [tabId, { state }] of this.tabs) {+ const agent = list(state.agents).find(a => a.machineId === this.machineId && a.harnessId === harnessId)+ const found = agent && cardId(agent.id) ? this.leadConversation(tabId, agent.id) : null+ if (!found) continue+ await backend(this.core, 'POST', `/api/super-tabs/${tabId}/commands`, { operationId: `pro-voice-${randomUUID()}`,+ command: { type: 'message.send', conversationId: found.id, text, replyTo: null, recipientIds: [] } })+ return true+ }+ return false+ }+/** Remembered recaps are kept only for Leads that are still in a tab. */private prune(): void {for (const [key, held] of this.recaps) if (!this.leadConversation(held.recap.tabId, held.recap.leadId)) this.recaps.delete(key)diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex e686f0b87..2ad72eef5 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -156,7 +156,7 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =// The devices' (core/devicesLink.ts): a Harness Pro that shows the Swarm cards is attached or gone, wants a Lead's recap, or// has one open. They read the account's Swarms as the person, and need no agent.// Only this computer's own devices ask: an account owner on another machine does not make this one read the Swarms.- if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen') {+ if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen' || payload.action === 'cardSay') {if (!asker.local) return { error: 'OWNER_REQUIRED' }if (payload.action === 'cardsWanted') {const include = Array.isArray(payload.include) ? payload.include.filter(cardId) : []@@ -164,6 +164,9 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =return { ok: true }}if (payload.action === 'cardRecap' && cardId(payload.tabId) && cardId(payload.leadId)) return { ok: true, ...await cards().recap(payload.tabId, payload.leadId) }+ if (payload.action === 'cardSay' && cardId(payload.harnessId) && typeof payload.text === 'string' && payload.text.trim() && payload.text.length <= 32_000) {+ return { ok: true, said: await cards().say(payload.harnessId, payload.text.trim()) }+ }if (payload.action === 'cardOpen' && cardId(payload.session) && cardId(payload.tabId) && (payload.leadId === null || cardId(payload.leadId))) {cards().open(payload.session, payload.tabId, payload.leadId)return { ok: true }