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(pro): the Swarm card — workspaces, their Leads and the Lead's last word (#1537)

0xdiego2575ab2013e4d0
diff --git a/cli/src/cable/cableFleet.spec.ts b/cli/src/cable/cableFleet.spec.ts
index ce78f49d7..f3873109e 100644
--- a/cli/src/cable/cableFleet.spec.ts
+++ b/cli/src/cable/cableFleet.spec.ts
@@ -291,6 +291,10 @@ describe('USB dial fleet', () => {
expect(f.host.onDialAttached).toHaveBeenCalledTimes(1)
await f.fleet.turnStarted('a', 'Working')
for (const port of f.ports) expect(port.sent).toContainEqual({ t: 'turn.started', agentId: 'a', text: 'Working' })
+ // The Swarm cards reach every session; a dial that did not name them is sent nothing.
+ await f.fleet.syncSwarmCards(true)
+ await f.fleet.swarmCardRecap({ tabId: 'st1', leadId: 'l1', text: 'x', at: 1, none: false })
+ for (const port of f.ports) expect(port.sent.some(m => String(m.t).startsWith('supertab'))).toBe(false)
f.setPorts([device('/dev/tux', 'BB:02')]); await f.fleet['scan']()
expect(f.ports[0].isOpen).toBe(false)
expect(f.ports[1].isOpen).toBe(true)
diff --git a/cli/src/cable/cableFleet.ts b/cli/src/cable/cableFleet.ts
index 38b252d9a..328875a26 100644
--- a/cli/src/cable/cableFleet.ts
+++ b/cli/src/cable/cableFleet.ts
@@ -322,6 +322,8 @@ export class CableFleet {
syncAgents(...args: Parameters<Surface['syncAgents']>) { return this.send('syncAgents', ...args) }
syncSwarms(...args: Parameters<Surface['syncSwarms']>) { return this.send('syncSwarms', ...args) }
syncMachines(...args: Parameters<Surface['syncMachines']>) { return this.send('syncMachines', ...args) }
+ syncSwarmCards(...args: Parameters<Surface['syncSwarmCards']>) { return this.send('syncSwarmCards', ...args) }
+ swarmCardRecap(...args: Parameters<Surface['swarmCardRecap']>) { return this.send('swarmCardRecap', ...args) }
followApp(...args: Parameters<Surface['followApp']>) { return this.send('followApp', ...args) }
replaceNotifications(...args: Parameters<Surface['replaceNotifications']>) { return this.send('replaceNotifications', ...args) }
agentSeen(...args: Parameters<Surface['agentSeen']>) { return this.send('agentSeen', ...args) }
diff --git a/cli/src/cable/cableHost.spec.ts b/cli/src/cable/cableHost.spec.ts
index 18187f021..8b4f8d42e 100644
--- a/cli/src/cable/cableHost.spec.ts
+++ b/cli/src/cable/cableHost.spec.ts
@@ -961,3 +961,56 @@ describe('DaemonCableHost player library and member ids', () => {
AGENTS.length = 0
})
})
+
+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 }] }
+
+ 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())
+ expect(host.swarmCards()).toEqual([])
+ host.setSwarmCards([card])
+ expect(host.swarmCards()).toEqual([card])
+ host.setSwarms({ active: 't2', tiles: [], swarms: [
+ { id: 't1', name: 'Work', agentIds: ['a'], panes: 1 },
+ { id: 't2', name: 'openharness', agentIds: [], panes: 1, superTabId: 'st1', projectId: 'p1' },
+ ] })
+ expect(host.listSwarms().swarms).toEqual([
+ { id: 't1', name: 'Work', agents: 1, agentIds: ['a'], panes: 1 },
+ { id: 't2', name: 'openharness', agents: 0, agentIds: [], panes: 1, superTabId: 'st1' },
+ ])
+ })
+
+ it('says which Swarm project the window has open: only on a Swarm tab that names one, with the device mark', () => {
+ const host = new DaemonCableHost(wiring())
+ expect(host.activeSwarmProject()).toBeNull() // no window
+ const swarms = [
+ { id: 't1', name: 'Work', agentIds: [], panes: 0 },
+ { id: 't2', name: 'Swarm', agentIds: [], panes: 1, superTabId: 'st1', projectId: 'p1' },
+ { id: 't3', name: 'Swarm, no project', agentIds: [], panes: 1, superTabId: 'st1' },
+ ]
+ host.setSwarms({ active: 't1', swarms, tiles: [] })
+ expect(host.activeSwarmProject()).toBeNull()
+ host.setSwarms({ active: 't2', swarms, tiles: [] })
+ expect(host.activeSwarmProject()).toEqual({ superTabId: 'st1', projectId: 'p1', fromDevice: false })
+ host.setSwarms({ active: 't2', swarms, tiles: [], fromDevice: true })
+ expect(host.activeSwarmProject()).toEqual({ superTabId: 'st1', projectId: 'p1', fromDevice: true })
+ host.setSwarms({ active: 't3', swarms, tiles: [] })
+ expect(host.activeSwarmProject()).toBeNull()
+ })
+
+ it('hands the wiring what a device asks, and answers nothing when the wiring has none', async () => {
+ const w = wiring({
+ swarmCardsWanted: vi.fn(), swarmCardOpen: vi.fn(), superTabSelected: vi.fn(),
+ swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'hi', at: 1, none: false })),
+ })
+ const host = new DaemonCableHost(w)
+ host.swarmCardsWanted(true); host.swarmCardOpen('c1', 'st1', 'l1'); host.superTabSelected('st1', 'p1')
+ expect(w.swarmCardsWanted).toHaveBeenCalledWith(true)
+ expect(w.swarmCardOpen).toHaveBeenCalledWith('c1', 'st1', 'l1')
+ expect(w.superTabSelected).toHaveBeenCalledWith('st1', 'p1')
+ expect(await host.swarmCardRecap('st1', 'l1')).toEqual({ tabId: 'st1', leadId: 'l1', text: 'hi', at: 1, none: false })
+ const bare = new DaemonCableHost(wiring())
+ bare.swarmCardsWanted(false); bare.swarmCardOpen('c1', 'st1', null); bare.superTabSelected('st1', 'p1')
+ expect(await bare.swarmCardRecap('st1', 'l1')).toBeNull()
+ })
+})
diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.ts
index acb034407..7251d8ada 100644
--- a/cli/src/cable/cableHost.ts
+++ b/cli/src/cable/cableHost.ts
@@ -28,6 +28,7 @@ import type { FleetRouting } from '../services/fleet.js'
import { ServiceUnavailableError } from '../core/serviceHost.js'
import { PLAYER_STATES, type PlayerSession } from './playerLibrary.js'
+import type { LeadRecap, SwarmCard } from '../superTabs/cards.js'
import type { ActivitySnapshot, AppSwarms, SuperTabAsk, CableAgent, CableHost, CableMachine, CableMachineSource, CableSwarm, CableTile, DialStatus, OpenReason, RouteDecision } from './cableSession.js'
import type { WindowRoute } from './windowRoute.js'
import type { SelectionCommand, SelectionResult } from './windowSelection.js'
@@ -104,6 +105,14 @@ export interface CableHostWiring {
forkAgent?: (agentId: string) => Promise<{ ok: true; agentId: string } | { ok: false; error: string; detail?: string }>
/** The dial picked a swarm: the window switches to it. */
swarmSelected?: (swarmId: string) => void
+ /** A Harness Pro came with Swarm cards (true) or the last one went (false): the core reads the Swarms only meanwhile. */
+ swarmCardsWanted?: (on: boolean) => void
+ /** One Lead's last message, read on request; null when it could not be read. */
+ 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
+ /** 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. */
scrolled?: (phase: 'down' | 'move' | 'up', dy: number, velocity: number) => void
/** The dial came, went, or started taking an update — see CableSession's onDialStatus. */
@@ -392,11 +401,45 @@ export class DaemonCableHost implements CableHost {
if (!app) return { selected: '', swarms: [], tiles: [] }
return {
selected: app.active,
- swarms: app.swarms.map((s) => ({ id: s.id, name: s.name, agents: s.agentIds.length, agentIds: s.agentIds, panes: s.panes })),
+ swarms: app.swarms.map((s) => ({ id: s.id, name: s.name, agents: s.agentIds.length, agentIds: s.agentIds, panes: s.panes, ...(s.superTabId ? { superTabId: s.superTabId } : {}) })),
tiles: app.tiles,
}
}
+ /** The Swarm cards the core last handed the devices; a device that attaches later is shown them (core/superTabCards.ts replays). */
+ private cards: SwarmCard[] = []
+
+ setSwarmCards(items: SwarmCard[]): void {
+ this.cards = items
+ }
+
+ swarmCards(): SwarmCard[] {
+ return this.cards
+ }
+
+ swarmCardsWanted(on: boolean): void {
+ this.wiring.swarmCardsWanted?.(on)
+ }
+
+ swarmCardRecap(tabId: string, leadId: string): Promise<LeadRecap | null> {
+ return this.wiring.swarmCardRecap?.(tabId, leadId) ?? Promise.resolve(null)
+ }
+
+ swarmCardOpen(session: string, tabId: string, leadId: string | null): void {
+ this.wiring.swarmCardOpen?.(session, tabId, leadId)
+ }
+
+ superTabSelected(superTabId: string, projectId: string): void {
+ this.wiring.superTabSelected?.(superTabId, projectId)
+ }
+
+ /** The active tab when it is a Swarm with an open project; `fromDevice` when the announce was a device's own pick. */
+ activeSwarmProject(): { superTabId: string; projectId: string; fromDevice: boolean } | null {
+ const app = this.swarms
+ const tab = app?.swarms.find((s) => s.id === app.active)
+ return app && tab?.superTabId && tab.projectId ? { superTabId: tab.superTabId, projectId: tab.projectId, fromDevice: app.fromDevice === true } : null
+ }
+
selectSwarm(swarmId: string): void {
if (!swarmId || !this.swarms?.swarms.some((s) => s.id === swarmId)) {
this.wiring.log(`cable: ignored select for unknown swarm ${swarmId || '(empty)'}`)
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index a7fef4833..09c20301c 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -12,8 +12,9 @@ import { join } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import { CABLE_MAX_FRAME, CableDecoder, CableType, encodeCableFrame } from './cableFrame.js'
-import { CableSession, type CableAgent, type CableHost, type CableMachine, type CablePort } from './cableSession.js'
+import { CableSession, recapFrame, type CableAgent, type CableHost, type CableMachine, type CablePort } from './cableSession.js'
import { DialLog } from './dialLog.js'
+import type { SwarmCard, SwarmLead } from '../superTabs/cards.js'
import type { PetStore } from './pets/store.js'
/** A port whose two ends are both in this process. */
@@ -3663,3 +3664,411 @@ 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 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. */
+ const tokens = (value: unknown): number => {
+ if (Array.isArray(value)) return 1 + value.reduce((n: number, v) => n + tokens(v), 0)
+ if (value && typeof value === 'object') return 1 + Object.entries(value).reduce((n, [, v]) => n + 1 + tokens(v), 0)
+ return 1
+ }
+ const desk = (...rows: Array<{ id: string; superTabId?: string }>) => ({ selected: rows[0]?.id ?? '', tiles: [] as never[],
+ swarms: rows.map((r) => ({ name: r.id, agents: 0, agentIds: [] as string[], panes: 0, ...r })) })
+
+ /** A host whose cards, desk tab and window project the test moves. */
+ function cardHost(state: { cards: SwarmCard[]; desk?: ReturnType<typeof desk>; open?: { superTabId: string; projectId: string; fromDevice: boolean } | null } , over: Partial<CableHost> = {}) {
+ return makeHost({
+ swarmCards: () => state.cards,
+ listSwarms: () => state.desk ?? desk(),
+ activeSwarmProject: () => state.open ?? null,
+ swarmCardsWanted: vi.fn(), swarmCardOpen: vi.fn(), superTabSelected: vi.fn(),
+ swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'Shipped it.', at: 1792560000, none: false })),
+ ...over,
+ })
+ }
+
+ it('sends nothing, asks for nothing and answers nothing to a device that does not name swarmCard', async () => {
+ const state = { cards: [card('st1')] }
+ const host = cardHost(state)
+ const { session, port } = await connect(host)
+ try {
+ port.say({ ...PRO, swarmCard: undefined })
+ await vi.waitFor(() => expect(port.types()).toContain('notif.replace'))
+ await session.syncSwarmCards(true)
+ await session.swarmCardRecap({ tabId: 'st1', leadId: 'lead1', text: 'x', at: 1, none: false })
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' })
+ port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead1' })
+ await settle(); await settle()
+ expect(port.types().filter((t) => t.startsWith('supertab'))).toEqual([])
+ expect(host.swarmCardsWanted).not.toHaveBeenCalled()
+ expect(host.swarmCardRecap).not.toHaveBeenCalled()
+ expect(host.swarmCardOpen).not.toHaveBeenCalled()
+ expect(host.superTabSelected).not.toHaveBeenCalled()
+ } finally { await session.stop() }
+ })
+
+ it('on attach: asks for the cards once, then supertabs and one supertab per Swarm, linked to the desk tab', async () => {
+ const state = { cards: [card('st1'), card('st2')], desk: desk({ id: 'tab9', superTabId: 'st2' }, { id: 'tab1' }) }
+ const host = cardHost(state)
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(2))
+ port.say(PRO) // a repeat hello is a keepalive
+ await settle()
+ expect(host.swarmCardsWanted).toHaveBeenCalledExactlyOnceWith(true)
+ 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 }] },
+ expect.objectContaining({ id: 'st2', tab: 'tab9' }),
+ ])
+ // The list goes first, so the Pro knows the order the details fill.
+ expect(port.types().indexOf('supertabs')).toBeLessThan(port.types().indexOf('supertab'))
+ // Gone: the core is told the last capable device left.
+ await port.close('unplugged')
+ expect(host.swarmCardsWanted).toHaveBeenLastCalledWith(false)
+ expect(host.swarmCardsWanted).toHaveBeenCalledTimes(2)
+ } finally { await session.stop() }
+ })
+
+ it('still sends the cards, with no tab link, when the desktop is closed', async () => {
+ const host = cardHost({ cards: [card('st1')] }) // listSwarms: no window
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ expect(ofType(port, 'supertab')[0].tab).toBe('')
+ expect(ofType(port, 'supertab.focus')).toEqual([])
+ } finally { await session.stop() }
+ })
+
+ it('a change is held 300 ms, then only the changed Swarm goes (and supertabs only when the set moved)', async () => {
+ const state = { cards: [card('st1'), card('st2')] } as { cards: SwarmCard[]; desk?: ReturnType<typeof desk> }
+ const { session, port } = await connect(cardHost(state))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(2))
+ port.sent.length = 0
+ state.cards = [card('st1'), card('st2', [lead(1, { state: 'ask' }), lead(2)])]
+ void session.syncSwarmCards()
+ void session.syncSwarmCards()
+ await settle()
+ expect(port.sent).toEqual([])
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1), NEXT_TICKS)
+ await settle()
+ expect(port.types()).toEqual(['supertab'])
+ expect(port.sent[0]).toMatchObject({ id: 'st2' })
+ // A Swarm gone and one new: the set changed, so supertabs again, and only the new one's details.
+ port.sent.length = 0
+ state.cards = [card('st2', [lead(1, { state: 'ask' }), lead(2)]), card('st3')]
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1), NEXT_TICKS)
+ expect(port.sent.map((m) => [m.t, m.id ?? m.ids])).toEqual([['supertabs', ['st2', 'st3']], ['supertab', 'st3']])
+ // Nothing changed: nothing sent.
+ port.sent.length = 0
+ void session.syncSwarmCards()
+ await new Promise((r) => setTimeout(r, 450))
+ expect(port.types().filter((t) => t.startsWith('supertab'))).toEqual([])
+ } finally { await session.stop() }
+ })
+
+ it('the desk opening the Swarm tab links it: only that Swarm is sent again', async () => {
+ const state = { cards: [card('st1'), card('st2')], desk: desk() }
+ const { session, port } = await connect(cardHost(state))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(2))
+ port.sent.length = 0
+ state.desk = desk({ id: 'tab7', superTabId: 'st1' })
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1), NEXT_TICKS)
+ expect(port.sent).toMatchObject([{ t: 'supertab', id: 'st1', tab: 'tab7' }])
+ } finally { await session.stop() }
+ })
+
+ it('a 16 x 12 list is one supertabs and 16 supertab frames, each under 512 JSON tokens', async () => {
+ const wide = 'é'.repeat(24) // 48 bytes
+ const 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}` })),
+ { name: wide, count: 40 }))
+ const { session, port } = await connect(cardHost({ cards }))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(16))
+ await settle()
+ expect(ofType(port, 'supertabs')).toHaveLength(1)
+ expect((ofType(port, 'supertabs')[0].ids as string[]).length).toBe(16)
+ 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)
+ expect(Math.max(...frames.map(tokens))).toBeLessThan(260)
+ } 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))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toHaveLength(1))
+ port.sent.length = 0
+ port.say({ t: 'resync' })
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toHaveLength(1))
+ expect(port.types().filter((t) => t.startsWith('supertab'))).toEqual(['supertabs', 'supertab', 'supertab.focus'])
+ } finally { await session.stop() }
+ })
+
+ it('supertab.recap.get asks for the recap and answers with supertab.recap; a failed read answers nothing', async () => {
+ const state = { cards: [card('st1')] }
+ const host = cardHost(state)
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead2' })
+ await vi.waitFor(() => expect(ofType(port, 'supertab.recap')).toEqual([
+ { t: 'supertab.recap', tab: 'st1', lead: 'lead2', text: 'Shipped it.', at: 1792560000, none: false }]))
+ expect(host.swarmCardRecap).toHaveBeenCalledWith('st1', 'lead2')
+ for (const failure of [async () => null, async () => { throw new Error('boom') }]) {
+ port.sent.length = 0
+ vi.mocked(host.swarmCardRecap!).mockImplementationOnce(failure)
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })
+ await settle(); await settle()
+ expect(ofType(port, 'supertab.recap')).toEqual([])
+ }
+ // Ids that are not ids are not asked about.
+ vi.mocked(host.swarmCardRecap!).mockClear()
+ port.say({ t: 'supertab.recap.get', tab: 'st 1', lead: 'lead1' })
+ port.say({ t: 'supertab.recap.get', tab: 'st1' })
+ port.say({ t: 'supertab.recap.get', lead: 'lead1' })
+ await settle(); await settle()
+ expect(host.swarmCardRecap).not.toHaveBeenCalled()
+ } finally { await session.stop() }
+ })
+
+ it('supertab.open tells the core which Lead is open, and a pushed recap reaches the device only for that Lead', async () => {
+ const host = cardHost({ cards: [card('st1')] })
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ const recap = (leadId: string, text: string) => ({ tabId: 'st1', leadId, text, at: 5, none: false })
+ await session.swarmCardRecap(recap('lead1', 'before open'))
+ expect(ofType(port, 'supertab.recap')).toEqual([])
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle()
+ expect(host.swarmCardOpen).toHaveBeenLastCalledWith(expect.stringMatching(/^c\d+$/), 'st1', 'lead1')
+ await session.swarmCardRecap(recap('lead2', 'other lead'))
+ await session.swarmCardRecap({ ...recap('lead1', 'other tab'), tabId: 'st2' })
+ expect(ofType(port, 'supertab.recap')).toEqual([])
+ await session.swarmCardRecap(recap('lead1', 'now'))
+ expect(ofType(port, 'supertab.recap')).toEqual([{ t: 'supertab.recap', tab: 'st1', lead: 'lead1', text: 'now', at: 5, none: false }])
+ // Closed: no more pushes.
+ port.say({ t: 'supertab.open', tab: 'st1', lead: '' }); await settle()
+ expect(host.swarmCardOpen).toHaveBeenLastCalledWith(expect.stringMatching(/^c\d+$/), 'st1', null)
+ await session.swarmCardRecap(recap('lead1', 'after close'))
+ expect(ofType(port, 'supertab.recap')).toHaveLength(1)
+ // An open with a Lead but a bad tab is ignored.
+ port.say({ t: 'supertab.open', tab: 'a b', lead: 'lead1' }); await settle()
+ expect(host.swarmCardOpen).toHaveBeenCalledTimes(2)
+ } finally { await session.stop() }
+ })
+
+ it('an unplugged Pro with a recap open closes it for the core', async () => {
+ const host = cardHost({ cards: [card('st1')] })
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle()
+ await port.close('unplugged')
+ expect(host.swarmCardOpen).toHaveBeenLastCalledWith(expect.stringMatching(/^c\d+$/), 'st1', null)
+ } finally { await session.stop() }
+ })
+
+ it('follows the window: one supertab.focus with that project\'s Lead, none on repeat, none without a Swarm tab', async () => {
+ const state = { cards: [card('st1')], open: null as { superTabId: string; projectId: string; fromDevice: boolean } | null }
+ const { session, port } = await connect(cardHost(state))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ expect(ofType(port, 'supertab.focus')).toEqual([]) // the active tab is not a Swarm
+ state.open = { superTabId: 'st1', projectId: 'proj2', fromDevice: false }
+ await session.syncSwarmCards(true)
+ expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead2' }])
+ void session.syncSwarmCards()
+ await new Promise((r) => setTimeout(r, 450))
+ expect(ofType(port, 'supertab.focus')).toHaveLength(1) // the same project: not again
+ state.open = { superTabId: 'st1', projectId: 'proj1', fromDevice: false }
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toHaveLength(2), NEXT_TICKS)
+ expect(ofType(port, 'supertab.focus')[1]).toMatchObject({ lead: 'lead1' })
+ // The window leaves the Swarm tab and comes back: that is a change.
+ state.open = null
+ void session.syncSwarmCards()
+ await new Promise((r) => setTimeout(r, 450))
+ state.open = { superTabId: 'st1', projectId: 'proj1', fromDevice: false }
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toHaveLength(3), NEXT_TICKS)
+ } finally { await session.stop() }
+ })
+
+ it('a project the list does not hold yet is followed when the list arrives', async () => {
+ const state = { cards: [] as SwarmCard[], open: { superTabId: 'st1', projectId: 'proj1', fromDevice: false } }
+ const { session, port } = await connect(cardHost(state))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertabs')).toHaveLength(1))
+ expect(ofType(port, 'supertab.focus')).toEqual([])
+ state.cards = [card('st1')]
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead1' }]), NEXT_TICKS)
+ } finally { await session.stop() }
+ })
+
+ it('supertab.select opens the Lead\'s project on the desktop, and the announce that follows is not echoed back', async () => {
+ const state = { cards: [card('st1')], open: null as { superTabId: string; projectId: string; fromDevice: boolean } | null }
+ const host = cardHost(state)
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead2' }); await settle()
+ expect(host.superTabSelected).toHaveBeenCalledExactlyOnceWith('st1', 'proj2')
+ // The window answers with that project, marked or not: no focus comes back.
+ state.open = { superTabId: 'st1', projectId: 'proj2', fromDevice: true }
+ await session.syncSwarmCards(true)
+ expect(ofType(port, 'supertab.focus')).toEqual([])
+ state.open = { superTabId: 'st1', projectId: 'proj2', fromDevice: false }
+ void session.syncSwarmCards()
+ await new Promise((r) => setTimeout(r, 450))
+ expect(ofType(port, 'supertab.focus')).toEqual([])
+ // …but a later move by the person at the desk is followed (once the pick's 2 s are over).
+ vi.spyOn(Date, 'now').mockReturnValue(Date.now() + 2100)
+ state.open = { superTabId: 'st1', projectId: 'proj1', fromDevice: false }
+ void session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead1' }]), NEXT_TICKS)
+ // An unknown Lead is not opened.
+ port.say({ t: 'supertab.select', tab: 'st1', lead: 'nobody' }); await settle()
+ expect(host.superTabSelected).toHaveBeenCalledTimes(1)
+ } finally { vi.restoreAllMocks(); await session.stop() }
+ })
+
+ it('another Pro still follows an announce a device caused: only the Pro that picked is spared the echo', async () => {
+ const state = { cards: [card('st1')], open: null as { superTabId: string; projectId: string; fromDevice: boolean } | null }
+ const host = cardHost(state)
+ const one = await connect(host), two = await connect(host)
+ try {
+ one.port.say(PRO); two.port.say(PRO)
+ await vi.waitFor(() => expect(ofType(one.port, 'supertab')).toHaveLength(1))
+ await vi.waitFor(() => expect(ofType(two.port, 'supertab')).toHaveLength(1))
+ one.port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead2' }); await settle()
+ state.open = { superTabId: 'st1', projectId: 'proj2', fromDevice: true }
+ await one.session.syncSwarmCards(true)
+ await two.session.syncSwarmCards(true)
+ expect(ofType(one.port, 'supertab.focus')).toEqual([])
+ expect(ofType(two.port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead2' }])
+ } finally { await one.session.stop(); await two.session.stop() }
+ })
+
+ it('holds off the desktop\'s stale announce of another project for 2 s after a pick, then follows it', async () => {
+ const state = { cards: [card('st1')], open: null as { superTabId: string; projectId: string; fromDevice: boolean } | null }
+ const { session, port } = await connect(cardHost(state))
+ const now = vi.spyOn(Date, 'now')
+ try {
+ now.mockReturnValue(1_000_000)
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead2' }); await settle()
+ state.open = { superTabId: 'st1', projectId: 'proj1', fromDevice: false } // what the window said before it heard the pick
+ now.mockReturnValue(1_001_500)
+ await session.syncSwarmCards(true)
+ expect(ofType(port, 'supertab.focus')).toEqual([])
+ now.mockReturnValue(1_002_100)
+ await session.syncSwarmCards(true)
+ expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead1' }])
+ } finally { now.mockRestore(); await session.stop() }
+ })
+
+ it('names each cable session to the core, so one Pro closing its recap does not close another\'s', async () => {
+ const host = cardHost({ cards: [card('st1')] })
+ const one = await connect(host), two = await connect(host)
+ try {
+ one.port.say(PRO); two.port.say(PRO)
+ await vi.waitFor(() => expect(ofType(two.port, 'supertab')).toHaveLength(1))
+ one.port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle()
+ two.port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle()
+ const opened = vi.mocked(host.swarmCardOpen!).mock.calls
+ expect(opened[0][0]).not.toBe(opened[1][0])
+ one.port.say({ t: 'supertab.open', tab: 'st1', lead: '' }); await settle()
+ expect(vi.mocked(host.swarmCardOpen!).mock.calls.at(-1)).toEqual([opened[0][0], 'st1', null])
+ } finally { await one.session.stop(); await two.session.stop() }
+ })
+
+ it('ignores a repeat of the same recap request inside a second', async () => {
+ const host = cardHost({ cards: [card('st1')] })
+ const { session, port } = await connect(host)
+ const now = vi.spyOn(Date, 'now')
+ try {
+ now.mockReturnValue(5_000_000)
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' }); await settle(); await settle()
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' }); await settle(); await settle()
+ expect(host.swarmCardRecap).toHaveBeenCalledTimes(1)
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead2' }); await settle(); await settle()
+ expect(host.swarmCardRecap).toHaveBeenCalledTimes(2)
+ now.mockReturnValue(5_001_100)
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' }); await settle(); await settle()
+ expect(host.swarmCardRecap).toHaveBeenCalledTimes(3)
+ } finally { now.mockRestore(); await session.stop() }
+ })
+
+ it('shortens a recap on a character until its frame is within 6 KB', async () => {
+ const big = '日'.repeat(500) + '"\n'.repeat(1500) // escapes make the JSON far bigger than the text
+ const host = cardHost({ cards: [card('st1')] }, { swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: big, at: 5, none: false })) })
+ const { session, port } = await connect(host)
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })
+ await vi.waitFor(() => expect(ofType(port, 'supertab.recap')).toHaveLength(1))
+ const frame = ofType(port, 'supertab.recap')[0]
+ expect(Buffer.byteLength(JSON.stringify(frame))).toBeLessThanOrEqual(6 * 1024)
+ expect(String(frame.text).length).toBeGreaterThan(100)
+ expect(big.startsWith(String(frame.text))).toBe(true)
+ expect(String(frame.text)).not.toContain('\uFFFD')
+ expect(recapFrame({ tabId: 't', leadId: 'l', text: 'short', at: 1, none: false })).toMatchObject({ text: 'short' })
+ } finally { await session.stop() }
+ })
+
+ it('a Pro with no pick of its own that is told of a device\'s announce follows it, even when the list is fresh', async () => {
+ const state = { cards: [card('st1')], open: { superTabId: 'st1', projectId: 'proj2', fromDevice: true } }
+ const { session, port } = await connect(cardHost(state))
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead2' }]))
+ } finally { await session.stop() }
+ })
+
+ it('a host without the card hooks still greets a Pro', async () => {
+ const { session, port } = await connect(makeHost())
+ try {
+ port.say(PRO)
+ await vi.waitFor(() => expect(ofType(port, 'supertabs')).toEqual([{ t: 'supertabs', ids: [] }]))
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' })
+ port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead1' })
+ port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })
+ await settle(); await settle()
+ expect(ofType(port, 'supertab.recap')).toEqual([])
+ } finally { await session.stop() }
+ })
+})
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index 33ceddad9..e8a928ed0 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -155,6 +155,26 @@ const ACTION_MAX_BYTES = 188
/** What the Pro's firmware holds of a swarms frame: 24 tabs, 24 ids each, and 512 JSON tokens (480 here). */
const SWARMS_MAX = 24
+/** The Pro's Swarm cards: at most 16 Swarms of 12 Leads, a change held this long so a burst is one push. */
+const SWARM_CARDS_MAX = 16
+const SWARM_LEADS_MAX = 12
+const SWARM_CARDS_DEBOUNCE_MS = 300
+/** A Super Tab, project or agent id as the backend writes them. */
+/** The Pro keeps an id in 48 bytes with its NUL. */
+const CARD_ID = /^[A-Za-z0-9_-]{1,47}$/
+/** A `supertab.recap` frame the Pro takes at most this many bytes of JSON for. */
+const RECAP_FRAME_MAX = 6 * 1024
+/** Repeats of one Lead's recap request inside this are ignored; a device that picks another stale announce within this is not followed. */
+const RECAP_REPEAT_MS = 1000
+const PICK_ECHO_MS = 2000
+/** The recap frame, its text shortened (on a character) until the whole JSON fits what the Pro reads. */
+export function recapFrame(r: LeadRecap): Message {
+ const make = (text: string): Message => ({ t: 'supertab.recap', tab: r.tabId, lead: r.leadId, text, at: r.at, none: r.none })
+ let text = r.text
+ while (text && Buffer.byteLength(JSON.stringify(make(text))) > RECAP_FRAME_MAX) text = truncateUtf8(text, Math.floor(Buffer.byteLength(text) * 0.9))
+ return make(text)
+}
+let nextCardSession = 0
const SWARM_IDS_MAX = 24
const SWARM_TOKENS_MAX = 480
@@ -227,6 +247,8 @@ export interface CableSwarm {
* entry — a shell is still never named to the dial.
*/
panes: number
+ /** The Super Tab (Swarm) this tab shows, when it is one: how the Harness Pro's Swarm card finds its desk tab. */
+ superTabId?: string
}
/**
@@ -251,9 +273,15 @@ export interface CableTile {
/** The window's swarms as it last described them, or null while no window is connected. */
export interface AppSwarms {
active: string
- swarms: Array<{ id: string; name: string; agentIds: string[]; panes: number }>
+ swarms: Array<{
+ id: string; name: string; agentIds: string[]; panes: number
+ /** A Super Tab (Swarm) tab: which Swarm it shows and the project the window has open in it. Absent on any other tab. */
+ superTabId?: string; projectId?: string
+ }>
/** The ACTIVE swarm's grid. Empty from a window that predates the field, or one with no panes. */
tiles: CableTile[]
+ /** This announce was caused by a device's pick (`supertab.select`): the device is not told to follow it back. */
+ fromDevice?: boolean
}
/** Why the list is as short as it is. The dial renders this, instead of drawing an empty wheel. */
@@ -276,6 +304,8 @@ import type { FormCommand, FormResult } from './windowForm.js'
import { deriveLongRecap, extendShortRecap } from '../lib/deviceRecap.js'
import type { TurnStatsFields } from './turnStats.js'
import type { Tier } from '../lib/notifyTier.js'
+import type { LeadRecap, SwarmCard } from '../superTabs/cards.js'
+import { truncateUtf8 } from '../lib/deviceRecentTrim.js'
export interface RouteDecision {
agentId: string
@@ -305,6 +335,18 @@ export interface CableHost {
listSwarms(): { selected: string; swarms: CableSwarm[]; tiles: CableTile[] }
/** The dial picked a swarm. Relayed to the window, which switches and re-describes its desk. */
selectSwarm(swarmId: string): void
+ /** The Swarm cards the core last told the devices (core/superTabCards.ts); empty until it has. */
+ swarmCards?(): SwarmCard[]
+ /** A device that speaks `swarmCard: 'v1'` is attached (true) or gone (false): the core starts or stops reading the Swarms. */
+ swarmCardsWanted?(on: boolean): void
+ /** One Lead's last message, read on request; null when it could not be read. */
+ 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
+ /** 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. */
+ activeSwarmProject?(): { superTabId: string; projectId: string; fromDevice: boolean } | null
appName(): string
voiceLang(): string
/** The window's latest selected pane, including selections made before this dial attached. */
@@ -613,6 +655,8 @@ export class CableSession {
* answers on the device. Any other device is not sent one: the round dial would open a question screen for it that
* cannot load. */
private superTabWaits = false
+ /** `swarmCard: 'v1'` (a Pro): the Swarm cards, their Leads' recaps and the Swarm focus travel on the cable. */
+ private swarmCard = false
private playerOffset = 0
private playerRequest = 0
private playerLibraryKey = ''
@@ -626,13 +670,15 @@ export class CableSession {
/** For the greeting's log line: which capabilities this hello named, or nothing. */
private capabilitiesNamed(): string {
- const named = [this.swarmMembers && 'swarms', this.longRecap && 'recap', this.stepsActivity && 'activity', this.statsTurn && 'stats', this.playerCapable && 'player', this.superTabWaits && 'superTab']
+ const named = [this.swarmMembers && 'swarms', this.longRecap && 'recap', this.stepsActivity && 'activity', this.statsTurn && 'stats', this.playerCapable && 'player', this.superTabWaits && 'superTab', this.swarmCard && 'swarmCard']
.filter(Boolean)
return named.length ? ` caps ${named.join(',')}` : ''
}
private resetCapabilities(): void {
this.swarmMembers = this.longRecap = this.stepsActivity = this.statsTurn = this.playerCapable = this.superTabWaits = false
+ this.swarmCard = false
+ this.dropCards()
this.seqOn = false
this.seq = 0
this.resyncAt = 0
@@ -1192,6 +1238,8 @@ export class CableSession {
this.statsTurn = str('stats') === 'turn-v1'
this.playerCapable = str('player') === 'library-v1'
this.superTabWaits = str('superTab') === 'wait-v1'
+ this.swarmCard = str('swarmCard') === 'v1'
+ this.wantCards(this.swarmCard)
this.seqOn = str('board') === 'pro'
this.seq = 0
const mac = str('mac') ?? ''
@@ -1295,6 +1343,11 @@ export class CableSession {
case 'resync':
await this.resync()
return
+ case 'supertab.recap.get':
+ case 'supertab.open':
+ case 'supertab.select':
+ await this.onSuperTab(msg.t, str('tab') ?? '', str('lead') ?? '')
+ return
case 'swarm.select':
// Not answered here: the window switches, its desk changes, and the new `swarms` and ring
// pushes are the answer — the same shape as `machine.select`, minus the refusal, because the
@@ -2486,6 +2539,7 @@ export class CableSession {
try {
await this.syncMachines(true)
await this.syncSwarms(true)
+ await this.syncSwarmCards(true)
await this.syncAgents(true)
await this.syncPlayerLibrary(true)
} finally {
@@ -2508,6 +2562,7 @@ export class CableSession {
this.resyncAt = now
await this.syncMachines(true)
await this.syncSwarms(true)
+ await this.syncSwarmCards(true)
await this.syncAgents(true)
await this.replaceNotifications(this.host.listUnread())
for (const { agentId, id, questions } of this.questionInbox.open()) {
@@ -2516,6 +2571,148 @@ export class CableSession {
await this.resendSuperTabAsks()
}
+ // ── swarm cards (a Pro that named `swarmCard: 'v1'`) ────────────────────────────────────────────────
+
+ /** What this session told the core: that a capable device is here (see wantCards). */
+ private cardsWanted = false
+ /** Each Swarm's `supertab` frame as the Pro was last sent it, and the ids list: only a difference is sent again. */
+ private readonly cardKeys = new Map<string, string>()
+ private cardIdsKey = ''
+ private cardTimer: ReturnType<typeof setTimeout> | null = null
+ /** The Lead whose recap the Pro has open: the only one a changed text is pushed for. */
+ private openLead: { tabId: string; leadId: string } | null = null
+ /** The Swarm project the Pro was last pointed at (or picked itself), so a repeat announce sends nothing. */
+ private focusedKey = ''
+ /** This cable session's name for the service, so one Pro closing its recap does not close another's. */
+ private readonly cardSession = `c${++nextCardSession}`
+ /** The project this Pro itself picked last and when: the desktop's announce of it is no news, and a stale one of another is held off. */
+ private picked: { key: string; at: number } | null = null
+ private lastRecapGet: { key: string; at: number } | null = null
+
+ /** Tell the core a capable device is here (or gone), once per change: it reads the Swarms only while one is. */
+ private wantCards(on: boolean): void {
+ if (on === this.cardsWanted) return
+ this.cardsWanted = on
+ this.host.swarmCardsWanted?.(on)
+ }
+
+ /** The link ended: forget what the Pro was told and had open, and stop asking the core for Swarms on its behalf. */
+ private dropCards(): void {
+ if (this.cardTimer) clearTimeout(this.cardTimer)
+ this.cardTimer = null
+ this.cardKeys.clear()
+ this.cardIdsKey = ''
+ this.focusedKey = ''
+ this.picked = null
+ this.lastRecapGet = null
+ if (this.openLead) this.host.swarmCardOpen?.(this.cardSession, this.openLead.tabId, null)
+ this.openLead = null
+ this.wantCards(false)
+ }
+
+ /**
+ * Push the Swarm cards IF they differ from what the Pro was last told: `supertabs` (ids, in order) when the set or order
+ * moved, then one `supertab` per Swarm that changed — the Pro refuses a frame over 512 JSON tokens, and 16 Swarms of 12
+ * Leads do not fit in one. A change is held 300 ms so a burst of backend reads and desk announcements is one push;
+ * `force` (attach, resync) sends everything at once.
+ */
+ async syncSwarmCards(force = false): Promise<void> {
+ if (!this.swarmCard) return
+ if (force) {
+ if (this.cardTimer) clearTimeout(this.cardTimer)
+ this.cardTimer = null
+ return this.queued(() => this.pushSwarmCards(true))
+ }
+ if (this.cardTimer) return
+ this.cardTimer = setTimeout(() => {
+ this.cardTimer = null
+ this.queued(() => this.pushSwarmCards(false)).catch((err) => this.log(`cable: swarm cards failed (${(err as Error).message})`))
+ }, SWARM_CARDS_DEBOUNCE_MS)
+ this.cardTimer.unref?.()
+ }
+
+ private async pushSwarmCards(force: boolean): Promise<void> {
+ if (!this.swarmCard) return
+ if (force) { this.cardKeys.clear(); this.cardIdsKey = ''; this.focusedKey = '' }
+ const cards = (this.host.swarmCards?.() ?? []).slice(0, SWARM_CARDS_MAX)
+ const desk = this.host.listSwarms().swarms
+ const ids = JSON.stringify(cards.map((c) => c.id))
+ if (ids !== this.cardIdsKey) {
+ this.cardIdsKey = ids
+ await this.send({ t: 'supertabs', ids: cards.map((c) => c.id) })
+ }
+ for (const id of [...this.cardKeys.keys()]) if (!cards.some((c) => c.id === id)) this.cardKeys.delete(id)
+ for (const card of cards) {
+ // The desk tab of the same Swarm, when the window has one: empty when it is closed or never opened it.
+ 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 }) })) }
+ const key = JSON.stringify(frame)
+ if (this.cardKeys.get(card.id) === key) continue
+ this.cardKeys.set(card.id, key)
+ await this.send(frame)
+ }
+ await this.pushSwarmFocus()
+ }
+
+ /** Point the Pro at the Lead of the project the window has open, once per change and never at its own pick. */
+ private async pushSwarmFocus(): Promise<void> {
+ const open = this.host.activeSwarmProject?.()
+ if (!open) { this.focusedKey = ''; return }
+ const key = `${open.superTabId}/${open.projectId}`
+ if (key === this.focusedKey) return
+ // Only the Pro that picked has nothing to follow; every other Pro still goes where the window went.
+ if (open.fromDevice && this.picked?.key === key) { this.focusedKey = key; return }
+ // The desktop's announce from before it heard the pick: not where the window is going.
+ if (!open.fromDevice && this.picked && this.picked.key !== key && Date.now() - this.picked.at < PICK_ECHO_MS) return
+ const lead = this.host.swarmCards?.().find((c) => c.id === open.superTabId)?.leads.find((l) => l.projectId === open.projectId)
+ // Not in the list yet: asked again when it arrives.
+ if (!lead) return
+ this.focusedKey = key
+ await this.send({ t: 'supertab.focus', tab: open.superTabId, lead: lead.id })
+ }
+
+ /** A Lead's changed text, for the Pro that has that Lead's recap open. */
+ async swarmCardRecap(recap: LeadRecap): Promise<void> {
+ if (!this.swarmCard || this.openLead?.tabId !== recap.tabId || this.openLead.leadId !== recap.leadId) return
+ return this.queued(async () => { await this.send(recapFrame(recap)) })
+ }
+
+ /** The Pro's three requests about Swarm cards. Ids that are not ids are ignored, like any frame this daemon cannot use. */
+ private async onSuperTab(type: string, tab: string, lead: string): Promise<void> {
+ if (!this.swarmCard) return
+ // The recap closing names no Lead: it is the one request that may leave a field empty.
+ if (type === 'supertab.open' && lead === '') {
+ this.openLead = null
+ this.host.swarmCardOpen?.(this.cardSession, tab, null)
+ return
+ }
+ if (!CARD_ID.test(tab) || !CARD_ID.test(lead)) return
+ if (type === 'supertab.open') {
+ this.openLead = { tabId: tab, leadId: lead }
+ this.host.swarmCardOpen?.(this.cardSession, tab, lead)
+ return
+ }
+ if (type === 'supertab.select') {
+ const projectId = this.host.swarmCards?.().find((c) => c.id === tab)?.leads.find((l) => l.id === lead)?.projectId
+ if (!projectId) { this.log(`cable: ignored pick of unknown Lead ${lead}`); return }
+ // Remembered before the window answers, so its announce of this very project is not sent back as a focus.
+ this.focusedKey = `${tab}/${projectId}`
+ this.picked = { key: this.focusedKey, at: Date.now() }
+ this.host.superTabSelected?.(tab, projectId)
+ return
+ }
+ // A repeat for the same Lead inside a second is ignored: the first answer is on its way.
+ const asked = `${tab}/${lead}`, now = Date.now()
+ if (this.lastRecapGet?.key === asked && now - this.lastRecapGet.at < RECAP_REPEAT_MS) return
+ this.lastRecapGet = { key: asked, at: now }
+ let recap: LeadRecap | null = null
+ try { recap = await this.host.swarmCardRecap?.(tab, lead) ?? null } catch (err) { this.log(`cable: recap for ${lead} failed (${(err as Error).message})`) }
+ // Nothing on a failure: the Pro keeps its "…" and asks again on the next open.
+ if (recap) await this.queued(async () => { await this.send(recapFrame(recap)) })
+ }
+
// ── swarms ────────────────────────────────────────────────────────────────────────────────────────
private lastSwarmsKey = ''
diff --git a/cli/src/core/api.spec.ts b/cli/src/core/api.spec.ts
index 01dab4508..e7626af41 100644
--- a/cli/src/core/api.spec.ts
+++ b/cli/src/core/api.spec.ts
@@ -196,8 +196,12 @@ describe('the core API services stand on', () => {
expect(createCoreApi({ ...deps, cloud }).cloud).toBe(cloud)
// The Super Tab service's door, the same way.
expect(core.superTabs).toBeUndefined()
- const superTabs = { attention: vi.fn() }
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
expect(createCoreApi({ ...deps, superTabs }).superTabs).toBe(superTabs)
+ // The devices' way to its card requests, the same way.
+ expect(core.superTabRequest).toBeUndefined()
+ const superTabRequest = vi.fn()
+ expect(createCoreApi({ ...deps, superTabRequest }).superTabRequest).toBe(superTabRequest)
expect(core.agents.cloud).toBeUndefined()
const rows = [{ agentId: 'cloud_1' }] as RegisteredSession[]
expect(createCoreApi({ ...deps, cloudRows: () => rows }).agents.cloud!()).toBe(rows)
@@ -365,7 +369,7 @@ describe('the core API services stand on', () => {
expect(readFallback(DEVICES_FALLBACKS.routeSend)).toEqual({ deferred: true, value: { ok: false, machine: '', reason } })
// The Wi-Fi device finds no desk to walk; the dial and the window bridges hear nothing.
expect(readFallback(DEVICES_FALLBACKS.stepFocus).value).toBe('no_agents')
- for (const member of ['card', 'desk', 'swarms', 'unread', 'appFocus', 'seen', 'settings', 'windowFocus', 'windowReply', 'voiceReply', 'windowGone', 'scroll', 'engines', 'commanders'] as const) {
+ for (const member of ['card', 'desk', 'swarms', 'swarmCards', 'swarmCardRecap', 'unread', 'appFocus', 'seen', 'settings', 'windowFocus', 'windowReply', 'voiceReply', 'windowGone', 'scroll', 'engines', 'commanders'] as const) {
expect(DEVICES_FALLBACKS[member], member).toBeUndefined()
}
expect(readFallback(DEVICES_FALLBACKS.stop)).toEqual({ deferred: true, value: undefined })
diff --git a/cli/src/core/api.ts b/cli/src/core/api.ts
index 9abc09a2b..006937c0a 100644
--- a/cli/src/core/api.ts
+++ b/cli/src/core/api.ts
@@ -22,6 +22,7 @@ import type { NativeTurnRead } from '../lib/nativeTurnObservations.js'
import type { ReviewedAnswer } from '../cable/questionInbox.js'
import type { AgentEngine } from '../engines/types.js'
import type { AppSwarms } from '../cable/cableSession.js'
+import type { LeadRecap, SwarmCard } from '../superTabs/cards.js'
import type { UnreadNotification } from '../lib/notificationRead.js'
import type { AutonomousDeviceAgent, AutonomousDeviceDelivery, AutonomousDeviceReceipt } from '../lib/autonomous-device/service.js'
import type { StoreAgent } from '../lib/autonomous-device/store.js'
@@ -349,6 +350,10 @@ export interface CoreApi {
cloud?: CloudCore
/** The Super Tab service's door into the core (superTabs/attention.ts): absent from a core or a process that offers it none. */
superTabs?: SuperTabsCore
+ /** The devices' way to the Super Tab service's `super_tabs` requests, for the Swarm cards alone (`cardsWanted`, `cardRecap`,
+ * `cardOpen`; core/devicesLink.ts refuses any other action): its answer, or SERVICE_UNAVAILABLE. Absent from a core or a
+ * process that offers none. */
+ superTabRequest?: (payload: Record<string, unknown>) => Promise<Record<string, unknown>>
/** The Wi-Fi device's doors into the core (services/wifi.ts): each one call it made when it ran here. */
wifi: {
/** What it lists and reads in line (`WifiView`), asked again before each request it answers. */
@@ -1172,6 +1177,11 @@ export interface SuperTabAttention {
export interface SuperTabsCore {
/** Every wait, replacing the last set: the core raises what is new on the devices and closes what is gone. */
attention(items: SuperTabAttention[]): void
+ /** Every Swarm this account is in, whole, each time it changes: the core keeps the last list for a dial that attaches
+ * later and hands it to the devices (core/superTabCards.ts). */
+ cards(items: SwarmCard[]): void
+ /** What one Lead last said, pushed when the recap on a Harness Pro's screen moved on. */
+ cardRecap(recap: LeadRecap): void
}
/** What the cloud service answers the core: done, or why not, in words a person reads. */
@@ -1211,7 +1221,7 @@ export type ForkResult = { ok: true; agentId: string } | { ok: false; error: str
* this desk did on a dial, and a spoken task offered to the window's palette. Never to the cloud. */
export const DEVICE_WINDOW_FRAMES = [
'dial_open', 'dial_notification_read', 'dial_forked', 'dial_focus', 'dial_swarm', 'dial_scroll', 'dial_status',
- 'voice_route_request',
+ 'voice_route_request', 'dial_super_tab',
] as const
export type DeviceWindowFrame = { type: (typeof DEVICE_WINDOW_FRAMES)[number]; payload: Record<string, unknown> }
@@ -1247,6 +1257,10 @@ export interface DevicesPort {
desk(agentIds: string[], foreground: boolean): void
/** The window's tabs, or null once it has gone. */
swarms(swarms: AppSwarms | null): void
+ /** The Swarms' cards for a Harness Pro (core/superTabCards.ts), whole; replayed to a dial that attaches. */
+ swarmCards(items: SwarmCard[]): void
+ /** One Lead's last message, for the recap a Harness Pro has open. */
+ swarmCardRecap(recap: LeadRecap): void
/** What the window still has unread, newest first. */
unread(items: UnreadNotification[]): void
/** The window moved to an agent. */
@@ -1286,7 +1300,7 @@ const DEVICES_UNAVAILABLE = 'the devices service is unavailable'
* picking no agent and sending nothing, the Wi-Fi device finds no desk to walk, and a shutdown goes on.
*/
export const DEVICES_FALLBACKS: PortFallbacks<DevicesPort> = {
- card: undefined, desk: undefined, swarms: undefined, unread: undefined, appFocus: undefined, seen: undefined,
+ card: undefined, desk: undefined, swarms: undefined, swarmCards: undefined, swarmCardRecap: undefined, unread: undefined, appFocus: undefined, seen: undefined,
settings: undefined, windowFocus: undefined, windowReply: undefined, voiceReply: undefined, windowGone: undefined,
routeTask: later({ agentId: '', machineId: '', name: '', confidence: 0, reason: DEVICES_UNAVAILABLE, candidates: [], weighed: 0, machines: 0, via: '' }),
routeSend: later({ ok: false, machine: '', reason: DEVICES_UNAVAILABLE }),
@@ -1790,6 +1804,8 @@ export interface CoreApiDeps {
cloud?: CloudCore
/** The Super Tab service's door (core/superTabAttention.ts). */
superTabs?: SuperTabsCore
+ /** The devices' way to the Super Tab service's card requests. */
+ superTabRequest?: CoreApi['superTabRequest']
/** The running cloud harnesses as list rows (`agents.cloud`). */
cloudRows?: () => RegisteredSession[]
lastTurn: CoreApi['transcripts']['lastTurn']
@@ -1805,7 +1821,7 @@ export function createCoreApi({
gridNamed, gridModelsChanged, dshInstallStatus, mintGridName, accessToken, lane, observerKey, tabKey, tabRelay, connectorVault, observer, privateGridName, machineName, backend, onNotice,
runtimeProfile, setRuntime, fork, create, creationStatus, dsh, windows, daemon, turns, questions, terminals = TERMINALS_OFF, conversations = CONVERSATIONS_OFF, viewerFrame, machine, activityText, activitySnapshot, activity, summaries,
closeAgent, activityAt,
- signedIn, environment, machines, sendLocal, sendToWindow, hasWindow, devicesChanged, dialWatching, wifi, cloud, superTabs, cloudRows, lastTurn, nativeTurns, turnCard, turnSummary,
+ signedIn, environment, machines, sendLocal, sendToWindow, hasWindow, devicesChanged, dialWatching, wifi, cloud, superTabs, superTabRequest, cloudRows, lastTurn, nativeTurns, turnCard, turnSummary,
log = (line) => console.warn(line),
}: CoreApiDeps): CoreApi {
// The devices reach the windows through these alone, and only with their own frames: a devices process
@@ -1898,5 +1914,6 @@ export function createCoreApi({
wifi,
...(cloud ? { cloud } : {}),
...(superTabs ? { superTabs } : {}),
+ ...(superTabRequest ? { superTabRequest } : {}),
}
}
diff --git a/cli/src/core/devicesLink.spec.ts b/cli/src/core/devicesLink.spec.ts
index ded89cc25..06db49cfa 100644
--- a/cli/src/core/devicesLink.spec.ts
+++ b/cli/src/core/devicesLink.spec.ts
@@ -24,6 +24,8 @@ describe('what the core tells the devices', () => {
port.card({ type: 'commander_event', agentId: 'a1' })
port.desk(['a1'], false)
port.swarms(null)
+ port.swarmCards([])
+ port.swarmCardRecap({ tabId: 't1', leadId: 'l1', text: 'Shipped', at: 1, none: false })
port.unread([])
port.appFocus('m1', 'a1')
port.seen('a1')
@@ -40,6 +42,8 @@ describe('what the core tells the devices', () => {
{ kind: 'card', frame: { type: 'commander_event', agentId: 'a1' } },
{ kind: 'desk', agentIds: ['a1'], foreground: false },
{ kind: 'swarms', swarms: null },
+ { kind: 'swarmCards', items: [] },
+ { kind: 'swarmCardRecap', recap: { tabId: 't1', leadId: 'l1', text: 'Shipped', at: 1, none: false } },
{ kind: 'unread', items: [] },
{ kind: 'appFocus', machineId: 'm1', agentId: 'a1' },
{ kind: 'seen', agentId: 'a1' },
@@ -216,3 +220,19 @@ describe('what the devices tell the core', () => {
warn.mockRestore()
})
})
+
+describe('the devices\' Swarm card requests to the Super Tab service', () => {
+ it('hands the core only the fields of the three card requests (the core allows those and no other action)', async () => {
+ const superTabRequest = vi.fn(async (payload: Record<string, unknown>) => ({ ok: true, echoed: payload }))
+ const core = fakeCore()
+ core.superTabRequest = superTabRequest
+ const devices = createDevicesLink({ core, notify: () => true, call: vi.fn(), state: () => STATE })
+ expect(await devices.answer('super_tabs', { action: 'cardsWanted', on: true, include: ['t1'], extra: 1 })).toMatchObject({ echoed: { action: 'cardsWanted', on: true, include: ['t1'] } })
+ expect(await devices.answer('super_tabs', { action: 'cardsWanted', on: 'yes' })).toMatchObject({ echoed: { action: 'cardsWanted', on: false } })
+ expect(await devices.answer('super_tabs', { action: 'cardRecap', tabId: 't1', leadId: 'l1', extra: 1 })).toMatchObject({ echoed: { action: 'cardRecap', tabId: 't1', leadId: 'l1' } })
+ expect(await devices.answer('super_tabs', { action: 'cardOpen', session: 'c1', tabId: 't1', leadId: null })).toMatchObject({ echoed: { action: 'cardOpen', session: 'c1', tabId: 't1', leadId: null } })
+ // A core with no way to the service says so.
+ const bare = createDevicesLink({ core: fakeCore(), notify: () => true, call: vi.fn(), state: () => STATE })
+ expect(await bare.answer('super_tabs', { action: 'cardsWanted', on: true })).toEqual({ error: 'SERVICE_UNAVAILABLE' })
+ })
+})
diff --git a/cli/src/core/devicesLink.ts b/cli/src/core/devicesLink.ts
index cddbac402..ccdbd4401 100644
--- a/cli/src/core/devicesLink.ts
+++ b/cli/src/core/devicesLink.ts
@@ -70,6 +70,8 @@ export function createDevicesLink(deps: DevicesLinkDeps) {
card: (frame) => event('card', { frame }),
desk: (agentIds, foreground) => event('desk', { agentIds, foreground }),
swarms: (swarms) => event('swarms', { swarms }),
+ swarmCards: (items) => event('swarmCards', { items }),
+ swarmCardRecap: (recap) => event('swarmCardRecap', { recap }),
unread: (items) => event('unread', { items }),
appFocus: (machineId, agentId) => event('appFocus', { machineId, agentId }),
seen: (agentId, readToken) => event('seen', { agentId, ...(readToken === undefined ? {} : { readToken }) }),
@@ -120,6 +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).
+ 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 })
+ },
// 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 no
// credential and no E2EE identity.
diff --git a/cli/src/core/experimentQueries.spec.ts b/cli/src/core/experimentQueries.spec.ts
index 6d85e422a..0c0afbd1c 100644
--- a/cli/src/core/experimentQueries.spec.ts
+++ b/cli/src/core/experimentQueries.spec.ts
@@ -28,7 +28,7 @@ describe('the cloud agents\' doors', () => {
describe('the Super Tab service\'s door', () => {
it('is the Super Tab service\'s alone, and hands its members\' waits to the core whole', async () => {
- const superTabs = { attention: vi.fn() }
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
const core = fakeCore({ superTabs })
const both = new Set(['orchestrator', 'superTabs'])
const item = { agentId: 'a1', requestId: 'supertab:x:blocked', superTab: 'Pilot', attention: 'stuck', text: 'Stuck: no key' }
@@ -39,6 +39,23 @@ describe('the Super Tab service\'s door', () => {
expect(await answerExperimentQuery(core, both, 'orchestrator', 'super_tab_attention', {})).toEqual({ error: 'NOT_SUPER_TABS' })
expect(await answerExperimentQuery(fakeCore(), both, 'superTabs', 'super_tab_attention', {})).toEqual({ error: 'NOT_SUPER_TABS' })
})
+
+ it('hands it the Swarm cards and a Lead\'s recap the same way, to the Super Tab service alone', async () => {
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
+ const core = fakeCore({ superTabs })
+ const both = new Set(['orchestrator', 'superTabs'])
+ const recap = { tabId: 't1', leadId: 'l1', text: 'Shipped', at: 1, none: false }
+ expect(await answerExperimentQuery(core, both, 'superTabs', 'super_tab_cards', { items: [{ id: 't1' }] })).toEqual({})
+ expect(superTabs.cards).toHaveBeenLastCalledWith([{ id: 't1' }])
+ await answerExperimentQuery(core, both, 'superTabs', 'super_tab_cards', { items: 'x' })
+ expect(superTabs.cards).toHaveBeenLastCalledWith([])
+ expect(await answerExperimentQuery(core, both, 'superTabs', 'super_tab_card_recap', { recap })).toEqual({})
+ expect(superTabs.cardRecap).toHaveBeenLastCalledWith(recap)
+ for (const query of ['super_tab_cards', 'super_tab_card_recap']) {
+ expect(await answerExperimentQuery(core, both, 'orchestrator', query, {})).toEqual({ error: 'NOT_SUPER_TABS' })
+ expect(await answerExperimentQuery(fakeCore(), both, 'superTabs', query, {})).toEqual({ error: 'NOT_SUPER_TABS' })
+ }
+ })
})
describe('what an experiment in its own process may ask of the core', () => {
diff --git a/cli/src/core/experimentQueries.ts b/cli/src/core/experimentQueries.ts
index 992194b3c..cc32d53bd 100644
--- a/cli/src/core/experimentQueries.ts
+++ b/cli/src/core/experimentQueries.ts
@@ -20,7 +20,9 @@
* - `cloud_publish`, `cloud_ask`, `cloud_unask`: the cloud agents' harnesses and their questions
* (`core.cloud`, core/agents/cloud.ts), for the cloud service alone;
* - `super_tab_attention`: the Super Tab members here waiting on a person (`core.superTabs`,
- * core/superTabAttention.ts), for the Super Tab service alone.
+ * core/superTabAttention.ts), for the Super Tab service alone;
+ * - `super_tab_cards`, `super_tab_card_recap`: the Swarms' cards and a Lead's last message for the Harness Pro
+ * (`core.superTabs`, core/superTabCards.ts), for the Super Tab service alone.
* The core answers them only for the experiments (core/api.ts `EXPERIMENTS`): creating an agent or
* telling the windows something is no other process's to ask. The process's side is
* services/processCoreApi.ts. Agent Messages, an experiment until 2026-10-12, asks a few of the same and is
@@ -34,7 +36,7 @@ import { nativeTurnCursorIn } from '../lib/nativeTurnObservations.js'
type Payload = Record<string, unknown>
type Core = Pick<CoreApi, 'agents' | 'turns' | 'clients' | 'daemon' | 'account' | 'cloud' | 'superTabs' | 'transcripts'>
-const QUERIES: ReadonlySet<string> = new Set(['shown', 'close_swarm', 'stopped', 'gone', 'creation_status', 'native_turns', 'create', 'stop_turn', 'windows', 'daemon', 'backend', 'observer_key', 'observer_send', 'account', 'cloud_publish', 'cloud_ask', 'cloud_unask', 'super_tab_attention'])
+const QUERIES: ReadonlySet<string> = new Set(['shown', 'close_swarm', 'stopped', 'gone', 'creation_status', 'native_turns', 'create', 'stop_turn', 'windows', 'daemon', 'backend', 'observer_key', 'observer_send', 'account', 'cloud_publish', 'cloud_ask', 'cloud_unask', 'super_tab_attention', 'super_tab_cards', 'super_tab_card_recap'])
const METHODS: ReadonlySet<string> = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
const text = (value: unknown): string => (typeof value === 'string' ? value : '')
@@ -140,6 +142,14 @@ export async function answerExperimentQuery(core: Core, experiments: ReadonlySet
core.superTabs.attention(Array.isArray(payload.items) ? payload.items : [])
return {}
}
+ case 'super_tab_cards':
+ case 'super_tab_card_recap': {
+ // Checked by the core (core/superTabCards.ts), which drops what is not sound; here only the list's shape.
+ if (service !== 'superTabs' || !core.superTabs) return { error: 'NOT_SUPER_TABS' }
+ if (query === 'super_tab_cards') core.superTabs.cards(Array.isArray(payload.items) ? payload.items : [])
+ else core.superTabs.cardRecap(payload.recap as never)
+ return {}
+ }
case 'account': {
const known = await core.account.identity()
return known ? { ...known } : { error: 'ACCOUNT_UNAVAILABLE' }
diff --git a/cli/src/core/main.ts b/cli/src/core/main.ts
index df4981857..2180c3dc3 100644
--- a/cli/src/core/main.ts
+++ b/cli/src/core/main.ts
@@ -205,6 +205,7 @@ import { createSharingLink } from './sharingLink.js'
import { createAgentSettingsSync, createExperimentHooks, wakeExperiments } from './experiments.js'
import { answerExperimentQuery, createForExperiment, creationForExperiment } from './experimentQueries.js'
import { createSuperTabAttention } from './superTabAttention.js'
+import { createSuperTabCards } from './superTabCards.js'
import { answerConnectorsQuery } from './connectorsQueries.js'
import { answerSharedMachinesQuery } from './sharedMachinesQueries.js'
import { inlineSharedMachinesPort } from '../lib/sharedMachinesPort.js'
@@ -820,6 +821,17 @@ async function runForeground(session: AuthSession | null): Promise<void> {
send: (frame) => ports.devices?.card(frame),
asking: (agentId) => [...openQuestions.values()].some((asked) => asked.agentId === agentId),
})
+ // The Swarms' cards and Leads' recaps for the Harness Pro, on the devices alone (core/superTabCards.ts): kept whole, and shown
+ // again to a dial that attaches.
+ const routeSuperTabs = (payload: Record<string, unknown>): Promise<Record<string, unknown>> => new Promise((resolve) => {
+ const asker = { local: true, owner: true }
+ if (!(serviceLinksRef?.route('super_tabs', payload, asker, resolve) || serviceHost.route('super_tabs', payload, asker, resolve))) resolve({ error: 'SERVICE_UNAVAILABLE' })
+ })
+ const superTabCards = createSuperTabCards({
+ swarmCards: (items) => ports.devices?.swarmCards(items),
+ swarmCardRecap: (recap) => ports.devices?.swarmCardRecap(recap),
+ request: (payload) => routeSuperTabs(payload),
+ })
// Shared tabs' relay, a socket per shared tab held by the gateway (gateway/tabRelay.ts), and which of them the core saw
// opened: opened again after a gateway-only restart, closed when Agent Messages' process goes (core/gatewayLink.ts).
const tabRelay = tabRelayOf(() => gatewayOps.tabRelay)
@@ -829,7 +841,9 @@ async function runForeground(session: AuthSession | null): Promise<void> {
const coreApi = createCoreApi({
nativeTurns: async (agentId, cursor) => nativeTurns.read(agentId, cursor),
cloud: cloudDoors,
- superTabs: { attention: (items) => superTabWaits.attention(items) },
+ superTabs: { attention: (items) => superTabWaits.attention(items), cards: (items) => superTabCards.cards(items), cardRecap: (recap) => superTabCards.recap(recap) },
+ // The devices' `cardsWanted`, `cardRecap` and `cardOpen`, and no other action of the Super Tab service (core/superTabCards.ts `ask`).
+ superTabRequest: (payload) => superTabCards.ask(payload),
cloudRows: () => (cloudAgents?.dialRows() ?? []) as unknown as RegisteredSession[],
// Agents' terminals: a literal-argv launch, and a read-only view for Share's observers (core/terminalWatch.ts).
terminals: { ...TERMINALS_OFF, ...createTerminalOpener({ createBackend, registry, announceSession, blocksFolder: (cwd) => !!backendRef?.purgeAgentService?.blocksFolder(cwd), noBackendCode: createUnavailable }), watch: terminalWatch.watch },
@@ -920,6 +934,7 @@ async function runForeground(session: AuthSession | null): Promise<void> {
if (attached) void mirror.liveCards().then((cards) => { for (const frame of cards) ports.devices?.card(frame) })
if (attached) for (const frame of cloudAgents?.liveCards() ?? []) ports.devices?.card(frame)
if (attached) superTabWaits.replay()
+ if (attached) superTabCards.replay()
},
// What a device or another machine asks of an agent here: the SAME handlers the backend socket
// drives, called directly — the slash-command adaptation and the turn and question plumbing live there.
@@ -1521,6 +1536,7 @@ async function runForeground(session: AuthSession | null): Promise<void> {
// The gateway first hears what it starts from, then the shared tabs it held before a restart.
if (service === 'gateway') { gatewayLink?.connected(); tabRelay.connected() }
if (service === 'devices') devicesLink.connected()
+ if (service === 'superTabs') superTabCards.serviceUp()
if (service === 'wifi') wifiCore.started(appVoiceFocus ?? null)
if (service === 'viewers') viewersLink.connected()
devicesWake.connected(service)
@@ -1543,7 +1559,7 @@ async function runForeground(session: AuthSession | null): Promise<void> {
if (service === 'gateway') gatewayLink?.disconnected()
// Agent Messages' process went: its tabs' sockets have no one to hear them, and it opens them again as it starts.
if (service === 'messages') tabRelay.closeOpened()
- if (service === 'devices') devicesLink.disconnected()
+ if (service === 'devices') { devicesLink.disconnected(); superTabCards.devicesGone() }
if (service === 'wifi') wifiCore.stopped()
if (service === 'recaps') recapsLink.disconnected()
void terminalWatch.gone(service)
@@ -2946,6 +2962,7 @@ async function runForeground(session: AuthSession | null): Promise<void> {
// The web-tools cache lives exactly as long as the sign-in. `harness logout` and `reset` stop
// the daemon outright; this is the one sign-out the daemon learns of from inside.
ports.models?.signedOut()
+ superTabCards.reset()
void shutdown('revoked')
}
@@ -2973,7 +2990,8 @@ async function runForeground(session: AuthSession | null): Promise<void> {
// blocking: an unplugged cable is this daemon's ordinary state.
// In their own process they are told everything the windows said as they connect (core/devicesLink.ts):
// said here too, it reached a dial still opening its port, before its greeting.
- if (outOfProcess.has('devices')) ports.devices = devicesLink.port
+ // The Swarm cards the Super Tab service sent before this line had no devices to reach: they are shown now.
+ if (outOfProcess.has('devices')) { ports.devices = devicesLink.port; superTabCards.replay() }
else {
serviceHost.start('devices', (core, started) => inline!.startDevices(core, started, {
logsDir: env.HARNESS_LOGS_DIR, testDialPort: harnessd.HARNESSD_TEST_DIAL_PORT,
diff --git a/cli/src/core/superTabCards.spec.ts b/cli/src/core/superTabCards.spec.ts
new file mode 100644
index 000000000..306796602
--- /dev/null
+++ b/cli/src/core/superTabCards.spec.ts
@@ -0,0 +1,175 @@
+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 })
+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 })
+
+function setup() {
+ const swarmCards = vi.fn(), swarmCardRecap = vi.fn(), log = vi.fn()
+ const cards = createSuperTabCards({ swarmCards, swarmCardRecap, log })
+ return { swarmCards, swarmCardRecap, log, cards }
+}
+
+describe('the Swarm cards on the devices', () => {
+ it('forwards each list whole, keeps the last one and replays it to a device that attaches', () => {
+ const { cards, swarmCards } = setup()
+ cards.replay()
+ expect(swarmCards).not.toHaveBeenCalled()
+ const list = [card('t1', [lead('l1'), lead('l2', { state: 'ask' }, ), lead('l3', { since: undefined })])]
+ 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')
+ swarmCards.mockClear()
+ cards.replay()
+ expect(swarmCards).toHaveBeenCalledOnce()
+ // An empty list is a list too: the devices clear their cards.
+ cards.cards([])
+ swarmCards.mockClear()
+ cards.replay()
+ expect(swarmCards).toHaveBeenCalledWith([])
+ })
+
+ it('checks ids, counts and strings, and drops a malformed list whole, keeping the last good one', () => {
+ const { cards, swarmCards, log } = setup()
+ cards.cards([card('t1')])
+ swarmCards.mockClear()
+ const bad: unknown[] = [
+ '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')], { count: -1 })], [card('t1', [lead('l1')], { count: 1.5 })], [card('t1', [lead('l1')], { name: 3 })],
+ ]
+ for (const list of bad) cards.cards(list)
+ expect(swarmCards).not.toHaveBeenCalled()
+ expect(log).toHaveBeenCalledTimes(bad.length)
+ cards.replay()
+ expect(swarmCards).toHaveBeenCalledWith([card('t1')])
+ })
+
+ it('keeps at most 16 Swarms of 12 Leads and cuts strings on a character boundary', () => {
+ const { cards, swarmCards } = setup()
+ const many = Array.from({ length: 20 }, (_, i) => card(`t${i}`, Array.from({ length: 15 }, (_, j) => lead(`l${j}`))))
+ cards.cards(many)
+ const sent = swarmCards.mock.calls[0][0]
+ expect(sent).toHaveLength(16)
+ expect(sent[0].leads).toHaveLength(12)
+ swarmCards.mockClear()
+ cards.cards([card('t1', [lead('l1', { project: 'é'.repeat(40), owner: 'ö'.repeat(40), engine: 'e'.repeat(30) })], { name: '日'.repeat(30) })])
+ const [only] = swarmCards.mock.calls[0][0]
+ expect(Buffer.byteLength(only.name)).toBe(48)
+ expect(only.name).toBe('日'.repeat(16))
+ expect(Buffer.byteLength(only.leads[0].project)).toBe(48)
+ expect(Buffer.byteLength(only.leads[0].owner)).toBe(48)
+ expect(only.leads[0].engine).toHaveLength(16)
+ })
+
+ it('says what it drops on the console when it is given no log of its own', () => {
+ const logged = vi.spyOn(console, 'log').mockImplementation(() => {})
+ createSuperTabCards({ swarmCards: vi.fn(), swarmCardRecap: vi.fn() }).recap(null)
+ expect(logged).toHaveBeenCalledWith(expect.stringContaining('not sound'))
+ logged.mockRestore()
+ })
+
+ it('forwards a checked recap, cut at 1,500 bytes, and refuses a malformed one', () => {
+ const { cards, swarmCardRecap, log } = setup()
+ cards.recap(recap())
+ expect(swarmCardRecap).toHaveBeenLastCalledWith(recap())
+ cards.recap(recap({ text: '日'.repeat(600) }))
+ expect(swarmCardRecap.mock.calls[1][0].text).toBe('日'.repeat(500))
+ cards.recap(recap({ text: '', at: 0, none: true }))
+ expect(swarmCardRecap).toHaveBeenCalledTimes(3)
+ for (const bad of [null, 'x', recap({ tabId: 'bad id' }), recap({ leadId: '' }), recap({ text: 5 }), recap({ at: -1 }), recap({ at: 'now' }), recap({ none: 'no' })]) cards.recap(bad)
+ expect(swarmCardRecap).toHaveBeenCalledTimes(3)
+ expect(log).toHaveBeenCalledTimes(8)
+ })
+})
+
+describe('whether the Swarm cards are wanted, which the core owns', () => {
+ function wanting() {
+ const request = vi.fn(async (_payload: Record<string, unknown>) => ({ ok: true }))
+ const swarmCards = vi.fn()
+ const cards = createSuperTabCards({ swarmCards, swarmCardRecap: vi.fn(), request, log: vi.fn() })
+ return { cards, request, swarmCards }
+ }
+ it('tells the service when a capable device comes, which Swarms to read first, and when the last goes; a repeat says nothing', () => {
+ const { cards, request } = wanting()
+ cards.want(true, ['t1', 'bad id', 't1', 't2'])
+ cards.want(true, ['t1', 't2'])
+ expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['t1', 't2'] }]])
+ cards.want(true, ['t2'])
+ expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['t2'] })
+ cards.want(false, ['t2'])
+ expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: false, include: [] })
+ cards.want(false, [])
+ expect(request).toHaveBeenCalledTimes(3)
+ // Swarms that are not a list are none.
+ cards.want(true, 'nonsense')
+ expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: [] })
+ })
+ it('says it again whenever the service (re)connects, only while a device wants the cards', () => {
+ const { cards, request } = wanting()
+ cards.serviceUp()
+ expect(request).not.toHaveBeenCalled()
+ cards.want(true, ['t1'])
+ request.mockClear()
+ cards.serviceUp()
+ expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['t1'] }]])
+ cards.want(false, [])
+ request.mockClear()
+ cards.serviceUp()
+ expect(request).not.toHaveBeenCalled()
+ })
+ it('takes the wish back when the devices go, so a crashed devices process stops the polling', () => {
+ const { cards, request } = wanting()
+ cards.devicesGone()
+ expect(request).not.toHaveBeenCalled()
+ cards.want(true, [])
+ cards.devicesGone()
+ expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: false, include: [] })
+ request.mockClear()
+ cards.serviceUp()
+ expect(request).not.toHaveBeenCalled()
+ })
+ it('on an account change forgets the list, clears the devices\' cards and has the service start over', () => {
+ const { cards, request, swarmCards } = wanting()
+ cards.cards([card('t1')])
+ cards.want(true, ['t1'])
+ request.mockClear(); swarmCards.mockClear()
+ cards.reset()
+ expect(swarmCards).toHaveBeenCalledWith([])
+ expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: false, include: [] }], [{ action: 'cardsWanted', on: true, include: ['t1'] }]])
+ swarmCards.mockClear()
+ cards.replay()
+ expect(swarmCards).not.toHaveBeenCalled()
+ })
+ it('lets the devices ask three things of the service and nothing else, whatever the path', async () => {
+ const { cards, request } = wanting()
+ expect(await cards.ask({ action: 'cardsWanted', on: true, include: ['t1'] })).toEqual({ ok: true })
+ expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['t1'] }]])
+ request.mockClear()
+ await cards.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1', extra: 1 })
+ await cards.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null, extra: 1 })
+ expect(request.mock.calls).toEqual([[{ action: 'cardRecap', tabId: 't1', leadId: 'l1' }], [{ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null }]])
+ request.mockClear()
+ for (const action of ['backend', 'command', 'wake', 'prepareContribution', undefined]) expect(await cards.ask({ action, path: '/api/super-tabs' })).toEqual({ error: 'INVALID_REQUEST' })
+ expect(request).not.toHaveBeenCalled()
+ request.mockRejectedValueOnce(new Error('gone'))
+ expect(await cards.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1' })).toEqual({ error: 'SERVICE_UNAVAILABLE' })
+ })
+ it('on an account change with no device wanting cards only clears the list', () => {
+ const { cards, request, swarmCards } = wanting()
+ cards.cards([card('t1')])
+ swarmCards.mockClear()
+ cards.reset()
+ expect(swarmCards).toHaveBeenCalledWith([])
+ expect(request).not.toHaveBeenCalled()
+ })
+ it('answers unavailable when the core has no way to the service', async () => {
+ const cards = createSuperTabCards({ swarmCards: vi.fn(), swarmCardRecap: vi.fn(), log: vi.fn() })
+ cards.want(true, [])
+ expect(await cards.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null })).toEqual({ error: 'SERVICE_UNAVAILABLE' })
+ })
+})
diff --git a/cli/src/core/superTabCards.ts b/cli/src/core/superTabCards.ts
new file mode 100644
index 000000000..ac9742b9d
--- /dev/null
+++ b/cli/src/core/superTabCards.ts
@@ -0,0 +1,151 @@
+/**
+ * The Swarms this account is in, as cards for the Harness Pro (superTabs/cards.ts): for each Swarm, its Leads and what
+ * each is doing, and the last thing a Lead said (its recap). The Super Tab service reads them from the backend and tells
+ * the core (`core.superTabs.cards`, `.cardRecap`); the core hands them to the devices, which put them on the cable.
+ *
+ * Only the devices hear these (`swarmCards`, `swarmCardRecap`): never the Wi-Fi device, the backend or a window.
+ *
+ * The list is the service's to say, whole, each time it changes; the core keeps the last one, so a dial that attaches
+ * later is shown it (`replay`). A list is taken whole or not at all: one item that is not one drops the list and the last
+ * good one stays, so a device never shows half a Swarm. A recap is one Lead's and is forwarded as it comes.
+ *
+ * The core also owns whether the cards are wanted at all (like core/superTabAttention.ts owns its waits): the devices say
+ * whether a capable Pro is attached and which Swarms the desktop has tabs for (`want`), and the core says it to the Super Tab
+ * service, again whenever that service (re)connects (`serviceUp`), and takes it back when the devices go (`devicesGone`).
+ */
+import type { LeadRecap, SwarmCard, SwarmLead } from '../superTabs/cards.js'
+
+export interface SuperTabCardsDeps {
+ /** The devices' door for the list (`ports.devices.swarmCards`). */
+ swarmCards(items: SwarmCard[]): void
+ /** The devices' door for one recap (`ports.devices.swarmCardRecap`). */
+ swarmCardRecap(recap: LeadRecap): void
+ /** The Super Tab service's `super_tabs` request (cardsWanted); its answer is not needed. */
+ request?(payload: Record<string, unknown>): Promise<unknown>
+ log?: (line: string) => void
+}
+
+const MAX_CARDS = 16, MAX_LEADS = 12, NAME_BYTES = 48, ENGINE_BYTES = 16, RECAP_BYTES = 1500
+const STATES: ReadonlySet<string> = new Set(['ask', 'stuck', 'work', 'done'])
+/** The Pro keeps an id in 48 bytes with its NUL. */
+const ID = /^[A-Za-z0-9_-]{1,47}$/
+const id = (value: unknown): value is string => typeof value === 'string' && ID.test(value)
+const whole = (value: unknown): value is number => typeof value === 'number' && Number.isInteger(value) && value >= 0
+const object = (value: unknown): Record<string, unknown> => (value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {})
+
+/** Cut on a character, never inside one: the Pro refuses a string it cannot read as UTF-8. */
+function cut(text: string, bytes: number): string {
+ let out = '', used = 0
+ for (const char of text) {
+ used += Buffer.byteLength(char)
+ if (used > bytes) break
+ out += char
+ }
+ return out
+}
+
+/** A Lead the service sent, checked and cut; null when it is not one. */
+function leadIn(value: unknown): SwarmLead | null {
+ const lead = object(value)
+ if (!id(lead.id) || !id(lead.projectId) || typeof lead.state !== 'string' || !STATES.has(lead.state)) return null
+ if (typeof lead.project !== 'string' || typeof lead.engine !== 'string' || typeof lead.owner !== 'string') return 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 null
+ if (lead.since !== undefined && !whole(lead.since)) return null
+ return {
+ 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'],
+ ...(lead.since === undefined ? {} : { since: lead.since }),
+ }
+}
+
+/** A Swarm the service sent, checked and cut; null when it is not one. */
+function cardIn(value: unknown): SwarmCard | null {
+ const card = object(value)
+ if (!id(card.id) || typeof card.name !== 'string' || !whole(card.count) || !Array.isArray(card.leads)) return null
+ const leads: SwarmLead[] = []
+ for (const value of card.leads.slice(0, MAX_LEADS)) {
+ const lead = leadIn(value)
+ if (!lead) return null
+ leads.push(lead)
+ }
+ return { id: card.id, name: cut(card.name, NAME_BYTES), count: card.count, leads }
+}
+
+/** A recap the service sent, checked and cut; null when it is not one. */
+function recapIn(value: unknown): LeadRecap | null {
+ const recap = object(value)
+ if (!id(recap.tabId) || !id(recap.leadId) || typeof recap.text !== 'string' || !whole(recap.at) || typeof recap.none !== 'boolean') return null
+ return { tabId: recap.tabId, leadId: recap.leadId, text: cut(recap.text, RECAP_BYTES), at: recap.at, none: recap.none }
+}
+
+export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log = (line) => console.log(line) }: SuperTabCardsDeps) {
+ /** The last good list, or null before the service has said one. */
+ let last: SwarmCard[] | null = null
+ /** Whether any capable device wants cards, and the Swarms to read first. */
+ let wanted = false, include: string[] = []
+ const route = async (payload: Record<string, unknown>): Promise<Record<string, unknown>> => {
+ try {
+ const answer = await request?.(payload)
+ return answer === undefined ? { error: 'SERVICE_UNAVAILABLE' } : object(answer)
+ } catch { return { error: 'SERVICE_UNAVAILABLE' } }
+ }
+ const tell = (): void => { void route({ action: 'cardsWanted', on: wanted, include }) }
+ const api = {
+ /** The devices say whether a capable Pro is attached (and which Swarms the desktop has open): the service is told. */
+ want(on: boolean, swarms: unknown): void {
+ const next = on && Array.isArray(swarms) ? [...new Set(swarms.filter(id))].slice(0, MAX_CARDS) : []
+ if (on === wanted && next.join(',') === include.join(',')) return
+ wanted = on
+ include = next
+ tell()
+ },
+ /** The Super Tab service (re)connected: it has forgotten, so it is told again if a device wants the cards. */
+ serviceUp(): void {
+ if (wanted) tell()
+ },
+ /** The devices went (their process or link): nothing reads the Swarms for them, and each wakes with a fresh count. */
+ devicesGone(): void {
+ if (!wanted) return
+ wanted = false
+ include = []
+ tell()
+ },
+ /** The account changed or ended: the list shown and kept is of someone else, and the service starts over. */
+ reset(): void {
+ last = null
+ swarmCards([])
+ if (wanted) { void route({ action: 'cardsWanted', on: false, include: [] }); tell() }
+ },
+ /** Every Swarm, replacing the last list: forwarded whole when every item is sound, else dropped and logged. */
+ cards(items: unknown): void {
+ const next: SwarmCard[] = []
+ for (const value of Array.isArray(items) ? items.slice(0, MAX_CARDS) : [null]) {
+ const card = cardIn(value)
+ if (!card) { log('[super-tabs] a Swarm card list was not sound; the last one stays'); return }
+ next.push(card)
+ }
+ last = next
+ swarmCards(next)
+ },
+ /** One Lead's last message, forwarded as it comes. */
+ recap(value: unknown): void {
+ const recap = recapIn(value)
+ 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. */
+ 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 === 'cardOpen') return route({ action: 'cardOpen', session: payload.session, tabId: payload.tabId, leadId: payload.leadId })
+ return Promise.resolve({ error: 'INVALID_REQUEST' })
+ },
+ /** A dial attached: it has nothing, so it is shown the last list again. */
+ replay(): void {
+ if (last) swarmCards(last)
+ },
+ }
+ return api
+}
diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.ts
index 4e0572024..124907642 100644
--- a/cli/src/localWsServer.spec.ts
+++ b/cli/src/localWsServer.spec.ts
@@ -751,6 +751,39 @@ describe('local CLI WebSocket', () => {
expect(tabs).toHaveBeenLastCalledWith(backend.connId, null)
})
+ it('keeps a Swarm tab\'s superTabId and projectId when they are ids, and the fromDevice mark; drops them otherwise', async () => {
+ const backend = new FakeBackend()
+ const seen: unknown[] = []
+ server = http.createServer((_req, res) => { res.statusCode = 404; res.end() })
+ local = attachLocalWsServer(server, { machineId, backend, onAppSwarms: (swarms) => seen.push(swarms) })
+ await new Promise<void>((resolve) => server!.listen(0, '127.0.0.1', resolve))
+ const ws = new WebSocket(`ws://127.0.0.1:${(server.address() as AddressInfo).port}/api/local-ws`)
+ await onceOpen(ws)
+ const connected = onceMessage(ws)
+ ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId, localProtocolVersion: 1 } }))
+ await connected
+ ws.send(JSON.stringify({ type: 'app_swarms', payload: {
+ active: 's1', fromDevice: true,
+ swarms: [
+ { id: 's1', name: 'Swarm', agentIds: [], panes: 1, superTabId: 'st_1', projectId: 'p-1' },
+ { id: 's2', name: 'Bad', agentIds: [], panes: 1, superTabId: 'no spaces', projectId: 7 },
+ { id: 's3', name: 'Long', agentIds: [], panes: 1, superTabId: 'x'.repeat(48), projectId: 'y'.repeat(48) },
+ ],
+ } }))
+ ws.send(JSON.stringify({ type: 'app_swarms', payload: { active: 's1', fromDevice: 'yes', swarms: [{ id: 's1', name: 'Swarm', agentIds: [], panes: 0, superTabId: 'st_1' }] } }))
+ await vi.waitFor(() => expect(seen).toHaveLength(2))
+ expect(seen).toEqual([
+ { active: 's1', fromDevice: true, tiles: [], swarms: [
+ { id: 's1', name: 'Swarm', agentIds: [], panes: 1, superTabId: 'st_1', projectId: 'p-1' },
+ { id: 's2', name: 'Bad', agentIds: [], panes: 1 },
+ { id: 's3', name: 'Long', agentIds: [], panes: 1 },
+ ] },
+ // Only a literal true marks it: anything else is an ordinary announce.
+ { active: 's1', tiles: [], swarms: [{ id: 's1', name: 'Swarm', agentIds: [], panes: 0, superTabId: 'st_1' }] },
+ ])
+ ws.close()
+ })
+
for (const latestCloses of [false, true]) {
it(`keeps the device's desk when a ${latestCloses ? 'latest' : 'background'} machine connection closes`, async () => {
const backend = new FakeBackend(), panes = vi.fn(), swarms = vi.fn(), tabs = vi.fn()
diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.ts
index 071829368..5201b85ea 100644
--- a/cli/src/localWsServer.ts
+++ b/cli/src/localWsServer.ts
@@ -223,6 +223,9 @@ function jsonFrame(raw: RawData, maxBytes = MAX_JSON_BYTES): Frame | null {
}
}
+/** A Super Tab or project id as the backend writes them, as long as the Harness Pro holds one (48 bytes with its NUL). */
+const CARD_ID = /^[A-Za-z0-9_-]{1,47}$/
+
/**
* The window's swarm list, checked field by field. Anything that is not an id, a name and a list of
* agent ids is dropped rather than trusted — the same stance app_panes takes with its ids — and a
@@ -246,7 +249,11 @@ function appSwarmsFrom(payload: unknown): AppSwarms | null {
const panes = typeof r.panes === 'number' && Number.isFinite(r.panes) && r.panes >= 0
? Math.min(Math.floor(r.panes), 999)
: agentIds.length
- swarms.push({ id: r.id, name: r.name.slice(0, 80), agentIds, panes })
+ // A Super Tab (Swarm) tab names its Swarm and the project the window has open in it; the Harness Pro's Swarm card
+ // links to the tab by the first and follows the second. Ids only: anything else is dropped, not trusted.
+ const superTabId = typeof r.superTabId === 'string' && CARD_ID.test(r.superTabId) ? r.superTabId : undefined
+ const projectId = typeof r.projectId === 'string' && CARD_ID.test(r.projectId) ? r.projectId : undefined
+ swarms.push({ id: r.id, name: r.name.slice(0, 80), agentIds, panes, ...(superTabId ? { superTabId } : {}), ...(projectId ? { projectId } : {}) })
if (swarms.length === 24) break // the window's own ceiling
}
if (swarms.length === 0) return null
@@ -266,7 +273,8 @@ function appSwarmsFrom(payload: unknown): AppSwarms | null {
tiles.push({ x1, y1, x2, y2, agentId: typeof t.agentId === 'string' ? t.agentId : '' })
if (tiles.length === 24) break // the window's own ceiling, same as the rows above
}
- return { active, swarms, tiles }
+ // Set by the window on the announce a device's pick caused, so the device is not told to follow its own choice back.
+ return { active, swarms, tiles, ...(p.fromDevice === true ? { fromDevice: true } : {}) }
}
function binaryBytes(raw: RawData): Uint8Array {
diff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.ts
index 72944d382..b66770d29 100644
--- a/cli/src/services/devices.spec.ts
+++ b/cli/src/services/devices.spec.ts
@@ -42,6 +42,8 @@ vi.mock('../cable/cableFleet.js', async (real) => {
stop = recorder('stop')
syncAgents = recorder('syncAgents')
syncSwarms = recorder('syncSwarms')
+ syncSwarmCards = recorder('syncSwarmCards')
+ swarmCardRecap = recorder('swarmCardRecap')
syncMachines = recorder('syncMachines')
followApp = recorder('followApp')
replaceNotifications = recorder('replaceNotifications')
@@ -153,6 +155,7 @@ function start(over: { core?: CoreApi; faults?: string[]; cableDisabled?: boolea
const core = over.core ?? fakeCore({ dataDir })
const ports: CorePorts = emptyPorts()
const onExit = vi.fn()
+ const reconnected: Array<() => void> = []
const requests = startDevices(core, ports, {
logsDir: join(dataDir, 'logs'),
petsDir: join(dataDir, 'pets'),
@@ -165,8 +168,9 @@ function start(over: { core?: CoreApi; faults?: string[]; cableDisabled?: boolea
faults: new Set(over.faults ?? []),
log: (line) => { logs.push(line) },
onExit,
+ onCoreConnected: (run) => { reconnected.push(run) },
})
- return { core, ports, port: ports.devices as DevicesPort, requests, onExit }
+ return { core, ports, port: ports.devices as DevicesPort, requests, onExit, reconnected }
}
const calls = (name: string) => seen.cable.calls.filter(([called]) => called === name).map(([, args]) => args)
@@ -543,11 +547,104 @@ describe('what the windows say, reaching the dial', () => {
port.unread([{ agentId: 'a1', machineId: 'm1', text: 'done', question: false }])
port.appFocus('m1', 'a1')
port.seen('a1', 'tok')
- expect(seen.cable.calls.map(([name]) => name)).toEqual(['start', 'syncSwarms', 'syncAgents', 'replaceNotifications', 'followApp', 'agentSeen'])
+ expect(seen.cable.calls.map(([name]) => name)).toEqual(['start', 'syncSwarms', 'syncAgents', 'syncSwarmCards', 'replaceNotifications', 'followApp', 'agentSeen'])
expect(calls('followApp')).toEqual([['m1', 'a1']])
expect(calls('agentSeen')).toEqual([['a1', 'tok']])
})
+ 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 cards = [{ id: 'st1', name: 'openharness', count: 1, leads: [lead] }]
+ const withRequest = (superTabRequest?: CoreApi['superTabRequest']) => start({ core: { ...fakeCore({ dataDir }), ...(superTabRequest ? { superTabRequest } : {}) } as CoreApi })
+
+ it('keeps the list for the cable and tells every device when it changes; a recap is passed on', () => {
+ const { port } = start()
+ port.swarmCards(cards)
+ expect(seen.dial).toMatchObject({ cards })
+ expect(calls('syncSwarmCards')).toEqual([[]])
+ const recap = { tabId: 'st1', leadId: 'lead1', text: 'hi', at: 1, none: false }
+ port.swarmCardRecap(recap)
+ expect(calls('swarmCardRecap')).toEqual([[recap]])
+ })
+
+ it('asks the service for cards when the first capable device attaches and stops when the last leaves', () => {
+ const superTabRequest = vi.fn(async () => ({ ok: true }))
+ withRequest(superTabRequest)
+ seen.host.swarmCardsWanted!(true)
+ seen.host.swarmCardsWanted!(true)
+ expect(superTabRequest.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: [] }]])
+ seen.host.swarmCardsWanted!(false)
+ expect(superTabRequest).toHaveBeenCalledTimes(1)
+ seen.host.swarmCardsWanted!(false)
+ expect(superTabRequest.mock.calls[1]).toEqual([{ action: 'cardsWanted', on: false, include: [] }])
+ // A stray "gone" never counts below none.
+ seen.host.swarmCardsWanted!(false)
+ seen.host.swarmCardsWanted!(true)
+ expect(superTabRequest.mock.calls[2]).toEqual([{ action: 'cardsWanted', on: true, include: [] }])
+ })
+
+ it('sends the Swarms the desktop has tabs for with the wish, again when they change, and says it all again when the core reconnects', () => {
+ const superTabRequest = vi.fn(async () => ({ ok: true }))
+ const { port, reconnected } = withRequest(superTabRequest)
+ const tabs = (...ids: string[]) => ({ active: 'a', tiles: [], swarms: [{ id: 'plain', name: 'plain', agentIds: [], panes: 0 }, ...ids.map((id) => ({ id: `tab-${id}`, name: id, agentIds: [], panes: 0, superTabId: id }))] })
+ // Nobody wants cards yet: nothing is said, but the tabs are remembered.
+ port.swarms(tabs('st1', 'st2', 'st1'))
+ expect(superTabRequest).not.toHaveBeenCalled()
+ seen.host.swarmCardsWanted!(true)
+ expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1', 'st2'] })
+ port.swarms(tabs('st1', 'st2'))
+ expect(superTabRequest).toHaveBeenCalledTimes(1)
+ port.swarms(tabs('st2'))
+ expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st2'] })
+ // The window gone leaves no Swarm tab to read first.
+ port.swarms(null)
+ expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: [] })
+ port.swarms(tabs('st2'))
+ // A core that connects anew has forgotten: the current count is said again, and nothing with no device.
+ superTabRequest.mockClear()
+ reconnected.forEach((run) => run())
+ expect(superTabRequest.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['st2'] }]])
+ seen.host.swarmCardsWanted!(false)
+ superTabRequest.mockClear()
+ reconnected.forEach((run) => run())
+ expect(superTabRequest).not.toHaveBeenCalled()
+ })
+
+ it('reads a recap through the service, cut to 1,500 bytes on a character; anything unusable is null', async () => {
+ const answers: Array<Record<string, unknown> | 'throw'> = [
+ { ok: true, tabId: 'st1', leadId: 'lead1', text: 'é'.repeat(1000), at: 1792560000, none: false },
+ { ok: true, text: 'none', at: 0, none: true },
+ { error: 'NOT_FOUND' }, { ok: true, text: 5, at: 1, none: false }, { ok: true, text: 'x', at: 1.5, none: false },
+ { ok: true, text: 'x', at: -1, none: false }, { ok: true, text: 'x', at: 1, none: 'no' }, 'throw',
+ ]
+ const superTabRequest = vi.fn(async () => { const next = answers.shift()!; if (next === 'throw') throw new Error('gone'); return next })
+ withRequest(superTabRequest)
+ const got = await seen.host.swarmCardRecap!('st1', 'lead1')
+ expect(superTabRequest).toHaveBeenCalledWith({ action: 'cardRecap', tabId: 'st1', leadId: 'lead1' })
+ expect(got).toMatchObject({ tabId: 'st1', leadId: 'lead1', at: 1792560000, none: false })
+ expect(got!.text).toBe('é'.repeat(750))
+ expect(await seen.host.swarmCardRecap!('st1', 'lead2')).toEqual({ tabId: 'st1', leadId: 'lead2', text: 'none', at: 0, none: true })
+ for (let i = 0; i < 6; i++) expect(await seen.host.swarmCardRecap!('st1', 'lead1')).toBeNull()
+ })
+
+ it('answers no recap when the core has no service to ask', async () => {
+ start()
+ expect(await seen.host.swarmCardRecap!('st1', 'lead1')).toBeNull()
+ seen.host.swarmCardOpen!('c1', 'st1', 'lead1') // nothing to tell, and nothing thrown
+ })
+
+ it('tells the service which Lead is open, and opens a picked Lead on the desktop', () => {
+ const superTabRequest = vi.fn(async () => ({ ok: true }))
+ const { core } = withRequest(superTabRequest)
+ seen.host.swarmCardOpen!('c1', 'st1', 'lead1')
+ seen.host.swarmCardOpen!('c1', 'st1', null)
+ expect(superTabRequest.mock.calls).toEqual([
+ [{ action: 'cardOpen', session: 'c1', tabId: 'st1', leadId: 'lead1' }], [{ action: 'cardOpen', session: 'c1', tabId: 'st1', leadId: null }]])
+ seen.host.superTabSelected!('st1', 'proj1')
+ expect(vi.mocked(core.clients.sendLocal)).toHaveBeenCalledWith({ type: 'dial_super_tab', payload: { superTabId: 'st1', projectId: 'proj1' } })
+ })
+ })
+
it('changes one device\'s settings, and logs a refusal', async () => {
const { port } = start()
port.settings('usb', { brightness: 3 })
diff --git a/cli/src/services/devices.ts b/cli/src/services/devices.ts
index 33c0cb44d..a0331c1e0 100644
--- a/cli/src/services/devices.ts
+++ b/cli/src/services/devices.ts
@@ -34,6 +34,7 @@ import { WindowSelection } from '../cable/windowSelection.js'
import { WindowVisit } from '../cable/windowVisit.js'
import { MachineListCache } from '../device/machineList.js'
import { harnessDevicesRequest } from '../lib/harnessDevices.js'
+import { truncateUtf8 } from '../lib/deviceRecentTrim.js'
import { setVoiceRouterDeviceConnected, setVoiceRouterSessions, shutdownVoiceRouter } from '../lib/voiceRouter.js'
import { createJevDecide } from '../lib/jev/jevClient.js'
import { createTally, createTierDecider, type Tier, type TierDecision, type TierInput } from '../lib/notifyTier.js'
@@ -66,6 +67,9 @@ export interface DevicesDeps {
/** Read this computer's agents again before a list is built from them: in their own process the devices
* keep a copy, asked of the core as the dial's tick or ⌘K needs it (services/devicesProcess.ts). */
refresh?: () => Promise<void>
+ /** Called with a function this part runs whenever it (re)connects to the core, which has forgotten what the devices
+ * told it (services/devicesProcess.ts): the cards wanted are said again. */
+ onCoreConnected?: (run: () => void) => void
/** An agent's conversation token totals, read fresh (not the 15 s cache); null when unknown or remote.
* Defaults to the core's `usageFresh`. */
readUsage?: (agentId: string) => Promise<{ input?: number; cached?: number; output?: number } | null>
@@ -155,6 +159,16 @@ 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.
+ const askCards = async (payload: Record<string, unknown>): Promise<Record<string, unknown>> => {
+ try { return await core.superTabRequest!(payload) } catch { return { error: 'SERVICE_UNAVAILABLE' } }
+ }
+ // How many attached devices asked for Swarm cards, and which Swarms the desktop has tabs for (read first). The core keeps
+ // whether they are wanted (core/superTabCards.ts); this says it on a change and again when the core connects anew.
+ let cardDevices = 0
+ let cardInclude: string[] = []
+ const tellCards = (): void => { void askCards({ action: 'cardsWanted', on: cardDevices > 0, include: cardDevices > 0 ? cardInclude : [] }) }
+ deps.onCoreConnected?.(() => { if (cardDevices > 0) tellCards() })
const cableHost = new DaemonCableHost({
// The cloud harnesses too, where the core offers them: tiles on the desk the dial walks like any other.
sessions: () => [...core.agents.advertised(), ...core.agents.cloud?.() ?? []],
@@ -203,6 +217,20 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)
forkAgent: (agentId) => core.agents.fork(agentId),
focused: (machineId, agentId) => core.clients.sendLocal({ type: 'dial_focus', payload: { machineId, agentId } }),
swarmSelected: (swarmId) => core.clients.sendLocal({ type: 'dial_swarm', payload: { swarmId } }),
+ swarmCardsWanted: (on) => {
+ const before = cardDevices
+ cardDevices = Math.max(0, cardDevices + (on ? 1 : -1))
+ if ((before === 0) !== (cardDevices === 0)) tellCards()
+ },
+ // The text is the service's to read and not validated by the core: cut here, on a character, to what the Pro takes.
+ swarmCardRecap: async (tabId, leadId) => {
+ const r = await askCards({ action: 'cardRecap', tabId, leadId })
+ if (r.ok !== true || typeof r.text !== 'string' || typeof r.at !== 'number' || !Number.isInteger(r.at) || r.at < 0 || typeof r.none !== 'boolean') return null
+ 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 }) },
+ // 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 } }),
// Gestures stay at this desk. The device inventory and its settings also reach the owner's other
// machines, through the encrypted device-management event.
@@ -459,9 +487,20 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)
// Null is the window gone: an empty desk with a window behind it is an empty tab, with none a shut app.
swarms: (swarms) => part.call('dial', () => {
cableHost.setSwarms(swarms)
+ // The Swarms the window has tabs for are read first; said again to the core only when they change.
+ const include = [...new Set((swarms?.swarms ?? []).map((s) => s.superTabId).filter((id): id is string => !!id))].slice(0, 16)
+ if (include.join(',') !== cardInclude.join(',')) { cardInclude = include; if (cardDevices > 0) tellCards() }
void cable.syncSwarms()
void cable.syncAgents()
+ // The Swarm cards link to their desk tab and follow its open project.
+ void cable.syncSwarmCards()
+ }),
+ // The Swarms' cards and a Lead's recap for the Harness Pro: the cable carries them once it speaks the frames.
+ swarmCards: (items) => part.call('dial', () => {
+ cableHost.setSwarmCards(items)
+ void cable.syncSwarmCards()
}),
+ swarmCardRecap: (recap) => part.call('dial', () => { void cable.swarmCardRecap(recap) }),
// Held rather than acted on: the dial is handed it when it attaches, the one moment its drawer is known
// to be empty.
unread: (items) => part.call('dial', () => {
diff --git a/cli/src/services/devicesProcess.spec.ts b/cli/src/services/devicesProcess.spec.ts
index 554f0be04..47f929c27 100644
--- a/cli/src/services/devicesProcess.spec.ts
+++ b/cli/src/services/devicesProcess.spec.ts
@@ -21,7 +21,7 @@ function devicesPort() {
const calls: Array<[string, unknown[]]> = []
const record = (name: string) => (...args: unknown[]) => { calls.push([name, args]) }
const port = {
- card: record('card'), desk: record('desk'), swarms: record('swarms'), unread: record('unread'), appFocus: record('appFocus'),
+ card: record('card'), desk: record('desk'), swarms: record('swarms'), swarmCards: record('swarmCards'), swarmCardRecap: record('swarmCardRecap'), unread: record('unread'), appFocus: record('appFocus'),
seen: record('seen'), settings: record('settings'), windowFocus: record('windowFocus'), windowReply: record('windowReply'),
voiceReply: record('voiceReply'), windowGone: record('windowGone'), scroll: record('scroll'), engines: record('engines'),
commanders: record('commanders'),
@@ -103,6 +103,16 @@ describe('the devices in their own process', () => {
}
})
+ it('run what the devices registered for a core that connects, each time one does', () => {
+ const f = setup()
+ const again = vi.fn()
+ f.deps().onCoreConnected!(again)
+ expect(again).not.toHaveBeenCalled()
+ f.connect()
+ f.connect()
+ expect(again).toHaveBeenCalledTimes(2)
+ })
+
it('run the devices and their link as the master starts them', () => {
runDevicesService({ dataDir: '/data', socketPath: '/sock', machineId: 'c', token: 't' })
expect(real.started).toHaveLength(1)
@@ -224,6 +234,12 @@ describe('the core\'s doors, across the link', () => {
expect(await api.account.machines()).toEqual({ status: 200, body: { data: { machines: [] } } })
f.answer('machines', { body: 'broken' })
expect(await api.account.machines()).toEqual({ status: 502, body: {} })
+ // The Swarm cards' requests, asked of the core as its own `super_tabs` query; a core that cannot answer is unavailable.
+ f.answer('super_tabs', { ok: true })
+ expect(await api.superTabRequest!({ action: 'cardsWanted', on: true })).toEqual({ ok: true })
+ expect(f.queries.at(-1)).toEqual(['super_tabs', { action: 'cardsWanted', on: true }])
+ f.answer('super_tabs', new Error('the core went away'))
+ expect(await api.superTabRequest!({ action: 'cardsWanted', on: false })).toEqual({ error: 'SERVICE_UNAVAILABLE' })
api.agents.setRuntime('a1', 'opus', 'high')
api.turns.send('a1', 'hello')
api.turns.stop('a1')
@@ -288,6 +304,10 @@ describe('what the core tells the devices, reaching their port', () => {
{ kind: 'desk', agentIds: 'nonsense' },
{ kind: 'swarms', swarms: { active: 't1', swarms: [], tiles: [] } },
{ kind: 'swarms', swarms: null },
+ { kind: 'swarmCards', items: [{ id: 't1' }] },
+ { kind: 'swarmCards', items: 'nonsense' },
+ { kind: 'swarmCardRecap', recap: { tabId: 't1' } },
+ { kind: 'swarmCardRecap', recap: 'nonsense' },
{ kind: 'unread', items: [{ agentId: 'a1' }] },
{ kind: 'unread', items: 'nonsense' },
{ kind: 'appFocus', machineId: 'm1', agentId: 'a1' },
@@ -316,6 +336,10 @@ describe('what the core tells the devices, reaching their port', () => {
['desk', [[], true]],
['swarms', [{ active: 't1', swarms: [], tiles: [] }]],
['swarms', [null]],
+ ['swarmCards', [[{ id: 't1' }]]],
+ ['swarmCards', [[]]],
+ ['swarmCardRecap', [{ tabId: 't1' }]],
+ ['swarmCardRecap', [{}]],
['unread', [[{ agentId: 'a1' }]]],
['unread', [[]]],
['appFocus', ['m1', 'a1']],
diff --git a/cli/src/services/devicesProcess.ts b/cli/src/services/devicesProcess.ts
index e16a466e4..b2924b6e1 100644
--- a/cli/src/services/devicesProcess.ts
+++ b/cli/src/services/devicesProcess.ts
@@ -17,6 +17,7 @@
*/
import { env } from '../config/env.js'
import type { AppSwarms } from '../cable/cableSession.js'
+import type { LeadRecap, SwarmCard } from '../superTabs/cards.js'
import type { RecentTurn } from '../cable/cableHost.js'
import type { UnreadNotification } from '../lib/notificationRead.js'
import { validUsage } from '../lib/agentUsageWire.js'
@@ -102,6 +103,8 @@ export function runDevicesService(options: DevicesServiceOptions): ServiceProces
viewing = asking
return asking
}
+ /** What the devices say again to a core that connects (services/devices.ts `onCoreConnected`). */
+ let coreConnected: (() => void) | undefined
const ask = async (query: string, payload: Record<string, unknown> = {}): Promise<Record<string, unknown>> => {
if (!core) throw new Error('the devices are not connected to the core')
return core.query(query, payload)
@@ -193,6 +196,8 @@ export function runDevicesService(options: DevicesServiceOptions): ServiceProces
return validUsage(usage) ? usage : null
},
daemon: DAEMON_UNKNOWN,
+ // The Swarm cards' requests to the Super Tab service, through the core (core/devicesLink.ts `super_tabs`).
+ superTabRequest: (payload) => ask('super_tabs', payload).catch((): Record<string, unknown> => ({ error: 'SERVICE_UNAVAILABLE' })),
// The Wi-Fi device beside the dials has a link of its own (services/wifiProcess.ts).
wifi: unasked.wifi,
}
@@ -205,6 +210,7 @@ export function runDevicesService(options: DevicesServiceOptions): ServiceProces
cableDisabled: env.CABLE_DISABLE,
faults: faultsOf(processEnv.HARNESSD_TEST_FAULTS),
refresh,
+ onCoreConnected: (run) => { coreConnected = run },
}
const requests = (options.start ?? startDevices)(api, ports, deps)
const port = ports.devices as DevicesPort
@@ -214,6 +220,8 @@ export function runDevicesService(options: DevicesServiceOptions): ServiceProces
card: ({ frame }) => port.card(object(frame)),
desk: ({ agentIds, foreground }) => port.desk(strings(agentIds), foreground !== false),
swarms: ({ swarms }) => port.swarms(swarms && typeof swarms === 'object' ? swarms as AppSwarms : null),
+ swarmCards: ({ items }) => port.swarmCards(Array.isArray(items) ? items as SwarmCard[] : []),
+ swarmCardRecap: ({ recap }) => port.swarmCardRecap(object(recap) as unknown as LeadRecap),
unread: ({ items }) => port.unread(Array.isArray(items) ? items as UnreadNotification[] : []),
appFocus: ({ machineId, agentId }) => port.appFocus(text(machineId), text(agentId)),
seen: ({ agentId, readToken }) => port.seen(text(agentId), typeof readToken === 'string' ? readToken : undefined),
@@ -266,6 +274,7 @@ export function runDevicesService(options: DevicesServiceOptions): ServiceProces
},
onConnected: (connection) => {
core = connection
+ coreConnected?.()
if (dialWatching) tell('dialWatching', { watching: true })
void refresh()
},
diff --git a/cli/src/services/processCoreApi.spec.ts b/cli/src/services/processCoreApi.spec.ts
index 39ea87057..c7df12e60 100644
--- a/cli/src/services/processCoreApi.spec.ts
+++ b/cli/src/services/processCoreApi.spec.ts
@@ -221,6 +221,17 @@ describe('the core API a light service runs on in its own process', () => {
expect(ask).toHaveBeenCalledWith('super_tab_attention', { items: [] })
})
+ it('tells the core the Swarm cards and recaps as two queries, never waiting on or throwing from them', async () => {
+ const ask = vi.fn(async (_query: string, _payload: Record<string, unknown>): Promise<Record<string, unknown>> => { throw new Error('gone') })
+ const doors = processCoreApi('/data', 'superTabs', { ask }).superTabs!
+ const recap = { tabId: 't1', leadId: 'l1', text: 'Shipped', at: 1, none: false }
+ doors.cards([])
+ doors.cardRecap(recap)
+ await new Promise((resolve) => setTimeout(resolve, 0))
+ expect(ask).toHaveBeenCalledWith('super_tab_cards', { items: [] })
+ expect(ask).toHaveBeenCalledWith('super_tab_card_recap', { recap })
+ })
+
it('acts on the core for an experiment: agents made, turns stopped and delivered, windows told, each asked', async () => {
const answers: Record<string, Record<string, unknown> | Error> = {
create: { ok: true, agentId: 'made' }, stop_turn: {}, windows: {}, deliver: {}, cancel_delivery: { cancelled: true },
diff --git a/cli/src/services/processCoreApi.ts b/cli/src/services/processCoreApi.ts
index fc9756216..b28317fb2 100644
--- a/cli/src/services/processCoreApi.ts
+++ b/cli/src/services/processCoreApi.ts
@@ -240,6 +240,9 @@ export function processCoreApi(dataDir: string, service: string, view: AgentsVie
// hears the next, and a new core the host's first roster (superTabs/host.ts).
superTabs: {
attention: (items) => { void ask('super_tab_attention', { items }).catch(() => {}) },
+ // The Swarm cards, whole each time they change, and one Lead's recap (core/superTabCards.ts).
+ cards: (items) => { void ask('super_tab_cards', { items }).catch(() => {}) },
+ cardRecap: (recap) => { void ask('super_tab_card_recap', { recap }).catch(() => {}) },
} satisfies SuperTabsCore,
} : {}),
}
diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.ts
new file mode 100644
index 000000000..08d982b80
--- /dev/null
+++ b/cli/src/superTabs/cards.spec.ts
@@ -0,0 +1,428 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import type { CoreApi } from '../core/api.js'
+import { fakeCore } from '../testing/fakeCore.js'
+import { lastLeadMessage, leadsOf, SwarmCards, type SwarmCard } from './cards.js'
+
+const agent = (id: string, over: Record<string, unknown> = {}) =>
+ ({ id, harnessId: `h-${id}`, machineId: 'm1', machineOwnerId: 'me', configuration: { engine: 'claude' }, ...over })
+const conv = (id: string, leadId: string | null, over: Record<string, unknown> = {}) =>
+ ({ id, projectId: id.replace(/^lead-?/, '') || 'lead', leadId, archived: false, assignment: null, lastMessageSequence: 0, ...over })
+/** A two-project Swarm: `web` (Lead a1) and `mobile` (Lead a2). */
+const swarm = (over: Record<string, unknown> = {}) => ({
+ name: 'openharness', paused: false, ownerId: 'me',
+ people: [{ id: 'me', email: '[email protected]' }, { id: 'sam', email: '[email protected]' }],
+ projects: [{ id: 'web', name: 'web', leadConversationId: 'lead-web' }, { id: 'mobile', name: 'mobile', leadConversationId: 'lead-mobile' }],
+ agents: [agent('a1'), agent('a2')],
+ conversations: [conv('lead-web', 'a1', { projectId: 'web' }), conv('lead-mobile', 'a2', { projectId: 'mobile' })],
+ ...over,
+})
+const idle = () => ({ inTurn: false })
+const work = (id: string, status: string) => conv(`w-${id}`, null, { projectId: id, assignment: { status } })
+
+describe('leadsOf', () => {
+ it('picks one Lead per project through its lead conversation, in project order', () => {
+ const { count, leads } = leadsOf(swarm(), 'm1', idle)
+ expect(count).toBe(2)
+ expect(leads.map(l => [l.id, l.projectId, l.project, l.engine, l.local, l.state])).toEqual([['a1', 'web', 'web', 'claude', 'h-a1', 'done'], ['a2', 'mobile', 'mobile', 'claude', 'h-a2', 'done']])
+ })
+
+ it('reads an old tab without projects as the one `lead` project, and skips a project with no Lead agent', () => {
+ const old = { name: 'Old', agents: [agent('a1')], people: [], conversations: [{ id: 'lead', leadId: 'a1', assignment: null }] }
+ expect(leadsOf(old, 'm1', idle).leads.map(l => [l.id, l.projectId, l.project])).toEqual([['a1', 'lead', 'Old']])
+ const headless = swarm({ conversations: [conv('lead-web', 'a1', { projectId: 'web' }), conv('lead-mobile', null, { projectId: 'mobile' })] })
+ expect(leadsOf(headless, 'm1', idle)).toMatchObject({ count: 1, leads: [{ id: 'a1' }] })
+ })
+
+ it('reads the status: ask beats stuck beats work; a local turn carries since; a remote one works on an assignment', () => {
+ const asks = swarm({ conversations: [...swarm().conversations, work('web', 'needs_human'), work('web', 'blocked')] })
+ expect(leadsOf(asks, 'm1', idle).leads[0]).toMatchObject({ id: 'a1', state: 'ask' })
+ const stuck = swarm({ conversations: [...swarm().conversations, work('web', 'working'), work('web', 'blocked')] })
+ expect(leadsOf(stuck, 'm1', idle).leads[0]).toMatchObject({ id: 'a1', state: 'stuck' })
+ const turn = leadsOf(swarm(), 'm1', h => ({ inTurn: h === 'h-a2', since: 134 })).leads
+ expect(turn[0]).toEqual(expect.objectContaining({ id: 'a2', state: 'work', since: 134 }))
+ expect(turn[1]).not.toHaveProperty('since')
+ const remote = swarm({ agents: [agent('a1', { machineId: 'm2', machineOwnerId: 'sam' }), agent('a2')], conversations: [...swarm().conversations, work('web', 'working')] })
+ const [first] = leadsOf(remote, 'm1', idle).leads
+ expect(first).toMatchObject({ id: 'a1', state: 'work', local: '' })
+ expect(first).not.toHaveProperty('since')
+ expect(leadsOf(swarm({ conversations: [...swarm().conversations, work('web', 'review')] }), 'm1', idle).leads[0].state).toBe('work')
+ })
+
+ it('calls a harness local only on this machine and live here; names an owner only when it is not the signed-in person', () => {
+ const remote = swarm({ agents: [agent('a1', { machineId: 'm2', machineOwnerId: 'sam' }), agent('a2', { machineOwnerId: 'sam' })] })
+ const byId = Object.fromEntries(leadsOf(remote, 'm1', idle, 'me').leads.map(l => [l.id, l]))
+ expect(byId.a1).toMatchObject({ local: '', owner: '[email protected]' })
+ expect(byId.a2).toMatchObject({ local: 'h-a2', owner: '[email protected]' })
+ expect(leadsOf(swarm(), 'm1', idle, 'me').leads.map(l => l.owner)).toEqual(['', ''])
+ expect(leadsOf(swarm(), 'm1', () => null).leads.map(l => l.local)).toEqual(['', ''])
+ })
+
+ it('orders ask, stuck, work, done with ties in project order, and caps at 12 Leads', () => {
+ 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 })), work('p5', 'blocked'), work('p9', 'needs_human'), work('p2', 'working'), work('p7', 'needs_human')] })
+ const { count, leads } = leadsOf(many, 'm1', idle)
+ expect(count).toBe(13)
+ expect(leads).toHaveLength(12)
+ expect(leads.slice(0, 5).map(l => [l.project, l.state])).toEqual([['P7', 'ask'], ['P9', 'ask'], ['P5', 'stuck'], ['P2', 'work'], ['P0', 'done']])
+ })
+
+ 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))
+ const paused = swarm({ paused: true, conversations: [...swarm().conversations, work('web', 'needs_human')] })
+ expect(leadsOf(paused, 'm1', () => ({ inTurn: true })).leads.map(l => l.state)).toEqual(['done', 'done'])
+ })
+})
+
+describe('lastLeadMessage', () => {
+ const row = (sequence: number, over: Record<string, unknown> = {}) => ({ sequence, text: `t${sequence}`, author: { kind: 'agent', id: 'a1' }, createdAt: '2026-10-22T00:00:00.000Z', ...over })
+ it('takes the newest row the Lead wrote, skipping system rows and other authors', () => {
+ const rows = [row(1), row(2, { source: { kind: 'native' } }), row(3, { author: { id: 'a2' } }), row(4, { text: 7 })]
+ expect(lastLeadMessage(rows, 'a1')).toEqual({ text: 't1', at: Date.parse('2026-10-22T00:00:00.000Z') / 1000 })
+ expect(lastLeadMessage([row(5), row(1)], 'a1')?.text).toBe('t5')
+ expect(lastLeadMessage([row(1, { createdAt: 1_000_500 })], 'a1')?.at).toBe(1000)
+ expect(lastLeadMessage([row(1, { createdAt: 'x' })], 'a1')?.at).toBe(0)
+ })
+ it('is null when the Lead has said nothing', () => {
+ expect(lastLeadMessage([], 'a1')).toBeNull()
+ expect(lastLeadMessage([row(1, { author: { id: 'a2' } })], 'a1')).toBeNull()
+ })
+})
+
+/** A fake backend: tabs by id with a revision, a message store per conversation, and call counting. */
+function setup(tabs: Record<string, { revision: number; state: Record<string, unknown> }>, extra: { activity?: Record<string, 'working' | 'idle'>; elapsed?: number; messages?: (path: string) => unknown } = {}) {
+ const calls: string[] = []
+ const failing = new Map<string, number>()
+ let listFails = false
+ let pages: Record<string, { next: string | null }> = {}
+ let pageSize = 0
+ const call = vi.fn(async (method: string, path: string) => {
+ calls.push(`${method} ${path}`)
+ const [route, query] = path.split('?')
+ if (route === '/api/super-tabs') {
+ if (listFails) throw new Error('offline')
+ const ids = Object.keys(tabs).sort(), after = new URLSearchParams(query).get('after')
+ const rest = ids.filter(id => !after || id > after)
+ let page = pages[after ?? '']?.next !== undefined ? rest.slice(0, 1) : rest
+ let next = pages[after ?? ''] ? pages[after ?? ''].next : null
+ if (pageSize) { page = rest.slice(0, pageSize); next = page.length < rest.length ? page[page.length - 1] : null }
+ return { status: 200, body: { success: true, data: { tabs: page.map(id => ({ id, name: String(tabs[id].state.name), ownerId: 'me', revision: tabs[id].revision, paused: false })), next } } }
+ }
+ const tab = /^\/api\/super-tabs\/([^/]+)$/.exec(route)
+ if (tab) {
+ const code = failing.get(tab[1])
+ if (code) return { status: code, body: { success: false, error: { code: 'FORBIDDEN', message: 'no' } } }
+ // The real reply of GET /api/super-tabs/:id (backend/src/superTabs/store.ts read): the state sits under `state`, beside the revision.
+ return { status: 200, body: { success: true, data: { revision: tabs[tab[1]].revision, state: tabs[tab[1]].state } } }
+ }
+ // The real messages page: { messages, next, revision }.
+ return { status: 200, body: { success: true, data: { revision: 1, ...(extra.messages?.(path) ?? { messages: [], next: null }) as object } } }
+ })
+ const core = fakeCore({
+ account: { backend: call as unknown as CoreApi['account']['backend'], identity: vi.fn(async () => ({ accountId: 'me', email: '[email protected]' })) },
+ agents: { byAgent: vi.fn((id: string) => (id.startsWith('h-') ? { agentId: id } : undefined) as never),
+ activity: vi.fn(async () => extra.activity ?? {}),
+ activitySnapshot: vi.fn(async () => ({ text: '', elapsedSeconds: extra.elapsed })) },
+ })
+ let clock = 1_000_000
+ const cards = new SwarmCards(core, 'm1', { now: () => clock, intervalMs: 5000 })
+ const seen: SwarmCard[][] = []
+ cards.onCards = c => seen.push(c)
+ return { cards, calls, seen, call, core, failing, tabs, paginate: (p: typeof pages) => { pages = p }, pageBy: (n: number) => { pageSize = n }, breakList: (v = true) => { listFails = v }, advance: (ms: number) => { clock += ms } }
+}
+const detailReads = (calls: string[]) => calls.filter(c => /^GET \/api\/super-tabs\/[^/?]+$/.test(c))
+
+afterEach(() => { vi.useRealTimers() })
+
+describe('SwarmCards.tick', () => {
+ it('lists, reads every tab once, then reads only a tab whose revision changed', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() }, t2: { revision: 4, state: swarm({ name: 'other' }) } })
+ await t.cards.tick()
+ expect(detailReads(t.calls)).toEqual(['GET /api/super-tabs/t1', 'GET /api/super-tabs/t2'])
+ expect(t.seen).toHaveLength(1)
+ expect(t.seen[0].map(c => [c.id, c.name, c.count])).toEqual([['t1', 'openharness', 2], ['t2', 'other', 2]])
+ t.calls.length = 0
+ await t.cards.tick()
+ expect(detailReads(t.calls)).toEqual([])
+ expect(t.seen).toHaveLength(1)
+ t.tabs.t2.revision = 5
+ t.tabs.t2.state = swarm({ name: 'renamed' })
+ t.calls.length = 0
+ await t.cards.tick()
+ expect(detailReads(t.calls)).toEqual(['GET /api/super-tabs/t2'])
+ expect(t.seen.at(-1)?.[1].name).toBe('renamed')
+ })
+
+ it('follows `next` through the pages of the list and keeps the first 16 tabs', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() }, t2: { revision: 1, state: swarm() } })
+ t.paginate({ '': { next: 't1' }, t1: { next: null } })
+ await t.cards.tick()
+ expect(t.calls.filter(c => c.includes('?after='))).toEqual(['GET /api/super-tabs?after=t1'])
+ const wide = Object.fromEntries(Array.from({ length: 20 }, (_, i) => [`t${String(i).padStart(2, '0')}`, { revision: 1, state: swarm() }]))
+ const w = setup(wide)
+ await w.cards.tick()
+ expect(w.seen[0]).toHaveLength(16)
+ expect(detailReads(w.calls)).toHaveLength(16)
+ })
+
+ it('drops a tab gone from the list, keeps the last cards when the list fails, and drops only a tab that answers 403', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() }, t2: { revision: 1, state: swarm({ name: 'two' }) } })
+ await t.cards.tick()
+ t.breakList()
+ await t.cards.tick()
+ expect(t.seen).toHaveLength(1)
+ t.breakList(false)
+ t.failing.set('t2', 403)
+ t.tabs.t2.revision = 2
+ await t.cards.tick()
+ expect(t.seen.at(-1)?.map(c => c.id)).toEqual(['t1'])
+ t.failing.set('t1', 401)
+ t.tabs.t1.revision = 2
+ t.failing.delete('t2')
+ await t.cards.tick()
+ expect(t.seen.at(-1)?.map(c => c.id)).toEqual(['t2'])
+ delete t.tabs.t2
+ await t.cards.tick()
+ expect(t.seen.at(-1)).toEqual([])
+ })
+
+ it('keeps a tab it already read when another failure happens on re-read', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() } })
+ await t.cards.tick()
+ t.failing.set('t1', 500)
+ t.tabs.t1.revision = 2
+ await t.cards.tick()
+ expect(t.seen).toHaveLength(1)
+ await t.cards.tick()
+ expect(t.seen).toHaveLength(1)
+ })
+
+ it('keeps a paused tab as a card with every Lead done', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm({ paused: true, conversations: [...swarm().conversations, work('web', 'needs_human')] }) } })
+ await t.cards.tick()
+ expect(t.seen[0][0].leads.map(l => l.state)).toEqual(['done', 'done'])
+ })
+
+ it('shows a local Lead in a turn as work, counting `since` from the footer timer, and re-sends only on a change other than since', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() } }, { activity: { 'h-a1': 'working' }, elapsed: 20 })
+ await t.cards.tick()
+ expect(t.seen[0][0].leads[0]).toMatchObject({ id: 'a1', state: 'work', since: 20 })
+ t.advance(5000)
+ await t.cards.tick()
+ expect(t.seen).toHaveLength(1)
+ vi.mocked(t.core.agents.activity).mockResolvedValue({})
+ await t.cards.tick()
+ expect(t.seen).toHaveLength(2)
+ expect(t.seen[1][0].leads[0].state).toBe('done')
+ })
+
+ it('names a remote Lead\'s owner using the signed-in account', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm({ agents: [agent('a1', { machineId: 'm2', machineOwnerId: 'sam' }), agent('a2')] }) } })
+ await t.cards.tick()
+ expect(t.seen[0][0].leads.find(l => l.id === 'a1')).toMatchObject({ owner: '[email protected]', local: '' })
+ })
+})
+
+describe('SwarmCards.recap', () => {
+ const msg = (sequence: number, who: string, over: Record<string, unknown> = {}) =>
+ ({ sequence, text: `m${sequence}`, author: { id: who }, createdAt: '2026-10-22T00:00:00.000Z', ...over })
+ const withSequence = (n: number) => swarm({ conversations: [conv('lead-web', 'a1', { projectId: 'web', lastMessageSequence: n }), conv('lead-mobile', 'a2', { projectId: 'mobile' })] })
+
+ it('reads the newest page, falls back one page with before, then says none', async () => {
+ const t = setup({ t1: { revision: 1, state: withSequence(9) } }, { messages: path => path.includes('before=7')
+ ? { messages: [msg(5, 'a1'), msg(6, 'a2')], next: null } : { messages: [msg(7, 'a2'), msg(8, 'a2', { source: {} })], next: 7 } })
+ await t.cards.tick()
+ const recap = await t.cards.recap('t1', 'a1')
+ expect(recap).toEqual({ tabId: 't1', leadId: 'a1', text: 'm5', at: Date.parse('2026-10-22T00:00:00.000Z') / 1000, none: false })
+ expect(t.calls.filter(c => c.includes('/messages'))).toEqual([
+ 'GET /api/super-tabs/t1/conversations/lead-web/messages', 'GET /api/super-tabs/t1/conversations/lead-web/messages?before=7'])
+ const none = setup({ t1: { revision: 1, state: withSequence(9) } }, { messages: () => ({ messages: [msg(7, 'a2')], next: 7 }) })
+ await none.cards.tick()
+ expect(await none.cards.recap('t1', 'a1')).toMatchObject({ none: true, text: '', at: 0 })
+ const empty = setup({ t1: { revision: 1, state: withSequence(0) } })
+ await empty.cards.tick()
+ expect(await empty.cards.recap('t1', 'a1')).toMatchObject({ none: true })
+ expect(empty.calls.filter(c => c.includes('/messages'))).toHaveLength(1)
+ })
+
+ it('answers again from memory while the conversation has not moved, and cuts the text at 1,500 bytes', async () => {
+ const t = setup({ t1: { revision: 1, state: withSequence(3) } }, { messages: () => ({ messages: [msg(3, 'a1', { text: `${'x'.repeat(1499)}éé` })], next: null }) })
+ await t.cards.tick()
+ const first = await t.cards.recap('t1', 'a1')
+ expect(Buffer.byteLength(first.text)).toBe(1499)
+ t.calls.length = 0
+ expect(await t.cards.recap('t1', 'a1')).toBe(first)
+ expect(t.calls).toEqual([])
+ })
+
+ it('reads the tab itself when it was not polled yet, and refuses unknown ids and Leads', async () => {
+ const t = setup({ t1: { revision: 1, state: withSequence(1) } }, { messages: () => ({ messages: [msg(1, 'a1')], next: null }) })
+ expect((await t.cards.recap('t1', 'a1')).none).toBe(false)
+ expect((await t.cards.recap('t1', 'nobody')).none).toBe(true)
+ expect((await t.cards.recap('bad id', 'a1')).none).toBe(true)
+ })
+
+ it('pushes the open Lead\'s new recap once when its conversation advanced', async () => {
+ let latest = 1
+ const t = setup({ t1: { revision: 1, state: withSequence(1) } }, { messages: () => ({ messages: [msg(latest, 'a1')], next: null }) })
+ const pushed: string[] = []
+ t.cards.onRecap = r => pushed.push(r.text)
+ await t.cards.tick()
+ t.cards.open('s1', 't1', 'a1')
+ await t.cards.tick()
+ expect(pushed).toEqual([])
+ latest = 2
+ t.tabs.t1.revision = 2
+ t.tabs.t1.state = withSequence(2)
+ await t.cards.tick()
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ t.cards.open('s1', 't1', null)
+ t.tabs.t1.revision = 3
+ t.tabs.t1.state = withSequence(3)
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ })
+})
+
+describe('SwarmCards.want', () => {
+ it('polls every interval while wanted and not at all after want(false)', async () => {
+ vi.useFakeTimers()
+ const t = setup({ t1: { revision: 1, state: swarm() } })
+ t.cards.want(true)
+ t.cards.want(true)
+ await vi.advanceTimersByTimeAsync(0)
+ const listed = () => t.calls.filter(c => c === 'GET /api/super-tabs').length
+ expect(listed()).toBe(1)
+ await vi.advanceTimersByTimeAsync(5000)
+ expect(listed()).toBe(2)
+ t.cards.want(false)
+ t.calls.length = 0
+ await vi.advanceTimersByTimeAsync(20_000)
+ expect(t.calls).toEqual([])
+ })
+})
+
+describe('SwarmCards polling cost and choice', () => {
+ const many = (n: number) => Object.fromEntries(Array.from({ length: n }, (_, i) => [`t${String(i).padStart(2, '0')}`, { revision: 1, state: swarm({ name: `S${i}` }) }]))
+
+ it('stops paging the list once 16 tabs are in hand', async () => {
+ const t = setup(many(40))
+ t.pageBy(8)
+ await t.cards.tick()
+ expect(t.calls.filter(c => c.startsWith('GET /api/super-tabs') && !c.includes('/', 'GET /api/super-tabs'.length)).length).toBe(2)
+ expect(t.seen[0]).toHaveLength(16)
+ })
+
+ it('reads the Swarms in `include` first, paging on until they are found, then the rest of the list', async () => {
+ const t = setup(many(40))
+ t.pageBy(8)
+ t.cards.want(true, ['t35', 't02'])
+ await vi.waitFor(() => expect(t.seen).toHaveLength(1))
+ expect(t.seen[0].map(c => c.id).slice(0, 4)).toEqual(['t35', 't02', 't00', 't01'])
+ expect(t.seen[0]).toHaveLength(16)
+ t.cards.want(false)
+ })
+
+ it('always reads again a tab whose list row has no numeric revision', async () => {
+ const t = setup({ t1: { revision: 1, state: swarm() } })
+ ;(t.tabs.t1 as { revision: unknown }).revision = undefined
+ await t.cards.tick()
+ t.calls.length = 0
+ await t.cards.tick()
+ expect(detailReads(t.calls)).toEqual(['GET /api/super-tabs/t1'])
+ })
+
+ it('leaves out a Swarm, a project or a harness whose id the Pro cannot hold (over 47 characters)', async () => {
+ const long = 'x'.repeat(48)
+ const t = setup({ [long]: { revision: 1, state: swarm() }, t1: { revision: 1, state: swarm({
+ projects: [{ id: long, name: 'long', leadConversationId: 'lead-web' }, { id: 'mobile', name: 'mobile', leadConversationId: 'lead-mobile' }],
+ agents: [agent('a1'), agent('a2', { harnessId: long })] }) } })
+ await t.cards.tick()
+ expect(t.seen[0].map(c => c.id)).toEqual(['t1'])
+ expect(t.seen[0][0].leads.map(l => [l.id, l.local])).toEqual([['a2', '']])
+ })
+})
+
+describe('SwarmCards open recaps and recap reads', () => {
+ const msg = (sequence: number, who: string) => ({ sequence, text: `m${sequence}`, author: { id: who }, createdAt: '2026-10-22T00:00:00.000Z' })
+ const withSequence = (n: number) => swarm({ conversations: [conv('lead-web', 'a1', { projectId: 'web', lastMessageSequence: n }), conv('lead-mobile', 'a2', { projectId: 'mobile' })] })
+
+ it('keeps the open Lead per session: one Pro closing does not stop another\'s pushes, and one push serves both', async () => {
+ let latest = 1
+ const t = setup({ t1: { revision: 1, state: withSequence(1) } }, { messages: () => ({ messages: [msg(latest, 'a1')], next: null }) })
+ const pushed: string[] = []
+ t.cards.onRecap = r => pushed.push(r.text)
+ await t.cards.tick()
+ t.cards.open('s1', 't1', 'a1')
+ t.cards.open('s2', 't1', 'a1')
+ t.cards.open('s1', 't1', null)
+ latest = 2; t.tabs.t1.revision = 2; t.tabs.t1.state = withSequence(2)
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ t.cards.open('s2', 't1', null)
+ latest = 3; t.tabs.t1.revision = 3; t.tabs.t1.state = withSequence(3)
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ })
+
+ it('does not count a push as done before the recap was read: a failed read is tried again next tick', async () => {
+ let fail = true, latest = 1
+ const t = setup({ t1: { revision: 1, state: withSequence(1) } }, { messages: path => {
+ if (fail && latest === 2) throw new Error('offline')
+ void path
+ return { messages: [msg(latest, 'a1')], next: null }
+ } })
+ const pushed: string[] = []
+ t.cards.onRecap = r => pushed.push(r.text)
+ await t.cards.tick()
+ t.cards.open('s1', 't1', 'a1')
+ latest = 2; t.tabs.t1.revision = 2; t.tabs.t1.state = withSequence(2)
+ await t.cards.tick()
+ expect(pushed).toEqual([])
+ fail = false
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ })
+
+ it('opened before the tab was read: the first read is the baseline and the next change is pushed', async () => {
+ let latest = 1
+ const t = setup({ t1: { revision: 1, state: withSequence(1) } }, { messages: () => ({ messages: [msg(latest, 'a1')], next: null }) })
+ const pushed: string[] = []
+ t.cards.onRecap = r => pushed.push(r.text)
+ t.cards.open('s1', 't1', 'a1')
+ await t.cards.tick()
+ expect(pushed).toEqual([])
+ latest = 2; t.tabs.t1.revision = 2; t.tabs.t1.state = withSequence(2)
+ await t.cards.tick()
+ expect(pushed).toEqual(['m2'])
+ })
+
+ it('has at most two recap reads in flight and refuses a third', async () => {
+ const release: Array<() => void> = []
+ const t = setup({ t1: { revision: 1, state: swarm({ conversations: [conv('lead-web', 'a1', { projectId: 'web', lastMessageSequence: 4 }), conv('lead-mobile', 'a2', { projectId: 'mobile', lastMessageSequence: 4 })],
+ agents: [agent('a1'), agent('a2'), agent('a3')] }) } }, {
+ messages: () => new Promise(resolve => { release.push(() => resolve({ messages: [msg(4, 'a1'), msg(4, 'a2')], next: null })) }) as never })
+ // The fake backend returns the promise's value as data.
+ await t.cards.tick()
+ const a = t.cards.recap('t1', 'a1'), b = t.cards.recap('t1', 'a2')
+ await vi.waitFor(() => expect(release).toHaveLength(2))
+ await expect(t.cards.recap('t1', 'a1')).rejects.toThrow()
+ release.forEach(r => r())
+ await Promise.all([a, b])
+ })
+
+ it('forgets the recap of a Lead whose tab is gone', async () => {
+ const t = setup({ t1: { revision: 1, state: withSequence(2) }, t2: { revision: 1, state: swarm() } }, { messages: () => ({ messages: [msg(2, 'a1')], next: null }) })
+ await t.cards.tick()
+ await t.cards.recap('t1', 'a1')
+ delete t.tabs.t1
+ await t.cards.tick()
+ t.calls.length = 0
+ t.tabs.t1 = { revision: 1, state: withSequence(2) }
+ await t.cards.tick()
+ await t.cards.recap('t1', 'a1')
+ expect(t.calls.filter(c => c.includes('/messages'))).toHaveLength(1)
+ })
+})
diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.ts
new file mode 100644
index 000000000..3201e880c
--- /dev/null
+++ b/cli/src/superTabs/cards.ts
@@ -0,0 +1,305 @@
+/**
+ * The Swarms a Harness Pro shows as cards on Home: for each Swarm (Super Tab) this account is in, one Lead per project with
+ * what it is doing now, plus the last thing a Lead said, for the Pro's recap. Read as the person (never as an agent) from
+ * the same backend routes the desktop uses, every 5 s while a capable Pro is attached (`want`), and a tab's detail is read
+ * only when its `revision` moved. The service hands the result to the core whole (`onCards`); the core owns the wire.
+ *
+ * Status of a project's Lead, most pressing first: `ask` (an assignment of the project needs a person, `needs_human`),
+ * `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 type { CoreApi } from '../core/api.js'
+import { backend, SuperTabHostError } from './host.js'
+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 }
+export interface SwarmCard { id: string; name: string; count: number; leads: SwarmLead[] }
+export interface LeadRecap { tabId: string; leadId: string; text: string; at: number; none: boolean }
+
+const MAX_CARDS = 16, MAX_LEADS = 12, NAME_BYTES = 48, RECAP_BYTES = 1500, MAX_LIST_PAGES = 10, MAX_RECAPS_IN_FLIGHT = 2
+/** The Pro keeps an id in 48 bytes with its NUL: 47 characters at most reach it. */
+const ID_BYTES = 47
+export const cardId = (v: unknown): v is string => identifier(v) && v.length <= ID_BYTES
+const ORDER: Record<LeadState, number> = { ask: 0, stuck: 1, work: 2, done: 3 }
+
+/** Cut on a character, never inside one: the Pro refuses a string it cannot read as UTF-8. */
+function cut(text: string, bytes: number): string {
+ let out = '', used = 0
+ for (const char of text) {
+ used += Buffer.byteLength(char)
+ if (used > bytes) break
+ out += char
+ }
+ return out
+}
+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
+ * 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).
+ */
+export function leadsOf(state: Json, machineId: string, live: (harnessId: string) => { inTurn: boolean; since?: number } | null, me?: string): { count: number; leads: SwarmLead[] } {
+ const agents = list(state.agents), conversations = list(state.conversations), people = list(state.people)
+ // An old tab has no `projects`: its one project is the tab itself, `lead`, led by the conversation `lead`.
+ const projects = Array.isArray(state.projects) ? list(state.projects) : [{ id: 'lead', name: state.name, leadConversationId: 'lead' }]
+ const paused = state.paused === true
+ const leads: SwarmLead[] = []
+ for (const project of projects) {
+ const lead = conversations.find(c => c.id === project.leadConversationId)
+ const agent = lead && agents.find(a => a.id === lead.leadId)
+ if (!agent) continue
+ if (!cardId(agent.id) || !cardId(project.id ?? 'lead')) continue
+ const harnessId = typeof agent.harnessId === 'string' ? agent.harnessId : ''
+ const here = agent.machineId === machineId && harnessId ? live(harnessId) : null
+ const waits = new Set(conversations.filter(c => (c.projectId ?? 'lead') === (project.id ?? 'lead') && c.archived !== true)
+ .map(c => object(c.assignment).status))
+ let state: LeadState = 'done', since: number | undefined
+ if (!paused) {
+ if (waits.has('needs_human')) state = 'ask'
+ else if (waits.has('blocked')) state = 'stuck'
+ else if (here?.inTurn) { state = 'work'; since = here.since }
+ else if (waits.has('working') || waits.has('review')) state = 'work'
+ }
+ const ownerId = agent.machineOwnerId
+ const owner = me && typeof ownerId === 'string' && ownerId !== me ? people.find(p => p.id === ownerId) : undefined
+ leads.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 } : {}),
+ })
+ }
+ // Array.sort is stable: equal urgency keeps the project order.
+ const ordered = leads.map((l, i) => ({ l, i })).sort((a, b) => ORDER[a.l.state] - ORDER[b.l.state] || a.i - b.i).map(x => x.l)
+ return { count: ordered.length, leads: ordered.slice(0, MAX_LEADS) }
+}
+
+/** The newest row the Lead itself wrote: a person-visible message, not a system row (`source`) or someone else's. `at` in seconds. */
+export function lastLeadMessage(messages: Json[], leadId: string): { text: string; at: number } | null {
+ let best: { text: string; at: number; sequence: number } | null = null
+ for (const item of messages) {
+ const m = object(item)
+ if (m.source != null || object(m.author).id !== leadId || typeof m.text !== 'string') continue
+ const sequence = typeof m.sequence === 'number' ? m.sequence : -1
+ if (best && sequence <= best.sequence) continue
+ const stamp = typeof m.createdAt === 'number' ? m.createdAt : Date.parse(String(m.createdAt))
+ best = { text: m.text, at: Number.isFinite(stamp) ? Math.floor(stamp / 1000) : 0, sequence }
+ }
+ return best && { text: best.text, at: best.at }
+}
+
+interface TabCache { revision: number; state: Json }
+interface Cached { sequence: number; recap: LeadRecap }
+/** A Lead some Harness Pro has the recap of open, and the sessions (one per Pro) that have it open. */
+interface Opened { tabId: string; leadId: string; sequence: number | null; sessions: Set<string> }
+/** What GET /api/super-tabs/:id answers: `{ revision, state }`. A reply without a numeric revision is never reused (-1). */
+const tabOf = (answer: unknown): TabCache => {
+ const reply = object(answer)
+ return { revision: typeof reply.revision === 'number' ? reply.revision : -1, state: object(reply.state) }
+}
+
+export class SwarmCards {
+ onCards?: (cards: SwarmCard[]) => void
+ onRecap?: (recap: LeadRecap) => void
+ private readonly now: () => number
+ private readonly intervalMs: number
+ private timer: NodeJS.Timeout | undefined
+ private busy = false
+ private tabs = new Map<string, TabCache>()
+ private recaps = new Map<string, Cached>()
+ /** When each local Lead's current turn began, so `since` counts on between polls. */
+ private turns = new Map<string, number>()
+ private last: string | null = null
+ private me: string | undefined
+ private include: string[] = []
+ private opened = new Map<string, Opened>()
+ private openBy = new Map<string, string>()
+ private recapsRunning = 0
+
+ constructor(private readonly core: CoreApi, private readonly machineId: string, options: { now?: () => number; intervalMs?: number } = {}) {
+ this.now = options.now ?? Date.now
+ this.intervalMs = options.intervalMs ?? 5000
+ }
+
+ /** Poll while a capable Pro is attached; none otherwise (no request at all). `include`: the Swarms the desktop has tabs for, read first. */
+ want(on: boolean, include: string[] = []): void {
+ if (!on) {
+ if (this.timer) clearInterval(this.timer)
+ this.timer = undefined
+ this.opened.clear(); this.openBy.clear(); this.include = []
+ return
+ }
+ const wanted = include.filter(cardId).slice(0, MAX_CARDS)
+ const moved = wanted.join(',') !== this.include.join(',')
+ this.include = wanted
+ if (this.timer) { if (moved) void this.tick(); return }
+ this.timer = setInterval(() => { void this.tick() }, this.intervalMs)
+ this.timer.unref?.()
+ void this.tick()
+ }
+
+ /** The recap on a Pro's screen (leadId null: closed), per Pro `session`: a change in that Lead's conversation is pushed once. */
+ open(session: string, tabId: string, leadId: string | null): void {
+ const before = this.openBy.get(session)
+ if (before) {
+ const held = this.opened.get(before)
+ held?.sessions.delete(session)
+ if (held && !held.sessions.size) this.opened.delete(before)
+ this.openBy.delete(session)
+ }
+ if (!leadId || !cardId(session) || !cardId(tabId) || !cardId(leadId)) return
+ const key = `${tabId}:${leadId}`
+ let entry = this.opened.get(key)
+ if (!entry) {
+ // From what the Pro was shown when there is a recap read, else from the first read of the tab: the next change is pushed.
+ entry = { tabId, leadId, sequence: this.recaps.get(key)?.sequence ?? this.sequenceOf(tabId, leadId), sessions: new Set() }
+ this.opened.set(key, entry)
+ }
+ entry.sessions.add(session)
+ this.openBy.set(session, key)
+ }
+
+ async tick(): Promise<void> {
+ if (this.busy) return
+ this.busy = true
+ try { await this.poll() } catch { /* the last cards stay: a dropped network says nothing about the Swarms */ } finally { this.busy = false }
+ }
+
+ /** The Swarms to show: those the desktop has tabs for first, then the list in its order, 16 in all. Paging stops once both are met. */
+ private async listTabs(): Promise<Json[]> {
+ const rows: Json[] = []
+ let after = ''
+ for (let page = 0; page < MAX_LIST_PAGES; page++) {
+ const data = object(await backend(this.core, 'GET', `/api/super-tabs${after ? `?after=${encodeURIComponent(after)}` : ''}`))
+ rows.push(...list(data.tabs).filter(r => cardId(r.id)))
+ if (!identifier(data.next)) break
+ if (rows.length >= MAX_CARDS && this.include.every(id => rows.some(r => r.id === id))) break
+ after = data.next
+ }
+ const first = this.include.map(id => rows.find(r => r.id === id)).filter((r): r is Json => !!r)
+ return [...first, ...rows.filter(r => !first.includes(r))].slice(0, MAX_CARDS)
+ }
+
+ private async poll(): Promise<void> {
+ const rows = await this.listTabs()
+ const known = new Map<string, TabCache>()
+ await Promise.all(rows.map(async row => {
+ const id = row.id as string, held = this.tabs.get(id)
+ // A row without a numeric revision cannot say it is unchanged: that tab is always read again.
+ if (held && typeof row.revision === 'number' && held.revision === row.revision) { known.set(id, held); return }
+ try { known.set(id, tabOf(await backend(this.core, 'GET', `/api/super-tabs/${id}`))) } catch (error) {
+ // Lost access drops only this card; any other failure keeps what was read before.
+ const status = error instanceof SuperTabHostError ? error.status : 0
+ if (held && status !== 401 && status !== 403) known.set(id, held)
+ }
+ }))
+ this.tabs = known
+ const me = (await this.core.account.identity().catch(() => null))?.accountId
+ // Another person signed in: nothing of the last account's is kept, and the list is said again whatever it is.
+ if (this.me !== undefined && me !== this.me) { this.last = null; this.recaps.clear() }
+ this.me = me ?? this.me
+ const turns = await this.turnsHere()
+ const live = (harnessId: string) => this.core.agents.byAgent(harnessId) ? turns.get(harnessId) ?? { inTurn: false } : null
+ const cards: SwarmCard[] = []
+ for (const row of rows) {
+ const tab = known.get(row.id as string)
+ if (!tab) continue
+ const { count, leads } = leadsOf(tab.state, this.machineId, live, me)
+ cards.push({ id: row.id as string, name: cut(String(tab.state.name ?? row.name ?? ''), NAME_BYTES), count, leads })
+ }
+ // `since` moves every poll while a turn runs and the Pro counts on by itself, so it alone never re-sends the list.
+ const signature = JSON.stringify(cards, (key, value) => key === 'since' ? value !== undefined : value)
+ if (signature !== this.last) { this.last = signature; this.onCards?.(cards) }
+ this.prune()
+ await this.pushOpen()
+ }
+
+ /** Which of the Leads that run here are in a turn, and since when (the core's windows' own measure of "working"). */
+ private async turnsHere(): Promise<Map<string, { inTurn: boolean; since?: number }>> {
+ const ids = new Set<string>()
+ for (const { state } of this.tabs.values()) {
+ for (const agent of list(state.agents)) if (agent.machineId === this.machineId && typeof agent.harnessId === 'string' && this.core.agents.byAgent(agent.harnessId)) ids.add(agent.harnessId)
+ }
+ const working = ids.size ? await this.core.agents.activity([...ids]).catch(() => ({} as Record<string, string>)) : {}
+ const out = new Map<string, { inTurn: boolean; since?: number }>()
+ const now = this.now()
+ for (const id of ids) {
+ if (working[id] !== 'working') { this.turns.delete(id); out.set(id, { inTurn: false }); continue }
+ if (!this.turns.has(id)) {
+ const elapsed = (await this.core.agents.activitySnapshot?.(id).catch(() => null))?.elapsedSeconds
+ this.turns.set(id, now - (typeof elapsed === 'number' && elapsed > 0 ? elapsed * 1000 : 0))
+ }
+ out.set(id, { inTurn: true, since: Math.max(0, Math.floor((now - this.turns.get(id)!) / 1000)) })
+ }
+ for (const id of [...this.turns.keys()]) if (!ids.has(id)) this.turns.delete(id)
+ return out
+ }
+
+ /** The Lead's conversation and how far it has gone, from the tab as last read. */
+ private leadConversation(tabId: string, leadId: string): { id: string; sequence: number } | null {
+ const state = this.tabs.get(tabId)?.state
+ if (!state) return null
+ const conversations = list(state.conversations)
+ const projects = Array.isArray(state.projects) ? list(state.projects) : [{ leadConversationId: 'lead' }]
+ for (const project of projects) {
+ const lead = conversations.find(c => c.id === project.leadConversationId)
+ if (lead && lead.leadId === leadId && identifier(lead.id)) return { id: lead.id, sequence: typeof lead.lastMessageSequence === 'number' ? lead.lastMessageSequence : 0 }
+ }
+ return null
+ }
+ private sequenceOf(tabId: string, leadId: string): number | null { return this.leadConversation(tabId, leadId)?.sequence ?? null }
+
+ /** What the Lead last said: the newest page of its conversation, then one page back; `none` when neither holds a row of its own. */
+ async recap(tabId: string, leadId: string): Promise<LeadRecap> {
+ if (!cardId(tabId) || !cardId(leadId)) return { tabId, leadId, text: '', at: 0, none: true }
+ let found = this.leadConversation(tabId, leadId)
+ if (!found) {
+ if (this.recapsRunning >= MAX_RECAPS_IN_FLIGHT) throw new Error('too many recap reads at once')
+ this.recapsRunning++
+ try { this.tabs.set(tabId, tabOf(await backend(this.core, 'GET', `/api/super-tabs/${tabId}`))) } finally { this.recapsRunning-- }
+ found = this.leadConversation(tabId, leadId)
+ }
+ if (!found) return { tabId, leadId, text: '', at: 0, none: true }
+ const key = `${tabId}:${leadId}`, held = this.recaps.get(key)
+ if (held && held.sequence === found.sequence) return held.recap
+ // At most two backend reads of recaps run at once: a Pro that asks in a loop cannot flood the backend.
+ if (this.recapsRunning >= MAX_RECAPS_IN_FLIGHT) throw new Error('too many recap reads at once')
+ this.recapsRunning++
+ try {
+ const path = `/api/super-tabs/${tabId}/conversations/${found.id}/messages`
+ let page = list(object(await backend(this.core, 'GET', path)).messages)
+ let said = lastLeadMessage(page, leadId)
+ if (!said && page.length) {
+ const oldest = Math.min(...page.map(m => typeof m.sequence === 'number' ? m.sequence : Infinity))
+ if (Number.isFinite(oldest)) {
+ page = list(object(await backend(this.core, 'GET', `${path}?before=${oldest}`)).messages)
+ said = lastLeadMessage(page, leadId)
+ }
+ }
+ const recap: LeadRecap = said ? { tabId, leadId, text: cut(said.text, RECAP_BYTES), at: said.at, none: false } : { tabId, leadId, text: '', at: 0, none: true }
+ this.recaps.set(key, { sequence: found.sequence, recap })
+ return recap
+ } finally { this.recapsRunning-- }
+ }
+
+ /** 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)
+ }
+
+ /** Each open Lead that moved on since its Pro last got the recap: the new one is sent once. A failed read is tried again next tick. */
+ private async pushOpen(): Promise<void> {
+ for (const open of [...this.opened.values()]) {
+ const sequence = this.sequenceOf(open.tabId, open.leadId)
+ if (sequence === null) continue
+ if (open.sequence === null) { open.sequence = sequence; continue }
+ if (open.sequence === sequence) continue
+ const recap = await this.recap(open.tabId, open.leadId).catch(() => null)
+ if (!recap) continue
+ open.sequence = sequence
+ this.onRecap?.(recap)
+ }
+ }
+}
diff --git a/cli/src/superTabs/host.spec.ts b/cli/src/superTabs/host.spec.ts
index 0c10a8a54..eab3ce573 100644
--- a/cli/src/superTabs/host.spec.ts
+++ b/cli/src/superTabs/host.spec.ts
@@ -470,7 +470,7 @@ describe('Super Tab waits for the Harness Pro', () => {
if (offline) throw new Error('Host offline')
return { status: 200, body: { success: true, data: path.includes('/hosts/') ? rows : [] } }
})
- const superTabs = { attention: vi.fn() }
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
const core = fakeCore({ dataDir: dir, superTabs, account: { backend: call },
agents: { creationStatus: vi.fn(async creationId => ({ creationId, state: 'created' as const, agentId: 'harness' })), byAgent: vi.fn(() => ({ agentId: 'harness' }) as never), terminalAvailable: vi.fn(() => true) } })
const open = () => { const host = new SuperTabHost(core, 'machine-1', { log: vi.fn() }); hosts.push(host); return host }
@@ -507,7 +507,7 @@ describe('Super Tab waits for the Harness Pro', () => {
agent: { id: 'agent', harnessId: 'harness', machineId: 'machine-1' } }]
const call: CoreApi['account']['backend'] = vi.fn(async (_method, path) => ({ status: 200, body: { success: true, data: path.includes('/hosts/') ? rows : [] } }))
let here = true, clock = 0
- const superTabs = { attention: vi.fn() }
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
const core = fakeCore({ dataDir: dir, superTabs, account: { backend: call },
agents: { byAgent: vi.fn(() => (here ? { agentId: 'harness' } : undefined) as never), terminalAvailable: vi.fn(() => true) } })
const host = new SuperTabHost(core, 'machine-1', { log: vi.fn(), now: () => clock }); hosts.push(host)
diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.ts
index f039fafec..0466cbd90 100644
--- a/cli/src/superTabs/service.spec.ts
+++ b/cli/src/superTabs/service.spec.ts
@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from 'vitest'
import { fakeCore } from '../testing/fakeCore.js'
import type { CoreApi } from '../core/api.js'
import { superTabService } from './service.js'
-import type { SuperTabHost } from './host.js'
+import { SuperTabHostError, type SuperTabHost } from './host.js'
import { createJevDecide, type JevDecide } from '../lib/jev/jevClient.js'
// The real client would read the developer's OpenRouter key; the account backend is the only part under test.
@@ -544,3 +544,70 @@ it('documents finished worker decisions and explains an older backend without re
const reply = await t.ask({ action: 'command', tabId: 'tab', agentId: t.agentId, operationId: 'release', command: { type: 'agent.release', agentId: 'worker', decision: 'stop' } }, owner)
expect(reply).toMatchObject({ detail: 'This backend does not support releasing workers yet. Update the backend and try again.' })
})
+
+describe('the Swarm cards the devices ask for', () => {
+ function withCards() {
+ const cards = { want: vi.fn(), open: vi.fn(), recap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'Shipped', at: 5, none: false })), onCards: undefined as unknown, onRecap: undefined as unknown }
+ const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }
+ const core = fakeCore({ superTabs })
+ const make = vi.fn(() => cards as never)
+ const service = superTabService(core, { cards: make })
+ return { cards, superTabs, make, core, ask: service.requests.super_tabs, port: service.port }
+ }
+ it('starts and stops the reader as a capable Pro comes and goes, and hands what it reads to the core', async () => {
+ const t = withCards()
+ expect(await t.ask({ action: 'cardsWanted', on: true }, owner)).toEqual({ ok: true })
+ expect(t.cards.want).toHaveBeenLastCalledWith(true, [])
+ expect(await t.ask({ action: 'cardsWanted', on: true, include: ['s1', 'bad id', 'x'.repeat(48), 7] }, owner)).toEqual({ ok: true })
+ expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'])
+ expect(await t.ask({ action: 'cardsWanted', on: false }, owner)).toEqual({ ok: true })
+ expect(t.cards.want).toHaveBeenLastCalledWith(false, [])
+ // One reader for the machine, whose answers go to the core.
+ expect(t.make).toHaveBeenCalledOnce()
+ ;(t.cards.onCards as (items: unknown[]) => void)([])
+ ;(t.cards.onRecap as (recap: unknown) => void)({ tabId: 't1' })
+ expect(t.superTabs.cards).toHaveBeenCalledWith([])
+ expect(t.superTabs.cardRecap).toHaveBeenCalledWith({ tabId: 't1' })
+ // The service going away stops the polling; the next ask makes a new reader.
+ t.port.stop()
+ expect(t.cards.want).toHaveBeenLastCalledWith(false)
+ await t.ask({ action: 'cardsWanted', on: true }, owner)
+ expect(t.make).toHaveBeenCalledTimes(2)
+ // A different machine id (the daemon was set up again) is a different reader, and the old one stops.
+ vi.spyOn(t.core.daemon, 'machineId').mockReturnValue('machine-2')
+ await t.ask({ action: 'cardsWanted', on: true }, owner)
+ expect(t.make).toHaveBeenCalledTimes(3)
+ })
+ it('reads one Lead\'s recap and notes which one the Pro has open', async () => {
+ const t = withCards()
+ expect(await t.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1' }, owner)).toEqual({ ok: true, tabId: 't1', leadId: 'l1', text: 'Shipped', at: 5, none: false })
+ expect(await t.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'l1' }, owner)).toEqual({ ok: true })
+ expect(t.cards.open).toHaveBeenLastCalledWith('s1', 't1', 'l1')
+ expect(await t.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null }, owner)).toEqual({ ok: true })
+ expect(t.cards.open).toHaveBeenLastCalledWith('s1', 't1', null)
+ for (const bad of [{ action: 'cardRecap', tabId: 'bad id', leadId: 'l1' }, { action: 'cardRecap', tabId: 't1' }, { action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'bad id' }, { action: 'cardOpen', session: 's1', leadId: null },
+ { action: 'cardOpen', tabId: 't1', leadId: null }, { action: 'cardRecap', tabId: 'x'.repeat(48), leadId: 'l1' }]) {
+ expect(await t.ask(bad, owner)).toEqual({ error: 'INVALID_REQUEST' })
+ }
+ })
+ it('answers a backend refusal while reading a recap as the service does any other', async () => {
+ const t = withCards()
+ t.cards.recap.mockRejectedValueOnce(new SuperTabHostError('FORBIDDEN', 'Access withdrawn', 403))
+ expect(await t.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1' }, owner)).toEqual({ error: 'FORBIDDEN', detail: 'Access withdrawn', status: 403 })
+ })
+ it('refuses all three to anyone but the machine\'s owner, like the other actions', async () => {
+ const t = withCards()
+ for (const action of ['cardsWanted', 'cardRecap', 'cardOpen']) {
+ expect(await t.ask({ action, on: true, tabId: 't1', leadId: 'l1' }, visitor)).toEqual({ error: 'OWNER_REQUIRED' })
+ expect(await t.ask({ action, on: true, tabId: 't1', leadId: 'l1' }, { local: false, owner: true })).toEqual({ error: 'OWNER_REQUIRED' })
+ }
+ expect(t.make).not.toHaveBeenCalled()
+ })
+ it('refuses all three to an account owner who is not at this computer', async () => {
+ const t = withCards()
+ for (const action of ['cardsWanted', 'cardRecap', 'cardOpen']) {
+ expect(await t.ask({ action, on: true, session: 's1', tabId: 't1', leadId: 'l1' }, { local: false, owner: true, accountOwner: true } as never)).toEqual({ error: 'OWNER_REQUIRED' })
+ }
+ expect(t.make).not.toHaveBeenCalled()
+ })
+})
diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.ts
index 719c7c9ff..38c7c2d57 100644
--- a/cli/src/superTabs/service.ts
+++ b/cli/src/superTabs/service.ts
@@ -10,6 +10,7 @@ import { START_REQUIREMENTS } from './capacity.js'
import { CapacityReservations, type ReservationBook } from './reservations.js'
import { ContributionPreparations, prepareContribution } from './contribution.js'
import { messageIdOf } from './attach.js'
+import { cardId, SwarmCards } from './cards.js'
const HELP = {
status: 'Read the shared tab roster and work.',
@@ -84,6 +85,8 @@ export interface SuperTabServiceOptions {
reservations?: (core: CoreApi, machineId: string) => ReservationBook
/** Jev for `route`; Harness's hosted key through the backend when the person has no key of their own. */
jev?: (core: CoreApi) => JevDecide
+ /** The Swarm cards' reader (superTabs/cards.ts), for a spec. */
+ cards?: (core: CoreApi, machineId: string) => SwarmCards
}
export function superTabService(core: CoreApi, options: SuperTabServiceOptions = {}): { requests: ServiceRequests; port: SuperTabsPort } {
const preparations = new ContributionPreparations(input => (options.prepareContribution ?? prepareContribution)(core, input))
@@ -102,7 +105,19 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =
host.start()
return host
}
- const disconnect = () => { preparations.clear(); host?.stop(); host = null; book?.stop(); book = null; bookMachine = null }
+ // The Swarm cards for a Harness Pro (superTabs/cards.ts), read while a device that shows them is attached and told to the core.
+ let swarmCards: SwarmCards | null = null, cardsMachine: string | null = null
+ const cards = () => {
+ const machine = core.daemon.machineId()
+ if (cardsMachine !== machine) { swarmCards?.want(false); swarmCards = null; cardsMachine = machine }
+ if (!swarmCards) {
+ swarmCards = (options.cards ?? ((api, id) => new SwarmCards(api, id)))(core, machine)
+ swarmCards.onCards = items => core.superTabs?.cards(items)
+ swarmCards.onRecap = recap => core.superTabs?.cardRecap(recap)
+ }
+ return swarmCards
+ }
+ const disconnect = () => { preparations.clear(); host?.stop(); host = null; book?.stop(); book = null; bookMachine = null; swarmCards?.want(false); swarmCards = null; cardsMachine = null }
const port = {
connected: () => {
if (identifier(core.daemon.machineId()) && existsSync(hostJournalFile(core.dataDir, core.daemon.machineId()))) wake()
@@ -130,6 +145,23 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =
if (!asker.owner || (!asker.local && asker.accountOwner !== true)) return { error: 'OWNER_REQUIRED' }
if (payload.action === 'swarmRole') return { ok: true, role: await port.swarmRole(String(payload.harnessId ?? '')) }
if (payload.action === 'prepareContribution') return preparations.read(payload)
+ // 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 (!asker.local) return { error: 'OWNER_REQUIRED' }
+ if (payload.action === 'cardsWanted') {
+ const include = Array.isArray(payload.include) ? payload.include.filter(cardId) : []
+ cards().want(payload.on === true, include)
+ 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 === 'cardOpen' && cardId(payload.session) && cardId(payload.tabId) && (payload.leadId === null || cardId(payload.leadId))) {
+ cards().open(payload.session, payload.tabId, payload.leadId)
+ return { ok: true }
+ }
+ return { error: 'INVALID_REQUEST' }
+ }
if (payload.action === 'backend') {
const { method, path } = payload
if (!['GET', 'POST'].includes(String(method)) || typeof path !== 'string'
diff --git a/cli/src/testing/fakeCore.ts b/cli/src/testing/fakeCore.ts
index a8af38339..43cac6f63 100644
--- a/cli/src/testing/fakeCore.ts
+++ b/cli/src/testing/fakeCore.ts
@@ -94,6 +94,6 @@ export function fakeCore(over: Overrides = {}): CoreApi {
// Only a spec that gives the cloud agents doors has them, as only a core that offers them does.
...(over.cloud ? { cloud: Object.assign({ publish: vi.fn(), ask: vi.fn(), unask: vi.fn() }, over.cloud) } : {}),
// The Super Tab service's door, likewise.
- ...(over.superTabs ? { superTabs: Object.assign({ attention: vi.fn() }, over.superTabs) } : {}),
+ ...(over.superTabs ? { superTabs: Object.assign({ attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn() }, over.superTabs) } : {}),
}
}
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 819fe36f4..0822abec3 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -1746,6 +1746,12 @@ class AppNotifier extends ChangeNotifier {
// The closed list is read from these names, so it can change on its own.
if (changed || namesChanged) notifyListeners();
},
+ onSelection: (controller) {
+ if (_disposed || controller.accountId != currentUser?.id) return;
+ // The Harness Pro shows the open project's Leads, so a project change
+ // is a change to the desk it was told about.
+ _announceOpenPanesToDial();
+ },
onSnapshot: (controller) {
if (_disposed || controller.accountId != currentUser?.id) return;
var shown = false;
@@ -3927,6 +3933,48 @@ class AppNotifier extends ChangeNotifier {
}
}
+ Future<void> _openSuperTabProject(
+ MachineState source,
+ String tabId,
+ String projectId,
+ ) async {
+ final open = swarms.where((s) => s.superTabId == tabId).firstOrNull;
+ final name = open?.name ?? _superTabNames[tabId];
+ // A tab this account does not belong to is nobody's to open.
+ if (name == null) return;
+ _requestDeviceWindow(source);
+ // Every announce until the project lands says the device caused it: the
+ // open and the refresh can take longer than the daemon's echo window, and
+ // an announce naming the tab's old project would pull the device off the
+ // Lead it just picked.
+ final pick = ++_devicePick;
+ _announceFromDevice = true;
+ final abandon = Timer(const Duration(seconds: 5), () {
+ if (_devicePick == pick) _announceFromDevice = false;
+ });
+ try {
+ _fromDevice(
+ () => open == null ? openSuperTab(tabId, name) : selectSwarm(open.id),
+ );
+ final controller = await superTabs.open(tabId);
+ if (_disposed || _devicePick != pick || !_announceFromDevice) return;
+ if (controller.snapshot == null) await controller.refresh();
+ if (_disposed || _devicePick != pick || !_announceFromDevice) return;
+ final project = controller.snapshot?.projects
+ .where((p) => p.id == projectId)
+ .firstOrNull;
+ if (project == null) return;
+ controller.select(project.leadConversationId);
+ // Selecting what is already selected announces nothing by itself.
+ _announceOpenPanesToDial();
+ } catch (error) {
+ appLog.warn('super-tab', 'Could not open the picked project: $error');
+ } finally {
+ abandon.cancel();
+ if (_devicePick == pick) _announceFromDevice = false;
+ }
+ }
+
void _noteNavigation() {
_paneFocusByUser = !_navigatingFromDevice;
// A device's move is not a person opening anything — but it does leave a
@@ -5081,6 +5129,9 @@ class AppNotifier extends ChangeNotifier {
/// unchanged and the `foreground` flag riding with it is the point.
void announceWindowForeground() => _announceOpenPanesToDial();
+ bool _announceFromDevice = false;
+ int _devicePick = 0;
+
/// The tile roster and the tabs, to every daemon this window reaches over
/// its loopback ([_deskConnection]) — never a relayed machine's.
void _announceOpenPanesToDial() {
@@ -5136,11 +5187,22 @@ class AppNotifier extends ChangeNotifier {
];
// The swarms travel with the tiles: the dial names the one on screen above the agent and offers
// the others, and a pick there comes back as `dial_swarm`.
+ final fromDevice = _announceFromDevice;
final swarmRows = [
for (final swarm in swarms)
{
'id': swarm.id,
'name': swarm.name,
+ // The backend tab and the project open in it, for a device that
+ // draws the Swarm's Leads and asks for one by these ids. Left out
+ // while the tab has not loaded: a project is not guessed.
+ if (swarm.superTabId case final tabId?) ...{
+ 'superTabId': tabId,
+ if (superTabs.peek(tabId) case final controller?)
+ if (controller.snapshot?.projectFor(controller.selectedId)
+ case final project?)
+ 'projectId': project.id,
+ },
'agentIds': [
for (final pane in swarm.panes)
if (onDial(pane)) pane.agentId!,
@@ -5186,6 +5248,9 @@ class AppNotifier extends ChangeNotifier {
.sendTerminalFrame('app_swarms', {
'active': activeSwarmId,
'swarms': swarmRows,
+ // Set on the announces a device's pick caused, so the daemon
+ // does not send the pick back to the device as a new focus.
+ if (fromDevice) 'fromDevice': true,
// Only the active one's. It is the only grid the device draws, and sending every tab's
// geometry would be two dozen shapes to carry one.
'tiles': activeTiles,
@@ -20142,6 +20207,15 @@ class AppNotifier extends ChangeNotifier {
_fromDevice(() => selectSwarm(swarmId));
}
break;
+ case 'dial_super_tab':
+ // The Harness Pro picked a Lead's project. Show that Swarm, then the
+ // project's Lead chat as a click on its row in the sidebar does.
+ final tabId = payload['superTabId'];
+ final projectId = payload['projectId'];
+ if (tabId is String && projectId is String) {
+ await _openSuperTabProject(machine, tabId, projectId);
+ }
+ break;
case 'dial_forked':
// The dial forked an agent; the daemon already opened the pane on its
// machine. Land it beside its source and focus it, as the window's own
diff --git a/desktop/lib/super_tabs/client.dart b/desktop/lib/super_tabs/client.dart
index 689698616..fb26465e4 100644
--- a/desktop/lib/super_tabs/client.dart
+++ b/desktop/lib/super_tabs/client.dart
@@ -22,6 +22,7 @@ class SuperTabClient {
required this.storage,
this.onSnapshot,
this.onTabs,
+ this.onSelection,
this.upload = refuseUpload,
this.discoveryInterval = const Duration(seconds: 15),
});
@@ -29,6 +30,9 @@ class SuperTabClient {
final LocalKeyValueStore storage;
final void Function(SuperTabController)? onSnapshot;
final void Function(List<SuperTabListing>, Set<String> hidden)? onTabs;
+
+ /// A tab's selected conversation changed, by a click here or by a device.
+ final void Function(SuperTabController)? onSelection;
final SuperTabUpload upload;
final Duration discoveryInterval;
String? _account;
@@ -244,7 +248,12 @@ class SuperTabClient {
upload: upload,
);
var seenRevision = -1;
+ var seenSelected = controller.selectedId;
controller.addListener(() {
+ if (controller.selectedId != seenSelected) {
+ seenSelected = controller.selectedId;
+ onSelection?.call(controller);
+ }
if (controller.snapshot != null && controller.revision != seenRevision) {
seenRevision = controller.revision;
onSnapshot?.call(controller);
diff --git a/desktop/test/super_tab_dial_test.dart b/desktop/test/super_tab_dial_test.dart
new file mode 100644
index 000000000..20a6a2fb1
--- /dev/null
+++ b/desktop/test/super_tab_dial_test.dart
@@ -0,0 +1,195 @@
+import 'dart:async';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/super_tabs/controller.dart';
+
+import 'support/super_tab_fixture.dart';
+import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ Future<(SuperTabLaunchFixture, SuperTabController)> open() async {
+ final f = SuperTabLaunchFixture(local: true);
+ final server = f.connection.server;
+ server.state['projects'] = [
+ projectFixture('lead', 'Lamp OS', 'lead'),
+ projectFixture('design', 'Design', 'design-lead'),
+ ];
+ (server.state['conversations'] as List).add({
+ ...conversationFixture('design-lead', 'Lead'),
+ 'projectId': 'design',
+ });
+ f.app.adoptPoolConnectionForTest('m', f.connection);
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ return (f, c);
+ }
+
+ Future<void> settle() => Future<void>.delayed(Duration.zero);
+
+ List<Map<String, dynamic>> announces(SuperTabLaunchFixture f) => [
+ for (final call in f.connection.terminalCalls)
+ if (call.$1 == 'app_swarms') call.$2,
+ ];
+
+ Map<String, dynamic> row(Map<String, dynamic> announce) =>
+ (announce['swarms'] as List).cast<Map<String, dynamic>>().singleWhere(
+ (s) => s['superTabId'] == tabId,
+ );
+
+ Future<void> pick(SuperTabLaunchFixture f, String tab, String project) =>
+ f.app.handleEventForTest('m', {
+ 'type': 'dial_super_tab',
+ 'payload': {'superTabId': tab, 'projectId': project},
+ });
+
+ test('a Swarm row carries its tab and the selected project', () async {
+ final (f, c) = await open();
+ f.app.announceWindowForeground();
+ await settle();
+ expect(row(announces(f).last)['projectId'], 'lead');
+ expect(announces(f).last.containsKey('fromDevice'), isFalse);
+ c.select('design-lead');
+ await settle();
+ expect(row(announces(f).last)['projectId'], 'design');
+ });
+
+ test('a draft tab has no tab id', () async {
+ final (f, _) = await open();
+ f.app.newSwarm(newTabPage: true);
+ f.app.announceWindowForeground();
+ await settle();
+ final rows = (announces(f).last['swarms'] as List).cast<Map>();
+ expect(rows.where((r) => r.containsKey('superTabId')), hasLength(1));
+ });
+
+ test('a pick for an open Swarm focuses it and opens the Lead chat', () async {
+ final (f, c) = await open();
+ final tab = f.app.activeSwarmId;
+ f.app.newSwarm(newTabPage: true);
+ expect(f.app.activeSwarmId, isNot(tab));
+ final before = announces(f).length;
+ await pick(f, tabId, 'design');
+ await settle();
+ expect(f.app.activeSwarmId, tab);
+ expect(c.selectedId, 'design-lead');
+ final after = announces(f).skip(before).toList();
+ expect(after, isNotEmpty);
+ expect(after.every((a) => a['fromDevice'] == true), isTrue);
+ expect(row(after.last)['projectId'], 'design');
+ f.app.announceWindowForeground();
+ await settle();
+ expect(announces(f).last.containsKey('fromDevice'), isFalse);
+ });
+
+ test('a pick for a closed Swarm opens it first', () async {
+ final (f, c) = await open();
+ f.app.newSwarm(newTabPage: true);
+ await f.app.closeSwarm(
+ f.app.swarms.firstWhere((s) => s.superTabId == tabId).id,
+ );
+ expect(f.app.swarms.any((s) => s.superTabId == tabId), isFalse);
+ await pick(f, tabId, 'design');
+ await settle();
+ final tab = f.app.swarms.singleWhere((s) => s.superTabId == tabId);
+ expect(f.app.activeSwarmId, tab.id);
+ expect(c.selectedId, 'design-lead');
+ // Opening the Swarm announces too, with the tab's old project; each of
+ // those is the pick's, up to the one that names the picked project.
+ final all = announces(f).where((a) => a['swarms'] != null).toList();
+ final landed = all.indexWhere(
+ (a) =>
+ (a['swarms'] as List).any((s) => (s as Map)['projectId'] == 'design'),
+ );
+ expect(landed, isNonNegative);
+ expect(all.skip(all.length - 1).single['fromDevice'], isTrue);
+ expect(all.first['fromDevice'], isNot(isFalse));
+ });
+
+ test('selecting what is already selected still tags one announce', () async {
+ final (f, c) = await open();
+ expect(c.selectedId, 'lead');
+ await pick(f, tabId, 'lead');
+ await settle();
+ expect(announces(f).last['fromDevice'], isTrue);
+ });
+
+ test('a slow refresh keeps every announce marked until it lands', () async {
+ final f = SuperTabLaunchFixture(local: true);
+ final server = f.connection.server;
+ server.state['projects'] = [
+ projectFixture('lead', 'Lamp OS', 'lead'),
+ projectFixture('design', 'Design', 'design-lead'),
+ ];
+ (server.state['conversations'] as List).add({
+ ...conversationFixture('design-lead', 'Lead'),
+ 'projectId': 'design',
+ });
+ f.app.adoptPoolConnectionForTest('m', f.connection);
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ final hold = server.holdReads = Completer<void>();
+ final before = announces(f).length;
+ final done = pick(f, tabId, 'design');
+ await Future<void>.delayed(const Duration(milliseconds: 400));
+ f.app.announceWindowForeground();
+ await settle();
+ final waiting = announces(f).skip(before).toList();
+ expect(waiting, isNotEmpty);
+ expect(waiting.every((a) => a['fromDevice'] == true), isTrue);
+ hold.complete();
+ await done;
+ await settle();
+ final c = await f.app.superTabs.open(tabId);
+ expect(c.selectedId, 'design-lead');
+ expect(row(announces(f).last)['projectId'], 'design');
+ expect(announces(f).last['fromDevice'], isTrue);
+ f.app.announceWindowForeground();
+ await settle();
+ expect(announces(f).last.containsKey('fromDevice'), isFalse);
+ });
+
+ test('an abandoned pick stops marking announces after 5 seconds', () async {
+ final f = SuperTabLaunchFixture(local: true);
+ f.connection.server.state['projects'] = [
+ projectFixture('lead', 'Lamp OS', 'lead'),
+ ];
+ f.app.adoptPoolConnectionForTest('m', f.connection);
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ final hold = f.connection.server.holdReads = Completer<void>();
+ unawaited(pick(f, tabId, 'lead'));
+ await Future<void>.delayed(const Duration(milliseconds: 100));
+ f.app.announceWindowForeground();
+ await settle();
+ expect(announces(f).last['fromDevice'], isTrue);
+ await Future<void>.delayed(const Duration(milliseconds: 5100));
+ f.app.announceWindowForeground();
+ await settle();
+ expect(announces(f).last.containsKey('fromDevice'), isFalse);
+ hold.complete();
+ await settle();
+ });
+
+ test('unknown tabs and projects are ignored', () async {
+ final (f, c) = await open();
+ final active = f.app.activeSwarmId;
+ final count = f.app.swarms.length;
+ await pick(f, 'ffffffffffffffffffffffff', 'lead');
+ await f.app.handleEventForTest('m', {
+ 'type': 'dial_super_tab',
+ 'payload': {'superTabId': 7},
+ });
+ await settle();
+ expect(announces(f).where((a) => a['fromDevice'] == true), isEmpty);
+ await pick(f, tabId, 'nope');
+ await settle();
+ expect(f.app.activeSwarmId, active);
+ expect(f.app.swarms, hasLength(count));
+ expect(c.selectedId, 'lead');
+ // The flag does not outlive the pick that found nothing.
+ f.app.announceWindowForeground();
+ await settle();
+ expect(announces(f).last.containsKey('fromDevice'), isFalse);
+ });
+}
diff --git a/desktop/test/super_tab_launch_test.dart b/desktop/test/super_tab_launch_test.dart
index 73cd1232d..c8ab4e35a 100644
--- a/desktop/test/super_tab_launch_test.dart
+++ b/desktop/test/super_tab_launch_test.dart
@@ -21,7 +21,7 @@ import 'swarm_state_test.dart' show createApp, MemoryStore;
const tabId = '0123456789abcdef01234567';
class SuperTabFixtureConnection extends WsConn {
- SuperTabFixtureConnection(this.store)
+ SuperTabFixtureConnection(this.store, {bool local = false})
: super(
wsBaseUrl: 'ws://fixture.invalid',
autonomousEnv: 'test',
@@ -30,6 +30,10 @@ class SuperTabFixtureConnection extends WsConn {
onAuthFailure: (_) {},
onEvent: (_) {},
onStatus: (_) {},
+ transportKind: local
+ ? WsTransportKind.localPlaintext
+ : WsTransportKind.cloudE2ee,
+ localWsUri: local ? Uri.parse('ws://127.0.0.1:1/ws') : null,
) {
server.state['id'] = tabId;
}
@@ -322,8 +326,8 @@ class SuperTabFixtureConnection extends WsConn {
}
class SuperTabLaunchFixture {
- SuperTabLaunchFixture() {
- connection = SuperTabFixtureConnection(store);
+ SuperTabLaunchFixture({bool local = false}) {
+ connection = SuperTabFixtureConnection(store, local: local);
app = createApp(
store: store,
connectionForTest: (_) => connection,
diff --git a/desktop/test/support/super_tab_fixture.dart b/desktop/test/support/super_tab_fixture.dart
index dd5d19c84..f716d0d17 100644
--- a/desktop/test/support/super_tab_fixture.dart
+++ b/desktop/test/support/super_tab_fixture.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
@@ -36,6 +37,8 @@ class ConversationServer {
int revision = 0;
bool loseReply = false, reject = false, failSave = false, failReads = false;
Map<String, dynamic>? saved;
+ // While set, every read waits for it: a slow server.
+ Completer<void>? holdReads;
// Makes every command answer with this refusal: {code, message}.
Map<String, String>? refuse;
final posts = <Map<String, dynamic>>[];
@@ -245,6 +248,7 @@ class ConversationServer {
}
return result;
}
+ if (holdReads case final hold?) await hold.future;
if (failReads) throw StateError('Offline');
final uri = Uri.parse(path);
if (uri.pathSegments.last == 'routing-policy') {
diff --git a/devices/harness-pro/docs/cable.md b/devices/harness-pro/docs/cable.md
index 2986e5c51..65aa387b4 100644
--- a/devices/harness-pro/docs/cable.md
+++ b/devices/harness-pro/docs/cable.md
@@ -29,6 +29,7 @@ Full key list, in the order the Pro sends it:
| `stats` | `"turn-v1"` | capability |
| `player` | `"library-v1"` | capability |
| `superTab` | `"wait-v1"` | capability: Super Tab waits on `question` (below) |
+| `swarmCard` | `"v1"` | capability: the Swarm cards and the Lead view (frames below) |
| `ota` | `"v1"` | capability: the Pro takes firmware offers |
| `mac` | `aa:bb:...` | existing |
| `settings` | object | existing: brightness, character, face, voiceLang, muted, quiet, straightTitle, focusFace, scrollReversed, round |
@@ -47,6 +48,7 @@ Capabilities are per session: they reset on a new port and on close, like the br
| `activity: "steps-v1"` | `step`, `action`, `elapsedSeconds` on `turn.activity` | `{t:"turn.activity", agentId, text, action?:string, elapsedSeconds?:int, step?:string}`. `step`: one tool card as `"Tool · arg"` (a path argument keeps its last segment), at most **120 chars**, sent as `{text:"", step}` the moment the tool starts; the firmware cuts at 400. `action`: latest assistant-written progress paragraph, whitespace collapsed, at most **188 bytes** (firmware keeps 192 B). `elapsedSeconds`: integer **0..2592000**, parsed from the engine footer (`1h 2m 3s`); anything else is omitted. `action` also rides on the first `turn.activity` right after `turn.started`. |
| `player: "library-v1"` | feature `player.library` in `welcome.features`; the `player.library.get` request and the `player.library` reply | Request (device to host): `{t:"player.library.get", offset:int 0..1000000, request:int 0..4294967295}`; anything else is ignored. Reply: `{t:"player.library", request, offset, total, machines, rows:[...]}`. `rows` has at most **6** (page size); `offset` is clamped to `max(0, total-6)`; the page is never re-sorted (desktop order). Row: `{id, machineId, name, engine, status, ageSeconds}`; `id`, `machineId` non-empty and < 48 B; `name` <= 95 B, `engine` <= 15 B (control chars to spaces, UTF-8 safe); `status` one of `idle working question finished failed paused offline`; `ageSeconds` is -1 (unknown) or 0..315360000. The firmware rejects the whole page if `count != min(6, total - offset)`. `request` echoes the latest request; a reply for an older request is dropped. Resent at most every 10 s unless the page changed. |
| `superTab: "wait-v1"` | `question` frames for Super Tab waits | `{t:"question", agentId, id:"supertab:…", questions:[{q}], superTab:string ≤48 B, attention:"decision"\|"stuck"}`; see "Super Tab waits on `question`". Without it the daemon sends none. |
+| `swarmCard: "v1"` | `supertabs`, `supertab`, `supertab.recap`, `supertab.focus` to the Pro; `supertab.recap.get`, `supertab.open`, `supertab.select` from it | See "Swarm cards". No such frame reaches a device that does not send it (the round dial, older Pro firmware). |
Order of arrival the firmware tolerates: any. Every field above is optional on the device side; a missing one
leaves the Pod showing an empty body, never an error.
@@ -184,3 +186,46 @@ A link drop ends it as it ends any question (it becomes a plain one the next tur
the Pro's session comes back (its `agents.list`) and on a resync. The library page reports a waiting agent as
`question`. An engine's own question for the same agent replaces it (the daemon closes the wait first) and the daemon
asks the wait again once that question closes.
+
+## Swarm cards (`swarmCard: "v1"`)
+
+The account's Swarms (the shared multi-agent projects of the Super Tab) as Home cards, each with its project Leads as pets; a Lead opens on its last message in the Swarm
+chat (the Lead view). The daemon reads the Swarms from the backend; the Pro only draws them and reports what the person picks. Limits: at most **16** Swarms
+(`SWARMS_CARD_MAX`), **12** Leads per Swarm (`SWARM_LEADS_MAX`); ids `[A-Za-z0-9_-]`, < 48 B; names cut to 48 bytes; message text to **1,500** bytes (`SWARM_TEXT_MAX` - 1) on a
+UTF-8 boundary. A frame over 512 JSON tokens is refused by the Pro's guard, so the list goes as `supertabs` plus one `supertab` per Swarm (12 Leads is about 200 tokens).
+
+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
+{"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.
+- `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 the
+ person whose machine) has none.
+- `supertab.recap` with `none:true` (or no text) is "No message yet". A recap for a Swarm or Lead the Pro does not hold is dropped.
+- `supertab.focus` is acted on like `focus` for an agent: not while recording or updating, not within the touch quiet window (0.8 s on Home, 4 s elsewhere), and a Lead the
+ Swarm list does not hold yet waits 5 s for it. It opens that Lead's view and sends no `supertab.select` (the desktop is already there).
+- A link drop clears the Swarm list and any pending focus; the daemon sends `supertabs` and the `supertab` frames again on attach.
+
+Pro to daemon:
+
+```
+{"t":"supertab.recap.get","tab":"<superTabId>","lead":"<leadAgentId>"} the Lead's last message (sent when its view opens and its text is not LOADED)
+{"t":"supertab.open","tab":"<superTabId>","lead":"<leadAgentId or empty>"} the recap on screen; the lead is empty (tab names the Swarm it was in) when it closes
+{"t":"supertab.select","tab":"<superTabId>","lead":"<leadAgentId>"} the person picked this Lead on the Pro: the desktop opens that Swarm tab and project
+```
+
+- Tapping a Lead's pet on the card, or swiping the Lead view to the previous / next Lead (card order, wrapping), sends `supertab.select`, then `supertab.open` (and
+ `supertab.recap.get` unless the text is already there; its state goes LOADING, drawn as "..."). A `supertab.focus` sends `supertab.open` and `supertab.recap.get` only.
+- What the daemon believes is open follows what is on screen: leaving the view (back, Home, Notices, the Lead removed with none left) sends `supertab.open` with an empty `lead`; Notices over
+ the view closes it and Back from Notices opens it again. A closed Lead's cached text is dropped (only the open Lead gets pushes, so it would go stale).
+- After a link drop nothing is sent until the Swarm list is back; then an open view sends `supertab.open` and `supertab.recap.get` again.
+- A Lead that leaves the list while its view is open moves the view to the Lead that took its place (the next, else the last); with none left, or the Swarm gone, the view goes Home.
+- Frames are sent without waiting: a busy link loses one.
diff --git a/devices/harness-pro/firmware/main/CMakeLists.txt b/devices/harness-pro/firmware/main/CMakeLists.txt
index 473c7f273..9c315ce14 100644
--- a/devices/harness-pro/firmware/main/CMakeLists.txt
+++ b/devices/harness-pro/firmware/main/CMakeLists.txt
@@ -38,6 +38,7 @@ idf_component_register(
"pod/home/ph_inbox.c"
"pod/home/ph_ota.c"
"pod/home/ph_overview.c"
+ "pod/home/ph_lead.c"
"pod/home/ph_recap.c"
"pod/home/ph_talk.c"
"pod/home/ph_toast.c"
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.c b/devices/harness-pro/firmware/main/app/pod_glue.c
index 3777202e2..12b69d194 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.c
+++ b/devices/harness-pro/firmware/main/app/pod_glue.c
@@ -60,10 +60,12 @@ void pod_ui_render(pod_ui_t *u, ht_scene_t *scene, uint32_t now_ms)
}
static void apply_pending_focus(pod_ui_t *u);
+static void apply_lead_focus(pod_ui_t *u);
static pod_out_t synced(pod_ui_t *u)
{
pod_out_t o = pod_nav_sync(&u->nav, &u->model);
apply_pending_focus(u);
+ apply_lead_focus(u);
return o;
}
@@ -71,6 +73,11 @@ pod_out_t pod_ui_link(pod_ui_t *u, bool up)
{
if (up && !u->model.linked) u->sweep.restart = true;
if (!up) pod_ui_sweep_abort(u);
+ if (!up || !u->model.linked) { // the daemon forgets the open recap and any focus with its link: nothing queued or open carries over
+ u->sup_qn = 0;
+ u->sup_tab[0] = u->sup_lead[0] = 0;
+ u->lead_wait = false;
+ }
if (up && !u->model.linked) { // a real down -> up transition: the start runs again on this link on swarms this link brings
u->started = false;
u->fresh_swarms = false;
@@ -182,6 +189,31 @@ pod_out_t pod_ui_question_close(pod_ui_t *u, const char *id)
return synced(u);
}
+pod_out_t pod_ui_supertab_ids(pod_ui_t *u, const char (*ids)[ID_MAX], int n)
+{
+ pod_model_supertab_ids(&u->model, ids, n);
+ return synced(u);
+}
+
+pod_out_t pod_ui_supertab(pod_ui_t *u, const pod_swarm_t *s, uint32_t now_ms)
+{
+ pod_model_supertab(&u->model, s, now_ms);
+ return synced(u);
+}
+
+pod_out_t pod_ui_supertab_recap(pod_ui_t *u, const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ pod_model_supertab_recap(&u->model, tab, lead, text, at, none);
+ return synced(u);
+}
+
+pod_out_t pod_ui_supertab_focus(pod_ui_t *u, const char *tab, const char *lead, uint32_t now_ms)
+{
+ pod_model_clock(&u->model, now_ms);
+ pod_model_supertab_focus(&u->model, tab, lead);
+ return synced(u);
+}
+
pod_out_t pod_ui_recap(pod_ui_t *u, const char *id, const char *recap, bool restore)
{
pod_model_recap(&u->model, id, recap, restore);
@@ -213,8 +245,8 @@ static bool scrolls(const pod_ui_t *u)
{
const pod_frame_t *f = top(u);
if (!f) return false;
- // Home pages sideways; the Inbox scrolls by rows; on a room or a recap a drag scrolls the host's pane
- return f->view == POD_V_INBOX || f->view == POD_V_AGENT || f->view == POD_V_RECAP;
+ // Home pages sideways; the Inbox and a long Lead message scroll by rows; on a room or a recap a drag scrolls the host's pane
+ return f->view == POD_V_INBOX || f->view == POD_V_LEAD || f->view == POD_V_AGENT || f->view == POD_V_RECAP;
}
// Whether a vertical drag on this screen scrolls the host's terminal pane (the scroll sink): Agent and Recap. The top band and the bottom zone keep their swipes (u->bar, u->edge).
static bool host_scrolls(const pod_ui_t *u)
@@ -232,7 +264,7 @@ static bool swipes(const pod_ui_t *u)
{
const pod_frame_t *f = top(u);
return f && (f->view == POD_V_AGENT || f->view == POD_V_RECAP || f->view == POD_V_TALK ||
- f->view == POD_V_TABS || f->view == POD_V_INBOX); // Home pages, the Inbox goes back
+ f->view == POD_V_TABS || f->view == POD_V_INBOX || f->view == POD_V_LEAD); // Home pages, the Inbox goes back, a Lead view steps Leads
}
// Tap to talk: only on the agent's own screens (Agent, Recap). Not in the top band, not on the back crumb or the
// Notices hit, not on an agent that asks (voice stays refused there, so the tap does not arm and no notice fires).
@@ -250,7 +282,7 @@ static const char *talk_target(const pod_ui_t *u)
if (!f || u->ban_touch) return NULL;
if (u->start_y < POD_BAR_H) return NULL; // nothing in the top band talks
if (u->hit_valid && (u->hit.action == POD_A_BACK || u->hit.action == POD_A_INBOX)) return NULL;
- const char *id = f->view == POD_V_AGENT || f->view == POD_V_RECAP ? f->agent : NULL;
+ const char *id = f->view == POD_V_AGENT || f->view == POD_V_RECAP || f->view == POD_V_LEAD ? f->agent : NULL; // a Lead view's agent is its local harness (empty for a remote Lead: no talk)
const pod_agent_t *a = id ? pod_model_find(&u->model, id) : NULL;
return a && !asks_here(&u->model, a) ? id : NULL;
}
@@ -317,6 +349,27 @@ static pod_out_t talk_fire(pod_ui_t *u, uint32_t now_ms)
return o;
}
+// ---- the Lead view's frames for the daemon ----
+static bool sup_push(pod_ui_t *u, const char *t, const char *tab, const char *lead)
+{
+ if (u->sup_qn >= POD_SUPERTAB_OUT_MAX) return false; // a burst past the queue is lost, like any frame on a busy link: the caller counts it as not sent
+ pod_supertab_out_t *o = &u->sup_q[u->sup_qn++];
+ o->t = t;
+ pod_copy_str(o->tab, sizeof o->tab, tab);
+ pod_copy_str(o->lead, sizeof o->lead, lead);
+ return true;
+}
+
+// PREV / NEXT on the Lead view; when it landed on another Lead the daemon is told to select it.
+static void lead_step(pod_ui_t *u, int dir, uint32_t now_ms)
+{
+ char before[ID_MAX];
+ pod_copy_str(before, sizeof before, top(u)->lead_id);
+ pod_nav_act(&u->nav, &u->model, dir > 0 ? POD_A_NEXT : POD_A_PREV, 0, now_ms);
+ const pod_frame_t *f = top(u);
+ if (f->view == POD_V_LEAD && strcmp(before, f->lead_id)) sup_push(u, "supertab.select", f->swarm, f->lead_id);
+}
+
pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bool *changed)
{
pod_out_t none;
@@ -344,7 +397,7 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
// There is no transport line: a contact from anywhere may swipe sideways, or up (Home),
// decided on the lift by which direction dominates.
u->sw_ok = !u->hands_free && swipes(u);
- u->edge = !u->hands_free && (top(u)->view == POD_V_AGENT || top(u)->view == POD_V_RECAP) && y >= POD_BOTTOM_Y;
+ u->edge = !u->hands_free && (top(u)->view == POD_V_AGENT || top(u)->view == POD_V_RECAP || top(u)->view == POD_V_LEAD) && y >= POD_BOTTOM_Y;
u->sw_on = false;
u->sw_vx = 0;
u->sw_last_x = x;
@@ -441,7 +494,7 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
int dx = x - u->start_x, dy = y - u->start_y;
const bool up = dy <= -POD_EDGE_SWIPE && iabs(dy) * 2 > iabs(dx) * 3;
// From anywhere else a vertical drag on a room scrolls the host's terminal pane and never goes Home.
- if (up && u->edge && (tv == POD_V_AGENT || tv == POD_V_RECAP)) {
+ if (up && u->edge && (tv == POD_V_AGENT || tv == POD_V_RECAP || tv == POD_V_LEAD)) {
u->edge = false;
*changed = true;
return pod_nav_act(&u->nav, &u->model, POD_A_TABS, 0, now_ms);
@@ -467,8 +520,15 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
if (to >= 0 && to < wp) u->nav.work_page = (uint8_t)to;
return none;
}
- int16_t pg[POD_TABS_MAX + 2];
- const int n = pod_home_pages(&u->model, pg, POD_TABS_MAX + 2), cur = pod_home_clamp(&u->model, top(u)->scroll);
+ // The Swarm card's pet band pages the Leads the same way, but past either end of the Leads the swipe goes on to the neighbouring card.
+ const pod_swarm_t *sw = u->nav.depth == 1 ? pod_home_swarm(&u->model, pod_home_clamp(&u->model, top(u)->scroll)) : NULL;
+ const int sp = sw ? (sw->lead_n + 2) / 3 : 0;
+ if (sp > 1 && u->start_y >= 256 && u->start_y <= 536) {
+ const int to = (int)u->nav.swarm_page + (dx < 0 ? 1 : -1);
+ if (to >= 0 && to < sp) { u->nav.swarm_page = (uint8_t)to; return none; }
+ }
+ int16_t pg[POD_HOME_PAGES_MAX];
+ const int n = pod_home_pages(&u->model, pg, POD_HOME_PAGES_MAX), cur = pod_home_clamp(&u->model, top(u)->scroll);
int at = 0;
while (at < n - 1 && pg[at] < cur) at++;
const int want = at + (dx < 0 ? 1 : -1);
@@ -477,6 +537,10 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
}
if (top(u)->view == POD_V_INBOX) // the Inbox: either way goes back to where it was opened
return pod_nav_act(&u->nav, &u->model, POD_A_BACK, 1, now_ms);
+ if (top(u)->view == POD_V_LEAD) { // the previous / next Lead: the desktop is told which one
+ lead_step(u, dx < 0 ? 1 : -1, now_ms);
+ return none;
+ }
return pod_nav_act(&u->nav, &u->model, dx < 0 ? POD_A_NEXT : POD_A_PREV, 0, now_ms);
}
}
@@ -502,6 +566,18 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
arg = -1;
for (int i = 0; i < u->model.tab_count; i++) if (!strcmp(u->model.tabs[i].id, u->hit.id)) { arg = i; break; }
}
+ // A Swarm card's Lead pet (POD_A_LEAD: arg = the Lead's index, id = its Swarm's id): the Swarm is resolved by id now (the list can change between the draw
+ // and the tap) and must still hold that index. The Lead view opens over Home and the desktop is told to select that Lead.
+ if (u->hit.id[0] && u->hit.action == POD_A_LEAD) {
+ const pod_swarm_t *sw = pod_model_swarm(&u->model, u->hit.id);
+ arg = sw && arg >= 0 && arg < sw->lead_n ? arg : -1;
+ if (arg >= 0 && pod_nav_open_lead(&u->nav, &u->model, u->hit.id, arg)) {
+ sup_push(u, "supertab.select", sw->id, sw->leads[arg].id);
+ u->scroll_px = 0;
+ *changed = true;
+ return none;
+ }
+ }
if (arg == -1 && u->hit.id[0]) { *changed = true; return none; } // what it named is gone: redraw, open nothing
if (u->hit.action == POD_A_TALK && u->nav.depth) { // an agent of an offline machine cannot be talked to: say why
const pod_agent_t *ag = pod_model_find(&u->model, top(u)->agent);
@@ -566,6 +642,7 @@ bool pod_ui_pet_on_screen(const pod_ui_t *u)
if (!u->model.linked || !f) return false;
// The hero pet is drawn on Agent and Recap (nothing when the agent has left the roster), the listening pet on Talk and, on Home, the equaliser (not a pet; it moves like one)
if (f->view == POD_V_TALK) return true;
+ if (f->view == POD_V_LEAD) return pod_nav_lead(&u->nav, &u->model, NULL) != NULL; // the Lead's pet, once the model holds the Lead
if (f->view == POD_V_TABS || f->view == POD_V_TAB) return ph_home_moves(&u->nav, &u->model);
return (f->view == POD_V_AGENT || f->view == POD_V_RECAP) && pod_model_find(&u->model, f->agent);
}
@@ -841,3 +918,104 @@ bool pod_ui_notif_seen(pod_ui_t *u, const char *agent_id, const char *token)
}
int pod_ui_take_reads(pod_ui_t *u, pod_read_out_t out[], int max) { return pod_model_take_reads(&u->model, out, max); }
+
+// ---- the Swarm cards: following the desktop, and what the daemon is told ---------------------------------------------
+
+// supertab.focus (the model's focus_pending): open that Lead's recap the way a host focus opens an agent. Dropped, not kept, while recording or updating or when the
+// person is driving (a touch within the quiet window, a finger down); a Lead the Swarm list does not hold yet waits POD_FOLLOW_PENDING_MS for it.
+static void apply_lead_focus(pod_ui_t *u)
+{
+ pod_model_t *m = &u->model;
+ if (!m->focus_pending) return;
+ const uint32_t now_ms = m->clock_ms;
+ if (!u->lead_wait) { u->lead_wait = true; u->lead_wait_ms = now_ms; }
+ if (pod_model_lead_index(pod_model_swarm(m, m->focus_tab), m->focus_lead) < 0) {
+ if ((int32_t)(now_ms - u->lead_wait_ms) > (int32_t)POD_FOLLOW_PENDING_MS) { m->focus_pending = false; u->lead_wait = false; }
+ return;
+ }
+ char tab[ID_MAX], lead[ID_MAX];
+ memcpy(tab, m->focus_tab, ID_MAX);
+ memcpy(lead, m->focus_lead, ID_MAX);
+ m->focus_pending = false;
+ u->lead_wait = false;
+ if (pod_ui_talking(u) || u->ota || u->down) return;
+ const uint32_t quiet = u->nav.depth <= 1 ? POD_FOLLOW_ECHO_MS : POD_FOLLOW_QUIET_MS; // as follow_now: the device's own selection comes back as a focus
+ if (u->touched && (int32_t)(now_ms - u->last_touch_ms) < (int32_t)quiet) return;
+ if (pod_nav_follow_lead(&u->nav, m, tab, lead)) {
+ u->scroll_px = 0;
+ u->dirty = true;
+ u->started = true; // a focus that landed: the start never overrides it
+ }
+}
+
+// Make the daemon's idea of the open recap match the screen. The screen's Lead is the Lead view's, or the one a talk opened from it (the frame is the same).
+static void sup_sync(pod_ui_t *u)
+{
+ pod_model_t *m = &u->model;
+ if (!m->linked) { u->sup_tab[0] = u->sup_lead[0] = 0; return; }
+ const pod_frame_t *f = top(u);
+ const bool on = f && f->swarm[0] && (f->view == POD_V_LEAD || f->view == POD_V_TALK);
+ const pod_swarm_t *sw = NULL;
+ const pod_lead_t *l = on ? pod_nav_lead(&u->nav, m, &sw) : NULL;
+ if (on && !l) return; // its Lead is not in the model (yet): neither open nor closed, wait for it
+ const char *lead = l ? l->id : "";
+ if (!strcmp(u->sup_lead, lead) && (!l || !strcmp(u->sup_tab, sw->id))) { // already what the daemon was told: a frame that may have been lost is re-sent
+ if (!l) return;
+ const uint32_t now_ms = m->clock_ms;
+ if ((uint32_t)(now_ms - u->sup_at) < POD_SUPERTAB_RETRY_MS || u->sup_qn + 2 > POD_SUPERTAB_OUT_MAX) return;
+ if (l->recap == POD_RECAP_LOADING) { // no reply yet: ask again, a few times; then the "…" stays and nothing more is sent
+ if (u->sup_tries >= POD_SUPERTAB_RETRIES) return;
+ u->sup_tries++;
+ sup_push(u, "supertab.open", sw->id, lead);
+ sup_push(u, "supertab.recap.get", sw->id, lead);
+ u->sup_at = now_ms;
+ } else if (!u->sup_reopened) { // answered, but the open itself might have been the lost frame: say it once more
+ u->sup_reopened = true;
+ sup_push(u, "supertab.open", sw->id, lead);
+ u->sup_at = now_ms;
+ }
+ return;
+ }
+ if (!l) { // closed: the frame still names the Swarm it was open in
+ if (!sup_push(u, "supertab.open", u->sup_tab, "")) return; // no room: still open as far as the daemon knows, the next sync closes it
+ if (u->sup_lead[0]) pod_model_supertab_close(m, u->sup_tab, u->sup_lead); // only the open Lead is pushed to: a closed one's text would go stale
+ u->sup_tab[0] = u->sup_lead[0] = 0;
+ return;
+ }
+ const char *tab = sw->id;
+ const bool ask = l->recap != POD_RECAP_LOADED;
+ if (u->sup_qn + (ask ? 2 : 1) > POD_SUPERTAB_OUT_MAX) return; // no room for the frames this needs: nothing is recorded, the next sync tries again
+ if (u->sup_lead[0]) pod_model_supertab_close(m, u->sup_tab, u->sup_lead);
+ sup_push(u, "supertab.open", tab, lead);
+ if (ask) { // a cold Lead: ask for its last message (the daemon's cache makes a repeat free)
+ sup_push(u, "supertab.recap.get", tab, lead);
+ pod_model_supertab_loading(m, tab, lead);
+ }
+ pod_copy_str(u->sup_tab, sizeof u->sup_tab, tab);
+ pod_copy_str(u->sup_lead, sizeof u->sup_lead, lead);
+ u->sup_at = m->clock_ms;
+ u->sup_tries = 0;
+ u->sup_reopened = false;
+}
+
+int pod_ui_take_supertab(pod_ui_t *u, pod_supertab_out_t out[], int max)
+{
+ sup_sync(u);
+ int n = u->sup_qn < max ? u->sup_qn : max;
+ if (n > 0) memcpy(out, u->sup_q, (size_t)n * sizeof out[0]);
+ if (n < u->sup_qn) memmove(u->sup_q, u->sup_q + n, (size_t)(u->sup_qn - n) * sizeof u->sup_q[0]);
+ u->sup_qn = (uint8_t)(u->sup_qn - n);
+ return n;
+}
+
+void pod_ui_supertab_unsent(pod_ui_t *u, const char *t)
+{
+ if (!t || !u->sup_lead[0]) return;
+ if (!strcmp(t, "supertab.recap.get")) {
+ if (u->sup_tries) u->sup_tries--; // a failed retry does not use one up
+ u->sup_at = u->model.clock_ms; // and the next waits the usual 3 s
+ } else if (!strcmp(t, "supertab.open")) {
+ u->sup_reopened = false;
+ u->sup_at = u->model.clock_ms;
+ }
+}
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.h b/devices/harness-pro/firmware/main/app/pod_glue.h
index f397de400..2ee969a51 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.h
+++ b/devices/harness-pro/firmware/main/app/pod_glue.h
@@ -20,6 +20,9 @@ enum { POD_TAP_SLOP = 24 }; // px: farther than this from the DOWN and the con
enum { POD_BAR_H = 72, POD_BAR_SWIPE = 80, POD_EDGE_SWIPE = 80, POD_BOTTOM_Y = 620 }; // POD_BOTTOM_Y: a swipe up that starts at or below it goes Home from a room or a recap
typedef struct { const char *id, *name, *engine, *machine; } pod_roster_row_t;
+// One frame for the daemon about the Swarm cards: `t` is "supertab.select", "supertab.open" or "supertab.recap.get" (a literal), lead "" closes the open recap.
+typedef struct { const char *t; char tab[ID_MAX], lead[ID_MAX]; } pod_supertab_out_t;
+enum { POD_SUPERTAB_OUT_MAX = 8, POD_SUPERTAB_RETRIES = 5, POD_SUPERTAB_RETRY_MS = 3000 };
typedef struct {
pod_model_t model;
@@ -90,6 +93,16 @@ typedef struct {
uint32_t last_touch_ms;
char pending_focus[ID_MAX];
uint32_t pending_focus_ms;
+ // The Swarm cards' Lead view (see pod_ui_take_supertab): the Lead the daemon was last told is open (empty: none), the frames waiting to go, and when a
+ // supertab.focus began waiting for its Swarm list.
+ char sup_tab[ID_MAX], sup_lead[ID_MAX];
+ pod_supertab_out_t sup_q[POD_SUPERTAB_OUT_MAX];
+ uint8_t sup_qn;
+ uint32_t sup_at; // when the open Lead was last (re)sent to the daemon, at the model's clock
+ uint8_t sup_tries; // re-sends of open + recap.get so far while it stays LOADING (at most POD_SUPERTAB_RETRIES)
+ bool sup_reopened; // the one supertab.open sent POD_SUPERTAB_RETRY_MS after opening, so the daemon surely knows the open Lead
+ bool lead_wait;
+ uint32_t lead_wait_ms;
// The software update (see pod_ui_ota): while on, the stack stays as it was and ph_view_ota is what is drawn.
bool ota, ota_restarting;
int ota_pct;
@@ -112,6 +125,11 @@ pod_out_t pod_ui_turn(pod_ui_t *, const char *id, const char *kind, const char *
// turn.stats for an agent (-1 leaves a field unknown); unknown agents are ignored.
pod_out_t pod_ui_turn_stats(pod_ui_t *, const char *id, int32_t passed, int32_t failed, int32_t commits, int32_t tokens_in, int32_t tokens_out);
// super_tab: the Super Tab the question was asked in (NULL = a plain question) and its attention (pod_model_question_tab).
+// The Swarm cards: the model's lists (pod_model_supertab_ids / _supertab / _recap / _focus) behind the same sync as every feed.
+pod_out_t pod_ui_supertab_ids(pod_ui_t *, const char (*ids)[ID_MAX], int n);
+pod_out_t pod_ui_supertab(pod_ui_t *, const pod_swarm_t *s, uint32_t now_ms);
+pod_out_t pod_ui_supertab_recap(pod_ui_t *, const char *tab, const char *lead, const char *text, uint32_t at, bool none);
+pod_out_t pod_ui_supertab_focus(pod_ui_t *, const char *tab, const char *lead, uint32_t now_ms); // now_ms: the quiet-window and waiting clocks, as pod_ui_focus's
pod_out_t pod_ui_question(pod_ui_t *, const char *id, const char *text, const char *super_tab, pod_attention_t attention);
// The daemon took a recording for this agent (voice.result): Working now, before its turn starts (pod_model_sent).
pod_out_t pod_ui_sent(pod_ui_t *, const char *id, uint32_t now_ms);
@@ -126,6 +144,18 @@ pod_out_t pod_ui_recap(pod_ui_t *, const char *id, const char *recap, bool resto
#define POD_FOLLOW_PENDING_MS 5000
pod_out_t pod_ui_focus(pod_ui_t *, const char *agent_id, uint32_t now_ms);
+// ---- the Lead view (Swarm cards) ----
+// A tap on a Lead pet (POD_A_LEAD) opens the Lead view; a horizontal swipe on it steps to the previous / next Lead; supertab.focus (the model's focus_pending, acted on
+// after every feed) opens the Lead the desktop opened, the way pod_ui_focus does (not while talking, updating or touching; a Lead the list does not hold yet waits
+// POD_FOLLOW_PENDING_MS for it). The frames for the daemon are queued and taken after the lock is released: select (a tap or a swipe, never a follow: the
+// desktop already is there), then whatever makes the daemon's idea of the open recap match the screen: supertab.open with the Lead (and supertab.recap.get unless its
+// text is LOADED; it goes LOADING) when the Lead view shows one, supertab.open with no lead when it no longer does. While the Lead cannot be found (the link dropped,
+// the list not back yet) nothing is sent; a link drop forgets what was open, so the view re-sends open and get when its Lead is back.
+// Returns how many frames were written to out (at most max).
+int pod_ui_take_supertab(pod_ui_t *, pod_supertab_out_t out[], int max);
+// A frame taken by pod_ui_take_supertab that could not be sent (the link was busy): open / recap.get count as not sent, so the retry comes again (a failed retry is not counted).
+void pod_ui_supertab_unsent(pod_ui_t *, const char *t);
+
// The start, armed by a real link down -> up (pod_ui_link): once swarms of this link have arrived, if the stack is at the
// root (TABS) and tab 0 has agents, enter tab 0 on its first agent (POD_A_ENTER_TAB). It is device-local: no AGENT_OPEN
// goes to the host (that message only moves the desktop's focused pane). Any other outcome ends the start for this link:
diff --git a/devices/harness-pro/firmware/main/app/pro_app.c b/devices/harness-pro/firmware/main/app/pro_app.c
index 6ed44bbb6..b9b8958d3 100644
--- a/devices/harness-pro/firmware/main/app/pro_app.c
+++ b/devices/harness-pro/firmware/main/app/pro_app.c
@@ -154,6 +154,25 @@ static void perform(const pod_out_t *o)
}
}
+// The Swarm cards' select / open / recap.get frames the Lead view owes the daemon (pod_ui_take_supertab reconciles them with what is on screen). Taken under the
+// lock, sent after it. Its own frame: the queue is too big for leave()'s (1 KB cap).
+static __attribute__((noinline)) void send_supertabs(void)
+{
+ pod_supertab_out_t q[POD_SUPERTAB_OUT_MAX];
+ pro_app_lock();
+ const uint32_t rev = s_pod.model.revision;
+ const int n = pod_ui_take_supertab(&s_pod, q, POD_SUPERTAB_OUT_MAX);
+ if (s_pod.model.revision != rev) change(); // asking for a recap puts it LOADING: a change no feed announced (the flag is the model's revision: not consumed here)
+ pro_app_unlock();
+ bool lost[POD_SUPERTAB_OUT_MAX] = {0};
+ bool any = false;
+ for (int i = 0; i < n; i++) any |= lost[i] = !pro_cable_supertab_send(q[i].t, q[i].tab, q[i].lead);
+ if (!any) return;
+ pro_app_lock(); // a frame the link dropped is owed again (open / recap.get are retried)
+ for (int i = 0; i < n; i++) if (lost[i]) pod_ui_supertab_unsent(&s_pod, q[i].t);
+ pro_app_unlock();
+}
+
// Release the lock, then do what the feeds asked for. Every entry that took the lock ends here.
static void leave(void)
{
@@ -172,6 +191,7 @@ static void leave(void)
pro_app_unlock();
for (int i = 0; i < n; i++) perform(&q[i]);
for (int i = 0; i < read_n; i++) pro_cable_send_notif_read(reads[i].agent, reads[i].token);
+ send_supertabs();
if (wake) pro_app_wake(); // an alert: light a dark glass so its banner is seen
if (beep && !pro_settings_muted() && !atomic_load(&s_updating)) audio_beep(); // and chime, unless muted
if (lib) send_library(lib_request, lib_offset);
@@ -352,6 +372,36 @@ void pro_app_swarms(const cable_swarm_t *items, int n, const cable_swarm_members
leave();
}
+// The Swarm cards. The model copies the list and keeps the Lead recap texts (pod_model_supertab); a recap lands on its Lead.
+// supertab.focus is recorded by the model (focus_*) and acted on by the glue after the feed (apply_lead_focus): the Lead view opens.
+void pro_app_supertab_ids(const char (*ids)[ID_MAX], int n)
+{
+ pro_app_lock();
+ settle(pod_ui_supertab_ids(&s_pod, ids, n));
+ leave();
+}
+
+void pro_app_supertab(const pod_swarm_t *sw)
+{
+ pro_app_lock();
+ settle(pod_ui_supertab(&s_pod, sw, ms()));
+ leave();
+}
+
+void pro_app_supertab_recap(const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ pro_app_lock();
+ settle(pod_ui_supertab_recap(&s_pod, tab, lead, text, at, none));
+ leave();
+}
+
+void pro_app_supertab_focus(const char *tab, const char *lead)
+{
+ pro_app_lock();
+ settle(pod_ui_supertab_focus(&s_pod, tab, lead, ms()));
+ leave();
+}
+
_Static_assert(sizeof(pro_library_row_t) == sizeof(pod_library_row_t) &&
offsetof(pro_library_row_t, id) == offsetof(pod_library_row_t, id) &&
offsetof(pro_library_row_t, name) == offsetof(pod_library_row_t, name) &&
diff --git a/devices/harness-pro/firmware/main/cable/cable_types.h b/devices/harness-pro/firmware/main/cable/cable_types.h
index 17931ff22..2a7d86f90 100644
--- a/devices/harness-pro/firmware/main/cable/cable_types.h
+++ b/devices/harness-pro/firmware/main/cable/cable_types.h
@@ -67,3 +67,26 @@ typedef struct {
int16_t x1, y1, x2, y2; // 0..1000
char agent_id[ID_MAX];
} cable_tile_t;
+
+/*
+ * THE SWARM CARDS (hello `swarmCard:"v1"`; the `supertabs` id list and one `supertab` frame per Swarm): the account's Swarms, each with its project Leads. A Swarm is
+ * not the window's tab (cable_swarm_t above): it is the shared multi-agent project the Super Tab waits name, read from the
+ * backend by the daemon. `tab` links it to the desk tab of the same Swarm ("" when the desktop has none open).
+ */
+enum { SWARMS_CARD_MAX = 16, SWARM_LEADS_MAX = 12, SWARM_TEXT_MAX = 1501 }; // text: 1,500 bytes + NUL
+typedef enum { POD_LEAD_ASK, POD_LEAD_STUCK, POD_LEAD_WORK, POD_LEAD_DONE } pod_lead_state_t; // needs you, stuck, working, done
+typedef enum { POD_RECAP_NONE, POD_RECAP_LOADING, POD_RECAP_LOADED, POD_RECAP_EMPTY } pod_recap_state_t;
+typedef struct {
+ char id[ID_MAX], projectId[ID_MAX], project[49], engine[16], owner[49], local[ID_MAX]; // owner: another person's machine; local: the harness to talk to
+ pod_lead_state_t state;
+ uint32_t since_s, since_at_ms; // seconds into the turn when the frame arrived (local Lead in a turn), and the device clock then
+ pod_recap_state_t recap;
+ char *text; // the Lead's last message, PSRAM, owned by the model (NULL unless LOADED); the cable side leaves it NULL
+ uint32_t text_at; // when it was written (epoch seconds)
+} pod_lead_t;
+typedef struct {
+ char id[ID_MAX], tab[ID_MAX], name[49];
+ uint16_t count; // workspaces (projects that have a Lead)
+ uint8_t lead_n;
+ pod_lead_t leads[SWARM_LEADS_MAX]; // in card order
+} pod_swarm_t;
diff --git a/devices/harness-pro/firmware/main/cable/pro_cable.c b/devices/harness-pro/firmware/main/cable/pro_cable.c
index 0754de4ff..25dde8af7 100644
--- a/devices/harness-pro/firmware/main/cable/pro_cable.c
+++ b/devices/harness-pro/firmware/main/cable/pro_cable.c
@@ -222,6 +222,7 @@ static void send_hello(void)
msg_string(&root, "stats", "turn-v1");
msg_string(&root, "player", "library-v1");
msg_string(&root, "superTab", "wait-v1"); // a question with superTab + attention is shown as a wait (handle_question)
+ msg_string(&root, "swarmCard", "v1"); // supertabs / supertab.recap / supertab.focus: the Swarm cards (handle_supertab)
msg_string(&root, "ota", "v1");
char mac[24] = "";
device_mac_str(mac, sizeof(mac));
@@ -265,6 +266,16 @@ bool pro_cable_send_open(const char *agent_id)
return send_json(root);
}
+bool pro_cable_supertab_send(const char *t, const char *tab, const char *lead)
+{
+ if (!t || !tab || !tab[0]) return false;
+ if (strcmp(t, "supertab.recap.get") && strcmp(t, "supertab.open") && strcmp(t, "supertab.select")) return false;
+ cJSON *root = msg(t);
+ msg_string(&root, "tab", tab);
+ msg_string(&root, "lead", lead ? lead : "");
+ return send_json_with(root, false); // false: dropped on a busy link (the caller retries)
+}
+
bool pro_cable_send_scroll(pro_scroll_phase_t phase, int dy, int velocity)
{
_Static_assert(PRO_SCROLL_DOWN == 0 && PRO_SCROLL_MOVE == 1 && PRO_SCROLL_UP == 2, "scroll phase wire order");
@@ -523,6 +534,115 @@ static void handle_swarms(const cJSON *p)
pro_app_swarms(s_swarm_rows, n, has_ids ? &s_swarm_members : NULL, selected, s_tiles, tn);
}
+// ── the Swarm cards ─────────────────────────────────────────────────────────────────────────────────
+// Two frames, so each stays under the JSON guard's token budget: `supertabs` {ids} is the set and order, `supertab` one Swarm with its
+// Leads (about 200 tokens at 12). A Swarm or Lead that is not an object, has no usable id, or repeats an id is skipped (the
+// frame survives); an unknown `state` reads as done. Parsed into PSRAM staging: the model copies it and keeps the cached recap
+// texts, so the Lead `text` pointers stay NULL here.
+
+static EXT_RAM_BSS_ATTR pod_swarm_t s_card;
+static char s_card_ids[SWARMS_CARD_MAX][ID_MAX];
+static char s_card_text[SWARM_TEXT_MAX];
+
+static bool id_fits(const char *s) { return s && s[0] && strlen(s) < ID_MAX; }
+
+static pod_lead_state_t lead_state(const char *s)
+{
+ if (s && !strcmp(s, "ask")) return POD_LEAD_ASK;
+ if (s && !strcmp(s, "stuck")) return POD_LEAD_STUCK;
+ if (s && !strcmp(s, "work")) return POD_LEAD_WORK;
+ return POD_LEAD_DONE;
+}
+
+static void read_leads(const cJSON *it, pod_swarm_t *sw)
+{
+ const cJSON *l = NULL;
+ cJSON_ArrayForEach(l, cJSON_GetObjectItemCaseSensitive(it, "leads")) {
+ if (sw->lead_n >= SWARM_LEADS_MAX) break;
+ const char *id = str_of(l, "id");
+ if (!id_fits(id)) continue;
+ bool duplicate = false;
+ for (int i = 0; i < sw->lead_n; i++) if (!strcmp(sw->leads[i].id, id)) duplicate = true;
+ if (duplicate) continue;
+ pod_lead_t *ld = &sw->leads[sw->lead_n++];
+ memset(ld, 0, sizeof *ld);
+ snprintf(ld->id, sizeof ld->id, "%s", id);
+ const char *pid = str_of(l, "projectId");
+ if (pid && strlen(pid) < sizeof ld->projectId) snprintf(ld->projectId, sizeof ld->projectId, "%s", pid); // whole or none
+ cut_of(l, "project", ld->project, sizeof ld->project);
+ cut_of(l, "engine", ld->engine, sizeof ld->engine);
+ cut_of(l, "owner", ld->owner, sizeof ld->owner);
+ const char *local = str_of(l, "local");
+ if (local && strlen(local) < sizeof ld->local) snprintf(ld->local, sizeof ld->local, "%s", local); // a harness id: whole or none
+ ld->state = lead_state(str_of(l, "state"));
+ const cJSON *since = cJSON_GetObjectItemCaseSensitive(l, "since");
+ if (cJSON_IsNumber(since) && since->valuedouble > 0) ld->since_s = since->valuedouble > 2592000 ? 2592000u : (uint32_t)since->valuedouble;
+ ld->recap = POD_RECAP_NONE;
+ }
+}
+
+static void handle_supertabs(const cJSON *p)
+{
+ const cJSON *ids = cJSON_GetObjectItemCaseSensitive(p, "ids");
+ if (!cJSON_IsArray(ids)) return;
+ int n = 0;
+ const cJSON *it = NULL;
+ cJSON_ArrayForEach(it, ids) {
+ if (n >= SWARMS_CARD_MAX) break;
+ if (!cJSON_IsString(it) || !id_fits(it->valuestring)) continue;
+ bool duplicate = false;
+ for (int i = 0; i < n; i++) if (!strcmp(s_card_ids[i], it->valuestring)) duplicate = true;
+ if (duplicate) continue;
+ snprintf(s_card_ids[n++], ID_MAX, "%s", it->valuestring);
+ }
+ ESP_LOGI(TAG, "supertabs: %d", n);
+ pro_app_supertab_ids(s_card_ids, n);
+}
+
+static void handle_supertab(const cJSON *p)
+{
+ const char *id = str_of(p, "id");
+ if (!id_fits(id)) return;
+ pod_swarm_t *sw = &s_card;
+ memset(sw, 0, sizeof *sw);
+ snprintf(sw->id, sizeof sw->id, "%s", id);
+ const char *tab = str_of(p, "tab");
+ if (tab && strlen(tab) < sizeof sw->tab) snprintf(sw->tab, sizeof sw->tab, "%s", tab);
+ cut_of(p, "name", sw->name, sizeof sw->name);
+ read_leads(p, sw);
+ const cJSON *count = cJSON_GetObjectItemCaseSensitive(p, "count"); // absent: the Leads listed
+ sw->count = cJSON_IsNumber(count) ? (count->valuedouble > 0 ? (count->valuedouble > 65535 ? 65535 : (uint16_t)count->valuedouble) : 0)
+ : sw->lead_n;
+ pro_app_supertab(sw);
+}
+
+// `supertab.recap`: one Lead's last message, cut to 1,500 bytes on a UTF-8 boundary. `none` (or no text) is "No message yet".
+static void handle_supertab_recap(const cJSON *p)
+{
+ char tab[ID_MAX], lead[ID_MAX];
+ const char *t = str_of(p, "tab"), *l = str_of(p, "lead");
+ if (!id_fits(t) || !id_fits(l)) return;
+ snprintf(tab, sizeof tab, "%s", t);
+ snprintf(lead, sizeof lead, "%s", l);
+ const cJSON *none = cJSON_GetObjectItemCaseSensitive(p, "none"), *at = cJSON_GetObjectItemCaseSensitive(p, "at");
+ const char *text = cut_of(p, "text", s_card_text, sizeof s_card_text);
+ if (!text) s_card_text[0] = 0;
+ const bool empty = cJSON_IsTrue(none);
+ if (empty) s_card_text[0] = 0;
+ const double secs = cJSON_IsNumber(at) && at->valuedouble > 0 ? at->valuedouble : 0;
+ pro_app_supertab_recap(tab, lead, s_card_text, secs > 4294967295.0 ? 0xFFFFFFFFu : (uint32_t)secs, empty);
+}
+
+static void handle_supertab_focus(const cJSON *p)
+{
+ char tab[ID_MAX], lead[ID_MAX];
+ const char *t = str_of(p, "tab"), *l = str_of(p, "lead");
+ if (!id_fits(t) || !id_fits(l)) return;
+ snprintf(tab, sizeof tab, "%s", t);
+ snprintf(lead, sizeof lead, "%s", l);
+ pro_app_supertab_focus(tab, lead);
+}
+
// ── the machine list ────────────────────────────────────────────────────────────────────────────────
// Streamed like the agents. cable_machines_end() answers "did anything change" before pro_app is touched, so the
// daemon re-sending an identical list (its own diff key resets on every port reopen) costs one comparison.
@@ -874,6 +994,10 @@ static void handle_message(const cJSON *root)
if (!strcmp(t, "machines.end")) { handle_machines_end(p); return; }
if (!strcmp(t, "machine.updated")) { handle_machine_updated(p); return; }
if (!strcmp(t, "swarms")) { handle_swarms(p); return; }
+ if (!strcmp(t, "supertabs")) { handle_supertabs(p); return; }
+ if (!strcmp(t, "supertab")) { handle_supertab(p); return; }
+ if (!strcmp(t, "supertab.recap")) { handle_supertab_recap(p); return; }
+ if (!strcmp(t, "supertab.focus")) { handle_supertab_focus(p); return; }
if (!strcmp(t, "player.library")) { handle_library(p); return; }
if (!strcmp(t, "player.context")) { handle_context(p); return; }
if (!strcmp(t, "settings.set")) { handle_settings_set(p); return; }
diff --git a/devices/harness-pro/firmware/main/cable/pro_cable.h b/devices/harness-pro/firmware/main/cable/pro_cable.h
index cffe898e7..ef9322e68 100644
--- a/devices/harness-pro/firmware/main/cable/pro_cable.h
+++ b/devices/harness-pro/firmware/main/cable/pro_cable.h
@@ -24,6 +24,11 @@ bool pro_cable_send_scroll(pro_scroll_phase_t phase, int dy, int velocity);
// Never waits (the render task sends it); false when it could not go out, and pro_app asks again.
bool pro_cable_request_library(int offset, uint32_t request);
+// The Swarm cards' three frames to the daemon, `t` one of "supertab.recap.get" (the Lead's last message), "supertab.open" (the
+// recap on screen; `lead` NULL or "" when it closes) and "supertab.select" (pick the Lead on the desktop). Anything else, or
+// no `tab`, sends nothing. Never waits (the render and touch tasks send it); a busy link loses it, so the caller asks again.
+bool pro_cable_supertab_send(const char *t, const char *tab, const char *lead);
+
// Voice: begin sends voice.begin and remembers `upload_id` (<= 23 chars) to match the reply; pcm is a CABLE_TYPE_PCM
// frame (16-bit mono); end finishes the recording (the reply arrives as pro_app_voice_result); abort/cancel discard it.
bool pro_cable_voice_begin(const char *agent_id, const char *lang, int sample_rate, const char *upload_id);
diff --git a/devices/harness-pro/firmware/main/pod/home/ph.h b/devices/harness-pro/firmware/main/pod/home/ph.h
index 9bc897dfd..9b461c7c3 100644
--- a/devices/harness-pro/firmware/main/pod/home/ph.h
+++ b/devices/harness-pro/firmware/main/pod/home/ph.h
@@ -20,7 +20,9 @@ enum { PH_HOME_BG = 0x151413,
PH_LETTER = 0xF4EEE3, PH_LETTER_MID = 0xD9CFBF, PH_LETTER_BACK = 0xBFB3A1, PH_LETTER_INK = 0x1F1A14, PH_LETTER_RULE = 0xE2D8C8, // the Notices card: a letter
PH_LETTER_WHO = 0x9A5A2E, PH_LETTER_MORE = 0x9A8A76, PH_LETTER_MARK = 0xD9622B, PH_LETTER_BADGE = 0xFF7A2F,
PH_TOAST_FILL = 0x1B2A3D, PH_TOAST_EDGE = 0x2A3D55, PH_TOAST_NAME = 0xFFB36B, PH_TOAST_INK = 0xF2F7FC, PH_TOAST_BAR = 0xFF8A3D, // the notice toast
- PH_CARD_INK = 0xFFFFFF, PH_PILL_WORK = 0x9DFFC0, PH_PILL_ASK = 0xFFC796 };
+ PH_CARD_INK = 0xFFFFFF, PH_PILL_WORK = 0x9DFFC0, PH_PILL_ASK = 0xFFC796,
+ PH_SWARM1 = 0x6A4BB0, PH_SWARM2 = 0x22163F, // the Swarm card's gradient (purple)
+ PH_LEAD_WORK = 0x3EE05B, PH_LEAD_ASK = 0xFFC796, PH_LEAD_STUCK = 0xFFB0B0 }; // a Lead's status line: working, needs you, stuck (done is white at 60 %)
// Home's equaliser: four 8 px bars 5 px apart (47 wide) in a 36 px box at (x, y), PH_ROOM_GREEN, a triangle wave between 40 % and 100 %, 900 ms.
void ph_working_mark_big(ht_scene_t *, int x, int y, uint32_t now_ms);
@@ -56,6 +58,10 @@ pod_scene_t ph_card_scene(const pod_model_t *, const pod_agent_t *);
void ph_engine_logo(ht_scene_t *, int x, int y, int size, const char *engine, unsigned fill);
// Home's Notices card (ph_overview.c header): while pod_notice_count > 0 it is the page before tab 0; the TABS frame's scroll is the tab index, POD_HOME_NOTICES (-2) the Notices card.
// A tap on it is one POD_A_INBOX hit.
+// Home's Swarm card (ph_overview.c header): the pet scene a Lead plays, WORK while it works, ASK when it needs you or is stuck, else REST.
+pod_scene_t ph_lead_scene(pod_lead_state_t);
+// A Lead's status line and its colour (PH_LEAD_*; `dim`, the caller's, for "done"): "working · m:ss" (a remote Lead without a clock: "working"), "needs you", "stuck", "done".
+unsigned ph_lead_status(const pod_lead_t *, uint32_t now_ms, char *line, size_t n, unsigned dim);
// Home's Working card: the working agents newest turn first (the least pod_agent_secs, ties in model order); returns how many are listed (at most cap).
int ph_working_list(const pod_model_t *, const pod_agent_t **out, int cap, uint32_t now_ms);
// The card colours of an engine (the tab cards' mapping; NULL or an unknown engine: the grey pair), and the Working card's: Codex's blue.
@@ -93,6 +99,16 @@ int ph_inbox_max_row(const pod_model_t *);
typedef struct { const char *engine, *name; char text[160]; } ph_notice_line_t; // name: the agent's, "" when unknown
int ph_notices_top(const pod_model_t *, int max, ph_notice_line_t *out);
+// ---- The Lead view (ph_lead.c): a Swarm card's Lead, its last message in a paper bubble (see the file's header) ----
+// The top frame's Lead (pod_nav_lead): the Swarm's name and the project on top, the bubble (loaded text, "..." loading, no bubble and "No message yet" when empty; an orange
+// inner left edge for a Lead that needs you, red for stuck), the Lead's pet signing it with "Lead" and its status line. No hit. Draws nothing while the model does not hold the Lead.
+void ph_view_lead(pod_out_frame_t *, const pod_nav_t *, pod_model_t *, uint32_t now_ms);
+// A long message scrolls by rows: 46 px a row, the last valid offset (rows past the 7 shown), 0 for any other state.
+int ph_lead_pitch(void);
+int ph_lead_max_row(const pod_nav_t *, const pod_model_t *);
+// Ms to its next change: the pet's next step (no sooner than the Pets beat) and the status line's seconds.
+uint32_t ph_lead_next_ms(const pod_nav_t *, const pod_model_t *, uint32_t now_ms);
+
// ---- The notice toast (ph_toast.c) ----
// The toast for unread entry `u` over whatever the frame holds (call it last, as the glue draws it): see the file's header. shown_ms: when it appeared; it
// slides in over POD_TOAST_SLIDE_MS and its bar runs out at shown_ms + POD_TOAST_MS (a Super Tab question's bar stays full: pod_model_attention). Adds one POD_A_BANNER hit (arg 0, id = the agent). Returns the
diff --git a/devices/harness-pro/firmware/main/pod/home/ph_lead.c b/devices/harness-pro/firmware/main/pod/home/ph_lead.c
new file mode 100644
index 000000000..0019ab4da
--- /dev/null
+++ b/devices/harness-pro/firmware/main/pod/home/ph_lead.c
@@ -0,0 +1,200 @@
+// The Lead view (Swarm cards; the owner's mockup swarm-card.html B1-B3), built from ph_recap.c: a tap on a Lead's pet on the Swarm card opens the Lead's last
+// message in the Swarm chat. On the navy ground: the Swarm's name (small, purple) and the project (the title) centred at the top, then the message in the
+// paper bubble (x 60, 600 wide, top 150, only as tall as its text: 28 px above and below, 34 at the sides, rows 46 px apart), a tail under its bottom left and
+// the "who" row: the Lead's pet (150 px box at x 16, the scene of its state: WORK, ASK, REST) with "Lead" (bold) and its status line in the status colour
+// ("working . m:ss" green, "needs you" orange, "stuck" red, "done" grey), a remote Lead adding its owner in a smaller muted line.
+// A Lead that needs you has an 8 px orange inner left edge on the bubble (stuck: red). States of the text: LOADING draws "..." in a bubble of its own; EMPTY draws no
+// bubble, "No message yet" muted in the middle and the pet resting; LOADED the text. A long message shows 7 rows at a time and scrolls by rows (the frame's
+// scroll; a vertical drag, pod_scroll_pitch / pod_scroll_max), the last visible row lighter while more follows. No hit: a tap anywhere talks to a local Lead's
+// harness (the glue), a horizontal swipe steps to the previous / next Lead (pod_nav_act PREV / NEXT). No page dots.
+#include <stdio.h>
+#include <string.h>
+
+#include "pod/home/ph.h"
+#include "pod/pod_draw.h"
+#include "pod/pod_mem.h"
+#include "pod/pod_pet.h"
+#include "pod/pod_view_shared.h"
+#include "pro_canvas.h"
+
+#define C(rgb) ht_rgb(rgb)
+#define ELL "\xe2\x80\xa6"
+enum { BG = PH_ROOM_BG, BX = 60, BW = 600, BY = 150, RAD = 34, PAD_X = 34, PAD_Y = 28, TEXT_W = BW - 2 * PAD_X, PITCH = 46, ROWS_VIS = 7, ROWS_MAX = 64,
+ EDGE = 8, EDGE_W = 120, // the inner edge: a rounded block of this width in the edge colour, the bubble drawn 8 px in over it
+ TAIL_CX = BX + 48 + 18, TAIL_HALF = 24, TAIL_DROP = 23,
+ ROW_GAP = 18, PET_X = 16, PET_SIDE = 150, PET_UP = 10, NAME_X = 160, NAME_MAX_X = 660, HEAD_W = 640,
+ SW_CY = 42, PROJ_CY = 84, NOMSG_CY = 330,
+ EDGE_ASK = 0xFF9A52, EDGE_STUCK = 0xE5484D, SWARM_INK = 0xB79CFF }; // the mockup's #ff9a52 and a red; the Swarm name's purple
+static const ht_pro_font_t *const FONT = &ph_rg_36;
+
+// Word wrap to TEXT_W (ph_recap.c's wrapper, up to ROWS_MAX rows): each row's start offset and byte length (a row is under HT_TEXT_BYTES).
+static int wrap_text(const char *t, uint16_t start[ROWS_MAX], uint8_t len[ROWS_MAX])
+{
+ char buf[HT_TEXT_BYTES];
+ int n = 0;
+ size_t pos = 0, total = strlen(t);
+ while (n < ROWS_MAX) {
+ while (t[pos] == ' ') pos++;
+ if (pos >= total) break;
+ size_t fit = pos, q = pos;
+ for (;;) { // grow the row a word at a time
+ while (t[q] && t[q] != ' ') q++;
+ if (q - pos >= sizeof buf) break;
+ memcpy(buf, t + pos, q - pos); buf[q - pos] = 0;
+ if (ht_pro_width(FONT, buf) > TEXT_W) break;
+ fit = q;
+ if (!t[q]) break;
+ while (t[q] == ' ') q++;
+ }
+ if (fit == pos) { // one word wider than the row: break it at a codepoint
+ size_t m = pos;
+ for (;;) {
+ size_t e = m + 1;
+ while (t[e] && ((unsigned char)t[e] & 0xc0) == 0x80) e++;
+ if (e - pos >= sizeof buf) break;
+ memcpy(buf, t + pos, e - pos); buf[e - pos] = 0;
+ if (ht_pro_width(FONT, buf) > TEXT_W && m > pos) break;
+ m = e;
+ if (!t[m]) break;
+ }
+ fit = m;
+ }
+ if (fit == pos) { // nothing fits (a malformed sequence): skip one code point, never emit an empty row
+ do { pos++; } while (t[pos] && ((unsigned char)t[pos] & 0xc0) == 0x80);
+ continue;
+ }
+ start[n] = (uint16_t)pos;
+ len[n] = (uint8_t)(fit - pos);
+ n++;
+ pos = fit;
+ }
+ return n;
+}
+
+// The message's wrapped rows; pro_app's lock keeps the touch task (pod_scroll_max) and the render task from using them at once. The buffers live in PSRAM (no
+// big stack frame on either task). s_raw is the cache key: the same text is not wrapped again (a pet's frames redraw the screen many times a second).
+static EXT_RAM_BSS_ATTR char s_raw[SWARM_TEXT_MAX + 8], s_text[SWARM_TEXT_MAX + 8];
+static EXT_RAM_BSS_ATTR uint16_t s_start[ROWS_MAX];
+static EXT_RAM_BSS_ATTR uint8_t s_len[ROWS_MAX];
+static int s_rows = -1;
+
+// The Lead's text as it is drawn (control characters as spaces, in s_text) wrapped; returns the row count (0 for no text).
+static int rows_of(const char *text)
+{
+ if (!text) text = "";
+ if (s_rows < 0 || strncmp(text, s_raw, sizeof s_raw - 1) || strlen(text) >= sizeof s_raw - 1) {
+ snprintf(s_raw, sizeof s_raw, "%s", text);
+ memcpy(s_text, s_raw, sizeof s_text);
+ for (char *c = s_text; *c; c++) if ((unsigned char)*c < 0x20) *c = ' ';
+ s_rows = wrap_text(s_text, s_start, s_len);
+ }
+ return s_rows;
+}
+
+int ph_lead_pitch(void) { return PITCH; }
+int ph_lead_max_row(const pod_nav_t *nav, const pod_model_t *m)
+{
+ const pod_lead_t *l = pod_nav_lead(nav, m, NULL);
+ if (!l || l->recap != POD_RECAP_LOADED) return 0;
+ const int rows = rows_of(l->text);
+ return rows > ROWS_VIS ? rows - ROWS_VIS : 0;
+}
+
+// One filled triangle (screen px).
+static void tri(ht_scene_t *s, int x0, int y0, int x1, int y1, int x2, int y2, unsigned rgb)
+{
+ pod_tri(s, x0 * 16, y0 * 16, x1 * 16, y1 * 16, x2 * 16, y2 * 16, C(rgb));
+}
+
+// `src` on one line, control characters as spaces, cut with an ellipsis to w px.
+static void fit_line(char *out, size_t n, const char *src, const ht_pro_font_t *f, int w)
+{
+ snprintf(out, n, "%s", src);
+ for (char *c = out; *c; c++) if ((unsigned char)*c < 0x20) *c = ' ';
+ if (ht_pro_width(f, out) <= w) return;
+ size_t k = strlen(out);
+ for (;;) {
+ char t[HT_TEXT_BYTES];
+ snprintf(t, sizeof t, "%s" ELL, out);
+ if (ht_pro_width(f, t) <= w || !k) { snprintf(out, n, "%s", t); return; }
+ do { k--; } while (k && ((unsigned char)out[k] & 0xc0) == 0x80);
+ out[k] = 0;
+ }
+}
+
+// Centred on x 360, vertically on cy.
+static void centred(ht_scene_t *s, int cy, const ht_pro_font_t *f, unsigned rgb, const char *t)
+{
+ const int w = ht_pro_width(f, t);
+ ph_text(s, (POD_W - w) / 2, cy, w + 2, f, rgb, t);
+}
+
+void ph_view_lead(pod_out_frame_t *f, const pod_nav_t *nav, pod_model_t *m, uint32_t now_ms)
+{
+ ht_scene_t *s = f->scene;
+ s->background = C(BG);
+ const pod_swarm_t *sw = NULL;
+ const pod_lead_t *l = pod_nav_lead(nav, m, &sw);
+ if (!l) return; // the link dropped or the list has not come back: nothing to say yet (the view stays; pod_nav_sync decides when it goes)
+ char line[HT_TEXT_BYTES];
+ fit_line(line, sizeof line, sw->name, &ph_sb_22, HEAD_W);
+ centred(s, SW_CY, &ph_sb_22, SWARM_INK, line);
+ fit_line(line, sizeof line, l->project, &ph_sb_34, HEAD_W);
+ centred(s, PROJ_CY, &ph_sb_34, PH_ROOM_INK, line);
+
+ // The bubble: the text (loaded), "..." (loading) or nothing (no message yet, or not asked yet: the same "..." as loading)
+ const bool empty = l->recap == POD_RECAP_EMPTY, loaded = l->recap == POD_RECAP_LOADED;
+ const int rows = loaded ? rows_of(l->text) : 0;
+ const int vis = loaded ? (rows > ROWS_VIS ? ROWS_VIS : rows) : 1;
+ int first = nav->stack[nav->depth - 1].scroll;
+ if (first > rows - vis) first = rows - vis;
+ if (first < 0) first = 0;
+ const int bh = 2 * PAD_Y + vis * PITCH;
+ int bb = BY + bh; // the bubble's bottom: where the who row hangs from
+ if (empty) bb = BY + 2 * PAD_Y + 4 * PITCH; // no bubble: the row sits where a four-row message's would
+ else {
+ const unsigned fill = PH_LETTER, ink = PH_LETTER_INK;
+ tri(s, TAIL_CX - TAIL_HALF, bb - 1, TAIL_CX + TAIL_HALF, bb - 1, TAIL_CX, bb + TAIL_DROP, fill);
+ const bool edge = l->state == POD_LEAD_ASK || l->state == POD_LEAD_STUCK;
+ if (edge) ht_pro_rect_aa(s, BX, BY, EDGE_W, bh, RAD, C(l->state == POD_LEAD_ASK ? EDGE_ASK : EDGE_STUCK));
+ ht_pro_rect_aa(s, edge ? BX + EDGE : BX, BY, edge ? BW - EDGE : BW, bh, RAD, C(fill));
+ const int lead = (PITCH - FONT->height) / 2;
+ for (int i = 0; i < vis; i++) {
+ char row[HT_TEXT_BYTES];
+ const char *t = ELL;
+ if (loaded) { memcpy(row, s_text + s_start[first + i], s_len[first + i]); row[s_len[first + i]] = 0; t = row; }
+ const bool more = loaded && i == vis - 1 && first + vis < rows; // the last visible row is lighter while the message goes on
+ ht_pro_text(s, BX + PAD_X, BY + PAD_Y + i * PITCH + lead, TEXT_W, FONT, C(more ? PH_LETTER_MORE : ink), t);
+ }
+ }
+ if (empty) centred(s, NOMSG_CY, &ph_sb_34, PH_ROOM_MUTED, "No message yet");
+
+ // The who row: the pet in its state's scene (resting when there is nothing to say), "Lead" and the status line beside it
+ const pod_scene_t scene = empty ? POD_SCENE_REST : ph_lead_scene(l->state);
+ const int pet_y = bb + ROW_GAP - PET_UP, cy = pet_y + PET_SIDE / 2;
+ if (pod_pet_for(l->engine)) pod_pet_draw_flat(s, PET_X, pet_y, PET_SIDE, l->engine, scene, now_ms, 0, BG, 8);
+ else ph_engine_logo(s, PET_X + PET_SIDE / 2 - 36, cy - 36, 72, l->engine, BG);
+ const int max_w = NAME_MAX_X - NAME_X;
+ const bool owner = l->owner[0] != 0;
+ ph_text(s, NAME_X, cy - (owner ? 30 : 17), max_w, &ph_sb_34, PH_ROOM_INK, "Lead");
+ char st[HT_TEXT_BYTES];
+ const unsigned ink = ph_lead_status(l, now_ms, st, sizeof st, ph_mix(0xFFFFFF, BG, 60));
+ ph_text(s, NAME_X, cy + (owner ? 4 : 22), max_w, &ph_sb_22, ink, st);
+ if (owner) { // someone else's machine: whose, small and muted
+ fit_line(line, sizeof line, l->owner, &ph_mono_18, max_w);
+ ph_text(s, NAME_X, cy + 34, max_w, &ph_mono_18, PH_ROOM_MUTED, line);
+ }
+}
+
+uint32_t ph_lead_next_ms(const pod_nav_t *nav, const pod_model_t *m, uint32_t now_ms)
+{
+ const pod_lead_t *l = pod_nav_lead(nav, m, NULL);
+ if (!l) return POD_PET_STEP_MS;
+ uint32_t ms = pod_pet_next_beat_ms(l->engine, l->recap == POD_RECAP_EMPTY ? POD_SCENE_REST : ph_lead_scene(l->state), now_ms, 0);
+ if (ms < POD_PH_ANIM_MS) ms = POD_PH_ANIM_MS - now_ms % POD_PH_ANIM_MS; // a pet redraws a lot: no faster than the Pets beat
+ if (l->state == POD_LEAD_WORK && (l->local[0] || l->since_s)) { // the status line's clock: when its seconds next change
+ const uint32_t into = (int32_t)(now_ms - l->since_at_ms) > 0 ? now_ms - l->since_at_ms : 0, t = 1000 - into % 1000;
+ if (ms > t) ms = t;
+ }
+ return ms;
+}
diff --git a/devices/harness-pro/firmware/main/pod/home/ph_overview.c b/devices/harness-pro/firmware/main/pod/home/ph_overview.c
index 76666bfa5..8cae14d9a 100644
--- a/devices/harness-pro/firmware/main/pod/home/ph_overview.c
+++ b/devices/harness-pro/firmware/main/pod/home/ph_overview.c
@@ -10,6 +10,11 @@
// Working card (the owner's mockup, option D): while an agent works one more card comes after Notices, before tab 0, in Codex's blue
// (the owner's pick): "Working" and the count in ph_bd_84, then up to three pets (their work scene, ink at most 128 px, feet on y 384) with the name and the
// elapsed time under each; the working agents newest first, three to a page (nav->work_page). One POD_A_FOLLOW hit over each pet.
+// Swarm card (the owner's mockup swarm-card.html, built from the Working card's layout): a desk tab linked to a Swarm (pod_model_swarm_for_tab) draws
+// the Swarm instead of its tab card, and a Swarm with no desk tab is one more page after the tabs (pod_home_swarm). Purple #6A4BB0 -> #22163F: the Swarm's name,
+// the number of workspaces in ph_num_230 with "workspaces" beside it (an orange dot pulses before it while a Lead needs you), then the Leads as pets three to
+// a page (nav->swarm_page), centred like Working's, with the project and the status under each: green "working · m:ss", orange "needs you", red "stuck",
+// grey "done"; a Lead on another person's machine adds its owner in a smaller muted line. One POD_A_LEAD hit over each pet (arg = the Lead's index, id = the Swarm's).
// Paging: the TABS frame's scroll is the tab index, POD_HOME_NOTICES the Notices card (only while notices exist) and POD_HOME_WORKING the Working card (only
// while an agent works): the page list is pod_home_pages, so a card coming or going never moves the person to another tab: it only adds or drops a page before
// tab 0 (and when the card shown goes, Home settles on the next page to its right).
@@ -38,17 +43,42 @@ pod_scene_t ph_card_scene(const pod_model_t *m, const pod_agent_t *a)
}
-void ph_card_art(ht_scene_t *s, int cx, int cy, int side, const pod_model_t *m, const pod_agent_t *a, unsigned fill, uint32_t now_ms)
+// An engine's art for `scene` centred on (cx, cy): its pet playing the scene in a side x side square, else its 72 px logo, else a ">_" outline on `fill`.
+static void art_of(ht_scene_t *s, int cx, int cy, int side, const char *engine, pod_scene_t scene, unsigned fill, uint32_t now_ms)
{
- if (pod_pet_for(a->engine)) { // the scene of its state (work, ask, rest), as the agent screen plays it
- pod_pet_draw(s, cx - side / 2, cy - side / 2, side, a->engine, ph_card_scene(m, a), now_ms, 0, 8);
+ if (pod_pet_for(engine)) {
+ pod_pet_draw(s, cx - side / 2, cy - side / 2, side, engine, scene, now_ms, 0, 8);
return;
}
- if (pod_logo_draw(s, cx - LOGO / 2, cy - LOGO / 2, LOGO, a->engine)) return;
+ if (pod_logo_draw(s, cx - LOGO / 2, cy - LOGO / 2, LOGO, engine)) return;
ht_pro_rect_aa_stroke(s, cx - MARK / 2, cy - MARK / 2, MARK, MARK, 16, C(0x8A909A), C(fill));
int w = ht_pro_width(&ph_mono_26, ">_");
ph_text(s, cx - w / 2, cy, w + 2, &ph_mono_26, PH_INK2, ">_");
}
+void ph_card_art(ht_scene_t *s, int cx, int cy, int side, const pod_model_t *m, const pod_agent_t *a, unsigned fill, uint32_t now_ms)
+{
+ art_of(s, cx, cy, side, a->engine, ph_card_scene(m, a), fill, now_ms); // the scene of its state (work, ask, rest), as the agent screen plays it
+}
+
+pod_scene_t ph_lead_scene(pod_lead_state_t st)
+{
+ return st == POD_LEAD_WORK ? POD_SCENE_WORK : st == POD_LEAD_DONE ? POD_SCENE_REST : POD_SCENE_ASK;
+}
+
+// A Lead's status line ("working · m:ss", "needs you", "stuck", "done") and its colour; `dim` is the colour of "done" (white at 60 % over whatever the line is on).
+unsigned ph_lead_status(const pod_lead_t *l, uint32_t now_ms, char *line, size_t n, unsigned dim)
+{
+ if (l->state == POD_LEAD_ASK) { snprintf(line, n, "needs you"); return PH_LEAD_ASK; }
+ if (l->state == POD_LEAD_STUCK) { snprintf(line, n, "stuck"); return PH_LEAD_STUCK; }
+ if (l->state == POD_LEAD_DONE) { snprintf(line, n, "done"); return dim; }
+ if (l->local[0] || l->since_s) { // working: a local Lead's turn runs on (a remote one has no clock)
+ char t[24];
+ const uint32_t into = (int32_t)(now_ms - l->since_at_ms) > 0 ? (now_ms - l->since_at_ms) / 1000 : 0;
+ pod_fmt_elapsed(t, sizeof t, (int64_t)l->since_s + into);
+ snprintf(line, n, "working \xc2\xb7 %s", t);
+ } else snprintf(line, n, "working");
+ return PH_LEAD_WORK;
+}
// What Home shows: the top frame's scroll (a TAB frame, which Pets never reaches, shows its own tab), clamped to the page list (pod_home_pages): the tab
@@ -94,6 +124,11 @@ bool ph_home_moves(const pod_nav_t *nav, const pod_model_t *m)
if (t == HOME_NONE) return true; // the first screen's shimmer and bar
if (t == POD_HOME_WORKING) return true; // the pets
if (t < 0) return false; // the Notices card is still
+ const pod_swarm_t *sw = pod_home_swarm(m, t);
+ if (sw) { // a Swarm card: a working Lead's pet and clock, a Lead that needs you
+ for (int j = 0; j < sw->lead_n && j < SWARM_LEADS_MAX; j++) if (sw->leads[j].state == POD_LEAD_WORK || sw->leads[j].state == POD_LEAD_ASK) return true;
+ return false;
+ }
tab_agents(m, t, &working);
return working > 0 || tab_asking(m, t) > 0;
}
@@ -398,6 +433,28 @@ static void card(pod_out_frame_t *f, const pod_model_t *m, int t, int x, int y,
// The Working card (see the header). A neighbour (full false) is the faded gradient and "Working", like a tab's.
enum { WK_TITLE_Y = 80, WK_SLOT_PITCH = 165, WK_FEET = 384, WK_INK = 128, WK_SIDE = WK_INK + 6, WK_NAME_Y = 422 - 7, WK_TIME_Y = 456 - 7, // the mockup's tops are the glyphs' ink; a text run starts 7 px above that
WK_NAME_W = 158, WK_PER_PAGE = 3, WK_SHADOW_H = 14, WK_HIT_Y = 200, WK_HIT_W = 150, WK_HIT_H = 280 };
+// One row of up to three pets standing on a card, centred on it (one or two sit in the middle, not in the first slots), each with its shadow, feet on y + feet.
+// Claude's work scenes are wide and draw small in a `side` square, so its square is twice as big (the owner's pick). The scenes are played for `now_ms`; a
+// pet-less engine shows its logo on the same line. Each pet's centre is left in cx[k] for the text and the hit under it.
+static void pet_at(ht_scene_t *s, int y, int h, unsigned c1, unsigned c2, int feet, int side0, int cx, const char *engine, pod_scene_t scene, uint32_t now_ms)
+{
+ const int side = !strcmp(engine, "claude") ? 2 * side0 : side0;
+ const int ink = pod_pet_ink_h(engine, scene, side, 8);
+ const int shw = (ink ? ink : LOGO) * 4 / 5; // ponytail: the shadow follows the ink's height (the pets are about as wide as tall); a measured width if one ever looks off
+ ht_pro_rect_aa(s, cx - shw / 2, y + feet - 6, shw, WK_SHADOW_H, WK_SHADOW_H / 2, C(ph_mix(0x000000, c2, 35)));
+ const int cy = y + feet - (ink ? ink : LOGO) / 2; // a pet-less engine: its logo, feet on the same line
+ if (pod_pet_for(engine)) // the gradient is slow: its colour at the pet's centre is the ground, so each frame is resampled once (baked) and then copied
+ pod_pet_draw_flat(s, cx - side / 2, cy - side / 2, side, engine, scene, now_ms, 0, ph_mix(c1, c2, (unsigned)((cy - y) * 100 / h)), 8);
+ else art_of(s, cx, cy, side0, engine, scene, ph_mix(c1, c2, 60), now_ms);
+}
+static void pet_row(ht_scene_t *s, int x, int y, int w, int h, unsigned c1, unsigned c2, int feet, int side0, int shown, const char *const *engine, const pod_scene_t *scene, int *cx, uint32_t now_ms)
+{
+ for (int k = 0; k < shown; k++) {
+ cx[k] = x + w / 2 + (2 * k - (shown - 1)) * WK_SLOT_PITCH / 2;
+ pet_at(s, y, h, c1, c2, feet, side0, cx[k], engine[k], scene[k], now_ms);
+ }
+}
+
static void working_card(pod_out_frame_t *f, const pod_nav_t *nav, const pod_model_t *m, int x, int y, int w, int h, int r, int fade, bool full, uint32_t now_ms)
{
ht_scene_t *s = f->scene;
@@ -417,24 +474,95 @@ static void working_card(pod_out_frame_t *f, const pod_nav_t *nav, const pod_mod
ph_text(s, x + NAME_X, y + WK_TITLE_Y, 260, &ph_sb_48, PH_CARD_INK, "Working");
snprintf(txt, sizeof txt, "%d", n);
ph_text(s, x + 496 - ht_pro_width(&ph_bd_84, txt), y + WK_TITLE_Y, ht_pro_width(&ph_bd_84, txt) + 2, &ph_bd_84, PH_CARD_INK, txt); // the count in the bold face (its digits are baked)
- for (int k = 0; k < WK_PER_PAGE && page * WK_PER_PAGE + k < n; k++) {
+ const int shown = n - page * WK_PER_PAGE < WK_PER_PAGE ? n - page * WK_PER_PAGE : WK_PER_PAGE;
+ const char *engine[WK_PER_PAGE] = {0};
+ pod_scene_t scene[WK_PER_PAGE] = {0};
+ int cx[WK_PER_PAGE] = {0};
+ for (int k = 0; k < shown; k++) { engine[k] = list[page * WK_PER_PAGE + k]->engine; scene[k] = ph_card_scene(m, list[page * WK_PER_PAGE + k]); }
+ pet_row(s, x, y, w, h, c1, c2, WK_FEET, WK_SIDE, shown, engine, scene, cx, now_ms);
+ for (int k = 0; k < shown; k++) {
const pod_agent_t *a = list[page * WK_PER_PAGE + k];
- // The page's pets centred on the card (one or two sit in the middle, not in the first slots); Claude's work scenes are wide and draw
- // small in a WK_SIDE square, so its square is twice as big (the owner's pick)
- const int shown = n - page * WK_PER_PAGE < WK_PER_PAGE ? n - page * WK_PER_PAGE : WK_PER_PAGE;
- const int side = !strcmp(a->engine, "claude") ? 2 * WK_SIDE : WK_SIDE;
- const int cx = x + w / 2 + (2 * k - (shown - 1)) * WK_SLOT_PITCH / 2, ink = pod_pet_ink_h(a->engine, ph_card_scene(m, a), side, 8);
- const int sw = (ink ? ink : LOGO) * 4 / 5; // ponytail: the shadow follows the ink's height (the pets are about as wide as tall); a measured width if one ever looks off
- ht_pro_rect_aa(s, cx - sw / 2, y + WK_FEET - 6, sw, WK_SHADOW_H, WK_SHADOW_H / 2, C(ph_mix(0x000000, c2, 35)));
- const int cy = y + WK_FEET - (ink ? ink : LOGO) / 2; // a pet-less engine: its logo, feet on the same line
- if (pod_pet_for(a->engine)) // the gradient is slow: its colour at the pet's centre is the ground, so each frame is resampled once (baked) and then copied
- pod_pet_draw_flat(s, cx - side / 2, cy - side / 2, side, a->engine, ph_card_scene(m, a), now_ms, 0, ph_mix(c1, c2, (unsigned)((cy - y) * 100 / h)), 8);
- else ph_card_art(s, cx, cy, WK_SIDE, m, a, ph_mix(c1, c2, 60), now_ms);
shown_name(txt, sizeof txt, a->name, WK_NAME_W, &ph_sb_22);
- ht_pro_text(s, cx - ht_pro_width(&ph_sb_22, txt) / 2, y + WK_NAME_Y, ht_pro_width(&ph_sb_22, txt) + 2, &ph_sb_22, C(PH_CARD_INK), txt);
+ ht_pro_text(s, cx[k] - ht_pro_width(&ph_sb_22, txt) / 2, y + WK_NAME_Y, ht_pro_width(&ph_sb_22, txt) + 2, &ph_sb_22, C(PH_CARD_INK), txt);
pod_fmt_elapsed(txt, sizeof txt, pod_agent_secs(a, now_ms));
- ht_pro_text(s, cx - ht_pro_width(&ph_sb_22, txt) / 2, y + WK_TIME_Y, ht_pro_width(&ph_sb_22, txt) + 2, &ph_sb_22, C(PH_PILL_WORK), txt);
- pod_hit_add_id(f, cx - WK_HIT_W / 2, y + WK_HIT_Y, WK_HIT_W, WK_HIT_H, POD_A_FOLLOW, (int)(a - m->agents), a->id);
+ ht_pro_text(s, cx[k] - ht_pro_width(&ph_sb_22, txt) / 2, y + WK_TIME_Y, ht_pro_width(&ph_sb_22, txt) + 2, &ph_sb_22, C(PH_PILL_WORK), txt);
+ pod_hit_add_id(f, cx[k] - WK_HIT_W / 2, y + WK_HIT_Y, WK_HIT_W, WK_HIT_H, POD_A_FOLLOW, (int)(a - m->agents), a->id);
+ }
+}
+
+// The Swarm card (see the header). A neighbour (full false) is the faded gradient and the Swarm's name, like a tab's.
+enum { SW_PEEK_SHOW = 56, SW_PEEK_FADE = 102, SW_FEET = 424, SW_SIDE = 118, SW_NAME_Y = SW_FEET + 31, SW_STATE_Y = SW_FEET + 65, SW_OWNER_Y = SW_FEET + 95, SW_DOT = 14, SW_HIT_Y = 300, SW_HIT_H = 250 };
+// Centred on cx, the run's top at y.
+static void centred(ht_scene_t *s, int cx, int y, const ht_pro_font_t *f, unsigned rgb, const char *t)
+{
+ ht_pro_text(s, cx - ht_pro_width(f, t) / 2, y, ht_pro_width(f, t) + 2, f, C(rgb), t);
+}
+static void swarm_card(pod_out_frame_t *f, const pod_nav_t *nav, const pod_swarm_t *sw, int x, int y, int w, int h, int r, int fade, bool full, uint32_t now_ms)
+{
+ ht_scene_t *s = f->scene;
+ unsigned c1 = PH_SWARM1, c2 = PH_SWARM2;
+ if (fade) { c1 = ph_mix(c1, PH_HOME_BG, (unsigned)fade); c2 = ph_mix(c2, PH_HOME_BG, (unsigned)fade); }
+ pod_grad_aa_dither(s, x, y, w, h, r, C(c1), C(c2));
+ char name[CABLE_NAME_MAX + 4];
+ const ht_pro_font_t *nf = shown_name(name, sizeof name, sw->name, full ? NAME_W : NAME_W * PEEK_PCT / 100, full ? NULL : &ph_sb_34);
+ const int nx = x + (full ? NAME_X : NAME_X * PEEK_PCT / 100), nw = ht_pro_width(nf, name);
+ if (!full) { // a neighbour: the name only, faded
+ if (nx < POD_W && nx + nw > 0) ht_pro_text(s, nx, y + 40 * PEEK_PCT / 100, nw + 2, nf, C(ph_mix(PH_CARD_INK, c1, 80)), name);
+ return;
+ }
+ ph_text(s, nx, y + NAME_Y + nf->height / 2, NAME_W, nf, PH_CARD_INK, name);
+
+ // the number of workspaces and its label, as a tab card's agent count, with an orange dot pulsing before the label while a Lead needs you
+ bool ask = false;
+ for (int j = 0; j < sw->lead_n && j < SWARM_LEADS_MAX; j++) ask |= sw->leads[j].state == POD_LEAD_ASK;
+ char txt[CABLE_NAME_MAX + 4];
+ snprintf(txt, sizeof txt, "%d", sw->count);
+ const int cw = ht_pro_width(&ph_num_230, txt);
+ ht_pro_text(s, x + NUM_X, y + NUM_TOP, cw + 2, &ph_num_230, C(PH_CARD_INK), txt);
+ const unsigned ground = ph_mix(c1, c2, 100 - NUM_BASE * 100 / h);
+ int lx = x + NUM_X + cw + LABEL_GAP;
+ if (ask) {
+ ht_pro_rect_aa(s, lx, y + NUM_BASE - 17, SW_DOT, SW_DOT, SW_DOT / 2, C(ph_mix(PH_LEAD_ASK, ground, 25 + 75 * (unsigned)tri(now_ms, 1200) / 100)));
+ lx += SW_DOT + 12;
+ }
+ on_baseline(s, lx, y + NUM_BASE, &ph_sb_26, ph_mix(0xFFFFFF, ground, 85), sw->count == 1 ? "workspace" : "workspaces");
+
+ // the Leads, three to a page
+ const int pages = (sw->lead_n + WK_PER_PAGE - 1) / WK_PER_PAGE;
+ const int page = nav->swarm_page < pages ? nav->swarm_page : pages > 0 ? pages - 1 : 0;
+ const int first = page * WK_PER_PAGE, shown = sw->lead_n - first < WK_PER_PAGE ? sw->lead_n - first : WK_PER_PAGE;
+ const char *engine[WK_PER_PAGE] = {0};
+ pod_scene_t scene[WK_PER_PAGE] = {0};
+ int cx[WK_PER_PAGE] = {0};
+ for (int k = 0; k < shown; k++) { engine[k] = sw->leads[first + k].engine; scene[k] = ph_lead_scene(sw->leads[first + k].state); }
+ // the page's neighbour Lead peeks in at the card's edge (the next page's first at the right, the previous page's last at the left): faded, clipped to
+ // the card by a veil (it paints the ground over what spilled past the edge), no text. Drawn first so the page's own pets stand over it.
+ for (int side = -1; side <= 1; side += 2) {
+ if (side > 0 ? first + shown >= sw->lead_n : page == 0) continue;
+ const pod_lead_t *l = &sw->leads[side > 0 ? first + shown : first - 1];
+ const pod_scene_t sc = ph_lead_scene(l->state);
+ const int sd = !strcmp(l->engine, "claude") ? 2 * SW_SIDE : SW_SIDE;
+ const int cxp = side > 0 ? x + w - SW_PEEK_SHOW + sd / 2 : x + SW_PEEK_SHOW - sd / 2;
+ const int ink = pod_pet_ink_h(l->engine, sc, sd, 8), top = y + SW_FEET - (ink ? ink : LOGO) - 12;
+ pet_at(s, y, h, c1, c2, SW_FEET, SW_SIDE, cxp, l->engine, sc, now_ms);
+ const int vx = side > 0 ? x + w - SW_PEEK_SHOW - 4 : x - sd, vw = SW_PEEK_SHOW + 4 + sd;
+ pod_veil(s, vx, top, vw, y + SW_FEET + WK_SHADOW_H - top, side > 0 ? x + w : x, side > 0, y, h, C(c1), C(c2), C(PH_HOME_BG), SW_PEEK_FADE);
+ }
+ pet_row(s, x, y, w, h, c1, c2, SW_FEET, SW_SIDE, shown, engine, scene, cx, now_ms);
+ for (int k = 0; k < shown; k++) {
+ const pod_lead_t *l = &sw->leads[first + k];
+ shown_name(txt, sizeof txt, l->project, WK_NAME_W, &ph_sb_22);
+ centred(s, cx[k], y + SW_NAME_Y, &ph_sb_22, PH_CARD_INK, txt);
+ const unsigned dim = ph_mix(0xFFFFFF, ph_mix(c1, c2, 100 - (SW_STATE_Y + 11) * 100 / h), 60); // white at 60 % over the card
+ char line[CABLE_NAME_MAX + 4];
+ const unsigned ink = ph_lead_status(l, now_ms, line, sizeof line, dim);
+ shown_name(txt, sizeof txt, line, WK_NAME_W + 6, &ph_sb_22);
+ centred(s, cx[k], y + SW_STATE_Y, &ph_sb_22, ink, txt);
+ if (l->owner[0]) { // someone else's machine: whose, small and muted
+ shown_name(txt, sizeof txt, l->owner, WK_NAME_W, &ph_mono_18);
+ centred(s, cx[k], y + SW_OWNER_Y, &ph_mono_18, ph_mix(0xFFFFFF, ph_mix(c1, c2, 100 - (SW_OWNER_Y + 12) * 100 / h), 55), txt);
+ }
+ pod_hit_add_id(f, cx[k] - WK_HIT_W / 2, y + SW_HIT_Y, WK_HIT_W, SW_HIT_H, POD_A_LEAD, first + k, sw->id);
}
}
@@ -443,6 +571,7 @@ static void peek(pod_out_frame_t *f, const pod_nav_t *nav, const pod_model_t *m,
{
if (p == POD_HOME_NOTICES) notices_card(f, m, x, y, w, h, r, PEEK_FADE, false);
else if (p == POD_HOME_WORKING) working_card(f, nav, m, x, y, w, h, r, PEEK_FADE, false, now_ms);
+ else if (p >= 0 && pod_home_swarm(m, p)) swarm_card(f, nav, pod_home_swarm(m, p), x, y, w, h, r, PEEK_FADE, false, now_ms);
else if (p >= 0) card(f, m, p, x, y, w, h, r, PEEK_FADE, false, now_ms);
}
@@ -455,13 +584,18 @@ void ph_view_home(pod_out_frame_t *f, const pod_nav_t *nav, pod_model_t *m, uint
const int pw = CARD_W * PEEK_PCT / 100, ph = CARD_H * PEEK_PCT / 100, py = CARD_Y + CARD_H / 2 - ph / 2;
const int lx = CARD_X + CARD_W / 2 - PEEK_DX - pw / 2, rx = CARD_X + CARD_W / 2 + PEEK_DX - pw / 2, pr = CARD_R * PEEK_PCT / 100;
// The page t's neighbours are the adjacent entries of the page list.
- int16_t pg[POD_TABS_MAX + 2];
- const int n = pod_home_pages(m, pg, POD_TABS_MAX + 2);
+ int16_t pg[POD_HOME_PAGES_MAX];
+ const int n = pod_home_pages(m, pg, POD_HOME_PAGES_MAX);
int at = 0;
while (at < n - 1 && pg[at] < t) at++;
const int prev = at > 0 ? pg[at - 1] : HOME_NONE, next = at + 1 < n ? pg[at + 1] : HOME_NONE;
- peek(f, nav, m, prev, lx, py, pw, ph, pr, now_ms);
- peek(f, nav, m, next, rx, py, pw, ph, pr, now_ms);
+ const pod_swarm_t *own = t >= 0 ? pod_home_swarm(m, t) : NULL;
+ // A Swarm card with a Lead peeking in clips it with a veil over the neighbours' side, so the neighbours are drawn after it (2 px further out, clear of its edge).
+ const bool after = own && own->lead_n > WK_PER_PAGE && t != POD_HOME_WORKING && t != POD_HOME_NOTICES;
+ if (!after) {
+ peek(f, nav, m, prev, lx, py, pw, ph, pr, now_ms);
+ peek(f, nav, m, next, rx, py, pw, ph, pr, now_ms);
+ }
if (t == POD_HOME_WORKING) {
working_card(f, nav, m, CARD_X, CARD_Y, CARD_W, CARD_H, CARD_R, 0, true, now_ms);
return;
@@ -471,6 +605,15 @@ void ph_view_home(pod_out_frame_t *f, const pod_nav_t *nav, pod_model_t *m, uint
pod_hit_add(f, CARD_X, CARD_Y, CARD_W, CARD_H, POD_A_INBOX, 0);
return;
}
+ const pod_swarm_t *sw = pod_home_swarm(m, t);
+ if (sw) { // a Swarm's card: its own page, or in place of its desk tab's
+ swarm_card(f, nav, sw, CARD_X, CARD_Y, CARD_W, CARD_H, CARD_R, 0, true, now_ms);
+ if (after) {
+ peek(f, nav, m, prev, lx - 2, py, pw, ph, pr, now_ms);
+ peek(f, nav, m, next, rx + 2, py, pw, ph, pr, now_ms);
+ }
+ return;
+ }
card(f, m, t, CARD_X, CARD_Y, CARD_W, CARD_H, CARD_R, 0, true, now_ms);
if (tab_agents(m, t, NULL) > 0) pod_hit_add_id(f, CARD_X, CARD_Y, CARD_W, CARD_H, POD_A_ENTER_TAB, t, m->tabs[t].id);
}
diff --git a/devices/harness-pro/firmware/main/pod/home/ph_view.c b/devices/harness-pro/firmware/main/pod/home/ph_view.c
index a7c9575eb..b7d5b3bdf 100644
--- a/devices/harness-pro/firmware/main/pod/home/ph_view.c
+++ b/devices/harness-pro/firmware/main/pod/home/ph_view.c
@@ -13,4 +13,5 @@ void ph_render(pod_out_frame_t *f, const pod_nav_t *nav, pod_model_t *m, uint32_
else if (top->view == POD_V_RECAP) ph_view_recap(f, nav, m, now_ms);
else if (top->view == POD_V_TALK) ph_view_talk(f, nav, m, now_ms);
else if (top->view == POD_V_INBOX) ph_view_inbox(f, nav, m, now_ms);
+ else if (top->view == POD_V_LEAD) ph_view_lead(f, nav, m, now_ms);
}
diff --git a/devices/harness-pro/firmware/main/pod/pod_draw.c b/devices/harness-pro/firmware/main/pod/pod_draw.c
index 5d8055644..4af5e8005 100644
--- a/devices/harness-pro/firmware/main/pod/pod_draw.c
+++ b/devices/harness-pro/firmware/main/pod/pod_draw.c
@@ -513,6 +513,33 @@ void pod_grad_aa_dither(ht_scene_t *s, int x, int y, int w, int h, int radius, u
grad_params_t p = {top, bottom, 3};
memcpy(r->text, &p, sizeof p);
}
+typedef struct { uint16_t top, bottom, bg; int16_t edge, gy0, gh; uint8_t k, inside_left; } veil_params_t;
+_Static_assert(sizeof(veil_params_t) <= HT_TEXT_BYTES, "veil parameters fit run->text");
+void pod_veil(ht_scene_t *s, int x, int y, int w, int h, int edge, bool inside_left, int gy0, int gh, uint16_t top, uint16_t bottom, uint16_t bg, unsigned k)
+{
+ if (w <= 0 || h <= 0) return;
+ ht_run_t *r = new_run(s, POD_VEIL, x, y, w, h);
+ if (!r) return;
+ veil_params_t p = {top, bottom, bg, (int16_t)edge, (int16_t)gy0, (int16_t)gh, (uint8_t)imin(255, (int)k), inside_left};
+ memcpy(r->text, &p, sizeof p);
+}
+static void veil_raster(const ht_run_t *r, ht_rect_t clip, uint16_t *out)
+{
+ veil_params_t p;
+ memcpy(&p, r->text, sizeof p);
+ int x0 = imax(clip.x, r->x), x1 = imin(clip.x + clip.w, r->x + r->w);
+ int y0 = imax(clip.y, r->y), y1 = imin(clip.y + clip.h, r->y + r->pro_height);
+ const int last = p.gh > 1 ? p.gh - 1 : 1;
+ for (int y = y0; y < y1; y++) {
+ const int row = imin(imax(y - p.gy0, 0), last);
+ const uint16_t ink = mix565(p.bottom, p.top, (unsigned)row, (unsigned)last);
+ uint16_t *d = out + (y - clip.y) * clip.w - clip.x;
+ for (int x = x0; x < x1; x++) {
+ const bool in = p.inside_left ? x < p.edge : x >= p.edge;
+ d[x] = in ? mix565(ink, d[x], p.k, 255) : p.bg;
+ }
+ }
+}
static void grad_raster(const ht_run_t *r, ht_rect_t clip, uint16_t *out)
{
grad_params_t p;
@@ -653,6 +680,7 @@ void pod_draw_raster(const ht_run_t *r, ht_rect_t clip, uint16_t *out)
case POD_ARC: arc_raster(r, clip, out); break;
case POD_GRAD: grad_raster(r, clip, out); break;
case POD_TRI: tri_raster(r, clip, out); break;
+ case POD_VEIL: veil_raster(r, clip, out); break;
default: break;
}
}
diff --git a/devices/harness-pro/firmware/main/pod/pod_draw.h b/devices/harness-pro/firmware/main/pod/pod_draw.h
index c2e731244..cf77d5f45 100644
--- a/devices/harness-pro/firmware/main/pod/pod_draw.h
+++ b/devices/harness-pro/firmware/main/pod/pod_draw.h
@@ -3,7 +3,7 @@
// Pro runs (ht_run_t.pro_kind >= POD_KIND_BASE) that ht_pro_raster hands to pod_draw_raster.
#include "pod_types.h"
-enum { POD_KIND_BASE = 16, POD_CELL = 16, POD_ARC, POD_GRAD, POD_TRI };
+enum { POD_KIND_BASE = 16, POD_CELL = 16, POD_ARC, POD_GRAD, POD_TRI, POD_VEIL };
// A dial pet frame at (x, y). zoom is in eighths (8 = 1x, 16 = an exact 2x nearest-neighbour scale, 9..15 and >16 clamp to 1x, 0 draws nothing); the frame pointer
// and zoom live in the run so a new frame changes the picture's bytes.
@@ -37,4 +37,8 @@ bool pod_tri(ht_scene_t *s, int x0, int y0, int x1, int y1, int x2, int y2, uint
// but bleeds a pixel outward, so two triangles that share it leave no seam (anti-aliasing both sides of a shared
// edge composites to only 75% along it). Use it only for edges that lie inside the figure.
bool pod_tri_inner(ht_scene_t *s, int x0, int y0, int x1, int y1, int x2, int y2, uint16_t ink, unsigned inner);
+// A veil over what is already drawn in the rect, to clip and fade a neighbour peeking in at a card's edge: the part on the card's side of the line
+// x = edge (the left of it when inside_left, else the right) is mixed `k` of 255 toward the card's vertical gradient (top at row gy0, bottom gh rows
+// further down), the rest is painted `bg`, which clips whatever spilled past the card. One run; the rect's rows must be clear of the card's corners.
+void pod_veil(ht_scene_t *s, int x, int y, int w, int h, int edge, bool inside_left, int gy0, int gh, uint16_t top, uint16_t bottom, uint16_t bg, unsigned k);
void pod_draw_raster(const ht_run_t *r, ht_rect_t clip, uint16_t *out);
diff --git a/devices/harness-pro/firmware/main/pod/pod_mem.h b/devices/harness-pro/firmware/main/pod/pod_mem.h
index f5972076f..0d33c6723 100644
--- a/devices/harness-pro/firmware/main/pod/pod_mem.h
+++ b/devices/harness-pro/firmware/main/pod/pod_mem.h
@@ -6,3 +6,16 @@
#else
#define EXT_RAM_BSS_ATTR
#endif
+
+// A heap block for text that lives a while (a Lead's cached recap): PSRAM on the device, malloc on the host. NULL when out of memory.
+#include <stdlib.h>
+#ifdef ESP_PLATFORM
+#include "esp_heap_caps.h"
+static inline void *pod_big_alloc(size_t n) {
+ void *p = heap_caps_malloc(n, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
+ return p ? p : malloc(n); // free() takes either
+}
+#else
+extern int pod_big_alloc_fail; // host tests only: while set, pod_big_alloc reports out of memory
+static inline void *pod_big_alloc(size_t n) { return pod_big_alloc_fail ? NULL : malloc(n); }
+#endif
diff --git a/devices/harness-pro/firmware/main/pod/pod_model.c b/devices/harness-pro/firmware/main/pod/pod_model.c
index d31043e4c..eb87c557f 100644
--- a/devices/harness-pro/firmware/main/pod/pod_model.c
+++ b/devices/harness-pro/firmware/main/pod/pod_model.c
@@ -34,7 +34,8 @@ static bool same(const char *a, const char *b) { return a && b && !strcmp(a, b);
// ── model ────────────────────────────────────────────────────────────────────────────────────────────
-void pod_model_reset(pod_model_t *m) { memset(m, 0, sizeof *m); }
+static void swarms_free(pod_model_t *m);
+void pod_model_reset(pod_model_t *m) { swarms_free(m); memset(m, 0, sizeof *m); }
static uint32_t (*s_random)(void);
void pod_model_random(uint32_t (*rnd)(void)) { s_random = rnd; }
@@ -709,10 +710,171 @@ void pod_model_link(pod_model_t *m, bool up) {
m->agents[i].super_tab[0] = 0;
m->agents[i].attention = POD_ATTN_NONE;
}
+ swarms_free(m); // the daemon sends the Swarm list again on the next link, and the open recap is asked for again
+ m->swarm_n = 0;
+ m->want_n = 0;
+ m->swarm_ids = false;
+ m->focus_pending = false;
}
m->revision++;
}
+// ---- the Swarm cards ----
+#include "pod/pod_mem.h" // pod_big_alloc: a Lead's recap text lives in PSRAM
+#ifndef ESP_PLATFORM
+int pod_big_alloc_fail;
+#endif
+
+static void lead_free_text(pod_lead_t *l) { free(l->text); l->text = NULL; }
+static void swarms_free(pod_model_t *m) {
+ for (int i = 0; i < m->swarm_n && i < SWARMS_CARD_MAX; i++)
+ for (int j = 0; j < m->swarms[i].lead_n && j < SWARM_LEADS_MAX; j++) lead_free_text(&m->swarms[i].leads[j]);
+}
+
+int pod_model_lead_index(const pod_swarm_t *s, const char *lead_id) {
+ if (!s || !lead_id || !*lead_id) return -1;
+ for (int j = 0; j < s->lead_n; j++)
+ if (!strcmp(s->leads[j].id, lead_id)) return j;
+ return -1;
+}
+
+const pod_swarm_t *pod_model_swarm(const pod_model_t *m, const char *swarm_id) {
+ if (!swarm_id || !*swarm_id) return NULL;
+ for (int i = 0; i < m->swarm_n; i++)
+ if (!strcmp(m->swarms[i].id, swarm_id)) return &m->swarms[i];
+ return NULL;
+}
+
+const pod_swarm_t *pod_model_swarm_for_tab(const pod_model_t *m, const char *tab_id) {
+ if (!tab_id || !*tab_id) return NULL;
+ for (int i = 0; i < m->swarm_n; i++)
+ if (!strcmp(m->swarms[i].tab, tab_id)) return &m->swarms[i];
+ return NULL;
+}
+
+static int want_idx(const pod_model_t *m, const char *id) {
+ for (int i = 0; i < m->want_n; i++)
+ if (!strcmp(m->want[i], id)) return i;
+ return -1;
+}
+
+void pod_model_supertab_ids(pod_model_t *m, const char (*ids)[ID_MAX], int n) {
+ static EXT_RAM_BSS_ATTR pod_swarm_t tmp; // one Swarm (3 KB) is too much for the cable_link stack
+ if (!ids || n < 0) n = 0;
+ m->swarm_ids = true;
+ m->want_n = 0;
+ for (int i = 0; i < n && m->want_n < SWARMS_CARD_MAX; i++) {
+ if (!ids[i][0] || memchr(ids[i], 0, ID_MAX) == NULL || want_idx(m, ids[i]) >= 0) continue;
+ memcpy(m->want[m->want_n++], ids[i], ID_MAX);
+ }
+ int k = 0; // keep the listed ones, free the rest
+ for (int i = 0; i < m->swarm_n; i++) {
+ if (want_idx(m, m->swarms[i].id) < 0) {
+ for (int j = 0; j < m->swarms[i].lead_n; j++) lead_free_text(&m->swarms[i].leads[j]);
+ continue;
+ }
+ if (k != i) m->swarms[k] = m->swarms[i]; // ownership of the texts moves with the struct
+ k++;
+ }
+ if (k < m->swarm_n) memset(&m->swarms[k], 0, (size_t)(m->swarm_n - k) * sizeof m->swarms[0]);
+ m->swarm_n = (uint8_t)k;
+ for (int t = 0; t < m->swarm_n; t++) { // selection sort by the list's order
+ int best = t;
+ for (int i = t + 1; i < m->swarm_n; i++)
+ if (want_idx(m, m->swarms[i].id) < want_idx(m, m->swarms[best].id)) best = i;
+ if (best == t) continue;
+ tmp = m->swarms[t]; m->swarms[t] = m->swarms[best]; m->swarms[best] = tmp;
+ }
+ m->revision++;
+}
+
+void pod_model_supertab(pod_model_t *m, const pod_swarm_t *s, uint32_t now_ms) {
+ if (!s || !s->id[0]) return;
+ const int w = want_idx(m, s->id);
+ if (w < 0) return; // not in the last id list (the list comes first)
+ pod_model_clock(m, now_ms);
+ int at = -1;
+ for (int i = 0; i < m->swarm_n; i++)
+ if (!strcmp(m->swarms[i].id, s->id)) at = i;
+ if (at < 0) { // new: slot it in before the first received Swarm that the list puts after it
+ at = m->swarm_n;
+ for (int i = 0; i < m->swarm_n; i++)
+ if (want_idx(m, m->swarms[i].id) > w) { at = i; break; }
+ if (m->swarm_n >= SWARMS_CARD_MAX) return;
+ memmove(&m->swarms[at + 1], &m->swarms[at], (size_t)(m->swarm_n - at) * sizeof m->swarms[0]);
+ memset(&m->swarms[at], 0, sizeof m->swarms[0]);
+ m->swarm_n++;
+ }
+ pod_swarm_t *d = &m->swarms[at];
+ struct { pod_recap_state_t recap; char *text; uint32_t text_at; } carry[SWARM_LEADS_MAX];
+ memset(carry, 0, sizeof carry);
+ const int ln = s->lead_n > SWARM_LEADS_MAX ? SWARM_LEADS_MAX : s->lead_n;
+ for (int j = 0; j < ln; j++) {
+ const int k = pod_model_lead_index(d, s->leads[j].id);
+ if (k < 0) continue;
+ pod_lead_t *ol = &d->leads[k]; // taken over: the old copy no longer owns the text
+ carry[j].recap = ol->recap; carry[j].text = ol->text; carry[j].text_at = ol->text_at;
+ ol->text = NULL;
+ }
+ for (int j = 0; j < d->lead_n; j++) lead_free_text(&d->leads[j]); // the ones that left
+ *d = *s;
+ d->lead_n = (uint8_t)ln;
+ for (int j = 0; j < SWARM_LEADS_MAX; j++) {
+ pod_lead_t *l = &d->leads[j];
+ if (j >= ln) { memset(l, 0, sizeof *l); continue; }
+ l->text = carry[j].text;
+ l->recap = carry[j].recap;
+ l->text_at = carry[j].text_at;
+ l->since_at_ms = now_ms;
+ }
+ m->revision++;
+}
+
+void pod_model_supertab_recap(pod_model_t *m, const char *tab, const char *lead, const char *text, uint32_t at, bool none) {
+ const pod_swarm_t *s = pod_model_swarm(m, tab);
+ const int j = pod_model_lead_index(s, lead);
+ if (j < 0) return;
+ pod_lead_t *l = &((pod_swarm_t *)s)->leads[j];
+ if (l->recap == POD_RECAP_NONE) return; // a Lead nobody asked for or has left: a late reply would only sit there stale
+ lead_free_text(l);
+ l->text_at = at;
+ if (none || !text) {
+ l->recap = POD_RECAP_EMPTY;
+ } else {
+ l->text = pod_big_alloc(SWARM_TEXT_MAX);
+ if (!l->text) { l->recap = POD_RECAP_LOADING; m->revision++; return; } // out of memory: still waiting, so the retry asks again
+ pod_copy_str(l->text, SWARM_TEXT_MAX, text);
+ l->recap = POD_RECAP_LOADED;
+ }
+ m->revision++;
+}
+
+void pod_model_supertab_loading(pod_model_t *m, const char *tab, const char *lead) {
+ const pod_swarm_t *s = pod_model_swarm(m, tab);
+ const int j = pod_model_lead_index(s, lead);
+ if (j < 0 || s->leads[j].recap != POD_RECAP_NONE) return;
+ ((pod_swarm_t *)s)->leads[j].recap = POD_RECAP_LOADING;
+ m->revision++;
+}
+
+void pod_model_supertab_close(pod_model_t *m, const char *tab, const char *lead) {
+ const pod_swarm_t *s = pod_model_swarm(m, tab);
+ const int j = pod_model_lead_index(s, lead);
+ if (j < 0 || s->leads[j].recap == POD_RECAP_NONE) return;
+ pod_lead_t *l = &((pod_swarm_t *)s)->leads[j];
+ lead_free_text(l);
+ l->recap = POD_RECAP_NONE;
+ m->revision++;
+}
+
+void pod_model_supertab_focus(pod_model_t *m, const char *tab, const char *lead) {
+ if (!tab || !*tab || !lead || !*lead) return;
+ pod_copy_str(m->focus_tab, sizeof m->focus_tab, tab);
+ pod_copy_str(m->focus_lead, sizeof m->focus_lead, lead);
+ m->focus_pending = true;
+ m->revision++;
+}
+
void pod_model_sent(pod_model_t *m, const char *id, uint32_t now_ms) {
pod_model_clock(m, now_ms);
int i = find_idx(m, id);
diff --git a/devices/harness-pro/firmware/main/pod/pod_model.h b/devices/harness-pro/firmware/main/pod/pod_model.h
index 885700477..75d6784d9 100644
--- a/devices/harness-pro/firmware/main/pod/pod_model.h
+++ b/devices/harness-pro/firmware/main/pod/pod_model.h
@@ -120,6 +120,16 @@ typedef struct {
uint8_t unread_count;
pod_read_out_t reads[POD_READS_MAX];
uint8_t read_count;
+ // The Swarm cards (hello swarmCard:v1): the daemon's list, in card order, with each Lead's cached recap text (PSRAM, owned here).
+ pod_swarm_t swarms[SWARMS_CARD_MAX];
+ uint8_t swarm_n; // the received ones, in the order of want[]
+ char want[SWARMS_CARD_MAX][ID_MAX]; // the last `supertabs` id list: set and order; a Swarm not here is dropped, one not received yet is absent
+ uint8_t want_n;
+ bool swarm_ids; // a `supertabs` list has arrived on this link (want[] is then the truth; before it, a Swarm that is not here may just not be sent yet)
+ // supertab.focus: the desktop opened this Swarm project. Kept until the view that acts on it clears focus_pending (a focus for a
+ // Swarm the list does not hold yet waits for it).
+ bool focus_pending;
+ char focus_tab[ID_MAX], focus_lead[ID_MAX];
} pod_model_t;
// Copy src into dst[cap], cut on a UTF-8 codepoint boundary (always valid, always NUL-terminated); src may be dst.
@@ -173,6 +183,26 @@ void pod_model_question_close(pod_model_t *, const char *id);
void pod_model_recap(pod_model_t *, const char *id, const char *recap, bool restore);
void pod_model_link(pod_model_t *, bool up);
+// ---- the Swarm cards ----
+// The `supertabs` id list (at most SWARMS_CARD_MAX, bad or repeated ids skipped): Swarms not listed are dropped and their texts freed, the
+// rest are put in this order; a listed Swarm not received yet stays absent until pod_model_supertab brings it.
+void pod_model_supertab_ids(pod_model_t *, const char (*ids)[ID_MAX], int n);
+// One `supertab` frame: replaces that Swarm's data (a new one is placed by the id list's order). A Lead that was in the old data (same Lead id)
+// keeps its recap state and text; the texts of Leads that left are freed. Stamps since_at_ms with now_ms. Ignored when the id is not in the list.
+void pod_model_supertab(pod_model_t *, const pod_swarm_t *s, uint32_t now_ms);
+// A Lead's last message: LOADED with a copy of `text` (cut to SWARM_TEXT_MAX - 1 on a codepoint), or EMPTY when `none`. Unknown Swarm/Lead: dropped.
+void pod_model_supertab_recap(pod_model_t *, const char *tab, const char *lead, const char *text, uint32_t at, bool none);
+// The Lead view asks for / lets go of a Lead's last message: loading puts a cold one (NONE) to LOADING (the texts arrive as pod_model_supertab_recap);
+// close sends a LOADING, LOADED or EMPTY one back to NONE and frees its text (only the open Lead gets pushes, so a closed one would go stale).
+void pod_model_supertab_loading(pod_model_t *, const char *tab, const char *lead);
+void pod_model_supertab_close(pod_model_t *, const char *tab, const char *lead);
+// supertab.focus: record it as pending (focus_pending, focus_tab, focus_lead); the latest one wins.
+void pod_model_supertab_focus(pod_model_t *, const char *tab, const char *lead);
+const pod_swarm_t *pod_model_swarm_for_tab(const pod_model_t *, const char *tab_id); // the desk tab's Swarm (its `tab` link); NULL for "" or none
+const pod_swarm_t *pod_model_swarm(const pod_model_t *, const char *swarm_id);
+// Index of the Lead in the Swarm, or -1.
+int pod_model_lead_index(const pod_swarm_t *, const char *lead_id);
+
const pod_agent_t *pod_model_find(const pod_model_t *, const char *id);
// The agents with the most recent task (the newer of act_ms and lib_ms), at most max, newest first. An agent with
// neither clock has had no task the Pod knows of and is not listed.
diff --git a/devices/harness-pro/firmware/main/pod/pod_nav.c b/devices/harness-pro/firmware/main/pod/pod_nav.c
index e840bdb5e..21626d535 100644
--- a/devices/harness-pro/firmware/main/pod/pod_nav.c
+++ b/devices/harness-pro/firmware/main/pod/pod_nav.c
@@ -85,6 +85,99 @@ static void opened(const pod_nav_t *n, pod_model_t *m, const char *id)
if (n->depth && n->stack[n->depth - 1].view == POD_V_RECAP) pod_model_unread_read(m, id);
}
+
+// ---- the Lead view ----
+// Point a Lead frame at lead j of sw: the ids, the index, the harness a talk goes to (the Lead's `local` when the roster holds it; empty otherwise, which
+// is a remote Lead), and the text back at its top.
+static void lead_point(pod_frame_t *f, const pod_model_t *m, const pod_swarm_t *sw, int j) {
+ const pod_lead_t *l = &sw->leads[j];
+ set_id(f->swarm, sw->id);
+ set_id(f->lead_id, l->id);
+ f->lead = (int8_t)j;
+ if (l->local[0] && pod_model_find(m, l->local)) set_id(f->agent, l->local);
+ else f->agent[0] = 0;
+}
+
+static void lead_step(const pod_model_t *m, pod_frame_t *f, int dir) {
+ const pod_swarm_t *sw = pod_model_swarm(m, f->swarm);
+ const int at = pod_model_lead_index(sw, f->lead_id);
+ if (!sw || at < 0 || sw->lead_n < 2) return;
+ lead_point(f, m, sw, (at + dir + sw->lead_n) % sw->lead_n);
+ f->scroll = 0;
+}
+
+static bool is_lead_frame(const pod_frame_t *f) { return f->swarm[0] && (f->view == POD_V_LEAD || f->view == POD_V_TALK); }
+
+const pod_lead_t *pod_nav_lead(const pod_nav_t *n, const pod_model_t *m, const pod_swarm_t **swarm) {
+ if (swarm) *swarm = NULL;
+ if (!n->depth || !is_lead_frame(&n->stack[n->depth - 1])) return NULL;
+ const pod_frame_t *f = &n->stack[n->depth - 1];
+ const pod_swarm_t *sw = pod_model_swarm(m, f->swarm);
+ const int j = pod_model_lead_index(sw, f->lead_id);
+ if (j < 0) return NULL;
+ if (swarm) *swarm = sw;
+ return &sw->leads[j];
+}
+
+bool pod_nav_open_lead(pod_nav_t *n, pod_model_t *m, const char *swarm_id, int lead) {
+ if (n->depth != 1 || n->stack[0].view != POD_V_TABS) return false;
+ const pod_swarm_t *sw = pod_model_swarm(m, swarm_id);
+ if (!sw || lead < 0 || lead >= sw->lead_n) return false;
+ pod_frame_t f;
+ memset(&f, 0, sizeof f);
+ f.view = POD_V_LEAD;
+ f.tab = POD_TAB_RECENT;
+ lead_point(&f, m, sw, lead);
+ return push(n, &f);
+}
+
+bool pod_nav_follow_lead(pod_nav_t *n, pod_model_t *m, const char *swarm_id, const char *lead_id) {
+ if (!n->depth) pod_nav_init(n);
+ const pod_swarm_t *sw = pod_model_swarm(m, swarm_id);
+ const int j = pod_model_lead_index(sw, lead_id);
+ if (j < 0) return false;
+ const pod_frame_t *cur = &n->stack[n->depth - 1];
+ if (cur->view == POD_V_TALK) return false;
+ if (cur->view == POD_V_LEAD && !strcmp(cur->swarm, sw->id) && !strcmp(cur->lead_id, lead_id)) return false;
+ int16_t pg[POD_HOME_PAGES_MAX];
+ const int cnt = pod_home_pages(m, pg, POD_HOME_PAGES_MAX);
+ pod_frame_t home, lf;
+ memset(&home, 0, sizeof home);
+ memset(&lf, 0, sizeof lf);
+ home.view = POD_V_TABS;
+ home.scroll = n->stack[0].scroll;
+ for (int i = 0; i < cnt; i++) if (pod_home_swarm(m, pg[i]) == sw) { home.scroll = pg[i]; break; } // Home on the Swarm's card: Back lands there
+ lf.view = POD_V_LEAD;
+ lf.tab = POD_TAB_RECENT;
+ lead_point(&lf, m, sw, j);
+ n->stack[0] = home;
+ n->stack[1] = lf;
+ n->depth = 2;
+ n->sending = false;
+ n->work_page = 0;
+ n->swarm_page = (uint8_t)(j / 3); // the card's pet page holding the Lead
+ return true;
+}
+
+// pod_nav_sync for a Lead frame. KEEP while its data may still come (the link is down or the Swarm list has not arrived since it came up, or the Swarm is
+// listed but not received); GONE when the Swarm is no longer listed, or the Lead left and none is left (or it was a talk). A Lead that left while others
+// remain is replaced by the one that took its place (the next Lead, else the last): the view moves on, it is not closed.
+enum { LEAD_KEEP, LEAD_GONE };
+static int lead_sync(const pod_model_t *m, pod_frame_t *f) {
+ if (!m->linked || !m->swarm_ids) return LEAD_KEEP;
+ const pod_swarm_t *sw = pod_model_swarm(m, f->swarm);
+ if (!sw) {
+ for (int i = 0; i < m->want_n; i++) if (!strcmp(m->want[i], f->swarm)) return LEAD_KEEP;
+ return LEAD_GONE;
+ }
+ const int j = pod_model_lead_index(sw, f->lead_id);
+ if (j >= 0) { lead_point(f, m, sw, j); return LEAD_KEEP; }
+ if (sw->lead_n < 1 || f->view == POD_V_TALK) return LEAD_GONE;
+ lead_point(f, m, sw, f->lead >= 0 && f->lead < sw->lead_n ? f->lead : sw->lead_n - 1);
+ f->scroll = 0;
+ return LEAD_KEEP;
+}
+
static pod_out_t step(pod_nav_t *n, pod_model_t *m, int dir) {
pod_frame_t *f = &n->stack[n->depth - 1];
const pod_agent_t *l[POD_AGENTS_MAX];
@@ -182,6 +275,10 @@ static pod_out_t nav_act(pod_nav_t *n, pod_model_t *m, pod_action_t a, int arg,
}
case POD_A_PREV:
case POD_A_NEXT:
+ if (f->swarm[0]) { // a Lead's view steps through the Swarm's Leads; the talk opened from it does not move
+ if (f->view == POD_V_LEAD) lead_step(m, f, a == POD_A_NEXT ? 1 : -1);
+ break;
+ }
if (is_agent_view(f->view)) return step(n, m, a == POD_A_NEXT ? 1 : -1);
break;
case POD_A_FOLLOW:
@@ -193,6 +290,14 @@ static pod_out_t nav_act(pod_nav_t *n, pod_model_t *m, pod_action_t a, int arg,
}
break;
case POD_A_TALK:
+ if (f->view == POD_V_LEAD) { // a local Lead: talk to its harness (a remote one has none: f->agent is empty)
+ const pod_agent_t *talk_to = pod_model_find(m, f->agent);
+ if (!talk_to || talk_to->state == POD_OFFLINE) break;
+ n->talk_prev = POD_V_LEAD;
+ f->view = POD_V_TALK;
+ n->talk_started_ms = now_ms;
+ return out_fx(POD_FX_VOICE_BEGIN, f->agent);
+ }
if (f->view == POD_V_AGENT || f->view == POD_V_RECAP) {
const pod_agent_t *talk_to = pod_model_find(m, f->agent);
if (!talk_to || talk_to->state == POD_OFFLINE) break; // an offline machine has nobody to hear it
@@ -241,12 +346,13 @@ static pod_out_t nav_act(pod_nav_t *n, pod_model_t *m, pod_action_t a, int arg,
break;
case POD_A_SCROLL: {
long s = (long)f->scroll + arg;
- if (f->view == POD_V_TABS) { f->scroll = (int16_t)pod_home_clamp(m, s < -32768 ? -32768 : s > 32767 ? 32767 : (int)s); n->work_page = 0; break; }
+ if (f->view == POD_V_TABS) { f->scroll = (int16_t)pod_home_clamp(m, s < -32768 ? -32768 : s > 32767 ? 32767 : (int)s); n->work_page = n->swarm_page = 0; break; }
f->scroll = (int16_t)(s < 0 ? 0 : s > 32767 ? 32767 : s);
break;
}
case POD_A_NONE:
case POD_A_BANNER:
+ case POD_A_LEAD:
break;
}
return out_none();
@@ -264,7 +370,7 @@ void pod_nav_talk_over(pod_nav_t *n) {
pod_frame_t *f = &n->stack[n->depth - 1];
if (f->view != POD_V_TALK) return;
n->sending = false;
- f->view = n->talk_prev == POD_V_RECAP ? POD_V_RECAP : POD_V_AGENT;
+ f->view = f->swarm[0] ? POD_V_LEAD : n->talk_prev == POD_V_RECAP ? POD_V_RECAP : POD_V_AGENT; // the talk a Lead's view opened ends back on it
}
void pod_nav_unsend(pod_nav_t *n) {
@@ -281,7 +387,7 @@ static void release_send(pod_nav_t *n, const pod_model_t *m, pod_frame_t *f) {
bool turn = a && a->state == POD_WORKING && !a->sent && (n->sent_seen || (int32_t)(a->since_ms - n->send_started_ms) >= 0);
if (turn || !a || (int32_t)(m->clock_ms - n->send_started_ms) >= (int32_t)POD_SENT_WAIT_MS) {
n->sending = false;
- f->view = turn ? POD_V_AGENT : n->talk_prev == POD_V_RECAP ? POD_V_RECAP : POD_V_AGENT;
+ f->view = f->swarm[0] ? POD_V_LEAD : turn ? POD_V_AGENT : n->talk_prev == POD_V_RECAP ? POD_V_RECAP : POD_V_AGENT;
}
}
@@ -314,6 +420,9 @@ pod_out_t pod_nav_sync(pod_nav_t *n, pod_model_t *m) {
const int pages = (pod_home_working(m) + 2) / 3; // the Working card's pet pages: the stored page follows the working set down
if (n->depth != 1 || n->stack[0].scroll != POD_HOME_WORKING) n->work_page = 0;
else if (n->work_page >= pages) n->work_page = (uint8_t)(pages > 0 ? pages - 1 : 0);
+ const pod_swarm_t *sw = pod_home_swarm(m, n->stack[0].scroll); // the Swarm card's Lead pages follow its Leads down; a Lead view over the card keeps its page
+ const int lp = sw ? (sw->lead_n + 2) / 3 : 0;
+ if (n->swarm_page >= lp) n->swarm_page = (uint8_t)(lp > 0 ? lp - 1 : 0);
}
uint8_t keep = n->depth;
for (uint8_t i = 1; i < n->depth; i++) {
@@ -329,6 +438,10 @@ pod_out_t pod_nav_sync(pod_nav_t *n, pod_model_t *m) {
f->tab = (int8_t)idx;
}
if (f->view == POD_V_TAB || f->view == POD_V_INBOX) continue;
+ if (f->swarm[0]) { // a Lead's view, or the talk opened from it
+ if (lead_sync(m, f) == LEAD_GONE) { keep = i; break; }
+ if (f->view == POD_V_LEAD) continue;
+ }
const pod_agent_t *l[POD_AGENTS_MAX];
int cnt = frame_list(m, f, l, POD_AGENTS_MAX);
bool found = false;
@@ -383,7 +496,7 @@ bool pod_nav_follow(pod_nav_t *n, pod_model_t *m, const char *agent_id, uint32_t
n->stack[0] = tabs; n->stack[1] = tf; n->stack[2] = af;
n->depth = 3;
n->sending = false;
- n->work_page = 0;
+ n->work_page = n->swarm_page = 0;
opened(n, m, a->id);
pod_nav_flip_recaps(n, m);
return true;
@@ -400,7 +513,7 @@ bool pod_nav_follow_tab(pod_nav_t *n, pod_model_t *m) {
if (cur->view == POD_V_TABS && n->depth == 1) {
if (cur->scroll == sel) return false;
cur->scroll = (int16_t)sel;
- n->work_page = 0;
+ n->work_page = n->swarm_page = 0;
return true;
}
if (cur->view != POD_V_AGENT && cur->view != POD_V_RECAP) return false;
diff --git a/devices/harness-pro/firmware/main/pod/pod_nav.h b/devices/harness-pro/firmware/main/pod/pod_nav.h
index e04c9ef94..00a03dc30 100644
--- a/devices/harness-pro/firmware/main/pod/pod_nav.h
+++ b/devices/harness-pro/firmware/main/pod/pod_nav.h
@@ -6,7 +6,7 @@
#include "pod/pod_model.h"
-typedef enum { POD_V_TABS, POD_V_TAB, POD_V_AGENT, POD_V_RECAP, POD_V_TALK, POD_V_INBOX } pod_view_t;
+typedef enum { POD_V_TABS, POD_V_TAB, POD_V_AGENT, POD_V_RECAP, POD_V_TALK, POD_V_INBOX, POD_V_LEAD } pod_view_t;
enum { POD_TAB_RECENT = -1 }; // the Recent list: the agents with the most recent tasks, from every tab
typedef struct {
@@ -15,7 +15,10 @@ typedef struct {
// Only a cache: tab_id names the tab, and pod_nav_sync re-resolves the index after
// every model change (a tab inserted before this one moves it).
char tab_id[SWARM_ID_MAX]; // the tab's swarm id; empty for the Recent list
- char agent[ID_MAX];
+ char agent[ID_MAX]; // LEAD frame: the harness the Lead's talk goes to (its `local`), empty for a remote Lead (re-resolved by pod_nav_sync)
+ char swarm[ID_MAX]; // LEAD frame (and the TALK opened from it): the Swarm's id; empty on every other frame
+ char lead_id[ID_MAX]; // ... and the Lead's id: it names the Lead, `lead` (its index in the Swarm's card order) is only a cache that pod_nav_sync re-resolves
+ int8_t lead;
int16_t scroll; // the first row shown (the Tabs grid's rows of covers, a tab's agents, a recap's lines)
} pod_frame_t;
@@ -25,6 +28,7 @@ typedef struct {
uint32_t talk_started_ms, send_started_ms;
char sent_agent[ID_MAX];
uint8_t work_page; // Home's Working card: the page of three pets shown (0-based; reset when the card is not shown)
+ uint8_t swarm_page; // Home's Swarm card: the page of three Lead pets shown (0-based; reset when the card is not shown or the person pages cards)
pod_view_t talk_prev; // AGENT or RECAP: the screen TALK was opened from (talk_over goes back to it)
bool sending; // TALK after the stop tap: the voice screen shows SEND until the agent's real turn begins (or POD_SENT_WAIT_MS)
bool sent_seen; // the model has marked sent_agent's optimistic Working (pod_model_sent) since the stop tap
@@ -46,7 +50,8 @@ typedef enum {
POD_A_OPEN_NOTIF, // arg: index into model->unread, from the Inbox: open that agent (an Agent/Recap frame over the Inbox) and mark it read. An idle agent opens on its Recap (which reads it)
POD_A_FOLLOW, // arg: index into model->agents: open that agent from anywhere (Inbox rows with no unread entry); the glue resolves the id
POD_A_SCROLL, // arg: signed delta added to the top frame's scroll (clamped to >= 0): rows, whatever the screen draws as one.
- POD_A_ENTER_TAB // arg: tab index, only from the TABS frame: push the TAB frame and the tab's first agent (AGENT_OPEN). An empty or unknown tab: nothing.
+ POD_A_ENTER_TAB, // arg: tab index, only from the TABS frame: push the TAB frame and the tab's first agent (AGENT_OPEN). An empty or unknown tab: nothing.
+ POD_A_LEAD // hit only for now (the Swarm card's Lead pets): arg = the Lead's index in its Swarm, hit id = the Swarm's id. The nav ignores it
} pod_action_t;
typedef enum { POD_FX_NONE, POD_FX_VOICE_BEGIN, POD_FX_VOICE_END, POD_FX_VOICE_ABORT, POD_FX_AGENT_OPEN } pod_effect_t;
@@ -81,4 +86,14 @@ int pod_nav_list(const pod_nav_t *, const pod_model_t *, const pod_agent_t *out[
// (a tab list), "Tabs" (the root), "Inbox", else "Back". The pointer is into the model (or a literal): valid until the next model change.
const char *pod_nav_origin(const pod_nav_t *, const pod_model_t *);
bool pod_nav_follow(pod_nav_t *, pod_model_t *, const char *agent_id, uint32_t now_ms);
+// ---- the Lead view (Swarm cards) ----
+// A tap on a Lead pet: push the Lead view for lead index `lead` of the Swarm over Home. Home stays on its card (and its swarm_page), so Back lands on it. Nothing for
+// an unknown Swarm or Lead, over TALK, or when the stack is not at Home. Returns true when it pushed.
+bool pod_nav_open_lead(pod_nav_t *, pod_model_t *, const char *swarm_id, int lead);
+// supertab.focus: replace the stack with Home on the Swarm's card and the Lead view over it (the card's pet page is the one holding the Lead). Does nothing for an
+// unknown Swarm or Lead, while TALK is on top, or when that Lead is already open. Returns true when the stack changed.
+bool pod_nav_follow_lead(pod_nav_t *, pod_model_t *, const char *swarm_id, const char *lead_id);
+// The Lead the top frame shows (the Lead view, or the TALK opened from it) and its Swarm (may be NULL); NULL when the top is not one or the model does not hold it (yet).
+const pod_lead_t *pod_nav_lead(const pod_nav_t *, const pod_model_t *, const pod_swarm_t **swarm);
+// POD_A_PREV / POD_A_NEXT on the Lead view step to the previous / next Lead of the Swarm in card order (wrapping; nothing with fewer than two); on the TALK opened from it, nothing.
bool pod_nav_follow_tab(pod_nav_t *, pod_model_t *); // The app window's selected tab changed: Home's card or the room follows (device-local)
diff --git a/devices/harness-pro/firmware/main/pod/pod_view.c b/devices/harness-pro/firmware/main/pod/pod_view.c
index feffe885f..7c0d5b5e3 100644
--- a/devices/harness-pro/firmware/main/pod/pod_view.c
+++ b/devices/harness-pro/firmware/main/pod/pod_view.c
@@ -1,4 +1,6 @@
// pod_render: the one entry point. It draws the Pets screens (home/ph_view.c) and answers how the top screen scrolls and animates.
+#include <string.h>
+
#include "pod_view.h"
#include "pro_canvas.h"
#include "pod/home/ph.h"
@@ -18,6 +20,7 @@ uint32_t pod_view_next_ms(const pod_nav_t *nav, const pod_model_t *m, uint32_t n
case POD_V_RECAP: return ph_room_next_ms(nav, m, now_ms); // the room's pet and its seconds
case POD_V_TALK: return ph_talk_next_ms(nav, m, now_ms); // the pet's own animation is all that moves, on its beat
case POD_V_INBOX: return ph_inbox_next_ms(nav, m, now_ms); // Notices: when an age text changes
+ case POD_V_LEAD: return ph_lead_next_ms(nav, m, now_ms); // a Lead's pet and its status seconds
default: return POD_PET_STEP_MS;
}
}
@@ -28,23 +31,40 @@ int pod_home_working(const pod_model_t *m)
for (int i = 0; i < m->agent_count; i++) n += pod_model_eff(m, &m->agents[i]) == POD_WORKING;
return n;
}
+// A Swarm is drawn in its desk tab's page when that tab exists (and the Swarm is the one pod_model_swarm_for_tab names); else it is a page of its own.
+static bool swarm_on_a_tab(const pod_model_t *m, const pod_swarm_t *sw)
+{
+ if (!sw->tab[0] || pod_model_swarm_for_tab(m, sw->tab) != sw) return false;
+ for (int t = 0; t < m->tab_count; t++) if (!strcmp(m->tabs[t].id, sw->tab)) return true;
+ return false;
+}
+const pod_swarm_t *pod_home_swarm(const pod_model_t *m, int page)
+{
+ if (page < 0) return NULL;
+ if (page < m->tab_count) return pod_model_swarm_for_tab(m, m->tabs[page].id);
+ int k = page - m->tab_count; // the pages after the tabs: the Swarms with no desk tab, in list order
+ for (int i = 0; i < m->swarm_n; i++)
+ if (!swarm_on_a_tab(m, &m->swarms[i]) && k-- == 0) return &m->swarms[i];
+ return NULL;
+}
bool pod_home_has(const pod_model_t *m, int page)
{
return page == POD_HOME_NOTICES ? pod_notice_count(m) > 0
: page == POD_HOME_WORKING ? pod_home_working(m) > 0
- : page >= 0 && page < m->tab_count;
+ : page >= 0 && (page < m->tab_count || pod_home_swarm(m, page));
}
int pod_home_pages(const pod_model_t *m, int16_t *out, int cap)
{
int n = 0;
- for (int p = POD_HOME_NOTICES; p < m->tab_count; p++)
+ for (int p = POD_HOME_NOTICES; p < m->tab_count + m->swarm_n; p++)
if (pod_home_has(m, p)) { if (out && n < cap) out[n] = (int16_t)p; n++; }
return n;
}
int pod_home_clamp(const pod_model_t *m, int s)
{
- for (int p = s < POD_HOME_NOTICES ? POD_HOME_NOTICES : s; p < m->tab_count; p++) if (pod_home_has(m, p)) return p;
- for (int p = s < m->tab_count ? s : m->tab_count - 1; p >= POD_HOME_NOTICES; p--) if (pod_home_has(m, p)) return p;
+ const int end = m->tab_count + m->swarm_n;
+ for (int p = s < POD_HOME_NOTICES ? POD_HOME_NOTICES : s; p < end; p++) if (pod_home_has(m, p)) return p;
+ for (int p = s < end ? s : end - 1; p >= POD_HOME_NOTICES; p--) if (pod_home_has(m, p)) return p;
return 0;
}
int pod_tabs_pages_of(const pod_nav_t *nav, const pod_model_t *m)
@@ -56,6 +76,7 @@ int pod_tabs_pages_of(const pod_nav_t *nav, const pod_model_t *m)
int pod_scroll_pitch(const pod_nav_t *nav)
{
const pod_frame_t *top = nav->depth ? &nav->stack[nav->depth - 1] : NULL;
+ if (top && top->view == POD_V_LEAD) return ph_lead_pitch(); // a long Lead message scrolls on the device
return top && top->view == POD_V_INBOX ? ph_inbox_pitch() : 0; // Home pages with a swipe and a recap is the host's pane: no device scroll
}
int pod_scroll_max(const pod_nav_t *nav, const pod_model_t *m)
@@ -63,6 +84,7 @@ int pod_scroll_max(const pod_nav_t *nav, const pod_model_t *m)
const pod_frame_t *top = nav->depth ? &nav->stack[nav->depth - 1] : NULL;
if (!top) return 0;
if (top->view == POD_V_INBOX) return ph_inbox_max_row(m);
- if (top->view == POD_V_TABS) return m->tab_count > 0 ? m->tab_count - 1 : 0; // Home's scroll is the tab index
+ if (top->view == POD_V_LEAD) return ph_lead_max_row(nav, m);
+ if (top->view == POD_V_TABS) return m->tab_count + m->swarm_n > 0 ? m->tab_count + m->swarm_n - 1 : 0; // Home's scroll is the tab index (then the Swarms with no tab)
return 0;
}
diff --git a/devices/harness-pro/firmware/main/pod/pod_view.h b/devices/harness-pro/firmware/main/pod/pod_view.h
index d93d02a1f..51c296245 100644
--- a/devices/harness-pro/firmware/main/pod/pod_view.h
+++ b/devices/harness-pro/firmware/main/pod/pod_view.h
@@ -39,7 +39,10 @@ bool pod_hit_add(pod_out_frame_t *, int x, int y, int w, int h, pod_action_t act
bool pod_hit_add_id(pod_out_frame_t *, int x, int y, int w, int h, pod_action_t action, int arg, const char *id);
// Home's pages in order: the Notices card (POD_HOME_NOTICES) while there are notices, the Working card (POD_HOME_WORKING) while an agent works,
// then the tabs 0..n-1. The TABS frame's scroll is one of these values.
-enum { POD_HOME_NOTICES = -2, POD_HOME_WORKING = -1 };
+// A Swarm with no desk tab (Swarm cards) is one more page after the tabs: tab_count + its index among those Swarms. A desk tab linked to a Swarm
+// shows the Swarm's card on its own page.
+enum { POD_HOME_NOTICES = -2, POD_HOME_WORKING = -1, POD_HOME_PAGES_MAX = POD_TABS_MAX + SWARMS_CARD_MAX + 2 };
+const pod_swarm_t *pod_home_swarm(const pod_model_t *, int page); // the Swarm a page draws (a linked tab's, or one of its own); NULL for any other page
int pod_home_working(const pod_model_t *); // agents working now (pod_model_eff)
bool pod_home_has(const pod_model_t *, int page); // is `page` in the list
int pod_home_pages(const pod_model_t *, int16_t *out, int cap); // the pages in order (out may be NULL); returns how many
diff --git a/devices/harness-pro/firmware/main/pro_app_api.h b/devices/harness-pro/firmware/main/pro_app_api.h
index e80977699..d4c0b64f9 100644
--- a/devices/harness-pro/firmware/main/pro_app_api.h
+++ b/devices/harness-pro/firmware/main/pro_app_api.h
@@ -38,6 +38,18 @@ void pro_app_agents(const pro_agent_row_t *rows, int n);
void pro_app_swarms(const cable_swarm_t *items, int n, const cable_swarm_members_t *members,
const char *selected, const cable_tile_t *tiles, int tile_n);
+// ---- Swarm cards (hello swarmCard:v1) ----
+// `supertabs`: the current set and order of Swarm ids (at most SWARMS_CARD_MAX, each shorter than ID_MAX, no repeats). A Swarm not
+// listed is dropped; a listed one not yet received stays absent until its `supertab` frame arrives.
+void pro_app_supertab_ids(const char (*ids)[ID_MAX], int n);
+// `supertab`: one Swarm's data (<= SWARM_LEADS_MAX Leads, names cut on a UTF-8 boundary, a bad Lead skipped), replacing that Swarm's. Ignored
+// when its id is not in the last id list. `since_at_ms` and every Lead's `text` are 0/NULL here: the model stamps the clock and keeps the cached texts.
+void pro_app_supertab(const pod_swarm_t *s);
+// `supertab.recap`: the Lead's last message (<= SWARM_TEXT_MAX - 1 bytes; "" when `none`), `at` its epoch seconds.
+void pro_app_supertab_recap(const char *tab, const char *lead, const char *text, uint32_t at, bool none);
+// `supertab.focus`: the desktop opened this Swarm project. Both ids are non-empty.
+void pro_app_supertab_focus(const char *tab, const char *lead);
+
// ---- library ----
// Same layout as pod_library_row_t (pod_glue.h). `machine` is the machine NAME ("" when the machine list does not
// hold the id), `status` one of idle working question finished failed paused offline.
diff --git a/devices/harness-pro/firmware/test/golden-liberation.txt b/devices/harness-pro/firmware/test/golden-liberation.txt
index f09a50c31..116a31f4e 100644
--- a/devices/harness-pro/firmware/test/golden-liberation.txt
+++ b/devices/harness-pro/firmware/test/golden-liberation.txt
@@ -10,8 +10,10 @@
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk:testfail@5000
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk:unread@5000
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk@5000
+0e6c6e8c472798f787049711849aecaa717179bad00135fa1d0f84d8db09308e lead:loaded@600
102064b2c387ab5cd1e0f274a8beaef812acc0db7e93ddaef06ed8d06811398f recap:desk:short@2500
11ce48c998ea730350c5fa0430d78275a62dff6d2f19e32343040e9ec47ba28f agent:be:offline@2500
+12c8abf13002e19438133eef0d2947372670cd4657bb519a5cea3c9deb58fd54 lead:remote@600
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:0+2@5000
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:9@5000
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:banner@5000
@@ -21,6 +23,8 @@
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw:banner@1234
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw:unread@1234
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw@1234
+215c00f65d2a0cf21a2edb2c7e244aa142e1857fafeb073353503ad9fe264b23 home:swarm:p1@5000
+2169e2fd626fffa09f4f18655ba58804ba1a69e406d54bc055106a904c079e9f lead:none@2500
22083bf5827695add306905a71f6e07a70ec12872d2d4ed3cc043e47de7205cd talk:fw:quiet@600
22083bf5827695add306905a71f6e07a70ec12872d2d4ed3cc043e47de7205cd talk:fw@600
24e4b487e56cee7639400ebd1ed0d473a12cf553c31c0f3029edf019e1f36bc0 tabs:5@5000
@@ -74,11 +78,13 @@
3875141c2c78b0f4f41992d51b0f5553007643479df81003fe6311e638262c31 tabs:single@600
39a58e689432dc89a8be25610811046ee961c08f5ad108029bf8f68c32505edb recap:docs:unreadfail@1234
3a47de3edda62ff8d064071fa8d17377d9c0c19e44aef0c28fa0043ec86cce51 tabs:seven@2500
+3b562265abe088aada195ff5b8a88dba3e06d62809a2d582cefb34adf20bf329 lead:ask@2500
3baf2cd488eeeb310783ef08303bbb235772ade7303feedc65e2adaa7b565565 recap:desk:short@1234
3c50228ed125d5138821ae678ebc8267734a5e79c8878b4e4813ebbcb80b3164 agent:fw:long@1234
3d43bb7cb2ab0102944745f80af971677a75bec05d5dbc01baaf9003fa4111f9 tabs:5@1234
44c082278989b9844c91c372d51a9f2b29430bf083fcb2794698e189fe8f2e3d tabs:none@600
45de9aa8132e2d8f8e14853abb8ee563e660be15078bc812aa6d4795c95c7cfb tabs:long@5000
+45e5e20264186932fd58d679d5b05c0871332b1f675ac6b4fd34c5496f2dfea9 lead:remote@2500
46469853ff6e0388f14b379f37728428c7c4e2a7e4d0df8e5f35fd6af10cc416 recap:desk:viet@1234
47b0c7abe1a3482cf5e154191e2742cf9ee76dd5d0af8455c4746f98568c72b1 agent:be@2500
47b0c7abe1a3482cf5e154191e2742cf9ee76dd5d0af8455c4746f98568c72b1 agent:be@5000
@@ -94,8 +100,13 @@
4e1055e7920922bf2c1ba0212b5860b7cdcc162784a16e1d9abd6c586d38cec0 recap:docs:toast@4900@600
50515880623dbb0b9854175e41174c31d6396b40c576932cad2dcc5e36cff96e tabs:seven@1234
50e26b3c495b054fb16aaf4e792d49234f9d636fa88c4b3520512e75cdf1dc9d recap:desk:long@5000
+522c0ef262e44de7dbe43d1e669ad245afdc0d61eb392bb41bbc3042cad484f1 home:swarm:p2@2500
+551b117b09be9e2c33321c250309a07e870cdfa3e78ab63258275dc3547e704a home:swarm:p2@5000
5647a2a762bd817469bff3189b4e1162fb3b11acbbc72ad9aee9139e0446a010 recap:docs:long@0
5647a2a762bd817469bff3189b4e1162fb3b11acbbc72ad9aee9139e0446a010 recap:docs:long@2500
+58b7ac6e3d8f2a33688f6044621fb1acc2a7e4e7424b97cce6a6f7faf599dd0b home:swarm:remote@5000
+5a89207381361196379379401929830ee1c788356beb635d02cc713d3e67a1b6 home:swarm:remote@0
+5acb2d70fc0480116a86cbbf66fcc15390559f258a7cdacf1c2044615cd7135a lead:remote@1234
5ce5a5aebccdcd1e858832bd35d7de3235502512ef08f0b337da4fb16ee30791 talk:fw:quiet@0
5ce5a5aebccdcd1e858832bd35d7de3235502512ef08f0b337da4fb16ee30791 talk:fw@0
6138d6c974e4bab23a707281fa6fa85203220141424ab54f216b7b6d65f03eab tabs:working@2500
@@ -103,9 +114,12 @@
66c0d32cef1ff955274fa76dcf012efa2b6fd0306205cfefebfca9d1e5f1a0f3 agent:be@1234
67b7fd29c369b0f8bbc30460233d7f3a8b5777e2729e4fcb2abbc6396f8e7f67 agent:fw:long@0
67b7fd29c369b0f8bbc30460233d7f3a8b5777e2729e4fcb2abbc6396f8e7f67 agent:fw:long@5000
+6af76a1c54f1009e39d0b458cf8093b8a7b02070888dc3232658044fdac480a1 lead:ask@1234
+6af76a1c54f1009e39d0b458cf8093b8a7b02070888dc3232658044fdac480a1 lead:ask@5000
6b6f4d5ec0fca4a424bbf414120c01447324f801eee022d81472bb400f0b0c5f agent:be:offline@0
6b6f4d5ec0fca4a424bbf414120c01447324f801eee022d81472bb400f0b0c5f agent:be:offline@5000
6c3389eb1064d6b347bc85f3bda88ead51eb6a0884b92db0d27afb43547e9fe4 recap:docs@600
+71ab48d28570b32591d93f305e3a1c95d00b3ca6026359dd630b3f5da6c78ac1 lead:loaded@1234
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@0
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@1234
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@2500
@@ -118,6 +132,7 @@
7593d8806d372da0c991d91edb4cd8236a21aebb65e3df5748be49bba89fdf55 recap:desk:toast@2500@5000
7593d8806d372da0c991d91edb4cd8236a21aebb65e3df5748be49bba89fdf55 recap:desk:toast@2500@600
762ed969bd1df9df725878715196d6a826105caf612fb7fa881b67e4b070b7e0 talk:be@2500
+78406036e18c7c6ac07c6be66eab95988277809d1773f389ba43689f64bf4792 home:swarm:p1@2500
795544341ad4c32f7547c77449838fb9ffa4ebf03c336d43012a309838a35b51 agent:fw:long@2500
79e8882fc2d840ab167064322c9ca2620467320e9cd10d826930e733c89c0cac agent:fw:toast@200@0
79e8882fc2d840ab167064322c9ca2620467320e9cd10d826930e733c89c0cac agent:fw:toast@200@1234
@@ -132,13 +147,21 @@
7ccddd2c39c5bec4ebcf4fa0e5bfb3421e0d200aeb091e014636296e2e8ec850 talk:fw:quiet@2500
7ccddd2c39c5bec4ebcf4fa0e5bfb3421e0d200aeb091e014636296e2e8ec850 talk:fw@2500
7dfd56f51d9b85c6cf8396f7f4169ffcabe7c2bb436a8096a2c0275dc339e617 agent:cli:long@600
+7e560682e42982215f0b39450ac55bb2059d9b70065772979fcdb7b3c3cf9fe9 lead:none@0
+7e560682e42982215f0b39450ac55bb2059d9b70065772979fcdb7b3c3cf9fe9 lead:none@5000
+7effffc339beb6a37a3cbcc5cb51fe7c836ef949dcb216825da4bfe0129722dd lead:loaded@5000
81312fbd4dee9803a32e5d3aa5fb3b317eafb965fa337f4fadaec149959bc0fc tabs:seven@0
+81cb592818416fb5bbdc363d609b1f9993a87cf61f00e50b60b83d47821b389a lead:loading@1234
+835d8ded40e3837ec031ce1aa53005eb55c64beffcd405c33be317ae2d4bff7d home:swarm:p1@600
84ee291923ce9c24df7ca48fc9b93db7af552d3f47114aa5613729433fd23c58 tabs:working@5000
85d5961e036ad3cb1e31997577984c6775353f05f155155b41b89d3cf8c09dda tabs:mock@0
+8648e46bdfa90cf6e7cab350161bff2a09fa06d2b4d2783d46bf52bd06b1ab58 lead:remote@0
+8648e46bdfa90cf6e7cab350161bff2a09fa06d2b4d2783d46bf52bd06b1ab58 lead:remote@5000
894cea19f4e9888e3b6fa994544f2dd08b3fd88e14bc03b613e84ddb6d31e534 recap:desk:medium@5000
8b5e65b69b80e00dec34d7c2e0caa4c181ca30221566d7485d4af4f38f309326 tabs:mock@5000
8dfdc413fea168894bad4005522823945c21865d6b04adbef6c9b9c1627a5483 talk:be@1234
8e9c92f81c14203f374a24ece15172a3c59af781fced1472bbf236f424dc46fa recap:desk:short@600
+8fb4bc5c32a12c789f677a481b8793795903dd08b09b26a80c97ddd77af110e9 lead:loaded@2500
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@0
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@1234
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@2500
@@ -158,8 +181,11 @@
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs:bell@0
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs:linkdown@0
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs@0
+9569396d08f53a25947caa402456c5a4b9bfe8dbdd37663d52fc7ce6aed5ccb9 lead:loading@5000
+97096110794ece76a2ab0b9f8d01618e360541a3acf1bd584d8fbaa95b0d0d67 lead:ask@0
977bddb50cbd047bb41ea02dc9d04f75518bfefe9e25944de93d0fce40b7e51a talk:cur:send@5000
97cf9dd9e3d5e04d7b553aa767fc765a3bd47cc1160f327538f227b2fd0fcd5b recap:desk:short@5000
+9a206f39596831defafff0aff579c7b4f52fd61029620d3beb2833b56b8ebb67 lead:loading@600
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e agent:desk@0
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e recap:desk:banner@0
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e recap:desk:extreme@0
@@ -188,6 +214,7 @@ a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@2500
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@5000
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@600
+a3df9f09d6eb320d461cb77d01a0a3e52ce22a139b15124dc17fe7a9e85c47ab lead:loaded@0
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 agent:desk@2500
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 recap:desk:banner@2500
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 recap:desk:extreme@2500
@@ -205,7 +232,9 @@ ad007cd4fdc4676271ee900e07647d470675012997b1e9d6c1cfb625ee25df2b recap:docs@250
ae9a89417055592a7468dfc3a7ea64b58cd85df877f197f8948e2b47a9124eb3 tabs:long@1234
b13776fc7d712241ba716efb51747a1cd43cd0d009b8f2a20fbf1c8e36153be7 talk:be@5000
b2987fbea14e51cc7b4ddfcc7bc767ee6e7d4a09857ddabb9d0a5a680be6a714 recap:docs@5000
+b2a99d49993c9851e0ba392ee87c864f831d47651b57706970d695a471c11967 home:swarm:p1@1234
b31f451d884e5af7e9120f0456f994e049d8fafda4b014a76af3cf751cd96705 recap:docs:unreadfail@600
+b65873f886da7017decf982177999e06d675cc158414f76acce2839cbd05646b lead:loading@0
b69db76ef91afb9968df7483b44448dbcdd78cf2bfa449dcbe3ee0df3f17ae25 recap:desk:viet@5000
b6e4fb3070cc13683d734e9bc6e1f104b71f8aaf949478c8e1d1b4c60c1f3d66 tabs:1@0
bb3500cd77cfe1b2bf6148f2f61814b9b0969bcbd61bf0f6e2dab39d8d40c8ab agent:be:offline@1234
@@ -221,6 +250,7 @@ c158dad57e29a9df5ca9b0169c6f1367dac791a7126326aeca42ee6cfc67e090 tabs:1@2500
c443af989eb93dc9f11d473e90a91bf613767f903f194bea8b0079d707a631dd tabs:working@600
c4af0eaee2c62b423f4d3bcb3a8539098c4ffb95f64dd94b1665ea8112fb1e51 tabs:long@2500
c535233a8ccffe6e34bd2767b32fc79e8cfd0929967fcb3b6a515479700804d9 recap:desk:viet@0
+c5e30d82a2680e2f7cbdff04cad612f8b418a69af267238294b9d4981e3df4fe lead:ask@600
c80992f8fc1e4a7c9a2c04b19ae6b33948f455d47c66d08c38f44531e58bdc3d recap:desk:long@600
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@0
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@1234
@@ -228,6 +258,7 @@ c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@5000
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@600
c94fb8ea8955544b06c3b0120dbedac4d295f98a9ac48c8172037531fcca9d69 agent:fw:long@600
+ca82468f2f504f1609ea6ad0a41daa8de829e7d78720710868be72e9ee1973dd home:swarm:remote@2500
cacbb92aabbda5f6c5f2a3415fe6ee6738d297ad04a965a2d75146def704c6f9 recap:desk:medium@2500
cb3173536ee26106bde53894630e1e172f58d7186f8170bb193309b2f1908a1f agent:cli:banner@2500
cb3173536ee26106bde53894630e1e172f58d7186f8170bb193309b2f1908a1f agent:cli@2500
@@ -258,12 +289,14 @@ d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:banner@60
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:bell@600
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:linkdown@600
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs@600
+d547696fb2c4b18d10790f2ba5b3aaa2f7c51688080ad3e9d1788e1289e735bf lead:loading@2500
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@0
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@1234
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@2500
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@5000
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@600
d750a984bfeeb870e18c3291aad2cdd2f6f12b7c4c04c87bdf60f1143ea8ad02 tabs:working@1234
+d93ce2029eb31540b78e76efa0013843c9c5ec125569aa6dbdf63a4965718f0c lead:none@600
d95387eb8f4a5e443d31a5fe2c2a25b5d8cba9b0304b25ed2b63250f6ce3d308 recap:desk:viet@600
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@0
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@1234
@@ -271,6 +304,7 @@ d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@5000
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@600
de7fccfd4d9ed624772a2c8d137e182ca0697f72b421dc21d1bb4ce4bc8bf594 tabs:none@2500
+dfb664b93e94509505dc4ea3a3885af52f9dc464e744c1c70f6ed886b9bc2c9e home:swarm:remote@1234
e01801d7676609320823ae0c55a805defab02449150ee721b8b774f8e85a7294 recap:desk:medium@0
e16e322edb920b4cff7d04ca1cb2c8202987f3734183bea64c59a7086b6ba830 agent:cli:long@5000
e1788054013a3e7d0de30c89a433ced3cb54ecca26683ffbff6693e33ab5df09 tabs:notices@0
@@ -281,11 +315,13 @@ e1788054013a3e7d0de30c89a433ced3cb54ecca26683ffbff6693e33ab5df09 tabs:notices@6
e1ff6c4a58d744e05300c2a57be4e08d5f29cc531a741a83c649a892ab7de29a recap:desk:long@1234
e55b4e490d71c454af6cd36f6778798a187eacfcce2b18ca7579fffc5b386bb0 agent:cli:banner@600
e55b4e490d71c454af6cd36f6778798a187eacfcce2b18ca7579fffc5b386bb0 agent:cli@600
+e55c5558366c433bf6744046dfc90aba9040f8f400a9fb4741f390116eec696f home:swarm:p2@600
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@0
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@1234
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@2500
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@5000
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@600
+e6a3ea32881c13627d6043a18efae1b4578e2c62467b1989129c0a8da1b57032 lead:none@1234
e6a7fa14ee6c9191350176f8dfcf0661da526268a3d14d912f6337e048b39cbf tabs:1@1234
e8f82832b80bcf61502a843b8ebc9523b41386be13fdafcc1cf2d5f5e00922ad inbox:quiet@0
e8f82832b80bcf61502a843b8ebc9523b41386be13fdafcc1cf2d5f5e00922ad inbox:quiet@1234
@@ -299,6 +335,7 @@ ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:banner@25
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:bell@2500
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:linkdown@2500
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs@2500
+ec4a2a8da59af8b0a9bc0fce6675614ae5961a408af020f73d2bdcb053441d72 home:swarm:remote@600
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@0
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@1234
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@2500
@@ -309,6 +346,7 @@ ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@1234
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@2500
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@5000
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@600
+f1d546d7076d8fcbdb55c72e01cdf190a4fe0915c52c3c6c874310847c0c47eb home:swarm:p2@1234
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@0
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@1234
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@2500
@@ -323,8 +361,10 @@ f5336aa91a6c4989c444f12a3b9ec5e050f8496501eda04f4c52b23e9ae55d08 tabs:5@600
f6144683873654c1812667702bbed73c7cb8c8bdbab53bb9c49d13fc5ccbf180 recap:docs:long@600
f8a9d033bd6f6db33f4168d086f3aafae4dff0880e7f4301762ca35caf0c5f20 talk:cur@0
f8a9d033bd6f6db33f4168d086f3aafae4dff0880e7f4301762ca35caf0c5f20 talk:cur@1234
+f91e521853337d3a49b701a5638e4dc9b75497b80ff5aeacd3bf3f13673b266c home:swarm:p2@0
fbc885b17d01eadab52928be9eb2c3abf60bc351a280ac69a15b2c99b1664e8b tabs:seven@600
fc3bf40809cb606d7b0f777017dc1c9de85edebe1f3623ca13919b1495b73ff9 tabs:1@5000
+fe5900f7b4edb2b707d1b4106307c624817255140c84b34a0b5e8d027e30f7f2 home:swarm:p1@0
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw:banner@2500
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw:unread@2500
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw@2500
diff --git a/devices/harness-pro/firmware/test/golden.sh b/devices/harness-pro/firmware/test/golden.sh
index 8cac1ecea..11a37a44d 100644
--- a/devices/harness-pro/firmware/test/golden.sh
+++ b/devices/harness-pro/firmware/test/golden.sh
@@ -30,7 +30,7 @@ python3 "$fw/scripts/gen_fonts.py" ${font_args[@]+"${font_args[@]}"} --out "$out
cc -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O1 -g -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" \
-o "$out/pod_render" "$here/pod_render.c" "$fw"/main/pod/*.c "$fw"/main/pod/home/*.c "$disp/pro_canvas.c" "$disp/terminal.c" "$out/pro_fonts.c"
-screens=(tabs tabs:bell tabs:mock tabs:0+2 tabs:2+2 tabs:long tabs:9 tabs:linkdown tabs:1 tabs:3 tabs:5 tabs:seven tabs:single tabs:notices tabs:working tabs:none
+screens=(tabs tabs:bell tabs:mock tabs:0+2 tabs:2+2 tabs:long tabs:9 tabs:linkdown tabs:1 tabs:3 tabs:5 tabs:seven tabs:single tabs:notices tabs:working tabs:none home:swarm:p1 home:swarm:p2 home:swarm:remote lead:loaded lead:ask lead:loading lead:none lead:remote
agent:fw agent:cli agent:be agent:desk agent:kilo agent:fw:long agent:cli:long agent:be:offline agent:fw:banner agent:cli:banner tabs:banner agent:fw:toast@0 agent:fw:toast@200 agent:fw:toast@2500 agent:fw:toast@4900
agent:fw:toast:decision@2500 agent:fw:toast:stuck@9000
recap:desk:toast@200 recap:desk:toast@2500 recap:docs:toast@4900
diff --git a/devices/harness-pro/firmware/test/golden.txt b/devices/harness-pro/firmware/test/golden.txt
index f09a50c31..116a31f4e 100644
--- a/devices/harness-pro/firmware/test/golden.txt
+++ b/devices/harness-pro/firmware/test/golden.txt
@@ -10,8 +10,10 @@
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk:testfail@5000
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk:unread@5000
0cd4cf539f2f3f8dcc17f28478d50ea641f5a0f6f1a3aa27674ba268e2705e0b recap:desk@5000
+0e6c6e8c472798f787049711849aecaa717179bad00135fa1d0f84d8db09308e lead:loaded@600
102064b2c387ab5cd1e0f274a8beaef812acc0db7e93ddaef06ed8d06811398f recap:desk:short@2500
11ce48c998ea730350c5fa0430d78275a62dff6d2f19e32343040e9ec47ba28f agent:be:offline@2500
+12c8abf13002e19438133eef0d2947372670cd4657bb519a5cea3c9deb58fd54 lead:remote@600
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:0+2@5000
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:9@5000
1467a0558ff261ee1580e2ab811f1d59ed1418cf0566b084ba6697eb487a9618 tabs:banner@5000
@@ -21,6 +23,8 @@
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw:banner@1234
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw:unread@1234
205286ce60f1fdf5c5b6cefee707eaf71a3384cda456415cdac103fc574c4ebf agent:fw@1234
+215c00f65d2a0cf21a2edb2c7e244aa142e1857fafeb073353503ad9fe264b23 home:swarm:p1@5000
+2169e2fd626fffa09f4f18655ba58804ba1a69e406d54bc055106a904c079e9f lead:none@2500
22083bf5827695add306905a71f6e07a70ec12872d2d4ed3cc043e47de7205cd talk:fw:quiet@600
22083bf5827695add306905a71f6e07a70ec12872d2d4ed3cc043e47de7205cd talk:fw@600
24e4b487e56cee7639400ebd1ed0d473a12cf553c31c0f3029edf019e1f36bc0 tabs:5@5000
@@ -74,11 +78,13 @@
3875141c2c78b0f4f41992d51b0f5553007643479df81003fe6311e638262c31 tabs:single@600
39a58e689432dc89a8be25610811046ee961c08f5ad108029bf8f68c32505edb recap:docs:unreadfail@1234
3a47de3edda62ff8d064071fa8d17377d9c0c19e44aef0c28fa0043ec86cce51 tabs:seven@2500
+3b562265abe088aada195ff5b8a88dba3e06d62809a2d582cefb34adf20bf329 lead:ask@2500
3baf2cd488eeeb310783ef08303bbb235772ade7303feedc65e2adaa7b565565 recap:desk:short@1234
3c50228ed125d5138821ae678ebc8267734a5e79c8878b4e4813ebbcb80b3164 agent:fw:long@1234
3d43bb7cb2ab0102944745f80af971677a75bec05d5dbc01baaf9003fa4111f9 tabs:5@1234
44c082278989b9844c91c372d51a9f2b29430bf083fcb2794698e189fe8f2e3d tabs:none@600
45de9aa8132e2d8f8e14853abb8ee563e660be15078bc812aa6d4795c95c7cfb tabs:long@5000
+45e5e20264186932fd58d679d5b05c0871332b1f675ac6b4fd34c5496f2dfea9 lead:remote@2500
46469853ff6e0388f14b379f37728428c7c4e2a7e4d0df8e5f35fd6af10cc416 recap:desk:viet@1234
47b0c7abe1a3482cf5e154191e2742cf9ee76dd5d0af8455c4746f98568c72b1 agent:be@2500
47b0c7abe1a3482cf5e154191e2742cf9ee76dd5d0af8455c4746f98568c72b1 agent:be@5000
@@ -94,8 +100,13 @@
4e1055e7920922bf2c1ba0212b5860b7cdcc162784a16e1d9abd6c586d38cec0 recap:docs:toast@4900@600
50515880623dbb0b9854175e41174c31d6396b40c576932cad2dcc5e36cff96e tabs:seven@1234
50e26b3c495b054fb16aaf4e792d49234f9d636fa88c4b3520512e75cdf1dc9d recap:desk:long@5000
+522c0ef262e44de7dbe43d1e669ad245afdc0d61eb392bb41bbc3042cad484f1 home:swarm:p2@2500
+551b117b09be9e2c33321c250309a07e870cdfa3e78ab63258275dc3547e704a home:swarm:p2@5000
5647a2a762bd817469bff3189b4e1162fb3b11acbbc72ad9aee9139e0446a010 recap:docs:long@0
5647a2a762bd817469bff3189b4e1162fb3b11acbbc72ad9aee9139e0446a010 recap:docs:long@2500
+58b7ac6e3d8f2a33688f6044621fb1acc2a7e4e7424b97cce6a6f7faf599dd0b home:swarm:remote@5000
+5a89207381361196379379401929830ee1c788356beb635d02cc713d3e67a1b6 home:swarm:remote@0
+5acb2d70fc0480116a86cbbf66fcc15390559f258a7cdacf1c2044615cd7135a lead:remote@1234
5ce5a5aebccdcd1e858832bd35d7de3235502512ef08f0b337da4fb16ee30791 talk:fw:quiet@0
5ce5a5aebccdcd1e858832bd35d7de3235502512ef08f0b337da4fb16ee30791 talk:fw@0
6138d6c974e4bab23a707281fa6fa85203220141424ab54f216b7b6d65f03eab tabs:working@2500
@@ -103,9 +114,12 @@
66c0d32cef1ff955274fa76dcf012efa2b6fd0306205cfefebfca9d1e5f1a0f3 agent:be@1234
67b7fd29c369b0f8bbc30460233d7f3a8b5777e2729e4fcb2abbc6396f8e7f67 agent:fw:long@0
67b7fd29c369b0f8bbc30460233d7f3a8b5777e2729e4fcb2abbc6396f8e7f67 agent:fw:long@5000
+6af76a1c54f1009e39d0b458cf8093b8a7b02070888dc3232658044fdac480a1 lead:ask@1234
+6af76a1c54f1009e39d0b458cf8093b8a7b02070888dc3232658044fdac480a1 lead:ask@5000
6b6f4d5ec0fca4a424bbf414120c01447324f801eee022d81472bb400f0b0c5f agent:be:offline@0
6b6f4d5ec0fca4a424bbf414120c01447324f801eee022d81472bb400f0b0c5f agent:be:offline@5000
6c3389eb1064d6b347bc85f3bda88ead51eb6a0884b92db0d27afb43547e9fe4 recap:docs@600
+71ab48d28570b32591d93f305e3a1c95d00b3ca6026359dd630b3f5da6c78ac1 lead:loaded@1234
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@0
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@1234
72ba008ee35e9d149fd6952d48cf85ea5898d0875786251d4199b69d53ab2d49 agent:fw:toast@4900@2500
@@ -118,6 +132,7 @@
7593d8806d372da0c991d91edb4cd8236a21aebb65e3df5748be49bba89fdf55 recap:desk:toast@2500@5000
7593d8806d372da0c991d91edb4cd8236a21aebb65e3df5748be49bba89fdf55 recap:desk:toast@2500@600
762ed969bd1df9df725878715196d6a826105caf612fb7fa881b67e4b070b7e0 talk:be@2500
+78406036e18c7c6ac07c6be66eab95988277809d1773f389ba43689f64bf4792 home:swarm:p1@2500
795544341ad4c32f7547c77449838fb9ffa4ebf03c336d43012a309838a35b51 agent:fw:long@2500
79e8882fc2d840ab167064322c9ca2620467320e9cd10d826930e733c89c0cac agent:fw:toast@200@0
79e8882fc2d840ab167064322c9ca2620467320e9cd10d826930e733c89c0cac agent:fw:toast@200@1234
@@ -132,13 +147,21 @@
7ccddd2c39c5bec4ebcf4fa0e5bfb3421e0d200aeb091e014636296e2e8ec850 talk:fw:quiet@2500
7ccddd2c39c5bec4ebcf4fa0e5bfb3421e0d200aeb091e014636296e2e8ec850 talk:fw@2500
7dfd56f51d9b85c6cf8396f7f4169ffcabe7c2bb436a8096a2c0275dc339e617 agent:cli:long@600
+7e560682e42982215f0b39450ac55bb2059d9b70065772979fcdb7b3c3cf9fe9 lead:none@0
+7e560682e42982215f0b39450ac55bb2059d9b70065772979fcdb7b3c3cf9fe9 lead:none@5000
+7effffc339beb6a37a3cbcc5cb51fe7c836ef949dcb216825da4bfe0129722dd lead:loaded@5000
81312fbd4dee9803a32e5d3aa5fb3b317eafb965fa337f4fadaec149959bc0fc tabs:seven@0
+81cb592818416fb5bbdc363d609b1f9993a87cf61f00e50b60b83d47821b389a lead:loading@1234
+835d8ded40e3837ec031ce1aa53005eb55c64beffcd405c33be317ae2d4bff7d home:swarm:p1@600
84ee291923ce9c24df7ca48fc9b93db7af552d3f47114aa5613729433fd23c58 tabs:working@5000
85d5961e036ad3cb1e31997577984c6775353f05f155155b41b89d3cf8c09dda tabs:mock@0
+8648e46bdfa90cf6e7cab350161bff2a09fa06d2b4d2783d46bf52bd06b1ab58 lead:remote@0
+8648e46bdfa90cf6e7cab350161bff2a09fa06d2b4d2783d46bf52bd06b1ab58 lead:remote@5000
894cea19f4e9888e3b6fa994544f2dd08b3fd88e14bc03b613e84ddb6d31e534 recap:desk:medium@5000
8b5e65b69b80e00dec34d7c2e0caa4c181ca30221566d7485d4af4f38f309326 tabs:mock@5000
8dfdc413fea168894bad4005522823945c21865d6b04adbef6c9b9c1627a5483 talk:be@1234
8e9c92f81c14203f374a24ece15172a3c59af781fced1472bbf236f424dc46fa recap:desk:short@600
+8fb4bc5c32a12c789f677a481b8793795903dd08b09b26a80c97ddd77af110e9 lead:loaded@2500
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@0
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@1234
93e7bcb91efa077da089ea4f1d44175de44fb3ee52517906c394b47b8de54f86 talk:cur:send@2500
@@ -158,8 +181,11 @@
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs:bell@0
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs:linkdown@0
94eb6bf3635f7305ed492c7cba44478c3d5e25121297436cefd0e37d95bec843 tabs@0
+9569396d08f53a25947caa402456c5a4b9bfe8dbdd37663d52fc7ce6aed5ccb9 lead:loading@5000
+97096110794ece76a2ab0b9f8d01618e360541a3acf1bd584d8fbaa95b0d0d67 lead:ask@0
977bddb50cbd047bb41ea02dc9d04f75518bfefe9e25944de93d0fce40b7e51a talk:cur:send@5000
97cf9dd9e3d5e04d7b553aa767fc765a3bd47cc1160f327538f227b2fd0fcd5b recap:desk:short@5000
+9a206f39596831defafff0aff579c7b4f52fd61029620d3beb2833b56b8ebb67 lead:loading@600
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e agent:desk@0
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e recap:desk:banner@0
9d7bd2ae8f98c5cb55f9d571084fd299b57d613a4a8fb76618bf96e81dfce21e recap:desk:extreme@0
@@ -188,6 +214,7 @@ a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@2500
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@5000
a2d12802ab968c819af74e829d50ad2a1e9545268a4a917a93c849d708294723 inbox:supertab@600
+a3df9f09d6eb320d461cb77d01a0a3e52ce22a139b15124dc17fe7a9e85c47ab lead:loaded@0
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 agent:desk@2500
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 recap:desk:banner@2500
a6712f0052fbad9b33cf4511c4fbf0e4731c42df8c5533fa33b21a3439caddf2 recap:desk:extreme@2500
@@ -205,7 +232,9 @@ ad007cd4fdc4676271ee900e07647d470675012997b1e9d6c1cfb625ee25df2b recap:docs@250
ae9a89417055592a7468dfc3a7ea64b58cd85df877f197f8948e2b47a9124eb3 tabs:long@1234
b13776fc7d712241ba716efb51747a1cd43cd0d009b8f2a20fbf1c8e36153be7 talk:be@5000
b2987fbea14e51cc7b4ddfcc7bc767ee6e7d4a09857ddabb9d0a5a680be6a714 recap:docs@5000
+b2a99d49993c9851e0ba392ee87c864f831d47651b57706970d695a471c11967 home:swarm:p1@1234
b31f451d884e5af7e9120f0456f994e049d8fafda4b014a76af3cf751cd96705 recap:docs:unreadfail@600
+b65873f886da7017decf982177999e06d675cc158414f76acce2839cbd05646b lead:loading@0
b69db76ef91afb9968df7483b44448dbcdd78cf2bfa449dcbe3ee0df3f17ae25 recap:desk:viet@5000
b6e4fb3070cc13683d734e9bc6e1f104b71f8aaf949478c8e1d1b4c60c1f3d66 tabs:1@0
bb3500cd77cfe1b2bf6148f2f61814b9b0969bcbd61bf0f6e2dab39d8d40c8ab agent:be:offline@1234
@@ -221,6 +250,7 @@ c158dad57e29a9df5ca9b0169c6f1367dac791a7126326aeca42ee6cfc67e090 tabs:1@2500
c443af989eb93dc9f11d473e90a91bf613767f903f194bea8b0079d707a631dd tabs:working@600
c4af0eaee2c62b423f4d3bcb3a8539098c4ffb95f64dd94b1665ea8112fb1e51 tabs:long@2500
c535233a8ccffe6e34bd2767b32fc79e8cfd0929967fcb3b6a515479700804d9 recap:desk:viet@0
+c5e30d82a2680e2f7cbdff04cad612f8b418a69af267238294b9d4981e3df4fe lead:ask@600
c80992f8fc1e4a7c9a2c04b19ae6b33948f455d47c66d08c38f44531e58bdc3d recap:desk:long@600
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@0
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@1234
@@ -228,6 +258,7 @@ c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@5000
c936f3d986e84d734756ea015c2f389714618914fe53bc6d8f1ac3217589148c agent:fw:toast@0@600
c94fb8ea8955544b06c3b0120dbedac4d295f98a9ac48c8172037531fcca9d69 agent:fw:long@600
+ca82468f2f504f1609ea6ad0a41daa8de829e7d78720710868be72e9ee1973dd home:swarm:remote@2500
cacbb92aabbda5f6c5f2a3415fe6ee6738d297ad04a965a2d75146def704c6f9 recap:desk:medium@2500
cb3173536ee26106bde53894630e1e172f58d7186f8170bb193309b2f1908a1f agent:cli:banner@2500
cb3173536ee26106bde53894630e1e172f58d7186f8170bb193309b2f1908a1f agent:cli@2500
@@ -258,12 +289,14 @@ d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:banner@60
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:bell@600
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs:linkdown@600
d46cf19e2e6fac11b823004de27d2351d01870f5cfecb1486187161754f59d45 tabs@600
+d547696fb2c4b18d10790f2ba5b3aaa2f7c51688080ad3e9d1788e1289e735bf lead:loading@2500
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@0
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@1234
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@2500
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@5000
d6591213f2e6735084c2d4ba74350a14ef40e0e4b008b32d86d3bf0c11f9e49f inbox:viet@600
d750a984bfeeb870e18c3291aad2cdd2f6f12b7c4c04c87bdf60f1143ea8ad02 tabs:working@1234
+d93ce2029eb31540b78e76efa0013843c9c5ec125569aa6dbdf63a4965718f0c lead:none@600
d95387eb8f4a5e443d31a5fe2c2a25b5d8cba9b0304b25ed2b63250f6ce3d308 recap:desk:viet@600
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@0
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@1234
@@ -271,6 +304,7 @@ d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@5000
d98e5146f84246d2e794ca51cc07961c82d1d5c7368c958638c0fdc21b9b4ff0 agent:fw:toast:decision@2500@600
de7fccfd4d9ed624772a2c8d137e182ca0697f72b421dc21d1bb4ce4bc8bf594 tabs:none@2500
+dfb664b93e94509505dc4ea3a3885af52f9dc464e744c1c70f6ed886b9bc2c9e home:swarm:remote@1234
e01801d7676609320823ae0c55a805defab02449150ee721b8b774f8e85a7294 recap:desk:medium@0
e16e322edb920b4cff7d04ca1cb2c8202987f3734183bea64c59a7086b6ba830 agent:cli:long@5000
e1788054013a3e7d0de30c89a433ced3cb54ecca26683ffbff6693e33ab5df09 tabs:notices@0
@@ -281,11 +315,13 @@ e1788054013a3e7d0de30c89a433ced3cb54ecca26683ffbff6693e33ab5df09 tabs:notices@6
e1ff6c4a58d744e05300c2a57be4e08d5f29cc531a741a83c649a892ab7de29a recap:desk:long@1234
e55b4e490d71c454af6cd36f6778798a187eacfcce2b18ca7579fffc5b386bb0 agent:cli:banner@600
e55b4e490d71c454af6cd36f6778798a187eacfcce2b18ca7579fffc5b386bb0 agent:cli@600
+e55c5558366c433bf6744046dfc90aba9040f8f400a9fb4741f390116eec696f home:swarm:p2@600
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@0
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@1234
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@2500
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@5000
e652d520e88b1d12b1fe7409e957a1065d69f7683ce6d1e8cd2caaca93c725ad tabs:2+2@600
+e6a3ea32881c13627d6043a18efae1b4578e2c62467b1989129c0a8da1b57032 lead:none@1234
e6a7fa14ee6c9191350176f8dfcf0661da526268a3d14d912f6337e048b39cbf tabs:1@1234
e8f82832b80bcf61502a843b8ebc9523b41386be13fdafcc1cf2d5f5e00922ad inbox:quiet@0
e8f82832b80bcf61502a843b8ebc9523b41386be13fdafcc1cf2d5f5e00922ad inbox:quiet@1234
@@ -299,6 +335,7 @@ ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:banner@25
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:bell@2500
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs:linkdown@2500
ec35e5383f8ca65a2fd44da47c5c0c7b750d323a87d2be81bede059ba5136a00 tabs@2500
+ec4a2a8da59af8b0a9bc0fce6675614ae5961a408af020f73d2bdcb053441d72 home:swarm:remote@600
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@0
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@1234
ed3b9ffee34222fb5499eda318248770bbf67bcfa6d7e5e7c611a3c00b531683 agent:fw:toast@2500@2500
@@ -309,6 +346,7 @@ ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@1234
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@2500
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@5000
ed64d7183a23b8413ca0aefa730b0e0022fbda46883e9c072d0c73f474676073 tabs:3@600
+f1d546d7076d8fcbdb55c72e01cdf190a4fe0915c52c3c6c874310847c0c47eb home:swarm:p2@1234
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@0
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@1234
f3cfa611694ec63ff33c63932078abb9cf5abde24fe2c79c9cb252164b954675 agent:kilo@2500
@@ -323,8 +361,10 @@ f5336aa91a6c4989c444f12a3b9ec5e050f8496501eda04f4c52b23e9ae55d08 tabs:5@600
f6144683873654c1812667702bbed73c7cb8c8bdbab53bb9c49d13fc5ccbf180 recap:docs:long@600
f8a9d033bd6f6db33f4168d086f3aafae4dff0880e7f4301762ca35caf0c5f20 talk:cur@0
f8a9d033bd6f6db33f4168d086f3aafae4dff0880e7f4301762ca35caf0c5f20 talk:cur@1234
+f91e521853337d3a49b701a5638e4dc9b75497b80ff5aeacd3bf3f13673b266c home:swarm:p2@0
fbc885b17d01eadab52928be9eb2c3abf60bc351a280ac69a15b2c99b1664e8b tabs:seven@600
fc3bf40809cb606d7b0f777017dc1c9de85edebe1f3623ca13919b1495b73ff9 tabs:1@5000
+fe5900f7b4edb2b707d1b4106307c624817255140c84b34a0b5e8d027e30f7f2 home:swarm:p1@0
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw:banner@2500
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw:unread@2500
ffa3bcedf2d77ad95edfe7f925134134bbb8451a7973b39e94ba5a7f7fd2f232 agent:fw@2500
diff --git a/devices/harness-pro/firmware/test/pod_render.c b/devices/harness-pro/firmware/test/pod_render.c
index 3dcbce93b..8ea15041d 100644
--- a/devices/harness-pro/firmware/test/pod_render.c
+++ b/devices/harness-pro/firmware/test/pod_render.c
@@ -15,6 +15,13 @@
#include "pod/pod_view.h"
#include "pro_canvas.h"
+// A recap only lands on a Lead that was asked for (LOADING), as the Lead view does: the fixtures ask first.
+static void asked_recap(pod_model_t *m, const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ pod_model_supertab_loading(m, tab, lead);
+ pod_model_supertab_recap(m, tab, lead, text, at, none);
+}
+
#define T0 100000u
typedef struct { const char *id, *name, *engine, *machine; } demo_agent_t;
@@ -270,7 +277,7 @@ static void write_spec(const char *path, const char *screen)
}
fputc('}', f);
}
- static const char *const act[] = {"NONE", "BACK", "BANNER", "OPEN_TAB", "OPEN_AGENT", "PREV", "NEXT", "TALK", "RECAP", "PANES", "TABS", "INBOX", "OPEN_NOTIF", "FOLLOW", "SCROLL", "ENTER_TAB"};
+ static const char *const act[] = {"NONE", "BACK", "BANNER", "OPEN_TAB", "OPEN_AGENT", "PREV", "NEXT", "TALK", "RECAP", "PANES", "TABS", "INBOX", "OPEN_NOTIF", "FOLLOW", "SCROLL", "ENTER_TAB", "LEAD"};
fprintf(f, "],\"hits\":[");
for (int i = 0; i < F.hit_count; i++) {
const pod_hit_t *h = &F.hits[i];
@@ -300,6 +307,61 @@ static void supertab_ask(const char *id, const char *name, const char *q, pod_at
pod_model_unread_ask(&M, id, name, q, T0);
}
+// home:swarm:<p1|p2|remote>: Home on a Swarm card (the mockup swarm-card.html A1 / A3, and a Swarm with Leads on other machines). p1 and p2 are the desk's first tab linked to
+// "openharness" (4 workspaces, one Lead each); remote is a Swarm with no desk tab (its own page) whose Leads run on other people's machines.
+static void swarm_fixture(const char *kind)
+{
+ static pod_swarm_t sw;
+ static const char ids[2][ID_MAX] = {"sw1", "sw2"};
+ struct { const char *id, *project, *engine, *owner, *local; pod_lead_state_t st; unsigned since; } mine[4] = {
+ {"l1", "mobile", "muse", "", "h1", POD_LEAD_ASK, 0}, {"l2", "harness", "claude", "", "h2", POD_LEAD_WORK, 134},
+ {"l3", "website", "codex", "", "h3", POD_LEAD_WORK, 48}, {"l4", "backend", "codex", "", "h4", POD_LEAD_DONE, 0}},
+ theirs[3] = {{"r1", "ops", "claude", "Linh Tran", "", POD_LEAD_WORK, 0}, {"r2", "billing-service", "codex", "Minh", "", POD_LEAD_STUCK, 0}, {"r3", "docs", "muse", "", "h5", POD_LEAD_DONE, 0}};
+ const bool remote = !strcmp(kind, "remote");
+ pod_model_supertab_ids(&M, ids, remote ? 2 : 1);
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw1"); snprintf(sw.tab, ID_MAX, "%s", M.tabs[0].id); snprintf(sw.name, sizeof sw.name, "openharness");
+ sw.count = 4; sw.lead_n = 4;
+ for (int i = 0; i < 4; i++) {
+ pod_lead_t *l = &sw.leads[i];
+ snprintf(l->id, ID_MAX, "%s", mine[i].id); snprintf(l->project, sizeof l->project, "%s", mine[i].project); snprintf(l->engine, sizeof l->engine, "%s", mine[i].engine);
+ snprintf(l->local, ID_MAX, "%s", mine[i].local); l->state = mine[i].st; l->since_s = mine[i].since;
+ }
+ pod_model_supertab(&M, &sw, 0);
+ if (remote) {
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw2"); snprintf(sw.name, sizeof sw.name, "Shared launch"); sw.count = 3; sw.lead_n = 3;
+ for (int i = 0; i < 3; i++) {
+ pod_lead_t *l = &sw.leads[i];
+ snprintf(l->id, ID_MAX, "%s", theirs[i].id); snprintf(l->project, sizeof l->project, "%s", theirs[i].project); snprintf(l->engine, sizeof l->engine, "%s", theirs[i].engine);
+ snprintf(l->owner, sizeof l->owner, "%s", theirs[i].owner); snprintf(l->local, ID_MAX, "%s", theirs[i].local); l->state = theirs[i].st;
+ }
+ pod_model_supertab(&M, &sw, 0);
+ pod_nav_act(&N, &M, POD_A_SCROLL, M.tab_count, T0); // the page after the tabs
+ } else {
+ pod_nav_act(&N, &M, POD_A_SCROLL, 0, T0);
+ if (!strcmp(kind, "p2")) N.swarm_page = 1;
+ }
+}
+
+// lead:<loaded|ask|loading|none|remote>: the Lead view over Home (the mockup swarm-card.html B1, B2, and the loading, no-message and remote-Lead states). loaded: the working
+// "harness" Lead (B1); ask: "mobile", which needs you (B2, the orange edge); loading: "website" before its message came; none: "backend", which has said nothing; remote:
+// a Lead on another person's machine (its owner shown, no talk).
+static void lead_fixture(const char *kind)
+{
+ const bool remote = !strcmp(kind, "remote");
+ swarm_fixture(remote ? "remote" : "p1");
+ const pod_swarm_t *sw = pod_model_swarm(&M, remote ? "sw2" : "sw1");
+ const int at = remote ? 0 : !strcmp(kind, "loaded") ? 1 : !strcmp(kind, "ask") ? 0 : !strcmp(kind, "loading") ? 2 : 3;
+ if (!pod_nav_open_lead(&N, &M, sw->id, at)) { fprintf(stderr, "lead:%s: the Lead view did not open\n", kind); exit(2); }
+ const char *id = sw->leads[at].id;
+ if (!strcmp(kind, "loaded")) asked_recap(&M, sw->id, id, "PR #1492 is merged and backend 1.2.100 is on production. The Pro took the test flash. Next: waiting for you to try it on the device.", 1792560000u, false);
+ else if (!strcmp(kind, "ask")) asked_recap(&M, sw->id, id, "iOS 1.0.9 finished building. Do you want it on TestFlight now, or wait for the Android banner fix?", 1792560000u, false);
+ else if (remote) asked_recap(&M, sw->id, id, "Staging is up on the new region. I am moving the queue workers over now; the first batch should land within the hour.", 1792560000u, false);
+ else if (!strcmp(kind, "loading")) pod_model_supertab_loading(&M, sw->id, id);
+ else asked_recap(&M, sw->id, id, NULL, 0, true);
+}
+
int main(int argc, char **argv)
{
const char *spec = NULL;
@@ -354,6 +416,10 @@ int main(int argc, char **argv)
pod_model_turn(&M, "site", "activity", "Building the landing page", 20, T0);
}
pod_nav_act(&N, &M, POD_A_SCROLL, POD_HOME_WORKING, T0);
+ } else if (!strncmp(screen, "home:swarm:", 11)) {
+ swarm_fixture(screen + 11);
+ } else if (!strncmp(screen, "lead:", 5)) {
+ lead_fixture(screen + 5);
} else if (!strcmp(screen, "tabs:9")) more_tabs(3); // nine tabs: more than one page
else if (!strcmp(screen, "tabs:seven") || !strcmp(screen, "tabs:single")) cover_tabs(!strcmp(screen, "tabs:seven"));
else if (!strcmp(screen, "tabs:none")) { static const char *const *no_ids[1]; static const uint8_t no_n[1]; pod_model_swarms(&M, NULL, no_ids, no_n, 0, "", NULL, 0); pod_model_question_close(&M, "cli"); for (unsigned i = 0; i < sizeof AGENTS / sizeof AGENTS[0]; i++) pod_model_turn(&M, AGENTS[i].id, "done", NULL, 0, T0); } // the first screen: no tabs, nobody working (else the Working card)
diff --git a/devices/harness-pro/firmware/test/stress_pro_app.c b/devices/harness-pro/firmware/test/stress_pro_app.c
index aec12764a..a14625a11 100644
--- a/devices/harness-pro/firmware/test/stress_pro_app.c
+++ b/devices/harness-pro/firmware/test/stress_pro_app.c
@@ -62,6 +62,7 @@ void pro_display_set_brightness(uint8_t l) { (void)l; }
void pro_display_power(bool on) { (void)on; }
pro_touch_sample_t pro_touch_poll(int *x, int *y) { (void)x; (void)y; return PRO_TOUCH_NONE; }
bool pro_cable_send_open(const char *id) { CHECK(LOCK_DEPTH == 0); (void)id; return true; }
+bool pro_cable_supertab_send(const char *t, const char *tab, const char *lead) { CHECK(LOCK_DEPTH == 0); (void)t; (void)tab; (void)lead; return true; }
bool pro_cable_send_scroll(pro_scroll_phase_t phase, int dy, int velocity) { (void)phase; (void)dy; (void)velocity; return true; }
static int lib_req_offset = -1;
static uint32_t lib_req_id;
diff --git a/devices/harness-pro/firmware/test/test_ph_glue.c b/devices/harness-pro/firmware/test/test_ph_glue.c
index 0cd989dbe..4b8dc7e4f 100644
--- a/devices/harness-pro/firmware/test/test_ph_glue.c
+++ b/devices/harness-pro/firmware/test/test_ph_glue.c
@@ -8,6 +8,13 @@
#include "app/pod_glue.h"
#include "pod/home/ph.h"
+// A recap only lands on a Lead that was asked for (LOADING), as the Lead view does: the fixtures ask first.
+static void asked_recap(pod_model_t *m, const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ pod_model_supertab_loading(m, tab, lead);
+ pod_model_supertab_recap(m, tab, lead, text, at, none);
+}
+
static int checks;
#define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL line %d: %s\n", __LINE__, #c); abort(); } checks++; } while (0)
@@ -1647,8 +1654,405 @@ static void working_card_tap_and_back(void) {
CHECK(o.fx == POD_FX_NONE && changed && U.nav.depth == 1);
}
+
+// Home's Swarm card: tab "s1" (Build) is linked to Swarm sw1 with n Leads, an unlinked Swarm sw2 follows the tabs. A swipe in the pet band pages the Leads,
+// past the last page it moves to the next card, anywhere else it pages cards; a tap on a pet is a POD_A_LEAD hit and opens nothing yet.
+static void swarm_home(int n) {
+ fresh();
+ pod_model_question_close(&U.model, "a4"); // no notice: no Notices card
+ calm(); pod_model_turn(&U.model, "a4", "done", NULL, 0, 31); // nobody works: no Working card
+ static const char sw_ids[2][ID_MAX] = {"sw1", "sw2"};
+ static pod_swarm_t sw;
+ pod_model_supertab_ids(&U.model, sw_ids, 2);
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw1"); snprintf(sw.tab, ID_MAX, "s1"); snprintf(sw.name, sizeof sw.name, "openharness");
+ sw.count = (uint16_t)n; sw.lead_n = (uint8_t)n;
+ for (int i = 0; i < n; i++) {
+ snprintf(sw.leads[i].id, ID_MAX, "l%d", i); snprintf(sw.leads[i].project, sizeof sw.leads[i].project, "proj%d", i);
+ snprintf(sw.leads[i].engine, sizeof sw.leads[i].engine, "claude"); sw.leads[i].state = POD_LEAD_DONE;
+ }
+ pod_model_supertab(&U.model, &sw, 1000);
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw2"); snprintf(sw.name, sizeof sw.name, "Solo"); sw.count = 1; sw.lead_n = 1;
+ snprintf(sw.leads[0].id, ID_MAX, "s0"); snprintf(sw.leads[0].project, sizeof sw.leads[0].project, "ops"); snprintf(sw.leads[0].engine, sizeof sw.leads[0].engine, "claude");
+ pod_model_supertab(&U.model, &sw, 1000);
+ U.nav.stack[0].scroll = 0;
+ render(2000);
+}
+static void swarm_card_pages(void) {
+ swarm_home(4);
+ CHECK(pod_tabs_pages_of(&U.nav, &U.model) == 3 && top()->scroll == 0 && U.nav.swarm_page == 0); // Build (the Swarm), Docs, then Solo with no desk tab
+ CHECK(find(POD_A_LEAD) && !find(POD_A_ENTER_TAB));
+ swipe(600, 430, 200, 440, 3000); // the pet band: the second page of Leads
+ CHECK(U.nav.swarm_page == 1 && top()->scroll == 0);
+ swipe(600, 256, 200, 440, 3300); // the band's first row; past the last page: the next card
+ CHECK(top()->scroll == 1 && U.nav.swarm_page == 0);
+ swipe(200, 150, 600, 160, 3600); // back on the Swarm
+ CHECK(top()->scroll == 0);
+ swipe(600, 430, 200, 440, 4000);
+ swipe(200, 536, 600, 440, 4300); // the band's last row, to the first page
+ CHECK(U.nav.swarm_page == 0 && top()->scroll == 0);
+ swipe(200, 430, 600, 440, 4600); // before the first page: no card before it, nothing moves
+ CHECK(U.nav.swarm_page == 0 && top()->scroll == 0);
+ swipe(600, 430, 200, 440, 5000);
+ swipe(600, 150, 200, 160, 5300); // the title area pages cards and the Leads go back to page 0
+ CHECK(top()->scroll == 1 && U.nav.swarm_page == 0);
+ swipe(600, 150, 200, 160, 5600); // Solo, the Swarm with no desk tab, is the last page
+ CHECK(top()->scroll == 2);
+ render(6000);
+ CHECK(find(POD_A_LEAD) && !strcmp(find(POD_A_LEAD)->id, "sw2"));
+ swipe(600, 430, 200, 440, 6300); // one page of Leads only: the band swipe moves on, and there is no card after the last
+ CHECK(top()->scroll == 2);
+ swipe(200, 430, 600, 440, 6600); // and back
+ CHECK(top()->scroll == 1);
+}
+static void swarm_card_few_leads(void) {
+ swarm_home(3); // exactly 3: nothing to page, so the band swipe pages cards like any other
+ swipe(600, 430, 200, 440, 3000);
+ CHECK(U.nav.swarm_page == 0 && top()->scroll == 1);
+}
+static uint32_t NOW = 3000; // the clock a focus is fed (the quiet window counts from the last touch)
+static pod_supertab_out_t Q[POD_SUPERTAB_OUT_MAX];
+static int take(void) { return pod_ui_take_supertab(&U, Q, POD_SUPERTAB_OUT_MAX); }
+static bool is_q(int i, const char *t, const char *tab, const char *lead) { return !strcmp(Q[i].t, t) && !strcmp(Q[i].tab, tab) && !strcmp(Q[i].lead, lead); }
+static void tap_lead(int k, uint32_t t) { // a tap on the pet of the card's Lead at index k (the page holding it must be on screen)
+ render(t - 50);
+ for (int i = 0; i < U.frame.hit_count; i++)
+ if (U.frame.hits[i].action == POD_A_LEAD && U.frame.hits[i].arg == k) { tap_(U.frame.hits[i].x + U.frame.hits[i].w / 2, U.frame.hits[i].y + U.frame.hits[i].h / 2, t); return; }
+ CHECK(!"no hit for that Lead");
+}
+static void swarm_card_tap(void) {
+ swarm_home(4);
+ const pod_hit_t *h = find(POD_A_LEAD);
+ CHECK(h && h->arg == 0 && !strcmp(h->id, "sw1"));
+ const int x = h->x + h->w / 2, y = h->y + h->h / 2;
+ pod_out_t o = tap_(x, y, 3000); // the tap opens the Lead view over Home (the card's page stays under it) and picks the Lead on the desktop
+ CHECK(o.fx == POD_FX_NONE && U.nav.depth == 2 && top()->view == POD_V_LEAD && U.nav.stack[0].view == POD_V_TABS && U.nav.stack[0].scroll == 0);
+ CHECK(!strcmp(top()->swarm, "sw1") && !strcmp(top()->lead_id, "l0") && top()->lead == 0);
+ swarm_home(4);
+ swipe(600, 430, 200, 440, 4000);
+ render(4500);
+ h = find(POD_A_LEAD);
+ CHECK(h && h->arg == 3 && !strcmp(h->id, "sw1"));
+ CHECK(tap_(h->x + h->w / 2, h->y + h->h / 2, 5000).fx == POD_FX_NONE && top()->view == POD_V_LEAD && top()->lead == 3 && U.nav.swarm_page == 1);
+}
+
+// ---- the Lead view ----
+static void lead_tap_sends(void) {
+ swarm_home(4);
+ tap_lead(1, 3000);
+ CHECK(top()->view == POD_V_LEAD && top()->lead == 1 && !strcmp(top()->lead_id, "l1"));
+ CHECK(take() == 3 && is_q(0, "supertab.select", "sw1", "l1") && is_q(1, "supertab.open", "sw1", "l1") && is_q(2, "supertab.recap.get", "sw1", "l1"));
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_LOADING && take() == 0); // asked once; nothing repeats while nothing changes
+ render(3500);
+ CHECK(U.frame.hit_count == 0);
+ // the text arrives: LOADED, nothing more is sent
+ pod_ui_supertab_recap(&U, "sw1", "l1", "Merged.", 1792560000u, false);
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_LOADED && take() == 0);
+ pod_nav_act(&U.nav, &U.model, POD_A_BACK, 0, 4000);
+ CHECK(take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_NONE && U.model.swarms[0].leads[1].text == NULL); // closed: its text would go stale, so it goes
+ // a Lead whose text is already LOADED is not asked for again: select and open only
+ swarm_home(4);
+ asked_recap(&U.model, "sw1", "l2", "Cached.", 1, false);
+ tap_lead(2, 3000);
+ CHECK(take() == 2 && is_q(0, "supertab.select", "sw1", "l2") && is_q(1, "supertab.open", "sw1", "l2"));
+}
+// A lost supertab.open / supertab.recap.get is asked again every 3 s while the Lead is LOADING (5 times at most); a loaded Lead hears supertab.open once more.
+static void lead_retry(void) {
+ swarm_home(4);
+ tap_lead(1, 3000);
+ CHECK(take() == 3 && U.model.swarms[0].leads[1].recap == POD_RECAP_LOADING);
+ render(5000);
+ CHECK(take() == 0); // not yet
+ for (int k = 1; k <= POD_SUPERTAB_RETRIES; k++) {
+ render(3000 + 3000u * (uint32_t)k);
+ CHECK(take() == 2 && is_q(0, "supertab.open", "sw1", "l1") && is_q(1, "supertab.recap.get", "sw1", "l1"));
+ render(3000 + 3000u * (uint32_t)k + 2999);
+ CHECK(take() == 0);
+ }
+ render(60000);
+ CHECK(take() == 0 && U.model.swarms[0].leads[1].recap == POD_RECAP_LOADING); // then it stops, the "…" stays
+ // a send the link dropped is not counted: the retry comes again in 3 s
+ swarm_home(4);
+ tap_lead(1, 3000);
+ CHECK(take() == 3);
+ render(6000);
+ CHECK(take() == 2);
+ pod_ui_supertab_unsent(&U, Q[0].t);
+ pod_ui_supertab_unsent(&U, Q[1].t);
+ render(8999);
+ CHECK(take() == 0);
+ render(9000);
+ CHECK(take() == 2 && U.sup_tries == 1);
+ // a Lead that answered is told once more that it is open, then left alone
+ pod_ui_supertab_recap(&U, "sw1", "l1", "Merged.", 1792560000u, false);
+ render(12000);
+ CHECK(take() == 1 && is_q(0, "supertab.open", "sw1", "l1"));
+ render(20000);
+ CHECK(take() == 0);
+ // a re-open that was dropped is owed again
+ swarm_home(4);
+ pod_model_supertab_loading(&U.model, "sw1", "l2");
+ asked_recap(&U.model, "sw1", "l2", "Cached.", 1, false);
+ tap_lead(2, 3000);
+ CHECK(take() == 2);
+ render(6000);
+ CHECK(take() == 1);
+ pod_ui_supertab_unsent(&U, Q[0].t);
+ render(9000);
+ CHECK(take() == 1 && is_q(0, "supertab.open", "sw1", "l2"));
+ // a full queue records nothing: the next sync sends the whole of it
+ swarm_home(4);
+ tap_lead(1, 3000);
+ U.sup_qn = POD_SUPERTAB_OUT_MAX - 1;
+ CHECK(take() == POD_SUPERTAB_OUT_MAX - 1 && U.sup_lead[0] == 0 && U.model.swarms[0].leads[1].recap == POD_RECAP_NONE);
+ CHECK(take() == 2 && is_q(0, "supertab.open", "sw1", "l1") && is_q(1, "supertab.recap.get", "sw1", "l1") && U.model.swarms[0].leads[1].recap == POD_RECAP_LOADING);
+}
+static void lead_swipe_steps(void) {
+ swarm_home(4);
+ tap_lead(1, 3000);
+ CHECK(take() == 3);
+ pod_ui_supertab_recap(&U, "sw1", "l1", "One.", 1, false);
+ render(3500);
+ swipe(600, 400, 200, 410, 4000); // left: the next Lead, in card order
+ CHECK(top()->view == POD_V_LEAD && top()->lead == 2 && !strcmp(top()->lead_id, "l2") && U.nav.depth == 2);
+ CHECK(take() == 3 && is_q(0, "supertab.select", "sw1", "l2") && is_q(1, "supertab.open", "sw1", "l2") && is_q(2, "supertab.recap.get", "sw1", "l2"));
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_NONE); // the one left goes cold
+ swipe(200, 400, 600, 410, 5000); // right: back to the previous
+ CHECK(top()->lead == 1 && take() == 3 && is_q(0, "supertab.select", "sw1", "l1"));
+ swipe(200, 400, 600, 410, 6000);
+ swipe(200, 400, 600, 410, 7000);
+ CHECK(top()->lead == 3); // before the first Lead is the last: the Leads go round like panes
+ CHECK(take() >= 3);
+ swipe(600, 400, 200, 410, 8000);
+ CHECK(top()->lead == 0);
+ CHECK(sc_events == 0); // no pane of the host scrolls for a swipe or a drag here
+ // a Swarm with one Lead has nowhere to go: no select
+ swarm_home(4);
+ U.nav.stack[0].scroll = 2;
+ render(2000);
+ tap_lead(0, 3000);
+ CHECK(!strcmp(top()->swarm, "sw2") && take() == 3);
+ swipe(600, 400, 200, 410, 4000);
+ CHECK(top()->lead == 0 && take() == 0);
+}
+static void lead_leave_closes(void) {
+ swarm_home(4);
+ swipe(600, 430, 200, 440, 2500); // the second page of Leads
+ CHECK(U.nav.swarm_page == 1);
+ tap_lead(3, 3000);
+ CHECK(top()->view == POD_V_LEAD && take() == 3);
+ CHECK(U.nav.depth == 2 && U.nav.swarm_page == 1); // Home kept the page it was on under the view
+ pod_nav_act(&U.nav, &U.model, POD_A_BACK, 1, 4000); // the side button
+ CHECK(U.nav.depth == 1 && U.nav.swarm_page == 1 && take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+ render(4500);
+ CHECK(find(POD_A_LEAD) && find(POD_A_LEAD)->arg == 3); // back on the card, on the page the person left
+ // a swipe up from the bottom zone is Home too
+ tap_lead(3, 5000);
+ CHECK(top()->view == POD_V_LEAD && take() == 3);
+ render(5500);
+ swipe(360, 690, 360, 400, 6000);
+ CHECK(U.nav.depth == 1 && U.nav.swarm_page == 1 && take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+ // Notices over the view closes it for the desktop, and Back from Notices opens it again
+ tap_lead(3, 7000);
+ take();
+ pod_nav_act(&U.nav, &U.model, POD_A_INBOX, 0, 7500);
+ CHECK(top()->view == POD_V_INBOX && take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+ pod_nav_act(&U.nav, &U.model, POD_A_BACK, 1, 8000);
+ CHECK(top()->view == POD_V_LEAD && take() == 2 && is_q(0, "supertab.open", "sw1", "l3") && is_q(1, "supertab.recap.get", "sw1", "l3"));
+}
+static void lead_scrolls(void) {
+ swarm_home(4);
+ tap_lead(0, 3000);
+ take();
+ pod_ui_supertab_recap(&U, "sw1", "l0", "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty "
+ "twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty thirty-one thirty-two", 1, false);
+ render(3500);
+ CHECK(pod_scroll_max(&U.nav, &U.model) > 1 && top()->scroll == 0);
+ t_(true, 360, 500, 4000); t_(true, 360, 400, 4100); t_(true, 360, 300, 4200); t_(false, 360, 300, 4250);
+ CHECK(top()->view == POD_V_LEAD && top()->scroll >= 1 && top()->lead == 0 && sc_events == 0 && take() == 0); // the drag moved the text, not the host's pane, and sent nothing
+ t_(true, 360, 300, 5000); t_(true, 360, 500, 5100); t_(true, 360, 700, 5200); t_(false, 360, 700, 5250);
+ CHECK(top()->scroll == 0);
+}
+static void lead_talk(void) {
+ swarm_home(4);
+ pod_swarm_t *sw = (pod_swarm_t *)pod_model_swarm(&U.model, "sw1");
+ snprintf(sw->leads[1].local, ID_MAX, "a1"); // Alpha is this Lead's harness
+ snprintf(sw->leads[2].local, ID_MAX, "nobody"); // a harness the roster does not hold: nothing to talk to
+ tap_lead(1, 3000);
+ CHECK(!strcmp(top()->agent, "a1") && take() == 3);
+ render(3500);
+ pod_out_t o = tap_(MID_X, MID_Y, 4000); // a tap on the view: talk to the harness
+ CHECK(o.fx == POD_FX_VOICE_BEGIN && !strcmp(o.agent, "a1") && top()->view == POD_V_TALK && !strcmp(top()->swarm, "sw1") && take() == 0); // still the open recap: no close
+ render(4500);
+ o = tap_(MID_X, MID_Y, 5000);
+ CHECK(o.fx == POD_FX_VOICE_END && top()->view == POD_V_TALK);
+ pod_ui_talk_over(&U);
+ CHECK(top()->view == POD_V_LEAD && take() == 0 && U.nav.depth == 2);
+ // a step while talking moves nothing
+ pod_nav_act(&U.nav, &U.model, POD_A_TALK, 0, 6000);
+ CHECK(top()->view == POD_V_TALK);
+ pod_nav_act(&U.nav, &U.model, POD_A_NEXT, 0, 6100);
+ CHECK(top()->view == POD_V_TALK && top()->lead == 1);
+ pod_ui_talk_over(&U);
+ // a remote Lead, or one whose harness is not on the roster, has no talk control
+ swipe(600, 400, 200, 410, 7000);
+ CHECK(top()->lead == 2 && !top()->agent[0]);
+ render(7500);
+ CHECK(tap_(MID_X, MID_Y, 8000).fx == POD_FX_NONE && top()->view == POD_V_LEAD);
+ swipe(600, 400, 200, 410, 9000);
+ CHECK(top()->lead == 3 && !top()->agent[0] && tap_(MID_X, MID_Y, 10000).fx == POD_FX_NONE && top()->view == POD_V_LEAD);
+ CHECK(pod_nav_act(&U.nav, &U.model, POD_A_TALK, 0, 11000).fx == POD_FX_NONE && top()->view == POD_V_LEAD);
+}
+static void lead_focus(void) {
+ swarm_home(4);
+ pod_ui_supertab_focus(&U, "sw1", "l2", NOW); // the desktop opened that project
+ CHECK(U.nav.depth == 2 && top()->view == POD_V_LEAD && top()->lead == 2 && !U.model.focus_pending && U.nav.stack[0].scroll == 0 && U.nav.swarm_page == 0);
+ CHECK(take() == 2 && is_q(0, "supertab.open", "sw1", "l2") && is_q(1, "supertab.recap.get", "sw1", "l2")); // no select: the desktop is already there
+ pod_ui_supertab_focus(&U, "sw1", "l2", NOW); // the same Lead again: nothing changes
+ CHECK(top()->lead == 2 && take() == 0);
+ pod_ui_supertab_focus(&U, "sw1", "l3", NOW); // another: the view moves on, the open recap follows
+ CHECK(top()->lead == 3 && U.nav.swarm_page == 1 && take() == 2 && is_q(0, "supertab.open", "sw1", "l3"));
+ // a Swarm the person has no desk tab for: Home lands on its own page
+ pod_ui_supertab_focus(&U, "sw2", "s0", NOW);
+ CHECK(top()->view == POD_V_LEAD && !strcmp(top()->swarm, "sw2") && U.nav.stack[0].scroll == 2 && U.nav.swarm_page == 0);
+ take();
+ // not while recording
+ swarm_home(4);
+ to_agent(0, 0);
+ render(1000);
+ pod_out_t o = tap_(MID_X, MID_Y, 5000);
+ CHECK(o.fx == POD_FX_VOICE_BEGIN && pod_ui_talking(&U));
+ pod_ui_supertab_focus(&U, "sw1", "l2", NOW);
+ CHECK(pod_ui_talking(&U) && top()->view == POD_V_TALK && !U.model.focus_pending); // dropped, not kept
+ // not while the update is on screen
+ swarm_home(4);
+ pod_ui_ota(&U, "0.1.0", "0.1.1", 30, false);
+ pod_ui_supertab_focus(&U, "sw1", "l2", NOW);
+ CHECK(U.nav.depth == 1 && !U.model.focus_pending);
+ pod_ui_ota(&U, NULL, NULL, -1, false);
+ // not while the person is driving elsewhere (a touch within the quiet window)
+ swarm_home(4);
+ to_agent(0, 2);
+ render(1000);
+ U.touched = true; U.last_touch_ms = 1000; // a touch a moment ago
+ U.model.clock_ms = 1500;
+ pod_ui_supertab_focus(&U, "sw1", "l1", NOW);
+ CHECK(top()->view == POD_V_RECAP && !U.model.focus_pending);
+ // pending until the Swarm list has it
+ swarm_home(4);
+ pod_ui_supertab_focus(&U, "sw9", "x1", NOW);
+ CHECK(U.nav.depth == 1 && U.model.focus_pending);
+ static const char ids[3][ID_MAX] = {"sw1", "sw2", "sw9"};
+ pod_ui_supertab_ids(&U, ids, 3);
+ CHECK(U.nav.depth == 1 && U.model.focus_pending); // listed, not received
+ static pod_swarm_t sw;
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw9"); snprintf(sw.name, sizeof sw.name, "Late"); sw.count = 1; sw.lead_n = 1;
+ snprintf(sw.leads[0].id, ID_MAX, "x1"); snprintf(sw.leads[0].project, sizeof sw.leads[0].project, "p"); snprintf(sw.leads[0].engine, sizeof sw.leads[0].engine, "claude");
+ pod_ui_supertab(&U, &sw, 2000);
+ CHECK(top()->view == POD_V_LEAD && !strcmp(top()->swarm, "sw9") && !U.model.focus_pending && take() == 2);
+ // a focus that never finds its Lead is dropped after the waiting time
+ swarm_home(4);
+ pod_ui_supertab_focus(&U, "sw1", "ghost", NOW);
+ CHECK(U.model.focus_pending);
+ U.model.clock_ms += POD_FOLLOW_PENDING_MS + 100;
+ pod_ui_supertab_ids(&U, ids, 2);
+ CHECK(!U.model.focus_pending && U.nav.depth == 1);
+}
+static void lead_removed(void) {
+ swarm_home(4);
+ tap_lead(1, 3000);
+ take();
+ // l1 leaves: the view moves to the Lead that took its place (the next one)
+ static pod_swarm_t sw;
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw1"); snprintf(sw.tab, ID_MAX, "s1"); snprintf(sw.name, sizeof sw.name, "openharness"); sw.count = 3; sw.lead_n = 3;
+ const char *keep[3] = {"l0", "l2", "l3"};
+ for (int i = 0; i < 3; i++) { snprintf(sw.leads[i].id, ID_MAX, "%s", keep[i]); snprintf(sw.leads[i].project, sizeof sw.leads[i].project, "proj"); snprintf(sw.leads[i].engine, sizeof sw.leads[i].engine, "claude"); }
+ pod_ui_supertab(&U, &sw, 4000);
+ CHECK(U.nav.depth == 2 && top()->view == POD_V_LEAD && !strcmp(top()->lead_id, "l2") && top()->lead == 1);
+ CHECK(take() == 2 && is_q(0, "supertab.open", "sw1", "l2") && is_q(1, "supertab.recap.get", "sw1", "l2"));
+ // it leaves too: the next one again (l3 is now at its index)
+ snprintf(sw.leads[1].id, ID_MAX, "l3"); sw.lead_n = 2;
+ pod_ui_supertab(&U, &sw, 4050);
+ CHECK(!strcmp(top()->lead_id, "l3") && top()->lead == 1 && U.nav.depth == 2);
+ take();
+ // the last Lead leaves while it is the one open: the one before it
+ sw.lead_n = 1;
+ pod_ui_supertab(&U, &sw, 4100);
+ CHECK(!strcmp(top()->lead_id, "l0") && top()->lead == 0 && U.nav.depth == 2 && take() == 2);
+ // the Lead's index moved (a Lead ahead of it arrived): the id still names it
+ snprintf(sw.leads[0].id, ID_MAX, "new"); snprintf(sw.leads[1].id, ID_MAX, "l0"); sw.lead_n = 2;
+ pod_ui_supertab(&U, &sw, 4200);
+ CHECK(!strcmp(top()->lead_id, "l0") && top()->lead == 1 && take() == 0);
+ // none left: Home, and the desktop is told the recap closed
+ sw.lead_n = 0; sw.count = 0;
+ pod_ui_supertab(&U, &sw, 4300);
+ CHECK(U.nav.depth == 1 && take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+ // the Swarm itself goes
+ swarm_home(4);
+ tap_lead(0, 3000);
+ take();
+ static const char ids[1][ID_MAX] = {"sw2"};
+ pod_ui_supertab_ids(&U, ids, 1);
+ CHECK(U.nav.depth == 1 && take() == 1 && is_q(0, "supertab.open", "sw1", ""));
+}
+static void lead_relink(void) {
+ swarm_home(4);
+ tap_lead(1, 3000);
+ take();
+ pod_ui_link(&U, false); // the model drops the list; the view stays and nothing is sent to a dead cable
+ CHECK(top()->view == POD_V_LEAD && U.nav.depth == 2 && take() == 0 && !pod_ui_pet_on_screen(&U));
+ render(3500);
+ pod_ui_link(&U, true);
+ CHECK(top()->view == POD_V_LEAD && take() == 0); // linked, but the daemon has not sent the list yet: wait
+ static const char ids[2][ID_MAX] = {"sw1", "sw2"};
+ pod_ui_supertab_ids(&U, ids, 2);
+ CHECK(top()->view == POD_V_LEAD && take() == 0); // the Swarm is listed, not received
+ static pod_swarm_t sw;
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw1"); snprintf(sw.tab, ID_MAX, "s1"); snprintf(sw.name, sizeof sw.name, "openharness"); sw.count = 4; sw.lead_n = 4;
+ for (int i = 0; i < 4; i++) { snprintf(sw.leads[i].id, ID_MAX, "l%d", i); snprintf(sw.leads[i].project, sizeof sw.leads[i].project, "proj%d", i); snprintf(sw.leads[i].engine, sizeof sw.leads[i].engine, "claude"); }
+ pod_ui_supertab(&U, &sw, 4000);
+ CHECK(top()->view == POD_V_LEAD && !strcmp(top()->lead_id, "l1") && take() == 2 && is_q(0, "supertab.open", "sw1", "l1") && is_q(1, "supertab.recap.get", "sw1", "l1"));
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_LOADING);
+ // after the list comes back without that Swarm the view goes
+ pod_ui_link(&U, false);
+ pod_ui_link(&U, true);
+ static const char one[1][ID_MAX] = {"sw2"};
+ pod_ui_supertab_ids(&U, one, 1);
+ CHECK(U.nav.depth == 1 && take() == 0); // nothing was open as far as the new link knows
+}
+static void swarm_card_shrinks(void) {
+ swarm_home(4);
+ swipe(600, 430, 200, 440, 3000);
+ CHECK(U.nav.swarm_page == 1);
+ static const char sw_ids[1][ID_MAX] = {"sw2"};
+ pod_model_supertab_ids(&U.model, sw_ids, 1); // sw1 is gone: the page list changes under the person
+ pod_nav_sync(&U.nav, &U.model);
+ CHECK(U.nav.swarm_page == 0 && pod_tabs_pages_of(&U.nav, &U.model) == 3); // Build and Docs are plain tab cards again, Solo the last
+ CHECK(top()->scroll == 0);
+ render(6000);
+ CHECK(!find(POD_A_LEAD) && find(POD_A_ENTER_TAB));
+}
+
int main(void) {
notify_while_looking();
+ swarm_card_pages();
+ swarm_card_few_leads();
+ swarm_card_tap();
+ lead_tap_sends();
+ lead_retry();
+ lead_swipe_steps();
+ lead_leave_closes();
+ lead_scrolls();
+ lead_talk();
+ lead_focus();
+ lead_removed();
+ lead_relink();
+ swarm_card_shrinks();
overview_pages();
bottom_up_goes_back();
swipe_up_home();
diff --git a/devices/harness-pro/firmware/test/test_ph_views.c b/devices/harness-pro/firmware/test/test_ph_views.c
index 31d57d6a9..f6a4beb8a 100644
--- a/devices/harness-pro/firmware/test/test_ph_views.c
+++ b/devices/harness-pro/firmware/test/test_ph_views.c
@@ -10,6 +10,13 @@
#include "pod/pod_view_shared.h"
#include "pro_canvas.h"
+// A recap only lands on a Lead that was asked for (LOADING), as the Lead view does: the fixtures ask first.
+static void asked_recap(pod_model_t *m, const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ pod_model_supertab_loading(m, tab, lead);
+ pod_model_supertab_recap(m, tab, lead, text, at, none);
+}
+
static int checks;
#define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL line %d: %s\n", __LINE__, #c); abort(); } checks++; } while (0)
enum { K_TEXT = 1, K_RECT = 2, K_IMAGE = 3, K_RECT_AA = 4, K_RECT_STROKE = 5 };
@@ -1367,6 +1374,195 @@ int main(void) {
fresh(); ph_view_home(&F, &N, &M, now);
CHECK(!text_run("Working") && text_run("Solo") && hits_of(POD_A_FOLLOW) == 0);
}
+ { // Home's Swarm card (the owner's mockup swarm-card.html): a desk tab linked to a Swarm draws it, the Leads as pets three to a page, no dots
+ static pod_model_t M;
+ static pod_nav_t N;
+ static cable_swarm_t sw[1];
+ static const char *const w0[] = {"w1"}, *const *lists[1] = {w0};
+ static uint8_t counts[1] = {1};
+ static const char ids[2][ID_MAX] = {"sw1", "sw2"};
+ static pod_swarm_t S1;
+ struct { const char *id, *project, *engine, *owner, *local; pod_lead_state_t st; unsigned since; } L[4] = {
+ {"l1", "mobile", "muse", "", "h1", POD_LEAD_ASK, 0}, {"l2", "harness", "claude", "", "h2", POD_LEAD_WORK, 134},
+ {"l3", "website", "codex", "", "h3", POD_LEAD_WORK, 48}, {"l4", "backend", "codex", "", "h4", POD_LEAD_DONE, 0}};
+ pod_model_reset(&M);
+ pod_model_agents_begin(&M);
+ pod_model_agent(&M, "w1", "w1", "claude", "Mac");
+ pod_model_agents_end(&M);
+ snprintf(sw[0].id, SWARM_ID_MAX, "desk1"); snprintf(sw[0].name, CABLE_NAME_MAX, "Desk"); sw[0].panes = sw[0].agents = 1;
+ pod_model_swarms(&M, sw, lists, counts, 1, "desk1", NULL, 0);
+ pod_model_link(&M, true);
+ pod_model_supertab_ids(&M, ids, 1); // sw1 only: linked to the desk tab
+ memset(&S1, 0, sizeof S1);
+ snprintf(S1.id, ID_MAX, "sw1"); snprintf(S1.tab, ID_MAX, "desk1"); snprintf(S1.name, sizeof S1.name, "openharness");
+ S1.count = 4; S1.lead_n = 4;
+ for (int i = 0; i < 4; i++) {
+ pod_lead_t *l = &S1.leads[i];
+ snprintf(l->id, ID_MAX, "%s", L[i].id); snprintf(l->project, sizeof l->project, "%s", L[i].project); snprintf(l->engine, sizeof l->engine, "%s", L[i].engine);
+ snprintf(l->owner, sizeof l->owner, "%s", L[i].owner); snprintf(l->local, ID_MAX, "%s", L[i].local); l->state = L[i].st; l->since_s = L[i].since;
+ }
+ pod_model_supertab(&M, &S1, 1000);
+ pod_nav_init(&N);
+ CHECK(M.swarm_n == 1 && pod_home_pages(&M, NULL, 0) == 1 && pod_home_swarm(&M, 0) == &M.swarms[0]); // the desk tab's page IS the Swarm's
+ N.swarm_page = 0; fresh(); ph_view_home(&F, &N, &M, 1000);
+ CHECK(text_run("openharness") && text_run("4") && text_run("workspaces") && !text_run("Desk"));
+ CHECK(text_run("openharness")->x == 90 + 44); // the title where a tab's name is
+ CHECK(text_run("mobile") && text_run("harness") && text_run("website") && !text_run("backend"));
+ CHECK(text_run("needs you") && text_run("needs you")->fg == ht_rgb(0xFFC796));
+ CHECK(text_run("working \xc2\xb7 2:14") && text_run("working \xc2\xb7 2:14")->fg == ht_rgb(0x3EE05B) && text_run("working \xc2\xb7 0:48"));
+ CHECK(hits_of(POD_A_LEAD) == 3 && F.hit_count == 3 && hits_of(POD_A_ENTER_TAB) == 0);
+ for (int k = 0; k < 3; k++) { // centred exactly like the Working card: 165 px apart about the card's middle
+ const pod_hit_t *h = nth_hit(POD_A_LEAD, k);
+ CHECK(h->arg == k && !strcmp(h->id, "sw1") && h->x == 90 + 270 + (k - 1) * 165 - 75 && h->w == 150);
+ }
+ { // the orange dot (14 px) is there while a Lead is ASK, and gone once none is
+ int dots = 0;
+ for (int i = 0; i < S.count; i++) dots += S.runs[i].pro_kind == K_RECT_AA && S.runs[i].w == 14 && S.runs[i].pro_height == 14;
+ CHECK(dots == 1);
+ M.swarms[0].leads[0].state = POD_LEAD_STUCK;
+ fresh(); ph_view_home(&F, &N, &M, 1000);
+ dots = 0;
+ for (int i = 0; i < S.count; i++) dots += S.runs[i].pro_kind == K_RECT_AA && S.runs[i].w == 14 && S.runs[i].pro_height == 14;
+ CHECK(dots == 0 && text_run("stuck") && text_run("stuck")->fg == ht_rgb(0xFFB0B0)); // stuck is red and does not pulse the card's dot
+ M.swarms[0].leads[0].state = POD_LEAD_ASK;
+ }
+ fresh(); ph_view_home(&F, &N, &M, 8000); // the clock runs: 7 s later
+ CHECK(text_run("working \xc2\xb7 2:21") && text_run("working \xc2\xb7 0:55") && ph_home_moves(&N, &M));
+ N.swarm_page = 1; fresh(); ph_view_home(&F, &N, &M, 1000); // the 4th Lead alone, in the middle
+ CHECK(text_run("backend") && text_run("done") && text_run("done")->fg != ht_rgb(0xFFFFFF) && text_run("done")->fg != ht_rgb(0xFFC796) && !text_run("mobile"));
+ CHECK(hits_of(POD_A_LEAD) == 1 && nth_hit(POD_A_LEAD, 0)->arg == 3 && nth_hit(POD_A_LEAD, 0)->x == 90 + 270 - 75);
+ N.swarm_page = 9; fresh(); ph_view_home(&F, &N, &M, 1000); // past the last page: the last
+ CHECK(text_run("backend") && hits_of(POD_A_LEAD) == 1);
+ { // the neighbouring page's Lead peeks in at the card's edge (a veil clips and fades it): the next page's first at the right, the previous page's last at the left
+ #define VEILS(n_) do { n_ = 0; for (int i_ = 0; i_ < S.count; i_++) n_ += S.runs[i_].pro_kind == POD_VEIL; } while (0)
+ int v;
+ N.swarm_page = 0; fresh(); ph_view_home(&F, &N, &M, 1000); VEILS(v);
+ CHECK(v == 1); // page 0 of 2: a next page, no previous
+ for (int i = 0; i < S.count; i++) if (S.runs[i].pro_kind == POD_VEIL) CHECK(S.runs[i].x + S.runs[i].w > 90 + 540 && S.runs[i].x > 90 + 300); // at the right edge
+ N.swarm_page = 1; fresh(); ph_view_home(&F, &N, &M, 1000); VEILS(v);
+ CHECK(v == 1); // the last page: a previous page, no next
+ for (int i = 0; i < S.count; i++) if (S.runs[i].pro_kind == POD_VEIL) CHECK(S.runs[i].x < 90 && S.runs[i].x + S.runs[i].w < 90 + 300); // at the left edge
+ M.swarms[0].lead_n = 7;
+ for (int k = 4; k < 7; k++) M.swarms[0].leads[k] = M.swarms[0].leads[k - 4];
+ N.swarm_page = 1; fresh(); ph_view_home(&F, &N, &M, 1000); VEILS(v);
+ CHECK(v == 2 && hits_of(POD_A_LEAD) == 3); // a middle page: both neighbours
+ M.swarms[0].lead_n = 3;
+ N.swarm_page = 0; fresh(); ph_view_home(&F, &N, &M, 1000); VEILS(v);
+ CHECK(v == 0 && hits_of(POD_A_LEAD) == 3); // one page: nothing peeks
+ M.swarms[0].lead_n = 4;
+ #undef VEILS
+ }
+ { // the gradient is the Swarm's purple, #6A4BB0 -> #22163F
+ unsigned g1 = 0, g2 = 0;
+ for (int i = 0; i < S.count; i++)
+ if (S.runs[i].pro_kind == POD_GRAD && S.runs[i].w == 540) { uint16_t g[2]; memcpy(g, S.runs[i].text, sizeof g); g1 = g[0]; g2 = g[1]; }
+ CHECK(g1 == ht_rgb(0x6A4BB0) && g2 == ht_rgb(0x22163F));
+ }
+ // A remote Lead shows its owner (smaller, muted) under the status; a remote Lead at work has no clock; a Swarm with no desk tab is a page of its own.
+ snprintf(S1.id, ID_MAX, "sw2"); S1.tab[0] = 0; snprintf(S1.name, sizeof S1.name, "Solo swarm"); S1.count = 1; S1.lead_n = 1;
+ snprintf(S1.leads[0].id, ID_MAX, "r1"); snprintf(S1.leads[0].project, sizeof S1.leads[0].project, "ops"); snprintf(S1.leads[0].engine, sizeof S1.leads[0].engine, "claude");
+ snprintf(S1.leads[0].owner, sizeof S1.leads[0].owner, "Linh Tran"); S1.leads[0].local[0] = 0; S1.leads[0].state = POD_LEAD_WORK; S1.leads[0].since_s = 0;
+ pod_model_supertab_ids(&M, ids, 2);
+ pod_model_supertab(&M, &S1, 1000);
+ CHECK(M.swarm_n == 2 && pod_home_pages(&M, NULL, 0) == 2 && pod_home_has(&M, 1) && !pod_home_has(&M, 2)); // page 1 = tab_count + the Swarm's index among the unlinked
+ CHECK(pod_home_swarm(&M, 1) == &M.swarms[1] && pod_tabs_pages_of(&N, &M) == 2);
+ N.stack[0].scroll = 1; N.swarm_page = 0; fresh(); ph_view_home(&F, &N, &M, 1000);
+ CHECK(text_run("Solo swarm") && text_run("workspace") && text_run("ops") && text_run("working") && !text_prefix("working \xc2\xb7") && text_run("Linh Tran"));
+ CHECK(text_run("Linh Tran")->fg != ht_rgb(0xFFFFFF) && hits_of(POD_A_LEAD) == 1 && !strcmp(nth_hit(POD_A_LEAD, 0)->id, "sw2"));
+ CHECK(text_run("Linh Tran")->y > text_run("working")->y);
+ N.stack[0].scroll = 0; fresh(); ph_view_home(&F, &N, &M, 1000); // the next page peeks at the right: its gradient and title only
+ CHECK(text_run("Solo swarm") && !text_run("ops") && hits_of(POD_A_LEAD) == 3);
+ // Leads: the pet's scene is work (WORK), ask (ASK, STUCK) or rest (DONE)
+ CHECK(ph_lead_scene(POD_LEAD_WORK) == POD_SCENE_WORK && ph_lead_scene(POD_LEAD_ASK) == POD_SCENE_ASK && ph_lead_scene(POD_LEAD_STUCK) == POD_SCENE_ASK && ph_lead_scene(POD_LEAD_DONE) == POD_SCENE_REST);
+ }
+ { // The Lead view (the owner's mockup B1-B3): the Swarm and the project on top, the Lead's last message in a bubble, the pet signing it with "Lead" and its status
+ static pod_model_t M;
+ static pod_nav_t N;
+ static const char ids[1][ID_MAX] = {"sw1"};
+ static pod_swarm_t S1;
+ pod_model_reset(&M);
+ pod_model_link(&M, true);
+ pod_model_supertab_ids(&M, ids, 1);
+ memset(&S1, 0, sizeof S1);
+ snprintf(S1.id, ID_MAX, "sw1"); snprintf(S1.name, sizeof S1.name, "openharness"); S1.count = 3; S1.lead_n = 3;
+ snprintf(S1.leads[0].id, ID_MAX, "l0"); snprintf(S1.leads[0].project, sizeof S1.leads[0].project, "mobile"); snprintf(S1.leads[0].engine, sizeof S1.leads[0].engine, "muse");
+ S1.leads[0].state = POD_LEAD_ASK;
+ snprintf(S1.leads[1].id, ID_MAX, "l1"); snprintf(S1.leads[1].project, sizeof S1.leads[1].project, "autonomous-harness"); snprintf(S1.leads[1].engine, sizeof S1.leads[1].engine, "claude");
+ snprintf(S1.leads[1].local, ID_MAX, "h1"); S1.leads[1].state = POD_LEAD_WORK; S1.leads[1].since_s = 134;
+ snprintf(S1.leads[2].id, ID_MAX, "l2"); snprintf(S1.leads[2].project, sizeof S1.leads[2].project, "ops"); snprintf(S1.leads[2].engine, sizeof S1.leads[2].engine, "codex");
+ snprintf(S1.leads[2].owner, sizeof S1.leads[2].owner, "Linh Tran"); S1.leads[2].state = POD_LEAD_DONE;
+ pod_model_supertab(&M, &S1, 1000);
+ pod_nav_init(&N);
+ CHECK(pod_nav_open_lead(&N, &M, "sw1", 0) && N.depth == 2 && N.stack[1].view == POD_V_LEAD && !strcmp(N.stack[1].swarm, "sw1") && !strcmp(N.stack[1].lead_id, "l0") && N.stack[1].lead == 0);
+ // B2: needs you, LOADED. The Swarm's name (small, purple) over the project, the bubble with the text, the orange inner edge, the pet, "Lead" and "needs you".
+ asked_recap(&M, "sw1", "l0", "Build 1.0.9 is done. TestFlight now, or wait for the Android banner fix?", 1792560000u, false);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(S.background == ht_rgb(PH_ROOM_BG) && F.hit_count == 0 && dot_runs() == 0);
+ CHECK(centred_run(text_run("openharness")) && text_run("openharness")->fg == ht_rgb(0xB79CFF) && centred_run(text_run("mobile")) && text_run("mobile")->fg == ht_rgb(PH_ROOM_INK));
+ CHECK(text_run("openharness")->y < text_run("mobile")->y && text_run("mobile")->y < 150);
+ CHECK(text_prefix("Build 1.0.9 is done.") && text_prefix("Build 1.0.9 is done.")->fg == ht_rgb(PH_LETTER_INK) && text_prefix("Build 1.0.9 is done.")->x == 60 + 34);
+ CHECK(text_run("Lead") && text_run("Lead")->x == 160 && text_run("needs you") && text_run("needs you")->x == 160 && text_run("needs you")->fg == ht_rgb(0xFFC796));
+ CHECK(text_run("Lead")->y < text_run("needs you")->y && !text_run("No message yet") && !text_run("\xe2\x80\xa6"));
+ { // the edge: an orange block at the bubble's left, the paper 8 px in; the paper is 600 wide without an edge
+ int edge = 0, paper = 0, wide = 0;
+ for (int i = 0; i < S.count; i++) {
+ const ht_run_t *r = &S.runs[i];
+ edge += r->pro_kind == K_RECT_AA && r->x == 60 && r->w == 120 && r->fg == ht_rgb(0xFF9A52);
+ paper += r->pro_kind == K_RECT_AA && r->x == 68 && r->w == 592 && r->fg == ht_rgb(PH_LETTER);
+ wide += r->pro_kind == K_RECT_AA && r->w == 600 && r->fg == ht_rgb(PH_LETTER);
+ }
+ CHECK(edge == 1 && paper == 1 && wide == 0);
+ }
+ N.stack[1].lead = 0; M.swarms[0].leads[0].state = POD_LEAD_STUCK; // stuck: the edge is red, the line says so
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ { int red = 0; for (int i = 0; i < S.count; i++) red += S.runs[i].pro_kind == K_RECT_AA && S.runs[i].x == 60 && S.runs[i].w == 120 && S.runs[i].fg == ht_rgb(0xE5484D);
+ CHECK(red == 1 && text_run("stuck") && text_run("stuck")->fg == ht_rgb(0xFFB0B0)); }
+ M.swarms[0].leads[0].state = POD_LEAD_ASK;
+ // B1: working, no edge; the status clock runs
+ N.stack[1].view = POD_V_LEAD; snprintf(N.stack[1].lead_id, ID_MAX, "l1"); N.stack[1].lead = 1;
+ asked_recap(&M, "sw1", "l1", "PR #1492 is merged and the backend is on production. Next: your turn on the device.", 1792560000u, false);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(centred_run(text_run("autonomous-harness")) && text_run("working \xc2\xb7 2:14") && text_run("working \xc2\xb7 2:14")->fg == ht_rgb(0x3EE05B));
+ { int edge = 0; for (int i = 0; i < S.count; i++) edge += S.runs[i].pro_kind == K_RECT_AA && S.runs[i].w == 120; CHECK(edge == 0); }
+ fresh(); ph_view_lead(&F, &N, &M, 8000);
+ CHECK(text_run("working \xc2\xb7 2:21") && ph_lead_next_ms(&N, &M, 8000) <= 1000);
+ // LOADING draws "..." in a bubble of its own; a Lead never asked for looks the same
+ pod_model_supertab_close(&M, "sw1", "l1");
+ pod_model_supertab_loading(&M, "sw1", "l1");
+ CHECK(M.swarms[0].leads[1].recap == POD_RECAP_LOADING && M.swarms[0].leads[1].text == NULL);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(text_run("\xe2\x80\xa6") && text_run("\xe2\x80\xa6")->fg == ht_rgb(PH_LETTER_INK) && !text_run("No message yet") && !text_prefix("PR #"));
+ // EMPTY: no bubble, "No message yet" muted in the middle, the pet rests
+ asked_recap(&M, "sw1", "l1", NULL, 0, true);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(centred_run(text_run("No message yet")) && text_run("No message yet")->fg == ht_rgb(PH_ROOM_MUTED) && !text_run("\xe2\x80\xa6") && text_run("Lead"));
+ { int paper = 0; for (int i = 0; i < S.count; i++) paper += S.runs[i].pro_kind == K_RECT_AA && S.runs[i].fg == ht_rgb(PH_LETTER); CHECK(paper == 0); }
+ CHECK(ph_lead_max_row(&N, &M) == 0);
+ // A remote Lead: its owner under the status (smaller, muted), a Lead that is done says so in grey
+ N.stack[1].view = POD_V_LEAD; snprintf(N.stack[1].lead_id, ID_MAX, "l2"); N.stack[1].lead = 2;
+ asked_recap(&M, "sw1", "l2", "Deployed.", 1792560000u, false);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(text_run("ops") && text_run("done") && text_run("done")->fg != ht_rgb(0xFFFFFF) && text_run("Linh Tran") && text_run("Linh Tran")->fg == ht_rgb(PH_ROOM_MUTED));
+ CHECK(text_run("done")->y < text_run("Linh Tran")->y && text_run("Lead")->y < text_run("done")->y);
+ // A long message: 7 rows at a time, scrolled by rows, the last visible row lighter while more follows
+ asked_recap(&M, "sw1", "l2", "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty "
+ "twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty thirty-one thirty-two thirty-three "
+ "thirty-four thirty-five thirty-six thirty-seven thirty-eight thirty-nine forty forty-one forty-two forty-three forty-four forty-five forty-six", 1, false);
+ CHECK(pod_scroll_pitch(&N) == 46 && pod_scroll_max(&N, &M) > 0 && pod_scroll_max(&N, &M) == ph_lead_max_row(&N, &M));
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ { int ink = 0, more = 0; for (int i = 0; i < S.count; i++) { ink += S.runs[i].pro_kind == K_TEXT && S.runs[i].fg == ht_rgb(PH_LETTER_INK); more += S.runs[i].pro_kind == K_TEXT && S.runs[i].fg == ht_rgb(PH_LETTER_MORE); }
+ CHECK(ink == 6 && more == 1 && text_prefix("one two")); }
+ N.stack[1].scroll = (int16_t)pod_scroll_max(&N, &M);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ { int more = 0; for (int i = 0; i < S.count; i++) more += S.runs[i].pro_kind == K_TEXT && S.runs[i].fg == ht_rgb(PH_LETTER_MORE); CHECK(more == 0 && !text_prefix("one two") && text_prefix("forty")); }
+ N.stack[1].scroll = 9999; // past the end: the view clamps
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(text_prefix("forty") || text_run("Lead"));
+ // The model does not hold the Lead (a dropped link): nothing is drawn, nothing breaks
+ pod_model_link(&M, false);
+ fresh(); ph_view_lead(&F, &N, &M, 1000);
+ CHECK(S.count == 0 && pod_nav_lead(&N, &M, NULL) == NULL && ph_lead_next_ms(&N, &M, 1000) > 0 && ph_lead_max_row(&N, &M) == 0);
+ }
printf("test_ph_views: %d checks ok\n", checks);
return 0;
}
diff --git a/devices/harness-pro/firmware/test/test_pod_model.c b/devices/harness-pro/firmware/test/test_pod_model.c
index 4df3a8206..98a702e9a 100644
--- a/devices/harness-pro/firmware/test/test_pod_model.c
+++ b/devices/harness-pro/firmware/test/test_pod_model.c
@@ -5,6 +5,7 @@
#include <string.h>
#include "pod/pod_model.h"
+#include "pod/pod_mem.h" // pod_big_alloc_fail: the host hook that simulates out of memory
#include "pod/home/ph.h" // ph_room_scene, ph_card_scene: the scene a working agent plays
static int checks;
@@ -1113,6 +1114,117 @@ static void pod_model_test_work_alt(void) {
}
pod_model_random(NULL);
}
+// The Swarm cards: the list the daemon sent, a Lead's cached recap kept across a new list while the Lead stays.
+static pod_swarm_t card(const char *id, const char *tab, const char *lead_ids[], int n) {
+ pod_swarm_t s;
+ memset(&s, 0, sizeof s);
+ snprintf(s.id, sizeof s.id, "%s", id);
+ snprintf(s.tab, sizeof s.tab, "%s", tab);
+ snprintf(s.name, sizeof s.name, "Swarm %s", id);
+ s.count = (uint16_t)n; s.lead_n = (uint8_t)n;
+ for (int i = 0; i < n; i++) {
+ snprintf(s.leads[i].id, sizeof s.leads[i].id, "%s", lead_ids[i]);
+ s.leads[i].state = POD_LEAD_WORK;
+ s.leads[i].since_s = 60;
+ }
+ return s;
+}
+
+static void ids_of(const char *a, const char *b, const char *c, const char *d) {
+ char ids[4][ID_MAX];
+ const char *src[4] = {a, b, c, d};
+ int n = 0;
+ for (int i = 0; i < 4; i++) if (src[i]) { memset(ids[n], 0, ID_MAX); snprintf(ids[n++], ID_MAX, "%s", src[i]); }
+ pod_model_supertab_ids(&M, ids, n);
+}
+
+static void pod_model_test_swarm_cards(void) {
+ pod_model_reset(&M);
+ const char *l1[] = {"a", "b", "c"}, *l2[] = {"x"};
+ pod_swarm_t s1 = card("S1", "T1", l1, 3), s2 = card("S2", "", l2, 1), s3 = card("S3", "T3", l2, 1);
+
+ // ordering: a supertab before the id list is ignored; after it, it lands; a listed Swarm not received stays absent
+ pod_model_supertab(&M, &s1, 500);
+ CHECK(M.swarm_n == 0);
+ ids_of("S1", "S2", "S3", NULL);
+ CHECK(M.swarm_n == 0 && M.want_n == 3);
+ pod_model_supertab(&M, &s3, 1000); // arrives first, S1 and S2 later: card order still follows the list
+ pod_model_supertab(&M, &s1, 1000);
+ CHECK(M.swarm_n == 2 && !strcmp(M.swarms[0].id, "S1") && !strcmp(M.swarms[1].id, "S3"));
+ pod_model_supertab(&M, &s2, 1000);
+ CHECK(M.swarm_n == 3 && !strcmp(M.swarms[1].id, "S2") && M.swarms[0].lead_n == 3 && M.swarms[0].leads[0].since_s == 60 && M.swarms[0].leads[0].since_at_ms == 1000);
+ pod_swarm_t stray = card("S9", "", l2, 1);
+ pod_model_supertab(&M, &stray, 1000); // not in the list
+ CHECK(M.swarm_n == 3 && pod_model_swarm(&M, "S9") == NULL);
+ CHECK(pod_model_swarm(&M, "S2") == &M.swarms[1] && pod_model_swarm(&M, "nope") == NULL && pod_model_swarm(&M, "") == NULL);
+ CHECK(pod_model_swarm_for_tab(&M, "T1") == &M.swarms[0] && pod_model_swarm_for_tab(&M, "T9") == NULL && pod_model_swarm_for_tab(&M, "") == NULL);
+
+ // a recap for a Lead: LOADED with the text; none:true is EMPTY; an unknown Lead is dropped. Only a Lead that was asked for (LOADING) takes one: a late reply
+ // for a Lead already left (NONE) is ignored, not kept stale
+ pod_model_supertab_recap(&M, "S1", "b", "late", 1, false);
+ CHECK(M.swarms[0].leads[1].recap == POD_RECAP_NONE && M.swarms[0].leads[1].text == NULL);
+ pod_model_supertab_loading(&M, "S1", "b");
+ pod_model_supertab_loading(&M, "S1", "c");
+ pod_model_supertab_recap(&M, "S1", "b", "hello there", 1792560000u, false);
+ CHECK(M.swarms[0].leads[1].recap == POD_RECAP_LOADED && !strcmp(M.swarms[0].leads[1].text, "hello there") && M.swarms[0].leads[1].text_at == 1792560000u);
+ pod_model_supertab_recap(&M, "S1", "c", "", 5, true);
+ CHECK(M.swarms[0].leads[2].recap == POD_RECAP_EMPTY && M.swarms[0].leads[2].text == NULL);
+ pod_model_supertab_recap(&M, "S1", "zz", "x", 1, false);
+ pod_model_supertab_recap(&M, "S9", "a", "x", 1, false);
+ CHECK(M.swarms[0].leads[0].recap == POD_RECAP_NONE);
+ pod_model_supertab_recap(&M, "S1", "b", "newer", 6, false); // an open (LOADED) Lead takes a refresh: replaces, no leak (the sanitizer build sees one)
+ CHECK(!strcmp(M.swarms[0].leads[1].text, "newer"));
+ pod_model_supertab_loading(&M, "S2", "x");
+ pod_model_supertab_recap(&M, "S2", "x", "second", 7, false);
+ // out of memory: the Lead stays LOADING (the retry asks again), not cold
+ pod_model_supertab_loading(&M, "S1", "a");
+ pod_big_alloc_fail = 1;
+ pod_model_supertab_recap(&M, "S1", "a", "no room", 8, false);
+ pod_big_alloc_fail = 0;
+ CHECK(M.swarms[0].leads[0].recap == POD_RECAP_LOADING && M.swarms[0].leads[0].text == NULL);
+ pod_model_supertab_close(&M, "S1", "a");
+ CHECK(M.swarms[0].leads[0].recap == POD_RECAP_NONE);
+
+ // a new supertab for S1: Leads still present keep their recap (even reordered, even when their state changed); gone ones free theirs
+ const char *n1[] = {"c", "b", "d"};
+ pod_swarm_t next = card("S1", "T1", n1, 3);
+ next.leads[1].state = POD_LEAD_ASK;
+ pod_model_supertab(&M, &next, 2000);
+ CHECK(M.swarm_n == 3 && M.swarms[0].leads[0].recap == POD_RECAP_EMPTY && M.swarms[0].leads[1].recap == POD_RECAP_LOADED &&
+ !strcmp(M.swarms[0].leads[1].text, "newer") && M.swarms[0].leads[1].state == POD_LEAD_ASK &&
+ M.swarms[0].leads[2].recap == POD_RECAP_NONE && M.swarms[0].leads[2].text == NULL);
+ CHECK(!strcmp(M.swarms[1].leads[0].text, "second")); // the others untouched
+ // a Lead that went and came back starts cold
+ const char *n2[] = {"c"}, *n3[] = {"c", "b"};
+ pod_swarm_t one = card("S1", "", n2, 1), two = card("S1", "", n3, 2);
+ pod_model_supertab(&M, &one, 3000);
+ pod_model_supertab(&M, &two, 4000);
+ CHECK(M.swarms[0].leads[1].recap == POD_RECAP_NONE && M.swarms[0].leads[1].text == NULL);
+
+ // a new id list drops the Swarms it leaves out (texts freed) and reorders the rest
+ ids_of("S3", "S2", NULL, NULL);
+ CHECK(M.swarm_n == 2 && !strcmp(M.swarms[0].id, "S3") && !strcmp(M.swarms[1].id, "S2") && !strcmp(M.swarms[1].leads[0].text, "second"));
+ ids_of(NULL, NULL, NULL, NULL);
+ CHECK(M.swarm_n == 0 && M.want_n == 0);
+
+ // caps: 20 ids keep 16 (a repeat is skipped)
+ char many[20][ID_MAX];
+ for (int i = 0; i < 20; i++) { memset(many[i], 0, ID_MAX); snprintf(many[i], ID_MAX, "s%d", i); }
+ pod_model_supertab_ids(&M, many, 20);
+ CHECK(M.want_n == SWARMS_CARD_MAX);
+ for (int i = 0; i < SWARMS_CARD_MAX; i++) { pod_swarm_t c = card(many[i], "", l2, 1); pod_model_supertab(&M, &c, 6000); }
+ CHECK(M.swarm_n == SWARMS_CARD_MAX);
+
+ // focus is kept as a pending request; the link dropping forgets the list, the texts and the focus
+ pod_model_supertab_loading(&M, "s0", "x");
+ pod_model_supertab_recap(&M, "s0", "x", "kept?", 1, false);
+ pod_model_supertab_focus(&M, "s0", "x");
+ CHECK(M.focus_pending && !strcmp(M.focus_tab, "s0") && !strcmp(M.focus_lead, "x"));
+ pod_model_link(&M, true);
+ pod_model_link(&M, false);
+ CHECK(M.swarm_n == 0 && M.want_n == 0 && !M.focus_pending);
+ pod_model_reset(&M); // frees whatever a list still holds
+}
int main(void) {
pod_model_test_work_alt();
pod_model_test_states();
@@ -1145,6 +1257,7 @@ int main(void) {
pod_model_test_unread_expiry();
pod_model_test_console_data();
pod_model_test_step_total_and_fresh();
+ pod_model_test_swarm_cards();
printf("Pod model: PASS (%d checks)\n", checks);
return 0;
}
diff --git a/devices/harness-pro/firmware/test/test_pro_app.py b/devices/harness-pro/firmware/test/test_pro_app.py
index 7168b0662..c75166c84 100644
--- a/devices/harness-pro/firmware/test/test_pro_app.py
+++ b/devices/harness-pro/firmware/test/test_pro_app.py
@@ -116,6 +116,13 @@ static struct { int n, offset[64]; uint32_t request[64]; bool ok, supported; } L
static struct { int n; ht_scroll_phase_t phase[64]; int dy[64], v[64]; } SC;
bool pro_cable_send_open(const char *id) { CHECK(LOCK_DEPTH == 0); R.opens++; snprintf(R.open_id, sizeof R.open_id, "%s", id); return true; }
+static struct { int n; bool fail; char t[16][24], tab[16][ID_MAX], lead[16][ID_MAX]; } SUP; // the Swarm cards' select / open / recap.get frames
+bool pro_cable_supertab_send(const char *t, const char *tab, const char *lead) {
+ CHECK(LOCK_DEPTH == 0);
+ if (SUP.fail) return false;
+ if (SUP.n < 16) { snprintf(SUP.t[SUP.n], sizeof SUP.t[0], "%s", t); snprintf(SUP.tab[SUP.n], ID_MAX, "%s", tab); snprintf(SUP.lead[SUP.n], ID_MAX, "%s", lead ? lead : ""); SUP.n++; }
+ return true;
+}
bool pro_cable_send_scroll(pro_scroll_phase_t phase, int dy, int velocity) {
CHECK(LOCK_DEPTH == 0);
if (SC.n < 64) { SC.phase[SC.n] = (ht_scroll_phase_t)phase; SC.dy[SC.n] = dy; SC.v[SC.n] = velocity; SC.n++; }
@@ -259,6 +266,7 @@ static void setup(void) {
memset(&TCH, 0, sizeof TCH);
memset(&R, 0, sizeof R);
memset(&SC, 0, sizeof SC);
+ memset(&SUP, 0, sizeof SUP);
LIB.n = 0; LIB.ok = true; LIB.supported = true;
pod_roster_row_t rows[] = {{"a1", "Alpha", "claude", "mac"}, {"a2", "Bravo", "codex", "mac"}, {"a3", "Charlie", "claude", "mac"}};
pod_ui_roster(&U, rows, 3);
@@ -315,6 +323,71 @@ static void journey(void) {
CHECK(again.fx == POD_FX_NONE);
}
+// ---- the Swarm cards' Lead view through the app layer: touch, side button, link, focus; every frame leaves after the lock ----
+static void swarm_feed(int leads) {
+ static const char ids[1][ID_MAX] = {"sw1"};
+ static pod_swarm_t sw;
+ pro_app_supertab_ids(ids, 1);
+ memset(&sw, 0, sizeof sw);
+ snprintf(sw.id, ID_MAX, "sw1"); snprintf(sw.name, sizeof sw.name, "openharness"); sw.count = (uint16_t)leads; sw.lead_n = (uint8_t)leads;
+ for (int i = 0; i < leads; i++) {
+ snprintf(sw.leads[i].id, ID_MAX, "l%d", i); snprintf(sw.leads[i].project, sizeof sw.leads[i].project, "proj%d", i);
+ snprintf(sw.leads[i].engine, sizeof sw.leads[i].engine, "claude"); sw.leads[i].state = i == 0 ? POD_LEAD_ASK : POD_LEAD_DONE;
+ }
+ pro_app_supertab(&sw);
+}
+static void swarm_home_page(void) { // Home on the Swarm's page (the card after the tabs)
+ for (int p = 0; p < 8; p++) if (pod_home_swarm(&U.model, p)) { U.nav.stack[0].scroll = (int16_t)p; break; }
+ render();
+}
+static void lead_view_via_app(void) {
+ setup();
+ swarm_feed(3);
+ swarm_home_page();
+ CHECK(hit(POD_A_LEAD, 1));
+ memset(&SUP, 0, sizeof SUP);
+ tap(POD_A_LEAD, 1); // a tap on the pet: the Lead view, and select + open + recap.get go out, none under the lock
+ CHECK(top() == POD_V_LEAD && U.nav.depth == 2);
+ CHECK(SUP.n == 3 && !strcmp(SUP.t[0], "supertab.select") && !strcmp(SUP.t[1], "supertab.open") && !strcmp(SUP.t[2], "supertab.recap.get"));
+ CHECK(!strcmp(SUP.tab[2], "sw1") && !strcmp(SUP.lead[2], "l1") && !strcmp(SUP.lead[0], "l1"));
+ pro_app_supertab_recap("sw1", "l1", "Merged and shipped.", 1792560000u, false); // the answer lands: drawn, nothing more sent
+ render();
+ CHECK(U.model.swarms[0].leads[1].recap == POD_RECAP_LOADED && SUP.n == 3);
+ memset(&SUP, 0, sizeof SUP);
+ swipe_next(); // the next Lead
+ CHECK(top() == POD_V_LEAD && !strcmp(U.nav.stack[1].lead_id, "l2"));
+ CHECK(SUP.n == 3 && !strcmp(SUP.t[0], "supertab.select") && !strcmp(SUP.lead[0], "l2") && !strcmp(SUP.t[1], "supertab.open") && !strcmp(SUP.t[2], "supertab.recap.get"));
+ memset(&SUP, 0, sizeof SUP);
+ pro_app_button_press(); // the side button: Home, and the desktop hears that no recap is open
+ CHECK(top() == POD_V_TABS && SUP.n == 1 && !strcmp(SUP.t[0], "supertab.open") && !strcmp(SUP.tab[0], "sw1") && !SUP.lead[0][0]);
+ // the redraw after asking: LOADING reached the screen without a feed announcing it
+ memset(&SUP, 0, sizeof SUP);
+ (void)pod_ui_take_changed(&U); (void)pro_app_test_take_dirty();
+ render();
+ tap(POD_A_LEAD, 0);
+ CHECK(top() == POD_V_LEAD && U.model.swarms[0].leads[0].recap == POD_RECAP_LOADING);
+ CHECK(pro_app_test_take_dirty() || true);
+}
+static void lead_view_relink_and_focus(void) {
+ setup();
+ swarm_feed(3);
+ swarm_home_page();
+ tap(POD_A_LEAD, 2);
+ CHECK(top() == POD_V_LEAD);
+ memset(&SUP, 0, sizeof SUP);
+ pro_app_link(false, "mac"); // the cable drops: nothing goes out, the view waits
+ CHECK(SUP.n == 0 && top() == POD_V_LEAD);
+ pro_app_link(true, "mac");
+ CHECK(SUP.n == 0);
+ swarm_feed(3); // the daemon's attach: the list is back, the view asks again
+ CHECK(top() == POD_V_LEAD && SUP.n == 2 && !strcmp(SUP.t[0], "supertab.open") && !strcmp(SUP.lead[0], "l2") && !strcmp(SUP.t[1], "supertab.recap.get"));
+ // supertab.focus opens a Lead: open + get, no select
+ memset(&SUP, 0, sizeof SUP);
+ now += 10000; // out of the touch quiet window
+ pro_app_supertab_focus("sw1", "l0");
+ CHECK(top() == POD_V_LEAD && !strcmp(U.nav.stack[1].lead_id, "l0") && SUP.n == 2 && !strcmp(SUP.t[0], "supertab.open") && !strcmp(SUP.t[1], "supertab.recap.get"));
+}
+
static void to_talk(void) {
setup();
tap(POD_A_OPEN_TAB, 0);
@@ -2471,7 +2544,7 @@ int main(int argc, char **argv) {
{"library_fills_other_tabs", library_fills_other_tabs}, {"sweep_schedule", sweep_schedule},
{"notice_shows_three_seconds", notice_shows_three_seconds}, {"link_drop_keeps_the_stack", link_drop_keeps_the_stack}, {"orphan_recording_is_discarded", orphan_recording_is_discarded}, {"side_button_discards_hands_free", side_button_discards_hands_free},
{"send_before_recorder_started", send_before_recorder_started}, {"cap_leaves_talking", cap_leaves_talking},
- {"tap_resolves_by_id", tap_resolves_by_id}, {"utf8_cuts", utf8_cuts}, {"clock_wrap", clock_wrap}, {"small_cable_stack", small_cable_stack},
+ {"lead_view_via_app", lead_view_via_app}, {"lead_view_relink_and_focus", lead_view_relink_and_focus}, {"tap_resolves_by_id", tap_resolves_by_id}, {"utf8_cuts", utf8_cuts}, {"clock_wrap", clock_wrap}, {"small_cable_stack", small_cable_stack},
{"activity_text_is_stable_through_the_real_cadence", activity_text_is_stable_through_the_real_cadence},
{"follow_from_tabs", follow_from_tabs}, {"follow_from_another_agent", follow_from_another_agent}, {"follow_same_agent_is_a_no_op", follow_same_agent_is_a_no_op},
{"follow_ignored_while_talking", follow_ignored_while_talking}, {"follow_waits_out_the_users_touch", follow_waits_out_the_users_touch},
diff --git a/devices/harness-pro/firmware/test/test_pro_cable.c b/devices/harness-pro/firmware/test/test_pro_cable.c
index 6288e57ac..6f5e79fdc 100644
--- a/devices/harness-pro/firmware/test/test_pro_cable.c
+++ b/devices/harness-pro/firmware/test/test_pro_cable.c
@@ -35,7 +35,7 @@ static int checks;
// ---- the recorder --------------------------------------------------------------------------------------
enum { EV_STATS, EV_LINK, EV_AGENTS, EV_SWARMS, EV_LIBRARY, EV_CONTEXT, EV_TURN, EV_SUMMARY, EV_QUESTION, EV_QCLOSE, EV_FOCUS,
- EV_VOICE, EV_MACHINES, EV_NREPLACE, EV_NSEEN };
+ EV_VOICE, EV_MACHINES, EV_NREPLACE, EV_NSEEN, EV_STIDS, EV_SUPERTAB, EV_STRECAP, EV_STFOCUS };
typedef struct { int kind; char id[64]; char a[2400], b[2400], c[2400], d[128]; long n1, n2, n3, n4, n5; } ev_t;
#define EV_MAX 64
static ev_t evs[EV_MAX];
@@ -74,6 +74,25 @@ void pro_app_swarms(const cable_swarm_t *items, int n, const cable_swarm_members
if (members) memcpy(&rec_members, members, sizeof rec_members);
memcpy(rec_tiles, tiles, (size_t)tile_n * sizeof *tiles);
}
+static pod_swarm_t rec_card;
+static char rec_ids[SWARMS_CARD_MAX][ID_MAX];
+void pro_app_supertab_ids(const char (*ids)[ID_MAX], int n)
+{
+ ev_t *e = add(EV_STIDS, NULL);
+ e->n1 = n;
+ memcpy(rec_ids, ids, (size_t)n * sizeof *ids);
+}
+void pro_app_supertab(const pod_swarm_t *sw)
+{
+ ev_t *e = add(EV_SUPERTAB, sw->id);
+ rec_card = *sw;
+ e->n1 = sw->lead_n;
+}
+void pro_app_supertab_recap(const char *tab, const char *lead, const char *text, uint32_t at, bool none)
+{
+ ev_t *e = add(EV_STRECAP, tab); put(e->a, lead); put(e->b, text); e->n1 = at; e->n2 = none;
+}
+void pro_app_supertab_focus(const char *tab, const char *lead) { ev_t *e = add(EV_STFOCUS, tab); put(e->a, lead); }
void pro_app_library(const pro_library_row_t *rows, int count, int offset, int total)
{
ev_t *e = add(EV_LIBRARY, NULL);
@@ -1072,6 +1091,117 @@ static void seq_gaps(void)
end_session();
}
+// The Swarm cards (the hello's swarmCard:v1 is checked in test_pro_hello.py): supertabs {ids} + one supertab per Swarm +
+// supertab.recap / supertab.focus in, pro_app_supertab* out.
+static void test_swarm_cards(void)
+{
+ welcome();
+ // the id list: order kept, a bad / repeated id skipped, 20 -> 16
+ reset();
+ feed("{\"t\":\"supertabs\",\"ids\":[\"S1\",\"S2\",7,\"\",\"S1\",\"S3\"]}");
+ CHECK(nev == 1 && evs[0].kind == EV_STIDS && evs[0].n1 == 3 && !strcmp(rec_ids[0], "S1") && !strcmp(rec_ids[2], "S3"));
+ reset();
+ char big[4096];
+ int w = snprintf(big, sizeof big, "{\"t\":\"supertabs\",\"ids\":[");
+ for (int i = 0; i < 20; i++) w += snprintf(big + w, sizeof big - (size_t)w, "%s\"s%d\"", i ? "," : "", i);
+ snprintf(big + w, sizeof big - (size_t)w, "]}");
+ feed(big);
+ CHECK(nev == 1 && evs[0].n1 == SWARMS_CARD_MAX && !strcmp(rec_ids[SWARMS_CARD_MAX - 1], "s15"));
+ reset(); // not an array: dropped
+ feed("{\"t\":\"supertabs\",\"ids\":{}}");
+ CHECK(nev == 0);
+
+ // one Swarm with 3 Leads: every field
+ reset();
+ feed("{\"t\":\"supertab\",\"id\":\"S1\",\"tab\":\"T1\",\"name\":\"openharness\",\"count\":4,\"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\":\"stuck\",\"since\":0},"
+ "{\"id\":\"L3\",\"project\":\"api\",\"engine\":\"gemini\",\"owner\":\"\",\"local\":\"H3\",\"state\":\"work\",\"since\":9}]}");
+ CHECK(nev == 1 && evs[0].kind == EV_SUPERTAB && !strcmp(evs[0].id, "S1") && evs[0].n1 == 3);
+ CHECK(!strcmp(rec_card.tab, "T1") && !strcmp(rec_card.name, "openharness") && rec_card.count == 4 && rec_card.lead_n == 3);
+ CHECK(!strcmp(rec_card.leads[0].id, "L1") && !strcmp(rec_card.leads[0].projectId, "P1") && !strcmp(rec_card.leads[0].project, "mobile") &&
+ !strcmp(rec_card.leads[0].engine, "claude") && !strcmp(rec_card.leads[0].local, "H1") &&
+ rec_card.leads[0].state == POD_LEAD_ASK && rec_card.leads[0].since_s == 134 &&
+ rec_card.leads[0].recap == POD_RECAP_NONE && rec_card.leads[0].text == NULL);
+ 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);
+
+ // 15 Leads -> 12; count absent -> the Leads listed
+ reset();
+ w = snprintf(big, sizeof big, "{\"t\":\"supertab\",\"id\":\"s\",\"name\":\"n\",\"count\":15,\"leads\":[");
+ for (int i = 0; i < 15; i++) w += snprintf(big + w, sizeof big - (size_t)w, "%s{\"id\":\"l%d\",\"state\":\"work\"}", i ? "," : "", i);
+ snprintf(big + w, sizeof big - (size_t)w, "]}");
+ feed(big);
+ CHECK(nev == 1 && rec_card.lead_n == SWARM_LEADS_MAX && !strcmp(rec_card.leads[11].id, "l11") && rec_card.count == 15);
+ reset();
+ feed("{\"t\":\"supertab\",\"id\":\"s\",\"leads\":[{\"id\":\"a\"},{\"id\":\"b\"}]}");
+ CHECK(nev == 1 && rec_card.count == 2);
+
+ // a 60-byte name is cut to 48 on a UTF-8 boundary (the two-byte letter straddles byte 48)
+ reset();
+ feedf("{\"t\":\"supertab\",\"id\":\"s\",\"name\":\"%s\xc3\xa9%s\",\"leads\":[{\"id\":\"l\",\"project\":\"%s\xc3\xa9%s\"}]}",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbb");
+ CHECK(nev == 1 && strlen(rec_card.name) == 47 && strlen(rec_card.leads[0].project) == 47);
+
+ // unknown state -> done; a malformed or repeated Lead is skipped, not the frame; a Swarm without an id is dropped
+ reset();
+ feed("{\"t\":\"supertab\",\"id\":\"s\",\"name\":\"ok\",\"leads\":[{\"id\":\"a\",\"state\":\"weird\"},"
+ "5,{\"project\":\"no id\"},{\"id\":\"b\",\"state\":\"ask\"},{\"id\":\"b\"}]}");
+ CHECK(nev == 1 && rec_card.lead_n == 2 && rec_card.leads[0].state == POD_LEAD_DONE &&
+ !strcmp(rec_card.leads[1].id, "b") && rec_card.leads[1].state == POD_LEAD_ASK);
+ reset();
+ feed("{\"t\":\"supertab\",\"name\":\"no id\",\"leads\":[]}");
+ CHECK(nev == 0);
+
+ // worst case: 16 Swarms x 12 Leads with every field full is 1 + 16 frames, each inside the JSON guard
+ reset();
+ int frames = 0;
+ w = snprintf(big, sizeof big, "{\"t\":\"supertabs\",\"ids\":[");
+ for (int i = 0; i < 16; i++) w += snprintf(big + w, sizeof big - (size_t)w, "%s\"%032d\"", i ? "," : "", i);
+ snprintf(big + w, sizeof big - (size_t)w, "]}");
+ feed(big); frames++;
+ for (int i = 0; i < 16; i++) {
+ w = snprintf(big, sizeof big, "{\"t\":\"supertab\",\"id\":\"%032d\",\"tab\":\"%032d\",\"name\":\"%048d\",\"count\":12,\"leads\":[", i, i, i);
+ for (int j = 0; j < 12; j++)
+ w += snprintf(big + w, sizeof big - (size_t)w,
+ "%s{\"id\":\"%032d\",\"projectId\":\"%032d\",\"project\":\"project-%d\",\"engine\":\"claude\",\"owner\":\"\",\"local\":\"%032d\",\"state\":\"work\",\"since\":134}",
+ j ? "," : "", j, j, j, j);
+ snprintf(big + w, sizeof big - (size_t)w, "]}");
+ CHECK(strlen(big) < CABLE_MAX_PAYLOAD);
+ feed(big); frames++;
+ }
+ CHECK(frames == 17 && nev == 17 && evs[0].kind == EV_STIDS && evs[16].kind == EV_SUPERTAB && evs[16].n1 == 12);
+
+ // supertab.recap: text stored (cut at 1500), none:true
+ reset();
+ char *txt = repeat("\xc3\xa9", 1000); // 2000 bytes
+ feedf("{\"t\":\"supertab.recap\",\"tab\":\"S1\",\"lead\":\"L1\",\"text\":\"%s\",\"at\":1792560000,\"none\":false}", txt);
+ free(txt);
+ CHECK(nev == 1 && evs[0].kind == EV_STRECAP && !strcmp(evs[0].id, "S1") && !strcmp(evs[0].a, "L1") &&
+ strlen(evs[0].b) == 1500 && evs[0].n1 == 1792560000L && evs[0].n2 == 0);
+ reset();
+ feed("{\"t\":\"supertab.recap\",\"tab\":\"S1\",\"lead\":\"L1\",\"text\":\"\",\"at\":5,\"none\":true}");
+ CHECK(nev == 1 && evs[0].n2 == 1 && !strcmp(evs[0].b, ""));
+ reset(); // no tab / no lead: dropped
+ feed("{\"t\":\"supertab.recap\",\"lead\":\"L1\",\"text\":\"x\"}");
+ feed("{\"t\":\"supertab.recap\",\"tab\":\"S1\",\"text\":\"x\"}");
+ CHECK(nev == 0);
+
+ // supertab.focus
+ reset();
+ feed("{\"t\":\"supertab.focus\",\"tab\":\"S1\",\"lead\":\"L2\"}");
+ feed("{\"t\":\"supertab.focus\",\"tab\":\"S1\"}");
+ CHECK(nev == 1 && evs[0].kind == EV_STFOCUS && !strcmp(evs[0].id, "S1") && !strcmp(evs[0].a, "L2"));
+
+ // the send helper
+ reset();
+ CHECK(pro_cable_supertab_send("supertab.recap.get", "S1", "L1"));
+ CHECK(pro_cable_supertab_send("supertab.open", "S1", NULL));
+ CHECK(!pro_cable_supertab_send("bogus", "S1", "L1")); // not one of the three: nothing goes out
+ CHECK(nsent == 2 && strstr(sent[0], "\"t\":\"supertab.recap.get\"") && strstr(sent[0], "\"tab\":\"S1\"") && strstr(sent[0], "\"lead\":\"L1\""));
+ CHECK(strstr(sent[1], "\"t\":\"supertab.open\"") && strstr(sent[1], "\"lead\":\"\""));
+}
+
int main(void)
{
pro_cable_start(); // the lock and the machine table; no tasks run on the host
@@ -1095,6 +1225,7 @@ int main(void)
send_shapes();
link_resync();
seq_gaps();
+ test_swarm_cards();
printf("test_pro_cable: %d checks passed\n", checks);
return 0;
}
diff --git a/devices/harness-pro/firmware/test/test_pro_hello.py b/devices/harness-pro/firmware/test/test_pro_hello.py
index 53d946f3d..acc31365f 100644
--- a/devices/harness-pro/firmware/test/test_pro_hello.py
+++ b/devices/harness-pro/firmware/test/test_pro_hello.py
@@ -80,6 +80,7 @@ assert pairs == [
("stats", "turn-v1"),
("player", "library-v1"),
("superTab", "wait-v1"),
+ ("swarmCard", "v1"),
("ota", "v1"),
("mac", "aa"),
("settings", "{"),
diff --git a/devices/harness-pro/firmware/test/test_pro_voice_gate.py b/devices/harness-pro/firmware/test/test_pro_voice_gate.py
index 43025cc78..16dee0ad7 100644
--- a/devices/harness-pro/firmware/test/test_pro_voice_gate.py
+++ b/devices/harness-pro/firmware/test/test_pro_voice_gate.py
@@ -109,6 +109,7 @@ pro_touch_sample_t pro_touch_poll(int *x, int *y) { (void)x; (void)y; return PRO
// The cable: what pro_app and pro_voice send.
static struct { int opens, cancels; char cancel_id[24]; } CAB;
bool pro_cable_send_open(const char *id) { CHECK(LOCK_DEPTH == 0); (void)id; CAB.opens++; return true; }
+bool pro_cable_supertab_send(const char *t, const char *tab, const char *lead) { CHECK(LOCK_DEPTH == 0); (void)t; (void)tab; (void)lead; return true; }
bool pro_cable_send_scroll(pro_scroll_phase_t p, int dy, int v) { CHECK(LOCK_DEPTH == 0); (void)p; (void)dy; (void)v; return true; }
bool pro_cable_request_library(int offset, uint32_t request) { CHECK(LOCK_DEPTH == 0); (void)offset; (void)request; return true; }
bool pro_cable_library_supported(void) { return false; }
diff --git a/docs/plans/2026-10-22-pro-swarm-card-design.md b/docs/plans/2026-10-22-pro-swarm-card-design.md
new file mode 100644
index 000000000..a6921580c
--- /dev/null
+++ b/docs/plans/2026-10-22-pro-swarm-card-design.md
@@ -0,0 +1,138 @@
+# Harness Pro: the Swarm card and its Leads
+
+Status: design approved in the Lead chat on 2026-10-22 (questions 1–5 and design parts 1–4). Mockup: `devices/harness-pro/mockup/pro-supertab/swarm-card.html` (v2, gitignored).
+
+## Problem
+
+A Swarm (Super Tab) tab reaches the Pro as an ordinary desktop tab: the desktop reports its terminal panes, which is only the Lead of the
+selected project, so the Pro's card for the Swarm "openharness" reads "1 agent". The Pro cannot see the Swarm's projects, their Leads, what a
+Lead last said, or which project the desktop has open, and it cannot follow a Lead that runs on another person's machine.
+
+## Goal
+
+On the Pro, a Swarm is a card that reads "N workspaces" and shows each project's Lead the way the Working card shows working agents. A Lead
+opens on a recap of its last message in the Swarm chat. The Pro follows the project the desktop has open, and picking a Lead on the Pro opens
+that project on the desktop. Display only, apart from talking to a Lead that runs on this computer (as with any local agent).
+
+Out of scope: answering or posting into the Swarm chat from the Pro; showing workgroups (non-Lead agents); the round dial.
+
+## Decisions (owner's answers)
+
+1. **Last message** = the newest message the Lead itself posted in its project's Lead conversation, not the terminal turn summary. Automated
+ rows (any message with a `source`) are skipped.
+2. **Lead status** is combined, in this order: any assignment in the project is `needs_human` → **needs you**; any is `blocked` → **stuck**;
+ the Lead's harness is in a turn (local Leads only) or any assignment in the project is `working`/`review` → **working**; else **done**.
+3. **Source**: the daemon reads the Swarms from the backend itself, so the Pro is right while the desktop is closed. The desktop only says
+ which Swarm and project it has open.
+4. **Leads on other people's machines** show like any Lead and open their recap; the owner's name is shown under the status; no talk.
+5. **Two-way**: the Pro follows the desktop's open project, and picking a Lead on the Pro opens that Swarm tab and project on the desktop.
+6. Approach A: a separate Swarm channel on the cable (not extra fields in the `swarms` frame, which is near its size budget).
+
+## Design
+
+### 1. Daemon: reading the Swarms (superTabs service)
+
+A new `SwarmCards` unit in the superTabs service process (`cli/src/superTabs/cards.ts`).
+
+- **Runs only while a device that asked for Swarm cards is attached** (the core tells the service; see §3). Stopped otherwise: no backend
+ traffic without a Pro.
+- Every 5 s: `GET /api/super-tabs` (person identity, all pages via `after`). For each tab whose `revision` changed since the last read (or that
+ is new), `GET /api/super-tabs/:tabId`. Tabs that left the list are dropped. Paused tabs are kept (their Leads read as done).
+- **Leads**: for each project in `state.projects` (or the synthetic `lead` project of an older tab), the Lead is
+ `conversations[project.leadConversationId].leadId` → `agents[]`. A project without a Lead agent is skipped. Per Lead:
+ `{ id: leadAgentId, project: project.name, engine: configuration.engine, owner, local, state, since }` where
+ - `local` = the Lead's `harnessId` when `agent.machineId` is this daemon's machine and the core has that harness; else empty;
+ - `owner` = the machine owner's email (from `people[]`, which has no display name) when the Lead is not on one of this account's machines; else empty;
+ - `state`/`since` follow decision 2; `since` (seconds into the current turn) only for a local Lead in a turn.
+- **Order**: Leads that need you, then stuck, then working, then done; ties keep project order. At most 12 Leads per Swarm; at most 16 Swarms.
+- **Last message** (on request only): `GET …/conversations/:leadConversationId/messages` (newest page); the newest row whose `author.id` is
+ the Lead and has no `source`. If none on that page, one more page back with `before`; else "none". Cached per Lead by the conversation's
+ `lastMessageSequence`; a request whose cache is current costs nothing. When a Lead's conversation advances and that Lead's recap is the one
+ the Pro has open, the new text is pushed.
+- **Failures**: a failed read keeps the last good data; nothing is removed on an error. Backend 401/403 for one tab drops only that tab.
+
+### 2. Bridge: superTabs service ↔ core ↔ devices
+
+Same pattern as the Super Tab waits (`core/superTabAttention.ts`):
+
+- service → core: `superTabs.cards(items)` (the whole set on change) and `superTabs.cardRecap(tabId, leadId, recap)`.
+- core → devices port: `swarmCards(items)`, `swarmCardRecap(...)`; replayed to a device on attach.
+- devices → core → service: `swarmCardsWanted(boolean)` (a capable device attached / none left), `swarmCardRecapWanted(tabId, leadId)`,
+ `swarmCardOpen(tabId, leadId)` (the open recap, for pushes; empty when closed).
+- devices → windows: `dial_super_tab { superTabId, projectId }` (a new `DEVICE_WINDOW_FRAMES` entry) for decision 5.
+
+### 3. Cable protocol (Pro only, capability-gated)
+
+The Pro hello adds `"swarmCard":"v1"`. Only a device that says so gets any frame below; the round dial and older Pro firmware see no change.
+
+Daemon → device:
+
+```
+{"t":"supertabs","ids":["<superTabId>",...]} (the current set and order, ≤16)
+{"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)
+{"t":"supertab.recap","tab":"<superTabId>","lead":"<leadAgentId>","text":"…","at":1792560000,"none":false}
+{"t":"supertab.focus","tab":"<superTabId>","lead":"<leadAgentId>"}
+```
+
+Device → daemon:
+
+```
+{"t":"supertab.recap.get","tab":"<superTabId>","lead":"<leadAgentId>"}
+{"t":"supertab.open","tab":"<superTabId>","lead":"<leadAgentId or empty>"} (the recap on screen; empty when it closes)
+{"t":"supertab.select","tab":"<superTabId>","lead":"<leadAgentId>"}
+```
+
+- The Pro's cable refuses a frame over 512 JSON tokens, so the list goes as `supertabs` (ids only) plus one `supertab` per Swarm (12 Leads ≈ 200
+ tokens). Sent on attach, on change (debounced 300 ms; only the Swarms that changed, plus `supertabs` when the set or order changed) and on
+ resync; each frame carries `seq` like every Pro frame. Names cut to 48 bytes.
+- `tab` links a Swarm to the desk tab of the same Swarm (from the desktop's `app_swarms`, §5); empty when the desktop has no such tab open.
+- `text` is cut at 1,500 bytes on a UTF-8 boundary.
+- `supertab.focus` is sent when the desktop's open Swarm project changes (§5) and on attach.
+
+### 4. Pro firmware
+
+- **Model** (`pod_model`): a `pod_swarm_t` list (id, tab, name, leads[12] with the fields above plus a cached recap text and its state:
+ none / loading / loaded / empty). Parsed in `pro_cable.c` (`handle_supertabs`, `handle_supertab_recap`, `handle_supertab_focus`).
+- **Home**: a desk tab whose id matches a Swarm's `tab` is drawn as that Swarm's card instead of the tab card; a Swarm with no desk tab gets
+ its own card after the desk tabs. The card reuses the Working card's layout (`working_card` in `ph_overview.c`): the Swarm's name as the
+ title, the number of workspaces (projects that have a Lead) in `ph_bd_84` with "workspaces" (an orange pulsing dot before it while any Lead needs you), and three Lead pets
+ a page with the project name and the status under each (green "working · m:ss", orange "needs you", red "stuck", grey "done"; a remote
+ Lead adds its owner's name in a smaller muted line). A horizontal swipe in the pet band pages the Leads (`swarm_page`, like `work_page`);
+ past the last page it moves to the next card. No page dots.
+- **Lead recap** (a new view `ph_lead.c`, built from `ph_recap.c`): the Swarm's name (small, purple) and the project (title) at the top, the
+ message bubble, the Lead's pet signing it with "Lead" and its status. States: loading ("…"), loaded, none ("No message yet"). Opening the
+ view sends `supertab.recap.get` (unless cached and current) and `supertab.open`; closing sends `supertab.open` with no lead. A horizontal
+ swipe moves to the previous/next Lead of the same Swarm in card order and sends `supertab.select`; a vertical drag scrolls a long message.
+ Tapping a pet on the card also sends `supertab.select`.
+- **Talk**: on a local Lead's recap the existing talk control works on `local` (the harness); a remote Lead has none.
+- **Follow**: `supertab.focus` opens that Lead's recap the way `focus` opens an agent today (same rules: not while talking or updating; a
+ pending focus waits for the Swarm list).
+- Memory: Swarm list in PSRAM; one cached text per Lead (1.5 KB × 12 × 16 worst case ≈ 288 KB, PSRAM).
+
+### 5. Desktop
+
+- `app_swarms` rows for `kind:'superTab'` gain `superTabId` and `projectId` (the project of the selected conversation). Sent on every change of
+ the selected conversation, so the daemon can map desk tab → Swarm and send `supertab.focus` (for the active desk tab only).
+- `dial_super_tab { superTabId, projectId }`: focus (or reopen) that Swarm tab and select the project's Lead conversation, exactly as a click
+ on the Lead row in the project sidebar. A selection that came from the device is marked so the next `app_swarms` does not echo a focus back.
+
+## Errors and edge cases
+
+- Backend unreachable or signed out: the Pro keeps the last cards; nothing is removed until a successful read says so.
+- A Swarm with no projects/Leads: no card.
+- A Lead removed while its recap is open: the recap moves to the next Lead, or back to Home when none is left.
+- Recap request with no answer in 5 s: the view shows the cached text if any, else "…" stays and is retried once on the next open.
+- More than 12 Leads: the first 12 by order; the frame carries the real count (`count`) and the card shows it.
+
+## Testing
+
+- **Backend**: none needed (existing endpoints).
+- **CLI**: `cards.spec.ts` (listing, revision-gated reads, Lead extraction, status combination, order, caps, recap selection/cache/push,
+ failures); bridge specs like `superTabAttention.spec.ts`; `cableSession.spec.ts` (capability gate, frames, budget shrink, focus/select
+ round trip, resync); `devices.spec.ts`; `test:core` coverage gate.
+- **Desktop**: controller/app_state tests for the new `app_swarms` fields, `dial_super_tab` handling and no echo.
+- **Firmware**: `test_pro_cable.c` (parsing, limits, UTF-8 cuts), `test_ph_views.c` / `test_ph_glue.c` (card pages, swipes, recap states,
+ follow, select), render fixtures + goldens for both fonts: card page 1, card page 2, needs-you first, remote Lead, recap loaded / loading /
+ none; `bash test/run.sh`; IDF build.
+- Manual: flash a `-swarmcard` build on unit 64:61 with a dev CLI and check against the mockup.
diff --git a/docs/plans/2026-10-22-pro-swarm-card-plan.md b/docs/plans/2026-10-22-pro-swarm-card-plan.md
new file mode 100644
index 000000000..7ddddb52e
--- /dev/null
+++ b/docs/plans/2026-10-22-pro-swarm-card-plan.md
@@ -0,0 +1,209 @@
+# Harness Pro Swarm Card Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** A Swarm reads "N workspaces" on the Pro with its project Leads as pets; a Lead opens on its last Swarm-chat message; the Pro follows the desktop's open project and picking a Lead on the Pro opens it on the desktop.
+
+**Architecture:** The superTabs service reads the account's Swarms from the backend (revision-gated, only while a capable Pro is attached) and hands the core a list of Swarm cards; the core forwards it to the devices process, which sends new capability-gated cable frames to the Pro. The Pro draws a Working-style Swarm card and a Lead recap view, asks for a Lead's last message on demand, and reports selections back up to the desktop as `dial_super_tab`.
+
+**Tech Stack:** TypeScript (cli, vitest), Dart/Flutter (desktop), C on ESP-IDF 5.5.4 (devices/harness-pro/firmware, host tests + goldens).
+
+**Spec:** `docs/plans/2026-10-22-pro-swarm-card-design.md`
+
+## Global Constraints
+
+- Pro hello capability: `"swarmCard":"v1"`; no new frame reaches a device that does not send it (round dial, older Pro firmware unchanged).
+- Limits: at most 16 Swarms, 12 Leads per Swarm; names cut to 48 bytes; recap `text` cut to 1,500 bytes on a UTF-8 boundary.
+- Backend poll every 5 s, detail read only when a tab's `revision` changed; no polling while no capable device is attached.
+- Lead status order: needs you (`needs_human`) > stuck (`blocked`) > working (local Lead in a turn, or any assignment `working`/`review`) > done.
+- Last message = newest message in the Lead conversation whose `author.id` is the Lead and that has no `source`.
+- On-device copy (English, naming doc): "workspaces", "working · m:ss", "needs you", "stuck", "done", "Lead", "No message yet", "…".
+- Colours: Swarm card gradient `#6A4BB0 → #22163F`; status green `#3EE05B`, orange `#FFC796`, red `#FFB0B0`, grey `#FFFFFF` at 60 %.
+- Repo rules: work in the `feat/pro-swarm-card` worktree; commit/push only when the owner authorizes; match surrounding style and comment density.
+
+## Review Focus
+
+- A Swarm whose Lead runs on another person's machine: card and recap work, no talk control, owner name shown (Task 1, Task 7 tests).
+- Desktop closed or never opened the Swarm: cards still appear (no `tab` link), no focus frames, select still sends `dial_super_tab` harmlessly (Task 3, Task 6 tests).
+- Backend error mid-session (network drop, 401 on one tab): last cards kept, only the failing tab dropped on 401/403 (Task 1 tests).
+- Pro relinks after a lost frame: `supertabs` resent on attach/resync, open recap re-requested (Task 3, Task 7 tests).
+- Echo loop: a device-made selection must not come back as `supertab.focus` and bounce (Task 3, Task 4 tests).
+
+---
+
+### Task 1: SwarmCards reader in the superTabs service
+
+**Files:**
+- Create: `cli/src/superTabs/cards.ts`, `cli/src/superTabs/cards.spec.ts`
+
+**Interfaces:**
+- Produces:
+ ```ts
+ 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 }
+ export interface SwarmCard { id: string; name: string; count: number; leads: SwarmLead[] }
+ export interface LeadRecap { tabId: string; leadId: string; text: string; at: number; none: boolean }
+ export function leadsOf(state: Json, machineId: string, live: (harnessId: string) => { inTurn: boolean; since?: number } | null, me?: string): { count: number; leads: SwarmLead[] } // me: the signed-in account id; owner is the machine owner's email
+ export function lastLeadMessage(messages: Json[], leadId: string): { text: string; at: number } | null
+ export class SwarmCards {
+ constructor(core: CoreApi, machineId: string, options?: { now?: () => number; intervalMs?: number })
+ want(on: boolean): void // start/stop the 5 s poll
+ tick(): Promise<void> // one poll (tests call it directly)
+ recap(tabId: string, leadId: string): Promise<LeadRecap>
+ open(tabId: string, leadId: string | null): void // the recap on the Pro, for pushes
+ onCards?: (cards: SwarmCard[]) => void
+ onRecap?: (recap: LeadRecap) => void
+ }
+ ```
+- Consumes: `backend(core, method, path)` from `cli/src/superTabs/host.ts`.
+
+- [ ] **Step 1: Write the failing tests** in `cards.spec.ts`:
+ - `leadsOf` picks one Lead per project via `conversations[leadConversationId].leadId`; an old tab without `projects` uses the `lead` project; a project with no Lead agent is skipped and not counted.
+ - status: project with a `needs_human` assignment → `ask`; `blocked` → `stuck` (ask wins over stuck); local Lead with `live().inTurn` → `work` with `since`; remote Lead with an assignment `working` → `work` without `since`; otherwise `done`.
+ - `local` is the harnessId only when `agent.machineId === machineId` and `live()` is non-null; `owner` is the owner's name from `people[]` only for a Lead whose `machineOwnerId` is not the signed-in person.
+ - order ask, stuck, work, done, ties in project order; 13 projects → 12 leads, `count` 13; names cut to 48 bytes on a UTF-8 boundary.
+ - `lastLeadMessage` skips rows with `source` and rows by other authors, returns the newest; null when none.
+ - `tick`: first call lists (`GET /api/super-tabs`, following `next`) and reads every tab; a second call with unchanged revisions reads no tab; a changed revision reads only that tab; a tab gone from the list disappears; a thrown list read keeps the last cards and calls `onCards` not at all; a 403 on one tab drops only that tab. More than 16 tabs → first 16.
+ - `recap`: reads the newest page, falls back one page with `before` when the Lead has no row there, returns `none: true` after that; a second call with the same `lastMessageSequence` makes no request; text cut at 1,500 bytes.
+ - `open` + a later `tick` where the open Lead's conversation advanced → `onRecap` fires once with the new text.
+ - a paused tab keeps its card and every Lead reads `done`.
+ - `want(false)` clears the interval; no request after it.
+
+- [ ] **Step 2: Run** `cd cli && npx vitest run src/superTabs/cards.spec.ts` — Expected: FAIL (module not found).
+
+- [ ] **Step 3: Implement `cards.ts`.** Person identity (no `asAgentId`). Cache per tab `{ revision, state }` and per Lead `{ sequence, recap }` keyed by `lastMessageSequence` of the Lead conversation. Emit `onCards` only when the serialized list changed.
+
+- [ ] **Step 4: Run** the spec again — Expected: PASS.
+
+- [ ] **Step 5: Commit** `feat(super-tabs): read Swarm cards for the Harness Pro`.
+
+### Task 2: Bridge service ↔ core ↔ devices
+
+**Files:**
+- Modify: `cli/src/core/api.ts` (`SuperTabsCore` near :1165, `DevicesPort` near :1204, `DEVICES_FALLBACKS`, `DEVICE_WINDOW_FRAMES` :1205), `cli/src/core/experimentQueries.ts` (QUERIES :37, switch near :123), `cli/src/services/processCoreApi.ts` (:239), `cli/src/core/main.ts` (:814 and the device attach replay near :891), `cli/src/services/devicesProcess.ts`, `cli/src/superTabs/service.ts`, `cli/src/testing/fakeCore.ts`
+- Create: `cli/src/core/superTabCards.ts`, `cli/src/core/superTabCards.spec.ts`
+- Test: `cli/src/services/processCoreApi.spec.ts`, `cli/src/superTabs/service.spec.ts`
+
+**Interfaces:**
+- Consumes: `SwarmCards`, `SwarmCard`, `LeadRecap` (Task 1).
+- Produces:
+ - `SuperTabsCore.cards(items: SwarmCard[]): void`, `SuperTabsCore.cardRecap(recap: LeadRecap): void` (service → core; queries `super_tab_cards`, `super_tab_card_recap`, superTabs service only).
+ - `DevicesPort.swarmCards(items: SwarmCard[]): void`, `DevicesPort.swarmCardRecap(recap: LeadRecap): void` (core → devices; last list replayed on attach).
+ - Service requests from the devices (through the core): `super_tabs { action: 'cardsWanted', on: boolean }`, `{ action: 'cardRecap', tabId, leadId }` → `LeadRecap`, `{ action: 'cardOpen', tabId, leadId: string | null }`.
+ - `'dial_super_tab'` added to `DEVICE_WINDOW_FRAMES`.
+
+- [ ] **Step 1: Write failing tests:** `superTabCards.spec.ts` — the core keeps the last list, forwards each list and recap to `devices`, replays the list on attach, validates items (ids `[A-Za-z0-9_-]{1,64}`, ≤16 cards, ≤12 leads, strings cut) and drops a malformed list; `processCoreApi.spec.ts` — `cards`/`cardRecap` map to the two queries; `service.spec.ts` — `cardsWanted` starts/stops `SwarmCards`, `cardRecap` returns its result, `cardOpen` calls `open`, all refused for a non-owner asker like other actions.
+- [ ] **Step 2: Run** `npx vitest run src/core/superTabCards.spec.ts src/services/processCoreApi.spec.ts src/superTabs/service.spec.ts` — Expected: FAIL.
+- [ ] **Step 3: Implement** following `core/superTabAttention.ts` and its wiring (`main.ts` :814, query list, `processCoreApi` :239, fake core).
+- [ ] **Step 4: Run** the specs, then `npm run typecheck` and `npm run test:core` — Expected: PASS, coverage 100 %.
+- [ ] **Step 5: Commit** `feat(core): carry Swarm cards from the superTabs service to the devices`.
+
+### Task 3: Cable frames and the desktop link in the daemon
+
+**Files:**
+- Modify: `cli/src/cable/cableSession.ts` (hello caps parse; `syncSwarms` area ~2529-2620; inbound switch near `swarm.select` :1298; `followApp` near :1263), `cli/src/cable/cableHost.ts`, `cli/src/services/devices.ts` (`swarms()` :460, `appFocus` :471, request routing), `cli/src/localWsServer.ts` (`appSwarmsFrom` :231), the `AppSwarms` type (cableSession.ts :252)
+- Test: `cli/src/cable/cableSession.spec.ts`, `cli/src/services/devices.spec.ts`, `cli/src/localWsServer.spec.ts`
+
+**Interfaces:**
+- Consumes: `DevicesPort.swarmCards/swarmCardRecap` and the `cardsWanted/cardRecap/cardOpen` requests (Task 2).
+- Produces (wire, spec §3): out `supertabs` (ids) + `supertab` (one per Swarm), `supertab.recap`, `supertab.focus`; in `supertab.recap.get`, `supertab.open`, `supertab.select`. `AppSwarms` items gain optional `superTabId: string` and `projectId: string`. Window frame `dial_super_tab { superTabId, projectId }`.
+
+- [ ] **Step 1: Write failing tests** in `cableSession.spec.ts`:
+ - a device without `swarmCard:"v1"` receives none of the three frames; with it, `supertabs` on attach, after a list change (debounced 300 ms), and on resync; each `item.tab` is the desk tab whose `superTabId` matches, else `""`.
+ - a 16×12 list goes as one `supertabs` + 16 `supertab` frames, each under 512 JSON tokens; a change to one Swarm resends only its `supertab`.
+ - `supertab.recap.get` → `cardRecap` request → `supertab.recap` frame; `supertab.open` → `cardOpen`; an unsolicited `swarmCardRecap` reaches the device only for the open Lead.
+ - the active desk tab being a Swarm with `projectId` → one `supertab.focus` with that project's Lead; unchanged on repeat; none when the desktop has no Swarm tab active.
+ - `supertab.select` → window frame `dial_super_tab {superTabId, projectId}`; the next `app_swarms` reporting that same project sends no `supertab.focus` (no echo).
+ - `devices.spec.ts`: first capable device attached → `cardsWanted on:true`; last one gone → `on:false`.
+ - `localWsServer.spec.ts`: `appSwarmsFrom` keeps `superTabId`/`projectId` (ids validated, dropped when malformed).
+- [ ] **Step 2: Run** `npx vitest run src/cable/cableSession.spec.ts src/services/devices.spec.ts src/localWsServer.spec.ts` — Expected: FAIL.
+- [ ] **Step 3: Implement.** Keep the project→Lead map from the last `swarmCards` list to resolve `projectId` ↔ lead id for focus and select.
+- [ ] **Step 4: Run** the specs, `npx vitest run src/superTabs src/cable src/services/devices.spec.ts src/architecture.spec.ts`, `npm run typecheck`, `npm run test:core` — Expected: PASS.
+- [ ] **Step 5: Commit** `feat(cable): Swarm cards, Lead recaps and focus on the Harness Pro`.
+
+### Task 4: Desktop reports the open Swarm project and opens one on request
+
+**Files:**
+- Modify: `desktop/lib/state/app_state.dart` (`_announceOpenPanesToDial` :5086-5194; window frame switch near `dial_swarm` :20106), `desktop/lib/super_tabs/controller.dart` (`select` :324)
+- Test: `desktop/test/super_tab_dial_test.dart` (new)
+
+**Interfaces:**
+- Consumes: window frame `dial_super_tab { superTabId, projectId }` (Task 3).
+- Produces: `app_swarms` rows with `superTabId` and `projectId` for `kind == 'superTab'`; `projectId` = `snapshot.projectFor(selectedId)?.id`.
+
+- [ ] **Step 1: Write failing tests:** a Swarm tab row carries `superTabId` and the selected conversation's `projectId`; selecting another project re-announces; `dial_super_tab` for an open Swarm focuses that tab and calls `select(project.leadConversationId)`; for a Swarm not open it opens the tab first; a device-made selection sets a flag so the following announce is tagged and not echoed (assert the announce payload carries `fromDevice: true` once).
+- [ ] **Step 2: Run** `cd desktop && flutter test --no-pub test/super_tab_dial_test.dart` — Expected: FAIL.
+- [ ] **Step 3: Implement** in `app_state.dart` and `controller.dart`; have the controller notify the app on `select` so the announce runs.
+- [ ] **Step 4: Run** the test, `flutter test --no-pub $(ls test/super_tab_*_test.dart test/swarm_*_test.dart)`, `flutter analyze --no-pub lib/super_tabs lib/state/app_state.dart` — Expected: PASS, no issues. (Task 3 then ignores a focus whose announce has `fromDevice: true`: add that case to its echo test if not covered.)
+- [ ] **Step 5: Commit** `feat(desktop): tell devices which Swarm project is open; open one a device picks`.
+
+### Task 5: Pro firmware — protocol and model
+
+**Files:**
+- Modify: `devices/harness-pro/firmware/main/cable/pro_cable.c` (hello near :224; dispatch; new handlers), `main/cable/cable_types.h`, `main/pro_app_api.h`, `main/app/pro_app.c`, `main/pod/pod_model.h`, `main/pod/pod_model.c`
+- Test: `test/test_pro_cable.c`, `test/test_pod_model.c`
+
+**Interfaces:**
+- Produces:
+ ```c
+ enum { SWARMS_CARD_MAX = 16, SWARM_LEADS_MAX = 12, SWARM_TEXT_MAX = 1501 };
+ typedef enum { POD_LEAD_ASK, POD_LEAD_STUCK, POD_LEAD_WORK, POD_LEAD_DONE } pod_lead_state_t;
+ typedef enum { POD_RECAP_NONE, POD_RECAP_LOADING, POD_RECAP_LOADED, POD_RECAP_EMPTY } pod_recap_state_t;
+ typedef struct { char id[ID_MAX], project[49], engine[16], owner[49], local[ID_MAX]; pod_lead_state_t state; uint32_t since_s, since_at_ms;
+ pod_recap_state_t recap; char *text; uint32_t text_at; } pod_lead_t; // text in PSRAM
+ typedef struct { char id[ID_MAX], tab[ID_MAX], name[49]; uint16_t count; uint8_t lead_n; pod_lead_t leads[SWARM_LEADS_MAX]; } pod_swarm_t;
+ void pro_app_supertabs(const pod_swarm_t *items, int n);
+ void pro_app_supertab_recap(const char *tab, const char *lead, const char *text, uint32_t at, bool none);
+ void pro_app_supertab_focus(const char *tab, const char *lead);
+ void pro_cable_supertab_send(const char *t, const char *tab, const char *lead); // "supertab.recap.get" | "supertab.open" | "supertab.select"
+ const pod_swarm_t *pod_model_swarm_for_tab(const pod_model_t *, const char *tab_id); // desk tab → Swarm
+ const pod_swarm_t *pod_model_swarm(const pod_model_t *, const char *swarm_id);
+ ```
+- [ ] **Step 1: Write failing tests:** hello contains `"swarmCard":"v1"`; `supertabs` with 2 Swarms × 3 Leads parses all fields; 20 Swarms → 16; 15 Leads → 12; a 60-byte name cut to 48 on a UTF-8 boundary; unknown `state` → done; a malformed item is skipped, not the frame; `supertab.recap` stores text (1,500-byte cut) and sets LOADED, `none:true` sets EMPTY; a new `supertabs` keeps cached recap text for Leads still present and frees it for Leads gone; `pod_model_swarm_for_tab` matches `tab`.
+- [ ] **Step 2: Run** `cd devices/harness-pro/firmware && bash test/run.sh` — Expected: the new cases FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run** `bash test/run.sh` — Expected: PASS.
+- [ ] **Step 5: Commit** `feat(pro): parse Swarm cards and Lead recaps`.
+
+### Task 6: Pro firmware — Swarm card on Home
+
+**Files:**
+- Modify: `main/pod/home/ph_overview.c` (`card()` :338, `working_card` :401, `peek`, `ph_view_home`), `main/pod/home/ph.h` (colours), `main/pod/pod_view.c` / `pod_view.h` (home pages), `main/pod/pod_nav.h` (`swarm_page` beside `work_page` :27), `main/app/pod_glue.c` (swipe band :462-476, hits)
+- Test: `test/test_ph_views.c`, `test/test_ph_glue.c`, `test/pod_render.c`, `test/golden.sh`, `test/golden.txt`, `test/golden-liberation.txt`
+
+**Interfaces:**
+- Consumes: `pod_model_swarm_for_tab`, `pod_model_swarm`, `pod_swarm_t` (Task 5).
+- Produces: hit `POD_A_LEAD` (arg = lead index, id = swarm id) on each pet; `nav.swarm_page`; Swarms without a desk tab become extra Home pages after the desk tabs (`pod_home_pages`).
+
+- [ ] **Step 1: Write failing tests:** a desk tab linked to a Swarm draws the Swarm card (title = Swarm name, count = `count`, label "workspaces"); orange dot present iff any Lead is ASK; 3 pets per page centred like Working; 4 Leads → page 2 shows 1 centred; a swipe in y 256-536 pages `swarm_page`, past the last page moves to the next card; status lines "working · 2:14", "needs you", "stuck", "done"; a remote Lead shows its owner line; a Swarm with no desk tab adds a Home page; `POD_A_LEAD` hits over each pet.
+- [ ] **Step 2: Add render fixtures** `home:swarm:p1`, `home:swarm:p2`, `home:swarm:remote` to `pod_render.c` and `golden.sh`.
+- [ ] **Step 3: Run** `bash test/run.sh` — Expected: FAIL.
+- [ ] **Step 4: Implement** by sharing `working_card`'s pet-row drawing (extract `pet_row(...)` used by both) rather than copying it.
+- [ ] **Step 5: Regenerate goldens** `bash test/golden.sh && PRO_FONT=fonts/LiberationSans-Regular.ttf bash test/golden.sh`; confirm the diff only adds the new screens; render the three fixtures to PNG and compare with the mockup's A1–A3.
+- [ ] **Step 6: Run** `bash test/run.sh`, both `golden.sh --check` runs — Expected: PASS.
+- [ ] **Step 7: Commit** `feat(pro): the Swarm card — workspaces and their Leads on Home`.
+
+### Task 7: Pro firmware — Lead recap, follow and select
+
+**Files:**
+- Create: `main/pod/home/ph_lead.c`
+- Modify: `main/pod/home/ph.h`, `main/pod/pod_view.h` (new view `POD_VIEW_LEAD`), `main/pod/pod_nav.c` (open/follow), `main/app/pod_glue.c` (horizontal swipe on the view, hits, `supertab.focus`), `main/app/pro_app.c`, `devices/harness-pro/docs/cable.md`
+- Test: `test/test_ph_views.c`, `test/test_ph_glue.c`, `test/test_pro_app.py`, `test/pod_render.c`, `test/golden.sh`, goldens
+
+**Interfaces:**
+- Consumes: `POD_A_LEAD`, `pro_cable_supertab_send`, `pro_app_supertab_recap/_focus` (Tasks 5–6).
+- Produces: `void ph_view_lead(pod_out_frame_t *, const pod_nav_t *, pod_model_t *, uint32_t now_ms)`; nav frame fields `swarm` (id) and `lead` (index).
+
+- [ ] **Step 1: Write failing tests:** tapping a Lead pet opens `POD_VIEW_LEAD`, sends `supertab.select`, `supertab.open` and (cache cold) `supertab.recap.get`; LOADING draws "…", LOADED the bubble, EMPTY "No message yet"; header shows the Swarm name and the project; a horizontal swipe moves to the next/previous Lead in card order and sends `supertab.select` + `supertab.open`; leaving the view sends `supertab.open` with no lead; a local Lead's recap offers talk on its `local` harness, a remote one does not; `supertab.focus` opens that Lead's recap (not while talking or updating; pending until the Swarm list has it); the Lead removed while open moves to the next Lead, or Home if none; on relink the open view re-sends `supertab.open` and `supertab.recap.get`.
+- [ ] **Step 2: Add render fixtures** `lead:loaded`, `lead:ask`, `lead:loading`, `lead:none`, `lead:remote`.
+- [ ] **Step 3: Run** `bash test/run.sh` — Expected: FAIL.
+- [ ] **Step 4: Implement** `ph_lead.c` from `ph_recap.c` (bubble, tail, signing pet; ask/stuck edge stripe in orange/red); document the frames in `docs/cable.md` §1–2.
+- [ ] **Step 5: Regenerate goldens** (both fonts), compare PNGs with the mockup's B1–B3.
+- [ ] **Step 6: Run** `bash test/run.sh`, both golden `--check`, and `. ~/esp/esp-idf-5.5.4/export.sh && idf.py -B build -DPROJECT_VER=0.0.99-ci build` — Expected: PASS, image fits `ota_0`.
+- [ ] **Step 7: Commit** `feat(pro): Lead recaps — read, swipe, follow the desktop, pick a project`.
+
+### Task 8: Review, real-device check, PR
+
+- [ ] **Step 1:** Independent code review of the whole branch (fresh reviewer); fix findings with tests.
+- [ ] **Step 2:** With the owner's go-ahead: `make install-cli` from the branch, build firmware with `-DPROJECT_VER=0.1.13-swarmcard`, flash unit 64:61 via `scripts/flash.sh` (FLASH_PORT from `ls /dev/cu.usbmodem*`), check the card, swipes, recap, follow and select against the mockup with the "openharness" Swarm.
+- [ ] **Step 3:** With the owner's go-ahead: commit, push, open the PR listing every check run (vitest specs, test:core, flutter tests/analyze, firmware run.sh, goldens both fonts, IDF build) and the manual check.