Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Swarm sidebar like a chat app: Chat with PM as a pinned direct message, # projects, ~ machines, unread counts and ⇧⌘K (#1783)

Jacob Phame7f303c55a2e
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index cb270e1b0..4148c4496 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -75,6 +75,8 @@ import '../state/harness_placement.dart';
import '../state/new_harness.dart';
import '../state/harness_launch_integration.dart';
import '../super_tabs/launch.dart';
+import '../super_tabs/pm_chat.dart' show countText;
+import '../super_tabs/pm_chat_shortcut.dart';
import '../super_tabs/workspace.dart';
import '../super_tabs/actions.dart';
import 'swarm_menu_bus.dart';
@@ -2244,7 +2246,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
app.questionFor(p.machineId, p.agentId!) != null,
)
.length +
- tabMentionsWaiting(app, swarm),
+ tabWaiting(app, swarm),
if (tabActivity(app, swarm) case final activity?)
'activity': nativeActivityPayload(
activity,
@@ -7691,6 +7693,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
for (var i = 1; i <= 9; i++)
'pane.focus_$i': () => app.focusPaneByIndex(i - 1),
'navigation.commands': _showSearchCommands,
+ 'swarm.chat_with_pm': () => unawaited(openActivePmChat(app)),
'agent_messages.show': () => _showAgentMessages(app.activeSwarmId),
'agent_messages.activity': _toggleTabActivity,
'agent_messages.make_leader': _toggleFocusedLeader,
@@ -9069,7 +9072,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
final swarm = shown[index];
final selected = app.activeSwarmId == swarm.id;
final activity = activities[index];
- final tags = tabMentionsWaiting(app, swarm);
+ final tags = tabWaiting(app, swarm);
// A status cell animates only while its tab is in view.
Widget tabStatus(Widget Function(bool visible) mark) =>
ListenableBuilder(
@@ -9155,9 +9158,9 @@ class _SwarmScreenState extends State<SwarmScreen> {
label: labels[index],
selected: selected,
tooltip: tabHint.isEmpty ? null : tabHint,
- activityLabel: tags > 0
- ? tabMentionsLabel(tags)
- : activity?.label,
+ activityLabel:
+ tabWaitingLabel(app, swarm) ??
+ activity?.label,
sharedCount: share.count,
onInvitePeople: menus && share.invite
? () => unawaited(_invitePeople(swarm.id))
@@ -9187,7 +9190,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
: null,
activity: tags > 0
? Text(
- '$tags',
+ countText(tags),
key: ValueKey('tab-tags:${swarm.id}'),
style: DesktopChrome.metadata(
color: grid.AppPalette.warn,
diff --git a/desktop/lib/shortcuts/app_shortcuts.dart b/desktop/lib/shortcuts/app_shortcuts.dart
index 19b5c899a..d6d97ead3 100644
--- a/desktop/lib/shortcuts/app_shortcuts.dart
+++ b/desktop/lib/shortcuts/app_shortcuts.dart
@@ -584,6 +584,9 @@ const windowsCommandKeys = <String, List<String>>{
'picker.refresh': ['ctrl+r'],
// Ctrl+Shift+Backspace removes the selected resource in the picker.
'picker.delete': ['alt+shift+backspace'],
+ // Ctrl+Shift+K is Focus Pane Above (⌘K); ⇧⌘K takes Alt+Shift like the
+ // other shifted twins.
+ 'swarm.chat_with_pm': ['alt+shift+k'],
};
/// Where "⌘ becomes Alt" would take a key a Linux terminal program already
diff --git a/desktop/lib/shortcuts/keymap_commands.dart b/desktop/lib/shortcuts/keymap_commands.dart
index e9881b6bf..196d06f68 100644
--- a/desktop/lib/shortcuts/keymap_commands.dart
+++ b/desktop/lib/shortcuts/keymap_commands.dart
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import '../logging/debug_surface.dart';
+import '../super_tabs/pm_chat.dart' show kChatWithPm;
import 'app_shortcuts.dart';
import 'keymap.dart';
import 'keymap_keyboard.dart';
@@ -219,6 +220,15 @@ final harnessCommands = <HarnessCommand>[
action: ShortcutAction.showAttention,
nativeAction: 'notifications',
),
+ // The current project's Chat with PM, in a Swarm tab. K for "talk": free on
+ // every platform (Alt+Shift+K on Linux, the web and Windows).
+ const HarnessCommand(
+ 'swarm.chat_with_pm',
+ kChatWithPm,
+ ShortcutGroup.navigate,
+ extraKeys: ['cmd+shift+k'],
+ keywords: ['product manager', 'PM', 'Swarm'],
+ ),
for (var i = 1; i <= 9; i++)
HarnessCommand(
'swarm.select_$i',
diff --git a/desktop/lib/state/harness_activity.dart b/desktop/lib/state/harness_activity.dart
index db281da20..628647aea 100644
--- a/desktop/lib/state/harness_activity.dart
+++ b/desktop/lib/state/harness_activity.dart
@@ -1,5 +1,6 @@
import '../core/models.dart';
import '../notify/alert_sounds.dart';
+import '../super_tabs/pm_chat.dart' show pmUnreadLabel;
import '../widgets/engine_identity.dart' show isTerminalEngine;
import 'app_state.dart';
import 'swarm.dart';
@@ -102,6 +103,25 @@ int tabMentionsWaiting(AppNotifier app, Swarm tab) =>
String tabMentionsLabel(int count) =>
'Tagged in $count ${count == 1 ? 'message' : 'messages'}';
+/// The unread messages in this account's own PM chats in a Swarm tab.
+int tabPmWaiting(AppNotifier app, Swarm tab) =>
+ tab.superTabId == null ? 0 : app.superTabs.waitingPm(tab.superTabId!);
+
+/// What a Swarm tab's badge counts: its tags and its unread PM messages.
+int tabWaiting(AppNotifier app, Swarm tab) =>
+ tabMentionsWaiting(app, tab) + tabPmWaiting(app, tab);
+
+/// What a Swarm tab's badge says, or null when it counts nothing:
+/// "Tagged in 1 message · 2 new in Chat with PM".
+String? tabWaitingLabel(AppNotifier app, Swarm tab) {
+ final tags = tabMentionsWaiting(app, tab), pm = tabPmWaiting(app, tab);
+ final parts = [
+ if (tags > 0) tabMentionsLabel(tags),
+ if (pm > 0) pmUnreadLabel(pm),
+ ];
+ return parts.isEmpty ? null : parts.join(' · ');
+}
+
/// A viewer refers to its owner; showing the same harness twice adds no vote.
/// A Lead's tag waiting in a Swarm tab needs the person, like a question.
HarnessActivity? tabActivity(AppNotifier app, Swarm tab) {
diff --git a/desktop/lib/super_tabs/client.dart b/desktop/lib/super_tabs/client.dart
index 6464abf45..245006548 100644
--- a/desktop/lib/super_tabs/client.dart
+++ b/desktop/lib/super_tabs/client.dart
@@ -61,6 +61,10 @@ class SuperTabClient {
return _loaded[id]?.snapshot?.mentionsWaiting ?? _tagCounts[id] ?? 0;
}
+ /// The unread messages in this account's own PM chats in a Swarm open
+ /// here ([SuperTabController.pmUnread]); none for one not open.
+ int waitingPm(String id) => _loaded[id]?.pmUnread ?? 0;
+
/// Open here, but not polling: not on screen while the reading pauses.
bool _paused(String id) =>
_reading.pausesAway && (_loaded[id]?.away ?? false);
@@ -447,7 +451,7 @@ class SuperTabClient {
upload: upload,
reading: _reading,
)..away = _isAway(id);
- var seenChange = (lastChangedAt: -1, mentionsWaiting: -1);
+ var seenChange = (lastChangedAt: -1, mentionsWaiting: -1, pmUnread: -1);
var seenSelected = controller.selectedId;
controller.addListener(() {
if (_reading.drawsSaved && generation == _generation) {
@@ -468,6 +472,8 @@ class SuperTabClient {
final change = (
lastChangedAt: controller.lastChangedAt,
mentionsWaiting: snapshot.mentionsWaiting,
+ // A read mark or a PM chat's messages move the Swarm badge too.
+ pmUnread: controller.pmUnread,
);
if (change != seenChange) {
seenChange = change;
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index 824dc64b9..9467d952c 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -10,6 +10,7 @@ import '../state/harness_attachments.dart';
import 'attachment_upload.dart';
import 'identity.dart';
import 'model.dart';
+import 'pm_chat.dart';
import 'parts.dart';
import 'reading.dart';
import 'review_verdict.dart';
@@ -692,6 +693,109 @@ class SuperTabController extends ChangeNotifier {
)
.firstOrNull;
+ /// How many of [group]'s messages from others came after the reader's read
+ /// mark: exact once the messages held reach back to the mark
+ /// ([_heldSinceRead]), else a lower bound, one at least, while more are read
+ /// ([_readUnreadPmChats]).
+ int unreadCount(SuperTabConversation group) {
+ if (!unread(group)) return 0;
+ final readAt = _readAt[group.id] ?? 0;
+ final count = messages(group.id)
+ .where((m) => m.sequence > readAt && !_ownMessage(m))
+ .length;
+ return _heldSinceRead(group) ? count : max(count, 1);
+ }
+
+ bool _ownMessage(SuperTabMessage m) =>
+ !m.fromAgent && !m.fromTerminal && m.authorId == accountId;
+
+ /// Whether the messages held of [group] run from its read mark (or its
+ /// first message) to its newest, update requests included.
+ bool _heldSinceRead(SuperTabConversation group) {
+ final held = _messages[group.id];
+ if (held == null || held.isEmpty) return false;
+ return held.last.sequence >= group.lastMessageSequence &&
+ (held.first.sequence <= (_readAt[group.id] ?? 0) ||
+ !hasOlder(group.id));
+ }
+
+ /// The unread messages in the reader's own PM chats, for the Swarm badge.
+ int get pmUnread => [
+ for (final project in snapshot?.projects ?? const <SuperTabProject>[])
+ if (pmChat(project.id) case final chat?) unreadCount(chat),
+ ].fold(0, (a, b) => a + b);
+
+ /// Reads each PM chat whose count is still open ([_pmCountOpen]), page by
+ /// page, so the count is exact up to [kCountCap]; nothing once every chat's
+ /// count is known.
+ void _readUnreadPmChats() {
+ for (final project in snapshot?.projects ?? const <SuperTabProject>[]) {
+ final chat = pmChat(project.id);
+ if (chat == null || !_pmCountOpen(chat) || !_pmCounting.add(chat.id)) {
+ continue;
+ }
+ unawaited(
+ _countPmChat(chat.id).whenComplete(() {
+ _pmCounting.remove(chat.id);
+ }),
+ );
+ }
+ }
+
+ final _pmCounting = <String>{};
+
+ /// A PM chat off screen, unread, under [kCountCap] and not held back to its
+ /// read mark: past the cap the badge says "99+" whatever the rest holds, so
+ /// a device with no read mark never reads the whole history.
+ bool _pmCountOpen(SuperTabConversation chat) =>
+ chat.id != selectedId &&
+ unread(chat) &&
+ unreadCount(chat) < kCountCap &&
+ !_heldSinceRead(chat);
+
+ /// Newer pages until the newest message is held, then older ones back to
+ /// the read mark; stops when a read brings nothing (no more, or it failed:
+ /// the next state read tries again).
+ Future<void> _countPmChat(String id) async {
+ while (!_disposed) {
+ final chat = snapshot?.conversation(id);
+ if (chat == null || !_pmCountOpen(chat)) return;
+ final held = _messages[id];
+ final before = (held?.firstOrNull?.sequence, held?.lastOrNull?.sequence);
+ final newer =
+ held == null ||
+ held.isEmpty ||
+ held.last.sequence < chat.lastMessageSequence;
+ await _readMessages(id, older: !newer, light: newer);
+ final after = _messages[id];
+ if ((after?.firstOrNull?.sequence, after?.lastOrNull?.sequence) ==
+ before) {
+ return;
+ }
+ }
+ }
+
+ /// The project of the conversation on screen, else the first one.
+ String? get currentProjectId {
+ final state = snapshot;
+ if (state == null) return null;
+ final selected = state.conversation(selectedId)?.projectId;
+ return state.projects.any((p) => p.id == selected)
+ ? selected
+ : state.projects.firstOrNull?.id;
+ }
+
+ /// Set by the Swarm view on screen: opens a project's PM chat in front of
+ /// whatever covers the conversation, Notifications or a terminal.
+ Future<bool> Function(String projectId)? pmChatOpener;
+
+ /// Opens the [currentProjectId]'s PM chat, through the view on screen
+ /// ([pmChatOpener]) when there is one, else [openPmChat].
+ Future<bool> openCurrentPmChat() async {
+ final project = currentProjectId;
+ return project != null && await (pmChatOpener ?? openPmChat)(project);
+ }
+
/// Opens [pmChat], creating it on first use: chat only, for this person
/// alone, named after them, with the project's Lead in it. The create is one
/// fixed request per person, membership and project, so a second click or
@@ -706,7 +810,7 @@ class SuperTabController extends ChangeNotifier {
'type': 'conversation.create',
'projectId': projectId,
'title': email == null || email.isEmpty
- ? 'Chat with PM'
+ ? kChatWithPm
: superTabPersonName(email),
'brief': '',
'checks': <dynamic>[],
@@ -876,6 +980,9 @@ class SuperTabController extends ChangeNotifier {
}
}
lastChangedAt = parts.lastChangedAt;
+ // Every state read, a quiet one too: a count a failed read left open is
+ // finished; one that is known reads nothing.
+ _readUnreadPmChats();
_partsReadAt = clock.now();
error = null;
await (selectedId == earlyId && messagesRead != null
diff --git a/desktop/lib/super_tabs/machines.dart b/desktop/lib/super_tabs/machines.dart
index 05c10a744..8761b33df 100644
--- a/desktop/lib/super_tabs/machines.dart
+++ b/desktop/lib/super_tabs/machines.dart
@@ -988,7 +988,11 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
})
: null;
final value = direct ? sample?.$1 : observed;
+ // The name the person gave it in their own Machines list (Rename) wins
+ // over the one the Swarm recorded, often its hostname.
+ final given = app?.stateOf(id)?.machine.name;
final name =
+ (given == null || given.isEmpty ? null : given) ??
shared?['name'] as String? ??
app?.stateOf(id)?.machine.displayName ??
'Unavailable machine';
@@ -2068,12 +2072,17 @@ class _MachineLine extends StatelessWidget {
child: Row(
children: [
const SizedBox(width: 4),
+ // A machine reads as a home directory, "~ Diego's Mac", beside the
+ // sidebar's "# project" channels.
SizedBox(
width: 32,
- child: Icon(
- AppIcons.monitor,
- size: AppIcons.inlineSize,
- color: DesktopChrome.muted,
+ child: Text(
+ '~',
+ textAlign: TextAlign.center,
+ style: DesktopChrome.control(
+ color: DesktopChrome.muted,
+ medium: true,
+ ),
),
),
Expanded(
diff --git a/desktop/lib/super_tabs/notifications.dart b/desktop/lib/super_tabs/notifications.dart
index 625fa95ce..b3417d346 100644
--- a/desktop/lib/super_tabs/notifications.dart
+++ b/desktop/lib/super_tabs/notifications.dart
@@ -9,6 +9,7 @@ import '../widgets/desktop_chrome.dart';
import 'controller.dart';
import 'machine_status.dart' show superTabAgo;
import 'model.dart';
+import 'pm_chat.dart';
import 'section_heading.dart';
/// A Lead's tag of the reader in one message (spec 2026-10-24-lead-mentions.md).
@@ -226,7 +227,7 @@ class _SuperTabNotificationsState extends State<SuperTabNotifications> {
final place =
widget.mentions.controller.pmChat(mention.projectId)?.id ==
mention.conversationId
- ? 'Chat with PM'
+ ? kChatWithPm
: mention.conversationTitle;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 1),
diff --git a/desktop/lib/super_tabs/pm_chat.dart b/desktop/lib/super_tabs/pm_chat.dart
new file mode 100644
index 000000000..b11335f09
--- /dev/null
+++ b/desktop/lib/super_tabs/pm_chat.dart
@@ -0,0 +1,13 @@
+/// The visible name of a person's private chat with a project's Product
+/// Manager (docs/naming-system.md).
+const kChatWithPm = 'Chat with PM';
+
+/// How far a sidebar or tab count goes: from here on it says "99+".
+const kCountCap = 100;
+
+/// A count as a badge shows it: "7", or "99+" from [kCountCap] on.
+String countText(int count) =>
+ count >= kCountCap ? '${kCountCap - 1}+' : '$count';
+
+/// What a PM chat's unread count says: "2 new in Chat with PM".
+String pmUnreadLabel(int count) => '${countText(count)} new in $kChatWithPm';
diff --git a/desktop/lib/super_tabs/pm_chat_rows.dart b/desktop/lib/super_tabs/pm_chat_rows.dart
new file mode 100644
index 000000000..d9e6b6012
--- /dev/null
+++ b/desktop/lib/super_tabs/pm_chat_rows.dart
@@ -0,0 +1,182 @@
+import 'package:flutter/material.dart';
+
+import '../shared/theme/app_theme.dart' as grid;
+import '../widgets/desktop_chrome.dart';
+import 'identity.dart';
+import 'pm_chat.dart';
+import 'section_heading.dart';
+
+/// A sidebar count, such as the tags waiting in Notifications.
+class SuperTabCountBadge extends StatelessWidget {
+ const SuperTabCountBadge(this.count, {super.key});
+ final int count;
+
+ @override
+ Widget build(BuildContext context) => Container(
+ constraints: const BoxConstraints(minWidth: 18),
+ padding: const EdgeInsets.symmetric(horizontal: 5),
+ decoration: BoxDecoration(
+ color: grid.AppPalette.warn.withValues(alpha: .16),
+ borderRadius: BorderRadius.circular(9),
+ ),
+ child: Text(
+ countText(count),
+ textAlign: TextAlign.center,
+ style: DesktopChrome.metadata(color: grid.AppPalette.warn),
+ ),
+ );
+}
+
+/// A PM chat's unread count, "2 new in Chat with PM"; [onTap] opens the chat.
+class SuperTabPmUnread extends StatelessWidget {
+ const SuperTabPmUnread(this.count, {super.key, this.onTap});
+ final int count;
+ final VoidCallback? onTap;
+
+ @override
+ Widget build(BuildContext context) => Tooltip(
+ message: pmUnreadLabel(count),
+ child: Semantics(
+ button: onTap != null,
+ label: pmUnreadLabel(count),
+ excludeSemantics: true,
+ child: InkWell(
+ onTap: onTap,
+ borderRadius: BorderRadius.circular(9),
+ child: SuperTabCountBadge(count),
+ ),
+ ),
+ );
+}
+
+/// A person's Chat with PM as a direct message: the Product Manager's avatar
+/// and name, like a chat app's direct messages, with the project named after
+/// it when the Swarm has several.
+class SuperTabPmChatRow extends StatelessWidget {
+ const SuperTabPmChatRow({
+ super.key,
+ required this.agentId,
+ required this.name,
+ required this.onTap,
+ this.project,
+ this.selected = false,
+ this.unread = false,
+ this.unreadCount = 0,
+ });
+
+ /// The Product Manager's agent, for its avatar; null while it has none.
+ final String? agentId;
+ final String name;
+
+ /// The project's name, shown when the Swarm has several.
+ final String? project;
+ final bool selected, unread;
+ final int unreadCount;
+ final VoidCallback? onTap;
+
+ static const _column = SuperTabSectionHeading.actionWidth;
+ static const _dotSize = 6.0;
+
+ @override
+ Widget build(BuildContext context) {
+ final strong = selected || unread;
+ final color = onTap == null
+ ? DesktopChrome.muted
+ : DesktopChrome.foreground;
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 2),
+ child: Material(
+ color: selected ? grid.AppSurface.selectedFill : Colors.transparent,
+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),
+ clipBehavior: Clip.antiAlias,
+ child: Semantics(
+ button: true,
+ selected: selected,
+ child: InkWell(
+ onTap: onTap,
+ hoverColor: grid.AppSurface.hoverFill,
+ focusColor: grid.AppSurface.hoverFill,
+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),
+ child: Tooltip(
+ message: project == null
+ ? kChatWithPm
+ : '$kChatWithPm · $project',
+ child: Row(
+ children: [
+ SizedBox(width: SuperTabSectionHeading.indentFor(0)),
+ SizedBox(
+ width: _column,
+ child: Center(
+ child: SuperTabAvatar(
+ identity: agentId == null
+ ? 'pm:$name'
+ : 'agent:$agentId',
+ name: name,
+ size: 20,
+ ),
+ ),
+ ),
+ Expanded(
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 36),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8),
+ child: Row(
+ children: [
+ Flexible(
+ child: Text(
+ name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: DesktopChrome.control(
+ medium: strong,
+ color: color,
+ ),
+ ),
+ ),
+ if (project case final project?) ...[
+ const SizedBox(width: 8),
+ Flexible(
+ child: Text(
+ project,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: DesktopChrome.metadata(),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
+ SizedBox(
+ width: _column,
+ child: Center(
+ child: unreadCount > 0
+ ? SuperTabPmUnread(unreadCount)
+ : unread
+ ? Semantics(
+ label: 'Unread messages',
+ child: Container(
+ width: _dotSize,
+ height: _dotSize,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: DesktopChrome.accent,
+ ),
+ ),
+ )
+ : null,
+ ),
+ ),
+ const SizedBox(width: _column),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/desktop/lib/super_tabs/pm_chat_shortcut.dart b/desktop/lib/super_tabs/pm_chat_shortcut.dart
new file mode 100644
index 000000000..dd174988d
--- /dev/null
+++ b/desktop/lib/super_tabs/pm_chat_shortcut.dart
@@ -0,0 +1,11 @@
+import '../state/app_state.dart';
+
+/// The Chat with PM shortcut: the active Swarm tab's current project's chat
+/// ([SuperTabController.openCurrentPmChat]). False when the active tab is no
+/// Swarm tab, or its Swarm is not open here.
+Future<bool> openActivePmChat(AppNotifier app) async {
+ final id = app.activeSwarm.superTabId;
+ if (id == null) return false;
+ final controller = app.superTabs.peek(id);
+ return controller != null && await controller.openCurrentPmChat();
+}
diff --git a/desktop/lib/super_tabs/project_sidebar.dart b/desktop/lib/super_tabs/project_sidebar.dart
index 3aa03cee3..bb88dfcdc 100644
--- a/desktop/lib/super_tabs/project_sidebar.dart
+++ b/desktop/lib/super_tabs/project_sidebar.dart
@@ -14,7 +14,9 @@ import 'controller.dart';
import 'local_models.dart';
import 'machines.dart';
import 'model.dart';
+import 'pm_chat_rows.dart';
import 'section_heading.dart';
+import 'workgroup_name.dart';
class ProjectSidebar extends StatelessWidget {
const ProjectSidebar({
@@ -30,6 +32,7 @@ class ProjectSidebar extends StatelessWidget {
this.onNotifications,
this.notificationsSelected = false,
this.onOpenAgent,
+ this.onOpenPmChat,
this.readLocal,
this.now = DateTime.now,
});
@@ -47,6 +50,10 @@ class ProjectSidebar extends StatelessWidget {
final bool notificationsSelected;
final ValueChanged<SuperTabAgent>? onOpenAgent;
+ /// Opens a project's Chat with PM, by project id; the controller's
+ /// [SuperTabController.openPmChat] when not given.
+ final ValueChanged<String>? onOpenPmChat;
+
/// Forwarded to the embedded [SuperTabMachines]; a test gives it to have
/// the Machines group's readings taken without a real machine.
@visibleForTesting
@@ -118,21 +125,7 @@ class ProjectSidebar extends StatelessWidget {
if (badge > 0)
Padding(
padding: const EdgeInsets.only(right: 10),
- child: Container(
- constraints: const BoxConstraints(minWidth: 18),
- padding: const EdgeInsets.symmetric(horizontal: 5),
- decoration: BoxDecoration(
- color: grid.AppPalette.warn.withValues(alpha: .16),
- borderRadius: BorderRadius.circular(9),
- ),
- child: Text(
- '$badge',
- textAlign: TextAlign.center,
- style: DesktopChrome.metadata(
- color: grid.AppPalette.warn,
- ),
- ),
- ),
+ child: SuperTabCountBadge(badge),
),
],
),
@@ -141,6 +134,17 @@ class ProjectSidebar extends StatelessWidget {
),
);
+ /// A project reads as a channel: "# openharness".
+ Widget _channelMark() => Text(
+ '#',
+ textAlign: TextAlign.center,
+ style: DesktopChrome.control(color: DesktopChrome.muted, medium: true),
+ );
+
+ void _openPmChat(String projectId) => onOpenPmChat != null
+ ? onOpenPmChat!(projectId)
+ : unawaited(controller.openPmChat(projectId));
+
/// Project names open their PM chat; only the trailing control expands them.
Widget _row(
SuperTabConversation group, {
@@ -159,9 +163,21 @@ class ProjectSidebar extends StatelessWidget {
(g) => g.projectId == project.id && !g.closed,
);
final waiting = groups.any((g) => needsHuman(g) > 0);
- final unread = groups.any(controller.unread);
+ // A project's PM chat shows its own count rather than the dot.
+ final pmChat = project == null ? null : controller.pmChat(project.id);
+ final projectPmUnread = pmChat == null ? 0 : controller.unreadCount(pmChat);
+ final unread = groups.any(
+ (g) =>
+ controller.unread(g) && (projectPmUnread == 0 || g.id != pmChat?.id),
+ );
final expanded =
project != null && controller.expandedProjects.contains(project.id);
+ final style = DesktopChrome.control(
+ medium: unread || selected,
+ color: selected || unread || project != null || label != null
+ ? DesktopChrome.foreground
+ : DesktopChrome.muted,
+ );
return Padding(
padding: const EdgeInsets.only(bottom: 2),
child: Material(
@@ -179,11 +195,12 @@ class ProjectSidebar extends StatelessWidget {
SizedBox(width: SuperTabSectionHeading.indentFor(0)),
SizedBox(
width: _iconColumn,
- child: project == null && icon == null
+ child: project != null
+ ? _channelMark()
+ : icon == null
? null
: Icon(
- icon ??
- (expanded ? AppIcons.folderOpen : AppIcons.folder),
+ icon,
size: AppIcons.inlineSize,
color: DesktopChrome.muted,
),
@@ -193,7 +210,10 @@ class ProjectSidebar extends StatelessWidget {
label: project?.isPrivate == true ? 'Private project' : null,
selected: selected,
child: Tooltip(
- message: label ?? project?.name ?? group.label,
+ message:
+ label ??
+ project?.name ??
+ SuperTabWorkgroupName.plain(group),
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 36),
child: Padding(
@@ -201,21 +221,14 @@ class ProjectSidebar extends StatelessWidget {
child: Row(
children: [
Expanded(
- child: Text(
- label ?? project?.name ?? group.label,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: DesktopChrome.control(
- medium: unread || selected,
- color:
- selected ||
- unread ||
- project != null ||
- label != null
- ? DesktopChrome.foreground
- : DesktopChrome.muted,
- ),
- ),
+ child: label == null && project == null
+ ? SuperTabWorkgroupName(group, style: style)
+ : Text(
+ label ?? project!.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: style,
+ ),
),
if (project?.isPrivate == true) ...[
const SizedBox(width: 8),
@@ -235,6 +248,15 @@ class ProjectSidebar extends StatelessWidget {
),
),
),
+ if (projectPmUnread > 0)
+ Padding(
+ padding: const EdgeInsets.only(left: 4),
+ child: SuperTabPmUnread(
+ projectPmUnread,
+ key: ValueKey('super-project-pm-unread-${project!.id}'),
+ onTap: () => _openPmChat(project.id),
+ ),
+ ),
SizedBox(
width: _iconColumn,
child: Center(
@@ -371,22 +393,38 @@ class ProjectSidebar extends StatelessWidget {
];
}
- /// The signed-in person's private chat with the project's Product Manager,
- /// above its workgroups; the first click opens it.
- Widget? _pmChat(SuperTabProject project) {
- const label = 'Chat with PM';
- final key = 'super-pm-chat-${project.id}';
- if (controller.pmChat(project.id) case final chat?) {
- return _row(chat, label: label, icon: AppIcons.messageSquare, key: key);
- }
- if (!controller.canWrite) return null;
- return _navigationRow(
- key: key,
- label: label,
- icon: AppIcons.messageSquare,
- onTap: controller.saving || controller.hasPendingAction
+ /// The signed-in person's private chat with each project's Product
+ /// Manager, as direct messages pinned above the projects so a collapsed
+ /// project never hides them; the first click opens one.
+ List<Widget> _pmChats(List<SuperTabProject> projects) => [
+ for (final project in projects)
+ ?_pmChat(project, named: projects.length > 1),
+ ];
+
+ Widget? _pmChat(SuperTabProject project, {required bool named}) {
+ final snapshot = controller.snapshot!;
+ final pmId = snapshot.conversation(project.leadConversationId)?.leadId;
+ final chat = controller.pmChat(project.id);
+ if (chat == null && !controller.canWrite) return null;
+ return SuperTabPmChatRow(
+ key: ValueKey('super-pm-chat-${project.id}'),
+ agentId: pmId,
+ name: pmId == null
+ ? 'Product Manager'
+ : snapshot.agentName(pmId, fallback: 'Product Manager'),
+ project: named ? project.name : null,
+ selected:
+ chat != null &&
+ !devicesSelected &&
+ !notificationsSelected &&
+ controller.selectedId == chat.id,
+ unread: chat != null && controller.unread(chat),
+ unreadCount: chat == null ? 0 : controller.unreadCount(chat),
+ onTap: chat != null
+ ? () => onSelect(chat.id)
+ : controller.saving || controller.hasPendingAction
? null
- : () => unawaited(controller.openPmChat(project.id)),
+ : () => _openPmChat(project.id),
);
}
@@ -423,11 +461,21 @@ class ProjectSidebar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final snapshot = controller.snapshot;
+ final pmChats = _pmChats(snapshot?.projects ?? const []);
return Material(
color: DesktopChrome.surface,
child: ListView(
padding: const EdgeInsets.all(8),
children: [
+ if (pmChats.isNotEmpty) ...[
+ SuperTabSectionHeading(
+ 'Direct messages',
+ endInset: 0,
+ startInset: SuperTabSectionHeading.indentFor(0),
+ ),
+ ...pmChats,
+ const SizedBox(height: 16),
+ ],
if (onNewProject != null)
_navigationRow(
key: 'super-new-project',
@@ -492,7 +540,6 @@ class ProjectSidebar extends StatelessWidget {
children: [
_row(lead, project: project),
if (controller.expandedProjects.contains(project.id)) ...[
- ?_pmChat(project),
..._workgroups(project),
..._closed(project),
],
diff --git a/desktop/lib/super_tabs/section_heading.dart b/desktop/lib/super_tabs/section_heading.dart
index 129ea94d0..658adb56a 100644
--- a/desktop/lib/super_tabs/section_heading.dart
+++ b/desktop/lib/super_tabs/section_heading.dart
@@ -15,6 +15,7 @@ class SuperTabSectionHeading extends StatelessWidget {
this.trailing,
this.actions = const [],
this.endInset = 12,
+ this.startInset,
this.collapsed,
this.onToggleCollapsed,
});
@@ -34,6 +35,11 @@ class SuperTabSectionHeading extends StatelessWidget {
/// with its rows' trailing disclosure controls.
final double endInset;
+ /// The space before the title; a collapsible heading's own inset when not
+ /// given, else 16. The left sidebar passes [indentFor] 0 for a heading that
+ /// does not collapse, to align it with the ones that do.
+ final double? startInset;
+
/// Whether a collapsible group's body is currently hidden. Ignored unless
/// [onToggleCollapsed] is set.
final bool? collapsed;
@@ -67,7 +73,7 @@ class SuperTabSectionHeading extends StatelessWidget {
final addWidth = phone ? kFingerTarget : actionWidth;
return Padding(
padding: EdgeInsets.fromLTRB(
- collapsible ? _leadingInset : 16,
+ startInset ?? (collapsible ? _leadingInset : 16),
0,
endInset,
4,
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index 49007a0dc..788ccba4f 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -20,6 +20,8 @@ import 'pull_requests.dart';
import 'controller.dart';
import 'dialog_scope.dart';
import 'model.dart';
+import 'pm_chat.dart';
+import 'workgroup_name.dart';
import 'message_row.dart';
import 'message_receipt.dart';
import 'notifications.dart';
@@ -127,6 +129,7 @@ class _SuperTabViewState extends State<SuperTabView>
WidgetsBinding.instance.addObserver(this);
_composer.addListener(_composerMoved);
c.addListener(_changed);
+ c.pmChatOpener = _openPmChat;
_registerDial();
_changed();
}
@@ -154,7 +157,11 @@ class _SuperTabViewState extends State<SuperTabView>
}
if (oldWidget.controller != c) {
oldWidget.controller.removeListener(_changed);
+ if (oldWidget.controller.pmChatOpener == _openPmChat) {
+ oldWidget.controller.pmChatOpener = null;
+ }
c.addListener(_changed);
+ c.pmChatOpener = _openPmChat;
for (final scroll in _scroll.values) {
scroll.dispose();
}
@@ -318,6 +325,7 @@ class _SuperTabViewState extends State<SuperTabView>
void dispose() {
WidgetsBinding.instance.removeObserver(this);
c.removeListener(_changed);
+ if (c.pmChatOpener == _openPmChat) c.pmChatOpener = null;
_unregisterDial?.call();
_dial.cancel();
_composer.dispose();
@@ -784,8 +792,21 @@ class _SuperTabViewState extends State<SuperTabView>
c.select(id);
_closeSidebar();
},
+ onOpenPmChat: (projectId) => unawaited(_openPmChat(projectId)),
);
+ /// Opens [projectId]'s PM chat in front of Notifications, pull requests and
+ /// a terminal: the sidebar's way in and ⇧⌘K's ([SuperTabController.pmChatOpener]).
+ Future<bool> _openPmChat(String projectId) {
+ setState(() {
+ _showNotifications = false;
+ _showPullRequests = false;
+ });
+ widget.onCloseTerminal?.call();
+ _closeSidebar();
+ return c.openPmChat(projectId);
+ }
+
bool get _notificationsVisible =>
_showNotifications && !_devicesVisible && !c.accessRevoked;
@@ -894,9 +915,11 @@ class _SuperTabViewState extends State<SuperTabView>
bool _isPmChat(SuperTabConversation group) =>
c.pmChat(group.projectId)?.id == group.id;
- /// The open conversation's name, or what the pane shows instead of one.
- Widget _title(SuperTabConversation? group) => Text(
- _devicesVisible
+ /// The open conversation's name, or what the pane shows instead of one. A
+ /// workgroup's is named as the sidebar names it ([SuperTabWorkgroupName]).
+ Widget _title(SuperTabConversation? group) {
+ final style = DesktopChrome.text(medium: true);
+ final name = _devicesVisible
? 'Your devices'
: _notificationsVisible
? 'Notifications'
@@ -909,12 +932,16 @@ class _SuperTabViewState extends State<SuperTabView>
: group.id == c.snapshot!.leadsConversationId
? 'Product Managers'
: _isPmChat(group)
- ? 'Chat with PM'
- : group.label,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: DesktopChrome.text(medium: true),
- );
+ ? kChatWithPm
+ : null;
+ if (name == null) return SuperTabWorkgroupName(group!, style: style);
+ return Text(
+ name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: style,
+ );
+ }
/// On a phone the header's bar holds Chat and ⋮, each a finger's size, and
/// ⋮ names the rest (terminals, pull requests, people) instead of five bare
diff --git a/desktop/lib/super_tabs/workgroup_name.dart b/desktop/lib/super_tabs/workgroup_name.dart
new file mode 100644
index 000000000..578365756
--- /dev/null
+++ b/desktop/lib/super_tabs/workgroup_name.dart
@@ -0,0 +1,34 @@
+import 'package:flutter/material.dart';
+
+import '../widgets/desktop_chrome.dart';
+import 'model.dart';
+
+/// A workgroup's name as the Swarm shows it, in the sidebar and the chat
+/// header alike: its number in grey and no #, so it does not read as a
+/// "# project" channel, then its title ("196 Regression…").
+class SuperTabWorkgroupName extends StatelessWidget {
+ const SuperTabWorkgroupName(this.group, {super.key, required this.style});
+ final SuperTabConversation group;
+ final TextStyle style;
+
+ /// The same name as plain text, for a tooltip.
+ static String plain(SuperTabConversation group) =>
+ [?group.number, group.title].join(' ');
+
+ @override
+ Widget build(BuildContext context) => Text.rich(
+ TextSpan(
+ children: [
+ if (group.number case final number?)
+ TextSpan(
+ text: '$number ',
+ style: style.copyWith(color: DesktopChrome.muted),
+ ),
+ TextSpan(text: group.title),
+ ],
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: style,
+ );
+}
diff --git a/desktop/lib/web/tabs/web_tab_menu.dart b/desktop/lib/web/tabs/web_tab_menu.dart
index b3566e55e..d844d6283 100644
--- a/desktop/lib/web/tabs/web_tab_menu.dart
+++ b/desktop/lib/web/tabs/web_tab_menu.dart
@@ -143,9 +143,8 @@ List<Widget> webTabMenuRows(
content: PaneMenuRow(
selected: tab.id == app.activeSwarmId,
title: '${index + 1}:${names[tab.id] ?? tab.name}',
- status: tabMentionsWaiting(app, tab) > 0
- ? tabMentionsLabel(tabMentionsWaiting(app, tab))
- : _statusLabel(tabActivity(app, tab)),
+ status:
+ tabWaitingLabel(app, tab) ?? _statusLabel(tabActivity(app, tab)),
),
),
// This tab's sharing with other accounts (1c) and its Agent Messages, as
diff --git a/desktop/lib/web/tabs/web_tab_switcher.dart b/desktop/lib/web/tabs/web_tab_switcher.dart
index 2b778b50d..c09bd2eb0 100644
--- a/desktop/lib/web/tabs/web_tab_switcher.dart
+++ b/desktop/lib/web/tabs/web_tab_switcher.dart
@@ -9,6 +9,7 @@ import '../../state/app_state.dart';
import '../../state/harness_activity.dart';
import '../../state/workspace_chrome.dart';
import '../../state/workspace_status.dart';
+import '../../super_tabs/pm_chat.dart' show countText;
import '../../terminal/terminal_theme.dart';
import '../../terminal/terminal_theme_store.dart';
import '../../widgets/finger_target.dart';
@@ -37,7 +38,7 @@ class WebTabSwitcher extends StatelessWidget {
final index = app.swarms.indexWhere((tab) => tab.id == app.activeSwarmId);
final name = workspaceTabNames(app)[app.activeSwarmId] ?? '';
final activity = tabActivity(app, app.activeSwarm);
- final tags = tabMentionsWaiting(app, app.activeSwarm);
+ final tags = tabWaiting(app, app.activeSwarm);
final panes = app.panes;
final shown = panes.indexWhere((pane) => pane.id == soloPaneId(app));
final label = [
@@ -45,7 +46,7 @@ class WebTabSwitcher extends StatelessWidget {
// Which of the tab's harnesses is on screen: a phone draws one.
if (panes.length > 1) '· ${shown + 1}/${panes.length}',
if (tags > 0)
- '$tags'
+ countText(tags)
else if (activity?.mark.isNotEmpty == true)
activity!.mark,
].join(' ');
diff --git a/desktop/test/keymap_host_test.dart b/desktop/test/keymap_host_test.dart
index 186d0e88d..bc0ad9a59 100644
--- a/desktop/test/keymap_host_test.dart
+++ b/desktop/test/keymap_host_test.dart
@@ -365,6 +365,8 @@ void main() {
('cmd+w', 'swarm.close'),
('cmd+shift+w', 'pane.close'),
('ctrl+tab', 'swarm.next'),
+ // Move Pane Up until it was retired; Chat with PM since.
+ ('cmd+shift+k', 'swarm.chat_with_pm'),
]) {
expect(command(keys), expected, reason: keys);
}
@@ -381,7 +383,7 @@ void main() {
final id = command(stroke.toString());
expect(harnessCommandById[id]?.action, shortcut.action);
}
- for (final retired in ['cmd+shift+h', 'cmd+shift+k', 'cmd+u', 'cmd+y']) {
+ for (final retired in ['cmd+shift+h', 'cmd+u', 'cmd+y']) {
expect(command(retired), isNull, reason: retired);
}
// ⌥⌘←/→ walk tabs, as in Safari and Chrome; ⇧⌘[ ] no longer do.
diff --git a/desktop/test/super_tab_machine_freshness_test.dart b/desktop/test/super_tab_machine_freshness_test.dart
index 94c84f875..198c77525 100644
--- a/desktop/test/super_tab_machine_freshness_test.dart
+++ b/desktop/test/super_tab_machine_freshness_test.dart
@@ -240,7 +240,7 @@ void main() {
expect(tipOf(tester, 'm'), tip);
expect(labelOf(tester, 'm'), 'Studio Mac, Live, $tip');
// Collapsed: name and owner avatar, with readings reserved for disclosure.
- expect(textsOf('m'), ['Studio Mac', 'O']);
+ expect(textsOf('m'), ['~', 'Studio Mac', 'O']);
expect(nameInkOf(tester, 'm'), isNot(DesktopChrome.muted));
expect(find.byType(SuperTabMachinesPill), findsNothing);
@@ -264,7 +264,7 @@ void main() {
labelOf(tester, 'm'),
startsWith('Studio Mac, Late, Owned by owner'),
);
- expect(textsOf('m'), ['Studio Mac', 'O']);
+ expect(textsOf('m'), ['~', 'Studio Mac', 'O']);
semantics.dispose();
await tester.pumpWidget(const SizedBox());
@@ -318,7 +318,7 @@ void main() {
const tip = 'Offline · Owned by owner';
expect(tipOf(tester, 'm'), tip);
expect(labelOf(tester, 'm'), 'Studio Mac, Offline, $tip');
- expect(textsOf('m'), ['Studio Mac', 'O']);
+ expect(textsOf('m'), ['~', 'Studio Mac', 'O']);
expect(find.byType(SuperTabMachinesPill), findsNothing);
// Opened, it stays open: saved with the Swarm's other sidebar state.
@@ -429,7 +429,7 @@ void main() {
const tip = 'Refreshing… · Owned by owner';
expect(tipOf(tester, 'far'), tip);
expect(labelOf(tester, 'far'), 'Far Mac, Refreshing, $tip');
- expect(textsOf('far'), ['Far Mac', 'O']);
+ expect(textsOf('far'), ['~', 'Far Mac', 'O']);
gate.complete();
await landed(tester);
diff --git a/desktop/test/super_tab_pm_chat_pinned_test.dart b/desktop/test/super_tab_pm_chat_pinned_test.dart
new file mode 100644
index 000000000..a007d264c
--- /dev/null
+++ b/desktop/test/super_tab_pm_chat_pinned_test.dart
@@ -0,0 +1,873 @@
+import 'dart:io';
+import 'dart:ui' as ui;
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/shared/theme/app_icons.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/shortcuts/app_keymap.dart';
+import 'package:harness/shortcuts/keyboard_practice.dart';
+import 'package:harness/shortcuts/keymap.dart';
+import 'package:harness/shortcuts/keymap_commands.dart';
+import 'package:harness/shortcuts/keymap_edit.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/harness_activity.dart';
+import 'package:harness/super_tabs/controller.dart';
+import 'package:harness/super_tabs/identity.dart';
+import 'package:harness/super_tabs/machines.dart';
+import 'package:harness/super_tabs/pm_chat.dart';
+import 'package:harness/super_tabs/pm_chat_shortcut.dart';
+import 'package:harness/super_tabs/project_sidebar.dart';
+import 'package:harness/super_tabs/view.dart';
+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/pm_chat_fixture.dart';
+import 'support/super_tab_fixture.dart';
+
+/// Set to a folder to write the PR's screenshots there.
+final shots = Platform.environment['SUPER_TAB_PM_CHAT_SHOTS'];
+
+/// Chat with PM pinned at the top of the Swarm sidebar, with its unread count
+/// on the row, the project and the Swarm tab, and a shortcut that opens it.
+void main() {
+ setUpAll(() async {
+ if (shots != null) await loadPreviewFonts();
+ });
+
+ /// [account]'s controller with their PM chat opened once and then left for
+ /// a workgroup, so the Product Manager's replies arrive unread.
+ Future<(SuperTabController, String)> awayFromChat(
+ ConversationServer server, {
+ String account = 'peer',
+ }) async {
+ final c = server.controller(account: account);
+ addTearDown(c.dispose);
+ await c.refresh();
+ await c.openPmChat('lead');
+ final chat = c.pmChat('lead')!.id;
+ await c.select('offline');
+ await pumpEventQueue();
+ return (c, chat);
+ }
+
+ /// A second project, Mobile, whose Product Manager is Wren.
+ void secondProject(ConversationServer server) {
+ server.state['projects'] = [
+ projectFixture('lead', 'Pilot', 'lead'),
+ projectFixture('mobile', 'Mobile', 'mobile-lead'),
+ ];
+ (server.state['agents'] as List).add({
+ 'id': 'mobile-pm',
+ 'name': 'Lead',
+ 'displayName': 'Wren',
+ 'machineId': 'm1',
+ 'harnessId': 'h2',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude', 'model': 'opus'},
+ });
+ (server.state['conversations'] as List).add({
+ ...conversationFixture('mobile-lead', 'Lead'),
+ 'projectId': 'mobile',
+ 'leadId': 'mobile-pm',
+ 'agentIds': ['mobile-pm'],
+ });
+ }
+
+ /// [pmChatSwarm] with its Product Manager called River.
+ ConversationServer riverSwarm() {
+ final server = pmChatSwarm();
+ (server.state['agents'] as List).first['displayName'] = 'River';
+ return server;
+ }
+
+ group('the unread count', () {
+ test("counts the Product Manager's new messages", () async {
+ final server = pmChatSwarm();
+ final (c, chat) = await awayFromChat(server);
+
+ pmReply(server, chat, 'Here is the plan.');
+ pmReply(server, chat, 'The build is green.');
+ pmReply(server, chat, 'Shall I ship it?');
+ await c.refresh();
+ await pumpEventQueue();
+
+ expect(c.unreadCount(c.pmChat('lead')!), 3);
+ expect(c.pmUnread, 3);
+ });
+
+ test('ignores the reader\'s own messages and clears once read', () async {
+ final server = pmChatSwarm();
+ final (c, chat) = await awayFromChat(server);
+ pmReply(server, chat, 'Here is the plan.');
+ server.append('Sent from my phone', conversationId: chat);
+ server.messages.last['author'] = {
+ 'kind': 'person',
+ 'id': 'peer',
+ 'name': '[email protected]',
+ };
+ await c.refresh();
+ await pumpEventQueue();
+ expect(c.unreadCount(c.pmChat('lead')!), 1);
+
+ await c.select(chat);
+ await pumpEventQueue();
+ c.markRead(chat);
+
+ expect(c.unreadCount(c.pmChat('lead')!), 0);
+ expect(c.pmUnread, 0);
+ });
+
+ test(
+ 'reads only a PM chat with news, and nothing when nothing changed',
+ () async {
+ final server = pmChatSwarm();
+ final (c, chat) = await awayFromChat(server);
+ final reads = <String>[];
+ server.onRead = reads.add;
+ bool readOf(String path, String id) =>
+ path.contains('/conversations/$id/');
+
+ pmReply(server, chat, 'Here is the plan.');
+ server.append('A note in the project', conversationId: 'lead');
+ await c.refresh();
+ await pumpEventQueue();
+ expect(reads.where((p) => readOf(p, chat)), hasLength(1));
+ expect(reads.where((p) => readOf(p, 'lead')), isEmpty);
+
+ reads.clear();
+ await c.refresh();
+ await pumpEventQueue();
+ expect(reads.where((p) => readOf(p, chat)), isEmpty);
+ },
+ );
+
+ test("never counts another person's chat, the owner's included", () async {
+ final server = pmChatSwarm();
+ final (_, peerChat) = await awayFromChat(server);
+ final owner = server.controller(account: 'owner');
+ addTearDown(owner.dispose);
+ await owner.refresh();
+ final reads = <String>[];
+ server.onRead = reads.add;
+
+ pmReply(server, peerChat, 'Only for Ken.');
+ await owner.refresh();
+ await pumpEventQueue();
+
+ expect(owner.pmUnread, 0);
+ expect(reads.where((p) => p.contains(peerChat)), isEmpty);
+ });
+ });
+
+ 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.
+ Future<(SuperTabController, String)> readOnce(
+ ConversationServer server, {
+ int page = 10,
+ }) async {
+ server.messagePage = page;
+ final (c, chat) = await awayFromChat(server);
+ pmReply(server, chat, 'Earlier, already read.');
+ await c.refresh();
+ await c.select(chat);
+ await pumpEventQueue(times: 100);
+ c.markRead(chat);
+ await c.select('offline');
+ return (c, chat);
+ }
+
+ List<String> readsOf(ConversationServer server, String chat) {
+ final reads = <String>[];
+ server.onRead = (path) {
+ if (path.contains('/conversations/$chat/')) reads.add(path);
+ };
+ return reads;
+ }
+
+ test('counts every unread message of a chat not held yet, then reads nothing more', () async {
+ final server = pmChatSwarm();
+ final (c, chat) = await readOnce(server);
+ for (var i = 1; i <= 25; i++) {
+ pmReply(server, chat, 'Update $i');
+ }
+ await c.flush();
+ // Another window: the same read mark, no messages held.
+ final fresh = server.controller(account: 'peer', initial: server.saved);
+ addTearDown(fresh.dispose);
+ final reads = readsOf(server, chat);
+
+ await fresh.refresh();
+ await pumpEventQueue(times: 100);
+ expect(fresh.unreadCount(fresh.pmChat('lead')!), 25);
+ expect(reads, hasLength(3));
+
+ reads.clear();
+ await fresh.refresh();
+ await pumpEventQueue(times: 100);
+ expect(fresh.unreadCount(fresh.pmChat('lead')!), 25);
+ expect(reads, isEmpty);
+ });
+
+ test(
+ 'counts a burst of new messages past a page, then reads nothing more',
+ () async {
+ final server = pmChatSwarm();
+ final (c, chat) = await readOnce(server);
+ final reads = readsOf(server, chat);
+ for (var i = 1; i <= 25; i++) {
+ pmReply(server, chat, 'Update $i');
+ }
+
+ await c.refresh();
+ await pumpEventQueue(times: 100);
+ expect(c.unreadCount(c.pmChat('lead')!), 25);
+ expect(reads, hasLength(3));
+
+ reads.clear();
+ await c.refresh();
+ await pumpEventQueue(times: 100);
+ expect(reads, isEmpty);
+ },
+ );
+
+ test('stops at 99+ rather than reading a whole history it has no read mark for', () async {
+ final server = pmChatSwarm();
+ server.messagePage = 10;
+ final (c, chat) = await awayFromChat(server);
+ for (var i = 1; i <= 150; i++) {
+ pmReply(server, chat, 'Update $i');
+ }
+ await c.flush();
+ final fresh = server.controller(account: 'peer');
+ addTearDown(fresh.dispose);
+ final reads = readsOf(server, chat);
+
+ await fresh.refresh();
+ await pumpEventQueue(times: 200);
+ final count = fresh.unreadCount(fresh.pmChat('lead')!);
+ expect(count, greaterThanOrEqualTo(100));
+ expect(pmUnreadLabel(count), '99+ new in Chat with PM');
+ expect(reads, hasLength(10));
+
+ reads.clear();
+ await fresh.refresh();
+ await pumpEventQueue(times: 100);
+ expect(reads, isEmpty);
+ });
+ });
+
+ group('the current project', () {
+ test("is the selected conversation's, else the first", () async {
+ final server = pmChatSwarm();
+ secondProject(server);
+ final c = server.controller(account: 'peer');
+ addTearDown(c.dispose);
+ await c.refresh();
+ // The Product Managers' conversation belongs to no project.
+ await c.select('offline');
+ expect(c.currentProjectId, 'lead');
+ await c.select('mobile-lead');
+ expect(c.currentProjectId, 'mobile');
+ });
+
+ test('opening its chat creates and selects it', () async {
+ final server = pmChatSwarm();
+ secondProject(server);
+ final c = server.controller(account: 'peer');
+ addTearDown(c.dispose);
+ await c.refresh();
+ await c.select('mobile-lead');
+
+ expect(await c.openCurrentPmChat(), isTrue);
+
+ expect(c.selectedId, c.pmChat('mobile')!.id);
+ expect(c.pmChat('lead'), isNull);
+ });
+ });
+
+ group('the sidebar', () {
+ Future<SuperTabController> show(
+ WidgetTester tester,
+ ConversationServer server, {
+ String account = 'peer',
+ }) async {
+ await tester.binding.setSurfaceSize(const Size(1280, 800));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ final c = server.controller(account: account);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.light),
+ home: Scaffold(
+ body: SuperTabView(
+ controller: c,
+ onInvite: () {},
+ onAddAgent: (_) {},
+ onOpenTerminal: (_) {},
+ machineName: (_) => 'Team Mac',
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ return c;
+ }
+
+ Future<void> close(WidgetTester tester, SuperTabController c) async {
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ }
+
+ final entry = find.byKey(const ValueKey('super-pm-chat-lead'));
+ final sidebar = find.byType(ProjectSidebar);
+ final projectRow = find.byKey(const ValueKey('super-group-lead'));
+
+ testWidgets(
+ 'pins Chat with PM as a direct message above the projects, shown with the project and the list collapsed',
+ (tester) async {
+ final c = await show(tester, riverSwarm());
+ expect(c.expandedProjects, isNot(contains('lead')));
+ // Listed by the Product Manager's name and avatar, like a direct message.
+ expect(
+ find.descendant(of: entry, matching: find.text('River')),
+ findsOne,
+ );
+ expect(
+ find.descendant(of: entry, matching: find.byType(SuperTabAvatar)),
+ findsOne,
+ );
+ expect(
+ find.descendant(of: entry, matching: find.byTooltip('Chat with PM')),
+ findsOne,
+ );
+ expect(
+ tester.getTopLeft(find.text('Direct messages')).dy,
+ lessThan(tester.getTopLeft(entry).dy),
+ );
+ expect(
+ tester.getTopLeft(find.text('Direct messages')).dx,
+ tester.getTopLeft(find.text('Projects')).dx,
+ );
+ expect(
+ tester.getTopLeft(entry).dy,
+ lessThan(tester.getTopLeft(find.text('Projects')).dy),
+ );
+
+ c.toggleProjectsGroup();
+ await tester.pumpAndSettle();
+ expect(c.projectsGroupOpen, isFalse);
+ expect(entry, findsOneWidget);
+
+ // Opening the project does not list it a second time.
+ c.toggleProjectsGroup();
+ c.toggleProject('lead');
+ await tester.pumpAndSettle();
+ expect(
+ find.descendant(of: sidebar, matching: find.text('River')),
+ findsOneWidget,
+ );
+ await close(tester, c);
+ },
+ );
+
+ testWidgets(
+ 'lists projects as channels: a # before the name, open or not',
+ (tester) async {
+ final c = await show(tester, riverSwarm());
+ expect(
+ find.descendant(of: projectRow, matching: find.text('#')),
+ findsOne,
+ );
+ expect(
+ find.descendant(
+ of: projectRow,
+ matching: find.byIcon(AppIcons.folder),
+ ),
+ findsNothing,
+ );
+ c.toggleProject('lead');
+ await tester.pumpAndSettle();
+ expect(
+ find.descendant(of: projectRow, matching: find.text('#')),
+ findsOne,
+ );
+ expect(
+ find.descendant(
+ of: projectRow,
+ matching: find.byIcon(AppIcons.folderOpen),
+ ),
+ findsNothing,
+ );
+ await close(tester, c);
+ },
+ );
+
+ testWidgets('shows a workgroup by its number in grey, with no #', (
+ tester,
+ ) async {
+ final server = riverSwarm();
+ (server.state['conversations'] as List).last['number'] = 196;
+ final c = await show(tester, server);
+ c.toggleProject('lead');
+ await tester.pumpAndSettle();
+ final row = find.byKey(const ValueKey('super-group-offline'));
+ final name = find.descendant(
+ of: row,
+ matching: find.text('196 Offline editing'),
+ );
+ expect(name, findsOne);
+ expect(
+ find.descendant(of: row, matching: find.textContaining('#')),
+ findsNothing,
+ );
+ final number =
+ (tester.widget<Text>(name).textSpan! as TextSpan).children!.first;
+ expect(number.toPlainText(), '196 ');
+ expect(number.style?.color, DesktopChrome.muted);
+ await close(tester, c);
+ });
+
+ testWidgets(
+ 'the shortcut leaves Notifications for the chat, first opened or already selected',
+ (tester) async {
+ final c = await show(tester, riverSwarm());
+ Future<void> shortcutOverNotifications() async {
+ await tester.tap(find.byKey(const ValueKey('super-notifications')));
+ await tester.pumpAndSettle();
+ expect(find.text('Message Product Manager'), findsNothing);
+ // What ⇧⌘K runs (openActivePmChat).
+ expect(await c.openCurrentPmChat(), isTrue);
+ await tester.pumpAndSettle();
+ expect(c.selectedId, c.pmChat('lead')?.id);
+ expect(find.text('Message Product Manager'), findsOneWidget);
+ }
+
+ await shortcutOverNotifications();
+ await shortcutOverNotifications();
+ await close(tester, c);
+ },
+ );
+
+ testWidgets(
+ 'the header names a workgroup as the sidebar does: its number in grey, no #',
+ (tester) async {
+ final server = riverSwarm();
+ (server.state['conversations'] as List).last['number'] = 196;
+ final c = await show(tester, server);
+ await c.select('offline');
+ await tester.pumpAndSettle();
+
+ expect(find.text('#196 Offline editing'), findsNothing);
+ final names = find.text('196 Offline editing');
+ // The header's and the sidebar row's.
+ expect(names, findsNWidgets(2));
+ for (final name in tester.widgetList<Text>(names)) {
+ final number = (name.textSpan! as TextSpan).children!.first;
+ expect(number.style?.color, DesktopChrome.muted);
+ }
+ await close(tester, c);
+ },
+ );
+
+ testWidgets('names the Product Manager role while a project has none', (
+ tester,
+ ) async {
+ final c = await show(tester, ConversationServer(), account: 'owner');
+ expect(
+ find.descendant(of: entry, matching: find.text('Product Manager')),
+ findsOne,
+ );
+ await close(tester, c);
+ });
+
+ testWidgets('the first open leaves Notifications for the new chat', (
+ tester,
+ ) async {
+ final c = await show(tester, pmChatSwarm());
+ await tester.tap(find.byKey(const ValueKey('super-notifications')));
+ await tester.pumpAndSettle();
+ expect(find.text('Message Product Manager'), findsNothing);
+
+ await tester.tap(entry);
+ await tester.pumpAndSettle();
+
+ expect(c.selectedId, c.pmChat('lead')!.id);
+ expect(find.text('Message Product Manager'), findsOneWidget);
+ await close(tester, c);
+ });
+
+ testWidgets('has one row per project, with its project named', (
+ tester,
+ ) async {
+ final server = riverSwarm();
+ secondProject(server);
+ final c = await show(tester, server);
+ final mobile = find.byKey(const ValueKey('super-pm-chat-mobile'));
+
+ for (final (row, pm, project) in [
+ (entry, 'River', 'Pilot'),
+ (mobile, 'Wren', 'Mobile'),
+ ]) {
+ expect(find.descendant(of: row, matching: find.text(pm)), findsOne);
+ expect(
+ find.descendant(of: row, matching: find.text(project)),
+ findsOne,
+ );
+ expect(
+ find.descendant(
+ of: row,
+ matching: find.byTooltip('Chat with PM · $project'),
+ ),
+ findsOne,
+ );
+ }
+
+ await tester.tap(find.byKey(const ValueKey('super-pm-chat-mobile')));
+ await tester.pumpAndSettle();
+ expect(c.selectedId, c.pmChat('mobile')!.id);
+ await close(tester, c);
+ });
+
+ testWidgets(
+ "shows the count on the row and the project, and the project's count opens the chat",
+ (tester) async {
+ final server = pmChatSwarm();
+ final c = await show(tester, server);
+ await tester.tap(entry);
+ await tester.pumpAndSettle();
+ final chat = c.pmChat('lead')!.id;
+ await tester.tap(find.byKey(const ValueKey('super-group-lead')));
+ await tester.pumpAndSettle();
+
+ pmReply(server, chat, 'Here is the plan.');
+ pmReply(server, chat, 'Shall I ship it?');
+ await c.refresh();
+ await tester.pumpAndSettle();
+
+ final projectCount = find.byKey(
+ const ValueKey('super-project-pm-unread-lead'),
+ );
+ expect(find.descendant(of: entry, matching: find.text('2')), findsOne);
+ expect(
+ find.descendant(of: projectCount, matching: find.text('2')),
+ findsOne,
+ );
+ expect(find.byTooltip('2 new in Chat with PM'), findsNWidgets(2));
+
+ await tester.tap(projectCount);
+ await tester.pumpAndSettle();
+ expect(c.selectedId, chat);
+ expect(
+ find.descendant(of: entry, matching: find.text('2')),
+ findsNothing,
+ );
+ expect(projectCount, findsNothing);
+ await close(tester, c);
+ },
+ );
+
+ testWidgets("never shows another person's chat or its count", (
+ tester,
+ ) async {
+ final server = pmChatSwarm();
+ final peer = server.controller(account: 'peer');
+ await peer.refresh();
+ await peer.openPmChat('lead');
+ final peerChat = peer.pmChat('lead')!.id;
+ peer.dispose();
+ pmReply(server, peerChat, 'Only for Ken.');
+
+ final c = await show(tester, server, account: 'owner');
+
+ expect(entry, findsOneWidget);
+ expect(c.pmChat('lead'), isNull);
+ expect(
+ find.byKey(const ValueKey('super-project-pm-unread-lead')),
+ findsNothing,
+ );
+ expect(
+ find.descendant(of: sidebar, matching: find.text('ken.tran')),
+ findsNothing,
+ );
+ await close(tester, c);
+ });
+ });
+
+ group('the Swarm tab', () {
+ test(
+ 'counts unread PM messages beside its tags, with its own label',
+ () async {
+ final f = SuperTabLaunchFixture(local: true);
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ final server = f.connection.server;
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await c.openPmChat('lead');
+ final chat = c.pmChat('lead')!.id;
+ await c.select('lead');
+ final tab = f.app.activeSwarm;
+ expect(tabWaiting(f.app, tab), 0);
+ expect(tabWaitingLabel(f.app, tab), isNull);
+
+ pmReply(server, chat, 'Here is the plan.');
+ pmReply(server, chat, 'Shall I ship it?');
+ await c.refresh();
+ await pumpEventQueue();
+ expect(tabPmWaiting(f.app, tab), 2);
+ expect(tabWaiting(f.app, tab), 2);
+ expect(tabWaitingLabel(f.app, tab), '2 new in Chat with PM');
+
+ server.tag('message-1');
+ await c.refresh();
+ expect(tabWaiting(f.app, tab), 3);
+ expect(
+ tabWaitingLabel(f.app, tab),
+ 'Tagged in 1 message · 2 new in Chat with PM',
+ );
+ },
+ );
+ });
+
+ for (final native in [false, true]) {
+ testWidgets('a Swarm tab behind another counts unread PM messages '
+ '(native=$native)', (tester) async {
+ final updates = <Map>[];
+ const channel = MethodChannel('harness/swarm_tabs');
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
+ call,
+ ) async {
+ if (call.method == 'update') updates.add(call.arguments as Map);
+ return true;
+ });
+ addTearDown(
+ () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ channel,
+ null,
+ ),
+ );
+ final f = SuperTabLaunchFixture(local: true);
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ final swarm = f.app.activeSwarm;
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await c.openPmChat('lead');
+ final chat = c.pmChat('lead')!.id;
+ await c.select('lead');
+ pmReply(f.connection.server, chat, 'Here is the plan.');
+ pmReply(f.connection.server, chat, 'Shall I ship it?');
+ await c.refresh();
+ await tester.runAsync(pumpEventQueue);
+ f.app.newSwarm(name: 'other');
+ await mount(tester, f.app, nativeTabs: native);
+ await tester.pump(const Duration(milliseconds: 100));
+ if (native) {
+ final tab = (updates.last['tabs'] as List).cast<Map>().singleWhere(
+ (t) => t['id'] == swarm.id,
+ );
+ expect(tab['attention'], 2);
+ } else {
+ expect(
+ tester
+ .widget<Text>(find.byKey(ValueKey('tab-tags:${swarm.id}')))
+ .data,
+ '2',
+ );
+ }
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ f.dispose();
+ });
+ }
+
+ testWidgets(
+ "machines read as '~ name', with the name the person gave it when set",
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ const renamed = Machine(
+ machineId: 'm2',
+ authMode: MachineAuthMode.remote,
+ name: "Diego's Mac",
+ );
+ f.app.machines = [...f.app.machines, renamed];
+ f.app.machineStates['m2'] = MachineState(renamed)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agentLoadStatus = AgentLoadStatus.loaded;
+ f.connection.server.state['machines'] = [
+ {
+ 'machineId': 'm2',
+ 'name': 'MacBookPro2021.local',
+ 'contributorId': 'owner',
+ },
+ // A teammate's: only the Swarm's name for it is known here.
+ {
+ 'machineId': 'studio',
+ 'name': 'Studio.local',
+ 'contributorId': 'owner',
+ },
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SuperTabMachines(
+ controller: c,
+ app: f.app,
+ onAddAgent: (_) {},
+ ),
+ ),
+ ),
+ );
+ await tester.pump();
+
+ String name(String id) => tester
+ .widget<Text>(find.byKey(ValueKey('super-machine-name-$id')))
+ .data!;
+ expect(name('m2'), "Diego's Mac");
+ expect(name('studio'), 'Studio');
+ final row = find.byKey(const ValueKey('super-machine-m2'));
+ expect(find.descendant(of: row, matching: find.text('~')), findsOne);
+ expect(
+ find.descendant(of: row, matching: find.byIcon(AppIcons.monitor)),
+ findsNothing,
+ );
+ expect(
+ find.descendant(of: row, matching: find.byType(SuperTabMachineDot)),
+ findsOne,
+ );
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ },
+ );
+
+ group('the shortcut', () {
+ HarnessCommand command() =>
+ harnessCommands.singleWhere((c) => c.id == 'swarm.chat_with_pm');
+
+ test('is ⇧⌘K, listed as Chat with PM in the shortcuts help', () {
+ expect(command().label, 'Chat with PM');
+ expect(command().keys, ['cmd+shift+k']);
+ final lesson = keyboardLessons(AppKeymap())
+ .singleWhere((l) => l.command == 'swarm.chat_with_pm');
+ expect(lesson.label, 'Chat with PM');
+ expect(lesson.group, 'Workspace');
+ expect(lesson.bindings.map((b) => b.sequence), ['cmd+shift+k']);
+ });
+
+ // A browser binds as Linux does (Alt for ⌘); the VM cannot be one.
+ for (final platform in [
+ TargetPlatform.macOS,
+ TargetPlatform.linux,
+ TargetPlatform.windows,
+ ]) {
+ test('clashes with nothing on ${platform.name}', () {
+ debugDefaultTargetPlatformOverride = platform;
+ addTearDown(() => debugDefaultTargetPlatformOverride = null);
+ final keys = command().keys;
+ expect(keys, hasLength(1));
+
+ final clash = findShortcutConflict(
+ harnessDefaultKeymap,
+ command: 'swarm.chat_with_pm',
+ context: KeymapContext.workspace,
+ keys: [KeyStroke.parse(keys.single)],
+ label: (id) => id,
+ linux: platform == TargetPlatform.linux,
+ );
+ expect(clash, isNull, reason: '${keys.single}: ${clash?.label}');
+ });
+ }
+
+ test("opens the active Swarm tab's current project chat, and nothing elsewhere", () async {
+ final f = SuperTabLaunchFixture(local: true);
+ final plain = f.app.activeSwarmId;
+ expect(await openActivePmChat(f.app), isFalse);
+
+ f.app.bindSuperTab(plain, tabId, 'Pilot');
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await c.select('offline');
+
+ expect(await openActivePmChat(f.app), isTrue);
+ expect(c.selectedId, c.pmChat('lead')!.id);
+ });
+ });
+
+ for (final brightness in Brightness.values) {
+ testWidgets('screenshots for review (${brightness.name})', (tester) async {
+ final picture = GlobalKey();
+ final server = riverSwarm();
+ (server.state['conversations'] as List).last['number'] = 196;
+ server.state['machines'] = [
+ {'machineId': 'diego', 'name': "Diego's Mac", 'contributorId': 'owner'},
+ ];
+ secondProject(server);
+ final c = server.controller(account: 'peer');
+ addTearDown(c.dispose);
+ await c.refresh();
+ await c.openPmChat('lead');
+ final chat = c.pmChat('lead')!.id;
+ await c.select('offline');
+ pmReply(server, chat, 'Here is the plan.');
+ pmReply(server, chat, 'Shall I ship it?');
+ await c.refresh();
+ grid.AppTheme.brightness.value = brightness;
+ addTearDown(() => grid.AppTheme.brightness.value = Brightness.light);
+ await tester.binding.setSurfaceSize(const Size(1200, 760));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: brightness),
+ builder: (context, child) =>
+ RepaintBoundary(key: picture, child: child),
+ home: Scaffold(
+ body: SuperTabView(
+ controller: c,
+ onInvite: () {},
+ onAddAgent: (_) {},
+ onOpenTerminal: (_) {},
+ machineName: (_) => 'Team Mac',
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ Future<void> shot(String name) => tester.runAsync(() async {
+ final boundary =
+ picture.currentContext!.findRenderObject()!
+ as RenderRepaintBoundary;
+ final image = await boundary.toImage(pixelRatio: 1.5);
+ final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
+ await Directory(shots!).create(recursive: true);
+ await File('$shots/pm-chat-$name-${brightness.name}.png')
+ .writeAsBytes(bytes!.buffer.asUint8List());
+ image.dispose();
+ });
+
+ c.expandedProjects.clear();
+ if (c.projectsGroupOpen) c.toggleProjectsGroup();
+ await tester.pumpAndSettle();
+ await shot('collapsed');
+ c.toggleProjectsGroup();
+ c.toggleProject('lead');
+ await tester.pumpAndSettle();
+ await shot('expanded');
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ }, skip: shots == null);
+ }
+}
diff --git a/desktop/test/super_tab_pm_chat_test.dart b/desktop/test/super_tab_pm_chat_test.dart
index b0f5bcd77..3d3d5ad78 100644
--- a/desktop/test/super_tab_pm_chat_test.dart
+++ b/desktop/test/super_tab_pm_chat_test.dart
@@ -5,33 +5,12 @@ import 'package:harness/super_tabs/controller.dart';
import 'package:harness/super_tabs/project_sidebar.dart';
import 'package:harness/super_tabs/view.dart';
+import 'support/pm_chat_fixture.dart';
import 'support/super_tab_fixture.dart';
/// Each person's private chat with a project's Product Manager: one per person
/// and project, read by that person and the Lead alone.
void main() {
- ConversationServer swarm() {
- final server = ConversationServer();
- server.state['people'] = [
- {'id': 'owner', 'email': '[email protected]', 'role': 'owner'},
- {'id': 'peer', 'email': '[email protected]', 'role': 'collaborator'},
- ];
- server.state['agents'] = [
- {
- 'id': 'lead-agent',
- 'name': 'Lead',
- 'machineId': 'm1',
- 'harnessId': 'h1',
- 'contributorId': 'owner',
- 'configuration': {'engine': 'claude', 'model': 'opus'},
- },
- ];
- (server.state['conversations'] as List).first
- ..['leadId'] = 'lead-agent'
- ..['agentIds'] = ['lead-agent'];
- return server;
- }
-
List<Map<String, dynamic>> creates(ConversationServer server) => [
for (final post in server.posts)
if ((post['command'] as Map)['type'] == 'conversation.create') post,
@@ -39,7 +18,7 @@ void main() {
group('the controller', () {
test('the first open creates a private conversation for the person alone, named after them', () async {
- final server = swarm();
+ final server = pmChatSwarm();
final c = server.controller(account: 'peer');
addTearDown(c.dispose);
await c.refresh();
@@ -68,7 +47,7 @@ void main() {
test(
'a later open reopens the same conversation and sends nothing',
() async {
- final server = swarm();
+ final server = pmChatSwarm();
final c = server.controller(account: 'peer');
addTearDown(c.dispose);
await c.refresh();
@@ -85,7 +64,7 @@ void main() {
);
test('two windows opening it at once get one conversation: the create repeats one request', () async {
- final server = swarm();
+ final server = pmChatSwarm();
final first = server.controller(account: 'peer');
final second = server.controller(account: 'peer');
addTearDown(first.dispose);
@@ -111,7 +90,7 @@ void main() {
});
test('each person and project has its own create request', () async {
- final server = swarm();
+ final server = pmChatSwarm();
final peer = server.controller(account: 'peer');
final owner = server.controller(account: 'owner');
addTearDown(peer.dispose);
@@ -128,7 +107,7 @@ void main() {
});
test('a person who left and rejoined gets a new chat, not the one they can no longer read', () async {
- final server = swarm();
+ final server = pmChatSwarm();
final people = (server.state['people'] as List).cast<Map>();
people.firstWhere((p) => p['id'] == 'peer')['generation'] = 'first';
final c = server.controller(account: 'peer');
@@ -158,7 +137,7 @@ void main() {
});
test("another member, the owner included, does not see a person's chat and opens their own", () async {
- final server = swarm();
+ final server = pmChatSwarm();
final peer = server.controller(account: 'peer');
addTearDown(peer.dispose);
await peer.refresh();
@@ -176,7 +155,7 @@ void main() {
test(
'a private conversation shared with someone else too is not the PM chat',
() async {
- final server = swarm();
+ final server = pmChatSwarm();
(server.state['conversations'] as List).add({
...conversationFixture('pair', 'Ken and owner'),
'projectId': 'lead',
@@ -238,10 +217,10 @@ void main() {
testWidgets('a project shows Chat with PM above its workgroups', (
tester,
) async {
- final c = await show(tester, swarm());
+ final c = await show(tester, pmChatSwarm());
expect(entry, findsOneWidget);
expect(
- find.descendant(of: entry, matching: find.text('Chat with PM')),
+ find.descendant(of: entry, matching: find.text('Lead')),
findsOneWidget,
);
final workgroup = find.byKey(const ValueKey('super-group-offline'));
@@ -255,7 +234,7 @@ void main() {
testWidgets(
'the first click opens a new chat, named Chat with PM in the header, not listed again among the workgroups',
(tester) async {
- final server = swarm();
+ final server = pmChatSwarm();
final c = await show(tester, server);
await tester.tap(entry);
await tester.pumpAndSettle();
@@ -264,7 +243,8 @@ void main() {
final chat = c.pmChat('lead')!;
expect(c.selectedId, chat.id);
expect(find.byKey(ValueKey('super-group-${chat.id}')), findsNothing);
- expect(find.text('Chat with PM'), findsNWidgets(2));
+ // The header names the chat; the sidebar names its Product Manager.
+ expect(find.text('Chat with PM'), findsOneWidget);
expect(find.text('Message Product Manager'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('super-group-offline')));
@@ -280,7 +260,7 @@ void main() {
testWidgets(
'the chat lists only its own people: the person and the Product Manager',
(tester) async {
- final server = swarm();
+ final server = pmChatSwarm();
(server.state['agents'] as List).add({
'id': 'builder',
'name': 'Builder',
@@ -308,7 +288,7 @@ void main() {
testWidgets(
'the chat offers no Add agent: the Product Manager is its only agent',
(tester) async {
- final c = await show(tester, swarm());
+ final c = await show(tester, pmChatSwarm());
final addAgent = find.byTooltip('Add agent');
expect(addAgent, findsOneWidget);
await tester.tap(entry);
@@ -320,10 +300,10 @@ void main() {
},
);
- testWidgets('a reply from the Product Manager marks the entry unread', (
+ testWidgets('a reply from the Product Manager counts on the entry', (
tester,
) async {
- final server = swarm();
+ final server = pmChatSwarm();
final c = await show(tester, server);
await tester.tap(entry);
await tester.pumpAndSettle();
@@ -336,12 +316,11 @@ void main() {
await tester.pumpAndSettle();
expect(c.unread(c.pmChat('lead')!), isTrue);
+ expect(find.descendant(of: entry, matching: find.text('1')), findsOne);
expect(
find.descendant(
of: entry,
- matching: find.byWidgetPredicate(
- (w) => w is Semantics && w.properties.label == 'Unread messages',
- ),
+ matching: find.byTooltip('1 new in Chat with PM'),
),
findsOneWidget,
);
@@ -351,7 +330,7 @@ void main() {
testWidgets(
"a Product Manager's tag in the chat is in Notifications under Chat with PM, and opens it",
(tester) async {
- final server = swarm();
+ final server = pmChatSwarm();
final c = await show(tester, server);
await tester.tap(entry);
await tester.pumpAndSettle();
@@ -388,7 +367,7 @@ void main() {
testWidgets("the owner's sidebar never lists a member's chat", (
tester,
) async {
- final server = swarm();
+ final server = pmChatSwarm();
final peer = server.controller(account: 'peer');
await peer.refresh();
await peer.openPmChat('lead');
diff --git a/desktop/test/super_tab_polish_test.dart b/desktop/test/super_tab_polish_test.dart
index 146da911f..67e93a8d6 100644
--- a/desktop/test/super_tab_polish_test.dart
+++ b/desktop/test/super_tab_polish_test.dart
@@ -12,6 +12,7 @@ import 'package:harness/core/open_in_browser.dart';
import 'package:harness/super_tabs/message_text.dart';
import 'package:harness/super_tabs/model.dart';
import 'package:harness/super_tabs/recording_notice.dart';
+import 'package:harness/super_tabs/project_sidebar.dart';
import 'package:harness/super_tabs/view.dart';
import 'support/super_tab_fixture.dart';
@@ -385,6 +386,17 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Conversations'));
await tester.pumpAndSettle();
+ // Below the pinned Chat with PM and the projects, a scroll away.
+ await tester.scrollUntilVisible(
+ find.text('Machines'),
+ 100,
+ scrollable: find
+ .descendant(
+ of: find.byType(ProjectSidebar),
+ matching: find.byType(Scrollable),
+ )
+ .first,
+ );
expect(find.text('Machines'), findsOneWidget);
expect(tester.takeException(), isNull);
await shot('-projects');
diff --git a/desktop/test/super_tab_sidebar_test.dart b/desktop/test/super_tab_sidebar_test.dart
index f3017b032..9af6630e1 100644
--- a/desktop/test/super_tab_sidebar_test.dart
+++ b/desktop/test/super_tab_sidebar_test.dart
@@ -142,31 +142,33 @@ void main() {
tester.getBottomLeft(newProject).dy,
lessThan(tester.getTopLeft(devices).dy),
);
- expect(
- inRow('super-group-lead', find.byIcon(AppIcons.folder)),
- findsOneWidget,
- );
+ expect(inRow('super-group-lead', find.text('#')), findsOneWidget);
- await tester.tap(find.text('sample-project'));
+ // Its name in the Projects list, not its direct message's grey tag.
+ final sample = inRow(
+ 'super-group-empty-lead',
+ find.text('sample-project'),
+ );
+ await tester.tap(sample);
await tester.pumpAndSettle();
expect(controller.selectedId, 'empty-lead');
await tester.tap(expand);
await tester.pumpAndSettle();
expect(controller.selectedId, 'empty-lead');
- expect(
- inRow('super-group-lead', find.byIcon(AppIcons.folderOpen)),
- findsOneWidget,
- );
+ expect(inRow('super-group-lead', find.text('#')), findsOneWidget);
final work = find.byKey(const ValueKey('super-group-offline'));
expect(work, findsOneWidget);
- final textX = tester.getTopLeft(find.text('web-project')).dx;
+ final textX = tester
+ .getTopLeft(inRow('super-group-lead', find.text('web-project')))
+ .dx;
for (final label in [
- 'New project',
- 'Your devices',
- 'sample-project',
- '#12 Offline editing',
+ find.text('New project'),
+ find.text('Your devices'),
+ sample,
+ // A workgroup's number is grey, with no #: it is no channel.
+ inRow('super-group-offline', find.text('12 Offline editing')),
]) {
- expect(tester.getTopLeft(find.text(label)).dx, textX, reason: label);
+ expect(tester.getTopLeft(label).dx, textX, reason: '$label');
}
expect(
tester.getCenter(unreadDot('offline')).dx,
@@ -397,12 +399,12 @@ void main() {
final controller = await projectSidebar(server);
await pumpSidebar(tester, controller, app);
const machinesBody = 'Add a machine for the product manager to use.';
- expect(find.text('web-project'), findsOneWidget);
+ expect(inRow('super-group-lead', find.text('web-project')), findsOneWidget);
expect(find.text(machinesBody), findsOneWidget);
await tester.tap(find.byTooltip('Collapse Projects'));
await tester.pumpAndSettle();
- expect(find.text('web-project'), findsNothing);
+ expect(inRow('super-group-lead', find.text('web-project')), findsNothing);
expect(controller.projectsGroupOpen, isFalse);
await tester.tap(find.byTooltip('Collapse Machines'));
await tester.pumpAndSettle();
@@ -424,7 +426,7 @@ void main() {
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
- expect(find.text('web-project'), findsOneWidget);
+ expect(inRow('super-group-lead', find.text('web-project')), findsOneWidget);
await disposeSidebar(tester, controller);
await reopened.flush();
reopened.dispose();
diff --git a/desktop/test/support/pm_chat_fixture.dart b/desktop/test/support/pm_chat_fixture.dart
new file mode 100644
index 000000000..f7f10cfb6
--- /dev/null
+++ b/desktop/test/support/pm_chat_fixture.dart
@@ -0,0 +1,35 @@
+import 'super_tab_fixture.dart';
+
+/// A Swarm with a Lead in its project and two people: the owner and Ken, a
+/// collaborator, each with their own chat with the Product Manager.
+ConversationServer pmChatSwarm() {
+ final server = ConversationServer();
+ server.state['people'] = [
+ {'id': 'owner', 'email': '[email protected]', 'role': 'owner'},
+ {'id': 'peer', 'email': '[email protected]', 'role': 'collaborator'},
+ ];
+ server.state['agents'] = [
+ {
+ 'id': 'lead-agent',
+ 'name': 'Lead',
+ 'machineId': 'm1',
+ 'harnessId': 'h1',
+ 'contributorId': 'owner',
+ 'configuration': {'engine': 'claude', 'model': 'opus'},
+ },
+ ];
+ (server.state['conversations'] as List).first
+ ..['leadId'] = 'lead-agent'
+ ..['agentIds'] = ['lead-agent'];
+ return server;
+}
+
+/// The Product Manager (the project's Lead) writes [text] in [conversationId].
+void pmReply(ConversationServer server, String conversationId, String text) {
+ server.append(text, conversationId: conversationId);
+ server.messages.last['author'] = {
+ 'kind': 'agent',
+ 'id': 'lead-agent',
+ 'name': 'Lead',
+ };
+}
diff --git a/desktop/test/swarm_projects_test.dart b/desktop/test/swarm_projects_test.dart
index eedf60c93..04fdc0f22 100644
--- a/desktop/test/swarm_projects_test.dart
+++ b/desktop/test/swarm_projects_test.dart
@@ -80,7 +80,7 @@ void main() {
await tester.tap(find.byKey(const ValueKey('super-project-expand-lead')));
await tester.pumpAndSettle();
expect(c.selectedId, 'lead');
- expect(find.text('#12 Offline editing'), findsOneWidget);
+ expect(find.text('12 Offline editing'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('super-group-offline')));
await tester.pumpAndSettle();
expect(c.selectedId, 'offline');
@@ -127,7 +127,7 @@ void main() {
);
// Workgroups share the project name column in the compact sidebar.
expect(
- tester.getTopLeft(find.text('#12 Offline editing')).dx,
+ tester.getTopLeft(find.text('12 Offline editing')).dx,
tester.getTopLeft(projectName).dx,
);
diff --git a/docs/naming-system.md b/docs/naming-system.md
index 8ea0677b5..d85c51149 100644
--- a/docs/naming-system.md
+++ b/docs/naming-system.md
@@ -98,11 +98,16 @@ no CLI keeps its maker's name (Fo).
A pane is a view, so closing a pane or tab closes views. **Stop Harness** ends the
running harness. Adding harnesses to a tab groups them without a separate team
setup. A **Swarm** occupies one tab in that same tab bar. A person can belong to several Swarms.
-Its sidebar starts with **New project** and **Your devices**. Projects and Machines have
-section headings with disclosure after the label and an add action at the right. Project rows
-show their project icon at the left, then their name, status and a right-hand disclosure.
-Project names open their product manager chats; disclosure reveals workgroups whose names
-align with the project name. An expanded project without workgroups says **No workgroups yet**.
+Its sidebar reads like a chat app's. It starts with **Direct messages**: the person's
+**Chat with PM** for each project, listed by the product manager's name and avatar, with the
+project's name in grey when the Swarm has several and a count of new messages. Hovering says
+**Chat with PM**, and ⇧⌘K opens the current project's. **New project** and **Your devices**
+follow. Projects and Machines have section headings with disclosure after the label and an add
+action at the right. Project rows read as channels: **#** at the left, then their name, status
+and a right-hand disclosure. Project names open their product manager chats; disclosure reveals
+workgroups, shown by their number in grey with no **#** and then their title
+(`12 Offline editing`), aligned with the project name. An expanded project without workgroups
+says **No workgroups yet**.
**Your devices** opens the Devices dashboard and its existing agent conversation inside the
current Swarm, preserving project drafts and the selected workgroup. Ordinary tabs retain
their standalone Devices workspace. The navigation, conversation and people panes have
@@ -117,7 +122,8 @@ tags retain their full text on hover. Reuse observed status and assignment data;
activity summaries or infer a work timer from the session's age. Engine names belong in details.
Chat headings and quoted replies use the same current agent identity as the roster, including
older messages. When an agent has left, its recorded author name remains available in history.
-Machine rows show a computer icon, name, owner avatar, status and right-hand disclosure.
+Machine rows show **~** at the left, then the name the person gave the machine (else the
+Swarm's name for it), owner avatar, status and right-hand disclosure.
In the Swarm's views, a Mac and its Harness Team account are one row, and agents in that account
read as on the Mac. App-wide machine lists still show the team account as its own machine.
When teammates' agents cannot run on a machine, its row adds one line, such as