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.

Backend hotfix: only the person and their own agent post in their private chat (#4558) (#3555)

0xken15c1b6a9f933b3
diff --git a/backend/integration/overdueDecisions.test.ts b/backend/integration/overdueDecisions.test.ts
index ef8f268f9..0804b7494 100644
--- a/backend/integration/overdueDecisions.test.ts
+++ b/backend/integration/overdueDecisions.test.ts
@@ -4,7 +4,7 @@ import type { MongoMemoryReplSet } from 'mongodb-memory-server-core'
import type { PrismaClient } from '@prisma/client'
import type { AuthUser } from '../src/lib/ssoAuth.js'
import { SuperTabStore } from '../src/superTabs/store.js'
-import type { Command } from '../src/superTabs/commands.js'
+import { commandSchema, type Command } from '../src/superTabs/commands.js'
import { overdueNotice } from '../src/superTabs/decisions.js'
import { OVERDUE_DECISION_MS, overdueDecisions, dueDefaultDecisions } from '../src/superTabs/overdueDecisions.js'
import { planDatabase, plan, profiled, reads } from './plans.test-support.js'
@@ -299,6 +299,14 @@ describe('a switched project’s direct asks at their default time', () => {
it('notifies the default Buddy only once when decision.ask repeats an open question', async () => {
const f = await direct()
+ // peer's own Buddy, on peer's Mac: it writes the line, as only peer and their own agent post in their private chat (task #4558).
+ await db.machine.create({ data: { machineId: 'peer-mac', userId: peer.sub, apiKey: `fixture-${randomUUID()}`, managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })
+ const added = await f.execute({ type: 'buddy.create', machineId: 'peer-mac', engine: 'claude', setup: { name: 'Peer Mac', cwd: '/peer', engines: ['claude'] } }, peer)
+ const startId = String(added.result.startId)
+ const host = (command: unknown) => f.store.execute(peer, f.tab, { operationId: randomUUID(), command: commandSchema.parse(command) }, undefined, 'peer-mac')
+ await host({ type: 'agent.startDispatch', startId })
+ await host({ type: 'agent.started', startId, harnessId: randomUUID(), configuration: config })
+ await host({ type: 'agent.startSettled', startId, warning: null })
const chat = String((await f.execute({ type: 'buddy.chat' }, peer)).result.conversationId)
const command: Command = { type: 'decision.ask', conversationId: f.task, personId: peer.sub,
questions: [{ question: 'Ship this copy?', options: ['Yes', 'No'], recommended: 0, unblocks: 'Release', defaultAt: at(HOUR) }] }
diff --git a/backend/integration/superTabBuddies.test.ts b/backend/integration/superTabBuddies.test.ts
index a2bfc9713..9ecc8d86b 100644
--- a/backend/integration/superTabBuddies.test.ts
+++ b/backend/integration/superTabBuddies.test.ts
@@ -706,65 +706,41 @@ describe('a Buddy matching agents to people (delta review 1 of #2258)', () => {
})
})
-describe('a person\'s Buddy chat before any Buddy, and the PM\'s private lines (Ken, 10-29)', () => {
+// Only the person and their own agent post in their private chat (anh Dee, 11-07, task #4558): the PM's private line, which
+// opened a person's Buddy chat before any Buddy (Ken, 10-29), is refused, and opens no chat.
+describe('a PM\'s private line to a person (task #4558)', () => {
const tell = (text: string) => ({ type: 'person.tell' as const, personId: peer.sub, text })
+ const chats = async (tab: string) => (await db.swarmGroup.findMany({ where: { tabId: tab, deleted: false } }))
+ .filter(row => ['buddy', 'swarm-buddy'].includes(String((row.data as { kind?: string }).kind))).map(row => row.key)
- it('opens on the person\'s ask and takes the PM\'s line, which they read and the PM cannot', async () => {
+ it('is refused, naming where to post instead, writes nothing in the person\'s chat, and the PM still cannot read it', async () => {
const f = await swarm()
const chat = String((await f.execute({ type: 'buddy.chat', projectId: 'lead' }, peer)).result.conversationId)
- await f.execute(tell('Your fix is merged.'), owner, f.lead)
- expect((await f.store.messages(peer, f.tab, chat, {})).messages.map(m => m.text)).toEqual(['Your fix is merged.'])
+ await expect(f.execute(tell('Your fix is merged.'), owner, f.lead)).rejects.toMatchObject({ code: 'PRIVATE_CHAT', message: expect.stringContaining('project chat') })
+ expect(await db.superTabMessage.count({ where: { tabId: f.tab, conversationId: chat } })).toBe(0)
await expect(f.store.messages(owner, f.tab, chat, {}, f.lead)).rejects.toThrow('unavailable')
expect(await db.superTabDelivery.count({ where: { tabId: f.tab, conversationId: chat } })).toBe(0)
})
- it('never lands for someone who stops reading the project while the line is sent (security review 2 of #2090)', async () => {
- const f = await swarm()
- const chat = String((await f.execute({ type: 'buddy.chat', projectId: 'lead' }, peer)).result.conversationId)
- // The line reads the Swarm with peer still a reader; just before it writes, the owner makes the project theirs alone.
- let raced = false
- const racing = new SuperTabStore(beforeFirstWrite(db, async () => {
- if (raced) return
- raced = true
- await f.execute({ type: 'project.sharing', projectId: 'lead', visibility: 'private', memberIds: [] })
- }), () => Date.now())
- await expect(racing.execute(owner, f.tab, { operationId: randomUUID(), command: tell('Your fix is merged.') }, f.lead))
- .rejects.toThrow('cannot read this project')
- expect(raced).toBe(true)
- expect(await db.superTabMessage.count({ where: { tabId: f.tab, conversationId: chat } })).toBe(0)
- })
-
- it('is opened for the PM\'s first line, and a quiet one takes the next line rather than a second chat', async () => {
+ it('opens no Buddy chat for the person, and tells the PM first when they cannot read the project', async () => {
const f = await swarm()
- await f.execute(tell('First.'), owner, f.lead)
- const chats = async () => (await db.swarmGroup.findMany({ where: { tabId: f.tab, deleted: false } }))
- .filter(row => (row.data as { kind?: string }).kind === 'buddy').map(row => row.key)
- const [chat] = await chats()
- await db.swarmGroup.updateMany({ where: { tabId: f.tab, key: chat }, data: { dormant: true } })
- await f.execute(tell('Second.'), owner, f.lead)
- expect((await f.execute({ type: 'buddy.chat', projectId: 'lead' }, peer)).result.conversationId).toBe(chat)
- expect(await chats()).toEqual([chat])
- expect((await f.store.messages(peer, f.tab, chat!, {})).messages.map(m => m.text)).toEqual(['First.', 'Second.'])
+ await expect(f.execute(tell('First.'), owner, f.lead)).rejects.toMatchObject({ code: 'PRIVATE_CHAT' })
+ expect(await chats(f.tab)).toEqual([])
+ await f.execute({ type: 'project.sharing', projectId: 'lead', visibility: 'private', memberIds: [] })
+ await expect(f.execute(tell('Second.'), owner, f.lead)).rejects.toThrow('cannot read this project')
+ expect(await chats(f.tab)).toEqual([])
})
- // People talk only to the PM (anh Dee, 11-05; crewNeeds.ts, task #3404): another agent's line is the PM's crew need, and the
- // PM's next line still lands in the quiet chat rather than opening a second one.
- it('takes the PM\'s line in a quiet chat rather than opening a second one, and gives the PM another agent\'s', async () => {
+ // People talk only to the PM (anh Dee, 11-05; crewNeeds.ts, task #3404): another agent's line is the PM's crew need.
+ it('gives the PM another agent\'s line as a crew need, and opens no Buddy chat for it', async () => {
const f = await swarm()
const engineer = String((await f.execute({ type: 'agent.add', conversationId: 'lead', machineId: 'owner-mac', harnessId: randomUUID(), name: 'Engineer',
configuration: config, lead: false })).result.agentId)
- await f.execute(tell('First.'), owner, f.lead)
- const chats = async () => (await db.swarmGroup.findMany({ where: { tabId: f.tab, deleted: false } }))
- .filter(row => (row.data as { kind?: string }).kind === 'buddy').map(row => row.key)
- const [chat] = await chats()
- await db.swarmGroup.updateMany({ where: { tabId: f.tab, key: chat }, data: { dormant: true } })
await f.execute(tell('From the Engineer.'), owner, engineer)
const needs = (await db.superTabMessage.findMany({ where: { tabId: f.tab, conversationId: 'lead' } }))
.filter(m => (m.source as { kind?: string } | null)?.kind === 'crew-need')
expect(needs).toEqual([expect.objectContaining({ recipientIds: [f.lead], source: expect.objectContaining({ crewNeed: expect.objectContaining({ agentId: engineer, personIds: [peer.sub] }) }) })])
- await f.execute(tell('Again.'), owner, f.lead)
- expect(await chats()).toEqual([chat])
- expect((await f.store.messages(peer, f.tab, chat!, {})).messages.map(m => m.text)).toEqual(['First.', 'Again.'])
+ expect(await chats(f.tab)).toEqual([])
})
})
@@ -1396,7 +1372,8 @@ describe('Buddy input and sleep race (#3824)', () => {
describe('a sleeping proposal sender (#3824)', () => {
- it('wakes the card’s original Buddy for a PM question even when another Buddy is the default', async () => {
+ // A PM question shows on the card alone: no notice in any Buddy chat wakes a Buddy for it (task #4558).
+ it('wakes no Buddy for a PM question on the card, and writes nothing in either Buddy chat', async () => {
let now = Date.now()
const f = await swarm(() => now)
await f.execute({ type: 'project.boardMode', projectId: 'lead', on: true })
@@ -1416,11 +1393,12 @@ describe('a sleeping proposal sender (#3824)', () => {
expect((await current(second.main)).asleep).toBeDefined()
await f.execute(commandSchema.parse({ type: 'proposal.ask', conversationId: proposal.result.conversationId, personId: peer.sub,
question: 'How long?', defaultAnswer: 'Seven days', deadline: now + 60_000 }), owner, f.lead)
- expect((await current(first.main)).asleep).toBeUndefined()
+ expect((await current(first.main)).asleep).toBeDefined()
expect((await current(second.main)).asleep).toBeDefined()
- const waiting = (await f.store.deliveries(peer, f.tab, first.main)).find(d => d.conversationId === first.swarmChat)!
- expect(waiting).toBeDefined()
- const claim = await f.store.delivery(peer, f.tab, first.main, waiting.id, { type: 'claim', claimId: randomUUID() })
- expect(claim).toMatchObject({ message: { source: { kind: 'proposal-notice' } } })
+ for (const [agentId, chat] of [[first.main, first.swarmChat], [second.main, second.swarmChat]] as const) {
+ expect((await f.store.deliveries(peer, f.tab, agentId)).filter(d => d.conversationId === chat)).toEqual([])
+ }
+ const rows = await db.superTabMessage.findMany({ where: { tabId: f.tab, conversationId: { in: [first.swarmChat, second.swarmChat] } } })
+ expect(rows.filter(m => (m.source as { kind?: string } | null)?.kind === 'proposal-notice')).toEqual([])
})
})
diff --git a/backend/integration/superTabInstructions.test.ts b/backend/integration/superTabInstructions.test.ts
index 2bbc4c960..444035a66 100644
--- a/backend/integration/superTabInstructions.test.ts
+++ b/backend/integration/superTabInstructions.test.ts
@@ -12,7 +12,7 @@ import { SuperTabStore } from '../src/superTabs/store.js'
import { noteChange, swarmTransaction } from '../src/superTabs/cache.js'
import { superTabRoutes } from '../src/routes/superTabs.js'
import { errorHandler } from '../src/middlewares/errorHandler.js'
-import type { Command } from '../src/superTabs/commands.js'
+import { commandSchema, type Command } from '../src/superTabs/commands.js'
import { appendRouting, FIRST_INSTRUCTIONS, instructionsHash } from '../src/superTabs/instructions.js'
import { stableId } from '../src/superTabs/model.js'
import { roleVersion } from '../src/superTabs/projects.js'
@@ -38,6 +38,18 @@ const host: AuthUser = { sub: '100000000000000000000003', email: '[email protected]
const config = { engine: 'codex', model: 'fixture-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }
const run = (tab: string, command: Command, user = owner, asAgentId?: string) =>
store.execute(user, tab, { operationId: randomUUID(), command }, asAgentId)
+/** [user]'s own Buddy, on a machine of theirs: it writes the server's notices in their private chat, where only they and it post
+ * (task #4558). */
+async function ownBuddy(tab: string, user: AuthUser) {
+ const machineId = `${user.email.split('@')[0]}-mac`
+ await db.machine.upsert({ where: { machineId }, update: {}, create: { machineId, userId: user.sub, apiKey: `fixture-${randomUUID()}`, managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })
+ const added = await run(tab, { type: 'buddy.create', machineId, engine: 'codex', setup: { name: 'Fixture Mac', cwd: '/fixture', engines: ['codex'] } }, user)
+ const startId = String(added.result.startId)
+ const onHost = (command: unknown) => store.execute(user, tab, { operationId: randomUUID(), command: commandSchema.parse(command) }, undefined, machineId)
+ await onHost({ type: 'agent.startDispatch', startId })
+ await onHost({ type: 'agent.started', startId, harnessId: randomUUID(), configuration: config })
+ await onHost({ type: 'agent.startSettled', startId, warning: null })
+}
async function invite(tab: string) {
const invitation = await run(tab, { type: 'invite.create', email: peer.email, role: 'collaborator', conversationId: 'lead' })
await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, peer)
@@ -143,6 +155,7 @@ describe('configured rule approvals through the store', () => {
await invite(tab)
const invitation = await run(tab, { type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })
await run(tab, { type: 'invite.accept', inviteId: String(invitation.result.inviteId) }, host)
+ for (const account of [owner, host, peer]) await ownBuddy(tab, account)
await run(tab, { type: 'rules.set', projectId: 'lead', baseRevision: 0, rules: { ...structuredClone(SEED_RULES),
instructionApprovals: { topDeciderId: peer.sub, people: [{ name: 'Ken', accountIds: [owner.sub, host.sub] }] } }, summary: 'Explicit approval authority' })
const text = '# Rules\n\n- Always test before merging (Ken, 2026-11-04).'
@@ -166,7 +179,8 @@ describe('configured rule approvals through the store', () => {
expect(read.returned).toBe(1)
}
const notices = await db.superTabMessage.findMany({ where: { tabId: tab, text: { contains: 'approved by peer' } } })
- // Dee's approval tells the decider and both affected author accounts, through each person's two private Buddy chats.
+ // Dee's approval tells the decider and both affected author accounts, through each person's two private Buddy chats, each
+ // line written by that person's own Buddy (task #4558).
expect(notices).toHaveLength(6)
for (const account of [owner, host, peer]) {
const visible = new Set((await store.read(account, tab)).state.conversations.map(c => c.id))
@@ -189,6 +203,7 @@ describe('a person\'s rules in a save', () => {
it('refuses the PM\'s drop, then saves it on the person\'s own approval and tells them privately', async () => {
const { tab, lead } = await withLead()
await invite(tab)
+ await ownBuddy(tab, peer)
const rule = 'A bug that reaches stable is promoted back within the hour (peer, 2026-11-04).'
expect((await run(tab, save(1, `# Rules\n\n- ${rule}\n- Tests run first (owner, 4 Nov).`), peer)).result.revision).toBe(2)
const asLead = (approvals?: string[]) => store.execute(host, tab, { operationId: randomUUID(), command: { ...save(2, '# Rules\n\n- Tests run first (owner, 4 Nov).',
diff --git a/backend/integration/superTabLiveness.test.ts b/backend/integration/superTabLiveness.test.ts
index 30ed68e1e..1a73de167 100644
--- a/backend/integration/superTabLiveness.test.ts
+++ b/backend/integration/superTabLiveness.test.ts
@@ -11,7 +11,7 @@ import { SuperTabStore, type Polled, type SuperTabStoreHooks } from '../src/supe
import { SWEEP_EVERY_MS } from '../src/superTabs/liveness.js'
import { DOWN_REMOVE_MS } from '../src/superTabs/closedAgents.js'
import { stableId } from '../src/superTabs/model.js'
-import type { Command } from '../src/superTabs/commands.js'
+import { commandSchema, type Command } from '../src/superTabs/commands.js'
import type { MachineObservation } from '../src/superTabs/machines.js'
import * as parts from '../src/superTabs/parts/index.js'
import { assignmentRows, poolRows, rosterRows } from './hostRows.test-support.js'
@@ -2136,6 +2136,14 @@ describe('the morning digest', () => {
const f = await swarm()
const WORK = 'a'.repeat(16)
const reading = { capabilities: ['leadSwitch'], profiles: [{ engine: 'codex' as const, id: WORK, label: 'Work', leftPercent: 80, resetsAt: null }] }
+ // The machine owner's own Buddy writes the notice: only they and it post in their private chat (task #4558).
+ await f.observe('test-host', [f.harness.worker], { capabilities: ['buddySessions', 'swarmBuddy'] })
+ const added = await f.execute({ type: 'buddy.create', machineId: 'test-host', engine: 'codex' }, host)
+ const startId = String(added.result.startId)
+ const onHost = (command: unknown) => f.timed.execute(host, f.tab, { operationId: randomUUID(), command: commandSchema.parse(command) }, undefined, 'test-host')
+ await onHost({ type: 'agent.startDispatch', startId })
+ const buddyId = String((await onHost({ type: 'agent.started', startId, harnessId: randomUUID(), configuration: config })).result.agentId)
+ await onHost({ type: 'agent.startSettled', startId, warning: null })
await f.observe('lead-host', [f.harness.lead], reading)
const projectId = (await f.timed.read(owner, f.tab)).state.projects![0]!.id
const notices = async () => (await db.superTabMessage.findMany({ where: { tabId: f.tab } })).filter(m => (m.source as { kind?: string } | null)?.kind === 'pm-switch-notice')
@@ -2151,6 +2159,7 @@ describe('the morning digest', () => {
await move(f.harness.lead, 'second-session')
const [first] = await notices()
expect(first!.text).toContain('your Codex account "Work"')
+ expect(first!.author).toMatchObject({ kind: 'agent', id: buddyId })
await db.swarmGroup.update({ where: { id: `${f.tab}:${first!.conversationId}` }, data: { dormant: true } })
await f.observe('lead-host', ['second-session'], reading)
await move('second-session', 'third-session')
diff --git a/backend/integration/superTabProposalCards.test.ts b/backend/integration/superTabProposalCards.test.ts
index 332b139a3..f88ce64c5 100644
--- a/backend/integration/superTabProposalCards.test.ts
+++ b/backend/integration/superTabProposalCards.test.ts
@@ -161,7 +161,7 @@ describe('durable proposal cards', () => {
expect((await db.superTabDelivery.findMany({ where: { tabId: f.tab, messageId: String(partial.result.messageId) } })).map(d => d.agentId)).toEqual([worker])
})
- it('delivers a decided notice inside the sending person’s private Buddy chat', async () => {
+ it('writes no decided notice in the sending person’s private Buddy chat, nor delivers one to their Buddy (task #4558)', async () => {
const f = await fixture()
const added = await f.execute({ type: 'buddy.create', machineId: 'proposal-mac', engine: 'codex', setup: { name: 'Fixture Mac', cwd: '/fixture', engines: ['codex'] } })
const startId = String(added.result.startId)
@@ -173,9 +173,8 @@ describe('durable proposal cards', () => {
await f.execute({ type: 'proposal.decide', conversationId: id, decision: 'no', reason: 'Outside positioning' }, owner, f.pm)
const delivered = await f.store.deliveries(owner, f.tab, buddyId)
const notices = await db.superTabMessage.findMany({ where: { tabId: f.tab, conversationId: String(added.result.conversationId) } })
- const decision = notices.find(m => (m.source as any)?.moment === 'decided')!
- expect(decision).toBeDefined()
- expect(delivered.some(d => d.messageId === decision.id)).toBe(true)
+ expect(notices.filter(m => (m.source as { kind?: string } | null)?.kind === 'proposal-notice')).toEqual([])
+ expect(delivered.filter(d => notices.some(m => m.id === d.messageId && (m.author as { id?: string }).id !== buddyId))).toEqual([])
})
it('keeps a dormant card loaded when its person has a dormant default Buddy chat', async () => {
@@ -192,10 +191,10 @@ describe('durable proposal cards', () => {
await f.execute({ type: 'proposal.decide', conversationId: id, decision: 'no', reason: 'Outside positioning' }, owner, f.pm)
expect((await f.card(id)).proposal!.decision).toMatchObject({ kind: 'no', reason: 'Outside positioning' })
const notices = await db.superTabMessage.findMany({ where: { tabId: f.tab, conversationId: String(second.result.conversationId) } })
- expect(notices.some(m => (m.source as { moment?: string } | null)?.moment === 'decided')).toBe(true)
+ expect(notices.some(m => (m.source as { moment?: string } | null)?.moment === 'decided')).toBe(false)
})
- it('routes a dormant proposal overdue notice to the dormant default Buddy chat', async () => {
+ it('marks a dormant proposal overdue on its card, with no notice in the dormant default Buddy chat (task #4558)', async () => {
const f = await fixture()
await f.execute({ type: 'buddy.create', machineId: 'proposal-mac', engine: 'codex', setup: { name: 'Fixture Mac', cwd: '/fixture', engines: ['codex'] } })
const second = await f.execute({ type: 'buddy.create', machineId: 'proposal-mac', engine: 'codex', name: 'Research' })
@@ -210,7 +209,7 @@ describe('durable proposal cards', () => {
await runTimeCheckPass(db, f.store, f.clock.now)
expect((await f.card(id)).proposal!.overdue).toBe(true)
const notices = await db.superTabMessage.findMany({ where: { tabId: f.tab, conversationId: String(second.result.conversationId) } })
- expect(notices.some(m => (m.source as { kind?: string } | null)?.kind === 'proposal-overdue')).toBe(true)
+ expect(notices.some(m => (m.source as { kind?: string } | null)?.kind === 'proposal-overdue')).toBe(false)
})
it('delivers urgent proposals first on both a full poll and its fast repeat', async () => {
diff --git a/backend/integration/superTabRead.test.ts b/backend/integration/superTabRead.test.ts
index 01cb6e17b..7416eab2b 100644
--- a/backend/integration/superTabRead.test.ts
+++ b/backend/integration/superTabRead.test.ts
@@ -907,7 +907,7 @@ describe('decisions asked of one person (v2)', () => {
expect(await decisions(s.tabId, owner, 'open', s.lead)).toEqual([expect.objectContaining({ id: second })])
})
- it('leaves a decision to the PM: the recommended option, listed as the PM\'s, and the PM\'s line in the person\'s quiet Buddy chat', async () => {
+ it('leaves a decision to the PM: the recommended option, listed as the PM\'s, and no PM line in the person\'s quiet Buddy chat', async () => {
const s = await scene()
clock = Date.now()
const asked = await post(s.tabId, { type: 'decision.ask', conversationId: s.web, personId: peer.sub,
@@ -924,9 +924,9 @@ describe('decisions asked of one person (v2)', () => {
expect(await decisions(s.tabId, peer, 'answered')).toEqual([])
// Agents read it as answered, as before, now saying who decided.
expect(await decisions(s.tabId, owner, 'answered', s.lead)).toEqual([expect.objectContaining(listed)])
- const line = (await db.superTabMessage.findMany({ where: { tabId: s.tabId, conversationId: s.buddyId } })).at(-1)
- expect(line).toMatchObject({ text: 'PM decided: To everyone — Ship how?', recipientIds: [], source: { kind: 'decision-delegated', decisionId: id } })
- expect(line!.author).toMatchObject({ kind: 'agent', id: s.lead })
+ // Only the person and their own agent post in their private chat (task #4558): with no Buddy of theirs, no line there.
+ expect((await db.superTabMessage.findMany({ where: { tabId: s.tabId, conversationId: s.buddyId } }))
+ .filter(m => (m.source as { kind?: string } | null)?.kind === 'decision-delegated')).toEqual([])
// Only the person asked may leave it to the PM, and only while it is open.
expect((await post(s.tabId, { type: 'decision.answer', decisionId: id, delegate: true }, peer)).body.error?.code).toBe('DECISION_ANSWERED')
expect((await post(s.tabId, { type: 'decision.answer', decisionId: id, delegate: true }, owner)).status).toBe(404)
diff --git a/backend/integration/superTabSwarmBuddy.test.ts b/backend/integration/superTabSwarmBuddy.test.ts
index 1d4e43f54..370427ed5 100644
--- a/backend/integration/superTabSwarmBuddy.test.ts
+++ b/backend/integration/superTabSwarmBuddy.test.ts
@@ -104,6 +104,13 @@ async function projectSession(f: Swarm, chat: string, projectId: string | undefi
const thread = String(sent.result.messageId)
return { thread, agentId: await f.launch(String(sent.result.startId)) }
}
+/** A line of the secret project in peer's one Buddy chat, marked with that project: the secret PM's question to peer, which peer's
+ * own Buddy writes there, as only peer and their own agent post in it (task #4558; decisions.ts askedThroughBuddy). */
+async function secretLine(f: Swarm, text: string) {
+ await f.execute({ type: 'project.boardMode', projectId: f.secret.projectId, on: true })
+ await f.execute({ type: 'decision.ask', conversationId: f.secret.conversationId, personId: peer.sub, questions: [{ question: text,
+ options: ['Yes', 'No'], recommended: 0, unblocks: 'The release', defaultAt: new Date(f.clock.now + 60 * 60_000).toISOString() }] }, owner, f.pms.secret)
+}
const texts = async (f: Swarm, chat: string, user: AuthUser, as?: string, cursor: Record<string, unknown> = {}) =>
(await f.store.messages(user, f.tab, chat, cursor, as)).messages.map(m => m.text)
@@ -581,22 +588,21 @@ describe('a project session', () => {
})
describe('the PM\'s lines and losing a project', () => {
- it('puts a PM\'s private line in the one chat, marked with its project, and in the old chat for older apps', async () => {
+ // Only the person and their own agent post in their private chat (anh Dee, 11-07, task #4558).
+ it('refuses a PM\'s private line, and writes it nowhere', async () => {
const f = await swarm()
- const { chat } = await buddy(f)
- await f.execute({ type: 'person.tell', personId: peer.sub, text: 'WEB PM LINE' }, owner, f.pms.web)
- const rows = await db.superTabMessage.findMany({ where: { tabId: f.tab, text: 'WEB PM LINE' } })
- const old = String((await f.execute({ type: 'buddy.chat', projectId: f.web.projectId }, peer)).result.conversationId)
- expect(rows.map(r => r.conversationId).sort()).toEqual([chat, old].sort())
- expect(rows.find(r => r.conversationId === chat)!.source).toMatchObject({ projectId: f.web.projectId })
+ await buddy(f)
+ await expect(f.execute({ type: 'person.tell', personId: peer.sub, text: 'WEB PM LINE' }, owner, f.pms.web))
+ .rejects.toMatchObject({ code: 'PRIVATE_CHAT' })
+ expect(await db.superTabMessage.count({ where: { tabId: f.tab, text: 'WEB PM LINE' } })).toBe(0)
})
it('takes a lost project out of the Buddy: its sessions end, its lines hide, and the main Buddy reads it no more', async () => {
const f = await swarm()
const { chat, main } = await buddy(f)
const { thread, agentId } = await projectSession(f, chat, f.secret.projectId, 'SECRET SESSION SENTINEL')
- await f.execute({ type: 'person.tell', personId: peer.sub, text: 'SECRET PM LINE' }, owner, f.pms.secret)
- expect(await texts(f, chat, peer)).toContain('SECRET PM LINE')
+ await secretLine(f, 'SECRET PM LINE')
+ expect((await texts(f, chat, peer)).join('\n')).toContain('SECRET PM LINE')
await f.execute({ type: 'project.sharing', projectId: f.secret.projectId, visibility: 'private', memberIds: [owner.sub] })
const state = (await f.store.read(peer, f.tab)).state
expect(state.agents.map(a => a.id)).not.toContain(agentId)
@@ -615,7 +621,7 @@ describe('the inbox (security review 1 of #2435)', () => {
const f = await swarm()
const { chat } = await buddy(f)
await send(f, chat, 'An earlier word of mine')
- await f.execute({ type: 'person.tell', personId: peer.sub, text: 'SECRET PM LINE' }, owner, f.pms.secret)
+ await secretLine(f, 'SECRET PM LINE')
const preview = async () => JSON.stringify((await readInbox(f.store, peer, f.tab)).latest.filter(l => l.conversationId === chat))
expect(await preview()).toContain('SECRET PM LINE')
await f.execute({ type: 'project.sharing', projectId: f.secret.projectId, visibility: 'private', memberIds: [owner.sub] })
@@ -780,8 +786,8 @@ describe('security re-check 2 of #2435', () => {
const f = await swarm()
const { chat } = await buddy(f)
await send(f, chat, 'Mine')
- await f.execute({ type: 'person.tell', personId: peer.sub, text: 'SECRET PM LINE' }, owner, f.pms.secret)
- // The PM's line is the one row by someone else: it is what they missed.
+ await secretLine(f, 'SECRET PM LINE')
+ // The secret project's line is the one row not theirs: it is what they missed.
expect(await f.store.catchUp(peer, f.tab, chat, 0)).toMatchObject({ unread: 1 })
await f.execute({ type: 'project.sharing', projectId: f.secret.projectId, visibility: 'private', memberIds: [owner.sub] })
expect(await f.store.catchUp(peer, f.tab, chat, 0)).toMatchObject({ unread: 0 })
diff --git a/backend/src/superTabs/asksThroughBuddy.test.ts b/backend/src/superTabs/asksThroughBuddy.test.ts
index 4deb0ea4e..7c9e724f4 100644
--- a/backend/src/superTabs/asksThroughBuddy.test.ts
+++ b/backend/src/superTabs/asksThroughBuddy.test.ts
@@ -62,7 +62,9 @@ describe('in a switched project, an agent’s ask reaches the person through the
const line = sent.messages.filter(m => m.conversationId === f.buddyChat)
expect(line).toEqual([expect.objectContaining({ recipients: ['peer-buddy'], buddyProject: f.app.projectId,
source: { kind: 'decision-asked', decisionId: sent.decisions![0]!.id, projectId: f.app.projectId } })])
- expect(line[0]!.author).toMatchObject({ kind: 'agent', id: f.worker })
+ // Written by peer's own Buddy, naming the agent that asks: only peer and their own agent post there (task #4558).
+ expect(line[0]!.author).toMatchObject({ kind: 'agent', id: 'peer-buddy' })
+ expect(line[0]!.text).toMatch(/^worker asks peer on task #\d+: /)
expect(line[0]!.text).toContain('Ship to everyone, or behind a flag?')
expect(line[0]!.text).toContain('Behind a flag (recommended)')
expect(line[0]!.text).toContain(defaultAt)
diff --git a/backend/src/superTabs/buddies.test.ts b/backend/src/superTabs/buddies.test.ts
index 40350a62b..36a966b4a 100644
--- a/backend/src/superTabs/buddies.test.ts
+++ b/backend/src/superTabs/buddies.test.ts
@@ -4,7 +4,8 @@ import { applyCommand, commandSchema, type Command, type CommandContext } from '
import { createSuperTab, stableId, visibleState, type Actor, type Conversation } from './model.js'
import { canReadGroup, canWatchAgent, isConfidential, readsRecordsIn, wordsOf } from './projects.js'
import { CLOSED_CHAT_ANSWERED_NOTICE } from './decisions.js'
-import { BUDDY_REQUIREMENTS, buddyChatId, defaultBuddy, defaultBuddyChat, shownBefore, swarmBuddyChatId } from './buddies.js'
+import { BUDDY_REQUIREMENTS, buddyChatId, defaultBuddy, defaultBuddyChat, ownAgentAuthor, refuseOthersInPrivateChat, shownBefore, swarmBuddyChatId } from './buddies.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
import { isRoleName } from './agentNames.js'
import { buddiesTold } from './buddyNews.js'
import { sweepLiveness } from './liveness.js'
@@ -872,7 +873,7 @@ describe('a Buddy\'s proposal to the PM', () => {
})
// River, 11-04 (task #2926): proposals answered before threads, or opened as tasks without the link, still read as open.
- it('is closed with a reason by its project\'s PM or a person in the project, posting only its person\'s notice, and by nobody else', () => {
+ it('is closed with a reason by its project\'s PM or a person in the project, posting nothing, and by nobody else', () => {
const { f, propose } = asked()
const root = propose().messages[0]!
const context = { proposal: { id: root.id, conversationId: f.app.conversationId, author: root.author, source: root.source as Record<string, unknown> } }
@@ -880,9 +881,8 @@ describe('a Buddy\'s proposal to the PM', () => {
f.run({ type: 'proposal.close', projectId: f.app.projectId, messageId, reason: ' Built in #2901 ' }, actor, loaded)
const closed = close(agentActor(f.pm))
expect(closed.closedProposal).toEqual({ messageId: root.id, conversationId: f.app.conversationId, reason: 'Built in #2901' })
- // Nothing in the project's chat: only the notice to its person (task #4252).
- expect(closed.messages.map(m => m.source?.kind)).toEqual(['proposal-notice'])
- expect(closed.messages.some(m => m.conversationId === f.app.conversationId)).toBe(false)
+ // Nothing in the project's chat (task #4252), nor in its person's private chat (task #4558): the card records it.
+ expect(closed.messages).toEqual([])
expect(close(peer).closedProposal).toMatchObject({ messageId: root.id })
const webPm = group(f, f.web.conversationId).leadId!
for (const actor of [agentActor('buddy'), agentActor(webPm)]) expect(() => close(actor)).toThrow()
@@ -1207,69 +1207,44 @@ describe('a person\'s Buddy chat before any Buddy (Lead, 10-29)', () => {
})
})
-describe('the PM\'s private line to a person (Ken, 10-29)', () => {
+describe('a person\'s private chat with their own agent (anh Dee, 11-07, task #4558)', () => {
const tell = (personId = 'peer', text = 'Your fix is merged.') => ({ type: 'person.tell' as const, personId, text })
+ const send = (conversationId: string, text = 'Hello') => ({ type: 'message.send' as const, conversationId, text, replyTo: null, recipientIds: [] })
- // In the person's one Buddy chat, marked with its project (Dee, 10-31), and in their older chat in that project, which older
- // apps and the phone still show (spec: Older apps).
- it('goes to the person\'s one Buddy chat marked with its project, and their older chat there, opening each when they have none, to nobody; the PM still cannot read them', () => {
+ // "I don't want River or Theo to show up in this chat": a Lead's private line is refused, its own project's or another's.
+ it('refuses a Lead\'s private line, from its own project or another, naming the project chat, and opens no chat for it', () => {
const f = fresh()
- const told = f.run(tell(), agentActor(f.pm))
- const swarm = group(f, peerSwarmChat)
- const older = f.state.conversations.find(c => c.kind === 'buddy' && c.projectId === f.app.projectId)!
- for (const chat of [swarm, older]) expect(chat).toMatchObject({ agentIds: [], audience: { people: [{ id: 'peer', generation: 'first' }] } })
- expect(told.messages).toEqual([
- expect.objectContaining({ conversationId: swarm.id, recipients: [], text: 'Your fix is merged.', source: { kind: 'pm-line', projectId: f.app.projectId },
- author: expect.objectContaining({ kind: 'agent', id: f.pm }) }),
- expect.objectContaining({ conversationId: older.id, recipients: [], text: 'Your fix is merged.', author: expect.objectContaining({ kind: 'agent', id: f.pm }) }),
- ])
- // Its own id, derived from the line's operation, so both rows are stored.
- expect(told.messages[1]!.id).toBe(stableId(told.messages[0]!.id, 'project-chat'))
- expect(told.messages[1]!.source).toBeUndefined()
- expect(told.result).toEqual({ messageId: told.messages[0]!.id })
- for (const chat of [swarm, older]) {
- expect(canReadGroup(f.state, agentActor(f.pm), chat)).toBe(false)
- expect(canReadGroup(f.state, owner, chat)).toBe(false)
- expect(canReadGroup(f.state, peer, chat)).toBe(true)
+ const webPm = f.state.agents.find(a => a.harnessId === 'web-pm')!.id
+ for (const lead of [f.pm, webPm]) {
+ expect(() => f.run(tell(), agentActor(lead))).toThrow(expect.objectContaining({ code: 'PRIVATE_CHAT',
+ message: expect.stringContaining('project chat') }))
}
- // The same one chat its Buddy joins later, and a line to it then reaches the person, not the Buddy.
- expect(addBuddy(f, peer, f.app.projectId).result.conversationId).toBe(swarm.id)
- expect(f.run(tell('peer', 'Again.'), agentActor(f.pm)).messages.map(m => [m.conversationId, m.recipients])).toEqual([[swarm.id, []], [older.id, []]])
+ expect(f.state.conversations.filter(c => c.kind === 'buddy' || c.kind === 'swarm-buddy')).toEqual([])
})
- it('is the PM\'s, never a person\'s, to a person in the Swarm, and needs a line', () => {
+ it('keeps another agent\'s line the PM\'s crew need in the project chat, and refuses a person, a stranger or a Buddy', () => {
const f = fresh()
const worker = f.run({ type: 'agent.add', conversationId: f.group, harnessId: 'worker-harness', machineId: 'machine', name: 'Worker',
configuration, lead: false }).result.agentId as string
expect(() => f.run(tell(), peer)).toThrow(expect.objectContaining({ code: 'FORBIDDEN' }))
expect(() => f.run(tell('stranger'), agentActor(f.pm))).toThrow('person in this Swarm')
- expect(() => f.run(tell('peer', ' '), agentActor(f.pm))).toThrow()
- expect(f.state.conversations.filter(c => c.kind === 'buddy' || c.kind === 'swarm-buddy')).toEqual([])
- // People talk only to the PM (anh Dee, 11-05; crewNeeds.ts, task #3404): another agent's line is the PM's crew need, in the
- // project chat, and reaches no Buddy chat of the person.
expect(f.run(tell(), agentActor(worker)).messages).toEqual([expect.objectContaining({ conversationId: f.app.conversationId, recipients: [f.pm],
source: expect.objectContaining({ kind: 'crew-need' }) })])
- expect(f.run(tell(), agentActor(f.pm)).messages).toEqual([expect.objectContaining({ conversationId: peerSwarmChat, text: 'Your fix is merged.', recipients: [] }),
- expect.objectContaining({ conversationId: buddyChatId(f.app.projectId, { id: 'peer', generation: 'first' }), text: 'Your fix is merged.', recipients: [] })])
- })
-
- it('reaches only a person who reads the Lead\'s project, and only in that project', () => {
- const f = fresh()
- const secret = f.run({ type: 'project.create', name: 'Secret', visibility: 'private', brief: '' }).result as { projectId: string; conversationId: string }
- const secretPm = f.run({ type: 'agent.add', conversationId: secret.conversationId, harnessId: 'secret-pm', machineId: 'machine', name: 'Secret PM',
- configuration, lead: true }).result.agentId as string
- // By username, never email (task #2954).
- expect(() => f.run(tell(), agentActor(secretPm))).toThrow(/^peer cannot read this project\.$/)
- const webPm = f.state.agents.find(a => a.harnessId === 'web-pm')!.id
- const told = f.run(tell(), agentActor(webPm))
- expect(told.messages.map(m => m.conversationId)).toEqual([peerSwarmChat, buddyChatId(f.web.projectId, { id: 'peer', generation: 'first' })])
- expect(told.messages[0]!.source).toEqual({ kind: 'pm-line', projectId: f.web.projectId })
- expect(f.state.conversations.filter(c => c.kind === 'buddy').map(c => c.projectId)).toEqual([f.web.projectId])
+ expect(f.state.conversations.filter(c => c.kind === 'buddy' || c.kind === 'swarm-buddy')).toEqual([])
+ expect(() => setup().run(tell('owner'), agentActor('buddy'))).toThrow('A Buddy')
})
- it('is refused to a Buddy, as every command but its own chat\'s', () => {
+ it('lets the person and their own agent post there, and refuses any other agent\'s row, whatever command writes it', () => {
const f = setup()
- expect(() => f.run(tell('owner'), agentActor('buddy'))).toThrow('A Buddy')
+ expect(f.run(send(f.chat, 'What outcome do you want?'), agentActor('buddy')).messages[0]).toMatchObject({ conversationId: f.chat })
+ expect(f.run(send(f.chat, 'Faster sync.'), peer).messages[0]).toMatchObject({ conversationId: f.chat })
+ const pm = { kind: 'agent' as const, id: f.pm, name: 'app-pm', membershipGeneration: 'first' }
+ const row = { id: 'r', conversationId: f.chat, author: pm, text: 'Hi', replyTo: null, recipients: [] }
+ expect(() => refuseOthersInPrivateChat(f.state, [row], f.state)).toThrow(expect.objectContaining({ code: 'PRIVATE_CHAT' }))
+ // Another person's agent, even a Buddy, is not this person's own.
+ f.state.agents.push({ ...f.state.agents.find(a => a.id === 'buddy')!, id: 'owners-buddy', buddyOf: { personId: 'owner', generation: f.state.people[0]!.generation } })
+ expect(() => refuseOthersInPrivateChat(f.state, [{ ...row, author: { ...pm, id: 'owners-buddy' } }], f.state)).toThrow(expect.objectContaining({ code: 'PRIVATE_CHAT' }))
+ expect(() => refuseOthersInPrivateChat(f.state, [{ ...row, author: { ...pm, id: 'buddy' } }, { ...row, conversationId: f.app.conversationId }], f.state)).not.toThrow()
})
})
@@ -1303,8 +1278,10 @@ describe('a Buddy\'s terminal alert', () => {
})
describe('a decision left to the PM while Buddies are on', () => {
- it('puts the PM\'s line in the person\'s one Buddy chat marked with its project, and in their older Buddy chat there, to no one, not in their read-only Chat with PM', () => {
+ it('has their own Buddy say what the PM chose in their one Buddy chat marked with its project, and in their older Buddy chat there, to no one, not in their read-only Chat with PM', () => {
const f = setup()
+ // Only they and their own agent post in their private chat (task #4558): their default Buddy writes the line.
+ giveOwnBuddy(f.state, 'peer')
const decision = { id: 'decision-1', personId: 'peer', conversationId: f.group, projectId: f.app.projectId, askerAgentId: f.pm,
question: 'Ship how?', options: ['Behind a flag', 'To everyone'], recommended: 1, answeredAt: null, createdAt: 0, assignmentId: null }
const delegate = () => f.run({ type: 'decision.answer', decisionId: 'decision-1', delegate: true }, peer, { decision }).messages
@@ -1312,7 +1289,7 @@ describe('a decision left to the PM while Buddies are on', () => {
const lines = delegate()
expect(lines).toEqual([
expect.objectContaining({ conversationId: peerSwarmChat, recipients: [], text: 'PM decided: To everyone — Ship how?',
- source: { kind: 'decision-delegated', decisionId: 'decision-1', projectId: f.app.projectId } }),
+ author: expect.objectContaining({ id: 'peer-buddy' }), source: { kind: 'decision-delegated', decisionId: 'decision-1', projectId: f.app.projectId } }),
expect.objectContaining({ conversationId: f.chat, recipients: [], text: 'PM decided: To everyone — Ship how?',
source: { kind: 'decision-delegated', decisionId: 'decision-1' } })])
expect(lines.map(m => m.conversationId)).not.toContain(f.pmChat)
@@ -1750,12 +1727,11 @@ describe('several Buddies: where a person\'s lines go', () => {
return { f, first: start(), second: start({ name: 'Research' }) }
}
- it('sends a PM\'s line to the default Buddy\'s chat, and an older app\'s Buddy chat is the default\'s', () => {
+ it('writes a server line in the default Buddy\'s chat, by that Buddy, and an older app\'s Buddy chat is the default\'s', () => {
const { f, second } = two()
f.run({ type: 'buddy.default', conversationId: second.chat } as Command, peer)
- const told = f.run({ type: 'person.tell', personId: 'peer', text: 'Your idea is next up.' }, agentActor(f.pm))
- expect(told.messages.filter(m => m.text === 'Your idea is next up.').map(m => m.conversationId)).toContain(second.chat)
- expect(told.messages.filter(m => m.text === 'Your idea is next up.').map(m => m.conversationId)).not.toContain(peerSwarmChat)
+ const me = f.state.people.find(p => p.id === 'peer')!
+ expect([defaultBuddyChat(f.state, me).id, ownAgentAuthor(f.state, me)?.id]).toEqual([second.chat, second.agentId])
expect(f.run({ type: 'buddy.chat' }, peer).result.conversationId).toBe(second.chat)
})
diff --git a/backend/src/superTabs/buddies.ts b/backend/src/superTabs/buddies.ts
index 7349e8a4b..e91580016 100644
--- a/backend/src/superTabs/buddies.ts
+++ b/backend/src/superTabs/buddies.ts
@@ -3,7 +3,7 @@
* reads what its person reads of its project but no private conversation (Ken, 10-29), and does nothing but post in its
* chat and propose. On in every Swarm: Buddies replaced Chat with PM (Ken, 10-29). */
import { agentDisplayName, isRoleName } from './agentNames.js'
-import { fail, nextConversationNumber, person, stableId, type Actor, type Agent, type AgentStartRequest, type Conversation, type Person, type SuperTabState } from './model.js'
+import { fail, nextConversationNumber, person, stableId, type Actor, type Agent, type AgentStartRequest, type Author, type Conversation, type MessageDraft, type Person, type SuperTabState } from './model.js'
export const isBuddy = (target: Pick<Agent, 'buddyOf'>): boolean => !!target.buddyOf
/** A person's Buddy chat: in a project, or their one chat for the whole Swarm. */
@@ -17,7 +17,6 @@ export const isSwarmBuddy = (target: Pick<Agent, 'buddyOf' | 'buddyScope'> | und
* chat, whose project is its chat's. */
export const sessionProjectId = (target: Pick<Agent, 'buddySession'> | undefined): string | undefined => target?.buddySession?.projectId
/** A project PM's private line to one person in their one Buddy chat (commands.ts person.tell): its source names the project. */
-export const PM_LINE_KIND = 'pm-line'
/** Whether a Buddy reads [group] of its own project, as its person would (Ken, 10-29): the project chat, its own chat, and
* the project's workgroups. Never a private conversation, its own person's with others included, nor another Buddy chat.
@@ -126,6 +125,32 @@ export function defaultBuddy(state: SuperTabState, personId: string): Agent | un
: state.agents.find(agent => ownBuddy(agent, person))
}
+/** Who writes a server notice in [person]'s private chat: their own default Buddy, as only they and it post there (anh Dee,
+ * 11-07, task #4558). Undefined when they have none: then the notice is not written, and what it tells stays where it lives
+ * (Needs you, Members, the card). */
+export function ownAgentAuthor(state: SuperTabState, person: Pick<Person, 'id'>): Author | undefined {
+ const buddy = defaultBuddy(state, person.id)
+ return buddy && { kind: 'agent', id: buddy.id, name: buddy.name, displayName: agentDisplayName(state.agents, buddy.id),
+ membershipGeneration: buddy.membershipGeneration }
+}
+
+export const PRIVATE_CHAT_REFUSAL = 'Only a person and their own agent post in their private chat. Post in the project chat, tagging them, or in the task\'s chat.'
+
+/** In a person's private chat with their own agent, only they and their own agent post (anh Dee, 11-07, task #4558: "I don't
+ * want River or Theo to show up in this chat"): any other agent's row, a Lead's included, refuses the command that wrote it.
+ * The writer is looked up after the command, else before it: a thread session that ended in it writes its own last line. */
+export function refuseOthersInPrivateChat(state: SuperTabState, messages: readonly MessageDraft[], before: Pick<SuperTabState, 'agents'>): void {
+ for (const m of messages) {
+ if (m.author.kind !== 'agent') continue
+ const chat = state.conversations.find(c => c.id === m.conversationId)
+ if (!chat || !isBuddyChat(chat)) continue
+ const owner = chat.audience?.people[0]
+ const writer = state.agents.find(a => a.id === m.author.id) ?? before.agents.find(a => a.id === m.author.id)
+ if (owner && writer?.buddyOf?.personId === owner.id && writer.buddyOf.generation === owner.generation) continue
+ fail('PRIVATE_CHAT', PRIVATE_CHAT_REFUSAL, 403)
+ }
+}
+
/** The chat a line for [person] goes to: their default Buddy's, or with none their main Buddy chat, opened if missing, so there
* is always somewhere to write (task #3818). */
export function defaultBuddyChat(state: SuperTabState, person: Person): Conversation {
@@ -179,16 +204,6 @@ export function dropBuddyChat(state: SuperTabState, person: Pick<Person, 'id' |
if (next) setDefaultBuddy(state, person, next)
}
-/** Where a notice about what [senderBuddyId] sent for [person] goes (task #3817's decided and needs-you lines): that Buddy and its
- * chat while it is still theirs, else their default (defaultBuddyChat), so a removed sender's news is never lost. */
-export function buddyFor(state: SuperTabState, person: Person, senderBuddyId: string | null): { agent?: Agent; chat: Conversation } {
- const sender = senderBuddyId ? state.agents.find(a => a.id === senderBuddyId && ownBuddy(a, person)) : undefined
- const chat = sender && state.conversations.find(c => isSwarmBuddyChat(c) && c.agentIds.includes(sender.id))
- if (sender && chat) return { agent: sender, chat }
- const agent = defaultBuddy(state, person.id)
- return { ...agent ? { agent } : {}, chat: defaultBuddyChat(state, person) }
-}
-
/** What a Buddy is called until its owner names it: "ken's Buddy". */
export const defaultBuddyName = (owner: Pick<Person, 'email'>): string => `${owner.email.split('@')[0]}'s Buddy`
diff --git a/backend/src/superTabs/buddyDefault.test.ts b/backend/src/superTabs/buddyDefault.test.ts
index bc0b97bf0..dcf4587ec 100644
--- a/backend/src/superTabs/buddyDefault.test.ts
+++ b/backend/src/superTabs/buddyDefault.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { createSuperTab, type Agent, type Person } from './model.js'
-import { buddyFor, defaultBuddy, defaultBuddyChat, openSwarmBuddyChat, swarmBuddyChatId } from './buddies.js'
+import { defaultBuddy, defaultBuddyChat, openSwarmBuddyChat, ownAgentAuthor, swarmBuddyChatId } from './buddies.js'
// Task #3818 (Phase 2 of the Buddy board spec, approved 11-06): a person's lines (a decision, a needs-you, a removed Buddy's
// news) go to their default Buddy, and a proposal's notice to the Buddy that sent it while it is still theirs. Until a person
@@ -44,24 +44,14 @@ describe('a person\'s default Buddy', () => {
})
})
-describe('the Buddy a proposal\'s notice goes to', () => {
- it('is the Buddy that sent it while it is still that person\'s, else their default', () => {
+describe('who writes a server notice in a person\'s private chat (task #4558)', () => {
+ it('is their own default Buddy, never another person\'s, and nobody when they have none', () => {
const { state, peer, buddy } = setup()
- const main = buddy('main')
- const chat = openSwarmBuddyChat(state, peer)
- chat.agentIds.push(main.id)
- expect(buddyFor(state, peer, 'main')).toEqual({ agent: main, chat })
- // Removed, an older membership's, another person's, or none named: the default.
- expect(buddyFor(state, peer, 'gone')).toEqual({ agent: main, chat })
- buddy('old', { buddyOf: { personId: 'peer', generation: 'first' } })
- expect(buddyFor(state, peer, 'old').agent?.id).toBe('main')
+ expect(ownAgentAuthor(state, peer)).toBeUndefined()
buddy('theirs', { buddyOf: { personId: 'other', generation: 'second' } })
- expect(buddyFor(state, peer, 'theirs').agent?.id).toBe('main')
- expect(buddyFor(state, peer, null)).toEqual({ agent: main, chat })
- })
-
- it('with no Buddy left, is the person\'s main Buddy chat, with no agent', () => {
- const { state, peer } = setup()
- expect(buddyFor(state, peer, 'gone')).toEqual({ chat: expect.objectContaining({ id: swarmBuddyChatId(peer) }) })
+ expect(ownAgentAuthor(state, peer)).toBeUndefined()
+ const main = buddy('main')
+ openSwarmBuddyChat(state, peer).agentIds.push(main.id)
+ expect(ownAgentAuthor(state, peer)).toMatchObject({ kind: 'agent', id: 'main', membershipGeneration: main.membershipGeneration })
})
})
diff --git a/backend/src/superTabs/buddyModel.test.ts b/backend/src/superTabs/buddyModel.test.ts
index 8ef973b48..01c658741 100644
--- a/backend/src/superTabs/buddyModel.test.ts
+++ b/backend/src/superTabs/buddyModel.test.ts
@@ -10,6 +10,7 @@ import { sweepLiveness } from './liveness.js'
import { withoutMachineNames } from './store.js'
import { BUDDY_MODEL_GONE_MS, BUDDY_MODEL_LEASE_MS } from './tidy.js'
import { expiredModelRequests, unservedBuddyModels } from './buddyModel.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }
const peer: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'peer', email: '[email protected]' }
@@ -186,6 +187,7 @@ describe('the Buddy\'s machine reporting the switch', () => {
it('names no machine to a Buddy reading these lines: a Buddy reads no machines', () => {
const { f, requestId } = asked()
+ giveOwnBuddy(f.state, 'owner')
const effects = f.run({ type: 'buddy.modelResult', agentId: f.buddyId, requestId, ok: true }, f.buddy())
const read = effects.messages.map(m => withoutMachineNames(m as unknown as Parameters<typeof withoutMachineNames>[0]).text)
expect(read).toEqual(['Your Buddy now runs on DeepSeek 4.1 Flash, served by a machine.',
@@ -275,8 +277,10 @@ describe('the Buddy\'s machine reporting the switch', () => {
})
describe('the member who serves the model', () => {
- const landed = (gridModel = MODEL) => {
+ const landed = (gridModel = MODEL, buddy = true) => {
const f = setup()
+ // The serving member's own Buddy writes their line: only they and it post in their private chat (task #4558).
+ if (buddy) giveOwnBuddy(f.state, 'owner')
f.run({ type: 'buddy.model', gridModel })
return { f, effects: f.run({ type: 'buddy.modelResult', agentId: f.buddyId, requestId: f.agent().modelRequest!.id, ok: true }, f.buddy()) }
}
@@ -284,8 +288,12 @@ describe('the member who serves the model', () => {
it('is told, in their own Buddy chat, whose Buddy now runs on their machine\'s model', () => {
const { effects } = landed()
- expect(effects.messages.filter(m => m.conversationId === ownerChat).map(m => m.text))
- .toEqual(["peer's Buddy now runs on DeepSeek 4.1 Flash, which your machine serves."])
+ expect(effects.messages.filter(m => m.conversationId === ownerChat).map(m => [m.text, m.author.id]))
+ .toEqual([["peer's Buddy now runs on DeepSeek 4.1 Flash, which your machine serves.", 'owner-buddy']])
+ })
+
+ it('is not told without a Buddy of their own', () => {
+ expect(landed(MODEL, false).effects.messages.filter(m => m.conversationId === ownerChat)).toEqual([])
})
it('is told when it is their saved API', () => {
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.ts
index 05a0814b8..8a234424c 100644
--- a/backend/src/superTabs/commands.test.ts
+++ b/backend/src/superTabs/commands.test.ts
@@ -20,6 +20,7 @@ import { NOW, owner as richOwner, peer as richPeer, richSwarm } from './read/fix
import { groupView } from './read/views.js'
import { weekStart } from './leaderboard/week.js'
import { lentIn, weekSpan } from './leaderboard/rolling.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
const HOLD = { kind: 'person', personId: 'owner', defaultAt: '2026-11-06T02:00:00.000Z' } as const
@@ -2456,16 +2457,13 @@ describe('any agent of the project', () => {
})
// People talk only to the PM (anh Dee, 11-05; crewNeeds.ts, task #3404): another agent's line is the PM's crew need.
- it('lets the PM tell a person of its project, and turns another agent\'s line into a crew need', () => {
+ it('refuses the PM\'s private line to a person, and turns another agent\'s line into a crew need', () => {
const { f, E } = project(), pm = f.leadActor
f.invite()
expect(f.run({ type: 'person.tell', personId: 'peer', text: 'Your fix is merged.' }, E).messages.map(m => m.source?.kind)).toEqual(['crew-need'])
- const told = f.run({ type: 'person.tell', personId: 'peer', text: 'Your fix is merged.' }, pm)
- // In their one Buddy chat, marked with its project, and in their older chat there for older apps (Dee, 10-31).
- const swarm = f.state.conversations.find(c => c.kind === 'swarm-buddy')!, chat = f.state.conversations.find(c => c.kind === 'buddy')!
- expect(told.messages).toEqual([
- expect.objectContaining({ conversationId: swarm.id, text: 'Your fix is merged.', recipients: [], source: { kind: 'pm-line', projectId: chat.projectId } }),
- expect.objectContaining({ conversationId: chat.id, text: 'Your fix is merged.', recipients: [] })])
+ // Only the person and their own agent post in their private chat (anh Dee, 11-07, task #4558): the PM tags them in the project chat.
+ expect(() => f.run({ type: 'person.tell', personId: 'peer', text: 'Your fix is merged.' }, pm)).toThrow(expect.objectContaining({ code: 'PRIVATE_CHAT' }))
+ expect(f.state.conversations.filter(c => c.kind === 'swarm-buddy' || c.kind === 'buddy')).toEqual([])
expect(() => f.run({ type: 'person.tell', personId: 'peer', text: 'Hello.' })).toThrow(expect.objectContaining({ code: 'FORBIDDEN' }))
})
@@ -5893,6 +5891,25 @@ describe('lead.switch', () => {
expect(result.messages.at(-1)!.text).toContain('PM moved to Codex')
})
+ // Security review of #4558: the account a moved PM lands on would be the destination machine's owner's. No person moves a PM
+ // onto another member's computer at all (Swarm v3, #4120), Buddy or not, so no member's account runs it without their knowing.
+ it('refuses moving the PM onto another member\'s computer, whether or not they have a Buddy', () => {
+ for (const buddy of [false, true]) {
+ const s = setup()
+ const destination = structuredClone(s.f.state.machines![0]!)
+ Object.assign(destination, { machineId: 'destination', name: 'Peer Mac', generation: 'g2', contributorId: 'peer',
+ membershipGeneration: s.f.state.people.find(p => p.id === 'peer')!.generation })
+ destination.observation!.generation = 'g2'
+ destination.observation!.capabilities = ['leadSwitch', 'leadStart']
+ s.f.state.machines!.push(destination)
+ if (buddy) giveOwnBuddy(s.f.state, 'peer')
+ for (const profileId of [WORK, 'default']) {
+ expect(code(() => s.f.run({ ...s.request, profileId, machineId: 'destination', model: 'gpt-5.1' }))).toBe('NOT_YOUR_COMPUTER')
+ }
+ expect(s.agent().switchRequest).toBeUndefined()
+ }
+ })
+
it('keeps the source lead and posts one safe line when the destination candidate fails', () => {
const s = setup()
const destination = structuredClone(s.f.state.machines![0]!)
@@ -5959,14 +5976,27 @@ describe('lead.switch', () => {
expect(team.agent().switchRequest).toBeDefined()
})
- it('tells the machine owner, in their Buddy chat, when another person moves the PM onto one of their other accounts', () => {
- const lent = () => { const s = setup(['leadSwitch'], 'peer'); s.agent().machineOwnerId = 'peer'; return s }
+ it('has the machine owner\'s own Buddy tell them, in their Buddy chat, when another person moves the PM onto one of their other accounts', () => {
+ const lent = () => { const s = setup(['leadSwitch'], 'peer'); s.agent().machineOwnerId = 'peer'; giveOwnBuddy(s.f.state, 'peer'); return s }
const done = (s: ReturnType<typeof setup>) => s.f.run({ type: 'agent.switchResult', agentId: s.pm, switchId: s.sid(), ok: true }, { ...s.as, machineOwnerId: 'peer' })
const s = lent()
s.f.run(s.request)
const told = done(s).messages.filter(m => (m.source as { kind?: string } | undefined)?.kind === 'pm-switch-notice')
expect(told).toEqual([expect.objectContaining({ conversationId: s.f.state.conversations.find(c => c.kind === 'swarm-buddy')!.id,
+ author: expect.objectContaining({ kind: 'agent', id: 'peer-buddy' }),
text: 'owner moved the PM of Pilot on Studio to your Codex account "Work".', source: { kind: 'pm-switch-notice', machineId: 'host' } })])
+ // Without a Buddy of theirs nobody could tell them (only they and their own agent post in their private chat, task #4558), so
+ // another person's move onto their other account is refused, saying why; on its default account, or their own move, it goes.
+ const bare = setup(['leadSwitch'], 'peer')
+ bare.agent().machineOwnerId = 'peer'
+ expect(() => bare.f.run(bare.request)).toThrow(expect.objectContaining({ code: 'OWNER_NOT_TOLD', message: expect.stringContaining('peer') }))
+ expect(bare.agent().switchRequest).toBeUndefined()
+ bare.f.run({ ...bare.request, profileId: 'default' })
+ expect(bare.agent().switchRequest).toBeDefined()
+ const theirs = setup(['leadSwitch'], 'peer')
+ theirs.agent().machineOwnerId = 'peer'
+ theirs.f.run(theirs.request, peer)
+ expect(theirs.agent().switchRequest).toMatchObject({ requestedBy: 'peer' })
// The owner's Buddy reads it: never an email, even one the asker took as their name (review of #2954).
const named = lent()
named.f.state.people.find(p => p.id === 'owner')!.name = '[email protected]'
@@ -6094,6 +6124,7 @@ describe('lead.switch', () => {
it('tells the machine owner after a real switch, where the rebind lands before the result', () => {
const s = setup(['leadSwitch'], 'peer')
s.agent().machineOwnerId = 'peer'
+ giveOwnBuddy(s.f.state, 'peer')
s.f.run(s.request)
const switchId = s.sid(), requester = s.agent().switchRequest!.requestedBy
s.f.run({ type: 'agent.rebind', agentId: s.pm, machineId: 'host', projectId: 'lead', previousHarnessId: 'pm', harnessId: 'pm-2', profileId: WORK,
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 1ed3ebfe9..a1ddebaa3 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -1,6 +1,6 @@
import { authorizeTaskApproval, pendingTaskApproval, personalApprovalCommand, rejectTaskApproval, reopenTaskApproval, REQUESTER_LEFT, requireTaskApproval, stageTaskApproval, undecidedProposal } from './taskApproval.js'
import type { PullRequestFilesRead } from './pullRequestFiles.js'
-import { legacyProposalId, migrateLegacyProposals, type LegacyProposalAsk, pmAcceptsMessage, applyProposalAction, authorizeProposalAction, authorizePersonProposal, cardPriority, createPersonProposal, createProposalCard, proposalCreateSchema, proposalFields, proposalNotices, proposalRoot, type ProposalRecord } from './proposalCards.js'
+import { legacyProposalId, migrateLegacyProposals, type LegacyProposalAsk, pmAcceptsMessage, applyProposalAction, authorizeProposalAction, authorizePersonProposal, cardPriority, createPersonProposal, createProposalCard, proposalCreateSchema, proposalFields, proposalRoot } from './proposalCards.js'
import { handoffAsk, pulseProjectOf, recordPulse, owe, settleDeleted, settleReaction, settleReply, settleRequest } from './pulse.js'
import { linesOf } from './statusCard.js'
import { applyPushOrigin, barredFromTeamWritten, failPushUnknown, failTeamWritten, mainAccountMembers, markTeamWritten, mayName, ownersOwnAgent, ownersOwnMachine, requireTeamWrittenAccount, requireTeamWrittenMachine, stepMark, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'
@@ -77,7 +77,7 @@ import { recordClosing, sessionClosed } from './closedAgents.js'
import { declinedWith, declinedWithout } from './sharing.js'
import { actorLabel, memberChanges, memberRowText, quotedName } from './memberRows.js'
import { BUDDY_SESSION_CAPABILITY, chatOwner, endSessionEntry, entryProject, liveSessions, mainBuddyOf, MAX_SESSION_WAITING, requireChatOwner, SESSION_ENDED_KIND, sessionAgentsOf, sessionOf, setSessions, type SessionEndReason } from './buddySessions.js'
-import { BUDDY_REQUIREMENTS, buddyCapOf, buddyCapRefusal, buddyChatId, buddyChatOf, buddyChatsOf, buddyCount, defaultBuddy, defaultBuddyChat, hasBuddy, dropBuddyChat, MAX_BUDDY_CAP, openNewBuddyChat, setDefaultBuddy, buddyReady, chosenBuddyName, isBuddy, isBuddyChat, isSwarmBuddy, isSwarmBuddyChat, MAX_PROPOSAL_ASKS, MAX_PROPOSAL_ATTACHMENTS, okayedWords, openBuddyChat, openSwarmBuddyChat, PM_LINE_KIND, PROPOSAL_ASK_MS, PROPOSAL_SENT_KIND, proposalBrief, proposalSentText, renameBuddy, requireBuddyCommand, swarmBuddyChatId } from './buddies.js'
+import { BUDDY_REQUIREMENTS, buddyCapOf, buddyCapRefusal, buddyChatId, buddyChatOf, buddyChatsOf, buddyCount, defaultBuddy, defaultBuddyChat, hasBuddy, dropBuddyChat, MAX_BUDDY_CAP, openNewBuddyChat, setDefaultBuddy, buddyReady, chosenBuddyName, isBuddy, isBuddyChat, isSwarmBuddy, isSwarmBuddyChat, MAX_PROPOSAL_ASKS, MAX_PROPOSAL_ATTACHMENTS, okayedWords, openBuddyChat, openSwarmBuddyChat, ownAgentAuthor, PRIVATE_CHAT_REFUSAL, refuseOthersInPrivateChat, PROPOSAL_ASK_MS, PROPOSAL_SENT_KIND, proposalBrief, proposalSentText, renameBuddy, requireBuddyCommand, swarmBuddyChatId } from './buddies.js'
import { BUDDY_OWN_MACHINE_REFUSAL } from './buddyContract.js'
import { askBuddyModel, buddyModelResult, sendBuddyHome, sessionModel } from './buddyModel.js'
import { askBuddyEngine, buddyEngineChat, buddyEngineName, checkBuddyRebind } from './buddyEngine.js'
@@ -1120,6 +1120,7 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
let sender: Author | undefined
try { sender = author(effects.state, actor) } catch { sender = undefined }
syncTaskLines(original, effects, sender, stableId(original.id, actorKey(actor), context.operationId))
+ refuseOthersInPrivateChat(effects.state, effects.messages, original)
for (const row of effects.messages) row.recipients = row.recipients.filter(id => pmAcceptsMessage(effects.state, id, row.source))
// Every open group is loaded for a command (parts/load.ts): the board's pulse is worked out on it (pulse.ts), for the project
// of the conversation the command names when it names one (it moves no other), else for every project.
@@ -2051,7 +2052,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
const firstAssignment = group.ledger?.firstAssignedAt == null && !group.ledger?.runs?.length
recordRun(state, group, group.assignment, worker, context.now)
const others = othersWorkNotice(state, group, worker, context.now, ENGINE_NAMES[worker.configuration.engine] ?? worker.configuration.engine)
- if (others) effects.messages.push({ id: stableId(assignmentId, 'others-work-notice'), conversationId: others.conversationId, author: sender,
+ if (others) effects.messages.push({ id: stableId(assignmentId, 'others-work-notice'), conversationId: others.conversationId, author: others.author,
replyTo: null, recipients: [], source: { kind: 'others-work-notice', machineId: others.machineId }, text: others.text })
group.checks.forEach(c => { c.evidence = null; c.passedBy = null; delete c.verdicts })
// The brief (a task with none: its title), and its acceptance checks when it has some: checks are information. Then
@@ -2297,6 +2298,13 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
if (profileId !== defaultProfileId(destination.machineId, command.engine) && !destination.observation!.profiles?.some(p => p.engine === command.engine && p.id === profileId)) {
fail('PROFILE_UNKNOWN', `That account isn’t on ${destination.name} any more.`, 409)
}
+ // Another person's move onto the machine owner's other account is told to the owner by their own Buddy (agent.switchResult):
+ // with none to tell them, their quota is never used without their knowing (security review of #4558).
+ const machineOwner = state.people.find(p => p.id === pm.machineOwnerId)
+ if (machineOwner && machineOwner.id !== actor.userId && profileId !== defaultProfileId(destination.machineId, command.engine)
+ && !ownAgentAuthor(state, machineOwner)) {
+ fail('OWNER_NOT_TOLD', `${usernameOf(state, machineOwner.id) ?? 'The machine\'s owner'} has no Buddy to tell them the ${name} runs on their account. Ask them to move it, or to add a Buddy first.`, 409)
+ }
if (destination.machineId !== pool.machineId) {
const start = state.starts!.find(candidate => candidate.request.leadFor?.switchId === operationId)!
start.request.profileId = profileId
@@ -2460,14 +2468,16 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
// The coordinator's save that says it is the tidy is that tidy done (pmSchedule.ts tidyRequest); a correction it saves
// meanwhile is not (review of #3112).
if (actor.kind === 'agent' && command.tidy) tidySaved(projectOf(state, project.id), current + 1)
- // Approvers and authors affected by a decider's override hear privately, in their one Buddy chat and older one here.
+ // Approvers and authors affected by a decider's override hear privately, in their one Buddy chat and older one here, from
+ // their own agent: only they and it post there (task #4558). Without one, the Instructions history records the drop.
for (const [personId, rules] of told) {
- const to = person(state, personId)
+ const to = person(state, personId), ownVoice = ownAgentAuthor(state, to)
+ if (!ownVoice) continue
const text = approvedDropNotice(who, project, rules, deciderId ? agentWrittenNameOf(state, deciderId) ?? 'the project top decider' : undefined)
const id = stableId(operationId, 'rule-approved', personId)
- message(defaultBuddyChat(state, to).id, text, [], null, { kind: PM_LINE_KIND, projectId: project.id }, undefined, undefined, undefined, id)
- Object.assign(effects.messages.at(-1)!, { buddyProject: project.id })
- effects.messages.push({ id: stableId(id, 'project-chat'), conversationId: openBuddyChat(state, project.id, to).id, author: sender, text, replyTo: null, recipients: [] })
+ effects.messages.push({ id, conversationId: defaultBuddyChat(state, to).id, author: ownVoice, text, replyTo: null, recipients: [],
+ source: { kind: 'rule-approved', projectId: project.id }, buddyProject: project.id },
+ { id: stableId(id, 'project-chat'), conversationId: openBuddyChat(state, project.id, to).id, author: ownVoice, text, replyTo: null, recipients: [] })
}
break
}
@@ -3627,10 +3637,6 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
if (mirror?.proposal && !mirror.proposal.mergedInto) {
mirror.archived = true
mirror.proposal.decision = { kind: 'no', reason: command.reason, at: context.now, by: sender.id }
- // Its person hears it through their Buddy, as a board decision tells them (proposalCards.ts), unless they closed it.
- const card = mirror as Conversation & { proposal: ProposalRecord }
- effects.messages.push(...proposalNotices(state, card, 'decided', `${mirror.title}: no. ${command.reason}`, sender, operationId,
- card.proposal.senders.filter(s => actor.kind !== 'person' || s.personId !== actor.userId)))
}
effects.closedProposal = { messageId, conversationId: project.leadConversationId, reason: command.reason }
result.proposalId = messageId
@@ -3691,8 +3697,11 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
// The machines a line names leave a Buddy's read of it (store.ts withoutMachineNames): a Buddy reads no machines.
buddyModelResult(state, actor, command, context.now).forEach((line, i) => {
const source = { ...SYSTEM_ROW, ...(line.machines.length ? { machines: line.machines } : {}) }
- if (i === 0) message(line.conversationId, line.text, [], null, source)
- else effects.messages.push({ id: stableId(operationId, 'buddy-model', String(i)), conversationId: line.conversationId, author: sender,
+ if (i === 0) { message(line.conversationId, line.text, [], null, source); return }
+ // Another member's line, in their private chat: written by their own agent, as only they and it post there (task #4558).
+ const chat = state.conversations.find(c => c.id === line.conversationId), member = chat && chatOwner(chat)
+ const ownVoice = member && ownAgentAuthor(state, member)
+ if (ownVoice) effects.messages.push({ id: stableId(operationId, 'buddy-model', String(i)), conversationId: line.conversationId, author: ownVoice,
text: line.text, replyTo: null, recipients: [], source })
})
break
@@ -3725,14 +3734,9 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
crewNeed(projectChat, pmInstead, { personIds: [to.id], conversationId: projectChat.id }, command.text)
break
}
- // To nobody: the person reads it; their Buddy, if they have one, is not asked to answer for them. In their one Buddy chat,
- // marked with its project so it hides once they lose it (buddies.ts hiddenProjectRow), and in their older chat there,
- // which older apps and the phone still show (spec: Older apps).
- message(defaultBuddyChat(state, to).id, command.text, [], null, { kind: PM_LINE_KIND, projectId: project.id })
- Object.assign(effects.messages.at(-1)!, { buddyProject: project.id })
- effects.messages.push({ id: stableId(operationId, 'project-chat'), conversationId: openBuddyChat(state, project.id, to).id, author: sender,
- text: command.text, replyTo: null, recipients: [] })
- break
+ // The PM's private line went in the person's private chat with their own agent, where only they and it post (anh Dee,
+ // 11-07, task #4558): the PM tags them in the project chat instead.
+ fail('PRIVATE_CHAT', PRIVATE_CHAT_REFUSAL, 403)
}
case 'buddy.create': {
if (actor.kind !== 'person') fail('BUDDY_PERSON', 'A person adds their own Buddy.', 403)
@@ -4287,10 +4291,12 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
: `Couldn't switch the PM: ${error || 'it failed'}. ${command.down ? `It has not come back on ${engine} yet; its machine keeps trying.` : `It is back on ${engine}.`}` })
// The machine owner hears when their non-default account runs another person's PM; the project line may be out of their reach.
const owner = state.people.find(p => p.id === target.machineOwnerId), pool = state.machines?.find(m => m.machineId === target.machineId)
- if (moved && label && asked && owner && asked !== owner.id) {
+ // Written by the owner's own agent: only they and it post in their private chat (task #4558).
+ const ownVoice = owner && ownAgentAuthor(state, owner)
+ if (moved && label && asked && owner && ownVoice && asked !== owner.id) {
// The owner's Buddy reads it: by name, never email (review of #2954).
const who = agentWrittenNameOf(state, asked) ?? 'Someone'
- effects.messages.push({ id: stableId(operationId, 'pm-switch-notice'), conversationId: defaultBuddyChat(state, owner).id, author: sender, replyTo: null, recipients: [],
+ effects.messages.push({ id: stableId(operationId, 'pm-switch-notice'), conversationId: defaultBuddyChat(state, owner).id, author: ownVoice, replyTo: null, recipients: [],
source: { kind: 'pm-switch-notice', machineId: target.machineId },
text: `${who} moved the PM of ${project.name} on ${pool?.name ?? target.machineId} to your ${engine} account "${label}".` })
}
diff --git a/backend/src/superTabs/crewNeeds.test.ts b/backend/src/superTabs/crewNeeds.test.ts
index ba92ef490..706731bd0 100644
--- a/backend/src/superTabs/crewNeeds.test.ts
+++ b/backend/src/superTabs/crewNeeds.test.ts
@@ -160,15 +160,14 @@ describe('an agent’s needs_human, decision ask and line to a person go to the
expect(needs(byPm)).toEqual([])
})
- it('turns a worker’s line to a person into a crew need in the project chat, and keeps the PM’s', () => {
+ it('turns a worker’s line to a person into a crew need in the project chat, and refuses the PM’s private line (task #4558)', () => {
const f = assigned()
const byWorker = f.run({ type: 'person.tell', personId: 'peer', text: 'Look at the mockup in #12' }, asAgent(f.worker))
// Nothing lands in the person's Buddy chats: the crew need is the command's only message.
expect(byWorker.messages.filter(m => !crewNeedOf(m.source))).toEqual([])
expect(needs(byWorker).map(m => [m.conversationId, m.recipients, crewNeedOf(m.source)!.personIds])).toEqual([[f.app.conversationId, [f.pm], ['peer']]])
expect(byWorker.result.routedToPm).toMatch(/PM/)
- const byPm = f.run({ type: 'person.tell', personId: 'peer', text: 'Look at the mockup in #12' }, asAgent(f.pm))
- expect(needs(byPm)).toEqual([])
- expect(byPm.messages.length).toBeGreaterThan(0)
+ expect(() => f.run({ type: 'person.tell', personId: 'peer', text: 'Look at the mockup in #12' }, asAgent(f.pm)))
+ .toThrow(expect.objectContaining({ code: 'PRIVATE_CHAT' }))
})
})
diff --git a/backend/src/superTabs/decisions.test.ts b/backend/src/superTabs/decisions.test.ts
index 381970423..437a01670 100644
--- a/backend/src/superTabs/decisions.test.ts
+++ b/backend/src/superTabs/decisions.test.ts
@@ -5,6 +5,7 @@ import { applyCommand, commandSchema, type Command, type CommandContext } from '
import { createSuperTab, type Actor, type AgentConfiguration } from './model.js'
import { ANSWERED_NOTICE, askDecisions, checkAsker, decisionsWaiting, listDecisions, overdueNotice, delegatedNotice, answerDecision, waitingInProject, withdrawIn, workEnded, workOver, type DecisionTarget } from './decisions.js'
import { buddyChatId } from './buddies.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
const HOLD = { kind: 'person', personId: 'owner', defaultAt: '2026-11-06T02:00:00.000Z' } as const
@@ -215,11 +216,14 @@ describe('leaving a decision to the PM', () => {
brief: '', checks: [], assignment: null, lastMessageSequence: 0, audience: { people: [{ id: 'peer', generation }] } })
return id
}
+ /** The peer's own Buddy, who writes the line: only they and it post in their private chat (task #4558). */
+ const withBuddy = (s: ReturnType<typeof swarm>) => giveOwnBuddy(s.state, 'peer')
const delegate = (s: ReturnType<typeof swarm>, actor: Actor, decision: DecisionTarget | undefined) =>
s.run({ type: 'decision.answer', decisionId: 'decision-1', delegate: true }, actor, decision ? { decision } : {})
- it('answers with the recommended option for the person asked, recorded as delegated, and the PM says so in their Buddy chat', () => {
+ it('answers with the recommended option for the person asked, recorded as delegated, and their own Buddy says what the PM chose', () => {
const s = swarm()
+ withBuddy(s)
const chat = buddyChat(s)
const answered = delegate(s, peer, open(s))
expect(answered.decisionAnswer).toEqual({ id: 'decision-1', choice: 1, note: null, delegated: true })
@@ -228,24 +232,26 @@ describe('leaving a decision to the PM', () => {
expect(notice).toMatchObject({ conversationId: s.group, recipients: [s.worker, s.lead], source: { kind: 'agent-only', decisionId: 'decision-1' } })
expect(notice!.text).toContain('left to the Product Manager')
for (const text of ['Ship how?', 'To everyone']) expect(notice!.text).not.toContain(text)
- // One line from the PM in the person's one Buddy chat, marked with its project, and the same in their older chat there for
- // older apps (Dee, 10-31): only they read either, and it goes to nobody.
+ // One line from their own Buddy in their one Buddy chat, marked with its project, and the same in their older chat there for
+ // older apps (Dee, 10-31): only they read either, and it goes to nobody. Never the PM's: only they and their agent post there.
const swarmChat = s.state.conversations.find(c => c.kind === 'swarm-buddy')!
expect(swarmLine).toMatchObject({ conversationId: swarmChat.id, recipients: [], text: 'PM decided: To everyone — Ship how?',
- author: { kind: 'agent', id: s.lead }, source: { kind: 'decision-delegated', decisionId: 'decision-1', projectId: 'lead' } })
+ author: { kind: 'agent', id: 'peer-buddy' }, source: { kind: 'decision-delegated', decisionId: 'decision-1', projectId: 'lead' } })
expect(line).toMatchObject({ conversationId: chat, recipients: [], text: 'PM decided: To everyone — Ship how?',
- author: { kind: 'agent', id: s.lead }, source: { kind: 'decision-delegated', decisionId: 'decision-1' } })
+ author: { kind: 'agent', id: 'peer-buddy' }, source: { kind: 'decision-delegated', decisionId: 'decision-1' } })
expect(new Set([notice!.id, swarmLine!.id, line!.id]).size).toBe(3)
expect(answered.messages).toHaveLength(3)
})
- it('opens the person\'s Buddy chat for the line when they have none, and opens an archived one again: the line never drops', () => {
+ it('writes no line without a Buddy, else opens the person\'s older chat for it when they have none, and an archived one again', () => {
const s = swarm()
+ expect(delegate(s, peer, open(s)).messages.map(m => m.conversationId)).toEqual([s.group])
+ withBuddy(s)
const answered = delegate(s, peer, open(s))
expect(answered.decisionAnswer).toMatchObject({ choice: 1, delegated: true })
const chat = s.state.conversations.find(c => c.kind === 'buddy')!, swarmChat = s.state.conversations.find(c => c.kind === 'swarm-buddy')!
expect(chat).toMatchObject({ projectId: 'lead', agentIds: [], audience: { people: [{ id: 'peer' }] } })
- expect(swarmChat).toMatchObject({ agentIds: [], audience: { people: [{ id: 'peer' }] } })
+ expect(swarmChat).toMatchObject({ agentIds: ['peer-buddy'], audience: { people: [{ id: 'peer' }] } })
expect(swarmChat.projectId).toBeUndefined()
expect(answered.messages.map(m => m.conversationId)).toEqual([s.group, swarmChat.id, chat.id])
chat.archived = true
@@ -280,6 +286,7 @@ describe('leaving a decision to the PM', () => {
it('takes a timed default only at its trusted deadline, and never accepts the marker from a client', () => {
const s = swarm()
+ withBuddy(s)
const decision = open(s, { defaultAt: 1000 })
const command = { type: 'decision.answer', decisionId: 'decision-1', delegate: true } as const
expect(() => s.run(command, peer, { decision, defaulted: true, now: 999 } as Partial<CommandContext>)).toThrow(/default.*time|deadline/i)
diff --git a/backend/src/superTabs/decisions.ts b/backend/src/superTabs/decisions.ts
index d6dd0cf50..43abc42f7 100644
--- a/backend/src/superTabs/decisions.ts
+++ b/backend/src/superTabs/decisions.ts
@@ -3,14 +3,13 @@
* with one tap, and the answer reaches the asking agent and the Lead in the conversation it came from. Decisions live in
* SuperTabDecision, never in the tab state, as mentions do. A decision is not a private channel: the PM's private lines go
* to the person's Buddy chat (buddies.ts). Called inside SuperTabStore's transactions. */
-import { defaultBuddy, defaultBuddyChat, isBuddy, isSwarmBuddy, openBuddyChat } from './buddies.js'
+import { defaultBuddyChat, isBuddy, isSwarmBuddy, openBuddyChat, ownAgentAuthor } from './buddies.js'
import { switched } from './boardRights.js'
import { usernameOf } from './usernames.js'
import { agentWrittenNameOf } from './personNames.js'
import { createHash } from 'node:crypto'
import type { Prisma } from '@prisma/client'
import { z } from 'zod'
-import { agentDisplayName } from './agentNames.js'
import { AGENT_ONLY, fail, isLeads, person, stableId, type Actor, type Author, type Conversation, type MessageDraft, type SuperTabState } from './model.js'
import { agentProjectId, canReadGroup, groupProject, isClosedPmChat, ledProject, projectAgent, projectOf, projectsOf, readsRecordsIn } from './projects.js'
import { LEDGER_WEEKS } from './leaderboard/record.js'
@@ -101,19 +100,21 @@ export function checkDirectAsk(questions: ReadonlyArray<{ defaultAt?: string }>)
/** Each asked decision's line in its person's default Buddy chat, to their default Buddy, which brings it to them: the Buddy
* cannot answer it (answerable), the person answers in their Needs you list. Marked with its project, so it hides once they
- * lose it (buddies.ts hiddenProjectRow). Written as [author], the agent that asked. */
-export function askedThroughBuddy(state: SuperTabState, group: Conversation, drafts: readonly DecisionDraft[], author: Author): MessageDraft[] {
- return drafts.map(d => {
+ * lose it (buddies.ts hiddenProjectRow). Written by that Buddy, naming [asker], the agent that asked: only the person and their
+ * own agent post in their private chat (task #4558). With no Buddy there is no line; the ask waits in Needs you. */
+export function askedThroughBuddy(state: SuperTabState, group: Conversation, drafts: readonly DecisionDraft[], asker: Author): MessageDraft[] {
+ return drafts.flatMap(d => {
const to = person(state, d.personId)
- const buddy = defaultBuddy(state, to.id)
+ const author = ownAgentAuthor(state, to)
+ if (!author) return []
const options = d.options.map((o, i) => i === d.recommended ? `${o} (recommended)` : o).join(' / ')
const task = group.number ? ` on task #${group.number}` : ''
- const text = `${author.displayName ?? author.name} asks ${usernameOf(state, to.id)}${task}: ${d.question}\n\nOptions: ${options}\n`
+ const text = `${asker.displayName ?? asker.name} asks ${usernameOf(state, to.id)}${task}: ${d.question}\n\nOptions: ${options}\n`
+ `Unblocks: ${d.unblocks}\n` + (d.mustAgree
? `No default applies: your agreement is required. At ${d.defaultAt}, the PM is told if you have not answered.`
: `At ${d.defaultAt}, if not answered: ${d.options[d.recommended]!}.`)
- return { id: stableId(d.id, 'buddy'), conversationId: defaultBuddyChat(state, to).id, author, text, replyTo: null,
- recipients: buddy ? [buddy.id] : [], source: { kind: DECISION_ASKED_KIND, decisionId: d.id, projectId: d.projectId }, buddyProject: d.projectId }
+ return [{ id: stableId(d.id, 'buddy'), conversationId: defaultBuddyChat(state, to).id, author, text, replyTo: null,
+ recipients: [author.id], source: { kind: DECISION_ASKED_KIND, decisionId: d.id, projectId: d.projectId }, buddyProject: d.projectId }]
})
}
export const DECISION_ASKED_KIND = 'decision-asked'
@@ -223,14 +224,13 @@ export function mustAgreePassed(state: SuperTabState, actor: Actor, decision: De
return { noticeIn: noticeIn.id, text, recipients: lead && noticeIn.agentIds.includes(lead) ? [lead] : [], source: { kind: MUST_AGREE_KIND, decisionId: asked.id } }
}
-/** The Lead's one line saying what it chose, in the person's own Buddy chat of that project: only they and their Buddy read
- * it, and they were asked the question. Opened for the line when they have none (buddies.ts openBuddyChat), so it never
- * drops: Buddies replaced Chat with PM (Ken, 10-29). */
+/** The one line saying what the Lead chose, in the person's own Buddy chat of that project: only they and their Buddy read
+ * it, and they were asked the question. Opened for the line when they have none (buddies.ts openBuddyChat). */
function delegatedLine(state: SuperTabState, projectId: string, leadId: string, asked: DecisionTarget, choice: number, defaulted = false) {
- const lead = state.agents.find(a => a.id === leadId)
- if (!lead) return null
const to = person(state, asked.personId)
- const author: Author = { kind: 'agent', id: lead.id, name: lead.name, displayName: agentDisplayName(state.agents, lead.id), membershipGeneration: lead.membershipGeneration }
+ // Written by their own agent, as only they and it post in their private chat (task #4558); with none, Needs you shows it.
+ const author = state.agents.some(a => a.id === leadId) ? ownAgentAuthor(state, to) : undefined
+ if (!author) return null
const question = asked.question.replace(/\s+/g, ' ')
const text = `${defaulted ? `Default applied: ${asked.options[choice]!}` : answerText(asked.options[choice]!, true)} — ${question}`
// In their one Buddy chat, marked with its project (Dee, 10-31), and in their older chat there for older apps.
diff --git a/backend/src/superTabs/instructions.test.ts b/backend/src/superTabs/instructions.test.ts
index 57d748be6..6e0f8d01b 100644
--- a/backend/src/superTabs/instructions.test.ts
+++ b/backend/src/superTabs/instructions.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import { applyCommand, type Command, type CommandContext } from './commands.js'
import { createSuperTab, type Actor, type AgentConfiguration } from './model.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
import { appendRouting, instructionsHash, legacyRoleName, MAX_INSTRUCTIONS_BYTES, roleNameOf, routingSummary, summarySchema } from './instructions.js'
import type { SwarmProject } from './projects.js'
import { INSTRUCTIONS_TEMPLATE, TEMPLATE_WORKFLOW } from './instructionsTemplate.js'
@@ -444,8 +445,13 @@ describe('an instructions save keeps the rules people gave', () => {
expect(f.run(save(2, doc(reworded, merged), { askedBy: 'owner' }), as(lead), stored(doc(leo, merged), 2)).result.revision).toBe(3)
})
- it('lets a drop approved by the rule\'s person go through, and tells that person in one private line', () => {
+ it('lets a drop approved by the rule\'s person go through, and their own Buddy tells them in one private line', () => {
+ // With no Buddy, no line: only they and their own agent post in their private chat (task #4558); the history records it.
+ const bare = pm()
+ expect(bare.f.run(save(1, doc(tony, quiet), { askedBy: 'owner', approvals: ['yes-from-peer'] }), as(bare.lead),
+ { ...stored(), approvals: [approval('yes-from-peer', { kind: 'person', id: 'peer' })] }).messages).toEqual([])
const { f, lead } = pm()
+ giveOwnBuddy(f.state, 'peer')
const effects = f.run(save(1, doc(tony, quiet), { askedBy: 'owner', approvals: ['yes-from-peer'] }), as(lead),
{ ...stored(), approvals: [approval('yes-from-peer', { kind: 'person', id: 'peer' })] })
expect(effects.result.revision).toBe(2)
@@ -453,6 +459,7 @@ describe('an instructions save keeps the rules people gave', () => {
expect(notices.length).toBeGreaterThan(0)
for (const notice of notices) {
expect(notice.recipients).toEqual([])
+ expect(notice.author).toMatchObject({ kind: 'agent', id: 'peer-buddy' })
expect(notice.text.split('\n')).toHaveLength(1)
expect(notice.text).toContain('A bug that reaches stable')
const chat = f.state.conversations.find(c => c.id === notice.conversationId)!
diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.ts
index 6fedcfe20..ed7feb8c6 100644
--- a/backend/src/superTabs/model.ts
+++ b/backend/src/superTabs/model.ts
@@ -872,7 +872,7 @@ export const NOTICE_READERS = {
// A member removed one of the coordinator's notes: told to the coordinator alone (instructions.ts).
'note-removed': 'recipients',
'project-report': 'people', route: 'people', 'route-override': 'people', 'buddy-proposal': 'people', 'buddy-proposal-sent': 'people', 'buddy-session-ended': 'people',
- // Proposal history and private Buddy notices are visible to the people who can read their card/chat.
+ // Proposal history, and the private Buddy notices stored before task #4558, are visible to the people who can read their card/chat.
'proposal-card': 'people', 'proposal-answer': 'people', 'proposal-notice': 'people', 'proposal-merged': 'people', 'proposal-overdue': 'people',
'decision-delegated': 'people', 'machine-removed': 'people', ship: 'people',
// An agent's question to a person in a switched project, in their default Buddy chat (decisions.ts askedThroughBuddy, #3826).
@@ -886,9 +886,11 @@ export const NOTICE_READERS = {
'machine-left': 'agent',
// A task's one line in its project chat, edited as it moves (taskLine.ts): people read a task's state there.
'task-line': 'people',
- // A project PM's private line in a person's one Buddy chat, marked with its project (commands.ts person.tell): its person
- // reads it, as they read the line in their older project chat.
+ // A project PM's private line in a person's one Buddy chat, no longer written (task #4558: only the person and their own agent
+ // post there): its person reads the rows stored before.
'pm-line': 'people',
+ // A decider's override of a person's rule, told to them by their own Buddy in their Buddy chats (commands.ts instructions.save).
+ 'rule-approved': 'people',
// Their one Buddy cannot start in a person's older project chat, told to them there once per outage (commands.ts buddyDownLine).
'buddy-cannot-start': 'people',
'auto-archive': 'people', native: 'people',
diff --git a/backend/src/superTabs/notices.test.ts b/backend/src/superTabs/notices.test.ts
index f86d901ae..7809e9400 100644
--- a/backend/src/superTabs/notices.test.ts
+++ b/backend/src/superTabs/notices.test.ts
@@ -87,8 +87,10 @@ describe('the notices the Swarm writes into a chat', () => {
// the Shipped line, now the task's own line (taskLine.ts; Quiet Swarm, Dee, 2026-11-02), people; a machine's removal ending,
// no longer said in any chat (anh Dee, 11-04, #2742), nobody; a task's own row under its requester's name, now only a person's
// own message (anh Dee, 11-04, 'bot messages', #2925), people; an instructions save's line, now only in the Instructions
- // history (Dee and Ken, 11-05, #3132), people; the card wake-up, now written by the server (anh Dee, 11-06, #3593), the Lead.
- const retired = ['idle-stop', 'project-report', 'ship', 'machine-left', 'task-line', 'routing-reflection', 'instructions', 'update-request']
+ // history (Dee and Ken, 11-05, #3132), people; the card wake-up, now written by the server (anh Dee, 11-06, #3593), the Lead;
+ // a proposal's notices and the PM's private line in a person's Buddy chat, now on the card or refused (anh Dee, 11-07, #4558), people.
+ const retired = ['idle-stop', 'project-report', 'ship', 'machine-left', 'task-line', 'routing-reflection', 'instructions', 'update-request',
+ 'proposal-notice', 'proposal-overdue', 'pm-line']
expect(Object.keys(NOTICE_READERS).filter(kind => !written.has(kind) && !retired.includes(kind))).toEqual([])
expect(retired.filter(kind => written.has(kind))).toEqual([])
})
diff --git a/backend/src/superTabs/othersWork.test.ts b/backend/src/superTabs/othersWork.test.ts
index 497c52a4d..46c20ffc8 100644
--- a/backend/src/superTabs/othersWork.test.ts
+++ b/backend/src/superTabs/othersWork.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import { applyCommand, commandSchema, type Command, type CommandContext } from './commands.js'
import type { ContributedMachine } from './machines.js'
import { createSuperTab, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'
+import { giveOwnBuddy } from './ownBuddy.test-support.js'
import { DAY_MS, WEEK_MS, weekStart } from './leaderboard/week.js'
import { othersWorkNotice } from './othersWork.js'
@@ -13,7 +14,7 @@ const config: AgentConfiguration = { engine: 'claude', model: 'opus', effort: 'h
const NOW = Date.UTC(2026, 9, 29, 12)
const NOTICE = 'others-work-notice'
-function fixture() {
+function fixture(buddy = true) {
let state: SuperTabState = createSuperTab('tab', 'Pilot', { id: 'owner', email: owner.email }, 'prod')
let sequence = 0, now = NOW
const run = (command: Command, actor: Actor = owner, context: Partial<CommandContext> = {}) => {
@@ -28,13 +29,15 @@ function fixture() {
generation: 'g1', cwd: '/repo', scope: 'swarm', engines: ['claude'], maxAgents: 4, paused: false,
observation: { receivedAt: NOW, runningHarnessIds: [], stoppedHarnessIds: [], quotas: [{ engine: 'claude', known: true, windows: [{ name: 'weekly', usedPercent: 38, resetsAt: NOW + 3 * DAY_MS }] }] } as never }
state.machines = [pool]
+ // Each person's own Buddy, who writes the notice: only they and it post in their private chat (task #4558).
+ if (buddy) for (const me of state.people) giveOwnBuddy(state, me.id)
const add = (harnessId: string, group = 'lead', lead = false) => run({ type: 'agent.add', conversationId: group, machineId: 'host', harnessId,
name: harnessId, configuration: config, lead }, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } }).result.agentId as string
const create = (actor: Actor, extra: Record<string, unknown> = {}) =>
run(commandSchema.parse({ type: 'conversation.create', title: 'Fix login', brief: 'Fix it.', checks: [], ...extra }), actor).result.conversationId as string
const assign = (id: string, worker = add(`worker-${id}`, id)) => run({ type: 'work.assign', conversationId: id, agentId: worker })
const told = (effects: ReturnType<typeof run>) => effects.messages.filter(m => (m.source as { kind?: string } | undefined)?.kind === NOTICE)
- const buddyChat = () => state.conversations.find(c => c.kind === 'swarm-buddy')
+ const buddyChat = () => state.conversations.find(c => c.kind === 'swarm-buddy' && c.audience?.people[0]?.id === 'owner')
return { run, add, create, assign, told, buddyChat, get state() { return state }, at(ms: number) { now = ms } }
}
@@ -43,12 +46,19 @@ describe('the owner hears when someone else\'s work starts on their machine', ()
const f = fixture(), id = f.create(peer)
const told = f.told(f.assign(id))
expect(told).toEqual([expect.objectContaining({ conversationId: f.buddyChat()!.id, recipients: [], source: { kind: NOTICE, machineId: 'host' },
+ author: expect.objectContaining({ kind: 'agent', id: 'owner-buddy' }),
text: 'peer\'s work "Fix login" started on your Mac Studio (Claude, 38% of this week used, resets in 3d). '
+ 'Members › your card shows what it runs and ships; Manage › Machines can pause new work.' })])
expect(f.buddyChat()!.audience).toEqual({ people: [{ id: 'owner', generation: f.state.people[0]!.generation }] })
expect(f.state.machines![0]!.othersToldWeek).toBe(weekStart(NOW))
})
+ it('writes nothing when the owner has no Buddy, and keeps the week untold', () => {
+ const f = fixture(false)
+ expect(f.told(f.assign(f.create(peer)))).toEqual([])
+ expect(f.state.machines![0]!.othersToldWeek).toBeUndefined()
+ })
+
it('tells once a week per machine: not again this week, again next week', () => {
const f = fixture()
expect(f.told(f.assign(f.create(peer)))).toHaveLength(1)
diff --git a/backend/src/superTabs/othersWork.ts b/backend/src/superTabs/othersWork.ts
index 42a514fc4..6025987da 100644
--- a/backend/src/superTabs/othersWork.ts
+++ b/backend/src/superTabs/othersWork.ts
@@ -1,13 +1,13 @@
/**
* A machine's owner hears when someone else's work starts on it (contributor view, #2444; AGENTS.md, contributed capacity: seen:
* "their quota is never drained without them knowing"). Once per machine per leaderboard week, in their own Buddy chat, in
- * the server's words; the person card shows the rest. Someone else's work is what Lent counts (leaderboard/lent.ts): a
+ * their own agent's voice; the person card shows the rest. Someone else's work is what Lent counts (leaderboard/lent.ts): a
* task its machine's contributor did not ask for, never a PM's or a private chat's.
*/
-import { defaultBuddyChat } from './buddies.js'
+import { defaultBuddyChat, ownAgentAuthor } from './buddies.js'
import { homeOf, weeklyUse } from './leaderboard/brought.js'
import { weekStart } from './leaderboard/week.js'
-import { isLeads, type Agent, type Conversation, type SuperTabState } from './model.js'
+import { isLeads, type Agent, type Author, type Conversation, type SuperTabState } from './model.js'
import { canReadProject, groupProject, ledProject } from './projects.js'
import { usernameOf } from './usernames.js'
@@ -25,12 +25,15 @@ function until(ms: number, now: number): string {
* [engineName]: how the server names the worker's engine ("Claude").
*/
export function othersWorkNotice(state: SuperTabState, group: Conversation, worker: Agent, now: number, engineName: string):
- { conversationId: string; machineId: string; text: string } | null {
+ { conversationId: string; machineId: string; author: Author; text: string } | null {
if (group.audience || isLeads(group) || ledProject(state, worker.id)) return null
const pool = state.machines?.find(m => m.machineId === worker.machineId)
if (!pool || pool.buddyOnly || group.requesterId === pool.contributorId) return null
const owner = state.people.find(p => p.id === pool.contributorId)
- if (!owner) return null
+ // Written by the owner's own agent, as only they and it post in their private chat (task #4558); with none, their Members
+ // card still shows what runs on the machine.
+ const author = owner && ownAgentAuthor(state, owner)
+ if (!owner || !author) return null
const home = homeOf(state.machines ?? [], pool.machineId) ?? pool, week = weekStart(now)
if (home.othersToldWeek === week) return null
home.othersToldWeek = week
@@ -39,7 +42,7 @@ export function othersWorkNotice(state: SuperTabState, group: Conversation, work
const readable = canReadProject(state, { kind: 'person', userId: owner.id, email: owner.email }, groupProject(state, group))
const use = weeklyUse(home, worker.configuration.engine)
const used = use.usedPercent == null ? '' : `, ${Math.round(use.usedPercent)}% of this week used${use.resetsAt == null ? '' : `, resets in ${until(use.resetsAt, now)}`}`
- return { conversationId: defaultBuddyChat(state, owner).id, machineId: pool.machineId,
+ return { conversationId: defaultBuddyChat(state, owner).id, machineId: pool.machineId, author,
text: `${requester ? `${requester}'s` : 'A teammate\'s'} work${readable ? ` "${group.title}"` : ''} started on your ${home.name} (${engineName}${used}). `
+ 'Members › your card shows what it runs and ships; Manage › Machines can pause new work.' }
}
diff --git a/backend/src/superTabs/ownBuddy.test-support.ts b/backend/src/superTabs/ownBuddy.test-support.ts
new file mode 100644
index 000000000..db4c642ff
--- /dev/null
+++ b/backend/src/superTabs/ownBuddy.test-support.ts
@@ -0,0 +1,14 @@
+import { openSwarmBuddyChat } from './buddies.js'
+import type { Agent, SuperTabState } from './model.js'
+
+/** Gives [personId] their own default Buddy in its Swarm chat, as buddy.create and its start leave it: the agent that writes the
+ * server's notices in their private chat, where only they and it post (task #4558). */
+export function giveOwnBuddy(state: SuperTabState, personId: string, id = `${personId}-buddy`): Agent {
+ const member = state.people.find(p => p.id === personId)!
+ const buddy = { id, machineId: `${personId}-mac`, harnessId: id, machineOwnerId: personId, contributorId: personId, membershipGeneration: member.generation,
+ name: 'Buddy', configuration: { engine: 'claude', model: null, effort: null, contextWindow: null, engineVersion: null },
+ buddyOf: { personId, generation: member.generation }, buddyScope: 'swarm' } as Agent
+ state.agents.push(buddy)
+ openSwarmBuddyChat(state, member).agentIds.push(id)
+ return buddy
+}
diff --git a/backend/src/superTabs/proposalCards.test.ts b/backend/src/superTabs/proposalCards.test.ts
index 33248ff24..5f137b921 100644
--- a/backend/src/superTabs/proposalCards.test.ts
+++ b/backend/src/superTabs/proposalCards.test.ts
@@ -10,6 +10,10 @@ import { CREDENTIAL_MARKER } from './credentials.js'
const words = 'Keep edits offline until the connection returns.'
const proposal = { title: 'Offline edits', text: words, goal: 'Keep drafts', why: 'People lose offline work',
doneWhen: 'Reconnect restores edits', evidence: ['Reproduced with network disabled'], priority: 'P2' as const }
+/** Rows a command wrote in a person's private chat with their own agent, or as a proposal notice: none since task #4558. */
+const inPrivate = (f: { state: SuperTabState }, messages: Array<{ conversationId: string; source?: Record<string, unknown> | null }>) =>
+ messages.filter(m => m.source?.kind === 'proposal-notice' || m.source?.kind === 'proposal-overdue'
+ || ['buddy', 'swarm-buddy'].includes(f.state.conversations.find(c => c.id === m.conversationId)?.kind ?? ''))
function fixture(switched = true) {
const f = fullSwarm(NOW)
if (switched) Object.assign(f.state.projects![0]!, { boardMode: true })
@@ -159,7 +163,7 @@ const ask = (conversationId: unknown, extra = {}) => ({ type: 'proposal.ask', co
question: 'Keep drafts for seven days?', defaultAnswer: 'Keep seven days', deadline, ...extra })
describe('PM decisions and card questions', () => {
- it('sends shipped notices once to every proposer after verified release, never at merge', async () => {
+ it('shows shipped on the card after verified release, never at merge, and tells no proposer privately', async () => {
const { notePendingRelease, pendingKey, settleReleases } = await import('./releases.js')
const { shippedNotice } = await import('./buddyNews.js')
const { author } = await import('./model.js')
@@ -174,8 +178,9 @@ describe('PM decisions and card questions', () => {
expect(settleReleases(f.state, 'lead', facts, NOW).messages.filter(m => m.source?.moment === 'shipped')).toHaveLength(0)
const verified = { resolved: [], releases: { backend: { tag: 'v1.0.0_backend', sha: 'verified', at: NOW + 1000, carries: [pendingKey(entry)] } } }
const result = settleReleases(f.state, 'lead', verified, NOW + 1000)
- expect(result.messages.filter(m => m.source?.moment === 'shipped')).toHaveLength(2)
- expect(settleReleases(f.state, 'lead', verified, NOW + 2000).messages.filter(m => m.source?.moment === 'shipped')).toHaveLength(0)
+ // The card says it shipped; no proposer's private chat gets a line (task #4558).
+ expect(f.card(id).released).toMatchObject({ at: NOW + 1000 })
+ expect(inPrivate(f, result.messages)).toEqual([])
})
it.each(['accept', 'reshape', 'later', 'no'])('records %s with its reason on the same card exactly once', decision => {
@@ -183,7 +188,7 @@ describe('PM decisions and card questions', () => {
const result = f.run(decide(id, decision, decision === 'later' ? { revisitAt: deadline } : {}), f.pm)
expect(f.card(id).proposal?.decision).toMatchObject({ kind: decision, reason: 'Prevents lost work for contributors', at: NOW, by: f.lead })
expect(result.messages.some(m => m.conversationId === id && m.text.includes('Prevents lost work'))).toBe(true)
- expect(result.messages.some(m => m.source?.kind === 'proposal-notice' && m.source.moment === 'decided')).toBe(true)
+ expect(inPrivate(f, result.messages)).toEqual([])
if (['accept', 'reshape'].includes(decision)) {
expect(f.card(id).task).toEqual(acceptedTask)
expect(queueSiblings(f.state, f.state.projects![0]!)).toContainEqual(f.card(id))
@@ -211,7 +216,13 @@ describe('PM decisions and card questions', () => {
// A direct Board proposal has no sending Buddy: its current default may answer for its person.
const asked = f.run(ask(id), f.pm), q = f.card(id).proposal!.questions[0]!
expect(q).toMatchObject({ personId: peer.userId, question: 'Keep drafts for seven days?', defaultAnswer: 'Keep seven days', deadline, requiresConsent: false })
- expect(asked.messages.some(m => m.source?.kind === 'proposal-notice' && m.source.moment === 'needs-you')).toBe(true)
+ expect(inPrivate(f, asked.messages)).toEqual([])
+ // An ordinary question tags nobody: it has a default. One that needs the person's own agreement has none, so it tags them on
+ // the card, which reaches their inbox and phone with or without a Buddy (security review of #4558).
+ expect(asked.messages.find(m => m.source?.kind === 'proposal-question')!.mentions).toBeUndefined()
+ const consent = f.run(ask(id, { requiresConsent: true, question: 'Share your drafts?' }), f.pm)
+ expect(consent.messages.find(m => m.source?.kind === 'proposal-question')).toMatchObject({ conversationId: id, mentions: [peer.userId] })
+ expect(inPrivate(f, consent.messages)).toEqual([])
const answer = { type: 'proposal.answer', conversationId: id, questionId: q.id, text: 'Keep fourteen days' }
expect(() => f.run(answer, outsider)).toThrow(expect.objectContaining({ code: 'PROPOSAL_ANSWER_FORBIDDEN' }))
f.state.people.find(p => p.id === peer.userId)!.role = 'viewer'
@@ -265,12 +276,12 @@ describe('PM decisions and card questions', () => {
expect(f.card(id).proposal!.questions[0]!.answer?.by).toBe(fallback.id)
})
- it('merges duplicates into one card, preserving attribution and notifying every proposer', () => {
+ it('merges duplicates into one card, preserving attribution, and writes nothing in a proposer\'s private chat', () => {
const f = fixture(), first = f.create().result.conversationId, second = f.create(outsider).result.conversationId
const merged = f.run({ type: 'proposal.merge', conversationId: second, intoConversationId: first, reason: 'Same reconnect loss' }, f.pm)
expect(f.card(second)).toMatchObject({ archived: true, proposal: { mergedInto: first } })
expect(f.card(first).proposal!.senders.map(s => s.personId).sort()).toEqual([peer.userId, outsider.userId].sort())
- expect(merged.messages.filter(m => m.source?.kind === 'proposal-notice')).toHaveLength(2)
+ expect(inPrivate(f, merged.messages)).toEqual([])
expect(() => f.run({ type: 'proposal.merge', conversationId: first, intoConversationId: second, reason: 'Cycle' }, f.pm)).toThrow()
expect(() => f.run({ type: 'proposal.merge', conversationId: first, intoConversationId: f.secretGroup, reason: 'Other project' }, f.pm)).toThrow()
const third = f.create(owner).result.conversationId
@@ -303,9 +314,8 @@ describe('credentials in proposal words', () => {
sent.push(f.run({ type: 'proposal.merge', conversationId: f.create(owner).result.conversationId, intoConversationId: id, reason: `Same as ${token}` }, f.pm))
const ruled = f.run(decide(id, 'accept', { reason: `Rotate ${token} first`, task: { ...acceptedTask, changes: `Remove ${token}` },
checks: [{ description: `No ${token} in logs`, independent: false }] }), f.pm)
- // Both proposers hear the ruling in their Buddy chats, in its cleaned words.
- const notices = ruled.messages.filter(m => m.source?.kind === 'proposal-notice')
- expect(notices.map(m => m.text)).toEqual([0, 1].map(() => `Rotate ${CREDENTIAL_MARKER}: accept. Rotate ${CREDENTIAL_MARKER} first`))
+ // The ruling stays on the card, in its cleaned words; no proposer's private chat gets a copy (task #4558).
+ expect(inPrivate(f, ruled.messages)).toEqual([])
expect(f.card(id).proposal!.decision!.reason).toBe(`Rotate ${CREDENTIAL_MARKER} first`)
expect(f.card(id).proposal!.questions[0]!.answer!.text).toBe(`Yes, ${CREDENTIAL_MARKER}`)
expect(JSON.stringify([...sent, ruled].map(e => e.messages))).not.toContain(token)
@@ -337,7 +347,7 @@ describe('proposal time and delivery boundaries', () => {
it('marks explicit consent overdue without defaulting, and still permits the named person', async () => {
const { advanceProposalCards } = await import('./proposalCards.js')
const f = fixture(), id = f.create().result.conversationId, qid = f.run(ask(id, { requiresConsent: true }), f.pm).result.questionId
- advanceProposalCards(f.state, deadline)
+ expect(inPrivate(f, advanceProposalCards(f.state, deadline))).toEqual([])
expect(f.card(id).proposal!.questions[0]).toMatchObject({ overdue: true })
expect(f.card(id).proposal!.questions[0]!.answer).toBeUndefined()
expect(advanceProposalCards(f.state, deadline + 1)).toEqual([])
@@ -353,7 +363,7 @@ describe('proposal time and delivery boundaries', () => {
expect(f.card(id).proposal!.decision).toBeUndefined()
const overdue = advanceProposalCards(f.state, date + 30 * 60_000)
expect(f.card(id).proposal!.overdue).toBe(true)
- expect(overdue.some(m => m.source?.kind === 'proposal-overdue')).toBe(true)
+ expect(inPrivate(f, overdue)).toEqual([])
expect(advanceProposalCards(f.state, date + 31 * 60_000)).toEqual([])
})
diff --git a/backend/src/superTabs/proposalCards.ts b/backend/src/superTabs/proposalCards.ts
index f53b6b78c..23aabc7fa 100644
--- a/backend/src/superTabs/proposalCards.ts
+++ b/backend/src/superTabs/proposalCards.ts
@@ -5,7 +5,7 @@ export { advanceProposalCards, proposalDueAt } from './proposalClock.js'
/** Durable proposal metadata lives on its existing version-guarded card. Discussion stays in message rows. */
import { z } from 'zod'
import { author, fail, nextConversationNumber, person, stableId, type Actor, type Author, type Conversation, type MessageDraft, renderWorkTask, type SuperTabState } from './model.js'
-import { buddyFor, defaultBuddy, isBuddy } from './buddies.js'
+import { defaultBuddy, isBuddy } from './buddies.js'
import { recordAsked } from './leaderboard/record.js'
import { stampLane } from './dispatch.js'
import { groupProject, ledProject, readConversation, canReadProject, readProject, type SwarmProject } from './projects.js'
@@ -155,19 +155,6 @@ export function authorizeProposalAction(state: SuperTabState, actor: Actor, comm
}
}
-/** Notices stay inside the consenting person's private Buddy chat, including when no Buddy can currently run. */
-export function proposalNotices(state: SuperTabState, card: Conversation & { proposal: ProposalRecord }, moment: 'decided' | 'needs-you' | 'shipped',
- text: string, sender: Author, operationId: string, recipients = card.proposal.senders): MessageDraft[] {
- const project = groupProject(state, card)
- return recipients.flatMap((identity, i) => {
- const member = state.people.find(p => p.id === identity.personId && p.generation === identity.generation)
- if (!member || !canReadProject(state, { kind: 'person', userId: member.id, email: member.email }, project)) return []
- const route = buddyFor(state, member, identity.buddyId ?? null)
- return [{ id: stableId(operationId, 'proposal-notice', String(i), moment), conversationId: route.chat.id, author: sender,
- text, replyTo: null, recipients: route.agent ? [route.agent.id] : [], buddyProject: project.id,
- source: { kind: 'proposal-notice', moment, projectId: project.id, cardId: card.id } }]
- })
-}
function pending(card: Conversation & { proposal: ProposalRecord }): void {
if (card.proposal.decision || card.proposal.mergedInto) fail('PROPOSAL_DECIDED', 'This proposal already has a decision or was merged.', 409)
}
@@ -196,9 +183,10 @@ export function applyProposalAction(state: SuperTabState, actor: Actor, command:
deadline: command.deadline, requiresConsent: command.requiresConsent ?? false }
card.proposal.questions.push(q)
result.questionId = q.id
+ // On the card alone: no line in the proposer's private chat with their own agent (task #4558). One that needs their own
+ // agreement has no default to fall back on, so it tags them there: their inbox and phone, with or without a Buddy.
row(`${q.question}\nDefault: ${q.defaultAnswer}\nBy: ${new Date(q.deadline).toISOString()}`, { kind: 'proposal-question', questionId: q.id })
- messages.push(...proposalNotices(state, card, 'needs-you', `${card.title}: ${q.question}`, sender, operationId,
- currentSender(state, card, command.personId)))
+ if (q.requiresConsent) messages.at(-1)!.mentions = [q.personId]
} else if (command.type === 'proposal.decide') {
pending(card)
if (hasOpenQuestion(card)) fail('PROPOSAL_QUESTION_OPEN', 'Answer the open questions before deciding.', 409)
@@ -220,7 +208,6 @@ export function applyProposalAction(state: SuperTabState, actor: Actor, command:
delete card.proposal.overdue
if (command.decision === 'no') card.archived = true
row(`${command.decision}: ${command.reason}`, { kind: 'proposal-decision', decision: command.decision })
- messages.push(...proposalNotices(state, card, 'decided', `${card.title}: ${command.decision}. ${command.reason}`, sender, operationId))
} else {
if (card.taskApproval) fail('TASK_APPROVAL_REQUIRED', 'Keep Review proposals separate so each person’s decision and chosen agent stay attached.', 409)
pending(card)
@@ -245,7 +232,6 @@ export function applyProposalAction(state: SuperTabState, actor: Actor, command:
row(`Merged into #${target.number}: ${command.reason}`, { kind: 'proposal-merged', intoConversationId: target.id })
messages.push({ id: stableId(operationId, 'merge-target'), conversationId: target.id, author: sender, text: `Merged #${card.number}: ${command.reason}`,
recipients: target.leadId ? [target.leadId] : [], replyTo: null, source: { kind: 'proposal-merged' } })
- messages.push(...proposalNotices(state, target, 'decided', `${card.title} was merged into ${target.title}. ${command.reason}`, sender, operationId))
result.conversationId = target.id
}
return { messages, result }
diff --git a/backend/src/superTabs/proposalClock.ts b/backend/src/superTabs/proposalClock.ts
index 85521af66..832508348 100644
--- a/backend/src/superTabs/proposalClock.ts
+++ b/backend/src/superTabs/proposalClock.ts
@@ -1,7 +1,7 @@
/** Timed proposal transitions run in the existing singleton worker and the answering card's transaction. */
import { author, stableId, type Author, type Conversation, type MessageDraft, type SuperTabState } from './model.js'
import { groupProject } from './projects.js'
-import { proposalNotices, type ProposalQuestion, type ProposalRecord } from './proposalCards.js'
+import type { ProposalQuestion, ProposalRecord } from './proposalCards.js'
export const PROPOSAL_WAIT_MS = 30 * 60_000
export type ProposalCard = Conversation & { proposal: ProposalRecord }
@@ -23,12 +23,12 @@ function clockAuthor(state: SuperTabState, card: ProposalCard): Author {
}
export function expireProposalQuestion(state: SuperTabState, card: ProposalCard, q: ProposalQuestion, now: number): MessageDraft[] {
if (q.answer || q.overdue || now < q.deadline) return []
- const sender = clockAuthor(state, card), id = stableId(q.id, 'deadline')
+ // Agreement overdue shows on the card alone: no line in the person's private chat (task #4558).
if (q.requiresConsent) {
q.overdue = true
- return proposalNotices(state, card, 'needs-you', `${card.title}: agreement is overdue. ${q.question}`, sender, id,
- card.proposal.senders.filter(s => s.personId === q.personId))
+ return []
}
+ const sender = clockAuthor(state, card), id = stableId(q.id, 'deadline')
q.answer = { text: q.defaultAnswer, at: q.deadline, by: 'default', defaulted: true }
return [{ id, conversationId: card.id, author: sender, text: q.defaultAnswer, recipients: card.leadId ? [card.leadId] : [], replyTo: null,
source: { kind: 'proposal-answer', questionId: q.id, defaulted: true, applied: true } }]
@@ -37,7 +37,7 @@ export function advanceProposalCards(state: SuperTabState, now: number): Message
const messages: MessageDraft[] = []
for (const group of state.conversations) {
if (!group.proposal || group.proposal.mergedInto) continue
- const card = group as ProposalCard, record = card.proposal, project = groupProject(state, card)
+ const card = group as ProposalCard, record = card.proposal
if (record.decision?.kind === 'later' && now >= record.decision.revisitAt!) {
const date = record.decision.revisitAt!
delete record.decision
@@ -48,15 +48,8 @@ export function advanceProposalCards(state: SuperTabState, now: number): Message
recipients: card.leadId ? [card.leadId] : [], replyTo: null, source: { kind: 'proposal-card', priority: card.priority } })
}
for (const q of record.questions) messages.push(...expireProposalQuestion(state, card, q, now))
- if (!record.decision && !record.overdue && now >= (record.waitSince ?? record.createdAt) + PROPOSAL_WAIT_MS) {
- record.overdue = true
- const owner = state.people.find(p => p.id === project.ownerId)
- if (owner) {
- const rows = proposalNotices(state, card, 'needs-you', `${card.title} has waited over 30 minutes for a PM decision.`, clockAuthor(state, card),
- stableId(card.id, 'overdue', String(record.waitSince ?? record.createdAt)), [{ personId: owner.id, generation: owner.generation }])
- messages.push(...rows.map(row => ({ ...row, source: { ...row.source, kind: 'proposal-overdue' } })))
- }
- }
+ // Overdue shows on the card alone: no line in the project owner's private chat (task #4558).
+ if (!record.decision && !record.overdue && now >= (record.waitSince ?? record.createdAt) + PROPOSAL_WAIT_MS) record.overdue = true
}
return messages
}
diff --git a/backend/src/superTabs/proposalMetrics.ts b/backend/src/superTabs/proposalMetrics.ts
index 4b1ebe35a..e3e0a5cf9 100644
--- a/backend/src/superTabs/proposalMetrics.ts
+++ b/backend/src/superTabs/proposalMetrics.ts
@@ -2,7 +2,7 @@ import { Counter, Histogram } from 'prom-client'
import { metrics } from '../lib/metrics.js'
import type { MessageDraft, SuperTabState } from './model.js'
-type Event = 'created' | 'decided' | 'answered' | 'defaulted' | 'overdue' | 'revisited' | 'merged' | 'shipped'
+type Event = 'created' | 'decided' | 'answered' | 'defaulted' | 'revisited' | 'merged'
interface Measure { event: Event; seconds?: number }
const events = new Counter({ name: 'swarm_proposal_events_total', help: 'Committed proposal transitions', labelNames: ['event'] as const, registers: [metrics.registry] })
const waits = new Histogram({ name: 'swarm_proposal_wait_seconds', help: 'Proposal decision and answer waits', labelNames: ['event'] as const,
@@ -17,8 +17,6 @@ export function proposalMeasures(values: Measure[]): void {
}
export function proposalMessageMeasures(state: SuperTabState, messages: MessageDraft[], now: number): Measure[] {
return messages.flatMap<Measure>(m => {
- if (m.source?.kind === 'proposal-overdue') return [{ event: 'overdue' }]
- if (m.source?.kind === 'proposal-notice' && m.source.moment === 'shipped') return [{ event: 'shipped' }]
const record = state.conversations.find(c => c.id === m.conversationId)?.proposal
if (!record) return []
const source = m.source, kind = source?.kind
diff --git a/backend/src/superTabs/releases.ts b/backend/src/superTabs/releases.ts
index 701653294..4e8b6cde9 100644
--- a/backend/src/superTabs/releases.ts
+++ b/backend/src/superTabs/releases.ts
@@ -1,4 +1,3 @@
-import { proposalNotices } from './proposalCards.js'
import { shippedNotice } from './buddyNews.js'
/**
* Releases scheduled by the Swarm (task #3405, anh Dee's Swarm redesign, 2026-11-05: the server does the routine). A merge
@@ -281,20 +280,15 @@ export function settleReleases(state: SuperTabState, projectId: string, facts: R
}
- // Shipped once a verified release holds all of it (task #4217: a merge alone is not shipped): a proposal's card says so, and a
- // task's requester's Buddy hears it, by an id the release fixes, so a settle retried tells nobody twice.
+ // Shipped once a verified release holds all of it (task #4217: a merge alone is not shipped): a proposal's card says so, and only
+ // there (task #4558); a task's requester's Buddy hears it, by an id the release fixes, so a settle retried tells nobody twice.
if (lead) for (const id of new Set(outcome.shipped)) {
const group = state.conversations.find(c => c.id === id)
if (!group || group.releasing) continue
const sender = { kind: 'agent' as const, id: lead.id, name: lead.name, membershipGeneration: lead.membershipGeneration }
const once = stableId(group.id, 'shipped', String(group.released!.at))
- if (group.proposal) {
- outcome.messages.push(...proposalNotices(state, group as Conversation & { proposal: NonNullable<Conversation['proposal']> },
- 'shipped', `${group.title} shipped.`, sender, once))
- } else {
- const news = shippedNotice(state, group, sender, once)
- if (news) outcome.messages.push(news)
- }
+ const news = shippedNotice(state, group, sender, once)
+ if (news) outcome.messages.push(news)
}
for (const component of RELEASE_COMPONENTS) {
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index be508022e..434209b9b 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -1098,8 +1098,6 @@ export class SuperTabStore {
// And their one Buddy chat, which takes it too (spec: Guard).
if (asked && command.delegate) swarmChat(asked.personId)
}
- // A private line from an agent goes to the person's default Buddy (task #3818): their Buddy chats, quiet or not.
- if (command.type === 'person.tell') swarmChat(command.personId)
// A switch's result tells the machine's owner in their one Buddy chat, quiet or not (commands.ts agent.switchResult).
if (command.type === 'agent.switchResult') swarmChat(state.agents.find(a => a.id === command.agentId)?.machineOwnerId)
// A project's sharing ends its sessions in the one Buddy chats of whoever loses it (commands.ts endLostProjectSessions).
@@ -1164,12 +1162,6 @@ export class SuperTabStore {
const chat = projectsOf(state).find(p => p.id === projectId)?.leadConversationId
if (chat) groupIds.push(chat)
}
- // Any agent of a project tells a person in that project's Buddy chat (commands.ts person.tell), loaded even when quiet.
- if (command.type === 'person.tell' && asAgentId) {
- const self = state.agents.find(a => a.id === asAgentId)
- if (self) buddyChat(agentProjectId(state, self), command.personId)
- swarmChat(command.personId)
- }
if (command.type === 'delivery.resolve') {
const delivery = await tx.superTabDelivery.findFirst({ where: { id: command.deliveryId, tabId }, select: { conversationId: true } })
if (delivery) groupIds.push(delivery.conversationId)
@@ -4737,21 +4729,12 @@ export class SuperTabStore {
if (!group || !sender) return false
const actor: Actor = delivery.authorKind === 'person' ? { kind: 'person', userId: delivery.authorId, email: '' }
: { kind: 'agent', agentId: delivery.authorId, machineOwnerId: (sender as Agent).machineOwnerId }
- const outsideChat = !canReadGroup(state, actor, group)
- if (ledProject(state, delivery.agentId)?.boardMode || outsideChat) {
+ // A sender outside the conversation delivers nothing there: no other agent writes in a person's private chat (task #4558).
+ if (!canReadGroup(state, actor, group)) return false
+ if (ledProject(state, delivery.agentId)?.boardMode) {
const source = knownSource === undefined
? (await tx.superTabMessage.findUnique({ where: { id: delivery.messageId }, select: { source: true } }))?.source : knownSource
if (!pmAcceptsMessage(state, delivery.agentId, source)) return false
- if (outsideChat) {
- // A server-written proposal notice may enter its person's private Buddy chat without giving its author read access.
- const notice = source as { kind?: string; projectId?: string } | null
- const project = projectsOf(state).find(p => p.id === notice?.projectId)
- const target = state.agents.find(a => a.id === delivery.agentId)
- if (!isBuddyChat(group) || !target || !isBuddy(target) || !project
- || !['proposal-notice', 'proposal-overdue'].includes(notice?.kind ?? '')
- || !canReadProject(state, actor, project)
- || !canReadProject(state, { kind: 'agent', agentId: target.id, machineOwnerId: target.machineOwnerId }, project)) return false
- }
}
if (delivery.nativeContextId && !await this.native.allowsDelivery(tx, state, delivery.nativeContextId)) return false
if (delivery.authorKind !== 'agent') return true
diff --git a/backend/src/superTabs/taskApproval.test.ts b/backend/src/superTabs/taskApproval.test.ts
index c7e8f5003..5f9ea0421 100644
--- a/backend/src/superTabs/taskApproval.test.ts
+++ b/backend/src/superTabs/taskApproval.test.ts
@@ -313,16 +313,15 @@ describe('personal approval enforced before work', () => {
{ proposal: { id: row.id, conversationId: row.conversationId, author: row.author, source: row.source ?? null } })
expect(f.state.conversations.find(c => c.proposal?.legacyMessageId === row.id)?.archived).toBe(true)
})
- it('tells the person, through their Buddy, that the PM closed their proposal and why (task #4252, audit 18)', () => {
+ it('records on the card that the PM closed their proposal and why, with no line in their private chat (tasks #4252, #4558)', () => {
const f = fixture(false); const sent = f.propose()
const row = sent.messages.find(m => m.source?.kind === 'buddy-proposal')!
const closed = f.runCommand({ type: 'proposal.close', projectId: 'lead', messageId: row.id, reason: 'Out of scope' }, f.pm,
{ proposal: { id: row.id, conversationId: row.conversationId, author: row.author, source: row.source ?? null } })
- const notice = closed.messages.find(m => m.source?.kind === 'proposal-notice')
const mirror = f.state.conversations.find(c => c.proposal?.legacyMessageId === row.id)!
- // Routed as a board decision's notice is (buddies.ts buddyFor).
- expect(notice).toMatchObject({ source: { moment: 'decided', cardId: mirror.id } })
- expect(notice!.text).toContain('Out of scope')
+ expect(mirror.proposal!.decision).toMatchObject({ kind: 'no', reason: 'Out of scope' })
+ const privateChats = new Set(f.state.conversations.filter(c => c.kind === 'buddy' || c.kind === 'swarm-buddy').map(c => c.id))
+ expect(closed.messages.filter(m => privateChats.has(m.conversationId) || m.source?.kind === 'proposal-notice')).toEqual([])
})
it('redacts a pasted credential from a rejection before its reason reaches stored parts or messages', () => {
const token = ['sk', 'AbCdEf0123456789'.repeat(3)].join('-') // Synthetic fixture, never a provider credential.
diff --git a/docs/plans/2026-11-07-private-chat-hotfix-plan.md b/docs/plans/2026-11-07-private-chat-hotfix-plan.md
new file mode 100644
index 000000000..5bfb12131
--- /dev/null
+++ b/docs/plans/2026-11-07-private-chat-hotfix-plan.md
@@ -0,0 +1,45 @@
+# Hotfix #4558: only the person and their own agent post in their private chat — Plan
+
+> Written by the Engineer and implemented by it, task by task, test first. No Execution Handoff.
+
+**Goal:** A Lead (River, Theo) or any agent other than a person's own agent never posts in that person's private chat with
+their own agent. Ships as a backend hotfix ahead of the full fix #4547.
+
+**Architecture:** One server rule in `applyCommand` (backend/src/superTabs/commands.ts): every row a command writes into a
+Buddy chat (`isBuddyChat`) must come from the chat's own person or an agent that is their Buddy, else the command is refused
+with `PRIVATE_CHAT`, naming the project chat or the task's chat as the place to post. Each path that wrote another agent's row
+there stops or moves, so no working command meets the refusal.
+
+**Tech Stack:** TypeScript backend, vitest.
+
+**Spec:** Task #4558 brief; anh Dee in project chat 19:05, 11-07: "I don't want River or Theo to show up in this chat".
+
+## Global Constraints
+
+- Backend only. Nothing the person needs is lost: a proposal's decision, question and shipping show on its card; a decision
+ asked of them waits in their Needs you list.
+- No schema or stored-data change; old rows stay as they are.
+
+## Review Focus
+
+- No path writes another agent's row into a person's private chat; the person's own agent still posts there.
+- The refusal names where to post instead.
+
+## Tasks
+
+### 1. The rule
+Files: `backend/src/superTabs/buddies.ts`, `backend/src/superTabs/commands.ts`, `backend/src/superTabs/privateChat.test.ts`
+- [ ] Failing test: a Lead's private line (`person.tell`), another project's Lead's line, and an agent's `message.send` into a
+ person's Buddy chat are refused with `PRIVATE_CHAT`; the person's own Buddy still posts there.
+- [ ] Code: `refuseOthersInPrivateChat` checked over every command's rows in `applyCommand`; `person.tell` from a PM refuses.
+
+### 2. Proposal notices
+Files: `backend/src/superTabs/proposalCards.ts`, `proposalClock.ts`, `releases.ts`, `commands.ts`, `store.ts`, `proposalMetrics.ts`
+- [ ] Failing test: a Lead's accept, ask, merge, the 30-minute overdue clock and a verified release write no row outside the card.
+- [ ] Code: `proposalNotices` and its callers go; the store's delivery exception for them goes.
+
+### 3. The other Lead lines
+Files: `backend/src/superTabs/commands.ts`, `decisions.ts`
+- [ ] Failing test: a rule-override notice goes to the project chat tagging the person; a decision asked or delegated writes
+ nothing in the Buddy chat; the PM-switch and others'-work notices to a machine owner are written by that owner's Buddy.
+- [ ] Code: as the test says.
diff --git a/docs/swarms.md b/docs/swarms.md
index ae7a919d9..d2363c07c 100644
--- a/docs/swarms.md
+++ b/docs/swarms.md
@@ -249,14 +249,13 @@ Buddies are on in every Swarm; there is no setting. They replaced Chat with PM (
listening, and a refused post shows as an error on the dial, never as words in a terminal. A new line from the
Buddy is quiet: no beep and no inbox entry, only the lower dot turning lilac and "Your Buddy replied", until you
open the Buddy screen.
-- **The product manager's lines to one person.** What the product manager tells one person directly goes to that
- person's Buddy chat in the project (a line it sends with `person.tell`, and the line saying what it chose for a
- decision left to it). The chat opens for the line if the person has none yet, so no line drops. Such a line reads
- as "River (PM) → you": the product manager writes there but cannot read the chat. It is addressed to the person;
- their Buddy does not answer it for them. They answer in the project chat, or through a proposal.
- Such a line is not secret from the project: every project member watching the product manager's terminal sees what
- it sends (Ken, 2026-10-28), and, as with any session, so does the owner of the machine running it. The product
- manager puts nothing there it would not say in the project chat.
+- **Only you and your own agent post in your private chat** (anh Dee, 2026-11-07). No product manager, Lead or other
+ agent writes in a person's chat with their own Buddy: the server refuses it and says to post in the project chat,
+ tagging them, or in the task's chat. A product manager's direct line to one person (`person.tell`) is refused for that
+ reason. What the server tells a person there (a decision asked of them or what the product manager chose for one, a
+ teammate's work starting on their machine, their account running a product manager) is written by their own Buddy;
+ with no Buddy it is not written, and Needs you, their Members card or the proposal's card still shows it. A proposal's
+ decision, question, overdue and shipped state show on its card only.
- Each person may add one Buddy per project. They choose the project, one of their own machines in the Swarm's Machines
list, and Claude Code or Codex. A Buddy runs only on its owner's own machine, in their own
account: never on a machine shared with them, and never in a Harness Team account. A Windows machine needs a Harness