The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Phone notifications ring only when a person must act or a person speaks to you (#3306)
harness-for-autonomous[bot]3034d9b276d4
diff --git a/backend/integration/superTabActivity.test.ts b/backend/integration/superTabActivity.test.tsindex 498b996e4..110e627a2 100644--- a/backend/integration/superTabActivity.test.ts+++ b/backend/integration/superTabActivity.test.ts@@ -377,12 +377,12 @@ describe('Phone push: who each push type reaches, and what it carries (task #324expect((await items(s.tabId, peer)).some(i => i.text === 'Owner again')).toBe(true)})- it('an agent\'s reply in a person\'s thread is worded with the agent\'s name', async () => {+ it('an agent\'s reply in a person\'s thread rings nobody: it stays in Activity and the badge (task #3607)', async () => {const s = await scene()const root = await send(s.tabId, s.web, 'Owner root')- const [notice, ...more] = await pushed(() => send(s.tabId, s.web, 'Worker answers', owner, root, s.worker))- expect(more).toEqual([])- expect(notice).toMatchObject({ personId: owner.sub, title: 'worker-harness replied in a thread' })+ expect(await pushed(() => send(s.tabId, s.web, 'Worker answers', owner, root, s.worker))).toEqual([])+ // The Activity row is still written: only the ring is gone.+ expect((await db.superTabActivity.findMany({ where: { tabId: s.tabId, personId: owner.sub, kind: 'reply' } })).length).toBe(1)})it('a reply that tags a person tells them by the tag alone, once', async () => {@@ -430,10 +430,9 @@ describe('Phone push: who each push type reaches, and what it carries (task #324expect(both!.link).toBe(`swarm:${s.tabId}/${s.web}/message/${alsoInChat}`)})- it('an agent\'s tag is worded with the agent\'s name; one\'s own tag tells nobody; a tag held for a quiet chat is not pushed', async () => {+ it('an agent\'s tag rings nobody (task #3607); one\'s own tag tells nobody; a tag held for a quiet chat is not pushed', async () => {const s = await scene()- expect(await pushed(() => tagging(s.tabId, s.web, 'Peer, the build is red', owner, null, [peer.sub], {}, s.worker)))- .toEqual([expect.objectContaining({ personId: peer.sub, title: 'worker-harness tagged you' })])+ expect(await pushed(() => tagging(s.tabId, s.web, 'Peer, the build is red', owner, null, [peer.sub], {}, s.worker))).toEqual([])expect(await whom(() => tagging(s.tabId, s.web, 'Note to self', owner, null, [owner.sub]))).toEqual([])expect(await whom(() => tagging(s.tabId, s.web, 'Peer, if nobody takes this', owner, null, [peer.sub], { mentionsIfNoWorker: true }))).toEqual([])})@@ -444,7 +443,7 @@ describe('Phone push: who each push type reaches, and what it carries (task #324questions: [{ question, options: ['Yes', 'No'], recommended: 0, unblocks: 'The release' }] } as Command, owner, s.worker)let ids: string[] = []const notices = await pushed(async () => { ids = (await ask('Ship it today?')).result.decisionIds as string[] })- expect(notices).toEqual([{ personId: peer.sub, key: `decision:${ids[0]}`, slot: `decision:${ids[0]}`, title: 'worker-harness asks you',+ expect(notices).toEqual([{ personId: peer.sub, key: `decision:${ids[0]}`, slot: `task:${s.tabId}:${s.web}`, title: 'worker-harness asks you',subtitle: await swarmName(s.tabId), body: 'Open Harness to answer.', link: `swarm:${s.tabId}/${s.web}/decision/${ids[0]}` }])// The same open question asked again is the same decision: no second push.expect(await pushed(() => ask('Ship it today?'))).toEqual([])diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex 2824e5998..8bbc97109 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -4394,7 +4394,7 @@ describe('Lead mentions', () => {expect(rest).toEqual([])expect(mention).toEqual({ id: expect.any(String), projectId: 'lead', projectName: 'Pilot', conversationId: group, conversationTitle: 'Copy review',// The picked tag the text did not say opens it, as the server stores it (mentions.ts withTags).- messageId, leadId: lead, leadName: expect.any(String), text: `@peer ${text}`.slice(0, 200), createdAt: expect.any(String), resolvedAt: null, resolvedBy: null,+ messageId, leadId: lead, leadName: expect.any(String), leadKind: 'agent', text: `@peer ${text}`.slice(0, 200), createdAt: expect.any(String), resolvedAt: null, resolvedBy: null,threadId: null, messageSequence: expect.any(Number) })// Where the tagged message is in its chat, as its page numbers it: Desktop clears the red number once read past it.const page = await app.inject({ method: 'GET', url: `/api/super-tabs/${tab}/conversations/${group}/messages`, headers: { authorization: `Bearer ${peer.sub}` } })@@ -4460,7 +4460,8 @@ describe('Lead mentions', () => {const messageId = (await run(tab, { type: 'message.send', conversationId: group, text: 'Peer, see above.', replyTo: null, recipientIds: [],mentions: [peer.sub] })).result.messageId as stringconst mention = (await list(tab, peer, 'waiting')).find(m => m.messageId === messageId)- expect(mention).toEqual(expect.objectContaining({ leadId: owner.sub, leadName: 'boss', text: '@peer Peer, see above.' }))+ // Who tagged, by kind: the phone rings for a person's tag and not for an agent's (task #3607).+ expect(mention).toEqual(expect.objectContaining({ leadId: owner.sub, leadName: 'boss', leadKind: 'person', text: '@peer Peer, see above.' }))expect(JSON.stringify(mention)).not.toContain(owner.email)})diff --git a/backend/src/push/notices.test.ts b/backend/src/push/notices.test.tsindex df4d1925b..340e44106 100644--- a/backend/src/push/notices.test.ts+++ b/backend/src/push/notices.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { phoneNotices } from './notices.js'+import { phoneNotices, taskSlot } from './notices.js'import { swarm, owner, peer } from '../superTabs/read/fixture.test-support.js'import { shownNameOf } from '../superTabs/personNames.js'import type { MessageDraft } from '../superTabs/model.js'@@ -30,9 +30,8 @@ describe('phoneNotices: what a write tells phones (task #2905)', () => {})it('words a tag as the phone does, and links the message, in its thread only when it is only there', () => {- const { state, web, worker } = scene()- const agent = { kind: 'agent' as const, id: worker, name: 'worker-harness', membershipGeneration: 'g' }- const inChat = draft({ id: 'm1', conversationId: web, author: agent, mentions: [owner.userId] })+ const { state, web } = scene()+ const inChat = draft({ id: 'm1', conversationId: web, author: person(peer), mentions: [owner.userId] })const inThread = draft({ id: 'm2', conversationId: web, author: person(peer), mentions: [owner.userId], thread: 'root2' })const alsoInChat = draft({ id: 'm3', conversationId: web, author: person(peer), mentions: [owner.userId], thread: 'root2', alsoInChat: true })const tag = (id: string, messageId: string) => ({ id, personId: owner.userId, conversationId: web, messageId })@@ -40,7 +39,7 @@ describe('phoneNotices: what a write tells phones (task #2905)', () => {// A tag is a notice of its own: it shows in the slot of its key, as the app's notice for it does.expect(notices.every(n => n.slot === n.key && !n.thread && !n.quiet)).toBe(true)expect(notices.map(n => [n.key, n.title, n.subtitle, n.link])).toEqual([- ['mention:t1', 'worker-harness tagged you', 'Web launch', `swarm:tab/${web}/message/m1`],+ ['mention:t1', `${shownNameOf(state, peer.userId)} tagged you`, 'Web launch', `swarm:tab/${web}/message/m1`],['mention:t2', `${shownNameOf(state, peer.userId)} tagged you`, 'Web launch', `swarm:tab/${web}/message/m2/thread/root2`],['mention:t3', `${shownNameOf(state, peer.userId)} tagged you`, 'Web launch', `swarm:tab/${web}/message/m3`],])@@ -50,10 +49,9 @@ describe('phoneNotices: what a write tells phones (task #2905)', () => {it('tells of a reply in a person\'s Swarm Buddy chat, which belongs to no project, without failing (security review 2)', () => {const { state } = scene()const buddy = openSwarmBuddyChat(state, state.people.find(p => p.id === peer.userId)!).id- const agent = { kind: 'agent' as const, id: 'buddy-session', name: 'Buddy', membershipGeneration: 'g' }- const reply = draft({ id: 'r1', conversationId: buddy, author: agent, thread: 'root1' })+ const reply = draft({ id: 'r1', conversationId: buddy, author: person(owner), thread: 'root1' })const notices = phoneNotices('tab', state, { replies: [{ id: 'row1', personId: peer.userId, conversationId: buddy, messageId: 'r1', threadId: 'root1',- actorKind: 'agent', actorId: 'buddy-session', why: 'starter', createdAt: AT }], tags: [] }, [reply])+ actorKind: 'person', actorId: owner.userId, why: 'starter', createdAt: AT }], tags: [] }, [reply])expect(notices).toEqual([expect.objectContaining({ personId: peer.userId, subtitle: '', link: `swarm:tab/${buddy}/message/r1/thread/root1` })])})@@ -100,10 +98,10 @@ describe('phoneNotices: the push rule Tony approved (task #3248)', () => {const agent = { kind: 'agent' as const, id: worker, name: 'worker-harness', membershipGeneration: 'g' }const line = draft({ id: 'r1', conversationId: web, author: agent, thread: 'root1', source: { kind: 'system' } })expect(phoneNotices('tab', state, { replies: [{ ...row('a', owner.userId, 'starter'), conversationId: web }], tags: [] }, [line])).toEqual([])- // The same row for an agent's own words is pushed.- const words = draft({ id: 'r1', conversationId: web, author: agent, thread: 'root1' })- expect(phoneNotices('tab', state, { replies: [{ ...row('a', owner.userId, 'starter'), conversationId: web, actorKind: 'agent', actorId: worker }], tags: [] }, [words]))- .toEqual([expect.objectContaining({ personId: owner.userId, title: 'worker-harness replied in a thread' })])+ // A person's own words in the same row are pushed; an agent's are not (task #3607: Activity and the badge only).+ const words = draft({ id: 'r1', conversationId: web, author: person(peer), thread: 'root1' })+ expect(phoneNotices('tab', state, { replies: [{ ...row('a', owner.userId, 'starter'), conversationId: web }], tags: [] }, [words]))+ .toEqual([expect.objectContaining({ personId: owner.userId, title: `${shownNameOf(state, peer.userId)} replied in a thread` })])})it('pushes a decision asked of a person as the app words it, linking its card, and only the first of one ask\'s questions sounds', () => {@@ -111,18 +109,79 @@ describe('phoneNotices: the push rule Tony approved (task #3248)', () => {const decision = (id: string, personId: string) => ({ id, personId, conversationId: web, askerAgentId: worker })const notices = phoneNotices('tab', state, { replies: [], tags: [], decisions: [decision('d1', owner.userId), decision('d2', owner.userId), decision('d3', peer.userId)] }, [])expect(notices).toEqual([- { personId: owner.userId, key: 'decision:d1', slot: 'decision:d1', title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',+ { personId: owner.userId, key: 'decision:d1', slot: `task:tab:${web}`, title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',link: `swarm:tab/${web}/decision/d1` },- { personId: owner.userId, key: 'decision:d2', slot: 'decision:d2', title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',+ { personId: owner.userId, key: 'decision:d2', slot: `task:tab:${web}`, title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',link: `swarm:tab/${web}/decision/d2`, quiet: true },- { personId: peer.userId, key: 'decision:d3', slot: 'decision:d3', title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',+ { personId: peer.userId, key: 'decision:d3', slot: `task:tab:${web}`, title: 'worker-harness asks you', subtitle: 'Web launch', body: 'Open Harness to answer.',link: `swarm:tab/${web}/decision/d3` },])})+ it('gives every decision of one task one slot, so a later question replaces the earlier in the notification centre; two tasks keep two', () => {+ const { state, web, worker } = scene()+ const decision = (id: string, conversationId: string) => ({ id, personId: owner.userId, conversationId, askerAgentId: worker })+ const notices = phoneNotices('tab', state, { replies: [], tags: [], decisions: [decision('d1', web), decision('d2', web), decision('d3', 'another-task')] }, [])+ expect(notices.map(n => [n.key, n.slot])).toEqual([['decision:d1', `task:tab:${web}`], ['decision:d2', `task:tab:${web}`], ['decision:d3', 'task:tab:another-task']])+ expect(taskSlot('tab', web)).toBe(`task:tab:${web}`)+ })+it('names an asker that is gone as the app does', () => {const { state, web } = scene()expect(phoneNotices('tab', state, { replies: [], tags: [], decisions: [{ id: 'd1', personId: owner.userId, conversationId: web, askerAgentId: 'gone' }] }, [])[0]!.title).toBe('Agent asks you')})})++describe('phoneNotices: who rings (task #3607, Tony 2026-11-06)', () => {+ const asAgent = (id: string) => ({ kind: 'agent' as const, id, name: 'worker-harness', membershipGeneration: 'g' })+ const row = (web: string, id: string, personId: string, why: 'starter' | 'quoted' | 'tagged' | 'replier', actorKind: 'person' | 'agent', actorId: string) =>+ ({ id, personId, conversationId: web, messageId: 'r1', threadId: 'root1', actorKind, actorId, why, createdAt: AT })++ it('an agent\'s reply rings nobody, for starter, quoted and tagged alike', () => {+ const { state, web, worker } = scene()+ const reply = draft({ id: 'r1', conversationId: web, author: asAgent(worker), thread: 'root1' })+ const rows = (['starter', 'quoted', 'tagged'] as const).map((why, i) => row(web, `a${i}`, `p${i}`, why, 'agent', worker))+ expect(phoneNotices('tab', state, { replies: rows, tags: [] }, [reply])).toEqual([])+ })++ it('a person\'s reply rings for starter, quoted and tagged, never for one who only replied', () => {+ const { state, web } = scene()+ const reply = draft({ id: 'r1', conversationId: web, author: person(peer), thread: 'root1' })+ const rows = (['starter', 'quoted', 'tagged', 'replier'] as const).map((why, i) => row(web, `a${i}`, `p${i}`, why, 'person', peer.userId))+ expect(phoneNotices('tab', state, { replies: rows, tags: [] }, [reply]).map(n => n.personId)).toEqual(['p0', 'p1', 'p2'])+ })++ it('an agent\'s tag rings nobody, a person\'s tag rings', () => {+ const { state, web, worker } = scene()+ const byAgent = draft({ id: 'm1', conversationId: web, author: asAgent(worker), mentions: [owner.userId] })+ const byPerson = draft({ id: 'm2', conversationId: web, author: person(peer), mentions: [owner.userId] })+ const tag = (id: string, messageId: string) => ({ id, personId: owner.userId, conversationId: web, messageId })+ const notices = phoneNotices('tab', state, { replies: [], tags: [tag('t1', 'm1'), tag('t2', 'm2')] }, [byAgent, byPerson])+ expect(notices.map(n => n.key)).toEqual(['mention:t2'])+ })++ it('an agent\'s words that say approve or decide ring nobody: the type of the event decides, never the text', () => {+ const { state, web, worker } = scene()+ const text = 'Please approve this and decide now: waiting on you'+ const reply = draft({ id: 'r1', conversationId: web, author: asAgent(worker), thread: 'root1', text })+ const tagging = draft({ id: 'm1', conversationId: web, author: asAgent(worker), mentions: [owner.userId], text })+ expect(phoneNotices('tab', state, { replies: [row(web, 'a', owner.userId, 'starter', 'agent', worker)],+ tags: [{ id: 't1', personId: owner.userId, conversationId: web, messageId: 'm1' }] }, [reply, tagging])).toEqual([])+ })++ it('the server\'s "no reviewer can start" tag is an agent\'s tag: it tells Activity and the badge, no ring', () => {+ // reviewCapacity.ts writes it as the agent that asked for review, with source kind `review-capacity`, tagging the+ // people who can add a machine. Tony's rule has no ring for an agent's tag that is not a decision or an approval.+ const { state, web, worker } = scene()+ const line = draft({ id: 'm1', conversationId: web, author: asAgent(worker), mentions: [owner.userId], source: { kind: 'review-capacity', engine: 'any', cause: 'none' } as never })+ expect(phoneNotices('tab', state, { replies: [], tags: [{ id: 't1', personId: owner.userId, conversationId: web, messageId: 'm1' }] }, [line])).toEqual([])+ })++ it('a decision an agent asks of a person still rings, however the asking agent words it', () => {+ const { state, web, worker } = scene()+ const [notice] = phoneNotices('tab', state, { replies: [], tags: [], decisions: [{ id: 'd1', personId: owner.userId, conversationId: web, askerAgentId: worker }] }, [])+ expect(notice).toEqual(expect.objectContaining({ key: 'decision:d1', title: 'worker-harness asks you' }))+ expect(notice!.quiet).toBeUndefined()+ })+})diff --git a/backend/src/push/notices.ts b/backend/src/push/notices.tsindex b1c077c43..4ba49460d 100644--- a/backend/src/push/notices.ts+++ b/backend/src/push/notices.ts@@ -39,12 +39,19 @@ function linkOf(tabId: string, conversationId: string, messageId: string, thread* (mobile lib/swarm/swarm_notices.dart threadSlot). */export const threadSlot = (tabId: string, conversationId: string, threadId: string) => `thread:${tabId}:${conversationId}:${threadId}`+/** The one notification a task's questions share on a phone (task #3607): a decision asked of the person, and the app's own+ * "stuck" and "needs you" for the same task, show in this slot, so a later one replaces the earlier (mobile+ * lib/swarm/swarm_notices.dart swarmTaskSlot). */+export const taskSlot = (tabId: string, conversationId: string) => `task:${tabId}:${conversationId}`+/*** What one write tells phones (tasks #2905, #3248): a notice for each reply row and tag row it wrote, and each decision it* asked, worded and keyed as the phone's own notices are, so the phone shows one or the other, never both. Who is told was* decided with the rows (#2954: muted chats and Unfollow write no reply row; a tag always tells); of a reply's rows, only* those Tony's rule pushes (PUSHED), and never for a Swarm line in a thread (a row with a source), which stays in Activity.- * A tag held for a quiet chat is not news yet. Of one ask's decisions to a person, only the first sounds.+ * Only a person's reply and a person's tag ring (task #3607): an agent's stay in Activity and the badge, whatever they say.+ * A tag held for a quiet chat is not news yet. Of one ask's decisions to a person, only the first sounds; all of a task's+ * decisions share one notification slot (taskSlot).*/export function phoneNotices(tabId: string, state: SuperTabState, written: { replies: ReplyRow[]; tags: TagRow[]; decisions?: DecisionRow[] },messages: MessageDraft[]): PhoneNotice[] {@@ -56,7 +63,9 @@ export function phoneNotices(tabId: string, state: SuperTabState, written: { repif (!group || isSwarmBuddyChat(group)) return ''return projectsOf(state).find(p => p.id === (group.projectId ?? 'lead'))?.name ?? ''}- const replies = written.replies.filter(row => PUSHED.has(row.why) && !byId.get(row.messageId)?.source).map((row): PhoneNotice => ({+ // Tony's rule (task #3607): a phone rings when a person speaks to its person, or when work waits on them (a decision). An+ // agent's reply or tag stays in Activity and the badge. By the event's kind (who wrote it), never by its words.+ const replies = written.replies.filter(row => row.actorKind === 'person' && PUSHED.has(row.why) && !byId.get(row.messageId)?.source).map((row): PhoneNotice => ({personId: row.personId, key: `reply:${tabId}:${row.id}`,title: `${actorName(state, row.actorKind, row.actorId, byId.get(row.messageId)?.author)} replied in a thread`,subtitle: project(row.conversationId), body: BODY, link: linkOf(tabId, row.conversationId, row.messageId, row.threadId),@@ -65,7 +74,7 @@ export function phoneNotices(tabId: string, state: SuperTabState, written: { rep}))const tags = written.tags.filter(row => !row.holdUntil).flatMap((row): PhoneNotice[] => {const message = byId.get(row.messageId)- if (!message) return []+ if (!message || message.author.kind !== 'person') return []// A tag in a reply only in its thread opens that thread (swarm_notices.dart).const thread = message.thread && message.thread !== message.id && !message.alsoInChat ? message.thread : nullconst key = `mention:${row.id}`@@ -80,7 +89,8 @@ export function phoneNotices(tabId: string, state: SuperTabState, written: { repconst first = !asked.has(row.personId)asked.add(row.personId)return { personId: row.personId, key, title: `${asker?.displayName ?? asker?.name ?? 'Agent'} asks you`, subtitle: project(row.conversationId),- body: ANSWER, link: `swarm:${e(tabId)}/${e(row.conversationId)}/decision/${e(row.id)}`, slot: key, ...first ? {} : { quiet: true as const } }+ body: ANSWER, link: `swarm:${e(tabId)}/${e(row.conversationId)}/decision/${e(row.id)}`, slot: taskSlot(tabId, row.conversationId),+ ...first ? {} : { quiet: true as const } }})return [...replies, ...tags, ...decisions]}diff --git a/backend/src/superTabs/chatSettings.test.ts b/backend/src/superTabs/chatSettings.test.tsnew file mode 100644index 000000000..19bbd881c--- /dev/null+++ b/backend/src/superTabs/chatSettings.test.ts@@ -0,0 +1,10 @@+import { describe, expect, it } from 'vitest'+import { DEFAULT_NOTIFY, NOTIFY_LEVELS } from './chatSettings.js'++describe('a chat\'s notification default (task #3607, Tony 2026-11-06)', () => {+ it('is Mentions only; All new messages only when the person turns it on', () => {+ expect(DEFAULT_NOTIFY).toBe('mentions')+ expect(NOTIFY_LEVELS).toEqual(['all', 'mentions', 'muted'])+ expect(NOTIFY_LEVELS.filter(level => level === DEFAULT_NOTIFY)).toEqual(['mentions'])+ })+})diff --git a/backend/src/superTabs/mentions.ts b/backend/src/superTabs/mentions.tsindex 22f858774..48c1f1317 100644--- a/backend/src/superTabs/mentions.ts+++ b/backend/src/superTabs/mentions.ts@@ -368,7 +368,7 @@ export async function listMentions(tx: Tx, tabId: string, state: SuperTabState,const authorName = taggerName(state, author && { ...author, id: row.authorAgentId })return { id: row.id, projectId: row.projectId, projectName: projectOf(state, group.projectId ?? 'lead').name,conversationId: row.conversationId, conversationTitle: group.title, messageId: row.messageId,- leadId: row.authorAgentId, leadName: authorName, text: (message?.text ?? '').slice(0, 200),+ leadId: row.authorAgentId, leadName: authorName, leadKind: author?.kind ?? null, text: (message?.text ?? '').slice(0, 200),createdAt: row.createdAt, resolvedAt: row.resolvedAt, resolvedBy: row.resolvedBy, threadId: message ? threads.get(message.id) ?? null : null,// Where the tagged message is in its chat: Desktop clears its red number once the reader has read past it (Slack).messageSequence: message?.sequence ?? null }diff --git a/docs/phone-notifications.md b/docs/phone-notifications.mdindex c731448cd..3aba003e8 100644--- a/docs/phone-notifications.md+++ b/docs/phone-notifications.md@@ -1,34 +1,65 @@# Phone notificationsEvery notification the Harness phone app (iOS and Android) can show in the system's notification centre, as of-2026-11-05 (task #3248). **Push** comes from the server through Apple (APNs) or Google (FCM) and reaches a phone+2026-11-06 (task #3607). **Push** comes from the server through Apple (APNs) or Google (FCM) and reaches a phonewhose app is closed or in the background. **Local** is posted by the app itself, from what it reads while it runs.A notice never says what was written: it can be read on a locked phone. It says who, and in which project.-The rule below is the one Tony approved on 2026-11-05 ("Yes, as proposed"): only what needs you pushes, and repeats-collapse.+## The rule++Tony's rule (2026-11-06, task #3607), on top of the one he approved on 2026-11-05 ("Yes, as proposed"). A phone+rings only when a person must act, or when a person speaks to you. Push and Local follow it together.++**Rings** (sound, banner):+- an agent asks you to decide or approve and the work waits on you: `decision.ask`, `needs_human` with an ask, a command+ approval on an agent's machine;+- a sign-in from a device you do not know (Local, below; the server does not push it yet);+- a **person** tags you;+- a **person** replies to you, or in a thread you started or were tagged in.++**Badge and Activity only** (no sound, no banner, nothing in the notification centre):+- an agent finishing a turn, or a whole task;+- an agent replying in your thread (unless it is a decision ask);+- an agent tagging you without a decision or approval. This includes the server's "no reviewer can start" notice: it is+ written as the agent that asked for the review, so it is an agent's tag.+- An agent's words never change this: a plain reply or tag from an agent that asks for your approval is still badge and+ Activity only. Only a real ask rings: `decision.ask`, `needs_human` with an ask, or a command approval on the agent's+ machine.++**One task, one notification.** A task's "stuck", "needs you" and decision question share one notification slot+(`task:<swarm>:<task chat>`): the later replaces the earlier, and it sounds once. Thread replies keep their own slot.++**By the kind of event, never by its words**: who wrote it (person or agent) and what it is (a reply, a tag, a decision, a+finished turn). An agent's message that says "please approve" is still an agent's tag. Only the real ask (`decision.ask`,+`needs_human` with an ask, an approval on the machine) rings.++**Per chat** the default is **Mentions only** (`DEFAULT_NOTIFY`; the app reads it as the same when the server says+nothing). A chat tells every new message only when its person sets **All new messages**.++Repeats collapse, as before: a thread, or a task, is one notification.## The table| Type | When it is received | Event | Title | Example | Test evidence ||---|---|---|---|---|---|-| Push | App closed or in the background. With Harness in front the push is not drawn (iOS `willPresent`, Android FCM in front): the app's own Local notice decides. | A reply, by a person or an agent, in a thread you started or were tagged in, or to your own message (it quotes it). Never your own reply, a Swarm status line in a thread (Working, Ready for review, Done), a thread you only replied in, a muted chat, an unfollowed thread, or a reply that tags you (the tag push tells you instead). **One notification per thread:** a newer reply replaces it. It sounds only when nothing in that thread was unread for you; otherwise it replaces quietly (iOS `passive`, no sound; Android channel `swarm-quiet`). | `<name> replied in a thread`, subtitle the project, body `Open Harness to read it.` | **River replied in a thread** · openharness · Open Harness to read it. Tap: the thread, at the newest reply. | `backend/src/push/notices.test.ts` "phoneNotices: the push rule Tony approved"; `backend/integration/superTabActivity.test.ts` "Phone push: who each push type reaches, and what it carries", "Phone push: a thread sounds once until it is read", "Phone push end to end on the server…"; `apns.test.ts` "APNs: one notification per slot, and quiet repeats"; `fcm.test.ts` "tags the notification with its slot…"; `send.test.ts` "sends each notice as its thread's repeats make it…" |-| Push | As above. | You are tagged, by a person or by an agent of the project, in a chat you can read, including a muted one; also the server's "no reviewer can start" notice, which tags the people who can fix it when no coordinator is in that chat. Never your own tag. A tag held for a quiet chat (no agent working there yet) is not pushed, then or later. Always with sound. | `<name> tagged you`, subtitle the project, body `Open Harness to read it.` | **Tony tagged you** · openharness · Open Harness to read it. Tap: the message, in its thread when it is only there. | `notices.test.ts` "words a tag as the phone does…", "pushes no tag held back for a quiet chat"; `superTabActivity.test.ts` "a tag links the message in the chat…", "keeps each person and each thread apart, and never quiets a tag"; `mobile/test/app_state_push_test.dart` "a tapped push opens the chat its link names" |-| Push | As above. **New in #3248.** | A decision an agent asks of you (`decision.ask`, or `needs_human` with an ask), the first time it is asked. One ask of several questions sounds once; the rest are quiet. | `<asker> asks you`, subtitle the project, body `Open Harness to answer.` | **River asks you** · openharness · Open Harness to answer. Tap: Activity, at the card. | `notices.test.ts` "pushes a decision asked of a person as the app words it…"; `superTabActivity.test.ts` "a decision asked of a person reaches their phone once…", "one ask of several questions sounds once" |-| Local | Harness in front with no Swarm screen open: the Swarm read every 15 s. | A reply in a thread, from the same Activity rows the reply push uses. Shares the push's notification for that thread: it replaces the push rather than adding a second, and posts nothing while a push still shows that thread. Quiet while the thread has an unread reply; taken down, with the push in it, once the thread is read. | `<name> replied in a thread` (`Someone` with no name), project, `Open Harness to read it.` | **Oak replied in a thread** · openharness | `mobile/test/swarm/swarm_notices_test.dart` "shares one notification per thread, the push's too…", "is not posted for a thread a push shows…", "a thread whose push was swiped away unread only replaces quietly…"; `swarm_activity_feed_test.dart`; `test/phone/phone_shell_swarm_notice_test.dart` |-| Local | As above. | A tag waiting for you (the same tags as the tag push), in the push's notification. | `<name> tagged you`, project, `Open Harness to read it.` | **River tagged you** · openharness | `swarm_notices_test.dart` "a tag in a thread opens that thread at the tag"; `swarm_notice_repeat_test.dart` "read again and again, each ask is told once" |-| Local | As above. | A decision asked of you, in the push's notification. | `<asker> asks you`, project, `Open Harness to answer.` | **River asks you** · openharness · Open Harness to answer. Tap: Activity, at the card. | `swarm_notices_test.dart` "a decision says who asks…"; `phone_shell_swarm_notice_test.dart` |-| Local | As above. | A task waiting on you is `blocked`: you are its chat's partner, or else the project's owner. | `<agent> is stuck`, project, `Open Harness to see why.` | **Magnolia2 is stuck** · openharness | `swarm_notices_test.dart` |-| Local | As above. | A task waiting on you (as above) needs a person (`needs_human`). | `<agent> needs you`, project, `Open Harness to answer.` | **Oak needs you** · openharness | `swarm_notices_test.dart` |+| Push | App closed or in the background. With Harness in front the push is not drawn (iOS `willPresent`, Android FCM in front): the app's own Local notice decides. | A reply **by a person** in a thread you started or were tagged in, or to your own message (it quotes it). **Never an agent's reply** (#3607: it stays in Activity and the badge). Never your own reply, a Swarm status line in a thread (Working, Ready for review, Done), a thread you only replied in, a muted chat, an unfollowed thread, or a reply that tags you (the tag push tells you instead). **One notification per thread:** a newer reply replaces it. It sounds only when nothing in that thread was unread for you; otherwise it replaces quietly (iOS `passive`, no sound; Android channel `swarm-quiet`). | `<name> replied in a thread`, subtitle the project, body `Open Harness to read it.` | **River replied in a thread** · openharness · Open Harness to read it. Tap: the thread, at the newest reply. | `backend/src/push/notices.test.ts` "phoneNotices: the push rule Tony approved", "phoneNotices: who rings (task #3607…)"; `backend/integration/superTabActivity.test.ts` "Phone push: who each push type reaches, and what it carries", "Phone push: a thread sounds once until it is read", "Phone push end to end on the server…"; `apns.test.ts` "APNs: one notification per slot, and quiet repeats"; `fcm.test.ts` "tags the notification with its slot…"; `send.test.ts` "sends each notice as its thread's repeats make it…" |+| Push | As above. | You are tagged **by a person** in a chat you can read, including a muted one. An agent's tag does not ring (#3607), nor does the server's "no reviewer can start" notice, which is written as an agent and tags the people who can fix it: both are in Activity and the badge. Never your own tag. A tag held for a quiet chat (no agent working there yet) is not pushed, then or later. Always with sound. | `<name> tagged you`, subtitle the project, body `Open Harness to read it.` | **Tony tagged you** · openharness · Open Harness to read it. Tap: the message, in its thread when it is only there. | `notices.test.ts` "words a tag as the phone does…", "pushes no tag held back for a quiet chat", "an agent's tag rings nobody, a person's tag rings", "the server's "no reviewer can start" tag is an agent's tag…"; `superTabActivity.test.ts` "a tag links the message in the chat…", "keeps each person and each thread apart, and never quiets a tag"; `mobile/test/app_state_push_test.dart` "a tapped push opens the chat its link names" |+| Push | As above. **New on 2026-11-05.** | A decision an agent asks of you (`decision.ask`, or `needs_human` with an ask), the first time it is asked. One ask of several questions sounds once; the rest are quiet. **All of a task's decisions share one slot** (`task:<swarm>:<task chat>`, #3607), the same slot as the task's Local "stuck" and "needs you". | `<asker> asks you`, subtitle the project, body `Open Harness to answer.` | **River asks you** · openharness · Open Harness to answer. Tap: Activity, at the card. | `notices.test.ts` "pushes a decision asked of a person as the app words it…"; `superTabActivity.test.ts` "a decision asked of a person reaches their phone once…", "one ask of several questions sounds once" |+| Local | Harness in front with no Swarm screen open: the Swarm read every 15 s. | A reply **by a person** in a thread, from the same Activity rows the reply push uses (an agent's reply posts nothing, #3607). Shares the push's notification for that thread: it replaces the push rather than adding a second, and posts nothing while a push still shows that thread. Quiet while the thread has an unread reply; taken down, with the push in it, once the thread is read. | `<name> replied in a thread` (`Someone` with no name), project, `Open Harness to read it.` | **Oak replied in a thread** · openharness | `mobile/test/swarm/swarm_notices_test.dart` "shares one notification per thread, the push's too…", "is not posted for a thread a push shows…", "a thread whose push was swiped away unread only replaces quietly…"; `swarm_activity_feed_test.dart`; `test/phone/phone_shell_swarm_notice_test.dart` |+| Local | As above. | A tag by a person waiting for you (the same tags as the tag push), in the push's notification. A tag by an agent is the badge only: the mention list says who tagged (`leadKind`), and the app posts nothing for an agent. | `<name> tagged you`, project, `Open Harness to read it.` | **River tagged you** · openharness | `swarm_notices_test.dart` "a tag in a thread opens that thread at the tag", group "who rings (task #3607)"; `swarm_notice_repeat_test.dart` "read again and again, each ask is told once" |+| Local | As above. | A decision asked of you, in the push's notification: the task's slot, shared with "stuck" and "needs you" below. | `<asker> asks you`, project, `Open Harness to answer.` | **River asks you** · openharness · Open Harness to answer. Tap: Activity, at the card. | `swarm_notices_test.dart` "a decision says who asks…", group "one task, one notification (task #3607)"; `phone_shell_swarm_notice_test.dart` |+| Local | As above. | A task waiting on you is `blocked`: you are its chat's partner, or else the project's owner. Shares the task's one slot: it replaces the task's earlier notice quietly. | `<agent> is stuck`, project, `Open Harness to see why.` | **Magnolia2 is stuck** · openharness | `swarm_notices_test.dart` |+| Local | As above. | A task waiting on you (as above) needs a person (`needs_human`). Shares the task's one slot, as above. | `<agent> needs you`, project, `Open Harness to answer.` | **Oak needs you** · openharness | `swarm_notices_test.dart` || Local | As above. | A new message in a chat you set to **All new messages**. One notice per chat; it sounds once until you read the chat, and a newer message replaces it quietly. | `New messages`, project, `Open Harness to read them.` | **New messages** · openharness | `mobile/test/swarm/swarm_chat_notices_test.dart` "All new messages: each new message in the chat is told, one notice…", "read, the chat's next message sounds again" |-| Local | Harness in front, or seconds after it goes to the background (the machine's socket). Not while you look at that agent. | An agent on your machine finished a turn the daemon ranks worth telling (not `silent` or `list`). One notice per agent; it sounds once until you go to the agent, and a newer turn replaces it quietly. | The agent's name, subtitle the machine, body the reply's last paragraph (180 characters at most). | **Fix login** · MacBook · Fixed it. Tap: the agent's chat (or terminal with Swarm off). | `mobile/test/notify/agent_announcer_test.dart` "a finished turn sounds once until the person goes to the agent…"; `local_system_notices_test.dart` "a finished turn: the agent, its machine, its news, on the done channel"; `announcer_lifecycle_test.dart`; `done_notice_test.dart` |+| None | Harness in front, or seconds after it goes to the background (the machine's socket). | An agent on your machine finished a turn. **Badge only** (#3607): the agent is marked unread, with no sound, no banner and no notification, whatever tier the daemon gave. Nothing at all for the agent you are looking at, for a `silent` turn, or for a turn that said nothing. | None. | The unread dot on the agent. | `mobile/test/notify/finished_turn_badge_only_test.dart`; `done_notice_test.dart`; `agent_announcer_test.dart`; `announcer_lifecycle_test.dart`; `local_system_notices_test.dart` || Local | As above; in front, only after 15 s still unanswered. | An agent on your machine asks a question (approval, choice). A repeat within 5 minutes is quiet: no sound, no banner. | The agent's name, the machine, the question. | **Fix login** · MacBook · Approve Bash command: rm -rf dist | `local_system_notices_test.dart` "a question rides a channel of its own…", "a quiet notice…"; `question_notice_test.dart`; `question_spam_incident_test.dart` || Local | When the phone next reads the account's devices (sign-in, or a device-keys change on a machine socket). | A new device joined or signed in to your account. Once per device. | `New device on your account` | **New device on your account** · Pixel 9 signed in to your account and can reach your machines. Not yours? Remove it in Settings ▸ Your devices. | `local_system_notices_test.dart` "a new device on the account…"; `test/phone/phone_shell_device_notice_test.dart` || Local | As above. | A device left your account: it signed out, another device removed it, or a new device you have not looked at removed it. | `Device signed out`, `Device removed` or `Removed by a new device` | **Device removed** · iPad was removed from your account by MacBook. | `test/state/device_removal_notice_test.dart`; `phone_shell_device_notice_test.dart` |-**Silent, never pushed** (in the app's Activity and badge only): a reply in a thread you only replied in, a Swarm status-line in a thread, reactions, and messages outside threads that tag nobody. Evidence: `superTabActivity.test.ts` "a reply+**Silent, never pushed** (in the app's Activity and badge only): an agent's reply or tag, an agent finishing a turn or a+task, a reply in a thread you only replied in, a Swarm status line in a thread, reactions, and messages outside threads+that tag nobody. Evidence: `superTabActivity.test.ts` "a replyreaches the thread's starter, the quoted message's author and people tagged earlier in it, never its author nor one whoonly replied", "tells the starter and every person who replied, but never the reply's author" (the Activity rows), "pushesnothing for a message outside threads that tags nobody, or for a reaction"; `notices.test.ts` "pushes no Swarm line in a@@ -48,13 +79,13 @@ reflection decisions) are listed in Activity and are not pushed.phone the person registered (`push/devices.ts`); `push/apns.ts` and `push/fcm.ts` talk to Apple and Google.- Keys and slots. Each notice has a **key** (`reply:<swarm>:<row>`, `mention:<row>`, `decision:<id>`), the same as theapp's Local notice for the same thing, and a **slot**, the notification it shows in: `thread:<swarm>:<chat>:<root>` for a- reply, the key for a tag or a decision. APNs: `apns-collapse-id` is the slot's id (`swarmNoticeId`, FNV-1a, the same as+ reply, `task:<swarm>:<task chat>` for a decision (and the app's "stuck" and "needs you" for that task), the key for a tag. APNs: `apns-collapse-id` is the slot's id (`swarmNoticeId`, FNV-1a, the same asthe app's `swarmNoticeIdFor`), so the app's notice under that id replaces the push. FCM: the notification's tag is theslot, and the app posts under that tag with id 0, as FCM draws it. The payload's `link` is`swarm:<swarm>/<chat>/message/<message>[/thread/<root>]` or `swarm:<swarm>/<chat>/decision/<id>`.- Local: `mobile/lib/notify/system_notices.dart` posts all of them. Swarm ones come from `lib/swarm/swarm_notices.dart`- (Android channel and iOS thread `swarm-needs-you`), agent ones from `lib/notify/agent_announcer.dart` (`agent-done`,- `agent-question`), device ones from `lib/state/app_state.dart` (`account-device`). On Android the app makes the+ (Android channel and iOS thread `swarm-needs-you`), agent ones from `lib/notify/agent_announcer.dart` (`agent-question`;+ a finished turn is a mark only), device ones from `lib/state/app_state.dart` (`account-device`). On Android the app makes the`swarm-needs-you` and `swarm-quiet` channels when push starts, before any push can arrive.- Back in front, the app asks which pushes are still shown (`PushChannel.shown`: iOS gives each push's key and slot,Android its tag, the slot) and posts none of them again (#3150), nor anything for a thread a push still shows.@@ -72,3 +103,8 @@ reflection decisions) are listed in Activity and are not pushed.5. A tag held for a quiet chat is never pushed, even once the hold ends. Unchanged (not part of the approved rule).6. A decision asked of you was Local only. Fixed: it pushes.7. A chat set to All new messages, and an agent's finished turns, buzzed every time. Fixed: they sound once until seen.+8. (#3607) An agent's reply or tag, and an agent finishing a turn, rang the phone as loudly as a person did. Fixed: they are+ badge and Activity only, classified by who wrote them, never by their words. A task's "stuck", "needs you" and decision+ question were three notifications; they are one slot now.+9. (#3607) Not changed, proposed: the server does not push "a sign-in from a device you do not know" (the app reads it+ when it next opens). A push needs the device-sign-in write path and two security reviews, so it is a separate task.diff --git a/docs/plans/2026-11-06-phone-notification-rules-plan.md b/docs/plans/2026-11-06-phone-notification-rules-plan.mdnew file mode 100644index 000000000..bfb6003b7--- /dev/null+++ b/docs/plans/2026-11-06-phone-notification-rules-plan.md@@ -0,0 +1,201 @@+# Phone notification rules Implementation Plan++> **How this plan is carried out:** by one Engineer in this session, task by task, each failing test committed and watched+> failing before the code that passes it (the project's way of working, not subagent-driven-development). Steps use+> checkbox (`- [ ]`) syntax.++**Goal:** The phone rings only when a person must act or a person speaks to you, the same way on the server's push and on+the app's own notices, and one task's stuck / needs-you / decision question is one notification.++**Architecture:** The backend's `phoneNotices` (`backend/src/push/notices.ts`) and the app's `SwarmAnnouncer`+(`mobile/lib/swarm/swarm_notices.dart`) already word and key the same notices so a push and the app's notice share one+slot. Each rule is applied in both places by the **type of the event** (who wrote it: person or agent; what it is: reply,+tag, decision, work waiting), never by its text. A decision and the work waiting on the same task get one shared slot,+`task:<swarm>:<conversation>`.++**Tech Stack:** TypeScript + vitest (`backend/`), Dart + flutter_test (`mobile/`).++**Spec:** the task #3607 brief (Tony's push thread, 2026-11-06) and the table in+[docs/phone-notifications.md](../phone-notifications.md), which this plan rewrites to the new rule.++## Global Constraints++- Ring (push or sound): an agent asks you to decide or approve and work waits on you (`decision.ask`, `needs_human` with an+ ask, a command approval); a sign-in from an unknown device; a person tags you; a person replies to you or in a thread you+ started.+- No ring, badge and Activity only: an agent finishing a turn or a whole task; an agent replying in your thread (unless it+ asks and waits for your approval, which is a decision); an agent tagging you without a decision or approval.+- Merge: "stuck", "needs you" and the decision question of the same task make one notification.+- Default per chat: Mentions only; All new messages only when the person turns it on.+- Classify by event type, never by reading message text. A notice never says what was written (unchanged).+- A reply keeps its reasons: `starter`, `quoted`, `tagged` push when a person wrote it; `replier` never (unchanged).+- Unchanged (Tony, 2026-11-06): questions and approvals ring; a device joining rings; thread replies share one notice; a+ question answered elsewhere takes its notice down; a teammate's Team-account agents never notify.+- Compatibility: a new phone on an old backend, and an old phone on a new backend, lose no alert. A tag whose tagger kind+ the phone does not know rings, as it does today.+- Swarm code stays out of `cli/src/core`. No schema, collection, index or query change.++**Decided, not asked:** (1) a reply in a thread you were tagged in (`tagged`) stays pushed when a person wrote it: it is+a person speaking to you, and the brief does not take it away. (2) A new *server push* for a device sign-in is not in+this change: the phone already rings for it locally (`New device on your account`), and a push there is sign-in code that+needs two security reviews; it goes to the PM as a follow-up.++**Design** (feature-design rules; this change exposes one field and stores nothing):++- growth, concurrency, read cost, scale, migration: N/A because nothing is stored and no read is added; the one field+ rides a row the mentions list already returns.+- compatibility: `leadKind` absent (old backend) rings as before; an old phone ignores it.+- audience: the field is the tagger's kind, already visible in the chat the person can read.+- identity: N/A. failure: a missing kind rings rather than loses an alert. platforms: iOS and Android alike.++## Review Focus++1. An agent's message whose words say "approve" or "decide" but is no decision stays silent (Task 1).+2. An old backend sends no `leadKind`: the phone still tells the tag (Task 3).+3. A task's decision answered on the desktop while its stuck notice is up: the one notification goes, and answering one of+ two needs leaves it up (Task 4).+4. Android: the push of a decision (tag = the task slot) is not posted again by the phone when it comes to the front, and+ does not sound twice (Task 4).+5. A person's tag in a muted chat still tells; a held tag (quiet chat) is still not pushed (Task 1).++---++### Task 1: Backend rings only for a person's reply and a person's tag++**Files:**+- Modify: `backend/src/push/notices.ts` (`phoneNotices`)+- Test: `backend/src/push/notices.test.ts`, `backend/integration/superTabActivity.test.ts` (three existing tests assume an+ agent's tag or reply pushes: "an agent's tag is worded with the agent's name…", the Buddy-chat reply test in+ `notices.test.ts`, and "words a tag as the phone does…")++**Interfaces:**+- Consumes: `ReplyRow.actorKind` (`'person' | 'agent'`), the tag message's `author.kind`.+- Produces: `phoneNotices` returns no reply notice for an agent actor and no tag notice for an agent author. Signature+ unchanged.++- [ ] **Step 1: Write the failing tests** in `notices.test.ts`, in a new `describe('phoneNotices: who rings (task #3607)')`:+ `an agent's reply rings nobody, for starter, quoted and tagged alike`; `a person's reply rings for starter, quoted and+ tagged, never replier`; `an agent's tag rings nobody, a person's tag rings`; `an agent's text that says approve or decide+ rings nobody (type, not words)`; `a tag held for a quiet chat is still not pushed`. Change the two existing tests that+ use an agent as the reply actor or tagger to use a person, and add the agent case beside them.+- [ ] **Step 2: Run** `cd backend && NODE_ENV=test HARNESS_CREDENTIAL_ENCRYPTION_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= npx vitest run src/push/notices.test.ts`. Expected: the new tests FAIL (agent notices returned).+- [ ] **Step 3: Implement** in `phoneNotices`: keep a reply row only when `row.actorKind === 'person'`; keep a tag row only+ when `byId.get(row.messageId)?.author.kind === 'person'`.+- [ ] **Step 4: Run** the same command. Expected: PASS.+- [ ] **Step 5: Update** the integration test expectations for the agent tag and Buddy reply to "no push" (they run in PR CI).+- [ ] **Step 6: Commit** the failing tests, then (after Step 3) the code, as two commits.++### Task 2: Backend decisions share a task slot; the mentions list says who tagged++**Files:**+- Modify: `backend/src/push/notices.ts` (export `taskSlot`, use it for decisions), `backend/src/superTabs/mentions.ts`+ (`listMentions` adds `leadKind`)+- Test: `backend/src/push/notices.test.ts`, `backend/src/push/apns.test.ts` / `fcm.test.ts` only if they pin a decision's slot,+ the mentions list test in `backend/integration` that already reads `listMentions`.++**Interfaces:**+- Produces: `export const taskSlot = (tabId: string, conversationId: string) => \`task:${tabId}:${conversationId}\``; a+ decision notice keeps `key: decision:<id>` and gets `slot: taskSlot(tabId, row.conversationId)`. Each `listMentions` row+ gains `leadKind: 'person' | 'agent' | null` (the tag message's `author.kind`).+- Consumed by Tasks 3 and 4 (the app builds the same slot string and reads `leadKind`).++- [ ] **Step 1: Write the failing tests:** `two decisions in one task share one slot, two tasks do not`; `a decision's key+ stays decision:<id>`; `listMentions says whether a person or an agent tagged` (integration, next to the existing+ listMentions test).+- [ ] **Step 2: Run** the unit file; Expected: FAIL (slot equals key; no `leadKind`).+- [ ] **Step 3: Implement** both changes. `leadKind` is read from the message already loaded for `leadName`.+- [ ] **Step 4: Run** the unit file; Expected: PASS. Run `npm test` in `backend/` once before Ready (the unit suite).+- [ ] **Step 5: Commit** tests, then code.++### Task 3: App: an agent's reply or tag is badge and Activity only++**Files:**+- Modify: `mobile/lib/swarm/swarm_asks.dart` (`SuperTabMention.leadKind`), `mobile/lib/swarm/swarm_notices.dart`+ (`SwarmAnnouncer.announce`, `announceReply`)+- Test: `mobile/test/swarm/swarm_notices_test.dart`, `mobile/test/swarm/swarm_notice_repeat_test.dart`++**Interfaces:**+- Consumes: the server's `leadKind` (Task 2) and `SwarmActivityEntry.actorKind` (`'person' | 'agent'`).+- Produces: `SuperTabMention.leadKind` (`String?`, null when the backend does not send it);+ `bool get taggedByAgent => leadKind == 'agent'`.++- [ ] **Step 1: Write the failing tests:** `a tag by an agent posts no notice but still counts on the badge`; `a tag by a+ person rings`; `a tag with no leadKind (old backend) rings`; `a reply by an agent posts no notice and takes no thread slot`;+ `a reply by a person rings and one reply sounds once per thread` (kept).+- [ ] **Step 2: Run** `cd mobile && flutter test test/swarm/swarm_notices_test.dart test/swarm/swarm_notice_repeat_test.dart --concurrency=2`. Expected: the agent cases FAIL.+- [ ] **Step 3: Implement** `SuperTabMention.leadKind` parse; `announce` returns early (the need still counts in `settle`'s+ badge) when `need` is a `SwarmMentionNeed` with `taggedByAgent`; `announceReply` returns early when+ `entry.actorKind == 'agent'`, before it registers a thread slot.+- [ ] **Step 4: Run** the same command. Expected: PASS.+- [ ] **Step 5: Commit** tests, then code.++### Task 4: App: stuck, needs you and the decision of one task are one notification++**Files:**+- Modify: `mobile/lib/swarm/swarm_notices.dart` (`swarmNotice`, `SwarmAnnouncer.announce`, `_posted`, `_takeDown`,+ `swarmRead`, `settle`)+- Test: `mobile/test/swarm/swarm_notices_test.dart`, `mobile/test/phone/phone_shell_swarm_notice_test.dart`++**Interfaces:**+- Produces: `String swarmTaskSlot(String swarmId, String conversationId)` returning `task:$swarmId:$conversationId`+ (the same string as the backend's `taskSlot`). `swarmNotice` for a `SwarmDecisionNeed` and a `SwarmWorkNeed` (stuck,+ needs you, at a prompt) uses that slot as its notice `key`; a `SwarmMentionNeed` keeps its own key.+- Behaviour: when a notice already shows that slot, the next one replaces it quietly. When `told.pushed(slot)` is true+ (the server's push shows it) the app posts none. The slot's notification is taken down only when no posted need holds it.++- [ ] **Step 1: Write the failing tests:** `stuck, needs you and a decision of one task post under one key, the later ones+ quiet`; `two tasks keep two notifications`; `answering one of two needs leaves the notification, answering both takes it+ down (two reads in a row, as before)`; `a task whose decision push shows its slot gets no local notice`; `the badge still+ counts each need`.+- [ ] **Step 2: Run** the Task 3 command plus `test/phone/phone_shell_swarm_notice_test.dart`. Expected: FAIL.+- [ ] **Step 3: Implement** `swarmTaskSlot`; make `_posted` map a need key to its swarm and slot; `announce` skips when+ `told.pushed(slot)`, and posts `quiet: true` when another posted need holds the slot; `_takeDown(needKey)` removes the need+ and cancels the slot only when no other posted need holds it.+- [ ] **Step 4: Run** the same command. Expected: PASS.+- [ ] **Step 5: Commit** tests, then code.++### Task 5: App: an agent's finished turn posts no notification++**Files:**+- Modify: `mobile/lib/notify/done_notice.dart` (`decideDoneNotice`), `mobile/lib/notify/agent_announcer.dart`+ (`_announceEnd`) if the decision is not enough+- Test: `mobile/test/notify/done_notice_test.dart`, `mobile/test/notify/agent_announcer_test.dart`,+ `mobile/test/notify/local_system_notices_test.dart`++**Interfaces:**+- Produces: a finished turn never returns an `AgentNotice` that alerts or chimes; the agent's unread mark (dot, badge) is+ kept. Questions (`questionAsked`) are unchanged.++- [ ] **Step 1: Write the failing tests:** `a finished turn marks the agent unread and posts nothing, in front or away, at+ any tier`; `a question still posts and chimes`; `a turn that ends while a question is up leaves the question`.+- [ ] **Step 2: Run** `cd mobile && flutter test test/notify/done_notice_test.dart test/notify/agent_announcer_test.dart test/notify/local_system_notices_test.dart --concurrency=2`. Expected: FAIL.+- [ ] **Step 3: Implement** in `decideDoneNotice`: the strongest result is the mark. Update the tests that expected a done+ notice to the new rule (a deliberate behaviour change, not a loosened assertion).+- [ ] **Step 4: Run** the same command. Expected: PASS.+- [ ] **Step 5: Commit** tests, then code.++### Task 6: The default per chat is Mentions only, pinned; the rule table in the docs++**Files:**+- Test: `backend/src/superTabs/chatSettings.test.ts` (or the file that already tests it), `mobile/test/swarm/swarm_chat_notices_test.dart`+- Modify: `docs/phone-notifications.md`++- [ ] **Step 1: Write the pinning tests:** backend `a chat with no row is mentions only, and a person's choice of all is kept`;+ app `SwarmNotify.parse(null)` and an unknown word are `mentions`; `a chat nobody set tells no new message; only a chat set+ to All new messages does`. They pass at once: the default already holds, and these keep it (no red phase; say so in the+ PR's evidence).+- [ ] **Step 2: Run** each file. Expected: PASS.+- [ ] **Step 3: Rewrite** the table in `docs/phone-notifications.md` to Ring / No ring with the new rule, the shared task slot+ and the tests that pin each row; keep the "Where each one comes from" section true.+- [ ] **Step 4: Commit.**++### Task 7: Evidence and Ready++- [ ] Run, in `backend/`, `npm test`; in `mobile/`, every file named above with `--concurrency=2`, rerunning any file lost to+ a flutter_tester connection error alone; `flutter analyze` on the changed Dart files; `npx tsc --noEmit` in `backend/`.+- [ ] For each task, check out the commit before its code and show its tests failing (red), then the commit with the code+ passing (green); post both in a PR comment.+- [ ] Run the changed behaviour once in the iOS simulator and once in the Android emulator (name the device with `-d`; never+ the attached iPhone): a person's tag, an agent's tag, a decision with the same task stuck. Record what each showed.+- [ ] Mark the PR ready and tell River (the Reviewer and Tester for this run are put on when it is Ready); Tony's iPhone+ test waits until he says the phone is free.diff --git a/mobile/integration_test/phone_notification_rules_test.dart b/mobile/integration_test/phone_notification_rules_test.dartnew file mode 100644index 000000000..99914907d--- /dev/null+++ b/mobile/integration_test/phone_notification_rules_test.dart@@ -0,0 +1,141 @@+import 'dart:async';++import 'package:flutter/foundation.dart';+import 'package:flutter_local_notifications/flutter_local_notifications.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:integration_test/integration_test.dart';++import 'package:harness_mobile/notify/agent_announcer.dart';+import 'package:harness_mobile/notify/done_notice.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/swarm/swarm_asks.dart';+import 'package:harness_mobile/swarm/swarm_inbox.dart';+import 'package:harness_mobile/swarm/swarm_notices.dart';++/// Which notices the phone puts in the system's notification centre (task #3607, Tony 2026-11-06):+/// the real [LocalSystemNotices] and the platform's own centre, on an iOS simulator or an Android+/// emulator, fed what the Swarm read and the machine socket would tell.+///+/// Rings: a person's tag, a decision asked, an agent's question. Never: an agent's tag, an+/// agent's finished turn. A task's decisions are one notification.+///+/// Nothing reaches an account, a machine or a backend. The app must be allowed to notify first:+/// Android `pm grant <package> android.permission.POST_NOTIFICATIONS`; on iOS, allowed once by+/// `integration_test/push_e2e/run.sh`, which the same simulator keeps between installs.+///+/// flutter test -d <simulator or emulator id> integration_test/phone_notification_rules_test.dart+void main() {+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();++ SwarmMentionNeed tag(String id, String who, String kind) => SwarmMentionNeed(+ 'tab-e2e',+ SuperTabMention.fromJson({+ 'id': id,+ 'projectName': 'Mobile',+ 'conversationId': 'g1',+ 'conversationTitle': 'Fix login',+ 'messageId': 'msg-$id',+ 'leadName': who,+ 'leadKind': kind,+ 'text': 'never in a notice',+ }),+ );++ SwarmDecisionNeed decision(String id, String asker) => SwarmDecisionNeed(+ 'tab-e2e',+ SuperTabDecision.fromJson({+ 'id': id,+ 'projectName': 'Mobile',+ 'conversationId': 'g9',+ 'conversationTitle': 'Ship it',+ 'askerName': asker,+ 'question': 'never in a notice',+ 'options': ['Yes', 'No'],+ }),+ );++ Future<List<String>> titles(FlutterLocalNotificationsPlugin plugin) async => [+ for (final n in await plugin.getActiveNotifications()) ?n.title,+ ];++ test('rings for a person and a question; badge only for an agent', () async {+ final plugin = FlutterLocalNotificationsPlugin();+ final notices = LocalSystemNotices(plugin);+ unawaited(notices.requestPermission());+ for (var i = 0; i < 30 && await notices.enabled() != true; i++) {+ await Future<void>.delayed(const Duration(seconds: 1));+ }+ expect(+ await notices.enabled(),+ isTrue,+ reason: 'the app must be allowed to notify before this runs',+ );+ await plugin.cancelAll();++ final swarm = SwarmAnnouncer(notices, quiet: (_) => false);+ swarm.announce(tag('m1', 'Robo', 'agent'));+ swarm.announce(tag('m2', 'Ada', 'person'));+ swarm.announce(decision('d1', 'River'));+ swarm.announce(decision('d2', 'Magnolia'));++ final agents = AgentAnnouncer(+ system: notices,+ chime: () async {},+ inFront: () => false,+ questionGrace: Duration.zero,+ );+ const finisher = (+ ref: (machineId: 'm', agentId: 'a'),+ name: 'Finisher',+ machine: 'MacBook',+ );+ const asker = (+ ref: (machineId: 'm', agentId: 'b'),+ name: 'Asker',+ machine: 'MacBook',+ );+ agents.turnEnded(finisher, (+ aborted: false,+ replay: false,+ subagent: false,+ reply: 'Fixed the login screen.',+ tier: NoticeTier.alert,+ ), watching: () => false);+ agents.questionAsked(+ asker,+ requestId: 'q1',+ prompt: 'Approve Bash command: ls',+ watching: () => false,+ );++ // The platform draws them a moment after being asked; wait for the ones+ // that must come, then a little longer for any that must not.+ var shown = <String>[];+ for (var i = 0; i < 20; i++) {+ shown = await titles(plugin);+ if (shown.contains('Ada tagged you') &&+ shown.contains('Magnolia asks you') &&+ shown.contains('Asker')) {+ break;+ }+ await Future<void>.delayed(const Duration(milliseconds: 500));+ }+ await Future<void>.delayed(const Duration(seconds: 2));+ shown = await titles(plugin);+ debugPrint('rules-e2e: in the centre: ${(shown..sort()).join(' | ')}');++ expect(shown, contains('Ada tagged you'), reason: "a person's tag rings");+ expect(shown, contains('Asker'), reason: "an agent's question rings");+ expect(shown.where((t) => t.endsWith(' asks you')), [+ 'Magnolia asks you',+ ], reason: "a task's decisions are one notification; the later replaces");+ expect(shown, isNot(contains('Robo tagged you')), reason: "an agent's tag");+ expect(+ shown,+ isNot(contains('Finisher')),+ reason: "an agent's finished turn",+ );++ await plugin.cancelAll();+ });+}diff --git a/mobile/lib/notify/agent_announcer.dart b/mobile/lib/notify/agent_announcer.dartindex 077cb9a30..0c047b94c 100644--- a/mobile/lib/notify/agent_announcer.dart+++ b/mobile/lib/notify/agent_announcer.dart@@ -125,10 +125,6 @@ class AgentAnnouncer {/// second thing to dismiss by hand — without asking the OS for one that was/// never posted.final _posted = <AgentRef>{};-- /// Of [_posted], the agents whose notice up tells of a finished turn: the- /// next turn's end replaces it quietly (task #3248).- final _doneUp = <AgentRef>{};final Future<void> Function() _chime;final bool Function() _inFront;@@ -224,13 +220,8 @@ class AgentAnnouncer {}) {final front = inFront;final seen = front && watching();- var notice = decideDoneNotice(end, inFront: front, watching: seen);- // Sounds once until the person goes to the agent (task #3248, the rule- // Tony approved): a turn that ends while the last one's notice is still up- // replaces it quietly.- if (notice == AgentNotice.alert && _doneUp.contains(agent.ref)) {- notice = AgentNotice.quiet;- }+ // A finished turn is a mark on the agent and nothing louder (task #3607).+ final notice = decideDoneNotice(end, inFront: front, watching: seen);// Ids and decisions only: what the turn said stays out of the log.appLog.debug('notify', 'done · ${_short(agent.ref)} · ${front ? 'front' : 'away'}${seen ? ' · watching' : ''} · ${notice.name}');_deliver(agent, notice, NoticeKind.done, () => noticeBody(end.reply!));@@ -437,7 +428,6 @@ class AgentAnnouncer {}void _withdraw(AgentRef ref) {- _doneUp.remove(ref);if (_posted.remove(ref)) system.cancel(ref);}@@ -451,13 +441,6 @@ class AgentAnnouncer {if (notice.marks) unread.mark(agent.ref, kind);if (!notice.alerts) return;_posted.add(agent.ref);- // The agent's one notice now tells of this kind: a question over a- // finished turn leaves the next turn's end free to sound.- if (kind == NoticeKind.done) {- _doneUp.add(agent.ref);- } else {- _doneUp.remove(agent.ref);- }system.show((agent: agent.ref,kind: kind,diff --git a/mobile/lib/notify/done_notice.dart b/mobile/lib/notify/done_notice.dartindex 2abf8d55c..be6d9550c 100644--- a/mobile/lib/notify/done_notice.dart+++ b/mobile/lib/notify/done_notice.dart@@ -93,22 +93,20 @@ bool isNewsEnd(TurnEnd end) {/// [inFront] is whether the app is on screen at all; [watching] whether the/// agent it is showing is the one that finished — only meaningful in front.///-/// The [TurnEnd] flags say whether the end is news at all; its tier, when-/// the daemon sends one, says how loud. As on the dial-/// (`ui_notify_summary`, 2026-10-19): the agent on screen already shows its-/// own news and gets nothing, a `list` turn is a mark with no tap and no-/// notice, and only an `alert` goes as far as the phone's place allows.+/// An agent finishing a turn is badge only (Tony, 2026-11-06, task #3607): a+/// mark on the agent and nothing louder — no chime, no system notice, whatever+/// tier the daemon gave. A turn the daemon calls `silent`, one that is not+/// news, and one of the agent the person is looking at (it shows its own news)+/// are nothing. What a person must act on, a question, rings elsewhere+/// (`question_notice.dart`).AgentNotice decideDoneNotice(TurnEnd end, {required bool inFront,required bool watching,}) {if (!isNewsEnd(end)) return AgentNotice.none;- final tier = end.tier;- if (tier == null) return escalate(inFront: inFront, watching: watching);- if (tier == NoticeTier.silent || (inFront && watching)) {+ if (end.tier == NoticeTier.silent || (inFront && watching)) {return AgentNotice.none;}- if (tier == NoticeTier.list) return AgentNotice.filed;- return escalate(inFront: inFront, watching: false);+ return AgentNotice.filed;}diff --git a/mobile/lib/swarm/swarm_asks.dart b/mobile/lib/swarm/swarm_asks.dartindex 4a4387057..31010335e 100644--- a/mobile/lib/swarm/swarm_asks.dart+++ b/mobile/lib/swarm/swarm_asks.dart@@ -77,6 +77,7 @@ class SuperTabMention implements SwarmAskItem {conversationTitle = row['conversationTitle'] as String? ?? '',messageId = row['messageId'] as String,leadName = row['leadName'] as String? ?? 'Lead',+ leadKind = row['leadKind'] as String?,text = row['text'] as String? ?? '',createdAt = DateTime.tryParse(row['createdAt'] as String? ?? ''),resolvedBy = row['resolvedBy'] as String?,@@ -88,6 +89,14 @@ class SuperTabMention implements SwarmAskItem {@overridefinal DateTime? createdAt;+ /// Who tagged, by kind: `person` or `agent`; null from a backend before it+ /// (task #3607).+ final String? leadKind;++ /// Whether an agent tagged, not a person: such a tag is badge and Activity+ /// only, never a notice. Unknown (an older backend) is told, as before.+ bool get taggedByAgent => leadKind == 'agent';+/// `reply` or `done` once it moved to Earlier; null while it waits.final String? resolvedBy;diff --git a/mobile/lib/swarm/swarm_notices.dart b/mobile/lib/swarm/swarm_notices.dartindex a7dc24312..44bdb77db 100644--- a/mobile/lib/swarm/swarm_notices.dart+++ b/mobile/lib/swarm/swarm_notices.dart@@ -15,7 +15,7 @@ import 'swarm_reader.dart';/// hide one part of it there for sure: so what is asked, and the conversation/// it is in, are read in the app only (Lead, 2026-10-27). The one place to/// change if notices may say more.-SwarmNoticeMessage swarmNotice(SwarmNeed need) {+SwarmNoticeMessage swarmNotice(SwarmNeed need, {bool quiet = false}) {final (title, project, body) = switch (need) {SwarmDecisionNeed(:final decision) => ('${decision.askerName} asks you',@@ -44,7 +44,16 @@ SwarmNoticeMessage swarmNotice(SwarmNeed need) {),};return (- key: need.key,+ key: switch (need) {+ // A task's decision, its "stuck" and its "needs you" are one+ // notification, the server's push for the decision too (task #3607).+ SwarmDecisionNeed() => swarmTaskSlot(need.swarmId, need.conversationId),+ SwarmWorkNeed(:final work) when !work.atPrompt => swarmTaskSlot(+ need.swarmId,+ need.conversationId,+ ),+ _ => need.key,+ },title: title,subtitle: project,body: body,@@ -56,10 +65,16 @@ SwarmNoticeMessage swarmNotice(SwarmNeed need) {// A tag in a reply only in its thread opens that thread.threadId: need is SwarmMentionNeed ? need.mention.threadId : null,),- quiet: false,+ quiet: quiet,);}+/// The notification one task's questions share (task #3607; backend+/// `push/notices.ts` taskSlot): a decision asked of the person, and the+/// task's "stuck" or "needs you". A later one replaces the earlier quietly.+String swarmTaskSlot(String swarmId, String conversationId) =>+ 'task:$swarmId:$conversationId';+/// The notification a thread's replies share, the server's push for them too/// (task #3248; backend `push/notices.ts` threadSlot): a newer reply replaces/// the one shown.@@ -90,8 +105,12 @@ class SwarmAnnouncer {/// What this phone has told the account already: never told again.final SwarmTold told;- /// The notices posted and not yet taken down: each key's Swarm.- final _posted = <String, String>{};+ /// The needs whose notice is posted and not yet taken down, by need key:+ /// each one's Swarm and the notification it shows in. Several needs of one+ /// task show in one ([swarmTaskSlot]), which stays until the last is gone.+ /// [viaPush]: the server's push shows it, and nothing was posted here; the+ /// need is followed so that answering it takes the push down.+ final _posted = <String, ({String swarmId, String slot, bool viaPush})>{};/// Posted notices whose need the last reads of its Swarm missed: how many/// in a row.@@ -105,11 +124,37 @@ class SwarmAnnouncer {/// again) is not news (Dee's iPhone, 2026-11-01: one notice every 5/// seconds).void announce(SwarmNeed need) {+ // An agent's tag that asks for no decision is badge and Activity only: the+ // need still counts on the icon ([settle]), but nothing is posted.+ if (need is SwarmMentionNeed && need.mention.taggedByAgent) return;if (quiet(need)) return;- if (!told.add(need.key)) return;- final notice = swarmNotice(need);- _posted[notice.key] = need.swarmId;- _missed.remove(notice.key);+ final fresh = told.add(need.key);+ final slot = swarmNotice(need).key;+ // The server's push shows this notification already: nothing is posted,+ // but the need is followed, so that answering it takes the push down and+ // frees the slot for the task's next question (review of task #3607). The+ // push may be the one that told this need ([fresh] false).+ if (told.pushed(slot)) {+ _posted.putIfAbsent(+ need.key,+ () => (swarmId: need.swarmId, slot: slot, viaPush: true),+ );+ _missed.remove(need.key);+ return;+ }+ if (!fresh) return;+ // Another need of the task is up here: this one replaces it without a+ // sound. A followed push-only need is not: the person may have swiped it.+ final up = _posted.values.any(+ (posted) => posted.slot == slot && !posted.viaPush,+ );+ final notice = swarmNotice(need, quiet: up);+ _posted[need.key] = (+ swarmId: need.swarmId,+ slot: notice.key,+ viaPush: false,+ );+ _missed.remove(need.key);unawaited(notices.showSwarm(notice));}@@ -119,10 +164,10 @@ class SwarmAnnouncer {/// once. [readable] null: the list is not read yet, and nothing goes.void settle(List<SwarmNeed> needs, {Set<String>? readable}) {final open = {for (final need in needs) need.key};- for (final MapEntry(key: key, value: swarm) in _posted.entries.toList()) {+ for (final MapEntry(key: key, value: posted) in _posted.entries.toList()) {if (open.contains(key)) {_missed.remove(key);- } else if (readable != null && !readable.contains(swarm)) {+ } else if (readable != null && !readable.contains(posted.swarmId)) {_takeDown(key);}}@@ -144,8 +189,8 @@ class SwarmAnnouncer {/// its whose need this read missed, as the one before did, is taken down.void swarmRead(String swarmId, List<SwarmNeed> needs) {final open = {for (final need in needs) need.key};- for (final MapEntry(key: key, value: swarm) in _posted.entries.toList()) {- if (swarm != swarmId) continue;+ for (final MapEntry(key: key, value: posted) in _posted.entries.toList()) {+ if (posted.swarmId != swarmId) continue;if (open.contains(key)) {_missed.remove(key);continue;@@ -229,6 +274,8 @@ class SwarmAnnouncer {required SwarmActivityEntry entry,required String project,}) {+ // Only a person's reply rings; an agent's is badge and Activity (task #3607).+ if (entry.actorKind != 'person') return;if (quiet(null)) return;final key = 'reply:$swarmId:${entry.id}';if (!told.add(key)) return;@@ -290,9 +337,14 @@ class SwarmAnnouncer {}void _takeDown(String key) {- _posted.remove(key);+ final gone = _posted.remove(key);_missed.remove(key);- unawaited(notices.cancelSwarm(key));+ if (gone == null) return;+ // The notification goes with the last need that showed in it, and a push+ // in it with it: the slot is free for the task's next question.+ if (_posted.values.any((posted) => posted.slot == gone.slot)) return;+ told.pushGone(gone.slot);+ unawaited(notices.cancelSwarm(gone.slot));}/// Takes every notice and the icon's count down: the account that saw themdiff --git a/mobile/test/notify/agent_announcer_test.dart b/mobile/test/notify/agent_announcer_test.dartindex 3618e9a0f..4f5754703 100644--- a/mobile/test/notify/agent_announcer_test.dart+++ b/mobile/test/notify/agent_announcer_test.dart@@ -28,7 +28,11 @@ class _RecordingNotices implements SystemNotices {Future<void> cancel(AgentRef agent) async => cancelled.add(agent);@override- Future<void> showAccountNotice({required String key, required String title, required String body}) async {}+ Future<void> showAccountNotice({+ required String key,+ required String title,+ required String body,+ }) async {}}void main() {@@ -62,40 +66,33 @@ void main() {addTearDown(announcer.dispose);});- test('watching: a chime, no mark, no notice', () {+ // Task #3607 (Tony, 2026-11-06): a finished turn is badge only. Done notices+ // are pinned in finished_turn_badge_only_test.dart; a question still rings.+ test('watching: nothing at all, no chime, no mark, no notice', () {final notice = announcer.turnEnded(agent, news, watching: () => true);- expect(notice, AgentNotice.chime);- expect(chimes, 1);+ expect(notice, AgentNotice.none);+ expect(chimes, 0);expect(announcer.unread.count, 0);expect(system.shown, isEmpty);});- test('elsewhere in the app: a chime, a mark and the notice, the banner over the app', () {+ test('elsewhere in the app: a mark, no chime and no notice', () {announcer.turnEnded(agent, news, watching: () => false);- expect(chimes, 1);+ expect(chimes, 0);expect(announcer.unread.contains(ref), isTrue);- expect(system.shown, hasLength(1));- expect(system.shown.single.agent, ref);+ expect(system.shown, isEmpty);});- test(- 'away: a mark and one notice naming the agent, its machine, its news',- () {- front = false;- announcer.turnEnded(agent, news, watching: () => true);+ test('away: a mark and no notice', () {+ front = false;+ announcer.turnEnded(agent, news, watching: () => true);- expect(chimes, 0, reason: 'nobody is holding a backgrounded app');- expect(announcer.unread.contains(ref), isTrue);- expect(system.shown, hasLength(1));- final shown = system.shown.single;- expect(shown.agent, ref);- expect(shown.title, 'Fix login');- expect(shown.machine, 'MacBook');- expect(shown.body, 'Fixed the login screen and pushed.');- },- );+ expect(chimes, 0);+ expect(announcer.unread.contains(ref), isTrue);+ expect(system.shown, isEmpty);+ });test('a sub-agent turn does nothing at all, even away', () {front = false;@@ -136,24 +133,35 @@ void main() {});test('list, elsewhere in the app: a mark with no tap', () {- announcer.turnEnded(agent, tiered(NoticeTier.list), watching: () => false);+ announcer.turnEnded(+ agent,+ tiered(NoticeTier.list),+ watching: () => false,+ );expect(chimes, 0);expect(announcer.unread.contains(ref), isTrue);expect(system.shown, isEmpty);});- test('alert, away: a mark and the notice', () {+ test('alert, away: a mark, never a notice', () {front = false;- announcer.turnEnded(agent, tiered(NoticeTier.alert), watching: () => false);+ announcer.turnEnded(+ agent,+ tiered(NoticeTier.alert),+ watching: () => false,+ );expect(announcer.unread.contains(ref), isTrue);- expect(system.shown, hasLength(1));- expect(system.shown.single.body, 'Fixed the login screen and pushed.');+ expect(system.shown, isEmpty);});test('alert, on the agent being watched: nothing at all', () {- announcer.turnEnded(agent, tiered(NoticeTier.alert), watching: () => true);+ announcer.turnEnded(+ agent,+ tiered(NoticeTier.alert),+ watching: () => true,+ );expect(chimes, 0);expect(announcer.unread.count, 0);@@ -162,7 +170,11 @@ void main() {test('silent, away: nothing at all', () {front = false;- announcer.turnEnded(agent, tiered(NoticeTier.silent), watching: () => false);+ announcer.turnEnded(+ agent,+ tiered(NoticeTier.silent),+ watching: () => false,+ );expect(chimes, 0);expect(announcer.unread.count, 0);@@ -176,7 +188,11 @@ void main() {prompt: 'Which branch?',watching: () => false,);- announcer.turnEnded(agent, tiered(NoticeTier.list), watching: () => false);+ announcer.turnEnded(+ agent,+ tiered(NoticeTier.list),+ watching: () => false,+ );expect(announcer.unread.kindFor(ref), NoticeKind.done);});@@ -214,24 +230,30 @@ void main() {});});- test('an older daemon\'s recap, with no tier, goes by the old rule at once', () {+ test('an older daemon\'s recap, with no tier, is a mark at once', () {inFakeTime((time, a) {front = false;a.turnEndedAwaitingTier(agent, news, watching: () => false);- expect(a.tierDecided(ref, null), AgentNotice.alert);- expect(system.shown, hasLength(1));+ expect(a.tierDecided(ref, null), AgentNotice.filed);+ expect(a.unread.contains(ref), isTrue);+ expect(system.shown, isEmpty);});});- test('a tier that never comes: the old rule once the wait runs out', () {+ test('a tier that never comes: a mark once the wait runs out', () {inFakeTime((time, a) {front = false;a.turnEndedAwaitingTier(agent, news, watching: () => false);time.elapse(wait - const Duration(milliseconds: 1));- expect(system.shown, isEmpty);+ expect(a.unread.count, 0);time.elapse(const Duration(milliseconds: 1));- expect(system.shown, hasLength(1));- expect(a.tierDecided(ref, NoticeTier.alert), isNull, reason: 'nothing waits any more');+ expect(a.unread.contains(ref), isTrue);+ expect(system.shown, isEmpty);+ expect(+ a.tierDecided(ref, NoticeTier.alert),+ isNull,+ reason: 'nothing waits any more',+ );});});@@ -263,21 +285,24 @@ void main() {});});- test('a question asked while it waits is what stands: no "done" over it', () {- inFakeTime((time, a) {- front = false;- a.turnEndedAwaitingTier(agent, news, watching: () => false);- a.questionAsked(- agent,- requestId: 'q1',- prompt: 'Which branch?',- watching: () => false,- );- expect(a.tierDecided(ref, NoticeTier.alert), AgentNotice.none);- expect(a.unread.kindFor(ref), NoticeKind.question);- expect(system.shown.map((m) => m.kind), [NoticeKind.question]);- });- });+ test(+ 'a question asked while it waits is what stands: no "done" over it',+ () {+ inFakeTime((time, a) {+ front = false;+ a.turnEndedAwaitingTier(agent, news, watching: () => false);+ a.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'Which branch?',+ watching: () => false,+ );+ expect(a.tierDecided(ref, NoticeTier.alert), AgentNotice.none);+ expect(a.unread.kindFor(ref), NoticeKind.question);+ expect(system.shown.map((m) => m.kind), [NoticeKind.question]);+ });+ },+ );test('the turn\'s end takes down the question it asked in, at once', () {inFakeTime((time, a) {@@ -303,7 +328,7 @@ void main() {});});- test('a newer end replaces the one waiting, and is told once', () {+ test('a newer end replaces the one waiting, and is marked once', () {inFakeTime((time, a) {front = false;a.turnEndedAwaitingTier(agent, news, watching: () => false);@@ -316,9 +341,10 @@ void main() {tier: null,), watching: () => false);time.elapse(wait ~/ 2);- expect(system.shown, isEmpty, reason: 'the first one\'s wait was dropped');+ expect(a.unread.count, 0, reason: 'the first one\'s wait was dropped');time.elapse(wait);- expect(system.shown.map((m) => m.body), ['Second answer.']);+ expect(a.unread.count, 1);+ expect(system.shown, isEmpty);});});@@ -336,18 +362,18 @@ void main() {});});- test('a finished turn sounds once until the person goes to the agent; '- 'the next only replaces it quietly (task #3248)', () {+ test('a finished turn never posts a notice, however many agents finish', () {front = false;- const other = (ref: (machineId: 'm', agentId: 'b'), name: 'Docs', machine: 'MacBook');+ const other = (+ ref: (machineId: 'm', agentId: 'b'),+ name: 'Docs',+ machine: 'MacBook',+ );announcer.turnEnded(agent, news, watching: () => false);announcer.turnEnded(agent, news, watching: () => false);announcer.turnEnded(other, news, watching: () => false);- expect([for (final n in system.shown) (n.agent.agentId, n.quiet)], [('a', false), ('a', true), ('b', false)]);-- announcer.seen(ref);- announcer.turnEnded(agent, news, watching: () => false);- expect(system.shown.last.quiet, isFalse, reason: 'seen: the next is news again');+ expect(system.shown, isEmpty);+ expect(announcer.unread.count, 2, reason: 'one mark for each agent');});test('an agent is one mark however many turns it finished', () {@@ -362,7 +388,13 @@ void main() {group('going to the agent', () {test('takes down its mark and the notice still in the OS centre', () {front = false;- announcer.turnEnded(agent, news, watching: () => false);+ announcer.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'Which branch?',+ watching: () => false,+ );+ expect(system.shown, hasLength(1));front = true;announcer.seen(ref);expect(announcer.unread.contains(ref), isFalse);@@ -370,14 +402,8 @@ void main() {});test('never asks the OS to cancel a notice it did not post', () {- // A `list` turn: marked, and no notice posted.- announcer.turnEnded(agent, (- aborted: false,- replay: false,- subagent: false,- reply: news.reply,- tier: NoticeTier.list,- ), watching: () => false);+ // A finished turn: marked, and no notice posted.+ announcer.turnEnded(agent, news, watching: () => false);expect(system.shown, isEmpty);announcer.seen(ref);expect(announcer.unread.contains(ref), isFalse);@@ -386,7 +412,12 @@ void main() {test('a notice is taken down once, not every time the agent is seen', () {front = false;- announcer.turnEnded(agent, news, watching: () => false);+ announcer.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'Which branch?',+ watching: () => false,+ );announcer..seen(ref)..seen(ref);@@ -395,7 +426,12 @@ void main() {test('signing out takes every posted notice down', () {front = false;- announcer.turnEnded(agent, news, watching: () => false);+ announcer.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'Which branch?',+ watching: () => false,+ );announcer.reset();expect(system.cancelled, [ref]);expect(announcer.unread.count, 0);@@ -432,7 +468,11 @@ void main() {expect(announcer.unread.contains(ref), isFalse);expect(system.cancelled, [ref]);expect(announcer.unread.kindFor(other), NoticeKind.question);- expect(announcer.unread.kindFor(elsewhere), NoticeKind.question, reason: 'another machine said nothing of it');+ expect(+ announcer.unread.kindFor(elsewhere),+ NoticeKind.question,+ reason: 'another machine said nothing of it',+ );// Heard again later it is open again, and posted again — but the person// was told of this very request already: no second buzz.expect(ask(), AgentNotice.quiet);@@ -462,7 +502,11 @@ void main() {test('the dialog moving to its next page is a new question, posted without a second buzz', () {ask();- expect(ask(id: 'q2'), AgentNotice.quiet, reason: 'the agent buzzed a moment ago');+ expect(+ ask(id: 'q2'),+ AgentNotice.quiet,+ reason: 'the agent buzzed a moment ago',+ );expect(chimes, 1);expect(announcer.unread.kindFor(ref), NoticeKind.question);expect(system.shown.map((m) => m.quiet), [false, true]);@@ -575,20 +619,23 @@ void main() {List<bool> quietness() => [for (final m in system.shown) m.quiet];- test('marked at once; it buzzes only once its grace runs out, still open', () {- inFakeTime((time, a) {- expect(ask(a), AgentNotice.filed);- expect(a.unread.kindFor(ref), NoticeKind.question);- expect(system.shown, isEmpty);- expect(chimes, 0);- time.elapse(grace - const Duration(milliseconds: 1));- expect(system.shown, isEmpty);- time.elapse(const Duration(milliseconds: 1));- expect(quietness(), [false]);- expect(system.shown.single.body, 'Approve Bash command: npm test');- expect(chimes, 1);- });- });+ test(+ 'marked at once; it buzzes only once its grace runs out, still open',+ () {+ inFakeTime((time, a) {+ expect(ask(a), AgentNotice.filed);+ expect(a.unread.kindFor(ref), NoticeKind.question);+ expect(system.shown, isEmpty);+ expect(chimes, 0);+ time.elapse(grace - const Duration(milliseconds: 1));+ expect(system.shown, isEmpty);+ time.elapse(const Duration(milliseconds: 1));+ expect(quietness(), [false]);+ expect(system.shown.single.body, 'Approve Bash command: npm test');+ expect(chimes, 1);+ });+ },+ );test('answered within its grace — at the desk, by an auto mode — it never buzzes', () {inFakeTime((time, a) {@@ -602,32 +649,42 @@ void main() {});});- test('a run of approvals answered at the desk in seconds: nothing at all', () {- inFakeTime((time, a) {- for (var i = 0; i < 10; i++) {- ask(a, id: 'q$i');- time.elapse(const Duration(seconds: 2));- a.questionClosed(ref, requestId: 'q$i');- }- time.elapse(grace * 2);- expect(system.shown, isEmpty);- expect(chimes, 0);- });- });+ test(+ 'a run of approvals answered at the desk in seconds: nothing at all',+ () {+ inFakeTime((time, a) {+ for (var i = 0; i < 10; i++) {+ ask(a, id: 'q$i');+ time.elapse(const Duration(seconds: 2));+ a.questionClosed(ref, requestId: 'q$i');+ }+ time.elapse(grace * 2);+ expect(system.shown, isEmpty);+ expect(chimes, 0);+ });+ },+ );- test('a newer question replaces the one waiting, and is the one told, once', () {- inFakeTime((time, a) {- ask(a);- time.elapse(const Duration(seconds: 5));- expect(ask(a, id: 'q2'), AgentNotice.filed);- time.elapse(const Duration(seconds: 10));- expect(system.shown, isEmpty, reason: 'the first one\'s wait was dropped');- time.elapse(const Duration(seconds: 5));- expect(quietness(), [false]);- time.elapse(grace * 2);- expect(system.shown, hasLength(1));- });- });+ test(+ 'a newer question replaces the one waiting, and is the one told, once',+ () {+ inFakeTime((time, a) {+ ask(a);+ time.elapse(const Duration(seconds: 5));+ expect(ask(a, id: 'q2'), AgentNotice.filed);+ time.elapse(const Duration(seconds: 10));+ expect(+ system.shown,+ isEmpty,+ reason: 'the first one\'s wait was dropped',+ );+ time.elapse(const Duration(seconds: 5));+ expect(quietness(), [false]);+ time.elapse(grace * 2);+ expect(system.shown, hasLength(1));+ });+ },+ );test('a dialog flickering off the pane buzzes once, then is only posted again quietly', () {inFakeTime((time, a) {@@ -639,7 +696,11 @@ void main() {expect(a.unread.contains(ref), isFalse);time.elapse(const Duration(milliseconds: 1500));expect(ask(a), AgentNotice.quiet);- expect(a.unread.kindFor(ref), NoticeKind.question, reason: 'it is open again');+ expect(+ a.unread.kindFor(ref),+ NoticeKind.question,+ reason: 'it is open again',+ );time.elapse(const Duration(seconds: 5));}expect(chimes, 1);@@ -667,16 +728,19 @@ void main() {});});- test('one back after its grace ran out while off the pane is told at once', () {- inFakeTime((time, a) {- ask(a);- time.elapse(const Duration(seconds: 3));- a.questionClosed(ref, requestId: 'q1');- time.elapse(grace);- expect(ask(a), AgentNotice.alert);- expect(quietness(), [false]);- });- });+ test(+ 'one back after its grace ran out while off the pane is told at once',+ () {+ inFakeTime((time, a) {+ ask(a);+ time.elapse(const Duration(seconds: 3));+ a.questionClosed(ref, requestId: 'q1');+ time.elapse(grace);+ expect(ask(a), AgentNotice.alert);+ expect(quietness(), [false]);+ });+ },+ );test('another question of the agent within the cooldown is posted quietly; after it, it buzzes again', () {inFakeTime((time, a) {@@ -722,18 +786,21 @@ void main() {});});- test('the same dialog asked again after the reopen window is news again', () {- inFakeTime((time, a) {- ask(a);- time.elapse(grace);- a.questionClosed(ref, requestId: 'q1');- time.elapse(reopen + const Duration(seconds: 1));- expect(ask(a), AgentNotice.filed);- time.elapse(grace);- expect(quietness(), [false, false]);- expect(chimes, 2);- });- });+ test(+ 'the same dialog asked again after the reopen window is news again',+ () {+ inFakeTime((time, a) {+ ask(a);+ time.elapse(grace);+ a.questionClosed(ref, requestId: 'q1');+ time.elapse(reopen + const Duration(seconds: 1));+ expect(ask(a), AgentNotice.filed);+ time.elapse(grace);+ expect(quietness(), [false, false]);+ expect(chimes, 2);+ });+ },+ );test('a question open longer than the window is still the same one when it flickers', () {inFakeTime((time, a) {@@ -816,16 +883,19 @@ void main() {});});- test('a deleted agent forgets what it was told: its next question buzzes', () {- inFakeTime((time, a) {- ask(a);- time.elapse(grace);- a.forgetAgent(ref);- expect(ask(a), AgentNotice.filed);- time.elapse(grace);- expect(quietness(), [false, false]);- });- });+ test(+ 'a deleted agent forgets what it was told: its next question buzzes',+ () {+ inFakeTime((time, a) {+ ask(a);+ time.elapse(grace);+ a.forgetAgent(ref);+ expect(ask(a), AgentNotice.filed);+ time.elapse(grace);+ expect(quietness(), [false, false]);+ });+ },+ );test('signing out drops a question still waiting, and what was told', () {inFakeTime((time, a) {@@ -844,7 +914,12 @@ void main() {inFront: () => true,now: () => start.add(time.elapsed),);- a.questionAsked(agent, requestId: 'q1', prompt: 'x', watching: () => false);+ a.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'x',+ watching: () => false,+ );expect(time.pendingTimers, hasLength(1));a.dispose();expect(time.pendingTimers, isEmpty);@@ -854,7 +929,11 @@ void main() {group('a Harness Team account\'s agents (2026-11-05: Dee\'s phone buzzed for a teammate\'s tester)', () {const teamRef = (machineId: 'team-mac', agentId: 't');- const teamAgent = (ref: teamRef, name: 'Tester 3256', machine: 'Macs-Mac-Studio-2.local · Team');+ const teamAgent = (+ ref: teamRef,+ name: 'Tester 3256',+ machine: 'Macs-Mac-Studio-2.local · Team',+ );late AgentAnnouncer withTeam;@@ -905,21 +984,24 @@ void main() {expect(system.shown, isEmpty);});- test('the owner\'s own agent still tells, beside it', () {+ test('the owner\'s own agent is still marked, beside it', () {front = false;withTeam.turnEnded(teamAgent, news, watching: () => false);final notice = withTeam.turnEnded(agent, news, watching: () => false);- expect(notice, AgentNotice.alert);- expect(system.shown.map((m) => m.agent), [ref]);+ expect(notice, AgentNotice.filed);expect(withTeam.unread.contains(ref), isTrue);expect(withTeam.unread.contains(teamRef), isFalse);});- test('with no rule given every agent tells, as before', () {+ test('with no rule given every agent is marked, as before', () {front = false;- final notice = announcer.turnEnded(teamAgent, news, watching: () => false);- expect(notice, AgentNotice.alert);+ final notice = announcer.turnEnded(+ teamAgent,+ news,+ watching: () => false,+ );+ expect(notice, AgentNotice.filed);});});diff --git a/mobile/test/notify/announcer_lifecycle_test.dart b/mobile/test/notify/announcer_lifecycle_test.dartindex f871017ea..1e02c545c 100644--- a/mobile/test/notify/announcer_lifecycle_test.dart+++ b/mobile/test/notify/announcer_lifecycle_test.dart@@ -29,103 +29,104 @@ void main() {expect(announcer.inFront, isTrue);});- testWidgets('in front while resumed; an agent not on screen gets the notice, in front or pocketed', (- tester,- ) async {- final system = _Recording();- final announcer = AgentAnnouncer(system: system);- addTearDown(announcer.dispose);+ testWidgets(+ 'in front while resumed; a finished turn is a mark, in front or pocketed (task #3607)',+ (tester) async {+ final system = _Recording();+ final announcer = AgentAnnouncer(system: system);+ addTearDown(announcer.dispose);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- expect(announcer.inFront, isTrue);- // In front, elsewhere: the haptic tap, a mark and the OS's banner over the- // app — the default chime must never throw, even where no platform answers it.- expect(- announcer.turnEnded(agent, news, watching: () => false),- AgentNotice.alert,- );- expect(system.shown, hasLength(1));+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);+ expect(announcer.inFront, isTrue);+ // In front, elsewhere: a mark and nothing louder — no chime, no banner. The+ // default chime must never throw, even where no platform answers it.+ expect(+ announcer.turnEnded(agent, news, watching: () => false),+ AgentNotice.filed,+ );+ expect(system.shown, isEmpty);- for (final state in [- AppLifecycleState.inactive,- AppLifecycleState.hidden,- AppLifecycleState.paused,- ]) {- tester.binding.handleAppLifecycleStateChanged(state);- }- expect(announcer.inFront, isFalse);- // Pocketed, even on the agent last on screen: the notice is posted. The- // first one is still up, unseen, so this one replaces it quietly (task #3248).- expect(- announcer.turnEnded(agent, news, watching: () => true),- AgentNotice.quiet,- );- expect(system.shown, hasLength(2));- expect(system.shown.last.quiet, isTrue);- expect(system.shown.last.body, 'Fixed the login screen.');+ for (final state in [+ AppLifecycleState.inactive,+ AppLifecycleState.hidden,+ AppLifecycleState.paused,+ ]) {+ tester.binding.handleAppLifecycleStateChanged(state);+ }+ expect(announcer.inFront, isFalse);+ // Pocketed, even on the agent last on screen: still only a mark.+ expect(+ announcer.turnEnded(agent, news, watching: () => true),+ AgentNotice.filed,+ );+ expect(system.shown, isEmpty);+ expect(announcer.unread.contains(agent.ref), isTrue);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- });+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);+ },+ );- testWidgets('a question waiting out its grace is told the moment the app is hidden', (- tester,- ) async {- final system = _Recording();- final announcer = AgentAnnouncer(system: system);- addTearDown(announcer.dispose);+ testWidgets(+ 'a question waiting out its grace is told the moment the app is hidden',+ (tester) async {+ final system = _Recording();+ final announcer = AgentAnnouncer(system: system);+ addTearDown(announcer.dispose);++ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);+ expect(+ announcer.questionAsked(+ agent,+ requestId: 'q1',+ prompt: 'Approve Bash command: npm test',+ watching: () => false,+ ),+ AgentNotice.filed,+ );+ expect(system.shown, isEmpty, reason: 'in front, it waits out its grace');- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- expect(+ // Locking the phone: iOS suspends the app within seconds, and the wait's+ // timer with it — so it goes now, and loud.+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);+ expect(system.shown, isEmpty, reason: 'inactive is not away');+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);+ expect(system.shown, hasLength(1));+ expect(system.shown.single.quiet, isFalse);+ expect(system.shown.single.body, 'Approve Bash command: npm test');++ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);+ expect(system.shown, hasLength(1), reason: 'told once');+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);+ },+ );++ testWidgets(+ 'going away after the announcer is disposed tells nothing, and throws nothing',+ (tester) async {+ final system = _Recording();+ final announcer = AgentAnnouncer(system: system);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);announcer.questionAsked(agent,requestId: 'q1',prompt: 'Approve Bash command: npm test',watching: () => false,- ),- AgentNotice.filed,- );- expect(system.shown, isEmpty, reason: 'in front, it waits out its grace');-- // Locking the phone: iOS suspends the app within seconds, and the wait's- // timer with it — so it goes now, and loud.- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);- expect(system.shown, isEmpty, reason: 'inactive is not away');- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);- expect(system.shown, hasLength(1));- expect(system.shown.single.quiet, isFalse);- expect(system.shown.single.body, 'Approve Bash command: npm test');-- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);- expect(system.shown, hasLength(1), reason: 'told once');- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- });-- testWidgets('going away after the announcer is disposed tells nothing, and throws nothing', (- tester,- ) async {- final system = _Recording();- final announcer = AgentAnnouncer(system: system);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- announcer.questionAsked(- agent,- requestId: 'q1',- prompt: 'Approve Bash command: npm test',- watching: () => false,- );- announcer.dispose();- // Its wait went with it, and so did its ear: going away tells of nothing.- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);- expect(system.shown, isEmpty);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);- tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);- });+ );+ announcer.dispose();+ // Its wait went with it, and so did its ear: going away tells of nothing.+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);+ expect(system.shown, isEmpty);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);+ tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);+ },+ );}class _Recording extends SilentSystemNotices {diff --git a/mobile/test/notify/done_notice_test.dart b/mobile/test/notify/done_notice_test.dartindex 4b3a12cba..4e075ca73 100644--- a/mobile/test/notify/done_notice_test.dart+++ b/mobile/test/notify/done_notice_test.dart@@ -37,26 +37,29 @@ void main() {}});- test('watching the agent: the chime still comes, nothing is filed', () {+ // Task #3607 (Tony, 2026-11-06): a finished turn is badge only.+ test('watching the agent: nothing at all, not even a chime', () {final notice = decide(end(), watching: true);- expect(notice, AgentNotice.chime);+ expect(notice, AgentNotice.none);+ expect(notice.chimes, isFalse);expect(notice.marks, isFalse);expect(notice.alerts, isFalse);});- test('in front on another agent: marked and noticed, the banner over the app', () {+ test('in front on another agent: a mark, no chime and no notice', () {final notice = decide(end());- expect(notice, AgentNotice.alert);- expect(notice.chimes, isTrue);+ expect(notice, AgentNotice.filed);+ expect(notice.chimes, isFalse);expect(notice.marks, isTrue);- expect(notice.alerts, isTrue);+ expect(notice.alerts, isFalse);});- test('away: marked and noticed, whatever was on screen', () {+ test('away: a mark and nothing louder, whatever was on screen', () {for (final watching in [true, false]) {final notice = decide(end(), inFront: false, watching: watching);- expect(notice, AgentNotice.alert);+ expect(notice, AgentNotice.filed);expect(notice.marks, isTrue);+ expect(notice.alerts, isFalse);}});@@ -135,11 +138,7 @@ void main() {end(reply: ' ', tier: tier),]) {for (final inFront in [true, false]) {- expect(- decide(e, inFront: inFront),- AgentNotice.none,- reason: '$e',- );+ expect(decide(e, inFront: inFront), AgentNotice.none, reason: '$e');}}}@@ -172,11 +171,11 @@ void main() {}});- test('alert: as far as the phone\'s place allows', () {- expect(decide(end(tier: NoticeTier.alert)), AgentNotice.alert);+ test('alert: a mark like any other news, never a notice or a chime', () {+ expect(decide(end(tier: NoticeTier.alert)), AgentNotice.filed);expect(decide(end(tier: NoticeTier.alert), inFront: false),- AgentNotice.alert,+ AgentNotice.filed,);});@@ -193,7 +192,7 @@ void main() {test('watching only counts in front', () {expect(decide(end(tier: NoticeTier.alert), inFront: false, watching: true),- AgentNotice.alert,+ AgentNotice.filed,);expect(decide(end(tier: NoticeTier.list), inFront: false, watching: true),diff --git a/mobile/test/notify/finished_turn_badge_only_test.dart b/mobile/test/notify/finished_turn_badge_only_test.dartnew file mode 100644index 000000000..aeded1c11--- /dev/null+++ b/mobile/test/notify/finished_turn_badge_only_test.dart@@ -0,0 +1,151 @@+import 'package:flutter/foundation.dart';+import 'package:flutter_test/flutter_test.dart';++import 'package:harness_mobile/core/last_opened_agent.dart';+import 'package:harness_mobile/notify/agent_announcer.dart';+import 'package:harness_mobile/notify/agent_notice.dart';+import 'package:harness_mobile/notify/done_notice.dart';+import 'package:harness_mobile/notify/system_notices.dart';++/// Task #3607 (Tony, 2026-11-06): an agent finishing a turn is badge only. The+/// agent is marked unread; nothing rings, nothing is posted to the+/// notification centre. A question, or an approval, still rings.+class _RecordingNotices implements SystemNotices {+ final shown = <AgentNoticeMessage>[];++ @override+ final opened = ValueNotifier<AgentRef?>(null);++ @override+ final openedDevice = ValueNotifier<String?>(null);++ @override+ Future<bool?> requestPermission() async => null;++ @override+ Future<void> show(AgentNoticeMessage message) async => shown.add(message);++ @override+ Future<void> cancel(AgentRef agent) async {}++ @override+ Future<void> showAccountNotice({+ required String key,+ required String title,+ required String body,+ }) async {}+}++void main() {+ const ref = (machineId: 'm', agentId: 'a');+ const agent = (ref: ref, name: 'Fix login', machine: 'MacBook');++ TurnEnd end({NoticeTier? tier, String? reply = 'Fixed the login screen.'}) =>+ (+ aborted: false,+ replay: false,+ subagent: false,+ reply: reply,+ tier: tier,+ );++ group('what a finished turn is worth', () {+ test('a mark and nothing louder, at every tier the daemon gives', () {+ for (final tier in [null, NoticeTier.alert, NoticeTier.list]) {+ for (final inFront in [true, false]) {+ final notice = decideDoneNotice(+ end(tier: tier),+ inFront: inFront,+ watching: false,+ );+ expect(notice, AgentNotice.filed, reason: '$tier front=$inFront');+ expect(notice.marks, isTrue);+ expect(notice.chimes, isFalse);+ expect(notice.alerts, isFalse);+ }+ }+ });++ test('nothing at all for the agent the person is looking at', () {+ for (final tier in [null, NoticeTier.alert, NoticeTier.list]) {+ expect(+ decideDoneNotice(end(tier: tier), inFront: true, watching: true),+ AgentNotice.none,+ );+ }+ });++ test('silent, and a turn that is not news, stay nothing', () {+ expect(+ decideDoneNotice(+ end(tier: NoticeTier.silent),+ inFront: false,+ watching: false,+ ),+ AgentNotice.none,+ );+ expect(+ decideDoneNotice(end(reply: null), inFront: false, watching: false),+ AgentNotice.none,+ );+ });+ });++ group('the announcer', () {+ late _RecordingNotices system;+ late int chimes;+ late bool front;+ late AgentAnnouncer announcer;++ setUp(() {+ system = _RecordingNotices();+ chimes = 0;+ front = false;+ announcer = AgentAnnouncer(+ system: system,+ chime: () async => chimes++,+ inFront: () => front,+ questionGrace: Duration.zero,+ );+ addTearDown(announcer.dispose);+ });++ test('a finished turn away marks the agent and rings nothing', () {+ announcer.turnEnded(agent, end(), watching: () => false);++ expect(announcer.unread.contains(ref), isTrue);+ expect(system.shown, isEmpty);+ expect(chimes, 0);+ });++ test('a finished turn with the app on another agent: a mark, no chime', () {+ front = true;+ announcer.turnEnded(agent, end(), watching: () => false);++ expect(announcer.unread.contains(ref), isTrue);+ expect(system.shown, isEmpty);+ expect(chimes, 0);+ });++ test('a finished turn of the agent on screen: nothing at all', () {+ front = true;+ announcer.turnEnded(agent, end(), watching: () => true);++ expect(announcer.unread.count, 0);+ expect(system.shown, isEmpty);+ expect(chimes, 0);+ });++ test('a question after a finished turn still posts', () {+ announcer.turnEnded(agent, end(), watching: () => false);+ announcer.questionAsked(+ agent,+ requestId: 'r1',+ prompt: 'Approve Bash command: rm -rf dist',+ watching: () => false,+ );++ expect([for (final n in system.shown) n.kind], [NoticeKind.question]);+ });+ });+}diff --git a/mobile/test/swarm/swarm_chat_notices_test.dart b/mobile/test/swarm/swarm_chat_notices_test.dartindex 18ef48248..6596d146d 100644--- a/mobile/test/swarm/swarm_chat_notices_test.dart+++ b/mobile/test/swarm/swarm_chat_notices_test.dart@@ -92,6 +92,22 @@ void main() {expect(told(), ['mention:t1']);});+ test(+ 'a chat nobody set tells no new message: Mentions only is the default, '+ 'All new messages only when the person turns it on (task #3607)',+ () async {+ backend.settings = {};+ final session = await start();++ backend+ ..move('g1', 4)+ ..move('g2', 4);+ await poll(session);++ expect(told(), isEmpty);+ },+ );+test('chosen on this phone, it tells at once: before any read carries the ''setting', () async {final session = await start();diff --git a/mobile/test/swarm/swarm_notice_repeat_test.dart b/mobile/test/swarm/swarm_notice_repeat_test.dartindex 47893c689..5f485e9f8 100644--- a/mobile/test/swarm/swarm_notice_repeat_test.dart+++ b/mobile/test/swarm/swarm_notice_repeat_test.dart@@ -72,12 +72,9 @@ void main() {..needsYou('g2');}- const all = [- 'decision:d1',- 'mention:t1',- 'work:a:g1:attempt-g1:blocked',- 'work:a:g2:attempt-g2:needs_human',- ];+ // A decision and a task's stuck or needs-you show in the task's one+ // notification (task #3607): the decision is in g9, the others in g1 and g2.+ const all = ['mention:t1', 'task:a:g1', 'task:a:g2', 'task:a:g9'];test('read again and again, each ask is told once', () async {final h = host();@@ -222,7 +219,7 @@ void main() {..decisions = kept..version += 1;await poll(h);- expect(told().where((k) => k == 'decision:d1'), hasLength(2));+ expect(told().where((k) => k == 'task:a:g9'), hasLength(2));});test('a relaunch tells nothing again of what waits', () async {@@ -253,7 +250,7 @@ void main() {..decision('d1')..version += 1;await poll(h);- expect(told(), ['decision:d1']);+ expect(told(), ['task:a:g9']);await features.set(PhoneExperiment.swarm, false);await features.set(PhoneExperiment.swarm, true);@@ -267,7 +264,7 @@ void main() {..decision('d1')..version += 1;await poll(h);- expect(told(), ['decision:d1', 'decision:d1']);+ expect(told(), ['task:a:g9', 'task:a:g9']);});test('the record keeps the newest keys, at most its limit', () {diff --git a/mobile/test/swarm/swarm_notices_test.dart b/mobile/test/swarm/swarm_notices_test.dartindex b4dbd1d19..2b3146769 100644--- a/mobile/test/swarm/swarm_notices_test.dart+++ b/mobile/test/swarm/swarm_notices_test.dart@@ -225,11 +225,11 @@ void main() {announcer.swarmRead('tab-b', [mention()]);expect(notices.cancelled, isEmpty, reason: 'one read may miss it');announcer.swarmRead('tab-b', [mention()]);- expect(notices.cancelled, [decision().key]);+ expect(notices.cancelled, [swarmNotice(decision()).key]);// Signed out: nothing of the account stays on the lock screen.announcer.clear();- expect(notices.cancelled, [decision().key, mention().key]);+ expect(notices.cancelled, [swarmNotice(decision()).key, mention().key]);});test('a need missed by one read and back at the next stays up', () {@@ -258,7 +258,7 @@ void main() {final announcer = SwarmAnnouncer(notices, quiet: (_) => false);announcer.announce(decision());announcer.settle(const [], readable: {'tab-other'});- expect(notices.cancelled, [decision().key]);+ expect(notices.cancelled, [swarmNotice(decision()).key]);});test('a need never shown is never taken down', () {@@ -272,18 +272,21 @@ void main() {});group('a reply in a thread the person is in', () {- SwarmActivityEntry reply(String id, {bool read = false, String threadId = 'root-1'}) =>- SwarmActivityEntry.fromJson({- 'id': id,- 'kind': 'reply',- 'conversationId': 'g9',- 'messageId': 'msg-$id',- 'threadId': threadId,- 'actor': {'kind': 'person', 'id': 'person-mia', 'name': 'Mia'},- 'text': "sounds good, I'll ship the copy today",- 'createdAt': DateTime.utc(2026, 11, 4, 9).toIso8601String(),- 'read': read,- });+ SwarmActivityEntry reply(+ String id, {+ bool read = false,+ String threadId = 'root-1',+ }) => SwarmActivityEntry.fromJson({+ 'id': id,+ 'kind': 'reply',+ 'conversationId': 'g9',+ 'messageId': 'msg-$id',+ 'threadId': threadId,+ 'actor': {'kind': 'person', 'id': 'person-mia', 'name': 'Mia'},+ 'text': "sounds good, I'll ship the copy today",+ 'createdAt': DateTime.utc(2026, 11, 4, 9).toIso8601String(),+ 'read': read,+ });test('says who replied and in which project, not the reply, and opens ''at it', () {@@ -345,60 +348,127 @@ void main() {'reply replaces it quietly until the thread is read (task #3248)', () {final notices = _Recording();final announcer = SwarmAnnouncer(notices, quiet: (_) => false);- announcer.announceReply(swarmId: 'tab-b', entry: reply('a1'), project: 'M');- announcer.announceReply(swarmId: 'tab-b', entry: reply('a2'), project: 'M');+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a1'),+ project: 'M',+ );+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a2'),+ project: 'M',+ );final slot = threadSlot('tab-b', 'g9', 'root-1');- expect(slot, 'thread:tab-b:g9:root-1', reason: 'the server\'s push slot (backend/src/push/notices.ts threadSlot)');- expect([for (final n in notices.shown) (n.key, n.quiet)], [(slot, false), (slot, true)]);- expect(notices.shown.last.target.messageId, 'msg-a2', reason: 'the tap opens the newest');+ expect(+ slot,+ 'thread:tab-b:g9:root-1',+ reason:+ 'the server\'s push slot (backend/src/push/notices.ts threadSlot)',+ );+ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false), (slot, true)],+ );+ expect(+ notices.shown.last.target.messageId,+ 'msg-a2',+ reason: 'the tap opens the newest',+ );// Read up to a1 only: the thread's notification stays for a2.announcer.repliesRead('tab-b', [reply('a1', read: true), reply('a2')]);expect(notices.cancelled, isEmpty);- announcer.repliesRead('tab-b', [reply('a1', read: true), reply('a2', read: true)]);+ announcer.repliesRead('tab-b', [+ reply('a1', read: true),+ reply('a2', read: true),+ ]);expect(notices.cancelled, [slot]);// Read, the next reply there sounds again; a reply in another thread is a notification of its own.- announcer.announceReply(swarmId: 'tab-b', entry: reply('a3'), project: 'M');- announcer.announceReply(swarmId: 'tab-b', entry: reply('b1', threadId: 'root-2'), project: 'M');- expect([for (final n in notices.shown.skip(2)) (n.key, n.quiet)],- [(slot, false), (threadSlot('tab-b', 'g9', 'root-2'), false)]);+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a3'),+ project: 'M',+ );+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('b1', threadId: 'root-2'),+ project: 'M',+ );+ expect(+ [for (final n in notices.shown.skip(2)) (n.key, n.quiet)],+ [(slot, false), (threadSlot('tab-b', 'g9', 'root-2'), false)],+ );});test('is not posted for a thread a push shows: the push already says ''so, and comes down once the thread is read (task #3248)', () {final notices = _Recording();final told = SwarmTold();- final announcer = SwarmAnnouncer(notices, quiet: (_) => false, told: told);+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );final slot = threadSlot('tab-b', 'g9', 'root-1');// Android's FCM push carries the thread's slot as its tag, iOS's the slot and the key it showed.told.pushesShown([slot, 'reply:tab-b:a1', 'decision:d1']);- announcer.announceReply(swarmId: 'tab-b', entry: reply('a1'), project: 'M');- announcer.announceReply(swarmId: 'tab-b', entry: reply('a2'), project: 'M');+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a1'),+ project: 'M',+ );+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a2'),+ project: 'M',+ );announcer.announce(decision());expect(notices.shown, isEmpty);// Read in the app: the push goes with the thread's notification, and the next reply there sounds.- announcer.repliesRead('tab-b', [reply('a1', read: true), reply('a2', read: true)]);+ announcer.repliesRead('tab-b', [+ reply('a1', read: true),+ reply('a2', read: true),+ ]);expect(notices.cancelled, [slot]);expect(told.pushed(slot), isFalse);- announcer.announceReply(swarmId: 'tab-b', entry: reply('a3'), project: 'M');- expect([for (final n in notices.shown) (n.key, n.quiet)], [(slot, false)]);+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a3'),+ project: 'M',+ );+ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false)],+ );});test('a thread whose push was swiped away unread only replaces quietly, ''as the server does', () {final notices = _Recording();final told = SwarmTold();- final announcer = SwarmAnnouncer(notices, quiet: (_) => false, told: told);+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );final slot = threadSlot('tab-b', 'g9', 'root-1');told.pushesShown([slot]);- announcer.announceReply(swarmId: 'tab-b', entry: reply('a1'), project: 'M');+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a1'),+ project: 'M',+ );expect(notices.shown, isEmpty);// Back again with that push gone, and a1 still unread.told.pushesShown(const []);- announcer.announceReply(swarmId: 'tab-b', entry: reply('a2'), project: 'M');+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: reply('a2'),+ project: 'M',+ );expect([for (final n in notices.shown) (n.key, n.quiet)], [(slot, true)]);});@@ -461,10 +531,16 @@ void main() {final [first, second] = [for (final n in notices.shown) n.key];announcer.repliesRead('tab-other', const []);- announcer.repliesRead('tab-b', [reply('a1'), reply('a2', threadId: 'root-2')]);+ announcer.repliesRead('tab-b', [+ reply('a1'),+ reply('a2', threadId: 'root-2'),+ ]);expect(notices.cancelled, isEmpty, reason: 'both still unread');- announcer.repliesRead('tab-b', [reply('a1'), reply('a2', threadId: 'root-2', read: true)]);+ announcer.repliesRead('tab-b', [+ reply('a1'),+ reply('a2', threadId: 'root-2', read: true),+ ]);expect(notices.cancelled, [second]);announcer.repliesRead('tab-b', const []);@@ -634,6 +710,308 @@ void main() {expect(swarmNoticeIdFor('decision:d1'), greaterThan(0));});});+ // Task #3607 (Tony, 2026-11-06): the phone rings when a person must act or a+ // person speaks to its person; an agent's tag or reply is badge and+ // Activity; one task's questions are one notification.+ group('who rings (task #3607)', () {+ SwarmMentionNeed tagBy(String? kind) => SwarmMentionNeed(+ 'tab-b',+ SuperTabMention.fromJson({+ 'id': 'm9',+ 'projectName': 'Mobile',+ 'conversationId': 'g9',+ 'messageId': 'msg-9',+ 'leadName': 'River',+ 'leadKind': ?kind,+ 'text': 'x',+ }),+ );++ SwarmActivityEntry replyBy(String id, String kind) =>+ SwarmActivityEntry.fromJson({+ 'id': id,+ 'kind': 'reply',+ 'conversationId': 'g9',+ 'messageId': 'msg-$id',+ 'threadId': 'root-1',+ 'actor': {'kind': kind, 'id': 'who', 'name': 'River'},+ 'text': 'approve this',+ 'createdAt': DateTime.utc(2026, 11, 6, 9).toIso8601String(),+ 'read': false,+ });++ test(+ 'a tag by an agent posts no notice, yet still counts on the badge',+ () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);+ final need = tagBy('agent');++ announcer.announce(need);+ announcer.settle([need]);++ expect(notices.shown, isEmpty);+ expect(notices.badges, [1]);+ },+ );++ test('a tag by a person rings', () {+ final notices = _Recording();+ SwarmAnnouncer(notices, quiet: (_) => false).announce(tagBy('person'));+ expect(notices.shown.single.title, 'River tagged you');+ expect(notices.shown.single.quiet, isFalse);+ });++ test(+ 'a tag whose tagger an older backend does not name rings as before',+ () {+ final notices = _Recording();+ SwarmAnnouncer(notices, quiet: (_) => false).announce(tagBy(null));+ expect(notices.shown.single.title, 'River tagged you');+ },+ );++ test('a reply by an agent posts no notice and takes no thread slot', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);++ announcer.announceReply(+ swarmId: 'tab-b',+ entry: replyBy('a1', 'agent'),+ project: 'M',+ );+ expect(notices.shown, isEmpty);++ // A person's reply in that thread is the first there: it sounds.+ announcer.announceReply(+ swarmId: 'tab-b',+ entry: replyBy('a2', 'person'),+ project: 'M',+ );+ expect(notices.shown.single.quiet, isFalse);+ });++ test('a reply by a person rings, whatever it says', () {+ final notices = _Recording();+ SwarmAnnouncer(notices, quiet: (_) => false).announceReply(+ swarmId: 'tab-b',+ entry: replyBy('a1', 'person'),+ project: 'M',+ );+ expect(notices.shown.single.title, 'River replied in a thread');+ });+ });++ group('one task, one notification (task #3607)', () {+ SwarmDecisionNeed decisionIn(+ String swarm,+ String conversation, [+ String id = 'd1',+ ]) => SwarmDecisionNeed(+ swarm,+ SuperTabDecision.fromJson({+ 'id': id,+ 'projectName': 'Mobile',+ 'conversationId': conversation,+ 'askerName': 'River',+ 'question': 'Ship it?',+ 'options': ['Yes', 'No'],+ }),+ );++ final slot = swarmTaskSlot(tab, 'g1');++ test("the slot is the server's push slot (backend taskSlot)", () {+ expect(swarmTaskSlot('tab-b', 'g9'), 'task:tab-b:g9');+ });++ test('stuck and a decision of one task post under one key, the later one '+ 'quiet', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);++ announcer.announce(work('blocked'));+ announcer.announce(decisionIn(tab, 'g1'));++ expect(+ [for (final n in notices.shown) (n.key, n.title, n.quiet)],+ [(slot, 'Nova is stuck', false), (slot, 'River asks you', true)],+ );+ });++ test('stuck, then needs you, of one task is one notification', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);++ announcer.announce(work('blocked'));+ announcer.announce(work('needs_human'));++ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false), (slot, true)],+ );+ });++ test('two tasks keep two notifications, each sounding', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);++ announcer.announce(work('blocked'));+ announcer.announce(decisionIn(tab, 'g2'));++ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false), (swarmTaskSlot(tab, 'g2'), false)],+ );+ });++ // A push of the task's slot is in the notification centre, then the+ // question is answered elsewhere: the notification goes, and the push's+ // mark in the slot with it, so the task's next question is told (review of+ // the first head, task #3607).+ test('a task whose last question is answered frees its slot: the next '+ 'question of the task sounds, after a push held the slot', () {+ final notices = _Recording();+ final told = SwarmTold();+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );+ announcer.announce(decisionIn(tab, 'g1', 'd1'));+ // The server's push for the task's second question replaced it.+ told.pushesShown([slot, 'decision:d2']);+ expect(told.pushed(slot), isTrue);++ // d1 is answered on the desktop: two reads miss it.+ announcer.swarmRead(tab, const []);+ announcer.swarmRead(tab, const []);+ expect(notices.cancelled, [slot]);+ expect(told.pushed(slot), isFalse, reason: 'the push went with it');++ announcer.announce(decisionIn(tab, 'g1', 'd3'));+ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false), (slot, false)],+ reason: 'a new question of the task is told, and sounds',+ );+ });++ test('a question only a push shows is followed: answered, the push comes '+ 'down and the slot is free', () {+ final notices = _Recording();+ final told = SwarmTold();+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );+ // iOS gives the push's slot and its key; the app came back to it.+ told.pushesShown([slot, 'decision:d1']);+ announcer.announce(decisionIn(tab, 'g1', 'd1'));+ expect(notices.shown, isEmpty, reason: 'the push says it already');++ announcer.swarmRead(tab, const []);+ announcer.swarmRead(tab, const []);+ expect(notices.cancelled, [slot], reason: 'answered: its push goes');+ expect(told.pushed(slot), isFalse);++ announcer.announce(decisionIn(tab, 'g1', 'd2'));+ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false)],+ );+ });++ test('a push the person swiped away does not keep the next question of '+ 'the task quiet', () {+ final notices = _Recording();+ final told = SwarmTold();+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );+ told.pushesShown([slot, 'decision:d1']);+ announcer.announce(decisionIn(tab, 'g1', 'd1'));+ // Swiped; the app reads the centre again on coming back.+ told.pushesShown(const []);++ announcer.announce(decisionIn(tab, 'g1', 'd2'));+ expect(+ [for (final n in notices.shown) (n.key, n.quiet)],+ [(slot, false)],+ );+ });++ test('a followed push-only question answered while another question of '+ 'the task stays leaves the notification up', () {+ final notices = _Recording();+ final told = SwarmTold();+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );+ told.pushesShown([slot, 'decision:d1']);+ announcer.announce(decisionIn(tab, 'g1', 'd1'));+ told.pushesShown(const []);+ final stays = decisionIn(tab, 'g1', 'd2');+ announcer.announce(stays);++ announcer.swarmRead(tab, [stays]);+ announcer.swarmRead(tab, [stays]);+ expect(notices.cancelled, isEmpty);+ announcer.swarmRead(tab, const []);+ announcer.swarmRead(tab, const []);+ expect(notices.cancelled, [slot]);+ });++ test('answering one of two needs leaves the notification up; answering '+ 'both takes it down once', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);+ final asked = decisionIn(tab, 'g1');+ announcer.announce(work('blocked'));+ announcer.announce(asked);++ // The work moves on; the decision still waits. Two reads miss it.+ announcer.settle([asked]);+ announcer.swarmRead(tab, [asked]);+ announcer.swarmRead(tab, [asked]);+ expect(notices.cancelled, isEmpty);++ // The decision is answered on the desktop.+ announcer.settle(const []);+ announcer.swarmRead(tab, const []);+ announcer.swarmRead(tab, const []);+ expect(notices.cancelled, [slot]);+ });++ test('a task whose decision push shows its slot gets no local notice', () {+ final notices = _Recording();+ final told = SwarmTold();+ final announcer = SwarmAnnouncer(+ notices,+ quiet: (_) => false,+ told: told,+ );+ // Android gives the slot alone as the push's tag.+ told.pushesShown([slot]);++ announcer.announce(work('blocked'));+ announcer.announce(decisionIn(tab, 'g1'));++ expect(notices.shown, isEmpty);+ });++ test('the badge still counts each need of the task', () {+ final notices = _Recording();+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);+ announcer.settle([work('blocked'), decisionIn(tab, 'g1')]);+ expect(notices.badges, [2]);+ });+ });}class _Recording extends SilentSystemNotices {