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
Group macOS notifications by tab (#496)
Dee15e2474f2d2a
diff --git a/desktop/design/images/notification-tab-groups.png b/desktop/design/images/notification-tab-groups.pngnew file mode 100644index 000000000..f09ef929fBinary files /dev/null and b/desktop/design/images/notification-tab-groups.png differdiff --git a/desktop/design/workspace-status-bar.md b/desktop/design/workspace-status-bar.mdindex b9bc37990..81fbdafa8 100644--- a/desktop/design/workspace-status-bar.md+++ b/desktop/design/workspace-status-bar.md@@ -217,18 +217,26 @@ sits slightly outside the mark so both remain legible. The combined templateadapts to the menu bar's light, dark, and selected appearances. It keeps a fixed size, showing `99+`above 99 with the exact count in its tooltip and accessibilityvalue. Its native menu lists only harnesses with unread-notifications, grouped by project, adding machine names when more than one-machine is represented. Read sessions disappear; an empty inbox says “No unread+notifications, grouped by their open tab's displayed name in tab order. Each+section lists its newest notifications first. Sessions outside open tabs appear+under “Other sessions” at the end. A session in multiple tabs appears once,+preferring the active tab, then the first tab containing it. Machine profiles+do not hide notification groups. Project and machine context stays in row+tooltips. Read sessions disappear; an empty inbox says “No unreadnotifications.” Blue dots mark unread rows. Long titles truncate withtheir full text and context in tooltips; unavailable rows are disabled. Rowsstay in place while the menu is open. New Harness, Clear All Notifications,Open Harness, Settings, and Quit follow the conversations. The window's titlebarhas search and Store without a duplicate bell.++Clear All acknowledges only the notifications in the displayed snapshot. Newerresults and replacement questions stay unread. Opening a conversation restores-its existing pane before bringing the window forward. Reading a question clears-its notification, while the question itself remains pending until answered.+its existing pane in the displayed tab before bringing the window forward. If+that view moved or closed, navigation resolves the session's current location.+Reading a question clears its notification, while the question itself remains+pending until answered.The menu uses AppKit's standard keyboard navigation and accessibility.On Linux and the web, a small bell sits in the top row between the search icondiff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 8ac0a9ef4..c413171e8 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -5670,9 +5670,23 @@ class _SwarmScreenState extends State<SwarmScreen> {).firstOrNull;if (row == null || row['unavailable'] != null) return;- final destination = swarmDestinations(app)- .where((item) => item.machineId == machineId && item.agentId == agentId)- .firstOrNull;+ // Keep the tab shown in the menu even if the active tab changed while it+ // was open. If that view moved or closed, resolve the session's new home.+ final destination =+ SwarmLocationCatalog()+ .read(app, const [])+ .where(+ (item) =>+ item.swarmId == receipt['tabId'] &&+ item.machineId == machineId &&+ item.agentId == agentId,+ )+ .firstOrNull ??+ swarmDestinations(app)+ .where(+ (item) => item.machineId == machineId && item.agentId == agentId,+ )+ .firstOrNull;if (destination == null || _newHarness?.requestDismiss() == false) return;_closeNewHarness(restoreFocus: false);_closeSearch(restoreFocus: false);diff --git a/desktop/lib/state/status_menu.dart b/desktop/lib/state/status_menu.dartindex b71ad77ea..8dc31f4bb 100644--- a/desktop/lib/state/status_menu.dart+++ b/desktop/lib/state/status_menu.dart@@ -1,24 +1,45 @@import 'app_state.dart';import 'notification_inbox.dart';+import 'swarm.dart';+import 'workspace_status.dart';-/// The macOS menu lists only harnesses with an unread notification.+/// The macOS menu lists unread harnesses in tab order, then Other sessions./// Receipts travel with each row so a menu left open cannot clear newer news.-List<Map<String, Object?>> statusMenuEntries(AppNotifier app) => [- for (final notification in notificationInbox(app)) _entry(app, notification),-];+List<Map<String, Object?>> statusMenuEntries(AppNotifier app) {+ final notifications = notificationInbox(app);+ if (notifications.isEmpty) return [];+ final names = workspaceTabNames(app);+ final owners = <(String, String), Swarm>{};+ // A shared session counts once. Prefer its active tab, otherwise the first+ // tab containing it. Include tabs hidden by the machine profile, too.+ for (final tab in app.swarms) {+ for (final pane in tab.panes) {+ if (pane.agentId == null) continue;+ final key = (pane.machineId, pane.agentId!);+ if (!owners.containsKey(key) || tab.id == app.activeSwarmId) {+ owners[key] = tab;+ }+ }+ }+ final groups = <String?, List<Map<String, Object?>>>{};+ for (final notification in notifications) {+ final tab = owners[(notification.machineId, notification.agentId)];+ (groups[tab?.id] ??= []).add({+ ..._entry(app, notification),+ 'tabId': tab?.id,+ 'tabName': tab == null ? 'Other sessions' : names[tab.id],+ });+ }+ return [for (final tab in app.swarms) ...?groups[tab.id], ...?groups[null]];+}Map<String, Object?> _entry(AppNotifier app, InboxNotification notification) {final machineId = notification.machineId;final agentId = notification.agentId;- final machine = app.stateOf(machineId);- final agent = machine?.agents.where((a) => a.id == agentId).firstOrNull;- final project = agent == null ? null : machine?.projectOf(agent);return {'machineId': machineId,'agentId': agentId,'title': notification.title,- 'machineName': machine?.machine.displayName ?? 'Unavailable machine',- 'project': project?.label ?? 'No Project','detail': notification.detail,'unavailable': notification.unavailable,'unread': true,diff --git a/desktop/macos/Runner/HarnessStatusMenu.swift b/desktop/macos/Runner/HarnessStatusMenu.swiftindex f5d96222c..174edc9dc 100644--- a/desktop/macos/Runner/HarnessStatusMenu.swift+++ b/desktop/macos/Runner/HarnessStatusMenu.swift@@ -81,14 +81,12 @@ final class HarnessStatusMenu: NSObject, NSMenuDelegate {empty.isEnabled = falsemenu.addItem(empty)} else {- // First occurrence preserves newest-first ordering across project groups.- var groups: [String] = []- var grouped: [String: [[String: Any]]] = [:]- let machines = Set(entries.compactMap { $0["machineId"] as? String })+ // Dart supplies tab order and newest-first rows within each tab. IDs keep+ // identically named tabs separate; nil holds sessions outside open tabs.+ var groups: [String?] = []+ var grouped: [String?: [[String: Any]]] = [:]for entry in entries {- let project = entry["project"] as? String ?? "No Project"- let machine = entry["machineId"] as? String ?? ""- let group = machine + "\u{0}" + project+ let group = entry["tabId"] as? Stringif grouped[group] == nil { groups.append(group) }grouped[group, default: []].append(entry)}@@ -96,8 +94,7 @@ final class HarnessStatusMenu: NSObject, NSMenuDelegate {if index > 0 { menu.addItem(.separator()) }let rows = grouped[group]!let first = rows[0]- var title = first["project"] as? String ?? "No Project"- if machines.count > 1 { title += " · " + (first["machineName"] as? String ?? "") }+ let title = first["tabName"] as? String ?? "Other sessions"let heading = NSMenuItem(title: compact(title), action: nil, keyEquivalent: "")heading.isEnabled = falseheading.toolTip = titlediff --git a/desktop/test/status_menu_test.dart b/desktop/test/status_menu_test.dartindex 3e17bed7f..430a4e86a 100644--- a/desktop/test/status_menu_test.dart+++ b/desktop/test/status_menu_test.dart@@ -3,9 +3,13 @@ import 'dart:async';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/models.dart';import 'package:harness/notify/alert_sounds.dart';+import 'package:harness/state/app_state.dart';import 'package:harness/state/notification_inbox.dart';import 'package:harness/state/status_menu.dart';+import 'package:harness/state/terminal_pane.dart';+import 'package:harness/state/workspace_status.dart';import 'swarm_attention_test.dart' show waitingQuestion;import 'swarm_screen_test.dart' show mount, terminal;@@ -25,8 +29,9 @@ void main() {expect(entries.any((r) => r['agentId'] == 'a0'), isFalse);expect(entries.map((r) => r['agentId']).toSet(), hasLength(entries.length));expect(entries.first['agentId'], 'a29');- expect(entries.first['project'], 'No Project');- expect(entries.first['machineName'], 'Test host');+ expect(entries.first['tabId'], isNull);+ expect(entries.first['tabName'], 'Other sessions');+ expect(entries.first['detail'], contains('Test host'));expect(entries.first['unavailable'], isNull);app.stateOf('m')!.nodeOnline = false;expect(statusMenuEntries(app).first['unavailable'], 'Offline');@@ -38,6 +43,103 @@ void main() {);});+ test('groups by tab identity across machines, in tab order with Other sessions last', () {+ final app = createApp(connected: true);+ addTearDown(app.dispose);+ const remote = Machine(+ machineId: 'remote',+ name: 'Remote host',+ authMode: MachineAuthMode.remote,+ );+ app.machineStates['remote'] = MachineState(remote)+ ..agents = [Agent(id: 'a0', name: 'Remote result', engine: 'codex')];+ final first = app.activeSwarm;+ app.renameSwarm(first.id, 'Design');+ first.panes.addAll([+ TerminalPane(id: 1, machineId: 'm', agentId: 'a0'),+ TerminalPane(id: 2, machineId: 'remote', agentId: 'a0'),+ ]);+ app.newSwarm(name: 'Design');+ final second = app.activeSwarm;+ second.panes.add(TerminalPane(id: 3, machineId: 'm', agentId: 'a1'));+ app.agentUnread.mark('m', 'a0', AlertKind.done);+ app.agentUnread.mark('m', 'a1', AlertKind.done);+ app.agentUnread.mark('remote', 'a0', AlertKind.done);+ app.agentUnread.mark('m', 'a9', AlertKind.done);++ final rows = statusMenuEntries(app);+ expect(rows.map((r) => (r['machineId'], r['agentId'])), [+ ('remote', 'a0'),+ ('m', 'a0'),+ ('m', 'a1'),+ ('m', 'a9'),+ ]);+ expect(rows.map((r) => r['tabId']), [first.id, first.id, second.id, null]);+ expect(rows.map((r) => r['tabName']), [+ 'Design',+ 'Design',+ 'Design',+ 'Other sessions',+ ]);++ app.renameSwarm(second.id, 'Review');+ expect(statusMenuEntries(app)[2]['tabName'], 'Review');+ expect(+ statusMenuReceiptIsCurrent(app, rows[2]),+ isTrue,+ reason: 'renaming a tab does not replace its notification',+ );+ });++ test(+ 'a shared session counts once and follows tab membership and display names',+ () {+ final app = createApp(connected: true);+ addTearDown(app.dispose);+ final first = app.activeSwarm;+ final pane = TerminalPane(id: 1, machineId: 'm', agentId: 'a0');+ first.panes.add(pane);+ app.agentUnread.mark('m', 'a0', AlertKind.done);+ expect(+ statusMenuEntries(app).single['tabName'],+ workspaceTabNames(app)[first.id],+ );+ expect(statusMenuEntries(app).single['tabName'], isNot(first.name));++ app.newSwarm(name: 'Review');+ final second = app.activeSwarm..panes.add(pane);+ expect(statusMenuEntries(app).single['tabId'], second.id);+ app.newSwarm(name: 'Unrelated');+ expect(statusMenuEntries(app).single['tabId'], first.id);+ first.remove(pane);+ expect(statusMenuEntries(app).single['tabId'], second.id);+ second.remove(pane);+ expect(statusMenuEntries(app).single['tabName'], 'Other sessions');+ expect(statusMenuEntries(app).single['tabId'], isNull);+ expect(app.agentUnread.kindFor('m', 'a0'), AlertKind.done);+ },+ );++ test(+ 'machine profiles keep unread sessions grouped under their hidden tabs',+ () {+ final app = createApp(connected: true);+ addTearDown(app.dispose);+ final hidden = app.activeSwarm;+ app.renameSwarm(hidden.id, 'Remote work');+ hidden.panes.add(TerminalPane(id: 1, machineId: 'remote', agentId: 'a0'));+ app.newSwarm(name: 'Local work');+ app.activeSwarm.panes.add(+ TerminalPane(id: 2, machineId: 'm', agentId: 'a1'),+ );+ app.setMachineProfile('m');+ app.agentUnread.mark('remote', 'a0', AlertKind.done);+ expect(app.profileSwarms, isNot(contains(hidden)));+ expect(statusMenuEntries(app).single['tabName'], 'Remote work');+ expect(statusMenuEntries(app).single['tabId'], hidden.id);+ },+ );+test('clear acknowledges displayed news, never answers or clears newer news',() {@@ -133,10 +235,18 @@ void main() {expect(app.activeSwarmId, originalTab);expect(app.agentUnread.kindFor('m', 'a8'), AlertKind.failed);- await select(- 'openStatusHarness',- rows().singleWhere((r) => r['agentId'] == 'a8'),+ final displayedResult = rows().singleWhere((r) => r['agentId'] == 'a8');+ expect(displayedResult['tabId'], resultTab);+ // A shared session becomes visible in the active tab while the native+ // menu is tracking. The click still belongs to the displayed tab.+ app.activeSwarm.panes.add(result);+ app.renameSwarm(originalTab, 'Desktop review');+ await tester.pump();+ expect(+ rows().singleWhere((r) => r['agentId'] == 'a8')['tabId'],+ originalTab,);+ await select('openStatusHarness', displayedResult);expect(app.activeSwarmId, resultTab);expect(app.focusedPane, same(result));expect(app.allPanes.where((p) => p.agentId == 'a8'), hasLength(1));@@ -148,6 +258,19 @@ void main() {containsAllInOrder(['isMinimized', 'restore', 'show', 'focus']),);+ // If the displayed tab has since closed, use the remaining view without+ // resurrecting a tab or creating another terminal controller.+ app.agentUnread.mark('m', 'a8', AlertKind.done);+ await tester.pump();+ final movedResult = rows().singleWhere((r) => r['agentId'] == 'a8');+ await app.closeSwarm(resultTab);+ await tester.pump();+ await select('openStatusHarness', movedResult);+ expect(app.activeSwarmId, originalTab);+ expect(app.focusedPane, same(result));+ expect(app.swarms.any((tab) => tab.id == resultTab), isFalse);+ expect(app.agentUnread.kindFor('m', 'a8'), isNull);+final displayed = rows();app.agentUnread.mark('m', 'a7', AlertKind.done);await tester.pump();diff --git a/desktop/tool/status_menu_checks.swift b/desktop/tool/status_menu_checks.swiftindex 7553b099e..6fe38ff4c 100644--- a/desktop/tool/status_menu_checks.swift+++ b/desktop/tool/status_menu_checks.swift@@ -20,10 +20,12 @@ private func renderedStatusPixels(_ image: NSImage) -> Data {}private func fixture(_ agent: String, project: String = "autonomous-harness",+ tabId: String? = "tab-build", tabName: String = "Build", machine: String = "office",unread: Bool = true, token: String = "first", offline: Bool = false) -> [String: Any] {- var row: [String: Any] = ["machineId": "office", "machineName": "Office Mac",- "agentId": agent, "title": agent, "project": project, "unread": unread,+ var row: [String: Any] = ["machineId": machine,+ "agentId": agent, "title": agent, "tabName": tabId == nil ? "Other sessions" : tabName, "unread": unread,"detail": "Office Mac · \(project)"]+ row["tabId"] = tabIdif unread { row["readToken"] = token; row["label"] = "Finished" }if offline { row["unavailable"] = "Offline" }return row@@ -47,11 +49,12 @@ let status = HarnessStatusMenu(installStatusItem: false, showWindow: { reveals +do {var rows = [fixture("General chat conversation"),fixture("DeepSeek model", project: "No Project", unread: false),- fixture("Math addition inquiry", project: "No Project", offline: true)]+ fixture("Math addition inquiry", project: "No Project", tabId: nil, offline: true)]status.update(["enabled": true, "statusMenuEntries": rows])try check(status.menu.items.filter { $0.state == .on }.count == 2, "Unread rows have dots")try check(status.row("General chat conversation").onStateImage != nil, "A blue dot replaces the checkmark")- try check(status.menu.items.contains { $0.title == "No Project" && !$0.isEnabled }, "Projects use native section headings")+ try check(status.menu.items.contains { $0.title == "Build" && !$0.isEnabled } &&+ status.menu.items.contains { $0.title == "Other sessions" && !$0.isEnabled }, "Tabs and other sessions use native section headings")try check(!status.row("Math addition inquiry").isEnabled, "Offline conversations stay visible but disabled")try check(status.row("Math addition inquiry").toolTip?.contains("Offline") == true, "Unavailable state is explained")try check(!status.menu.items.contains { $0.title == "DeepSeek model" }, "Read conversations are absent from the notification menu")@@ -66,10 +69,10 @@ do {let selected = status.row("General chat conversation")let before = emitted.countrows[0] = fixture("General chat conversation", token: "newer")- rows.append(fixture("New result", project: "website"))+ rows.append(fixture("New result", project: "website", tabId: "tab-website", tabName: "Website"))status.update(["enabled": true, "statusMenuEntries": rows])try check(status.row("General chat conversation") === selected &&- !status.menu.items.contains { $0.title == "website" }, "Arrivals do not move open-menu rows")+ !status.menu.items.contains { $0.title == "Website" }, "Arrivals do not move open-menu rows")status.click(selected)try check(emitted.count == before, "A replaced notification cannot dispatch an old click")status.click(status.item("clearStatusNotifications"))@@ -79,7 +82,21 @@ do {cleared?.first?["readToken"] as? String == "first", "Clear sends only displayed receipts, never new arrivals")status.menuDidClose(status.menu)status.menuNeedsUpdate(status.menu)- try check(status.menu.items.contains { $0.title == "website" }, "The next opening shows new arrivals")+ try check(status.menu.items.contains { $0.title == "Website" }, "The next opening shows new arrivals")++ status.menuWillOpen(status.menu)+ let originalLocation = status.row("General chat conversation")+ rows[0]["tabId"] = "tab-review"+ rows[0]["tabName"] = "Review"+ status.update(["enabled": true, "statusMenuEntries": rows])+ status.click(originalLocation)+ let originalReceipt = emitted.last?.1 as? [String: Any]+ try check(emitted.last?.0 == "openStatusHarness" && originalReceipt?["tabId"] as? String == "tab-build",+ "A current notification retains its displayed destination when tabs change")+ try check(!status.menu.items.contains { $0.title == "Review" }, "Tab changes do not move open-menu rows")+ status.menuDidClose(status.menu)+ status.menuNeedsUpdate(status.menu)+ try check(status.menu.items.contains { $0.title == "Review" }, "The next opening reflects the new tab group")status.update(["enabled": false, "statusMenuEntries": rows])try check(!status.item("newAgent").isEnabled && !status.item("settings").isEnabled &&@@ -130,6 +147,20 @@ do {"Unread notifications add a visible badge to the icon")}try checkCounter()+ status.update(["enabled": true, "statusMenuEntries": [+ fixture("API result", tabId: "tab-one", tabName: "Work"),+ fixture("Website result", project: "website", tabId: "tab-one", tabName: "Work", machine: "laptop"),+ fixture("Review result", tabId: "tab-two", tabName: "Work"),+ fixture("Background result", tabId: nil),+ ]])+ let headings = status.menu.items.filter { !$0.isEnabled && !$0.isSeparatorItem && $0.representedObject == nil }+ try check(headings.map { $0.title } == ["Work", "Work", "Other sessions"],+ "Tab IDs keep equal names separate, combine projects and machines, and preserve section order")+ try check(status.menu.index(of: status.row("Website result")) < status.menu.index(of: headings[1]) &&+ status.menu.index(of: status.row("Review result")) > status.menu.index(of: headings[1]),+ "Each row stays inside its tab's section")+ try check(status.row("Website result").toolTip?.contains("website") == true,+ "Project context remains available in the row tooltip")print("Harness status menu passed \(checks) checks")} catch {fputs("Harness status menu failed: \(error)\n", stderr)