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
Place new agents in deliberate right and down splits
dee90a7ec461fbc
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 4451cb4e2..7a186f196 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -14,6 +14,7 @@ import '../shared/theme/app_theme.dart' as grid;import '../shortcuts/app_shortcuts.dart';import '../shortcuts/keymap_commands.dart';import '../state/app_state.dart';+import '../state/pane_arrangement.dart';import '../terminal/terminal_viewport.dart';import '../usage/models_menu_controller.dart';import '../state/swarm_catalog.dart';@@ -393,6 +394,7 @@ class _SwarmScreenState extends State<SwarmScreen> {String? machineId,String? folder,String? swarmId,+ PaneSplitRequest? split,}) => _dialog(() async {final local = app.machineStates.values.where((m) => m.isLocalMachine)@@ -412,8 +414,26 @@ class _SwarmScreenState extends State<SwarmScreen> {source: 'swarm',initialFolder: folder,swarmId: swarmId,+ split: split,);});++ Future<void> _splitAgent(PaneResizeAxis axis) async {+ final split = app.preparePaneSplit(axis);+ final pane = app.focusedPane;+ if (split == null || pane == null) return;+ final machine = app.machineStates[pane.machineId];+ final agent = machine?.agents+ .where((a) => a.id == pane.agentId)+ .firstOrNull;+ await _newAgent(+ machineId: pane.machineId,+ folder: agent == null ? null : machine?.projectOf(agent)?.cwd,+ swarmId: split.swarmId,+ split: split,+ );+ }+Future<void> _jump({bool historyOnly = false}) async {if (!historyOnly) {_openSearch();@@ -845,6 +865,8 @@ class _SwarmScreenState extends State<SwarmScreen> {'project.add': _addProject,'pane.resize': app.beginPaneResize,'pane.reset_sizes': app.resetPaneSizes,+ 'pane.split_right': () => _splitAgent(PaneResizeAxis.x),+ 'pane.split_down': () => _splitAgent(PaneResizeAxis.y),};bool _canExecuteCommand(String id) {@@ -868,6 +890,12 @@ class _SwarmScreenState extends State<SwarmScreen> {if (id == 'pane.resize') {return app.panes.length > 1 && app.zoomedPaneId == null;}+ if (id == 'pane.split_right') {+ return app.preparePaneSplit(PaneResizeAxis.x) != null;+ }+ if (id == 'pane.split_down') {+ return app.preparePaneSplit(PaneResizeAxis.y) != null;+ }if (id == 'pane.reset_sizes') {return app.activeSwarm.paneSizes.keys.any((key) => key.startsWith('${app.panes.length}:'),diff --git a/desktop/lib/shortcuts/keymap_commands.dart b/desktop/lib/shortcuts/keymap_commands.dartindex b5dfe09b7..e81de7a31 100644--- a/desktop/lib/shortcuts/keymap_commands.dart+++ b/desktop/lib/shortcuts/keymap_commands.dart@@ -237,6 +237,8 @@ final harnessCommands = <HarnessCommand>[nativeAction: 'layout',),const HarnessCommand('pane.resize', 'Resize panes', ShortcutGroup.panes),+ const HarnessCommand('pane.split_right', 'Split right…', ShortcutGroup.panes),+ const HarnessCommand('pane.split_down', 'Split down…', ShortcutGroup.panes),const HarnessCommand('pane.reset_sizes','Reset pane sizes',diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 7b318069f..9f3c9bde9 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -606,7 +606,31 @@ class AppNotifier extends ChangeNotifier {agentId: agent.agentId,)..composerVisible = agent.composerVisible);if (!target.panes.contains(pane)) {+ final restoreManual =+ agent.manualLayout != null &&+ listEquals(+ target.panes.map((p) => (p.machineId, p.agentId)).toList(),+ agent.remainingAgents,+ ) &&+ (target.panes.length == 1 ||+ listEquals(+ target.manualLayout?.tiles,+ agent.manualLayout!.remove(agent.index)?.tiles,+ ));+ if (restoreManual) {+ target.pinnedSlots.updateAll(+ (_, slot) => slot >= agent.index ? slot + 1 : slot,+ );+ }target.panes.insert(agent.index.clamp(0, target.panes.length), pane);+ if (restoreManual) {+ target.savePaneSizes(+ '${target.panes.length}:manual',+ agent.manualLayout!,+ );+ } else if (agent.manualLayout != null) {+ target.paneSizes.remove('${target.panes.length}:manual');+ }if (agent.pinnedSlot != null &&!target.pinnedSlots.containsValue(agent.pinnedSlot)) {target.pinnedSlots[pane.id] = agent.pinnedSlot!;@@ -697,6 +721,47 @@ class AppNotifier extends ChangeNotifier {notifyListeners();}+ PaneSplitRequest? preparePaneSplit(PaneResizeAxis axis) {+ if (zoomedPaneId != null || panes.length >= maxPanes) return null;+ final before = activeSwarm.arranged;+ final minimum = activeSwarm.arrangedMinimum;+ final index = panes.indexWhere(+ (p) => p.id == focusedPaneId && p.agentId != null,+ );+ if (before == null ||+ minimum == null ||+ before.tiles.length != panes.length) {+ return null;+ }+ final after = before.split(index, axis, minimum: minimum);+ if (after == null || focusedPaneId == null) return null;+ return PaneSplitRequest(+ swarmId: activeSwarmId,+ paneId: focusedPaneId!,+ axis: axis,+ paneIds: panes.map((p) => p.id),+ before: before,+ after: after,+ );+ }++ bool isPaneSplitCurrent(PaneSplitRequest split) {+ final target = swarms.where((s) => s.id == split.swarmId).firstOrNull;+ final minimum = target?.arrangedMinimum;+ return !_disposed &&+ target != null &&+ target.zoomedPaneId == null &&+ minimum != null &&+ listEquals(target.panes.map((p) => p.id).toList(), split.paneIds) &&+ listEquals(target.arranged?.tiles, split.before.tiles) &&+ split.before.split(+ split.paneIds.indexOf(split.paneId),+ split.axis,+ minimum: minimum,+ ) !=+ null;+ }+/// Drag frames only update in-memory intent. The completed gesture performs/// one ordinary coalesced layout save; terminal sessions remain untouched.bool resizePanes(@@ -715,10 +780,7 @@ class AppNotifier extends ChangeNotifier {if (persist) _persistLayout();return true;}- activeSwarm.paneSizes[layoutKey] = arrangement;- while (activeSwarm.paneSizes.length > 64) {- activeSwarm.paneSizes.remove(activeSwarm.paneSizes.keys.first);- }+ activeSwarm.savePaneSizes(layoutKey, arrangement);activeSwarm.arranged = arrangement;notifyListeners();if (persist) _persistLayout();@@ -3314,8 +3376,12 @@ class AppNotifier extends ChangeNotifier {bool bypassPermission = false,String? codexHome,String? swarmId,+ PaneSplitRequest? split,}) async {- final targetId = swarmId ?? activeSwarmId;+ if (split != null && !isPaneSplitCurrent(split)) {+ return 'The layout changed. Close this dialog and split the agent again.';+ }+ final targetId = split?.swarmId ?? swarmId ?? activeSwarmId;if (!swarms.any((s) => s.id == targetId)) return 'This swarm was closed';final target = swarms.firstWhere((s) => s.id == targetId);if (target.panes.length >= maxPanes) {@@ -3367,7 +3433,19 @@ class AppNotifier extends ChangeNotifier {// count of what this app launched.harnessStats.onAgentSpawned();notifyListeners();- await addAgentToSwarm(machineId, agent.id, swarmId: targetId);+ if (split != null && !isPaneSplitCurrent(split)) {+ _lastError = 'The agent was created, but the original layout changed. Find it in Search.';+ _lastErrorRetryable = false;+ notifyListeners();+ return null;+ }+ await assignAgentToPane(+ null,+ machineId,+ agent.id,+ swarmId: targetId,+ split: split,+ );return null;}@@ -3717,11 +3795,18 @@ class AppNotifier extends ChangeNotifier {String machineId,String agentId, {String? swarmId,+ PaneSplitRequest? split,}) async {final target = swarms.where((s) => s.id == (swarmId ?? activeSwarmId)).firstOrNull;if (target == null || _disposed) return;+ if (split != null &&+ (split.swarmId != target.id ||+ paneId != null ||+ !isPaneSplitCurrent(split))) {+ return;+ }final targetPanes = target.panes;final machine = machineStates[machineId];if (machine == null) return;@@ -3760,7 +3845,9 @@ class AppNotifier extends ChangeNotifier {return;}final insertion = replaced == null- ? targetPanes.length+ ? split == null+ ? targetPanes.length+ : split.paneIds.indexOf(split.paneId) + 1: targetPanes.indexOf(replaced);if (existing != null) target.remove(existing);if (replaced != null) target.remove(replaced);@@ -3768,6 +3855,15 @@ class AppNotifier extends ChangeNotifier {shared ??TerminalPane(id: _nextPaneId++, machineId: machineId, agentId: agentId);targetPanes.insert(insertion.clamp(0, targetPanes.length), pane);+ if (split != null) {+ target.pinnedSlots.updateAll(+ (_, slot) => slot >= insertion ? slot + 1 : slot,+ );+ final key = '${targetPanes.length}:manual';+ target.savePaneSizes(key, split.after);+ target.arranged = split.after;+ target.arrangedKey = key;+ }if (replaced != null && !allPanes.contains(replaced)) {// Release just the desktop stream. The CLI agent process keeps running.unawaited(_detachSession(replaced, sendClose: true));@@ -3800,7 +3896,10 @@ class AppNotifier extends ChangeNotifier {notifyListeners();return;}- if (!machine.terminalCapabilityAvailable) return;+ if (!machine.terminalCapabilityAvailable) {+ notifyListeners();+ return;+ }machine.pendingOfflineAgentId = null;_stopOfflineRetry(machineId);notifyListeners();diff --git a/desktop/lib/state/pane_arrangement.dart b/desktop/lib/state/pane_arrangement.dartindex 19744d760..ab9ca8c4f 100644--- a/desktop/lib/state/pane_arrangement.dart+++ b/desktop/lib/state/pane_arrangement.dart@@ -12,6 +12,88 @@ class PaneArrangement {late final List<PaneDivider> dividers = _findDividers();+ PaneArrangement? split(+ int index,+ PaneResizeAxis axis, {+ required Size minimum,+ }) {+ if (index < 0 || index >= tiles.length || tiles.length >= 64) return null;+ final tile = tiles[index];+ final x = axis == PaneResizeAxis.x;+ if (x ? tile.width / 2 < minimum.width : tile.height / 2 < minimum.height) {+ return null;+ }+ final first = x+ ? Rect.fromLTRB(tile.left, tile.top, tile.center.dx, tile.bottom)+ : Rect.fromLTRB(tile.left, tile.top, tile.right, tile.center.dy);+ final second = x+ ? Rect.fromLTRB(tile.center.dx, tile.top, tile.right, tile.bottom)+ : Rect.fromLTRB(tile.left, tile.center.dy, tile.right, tile.bottom);+ return PaneArrangement([+ ...tiles.take(index),+ first,+ second,+ ...tiles.skip(index + 1),+ ]);+ }++ /// Expand a complete neighboring edge into a removed slot. This preserves+ /// the other cuts, including nested splits. An unsupported shape falls back+ /// to the count's preset instead of leaving a hole or overlapping terminals.+ PaneArrangement? remove(int index) {+ if (index < 0 || index >= tiles.length || tiles.length < 2) return null;+ final removed = tiles[index];+ for (final axis in PaneResizeAxis.values) {+ final x = axis == PaneResizeAxis.x;+ final start = x ? removed.top : removed.left;+ final end = x ? removed.bottom : removed.right;+ for (final before in [true, false]) {+ final at = x+ ? (before ? removed.left : removed.right)+ : (before ? removed.top : removed.bottom);+ final neighbors = [+ for (var i = 0; i < tiles.length; i++)+ if (i != index &&+ _touches(tiles[i], axis, at, start, end, before: before))+ i,+ ];+ neighbors.sort(+ (a, b) => (x ? tiles[a].top : tiles[a].left).compareTo(+ x ? tiles[b].top : tiles[b].left,+ ),+ );+ var cursor = start;+ var covers = neighbors.isNotEmpty;+ for (final i in neighbors) {+ final tile = tiles[i];+ final from = x ? tile.top : tile.left;+ final to = x ? tile.bottom : tile.right;+ if ((from - cursor).abs() > _epsilon || to > end + _epsilon) {+ covers = false;+ break;+ }+ cursor = to;+ }+ if (!covers || (cursor - end).abs() > _epsilon) continue;+ final moving = neighbors.toSet();+ return PaneArrangement([+ for (var i = 0; i < tiles.length; i++)+ if (i != index)+ if (!moving.contains(i))+ tiles[i]+ else+ Rect.fromLTRB(+ x && !before ? removed.left : tiles[i].left,+ !x && !before ? removed.top : tiles[i].top,+ x && before ? removed.right : tiles[i].right,+ !x && before ? removed.bottom : tiles[i].bottom,+ ),+ ]);+ }+ }+ return null;+ }+List<PaneDivider> _findDividers() {final segments =<({PaneResizeAxis axis, double at, double start, double end})>[];@@ -224,6 +306,24 @@ class PaneArrangement {}}+/// Captured before a creation dialog/network request. Completion must still+/// match these slots; it can never split whichever agent is focused later.+class PaneSplitRequest {+ PaneSplitRequest({+ required this.swarmId,+ required this.paneId,+ required this.axis,+ required Iterable<int> paneIds,+ required this.before,+ required this.after,+ }) : paneIds = List.unmodifiable(paneIds);+ final String swarmId;+ final int paneId;+ final PaneResizeAxis axis;+ final List<int> paneIds;+ final PaneArrangement before, after;+}+class PaneDivider {PaneDivider({required this.axis,diff --git a/desktop/lib/state/swarm.dart b/desktop/lib/state/swarm.dartindex 66f7c0d46..740b62591 100644--- a/desktop/lib/state/swarm.dart+++ b/desktop/lib/state/swarm.dart@@ -1,3 +1,5 @@+import 'dart:ui' show Size;+import 'pane_preset.dart';import 'pane_arrangement.dart';import 'terminal_pane.dart';@@ -15,16 +17,40 @@ class Swarm {final Map<String, PaneArrangement> paneSizes = {};PaneArrangement? arranged;String? arrangedKey;+ Size? arrangedMinimum;int? focusedPaneId;int? zoomedPaneId;int? previousPaneId;int? gridColumns;final Map<int, int> pinnedSlots = {};+ PaneArrangement? get manualLayout => paneSizes['${panes.length}:manual'];++ void savePaneSizes(String key, PaneArrangement arrangement) {+ paneSizes[key] = arrangement;+ while (paneSizes.length > 64) {+ paneSizes.remove(paneSizes.keys.first);+ }+ }+void remove(TerminalPane pane) {final index = panes.indexOf(pane);if (index < 0) return;+ final manual = manualLayout;panes.removeAt(index);+ if (manual != null && panes.length > 1) {+ final next = manual.remove(index);+ if (next == null) {+ paneSizes.remove('${panes.length}:manual');+ } else {+ savePaneSizes('${panes.length}:manual', next);+ }+ }+ if (manual != null) {+ pinnedSlots.updateAll((_, slot) => slot > index ? slot - 1 : slot);+ }+ arranged = null;+ arrangedKey = null;pinnedSlots.remove(pane.id);if (focusedPaneId == pane.id) {focusedPaneId = panes.isEmpty@@ -84,6 +110,11 @@ class ClosedAgent extends ClosedWork {agentId = pane.agentId!,composerVisible = pane.composerVisible,pinnedSlot = swarm.pinnedSlots[pane.id],+ manualLayout = swarm.manualLayout,+ remainingAgents = List.unmodifiable([+ for (final other in swarm.panes)+ if (other != pane) (other.machineId, other.agentId),+ ]),zoomed = swarm.zoomedPaneId == pane.id;final String swarmId, swarmName, machineId, machineName, agentId, name;@@ -91,6 +122,8 @@ class ClosedAgent extends ClosedWork {final int index;final bool composerVisible, zoomed;final int? pinnedSlot;+ final PaneArrangement? manualLayout;+ final List<(String, String?)> remainingAgents;}/// Terminal buffers and controllers are released normally; a reopened viewdiff --git a/desktop/lib/widgets/new_agent_dialog.dart b/desktop/lib/widgets/new_agent_dialog.dartindex 726832d83..0891c4179 100644--- a/desktop/lib/widgets/new_agent_dialog.dart+++ b/desktop/lib/widgets/new_agent_dialog.dart@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';import '../analytics/analytics.dart';+import '../state/pane_arrangement.dart';import '../core/engine_availability.dart';import '../core/codex_profiles.dart';import '../shared/theme/app_theme.dart' as grid;@@ -41,6 +42,7 @@ Future<void> showNewAgentDialog(required String source,String? initialFolder,String? swarmId,+ PaneSplitRequest? split,}) {// Reported here rather than at each call site: the doors are four and// growing, and one that forgets to track is a hole in the funnel that only@@ -53,6 +55,7 @@ Future<void> showNewAgentDialog(machineId: machineId,initialFolder: initialFolder,swarmId: swarmId ?? notifier.activeSwarmId,+ split: split,),);}@@ -62,12 +65,14 @@ class _NewAgentDialog extends StatefulWidget {final String machineId;final String? initialFolder;final String swarmId;+ final PaneSplitRequest? split;const _NewAgentDialog({required this.notifier,required this.machineId,this.initialFolder,required this.swarmId,+ this.split,});@override@@ -322,6 +327,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {engine: engine,folder: folder,swarmId: widget.swarmId,+ split: widget.split,bypassPermission: bypassPermission,// Keep the explicit choice even if machine discovery changes mid-submit.// The notifier must reject a now-remote target, never use its default login.@@ -357,11 +363,11 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {_folder != null && !_submitting && !_waitingForCodexProfile;return AlertDialog(- // JUST "New agent". The machine used to be named here, and it was telling- // somebody what they had already done: this dialog is opened FROM a- // machine — its row, its `+`, its empty pane — so there is no other one it- // could be for.- title: const Text('New agent'),+ title: Text(switch (widget.split?.axis) {+ PaneResizeAxis.x => 'New agent to the right',+ PaneResizeAxis.y => 'New agent below',+ null => 'New agent',+ }),titleTextStyle: Theme.of(context).textTheme.titleMedium,content: SizedBox(width: _dialogWidth,diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dartindex d399cad06..10905aa13 100644--- a/desktop/lib/widgets/pane_grid.dart+++ b/desktop/lib/widgets/pane_grid.dart@@ -386,6 +386,11 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {if (app.zoomedPaneId == null) {app.activeSwarm.arranged = layout.arrangement;app.activeSwarm.arrangedKey = layout.key;+ final minimum = _MinTile.of();+ app.activeSwarm.arrangedMinimum = Size(+ (minimum.width + kPaneGap) / (constraints.maxWidth + kPaneGap),+ (minimum.height + kPaneGap) / (layout.height + kPaneGap),+ );}if (layout.columns != null) app.gridColumns = layout.columns;final rectangles = {@@ -429,7 +434,8 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {),),),- if (app.zoomedPaneId == null && layout.arrangement != null)+ if (app.zoomedPaneId == null &&+ layout.arrangement?.dividers.isNotEmpty == true)Positioned.fill(child: _resizeLayer(layout, constraints.biggest),),@@ -545,13 +551,17 @@ class _SwarmGeometry {if (count == 0) return;if (count == 1) {rectangles = [Offset.zero & viewport];+ arrangement = PaneArrangement(const [Rect.fromLTRB(0, 0, 1, 1)]);+ key = '1:single';return;}var shape = preset ?? PanePreset.defaultFor(count)!;if (shape == PanePreset.splitLong && viewport.height > viewport.width) {shape = PanePreset.rows;}- if (shape == PanePreset.auto || shape.statedColumns != null) {+ final manual = sizes['$count:manual'];+ if (manual == null &&+ (shape == PanePreset.auto || shape.statedColumns != null)) {columns =(shape.statedColumns ?? (viewport.width / minimum.width).floor()).clamp(1, count);@@ -561,8 +571,9 @@ class _SwarmGeometry {double.infinity,);}- key =- '$count:${(preset ?? PanePreset.defaultFor(count))!.id}:${columns ?? 0}:${shape.id}';+ key = manual != null+ ? '$count:manual'+ : '$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) {diff --git a/desktop/test/agent_events_test.dart b/desktop/test/agent_events_test.dartindex d330a9d9d..028179a59 100644--- a/desktop/test/agent_events_test.dart+++ b/desktop/test/agent_events_test.dart@@ -14,6 +14,7 @@ import 'package:harness/auth/auth_session.dart';import 'package:harness/core/config.dart';import 'package:harness/core/models.dart';import 'package:harness/state/app_state.dart';+import 'package:harness/state/pane_arrangement.dart';import 'package:harness/widgets/new_agent_dialog.dart';/// Keeps every tracked event, so a test can assert on the name AND the params@@ -60,6 +61,7 @@ class FakeCreateAgentNotifier extends AppNotifier {bool bypassPermission = false,String? codexHome,String? swarmId,+ PaneSplitRequest? split,}) async => null;}diff --git a/desktop/test/first_workspace_test.dart b/desktop/test/first_workspace_test.dartindex 488885d71..462071828 100644--- a/desktop/test/first_workspace_test.dart+++ b/desktop/test/first_workspace_test.dart@@ -9,6 +9,7 @@ import 'package:harness/core/engine_availability.dart';import 'package:harness/core/models.dart';import 'package:harness/shared/widgets/app_select_field.dart';import 'package:harness/state/app_state.dart';+import 'package:harness/state/pane_arrangement.dart';import 'package:harness/terminal/terminal_binary.dart';import 'package:xterm/xterm.dart';@@ -52,6 +53,7 @@ class _FirstUseApp extends AppNotifier {bool bypassPermission = false,String? codexHome,String? swarmId,+ PaneSplitRequest? split,}) async {launches.add((machine: machineId,diff --git a/desktop/test/new_agent_codex_profile_test.dart b/desktop/test/new_agent_codex_profile_test.dartindex 683850f76..0f692ce2c 100644--- a/desktop/test/new_agent_codex_profile_test.dart+++ b/desktop/test/new_agent_codex_profile_test.dart@@ -8,6 +8,7 @@ import 'package:harness/core/config.dart';import 'package:harness/core/engine_availability.dart';import 'package:harness/core/models.dart';import 'package:harness/state/app_state.dart';+import 'package:harness/state/pane_arrangement.dart';import 'package:harness/widgets/new_agent_dialog.dart';class _Folders extends FileSelectorPlatform {@@ -98,6 +99,7 @@ class _Notifier extends AppNotifier {bool bypassPermission = false,String? codexHome,String? swarmId,+ PaneSplitRequest? split,}) async {calls.add({'engine': engine, 'codexHome': codexHome, 'folder': folder});return null;diff --git a/desktop/test/pane_arrangement_test.dart b/desktop/test/pane_arrangement_test.dartindex d9edb9170..5cd9afec6 100644--- a/desktop/test/pane_arrangement_test.dart+++ b/desktop/test/pane_arrangement_test.dart@@ -1,10 +1,45 @@import 'dart:ui';+import 'dart:math';import 'package:flutter_test/flutter_test.dart';import 'package:harness/state/pane_arrangement.dart';import 'package:harness/state/pane_preset.dart';void main() {+ test('nested splits and local close repairs retain complete nonoverlapping coverage', () {+ final random = Random(17);+ for (var trial = 0; trial < 30; trial++) {+ var arrangement = PaneArrangement(const [Rect.fromLTRB(0, 0, 1, 1)]);+ for (var count = 1; count < 16; count++) {+ arrangement = arrangement.split(+ random.nextInt(count),+ PaneResizeAxis.values[random.nextInt(2)],+ minimum: Size.zero,+ )!;+ }+ while (arrangement.tiles.length > 1) {+ expect(PaneArrangement.fromJson(arrangement.toJson()), isNotNull);+ expect(+ arrangement.tiles.fold<double>(+ 0,+ (sum, tile) => sum + tile.width * tile.height,+ ),+ closeTo(1, .000001),+ );+ final next = arrangement.remove(+ random.nextInt(arrangement.tiles.length),+ );+ // Interlocking cuts may have no complete edge that can fill the hole.+ // A null repair explicitly asks the caller to return to its preset.+ if (next == null) break;+ arrangement = next;+ }+ if (arrangement.tiles.length == 1) {+ expect(arrangement.tiles.single, const Rect.fromLTRB(0, 0, 1, 1));+ }+ }+ });+test('all preset dividers preserve coverage and avoid overlaps at either limit',() {diff --git a/desktop/test/swarm_split_test.dart b/desktop/test/swarm_split_test.dartnew file mode 100644index 000000000..78bc232d0--- /dev/null+++ b/desktop/test/swarm_split_test.dart@@ -0,0 +1,244 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/models.dart';+import 'package:harness/state/pane_arrangement.dart';+import 'package:harness/state/pane_preset.dart';+import 'package:harness/terminal/terminal_binary.dart';+import 'package:harness/ws/ws_conn.dart';+import 'package:xterm/xterm.dart';++import 'swarm_interactions_test.dart' show chord;+import 'swarm_resize_test.dart' show mountWide;+import 'swarm_screen_test.dart' show terminal;+import 'swarm_state_test.dart' show createApp, MemoryStore;++class _Creation extends WsConn {+ _Creation()+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'm',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );+ final reply = Completer<Map<String, dynamic>>();+ final calls = <String>[];+ @override+ Future<Map<String, dynamic>> request(+ String type, {+ Map<String, dynamic> payload = const {},+ Duration timeout = const Duration(seconds: 20),+ }) {+ calls.add(type);+ return type == 'agent_create' ? reply.future : Future.value({});+ }++ void complete() => reply.complete({+ 'agent': {'id': 'created', 'name': 'Created', 'engine': 'claude'},+ });+}++void main() {+ testWidgets(+ 'manual split keeps neighboring terminals and pins, restores offline and closes/reopens precisely',+ (tester) async {+ final store = MemoryStore();+ final app = createApp(store: store);+ app.machineStates['m']!.nodeOnline = true;+ app.machineStates['m']!.localOnly = true;+ final frames = <TerminalBinaryFrame>[];+ final first = app.adoptSessionForTest(terminal('a0', frames));+ final second = app.adoptSessionForTest(terminal('a1', frames));+ final third = app.adoptSessionForTest(terminal('a2', frames));+ final original = app.activeSwarmId;+ app.togglePinPane(second.id);+ app.newSwarm();+ final shared = app.adoptSessionForTest(terminal('a3', frames));+ app.selectSwarm(original);+ app.focusPane(first.id);+ await mountWide(tester, app);+ expect(app.preparePaneSplit(PaneResizeAxis.x), isNull);+ tester.view.physicalSize = const Size(3000, 1800);+ await tester.pump();+ final unchanged = [second, third];+ final rects = [+ for (final pane in unchanged) tester.getRect(find.byKey(pane.cellKey)),+ ];+ final retained = [+ for (final pane in [first, second, third])+ tester.element(+ find.descendant(+ of: find.byKey(pane.cellKey),+ matching: find.byType(TerminalView),+ ),+ ),+ ];+ final before = app.activeSwarm.arranged!;+ final split = app.preparePaneSplit(PaneResizeAxis.x)!;+ expect(app.machineStates['m']!.terminalCapabilityAvailable, isFalse);+ await app.assignAgentToPane(+ null,+ 'm',+ 'a3',+ swarmId: original,+ split: split,+ );+ await tester.pump();+ expect(app.panes, [first, shared, second, third]);+ expect(find.byKey(shared.cellKey), findsOneWidget);+ expect(tester.getRect(find.byKey(shared.cellKey)).width, greaterThan(0));+ expect(app.pinnedSlotFor(second), 2);+ for (var i = 0; i < unchanged.length; i++) {+ expect(tester.getRect(find.byKey(unchanged[i].cellKey)), rects[i]);+ }+ for (var i = 0; i < retained.length; i++) {+ expect(+ tester.element(+ find.descendant(+ of: find.byKey([first, second, third][i].cellKey),+ matching: find.byType(TerminalView),+ ),+ ),+ same(retained[i]),+ );+ }+ expect(app.activeSwarm.manualLayout!.tiles, split.after.tiles);+ await app.flushPaneLayout();+ final restored = createApp(store: store);+ await restored.restorePaneLayoutForTest();+ expect(restored.activeSwarm.manualLayout!.tiles, split.after.tiles);+ restored.dispose();+ await app.closePane(shared.id);+ await tester.pump();+ expect(app.activeSwarm.manualLayout!.tiles, before.tiles);+ expect(app.pinnedSlotFor(second), 1);+ expect(app.reopenClosed(), isTrue);+ await tester.pump();+ expect(app.activeSwarm.manualLayout!.tiles, split.after.tiles);+ expect(app.panes[1], same(shared));+ expect(app.pinnedSlotFor(second), 2);+ await app.closePane(shared.id);+ await tester.pump();+ final current = app.activeSwarm.manualLayout!;+ final resized = current.resize(+ current.dividers.firstWhere((d) => d.axis == PaneResizeAxis.x),+ .6,+ minimum: app.activeSwarm.arrangedMinimum!,+ );+ app.resizePanes(original, '3:manual', resized);+ await tester.pump();+ expect(app.reopenClosed(), isTrue);+ await tester.pump();+ expect(+ app.activeSwarm.manualLayout,+ isNull,+ reason: 'Reopening must not resurrect the old layout over newer sizing choices',+ );+ expect(app.activeSwarm.paneSizes['3:manual']!.tiles, resized.tiles);+ app.setPreset(4, PanePreset.quad);+ await tester.pump();+ expect(app.activeSwarm.manualLayout, isNull);+ expect(frames, isEmpty);+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );++ for (final change in ['switch', 'layout', 'close', 'window']) {+ testWidgets(+ 'a pending split respects its original destination after $change',+ (tester) async {+ final connection = _Creation();+ final app = createApp(connectionForTest: (_) => connection);+ app.adoptSessionForTest(terminal('a0', []));+ app.adoptSessionForTest(terminal('a1', []));+ await mountWide(tester, app);+ tester.view.physicalSize = const Size(3000, 1800);+ await tester.pump();+ final original = app.activeSwarm;+ final split = app.preparePaneSplit(PaneResizeAxis.x)!;+ final creating = app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/work',+ split: split,+ );+ expect(connection.calls, ['agent_create']);+ if (change == 'layout') app.setPreset(2, PanePreset.rows);+ if (change == 'window') {+ tester.view.physicalSize = const Size(1000, 800);+ await tester.pump();+ }+ app.newSwarm();+ if (change == 'close') await app.closeSwarm(original.id);+ connection.complete();+ expect(await creating, isNull);+ await tester.pump();+ expect(app.panes, isEmpty);+ expect(+ original.panes.map((p) => p.agentId),+ change == 'switch' ? ['a0', 'a1', 'created'] : ['a0', 'a1'],+ );+ expect(original.manualLayout != null, change == 'switch');+ expect(+ app.machineStates['m']!.agents.any((a) => a.id == 'created'),+ isTrue,+ );+ if (change != 'switch') {+ expect(app.lastError, contains('agent was created'));+ }+ expect(connection.calls, isNot(contains('agent_delete')));+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ );+ }++ testWidgets(+ 'split command inherits folder and machine, and cancel keeps the workspace',+ (tester) async {+ final connection = _Creation();+ final app = createApp(connectionForTest: (_) => connection);+ final machine = app.machineStates['m']!;+ machine.nodeOnline = true;+ machine.agents[0] = const Agent(+ id: 'a0',+ name: 'Checkout',+ engine: 'claude',+ project: AgentProject(name: 'work', cwd: '/work/checkout'),+ );+ final frames = <TerminalBinaryFrame>[];+ final pane = app.adoptSessionForTest(terminal('a0', frames));+ await mountWide(tester, app);+ tester.view.physicalSize = const Size(3000, 1800);+ await tester.pump();+ await chord(tester, LogicalKeyboardKey.keyP);+ await tester.enterText(+ find.byKey(const ValueKey('swarm-search-input')),+ '> split right',+ );+ await tester.pump();+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);+ await tester.pump();+ expect(find.text('New agent to the right'), findsOneWidget);+ expect(find.text('/work/checkout'), findsOneWidget);+ expect(app.panes, [pane]);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pump();+ expect(find.byType(AlertDialog), findsNothing);+ expect(app.panes, [pane]);+ expect(connection.calls, isNot(contains('agent_create')));+ expect(frames, isEmpty);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);+ await tester.pump(const Duration(milliseconds: 10));+ expect(frames.single.bytes, [27, 91, 67]);+ 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 5bf673e22..ea22adf06 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. |-| 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. |+| Resizing, splits and commands implemented; preview next | `>` commands work in both search fields. Controlled resizing uses the existing gaps, saves proportions, protects usable sizes and retains terminal elements. Explicit right/down splits use the normal New agent form and preserve the surrounding rectangles. Cmd-S returns to a preset. Optional cached search preview and match highlighting remain next. The [progress log](harness-v2-progress.md) records validation and the close-layout fallback. [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 7771a15d7..bb16f287d 100644--- a/docs/harness-v2-progress.md+++ b/docs/harness-v2-progress.md@@ -2,7 +2,17 @@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: controlled resizing+## Active follow-up: deliberate splits++- `> Split right` and `> Split down` open New agent with the focused agent's machine and known folder preselected. Creation remains explicit. The new agent takes half that agent's rectangle; neighboring agents retain their rectangles, terminal elements and pins. These commands are available only when both resulting agents meet the measured minimum size. No existing key was reassigned.+- The captured split is checked before creation and again after its asynchronous reply. It remains tied to the original Swarm and pane order, even after tab navigation. If the original layout closes, changes or becomes too small while creation is in flight, the agent remains in Search and an honest notice explains why it was not inserted; no second creation or destructive cleanup occurs.+- Manual shapes persist through offline restoration and closed-Swarm recovery. Closing an agent expands a complete neighboring edge into its space. If interlocking cuts prevent that local repair, that pane count returns to its selected preset. Reopening restores the original manual shape only if the intervening membership and sizing still match; newer sizing is retained. Cmd-S resets to the chosen preset.+- Visual review exposed an existing assignment edge case: a machine without a terminal-capability report could receive new membership without notifying the screen. That path now publishes its change immediately; the new split renders with retained output or the existing unavailable state.+- Validation: **1,138 Flutter tests passed, one existing skip** in the final full run after the notification correction (`/private/tmp/harness-v2-split-full-tests.log`). Focused split checks and the isolated render also passed. Analyzer has no errors/warnings and 12 existing vendored infos. Other artifacts: `/private/tmp/harness-v2-split-{tests,final-checks,analyze,render,build}.log` and `/private/tmp/harness-v2-split-{placed,form}.png`. The rendered form and actual five-agent split were reviewed with system fonts; this remains isolated UI evidence.+- The Release build succeeded and was relaunched. The verified preview PID 820 was normally quit and confirmed exited before rebuilding. Re-observe the relaunched preview before later native interaction. No real agent received test input.+- Next: optional bounded search preview, file-remapping ownership across AppKit and Flutter, and a small onboarding copy pass. The New agent form's unavailable-engine explanation is too wordy; shorten it while preserving the distinction between unavailable checks and a known missing engine.++## Controlled resizing checkpoint- 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.