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.

Web: right-clicking a machine in the Swarm sidebar opens the Swarm menu; a long press opens it too (Huy) (#2518)

0xken1521ffb0f0941e
diff --git a/desktop/lib/super_tabs/machines.dart b/desktop/lib/super_tabs/machines.dart
index 3ebe0f626..2e3ead4a5 100644
--- a/desktop/lib/super_tabs/machines.dart
+++ b/desktop/lib/super_tabs/machines.dart
@@ -17,6 +17,7 @@ import '../state/harness_activity.dart';
import '../terminal/terminal_theme.dart';
import '../terminal/terminal_theme_store.dart';
import '../usage/models_menu_controller.dart';
+import '../widgets/browser_menu_guard.dart';
import '../widgets/desktop_chrome.dart';
import '../widgets/engine_identity.dart';
import '../widgets/harness_activity_mark.dart';
@@ -1536,7 +1537,9 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
for (final agent in preview.agents) ...[
const SizedBox(height: 4),
Text(
- '${agent.name} · ${agent.projectName}',
+ agent.projectName.isEmpty
+ ? agent.name
+ : '${agent.name} · ${agent.projectName}',
),
if (agent.task != null)
Text(
@@ -1762,47 +1765,59 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
}
}
+ /// Where a long press opens the menu: under the middle of the row, which the touch gives no point for.
+ Offset _longPressAt(BuildContext rowContext) {
+ final box = rowContext.findRenderObject();
+ if (box is! RenderBox || !box.hasSize) return Offset.zero;
+ return box.localToGlobal(Offset(box.size.width / 2, box.size.height));
+ }
+
Widget _machine(_MachineView view) {
final tipKey = _tips.putIfAbsent(view.id, GlobalKey<TooltipState>.new);
final expanded = c.isMachineExpanded(view.id);
final selected = _selectedMachineId == view.id;
- final row = Material(
- color: selected ? grid.AppSurface.selectedFill : Colors.transparent,
- borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),
- clipBehavior: Clip.antiAlias,
- // No chevron (Dee, 2026-10-27): a click expands the machine, and its
- // details are in the right-click menu, or a long press on a touch screen.
- child: InkWell(
- key: ValueKey('super-machine-${view.id}'),
- onTap: () {
- c.toggleMachineExpanded(view.id);
- _changed();
- },
- onLongPress: () => unawaited(_openDetails(view)),
- onSecondaryTapUp: (event) =>
- unawaited(_menu(view, event.globalPosition)),
- hoverColor: grid.AppSurface.hoverFill,
- focusColor: grid.AppSurface.hoverFill,
+ final row = BrowserMenuOff(
+ active: true,
+ child: Material(
+ color: selected ? grid.AppSurface.selectedFill : Colors.transparent,
borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),
- onFocusChange: (focused) {
- if (focused &&
- FocusManager.instance.highlightMode ==
- FocusHighlightMode.traditional) {
- tipKey.currentState?.ensureTooltipVisible();
- } else if (!focused) {
- Tooltip.dismissAllToolTips();
- }
- },
- child: Semantics(
- expanded: expanded,
- child: _MachineLine(
- view: view,
- onSetUpTeam: view.setUpTeam
- ? () async {
- await showTeamAccountSetup(context, widget.app!);
- await _readTeamSetup();
- }
- : null,
+ clipBehavior: Clip.antiAlias,
+ // No chevron (Dee, 2026-10-27): a click expands the machine, and its
+ // details are in the right-click menu, or a long press on a touch screen.
+ child: Builder(
+ builder: (rowContext) => InkWell(
+ key: ValueKey('super-machine-${view.id}'),
+ onTap: () {
+ c.toggleMachineExpanded(view.id);
+ _changed();
+ },
+ onLongPress: () => unawaited(_menu(view, _longPressAt(rowContext))),
+ onSecondaryTapUp: (event) =>
+ unawaited(_menu(view, event.globalPosition)),
+ hoverColor: grid.AppSurface.hoverFill,
+ focusColor: grid.AppSurface.hoverFill,
+ borderRadius: BorderRadius.circular(DesktopChrome.rowRadius),
+ onFocusChange: (focused) {
+ if (focused &&
+ FocusManager.instance.highlightMode ==
+ FocusHighlightMode.traditional) {
+ tipKey.currentState?.ensureTooltipVisible();
+ } else if (!focused) {
+ Tooltip.dismissAllToolTips();
+ }
+ },
+ child: Semantics(
+ expanded: expanded,
+ child: _MachineLine(
+ view: view,
+ onSetUpTeam: view.setUpTeam
+ ? () async {
+ await showTeamAccountSetup(context, widget.app!);
+ await _readTeamSetup();
+ }
+ : null,
+ ),
+ ),
),
),
),
@@ -2208,10 +2223,10 @@ class _RemovalPreview {
final agent = superTabMap(item);
final name = agent['name'], projectName = agent['projectName'];
final task = agent['task'];
+ // A Swarm-wide Buddy has no project: the server sends an empty name.
if (name is! String ||
name.isEmpty ||
projectName is! String ||
- projectName.isEmpty ||
(task != null && task is! String)) {
throw const FormatException('Invalid machine removal preview');
}
diff --git a/desktop/lib/widgets/browser_menu_guard.dart b/desktop/lib/widgets/browser_menu_guard.dart
new file mode 100644
index 000000000..acdd3b7ce
--- /dev/null
+++ b/desktop/lib/widgets/browser_menu_guard.dart
@@ -0,0 +1,131 @@
+import 'dart:async';
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+/// Keeps the browser's own context menu off while the pointer is over a widget that opens a menu of its own.
+///
+/// Several widgets can want it off at once (a tab and a machine row never overlap, but a pointer that moves from one
+/// to another reports the new enter and the old exit in either order), so each holds the switch under its own key and
+/// the browser's menu comes back only when nobody holds it. Anywhere else (a terminal, a text field) a right-click
+/// keeps the browser's Copy and Paste. A computer, where there is no browser menu, does nothing at all.
+class BrowserMenuGuard {
+ BrowserMenuGuard._();
+
+ static final Set<Object> _holders = {};
+ static bool _off = false;
+
+ /// Test seam: pretend to be a browser, and see what the switch is told.
+ @visibleForTesting
+ static bool? debugWeb;
+ @visibleForTesting
+ static Future<void> Function(bool off)? debugSink;
+
+ @visibleForTesting
+ static void debugReset() {
+ _holders.clear();
+ _off = false;
+ debugWeb = null;
+ debugSink = null;
+ }
+
+ static bool get _web => debugWeb ?? kIsWeb;
+
+ /// Whether the browser's menu is off now.
+ static bool get isOff => _off;
+
+ /// [owner] wants the browser's menu off until it releases.
+ static void hold(Object owner) {
+ if (!_web || !_holders.add(owner)) return;
+ _sync();
+ }
+
+ /// [owner] no longer needs it off.
+ static void release(Object owner) {
+ if (!_holders.remove(owner)) return;
+ _sync();
+ }
+
+ static void _sync() {
+ final off = _holders.isNotEmpty;
+ if (off == _off) return;
+ _off = off;
+ final sink = debugSink;
+ if (sink != null) {
+ unawaited(sink(off));
+ return;
+ }
+ // The channel itself rather than BrowserContextMenu: that one asserts it runs in a browser, which a test is not.
+ unawaited(
+ SystemChannels.contextMenu.invokeMethod<void>(
+ off ? 'disableContextMenu' : 'enableContextMenu',
+ ),
+ );
+ }
+}
+
+/// Wraps [child] so the browser's context menu is off while the pointer is over it or pressed on it, and [active].
+class BrowserMenuOff extends StatefulWidget {
+ const BrowserMenuOff({super.key, required this.active, required this.child});
+
+ /// False when the child has no menu to show (nothing opens, so the browser's menu stays).
+ final bool active;
+ final Widget child;
+
+ @override
+ State<BrowserMenuOff> createState() => _BrowserMenuOffState();
+}
+
+class _BrowserMenuOffState extends State<BrowserMenuOff> {
+ bool _hovered = false, _pressed = false;
+
+ void _sync() {
+ if ((_hovered || _pressed) && widget.active) {
+ BrowserMenuGuard.hold(this);
+ } else {
+ BrowserMenuGuard.release(this);
+ }
+ }
+
+ @override
+ void didUpdateWidget(BrowserMenuOff oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ _sync();
+ }
+
+ @override
+ void dispose() {
+ BrowserMenuGuard.release(this);
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) => MouseRegion(
+ onEnter: (_) {
+ _hovered = true;
+ _sync();
+ },
+ onExit: (_) {
+ _hovered = false;
+ _sync();
+ },
+ // A finger never hovers: a phone's browser asks for its menu while the finger is still down on a long press.
+ child: Listener(
+ behavior: HitTestBehavior.translucent,
+ onPointerDown: (_) {
+ _pressed = true;
+ _sync();
+ },
+ onPointerUp: (_) {
+ _pressed = false;
+ _sync();
+ },
+ onPointerCancel: (_) {
+ _pressed = false;
+ _sync();
+ },
+ child: widget.child,
+ ),
+ );
+}
diff --git a/desktop/lib/widgets/desktop_workspace_tab.dart b/desktop/lib/widgets/desktop_workspace_tab.dart
index a122d0665..86e2ccf7f 100644
--- a/desktop/lib/widgets/desktop_workspace_tab.dart
+++ b/desktop/lib/widgets/desktop_workspace_tab.dart
@@ -1,4 +1,3 @@
-import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
@@ -11,6 +10,7 @@ import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/app_menu.dart';
import '../state/workspace_chrome.dart';
import 'box_chrome.dart';
+import 'browser_menu_guard.dart';
import 'desktop_chrome.dart';
/// The Flutter counterpart of the AppKit tab: a centered name/status group
@@ -225,17 +225,12 @@ class _DesktopWorkspaceTabState extends State<DesktopWorkspaceTab> {
/// right-click. It is off only while the pointer is over a tab that has a
/// menu, so a right-click anywhere else (a terminal, a text field) keeps the
/// browser's Copy and Paste.
- bool _browserMenuOff = false;
-
void _syncBrowserMenu() {
- final off = kIsWeb && _hovered && _hasMenu && mounted;
- if (off == _browserMenuOff) return;
- _browserMenuOff = off;
- unawaited(
- off
- ? BrowserContextMenu.disableContextMenu()
- : BrowserContextMenu.enableContextMenu(),
- );
+ if (_hovered && _hasMenu && mounted) {
+ BrowserMenuGuard.hold(this);
+ } else {
+ BrowserMenuGuard.release(this);
+ }
}
@override
@@ -246,10 +241,7 @@ class _DesktopWorkspaceTabState extends State<DesktopWorkspaceTab> {
@override
void dispose() {
- if (_browserMenuOff) {
- _browserMenuOff = false;
- unawaited(BrowserContextMenu.enableContextMenu());
- }
+ BrowserMenuGuard.release(this);
super.dispose();
}
diff --git a/desktop/test/browser_menu_guard_test.dart b/desktop/test/browser_menu_guard_test.dart
new file mode 100644
index 000000000..3a3c52fb7
--- /dev/null
+++ b/desktop/test/browser_menu_guard_test.dart
@@ -0,0 +1,141 @@
+import 'package:flutter/gestures.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/widgets/browser_menu_guard.dart';
+
+void main() {
+ late List<bool> told;
+
+ setUp(() {
+ told = [];
+ BrowserMenuGuard.debugWeb = true;
+ BrowserMenuGuard.debugSink = (off) async => told.add(off);
+ });
+ tearDown(BrowserMenuGuard.debugReset);
+
+ test(
+ 'the browser menu is off while anyone holds it, back when all let go',
+ () {
+ final a = Object(), b = Object();
+ BrowserMenuGuard.hold(a);
+ BrowserMenuGuard.hold(b);
+ BrowserMenuGuard.hold(b);
+ expect(told, [true]);
+ BrowserMenuGuard.release(a);
+ expect(BrowserMenuGuard.isOff, isTrue);
+ BrowserMenuGuard.release(b);
+ BrowserMenuGuard.release(b);
+ expect(BrowserMenuGuard.isOff, isFalse);
+ expect(told, [true, false]);
+ },
+ );
+
+ test('a computer has no browser menu to switch', () {
+ BrowserMenuGuard.debugWeb = false;
+ BrowserMenuGuard.hold(Object());
+ expect(told, isEmpty);
+ expect(BrowserMenuGuard.isOff, isFalse);
+ });
+
+ testWidgets('off over the child, on again when the pointer leaves', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ const MaterialApp(
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: BrowserMenuOff(
+ active: true,
+ child: SizedBox(key: ValueKey('row'), width: 100, height: 40),
+ ),
+ ),
+ ),
+ ),
+ );
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(400, 400));
+ await tester.pump();
+ expect(told, isEmpty);
+ await mouse.moveTo(tester.getCenter(find.byKey(const ValueKey('row'))));
+ await tester.pump();
+ expect(told, [true]);
+ await mouse.moveTo(const Offset(400, 400));
+ await tester.pump();
+ expect(told, [true, false]);
+ });
+
+ testWidgets('a finger held down keeps it off, and lifting restores it', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ const MaterialApp(
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: BrowserMenuOff(
+ active: true,
+ child: SizedBox(key: ValueKey('row'), width: 100, height: 40),
+ ),
+ ),
+ ),
+ ),
+ );
+ final finger = await tester.startGesture(
+ tester.getCenter(find.byKey(const ValueKey('row'))),
+ kind: PointerDeviceKind.touch,
+ );
+ await tester.pump();
+ expect(told, [true]);
+ await finger.up();
+ await tester.pump();
+ expect(told, [true, false]);
+ });
+
+ testWidgets('a row that goes away under the pointer gives the menu back', (
+ tester,
+ ) async {
+ Widget app(bool show) => MaterialApp(
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: show
+ ? const BrowserMenuOff(
+ active: true,
+ child: SizedBox(key: ValueKey('row'), width: 100, height: 40),
+ )
+ : const SizedBox(),
+ ),
+ ),
+ );
+ await tester.pumpWidget(app(true));
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(20, 20));
+ await tester.pump();
+ expect(told, [true]);
+ await tester.pumpWidget(app(false));
+ expect(told, [true, false]);
+ });
+
+ testWidgets('an inactive child leaves the browser menu alone', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ const MaterialApp(
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: BrowserMenuOff(
+ active: false,
+ child: SizedBox(key: ValueKey('row'), width: 100, height: 40),
+ ),
+ ),
+ ),
+ ),
+ );
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(20, 20));
+ await tester.pump();
+ expect(told, isEmpty);
+ });
+}
diff --git a/desktop/test/super_tab_machines_test.dart b/desktop/test/super_tab_machines_test.dart
index 4545effd9..ccd121b2e 100644
--- a/desktop/test/super_tab_machines_test.dart
+++ b/desktop/test/super_tab_machines_test.dart
@@ -20,6 +20,7 @@ import 'package:harness/super_tabs/identity.dart';
import 'package:harness/super_tabs/model.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/shared/widgets/app_icon_button.dart';
+import 'package:harness/widgets/browser_menu_guard.dart';
import 'package:harness/widgets/desktop_chrome.dart';
import 'package:harness/widgets/engine_identity.dart';
@@ -1538,6 +1539,42 @@ void main() {
},
);
+ testWidgets(
+ 'a Swarm-wide Buddy has no project: its name is listed alone and Remove still asks',
+ (tester) async {
+ final server = _RemovalServer();
+ server.state['machines'] = [machine('owner')];
+ server.preview = {
+ 'blockedBy': null,
+ 'agents': [
+ {'id': 'a1', 'name': 'Wren', 'projectName': ''},
+ ],
+ 'soleSourceProjects': <Object>[],
+ };
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
+ await tester.tap(
+ find.byKey(const ValueKey('super-machine-studio')),
+ buttons: kSecondaryMouseButton,
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(
+ find.byKey(const ValueKey('super-machine-menu-remove')),
+ );
+ await tester.pumpAndSettle();
+ expect(find.text('Remove Studio from this Swarm?'), findsOneWidget);
+ expect(find.text('Wren'), findsOneWidget);
+ expect(find.textContaining('Wren ·'), findsNothing);
+ expect(find.text('Could not check this machine.'), findsNothing);
+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));
+ await tester.pumpAndSettle();
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ },
+ );
+
testWidgets('a right-click offers it to whoever may remove the machine', (
tester,
) async {
@@ -1563,6 +1600,63 @@ void main() {
c.dispose();
});
+ testWidgets(
+ 'a long press opens the same menu, Details and Remove, not the details',
+ (tester) async {
+ final server = _RemovalServer();
+ server.state['machines'] = [machine('owner')];
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
+ await tester.longPress(
+ find.byKey(const ValueKey('super-machine-studio')),
+ );
+ await tester.pumpAndSettle();
+ expect(find.text('Details'), findsOneWidget);
+ expect(
+ find.byKey(const ValueKey('super-machine-menu-remove')),
+ findsOneWidget,
+ );
+ expect(find.byType(SuperTabMachineDetails), findsNothing);
+ await tester.tap(find.text('Details'));
+ await tester.pumpAndSettle();
+ expect(find.byType(SuperTabMachineDetails), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ },
+ );
+
+ testWidgets(
+ 'in a browser, pointing at a machine row switches the browser menu off',
+ (tester) async {
+ final told = <bool>[];
+ BrowserMenuGuard.debugWeb = true;
+ BrowserMenuGuard.debugSink = (off) async => told.add(off);
+ addTearDown(BrowserMenuGuard.debugReset);
+ final server = _RemovalServer();
+ server.state['machines'] = [machine('owner')];
+ final c = server.controller();
+ await c.refresh();
+ await mount(tester, c);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(900, 700));
+ await tester.pump();
+ expect(told, isEmpty);
+ await mouse.moveTo(
+ tester.getCenter(find.byKey(const ValueKey('super-machine-studio'))),
+ );
+ await tester.pump();
+ expect(told, [true]);
+ await mouse.moveTo(const Offset(900, 700));
+ await tester.pump();
+ expect(told, [true, false]);
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ c.dispose();
+ },
+ );
+
testWidgets('machine with a Product Manager cannot be removed', (
tester,
) async {