The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(desktop): move a pane to another tab (#252)
Deec35acf53a4b0
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 63c05a939..40154fe02 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -39,6 +39,7 @@ import '../state/swarm.dart';import '../state/terminal_pane.dart';import '../widgets/transient_menus.dart';import '../widgets/layout_palette.dart';+import '../widgets/move_pane_palette.dart';import '../widgets/engine_identity.dart';import '../store/store_mark.dart';import '../store/store_screen.dart';@@ -1010,6 +1011,10 @@ class _SwarmScreenState extends State<SwarmScreen>unawaited(_splitAgent(PaneResizeAxis.x));case 'splitDown':unawaited(_splitAgent(PaneResizeAxis.y));+ case 'movePaneToTab':+ if (app.focusedPaneId != null) {+ _dialog(() => showMovePanePalette(context, app));+ }case 'zoomPane':app.toggleZoomPane();case 'pinPane':@@ -2579,6 +2584,10 @@ class _SwarmScreenState extends State<SwarmScreen>ShortcutAction.reload: app.retryMachines,ShortcutAction.showLayout: () =>_dialog(() => showLayoutPalette(context, app)),+ ShortcutAction.movePaneToTab: () {+ if (app.focusedPaneId == null) return;+ _dialog(() => showMovePanePalette(context, app));+ },ShortcutAction.pinPane: () {if (app.focusedPaneId != null) {app.togglePinPane(app.focusedPaneId!);diff --git a/desktop/lib/shortcuts/app_shortcuts.dart b/desktop/lib/shortcuts/app_shortcuts.dartindex a817e0510..cc404f15d 100644--- a/desktop/lib/shortcuts/app_shortcuts.dart+++ b/desktop/lib/shortcuts/app_shortcuts.dart@@ -36,6 +36,9 @@ enum ShortcutAction {movePaneUp,movePaneDown,+ /// Send the focused pane to another tab, terminal and all.+ movePaneToTab,+/// The agent this window was on before the current one — tmux's `prefix ;`.lastPane,@@ -214,6 +217,16 @@ const List<AppShortcut> kAppShortcuts = [label: 'Move this pane right',group: ShortcutGroup.panes,),+ AppShortcut(+ action: ShortcutAction.movePaneToTab,+ activator: SingleActivator(+ LogicalKeyboardKey.keyM,+ meta: true,+ shift: true,+ ),+ label: 'Move this pane to another tab',+ group: ShortcutGroup.panes,+ ),// ⌘⏎ — tmux's `prefix z`, one of the most-pressed keys that multiplexer has.// Enter because it reads as "make THIS the thing", and because it is the onediff --git a/desktop/lib/shortcuts/keymap_commands.dart b/desktop/lib/shortcuts/keymap_commands.dartindex fd8e51d12..826298c58 100644--- a/desktop/lib/shortcuts/keymap_commands.dart+++ b/desktop/lib/shortcuts/keymap_commands.dart@@ -208,6 +208,14 @@ final harnessCommands = <HarnessCommand>[action: ShortcutAction.movePaneDown,repeatable: true,),+ const HarnessCommand(+ 'pane.move_to_tab',+ 'Move the pane to another tab',+ ShortcutGroup.panes,+ action: ShortcutAction.movePaneToTab,+ nativeAction: 'movePaneToTab',+ keywords: ['send', 'tab', 'another'],+ ),const HarnessCommand('pane.zoom','Zoom or restore the focused pane',diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex d9359afc2..40a03e155 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -8762,6 +8762,114 @@ class AppNotifier extends ChangeNotifier {}}+ /// Move a pane to another tab, terminal and all.+ ///+ /// The tile is the SAME [TerminalPane] on the other side — never a fresh one+ /// — which is what keeps the terminal attached: the session hangs off the+ /// pane ([TerminalPane.session]), the cell is a `GlobalKey`, and+ /// `TerminalPanel` is built to survive a change of tab without remounting.+ /// Closing here and opening there would tear the session down and ask the+ /// daemon to open it again, losing the viewport and the scrollback.+ ///+ /// Refuses rather than half-moves: an unknown pane or tab, the tab it is+ /// already on, and a destination at [maxPanes] all leave everything as it+ /// was, the last one with the same message [assignAgentToPane] gives.+ ///+ /// A destination already showing this agent takes the move as a plain close+ /// here — one membership per tab, the rule [assignAgentToPane] keeps.+ bool movePaneToSwarm(int paneId, String swarmId, {bool follow = true}) {+ final source = activeSwarm;+ final pane = source.panes.where((p) => p.id == paneId).firstOrNull;+ final target = swarms.where((swarm) => swarm.id == swarmId).firstOrNull;+ if (pane == null || target == null || target.id == source.id) return false;+ final twin = pane.agentId == null+ ? null+ : target.panes+ .where(+ (p) =>+ p.machineId == pane.machineId && p.agentId == pane.agentId,+ )+ .firstOrNull;+ if (twin == null && target.panes.length >= maxPanes) {+ _lastError =+ 'That tab holds $maxPanes agents. Close one there to move this in.';+ _lastErrorRetryable = false;+ notifyListeners();+ return false;+ }+ source.remove(pane);+ // The tab left behind re-tiles. `Swarm.remove` keeps the shape by carrying+ // the manual layout down a tile — right when a pane CLOSES, because the+ // split was drawn around the tiles that remain. A tile that left for+ // another tab is not that: what is left here is a different set, and+ // holding the old proportions leaves it visibly lopsided. A layout chosen+ // outright in the Layout palette still stands; only the dragged sizes go.+ source.paneSizes.removeWhere(+ (key, _) => key.startsWith('${source.panes.length}:'),+ );+ source.arranged = null;+ source.arrangedKey = null;+ // A harness's viewer lives beside its terminal, so it travels with it —+ // the same rule `closePane` keeps when the terminal goes.+ final viewers = <TerminalPane>[];+ if (!pane.isWeb && pane.agentId != null) {+ for (final viewer in source.panes.toList()) {+ if (viewer.isWeb &&+ viewer.machineId == pane.machineId &&+ viewer.ownerAgentId == pane.agentId) {+ source.remove(viewer);+ viewers.add(viewer);+ }+ }+ }+ if (twin == null) {+ final firstAgent = target.panes.every((pane) => pane.agentId == null);+ target.panes.add(pane);+ // A tab that had no harness in it takes this one's name, the way it+ // would for a harness opened into it.+ if (firstAgent && !target.nameIsCustom && pane.agentId != null) {+ final agent = machineStates[pane.machineId]?.agents+ .where((agent) => agent.id == pane.agentId)+ .firstOrNull;+ target.titleMachineId = pane.machineId;+ target.titleAgentId = pane.agentId;+ target.name = agent == null || agent.displayName == kUntitledPane+ ? Swarm.defaultName+ : agent.displayName;+ }+ for (final viewer in viewers) {+ if (target.panes.length >= maxPanes) break;+ target.panes.add(viewer);+ }+ // The destination reflows for a tile it has never held, exactly as it+ // would for a new one: remembered shapes for the old count cannot decide+ // where this lands.+ target.presets.remove(target.panes.length);+ target.paneSizes.removeWhere(+ (key, _) => key.startsWith('${target.panes.length}:'),+ );+ target.arranged = null;+ target.arrangedKey = null;+ if (target.focusedPaneId != pane.id) {+ target.previousPaneId = target.focusedPaneId;+ target.focusedPaneId = pane.id;+ }+ if (target.zoomedPaneId != null) target.zoomedPaneId = pane.id;+ }+ _settlePins();+ if (follow) {+ _activeSwarmId = target.id;+ railFocused = false;+ _noteNavigation();+ _paneFocusRequest++;+ }+ selectedMachineId = focusedPane?.machineId;+ _persistLayout();+ _announceAppFocus();+ notifyListeners();+ return true;+ }+Future<void> closePane(int paneId, {bool persist = true}) async {final pane = panes.where((p) => p.id == paneId).firstOrNull;if (pane == null) return;diff --git a/desktop/lib/widgets/move_pane_palette.dart b/desktop/lib/widgets/move_pane_palette.dartnew file mode 100644index 000000000..757978f76--- /dev/null+++ b/desktop/lib/widgets/move_pane_palette.dart@@ -0,0 +1,267 @@+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';++import '../shared/theme/app_theme.dart' as grid;+import '../shared/widgets/app_dialog.dart';+import '../state/app_state.dart';++/// ⇧⌘M — send the focused pane to another tab.+///+/// A list, not a grid: tabs are told apart by their NAMES, and a name is read,+/// not recognised by shape — which is the one thing that makes this different+/// from the layout palette it otherwise copies (arrows walk, digits jump,+/// Enter takes, Escape leaves).+///+/// The destinations are every other tab plus a new one. The Store tab is not+/// among them: it holds a storefront, not harnesses, and a terminal dropped+/// there would have nowhere to draw.+Future<void> showMovePanePalette(BuildContext context, AppNotifier notifier) {+ if (notifier.focusedPaneId == null) return Future<void>.value();+ return showAppDialog<void>(+ context: context,+ builder: (context) => _MovePanePalette(notifier: notifier),+ );+}++/// One row: an existing tab, or the new one at the end.+class _Destination {+ const _Destination({required this.label, required this.detail, this.id});++ /// Null for "New Tab" — the tab does not exist until it is chosen.+ final String? id;+ final String label;+ final String detail;+}++List<_Destination> _destinationsFor(AppNotifier notifier) => [+ for (final swarm in notifier.swarms)+ if (swarm.id != notifier.activeSwarmId && !swarm.isStore)+ _Destination(+ id: swarm.id,+ label: swarm.name,+ detail: switch (swarm.panes+ .where((pane) => pane.agentId != null)+ .length) {+ 0 => 'empty',+ 1 => '1 harness',+ final count => '$count harnesses',+ },+ ),+ const _Destination(label: 'New Tab', detail: 'a tab of its own'),+];++class _MovePanePalette extends StatefulWidget {+ const _MovePanePalette({required this.notifier});++ final AppNotifier notifier;++ @override+ State<_MovePanePalette> createState() => _MovePanePaletteState();+}++class _MovePanePaletteState extends State<_MovePanePalette> {+ /// An explicit node, requested after the first frame: the route that opened+ /// this has already settled focus somewhere, so `autofocus` alone leaves the+ /// arrow keys unheard. Same reason the layout palette keeps one.+ final FocusNode _keys = FocusNode(debugLabel: 'move-pane-palette');+ int _cursor = 0;++ @override+ void initState() {+ super.initState();+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (mounted) _keys.requestFocus();+ });+ }++ @override+ void dispose() {+ _keys.dispose();+ super.dispose();+ }++ void _take(_Destination destination) {+ final notifier = widget.notifier;+ final paneId = notifier.focusedPaneId;+ Navigator.of(context).pop();+ if (paneId == null) return;+ var targetId = destination.id;+ if (targetId == null) {+ // The tab is made from here, then stepped back out of, because the move+ // reads the pane from the tab in front: `newSwarm` selects what it makes.+ final source = notifier.activeSwarmId;+ notifier.newSwarm(newTabPage: true);+ targetId = notifier.activeSwarmId;+ if (targetId == source) return;+ notifier.selectSwarm(source);+ }+ notifier.movePaneToSwarm(paneId, targetId);+ }++ KeyEventResult _onKey(FocusNode node, KeyEvent event) {+ if (event is! KeyDownEvent && event is! KeyRepeatEvent) {+ return KeyEventResult.ignored;+ }+ final destinations = _destinationsFor(widget.notifier);+ final key = event.logicalKey;+ if (key == LogicalKeyboardKey.escape) {+ Navigator.of(context).pop();+ return KeyEventResult.handled;+ }+ if (key == LogicalKeyboardKey.enter ||+ key == LogicalKeyboardKey.numpadEnter) {+ _take(destinations[_cursor.clamp(0, destinations.length - 1)]);+ return KeyEventResult.handled;+ }+ if (key == LogicalKeyboardKey.arrowDown || key == LogicalKeyboardKey.tab) {+ setState(() => _cursor = (_cursor + 1) % destinations.length);+ return KeyEventResult.handled;+ }+ if (key == LogicalKeyboardKey.arrowUp) {+ setState(+ () =>+ _cursor = (_cursor - 1 + destinations.length) % destinations.length,+ );+ return KeyEventResult.handled;+ }+ // ⌘1–⌘9 select a tab, so the same digits pick one here.+ for (var i = 0; i < 9 && i < destinations.length; i++) {+ if (key == _digits[i]) {+ _take(destinations[i]);+ return KeyEventResult.handled;+ }+ }+ return KeyEventResult.ignored;+ }++ static const _digits = [+ LogicalKeyboardKey.digit1,+ LogicalKeyboardKey.digit2,+ LogicalKeyboardKey.digit3,+ LogicalKeyboardKey.digit4,+ LogicalKeyboardKey.digit5,+ LogicalKeyboardKey.digit6,+ LogicalKeyboardKey.digit7,+ LogicalKeyboardKey.digit8,+ LogicalKeyboardKey.digit9,+ ];++ @override+ Widget build(BuildContext context) {+ grid.AppTheme.watch(context);+ final destinations = _destinationsFor(widget.notifier);+ final cursor = _cursor.clamp(0, destinations.length - 1);+ return Focus(+ focusNode: _keys,+ onKeyEvent: _onKey,+ child: Dialog(+ key: const ValueKey('move-pane-palette'),+ backgroundColor: grid.AppGlass.surfaceFill,+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(13),+ side: BorderSide(color: grid.AppGlass.hair),+ ),+ child: SizedBox(+ width: 360,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ mainAxisSize: MainAxisSize.min,+ children: [+ Padding(+ padding: const EdgeInsets.fromLTRB(14, 12, 14, 8),+ child: Text(+ 'Move pane to',+ style: grid.AppType.heading(+ color: grid.AppPalette.textPrimary,+ ),+ ),+ ),+ for (var i = 0; i < destinations.length; i++)+ _Row(+ destination: destinations[i],+ index: i,+ selected: i == cursor,+ onTap: () => _take(destinations[i]),+ onHover: () => setState(() => _cursor = i),+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(14, 8, 14, 12),+ child: Text(+ '↑↓ choose · ⏎ move · esc cancel',+ style: grid.AppType.monoMeta(+ color: grid.AppPalette.textFaint,+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ );+ }+}++class _Row extends StatelessWidget {+ const _Row({+ required this.destination,+ required this.index,+ required this.selected,+ required this.onTap,+ required this.onHover,+ });++ final _Destination destination;+ final int index;+ final bool selected;+ final VoidCallback onTap;+ final VoidCallback onHover;++ @override+ Widget build(BuildContext context) {+ final ink = selected+ ? grid.AppPalette.textPrimary+ : grid.AppPalette.textSecondary;+ return MouseRegion(+ onEnter: (_) => onHover(),+ child: GestureDetector(+ onTap: onTap,+ behavior: HitTestBehavior.opaque,+ child: Container(+ key: ValueKey('move-pane-destination-$index'),+ margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 1),+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 7),+ decoration: BoxDecoration(+ color: selected ? grid.AppSurface.selectedFill : null,+ borderRadius: BorderRadius.circular(5),+ ),+ child: Row(+ children: [+ SizedBox(+ width: 18,+ child: Text(+ index < 9 ? '${index + 1}' : '',+ style: grid.AppType.monoMeta(+ color: grid.AppPalette.textFaint,+ ),+ ),+ ),+ Expanded(+ child: Text(+ destination.label,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: grid.AppType.label(color: ink),+ ),+ ),+ const SizedBox(width: 8),+ Text(+ destination.detail,+ style: grid.AppType.monoMeta(color: grid.AppPalette.textFaint),+ ),+ ],+ ),+ ),+ ),+ );+ }+}diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swiftindex e23fc2f8d..e92db8583 100644--- a/desktop/macos/Runner/SwarmTitlebar.swift+++ b/desktop/macos/Runner/SwarmTitlebar.swift@@ -155,7 +155,7 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {}private func sendTabAction(_ method: String, arguments: Any?) {- guard ["select", "close", "new", "rename", "commands", "notifications", "store", "sessions", "addAgent", "newAgent", "newTerminal", "cloneAgent", "runLocalModel", "splitRight", "splitDown", "zoomPane", "pinPane", "machineDestination", "machineAgent", "manageMachines", "machineList"].contains(method) else {+ guard ["select", "close", "new", "rename", "commands", "notifications", "store", "sessions", "addAgent", "newAgent", "newTerminal", "cloneAgent", "movePaneToTab", "runLocalModel", "splitRight", "splitDown", "zoomPane", "pinPane", "machineDestination", "machineAgent", "manageMachines", "machineList"].contains(method) else {channel.invokeMethod(method, arguments: arguments)return}@@ -295,7 +295,7 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {"cloneAgent": "plus.square.on.square","renameActive": "pencil", "closeActive": "xmark","splitRight": "rectangle.split.2x1", "splitDown": "rectangle.split.1x2",- "zoomPane": "viewfinder", "closePane": "xmark",+ "zoomPane": "viewfinder", "movePaneToTab": "arrow.right.square", "closePane": "xmark","commands": "command", "notifications": "bell",]if let symbol = symbols[action] {@@ -325,6 +325,7 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {add(file, "Split Right", "r", "splitRight")add(file, "Split Down", "d", "splitDown")add(file, "Zoom Pane", "", "zoomPane")+ add(file, "Move Pane to Tab", "m", "movePaneToTab", [.command, .shift])add(file, "Close Pane", "w", "closePane", [.command, .shift])install(file, at: 1)@@ -779,7 +780,7 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {return actionsEnabled && (action != "reopen" || canReopen) &&(action != "historyBack" || canGoBack) && (action != "historyForward" || canGoForward) &&(action != "closePane" || canClosePane) &&- (!["findTerminal", "findNext", "findPrevious", "splitRight", "splitDown", "zoomPane", "pinPane"].contains(action) || canFind)+ (!["findTerminal", "findNext", "findPrevious", "splitRight", "splitDown", "zoomPane", "pinPane", "movePaneToTab"].contains(action) || canFind)}@objc private func menuAction(_ sender: NSMenuItem) {diff --git a/desktop/test/move_pane_palette_test.dart b/desktop/test/move_pane_palette_test.dartnew file mode 100644index 000000000..92e163f38--- /dev/null+++ b/desktop/test/move_pane_palette_test.dart@@ -0,0 +1,145 @@+// Choosing where a pane goes.+//+// The list is the other tabs and a new one. Arrows walk it, digits and clicks+// take a row outright, and Escape leaves the tile where it was — the same+// grammar the layout palette uses, on names instead of shapes.+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';++import 'package:harness/state/app_state.dart';+import 'package:harness/state/terminal_pane.dart';+import 'package:harness/widgets/move_pane_palette.dart';++import 'swarm_state_test.dart' show createApp;++List<String?> _agentsOf(AppNotifier app, String swarmId) => [+ for (final pane in app.swarms.firstWhere((s) => s.id == swarmId).panes)+ pane.agentId,+];++/// One tab with two harnesses in front, [others] named tabs behind it.+Future<(AppNotifier, String)> _open(+ WidgetTester tester, {+ List<String> others = const ['Second'],+}) async {+ final app = createApp();+ addTearDown(app.dispose);+ final source = app.activeSwarmId;+ for (var i = 0; i < 2; i++) {+ app.panes.add(TerminalPane(id: i, machineId: 'm', agentId: 'a$i'));+ }+ for (final name in others) {+ app.newSwarm(name: name);+ }+ app.selectSwarm(source);+ app.focusPane(0);+ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => TextButton(+ onPressed: () => showMovePanePalette(context, app),+ child: const Text('open'),+ ),+ ),+ ),+ );+ await tester.tap(find.text('open'));+ await tester.pumpAndSettle();+ return (app, source);+}++void main() {+ testWidgets('it lists the other tabs, and a new one last', (tester) async {+ await _open(tester, others: const ['Second', 'Third']);++ expect(find.text('Second'), findsOneWidget);+ expect(find.text('Third'), findsOneWidget);+ expect(find.text('New Tab'), findsOneWidget);+ expect(+ find.byKey(const ValueKey('move-pane-destination-2')),+ findsOneWidget,+ reason: 'two tabs and the new one',+ );+ });++ testWidgets('a click sends the tile there and follows it', (tester) async {+ final (app, source) = await _open(tester);++ await tester.tap(find.text('Second'));+ await tester.pumpAndSettle();++ final target = app.swarms.firstWhere((s) => s.name == 'Second').id;+ expect(_agentsOf(app, source), ['a1']);+ expect(_agentsOf(app, target), ['a0']);+ expect(app.activeSwarmId, target);+ expect(find.byKey(const ValueKey('move-pane-palette')), findsNothing);+ });++ testWidgets('a digit takes the row it numbers', (tester) async {+ final (app, source) = await _open(tester, others: const ['Second', 'Third']);++ await tester.sendKeyEvent(LogicalKeyboardKey.digit2);+ await tester.pumpAndSettle();++ final third = app.swarms.firstWhere((s) => s.name == 'Third').id;+ expect(_agentsOf(app, third), ['a0']);+ expect(_agentsOf(app, source), ['a1']);+ });++ testWidgets('the arrows walk the list and Enter takes it', (tester) async {+ final (app, _) = await _open(tester, others: const ['Second', 'Third']);++ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);+ await tester.pumpAndSettle();++ final third = app.swarms.firstWhere((s) => s.name == 'Third').id;+ expect(_agentsOf(app, third), ['a0']);+ });++ testWidgets('the last row opens a tab of its own', (tester) async {+ final (app, source) = await _open(tester);+ final before = app.swarms.length;++ await tester.tap(find.text('New Tab'));+ await tester.pumpAndSettle();++ expect(app.swarms.length, before + 1);+ expect(_agentsOf(app, source), ['a1']);+ expect(_agentsOf(app, app.activeSwarmId), ['a0']);+ });++ testWidgets('Escape leaves every tile where it was', (tester) async {+ final (app, source) = await _open(tester);++ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();++ expect(_agentsOf(app, source), ['a0', 'a1']);+ expect(app.activeSwarmId, source);+ expect(find.byKey(const ValueKey('move-pane-palette')), findsNothing);+ });++ testWidgets('with no pane focused there is nothing to move', (tester) async {+ final app = createApp();+ addTearDown(app.dispose);+ app.newSwarm(name: 'Second');+ app.selectSwarm(app.swarms.first.id);+ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => TextButton(+ onPressed: () => showMovePanePalette(context, app),+ child: const Text('open'),+ ),+ ),+ ),+ );++ await tester.tap(find.text('open'));+ await tester.pumpAndSettle();++ expect(find.byKey(const ValueKey('move-pane-palette')), findsNothing);+ });+}diff --git a/desktop/test/pane_move_to_tab_test.dart b/desktop/test/pane_move_to_tab_test.dartnew file mode 100644index 000000000..99e92d46d--- /dev/null+++ b/desktop/test/pane_move_to_tab_test.dart@@ -0,0 +1,198 @@+// Moving a tile to another tab is a change of membership, not a close and a+// reopen: the same TerminalPane — and so the same live terminal — comes out the+// other side. These pin that, and the bookkeeping the destination inherits.+import 'package:flutter_test/flutter_test.dart';++import 'dart:ui';++import 'package:harness/state/app_state.dart';+import 'package:harness/state/pane_arrangement.dart';+import 'package:harness/state/pane_preset.dart';+import 'package:harness/state/terminal_pane.dart';++import 'swarm_state_test.dart' show createApp;++List<String?> agentsOf(AppNotifier n, String swarmId) => [+ for (final pane in n.swarms.firstWhere((s) => s.id == swarmId).panes)+ pane.agentId,+];++/// Two tabs: the first holding [count] agents, the second empty and returned.+(AppNotifier, String, String) twoTabs({int count = 2}) {+ final app = createApp();+ final source = app.activeSwarmId;+ for (var i = 0; i < count; i++) {+ app.panes.add(TerminalPane(id: i, machineId: 'm', agentId: 'a$i'));+ }+ app.newSwarm();+ final target = app.activeSwarmId;+ app.selectSwarm(source);+ return (app, source, target);+}++void main() {+ test('the tile lands on the other tab and leaves this one', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);+ app.focusPane(0);++ expect(app.movePaneToSwarm(0, target), isTrue);++ expect(agentsOf(app, source), ['a1']);+ expect(agentsOf(app, target), ['a0']);+ });++ test('the same tile object moves, so its terminal is never reopened', () {+ final (app, _, target) = twoTabs();+ addTearDown(app.dispose);+ final moved = app.panes.firstWhere((pane) => pane.id == 0);++ app.movePaneToSwarm(0, target);++ final landed = app.swarms+ .firstWhere((swarm) => swarm.id == target)+ .panes+ .single;+ expect(identical(landed, moved), isTrue);+ });++ test('the view follows the tile, which is then the focused one', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);+ app.focusPane(0);++ app.movePaneToSwarm(0, target);++ expect(app.activeSwarmId, target);+ expect(app.focusedPaneId, 0);++ app.selectSwarm(source);+ expect(+ app.focusedPaneId,+ 1,+ reason: 'the tab left behind hands focus to a neighbour',+ );+ });++ test('staying put is a choice the caller has', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);++ app.movePaneToSwarm(0, target, follow: false);++ expect(app.activeSwarmId, source);+ expect(agentsOf(app, target), ['a0']);+ });++ test('an unknown tile, an unknown tab, or this tab, all change nothing', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);++ expect(app.movePaneToSwarm(99, target), isFalse);+ expect(app.movePaneToSwarm(0, 'no-such-tab'), isFalse);+ expect(app.movePaneToSwarm(0, source), isFalse);++ expect(agentsOf(app, source), ['a0', 'a1']);+ expect(agentsOf(app, target), isEmpty);+ });++ test('a destination already holding the agent takes it as a close', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);+ app.swarms+ .firstWhere((swarm) => swarm.id == target)+ .panes+ .add(TerminalPane(id: 7, machineId: 'm', agentId: 'a0'));++ expect(app.movePaneToSwarm(0, target), isTrue);++ expect(agentsOf(app, source), ['a1']);+ expect(agentsOf(app, target), [+ 'a0',+ ], reason: 'one membership per tab, never the agent twice');+ });++ test('a full destination refuses, and says where to make room', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);+ final full = app.swarms.firstWhere((swarm) => swarm.id == target);+ for (var i = 0; i < AppNotifier.maxPanes; i++) {+ full.panes.add(TerminalPane(id: 100 + i, machineId: 'm', agentId: 'b$i'));+ }++ expect(app.movePaneToSwarm(0, target), isFalse);++ expect(agentsOf(app, source), ['a0', 'a1']);+ expect(full.panes.length, AppNotifier.maxPanes);+ expect(app.lastError, contains('Close one there'));+ });++ test('the harness viewer travels beside its terminal', () {+ final (app, source, target) = twoTabs();+ addTearDown(app.dispose);+ app.panes.add(+ TerminalPane(+ id: 5,+ machineId: 'm',+ kind: PaneKind.web,+ ownerAgentId: 'a0',+ url: 'http://127.0.0.1:1/',+ ),+ );++ app.movePaneToSwarm(0, target);++ expect(agentsOf(app, source), ['a1']);+ final landed = app.swarms.firstWhere((swarm) => swarm.id == target).panes;+ expect(landed.map((pane) => pane.id), [0, 5]);+ });++ test('the tab left behind re-tiles instead of keeping a lopsided split', () {+ // Panes opened with Split Right/Down save a manual layout, so a tab that+ // never had a divider dragged still has one. Carrying it down a tile — what+ // a close does — leaves the rest at proportions drawn for a tile that is no+ // longer there.+ final (app, source, target) = twoTabs(count: 3);+ addTearDown(app.dispose);+ app.activeSwarm.savePaneSizes(+ '3:manual',+ PaneArrangement(const [+ Rect.fromLTRB(0, 0, .7, 1),+ Rect.fromLTRB(.7, 0, 1, .5),+ Rect.fromLTRB(.7, .5, 1, 1),+ ]),+ );++ app.movePaneToSwarm(1, target, follow: false);++ final left = app.swarms.firstWhere((swarm) => swarm.id == source);+ expect(left.panes.length, 2);+ expect(left.paneSizes['2:manual'], isNull);+ expect(left.arranged, isNull);+ });++ test('a layout chosen outright still stands after a move', () {+ final (app, source, target) = twoTabs(count: 3);+ addTearDown(app.dispose);+ app.setPreset(2, PanePreset.rows);++ app.movePaneToSwarm(1, target, follow: false);++ final left = app.swarms.firstWhere((swarm) => swarm.id == source);+ expect(left.presets[2], PanePreset.rows);+ });++ test('the destination forgets a shape it remembered for this count', () {+ final (app, _, target) = twoTabs();+ addTearDown(app.dispose);+ final destination = app.swarms.firstWhere((swarm) => swarm.id == target);+ destination.panes.add(TerminalPane(id: 8, machineId: 'm', agentId: 'b0'));+ destination.presets[2] = PanePreset.columns;+ destination.arrangedKey = '2:manual';++ app.movePaneToSwarm(0, target);++ expect(destination.presets[2], isNull);+ expect(destination.arrangedKey, isNull);+ });+}diff --git a/desktop/tool/swarm_titlebar_checks.swift b/desktop/tool/swarm_titlebar_checks.swiftindex bb954a1d7..89974b606 100644--- a/desktop/tool/swarm_titlebar_checks.swift+++ b/desktop/tool/swarm_titlebar_checks.swift@@ -708,7 +708,7 @@ private extension SwarmTitlebar {"New Terminal stays off the File menu; its chord lives in the keymap")let historyMenu = main.item(withTitle: "History")!.submenu!try checkTitlebar(agent.items.contains { $0.title == "Clone Harness" && $0.representedObject as? String == "cloneAgent" }, "Clone Harness preserves its action")- try checkTitlebar(agent.items.map { $0.isSeparatorItem ? "separator" : ($0.representedObject as? String ?? "") } == ["newAgent", "addAgent", "cloneAgent", "separator", "new", "renameActive", "closeActive", "separator", "splitRight", "splitDown", "zoomPane", "closePane"], "File groups harness, tab and pane actions, harnesses first")+ try checkTitlebar(agent.items.map { $0.isSeparatorItem ? "separator" : ($0.representedObject as? String ?? "") } == ["newAgent", "addAgent", "cloneAgent", "separator", "new", "renameActive", "closeActive", "separator", "splitRight", "splitDown", "zoomPane", "movePaneToTab", "closePane"], "File groups harness, tab and pane actions, harnesses first")try checkTitlebar(agent.items.first?.title == "New Harness" && agent.items.first?.keyEquivalent == "n" && agent.items.first?.keyEquivalentModifierMask == [.command],"New Harness leads File on Command-N")for (action, title, key) in [("splitRight", "Split Right", "r"), ("splitDown", "Split Down", "d")] {@@ -726,6 +726,14 @@ private extension SwarmTitlebar {try checkTitlebar(agent.items.filter { !$0.isSeparatorItem }.allSatisfy { $0.image != nil && $0.toolTip == nil },"Every File action has a native icon and no hover hint")try checkTitlebar(agent.items.contains { $0.title == "Rename Tab" && $0.representedObject as? String == "renameActive" }, "Rename Tab preserves its command")+ let movePane = agent.items.first(where: { $0.representedObject as? String == "movePaneToTab" })!+ try checkTitlebar(movePane.title == "Move Pane to Tab" && movePane.keyEquivalent == "m" && movePane.keyEquivalentModifierMask == [.command, .shift],+ "Move Pane to Tab advertises Command-Shift-M")+ actionsEnabled = true+ canFind = false+ try checkTitlebar(!validateMenuItem(movePane), "Move Pane to Tab needs a focused pane")+ canFind = true+ try checkTitlebar(validateMenuItem(movePane), "Move Pane to Tab is available with a focused pane")try checkTitlebar(agent.items.contains { $0.title == "Close Tab" && $0.representedObject as? String == "closeActive" }, "Close Tab preserves its command")let commands = edit.submenu!.items.first(where: { $0.representedObject as? String == "commands" })!try checkTitlebar(commands.keyEquivalent == "p" && commands.keyEquivalentModifierMask == [.command], "Command search keeps its native menu owner")