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
Swarm v3: remove Team accounts (#4120) (#3446)
harness-for-autonomous[bot]c18dc5ede6ed
diff --git a/backend/integration/crewDispatch.test.ts b/backend/integration/crewDispatch.test.tsindex 1cc88d77b..5d3b8b6d1 100644--- a/backend/integration/crewDispatch.test.ts+++ b/backend/integration/crewDispatch.test.ts@@ -425,21 +425,6 @@ describe('the crew dispatch pass', () => {expect(await s.holders()).toEqual({ Api: 'Ash' })})- it('assigns within the short retry once the repository is approved, and not before it', async () => {- const s = await swarm({ Ash: 'backend' }, { Api: 'backend/src/a.ts' })- // Ash runs in a Team account, which reaches the repository only through the GitHub App (repositoryReach.ts).- await editAgent(s.tab, s.crew.Ash!, agent => ({ ...agent, teamAccount: true }))- const store = s.store as unknown as { repositoryReachFor: (...args: unknown[]) => Promise<unknown> }- vi.spyOn(store, 'repositoryReachFor').mockResolvedValueOnce({ state: 'not-approved', repository: 'owner/repo' })- const refused = await s.store.dispatchCrew(s.tab)- expect(refused).toMatchObject({ assigned: 0, skipped: { REPOSITORY_UNREACHABLE: 1 } })- // Approved now, in the same round. The pick waits its short retry, then goes.- expect(await s.store.dispatchCrew(s.tab)).toEqual({ assigned: 0, skipped: {} })- s.advance(DISPATCH_RETRY_MS)- expect(await s.store.dispatchCrew(s.tab)).toMatchObject({ assigned: 1 })- expect(await s.holders()).toEqual({ Api: 'Ash' })- })-it('does not assign a task postponed while the pass read GitHub', async () => {const s = await swarm({ Ash: 'backend' }, { Api: 'backend/src/a.ts' })// Between the pass's read and its write: a person moves the task to tomorrow.@@ -465,12 +450,12 @@ describe('the crew dispatch pass', () => {expect(second.status).toBe('working')})- it('skips a task the member may not take (Team-written code, main account) and gives it its next one', async () => {+ // Swarm v3 (task #4120, the PM's ruling): Team-written code goes only to the project owner's own agent, as Ash is here.+ it('gives Team-written code to the project owner\'s own agent', async () => {const s = await swarm({ Ash: 'backend' }, { Api: 'backend/src/a.ts', Store: 'backend/src/b.ts' })- // Team-written code goes only to a Team account's agent: Ash runs in the main account.await editGroup(s.tab, s.tasks.Api!, group => ({ ...group, teamWritten: true }))const done = await s.store.dispatchCrew(s.tab)expect(done.assigned).toBe(1)- expect(await s.holders()).toEqual({ Api: null, Store: 'Ash' })+ expect(await s.holders()).toEqual({ Api: 'Ash', Store: null })})})diff --git a/backend/integration/superTabCosts.test.ts b/backend/integration/superTabCosts.test.tsindex b5ee8d416..3265be222 100644--- a/backend/integration/superTabCosts.test.ts+++ b/backend/integration/superTabCosts.test.ts@@ -61,8 +61,9 @@ async function swarm() {const generations = new Map<string, string>()for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(store, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID() }+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId, name, configuration: config, lead }, host)).result.agentId)const lead = await add('lead', 'lead-host', harness.lead, 'Lead', true)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)diff --git a/backend/integration/superTabEvidence.test.ts b/backend/integration/superTabEvidence.test.tsindex 278eefcc0..8160097d6 100644--- a/backend/integration/superTabEvidence.test.ts+++ b/backend/integration/superTabEvidence.test.ts@@ -62,8 +62,9 @@ async function swarm() {const generations = new Map<string, string>()for (const machineId of ['ev-lead-host', 'ev-test-host']) generations.set(machineId, (await poolRows(store, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const leadHarness = randomUUID(), workers = new Map<string, { agentId: string; harness: string }>()+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId, name, configuration: config, lead }, host)).result.agentId)const lead = await add('lead', 'ev-lead-host', leadHarness, 'Lead', true)const observe = (machineId: string, running: string[], extra: Partial<MachineObservation> = {}) => store.observeMachine(host, tab, machineId, {generation: generations.get(machineId)!, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9,diff --git a/backend/integration/superTabGithub.test.ts b/backend/integration/superTabGithub.test.tsindex e43fc1386..682597d83 100644--- a/backend/integration/superTabGithub.test.ts+++ b/backend/integration/superTabGithub.test.ts@@ -272,8 +272,8 @@ describe('the GitHub token endpoint', () => {describe('a queued start\'s preparation token', () => {/** The host's pool rows, now each Swarm's `pool` in the host form (design 4.10), in the shape the old pools route answered. */const hostPools = async (env: Env) => {- // gh-pool is a Team machine (`queued`): its host reads are its team session's.- const response = await env.app.inject({ method: 'GET', url: '/api/super-tabs/hosts/gh-pool/changes?full=1', headers: { authorization: `Bearer ${host.sub}`, 'x-test-team': '1' } })+ // gh-pool is the host's own computer (`queued`): its host reads are the host's.+ const response = await env.app.inject({ method: 'GET', url: '/api/super-tabs/hosts/gh-pool/changes?full=1', headers: { authorization: `Bearer ${host.sub}` } })const rows = (response.json().data.tabs as Array<{ pool: unknown }>).flatMap(tab => tab.pool ? [tab.pool] : [])return { json: () => ({ data: rows }) }}@@ -291,34 +291,21 @@ describe('a queued start\'s preparation token', () => {await env.run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string } as Command, contributor)}await env.run(tab, { type: 'machine.contribute', machineId, name: 'Pool', cwd: '/swarm-root', scope: 'swarm', engines: ['codex'], maxAgents: 2 } as Command, contributor)- if (contributor === owner) {- const pool = (await poolRows(env.store, contributor, machineId)).find(p => p.tabId === tab)!- await env.store.observeMachine(contributor, tab, machineId, { generation: pool.machine.generation, ...observed })- } else {- // Another person's project runs only on a Team machine (#1694): this one is used only for agents (`harness team on`).- const computerId = createHash('sha256').update(machineId).digest('hex').slice(0, 32)- await db.machine.update({ where: { machineId }, data: { computerId, sessionKind: 'team' } })- onTestFinished(async () => { await db.machine.update({ where: { machineId }, data: { computerId: null, sessionKind: null } }) })- const team: AuthUser = { ...contributor, harnessSessionId: `team-${machineId}`, harnessSessionKind: 'team', harnessComputerId: computerId }- // Its host routes take its team session alone (security review 2 of #2089): `prepare` signs in as it.- if (!users.some(u => u.sub === team.sub && u.harnessSessionKind === 'team')) {- users.push(team)- onTestFinished(() => { users.splice(users.indexOf(team), 1) })- }- const pool = (await poolRows(env.store, team, machineId)).find(p => p.tabId === tab)!- await env.store.observeMachine(team, tab, machineId, { generation: pool.machine.generation, ...observed, privacy: { mode: 'dedicated' } })- }+ // Its own person's computer, as v3 runs every agent (task #4120): no Team account, and the contributor starts its own agent.+ const pool = (await poolRows(env.store, contributor, machineId)).find(p => p.tabId === tab)!+ await env.store.observeMachine(contributor, tab, machineId, { generation: pool.machine.generation, ...observed })// A group of the project, its start's conversation: no agent but the coordinator starts into the project chat (#2207).// [requester] asked for it, where given. The contributor joined above.const conversationId = String((await env.run(tab, { type: 'conversation.create', title: 'Add search', brief: 'Add a search field',checks: [], ...(requester ? { requesterId: requester.sub } : {}) } as Command)).result.conversationId)const startId = String((await env.run(tab, { type: 'agent.start', request: { conversationId, machineId, engine: 'codex', name: 'Builder',- cwd: '/swarm-root/lead', permissionMode: 'full', worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } } as Command)).result.startId)+ cwd: '/swarm-root/lead', permissionMode: 'full', worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } } as Command,+ contributor)).result.startId)return { tab, startId }}- /** As [user]'s Harness Team account by default on `gh-pool`, the Team machine `queued` makes for another person's start. */+ /** As [user], by default the host on `gh-pool`, its own computer where `queued` starts its agent for the owner's project. */const prepare = (env: Env, tab: string, startId: string, machineId = 'gh-pool', user = host, payload: Record<string, unknown> = {},- team = user === host && machineId === 'gh-pool') => env.app.inject({ method: 'POST',+ team = false) => env.app.inject({ method: 'POST',url: `/api/super-tabs/hosts/${machineId}/starts/${tab}/${startId}/github-token`, headers: { authorization: `Bearer ${user.sub}`, ...(team ? { 'x-test-team': '1' } : {}) }, payload })it('gives the host of another person\'s start a token that only reads the project\'s repository, and says whom the work is for', async () => {@@ -529,9 +516,8 @@ describe('a queued start\'s preparation token', () => {expect((await prepare(env, tab, startId, 'gh-host-mini')).statusCode).toBe(403)expect((await prepare(env, tab, 'missing-start')).statusCode).toBe(404)expect((await prepare(env, tab, startId, 'gh-pool', host, { machineId: 'gh-pool' })).statusCode).toBe(400)- // gh-pool is a Team machine (`queued`): its team session hosts it.- const team = users.find(u => u.sub === host.sub && u.harnessSessionKind === 'team')!- const hostRun = (command: Command) => env.store.execute(team, tab, { operationId: randomUUID(), command }, undefined, 'gh-pool')+ // gh-pool is the host's own computer (`queued`): the host's session runs it.+ const hostRun = (command: Command) => env.store.execute(host, tab, { operationId: randomUUID(), command }, undefined, 'gh-pool')await hostRun({ type: 'agent.startDispatch', startId } as Command)await hostRun({ type: 'agent.started', startId, harnessId: randomUUID(), configuration: config } as Command)const settled = await prepare(env, tab, startId)diff --git a/backend/integration/superTabLiveness.test.ts b/backend/integration/superTabLiveness.test.tsindex 9ba1ed2f4..6a29dcd90 100644--- a/backend/integration/superTabLiveness.test.ts+++ b/backend/integration/superTabLiveness.test.ts@@ -48,7 +48,9 @@ afterAll(async () => {})/** A Swarm whose Lead runs on one of host's machines and whose worker runs on another, assigned "Ship the parser". */-async function swarm({ legacy = false, client = db, hooks, independent = false, engines = ['codex'] }: { legacy?: boolean; client?: PrismaClient; hooks?: SuperTabStoreHooks; independent?: boolean; engines?: string[] } = {}) {+/** [lent]: its agents are the owner's, lent through the host's machine share, as before Swarm v3; such an agent takes no new work+ * on another person's computer now (task #4120), so the task is left unassigned. */+async function swarm({ legacy = false, client = db, hooks, independent = false, engines = ['codex'], lent = false }: { legacy?: boolean; client?: PrismaClient; hooks?: SuperTabStoreHooks; independent?: boolean; engines?: string[]; lent?: boolean } = {}) {let now = 10_000_000const timed = new SuperTabStore(client, () => now, null, hooks)const tab = (await timed.create(owner, randomUUID(), 'Liveness', legacy ? undefined : 'public')).id@@ -62,13 +64,14 @@ async function swarm({ legacy = false, client = db, hooks, independent = false,const generations = new Map<string, string>()for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(timed, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID(), other: randomUUID() }+ // Added by the machines' own person: an agent runs on its person's own computer, as them (Swarm v3, task #4120).const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId, name, configuration: config, lead }, lent ? owner : host)).result.agentId)const lead = await add('lead', 'lead-host', harness.lead, 'Lead', true)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent }] })).result.conversationId)const worker = await add(group, 'test-host', harness.worker, 'Worker')- const assignmentId = String((await execute({ type: 'work.assign', conversationId: group, agentId: worker })).result.assignmentId)+ const assignmentId = lent ? '' : String((await execute({ type: 'work.assign', conversationId: group, agentId: worker })).result.assignmentId)const observe = (machineId: string, running: string[], extra: Partial<MachineObservation> = {}, store = timed) => store.observeMachine(host, tab, machineId, {generation: generations.get(machineId)!, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9,diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture', os: 'macOS', gpuPercent: null },@@ -1288,8 +1291,8 @@ describe('a task that stalls', () => {expect(await page(host, wake.conversationId, f.lead)).toContain(wake.id)expect(await page(host, moved.conversationId, f.worker)).toContain(moved.id)// People read none of them: not in the project chat, not in the task's chat, not by its id, which reads as no such message.- // Neither the Lead's owner (the tab's owner added it) nor its machine's owner: each reads as a person, not as the agent.- expect((await f.timed.read(owner, f.tab)).state.agents.find(a => a.id === f.lead)).toMatchObject({ contributorId: owner.sub, machineOwnerId: host.sub })+ // Neither the tab's owner nor the Lead's own person (its machine's, who added it: task #4120): each reads as a person, not as the agent.+ expect((await f.timed.read(owner, f.tab)).state.agents.find(a => a.id === f.lead)).toMatchObject({ contributorId: host.sub, machineOwnerId: host.sub })for (const user of [owner, host]) {for (const conversationId of new Set(notices.map(m => m.conversationId))) {expect((await page(user, conversationId)).filter(id => ids.includes(id))).toEqual([])@@ -1547,7 +1550,8 @@ describe('the delivery poll of an agent with nothing waiting', () => {// while the host polls each second (Diego, 10-28): the poll answers it from one indexed read while nothing it relied on moved.describe('the delivery poll of an agent with a held delivery', () => {// The open deliveries, then the grant the host speaks for its agent under, read outside the Swarm (store.ts grantHolds):- // its contributor's Workspace membership, its machine and, lent by host to owner here, the contributor and the share.+ // its contributor's Workspace membership, its machine and, lent by host to owner here (an agent from before Swarm v3), the+ // contributor and the share.const HELD_READS = ['SuperTabDelivery.aggregateRaw', 'SwarmWorkspaceMember.findUnique', 'Machine.findFirst', 'User.findUnique', 'MachineShare.findUnique']/** A person's message to the Lead, read by a full poll, claimed and held by its host. */const held = async (f: Awaited<ReturnType<typeof swarm>>) => {@@ -1561,7 +1565,7 @@ describe('the delivery poll of an agent with a held delivery', () => {it('answers the next poll without loading the Swarm: its open deliveries and its host\'s grant, each one indexed read', async () => {const counted = counting()- const f = await swarm({ client: counted.client })+ const f = await swarm({ client: counted.client, lent: true })const row = await held(f)f.clock.now += 1_000await f.timed.deliveries(host, f.tab, f.lead)@@ -1585,7 +1589,7 @@ describe('the delivery poll of an agent with a held delivery', () => {it('answers a worker\'s held delivery from the same reads', async () => {const counted = counting()- const f = await swarm({ client: counted.client })+ const f = await swarm({ client: counted.client, lent: true })const sent = await f.execute({ type: 'message.send', conversationId: f.group, text: 'Status?', replyTo: null, recipientIds: [f.worker] })const full = await f.timed.deliveries(host, f.tab, f.worker)const row = full.find(r => r.messageId === sent.result.messageId)!@@ -1664,7 +1668,7 @@ describe('the delivery poll of an agent with a held delivery', () => {// What no Swarm write records (a machine share revoked, a machine gone, a Workspace left) is read on every poll.it('refuses on the next poll once its host\'s machine share is revoked', async () => {- const f = await swarm()+ const f = await swarm({ lent: true })await held(f)const share = await db.machineShare.findUniqueOrThrow({ where: { machineId: 'lead-host' } })await db.machineShare.update({ where: { machineId: 'lead-host' }, data: { emails: [] } })@@ -1741,7 +1745,7 @@ describe('the delivery poll of an agent with a held delivery', () => {// A Workspace removal is read outside the Swarm, as a machine share is (superTabs.test.ts): the next poll meets it.it('refuses on the next poll once the agent\'s contributor is out of the Swarm\'s Workspace', async () => {- const f = await swarm()+ const f = await swarm({ lent: true })await held(f)const { workspaceId } = (await f.timed.read(owner, f.tab)).stateconst id = `${workspaceId}:${owner.sub}`@@ -2393,8 +2397,8 @@ describe('a session reopened after its agent was removed', () => {const state = async (f: Awaited<ReturnType<typeof swarm>>) => (await f.timed.read(owner, f.tab)).stateconst machinePart = async (f: { tab: string }, machineId: string) => (await db.swarmMachine.findFirstOrThrow({ where: { tabId: f.tab, key: machineId } })).data as { removedSessions?: Array<Record<string, any>> }/** A Swarm with an idle agent of a role, in the task's group, that its machine's report just removed. */- async function removed(over: Record<string, unknown> = {}) {- const f = await swarm()+ async function removed(over: Record<string, unknown> = {}, lent = false) {+ const f = await swarm({ lent })await f.beat(f.clock.now)const idle = await f.add(f.group, 'test-host', f.harness.other, 'Idle one')const row = await db.swarmAgent.findFirstOrThrow({ where: { tabId: f.tab, key: idle } })@@ -2510,7 +2514,6 @@ describe('a session reopened after its agent was removed', () => {['a contributor no longer in the Swarm', (r: Record<string, any>) => { r.agent.contributorId = 'someone-else' }],['its contributor left and came back', (r: Record<string, any>) => { r.agent.membershipGeneration = 'an-older-one' }],['its project gone', (r: Record<string, any>) => { r.agent.projectId = 'no-such-project' }],- ['a share grant that changed', (r: Record<string, any>) => { r.agent.hostGrant = 'revoked' }],['a harness that does not match', (r: Record<string, any>) => { r.agent.harnessId = 'other-session' }],])('is not restored with %s, and its record goes', async (_, change) => {const f = await removed()@@ -2520,6 +2523,15 @@ describe('a session reopened after its agent was removed', () => {expect((await machinePart(f, 'test-host')).removedSessions ?? []).toEqual([])})+ // A session lent through another person's machine share (before Swarm v3) never comes back to work on that computer: it is not+ // its person's own (task #4120), whatever its share grant says now.+ it('is not restored when it was lent through another person\'s share, and its record goes', async () => {+ const f = await removed({}, true)+ await resume(f)+ expect((await state(f)).agents.map(a => a.id)).not.toContain(f.idle)+ expect((await machinePart(f, 'test-host')).removedSessions ?? []).toEqual([])+ })+it('does not come back into an archived group, a private chat, or one that is gone; it is listed all the same', async () => {const f = await removed()const open = String((await f.execute({ type: 'conversation.create', title: 'Open one', brief: 'b', checks: [] })).result.conversationId)diff --git a/backend/integration/superTabMachineReports.test.ts b/backend/integration/superTabMachineReports.test.tsindex 88039cc51..a47e1ff7f 100644--- a/backend/integration/superTabMachineReports.test.ts+++ b/backend/integration/superTabMachineReports.test.ts@@ -72,12 +72,13 @@ async function swarm(memory?: (now: () => number) => ReportMemory, shared?: { clconst generations = new Map<string, string>()for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(timed, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID() }- const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ // An agent runs as its own person, on their own computer (task #4120): the machines are host's, so host adds the worker.+ const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false, user = owner) => String((await execute({ type: 'agent.add',+ conversationId, machineId, harnessId, name, configuration: config, lead }, user)).result.agentId)const lead = await add('lead', 'lead-host', harness.lead, 'Lead', true)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)- const worker = await add(group, 'test-host', harness.worker, 'Worker')+ const worker = await add(group, 'test-host', harness.worker, 'Worker', false, host)await execute({ type: 'work.assign', conversationId: group, agentId: worker })const reading = (machineId: string, running: string[], extra: Partial<MachineObservation> = {}): MachineObservation => ({generation: generations.get(machineId)!, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9,@@ -185,11 +186,11 @@ describe('every reason a report runs in full (DB 2.5 spec, Tests)', () => {['a running session lost its progress entry', async () => ({ extra: { harnessProgress: {} } }), { progress: true }],// What concerns this machine changed since its last full report (task #3119): what its host reads (commit.ts hostsToTell).['an agent was added on it', async f => {- await f.execute({ type: 'agent.add', conversationId: f.group, machineId: 'test-host', harnessId: randomUUID(), name: 'Helper', configuration: config, lead: false })+ await f.execute({ type: 'agent.add', conversationId: f.group, machineId: 'test-host', harnessId: randomUUID(), name: 'Helper', configuration: config, lead: false }, host)}],['a start was queued on it', async f => {await f.execute({ type: 'agent.start', request: { conversationId: f.group, machineId: 'test-host', engine: 'codex', name: 'Builder', cwd: '/repo',- worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } })+ worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } }, host)}],['a conversation an agent on it works in changed', async f => {await f.execute({ type: 'message.send', conversationId: f.group, text: 'hi', replyTo: null, recipientIds: [] })@@ -501,9 +502,9 @@ describe('a busy Swarm\'s readings (task #3119)', () => {const [spare] = spares[0]!for (const [machineId, generation] of spares) await f.timed.observeMachine(host, f.tab, machineId, { ...f.reading('test-host', []), generation })for (let i = 0; i < 10; i++) {- await f.execute({ type: 'agent.add', conversationId: f.group, machineId: spare, harnessId: randomUUID(), name: `Helper ${i}`, configuration: config, lead: false })+ await f.execute({ type: 'agent.add', conversationId: f.group, machineId: spare, harnessId: randomUUID(), name: `Helper ${i}`, configuration: config, lead: false }, host)await f.execute({ type: 'agent.start', request: { conversationId: f.group, machineId: spare, engine: 'codex', name: `Builder ${i}`, cwd: '/repo',- worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } })+ worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } }, host)}await f.beat({}, store)f.clock.now += BEATdiff --git a/backend/integration/superTabMergeTrain.test.ts b/backend/integration/superTabMergeTrain.test.tsindex 60e3a0610..a4c25ff5c 100644--- a/backend/integration/superTabMergeTrain.test.ts+++ b/backend/integration/superTabMergeTrain.test.ts@@ -53,13 +53,14 @@ async function swarm() {for (const [machineId, name] of [['lead-host', 'Lead Mac'], ['test-host', 'Worker Mac']]) {await execute({ type: 'machine.contribute', machineId: machineId!, name: name!, cwd: '/repo', engines: ['codex'], maxAgents: 4 }, host)}- const add = async (conversationId: string, machineId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId: randomUUID(), name, configuration: config, lead })).result.agentId)+ // An agent runs as its own person, on their own computer (task #4120): the machines are host's, so host adds the worker.+ const add = async (conversationId: string, machineId: string, name: string, lead = false, user = owner) => String((await execute({ type: 'agent.add',+ conversationId, machineId, harnessId: randomUUID(), name, configuration: config, lead }, user)).result.agentId)await add('lead', 'lead-host', 'Lead', true)await execute({ type: 'tab.project', machineId: 'lead-host', project: { cwd: '/repo', repositoryUrl: null } })await execute({ type: 'project.repository', projectId: 'lead', repositoryUrl: 'https://github.com/acme/app' })const task = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it', checks: [] })).result.conversationId)- const worker = await add(task, 'test-host', 'Worker')+ const worker = await add(task, 'test-host', 'Worker', false, host)const assignment = String((await execute({ type: 'work.assign', conversationId: task, agentId: worker })).result.assignmentId)await execute({ type: 'work.status', conversationId: task, assignmentId: assignment, status: 'review', result: `Ready ${PR}` }, host, worker)const step = String((await execute({ type: 'conversation.create', title: 'Review', brief: 'Read it', reviewOf: task, step: 'Review',diff --git a/backend/integration/superTabNoticeDigest.test.ts b/backend/integration/superTabNoticeDigest.test.tsindex f74c02c95..d7b28d6df 100644--- a/backend/integration/superTabNoticeDigest.test.ts+++ b/backend/integration/superTabNoticeDigest.test.ts@@ -65,7 +65,8 @@ async function swarm({ fresh = false, told, capable = false }: { fresh?: booleanconst harnessOf = new Map<string, string>()const add = async (conversationId: string, machineId: string, name: string, lead = false) => {const harnessId = randomUUID()- const agentId = String((await execute({ type: 'agent.add', conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ // Added by the machine's own person: an agent is its own person's, on their own computer (task #4120).+ const agentId = String((await execute({ type: 'agent.add', conversationId, machineId, harnessId, name, configuration: config, lead }, machineId === 'owner-mac' ? owner : host)).result.agentId)harnessOf.set(machineId, harnessId)return agentId}diff --git a/backend/integration/superTabPmSchedule.test.ts b/backend/integration/superTabPmSchedule.test.tsindex 3ce39e869..ab0b54dad 100644--- a/backend/integration/superTabPmSchedule.test.ts+++ b/backend/integration/superTabPmSchedule.test.ts@@ -66,7 +66,8 @@ async function swarm({ fresh = false, told }: { fresh?: boolean; told?: string[]const harnessOf = new Map<string, string>()const add = async (conversationId: string, machineId: string, name: string, lead = false) => {const harnessId = randomUUID()- const agentId = String((await execute({ type: 'agent.add', conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).+ const agentId = String((await execute({ type: 'agent.add', conversationId, machineId, harnessId, name, configuration: config, lead }, host)).result.agentId)harnessOf.set(machineId, harnessId)return agentId}diff --git a/backend/integration/superTabPullRequestEvents.test.ts b/backend/integration/superTabPullRequestEvents.test.tsindex 60bc9ca7c..444add91a 100644--- a/backend/integration/superTabPullRequestEvents.test.ts+++ b/backend/integration/superTabPullRequestEvents.test.ts@@ -79,8 +79,9 @@ async function swarm({ reads = false } = {}) {for (const [machineId, name] of [['lead-host', 'Lead Mac'], ['test-host', 'Worker Mac']]) {await execute({ type: 'machine.contribute', machineId: machineId!, name: name!, cwd: '/repo', engines: ['codex'], maxAgents: 4 }, host)}+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).const add = async (conversationId: string, machineId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId: randomUUID(), name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId: randomUUID(), name, configuration: config, lead }, host)).result.agentId)const lead = await add('lead', 'lead-host', 'Lead', true)const task = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)diff --git a/backend/integration/superTabReflection.test.ts b/backend/integration/superTabReflection.test.tsindex 26d55d866..60fc29b26 100644--- a/backend/integration/superTabReflection.test.ts+++ b/backend/integration/superTabReflection.test.ts@@ -62,11 +62,11 @@ async function swarm() {for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(store, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID() }const lead = String((await execute({ type: 'agent.add', conversationId: 'lead', machineId: 'lead-host', harnessId: harness.lead, name: 'Lead',- configuration: config, lead: true })).result.agentId)+ configuration: config, lead: true }, host)).result.agentId)const group = String((await execute({ type: 'conversation.create', title: 'Secret parser plan', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)const worker = String((await execute({ type: 'agent.add', conversationId: group, machineId: 'test-host', harnessId: harness.worker, name: 'Worker',- configuration: config, lead: false })).result.agentId)+ configuration: config, lead: false }, host)).result.agentId)const beat = async (tokens: TokensByModel) => {for (const [machineId, running] of [['lead-host', [harness.lead]], ['test-host', [harness.worker]]] as const) {await store.observeMachine(host, tab, machineId, { generation: generations.get(machineId)!, resources: { cpuPercent: 10, memoryTotalBytes: 32e9,diff --git a/backend/integration/superTabReviewSteps.test.ts b/backend/integration/superTabReviewSteps.test.tsindex 3d1eed636..9efac54f8 100644--- a/backend/integration/superTabReviewSteps.test.ts+++ b/backend/integration/superTabReviewSteps.test.ts@@ -10,6 +10,7 @@ import type { AuthUser } from '../src/lib/ssoAuth.js'import { SuperTabStore, type SuperTabStoreHooks } from '../src/superTabs/store.js'import type { Command } from '../src/superTabs/commands.js'import { SEED_RULES } from '../src/superTabs/policy.js'+import { poolRows } from './hostRows.test-support.js'// Task #3401: a task's Ready reads its pull request's files from GitHub, outside the command's transaction, and the server// opens its review steps from them. A fresh loopback replica set, created here.@@ -45,8 +46,14 @@ async function swarm(hooks: SuperTabStoreHooks) {const invitation = await execute({ type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await execute({ type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await execute({ type: 'machine.contribute', machineId: 'review-host', name: 'Review Mac', cwd: '/repo', engines: ['claude'], maxAgents: 8 }, host)+ // It reports as a live machine does, so its own agents can take steps (reviewSeats.ts canStart): they are its person's own (task #4120).+ const generation = (await poolRows(store, host, 'review-host')).find(p => p.tabId === tab)!.machine.generation+ await store.observeMachine(host, tab, 'review-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,+ diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture', os: 'macOS', gpuPercent: null },+ quotas: [{ engine: 'claude', known: true, windows: [{ name: 'weekly', usedPercent: 10, resetsAt: null }] }], tools: {}, runningHarnessIds: [], stoppedHarnessIds: [],+ readiness: { engines: [{ engine: 'claude', installed: true, signedIn: true }] } } as never)const add = async (conversationId: string, name: string, lead = false, roleName?: string) => String((await execute({ type: 'agent.add',- conversationId, machineId: 'review-host', harnessId: randomUUID(), name, configuration: opus, lead, ...roleName ? { roleName } : {} } as Command)).result.agentId)+ conversationId, machineId: 'review-host', harnessId: randomUUID(), name, configuration: opus, lead, ...roleName ? { roleName } : {} } as Command, host)).result.agentId)const lead = await add('lead', 'PM', true)const task = String((await execute({ type: 'conversation.create', title: 'Fix sign-in', brief: 'Sign in works offline.', checks: [] })).result.conversationId)const dev = await add(task, 'Dev', false, 'Engineer')diff --git a/backend/integration/superTabTeam.test.ts b/backend/integration/superTabTeam.test.tsindex 4563b8c03..107c78e6e 100644--- a/backend/integration/superTabTeam.test.ts+++ b/backend/integration/superTabTeam.test.ts@@ -81,16 +81,42 @@ async function fixture() {harnessId: randomUUID(), name: 'Personal', configuration: config, lead: false }, person)).result.agentId)await run(tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', engines: ['codex'], maxAgents: 4 }, person)const generation = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === tab)!.machine.generation+ // A Team agent from before Swarm v3 (task #4120): no new agent starts in a Team account now, so this one is started by the+ // machine's own person while its stored reading does not yet say Team, as when Team accounts took work; then its Team session+ // reports again. It keeps what it holds.await store.observeMachine(team, tab, 'team-mac', reading(generation))- const startId = String((await run(tab, { type: 'agent.start', request: { conversationId: teamGroup, machineId: 'team-mac', engine: 'codex',- name: 'Builder', cwd: '/team', worktree: false, requirements } })).result.startId)+ const startId = await asBeforeV3('team-mac', async () => {+ const before = await storedState(tab)+ before.machines!.find(m => m.machineId === 'team-mac')!.observation!.sessionKind = 'computer'+ await saveState(tab, before)+ return String((await run(tab, { type: 'agent.start', request: { conversationId: teamGroup, machineId: 'team-mac', engine: 'codex',+ name: 'Builder', cwd: '/team', worktree: false, requirements } }, person)).result.startId)+ })await hostRun(tab, { type: 'agent.startDispatch', startId })const started = await hostRun(tab, { type: 'agent.started', startId, harnessId: `team-builder-${randomUUID()}`, configuration: config })await hostRun(tab, { type: 'agent.startSettled', startId, warning: null })+ await store.observeMachine(team, tab, 'team-mac', reading(generation))const builder = String(started.result.agentId)return { tab, lead, personal, builder, personalGroup, teamGroup, startId, generation, own }}+/** Runs [body] as before Swarm v3, when a Team account still took work (task #4120): its stored reading reads as the Mac's own for+ * the while, then its Team session reports again. What a Team agent was given then, it keeps. */+async function beforeV3<T>(tab: string, generation: string, body: () => Promise<T>, machineId = 'team-mac', host: AuthUser = team): Promise<T> {+ const state = await storedState(tab)+ state.machines!.find(m => m.machineId === machineId)!.observation!.sessionKind = 'computer'+ await saveState(tab, state)+ try { return await body() } finally { await store.observeMachine(host, tab, machineId, reading(generation)) }+}++/** Makes a start [body] with [machineId]'s account row read as an ordinary computer, as before Swarm v3, when a start there was+ * taken: the start's grant now refuses a Team sign-in's row (commands.ts agent.start, security review 2 of #3446). Only the start:+ * its Team host's own commands need the row as Team, which it is again after. */+async function asBeforeV3<T>(machineId: string, body: () => Promise<T>): Promise<T> {+ await db.machine.update({ where: { machineId }, data: { sessionKind: 'computer' } })+ try { return await body() } finally { await db.machine.update({ where: { machineId }, data: { sessionKind: 'team' } }) }+}+beforeAll(async () => {replica = await MongoMemoryReplSet.create({ binary: { version: '7.0.24', downloadDir: join(tmpdir(), 'harness-super-tab-mongodb-binaries') },replSet: { count: 1, ip: '127.0.0.1', storageEngine: 'wiredTiger' } })@@ -121,7 +147,8 @@ describe('a team session hosting its own machine', () => {expect((await poolRows(store, team, 'team-mac')).map(p => p.tabId)).toContain(f.tab)expect((await rosterRows(store, team, 'team-mac')).filter(r => r.tabId === f.tab).map(r => r.agent.id)).toEqual([f.builder])expect(await store.hostTerminal(team, 'team-mac')).toEqual([])- const assignmentId = String((await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })).result.assignmentId)+ // Its task from before the release (task #4120): a Team agent keeps what it holds, and takes nothing new.+ const assignmentId = String((await beforeV3(f.tab, f.generation, () => run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder }))).result.assignmentId)expect(await assignmentRows(store, team, 'team-mac')).toContainEqual(expect.objectContaining({ tabId: f.tab, assignmentId }))await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation))// The reading is stamped with how the machine is signed in, from the session and never from the request.@@ -167,16 +194,21 @@ describe('a team session hosting its own machine', () => {// Audit H2: Team-written code stays out of the main account, through the real store, and the mark survives a save and a load.describe('a task a Team agent worked on', () => {- const owners = async (tab: string, conversationId: string) => String((await run(tab, { type: 'agent.add', conversationId, machineId: 'owner-host',- harnessId: randomUUID(), name: 'Owner Reviewer', configuration: config, lead: false })).result.agentId)+ // The agent the guard bars: a teammate's own, on their own Mac. Only the project owner's own agent may take it (task #4120).+ const owners = async (tab: string, conversationId: string) => String((await run(tab, { type: 'agent.add', conversationId, machineId: 'personal-mac',+ harnessId: randomUUID(), name: 'Mate Reviewer', configuration: config, lead: false }, person)).result.agentId)const task = async (tab: string, title: string) => String((await run(tab, { type: 'conversation.create', projectId: 'lead', title, brief: 'Do it', checks: [] })).result.conversationId)const step = async (tab: string, reviewOf: string) => String((await run(tab, { type: 'conversation.create', projectId: 'lead', title: 'Review', brief: 'Read it', reviewOf, step: 'Review', checks: [] })).result.conversationId)it('keeps its mark through a save and a load, and refuses the main account\'s agent on its step', async () => {- const { tab, builder, teamGroup } = await fixture()+ const { tab, builder, teamGroup, generation } = await fixture()const free = await task(tab, 'Free')const main = await owners(tab, free)- await run(tab, { type: 'work.assign', conversationId: teamGroup, agentId: builder })+ // Built by the Team agent before the release, and marked then, as that release left it (task #4120).+ await beforeV3(tab, generation, () => run(tab, { type: 'work.assign', conversationId: teamGroup, agentId: builder }))+ const marked = await storedState(tab)+ Object.assign(marked.conversations.find(c => c.id === teamGroup)!, { teamWritten: true, teamWrittenBy: { kind: 'assigned' } })+ await saveState(tab, marked)expect((await storedState(tab)).conversations.find(c => c.id === teamGroup)?.teamWritten).toBe(true)const review = await step(tab, teamGroup)await expect(run(tab, { type: 'work.assign', conversationId: review, agentId: main })).rejects.toMatchObject({ code: 'TEAM_WRITTEN_WORK', status: 403 })@@ -200,14 +232,17 @@ describe('a task a Team agent worked on', () => {await expect(run(tab, { type: 'work.assign', conversationId: review, agentId: main })).rejects.toMatchObject({ code: 'TEAM_WRITTEN_WORK' })})- it('stores a mark set from a step on its task, and tells the main-account members in their own chats', async () => {- const { tab, builder } = await fixture()+ it('stores a mark set from a step on its task, and tells the members it bars in their own chats', async () => {+ const { tab } = await fixture()const clean = await task(tab, 'Owner work'), main = await owners(tab, clean), review = await step(tab, clean)+ // The project owner's own agent may take it (task #4120): its assignment reads the bot's push and marks the task.+ const ownersOwn = String((await run(tab, { type: 'agent.add', conversationId: review, machineId: 'owner-host', harnessId: randomUUID(),+ name: 'Owner Reviewer', configuration: config, lead: false })).result.agentId)const state = await storedState(tab)state.conversations.find(c => c.id === clean)!.codePullRequestUrls = ['https://github.com/acme/app/pull/9']await saveState(tab, state)const asked = new SuperTabStore(db, Date.now, undefined, { pushOrigin: async () => 'team' })- await asked.execute(owner, tab, { operationId: randomUUID(), command: { type: 'work.assign', conversationId: review, agentId: builder } })+ await asked.execute(owner, tab, { operationId: randomUUID(), command: { type: 'work.assign', conversationId: review, agentId: ownersOwn } })expect((await storedState(tab)).conversations.find(c => c.id === clean)?.teamWritten).toBe(true)const told = await db.superTabMessage.findMany({ where: { tabId: tab, conversationId: clean, text: { startsWith: 'Stop: GitHub shows' } } })expect(told).toHaveLength(1)@@ -308,16 +343,19 @@ describe('a task\'s Team-written mark rests on its own code', () => {const assignment = (await storedState(f.tab)).conversations.find(c => c.id === task)!.assignment!.id// The builder's own pull request, as its status names it.await exec({ type: 'work.status', conversationId: task, assignmentId: assignment, status: 'working', result: `Draft PR ${OWN}` }, ownBuilder)- /** A main-account agent of the project joining the task: the read River's handover of #3462 met. */- const join = async (name: string) => exec({ type: 'conversation.agent', conversationId: task, agentId: await agentOf('lead', name), present: true, lead: false })+ /** An agent the guard bars: a teammate's own, on their own Mac (only the project owner's own may take it, task #4120). */+ const mateOf = async (conversationId: string, name: string) => String((await run(f.tab, { type: 'agent.add', conversationId, machineId: 'personal-mac',+ harnessId: randomUUID(), name, configuration: config, lead: false }, person)).result.agentId)+ /** A teammate's agent of the project joining the task: the read River's handover of #3462 met. */+ const join = async (name: string) => exec({ type: 'conversation.agent', conversationId: task, agentId: await mateOf('lead', name), present: true, lead: false })const marked = async (id: string) => (await storedState(f.tab)).conversations.find(c => c.id === id)?.teamWritten === true- return { ...f, read, exec, execTeam, agentOf, join, task, ownBuilder, marked }+ return { ...f, read, exec, execTeam, agentOf, mateOf, join, task, ownBuilder, marked }}it('does not read a Team pull request another agent linked in the task, and still reads the task\'s own', async () => {const f = await setup()- // A Team agent's log lines in the task, as in #3514.- await f.execTeam({ type: 'message.send', conversationId: f.task, text: `Log: CI on ${TEAM_PR} failed at step 3`, replyTo: null, recipientIds: [] }, f.builder)+ // A Team agent's log lines in the task, as in #3514, posted before the release: a Team agent joins nothing new now (task #4120).+ await beforeV3(f.tab, f.generation, () => f.execTeam({ type: 'message.send', conversationId: f.task, text: `Log: CI on ${TEAM_PR} failed at step 3`, replyTo: null, recipientIds: [] }, f.builder))await expect(f.join('Owner Builder 2')).resolves.toBeTruthy()expect(f.read).toHaveBeenLastCalledWith(REPO, [OWN])expect(await f.marked(f.task)).toBe(false)@@ -341,15 +379,15 @@ describe('a task\'s Team-written mark rests on its own code', () => {const f = await setup()const bare = String((await run(f.tab, { type: 'conversation.create', projectId: 'lead', title: 'Owner work 2', brief: 'Do it', checks: [] })).result.conversationId)await run(f.tab, { type: 'message.send', conversationId: bare, text: `Start from ${TEAM_PR}.`, replyTo: null, recipientIds: [] })- const next = await f.agentOf('lead', 'Owner Builder 3')+ const next = await f.mateOf('lead', 'Mate Builder 3')await expect(f.exec({ type: 'conversation.agent', conversationId: bare, agentId: next, present: true, lead: false })).rejects.toMatchObject({ code: 'TEAM_WRITTEN_WORK' })})it('marks a step for a Team pull request its reviewer names in its Ready, never the task; a link posted there marks nothing', async () => {const f = await setup()const review = String((await run(f.tab, { type: 'conversation.create', projectId: 'lead', title: 'Review', brief: 'Read it', reviewOf: f.task, step: 'Review', checks: [] })).result.conversationId)- // A Team-account reviewer, as #3462's were.- await f.exec({ type: 'work.assign', conversationId: review, agentId: f.builder })+ // A Team-account reviewer, as #3462's were, given the step before the release (task #4120).+ await beforeV3(f.tab, f.generation, () => f.exec({ type: 'work.assign', conversationId: review, agentId: f.builder }))const step = (await storedState(f.tab)).conversations.find(c => c.id === review)!await run(f.tab, { type: 'message.send', conversationId: review, text: `Same bug as ${TEAM_PR}.`, replyTo: null, recipientIds: [] })await f.execTeam({ type: 'work.status', conversationId: review, assignmentId: step.assignment!.id, status: 'working', result: 'Reading it' }, f.builder)@@ -386,12 +424,20 @@ describe('a start whose account cannot reach the project repository', () => {state.projects!.find(p => p.id === 'lead')!.repository = { machineId: 'owner-host', cwd: '/repo', repositoryUrl: 'https://github.com/acme/app' }await saveState(tab, state)}- const startOn = (asked: SuperTabStore, tab: string, conversationId: string) => asked.execute(owner, tab, { operationId: randomUUID(), command: { type: 'agent.start',- request: { conversationId, machineId: 'team-mac', engine: 'codex', name: 'Reviewer', cwd: '/team', worktree: false, requirements } } })+ // A teammate's own agent, started by them on their own Mac (task #4120: no start lands in a Team account now): it reaches the+ // owner's repository only through the Harness GitHub App, as a Team account did.+ const personalMac = async (tab: string) => {+ await run(tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)+ const generation = (await poolRows(store, person, 'personal-mac')).find(p => p.tabId === tab)!.machine.generation+ await store.observeMachine(person, tab, 'personal-mac', reading(generation))+ }+ const startOn = (asked: SuperTabStore, tab: string, conversationId: string) => asked.execute(person, tab, { operationId: randomUUID(), command: { type: 'agent.start',+ request: { conversationId, machineId: 'personal-mac', engine: 'codex', name: 'Reviewer', cwd: '/work/lead', worktree: false, requirements } } })const starts = async (tab: string) => (await storedState(tab)).starts?.length ?? 0it('is refused through the store before anything is queued, from the access it reads for that project', async () => {const { tab, teamGroup } = await fixture()+ await personalMac(tab)await withRepository(tab)const reach = vi.fn(async () => ({ state: 'not-installed' as const, repository: 'acme/app', installUrl: 'https://github.com/apps/harness/installations/new' }))const asked = new SuperTabStore(db, Date.now, undefined, { repositoryReach: reach })@@ -404,6 +450,7 @@ describe('a start whose account cannot reach the project repository', () => {it('starts as before when the read fails, and reads nothing for a project with no GitHub repository', async () => {const { tab, teamGroup } = await fixture()+ await personalMac(tab)const reach = vi.fn(async () => { throw new Error('GitHub did not answer') })const asked = new SuperTabStore(db, Date.now, undefined, { repositoryReach: reach })await expect(startOn(asked, tab, teamGroup)).resolves.toBeTruthy()@@ -486,42 +533,16 @@ describe('a team session speaking in a Swarm', () => {expect((await store.read(owner, f.tab)).state.machines!.map(m => m.machineId)).toEqual(['team-mac'])})- // Tasks #2178 and #2215 (11-02): a Team Engineer could not assign its review step to a Reviewer on another Team machine,- // and the PM had to. Assigning or adding an agent that also runs in a Team account never reaches a main account; typing into its- // terminal or reading it still would cross a machine, and anything in the main account stays out of reach.- it('assigns and adds an agent in another machine\'s Team account, and still reaches nothing in a main account', async () => {+ // Task #4120: a Team agent takes no new work and starts none, so the Team-to-Team review hand-over of #2178 and #2215 is gone. What+ // stays: a team session reaches nothing in a main account, for every command.+ it('still reaches nothing in a main account', async () => {const f = await fixture()- await run(f.tab, { type: 'machine.contribute', machineId: 'owner-team-mac', name: 'Mac Studio · Team', cwd: '/team', engines: ['codex'], maxAgents: 4 })- const generation = (await poolRows(store, ownerTeam, 'owner-team-mac')).find(p => p.tabId === f.tab)!.machine.generation- await store.observeMachine(ownerTeam, f.tab, 'owner-team-mac', reading(generation))- await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })- const review = String((await run(f.tab, { type: 'conversation.create', projectId: 'lead', title: 'Review', brief: 'Review it', reviewOf: f.teamGroup,- step: 'Review', checks: [] })).result.conversationId)- const startId = String((await run(f.tab, { type: 'agent.start', request: { conversationId: review, machineId: 'owner-team-mac', engine: 'codex',- name: 'Reviewer', cwd: '/team', worktree: false, requirements } })).result.startId)- await hostRun(f.tab, { type: 'agent.startDispatch', startId }, 'owner-team-mac', ownerTeam)- const reviewer = String((await hostRun(f.tab, { type: 'agent.started', startId, harnessId: `owner-team-reviewer-${randomUUID()}`, configuration: config },- 'owner-team-mac', ownerTeam)).result.agentId)- await hostRun(f.tab, { type: 'agent.startSettled', startId, warning: null }, 'owner-team-mac', ownerTeam)const refused = vi.spyOn(logger, 'warn')onTestFinished(() => refused.mockRestore())-- // The Engineer in the person's Team account hands its review to the Reviewer in the owner's.- await run(f.tab, { type: 'conversation.agent', conversationId: review, agentId: reviewer, present: false, lead: false }, team, f.builder)- await run(f.tab, { type: 'conversation.agent', conversationId: review, agentId: reviewer, present: true, lead: false }, team, f.builder)- expect((await run(f.tab, { type: 'work.assign', conversationId: review, agentId: reviewer }, team, f.builder)).result.assignmentId).toBeTruthy()- expect((await storedState(f.tab)).conversations.find(c => c.id === review)!.assignment).toMatchObject({ agentId: reviewer, status: 'working' })- expect(refused).not.toHaveBeenCalledWith('[super-tab] team command refused', expect.anything())-- // The same Reviewer's terminal stays its own machine's; so does the person's main-account agent, for every command.- for (const command of [{ type: 'agent.screen', agentId: reviewer }, { type: 'agent.input', agentId: reviewer, text: 'echo hi' },- { type: 'agent.release', agentId: reviewer, decision: 'stop' }, { type: 'agent.stopLease', agentId: reviewer, releaseId: 'release-1' },- { type: 'work.assign', conversationId: f.personalGroup, agentId: f.personal },+ for (const command of [{ type: 'work.assign', conversationId: f.personalGroup, agentId: f.personal },{ type: 'conversation.agent', conversationId: f.teamGroup, agentId: f.personal, present: true, lead: false }] as Command[]) {await expect(run(f.tab, command, team, f.builder), command.type).rejects.toMatchObject(LIMITED)}- expect(refused).toHaveBeenCalledWith('[super-tab] team command refused', expect.objectContaining({ tabId: f.tab, command: 'agent.input',- teamMachineId: 'team-mac', targetMachineId: 'owner-team-mac', targetTeamAccount: true }))expect(refused).toHaveBeenCalledWith('[super-tab] team command refused', expect.objectContaining({ command: 'work.assign',targetMachineId: 'personal-mac', targetTeamAccount: false }))})@@ -530,7 +551,7 @@ describe('a team session speaking in a Swarm', () => {const f = await fixture()const assign = async (conversationId: string, agentId: string) =>String((await run(f.tab, { type: 'work.assign', conversationId, agentId })).result.assignmentId)- const personalWork = await assign(f.personalGroup, f.personal), teamWork = await assign(f.teamGroup, f.builder)+ const personalWork = await assign(f.personalGroup, f.personal), teamWork = await beforeV3(f.tab, f.generation, () => assign(f.teamGroup, f.builder))await expect(store.stopped(team, f.tab, personalWork, 'stopped')).rejects.toMatchObject(LIMITED)expect(await store.stopped(team, f.tab, teamWork, 'stopped')).toEqual({ confirmed: true })@@ -552,7 +573,7 @@ describe('a team session speaking in a Swarm', () => {it('what it records from its own agent\'s terminal reaches the Lead as the agent\'s, never as the person\'s', async () => {const f = await fixture()await run(f.tab, { type: 'conversation.agent', conversationId: f.teamGroup, agentId: f.lead, present: true, lead: true })- await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })+ await beforeV3(f.tab, f.generation, () => run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder }))const gap = (turnId: string, incidentId: string) => ({ turnId, kind: 'gap' as const, previousEventId: null, text: '', truncated: false,interrupted: false, gap: { incidentId, reason: 'recording_restarted' as const, detectedAt: Date.now() + 1000 } })const opened = await store.native.open(person, f.tab, { operationId: randomUUID(), conversationId: f.teamGroup, agentId: f.builder })@@ -572,7 +593,7 @@ describe('a team session speaking in a Swarm', () => {it('gets a GitHub token only as an agent on its own machine, naming its own machine (Task 4)', async () => {const f = await fixture()- await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })+ await beforeV3(f.tab, f.generation, () => run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder }))await run(f.tab, { type: 'work.assign', conversationId: f.personalGroup, agentId: f.personal })expect(await store.githubAssignment(team, f.tab, f.builder, 'team-mac')).toMatchObject({ tabId: f.tab, agentId: f.builder })// As the person's agent on their personal Mac: refused before anything is read about the task.@@ -642,15 +663,15 @@ describe('a team session speaking in a Swarm', () => {})})-// Teammates' work runs only on Team machines (Task 3): the owner's project on the person's machines needs the person's-// Harness Team account with its privacy check passed. The person's own projects run on the person's machines as before.+// Teammates' work once ran only on Team machines (Task 3). Swarm v3 (task #4120) has none: a person's own agent works on any task of a+// project they read, in their own account. What reads a Team machine's privacy is unchanged until its entries go.describe('a teammate\'s work and the machines that take it', () => {// With the rule required everywhere, as it will be once team accounts can be made (machines.ts teamAccountRequired).beforeAll(() => { process.env.SWARM_TEAM_ACCOUNT_REQUIRED = '1' })afterAll(() => { delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED })/** The person's personal MacBook, contributed for every project, reporting from the person's own sign-in. */async function personalMac(f: Awaited<ReturnType<typeof fixture>>) {- await run(f.tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 2 }, person)+ await run(f.tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)const generation = (await poolRows(store, person, 'personal-mac')).find(p => p.tabId === f.tab)!.machine.generationawait store.observeMachine(person, f.tab, 'personal-mac', reading(generation))return generation@@ -686,66 +707,44 @@ describe('a teammate\'s work and the machines that take it', () => {await expect(store.observeMachine(person, f.tab, 'team-mac', reading(f.generation))).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY' })})- it('refuses the owner\'s project on the person\'s personal Mac and admits it on their Team machine; the person\'s own work is unchanged', async () => {+ // Swarm v3 (task #4120, the PM's rulings): no Team account takes work, a new agent starts only on its own person's computer, and a+ // person's own agent works on any task of a project they can read, in their own account.+ it('runs the owner\'s project on the person\'s own Mac when they start it, and on no Team machine; the person\'s own work is unchanged', async () => {const f = await fixture()await personalMac(f)- await expect(start(f.tab, f.teamGroup, 'personal-mac')).rejects.toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', status: 403, message: NO_TEAM_ACCOUNT })- expect((await start(f.tab, f.teamGroup, 'team-mac')).result.startId).toBeTruthy()+ expect((await start(f.tab, f.teamGroup, 'personal-mac', person)).result.startId).toBeTruthy()+ expect((await storedState(f.tab)).starts!.at(-1)!.request.machineId).toBe('personal-mac')+ await expect(start(f.tab, f.teamGroup, 'personal-mac')).rejects.toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ await expect(start(f.tab, f.teamGroup, 'team-mac', person)).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })expect((await start(f.tab, f.personalGroup, 'personal-mac', person, `/work/${f.own}`)).result.startId).toBeTruthy()- // Off the Machines list nothing shows a privacy check, so the person's uncontributed laptop never takes the owner's project.- await expect(start(f.tab, f.teamGroup, 'personal-laptop', person, '/work')).rejects.toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED' })})- it('refuses it on a Team machine whose check failed, is missing or went stale', async () => {- const f = await fixture()- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation, FAILED))- await expect(start(f.tab, f.teamGroup, 'team-mac')).rejects.toMatchObject({ code: 'PRIVACY_CHECK_FAILED',- message: 'The Harness Team account on MacBook Pro · Team is not private (gitconfig: it could read its owner\'s ~/.gitconfig), so it runs only its owner\'s projects.' })- // A reading with no check at all (the person's own sign-in may no longer report for it, security review 2 of #2089).- const { privacy: _privacy, ...unchecked } = reading(f.generation) as Record<string, unknown>- await store.observeMachine(team, f.tab, 'team-mac', unchecked as Parameters<SuperTabStore['observeMachine']>[3])- await expect(start(f.tab, f.teamGroup, 'team-mac')).rejects.toMatchObject({ code: 'PRIVACY_UNCHECKED' })- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation))- // Twenty minutes on, the team daemon still sends the same check: it stopped running.- const later = new SuperTabStore(db, () => Date.now() + 20 * 60_000)- await later.observeMachine(team, f.tab, 'team-mac', reading(f.generation))- await expect(start(f.tab, f.teamGroup, 'team-mac', owner, '/team', later)).rejects.toMatchObject({ code: 'PRIVACY_CHECK_STALE' })- expect((await pool(f.tab, 'team-mac', owner, later)).teamWork.reason).toMatch(/^The privacy check on MacBook Pro · Team last passed 20 minutes ago/)- })-- it('refuses work.assign of the owner\'s project to an agent on the person\'s personal Mac', async () => {+ it('assigns the owner\'s project to the person\'s own agent on their Mac, and nothing new to the Team agent', async () => {const f = await fixture()await personalMac(f)// The person added an agent of theirs to the owner's project by hand.const volunteer = String((await run(f.tab, { type: 'agent.add', conversationId: f.teamGroup, machineId: 'personal-mac', harnessId: randomUUID(),name: 'Volunteer', configuration: config, lead: false }, person)).result.agentId)- await expect(run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: volunteer })).rejects.toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', message: NO_TEAM_ACCOUNT })- expect((await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })).result.assignmentId).toBeTruthy()+ await expect(run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: f.builder })).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect((await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: volunteer })).result.assignmentId).toBeTruthy()// The person's own project, to the person's own agent there, as before.expect((await run(f.tab, { type: 'work.assign', conversationId: f.personalGroup, agentId: f.personal }, person)).result.assignmentId).toBeTruthy()})- // Joining a task by a post or by opening one checks team access as adding one does (spec, "Kept as access"; final review).- it('refuses to add an agent on the person\'s personal Mac to the owner\'s task by naming it, by its own post or by its new task', async () => {+ it('adds the person\'s own agent to the owner\'s task by naming it or by its own post, and names the Team agent into nothing new', async () => {const f = await fixture()await personalMac(f)- // The person added an agent of theirs to the owner's project chat by hand: an agent of that project, in no task.const volunteer = String((await run(f.tab, { type: 'agent.add', conversationId: 'lead', machineId: 'personal-mac', harnessId: randomUUID(),name: 'Volunteer', configuration: config, lead: false }, person)).result.agentId)- const post = (recipientIds: string[]) => ({ type: 'message.send', conversationId: f.teamGroup, text: 'Look at this.', replyTo: null, recipientIds }) as Command- const refused = { code: 'TEAM_ACCOUNT_REQUIRED', message: NO_TEAM_ACCOUNT }- await expect(run(f.tab, post([volunteer]), owner, f.lead)).rejects.toMatchObject(refused)- await expect(run(f.tab, post([]), person, volunteer)).rejects.toMatchObject(refused)- await expect(run(f.tab, { type: 'conversation.create', title: 'Its own task', brief: 'Do it', checks: [{ description: 'Done', independent: false }], priority: 'P2', requesterId: person.sub }, person, volunteer)).rejects.toMatchObject(refused)- const task = (await store.read(owner, f.tab)).state.conversations.find(c => c.id === f.teamGroup)!- expect(task.agentIds).not.toContain(volunteer)- // The agent on the person's Team machine is named into another task of the owner's project.+ const post = (recipientIds: string[], conversationId = f.teamGroup) => ({ type: 'message.send', conversationId, text: 'Look at this.', replyTo: null, recipientIds }) as Command+ await run(f.tab, post([volunteer]), owner, f.lead)+ expect((await store.read(owner, f.tab)).state.conversations.find(c => c.id === f.teamGroup)!.agentIds).toContain(volunteer)const other = String((await run(f.tab, { type: 'conversation.create', title: 'Second', brief: 'Do it', checks: [] })).result.conversationId)- await run(f.tab, { type: 'message.send', conversationId: other, text: 'Take a look.', replyTo: null, recipientIds: [f.builder] }, owner, f.lead)- expect((await store.read(owner, f.tab)).state.conversations.find(c => c.id === other)!.agentIds).toContain(f.builder)+ await expect(run(f.tab, post([f.builder], other), owner, f.lead)).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect((await store.read(owner, f.tab)).state.conversations.find(c => c.id === other)!.agentIds).not.toContain(f.builder)})- it('routes the owner\'s project around the machines that cannot take it, records why, and refuses a pick or reroute there', async () => {+ it('routes the owner\'s project past Team machines and new agents on another person\'s computer, records why, and refuses a pick there', async () => {const f = await fixture()await personalMac(f)const volunteer = String((await run(f.tab, { type: 'agent.add', conversationId: f.teamGroup, machineId: 'personal-mac', harnessId: randomUUID(),@@ -755,59 +754,40 @@ describe('a teammate\'s work and the machines that take it', () => {const decision = (pick: string) => ({ assessment: { difficulty: 'medium' as const, risk: 'low' as const, why: 'A small change.' },candidates: [candidate('c0', 'team-mac'), candidate('c1', 'personal-mac'), candidate('c2', 'personal-mac', { kind: 'member', agentId: volunteer, title: 'Volunteer · personal-mac' })],excluded: [], floor: 2, notes: false, pick, via: 'order' as const, p: null, belowFloor: false, why: 'Policy order.' })- const routed = await run(f.tab, { type: 'route.record', conversationId: f.teamGroup, decision: decision('c0') }, owner, f.lead)+ const routed = await run(f.tab, { type: 'route.record', conversationId: f.teamGroup, decision: decision('c2') }, owner, f.lead)const recorded = await store.routeDecision(owner, f.tab, String(routed.result.routeDecisionId))- expect(recorded.record.candidates.map(c => c.id)).toEqual(['c0'])- expect(recorded.record.excluded).toEqual([{ title: 'Builder · personal-mac', reason: NO_TEAM_ACCOUNT }, { title: 'Volunteer · personal-mac', reason: NO_TEAM_ACCOUNT }])- await expect(run(f.tab, { type: 'route.record', conversationId: f.teamGroup, decision: decision('c1') }, owner, f.lead))- .rejects.toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', message: `${NO_TEAM_ACCOUNT} Route again.` })- // A person's reroute to a machine that stopped showing its privacy since the route.- const both = await run(f.tab, { type: 'route.record', conversationId: f.teamGroup, decision: { ...decision('c1'), candidates: [candidate('c0', 'team-mac'), candidate('c1', 'owner-host')] } }, owner, f.lead)- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation, FAILED))- await expect(run(f.tab, { type: 'route.override', decisionId: String(both.result.routeDecisionId), candidateId: 'c0', reason: 'More quota there.' }))- .rejects.toMatchObject({ code: 'PRIVACY_CHECK_FAILED' })+ expect(recorded.record.candidates.map(c => c.id)).toEqual(['c2'])+ expect(recorded.record.excluded.map(e => e.title)).toEqual(['Builder · team-mac', 'Builder · personal-mac'])+ await expect(run(f.tab, { type: 'route.record', conversationId: f.teamGroup, decision: decision('c0') }, owner, f.lead))+ .rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })})- it('fails a queued start its Team machine will not take for good, and keeps one that waits on a stale check', async () => {+ it('refuses at its launch a start queued in a Team account before the release', async () => {const f = await fixture()- const queued = String((await start(f.tab, f.teamGroup, 'team-mac')).result.startId)- // The check failed before the team daemon launched it: the start fails with that reason, the group is told.- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation, FAILED))- await expect(hostRun(f.tab, { type: 'agent.startDispatch', startId: queued })).rejects.toMatchObject({ code: 'PRIVACY_CHECK_FAILED' })- const failed = (await store.read(owner, f.tab)).state.starts!.find(s => s.id === queued)!- expect(failed).toMatchObject({ dispatched: false, error: expect.stringContaining('is not private (gitconfig') })- // The group reads a generic reason: the check's detail names the machine and files on it (review of #1847).- expect((await store.messages(owner, f.tab, f.teamGroup, {})).messages.at(-1)!.text)- .toBe('Could not start Builder: its machine could not prepare or launch it. Whoever started it, the Product Manager and the machine owner can read why.')- expect((await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.starts.map(s => s.id)).not.toContain(queued)- // A stale check may pass again by itself: that start keeps waiting for it.- const passedAgain = { ...PASSED, checkedAt: Date.now() + 1 }- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation, passedAgain))- const waiting = String((await start(f.tab, f.teamGroup, 'team-mac')).result.startId)- const later = new SuperTabStore(db, () => Date.now() + 20 * 60_000)- await later.observeMachine(team, f.tab, 'team-mac', reading(f.generation, passedAgain))- await expect(later.execute(team, f.tab, { operationId: randomUUID(), command: { type: 'agent.startDispatch', startId: waiting } }, undefined, 'team-mac'))- .rejects.toMatchObject({ code: 'PRIVACY_CHECK_STALE' })- expect((await store.read(owner, f.tab)).state.starts!.find(s => s.id === waiting)).toMatchObject({ dispatched: false, error: null })- })-- it('never fails a start its host already launched when the dispatch is repeated after the check failed', async () => {+ const queued = String((await beforeV3(f.tab, f.generation, () => asBeforeV3('team-mac', () => start(f.tab, f.teamGroup, 'team-mac', person)))).result.startId)+ await expect(hostRun(f.tab, { type: 'agent.startDispatch', startId: queued })).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect((await store.read(owner, f.tab)).state.starts!.find(s => s.id === queued)).toMatchObject({ dispatched: false })+ })++ it('never fails a start its host already launched before the release when the dispatch is repeated', async () => {const f = await fixture()- const launched = String((await start(f.tab, f.teamGroup, 'team-mac')).result.startId)- await hostRun(f.tab, { type: 'agent.startDispatch', startId: launched })- await store.observeMachine(team, f.tab, 'team-mac', reading(f.generation, FAILED))- await expect(hostRun(f.tab, { type: 'agent.startDispatch', startId: launched })).rejects.toMatchObject({ code: 'PRIVACY_CHECK_FAILED' })+ const launched = await beforeV3(f.tab, f.generation, async () => {+ const id = String((await asBeforeV3('team-mac', () => start(f.tab, f.teamGroup, 'team-mac', person))).result.startId)+ await hostRun(f.tab, { type: 'agent.startDispatch', startId: id })+ return id+ })+ await expect(hostRun(f.tab, { type: 'agent.startDispatch', startId: launched })).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })expect((await store.read(owner, f.tab)).state.starts!.find(s => s.id === launched)).toMatchObject({ dispatched: true, error: null })// Its agent still arrives.expect((await hostRun(f.tab, { type: 'agent.started', startId: launched, harnessId: `launched-${randomUUID()}`, configuration: config })).result.agentId).toBeTruthy()})- it('leaves agents already working for the owner\'s project on a personal Mac running; only new work for them is refused', async () => {+ it('leaves agents already working for the owner\'s project on a personal Mac running, and gives them new work', async () => {const f = await fixture()const generation = await personalMac(f)const old = String((await run(f.tab, { type: 'agent.add', conversationId: f.teamGroup, machineId: 'personal-mac', harnessId: 'before-release',name: 'Old', configuration: config, lead: false }, person)).result.agentId)- // Its task was assigned by a release from before the rule: written into the stored Swarm as that release left it.+ // Its task was assigned by a release from before: written into the stored Swarm as that release left it.const state = await storedState(f.tab)const work = state.conversations.find(c => c.id === f.teamGroup)!work.assignment = { id: 'assigned-before', agentId: old, status: 'working', configuration: config, result: null,@@ -821,8 +801,8 @@ describe('a teammate\'s work and the machines that take it', () => {await run(f.tab, { type: 'work.status', conversationId: f.teamGroup, assignmentId: 'assigned-before', status: 'blocked', hold: quotaReset(), result: 'Needs a token.' }, person, old)await run(f.tab, { type: 'message.send', conversationId: f.teamGroup, text: 'Here it is.', replyTo: null, recipientIds: [old] })expect(await db.superTabDelivery.count({ where: { tabId: f.tab, agentId: old } })).toBeGreaterThan(0)- await run(f.tab, { type: 'work.cancel', conversationId: f.teamGroup, assignmentId: 'assigned-before', reason: 'Moving it to the Team machine.' })- await expect(run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: old })).rejects.toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED' })+ await run(f.tab, { type: 'work.cancel', conversationId: f.teamGroup, assignmentId: 'assigned-before', reason: 'Starting it again.' })+ expect((await run(f.tab, { type: 'work.assign', conversationId: f.teamGroup, agentId: old })).result.assignmentId).toBeTruthy()})})@@ -897,7 +877,7 @@ describe('one machine: a Mac and its Harness Team account', () => {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 () => {+ it('the Mac\'s host adds its team account, and the owner\'s project started on the Mac stays on the Mac (task #4120)', async () => {await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: 'personal-mac' } })try {const tab = (await store.create(owner, randomUUID(), 'One machine')).id@@ -920,11 +900,14 @@ describe('one machine: a Mac and its Harness Team account', () => {await store.observeMachine(team, tab, 'team-mac', reading(generation))const group = String((await run(tab, { type: 'conversation.create', projectId: 'lead', title: 'Work', brief: 'Do it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)+ // Started by the Mac's own person: it runs on the Mac, in their own account, and never moves into the Team account.+ const personalGeneration = (await poolRows(store, person, 'personal-mac')).find(p => p.tabId === tab)!.machine.generation+ await store.observeMachine(person, tab, 'personal-mac', reading(personalGeneration))const started = await run(tab, { type: 'agent.start', request: { conversationId: group, machineId: 'personal-mac', engine: 'codex', name: 'Builder',- cwd: '/work/lead', worktree: false, requirements } })- const queued = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === tab)!.starts- expect(queued).toEqual([expect.objectContaining({ id: started.result.startId, request: expect.objectContaining({ machineId: 'team-mac', cwd: '/team/lead' }) })])- expect((await poolRows(store, person, 'personal-mac')).find(p => p.tabId === tab)!.starts).toEqual([])+ cwd: '/work/lead', worktree: false, requirements } }, person)+ expect((await poolRows(store, team, 'team-mac')).find(p => p.tabId === tab)!.starts).toEqual([])+ expect((await poolRows(store, person, 'personal-mac')).find(p => p.tabId === tab)!.starts)+ .toEqual([expect.objectContaining({ id: started.result.startId, request: expect.objectContaining({ machineId: 'personal-mac', cwd: '/work/lead' }) })])} finally {await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: null } })}@@ -1077,169 +1060,40 @@ describe('one machine: a Mac and its Harness Team account', () => {// A project's Product Manager on another person's Team machine (leadStart.ts, Dee 10-29): on the machine its person names// (Ken 10-29), launched from a list older hosts do not read, and the project's Lead once it runs.-describe('a project\'s Product Manager on a teammate\'s Team machine', () => {+// Swarm v3 (task #4120, the PM's ruling): a Product Manager starts only on its own person's computer, never in a Team account. A PM+// already in a Team account from before keeps running until it is stopped; its terminal privacy and its hold on the account are+// covered in leadStart.test.ts, with the PM placed as that release left it.+describe('a project\'s Product Manager and a teammate\'s machines', () => {const capable = (generation: string) => ({ ...reading(generation), capabilities: ['leadStart'] }) as Parameters<SuperTabStore['observeMachine']>[3]- it('needs a machine named, starts on the Team machine named, and leads the project', async () => {+ it('needs a machine named, and never starts on a Team machine', async () => {const f = await fixture()const created = (await run(f.tab, { type: 'project.create', name: 'App', visibility: 'private', brief: 'Build it.' })).result- const projectId = String(created.projectId), home = String(created.conversationId)+ const projectId = String(created.projectId)// Only its person knows which machine stays on: none is chosen for them.await expect(run(f.tab, { type: 'lead.start', projectId, machineId: null, engine: 'codex', repositoryUrl: 'https://github.com/example/app' })).rejects.toMatchObject({ code: 'MACHINE_REQUIRED', status: 400 })- expect((await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.leadStarts).toBeUndefined()- // Contributed for every project, as a Mac added to a Swarm with projects is; the fixture's serves only the first. Its- // Builder of that first project goes, so the account can serve this project alone.await run(f.tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)- await run(f.tab, { type: 'agent.remove', agentId: f.builder })const generation = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.machine.generationawait store.observeMachine(team, f.tab, 'team-mac', capable(generation))- await run(f.tab, { type: 'lead.start', projectId, machineId: 'team-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' })- const row = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!- expect(row.leadStarts).toEqual([expect.objectContaining({ request: expect.objectContaining({ machineId: 'team-mac', cwd: `/team/${projectId}`,- leadFor: expect.objectContaining({ projectId, personId: owner.sub }) }) })])- expect(row.starts.some(s => s.request.leadFor)).toBe(false)- const startId = row.leadStarts![0]!.id- await hostRun(f.tab, { type: 'agent.startDispatch', startId })- const agentId = String((await hostRun(f.tab, { type: 'agent.started', startId, harnessId: `team-pm-${randomUUID()}`, configuration: config })).result.agentId)- const read = await store.read(owner, f.tab)- expect(read.state.conversations.find(c => c.id === home)).toMatchObject({ leadId: agentId })- expect(read.state.projects!.find(p => p.id === projectId)!.lead).toMatchObject({ status: 'started', machineId: 'team-mac' })- expect((await store.messages(owner, f.tab, home, {})).messages.map(m => m.text))- .toEqual(expect.arrayContaining(['Product Manager started on MacBook Pro · Team.']))- })-- // The isolated confidential run (docs/performance/2026-10-27-pm-confidential-isolated-run.test.mts), its Team machine case:- // a Product Manager in another person's Team account, every way of watching or driving it through the Swarm.- it('in another person\'s Team account: its project\'s owner only watches it, and the Mac\'s owner neither watches nor drives it', async () => {- const f = await fixture()- const created = (await run(f.tab, { type: 'project.create', name: 'App', visibility: 'public', brief: '' })).result- const projectId = String(created.projectId)- await run(f.tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)- const generation = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.machine.generation- await store.observeMachine(team, f.tab, 'team-mac', capable(generation))- // The fixture's own Builder of the owner's first project runs there: it goes first, so the account serves one project.- await run(f.tab, { type: 'agent.remove', agentId: f.builder })- const placed = await run(f.tab, { type: 'lead.start', projectId, machineId: 'team-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' })- const startId = String(placed.result.startId)- await hostRun(f.tab, { type: 'agent.startDispatch', startId })- const pm = String((await hostRun(f.tab, { type: 'agent.started', startId, harnessId: `team-pm-${randomUUID()}`, configuration: config })).result.agentId)- const terminal = (user: AuthUser, command: Command) => run(f.tab, command, user).then(() => 'ok', (error: { code?: string }) => error.code)- expect(await terminal(owner, { type: 'agent.screen', agentId: pm, scrollback: 50 })).toBe('ok')- expect(await terminal(owner, { type: 'agent.input', agentId: pm, text: 'ls ~' })).toBe('TERMINAL_PRIVATE')- expect(await terminal(person, { type: 'agent.screen', agentId: pm, scrollback: 50 })).toBe('TERMINAL_PRIVATE')- expect(await terminal(person, { type: 'agent.input', agentId: pm, text: 'ls ~' })).toBe('TERMINAL_PRIVATE')- // Its host's roster: confidential, watched by its project's owner alone, never by the Mac's owner.- const row = (await rosterRows(store, team, 'team-mac')).find(r => r.tabId === f.tab && r.agent.id === pm)!- expect(row).toMatchObject({ confidential: true })- expect(row.observers.map((o: { email: string }) => o.email)).toEqual([owner.email])- // Security review 2 of #2089: the Mac owner's own sign-in, ordinary tools, cannot act as the Team machine's host or as- // its Product Manager: no reading the chats it reads, no claiming its deliveries, no posting as it.- // People talk to the PM in its project's conversation (Chat with PM is closed on main): what it reads there, it reads.- const chat = String(created.conversationId)- await run(f.tab, { type: 'message.send', conversationId: chat, text: 'For the PM: the launch slips a week.', replyTo: null, recipientIds: [] })- await expect(store.messages(person, f.tab, chat, {}, pm)).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(store.deliveries(person, f.tab, pm)).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(store.execute(person, f.tab, { operationId: randomUUID(), command: { type: 'message.send', conversationId: chat, text: 'as the PM',- replyTo: null, recipientIds: [] } }, pm)).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(store.observeMachine(person, f.tab, 'team-mac', capable(generation))).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- // Its own team session still is its host.- await expect(store.deliveries(team, f.tab, pm)).resolves.toBeInstanceOf(Array)- // An ordinary sign-in connecting as the Team computer resets its account row's mark (lib/adapterWs.ts): the Swarm's own- // record that it is a Team account still refuses the owner (security re-check 2 of #2089).- await db.machine.update({ where: { machineId: 'team-mac' }, data: { sessionKind: 'computer' } })- onTestFinished(async () => { await db.machine.update({ where: { machineId: 'team-mac' }, data: { sessionKind: 'team' } }) })- await expect(store.messages(person, f.tab, chat, {}, pm)).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(store.deliveries(person, f.tab, pm)).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(store.observeMachine(person, f.tab, 'team-mac', capable(generation))).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await expect(rosterRows(store, person, 'team-mac')).rejects.toMatchObject({ code: 'TEAM_HOST_ONLY', status: 403 })- await db.machine.update({ where: { machineId: 'team-mac' }, data: { sessionKind: 'team' } })- // And no other project's work starts there while it runs.- await expect(run(f.tab, { type: 'agent.start', request: { conversationId: f.teamGroup, machineId: 'team-mac', engine: 'codex', name: 'Builder',- cwd: '/team/lead', worktree: true, requirements } })).rejects.toMatchObject({ code: 'TEAM_ACCOUNT_HELD' })- })-- // Review of #2142: the hold outlives its removal through the store's saves and loads, and only its host's confirmed close,- // sent once its session data is deleted, releases it (commands.ts agent.sessionClosed).- it('stays held for its project after its removal until its host confirms the close, across saves and loads', async () => {- const f = await fixture()- const projectId = String((await run(f.tab, { type: 'project.create', name: 'App', visibility: 'public', brief: '' })).result.projectId)- await run(f.tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)- const generation = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.machine.generation- await store.observeMachine(team, f.tab, 'team-mac', capable(generation))- await run(f.tab, { type: 'agent.remove', agentId: f.builder })- const startId = String((await run(f.tab, { type: 'lead.start', projectId, machineId: 'team-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' })).result.startId)- await hostRun(f.tab, { type: 'agent.startDispatch', startId })- const harnessId = `team-pm-${randomUUID()}`- const pm = String((await hostRun(f.tab, { type: 'agent.started', startId, harnessId, configuration: config })).result.agentId)- await hostRun(f.tab, { type: 'agent.startSettled', startId, warning: null })- // A Product Manager leaves with its project.- await run(f.tab, { type: 'project.delete', projectId })- const start = () => run(f.tab, { type: 'agent.start', request: { conversationId: f.teamGroup, machineId: 'team-mac', engine: 'codex', name: 'Builder',- cwd: '/team/lead', worktree: true, requirements } }).then(() => 'started', (error: { code?: string }) => error.code)- // Each command loads the Swarm from its stored parts: the hold is there each time.- expect(await start()).toBe('TEAM_ACCOUNT_HELD')- expect(await start()).toBe('TEAM_ACCOUNT_HELD')- // No one else confirms it: not the Swarm's owner, nor anyone for another session.- await expect(run(f.tab, { type: 'agent.sessionClosed', agentId: pm, harnessId })).rejects.toMatchObject({ code: 'NOT_FOUND' })- await expect(run(f.tab, { type: 'agent.sessionClosed', agentId: pm, harnessId: 'another' }, team)).rejects.toMatchObject({ code: 'NOT_FOUND' })- expect(await start()).toBe('TEAM_ACCOUNT_HELD')- // Nor the Mac's owner from an ordinary sign-in, which shares the Team session's person but is not its host, with no- // purge run (both security reviews of 0a181c00c), even once that sign-in resets the account row's Team mark.- const ordinary = () => run(f.tab, { type: 'agent.sessionClosed', agentId: pm, harnessId }, person).then(() => 'closed', (error: { code?: string }) => error.code)- expect({ forged: await ordinary(), after: await start() }).toEqual({ forged: 'TEAM_HOST_ONLY', after: 'TEAM_ACCOUNT_HELD' })- const row = (await db.machine.findFirst({ where: { machineId: 'team-mac' } }))!- const restore = () => db.machine.update({ where: { machineId: 'team-mac' }, data: { sessionKind: row.sessionKind, hostMachineId: row.hostMachineId } })- await db.machine.update({ where: { machineId: 'team-mac' }, data: { sessionKind: 'computer', hostMachineId: null } })- onTestFinished(async () => { await restore() })- expect({ forged: await ordinary(), after: await start() }).toEqual({ forged: 'TEAM_HOST_ONLY', after: 'TEAM_ACCOUNT_HELD' })- await restore()- await run(f.tab, { type: 'agent.sessionClosed', agentId: pm, harnessId }, team)- expect(await start()).not.toBe('TEAM_ACCOUNT_HELD')- })-- // Security review L3: a coordinator carries on its agents' starts (mayResumeStart), and its Team account's session, by its- // Mac owner's grant, completed one on the owner's personal Mac with a session of its choosing, in the owner's own account.- // Elsewhere it only fails another agent's start.- it('completes only starts on its own machine; another agent\'s start elsewhere it only fails', async () => {- const f = await fixture()- const created = (await run(f.tab, { type: 'project.create', name: 'App', visibility: 'public', brief: '' })).result- const projectId = String(created.projectId)- await run(f.tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)- const generation = (await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.machine.generation- await store.observeMachine(team, f.tab, 'team-mac', capable(generation))- await run(f.tab, { type: 'agent.remove', agentId: f.builder })- const placed = String((await run(f.tab, { type: 'lead.start', projectId, machineId: 'team-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' })).result.startId)- await hostRun(f.tab, { type: 'agent.startDispatch', startId: placed })- const pm = String((await hostRun(f.tab, { type: 'agent.started', startId: placed, harnessId: `team-pm-${randomUUID()}`, configuration: config })).result.agentId)- // The person's own agent of the project, on their personal Mac, starts another there: no contributed machine, so its- // host completes it.- const task = String((await run(f.tab, { type: 'conversation.create', projectId, title: 'Task', brief: 'Do it', checks: [] })).result.conversationId)- const worker = String((await run(f.tab, { type: 'agent.add', conversationId: task, machineId: 'personal-mac', harnessId: randomUUID(), name: 'Worker',- configuration: config, lead: false }, person)).result.agentId)- const request = { conversationId: task, machineId: 'personal-mac', engine: 'codex', name: 'Helper', cwd: '/work', worktree: false, requirements }- const startId = String((await run(f.tab, { type: 'agent.start', request }, person, worker)).result.startId)- const session = `owner-session-${randomUUID()}`- for (const command of [{ type: 'agent.startDispatch', startId }, { type: 'agent.started', startId, harnessId: session, configuration: config },- { type: 'agent.startSettled', startId, warning: null }] as Command[]) {- await expect(run(f.tab, command, team, pm), command.type).rejects.toMatchObject(LIMITED)- }- expect((await store.read(owner, f.tab)).state.agents.some(a => a.harnessId === session)).toBe(false)- await expect(run(f.tab, { type: 'agent.startFailed', startId, error: 'Not started.' }, team, pm)).resolves.toBeDefined()- await expect(run(f.tab, { type: 'agent.started', startId, harnessId: randomUUID(), configuration: config }, person, worker))- .rejects.toMatchObject({ code: 'START_FAILED' })+ await expect(run(f.tab, { type: 'lead.start', projectId, machineId: 'team-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' }))+ .rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect((await poolRows(store, team, 'team-mac')).find(p => p.tabId === f.tab)!.leadStarts ?? []).toEqual([])})- it('on the teammate\'s personal Mac with no Team account, starts there, as its owner (Ken 10-29)', async () => {+ it('never starts on a teammate\'s personal Mac for another person\'s project; on their own project it starts there', async () => {const f = await fixture()const projectId = String((await run(f.tab, { type: 'project.create', name: 'App', visibility: 'private', brief: '' })).result.projectId)- await run(f.tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 2 }, person)+ await run(f.tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 4 }, person)const generation = (await poolRows(store, person, 'personal-mac')).find(p => p.tabId === f.tab)!.machine.generationawait store.observeMachine(person, f.tab, 'personal-mac', capable(generation))- const placed = await run(f.tab, { type: 'lead.start', projectId, machineId: 'personal-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' })+ await expect(run(f.tab, { type: 'lead.start', projectId, machineId: 'personal-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/app' }))+ .rejects.toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ const theirs = String((await run(f.tab, { type: 'project.create', name: 'Theirs', visibility: 'private', brief: '' }, person)).result.projectId)+ const placed = await run(f.tab, { type: 'lead.start', projectId: theirs, machineId: 'personal-mac', engine: 'codex', repositoryUrl: 'https://github.com/example/theirs' }, person)expect(placed.result).toMatchObject({ machineId: 'personal-mac' })expect((await poolRows(store, person, 'personal-mac')).find(p => p.tabId === f.tab)!.leadStarts)- .toEqual([expect.objectContaining({ request: expect.objectContaining({ machineId: 'personal-mac', cwd: `/work/${projectId}` }) })])+ .toEqual([expect.objectContaining({ request: expect.objectContaining({ machineId: 'personal-mac', cwd: `/work/${theirs}` }) })])})})@@ -1254,7 +1108,15 @@ describe('a message from an agent of another account (audit M3)', () => {await run(f.tab, { type: 'machine.contribute', machineId: 'owner-team-mac', name: 'Mac Studio · Team', cwd: '/owner-team', engines: ['codex'], maxAgents: 4 })const generation = (await poolRows(store, ownerTeam, 'owner-team-mac')).find(p => p.tabId === f.tab)!.machine.generationawait store.observeMachine(ownerTeam, f.tab, 'owner-team-mac', reading(generation))- const tester = await startTeam(f, 'Tester')+ // A Team agent from before the release (task #4120): started by the machine's own person, the owner, as it was then, with the+ // Swarm's record that it joined on a Team account.+ const startOld = (name: string) => beforeV3(f.tab, generation, () => startTeam(f, name), 'owner-team-mac', ownerTeam).then(async agentId => {+ const id = `${f.tab}:${agentId}`+ const part = await db.swarmAgent.findUniqueOrThrow({ where: { id } })+ await db.swarmAgent.update({ where: { id }, data: { data: { ...part.data as Record<string, unknown>, teamAccount: true } as never } })+ return agentId+ })+ const tester = await startOld('Tester')const helper = String((await run(f.tab, { type: 'agent.add', conversationId: f.teamGroup, machineId: 'owner-host', harnessId: randomUUID(),name: 'Helper', configuration: config, lead: false })).result.agentId)// The owner's agent leading the task, not the project's coordinator: agents' posts to the coordinator wait for its digest,@@ -1262,7 +1124,7 @@ describe('a message from an agent of another account (audit M3)', () => {const lead = String((await run(f.tab, { type: 'agent.add', conversationId: f.teamGroup, machineId: 'owner-host', harnessId: randomUUID(),name: 'Owner Lead', configuration: config, lead: false })).result.agentId)await run(f.tab, { type: 'conversation.agent', conversationId: f.teamGroup, agentId: lead, present: true, lead: true })- return { ...f, lead, tester, helper }+ return { ...f, lead, tester, helper, startOld }}/** What an ordinary sign-in connecting as the Team computer does to its account row (lib/adapterWs.ts), after the send,* which the team session could no longer make. */@@ -1272,8 +1134,8 @@ describe('a message from an agent of another account (audit M3)', () => {}/** Starts an agent [name] of the owner's project on the owner's Team machine, through its team session. */async function startTeam(f: Awaited<ReturnType<typeof fixture>>, name: string) {- const startId = String((await run(f.tab, { type: 'agent.start', request: { conversationId: f.teamGroup, machineId: 'owner-team-mac', engine: 'codex',- name, cwd: '/owner-team', worktree: false, requirements } })).result.startId)+ const startId = String((await asBeforeV3('owner-team-mac', () => run(f.tab, { type: 'agent.start', request: { conversationId: f.teamGroup,+ machineId: 'owner-team-mac', engine: 'codex', name, cwd: '/owner-team', worktree: false, requirements } }))).result.startId)await hostRun(f.tab, { type: 'agent.startDispatch', startId }, 'owner-team-mac', ownerTeam)const agentId = String((await hostRun(f.tab, { type: 'agent.started', startId, harnessId: `owner-team-${randomUUID()}`, configuration: config },'owner-team-mac', ownerTeam)).result.agentId)@@ -1329,7 +1191,7 @@ describe('a message from an agent of another account (audit M3)', () => {// reset: the Swarm's record of another agent there still makes the machine a Team account's (teamByRecord).it('reads the Team account from another agent the Swarm recorded on that machine, when the account row was reset', async () => {const f = await accounts()- const second = await startTeam(f, 'Checker')+ const second = await f.startOld('Checker')const id = `${f.tab}:${second}`const part = await db.swarmAgent.findUniqueOrThrow({ where: { id } })const { teamAccount: _flag, ...data } = part.data as Record<string, unknown>@@ -1430,7 +1292,7 @@ describe('a message from an agent of another account (audit M3)', () => {// Task #2390 (Tony, 11-03): a machine's owner keeps it for some projects; every other project's work is refused there.describe('a machine its owner keeps for some projects', () => {- it('is kept for them across reads, set by its owner alone, and takes no start for another project', async () => {+ it('is kept for them across reads, set by its owner alone, and its Team account takes no start at all (task #4120)', async () => {const f = await fixture()const limit = (projectIds: string[] | null, user: AuthUser) => run(f.tab, { type: 'machine.projects', machineId: 'team-mac', projectIds } as Command, user)await expect(limit([f.own], owner)).rejects.toMatchObject({ code: 'OWNER_REQUIRED' })@@ -1439,7 +1301,7 @@ describe('a machine its owner keeps for some projects', () => {await limit([f.own], person)expect((await store.read(owner, f.tab)).state.machines!.find(m => m.machineId === 'team-mac')!.projects).toEqual([f.own])await expect(run(f.tab, { type: 'agent.start', request: { conversationId: f.teamGroup, machineId: 'team-mac', engine: 'codex',- name: 'Second', cwd: '/team', worktree: false, requirements } })).rejects.toMatchObject({ code: 'MACHINE_PROJECTS', message: 'MacBook Pro · Team runs only Own.' })+ name: 'Second', cwd: '/team', worktree: false, requirements } }, person)).rejects.toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })await limit(null, person)expect((await store.read(owner, f.tab)).state.machines!.find(m => m.machineId === 'team-mac')!.projects).toBeUndefined()})diff --git a/backend/integration/superTabTidy.test.ts b/backend/integration/superTabTidy.test.tsindex 23fc06d48..c245803cd 100644--- a/backend/integration/superTabTidy.test.ts+++ b/backend/integration/superTabTidy.test.ts@@ -62,8 +62,9 @@ async function swarm() {const generations = new Map<string, string>()for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(timed, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID() }+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId, name, configuration: config, lead }, host)).result.agentId)const lead = await add('lead', 'lead-host', harness.lead, 'Lead', true)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)diff --git a/backend/integration/superTabTimeChecks.test.ts b/backend/integration/superTabTimeChecks.test.tsindex 7cac9b2d7..6d24e6b21 100644--- a/backend/integration/superTabTimeChecks.test.ts+++ b/backend/integration/superTabTimeChecks.test.ts@@ -57,8 +57,9 @@ async function swarm() {const generations = new Map<string, string>()for (const machineId of ['lead-host', 'test-host']) generations.set(machineId, (await poolRows(timed, host, machineId)).find(p => p.tabId === tab)!.machine.generation)const harness = { lead: randomUUID(), worker: randomUUID() }+ // Added by the host, whose machines they run on: an agent is its own person's, on their own computer (task #4120).const add = async (conversationId: string, machineId: string, harnessId: string, name: string, lead = false) => String((await execute({ type: 'agent.add',- conversationId, machineId, harnessId, name, configuration: config, lead })).result.agentId)+ conversationId, machineId, harnessId, name, configuration: config, lead }, host)).result.agentId)const lead = await add('lead', 'lead-host', harness.lead, 'Lead', true)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)@@ -149,7 +150,7 @@ describe('the time checks with the PM down', () => {const tag = () => db.superTabMention.findMany({ where: { tabId: f.tab, messageId: told[0]!.id } })expect(await tag()).toEqual([expect.objectContaining({ personId: owner.sub, conversationId: f.group, resolvedAt: null })])const taker = String((await f.execute({ type: 'agent.add', conversationId: f.group, machineId: 'lead-host', harnessId: randomUUID(), name: 'Taker',- configuration: config, lead: false })).result.agentId)+ configuration: config, lead: false }, host)).result.agentId)await f.execute({ type: 'work.assign', conversationId: f.group, agentId: taker })f.clock.now += MINUTE// Its tag resolves on the `[tabId, conversationId, personId]` index, examining only that person's tags there (backend AGENTS.md 3).diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex dde39a142..39ca7039d 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -49,9 +49,13 @@ let app: FastifyInstanceconst owner: AuthUser = { sub: '100000000000000000000001', email: '[email protected]', autonomousEnv: 'prod', role: 'user' }const peer: AuthUser = { sub: '100000000000000000000002', email: '[email protected]', autonomousEnv: 'prod', role: 'user' }const host: AuthUser = { sub: '100000000000000000000003', email: '[email protected]', autonomousEnv: 'prod', role: 'user' }+/** The owner's own computer, where the owner and the owner's agents start new agents (task #4120). */+const OWN_MAC = 'owner-mac'const config = { engine: 'codex', model: 'fixture-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }const run = (tab: string, command: Command, user = owner, asAgentId?: string, operationId = randomUUID()) =>store.execute(user, tab, { operationId, command }, asAgentId)+/** A command as the machine's own person, `host`: in Swarm v3 a new agent starts only on its own person's computer (task #4120). */+const asHost = (tab: string, command: Command, _user?: AuthUser, asAgentId?: string, operationId = randomUUID()) => run(tab, command, host, asAgentId, operationId)/** A harness id for the fixture's Lead whose member name is (or is not) `name`. A Lead called "Lead" is given a member name* from agentNames.ts by its id alone, so a random id gives it any of 32 names; a test that adds a harness by one of those* names fails about one run in 32 when the Lead drew it first (task #3078). */@@ -71,12 +75,17 @@ async function fixture(leadHarnessId = randomUUID()) {async function routedStart(tab: string, lead: string, role?: 'reviewer', model = 'fixture-model', conversationId?: string) {// In a new task unless one is named: no agent but its coordinator starts into the project chat (#2207).conversationId ??= String((await run(tab, { type: 'conversation.create', title: 'Routed work', brief: '', checks: [] })).result.conversationId)+ // On the owner's own computer, which an agent of the Swarm already runs on: an agent starts nowhere unlisted, and a new agent only on+ // its own person's computer (task #4120). The Lead's person is the owner.+ if (!(await store.read(owner, tab)).state.agents.some(a => a.machineId === OWN_MAC)) {+ await run(tab, { type: 'agent.add', conversationId: 'lead', machineId: OWN_MAC, harnessId: randomUUID(), name: 'Owner Mac', configuration: config, lead: false })+ }const decision = { assessment: { difficulty: 'low', risk: 'low', why: 'Small task.' },- candidates: [{ id: 'c0', kind: 'new', machineId: 'test-host', engine: 'codex', model, effort: 'high',+ candidates: [{ id: 'c0', kind: 'new', machineId: OWN_MAC, engine: 'codex', model, effort: 'high',quality: 2, cost: 2, title: 'New agent', label: 'New agent' }],excluded: [], floor: 1, notes: false, pick: 'c0', via: 'only', p: null, belowFloor: false, why: 'Only candidate.' }const routeDecisionId = String((await run(tab, { type: 'route.record', conversationId, decision } as Command, host, lead)).result.routeDecisionId)- const request = { conversationId, machineId: 'test-host', engine: 'codex', model, effort: 'high',+ const request = { conversationId, machineId: OWN_MAC, engine: 'codex', model, effort: 'high',name: 'Builder', cwd: '/fixture/repo', worktree: false, ...(role ? { role } : {}),requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }const startId = String((await run(tab, { type: 'agent.start', request, routeDecisionId } as Command, host, lead)).result.startId)@@ -87,17 +96,6 @@ async function routedStart(tab: string, lead: string, role?: 'reviewer', model =const memberRow = (row: { text: string; source?: unknown }) => (row.source as { kind?: string } | null | undefined)?.kind === 'system' &&/^[^.]+ (added|removed) [^.]+\.$|^[^.]+ (joined|left)\.$/.test(row.text)const message = (text: string): Command => ({ type: 'message.send', conversationId: 'lead', text, replyTo: null, recipientIds: [] })-/** Makes [machineId], a machine of `host`'s, one used only for agents (`harness team on`) for this test: its account row- * is a team machine and it reports from its team session with that privacy, so it may take the owner's projects- * (docs/plans/2026-10-24-swarm-team-account.md, Task 3). A teammate's work runs only on such a machine. Its host routes then- * take its team session alone, never its owner's own sign-in (security review 2 of #2089). */-async function teamMachine(machineId: string) {- const computerId = createHash('sha256').update(machineId).digest('hex').slice(0, 32)- await db.machine.update({ where: { machineId }, data: { computerId, sessionKind: 'team' } })- onTestFinished(async () => { await db.machine.update({ where: { machineId }, data: { computerId: null, sessionKind: null } }) })- const session: AuthUser = { ...host, harnessSessionId: `team-${machineId}`, harnessSessionKind: 'team', harnessComputerId: computerId }- return { session, privacy: { mode: 'dedicated' as const } }-}/** A Swarm's whole state as its parts hold it, dormant groups included (test helper: the store keeps no single document). */async function storedState(tab: string): Promise<SuperTabState> {return parts.reassemble(await db.$transaction(tx => parts.loadAll(tx, tab)))@@ -161,6 +159,9 @@ beforeAll(async () => {await db.machine.create({ data: { machineId: 'test-host', userId: host.sub, apiKey: 'fixture-only', managerId: 'fixture',autonomousEnv: 'prod', authMode: 'remote' } })await db.machineShare.create({ data: { machineId: 'test-host', ownerId: host.sub, autonomousEnv: 'prod', emails: [owner.email, peer.email] } })+ // The owner's own computer: a new agent starts only on its own person's computer, through no share (Swarm v3, task #4120).+ await db.machine.create({ data: { machineId: OWN_MAC, userId: owner.sub, apiKey: 'fixture-owner-mac', managerId: 'fixture',+ autonomousEnv: 'prod', authMode: 'remote' } })app = Fastify()app.setErrorHandler(errorHandler)// External SSO is replaced with three fixture accounts; every permission/transaction below is real.@@ -710,7 +711,7 @@ describe('deleting abandoned swarm projects', () => {const { projectId } = (await run(tab, { type: 'project.create', name: 'Heavy start', visibility: 'public', brief: '' })).result as { projectId: string }// In a task of the project: the project chat holds only its coordinator among agents (#2207).const conversationId = String((await run(tab, { type: 'conversation.create', projectId, title: 'Build', brief: '', checks: [] })).result.conversationId)- const request = { conversationId, machineId: 'test-host', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true, heavy: ['build'],+ const request = { conversationId, machineId: OWN_MAC, engine: 'codex', name: 'Builder', cwd: '/work', worktree: true, heavy: ['build'],requirements: { memoryBytes: 4e9, diskBytes: 15e9, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }const startId = String((await run(tab, { type: 'agent.start', request } as Command)).result.startId)expect((await store.start(owner, tab, startId)).request).toMatchObject({ heavy: ['build'] })@@ -722,7 +723,7 @@ describe('deleting abandoned swarm projects', () => {const { projectId } = (await run(tab, { type: 'project.create', name: 'Failed start', visibility: 'public', brief: '' })).result as { projectId: string }// In a task of the project: the project chat holds only its coordinator among agents (#2207).const conversationId = String((await run(tab, { type: 'conversation.create', projectId, title: 'Build', brief: '', checks: [] })).result.conversationId)- const request = { conversationId, machineId: 'test-host', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,+ const request = { conversationId, machineId: OWN_MAC, engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }const startId = String((await run(tab, { type: 'agent.start', request })).result.startId)await expect(run(tab, { type: 'project.delete', projectId })).rejects.toMatchObject({ code: 'STARTS_PENDING' })@@ -765,23 +766,22 @@ describe('deleting abandoned swarm projects', () => {})describe('private swarm projects on the real control API', () => {+ // Swarm v3 (task #4120): the machine is its person's own, and that person starts its agents there, in their own account.it('uses one contributed machine across projects with a separate authorized checkout for each', async () => {const { tab } = await fixture()const invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)- const machineId = 'swarm-pool-host'- await db.machine.create({ data: { machineId, userId: host.sub, apiKey: 'fixture-swarm-pool', managerId: 'fixture',+ const machineId = 'swarm-pool-owner'+ await db.machine.create({ data: { machineId, userId: owner.sub, apiKey: 'fixture-swarm-pool-owner', managerId: 'fixture',autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine(machineId)+ onTestFinished(async () => { await db.machine.deleteMany({ where: { machineId } }) })const project = (await run(tab, { type: 'project.create', name: 'Second project', visibility: 'private', brief: '' })).resultconst conversationId = String(project.conversationId), projectId = String(project.projectId)await run(tab, { type: 'agent.add', conversationId, machineId: 'test-host', harnessId: randomUUID(),name: 'Project lead', configuration: config, lead: true,project: { cwd: '/lead/second', repositoryUrl: 'https://github.com/example/second' } })await run(tab, { type: 'machine.contribute', machineId, name: 'Shared capacity', cwd: '/swarm-root',- engines: ['codex'], maxAgents: 2 }, host)- await expect(run(tab, { type: 'tab.project', machineId, project: { cwd: '/unrelated', repositoryUrl: null } }))- .rejects.toMatchObject({ code: 'HOST_REQUIRED' })+ engines: ['codex'], maxAgents: 2 })// Builders start in each project's task: the project chat holds only its coordinator among agents (#2207).const task = String((await run(tab, { type: 'conversation.create', projectId, title: 'Second work', brief: '', checks: [] })).result.conversationId)const leadTask = String((await run(tab, { type: 'conversation.create', title: 'Lead work', brief: '', checks: [] })).result.conversationId)@@ -790,32 +790,31 @@ describe('private swarm projects on the real control API', () => {requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }await expect(run(tab, { type: 'agent.start', request })).rejects.toMatchObject({ code: 'PROJECT_CONTRIBUTION' })await run(tab, { type: 'machine.contribute', machineId, name: 'Shared capacity', cwd: '/swarm-root',- scope: 'swarm', engines: ['codex'], maxAgents: 2 }, host)- const pool = (await poolRows(store, team.session, machineId))[0]!- await store.observeMachine(team.session, tab, machineId, { generation: pool.machine.generation,+ scope: 'swarm', engines: ['codex'], maxAgents: 2 })+ const pool = (await poolRows(store, owner, machineId))[0]!+ await store.observeMachine(owner, tab, machineId, { generation: pool.machine.generation,resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, projectDiskFreeBytes: 100e9,diskFreeBytes: 100e9, diskTotalBytes: 500e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null },- quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy })- expect(pool.projects).toEqual([])+ quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [] })await expect(run(tab, { type: 'agent.start', request: { ...request, cwd: '/swarm-root/lead' } })).rejects.toMatchObject({ code: 'OUTSIDE_CONTRIBUTION' })const secondStart = (await run(tab, { type: 'agent.start', request })).result.startId as stringawait run(tab, { type: 'agent.start', request: { ...request, conversationId: leadTask, cwd: '/swarm-root/lead' } })- const queued = (await poolRows(store, team.session, machineId))[0]!+ const queued = (await poolRows(store, owner, machineId))[0]!expect(queued.starts).toHaveLength(2)expect(queued.projects!.find(p => p.id === projectId)).toMatchObject({repository: { machineId: 'test-host', cwd: '/lead/second', repositoryUrl: 'https://github.com/example/second' },conversationIds: [conversationId, task],})expect((await store.read(host, tab)).state.projects!.some(p => p.id === projectId)).toBe(false)- const hostRun = (command: Command) => store.execute(team.session, tab, { operationId: randomUUID(), command }, undefined, machineId)+ const hostRun = (command: Command) => store.execute(owner, tab, { operationId: randomUUID(), command }, undefined, machineId)await hostRun({ type: 'agent.startDispatch', startId: secondStart })const started = await hostRun({ type: 'agent.started', startId: secondStart, harnessId: 'second-builder', configuration: config })await hostRun({ type: 'agent.startSettled', startId: secondStart, warning: null })const agentId = String(started.result.agentId)// Its project's chat and the task it started in, nothing of the other project's.- expect((await store.read(team.session, tab, agentId)).state.conversations.map(c => c.id)).toEqual([conversationId, task])- await expect(store.messages(team.session, tab, 'lead', {}, agentId)).rejects.toMatchObject({ code: 'NOT_FOUND' })+ expect((await store.read(owner, tab, agentId)).state.conversations.map(c => c.id)).toEqual([conversationId, task])+ await expect(store.messages(owner, tab, 'lead', {}, agentId)).rejects.toMatchObject({ code: 'NOT_FOUND' })expect(await db.machineShare.findUnique({ where: { machineId } })).toBeNull()})@@ -937,8 +936,9 @@ describe('since when a worker is down', () => {name: 'Lead', configuration: config, lead: true })).result.agentId)const group = String((await execute({ type: 'conversation.create', title: 'Ship the parser', brief: 'Implement it',checks: [{ description: 'Verified', independent: false }] })).result.conversationId)+ // The machine's own person adds its worker, which then runs in their own account (Swarm v3, task #4120).const worker = String((await execute({ type: 'agent.add', conversationId: group, machineId: 'test-host', harnessId: workerHarness,- name: 'Worker', configuration: config, lead: false })).result.agentId)+ name: 'Worker', configuration: config, lead: false }, host)).result.agentId)const assignmentId = String((await execute({ type: 'work.assign', conversationId: group, agentId: worker })).result.assignmentId)const generation = (await poolRows(timed, host, 'test-host')).find(p => p.tabId === tab)!.machine.generationconst observe = (running: string[], stopped: string[] = []) => timed.observeMachine(host, tab, 'test-host', { generation,@@ -998,26 +998,26 @@ describe('since when a worker is down', () => {describe('Super Tabs on a real Mongo replica set', () => {it('records a grid worker\'s model on every assignment, after its start is finished and no longer loaded', async () => {+ // Swarm v3 (task #4120): the machine is its person's own, who starts its agents, in their own account.// Review of #1808: the run read the start, which a command does not load once the start is finished, so an assigned or// reused Kimi worker counted as a subscription run.const tab = (await store.create(owner, randomUUID(), 'Grid pool')).idconst invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await db.machine.create({ data: { machineId: 'grid-host', userId: host.sub, apiKey: 'fixture-grid-host', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine('grid-host')await run(tab, { type: 'machine.contribute', machineId: 'grid-host', name: 'Grid laptop', cwd: '/project', engines: ['claude'], maxAgents: 2 }, host)const grid = (await store.read(owner, tab)).state.localModels!.grid- const generation = (await poolRows(store, team.session, 'grid-host'))[0]!.machine.generation- await store.observeMachine(team.session, tab, 'grid-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,+ const generation = (await poolRows(store, host, 'grid-host'))[0]!.machine.generation+ await store.observeMachine(host, tab, 'grid-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null },- quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy,+ quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [],localModels: [{ grid, model: 'moonshotai/kimi-k3', name: 'Kimi K3', kind: 'api' }] })const group = String((await run(tab, { type: 'conversation.create', title: 'Small fix', brief: 'Fix it.',checks: [{ description: 'Independent review', independent: true }] })).result.conversationId)- const startId = String((await run(tab, { type: 'agent.start', request: { conversationId: group, machineId: 'grid-host', engine: 'claude', name: 'Builder',+ const startId = String((await asHost(tab, { type: 'agent.start', request: { conversationId: group, machineId: 'grid-host', engine: 'claude', name: 'Builder',cwd: '/project', worktree: true, gridModel: 'moonshotai/kimi-k3', gridName: grid,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } })).result.startId)- const hostRun = (command: Command) => store.execute(team.session, tab, { operationId: randomUUID(), command }, undefined, 'grid-host')+ const hostRun = (command: Command) => store.execute(host, tab, { operationId: randomUUID(), command }, undefined, 'grid-host')await hostRun({ type: 'agent.startDispatch', startId })const agentId = String((await hostRun({ type: 'agent.started', startId, harnessId: 'grid-builder',configuration: { engine: 'claude', model: null, effort: null, contextWindow: null, engineVersion: null } })).result.agentId)@@ -1032,25 +1032,25 @@ describe('Super Tabs on a real Mongo replica set', () => {})it('rates a Reviewer launched on its engine\'s default by the default row after it reports its model, its start finished', async () => {+ // Swarm v3 (task #4120): the machine is its person's own, who starts its agents, in their own account.// Live bug 10-29: a command does not load a finished start, so a Codex Reviewer that reported gpt-6.1-sol was rated 1.const tab = (await store.create(owner, randomUUID(), 'Default pool')).idconst invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await db.machine.create({ data: { machineId: 'default-host', userId: host.sub, apiKey: 'fixture-default-host', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine('default-host')await run(tab, { type: 'machine.contribute', machineId: 'default-host', name: 'Default laptop', cwd: '/project', engines: ['codex'], maxAgents: 2 }, host)- const generation = (await poolRows(store, team.session, 'default-host'))[0]!.machine.generation- await store.observeMachine(team.session, tab, 'default-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,+ const generation = (await poolRows(store, host, 'default-host'))[0]!.machine.generation+ await store.observeMachine(host, tab, 'default-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null },- quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy })+ quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [] })const group = String((await run(tab, { type: 'conversation.create', title: 'Fix', brief: 'Fix it.',checks: [{ description: 'Independent review', independent: true }] })).result.conversationId)const review = async () => String((await run(tab, { type: 'conversation.create', title: 'Review', brief: 'Review it.', reviewOf: group,checks: [{ description: 'Verdict', independent: false }] })).result.conversationId)const first = await review()- const startId = String((await run(tab, { type: 'agent.start', request: { conversationId: first, role: 'reviewer', machineId: 'default-host', engine: 'codex',+ const startId = String((await asHost(tab, { type: 'agent.start', request: { conversationId: first, role: 'reviewer', machineId: 'default-host', engine: 'codex',name: 'Reviewer', cwd: '/project', worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } })).result.startId)- const hostRun = (command: Command) => store.execute(team.session, tab, { operationId: randomUUID(), command }, undefined, 'default-host')+ const hostRun = (command: Command) => store.execute(host, tab, { operationId: randomUUID(), command }, undefined, 'default-host')await hostRun({ type: 'agent.startDispatch', startId })const agentId = String((await hostRun({ type: 'agent.started', startId, harnessId: 'default-reviewer',configuration: { engine: 'codex', model: null, effort: null, contextWindow: null, engineVersion: null } })).result.agentId)@@ -1058,31 +1058,31 @@ describe('Super Tabs on a real Mongo replica set', () => {const assign = async (conversationId: string) => (await run(tab, { type: 'work.assign', conversationId, agentId })).result.warningsexpect(await assign(first)).toBeUndefined()const previousVersion = (await storedState(tab)).agents.find(a => a.id === agentId)!.configurationVersion!- await run(tab, { type: 'agent.configuration', previousVersion, configuration: { engine: 'codex', model: 'gpt-6.1-sol', effort: null, contextWindow: null, engineVersion: null } }, team.session, agentId)+ await run(tab, { type: 'agent.configuration', previousVersion, configuration: { engine: 'codex', model: 'gpt-6.1-sol', effort: null, contextWindow: null, engineVersion: null } }, host, agentId)const firstWork = (await store.read(owner, tab)).state.conversations.find(c => c.id === first)!.assignment!.idawait run(tab, { type: 'work.cancel', conversationId: first, assignmentId: firstWork, reason: 'Again.' })expect(await assign(await review())).toBeUndefined()})it('tells a contributed machine its start\'s project skills, which its host cannot read from the Swarm', async () => {+ // Swarm v3 (task #4120): the machine is its person's own, who starts its agents, in their own account.// Prod logs 2026-10-28: the host asked for a Swarm status read it may not make (a 400 at every start), then launched// every agent on Harness orchestration, whatever its project ran.const tab = (await store.create(owner, randomUUID(), 'Skills pool')).idconst invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await db.machine.create({ data: { machineId: 'skills-host', userId: host.sub, apiKey: 'fixture-skills-host', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine('skills-host')await run(tab, { type: 'machine.contribute', machineId: 'skills-host', name: 'Skills laptop', cwd: '/project', engines: ['claude'], maxAgents: 4 }, host)- const generation = (await poolRows(store, team.session, 'skills-host'))[0]!.machine.generation- await store.observeMachine(team.session, tab, 'skills-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,+ const generation = (await poolRows(store, host, 'skills-host'))[0]!.machine.generation+ await store.observeMachine(host, tab, 'skills-host', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9,diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null },- quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy })+ quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [] })// Started in a task: the project chat holds only its coordinator among agents (#2207).const task = String((await run(tab, { type: 'conversation.create', title: 'Skills work', brief: '', checks: [] })).result.conversationId)- const start = async () => String((await run(tab, { type: 'agent.start', request: { conversationId: task, machineId: 'skills-host', engine: 'claude',+ const start = async () => String((await asHost(tab, { type: 'agent.start', request: { conversationId: task, machineId: 'skills-host', engine: 'claude',name: 'Builder', cwd: '/project', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } })).result.startId)- const skillMode = async (startId: string) => (await store.start(team.session, tab, startId, undefined, 'skills-host')).skillMode+ const skillMode = async (startId: string) => (await store.start(host, tab, startId, undefined, 'skills-host')).skillModeexpect(await skillMode(await start())).toBe('default')// What an older client stored before project instructions: the host still reads it.@@ -1095,38 +1095,38 @@ describe('Super Tabs on a real Mongo replica set', () => {})it('contributes project capacity without sharing the computer and fences host execution', async () => {+ // Swarm v3 (task #4120): the machine is its person's own, who starts its agents, in their own account.const tab = (await store.create(owner, randomUUID(), 'Machine pool')).idconst invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)const contribute = { type: 'machine.contribute' as const, machineId: 'pool-host', name: 'Host laptop', cwd: '/project', engines: ['codex' as const], maxAgents: 1 }await db.machine.create({ data: { machineId: 'pool-host', userId: host.sub, apiKey: 'fixture-pool-only', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine('pool-host')await expect(run(tab, contribute)).rejects.toMatchObject({ code: 'HOST_REQUIRED' })await run(tab, contribute, host)expect(await db.machineShare.findUnique({ where: { machineId: 'pool-host' } })).toBeNull()- const pools = await poolRows(store, team.session, 'pool-host')+ const pools = await poolRows(store, host, 'pool-host')expect(pools).toHaveLength(1)const generation = pools[0]!.machine.generationconst observation = { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9, diskTotalBytes: 500e9,projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null }, quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [] }await expect(store.observeMachine(owner, tab, 'pool-host', observation)).rejects.toMatchObject({ code: 'CONTRIBUTION_REVOKED' })- await store.observeMachine(team.session, tab, 'pool-host', { ...observation, privacy: team.privacy })+ await store.observeMachine(host, tab, 'pool-host', { ...observation })// Started and assigned in a task: the project chat holds only its coordinator among agents (#2207).const task = String((await run(tab, { type: 'conversation.create', title: 'Pool work', brief: '', checks: [] })).result.conversationId)const request = { permissionMode: 'full', conversationId: task, machineId: 'pool-host', engine: 'codex', name: 'Builder', cwd: '/project', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- await expect(run(tab, { type: 'agent.start', request: { ...request, cwd: '/private' } })).rejects.toMatchObject({ code: 'OUTSIDE_CONTRIBUTION' })- await expect(run(tab, { type: 'agent.start', request: { ...request, permissionMode: 'bypassPermissions' } })).rejects.toMatchObject({ code: 'OUTSIDE_CONTRIBUTION' })- const starts = await Promise.allSettled([run(tab, { type: 'agent.start', request }), run(tab, { type: 'agent.start', request })])+ await expect(asHost(tab, { type: 'agent.start', request: { ...request, cwd: '/private' } })).rejects.toMatchObject({ code: 'OUTSIDE_CONTRIBUTION' })+ await expect(asHost(tab, { type: 'agent.start', request: { ...request, permissionMode: 'bypassPermissions' } })).rejects.toMatchObject({ code: 'OUTSIDE_CONTRIBUTION' })+ const starts = await Promise.allSettled([asHost(tab, { type: 'agent.start', request }), asHost(tab, { type: 'agent.start', request })])expect(starts.filter(r => r.status === 'fulfilled')).toHaveLength(1)expect(starts.filter(r => r.status === 'rejected')).toHaveLength(1)const startId = (starts.find(r => r.status === 'fulfilled') as PromiseFulfilledResult<Awaited<ReturnType<typeof run>>>).value.result.startId as string- const queued = await store.start(owner, tab, startId)+ const queued = await store.start(host, tab, startId)expect(queued.poolGeneration).toBe(generation)expect(queued.request.permissionMode).toBe('full')await expect(run(tab, { type: 'agent.startDispatch', startId })).rejects.toMatchObject({ code: 'HOST_REQUIRED' })await expect(store.start(peer, tab, startId, undefined, 'pool-host')).rejects.toMatchObject({ code: 'FORBIDDEN' })- const hostRun = (command: Command) => store.execute(team.session, tab, { operationId: randomUUID(), command }, undefined, 'pool-host')+ const hostRun = (command: Command) => store.execute(host, tab, { operationId: randomUUID(), command }, undefined, 'pool-host')await expect(hostRun(message('Not a generic proxy'))).rejects.toMatchObject({ code: 'FORBIDDEN' })await run(tab, { type: 'machine.pause', machineId: 'pool-host', paused: true }, host)await expect(hostRun({ type: 'agent.startDispatch', startId })).rejects.toMatchObject({ code: 'MACHINE_PAUSED' })@@ -1139,59 +1139,59 @@ describe('Super Tabs on a real Mongo replica set', () => {await expect(run(tab, contribute, host)).rejects.toMatchObject({ code: 'STARTS_PENDING' })await expect(run(tab, { type: 'agent.startSettled', startId, warning: null })).rejects.toMatchObject({ code: 'HOST_REQUIRED' })await hostRun({ type: 'agent.startSettled', startId, warning: null })- expect((await store.start(owner, tab, startId)).poolSettled).toBe(true)+ expect((await store.start(host, tab, startId)).poolSettled).toBe(true)expect((await store.read(owner, tab)).state.agents[0]).toMatchObject({ contributorId: host.sub, machineOwnerId: host.sub, harnessId: 'pool-builder' })await run(tab, { type: 'member.remove', userId: host.sub })- expect(await poolRows(store, team.session, 'pool-host')).toEqual([])+ expect(await poolRows(store, host, 'pool-host')).toEqual([])// The machine stays listed while its host cleans up, but its owner left: a reading is refused as theirs no longer.- await expect(store.observeMachine(team.session, tab, 'pool-host', observation)).rejects.toMatchObject({ code: 'FORBIDDEN' })- await expect(store.start(team.session, tab, startId, undefined, 'pool-host')).rejects.toMatchObject({ code: 'FORBIDDEN' })+ await expect(store.observeMachine(host, tab, 'pool-host', observation)).rejects.toMatchObject({ code: 'FORBIDDEN' })+ await expect(store.start(host, tab, startId, undefined, 'pool-host')).rejects.toMatchObject({ code: 'FORBIDDEN' })})// Ken, 2026-10-28: work kept landing on engines that could not run on their machine. Two failed starts suspend the engine// there, saved with the machine; a reading that shows it signed in with quota, or its owner, offers it again.it('suspends an engine after two failed starts on a machine, keeps why its allowance is unknown, and offers it again', async () => {+ // Swarm v3 (task #4120): the machine is its person's own, who starts its agents, in their own account.const tab = (await store.create(owner, randomUUID(), 'Engine health')).idconst invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await db.machine.create({ data: { machineId: 'health-host', userId: host.sub, apiKey: 'fixture-health-only', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- const team = await teamMachine('health-host')await run(tab, { type: 'machine.contribute', machineId: 'health-host', name: 'Health laptop', cwd: '/project', engines: ['codex', 'claude'], maxAgents: 2 }, host)- const generation = (await poolRows(store, team.session, 'health-host'))[0]!.machine.generation+ const generation = (await poolRows(store, host, 'health-host'))[0]!.machine.generationconst observation = { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9, diskTotalBytes: 500e9,projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null }, tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [],- privacy: team.privacy, quotas: [{ engine: 'codex', known: false, windows: [] }], quotaReasons: { codex: 'OpenAI could not be reached.' } }- await store.observeMachine(team.session, tab, 'health-host', observation)+ quotas: [{ engine: 'codex', known: false, windows: [] }], quotaReasons: { codex: 'OpenAI could not be reached.' } }+ await store.observeMachine(host, tab, 'health-host', observation)const pool = async () => (await store.read(owner, tab)).state.machines!.find(m => m.machineId === 'health-host')! as Record<string, any>expect((await pool()).observation.quotaReasons).toEqual({ codex: 'OpenAI could not be reached.' })// Started in a task: the project chat holds only its coordinator among agents (#2207).const task = String((await run(tab, { type: 'conversation.create', title: 'Health work', brief: '', checks: [] })).result.conversationId)const request = { permissionMode: 'full', conversationId: task, machineId: 'health-host', engine: 'codex', name: 'Builder', cwd: '/project', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const hostRun = (command: Command) => store.execute(team.session, tab, { operationId: randomUUID(), command }, undefined, 'health-host')+ const hostRun = (command: Command) => store.execute(host, tab, { operationId: randomUUID(), command }, undefined, 'health-host')// Preparation failures remain failed starts, but do not disable either engine.for (let i = 0; i < 2; i++) {- const startId = (await run(tab, { type: 'agent.start', request })).result.startId as string+ const startId = (await asHost(tab, { type: 'agent.start', request })).result.startId as stringawait hostRun({ type: 'agent.startFailed', startId, error: 'The Harness server answered without a GitHub token for this project.' })}expect((await pool()).suspendedEngines).toBeUndefined()for (let i = 0; i < 2; i++) {- const startId = (await run(tab, { type: 'agent.start', request })).result.startId as string+ const startId = (await asHost(tab, { type: 'agent.start', request })).result.startId as stringawait hostRun({ type: 'agent.startDispatch', startId })await hostRun({ type: 'agent.startFailed', startId, error: 'Codex sign-in failed.' })}expect((await pool()).suspendedEngines).toEqual({ codex: expect.stringContaining('Codex is suspended on this machine for new work') })const notices = (await store.messages(owner, tab, task, {})).messages.filter(m => m.text.includes('Codex is suspended'))expect(notices.map(m => m.mentions)).toEqual([[host.sub]])- await expect(run(tab, { type: 'agent.start', request })).rejects.toMatchObject({ code: 'ENGINE_UNAVAILABLE' })+ await expect(asHost(tab, { type: 'agent.start', request })).rejects.toMatchObject({ code: 'ENGINE_UNAVAILABLE' })// Signed in, even with unknown quota: a sign-in suspension ends.- await store.observeMachine(team.session, tab, 'health-host', { ...observation, quotaReasons: undefined,+ await store.observeMachine(host, tab, 'health-host', { ...observation, quotaReasons: undefined,quotas: [{ engine: 'codex', known: false, windows: [] }],readiness: { engines: [{ engine: 'codex', installed: true, signedIn: true }] } })expect((await pool()).suspendedEngines).toBeUndefined()// Suspended again, and resumed by its owner.for (let i = 0; i < 2; i++) {- const startId = (await run(tab, { type: 'agent.start', request })).result.startId as string+ const startId = (await asHost(tab, { type: 'agent.start', request })).result.startId as stringawait hostRun({ type: 'agent.startDispatch', startId })await hostRun({ type: 'agent.startFailed', startId, error: 'Codex could not launch.' })}@@ -1201,21 +1201,21 @@ describe('Super Tabs on a real Mongo replica set', () => {expect((await pool()).suspendedEngines).toBeUndefined()// Timeouts of different engines share one machine cooldown, persisted across reports and reads.for (const engine of ['codex', 'claude']) {- const startId = (await run(tab, { type: 'agent.start', request: { ...request, engine } })).result.startId as string+ const startId = (await asHost(tab, { type: 'agent.start', request: { ...request, engine } })).result.startId as stringawait hostRun({ type: 'agent.startDispatch', startId })await hostRun({ type: 'agent.startFailed', startId, error: 'Health laptop did not start it within 3 minutes' })}- await store.observeMachine(team.session, tab, 'health-host', observation)+ await store.observeMachine(host, tab, 'health-host', observation)expect(await pool()).toMatchObject({ machineSuspended: expect.stringContaining('This machine is suspended'),suspendedEngines: { codex: expect.stringContaining('This machine is suspended'), claude: expect.stringContaining('This machine is suspended') } })for (const engine of ['codex', 'claude']) {- await expect(run(tab, { type: 'agent.start', request: { ...request, engine } })).rejects.toMatchObject({ code: 'MACHINE_UNAVAILABLE' })+ await expect(asHost(tab, { type: 'agent.start', request: { ...request, engine } })).rejects.toMatchObject({ code: 'MACHINE_UNAVAILABLE' })}await expect(run(tab, { type: 'machine.engineResume', machineId: 'health-host', engine: 'codex' })).rejects.toMatchObject({ code: 'OWNER_REQUIRED' })await run(tab, { type: 'machine.engineResume', machineId: 'health-host', engine: 'codex' }, host)expect((await pool()).machineSuspended).toBeUndefined()expect((await pool()).suspendedEngines).toBeUndefined()- expect((await run(tab, { type: 'agent.start', request })).result.startId).toBeTruthy()+ expect((await asHost(tab, { type: 'agent.start', request })).result.startId).toBeTruthy()})it('resolves a reply beyond recent history without crossing conversation or membership boundaries', async () => {@@ -1879,17 +1879,17 @@ describe('Super Tabs on a real Mongo replica set', () => {await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await run(tab, { type: 'machine.contribute', machineId: 'test-host', name: 'Host', cwd: '/swarm-root', scope: 'swarm', engines: ['codex'], maxAgents: 2 }, host)const pool = (await poolRows(store, host, 'test-host')).find(p => p.tabId === tab)!- const team = await teamMachine('test-host')- await store.observeMachine(team.session, tab, 'test-host', { generation: pool.machine.generation,+ await store.observeMachine(host, tab, 'test-host', { generation: pool.machine.generation,resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, projectDiskFreeBytes: 100e9,diskFreeBytes: 100e9, diskTotalBytes: 500e9, deviceType: 'Laptop', chip: 'Fixture CPU', os: 'macOS', gpuPercent: null },- quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy })+ quotas: [], tools: { git: true }, runningHarnessIds: [], stoppedHarnessIds: [] })// Started in the project's task: the project chat holds only its coordinator among agents (#2207).const task = String((await run(tab, { type: 'conversation.create', title: 'App work', brief: '', checks: [] })).result.conversationId)const request = { conversationId: task, machineId: 'test-host', engine: 'codex', name: 'Builder', cwd: '/work/app', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- await run(tab, { type: 'agent.start', request })- expect((await poolRows(store, team.session, 'test-host')).find(p => p.tabId === tab)!.projects).toEqual([expect.objectContaining({ id: 'lead', repository })])+ // The machine's own person starts it (Swarm v3, task #4120).+ await run(tab, { type: 'agent.start', request }, host)+ expect((await poolRows(store, host, 'test-host')).find(p => p.tabId === tab)!.projects).toEqual([expect.objectContaining({ id: 'lead', repository })])})it('answers an older client\'s skill change and keeps it nowhere, while the host reads the mode stored before', async () => {const tab = (await store.create(owner, randomUUID(), 'Skills')).id@@ -2475,11 +2475,11 @@ describe('Super Tabs on a real Mongo replica set', () => {expect(await active()).toEqual({ [lead]: true, [worker]: false })})- it('serializes native start claims and fences a restored target-machine grant', async () => {+ it('serializes native start claims, and starts nothing through another person\'s machine share (task #4120)', async () => {const { tab } = await fixture()// In a task: the project chat holds only its coordinator among agents (#2207).const group = String((await run(tab, { type: 'conversation.create', title: 'Task', brief: '', checks: [] })).result.conversationId)- const request = { conversationId: group, machineId: 'test-host', engine: 'claude', name: 'Builder', cwd: '/fixture/repo', worktree: true,+ const request = { conversationId: group, machineId: OWN_MAC, engine: 'claude', name: 'Builder', cwd: '/fixture/repo', worktree: true,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }const intent = randomUUID()const starts = await Promise.all(Array.from({ length: 3 }, () => run(tab, { type: 'agent.start', request }, owner, undefined, intent)))@@ -2489,18 +2489,9 @@ describe('Super Tabs on a real Mongo replica set', () => {const claims = await Promise.allSettled(Array.from({ length: 2 }, () => run(tab, { type: 'agent.startDispatch', startId })))expect(claims.filter(c => c.status === 'fulfilled')).toHaveLength(1)expect((await store.start(owner, tab, startId)).dispatched).toBe(true)- const original = await db.machineShare.findUniqueOrThrow({ where: { machineId: 'test-host' } })- try {- await db.machineShare.update({ where: { machineId: 'test-host' }, data: { emails: [peer.email],- grantVersions: nextMachineShareGrants(original, [peer.email], null) } })- await expect(store.start(owner, tab, startId)).rejects.toMatchObject({ code: 'HOST_REQUIRED' })- } finally {- const current = await db.machineShare.findUniqueOrThrow({ where: { machineId: 'test-host' } })- await db.machineShare.update({ where: { machineId: 'test-host' }, data: { emails: [owner.email, peer.email],- grantVersions: nextMachineShareGrants(current, [owner.email, peer.email], null) } })- }- await expect(store.start(owner, tab, startId)).rejects.toMatchObject({ code: 'CONTRIBUTION_REVOKED' })- await expect(run(tab, { type: 'agent.started', startId, harnessId: 'must-not-join', configuration: config })).rejects.toMatchObject({ code: 'CONTRIBUTION_REVOKED' })+ // A start on the host's machine, shared with the owner, would run in the host's account: refused before anything is queued.+ await expect(run(tab, { type: 'agent.start', request: { ...request, machineId: 'test-host' } })).rejects.toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ expect((await store.read(owner, tab)).state.starts).toHaveLength(1)})// Any agent of the project starts agents (project instructions, phase 4); a stuck start is its maker's or its coordinator's.@@ -2642,8 +2633,8 @@ describe('Super Tabs on a real Mongo replica set', () => {it('returns the receipt of a recorded agent start after its machine stops being listed', async () => {const { tab, lead } = await fixture()const machineId = `second-${randomUUID()}`- await db.machine.create({ data: { machineId, userId: host.sub, apiKey: 'fixture-only', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })- await db.machineShare.create({ data: { machineId, ownerId: host.sub, autonomousEnv: 'prod', emails: [owner.email] } })+ // The owner's own second computer, shared with nobody: a new agent starts only on its own person's computer (task #4120).+ await db.machine.create({ data: { machineId, userId: owner.sub, apiKey: `fixture-${machineId}`, managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })const helper = (await run(tab, { type: 'agent.add', conversationId: 'lead', machineId, harnessId: randomUUID(), name: 'Helper', configuration: config, lead: false })).result.agentId as string// Routed and started in a task: the project chat holds only its coordinator among agents (#2207).const group = String((await run(tab, { type: 'conversation.create', title: 'Task', brief: '', checks: [] })).result.conversationId)@@ -2663,13 +2654,15 @@ describe('Super Tabs on a real Mongo replica set', () => {it('corrects the log to the model that ran when the routed switch failed, and reads the times of one decision', async () => {const { tab, lead } = await fixture()+ // The Lead's person's own computer, listed by an agent on it (task #4120).+ await run(tab, { type: 'agent.add', conversationId: 'lead', machineId: OWN_MAC, harnessId: randomUUID(), name: 'Owner Mac', configuration: config, lead: false })// Routed and started in a task: the project chat holds only its coordinator among agents (#2207).const group = String((await run(tab, { type: 'conversation.create', title: 'Task', brief: '', checks: [] })).result.conversationId)const decision = { assessment: { difficulty: 'low', risk: 'low', why: 'Docs.' },- candidates: [{ id: 'c0', kind: 'new', machineId: 'test-host', engine: 'claude', model: 'haiku', effort: 'auto', quality: 1, cost: 1, title: 'New agent', label: 'New agent' }],+ candidates: [{ id: 'c0', kind: 'new', machineId: OWN_MAC, engine: 'claude', model: 'haiku', effort: 'auto', quality: 1, cost: 1, title: 'New agent', label: 'New agent' }],excluded: [], floor: 1, notes: false, pick: 'c0', via: 'only', p: null, belowFloor: false, why: 'Only candidate.' }const routeDecisionId = (await run(tab, { type: 'route.record', conversationId: group, decision } as Command, host, lead)).result.routeDecisionId as string- const request = { conversationId: group, machineId: 'test-host', engine: 'claude', model: 'haiku', effort: 'auto', name: 'Builder', cwd: '/fixture/repo', worktree: false,+ const request = { conversationId: group, machineId: OWN_MAC, engine: 'claude', model: 'haiku', effort: 'auto', name: 'Builder', cwd: '/fixture/repo', worktree: false,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }const startId = (await run(tab, { type: 'agent.start', request, routeDecisionId } as Command, host, lead)).result.startId as string// A queued start already holds its account's quota when the Lead routes again.@@ -2699,18 +2692,30 @@ describe('Super Tabs on a real Mongo replica set', () => {const leadMachineId = `lead-${randomUUID()}`await db.machine.create({ data: { machineId: leadMachineId, userId: host.sub, apiKey: 'fixture-only', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })await db.machineShare.create({ data: { machineId: leadMachineId, ownerId: host.sub, autonomousEnv: 'prod', emails: [owner.email] } })- const lead = (await run(tab, { type: 'agent.add', conversationId: 'lead', machineId: leadMachineId, harnessId: randomUUID(),- name: 'Lead', configuration: config, lead: true })).result.agentId as string+ await run(tab, { type: 'agent.add', conversationId: 'lead', machineId: leadMachineId, harnessId: randomUUID(),+ name: 'Lead', configuration: config, lead: true })const invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)await run(tab, { type: 'machine.contribute', machineId: 'test-host', name: 'Host', cwd: '/fixture/repo', engines: ['codex'], maxAgents: 4 }, host)const machine = (await poolRows(store, host, 'test-host')).find(pool => pool.tabId === tab)!.machine- const team = await teamMachine('test-host')- await store.observeMachine(team.session, tab, 'test-host', { generation: machine.generation,+ await store.observeMachine(host, tab, 'test-host', { generation: machine.generation,resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9, diskTotalBytes: 500e9,projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture', os: 'macOS', gpuPercent: null },- quotas: [], tools: {}, runningHarnessIds: [], stoppedHarnessIds: [], privacy: team.privacy })- const starts = [await routedStart(tab, lead), await routedStart(tab, lead)]+ quotas: [], tools: {}, runningHarnessIds: [], stoppedHarnessIds: [] })+ // Routed and started by the machine's own person: a new agent starts only on its own person's computer (Swarm v3, task #4120).+ const hostStart = async () => {+ const conversationId = String((await run(tab, { type: 'conversation.create', title: 'Routed work', brief: '', checks: [] })).result.conversationId)+ const decision = { assessment: { difficulty: 'low', risk: 'low', why: 'Small task.' },+ candidates: [{ id: 'c0', kind: 'new', machineId: 'test-host', engine: 'codex', model: 'fixture-model', effort: 'high',+ quality: 2, cost: 2, title: 'New agent', label: 'New agent' }],+ excluded: [], floor: 1, notes: false, pick: 'c0', via: 'only', p: null, belowFloor: false, why: 'Only candidate.' }+ const routeDecisionId = String((await run(tab, { type: 'route.record', conversationId, decision } as Command, host)).result.routeDecisionId)+ const request = { conversationId, machineId: 'test-host', engine: 'codex', model: 'fixture-model', effort: 'high', name: 'Builder', cwd: '/fixture/repo',+ worktree: false, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }+ const startId = String((await run(tab, { type: 'agent.start', request, routeDecisionId } as Command, host)).result.startId)+ return { routeDecisionId, startId }+ }+ const starts = [await hostStart(), await hostStart()]for (const { routeDecisionId } of starts) expect((await store.routeDecision(owner, tab, routeDecisionId)).outcome).toBeNull()await run(tab, how === 'its owner removes it' ? { type: 'machine.remove', machineId: 'test-host' } : { type: 'member.remove', userId: host.sub }, host)@@ -2747,7 +2752,8 @@ describe('Super Tabs on a real Mongo replica set', () => {expect((await store.routeDecision(owner, tab, routeDecisionId)).outcome).toBeNull()await run(tab, { type: 'agent.release', agentId, decision: 'stop' }, host, lead)const releaseId = (await store.read(owner, tab)).state.agents.find(agent => agent.id === agentId)!.releaseId!- await run(tab, { type: 'agent.remove', agentId, releaseId }, host, agentId)+ // Its execution host is its own person's: the owner's computer it was started on (task #4120).+ await run(tab, { type: 'agent.remove', agentId, releaseId }, owner, agentId)expect((await store.routeDecision(owner, tab, routeDecisionId)).outcome).toBe('stopped')})@@ -3543,7 +3549,8 @@ it('releases a finished worker through its execution host, cancels deliveries anawait run(tab, { type: 'machine.contribute', machineId: 'test-host', name: 'Host', cwd: '/repo', engines: ['codex'], maxAgents: 4 }, host)const group = (await run(tab, { type: 'conversation.create', title: 'Task', brief: 'Deliver it', checks: [{ description: 'Verified', independent: false }] })).result.conversationId as stringconst native = randomUUID()- const worker = (await run(tab, { type: 'agent.add', conversationId: group, machineId: 'test-host', harnessId: native, name: 'Worker', configuration: config, lead: false })).result.agentId as string+ // The machine's own person adds its worker, which then runs in their own account (Swarm v3, task #4120).+ const worker = (await run(tab, { type: 'agent.add', conversationId: group, machineId: 'test-host', harnessId: native, name: 'Worker', configuration: config, lead: false }, host)).result.agentId as stringconst pool = (await poolRows(store, host, 'test-host')).find(p => p.tabId === tab)!.machineconst oldObservation = { generation: pool.generation,resources: { cpuPercent: 10, memoryTotalBytes: 32e9, memoryUsedBytes: 4e9, diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture', os: 'macOS', gpuPercent: null },@@ -4279,8 +4286,10 @@ describe('machine removal', () => {taskChat.agentIds.push(workerId)project.repository = { machineId: 'test-host', cwd: '/secret/repository', repositoryUrl: null }state.agents.push(pm, worker)+ // Its work from before Swarm v3, which no longer assigns a project to an agent whose person cannot read it (task #4120).+ taskChat.assignment = { id: randomUUID(), agentId: workerId, status: 'working', configuration: config,+ execution: { machineId: 'test-host', harnessId: worker.harnessId, machineOwnerId: host.sub }, result: null } as neverawait saveState(tab, state)- await run(tab, { type: 'work.assign', conversationId: taskConversationId, agentId: workerId })const legacy = await app.inject({ method: 'GET', url: `/api/super-tabs/${tab}/machines/test-host/removal`, headers: { authorization: `Bearer ${host.sub}` } })expect(legacy.statusCode, legacy.body).toBe(426)diff --git a/backend/src/superTabs/closedAgents.test.ts b/backend/src/superTabs/closedAgents.test.tsindex e924fd87c..5ee83107e 100644--- a/backend/src/superTabs/closedAgents.test.ts+++ b/backend/src/superTabs/closedAgents.test.ts@@ -178,18 +178,25 @@ describe('what may come back', () => {expect(restoreRefusal(restoring({ closingSessions: mine } as Partial<SuperTabState>, team), onTeam, 'owner', AT, { ...facts, teamMachines: ['mac'] })).toBeNull()})- it('never a teammate\'s project on a machine that can no longer take it', () => {- // The Team account was removed: its owner's own project may come back there, and nobody else's.+ // Swarm v3 (task #4120, the PM's ruling): an agent works on any project its person reads, so it comes back to a teammate's+ // project too; one its person no longer reads ends (project-ended, above).+ it('comes back to a teammate\'s project its person reads', () => {expect(restoreRefusal(restoring({}, { hostMachineId: 'host-mac' }), record(), 'owner', AT, facts)).toBeNull()const theirs = restoring({ projects: [{ id: 'p', name: 'P', ownerId: 'mate', leadConversationId: 'lead-p', visibility: 'public', members: [] }] } as unknown as Partial<SuperTabState>, { hostMachineId: 'host-mac' })- expect(restoreRefusal(theirs, record(), 'owner', AT, facts)).toBe('team-work')- })-- it('leaves out a task marked Team-written while it was away, and keeps the rest', () => {- const state = restoring({ conversations: [removedGroup({ teamWritten: true }), removedGroup({ id: 'g2' })], removedSessions: [record({ groupIds: ['g1', 'g2'] })] })- restoreSessions(state, 'mac', ['h1'], AT, new Set(['h1']), () => {})- expect(state.conversations.find(c => c.id === 'g1')!.agentIds).toEqual([])- expect(state.conversations.find(c => c.id === 'g2')!.agentIds).toEqual(['a1'])+ expect(restoreRefusal(theirs, record(), 'owner', AT, facts)).toBeNull()+ })++ // Swarm v3 (task #4120, the PM's ruling): only the project owner's own agent may take over a task a Team agent wrote.+ it('leaves out a task marked Team-written while it was away, unless it is the project owner\'s own agent, and keeps the rest', () => {+ const groups = () => [removedGroup({ teamWritten: true }), removedGroup({ id: 'g2' })]+ const mates = restoring({ conversations: groups(), removedSessions: [record({ groupIds: ['g1', 'g2'] })],+ projects: [{ id: 'p', name: 'P', ownerId: 'mate', leadConversationId: 'lead-p', visibility: 'public', members: [] }] } as unknown as Partial<SuperTabState>)+ restoreSessions(mates, 'mac', ['h1'], AT, new Set(['h1']), () => {})+ expect(mates.conversations.find(c => c.id === 'g1')!.agentIds).toEqual([])+ expect(mates.conversations.find(c => c.id === 'g2')!.agentIds).toEqual(['a1'])+ const owners = restoring({ conversations: groups(), removedSessions: [record({ groupIds: ['g1', 'g2'] })] })+ restoreSessions(owners, 'mac', ['h1'], AT, new Set(['h1']), () => {})+ expect(owners.conversations.map(c => c.agentIds)).toEqual([['a1'], ['a1']])})// #2207 (Ken): the project chat holds only its coordinator among agents, so a session that was a member there comes back todiff --git a/backend/src/superTabs/closedAgents.ts b/backend/src/superTabs/closedAgents.tsindex 677acda49..45d928d2e 100644--- a/backend/src/superTabs/closedAgents.ts+++ b/backend/src/superTabs/closedAgents.ts@@ -144,7 +144,7 @@ export function restoreRefusal(state: SuperTabState, record: RemovedSession, macconst held = productManagerOn(state, record.machineId)if (held && held !== project.id) return 'team-other-project'}- return teamWorkCheck(state, record.machineId, agent.contributorId, project, now, facts.teamMachines, facts.otherWorkspaceMachines) ? 'team-work' : null+ return teamWorkCheck(state, record.machineId, agent.contributorId, project) ? 'team-work' : null}/**diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex cb85416b3..ecc03e9ea 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -59,18 +59,29 @@ function fixture() {return { run, invite, add, seat, group, get state() { return state } }}-/** Makes [machineId] [contributorId]'s contributed machine used only for agents (`harness team on`), reporting now, so a- * teammate's agent there may take another person's project (machines.ts teamWorkCheck). */-function teamMachine(f: ReturnType<typeof fixture>, contributorId: string, machineId = 'host') {- const team = { sessionKind: 'team' as const, privacy: { mode: 'dedicated' as const, seenAt: 1000 } }+/** Makes [machineId] [contributorId]'s own contributed computer, reporting now, so its agents take any project [contributorId]+ * reads, in their own account (machines.ts teamWorkCheck; Swarm v3 has no Team accounts, task #4120). */+function ownMachine(f: ReturnType<typeof fixture>, contributorId: string, machineId = 'host') {+ const own = { sessionKind: 'computer' as const }const existing = f.state.machines?.find(m => m.machineId === machineId)- if (existing) return void Object.assign(existing.observation!, team)+ if (existing) return void Object.assign(existing.observation!, own)f.state.machines = [...(f.state.machines ?? []), { machineId, name: 'Studio', contributorId, membershipGeneration: f.state.people.find(p => p.id === contributorId)!.generation,- generation: 'g1', cwd: '/repo', engines: ['claude'], maxAgents: 2, paused: false, observation: { generation: 'g1', receivedAt: 1000, ...team,+ generation: 'g1', cwd: '/repo', engines: ['claude'], maxAgents: 2, paused: false, observation: { generation: 'g1', receivedAt: 1000, ...own,resources: { cpuPercent: null, memoryTotalBytes: null, memoryUsedBytes: null, diskFreeBytes: null, diskTotalBytes: null, projectDiskFreeBytes: null,deviceType: null, chip: null, os: null, gpuPercent: null }, tools: {}, quotas: [], runningHarnessIds: [], stoppedHarnessIds: [] } }]}+/** Puts [agentId] on a machine of its own: [contributorId]'s own computer, or with [team] a Harness Team account's entry on it,+ * which Swarm v3 gives no new work (task #4120). */+function placeOn(f: ReturnType<typeof fixture>, agentId: string, contributorId: string, machineId: string, team = false) {+ if (!f.state.machines?.some(m => m.machineId === machineId)) {+ ownMachine(f, contributorId, machineId)+ const pool = f.state.machines!.find(m => m.machineId === machineId)!+ if (team) Object.assign(pool, { hostMachineId: 'host' }, { observation: { ...pool.observation!, sessionKind: 'team' } })+ }+ f.state.agents.find(a => a.id === agentId)!.machineId = machineId+}+describe('five-part tasks', () => {const task = { goal: 'Save edits', changes: 'Persist the draft', constraints: 'No dependencies', owns: ['backend/src/superTabs'] }const brief = 'Goal:\nSave edits\n\nChanges:\nPersist the draft\n\nConstraints:\nNo dependencies\n\nOwns:\n- backend/src/superTabs'@@ -749,7 +760,7 @@ describe('Super Tab collaboration policy', () => {it('withdraws a departing contributor and preserves execution identity until the host confirms a stop', () => {const f = fixture()f.invite()- teamMachine(f, 'peer')+ ownMachine(f, 'peer')const group = f.group()const worker = f.add('worker', 'peer', group)const assignmentId = f.run({ type: 'work.assign', conversationId: group, agentId: worker }).result.assignmentId as string@@ -839,11 +850,11 @@ describe('Super Tab collaboration policy', () => {it('starts only in the chosen conversation, captures authority, and never assigns on join', () => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()const actor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const request = { conversationId: group, machineId: 'host', engine: 'claude', name: 'Builder', cwd: '/repo', worktree: true,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }const startId = f.run({ type: 'agent.start', request, ...via }, actor, { contribution, ...decisionIn(group) }).result.startId as string- expect(f.state.starts![0]).toMatchObject({ request, hostGrant: 'grant-1', dispatched: false })+ expect(f.state.starts![0]).toMatchObject({ request, hostGrant: null, dispatched: false })expect(f.state.agents).toHaveLength(1)expect(f.state.conversations).toHaveLength(2) // Lead and the groupexpect(() => f.run({ type: 'agent.startDispatch', startId }, actor, { contribution: { ...contribution, hostGrant: 'new-grant' } })).toThrow('revoked')@@ -863,7 +874,7 @@ describe('a Codex start that asks for default', () => {const stored = (patch: Record<string, unknown>, withVia = false) => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()const actor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const request = { conversationId: group, machineId: 'host', engine: 'codex', name: 'Builder', cwd: '/repo', worktree: true,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false }, ...patch }f.run({ type: 'agent.start', request, ...(withVia ? { routeDecisionId: 'd1' } : via) } as Command, actor, { contribution, ...decisionIn(group,@@ -889,7 +900,7 @@ describe('a Codex start that asks for default', () => {for (const asked of [{ model: 'default', effort: 'default' }, { model: 'gpt-6.1-sol', effort: 'high' }]) {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()const actor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const request = { conversationId: group, machineId: 'host', engine: 'codex', name: 'Builder', cwd: '/repo', worktree: true, ...asked,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }const routing = decisionIn(group, { candidates: [candidate('c0', { machineId: 'host', engine: 'codex', ...asked })], pick: undefined, via: 'instructions', p: null })@@ -902,7 +913,7 @@ describe('a Codex start that asks for default', () => {it.each(['opencode', 'kilo'])('refuses to dispatch a stored legacy %s start before native launch', engine => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()const actor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const request = { conversationId: group, machineId: 'host', engine: 'claude', name: 'Builder', cwd: '/repo', worktree: true,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }const startId = f.run({ type: 'agent.start', request, ...via }, actor, { contribution, ...decisionIn(group) }).result.startId as string@@ -914,7 +925,7 @@ it.each(['opencode', 'kilo'])('refuses to dispatch a stored legacy %s start befodescribe('agent.start on the Swarm\'s listed machines', () => {const request = (group: string, machineId: string) => ({ conversationId: group, machineId, engine: 'claude', name: 'Builder', cwd: '/repo', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } })- const grant = { machineOwnerId: 'target-owner', contributorId: 'owner' }+ const grant = { machineOwnerId: 'owner', contributorId: 'owner' }it('refuses an agent\'s start on a machine nobody listed, and records nothing', () => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()@@ -1054,7 +1065,7 @@ function routed() {f.state.starts.push({ id: `start-${agentId}`, harnessId: member.harnessId, request: { machineId: member.machineId } } as never)return `start-${agentId}`}- return { ...f, get state() { return f.state }, lead, worker, define, startedFor, contribution: { machineOwnerId: 'host-owner', contributorId: 'owner' },+ return { ...f, get state() { return f.state }, lead, worker, define, startedFor, contribution: { machineOwnerId: 'owner', contributorId: 'owner' },leadActor: agentActor(lead), workerActor: agentActor(worker) }}@@ -1151,7 +1162,7 @@ describe('agent bookkeeping in the chats people read', () => {it('keeps an agent\'s joined and ready lines out of the project chat, and in a task\'s chat', () => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()const actor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const lines = (conversationId: string, harnessId: string) => {const request = { conversationId, machineId: 'host', engine: 'claude', name: 'Builder', cwd: '/repo', worktree: true,requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }@@ -1939,7 +1950,7 @@ it('lets the Lead stop a worker that never had an assignment, and never a Buddy'it('allows the contributor to keep a completed worker and refuses another project’s Lead', () => {const f = fixture(); f.invite()- teamMachine(f, 'peer')+ ownMachine(f, 'peer')f.add('lead', 'owner', 'lead', true)const group = f.group(), worker = f.add('worker', 'peer', group)const assignmentId = f.run({ type: 'work.assign', conversationId: group, agentId: worker }).result.assignmentId as string@@ -2449,7 +2460,7 @@ describe('any agent of the project', () => {// An older client's role kind (builder or reviewer) is stored for older readers and decides nothing; its custom role or// kind becomes the agent's role name (project instructions, phase 4, decision 2).describe('role kinds decide nothing', () => {- const contribution = { machineOwnerId: 'host-owner', contributorId: 'owner' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner' }const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })const request = (group: string, extra: Record<string, unknown> = {}) => ({ conversationId: group, machineId: 'host', engine: 'claude', name: 'Reviewer',cwd: '/repo', worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false }, ...extra })@@ -2562,17 +2573,18 @@ describe('role kinds decide nothing', () => {const f = fixture()f.invite()const lead = f.add('lead', 'owner', 'lead', true), group = f.group(), other = f.group()- // The teammate's own Mac, not its Harness Team account: another person's work runs there only through one (machines.ts).- teamMachine(f, 'peer')- const mac = f.state.machines!.find(m => m.machineId === 'host')!- mac.observation!.sessionKind = 'computer'- mac.teamAccountOnly = true- const mate = f.add('mate', 'peer', group)+ // The teammate's own Mac takes another person's work in their own account; its Harness Team account takes none (task #4120).+ ownMachine(f, 'peer')+ const mate = f.add('mate', 'peer', group), own = f.add('own', 'peer', group)+ placeOn(f, mate, 'peer', 'peer-team', true)expect(() => f.run({ type: 'conversation.agent', conversationId: other, agentId: mate, present: true, lead: false }, as(lead)))- .toThrow(expect.objectContaining({ code: 'TEAM_ACCOUNT_REQUIRED' }))+ .toThrow(expect.objectContaining({ code: 'TEAM_ACCOUNTS_REMOVED' }))expect(f.state.conversations.find(c => c.id === other)!.agentIds).not.toContain(mate)- // The project owner's own agent there: added, and its finished-work decision cleared as an assignment clears it.+ f.run({ type: 'conversation.agent', conversationId: other, agentId: own, present: true, lead: false }, as(lead))+ expect(f.state.conversations.find(c => c.id === other)!.agentIds).toContain(own)+ // The project owner's own agent on their own computer: added, and its finished-work decision cleared as an assignment clears it.const mine = f.add('mine', 'owner', group)+ placeOn(f, mine, 'owner', 'owner-mac')f.state.agents.find(a => a.id === mine)!.workDecision = 'awaiting'f.run({ type: 'conversation.agent', conversationId: other, agentId: mine, present: true, lead: false }, as(lead))expect(f.state.agents.find(a => a.id === mine)).not.toHaveProperty('workDecision')@@ -2585,19 +2597,19 @@ describe('role kinds decide nothing', () => {// The team-access check applies to every agent added to a task (spec, "Kept as access"): one named into it, one that posts// into it and one that opens it join it, as conversation.agent adds one (final review of the branch).describe('an agent joining a task by a post or by opening it', () => {- /** A teammate's agent (mate) on its own Mac, which runs another person's work only through its Harness Team account. */+ /** A teammate's agent (mate) in its Mac's Harness Team account, which Swarm v3 gives no new work (task #4120), and the project+ * owner's own agent (mine) on the owner's own computer. */function teammate() {const f = fixture()f.invite()const lead = f.add('lead', 'owner', 'lead', true), group = f.group(), other = f.group()- teamMachine(f, 'peer')- const mac = f.state.machines!.find(m => m.machineId === 'host')!- mac.observation!.sessionKind = 'computer'- mac.teamAccountOnly = true+ ownMachine(f, 'peer')const mate = f.add('mate', 'peer', group), mine = f.add('mine', 'owner', group)+ placeOn(f, mate, 'peer', 'peer-team', true)+ placeOn(f, mine, 'owner', 'owner-mac')return { f, lead, group, other, mate, mine }}- const refused = expect.objectContaining({ code: 'TEAM_ACCOUNT_REQUIRED' })+ const refused = expect.objectContaining({ code: 'TEAM_ACCOUNTS_REMOVED' })const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })const post = (conversationId: string, recipientIds: string[] = []) =>({ type: 'message.send', conversationId, text: 'Look at this.', replyTo: null, recipientIds }) as Command@@ -2622,7 +2634,8 @@ describe('an agent joining a task by a post or by opening it', () => {it('checks a person\'s add of a session already in the Swarm as conversation.agent does', () => {const { f, other, mate, mine } = teammate()const again = (harnessId: string, actor: Extract<Actor, { kind: 'person' }>) => f.run({ type: 'agent.add', conversationId: other,- machineId: 'host', harnessId, name: harnessId, configuration: config, lead: false }, actor, { contribution: { machineOwnerId: 'host-owner', contributorId: actor.userId } })+ machineId: f.state.agents.find(a => a.harnessId === harnessId)!.machineId, harnessId, name: harnessId, configuration: config, lead: false }, actor,+ { contribution: { machineOwnerId: 'host-owner', contributorId: actor.userId } })const members = (id: string) => f.state.conversations.find(c => c.id === id)!.agentIdsexpect(() => again('mate', peer)).toThrow(refused)f.state.agents.find(a => a.id === mine)!.workDecision = 'stop'@@ -2803,7 +2816,7 @@ it('allows routing directly to the awaiting worker without first keeping it', ()})describe('Reviewer role', () => {- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner' }const request = (group: string, extra: Record<string, unknown> = {}) => ({ conversationId: group, machineId: 'host', engine: 'claude', name: 'Reviewer',cwd: '/repo', worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false }, ...extra })function reviewed() {@@ -2872,7 +2885,7 @@ describe('Reviewer role', () => {const check = { type: 'work.check', conversationId: review, assignmentId: verdict.assignment!.id, checkId: verdict.checks[0]!.id, passed: true, evidence: 'Looks fine.' } as Commandf.run(check, { kind: 'agent', agentId: builder, machineOwnerId: 'host-owner' })expect(f.state.conversations.find(c => c.id === review)!.checks[0]!.passedBy).toBe(`agent:${builder}`)- f.run(check, { kind: 'agent', agentId: reviewer, machineOwnerId: 'target-owner' })+ f.run(check, { kind: 'agent', agentId: reviewer, machineOwnerId: 'owner' })expect(f.state.conversations.find(c => c.id === review)!.checks[0]!.passedBy).toBe(`agent:${reviewer}`)})@@ -2954,7 +2967,7 @@ describe('Reviewer role', () => {f.run({ type: 'route.record', conversationId: review, decision: pick(reviewer) } as Command, leadActor)const built = f.run({ type: 'work.assign', conversationId: group, agentId: builder }).result.assignmentId as stringconst assignmentId = f.run({ type: 'work.assign', conversationId: review, agentId: reviewer }).result.assignmentId as string- const reviewerActor: Actor = { kind: 'agent', agentId: reviewer, machineOwnerId: 'target-owner' }+ const reviewerActor: Actor = { kind: 'agent', agentId: reviewer, machineOwnerId: 'owner' }const checkId = f.state.conversations.find(c => c.id === group)!.checks[0]!.idf.run({ type: 'work.check', conversationId: group, assignmentId: built, checkId, passed: true, evidence: 'Ready: yes — revision abc' }, reviewerActor)expect(f.state.conversations.find(c => c.id === group)!.checks[0]!.passedBy).toBe(`agent:${reviewer}`)@@ -2973,7 +2986,7 @@ describe('Reviewer role', () => {const { f, group, builder, reviewer } = setupconst built = f.run({ type: 'work.assign', conversationId: group, agentId: builder }).result.assignmentId as stringconst builderActor: Actor = { kind: 'agent', agentId: builder, machineOwnerId: 'host-owner' }- const reviewerActor: Actor = { kind: 'agent', agentId: reviewer, machineOwnerId: 'target-owner' }+ const reviewerActor: Actor = { kind: 'agent', agentId: reviewer, machineOwnerId: 'owner' }f.run({ type: 'work.status', conversationId: group, assignmentId: built, status, result: 'Ready for review: PR #42 at abc1234' }, builderActor, { now: 2000 })const checkId = f.state.conversations.find(c => c.id === group)!.checks[0]!.idconst verdict = (passed: boolean, now: number) => f.run({ type: 'work.check', conversationId: group, assignmentId: built, checkId, passed,@@ -3055,7 +3068,7 @@ describe('Reviewer role', () => {const review = f.run({ type: 'conversation.create', title: 'Review', brief: 'Review it.', reviewOf: group, checks: [{ description: 'Verdict', independent: false }] },leadActor).result.conversationId as stringf.run({ type: 'work.assign', conversationId: review, agentId: reviewer })- f.run({ type: 'agent.alert', agentId: reviewer, alert: 'model', active: true }, { kind: 'agent', agentId: reviewer, machineOwnerId: 'target-owner' })+ f.run({ type: 'agent.alert', agentId: reviewer, alert: 'model', active: true }, { kind: 'agent', agentId: reviewer, machineOwnerId: 'owner' })expect(f.state.conversations.find(c => c.id === review)!.assignment).toMatchObject({ status: 'lost', lost: { reason: 'its model keeps failing' } })expect(f.state.agents.find(a => a.id === reviewer)!.lostTask).toMatchObject({ conversationId: review })})@@ -3878,7 +3891,7 @@ describe('machine.remove', () => {f.state.agents.find(a => a.id === lead)!.machineId = 'elsewhere'f.invite()contribute(f, 'peer')- teamMachine(f, 'peer')+ ownMachine(f, 'peer')const worker = f.add('worker', 'peer', group), owners = f.add('owners', 'owner')f.run({ type: 'work.assign', conversationId: group, agentId: worker })f.state.rules = [{ id: 'both', projectId: 'lead', rule: { kind: 'machines', machineIds: ['host', 'elsewhere'] }, text: 'Only these two.',@@ -4188,7 +4201,7 @@ describe('the Local models add-on', () => {const start = (gridName: string, patch: Record<string, unknown> = {}) => ({ conversationId: 'lead', machineId: 'host', engine: 'claude', name: 'Local builder',cwd: '/repo/lead', worktree: true, gridModel: 'qwen3-30b', gridName, ...patch,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } })- const grant = { contribution: { machineOwnerId: 'host-owner', contributorId: 'owner' } }+ const grant = { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } }it('is on in a new Swarm, its grid named, so the owner\'s computer sets it up in the background', () => {const f = fixture()@@ -5065,7 +5078,7 @@ describe('linked tasks', () => {// untagged, in its chat. With no coordinator there, people read it, tagging who can fix it.it('tells the coordinator once when no machine the project may use can start either engine, and people when there is none', () => {const { f, T, E, built } = linked()- teamMachine(f, 'owner')+ ownMachine(f, 'owner')f.state.machines![0]!.engines = ['claude', 'codex']f.state.machines![0]!.observation!.quotas = [{ engine: 'claude', known: true, windows: [{ name: 'weekly', usedPercent: 10, resetsAt: null }] },{ engine: 'codex', known: true, windows: [{ name: 'weekly', usedPercent: 100, resetsAt: null }] }]@@ -5342,7 +5355,7 @@ describe('an engine that cannot run on a contributed machine', () => {// Scholes, 2026-10-30: the sidebar's Models showed "Codex, model not reported". A Codex agent at its own default reported its// model only after the work it was assigned 30 s after its start was recorded; the start now settles with what it saw.describe('a settling start names the model its agent runs', () => {- const contribution = { machineOwnerId: 'target-owner', contributorId: 'owner', hostGrant: 'grant-1' }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const reported = { engine: 'codex', model: 'gpt-6.1-sol', effort: 'auto', contextWindow: null, engineVersion: '0.165.0' }const setup = () => {const f = fixture(), lead = f.add('lead', 'owner', 'lead', true), group = f.group()@@ -5385,7 +5398,7 @@ describe('a settling start names the model its agent runs', () => {expect(activeWork(t.f.state.conversations.find(c => c.id === t.group)!)).toBe(false)const agent = t.worker(agentId)t.f.run({ type: 'agent.configuration', previousVersion: agent.configurationVersion!, configuration: reported },- { kind: 'agent', agentId, machineOwnerId: 'target-owner' })+ { kind: 'agent', agentId, machineOwnerId: 'owner' })expect(t.run()).toMatchObject({ assignmentId, model: 'gpt-6.1-sol' })})@@ -5429,9 +5442,9 @@ describe('lead.switch', () => {const f = fixture()f.invite()const pm = f.add('pm', contributorId, 'lead', true)- const team = { sessionKind: 'team' as const, privacy: { mode: 'dedicated' as const, seenAt: 1000 } }+ // Its person's own computer (Swarm v3 has no Team accounts, task #4120).f.state.machines = [{ machineId: 'host', name: 'Studio', contributorId, membershipGeneration: f.state.people.find(p => p.id === contributorId)!.generation,- generation: 'g1', cwd: '/repo', engines: ['claude', 'codex'], maxAgents: 2, paused: false, observation: { generation: 'g1', receivedAt: 1000, ...team,+ generation: 'g1', cwd: '/repo', engines: ['claude', 'codex'], maxAgents: 2, paused: false, observation: { generation: 'g1', receivedAt: 1000, sessionKind: 'computer',...(capabilities ? { capabilities } : {}),profiles: [{ engine: 'codex', id: WORK, label: 'Work', leftPercent: 80, resetsAt: null }],resources: { cpuPercent: null, memoryTotalBytes: null, memoryUsedBytes: null, diskFreeBytes: null, diskTotalBytes: null, projectDiskFreeBytes: null,diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex d6423f22b..3be9f63b7 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -2,12 +2,12 @@ import { authorizeTaskApproval, pendingTaskApproval, personalApprovalCommand, reimport type { PullRequestFilesRead } from './pullRequestFiles.js'import { legacyProposalId, migrateLegacyProposals, type LegacyProposalAsk, pmAcceptsMessage, applyProposalAction, authorizeProposalAction, authorizePersonProposal, cardPriority, createPersonProposal, createProposalCard, proposalCreateSchema, proposalFields, proposalRoot } from './proposalCards.js'import { pulseProjectOf, recordPulse, owe, settleDeleted, settleReaction, settleReply, settleRequest } from './pulse.js'-import { applyPushOrigin, failPushUnknown, failTeamWritten, mainAccountMembers, markTeamWritten, mayName, requireTeamWrittenAccount, requireTeamWrittenMachine, stepMark, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'+import { applyPushOrigin, barredFromTeamWritten, failPushUnknown, failTeamWritten, mainAccountMembers, markTeamWritten, mayName, ownersOwnAgent, ownersOwnMachine, requireTeamWrittenAccount, requireTeamWrittenMachine, stepMark, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'import { crewMoveFailed, takeOverCrewMember, wakeCrewMember } from './crewKeep.js'import { moveTimingRow, startWake } from './crewTimes.js'import type { PushOrigin } from '../github/pushOrigin.js'import { requireRepositoryReach, unknownPushReason, type RepositoryReach } from './repositoryReach.js'-import { admitByRoom, admitMachineStart, noRepositoryStart, failOwnAccountTeamEntry, ownAccountTeamEntry, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, refusesWindowsBuddy, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, machineLimitReached, MACHINE_LIMIT_MESSAGE, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamMachineFor, teamAccountPool, teamPoolsOf, teamStartRequest, teamWorkCheck, movedToTeamAccount, type ContributedMachine } from './machines.js'+import { admitByRoom, admitMachineStart, noRepositoryStart, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, refusesWindowsBuddy, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, machineLimitReached, MACHINE_LIMIT_MESSAGE, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamAccountPool, teamPoolsOf, teamWorkCheck, TEAM_ACCOUNTS_GONE, NOT_YOUR_COMPUTER, type ContributedMachine } from './machines.js'import { movableEntry } from './computerMoves.js'import { agentDisplayName, assignAgentDisplayNames } from './agentNames.js'import { addedAgentName, renameAgentTo } from './agentRename.js'@@ -732,9 +732,6 @@ export interface CommandContext {inviteeRemoved?: boolean/** Machines of this Swarm also contributed to a Swarm of another Workspace (store.ts otherWorkspaceMachines). */otherWorkspaceMachines?: string[]- /** No Harness GitHub App on this server (routes/superTabs.ts): a Mac's Harness Team account has no git login to fetch or- * push with, so starts on the Mac stay with the Mac, as before team accounts (machines.ts teamMachineFor). */- teamAccountsIdle?: boolean}/** What an agent's post that reached no agent tells its sender, in the result every CLI prints (Egret6's review of #2963):@@ -1219,9 +1216,15 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,}/** An agent added to a task may work on it, so one added by a post or by opening it takes that project's work only where* conversation.agent would add it (machines.ts teamWorkCheck; spec, "Kept as access"). */- const teamJoin = (project: SwarmProject, agentId: string, group?: Conversation) => {+ /** A Team account's agent keeps the conversations it is in and joins no new one, but its project's coordinator, which keeps+ * coordinating until it is stopped after the release (task #4120). [joiningNew]: [member] is not yet in where it joins. */+ const teamAgentStays = (member: Agent, joiningNew: boolean) => {+ if (joiningNew && onTeamAccount(state, member) && !ledProject(state, member.id)) failTeamWork(TEAM_ACCOUNTS_GONE)+ }+ const teamJoin = (project: SwarmProject, agentId: string, group?: Conversation, joiningNew = true) => {const member = agent(state, agentId)- requireTeamWork(state, member.machineId, member.contributorId, project, context.now, context.teamMachines, context.otherWorkspaceMachines)+ teamAgentStays(member, joiningNew)+ requireTeamWork(state, member.machineId, member.contributorId, project)// A named agent or a poster joins a task as an assignment would: Team-written code stays in a Team account (audit H2).// Joining a chat is not writing its code, so it marks nothing: a Team agent's push shows in GitHub's record (#3304).if (group) requireTeamWrittenAccount(state, group, member)@@ -1241,7 +1244,8 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,* refuses the main account, and the store keeps that mark after this command is refused. Unknown refuses it unmarked. */const pushedRefusal = (group: Conversation, worker: Agent) => {marking(group, () => applyPushOrigin(state, group, context.pushOrigin, context.pushOriginPulls, context.pushOriginTask))- if (onTeamAccount(state, worker) || ledProject(state, worker.id)?.id === groupProject(state, group).id) return+ // The project owner's own agent may take it too (teamWritten.ts, task #4120, the PM's ruling).+ if (onTeamAccount(state, worker) || ledProject(state, worker.id)?.id === groupProject(state, group).id || ownersOwnAgent(state, group, worker)) returnif (context.pushOrigin === 'unknown') failPushUnknown(unknownPushReason(context.repositoryReach))if (context.pushOrigin === 'team') failTeamWritten({ pushed: true })}@@ -1253,7 +1257,8 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,if (isBuddy(member)) fail('BUDDY_CHAT_ONLY', 'A Buddy stays in its own chat: its owner\'s alone.', 403)sameProject(state, group, member)if (member.workDecision === 'stop') fail('STOP_REQUESTED', 'This agent is stopping. Wait for its execution host.')- requireTeamWork(state, member.machineId, member.contributorId, groupProject(state, group), context.now, context.teamMachines, context.otherWorkspaceMachines)+ teamAgentStays(member, !group.agentIds.includes(member.id))+ requireTeamWork(state, member.machineId, member.contributorId, groupProject(state, group))requireTeamWrittenAccount(state, group, member)}/** The project chat is the people's and is never archived: its work, name and records are its coordinator's or a person's,@@ -1449,15 +1454,20 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,if (candidate.kind === 'member' && !member) return null// A new agent never starts on a Buddy-only machine; an agent its person added there runs as one on a machine outside the Swarm.if (!member && state.machines?.some(m => m.machineId === candidate.machineId && m.buddyOnly)) return { code: 'NOT_SWARM_MACHINE' as const, reason: NOT_SWARM_MACHINE }- // A new agent on a Mac for a teammate's project runs in the Mac's Harness Team account (machines.ts teamStartRequest).+ // Where it would run is where it names: no start moves to a Team account any more, and none starts in one (task #4120).const group = conversation(state, conversationId), written = teamWrittenTask(state, group), needed = taskAccess(group)- const machineId = member?.machineId ?? teamMachineFor(state, candidate.machineId, project, context.teamAccountsIdle, context.teamMachines, written, needed)- // Team-written code takes a Team account only (audit H2). Its own check below says nothing for the owner's own account.- if (written && !(member ? onTeamAccount(state, member) : teamAccountPool(state.machines?.find(m => m.machineId === machineId)))- && !(member && ledProject(state, member.id)?.id === project.id)) return { code: 'TEAM_WRITTEN_WORK' as const, reason: TEAM_WRITTEN_REASON }- const contributor = member?.contributorId ?? state.machines?.find(m => m.machineId === machineId)?.contributorId ?? starter+ const machineId = member?.machineId ?? candidate.machineId+ const pool = state.machines?.find(m => m.machineId === machineId)+ if (teamAccountPool(pool) || (member && onTeamAccount(state, member))) return TEAM_ACCOUNTS_GONE+ // A new agent starts only on its starter's own computer, as them (task #4120, the PM's ruling).+ if (!member && pool && pool.contributorId !== starter) return { code: 'NOT_YOUR_COMPUTER' as const, reason: NOT_YOUR_COMPUTER }+ // Code a Team agent wrote: only the project owner's own agent, on their own computer (teamWritten.ts, the PM's ruling; audit H2).+ if (written && (member ? barredFromTeamWritten(state, group, member) : !ownersOwnMachine(state, group, machineId))) {+ return { code: 'TEAM_WRITTEN_WORK' as const, reason: TEAM_WRITTEN_REASON }+ }+ const contributor = member?.contributorId ?? pool?.contributorId ?? starter// Then what the task needs to reach, in the account it would run in (machineAccess.ts, task #3047).- return teamWorkCheck(state, machineId, contributor, project, context.now, context.teamMachines, context.otherWorkspaceMachines, needed)+ return teamWorkCheck(state, machineId, contributor, project)?? accessRefusal(state, machineId, project, needed)}/**@@ -1861,15 +1871,17 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,sameProject(state, group, worker, true)const home = groupProject(state, group)// A teammate's agent on a personal machine keeps what it has; it takes no new task for another person's project.- requireTeamWork(state, worker.machineId, worker.contributorId, home, context.now, context.teamMachines, context.otherWorkspaceMachines, taskAccess(group))+ requireTeamWork(state, worker.machineId, worker.contributorId, home)// And what the task needs to reach, where it runs (machineAccess.ts): an assignment is held to it as a start is.const unreached = accessRefusal(state, worker.machineId, home, taskAccess(group))if (unreached) failTeamWork(unreached)requireRepositoryReach(state, onTeamAccount(state, worker), worker.machineOwnerId, home, context.repositoryReach)- // Team-written code runs only in a Team account (teamWritten.ts, audit H2).+ // Team-written code: only the project owner's own agent (teamWritten.ts, task #4120; audit H2).pushedRefusal(group, worker)requireTeamWrittenAccount(state, group, worker)if (worker.workDecision === 'stop') fail('STOP_REQUESTED', 'This worker is stopping. Wait for its execution host.')+ // A Team account's agent keeps what it holds and takes nothing new (task #4120); it is stopped after the release.+ if (onTeamAccount(state, worker)) failTeamWork(TEAM_ACCOUNTS_GONE)// A handed task does not occupy its Engineer (#3399 handed.ts): it may take this.if (state.conversations.some(c => occupiesAgent(c) && c.assignment?.agentId === worker.id)) fail('AGENT_BUSY', 'This agent already owns an active assignment.')}@@ -2840,7 +2852,11 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,state.groupCounter = number// The agent that opens a task is in it, so an Engineer that opens its own review can post there and pass its checks.const creator = actor.kind === 'agent' && actor.agentId !== leadId ? [actor.agentId] : []- for (const id of creator) teamJoin(project, id, command.reviewOf ? conversation(state, command.reviewOf) : undefined)+ // A step a Team agent opens for the task it holds is part of that task, not new work (task #4120).+ for (const id of creator) {+ const of = command.reviewOf ? conversation(state, command.reviewOf) : undefined+ teamJoin(project, id, of, !of?.agentIds.includes(id))+ }// A step's opener is in its task too: the task's chat is where the step's work is talked over (task steps design).if (command.step && command.reviewOf) {const owning = conversation(state, command.reviewOf)@@ -3259,36 +3275,30 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,if (state.starts.filter(s => !s.harnessId && !s.error).length >= 32) {fail('STARTS_PENDING', 'Reconcile pending agent starts before adding more.')}- // A teammate's project started on a Mac runs in that Mac's Harness Team account, never as its owner (machines.ts). A start- // that names no model runs its engine's own: role defaults live in the project's instructions now.- // So does a start for code a Team agent wrote, whoever's project it is, with its project settings off (audit H2).+ // A start that names no model runs its engine's own: role defaults live in the project's instructions now.const startGroup = conversation(state, command.request.conversationId)marking(startGroup, () => applyPushOrigin(state, startGroup, context.pushOrigin, context.pushOriginPulls, context.pushOriginTask))const written = teamWrittenTask(state, startGroup)- // Named the Team account's entry itself, which its owner's choice keeps teammates' work off (task #3060). A branch GitHub- // cannot place runs only in a Team account (below), so it counts as Team-written here (security review 2 of #3081).- const ownEntry = ownAccountTeamEntry(state, named.machineId, home, written || context.pushOrigin === 'unknown')- if (ownEntry) failOwnAccountTeamEntry(ownEntry)- const moved = teamStartRequest(state, named, home, context.teamAccountsIdle, context.teamMachines, written, taskAccess(startGroup))- // Moved to the Mac's Team account: the starter is told why in one line (task #2806).- if (moved.machineId !== named.machineId) {- const mac = state.machines?.find(m => m.machineId === named.machineId)- if (mac) result.moved = movedToTeamAccount(mac, written)- }- if (written) requireTeamWrittenMachine(state, startGroup, moved.machineId)- // A branch GitHub cannot place stays out of the main account too, unmarked, as it may yet read clean.- else if (context.pushOrigin === 'unknown' && !teamAccountPool(state.machines?.find(m => m.machineId === moved.machineId))) failPushUnknown(unknownPushReason(context.repositoryReach))- const request: AgentStartRequest = noRepositoryStart(state.machines?.find(m => m.machineId === moved.machineId), home,- written ? { ...moved, projectSettings: 'off' } : moved)+ // A new agent starts only on its own person's computer, as them (task #4120, the PM's ruling): never the PM on another+ // person's, and never in a Team account (machines.ts admitMachineStart).+ // The machine's own owner, as its contributor, with no machine share, Team account or Team session, as agent.new checks+ // (security review 2 of #3446: off the Machines list, or through a share, the contributor is not the machine's owner).+ const starter = actor.kind === 'person' ? actor.userId : agent(state, actor.agentId).contributorId+ if (grant.hostMachineId || grant.teamSession) failTeamWork(TEAM_ACCOUNTS_GONE)+ if (starter !== grant.contributorId || starter !== grant.machineOwnerId || grant.hostGrant) failTeamWork({ code: 'NOT_YOUR_COMPUTER', reason: NOT_YOUR_COMPUTER })+ // Code a Team agent wrote, or a branch GitHub cannot place, runs only on the project owner's own computer, with its project+ // settings off (teamWritten.ts, the PM's ruling; audit H2, security review 2 of #3081).+ if (written) requireTeamWrittenMachine(state, startGroup, named.machineId)+ else if (context.pushOrigin === 'unknown' && !ownersOwnMachine(state, startGroup, named.machineId)) failPushUnknown(unknownPushReason(context.repositoryReach))+ const request: AgentStartRequest = noRepositoryStart(state.machines?.find(m => m.machineId === named.machineId), home,+ written ? { ...named, projectSettings: 'off' } : named)// Before it is queued: a machine that cannot get the app's token for it would fail it, and count that against its engine.- requireRepositoryReach(state, teamAccountPool(state.machines?.find(m => m.machineId === request.machineId)), grant.machineOwnerId, home, context.repositoryReach)- // The project's machine rules (machineRules.ts), on the machine named and the one the start lands on (a Mac's Team account).- for (const machineId of new Set([named.machineId, request.machineId])) {- refuseByMachineRules(context, { machineId, engine: request.engine, review: isReview(startGroup) })- }+ requireRepositoryReach(state, false, grant.machineOwnerId, home, context.repositoryReach)+ // The project's machine rules (machineRules.ts).+ refuseByMachineRules(context, { machineId: request.machineId, engine: request.engine, review: isReview(startGroup) })const pool = admitMachineStart(state, request, context.now, undefined, context.teamMachines, context.otherWorkspaceMachines)// Off the Machines list, a teammate's project never runs: nothing there shows a privacy check (machines.ts).- if (!pool) requireTeamWork(state, request.machineId, grant.contributorId, home, context.now, context.teamMachines, context.otherWorkspaceMachines)+ if (!pool) requireTeamWork(state, request.machineId, grant.contributorId, home)// Nor one that needs access: a machine off the list lists nothing it can reach (machineAccess.ts).const unlisted = pool ? null : accessRefusal(state, request.machineId, home, taskAccess(startGroup))if (unlisted) failTeamWork(unlisted)@@ -4133,8 +4143,9 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,fail('AUDIENCE_LEAD_ONLY', 'A private conversation holds only the Lead among agents.', 403)}// An agent added to a task may work on it, so a teammate's agent is added only where it may take that project's work,- // as an assignment checks (machines.ts teamWorkCheck).- requireTeamWork(state, member.machineId, member.contributorId, groupProject(state, group), context.now, context.teamMachines, context.otherWorkspaceMachines)+ // as an assignment checks (machines.ts teamWorkCheck). A Team account's agent joins nothing new (task #4120).+ teamAgentStays(member, !group.agentIds.includes(member.id))+ requireTeamWork(state, member.machineId, member.contributorId, groupProject(state, group))pushedRefusal(group, member)requireTeamWrittenAccount(state, group, member)if (!group.agentIds.includes(command.agentId)) group.agentIds.push(command.agentId)@@ -4723,7 +4734,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,// they were not, the agent whose work is ready opens and assigns them (project instructions, phase 4). When no machine the project may use can start either engine, or soon none// will, the project's coordinator hears it once, in its chat (reviewCapacity.ts).const short = command.status === 'review' && !group.reviewOf ? reviewCapacityNotice(state, group, context.now, (machineId, contributorId) =>- !teamWorkCheck(state, machineId, contributorId, groupProject(state, group), context.now, context.teamMachines, context.otherWorkspaceMachines)) : null+ !teamWorkCheck(state, machineId, contributorId, groupProject(state, group))) : null// A row of its own beside the command's, as the ship notice is: written as the Engineer who handed over. A server notice,// the coordinator's alone (model.ts NOTICE_READERS), untagged, since people cannot read it; with no coordinator in the// chat, its people read it and those who can fix it are tagged (spec, "Server notices to the coordinator"; final review).diff --git a/backend/src/superTabs/crewKeep.apply.test.ts b/backend/src/superTabs/crewKeep.apply.test.tsindex 9358637db..bc0dc0256 100644--- a/backend/src/superTabs/crewKeep.apply.test.ts+++ b/backend/src/superTabs/crewKeep.apply.test.ts@@ -92,18 +92,20 @@ describe('waking and moving through commands', () => {})describe('a take-over never joins a conversation its new session is barred from (security review of #3229)', () => {- it('leaves a Team-written task out when the new session runs in the main account', () => {+ // Task #4120 (the PM's ruling): only the project owner's own agent may take over Team-written work, as ada is here; another+ // member's agent stays out (teamWritten.test.ts, closedAgents.test.ts).+ it('takes a Team-written task back when the new session is the project owner\'s own agent', () => {const f = fixture([machine('mac', { signedIn: false }), machine('mini')])f.state = run(f.state, { type: 'conversation.create', title: 'Team task', brief: 'b', checks: [] } as Command, 'tw', NOW - 3_600_000)const task = f.state.conversations.find(c => c.title === 'Team task')!task.agentIds.push(f.ada.id)- // Placed by hand, as an older server could have: the take-over itself must still refuse the join.+ // Placed by hand, as an older server could have: the take-over keeps it, the owner's own agent.applyCrewKeep(f.state, NOW, everywhere)const start = f.state.starts!.find(s => s.request.crewMoveOf === f.ada.id)!f.state.conversations.find(c => c.id === task.id)!.teamWritten = truef.state = run(f.state, { type: 'agent.started', startId: start.id, harnessId: 'ada-2', configuration: config } as Command, 'started-tw', NOW + 5000, host)const moved = f.state.agents.find(a => a.harnessId === 'ada-2')!- expect(f.state.conversations.find(c => c.id === task.id)!.agentIds).not.toContain(moved.id)+ expect(f.state.conversations.find(c => c.id === task.id)!.agentIds).toContain(moved.id)expect(f.state.conversations.find(c => c.id === 'lead')!.agentIds).toContain(moved.id)})})diff --git a/backend/src/superTabs/dispatch.ts b/backend/src/superTabs/dispatch.tsindex 38bc51e60..ea18c2859 100644--- a/backend/src/superTabs/dispatch.ts+++ b/backend/src/superTabs/dispatch.ts@@ -116,7 +116,8 @@ export function freeCrew(state: SuperTabState, projectId: string, rules: Dispatcconst launching = (agent: Agent) => !!state.starts?.some(s => !s.poolSettled && s.poolGeneration && s.request.machineId === agent.machineId && s.harnessId === agent.harnessId)return state.agents.filter(agent => agentProjectId(state, agent) === projectId && !leads.has(agent.id) && !isBuddy(agent)- && agent.workDecision !== 'stop' && !moving(agent) && (asleep(agent) || !sessionClosed(state, agent, now)) && !launching(agent)+ // Nor a Team account's, which takes no new work (task #4120).+ && agent.workDecision !== 'stop' && !onTeamAccount(state, agent) && !moving(agent) && (asleep(agent) || !sessionClosed(state, agent, now)) && !launching(agent)&& !busy.has(agent.id) && (handedBy.get(agent.id) ?? 0) < rules.maxHanded && reachable(agent)// A member its machine or engine cannot serve now would lose the task at once (liveness.ts): until that clears.&& !unavailableReason(state, agent, now, asleep(agent)))diff --git a/backend/src/superTabs/instructions.test.ts b/backend/src/superTabs/instructions.test.tsindex 013a7e0cd..57d748be6 100644--- a/backend/src/superTabs/instructions.test.ts+++ b/backend/src/superTabs/instructions.test.ts@@ -716,7 +716,7 @@ describe('role names and the coordinator\'s name', () => {expect(f.state.agents.find(a => a.id === tester)!.roleName).toBe('Tester')expect(f.state.agents.find(a => a.id === plain)).not.toHaveProperty('roleName')expect(() => f.add('long', group, false, { roleName: 'x'.repeat(41) })).toThrow()- const contribution = { machineOwnerId: 'host-owner', contributorId: 'owner', hostGrant: null }+ const contribution = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }const request = { conversationId: group, machineId: 'host', engine: 'claude', name: 'Designer', cwd: '/repo', worktree: true, roleName: 'Designer',requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }const startId = f.run({ type: 'agent.start', request }, owner, { contribution }).result.startId as stringdiff --git a/backend/src/superTabs/leadStart.test.ts b/backend/src/superTabs/leadStart.test.tsindex dbadfed03..8c595d7d8 100644--- a/backend/src/superTabs/leadStart.test.ts+++ b/backend/src/superTabs/leadStart.test.ts@@ -1,10 +1,10 @@-import { afterEach, describe, expect, it } from 'vitest'+import { describe, expect, it } from 'vitest'import { applyCommand, commandSchema, type Command, type CommandContext } from './commands.js'import type { ContributedMachine, MachinePrivacy } from './machines.js'import { createSuperTab, SuperTabError, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'-// A project's Product Manager started by the Swarm on the machine its person names (Dee, 10-29, option B; Ken, 10-29): on-// another person's Mac it runs in that Mac's Harness Team account when the account takes it, else on the Mac as its owner.+// A project's Product Manager started by the Swarm on the machine its person names (Dee, 10-29, option B). Swarm v3 (task+// #4120, the PM's ruling): that is its person's own computer, never another person's and never a Harness Team account.const NOW = 50_000_000const MINUTE = 60_000@@ -14,7 +14,6 @@ const config: AgentConfiguration = { engine: 'claude', model: 'opus', effort: 'hconst resources = { cpuPercent: 1, memoryTotalBytes: 8, memoryUsedBytes: 1, diskFreeBytes: 8, diskTotalBytes: 8, projectDiskFreeBytes: 8,deviceType: null, chip: null, os: null, gpuPercent: null }const PASSED: MachinePrivacy = { mode: 'account', passed: true, checkedAt: NOW - MINUTE }-const FAILED: MachinePrivacy = { mode: 'account', passed: false, item: 'gitconfig', detail: 'The team account could read ~/.gitconfig.', checkedAt: NOW - MINUTE }const REPO = 'https://github.com/example/app'type Reading = NonNullable<ContributedMachine['observation']>/** A reading as the store keeps it, from a host that starts Product Managers unless [capable] is false. */@@ -25,8 +24,6 @@ const refusal = (body: () => unknown): SuperTabError | null => {try { body(); return null } catch (error) { if (error instanceof SuperTabError) return error; throw error }}-afterEach(() => { delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED })-/** The owner's Swarm with the owner's project App: the owner's Mac, and the teammate's MacBook with its Harness Team account. */function swarm() {let state: SuperTabState = createSuperTab('tab', 'Pilot', { id: 'owner', email: owner.email }, 'prod')@@ -72,91 +69,31 @@ describe('starting a project\'s Product Manager on a Swarm machine', () => {expect(f.project().repository).toEqual({ machineId: 'owner-mac', cwd: `/swarm/${f.app.projectId}`, repositoryUrl: REPO })})- it('on a teammate\'s Mac, runs in that Mac\'s Harness Team account and its folder', () => {- const f = swarm()- f.lead('mate-mac')- expect(f.state.starts).toEqual([expect.objectContaining({ machineOwnerId: 'mate',- request: expect.objectContaining({ machineId: 'mate-team', cwd: `/team-swarm/${f.app.projectId}` }) })])- expect(f.project().lead).toMatchObject({ status: 'starting', machineId: 'mate-team', machineName: 'MacBook Pro' })- })-- it('on a teammate\'s Mac whose Team account cannot take it now, runs on the Mac itself, as its owner', () => {- const f = swarm()- f.machine('mate-team').observation = reading('team', FAILED)- f.lead('mate-mac')- expect(f.state.starts).toEqual([expect.objectContaining({ machineOwnerId: 'mate', contributorId: 'mate',- request: expect.objectContaining({ machineId: 'mate-mac', cwd: `/swarm/${f.app.projectId}` }) })])- expect(f.project().lead).toMatchObject({ status: 'starting', machineId: 'mate-mac', machineName: 'MacBook Pro' })- // Offline, or paused, the same.- const offline = swarm()- offline.machine('mate-team').observation = { ...reading('team', PASSED), receivedAt: NOW - 10 * MINUTE }- expect(offline.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- const paused = swarm()- paused.machine('mate-team').paused = true- expect(paused.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- })-- it('on a teammate\'s Mac added as they joined, runs only in its Team account', () => {- const f = swarm()- f.machine('mate-mac').teamAccountOnly = true- expect(f.lead('mate-mac').result).toMatchObject({ machineId: 'mate-team' })- const failing = swarm()- failing.machine('mate-mac').teamAccountOnly = true- failing.machine('mate-team').observation = reading('team', FAILED)- expect(refusal(() => failing.lead('mate-mac'))?.code).toBe('PRIVACY_CHECK_FAILED')- const none = swarm()- none.machine('mate-mac').teamAccountOnly = true- none.state.machines = none.state.machines!.filter(m => m.machineId !== 'mate-team')- expect(refusal(() => none.lead('mate-mac'))?.code).toBe('TEAM_ACCOUNT_REQUIRED')- expect(none.state.starts ?? []).toEqual([])- })-- // Task #2806: its owner let teammates' work run in their own account there (machine.ownAccountWork).- it('on a teammate\'s Mac whose owner lets teammates\' work run in their own account, runs on the Mac itself', () => {- const f = swarm()- f.machine('mate-mac').teamAccountOnly = true- f.run({ type: 'machine.ownAccountWork', machineId: 'mate-mac', allowed: true } as Command, mate)- expect(f.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- })-- // Task #3060: a start naming the Team account entry itself is refused there too, pointing at the Mac.- it('named in a Team account itself whose Mac\'s owner runs teammates\' work in their own account, is refused, pointing at the Mac', () => {+ it('named in a Team account\'s entry, is refused, whatever its Mac\'s owner chose, and records nothing', () => {const f = swarm()+ expect(refusal(() => f.lead('mate-team'))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED', status: 403 })f.run({ type: 'machine.ownAccountWork', machineId: 'mate-mac', allowed: true } as Command, mate)- expect(refusal(() => f.lead('mate-team'))).toMatchObject({ code: 'OWN_ACCOUNT_WORK', message: expect.stringContaining('mate-mac') })+ expect(refusal(() => f.lead('mate-team'))?.code).toBe('TEAM_ACCOUNTS_REMOVED')expect(f.state.starts ?? []).toEqual([])+ expect(f.project().lead).toBeUndefined()})- it('on a teammate\'s Mac with no Team account, runs on the Mac itself, whatever the Swarm\'s switch says for workers', () => {- process.env.SWARM_TEAM_ACCOUNT_REQUIRED = '1'+ it('on a teammate\'s Mac, is refused: it starts only on its person\'s own computer, and records nothing', () => {const f = swarm()+ expect(refusal(() => f.lead('mate-mac'))).toMatchObject({ code: 'NOT_YOUR_COMPUTER', status: 403 })+ // Whatever that Mac's owner chose, and with no Team account there either.+ f.run({ type: 'machine.ownAccountWork', machineId: 'mate-mac', allowed: true } as Command, mate)f.state.machines = f.state.machines!.filter(m => m.machineId !== 'mate-team')- expect(f.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- // With no GitHub App the Team account takes no work: the Mac runs it itself.- expect(swarm().lead('mate-mac', {}, owner, { teamAccountsIdle: true }).result).toMatchObject({ machineId: 'mate-mac' })- })-- it('named in a Team account itself, is refused with the account\'s own reason, and records nothing', () => {- const f = swarm()- f.machine('mate-team').observation = reading('team', FAILED)- expect(refusal(() => f.lead('mate-team'))).toMatchObject({ code: 'PRIVACY_CHECK_FAILED', status: 403,- message: 'The Harness Team account on MacBook Pro is not private (gitconfig: it could read its owner\'s ~/.gitconfig), so it runs only its owner\'s projects.' })- f.machine('mate-team').observation = { ...reading('team', PASSED), receivedAt: NOW - 10 * MINUTE }- expect(refusal(() => f.lead('mate-team'))?.code).toBe('MACHINE_OFFLINE')+ expect(refusal(() => f.lead('mate-mac'))?.code).toBe('NOT_YOUR_COMPUTER')expect(f.state.starts ?? []).toEqual([])expect(f.project().lead).toBeUndefined()})it('is refused on a machine whose Harness is too old to start a Product Manager', () => {const f = swarm()- f.machine('mate-team').observation = reading('team', PASSED, false)- // Its Team account's host is too old: the Mac takes it.- expect(f.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- const g = swarm()- g.machine('mate-team').observation = reading('team', PASSED, false)- g.machine('mate-mac').observation = reading('computer', undefined, false)- expect(refusal(() => g.lead('mate-mac'))).toMatchObject({ code: 'HOST_OUTDATED',- message: 'Update Harness on MacBook Pro to run a Product Manager there.' })+ f.machine('owner-mac').observation = reading('computer', undefined, false)+ expect(refusal(() => f.lead('owner-mac'))).toMatchObject({ code: 'HOST_OUTDATED',+ message: 'Update Harness on Owner Mac to run a Product Manager there.' })})it('is refused off the Swarm\'s Machines list', () => {@@ -171,15 +108,14 @@ describe('starting a project\'s Product Manager on a Swarm machine', () => {expect(f.state.starts ?? []).toEqual([])})- it('is refused on a teammate\'s Mac once they left the Swarm, or while it is being removed, and records nothing', () => {+ it('is refused on a machine whose person left the Swarm, or while it is being removed, and records nothing', () => {const left = swarm()left.run({ type: 'member.remove', userId: 'mate' })expect(refusal(() => left.lead('mate-mac'))?.code).toBe('CONTRIBUTION_REVOKED')expect(left.state.starts ?? []).toEqual([])const removing = swarm()- removing.machine('mate-mac').removal = { id: 'r1', state: 'cleaning', requestedAt: new Date(NOW).toISOString() }- removing.machine('mate-team').observation = reading('team', FAILED)- expect(refusal(() => removing.lead('mate-mac'))?.code).toBe('MACHINE_REMOVED')+ removing.machine('owner-mac').removal = { id: 'r1', state: 'cleaning', requestedAt: new Date(NOW).toISOString() }+ expect(refusal(() => removing.lead('owner-mac'))?.code).toBe('MACHINE_REMOVED')expect(removing.state.starts ?? []).toEqual([])})@@ -282,11 +218,11 @@ describe('a Product Manager\'s start, once its host reports it', () => {describe('a start that finishes after a person set another coordinator', () => {const late = () => {const f = swarm()- const startId = f.lead('mate-mac').result.startId as string+ const startId = f.lead('owner-mac').result.startId as stringconst hand = f.run({ type: 'agent.add', conversationId: f.app.conversationId, machineId: 'owner-mac', harnessId: 'by-hand', name: 'Mine',configuration: config, lead: true }, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null } }).result.agentId as stringconst home = () => f.state.conversations.find(c => c.id === f.app.conversationId)!- const finish = (operation?: string) => f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { ...hosted(f, 'mate-team'), ...(operation ? { operationId: operation } : {}) })+ const finish = (operation?: string) => f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { ...hosted(f, 'owner-mac'), ...(operation ? { operationId: operation } : {}) })return { f, startId, hand, home, finish }}@@ -305,8 +241,8 @@ describe('a Product Manager\'s start, once its host reports it', () => {const t = late()const answer = t.finish()const rows = answer.messages.filter(m => m.conversationId === t.f.app.conversationId)- expect(rows.map(m => m.text)).toEqual(['Product Manager started on MacBook Pro, but this project already has Mine as its Product Manager, so it did not join.'])- expect(rows[0]!.source).toEqual({ kind: 'system', machine: 'MacBook Pro' })+ expect(rows.map(m => m.text)).toEqual(['Product Manager started on Owner Mac, but this project already has Mine as its Product Manager, so it did not join.'])+ expect(rows[0]!.source).toEqual({ kind: 'system', machine: 'Owner Mac' })expect(rows[0]!.recipients).toEqual([])expect(t.f.project().lead).toBeUndefined()})@@ -334,8 +270,8 @@ describe('a Product Manager\'s start, once its host reports it', () => {it('a first start with nobody set joins and leads, as before', () => {const f = swarm()- const startId = f.lead('mate-mac').result.startId as string- const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, hosted(f, 'mate-team')).result.agentId as string+ const startId = f.lead('owner-mac').result.startId as string+ const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, hosted(f, 'owner-mac')).result.agentId as stringexpect(f.state.conversations.find(c => c.id === f.app.conversationId)).toMatchObject({ leadId: pm, agentIds: [pm] })expect(f.project().lead).toMatchObject({ status: 'started' })})@@ -344,30 +280,30 @@ describe('a Product Manager\'s start, once its host reports it', () => {it('says when it runs another model or effort than it asked for, and nothing when it cannot tell', () => {const joinedWith = (configuration: AgentConfiguration) => {const f = swarm()- const startId = f.lead('mate-mac').result.startId as string- return messages(f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration }, owner, hosted(f, 'mate-team')), f.app.conversationId)+ const startId = f.lead('owner-mac').result.startId as string+ return messages(f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration }, owner, hosted(f, 'owner-mac')), f.app.conversationId)}expect(joinedWith({ ...config, model: 'claude-sonnet-5-5', effort: 'high' })).toEqual(- ['Product Manager started on MacBook Pro. It asked for opus at xhigh and runs claude-sonnet-5-5 at high there.'])+ ['Product Manager started on Owner Mac. It asked for opus at xhigh and runs claude-sonnet-5-5 at high there.'])expect(joinedWith({ ...config, model: 'claude-opus-5-5', effort: 'high' })).toEqual(- ['Product Manager started on MacBook Pro. It asked for opus at xhigh and runs claude-opus-5-5 at high there.'])- expect(joinedWith({ ...config, model: 'claude-opus-5-5', effort: 'xhigh' })).toEqual(['Product Manager started on MacBook Pro.'])- expect(joinedWith({ ...config, model: 'claude-opus-5-5[1m]', effort: 'auto' })).toEqual(['Product Manager started on MacBook Pro.'])- expect(joinedWith({ ...config, model: null, effort: null })).toEqual(['Product Manager started on MacBook Pro.'])+ ['Product Manager started on Owner Mac. It asked for opus at xhigh and runs claude-opus-5-5 at high there.'])+ expect(joinedWith({ ...config, model: 'claude-opus-5-5', effort: 'xhigh' })).toEqual(['Product Manager started on Owner Mac.'])+ expect(joinedWith({ ...config, model: 'claude-opus-5-5[1m]', effort: 'auto' })).toEqual(['Product Manager started on Owner Mac.'])+ expect(joinedWith({ ...config, model: null, effort: null })).toEqual(['Product Manager started on Owner Mac.'])})it('running, becomes the project\'s Lead and says on which machine', () => {const f = swarm()- const startId = f.lead('mate-mac').result.startId as string- const joined = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: { ...config, effort: 'xhigh' } }, owner, hosted(f, 'mate-team'))+ const startId = f.lead('owner-mac').result.startId as string+ const joined = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: { ...config, effort: 'xhigh' } }, owner, hosted(f, 'owner-mac'))const agentId = joined.result.agentId as stringconst home = f.state.conversations.find(c => c.id === f.app.conversationId)!expect(home).toMatchObject({ leadId: agentId, agentIds: [agentId] })- expect(f.state.agents.find(a => a.id === agentId)).toMatchObject({ machineId: 'mate-team', machineOwnerId: 'mate', projectId: f.app.projectId })- expect(messages(joined, f.app.conversationId)).toEqual(['Product Manager started on MacBook Pro.'])- expect(f.project().lead).toMatchObject({ status: 'started', machineId: 'mate-team', machineName: 'MacBook Pro' })+ expect(f.state.agents.find(a => a.id === agentId)).toMatchObject({ machineId: 'owner-mac', machineOwnerId: 'owner', projectId: f.app.projectId })+ expect(messages(joined, f.app.conversationId)).toEqual(['Product Manager started on Owner Mac.'])+ expect(f.project().lead).toMatchObject({ status: 'started', machineId: 'owner-mac', machineName: 'Owner Mac' })// Settling it does not call the Product Manager ready for an assignment.- const settled = f.run({ type: 'agent.startSettled', startId, warning: null }, owner, hosted(f, 'mate-team'))+ const settled = f.run({ type: 'agent.startSettled', startId, warning: null }, owner, hosted(f, 'owner-mac'))expect(messages(settled, f.app.conversationId)).toEqual([])})@@ -375,11 +311,11 @@ describe('a Product Manager\'s start, once its host reports it', () => {it('names the coordinator as its project calls it', () => {const f = swarm()f.run({ type: 'project.coordinatorName', projectId: f.app.projectId, name: 'Coordinator' })- const startId = f.lead('mate-mac').result.startId as string+ const startId = f.lead('owner-mac').result.startId as stringexpect(f.state.starts!.find(s => s.id === startId)!.request.name).toBe('Coordinator')expect(refusal(() => f.lead('owner-mac'))).toMatchObject({ code: 'LEAD_STARTING', message: 'This project\'s Coordinator is already starting.' })- const joined = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: { ...config, effort: 'xhigh' } }, owner, hosted(f, 'mate-team'))- expect(messages(joined, f.app.conversationId)).toEqual(['Coordinator started on MacBook Pro.'])+ const joined = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: { ...config, effort: 'xhigh' } }, owner, hosted(f, 'owner-mac'))+ expect(messages(joined, f.app.conversationId)).toEqual(['Coordinator started on Owner Mac.'])const agentId = joined.result.agentId as stringexpect(f.state.agents.find(a => a.id === agentId)!.name).toBe('Coordinator')expect(refusal(() => f.lead('owner-mac'))).toMatchObject({ code: 'LEAD_EXISTS', message: 'This project already has its Coordinator.' })@@ -390,8 +326,8 @@ describe('a Product Manager\'s start, once its host reports it', () => {it('failed on the machine the person chose, says why and waits for them', () => {const f = swarm()- const startId = f.lead('mate-mac').result.startId as string- f.run({ type: 'agent.startFailed', startId, error: 'Could not clone the repository.' }, owner, hosted(f, 'mate-team'))+ const startId = f.lead('owner-mac').result.startId as string+ f.run({ type: 'agent.startFailed', startId, error: 'Could not clone the repository.' }, owner, hosted(f, 'owner-mac'))// Every reader of the project reads it, so not the host's own words (startFailure.ts publicReason).expect(f.project().lead).toMatchObject({ status: 'failed', reason: 'Its machine could not prepare or launch it.' })// They can start it again.@@ -401,16 +337,16 @@ describe('a Product Manager\'s start, once its host reports it', () => {it('refused for want of the owner\'s relay, says so plainly to the project', async () => {const f = swarm()const reason = 'The owner\'s subscription relay is not available on this machine, so a Codex Product Manager cannot sign in here.'- const startId = f.lead('mate-mac').result.startId as string- f.run({ type: 'agent.startFailed', startId, error: reason }, owner, hosted(f, 'mate-team'))+ const startId = f.lead('owner-mac').result.startId as string+ f.run({ type: 'agent.startFailed', startId, error: reason }, owner, hosted(f, 'owner-mac'))expect(f.project().lead).toMatchObject({ status: 'failed', reason })})it('never taken by its machine, fails as a Buddy\'s does', async () => {const { sweepLiveness, BUDDY_PICKUP_MS } = await import('./liveness.js')const f = swarm()- f.lead('mate-mac')- f.machine('mate-team').observation = { ...f.machine('mate-team').observation!, receivedAt: NOW + BUDDY_PICKUP_MS + MINUTE }+ f.lead('owner-mac')+ f.machine('owner-mac').observation = { ...f.machine('owner-mac').observation!, receivedAt: NOW + BUDDY_PICKUP_MS + MINUTE }const said = sweepLiveness(f.state, NOW + BUDDY_PICKUP_MS + MINUTE)expect(f.project().lead).toMatchObject({ status: 'failed', reason: 'Its machine did not start it. Harness there may need an update.' })// Said once in its project's conversation, in the name of the person who asked for it.@@ -421,69 +357,18 @@ describe('a Product Manager\'s start, once its host reports it', () => {})})-// Security reviews 1 and 2 of #2228: the Team account was chosen before checking it could run the requested engine, so a-// busy account, or one with that engine signed out or not offered, refused the start though the Mac itself could run it.+// New Project reads where a Product Manager would run on each teammate's machine (security review 1 of #2228): with Swarm v3,+// nowhere, since it starts only on its person's own computer (task #4120).describe('where a Product Manager on a teammate\'s Mac runs, for its engine', () => {- /** Another project's agent in the Mac's Team account. */- function busy(f: ReturnType<typeof swarm>) {- const web = f.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string }- const group = f.run({ type: 'conversation.create', projectId: web.projectId, title: 'Work', brief: 'Build it.', checks: [] }).result.conversationId as string- f.run({ type: 'agent.add', conversationId: group, machineId: 'mate-team', harnessId: 'web-worker', name: 'Builder', configuration: config, lead: false }, owner,- { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } })- }- const signedOut = (engine: string): Reading => ({ ...reading('team', PASSED),- readiness: { engines: [{ engine, installed: true, signedIn: false }] } } as unknown as Reading)-- it('a Team account busy with another project\'s agents leaves it to the Mac itself, with the engine the Mac runs', () => {- const f = swarm()- f.machine('mate-team').engines = ['codex']- f.machine('mate-mac').engines = ['claude']- busy(f)- expect(f.lead('mate-mac', { engine: 'claude' }).result).toMatchObject({ machineId: 'mate-mac' })- const g = swarm()- g.machine('mate-team').engines = ['codex']- g.machine('mate-mac').engines = ['claude']- busy(g)- // Codex runs only in the busy account: refused for the Mac's reason, and nothing recorded.- expect(refusal(() => g.lead('mate-mac', { engine: 'codex' }))?.code).toBe('ENGINE_NOT_OFFERED')- expect((g.state.starts ?? []).filter(s => s.request.leadFor)).toEqual([])- })-- it('a Team account with the engine signed out, or not offering it, leaves it to the Mac itself', () => {- const out = swarm()- out.machine('mate-team').observation = signedOut('claude')- expect(out.lead('mate-mac', { engine: 'claude' }).result).toMatchObject({ machineId: 'mate-mac' })- const offered = swarm()- offered.machine('mate-team').engines = ['codex']- expect(offered.lead('mate-mac', { engine: 'claude' }).result).toMatchObject({ machineId: 'mate-mac' })- // The engine it runs still goes to the Team account.- expect(swarm().lead('mate-mac', { engine: 'claude' }).result).toMatchObject({ machineId: 'mate-team' })- })-- it('a Mac added as its person joined still runs it only in its Team account, refused when that cannot run the engine', () => {- const f = swarm()- f.machine('mate-mac').teamAccountOnly = true- f.machine('mate-team').observation = signedOut('claude')- expect(refusal(() => f.lead('mate-mac', { engine: 'claude' }))?.code).toBe('ENGINE_UNAVAILABLE')- expect(f.state.starts ?? []).toEqual([])- })-- it('New Project reads the same decision for each engine before the project exists, naming no other project', async () => {+ it('New Project reads the same refusal for each engine before the project exists, naming no other project', async () => {const { leadChoices } = await import('./leadStart.js')const f = swarm()- f.machine('mate-team').engines = ['codex']- f.machine('mate-mac').engines = ['claude']- const context = { now: NOW, teamMachines: ['mate-team'] }- // The owner's own machines are left to Desktop; the Team account row is read through its Mac.- expect(Object.keys(leadChoices(f.state, 'owner', context))).toEqual(['mate-mac'])- expect(leadChoices(f.state, 'owner', context)['mate-mac']).toEqual({ claude: { machineId: 'mate-mac' }, codex: { machineId: 'mate-team' } })- busy(f)- const choices = leadChoices(f.state, 'owner', context)['mate-mac']!- expect(choices.claude).toEqual({ machineId: 'mate-mac' })- expect(choices.codex).toEqual({ refused: 'Codex isn’t offered on MacBook Pro.' })- expect(JSON.stringify(choices)).not.toContain('Web')- // The same answer the start gives.- expect(refusal(() => f.lead('mate-mac', { engine: 'codex' }))?.message).toBe('Codex isn’t offered on MacBook Pro.')+ const choices = leadChoices(f.state, 'owner', { now: NOW, teamMachines: ['mate-team'] })+ expect(Object.keys(choices)).not.toContain('owner-mac')+ for (const byEngine of Object.values(choices)) {+ for (const choice of Object.values(byEngine)) expect(choice).toMatchObject({ refused: expect.any(String) })+ }+ expect(JSON.stringify(choices)).not.toContain('App')})})@@ -504,14 +389,25 @@ describe('the machine a Product Manager starts on', () => {})describe('the terminal of a Product Manager in a Team account', () => {+ /** Its Product Manager running on [machineId]: on the owner's Mac started there, or, from before Swarm v3, in the teammate's+ * Team account, where no new one starts now (task #4120). */async function running(machineId: string) {const f = swarm()// Public, so the Mac's owner reads the project as every member does.f.run({ type: 'project.sharing', projectId: f.app.projectId, visibility: 'public', memberIds: [] })- const startId = f.lead(machineId).result.startId as string- const pool = f.state.starts!.find(s => s.id === startId)!.request.machineId- const contribution = { machineOwnerId: f.machine(pool).contributorId, contributorId: f.machine(pool).contributorId, hostGrant: null }- const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { contribution }).result.agentId as string+ let pm: string+ if (machineId === 'mate-mac') {+ pm = 'pm'+ f.state.agents.push({ id: pm, machineId: 'mate-team', harnessId: 'pm', projectId: f.app.projectId, machineOwnerId: 'mate', contributorId: 'mate',+ membershipGeneration: f.state.people.find(p => p.id === 'mate')!.generation, hostGrant: null, name: 'PM', configuration: config, teamAccount: true } as never)+ const home = f.state.conversations.find(c => c.id === f.app.conversationId)!+ home.agentIds.push(pm); home.leadId = pm+ } else {+ const startId = f.lead(machineId).result.startId as string+ const pool = f.state.starts!.find(s => s.id === startId)!.request.machineId+ const contribution = { machineOwnerId: f.machine(pool).contributorId, contributorId: f.machine(pool).contributorId, hostGrant: null }+ pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { contribution }).result.agentId as string+ }const { canWatchAgent } = await import('./projects.js')const watch = (actor: Actor) => canWatchAgent(f.state, actor, f.state.agents.find(a => a.id === pm)!)const screen = (actor: Actor) => refusal(() => f.run({ type: 'agent.screen', agentId: pm, scrollback: 50 }, actor))?.code ?? 'ok'@@ -597,13 +493,15 @@ describe('the terminal of a Product Manager in a Team account', () => {// its owner's own account. That owner can read whatever the Product Manager reads on their Mac. Project members watch its// terminal live whichever account it runs in (Lead's ruling on #2228).describe('the terminal of a Product Manager on a teammate\'s Mac, as its owner', () => {+ /** From before Swarm v3, which starts none there now (task #4120): a Product Manager on the teammate's Mac, as its owner. */async function running(visibility: 'private' | 'public') {const f = swarm()if (visibility === 'public') f.run({ type: 'project.sharing', projectId: f.app.projectId, visibility: 'public', memberIds: [] })- f.machine('mate-team').observation = reading('team', FAILED)- const startId = f.lead('mate-mac').result.startId as string- const contribution = { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null }- const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { contribution }).result.agentId as string+ const pm = 'pm'+ f.state.agents.push({ id: pm, machineId: 'mate-mac', harnessId: 'pm', projectId: f.app.projectId, machineOwnerId: 'mate', contributorId: 'mate',+ membershipGeneration: f.state.people.find(p => p.id === 'mate')!.generation, hostGrant: null, name: 'PM', configuration: config } as never)+ const home = f.state.conversations.find(c => c.id === f.app.conversationId)!+ home.agentIds.push(pm); home.leadId = pmconst { canWatchAgent } = await import('./projects.js')const agent = f.state.agents.find(a => a.id === pm)!const code = (actor: Actor, command: Command) => refusal(() => f.run(command, actor))?.code ?? 'ok'@@ -612,12 +510,6 @@ describe('the terminal of a Product Manager on a teammate\'s Mac, as its owner',input: (actor: Actor) => code(actor, { type: 'agent.input', agentId: pm, text: 'ls ~' }) }}- it('runs on the Mac itself, outside any Team account', async () => {- const t = await running('private')- expect(t.agent).toMatchObject({ machineId: 'mate-mac', machineOwnerId: 'mate' })- expect((t.agent as { teamAccount?: boolean }).teamAccount).toBeUndefined()- })-it('its project\'s owner watches its terminal live, but neither types in it nor reads its screen in another person\'s account', async () => {for (const visibility of ['private', 'public'] as const) {const t = await running(visibility)@@ -642,41 +534,30 @@ describe('the terminal of a Product Manager on a teammate\'s Mac, as its owner',// Every agent in a Team account runs as one macOS user and can read the others' files, the Product Manager's saved// sessions with people's private chats among them. So a Team account hosting a Product Manager serves only its project.describe('a Team account hosting a Product Manager', () => {- const other = (f: ReturnType<typeof swarm>) => {- const web = f.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string; conversationId: string }- const group = f.run({ type: 'conversation.create', projectId: web.projectId, title: 'Work', brief: 'Build it.', checks: [] }).result.conversationId as string- const request = { conversationId: group, machineId: 'mate-mac', engine: 'claude', name: 'Builder', cwd: `/swarm/${web.projectId}`, worktree: true,- requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const pooled = { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } }- return { start: () => f.run({ type: 'agent.start', request }, owner, pooled), web }+ /** From before Swarm v3, which starts none there now (task #4120): App's Product Manager in the teammate's Team account. */+ const hosting = (f: ReturnType<typeof swarm>) => {+ const pm = 'pm'+ f.state.agents.push({ id: pm, machineId: 'mate-team', harnessId: 'pm', projectId: f.app.projectId, machineOwnerId: 'mate', contributorId: 'mate',+ membershipGeneration: f.state.people.find(p => p.id === 'mate')!.generation, hostGrant: null, name: 'PM', configuration: config, teamAccount: true,+ confidential: true } as never)+ const home = f.state.conversations.find(c => c.id === f.app.conversationId)!+ home.agentIds.push(pm); home.leadId = pm+ return pm}+ /** Another project's agent added by hand in that Team account. */+ const addOther = (f: ReturnType<typeof swarm>, web: { conversationId: string }, harnessId = 'web-worker') =>+ f.run({ type: 'agent.add', conversationId: web.conversationId, machineId: 'mate-team', harnessId, name: harnessId, configuration: config, lead: false },+ mate, { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } })+ const webProject = (f: ReturnType<typeof swarm>) =>+ f.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string; conversationId: string }- it('takes no other project\'s new work while the Product Manager starts or runs there', () => {- const f = swarm(), web = other(f)- f.lead('mate-mac')- expect(refusal(() => web.start())).toMatchObject({ code: 'TEAM_ACCOUNT_HELD',- message: 'The Harness Team account on MacBook Pro runs another project\'s Product Manager, so it takes only that project\'s work for now.' })- })-- it('is not where a Product Manager goes while another project\'s agents run there', () => {- const f = swarm(), web = other(f)- web.start()- expect(refusal(() => f.lead('mate-team'))).toMatchObject({ code: 'TEAM_ACCOUNT_BUSY',- message: 'The Harness Team account on MacBook Pro runs other projects\' agents, so it cannot host this Product Manager now.' })- // Named by its Mac, the Mac takes it itself.- expect(f.lead('mate-mac').result).toMatchObject({ machineId: 'mate-mac' })- })-- it('holds an agent added by hand as it holds a start', () => {+ it('holds an agent added by hand', () => {const f = swarm()- const web = f.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string; conversationId: string }- const add = (conversationId: string, harnessId: string, lead: boolean) => f.run({ type: 'agent.add', conversationId, machineId: 'mate-team', harnessId,- name: harnessId, configuration: config, lead }, mate, { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } })- f.lead('mate-mac')- expect(refusal(() => add(web.conversationId, 'web-worker', false))?.code).toBe('TEAM_ACCOUNT_HELD')+ hosting(f)+ expect(refusal(() => addOther(f, webProject(f)))?.code).toBe('TEAM_ACCOUNT_HELD')// The other way round: another project's agent there first, a Product Manager added by hand is refused.const g = swarm()- const web2 = g.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string; conversationId: string }+ const web2 = webProject(g)const group = g.run({ type: 'conversation.create', projectId: web2.projectId, title: 'Work', brief: 'Build it.', checks: [] }).result.conversationId as stringconst pooled = { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } }g.run({ type: 'agent.add', conversationId: group, machineId: 'mate-team', harnessId: 'web-worker', name: 'W', configuration: config, lead: false }, mate, pooled)@@ -686,18 +567,13 @@ describe('a Team account hosting a Product Manager', () => {expect(g.state.agents.find(a => a.harnessId === 'web-worker')).toMatchObject({ teamAccount: true })})- // Security re-check 2 of #2089: the hold went the moment the Product Manager left the roster, before its host deleted its- // saved session there. It stays until the host confirms the close, which it does only once that data is deleted.it('stays held after its Product Manager is removed, until its host confirms its data is gone, and says so if that lasts', async () => {const { sweepLiveness, PURGE_NOTICE_MS } = await import('./liveness.js')- const f = swarm(), web = other(f)- const startId = f.lead('mate-mac').result.startId as string- const contribution = { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null }- const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { contribution }).result.agentId as string- f.run({ type: 'agent.startSettled', startId, warning: null }, owner, { contribution })+ const f = swarm(), web = webProject(f)+ const pm = hosting(f)f.run({ type: 'project.delete', projectId: f.app.projectId })expect(f.state.agents.some(a => a.id === pm)).toBe(false)- expect(refusal(() => web.start())?.code).toBe('TEAM_ACCOUNT_HELD')+ expect(refusal(() => addOther(f, web))?.code).toBe('TEAM_ACCOUNT_HELD')// Still not confirmed after a while: its project's conversation is gone with it, so the Swarm's Lead conversation hears.const later = sweepLiveness(f.state, NOW + PURGE_NOTICE_MS + MINUTE)// Its source names the machine, so a Buddy reading this conversation reads it without (store.ts withoutMachineNames; review 2 of #2258).@@ -705,15 +581,13 @@ describe('a Team account hosting a Product Manager', () => {expect(later[0]!.text).toBe('The saved session of a removed agent that held people\'s private chats, on MacBook Pro, is not deleted yet, so its Harness Team account takes no other project\'s work until it is.')expect(sweepLiveness(f.state, NOW + PURGE_NOTICE_MS + 2 * MINUTE)).toEqual([])f.run({ type: 'agent.sessionClosed', agentId: pm, harnessId: 'pm' }, mate)- expect(web.start().result.startId).toBeTruthy()+ expect(refusal(() => addOther(f, web))).toBeNull()})it('keeps a removed confidential session from being added back while its data is being deleted (review of #2142)', () => {- const f = swarm(), { web } = other(f)- const startId = f.lead('mate-mac').result.startId as string+ const f = swarm(), web = webProject(f)+ const pm = hosting(f)const contribution = { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null }- const pm = f.run({ type: 'agent.started', startId, harnessId: 'pm', configuration: config }, owner, { contribution }).result.agentId as string- f.run({ type: 'agent.startSettled', startId, warning: null }, owner, { contribution })f.run({ type: 'project.delete', projectId: f.app.projectId })// Even into the very project it is held for: adding it back dropped the hold, its private chats still on the account.f.state.closingSessions![0]!.heldFor = web.projectId@@ -736,9 +610,9 @@ describe('a Team account hosting a Product Manager', () => {})})-// Security reviews of #2705 (destination access, Team accounts): moving a running Product Manager to another machine is a new-// start there, so it follows a new start's placement, placed and recorded as the person who asked, and only the project's-// owner asks it. The PM machine's owner still switches the engine or account on that machine itself.+// Security reviews of #2705 (destination access): moving a running Product Manager to another machine is a new start there, so it+// follows a new start's placement, recorded as the person who asked, and only the project's owner asks it. With Swarm v3 that is+// only another of its person's own computers (task #4120).describe('moving a running Product Manager to another machine', () => {const contributionOf = (machineOwnerId: string) => ({ contribution: { machineOwnerId, contributorId: machineOwnerId, hostGrant: null } })/** The owner's Swarm with its Product Manager running on [on], every host able to start and switch one. */@@ -746,6 +620,8 @@ describe('moving a running Product Manager to another machine', () => {const f = swarm()// A project the teammate reads, so its refusals are about who may move it, not who may see it.f.project().visibility = 'public'+ // A second computer of the owner's own, where a move may go.+ f.state.machines!.push({ ...structuredClone(f.machine('owner-mac')), machineId: 'owner-mini', name: 'Owner Mini' })for (const pool of f.state.machines!) pool.observation = { ...pool.observation!, capabilities: ['leadStart', 'leadSwitch'] }prepare(f)const startId = f.lead(on).result.startId as string@@ -759,85 +635,39 @@ describe('moving a running Product Manager to another machine', () => {return { f, pm, move, candidates, agent }}- it('places the move in a teammate\'s Team account, as a new start would, recorded as the person who asked', () => {+ it('moves to another of its person\'s own computers, recorded as the person who asked', () => {const s = moving()- s.move('mate-mac')- expect(s.candidates()).toEqual([expect.objectContaining({ actorKey: 'person:owner', machineOwnerId: 'mate',- request: expect.objectContaining({ machineId: 'mate-team', leadFor: expect.objectContaining({ personId: 'owner', switchId: s.agent().switchRequest!.id }) }) })])- expect(s.agent().switchRequest).toMatchObject({ targetMachineId: 'mate-team', requestedBy: 'owner' })- })-- // Security review 2 of #2705 at 00d97f9a0: the Mac whose Team account already runs the PM is placed back in that account, so- // it is a switch where it runs, and no candidate start is left to time out with a false failure line.- it('switches in place, leaving no candidate, when the Mac named places it back in the Team account it runs in', () => {- const s = moving('mate-mac')- expect(s.agent().machineId).toBe('mate-team')- s.move('mate-mac')- expect(s.candidates()).toEqual([])- expect((s.f.state.starts ?? []).filter(start => !start.harnessId && !start.error)).toEqual([])- expect(s.agent().switchRequest).toMatchObject({ engine: 'claude', requestedBy: 'owner' })- expect(s.agent().switchRequest).not.toHaveProperty('targetMachineId')- expect(s.f.project().lead).toMatchObject({ status: 'started', machineId: 'mate-team' })- })-- it('refuses the PM machine\'s owner who does not own the project, on any other machine, and records nothing', () => {- // Its Team account cannot take it, so it runs on the Mac itself, as its owner.- const s = moving('mate-mac', f => { f.machine('mate-team').observation = { ...reading('team', FAILED), capabilities: ['leadStart', 'leadSwitch'] } })- expect(s.agent()).toMatchObject({ machineId: 'mate-mac', machineOwnerId: 'mate' })- for (const machineId of ['owner-mac', 'mate-team']) {- expect(refusal(() => s.move(machineId, mate))?.code).toBe('PROJECT_OWNER_REQUIRED')- }- expect(s.candidates()).toEqual([])- expect(s.agent().switchRequest).toBeUndefined()- // On the machine it runs on, its owner still switches the engine or account.- s.move('mate-mac', mate)- expect(s.agent().switchRequest).toMatchObject({ requestedBy: 'mate' })- expect(s.agent().switchRequest).not.toHaveProperty('targetMachineId')+ s.move('owner-mini')+ expect(s.candidates()).toEqual([expect.objectContaining({ actorKey: 'person:owner', machineOwnerId: 'owner',+ request: expect.objectContaining({ machineId: 'owner-mini', leadFor: expect.objectContaining({ personId: 'owner', switchId: s.agent().switchRequest!.id }) }) })])+ expect(s.agent().switchRequest).toMatchObject({ targetMachineId: 'owner-mini', requestedBy: 'owner' })})- it('refuses a member who owns neither the project nor the PM\'s machine', () => {+ it('refuses a teammate\'s Mac and its Team account, and records nothing', () => {const s = moving()- expect(refusal(() => s.move('mate-mac', mate))?.code).toBe('PROJECT_OWNER_REQUIRED')+ expect(refusal(() => s.move('mate-mac'))?.code).toBe('NOT_YOUR_COMPUTER')+ expect(refusal(() => s.move('mate-team'))?.code).toBe('TEAM_ACCOUNTS_REMOVED')expect(s.candidates()).toEqual([])+ expect(s.agent().switchRequest).toBeUndefined()})- it('takes a teammate\'s Team account only while Team accounts take work: with none, the Mac itself, and the account named is refused', () => {- const idle = { teamAccountsIdle: true }- const named = moving()- expect(refusal(() => named.move('mate-team', owner, idle))?.code).toBe('TEAM_ACCOUNT_REQUIRED')- expect(named.candidates()).toEqual([])- const mac = moving()- mac.move('mate-mac', owner, idle)- expect(mac.candidates().map(s => s.request.machineId)).toEqual(['mate-mac'])- })-- it('does not put it in a Team account that runs another project\'s agents', () => {+ it('refuses a member who owns neither the project nor the PM\'s machine', () => {const s = moving()- const web = s.f.run({ type: 'project.create', name: 'Web', visibility: 'public', brief: '' }).result as { projectId: string }- const group = s.f.run({ type: 'conversation.create', projectId: web.projectId, title: 'Work', brief: 'Build it.', checks: [] }).result.conversationId as string- s.f.run({ type: 'agent.start', request: { conversationId: group, machineId: 'mate-mac', engine: 'claude', name: 'Builder', cwd: `/swarm/${web.projectId}`,- worktree: true, requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } } }, owner, contributionOf('mate'))- expect(refusal(() => s.move('mate-team'))?.code).toBe('TEAM_ACCOUNT_BUSY')+ expect(refusal(() => s.move('mate-mac', mate))?.code).toBe('PROJECT_OWNER_REQUIRED')expect(s.candidates()).toEqual([])- // Named by its Mac, the Mac takes it itself.- s.move('mate-mac')- expect(s.candidates().map(c => c.request.machineId)).toEqual(['mate-mac'])})- it('refuses a machine that is not in the Swarm, withdrawn, failing its privacy check or too old to switch, and records nothing', () => {+ it('refuses a machine that is not in the Swarm, withdrawn or too old to switch, and records nothing', () => {const unlisted = moving()expect(refusal(() => unlisted.move('nowhere'))?.code).toBe('MACHINE_NOT_LISTED')const withdrawn = moving()- withdrawn.f.machine('mate-mac').membershipGeneration = 'an earlier membership'- expect(refusal(() => withdrawn.move('mate-mac'))?.code).toBe('CONTRIBUTION_REVOKED')- const failing = moving()- failing.f.machine('mate-team').observation = { ...reading('team', FAILED), capabilities: ['leadStart', 'leadSwitch'] }- expect(refusal(() => failing.move('mate-team'))?.code).toBe('PRIVACY_CHECK_FAILED')+ withdrawn.f.machine('owner-mini').membershipGeneration = 'an earlier membership'+ expect(refusal(() => withdrawn.move('owner-mini'))?.code).toBe('CONTRIBUTION_REVOKED')const old = moving()- old.f.machine('mate-team').observation = { ...reading('team', PASSED), capabilities: ['leadStart'] }+ old.f.machine('owner-mini').observation = { ...old.f.machine('owner-mini').observation!, capabilities: ['leadStart'] }const lead = structuredClone(old.f.project().lead)- expect(refusal(() => old.move('mate-team'))?.code).toBe('HOST_OUTDATED')- for (const s of [unlisted, withdrawn, failing, old]) {+ expect(refusal(() => old.move('owner-mini'))?.code).toBe('HOST_OUTDATED')+ for (const s of [unlisted, withdrawn, old]) {expect(s.candidates()).toEqual([])expect(s.agent().switchRequest).toBeUndefined()}diff --git a/backend/src/superTabs/leadStart.ts b/backend/src/superTabs/leadStart.tsindex e0663255e..b313648dc 100644--- a/backend/src/superTabs/leadStart.ts+++ b/backend/src/superTabs/leadStart.ts@@ -1,13 +1,11 @@/** A project's Product Manager started by the Swarm on one of its machines (Dee, 10-29, option B), as a Buddy's start is- * (buddies.ts): recorded on the machine's contribution and launched by its host. Any machine of the Swarm takes it (Ken,- * 10-29): on another person's Mac it runs in that Mac's Harness Team account when the account can take it now, else on the- * Mac itself, as its owner, whatever the Swarm's switch (machines.ts teamAccountRequired) says for workers. Its person always- * names the machine: only they know which one stays on (Ken, 10-29). Desktop's own-machine flow (project.create, a local- * start, agent.add) is unchanged. */-import { admitMachineStart, contributedEngines, failTeamWork, machineContribution, projectFolder, projectsOnMachine, teamAccountPool, teamPoolOf,- noRepositoryStart, slotCounter, teamWorkRefusal, ownAccountWork, ownAccountTeamEntry, failOwnAccountTeamEntry, type ContributedMachine } from './machines.js'+ * (buddies.ts): recorded on the machine's contribution and launched by its host. Its person names the machine, which is their+ * own computer: Swarm v3 starts no agent on another person's computer and none in a Team account (task #4120). Desktop's+ * own-machine flow (project.create, a local start, agent.add) is unchanged. */+import { admitMachineStart, contributedEngines, failTeamWork, machineContribution, NOT_YOUR_COMPUTER, projectFolder, projectsOnMachine, teamAccountPool,+ noRepositoryStart, slotCounter, TEAM_ACCOUNTS_GONE, type ContributedMachine } from './machines.js'import { actorKey, fail, person, SuperTabError, type AgentStart, type AgentStartRequest, type Conversation, type Person, type SuperTabState } from './model.js'-import { BUILT_IN_ROLE_DEFAULTS, ownsProject, projectsOf, type SwarmProject } from './projects.js'+import { BUILT_IN_ROLE_DEFAULTS, projectsOf, type SwarmProject } from './projects.js'import { failureNotice, publicReason } from './startFailure.js'import { coordinatorNameOf } from './instructions.js'@@ -35,7 +33,6 @@ export interface LeadContext {now: numberteamMachines?: readonly string[]otherWorkspaceMachines?: readonly string[]- teamAccountsIdle?: boolean/** The slots of each pool, counted once for a read that admits many (machines.ts slotCounter). */slots?: (pool: ContributedMachine) => number}@@ -92,45 +89,13 @@ export function leadHost(state: SuperTabState, project: SwarmProject, machineId:const startIn = (pool: ContributedMachine): AgentStartRequest => noRepositoryStart(pool, project, { conversationId: project.leadConversationId, machineId: pool.machineId,engine: request.engine, ...(request.model ? { model: request.model } : {}), ...(request.effort ? { effort: request.effort } : {}), name: coordinatorNameOf(project),cwd: projectFolder(pool, project), worktree: true, ...(request.branchRef ? { branchRef: request.branchRef } : {}), requirements: LEAD_REQUIREMENTS, leadFor })- const teamMachines = context.teamMachines ?? []- // With no GitHub App a Team account takes no work (machines.ts teamMachineFor).- const teamsWork = !context.teamAccountsIdle- const refusal = (pool: ContributedMachine) => teamWorkRefusal(pool, context.now, teamMachines.includes(pool.machineId), true,- (context.otherWorkspaceMachines ?? []).includes(pool.machineId))- let candidates: ContributedMachine[]- if (ownsProject(state, named.contributorId, project)) candidates = [named]- else if (teamAccountPool(named)) {- // Its Mac's owner runs teammates' work in their own account: the Mac, not this entry (machines.ts ownAccountTeamEntry, #3060).- const mac = ownAccountTeamEntry(state, named.machineId, project, false)- if (mac) failOwnAccountTeamEntry(mac)- if (!teamsWork) fail('TEAM_ACCOUNT_REQUIRED', `Harness Team accounts take no work in this Swarm yet, so ${named.name} runs only its owner's projects.`, 403)- const why = refusal(named)- if (why) failTeamWork(why)- candidates = [named]- } else {- const team = teamsWork ? teamPoolOf(state, named, teamMachines) : undefined- // Its owner lets teammates' work run in their own account there (machines.ts ownAccountWork): the Mac itself, as its owner.- if (ownAccountWork(named)) candidates = [named]- // A Mac added as its person joined, not lent, takes teammates' work only in its Team account (machines.ts teamAccountOnly).- else if (named.teamAccountOnly) {- const pool = team ?? named- const why = refusal(pool)- if (why) failTeamWork(why)- candidates = [pool]- } else candidates = team && !refusal(team) ? [team, named] : [named]- }- // The Team account first, with every check its start has (engine, sign-in, room, other projects' work, its host); refused- // there for any reason, the Mac itself (security reviews 1 and 2 of #2228). The last one's reason is the answer.- for (const [i, pool] of candidates.entries()) {- const start = startIn(pool)- try {- admitLead(state, project, pool, start, context)- return start- } catch (error) {- if (!(error instanceof SuperTabError) || i === candidates.length - 1) throw error- }- }- throw new Error('unreachable: a Product Manager has at least one candidate machine')+ // A PM starts only on its person's own computer, as them, and never in a Team account (task #4120, the PM's ruling): the+ // person starting it is [leadFor]'s, else the project's owner.+ if (teamAccountPool(named)) failTeamWork(TEAM_ACCOUNTS_GONE)+ if (named.contributorId !== (leadFor?.personId ?? project.ownerId)) failTeamWork({ code: 'NOT_YOUR_COMPUTER', reason: NOT_YOUR_COMPUTER })+ const start = startIn(named)+ admitLead(state, project, named, start, context)+ return start}/** Where New Project's Product Manager would run on each teammate's machine, for [personId] as its owner, by engine: thediff --git a/backend/src/superTabs/machineAccess.test.ts b/backend/src/superTabs/machineAccess.test.tsindex 7f24a1a78..f18f355c0 100644--- a/backend/src/superTabs/machineAccess.test.ts+++ b/backend/src/superTabs/machineAccess.test.ts@@ -71,7 +71,8 @@ function swarm() {const group = (projectId = 'lead', actor: Actor = owner, requires?: Record<string, unknown>) => String(run({ type: 'conversation.create', projectId, title: 'Work',...(requires ? { task: { goal: 'Test on a lamp.', changes: 'Firmware.', constraints: 'None.', owns: ['fw'], requires } } : { brief: 'Build it.' }),checks: [] } as Command, actor).result.conversationId)- const start = (conversationId: string, actor: Actor = owner, projectId = 'lead') =>+ /** Gray's start on Gray's own Mac: Swarm v3 starts a new agent only on its own person's computer (task #4120). */+ const start = (conversationId: string, actor: Actor = gray, projectId = 'lead') =>run({ type: 'agent.start', request: { conversationId, machineId: 'gray-mac', engine: 'codex', name: 'Builder', cwd: `/swarm/${projectId}`, worktree: true,requirements } }, actor, joined)return { run, machine, access, add, entry, agent, group, start, joined, grays, leadActor, generation, get state() { return state }, set state(s) { state = s } }@@ -345,10 +346,10 @@ describe('requires.access and the start check (design section 3)', () => {expect(f.state.starts ?? []).toEqual([])})- it('never counts the owner\'s unshared own-account entry for a teammate\'s task, nor the Team account for it', () => {+ it('never counts the owner\'s unshared own-account entry for a teammate\'s task', () => {const f = swarm()f.add('Lamp')- // The Swarm owner's project is a teammate's on Gray's Mac: it runs in the Team account, which has no Lamp.+ // The Swarm owner's project is a teammate's on Gray's Mac: Gray's own Lamp serves it only once Gray shares it.const work = f.group('lead', owner, { access: ['Lamp'] })expect(refusal(() => f.start(work))).toMatchObject({ code: 'ACCESS_MISSING', message: 'Lamp is in gray\'s own account, not shared with teammates.' })})@@ -361,32 +362,19 @@ describe('requires.access and the start check (design section 3)', () => {const started = f.start(work)expect(lastStart(f).machineId).toBe('gray-mac')expect(started.result.moved).toBeUndefined()- // A task that needs nothing shared still goes to the Team account, as before.+ // A task that needs nothing stays on the Mac too: no start moves to a Team account any more (task #4120).f.start(f.group('lead', owner))- expect(lastStart(f).machineId).toBe('gray-team')- })-- it('starts a recorded route\'s Mac candidate on the Mac only for a task that names the shared entry (security review 2)', () => {- const f = swarm()- const id = f.add('Lamp')- f.access({ action: 'change', entryId: id, teammates: true })- const named = f.group('lead', owner, { access: ['Lamp'] })- const routed = f.run({ type: 'route.record', conversationId: named, decision: record([candidate('c0', 'gray-mac')]) } as Command, owner)- expect(routed.routeDecisions[0]).toMatchObject({ op: 'create', record: { candidates: [{ id: 'c0' }], excluded: [] } })- f.start(named)expect(lastStart(f).machineId).toBe('gray-mac')- // Named in the route alone, not the task: the start goes to the Team account, which the route offers in its place.- f.start(f.group('lead', owner))- expect(lastStart(f).machineId).toBe('gray-team')})- it('sends Team-written code to the Team account even for a shared entry, and refuses it there', () => {+ // Swarm v3 (task #4120, the PM's ruling): code a Team agent wrote runs only on its project owner's own computer.+ it('runs Team-written code only on the project owner\'s own computer, even for a shared entry', () => {const f = swarm()const id = f.add('Lamp')f.access({ action: 'change', entryId: id, teammates: true })const work = f.group('lead', owner, { access: ['Lamp'] })f.state.conversations.find(c => c.id === work)!.teamWritten = true- expect(refusal(() => f.start(work))?.code).toBe('ACCESS_MISSING')+ expect(refusal(() => f.start(work))?.code).toBe('TEAM_WRITTEN_WORK')expect(f.state.starts ?? []).toEqual([])})@@ -400,9 +388,9 @@ describe('requires.access and the start check (design section 3)', () => {it('refuses an entry waiting for its owner to confirm', () => {const f = swarm()- f.add('Lamp', { account: 'team', askedIn: { conversationId: 'lead', messageId: 'm-1' } }, f.leadActor, said('owner'))- const work = f.group('lead', owner, { access: ['Lamp'] })- expect(refusal(() => f.start(work))).toMatchObject({ code: 'ACCESS_MISSING', message: 'Lamp on Gray\'s Mac is waiting for gray to confirm.' })+ f.add('Lamp', { askedIn: { conversationId: 'lead', messageId: 'm-1' } }, f.leadActor, said('owner'))+ const work = f.group(f.grays, gray, { access: ['Lamp'] })+ expect(refusal(() => f.start(work, gray, f.grays))).toMatchObject({ code: 'ACCESS_MISSING', message: 'Lamp on Gray\'s Mac is waiting for gray to confirm.' })})it('refuses the owner\'s own task needing a Team-account entry: that account runs only teammates\' work', () => {@@ -428,21 +416,25 @@ describe('requires.access and the start check (design section 3)', () => {it('matches names without case or spacing, and leaves a start with no requirement as it was', () => {const f = swarm()- f.add('Lamp', { account: 'team' })- f.start(f.group('lead', owner, { access: [' lamp '] }))- expect(lastStart(f).machineId).toBe('gray-team')+ f.add('Lamp')+ f.start(f.group(f.grays, gray, { access: [' lamp '] }), gray, f.grays)+ expect(lastStart(f).machineId).toBe('gray-mac')const g = swarm()g.start(g.group('lead', owner))- expect(g.state.starts!.at(-1)!.request.machineId).toBe('gray-team')+ expect(g.state.starts!.at(-1)!.request.machineId).toBe('gray-mac')})it('leaves a machine without the access out of a recorded route, and refuses it as the only choice', () => {const f = swarm()const work = f.group('lead', owner, { access: ['Lamp'] })- f.add('Lamp', { account: 'team' })+ const id = f.add('Lamp')+ f.access({ action: 'change', entryId: id, teammates: true })expect(refusal(() => f.run({ type: 'route.record', conversationId: work, decision: record([candidate('c0', 'owner-mac')]) } as Command, owner))).toMatchObject({ code: 'ACCESS_MISSING', message: 'No Lamp here. Route again.' })- const routed = f.run({ type: 'route.record', conversationId: work, decision: record([candidate('c0', 'owner-mac'), candidate('c1', 'gray-mac')]) } as Command, owner)+ // Gray's own agent on Gray's Mac, where Gray shared the Lamp: it stays (a new agent there is Gray's alone to start, task #4120).+ f.agent('gray-builder', 'gray-mac')+ const member = { ...candidate('c1', 'gray-mac'), kind: 'member', agentId: 'gray-builder' }+ const routed = f.run({ type: 'route.record', conversationId: work, decision: record([candidate('c0', 'owner-mac'), member]) } as Command, owner)expect(routed.routeDecisions[0]).toMatchObject({ op: 'create', record: { candidates: [{ id: 'c1' }],excluded: [{ title: 'c0 on owner-mac', reason: 'No Lamp here.' }] } })})diff --git a/backend/src/superTabs/machineAccess.ts b/backend/src/superTabs/machineAccess.tsindex 0d32f845d..2aa43e74c 100644--- a/backend/src/superTabs/machineAccess.ts+++ b/backend/src/superTabs/machineAccess.ts@@ -199,16 +199,6 @@ export const taskAccess = (group: Pick<Conversation, 'task'> | undefined): strinconst entryFor = (mac: ContributedMachine, name: string, account: AccessEntry['account']): AccessEntry | undefined =>mac.access?.find(e => e.account === account && sameAccessName(e.name, name))-/**- * Whether every name in [needed] is an own-account entry of [pool] its owner shared with teammates (`teammates`), ok: a- * teammate's task that needs them runs in the owner's own account on that Mac, as with own-account work (design section 4).- * Never for a Harness Team account's pool, which keeps no list, and never for a task that needs nothing.- */-export function sharedOwnAccess(pool: ContributedMachine | undefined, needed: readonly string[]): boolean {- if (!pool || pool.hostMachineId || pool.buddyOnly || !needed.length) return false- return needed.every(name => { const e = entryFor(pool, name, 'own'); return !!e && e.state === 'ok' && e.teammates === true })-}-/*** Why work for [project] that needs [needed] cannot run on [machineId], the pool it would run in (after teamMachineFor), or* null. It reads the entries of that account only: the Mac's own for the Mac, its Team account's for the Team pool. An entrydiff --git a/backend/src/superTabs/machineProjects.test.ts b/backend/src/superTabs/machineProjects.test.tsindex 61fb76dfa..5ac8e3ea5 100644--- a/backend/src/superTabs/machineProjects.test.ts+++ b/backend/src/superTabs/machineProjects.test.ts@@ -46,8 +46,9 @@ function swarm() {const requirements = { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false }const request = (conversationId: string, machineId: string, projectId: string) =>({ conversationId, machineId, engine: 'codex', name: 'Builder', cwd: `/swarm/${projectId}`, worktree: true, requirements })+ // A new agent starts only on its own person's computer, as them (task #4120): the machine's person starts it.const start = (conversationId: string, machineId: string, projectId: string) => run({ type: 'agent.start', request: request(conversationId, machineId, projectId) },- owner, { contribution: { machineOwnerId: machine(machineId).contributorId, contributorId: machine(machineId).contributorId, hostGrant: null } })+ machine(machineId).contributorId === 'tony' ? tony : owner, { contribution: { machineOwnerId: machine(machineId).contributorId, contributorId: machine(machineId).contributorId, hostGrant: null } })/** An agent already in the Swarm on [machineId], of [projectId]. */const member = (id: string, machineId: string, projectId: string) => {const contributorId = machine(machineId).contributorId@@ -160,21 +161,19 @@ describe('a machine kept for some projects', () => {const f = swarm()f.limit(['lead'])const work = f.group(f.lampos)- const effects = f.run({ type: 'route.record', conversationId: work, decision: record([candidate('c0', 'owner-mac'), candidate('c1', 'tony-mac')]) } as Command)+ // Tony's own agent there: a new agent would start only on its starter's own computer (task #4120).+ const tonys = { kind: 'member', agentId: f.member('tonys', 'tony-mac', f.lampos) }+ const effects = f.run({ type: 'route.record', conversationId: work, decision: record([candidate('c0', 'owner-mac'), candidate('c1', 'tony-mac', tonys)]) } as Command)expect(effects.routeDecisions[0]).toMatchObject({ op: 'create', record: { candidates: [{ id: 'c0' }],excluded: [{ title: 'c1 on tony-mac', reason: 'MacBook Pro runs only Pilot.' }] } })- expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group(f.lampos), decision: record([candidate('c0', 'tony-mac')]) } as Command))).toMatchObject({ code: 'MACHINE_PROJECTS', message: 'MacBook Pro runs only Pilot. Route again.' })+ expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group(f.lampos), decision: record([candidate('c0', 'tony-mac', tonys)]) } as Command))).toMatchObject({ code: 'MACHINE_PROJECTS', message: 'MacBook Pro runs only Pilot. Route again.' })})- it('holds for its Mac\'s Harness Team account too', () => {+ // A Team account takes no new start at all now (task #4120, teamAccountsRemoved.test.ts); the list stays the Mac's own.+ it('is set on the Mac, never on its Harness Team account', () => {const f = swarm()f.state.machines!.push(f.pool('tony-team', 'tony', 'MacBook Pro · Team', { hostMachineId: 'tony-mac',observation: { ...f.machine('tony-mac').observation!, sessionKind: 'team', privacy: { mode: 'dedicated', seenAt: NOW } } }))- f.limit(['lead'])- const theirs = f.group(f.lampos), ours = f.group('lead')- expect(refusal(() => admitMachineStart(f.state, f.request(theirs, 'tony-team', f.lampos), NOW, undefined, ['tony-team']))?.code).toBe('MACHINE_PROJECTS')- expect(admitMachineStart(f.state, f.request(ours, 'tony-team', 'lead'), NOW, undefined, ['tony-team'])?.machineId).toBe('tony-team')- // It is set on the Mac, never on its account.expect(refusal(() => f.limit(['lead'], 'tony-team'))?.code).toBe('NOT_FOUND')})diff --git a/backend/src/superTabs/machineRules.commands.test.ts b/backend/src/superTabs/machineRules.commands.test.tsindex 6dbd1934b..96a5c93a7 100644--- a/backend/src/superTabs/machineRules.commands.test.ts+++ b/backend/src/superTabs/machineRules.commands.test.ts@@ -41,7 +41,9 @@ const refusal = (run: () => unknown) => { try { run(); return null } catch (errodescribe('a start follows the machine rules', () => {const start = (s: ReturnType<typeof swarm>, group: string, machineId: string, engine: string, now = BACK) => s.run({ type: 'agent.start',request: { conversationId: group, machineId, engine, name: 'Worker', cwd: '/repo', worktree: true,- requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: [], devices: [], quotaRequired: false } } }, s.as(s.pm), { now })+ requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: [], devices: [], quotaRequired: false } } }, s.as(s.pm),+ // The PM's own person's computer (task #4120: a start runs as the machine's own person, through no share).+ { now, contribution: { machineOwnerId: 'owner', contributorId: 'owner' } })it('refuses an engine a machine refuses, a Reviewer where none runs, and anything while the machine is away, with the why', () => {const s = swarm()@@ -61,7 +63,7 @@ describe('a start follows the machine rules', () => {const work = s.task('Server', ['backend/src/a.ts'])expect(refusal(() => s.run({ type: 'agent.start', request: { conversationId: work, machineId: 'no-codex', engine: 'codex', name: 'Worker', cwd: '/repo',worktree: true, requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: [], devices: [], quotaRequired: false } } },- s.as(s.pm), { projectRules: { revision: 0, rules: SEED_RULES } }))).toBeNull()+ s.as(s.pm), { projectRules: { revision: 0, rules: SEED_RULES }, contribution: { machineOwnerId: 'owner', contributorId: 'owner' } }))).toBeNull()})})diff --git a/backend/src/superTabs/machines.ts b/backend/src/superTabs/machines.tsindex 718efec25..4a10128de 100644--- a/backend/src/superTabs/machines.ts+++ b/backend/src/superTabs/machines.ts@@ -1,4 +1,4 @@-import { accessRefusal, sharedOwnAccess, taskAccess } from './machineAccess.js'+import { accessRefusal, taskAccess } from './machineAccess.js'import { createHash } from 'node:crypto'import { z } from 'zod'import { engineUnusable, machineSuspensionReason } from './engineHealth.js'@@ -314,7 +314,7 @@ export function observedPrivacy(previous: StoredPrivacy | undefined, reported: M}export type TeamWorkCode = 'TEAM_WRITTEN_WORK' | 'MACHINE_OFFLINE' | 'TEAM_ACCOUNT_REQUIRED' | 'PRIVACY_UNCHECKED' | 'PRIVACY_CHECK_FAILED' | 'PRIVACY_CHECK_STALE'- | 'MACHINE_IN_OTHER_WORKSPACE' | 'NOT_SWARM_MACHINE' | 'MACHINE_PROJECTS' | 'ACCESS_MISSING' | 'TEAM_ACCOUNT_JOINING'+ | 'MACHINE_IN_OTHER_WORKSPACE' | 'NOT_SWARM_MACHINE' | 'MACHINE_PROJECTS' | 'ACCESS_MISSING' | 'TEAM_ACCOUNT_JOINING' | 'TEAM_ACCOUNTS_REMOVED' | 'NOT_YOUR_COMPUTER' | 'READ_ONLY'export interface TeamWorkRefusal { code: TeamWorkCode; reason: string }/** Refusals that hold until a person acts on the machine; a stale check or an offline machine may pass again by itself. */export const LASTING_TEAM_REFUSALS: readonly string[] = ['TEAM_ACCOUNT_REQUIRED', 'PRIVACY_UNCHECKED', 'PRIVACY_CHECK_FAILED', 'MACHINE_IN_OTHER_WORKSPACE']@@ -381,34 +381,34 @@ export function teamWorkRefusal(pool: ContributedMachine, now: number, teamRow =}/**- * Whether work for [project] may run on [machineId] under [contributorId]'s grant there: the pool's contributor for a- * start on a contributed machine, the agent's contributor for an agent already in the Swarm. The project owner's own- * grant always may. A teammate's needs a contributed Team machine that shows its privacy (teamWorkRefusal); a machine- * outside the Swarm's Machines list reports nothing, so it never does. `teamMachines`: the tab's machines whose account- * row is signed in as a team account, read by the store.+ * Whether work for [project] may run on [machineId] under [contributorId]'s grant there: the pool's contributor for a start, the+ * agent's contributor for an agent already in the Swarm. Swarm v3 has no Team accounts (task #4120, the PM's ruling there): an+ * agent a person brought works on any task of a project that person can read, in their own account, so the work runs as its own+ * person and never as a machine owner it does not belong to.*/-export function teamWorkCheck(state: SuperTabState, machineId: string, contributorId: string, project: SwarmProject, now: number,- teamMachines: readonly string[] = [], otherWorkspaceMachines: readonly string[] = [],- /** What the task needs to reach (machineAccess.ts): own-account entries its owner shared let it run in their account. */- access: readonly string[] = []): TeamWorkRefusal | null {+export function teamWorkCheck(state: SuperTabState, machineId: string, contributorId: string, project: SwarmProject): TeamWorkRefusal | null {// Its owner kept it for other projects (machine.projects): whoever's project and grant it is.const kept = machineProjectRefusal(state, machineId, project)if (kept) return keptconst pool = state.machines?.find(m => m.machineId === machineId)- // A Buddy-only machine is its person's alone: an agent they added there takes their own projects' work and no other's,- // whatever the Team account switches say (security re-check 1 of #2234). New starts there are refused in admitMachineStart.+ // A Buddy-only machine is its person's alone: an agent they added there takes their own projects' work and no other's+ // (security re-check 1 of #2234). New starts there are refused in admitMachineStart.if (pool?.buddyOnly) return ownsProject(state, pool.contributorId, project) ? null : { code: 'NOT_SWARM_MACHINE', reason: NOT_SWARM_MACHINE }- if (ownsProject(state, contributorId, project)) return null- if (!pool) {- // Off the Machines list nothing reports a team account (store.ts teamMachines), so this is the switch alone.- if (!teamAccountRequired()) return null- return { code: 'TEAM_ACCOUNT_REQUIRED', reason: `This machine is not a Team machine of this Swarm, ${ONLY_OWN}.` }- }- // Its owner shared what this task needs from their own account with teammates: the owner's choice, as ownAccountWork, for- // the tasks that need it only (design section 4).- if (sharedOwnAccess(pool, access)) return null- return teamWorkRefusal(pool, now, teamMachines.includes(machineId), teamAccountRequired(), otherWorkspaceMachines.includes(machineId))-}+ // A Team account's agent already in the Swarm keeps working in what it holds until it is stopped after the release; it gets no+ // new work and no new agent starts there, which their own gates refuse (admitMachineStart, work.assign, the route, the picks).+ if (pool && pool.contributorId !== contributorId) return { code: 'NOT_YOUR_COMPUTER', reason: NOT_YOUR_COMPUTER }+ const person = state.people.find(p => p.id === contributorId)+ // Reading is not working: a viewer's agent takes no work (security review 1 of #3446).+ if (person?.role === 'viewer') return { code: 'READ_ONLY', reason: 'This agent\'s person is a viewer here, so their agents take no work.' }+ if (ownsProject(state, contributorId, project) || (person && canReadProject(state, { kind: 'person', userId: person.id, email: person.email }, project))) return null+ return { code: 'NOT_YOUR_COMPUTER', reason: `${pool?.name ?? 'This machine'}'s person cannot read this project, so its agents take none of its work.` }+}++/** Why a Team account's entry takes no new agent and no new work (task #4120). */+export const TEAM_ACCOUNTS_GONE: TeamWorkRefusal = { code: 'TEAM_ACCOUNTS_REMOVED',+ reason: 'Harness Team accounts are gone: an agent runs on its own person\'s computer, in their own account.' }+/** Why a new agent does not start on another person's computer (task #4120): it would run as that computer's person. */+export const NOT_YOUR_COMPUTER = 'A new agent starts only on its own person\'s computer, in their own account, never on another person\'s.'/*** Why [machineId] takes no work of [project]: its owner kept it for other projects (commands.ts machine.projects, Tony@@ -533,47 +533,6 @@ export const ownAccountWork = (pool: Pick<ContributedMachine, 'ownAccountChoice'export const ownAccountNote = (pool: Pick<ContributedMachine, 'name'>, ownerName: string | undefined): string =>`${pool.name} runs teammates' work in ${ownerName ?? 'its owner'}'s own account.`-/** What a start moved to [pool]'s Team account says, so it is never moved silently (task #2806). The owner's choice is kept- * on each Swarm's own entry for the Mac, so it says which Swarm's to change (task #2993: Gray turned it on in another- * Swarm). Team-written code moves whatever the owner chose, so that note names the code, not a setting that would not help. */-export const movedToTeamAccount = (pool: Pick<ContributedMachine, 'name'>, teamWritten = false): string => teamWritten- ? `A Harness Team agent wrote this task's code, so it runs in the Harness Team account on ${pool.name}.`- : `${pool.name} runs teammates' work in its Harness Team account in this Swarm. Its owner can change that in this Swarm's Manage > Machines.`--/** Where a new agent for [project] runs when a start names [machineId]: the Mac's team account when the project is not- * its contributor's own and the Mac has one in this Swarm, else the machine named. Not when its owner lets teammates'- * work run in their own account there (ownAccountWork), unless a Team agent wrote the code. */-export function teamMachineFor(state: SuperTabState, machineId: string, project: SwarmProject, idle = false, live?: readonly string[], teamWritten = false,- /** What the task needs to reach: a teammate's task needing only own-account entries its owner shared stays on the Mac. */- access: 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- const pool = state.machines?.find(m => m.machineId === machineId)- // [teamWritten]: code a Team agent wrote takes the Team account even in its owner's own project (teamWritten.ts, audit H2).- if (!pool || (!teamWritten && ownsProject(state, pool.contributorId, project))) return machineId- if (!teamWritten && (ownAccountWork(pool) || sharedOwnAccess(pool, access))) return machineId- return teamPoolOf(state, pool, live)?.machineId ?? machineId-}--/** The Mac's own entry when [machineId] is its Harness Team account's and its owner lets teammates' work run in their own- * account there (ownAccountWork), for a teammate's [project] whose code no Team agent wrote; else undefined. Such a start- * belongs on the Mac, not the Team account it named (task #3060: a lamp start named Gray's Team entry, both entries named- * 'Gray.local', and was placed there as named). */-export function ownAccountTeamEntry(state: SuperTabState, machineId: string, project: SwarmProject, teamWritten: boolean): ContributedMachine | undefined {- if (teamWritten) return undefined- const team = state.machines?.find(m => m.machineId === machineId)- if (!team?.hostMachineId || team.contributorId === project.ownerId) return undefined- const mac = state.machines?.find(m => m.machineId === team.hostMachineId && m.contributorId === team.contributorId && !m.removal)- return ownAccountWork(mac) ? mac : undefined-}--/** Refuses a start that names a Team account's entry its owner's choice keeps teammates' work off (ownAccountTeamEntry), with- * the Mac's own entry to start on. Refused, not moved: a move would put the work in a person's own account, with their files- * and sign-ins, when the start named the isolated one; the starter picks the Mac knowingly, as its route row says. */-export function failOwnAccountTeamEntry(mac: ContributedMachine): never {- fail('OWN_ACCOUNT_WORK', `${mac.name}'s owner runs teammates' work in their own account in this Swarm, so its Harness Team account takes only work a Harness Team agent wrote. Start on ${mac.name} itself (machine ${mac.machineId}).`, 409)-}-/** The folder a start for [project] uses on [pool]: what admitMachineStart accepts there. */export function projectFolder(pool: ContributedMachine, project: SwarmProject): string {return pool.scope === 'swarm'@@ -618,19 +577,6 @@ export function buddyProjectsOn(state: SuperTabState, pool: ContributedMachine,return readable.filter(p => counts.get(p.cwd) === 1).slice(0, MAX_BUDDY_PROJECTS)}-/**- * A start on a Mac for another person's project, moved to the Mac's Harness Team account: its machine, and its folder in- * place of the Mac's own for that project. Every other start is returned as it is, so the Mac's owner's own projects- * stay with the owner's daemon, and a Mac without a team account here refuses it as before (teamWorkCheck).- */-export function teamStartRequest(state: SuperTabState, request: AgentStartRequest, project: SwarmProject, idle = false,- live?: readonly string[], teamWritten = false, access: readonly string[] = []): AgentStartRequest {- const machineId = teamMachineFor(state, request.machineId, project, idle, live, teamWritten, access)- if (machineId === request.machineId) return request- const pool = state.machines!.find(m => m.machineId === request.machineId)!, team = state.machines!.find(m => m.machineId === machineId)!- return { ...request, machineId, cwd: request.cwd === projectFolder(pool, project) ? projectFolder(team, project) : request.cwd }-}-/** Refuses with the refusal's code and sentence: 403, or 409 like any start on an offline machine. */export function failTeamWork(refusal: TeamWorkRefusal, after = ''): never {fail(refusal.code, `${refusal.reason}${after}`, refusal.code === 'MACHINE_OFFLINE' ? 409 : 403)@@ -875,6 +821,8 @@ export function admitMachineStart(state: SuperTabState, request: AgentStartRequeslots: (pool: ContributedMachine) => number = pool => machineSlots(state, pool)) {const pool = machineContribution(state, request.machineId)if (!pool) return null+ // No new agent in a Harness Team account, whoever asks (task #4120): its agents keep what they hold until they are stopped.+ if (teamAccountPool(pool)) failTeamWork(TEAM_ACCOUNTS_GONE)if (pool.buddyOnly && request.buddyOf?.personId !== pool.contributorId) fail('NOT_SWARM_MACHINE', NOT_SWARM_MACHINE, 403)// At its add and again at its launch: a Buddy-only machine is first read after its Buddy was asked for.if (request.buddyOf && refusesWindowsBuddy(pool)) fail('BUDDY_WINDOWS', BUDDY_WINDOWS_REFUSAL, 403)@@ -901,7 +849,7 @@ export function admitMachineStart(state: SuperTabState, request: AgentStartReque// What the task needs to reach, checked here for every start whatever the route sent (an older CLI drops needs.access):// a Buddy and a Product Manager need none (design section 3).const needed = !request.buddyOf && !request.leadFor && !request.regular ? taskAccess(group) : []- if (!request.buddyOf && !request.regular && !(request.leadFor && !teamAccountPool(pool))) requireTeamWork(state, pool.machineId, pool.contributorId, project!, now, teamMachines, otherWorkspaceMachines, needed)+ if (!request.buddyOf && !request.leadFor && !request.regular) requireTeamWork(state, pool.machineId, pool.contributorId, project!)const missing = project ? accessRefusal(state, pool.machineId, project, needed) : nullif (missing) failTeamWork(missing)const cwd = project ? projectFolder(pool, project) : buddyHomeFolder(pool, { id: request.buddyOf?.personId ?? pool.contributorId })diff --git a/backend/src/superTabs/ownAccountWork.test.ts b/backend/src/superTabs/ownAccountWork.test.tsindex b627ffbb1..a77cbab3c 100644--- a/backend/src/superTabs/ownAccountWork.test.ts+++ b/backend/src/superTabs/ownAccountWork.test.ts@@ -3,10 +3,10 @@ import { applyCommand, commandSchema, type Command, type CommandContext } from 'import { machineTeamWork, teamWorkRefusal, type ContributedMachine, type MachinePrivacy } from './machines.js'import { createSuperTab, SuperTabError, visibleState, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'-// Task #2806 (Scholes, 11-04): a Mac added as its person joined runs teammates' work only in its Harness Team account-// (teamAccountOnly). The lampOS mobile team needs it in the owner's own account on Gray's Mac (Flutter and the phone signing-// are there). The machine's owner, and nobody else, may say that teammates' work may run in their own account; the default-// stays Team-account-only. Everything here runs with Team accounts required everywhere, the strictest setting.+// Task #2806 (Scholes, 11-04): the machine's owner, and nobody else, records whether teammates' work may run in their own+// account. Swarm v3 has no Team accounts (task #4120): a person's own agent works any project they read in their own account,+// and no start moves to a Team account, so the choice no longer moves a start. What stays here is the choice itself, who may+// set it and how routing reads it. Everything runs with Team accounts required everywhere, the strictest setting.beforeEach(() => { process.env.SWARM_TEAM_ACCOUNT_REQUIRED = '1' })afterEach(() => { delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED })@@ -75,21 +75,18 @@ function swarm() {}describe('teammates\' work in a Mac owner\'s own account', () => {- it('is off by default: a teammate\'s start on a Mac added as its person joined goes to its Team account', () => {+ it('is off by default, and a teammate\'s own start on their own Mac stays there, never moved to its Team account (task #4120)', () => {const f = swarm()expect(f.machine('gray-mac').ownAccountChoice).toBeUndefined()- f.start(f.group())- expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'gray-team', cwd: '/team-swarm/lead' })+ f.start(f.group(), gray)+ expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'gray-mac', cwd: '/swarm/lead' })})- it('is turned on by the machine\'s owner, recording who and when, and then a teammate\'s start runs on the Mac itself', () => {+ it('is turned on by the machine\'s owner, recording who and when', () => {const f = swarm()f.choose(true)expect(f.machine('gray-mac').ownAccountChoice).toEqual({ allowed: true, by: 'gray', at: new Date(NOW).toISOString() })- // The Team account rule stays: only the move to the Team account is off.expect(f.machine('gray-mac').teamAccountOnly).toBe(true)- f.start(f.group())- expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'gray-mac', cwd: '/swarm/lead' })// Routing reads it as a machine that takes a teammate's work.expect(teamWorkRefusal(f.machine('gray-mac'), NOW)).toBeNull()expect(machineTeamWork(f.state, f.machine('gray-mac'), NOW, ['gray-team'])).toBeNull()@@ -129,13 +126,6 @@ describe('teammates\' work in a Mac owner\'s own account', () => {askedIn: { conversationId: 'lead', messageId: 'm-gray' } })})- it('counts only a choice recorded as the machine owner\'s', () => {- const f = swarm()- f.machine('gray-mac').ownAccountChoice = { allowed: true, by: 'mate', at: new Date(NOW).toISOString() }- f.start(f.group())- expect(f.state.starts![0]!.request.machineId).toBe('gray-team')- })-it('reads the Mac itself, not its Team account, for routing once it is on', () => {const f = swarm()// A stale privacy check on the Team account refuses teammates there; with the owner's choice on, starts run on the Mac.@@ -192,17 +182,12 @@ describe('teammates\' work in a Mac owner\'s own account', () => {expect(f.machine('gray-mac').ownAccountChoice).toBeUndefined()})- it('turned back off, moves the next start to the Team account again and says why; agents already running stay', () => {+ it('turned back off, is recorded as off, and agents already running stay', () => {const f = swarm()f.choose(true)- f.start(f.group())const running = f.agent('running', { projectId: 'lead' })f.choose(false)expect(f.machine('gray-mac').ownAccountChoice).toEqual({ allowed: false, by: 'gray', at: new Date(NOW).toISOString() })- const moved = f.start(f.group())- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })- // The choice is per Swarm: the note says where this Swarm's is (task #2993: Gray turned it on in another Swarm).- expect(moved.result.moved).toBe('Gray\'s Mac runs teammates\' work in its Harness Team account in this Swarm. Its owner can change that in this Swarm\'s Manage > Machines.')expect(f.state.agents.find(a => a.id === (running as { agentId: string }).agentId)!.machineId).toBe('gray-mac')})@@ -213,98 +198,21 @@ describe('teammates\' work in a Mac owner\'s own account', () => {expect(own.result.moved).toBeUndefined()})- it('still sends code a Team agent wrote to the Team account', () => {- const f = swarm()- f.choose(true)- const group = f.group()- const conversation = f.state.conversations.find(c => c.id === group)!- Object.assign(conversation, { teamWritten: true })- const result = refusal(() => f.start(group))- // Moved or refused, never run as Gray.- expect(result === null ? f.state.starts!.at(-1)!.request.machineId : result.code).not.toBe('gray-mac')- })-- it('says a Team-written start moved for its code, not for a choice its owner can change (task #2993)', () => {+ it('never runs code a Team agent wrote on a teammate\'s Mac, whatever its owner chose: only the project owner\'s own agent (task #4120)', () => {const f = swarm()f.choose(true)const group = f.group()Object.assign(f.state.conversations.find(c => c.id === group)!, { teamWritten: true })- const moved = f.start(group)- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })- expect(moved.result.moved).toBe('A Harness Team agent wrote this task\'s code, so it runs in the Harness Team account on Gray\'s Mac.')+ expect(refusal(() => f.start(group, gray))?.code).toBe('TEAM_WRITTEN_WORK')})it('is kept per Swarm: turning it on in one Swarm leaves another Swarm\'s entry for the same Mac as it was (task #2993)', () => {const ours = swarm(), theirs = swarm()ours.choose(true)expect(theirs.machine('gray-mac').ownAccountChoice).toBeUndefined()- const moved = theirs.start(theirs.group())- expect(theirs.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })- expect(moved.result.moved).toContain('in this Swarm\'s Manage > Machines')- })-})--// Task #3060 (Scholes, 11-05): on 11-04 a lamp start named Gray's Team account entry itself, not the Mac, after Gray had-// turned own-account work on. Both entries were named 'Gray.local', and the server placed it as named, with no note. A-// start that names the Team entry for a teammate's work no Team agent wrote is refused, with a pointer to the Mac's own-// entry: moving it would put the work in a person's own account when the start named the isolated one.-describe('a start that names a Mac\'s Team account entry while its owner runs teammates\' work in their own account', () => {- const startOnTeam = (f: ReturnType<typeof swarm>, group: string, actor: Actor = f.leadActor, projectId = 'lead') =>- f.run({ type: 'agent.start', request: { ...f.request(group, 'gray-team', projectId), cwd: `/team-swarm/${projectId}` } }, actor, f.joined)-- it('is refused for a teammate\'s task, pointing at the Mac\'s own entry, and nothing starts', () => {- const f = swarm()- f.choose(true)- const result = refusal(() => startOnTeam(f, f.group()))- expect(result?.code).toBe('OWN_ACCOUNT_WORK')- expect(result?.message).toContain('Gray\'s Mac')- expect(result?.message).toContain('gray-mac')- expect(f.state.starts ?? []).toHaveLength(0)- })-- it('is refused for a person\'s start too', () => {- const f = swarm()- f.choose(true)- expect(refusal(() => startOnTeam(f, f.group(), owner))?.code).toBe('OWN_ACCOUNT_WORK')- })-- it('still starts work a Team agent wrote in the Team account', () => {- const f = swarm()- f.choose(true)- const group = f.group()- Object.assign(f.state.conversations.find(c => c.id === group)!, { teamWritten: true })- startOnTeam(f, group)- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team', cwd: '/team-swarm/lead' })- })-- // Security review 2 of #3081: a branch GitHub cannot place runs only in a Team account (commands.ts failPushUnknown), so it- // is not sent to the Mac, which would refuse it in turn.- it('still starts work whose push GitHub cannot place in the Team account, as Team-written work', () => {- const f = swarm()- f.choose(true)- f.run({ type: 'agent.start', request: { ...f.request(f.group(), 'gray-team'), cwd: '/team-swarm/lead' } }, f.leadActor, { ...f.joined, pushOrigin: 'unknown' })- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team', cwd: '/team-swarm/lead' })- })-- it('starts there as before when its owner has not turned own-account work on, or turned it off', () => {- const f = swarm()- startOnTeam(f, f.group())- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })- f.choose(true)- f.choose(false)- startOnTeam(f, f.group())- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })- })-- it('leaves a choice recorded by someone other than the owner unread, as ownAccountWork does', () => {- const f = swarm()- f.machine('gray-mac').ownAccountChoice = { allowed: true, by: 'mate', at: new Date(NOW).toISOString() }- startOnTeam(f, f.group())- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'gray-team' })})})-// Task #3060: both of Gray's entries were named 'Gray.local', so whoever picked one could not tell the Team account from the Mac.describe('a Mac\'s Team account entry, as every read shows it', () => {it('goes by its Mac\'s name and "· Team account", while the Mac keeps its own name', () => {const f = swarm()diff --git a/backend/src/superTabs/parts/touches.test.ts b/backend/src/superTabs/parts/touches.test.tsindex 0492e99ca..3d1396192 100644--- a/backend/src/superTabs/parts/touches.test.ts+++ b/backend/src/superTabs/parts/touches.test.ts@@ -128,7 +128,7 @@ describe('the parts a command touches (design section 1.2, column T)', () => {const f = swarm()const request = { conversationId: f.group('A').id, machineId: 'host', engine: 'codex', name: 'New', cwd: '/w', worktree: false,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const { touches } = f.run({ type: 'agent.start', request }, owner, { contribution: { machineOwnerId: 'host-owner', contributorId: 'owner' } })+ const { touches } = f.run({ type: 'agent.start', request }, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } })expect(has(touches, 'machine', 'host')).toBe(true)expect(has(touches, 'head', 'head')).toBe(true)})diff --git a/backend/src/superTabs/projectOwners.test.ts b/backend/src/superTabs/projectOwners.test.tsindex 89f34cbf8..054ed3c19 100644--- a/backend/src/superTabs/projectOwners.test.ts+++ b/backend/src/superTabs/projectOwners.test.ts@@ -159,12 +159,13 @@ describe('a project whose owner leaves or is removed', () => {describe('a private project left with no member', () => {const configuration = { engine: 'codex', model: null, effort: null, contextWindow: null, engineVersion: null }- /** P's private X, with a task worked by an agent on D's machine, and P removed by the Swarm's owner. */+ /** P's private X, with a task worked by P's own agent on P's machine (Swarm v3: an agent works only on projects its person+ * reads, task #4120), and P removed by the Swarm's owner. */function ownerless() {const f = setup(), x = f.create(p)const task = f.run({ type: 'conversation.create', projectId: x.projectId, title: 'Secret task', brief: 'Secret', checks: [] }, p).conversationId as string- const agentId = f.run({ type: 'agent.add', conversationId: task, harnessId: 'h', machineId: 'd-mac', name: 'Worker', configuration, lead: false }, p,- { contribution: { machineOwnerId: 'd', contributorId: 'd' } }).agentId as string+ const agentId = f.run({ type: 'agent.add', conversationId: task, harnessId: 'h', machineId: 'p-mac', name: 'Worker', configuration, lead: false }, p,+ { contribution: { machineOwnerId: 'p', contributorId: 'p' } }).agentId as stringf.run({ type: 'work.assign', conversationId: task, agentId }, p)f.run({ type: 'member.remove', userId: 'p' })return { f, x, task, agentId }@@ -187,7 +188,10 @@ describe('a private project left with no member', () => {const { f, x } = ownerless()expect(visibleState(f.state, owner).ownerlessProjects).toEqual([{ id: x.projectId, name: 'X', conversations: 2 }])expect(visibleState(f.state, c).ownerlessProjects).toBeUndefined()- const agent: Actor = { kind: 'agent', agentId: f.state.agents[0]!.id, machineOwnerId: 'd' }+ // Another member's agent, in the Swarm's own project: it sees nothing of X either.+ const other = f.run({ type: 'agent.add', conversationId: 'lead', harnessId: 'other', machineId: 'd-mac', name: 'Other', configuration, lead: false }, owner,+ { contribution: { machineOwnerId: 'd', contributorId: 'd' } }).agentId as string+ const agent: Actor = { kind: 'agent', agentId: other, machineOwnerId: 'd' }expect(visibleState(f.state, agent).ownerlessProjects).toBeUndefined()})@@ -271,8 +275,8 @@ describe('every way in and out of the Swarm', () => {it('places work on a machine as its owner\'s own only for its owner now, not the same account at a later membership', () => {const f = setup(), x = f.create(p)f.state.machines = [{ machineId: 'p-mac', contributorId: 'p', buddyOnly: true } as unknown as ContributedMachine]- expect(teamWorkCheck(f.state, 'p-mac', 'p', projectOf(f.state, x.projectId), 1000)).toBeNull()+ expect(teamWorkCheck(f.state, 'p-mac', 'p', projectOf(f.state, x.projectId))).toBeNull()f.state.people.find(person => person.id === 'p')!.generation = 'p-second'- expect(teamWorkCheck(f.state, 'p-mac', 'p', projectOf(f.state, x.projectId), 1000)).toMatchObject({ code: 'NOT_SWARM_MACHINE' })+ expect(teamWorkCheck(f.state, 'p-mac', 'p', projectOf(f.state, x.projectId))).toMatchObject({ code: 'NOT_SWARM_MACHINE' })})})diff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.tsindex 35e646325..1138c147b 100644--- a/backend/src/superTabs/projects.test.ts+++ b/backend/src/superTabs/projects.test.ts@@ -7,6 +7,8 @@ import { mayDrive } from './terminal.js'const owner: Actor = { kind: 'person', userId: 'owner', email: '[email protected]' }const peer: Actor = { kind: 'person', userId: 'peer', email: '[email protected]' }+/** A start on its person's own computer: a start runs as the machine's own person, through no share (task #4120). */+const ownComputer = (actor: { userId: string }) => ({ contribution: { machineOwnerId: actor.userId, contributorId: actor.userId } })const configuration = { engine: 'codex', model: null, effort: null, contextWindow: null, engineVersion: null }function setup() {let state = createSuperTab('swarm', 'Team', { id: 'owner', email: '[email protected]' }, 'test')@@ -198,7 +200,7 @@ describe('projects inside an invite-only swarm', () => {const request = { conversationId: f.task(p.projectId), machineId: 'machine', engine: 'codex', name: 'Builder',cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const startId = String(f.run({ type: 'agent.start', request }).startId)+ const startId = String(f.run({ type: 'agent.start', request }, owner, ownComputer(owner)).startId)let start = f.state.starts!.find(s => s.id === startId)!start.dispatched = phase !== 'queued'if (phase === 'settling') {@@ -220,7 +222,7 @@ describe('projects inside an invite-only swarm', () => {const conversationId = f.task(p.projectId)const request = { conversationId, machineId: 'machine', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- f.run({ type: 'agent.start', request })+ f.run({ type: 'agent.start', request }, owner, ownComputer(owner))f.state.conversations.find(c => c.id === conversationId)!.archived = truef.run({ type: 'project.delete', projectId: p.projectId })expect(projectsOf(f.state).map(p => p.id)).toEqual(['lead'])@@ -232,7 +234,7 @@ describe('projects inside an invite-only swarm', () => {const conversationId = f.task(p.projectId)const request = { conversationId, machineId: 'machine', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const startId = String(f.run({ type: 'agent.start', request }).startId)+ const startId = String(f.run({ type: 'agent.start', request }, owner, ownComputer(owner)).startId)Object.assign(f.state.starts!.find(s => s.id === startId)!, { dispatched: true, poolGeneration: 'pool', harnessId: 'native', poolSettled: false })const agentId = f.add(conversationId, 'native', false)f.run({ type: 'agent.remove', agentId })@@ -246,8 +248,8 @@ describe('projects inside an invite-only swarm', () => {const conversationId = f.task(p.projectId)const request = { conversationId, machineId: 'machine', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const queued = String(f.run({ type: 'agent.start', request }).startId)- const settling = String(f.run({ type: 'agent.start', request: { ...request, name: 'Checker' } }).startId)+ const queued = String(f.run({ type: 'agent.start', request }, owner, ownComputer(owner)).startId)+ const settling = String(f.run({ type: 'agent.start', request: { ...request, name: 'Checker' } }, owner, ownComputer(owner)).startId)Object.assign(f.state.starts!.find(s => s.id === settling)!, { dispatched: true, dispatchedAt: 1000, poolGeneration: 'pool', harnessId: 'native', poolSettled: false })f.add(conversationId, 'native', false)expect(() => f.run({ type: 'project.delete', projectId: p.projectId })).toThrow('pending agent starts before deleting it: Builder in “Work”, Checker in “Work”.')@@ -261,7 +263,7 @@ describe('projects inside an invite-only swarm', () => {const conversationId = f.task(p.projectId)const request = { conversationId, machineId: 'machine', engine: 'codex', name: 'Builder', cwd: '/work', worktree: true,requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } }- const startId = String(f.run({ type: 'agent.start', request }).startId)+ const startId = String(f.run({ type: 'agent.start', request }, owner, ownComputer(owner)).startId)f.state.starts!.find(s => s.id === startId)!.dispatched = truef.state.conversations.find(c => c.id === conversationId)!.archived = trueexpect(() => f.run({ type: 'project.delete', projectId: p.projectId })).toThrow('pending agent starts')@@ -398,7 +400,7 @@ describe('custom role sets', () => {const work = f.task(p.projectId, peer)expect(roles()!.find(r => r.id === 'abcdefabcdef')).toMatchObject({ defaults: { engine: 'codex', model: 'gpt-6.1-sol', effort: 'medium' } })const startWith = (extra: Record<string, unknown>) => {- const startId = String(f.run({ type: 'agent.start', request: request(work, extra) } as Command, peer).startId)+ const startId = String(f.run({ type: 'agent.start', request: request(work, extra) } as Command, peer, ownComputer(peer)).startId)return f.state.starts!.find(s => s.id === startId)!.request}expect(startWith({ roleId: 'abcdefabcdef' })).not.toHaveProperty('model')@@ -417,22 +419,22 @@ describe('custom role sets', () => {// An older client's role id is kept for older readers and names the agent; its kind decides nothing (project instructions, phase 4).it('starts and assigns in any role id an older client sends, keeping it and naming the agent by it', () => {const { f, p } = custom([...defaults(), role('abcdefabcdef', 'Docs writer', 'builder')])- // The project's owner starts it: a teammate's project runs only on a Team machine (machines.ts teamWorkCheck).+ // The project's owner starts it on their own computer (task #4120: a start runs as the machine's own person).const work = f.task(p.projectId, peer)- const start = (extra: Record<string, unknown>) => String(f.run({ type: 'agent.start', request: request(work, extra) } as Command, peer).startId)+ const start = (extra: Record<string, unknown>) => String(f.run({ type: 'agent.start', request: request(work, extra) } as Command, peer, ownComputer(peer)).startId)for (const extra of [{ roleId: 'review' }, { roleId: 'lead' }, { roleId: 'eeeeeeeeeeee' }, { role: 'reviewer', roleId: 'dev' }]) {const id = start(extra)expect(f.state.starts!.find(s => s.id === id)!.request).toMatchObject(extra)}const startId = start({ roleId: 'abcdefabcdef' })- const worker = String(f.run({ type: 'agent.started', startId, harnessId: 'native', configuration }, peer).agentId)+ const worker = String(f.run({ type: 'agent.started', startId, harnessId: 'native', configuration }, peer, ownComputer(peer)).agentId)expect(f.state.agents.find(a => a.id === worker)).toMatchObject({ roleId: 'abcdefabcdef', roleName: 'Docs writer' })const group = String(f.run({ type: 'conversation.create', projectId: p.projectId, title: 'Work', brief: 'Do it', checks: [{ description: 'Done', independent: false }] }, peer).conversationId)f.run({ type: 'work.assign', conversationId: group, agentId: worker, roleId: 'review' }, peer)// Its role name stays the one it started in.expect(f.state.agents.find(a => a.id === worker)).toMatchObject({ roleId: 'review', roleName: 'Docs writer' })const plain = f.project('public', peer)- expect(f.run({ type: 'agent.start', request: request(f.task(plain.projectId), { roleId: 'dev' }) } as Command).startId).toEqual(expect.any(String))+ expect(f.run({ type: 'agent.start', request: request(f.task(plain.projectId), { roleId: 'dev' }) } as Command, owner, ownComputer(owner)).startId).toEqual(expect.any(String))})it('joins an agent with the role the New Harness form sends, kept with a reviewer role\'s kind for older readers and naming it', () => {@@ -474,7 +476,7 @@ describe('custom role sets', () => {Object.assign(projectOf(f.state, p.projectId), { skillSet: 'custom' })// A role set decides nothing (project instructions, phase 4): a review group, a Reviewer's start and its assignment are accepted.const review = String(f.run({ type: 'conversation.create', projectId: p.projectId, title: 'Review', brief: 'Check it', reviewOf: build, checks: [{ description: 'Read', independent: true }] }, peer).conversationId)- expect(f.run({ type: 'agent.start', request: request(build, { role: 'reviewer' }) } as Command).startId).toEqual(expect.any(String))+ expect(f.run({ type: 'agent.start', request: request(build, { role: 'reviewer' }) } as Command, owner, ownComputer(owner)).startId).toEqual(expect.any(String))f.run({ type: 'work.assign', conversationId: review, agentId: reviewer }, peer)expect(f.state.conversations.find(c => c.id === review)!.assignment).toMatchObject({ agentId: reviewer })})diff --git a/backend/src/superTabs/read/views.test.ts b/backend/src/superTabs/read/views.test.tsindex e9084def4..fba19e813 100644--- a/backend/src/superTabs/read/views.test.ts+++ b/backend/src/superTabs/read/views.test.ts@@ -144,9 +144,10 @@ describe('reader view of the parts (design 4.1, 4.3)', () => {const view = readerView(parts, peer, NOW, { teamMachines: [] })expect(view.parts.machines.map(m => m.key)).toEqual(['mac'])expect(view.parts.machines[0]!.data.observation!.runningHarnessIds).toEqual(['lead-harness'])- // A teammate's machine says where New Project's Product Manager would run there, by engine (leadStart.ts leadChoices).- expect(view.derived.machines).toEqual({ mac: { availableSlots: 1, teamWork: { allowed: true }, lead: {- claude: { refused: 'Claude Code isn’t offered on mac.' }, codex: { refused: 'Update Harness on mac to run a Product Manager there.' } } } })+ // A teammate's machine says where New Project's Product Manager would run there, by engine (leadStart.ts leadChoices): nowhere,+ // as Swarm v3 starts no PM on another person's computer (task #4120).+ const refused = { refused: 'A new agent starts only on its own person\'s computer, in their own account, never on another person\'s.' }+ expect(view.derived.machines).toEqual({ mac: { availableSlots: 1, teamWork: { allowed: true }, lead: { claude: refused, codex: refused } } })})it('tells only a person where New Project\'s Product Manager would run, and only on a teammate\'s machine', () => {diff --git a/backend/src/superTabs/repositoryReach.test.ts b/backend/src/superTabs/repositoryReach.test.tsindex 418cb68c8..26adbc18f 100644--- a/backend/src/superTabs/repositoryReach.test.ts+++ b/backend/src/superTabs/repositoryReach.test.ts@@ -3,7 +3,6 @@ import { applyCommand, type Command, type CommandContext } from './commands.js'import type { ContributedMachine } from './machines.js'import { createSuperTab, SuperTabError, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'import { REPOSITORY_UNREACHABLE, repositoryReachOf, type RepositoryReach } from './repositoryReach.js'-import { TEAM_WRITTEN_WORK } from './teamWritten.js'// 11-05, Huy's groupme (task #3266): the Harness GitHub App was not on ngochuy13/groupme, so a Reviewer in the Mac's Team// account, which reaches GitHub only through the app, failed to start twice and Claude was suspended there. Such a start@@ -50,60 +49,27 @@ const refused = (body: () => unknown): SuperTabError | null => {}describe('a start whose account cannot reach the project repository', () => {- it('is refused at once in a Team account where the app is not installed, naming the repository and the install, and nothing is queued', () => {- const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })- const error = refused(() => f.start(review, 'mac-team', { repositoryReach: notInstalled }))- expect(error?.code).toBe(REPOSITORY_UNREACHABLE)- expect(error?.status).toBe(409)- expect(error?.message).toBe('An agent in this account reaches ngochuy13/groupme only through the Harness GitHub App, which is not installed on it. '- + `An owner of ngochuy13 installs it (${INSTALL}), then start or assign it again.`)- expect(f.state.starts ?? []).toEqual([])- })-- it('says to approve it when the app is installed but nobody approved the repository for this project', () => {- const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })- const error = refused(() => f.start(review, 'mac-team', { repositoryReach: notApproved }))- expect(error?.code).toBe(REPOSITORY_UNREACHABLE)- expect(error?.message).toBe('An agent in this account reaches ngochuy13/groupme only through the Harness GitHub App, and nobody who can push to it '- + 'has approved it for this project. Someone who can push to it approves it in Harness (Project details, GitHub access), then start or assign it again.')- })-- it('is refused where a start on the Mac moves into its Team account', () => {- const f = swarm(), task = f.group()- f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') })- const review = f.group({ reviewOf: task, step: 'Review' })- expect(refused(() => f.start(review, 'mac', { repositoryReach: notInstalled }))?.code).toBe(REPOSITORY_UNREACHABLE)- })-- it('starts as before when the app covers it, when the read could not say, or with no read', () => {- for (const repositoryReach of [{ state: 'covered', repository: 'ngochuy13/groupme' }, { state: 'unknown', repository: 'ngochuy13/groupme' }, undefined] as const) {- const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })- f.start(review, 'mac-team', repositoryReach ? { repositoryReach } : {})- expect(f.state.starts!.at(-1)!.request.machineId).toBe('mac-team')- }- })-it('starts the owner\'s own work in their own account, which uses their own GitHub login', () => {const f = swarm()f.start(f.group(), 'mac', { repositoryReach: notInstalled, pushOrigin: 'clean' })expect(f.state.starts!.at(-1)!.request.machineId).toBe('mac')})- it('names the install when it holds an own-account start for want of knowing who pushed', () => {+ // Swarm v3 has no Team account to hold it (task #4120, the PM's ruling): code nobody can place runs on the project owner's own+ // computer, which reaches the repository with the owner's own GitHub login.+ it('starts work whose pusher GitHub cannot show on the project owner\'s own computer', () => {const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })- const error = refused(() => f.start(review, 'mac', { repositoryReach: notInstalled, pushOrigin: 'unknown' }))- expect(error?.code).toBe(TEAM_WRITTEN_WORK)- expect(error?.message).toBe('GitHub cannot show who pushed this task\'s code because the Harness GitHub App is not installed on ngochuy13/groupme, '- + 'so it may run only in a Team account, and a Team account reaches the repository only through that app. '- + `An owner of ngochuy13 installs it (${INSTALL}); then it runs in your own account.`)+ f.start(review, 'mac', { repositoryReach: notInstalled, pushOrigin: 'unknown' })+ expect(f.state.starts!.at(-1)!.request.machineId).toBe('mac')})})describe('an assignment whose agent cannot reach the project repository', () => {+ // A Team account's agent takes no new work at all in Swarm v3 (task #4120).it('is refused for a Team agent, and taken by the owner\'s agent in their own account', () => {const f = swarm(), task = f.group()- expect(refused(() => f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') }, { repositoryReach: notInstalled }))?.code)- .toBe(REPOSITORY_UNREACHABLE)+ expect(refused(() => f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') }))?.code)+ .toBe('TEAM_ACCOUNTS_REMOVED')expect(f.state.conversations.find(c => c.id === task)!.assignment).toBeNull()f.run({ type: 'work.assign', conversationId: task, agentId: f.member('own-builder', 'mac') }, { repositoryReach: notInstalled })expect(f.state.conversations.find(c => c.id === task)!.assignment?.agentId).toBe('own-builder')diff --git a/backend/src/superTabs/repositoryReach.ts b/backend/src/superTabs/repositoryReach.tsindex c53234c3d..b3652d49e 100644--- a/backend/src/superTabs/repositoryReach.ts+++ b/backend/src/superTabs/repositoryReach.ts@@ -30,11 +30,11 @@ export function requireRepositoryReach(state: SuperTabState, team: boolean, mach+ '(Project details, GitHub access), then start or assign it again.', 409)}-/** Why GitHub cannot show who pushed, when it is that the app is not installed: a Team account cannot reach it either. */+/** Why GitHub cannot show who pushed, when it is that the app is not installed (task #4120: only the owner's own agent runs it then). */export function unknownPushReason(reach: RepositoryReach | undefined): string | null {return reach?.state === 'not-installed'- ? `GitHub cannot show who pushed this task's code because the Harness GitHub App is not installed on ${reach.repository}, so it may run only in a `- + `Team account, and a Team account reaches the repository only through that app. ${install(reach)}; then it runs in your own account.`+ ? `GitHub cannot show who pushed this task's code because the Harness GitHub App is not installed on ${reach.repository}, so only the project `+ + `owner's own agent may run it. ${install(reach)}; then it runs in your own account.`: null}diff --git a/backend/src/superTabs/reviewerPick.ts b/backend/src/superTabs/reviewerPick.tsindex c4bd3e065..e8559ad55 100644--- a/backend/src/superTabs/reviewerPick.ts+++ b/backend/src/superTabs/reviewerPick.ts@@ -9,7 +9,7 @@ import { isBuddy } from './buddies.js'import { MODEL_CATALOG, namedDefault } from './catalog.js'import { roleNameOf } from './instructions.js'import { activeWork, workerIndex, type Agent, type CheckVerdict, type Conversation, type SuperTabState } from './model.js'-import { agentProjectId, groupProject } from './projects.js'+import { agentProjectId, groupProject, onTeamAccount } from './projects.js'import { agentTarget, modelMatches } from './rules.js'import { canStart, standing } from './reviewSeats.js'import { stepsOf } from './steps.js'@@ -82,7 +82,8 @@ export function reviewerCandidates(state: SuperTabState, task: Conversation, kin.filter(verdict => atHead(verdict, head)).map(verdict => verdict.by))const ranked = state.agents.flatMap(agent => {if (built.has(agent.id) || index.leaders.has(agent.id) || index.working.has(agent.id) || holding.has(agent.id)) return []- if (isBuddy(agent) || agent.workDecision === 'stop' || agentProjectId(state, agent) !== projectId) return []+ // Nor a Team account's agent, which takes no new work (task #4120).+ if (isBuddy(agent) || agent.workDecision === 'stop' || onTeamAccount(state, agent) || agentProjectId(state, agent) !== projectId) return []if (judged.has(`agent:${agent.id}`)) return []const role = roleNameOf(state, agent)if (NEVER.test(role) || NEVER_NAMED.test(agent.name) || NEVER_NAMED.test(agent.displayName ?? '')) return []diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex fe04649fd..d229ce2b6 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -2161,7 +2161,6 @@ export class SuperTabStore {context.teamMachines = facts.teamcontext.machineVersions = facts.versionscontext.otherWorkspaceMachines = await this.otherWorkspaceMachines(tx, original)- if (this.hooks.teamAccountsIdle) context.teamAccountsIdle = true}if (pushOrigin) Object.assign(context, { pushOrigin: pushOrigin.origin, pushOriginPulls: pushOrigin.pulls, ...pushOrigin.task ? { pushOriginTask: pushOrigin.task } : {} })if (repositoryReach) context.repositoryReach = repositoryReachdiff --git a/backend/src/superTabs/taskApproval.test.ts b/backend/src/superTabs/taskApproval.test.tsindex e52f4b91c..7e044c72e 100644--- a/backend/src/superTabs/taskApproval.test.ts+++ b/backend/src/superTabs/taskApproval.test.ts@@ -11,6 +11,12 @@ const words = 'Keep offline edits.'const task = { goal: words, changes: 'Persist drafts', constraints: 'No sign-in', owns: ['backend/src/superTabs/'] }function fixture(board = true) {const f = fullSwarm(NOW)+ // Its machine is its person's own computer: a Team-session machine takes no new work in Swarm v3 (task #4120).+ f.edit(state => {+ const reading = state.machines!.find(m => m.machineId === 'host')!.observation!+ reading.sessionKind = 'computer'+ delete reading.privacy+ })if (board) f.state.projects![0]!.boardMode = trueelse delete f.state.projects![0]!.boardModeconst candidate = f.add('candidate', f.web), other = f.add('other-candidate', f.web)diff --git a/backend/src/superTabs/teamAccountsRemoved.test.ts b/backend/src/superTabs/teamAccountsRemoved.test.tsnew file mode 100644index 000000000..6db48ea43--- /dev/null+++ b/backend/src/superTabs/teamAccountsRemoved.test.ts@@ -0,0 +1,157 @@+/**+ * Swarm v3 removes Team accounts (task #4120, anh Dee 2026-11-07). No new agent starts in a Mac's Harness Team account, nothing+ * routes or hands new work to one, and the agents there keep what they hold until they are stopped after the release. The PM's+ * rulings in the task: an agent a person brought works on any task of a project that person can read, in their own account,+ * and a new agent starts only on its own person's computer; a task whose code a Team agent pushed stays guarded, and only the+ * project owner's own agent may take it over.+ */+import { describe, expect, it } from 'vitest'+import { applyCommand, type Command, type CommandContext } from './commands.js'+import { DISPATCH_RULES, freeCrew } from './dispatch.js'+import type { ContributedMachine } from './machines.js'+import { createSuperTab, SuperTabError, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'+import { reviewerCandidates } from './reviewerPick.js'++const NOW = 50_000_000+const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }+const mate: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'mate', email: '[email protected]' }+const config: AgentConfiguration = { engine: 'claude', model: 'opus', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }+const requirements = { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false }+const resources = { cpuPercent: 1, memoryTotalBytes: 8e9, memoryUsedBytes: 1, diskFreeBytes: 8e9, diskTotalBytes: 8e9, projectDiskFreeBytes: 8e9,+ deviceType: null, chip: null, os: 'macOS', gpuPercent: null }+const reading = (sessionKind: 'team' | 'computer') => ({ generation: 'g1', receivedAt: NOW, sessionKind, resources, tools: {},+ quotas: [{ engine: 'claude', known: true, windows: [{ name: 'weekly', usedPercent: 10, resetsAt: null }] }], runningHarnessIds: [], stoppedHarnessIds: [],+ readiness: { engines: [{ engine: 'claude', installed: true, signedIn: true }] },+ ...(sessionKind === 'team' ? { privacy: { mode: 'account', passed: true, checkedAt: NOW, seenAt: NOW } } : {}) })+const refusal = (body: () => unknown): SuperTabError | null => {+ try { body(); return null } catch (error) { if (error instanceof SuperTabError) return error; throw error }+}++/** The owner's project 'lead' and the teammate's own Mac with its Harness Team account, and the owner's Mac. */+function swarm() {+ let state: SuperTabState = createSuperTab('tab', 'Pilot', { id: 'owner', email: owner.email }, 'prod')+ let sequence = 0+ const run = (command: Command, actor: Actor = owner, context: Partial<CommandContext> = {}) => {+ const teamMachines = (state.machines ?? []).filter(m => m.hostMachineId).map(m => m.machineId)+ const effects = applyCommand(state, actor, command, { now: NOW, operationId: `op-${++sequence}`, teamMachines, ...context })+ state = effects.state+ return effects+ }+ const invited = run({ type: 'invite.create', email: mate.email, role: 'collaborator', conversationId: 'lead' })+ run({ type: 'invite.accept', inviteId: invited.result.inviteId as string }, mate)+ const generation = (userId: string) => state.people.find(p => p.id === userId)!.generation+ const pool = (machineId: string, contributorId: string, name: string, kind: 'team' | 'computer', host?: string): ContributedMachine => ({ machineId, name,+ contributorId, membershipGeneration: generation(contributorId), generation: 'g1', cwd: '/swarm', scope: 'swarm', engines: ['claude'], maxAgents: 4,+ paused: false, observation: reading(kind) as never, ...host ? { hostMachineId: host } : {} })+ state.machines = [pool('owner-mac', 'owner', 'Owner Mac', 'computer'), pool('mate-mac', 'mate', 'MacBook Pro', 'computer'),+ pool('mate-team', 'mate', 'MacBook Pro', 'team', 'mate-mac')]+ /** An agent already in the Swarm on [machineId], under [contributorId]'s grant there. */+ const member = (id: string, machineId: string, contributorId: string, roleName = 'Engineer') => {+ state.agents.push({ id, machineId, harnessId: `harness-${id}`, projectId: 'lead', machineOwnerId: contributorId, contributorId,+ membershipGeneration: generation(contributorId), hostGrant: null, name: id, configuration: config, roleName } as never)+ return id+ }+ const pm = member('pm', 'owner-mac', 'owner', 'PM')+ const chat = state.conversations.find(c => c.id === 'lead')!+ chat.leadId = pm+ chat.agentIds = [...chat.agentIds, pm]+ const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: state.agents.find(a => a.id === agentId)!.machineOwnerId })+ const task = String(run({ type: 'conversation.create', projectId: 'lead', title: 'Work', brief: 'Build it.', priority: 'P2', requesterId: 'owner',+ checks: [{ description: 'Tests pass.', independent: false }] } as Command, as(pm)).result.conversationId)+ const machine = (machineId: string) => state.machines!.find(m => m.machineId === machineId)!+ const start = (machineId: string, actor: Actor) => run({ type: 'agent.start', request: { conversationId: task, machineId, engine: 'claude', name: 'Builder',+ cwd: '/swarm/lead', worktree: true, requirements } } as Command, actor, { contribution: { machineOwnerId: machine(machineId).contributorId,+ contributorId: machine(machineId).contributorId, hostGrant: null } as never })+ const assign = (agentId: string, conversationId = task) => run({ type: 'work.assign', conversationId, agentId } as Command, as(pm))+ return { run, member, machine, start, assign, as, pm, task, group: (id = task) => state.conversations.find(c => c.id === id)!, get state() { return state } }+}++describe('with Team accounts removed', () => {+ it('starts no agent in a Team account, and never moves a start there', () => {+ const f = swarm()+ expect(refusal(() => f.start('mate-team', mate))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ // The teammate's own agent on their own Mac, for a project they read: it stays on the Mac, in their own account.+ f.start('mate-mac', mate)+ expect(f.state.starts!.at(-1)!.request.machineId).toBe('mate-mac')+ })++ it('starts a new agent only on its own person\'s computer: never the PM on another person\'s', () => {+ const f = swarm()+ expect(refusal(() => f.start('mate-mac', f.as(f.pm)))).toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ expect(refusal(() => f.start('mate-mac', owner))).toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ expect(refusal(() => f.start('owner-mac', f.as(f.pm)))).toBeNull()+ })++ it('routes past a Team account and another person\'s computer, and keeps a teammate\'s own agent', () => {+ const f = swarm()+ const own = f.member('mates-own', 'mate-mac', 'mate'), team = f.member('mates-team', 'mate-team', 'mate')+ const candidate = (id: string, machineId: string, agentId?: string) => ({ id, kind: agentId ? 'member' : 'new', ...agentId ? { agentId } : {}, machineId,+ engine: 'claude', model: 'opus', effort: 'high', quality: 3, cost: 2, title: `${id} on ${machineId}`, label: id })+ const decision = { assessment: { difficulty: 'low', risk: 'low', why: 'Work.' }, excluded: [], floor: 2, notes: false, via: 'instructions', p: null,+ belowFloor: false, why: 'Instructions.', candidates: [candidate('c0', 'mate-team'), candidate('c1', 'mate-team', team), candidate('c2', 'mate-mac'),+ candidate('c3', 'mate-mac', own), candidate('c4', 'owner-mac')] }+ const routed = f.run({ type: 'route.record', conversationId: f.task, decision } as Command, f.as(f.pm))+ const record = (routed.routeDecisions[0] as { record: { candidates: Array<{ id: string }>; excluded: Array<{ title: string; reason: string }> } }).record+ expect(record.candidates.map(c => c.id)).toEqual(['c3', 'c4'])+ expect(record.excluded.map(e => e.title)).toEqual(['c0 on mate-team', 'c1 on mate-team', 'c2 on mate-mac'])+ expect(record.excluded[0]!.reason).toContain('Team accounts')+ })++ it('gives a Team-account agent no new work, and leaves it the task it holds', () => {+ const f = swarm()+ const team = f.member('mates-team', 'mate-team', 'mate')+ const own = f.member('mates-own', 'mate-mac', 'mate', 'Tester')+ expect(refusal(() => f.assign(team))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect(freeCrew(f.state, 'lead', DISPATCH_RULES, NOW).map(a => a.id)).not.toContain(team)+ f.state.agents.find(a => a.id === team)!.roleName = 'Tester'+ expect(reviewerCandidates(f.state, f.group(), 'test', null, NOW).map(a => a.id)).toEqual([own])+ // What it already holds stays with it.+ const held = f.group()+ held.assignment = { id: 'a1', agentId: team, status: 'working', configuration: config, execution: { machineId: 'mate-team', harnessId: 'harness-mates-team',+ machineOwnerId: 'mate' }, result: null } as never+ f.run({ type: 'work.status', conversationId: f.task, assignmentId: 'a1', status: 'working', result: 'Still on it.' } as Command, f.as(team))+ expect(f.group().assignment).toMatchObject({ agentId: team, status: 'working' })+ })++ it('lets a teammate\'s own agent take any task of a project they read, in their own account', () => {+ const f = swarm()+ const own = f.member('mates-own', 'mate-mac', 'mate')+ expect(refusal(() => f.assign(own))).toBeNull()+ })++ // Security review 1 of #3446: reading a project is not enough to work in it; a viewer's agent takes none of its work.+ it('gives no task to the agent of a person who is only a viewer', () => {+ const f = swarm()+ const own = f.member('mates-own', 'mate-mac', 'mate')+ f.state.people.find(p => p.id === 'mate')!.role = 'viewer'+ expect(refusal(() => f.assign(own))).toMatchObject({ code: 'READ_ONLY' })+ })++ // Security review 2 of #3446: off the Machines list, or through a machine share, the grant's contributor is not the machine's+ // owner; the start must be its owner's own, with no share, no Team account and no Team session, as agent.new checks.+ it('starts nothing on a computer shared through a machine share, or an unlisted Team sign-in', () => {+ const f = swarm()+ const startOn = (machineId: string, contribution: Record<string, unknown>) => () => f.run({ type: 'agent.start', request: { conversationId: f.task,+ machineId, engine: 'claude', name: 'Builder', cwd: '/swarm/lead', worktree: true, requirements } } as Command, mate, { contribution: contribution as never })+ expect(refusal(startOn('strangers-mac', { machineOwnerId: 'stranger', contributorId: 'mate', hostGrant: 'share-1' }))).toMatchObject({ code: 'NOT_YOUR_COMPUTER' })+ expect(refusal(startOn('mates-team', { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null, teamSession: true }))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ expect(refusal(startOn('mates-team', { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null, hostMachineId: 'mate-mac' }))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED' })+ })++ it('never lets the owner\'s agent on a machine shared with them take a task a Team agent wrote', () => {+ const f = swarm()+ // A machine off the Machines list that its owner, mate, shared with the project owner: the agent runs in mate's account.+ const shared = f.member('owners-shared', 'strangers-mac', 'owner')+ Object.assign(f.state.agents.find(a => a.id === shared)!, { machineOwnerId: 'mate', hostGrant: 'share-1' })+ Object.assign(f.group(), { teamWritten: true, teamWrittenBy: { kind: 'assigned' } })+ expect(refusal(() => f.assign(shared))).toMatchObject({ code: 'TEAM_WRITTEN_WORK' })+ })++ it('lets only the project owner\'s own agent take over a task a Team agent wrote', () => {+ const f = swarm()+ const mates = f.member('mates-own', 'mate-mac', 'mate'), owners = f.member('owners-own', 'owner-mac', 'owner')+ Object.assign(f.group(), { teamWritten: true, teamWrittenBy: { kind: 'assigned' } })+ expect(refusal(() => f.assign(mates))).toMatchObject({ code: 'TEAM_WRITTEN_WORK' })+ expect(refusal(() => f.assign(owners))).toBeNull()+ })+})diff --git a/backend/src/superTabs/teamRouting.test.ts b/backend/src/superTabs/teamRouting.test.tsindex 7a4ccfa5a..cd99c8373 100644--- a/backend/src/superTabs/teamRouting.test.ts+++ b/backend/src/superTabs/teamRouting.test.ts@@ -168,74 +168,64 @@ describe('which machines take a teammate\'s project', () => {})})+// Swarm v3 has no Team accounts (task #4120, the PM's ruling): an agent a person brought works on any task of a project that+// person can read, in their own account, and a new agent starts only on its own person's computer.describe('starting a teammate\'s work', () => {- it('is refused on a personal machine, with a reason a person understands', () => {+ it('runs on the teammate\'s own computer, in their own account, when they start it', () => {const f = swarm(), group = f.group()- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))))- .toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', status: 403, message: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects.' })- expect(f.state.starts ?? []).toEqual([])+ f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, mate, f.pooled('mate-mac'))+ expect(f.state.starts).toEqual([expect.objectContaining({ request: expect.objectContaining({ machineId: 'mate-mac', cwd: '/swarm/lead' }) })])})- it('is admitted on the teammate\'s Team machine whose privacy check passed', () => {+ it('is never started by another person on the teammate\'s computer', () => {const f = swarm(), group = f.group()- f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, f.pooled('mate-team'))- expect(f.state.starts).toHaveLength(1)+ expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))))+ .toMatchObject({ code: 'NOT_YOUR_COMPUTER', status: 403 })+ expect(f.state.starts ?? []).toEqual([])})- it('is refused on a Team machine whose check is stale, failing or missing, and while it is offline', () => {- for (const [observation, code] of [[reading('team', PASSED, NOW, NOW - 20 * MINUTE), 'PRIVACY_CHECK_STALE'], [reading('team', FAILED), 'PRIVACY_CHECK_FAILED'],- [reading('team'), 'PRIVACY_UNCHECKED'], [reading('team', PASSED, NOW - 60_000), 'MACHINE_OFFLINE']] as const) {+ it('never starts in a Team account, whatever its privacy check says', () => {+ for (const observation of [reading('team', PASSED), reading('team', FAILED), reading('team')]) {const f = swarm(), group = f.group()f.machine('mate-team').observation = observation- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, f.pooled('mate-team')))?.code).toBe(code)+ expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, mate, f.pooled('mate-team')))?.code).toBe('TEAM_ACCOUNTS_REMOVED')}})- it('reads the account row too: a team row with an ordinary reading has no privacy check to show', () => {- const f = swarm(), group = f.group()- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, { ...f.pooled('mate-mac'), teamMachines: ['mate-mac'] }))?.code)- .toBe('PRIVACY_UNCHECKED')- })-it('leaves a person\'s own projects on their own machines as they were', () => {const f = swarm()f.run({ type: 'agent.start', request: f.request(f.group(), 'owner-mac') }, owner, f.pooled('owner-mac'))const mine = f.group(f.mine, mate)f.run({ type: 'agent.start', request: f.request(mine, 'mate-mac', f.mine) }, mate, f.pooled('mate-mac'))expect(f.state.starts).toHaveLength(2)- // The teammate's project on the owner's Mac is the same rule the other way round.- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(mine, 'owner-mac', f.mine) }, mate, f.pooled('owner-mac')))?.code).toBe('TEAM_ACCOUNT_REQUIRED')+ // The teammate's project on the owner's Mac is another person's computer.+ expect(refusal(() => f.run({ type: 'agent.start', request: f.request(mine, 'owner-mac', f.mine) }, mate, f.pooled('owner-mac')))?.code).toBe('NOT_YOUR_COMPUTER')})- it('is re-checked when its host launches it: an admitted start whose check went stale waits', () => {+ it('is refused when its host launches it in a Team account, though it was admitted before the release', () => {const f = swarm(), group = f.group()- f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, f.pooled('mate-team'))- const start = f.state.starts![0]! as AgentStart- f.machine('mate-team').observation = reading('team', PASSED, NOW, NOW - 20 * MINUTE)- expect(refusal(() => admitMachineStart(f.state, start.request, NOW, start))?.code).toBe('PRIVACY_CHECK_STALE')+ const start = { id: 'before-release', request: f.request(group, 'mate-team'), poolGeneration: 'g1' } as unknown as AgentStart+ expect(refusal(() => admitMachineStart(f.state, start.request, NOW, start))?.code).toBe('TEAM_ACCOUNTS_REMOVED')})- it('is refused on a machine outside the Swarm\'s Machines list, which shows no privacy check', () => {+ it('runs off the Machines list on its person\'s own computer, for a project they read', () => {const f = swarm(), group = f.group()- // The teammate by hand, on their own uncontributed laptop, for the owner's project.- expect(refusal(() => f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-laptop'), cwd: '/work' } }, mate,- { contribution: { machineOwnerId: 'mate', contributorId: 'mate' } }))).toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED',- message: 'This machine is not a Team machine of this Swarm, so it runs only its owner\'s projects.' })- // Their own project there, or the owner's project on a machine shared with the owner by name, as before.+ f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-laptop'), cwd: '/work' } }, mate, { contribution: { machineOwnerId: 'mate', contributorId: 'mate' } })f.run({ type: 'agent.start', request: { ...f.request(f.group(f.mine, mate), 'mate-laptop'), cwd: '/work' } }, mate, { contribution: { machineOwnerId: 'mate', contributorId: 'mate' } })- f.run({ type: 'agent.start', request: { ...f.request(group, 'shared-mac'), cwd: '/work' } }, owner, { contribution: { machineOwnerId: 'mate', contributorId: 'owner', hostGrant: 'grant-1' } })+ // Through another person's machine share it would run in their account: refused (security review 2 of #3446).+ expect(refusal(() => f.run({ type: 'agent.start', request: { ...f.request(group, 'shared-mac'), cwd: '/work' } }, owner,+ { contribution: { machineOwnerId: 'mate', contributorId: 'owner', hostGrant: 'grant-1' } }))?.code).toBe('NOT_YOUR_COMPUTER')expect(f.state.starts).toHaveLength(2)})})describe('giving an existing agent a teammate\'s work', () => {- it('work.assign is refused for an agent on a personal machine and admitted on a Team machine', () => {+ it('work.assign is admitted for the teammate\'s own agent and refused for an agent in a Team account', () => {const f = swarm(), group = f.group()const personal = f.member('personal', 'mate-mac', 'mate'), team = f.member('team', 'mate-team', 'mate')- expect(refusal(() => f.run({ type: 'work.assign', conversationId: group, agentId: personal })))- .toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', status: 403, message: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects.' })- f.run({ type: 'work.assign', conversationId: group, agentId: team })- expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ agentId: team, status: 'working' })+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: group, agentId: team }))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED', status: 403 })+ f.run({ type: 'work.assign', conversationId: group, agentId: personal })+ expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ agentId: personal, status: 'working' })})it('work.assign of a person\'s own project to their own agent is unchanged', () => {@@ -245,13 +235,13 @@ describe('giving an existing agent a teammate\'s work', () => {expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ agentId: personal })})- it('adding a Reviewer to a group, which hands it the review, is refused on a personal machine', () => {+ it('adding a Reviewer to a group, which hands it the review, is admitted for the teammate\'s own agent and refused in a Team account', () => {const f = swarm(), group = f.group()const reviewer = f.member('reviewer', 'mate-mac', 'mate', 'lead', { role: 'reviewer' })- expect(refusal(() => f.run({ type: 'conversation.agent', conversationId: group, agentId: reviewer, present: true, lead: false }))?.code).toBe('TEAM_ACCOUNT_REQUIRED')+ f.run({ type: 'conversation.agent', conversationId: group, agentId: reviewer, present: true, lead: false })+ expect(f.state.conversations.find(c => c.id === group)!.agentIds).toContain(reviewer)const teamReviewer = f.member('team-reviewer', 'mate-team', 'mate', 'lead', { role: 'reviewer' })- f.run({ type: 'conversation.agent', conversationId: group, agentId: teamReviewer, present: true, lead: false })- expect(f.state.conversations.find(c => c.id === group)!.agentIds).toContain(teamReviewer)+ expect(refusal(() => f.run({ type: 'conversation.agent', conversationId: group, agentId: teamReviewer, present: true, lead: false }))?.code).toBe('TEAM_ACCOUNTS_REMOVED')})})@@ -271,40 +261,26 @@ describe('routing a teammate\'s work', () => {return { ...f, get state() { return f.state }, group, leadActor, personal }}- it('leaves out the machines that cannot take it, and says why', () => {+ it('leaves out a Team account and a new agent on another person\'s computer, keeps the teammate\'s own agent, and says why', () => {const f = routed()const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'mate-team'), candidate('c1', 'mate-mac'),- candidate('c2', 'mate-mac', { kind: 'member', agentId: f.personal, title: 'personal on mate-mac' }), candidate('c3', 'owner-mac')]) } as Command,+ candidate('c2', 'mate-mac', { kind: 'member', agentId: f.personal, title: 'personal on mate-mac' }), candidate('c3', 'owner-mac')], 'c3') } as Command,f.leadActor, {})expect(effects.routeDecisions[0]).toMatchObject({ op: 'create', record: {- candidates: [{ id: 'c0' }, { id: 'c3' }],+ candidates: [{ id: 'c2' }, { id: 'c3' }],excluded: [- { title: 'c1 on mate-mac', reason: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects.' },- { title: 'personal on mate-mac', reason: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects.' },+ { title: 'c0 on mate-team', reason: 'Harness Team accounts are gone: an agent runs on its own person\'s computer, in their own account.' },+ { title: 'c1 on mate-mac', reason: 'A new agent starts only on its own person\'s computer, in their own account, never on another person\'s.' },{ title: 'Owner Mac · claude', reason: 'Subscription exhausted.' },] } })- expect(effects.messages[0]!.source).toMatchObject({ pick: { id: 'c0' }, alternatives: [{ id: 'c3', title: 'c3 on owner-mac' }] })- })-- it('names the failing item and a stale or missing check in the exclusion', () => {- const f = routed()- f.state.machines!.push({ ...structuredClone(f.machine('mate-team')), machineId: 'mate-stale', name: 'Mini · Team',- observation: reading('team', PASSED, NOW, NOW - 30 * MINUTE) })- f.machine('mate-team').observation = reading('team', FAILED)- const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'owner-mac'), candidate('c1', 'mate-team'),- candidate('c2', 'mate-stale')]) } as Command, f.leadActor, {})- expect((effects.routeDecisions[0] as { record: { excluded: { reason: string }[] } }).record.excluded.map(e => e.reason)).toEqual([- 'The Harness Team account on MacBook Pro · Team is not private (gitconfig: it could read its owner\'s ~/.gitconfig), so it runs only its owner\'s projects.',- 'The privacy check on Mini · Team last passed 30 minutes ago, so it runs only its owner\'s projects until it passes again.',- 'Subscription exhausted.',- ])+ expect(effects.messages[0]!.source).toMatchObject({ pick: { id: 'c3' }, alternatives: [{ id: 'c2', title: 'personal on mate-mac' }] })})it('refuses a pick that cannot take it, so no decision names it', () => {const f = routed()- expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'mate-mac'), candidate('c1', 'mate-team')]) } as Command,- f.leadActor, {}))).toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED',- message: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects. Route again.' })+ expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'mate-team'), candidate('c1', 'owner-mac')]) } as Command,+ f.leadActor, {}))).toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED',+ message: 'Harness Team accounts are gone: an agent runs on its own person\'s computer, in their own account. Route again.' })})// Task #2901 (Ken, 2026-11-04): a route names no pick, so no single refusal decides it; it is refused once no candidate is left.@@ -314,24 +290,21 @@ describe('routing a teammate\'s work', () => {const { pick: _pick, ...rest } = record(candidates)return { ...rest, via: 'instructions', floor: 1, why: 'No ranking: the project\'s Routing instructions choose.' }}- const effects = f.run({ type: 'route.record', conversationId: f.group, decision: pickless([candidate('c0', 'mate-mac'), candidate('c1', 'mate-team')]) } as Command,+ const effects = f.run({ type: 'route.record', conversationId: f.group, decision: pickless([candidate('c0', 'mate-mac'), candidate('c1', 'owner-mac')]) } as Command,f.leadActor, {})expect(effects.routeDecisions[0]).toMatchObject({ op: 'create', record: { candidates: [{ id: 'c1' }],- excluded: [{ title: 'c0 on mate-mac', reason: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects.' }, { title: 'Owner Mac · claude' }] } })- expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group, decision: pickless([candidate('c0', 'mate-mac')]) } as Command, f.leadActor, {})))- .toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', message: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects. Route again.' })+ excluded: [{ title: 'c0 on mate-mac', reason: 'A new agent starts only on its own person\'s computer, in their own account, never on another person\'s.' },+ { title: 'Owner Mac · claude' }] } })+ expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group, decision: pickless([candidate('c0', 'mate-team')]) } as Command, f.leadActor, {})))+ .toMatchObject({ code: 'TEAM_ACCOUNTS_REMOVED', message: 'Harness Team accounts are gone: an agent runs on its own person\'s computer, in their own account. Route again.' })})- it('refuses a person\'s reroute to a candidate whose machine can no longer take it', () => {+ it('refuses a person\'s reroute to a candidate in a Team account', () => {const f = routed()const decision = { id: 'd1', conversationId: f.group, record: record([candidate('c0', 'owner-mac'), candidate('c1', 'mate-team')]),final: null, override: null, assignmentId: null, outcome: null } as unknown as RouteDecision- f.machine('mate-team').observation = reading('team', FAILED)expect(refusal(() => f.run({ type: 'route.override', decisionId: 'd1', candidateId: 'c1', reason: 'More quota there.' }, owner, { routeDecision: decision }))?.code)- .toBe('PRIVACY_CHECK_FAILED')- f.machine('mate-team').observation = reading('team', PASSED)- expect(f.run({ type: 'route.override', decisionId: 'd1', candidateId: 'c1', reason: 'More quota there.' }, owner, { routeDecision: decision }).routeDecisions)- .toEqual([expect.objectContaining({ op: 'override', id: 'd1' })])+ .toBe('TEAM_ACCOUNTS_REMOVED')})it('keeps a person\'s own project routing as it was', () => {@@ -341,22 +314,22 @@ describe('routing a teammate\'s work', () => {})})-describe('agents already working on a personal machine', () => {+describe('agents already working in a Team account', () => {it('keep their task, its reports and their messages; only new work for them is refused', () => {const f = swarm(), group = f.group()- // Work assigned before the rule: a teammate's agent on their personal Mac doing the owner's project.- const old = f.member('old', 'mate-mac', 'mate')+ // Work assigned before the release: a teammate's Team-account agent doing the owner's project.+ const old = f.member('old', 'mate-team', 'mate')const work = f.state.conversations.find(c => c.id === group)!work.agentIds.push(old)work.assignment = { id: 'before-release', agentId: old, status: 'working', configuration: config,- execution: { machineId: 'mate-mac', harnessId: 'harness-old', machineOwnerId: 'mate' }, result: null }+ execution: { machineId: 'mate-team', harnessId: 'harness-old', machineOwnerId: 'mate' }, result: null }const oldActor: Actor = { kind: 'agent', agentId: old, machineOwnerId: 'mate' }f.run({ type: 'work.status', conversationId: group, assignmentId: 'before-release', status: 'blocked', hold: HOLD, result: 'Needs a token.' }, oldActor)expect(f.run({ type: 'message.send', conversationId: group, text: 'Here it is.', replyTo: null, recipientIds: [old] }).messages[0]!.recipients).toEqual([old])expect(f.state.agents.find(a => a.id === old)).not.toHaveProperty('workDecision')expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ id: 'before-release', status: 'blocked' })f.run({ type: 'work.cancel', conversationId: group, assignmentId: 'before-release', reason: 'Moving it.' })- expect(refusal(() => f.run({ type: 'work.assign', conversationId: group, agentId: old }))?.code).toBe('TEAM_ACCOUNT_REQUIRED')+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: group, agentId: old }))?.code).toBe('TEAM_ACCOUNTS_REMOVED')})})@@ -378,23 +351,6 @@ describe('until a team account is required everywhere', () => {expect(teamWorkRefusal(pool(reading('team', PASSED)), NOW)).toBeNull()})- it('starts, assignments and Reviewers on a personal machine or off the Machines list are admitted as before', () => {- const f = swarm(), group = f.group()- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))- f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-laptop'), cwd: '/work' } }, mate, { contribution: { machineOwnerId: 'mate', contributorId: 'mate' } })- expect(f.state.starts).toHaveLength(2)- const personal = f.member('personal', 'mate-mac', 'mate')- f.run({ type: 'work.assign', conversationId: group, agentId: personal })- expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ agentId: personal, status: 'working' })- const reviewer = f.member('reviewer', 'mate-mac', 'mate', 'lead', { role: 'reviewer' })- f.run({ type: 'conversation.agent', conversationId: f.group(), agentId: reviewer, present: true, lead: false })- })-- it('a Team machine whose check fails still refuses it', () => {- const f = swarm(), group = f.group()- f.machine('mate-team').observation = reading('team', FAILED)- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, f.pooled('mate-team')))?.code).toBe('PRIVACY_CHECK_FAILED')- })})// Every Swarm alike (2026-11-02). The switch was held to listed owners' Swarms while it was tried on production@@ -402,25 +358,11 @@ describe('until a team account is required everywhere', () => {describe('the switch, in every Swarm', () => {afterEach(() => { delete process.env.SWARM_TEAM_ACCOUNT_OWNERS })- it('requires a team account in any Swarm, whatever SWARM_TEAM_ACCOUNT_OWNERS says, and in none with the switch off', () => {- const f = swarm(), group = f.group()+ it('reads as on in any Swarm, whatever SWARM_TEAM_ACCOUNT_OWNERS says, and off with the switch off', () => {process.env.SWARM_TEAM_ACCOUNT_OWNERS = '[email protected]'expect(teamAccountRequired()).toBe(true)- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))?.code)- .toBe('TEAM_ACCOUNT_REQUIRED')delete process.env.SWARM_TEAM_ACCOUNT_REQUIREDexpect(teamAccountRequired()).toBe(false)- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))- expect(f.state.starts).toHaveLength(1)- })-- it('sends a teammate\'s work on a Mac to its team account in any Swarm, whatever SWARM_TEAM_ACCOUNT_OWNERS says', () => {- 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]'- 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-team', cwd: '/team-swarm/lead' })})})@@ -435,14 +377,10 @@ describe('one machine: a Mac and its Harness Team account', () => {return f}- it('a teammate\'s project started on the Mac runs in its Harness Team account, in that account\'s folder', () => {+ it('a teammate\'s project started on the Mac stays on the Mac, in its person\'s own account and folder', () => {const f = oneMachine(), group = f.group()- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))- expect(f.state.starts).toEqual([expect.objectContaining({ poolGeneration: 'g1', machineOwnerId: 'mate',- request: expect.objectContaining({ machineId: 'mate-team', cwd: '/team-swarm/lead' }) })])- // A Lead that already named the team account's folder keeps it.- f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-mac'), cwd: '/team-swarm/lead' } }, owner, f.pooled('mate-mac'))- expect(f.state.starts![1]!.request).toMatchObject({ machineId: 'mate-team', cwd: '/team-swarm/lead' })+ f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, mate, f.pooled('mate-mac'))+ expect(f.state.starts).toEqual([expect.objectContaining({ request: expect.objectContaining({ machineId: 'mate-mac', cwd: '/swarm/lead' }) })])})// 2026-10-28: every Mac read "has no Harness Team account yet" beside the account that took its teammates' work.@@ -459,43 +397,13 @@ describe('one machine: a Mac and its Harness Team account', () => {expect(machineTeamWork(f.state, f.machine('mate-mac'), NOW, [])?.code).toBe('TEAM_ACCOUNT_REQUIRED')})- it('once the team account is removed, its pool left behind takes nothing: the Mac is a Mac without one again', () => {- // Its machine is deleted, so the store no longer lists it among the tab's team machines.- const f = oneMachine(), group = f.group()- f.machine('mate-team').observation = reading('team', PASSED, NOW - 60_000)- delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, { ...f.pooled('mate-mac'), teamMachines: [] })- expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'mate-mac', cwd: '/swarm/lead' })- process.env.SWARM_TEAM_ACCOUNT_REQUIRED = '1'- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, { ...f.pooled('mate-mac'), teamMachines: [] }))?.code)- .toBe('TEAM_ACCOUNT_REQUIRED')- // While it is still an account row, it is the account that runs teammates' work, offline or not.- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, { ...f.pooled('mate-mac'), teamMachines: ['mate-team'] }))?.code)- .toBe('MACHINE_OFFLINE')- })-- // Local Team account run, 2026-10-28: for a minute after `harness team remove`, its last reading still read as taking- // teammates' work, and a Lead's route named it.- it('once the team account is removed, its pool takes nothing at once, though its last reading is still fresh', () => {+ it('takes nothing in its Team account, whether its account row is still listed or not', () => {const f = oneMachine(), group = f.group()- f.machine('mate-team').observation = reading('team', PASSED)- expect(machineTeamWork(f.state, f.machine('mate-team'), NOW, [])?.code).toBe('TEAM_ACCOUNT_REQUIRED')- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, { ...f.pooled('mate-team'), teamMachines: [] }))?.code)- .toBe('TEAM_ACCOUNT_REQUIRED')- expect(f.state.starts ?? []).toEqual([])- // Until the switch is on, the same: a removed Harness Team account is no Team machine.- delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED+ for (const teamMachines of [[], ['mate-team']]) {+ expect(refusal(() => f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-team'), cwd: '/team-swarm/lead' } }, mate,+ { ...f.pooled('mate-team'), teamMachines }))?.code).toBe('TEAM_ACCOUNTS_REMOVED')+ }expect(machineTeamWork(f.state, f.machine('mate-team'), NOW, [])?.code).toBe('TEAM_ACCOUNT_REQUIRED')- process.env.SWARM_TEAM_ACCOUNT_REQUIRED = '1'- })-- it('is refused with the team account\'s own reason, and never falls back to the Mac\'s owner', () => {- const f = oneMachine(), group = f.group()- f.machine('mate-team').observation = reading('team', FAILED)- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))).toMatchObject({- code: 'PRIVACY_CHECK_FAILED', message: 'The Harness Team account on MacBook Pro is not private (gitconfig: it could read its owner\'s ~/.gitconfig), so it runs only its owner\'s projects.' })- f.machine('mate-team').observation = reading('team', PASSED, NOW - 60_000)- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))?.code).toBe('MACHINE_OFFLINE')expect(f.state.starts ?? []).toEqual([])})@@ -505,46 +413,6 @@ describe('one machine: a Mac and its Harness Team account', () => {expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'mate-mac', cwd: `/swarm/${f.mine}` })})- it('with no GitHub App on the server, sends nothing to the team account: the Mac takes the start as before', () => {- // Until a team account is required everywhere: a team account with no git login of its own cannot fetch or push.- delete process.env.SWARM_TEAM_ACCOUNT_REQUIRED- const f = oneMachine(), group = f.group()- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, { ...f.pooled('mate-mac'), teamAccountsIdle: true })- expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'mate-mac', cwd: '/swarm/lead' })- })-- it('still takes a start that names the team account\'s machine directly', () => {- const f = oneMachine(), group = f.group()- f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-team'), cwd: '/team-swarm/lead' } }, owner, f.pooled('mate-team'))- expect(f.state.starts![0]!.request).toMatchObject({ machineId: 'mate-team' })- })-- it('a Mac whose team account is not in the Swarm refuses as before', () => {- const f = oneMachine(), group = f.group()- f.state.machines = f.state.machines!.filter(m => m.machineId !== 'mate-team')- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))?.code).toBe('TEAM_ACCOUNT_REQUIRED')- })-- it('a route that picked the Mac for a teammate\'s project keeps it, and the start there is the pick', () => {- const f = oneMachine()- const lead = String(f.run({ type: 'agent.add', conversationId: 'lead', machineId: 'owner-mac', harnessId: 'lead', name: 'Lead', configuration: config, lead: true },- owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } }).result.agentId)- const group = f.group(), leadActor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'owner' }- const candidate = { id: 'c0', kind: 'new', machineId: 'mate-mac', engine: 'codex', model: 'default', effort: 'default', quality: 3, cost: 2,- title: 'Builder on MacBook Pro', label: 'Codex' }- const effects = f.run({ type: 'route.record', conversationId: group, decision: { assessment: { difficulty: 'medium', risk: 'low', why: 'A small change.' },- candidates: [candidate], excluded: [], floor: 2, notes: false, pick: 'c0', via: 'order', p: null, belowFloor: false, why: 'Policy order.' } } as Command,- leadActor, {})- const recorded = effects.routeDecisions[0] as unknown as { id: string; record: RouteDecision['record'] }- expect(recorded.record.candidates).toEqual([expect.objectContaining({ id: 'c0' })])- const decision = { id: recorded.id, conversationId: group, record: recorded.record, final: null, override: null, assignmentId: null, outcome: null } as unknown as RouteDecision- const started = f.run({ type: 'agent.start', routeDecisionId: recorded.id, request: { ...f.request(group, 'mate-mac'), model: 'default', effort: 'default' } },- leadActor, { ...f.pooled('mate-mac'), routeDecision: decision })- expect(f.state.starts!.at(-1)!.request.machineId).toBe('mate-team')- expect(started.routeDecisions).toEqual([expect.objectContaining({ op: 'final', id: recorded.id })])- expect(started.routeDecisions[0]).not.toHaveProperty('override')- })-it('joins by itself where its owner added the Mac, under the Mac\'s name, slots and pause', () => {const f = swarm()f.state.machines = f.state.machines!.filter(m => m.machineId !== 'mate-team')@@ -591,16 +459,16 @@ describe('one machine: a Mac and its Harness Team account', () => {})describe('one machine: the Mac\'s agent slots', () => {- it('are shared by the Mac and its Harness Team account', () => {+ it('are shared by the Mac and its Harness Team account while an agent is still there', () => {const f = swarm(), group = f.group()Object.assign(f.machine('mate-team'), { hostMachineId: 'mate-mac', name: 'MacBook Pro', cwd: '/team-swarm', maxAgents: 2 })f.machine('mate-mac').maxAgents = 2f.member('mine', 'mate-mac', 'mate', f.mine)- f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac'))- // One on the owner's daemon and one in the team account: the Mac's two slots are taken, whichever side asks.+ f.member('team-agent', 'mate-team', 'mate')+ // One on the owner's daemon and one left in the team account: the Mac's two slots are taken, whichever side asks.expect(machineSlots(f.state, f.machine('mate-mac'))).toBe(2)expect(machineSlots(f.state, f.machine('mate-team'))).toBe(2)- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))?.code).toBe('MACHINE_FULL')+ expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, mate, f.pooled('mate-mac')))?.code).toBe('MACHINE_FULL')// A machine without a team account counts only its own.expect(machineSlots(f.state, f.machine('owner-mac'))).toBe(0)})@@ -616,13 +484,10 @@ describe('one machine: a Mac whose Harness Team account was made again', () => {return f}- it('sends a teammate\'s start on the Mac to the account that runs, not the old one', () => {- const f = remade(), group = f.group()+ it('counts no slot of the Mac for the old account\'s leftover agent', () => {+ const f = remade()f.member('old-agent', 'mate-team', 'mate')- 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-team-2', cwd: '/team-swarm/lead' })- // The old account's leftover agent holds none of the Mac's slots.- expect(machineSlots(f.state, f.machine('mate-mac'))).toBe(1)+ expect(machineSlots(f.state, f.machine('mate-mac'))).toBe(0)})it('pauses and removes both with the Mac, and its removal preview names every agent it takes', () => {@@ -638,32 +503,12 @@ describe('one machine: a Mac whose Harness Team account was made again', () => {expect(f.state.machineCleanups).toEqual(expect.arrayContaining([expect.objectContaining({ machineId: 'mate-team' })]))})- it('never sends work to an account that is being removed', () => {- const f = swarm(), group = f.group()- Object.assign(f.machine('mate-team'), { hostMachineId: 'mate-mac', name: 'MacBook Pro', removal: { id: 'r', state: 'cleaning', requestedAt: new Date(NOW).toISOString() } })- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-mac') }, owner, f.pooled('mate-mac')))?.code).toBe('TEAM_ACCOUNT_REQUIRED')- })})// A Harness Team account runs every teammate's work as one macOS user, so in Swarms of two Workspaces one Workspace's agents could// read the other's folders there (docs/plans/2026-10-27-swarm-workspaces.md, Audience). `otherWorkspaceMachines`: the machines this// Swarm's store found contributed to a Swarm of another Workspace.describe('a Team machine serving more than one Workspace', () => {- it('takes no teammate\'s work while it is in Swarms of another Workspace, and says why', () => {- const f = swarm(), group = f.group()- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'mate-team') }, owner, { ...f.pooled('mate-team'), otherWorkspaceMachines: ['mate-team'] })))- .toMatchObject({ code: 'MACHINE_IN_OTHER_WORKSPACE', status: 403,- message: 'The Harness Team account on MacBook Pro · Team also serves another Workspace\'s Swarms, so it runs only its owner\'s projects here.' })- expect(f.state.starts ?? []).toEqual([])- })-- it('still runs its owner\'s own projects there, and a teammate\'s work once it serves this Workspace alone', () => {- const f = swarm()- f.run({ type: 'agent.start', request: f.request(f.group(f.mine, mate), 'mate-team', f.mine) }, mate, { ...f.pooled('mate-team'), otherWorkspaceMachines: ['mate-team'] })- f.run({ type: 'agent.start', request: f.request(f.group(), 'mate-team') }, owner, { ...f.pooled('mate-team'), otherWorkspaceMachines: [] })- expect(f.state.starts).toHaveLength(2)- })-it('shows routing the reason, like any other refusal', () => {const f = swarm()expect(teamWorkRefusal(f.machine('mate-team'), NOW, true, true, true)?.code).toBe('MACHINE_IN_OTHER_WORKSPACE')@@ -680,15 +525,14 @@ describe('a machine added as its person joined', () => {cwd: '/swarm', scope: 'swarm', engines: ['codex'], maxAgents: 4, teamAccountOnly: true }const contribution = { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } }- it('refuses a teammate\'s start on it while it has no Harness Team account, and keeps its person\'s own projects', () => {+ it('takes its person\'s own agent for any project they read, and no other person\'s start', () => {const f = swarm(), group = f.group(), own = f.group(f.mine, mate)f.run(joined, mate, contribution)f.machine('joined-mac').observation = reading('computer')- expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'joined-mac') }, owner, f.pooled('joined-mac'))))- .toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED', status: 403, message: 'MacBook Air has no Harness Team account yet, so it runs only its owner\'s projects.' })- expect(f.state.starts ?? []).toEqual([])+ expect(refusal(() => f.run({ type: 'agent.start', request: f.request(group, 'joined-mac') }, owner, f.pooled('joined-mac')))?.code).toBe('NOT_YOUR_COMPUTER')f.run({ type: 'agent.start', request: f.request(own, 'joined-mac', f.mine) }, mate, f.pooled('joined-mac'))- expect(f.state.starts).toHaveLength(1)+ f.run({ type: 'agent.start', request: f.request(group, 'joined-mac') }, mate, f.pooled('joined-mac'))+ expect(f.state.starts).toHaveLength(2)})it('says why in its reading, so routing leaves it out of a teammate\'s project', () => {@@ -828,7 +672,7 @@ describe('machines take agents as memory allows (Dee, 11-04: "remove the limit")const room = (id: string) => availableSlots(f.state, f.machine(id), machineSlots(f.state, f.machine(id)))expect([room('mate-mac'), room('mate-team')]).toEqual([1, 1])f.member('mine', 'mate-mac', 'mate', f.mine)- expect(refusal(() => f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-mac'), requirements: twoGiB } }, owner, f.pooled('mate-mac')))).toBeNull()+ expect(refusal(() => f.run({ type: 'agent.start', request: { ...f.request(group, 'mate-mac'), requirements: twoGiB } }, mate, f.pooled('mate-mac')))).toBeNull()// The one start holds the 2 GiB both readings show.expect([room('mate-mac'), room('mate-team')]).toEqual([0, 0])})diff --git a/backend/src/superTabs/teamWritten.test.ts b/backend/src/superTabs/teamWritten.test.tsindex 1c88a35b4..69468447b 100644--- a/backend/src/superTabs/teamWritten.test.ts+++ b/backend/src/superTabs/teamWritten.test.ts@@ -5,8 +5,10 @@ import { createSuperTab, SuperTabError, type Actor, type AgentConfiguration, typimport { LEAD_CAPABILITY } from './leadStart.js'import { applyPushOrigin, TEAM_WRITTEN_STOP, TEAM_WRITTEN_WORK, teamWrittenTask } from './teamWritten.js'-// Audit H2: a branch a Team agent wrote runs only in a Team account, whoever's project it is, so nothing the branch-// carries runs with the main account's rights (docs/plans/2026-11-02-team-written-branch-plan.md).+// Audit H2: a branch a Team agent wrote never runs with another person's rights (docs/plans/2026-11-02-team-written-branch-plan.md).+// Swarm v3 has no Team accounts to run it (task #4120, the PM's ruling there): the mark stays on every branch a Team agent pushed+// before the release, and only the project owner's own agent, on their own computer, may take one over. A teammate's agent, here+// mate's, is refused as the main account's was. Team agents keep what they hold and take nothing new.const NOW = 50_000_000const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }const config: AgentConfiguration = { engine: 'claude', model: 'fixture-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }@@ -22,7 +24,9 @@ function swarm() {const generation = state.people.find(p => p.id === 'owner')!.generationconst pool = (machineId: string, sessionKind: 'team' | 'computer', extra: Partial<ContributedMachine> = {}): ContributedMachine => ({ machineId, name: machineId, contributorId: 'owner',membershipGeneration: generation, generation: 'g1', cwd: '/swarm', scope: 'swarm', engines: ['claude'], maxAgents: 4, paused: false, observation: reading(sessionKind), ...extra })- state.machines = [pool('mac', 'computer'), pool('mac-team', 'team', { hostMachineId: 'mac' })]+ state.people.push({ id: 'mate', email: '[email protected]', role: 'collaborator', generation: 'm1' })+ state.machines = [pool('mac', 'computer'), pool('mac-team', 'team', { hostMachineId: 'mac' }),+ pool('mate-mac', 'computer', { contributorId: 'mate', membershipGeneration: 'm1' })]const run = (command: Command, actor: Actor = owner, context: Partial<CommandContext> = {}) => {const effects = applyCommand(state, actor, command, { now: NOW, operationId: `op-${++sequence}`, teamMachines: ['mac-team'],contribution: { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }, ...context })@@ -34,16 +38,35 @@ function swarm() {membershipGeneration: generation, hostGrant: null, name: id, configuration: config })return id}+ /** A teammate's own agent on their own computer: the one Team-written code refuses (the main account's, before v3). */+ const mates = (id: string) => {+ state.agents.push({ id, machineId: 'mate-mac', harnessId: `harness-${id}`, projectId: 'lead', machineOwnerId: 'mate', contributorId: 'mate',+ membershipGeneration: 'm1', hostGrant: null, name: id, configuration: config })+ return id+ }+ /** [agentId] already in [conversationId], as a Team agent that joined before the release still is. */+ const within = (conversationId: string, agentId: string) => {+ const group = state.conversations.find(c => c.id === conversationId)!+ group.agentIds = [...new Set([...group.agentIds, agentId])]+ }const group = (extra: Partial<Extract<Command, { type: 'conversation.create' }>> = {}, actor: Actor = owner) => String(run({ type: 'conversation.create', projectId: 'lead', title: 'Work', brief: 'Build it.',checks: [], ...extra }, actor).result.conversationId)- const start = (conversationId: string, machineId: string) => run({ type: 'agent.start', request: { conversationId, machineId, engine: 'claude', name: 'Reviewer', cwd: '/swarm/lead', worktree: true, requirements } })- /** A task a Team agent was assigned, with its finished assignment left behind so a review can begin. */+ const start = (conversationId: string, machineId: string, actor: Actor = owner, context: Partial<CommandContext> = {}) => run({ type: 'agent.start',+ request: { conversationId, machineId, engine: 'claude', name: 'Reviewer', cwd: '/swarm/lead', worktree: true, requirements } }, actor, context)+ /** As a teammate, on their own computer under their own grant. */+ const asMate: Actor = { kind: 'person', userId: 'mate', email: '[email protected]' }+ const mateGrant = { contribution: { machineOwnerId: 'mate', contributorId: 'mate', hostGrant: null } }+ /** A task a Team agent built before the release: marked, its builder still in it with its finished assignment, so a review can begin. */const written = () => {- const task = group()- run({ type: 'work.assign', conversationId: task, agentId: member('team-builder', 'mac-team') })+ const task = group(), builder = member('team-builder', 'mac-team')+ const stored = state.conversations.find(c => c.id === task)!+ Object.assign(stored, { teamWritten: true, teamWrittenBy: { kind: 'assigned' } })+ stored.assignment = { id: 'built', agentId: builder, status: 'done', configuration: config, result: null,+ execution: { machineId: 'mac-team', harnessId: `harness-${builder}`, machineOwnerId: 'owner' } } as never+ within(task, builder)return task}- return { run, group, member, start, written, get state() { return state } }+ return { run, group, member, mates, within, start, asMate, mateGrant, written, get state() { return state } }}const refusal = (body: () => unknown): string | null => {try { body(); return null } catch (error) { if (error instanceof SuperTabError) return error.code; throw error }@@ -58,74 +81,37 @@ describe('a task a Team agent worked on', () => {expect(teamWrittenTask(f.state, stored())).toBe(true)})- // #3304: joining a task is not writing its code. Hazel4 joined Magnolia2's task to post a list, and no main-account agent could- // take its steps after, though every commit on its branch was a person's. A Team agent's push shows in GitHub's record.- it('does not mark a task when a Team agent opens it, is added to it, is named into it or posts there', () => {- const f = swarm(), builder = f.member('main-builder', 'mac')- const asBuilder: Actor = { kind: 'agent', agentId: builder, machineOwnerId: 'owner' }- const opened = f.group({ checks: [{ description: 'Done', independent: false }], priority: 'P2', requesterId: 'owner' }, { kind: 'agent', agentId: f.member('team-a', 'mac-team'), machineOwnerId: 'owner' })- const added = f.group(), named = f.group(), posted = f.group()- for (const task of [added, named, posted]) f.run({ type: 'conversation.agent', conversationId: task, agentId: builder, present: true, lead: false })- const told = [- f.run({ type: 'conversation.agent', conversationId: added, agentId: f.member('team-b', 'mac-team'), present: true, lead: false }),- f.run({ type: 'message.send', conversationId: named, text: 'Please look.', replyTo: null, recipientIds: [f.member('team-c', 'mac-team')] }, asBuilder),- ]- const poster = f.member('team-d', 'mac-team')- f.run({ type: 'conversation.agent', conversationId: posted, agentId: poster, present: true, lead: false })- f.state.conversations.find(c => c.id === posted)!.agentIds = f.state.conversations.find(c => c.id === posted)!.agentIds.filter(id => id !== poster)- told.push(f.run({ type: 'message.send', conversationId: posted, text: 'Here is the list.', replyTo: null, recipientIds: [] }, { kind: 'agent', agentId: poster, machineOwnerId: 'owner' }))- expect(told.flatMap(e => e.messages).some(m => m.text === TEAM_WRITTEN_STOP)).toBe(false)- for (const task of [opened, added, named, posted]) {- expect(f.state.conversations.find(c => c.id === task)!.teamWritten, task).toBeUndefined()- const step = f.group({ reviewOf: task, step: 'Review' })- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: f.member(`main-reviewer-${task}`, 'mac') })), task).toBeNull()- }- })-- it('is marked when a Team agent is assigned to build it', () => {- const f = swarm(), task = f.written()- expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBe(true)- })-- it('refuses an agent in the main account: assigned to its step, or to the task itself', () => {- const f = swarm(), task = f.written(), main = f.member('main-reviewer', 'mac')+ it('refuses a teammate\'s agent, assigned to its step or to the task itself, and takes the project owner\'s own', () => {+ const f = swarm(), task = f.written(), mates = f.mates('mates-reviewer')const step = f.group({ reviewOf: task, step: 'Review' })- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: main }))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: mates }))).toBe(TEAM_WRITTEN_WORK)f.state.conversations.find(c => c.id === task)!.assignment = null- expect(refusal(() => f.run({ type: 'work.assign', conversationId: task, agentId: main }))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: task, agentId: mates }))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: f.member('owners-reviewer', 'mac') }))).toBeNull()})- it('refuses adding the main account\'s agent to it, and another agent\'s post naming it does not add it', () => {- const f = swarm(), task = f.written(), main = f.member('main-reviewer', 'mac')- expect(refusal(() => f.run({ type: 'conversation.agent', conversationId: task, agentId: main, present: true, lead: false }))).toBe(TEAM_WRITTEN_WORK)- const sent = f.run({ type: 'message.send', conversationId: task, text: 'Please test this.', replyTo: null, recipientIds: [main] },+ it('refuses adding a teammate\'s agent to it, and another agent\'s post naming it does not add it', () => {+ const f = swarm(), task = f.written(), mates = f.mates('main-reviewer')+ expect(refusal(() => f.run({ type: 'conversation.agent', conversationId: task, agentId: mates, present: true, lead: false }))).toBe(TEAM_WRITTEN_WORK)+ const sent = f.run({ type: 'message.send', conversationId: task, text: 'Please test this.', replyTo: null, recipientIds: [mates] },{ kind: 'agent', agentId: 'team-builder', machineOwnerId: 'owner' })- expect(f.state.conversations.find(c => c.id === task)!.agentIds).not.toContain(main)+ expect(f.state.conversations.find(c => c.id === task)!.agentIds).not.toContain(mates)expect(sent.result.notReached).toContain('main-reviewer')})- it('takes a Team agent as its Reviewer, and that does not mark a clean task', () => {- const f = swarm(), task = f.written(), reviewer = f.member('team-reviewer', 'mac-team')- const step = f.group({ reviewOf: task, step: 'Review' })- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: reviewer }))).toBeNull()- const clean = f.group(), cleanStep = f.group({ reviewOf: clean, step: 'Test' })- f.run({ type: 'work.assign', conversationId: cleanStep, agentId: f.member('team-tester', 'mac-team') })- expect(f.state.conversations.find(c => c.id === clean)!.teamWritten).toBeUndefined()- expect(refusal(() => f.run({ type: 'work.assign', conversationId: clean, agentId: f.member('main-builder', 'mac') }))).toBeNull()- })-- it('moves a start on the Mac into its Team account, with project settings off', () => {+ it('starts only on the project owner\'s own computer, with project settings off, and never in a Team account', () => {const f = swarm(), task = f.written()f.start(f.group({ reviewOf: task, step: 'Review' }), 'mac')const started = f.state.starts!.at(-1)!.request- expect(started.machineId).toBe('mac-team')+ expect(started.machineId).toBe('mac')expect(started.projectSettings).toBe('off')+ expect(refusal(() => f.start(f.group({ reviewOf: task, step: 'Test' }), 'mac-team'))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.start(f.group(), 'mac-team'))).toBe('TEAM_ACCOUNTS_REMOVED')})- it('refuses a start where the Mac has no Team account', () => {+ it('refuses a start on a teammate\'s computer', () => {const f = swarm(), task = f.written(), step = f.group({ reviewOf: task, step: 'Review' })- f.state.machines = f.state.machines!.filter(m => m.machineId !== 'mac-team')- expect(refusal(() => f.start(step, 'mac'))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.start(step, 'mate-mac', f.asMate, f.mateGrant))).toBe(TEAM_WRITTEN_WORK)})it('leaves an owner\'s clean task as it was: a start in the main account, project settings on', () => {@@ -136,28 +122,28 @@ describe('a task a Team agent worked on', () => {expect(started.projectSettings).toBeUndefined()})- it('takes GitHub\'s record of a bot\'s push: a clean task is marked for good and refuses the main account', () => {- const f = swarm(), task = f.group(), step = f.group({ reviewOf: task, step: 'Review' }), main = f.member('main-reviewer', 'mac')- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: main }, owner, { pushOrigin: 'team' }))).toBe(TEAM_WRITTEN_WORK)+ it('takes GitHub\'s record of a bot\'s push: a clean task is marked for good and refuses a teammate\'s agent', () => {+ const f = swarm(), task = f.group(), step = f.group({ reviewOf: task, step: 'Review' }), mates = f.mates('mates-reviewer')+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: mates }, owner, { pushOrigin: 'team' }))).toBe(TEAM_WRITTEN_WORK)// Refused, so nothing it did stays: the next reading decides again, and a clean reading never clears a mark.f.state.conversations.find(c => c.id === task)!.teamWritten = true- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: main }, owner, { pushOrigin: 'clean' }))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: mates }, owner, { pushOrigin: 'clean' }))).toBe(TEAM_WRITTEN_WORK)})- it('refuses the main account while GitHub cannot say who pushed, without marking the task, and takes it once GitHub answers', () => {- const f = swarm(), task = f.group(), step = f.group({ reviewOf: task, step: 'Review' }), main = f.member('main-reviewer', 'mac')- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: main }, owner, { pushOrigin: 'unknown' }))).toBe(TEAM_WRITTEN_WORK)+ it('refuses a teammate\'s agent while GitHub cannot say who pushed, without marking the task, and takes it once GitHub answers', () => {+ const f = swarm(), task = f.group(), step = f.group({ reviewOf: task, step: 'Review' }), mates = f.mates('mates-reviewer')+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: mates }, owner, { pushOrigin: 'unknown' }))).toBe(TEAM_WRITTEN_WORK)expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBeUndefined()- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: main }, owner, { pushOrigin: 'clean' }))).toBeNull()+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: mates }, owner, { pushOrigin: 'clean' }))).toBeNull()})- it('still gives a Team agent the work while GitHub cannot say who pushed', () => {- const f = swarm(), step = f.group({ reviewOf: f.group(), step: 'Review' })- expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: f.member('team-reviewer', 'mac-team') }, owner, { pushOrigin: 'unknown' }))).toBeNull()+ it('lets the project owner\'s own agent take it while GitHub cannot say who pushed (task #4120)', () => {+ const f = swarm(), task = f.group(), step = f.group({ reviewOf: task, step: 'Review' }), own = f.member('owners-reviewer', 'mac')+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: own }, owner, { pushOrigin: 'unknown' }))).toBeNull()})- it('tells a main-account agent on a step to stop when a Ready shows a bot\'s push on the owner\'s branch', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), reviewer = f.member('main-reviewer', 'mac')+ it('tells a teammate\'s agent on a step to stop when a Ready shows a bot\'s push on the owner\'s branch, never the owner\'s own', () => {+ const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), reviewer = f.mates('mates-reviewer')f.run({ type: 'work.assign', conversationId: task, agentId: builder })const assignmentId = f.state.conversations.find(c => c.id === task)!.assignment!.idf.run({ type: 'work.assign', conversationId: f.group({ reviewOf: task, step: 'Review' }), agentId: reviewer })@@ -167,29 +153,24 @@ describe('a task a Team agent worked on', () => {expect(effects.messages.find(m => m.text === TEAM_WRITTEN_STOP)?.recipients).toEqual([reviewer])})- it('tells every main-account member once when it is marked, finished steps included, and never the coordinator or a Team agent', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.member('main-tester', 'mac'), team = f.member('team-reviewer', 'mac-team')+ it('tells every barred member once when it is marked, finished steps included, never the owner\'s own agent, the coordinator or a Team agent', () => {+ const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.mates('mates-tester'), team = f.member('team-reviewer', 'mac-team')f.run({ type: 'work.assign', conversationId: task, agentId: builder })const assignmentId = f.state.conversations.find(c => c.id === task)!.assignment!.idconst testStep = f.group({ reviewOf: task, step: 'Test' }), reviewStep = f.group({ reviewOf: task, step: 'Review' })f.run({ type: 'work.assign', conversationId: testStep, agentId: tester })- f.run({ type: 'work.assign', conversationId: reviewStep, agentId: team })+ // A Team agent already on the review from before the release.+ f.within(reviewStep, team)// The Tester's step ended: it is still a member, and the same-step re-ask would reach it.f.state.conversations.find(c => c.id === testStep)!.assignment!.status = 'done'const effects = f.run({ type: 'work.status', conversationId: task, assignmentId, status: 'review', result: 'https://github.com/acme/app/pull/7' }, owner, { pushOrigin: 'team' })const told = effects.messages.filter(m => m.text === TEAM_WRITTEN_STOP).flatMap(m => m.recipients)- expect(told.sort()).toEqual([builder, tester].sort())+ expect(told).toEqual([tester])+ expect(told).not.toContain(builder)})- it('tells the main-account members when a Team agent is assigned to their clean task', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac')- f.run({ type: 'conversation.agent', conversationId: task, agentId: builder, present: true, lead: false })- const effects = f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') })- expect(effects.messages.find(m => m.text === TEAM_WRITTEN_STOP)?.recipients).toEqual([builder])- })-- it('delivers a post without a main-account member it names in a marked task, and says who was left out', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.member('main-tester', 'mac')+ it('delivers a post without a teammate\'s agent it names in a marked task, and says who was left out', () => {+ const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.mates('main-tester')f.run({ type: 'work.assign', conversationId: task, agentId: builder })f.run({ type: 'conversation.agent', conversationId: task, agentId: tester, present: true, lead: false })f.state.conversations.find(c => c.id === task)!.teamWritten = true@@ -200,9 +181,9 @@ describe('a task a Team agent worked on', () => {// The result names the agent who was left out, and says the post itself went out.expect(sent.result.notReached).toContain('main-tester')expect(sent.result.notReached).toContain('post was delivered')- // A Team agent may still be named, and a person speaks to whom they choose.+ // A Team agent already in it may still be named, and a person speaks to whom they choose.const team = f.member('team-tester', 'mac-team')- f.run({ type: 'conversation.agent', conversationId: task, agentId: team, present: true, lead: false })+ f.within(task, team)const toTeam = post(task, [team], asBuilder)expect(toTeam.messages.find(m => m.text === 'Please test again.')!.recipients).toEqual([team])expect(toTeam.result).not.toHaveProperty('notReached')@@ -211,12 +192,10 @@ describe('a task a Team agent worked on', () => {expect(byPerson.result).not.toHaveProperty('notReached')})- // Heron21 (Team Reviewer of #3245) named the Integrator, a main-account agent outside the group: the whole post was refused with a- // reason about Team accounts that read as being about Heron21. The post goes out; only the recipient is left out, and by name.- it('a Team agent\'s post naming a main-account agent outside the group goes out without it, and the agent does not join', () => {- const f = swarm(), task = f.written(), integrator = f.member('main-integrator', 'mac'), team = f.member('team-reviewer', 'mac-team')+ it('a Team agent\'s post naming a teammate\'s agent outside the group goes out without it, and the agent does not join', () => {+ const f = swarm(), task = f.written(), integrator = f.mates('main-integrator'), team = f.member('team-reviewer', 'mac-team')const step = f.group({ reviewOf: task, step: 'Review' })- f.run({ type: 'work.assign', conversationId: step, agentId: team })+ f.within(step, team)const asTeam: Actor = { kind: 'agent', agentId: team, machineOwnerId: 'owner' }const sent = f.run({ type: 'message.send', conversationId: step, text: 'Ready to merge: Yes.', replyTo: null, recipientIds: [integrator] }, asTeam)expect(sent.messages.find(m => m.text === 'Ready to merge: Yes.')!.recipients).not.toContain(integrator)@@ -225,24 +204,22 @@ describe('a task a Team agent worked on', () => {expect(f.state.conversations.find(c => c.id === task)!.agentIds).not.toContain(integrator)})- it('leaves out only the barred recipient when a post names a main-account agent and a Team agent', () => {- const f = swarm(), task = f.written(), integrator = f.member('main-integrator', 'mac'), team = f.member('team-reviewer', 'mac-team'), other = f.member('team-other', 'mac-team')+ it('leaves out only the barred recipient when a post names a teammate\'s agent and a Team agent', () => {+ const f = swarm(), task = f.written(), integrator = f.mates('main-integrator'), team = f.member('team-reviewer', 'mac-team'), other = f.member('team-other', 'mac-team')const step = f.group({ reviewOf: task, step: 'Review' })- f.run({ type: 'work.assign', conversationId: step, agentId: team })- f.run({ type: 'conversation.agent', conversationId: step, agentId: other, present: true, lead: false })+ f.within(step, team)+ f.within(step, other)const sent = f.run({ type: 'message.send', conversationId: step, text: 'Verdict.', replyTo: null, recipientIds: [integrator, other] }, { kind: 'agent', agentId: team, machineOwnerId: 'owner' })expect(sent.messages.find(m => m.text === 'Verdict.')!.recipients).toEqual([other])expect(sent.result.notReached).toContain('main-integrator')expect(sent.result.notReached).not.toContain('team-other')})- // Security review of #3199: with the barred id gone, the post fell back to the task's assignee, or to the author it replies to,- // and reached the very agent it was said not to reach.it('does not fall back to the barred agent: its assignee, or the author of the message it answers', () => {- const f = swarm(), task = f.group(), engineer = f.member('main-engineer', 'mac'), team = f.member('team-reviewer', 'mac-team')+ const f = swarm(), task = f.group(), engineer = f.mates('main-engineer'), team = f.member('team-reviewer', 'mac-team')f.run({ type: 'work.assign', conversationId: task, agentId: engineer })- f.run({ type: 'conversation.agent', conversationId: task, agentId: team, present: true, lead: false })- // Marked by GitHub's push record: the main-account Engineer is still assigned and in the group.+ f.within(task, team)+ // Marked by GitHub's push record: the teammate's Engineer is still assigned and in the group.f.state.conversations.find(c => c.id === task)!.teamWritten = trueconst asTeam: Actor = { kind: 'agent', agentId: team, machineOwnerId: 'owner' }const sent = f.run({ type: 'message.send', conversationId: task, text: 'Please test again.', replyTo: null, recipientIds: [engineer] }, asTeam)@@ -262,31 +239,30 @@ describe('a task a Team agent worked on', () => {expect(sent.result).not.toHaveProperty('notReached')})- it('a main-account agent\'s own post in a Team-written group is still refused: the rule about itself is unchanged', () => {- const f = swarm(), task = f.written(), main = f.member('main-reviewer', 'mac')- const own = () => f.run({ type: 'message.send', conversationId: task, text: 'Looks fine.', replyTo: null, recipientIds: [] }, { kind: 'agent', agentId: main, machineOwnerId: 'owner' })+ it('a teammate\'s agent\'s own post in a Team-written group is still refused: the rule about itself is unchanged', () => {+ const f = swarm(), task = f.written(), mates = f.mates('main-reviewer')+ const own = () => f.run({ type: 'message.send', conversationId: task, text: 'Looks fine.', replyTo: null, recipientIds: [] }, { kind: 'agent', agentId: mates, machineOwnerId: 'mate' })expect(refusal(own)).toBe(TEAM_WRITTEN_WORK)})- // #2963: @Name in the text names an agent too, but only one the sender may name; it never turns a post into a refusal.- it('skips a main-account member a post names by @Name in a marked task, and still posts', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.member('main-tester', 'mac')+ it('skips a teammate\'s agent a post names by @Name in a marked task, and still posts', () => {+ const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.mates('main-tester')f.run({ type: 'work.assign', conversationId: task, agentId: builder })f.run({ type: 'conversation.agent', conversationId: task, agentId: tester, present: true, lead: false })f.state.conversations.find(c => c.id === task)!.teamWritten = trueconst team = f.member('team-tester', 'mac-team')- f.run({ type: 'conversation.agent', conversationId: task, agentId: team, present: true, lead: false })+ f.within(task, team)const sent = f.run({ type: 'message.send', conversationId: task, text: '@main-tester and @team-tester, please test again.', replyTo: null, recipientIds: [] },{ kind: 'agent', agentId: builder, machineOwnerId: 'owner' })expect(sent.messages[0]!.recipients).toEqual([team])})- it('reads who pushed before adding an agent: a bot\'s push or an unknown refuses the main account, and a Team agent still joins', () => {- const f = swarm(), task = f.group(), main = f.member('main-reviewer', 'mac')+ it('reads who pushed before adding an agent: a bot\'s push or an unknown refuses a teammate\'s agent, and a Team agent joins nothing new', () => {+ const f = swarm(), task = f.group(), mates = f.mates('main-reviewer')const add = (agentId: string, pushOrigin: 'team' | 'unknown') => f.run({ type: 'conversation.agent', conversationId: task, agentId, present: true, lead: false }, owner, { pushOrigin })- expect(refusal(() => add(main, 'unknown'))).toBe(TEAM_WRITTEN_WORK)- expect(refusal(() => add(main, 'team'))).toBe(TEAM_WRITTEN_WORK)- expect(refusal(() => add(f.member('team-a', 'mac-team'), 'unknown'))).toBeNull()+ expect(refusal(() => add(mates, 'unknown'))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => add(mates, 'team'))).toBe(TEAM_WRITTEN_WORK)+ expect(refusal(() => add(f.member('team-a', 'mac-team'), 'unknown'))).toBe('TEAM_ACCOUNTS_REMOVED')})it('refuses a PM start in the main account on a branch a bot pushed or GitHub cannot place, and takes a clean one', () => {@@ -306,39 +282,14 @@ describe('a task a Team agent worked on', () => {expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBe(true)})- it('does not mark a clean task when a Team agent with a step on it joins its chat: it reads or tests, and a push of its own shows in GitHub', () => {- const f = swarm(), task = f.group(), builder = f.member('main-builder', 'mac'), tester = f.member('team-tester', 'mac-team')- f.run({ type: 'work.assign', conversationId: task, agentId: builder })- f.run({ type: 'work.assign', conversationId: f.group({ reviewOf: task, step: 'Test' }), agentId: tester })- const stored = f.state.conversations.find(c => c.id === task)!- // Named after leaving the task's chat, and posting there itself: each joins it again.- stored.agentIds = stored.agentIds.filter(id => id !== tester)- const named = f.run({ type: 'message.send', conversationId: task, text: 'Please test again.', replyTo: null, recipientIds: [tester] }, { kind: 'agent', agentId: builder, machineOwnerId: 'owner' })- expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBeUndefined()- expect(named.messages.some(m => m.text === TEAM_WRITTEN_STOP)).toBe(false)- const again = f.state.conversations.find(c => c.id === task)!- again.agentIds = again.agentIds.filter(id => id !== tester)- f.run({ type: 'message.send', conversationId: task, text: 'Testing now.', replyTo: null, recipientIds: [] }, { kind: 'agent', agentId: tester, machineOwnerId: 'owner' })- expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBeUndefined()- })-- it('still marks a task when a Team agent with a step on it is assigned the task itself', () => {- const f = swarm(), task = f.group(), tester = f.member('team-tester', 'mac-team')- f.run({ type: 'work.assign', conversationId: f.group({ reviewOf: task, step: 'Test' }), agentId: tester })- f.state.conversations.find(c => c.id === task)!.assignment = null- const free = f.state.conversations.find(c => c.reviewOf === task)!- free.assignment!.status = 'done'- f.run({ type: 'work.assign', conversationId: task, agentId: tester })- expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBe(true)- })-- it('reads who pushed the branch a start names: a bot\'s push moves it to the Team account, an unknown branch stays out of the main account', () => {+ it('reads who pushed the branch a start names: the owner\'s own computer takes a bot\'s push with project settings off, a teammate\'s takes neither it nor an unknown', () => {const f = swarm(), task = f.group()- const request = (conversationId: string) => ({ type: 'agent.start' as const, request: { conversationId, machineId: 'mac', engine: 'claude', name: 'Tester', cwd: '/swarm/lead', worktree: true, branchRef: 'refs/remotes/origin/fix', requirements } })- expect(refusal(() => f.run(request(task), owner, { pushOrigin: 'unknown' }))).toBe(TEAM_WRITTEN_WORK)- f.run(request(task), owner, { pushOrigin: 'team' })- expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'mac-team', projectSettings: 'off' })+ const request = (conversationId: string, machineId: string) => ({ type: 'agent.start' as const, request: { conversationId, machineId, engine: 'claude', name: 'Tester', cwd: '/swarm/lead', worktree: true, branchRef: 'refs/remotes/origin/fix', requirements } })+ expect(refusal(() => f.run(request(task, 'mate-mac'), f.asMate, { ...f.mateGrant, pushOrigin: 'unknown' }))).toBe(TEAM_WRITTEN_WORK)+ f.run(request(task, 'mac'), owner, { pushOrigin: 'team' })+ expect(f.state.starts!.at(-1)!.request).toMatchObject({ machineId: 'mac', projectSettings: 'off' })expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBe(true)+ expect(refusal(() => f.run(request(task, 'mate-mac'), f.asMate, { ...f.mateGrant, pushOrigin: 'team' }))).toBe(TEAM_WRITTEN_WORK)})it('refuses an agent of another project as it refuses one on any task, so the answer says nothing of the mark', () => {@@ -353,11 +304,11 @@ describe('a task a Team agent worked on', () => {expect(code(task)).not.toBe(TEAM_WRITTEN_WORK)})- it('marks the task and not the agent: the same Team agent\'s next task elsewhere starts clean until it is assigned there', () => {+ it('marks the task, not its agents: another task starts clean', () => {const f = swarm(), task = f.written(), clean = f.group()expect(f.state.conversations.find(c => c.id === task)!.teamWritten).toBe(true)expect(f.state.conversations.find(c => c.id === clean)!.teamWritten).toBeUndefined()- expect(refusal(() => f.run({ type: 'work.assign', conversationId: clean, agentId: f.member('main-builder', 'mac') }))).toBeNull()+ expect(refusal(() => f.run({ type: 'work.assign', conversationId: clean, agentId: f.mates('mates-builder') }))).toBeNull()})it('keeps the coordinator on a marked task, and it marks nothing when it runs in a Team account', () => {@@ -372,8 +323,9 @@ describe('a task a Team agent worked on', () => {// #3304: a mark set by a join before this change clears once GitHub reads every pull request the task records as clean.describe('a clean read from GitHub', () => {const P = 'https://github.com/acme/app/pull/7', Q = 'https://github.com/acme/app/pull/8'+ /** A teammate's agent assigned to [step] after a clean read of [pushOriginPulls]: what a mark refuses. */const assignMain = (f: ReturnType<typeof swarm>, step: string, pushOriginPulls: string[]) =>- refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: f.member(`main-${step}-${pushOriginPulls.length}`, 'mac') }, owner, { pushOrigin: 'clean', pushOriginPulls }))+ refusal(() => f.run({ type: 'work.assign', conversationId: step, agentId: f.mates(`mates-${step}-${pushOriginPulls.length}`) }, owner, { pushOrigin: 'clean', pushOriginPulls }))/** A task marked as a join marked it before #3304: no cause, a step opened after it holding a copy. */const joinMarked = (f: ReturnType<typeof swarm>, recorded: string[]) => {const task = f.group(), stored = f.state.conversations.find(c => c.id === task)!diff --git a/backend/src/superTabs/teamWritten.ts b/backend/src/superTabs/teamWritten.tsindex 65a602070..b66c3c2aa 100644--- a/backend/src/superTabs/teamWritten.ts+++ b/backend/src/superTabs/teamWritten.ts@@ -14,13 +14,13 @@ import { codePullRequests, fail, type Agent, type Conversation, type SuperTabStaimport { groupProject, ledProject, onTeamAccount, teamAccountPool } from './projects.js'export const TEAM_WRITTEN_WORK = 'TEAM_WRITTEN_WORK'-export const TEAM_WRITTEN_REASON = 'A Harness Team agent wrote this task\'s code, so it runs only in a Team account, never in the main account. Choose an agent or machine in a Team account.'+export const TEAM_WRITTEN_REASON = 'A Harness Team agent wrote this task\'s code, so only the project owner\'s own agent, on their own computer, may run it.'const coordinates = (state: SuperTabState, group: Conversation, worker: Agent): boolean =>ledProject(state, worker.id)?.id === groupProject(state, group).id/** Told to an agent in the main account when a task it works on turns out to be Team-written. */-export const TEAM_WRITTEN_STOP = 'Stop: GitHub shows a Harness Team agent pushed to this task\'s branch. Do not install, build, test or run it in the main account. Set this step blocked and hand it to an agent in a Team account.'+export const TEAM_WRITTEN_STOP = 'Stop: GitHub shows a Harness Team agent pushed to this task\'s branch. Do not install, build, test or run it. Set this step blocked: only the project owner\'s own agent may take it.'/** The task a group's code belongs to: its own, or for a step, the task the step belongs to. */const taskOf = (state: SuperTabState, group: Conversation): Conversation | undefined =>@@ -62,13 +62,28 @@ export function requireTeamWrittenAccount(state: SuperTabState, group: Conversatif (barredFromTeamWritten(state, group, worker)) failTeamWritten()}-/** Whether [worker] may not join [group]: an agent outside a Team account, in Team-written code, and not its project's coordinator. */-export const barredFromTeamWritten = (state: SuperTabState, group: Conversation, worker: Agent): boolean =>- !coordinates(state, group, worker) && teamWrittenTask(state, group) && !onTeamAccount(state, worker)+/** Whether [worker] may not join [group], Team-written code: anyone but its project's coordinator, the project owner's own agent+ * outside a Team account (Swarm v3 has none left to take it: task #4120, the PM's ruling), and the Team agent already on it,+ * which keeps what it holds until it is stopped. */+export const barredFromTeamWritten = (state: SuperTabState, group: Conversation, worker: Agent, marked = teamWrittenTask(state, group)): boolean =>+ marked && !coordinates(state, group, worker) && !onTeamAccount(state, worker) && !ownersOwnAgent(state, group, worker)++/** Whether [worker] is [group]'s project owner's own agent, on their own machine: brought by them, on a machine they own, through no+ * machine share and outside a Team account (task #4120, the PM's ruling; security review 2 of #3446). */+export const ownersOwnAgent = (state: SuperTabState, group: Conversation, worker: Agent): boolean => {+ const ownerId = groupProject(state, group).ownerId+ return worker.contributorId === ownerId && worker.machineOwnerId === ownerId && !worker.hostGrant && !onTeamAccount(state, worker)+}++/** Whether [machineId] is [group]'s project owner's own computer: a listed machine they contributed, never a Team account's. */+export function ownersOwnMachine(state: SuperTabState, group: Conversation, machineId: string): boolean {+ const pool = state.machines?.find(m => m.machineId === machineId)+ return !!pool && !teamAccountPool(pool) && pool.contributorId === groupProject(state, group).ownerId+}-/** Refuses a start for Team-written code on a machine outside a Team account. */+/** Refuses a start for Team-written code anywhere but its project owner's own computer (task #4120, the PM's ruling). */export function requireTeamWrittenMachine(state: SuperTabState, group: Conversation, machineId: string): void {- if (teamWrittenTask(state, group) && !teamAccountPool(state.machines?.find(m => m.machineId === machineId))) failTeamWritten()+ if (teamWrittenTask(state, group) && !ownersOwnMachine(state, group, machineId)) failTeamWritten()}export function failTeamWritten(details?: Record<string, unknown>): never {@@ -88,7 +103,8 @@ export function mainAccountMembers(state: SuperTabState, group: Conversation, exreturn [task, ...state.conversations.filter(c => c.reviewOf === task.id)].flatMap(c => {const agentIds = c.agentIds.filter(id => {const member = state.agents.find(a => a.id === id)- if (!member || seen.has(id) || onTeamAccount(state, member) || coordinates(state, group, member)) return false+ // Only those it bars: not a Team agent, the coordinator or the project owner's own agent (barredFromTeamWritten).+ if (!member || seen.has(id) || !barredFromTeamWritten(state, task, member, true)) return falseseen.add(id)return true})@@ -130,5 +146,5 @@ export function applyPushOrigin(state: SuperTabState, group: Conversation, origi/** [reason]: why GitHub cannot show it, when that is known (repositoryReach.ts unknownPushReason). */export function failPushUnknown(reason?: string | null): never {- return fail(TEAM_WRITTEN_WORK, reason ?? 'GitHub could not show who pushed this task\'s code, so it runs only in a Team account for now. Choose an agent in a Team account, or try again in a minute.', 403)+ return fail(TEAM_WRITTEN_WORK, reason ?? 'GitHub could not show who pushed this task\'s code, so only the project owner\'s own agent may run it for now. Try again in a minute.', 403)}diff --git a/docs/plans/2026-11-07-remove-team-accounts-plan.md b/docs/plans/2026-11-07-remove-team-accounts-plan.mdnew file mode 100644index 000000000..ea7ba6542--- /dev/null+++ b/docs/plans/2026-11-07-remove-team-accounts-plan.md@@ -0,0 +1,65 @@+# Swarm v3: remove Team accounts: implementation plan++> Written by the project's Engineer way of working (project instructions, Engineer): plan first, then each task test first,+> the failing test committed before its code. No Execution Handoff.++**Goal:** Team accounts go (task #4120, anh Dee's Swarm v3 spec, 2026-11-07): no new agent ever starts in a Mac's Harness Team+account, nothing routes or hands work to one, and the agents already there finish what they hold. Team agents are stopped only+after the 09:00 VN release is out and verified, with their work pushed first (the stop list is in the pull request). This pull+request merges last of the v3 pull requests.++**Architecture:** one gate per way work arrives, each refusing a Team account's entry (`ContributedMachine.hostMachineId`)+with `TEAM_ACCOUNTS_REMOVED`:++- a start: `machines.ts admitMachineStart`, which every start passes (agent.start, a PM's start through leadHost, a crew+ move through crewKeep, a Buddy start), so none lands on a Team account's entry;+- the move into one: `teamMachineFor`, `teamStartRequest`, `ownAccountTeamEntry` and `movedToTeamAccount` are deleted, so a+ start stays on the machine it names; leadHost no longer offers a Team account first;+- routing: route.record's `candidateRefusal` excludes a candidate on a Team account, new or member, with the reason;+- new work: `work.assign` refuses an agent on a Team account, and the dispatch (`freeCrew`) and step picks+ (`reviewerCandidates`) skip it. Its current work stays with it.++Two calls are the PM's (asked in the task, defaults at 02:00 VN): where a teammate's work runs once no Team account takes it,+and who may take a task whose code a Team agent pushed. Each is its own plan task below, done once answered.++What only reads an existing Team account's entry (its privacy check, its readings, its slots) stays until the last Team agent+is stopped; a follow-up removes it then, with the entries.++**Tech Stack:** TypeScript backend (vitest). **Spec:** task #4120 brief (docs/specs/2026-11-07-swarm-v3.md once #V3-backend+writes it).++## Global Constraints++- Never stop or move a Team agent's current work in this pull request; never read a login or credential.+- Identity is the person's own, never the machine owner's.+- Owns backend/src/superTabs/.++## Design++- growth: N/A because nothing new is stored.+- concurrency: inside each command's own write, as the refusals it sits beside.+- read cost and scale: one check of the loaded machine list per start, route candidate and pick.+- compatibility: a new refusal code; a host from before keeps working, and its Team account's entry simply takes no new work.+ The Team-account code that only reads existing entries is removed with them, after the release.+- migration and rollback: none; revert. No data is changed.+- audience and identity: the server enforces it; nothing runs under a new login.+- failure: each refusal says Team accounts are gone and to start on the person's own computer.+- platforms: backend only.++## Task 1: no new work in a Team account++**Files:** machines.ts, commands.ts, leadStart.ts, dispatch.ts, reviewerPick.ts, teamAccountsRemoved.test.ts (new); the+tests that pin the removed moves (teamRouting, leadStart, ownAccountWork, teamWritten) change with them.++- [ ] Tests: agent.start and a PM's start naming a Team account's entry are refused; a teammate's start on a Mac with a Team+ account is never moved there; route.record excludes a Team-account candidate; work.assign refuses a Team-account agent+ and the dispatch and step picks skip it; its current task stays with it.+- [ ] Watch them fail; code; watch them pass; commit.++## Task 2 (the PM's call 1): where a teammate's work runs++- [ ] Tests and code once answered.++## Task 3 (the PM's call 2): a task a Team agent wrote++- [ ] Tests and code once answered.