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: add remote machine deletion action to native menu and swarm screen
0xken1531cb48062381
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 5190d1dc3..78ec03a74 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -33,6 +33,7 @@ import '../widgets/layout_palette.dart';import '../widgets/engine_identity.dart';import '../widgets/harness_start_page.dart';import '../widgets/link_machine_screen.dart';+import '../widgets/machine_actions.dart';import '../widgets/machines_manager.dart';import '../widgets/new_agent_dialog.dart';import '../widgets/pane_grid.dart';@@ -580,6 +581,20 @@ class _SwarmScreenState extends State<SwarmScreen> {if (machine != null) {_openSearch(adding: true, query: machine.machine.displayName);}+ case 'deleteMachine':+ final machine = args['id'] is String ? app.stateOf(args['id']) : null;+ if (machine != null && !machine.isLocalMachine) {+ unawaited(+ _dialog(+ () => confirmDeleteMachine(+ context,+ app,+ machineId: machine.machine.machineId,+ displayName: machine.machine.displayName,+ ),+ ),+ );+ }case 'machineAgent':final machineId = args['machineId'], agentId = args['agentId'];if (machineId is String &&@@ -643,6 +658,7 @@ class _SwarmScreenState extends State<SwarmScreen> {'addAgent','newAgent','manageMachines',+ 'deleteMachine','splitRight','splitDown','zoomPane',diff --git a/desktop/lib/widgets/machine_actions.dart b/desktop/lib/widgets/machine_actions.dartnew file mode 100644index 000000000..9b6e21a8e--- /dev/null+++ b/desktop/lib/widgets/machine_actions.dart@@ -0,0 +1,48 @@+import 'package:flutter/material.dart';++import '../shared/theme/app_theme.dart' as grid;+import '../shared/widgets/app_dialog.dart';+import '../state/app_state.dart';++/// Shared "Delete machine" confirmation, used by the sidebar rail's context+/// menu and the native Machines menu. Delete disconnects the machine's agents+/// and drops the link (see [AppNotifier.deleteMachine]); it cannot be undone.+Future<void> confirmDeleteMachine(+ BuildContext context,+ AppNotifier notifier, {+ required String machineId,+ required String displayName,+}) async {+ final confirmed = await showAppDialog<bool>(+ context: context,+ builder: (dialogContext) => AlertDialog(+ title: const Text('Delete machine'),+ content: SizedBox(+ width: 360,+ child: Text(+ 'Delete "$displayName"? All its agents will be disconnected and '+ "it'll need to be linked again. This can't be undone.",+ style: TextStyle(fontFamily: grid.AppFont.sans, fontSize: 13.5),+ ),+ ),+ actions: [+ TextButton(+ onPressed: () => Navigator.of(dialogContext).pop(false),+ child: const Text('Cancel'),+ ),+ FilledButton(+ style: FilledButton.styleFrom(+ backgroundColor: grid.AppPalette.dangerFill,+ ),+ onPressed: () => Navigator.of(dialogContext).pop(true),+ child: const Text('Delete'),+ ),+ ],+ ),+ );+ if (confirmed != true || !context.mounted) return;+ final error = await notifier.deleteMachine(machineId);+ if (error != null && context.mounted) {+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error)));+ }+}diff --git a/desktop/lib/widgets/machine_rail.dart b/desktop/lib/widgets/machine_rail.dartindex ce293f39b..1fdecfbfe 100644--- a/desktop/lib/widgets/machine_rail.dart+++ b/desktop/lib/widgets/machine_rail.dart@@ -10,13 +10,13 @@ import '../core/models.dart';import '../shared/layouts/widgets/sidebar_item.dart';import '../shared/layouts/widgets/sidebar_timeline.dart';import '../shared/theme/app_theme.dart' as grid;-import '../shared/widgets/app_dialog.dart';import '../shared/widgets/app_icon_button.dart';import '../shared/widgets/app_menu.dart';import '../shared/widgets/skeleton.dart';import '../shortcuts/app_shortcuts.dart';import '../state/app_state.dart';import 'agent_drag.dart';+import 'machine_actions.dart';import 'delete_agent_dialog.dart';import 'restart_agent_action.dart';import 'rename_agent_dialog.dart';@@ -442,41 +442,12 @@ class _MachineNodeState extends State<_MachineNode> {machine.displayName,);- Future<void> _confirmDeleteMachine() async {- final confirmed = await showAppDialog<bool>(- context: context,- builder: (dialogContext) => AlertDialog(- title: const Text('Delete machine'),- content: SizedBox(- width: 360,- child: Text(- 'Delete "${machine.displayName}"? All its agents will be disconnected and '- "it'll need to be linked again. This can't be undone.",- style: TextStyle(fontFamily: grid.AppFont.sans, fontSize: 13.5),- ),- ),- actions: [- TextButton(- onPressed: () => Navigator.of(dialogContext).pop(false),- child: const Text('Cancel'),- ),- FilledButton(- style: FilledButton.styleFrom(- backgroundColor: grid.AppPalette.dangerFill,- ),- onPressed: () => Navigator.of(dialogContext).pop(true),- child: const Text('Delete'),- ),- ],- ),- );- if (confirmed != true || !mounted) return;- final error = await notifier.deleteMachine(machine.machineId);- if (error != null && mounted) {- ScaffoldMessenger.of(context)- .showSnackBar(SnackBar(content: Text(error)));- }- }+ Future<void> _confirmDeleteMachine() => confirmDeleteMachine(+ context,+ notifier,+ machineId: machine.machineId,+ displayName: machine.displayName,+ );@overrideWidget build(BuildContext context) {diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swiftindex 8cb56eaf6..67762c317 100644--- a/desktop/macos/Runner/SwarmTitlebar.swift+++ b/desktop/macos/Runner/SwarmTitlebar.swift@@ -325,6 +325,14 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {find.target = selffind.representedObject = machine.idsubmenu.addItem(find)+ if !machine.local {+ submenu.addItem(.separator())+ let del = NSMenuItem(title: "Delete Machine…", action: #selector(machineDeleteAction(_:)), keyEquivalent: "")+ del.target = self+ del.representedObject = machine.id+ del.image = NSImage(systemSymbolName: "trash", accessibilityDescription: nil)+ submenu.addItem(del)+ }item.submenu = submenumachinesMenu.addItem(item)}@@ -483,6 +491,9 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {if menuItem.action == #selector(machineAction(_:)) {return actionsEnabled && machines.contains(where: { $0.id == action })}+ if menuItem.action == #selector(machineDeleteAction(_:)) {+ return actionsEnabled && machines.contains(where: { $0.id == action && !$0.local })+ }if menuItem.action == #selector(historyAction(_:)) {return actionsEnabled && history.contains(where: { $0.id == action })}@@ -505,6 +516,11 @@ final class SwarmTitlebar: NSObject, NSMenuItemValidation, NSMenuDelegate {sendTabAction("machineDestination", arguments: ["id": id])}+ @objc private func machineDeleteAction(_ sender: NSMenuItem) {+ guard validateMenuItem(sender), let id = sender.representedObject as? String else { return }+ sendTabAction("deleteMachine", arguments: ["id": id])+ }+@objc private func machineAgentAction(_ sender: NSMenuItem) {guard validateMenuItem(sender), let target = sender.representedObject as? [String: String] else { return }sendTabAction("machineAgent", arguments: target)diff --git a/desktop/test/machines_menu_test.dart b/desktop/test/machines_menu_test.dartindex 5c00c8316..269ca560e 100644--- a/desktop/test/machines_menu_test.dart+++ b/desktop/test/machines_menu_test.dart@@ -3,6 +3,9 @@ import 'dart:async';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';+import 'package:harness/api/api_client.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/core/config.dart';import 'package:harness/core/models.dart';import 'package:harness/screens/swarm_screen.dart';import 'package:harness/state/swarm_catalog.dart';@@ -11,6 +14,17 @@ import 'package:harness/terminal/terminal_binary.dart';import 'swarm_state_test.dart' show createApp;import 'swarm_screen_test.dart' show terminal;+/// Records `deleteMachine` calls without touching the network. The real client+/// only builds its `Dio` lazily, so overriding the method keeps it offline.+class _RecordingApi extends ApiClient {+ _RecordingApi() : super(config: AppConfig.dev, session: AuthSession());+ final List<String> deleted = [];+ @override+ Future<void> deleteMachine({required String machineId}) async {+ deleted.add(machineId);+ }+}+void main() {testWidgets('tab navigation does not resend the agent inventory', (tester,@@ -168,4 +182,138 @@ void main() {projects.dispose();},);+ testWidgets('deleteMachine confirms before dropping a remote machine', (+ tester,+ ) async {+ const channel = MethodChannel('harness/swarm_tabs');+ final messenger = tester.binding.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(channel, (call) async => true);+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));+ final app = createApp();+ final projects = SwarmProjectStore();+ await tester.pumpWidget(+ MaterialApp(+ home: SwarmScreen(+ notifier: app,+ nativeTabs: true,+ projectStore: projects,+ ),+ ),+ );+ await tester.pump();++ // The remote machine's row is deletable; the native menu drives this call.+ final reply = Completer<void>();+ messenger.handlePlatformMessage(+ channel.name,+ const StandardMethodCodec().encodeMethodCall(+ const MethodCall('deleteMachine', {'id': 'm'}),+ ),+ (_) => reply.complete(),+ );+ // The native reply is withheld until endOfFrame (focus handoff), so pump+ // first, then the dialog opens on the following frames.+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ await reply.future;+ expect(find.text('Delete machine'), findsOneWidget);+ expect(find.widgetWithText(FilledButton, 'Delete'), findsOneWidget);++ // Cancelling leaves the machine in place.+ await tester.tap(find.text('Cancel'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ expect(find.text('Delete machine'), findsNothing);+ expect(app.machineStates.containsKey('m'), isTrue);++ await tester.pumpWidget(const SizedBox());+ app.dispose();+ projects.dispose();+ });++ testWidgets('deleteMachine removes the machine once confirmed', (+ tester,+ ) async {+ const channel = MethodChannel('harness/swarm_tabs');+ final messenger = tester.binding.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(channel, (call) async => true);+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));+ final app = createApp();+ final api = _RecordingApi();+ app.api = api; // keep the delete off the network+ final projects = SwarmProjectStore();+ await tester.pumpWidget(+ MaterialApp(+ home: SwarmScreen(+ notifier: app,+ nativeTabs: true,+ projectStore: projects,+ ),+ ),+ );+ await tester.pump();++ final reply = Completer<void>();+ messenger.handlePlatformMessage(+ channel.name,+ const StandardMethodCodec().encodeMethodCall(+ const MethodCall('deleteMachine', {'id': 'm'}),+ ),+ (_) => reply.complete(),+ );+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ await reply.future;+ expect(find.text('Delete machine'), findsOneWidget);++ // Confirming drops the machine from the client and the API.+ await tester.tap(find.widgetWithText(FilledButton, 'Delete'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ expect(api.deleted, ['m']);+ expect(app.machineStates.containsKey('m'), isFalse);+ expect(app.machines.any((m) => m.machineId == 'm'), isFalse);++ await tester.pumpWidget(const SizedBox());+ app.dispose();+ projects.dispose();+ });++ testWidgets('deleteMachine ignores this computer', (tester) async {+ const channel = MethodChannel('harness/swarm_tabs');+ final messenger = tester.binding.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(channel, (call) async => true);+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));+ final app = createApp();+ app.machineStates['m']!.localOnly = true; // this computer, not deletable+ final projects = SwarmProjectStore();+ await tester.pumpWidget(+ MaterialApp(+ home: SwarmScreen(+ notifier: app,+ nativeTabs: true,+ projectStore: projects,+ ),+ ),+ );+ await tester.pump();++ final reply = Completer<void>();+ messenger.handlePlatformMessage(+ channel.name,+ const StandardMethodCodec().encodeMethodCall(+ const MethodCall('deleteMachine', {'id': 'm'}),+ ),+ (_) => reply.complete(),+ );+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ await reply.future;+ expect(find.text('Delete machine'), findsNothing);+ expect(app.machineStates.containsKey('m'), isTrue);++ await tester.pumpWidget(const SizedBox());+ app.dispose();+ projects.dispose();+ });}