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
feat(super-tabs): send each Lead's project order (#1616)
0xdiego253af8c8dc51c3
diff --git a/cli/src/cable/cableHost.spec.ts b/cli/src/cable/cableHost.spec.tsindex 8b4f8d42e..1c7822c8d 100644--- a/cli/src/cable/cableHost.spec.ts+++ b/cli/src/cable/cableHost.spec.ts@@ -963,7 +963,7 @@ describe('DaemonCableHost player library and member ids', () => {})describe('Swarm cards', () => {- const card = { id: 'st1', name: 'openharness', count: 1, leads: [{ id: 'l1', projectId: 'p1', project: 'mobile', engine: 'claude', owner: '', local: '', state: 'work' as const }] }+ const card = { id: 'st1', name: 'openharness', count: 1, leads: [{ id: 'l1', projectId: 'p1', project: 'mobile', engine: 'claude', owner: '', local: '', state: 'work' as const, order: 0 }] }it('keeps the list the core last handed it, and names a Swarm tab\'s Swarm on the desk row', () => {const host = new DaemonCableHost(wiring())diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.tsindex 27cb825ee..595f87285 100644--- a/cli/src/cable/cableSession.spec.ts+++ b/cli/src/cable/cableSession.spec.ts@@ -3685,7 +3685,7 @@ describe('hello capabilities', () => {// ── swarm cards (a Pro that names swarmCard: 'v1') ────────────────────────────────────────────────────describe('swarm cards', () => {const PRO = { t: 'hello', product: 'harness', mac: 'aa:bb', board: 'pro', swarmCard: 'v1' }- const lead = (n: number, over: Partial<SwarmLead> = {}): SwarmLead => ({ projectId: `proj${n}`, project: `Project ${n}`, engine: 'claude', owner: '', local: '', state: 'work', since: 134, ...over, id: over.id ?? `lead${n}` })+ const lead = (n: number, over: Partial<SwarmLead> = {}): SwarmLead => ({ projectId: `proj${n}`, project: `Project ${n}`, engine: 'claude', owner: '', local: '', state: 'work', order: n, since: 134, ...over, id: over.id ?? `lead${n}` })const card = (id: string, leads: SwarmLead[] = [lead(1), lead(2)], over: Partial<SwarmCard> = {}): SwarmCard => ({ id, name: `Swarm ${id}`, count: leads.length, leads, ...over })const ofType = (port: LoopbackPort, t: string) => port.sent.filter((m) => m.t === t)/** The firmware's JSON guard counts one token per object, array, string (keys included) and bare value. */@@ -3743,8 +3743,8 @@ describe('swarm cards', () => {expect(ofType(port, 'supertabs')).toEqual([{ t: 'supertabs', ids: ['st1', 'st2'] }])expect(ofType(port, 'supertab')).toEqual([{ t: 'supertab', id: 'st1', tab: '', name: 'Swarm st1', count: 2, leads: [- { id: 'lead1', projectId: 'proj1', project: 'Project 1', engine: 'claude', owner: '', local: '', state: 'work', since: 134 },- { id: 'lead2', projectId: 'proj2', project: 'Project 2', engine: 'claude', owner: '', local: '', state: 'work', since: 134 }] },+ { id: 'lead1', projectId: 'proj1', project: 'Project 1', engine: 'claude', owner: '', local: '', state: 'work', order: 1, since: 134 },+ { id: 'lead2', projectId: 'proj2', project: 'Project 2', engine: 'claude', owner: '', local: '', state: 'work', order: 2, since: 134 }] },expect.objectContaining({ id: 'st2', tab: 'tab9' }),])// The list goes first, so the Pro knows the order the details fill.@@ -3814,7 +3814,7 @@ describe('swarm cards', () => {it('a 16 x 12 list is one supertabs and 16 supertab frames, each under 512 JSON tokens', async () => {const wide = 'é'.repeat(24) // 48 bytesconst cards = Array.from({ length: 18 }, (_, s) => card(`st${s}`,- Array.from({ length: 13 }, (_, l) => lead(l, { project: wide, owner: wide, local: 'a'.repeat(64), engine: 'codex', id: `l${s}x${l}`, projectId: `p${l}` })),+ Array.from({ length: 13 }, (_, l) => lead(l, { project: wide, owner: wide, local: 'a'.repeat(64), engine: 'codex', id: `l${s}x${l}`, projectId: `p${l}`, order: 100 + l })),{ name: wide, count: 40 }))const { session, port } = await connect(cardHost({ cards }))try {@@ -3826,11 +3826,25 @@ describe('swarm cards', () => {const frames = port.sent.map((m, i) => ({ ...m, seq: port.seqs[i] } as Record<string, unknown>)).filter((m) => m.t === 'supertabs' || m.t === 'supertab')expect(frames).toHaveLength(17)for (const f of frames) expect(tokens(f)).toBeLessThan(512)- for (const f of ofType(port, 'supertab')) expect((f.leads as unknown[]).length).toBe(12)+ for (const f of ofType(port, 'supertab')) expect((f.leads as Array<{ order: number }>).map((l) => l.order)).toEqual(Array.from({ length: 12 }, (_, l) => 100 + l))expect(Math.max(...frames.map(tokens))).toBeLessThan(260)} finally { await session.stop() }})+ it('a round dial naming both capabilities gets the Swarms with no seq, and Super Tab waits on question', async () => {+ const { session, port } = await connect(cardHost({ cards: [card('st1', [lead(1, { order: 3 }), lead(2, { order: 0 })])] }))+ try {+ port.say({ t: 'hello', product: 'harness', mac: 'cc:dd', swarmCard: 'v1', superTab: 'wait-v1' })+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))+ expect(ofType(port, 'supertabs')).toEqual([{ t: 'supertabs', ids: ['st1'] }])+ expect((ofType(port, 'supertab')[0].leads as Array<{ id: string; order: number }>).map((l) => [l.id, l.order])).toEqual([['lead1', 3], ['lead2', 0]])+ expect(port.seqs.every((seq) => seq === undefined)).toBe(true)+ await session.question('a1', 'supertab:as1:needs_human', [{ q: 'Which?' }], { superTab: 'Pilot', attention: 'decision' })+ expect(ofType(port, 'question')).toMatchObject([{ agentId: 'a1', id: 'supertab:as1:needs_human', superTab: 'Pilot', attention: 'decision' }])+ expect(port.seqs.every((seq) => seq === undefined)).toBe(true)+ } finally { await session.stop() }+ })+it('resync sends everything again, as attach does', async () => {const state = { cards: [card('st1')], open: { superTabId: 'st1', projectId: 'proj2', fromDevice: false } }const { session, port } = await connect(cardHost(state))diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.tsindex 9006829e6..9a70da7f3 100644--- a/cli/src/cable/cableSession.ts+++ b/cli/src/cable/cableSession.ts@@ -2657,7 +2657,7 @@ export class CableSession {const tab = desk.find((s) => s.superTabId === card.id)?.id ?? ''const frame = { t: 'supertab', id: card.id, tab, name: card.name, count: card.count,leads: card.leads.slice(0, SWARM_LEADS_MAX).map((l) => ({ id: l.id, projectId: l.projectId, project: l.project,- engine: l.engine, owner: l.owner, local: l.local, state: l.state, ...(l.since === undefined ? {} : { since: l.since }) })) }+ engine: l.engine, owner: l.owner, local: l.local, state: l.state, order: l.order, ...(l.since === undefined ? {} : { since: l.since }) })) }const key = JSON.stringify(frame)if (this.cardKeys.get(card.id) === key) continuethis.cardKeys.set(card.id, key)diff --git a/cli/src/core/superTabCards.spec.ts b/cli/src/core/superTabCards.spec.tsindex 9afad1bb5..f5596a4e5 100644--- a/cli/src/core/superTabCards.spec.ts+++ b/cli/src/core/superTabCards.spec.ts@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'import { createSuperTabCards } from './superTabCards.js'const lead = (id: string, over: Record<string, unknown> = {}) =>- ({ id, projectId: `p-${id}`, project: 'mobile', engine: 'claude', owner: '', local: 'h1', state: 'work', since: 12, ...over })+ ({ id, projectId: `p-${id}`, project: 'mobile', engine: 'claude', owner: '', local: 'h1', state: 'work', order: 0, since: 12, ...over })const card = (id: string, leads: unknown[] = [lead('l1')], over: Record<string, unknown> = {}) => ({ id, name: 'openharness', count: 4, leads, ...over })const recap = (over: Record<string, unknown> = {}) => ({ tabId: 't1', leadId: 'l1', text: 'Shipped it', at: 1792560000, none: false, ...over })@@ -17,11 +17,12 @@ describe('the Swarm cards on the devices', () => {const { cards, swarmCards } = setup()cards.replay()expect(swarmCards).not.toHaveBeenCalled()- const list = [card('t1', [lead('l1'), lead('l2', { state: 'ask' }, ), lead('l3', { since: undefined })])]+ const list = [card('t1', [lead('l1', { order: 2 }), lead('l2', { state: 'ask', order: 0 }), lead('l3', { since: undefined, order: 5 })])]cards.cards(list)expect(swarmCards).toHaveBeenLastCalledWith(JSON.parse(JSON.stringify(list)))// Without `since` the key is left out; with an empty owner the lead is still whole.expect(swarmCards.mock.calls[0][0][0].leads[2]).not.toHaveProperty('since')+ expect(swarmCards.mock.calls[0][0][0].leads.map((l: { order: number }) => l.order)).toEqual([2, 0, 5])swarmCards.mockClear()cards.replay()expect(swarmCards).toHaveBeenCalledOnce()@@ -40,6 +41,7 @@ describe('the Swarm cards on the devices', () => {'not a list', [null], [card('bad id')], [card('')], [card('x'.repeat(65))], [card('x'.repeat(48))], [card('t1', [lead('l1', { local: 'x'.repeat(48) })])], [card('t1', 'nope' as never)], [card('t1', [lead('bad id')])],[card('t1', [lead('l1', { projectId: 'no good' })])], [card('t1', [lead('l1', { state: 'sleeping' })])], [card('t1', [lead('l1', { project: 7 })])],[card('t1', [lead('l1', { local: 'bad local' })])], [card('t1', [lead('l1', { since: -1 })])], [card('t1', [lead('l1', { since: 'soon' })])],+ [card('t1', [lead('l1', { order: undefined })])], [card('t1', [lead('l1', { order: -1 })])], [card('t1', [lead('l1', { order: 1.5 })])],[card('t1', [lead('l1')], { count: -1 })], [card('t1', [lead('l1')], { count: 1.5 })], [card('t1', [lead('l1')], { name: 3 })],]for (const list of bad) cards.cards(list)diff --git a/cli/src/core/superTabCards.ts b/cli/src/core/superTabCards.tsindex f39c2a9fa..bc8359b8e 100644--- a/cli/src/core/superTabCards.ts+++ b/cli/src/core/superTabCards.ts@@ -52,9 +52,11 @@ function leadIn(value: unknown): SwarmLead | null {// `local` is the harness here that runs the Lead, or empty when it runs on another machine.if (typeof lead.local !== 'string' || (lead.local !== '' && !id(lead.local))) return nullif (lead.since !== undefined && !whole(lead.since)) return null+ // The project's index in its Swarm, which the round dial shows the Leads by (the Pro sorts its own and ignores it).+ if (!whole(lead.order)) return nullreturn {id: lead.id, projectId: lead.projectId, project: cut(lead.project, NAME_BYTES), engine: cut(lead.engine, ENGINE_BYTES),- owner: cut(lead.owner, NAME_BYTES), local: lead.local, state: lead.state as SwarmLead['state'],+ owner: cut(lead.owner, NAME_BYTES), local: lead.local, state: lead.state as SwarmLead['state'], order: lead.order,...(lead.since === undefined ? {} : { since: lead.since }),}}diff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.tsindex 42ed02b26..6a6ec80db 100644--- a/cli/src/services/devices.spec.ts+++ b/cli/src/services/devices.spec.ts@@ -553,7 +553,7 @@ describe('what the windows say, reaching the dial', () => {})describe('the Swarm cards for a Harness Pro', () => {- const lead = { id: 'lead1', projectId: 'proj1', project: 'mobile', engine: 'claude', owner: '', local: '', state: 'work' as const }+ const lead = { id: 'lead1', projectId: 'proj1', project: 'mobile', engine: 'claude', owner: '', local: '', state: 'work' as const, order: 0 }const cards = [{ id: 'st1', name: 'openharness', count: 1, leads: [lead] }]const withRequest = (superTabRequest?: CoreApi['superTabRequest']) => start({ core: { ...fakeCore({ dataDir }), ...(superTabRequest ? { superTabRequest } : {}) } as CoreApi })diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.tsindex 28eb8761c..87e3ade37 100644--- a/cli/src/superTabs/cards.spec.ts+++ b/cli/src/superTabs/cards.spec.ts@@ -67,6 +67,22 @@ describe('leadsOf', () => {expect(leads.slice(0, 5).map(l => [l.project, l.state])).toEqual([['P7', 'ask'], ['P9', 'ask'], ['P5', 'stuck'], ['P2', 'work'], ['P0', 'done']])})+ it('gives each Lead its project\'s index as `order`, whatever place urgency gives it', () => {+ const three = swarm({+ projects: [...swarm().projects, { id: 'api', name: 'api', leadConversationId: 'lead-api' }],+ agents: [agent('a1'), agent('a2'), agent('a3')],+ conversations: [...swarm().conversations, conv('lead-api', 'a3', { projectId: 'api' }), work('mobile', 'needs_human'), work('api', 'working')],+ })+ expect(leadsOf(three, 'm1', idle).leads.map(l => [l.project, l.state, l.order])).toEqual([['mobile', 'ask', 1], ['api', 'work', 2], ['web', 'done', 0]])+ // The 12 most urgent of 13 keep their own index: the one left out leaves a gap.+ const projects = Array.from({ length: 13 }, (_, i) => ({ id: `p${i}`, name: `P${i}`, leadConversationId: `lead-p${i}` }))+ const many = swarm({ projects, agents: projects.map((_, i) => agent(`a${i}`)),+ conversations: [...projects.map((p, i) => conv(p.leadConversationId, `a${i}`, { projectId: p.id })), ...projects.slice(1).map(p => work(p.id, 'working'))] })+ expect(leadsOf(many, 'm1', idle).leads.map(l => l.order)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])+ const old = { name: 'Old', agents: [agent('a1')], people: [], conversations: [{ id: 'lead', leadId: 'a1', assignment: null }] }+ expect(leadsOf(old, 'm1', idle).leads[0].order).toBe(0)+ })+it('cuts a name to 48 bytes on a character boundary and reads a paused Swarm as done', () => {const named = swarm({ projects: [{ id: 'web', name: `${'a'.repeat(47)}éé`, leadConversationId: 'lead-web' }] })expect(leadsOf(named, 'm1', idle).leads[0].project).toBe('a'.repeat(47))diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.tsindex e8cc223ae..757549d7d 100644--- a/cli/src/superTabs/cards.ts+++ b/cli/src/superTabs/cards.ts@@ -15,7 +15,8 @@ import { identifier, object } from './wire.js'type Json = Record<string, unknown>export type LeadState = 'ask' | 'stuck' | 'work' | 'done'-export interface SwarmLead { id: string; projectId: string; project: string; engine: string; owner: string; local: string; state: LeadState; since?: number }+/** `order`: the project's index in the Swarm (the app's order), so a dial can show the Leads as the app does whatever their urgency. */+export interface SwarmLead { id: string; projectId: string; project: string; engine: string; owner: string; local: string; state: LeadState; order: number; since?: number }export interface SwarmCard { id: string; name: string; count: number; leads: SwarmLead[] }export interface LeadRecap { tabId: string; leadId: string; text: string; at: number; none: boolean }@@ -38,7 +39,8 @@ function cut(text: string, bytes: number): string {const list = (v: unknown): Json[] => Array.isArray(v) ? v.map(object) : []/**- * One Lead per project of the Swarm, in project order then by urgency. `live` says whether this machine's core has a+ * One Lead per project of the Swarm, most urgent first with ties in project order; the 12 most urgent are kept, and each+ * carries its project's index as `order` (gaps where a project has no Lead or was cut). `live` says whether this machine's core has a* harness and whether it is in a turn (null: not here); `me` is the signed-in person's id, so a Lead on someone else's* machine names that owner (people[] has an email, which is the name a Swarm shows a person by).*/@@ -48,7 +50,7 @@ export function leadsOf(state: Json, machineId: string, live: (harnessId: stringconst projects = Array.isArray(state.projects) ? list(state.projects) : [{ id: 'lead', name: state.name, leadConversationId: 'lead' }]const paused = state.paused === trueconst leads: SwarmLead[] = []- for (const project of projects) {+ for (const [order, project] of projects.entries()) {const lead = conversations.find(c => c.id === project.leadConversationId)const agent = lead && agents.find(a => a.id === lead.leadId)if (!agent) continue@@ -69,7 +71,7 @@ export function leadsOf(state: Json, machineId: string, live: (harnessId: stringleads.push({id: String(agent.id), projectId: String(project.id ?? 'lead'), project: cut(String(project.name ?? ''), NAME_BYTES), engine: String(object(agent.configuration).engine ?? ''),owner: owner && typeof owner.email === 'string' ? cut(owner.email, NAME_BYTES) : '',- local: here && cardId(harnessId) ? harnessId : '', state, ...(since !== undefined ? { since } : {}),+ local: here && cardId(harnessId) ? harnessId : '', state, order, ...(since !== undefined ? { since } : {}),})}// Array.sort is stable: equal urgency keeps the project order.diff --git a/devices/harness-pro/docs/cable.md b/devices/harness-pro/docs/cable.mdindex 65aa387b4..1032c498c 100644--- a/devices/harness-pro/docs/cable.md+++ b/devices/harness-pro/docs/cable.md@@ -200,12 +200,15 @@ Daemon to Pro:{"t":"supertabs","ids":["<superTabId>",...]} the set and order of the Swarms (at most 16); a Swarm not listed is dropped{"t":"supertab","id":"<superTabId>","tab":"<desk tab id or empty>","name":"openharness","count":4,"leads":[{"id":"<leadAgentId>","projectId":"<projectId>","project":"mobile","engine":"claude","owner":"","local":"<harnessId or empty>",- "state":"ask|stuck|work|done","since":134}]} one per Swarm, replacing it; `leads` in card order+ "state":"ask|stuck|work|done","order":1,"since":134}]} one per Swarm, replacing it; `leads` in card order{"t":"supertab.recap","tab":"<superTabId>","lead":"<leadAgentId>","text":"...","at":1792560000,"none":false} a Lead's last message (answers recap.get, and is pushed while that Lead is open){"t":"supertab.focus","tab":"<superTabId>","lead":"<leadAgentId>"} the desktop opened this Swarm project```- `tab` links a Swarm to the desk tab of the same Swarm (empty: the desktop has none open); a linked desk tab shows the Swarm's card, an unlinked Swarm is one more Home page after the tabs.+- `leads` come most urgent first (`ask`, `stuck`, `work`, `done`), ties in project order, and only the 12 most urgent are sent. `order` (optional) is the project's+ 0-based place in the Swarm as the app lists it (an old Swarm without projects is 0), so the round dial can show the Leads in the app's order; values may skip+ where a project has no Lead or was cut. The Pro ignores it and keeps its own order.- `state`: `ask` (needs you), `stuck`, `work`, `done`. `since` is the seconds into the turn of a local Lead at work (the Pro counts on from it); a remote Lead at work has none and shows "working".- `local` is the harness id of a Lead that runs on this account's machine, else empty. A Lead with `local` offers the usual talk control in its view; a remote one (`owner` names theperson whose machine) has none.diff --git a/devices/harness-pro/firmware/test/test_pro_cable.c b/devices/harness-pro/firmware/test/test_pro_cable.cindex 6f5e79fdc..24b7ad89f 100644--- a/devices/harness-pro/firmware/test/test_pro_cable.c+++ b/devices/harness-pro/firmware/test/test_pro_cable.c@@ -1126,6 +1126,25 @@ static void test_swarm_cards(void)CHECK(rec_card.leads[1].state == POD_LEAD_STUCK && !strcmp(rec_card.leads[1].owner, "Mai") && rec_card.leads[1].projectId[0] == 0 &&rec_card.leads[2].state == POD_LEAD_WORK && rec_card.leads[2].since_s == 9);+ // a daemon from the round dial's Swarm tab on adds `order` to each Lead: the Pro reads past it to the same model+ static const char *plain_leads = "{\"id\":\"L1\",\"projectId\":\"P1\",\"project\":\"mobile\",\"engine\":\"claude\",\"owner\":\"\",\"local\":\"H1\",\"state\":\"ask\",\"since\":134},"+ "{\"id\":\"L2\",\"project\":\"web\",\"engine\":\"codex\",\"owner\":\"Mai\",\"local\":\"\",\"state\":\"done\"}";+ static const char *order_leads = "{\"id\":\"L1\",\"projectId\":\"P1\",\"project\":\"mobile\",\"engine\":\"claude\",\"owner\":\"\",\"local\":\"H1\",\"state\":\"ask\",\"order\":2,\"since\":134},"+ "{\"order\":0,\"id\":\"L2\",\"project\":\"web\",\"engine\":\"codex\",\"owner\":\"Mai\",\"local\":\"\",\"state\":\"done\"}";+ reset();+ feedf("{\"t\":\"supertab\",\"id\":\"S1\",\"tab\":\"T1\",\"name\":\"openharness\",\"count\":2,\"leads\":[%s]}", plain_leads);+ pod_swarm_t plain = rec_card;+ reset();+ feedf("{\"t\":\"supertab\",\"id\":\"S1\",\"tab\":\"T1\",\"name\":\"openharness\",\"count\":2,\"leads\":[%s]}", order_leads);+ CHECK(nev == 1 && evs[0].kind == EV_SUPERTAB && rec_card.lead_n == 2 && plain.lead_n == 2);+ CHECK(!strcmp(rec_card.id, plain.id) && !strcmp(rec_card.tab, plain.tab) && !strcmp(rec_card.name, plain.name) && rec_card.count == plain.count);+ for (int i = 0; i < 2; i++) {+ const pod_lead_t *a = &plain.leads[i], *b = &rec_card.leads[i];+ CHECK(!strcmp(a->id, b->id) && !strcmp(a->projectId, b->projectId) && !strcmp(a->project, b->project) && !strcmp(a->engine, b->engine) &&+ !strcmp(a->owner, b->owner) && !strcmp(a->local, b->local) && a->state == b->state && a->since_s == b->since_s &&+ a->recap == b->recap && a->text == b->text && a->text_at == b->text_at);+ }+// 15 Leads -> 12; count absent -> the Leads listedreset();w = snprintf(big, sizeof big, "{\"t\":\"supertab\",\"id\":\"s\",\"name\":\"n\",\"count\":15,\"leads\":[");