Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Leaderboard: a Buddy proposal that ships credits the person's one Buddy, not its session (Diego) (#2507)

0xken153dab98249bea
diff --git a/backend/integration/superTabSwarmBuddy.test.ts b/backend/integration/superTabSwarmBuddy.test.ts
index 8603a2b99..12ba04085 100644
--- a/backend/integration/superTabSwarmBuddy.test.ts
+++ b/backend/integration/superTabSwarmBuddy.test.ts
@@ -13,6 +13,7 @@ import type { Command } from '../src/superTabs/commands.js'
import { poolRows } from './hostRows.test-support.js'
import { beforeFirstWrite } from './interleave.test-support.js'
import { readInbox } from '../src/superTabs/read/inbox.js'
+import { SwarmReads } from '../src/superTabs/read/service.js'
// One Buddy per person per Swarm (docs/specs/2026-10-31-one-buddy-per-swarm.md; Dee, 10-31): one chat at Swarm level, a main
// Buddy that reads every project its person reads and writes nowhere but that chat, and project sessions, the only Buddies that
@@ -231,6 +232,91 @@ describe('a project session', () => {
expect(row).toMatchObject({ conversationId: f.web.conversationId, recipientIds: [f.pms.web], source: { kind: 'buddy-proposal', personId: peer.sub } })
})
+ /** peer's session proposes in web, the PM opens the group from it and the group's PR merges; the session then ends. */
+ async function shippedFromSession(f: Swarm, { endBeforeOpen = false } = {}) {
+ const { chat, main } = await buddy(f)
+ const { thread, agentId } = await projectSession(f, chat, f.web.projectId, 'Let us plan web offline sync')
+ const ask = String((await send(f, chat, 'Send it to the PM', { replyTo: thread })).result.messageId)
+ const proposal = String((await f.execute({ type: 'buddy.propose', conversationId: chat, ownerMessageId: ask, goal: 'Offline sync', scope: 'Web only',
+ priority: 'normal' }, peer, agentId)).result.messageId)
+ // Sessions end by themselves after 30 idle minutes, so the PM often opens the group after the session is gone.
+ if (endBeforeOpen) await f.execute({ type: 'buddy.sessionEnd', conversationId: chat, thread, reason: 'ended' }, peer)
+ const group = String((await f.execute({ type: 'conversation.create', projectId: f.web.projectId, title: 'Offline sync', brief: 'Web keeps edits offline.',
+ checks: [], proposalMessageId: proposal }, owner, f.pms.web)).result.conversationId)
+ await f.execute({ type: 'conversation.merged', conversationId: group, pullRequestUrl: 'https://github.com/example/app/pull/7' })
+ if (!endBeforeOpen) await f.execute({ type: 'buddy.sessionEnd', conversationId: chat, thread, reason: 'ended' }, peer)
+ return { chat, main, agentId, group }
+ }
+ const buddyRows = async (f: Swarm, user: AuthUser, projectId: string) =>
+ (await new SwarmReads(f.store).leaderboard(user, f.tab, projectId)).agents.filter(a => a.kind === 'buddy')
+
+ it('credits a shipped proposal to the person\'s one Buddy, so its row keeps its name and person after the session ends (Diego, 11-02)', async () => {
+ const f = await swarm()
+ const { main, agentId, group } = await shippedFromSession(f)
+ // The session is gone; the credit was recorded under the one Buddy, not the session.
+ expect((await f.store.read(peer, f.tab)).state.agents.map(a => a.id)).not.toContain(agentId)
+ expect((await f.store.read(owner, f.tab)).state.conversations.find(c => c.id === group)!.ledger!.proposal!.buddyId).toBe(main)
+ const name = (await f.store.read(peer, f.tab)).state.agents.find(a => a.id === main)!.displayName
+ const rows = await buddyRows(f, peer, f.web.projectId)
+ expect(rows).toHaveLength(1)
+ expect(rows[0]).toMatchObject({ agentId: main, displayName: name, personId: peer.sub, shipped: 1, points: 3 })
+ expect(rows[0]!.displayName).not.toBe('Former Buddy')
+ // The same row to another reader of the project, and in a project it shipped nothing in: listed, with 0 shipped.
+ expect((await buddyRows(f, owner, f.web.projectId)).map(r => [r.agentId, r.displayName, r.personId, r.shipped])).toEqual([[main, name, peer.sub, 1]])
+ expect((await buddyRows(f, peer, 'lead')).map(r => [r.agentId, r.displayName, r.personId, r.shipped])).toEqual([[main, name, peer.sub, 0]])
+ })
+
+ it('credits the one Buddy when the session ended before the PM opened the group from its proposal (reviewer of #2507)', async () => {
+ const f = await swarm()
+ const { main, agentId, group } = await shippedFromSession(f, { endBeforeOpen: true })
+ expect((await f.store.read(peer, f.tab)).state.agents.map(a => a.id)).not.toContain(agentId)
+ expect((await f.store.read(owner, f.tab)).state.conversations.find(c => c.id === group)!.ledger!.proposal!.buddyId).toBe(main)
+ const name = (await f.store.read(peer, f.tab)).state.agents.find(a => a.id === main)!.displayName
+ expect((await buddyRows(f, peer, f.web.projectId)).map(r => [r.agentId, r.displayName, r.personId, r.shipped])).toEqual([[main, name, peer.sub, 1]])
+ })
+
+ it('names nobody when the session ended and its person lost the project before the PM opened the group', async () => {
+ const f = await swarm()
+ const { chat, main } = await buddy(f)
+ const { thread, agentId } = await projectSession(f, chat, f.web.projectId, 'Plan it')
+ const ask = String((await send(f, chat, 'Send it', { replyTo: thread })).result.messageId)
+ const proposal = String((await f.execute({ type: 'buddy.propose', conversationId: chat, ownerMessageId: ask, goal: 'G', scope: 'S', priority: 'normal' },
+ peer, agentId)).result.messageId)
+ await f.execute({ type: 'buddy.sessionEnd', conversationId: chat, thread, reason: 'ended' }, peer)
+ await f.execute({ type: 'project.sharing', projectId: f.web.projectId, visibility: 'private', memberIds: [owner.sub] })
+ const group = String((await f.execute({ type: 'conversation.create', projectId: f.web.projectId, title: 'T', brief: '', checks: [], proposalMessageId: proposal },
+ owner, f.pms.web)).result.conversationId)
+ await f.execute({ type: 'conversation.merged', conversationId: group, pullRequestUrl: 'https://github.com/example/app/pull/8' })
+ const board = await new SwarmReads(f.store).leaderboard(owner, f.tab, f.web.projectId)
+ expect(board.agents.filter(a => a.kind === 'buddy').map(a => [a.agentId, a.displayName, a.personId, a.machineId])).toEqual([[main, 'Former Buddy', null, '']])
+ expect(JSON.stringify(board)).not.toMatch(/Peer Mac|peer-mac/)
+ })
+
+ it('never names the one Buddy, its person or its Mac on a board of a project its person no longer reads', async () => {
+ const f = await swarm()
+ const { main } = await shippedFromSession(f)
+ await f.execute({ type: 'project.sharing', projectId: f.web.projectId, visibility: 'private', memberIds: [owner.sub] })
+ const board = await new SwarmReads(f.store).leaderboard(owner, f.tab, f.web.projectId)
+ expect(board.agents.filter(a => a.kind === 'buddy').map(a => [a.agentId, a.displayName, a.personId, a.machineId, a.shipped])).toEqual([[main, 'Former Buddy', null, '', 1]])
+ expect(JSON.stringify(board)).not.toMatch(/peer-mac|Peer Mac/)
+ // The person lost the project: the board is closed to them like a made-up project.
+ await expect(new SwarmReads(f.store).leaderboard(peer, f.tab, f.web.projectId)).rejects.toThrow()
+ // And a private project the person reads lists their Buddy there, which a person who is not in it never sees.
+ expect((await buddyRows(f, peer, f.secret.projectId)).map(r => r.agentId)).toEqual([main])
+ await expect(new SwarmReads(f.store).leaderboard(other, f.tab, f.secret.projectId)).rejects.toThrow()
+ })
+
+ it('keeps a session\'s proposal credited to the one Buddy while the session still runs, with no row of its own', async () => {
+ const f = await swarm()
+ const { chat, main } = await buddy(f)
+ const { thread, agentId } = await projectSession(f, chat, f.web.projectId, 'Plan it')
+ const ask = String((await send(f, chat, 'Send it', { replyTo: thread })).result.messageId)
+ const proposal = String((await f.execute({ type: 'buddy.propose', conversationId: chat, ownerMessageId: ask, goal: 'G', scope: 'S', priority: 'normal' },
+ peer, agentId)).result.messageId)
+ await f.execute({ type: 'conversation.create', projectId: f.web.projectId, title: 'T', brief: '', checks: [], proposalMessageId: proposal }, owner, f.pms.web)
+ expect((await buddyRows(f, peer, f.web.projectId)).map(r => r.agentId)).toEqual([main])
+ })
+
it('a plain New session reads like the main Buddy and proposes nothing', async () => {
const f = await swarm()
const { chat } = await buddy(f)
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 4f1cee8a0..a52cd2eeb 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -651,7 +651,16 @@ function proposalOf(state: SuperTabState, project: SwarmProject, proposal: Comma
}
// The person it was sent for, as buddy.propose recorded them: the Swarm writes this source, never a sender.
const personId = typeof proposal.source.personId === 'string' ? proposal.source.personId : undefined
- return { buddyId: author.id, messageId: proposal.id, ...personId ? { personId } : {} }
+ // Credited to the person's one Buddy, not to the thread session that wrote it: a session ends (after 30 idle minutes, often
+ // before the PM opens the group), and its row then showed as an unnamed "Former Buddy" with no person (Diego, 11-02). The
+ // person is the session's owner, else (the author gone) the one the Swarm recorded the proposal for, at their current
+ // membership. Without a one Buddy (removed since), the author keeps it.
+ const gone = !buddy ? state.people.find(p => p.id === personId) : undefined
+ const owner = buddy?.buddyOf ?? (gone ? { personId: gone.id, generation: gone.generation } : undefined)
+ const main = owner && !(buddy && isSwarmBuddy(buddy))
+ ? state.agents.find(a => isSwarmBuddy(a) && !a.buddySession && a.buddyOf!.personId === owner.personId && a.buddyOf!.generation === owner.generation)
+ : undefined
+ return { buddyId: main?.id ?? author.id, messageId: proposal.id, ...personId ? { personId } : {} }
}
/** The person a proposal was sent for, while they are still in the Swarm and read [project]; otherwise nobody, so a person
* who left or lost the project is never credited and opening the group still works (the PM is told to name someone). */
diff --git a/backend/src/superTabs/leaderboard/stats.test.ts b/backend/src/superTabs/leaderboard/stats.test.ts
index e6e87ad56..f3c6c33fc 100644
--- a/backend/src/superTabs/leaderboard/stats.test.ts
+++ b/backend/src/superTabs/leaderboard/stats.test.ts
@@ -465,6 +465,66 @@ describe('Agents: the permanent agents, the PM and Buddies, by name like people
expect(of(view, 'sparky')).toMatchObject({ points: 3, shipped: 1 })
expect(of(view, 'river')).toMatchObject({ points: 0, shipped: 0, rank: 2 })
})
+
+ describe('a person\'s one Swarm Buddy (Diego, 2026-11-02)', () => {
+ /** Dee's one Buddy: Swarm-wide, in no project, on her Mac; and a project session of it. */
+ function oneBuddy(state: SuperTabState) {
+ agents(state)
+ state.agents = state.agents.filter(a => a.id !== 'sparky')
+ const base = state.agents.find(a => a.id === 'river')!
+ const dee = { personId: 'dee', generation: 'g' }
+ state.agents.push({ ...base, id: 'main', name: 'main', displayName: 'Sparky', projectId: undefined, buddyOf: dee, buddyScope: 'swarm',
+ machineOwnerId: 'dee', contributorId: 'dee', machineId: 'mac-dee' },
+ { ...base, id: 'session', name: 'session', displayName: 'Session', projectId: 'lead', buddyOf: dee, buddyScope: undefined,
+ buddySession: { thread: 't', from: 1, projectId: 'lead' }, machineId: 'mac-dee' })
+ return state
+ }
+ const ledger = (buddyId: string) => ({ askedAt: WEEK, shippedAt: WEEK + HOUR, proposal: { buddyId, messageId: 'm1' } })
+ const buddies = (view: ReturnType<typeof board>) => view.agents.filter(a => a.kind === 'buddy')
+
+ it('lists it in every project its person reads, with its name and person, and never its sessions', () => {
+ const view = board(oneBuddy(swarm()), [], WEEK, NOW, [machine('dee', [], 'mac-dee')])
+ expect(buddies(view).map(a => [a.agentId, a.displayName, a.personId, a.machineId])).toEqual([['main', 'Sparky', 'dee', 'mac-dee']])
+ })
+
+ it('credits a proposal its session recorded to the one Buddy, with its own, and shows no Former Buddy', () => {
+ const view = board(oneBuddy(swarm()), [shipped('dee', WEEK, WEEK + HOUR, { ledger: ledger('session') }),
+ shipped('dee', WEEK, WEEK + HOUR, { ledger: ledger('main') })])
+ expect(buddies(view).map(a => [a.agentId, a.displayName, a.personId, a.shipped, a.points])).toEqual([['main', 'Sparky', 'dee', 2, 6]])
+ })
+
+ it('shows a session that ended before this change as Former Buddy, with no person', () => {
+ const view = board(oneBuddy(swarm()), [shipped('dee', WEEK, WEEK + HOUR, { ledger: ledger('ended-session') })])
+ expect(of(view, 'ended-session')).toMatchObject({ displayName: 'Former Buddy', personId: null, machineId: '', shipped: 1 })
+ })
+
+ it('shows only a Former Buddy, with no name, person or Mac, in a private project its person does not read', () => {
+ const state = oneBuddy(swarm())
+ state.projects![0] = { ...state.projects![0]!, visibility: 'private', members: [{ id: 'tony', generation: 'g' }] }
+ const view = board(state, [shipped('tony', WEEK, WEEK + HOUR, { ledger: ledger('main') })])
+ expect(buddies(view).map(a => [a.agentId, a.displayName, a.personId, a.machineId])).toEqual([['main', 'Former Buddy', null, '']])
+ expect(JSON.stringify(view)).not.toMatch(/Sparky|mac-dee/)
+ })
+
+ it('shows a Buddy whose person left or was re-invited (another generation) as Former Buddy', () => {
+ const state = oneBuddy(swarm())
+ state.people.find(p => p.id === 'dee')!.generation = 'g2'
+ const view = board(state, [shipped('tony', WEEK, WEEK + HOUR, { ledger: ledger('main') })])
+ expect(buddies(view).map(a => [a.agentId, a.displayName, a.personId])).toEqual([['main', 'Former Buddy', null]])
+ })
+
+ it('names its Mac only when the reader sees that Mac', () => {
+ const view = board(oneBuddy(swarm()), [], WEEK, NOW, [])
+ expect(buddies(view).map(a => [a.displayName, a.machineId])).toEqual([['Sparky', '']])
+ })
+
+ it('does not list another project\'s old-style Buddy, nor one with the same name elsewhere', () => {
+ const state = oneBuddy(swarm())
+ const base = state.agents.find(a => a.id === 'river')!
+ state.agents.push({ ...base, id: 'web-buddy', name: 'web-buddy', displayName: 'Sparky', projectId: 'web', buddyOf: { personId: 'tony', generation: 'g' } })
+ expect(buddies(board(state, [])).map(a => a.agentId)).toEqual(['main'])
+ })
+ })
})
describe('Models, last 7 days: each model\'s tasks over a rolling week, for the sidebar (Dee, 2026-10-30)', () => {
diff --git a/backend/src/superTabs/leaderboard/stats.ts b/backend/src/superTabs/leaderboard/stats.ts
index be1b058b4..d5dc7ac0f 100644
--- a/backend/src/superTabs/leaderboard/stats.ts
+++ b/backend/src/superTabs/leaderboard/stats.ts
@@ -5,8 +5,8 @@
* left out here too.
*/
import type { ContributedMachine } from '../machines.js'
-import { isLeads, type Conversation, type SuperTabState } from '../model.js'
-import { isBuddy } from '../buddies.js'
+import { isLeads, type Agent, type Conversation, type SuperTabState } from '../model.js'
+import { isBuddy, isSwarmBuddy } from '../buddies.js'
import { agentProjectId, canReadProject, projectOf } from '../projects.js'
import { firstAssignedAt, waitedOn, waitsNow, type RanOn, type Unblock } from './record.js'
import { DAY_MS, WEEK_MS } from './week.js'
@@ -98,7 +98,7 @@ export function leaderboard({ state, groups, machines: visibleMachines, projectI
people,
waiting: waitingNow(state, shared),
models: { thisWeek: modelShare(requests, week), lastWeek: modelShare(requests, week - WEEK_MS) },
- agents: agentScores(state, projectId, shippedRequests.filter(g => inWeek(g.ledger!.shippedAt!))),
+ agents: agentScores(state, projectId, shippedRequests.filter(g => inWeek(g.ledger!.shippedAt!)), visibleMachines),
byModel: modelScores(requests, shippedRequests.filter(g => inWeek(g.ledger!.shippedAt!)), inWeek),
recentModels: recentModels(requests, now),
}
@@ -126,11 +126,27 @@ function recentModels(requests: Conversation[], now: number): RecentModel[] {
* Buddy by the groups opened from its proposals. One credited this week stays listed after it was removed or replaced,
* as "Former PM" or "Former Buddy" once the Swarm no longer has it (full review of #2097). Builders and Reviewers are
* counted by model instead (modelScores). */
-function agentScores(state: SuperTabState, projectId: string, shippedThisWeek: Conversation[]): AgentScore[] {
+function agentScores(state: SuperTabState, projectId: string, shippedThisWeek: Conversation[], visibleMachines: readonly ContributedMachine[]): AgentScore[] {
+ const project = projectOf(state, projectId)
+ // A person's one Buddy belongs to no project (Dee, 10-31): it is listed in each project its person reads, and in none else,
+ // so a private project never shows a Buddy, name or Mac of someone outside it. Its sessions are never rows of their own.
+ const listedHere = (a: Agent): boolean => {
+ if (!isBuddy(a) || a.buddySession) return false
+ if (!isSwarmBuddy(a)) return agentProjectId(state, a) === projectId
+ const owner = state.people.find(p => p.id === a.buddyOf!.personId && p.generation === a.buddyOf!.generation)
+ return !!owner && canReadProject(state, { kind: 'person', userId: owner.id, email: owner.email }, project)
+ }
+ // A proposal recorded before the credit moved to the one Buddy names its session: the person's one Buddy earns it.
+ const creditee = (agentId: string): string => {
+ const a = state.agents.find(agent => agent.id === agentId)
+ if (!a?.buddySession || !a.buddyOf) return agentId
+ return state.agents.find(m => isSwarmBuddy(m) && !m.buddySession && listedHere(m)
+ && m.buddyOf!.personId === a.buddyOf!.personId && m.buddyOf!.generation === a.buddyOf!.generation)?.id ?? agentId
+ }
const pmId = state.conversations.find(c => c.id === projectOf(state, projectId).leadConversationId)?.leadId
const shipped = new Map<string, { kind: 'pm' | 'buddy'; count: number }>()
for (const a of state.agents) {
- if (a.id === pmId || (isBuddy(a) && agentProjectId(state, a) === projectId)) shipped.set(a.id, { kind: isBuddy(a) ? 'buddy' : 'pm', count: 0 })
+ if (a.id === pmId || listedHere(a)) shipped.set(a.id, { kind: isBuddy(a) ? 'buddy' : 'pm', count: 0 })
}
const credit = (agentId: string, kind: 'pm' | 'buddy') => {
const entry = shipped.get(agentId) ?? { kind, count: 0 }
@@ -141,14 +157,16 @@ function agentScores(state: SuperTabState, projectId: string, shippedThisWeek: C
// The lead recorded when it shipped; a request shipped before that was recorded, its lead now.
const ledBy = g.ledger?.shippedLeadId !== undefined ? g.ledger.shippedLeadId : g.leadId
if (ledBy) credit(ledBy, 'pm')
- if (g.ledger?.proposal) credit(g.ledger.proposal.buddyId, 'buddy')
+ if (g.ledger?.proposal) credit(creditee(g.ledger.proposal.buddyId), 'buddy')
}
const scored = [...shipped].map(([agentId, { kind, count }]) => {
// Who it is now only while it is this project's: an agent id stays the same when its terminal is added again
// elsewhere, and a private project's names and owners are not this board's to show (review of #2128).
- const a = state.agents.find(agent => agent.id === agentId && agentProjectId(state, agent) === projectId)
+ const a = state.agents.find(agent => agent.id === agentId && (listedHere(agent) || (!isBuddy(agent) && agentProjectId(state, agent) === projectId)))
+ // Its Mac only to a reader who sees that Mac: the one Buddy's is its person's, not the project's.
+ const machineId = a && (!isSwarmBuddy(a) || visibleMachines.some(m => m.machineId === a.machineId)) ? a.machineId : ''
return { agentId, displayName: a ? a.displayName ?? a.name : kind === 'pm' ? 'Former PM' : 'Former Buddy', kind,
- personId: a?.buddyOf?.personId ?? null, machineId: a?.machineId ?? '', points: count * SHIPPED_POINTS, shipped: count }
+ personId: a?.buddyOf?.personId ?? null, machineId, points: count * SHIPPED_POINTS, shipped: count }
}).sort((a, b) => b.points - a.points || (a.kind === b.kind ? a.displayName.localeCompare(b.displayName) : a.kind === 'pm' ? -1 : 1))
return scored.map(entry => ({ ...entry, rank: 1 + scored.filter(other => other.points > entry.points).length }))
}