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.

Swarm team account and repository approvals only in the Swarms of SWARM_TEAM_ACCOUNT_OWNERS

bitcoinbuilder5a24dcb44b7f
diff --git a/backend/integration/superTabGithub.test.ts b/backend/integration/superTabGithub.test.ts
index 31664f53b..8288937ef 100644
--- a/backend/integration/superTabGithub.test.ts
+++ b/backend/integration/superTabGithub.test.ts
@@ -82,6 +82,12 @@ async function fresh(options: { github?: boolean; approveAll?: boolean; signIn?:
}
type Env = Awaited<ReturnType<typeof fresh>>
+/** The team account switched on for this test, in the Swarms of [owners] or everyone's. */
+function teamAccounts(owners = '') {
+ vi.stubEnv('SWARM_TEAM_ACCOUNT_REQUIRED', '1')
+ vi.stubEnv('SWARM_TEAM_ACCOUNT_OWNERS', owners)
+ onTestFinished(() => { vi.unstubAllEnvs() })
+}
/** A tab whose project is on [repositoryUrl], with a Builder on the host's machine working on a task. */
async function working(env: Env, repositoryUrl: string | null = 'https://github.com/example/app.git') {
const tab = (await env.store.create(owner, randomUUID(), 'Pilot')).id
@@ -238,20 +244,38 @@ describe('a queued start\'s preparation token', () => {
})
it('gives no token for a repository nobody who can push to it approved for the project', async () => {
+ teamAccounts()
const env = await fresh({ approveAll: false })
const { tab, startId } = await queued(env)
+ const status = await env.app.inject({ method: 'GET', url: `/api/super-tabs/${tab}/projects/lead/github`, headers: { authorization: `Bearer ${owner.sub}` } })
+ expect(status.json().data).toMatchObject({ state: 'not-approved', repository: 'example/app' })
const response = await prepare(env, tab, startId)
expect(response.statusCode).toBe(403)
expect(response.json().error).toMatchObject({ code: 'GITHUB_REPOSITORY_NOT_APPROVED' })
expect(env.github.calls.some(c => c.path.endsWith('/access_tokens'))).toBe(false)
})
+ // Rolled out with the team account (machines.ts teamAccountRequired), so a bug in it cannot stop anyone else's Swarm.
+ it('asks no approval in a Swarm the team account is not tried in, or with the switch off', async () => {
+ teamAccounts('[email protected]')
+ const env = await fresh({ approveAll: false })
+ const { tab, startId } = await queued(env)
+ const status = await env.app.inject({ method: 'GET', url: `/api/super-tabs/${tab}/projects/lead/github`, headers: { authorization: `Bearer ${owner.sub}` } })
+ expect(status.json().data).toMatchObject({ state: 'covered', repository: 'example/app' })
+ expect((await prepare(env, tab, startId)).json().data).toMatchObject({ github: true, token: 'ghs_fixture_1' })
+ vi.unstubAllEnvs()
+ const off = await queued(env)
+ expect((await prepare(env, off.tab, off.startId)).json().data).toMatchObject({ github: true })
+ })
+
it('approves a repository through the app\'s sign-in, for someone who can push to it, and gives the token after', async () => {
let push = true
const signIn = { authorizeUrl: (state: string) => `https://github.test/login/oauth/authorize?state=${state}`,
permission: async () => ({ login: 'olive', push }) } as unknown as GitHubSignIn
+ teamAccounts()
const env = await fresh({ approveAll: false, signIn })
const { tab, startId } = await queued(env)
+ expect((await prepare(env, tab, startId)).statusCode).toBe(403)
const asked = await env.app.inject({ method: 'POST', url: `/api/super-tabs/${tab}/projects/lead/github/approve`,
headers: { authorization: `Bearer ${owner.sub}` }, payload: { scope: 'project' } })
expect(asked.statusCode, asked.body).toBe(200)
diff --git a/backend/integration/superTabTeam.test.ts b/backend/integration/superTabTeam.test.ts
index ad0009fea..32597041c 100644
--- a/backend/integration/superTabTeam.test.ts
+++ b/backend/integration/superTabTeam.test.ts
@@ -3,11 +3,12 @@ import { execFile } from 'node:child_process'
import { promisify } from 'node:util'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
-import { afterAll, beforeAll, describe, expect, it } from 'vitest'
+import { afterAll, beforeAll, describe, expect, it, onTestFinished, vi } from 'vitest'
import { MongoMemoryReplSet } from 'mongodb-memory-server-core'
import { PrismaClient } from '@prisma/client'
import type { AuthUser } from '../src/lib/ssoAuth.js'
import { SuperTabStore } from '../src/superTabs/store.js'
+import { SwarmReads } from '../src/superTabs/read/service.js'
import type { Command } from '../src/superTabs/commands.js'
import type { ContributedMachine } from '../src/superTabs/machines.js'
import * as parts from '../src/superTabs/parts/index.js'
@@ -458,10 +459,10 @@ describe('a teammate\'s work and the machines that take it', () => {
describe('a project\'s repository, for its GitHub access', () => {
it('is read by those who may open the project, and by nobody else', async () => {
const f = await fixture()
- expect(await store.projectRepository(owner, f.tab, 'lead')).toBeNull()
+ expect(await store.projectRepository(owner, f.tab, 'lead')).toEqual({ repositoryUrl: null, approvalRequired: false })
await run(f.tab, { type: 'tab.project', machineId: 'owner-host', project: { cwd: '/work', repositoryUrl: 'https://github.com/acme/app' } })
- expect(await store.projectRepository(owner, f.tab, 'lead')).toBe('https://github.com/acme/app')
- expect(await store.projectRepository(person, f.tab, 'lead')).toBe('https://github.com/acme/app')
+ expect(await store.projectRepository(owner, f.tab, 'lead')).toMatchObject({ repositoryUrl: 'https://github.com/acme/app' })
+ expect(await store.projectRepository(person, f.tab, 'lead')).toMatchObject({ repositoryUrl: 'https://github.com/acme/app' })
const secret = String((await run(f.tab, { type: 'project.create', name: 'Secret', visibility: 'private', brief: '' })).result.projectId)
await expect(store.projectRepository(person, f.tab, secret)).rejects.toMatchObject({ code: 'NOT_FOUND' })
await expect(store.projectRepository(owner, f.tab, 'nope')).rejects.toMatchObject({ code: 'NOT_FOUND' })
@@ -486,6 +487,28 @@ describe('one machine: a Mac and its Harness Team account', () => {
}
})
+ // Tried in listed owners' Swarms only (machines.ts teamAccountSwarm, 2026-10-28): anyone else's Swarm never gets a team
+ // account, and says so, so neither the Mac's daemon nor Desktop offers to set one up for it.
+ it('joins only a Swarm the team account is tried in, and tells the others they use none', async () => {
+ await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: 'personal-mac' } })
+ onTestFinished(async () => {
+ vi.unstubAllEnvs()
+ await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: null } })
+ })
+ const tab = (await store.create(owner, randomUUID(), 'Elsewhere')).id
+ const invitation = await run(tab, { type: 'invite.create', email: person.email, role: 'collaborator', conversationId: 'lead' })
+ await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, person)
+ await run(tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 3 }, person)
+ const joins = async () => (await rosterRows(store, person, 'personal-mac')).some(r => r.tabId === tab && 'joinTeam' in r)
+ const derived = async () => (await new SwarmReads(store).firstLoad(person, tab)).derived
+ vi.stubEnv('SWARM_TEAM_ACCOUNT_OWNERS', '[email protected]')
+ expect(await joins()).toBe(false)
+ expect(await derived()).toMatchObject({ teamAccounts: false })
+ vi.stubEnv('SWARM_TEAM_ACCOUNT_OWNERS', `[email protected],${owner.email.toUpperCase()}`)
+ expect(await joins()).toBe(true)
+ expect(await derived()).not.toHaveProperty('teamAccounts')
+ })
+
it('the Mac\'s host adds its team account, which then takes the owner\'s project started on the Mac', async () => {
await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: 'personal-mac' } })
try {
diff --git a/backend/src/routes/superTabs.ts b/backend/src/routes/superTabs.ts
index ab3e1b5f2..2e57382fb 100644
--- a/backend/src/routes/superTabs.ts
+++ b/backend/src/routes/superTabs.ts
@@ -108,7 +108,12 @@ export async function superTabRoutes(app: FastifyInstance, options: { store?: Su
const approvalSecret = github ? stateSecret(github.app.config) : null
// No token for a repository nobody who can push to it approved for this project: a project names its repository as
// text, and the app is on other people's repositories too.
- const requireApproval = async (user: { autonomousEnv: string }, tabId: string, projectId: string, repository: GitHubRepository) => {
+ // Rolled out with the team account (machines.ts `teamAccountRequired`): a Swarm outside it gets tokens as before, so a
+ // bug here cannot stop other people's Swarms.
+ const requireApproval = async (user: { autonomousEnv: string }, grant: { tabId: string; projectId: string; approvalRequired: boolean },
+ repository: GitHubRepository) => {
+ if (!grant.approvalRequired) return
+ const { tabId, projectId } = grant
if (await approvals.approved(user.autonomousEnv, tabId, projectId, repository.fullName)) return
throw new SuperTabError('GITHUB_REPOSITORY_NOT_APPROVED', `Nobody who can push to ${repository.fullName} has approved it for this project yet, `
+ 'so teammates\' agents get no access to it. Someone who can push to it approves it in Harness: Project details, GitHub access.', 403)
@@ -147,7 +152,7 @@ export async function superTabRoutes(app: FastifyInstance, options: { store?: Su
? 'This project\'s repository is not on github.com, so the Harness GitHub App cannot give a token for it.'
: 'This project has no repository address yet. Its owner or Lead can share it (project.repository).', 409)
}
- await requireApproval(req.user!, grant.tabId, grant.projectId, repository)
+ await requireApproval(req.user!, grant, repository)
return { github: true, ...await github.prepare(repository), requestedBy: grant.requester }
}))
app.get<{ Params: z.infer<typeof hostStartParams> }>('/api/super-tabs/hosts/:machineId/starts/:tabId/:startId', { preHandler: validateParams(hostStartParams) },
@@ -161,17 +166,19 @@ export async function superTabRoutes(app: FastifyInstance, options: { store?: Su
// (github/projectAccess.ts). `refresh=1`: a person installed it just now and checks again.
app.get<{ Params: z.infer<typeof projectParams>; Querystring: z.infer<typeof refreshQuery> }>('/api/super-tabs/:tabId/projects/:projectId/github',
{ preHandler: [validateParams(projectParams), validateQuery(refreshQuery)] },
- (req, reply) => respond(reply, async () => projectGitHubAccess(github?.app ?? null,
- await store.projectRepository(req.user!, req.params.tabId, req.params.projectId),
- { approved: repository => approvals.approved(req.user!.autonomousEnv, req.params.tabId, req.params.projectId, repository), canApprove: !!signIn },
- req.query.refresh === '1')))
+ (req, reply) => respond(reply, async () => {
+ const project = await store.projectRepository(req.user!, req.params.tabId, req.params.projectId)
+ return projectGitHubAccess(github?.app ?? null, project.repositoryUrl, { canApprove: !!signIn,
+ approved: async repository => !project.approvalRequired || approvals.approved(req.user!.autonomousEnv, req.params.tabId, req.params.projectId, repository) },
+ req.query.refresh === '1')
+ }))
// Approving a project's repository: the person signs in to GitHub through the app (or installs it, which signs them in
// too), and GitHub sends them back to /api/github/callback with the state signed here for them, this project and scope.
app.post<{ Params: z.infer<typeof projectParams>; Body: z.infer<typeof approveBody> }>('/api/super-tabs/:tabId/projects/:projectId/github/approve',
{ preHandler: [validateParams(projectParams), validateBody(approveBody)] }, (req, reply) => respond(reply, async () => {
if (!github || !approvalSecret) throw new GitHubAppError('GITHUB_APP_NOT_CONFIGURED', 'This Harness server has no GitHub App configured.', 503)
if (!signIn) throw new GitHubAppError('GITHUB_APPROVAL_NOT_CONFIGURED', 'This Harness server cannot approve repositories yet: its administrator sets GITHUB_APP_CLIENT_ID and GITHUB_APP_CLIENT_SECRET.', 503)
- const repositoryUrl = await store.projectRepository(req.user!, req.params.tabId, req.params.projectId)
+ const { repositoryUrl } = await store.projectRepository(req.user!, req.params.tabId, req.params.projectId)
const repository = githubRepository(repositoryUrl) ?? fail('REPOSITORY_NOT_GITHUB', 'This project\'s repository is not on github.com.', 409)
const state = signState(approvalSecret, { userId: req.user!.sub, autonomousEnv: req.user!.autonomousEnv, tabId: req.params.tabId,
projectId: req.params.projectId, repository: repository.fullName.toLowerCase(), scope: req.body.scope }, Date.now())
@@ -273,7 +280,7 @@ export async function superTabRoutes(app: FastifyInstance, options: { store?: Su
? 'This project\'s repository is not on github.com, so the Harness GitHub App cannot give a token for it.'
: 'This project has no repository address yet. Its owner or Lead can share it (project.repository).', 409)
}
- await requireApproval(req.user!, grant.tabId, grant.projectId, repository)
+ await requireApproval(req.user!, grant, repository)
const issued = await github.issue({ tabId: grant.tabId, agentId: grant.agentId, assignmentId: grant.assignmentId, repository })
return { ...issued, ...attribution(grant) }
}))
diff --git a/backend/src/superTabs/machines.ts b/backend/src/superTabs/machines.ts
index 1399ca5cb..6853873d8 100644
--- a/backend/src/superTabs/machines.ts
+++ b/backend/src/superTabs/machines.ts
@@ -165,7 +165,16 @@ const ONLY_OWN = 'so it runs only its owner\'s projects'
* read on every call, so a test can set them.
*/
export function teamAccountRequired(state?: Pick<SuperTabState, 'ownerId' | 'people'>): boolean {
- if (process.env.SWARM_TEAM_ACCOUNT_REQUIRED !== '1') return false
+ return process.env.SWARM_TEAM_ACCOUNT_REQUIRED === '1' && teamAccountSwarm(state)
+}
+
+/**
+ * Whether Harness Team accounts take part in [state]'s Swarm at all: they join it where their Mac was added (hostRows.ts)
+ * and teammates' work goes to them (teamMachineFor). With `SWARM_TEAM_ACCOUNT_OWNERS` set, only the Swarms those people
+ * own, so a bug in the team account cannot reach anyone else's Swarm while it is tried out (2026-10-28): elsewhere a Mac
+ * runs teammates' work itself, as before team accounts. Empty, every Swarm.
+ */
+export function teamAccountSwarm(state?: Pick<SuperTabState, 'ownerId' | 'people'>): boolean {
const owners = (process.env.SWARM_TEAM_ACCOUNT_OWNERS ?? '').split(',').map(email => email.trim().toLowerCase()).filter(Boolean)
if (!owners.length) return true
const owner = state?.people.find(person => person.id === state.ownerId)?.email.toLowerCase()
@@ -241,7 +250,7 @@ export function teamPoolOf(state: SuperTabState, pool: ContributedMachine, live?
* its contributor's own and the Mac has one in this Swarm, else the machine named. */
export function teamMachineFor(state: SuperTabState, machineId: string, project: SwarmProject, idle = false, live?: readonly string[]): string {
// With no GitHub App on this server a team account cannot fetch or push, so the work stays on the Mac, as before.
- if (idle) return machineId
+ if (idle || !teamAccountSwarm(state)) return machineId
const pool = state.machines?.find(m => m.machineId === machineId)
if (!pool || project.ownerId === pool.contributorId) return machineId
return teamPoolOf(state, pool, live)?.machineId ?? machineId
diff --git a/backend/src/superTabs/read/contract.ts b/backend/src/superTabs/read/contract.ts
index 50aa6a65a..18e736702 100644
--- a/backend/src/superTabs/read/contract.ts
+++ b/backend/src/superTabs/read/contract.ts
@@ -64,6 +64,9 @@ export interface Derived {
decisionsWaiting?: number
/** A person only: a digest of which decisions are open, moving when they change though the count may not. */
decisionsDigest?: string
+ /** Present, and false, only in a Swarm Harness Team accounts are not tried in yet (machines.ts teamAccountSwarm): this
+ * Mac's daemon and Desktop then offer no team account for it. Absent is every older backend's "yes". */
+ teamAccounts?: false
}
export interface OtherProjectWorkView {
conversationId: string; projectName: string; title: string; owns: string[]; status: WorkStatus; agentName: string; pr: string | null
diff --git a/backend/src/superTabs/read/hostRows.ts b/backend/src/superTabs/read/hostRows.ts
index 651fea904..b39db0c8d 100644
--- a/backend/src/superTabs/read/hostRows.ts
+++ b/backend/src/superTabs/read/hostRows.ts
@@ -5,7 +5,7 @@
*/
import type { AuthUser } from '../../lib/ssoAuth.js'
import { activeWork, agent, isLeads, SuperTabError, conversation, type Agent, type SuperTabState } from '../model.js'
-import { hostLocalGrid, machineContribution, type MachineCleanup } from '../machines.js'
+import { hostLocalGrid, machineContribution, teamAccountSwarm, type MachineCleanup } from '../machines.js'
import { agentProjectId, agentSetRole, canWatchAgent, isConfidential, groupProject, ledProject, projectsOf, skillModeOf, skillSetOf } from '../projects.js'
import type { HostAgentRow, HostPool, HostRosterRow, HostTabRows } from './contract.js'
import { hostEtag } from './hostEtag.js'
@@ -35,8 +35,10 @@ export async function hostTab(tabId: string, state: SuperTabState, machineId: st
async function roster(tabId: string, state: SuperTabState, machineId: string, user: AuthUser, lastChangedAt: number | null, lookups: HostLookups): Promise<HostRosterRow[]> {
const rows: HostRosterRow[] = []
- // Where its owner added this Mac and its team account is missing, this host adds that account (cli/src/superTabs/host.ts).
- const mac = state.machines?.find(m => m.machineId === machineId && m.contributorId === user.sub && m.scope === 'swarm' && !m.removal)
+ // Where its owner added this Mac and its team account is missing, this host adds that account (cli/src/superTabs/host.ts),
+ // in a Swarm the team account is tried in (teamAccountSwarm).
+ const mac = !teamAccountSwarm(state) ? undefined
+ : state.machines?.find(m => m.machineId === machineId && m.contributorId === user.sub && m.scope === 'swarm' && !m.removal)
for (const team of mac ? lookups.teams : []) {
if (state.machines?.some(m => m.machineId === team.machineId) || state.machineCleanups?.some(c => c.machineId === team.machineId)) continue
rows.push({ tabId, joinTeam: { machineId: team.machineId, name: mac!.name, maxAgents: mac!.maxAgents } })
diff --git a/backend/src/superTabs/read/views.ts b/backend/src/superTabs/read/views.ts
index 5e8f8477b..e8ac09de7 100644
--- a/backend/src/superTabs/read/views.ts
+++ b/backend/src/superTabs/read/views.ts
@@ -4,7 +4,7 @@
* in `derived`, so a part never changes without a new version (Lead's ruling).
*/
import { isLeads, visibleState, type Actor, type Agent, type Conversation, type SuperTabState } from '../model.js'
-import { machineSlots, teamAccountRequired, teamWorkRefusal, type ContributedMachine } from '../machines.js'
+import { machineSlots, teamAccountRequired, teamAccountSwarm, teamWorkRefusal, type ContributedMachine } from '../machines.js'
import * as store from '../parts/index.js'
import type { Part, SwarmParts } from '../parts/index.js'
import { canReadGroup } from '../projects.js'
@@ -104,5 +104,6 @@ function derive(state: SuperTabState, visible: SuperTabState, actor: Actor, now:
...(actor.kind === 'person' && extras.mentionsWaiting !== undefined ? { mentionsWaiting: extras.mentionsWaiting } : {}),
...(actor.kind === 'person' && extras.decisionsWaiting !== undefined ? { decisionsWaiting: extras.decisionsWaiting } : {}),
...(actor.kind === 'person' && extras.decisionsDigest !== undefined ? { decisionsDigest: extras.decisionsDigest } : {}),
+ ...(teamAccountSwarm(state) ? {} : { teamAccounts: false as const }),
}
}
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index e016d66ba..318ff4e45 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -1005,7 +1005,8 @@ export class SuperTabStore {
const contributed = state.machines?.find(m => m.machineId === target.machineId)?.name
const machineName = contributed ?? await tx.machine.findFirst({ where: { machineId: target.machineId, userId: target.machineOwnerId },
select: { name: true, hostname: true } }).then(m => m?.name ?? m?.hostname ?? null)
- return { tabId, projectId: project.id, agentId: target.id, assignmentId: group.assignment!.id, repositoryUrl: project.repository?.repositoryUrl ?? null,
+ return { tabId, projectId: project.id, approvalRequired: teamAccountRequired(state), agentId: target.id, assignmentId: group.assignment!.id,
+ repositoryUrl: project.repository?.repositoryUrl ?? null,
requester: { name: requester.name?.trim() || null, email: requester.email },
agentName: agentDisplayName(state.agents, target.id) ?? target.displayName ?? target.name, machineName: machineName?.trim() || null }
})
@@ -1033,7 +1034,8 @@ export class SuperTabStore {
const project = groupProject(state, group)
const owner = await tx.user.findUnique({ where: { id: project.ownerId }, select: { name: true, email: true } })
const email = owner?.email ?? state.people.find(p => p.id === project.ownerId)?.email ?? ''
- return { tabId, projectId: project.id, repositoryUrl: project.repository?.repositoryUrl ?? null, startId, own: project.ownerId === start.machineOwnerId,
+ return { tabId, projectId: project.id, repositoryUrl: project.repository?.repositoryUrl ?? null, approvalRequired: teamAccountRequired(state),
+ startId, own: project.ownerId === start.machineOwnerId,
requester: { name: owner?.name?.trim() || null, email } }
})
}
@@ -1416,14 +1418,16 @@ export class SuperTabStore {
/** What removing a machine would do, for its owner's confirmation (machines.ts removalPreview). */
/** A project's repository address, for a person who may open the project (routes/superTabs.ts, its GitHub access):
- * a private project's members only. Null when it has none yet. */
- async projectRepository(user: AuthUser, tabId: string, projectId: string): Promise<string | null> {
+ * a private project's members only. Null when it has none yet. [approvalRequired]: whether this Swarm's projects need a
+ * repository approved before the app gives them tokens, rolled out with the team account (machines.ts
+ * `teamAccountRequired`). */
+ async projectRepository(user: AuthUser, tabId: string, projectId: string): Promise<{ repositoryUrl: string | null; approvalRequired: boolean }> {
return transaction(this.db, async tx => {
const { state } = await this.load(tx, user, tabId)
const actor = await this.actor(tx, user, state)
const project = visibleState(state, actor, this.now()).projects?.find(p => p.id === projectId)
?? fail('NOT_FOUND', 'This project is unavailable.', 404)
- return project.repository?.repositoryUrl ?? null
+ return { repositoryUrl: project.repository?.repositoryUrl ?? null, approvalRequired: teamAccountRequired(state) }
})
}
diff --git a/backend/src/superTabs/teamRouting.test.ts b/backend/src/superTabs/teamRouting.test.ts
index cdeced0df..bb9f26fc5 100644
--- a/backend/src/superTabs/teamRouting.test.ts
+++ b/backend/src/superTabs/teamRouting.test.ts
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { applyCommand, type Command, type CommandContext } from './commands.js'
-import { admitMachineStart, machineObservationSchema, machineSlots, observedPrivacy, PRIVACY_FRESH_MS, removalPreview, teamAccountRequired, teamWorkRefusal, type ContributedMachine, type MachinePrivacy } from './machines.js'
+import { admitMachineStart, machineObservationSchema, machineSlots, observedPrivacy, PRIVACY_FRESH_MS, removalPreview, teamAccountRequired, teamAccountSwarm, teamWorkRefusal, type ContributedMachine, type MachinePrivacy } from './machines.js'
import { createSuperTab, SuperTabError, visibleState, type Actor, type AgentConfiguration, type AgentStart, type SuperTabState } from './model.js'
import type { RouteDecision } from './routeRecord.js'
@@ -393,6 +393,20 @@ describe('the switch held to the Swarms of listed owners', () => {
expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, f.pooled('mate-team')))?.code).toBe('PRIVACY_CHECK_FAILED')
})
+ it('leaves a teammate\'s work on the Mac, not its team account, in a Swarm the team account is not tried in', () => {
+ const f = swarm(), group = f.group()
+ Object.assign(f.machine('mate-team'), { hostMachineId: 'mate-mac', name: 'MacBook Pro', cwd: '/team-swarm' })
+ delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED
+ process.env.SWARM_TEAM_ACCOUNT_OWNERS = '[email protected]'
+ expect(teamAccountSwarm(f.state)).toBe(false)
+ f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))
+ expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'mate-mac', cwd: '/swarm/lead' })
+ process.env.SWARM_TEAM_ACCOUNT_OWNERS = '[email protected]'
+ expect(teamAccountSwarm(f.state)).toBe(true)
+ f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))
+ expect(f.state.starts![1]!.request).toMatchObject({ machineId: 'mate-team', cwd: '/team-swarm/lead' })
+ })
+
it('is every Swarm\'s with no list, and none with the switch off, list or not', () => {
const f = swarm()
process.env.SWARM_TEAM_ACCOUNT_OWNERS = ' , '
diff --git a/cli/src/superTabs/fixtures/read/index.ts b/cli/src/superTabs/fixtures/read/index.ts
index 6c1584363..317d2083d 100644
--- a/cli/src/superTabs/fixtures/read/index.ts
+++ b/cli/src/superTabs/fixtures/read/index.ts
@@ -45,13 +45,14 @@ export function hostForm(rows: unknown, options: { tabs?: string[]; pools?: unkn
export function partsOf(state: Json, options: { githubApp?: boolean; lastChangedAt?: number } = {}): Json {
const v = ++version
const part = (key: unknown, data: Json) => ({ key: String(key), version: v, changedAt: v, data })
- const { people, agents, conversations, machines, starts, otherProjectsWork, mentionsWaiting, ...head } = state
+ const { people, agents, conversations, machines, starts, otherProjectsWork, mentionsWaiting, teamAccounts, ...head } = state
return { format: 2, tabId: String(state.id ?? 'tab'), cursor: `tab-${v}`, serverTime: v, lastChangedAt: options.lastChangedAt ?? v, epoch: 1,
...(options.githubApp ? { githubApp: true } : {}),
head: part('head', head), members: asList(people).map(p => part(p.id, p)), agents: asList(agents).map(a => part(a.id, a)),
groups: asList(conversations).map((c, i) => part(c.id ?? `group-${i}`, c)), machines: asList(machines).map(m => part(m.machineId, m)),
starts: asList(starts).map(s => part(s.id, s)), progress: [],
- derived: { ...(otherProjectsWork !== undefined ? { otherProjectsWork } : {}), ...(mentionsWaiting !== undefined ? { mentionsWaiting } : {}) } }
+ derived: { ...(otherProjectsWork !== undefined ? { otherProjectsWork } : {}), ...(mentionsWaiting !== undefined ? { mentionsWaiting } : {}),
+ ...(teamAccounts === false ? { teamAccounts } : {}) } }
}
/** A fake Swarm read: a changes read asks for a reload, so every read is a first load of the state the test holds now (a
diff --git a/cli/src/superTabs/readContract.ts b/cli/src/superTabs/readContract.ts
index 05b7ff0e4..413549cee 100644
--- a/cli/src/superTabs/readContract.ts
+++ b/cli/src/superTabs/readContract.ts
@@ -35,6 +35,8 @@ export interface Derived {
otherProjectsWork?: Json[]
/** A person only. */
mentionsWaiting?: number
+ /** False only in a Swarm Harness Team accounts are not tried in yet (backend machines.ts teamAccountSwarm). */
+ teamAccounts?: false
}
interface ReadMeta {
diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.ts
index 1a2998b7c..63ae7a8f1 100644
--- a/cli/src/superTabs/service.spec.ts
+++ b/cli/src/superTabs/service.spec.ts
@@ -814,6 +814,25 @@ describe('the Harness Team account, offered by Desktop on this Mac', () => {
expect(await service.requests.super_tabs({ action: 'teamSetupCheck', reason: 'later' }, owner)).toEqual({ error: 'INVALID_REQUEST' })
})
+ it('offers nothing for a Swarm joined or added to that the team account is not tried in yet', async () => {
+ const offer = vi.fn(async () => ({ state: 'wanted' as const }))
+ const tabs: Record<string, Record<string, unknown>> = { elsewhere: { people: [{ id: 'me' }], teamAccounts: false }, mine: { people: [{ id: 'me' }] } }
+ const backend = vi.fn<CoreApi['account']['backend']>(async (_method, path) => {
+ const tab = tabs[path.split('/')[3]!]
+ return tab ? { status: 200, body: { success: true, data: swarmReply(path, tab) } } : { status: 503, body: { success: false } }
+ })
+ const service = superTabService(fakeCore({ account: { backend } }), { teamSetup: async () => ({ offer, decline: vi.fn() }) })
+ for (const reason of ['join', 'contribute']) {
+ expect(await service.requests.super_tabs({ action: 'teamSetupCheck', reason, tabId: 'elsewhere' }, owner)).toEqual({ ok: true, state: 'not-used' })
+ }
+ expect(offer).not.toHaveBeenCalled()
+ // Its own Swarm, one the server cannot read now, and an older Desktop that names none are offered, as before.
+ for (const tabId of ['mine', 'unreadable', undefined]) {
+ expect(await service.requests.super_tabs({ action: 'teamSetupCheck', reason: 'join', tabId }, owner)).toEqual({ ok: true, state: 'wanted' })
+ }
+ expect(offer).toHaveBeenCalledTimes(3)
+ })
+
it('tries again to make its setup when making it failed', async () => {
const make = vi.fn().mockRejectedValueOnce(new Error('import failed')).mockResolvedValueOnce({ offer: async () => ({ state: 'exists' }), decline: vi.fn() })
const service = superTabService(fakeCore(), { teamSetup: make })
@@ -835,6 +854,8 @@ describe('the Harness Team account, offered by Desktop on this Mac', () => {
const shared = answers([{ tabId: 'solo' }, { tabId: 'gone' }, { tabId: 'team' }],
{ solo: { people: [{ id: 'me' }] }, team: { people: [{ id: 'me' }, { id: 'kim' }] } })
expect(await sharedSwarm(sources(shared))).toBe(true)
+ // A Swarm the team account is not tried in yet (backend machines.ts teamAccountSwarm) does not count.
+ expect(await sharedSwarm(sources(answers([{ tabId: 'team' }], { team: { people: [{ id: 'me' }, { id: 'kim' }], teamAccounts: false } })))).toBe(false)
expect(shared.mock.calls.map(c => c[1])).toEqual(['/api/super-tabs/hosts/machine-1/changes?full=1',
'/api/super-tabs/solo/parts', '/api/super-tabs/gone/parts', '/api/super-tabs/team/parts'])
expect(await sharedSwarm(sources(answers([{ tabId: 'solo' }, { tabId: '../x' }], { solo: { people: [{ id: 'me' }] } })))).toBe(false)
diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.ts
index e3db371a9..a32b45771 100644
--- a/cli/src/superTabs/service.ts
+++ b/cli/src/superTabs/service.ts
@@ -170,12 +170,19 @@ export async function sharedSwarm(sources: SwarmSources): Promise<boolean> {
const pools = await sources.feed.current(POOLS_FRESH_MS).then(read => read.pools, () => [])
for (const row of pools) {
if (!identifier(row.tabId)) continue
- const people = await sources.reads.read(row.tabId).then(read => read.state.people, () => null)
- if (Array.isArray(people) && people.length > 1) return true
+ // A Swarm Harness Team accounts are not tried in yet (backend machines.ts teamAccountSwarm) asks for none.
+ const read = await sources.reads.read(row.tabId).catch(() => null)
+ if (read?.teamAccounts && Array.isArray(read.state.people) && read.state.people.length > 1) return true
}
return false
}
+/** Whether the Swarm a person just joined or added this Mac to uses Harness Team accounts: false only when its server
+ * says it does not, so a read that fails still offers, as before. */
+export async function teamAccountsIn(sources: SwarmSources, tabId: string): Promise<boolean> {
+ return sources.reads.read(tabId).then(read => read.teamAccounts, () => true)
+}
+
export interface SuperTabServiceOptions {
prepareContribution?: typeof prepareContribution
capacity?: typeof readCapabilities
@@ -309,6 +316,10 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =
if (payload.reason === 'startup' && !(identifier(core.daemon.machineId()) && existsSync(hostJournalFile(core.dataDir, core.daemon.machineId())))) {
return { ok: true, state: 'not-shared' }
}
+ // Joined or added to a Swarm Harness Team accounts are not tried in yet: nothing asked (2026-10-28). An older
+ // Desktop names no Swarm and is offered as before.
+ if ((payload.reason === 'join' || payload.reason === 'contribute') && identifier(payload.tabId)
+ && !await teamAccountsIn(sources(), payload.tabId)) return { ok: true, state: 'not-used' }
return { ok: true, ...await (await setup()).offer(payload.reason as AutoSetupReason, () => sharedSwarm(sources()),
payload.action === 'teamSetupCheck') }
}
diff --git a/cli/src/superTabs/swarmReads.spec.ts b/cli/src/superTabs/swarmReads.spec.ts
index ae30d03bf..61c46adb4 100644
--- a/cli/src/superTabs/swarmReads.spec.ts
+++ b/cli/src/superTabs/swarmReads.spec.ts
@@ -27,7 +27,7 @@ describe('the daemon\'s Swarm reads', () => {
it('first loads a Swarm once as the agent, then reads only what changed', async () => {
const { call, reads } = backendOf({ [FIRST]: [ok(readFixture('parts-lead'))], [CHANGES()]: [ok(readFixture('changes-lead'))] })
const first = await reads.read(T, LEAD)
- expect(first).toEqual({ state: readFixture<{ state: Json }>('legacy-tab-lead').state, lastChangedAt: 1793010101002, githubApp: true })
+ expect(first).toEqual({ state: readFixture<{ state: Json }>('legacy-tab-lead').state, lastChangedAt: 1793010101002, githubApp: true, teamAccounts: true })
const next = await reads.read(T, LEAD)
expect(conversations(next.state)).toEqual([FIXTURE.leadGroup, FIXTURE.leadsGroup, FIXTURE.workGroup])
expect(next.lastChangedAt).toBe(1793010106120)
diff --git a/cli/src/superTabs/swarmReads.ts b/cli/src/superTabs/swarmReads.ts
index d6229960d..bc1fa3846 100644
--- a/cli/src/superTabs/swarmReads.ts
+++ b/cli/src/superTabs/swarmReads.ts
@@ -11,7 +11,9 @@ import { backend, object, readable, SuperTabHostError } from './wire.js'
type Json = Record<string, unknown>
/** A Swarm as `GET /api/super-tabs/:id` gave it: its state in the old shape, `lastChangedAt` in place of `revision`. */
-export interface SwarmRead { state: Json; lastChangedAt: number | null; githubApp: boolean }
+/** `teamAccounts`: whether Harness Team accounts are used in this Swarm; false only where its server says they are not tried
+ * yet, so an older server's Swarm reads true. */
+export interface SwarmRead { state: Json; lastChangedAt: number | null; githubApp: boolean; teamAccounts: boolean }
/** One per running agent and Swarm on a machine, plus up to 16 the Pro cards read as the person; one of the largest Swarms
* holds about a megabyte. */
@@ -60,6 +62,6 @@ export class SwarmReads {
if (this.held.size <= this.maxSwarms) break
this.held.delete(oldest)
}
- return { state: reassemble(store), lastChangedAt: store.lastChangedAt, githubApp: store.githubApp }
+ return { state: reassemble(store), lastChangedAt: store.lastChangedAt, githubApp: store.githubApp, teamAccounts: store.derived.teamAccounts !== false }
}
}
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index d6485d3e0..688c6759b 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -1983,15 +1983,19 @@ class AppNotifier extends ChangeNotifier {
/// recognised as Harness (2026-10-27). Nothing on Windows or Linux, and never
/// for another machine, where nobody may be at it.
///
+ /// [tabId]: the Swarm joined or added to, so a Swarm its server does not
+ /// try team accounts in yet asks nothing (the daemon reads it).
+ ///
/// True when the daemon answered, whatever it decided; false when it was not
/// asked or could not say.
- Future<bool> offerTeamAccount(String reason) async {
+ Future<bool> offerTeamAccount(String reason, {String? tabId}) async {
final here = _teamAccountHere();
if (here == null) return false;
try {
final answer = await superTabMachineRequest(here, {
'action': 'teamSetupCheck',
'reason': reason,
+ 'tabId': ?tabId,
});
appLog.info('super-tabs', 'team account offer ($reason): ${answer['state']}');
if (answer['state'] == 'wanted') {
diff --git a/desktop/lib/super_tabs/join_dialog.dart b/desktop/lib/super_tabs/join_dialog.dart
index 066e7a7a6..9d6c88489 100644
--- a/desktop/lib/super_tabs/join_dialog.dart
+++ b/desktop/lib/super_tabs/join_dialog.dart
@@ -71,7 +71,7 @@ class _SwarmJoinHostState extends State<SwarmJoinHost> {
app.openSuperTab(id, name);
// Joined by the person at this Mac: macOS asks once for
// the Harness Team account (cli/src/team/autoSetup.ts).
- unawaited(app.offerTeamAccount('join'));
+ unawaited(app.offerTeamAccount('join', tabId: id));
},
)
: AlertDialog(
diff --git a/desktop/lib/super_tabs/machines.dart b/desktop/lib/super_tabs/machines.dart
index 2a92778a2..a18abb053 100644
--- a/desktop/lib/super_tabs/machines.dart
+++ b/desktop/lib/super_tabs/machines.dart
@@ -728,7 +728,9 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
// This Mac, added while its person is here: macOS asks once
// for the Harness Team account (cli/src/team/autoSetup.ts).
if (app.stateOf(selected)?.isLocalMachine == true) {
- unawaited(app.offerTeamAccount('contribute'));
+ unawaited(
+ app.offerTeamAccount('contribute', tabId: c.tabId),
+ );
}
if (context.mounted) Navigator.pop(context);
} catch (failure) {
diff --git a/desktop/test/team_account_offer_test.dart b/desktop/test/team_account_offer_test.dart
index 2f0f21933..dfcbcfb1b 100644
--- a/desktop/test/team_account_offer_test.dart
+++ b/desktop/test/team_account_offer_test.dart
@@ -73,12 +73,12 @@ void main() {
test('asks this Mac\'s own daemon whether it is wanted, and explains it only then', () async {
final explained = <String>[];
final listening = app.teamSetupAsks.listen(explained.add);
- await app.offerTeamAccount('join');
+ await app.offerTeamAccount('join', tabId: 'tab-1');
daemon.answer = {'ok': true, 'state': 'declined'};
await app.offerTeamAccount('contribute');
await pumpEventQueue();
expect(daemon.asked, [
- {'action': 'teamSetupCheck', 'reason': 'join'},
+ {'action': 'teamSetupCheck', 'reason': 'join', 'tabId': 'tab-1'},
{'action': 'teamSetupCheck', 'reason': 'contribute'},
]);
expect(explained, ['join']);
diff --git a/docs/plans/2026-10-28-swarm-project-github-access.md b/docs/plans/2026-10-28-swarm-project-github-access.md
index f9d4b219c..af52f9f9c 100644
--- a/docs/plans/2026-10-28-swarm-project-github-access.md
+++ b/docs/plans/2026-10-28-swarm-project-github-access.md
@@ -43,6 +43,11 @@ can push to it approved it, for that project or for every project of the Swarm:
`GITHUB_REPOSITORY_NOT_APPROVED`. The status says `not-approved`, with the buttons, until then.
- The signed state names the person, Swarm, project, repository and scope, lasts ten minutes, and is signed with a key
derived from the app's private key. The callback trusts nothing else.
+- **Rollout:** approvals are rolled out with the team account (`SWARM_TEAM_ACCOUNT_REQUIRED=1`, held to the Swarms of
+ `SWARM_TEAM_ACCOUNT_OWNERS`). Every other Swarm gets tokens as before and reads `covered`, so a bug here cannot stop
+ anyone else's Swarm. The same owner list keeps Harness Team accounts out of other Swarms altogether: they do not join
+ them, teammates' work there stays on the Mac, and their reads say `teamAccounts: false`, so neither the Mac's daemon nor
+ Desktop offers the team account (and macOS's administrator prompt) on joining or adding a Mac to one.
## Build