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
Desktop: the Swarm badge counts new lines in # buddy where the Swarm has one Buddy (Diego) (#2503)
0xken15117cebf2ce72
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dartindex a2155836b..c04469af7 100644--- a/desktop/lib/super_tabs/controller.dart+++ b/desktop/lib/super_tabs/controller.dart@@ -2710,25 +2710,34 @@ class SuperTabController extends ChangeNotifier {(held.first.sequence <= readMark(group.id) || !hasOlder(group.id));}+ /// The reader's Buddy chats that count toward the Swarm badge: the one+ /// Buddy's chat where the Swarm gives one Buddy for the whole Swarm (its+ /// older project Buddy chats are copies of its lines, so they never count+ /// twice), else each project's.+ Iterable<SuperTabConversation> get _countedBuddyChats sync* {+ if (oneBuddy) {+ if (buddyChat(kSwarmBuddyKey) case final chat?) yield chat;+ return;+ }+ for (final project in snapshot?.projects ?? const <SuperTabProject>[]) {+ if (buddyChat(project.id) case final chat?) yield chat;+ }+ }+/// The unread messages in the reader's own Buddy chats, the PM's private/// lines among them, for the Swarm badge.int get buddyUnread => [- for (final project in snapshot?.projects ?? const <SuperTabProject>[])+ for (final chat in _countedBuddyChats)// A muted chat never counts (Slack).- if (buddyChat(project.id) case final chat?- when notifyOf(chat.id) != SuperTabNotify.muted)- unreadCount(chat),+ if (notifyOf(chat.id) != SuperTabNotify.muted) unreadCount(chat),].fold(0, (a, b) => a + b);/// Reads each Buddy chat whose count is still open ([_countOpen]), page by/// page, so the count is exact up to [kCountCap]; nothing once every chat's/// count is known.void _readUnreadBuddyChats() {- for (final project in snapshot?.projects ?? const <SuperTabProject>[]) {- final chat = buddyChat(project.id);- if (chat == null || !_countOpen(chat) || !_counting.add(chat.id)) {- continue;- }+ for (final chat in _countedBuddyChats) {+ if (!_countOpen(chat) || !_counting.add(chat.id)) continue;unawaited(_countChat(chat.id).whenComplete(() {_counting.remove(chat.id);diff --git a/desktop/test/super_tab_buddy_chat_counts_test.dart b/desktop/test/super_tab_buddy_chat_counts_test.dartindex 9c904cdb2..95cd0f72d 100644--- a/desktop/test/super_tab_buddy_chat_counts_test.dart+++ b/desktop/test/super_tab_buddy_chat_counts_test.dart@@ -19,6 +19,7 @@ import 'package:harness/state/harness_activity.dart';import 'package:harness/super_tabs/controller.dart';import 'package:harness/super_tabs/machine_icon.dart';import 'package:harness/super_tabs/machines.dart';+import 'package:harness/super_tabs/model.dart' show SuperTabNotify;import 'package:harness/super_tabs/buddy_chat.dart';import 'package:harness/super_tabs/buddy_chat_shortcut.dart';import 'package:harness/super_tabs/buddy_rows.dart';@@ -29,6 +30,7 @@ import 'package:harness/widgets/desktop_chrome.dart';import 'box_render_preview_test.dart' show loadPreviewFonts;import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;import 'swarm_screen_test.dart' show mount;+import 'support/buddy_fixture.dart';import 'support/pm_chat_fixture.dart';import 'support/super_tab_fixture.dart';@@ -168,6 +170,154 @@ void main() {});});+ group('the unread count with one Buddy for the Swarm', () {+ const key = SuperTabController.kSwarmBuddyKey;++ /// [account]'s controller in a Swarm with one Buddy each, their # buddy+ /// opened once and then left for a workgroup, so the Buddy's replies+ /// arrive unread.+ Future<(SuperTabController, String)> awayFromBuddy(+ ConversationServer server, {+ String account = 'peer',+ }) async {+ final c = server.controller(account: account);+ addTearDown(c.dispose);+ await c.refresh();+ await c.openBuddyChat(key);+ final chat = c.buddyChat(key)!.id;+ await c.select('offline');+ await pumpEventQueue();+ return (c, chat);+ }++ ConversationServer swarmWithBuddy() {+ final server = oneBuddySwarm();+ giveSwarmBuddy(server);+ return server;+ }++ test("counts the Buddy's replies after leaving # buddy", () async {+ final server = swarmWithBuddy();+ final (c, chat) = await awayFromBuddy(server);+ expect(c.buddyUnread, 0);++ buddyReply(server, chat, 'Here is the plan.');+ buddyReply(server, chat, 'Shall I ship it?');+ await c.refresh();+ await pumpEventQueue();++ expect(c.unreadCount(c.buddyChat(key)!), 2);+ expect(c.buddyUnread, 2);+ });++ test('a muted # buddy never counts, and counts again unmuted', () async {+ final server = swarmWithBuddy();+ final (c, chat) = await awayFromBuddy(server);+ buddyReply(server, chat, 'Here is the plan.');+ buddyReply(server, chat, 'Shall I ship it?');+ await c.refresh();+ await pumpEventQueue();+ expect(c.buddyUnread, 2);++ expect(await c.setNotify(chat, SuperTabNotify.muted), isTrue);+ expect(c.buddyUnread, 0);++ expect(await c.setNotify(chat, SuperTabNotify.all), isTrue);+ expect(c.buddyUnread, 2);+ });++ test('clears once # buddy is read', () async {+ final server = swarmWithBuddy();+ final (c, chat) = await awayFromBuddy(server);+ buddyReply(server, chat, 'Here is the plan.');+ await c.refresh();+ await pumpEventQueue();+ expect(c.buddyUnread, 1);++ await c.select(chat);+ await pumpEventQueue();+ c.markRead(chat);++ expect(c.buddyUnread, 0);+ });++ test("never counts or reads the older project Buddy chat: its lines are copies", () async {+ final server = swarmWithBuddy();+ // The reader's older Buddy chat in the lead project, with news.+ (server.state['conversations'] as List).add({+ ...conversationFixture('buddy-peer-lead', "peer's Buddy"),+ 'kind': 'buddy',+ 'projectId': 'lead',+ 'buddyOwnerId': 'peer',+ 'agentIds': <String>[],+ });+ final (c, chat) = await awayFromBuddy(server);+ final reads = <String>[];+ server.onRead = reads.add;++ buddyReply(server, 'buddy-peer-lead', 'A copy of the plan.');+ buddyReply(server, chat, 'Here is the plan.');+ await c.refresh();+ await pumpEventQueue();++ expect(c.buddyChat('lead'), isNotNull);+ expect(c.buddyUnread, 1);+ expect(reads.where((p) => p.contains('/buddy-peer-lead/')), isEmpty);+ });++ test("never counts or reads another person's Buddy chat", () async {+ final server = swarmWithBuddy();+ final (_, peerChat) = await awayFromBuddy(server);+ final owner = server.controller(account: 'owner');+ addTearDown(owner.dispose);+ await owner.refresh();+ final reads = <String>[];+ server.onRead = reads.add;++ buddyReply(server, peerChat, 'Only for Ken.');+ await owner.refresh();+ await pumpEventQueue();++ expect(owner.buddyChat(key), isNull);+ expect(owner.buddyUnread, 0);+ expect(reads.where((p) => p.contains(peerChat)), isEmpty);+ });++ test(+ 'counts every unread line of a chat not held yet, past a page',+ () async {+ final server = swarmWithBuddy();+ server.messagePage = 10;+ final (c, chat) = await awayFromBuddy(server);+ // One line read first, so the read mark sits at it.+ buddyReply(server, chat, 'Earlier, already read.');+ await c.refresh();+ await c.select(chat);+ await pumpEventQueue(times: 100);+ c.markRead(chat);+ await c.select('offline');+ for (var i = 1; i <= 25; i++) {+ buddyReply(server, chat, 'Update $i');+ }+ await c.refresh();+ await pumpEventQueue(times: 100);++ expect(c.buddyUnread, 25);+ },+ );++ test('a Swarm with no Buddy chat yet counts nothing', () async {+ final server = oneBuddySwarm();+ final c = server.controller(account: 'peer');+ addTearDown(c.dispose);+ await c.refresh();+ await pumpEventQueue();++ expect(c.buddyChat(key), isNull);+ expect(c.buddyUnread, 0);+ });+ });+group('the unread count past a page', () {/// [awayFromChat] with one reply read first, so the read mark sits at it,/// and pages of [page] messages.