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: tag and decision counts as Desktop; Threads opens a read thread in its thread (Tony, task 5) (#2465)
harness-for-autonomous[bot]f94937f7fbad
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dartindex cd8e9843a..916aa9ad9 100644--- a/mobile/lib/swarm/swarm_conversation_page.dart+++ b/mobile/lib/swarm/swarm_conversation_page.dart@@ -110,6 +110,7 @@ class SwarmConversationPage extends StatefulWidget {this.buddy,this.messageId,this.decisionId,+ this.threadId,this.mention,this.homeC = false,});@@ -117,6 +118,11 @@ class SwarmConversationPage extends StatefulWidget {final String swarmId, conversationId;final String? messageId, decisionId;+ /// A thread to open over the chat as it opens, when [messageId] is its+ /// root: as Threads opens one on the desktop (`_openThreadFromList`), the+ /// chat behind it at the root.+ final String? threadId;+/// An agent to @mention in the draft as the chat opens: the PM, as its/// private line is answered in the project chat.final String? mention;@@ -929,10 +935,18 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>/// a tag opens through on the desktop.static const _findPages = 50;+ /// The thread the chat opens with, until its first jump+ /// ([SwarmConversationPage.threadId]).+ late String? _threadAt = widget.threadId;+/// Brings [messageId] into view and lights it — read in from earlier pages/// when it is further back — or says why it cannot.Future<void> _jumpTo(SwarmConversation c, String messageId) async {if (_finding) return;+ // Only the jump the chat opened with opens [SwarmConversationPage.threadId]:+ // a quote of the root tapped later brings the root into view.+ final thread = _threadAt;+ _threadAt = null;final landing = _land();setState(() {_decisionTarget = null;@@ -948,6 +962,13 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>final target = found? c.messages.where((m) => m.id == messageId).firstOrNull: null;+ // Threads opens the thread itself, its root read back or not, while the+ // chat is still one the reader may read.+ if (thread == messageId &&+ !c.reader.accessRevoked &&+ c.reader.snapshot?.conversation(c.id) != null) {+ _openThread(c, messageId);+ }if (target != null && target.threadReply) {_openThread(c, target.thread!);if (!target.inMainStream) {diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dartindex 8ae9175ae..4119b6ecb 100644--- a/mobile/lib/swarm/swarm_project_page.dart+++ b/mobile/lib/swarm/swarm_project_page.dart@@ -102,19 +102,22 @@ void openSwarmProject(}/// A route to chat [conversationId] of Swarm [swarmId], at [messageId] with-/// [decisionId] asked, as a notice, a link, Activity or a row opens it+/// [decisionId] asked, or with [threadId]'s thread open over it at its root,+/// as a notice, a link, Activity, Threads or a row opens it/// ([SwarmOpenedChat]).Route<void> swarmChatRoute({required String swarmId,required String conversationId,String? messageId,String? decisionId,+ String? threadId,}) => phoneRoute((_) => SwarmOpenedChat(swarmId: swarmId,conversationId: conversationId,messageId: messageId,decisionId: decisionId,+ threadId: threadId,),listensForItself: true,);@@ -139,11 +142,15 @@ class SwarmOpenedChat extends StatefulWidget {required this.conversationId,this.messageId,this.decisionId,+ this.threadId,});final String swarmId, conversationId;final String? messageId, decisionId;+ /// The thread opened over the chat ([SwarmConversationPage.threadId]).+ final String? threadId;+@overrideState<SwarmOpenedChat> createState() => _SwarmOpenedChatState();}@@ -258,6 +265,7 @@ class _SwarmOpenedChatState extends State<SwarmOpenedChat> {projectId: projectId,messageId: widget.messageId,decisionId: widget.decisionId,+ threadId: widget.threadId,),null => SwarmConversationPage(key: const ValueKey('swarm-opened-chat'),@@ -265,6 +273,7 @@ class _SwarmOpenedChatState extends State<SwarmOpenedChat> {conversationId: widget.conversationId,messageId: widget.messageId,decisionId: widget.decisionId,+ threadId: widget.threadId,),};}@@ -289,6 +298,7 @@ class SwarmProjectPage extends StatefulWidget {this.mention,this.messageId,this.decisionId,+ this.threadId,});final String swarmId, projectId;@@ -305,8 +315,9 @@ class SwarmProjectPage extends StatefulWidget {/// Where its chat opens, as a notice or a link names it: at that message,/// with that decision asked ([SwarmConversationPage.messageId] and- /// [SwarmConversationPage.decisionId]). Only the first time the chat shows.- final String? messageId, decisionId;+ /// [SwarmConversationPage.decisionId]), or with that thread open over it+ /// ([SwarmConversationPage.threadId]). Only the first time the chat shows.+ final String? messageId, decisionId, threadId;@overrideState<SwarmProjectPage> createState() => _SwarmProjectPageState();@@ -323,7 +334,9 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {/// Where the chat opens ([SwarmProjectPage.messageId]): forgotten once/// another tab is picked, so the chat shown again opens at its end.- late String? _messageId = widget.messageId, _decisionId = widget.decisionId;+ late String? _messageId = widget.messageId,+ _decisionId = widget.decisionId,+ _threadId = widget.threadId;/// What the page shows of the inbox ([_inboxChanged]): its Swarm's/// reader, whether there are several Swarms, why the list was not read.@@ -576,6 +589,7 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {mention: widget.mention,messageId: _messageId,decisionId: _decisionId,+ threadId: _threadId,homeC: _homeC,),SwarmProjectTab.buddy => SwarmProjectBuddy(@@ -640,7 +654,7 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {: swarmChatNews(reader, asks, chat),onSelect: (tab) => setState(() {_tab = tab;- _messageId = _decisionId = null;+ _messageId = _decisionId = _threadId = null;}),),),diff --git a/mobile/lib/swarm/swarm_read_marks.dart b/mobile/lib/swarm/swarm_read_marks.dartindex 26e18be91..005745181 100644--- a/mobile/lib/swarm/swarm_read_marks.dart+++ b/mobile/lib/swarm/swarm_read_marks.dart@@ -95,8 +95,9 @@ class SwarmReadMarkSender<K> {/// each chat's id and a number. The first read of a Swarm on this phone, with/// no mark yet from the phone or the server, counts what is already there as/// read (Tony, 2026-10-29), so a new phone does not start with every chat in-/// bold; the Home kept from before is no read. Nothing is unread until the-/// marks are read back. Access lost takes them off the phone too.+/// bold; the Home kept from before is no read. That first mark is no read of+/// a tag, though: a tag already waiting then still counts ([tagsReadThrough]).+/// Nothing is unread until the marks are read back. Access lost takes them off the phone too.class SwarmReadMarks extends ChangeNotifier {SwarmReadMarks(this.reader, {@@ -153,6 +154,11 @@ class SwarmReadMarks extends ChangeNotifier {/// The phone's own marks, by chat.final _marks = <String, int>{};+ /// The marks of [_marks] that only the first read set, by chat: no read by+ /// the person. Kept apart in what the phone keeps too, so a phone before+ /// them reads [_marks] as it always has.+ final _firstRead = <String, int>{};+/// The phone's own thread marks, by chat then thread root.final _threads = <String, Map<String, int>>{};@@ -189,6 +195,20 @@ class SwarmReadMarks extends ChangeNotifier {): null;+ /// How far the person has read [conversationId] for its tags: the higher+ /// of the server's mark and this phone's, leaving out the first read's,+ /// which saw nothing (the desktop's `readMark`). Null as [readThrough] is.+ int? tagsReadThrough(String conversationId) =>+ _loaded && !reader.accessRevoked+ ? max(+ reader.snapshot?.readMarks[conversationId] ?? 0,+ switch (_marks[conversationId]) {+ final mark? when mark != _firstRead[conversationId] => mark,+ _ => 0,+ },+ )+ : null;+/// How far the person has read [root]'s thread in [conversationId]: the/// higher of the server's thread mark, from any of their devices, and this/// phone's; null until the phone's are read back, and once access is lost.@@ -231,14 +251,25 @@ class SwarmReadMarks extends ChangeNotifier {sequence,kept: reader.snapshot?.readMarks[conversationId] ?? 0,);- if (sequence <= (_marks[conversationId] ?? 0)) return;- _marks[conversationId] = sequence;+ // Seen through the first read's mark, or through the chat's newest+ // message in its main stream when replies only in a thread came after+ // it: the mark is the person's own now.+ final first = _firstRead[conversationId];+ final main = reader.snapshot?.conversation(conversationId)?.mainSequence;+ final seen =+ first != null &&+ (sequence >= first || (main != null && sequence >= main));+ if (seen) _firstRead.remove(conversationId);+ final moved = sequence > (_marks[conversationId] ?? 0);+ if (!moved && !seen) return;+ if (moved) _marks[conversationId] = sequence;_saveSoon();notifyListeners();}Future<void> _load() async {final held = <String, int>{};+ final first = <String, int>{};final threads = <String, Map<String, int>>{};var found = false;try {@@ -250,6 +281,12 @@ class SwarmReadMarks extends ChangeNotifier {}found = true;}+ // Absent from what a phone before them wrote.+ if (value case {'firstRead': final Map marks}) {+ for (final MapEntry(:key, :value) in marks.entries) {+ if (key is String && value is num) first[key] = value.toInt();+ }+ }// Absent from what a phone before thread marks wrote.if (value case {'threads': final Map kept}) {for (final MapEntry(key: id, value: roots) in kept.entries) {@@ -270,6 +307,10 @@ class SwarmReadMarks extends ChangeNotifier {for (final MapEntry(:key, :value) in held.entries) {if (value > (_marks[key] ?? 0)) _marks[key] = value;}+ // A first read's mark stays one while nothing read moved it on.+ for (final MapEntry(:key, :value) in first.entries) {+ if (_marks[key] == value) _firstRead[key] = value;+ }// A thread read before the marks were back keeps the higher of the two.for (final MapEntry(key: id, value: roots) in threads.entries) {final now = _threads[id] ??= {};@@ -303,6 +344,7 @@ class SwarmReadMarks extends ChangeNotifier {for (final group in snapshot.conversations) {if (group.lastMessageSequence > (_marks[group.id] ?? 0)) {_marks[group.id] = group.lastMessageSequence;+ _firstRead[group.id] = group.lastMessageSequence;}}}@@ -315,6 +357,7 @@ class SwarmReadMarks extends ChangeNotifier {_save = null;final had = _marks.isNotEmpty || _threads.isNotEmpty || _started;_marks.clear();+ _firstRead.clear();_threads.clear();_started = false;unawaited(store?.delete(_key).catchError((Object _) {}));@@ -332,6 +375,7 @@ class SwarmReadMarks extends ChangeNotifier {_trim();final value = jsonEncode({'marks': _marks,+ if (_firstRead.isNotEmpty) 'firstRead': _firstRead,if (_threads.isNotEmpty) 'threads': _threads,});unawaited(store?.write(_key, value).catchError((Object _) {}));@@ -341,6 +385,7 @@ class SwarmReadMarks extends ChangeNotifier {/// first, then the oldest kept.void _trim() {_trimThreads();+ _firstRead.removeWhere((id, first) => _marks[id] != first);if (_marks.length <= kept) return;final read = {for (final group in reader.snapshot?.conversations ?? const []) group.id,@@ -355,6 +400,7 @@ class SwarmReadMarks extends ChangeNotifier {while (_marks.length > kept) {_marks.remove(_marks.keys.first);}+ _firstRead.removeWhere((id, _) => !_marks.containsKey(id));}/// At most [keptThreads] thread marks: those of chats the Swarm's read nodiff --git a/mobile/lib/swarm/swarm_threads_page.dart b/mobile/lib/swarm/swarm_threads_page.dartindex 5be5d1d36..43c463812 100644--- a/mobile/lib/swarm/swarm_threads_page.dart+++ b/mobile/lib/swarm/swarm_threads_page.dart@@ -288,7 +288,8 @@ class _SwarmThreadsPageState extends State<SwarmThreadsPage> {}/// Opens [entry]'s chat at its newest new reply, which opens its thread,- /// else at its root.+ /// else at its root with its thread open over it, as the desktop's Threads+ /// opens one.void _open(BuildContext context,SwarmThreadsMerge threads,@@ -301,6 +302,7 @@ class _SwarmThreadsPageState extends State<SwarmThreadsPage> {swarmId: entry.swarmId,conversationId: entry.thread.conversationId,messageId: reply?.id ?? entry.thread.rootId,+ threadId: reply == null ? entry.thread.rootId : null,),),);diff --git a/mobile/lib/swarm/swarm_unread.dart b/mobile/lib/swarm/swarm_unread.dartindex 0099a1bc6..99c5a640b 100644--- a/mobile/lib/swarm/swarm_unread.dart+++ b/mobile/lib/swarm/swarm_unread.dart@@ -11,51 +11,114 @@ typedef SwarmRowNews = ({bool bold, int tags});/// Nothing new.const SwarmRowNews swarmNoNews = (bold: false, tags: 0);-/// [group]'s row: bold while it is unread ([SwarmReader.readMarks]) or holds-/// tags still waiting ([asks]), with their count.+/// [group]'s row: bold while it is unread ([SwarmReader.readMarks]) and not+/// muted, or while something counts in it ([swarmChatCount]), with that count.SwarmRowNews swarmChatNews(SwarmReader reader,SwarmAsks? asks,SuperTabConversation group,) {- var tags = 0;- for (final mention in asks?.mentions ?? const <SuperTabMention>[]) {- if (mention.conversationId == group.id) tags++;+ final tags = swarmChatCount(reader, asks, group);+ return (bold: _unreadShown(reader, group) || tags > 0, tags: tags);+}++/// The `@` count of [group], as the desktop's red number counts+/// (attention.dart `mentionsIn`): tags of the reader waiting in its main+/// stream — a reply also sent to the chat is in it, one that lives only in+/// its thread counts on Threads instead — that the reader has not read past,+/// and decisions asked of them there while the chat shows unread (a+/// decision's row does not say which message asked). A muted chat never+/// counts; its tags stay listed in Activity. No tag counts until the phone's+/// marks are back, and nothing once access is gone.+int swarmChatCount(+ SwarmReader reader,+ SwarmAsks? asks,+ SuperTabConversation group,+) => _countIn(+ reader,+ group,+ [+ for (final m in asks?.mentions ?? const <SuperTabMention>[])+ if (m.conversationId == group.id) m,+ ],+ (asks?.decisions ?? const [])+ .where((d) => d.conversationId == group.id)+ .length,+);++/// How much counts in [group] ([swarmChatCount]) of [mentions] and [asked]+/// open decisions, all of them in it.+int _countIn(+ SwarmReader reader,+ SuperTabConversation group,+ Iterable<SuperTabMention> mentions,+ int asked,+) {+ final snapshot = reader.snapshot;+ if (reader.accessRevoked || snapshot == null) return 0;+ if (snapshot.chatSettings[group.id] == 'muted') return 0;+ var count = 0;+ if (reader.readMarks?.tagsReadThrough(group.id) case final through?) {+ for (final m in mentions) {+ if (m.threadId == null && (m.messageSequence ?? _unknown) > through) {+ count++;+ }+ }}- final unread = reader.readMarks?.unread(group) ?? false;- return (bold: unread || tags > 0, tags: tags);+ if (asked > 0 && _unreadShown(reader, group)) count += asked;+ return count;}+/// A tag from a server that does not say where it is: it counts until+/// answered, past any read mark.+const _unknown = 1 << 52;++/// Whether [group] shows as unread: unread, and not muted. A muted chat stays+/// listed and never counts (the desktop's `unreadShown`).+bool _unreadShown(SwarmReader reader, SuperTabConversation group) =>+ reader.snapshot?.chatSettings[group.id] != 'muted' &&+ (reader.readMarks?.unread(group) ?? false);+/// Each project's row with something new, by project id: bold while its-/// project chat or any of its open work is unread, as the desktop's sidebar-/// reads a project — never for closed work, a private chat or the person's-/// Buddy chat, which has a row of its own — or while tags wait in it, with-/// the count of all of them. One pass over the Swarm's chats for every-/// project.+/// project chat or any of its open work shows unread, as the desktop's+/// sidebar reads a collapsed project — never for closed work, a private chat+/// or the person's Buddy chat, which has a row of its own — or while tags+/// count there, with the sum of those chats' counts ([swarmChatCount]). A tag+/// counts only in a chat this Swarm lists, under that chat's own project.+/// One pass over the Swarm's chats for every project.Map<String, SwarmRowNews> swarmProjectNews(SwarmReader reader,SwarmAsks? asks,) {- final snapshot = reader.snapshot, marks = reader.readMarks;- if (snapshot == null) return const {};- final unread = <String>{};- if (marks != null) {- for (final group in snapshot.conversations) {- if (group.closed ||- group.audience != null ||- reader.buddies.chatOwners.containsKey(group.id) ||- unread.contains(group.projectId)) {- continue;- }- if (marks.unread(group)) unread.add(group.projectId);- }+ final snapshot = reader.snapshot;+ if (snapshot == null || reader.accessRevoked) return const {};+ final waiting = <String, List<SuperTabMention>>{};+ for (final m in asks?.mentions ?? const <SuperTabMention>[]) {+ (waiting[m.conversationId] ??= []).add(m);+ }+ final asked = <String, int>{};+ for (final d in asks?.decisions ?? const <SuperTabDecision>[]) {+ asked[d.conversationId] = (asked[d.conversationId] ?? 0) + 1;}+ final unread = <String>{};final tags = <String, int>{};- for (final mention in asks?.mentions ?? const <SuperTabMention>[]) {- final projectId = mention.projectId.isNotEmpty- ? mention.projectId- : snapshot.conversation(mention.conversationId)?.projectId;- if (projectId != null) tags[projectId] = (tags[projectId] ?? 0) + 1;+ for (final group in snapshot.conversations) {+ if (group.closed ||+ group.audience != null ||+ reader.buddies.chatOwners.containsKey(group.id)) {+ continue;+ }+ final projectId = group.projectId;+ if (!unread.contains(projectId) && _unreadShown(reader, group)) {+ unread.add(projectId);+ }+ final count = _countIn(+ reader,+ group,+ waiting[group.id] ?? const [],+ asked[group.id] ?? 0,+ );+ if (count > 0) tags[projectId] = (tags[projectId] ?? 0) + count;}return {for (final id in {...unread, ...tags.keys})diff --git a/mobile/test/swarm/swarm_inbox_test.dart b/mobile/test/swarm/swarm_inbox_test.dartindex 3c8299bf5..3e9a855f1 100644--- a/mobile/test/swarm/swarm_inbox_test.dart+++ b/mobile/test/swarm/swarm_inbox_test.dart@@ -1013,8 +1013,10 @@ void main() {await settle();expect(store.values[key], isNotNull, reason: 'kept, not forgotten');+ // The first read's mark, kept apart as no read of a tag.expect(jsonDecode(store.values[key]!), {'marks': {'g1': 3},+ 'firstRead': {'g1': 3},});final next = SwarmInbox(accountId: me,diff --git a/mobile/test/swarm/swarm_read_marks_test.dart b/mobile/test/swarm/swarm_read_marks_test.dartindex 90b449c79..9470fff2f 100644--- a/mobile/test/swarm/swarm_read_marks_test.dart+++ b/mobile/test/swarm/swarm_read_marks_test.dart@@ -284,8 +284,10 @@ void main() {await settle();first.marks.markRead(work, 4);await settle();+ // The project chat's mark is the first read's alone; the work's was read.expect(jsonDecode(first.store.values[key]!), {'marks': {work: 4, leadChat: 2},+ 'firstRead': {leadChat: 2},});// Started again later, after a message came.diff --git a/mobile/test/swarm/swarm_screens_test.dart b/mobile/test/swarm/swarm_screens_test.dartindex 81492294c..69ce58b91 100644--- a/mobile/test/swarm/swarm_screens_test.dart+++ b/mobile/test/swarm/swarm_screens_test.dart@@ -171,6 +171,8 @@ void main() {request: fake.request,notices: SilentSystemNotices(),features: features,+ // The phone's read marks: a tag counts only once they are back.+ readMarks: MemoryKeyValueStore(),)..foreground = false;addTearDown(host.dispose);await tester.pumpWidget(diff --git a/mobile/test/swarm/swarm_thread_jump_test.dart b/mobile/test/swarm/swarm_thread_jump_test.dartindex f6ba51ad6..55eb163e8 100644--- a/mobile/test/swarm/swarm_thread_jump_test.dart+++ b/mobile/test/swarm/swarm_thread_jump_test.dart@@ -6,6 +6,7 @@ import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;import 'package:harness_mobile/swarm/swarm_conversation_page.dart';import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_thread_page.dart';import '../voice_fakes.dart';import 'swarm_fixture.dart';@@ -143,6 +144,90 @@ void main() {return row.top >= view.top && row.bottom <= view.bottom;}+ group('opened from Threads', () {+ Future<void> openAt(+ WidgetTester tester,+ FakeSwarm fake, {+ String? threadId,+ }) async {+ final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm};+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: fake.request,+ upload: refuseSwarmUpload,+ notices: SilentSystemNotices(),+ features: features,+ readMarks: MemoryKeyValueStore(),+ )..foreground = false;+ addTearDown(host.dispose);+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ builder: (context, child) =>+ SwarmScope(notifier: host, child: child!),+ home: SwarmConversationPage(+ swarmId: tab,+ conversationId: 'g1',+ messageId: 'm1',+ threadId: threadId,+ ),+ ),+ );+ await tester.pumpAndSettle();+ }++ testWidgets('a thread with no new replies opens in its thread', (+ tester,+ ) async {+ await openAt(tester, backend(replies(3), mark: 3), threadId: 'm1');++ expect(find.byType(SwarmThreadPage), findsOneWidget);+ expect(find.text('Reply 3.'), findsOneWidget);+ });++ testWidgets('a quote of the root tapped after the thread is left brings '+ 'the root into view, no thread open again', (tester) async {+ final fake = backend(replies(3), mark: 3);+ fake.routes[messages] = (_) => {+ 'messages': [+ {+ ...said(9),+ 'id': 'm9',+ 'text': 'About the question.',+ 'thread': 'm9',+ 'replyTo': 'm1',+ },+ said(1),+ ],+ 'next': null,+ 'threads': [lineOf(2, 3)],+ };+ await openAt(tester, fake, threadId: 'm1');+ expect(find.byType(SwarmThreadPage), findsOneWidget);++ Navigator.of(tester.element(find.byType(SwarmThreadPage))).pop();+ await tester.pumpAndSettle();+ expect(find.byType(SwarmThreadPage), findsNothing);++ await tester.tap(find.byKey(const ValueKey('swarm-quote-m9')));+ await tester.pumpAndSettle();++ expect(find.byType(SwarmThreadPage), findsNothing);+ });++ testWidgets('a link to a root lands on it in the chat, no thread open', (+ tester,+ ) async {+ await openAt(tester, backend(replies(3), mark: 3));++ expect(find.byType(SwarmThreadPage), findsNothing);+ expect(find.text('The question.'), findsOneWidget);+ });+ });+group('Jump to latest', () {testWidgets('while the latest is more than a screen below it takes the ''person to the foot; near the foot, none', (tester) async {diff --git a/mobile/test/swarm/swarm_threads_page_test.dart b/mobile/test/swarm/swarm_threads_page_test.dartindex 5e5b60350..24f25d2b7 100644--- a/mobile/test/swarm/swarm_threads_page_test.dart+++ b/mobile/test/swarm/swarm_threads_page_test.dart@@ -170,6 +170,35 @@ void main() {await leave(tester);});+ testWidgets('a tap on a thread with no new replies opens its thread over '+ 'the chat at its root, as the desktop does', (tester) async {+ await pump(+ tester,+ backend(+ threads: () => {+ 'unread': [],+ 'read': [row('m7', follow: true, text: 'Rate limits')],+ },+ ),+ );++ await tester.tap(find.text('Rate limits'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 500));++ expect(+ find.byWidgetPredicate(+ (w) =>+ w is SwarmOpenedChat &&+ w.conversationId == 'g1' &&+ w.messageId == 'm7' &&+ w.threadId == 'm7',+ ),+ findsOneWidget,+ );+ await leave(tester);+ });+testWidgets('Unfollow from ⋯ is kept on the server, and the thread leaves', (tester,) async {diff --git a/mobile/test/swarm/swarm_unread_test.dart b/mobile/test/swarm/swarm_unread_test.dartindex 285535d13..4954ca0d4 100644--- a/mobile/test/swarm/swarm_unread_test.dart+++ b/mobile/test/swarm/swarm_unread_test.dart@@ -1,10 +1,16 @@+import 'dart:async';+import 'dart:convert';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/core/local_key_value_store.dart';import 'package:harness_mobile/swarm/swarm_asks.dart';import 'package:harness_mobile/swarm/swarm_read_marks.dart';import 'package:harness_mobile/swarm/swarm_reader.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_unread.dart';+import '../voice_fakes.dart';import 'swarm_fixture.dart';/// What a chat's or a project's row says is new (desktop design system,@@ -17,8 +23,12 @@ void main() {String id, {String conversationId = 'g1',String projectId = project,+ String? threadId,+ int? messageSequence,}) => {'id': id,+ 'threadId': ?threadId,+ 'messageSequence': ?messageSequence,'projectId': projectId,'projectName': 'Mobile','conversationId': conversationId,@@ -29,11 +39,31 @@ void main() {'createdAt': '2026-10-27T01:00:00.000Z',};+ Map<String, dynamic> decisionRow(String id, {String conversationId = 'g1'}) =>+ {+ 'id': id,+ 'batchId': 'batch-$id',+ 'projectId': project,+ 'projectName': 'Mobile',+ 'conversationId': conversationId,+ 'conversationTitle': 'Fix login',+ 'askerName': 'River',+ 'question': 'Ship it?',+ 'options': ['Yes', 'No'],+ 'recommended': 0,+ 'unblocks': 'The release',+ 'createdAt': '2026-10-27T01:00:00.000Z',+ };+/// A Swarm of two projects: Mobile with its project chat, work g1 and g2,/// closed work, a private chat and the reader's Buddy chat; Web with its- /// project chat. Read once, so what is there counts as read; [tags] wait.+ /// project chat. Read once, so what is there counts as read; [tags] wait,+ /// and [decisions] are open. [settings] are the reader's own notification+ /// settings by chat.Future<({FakeSwarm swarm, SwarmReader reader, SwarmAsks asks})> rig({List<Map<String, dynamic>> tags = const [],+ List<Map<String, dynamic>> decisions = const [],+ Map<String, String> settings = const {},}) async {final swarm = FakeSwarm();Map<String, dynamic> inWeb(Map<String, dynamic> group) => {@@ -62,7 +92,11 @@ void main() {},],);- final derived = {'mentionsWaiting': tags.length};+ final derived = {+ 'mentionsWaiting': tags.length,+ 'decisionsWaiting': decisions.length,+ if (settings.isNotEmpty) 'chatSettings': settings,+ };swarm.routes['/api/super-tabs/$tab/parts'] = (_) =>firstLoad(head: head, groups: groups, derived: derived);swarm.routes['/api/super-tabs/$tab/changes'] = (_) =>@@ -71,7 +105,7 @@ void main() {'mentions': tags,};swarm.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {- 'decisions': <Object>[],+ 'decisions': decisions,};swarm.routes['/api/super-tabs/$tab/conversations/'] = (body) => {'sequence': body!['sequence'],@@ -98,9 +132,11 @@ void main() {({FakeSwarm swarm, SwarmReader reader, SwarmAsks asks}) r,Map<String, Map<String, dynamic>> groups, {int version = 20,+ Map<String, dynamic> derived = const {},}) async {r.swarm.routes['/api/super-tabs/$tab/changes'] = (_) => changes(cursor: 'c$version',+ derived: derived,groups: [for (final MapEntry(:key, :value) in groups.entries)part(key, version, value),@@ -159,7 +195,8 @@ void main() {});test("a chat the Lead tagged the person in is bold with the count of the "- "tags still waiting, read or not", () async {+ "tags still waiting, from a server that does not say where they are "+ "past any read mark", () async {final r = await rig(tags: [mentionRow('t1'),@@ -237,4 +274,281 @@ void main() {));expect(swarmProjectNews(reader, null), isEmpty);});++ group('counts as the desktop counts (attention.dart mentionsIn)', () {+ test('a tag stops counting once the person has read past it', () async {+ final r = await rig(+ tags: [+ mentionRow('t-read', messageSequence: 3),+ mentionRow('t-new', messageSequence: 4),+ ],+ );+ // The person read through t-read; the first read alone marks no tag.+ r.reader.readMarks!.markRead('g1', 3);+ await moveOn(r, {+ 'g1': groupData('g1', title: 'Fix login', lastMessageSequence: 4),+ });++ expect(chat(r, 'g1'), (bold: true, tags: 1));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 1),+ });++ r.reader.readMarks!.markRead('g1', 4);+ await settle();++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ expect(swarmProjectNews(r.reader, r.asks), isEmpty);+ });++ test('a tag already waiting when the Swarm is first read counts: that '+ 'first read marks no tag read', () async {+ final r = await rig(tags: [mentionRow('t1', messageSequence: 3)]);++ expect(chat(r, 'g1'), (bold: true, tags: 1));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 1),+ });++ // The person reads the chat as far as the first read had marked it.+ r.reader.readMarks!.markRead('g1', 3);+ await settle();++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ });++ test('reading a chat to its newest main-stream message is a read of its '+ 'tags, though replies only in a thread came after it', () async {+ final r = await rig(tags: [mentionRow('t1', messageSequence: 3)]);+ // Read once as it is now: the newest message is a reply only in its+ // thread.+ await moveOn(r, {+ 'g1': {+ ...groupData('g1', title: 'Fix login', lastMessageSequence: 5),+ 'lastMainSequence': 3,+ },+ });+ final fresh = SwarmReadMarks(r.reader, store: null);+ addTearDown(fresh.dispose);+ r.reader.readMarks = fresh;+ await settle();+ expect(chat(r, 'g1'), (bold: true, tags: 1));++ // The chat read to its end: its newest main-stream message, offline.+ fresh.markRead('g1', 3);+ await settle();++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ });++ test("the first read's marks are kept apart on the phone: read back, the "+ 'tag still counts, and once read it stays read', () async {+ final store = MemoryKeyValueStore();+ final r = await rig(tags: [mentionRow('t1', messageSequence: 3)]);+ final first = SwarmReadMarks(r.reader, store: store);+ r.reader.readMarks = first;+ await settle();+ first.dispose();++ final again = SwarmReadMarks(r.reader, store: store);+ r.reader.readMarks = again;+ await settle();+ expect(chat(r, 'g1'), (bold: true, tags: 1));++ again.markRead('g1', 3);+ again.dispose();+ final last = SwarmReadMarks(r.reader, store: store);+ addTearDown(last.dispose);+ r.reader.readMarks = last;+ await settle();++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ });++ test('marks a phone kept before first reads were apart still count as '+ 'read', () async {+ final store = MemoryKeyValueStore();+ final r = await rig(tags: [mentionRow('t1', messageSequence: 3)]);+ await store.write(+ 'swarm_read_marks.$me.$tab',+ jsonEncode({+ 'marks': {'g1': 3},+ }),+ );+ final kept = SwarmReadMarks(r.reader, store: store);+ addTearDown(kept.dispose);+ r.reader.readMarks = kept;+ await settle();++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ });++ test('a tag in a reply only in its thread counts on Threads, not in its '+ 'chat or project', () async {+ final r = await rig(+ tags: [mentionRow('t1', threadId: 'm-root', messageSequence: 9)],+ );++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ expect(swarmProjectNews(r.reader, r.asks), isEmpty);+ });++ test('a tag in a reply also sent to the chat counts in the chat and its '+ 'project', () async {+ // The server names no thread for a reply also in the chat+ // (backend mentions.ts threadsOf).+ final r = await rig(tags: [mentionRow('t1', messageSequence: 4)]);+ await moveOn(r, {+ 'g1': groupData('g1', title: 'Fix login', lastMessageSequence: 4),+ });++ expect(chat(r, 'g1'), (bold: true, tags: 1));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 1),+ });+ });++ test('a muted chat never counts and is never bold; its tags stay in '+ 'Activity', () async {+ final r = await rig(+ tags: [+ mentionRow('t1'),+ mentionRow('t2', conversationId: 'g2'),+ ],+ settings: {'g1': 'muted'},+ );+ await moveOn(r, {+ 'g1': groupData('g1', title: 'Fix login', lastMessageSequence: 4),+ });++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ expect(chat(r, 'g2'), (bold: true, tags: 1));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 1),+ });+ expect(r.asks.mentions, hasLength(2));+ });++ test("a project counts only the chats this Swarm lists under it: not "+ "another project's chat a tag names it for, closed work, a private "+ "chat, the person's Buddy chat or a chat not listed", () async {+ final r = await rig(+ tags: [+ mentionRow('t-web', conversationId: 'web-lead'),+ mentionRow('t-closed', conversationId: 'closed'),+ mentionRow('t-private', conversationId: 'private'),+ mentionRow('t-buddy', conversationId: 'buddy-chat'),+ mentionRow('t-gone', conversationId: 'not-listed'),+ ],+ );++ expect(swarmProjectNews(r.reader, r.asks), {+ other: (bold: true, tags: 1),+ });+ // The private chat's own row still counts its tag, as the desktop's.+ expect(chat(r, 'private'), (bold: true, tags: 1));+ });++ test('nothing counts until the phone has its read marks back', () async {+ final r = await rig(tags: [mentionRow('t1', messageSequence: 9)]);+ final waiting = Completer<String?>();+ final slow = SwarmReadMarks(r.reader, store: _HeldStore(waiting.future));+ addTearDown(slow.dispose);+ r.reader.readMarks = slow;++ expect(chat(r, 'g1'), (bold: false, tags: 0));+ expect(swarmProjectNews(r.reader, r.asks), isEmpty);++ waiting.complete(null);+ await settle();++ expect(chat(r, 'g1').tags, 1);+ });++ test('nothing counts once access is gone', () async {+ final r = await rig(tags: [mentionRow('t1')]);+ final g1 = r.reader.snapshot!.conversation('g1')!;+ expect(chat(r, 'g1'), (bold: true, tags: 1));++ const refused = SuperTabFailure(+ 'FORBIDDEN',+ 'Not yours.',+ statusCode: 403,+ );+ r.swarm.routes['/api/super-tabs/$tab/changes'] = (_) => throw refused;+ r.swarm.routes['/api/super-tabs/$tab/parts'] = (_) => throw refused;+ await r.reader.refresh();+ await settle();++ expect(r.reader.accessRevoked, isTrue);+ expect(swarmChatNews(r.reader, r.asks, g1), (bold: false, tags: 0));+ expect(swarmProjectNews(r.reader, r.asks), isEmpty);+ });++ test(+ 'a decision asked in a chat counts while the chat is unread',+ () async {+ final r = await rig(decisions: [decisionRow('d1')]);++ expect(chat(r, 'g1'), (bold: false, tags: 0), reason: 'read');++ await moveOn(r, {+ 'g1': groupData('g1', title: 'Fix login', lastMessageSequence: 4),+ });++ expect(chat(r, 'g1'), (bold: true, tags: 1));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 1),+ });+ },+ );++ test('a decision answered on another device leaves the count without a '+ 'reload', () async {+ final r = await rig(decisions: [decisionRow('d1')]);+ await moveOn(+ r,+ {'g1': groupData('g1', title: 'Fix login', lastMessageSequence: 4)},+ derived: {'decisionsWaiting': 1, 'mentionsWaiting': 0},+ );+ expect(chat(r, 'g1'), (bold: true, tags: 1));+ final loads = r.swarm.paths.where((p) => p.endsWith('/parts')).length;++ r.swarm.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ r.swarm.routes['/api/super-tabs/$tab/changes'] = (_) => changes(+ cursor: 'c30',+ derived: {'decisionsWaiting': 0, 'mentionsWaiting': 0},+ );+ await r.reader.refresh();+ await settle();++ expect(chat(r, 'g1'), (bold: true, tags: 0));+ expect(swarmProjectNews(r.reader, r.asks), {+ project: (bold: true, tags: 0),+ });+ expect(+ r.swarm.paths.where((p) => p.endsWith('/parts')),+ hasLength(loads),+ reason: 'no reload',+ );+ });+ });+}++/// A phone store whose read answers when [value] does.+class _HeldStore implements LocalKeyValueStore {+ _HeldStore(this.value);++ final Future<String?> value;++ @override+ Future<String?> read(String key) => value;++ @override+ Future<void> write(String key, String value) async {}++ @override+ Future<void> delete(String key) async {}}