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.

fix(desktop): a New Tab under a machine profile keeps the other tabs in sight, and closes (#2513)

Bubu-Dudu-52hz229512a7717e
diff --git a/desktop/lib/state/machine_profile.dart b/desktop/lib/state/machine_profile.dart
index 1420b56a9..b6c7cc02e 100644
--- a/desktop/lib/state/machine_profile.dart
+++ b/desktop/lib/state/machine_profile.dart
@@ -51,10 +51,24 @@ String? profileNeighborId(
/// 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.
+///
+/// Whether any tab is the computer's own is asked of the tabs that name a
+/// computer: one with no agent yet matches every profile, so a New Tab opened
+/// under a profile none of the tabs were on hid all of them, and was then the
+/// last tab in sight, which ⌘W does not close.
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;
+ return shown.any(_namesAMachine) ? shown : swarms;
+}
+
+/// A tab whose membership comes from a computer: its agents, its orchestrator
+/// or its title's. Not the Store, a Super Tab or a tab with nothing in it yet.
+bool _namesAMachine(Swarm swarm) {
+ if (swarm.isUtility || swarm.isSuperTab) return false;
+ return swarm.panes.any((pane) => pane.machineId.isNotEmpty) ||
+ (swarm.orchestratorMachineId?.isNotEmpty ?? false) ||
+ (swarm.titleMachineId?.isNotEmpty ?? false);
}
diff --git a/desktop/test/machine_profile_test.dart b/desktop/test/machine_profile_test.dart
index 91ef0eed9..00f852eb2 100644
--- a/desktop/test/machine_profile_test.dart
+++ b/desktop/test/machine_profile_test.dart
@@ -71,4 +71,14 @@ void main() {
// Only hides: the desk itself is never rewritten or padded.
expect(desk.map((s) => s.id), ['remote', 'mixed']);
});
+
+ test('a New Tab under a profile with no tab of its own keeps every tab in '
+ 'sight', () {
+ final remote = tab('remote', ['m2']);
+ final mixed = tab('mixed', ['m1', 'm2']);
+ final opened = Swarm(id: 'new', isNewTabPage: true);
+ final shown = swarmsForMachineProfile([remote, mixed, opened], 'm1');
+ // Not the New Tab alone — the last tab in sight, which ⌘W leaves open.
+ expect(shown.map((s) => s.id), ['remote', 'mixed', 'new']);
+ });
}