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
Polish tab renaming and contain native tab clicks
dee8ada8517918a
diff --git a/desktop/lib/widgets/machine_rail.dart b/desktop/lib/widgets/machine_rail.dartindex bd202b85f..15329a526 100644--- a/desktop/lib/widgets/machine_rail.dart+++ b/desktop/lib/widgets/machine_rail.dart@@ -1211,7 +1211,7 @@ class _AgentRowState extends State<_AgentRow> {),const AppMenuDivider(),AppMenuItem(- icon: LucideIcons.circleStop300,+ icon: Icons.stopRounded,label: 'Stop Harness',danger: true,onPressed: () {diff --git a/desktop/lib/widgets/pane_header_actions.dart b/desktop/lib/widgets/pane_header_actions.dartindex 69c673c7e..f271fee30 100644--- a/desktop/lib/widgets/pane_header_actions.dart+++ b/desktop/lib/widgets/pane_header_actions.dart@@ -87,7 +87,7 @@ class PaneHeaderActions extends StatelessWidget {const SizedBox(width: 2),action('Restart Harness', LucideIcons.refreshCw, onRestart),const SizedBox(width: 2),- action('Stop Harness', LucideIcons.circleStop, onDelete),+ action('Stop Harness', Icons.stopRounded, onDelete),const SizedBox(width: 2),action('Close Pane', LucideIcons.x, onClose),],diff --git a/desktop/lib/widgets/swarm_dialogs.dart b/desktop/lib/widgets/swarm_dialogs.dartindex 36b5e6149..794b31988 100644--- a/desktop/lib/widgets/swarm_dialogs.dart+++ b/desktop/lib/widgets/swarm_dialogs.dart@@ -3,6 +3,7 @@ import 'dart:async';import 'package:file_selector/file_selector.dart';import 'package:flutter/material.dart';+import '../shared/theme/app_theme.dart' as grid;import '../shared/widgets/app_dialog.dart';import '../shared/widgets/app_select_field.dart';import '../state/app_state.dart';@@ -16,6 +17,8 @@ Future<String?> showSwarmRenameDialog(BuildContext context, String name) =>showAppDialog<String>(context: context,transitionDuration: Duration.zero,+ veilBlur: 0,+ veilTint: const Color(0x99000000),builder: (_) => _RenameSwarmDialog(name: name),);@@ -49,31 +52,96 @@ class _RenameSwarmDialogState extends State<_RenameSwarmDialog> {super.dispose();}+ void _save() {+ final name = _text.text.trim();+ if (name.isNotEmpty) Navigator.pop(context, name);+ }+@override- Widget build(BuildContext context) => AlertDialog(- title: const Text('Rename Tab'),- content: SizedBox(- width: 360,- child: TextField(- controller: _text,- focusNode: _focus,- autofocus: true,- maxLength: 80,- decoration: const InputDecoration(labelText: 'Name'),- onSubmitted: (value) => Navigator.pop(context, value),- ),- ),- actions: [- TextButton(- onPressed: () => Navigator.pop(context),- child: const Text('Cancel'),- ),- FilledButton(- onPressed: () => Navigator.pop(context, _text.text),- child: const Text('Save'),+ Widget build(BuildContext context) {+ grid.AppTheme.watch(context);+ final accent = grid.AppPalette.accentOnSurface;+ final border = OutlineInputBorder(+ borderRadius: BorderRadius.circular(10),+ borderSide: BorderSide.none,+ );+ return ListenableBuilder(+ listenable: _text,+ builder: (context, _) => AlertDialog(+ title: const Text('Rename Tab'),+ titleTextStyle: Theme.of(context).textTheme.titleMedium,+ content: SizedBox(+ width: 360,+ child: Semantics(+ label: 'Tab name',+ child: TextSelectionTheme(+ data: TextSelectionTheme.of(context)+ .copyWith(selectionColor: accent.withValues(alpha: .3)),+ child: TextField(+ controller: _text,+ focusNode: _focus,+ autofocus: true,+ maxLength: 80,+ cursorColor: accent,+ textInputAction: TextInputAction.done,+ style: TextStyle(+ fontSize: 15,+ color: grid.AppPalette.textPrimary,+ ),+ decoration: InputDecoration(+ filled: true,+ fillColor: grid.AppSurface.recess,+ isDense: true,+ contentPadding: const EdgeInsets.symmetric(+ horizontal: 14,+ vertical: 14,+ ),+ border: border,+ enabledBorder: border,+ focusedBorder: border.copyWith(+ borderSide: BorderSide(color: accent),+ ),+ counterText: '',+ suffixText: _text.text.characters.length >= 70+ ? '${_text.text.characters.length}/80'+ : null,+ suffixStyle: TextStyle(+ fontSize: 11,+ color: grid.AppPalette.textSecondary,+ ),+ ),+ onSubmitted: (_) => _save(),+ ),+ ),+ ),+ ),+ actions: [+ OutlinedButton(+ onPressed: () => Navigator.pop(context),+ style: OutlinedButton.styleFrom(+ foregroundColor: grid.AppPalette.textSecondary,+ minimumSize: const Size(88, 38),+ padding: const EdgeInsets.symmetric(horizontal: 18),+ side: const BorderSide(color: Colors.white24),+ shape: const StadiumBorder(),+ ),+ child: const Text('Cancel'),+ ),+ FilledButton(+ onPressed: _text.text.trim().isEmpty ? null : _save,+ style: FilledButton.styleFrom(+ backgroundColor: grid.AppPalette.swarmAccent,+ foregroundColor: grid.AppPalette.swarmTabBar,+ minimumSize: const Size(88, 38),+ padding: const EdgeInsets.symmetric(horizontal: 18),+ shape: const StadiumBorder(),+ ),+ child: const Text('Rename'),+ ),+ ],),- ],- );+ );+ }}Future<SavedSwarmProject?> showSwarmProjectDialog(diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swiftindex 65cd87fe6..187d6fe58 100644--- a/desktop/macos/Runner/SwarmTitlebar.swift+++ b/desktop/macos/Runner/SwarmTitlebar.swift@@ -754,16 +754,17 @@ private final class SwarmActionButton: NSButton {override func mouseExited(with event: NSEvent) { hovered = false; needsDisplay = true }override func draw(_ dirtyRect: NSRect) {- let opacity: CGFloat = isEnabled ? 1 : 0.35+ // A workspace modal dims the canvas, not this native chrome. Keep the+ // normal appearance while isEnabled still prevents actions behind it.let emphasis: CGFloat = isHighlighted ? 0.16 : 0.08let hoverFill = fillColor.alphaComponent == 0? labelColor.withAlphaComponent(emphasis): fillColor.blended(withFraction: emphasis, of: labelColor) ?? fillColorlet fill = isEnabled && (hovered || isHighlighted) ? hoverFill : fillColor- fill.withAlphaComponent(fill.alphaComponent * opacity).setFill()+ fill.setFill()NSBezierPath(roundedRect: bounds, xRadius: bounds.height / 2, yRadius: bounds.height / 2).fill()if let borderColor {- borderColor.withAlphaComponent(borderColor.alphaComponent * opacity).setStroke()+ borderColor.setStroke()let border = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5),xRadius: (bounds.height - 1) / 2, yRadius: (bounds.height - 1) / 2)border.lineWidth = 1@@ -771,7 +772,7 @@ private final class SwarmActionButton: NSButton {}let label = NSAttributedString(string: title, attributes: [.font: font ?? NSFont.systemFont(ofSize: 12, weight: .medium),- .foregroundColor: labelColor.withAlphaComponent(opacity),+ .foregroundColor: labelColor,])let size = label.size()label.draw(at: NSPoint(x: (bounds.width - size.width) / 2, y: (bounds.height - size.height) / 2))@@ -1171,6 +1172,9 @@ private final class SwarmTabButton: NSView, NSDraggingSource, NSMenuItemValidatiif event.clickCount == 2 { renameSwarm() }else { emit?("select", ["id": swarmId]) }}+ // The tab owns the full click sequence, including clicks on its padding.+ // Forwarding mouseUp lets AppKit also treat a rename as a titlebar zoom.+ override func mouseUp(with event: NSEvent) {}override func mouseDragged(with event: NSEvent) {guard actionsEnabled else { return }if hypot(event.locationInWindow.x - downPoint.x, event.locationInWindow.y - downPoint.y) < 5 { return }@@ -1196,6 +1200,7 @@ private final class SwarmTabButton: NSView, NSDraggingSource, NSMenuItemValidatiprivate class SwarmTabActionButton: NSButton {weak var owner: SwarmTabButton?private(set) var hasKeyboardFocus = false+ override var mouseDownCanMoveWindow: Bool { false }override func becomeFirstResponder() -> Bool {guard super.becomeFirstResponder() else { return false }hasKeyboardFocus = true@@ -1225,6 +1230,7 @@ private final class SwarmSelectButton: SwarmTabActionButton {guard isEnabled else { return }owner?.mouseDown(with: event)}+ override func mouseUp(with event: NSEvent) {}override func mouseDragged(with event: NSEvent) {guard isEnabled else { return }owner?.mouseDragged(with: event)diff --git a/desktop/test/swarm_rename_dialog_test.dart b/desktop/test/swarm_rename_dialog_test.dartnew file mode 100644index 000000000..a5e936130--- /dev/null+++ b/desktop/test/swarm_rename_dialog_test.dart@@ -0,0 +1,107 @@+import 'dart:io';+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/widgets/swarm_dialogs.dart';++import 'support/real_fonts.dart';++void main() {+ setUpAll(loadRealFonts);+ for (final scale in [1.0, 2.0]) {+ testWidgets(+ 'rename keeps keyboard ownership and rejects blank names at $scale',+ (tester) async {+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = const Size(640, 540);+ addTearDown(tester.view.reset);+ final boundaryKey = GlobalKey();+ String? result;+ var completions = 0;+ await tester.pumpWidget(+ RepaintBoundary(+ key: boundaryKey,+ child: MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(context)+ .copyWith(textScaler: TextScaler.linear(scale)),+ child: child!,+ ),+ home: Scaffold(+ body: Builder(+ builder: (context) => TextButton(+ onPressed: () async {+ result = await showSwarmRenameDialog(context, 'app v2');+ completions++;+ },+ child: const Text('Open'),+ ),+ ),+ ),+ ),+ ),+ );+ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ final field = find.byType(TextField);+ final editor = tester.widget<TextField>(field);+ expect(editor.focusNode!.hasPrimaryFocus, isTrue);+ expect(+ editor.controller!.selection,+ const TextSelection(baseOffset: 0, extentOffset: 6),+ );++ final output = Platform.environment['HARNESS_RENAME_CAPTURE_DIR'];+ if (output != null) {+ final boundary =+ boundaryKey.currentContext!.findRenderObject()!+ as RenderRepaintBoundary;+ await tester.runAsync(() async {+ final image = await boundary.toImage(pixelRatio: 1);+ final bytes = await image.toByteData(+ format: ui.ImageByteFormat.png,+ );+ await Directory(output).create(recursive: true);+ await File('$output/rename-$scale.png')+ .writeAsBytes(bytes!.buffer.asUint8List());+ image.dispose();+ });+ }++ await tester.enterText(field, ' ');+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await tester.pump();+ expect(find.byType(AlertDialog), findsOneWidget);+ expect(completions, 0);+ expect(+ tester+ .widget<FilledButton>(find.widgetWithText(FilledButton, 'Rename'))+ .onPressed,+ isNull,+ );+ await tester.enterText(field, ' Search polish ');+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await tester.pumpAndSettle();+ expect(result, 'Search polish');+ expect(completions, 1);+ expect(find.byType(AlertDialog), findsNothing);++ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ await tester.enterText(find.byType(TextField), 'Unsaved name');+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(result, isNull);+ expect(completions, 2);+ expect(find.byType(AlertDialog), findsNothing);+ expect(tester.takeException(), isNull);+ },+ );+ }+}diff --git a/desktop/tool/swarm_titlebar_checks.swift b/desktop/tool/swarm_titlebar_checks.swiftindex d76438459..9e2318364 100644--- a/desktop/tool/swarm_titlebar_checks.swift+++ b/desktop/tool/swarm_titlebar_checks.swift@@ -11,7 +11,59 @@ private func checkTitlebar(_ condition: @autoclosure () -> Bool, _ message: StrititlebarCheckCount += 1}+private final class TitlebarMouseUpProbe: NSResponder {+ var mouseUps = 0+ override func mouseUp(with event: NSEvent) { mouseUps += 1 }+}++private extension SwarmActionButton {+ func renderedPixels() -> Data {+ let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil,+ pixelsWide: Int(bounds.width), pixelsHigh: Int(bounds.height),+ bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,+ colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!+ let count = bitmap.bytesPerRow * bitmap.pixelsHigh+ bitmap.bitmapData!.initialize(repeating: 0, count: count)+ NSGraphicsContext.saveGraphicsState()+ NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: bitmap)+ draw(bounds)+ NSGraphicsContext.restoreGraphicsState()+ return Data(bytes: bitmap.bitmapData!, count: count)+ }+}+private extension SwarmTabButton {+ func checkDoubleClickIsolation() throws {+ let parent = nextResponder+ let originalEmit = emit+ let probe = TitlebarMouseUpProbe()+ nextResponder = probe+ var actions: [String] = []+ emit = { method, _ in actions.append(method) }+ defer {+ nextResponder = parent+ emit = originalEmit+ actionsEnabled = true+ }+ func event(_ type: NSEvent.EventType, _ count: Int) -> NSEvent {+ NSEvent.mouseEvent(with: type, location: NSPoint(x: 60, y: 20),+ modifierFlags: [], timestamp: Double(count) / 10, windowNumber: 0,+ context: nil, eventNumber: count, clickCount: count, pressure: 1)!+ }+ selectButton.mouseDown(with: event(.leftMouseDown, 1))+ selectButton.mouseUp(with: event(.leftMouseUp, 1))+ selectButton.mouseDown(with: event(.leftMouseDown, 2))+ // Rename can open a modal before the second mouse-up arrives.+ actionsEnabled = false+ selectButton.mouseUp(with: event(.leftMouseUp, 2))+ mouseUp(with: event(.leftMouseUp, 2))+ try checkTitlebar(actions == ["select", "rename"], "A tab double-click selects and renames exactly once")+ try checkTitlebar(probe.mouseUps == 0,+ "Tab mouse-up events cannot reach the window's titlebar double-click handler")+ try checkTitlebar(!selectButton.mouseDownCanMoveWindow && !closeButton.mouseDownCanMoveWindow,+ "Tab action buttons opt out of automatic window movement")+ }+func checkAccessibility(expectedName: String, active: Bool) throws {try checkTitlebar(accessibilityLabel() == expectedName, "Tab group name is available before paint")let children = accessibilityChildren()?.compactMap { $0 as? NSButton } ?? []@@ -103,6 +155,7 @@ private extension SwarmTabStrip {["tabs": rows, "activeId": active, "enabled": enabled, "attention": 2]}update(state(rows, active: "swarm-11"))+ try tabs[0].checkDoubleClickIsolation()let hover = NSEvent.mouseEvent(with: .mouseMoved, location: .zero, modifierFlags: [],timestamp: 0, windowNumber: 0, context: nil, eventNumber: 0, clickCount: 0, pressure: 0)!func click(_ count: Int, at point: NSPoint, time: TimeInterval) -> NSEvent {@@ -206,10 +259,13 @@ private extension SwarmTabStrip {original.clickBothActions()try checkTitlebar(events == ["select", "close"], "Native selection and close dispatch once each")+ let actionPixels = [createButton.renderedPixels(), openButton.renderedPixels()]events.removeAll()update(state([["id": "swarm-0", "name": "Renamed tab"]], active: "swarm-0", enabled: false))try original.checkEnabled(false)try checkTitlebar(!newButton.isEnabled && !notificationButton.isEnabled && !createButton.isEnabled && !openButton.isEnabled, "Titlebar actions disable with a modal")+ try checkTitlebar(actionPixels == [createButton.renderedPixels(), openButton.renderedPixels()],+ "New and Open Harness keep their rendered colors when a workspace modal opens")original.clickBothActions()newButton.performClick(nil)notificationButton.performClick(nil)