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: implement tab closing functionality and machine selection in workspace
Dev jacob7b4e27a2c854
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex b25f29fd8..deceef8a9 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -73,6 +73,7 @@ import '../widgets/harness_activity_mark.dart';import '../widgets/workspace_status_line.dart';import '../widgets/workspace_pull_request_label.dart';import '../widgets/workspace_bar_control.dart';+import '../widgets/workspace_tab_close.dart';import '../widgets/session_work_dialog.dart';import '../widgets/web_download_button.dart';import '../widgets/workspace_share_button.dart';@@ -4967,6 +4968,13 @@ class _SwarmScreenState extends State<SwarmScreen> {}}+ /// View on a machine when the host asks it to close the picker: that+ /// machine becomes the one New Harness starts on.+ void _viewMachine(String machineId) {+ _dismissSearch();+ app.selectMachine(machineId);+ }+void _dismissSearch() {final target = _search?.targetId;_closeSearch();@@ -5175,6 +5183,9 @@ class _SwarmScreenState extends State<SwarmScreen> {onRefocus: _focusSearch,onModalChanged: _pickerModalChanged,onCommands: _showSearchCommands,+ onViewMachine: widget.chrome?.viewMachineCloses == true+ ? _viewMachine+ : null,);final terminalTheme = terminalThemeFor(grid.AppTheme.palette.value,@@ -6781,6 +6792,9 @@ class _SwarmScreenState extends State<SwarmScreen> {math.max(0.0, constraints.maxWidth - cell.width * 14),);final leadingWidth = chrome?.leadingWidth(context) ?? 0.0;+ final closeCells = chrome?.closesTabs == true+ ? kWorkspaceTabCloseCells+ : 0;final tabBudget = math.max(0.0,constraints.maxWidth -@@ -6793,12 +6807,15 @@ class _SwarmScreenState extends State<SwarmScreen> {_tabWidths = [for (var i = 0; i < labels.length; i++)math.max(- activities[i] == null ? 0 : ('${i + 1}:'.length + 4) * cell.width,+ activities[i] == null+ ? 0+ : ('${i + 1}:'.length + 4 + closeCells) * cell.width,math.min(math.min(labels[i].characters.length +2 +- (activities[i] == null ? 0 : 2),+ (activities[i] == null ? 0 : 2) ++ closeCells,24,) *cell.width,@@ -6887,77 +6904,86 @@ class _SwarmScreenState extends State<SwarmScreen> {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,- ),- )- : Row(- mainAxisSize: MainAxisSize.min,- children: [- Text(- '${index + 1}:',- style: workspaceBarTextStyle(- color: theme.foreground,- emphasized: emphasized,- ),+ child: _withTabClose(+ closeCells > 0,+ id: swarm.id,+ visible: selected || emphasized,+ color: theme.foreground,+ child: Center(+ child: activity == null+ ? Text(+ labels[index],+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.center,+ style: workspaceBarTextStyle(+ color: theme.foreground,+ emphasized: emphasized,),- Flexible(- child: Text(- names[swarm.id]!,- maxLines: 1,- overflow:- TextOverflow.ellipsis,+ )+ : Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ '${index + 1}:',style: workspaceBarTextStyle(color: theme.foreground,emphasized: emphasized,),),- ),- 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,- );- },- ),- ],- ),+ Flexible(+ child: Text(+ names[swarm.id]!,+ maxLines: 1,+ overflow:+ TextOverflow.ellipsis,+ style:+ workspaceBarTextStyle(+ color:+ theme.foreground,+ emphasized:+ emphasized,+ ),+ ),+ ),+ 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,+ );+ },+ ),+ ],+ ),+ ),),),),@@ -7045,6 +7071,23 @@ class _SwarmScreenState extends State<SwarmScreen> {/// A host's narrow bar (the web on a phone): its tab switcher in place of/// the tab list, and no Store button, which the host's menu already offers.+ /// A tab's label, with a close mark when the host closes tabs by mouse.+ Widget _withTabClose(+ bool closes, {+ required String id,+ required bool visible,+ required Color color,+ required Widget child,+ }) => !closes+ ? child+ : WorkspaceTabCloseSlot(+ tabId: id,+ visible: visible,+ color: color,+ onClose: () => unawaited(app.closeSwarm(id)),+ child: child,+ );+Widget _compactTabStrip(WorkspaceChrome chrome, TerminalTheme theme) =>Builder(builder: (context) {diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex d5d1f81ef..c24a6460e 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -5805,6 +5805,14 @@ class AppNotifier extends ChangeNotifier {notifyListeners();}+ /// Makes [machineId] the workspace's machine, where New Harness starts,+ /// until focus moves to a pane on another one.+ void selectMachine(String machineId) {+ if (selectedMachineId == machineId) return;+ selectedMachineId = machineId;+ notifyListeners();+ }+/// Selects a machine without toggling its tree. Setup/status rows use this/// action so clicking an E2EE prompt always opens that machine's setup pane.Future<void> selectMachineForSetup(String machineId) async {diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dartindex 11bba85d0..2a0aea1ea 100644--- a/desktop/lib/state/workspace_chrome.dart+++ b/desktop/lib/state/workspace_chrome.dart@@ -44,6 +44,8 @@ class WorkspaceChrome {this.newHarnessMachine,this.pickerBar,this.showsKeyHints = true,+ this.viewMachineCloses = false,+ this.closesTabs = false,this.compactTabs,this.compactBelow = 0,});@@ -63,6 +65,14 @@ class WorkspaceChrome {/// False hides keyboard hints inside the workspace's pickers ([KeyHints]).final bool showsKeyHints;+ /// True makes a machine's View pick it for New Harness and close the+ /// picker; false keeps View scoping the picker to its harnesses.+ final bool viewMachineCloses;++ /// True puts a close mark on the selected and hovered tab, for a host with+ /// no ⌘W menu to close one — an empty New Tab included.+ final bool closesTabs;+/// Below [compactBelow] of window width the workspace goes compact: this/// replaces the tab list (the Store button steps aside), and only the focused/// harness is drawn — a phone has room for neither a tab row nor a grid.diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dartindex 3f7fc9bdd..e0225984d 100644--- a/desktop/lib/web/shell/web_chrome.dart+++ b/desktop/lib/web/shell/web_chrome.dart@@ -17,6 +17,8 @@ WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(newHarnessMachine: () => webNewHarnessMachine(app),pickerBar: (context, picker) => WebPickerBar(picker: picker),showsKeyHints: false,+ viewMachineCloses: true,+ closesTabs: true,compactTabs: (context, commands) =>WebTabSwitcher(app: app, commands: commands),compactBelow: kWebCompactBelow,diff --git a/desktop/lib/web/shell/web_menu_items.dart b/desktop/lib/web/shell/web_menu_items.dartindex 54df491ef..c6e95131d 100644--- a/desktop/lib/web/shell/web_menu_items.dart+++ b/desktop/lib/web/shell/web_menu_items.dart@@ -20,6 +20,9 @@ const List<List<WebMenuItem>> kWebMenuGroups = [],[(command: 'agent.share', label: 'Share harness', width: WebMenuWidth.any),+ // One split, always to the right: a second "down" row only lengthens the+ // menu, and All commands still has Split down.+ (command: 'pane.split_right', label: 'Split pane', width: WebMenuWidth.any),(command: 'pane.close', label: 'Close pane', width: WebMenuWidth.any),],[diff --git a/desktop/lib/widgets/swarm_resource_preview.dart b/desktop/lib/widgets/swarm_resource_preview.dartindex 07ef1b685..c08e26a50 100644--- a/desktop/lib/widgets/swarm_resource_preview.dart+++ b/desktop/lib/widgets/swarm_resource_preview.dart@@ -81,6 +81,7 @@ class SwarmResourcePreview extends StatefulWidget {required this.onRefocus,required this.onModalChanged,required this.onCommands,+ this.onViewMachine,});final SwarmSearchController search;final SearchPreviewControls controls;@@ -89,6 +90,10 @@ class SwarmResourcePreview extends StatefulWidget {final ValueChanged<bool> onModalChanged;final VoidCallback onCommands;+ /// Where View takes a machine instead of scoping the picker to it, when+ /// the host composition asks for that ([WorkspaceChrome.viewMachineCloses]).+ final ValueChanged<String>? onViewMachine;+@overrideState<SwarmResourcePreview> createState() => _SwarmResourcePreviewState();}@@ -157,7 +162,12 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {/// a project/machine group opens, so Rename/Delete are not the only doors.void _viewMachine() {final selected = row;- if (selected == null || !widget.search.scopeToGroup(selected.id)) return;+ if (selected == null) return;+ if (widget.onViewMachine case final view?) {+ view(selected.machineId!);+ return;+ }+ if (!widget.search.scopeToGroup(selected.id)) return;widget.onRefocus();}diff --git a/desktop/lib/widgets/workspace_tab_close.dart b/desktop/lib/widgets/workspace_tab_close.dartnew file mode 100644index 000000000..5cf8a4444--- /dev/null+++ b/desktop/lib/widgets/workspace_tab_close.dart@@ -0,0 +1,58 @@+import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import '../shared/theme/workspace_bar_style.dart';++/// Cells a tab reserves for its close mark, so hovering never reflows the row.+const int kWorkspaceTabCloseCells = 2;++/// A tab's label with a close mark after it, for hosts that close tabs by+/// mouse ([WorkspaceChrome.closesTabs]). The mark keeps its cells while+/// hidden and only shows on the selected or hovered tab, as browser tabs do.+class WorkspaceTabCloseSlot extends StatelessWidget {+ const WorkspaceTabCloseSlot({+ super.key,+ required this.tabId,+ required this.visible,+ required this.color,+ required this.onClose,+ required this.child,+ });++ final String tabId;+ final bool visible;+ final Color color;+ final VoidCallback onClose;+ final Widget child;++ @override+ Widget build(BuildContext context) {+ final width =+ workspaceBarCellSizeOf(context).width * kWorkspaceTabCloseCells;+ return Row(+ children: [+ Expanded(child: child),+ SizedBox(+ width: width,+ child: !visible+ ? null+ : Tooltip(+ message: 'Close tab',+ waitDuration: const Duration(milliseconds: 700),+ child: MouseRegion(+ cursor: SystemMouseCursors.click,+ // Inside the tab's own tap target: the innermost detector+ // wins the tap, so this closes without selecting first.+ child: GestureDetector(+ key: ValueKey('tab-close:$tabId'),+ behavior: HitTestBehavior.opaque,+ onTap: onClose,+ child: Icon(LucideIcons.x, size: 13, color: color),+ ),+ ),+ ),+ ),+ ],+ );+ }+}diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dartindex efc50a9fb..1b7977a09 100644--- a/desktop/test/web/web_app_menu_test.dart+++ b/desktop/test/web/web_app_menu_test.dart@@ -61,6 +61,10 @@ void main() {expect(find.byKey(const ValueKey('web-menu:web.sign_out')), findsOneWidget);// An empty tab has no pane to split, zoom or close.expect(find.byKey(const ValueKey('web-menu:pane.close')), findsNothing);+ expect(+ find.byKey(const ValueKey('web-menu:pane.split_right')),+ findsNothing,+ );await tester.tap(find.byKey(const ValueKey('web-menu:app.settings')));await tester.pump(const Duration(milliseconds: 400));expect(find.byType(SettingsScreen), findsOneWidget);@@ -109,6 +113,47 @@ void main() {app.dispose();});+ testWidgets('View on a machine picks it and closes Machines', (tester) async {+ final app = await _mount(tester, connectedMachine: 'remote-box');+ await _openMenu(tester);+ await tester.tap(find.byKey(const ValueKey('web-menu:machines.list')));+ await tester.pump(const Duration(milliseconds: 400));+ final search = tester+ .widget<SwarmSearchResults>(find.byType(SwarmSearchResults))+ .search;+ final index = search.rows.indexWhere(+ (row) => row.isMachine && row.machineId == 'remote-box',+ );+ search.move(index - search.cursor);+ await tester.pump(const Duration(milliseconds: 200));+ await tester.tap(+ find.byKey(const ValueKey('resource-action:picker.resource_view')),+ );+ await tester.pump(const Duration(milliseconds: 400));+ expect(find.byType(SwarmSearchResults), findsNothing);+ expect(app.selectedMachineId, 'remote-box');+ expect(tester.takeException(), isNull);+ await tester.pumpWidget(const SizedBox.shrink());+ app.dispose();+ });++ testWidgets('an empty new tab closes from its close mark', (tester) async {+ final app = await _mount(tester);+ app.newSwarm(newTabPage: true);+ await tester.pump(const Duration(milliseconds: 200));+ final tabs = app.swarms.length;+ final empty = app.activeSwarmId;+ expect(app.activeSwarm.panes, isEmpty);+ await tester.tap(find.byKey(ValueKey('tab-close:$empty')));+ // Past the tab's double-tap-to-rename window, which holds the tap.+ await tester.pump(const Duration(milliseconds: 400));+ expect(app.swarms, hasLength(tabs - 1));+ expect(app.swarms.any((tab) => tab.id == empty), isFalse);+ expect(tester.takeException(), isNull);+ await tester.pumpWidget(const SizedBox.shrink());+ app.dispose();+ });+testWidgets('keys still reach Settings beside the menu', (tester) async {final app = await _mount(tester);await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);diff --git a/desktop/test/web_menu_items_test.dart b/desktop/test/web_menu_items_test.dartindex ac0b0a971..2dcfbb091 100644--- a/desktop/test/web_menu_items_test.dart+++ b/desktop/test/web_menu_items_test.dart@@ -33,7 +33,6 @@ void main() {'swarm.new','harnesses.list','navigation.needs_input',- 'pane.split_right','pane.zoom','pane.layout','keyboard.help',@@ -43,9 +42,15 @@ void main() {}});+ test('the menu splits one way only: right', () {+ final all = _commands(runnableWebMenu((_) => true, compact: false));+ expect(all, contains('pane.split_right'));+ expect(all, isNot(contains('pane.split_down')));+ });+test('rows that cannot run, and groups left empty, are not drawn', () {final menu = runnableWebMenu(- (command) => command != 'agent.share' && command != 'pane.close',+ (command) => !command.startsWith('pane.') && command != 'agent.share',compact: false,);expect(menu, hasLength(kWebMenuGroups.length - 1));