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.

Merge origin/main into machine-profiles; a profile only hides

bubu-dudu580ee23ec523
diff --cc desktop/lib/screens/swarm_screen.dart
index e0514e69f,4926226b6..1d8913b02
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@@ -591,11 -1743,12 +1743,15 @@@ class _SwarmScreenState extends State<S
'current': entry.current,
},
],
++ // The tabs this window's machine profile shows (all of them under
++ // All machines); the rest stay on the account desk, only not drawn here.
'tabs': [
- for (final swarm in app.swarms)
+ for (final swarm in app.profileSwarms)
{
'id': swarm.id,
'name': swarm.name,
- 'label': '${app.swarms.indexOf(swarm) + 1}:${names[swarm.id]}',
++ 'label':
++ '${app.profileSwarms.indexOf(swarm) + 1}:${names[swarm.id]}',
'kind': swarm.kind,
'agentCount': _tabAgents(swarm).length,
'engine': swarm.isStore ? 'store' : _tabEngine(swarm),
@@@ -2469,7 -5640,7 +5643,9 @@@
if (id == 'pane.layout' || id == 'task.route') return true;
if (id.startsWith('swarm.select_')) {
final number = int.tryParse(id.substring('swarm.select_'.length));
- return number != null && number >= 1 && number <= app.profileSwarms.length;
- return number != null && number >= 1 && number <= app.swarms.length;
++ return number != null &&
++ number >= 1 &&
++ number <= app.profileSwarms.length;
}
if (id == 'swarm.new') return true;
if (id == 'swarm.reopen') return app.canReopenLastClosed;
@@@ -3020,7 -6239,7 +6244,9 @@@
void _revealSelectedTab(double viewport) {
final previous = _tabGeometry;
- final order = app.profileSwarms.map((tab) => tab.id).toList(growable: false);
- final order = app.swarms.map((tab) => tab.id).toList(growable: false);
++ final order = app.profileSwarms
++ .map((tab) => tab.id)
++ .toList(growable: false);
if (previous != null &&
previous.activeId == app.activeSwarmId &&
previous.viewport == viewport &&
@@@ -3050,15 -6273,14 +6280,16 @@@
WidgetsBinding.instance.addPostFrameCallback((_) {
_tabRevealScheduled = false;
if (!mounted || !_tabScroll.hasClients) return;
- final index = app.swarms.indexWhere((tab) => tab.id == app.activeSwarmId);
+ final index = app.profileSwarms.indexWhere(
+ (tab) => tab.id == app.activeSwarmId,
+ );
if (index < 0) return;
final position = _tabScroll.position;
- final left = index * _tabExtent;
- final right = left + _tabExtent;
+ final left = _tabWidths.take(index).fold(0.0, (a, b) => a + b);
+ final extent = _tabWidths[index];
+ final right = left + extent;
final offset =
- left < position.pixels || _tabExtent > position.viewportDimension
+ left < position.pixels || extent > position.viewportDimension
? left
: right > position.pixels + position.viewportDimension
? right - position.viewportDimension
@@@ -3089,122 -6467,273 +6476,274 @@@
),
),
),
- const SizedBox(width: 10),
- Expanded(
- child: LayoutBuilder(
- builder: (context, constraints) {
- _tabExtent = constraints.maxWidth.clamp(64, 188);
- _revealSelectedTab(constraints.maxWidth);
- return ReorderableListView.builder(
- scrollController: _tabScroll,
- itemExtent: _tabExtent,
- scrollDirection: Axis.horizontal,
- shrinkWrap: true,
- buildDefaultDragHandles: false,
- itemCount: app.profileSwarms.length,
- onReorderItem: (old, to) =>
- app.reorderSwarm(app.profileSwarms[old].id, to),
- itemBuilder: (context, index) {
- final swarm = app.profileSwarms[index];
- return ReorderableDragStartListener(
- key: ValueKey(swarm.id),
- index: index,
+ ],
+ ],
+ );
+ return Material(
+ key: const ValueKey('workspace-status-bar'),
+ type: MaterialType.transparency,
+ child: SizedBox(
+ height: _statusBarHeight,
+ child: Padding(
+ padding: EdgeInsets.symmetric(horizontal: cell.width),
+ child: Row(
+ children: [
+ Expanded(
+ child: _zoo.loaded
+ ? DaemonVoiceLine(
+ face: _face,
+ brain: _brain,
+ onAnswer: _shortcutsEnabled ? _answerDaemon : null,
+ fallback: paneContext,
+ )
+ : paneContext,
+ ),
+ if (kIsWeb) ...[
+ SizedBox(width: cell.width),
+ ConstrainedBox(
+ constraints: BoxConstraints(maxWidth: downloadWidth),
+ child: const WebDownloadButton(),
+ ),
+ ],
+ if (_slotShown)
+ ConstrainedBox(
+ constraints: BoxConstraints(maxWidth: daemonWidth),
+ child: DaemonSlotButton(
+ face: _face,
+ tooltip: () => _daemonTooltip,
+ selected: _daemonOverlay != null,
+ onPressed: _activateDaemon,
+ ),
+ ),
+ if (_showShareButton) ...[
+ SizedBox(width: cell.width),
+ ConstrainedBox(
+ constraints: BoxConstraints(maxWidth: shareWidth),
+ child: WorkspaceShareButton(
+ key: const ValueKey('workspace-share-button'),
+ label: _shareLabel(focused),
+ tooltip: _shareTooltip(focused),
+ onPressed: _canExecuteCommand('agent.share')
+ ? () => _runShortcut('agent.share')
+ : null,
+ ),
+ ),
+ ],
+ if (focused != null && modelPickerSupports(focused.engine)) ...[
+ SizedBox(width: cell.width * 2),
+ ConstrainedBox(
+ constraints: BoxConstraints(maxWidth: modelWidth),
+ child: _focusedModelPicker(focused),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ );
+
+ Widget _tabStrip() => LayoutBuilder(
+ builder: (context, constraints) {
+ final cell = workspaceBarCellSizeOf(context);
+ final theme = terminalThemeFor(
+ grid.AppTheme.palette.value,
+ terminalThemeStore.value,
+ );
+ final names = workspaceTabNames(app);
- final activities = [for (final tab in app.swarms) tabActivity(app, tab)];
++ final shown = app.profileSwarms;
++ final activities = [for (final tab in shown) tabActivity(app, tab)];
+ final labels = [
- for (var index = 0; index < app.swarms.length; index++)
- '${index + 1}:${names[app.swarms[index].id]}',
++ for (var index = 0; index < shown.length; index++)
++ '${index + 1}:${names[shown[index].id]}',
+ ];
+ final toolHeight = workspaceBarControlHeight(context);
+ final prefs = appearancePrefsStore.value.prompt;
+ final storeWidth = math.min(
+ WorkspaceStoreButton.widthOf(context),
+ math.max(0.0, constraints.maxWidth - cell.width * 14),
+ );
+ final chrome = widget.chrome;
+ final leadingWidth = chrome?.leadingWidth(context) ?? 0.0;
+ final tabBudget = math.max(
+ 0.0,
+ constraints.maxWidth -
+ cell.width * 6 -
+ storeWidth -
+ cell.width * 8 -
+ leadingWidth,
+ );
+ _tabWidths = [
+ for (var i = 0; i < labels.length; i++)
+ math.max(
+ activities[i] == null ? 0 : ('${i + 1}:'.length + 4) * cell.width,
+ math.min(
+ math.min(
+ labels[i].characters.length +
+ 2 +
+ (activities[i] == null ? 0 : 2),
+ 24,
+ ) *
+ cell.width,
+ tabBudget,
+ ),
+ ),
+ ];
+ final total = _tabWidths.fold(0.0, (sum, width) => sum + width);
+ final tabsWidth = math.min(total, tabBudget);
+ _revealSelectedTab(tabsWidth);
+ return Material(
+ key: const ValueKey('workspace-tab-bar'),
+ color: grid.AppPalette.swarmTabBar,
+ child: SizedBox(
+ height: math.max(_tabBarHeight, cell.height * 2),
+ child: Row(
+ children: [
+ SizedBox(width: cell.width),
+ if (chrome != null)
+ SizedBox(
+ width: leadingWidth,
+ child: chrome.leading(context, _workspaceCommands),
+ ),
+ SizedBox(
+ width: tabsWidth,
+ child: ReorderableListView.builder(
+ scrollController: _tabScroll,
+ itemExtentBuilder: (index, _) => _tabWidths[index],
+ scrollDirection: Axis.horizontal,
+ shrinkWrap: true,
+ buildDefaultDragHandles: false,
- itemCount: app.swarms.length,
++ itemCount: shown.length,
+ onReorderItem: (old, to) =>
- app.reorderSwarm(app.swarms[old].id, to),
++ app.reorderSwarm(shown[old].id, to),
+ itemBuilder: (context, index) {
- final swarm = app.swarms[index];
++ final swarm = shown[index];
+ final selected = app.activeSwarmId == swarm.id;
+ final activity = activities[index];
+ final nameHint = workspaceTabTooltip(
+ labels[index],
+ swarm.name,
+ clipped:
+ workspaceBarTextSizeOf(context, labels[index]).width +
+ (activity == null ? 0 : cell.width * 2) >
+ _tabWidths[index] - cell.width * 2,
+ );
+ final tabHint = [
+ ?nameHint,
+ if (activity != null) activity.label,
+ ].join('\n');
+ return ReorderableDragStartListener(
+ key: ValueKey(swarm.id),
+ index: index,
+ child: Listener(
+ onPointerDown: (event) {
+ _middleDownTab = event.buttons == kTertiaryButton
+ ? swarm.id
+ : null;
+ },
+ onPointerUp: (event) {
+ final armed = _middleDownTab;
+ _middleDownTab = null;
+ if (armed == swarm.id) {
+ unawaited(app.closeSwarm(swarm.id));
+ }
+ },
child: GestureDetector(
onDoubleTap: () => _rename(swarm.id),
- child: _TabActionsReveal(
- builder: (showClose) => Container(
- width: _tabExtent - 2,
- margin: const EdgeInsets.only(top: 4, right: 2),
- decoration: ShapeDecoration(
- color: app.activeSwarmId == swarm.id
- ? grid.AppPalette.swarmField
- : Colors.transparent,
- shape: const TerminalTabBorder(),
- ),
- child: Row(
- children: [
- Expanded(
- child: TextButton(
- onPressed: () =>
- app.selectSwarm(swarm.id),
- style: TextButton.styleFrom(
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.all(
- Radius.circular(
- kTerminalCornerRadius,
+ child: Center(
+ child: WorkspaceBarControl(
+ label:
+ '${labels[index]}: ${swarm.name}${activity == null ? '' : ', ${activity.label}'}',
+ tooltip: tabHint.isEmpty ? null : tabHint,
+ selectedBackground: grid.AppPalette.swarmWelcome,
+ selected: selected,
+ highlighted:
+ selected &&
+ app.tabStripFocused &&
+ _tabStripFocus.hasPrimaryFocus,
+ onPressed: _shortcutsEnabled
+ ? () => app.selectSwarm(swarm.id)
+ : null,
+ builder: (context, emphasized) => SizedBox(
+ height: double.infinity,
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ horizontal: cell.width,
+ ),
+ child: Center(
+ child: activity == null
+ ? Text(
+ labels[index],
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: workspaceBarTextStyle(
+ color: theme.foreground,
+ emphasized: emphasized,
),
- ),
- ),
- animationDuration: Duration.zero,
- foregroundColor:
- app.activeSwarmId == swarm.id
- ? Colors.white
- : Colors.white70,
- ),
- child: Row(
- children: [
- if (swarm.isStore)
- StoreMark(
- key: ValueKey(
- 'tab-store:${swarm.id}',
+ )
+ : Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ '${index + 1}:',
+ style: workspaceBarTextStyle(
+ color: theme.foreground,
+ emphasized: emphasized,
+ ),
),
- )
- else if (_tabAgents(swarm).length ==
- 1)
- EngineMark(
- key: ValueKey(
- 'tab-engine:${swarm.id}',
+ Flexible(
+ child: Text(
+ names[swarm.id]!,
+ maxLines: 1,
+ overflow:
+ TextOverflow.ellipsis,
+ style: workspaceBarTextStyle(
+ color: theme.foreground,
+ emphasized: emphasized,
+ ),
+ ),
),
- engine: _tabEngine(swarm),
- size: 16,
- )
- else if (_tabAgents(swarm).length > 1)
- SwarmIcon(
- key: ValueKey(
- 'tab-group:${swarm.id}',
+ SizedBox(width: cell.width),
+ ListenableBuilder(
+ listenable: _tabScroll,
+ builder: (context, _) {
+ final left = _tabWidths
+ .take(index)
+ .fold(
+ 0.0,
+ (a, b) => a + b,
+ );
+ final offset =
+ _tabScroll.hasClients
+ ? _tabScroll.offset
+ : 0.0;
+ return ActivityMark(
+ key: ValueKey(
+ 'tab-activity:${swarm.id}',
+ ),
+ activity: activity,
+ color: activityColor(
+ activity,
+ theme,
+ color: prefs.color,
+ ),
+ emphasized: emphasized,
+ tooltip: false,
+ visible:
+ left <
+ offset +
+ tabsWidth &&
+ left + _tabWidths[index] >
+ offset,
+ );
+ },
),
- size: 16,
- color: Colors.white70,
- )
- else
- const Icon(Icons.add, size: 16),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- swarm.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- // Like the native tabs.
- style: grid.AppType.monoLabel(
- color: Colors.white,
- fontWeight: FontWeight.w400,
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- Opacity(
- key: ValueKey('tab-close:${swarm.id}'),
- opacity: showClose ? 1 : 0,
- alwaysIncludeSemantics: true,
- child: IconButton(
- onPressed: () => app.closeSwarm(swarm.id),
- icon: Icon(
- Icons.close,
- size: 13,
- semanticLabel: 'Close ${swarm.name}',
- ),
- constraints:
- const BoxConstraints.tightFor(
- width: 30,
- height: 30,
+ ],
),
- padding: EdgeInsets.zero,
- ),
),
- ],
+ ),
),
),
),
diff --cc desktop/lib/settings/settings_screen.dart
index edfe25d7e,390a2af15..80972e904
--- a/desktop/lib/settings/settings_screen.dart
+++ b/desktop/lib/settings/settings_screen.dart
@@@ -5,11 -5,12 +5,13 @@@ import '../analytics/analytics.dart'
import '../shared/theme/app_theme.dart' as grid;
import '../state/app_state.dart';
import '../widgets/harness_customize_pane.dart';
+ import 'experimental_features.dart';
import 'sections/about_section.dart';
import 'sections/account_section.dart';
+import 'sections/profiles_section.dart';
import 'sections/debug_section.dart';
import 'sections/devices_section.dart';
+ import 'sections/experimental_section.dart';
import 'sections/shortcuts_section.dart';
import 'sections/tracking_section.dart';
import 'sections/usage_section.dart';
diff --cc desktop/lib/settings/settings_section.dart
index f7812a458,02cbc5f67..983632eb4
--- a/desktop/lib/settings/settings_section.dart
+++ b/desktop/lib/settings/settings_section.dart
@@@ -11,9 -12,10 +12,11 @@@ import '../logging/debug_surface.dart'
/// be listed without a screen behind it or reachable without a row.
enum SettingsSection {
account(LucideIcons.user300, 'Account'),
+ profiles(LucideIcons.monitor300, 'Profiles'),
usage(LucideIcons.chartNoAxesColumn300, 'Usage'),
customize(LucideIcons.palette300, 'Customize'),
+ notifications(LucideIcons.bell300, 'Notifications'),
+ experimental(LucideIcons.flaskConical300, 'Experimental'),
devices(LucideIcons.zap300, 'Autonomous robots'),
shortcuts(LucideIcons.keyboard300, 'Keyboard shortcuts'),
debug(LucideIcons.bug300, 'Debug'),
@@@ -86,9 -89,14 +90,15 @@@ const _kSettingsGroups =
SettingsGroup('Preferences', [
SettingsSection.usage,
SettingsSection.customize,
+ // Beside Customize because it is the same kind of decision — how this Mac behaves while you
+ // work — and NOT inside it, which is where the alert switch started. Customize is about how
+ // the app looks; a sound is not a look, and somebody turning one off does not think to look
+ // under Appearance for it.
+ SettingsSection.notifications,
+ SettingsSection.experimental,
SettingsSection.devices,
SettingsSection.account,
+ SettingsSection.profiles,
]),
// Debug and Tracking sit between the two things they are most often reached
// from: the keys that open them, and the version a report has to name. The
diff --cc desktop/lib/state/app_state.dart
index b9287711b,e8c8a66c6..3433c08d1
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@@ -48,11 -61,13 +61,14 @@@ import '../widgets/engine_identity.dart
show allEngines, engineIdentity, isTerminalEngine;
import '../store/store_screen.dart' show openStoreAgent;
import 'dial_status.dart';
+ import 'grid_pictures.dart';
+ import 'model_start_watch.dart';
import 'harness_placement.dart';
import 'desk_sync.dart';
+import 'machine_profile.dart';
import 'pane_layout_store.dart';
import 'terminal_pane.dart';
+ import 'device_visit.dart';
import 'swarm.dart';
import '../terminal/terminal_binary.dart';
import '../update/desktop_updater.dart';
@@@ -1138,20 -1472,19 +1518,25 @@@ class AppNotifier extends ChangeNotifie
),
);
if (_activeSwarmId == id) {
- _activeSwarmId = swarms[index.clamp(0, swarms.length - 1)].id;
+ // The next full-list tab may belong to another computer. Land on the
- // next tab this profile still shows, never on one it is hiding.
- final neighbor = profileNeighborId(swarms, _machineProfileId, index);
- if (neighbor != null) {
- _activeSwarmId = neighbor;
- } else if (swarms.isNotEmpty) {
- final starter = Swarm(
- id: _desk.enabled ? newDeskId() : 'swarm-${_nextSwarmId++}',
- );
- swarms.add(starter);
- _activeSwarmId = starter.id;
++ // next tab this profile still shows. With none left the profile shows
++ // every tab (see [profileSwarms]) rather than a new one being made: a
++ // profile only hides, it never adds to the account desk.
++ _activeSwarmId =
++ profileNeighborId(swarms, _machineProfileId, index) ??
++ swarms[index.clamp(0, swarms.length - 1)].id;
+ // The tab beside it is shown and selected, but its terminal is not where
+ // the next key goes: that key was typed at the work that just closed. The
+ // keyboard waits on the tab strip ([tabStripFocused]). A fresh welcome
+ // has no terminal to protect and keeps its own focus; closing a tab with
+ // no panes (the Store, an unused New Tab) goes back to work as before.
+ if (replacement == null && removed.panes.isNotEmpty) {
+ _holdTabStrip();
+ } else {
+ _tabStripHold = null;
}
}
- _persistLayout();
+ if (persist) _persistLayout();
notifyListeners();
selectedMachineId = focusedPane?.machineId;
_announceAppFocus();
@@@ -9202,16 -11677,14 +11729,20 @@@
if (!swarms.any((s) => s.id == _activeSwarmId)) {
_activeSwarmId = swarms.first.id;
selectedMachineId = focusedPane?.machineId;
- // Another Mac closed the tab this one was on. The tab that comes forward
- // instead is nobody's arrival here — see [paneFocusByUser].
+ }
+ if (activeSwarmId != previousTab ||
+ !identical(focusedPane, previousFocus)) {
+ // A peer moving the focused pane also focuses its neighbour. That is
+ // remote navigation, just like a peer closing this window's active tab.
+ // Treating it as a gesture here can start a terminal takeover loop.
_paneFocusByUser = false;
}
+ final visible = profileSwarms;
+ if (visible.isNotEmpty && visible.every((s) => s.id != _activeSwarmId)) {
+ _activeSwarmId = visible.first.id;
+ selectedMachineId = focusedPane?.machineId;
+ _paneFocusByUser = false;
+ }
// Streams nobody shows any more.
for (final pane in released.toSet()) {
@@@ -9235,24 -11713,13 +11771,25 @@@
notifyListeners();
}
+ void _ensureProfileFocus() {
+ if (_machineProfileId == null || _machineProfileId!.isEmpty) return;
+ if (profileSwarms.any((swarm) => swarm.id == _activeSwarmId)) return;
- final visible = swarmsForMachineProfile(swarms, _machineProfileId);
- if (visible.isNotEmpty) {
- _activeSwarmId = visible.first.id;
- } else {
- final starter = Swarm(
- id: _desk.enabled ? newDeskId() : 'swarm-${_nextSwarmId++}',
- );
- swarms.add(starter);
- _activeSwarmId = starter.id;
- }
++ // Never empty while the desk has a tab: a profile that matches none shows
++ // them all (swarmsForMachineProfile), so nothing is made to fill it.
++ final visible = profileSwarms;
++ if (visible.isEmpty) return;
++ _activeSwarmId = visible.first.id;
+ selectedMachineId = focusedPane?.machineId;
+ }
+
void _persistLayout() {
+ if (workspaceEnabled?.call() == false) return;
+ _ensureProfileFocus();
+ for (final pane in allPanes) {
+ if (pane.agentId case final id?) {
+ rememberOpenedHarness(pane.machineId, id);
+ }
+ }
_draftSwarmReturns.removeWhere((id, _) {
final swarm = swarms.where((swarm) => swarm.id == id).firstOrNull;
return swarm == null ||
@@@ -9291,12 -11777,16 +11847,22 @@@
final initialSwarm = activeSwarm;
final revision = _layoutRevision;
final authRevision = _authRevision;
+ final savedProfile = await store.loadMachineProfile();
final saved = await store.loadSwarms();
- if (!_authWorkCurrent(authRevision) || revision != _layoutRevision) return;
+ final known = await store.loadMonitorHarnesses(saved);
+ if (!_authWorkCurrent(authRevision)) return;
++ // This window's own choice, never the desk's. No saved choice — a window
++ // that never picked one — is All machines.
+ _machineProfileId = savedProfile == null || savedProfile.isEmpty
+ ? null
+ : savedProfile;
+ for (final (machine, agent) in known) {
+ rememberOpenedHarness(machine, agent);
+ }
+ if (revision != _layoutRevision) {
+ _persistLayout();
+ return;
+ }
if (saved != null &&
allPanes.isEmpty &&
swarms.length == 1 &&
diff --cc desktop/lib/state/machine_profile.dart
index 41d0c4f05,000000000..3cf4e1fb6
mode 100644,000000..100644
--- a/desktop/lib/state/machine_profile.dart
+++ b/desktop/lib/state/machine_profile.dart
@@@ -1,51 -1,0 +1,58 @@@
+import 'swarm.dart';
+
+/// Which computer a window is looking at.
+///
+/// The account still has one desk — the same tabs on every computer — and a
+/// profile only decides which of those tabs this window draws. `null` is every
+/// machine. A machine id is that computer alone: a tab is in it when every
+/// agent it holds is on that computer. The Store and a tab with no agent yet
+/// stay, so there is always a place to start one.
+bool swarmMatchesMachineProfile(Swarm swarm, String? machineId) {
+ if (machineId == null || machineId.isEmpty) return true;
+ if (swarm.isStore) return true;
+ final paneIds = <String>{
+ for (final pane in swarm.panes)
+ if (pane.machineId.isNotEmpty) pane.machineId,
+ };
+ // Panes are the membership. A title left over from an agent that has since
+ // left the tab must not hide a tab whose remaining agents are all here.
+ if (paneIds.isNotEmpty) return paneIds.every((id) => id == machineId);
+ if (swarm.orchestratorMachineId != null &&
+ swarm.orchestratorMachineId!.isNotEmpty) {
+ return swarm.orchestratorMachineId == machineId;
+ }
+ if (swarm.titleMachineId != null && swarm.titleMachineId!.isNotEmpty) {
+ return swarm.titleMachineId == machineId;
+ }
+ return true;
+}
+
+/// After [closedIndex] is removed, the visible tab that should come forward.
+/// The hidden tabs in between are not candidates. Null when none are visible.
+String? profileNeighborId(
+ List<Swarm> swarms,
+ String? machineId,
+ int closedIndex,
+) {
+ Swarm? fallback;
+ for (var i = 0; i < swarms.length; i++) {
+ if (!swarmMatchesMachineProfile(swarms[i], machineId)) continue;
+ fallback = swarms[i];
+ if (i >= closedIndex) return swarms[i].id;
+ }
+ return fallback?.id;
+}
+
+/// Tabs this window shows for [machineId]. The underlying list is not copied
+/// and is not filtered in place: the desk keeps every machine's tabs.
- List<Swarm> swarmsForMachineProfile(List<Swarm> swarms, String? machineId) => [
- for (final swarm in swarms)
- if (swarmMatchesMachineProfile(swarm, machineId)) swarm,
- ];
++///
++/// A profile only hides. When it would hide every tab, this window shows them
++/// all rather than a tab being made to stand in: making one would add it to
++/// the account desk, on every computer.
++List<Swarm> swarmsForMachineProfile(List<Swarm> swarms, String? machineId) {
++ final shown = [
++ for (final swarm in swarms)
++ if (swarmMatchesMachineProfile(swarm, machineId)) swarm,
++ ];
++ return shown.isEmpty ? swarms : shown;
++}
diff --cc desktop/test/machine_profile_test.dart
index 046e40836,000000000..e71a98e26
mode 100644,000000..100644
--- a/desktop/test/machine_profile_test.dart
+++ b/desktop/test/machine_profile_test.dart
@@@ -1,58 -1,0 +1,68 @@@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/state/machine_profile.dart';
+import 'package:harness/state/swarm.dart';
+import 'package:harness/state/terminal_pane.dart';
+
+Swarm tab(
+ String id,
+ List<String> machines, {
+ String? titleMachine,
+ String kind = 'harness',
+}) {
+ final swarm = Swarm(id: id, name: id, kind: kind)
+ ..titleMachineId = titleMachine;
+ for (var i = 0; i < machines.length; i++) {
+ swarm.panes.add(TerminalPane(id: i, machineId: machines[i], agentId: 'a$i'));
+ }
+ return swarm;
+}
+
+void main() {
+ test('no profile shows every tab', () {
+ final tabs = [tab('local', ['m1']), tab('remote', ['m2'])];
+ expect(swarmsForMachineProfile(tabs, null).map((s) => s.id), ['local', 'remote']);
+ expect(swarmsForMachineProfile(tabs, '').map((s) => s.id), ['local', 'remote']);
+ });
+
+ test('a machine profile keeps that computer and drops the other', () {
+ final store = Swarm(id: 'store', name: Swarm.storeName, kind: 'store');
+ final blank = Swarm(id: 'blank');
+ final local = tab('local', ['m1']);
+ final remote = tab('remote', ['m2'], titleMachine: 'm2');
+ final mixed = tab('mixed', ['m1', 'm2']);
+ final shown = swarmsForMachineProfile([store, blank, local, remote, mixed], 'm1');
+ expect(shown.map((s) => s.id), ['store', 'blank', 'local']);
+ });
+
+ test('a tab titled for another computer stays out even with no pane yet', () {
+ final named = Swarm(id: 'remote-blank')..titleMachineId = 'm2';
+ expect(swarmMatchesMachineProfile(named, 'm1'), isFalse);
+ expect(swarmMatchesMachineProfile(named, 'm2'), isTrue);
+ });
+
+ test('a stale title does not hide a tab whose agents are all on this computer', () {
+ final local = tab('local', ['m1'])..titleMachineId = 'm2';
+ expect(swarmMatchesMachineProfile(local, 'm1'), isTrue);
+ expect(swarmMatchesMachineProfile(local, 'm2'), isFalse);
+ });
+
+ test('closing a visible tab does not land on a hidden one in between', () {
+ final local = tab('local', ['m1']);
+ final remote = tab('remote', ['m2']);
+ final store = Swarm(id: 'store', name: Swarm.storeName, kind: 'store');
+ final swarms = [local, remote, store];
+ swarms.removeAt(0);
+ expect(profileNeighborId(swarms, 'm1', 0), 'store');
+ expect(profileNeighborId([remote], 'm1', 0), isNull);
+ });
++
++ test('a profile that would hide every tab shows them all and adds none', () {
++ final remote = tab('remote', ['m2']);
++ final mixed = tab('mixed', ['m1', 'm2']);
++ final desk = [remote, mixed];
++ final shown = swarmsForMachineProfile(desk, 'm1');
++ expect(shown.map((s) => s.id), ['remote', 'mixed']);
++ // Only hides: the desk itself is never rewritten or padded.
++ expect(desk.map((s) => s.id), ['remote', 'mixed']);
++ });
+}
diff --cc desktop/test/settings_section_test.dart
index 2a14617e0,3d4c3b488..822769f35
--- a/desktop/test/settings_section_test.dart
+++ b/desktop/test/settings_section_test.dart
@@@ -33,9 -34,10 +34,11 @@@ void main()
// there is nothing here for a shipped build to hide.
SettingsSection.usage,
SettingsSection.customize,
- SettingsSection.devices,
+ SettingsSection.notifications,
+ SettingsSection.experimental,
+ if (!kIsWeb) SettingsSection.devices,
SettingsSection.account,
+ SettingsSection.profiles,
SettingsSection.shortcuts,
SettingsSection.about,
]);