Skip to content

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

fix(super-tabs): apply routing rules per project (#1604)

0xken1573ca41f23457
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.ts
index 9091a08dd..1ba1187aa 100644
--- a/backend/src/superTabs/commands.test.ts
+++ b/backend/src/superTabs/commands.test.ts
@@ -1178,7 +1178,7 @@ describe('the owner\'s rules', () => {
it('lets the owner set, list and remove rules, and records who asked', () => {
const f = routed()
const added = f.run(set({ kind: 'forbidModel', model: 'haiku' }))
- expect(f.state.rules).toEqual([{ id: added.result.ruleId, rule: { kind: 'forbidModel', model: 'haiku' }, text: 'No Haiku.', askedBy: 'owner', askedIn: null,
+ expect(f.state.rules).toEqual([{ id: added.result.ruleId, projectId: 'lead', rule: { kind: 'forbidModel', model: 'haiku' }, text: 'No Haiku.', askedBy: 'owner', askedIn: null,
addedBy: 'person:owner', createdAt: new Date(1000).toISOString() }])
expect(added.messages[0]).toMatchObject({ conversationId: 'lead', text: 'Rule added: No Haiku.', source: { kind: 'rule' } })
// Everyone in the Swarm reads the rules with the tab.
@@ -1200,21 +1200,21 @@ describe('the owner\'s rules', () => {
const added = f.run({ ...set({ kind: 'forbidModel', model: 'haiku' }), ...asked } as Command, f.leadActor, ownerSaid)
expect(f.state.rules![0]).toMatchObject({ askedBy: 'owner', askedIn: asked.askedIn, addedBy: `agent:${f.lead}` })
const relay = (messageId: string, context: Partial<CommandContext>) => f.run({ ...set({ kind: 'preferIdle' }), ...quoting(messageId) } as Command, f.leadActor, context)
- expect(() => f.run(set({ kind: 'preferIdle' }), f.leadActor, ownerSaid)).toThrow('quote a chat message the owner wrote')
- expect(() => relay('m2', {})).toThrow('quote a chat message the owner wrote')
+ expect(() => f.run(set({ kind: 'preferIdle' }), f.leadActor, ownerSaid)).toThrow('quote a chat message the project owner wrote')
+ expect(() => relay('m2', {})).toThrow('quote a chat message the project owner wrote')
for (const author of [{ kind: 'person', id: 'peer' }, { kind: 'agent', id: 'owner' }]) {
- expect(() => relay('m2', said({ author }))).toThrow('quote a chat message the owner wrote')
+ expect(() => relay('m2', said({ author }))).toThrow('quote a chat message the project owner wrote')
}
// The owner's own system rows ("Rule added", warnings) and a message older than a day do not count.
- expect(() => relay('m2', said({ source: true }))).toThrow('quote a chat message the owner wrote')
- expect(() => relay('m2', said({ createdAt: 1000 - 24 * 3_600_000 - 1 }))).toThrow('quote a chat message the owner wrote')
+ expect(() => relay('m2', said({ source: true }))).toThrow('quote a chat message the project owner wrote')
+ expect(() => relay('m2', said({ createdAt: 1000 - 24 * 3_600_000 - 1 }))).toThrow('quote a chat message the project owner wrote')
// One message may ask for several rules.
expect(relay('m1', ownerSaid).result.ruleId).toBeTruthy()
expect(relay('m2', said({ createdAt: 1000 - 24 * 3_600_000 })).result.ruleId).toBeTruthy()
- expect(() => f.run({ ...set({ kind: 'preferIdle' }), ...asked } as Command, f.workerActor, ownerSaid)).toThrow('Only the Swarm owner')
+ expect(() => f.run({ ...set({ kind: 'preferIdle' }), ...asked } as Command, f.workerActor, ownerSaid)).toThrow('Only the project owner')
f.invite()
- expect(() => f.run(set({ kind: 'preferIdle' }), peer)).toThrow('Only the Swarm owner')
- expect(() => f.run({ type: 'rule.remove', ruleId: added.result.ruleId as string }, peer)).toThrow('Only the Swarm owner')
+ expect(() => f.run(set({ kind: 'preferIdle' }), peer)).toThrow('Only the project owner')
+ expect(() => f.run({ type: 'rule.remove', ruleId: added.result.ruleId as string }, peer)).toThrow('Only the project owner')
f.run({ type: 'rule.remove', ruleId: added.result.ruleId as string, ...asked }, f.leadActor, ownerSaid)
expect(f.state.rules!.map(r => r.text)).toEqual(['No Haiku.', 'No Haiku.'])
})
@@ -1309,10 +1309,66 @@ describe('the owner\'s rules in a Swarm of projects', () => {
it('refuses another project\'s Lead, a worker, a collaborator, a system row and an old message', () => {
const f = projects()
expect(() => f.run(machines(f.app), f.siteLead, said())).toThrow('unavailable')
- expect(() => f.run(machines(f.app), f.worker, said())).toThrow('Only the Swarm owner')
- expect(() => f.run(machines(f.app), peer, said({ author: { kind: 'person', id: 'peer' } }))).toThrow('Only the Swarm owner')
- expect(() => f.run(machines(f.app), f.lead, said({ source: true }))).toThrow('quote a chat message the owner wrote')
- expect(() => f.run(machines(f.app), f.lead, said({ createdAt: 1000 - 24 * 3_600_000 - 1 }))).toThrow('quote a chat message the owner wrote')
+ expect(() => f.run(machines(f.app), f.worker, said())).toThrow('Only the project owner')
+ expect(() => f.run(machines(f.app), peer, said({ author: { kind: 'person', id: 'peer' } }))).toThrow('Only the project owner')
+ expect(() => f.run(machines(f.app), f.lead, said({ source: true }))).toThrow('quote a chat message the project owner wrote')
+ expect(() => f.run(machines(f.app), f.lead, said({ createdAt: 1000 - 24 * 3_600_000 - 1 }))).toThrow('quote a chat message the project owner wrote')
+ expect(f.state).not.toHaveProperty('rules')
+ })
+ const projectIdOf = (f: ReturnType<typeof projects>, conversationId: string) => f.state.conversations.find(c => c.id === conversationId)!.projectId!
+ const forbid = (projectId: string, model: string) => ({ type: 'rule.set', projectId, rule: { kind: 'forbidModel', model }, text: `No ${model}.` }) as Command
+
+ it('applies a project\'s rules only to that project\'s groups', () => {
+ // 2026-10-23: one project's rules (three machines, no Haiku, high effort) refused every other project's Lead.
+ const f = projects(), app = projectIdOf(f, f.app)
+ f.run(forbid(app, 'sonnet')); f.run(forbid(app, 'test-model'))
+ expect(f.state.rules!.map(r => r.projectId)).toEqual([app, app])
+ const route = (conversationId: string, actor: Actor) => f.run({ type: 'route.record', conversationId, decision: record({ pick: 'c1' }) } as Command, actor, { recentRoutes: 0 })
+ expect(route(f.site, f.siteLead).result.routeDecisionId).toBeTruthy()
+ expect(() => route(f.app, f.lead)).toThrow('The owner\'s rule "No sonnet." rules out Claude sonnet.')
+ const siteWorker = f.add('site-worker', 'owner', f.site)
+ const assign = (conversationId: string, agentId: string) => {
+ f.run({ type: 'work.define', conversationId, brief: 'Build it.', checks: [{ description: 'Tests pass.', independent: false }] })
+ return f.run({ type: 'work.assign', conversationId, agentId })
+ }
+ expect(assign(f.site, siteWorker).result.warnings).toBeUndefined()
+ expect(assign(f.app, f.worker.kind === 'agent' ? f.worker.agentId : '').result.warnings).toEqual(['The owner\'s rule "No test-model." rules out Codex test-model.'])
+ })
+ it('keeps one machines list and the rule limit per project', () => {
+ const f = projects(), app = projectIdOf(f, f.app), site = projectIdOf(f, f.site)
+ const machinesIn = (projectId: string, machineId: string) => f.run({ type: 'rule.set', projectId, rule: { kind: 'machines', machineIds: [machineId] }, text: `Only ${machineId}.` } as Command)
+ machinesIn(app, 'm1'); machinesIn(site, 'm2'); machinesIn(app, 'm3')
+ expect(f.state.rules!.map(r => [r.projectId, r.text])).toEqual([[site, 'Only m2.'], [app, 'Only m3.']])
+ for (let i = 0; i < 49; i++) f.run({ type: 'rule.set', projectId: app, rule: { kind: 'preferIdle' }, text: `Rule ${i}.` } as Command)
+ expect(() => f.run(forbid(app, 'haiku'))).toThrow('50 rules')
+ expect(f.run(forbid(site, 'haiku')).result.ruleId).toBeTruthy()
+ })
+ it('moves Swarm-level rules to the project they were asked in, else to the Lead chat\'s project', () => {
+ const f = projects(), app = projectIdOf(f, f.app), site = projectIdOf(f, f.site)
+ const old = (id: string, askedIn: { conversationId: string; messageId: string } | null) =>
+ ({ id, rule: { kind: 'preferIdle' } as const, text: id, askedBy: 'owner', askedIn, addedBy: 'person:owner', createdAt: '' })
+ f.state.rules = [old('site', { conversationId: f.site, messageId: 'm1' }), old('direct', null), old('gone', { conversationId: 'deleted', messageId: 'm2' })]
+ expect(visibleState(f.state, owner).rules!.map(r => r.projectId)).toEqual([site, app, app])
+ f.run({ type: 'project.cadence', projectId: app, minutes: 1 })
+ expect(f.state.rules!.map(r => r.projectId)).toEqual([site, app, app])
+ f.run({ type: 'project.delete', projectId: site })
+ expect(f.state.rules!.map(r => r.id)).toEqual(['direct', 'gone'])
+ })
+ it('lets the project owner set its rules directly, and refuses the Swarm owner and Leads for another person\'s project', () => {
+ const f = projects()
+ const mine = f.run({ type: 'project.create', name: 'Peer', visibility: 'private', brief: '' }, peer).result as { projectId: string; conversationId: string }
+ const added = f.run(forbid(mine.projectId, 'haiku'), peer)
+ expect(added.messages).toEqual([expect.objectContaining({ conversationId: mine.conversationId, text: 'Rule added: No haiku.', source: { kind: 'rule' } })])
+ expect(f.state.rules![0]).toMatchObject({ projectId: mine.projectId, askedBy: 'peer', askedIn: null, addedBy: 'person:peer' })
+ expect(visibleState(f.state, owner).rules).toEqual([])
+ expect(() => f.run(forbid(mine.projectId, 'opus'))).toThrow('unavailable')
+ f.run({ type: 'project.sharing', projectId: mine.projectId, visibility: 'public', memberIds: [] }, peer)
+ expect(() => f.run(forbid(mine.projectId, 'opus'))).toThrow('Only the project owner')
+ expect(() => f.run({ type: 'rule.remove', ruleId: added.result.ruleId as string })).toThrow('Only the project owner')
+ expect(() => f.run({ ...forbid(projectIdOf(f, f.app), 'opus'), projectId: undefined, askedIn: { conversationId: f.app, messageId: 'm1' } } as Command,
+ f.lead, said({ author: { kind: 'person', id: 'peer' } }))).toThrow('quote a chat message the project owner wrote')
+ expect(() => f.run({ ...forbid(projectIdOf(f, f.site), 'opus'), askedIn: { conversationId: f.app, messageId: 'm1' } } as Command, f.lead, said())).toThrow('unavailable')
+ f.run({ type: 'rule.remove', ruleId: added.result.ruleId as string }, peer)
expect(f.state).not.toHaveProperty('rules')
})
it('tells each project\'s Lead chat which of its starts were abandoned when the machine joins', () => {
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 6f6b9f80e..b9cf3fde4 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -10,7 +10,7 @@ import { routeRecordSchema, routeTitle, startedAs, type RouteCandidate, type Rou
import { routingOverrideSchema } from './routingPolicy.js'
import { agentTarget, askedInSchema, broken, MAX_RULES, RULE_MESSAGE_MS, ruleSchema, ruleTextSchema, startTarget, type RunTarget } from './rules.js'
import { MAX_ATTACHMENTS, type Attachment } from './attachments.js'
-import { agentProjectId, deleteProject, groupProject, inviteLanding, manageProject, mutableProjects, projectMembers, projectOf, readAgent, readConversation, readProject, sameProject } from './projects.js'
+import { agentProjectId, deleteProject, groupProject, inviteLanding, manageProject, mutableProjects, placeRules, projectMembers, projectOf, projectRules, readAgent, readConversation, readProject, sameProject, type SwarmProject } from './projects.js'
const id = z.string().min(1).max(160).regex(/^[A-Za-z0-9_-]+$/)
const title = z.string().trim().min(1).max(160)
@@ -59,8 +59,8 @@ export const commandSchema = z.discriminatedUnion('type', [
z.object({ type: z.literal('tab.project'), machineId: id, project }).strict(),
z.object({ type: z.literal('tab.pause'), paused: z.boolean() }).strict(),
z.object({ type: z.literal('tab.routingPolicy'), policy: routingOverrideSchema.nullable() }).strict(),
- z.object({ type: z.literal('rule.set'), rule: ruleSchema, text: ruleTextSchema, askedIn: askedInSchema.optional() }).strict(),
- z.object({ type: z.literal('rule.remove'), ruleId: id, askedIn: askedInSchema.optional() }).strict(),
+ z.object({ type: z.literal('rule.set'), projectId: id.optional(), rule: ruleSchema, text: ruleTextSchema, askedIn: askedInSchema.optional() }).strict(),
+ z.object({ type: z.literal('rule.remove'), projectId: id.optional(), ruleId: id, askedIn: askedInSchema.optional() }).strict(),
z.object({ type: z.literal('project.create'), name: title, visibility: z.enum(['public', 'private']), brief: z.string().trim().max(8000).default('') }).strict(),
z.object({ type: z.literal('project.rename'), projectId: id, name: title }).strict(),
z.object({ type: z.literal('project.delete'), projectId: id }).strict(),
@@ -210,6 +210,7 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
const command = commandSchema.parse(input)
const state = structuredClone(original)
numberConversations(state)
+ placeRules(state)
assignAgentDisplayNames(state.agents)
const result: Record<string, unknown> = {}
const effects: CommandEffects = { state, messages: [], cancelledAgents: [], previousAttempts: [], routeDecisions: [], result }
@@ -254,29 +255,35 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
const who = sender.kind === 'person' ? sender.name.split('@')[0]! : sender.name
/** A hard rule refuses an agent, unless it carries out what a person chose by hand. A person is not blocked: the
* command goes through and the group is told. */
+ const groupRules = (conversationId: string) => projectRules(state, groupProject(state, conversation(state, conversationId)).id)
const ruled = (target: RunTarget, conversationId: string, done: string, personChose = false) => {
- const why = broken(state.rules, target)
+ const why = broken(groupRules(conversationId), target)
if (!why) return
if (actor.kind === 'agent' && !personChose) fail('RULE_BROKEN', `${why} Route again.`, 403)
result.warnings = [why]
effects.messages.push({ id: stableId(operationId, 'rule'), conversationId, author: sender, text: `${done} anyway. ${why}`, replyTo: null, recipients: [], source: RULE_ROW })
}
- /** Only the owner changes rules, or the Lead of the quoted chat's project quoting a message the owner wrote there in the
- * last day (review of #1586: any owner row, a rule row included, could otherwise be quoted at any time). One message may
- * ask for several rules. Returns the Lead chat that hears the change: the quoted project's, else a remaining one. A Swarm
- * of projects has no 'lead' chat; on backend v1.3.14 looking for it refused every Lead's rule. */
- const ruleChange = (askedIn: { conversationId: string; messageId: string } | undefined): string | null => {
- const leadChat = askedIn ? groupProject(state, conversation(state, askedIn.conversationId)).leadConversationId : inviteLanding(state)
- if (actor.kind === 'person' && actor.userId === state.ownerId) return leadChat
- if (actor.kind !== 'agent' || !leadChat || conversation(state, leadChat).leadId !== actor.agentId) {
- fail('OWNER_REQUIRED', 'Only the Swarm owner, or the Lead passing on the owner\'s request, changes rules.', 403)
+ /** Rules are per project. Only its owner changes them, or its Lead quoting a message the project owner wrote in its chat in
+ * the last day (review of #1586: any owner row, a rule row included, could otherwise be quoted at any time). One message
+ * may ask for several rules. The project is the one named, else the quoted chat's, else the actor's: the person's remaining
+ * Lead chat (a Swarm of projects has no 'lead' chat; on backend v1.3.14 looking for it refused every Lead's rule) or the
+ * agent's own project. */
+ const ruleChange = (askedIn: { conversationId: string; messageId: string } | undefined, projectId?: string): SwarmProject => {
+ const quoted = askedIn && groupProject(state, conversation(state, askedIn.conversationId))
+ const landing = actor.kind === 'agent' ? agentProjectId(state, agent(state, actor.agentId)) : inviteLanding(state)
+ const project = projectId ? projectOf(state, projectId) : quoted ? quoted
+ : actor.kind === 'agent' ? projectOf(state, landing!) : landing ? groupProject(state, conversation(state, landing)) : fail('NOT_FOUND', 'This Swarm has no project.', 404)
+ readProject(state, actor, project.id)
+ if (actor.kind === 'person' && actor.userId === project.ownerId) return project
+ if (actor.kind !== 'agent' || conversation(state, project.leadConversationId).leadId !== actor.agentId) {
+ fail('OWNER_REQUIRED', 'Only the project owner, or its Lead passing on the owner\'s request, changes its rules.', 403)
}
const asked = askedIn && context.askedIn
- if (!asked || asked.author.kind !== 'person' || asked.author.id !== state.ownerId || asked.source
+ if (!asked || quoted!.id !== project.id || asked.author.kind !== 'person' || asked.author.id !== project.ownerId || asked.source
|| context.now - asked.createdAt > RULE_MESSAGE_MS) {
- fail('OWNER_MESSAGE_REQUIRED', 'Only the Swarm owner sets rules; quote a chat message the owner wrote in the last day asking for this change.', 403)
+ fail('OWNER_MESSAGE_REQUIRED', 'Only the project owner sets its rules; quote a chat message the project owner wrote in its chat in the last day asking for this change.', 403)
}
- return leadChat
+ return project
}
const openDecision = (): RouteDecision => {
const decision = context.routeDecision ?? fail('NOT_FOUND', 'This routing decision is unavailable.', 404)
@@ -438,22 +445,23 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
else delete state.routingPolicy
break
case 'rule.set': {
- const leadChat = ruleChange(command.askedIn)
- // There is one machines list; a new one replaces it.
- const rules = (state.rules ?? []).filter(r => command.rule.kind !== 'machines' || r.rule.kind !== 'machines')
- if (rules.length >= MAX_RULES) fail('RULES_FULL', `This Swarm has ${MAX_RULES} rules. Remove one first.`)
- state.rules = [...rules, { id: operationId, rule: command.rule, text: command.text, askedBy: state.ownerId,
+ const project = ruleChange(command.askedIn, command.projectId)
+ // A project has one machines list; a new one replaces it.
+ const rules = (state.rules ?? []).filter(r => r.projectId !== project.id || command.rule.kind !== 'machines' || r.rule.kind !== 'machines')
+ if (rules.filter(r => r.projectId === project.id).length >= MAX_RULES) fail('RULES_FULL', `This project has ${MAX_RULES} rules. Remove one first.`)
+ state.rules = [...rules, { id: operationId, projectId: project.id, rule: command.rule, text: command.text, askedBy: project.ownerId,
askedIn: command.askedIn ?? null, addedBy: actorKey(actor), createdAt: new Date(context.now).toISOString() }]
result.ruleId = operationId
- if (leadChat) message(leadChat, `Rule added: ${command.text}`, [], null, RULE_ROW)
+ message(project.leadConversationId, `Rule added: ${command.text}`, [], null, RULE_ROW)
break
}
case 'rule.remove': {
- const leadChat = ruleChange(command.askedIn)
- const rule = state.rules?.find(r => r.id === command.ruleId) ?? fail('NOT_FOUND', 'This Swarm has no such rule.', 404)
+ const found = state.rules?.find(r => r.id === command.ruleId)
+ const project = ruleChange(command.askedIn, command.projectId ?? found?.projectId)
+ const rule = found?.projectId === project.id ? found : fail('NOT_FOUND', 'This project has no such rule.', 404)
state.rules = state.rules!.filter(r => r.id !== rule.id)
if (!state.rules.length) delete state.rules
- if (leadChat) message(leadChat, `Rule removed: ${rule.text}`, [], null, RULE_ROW)
+ message(project.leadConversationId, `Rule removed: ${rule.text}`, [], null, RULE_ROW)
break
}
case 'conversation.create': {
@@ -591,7 +599,7 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
if (command.type === 'agent.startDispatch') {
if (state.paused) fail('PAUSED', 'New work is paused in this Super Tab.')
// A start recorded before a rule was added is not launched past it, unless a person asked for it by hand.
- const why = actor.kind === 'agent' && !(start.routeDecisionId && context.routeDecision?.override?.by === 'person') && broken(state.rules, startTarget(start.request))
+ const why = actor.kind === 'agent' && !(start.routeDecisionId && context.routeDecision?.override?.by === 'person') && broken(groupRules(start.request.conversationId), startTarget(start.request))
if (why) fail('RULE_BROKEN', `${why} This start was not launched. Route again.`, 403)
requireWorkerDecisions(state, actor, open(state, start.request.conversationId))
const grant = context.contribution ?? fail('HOST_REQUIRED', 'The original machine grant is unavailable.', 403)
diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.ts
index f089a58d9..8f2724bd0 100644
--- a/backend/src/superTabs/model.ts
+++ b/backend/src/superTabs/model.ts
@@ -1,7 +1,7 @@
import { createHash } from 'node:crypto'
import type { RouteDecisionEffect } from './routeRecord.js'
import { agentDisplayName, assignAgentDisplayNames } from './agentNames.js'
-import { canReadAgent, canReadProject, groupProject, projectsOf, type ProjectVisibility, type SwarmProject } from './projects.js'
+import { canReadAgent, canReadProject, groupProject, placeRules, projectsOf, type ProjectVisibility, type SwarmProject } from './projects.js'
export type Role = 'owner' | 'collaborator' | 'viewer'
export interface Person { id: string; email: string; role: Role; generation: string }
@@ -278,6 +278,8 @@ export function visibleState(state: SuperTabState, actor: Actor): SuperTabState
delete visible.releasedHarnesses
numberConversations(visible)
delete visible.retiredConversationNumber
+ placeRules(visible)
+ if (visible.rules) visible.rules = visible.rules.filter(r => projectsOf(state).some(p => p.id === r.projectId && canReadProject(state, actor, p)))
if (visible.projects) {
visible.projects = visible.projects.filter(p => canReadProject(state, actor, p))
visible.conversations = visible.conversations.filter(c => canReadProject(state, actor, groupProject(state, c)))
diff --git a/backend/src/superTabs/projects.ts b/backend/src/superTabs/projects.ts
index 6a5280b85..9613657e8 100644
--- a/backend/src/superTabs/projects.ts
+++ b/backend/src/superTabs/projects.ts
@@ -1,4 +1,5 @@
import { activeWork, agent, author, conversation, fail, nextConversationNumber, person, type Actor, type Agent, type Conversation, type SuperTabState } from './model.js'
+import type { SwarmRule } from './rules.js'
export type ProjectVisibility = 'public' | 'private'
export interface SwarmProject {
@@ -110,6 +111,8 @@ export function deleteProject(state: SuperTabState, actor: Actor, projectId: str
if (groups.some(activeWork)) fail('WORK_ACTIVE', 'Resolve this project’s active work before deleting it.')
state.retiredConversationNumber = nextConversationNumber(state) - 1
state.projects = state.projects!.filter(p => p.id !== project.id)
+ state.rules = state.rules?.filter(r => r.projectId !== project.id)
+ if (!state.rules?.length) delete state.rules
state.conversations = state.conversations.filter(c => !groupIds.has(c.id))
state.starts = state.starts?.filter(s => !groupIds.has(s.request.conversationId))
// A pending invitation is to the Swarm, not to this project: it lands somewhere that is left instead.
@@ -121,6 +124,21 @@ export function deleteProject(state: SuperTabState, actor: Actor, projectId: str
}
}
+/** Rules were the Swarm's until 2026-10-23, when one project's rules refused every other project's Lead. A rule from then
+ * belongs to the project whose chat it was asked in, else to the project of a remaining Lead chat (inviteLanding). */
+export function placeRules(state: SuperTabState): void {
+ for (const rule of state.rules ?? []) {
+ if (rule.projectId) continue
+ const asked = rule.askedIn && state.conversations.find(c => c.id === rule.askedIn!.conversationId)
+ const landing = state.conversations.find(c => c.id === inviteLanding(state))
+ rule.projectId = asked ? groupProject(state, asked).id : landing ? groupProject(state, landing).id : 'lead'
+ }
+}
+
+export function projectRules(state: SuperTabState, projectId: string): SwarmRule[] {
+ return (state.rules ?? []).filter(r => r.projectId === projectId)
+}
+
/** Where an invited person lands: the asked-for group while it exists, else a remaining project's Lead
* conversation, public first. Desktop asks for the original 'lead' group, which is gone once its project is
* deleted; on 2026-10-22 that refused every invitation with "This conversation is unavailable". */
diff --git a/backend/src/superTabs/rules.ts b/backend/src/superTabs/rules.ts
index 6378c6bfd..c3f2d62a6 100644
--- a/backend/src/superTabs/rules.ts
+++ b/backend/src/superTabs/rules.ts
@@ -17,12 +17,15 @@ export const ruleSchema = z.discriminatedUnion('kind', [
])
export const ruleTextSchema = z.string().trim().min(1).max(200)
export const askedInSchema = z.object({ conversationId: id, messageId: id }).strict()
+/** Per project. */
export const MAX_RULES = 50
/** How long an owner's message can back the rule changes the Lead passes on. */
export const RULE_MESSAGE_MS = 24 * 3_600_000
export interface SwarmRule {
id: string
+ /** The project whose agents the rule binds. Absent only on a rule from before rules were per project, until placeRules. */
+ projectId?: string
rule: z.infer<typeof ruleSchema>
/** The owner's words, shown when the rules are listed and quoted when one refuses. */
text: string
diff --git a/cli/src/superTabs/routeCommand.spec.ts b/cli/src/superTabs/routeCommand.spec.ts
index 4eec3fd69..03355c979 100644
--- a/cli/src/superTabs/routeCommand.spec.ts
+++ b/cli/src/superTabs/routeCommand.spec.ts
@@ -103,6 +103,17 @@ describe('routeTask', () => {
expect(decision.candidates.every((c: { model: string }) => c.model === 'opus')).toBe(true)
expect(decision.excluded).toEqual(expect.arrayContaining([{ title: 'Multiply · Claude sonnet medium · remote-1', reason: 'Breaks the owner\'s rule: No Sonnet.' }]))
})
+ it('applies only the rules of the group\'s project', async () => {
+ // 2026-10-23: one project's rules (three machines, no Haiku, high effort) left every other project's Lead without candidates.
+ const models = async (projectId: string) => {
+ const ruled = tab(); (ruled.state as Record<string, unknown>).rules = [{ id: 'r1', projectId, rule: { kind: 'forbidModel', model: 'sonnet' }, text: 'No Sonnet.' }]
+ const s = scoped({ tab: ruled })
+ await routeTask(input, s, where as never, opener(), () => 'op')
+ return new Set(recorded(s).command.decision.candidates.map((c: { model: string }) => c.model))
+ }
+ expect(await models('other')).toContain('sonnet')
+ expect(await models('lead')).not.toContain('sonnet')
+ })
it('offers a Reviewer only for a review group, and starts a new one as a Reviewer', async () => {
const offered = async (reviewer: boolean, reviewGroup: boolean) => {
const t = tab(); t.state.agents = agents.map(a => a.id === 'a1' && reviewer ? { ...a, role: 'reviewer' } : a)
diff --git a/cli/src/superTabs/routeCommand.ts b/cli/src/superTabs/routeCommand.ts
index 34b909680..f9584c089 100644
--- a/cli/src/superTabs/routeCommand.ts
+++ b/cli/src/superTabs/routeCommand.ts
@@ -129,8 +129,9 @@ export async function routeTask(input: { tabId: string; conversationId: string;
// A review group is assigned only to a Reviewer, and a Reviewer nothing else.
const review = typeof group.reviewOf === 'string'
if (review) assessment = { ...assessment, kind: 'review' }
- // A backend from before rules keeps none, so routing there is the policy order alone.
- const rules = list(state.rules).filter(r => r.rule && typeof r.text === 'string') as unknown as SwarmRule[]
+ // A backend from before rules keeps none, so routing there is the policy order alone. Rules bind only their own project's
+ // groups; a backend from before per-project rules gives none a project, and its rules bind every group.
+ const rules = list(state.rules).filter(r => r.rule && typeof r.text === 'string' && (r.projectId === undefined || r.projectId === projectId)) as unknown as SwarmRule[]
const members = agents.filter(a => !busy.has(String(a.id)) && (a.role === 'reviewer') === review && ENGINES.includes(String(object(a.configuration).engine))).map(a => withLaunchEffort(a, list(state.starts)))
// A new agent starts only on a machine in the Swarm's Machines list (the backend refuses any other): a contributed machine, or
// one an agent of the Swarm runs on. The Lead runs here, so its own machine is always listed. Of the account's machines
diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.ts
index dc056f536..d51155651 100644
--- a/cli/src/superTabs/service.ts
+++ b/cli/src/superTabs/service.ts
@@ -12,7 +12,7 @@ import { messageIdOf } from './attach.js'
import { cardId, SwarmCards } from './cards.js'
const HELP = {
- status: 'Read the shared tab roster and work. Its rules are the owner\'s routing rules, each in the owner\'s own words.',
+ status: 'Read the shared tab roster and work. Its rules are the project owners\' routing rules, each in the owner\'s own words; each binds only the agents of its projectId.',
messages: 'messages GROUP: read recent messages in a conversation.',
message: 'message GROUP MESSAGE_ID: read one exact message, including an earlier question or result referenced by a reply.',
post: 'post GROUP TEXT OPERATION_ID [--reply-to MESSAGE_ID] [--attach PATH]...: reply in that conversation. Use a unique ID per message and reuse it after an interrupted request. Answer a message once, with --reply-to its ID. --attach sends a file (a screenshot, a log; up to 10 files of 10 MB each), and TEXT may then be empty.',
@@ -23,7 +23,7 @@ const HELP = {
capacity: 'capacity MACHINE_ID JSON: inspect machine, engine and quota headroom. JSON uses the start request fields below. Unknown allowances are not reported as free tokens.',
startRequest: { conversationId: 'GROUP', machineId: 'MACHINE', engine: 'codex', name: 'Builder', cwd: '/absolute/repo/on/that/machine', worktree: true, branchRef: 'refs/remotes/origin/BASE_BRANCH', requirements: START_REQUIREMENTS,
model: 'opus', effort: 'high', routeDecisionId: 'DECISION' },
- command: 'command OPERATION_ID JSON: send one of the commands below. Reuse exactly the same ID and JSON after an interrupted request. When your assignment needs a person to decide, set work.status needs_human; when you cannot go on, blocked. Set working again once it moves. rule.set and rule.remove change the owner\'s routing rules: only the owner does, or the Lead passing on the owner\'s request, with askedIn naming the owner\'s message. A start, assignment or route that breaks a hard rule (forbidModel, machines, minEffort) is refused for agents; preferEngine and preferIdle only rank.',
+ command: 'command OPERATION_ID JSON: send one of the commands below. Reuse exactly the same ID and JSON after an interrupted request. When your assignment needs a person to decide, set work.status needs_human; when you cannot go on, blocked. Set working again once it moves. rule.set and rule.remove change one project\'s routing rules: only the project owner does (naming projectId), or that project\'s Lead passing on the project owner\'s request, with askedIn naming the project owner\'s message in that project\'s chat. A start, assignment or route that breaks a hard rule (forbidModel, machines, minEffort) is refused for agents; preferEngine and preferIdle only rank.',
commands: [
{ type: 'project.report', projectId: 'PROJECT', throughRevision: 123, text: 'What changed, what is blocked, and what comes next. Use null when nothing merits repeating.' },
{ type: 'project.repository', projectId: 'PROJECT', repositoryUrl: 'https://github.com/OWNER/REPOSITORY' },