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.

Merge batch 11-05 i1425: #3101 (#3120)

0xken15216730a469f0
diff --git a/backend/integration/superTabInstructions.test.ts b/backend/integration/superTabInstructions.test.ts
index 5e0697ed4..17c265600 100644
--- a/backend/integration/superTabInstructions.test.ts
+++ b/backend/integration/superTabInstructions.test.ts
@@ -100,7 +100,7 @@ describe('project instructions storage', () => {
expect(head.map(p => p.instructionsRevision)).toEqual([1, 1])
})
- it('refuses the second of two saves on the same revision with the first one\'s text, and posts one line per save', async () => {
+ it('refuses the second of two saves on the same revision with the first one\'s text, and posts no line for either save', async () => {
const tab = (await store.create(owner, randomUUID(), 'Pilot')).id
await invite(tab)
const first = await post(owner, tab, save(1, 'Reviews run on Opus.', 'Reviews run on Opus'))
@@ -109,11 +109,11 @@ describe('project instructions storage', () => {
expect(second.statusCode).toBe(409)
expect(second.json().error).toMatchObject({ code: 'INSTRUCTIONS_STALE', revision: 2, text: 'Reviews run on Opus.' })
expect((await post(peer, tab, save(2, 'Reviews run on Opus.\nTests run on the Mac.', 'Tests run on the Mac'))).statusCode).toBe(200)
+ // No chat line for a save (#3132); each stays a kept revision.
const lines = (await store.messages(owner, tab, 'lead', {})).messages.filter(m => (m.source as { kind?: string } | null)?.kind === 'instructions')
- // Each line shows what its save really changed against the stored revision before it (#3021): the first replaced the template.
- expect(lines.map(m => m.text)).toEqual([expect.stringMatching(/^owner changed the instructions: Reviews run on Opus\.\n\nRemoved section: Project instructions\n[^]*\n\nand \d+ more changes\.$/),
- // Its text adds a line to the same paragraph (no blank line), so the paragraph shows whole, as it was and as it is.
- 'peer changed the instructions: Tests run on the Mac.\n\nRemoved: Reviews run on Opus.\nAdded: Reviews run on Opus. Tests run on the Mac.'])
+ expect(lines).toEqual([])
+ expect((await db.superTabInstructionsRevision.findMany({ where: { tabId: tab, projectId: 'lead' }, orderBy: { revision: 'asc' } })).map(r => [r.revision, r.summary]))
+ .toEqual([[1, expect.any(String)], [2, 'Reviews run on Opus'], [3, 'Tests run on the Mac']])
expect((await db.superTabInstructions.findFirstOrThrow({ where: { tabId: tab, projectId: 'lead' } })).revision).toBe(3)
})
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.ts
index 0bbb33939..8ad63761f 100644
--- a/backend/integration/superTabs.test.ts
+++ b/backend/integration/superTabs.test.ts
@@ -1820,9 +1820,8 @@ describe('Super Tabs on a real Mongo replica set', () => {
expect(revisions.map(r => [r.revision, r.askedBy, r.summary])).toEqual([[1, owner.sub, expect.any(String)],
[2, owner.sub, 'Routing: Never use Haiku.'], [3, peer.sub, 'Routing: Haiku writes docs.']])
expect((await store.read(owner, tab)).state).not.toHaveProperty('rules')
- // The save's own row is the system's: quoting it names no one.
- const row = (await store.messages(owner, tab, 'lead', {})).messages.find(m => m.text.includes('changed the instructions'))!
- await expect(run(tab, rule(row.id), host, lead)).rejects.toMatchObject({ code: 'ASKED_BY_REQUIRED' })
+ // A save posts no row in the chat (#3132): the revisions above are where it is read.
+ expect((await store.messages(owner, tab, 'lead', {})).messages.filter(m => m.text.includes('changed the instructions'))).toEqual([])
})
it('lets a project\'s Lead write a rule from the owner\'s message into that project\'s instructions, and answers a removal', async () => {
// Backend v1.3.14 refused it: a Swarm of projects has no 'lead' chat.
@@ -1839,8 +1838,8 @@ describe('Super Tabs on a real Mongo replica set', () => {
expect((await run(tab, { type: 'rule.remove', ruleId: 'old', askedIn }, host, lead)).result).toMatchObject({ ignored: true })
expect((await store.read(owner, tab)).state).not.toHaveProperty('rules')
const rows = (await store.messages(owner, tab, chat, {})).messages.filter(m => m.source).map(m => m.text)
- // After the row naming who added the Lead (#2207).
- expect(rows).toEqual([expect.stringMatching(/^owner added [^.]+\.$/), 'Lead changed the instructions for owner: Routing: Only this Mac.\n\nIn Routing:\nAdded: Only this Mac.'])
+ // Only the row naming who added the Lead (#2207): the save posts none (#3132).
+ expect(rows).toEqual([expect.stringMatching(/^owner added [^.]+\.$/)])
expect((await store.read(owner, tab)).state.projects!.map(p => p.id)).toEqual([projectId])
})
it('keeps a new Swarm\'s folder from tab.project on its first project, so the repository can be shared and the host uses it', async () => {
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.ts
index 48f812d39..b7392054a 100644
--- a/backend/src/superTabs/commands.test.ts
+++ b/backend/src/superTabs/commands.test.ts
@@ -3076,16 +3076,15 @@ describe('the owner\'s rules', () => {
expect(effects.instructions).toEqual({ projectId: 'lead', revision: 2, hash: instructionsHash(text), text, summary: 'Routing: No Haiku.',
writtenBy: { kind: 'agent', id: f.lead }, askedBy: 'owner', at: 1000 })
expect(f.state.projects![0]).toMatchObject({ instructionsRevision: 2, instructionsHash: instructionsHash(text) })
- // One line, as any save: in the writer's name, for the member who asked.
- expect(effects.messages).toEqual([expect.objectContaining({ conversationId: 'lead', text: 'lead changed the instructions for owner: Routing: No Haiku.\n\nIn Routing:\nAdded: No Haiku.',
- source: { kind: 'instructions', projectId: 'lead', revision: 2 } })])
+ // A save posts no line in any chat (#3132); the revision is in the history.
+ expect(effects.messages).toEqual([])
expect(f.state).not.toHaveProperty('rules')
// A project at revision 0 runs on the template: the rule lands in its copy, as revision 1. A person asks for themselves.
delete f.state.projects![0]!.instructionsRevision
const first = f.run(set({ kind: 'preferIdle' }, 'Idle agents first.'))
expect(first.instructions).toMatchObject({ revision: 1, text: appendRouting(INSTRUCTIONS_TEMPLATE, 'Idle agents first.'), askedBy: 'owner',
writtenBy: { kind: 'person', id: 'owner' } })
- expect(first.messages.map(m => m.text)).toEqual(['owner changed the instructions: Routing: Idle agents first.\n\nIn Routing:\nAdded: Idle agents first.'])
+ expect(first.messages).toEqual([])
// The stored document must be the revision the state names, or nothing is written.
expect(() => f.run(set({ kind: 'preferIdle' }), owner, { instructions: { revision: 7, text: doc } }))
.toThrow(expect.objectContaining({ code: 'INSTRUCTIONS_UNAVAILABLE' }))
@@ -3220,13 +3219,12 @@ describe('the owner\'s rules in a Swarm of projects', () => {
const doc = (text = '# Doc\n\n## Routing\n\n- Opus.') => ({ instructions: { revision: 1, text } })
const projectOfChat = (f: ReturnType<typeof projects>, chat: string) => f.state.projects!.find(p => p.leadConversationId === chat)!
- it('lets a project\'s Lead write a rule into that project\'s instructions by quoting a person in its chat, and posts the line there', () => {
+ it('lets a project\'s Lead write a rule into that project\'s instructions by quoting a person in its chat, and posts no line', () => {
const f = projects()
const added = f.run(machines(f.app), f.lead, { ...said(), ...doc() })
expect(added.instructions).toMatchObject({ projectId: projectOfChat(f, f.app).id, revision: 2, text: appendRouting('# Doc\n\n## Routing\n\n- Opus.', 'Only m1.'),
askedBy: 'owner', summary: 'Routing: Only m1.' })
- expect(added.messages).toEqual([expect.objectContaining({ conversationId: f.app, text: 'app-lead changed the instructions for owner: Routing: Only m1.\n\nIn Routing:\nAdded: Only m1.',
- source: { kind: 'instructions', projectId: projectOfChat(f, f.app).id, revision: 2 } })])
+ expect(added.messages).toEqual([])
expect(f.state).not.toHaveProperty('rules')
expect(f.run({ type: 'rule.remove', ruleId: 'any', askedIn: { conversationId: f.app, messageId: 'm2' } }, f.lead, said()).result).toMatchObject({ ignored: true })
})
@@ -3263,7 +3261,7 @@ describe('the owner\'s rules in a Swarm of projects', () => {
const mine = f.run({ type: 'project.create', name: 'Peer', visibility: 'private', brief: '' }, peer).result as { projectId: string; conversationId: string }
const added = f.run(forbid(mine.projectId, 'haiku'), peer, doc())
expect(added.instructions).toMatchObject({ projectId: mine.projectId, askedBy: 'peer' })
- expect(added.messages).toEqual([expect.objectContaining({ conversationId: mine.conversationId, text: 'peer changed the instructions: Routing: No haiku.\n\nIn Routing:\nAdded: No haiku.' })])
+ expect(added.messages).toEqual([])
expect(() => f.run(forbid(mine.projectId, 'opus'), owner, doc())).toThrow('unavailable')
// Public, any member who reads it writes its instructions, the Swarm owner too.
f.run({ type: 'project.sharing', projectId: mine.projectId, visibility: 'public', memberIds: [] }, peer)
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 23a31996c..1c53d3c67 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -58,7 +58,6 @@ import { askBuddyModel, buddyModelResult, sendBuddyHome, sessionModel } from './
import { launchRefusedLine, leadArrived, LEAD_CLAIM_MS, leadEffort, leadJoined, leadOvertaken, leadStartFailed, leadStarting, leadHost, leadWaits, LEAD_CAPABILITY, placeLead } from './leadStart.js'
import { appendRouting, coordinatorNameOf, routingSummary, FIRST_INSTRUCTIONS, FIRST_SUMMARY, instructionsHash, instructionsTextSchema, legacyRoleName, liveNotes, MAX_NOTES, noteTextSchema, roleNameSchema, summarySchema, type PmNote } from './instructions.js'
import { INSTRUCTIONS_TEMPLATE } from './instructionsTemplate.js'
-import { instructionsChange } from './instructionsDiff.js'
import { BUILT_IN_HEADING } from './pmSchedule.js'
import { placeAfter, queueSiblings } from './taskQueue.js'
@@ -1124,21 +1123,15 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
}
/** Accepted, kept nowhere: an older client's save of what each project's instructions say now (IGNORED_NOTE). */
const ignored = () => Object.assign(result, { ignored: true, note: IGNORED_NOTE })
- /** A new revision of [project]'s instructions from revision [current], whose text was [before] (null when the store could not
- * read it), with one line in its chat in the writer's name, for the member who asked when that is someone else: what
- * instructions.save and an older client's rule.set write. The line shows the lines really removed and added under the
- * writer's summary, so nobody takes the summary's word for what was saved (#3021). */
- const saveInstructions = (project: SwarmProject, current: number, before: string | null, text: string, summary: string, askedBy: string) => {
+ /** A new revision of [project]'s instructions from revision [current]: what instructions.save and an older client's rule.set
+ * write. It is kept in the revision history, who wrote it and for whom, and posts nothing in any chat (Dee and Ken,
+ * 2026-11-05, #3132): a change is read and undone in the Instructions history. */
+ const saveInstructions = (project: SwarmProject, current: number, text: string, summary: string, askedBy: string) => {
const hash = instructionsHash(text)
mutableProjects(state)
Object.assign(projectOf(state, project.id), { instructionsRevision: current + 1, instructionsHash: hash })
effects.instructions = { projectId: project.id, revision: current + 1, hash, text, summary,
writtenBy: { kind: sender.kind, id: sender.id }, askedBy, at: context.now }
- // A save for someone else, a coordinator's or a person's, names the member it was for, so the record never names an asker
- // the chat line did not (review of phase 2).
- const asked = askedBy !== sender.id ? ` for ${person(state, askedBy).email.split('@')[0]}` : ''
- message(project.leadConversationId, `${who} changed the instructions${asked}: ${summary}${/[.!?]$/.test(summary) ? '' : '.'}\n\n${instructionsChange(before, text)}`, [], null,
- { kind: 'instructions', projectId: project.id, revision: current + 1 })
Object.assign(result, { projectId: project.id, revision: current + 1, hash })
}
/** No private channel to the PM: Buddies replaced Chat with PM (Ken, 10-29). A closed one is nobody's to read or post in
@@ -1811,9 +1804,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
Object.assign(result, { projectId: project.id, revision: current, hash, unchanged: true })
break
}
- // The text this save replaces, which the store read for the stale check above: what its chat line diffs against.
- const before = !current ? INSTRUCTIONS_TEMPLATE : context.instructions?.revision === current ? context.instructions.text : null
- saveInstructions(project, current, before, command.text, command.summary, askedBy)
+ saveInstructions(project, current, command.text, command.summary, askedBy)
break
}
case 'note.add': {
@@ -2139,7 +2130,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
// Revision 0 runs on the template (design, Migration); otherwise the stored document of this revision, read by the store.
const stored = !current ? INSTRUCTIONS_TEMPLATE : context.instructions?.revision === current ? context.instructions.text
: fail('INSTRUCTIONS_UNAVAILABLE', 'This project\'s instructions cannot be read now. Try again in a moment.', 503)
- saveInstructions(project, current, stored, appendRouting(stored, command.text), routingSummary(command.text), askedBy)
+ saveInstructions(project, current, appendRouting(stored, command.text), routingSummary(command.text), askedBy)
break
}
case 'rule.remove':
diff --git a/backend/src/superTabs/instructions.test.ts b/backend/src/superTabs/instructions.test.ts
index a53f333cd..85b3ce389 100644
--- a/backend/src/superTabs/instructions.test.ts
+++ b/backend/src/superTabs/instructions.test.ts
@@ -11,8 +11,6 @@ const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'own
const peer: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'peer', email: '[email protected]' }
const config: AgentConfiguration = { engine: 'codex', model: 'test-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }
const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })
-/** A save's chat line: its summary line, above the change it shows. */
-const firstLine = (text: string) => text.split('\n')[0]
function fixture() {
let state = createSuperTab('tab', 'Pilot', { id: 'owner', email: owner.email }, 'prod')
@@ -237,7 +235,7 @@ describe('instructions.save', () => {
const save = (baseRevision: number, text: string, extra: Partial<Extract<Command, { type: 'instructions.save' }>> = {}): Command =>
({ type: 'instructions.save', projectId: 'lead', baseRevision, text, summary: 'Reviews run on Opus', ...extra })
- it('saves on the latest revision, announces it in the project chat and hands the text to the store', () => {
+ it('saves on the latest revision, posts nothing in any chat and hands the text to the store', () => {
const f = fixture()
expect(f.state.projects![0]).toMatchObject({ instructionsRevision: 1, instructionsHash: instructionsHash(INSTRUCTIONS_TEMPLATE) })
const effects = f.run(save(1, 'Reviews run on Opus.'))
@@ -245,34 +243,24 @@ describe('instructions.save', () => {
expect(effects.instructions).toEqual({ projectId: 'lead', revision: 2, hash: instructionsHash('Reviews run on Opus.'), text: 'Reviews run on Opus.',
summary: 'Reviews run on Opus', writtenBy: { kind: 'person', id: 'owner' }, askedBy: 'owner', at: 1000 })
expect(f.state.projects![0]).toMatchObject({ instructionsRevision: 2, instructionsHash: instructionsHash('Reviews run on Opus.') })
- expect(effects.messages).toHaveLength(1)
- expect(effects.messages[0]).toMatchObject({ conversationId: 'lead', author: { kind: 'person', id: 'owner' }, recipients: [],
- source: { kind: 'instructions', projectId: 'lead', revision: 2 } })
- expect(firstLine(effects.messages[0]!.text)).toBe('owner changed the instructions: Reviews run on Opus.')
+ // Dee and Ken, 11-05 (#3132): a save is read in the Instructions history, never posted in the project chat or any other.
+ expect(effects.messages).toEqual([])
})
- // Ken, 11-05: the line named only the PM's summary, so "I wrote it into the instructions" could not be checked (#3021).
- it('posts the lines the save really added and removed, from the revision it replaced, under the summary', () => {
+ // #3132: the chat line #3021 added is gone with the line; what the save changed stays readable as two kept revisions.
+ it('posts nothing for a save that changes lines, a long change or an unreadable earlier revision, and still records each revision', () => {
const f = fixture()
const stored = { instructions: { revision: 1, text: '# Rules\n\n- Opus builds.\n- Haiku reviews.' } }
const effects = f.run(save(1, '# Rules\n\n- Opus builds.\n- Sonnet reviews.\n- Tests run first.'), owner, stored)
- expect(effects.messages).toEqual([expect.objectContaining({ conversationId: 'lead', source: { kind: 'instructions', projectId: 'lead', revision: 2 },
- text: 'owner changed the instructions: Reviews run on Opus.\n\nIn Rules:\nRemoved: Haiku reviews.\nAdded: Sonnet reviews.\nAdded: Tests run first.' })])
- // The summary never stands in for the change: a summary claiming a rule shows the lines the text really holds.
- const claimed = f.run(save(2, '# Rules\n\n- Opus builds.\n- Sonnet reviews.\n- Tests run first.\n- Ship daily.', { summary: 'Added the Haiku ban' }),
- owner, { instructions: { revision: 2, text: '# Rules\n\n- Opus builds.\n- Sonnet reviews.\n- Tests run first.' } })
- expect(claimed.messages[0]!.text).toBe('owner changed the instructions: Added the Haiku ban.\n\nIn Rules:\nAdded: Ship daily.')
- })
-
- it('shows 12 items of a long change and how many more, and says when the earlier revision could not be read', () => {
- const f = fixture()
+ expect(effects.messages).toEqual([])
+ expect(effects.instructions).toMatchObject({ projectId: 'lead', revision: 2, summary: 'Reviews run on Opus' })
const rules = Array.from({ length: 30 }, (_, i) => `- Rule ${i + 1}.`)
- const long = f.run(save(1, ['# Rules', ...rules].join('\n')), owner, { instructions: { revision: 1, text: '# Rules' } }).messages[0]!.text
- expect(long).toBe(['owner changed the instructions: Reviews run on Opus.', '', 'In Rules:', ...rules.slice(0, 12).map(r => `Added: ${r.slice(2)}`), '',
- 'and 18 more changes.'].join('\n'))
- // The store reads the current revision for every save (store.ts); one it could not read is said, never shown as no change.
- expect(f.run(save(2, 'Other.'), owner, { instructions: null }).messages[0]!.text)
- .toBe('owner changed the instructions: Reviews run on Opus.\n\nThe earlier revision could not be read, so the change is not shown.')
+ const long = f.run(save(2, ['# Rules', ...rules].join('\n')), owner, { instructions: { revision: 2, text: '# Rules' } })
+ expect(long.messages).toEqual([])
+ expect(long.instructions).toMatchObject({ revision: 3 })
+ const unreadable = f.run(save(3, 'Other.'), owner, { instructions: null })
+ expect(unreadable.messages).toEqual([])
+ expect(unreadable.instructions).toMatchObject({ revision: 4 })
})
it('refuses a save on an older revision with the current revision and text, so the caller can merge', () => {
@@ -298,8 +286,7 @@ describe('instructions.save', () => {
expect(() => f.run(save(1, 'PM text.', { askedBy: 'stranger' }), as(lead))).toThrow(expect.objectContaining({ code: 'ASKED_BY_UNAVAILABLE' }))
const effects = f.run(save(1, 'PM text.', { askedBy: 'peer' }), as(lead))
expect(effects.instructions).toMatchObject({ writtenBy: { kind: 'agent', id: lead }, askedBy: 'peer' })
- expect(effects.messages[0]).toMatchObject({ author: { kind: 'agent', id: lead } })
- expect(firstLine(effects.messages[0]!.text)).toBe('lead changed the instructions for peer: Reviews run on Opus.')
+ expect(effects.messages).toEqual([])
expect(() => f.run(save(2, 'Engineer text.', { askedBy: 'owner' }), as(engineer))).toThrow(expect.objectContaining({ code: 'COORDINATOR_REQUIRED' }))
const buddy = f.add('buddy', group)
f.state.agents.find(a => a.id === buddy)!.buddyOf = { personId: 'owner', generation: 'tab' }
@@ -309,13 +296,15 @@ describe('instructions.save', () => {
expect(() => viewer.run(save(1, 'Viewer text.'), peer)).toThrow(expect.objectContaining({ code: 'READ_ONLY' }))
})
- it('names in the chat line the member a person saved for, and no one when they saved for themselves (review of phase 2)', () => {
+ it('records the member a person saved for, and posts no line naming them (review of phase 2, #3132)', () => {
const f = fixture()
f.invite()
const effects = f.run(save(1, 'Peer text.', { askedBy: 'peer' }))
expect(effects.instructions).toMatchObject({ writtenBy: { kind: 'person', id: 'owner' }, askedBy: 'peer' })
- expect(firstLine(effects.messages[0]!.text)).toBe('owner changed the instructions for peer: Reviews run on Opus.')
- expect(firstLine(f.run(save(2, 'Owner text.', { askedBy: 'owner' })).messages[0]!.text)).toBe('owner changed the instructions: Reviews run on Opus.')
+ expect(effects.messages).toEqual([])
+ const own = f.run(save(2, 'Owner text.', { askedBy: 'owner' }))
+ expect(own.instructions).toMatchObject({ askedBy: 'owner' })
+ expect(own.messages).toEqual([])
})
it('keeps a document within 64 KB and a summary on one line, and saves nothing new for the same text', () => {
diff --git a/backend/src/superTabs/instructionsDiff.test.ts b/backend/src/superTabs/instructionsDiff.test.ts
deleted file mode 100644
index 6a9f31bd0..000000000
--- a/backend/src/superTabs/instructionsDiff.test.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import { describe, expect, it } from 'vitest'
-import { instructionsChange, CHANGE_ITEMS, ITEM_CHARS } from './instructionsDiff.js'
-
-/** The words every line of a change starts with: none can open a Markdown block (a heading, list, quote, code or table). */
-const LINE_START = /^(?:In .+:|Added: |Removed: |Added section: |Removed section: |and \d+ more changes?\.$|$)/
-
-describe('instructionsChange', () => {
- // Ken, 11-05 (#3021): instructions wrap at about 120 characters, so one bullet spans several lines; a one-word edit rewraps
- // it. Compared by line, it showed fragments, none of them the bullet's start. Compared by item, it shows the whole rule.
- it('shows a rewrapped bullet\'s whole old and new words, under the section it sits in', () => {
- const before = '# Project instructions\n\n## Routing\n\n### Models\n\n- No agent runs below high effort,\n and none on Haiku.\n- Reviewers run on Opus.'
- const after = '# Project instructions\n\n## Routing\n\n### Models\n\n- No agent runs below high\n effort, and none on Claude Haiku.\n- Reviewers run on Opus.'
- expect(instructionsChange(before, after)).toBe('In Routing › Models:\nRemoved: No agent runs below high effort, and none on Haiku.\n'
- + 'Added: No agent runs below high effort, and none on Claude Haiku.')
- })
-
- it('shows nothing for a rewrap or spacing alone, and says so', () => {
- const before = '## Workflow\n\nThe PM opens each task with its goal and\n"Done when".\n\n- One request is one task.'
- expect(instructionsChange(before, '## Workflow\n\n\nThe PM opens each task\nwith its goal and "Done when".\n- One request is one task.\n'))
- .toBe('Only spacing and line breaks changed.')
- })
-
- it('joins a paragraph\'s wrapped lines into one item', () => {
- expect(instructionsChange('Intro.\n\nEvery agent works by these\ninstructions.', 'Intro.\n\nEvery agent works by these\ninstructions, always.'))
- .toBe('Removed: Every agent works by these instructions.\nAdded: Every agent works by these instructions, always.')
- })
-
- it('shows 12 items of a long change, then how many more changes there are', () => {
- const rules = Array.from({ length: 20 }, (_, i) => `- Rule ${i + 1}.`)
- const change = (n: number) => instructionsChange('## Rules\n\n- Rule 0.', ['## Rules', '', '- Rule 0.', ...rules.slice(0, n)].join('\n'))
- expect(CHANGE_ITEMS).toBe(12)
- expect(change(20)).toBe(['In Rules:', ...rules.slice(0, 12).map(r => `Added: ${r.slice(2)}`), '', 'and 8 more changes.'].join('\n'))
- expect(change(13).endsWith('\n\nand 1 more change.')).toBe(true)
- expect(change(12)).not.toContain('more change')
- })
-
- it('drops list markers, so a numbered step inserted shows alone and the steps renumbered after it do not', () => {
- expect(instructionsChange('## Workflow\n\n1. Plan.\n2. Build.\n3. Ship.', '## Workflow\n\n1. Plan.\n2. Test first.\n3. Build.\n4. Ship.'))
- .toBe('In Workflow:\nAdded: Test first.')
- })
-
- it('names each change\'s own section, a section added too', () => {
- const before = '# Doc\n\n## Roles\n\n### PM\n\n- Talks with people.\n\n## Routing\n\n- Opus builds.'
- const after = '# Doc\n\n## Roles\n\n### PM\n\n- Talks with people.\n- Merges work.\n\n## Routing\n\n- Opus builds.\n\n### Testers\n\n- A Mac for Desktop.'
- expect(instructionsChange(before, after)).toBe('In Roles › PM:\nAdded: Merges work.\n\nIn Routing:\nAdded section: Testers\n\n'
- + 'In Routing › Testers:\nAdded: A Mac for Desktop.')
- })
-
- it('keeps a saved item\'s Markdown from opening a block in the chat', () => {
- const change = instructionsChange('A.', 'A.\n\n```\ncode\n```\n\n> quote\n\n| a | b |\n|---|---|\n\n---\n\n<details>')
- for (const line of change.split('\n')) expect(line).toMatch(LINE_START)
- })
-
- it('cuts a very long item, never the count', () => {
- const long = 'x'.repeat(ITEM_CHARS + 50)
- expect(instructionsChange('A.', `A.\n\n${long}`)).toBe(`Added: ${'x'.repeat(ITEM_CHARS - 1)}…`)
- })
-
- it('says when the earlier revision could not be read, rather than showing no change', () => {
- expect(instructionsChange(null, 'Anything.')).toBe('The earlier revision could not be read, so the change is not shown.')
- })
-
- it('shows a rewrite too big to compare item by item as its real removed and added items, quickly', () => {
- const before = Array.from({ length: 2000 }, (_, i) => `- Old ${i}`).join('\n')
- const after = Array.from({ length: 2000 }, (_, i) => `- New ${i}`).join('\n')
- const started = performance.now()
- const change = instructionsChange(before, after)
- expect(performance.now() - started).toBeLessThan(500)
- expect(change).toBe([...Array.from({ length: 12 }, (_, i) => `Removed: Old ${i}`), '', 'and 3988 more changes.'].join('\n'))
- })
-
- it('compares a large document\'s small change item by item', () => {
- const items = Array.from({ length: 2000 }, (_, i) => `- Item ${i}`)
- const after = [...items.slice(0, 500), '- Inserted', ...items.slice(500, 1500), ...items.slice(1501)]
- expect(instructionsChange(items.join('\n'), after.join('\n'))).toBe('Added: Inserted\nRemoved: Item 1500')
- })
-})
diff --git a/backend/src/superTabs/instructionsDiff.ts b/backend/src/superTabs/instructionsDiff.ts
deleted file mode 100644
index 6f5de9964..000000000
--- a/backend/src/superTabs/instructionsDiff.ts
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * What an instructions save really changed, for the line it posts in the project chat (task #3021, Ken 11-05): the items it
- * removed and added against the revision it replaced, so a PM's "I wrote it into the instructions" can be checked.
- * Computed once per save from the two texts the save already holds (commands.ts saveInstructions); nothing is stored or
- * read for it.
- *
- * Instructions are hard-wrapped, so one bullet spans several lines and a one-word edit rewraps it. They are compared by
- * item instead: a bullet, a numbered step, a paragraph or a fenced block, its wrapped lines joined, its list marker
- * dropped (so renumbered steps are no change), and each heading. A change is written in words, "Added:" or "Removed:"
- * under the section it sits in ("In Routing › Models:"), which reads the same in every client with no colouring (Ken's
- * review; River chose words).
- */
-
-/** Changed items the chat line shows; the rest are counted. */
-export const CHANGE_ITEMS = 12
-/** Characters of one shown item; a longer one is cut, never left out. */
-export const ITEM_CHARS = 400
-/** Edits compared item by item. Past this a 64 KB rewrite would cost (N+M)·D steps, so the region between the common head
- * and tail is shown as removed and added whole: still the real items, only not the fewest changes. */
-const MAX_EDITS = 1000
-
-/** One item of a document: its words on one line, the section path it sits under, and whether it is a heading. */
-interface Item { key: string; text: string; path: string; heading: boolean }
-interface Edit { added: boolean; item: Item }
-
-/** The words under the summary of a save from [before] to [after]: each changed item on its own line, starting "Added:" or
- * "Removed:", grouped under its section, then how many more changes there are. Every line starts with one of those words,
- * so a saved item's Markdown never opens a heading, list, quote, code block or table in the chat. [before] null is an
- * earlier revision the store could not read: said, never shown as no change. */
-export function instructionsChange(before: string | null, after: string): string {
- if (before === null) return 'The earlier revision could not be read, so the change is not shown.'
- const edits = itemEdits(items(before), items(after))
- if (!edits.length) return 'Only spacing and line breaks changed.'
- const lines: string[] = []
- let section: string | undefined
- for (const { added, item } of edits.slice(0, CHANGE_ITEMS)) {
- if (item.path !== section) {
- if (lines.length) lines.push('')
- if (item.path) lines.push(`In ${item.path}:`)
- section = item.path
- }
- lines.push(`${added ? 'Added' : 'Removed'}${item.heading ? ' section' : ''}: ${cut(item.text)}`)
- }
- const more = edits.length - CHANGE_ITEMS
- if (more > 0) lines.push('', `and ${more} more change${more === 1 ? '' : 's'}.`)
- return lines.join('\n')
-}
-
-const HEADING = /^ {0,3}(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/
-const LIST_ITEM = /^[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(.*)$/
-const FENCE = /^ {0,3}(?:```|~~~)/
-
-/** [text]'s items in document order. A section's path is its headings below the document's title (level 1), or the title
- * alone when it has no others. */
-function items(text: string): Item[] {
- const found: Item[] = []
- const headings: (string | undefined)[] = []
- const pathOf = (levels: (string | undefined)[]) => {
- const below = levels.slice(1).filter((h): h is string => !!h)
- return (below.length ? below : levels.slice(0, 1).filter((h): h is string => !!h)).join(' › ')
- }
- let open: string[] | null = null
- let fenced = false
- const close = () => {
- if (open) found.push(item(open.join(' '), pathOf(headings), false))
- open = null
- }
- for (const raw of text.split(/\r?\n/)) {
- const line = raw.trim()
- if (fenced) {
- open!.push(line)
- if (FENCE.test(raw)) { fenced = false; close() }
- continue
- }
- if (!line) { close(); continue }
- if (FENCE.test(raw)) { close(); open = [line]; fenced = true; continue }
- const heading = HEADING.exec(raw)
- if (heading) {
- close()
- const level = heading[1]!.length
- headings.length = level - 1
- found.push(item(heading[2]!, pathOf(headings), true))
- headings[level - 1] = heading[2]!.trim()
- continue
- }
- const listed = LIST_ITEM.exec(raw)
- if (listed) { close(); open = [listed[1]!] } else if (open) (open as string[]).push(line)
- else open = [line]
- }
- close()
- return found.filter(i => i.text)
-}
-
-function item(words: string, path: string, heading: boolean): Item {
- const text = words.replace(/\s+/g, ' ').trim()
- return { key: `${heading ? '#' : '-'}${text}`, text, path, heading }
-}
-
-function cut(text: string): string {
- if (text.length <= ITEM_CHARS) return text
- let end = ITEM_CHARS - 1
- // Never half of a surrogate pair.
- if (/[\uD800-\uDBFF]/.test(text[end - 1]!)) end -= 1
- return `${text.slice(0, end)}…`
-}
-
-/** The removals and additions from [a] to [b] in document order, a removal before the addition that replaces it. */
-function itemEdits(a: Item[], b: Item[]): Edit[] {
- let head = 0
- while (head < a.length && head < b.length && a[head]!.key === b[head]!.key) head++
- let tail = 0
- while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail]!.key === b[b.length - 1 - tail]!.key) tail++
- const from = a.slice(head, a.length - tail), to = b.slice(head, b.length - tail)
- return myers(from, to) ?? [...from.map(item => ({ added: false, item })), ...to.map(item => ({ added: true, item }))]
-}
-
-/** Myers' shortest edit script (1986), or null past MAX_EDITS. Each step keeps only its own diagonals -d..d. */
-function myers(a: Item[], b: Item[]): Edit[] | null {
- const n = a.length, m = b.length
- if (!n || !m) return [...a.map(item => ({ added: false, item })), ...b.map(item => ({ added: true, item }))]
- const offset = n + m + 1
- const v = new Int32Array(2 * offset + 1)
- const trace: Int32Array[] = []
- let found = -1
- for (let d = 0; d <= Math.min(n + m, MAX_EDITS) && found < 0; d++) {
- for (let k = -d; k <= d; k += 2) {
- let x = k === -d || (k !== d && v[offset + k - 1]! < v[offset + k + 1]!) ? v[offset + k + 1]! : v[offset + k - 1]! + 1
- let y = x - k
- while (x < n && y < m && a[x]!.key === b[y]!.key) { x++; y++ }
- v[offset + k] = x
- if (x >= n && y >= m) { found = d; break }
- }
- trace.push(v.slice(offset - d, offset + d + 1))
- }
- if (found < 0) return null
- const at = (d: number, k: number) => trace[d]![k + d]!
- const edits: Edit[] = []
- let x = n, y = m
- for (let d = found; d > 0; d--) {
- const k = x - y
- const down = k === -d || (k !== d && at(d - 1, k - 1) < at(d - 1, k + 1))
- const prevK = down ? k + 1 : k - 1
- const prevX = at(d - 1, prevK), prevY = prevX - prevK
- while (x > prevX && y > prevY) { x--; y-- }
- edits.push(down ? { added: true, item: b[prevY]! } : { added: false, item: a[prevX]! })
- x = prevX
- y = prevY
- }
- return edits.reverse()
-}
diff --git a/backend/src/superTabs/notices.test.ts b/backend/src/superTabs/notices.test.ts
index 9a53f352c..777637564 100644
--- a/backend/src/superTabs/notices.test.ts
+++ b/backend/src/superTabs/notices.test.ts
@@ -76,7 +76,7 @@ describe('the notices the Swarm writes into a chat', () => {
const written = writtenKinds()
it('finds the notices it is known to write, so a change in how they are written cannot empty this check', () => {
- expect([...written.keys()]).toEqual(expect.arrayContaining(['system', 'instructions', 'agent-only', 'idle', 'review-failed', 'work-lost', 'terminal-alert', 'native']))
+ expect([...written.keys()]).toEqual(expect.arrayContaining(['system', 'agent-only', 'idle', 'review-failed', 'work-lost', 'terminal-alert', 'native']))
})
it('classifies every kind it writes, and only those', () => {
@@ -86,8 +86,9 @@ describe('the notices the Swarm writes into a chat', () => {
// phase 4) told only the Lead; the coordinator's progress post, now the project's status card (Dee, 2026-10-31), people;
// 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.
- const retired = ['idle-stop', 'project-report', 'ship', 'machine-left', 'task-line', 'routing-reflection']
+ // 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.
+ const retired = ['idle-stop', 'project-report', 'ship', 'machine-left', 'task-line', 'routing-reflection', 'instructions']
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/cli/src/lib/swarmTools.ts b/cli/src/lib/swarmTools.ts
index dc62a1bda..a51eca621 100644
--- a/cli/src/lib/swarmTools.ts
+++ b/cli/src/lib/swarmTools.ts
@@ -82,7 +82,7 @@ Swarm and machine settings (each refused unless you may change that setting; a p
### The project's instructions and notes
- Save: \`{"type":"instructions.save","projectId":"PROJECT","baseRevision":N,"text":"the whole new document","summary":"one line, up to 200 characters","askedBy":"PERSON"}\`. \`baseRevision\` is the revision you read with \`instructions\`. \`text\` is the whole document, not a patch. A person who reads the project saves it; of the agents, only the project's coordinator does, and always with \`askedBy\` naming the member whose words the change carries. Any other agent asks the coordinator or a person. A save of unchanged text changes nothing.
- A stale base is refused with INSTRUCTIONS_STALE, which names the current revision: read \`instructions\` again, merge your change into that text and save on the new revision. Never overwrite another writer's text.
-- A save posts one line in the project's chat, with your summary. Do not post another about it.
+- A save posts nothing in any chat; the change is read in the project's Instructions history.
- Add a note: \`{"type":"note.add","projectId":"PROJECT","text":"up to 300 characters","askedBy":"PERSON","expiresAt":"optional ISO time"}\`. Only the project's coordinator adds one; anyone else tells the coordinator what to note. A note is a small thing a member told the coordinator, kept beside the instructions until it ends. A project keeps at most 100; remove one (or write what lasts into the instructions) when it is full.
- Remove a note: \`{"type":"note.remove","projectId":"PROJECT","noteId":"NOTE"}\` (each note's id is in the \`instructions\` output): the coordinator, or a person who reads the project. An expired note is already gone.
diff --git a/docs/plans/2026-10-30-project-instructions-design.md b/docs/plans/2026-10-30-project-instructions-design.md
index 9738db300..93a6fd1b1 100644
--- a/docs/plans/2026-10-30-project-instructions-design.md
+++ b/docs/plans/2026-10-30-project-instructions-design.md
@@ -112,8 +112,9 @@ Quota is information, not a gate.
(otherwise it is refused with the current text, to merge and save again).
- The PM edits it when a member asks; `askedBy` names the member, and no quoted message is needed (the `askedIn` check and
`RULE_MESSAGE_MS` go).
-- Every save posts one line in the project chat with its summary ("Dee changed the instructions: Reviews run on Opus."),
- so the team sees it without opening the document.
+- A save posts nothing in any chat (Dee and Ken, 2026-11-05, #3132): every save is a kept revision with its summary, who
+ wrote it and for whom, and the team reads and undoes a change in the Instructions history. (Until then each save posted
+ one line in the project chat; those older posts stay.)
- Conflicts in content: when a request contradicts the document, the PM changes the document, says so and tells the
author of the line it replaced. It never silently keeps both.
diff --git a/docs/swarms.md b/docs/swarms.md
index c843627cd..ae7a919d9 100644
--- a/docs/swarms.md
+++ b/docs/swarms.md
@@ -1030,8 +1030,8 @@ and on which model is the document's to say, and the agents follow it.
the document again, keeps the draft in the editor and shows the newer text
beside it, and the next Save goes on the newer revision. **Restore** loads an
old revision into the editor with the summary "Restored revision N."; Save
- writes it. Each save posts one line in the project chat: "dee changed the
- instructions: Reviews run on Opus." When a request contradicts the document,
+ writes it. A save posts nothing in any chat; every save is a kept
+ revision, read in History. When a request contradicts the document,
the coordinator changes the document, says so and tells the author of the line
it replaced.
- **History**: the last 50 revisions, each with who wrote it, whose words it