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.

Merge batch 11-03 b2300: #2845 (#2847)

0xken152ec58cb42d1e
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index b131549b2..975fc4173 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -4925,16 +4925,47 @@ describe('swarm cards', () => {
} finally { await session.stop() }
})
- it('a round\'s swarmBuddy supertab frame is unchanged by the Pro budget', async () => {
+ // Task #2525: the firmware's guard (cable_json_guard.h) drops any JSON frame over 512 tokens whole, a round dial's too.
+ // A round frame carries no seq, so the guard's 512 is its budget: 12 Leads with a Buddy each (483) and 11 go unchanged.
+ it('a round\'s swarmBuddy supertab frame of 12 or 11 Leads without a thread is unchanged by the token budget', async () => {
+ for (const count of [12, 11]) {
+ const log = vi.fn()
+ const { session, port } = await connect(cardHost({ cards: [card('st1', Array.from({ length: count }, (_, i) => big(i + 1)))] }, { log }))
+ try {
+ port.say(BUDDY)
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
+ const frame = ofType(port, 'supertab')[0], leads = frame.leads as Array<Record<string, unknown>>
+ expect(tokens(frame)).toBeLessThanOrEqual(512)
+ expect(leads).toHaveLength(count)
+ expect(leads.every((l) => 'buddy' in l && String(l.project).length === 48 && String(l.chatName).length === 48)).toBe(true)
+ expect(log).not.toHaveBeenCalledWith(expect.stringContaining('too large'))
+ } finally { await session.stop() }
+ }
+ })
+
+ // Task #2525: the Swarm chat is every project's Buddy face, so the cards gave its thread to every Lead; with 12 the frame
+ // came to 513 tokens and the dial dropped every one (frozen card, no recap, no way out of the thread).
+ it('a swarmThread dial\'s frame of 12 Leads in the Swarm chat\'s thread fits 512 tokens, and the open Lead keeps its thread', async () => {
+ const swarmChat = { ...buddyChat, id: 'sb', thread: { root: 'm9', title: 'help me', replies: 2 } }
+ const cards = [card('st1', Array.from({ length: 12 }, (_, i) => big(i + 1)).map((l) => ({ ...l, sideChat: { ...swarmChat, name: String(l.sideChat!.name) } })))]
const log = vi.fn()
- const { session, port } = await connect(cardHost({ cards: twelve() }, { log }))
+ const { session, port } = await connect(cardHost({ cards }, { log }))
try {
- port.say(BUDDY)
+ port.say({ ...BUDDY, swarmThread: 'v1' })
await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))
- const leads = ofType(port, 'supertab')[0].leads as Array<Record<string, unknown>>
- expect(leads).toHaveLength(12)
+ // No Lead open yet: no thread is kept.
+ expect(tokens(ofType(port, 'supertab')[0])).toBeLessThanOrEqual(512)
+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead5' })
+ await settle()
+ await session.syncSwarmCards()
+ await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(2))
+ for (const f of ofType(port, 'supertab')) expect(tokens(f)).toBeLessThanOrEqual(512)
+ const leads = ofType(port, 'supertab').at(-1)!.leads as Array<Record<string, unknown>>
+ expect(leads.find((l) => l.id === 'lead5')).toMatchObject({ chatId: 'sb', thread: 'm9', threadTitle: 'help me', threadReplies: 2 })
+ expect(leads.filter((l) => 'thread' in l || 'threadTitle' in l || 'threadReplies' in l).map((l) => l.id)).toEqual(['lead5'])
+ // Threads go before any Buddy: every Lead keeps its Buddy.
expect(leads.every((l) => 'buddy' in l)).toBe(true)
- expect(log).not.toHaveBeenCalledWith(expect.stringContaining('Buddy block'))
+ expect(log).toHaveBeenCalledWith(expect.stringMatching(/supertab st1 too large — \d+ thread\(s\) dropped/))
} finally { await session.stop() }
})
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index a5c161d15..2cd01b1ba 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -206,11 +206,13 @@ const NAME_CUTS = [24, 12, 6, 3, 1, 0]
* doubles, past it even with no Buddy names at all (review of #2146). Last, whole Buddy blocks go, from the least urgent Lead
* up: engines of control characters (six bytes each in JSON) leave a Buddy frame at 8,275 bytes with every name empty, and
* without its Buddies a frame is today's swarmChat one, about 5.3 KB at most. A frame that fits is sent as it is.
- * With `tokens`, as for the Harness Pro, whose guard refuses a JSON frame over 512 tokens, a frame fits only if it is also
- * within that many JSON tokens. Shorter names do not lower that count, so only the Buddy blocks go for it.
- * Returns how many Buddy blocks went, for the caller's log.
+ * With `tokens`, as for every dial, whose guard refuses a JSON frame over 512 tokens whole (firmware cable_json_guard.h), a
+ * frame fits only if it is also within that many JSON tokens. Shorter names do not lower that count, so for it the threads of
+ * every Lead but the one the dial has open (`open`) go first, then the Buddy blocks (task #2525: 12 Leads in the Swarm chat's
+ * thread came to 513 tokens, and the dial dropped every frame).
+ * Returns how many threads and Buddy blocks went, for the caller's log.
*/
-function fitFrame(frame: { name: string; leads: Array<Record<string, unknown>> }, tokens?: number): number {
+function fitFrame(frame: { name: string; leads: Array<Record<string, unknown>> }, tokens?: number, open?: string): { threads: number; buddies: number } {
const small = () => Buffer.byteLength(JSON.stringify(frame)) < CABLE_MAX_PAYLOAD
const fits = () => small() && (tokens === undefined || jsonTokens(frame) <= tokens)
type Named = { [key: string]: unknown }
@@ -222,9 +224,15 @@ function fitFrame(frame: { name: string; leads: Array<Record<string, unknown>> }
for (const [holder, key] of fields) holder[key] = truncateUtf8(String(holder[key]), bytes)
}
}
- let dropped = 0
- for (let i = frame.leads.length - 1; i >= 0 && !fits(); i--) if (frame.leads[i].buddy !== undefined) { delete frame.leads[i].buddy; dropped++ }
- return dropped
+ let threads = 0, blocks = 0
+ if (!fits()) {
+ for (const l of frame.leads) {
+ if (l.id === open || !('thread' in l)) continue
+ delete l.thread; delete l.threadTitle; delete l.threadReplies; threads++
+ }
+ }
+ for (let i = frame.leads.length - 1; i >= 0 && !fits(); i--) if (frame.leads[i].buddy !== undefined) { delete frame.leads[i].buddy; blocks++ }
+ return { threads, buddies: blocks }
}
/** A Lead's new message as the round dial's alert, sized as the recap is. */
function noticeFrame(tab: string, lead: string, n: LeadNotice): Message {
@@ -240,6 +248,9 @@ function fitText(full: string, make: (text: string) => Message): Message {
let nextCardSession = 0
const SWARM_IDS_MAX = 24
const SWARM_TOKENS_MAX = 480
+/** The firmware's JSON guard itself (cable_json_guard.h): a frame of more tokens is dropped whole. A round dial's frames carry
+ * no seq, so they are fitted to it; a Pro's keep SWARM_TOKENS_MAX's margin for theirs. */
+const GUARD_TOKENS_MAX = 512
/** The models a dial's picker holds (ui_habitat.c): more are never sent. */
const MODELS_MAX = 48
@@ -2982,12 +2993,15 @@ export class CableSession {
const frame = { t: 'supertab', id: card.id, tab, name: card.name, count: card.count, ...(this.swarmBuddy ? { side: card.side ?? 'pm' } : {}),
leads: card.leads.slice(0, SWARM_LEADS_MAX).map((l) => this.swarmBuddy ? buddyLead(l, this.swarmThread) : this.swarmChat ? chatLead(l, l.chat, this.swarmThread) : { id: l.id, projectId: l.projectId, project: l.project,
engine: l.engine, owner: l.owner, local: l.local, state: l.state, order: l.order, ...(l.since === undefined ? {} : { since: l.since }) }) }
- const buddiesDropped = fitFrame(frame, this.seqOn ? SWARM_TOKENS_MAX : undefined)
+ // Every dial's guard drops a frame over 512 tokens whole, a round dial's too (task #2525).
+ const dropped = fitFrame(frame, this.seqOn ? SWARM_TOKENS_MAX : GUARD_TOKENS_MAX, this.openLead?.tabId === card.id ? this.openLead.leadId : undefined)
const key = JSON.stringify(frame)
if (this.cardKeys.get(card.id) === key) continue
this.cardKeys.set(card.id, key)
- // Once per frame sent: those Leads show "No Buddy here yet" though they have one (spec 2026-10-30-harness-pro-swarm-parity, Scale).
- if (buddiesDropped) this.log(`cable: supertab ${card.id.slice(0, 8)} too large — ${buddiesDropped} Buddy block(s) dropped`)
+ // Once per frame sent: those Leads show "No Buddy here yet" though they have one (spec 2026-10-30-harness-pro-swarm-parity,
+ // Scale), and the other Leads read their chat's main stream.
+ const cuts = [dropped.threads && `${dropped.threads} thread(s)`, dropped.buddies && `${dropped.buddies} Buddy block(s)`].filter(Boolean)
+ if (cuts.length) this.log(`cable: supertab ${card.id.slice(0, 8)} too large — ${cuts.join(', ')} dropped`)
await this.send(frame)
}
if (this.swarmChat) await this.pushNotices(cards, force)
diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.ts
index e17ce5dc9..9abf25a9f 100644
--- a/cli/src/superTabs/cards.spec.ts
+++ b/cli/src/superTabs/cards.spec.ts
@@ -1978,8 +1978,8 @@ describe('SwarmCards with one Buddy per Swarm', () => {
const state = (seq = 1, over: Record<string, unknown> = {}) => chats({ buddies: true, agents: [...chats().agents as object[], buddy({ buddyScope: 'swarm' })],
conversations: [...swarm().conversations, sb(seq), group()], ...over })
const hears = [said(1, 'a1', { text: 'from the PM' }), said(2, 'y1', { text: 'from the Buddy' }), said(3, 'me', { author: { kind: 'person', id: 'me' }, text: 'mine' })]
- const build = (pages: Record<string, unknown[]> = { sb: hears }) => {
- const t = setup({ t1: { lastChangedAt: 1, state: state() } }, { messages: path => ({ messages: pages[/conversations\/([^/]+)\/messages/.exec(path)?.[1] ?? ''] ?? [], next: null }) })
+ const build = (pages: Record<string, unknown[]> = { sb: hears }, post?: () => { status: number; body: Record<string, unknown> }) => {
+ const t = setup({ t1: { lastChangedAt: 1, state: state() } }, { messages: path => ({ messages: pages[/conversations\/([^/]+)\/messages/.exec(path)?.[1] ?? ''] ?? [], next: null }), post })
const lead = (id: string, cards = t.seen.at(-1)) => cards?.[0].leads.find(l => l.id === id)
const reads = () => t.calls.filter(c => c.includes('/conversations/sb/messages')).length
const move = async (seq: number, over: Record<string, unknown> = {}) => { t.tabs.t1.lastChangedAt++; t.tabs.t1.state = state(seq, over); await t.cards.tick() }
@@ -2060,6 +2060,34 @@ describe('SwarmCards with one Buddy per Swarm', () => {
expect(t.lead('a1')).not.toHaveProperty('buddyNotice')
})
+ // Task #2525: the Swarm chat is every project's Buddy face, so a thread matched by conversation landed on every Lead, and
+ // with 12 projects the round dial's frame passed the firmware's 512-token guard. The thread is on the face Lead's alone.
+ it('puts a dial thread in the Swarm chat on the Lead it was started from only', async () => {
+ const t = build({ sb: hears }, () => ({ status: 200, body: { success: true, data: { result: { messageId: 'm9' } } } }))
+ t.cards.want(true, [], null)
+ await vi.waitFor(() => expect(t.seen).toHaveLength(1))
+ t.cards.side('t1', 'buddy')
+ expect(await t.cards.say('h-a1', 'help me\nplease', 'buddy', undefined, false, { threaded: true }))
+ .toEqual({ said: true, thread: { tabId: 't1', conversationId: 'sb', root: 'm9' } })
+ expect(t.lead('a1')?.sideChat).toMatchObject({ kind: 'buddy', id: 'sb', thread: { root: 'm9', title: 'help me' } })
+ // The other project's Buddy face is the same chat, read as its main stream.
+ expect(t.lead('a2')?.sideChat).toMatchObject({ kind: 'buddy', id: 'sb' })
+ expect(t.lead('a2')?.sideChat).not.toHaveProperty('thread')
+ expect(await t.cards.recap('t1', 'a2', 'buddy')).not.toHaveProperty('thread')
+ t.cards.want(false)
+ })
+
+ it('puts the window\'s thread in the Swarm chat on the Lead the dial has open only', async () => {
+ const t = build()
+ t.cards.want(true, [], null)
+ await vi.waitFor(() => expect(t.seen).toHaveLength(1))
+ t.cards.open('s1', 't1', 'a2', 'buddy')
+ t.cards.want(true, [], { tabId: 't1', conversationId: 'sb', threadRoot: 'r1' })
+ expect(t.lead('a2')?.sideChat?.thread?.root).toBe('r1')
+ expect(t.lead('a1')?.sideChat).not.toHaveProperty('thread')
+ t.cards.want(false)
+ })
+
it('refuses a recap or a word for the Swarm chat once it stops being the reader\'s while the read is out, and for a stale or foreign chat id', async () => {
const t = build()
t.cards.want(true, [], null)
diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.ts
index c1caa28f9..a10dd85ad 100644
--- a/cli/src/superTabs/cards.ts
+++ b/cli/src/superTabs/cards.ts
@@ -133,7 +133,7 @@ function buddyOf(agents: Json[], chat: Json, me: string | undefined, local: (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, focus?: string, side?: CardSide, thread?: (conversationId: string) => SwarmChat['thread']): { count: number; leads: SwarmLead[] } {
+export function leadsOf(state: Json, machineId: string, live: (harnessId: string) => { inTurn: boolean; since?: number } | null, me?: string, focus?: string, side?: CardSide, thread?: (conversationId: string, leadId: string) => SwarmChat['thread']): { count: number; leads: SwarmLead[] } {
const agents = list(state.agents), conversations = list(state.conversations), people = list(state.people)
const buddies = state.buddies === true
// An old tab has no `projects`: its one project is the tab itself, `lead`, led by the conversation `lead`.
@@ -177,7 +177,7 @@ export function leadsOf(state: Json, machineId: string, live: (harnessId: string
const projectId = projectKey(project)
const chatOf = (face: Face | null): SwarmChat | undefined => {
if (!face) return undefined
- const inThread = thread?.(face.conversation.id as string)
+ const inThread = thread?.(face.conversation.id as string, String(agent.id))
return { ...faceChat(face, String(agent.id), agents, me, turnHere), ...(inThread ? { thread: inThread } : {}) }
}
const chat = chatOf(faceOf(conversations, projectId, lead, focus, me, buddies))
@@ -308,8 +308,9 @@ export class SwarmCards {
private inChat = new WeakSet<LeadNotice>()
/** The side a swarmBuddy dial swiped to, per Swarm; cleared by the window's next focus change (the newest wins). */
private sides = new Map<string, CardSide>()
- /** The thread the dial's own words started, per Swarm (spec 2026-11-03-dial-thread-face); cleared like `sides`. */
- private threads = new Map<string, { conversationId: string; root: string; title: string; at: number; opened?: true }>()
+ /** The thread the dial's own words started, per Swarm (spec 2026-11-03-dial-thread-face), and the Lead whose face it was
+ * started from; cleared like `sides`. */
+ private threads = new Map<string, { conversationId: string; root: string; title: string; at: number; leadId: string; opened?: true }>()
/** Title and reply count of the app's threads, as the recap reads gave them (`${tab}/${root}`). */
private titles = new Map<string, { title: string; replies?: number; looked?: true; failures?: number; retryAt?: number }>()
/** The thread the dial last left, per Swarm: an older Desktop that announces it again does not pull the dial back into it. */
@@ -416,16 +417,27 @@ export class SwarmCards {
if (this.timer && this.live) { this.emit(); void this.pushOpen() }
}
- /** The root of the thread on the face whose conversation is `conversationId`: the one open in the window beside it, else the
- * one the dial's words started there. */
- private threadOn(tabId: string, conversationId: string): string | undefined {
+ /** The root of the thread on Lead `leadId`'s face, whose conversation is `conversationId`: the one open in the window beside
+ * it, else the one the dial's words started there. One chat can be on many Leads' faces (the Swarm chat is every project's
+ * Buddy face), and its thread is on one Lead's alone: the dial's own on the Lead it was started from, the window's on the
+ * Lead the dial has open (on each while it has none open). Matched by conversation alone, it went on every Lead, and 12
+ * projects took the round dial's frame past the firmware's 512-token guard (task #2525). */
+ private threadOn(tabId: string, conversationId: string, leadId: string): string | undefined {
const open = this.focus?.tabId === tabId && this.focus.conversationId === conversationId ? this.focus.threadRoot : undefined
const own = this.threads.get(tabId)
- return open ?? (own?.conversationId === conversationId ? own.root : undefined)
+ const mine = own?.conversationId === conversationId ? own : undefined
+ if (open !== undefined && open !== mine?.root) return this.dialOpens(tabId, leadId) ? open : undefined
+ return mine?.leadId === leadId ? mine.root : undefined
}
- private threadInfo(tabId: string, conversationId: string): SwarmChat['thread'] {
- const root = this.threadOn(tabId, conversationId)
+ /** Whether the dial has Lead `leadId`'s chat open in this Swarm, or no Lead's chat at all. */
+ private dialOpens(tabId: string, leadId: string): boolean {
+ const open = [...this.opened.values()].filter(o => o.tabId === tabId && o.chat)
+ return !open.length || open.some(o => o.leadId === leadId)
+ }
+
+ private threadInfo(tabId: string, conversationId: string, leadId: string): SwarmChat['thread'] {
+ const root = this.threadOn(tabId, conversationId, leadId)
if (root === undefined) return undefined
const own = this.threads.get(tabId), read = this.titles.get(`${tabId}/${root}`)
return { root, title: own?.root === root ? own.title : read?.title ?? '', ...(read?.replies !== undefined ? { replies: read.replies } : {}) }
@@ -573,7 +585,7 @@ export class SwarmCards {
if (!tab) continue
const focus = this.focus?.tabId === row.id ? this.focus.conversationId : undefined
const side = this.sideOf(row.id, tab.state)
- const { count, leads } = leadsOf(tab.state, this.machineId, live, this.me, focus, side, id => this.threadInfo(row.id, id))
+ const { count, leads } = leadsOf(tab.state, this.machineId, live, this.me, focus, side, (id, lead) => this.threadInfo(row.id, id, lead))
const noticed = leads.map(lead => {
const notice = this.notices.get(recapKey(row.id, lead.id)), buddyNotice = this.buddyNotices.get(recapKey(row.id, lead.id))
return { ...lead, ...(notice ? { notice } : {}), ...(buddyNotice ? { buddyNotice } : {}) }
@@ -721,7 +733,7 @@ export class SwarmCards {
const id = face.conversation.id as string
// The thread open beside the window's conversation, while that conversation is the one on the face: any agent's reply
// there is its recap (a worker answering in the Lead's thread, the Buddy's thread session).
- const thread = this.threadOn(tabId, id)
+ const thread = this.threadOn(tabId, id, leadId)
const voices = thread === undefined ? voicesOf(face, leadId, list(state.agents), this.me)
: new Set(list(state.agents).map(a => a.id).filter((a): a is string => typeof a === 'string'))
return { id, sequence: sequenceOf(face.conversation), voices, chatId: id,
@@ -895,7 +907,7 @@ export class SwarmCards {
// Only if the person, the face and the window are where the call began: a post out while any moved starts no thread.
const now = this.target(tabId, agent!.id as string, chat)
if (this.me !== reader || gen !== this.focusGen || now?.id !== to || now.thread !== undefined) return { said: true }
- this.threads.set(tabId, { conversationId: to, root, title: titleOf(text), at: this.now() })
+ this.threads.set(tabId, { conversationId: to, root, title: titleOf(text), at: this.now(), leadId: agent!.id as string })
if (this.timer && this.live) { this.emit(); void this.pushOpen() }
return { said: true, thread: { tabId, conversationId: to, root } }
}