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
Super Tab backend: Leads conversation, other projects' work and overlap alerts (#1645)
0xken15ca94e66b4376
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex 6b2430e8d..03e754061 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -388,7 +388,7 @@ describe('deleting abandoned swarm projects', () => {expect(await run(tab, command, owner, undefined, deleteId)).toEqual(response.json().data)const state = (await store.read(owner, tab)).stateexpect(state.projects!.map(p => p.id)).toEqual(['lead'])- expect(state.conversations.map(c => c.id)).toEqual(['lead'])+ expect(state.conversations.map(c => c.id)).toEqual(['lead', state.leadsConversationId])// An invitation is to the Swarm: it moves to the project that is left rather than disappearing.expect(state.invitations.map(i => [i.email, i.conversationId])).toEqual([['[email protected]', 'lead']])for (const id of [conversationId, group]) {@@ -409,7 +409,8 @@ describe('deleting abandoned swarm projects', () => {await run(tab, { type: 'project.delete', projectId: 'lead' })const empty = (await store.read(owner, tab)).stateexpect(empty.projects).toEqual([])- expect(empty.conversations).toEqual([])+ // Only the Swarm-wide Leads conversation is left.+ expect(empty.conversations.map(c => c.kind)).toEqual(['leads'])expect(empty.agents).toEqual([])expect(empty.people).toHaveLength(1)const projectId = String((await run(tab, { type: 'project.create', name: 'Fresh project', visibility: 'public', brief: '' })).result.projectId)@@ -1722,7 +1723,7 @@ it('allocates workgroup numbers transactionally and replays the same number afteconst results = await Promise.all(operations.map(id => run(tab, command, owner, undefined, id)))expect(results.map(r => r.result.number).sort()).toEqual([1, 2, 3])expect((await run(tab, command, owner, undefined, operations[0])).result).toEqual(results[0]!.result)- expect((await store.read(owner, tab)).state.conversations.map(c => c.number)).toEqual([undefined, 1, 2, 3])+ expect((await store.read(owner, tab)).state.conversations.map(c => c.number)).toEqual([undefined, 1, 2, 3, undefined])})describe('Super Tab chat attachments', () => {@@ -2203,3 +2204,66 @@ describe('the Lead reads and types in an agent terminal', () => {expect(answer.json().data).toEqual({ requestId, ok: false, error: 'The pane closed.' })})})++describe('Leads conversation', () => {+ it('appears in an old Swarm, lets people and Leads post, and delivers only to the other Leads', async () => {+ const { tab, lead } = await fixture()+ // A Swarm stored before the Leads conversation existed.+ const row = await db.superTab.findUniqueOrThrow({ where: { id: tab } })+ const stored = row.state as unknown as { leadsConversationId?: string; conversations: Array<{ kind?: string }> }+ const leads = stored.leadsConversationId!+ delete stored.leadsConversationId+ stored.conversations = stored.conversations.filter(c => c.kind !== 'leads')+ await db.superTab.update({ where: { id: tab }, data: { state: stored as never } })+ // Clients find it without a project: by the tab's id for it and its kind.+ const read = (await store.read(owner, tab)).state+ expect(read.leadsConversationId).toBe(leads)+ const found = read.conversations.find(c => c.id === leads)!+ expect(found.kind).toBe('leads')+ expect(found).not.toHaveProperty('projectId')+ expect((await store.messages(owner, tab, leads, {})).messages).toEqual([])++ const docs = String((await run(tab, { type: 'project.create', name: 'Docs', visibility: 'public', brief: '' })).result.conversationId)+ const docsLead = (await run(tab, { type: 'agent.add', conversationId: docs, machineId: 'test-host', harnessId: randomUUID(), name: 'Docs Lead',+ configuration: config, lead: true })).result.agentId as string+ const worker = (await run(tab, { type: 'agent.add', conversationId: 'lead', machineId: 'test-host', harnessId: randomUUID(), name: 'Worker',+ configuration: config, lead: false })).result.agentId as string+ const post = (text: string, user = owner, asAgentId?: string) => store.execute(user, tab, { operationId: randomUUID(),+ command: { type: 'message.send', conversationId: leads, text, replyTo: null, recipientIds: [] } }, asAgentId)+ await post('Who goes first?')+ const waiting = async (agentId: string) => (await store.deliveries(host, tab, agentId)).filter(d => d.conversationId === leads).length+ expect([await waiting(lead), await waiting(docsLead), await waiting(worker)]).toEqual([1, 1, 0])+ await post('Pilot goes first.', host, lead)+ expect([await waiting(lead), await waiting(docsLead)]).toEqual([1, 2])+ await expect(post('Me too', host, worker)).rejects.toMatchObject({ code: 'NOT_FOUND' })+ await expect(store.messages(host, tab, leads, {}, worker)).rejects.toMatchObject({ code: 'NOT_FOUND' })+ expect((await store.messages(owner, tab, leads, {})).messages.map(m => m.text)).toEqual(['Who goes first?', 'Pilot goes first.'])+ })++ it('shows Leads the other projects\' work and posts one overlap alert for both Leads', async () => {+ const { tab, lead } = await fixture()+ const docs = String((await run(tab, { type: 'project.create', name: 'Docs', visibility: 'public', brief: '' })).result.projectId)+ const docsChat = (await store.read(owner, tab)).state.projects!.find(p => p.id === docs)!.leadConversationId+ const docsLead = (await run(tab, { type: 'agent.add', conversationId: docsChat, machineId: 'test-host', harnessId: randomUUID(), name: 'Docs Lead',+ configuration: config, lead: true })).result.agentId as string+ const task = (owns: string[]) => ({ goal: 'Polish', changes: 'Roster', constraints: 'None', owns })+ const checks = [{ description: 'Done', independent: false }]+ const roster = String((await run(tab, { type: 'conversation.create', projectId: docs, title: 'Roster', task: task(['desktop/lib/super_tabs']), checks })).result.conversationId)+ const worker = (await run(tab, { type: 'agent.add', conversationId: roster, machineId: 'test-host', harnessId: randomUUID(), name: 'Docs Worker',+ configuration: config, lead: false })).result.agentId as string+ await run(tab, { type: 'work.assign', conversationId: roster, agentId: worker })++ expect((await store.read(host, tab, lead)).state.otherProjectsWork).toEqual([expect.objectContaining({ conversationId: roster, projectName: 'Docs',+ title: 'Roster', owns: ['desktop/lib/super_tabs'], status: 'working' })])+ expect((await store.read(host, tab, worker)).state).not.toHaveProperty('otherProjectsWork')++ const filter = String((await run(tab, { type: 'conversation.create', title: 'Agents filter', task: task(['desktop/lib/super_tabs/roster.dart']), checks },+ host, lead)).result.conversationId)+ await run(tab, { type: 'work.define', conversationId: filter, task: task(['desktop/lib/super_tabs']), checks }, host, lead)+ const leads = (await store.read(owner, tab)).state.leadsConversationId!+ const alerts = (await store.messages(owner, tab, leads, {})).messages+ expect(alerts).toEqual([expect.objectContaining({ source: { kind: 'overlap', conversationIds: [filter, roster] }, recipientIds: [docsLead],+ text: expect.stringContaining('"Agents filter" (Pilot') })])+ expect((await store.deliveries(host, tab, docsLead)).filter(d => d.conversationId === leads)).toHaveLength(1)+ })+})diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 46d490079..64ade471c 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -200,11 +200,11 @@ describe('Super Tab collaboration policy', () => {const lead = f.add('lead', 'owner', 'lead', true)const group = f.group()const worker = f.add('worker', 'owner', group)- expect(f.state.conversations.map(c => c.title)).toEqual(['Lead', 'Offline editing'])+ expect(f.state.conversations.map(c => c.title)).toEqual(['Lead', 'Offline editing', 'Leads'])expect(f.state.conversations[1]).toMatchObject({ leadId: lead, agentIds: [lead, worker], assignment: null })f.run({ type: 'conversation.agent', conversationId: 'lead', agentId: worker, present: true, lead: false })expect(f.state.agents).toHaveLength(2)- expect(f.state.conversations).toHaveLength(2)+ expect(f.state.conversations).toHaveLength(3) // Lead, the group and Leads})it('routes a human reply to its author, and does not create agent chatter loops', () => {@@ -463,7 +463,7 @@ it('starts only in the chosen conversation, captures authority, and never assignconst startId = f.run({ type: 'agent.start', request, ...via }, actor, { contribution, ...decisionIn(group) }).result.startId as stringexpect(f.state.starts![0]).toMatchObject({ request, hostGrant: 'grant-1', dispatched: false })expect(f.state.agents).toHaveLength(1)- expect(f.state.conversations).toHaveLength(2)+ expect(f.state.conversations).toHaveLength(3) // Lead, the group and Leadsexpect(() => f.run({ type: 'agent.startDispatch', startId }, actor, { contribution: { ...contribution, hostGrant: 'new-grant' } })).toThrow('revoked')f.run({ type: 'agent.startDispatch', startId }, actor, { contribution })expect(() => f.run({ type: 'agent.startDispatch', startId }, actor, { contribution })).toThrow('already requested')@@ -800,15 +800,16 @@ describe('agents route before they start or assign', () => {it('assigns stable workgroup numbers through old snapshots, rename, archive and new groups', () => {const f = fixture(), first = f.group(), second = f.group()- expect(f.state.conversations.map(c => c.number)).toEqual([undefined, 1, 2])+ // The Lead and Leads conversations have no number.+ expect(f.state.conversations.map(c => c.number)).toEqual([undefined, 1, 2, undefined])delete f.state.conversations[1]!.numberdelete f.state.conversations[2]!.number- expect(visibleState(f.state, owner).conversations.map(c => c.number)).toEqual([undefined, 1, 2])+ expect(visibleState(f.state, owner).conversations.map(c => c.number)).toEqual([undefined, 1, 2, undefined])expect(f.state.conversations[1]!.number).toBeUndefined()f.run({ type: 'conversation.rename', conversationId: first, title: 'Renamed' })f.run({ type: 'conversation.archive', conversationId: second, archived: true })const third = f.group()- expect(f.state.conversations.map(c => [c.id, c.number])).toEqual([['lead', undefined], [first, 1], [second, 2], [third, 3]])+ expect(f.state.conversations.map(c => [c.id, c.number])).toEqual([['lead', undefined], [first, 1], [second, 2], [third, 3], [f.state.leadsConversationId, undefined]])})it('records the lead project once and accepts only Claude Code and Codex contributions', () => {const f = fixture(), project = { cwd: '/repo', repositoryUrl: 'https://github.com/example/project' }@@ -1676,3 +1677,136 @@ describe('Lead protection', () => {expect(f.state.closingSessions).toBeUndefined()})})++describe('Leads conversation', () => {+ const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })+ const send = (conversationId: string, text: string, recipientIds: string[] = []): Command =>+ ({ type: 'message.send', conversationId, text, replyTo: null, recipientIds })+ const swarm = () => {+ const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), worker = f.add('worker')+ const docs = f.run({ type: 'project.create', name: 'Docs', visibility: 'public', brief: 'Docs' }).result as { projectId: string; conversationId: string }+ const docsLead = f.add('docs-lead', 'owner', docs.conversationId, true)+ return { f, lead, worker, docs, docsLead, leads: f.state.leadsConversationId! }+ }++ it('gives every Swarm one, an old one too, outside every project', () => {+ const f = fixture(), id = f.state.leadsConversationId!+ expect(f.state.conversations.find(c => c.id === id)).toMatchObject({ kind: 'leads', title: 'Leads', archived: false, leadId: null })+ expect(f.state.conversations.find(c => c.id === id)).not.toHaveProperty('number')++ const old = fixture()+ delete old.state.leadsConversationId+ old.state.conversations = old.state.conversations.filter(c => c.id !== id)+ expect(visibleState(old.state, owner).leadsConversationId).toBe(id)+ old.run({ type: 'tab.rename', name: 'Renamed' })+ expect(old.state.leadsConversationId).toBe(id)+ expect(old.state.conversations.filter(c => c.kind === 'leads')).toHaveLength(1)+ })++ it('lets people and Leads post, delivers to every other Lead, and keeps it from other agents', () => {+ const { f, lead, worker, docsLead, leads } = swarm()+ expect(f.run(send(leads, 'Who goes first?')).messages[0]!.recipients.sort()).toEqual([lead, docsLead].sort())+ expect(f.run(send(leads, 'Docs waits for Pilot.'), as(docsLead)).messages[0]!.recipients).toEqual([lead])+ // Naming a Lead adds emphasis; every other Lead still hears it.+ expect(f.run(send(leads, 'Pilot, can you go first?', [lead])).messages[0]!.recipients.sort()).toEqual([lead, docsLead].sort())+ expect(() => f.run(send(leads, 'Me too'), as(worker))).toThrow(expect.objectContaining({ code: 'NOT_FOUND' }))+ expect(() => f.run(send(leads, 'Hi', [worker]))).toThrow()+ expect(visibleState(f.state, as(lead)).conversations.map(c => c.id)).toContain(leads)+ const workerView = visibleState(f.state, as(worker))+ expect(workerView.conversations.map(c => c.id)).not.toContain(leads)+ expect(workerView).not.toHaveProperty('leadsConversationId')++ f.invite('viewer')+ expect(visibleState(f.state, peer).conversations.map(c => c.id)).toContain(leads)+ expect(() => f.run(send(leads, 'Viewer here'), peer)).toThrow(expect.objectContaining({ code: 'READ_ONLY' }))+ })++ it('takes no work, members or archiving, and outlives every project', () => {+ const { f, worker, docs, leads } = swarm()+ const checks = [{ description: 'Done', independent: false }]+ for (const command of [+ { type: 'conversation.archive', conversationId: leads, archived: true },+ { type: 'conversation.rename', conversationId: leads, title: 'Chat' },+ { type: 'work.define', conversationId: leads, brief: 'Work', checks },+ { type: 'conversation.agent', conversationId: leads, agentId: worker, present: true, lead: false },+ { type: 'conversation.create', title: 'Review', reviewOf: leads, brief: 'Review', checks },+ ] as Command[]) expect(() => f.run(command)).toThrow(expect.objectContaining({ code: 'LEADS_CONVERSATION' }))+ f.run({ type: 'project.delete', projectId: docs.projectId })+ expect(f.state.conversations.some(c => c.id === leads)).toBe(true)+ })+})++describe('other projects\' work for Leads', () => {+ const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })+ const checks = [{ description: 'Done', independent: false }]+ const task = (owns: string[]) => ({ goal: 'Polish', changes: 'The roster', constraints: 'None', owns })+ const swarm = () => {+ const f = fixture(), lead = f.add('lead', 'owner', 'lead', true)+ const project = (name: string, visibility: 'public' | 'private') => {+ const created = f.run({ type: 'project.create', name, visibility, brief: name }).result as { projectId: string; conversationId: string }+ return { ...created, lead: f.add(`${name}-lead`, 'owner', created.conversationId, true) }+ }+ /** A task in that project, assigned to a new worker. */+ const work = (projectId: string, title: string, owns: string[]) => {+ const group = f.run({ type: 'conversation.create', projectId, title, task: task(owns), checks }).result.conversationId as string+ const worker = f.add(`${title}-worker`, 'owner', group)+ const assignmentId = f.run({ type: 'work.assign', conversationId: group, agentId: worker }).result.assignmentId as string+ return { group, worker, assignmentId }+ }+ return { f, lead, project, work }+ }++ it('shows a Lead the active work of every other shared project, and nobody else', () => {+ const { f, lead, project, work } = swarm()+ const docs = project('Docs', 'public'), secret = project('Secret', 'private')+ const roster = work(docs.projectId, 'Roster', ['desktop/lib/super_tabs'])+ f.run({ type: 'work.status', conversationId: roster.group, assignmentId: roster.assignmentId, status: 'review',+ result: 'Ready: https://github.com/example/project/pull/12 head abc.' }, as(roster.worker))+ const finished = work(docs.projectId, 'Finished', ['docs'])+ f.run({ type: 'work.cancel', conversationId: finished.group, assignmentId: finished.assignmentId, reason: 'Not needed.' })+ work(secret.projectId, 'Hidden', ['backend'])+ const own = work('lead', 'Own', ['cli'])+ const workerName = f.state.agents.find(a => a.id === roster.worker)!.displayName++ expect(visibleState(f.state, as(lead)).otherProjectsWork).toEqual([{ conversationId: roster.group, projectName: 'Docs',+ title: 'Roster', owns: ['desktop/lib/super_tabs'], status: 'review', agentName: workerName, pr: 'https://github.com/example/project/pull/12' }])+ expect(visibleState(f.state, as(docs.lead)).otherProjectsWork).toEqual([expect.objectContaining({ conversationId: own.group,+ projectName: 'Pilot', status: 'working', pr: null })])+ expect(visibleState(f.state, as(roster.worker))).not.toHaveProperty('otherProjectsWork')+ expect(visibleState(f.state, owner)).not.toHaveProperty('otherProjectsWork')+ })++ it('tells both Leads once when a task\'s owned code overlaps another project\'s active task', () => {+ const { f, lead, project, work } = swarm()+ const docs = project('Docs', 'public')+ const roster = work(docs.projectId, 'Roster', ['desktop/lib/super_tabs'])+ const alerts = () => f.state.leadsConversationId+ const name = (id: string) => f.state.agents.find(a => a.id === id)!.displayName+ const created = f.run({ type: 'conversation.create', title: 'Agents filter', task: task([' ./desktop/lib/super_tabs/roster.dart ', 'cli']), checks }, as(lead))+ const group = created.result.conversationId as string+ const alert = created.messages.find(m => m.conversationId === alerts())!+ expect(alert).toMatchObject({ author: { id: lead }, recipients: [docs.lead],+ source: { kind: 'overlap', conversationIds: [group, roster.group] } })+ expect(alert.text).toBe(`"Agents filter" (Pilot, ${name(lead)}) and "Roster" (Docs, ${name(docs.lead)}) both change `+ + 'desktop/lib/super_tabs/roster.dart. Agree an order or a split here, then each tell your own project.')+ // The same pair is not alerted again.+ f.run({ type: 'work.define', conversationId: group, task: task(['desktop/lib/super_tabs/roster.dart']), checks }, as(lead))+ const worker = f.add('pilot-worker', 'owner', group)+ expect(f.run({ type: 'work.assign', conversationId: group, agentId: worker }).messages.some(m => m.conversationId === alerts())).toBe(false)+ expect(visibleState(f.state, owner)).not.toHaveProperty('overlapAlerts')+ })++ it('stays silent within one project, for owned code that is not a path, and for private projects', () => {+ const { f, project, work } = swarm()+ const secret = project('Secret', 'private'), docs = project('Docs', 'public')+ work('lead', 'Own', ['desktop/lib'])+ work(secret.projectId, 'Hidden', ['desktop/lib'])+ work(docs.projectId, 'Phrase', ['The Desktop roster'])+ for (const owns of [['desktop/lib/super_tabs'], ['The Desktop roster']]) {+ const effects = f.run({ type: 'conversation.create', title: 'More', task: task(owns), checks })+ expect(effects.messages.filter(m => m.conversationId === f.state.leadsConversationId)).toEqual([])+ }+ expect(f.run({ type: 'conversation.create', projectId: secret.projectId, title: 'Secret too', task: task(['desktop/lib']), checks })+ .messages.filter(m => m.conversationId === f.state.leadsConversationId)).toEqual([])+ })+})diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 648419464..616db44cf 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -2,7 +2,7 @@ import { admitMachineStart, machineContribution } from './machines.js'import { assignAgentDisplayNames } from './agentNames.js'import { z } from 'zod'import {- activeWork, actorKey, agent, agentRole, author, conversation, fail, person, stableId, numberConversations, nextConversationNumber, renderWorkTask,+ activeWork, actorKey, agent, agentRole, author, conversation, crossProjectActive, fail, isLeads, person, stableId, syncLeads, numberConversations, nextConversationNumber, renderWorkTask,finishWorker, requireWorkerDecisions, reviewing,type Actor, type Agent, type Author, type CommandEffects, type Conversation, type SuperTabState,} from './model.js'@@ -11,7 +11,7 @@ import { routingOverrideSchema } from './routingPolicy.js'import { agentTarget, askedInSchema, broken, MAX_RULES, RULE_MESSAGE_MS, ruleSchema, ruleTextSchema, startTarget, type RunTarget } from './rules.js'import { MAX_ATTACHMENTS, type Attachment } from './attachments.js'import { TERMINAL_KEYS, terminalAlert, terminalRequest, terminalResult, type TerminalRequest } from './terminal.js'-import { agentProjectId, deleteProject, groupProject, inviteLanding, ledProject, manageProject, mutableProjects, placeRules, projectMembers, projectOf, projectRules, readAgent, readConversation, readProject, sameProject, SKILL_MODE_NAMES, skillModeOf, type SwarmProject } from './projects.js'+import { agentProjectId, deleteProject, groupProject, inviteLanding, ledProject, manageProject, mutableProjects, placeRules, projectMembers, projectOf, projectRules, readAgent, readConversation, readProject, sameProject, sharedWithLeads, SKILL_MODE_NAMES, skillModeOf, type SwarmProject } from './projects.js'const id = z.string().min(1).max(160).regex(/^[A-Za-z0-9_-]+$/)const title = z.string().trim().min(1).max(160)@@ -181,6 +181,13 @@ function controls(state: SuperTabState, actor: Actor, conversationId = 'lead'):}}+/** The repo path an owns entry names, or null for anything else (a phrase, a glob), which is never compared. */+function ownedPath(entry: string): string | null {+ const path = entry.trim().replace(/^\.\//, '').replace(/\/+$/, '')+ return /^[\w.@-]+(\/[\w.@-]+)*$/.test(path) ? path : null+}+const pathsOverlap = (a: string, b: string) => a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`)+/** A project's Lead (Product Manager) leaves only with its project: every other removal path refuses it. */function protectLead(state: SuperTabState, agentId: string): void {const project = ledProject(state, agentId), target = state.agents.find(a => a.id === agentId)@@ -213,7 +220,10 @@ export function authorizeCommandAccess(state: SuperTabState, actor: Actor, commaconst leaving = command.type === 'member.remove' && actor.kind === 'person' && command.userId === actor.userIdauthor(state, actor, !leaving)// An invitation's group is only where the person lands, and invite.create replaces a deleted one (inviteLanding).- if ('conversationId' in command && command.type !== 'invite.create') readConversation(state, actor, command.conversationId)+ if ('conversationId' in command && command.type !== 'invite.create') {+ const group = readConversation(state, actor, command.conversationId)+ if (isLeads(group) && command.type !== 'message.send') groupProject(state, group)+ }if ('projectId' in command && command.projectId) readProject(state, actor, command.projectId)if ('agentId' in command) readAgent(state, actor, command.agentId)if (command.type === 'agent.start') readConversation(state, actor, command.request.conversationId)@@ -251,6 +261,7 @@ function open(state: SuperTabState, conversationId: string) {export function applyCommand(original: SuperTabState, actor: Actor, input: Command, context: CommandContext): CommandEffects {const command = commandSchema.parse(input)const state = structuredClone(original)+ syncLeads(state)numberConversations(state)placeRules(state)assignAgentDisplayNames(state.agents)@@ -372,6 +383,32 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma}}+ /** Projects in one Swarm changed the same code without knowing it (2026-10-23). When a task is created, defined or assigned,+ * its Leads hear once per pair of tasks that it owns code another shared project's active task owns too. */+ const alertOverlaps = (group: Conversation) => {+ const project = groupProject(state, group)+ const mine = (group.task?.owns ?? []).flatMap(entry => ownedPath(entry) ?? [])+ if (!mine.length || !sharedWithLeads(project)) return+ state.overlapAlerts = state.overlapAlerts?.filter(pair => pair.split(':').every(id => state.conversations.some(c => c.id === id)))+ const leadOf = (p: SwarmProject) => state.agents.find(a => a.id === conversation(state, p.leadConversationId).leadId)+ const named = (a: Agent | undefined) => a ? a.displayName ?? a.name : 'no Lead'+ for (const other of state.conversations.filter(crossProjectActive)) {+ const theirs = groupProject(state, other)+ if (theirs.id === project.id || !sharedWithLeads(theirs)) continue+ const owned = (other.task?.owns ?? []).flatMap(entry => ownedPath(entry) ?? [])+ const shared = mine.filter(a => owned.some(b => pathsOverlap(a, b)))+ const pair = [group.id, other.id].sort().join(':')+ if (!shared.length || state.overlapAlerts?.includes(pair)) continue+ (state.overlapAlerts ??= []).push(pair)+ const ours = leadOf(project), their = leadOf(theirs)+ effects.messages.push({ id: stableId(operationId, 'overlap', pair), conversationId: state.leadsConversationId!, author: sender,+ text: `"${group.title}" (${project.name}, ${named(ours)}) and "${other.title}" (${theirs.name}, ${named(their)}) both change `+ + `${shared.join(', ')}. Agree an order or a split here, then each tell your own project.`,+ replyTo: null, recipients: [ours, their].flatMap(a => a && !(actor.kind === 'agent' && a.id === actor.agentId) ? [a.id] : []),+ source: { kind: 'overlap', conversationIds: [group.id, other.id] } })+ }+ }+/** Changing or clearing the Lead of a project's Lead conversation would let it be stopped next. */const keepLead = (group: Conversation, next: string | null) => {if (group.leadId && group.leadId !== next && group.id === groupProject(state, group).leadConversationId) protectLead(state, group.leadId)@@ -981,7 +1018,10 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma&& group.leadId && group.leadId !== actor.agentId && group.agentIds.includes(group.leadId) ? group.leadId : nullconst agentRecipient = leadToWorker ?? workerToLeadconst automatic = actor.kind === 'person' ? (replyAgent && group.agentIds.includes(replyAgent) ? replyAgent : group.leadId) : agentRecipient- const recipients = [...new Set(command.recipientIds.length ? command.recipientIds : automatic ? [automatic] : [])]+ // In the Leads conversation everything posted reaches every other Lead; naming some only adds emphasis.+ const everyLead = isLeads(group) ? group.agentIds.filter(id => actor.kind !== 'agent' || id !== actor.agentId) : []+ const recipients = [...new Set([...command.recipientIds, ...everyLead,+ ...(command.recipientIds.length || everyLead.length || !automatic ? [] : [automatic])])]for (const id of recipients) {agent(state, id)if (!group.agentIds.includes(id)) fail('INVALID_RECIPIENT', 'Choose an agent in this conversation.', 400)@@ -1186,11 +1226,15 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commabreak}}+ if (command.type === 'conversation.create' || command.type === 'work.define' || command.type === 'work.assign') {+ alertOverlaps(conversation(state, command.type === 'conversation.create' ? result.conversationId as string : command.conversationId))+ }for (const target of original.agents.filter(a => a.workDecision === 'stop')) {const acknowledged = command.type === 'agent.remove' && command.agentId === target.id &&(actor.kind === 'agent' && actor.agentId === target.id || actor.kind === 'person' && [state.ownerId, target.contributorId].includes(actor.userId))if (!acknowledged && !state.agents.some(a => a.id === target.id)) fail('STOP_REQUESTED', 'Wait for the execution host to finish stopping its workers before withdrawing them.')}+ syncLeads(state)// MongoDB limits a document to 16 MiB. Leave room for indexes and metadata, and refuse before losing state.assignAgentDisplayNames(state.agents)if (Buffer.byteLength(JSON.stringify(state)) > 8 * 1024 * 1024) fail('TAB_TOO_LARGE', 'This Super Tab has reached its metadata limit.', 413)diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.tsindex 4a21b38b8..dc388297e 100644--- a/backend/src/superTabs/model.ts+++ b/backend/src/superTabs/model.ts@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto'import type { RouteDecisionEffect } from './routeRecord.js'import { agentDisplayName, assignAgentDisplayNames } from './agentNames.js'import { downSince } from './machines.js'-import { canReadAgent, canReadProject, groupProject, placeRules, projectsOf, type ProjectVisibility, type SwarmProject } from './projects.js'+import { canReadAgent, canReadProject, groupProject, ledProject, placeRules, projectsOf, sharedWithLeads, type ProjectVisibility, type SwarmProject } from './projects.js'export type Role = 'owner' | 'collaborator' | 'viewer'export interface Person { id: string; email: string; role: Role; generation: string }@@ -114,6 +114,8 @@ export function renderWorkTask(task: WorkTask): string {export interface Conversation {id: string+ /** The Swarm-wide Leads conversation (syncLeads); absent on every project conversation. */+ kind?: 'leads'projectId?: string/** Stable, tab-local workgroup reference. Lead has no number. */number?: number@@ -142,6 +144,12 @@ export interface SuperTabState {name: stringproject?: { machineId: string; cwd: string; repositoryUrl: string | null }projects?: SwarmProject[]+ /** The Leads conversation, outside every project (syncLeads). */+ leadsConversationId?: string+ /** Pairs of tasks ("a:b", sorted ids) whose Leads were told their owned code overlaps, so each pair is told once. */+ overlapAlerts?: string[]+ /** Read-only, for a Lead's own reads (visibleState): the active work of the other projects it may know about. */+ otherProjectsWork?: OtherProjectWork[]ownerId: stringenvironment: string/** Fields this tab overrides from its owner's account routing policy (routingPolicy.ts). */@@ -166,6 +174,16 @@ export interface SuperTabState {/** Sessions of removed agents their host closes, listed to that host until it says they closed (agent.sessionClosed). */closingSessions?: Array<{ agentId: string; machineId: string; harnessId: string; machineOwnerId: string }>}+export interface OtherProjectWork {+ conversationId: string+ projectName: string+ title: string+ owns: string[]+ status: WorkStatus+ agentName: string+ /** The first pull request link in the assignment's result, when its agent reported one. */+ pr: string | null+}export type Actor =| { kind: 'person'; userId: string; email: string }| { kind: 'agent'; agentId: string; machineOwnerId: string }@@ -248,13 +266,40 @@ export function conversation(state: SuperTabState, id: string): Conversation {return state.conversations.find(c => c.id === id) ?? fail('NOT_FOUND', 'This conversation is unavailable.', 404)}+export const isLeads = (group: Conversation): boolean => group.kind === 'leads'++/** Work a Lead of another project should know about: assigned and moving, not finished, stuck or archived. */+export const crossProjectActive = (group: Conversation): boolean => !group.archived && !isLeads(group)+ && ['working', 'review', 'needs_human'].includes(group.assignment?.status ?? '')++function otherProjectsWork(state: SuperTabState, own: SwarmProject): OtherProjectWork[] {+ return state.conversations.filter(crossProjectActive).flatMap(group => {+ const project = groupProject(state, group), assignment = group.assignment!+ if (project.id === own.id || !sharedWithLeads(project)) return []+ const worker = state.agents.find(a => a.id === assignment.agentId)+ return [{ conversationId: group.id, projectName: project.name, title: group.title, owns: group.task?.owns ?? [], status: assignment.status,+ agentName: worker ? worker.displayName ?? worker.name : '', pr: assignment.result?.match(/https:\/\/github\.com\/[^\s/]+\/[^\s/]+\/pull\/\d+/)?.[0] ?? null }]+ })+}++/** The Swarm-wide conversation where Leads agree an order across projects and every person reads along. It belongs to no+ * project and stays after the project conversations; an older Swarm gets it on its next read or write. Its members are+ * always the projects' current Leads, so only they receive what is posted there. */+export function syncLeads(state: SuperTabState): void {+ const id = state.leadsConversationId ??= stableId(state.id, 'leads')+ const group = state.conversations.find(c => c.id === id) ?? { id, kind: 'leads', title: 'Leads', leadId: null, agentIds: [],+ archived: false, brief: '', checks: [], assignment: null, lastMessageSequence: 0 }+ state.conversations = [...state.conversations.filter(c => c !== group), group]+ group.agentIds = state.agents.filter(a => ledProject(state, a.id)).map(a => a.id)+}+/** Legacy groups keep their append order, including archived groups. Persisted* numbers are never reassigned; the store serializes concurrent additions. */export function numberConversations(state: SuperTabState): void {let next = nextConversationNumber(state)const leads = new Set(projectsOf(state).map(p => p.leadConversationId))for (const group of state.conversations) {- if (!leads.has(group.id) && group.number == null) group.number = next+++ if (!leads.has(group.id) && !isLeads(group) && group.number == null) group.number = next++}}export function nextConversationNumber(state: SuperTabState): number {@@ -281,6 +326,7 @@ export function createSuperTab(id: string, name: string, owner: { id: string; em}// A new Swarm's first project starts in Default; only a project from before skill modes reads as Harness orchestration.state.projects = [{ ...projectsOf(state)[0]!, ...(visibility ? { visibility } : {}), skillMode: 'default' }]+ syncLeads(state)return state}@@ -288,7 +334,15 @@ export function createSuperTab(id: string, name: string, owner: { id: string; emexport function visibleState(state: SuperTabState, actor: Actor, now = Date.now()): SuperTabState {author(state, actor)const visible = structuredClone(state)+ syncLeads(visible)+ // People and Leads read the Leads conversation; it is not there for any other agent.+ if (actor.kind === 'agent' && !ledProject(visible, actor.agentId)) {+ visible.conversations = visible.conversations.filter(c => !isLeads(c))+ delete visible.leadsConversationId+ }assignAgentDisplayNames(visible.agents)+ const led = actor.kind === 'agent' ? ledProject(visible, actor.agentId) : undefined+ if (led) visible.otherProjectsWork = otherProjectsWork(visible, led)for (const target of visible.agents) {const since = downSince(state, target, now)if (since) target.downSince = since@@ -298,6 +352,7 @@ export function visibleState(state: SuperTabState, actor: Actor, now = Date.now(delete visible.sharingdelete visible.harnessReservationsdelete visible.releasedHarnesses+ delete visible.overlapAlerts// Only that machine's host roster lists them (store.ts hostTabs); a removed private agent's session is not every member's.delete visible.closingSessionsnumberConversations(visible)@@ -306,8 +361,9 @@ export function visibleState(state: SuperTabState, actor: Actor, now = Date.now(if (visible.rules) visible.rules = visible.rules.filter(r => projectsOf(state).some(p => p.id === r.projectId && canReadProject(state, actor, p)))if (visible.projects) {visible.projects = visible.projects.filter(p => canReadProject(state, actor, p))- visible.conversations = visible.conversations.filter(c => canReadProject(state, actor, groupProject(state, c)))+ visible.conversations = visible.conversations.filter(c => isLeads(c) || canReadProject(state, actor, groupProject(state, c)))visible.agents = visible.agents.filter(a => canReadAgent(state, actor, a))+ for (const group of visible.conversations.filter(isLeads)) group.agentIds = group.agentIds.filter(id => visible.agents.some(a => a.id === id))visible.starts = visible.starts?.filter(s => visible.conversations.some(c => c.id === s.request.conversationId))if (!visible.projects.some(p => p.id === 'lead')) {delete visible.projectdiff --git a/backend/src/superTabs/native.ts b/backend/src/superTabs/native.tsindex 1b999e5ba..6d4bf0b45 100644--- a/backend/src/superTabs/native.ts+++ b/backend/src/superTabs/native.ts@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto'import type { Prisma, SuperTab, SuperTabNativeContext } from '@prisma/client'import { z } from 'zod'import type { AuthUser } from '../lib/ssoAuth.js'-import { activeWork, agent, author, conversation, fail, stableId, SuperTabError,+import { activeWork, agent, author, conversation, fail, isLeads, stableId, SuperTabError,type Actor, type Agent, type Author, type Conversation, type SuperTabState } from './model.js'import { canReadProject, groupProject, readConversation } from './projects.js'import { noteProjectReports } from './projectUpdates.js'@@ -80,6 +80,7 @@ export class SuperTabNativeStore {const operator = author(state, { kind: 'person', userId: user.sub, email: user.email }, true)const target = agent(state, request.agentId)const group = readConversation(state, { kind: 'person', userId: user.sub, email: user.email }, request.conversationId)+ groupProject(state, group) // A terminal opens only in a project's conversation, never in the Leads conversation.if (group.archived || !group.agentIds.includes(target.id)) fail('AGENT_UNAVAILABLE', 'Choose an agent in this conversation.')await this.deps.agentGrant(tx, state, target)const grant = await this.deps.contribution(tx, state, { kind: 'person', userId: user.sub, email: user.email }, target)@@ -224,7 +225,8 @@ export async function revokeNativeContexts(tx: Transaction, before: SuperTabStatfor (const group of before.conversations) {const current = after.conversations.find(c => c.id === group.id)if (!current || current.archived) conditions.push({ conversationId: group.id })- else {+ // No terminal opens in the Leads conversation (open), so it holds no context to revoke.+ else if (!isLeads(current)) {for (const member of after.people) {if (!canReadProject(after, { kind: 'person', userId: member.id, email: member.email }, groupProject(after, current))) {conditions.push({ conversationId: group.id, userId: member.id })diff --git a/backend/src/superTabs/projectUpdates.ts b/backend/src/superTabs/projectUpdates.tsindex ceea06fb3..e68c0c741 100644--- a/backend/src/superTabs/projectUpdates.ts+++ b/backend/src/superTabs/projectUpdates.ts@@ -1,4 +1,4 @@-import { activeWork, author, conversation, stableId, type Agent, type MessageDraft, type SuperTabState } from './model.js'+import { activeWork, author, conversation, isLeads, stableId, type Agent, type MessageDraft, type SuperTabState } from './model.js'import { downSince } from './machines.js'import { agentProjectId, groupProject, projectOf } from './projects.js'@@ -7,7 +7,9 @@ import { agentProjectId, groupProject, projectOf } from './projects.js'export function noteProjectReports(state: SuperTabState, messages: MessageDraft[], revision: number, now: number) {if (!state.projects) returnfor (const message of messages) {- const group = conversation(state, message.conversationId), project = groupProject(state, group)+ const group = conversation(state, message.conversationId)+ if (isLeads(group)) continue+ const project = groupProject(state, group)if (group.id === project.leadConversationId) continueproject.progress ??= { dirtyRevision: revision, summarizedRevision: 0, requestedRevision: 0, since: now }if (project.progress.dirtyRevision <= project.progress.summarizedRevision) project.progress.since = nowdiff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.tsindex 8c9fd0501..2a6acf770 100644--- a/backend/src/superTabs/projects.test.ts+++ b/backend/src/superTabs/projects.test.ts@@ -31,7 +31,7 @@ describe('projects inside an invite-only swarm', () => {const original = f.run({ type: 'conversation.create', title: 'First', brief: '', checks: [] })const p = f.project()const next = f.run({ type: 'conversation.create', projectId: p.projectId, title: 'Second', brief: '', checks: [] })- expect(f.state.conversations.map(c => c.number)).toEqual([undefined, 1, undefined, 2])+ expect(f.state.conversations.map(c => c.number)).toEqual([undefined, 1, undefined, 2, undefined])expect(f.state.conversations.map(c => c.id)).toContain(original.conversationId)expect(next.number).toBe(2)expect(() => f.run({ type: 'conversation.archive', conversationId: p.conversationId, archived: true })).toThrow('stays available')@@ -42,7 +42,7 @@ describe('projects inside an invite-only swarm', () => {const id = f.add(p.conversationId, 'private-lead')const visible = visibleState(f.state, peer)expect(visible.projects!.map(p => p.id)).toEqual(['lead'])- expect(visible.conversations.map(c => c.id)).toEqual(['lead'])+ expect(visible.conversations.map(c => c.id)).toEqual(['lead', f.state.leadsConversationId])expect(visible.agents).toEqual([])expect(canReadAgent(f.state, peer, f.state.agents[0]!)).toBe(false)expect(() => readConversation(f.state, peer, p.conversationId)).toThrow('unavailable')@@ -95,7 +95,8 @@ describe('projects inside an invite-only swarm', () => {f.run({ type: 'invite.create', email: '[email protected]', role: 'collaborator', conversationId: 'lead' })expect(f.run({ type: 'project.delete', projectId: 'lead' })).toEqual({})expect(projectsOf(f.state)).toEqual([])- expect(f.state.conversations).toEqual([])+ // Only the Swarm-wide Leads conversation is left.+ expect(f.state.conversations.map(c => c.kind)).toEqual(['leads'])expect(f.state.invitations).toEqual([])expect(f.state.project).toBeUndefined()expect(f.state.machines?.map(m => m.machineId)).toEqual(['shared'])diff --git a/backend/src/superTabs/projects.ts b/backend/src/superTabs/projects.tsindex 123fa2bf7..a9960b061 100644--- a/backend/src/superTabs/projects.ts+++ b/backend/src/superTabs/projects.ts@@ -1,4 +1,4 @@-import { activeWork, agent, author, conversation, fail, nextConversationNumber, person, type Actor, type Agent, type Conversation, type SuperTabState } from './model.js'+import { activeWork, agent, author, conversation, fail, isLeads, nextConversationNumber, person, type Actor, type Agent, type Conversation, type SuperTabState } from './model.js'import type { SwarmRule } from './rules.js'export type ProjectVisibility = 'public' | 'private'@@ -43,6 +43,7 @@ export function projectOf(state: SuperTabState, projectId: string): SwarmProject}export function groupProject(state: SuperTabState, group: Conversation): SwarmProject {+ if (isLeads(group)) fail('LEADS_CONVERSATION', 'The Leads conversation is only for messages between Leads and people.')return projectOf(state, group.projectId ?? 'lead')}@@ -55,6 +56,10 @@ export function ledProject(state: SuperTabState, agentId: string): SwarmProjectreturn projectsOf(state).find(p => state.conversations.some(c => c.id === p.leadConversationId && c.leadId === agentId))}+/** Whose active work other projects' Leads see and are alerted about. A private project's work stays with its own people:+ * the Leads conversation is read by the whole Swarm. */+export const sharedWithLeads = (project: SwarmProject): boolean => project.visibility !== 'private'+export function canReadProject(state: SuperTabState, actor: Actor, project: SwarmProject): boolean {if (actor.kind === 'agent') {const target = state.agents.find(a => a.id === actor.agentId)@@ -74,6 +79,11 @@ export function readProject(state: SuperTabState, actor: Actor, projectId: strinexport function readConversation(state: SuperTabState, actor: Actor, conversationId: string): Conversation {const group = conversation(state, conversationId)+ if (isLeads(group)) {+ author(state, actor)+ if (actor.kind === 'agent' && !ledProject(state, actor.agentId)) fail('NOT_FOUND', 'This conversation is unavailable.', 404)+ return group+ }readProject(state, actor, groupProject(state, group).id)return group}@@ -114,7 +124,7 @@ export function manageProject(state: SuperTabState, actor: Actor, projectId: str* Pending starts must be reconciled first; terminal-history privacy bindings remain permanent. */export function deleteProject(state: SuperTabState, actor: Actor, projectId: string): void {const project = manageProject(state, actor, projectId)- const groups = state.conversations.filter(c => groupProject(state, c).id === project.id)+ const groups = state.conversations.filter(c => !isLeads(c) && groupProject(state, c).id === project.id)const groupIds = new Set(groups.map(c => c.id))if (state.starts?.some(s => groupIds.has(s.request.conversationId) && !s.error &&(!s.harnessId || s.poolGeneration && !s.poolSettled))) {diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 771072f96..18b1e759c 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -16,7 +16,7 @@ import { noteProjectReports, projectUpdateRequest } from './projectUpdates.js'import { revokeNativeContexts, SuperTabNativeStore } from './native.js'import {activeWork, actorKey, agent, author, conversation, createSuperTab, fail, person, stableId, visibleState, finishWorker,- SuperTabError, type Actor, type Agent, type Assignment, type Author, type MessageDraft, type SuperTabState,+ SuperTabError, isLeads, syncLeads, type Actor, type Agent, type Assignment, type Author, type MessageDraft, type SuperTabState,} from './model.js'import { holdNoticeText, type HoldReason } from './holdNotice.js'import { mayDrive, TERMINAL_ANSWER_MS, TERMINAL_EXPIRY_MS, TERMINAL_PICKUP_MS, type TerminalEffect } from './terminal.js'@@ -34,6 +34,7 @@ const hash = (value: unknown): string => createHash('sha256').update(JSON.stringconst stateOf = (row: SuperTab): SuperTabState => {const state = row.state as unknown as SuperTabStateif (state.version !== 1) fail('UPDATE_REQUIRED', 'Update Harness to open this Super Tab.', 409)+ syncLeads(state)return state}const indexes = (state: SuperTabState) => ({@@ -866,7 +867,7 @@ export class SuperTabStore {...(pool.scope === 'swarm' ? { projects: projectsOf(state).filter(p => starts.some(s =>groupProject(state, conversation(state, s.request.conversationId)).id === p.id)).map(p => ({ id: p.id, leadConversationId: p.leadConversationId, repository: p.repository,- conversationIds: state.conversations.filter(c => groupProject(state, c).id === p.id).map(c => c.id) })) } : {}),+ conversationIds: state.conversations.filter(c => !isLeads(c) && groupProject(state, c).id === p.id).map(c => c.id) })) } : {}),reservations: (state.harnessReservations ?? []).filter(r => r.machineId === machineId).map(({ harnessId, generation }) => ({ harnessId, generation })),harnessIds: [...new Set([...state.agents.filter(a => a.machineId === machineId).map(a => a.harnessId), ...(state.harnessReservations ?? []).filter(r => r.machineId === machineId).map(r => r.harnessId), ...(state.starts ?? []).filter(s => s.request.machineId === machineId && s.harnessId).map(s => s.harnessId!)])] }]})@@ -982,8 +983,9 @@ export class SuperTabStore {const actor: Actor = delivery.authorKind === 'person'? { kind: 'person', userId: delivery.authorId, email: '' }: { kind: 'agent', agentId: delivery.authorId, machineOwnerId: (sender as Agent).machineOwnerId }- if (!canReadProject(state, actor, groupProject(state, group))) return false- if (!canReadAgent(state, { kind: 'agent', agentId: target.id, machineOwnerId: target.machineOwnerId }, target) ||+ // The Leads conversation belongs to no project: its members are the Leads, and an agent posts there only as a Lead.+ if (isLeads(group) ? actor.kind === 'agent' && !ledProject(state, actor.agentId) : !canReadProject(state, actor, groupProject(state, group))) return false+ if (!canReadAgent(state, { kind: 'agent', agentId: target.id, machineOwnerId: target.machineOwnerId }, target) || !isLeads(group) &&!canReadProject(state, { kind: 'agent', agentId: target.id, machineOwnerId: target.machineOwnerId }, groupProject(state, group))) return falseconst generation = 'generation' in sender ? sender.generation : sender.membershipGenerationreturn generation === delivery.authorGeneration && (!('role' in sender) || sender.role !== 'viewer')diff --git a/backend/src/superTabs/terminal.ts b/backend/src/superTabs/terminal.tsindex cfe7a7a5a..31c3cd530 100644--- a/backend/src/superTabs/terminal.ts+++ b/backend/src/superTabs/terminal.ts@@ -1,5 +1,5 @@import type { PrismaClient } from '@prisma/client'-import { activeWork, actorKey, agent, author, conversation, fail, stableId, type Actor, type Agent, type Author, type Conversation, type MessageDraft,+import { activeWork, actorKey, agent, author, conversation, fail, isLeads, stableId, type Actor, type Agent, type Author, type Conversation, type MessageDraft,type SuperTabState } from './model.js'import { downSince } from './machines.js'import { agentProjectId, projectOf, readAgent } from './projects.js'@@ -40,10 +40,11 @@ export function mayDrive(state: SuperTabState, actor: Actor, target: Agent): voi}}-/** The group a terminal row belongs in: the agent's active work, else its newest open group as a member, else its project's Lead chat. */+/** The group a terminal row belongs in: the agent's active work, else its newest open project group as a member (never the+ * Swarm-wide Leads conversation), else its project's Lead chat. */export function currentGroup(state: SuperTabState, target: Agent): Conversation {return state.conversations.find(c => activeWork(c) && c.assignment!.agentId === target.id)- ?? state.conversations.findLast(c => !c.archived && c.agentIds.includes(target.id) && c.leadId !== target.id)+ ?? state.conversations.findLast(c => !c.archived && !isLeads(c) && c.agentIds.includes(target.id) && c.leadId !== target.id)?? conversation(state, projectOf(state, agentProjectId(state, target)).leadConversationId)}