The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Round dial: Buddy only on the Lead face, no PM side, no threads (daemon) (#3411)
harness-for-autonomous[bot]1795c4a3003d
diff --git a/cli/src/cable/cableHost.spec.ts b/cli/src/cable/cableHost.spec.tsindex 66ba0399e..31954aeeb 100644--- a/cli/src/cable/cableHost.spec.ts+++ b/cli/src/cable/cableHost.spec.ts@@ -1029,7 +1029,7 @@ describe('Swarm cards', () => {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(), swarmCardSide: vi.fn(), superTabSelected: vi.fn(), superTabThread: vi.fn(), swarmSay: vi.fn(async () => ({ said: true as const })),+ swarmCardsWanted: vi.fn(), swarmCardOpen: vi.fn(), superTabSelected: vi.fn(), swarmSay: vi.fn(async () => ({ said: true as const })),swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'hi', at: 1, none: false })),})const host = new DaemonCableHost(w)@@ -1049,28 +1049,13 @@ describe('Swarm cards', () => {expect(w.swarmSay).toHaveBeenLastCalledWith('h1', 'ship it', true)await host.swarmSay('h1', 'ship it')expect(w.swarmSay).toHaveBeenLastCalledWith('h1', 'ship it', false)- // A dial that speaks swarmBuddy asks for the face on its side, and says which side it swiped to.+ // A dial that speaks swarmBuddy asks for its Buddy face.await host.swarmCardRecap('st1', 'l1', 'buddy')expect(w.swarmCardRecap).toHaveBeenLastCalledWith('st1', 'l1', 'buddy')- host.swarmCardSide('st1', 'buddy')- expect(w.swarmCardSide).toHaveBeenLastCalledWith('st1', 'buddy')await host.swarmSay('h1', 'ship it', 'buddy', 'pm1')expect(w.swarmSay).toHaveBeenLastCalledWith('h1', 'ship it', 'buddy', 'pm1')- // A swarmThread dial leaves the thread on its face (with its chat flag), and the window closes (null) or opens (a root) a- // thread beside a conversation, with no project pick.- const left = vi.fn(async () => ({ tabId: 'st1', conversationId: 'c1' }))- const threaded = new DaemonCableHost(wiring({ swarmThreadLeave: left, superTabThread: w.superTabThread }))- expect(await threaded.swarmThreadLeave('st1', 'l1', 'buddy')).toEqual({ tabId: 'st1', conversationId: 'c1' })- expect(left).toHaveBeenLastCalledWith('st1', 'l1', 'buddy')- threaded.superTabThread('st1', 'c1', null)- expect(w.superTabThread).toHaveBeenLastCalledWith('st1', 'c1', null)- threaded.superTabThread('st1', 'c1', 'm9')- expect(w.superTabThread).toHaveBeenLastCalledWith('st1', 'c1', 'm9')- await host.swarmSay('h1', 'ship it', 'buddy', 'pm1', false, { thread: null, threaded: true })- expect(w.swarmSay).toHaveBeenLastCalledWith('h1', 'ship it', 'buddy', 'pm1', false, { thread: null, threaded: true })const bare = new DaemonCableHost(wiring())- expect(await bare.swarmThreadLeave('st1', 'l1')).toBeNull()- bare.swarmCardsWanted(false); bare.swarmCardOpen('c1', 'st1', null); bare.swarmCardSide('st1', 'pm'); bare.superTabSelected('st1', 'p1'); bare.superTabThread('st1', 'c1', null)+ bare.swarmCardsWanted(false); bare.swarmCardOpen('c1', 'st1', null); bare.superTabSelected('st1', 'p1')expect(await bare.swarmCardRecap('st1', 'l1')).toBeNull()expect(await bare.swarmSay('h1', 'ship it')).toEqual({ said: false })})diff --git a/cli/src/cable/cableHost.ts b/cli/src/cable/cableHost.tsindex f50015fa9..4fbcf106e 100644--- a/cli/src/cable/cableHost.ts+++ b/cli/src/cable/cableHost.ts@@ -28,7 +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 { CardChat, CardSide, LeadRecap, SaidOnCard, SayOptions, SwarmCard } from '../superTabs/cards.js'+import type { CardChat, CardSide, LeadRecap, SaidOnCard, 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'@@ -111,17 +111,11 @@ export interface CableHostWiring {swarmCardRecap?: (tabId: string, leadId: string, chat?: CardChat) => Promise<LeadRecap | null>/** The recap a device (one cable `session`) has open, or null once closed. */swarmCardOpen?: (session: string, tabId: string, leadId: string | null, chat?: CardChat) => void- /** A round dial that speaks swarmBuddy swiped to a side of a Swarm (spec 2026-10-29-round-dial-pm-buddy). */- swarmCardSide?: (tabId: string, side: CardSide) => void- /** A swarmThread dial left the thread on its face: the conversation whose thread the window should close, or null when it had none. */- swarmThreadLeave?: (tabId: string, leadId: string, chat?: CardChat) => Promise<{ tabId: string; conversationId: string } | null>/** Words for a Lead that runs here, posted as the person in its Swarm chat; not `said` when the harness leads no project,* `refused` with the backend's reason when it refused the post. */- swarmSay?: (harnessId: string, text: string, chat?: CardChat, chatId?: string, reviewed?: boolean, options?: SayOptions) => Promise<SaidOnCard>+ swarmSay?: (harnessId: string, text: string, chat?: CardChat, chatId?: string, reviewed?: boolean) => Promise<SaidOnCard>/** A device picked a Lead: the window opens that Swarm tab and project. */superTabSelected?: (superTabId: string, projectId: string, chat?: CardSide) => void- /** The dial's thread opened (a root) or closed (null) beside a conversation of a Swarm tab, with no project pick. */- superTabThread?: (superTabId: string, conversationId: string, threadRoot: string | null) => void/** A finger on the dial's glass, in pieces, while it is down; `superTabId` when it scrolls that Swarm's chat (a Pro's Lead view). */scrolled?: (phase: 'down' | 'move' | 'up', dy: number, velocity: number, superTabId?: string) => void/** The dial came, went, or started taking an update — see CableSession's onDialStatus. */@@ -561,29 +555,16 @@ export class DaemonCableHost implements CableHost {this.wiring.swarmCardOpen?.(session, tabId, leadId, chat)}- swarmCardSide(tabId: string, side: CardSide): void {- this.wiring.swarmCardSide?.(tabId, side)- }-- swarmSay(harnessId: string, text: string, chat: CardChat = false, chatId?: string, reviewed = false, options?: SayOptions): Promise<SaidOnCard> {- if (options) return this.wiring.swarmSay?.(harnessId, text, chat, chatId, reviewed, options) ?? Promise.resolve({ said: false })+ swarmSay(harnessId: string, text: string, chat: CardChat = false, chatId?: string, reviewed = false): Promise<SaidOnCard> {const pinned: [chatId?: string, reviewed?: boolean] = chatId ? (reviewed ? [chatId, true] : [chatId]) : []return this.wiring.swarmSay?.(harnessId, text, chat, ...pinned) ?? Promise.resolve({ said: false })}- swarmThreadLeave(tabId: string, leadId: string, chat: CardChat = true): Promise<{ tabId: string; conversationId: string } | null> {- return this.wiring.swarmThreadLeave?.(tabId, leadId, chat) ?? Promise.resolve(null)- }-superTabSelected(superTabId: string, projectId: string, chat?: CardSide): void {if (chat) this.wiring.superTabSelected?.(superTabId, projectId, chat)else this.wiring.superTabSelected?.(superTabId, projectId)}- superTabThread(superTabId: string, conversationId: string, threadRoot: string | null): void {- this.wiring.superTabThread?.(superTabId, conversationId, threadRoot)- }-/*** The active tab when it is a Swarm, with its open project or '' when none is (its Chat with PM, a DM, or a Swarm* not loaded yet); `fromDevice` when the announce was a device's own pick. A Swarm tab with no project used to readdiff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.tsindex 869d2581b..eb80af61d 100644--- a/cli/src/cable/cableSession.spec.ts+++ b/cli/src/cable/cableSession.spec.ts@@ -3949,7 +3949,7 @@ describe('swarm cards', () => {swarmCards: () => state.cards,listSwarms: () => state.desk ?? desk(),activeSwarmProject: () => state.open ?? null,- swarmCardsWanted: vi.fn(), swarmCardOpen: vi.fn(), superTabSelected: vi.fn(), superTabThread: vi.fn(),+ 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,})@@ -4943,32 +4943,6 @@ describe('swarm cards', () => {}})- // 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 }, { log }))- try {- port.say({ ...BUDDY, swarmThread: 'v1' })- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- // 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).toHaveBeenCalledWith(expect.stringMatching(/supertab st1 too large — \d+ thread\(s\) dropped/))- } finally { await session.stop() }- })-it('a swarmBuddy dial gets each Lead\'s buddy block and buddies flag', async () => {const cards = [card('st1', [withBuddy(), lead(2, { chat: pmChat, sideChat: { kind: 'lead', id: 'lead-c2', name: 'Lead', working: false }, buddies: true }), lead(3)])]const { session, port } = await connect(cardHost({ cards }))@@ -4983,14 +4957,14 @@ describe('swarm cards', () => {// Buddies off: exactly a swarmChat dial's Lead.{ ...base(3) },])- // The Swarm's side, which the dial follows as the daemon's: 'pm' unless the cards keep the Buddy side.- expect(ofType(port, 'supertab')[0].side).toBe('pm')+ // The Buddy face is the only one: the side field stays 'buddy' for firmware before task #3928 (task #3908).+ expect(ofType(port, 'supertab')[0].side).toBe('buddy')} finally { await session.stop() }})- it('a swarmBuddy dial hears the Swarm\'s Buddy side; a swarmChat dial never hears a side', async () => {+ it('a swarmBuddy dial hears the Buddy side only; a swarmChat dial never hears a side', async () => {for (const [hello, side] of [[BUDDY, 'buddy'], [ROUND, undefined]] as const) {- const { session, port } = await connect(cardHost({ cards: [card('st1', [withBuddy()], { side: 'buddy' })] }))+ const { session, port } = await connect(cardHost({ cards: [card('st1', [withBuddy()])] }))try {port.say(hello)await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))@@ -5021,78 +4995,11 @@ describe('swarm cards', () => {expect(buddies).toEqual(today)})- it('supertab.side reaches the cards as cardSide, and only from a swarmBuddy dial', async () => {- for (const hello of [BUDDY, ROUND, PRO]) {- const swarmCardSide = vi.fn()- const { session, port } = await connect(cardHost({ cards: [card('st1', [withBuddy()])] }, { swarmCardSide }))- try {- port.say(hello)- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' })- port.say({ t: 'supertab.side', tab: 'st1', side: 'pm' })- for (const bad of [{ tab: 'bad id', side: 'pm' }, { tab: 'x'.repeat(48), side: 'pm' }, { tab: 'st1', side: 'up' }, { tab: 'st1' }, { side: 'pm' }]) port.say({ t: 'supertab.side', ...bad })- await settle(); await settle()- expect(swarmCardSide.mock.calls).toEqual(hello === BUDDY ? [['st1', 'buddy'], ['st1', 'pm']] : [])- } finally { await session.stop() }- }- })-// ── the desktop follows the dial into Buddy chats (Diego, 10-30) ─────────────────────────────────────────────const onDesk = (projectId = 'proj1') => ({ superTabId: 'st1', projectId, fromDevice: false })const mine = { ...buddy, local: 'h-buddy' }const twoProjects = () => [withBuddy({ local: 'h-lead1', buddy: mine }), lead(2, { chat: pmChat, sideChat: pmChat, buddies: true, local: 'h-lead2' })]- it('a swipe to the Buddy side opens that project\'s Buddy chat on the desktop, and back to the PM its Lead chat', async () => {- const state = { cards: [card('st1', twoProjects())], open: onDesk() as ReturnType<typeof onDesk> | null }- const swarmCardSide = vi.fn()- const host = cardHost(state, { swarmCardSide })- const { session, port } = await connect(host)- try {- port.say(BUDDY)- await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toEqual([{ t: 'supertab.focus', tab: 'st1', lead: 'lead1' }]), NEXT_TICKS)- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' }); await settle()- expect(vi.mocked(host.superTabSelected!).mock.calls).toEqual([['st1', 'proj1', 'buddy']])- port.say({ t: 'supertab.side', tab: 'st1', side: 'pm' }); await settle()- expect(vi.mocked(host.superTabSelected!).mock.calls).toEqual([['st1', 'proj1', 'buddy'], ['st1', 'proj1', 'pm']])- // The cards still hear each side: the dial's faces follow from them as before.- expect(swarmCardSide.mock.calls).toEqual([['st1', 'buddy'], ['st1', 'pm']])- // A side the dial kept across a restart, with no finger on it: the cards hear it, and the window stays.- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy', kept: true }); await settle()- expect(swarmCardSide).toHaveBeenLastCalledWith('st1', 'buddy')- expect(vi.mocked(host.superTabSelected!).mock.calls).toHaveLength(2)- // The window's announce of the move it made for the dial is not sent back as a focus.- state.open = { ...onDesk(), fromDevice: true }- await session.syncSwarmCards(true)- expect(ofType(port, 'supertab.focus')).toHaveLength(1)- } finally { await session.stop() }- })-- // Review of #2500: with the window on # buddy (the Swarm's one Buddy chat, no project) the PM side had no project to open.- it('a swipe back to the PM side from the Swarm\'s Buddy chat, which names no project, opens the Lead chat of the project the dial has open, else the first', async () => {- const state = { cards: [card('st1', [withBuddy({ buddy: mine }), lead(2, { buddies: true, buddy: mine, chat: pmChat, sideChat: pmChat })])], open: { superTabId: 'st1', projectId: '', conversationId: 'pm1', fromDevice: false } }- const host = cardHost(state)- const { session, port } = await connect(host)- try {- port.say(BUDDY)- await vi.waitFor(() => expect(ofType(port, 'supertab.focus')).toHaveLength(1), NEXT_TICKS)- // Already on the Buddy side: nothing to open.- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' }); await settle()- expect(host.superTabSelected).not.toHaveBeenCalled()- port.say({ t: 'supertab.side', tab: 'st1', side: 'pm' }); await settle()- expect(vi.mocked(host.superTabSelected!).mock.calls).toEqual([['st1', 'proj1', 'pm']])- } finally { await session.stop() }- // The dial has the second project open: that one.- const second = cardHost({ cards: state.cards, open: { superTabId: 'st1', projectId: '', conversationId: 'pm1', fromDevice: false } })- const again = await connect(second)- try {- again.port.say(BUDDY)- await vi.waitFor(() => expect(ofType(again.port, 'supertab.focus')).toHaveLength(1), NEXT_TICKS)- again.port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead2' }); await settle()- again.port.say({ t: 'supertab.side', tab: 'st1', side: 'pm' }); await settle()- expect(vi.mocked(second.superTabSelected!).mock.calls).toEqual([['st1', 'proj2', 'pm']])- } finally { await again.session.stop() }- })-// Second review of #2500: a DM or Chat with PM names no project either, but is not the Buddy chat: the swipe opens nothing.it('a swipe to the PM side from a chat with no project that is not the reader\'s Buddy chat (a DM, Chat with PM) opens nothing', async () => {for (const conversationId of ['dm1', undefined]) {@@ -5121,43 +5028,8 @@ describe('swarm cards', () => {} finally { await session.stop() }})- it('a swipe asks the desktop nothing new from an older dial, for a Swarm the dial is not in, or to a Buddy the reader has not got', async () => {- // An older round dial and the Pro: the side frame is not theirs, and nothing reaches the window.- for (const hello of [ROUND, PRO]) {- const host = cardHost({ cards: [card('st1', twoProjects())], open: onDesk() })- const { session, port } = await connect(host)- try {- port.say(hello)- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' }); await settle()- expect(host.superTabSelected).not.toHaveBeenCalled()- } finally { await session.stop() }- }- // A Swarm with no project known on the dial face: no project is guessed.- const unknown = cardHost({ cards: [card('st1', twoProjects()), card('st2', [lead(5, { buddies: true, buddy: mine })])], open: onDesk() })- const first = await connect(unknown)- try {- first.port.say(BUDDY)- await vi.waitFor(() => expect(ofType(first.port, 'supertab.focus')).toHaveLength(1), NEXT_TICKS)- first.port.say({ t: 'supertab.side', tab: 'st2', side: 'buddy' })- first.port.say({ t: 'supertab.side', tab: 'st9', side: 'pm' }); await settle()- expect(unknown.superTabSelected).not.toHaveBeenCalled()- } finally { await first.session.stop() }- // The project on the face has no Buddy of the reader's (another person's never reaches the cards): no Buddy chat is- // opened, or made, for it; the PM side still opens the Lead chat.- const none = cardHost({ cards: [card('st1', twoProjects())], open: onDesk('proj2') })- const second = await connect(none)- try {- second.port.say(BUDDY)- await vi.waitFor(() => expect(ofType(second.port, 'supertab.focus')).toHaveLength(1), NEXT_TICKS)- second.port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' })- second.port.say({ t: 'supertab.side', tab: 'st1', side: 'pm' }); await settle()- expect(vi.mocked(none.superTabSelected!).mock.calls).toEqual([['st1', 'proj2', 'pm']])- } finally { await second.session.stop() }- })-it('a project picked on the Buddy side opens that project\'s Buddy chat', async () => {- const state = { cards: [card('st1', [withBuddy({ buddy: mine }), lead(2, { buddies: true, buddy: { ...mine, chatId: 'b2' } }), lead(3, { buddies: true })], { side: 'buddy' })], open: onDesk() }+ const state = { cards: [card('st1', [withBuddy({ buddy: mine }), lead(2, { buddies: true, buddy: { ...mine, chatId: 'b2' } }), lead(3, { buddies: true })])], open: onDesk() }const host = cardHost(state)const { session, port } = await connect(host)try {@@ -5200,7 +5072,7 @@ describe('swarm cards', () => {// The dial is now on project 1; a pick of project 2 moves it, and the Buddy opens there.port.say({ t: 'supertab.select', tab: 'st1', lead: 'lead2' }); await settle()port.say({ t: 'agent.open', agentId: 'h-buddy' }); await settle()- expect(vi.mocked(host.superTabSelected!).mock.calls).toEqual([['st1', 'proj1', 'buddy'], ['st1', 'proj2'], ['st1', 'proj2', 'buddy']])+ expect(vi.mocked(host.superTabSelected!).mock.calls).toEqual([['st1', 'proj1', 'buddy'], ['st1', 'proj2', 'buddy'], ['st1', 'proj2', 'buddy']])expect(host.openAgent).not.toHaveBeenCalled()} finally { await session.stop() }// The same Buddy session on the cards of two Swarms is still no one Swarm's.@@ -5369,7 +5241,7 @@ describe('swarm cards', () => {})// Review of #2500: with one Swarm Buddy, its one word badges every card; seeing the Buddy side clears them all.- it('showing the Buddy side reads the Swarm Buddy\'s notice on every card that shares it, and no other chat\'s', async () => {+ it('opening a Lead\'s Buddy face reads the Swarm Buddy\'s notice on every card that shares it, and no other chat\'s', async () => {const own = { ...buddyNotice('o1'), chatId: 'own-chat' }const state = { cards: [card('st1', [withBuddy(), lead(2, { chat: pmChat, sideChat: buddyChat, buddies: true }), lead(3, { chat: pmChat, sideChat: buddyChat, buddies: true })])] }const { session, port } = await connect(cardHost(state))@@ -5381,12 +5253,12 @@ describe('swarm cards', () => {lead(3, { chat: pmChat, sideChat: buddyChat, buddies: true, buddyNotice: own })])]await session.syncSwarmCards()await vi.waitFor(() => expect(ofType(port, 'supertab.notice')).toHaveLength(3))- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' })+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' })await vi.waitFor(() => expect(ofType(port, 'supertab.notice.read')).toHaveLength(2))expect(ofType(port, 'supertab.notice.read')).toEqual([{ t: 'supertab.notice.read', tab: 'st1', lead: 'lead1', chatId: 'pm1' }, { t: 'supertab.notice.read', tab: 'st1', lead: 'lead2', chatId: 'pm1' }])- // Swiping again reads nothing twice; the Lead whose own chat spoke is still unread.- port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy' }); await settle(); await settle()+ // Opening again reads nothing twice; the Lead whose own chat spoke is still unread.+ port.say({ t: 'supertab.open', tab: 'st1', lead: 'lead1' }); await settle(); await settle()expect(ofType(port, 'supertab.notice.read')).toHaveLength(2)} finally { await session.stop() }})@@ -5421,8 +5293,9 @@ describe('swarm cards', () => {describe('swarmThread', () => {const THREAD = { ...BUDDY, swarmThread: 'v1' }const ROUND_THREAD = { ...ROUND, swarmThread: 'v1' }- const inThread = { kind: 'lead' as const, id: 'lead-c1', name: 'Lead', working: false, thread: { root: 'm9', title: 'build it', replies: 2 } }- const threaded = () => withBuddy({ local: 'h1', sideChat: inThread, chat: { ...pmChat, thread: { root: 'm9', title: 'build it' } } })+ // A card as a daemon before task #3908 would have built it for a face in a thread: the cards carry no thread now, and a dial+ // that still announces swarmThread must see none.+ const threaded = () => withBuddy({ local: 'h1', sideChat: { kind: 'lead' as const, id: 'lead-c1', name: 'Lead', working: false }, chat: pmChat })const threadKeys = (l: Record<string, unknown>) => Object.fromEntries(Object.entries(l).filter(([k]) => k.startsWith('thread')))// A PM reply inside a task thread (Diego, 2026-10-29): opening its chat is not reading it.@@ -5435,7 +5308,7 @@ describe('swarm cards', () => {await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))state.cards = [card('st1', [lead(1, { chat: pmChat, notice: { ...pmNotice('n1'), thread: 'r1' } })])]await session.syncSwarmCards()- await vi.waitFor(() => expect(ofType(port, 'supertab.notice')).toEqual([{ ...pmFrame, thread: 'r1' }]))+ await vi.waitFor(() => expect(ofType(port, 'supertab.notice')).toEqual([pmFrame]))// Another thread of that chat open: still unread.state.open = { superTabId: 'st1', projectId: 'proj1', conversationId: 'pm1', threadRoot: 'r2', fromDevice: false }await session.syncSwarmCards()@@ -5475,7 +5348,7 @@ describe('swarm cards', () => {state.cards = [card('st1', [lead(1, { chat: pmChat, notice: tagged('msg1') })])]await session.syncSwarmCards()await vi.waitFor(() => expect(ofType(port, 'supertab.notice')).toEqual([- { t: 'supertab.notice', tab: 'st1', lead: 'lead1', chat: 'group', chatId: 'g1', id: 'msg1', text: 'Sam: @diego look', at: 1792560000, thread: 'r1' }]))+ { t: 'supertab.notice', tab: 'st1', lead: 'lead1', chat: 'group', chatId: 'g1', id: 'msg1', text: 'Sam: @diego look', at: 1792560000 }]))await session.syncSwarmCards()await new Promise((r) => setTimeout(r, 350))expect(ofType(port, 'supertab.notice')).toHaveLength(1)@@ -5487,39 +5360,12 @@ describe('swarm cards', () => {} finally { await session.stop() }})- it('a dial without swarmThread gets today\'s frame for a thread notice', async () => {- const state: Parameters<typeof cardHost>[0] = { cards: [card('st1', [lead(1, { chat: pmChat })])], open: { superTabId: 'st1', projectId: 'proj1', conversationId: 'pm1', fromDevice: false } }- const { session, port } = await connect(cardHost(state))- try {- port.say(ROUND)- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- state.cards = [card('st1', [lead(1, { chat: pmChat, notice: { ...pmNotice('n1'), thread: 'r1' } })])]- await session.syncSwarmCards()- await vi.waitFor(() => expect(ofType(port, 'supertab.notice')).toEqual([pmFrame]))- } finally { await session.stop() }- })-- it('a swarmThread dial is sent the face\'s thread and its recap\'s thread', async () => {- for (const [hello, expected] of [[THREAD, { thread: 'm9', threadTitle: 'build it', threadReplies: 2 }], [ROUND_THREAD, { thread: 'm9', threadTitle: 'build it' }]] as const) {+ // Task #3908 (Diego, 11-06, the final Board spec): people talk only to their Buddies and there is no Threads feature, so a dial+ // that still announces swarmThread (shipped firmware) is sent no thread data at all.+ it('a dial that still announces swarmThread is sent no thread, on its face or in its recap', async () => {+ for (const hello of [THREAD, ROUND_THREAD, BUDDY, ROUND]) {const host = cardHost({ cards: [card('st1', [threaded()])] }, {- swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'on it', at: 7, none: false, chatId: 'lead-c1', thread: 'm9' })) })- const { session, port } = await connect(host)- try {- port.say(hello)- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- expect(threadKeys((ofType(port, 'supertab')[0].leads as Array<Record<string, unknown>>)[0])).toEqual(expected)- port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })- await vi.waitFor(() => expect(ofType(port, 'supertab.recap')).toEqual([- { t: 'supertab.recap', tab: 'st1', lead: 'lead1', text: 'on it', at: 7, none: false, chatId: 'lead-c1', thread: 'm9' }]))- } finally { await session.stop() }- }- })-- it('an older dial is sent no thread and its leave is ignored', async () => {- for (const hello of [BUDDY, ROUND]) {- const swarmThreadLeave = vi.fn(async () => ({ tabId: 'st1', conversationId: 'lead-c1' }))- const host = cardHost({ cards: [card('st1', [threaded()])] }, { swarmThreadLeave,- swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'on it', at: 7, none: false, chatId: 'lead-c1', thread: 'm9' })) })+ swarmCardRecap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'on it', at: 7, none: false, chatId: 'lead-c1' })) })const { session, port } = await connect(host)try {port.say(hello)@@ -5528,34 +5374,24 @@ describe('swarm cards', () => {port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' })await vi.waitFor(() => expect(ofType(port, 'supertab.recap')).toHaveLength(1))expect(ofType(port, 'supertab.recap')[0]).not.toHaveProperty('thread')- port.say({ t: 'supertab.thread.leave', tab: 'st1', lead: 'lead1' }); await settle(); await settle()- expect(swarmThreadLeave).not.toHaveBeenCalled()- expect(host.superTabSelected).not.toHaveBeenCalled()- expect(host.superTabThread).not.toHaveBeenCalled()} finally { await session.stop() }}})- it('supertab.thread.leave asks the service and closes the window\'s thread', async () => {- const swarmThreadLeave = vi.fn(async (): Promise<{ tabId: string; conversationId: string } | null> => ({ tabId: 'st1', conversationId: 'lead-c1' }))- const host = cardHost({ cards: [card('st1', [threaded()])] }, { swarmThreadLeave })+ it('ignores supertab.thread.leave and supertab.side from any dial, without an error or a host call', async () => {+ const host = cardHost({ cards: [card('st1', [threaded()])] })const { session, port } = await connect(host)try {port.say(THREAD)await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- for (const bad of [{ tab: 'bad id', lead: 'lead1' }, { tab: 'st1', lead: 'x'.repeat(48) }, { tab: 'st1' }, { lead: 'lead1' }]) port.say({ t: 'supertab.thread.leave', ...bad })+ const frames = JSON.stringify(ofType(port, 'supertab'))+ port.say({ t: 'supertab.thread.leave', tab: 'st1', lead: 'lead1' })+ for (const side of ['pm', 'buddy']) port.say({ t: 'supertab.side', tab: 'st1', side })+ port.say({ t: 'supertab.side', tab: 'st1', side: 'buddy', kept: true })await settle(); await settle()- expect(swarmThreadLeave).not.toHaveBeenCalled()- port.say({ t: 'supertab.thread.leave', tab: 'st1', lead: 'lead1' }); await settle(); await settle()- // The dial's own chat flag rides along (a swarmBuddy dial: 'buddy').- expect(swarmThreadLeave.mock.calls).toEqual([['st1', 'lead1', 'buddy']])- // A leave closes the thread in the window without a project pick.- expect(vi.mocked(host.superTabThread!).mock.calls).toEqual([['st1', 'lead-c1', null]])expect(host.superTabSelected).not.toHaveBeenCalled()- // A Lead that was in no thread closes nothing.- swarmThreadLeave.mockResolvedValueOnce(null)- port.say({ t: 'supertab.thread.leave', tab: 'st1', lead: 'lead1' }); await settle(); await settle()- expect(host.superTabThread).toHaveBeenCalledTimes(1)+ expect(ofType(port, 'error')).toEqual([])+ expect(JSON.stringify(ofType(port, 'supertab'))).toBe(frames)} finally { await session.stop() }})@@ -5570,61 +5406,16 @@ describe('swarm cards', () => {voice(port, 'h1')await vi.waitFor(() => expect(swarmSay).toHaveBeenCalled())await settle(); await settle()- expect(swarmSay.mock.calls[0][5]).toEqual({ thread: null })- expect(host.superTabThread).not.toHaveBeenCalled()+ expect(swarmSay.mock.calls[0].slice(5)).toEqual([])expect(host.superTabSelected).not.toHaveBeenCalled()} finally { await session.stop() }}})- it('words to a Lead\'s terminal tile start no thread, but are held to the face\'s thread', async () => {- const swarmSay = vi.fn(async (..._args: unknown[]) => ({ said: true as const }))- const host = cardHost({ cards: [card('st1', [threaded()])] }, { transcribe: vi.fn(async () => 'build it'), route: vi.fn(), swarmSay,- appFocus: () => ({ machineId: 'm1', agentId: 'h1' }) })- const { session, port } = await connect(host)- try {- port.say(THREAD); await settle()- // The dial names a terminal that is no Lead; the window's focused pane is the Lead's.- voice(port, 't9')- await vi.waitFor(() => expect(swarmSay).toHaveBeenCalled())- expect(swarmSay.mock.calls[0][5]).toEqual({ thread: 'm9' })- voice(port, 'h1')- await vi.waitFor(() => expect(swarmSay).toHaveBeenCalledTimes(2))- expect(swarmSay.mock.calls[1][5]).toEqual({ thread: 'm9' })- } finally { await session.stop() }- })-- it('a recap.get right after the face\'s thread changes reads again', async () => {- const state = { cards: [card('st1', [withBuddy({ local: 'h1', sideChat: { kind: 'lead', id: 'lead-c1', name: 'Lead', working: false } })])] }- const swarmCardRecap = vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'A', at: 1, none: false, chatId: 'lead-c1' }))- const swarmThreadLeave = vi.fn(async () => ({ tabId: 'st1', conversationId: 'lead-c1' }))- const swarmSay = vi.fn(async () => ({ said: true as const, thread: { tabId: 'st1', conversationId: 'lead-c1', root: 'm9' } }))- const host = cardHost(state, { swarmCardRecap, swarmThreadLeave, swarmSay, transcribe: vi.fn(async () => 'build it'), route: vi.fn() })- const { session, port } = await connect(host)- const now = vi.spyOn(Date, 'now')- try {- now.mockReturnValue(5_000_000)- port.say(THREAD)- await vi.waitFor(() => expect(ofType(port, 'supertab')).toHaveLength(1))- const get = async () => { port.say({ t: 'supertab.recap.get', tab: 'st1', lead: 'lead1' }); await settle(); await settle() }- await get(); await get()- expect(swarmCardRecap).toHaveBeenCalledTimes(1)- // A cards frame that puts the face in a thread.- state.cards = [card('st1', [withBuddy({ local: 'h1', sideChat: inThread })])]- await session.syncSwarmCards(true); await get()- expect(swarmCardRecap).toHaveBeenCalledTimes(2)- await get()- expect(swarmCardRecap).toHaveBeenCalledTimes(2)- // The dial leaving it.- port.say({ t: 'supertab.thread.leave', tab: 'st1', lead: 'lead1' }); await settle(); await settle()- await get()- expect(swarmCardRecap).toHaveBeenCalledTimes(3)- } finally { now.mockRestore(); await session.stop() }- })})it('an older dial\'s voice post starts no thread and opens nothing in the window', async () => {- for (const [hello, threaded] of [[BUDDY, false], [{ ...BUDDY, swarmThread: 'v1' }, true]] as const) {+ for (const hello of [BUDDY, { ...BUDDY, swarmThread: 'v1' }]) {const swarmSay = vi.fn(async (..._args: unknown[]) => ({ said: true as const }))const host = cardHost({ cards: [card('st1', [withBuddy({ local: 'h1', sideChat: { kind: 'lead', id: 'lead-c1', name: 'Lead', working: false } })])] },{ transcribe: vi.fn(async () => 'build it'), route: vi.fn(), swarmSay })@@ -5633,7 +5424,7 @@ describe('swarm cards', () => {port.say(hello); await settle()voice(port, 'h1')await vi.waitFor(() => expect(swarmSay).toHaveBeenCalled())- expect(swarmSay.mock.calls[0].slice(5)).toEqual(threaded ? [{ thread: null }] : [])+ expect(swarmSay.mock.calls[0].slice(5)).toEqual([])} finally { await session.stop() }}})diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.tsindex 7f9535873..49ca0983d 100644--- a/cli/src/cable/cableSession.ts+++ b/cli/src/cable/cableSession.ts@@ -171,19 +171,16 @@ const PICK_ECHO_MS = 2000const CARDS_UNREAD_MS = 10_000/** The recap frame, its text shortened (on a character) until the whole JSON fits what the Pro reads. A chat's recap names* its chat (`chatId`), for a round dial that speaks swarmChat; any other is today's frame. */-export function recapFrame(r: LeadRecap, threaded = false): Message {- return fitText(r.text, (text) => ({ t: 'supertab.recap', tab: r.tabId, lead: r.leadId, text, at: r.at, none: r.none, ...(r.chatId ? { chatId: r.chatId } : {}),- ...(threaded && r.thread ? { thread: r.thread } : {}) }))+export function recapFrame(r: LeadRecap): Message {+ return fitText(r.text, (text) => ({ t: 'supertab.recap', tab: r.tabId, lead: r.leadId, text, at: r.at, none: r.none, ...(r.chatId ? { chatId: r.chatId } : {}) }))}/** A Lead's entry for a swarmChat dial: its face chat, `work` only for a working group (with that group's clock), and never* `ask` or `stuck`, which a group's state used to raise. A Lead whose chat did not come through reads as its Lead chat. */-function chatLead(l: SwarmLead, chat = l.chat, threaded = false): Record<string, unknown> {+function chatLead(l: SwarmLead, chat: SwarmChat | null | undefined = l.chat): Record<string, unknown> {const working = chat?.kind === 'group' && chat.workingreturn { id: l.id, projectId: l.projectId, project: l.project, engine: l.engine, owner: l.owner, local: l.local,state: working ? 'work' : 'done', order: l.order, ...(working && chat.since !== undefined ? { since: chat.since } : {}),- ...(chat ? { chat: chat.kind, chatId: chat.id, chatName: chat.name } : {}),- // A swarmThread dial: the thread the face is in (spec 2026-11-03-dial-thread-face).- ...(threaded && chat?.thread ? { thread: chat.thread.root, threadTitle: chat.thread.title, ...(chat.thread.replies !== undefined ? { threadReplies: chat.thread.replies } : {}) } : {}) }+ ...(chat ? { chat: chat.kind, chatId: chat.id, chatName: chat.name } : {}) }}/** A Lead's entry for a swarmBuddy dial (spec 2026-10-29-round-dial-pm-buddy): the face on the side it keeps, and while the* Swarm has Buddies on, `buddies` and the reader's Buddy. With Buddies off it is a swarmChat dial's entry. */@@ -191,8 +188,8 @@ function chatLead(l: SwarmLead, chat = l.chat, threaded = false): Record<string,function dialBuddy({ local: _local, ...drawn }: SwarmBuddy): Record<string, unknown> {return { ...drawn }}-function buddyLead(l: SwarmLead, threaded = false): Record<string, unknown> {- return { ...chatLead(l, l.sideChat ?? l.chat, threaded), ...(l.buddies ? { buddies: true } : {}), ...(l.buddies && l.buddy ? { buddy: dialBuddy(l.buddy) } : {}) }+function buddyLead(l: SwarmLead): Record<string, unknown> {+ return { ...chatLead(l, l.sideChat ?? null), ...(l.buddies ? { buddies: true } : {}), ...(l.buddies && l.buddy ? { buddy: dialBuddy(l.buddy) } : {}) }}/** A Swarm agent's id as the backend makes it; a harness's id is a UUID, so the two never meet. */const SWARM_AGENT_ID = /^[0-9a-f]{24}$/@@ -207,38 +204,29 @@ const NAME_CUTS = [24, 12, 6, 3, 1, 0]* 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 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.+ * frame fits only if it is also within that many JSON tokens. Shorter names do not lower that count, so the Buddy blocks go+ * (task #2525: 12 Leads came to 513 tokens, and the dial dropped every frame).+ * Returns how many Buddy blocks went, for the caller's log.*/-function fitFrame(frame: { name: string; leads: Array<Record<string, unknown>> }, tokens?: number, open?: string): { threads: number; buddies: number } {+function fitFrame(frame: { name: string; leads: Array<Record<string, unknown>> }, tokens?: number): { buddies: number } {const small = () => Buffer.byteLength(JSON.stringify(frame)) < CABLE_MAX_PAYLOADconst fits = () => small() && (tokens === undefined || jsonTokens(frame) <= tokens)type Named = { [key: string]: unknown }const buddies: Array<[Named, string]> = frame.leads.map((l) => l.buddy as Named | undefined).filter((b) => b !== undefined).map((b) => [b, 'name'])- const names: Array<[Named, string]> = [[frame, 'name'], ...frame.leads.flatMap((l) => ['project', 'owner', 'chatName', 'threadTitle'].filter((key) => key in l).map((key): [Named, string] => [l, key]))]+ const names: Array<[Named, string]> = [[frame, 'name'], ...frame.leads.flatMap((l) => ['project', 'owner', 'chatName'].filter((key) => key in l).map((key): [Named, string] => [l, key]))]for (const fields of [buddies, [...buddies, ...names]]) {for (const bytes of NAME_CUTS) {if (small()) breakfor (const [holder, key] of fields) holder[key] = truncateUtf8(String(holder[key]), bytes)}}- 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++- }- }+ let blocks = 0for (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 }+ return { buddies: blocks }}/** A Lead's new message as the round dial's alert, sized as the recap is. */-/** `threaded`: a swarmThread dial, which is told the thread a reply is in, and reads it only on that thread's face. */-function noticeFrame(tab: string, lead: string, n: LeadNotice, threaded = false): Message {- return fitText(n.text, (text) => ({ t: 'supertab.notice', tab, lead, chat: n.chat, chatId: n.chatId, id: n.id, text, at: n.at,- ...(threaded && n.thread ? { thread: n.thread } : {}) }))+function noticeFrame(tab: string, lead: string, n: LeadNotice): Message {+ return fitText(n.text, (text) => ({ t: 'supertab.notice', tab, lead, chat: n.chat, chatId: n.chatId, id: n.id, text, at: n.at }))}/** `make(text)`, with the text shortened (on a character) until the whole JSON fits what a dial reads: escapes can grow* 1,500 bytes of text past it. */@@ -393,7 +381,7 @@ 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 { CardChat, CardSide, LeadNotice, LeadRecap, SaidOnCard, SayOptions, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../superTabs/cards.js'+import type { CardChat, CardSide, LeadNotice, LeadRecap, SaidOnCard, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../superTabs/cards.js'import { truncateUtf8 } from '../lib/deviceRecentTrim.js'export interface RouteDecision {@@ -435,20 +423,13 @@ export interface CableHost {/** 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, chat?: CardChat): void/** A round dial that speaks swarmBuddy swiped to a side of a Swarm: the cards show that side's face. */- swarmCardSide?(tabId: string, side: CardSide): void- /** A swarmThread dial left the thread on its face: the cards forget it. The conversation whose thread the window should close, or- * null when the Lead's face was in none. */- swarmThreadLeave?(tabId: string, leadId: string, chat?: CardChat): Promise<{ tabId: string; conversationId: string } | null>/** Words for a Lead that runs here: posted as the person in its Swarm chat. Not `said`: not a Lead, send the turn as before;* `refused`: the backend refused the post, whose words are never typed anywhere instead. `chatId`: the chat they were* spoken to, the only one they may be posted in. */- swarmSay?(harnessId: string, text: string, chat?: CardChat, chatId?: string, reviewed?: boolean, options?: SayOptions): Promise<SaidOnCard>+ swarmSay?(harnessId: string, text: string, chat?: CardChat, chatId?: string, reviewed?: boolean): Promise<SaidOnCard>/** A device picked a Lead: the window opens that Swarm tab and project. `chat` (a round dial that speaks swarmBuddy): the* reader's Buddy chat there ('buddy') or the project's Lead chat ('pm'), so the desktop follows the dial's side. */superTabSelected?(superTabId: string, projectId: string, chat?: CardSide): void- /** The dial's thread opened (a root) or closed (null) beside a conversation of a Swarm tab: the window shows it without a project- * pick, raising or refocusing nothing. */- superTabThread?(superTabId: string, conversationId: string, threadRoot: string | null): void/** The Swarm tab the window has on screen and the project open in it ('' when none is); null when the active tab is not a Swarm or there is no window. */activeSwarmProject?(): { superTabId: string; projectId: string; conversationId?: string; threadRoot?: string; fromDevice: boolean } | nullappName(): string@@ -772,16 +753,13 @@ export class CableSession {* open in its project, its recap is that chat's, `work` only for a working group, and the alerts are the Lead's new* messages (`supertab.notice`). Any other device gets today's frames byte for byte. */private swarmChat = false- /** `swarmBuddy: 'v1'` beside swarmChat (spec 2026-10-29-round-dial-pm-buddy): the dial keeps a PM and a Buddy side per Swarm- * (`supertab.side`), each Lead carries `buddies` and the reader's Buddy, and the Buddy's word is a quiet notice. A+ /** `swarmBuddy: 'v1'` beside swarmChat (spec 2026-10-29-round-dial-pm-buddy): the dial shows the reader's Buddy only (task #3908; its+ * side swipes are ignored), each Lead carries `buddies` and the reader's Buddy, and the Buddy's word is a quiet notice. A* swarmChat dial without it gets today's frames byte for byte. */private swarmBuddy = false/** `swarmNeedsYou: 'v1'` beside swarmChat (spec 2026-11-05-dial-lead-pm-buddy-pair): the bell and inbox hold only what needs the* reader, so the Buddy's quiet notices are never sent to it. */private swarmNeedsYou = false- /** `swarmThread: 'v1'` beside swarmChat (spec 2026-11-03-dial-thread-face): the dial draws the thread its face is in- * (`thread`, `threadTitle`, `threadReplies` on a Lead, `thread` on a recap) and leaves it with `supertab.thread.leave`. */- private swarmThread = false/** `swarmReview: 'v1'` beside swarmChat (docs/device-voice-swarm-chat.md): the dial reviews every word for a Swarm chat* before it is posted, so one that comes unreviewed is refused before it is transcribed. */private swarmReview = false@@ -798,14 +776,14 @@ 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', this.swarmCard && 'swarmCard', this.swarmChat && 'swarmChat', this.swarmBuddy && 'swarmBuddy', this.swarmNeedsYou && 'swarmNeedsYou', this.swarmThread && 'swarmThread', this.swarmReview && 'swarmReview']+ const named = [this.swarmMembers && 'swarms', this.longRecap && 'recap', this.stepsActivity && 'activity', this.statsTurn && 'stats', this.playerCapable && 'player', this.superTabWaits && 'superTab', this.swarmCard && 'swarmCard', this.swarmChat && 'swarmChat', this.swarmBuddy && 'swarmBuddy', this.swarmNeedsYou && 'swarmNeedsYou', this.swarmReview && 'swarmReview'].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 = this.swarmChat = this.swarmBuddy = this.swarmNeedsYou = this.swarmThread = this.swarmReview = false+ this.swarmCard = this.swarmChat = this.swarmBuddy = this.swarmNeedsYou = this.swarmReview = falsethis.dropCards()this.seqOn = falsethis.seq = 0@@ -1374,7 +1352,6 @@ export class CableSession {this.swarmCard = str('swarmCard') === 'v1'this.swarmChat = this.swarmCard && str('swarmChat') === 'v1'this.swarmBuddy = this.swarmChat && str('swarmBuddy') === 'v1'- this.swarmThread = this.swarmChat && str('swarmThread') === 'v1'this.swarmNeedsYou = this.swarmChat && str('swarmNeedsYou') === 'v1'this.swarmReview = this.swarmChat && str('swarmReview') === 'v1'this.wantCards(this.swarmCard)@@ -1492,22 +1469,6 @@ export class CableSession {case 'supertab.select':await this.onSuperTab(msg.t, str('tab') ?? '', str('lead') ?? '')return- case 'supertab.side': {- // Only a dial that keeps sides, for a Swarm id it can hold; anything else is a frame this daemon cannot use.- const tab = str('tab') ?? '', side = str('side')- if (this.swarmBuddy && CARD_ID.test(tab) && (side === 'pm' || side === 'buddy')) {- this.host.swarmCardSide?.(tab, side)- // `kept`: the side a restart took off the dial's face, with no finger on it. The window stays where the person left it.- if (msg.kept !== true) this.followSide(tab, side)- if (side === 'buddy') this.queued(() => this.readSharedBuddyNotices(tab)).catch((err) => this.log(`cable: Buddy notices not cleared (${(err as Error).message})`))- }- return- }- case 'supertab.thread.leave': {- const tab = str('tab') ?? '', lead = str('lead') ?? ''- if (this.swarmThread && CARD_ID.test(tab) && CARD_ID.test(lead)) await this.threadLeave(tab, 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@@ -2443,7 +2404,7 @@ export class CableSession {context: 'Swarm chat',submit: async words => {const [chat] = this.sayArgs(face)- const said = await say(recipient, turn.cmd ? `/${turn.cmd} ${words}` : words, chat, face.id, true, ...(this.swarmThread ? [this.sayOptions(face)!] as const : []))+ const said = await say(recipient, turn.cmd ? `/${turn.cmd} ${words}` : words, chat, face.id, true).catch((): SaidOnCard => ({ said: false }))if (said.said) return { ok: true }return { ok: false, error: said.refused?.message ?? (face.kind === 'buddy' ? 'Could not reach your Buddy. Try again.' : 'Could not reach the Swarm. Try again.') }@@ -2844,8 +2805,6 @@ export class CableSession {/** 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 = nullprivate lastRecapGet: { key: string; at: number; read: Promise<LeadRecap | null> } | null = null- /** The root of the thread each Lead's face was last told to be in (`${tab}/${lead}`), so a change drops a recap read held for the other. */- private readonly leadThreads = new Map<string, string | undefined>()/** `${lead} ${why}` of each recap that came back with nothing and was logged (recapMissed). */private readonly recapsMissed = new Set<string>()/** A swarmChat dial's alerts (`${tab}:${lead}`): the notice it was last given or shown as already there, and whether it@@ -2888,24 +2847,15 @@ export class CableSession {}/** The extra arguments of words spoken to a Swarm Lead: the dial's chat flag, and the chat they were spoken to. */- private sayArgs(face: SwarmFace | undefined): [chat?: CardChat, chatId?: string, reviewed?: boolean, options?: SayOptions] {+ private sayArgs(face: SwarmFace | undefined): [chat?: CardChat, chatId?: string, reviewed?: boolean] {// A chat flag with no id means "the chat open on the desktop" to the Swarm service: a Pro sends neither unless its words// were for the face chat it showed (voiceFaceOf), and then names that chat.if (this.seqOn && !face) return []const [chat] = this.chatFlag()if (chat === undefined) return []- const options = this.sayOptions(face)- if (options) return [chat, face?.id, false, options]return face ? [chat, face.id] : [chat]}- /** A swarmThread dial's words are held to the thread on the face as the person began to speak (none included). They never- * start a thread: the face stays where it was when the person spoke (Diego, 2026-11-05: it jumped into the new thread). */- private sayOptions(face: SwarmFace | undefined): SayOptions | undefined {- if (!this.swarmThread) return undefined- return face ? { thread: face.thread?.root ?? null } : {}- }-/** The extra argument a swarmChat dial's requests carry ('buddy' for a swarmBuddy dial's); none for any other device, whose* calls stay as they were. */private chatFlag(): [] | [CardChat] { return this.swarmBuddy ? ['buddy'] : this.swarmChat ? [true] : [] }@@ -2929,7 +2879,6 @@ export class CableSession {this.focusLogged = ''this.picked = nullthis.lastRecapGet = null- this.leadThreads.clear()this.notices.clear()this.noticesReplay = trueif (this.openLead) this.host.swarmCardOpen?.(this.cardSession, this.openLead.tabId, null, ...this.chatFlag())@@ -2992,23 +2941,18 @@ export class CableSession {// 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 ?? ''// A swarmBuddy dial follows the Swarm's side as the daemon's (review of #2218); no other device hears one.- // A face that went into or out of a thread: a recap read held for the other is not handed out again.- for (const l of card.leads.slice(0, SWARM_LEADS_MAX)) {- const key = `${card.id}/${l.id}`, root = (this.swarmBuddy ? l.sideChat ?? l.chat : l.chat)?.thread?.root- if (this.leadThreads.has(key) && this.leadThreads.get(key) !== root && this.lastRecapGet?.key === key) this.lastRecapGet = null- this.leadThreads.set(key, root)- }- const frame = { t: 'supertab', id: card.id, tab, name: card.name, count: card.count, ...(card.personal ? { personal: true } : {}), ...(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,+ const frame = { t: 'supertab', id: card.id, tab, name: card.name, count: card.count, ...(card.personal ? { personal: true } : {}), ...(this.swarmBuddy ? { side: 'buddy' } : {}), // the Buddy face is the only one: firmware before task #3928 still reads this field++ leads: card.leads.slice(0, SWARM_LEADS_MAX).map((l) => this.swarmBuddy ? buddyLead(l) : this.swarmChat ? chatLead(l, l.chat) : { 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 }) }) }// 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 dropped = fitFrame(frame, this.seqOn ? SWARM_TOKENS_MAX : GUARD_TOKENS_MAX)const key = JSON.stringify(frame)if (this.cardKeys.get(card.id) === key) continuethis.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), 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)+ const cuts = [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)}@@ -3071,7 +3015,7 @@ export class CableSession {// Replayed or read on the desktop: noted as not open on the dial, so nothing is sent for it now or later.const sent = !replay && !openedthis.notices.set(key, { id: notice.id, chatId: notice.chatId, open: sent })- if (sent) await this.send(noticeFrame(tab, lead, notice, this.swarmThread))+ if (sent) await this.send(noticeFrame(tab, lead, notice))return}if (held.open && opened) {@@ -3126,7 +3070,7 @@ export class CableSession {if (!this.swarmCard || this.openLead?.tabId !== recap.tabId || this.openLead.leadId !== recap.leadId) return// The service pushes a Lead's recap and each dial's face chat's apart: each device takes only the kind it asked for.if (this.swarmChat !== (recap.chatId !== undefined) || this.swarmBuddy !== (recap.buddy === true)) return- return this.queued(async () => { await this.send(recapFrame(recap, this.swarmThread)) })+ 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. */@@ -3142,14 +3086,16 @@ export class CableSession {if (type === 'supertab.open') {this.openLead = { tabId: tab, leadId: lead }this.host.swarmCardOpen?.(this.cardSession, tab, lead, ...this.chatFlag())+ // The Buddy face is on the dial: seeing it once reads the shared Buddy's word on every card.+ if (this.swarmBuddy) this.queued(() => this.readSharedBuddyNotices(tab)).catch((err) => this.log(`cable: Buddy notices not cleared (${(err as Error).message})`))return}if (type === 'supertab.select') {const projectId = this.host.swarmCards?.()?.find((c) => c.id === tab)?.leads.find((l) => l.id === lead)?.projectIdif (!projectId) { this.log(`cable: ignored pick of unknown Lead ${lead}`); return }- // A swarmBuddy dial on the Buddy side: the next project's Buddy chat, where the reader has one there.+ // A swarmBuddy dial shows only Buddies: the next project's Buddy chat, where the reader has one there.const card = this.host.swarmCards?.()?.find((c) => c.id === tab)- const onBuddy = this.swarmBuddy && card?.side === 'buddy' && this.buddyIn(card, projectId)+ const onBuddy = this.swarmBuddy && !!card && this.buddyIn(card, projectId)this.openSwarmChat(tab, projectId, onBuddy ? 'buddy' : undefined)return}@@ -3167,7 +3113,7 @@ export class CableSession {}const recap = await this.lastRecapGet.read// 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, this.swarmThread)) })+ if (recap) await this.queued(async () => { await this.send(recapFrame(recap)) })}/** A recap the dial asked for that came back with nothing leaves its face on the resting pet: said once per Lead and why,@@ -3188,45 +3134,12 @@ export class CableSession {else this.host.superTabSelected?.(tab, projectId)}- /** The dial left the thread on its face: the cards forget it, and the window closes its thread pane (the project stays). */- private async threadLeave(tab: string, lead: string): Promise<void> {- const left = await this.host.swarmThreadLeave?.(tab, lead, this.chatFlag()[0]).catch((err: Error) => { this.log(`cable: thread leave failed (${err.message})`); return null })- this.lastRecapGet = null- if (left) this.host.superTabThread?.(left.tabId, left.conversationId, null)- }-/** The reader's Buddy in a project of a card, when Buddies are on and they have one there. */private buddyIn(card: SwarmCard, projectId: string): boolean {const lead = card.leads.find((l) => l.projectId === projectId)return lead?.buddies === true && lead.buddy !== undefined}- /**- * A swarmBuddy dial swiped a Swarm to a side: the desktop opens the Buddy chat (or the Lead chat) of the project on the- * dial's face, which is the one it last picked or was pointed at in that Swarm. With none known there, no project is- * guessed; a Buddy side where the reader has no Buddy opens nothing, so no Buddy chat is made from a swipe.- */- private followSide(tab: string, side: CardSide): void {- const [focusedTab, focusedProject] = this.focusedKey.split('/')- if (focusedTab !== tab) return- const card = this.host.swarmCards?.()?.find((c) => c.id === tab)- // The window is on the Swarm's one Buddy chat, which names no project (# buddy): the Buddy side is already open, and the- // PM side opens the Lead chat of the project the dial has open, else its first, so the dial is not stranded on # buddy- // (review of #2500). The Buddy side there asks for nothing. Only that chat: a DM or Chat with PM names no project either,- // and a swipe from one of them opens nothing, as before (second review of #2500).- let projectId = focusedProject- const window = this.host.activeSwarmProject?.()- const onBuddy = window?.superTabId === tab && window.conversationId !== undefined- && card?.leads.some((l) => l.buddies === true && l.buddy?.chatId === window.conversationId) === true- if (!projectId && side === 'pm' && card && onBuddy) {- const shown = this.openLead?.tabId === tab ? card.leads.find((l) => l.id === this.openLead?.leadId) : undefined- projectId = (shown ?? card.leads[0])?.projectId- }- if (!projectId || !card?.leads.some((l) => l.projectId === projectId)) return- if (side === 'buddy' && !this.buddyIn(card, projectId)) return- this.openSwarmChat(tab, projectId, side)- }-/*** The Swarm session a round dial's tap names: the reader's Buddy ('buddy') or a Lead ('pm') whose session runs on this* computer, by the session id the cards hold for it. Any round dial, older ones too (PM ruling, 10-30): the tap is adiff --git a/cli/src/core/api.ts b/cli/src/core/api.tsindex e7ec9ca47..a6209033e 100644--- a/cli/src/core/api.ts+++ b/cli/src/core/api.ts@@ -359,7 +359,7 @@ export interface CoreApi {/** 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`, `cardSay`, `cardSide`, `cardWorker`; superTabs/inCore/cards.ts refuses any other action): its answer, or SERVICE_UNAVAILABLE. Absent from a core or a+ * `cardOpen`, `cardSay`, `cardWorker`; superTabs/inCore/cards.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. */@@ -1260,16 +1260,12 @@ export interface SwarmLead {buddyNotice?: LeadNotice}/** One Swarm this account is in, as a Harness Pro's card: its Leads, most urgent first. */-/** `side` 'buddy' while a swarmBuddy dial keeps the Swarm on its Buddy side (spec 2026-10-29-round-dial-pm-buddy): the dial- * follows it as the daemon's, which a face alone cannot tell where no project has a Buddy chat (review of #2218). */-export interface SwarmCard { id: string; name: string; count: number; leads: SwarmLead[]; side?: 'buddy'+export interface SwarmCard { id: string; name: string; count: number; leads: SwarmLead[]/** The reader's own Personal Swarm (the list row's `personal: true`); never set on a Team Swarm. */personal?: true }/** A Lead's last message, for its card; `chatId` when it is the last message of the chat on the round dial's face, and* `buddy` when that face is a swarmBuddy dial's (`CardChat` 'buddy'), so each dial takes only the recaps it asked for. */-export interface LeadRecap { tabId: string; leadId: string; text: string; at: number; none: boolean; chatId?: string; buddy?: true- /** The root of the thread this recap is of, when the face was in one: a dial never takes it for the main chat's. */- thread?: string }+export interface LeadRecap { tabId: string; leadId: string; text: string; at: number; none: boolean; chatId?: string; buddy?: true }/** A project's places to chat (designs 2026-10-28-round-dial-swarm-chat and 2026-10-29-round-dial-pm-buddy): its Lead* conversation, the reader's Buddy chat, and a group. A dial without swarmBuddy calls the Buddy chat `pm`, where the PM's* private lines land since Buddies replaced Chat with PM; a swarmBuddy dial calls it `buddy` and hears the Buddy there. */@@ -1277,10 +1273,7 @@ export type ChatKind = 'lead' | 'pm' | 'group' | 'buddy'/** The chat on a project's face on the round dial: the Lead's, unless the window has the project's Buddy chat or a group* open (or a swarmBuddy dial's side says the Buddy's). `working` only for a working group, `since` from one of its agents'* turn here. */-export interface SwarmChat { kind: ChatKind; id: string; name: string; working: boolean; since?: number- /** While the face is in a thread (the app's, or the one the dial's words started): its root, its title (first line, 80 bytes)- * and, when the read gives it, its reply count. Sent only to a dial that speaks swarmThread. */- thread?: { root: string; title: string; replies?: number } }+export interface SwarmChat { kind: ChatKind; id: string; name: string; working: boolean; since?: number }/** The newest tag of the reader's in the project since the baseline, the dial's alert: in its Lead conversation (`lead`), the* reader's Buddy chat or a Chat with PM (`pm`), or a task chat (`group`, #2965); or the newest message the reader's Buddy* wrote in its chat (`buddy`, the quiet one). `thread`: the root of the thread it is in, when it is in that thread only; such@@ -1296,22 +1289,16 @@ export interface SwarmBuddy { chatId: string; name: string; engine: string; cell/** Its session id when it runs on this computer: how a tap on its notification is told from any other agent's. Never sent* to a device. */local?: string }-/** The screen a round dial shows of each project of a Swarm: the PM's (today's face) or the reader's Buddy's. */+/** The chat the window opens when a device picks a project or taps a session: the project's Lead conversation or the reader's Buddy's. */export type CardSide = 'pm' | 'buddy'/** Which chat a card request is about: the Lead's conversation (false, the Pro), today's face (true, a swarmChat dial), or* the face on a swarmBuddy dial's side ('buddy'). */export type CardChat = boolean | 'buddy'/** What became of words spoken on a device for a Lead: posted, not a Lead here (`said` false, so the turn goes as before), or* refused by the backend with its code and message, which must never become a terminal turn instead. */-/** `thread`: set when the post started the dial's thread (spec 2026-11-03-dial-thread-face), so the window opens it. */-export type SaidOnCard = { said: true; thread?: { tabId: string; conversationId: string; root: string } } | { said: false; refused?: { code: string; message: string } }-/** How words for a Lead relate to the dial's thread (a swarmThread dial only): `thread` is the root of the thread on its face when- * they were spoken, null for none, and the post is held to it; `threaded`: they were spoken from the face, so they may start one. */-export interface SayOptions { thread?: string | null; threaded?: boolean }+export type SaidOnCard = { said: true } | { said: false; refused?: { code: string; message: string } }/** The conversation the window has open in a Swarm tab. */-/** `fromDevice`: the window moved there because a device picked it (a dial's swipe to the next project), so the move is- * that device's own and keeps the side it keeps (spec 2026-10-29-round-dial-pm-buddy, newest wins). */-export interface CardFocus { tabId: string; conversationId: string; fromDevice?: true }+export interface CardFocus { tabId: string; conversationId: string }/** The Super Tab service's door into the core (superTabs/inCore/attention.ts): the waits of its members here. */export interface SuperTabsCore {diff --git a/cli/src/core/devicesLink.spec.ts b/cli/src/core/devicesLink.spec.tsindex 87e772922..5b283fe61 100644--- a/cli/src/core/devicesLink.spec.ts+++ b/cli/src/core/devicesLink.spec.ts@@ -253,7 +253,7 @@ describe('the devices\' Swarm card requests to the Super Tab service', () => {expect((await devices.answer('super_tabs', { action: 'cardsWanted', on: true, include: [] })).echoed).toEqual({ action: 'cardsWanted', on: true, include: [] })})- it('passes a swarmBuddy dial\'s buddy flag and its side (cardSide), as it passes the other card requests', async () => {+ it('passes a swarmBuddy dial\'s buddy flag, as it passes the other card requests', async () => {const superTabRequest = vi.fn(async (payload: Record<string, unknown>) => ({ ok: true, echoed: payload }))const core = fakeCore()core.superTabRequest = superTabRequest@@ -264,10 +264,10 @@ describe('the devices\' Swarm card requests to the Super Tab service', () => {expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', chatId: 'pm1', reviewed: true })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chatId: 'pm1', reviewed: true })expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', chatId: 'pm1', reviewed: 'yes' })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chatId: 'pm1' })expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', chatId: 7 })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it' })- // A swarmThread dial's words carry the thread on the face as it began (null: none) and whether they may start one (#2756).- expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'b0', thread: 'm9', threaded: true })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'b0', thread: 'm9', threaded: true })- expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', thread: null })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it', thread: null })- expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', thread: 7, threaded: 'yes' })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it' })- expect((await devices.answer('super_tabs', { action: 'cardSide', tabId: 't1', side: 'buddy', leadId: 'l1', text: 'x' })).echoed).toEqual({ action: 'cardSide', tabId: 't1', side: 'buddy' })+ // An older dial's words may still name a thread (swarmThread, #2756): it is not passed on (task #3908).+ expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'b0', thread: 'm9', threaded: true })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'b0' })+ expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', thread: null })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it' })+ // An older dial's side is no request any more (task #3908): it reaches the service as an unknown action.+ expect((await devices.answer('super_tabs', { action: 'cardSide', tabId: 't1', side: 'buddy', leadId: 'l1', text: 'x' })).echoed).toEqual({ action: 'cardSide', tabId: 't1', leadId: 'l1' })})})diff --git a/cli/src/core/devicesLink.ts b/cli/src/core/devicesLink.tsindex 10f6f37da..5d342fc5c 100644--- a/cli/src/core/devicesLink.ts+++ b/cli/src/core/devicesLink.ts@@ -125,18 +125,14 @@ export function createDevicesLink(deps: DevicesLinkDeps) {// The Swarm cards' requests (core/main.ts `superTabRequest` allows those and no other action of the Super Tab service).super_tabs: async (payload) => {if (!core.superTabRequest) return { error: 'SERVICE_UNAVAILABLE' }- const { action, tabId, leadId, on, include, session, harnessId, machineId, text, focus, side } = payload+ const { action, tabId, leadId, on, include, session, harnessId, machineId, text, focus } = payload// A round dial that speaks swarmChat asks for the chat on the face (one that speaks swarmBuddy, 'buddy'), and the// window's open conversation rides with the wish (superTabs/inCore/cards.ts checks them); absent, the request is today's.const chat = payload.chat === true || payload.chat === 'buddy' ? { chat: payload.chat } : {}return core.superTabRequest(action === 'cardsWanted' ? { action, on: on === true, include, ...(focus !== undefined ? { focus } : {}) }: action === 'cardSay' ? { action, harnessId, text, ...chat, ...(typeof payload.chatId === 'string' ? { chatId: payload.chatId } : {}),- ...(payload.reviewed === true ? { reviewed: true } : {}),- // A swarmThread dial's pinned thread (null: none) and whether its words may start one (spec 2026-11-03-dial-thread-face).- ...(payload.thread === null || typeof payload.thread === 'string' ? { thread: payload.thread } : {}),- ...(payload.threaded === true ? { threaded: true } : {}) }+ ...(payload.reviewed === true ? { reviewed: true } : {}) }: action === 'cardWorker' ? { action, machineId, harnessId }- : action === 'cardSide' ? { action, tabId, side }: { action, tabId, leadId, session, ...chat })},// The transcriber's and the fleet's lane's sign-in, and the lane's sealing, asked of the core at everydiff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.tsindex abe21cb19..0a5cf8d85 100644--- a/cli/src/services/devices.spec.ts+++ b/cli/src/services/devices.spec.ts@@ -652,19 +652,18 @@ describe('what the windows say, reaching the dial', () => {expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1'] })port.swarms(open('tab-st1'))expect(superTabRequest).toHaveBeenCalledTimes(3)- // The window followed a device's own pick: the focus says so, for the cards to keep the dial's side.+ // Whether the window followed a device's own pick is no part of the focus any more.port.swarms({ ...open('tab-st1', 'g2'), fromDevice: true })- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1'], focus: { tabId: 'st1', conversationId: 'g2', fromDevice: true } })+ expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1'], focus: { tabId: 'st1', conversationId: 'g2' } })port.swarms(open('tab-st1', 'g1'))superTabRequest.mockClear()reconnected.forEach((run) => run())expect(superTabRequest.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['st1'], focus: { tabId: 'st1', conversationId: 'g1' } }]])- // A thread opened beside it is news, and so is its closing.+ // A thread opened or closed beside it is no news to the cards.+ superTabRequest.mockClear()port.swarms(open('tab-st1', 'g1', 'm1'))- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1'], focus: { tabId: 'st1', conversationId: 'g1', threadRoot: 'm1' } })port.swarms(open('tab-st1', 'g1'))- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['st1'], focus: { tabId: 'st1', conversationId: 'g1' } })- superTabRequest.mockClear()+ expect(superTabRequest).not.toHaveBeenCalled()// Nobody wants cards: a focus change says nothing.seen.host.swarmCardsWanted!(false)superTabRequest.mockClear()@@ -704,7 +703,7 @@ describe('what the windows say, reaching the dial', () => {await expect(seen.host.swarmCardRecap!('st1', 'lead1', true)).rejects.toThrow('SERVICE_UNAVAILABLE')})- it('asks for a swarmBuddy dial\'s face with the buddy flag, says so on its recap, and sends its side as cardSide', async () => {+ it('asks for a swarmBuddy dial\'s face with the buddy flag, and says so on its recap', async () => {const answers: Array<Record<string, unknown>> = [{ ok: true, text: 'from the Buddy', at: 3, none: false, chatId: 'b1', buddy: true },{ ok: true, text: 'no chat named', at: 3, none: false, buddy: true },@@ -722,39 +721,21 @@ describe('what the windows say, reaching the dial', () => {expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1', reviewed: true })seen.host.swarmCardOpen!('c1', 'st1', 'lead1', 'buddy')expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardOpen', session: 'c1', tabId: 'st1', leadId: 'lead1', chat: 'buddy' })- seen.host.swarmCardSide!('st1', 'buddy')- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardSide', tabId: 'st1', side: 'buddy' })})- it('carries a thread on the recap, on a post that started one, and leaves a thread through the service', async () => {+ // Task #3908: a recap, a post and a pick carry no thread; the service's answers about one are not read.+ it('carries no thread on a recap or a post, whatever the service answers', async () => {const answers: Array<Record<string, unknown>> = [{ ok: true, text: 'on it', at: 3, none: false, chatId: 'lead-c1', thread: 'm9' },- { ok: true, text: 'on it', at: 3, none: false, chatId: 'lead-c1', thread: 'bad id' },{ ok: true, said: true, thread: { tabId: 'st1', conversationId: 'lead-c1', root: 'm9' } },- { ok: true, said: true, thread: { tabId: 'st1', conversationId: 7, root: 'm9' } },- { ok: true, conversationId: 'lead-c1' }, { ok: true }, { error: 'OWNER_REQUIRED' },+ { ok: true, said: true },]const superTabRequest = vi.fn(async (_payload: Record<string, unknown>) => answers.shift()!)const { core } = withRequest(superTabRequest)- expect(await seen.host.swarmCardRecap!('st1', 'lead1', true)).toEqual({ tabId: 'st1', leadId: 'lead1', text: 'on it', at: 3, none: false, chatId: 'lead-c1', thread: 'm9' })- expect(await seen.host.swarmCardRecap!('st1', 'lead1', true)).not.toHaveProperty('thread')- expect(await seen.host.swarmSay!('h1', 'build it', true)).toEqual({ said: true, thread: { tabId: 'st1', conversationId: 'lead-c1', root: 'm9' } })+ expect(await seen.host.swarmCardRecap!('st1', 'lead1', true)).toEqual({ tabId: 'st1', leadId: 'lead1', text: 'on it', at: 3, none: false, chatId: 'lead-c1' })expect(await seen.host.swarmSay!('h1', 'build it', true)).toEqual({ said: true })- answers.unshift({ ok: true, said: true })- await seen.host.swarmSay!('h1', 'build it', true, undefined, false, { threaded: true, thread: null })- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'build it', chat: true, threaded: true, thread: null })- answers.unshift({ ok: true, said: true })- await seen.host.swarmSay!('h1', 'build it', true, 'lead-c1', true, { thread: 'm9' })- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'build it', chat: true, chatId: 'lead-c1', reviewed: true, thread: 'm9' })- expect(await seen.host.swarmThreadLeave!('st1', 'lead1', 'buddy')).toEqual({ tabId: 'st1', conversationId: 'lead-c1' })- expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardThreadLeave', tabId: 'st1', leadId: 'lead1', chat: 'buddy' })- expect(await seen.host.swarmThreadLeave!('st1', 'lead1')).toBeNull()- expect(await seen.host.swarmThreadLeave!('st1', 'lead1')).toBeNull()- // The window is told to open a thread beside a conversation, or to close the open one: no project, so an older window ignores it.- seen.host.superTabThread!('st1', 'lead-c1', 'm9')- expect(vi.mocked(core.clients.sendLocal)).toHaveBeenLastCalledWith({ type: 'dial_super_tab', payload: { superTabId: 'st1', conversationId: 'lead-c1', threadRoot: 'm9', threadOnly: true } })- seen.host.superTabThread!('st1', 'lead-c1', null)- expect(vi.mocked(core.clients.sendLocal)).toHaveBeenLastCalledWith({ type: 'dial_super_tab', payload: { superTabId: 'st1', conversationId: 'lead-c1', threadRoot: null, threadOnly: true } })+ await seen.host.swarmSay!('h1', 'build it', true, 'lead-c1', true)+ expect(superTabRequest).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'build it', chat: true, chatId: 'lead-c1', reviewed: true })// An ordinary pick is untouched.seen.host.superTabSelected!('st1', 'proj1', 'buddy')expect(vi.mocked(core.clients.sendLocal)).toHaveBeenLastCalledWith({ type: 'dial_super_tab', payload: { superTabId: 'st1', projectId: 'proj1', chat: 'buddy' } })diff --git a/cli/src/services/devices.ts b/cli/src/services/devices.tsindex faaad09aa..b457be92d 100644--- a/cli/src/services/devices.ts+++ b/cli/src/services/devices.ts@@ -174,11 +174,7 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)/** What became of words for a Lead, as the service answered: a refusal keeps its code and its message, cut to what a dial* shows in a voice error. */const saidOf = (answer: Record<string, unknown>): SaidOnCard => {- if (answer.said === true) {- const t = answer.thread && typeof answer.thread === 'object' ? answer.thread as Record<string, unknown> : {}- const ids = [t.tabId, t.conversationId, t.root]- return ids.every((v): v is string => typeof v === 'string' && CHAT_ID.test(v)) ? { said: true, thread: { tabId: ids[0], conversationId: ids[1], root: ids[2] } } : { said: true }- }+ if (answer.said === true) return { said: true }const refused = answer.refused && typeof answer.refused === 'object' ? answer.refused as Record<string, unknown> : {}if (typeof refused.code !== 'string' || typeof refused.message !== 'string') return { said: false }return { said: false, refused: { code: refused.code, message: truncateUtf8(refused.message, VOICE_ERROR_BYTES) } }@@ -194,7 +190,7 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)let cardInclude: string[] = []// The conversation the window has open in its active Swarm tab, which the round dial's face follows (design// 2026-10-28-round-dial-swarm-chat): said with the wish, and left out when there is none, as before.- let cardFocus: { tabId: string; conversationId: string; threadRoot?: string; fromDevice?: true } | null = null+ let cardFocus: { tabId: string; conversationId: string } | null = nullconst tellCards = (): void => {const on = cardDevices > 0void askCards({ action: 'cardsWanted', on, include: on ? cardInclude : [], ...(on && cardFocus ? { focus: cardFocus } : {}) })@@ -263,27 +259,16 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)if (r.ok !== true || typeof r.text !== 'string' || typeof r.at !== 'number' || !Number.isInteger(r.at) || r.at < 0 || typeof r.none !== 'boolean') return nullif (chat && !(typeof r.chatId === 'string' && CHAT_ID.test(r.chatId))) return nullreturn { tabId, leadId, text: truncateUtf8(r.text, 1500), at: r.at, none: r.none, ...(chat ? { chatId: r.chatId as string } : {}),- ...(chat === 'buddy' ? { buddy: true as const } : {}), ...(chat && typeof r.thread === 'string' && CHAT_ID.test(r.thread) ? { thread: r.thread } : {}) }+ ...(chat === 'buddy' ? { buddy: true as const } : {}) }},swarmCardOpen: (session, tabId, leadId, chat) => { void askCards({ action: 'cardOpen', session, tabId, leadId, ...chatFlag(chat) }) },- swarmCardSide: (tabId, side) => { void askCards({ action: 'cardSide', tabId, side }) },- // The conversation whose thread the window should close, or null when the Lead's face was in none (or the service is away).- swarmThreadLeave: async (tabId, leadId, chat) => {- const r = await askCards({ action: 'cardThreadLeave', tabId, leadId, ...chatFlag(chat) })- return r.ok === true && typeof r.conversationId === 'string' && CHAT_ID.test(r.conversationId) ? { tabId, conversationId: r.conversationId } : null- },// An error (no service, a refused post) is not `said`: the words go to the harness instead, never lost.- swarmSay: async (harnessId, text, chat, chatId, reviewed, options) => saidOf(await askCards({ action: 'cardSay', harnessId, text, ...chatFlag(chat),- ...(chatId ? { chatId, ...(reviewed ? { reviewed: true } : {}) } : {}), ...(options?.threaded ? { threaded: true } : {}),- ...(options?.thread !== undefined ? { thread: options.thread } : {}) })),+ swarmSay: async (harnessId, text, chat, chatId, reviewed) => saidOf(await askCards({ action: 'cardSay', harnessId, text, ...chatFlag(chat),+ ...(chatId ? { chatId, ...(reviewed ? { reviewed: true } : {}) } : {}) })),// The Pro picked a Lead: the window opens that Swarm tab and project. Harmless with no window. `chat`, from a round dial// that keeps sides: the Buddy chat or the Lead chat there; a window from before it opens the project's Lead chat.superTabSelected: (superTabId, projectId, chat) =>core.clients.sendLocal({ type: 'dial_super_tab', payload: { superTabId, projectId, ...(chat ? { chat } : {}) } }),- // The dial's thread opened (a root) or closed (null) beside a conversation, with no project pick: no `projectId`, so an older- // window ignores it, and the new one neither raises nor refocuses (spec 2026-11-03-dial-thread-face).- superTabThread: (superTabId, conversationId, threadRoot) =>- core.clients.sendLocal({ type: 'dial_super_tab', payload: { superTabId, conversationId, threadRoot, threadOnly: true } }),scrolled: (phase, dy, velocity, superTabId) => core.clients.sendLocal({ type: 'dial_scroll', payload: { phase, dy, velocity, ...(superTabId ? { superTabId } : {}) } }),// Gestures stay at this desk. The device inventory and its settings also reach the owner's other// machines, through the encrypted device-management event.@@ -597,12 +582,9 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)// 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)const open = cableHost.activeSwarmProject()- // `fromDevice`: the window followed a device's own pick, which the cards keep a dial's side through.- // `threadRoot`: the thread open beside it, whose opening or closing moves the dial's face too.const focus = open?.conversationId- ? { tabId: open.superTabId, conversationId: open.conversationId, ...(open.threadRoot ? { threadRoot: open.threadRoot } : {}),- ...(open.fromDevice ? { fromDevice: true as const } : {}) } : null- const refocused = `${focus?.tabId}/${focus?.conversationId}/${focus?.threadRoot}` !== `${cardFocus?.tabId}/${cardFocus?.conversationId}/${cardFocus?.threadRoot}`+ ? { tabId: open.superTabId, conversationId: open.conversationId } : null+ const refocused = `${focus?.tabId}/${focus?.conversationId}` !== `${cardFocus?.tabId}/${cardFocus?.conversationId}`if (include.join(',') !== cardInclude.join(',') || refocused) { cardInclude = include; cardFocus = focus; if (cardDevices > 0) tellCards() }void cable.syncSwarms()void cable.syncAgents()diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.tsindex 2737bc00e..53dcd9154 100644--- a/cli/src/superTabs/cards.spec.ts+++ b/cli/src/superTabs/cards.spec.ts@@ -239,11 +239,6 @@ describe('lastAgentMessage in a chat or a thread', () => {expect(lastAgentMessage(rows, lead)?.text).toBe('t5')})- it('in a thread, takes only that thread\'s rows, its root among them', () => {- expect(lastAgentMessage(rows, lead, { thread: 'm1' })?.text).toBe('t4')- expect(lastAgentMessage([row(1, { thread: 'm1' }), row(5, { thread: 'm9' })], lead, { thread: 'm1' })?.text).toBe('t1')- expect(lastAgentMessage(rows, lead, { thread: 'nope' })).toBeNull()- })})/** A fake backend: tabs by id with the time each last changed, a message store per conversation, and call counting. */@@ -1169,8 +1164,8 @@ describe('SwarmCards.worker', () => {describe('leadsOf Buddies', () => {const on = (over: Record<string, unknown> = {}) => chats({ buddies: true, agents: [...chats().agents as object[], buddy()],conversations: [...swarm().conversations, pm({ agentIds: ['y1'] }), group()], ...over })- const web = (state: Record<string, unknown>, focus?: string, side?: 'pm' | 'buddy') =>- leadsOf(state, 'm1', idle, 'me', focus, side).leads.find(l => l.projectId === 'web')!+ const web = (state: Record<string, unknown>, focus?: string) =>+ leadsOf(state, 'm1', idle, 'me', focus).leads.find(l => l.projectId === 'web')!it('gives each Lead a buddy block for the reader\'s own Buddy, with Desktop\'s avatar', () => {expect(web(on()).buddy).toEqual({ chatId: 'pm-web', name: "diego's Buddy", engine: 'codex', cells: 25513, color: '#d6a79a', live: true, local: 'h-y1' })@@ -1197,30 +1192,29 @@ describe('leadsOf Buddies', () => {expect(web(off)).not.toHaveProperty('buddy')expect(web(off)).not.toHaveProperty('sideChat')// And with Buddies off a dial's side changes nothing: the face is today's.- expect(web(off, undefined, 'buddy').chat).toEqual({ kind: 'lead', id: 'lead-web', name: 'Lead', working: false })+ expect(web(off, undefined).chat).toEqual({ kind: 'lead', id: 'lead-web', name: 'Lead', working: false })})it('shows no buddy block for a Buddy chat with no Buddy agent', () => {const removed = on({ agents: chats().agents })expect(web(removed)).not.toHaveProperty('buddy')// Its screen is still the Buddy chat (the dial draws the empty state), and nothing is said there.- expect(web(removed, undefined, 'buddy').sideChat).toEqual({ kind: 'buddy', id: 'pm-web', name: 'Buddy', working: false })+ expect(web(removed, undefined).sideChat).toEqual({ kind: 'buddy', id: 'pm-web', name: 'Buddy', working: false })})it('never takes another person\'s Buddy chat or Buddy for a face or a block', () => {const sams = (over: Record<string, unknown> = {}) => on({ agents: [...chats().agents as object[], buddy({ buddyOf: { personId: 'sam', generation: 'g2' } })],conversations: [...swarm().conversations, pm({ agentIds: ['y1'], buddyOwnerId: 'sam' }), group()], ...over })const lead = { kind: 'lead', id: 'lead-web', name: 'Lead', working: false }- for (const side of [undefined, 'pm', 'buddy'] as const) {- const l = web(sams(), 'pm-web', side)- expect([l.chat, l.sideChat]).toEqual([lead, lead])- expect(l).not.toHaveProperty('buddy')- }+ // The Buddy-only face has none to show where the Buddy chat is another person's (task #3908): never the Lead's in its place.+ const l = web(sams(), 'pm-web')+ expect([l.chat, l.sideChat]).toEqual([lead, undefined])+ expect(l).not.toHaveProperty('buddy')// Sam's Buddy in the reader's own chat (an agent id reused or misfiled) is not the reader's Buddy either.const misfiled = on({ agents: [...chats().agents as object[], buddy({ buddyOf: { personId: 'sam', generation: 'g2' } })] })expect(web(misfiled)).not.toHaveProperty('buddy')// With nobody signed in, no Buddy chat is anyone's.- expect(leadsOf(on(), 'm1', idle, undefined, 'pm-web').leads.find(l => l.projectId === 'web')).toMatchObject({ chat: lead, sideChat: lead })+ expect(leadsOf(on(), 'm1', idle, undefined, 'pm-web').leads.find(l => l.projectId === 'web')).toMatchObject({ chat: lead })})// Spec 2026-10-30-buddy-thread-sessions: a thread session is a second Buddy agent in the chat, answering in its thread only.@@ -1238,25 +1232,16 @@ describe('leadsOf Buddies', () => {it('never puts a read-only Chat with PM on the face while Buddies are on', () => {const chatWithPm = conv('cpm-web', null, { projectId: 'web', agentIds: ['a1'], audience: { people: [{ id: 'me' }] } })const state = on({ conversations: [...swarm().conversations, pm({ agentIds: ['y1'] }), chatWithPm] })- expect(web(state, 'cpm-web')).toMatchObject({ chat: { kind: 'lead' }, sideChat: { kind: 'lead' } })+ expect(web(state, 'cpm-web')).toMatchObject({ chat: { kind: 'lead' }, sideChat: { kind: 'buddy' } })// With Buddies off it is today's: a conversation of the project the window has open.expect(web(on({ buddies: undefined, conversations: state.conversations }), 'cpm-web').chat).toMatchObject({ kind: 'group', id: 'cpm-web' })})- it('keeps today\'s face for a dial without swarmBuddy: the Buddy chat the window has open is `pm`, whatever the side', () => {- for (const side of [undefined, 'pm', 'buddy'] as const) {- expect(web(on(), 'pm-web', side).chat).toEqual({ kind: 'pm', id: 'pm-web', name: 'PM', working: false })- expect(web(on(), undefined, side).chat).toEqual({ kind: 'lead', id: 'lead-web', name: 'Lead', working: false })- }+ it('keeps today\'s face for a dial without swarmBuddy: the Buddy chat the window has open is `pm`', () => {+ expect(web(on(), 'pm-web').chat).toEqual({ kind: 'pm', id: 'pm-web', name: 'PM', working: false })+ expect(web(on(), undefined).chat).toEqual({ kind: 'lead', id: 'lead-web', name: 'Lead', working: false })})- it('shows a swarmBuddy dial the Buddy chat the window has open as `buddy`, unless the dial swiped back to the PM', () => {- expect(web(on(), 'pm-web').sideChat).toEqual({ kind: 'buddy', id: 'pm-web', name: "diego's Buddy", working: false })- expect(web(on(), 'pm-web', 'pm').sideChat).toEqual({ kind: 'lead', id: 'lead-web', name: 'Lead', working: false })- // A group the window has open stays the PM screen's face on the PM side, and the Buddy side shows the Buddy chat.- expect(web(on(), 'g-web').sideChat).toMatchObject({ kind: 'group', id: 'g-web' })- expect(web(on(), 'g-web', 'buddy').sideChat).toMatchObject({ kind: 'buddy', id: 'pm-web' })- })})// Diego's dial, 2026-11-03: a switch to the PM or Buddy side showed the resting pet 5-6 s before the recap, the dial's own@@ -1266,8 +1251,8 @@ describe('SwarmCards dial recap', () => {it('answers the dial\'s recap while two background reads run', async () => {let digest = digestOf([])- const state = () => ({ ...chats({ buddies: true, agents: [...chats().agents as object[], buddy()],- conversations: [...swarm().conversations, pm({ agentIds: ['y1'] }), group()] }), mentionsDigest: digest })+ const state = (sequence = 0) => ({ ...chats({ buddies: true, agents: [...chats().agents as object[], buddy()],+ conversations: [...swarm().conversations, pm({ agentIds: ['y1'], lastMessageSequence: sequence }), group()] }), mentionsDigest: digest })const pages: Record<string, unknown[]> = { 'pm-web': buddySays, 'lead-mobile': [said(1, 'a2', { text: 'mobile says' })] }const t = setup({ t1: { lastChangedAt: 1, state: state() } }, { delayMs: 50, mentions: () => [tag('tag1', 'g-web')],messages: path => ({ messages: pages[/conversations\/([^/]+)\//.exec(path)?.[1] ?? ''] ?? [], next: null }) })@@ -1277,33 +1262,16 @@ describe('SwarmCards dial recap', () => {// Someone tagged the reader: the poll reads the tags.digest = digestOf(['tag1'])t.tabs.t1.lastChangedAt++- t.tabs.t1.state = state()+ t.tabs.t1.state = state(9)const polled = t.cards.tick()await vi.waitFor(() => expect(t.calls.filter(c => c.includes('/mentions'))).toHaveLength(1), { interval: 1 })- // The dial swiped: the push of its new face reads the Buddy chat.- t.cards.side('t1', 'buddy')+ // The Buddy chat moved on: the push of its new recap reads it.await vi.waitFor(() => expect(t.calls.filter(c => c.includes('/conversations/pm-web/messages'))).toHaveLength(1), { interval: 1 })- await expect(t.cards.recap('t1', 'a2', 'buddy')).resolves.toMatchObject({ text: 'mobile says', none: false, chatId: 'lead-mobile' })+ await expect(t.cards.recap('t1', 'a2', true)).resolves.toMatchObject({ text: 'mobile says', none: false, chatId: 'lead-mobile' })await polledt.cards.want(false)})- it('answers a side switch from the held recap with no backend request', async () => {- const t = chatSwarm({ 'lead-web': [said(1, 'a1', { text: 'lead says' })], 'pm-web': buddySays }, true)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ text: 'lead says', chatId: 'lead-web' })- t.cards.side('t1', 'buddy')- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ text: 'from the Buddy', chatId: 'pm-web' })- // A poll between the swipes keeps the recap of the side not shown.- await t.cards.tick()- t.calls.length = 0- t.cards.side('t1', 'pm')- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ text: 'lead says', chatId: 'lead-web' })- expect(t.calls.filter(c => c.includes('/messages'))).toEqual([])- t.cards.want(false)- })-it('answers a held recap at once when its chat moved on, then pushes the newer one', async () => {let latest = 1const t = chatSwarm({ 'g-web': () => [said(latest, 'b1', { text: `group ${latest}` })] })@@ -1361,41 +1329,10 @@ describe('SwarmCards chat recap and threads', () => {}const onThread = { tabId: 't1', conversationId: 'lead-web', threadRoot: 'x1' }- it('shows a thread on the face by its newest agent reply, and closing it pushes the chat recap', async () => {- const t = chatSwarm(threadPages)- const pushed: string[] = []- t.cards.onRecap = r => pushed.push(r.text)- t.cards.want(true, [], onThread)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.open('s1', 't1', 'a1', true)- expect(await t.cards.recap('t1', 'a1', true)).toMatchObject({ text: 'worker reply', chatId: 'lead-web', none: false })- expect(t.calls.filter(c => c.includes('/messages'))).toEqual(['GET /api/super-tabs/t1/conversations/lead-web/messages?thread=x1'])- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })- await vi.waitFor(() => expect(pushed).toEqual(['other top']))- // Opened again, the thread's recap is its own, not the chat's.- t.cards.want(true, [], onThread)- await vi.waitFor(() => expect(pushed).toEqual(['other top', 'worker reply']))- t.cards.want(false)- })-- it('says words spoken with a thread on the face in that thread, and in the chat once it closed', async () => {- const t = chatSwarm(threadPages)- t.cards.want(true, [], onThread)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- expect(await t.cards.say('h-a1', 'in the thread', true)).toEqual({ said: true })- expect(await t.cards.say('h-a1', 'pinned to the chat', true, 'lead-web')).toEqual({ said: true })- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })- expect(await t.cards.say('h-a1', 'in the chat', true, 'lead-web')).toEqual({ said: true })- const posts = t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: { conversationId: string; text: string; replyTo: string | null } }).command)- expect(posts.map(p => [p.conversationId, p.text, p.replyTo])).toEqual([['lead-web', 'in the thread', 'x1'], ['lead-web', 'pinned to the chat', 'x1'], ['lead-web', 'in the chat', null]])- t.cards.want(false)- })-it('leaves out a thread whose conversation is not the one on the face', async () => {const t = chatSwarm({ ...threadPages, 'pm-web': [said(2, 'y1', { text: 'from the Buddy' })] }, true)t.cards.want(true, [], onThread)await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ text: 'from the Buddy', chatId: 'pm-web' })expect(await t.cards.say('h-a1', 'to the Buddy', 'buddy')).toEqual({ said: true })const [post] = t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: { conversationId: string; replyTo: string | null } }).command)@@ -1433,329 +1370,14 @@ describe('the face thread', () => {const posts = (t: { call: { mock: { calls: unknown[][] } } }) =>t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: { conversationId: string; replyTo: string | null } }).command)- it('words said at top level start the dial\'s thread', async () => {- const t = await started()- expect(t.webLead()?.chat).not.toHaveProperty('thread')- expect(await t.cards.say('h-a1', 'build it\nplease', true, undefined, false, { threaded: true })).toEqual({ said: true, thread: { tabId: 't1', conversationId: 'lead-web', root: 'm9' } })- expect(t.webLead()?.chat?.thread).toEqual({ root: 'm9', title: 'build it' })- expect(await t.cards.recap('t1', 'a1', true)).toMatchObject({ text: 'on it', chatId: 'lead-web', thread: 'm9' })- t.cards.want(false)- })-- it('cuts the dial\'s thread title to 80 bytes on a character', async () => {- const t = await started()- await t.cards.say('h-a1', 'é'.repeat(60), true, undefined, false, { threaded: true })- expect(t.webLead()?.chat?.thread?.title).toBe('é'.repeat(40))- t.cards.want(false)- })-- it('words said by a dial without swarmThread start no thread', async () => {+ it('words said on the face start no thread, and a thread the window has open is none of the face\'s (task #3908)', async () => {const t = await started()expect(await t.cards.say('h-a1', 'build it', true)).toEqual({ said: true })+ t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', threadRoot: 'm9' } as never)expect(t.webLead()?.chat).not.toHaveProperty('thread')expect(await t.cards.recap('t1', 'a1', true)).not.toHaveProperty('thread')t.cards.want(false)})-- it('swiping to the Buddy side forgets the PM\'s thread', async () => {- const t = await started(true)- await t.cards.say('h-a1', 'build it', 'buddy', undefined, false, { threaded: true })- expect(t.webLead()?.sideChat?.thread?.root).toBe('m9')- t.cards.side('t1', 'buddy')- t.cards.side('t1', 'pm')- expect(t.webLead()?.sideChat).not.toHaveProperty('thread')- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('starts no thread when the answer has no message id', async () => {- const t = chatSwarm(pages, false, 0, () => ({ status: 200, body: { success: true, data: {} } }))- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- expect(await t.cards.say('h-a1', 'hello', true, undefined, false, { threaded: true })).toEqual({ said: true })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('words said in a thread reply in it and start nothing', async () => {- const t = await started()- t.cards.want(true, [], onThread)- expect(await t.cards.say('h-a1', 'more', true, undefined, false, { threaded: true })).toEqual({ said: true })- expect(posts(t).map(p => [p.conversationId, p.replyTo])).toEqual([['lead-web', 'x1']])- t.cards.want(false)- })-- it('the app\'s thread is the face\'s, titled from its root and counted from the read', async () => {- const t = await started()- t.cards.want(true, [], onThread)- expect(t.webLead()?.chat?.thread).toMatchObject({ root: 'x1' })- expect(await t.cards.recap('t1', 'a1', true)).toMatchObject({ text: 'done', thread: 'x1' })- await vi.waitFor(() => expect(t.webLead()?.chat?.thread).toEqual({ root: 'x1', title: 'fix login', replies: 2 }))- t.cards.want(false)- })-- it('a focus move clears the dial\'s thread', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, { threaded: true })- // The move the dial's own thread caused keeps it.- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', threadRoot: 'm9', fromDevice: true })- expect(t.webLead()?.chat?.thread?.root).toBe('m9')- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- expect(await t.cards.recap('t1', 'a1', true)).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('threadLeave clears the dial\'s thread and names the conversation', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, { threaded: true })- expect(t.cards.threadLeave('t1', 'a1')).toEqual({ tabId: 't1', conversationId: 'lead-web' })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- expect(t.cards.threadLeave('t1', 'a1')).toBeNull()- // The app's thread too: the dial is off it until the app moves again.- t.cards.want(true, [], onThread)- expect(t.cards.threadLeave('t1', 'a1')).toEqual({ tabId: 't1', conversationId: 'lead-web' })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- expect(t.cards.threadLeave('t1', 'zz')).toBeNull()- t.cards.want(false)- })-- it('a thread lives only while its conversation is on the face', async () => {- const t = await started(true)- expect(await t.cards.say('h-a1', 'build it', 'buddy', undefined, false, { threaded: true })).toMatchObject({ said: true, thread: { root: 'm9' } })- expect(t.webLead()?.sideChat?.thread?.root).toBe('m9')- t.cards.side('t1', 'buddy')- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy' })- expect(t.webLead()?.sideChat).not.toHaveProperty('thread')- expect(await t.cards.recap('t1', 'a1', 'buddy')).not.toHaveProperty('thread')- t.cards.want(false)- })- const asMe = { threaded: true, thread: null as string | null }- const hidden = (t: Awaited<ReturnType<typeof started>>, over: Record<string, unknown> = {}) => t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', ...over })-- it('a hidden pane keeps the dial\'s thread: the same root announced again clears nothing, the app closing it does', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, asMe)- // The window announces the very thread it was asked to open, and keeps announcing it while the pane is hidden.- for (let i = 0; i < 3; i++) {- hidden(t, { threadRoot: 'm9' })- expect(t.webLead()?.chat?.thread).toEqual({ root: 'm9', title: 'build it' })- }- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- t.cards.want(false)- const u = await started()- await u.cards.say('h-a1', 'build it', true, undefined, false, asMe)- hidden(u, { threadRoot: 'm9' })- hidden(u)- expect(u.webLead()?.chat).not.toHaveProperty('thread')- u.cards.want(false)- })-- it('the window\'s selecting the thread\'s chat keeps the dial\'s thread until it opens it', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, asMe)- hidden(t)- expect(t.webLead()?.chat?.thread?.root).toBe('m9')- hidden(t, { threadRoot: 'm9' })- expect(t.webLead()?.chat?.thread?.root).toBe('m9')- hidden(t)- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('an unconfirmed dial thread ends 15 s later without the window naming it', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, asMe)- t.advance(14_999)- hidden(t)- expect(t.webLead()?.chat?.thread?.root).toBe('m9')- t.cards.want(true, [], null)- t.advance(1)- hidden(t)- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('another root named before confirmation ends the dial\'s thread', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, asMe)- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- hidden(t)- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('a group face\'s thread is kept like a chat\'s', async () => {- const t = await started()- t.cards.want(true, [], { tabId: 't1', conversationId: 'g-web' })- expect(await t.cards.say('h-a1', 'status?', true, undefined, false, asMe)).toEqual({ said: true, thread: { tabId: 't1', conversationId: 'g-web', root: 'm9' } })- expect(t.webLead()?.chat).toMatchObject({ kind: 'group', thread: { root: 'm9' } })- t.cards.want(false)- })-- it('words spoken on a thread face post there even if the face left it (reviewed), and are refused CHAT_MOVED when not reviewed', async () => {- const t = await started()- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- t.cards.threadLeave('t1', 'a1')- const refused = await t.cards.say('h-a1', 'more', true, 'lead-web', false, { thread: 'x1' })- expect(refused).toEqual({ said: false, refused: { code: 'CHAT_MOVED', message: 'That chat is no longer on the dial. Say it again.' } })- expect(posts(t)).toEqual([])- expect(await t.cards.say('h-a1', 'more', true, 'lead-web', true, { thread: 'x1', threaded: true })).toEqual({ said: true })- expect(posts(t).map(p => [p.conversationId, p.replyTo])).toEqual([['lead-web', 'x1']])- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)- })-- it('words spoken on the main chat never land in a thread the app opened meanwhile', async () => {- const t = await started()- hidden(t, { threadRoot: 'x1' })- expect(await t.cards.say('h-a1', 'main', true, 'lead-web', false, asMe)).toMatchObject({ said: false, refused: { code: 'CHAT_MOVED' } })- expect(posts(t)).toEqual([])- expect(await t.cards.say('h-a1', 'main', true, 'lead-web', true, asMe)).toEqual({ said: true })- expect(posts(t).map(p => p.replyTo)).toEqual([null])- // Posted at top level, but the face is in the app's thread now: no thread of the dial's.- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- t.cards.want(false)- })-- it('a post whose face or focus moved meanwhile starts no thread', async () => {- let during: (() => void) | undefined- const t = chatSwarm(pages, true, 0, () => { during?.(); return posted() })- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- during = () => { during = undefined; t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', fromDevice: true }) }- expect(await t.cards.say('h-a1', 'one', true, undefined, false, asMe)).toEqual({ said: true })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- during = () => { during = undefined; t.cards.side('t1', 'buddy') }- expect(await t.cards.say('h-a1', 'two', 'buddy', undefined, false, asMe)).toEqual({ said: true })- t.cards.side('t1', 'pm')- expect(t.webLead()?.sideChat).not.toHaveProperty('thread')- during = () => { during = undefined; t.core.account.identity = vi.fn(async () => ({ accountId: 'sam', email: '[email protected]' })) as never; t.tabs.t1.lastChangedAt++; void t.cards.tick() }- await t.cards.say('h-a1', 'three', true, undefined, false, asMe)- await vi.waitFor(() => expect(t.cards.threadLeave('t1', 'a1')).toBeNull())- t.cards.want(false)- })-- it('an old Desktop\'s re-announce after a leave does not pull the dial back, until the app names another thread', async () => {- const t = await started()- hidden(t, { threadRoot: 'x1' })- expect(t.cards.threadLeave('t1', 'a1')).toEqual({ tabId: 't1', conversationId: 'lead-web' })- hidden(t, { threadRoot: 'x1' })- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat).not.toHaveProperty('thread')- hidden(t, { threadRoot: 'x2' })- expect(t.webLead()?.chat?.thread?.root).toBe('x2')- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- // Closed in the app, then opened again: it is the app's.- t.cards.threadLeave('t1', 'a1')- hidden(t)- hidden(t, { threadRoot: 'x1' })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- t.cards.want(false)- })-- it('a leave resolves the face by the dial\'s own chat flag and strips the focus thread only of that conversation', async () => {- const t = await started(true)- t.cards.side('t1', 'buddy')- await t.cards.say('h-a1', 'hello buddy', 'buddy', undefined, false, asMe)- const buddyId = t.webLead()?.sideChat?.id- expect(t.webLead()?.sideChat?.thread?.root).toBe('m9')- // The window is in another conversation's thread, set by the dial's own pick so the dial's thread stays.- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', threadRoot: 'x1', fromDevice: true })- expect(t.cards.threadLeave('t1', 'a1', 'buddy')).toEqual({ tabId: 't1', conversationId: buddyId })- expect(t.webLead()?.chat?.thread?.root).toBe('x1')- expect(t.webLead()?.sideChat).not.toHaveProperty('thread')- expect(t.cards.threadLeave('t1', 'a1', false)).toBeNull()- t.cards.want(false)- })-- it('an app thread whose root is not on the page is titled by reading its root once, and keeps the last title', async () => {- const t = chatSwarm({ ...pages, 'lead-web#x2': Object.assign([said(5, 'a1', { text: 'reply', thread: 'x2' })], { threads: [{ id: 'x2', replies: 1 }] }),- 'lead-web@x2': [root('x2', 'old root\nmore')] }, false, 0, posted)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- hidden(t, { threadRoot: 'x2' })- await t.cards.recap('t1', 'a1', true)- await vi.waitFor(() => expect(t.webLead()?.chat?.thread).toEqual({ root: 'x2', title: 'old root', replies: 1 }))- await t.move(2)- await t.cards.recap('t1', 'a1', true)- expect(t.webLead()?.chat?.thread?.title).toBe('old root')- expect(t.calls.filter(c => c.includes('messageId=x2'))).toHaveLength(1)- t.cards.want(false)- })-- // Review of #2756 (AGENTS.md standard 6): a failed read of the root was dropped silently and never tried again, so the face kept a- // blank title. It is logged, by its code and nothing of the thread, and read again after a wait.- it('a failed read of an app thread\'s root is logged and read again after a wait', async () => {- let fails = true- const t = chatSwarm({ ...pages, 'lead-web#x2': Object.assign([said(5, 'a1', { text: 'reply', thread: 'x2' })], { threads: [{ id: 'x2', replies: 1 }] }),- 'lead-web@x2': () => { if (fails) throw Object.assign(new Error('busy'), { code: 'SERVICE_UNAVAILABLE' }); return [root('x2', 'old root')] } }, false, 0, posted)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- hidden(t, { threadRoot: 'x2' })- await t.cards.recap('t1', 'a1', true)- await vi.waitFor(() => expect(t.calls.filter(c => c.includes('messageId=x2'))).toHaveLength(1))- const lines = t.log.mock.calls.map(c => String(c[0])).filter(l => l.includes('thread'))- expect(lines).toHaveLength(1)- expect(lines[0]).not.toContain('x2')- // Within the wait it is not read again; after it, it is, and the face takes the title.- await t.move(2)- await t.cards.recap('t1', 'a1', true)- expect(t.calls.filter(c => c.includes('messageId=x2'))).toHaveLength(1)- fails = false- t.advance(60_000)- await t.move(3)- await t.cards.recap('t1', 'a1', true)- await vi.waitFor(() => expect(t.webLead()?.chat?.thread?.title).toBe('old root'))- expect(t.calls.filter(c => c.includes('messageId=x2'))).toHaveLength(2)- t.cards.want(false)- })-- it('a thread of a reader that was not signed in when the read ended is not learned', async () => {- const t = await started()- hidden(t, { threadRoot: 'x1' })- const pending = t.cards.recap('t1', 'a1', true)- vi.mocked(t.core.account.identity).mockResolvedValue({ accountId: 'sam', email: '[email protected]' } as never)- t.tabs.t1.lastChangedAt++- await t.cards.tick()- await pending- expect(t.webLead()?.chat?.thread).not.toHaveProperty('title', 'fix login')- t.cards.want(false)- })-- it('forgets the dial\'s thread when the device is gone, another person signs in, or the Swarm is lost', async () => {- const t = await started()- await t.cards.say('h-a1', 'build it', true, undefined, false, asMe)- t.cards.want(false)- const shown = t.seen.length- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen.length).toBeGreaterThan(shown))- expect(t.webLead()?.chat).not.toHaveProperty('thread')- t.cards.want(false)-- const u = await started()- await u.cards.say('h-a1', 'build it', true, undefined, false, asMe)- vi.mocked(u.core.account.identity).mockResolvedValue({ accountId: 'sam', email: '[email protected]' } as never)- u.tabs.t1.lastChangedAt++- await u.cards.tick()- expect(u.webLead()?.chat).not.toHaveProperty('thread')- u.cards.want(false)-- const v = await started()- await v.cards.say('h-a1', 'build it', true, undefined, false, asMe)- const kept = v.tabs.t1- delete v.tabs.t1- await v.cards.tick()- v.tabs.t1 = kept- v.tabs.t1.lastChangedAt++- await v.cards.tick()- expect(v.webLead()?.chat).not.toHaveProperty('thread')- v.cards.want(false)- })})describe('SwarmCards Buddy side', () => {@@ -1766,7 +1388,6 @@ describe('SwarmCards Buddy side', () => {t.cards.want(true, [], null)await vi.waitFor(() => expect(t.seen).toHaveLength(1))t.calls.length = 0- t.cards.side('t1', 'buddy')expect(t.webLead()?.sideChat).toEqual({ kind: 'buddy', id: 'pm-web', name: "diego's Buddy", working: false })// Rebuilt from the last reads, with no request; an older dial's face did not move.expect(t.calls).toEqual([])@@ -1775,99 +1396,11 @@ describe('SwarmCards Buddy side', () => {t.cards.want(false)})- it('keeps the Lead face on the buddy side when the project has no Buddy chat', async () => {- const t = chatSwarm({}, true)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')- expect(t.seen.at(-1)?.[0].leads.find(l => l.id === 'a2')?.sideChat).toEqual({ kind: 'lead', id: 'lead-mobile', name: 'Lead', working: false })- t.cards.want(false)- })-- it('a later desktop focus clears the dial\'s side', async () => {- const t = chatSwarm({}, true)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead' })- // Review Focus 1: the desktop opens the Buddy chat (the Buddy screen), then the person swipes down: the swipe wins.- t.cards.want(true, [], { tabId: 't1', conversationId: 'pm-web' })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy' })- t.cards.side('t1', 'pm')- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead', id: 'lead-web' })- // The same focus said again is no change; the desktop's next one clears the side.- t.cards.want(true, [], { tabId: 't1', conversationId: 'pm-web' })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead' })- t.cards.want(true, [], { tabId: 't1', conversationId: 'g-web' })- t.cards.want(true, [], { tabId: 't1', conversationId: 'pm-web' })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy' })- t.cards.want(false)- })-- it('keeps the side through a desktop focus the dial itself caused, and clears it on the desktop\'s own next one', async () => {- const t = chatSwarm({}, true)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')- // The dial swiped to the next project: its select moved the desktop there, and that announce says so.- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web', fromDevice: true })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy' })- // The person then opens another conversation on the desktop: newest wins, the side goes and the face follows it.- t.cards.want(true, [], { tabId: 't1', conversationId: 'g-web' })- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'group', id: 'g-web' })- t.cards.want(false)- })-- it('says the Swarm\'s side on its card, so a dial follows the daemon\'s side even where no face changes', async () => {- // No Buddy chat in the Swarm: a side changes no face, and the card alone tells the dial (review of #2218).- const t = chatSwarm({})- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- expect(t.seen.at(-1)?.[0].side).toBeUndefined()- t.cards.side('t1', 'buddy')- expect(t.seen.at(-1)?.[0].side).toBe('buddy')- // The desktop opens a group: the side goes, and the card says so.- t.cards.want(true, [], { tabId: 't1', conversationId: 'g-web' })- expect(t.seen.at(-1)?.[0].side).toBeUndefined()- t.cards.want(false)- })-- it('says the Buddy side when the desktop opens the Buddy chat, so the side and the face agree', async () => {- // Re-check of #2216: the face followed the desktop to the Buddy chat while the card said the PM side, and the dial- // (#2218) showed the PM screen without the Buddy's recap.- const t = chatSwarm({ 'pm-web': [said(2, 'y1', { text: 'from the Buddy' })] }, true)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.want(true, [], { tabId: 't1', conversationId: 'pm-web' })- expect(t.seen.at(-1)?.[0].side).toBe('buddy')- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy', id: 'pm-web' })- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ chatId: 'pm-web', text: 'from the Buddy' })- // A swipe down wins over that focus: both say the PM side.- t.cards.side('t1', 'pm')- expect(t.seen.at(-1)?.[0].side).toBeUndefined()- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead' })- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ chatId: 'lead-web' })- // The desktop moving to a group clears both.- t.cards.want(true, [], { tabId: 't1', conversationId: 'g-web' })- expect(t.seen.at(-1)?.[0].side).toBeUndefined()- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'group' })- t.cards.want(false)- })-- it('keeps the side per Swarm, refuses a bad tab or side, and forgets every side when the devices go', async () => {+ it('has no face for a project without a Buddy chat: never the Lead\'s in its place (task #3908)', async () => {const t = chatSwarm({}, true)t.cards.want(true, [], null)await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t2', 'buddy')- t.cards.side('bad id', 'buddy')- t.cards.side('t1', 'sideways' as 'pm')- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead' })- t.cards.side('t1', 'buddy')- expect(t.webLead()?.sideChat).toMatchObject({ kind: 'buddy' })- t.cards.want(false)- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.webLead()?.sideChat).toMatchObject({ kind: 'lead' }))+ expect(t.seen.at(-1)?.[0].leads.find(l => l.id === 'a2')?.sideChat).toBeUndefined()t.cards.want(false)})@@ -1885,24 +1418,10 @@ describe('SwarmCards Buddy side', () => {t.cards.want(false)})- it('pushes the Buddy face\'s recap to the dial that has it open when the side changes, and only that one', async () => {- const t = chatSwarm({ 'lead-web': [said(1, 'a1', { text: 'lead says' })], 'pm-web': buddySays }, true)- const pushed: Array<{ text: string; buddy?: true }> = []- t.cards.onRecap = r => pushed.push({ text: r.text, ...(r.buddy ? { buddy: r.buddy } : {}) })- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.open('s1', 't1', 'a1', 'buddy')- t.cards.open('s2', 't1', 'a1', true)- t.cards.side('t1', 'buddy')- await vi.waitFor(() => expect(pushed).toEqual([{ text: 'from the Buddy', buddy: true }]))- t.cards.want(false)- })-it('say on the buddy side posts message.send to the Buddy chat', async () => {const t = chatSwarm({}, true)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', 'to my Buddy', 'buddy')).toEqual({ said: true })expect(await t.cards.say('h-a1', 'to the Lead', true)).toEqual({ said: true })const posts = t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: { conversationId: string; text: string } }).command)@@ -1914,11 +1433,9 @@ describe('SwarmCards Buddy side', () => {const t = chatSwarm({}, true)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', 'to my Buddy', 'buddy', 'pm-web')).toEqual({ said: true })- // The window opened the Lead after the words were spoken to the Buddy: they are not posted in the project's chat.- t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })- expect(await t.cards.say('h-a1', 'still for my Buddy', 'buddy', 'pm-web')).toEqual({ said: false,+ // Words for another chat than the Buddy's, which the dial no longer shows, are not posted in the project's chat.+ expect(await t.cards.say('h-a1', 'still for my Buddy', 'buddy', 'lead-web')).toEqual({ said: false,refused: { code: 'CHAT_MOVED', message: 'That chat is no longer on the dial. Say it again.' } })const posts = t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: { conversationId: string } }).command.conversationId)expect(posts).toEqual(['pm-web'])@@ -1929,7 +1446,6 @@ describe('SwarmCards Buddy side', () => {const t = chatSwarm({}, true)t.cards.want(true, [], null)await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')// The person reviewed the words for their Buddy chat; the window opened the Lead before they pressed Send.t.cards.want(true, [], { tabId: 't1', conversationId: 'lead-web' })expect(await t.cards.say('h-a1', 'reviewed for my Buddy', 'buddy', 'pm-web', true)).toEqual({ said: true })@@ -1959,7 +1475,6 @@ describe('SwarmCards access ending while a read is out', () => {it('drops a recap read in flight when access to its Swarm is lost, and keeps nothing of it', async () => {const t = chatSwarm({ 'pm-web': buddySays }, true)await t.cards.tick()- t.cards.side('t1', 'buddy')const release = held(t)const pending = t.cards.recap('t1', 'a1', 'buddy')t.failing.set('t1', 403)@@ -1967,13 +1482,11 @@ describe('SwarmCards access ending while a read is out', () => {await t.cards.tick()release()expect(await pending).toEqual({ tabId: 't1', leadId: 'a1', text: '', at: 0, none: true })- // Access back: the side is forgotten with the Swarm, and the recap is read again, never served from the dropped one.+ // Access back: the recap is read again, never served from the dropped one.t.failing.delete('t1')t.tabs.t1.lastChangedAt++await t.cards.tick()const reads = t.reads('pm-web')- expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ chatId: 'lead-web', none: true })- t.cards.side('t1', 'buddy')expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ text: 'from the Buddy', chatId: 'pm-web' })expect(t.reads('pm-web')).toBe(reads + 1)})@@ -1981,7 +1494,6 @@ describe('SwarmCards access ending while a read is out', () => {it('drops a recap read in flight when another person signs in', async () => {const t = chatSwarm({ 'pm-web': buddySays }, true)await t.cards.tick()- t.cards.side('t1', 'buddy')const release = held(t)const pending = t.cards.recap('t1', 'a1', 'buddy')vi.mocked(t.core.account.identity).mockResolvedValue({ accountId: 'sam', email: '[email protected]' } as never)@@ -2057,8 +1569,8 @@ describe('one Buddy per Swarm', () => {const sb = (over: Record<string, unknown> = {}) => conv('sb', null, { projectId: undefined, kind: 'swarm-buddy', buddyOwnerId: 'me', agentIds: ['y1'], ...over })const one = (over: Record<string, unknown> = {}) => chats({ buddies: true, agents: [...chats().agents as object[], buddy({ buddyScope: 'swarm' })],conversations: [...swarm().conversations, sb(), group()], ...over })- const lead = (state: Record<string, unknown>, project = 'web', focus?: string, side?: 'pm' | 'buddy') =>- leadsOf(state, 'm1', idle, 'me', focus, side).leads.find(l => l.projectId === project)!+ const lead = (state: Record<string, unknown>, project = 'web', focus?: string) =>+ leadsOf(state, 'm1', idle, 'me', focus).leads.find(l => l.projectId === project)!const inLead = { kind: 'lead', id: 'lead-web', name: 'Lead', working: false }// Task #3818: a reader with several Buddies sees their default on the dial, the chat the backend marks buddyDefault.@@ -2067,23 +1579,23 @@ describe('one Buddy per Swarm', () => {const state = one({ agents: [...chats().agents as object[], buddy({ buddyScope: 'swarm' }), research],conversations: [...swarm().conversations, sb(), conv('sb2', null, { projectId: undefined, kind: 'swarm-buddy', buddyOwnerId: 'me', agentIds: ['y2'], buddyDefault: true }), group()] })expect(lead(state).buddy).toMatchObject({ chatId: 'sb2', name: 'Research' })+ expect(lead(state).sideChat).toMatchObject({ id: 'sb2', kind: 'buddy' })})- it('gives every project\'s card the reader\'s one Buddy, and the Buddy side shows its chat', () => {+ it('gives every project\'s card the reader\'s one Buddy, and the Buddy face shows its chat', () => {const block = { chatId: 'sb', name: "diego's Buddy", engine: 'codex', cells: 25513, color: '#d6a79a', live: true, local: 'h-y1' }for (const project of ['web', 'mobile']) {expect(lead(one(), project).buddy).toEqual(block)- expect(lead(one(), project, undefined, 'buddy').sideChat).toEqual({ kind: 'buddy', id: 'sb', name: "diego's Buddy", working: false })+ expect(lead(one(), project).sideChat).toEqual({ kind: 'buddy', id: 'sb', name: "diego's Buddy", working: false })}- // The PM side and an older dial's face are the project's Lead, as before: the Swarm chat is no project's PM line.- expect(lead(one()).sideChat).toEqual(inLead)- expect(lead(one(), 'web', undefined, 'buddy').chat).toEqual(inLead)+ // An older dial's face is the project's Lead, as before: the Swarm chat is no project's PM line.+ expect(lead(one()).chat).toEqual(inLead)})it('prefers the Swarm chat over an older Buddy chat of the project, and falls back to it when the Swarm chat is gone', () => {const both = one({ conversations: [...swarm().conversations, pm({ agentIds: ['y1'] }), sb(), group()] })expect(lead(both).buddy).toMatchObject({ chatId: 'sb' })- expect(lead(both, 'web', undefined, 'buddy').sideChat).toMatchObject({ kind: 'buddy', id: 'sb' })+ expect(lead(both, 'web', undefined).sideChat).toMatchObject({ kind: 'buddy', id: 'sb' })// Archived: the older chat of the project is what an older Swarm keeps, and the other project has none.const archived = one({ conversations: [...swarm().conversations, pm({ agentIds: ['y1'] }), sb({ archived: true }), group()] })expect(lead(archived).buddy).toMatchObject({ chatId: 'pm-web' })@@ -2107,17 +1619,15 @@ describe('one Buddy per Swarm', () => {it('never takes another person\'s Swarm chat or Buddy, whatever a read holds or the window has open', () => {const sams = one({ agents: [...chats().agents as object[], buddy({ buddyOf: { personId: 'sam', generation: 'g2' }, buddyScope: 'swarm' })],conversations: [...swarm().conversations, sb({ buddyOwnerId: 'sam' }), group()] })- for (const side of [undefined, 'pm', 'buddy'] as const) {- const l = lead(sams, 'web', 'sb', side)- expect([l.chat, l.sideChat]).toEqual([inLead, inLead])- expect(l).not.toHaveProperty('buddy')- }+ const l = lead(sams, 'web', 'sb')+ expect([l.chat, l.sideChat]).toEqual([inLead, undefined])+ expect(l).not.toHaveProperty('buddy')// Sam's Buddy listed in the reader's own chat (an agent id reused or misfiled) is not the reader's, and the block never// carries its name or avatar.const misfiled = one({ agents: [...chats().agents as object[], buddy({ buddyOf: { personId: 'sam', generation: 'g2' }, displayName: 'Sam secret' })] })expect(lead(misfiled)).not.toHaveProperty('buddy')- expect(lead(misfiled, 'web', undefined, 'buddy').sideChat).toEqual({ kind: 'buddy', id: 'sb', name: 'Buddy', working: false })- expect(JSON.stringify(leadsOf(misfiled, 'm1', idle, 'me', undefined, 'buddy'))).not.toContain('Sam secret')+ expect(lead(misfiled, 'web', undefined).sideChat).toEqual({ kind: 'buddy', id: 'sb', name: 'Buddy', working: false })+ expect(JSON.stringify(leadsOf(misfiled, 'm1', idle, 'me', undefined))).not.toContain('Sam secret')// A thread session of the reader's Buddy is not "the Buddy", and an agent id reused in a project chat is not either.const session = agent('y1', { buddyOf: { personId: 'me', generation: 'g1' }, buddySession: { thread: 'r', from: 1 }, name: 'Thread' })expect(lead(one({ agents: [...chats().agents as object[], session] }))).not.toHaveProperty('buddy')@@ -2147,7 +1657,6 @@ describe('SwarmCards with one Buddy per Swarm', () => {const t = build()t.cards.want(true, [], null)await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')for (const lead of ['a1', 'a2']) {expect(t.lead(lead)?.sideChat).toMatchObject({ kind: 'buddy', id: 'sb' })expect(await t.cards.recap('t1', lead, 'buddy')).toEqual({ tabId: 't1', leadId: lead, text: 'from the Buddy', at: saidAt, none: false, chatId: 'sb', buddy: true })@@ -2157,19 +1666,6 @@ describe('SwarmCards with one Buddy per Swarm', () => {t.cards.want(false)})- it('shows the Buddy side when the window opens the Swarm chat, and the PM side after a swipe back', async () => {- const t = build()- t.cards.want(true, [], null)- await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.want(true, [], { tabId: 't1', conversationId: 'sb' })- expect(t.seen.at(-1)?.[0].side).toBe('buddy')- expect(t.lead('a1')?.sideChat).toMatchObject({ kind: 'buddy', id: 'sb' })- expect(t.lead('a1')?.chat).toMatchObject({ kind: 'lead' })- t.cards.side('t1', 'pm')- expect(t.lead('a1')?.sideChat).toMatchObject({ kind: 'lead' })- t.cards.want(false)- })-it('notices the Buddy\'s new word on every project\'s card from one read, and keeps the baseline when that read fails', async () => {const t = build()await t.cards.tick()@@ -2217,52 +1713,26 @@ 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)await vi.waitFor(() => expect(t.seen).toHaveLength(1))- t.cards.side('t1', 'buddy')- // The read is out when the chat is replaced by Sam's: the answer is neither given nor kept.+ // The read is out when the chat is replaced by Sam's: the answer is neither given nor kept. (The Buddy's held word would answer+ // without a read, so it is forgotten first.)+ ;(t.cards as unknown as { buddyNotices: Map<string, unknown> }).buddyNotices.clear()t.call.mockImplementationOnce(async () => {t.tabs.t1.state = state(1, { conversations: [...swarm().conversations, { ...sb(), buddyOwnerId: 'sam' }, group()] })- t.cards.side('t1', 'pm')+ t.tabs.t1.lastChangedAt+++ await t.cards.tick()return { status: 200, body: { success: true, data: { messages: hears, next: null } } }})expect(await t.cards.recap('t1', 'a1', 'buddy')).toMatchObject({ none: true, text: '' })- // Words reviewed for a chat id that is not on this project's face are refused alike for Sam's chat, a private chat and a stranger.+ // With no Buddy of the reader's in the project there is no face, and words for any chat id are none of the dial's: not posted.t.tabs.t1.lastChangedAt++t.tabs.t1.state = state(1, { conversations: [...swarm().conversations, { ...sb(), buddyOwnerId: 'sam' }, conv('priv-1', null, { projectId: 'mobile', audience: { people: [{ id: 'sam' }] } }), group()] })await t.cards.tick()for (const chatId of ['sb', 'priv-1', 'nope']) {- expect(await t.cards.say('h-a1', 'secret', 'buddy', chatId, true)).toEqual({ said: false, refused: { code: 'CHAT_MOVED', message: expect.any(String) } })+ expect(await t.cards.say('h-a1', 'secret', 'buddy', chatId, true)).toEqual({ said: false })}expect(t.call.mock.calls.filter(c => c[0] === 'POST')).toHaveLength(0)t.cards.want(false)diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.tsindex d0a71e3e3..d69658b18 100644--- a/cli/src/superTabs/cards.ts+++ b/cli/src/superTabs/cards.ts@@ -26,8 +26,8 @@ import { buddyAvatar } from './buddyAvatar.js'type Json = Record<string, unknown>/** The cards' shapes are the core's contract with the Swarm (core/api.ts), which the core declares and the Swarm imports. */-import type { CardChat, CardFocus, CardSide, ChatKind, LeadNotice, LeadRecap, LeadState, SaidOnCard, SayOptions, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../core/api.js'-export type { CardChat, CardFocus, CardSide, LeadNotice, LeadRecap, LeadState, SaidOnCard, SayOptions, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../core/api.js'+import type { CardChat, CardFocus, CardSide, ChatKind, LeadNotice, LeadRecap, LeadState, SaidOnCard, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../core/api.js'+export type { CardChat, CardFocus, CardSide, LeadNotice, LeadRecap, LeadState, SaidOnCard, SwarmBuddy, SwarmCard, SwarmChat, SwarmLead } from '../core/api.js'const MAX_CARDS = 16, MAX_LEADS = 12, NAME_BYTES = 48, RECAP_BYTES = 1500, MAX_LIST_PAGES = 10, MAX_RECAPS_IN_FLIGHT = 2/** The tag ids kept per Swarm as seen: the server lists at most 500 of a person's tags there (backend mentions.ts tagRows). */@@ -36,8 +36,6 @@ const MAX_TAGS_SEEN = 500const NO_TAGS = createHash('sha256').update('').digest('base64url').slice(0, 16)/** The longest a dial's recap read waits on the one before it. */const ASK_WAIT_MS = 10_000-/** A failed read of a dial thread's first message is tried again after this, doubling, at most ROOT_READ_TRIES times in all. */-const ROOT_READ_WAIT_MS = 10_000, ROOT_READ_TRIES = 5/** The Pro keeps an id in 48 bytes with its NUL: 47 characters at most reach it. */const ID_BYTES = 47export const cardId = (v: unknown): v is string => identifier(v) && v.length <= ID_BYTES@@ -112,15 +110,11 @@ function faceOf(conversations: Json[], projectId: string, lead: Json, focus: strif (!open || (isBuddyChat(open) && !isReadersBuddyChat(open, me)) || (buddies && isChatWithPm(open))) return leadFace(lead)return { conversation: open, kind: isBuddyChat(open) ? 'pm' : 'group' }}-/** A swarmBuddy dial's face (spec 2026-10-29 Switching): on the Buddy side the reader's Buddy chat; otherwise today's face,- * where the Buddy chat the window has open is the Buddy screen, unless the dial swiped back to the PM since (the newest- * wins: a swipe sets the side, and the window's next focus change clears it). */-function sideFaceOf(conversations: Json[], projectId: string, lead: Json, focus: string | undefined, me: string | undefined, side: CardSide | undefined): Face | null {+/** A swarmBuddy dial's face: the reader's Buddy chat in the project, and nothing else, whatever the window has open (task #3908: people+ * talk only to their Buddies). Null where the reader has none there: the dial says "No Buddy here yet". */+function buddyFaceOf(conversations: Json[], projectId: string, me: string | undefined): Face | null {const buddyChat = buddyChatOf(conversations, projectId, me)- if (side === 'buddy' && buddyChat) return { conversation: buddyChat, kind: 'buddy' }- const face = faceOf(conversations, projectId, lead, focus, me, true)- if (face?.kind !== 'pm') return face- return side === 'pm' ? leadFace(lead) : { conversation: face.conversation, kind: 'buddy' }+ return buddyChat ? { conversation: buddyChat, kind: 'buddy' } : null}/** Whose messages are the chat's recap: the Lead's in its conversation and, for an older dial, in the reader's Buddy chat* (its private lines); the reader's Buddy's on a swarmBuddy dial's Buddy face; the group's agents' in a group. */@@ -146,7 +140,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, leadId: 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): { 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`.@@ -188,14 +182,10 @@ export function leadsOf(state: Json, machineId: string, live: (harnessId: stringconst ownerId = agent.machineOwnerIdconst owner = me && typeof ownerId === 'string' && ownerId !== me ? people.find(p => p.id === ownerId) : undefinedconst projectId = projectKey(project)- const chatOf = (face: Face | null): SwarmChat | undefined => {- if (!face) return undefined- const inThread = thread?.(face.conversation.id as string, String(agent.id))- return { ...faceChat(face, String(agent.id), agents, me, turnHere), ...(inThread ? { thread: inThread } : {}) }- }+ const chatOf = (face: Face | null): SwarmChat | undefined => face ? faceChat(face, String(agent.id), agents, me, turnHere) : undefinedconst chat = chatOf(faceOf(conversations, projectId, lead, focus, me, buddies))const buddyChat = buddies ? buddyChatOf(conversations, projectId, me) : undefined- const sideChat = buddies ? chatOf(sideFaceOf(conversations, projectId, lead, focus, me, side)) : undefined+ const sideChat = buddies ? chatOf(buddyFaceOf(conversations, projectId, me)) : undefinedconst buddy = buddyChat && buddyOf(agents, buddyChat, me, a => turnHere(a) && cardId(a.harnessId) ? String(a.harnessId) : '')leads.push({id: String(agent.id), projectId: String(project.id ?? 'lead'), project: cut(String(project.name ?? ''), NAME_BYTES), engine: String(object(agent.configuration).engine ?? ''),@@ -223,12 +213,11 @@ function faceChat(face: Face, leadId: string, agents: Json[], me: string | undefreturn { kind, id: conversation.id as string, name, working, ...(secs.length ? { since: Math.max(...secs) } : {}) }}-/** Where a message is looked for: anywhere in the page, in the chat's main stream (a top-level message, one from before- * threads, or a thread reply also sent to the chat: backend catchUp.ts `inMainStream`), or in one thread, its root among it. */-export type MessagePlace = 'any' | 'chat' | { thread: string }+/** Where a message is looked for: anywhere in the page, or in the chat's main stream (a top-level message, one from before+ * threads, or a thread reply also sent to the chat: backend catchUp.ts `inMainStream`). */+export type MessagePlace = 'any' | 'chat'const isIn = (m: Json, place: MessagePlace): boolean => place === 'any' ? true- : place === 'chat' ? typeof m.thread !== 'string' || m.thread === m.id || m.alsoInChat === true- : m.thread === place.thread+ : typeof m.thread !== 'string' || m.thread === m.id || m.alsoInChat === true/** The newest row one of the chat's agents wrote: a person-visible message, not a system row (`source`), the person's or* another agent's, in `place`. `at` in seconds; `id` the message's, or '' when it has none; `thread` the root of the thread@@ -249,25 +238,19 @@ export function lastAgentMessage(messages: Json[], agentIds: ReadonlySet<string>}interface TabCache { lastChangedAt: number | null; state: Json }-/** A recap read, and the thread it is of when one was on the face. */-interface Cached { sequence: number; recap: LeadRecap; thread?: string }-/** The window's focus, with the thread whose pane is on screen beside its conversation (Desktop's app_swarms `threadRoot`). */-type Focus = CardFocus & { threadRoot?: string }+/** A recap read. */+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. With `chat` (a round dial* that speaks `swarmChat`, or 'buddy' for one that speaks swarmBuddy), the recap is that dial's face chat's, and `chatId`* the chat it was last told of. */-interface Opened { tabId: string; leadId: string; chat: CardChat; chatId: string | null; thread: string | null; sequence: number | null; sessions: Set<string> }+interface Opened { tabId: string; leadId: string; chat: CardChat; chatId: string | null; sequence: number | null; sessions: Set<string> }/** Where a recap is read, or talk is posted: a conversation, how far it has gone, and whose messages are its recap; `buddy`- * when it is a swarmBuddy dial's Buddy face, whose notice is the Buddy's; `thread` the root of the thread open on the face. */-interface Target { id: string; sequence: number; voices: Set<string>; chatId?: string; buddy?: true; thread?: string }+ * when it is a swarmBuddy dial's Buddy face, whose notice is the Buddy's. */+interface Target { id: string; sequence: number; voices: Set<string>; chatId?: string; buddy?: true }const recapKey = (tabId: string, leadId: string, chatId?: string) => chatId === undefined ? `${tabId}:${leadId}` : `${tabId}:${leadId}:${chatId}`-/** A recap's cache key: an older dial's and a swarmBuddy dial's recap of one Buddy chat hear different voices, and a thread on- * the face is apart from its chat. */-const cachedKey = (tabId: string, leadId: string, target: Pick<Target, 'chatId' | 'thread'>, chat: CardChat) =>- `${recapKey(tabId, leadId, target.chatId)}${target.thread === undefined ? '' : `#${target.thread}`}${chat === 'buddy' ? ':buddy' : ''}`-/** A thread's title on the dial: the first line, at most 80 bytes. */-const titleOf = (text: string): string => cut(text.split('\n')[0].trim(), 80)-const isSide = (v: unknown): v is CardSide => v === 'pm' || v === 'buddy'+/** A recap's cache key: an older dial's and a swarmBuddy dial's recap of one Buddy chat hear different voices. */+const cachedKey = (tabId: string, leadId: string, target: Pick<Target, 'chatId'>, chat: CardChat) =>+ `${recapKey(tabId, leadId, target.chatId)}${chat === 'buddy' ? ':buddy' : ''}`/** Spec 2026-11-02-poll-cost Part 4.3: the list was read every 5 s whatever changed (prod 2026-11-02: about 200 list reads a* minute). While the server says it pushes this account's Swarm changes (`swarm_changed` naming none, repeated every 4* minutes: backend lib/swarmClientPushes.ts), the list is read when a Swarm's main parts change, and after this long as the@@ -304,7 +287,7 @@ export class SwarmCards {private me: string | undefinedprivate include: string[] = []/** The conversation the window has open in a Swarm tab: that project's face follows it. */- private focus: Focus | null = null+ private focus: CardFocus | null = nullprivate opened = new Map<string, Opened>()private openBy = new Map<string, string>()/** Background reads of recaps and notices in flight, at most MAX_RECAPS_IN_FLIGHT. */@@ -326,17 +309,6 @@ export class SwarmCards {private personal = new Set<string>()/** Each Lead's newest quiet notice from the reader's Buddy (`${tab}:${lead}`): apart, so it never hides the Lead's. */private buddyNotices = new Map<string, 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), 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. */- private left = new Map<string, { conversationId: string; root: string }>()- /** Bumped at each refocus of the window, so a post that was out while it moved knows it did (spec 2026-11-03-dial-thread-face). */- private focusGen = 0/** Watched conversations whose last read failed, so a run of failures is logged once. */private failed = new Set<string>()private readonly reads: SwarmReads@@ -357,14 +329,14 @@ export class SwarmCards {/** Poll while a capable Pro is attached; none otherwise (no request at all). `include`: the Swarms the desktop has tabs for,* read first. `focus`: the conversation the window has open in a Swarm tab; a change rebuilds the cards at once from the* last reads, with no request. */- want(on: boolean, include: string[] = [], focus: Focus | null = null): void {+ want(on: boolean, include: string[] = [], focus: CardFocus | null = null): void {if (!on) {if (this.timer) clearInterval(this.timer)this.timer = undefinedthis.stopNotices?.()this.stopNotices = nullthis.pushUntil = 0- this.opened.clear(); this.openBy.clear(); this.include = []; this.focus = null; this.sides.clear(); this.threads.clear(); this.titles.clear(); this.left.clear()+ this.opened.clear(); this.openBy.clear(); this.include = []; this.focus = null// A device that attaches again starts a fresh baseline: what was said while none was here never alerts.this.seen.clear(); this.forgetNotices()return@@ -372,35 +344,10 @@ export class SwarmCards {const wanted = include.filter(cardId).slice(0, MAX_CARDS)const moved = wanted.join(',') !== this.include.join(',')this.include = wanted- let next: Focus | null = focus && cardId(focus.tabId) && cardId(focus.conversationId)- ? { tabId: focus.tabId, conversationId: focus.conversationId, ...(cardId(focus.threadRoot) ? { threadRoot: focus.threadRoot } : {}),- ...(focus.fromDevice === true ? { fromDevice: true as const } : {}) } : null- // A thread the dial left stays left until the window names another conversation or another root (an older Desktop announces- // it again): its root is not the focus's.- for (const [tabId, gone] of [...this.left]) {- if (!(next?.tabId === tabId && next.conversationId === gone.conversationId && next.threadRoot === gone.root)) this.left.delete(tabId)- else { const { threadRoot: _, ...rest } = next; next = rest }- }- // A thread opened or closed beside the conversation moves the face too.- const refocused = `${next?.tabId}/${next?.conversationId}/${next?.threadRoot}` !== `${this.focus?.tabId}/${this.focus?.conversationId}/${this.focus?.threadRoot}`- const before = this.focus+ const next: CardFocus | null = focus && cardId(focus.tabId) && cardId(focus.conversationId)+ ? { tabId: focus.tabId, conversationId: focus.conversationId } : null+ const refocused = `${next?.tabId}/${next?.conversationId}` !== `${this.focus?.tabId}/${this.focus?.conversationId}`this.focus = next- // The desktop's own move clears the dial's side; the move a dial's pick caused is the dial's, and keeps it.- // The dial's thread outlives the window's announce of that very thread (same conversation, same root), which a hidden pane keeps- // making; another conversation, another root, or no root (the app closed it) ends it.- if (refocused) this.focusGen++- // The window opens the dial's thread only after selecting its chat (up to 10 s): a no-root announce of that chat is not the- // person closing it until the window has named the root once, or 15 s have passed.- const mine = next && this.threads.get(next.tabId)- if (mine && next!.conversationId === mine.conversationId && next!.threadRoot === mine.root) mine.opened = true- if (refocused && !next?.fromDevice) {- const own = mine- const confirmed = !!next && !!own && own.conversationId === next.conversationId &&- (own.root === next.threadRoot || (next.threadRoot === undefined && !own.opened && this.now() - own.at < 15_000))- // Only the root appearing beside the same conversation is no move of the person's: the dial's side stays.- if (!(confirmed && before?.tabId === next!.tabId && before.conversationId === next!.conversationId)) this.sides.clear()- for (const tabId of [...this.threads.keys()]) if (!(confirmed && tabId === next!.tabId)) this.threads.delete(tabId)- }// Other Swarms to show first: the list is read for them now, whatever the server pushes.if (moved) this.listTold = trueif (this.timer) {@@ -414,68 +361,6 @@ export class SwarmCards {void this.tick()}- /**- * The side a swarmBuddy dial is shown for a Swarm, which its faces, recaps and card all follow: the one it swiped to, else- * the Buddy side while the window has the reader's Buddy chat open there (spec 2026-10-29: opening it on the desktop- * shows the Buddy screen). Taken from the swipes alone, the card said the PM side over a Buddy face (re-check of #2216).- */- private sideOf(tabId: string, state: Json): CardSide | undefined {- const swiped = this.sides.get(tabId)- if (swiped) return swiped- const focus = this.focus?.tabId === tabId ? this.focus.conversationId : undefined- return focus !== undefined && state.buddies === true &&- list(state.conversations).some(c => c.id === focus && isReadersBuddyChat(c, this.me) && c.archived !== true) ? 'buddy' : undefined- }-- /** A swarmBuddy dial swiped to a side of a Swarm (spec 2026-10-29): every project of it shows that side until the window- * opens another conversation. The cards are rebuilt at once from the last reads, as a focus change does. */- side(tabId: string, side: CardSide): void {- if (!cardId(tabId) || !isSide(side) || this.sides.get(tabId) === side) return- this.sides.set(tabId, side)- // Up to the Buddy side leaves the PM's thread for good (spec 2026-11-03-dial-thread-face).- this.threads.delete(tabId)- if (this.timer && this.live) { this.emit(); void this.pushOpen() }- }-- /** 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)- 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- }-- /** 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 } : {}) }- }-- /** The dial leaves the thread on its face (`chat`: the dial's own chat flag): the dial's own is forgotten and the app's is no- * longer the face's (the window is asked to close it), and an older Desktop's announce of it is ignored from now on. The- * conversation whose thread that was, or null when the Lead's face was in none. */- threadLeave(tabId: string, leadId: string, chat: CardChat = true): { tabId: string; conversationId: string } | null {- const face = chat ? this.target(tabId, leadId, chat) : null- if (!face || face.thread === undefined) return null- if (this.threads.get(tabId)?.conversationId === face.id) this.threads.delete(tabId)- if (this.focus?.tabId === tabId && this.focus.conversationId === face.id && this.focus.threadRoot !== undefined) { const { threadRoot: _, ...rest } = this.focus; this.focus = rest }- this.left.set(tabId, { conversationId: face.id, root: face.thread })- if (this.timer && this.live) { this.emit(); void this.pushOpen() }- return { tabId, conversationId: face.id }- }-/** The recap on a Pro's screen (leadId null: closed), per Pro `session`: a change in that Lead's conversation is pushed once.* With `chat`, the face chat's: a change in it, or another chat on the face, is pushed once. */open(session: string, tabId: string, leadId: string | null, chat: CardChat = false): void {@@ -492,7 +377,7 @@ export class SwarmCards {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.const target = this.target(tabId, leadId, chat)- entry = { tabId, leadId, chat, chatId: target?.chatId ?? null, thread: target?.thread ?? null,+ entry = { tabId, leadId, chat, chatId: target?.chatId ?? null,sequence: target ? this.recaps.get(cachedKey(tabId, leadId, target, chat))?.sequence ?? target.sequence : null, sessions: new Set() }this.opened.set(key, entry)}@@ -577,16 +462,12 @@ export class SwarmCards {const first = unread && this.last === nullthis.unreadSince = first ? this.unreadSince ?? this.now() : nullthis.holding = this.unreadSince !== null && this.now() - this.unreadSince < UNREAD_HOLD_MS- // A Swarm that left the cards (access lost) takes the dial's side with it.- for (const tabId of [...this.sides.keys()]) if (!known.has(tabId)) this.sides.delete(tabId)- for (const tabId of [...this.threads.keys()]) if (!known.has(tabId)) this.threads.delete(tabId)- for (const tabId of [...this.left.keys()]) if (!known.has(tabId)) this.left.delete(tabId)this.rows = rows.map(row => ({ id: row.id as string, name: row.name }))this.personal = new Set(rows.filter(row => row.personal === true).map(row => row.id as string))}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.seen.clear(); this.forgetNotices(); this.sides.clear(); this.threads.clear(); this.titles.clear(); this.left.clear() }+ if (this.me !== undefined && me !== this.me) { this.last = null; this.recaps.clear(); this.seen.clear(); this.forgetNotices() }this.me = me ?? this.meconst turns = await this.turnsHere()this.live = (harnessId: string) => this.core.agents.byAgent(harnessId) ? turns.get(harnessId) ?? { inTurn: false } : null@@ -605,14 +486,13 @@ export class SwarmCards {const tab = this.tabs.get(row.id)if (!tab) continueconst 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, lead) => this.threadInfo(row.id, id, lead))+ const { count, leads } = leadsOf(tab.state, this.machineId, live, this.me, focus)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 } : {}) }})cards.push({ id: row.id, name: cut(String(tab.state.name ?? row.name ?? ''), NAME_BYTES), count, leads: noticed,- ...(side === 'buddy' ? { side: 'buddy' as const } : {}), ...(this.personal.has(row.id) ? { personal: true as const } : {}) })+ ...(this.personal.has(row.id) ? { personal: true as const } : {}) })}// `since` moves every poll while a turn runs and the Pro counts on by itself, so it alone never re-sends the list.// Nor does a clock that keeps its turn; one whose turn changed (the Lead's ended, a worker's goes on) does. The start is@@ -840,17 +720,12 @@ export class SwarmCards {if (!chat) return { id: found.lead.id, sequence: sequenceOf(found.lead), voices: new Set([leadId]) }const focus = this.focus?.tabId === tabId ? this.focus.conversationId : undefinedconst conversations = list(state.conversations), projectId = projectKey(found.project), buddies = state.buddies === true- const face = chat === 'buddy' && buddies ? sideFaceOf(conversations, projectId, found.lead, focus, this.me, this.sideOf(tabId, state))+ const face = chat === 'buddy' && buddies ? buddyFaceOf(conversations, projectId, this.me): faceOf(conversations, projectId, found.lead, focus, this.me, buddies)if (!face) return nullconst 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, 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,- ...(face.kind === 'buddy' ? { buddy: true as const } : {}), ...(thread === undefined ? {} : { thread }) }+ return { id, sequence: sequenceOf(face.conversation), voices: voicesOf(face, leadId, list(state.agents), this.me), chatId: id,+ ...(face.kind === 'buddy' ? { buddy: true as const } : {}) }}/** What the Lead last said: the newest page of its conversation, then one page back; `none` when neither holds a row of its own.@@ -882,8 +757,7 @@ export class SwarmCards {const found = this.target(tabId, leadId, chat)if (!found) return nullconst kept = this.recaps.get(cachedKey(tabId, leadId, found, chat))- // A notice is of the chat, never of a thread on the face.- const notice = found.thread === undefined && found.buddy ? this.buddyNotices.get(recapKey(tabId, leadId)) : undefined+ const notice = found.buddy ? this.buddyNotices.get(recapKey(tabId, leadId)) : undefinedconst heard = notice && notice.chatId === found.id && notice.thread === undefined ? notice : undefinedif (kept && (!heard || heard.at <= kept.recap.at)) return { recap: kept.recap, sequence: kept.sequence, stale: kept.sequence !== found.sequence }if (!heard) return null@@ -896,8 +770,7 @@ export class SwarmCards {// Its open sessions are told this one: their next push is for the chat's next move.const target = this.target(tabId, leadId, chat), kept = target && this.recaps.get(cachedKey(tabId, leadId, target, chat))for (const open of this.opened.values()) {- if (kept && open.tabId === tabId && open.leadId === leadId && open.chat === chat && open.chatId === (target.chatId ?? null)- && open.thread === (target.thread ?? null)) open.sequence = kept.sequence+ if (kept && open.tabId === tabId && open.leadId === leadId && open.chat === chat && open.chatId === (target.chatId ?? null)) open.sequence = kept.sequence}if (recap.text !== shown.text || recap.at !== shown.at || recap.none !== shown.none || recap.chatId !== shown.chatId) this.onRecap?.(recap)}, () => { /* read again at the next push or ask */ })@@ -923,64 +796,25 @@ export class SwarmCards {const key = cachedKey(tabId, leadId, target, chat), held = this.recaps.get(key)if (held && held.sequence === target.sequence) return held.recapconst reader = this.me- // A thread on the face is read by its root, as Desktop reads it (super_tabs/controller.dart loadThread).- const place: MessagePlace = target.thread === undefined ? 'chat' : { thread: target.thread }- const thread = target.thread === undefined ? '' : `thread=${encodeURIComponent(target.thread)}`return slot(async () => {const path = `/api/super-tabs/${tabId}/conversations/${target.id}/messages`- const newest = object(await backend(this.core, 'GET', thread ? `${path}?${thread}` : path))- let said = lastAgentMessage(list(newest.messages), target.voices, place)+ const newest = object(await backend(this.core, 'GET', path))+ let said = lastAgentMessage(list(newest.messages), target.voices, 'chat')// The page before, from the page's own (sequence, id) cursor: a page edge inside equal sequences skips nothing (design 4.6).const before = object(newest.next)if (!said && typeof before.sequence === 'number' && identifier(before.id)) {- said = lastAgentMessage(list(object(await backend(this.core, 'GET', `${path}?${thread ? `${thread}&` : ''}before=${before.sequence}&beforeId=${before.id}`)).messages), target.voices, place)+ said = lastAgentMessage(list(object(await backend(this.core, 'GET', `${path}?before=${before.sequence}&beforeId=${before.id}`)).messages), target.voices, 'chat')}// Access to the Swarm ended, another person signed in, or the face moved on while the read was out: the answer is not// this reader's to have now (a Buddy chat is its owner's alone), so it is neither given nor kept.const now = this.target(tabId, leadId, chat)- if (this.me !== reader || now?.id !== target.id || now.thread !== target.thread) return { tabId, leadId, text: '', at: 0, none: true }- if (target.thread !== undefined) await this.learnThread(tabId, target.id, target.thread, newest)+ if (this.me !== reader || now?.id !== target.id) return { tabId, leadId, text: '', at: 0, none: true }const recap: LeadRecap = said ? { tabId, leadId, text: cut(said.text, RECAP_BYTES), at: said.at, none: false, ...named } : { tabId, leadId, text: '', at: 0, none: true, ...named }- this.recaps.set(key, { sequence: target.sequence, recap, ...(target.thread === undefined ? {} : { thread: target.thread }) })+ this.recaps.set(key, { sequence: target.sequence, recap })return recap})}- /** The title (the root's first line) and reply count of a thread read for the face, said again to the dial when they changed.- * A page that lacks the root (an app thread's root is further back) has it read once by its id; the last title is kept. A- * failed read is logged and tried again after a wait that doubles, at most ROOT_READ_TRIES times (review of #2756). */- private async learnThread(tabId: string, conversationId: string, root: string, page: Json): Promise<void> {- const key = `${tabId}/${root}`, was = this.titles.get(key)- let text = list(page.messages).find(m => m.id === root)?.text- let looked = was?.looked, failures = was?.failures, retryAt = was?.retryAt- if (typeof text !== 'string' && !was?.title && !looked && (retryAt === undefined || this.now() >= retryAt)) {- try {- const one = await backend(this.core, 'GET', `/api/super-tabs/${tabId}/conversations/${conversationId}/messages?messageId=${encodeURIComponent(root)}`)- text = list(object(one).messages).find(m => m.id === root)?.text- looked = true- } catch (error) {- failures = (failures ?? 0) + 1- // Nothing of the thread in the line: its id and title are the reader's.- const code = String(object(error).code ?? (error instanceof Error ? error.name : 'error'))- if (failures >= ROOT_READ_TRIES) {- looked = true- this.log(`[super-tabs] a dial thread's first message was not read (${code}); its title stays as it is`)- } else {- const wait = Math.min(ROOT_READ_WAIT_MS * 2 ** (failures - 1), 5 * 60_000)- retryAt = this.now() + wait- this.log(`[super-tabs] a dial thread's first message was not read (${code}); read again in ${Math.round(wait / 1000)} s`)- }- }- }- const replies = list(page.threads).find(t => t.id === root)?.replies- const next = { title: (typeof text === 'string' ? titleOf(text) : '') || was?.title || '', ...(typeof replies === 'number' ? { replies } : {}),- ...(looked ? { looked: true as const } : {}), ...(failures && !looked ? { failures, retryAt } : {}) }- if (was?.title === next.title && was.replies === next.replies && was.looked === next.looked && was.failures === next.failures && was.retryAt === next.retryAt) return- this.titles.set(key, next)- if (this.titles.size > 32) this.titles.delete(this.titles.keys().next().value!)- if (was?.title !== next.title || was.replies !== next.replies) { if (this.timer && this.live) this.emit() }- }-/** Words spoken on a Pro to a Lead that runs here (its harness): posted as the person in that Lead's conversation, as typed in* the Swarm chat; with `chat`, in the chat on its face. Not `said` when that harness leads no project in the Swarms as last* read, so the caller sends the turn as before; `refused` when the backend refused the post (a 4xx: a read-only Chat with@@ -993,8 +827,7 @@ export class SwarmCards {* face when the words were spoken (null: none), pinned like `chatId`: another one now refuses the words (CHAT_MOVED), unless* `reviewed`, which posts them where they were spoken. `options.threaded`: the words came from the face, so a top-level post* may start the dial's thread, if nothing moved meanwhile (spec 2026-11-03-dial-thread-face). */- async say(harnessId: string, text: string, chat: CardChat = false, chatId?: string, reviewed = false, options: SayOptions = {}): Promise<SaidOnCard> {- const reader = this.me, gen = this.focusGen+ async say(harnessId: string, text: string, chat: CardChat = false, chatId?: string, reviewed = false): Promise<SaidOnCard> {for (const [tabId, { state }] of this.tabs) {// A Lead on another machine has no harness here, so the dial names it by its Swarm id (Diego's dial, 2026-10-29).const agent = list(state.agents).find(a => (a.machineId === this.machineId && a.harnessId === harnessId) || a.id === harnessId)@@ -1003,27 +836,15 @@ export class SwarmCards {const to = chatId === undefined || found.id === chatId ? found.id: reviewed && this.chatOfLead(state, agent!.id as string, chatId) ? chatId : nullif (!to) return { said: false, refused: { code: 'CHAT_MOVED', message: 'That chat is no longer on the dial. Say it again.' } }- // A thread pinned with the words is where they go, or none; with none pinned, the thread on the face as they are sent.- const pinned = options.thread- if (pinned !== undefined && !reviewed && (found.thread ?? null) !== pinned) return { said: false, refused: { code: 'CHAT_MOVED', message: 'That chat is no longer on the dial. Say it again.' } }- const replyTo = pinned !== undefined ? pinned : to === found.id ? found.thread ?? null : nulllet sent: unknowntry {sent = await backend(this.core, 'POST', `/api/super-tabs/${tabId}/commands`, { operationId: `pro-voice-${randomUUID()}`,- command: { type: 'message.send', conversationId: to, text, replyTo, recipientIds: [] } })+ command: { type: 'message.send', conversationId: to, text, replyTo: null, recipientIds: [] } })} catch (error) {if (error instanceof SuperTabHostError && error.status >= 400 && error.status < 500) return { said: false, refused: { code: error.code, message: error.message } }throw error}- // Words said on the dial at top level, on the face, start the dial's thread, rooted at the message just posted.- const root = object(object(sent).result).messageId- if (chat === false || !options.threaded || replyTo !== null || !cardId(root)) return { said: true }- // 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(), leadId: agent!.id as string })- if (this.timer && this.live) { this.emit(); void this.pushOpen() }- return { said: true, thread: { tabId, conversationId: to, root } }+ return { said: true }}return { said: false }}@@ -1043,11 +864,9 @@ export class SwarmCards {* face: a swipe back to the other side, or the window back on a chat, is answered from it at once. */private prune(): void {for (const [key, held] of this.recaps) {- const { tabId, leadId, chatId, buddy } = held.recap+ const { tabId, leadId, chatId } = held.recapconst state = this.tabs.get(tabId)?.stateif (!state || !leadProjects(state).some(p => p.leadId === leadId) || (chatId !== undefined && !this.chatOfLead(state, leadId, chatId))) this.recaps.delete(key)- // A thread's only while it is on the face.- else if (held.thread !== undefined && this.target(tabId, leadId, buddy ? 'buddy' : true)?.thread !== held.thread) this.recaps.delete(key)}}@@ -1062,17 +881,15 @@ export class SwarmCards {for (const open of [...this.opened.values()]) {const target = this.target(open.tabId, open.leadId, open.chat)if (!target) continue- const thread = target.thread ?? null- if (open.sequence === null) { open.sequence = target.sequence; open.chatId = target.chatId ?? null; open.thread = thread; continue }- if (open.sequence === target.sequence && open.chatId === (target.chatId ?? null) && open.thread === thread) continue- // Another chat or thread on the face (a swipe, the window's move): what is held for it is pushed at once, and read again after.- const moved = open.chatId !== (target.chatId ?? null) || open.thread !== thread+ if (open.sequence === null) { open.sequence = target.sequence; open.chatId = target.chatId ?? null; continue }+ if (open.sequence === target.sequence && open.chatId === (target.chatId ?? null)) continue+ // Another chat on the face (a swipe, the window's move): what is held for it is pushed at once, and read again after.+ const moved = open.chatId !== (target.chatId ?? null)const quick = moved ? this.held(open.tabId, open.leadId, open.chat) : nullconst recap = quick?.recap ?? await this.read(open.tabId, open.leadId, open.chat, 'background').catch(() => null)if (!recap) continueopen.sequence = quick ? quick.sequence : target.sequenceopen.chatId = target.chatId ?? null- open.thread = threadthis.onRecap?.(recap)if (quick?.stale) this.refresh(open.tabId, open.leadId, open.chat, recap)}@@ -1080,8 +897,8 @@ export class SwarmCards {}/** How a chat's recap names it: by its id, and as a swarmBuddy dial's when asked for one. */-function namedFor(target: Target, chat: CardChat): { chatId?: string; buddy?: true; thread?: string } {- return target.chatId === undefined ? {} : { chatId: target.chatId, ...(chat === 'buddy' ? { buddy: true as const } : {}), ...(target.thread === undefined ? {} : { thread: target.thread }) }+function namedFor(target: Target, chat: CardChat): { chatId?: string; buddy?: true } {+ return target.chatId === undefined ? {} : { chatId: target.chatId, ...(chat === 'buddy' ? { buddy: true as const } : {}) }}diff --git a/cli/src/superTabs/inCore/cards.spec.ts b/cli/src/superTabs/inCore/cards.spec.tsindex bd7df57b7..63356290d 100644--- a/cli/src/superTabs/inCore/cards.spec.ts+++ b/cli/src/superTabs/inCore/cards.spec.ts@@ -33,14 +33,6 @@ describe('the Swarm cards on the devices', () => {expect(swarmCards).toHaveBeenCalledWith([])})- it('passes a Swarm\'s Buddy side on, and nothing else as a side', () => {- const { cards, swarmCards } = setup()- cards.cards([card('t1', [lead('l1')], { side: 'buddy' }), card('t2', [lead('l2')], { side: 'pm' }), card('t3', [lead('l3')], { side: true })])- const sent = swarmCards.mock.calls.at(-1)?.[0] as Array<Record<string, unknown>>- expect(sent.map((c) => c.side)).toEqual(['buddy', undefined, undefined])- expect('side' in sent[1]).toBe(false)- })-it('passes the reader\'s own Personal Swarm on as `personal`, and nothing else as one (round dial Personal | Team)', () => {const { cards, swarmCards } = setup()cards.cards([card('t1', [lead('l1')], { personal: true }), card('t2', [lead('l2')]), card('t3', [lead('l3')], { personal: 'yes' })])@@ -305,15 +297,8 @@ describe('whether the Swarm cards are wanted, which the core owns', () => {cards.want(true, ['t1'], bad)expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['t1'] }]])}- // A focus the device's own pick caused says so, as a change of its own; anything but true is not that.- cards.want(true, ['t1'], { ...focus, fromDevice: true })- expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['t1'], focus: { ...focus, fromDevice: true } })- cards.want(true, ['t1'], { ...focus, fromDevice: 1 })- expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['t1'], focus })- // The thread the window has open beside it rides along, an id or nothing; its change is a change.- cards.want(true, ['t1'], { ...focus, threadRoot: 'm1' })- expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['t1'], focus: { ...focus, threadRoot: 'm1' } })- cards.want(true, ['t1'], { ...focus, threadRoot: 'bad id' })+ // Neither whether a device caused the move nor a thread open beside it is part of the focus any more (task #3908).+ cards.want(true, ['t1'], { ...focus, fromDevice: true, threadRoot: 'm1' })expect(request).toHaveBeenLastCalledWith({ action: 'cardsWanted', on: true, include: ['t1'], focus })// The devices gone take the focus with them.cards.want(true, ['t1'], focus)@@ -333,44 +318,35 @@ describe('whether the Swarm cards are wanted, which the core owns', () => {expect(request.mock.calls).toEqual([[{ action: 'cardRecap', tabId: 't1', leadId: 'l1', chat: true }], [{ action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'l1', chat: true }],[{ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true }], [{ action: 'cardRecap', tabId: 't1', leadId: 'l1' }]])})- it('passes a swarmBuddy dial\'s buddy flag, and its side as cardSide with a sound side only', async () => {+ it('passes a swarmBuddy dial\'s buddy flag, and refuses its side as it refuses any other action', async () => {const { cards, request } = wanting()await cards.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1', chat: 'buddy' })await cards.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'l1', chat: 'buddy' })await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1' })- expect(await cards.ask({ action: 'cardSide', tabId: 't1', side: 'buddy', extra: 1 })).toEqual({ ok: true })- await cards.ask({ action: 'cardSide', tabId: 't1', side: 'pm' })await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true, chatId: 'bad id' })await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1', reviewed: true })expect(request.mock.calls).toEqual([[{ action: 'cardRecap', tabId: 't1', leadId: 'l1', chat: 'buddy' }], [{ action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'l1', chat: 'buddy' }],- [{ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1' }], [{ action: 'cardSide', tabId: 't1', side: 'buddy' }], [{ action: 'cardSide', tabId: 't1', side: 'pm' }],+ [{ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1' }],[{ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true }],[{ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', chatId: 'pm1', reviewed: true }]])request.mockClear()- for (const side of ['up', null, undefined, true]) expect(await cards.ask({ action: 'cardSide', tabId: 't1', side })).toEqual({ error: 'INVALID_REQUEST' })+ for (const side of ['pm', 'buddy', null, undefined]) expect(await cards.ask({ action: 'cardSide', tabId: 't1', side })).toEqual({ error: 'INVALID_REQUEST' })expect(request).not.toHaveBeenCalled()})- it('keeps a sound face thread and a recap\'s thread, drops a malformed one, and passes cardThreadLeave on', async () => {+ it('passes no thread: a face\'s or a recap\'s is dropped, a say\'s options are not passed on, and cardThreadLeave is refused (task #3908)', async () => {const { cards, request, swarmCards, swarmCardRecap } = wantingRecaps()const face = { kind: 'lead', id: 'lead-c1', name: 'Lead', working: false }- cards.cards([card('t1', [lead('l1', { chat: { ...face, thread: { root: 'm9', title: 'é'.repeat(60), replies: 2 } } }),- lead('l2', { chat: { ...face, thread: { root: 'bad id', title: 'x' } } }), lead('l3', { chat: { ...face, thread: { root: 'm9', title: 'x', replies: -1 } } })])])+ cards.cards([card('t1', [lead('l1', { chat: { ...face, thread: { root: 'm9', title: 'x', replies: 2 } } })])])const leads = (swarmCards.mock.calls.at(-1)?.[0] as Array<{ leads: Array<{ chat: Record<string, unknown> }> }>)[0].leads- expect(leads[0].chat.thread).toEqual({ root: 'm9', title: 'é'.repeat(40), replies: 2 })- expect(leads[1].chat).not.toHaveProperty('thread')- expect(leads[2].chat.thread).toEqual({ root: 'm9', title: 'x' })- cards.recap(recap({ chatId: 'lead-c1', thread: 'm9' })); cards.recap(recap({ chatId: 'lead-c1', thread: 'bad id' }))- expect(swarmCardRecap.mock.calls.map((c: Array<{ thread?: string }>) => c[0].thread)).toEqual(['m9', undefined])+ expect(leads[0].chat).not.toHaveProperty('thread')+ cards.recap(recap({ chatId: 'lead-c1', thread: 'm9' }))+ expect(swarmCardRecap.mock.calls.map((c: Array<{ thread?: string }>) => c[0].thread)).toEqual([undefined])request.mockClear()- await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, threaded: true, thread: null })- expect(request).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, threaded: true, thread: null })- await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, thread: 'm9' })- expect(request).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, thread: 'm9' })- await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, thread: 'bad id' })+ await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true, threaded: true, thread: 'm9' })expect(request).toHaveBeenLastCalledWith({ action: 'cardSay', harnessId: 'h1', text: 'x', chat: true })request.mockClear()- await cards.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1', extra: 1 })- expect(request.mock.calls).toEqual([[{ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1' }]])+ expect(await cards.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1' })).toEqual({ error: 'INVALID_REQUEST' })+ expect(request).not.toHaveBeenCalled()})it('on an account change with no device wanting cards only clears the list', () => {const { cards, request, swarmCards } = wanting()diff --git a/cli/src/superTabs/inCore/cards.ts b/cli/src/superTabs/inCore/cards.tsindex 3d43b51a6..07fd3981f 100644--- a/cli/src/superTabs/inCore/cards.ts+++ b/cli/src/superTabs/inCore/cards.ts@@ -35,8 +35,6 @@ const BUDDY_NOTICE_CHATS: ReadonlySet<string> = new Set(['buddy'])/** Desktop's pattern is the 15 half bits of a 5×5 grid (superTabs/buddyAvatar.ts). */const MAX_CELLS = 0x7fffconst COLOR = /^#[0-9a-f]{6}$/-/** The dial's thread title: the first line, at most 80 bytes (the cards service cuts it; checked again here). */-const THREAD_TITLE_BYTES = 80/** A notice's thread root, cut to this: kept when longer than the dial holds, so no face matches it and the dial beeps. */const THREAD_ROOT_BYTES = 128/** The Pro keeps an id in 48 bytes with its NUL. */@@ -61,11 +59,7 @@ function chatIn(value: unknown): SwarmChat | null {const chat = object(value)if (typeof chat.kind !== 'string' || !CHATS.has(chat.kind) || !id(chat.id) || typeof chat.name !== 'string' || typeof chat.working !== 'boolean') return nullif (chat.since !== undefined && !whole(chat.since)) return null- // The thread the face is in (spec 2026-11-03-dial-thread-face); one that is not sound is left out and the chat is kept.- const thread = object(chat.thread)- const inThread = id(thread.root) && typeof thread.title === 'string'- return { kind: chat.kind as SwarmChat['kind'], id: chat.id, name: cut(chat.name, NAME_BYTES), working: chat.working, ...(chat.since === undefined ? {} : { since: chat.since }),- ...(inThread ? { thread: { root: thread.root as string, title: cut(thread.title as string, THREAD_TITLE_BYTES), ...(whole(thread.replies) ? { replies: thread.replies } : {}) } } : {}) }+ return { kind: chat.kind as SwarmChat['kind'], id: chat.id, name: cut(chat.name, NAME_BYTES), working: chat.working, ...(chat.since === undefined ? {} : { since: chat.since }) }}/** A Lead's notice from one of `chats`, checked and cut; null when it is not one, and the Lead goes on without it. */@@ -131,7 +125,7 @@ function cardIn(value: unknown): SwarmCard | null {}// `personal`: the reader's own Personal Swarm, for the round dial's Personal | Team picker. The port rebuilt each card without// it, so no dial ever showed the picker (Diego's dial, 2026-11-06).- return { id: card.id, name: cut(card.name, NAME_BYTES), count: card.count, leads, ...(card.side === 'buddy' ? { side: 'buddy' as const } : {}),+ return { id: card.id, name: cut(card.name, NAME_BYTES), count: card.count, leads,...(card.personal === true ? { personal: true as const } : {}) }}@@ -142,7 +136,7 @@ function recapIn(value: unknown): LeadRecap | null {// A chat's recap names its chat or is not one: a dial must never show it for another chat.if (recap.chatId !== undefined && !id(recap.chatId)) return nullreturn { tabId: recap.tabId, leadId: recap.leadId, text: cut(recap.text, RECAP_BYTES), at: recap.at, none: recap.none, ...(recap.chatId === undefined ? {} : { chatId: recap.chatId }),- ...(recap.buddy === true ? { buddy: true as const } : {}), ...(id(recap.thread) ? { thread: recap.thread } : {}) }+ ...(recap.buddy === true ? { buddy: true as const } : {}) }}export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log = (line) => console.log(line) }: SuperTabCardsDeps) {@@ -150,7 +144,7 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =let last: SwarmCard[] | null = null/** Whether any capable device wants cards, the Swarms to read first, and the conversation the window has open in a Swarm tab. */let wanted = false, include: string[] = []- let focus: { tabId: string; conversationId: string; threadRoot?: string; fromDevice?: true } | null = null+ let focus: { tabId: string; conversationId: string } | null = nullconst route = async (payload: Record<string, unknown>): Promise<Record<string, unknown>> => {try {const answer = await request?.(payload)@@ -165,9 +159,8 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =const next = on && Array.isArray(swarms) ? [...new Set(swarms.filter(id))].slice(0, MAX_CARDS) : []const asked = object(open)const nextFocus = on && id(asked.tabId) && id(asked.conversationId)- ? { tabId: asked.tabId, conversationId: asked.conversationId, ...(id(asked.threadRoot) ? { threadRoot: asked.threadRoot } : {}),- ...(asked.fromDevice === true ? { fromDevice: true as const } : {}) } : null- const key = (f: typeof focus) => `${f?.tabId}/${f?.conversationId}/${f?.threadRoot}/${f?.fromDevice === true}`+ ? { tabId: asked.tabId, conversationId: asked.conversationId } : null+ const key = (f: typeof focus) => `${f?.tabId}/${f?.conversationId}`if (on === wanted && next.join(',') === include.join(',') && key(nextFocus) === key(focus)) returnwanted = oninclude = next@@ -210,26 +203,19 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =swarmCardRecap(recap)},/** What the devices may ask of the Super Tab service, and nothing else of it: `cardsWanted` is kept here, `cardRecap`,- * `cardOpen`, `cardSay`, `cardSide` and `cardWorker` go to the service; any other action is refused. */+ * `cardOpen`, `cardSay` and `cardWorker` 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, payload.focus); return Promise.resolve({ ok: true }) }// A round dial that speaks swarmChat asks for the chat on its face, and one that speaks swarmBuddy for the face on its// side ('buddy'); without the flag, the request is today's.const chat = payload.chat === true || payload.chat === 'buddy' ? { chat: payload.chat } : {}- // The side a swarmBuddy dial swiped to.- if (payload.action === 'cardSide') {- return payload.side === 'pm' || payload.side === 'buddy' ? route({ action: 'cardSide', tabId: payload.tabId, side: payload.side }) : Promise.resolve({ error: 'INVALID_REQUEST' })- }if (payload.action === 'cardRecap') return route({ action: 'cardRecap', tabId: payload.tabId, leadId: payload.leadId, ...chat })// The chat on the dial's face when the words were spoken, which they may be posted in and no other.// `reviewed`: the person saw that chat named on the dial and pressed Send.if (payload.action === 'cardSay') return route({ action: 'cardSay', harnessId: payload.harnessId, text: payload.text, ...chat,- ...(id(payload.chatId) ? { chatId: payload.chatId, ...(payload.reviewed === true ? { reviewed: true } : {}) } : {}),- ...(payload.threaded === true ? { threaded: true } : {}), ...(payload.thread === null || id(payload.thread) ? { thread: payload.thread } : {}) })+ ...(id(payload.chatId) ? { chatId: payload.chatId, ...(payload.reviewed === true ? { reviewed: true } : {}) } : {}), })if (payload.action === 'cardOpen') return route({ action: 'cardOpen', session: payload.session, tabId: payload.tabId, leadId: payload.leadId, ...chat })// A card's failure from another computer: whether its agent is a Swarm's worker (services/devices.ts asks; it decides).- // The dial left the thread on its face: the service forgets it and names the conversation whose thread the window should close.- if (payload.action === 'cardThreadLeave') return route({ action: 'cardThreadLeave', tabId: payload.tabId, leadId: payload.leadId, ...chat })if (payload.action === 'cardWorker') return route({ action: 'cardWorker', machineId: payload.machineId, harnessId: payload.harnessId })return Promise.resolve({ error: 'INVALID_REQUEST' })},diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.tsindex 01d0662ae..4a8c6fa2c 100644--- a/cli/src/superTabs/service.spec.ts+++ b/cli/src/superTabs/service.spec.ts@@ -1017,15 +1017,11 @@ describe('the Swarm cards the devices ask for', () => {const t = withCards()await t.ask({ action: 'cardsWanted', on: true, include: ['s1'], focus: { tabId: 's1', conversationId: 'g1', extra: 1 } }, owner)expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'], { tabId: 's1', conversationId: 'g1' })- // A focus the device's own pick caused says so; anything but true is not that.+ // Whether a device caused the move is no part of the focus any more (it only kept a dial's side, task #3908).await t.ask({ action: 'cardsWanted', on: true, include: ['s1'], focus: { tabId: 's1', conversationId: 'g1', fromDevice: true } }, owner)- expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'], { tabId: 's1', conversationId: 'g1', fromDevice: true })- await t.ask({ action: 'cardsWanted', on: true, include: ['s1'], focus: { tabId: 's1', conversationId: 'g1', fromDevice: 'yes' } }, owner)expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'], { tabId: 's1', conversationId: 'g1' })- // The thread open beside it, an id or nothing.+ // A thread open beside it is no part of the focus any more.await t.ask({ action: 'cardsWanted', on: true, include: ['s1'], focus: { tabId: 's1', conversationId: 'g1', threadRoot: 'm1' } }, owner)- expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'], { tabId: 's1', conversationId: 'g1', threadRoot: 'm1' })- await t.ask({ action: 'cardsWanted', on: true, include: ['s1'], focus: { tabId: 's1', conversationId: 'g1', threadRoot: 'bad id' } }, owner)expect(t.cards.want).toHaveBeenLastCalledWith(true, ['s1'], { tabId: 's1', conversationId: 'g1' })// A focus that is not two ids is none.for (const focus of [{ tabId: 'bad id', conversationId: 'g1' }, { tabId: 's1', conversationId: 'x'.repeat(48) }, { tabId: 's1' }, 'g1']) {@@ -1043,18 +1039,9 @@ describe('the Swarm cards the devices ask for', () => {await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it' }, owner)expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', false)})- it('cardSide sets a swarmBuddy dial\'s side, and the buddy flag reaches recap, open and say', async () => {+ it('answers an older dial\'s cardSide as no request, and the buddy flag reaches recap, open and say', async () => {const t = withCards()- expect(await t.ask({ action: 'cardSide', tabId: 't1', side: 'buddy' }, owner)).toEqual({ ok: true })- expect(t.cards.side).toHaveBeenLastCalledWith('t1', 'buddy')- expect(await t.ask({ action: 'cardSide', tabId: 't1', side: 'pm' }, owner)).toEqual({ ok: true })- expect(t.cards.side).toHaveBeenLastCalledWith('t1', 'pm')- for (const bad of [{ tabId: 'bad id', side: 'pm' }, { tabId: 'x'.repeat(48), side: 'pm' }, { tabId: 't1', side: 'up' }, { tabId: 't1' }]) {- expect(await t.ask({ action: 'cardSide', ...bad }, owner)).toEqual({ error: 'INVALID_REQUEST' })- }- // Only this computer's own devices set it.- expect(await t.ask({ action: 'cardSide', tabId: 't1', side: 'buddy' }, visitor)).toEqual({ error: 'OWNER_REQUIRED' })- expect(t.cards.side).toHaveBeenCalledTimes(2)+ expect(await t.ask({ action: 'cardSide', tabId: 't1', side: 'buddy' }, owner)).toMatchObject({ error: expect.any(String) })await t.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1', chat: 'buddy' }, owner)expect(t.cards.recap).toHaveBeenLastCalledWith('t1', 'l1', 'buddy')await t.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: 'l1', chat: 'buddy' }, owner)@@ -1072,27 +1059,16 @@ describe('the Swarm cards the devices ask for', () => {await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: 'buddy', reviewed: true }, owner)expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', 'buddy')})- it('cardThreadLeave tells the cards and answers the project; cardSay answers the thread its words started', async () => {+ // Task #3908: threads are gone from the dial. An older dial's frames still arrive and are answered as before they existed.+ it('answers an older dial\'s thread frames without a thread: cardThreadLeave is no request, and cardSay passes no thread options', async () => {const t = withCards()- t.cards.threadLeave.mockReturnValueOnce({ tabId: 't1', conversationId: 'lead-web' })- expect(await t.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1', chat: 'buddy' }, owner)).toEqual({ ok: true, conversationId: 'lead-web' })- expect(t.cards.threadLeave).toHaveBeenLastCalledWith('t1', 'l1', 'buddy')- expect(await t.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1' }, owner)).toEqual({ ok: true })- for (const bad of [{ tabId: 'bad id', leadId: 'l1' }, { tabId: 't1', leadId: 'x'.repeat(48) }, { tabId: 't1' }]) {- expect(await t.ask({ action: 'cardThreadLeave', ...bad }, owner)).toEqual({ error: 'INVALID_REQUEST' })- }- expect(await t.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1' }, visitor)).toEqual({ error: 'OWNER_REQUIRED' })- expect(t.cards.threadLeave).toHaveBeenCalledTimes(2)- expect(t.cards.threadLeave).toHaveBeenLastCalledWith('t1', 'l1', false)+ expect(await t.ask({ action: 'cardThreadLeave', tabId: 't1', leadId: 'l1', chat: 'buddy' }, owner)).toMatchObject({ error: expect.any(String) })await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true, threaded: true, thread: null }, owner)- expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', true, undefined, false, { threaded: true, thread: null })- await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true, chatId: 'lead-web', reviewed: true, thread: 'm9' }, owner)- expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', true, 'lead-web', true, { thread: 'm9' })- await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true, thread: 'bad id' }, owner)expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', true)- t.cards.say.mockResolvedValueOnce({ said: true, thread: { tabId: 't1', conversationId: 'lead-web', root: 'm9' } })- expect(await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true }, owner))- .toEqual({ ok: true, said: true, thread: { tabId: 't1', conversationId: 'lead-web', root: 'm9' } })+ await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true, chatId: 'lead-web', reviewed: true, thread: 'm9' }, owner)+ expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', true, 'lead-web', true)+ t.cards.say.mockResolvedValueOnce({ said: true })+ expect(await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', chat: true }, owner)).toEqual({ ok: true, said: true })})it('cardSay passes a refused post\'s code and message on, and says nothing of a refusal otherwise', async () => {const t = withCards()diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex 898f8541a..1decd64d9 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -536,7 +536,7 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =// The devices' (core/devicesLink.ts): a Harness Pro that shows the Swarm cards is attached or gone, wants a Lead's recap, or// has one open. They read the account's Swarms as the person, and need no agent.// Only this computer's own devices ask: an account owner on another machine does not make this one read the Swarms.- if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen' || payload.action === 'cardSay' || payload.action === 'cardWorker' || payload.action === 'cardSide' || payload.action === 'cardThreadLeave') {+ if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen' || payload.action === 'cardSay' || payload.action === 'cardWorker') {if (!asker.local) return { error: 'OWNER_REQUIRED' }// A round dial that speaks swarmChat asks for the chat on its face (design 2026-10-28-round-dial-swarm-chat), and one// that speaks swarmBuddy for the face on the side it keeps ('buddy', spec 2026-10-29-round-dial-pm-buddy).@@ -545,37 +545,22 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =const include = Array.isArray(payload.include) ? payload.include.filter(cardId) : []const asked = payload.focus && typeof payload.focus === 'object' ? payload.focus as Record<string, unknown> : {}const focus = cardId(asked.tabId) && cardId(asked.conversationId)- ? { tabId: asked.tabId, conversationId: asked.conversationId, ...(cardId(asked.threadRoot) ? { threadRoot: asked.threadRoot } : {}),- ...(asked.fromDevice === true ? { fromDevice: true as const } : {}) } : null+ ? { tabId: asked.tabId, conversationId: asked.conversationId } : nullcards().want(payload.on === true, include, focus)return { ok: true }}if (payload.action === 'cardRecap' && cardId(payload.tabId) && cardId(payload.leadId)) return { ok: true, ...await cards().recap(payload.tabId, payload.leadId, chat) }if (payload.action === 'cardSay' && cardId(payload.harnessId) && typeof payload.text === 'string' && payload.text.trim() && payload.text.length <= 32_000) {- // `threaded`: the dial speaks swarmThread and the words came from its face; `thread`: the root of the thread on the face- // then (null: none), which the words are held to.- const options = { ...(payload.threaded === true ? { threaded: true } : {}),- ...(payload.thread === null || cardId(payload.thread) ? { thread: payload.thread } : {}) }const pinned: [chatId?: string, reviewed?: boolean] = !cardId(payload.chatId) ? []: payload.reviewed === true ? [payload.chatId, true] : [payload.chatId]- const result = Object.keys(options).length- ? await cards().say(payload.harnessId, payload.text.trim(), chat, cardId(payload.chatId) ? payload.chatId : undefined, cardId(payload.chatId) && payload.reviewed === true, options)- : await cards().say(payload.harnessId, payload.text.trim(), chat, ...pinned)+ const result = await cards().say(payload.harnessId, payload.text.trim(), chat, ...pinned)// A refusal travels with its code and message, which the dial shows instead of typing the words anywhere.- return { ok: true, said: result.said, ...(!result.said && result.refused ? { refused: result.refused } : {}), ...(result.said && result.thread ? { thread: result.thread } : {}) }+ return { ok: true, said: result.said, ...(!result.said && result.refused ? { refused: result.refused } : {}) }}// A card's failure from another computer: whether its agent is a Swarm's Builder or Reviewer, from the Swarms read last.if (payload.action === 'cardWorker' && identifier(payload.machineId) && identifier(payload.harnessId)) {return { ok: true, worker: cards().worker(payload.machineId, payload.harnessId) }}- if (payload.action === 'cardThreadLeave' && cardId(payload.tabId) && cardId(payload.leadId)) {- const left = cards().threadLeave(payload.tabId, payload.leadId, chat)- return { ok: true, ...(left ? { conversationId: left.conversationId } : {}) }- }- if (payload.action === 'cardSide' && cardId(payload.tabId) && (payload.side === 'pm' || payload.side === 'buddy')) {- cards().side(payload.tabId, payload.side)- return { ok: true }- }if (payload.action === 'cardOpen' && cardId(payload.session) && cardId(payload.tabId) && (payload.leadId === null || cardId(payload.leadId))) {cards().open(payload.session, payload.tabId, payload.leadId, chat)return { ok: true }diff --git a/docs/plans/2026-11-06-dial-buddy-only-daemon-plan.md b/docs/plans/2026-11-06-dial-buddy-only-daemon-plan.mdnew file mode 100644index 000000000..db5c6f1c6--- /dev/null+++ b/docs/plans/2026-11-06-dial-buddy-only-daemon-plan.md@@ -0,0 +1,35 @@+# Round dial: Buddy only on the Lead face, no PM side, no threads — daemon plan++**Goal:** The daemon stops giving a round dial the PM side and the thread face: a swarmBuddy dial's Swarm face shows and talks to the person's Buddy only, and nothing about threads reaches any dial. Old dials keep connecting.++**Architecture:** The dial's `supertab` frame carries both a Lead chat (`chat`) and a Buddy (`buddies`, `sideChat`), a frame-level `side`, and thread fields (`thread`, `threadTitle`, `threadReplies`) for a `swarmThread` dial. `cards.ts` (`CardsHost`) keeps the per-Swarm `sides`, the dial's own `threads`, `titles`, `left` and the window's `threadRoot` focus; `cableSession.ts` reads `supertab.side` and `supertab.thread.leave` and announces nothing for threads. Buddy-only means the Buddy chat is the face for a swarmBuddy dial and nothing in the frame says "side" or "thread"; an old dial (no swarmBuddy) keeps the Lead face it has.++**Tech Stack:** TypeScript, vitest (cli/src/cable, cli/src/superTabs, cli/src/core, cli/src/services).++**Spec:** task #3908 (Diego, the final Board spec: people talk only to their Buddies; no Threads feature).++## Scope: this plan is the daemon half only+The firmware half (devices/harness-device/firmware/main: ui_habitat.c, cable_client.c, supertab.c/h and their host tests) needs ESP-IDF for `idf.py build`; ui_habitat.c is not compiled by `test/run.sh`. It is its own task for an Engineer on a machine with ESP-IDF. Shipping the daemon first is safe: an old dial that still sends `swarmThread` in its hello or `supertab.side`/`supertab.thread.leave` frames gets no thread data and its frames are ignored with no error.++## Global Constraints+- Old dials still connect; side and thread frames from them are ignored without errors or log noise; a hello with `swarmThread` is accepted and the capability not granted.+- Holding the recap still opens Personal | Team; tapping the name still opens the project list.+- Never publish firmware or touch the device update manifest; flash no device.+- `npm run test:core` stays at 100% for cli/src/core and cli/src/services.++## Review Focus+- No frame field a shipped firmware reads as mandatory is removed in a way that makes it drop the frame (cable_client.c / supertab.c parse side and thread fields as optional).+- The window's thread pane is never closed or opened by a dial again; Desktop moved its threads in #3365.++## Task 1: threads leave the dial's path (cards.ts, cableSession.ts, cableHost.ts, devicesLink.ts, core/api.ts, services/devices.ts, superTabs/service.ts)+**Files:** those, and their specs.+- [ ] Failing test: a dial that announces `swarmThread: 'v1'` is sent no `thread`, `threadTitle` or `threadReplies` fields on a Lead, a recap or a notice, and `supertab.thread.leave` from it is ignored without an error or a host call.+- [ ] Remove the capability, `threadLeave`, `swarmThreadLeave`, `superTabThread`, the dial's thread bookkeeping in cards.ts (`threads`, `titles`, `left`, `threadRoot` focus, thread-aware recap keys, `sayOptions`), and the thread fields of `SwarmChat`, `LeadRecap`, `LeadNotice`.++## Task 2: the PM side leaves the dial's path (cards.ts, cableSession.ts)+- [ ] Failing test: a swarmBuddy dial's frame has no `side`, each Lead is its Buddy face (`buddyLead`), and `supertab.side` (kept or not) is ignored with no error and no `swarmCardSide`/`followSide` call.+- [ ] Remove `sides`, `side()`, `sideOf`, `swarmCardSide`, `followSide`, the PM `sideChat` for Buddy dials, and the frame's `side`.+- [ ] An old dial's test: a dial without swarmBuddy gets the frame it got before.++## Task 3: gates+- [ ] `npx tsc --noEmit -p .`, `npx vitest run src/cable src/superTabs src/core src/services`, `npm run test:core` (100%), `npm run test:portability` if touched.