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
Resize swarm panes with saved proportions and keyboard control
dee79cbf1c1cf49
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 9f8468bc2..4451cb4e2 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -843,6 +843,8 @@ class _SwarmScreenState extends State<SwarmScreen> {command.id: _actionHandlers[command.action]!,'machine.link': () => _dialog(() => showSwarmLinkDialog(context, app)),'project.add': _addProject,+ 'pane.resize': app.beginPaneResize,+ 'pane.reset_sizes': app.resetPaneSizes,};bool _canExecuteCommand(String id) {@@ -863,6 +865,14 @@ class _SwarmScreenState extends State<SwarmScreen> {if (id == 'navigation.back') return _navigation.canGoBack(app);if (id == 'navigation.forward') return _navigation.canGoForward(app);if (id.startsWith('terminal.')) return _canFindTerminal;+ if (id == 'pane.resize') {+ return app.panes.length > 1 && app.zoomedPaneId == null;+ }+ if (id == 'pane.reset_sizes') {+ return app.activeSwarm.paneSizes.keys.any(+ (key) => key.startsWith('${app.panes.length}:'),+ );+ }if (id.startsWith('pane.') || id == 'task.route') {return app.focusedPane != null;}diff --git a/desktop/lib/shortcuts/keymap_commands.dart b/desktop/lib/shortcuts/keymap_commands.dartindex f53ffda6f..b5dfe09b7 100644--- a/desktop/lib/shortcuts/keymap_commands.dart+++ b/desktop/lib/shortcuts/keymap_commands.dart@@ -236,6 +236,12 @@ final harnessCommands = <HarnessCommand>[action: ShortcutAction.showLayout,nativeAction: 'layout',),+ const HarnessCommand('pane.resize', 'Resize panes', ShortcutGroup.panes),+ const HarnessCommand(+ 'pane.reset_sizes',+ 'Reset pane sizes',+ ShortcutGroup.panes,+ ),const HarnessCommand('terminal.find','Find in the focused terminal',diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 50738deb5..7b318069f 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -36,6 +36,7 @@ import '../ws/ws_conn.dart';import '../ws/local_cli_discovery.dart';import '../ws/ws_pool.dart';import 'pane_preset.dart';+import 'pane_arrangement.dart';import 'pending_question.dart';import '../usage/remote_usage.dart';import '../usage/usage_accounts.dart';@@ -546,7 +547,8 @@ class AppNotifier extends ChangeNotifier {}final restored = Swarm(id: id, name: saved.name)..gridColumns = saved.gridColumns- ..presets.addAll(saved.presets);+ ..presets.addAll(saved.presets)+ ..paneSizes.addAll(saved.paneSizes);for (final entry in saved.panes) {final pane = pool.putIfAbsent((entry.machineId, entry.agentId),@@ -669,21 +671,64 @@ class AppNotifier extends ChangeNotifier {PanePreset? presetFor(int paneCount) =>panePresets[paneCount] ?? PanePreset.defaultFor(paneCount);- /// Choose a shape. Keyed by tile COUNT: three tiles and four tiles are- /// different shapes and one choice cannot speak for both.- ///- /// The shape is now the ONLY thing to choose about the grid — tiles are laid- /// out at the proportions the shape states and nothing is draggable. Which is- /// why the shapes had to become a real list first: dragging was what a person- /// reached for when the one shape on offer was not the one they wanted.+ /// Choosing a preset also resets custom sizes for that pane count. Selecting+ /// the current preset in Command-S is the quick way back to its proportions.void setPreset(int paneCount, PanePreset preset) {if (!PanePreset.forCount(paneCount).contains(preset)) return;- if (presetFor(paneCount) == preset) return;+ final resized = activeSwarm.paneSizes.keys.any(+ (key) => key.startsWith('$paneCount:'),+ );+ if (presetFor(paneCount) == preset && !resized) return;panePresets[paneCount] = preset;+ activeSwarm.paneSizes.removeWhere(+ (key, _) => key.startsWith('$paneCount:'),+ );+ activeSwarm.arranged = null;+ activeSwarm.arrangedKey = null;notifyListeners();_persistLayout();}+ int _paneResizeRequest = 0;+ int get paneResizeRequest => _paneResizeRequest;+ void beginPaneResize() {+ if (panes.length < 2 || zoomedPaneId != null) return;+ _paneResizeRequest++;+ notifyListeners();+ }++ /// Drag frames only update in-memory intent. The completed gesture performs+ /// one ordinary coalesced layout save; terminal sessions remain untouched.+ bool resizePanes(+ String swarmId,+ String layoutKey,+ PaneArrangement arrangement, {+ bool persist = true,+ }) {+ if (activeSwarmId != swarmId ||+ zoomedPaneId != null ||+ arrangement.tiles.length != panes.length ||+ activeSwarm.arrangedKey != layoutKey) {+ return false;+ }+ if (identical(activeSwarm.paneSizes[layoutKey], arrangement)) {+ if (persist) _persistLayout();+ return true;+ }+ activeSwarm.paneSizes[layoutKey] = arrangement;+ while (activeSwarm.paneSizes.length > 64) {+ activeSwarm.paneSizes.remove(activeSwarm.paneSizes.keys.first);+ }+ activeSwarm.arranged = arrangement;+ notifyListeners();+ if (persist) _persistLayout();+ return true;+ }++ void resetPaneSizes() {+ setPreset(panes.length, presetFor(panes.length) ?? PanePreset.auto);+ }+int _nextPaneId = 1;static const maxPanes = 64;@@ -3894,7 +3939,9 @@ class AppNotifier extends ChangeNotifier {int? _wrapVertically(int delta) {final count = panes.length;if (count < 2) return null;- final shape = presetFor(count)?.tilesFor(count, columns: gridColumns);+ final shape = activeSwarm.arranged?.tiles.length == count+ ? activeSwarm.arranged!.tiles+ : presetFor(count)?.tilesFor(count, columns: gridColumns);if (shape == null || shape.length != count) return null;final at = panes.indexWhere((pane) => pane.id == focusedPaneId);if (at < 0) return null;@@ -3989,7 +4036,9 @@ class AppNotifier extends ChangeNotifier {int? _neighbour({required int dx, required int dy}) {final count = panes.length;if (count < 2) return null;- final shape = presetFor(count)?.tilesFor(count, columns: gridColumns);+ final shape = activeSwarm.arranged?.tiles.length == count+ ? activeSwarm.arranged!.tiles+ : presetFor(count)?.tilesFor(count, columns: gridColumns);if (shape == null || shape.length != count) return null;final at = panes.indexWhere((pane) => pane.id == focusedPaneId);if (at < 0) return null;@@ -4279,6 +4328,7 @@ class AppNotifier extends ChangeNotifier {}}}+ swarm.paneSizes.addAll(PaneArrangement.readSaved(raw['paneSizes']));restored.add(swarm);}if (restored.isNotEmpty) {diff --git a/desktop/lib/state/pane_arrangement.dart b/desktop/lib/state/pane_arrangement.dartnew file mode 100644index 000000000..19744d760--- /dev/null+++ b/desktop/lib/state/pane_arrangement.dart@@ -0,0 +1,242 @@+import 'dart:math' as math;+import 'dart:ui';++enum PaneResizeAxis { x, y }++/// Normalized rectangles preserve the preset's topology while its dividers+/// move. They describe slots, not sessions, so moving agents keeps their sizes.+class PaneArrangement {+ PaneArrangement(Iterable<Rect> tiles) : tiles = List.unmodifiable(tiles);+ final List<Rect> tiles;+ static const _epsilon = 0.000001;++ late final List<PaneDivider> dividers = _findDividers();++ List<PaneDivider> _findDividers() {+ final segments =+ <({PaneResizeAxis axis, double at, double start, double end})>[];+ for (final a in tiles) {+ for (final b in tiles) {+ final top = math.max(a.top, b.top);+ final bottom = math.min(a.bottom, b.bottom);+ if ((a.right - b.left).abs() < _epsilon && bottom - top > _epsilon) {+ segments.add((+ axis: PaneResizeAxis.x,+ at: a.right,+ start: top,+ end: bottom,+ ));+ }+ final left = math.max(a.left, b.left);+ final right = math.min(a.right, b.right);+ if ((a.bottom - b.top).abs() < _epsilon && right - left > _epsilon) {+ segments.add((+ axis: PaneResizeAxis.y,+ at: a.bottom,+ start: left,+ end: right,+ ));+ }+ }+ }+ segments.sort((a, b) {+ final axis = a.axis.index.compareTo(b.axis.index);+ if (axis != 0) return axis;+ final at = a.at.compareTo(b.at);+ return at != 0 ? at : a.start.compareTo(b.start);+ });+ final merged =+ <({PaneResizeAxis axis, double at, double start, double end})>[];+ for (final segment in segments) {+ if (merged.isNotEmpty) {+ final previous = merged.last;+ if (segment.axis == previous.axis &&+ (segment.at - previous.at).abs() < _epsilon &&+ segment.start <= previous.end + _epsilon) {+ merged[merged.length - 1] = (+ axis: previous.axis,+ at: previous.at,+ start: previous.start,+ end: math.max(previous.end, segment.end),+ );+ continue;+ }+ }+ merged.add(segment);+ }+ return List.unmodifiable([+ for (final segment in merged)+ PaneDivider(+ axis: segment.axis,+ position: segment.at,+ start: segment.start,+ end: segment.end,+ before: [+ for (var i = 0; i < tiles.length; i++)+ if (_touches(+ tiles[i],+ segment.axis,+ segment.at,+ segment.start,+ segment.end,+ before: true,+ ))+ i,+ ],+ after: [+ for (var i = 0; i < tiles.length; i++)+ if (_touches(+ tiles[i],+ segment.axis,+ segment.at,+ segment.start,+ segment.end,+ before: false,+ ))+ i,+ ],+ ),+ ]);+ }++ static bool _touches(+ Rect tile,+ PaneResizeAxis axis,+ double at,+ double start,+ double end, {+ required bool before,+ }) {+ final edge = axis == PaneResizeAxis.x+ ? before+ ? tile.right+ : tile.left+ : before+ ? tile.bottom+ : tile.top;+ final from = axis == PaneResizeAxis.x ? tile.top : tile.left;+ final to = axis == PaneResizeAxis.x ? tile.bottom : tile.right;+ return (edge - at).abs() < _epsilon &&+ math.min(end, to) - math.max(start, from) > _epsilon;+ }++ PaneArrangement resize(+ PaneDivider divider,+ double position, {+ required Size minimum,+ }) {+ if (!position.isFinite || divider.before.isEmpty || divider.after.isEmpty) {+ return this;+ }+ final horizontal = divider.axis == PaneResizeAxis.x;+ final floor = horizontal ? minimum.width : minimum.height;+ if (!floor.isFinite || floor < 0) return this;+ // A deliberately dense preset may already be below the normal floor.+ // Resizing can improve that tile, but cannot make it smaller than it was.+ final lower = divider.before+ .map((i) {+ final tile = tiles[i];+ return horizontal+ ? tile.left + math.min(floor, tile.width)+ : tile.top + math.min(floor, tile.height);+ })+ .reduce(math.max);+ final upper = divider.after+ .map((i) {+ final tile = tiles[i];+ return horizontal+ ? tile.right - math.min(floor, tile.width)+ : tile.bottom - math.min(floor, tile.height);+ })+ .reduce(math.min);+ if (lower > upper + _epsilon) return this;+ final next = position.clamp(lower, math.max(lower, upper)).toDouble();+ if ((next - divider.position).abs() < _epsilon) return this;+ final before = divider.before.toSet(), after = divider.after.toSet();+ return PaneArrangement([+ for (var i = 0; i < tiles.length; i++)+ Rect.fromLTRB(+ horizontal && after.contains(i) ? next : tiles[i].left,+ !horizontal && after.contains(i) ? next : tiles[i].top,+ horizontal && before.contains(i) ? next : tiles[i].right,+ !horizontal && before.contains(i) ? next : tiles[i].bottom,+ ),+ ]);+ }++ double balancedPosition(PaneDivider divider) {+ final x = divider.axis == PaneResizeAxis.x;+ final start = divider.before+ .map((i) => x ? tiles[i].left : tiles[i].top)+ .reduce(math.max);+ final end = divider.after+ .map((i) => x ? tiles[i].right : tiles[i].bottom)+ .reduce(math.min);+ return (start + end) / 2;+ }++ List<List<double>> toJson() => [+ for (final tile in tiles) [tile.left, tile.top, tile.right, tile.bottom],+ ];++ static PaneArrangement? fromJson(Object? value) {+ if (value is! List || value.length < 2 || value.length > 64) return null;+ final tiles = <Rect>[];+ for (final item in value) {+ if (item is! List ||+ item.length != 4 ||+ item.any((v) => v is! num || !v.isFinite || v < 0 || v > 1)) {+ return null;+ }+ final numbers = item.cast<num>().map((v) => v.toDouble()).toList();+ final rect = Rect.fromLTRB(+ numbers[0],+ numbers[1],+ numbers[2],+ numbers[3],+ );+ if (rect.width < _epsilon ||+ rect.height < _epsilon ||+ tiles.any((tile) {+ final overlap = tile.intersect(rect);+ return overlap.width > _epsilon && overlap.height > _epsilon;+ })) {+ return null;+ }+ tiles.add(rect);+ }+ return PaneArrangement(tiles);+ }++ static Map<String, PaneArrangement> readSaved(Object? value) {+ if (value is! Map) return {};+ final result = <String, PaneArrangement>{};+ for (final entry in value.entries.take(64)) {+ final key = entry.key;+ if (key is! String || key.length > 80) continue;+ final count = int.tryParse(key.split(':').first);+ final arrangement = fromJson(entry.value);+ if (arrangement != null && count == arrangement.tiles.length) {+ result[key] = arrangement;+ }+ }+ return result;+ }+}++class PaneDivider {+ PaneDivider({+ required this.axis,+ required this.position,+ required this.start,+ required this.end,+ required List<int> before,+ required List<int> after,+ }) : before = List.unmodifiable(before),+ after = List.unmodifiable(after);+ final PaneResizeAxis axis;+ final double position, start, end;+ final List<int> before, after;+ String get id => '${axis.name}:${before.join(',')}:${after.join(',')}';+ bool touches(int tile) => before.contains(tile) || after.contains(tile);+}diff --git a/desktop/lib/state/swarm.dart b/desktop/lib/state/swarm.dartindex e19c674b7..66f7c0d46 100644--- a/desktop/lib/state/swarm.dart+++ b/desktop/lib/state/swarm.dart@@ -1,4 +1,5 @@import 'pane_preset.dart';+import 'pane_arrangement.dart';import 'terminal_pane.dart';/// A named arrangement of agents. Membership never owns the agent process.@@ -11,6 +12,9 @@ class Swarm {String name;final List<TerminalPane> panes = [];final Map<int, PanePreset> presets = {};+ final Map<String, PaneArrangement> paneSizes = {};+ PaneArrangement? arranged;+ String? arrangedKey;int? focusedPaneId;int? zoomedPaneId;int? previousPaneId;@@ -42,6 +46,10 @@ class Swarm {'previousFocus': agents.indexWhere((p) => p.id == previousPaneId),'zoom': agents.indexWhere((p) => p.id == zoomedPaneId),'presets': {for (final e in presets.entries) '${e.key}': e.value.id},+ if (paneSizes.isNotEmpty)+ 'paneSizes': {+ for (final e in paneSizes.entries) e.key: e.value.toJson(),+ },'panes': [for (final p in agents)PaneLayoutEntry(@@ -102,6 +110,7 @@ class ClosedSwarm extends ClosedWork {),zoom = swarm.panes.indexWhere((p) => p.id == swarm.zoomedPaneId),presets = Map.unmodifiable(swarm.presets),+ paneSizes = Map.unmodifiable(swarm.paneSizes),panes = List.unmodifiable([for (final pane in swarm.panes)(@@ -121,6 +130,7 @@ class ClosedSwarm extends ClosedWork {final int previousFocus;final int zoom;final Map<int, PanePreset> presets;+ final Map<String, PaneArrangement> paneSizes;final List<({String machineId, String? agentId, bool composerVisible, int? pinnedSlot})>diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dartindex 1d2bc8a1e..d399cad06 100644--- a/desktop/lib/widgets/pane_grid.dart+++ b/desktop/lib/widgets/pane_grid.dart@@ -14,6 +14,7 @@ import '../shared/theme/app_theme.dart' as grid;import '../shortcuts/app_shortcuts.dart' hide TerminalKey;import '../state/app_state.dart';import '../state/pane_preset.dart';+import '../state/pane_arrangement.dart';import '../state/terminal_pane.dart';import '../terminal/terminal_binary.dart';import '../terminal/terminal_font_store.dart';@@ -23,6 +24,7 @@ import 'agent_drag.dart';import 'harness_join_guide_screen.dart';import 'new_agent_dialog.dart';import 'terminal_panel.dart';+import 'pane_resize_handle.dart';/// Terminal views arranged by the chosen preset. Swarms keep each view under/// one stable parent as its rectangle, visibility and keyboard focus change.@@ -218,6 +220,9 @@ class _SwarmCanvas extends StatefulWidget {class _SwarmCanvasState extends State<_SwarmCanvas> {final _scroll = ScrollController(keepScrollOffset: false);final _offsets = <String, double>{};+ final _resizeFocus = FocusNode(debugLabel: 'Resize focused agent');+ final _resizeHelp = OverlayPortalController();+ late int _resizeRequest = widget.notifier.paneResizeRequest;late String _activeId = widget.notifier.activeSwarmId;late int _focusRequest = widget.notifier.paneFocusRequest;Size? _viewportSize;@@ -245,7 +250,13 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {void _onAppChanged() {final app = widget.notifier;+ if (_resizeRequest != app.paneResizeRequest) {+ _resizeRequest = app.paneResizeRequest;+ _resizeFocus.requestFocus();+ _resizeHelp.show();+ }if (_activeId != app.activeSwarmId) {+ if (_resizeHelp.isShowing) _resizeHelp.hide();if (_scroll.hasClients) _offsets[_activeId] = _scroll.offset;_activeId = app.activeSwarmId;// The notification precedes the frame. Restore before layout/paint so@@ -276,6 +287,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {viewport: viewport,preset: app.presetFor(panes.length),minimum: _MinTile.of(),+ sizes: app.activeSwarm.paneSizes,);final rect = geometry.rectangles[index];final current = _scroll.offset;@@ -305,6 +317,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {void dispose() {widget.notifier.removeListener(_onAppChanged);terminalFontStore.removeListener(_onFontChanged);+ _resizeFocus.dispose();_scroll.dispose();super.dispose();}@@ -368,7 +381,12 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {viewport: constraints.biggest,preset: app.presetFor(visible.length),minimum: _MinTile.of(),+ sizes: app.activeSwarm.paneSizes,);+ if (app.zoomedPaneId == null) {+ app.activeSwarm.arranged = layout.arrangement;+ app.activeSwarm.arrangedKey = layout.key;+ }if (layout.columns != null) app.gridColumns = layout.columns;final rectangles = {for (var i = 0; i < visible.length; i++)@@ -411,12 +429,106 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {),),),+ if (app.zoomedPaneId == null && layout.arrangement != null)+ Positioned.fill(+ child: _resizeLayer(layout, constraints.biggest),+ ),],),),);},);++ Widget _resizeLayer(_SwarmGeometry layout, Size viewport) {+ final app = widget.notifier;+ final swarmId = app.activeSwarmId;+ final arrangement = layout.arrangement!;+ final focused = app.panes.indexWhere(+ (pane) => pane.id == app.focusedPaneId,+ );+ final preferred = arrangement.dividers+ .where((divider) => divider.touches(focused))+ .firstOrNull;+ final extent = Size(viewport.width + kPaneGap, layout.height + kPaneGap);+ final floor = _MinTile.of();+ final minimum = Size(+ (floor.width + kPaneGap) / extent.width,+ (floor.height + kPaneGap) / extent.height,+ );+ return OverlayPortal(+ controller: _resizeHelp,+ overlayChildBuilder: (context) => Positioned(+ bottom: 24,+ left: 24,+ right: 24,+ child: IgnorePointer(+ child: Center(+ child: Container(+ key: const ValueKey('pane-resize-hint'),+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),+ decoration: BoxDecoration(+ color: AppColors.surface,+ border: Border.all(color: AppColors.borderStrong),+ borderRadius: BorderRadius.circular(10),+ ),+ child: Text(+ 'Arrow keys resize · Shift for larger steps · Tab next divider · Esc done',+ style: TextStyle(fontSize: 13, color: AppColors.textSoft),+ textAlign: TextAlign.center,+ ),+ ),+ ),+ ),+ ),+ child: FocusScope(+ onFocusChange: (focused) {+ if (!focused && _resizeHelp.isShowing) _resizeHelp.hide();+ },+ child: Stack(+ children: [+ for (final divider in arrangement.dividers)+ Positioned.fromRect(+ key: ValueKey('resize:$swarmId:${layout.key}:${divider.id}'),+ rect: divider.axis == PaneResizeAxis.x+ ? Rect.fromLTWH(+ divider.position * extent.width - kPaneGap,+ divider.start * extent.height,+ kPaneGap,+ (divider.end - divider.start) * extent.height -+ kPaneGap,+ )+ : Rect.fromLTWH(+ divider.start * extent.width,+ divider.position * extent.height - kPaneGap,+ (divider.end - divider.start) * extent.width - kPaneGap,+ kPaneGap,+ ),+ child: PaneResizeHandle(+ arrangement: arrangement,+ divider: divider,+ extent: extent,+ minimum: minimum,+ focusNode: identical(divider, preferred)+ ? _resizeFocus+ : null,+ onChanged: (next, persist) => app.resizePanes(+ swarmId,+ layout.key!,+ next,+ persist: persist,+ ),+ onLeave: () {+ final id = app.focusedPaneId;+ if (id != null) app.focusPane(id, reveal: true);+ },+ ),+ ),+ ],+ ),+ ),+ );+ }}/// Convert the same unit rectangles used by the layout picker and keyboard@@ -428,6 +540,7 @@ class _SwarmGeometry {required Size viewport,required PanePreset? preset,required Size minimum,+ Map<String, PaneArrangement> sizes = const {},}) : height = viewport.height {if (count == 0) return;if (count == 1) {@@ -448,8 +561,18 @@ class _SwarmGeometry {double.infinity,);}+ key =+ '$count:${(preset ?? PanePreset.defaultFor(count))!.id}:${columns ?? 0}:${shape.id}';+ arrangement =+ sizes[key] ?? PaneArrangement(shape.tilesFor(count, columns: columns));+ for (final tile in arrangement!.tiles) {+ height = ((minimum.height + kPaneGap) / tile.height - kPaneGap).clamp(+ height,+ double.infinity,+ );+ }rectangles = [- for (final tile in shape.tilesFor(count, columns: columns))+ for (final tile in arrangement!.tiles)Rect.fromLTWH(tile.left * (viewport.width + kPaneGap),tile.top * (height + kPaneGap),@@ -464,6 +587,8 @@ class _SwarmGeometry {),];}+ String? key;+ PaneArrangement? arrangement;double height;int? columns;List<Rect> rectangles = const [];diff --git a/desktop/lib/widgets/pane_resize_handle.dart b/desktop/lib/widgets/pane_resize_handle.dartnew file mode 100644index 000000000..d78bdaee3--- /dev/null+++ b/desktop/lib/widgets/pane_resize_handle.dart@@ -0,0 +1,208 @@+import 'package:flutter/material.dart';+import 'package:flutter/gestures.dart';+import 'package:flutter/services.dart';++import '../state/pane_arrangement.dart';++/// The existing gap is the hit target. Only hover or keyboard focus reveals+/// its thin grip; pointer movement never changes the focused agent.+class PaneResizeHandle extends StatefulWidget {+ const PaneResizeHandle({+ super.key,+ required this.arrangement,+ required this.divider,+ required this.extent,+ required this.minimum,+ required this.onChanged,+ required this.onLeave,+ this.focusNode,+ });+ final PaneArrangement arrangement;+ final PaneDivider divider;+ final Size extent, minimum;+ final void Function(PaneArrangement arrangement, bool persist) onChanged;+ final VoidCallback onLeave;+ final FocusNode? focusNode;++ @override+ State<PaneResizeHandle> createState() => _PaneResizeHandleState();+}++class _PaneResizeHandleState extends State<PaneResizeHandle> {+ final _ownFocus = FocusNode(debugLabel: 'Resize agents');+ bool _hover = false, _focused = false;+ PaneArrangement? _start, _last;+ PaneDivider? _startDivider;+ FocusNode? _previousFocus;+ double _startPosition = 0;+ bool get _horizontal => widget.divider.axis == PaneResizeAxis.x;+ FocusNode get _focus => widget.focusNode ?? _ownFocus;++ PaneArrangement _resized(double delta) => widget.arrangement.resize(+ widget.divider,+ widget.divider.position + delta,+ minimum: widget.minimum,+ );++ String _value(PaneArrangement arrangement) {+ final tile = arrangement.tiles[widget.divider.before.first];+ final position = _horizontal ? tile.right : tile.bottom;+ return '${(position * 100).round()} percent';+ }++ void _step(double delta) {+ final next = _resized(delta);+ if (!identical(next, widget.arrangement)) widget.onChanged(next, true);+ }++ void _balance() => widget.onChanged(+ widget.arrangement.resize(+ widget.divider,+ widget.arrangement.balancedPosition(widget.divider),+ minimum: widget.minimum,+ ),+ true,+ );++ void _begin(DragStartDetails details) {+ _previousFocus = _focus.hasFocus+ ? null+ : FocusManager.instance.primaryFocus;+ _focus.requestFocus();+ _start = _last = widget.arrangement;+ _startDivider = widget.divider;+ _startPosition = _horizontal+ ? details.globalPosition.dx+ : details.globalPosition.dy;+ }++ void _drag(DragUpdateDetails details) {+ final start = _start, divider = _startDivider;+ if (start == null || divider == null) return;+ final extent = _horizontal ? widget.extent.width : widget.extent.height;+ if (extent <= 0) return;+ final position = _horizontal+ ? details.globalPosition.dx+ : details.globalPosition.dy;+ _last = start.resize(+ divider,+ divider.position + (position - _startPosition) / extent,+ minimum: widget.minimum,+ );+ widget.onChanged(_last!, false);+ }++ void _end(DragEndDetails _) {+ if (_start == null) return;+ _start = null;+ _startDivider = null;+ widget.onChanged(_last ?? widget.arrangement, true);+ _last = null;+ _restoreFocus();+ }++ void _restoreFocus() {+ final previous = _previousFocus;+ _previousFocus = null;+ if (_focus.hasFocus &&+ previous?.context != null &&+ previous!.canRequestFocus) {+ previous.requestFocus();+ }+ }++ void _cancel() {+ final previous = _start;+ _start = null;+ _startDivider = null;+ _last = null;+ if (previous != null) widget.onChanged(previous, true);+ _restoreFocus();+ }++ @override+ void dispose() {+ _ownFocus.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) => Semantics(+ label: _horizontal ? 'Resize agent columns' : 'Resize agent rows',+ value: _value(widget.arrangement),+ increasedValue: _value(_resized(.02)),+ decreasedValue: _value(_resized(-.02)),+ hint: 'Arrow keys resize. Double-click balances. Escape returns to the agent.',+ slider: true,+ onIncrease: () => _step(.02),+ onDecrease: () => _step(-.02),+ child: Focus(+ focusNode: _focus,+ onFocusChange: (value) => setState(() => _focused = value),+ onKeyEvent: (_, event) {+ if (event is! KeyDownEvent && event is! KeyRepeatEvent) {+ return KeyEventResult.ignored;+ }+ final keyboard = HardwareKeyboard.instance;+ if (keyboard.isMetaPressed ||+ keyboard.isControlPressed ||+ keyboard.isAltPressed) {+ return KeyEventResult.ignored;+ }+ if (event.logicalKey == LogicalKeyboardKey.escape) {+ _cancel();+ widget.onLeave();+ return KeyEventResult.handled;+ }+ final decrease = _horizontal+ ? LogicalKeyboardKey.arrowLeft+ : LogicalKeyboardKey.arrowUp;+ final increase = _horizontal+ ? LogicalKeyboardKey.arrowRight+ : LogicalKeyboardKey.arrowDown;+ if (event.logicalKey != decrease && event.logicalKey != increase) {+ return KeyEventResult.ignored;+ }+ _step(+ (event.logicalKey == decrease ? -1 : 1) *+ (keyboard.isShiftPressed ? .1 : .02),+ );+ return KeyEventResult.handled;+ },+ child: MouseRegion(+ cursor: _horizontal+ ? SystemMouseCursors.resizeColumn+ : SystemMouseCursors.resizeRow,+ onEnter: (_) => setState(() => _hover = true),+ onExit: (_) => setState(() => _hover = false),+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ dragStartBehavior: DragStartBehavior.down,+ onDoubleTap: _balance,+ onHorizontalDragStart: _horizontal ? _begin : null,+ onHorizontalDragUpdate: _horizontal ? _drag : null,+ onHorizontalDragEnd: _horizontal ? _end : null,+ onHorizontalDragCancel: _horizontal ? _cancel : null,+ onVerticalDragStart: _horizontal ? null : _begin,+ onVerticalDragUpdate: _horizontal ? null : _drag,+ onVerticalDragEnd: _horizontal ? null : _end,+ onVerticalDragCancel: _horizontal ? null : _cancel,+ child: Center(+ child: Container(+ width: _horizontal ? 2 : double.infinity,+ height: _horizontal ? double.infinity : 2,+ margin: _horizontal+ ? const EdgeInsets.symmetric(vertical: 12)+ : const EdgeInsets.symmetric(horizontal: 12),+ color: _focused+ ? Colors.white70+ : _hover+ ? Colors.white30+ : Colors.transparent,+ ),+ ),+ ),+ ),+ ),+ );+}diff --git a/desktop/test/pane_arrangement_test.dart b/desktop/test/pane_arrangement_test.dartnew file mode 100644index 000000000..d9edb9170--- /dev/null+++ b/desktop/test/pane_arrangement_test.dart@@ -0,0 +1,114 @@+import 'dart:ui';++import 'package:flutter_test/flutter_test.dart';+import 'package:harness/state/pane_arrangement.dart';+import 'package:harness/state/pane_preset.dart';++void main() {+ test(+ 'all preset dividers preserve coverage and avoid overlaps at either limit',+ () {+ for (var count = 2; count <= 16; count++) {+ for (final preset in PanePreset.forCount(count)) {+ final layout = PaneArrangement(preset.tilesFor(count));+ final area = layout.tiles.fold<double>(+ 0,+ (sum, tile) => sum + tile.width * tile.height,+ );+ for (final divider in layout.dividers) {+ for (final position in [-2.0, 2.0]) {+ final moved = layout.resize(+ divider,+ position,+ minimum: const Size(.08, .08),+ );+ expect(+ PaneArrangement.fromJson(moved.toJson()),+ isNotNull,+ reason: '$count ${preset.name} ${divider.id}',+ );+ expect(+ moved.tiles.fold<double>(+ 0,+ (sum, tile) => sum + tile.width * tile.height,+ ),+ closeTo(area, .000001),+ );+ for (var i = 0; i < count; i++) {+ expect(+ moved.tiles[i].width,+ greaterThanOrEqualTo(+ layout.tiles[i].width.clamp(0, .08) - .000001,+ ),+ );+ expect(+ moved.tiles[i].height,+ greaterThanOrEqualTo(+ layout.tiles[i].height.clamp(0, .08) - .000001,+ ),+ );+ }+ }+ }+ }+ }+ },+ );++ test('connected grid dividers stay aligned while separate side stacks resize independently', () {+ final quad = PaneArrangement(PanePreset.quad.tilesFor(4));+ expect(quad.dividers.length, 2);+ final vertical = quad.dividers.singleWhere(+ (d) => d.axis == PaneResizeAxis.x,+ );+ final resized = quad.resize(vertical, .6, minimum: const Size(.1, .1));+ expect(resized.tiles[0].right, .6);+ expect(resized.tiles[2].right, .6);+ final sides = PaneArrangement(PanePreset.middleMain.tilesFor(5));+ expect(sides.dividers.length, 4);+ final left = sides.dividers.singleWhere(+ (d) => d.axis == PaneResizeAxis.y && d.before.contains(0),+ );+ final changed = sides.resize(left, .65, minimum: const Size(.1, .1));+ expect(changed.tiles[0].bottom, .65);+ expect(changed.tiles[3].top, .65);+ for (final untouched in [1, 2, 4]) {+ expect(changed.tiles[untouched], sides.tiles[untouched]);+ }+ });++ test('saved sizes reject malformed, overlapping and non-finite geometry', () {+ for (final raw in [+ null,+ {},+ [],+ [+ [0, 0, 1, 1],+ ],+ [+ [0, 0, .8, 1],+ [.7, 0, 1, 1],+ ],+ [+ [0, 0, double.nan, 1],+ [.5, 0, 1, 1],+ ],+ [+ [0, 0, .5, 1],+ [.5, 0, double.infinity, 1],+ ],+ [+ [0, 0, 0, 1],+ [.5, 0, 1, 1],+ ],+ ]) {+ expect(PaneArrangement.fromJson(raw), isNull);+ }+ final valid = PaneArrangement(PanePreset.columns.tilesFor(2)).toJson();+ expect(+ PaneArrangement.readSaved({'2:columns:0:columns': valid, '3:bad': valid})+ .keys,+ ['2:columns:0:columns'],+ );+ });+}diff --git a/desktop/test/swarm_resize_test.dart b/desktop/test/swarm_resize_test.dartnew file mode 100644index 000000000..5c745e8f2--- /dev/null+++ b/desktop/test/swarm_resize_test.dart@@ -0,0 +1,151 @@+import 'dart:convert';++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/terminal/terminal_binary.dart';+import 'package:harness/widgets/pane_resize_handle.dart';+import 'package:xterm/xterm.dart';++import 'swarm_interactions_test.dart' show chord;+import 'swarm_screen_test.dart' show mount, terminal;+import 'swarm_state_test.dart' show createApp, MemoryStore;++Future<void> mountWide(WidgetTester tester, AppNotifier app) async {+ await mount(tester, app);+ tester.view.physicalSize = const Size(2000, 1200);+ await tester.pump();+}++void main() {+ testWidgets(+ 'dragged proportions retain terminals, survive save/reopen and reset with the same preset',+ (tester) async {+ final store = MemoryStore();+ final app = createApp(store: store);+ app.machineStates['m']!.nodeOnline = true;+ final frames = <TerminalBinaryFrame>[];+ final left = app.adoptSessionForTest(terminal('a0', frames));+ app.adoptSessionForTest(terminal('a1', frames));+ await mountWide(tester, app);+ final pane = find.byKey(left.cellKey);+ final retained = tester.element(+ find.descendant(of: pane, matching: find.byType(TerminalView)),+ );+ final before = tester.getSize(pane).width;+ final focus = app.focusedPaneId;+ await tester.drag(find.byType(PaneResizeHandle), const Offset(130, 0));+ await tester.pump(const Duration(milliseconds: 50));+ expect(tester.getSize(pane).width, greaterThan(before + 100));+ expect(+ tester.element(+ find.descendant(of: pane, matching: find.byType(TerminalView)),+ ),+ same(retained),+ );+ expect(app.focusedPaneId, focus);+ expect(frames, isEmpty);+ await app.flushPaneLayout();+ final saved = jsonDecode(store.values['swarm_layout_v1']!) as Map;+ expect((saved['swarms'] as List).first['paneSizes'], isNotEmpty);+ final sizes = app.activeSwarm.paneSizes.values.single.toJson();+ final restored = createApp(store: store);+ await restored.restorePaneLayoutForTest();+ expect(restored.activeSwarm.paneSizes.values.single.toJson(), sizes);+ expect(restored.panes.every((pane) => pane.session == null), isTrue);+ restored.dispose();+ final originalId = app.activeSwarmId;+ app.newSwarm();+ await app.addAgentToSwarm('m', 'a0');+ // Keep one real fixture session shared during close/reopen.+ app.selectSwarm(originalId);+ await app.closeSwarm(originalId);+ app.reopenClosedSwarm();+ await tester.pump();+ expect(app.activeSwarm.paneSizes.values.single.toJson(), sizes);+ final current = app.presetFor(2)!;+ app.setPreset(2, current);+ await tester.pump();+ expect(app.activeSwarm.paneSizes, isEmpty);+ expect(+ tester.getSize(find.byKey(app.panes.first.cellKey)).width,+ closeTo(before, .1),+ );+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );++ testWidgets(+ 'Escape cancels a pointer resize and returns the next key to the agent',+ (tester) async {+ final app = createApp();+ app.machineStates['m']!.nodeOnline = true;+ final frames = <TerminalBinaryFrame>[];+ final left = app.adoptSessionForTest(terminal('a0', frames));+ final right = app.adoptSessionForTest(terminal('a1', frames));+ await mountWide(tester, app);+ final initial = tester.getSize(find.byKey(left.cellKey));+ final gesture = await tester.startGesture(+ tester.getCenter(find.byType(PaneResizeHandle)),+ );+ await gesture.moveBy(const Offset(120, 0));+ await tester.pump();+ expect(+ tester.getSize(find.byKey(left.cellKey)).width,+ greaterThan(initial.width),+ );+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await gesture.up();+ await tester.pump(const Duration(milliseconds: 50));+ expect(tester.getSize(find.byKey(left.cellKey)), initial);+ expect(app.focusedPaneId, right.id);+ expect(frames, isEmpty);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);+ await tester.pump(const Duration(milliseconds: 10));+ expect(frames.single.bytes, [27, 91, 68]);+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );++ testWidgets(+ 'search opens keyboard resizing without taking Command movement keys',+ (tester) async {+ final app = createApp();+ app.machineStates['m']!.nodeOnline = true;+ final frames = <TerminalBinaryFrame>[];+ final left = app.adoptSessionForTest(terminal('a0', frames));+ app.adoptSessionForTest(terminal('a1', frames));+ await mountWide(tester, app);+ final before = tester.getSize(find.byKey(left.cellKey)).width;+ await chord(tester, LogicalKeyboardKey.keyP);+ await tester.enterText(+ find.byKey(const ValueKey('swarm-search-input')),+ '> resize panes',+ );+ await tester.pump();+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);+ await tester.pump();+ expect(find.byKey(const ValueKey('pane-resize-hint')), findsOneWidget);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);+ await tester.pump();+ expect(+ tester.getSize(find.byKey(left.cellKey)).width,+ greaterThan(before),+ );+ expect(frames, isEmpty);+ await chord(tester, LogicalKeyboardKey.keyH);+ await tester.pump();+ expect(app.focusedPaneId, left.id);+ expect(frames, isEmpty);+ expect(find.byKey(const ValueKey('pane-resize-hint')), findsNothing);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);+ await tester.pump(const Duration(milliseconds: 10));+ expect(frames.single.bytes, [27, 91, 65]);+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );+}diff --git a/docs/harness-v2-developer-tools-research.md b/docs/harness-v2-developer-tools-research.mdindex b0a4fe92c..5bf673e22 100644--- a/docs/harness-v2-developer-tools-research.md+++ b/docs/harness-v2-developer-tools-research.md@@ -22,7 +22,7 @@ Updated 2026-09-13 after user review. Keep the existing simple Command shortcuts| Implemented; measured in isolation | Unified search construction and ranking avoid repeated scans/metadata work. Median catalog construction fell 50% in the 2,059-destination debug fixture; native input-to-display measurement remains separate. || In progress | [Audit all shortcuts and implement a coherent agent-workspace key system with file-first remapping](harness-v2-keyboard-system.md). Config parser/resolver and live reload core pass isolated tests. The catalog now derives the live defaults and feeds `>` search commands. Finish runtime remapping, native menus and help while retaining those defaults. Remapping is not yet enabled. || Calibration in progress; foreground runs paused | Native Release input/navigation fixture with synthetic terminals. No validated latency result yet; resume after the keyboard work stabilizes. Live keyboard/tab/drag and real remote interruption checks remain. |-| Approved; queued | Manual splits/resizing and optional cached search preview. `>` commands are implemented in both search fields; the full 1,125-test suite passed. The user accepted these after reviewing primary-source precedents; no permanent clutter or slowing the fast path. Match highlighting is the smaller search refinement. [The six-prototype review](harness-v2-prototype-review.md) records what to borrow and what stays out. |+| Resizing and commands implemented; splits/preview next | `>` commands work in both search fields. Controlled resizing uses the existing gaps, saves proportions, protects usable sizes, retains terminal elements and has keyboard access through search; Cmd-S resets through the layout picker. The full 1,131-test suite passed before the final temporary-hint refinement, which passed focused checks. Deliberate right/down splits and optional cached search preview remain next. Match highlighting is the smaller search refinement. [The six-prototype review](harness-v2-prototype-review.md) records what to borrow and what stays out. || Keep deferred | Workflow canvases, autonomous manager layers, a full IDE/Git client and a marketplace. |## Remaining ideas for reviewdiff --git a/docs/harness-v2-progress.md b/docs/harness-v2-progress.mdindex 4ef2c24f2..7771a15d7 100644--- a/docs/harness-v2-progress.md+++ b/docs/harness-v2-progress.md@@ -2,14 +2,23 @@Updated 2026-09-13 with coordinated palettes, Models, combined closed-work History and faster unified search. This is a working preview, not a release.-## Active follow-up: commands and keyboard integration+## Active follow-up: controlled resizing++- The existing Swarm gaps now resize adjacent agents. Connected divider segments stay aligned; disconnected side stacks can resize independently. Limits derive from the existing 40-column/12-row terminal floor. A deliberately dense preset cannot shrink further below its existing size. Double-click balances the neighboring space.+- Proportions persist per Swarm, pane count, preset and responsive orientation/column count. Drag frames stay in memory, with an ordinary coalesced layout save when the drag finishes. Saved data is bounded and rejects malformed/overlapping rectangles. Offline restoration and closed-Swarm reopening retain sizes. Selecting any layout through Cmd-S, including the current one, resets custom proportions for that pane count.+- `> Resize panes` focuses a nearby divider. Arrows move in 2% steps, Shift-arrows in 10% steps, Tab selects another divider and Escape returns to the agent. A temporary hint explains those keys. `> Reset pane sizes` resets directly. No existing shortcut changed. Pointer cancellation restores the starting arrangement; input focus returns to the original agent. Terminal elements and sessions stay mounted.+- Validation: **1,131 Flutter tests passed, one existing skip**, including geometry limits across all existing presets, saved/offline/reopened proportions, cancellation and exact next-key ownership. The final temporary-hint refinement passed the focused resize/canvas run plus an isolated render. The render initially targeted the crossing of two dividers; its corrected pointer position and explicit width assertion verify the intended drag. Analyzer has no errors/warnings and 12 existing vendored infos. Artifacts: `/private/tmp/harness-v2-resize-{tests,full-tests,final-checks,analyze,render,build}.log` and `/private/tmp/harness-v2-resize-{resized,focused}.png`.+- Release build succeeded and the preview was relaunched. The verified preview PID 84992 was normally quit and confirmed exited before rebuilding; re-observe the current PID before another restart. Live native capture remains unavailable; current visual evidence is isolated rendering with system fonts. No real agent received test input.+- Next: deliberate right/down splits using the same stable rectangles, optional cached search preview, and file-remapping ownership across AppKit and Flutter.++## Commands and keyboard integration checkpoint- Both real search fields now accept `>` for existing workspace commands. Command results use compact rows and show the actual default shortcut. Commands stay out of ordinary agent/swarm search and History; clearing `>` returns to regular navigation. A small hint appears only in open, empty search. No new permanent button or conflicting shortcut was added.- Search and keyboard actions share the same callbacks. The command catalog derives workspace bindings directly from the current live table, including Cmd-H/J/K/L and arrows, Cmd-B, Cmd-S, Cmd-R, Cmd-number pane selection, Cmd-Enter zoom, Cmd-Shift-P pin and current tab/history keys. The withdrawn modifier-heavy defaults are removed. **File remapping remains unconnected until native menus, Flutter input, help and native search can agree on its effective bindings.**- Availability is checked again at selection and execution. A command cannot add an agent or be resolved as an agent destination. Queries never reach a session. Fixed return focus after non-navigation commands and made Rename focus its selected name immediately; the Rename controller now follows the dialog lifecycle instead of a delayed disposal timer.- **1,125 Flutter tests passed, with one existing skip.** Analyzer: no errors or warnings, 12 existing vendored infos. After making command rows compact, all 15 focused command/search checks passed. Final visual fixtures for both inputs were rendered and reviewed; their helper initially failed its cleanup invariant after enabling real shadows, then was corrected to restore that test-only flag. Logs: `/private/tmp/harness-v2-command-{full-tests,focus,final-checks,analyze,render,build}.log`; images: `/private/tmp/harness-v2-commands-{top,inline}.png`.- Release build succeeded. Before rebuilding, normally quit verified preview PID 71858 and verified it exited. Re-observe the relaunched preview process/window before later interaction. No real agent received test input and no real session was closed for testing.-- Next: complete file-remapping ownership across AppKit and Flutter, then controlled splits/resizing and optional cached preview. Do not reapply `/private/tmp/harness-v2-keyboard-wiring-before-inline-search.patch` blindly; its search paths and assumptions are obsolete.+- File-remapping ownership across AppKit and Flutter remains pending. Do not reapply `/private/tmp/harness-v2-keyboard-wiring-before-inline-search.patch` blindly; its search paths and assumptions are obsolete.## Previous checkpoint: first use