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
refactor(mobile): drop pane presets, arrangements and splits
dee1a4e6b51c7a3
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 1edc2e82b..daf5e2db0 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -58,8 +58,6 @@ import '../update/manual_update_check.dart';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 'search_when.dart';import 'session_content_search.dart';@@ -107,7 +105,6 @@ class AgentCreationAttempt {final String _id;String? _machineId, _targetId;Map<String, dynamic>? _choices;- PaneSplitRequest? _split;Future<String?>? _inFlight;bool _awaitingConfirmation = false, _finished = false;String? _outcome;@@ -647,8 +644,7 @@ class AppNotifier extends ChangeNotifier {// restored from builds that did not mark them as drafts.if (entry is ClosedSwarm &&entry.name == Swarm.defaultName &&- entry.panes.isEmpty &&- entry.presets.isEmpty) {+ entry.panes.isEmpty) {return;}_closedHistory.add(entry);@@ -674,8 +670,7 @@ class AppNotifier extends ChangeNotifier {final swarm = swarms.where((swarm) => swarm.id == id).firstOrNull;return swarm != null &&swarm.panes.isEmpty &&- swarm.name == Swarm.defaultName &&- swarm.presets.isEmpty;+ swarm.name == Swarm.defaultName;}void newSwarm({String name = Swarm.defaultName, bool draft = false}) {@@ -737,7 +732,6 @@ class AppNotifier extends ChangeNotifier {target == null ||target.panes.isNotEmpty ||target.name != Swarm.defaultName ||- target.presets.isNotEmpty ||swarms.length == 1) {return false;}@@ -834,8 +828,7 @@ class AppNotifier extends ChangeNotifier {// welcome tabs, evicting the real work from recently closed history.if (swarms.length == 1 &&swarms.single.panes.isEmpty &&- swarms.single.name == Swarm.defaultName &&- swarms.single.presets.isEmpty) {+ swarms.single.name == Swarm.defaultName) {return;}final removed = swarms.removeAt(index);@@ -902,7 +895,6 @@ class AppNotifier extends ChangeNotifier {final present = {for (final pane in target.panes) (pane.machineId, pane.agentId),};- final previousCount = target.panes.length;for (final entry in saved.panes) {if (!present.add((entry.machineId, entry.agentId))) continue;target.panes.add(@@ -916,22 +908,12 @@ class AppNotifier extends ChangeNotifier {),);}- if (target.panes.length != previousCount) {- // An old manual shape for this count describes different membership.- // Keep current presets/pins and use the normal layout for added views.- target.paneSizes.remove('${target.panes.length}:manual');- target.arranged = null;- target.arrangedKey = null;- }target.focusedPaneId ??= target.panes.firstOrNull?.id;_paneFocusRequest++;selectSwarm(target.id);return;}- final restored = Swarm(id: saved.id, name: saved.name)- ..gridColumns = saved.gridColumns- ..presets.addAll(saved.presets)- ..paneSizes.addAll(saved.paneSizes);+ final restored = Swarm(id: saved.id, name: saved.name);for (final entry in saved.panes) {final pane = pool.putIfAbsent((entry.machineId, entry.agentId),@@ -989,31 +971,7 @@ class AppNotifier extends ChangeNotifier {agentId: agent.agentId,);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!;@@ -1079,119 +1037,6 @@ class AppNotifier extends ChangeNotifier {/// Explicit navigation must reveal and refocus even an already-selected pane.int get paneFocusRequest => _paneFocusRequest;- /// An explicit relayout reveals live output even in tiles whose rectangle- /// does not change. This is view intent, so it is never persisted.- int _paneLayoutRequest = 0;- int get paneLayoutRequest => _paneLayoutRequest;-- /// The chosen shape for a grid of this size, or the shipped one.- Map<int, PanePreset> get panePresets => activeSwarm.presets;-- PanePreset? presetFor(int paneCount) =>- panePresets[paneCount] ?? PanePreset.defaultFor(paneCount);-- /// 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 (!preset.supportsCount(paneCount)) return;- final resized = activeSwarm.paneSizes.keys.any(- (key) => key.startsWith('$paneCount:'),- );- _paneLayoutRequest++;- if (presetFor(paneCount) == preset && !resized) {- notifyListeners();- 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();- }-- PaneSplitRequest? preparePaneSplit(PaneResizeAxis axis, {int? paneId}) {- if (zoomedPaneId != null || panes.length >= maxPanes) return null;- final targetId = paneId ?? focusedPaneId;- final before = activeSwarm.arranged;- final minimum = activeSwarm.arrangedMinimum;- final index = panes.indexWhere(- (p) => p.id == targetId && 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 || targetId == null) return null;- return PaneSplitRequest(- swarmId: activeSwarmId,- paneId: targetId,- 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(- 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.savePaneSizes(layoutKey, arrangement);- activeSwarm.arranged = arrangement;- _paneLayoutRequest++;- notifyListeners();- if (persist) _persistLayout();- return true;- }-- void resetPaneSizes() {- setPreset(panes.length, presetFor(panes.length) ?? PanePreset.auto);- }-int _nextPaneId = 1;static const maxPanes = 64;@@ -4736,7 +4581,6 @@ class AppNotifier extends ChangeNotifier {String? permissionMode,String? codexHome,String? swarmId,- PaneSplitRequest? split,AgentCreationAttempt? attempt,String? prompt,}) {@@ -4761,13 +4605,7 @@ class AppNotifier extends ChangeNotifier {: permissionModeApproves(permissionMode),'codexHome': ?codexHome,};- return _create(- machineId,- choices,- swarmId: swarmId,- split: split,- attempt: creation,- );+ return _create(machineId, choices, swarmId: swarmId, attempt: creation);}/// A Claude Code or Codex conversation Harness did not start, opened as a harness that resumes@@ -4794,7 +4632,6 @@ class AppNotifier extends ChangeNotifier {String machineId,Map<String, dynamic> choices, {String? swarmId,- PaneSplitRequest? split,AgentCreationAttempt? attempt,}) {final creation = attempt ?? AgentCreationAttempt();@@ -4810,18 +4647,14 @@ class AppNotifier extends ChangeNotifier {if (creation._choices == null) {creation._choices = choices;creation._machineId = machineId;- creation._targetId = split?.swarmId ?? swarmId ?? activeSwarmId;- creation._split = split;+ creation._targetId = swarmId ?? activeSwarmId;}final work = _createAgentWithReceipt(creation);creation._inFlight = work;return work.whenComplete(() => creation._inFlight = null);}- String? _creationPlacementError(String targetId, PaneSplitRequest? split) {- if (split != null && !isPaneSplitCurrent(split)) {- return 'The layout changed. Close this dialog and split the pane again.';- }+ String? _creationPlacementError(String targetId) {final target = swarms.where((s) => s.id == targetId).firstOrNull;if (target == null) return 'This tab was closed';if (target.panes.length >= maxPanes) {@@ -4863,7 +4696,6 @@ class AppNotifier extends ChangeNotifier {Future<String?> _createAgentWithReceipt(AgentCreationAttempt creation) async {final machineId = creation._machineId!;final targetId = creation._targetId!;- final split = creation._split;final choices = creation._choices!;final machine = machineStates[machineId];if (machine == null) return 'Machine not found';@@ -4871,7 +4703,7 @@ class AppNotifier extends ChangeNotifier {// A status check must remain possible even if the destination closed or a// capability probe changed while the first create was already in flight.if (!creation.awaitingConfirmation) {- final placementError = _creationPlacementError(targetId, split);+ final placementError = _creationPlacementError(targetId);if (placementError != null) return placementError;if (choices['codexHome'] != null) {if (choices['engine'] != 'codex') {@@ -5017,7 +4849,7 @@ class AppNotifier extends ChangeNotifier {// Apply each creation receipt once, even if its transport result is replayed.stats.onAgentSpawned();notifyListeners();- if (_creationPlacementError(targetId, split) != null) {+ if (_creationPlacementError(targetId) != null) {_lastError ='The harness was created, but its original tab or layout changed. ''Use Open Harness to find it.';@@ -5032,13 +4864,7 @@ class AppNotifier extends ChangeNotifier {machineId: machineId,agentId: agent.id,), name: agent.displayName);- await assignAgentToPane(- null,- machineId,- agent.id,- swarmId: targetId,- split: split,- );+ await assignAgentToPane(null, machineId, agent.id, swarmId: targetId);return null;}@@ -5918,19 +5744,12 @@ class AppNotifier extends ChangeNotifier {String machineId,String agentId, {String? swarmId,- PaneSplitRequest? split,bool takeControl = false,}) 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;@@ -5969,9 +5788,7 @@ class AppNotifier extends ChangeNotifier {return;}final insertion = replaced == null- ? split == null- ? targetPanes.length- : split.paneIds.indexOf(split.paneId) + 1+ ? targetPanes.length: targetPanes.indexOf(replaced);if (existing != null) target.remove(existing);if (replaced != null) target.remove(replaced);@@ -5980,15 +5797,6 @@ class AppNotifier extends ChangeNotifier {TerminalPane(id: _nextPaneId++, machineId: machineId, agentId: agentId);final firstAgent = targetPanes.every((pane) => pane.agentId == null);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 (firstAgent && target.name == Swarm.defaultName) {final name = agent.name.trim();if (name.isNotEmpty) {@@ -6198,131 +6006,8 @@ class AppNotifier extends ChangeNotifier {notifyListeners();}- /// How many columns the grid last laid out.- ///- /// Only `auto` needs telling: it measures the window, so it is the one shape- /// whose columns are not in its own description. Reported by the grid as it- /// builds; null until then, and then the shape's own guess stands.- int? get gridColumns => activeSwarm.gridColumns;- set gridColumns(int? value) => activeSwarm.gridColumns = value;-bool hasNavigationRail = true;- /// Focus the tile above or below the focused one — ⌘↑ / ⌘↓.- ///- /// SPATIAL, unlike the left/right pair, which walks the tiles in order. Down- /// from the top-left of a 2×2 is the tile under it, not the next one along,- /// because that is what the arrow is pointing at. The shapes are read from- /// [PanePreset.tilesFor] — the same rectangles the layout is built from and- /// the picker draws — so this cannot describe a grid the app does not build.- ///- /// Nothing above or below (a single row, or the edge) leaves the focus where- /// it is: an arrow that wraps to the far side of the screen reads as a jump,- /// not as a step.- void focusPaneVertically(int delta) {- final to = _neighbour(dx: 0, dy: delta) ?? _wrapVertically(delta);- if (to != null) focusPane(panes[to].id);- }-- /// The tile at the far end of this column — ⌘j off the bottom row, ⌘k off the- /// top.- ///- /// IN COLUMN, not in list order. Wrapping to `panes.first` from the bottom- /// right of a 2x2 would jump a column as well as a row, which reads as the key- /// having misfired rather than as having come round. This finds the tile that- /// still overlaps ours horizontally and sits furthest in the direction pressed- /// — the one directly above or below, as far as it goes.- int? _wrapVertically(int delta) {- final count = panes.length;- if (count < 2) return null;- 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;-- final from = shape[at];- int? best;- double bestEdge = 0;- for (var i = 0; i < count; i++) {- if (i == at) continue;- final to = shape[i];- if ((from.right < to.left + 0.001) || (to.right < from.left + 0.001)) {- continue;- }- // Going DOWN wraps to the topmost; going up, to the bottom-most.- final edge = delta > 0 ? -to.top : to.top;- if (best == null || edge > bestEdge) {- bestEdge = edge;- best = i;- }- }- return best;- }-- /// ⇧⌘h j k l — put this pane where its neighbour is, and that one here.- ///- /// A SWAP, not an insert. vim's `Ctrl-w H/J/K/L` — the capitals this mirrors —- /// moves a window to the far edge, which needs a tree of splits to mean- /// anything; this grid is a list of slots rendered into a shape, so the honest- /// equivalent is to trade places with whoever is in the direction pressed.- void movePaneDirection({required int dx, required int dy}) {- final id = focusedPaneId;- if (id == null) return;- final at = panes.indexWhere((pane) => pane.id == id);- final to = _neighbour(dx: dx, dy: dy);- if (at < 0 || to == null) return;- final moved = panes.removeAt(at);- panes.insert(to, moved);- _persistLayout();- notifyListeners();- }-- /// The index of the tile in the given direction, or null at the edge.- ///- /// Reads the laid-out RECTANGLES rather than the list, so "left" means left on- /// screen whatever order the panes happen to be in. The two rules that make it- /// honest: the neighbour has to actually be on that side (a tile whose edge is- /// level with ours is not beside us), and the two have to OVERLAP on the other- /// axis — otherwise the tile diagonally across counts as "down", which is how- /// a 2x2 ends up with a key that moves like a knight.- int? _neighbour({required int dx, required int dy}) {- final count = panes.length;- if (count < 2) return null;- 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;-- final from = shape[at];- int? best;- double bestGap = double.infinity;- for (var i = 0; i < count; i++) {- if (i == at) continue;- final to = shape[i];- final double gap;- final bool apart;- if (dy != 0) {- gap = dy > 0 ? to.top - from.top : from.top - to.top;- apart =- (from.right < to.left + 0.001) || (to.right < from.left + 0.001);- } else {- gap = dx > 0 ? to.left - from.left : from.left - to.left;- apart =- (from.bottom < to.top + 0.001) || (to.bottom < from.top + 0.001);- }- if (gap <= 0.001 || apart) continue;- if (gap < bestGap) {- bestGap = gap;- best = i;- }- }- return best;- }-/// ⌘; — the pane focused before this one.////// tmux spells it the same way, and the reason it earns a key is that two@@ -6516,8 +6201,7 @@ class AppNotifier extends ChangeNotifier {final swarm = swarms.where((swarm) => swarm.id == id).firstOrNull;return swarm == null ||swarm.panes.isNotEmpty ||- swarm.name != Swarm.defaultName ||- swarm.presets.isNotEmpty;+ swarm.name != Swarm.defaultName;});_layoutRevision++;_announceOpenPanesToDial();@@ -6599,25 +6283,11 @@ class AppNotifier extends ChangeNotifier {paneAt(raw['focus']) ?? swarm.panes.firstOrNull?.id;swarm.zoomedPaneId = paneAt(raw['zoom']);swarm.previousPaneId = paneAt(raw['previousFocus']);- if (raw['presets'] case final Map presets) {- for (final e in presets.entries) {- final count = int.tryParse(e.key.toString());- final preset = PanePreset.byId(e.value?.toString());- if (count != null &&- count >= 2 &&- count <= maxPanes &&- preset != null &&- preset.supportsCount(count)) {- swarm.presets[count] = preset;- }- }- }- swarm.paneSizes.addAll(PaneArrangement.readSaved(raw['paneSizes']));restored.add(swarm);}if (restored.isNotEmpty) {// Older builds saved multiple unused start pages. Retain the selected- // one when possible; custom names, presets and real work stay intact.+ // one when possible; custom names and real work stay intact.final starters = restored.where((swarm) => swarm.isEmptyStarter);final starter =starters@@ -6645,11 +6315,6 @@ class AppNotifier extends ChangeNotifier {return;}}- // Read before the guards below: the dividers are remembered even for a- // grid this run has not restored any agents into, so a window that opens- // empty and is then filled by hand still comes up the shape it was left.- final legacyPresets = await store.loadPresets();- if (_disposed || revision != _layoutRevision) return;if (allPanes.isNotEmpty ||swarms.length != 1 ||activeSwarm != initialSwarm) {@@ -6657,11 +6322,7 @@ class AppNotifier extends ChangeNotifier {}final entries = await store.load();if (_disposed || revision != _layoutRevision) return;- panePresets.addAll(legacyPresets);- if (entries.isEmpty) {- if (panePresets.isNotEmpty) notifyListeners();- return;- }+ if (entries.isEmpty) return;for (final entry in entries) {panes.add(TerminalPane(diff --git a/mobile/lib/state/pane_arrangement.dart b/mobile/lib/state/pane_arrangement.dartdeleted file mode 100644index ab9ca8c4f..000000000--- a/mobile/lib/state/pane_arrangement.dart+++ /dev/null@@ -1,342 +0,0 @@-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();-- 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})>[];- 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;- }-}--/// 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,- 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/mobile/lib/state/pane_layout_store.dart b/mobile/lib/state/pane_layout_store.dartindex d4ae5bcc7..a80e4dc31 100644--- a/mobile/lib/state/pane_layout_store.dart+++ b/mobile/lib/state/pane_layout_store.dart@@ -3,7 +3,6 @@ import 'dart:convert';import '../core/harness_file_store.dart';import '../core/local_key_value_store.dart';-import 'pane_preset.dart';import 'terminal_pane.dart';import 'swarm.dart';@@ -19,19 +18,6 @@ class PaneLayoutStore {static const _key = 'terminal_pane_layout';- /// Chosen shapes, by tile count. A SECOND key rather than a field on the- /// layout entries: the two answer different questions — which agents were- /// open, and what shape the grid was in — and the entry schema above already- /// refuses anything it does not recognise, so widening it would make an old- /// build drop a new build's whole layout rather than just the part it cannot- /// use.- ///- /// A third key, `terminal_pane_splits`, is written by older builds and no- /// longer read: dividers were draggable and their positions were remembered.- /// Nothing deletes it — a downgrade would want it back, and a few hundred- /// bytes of dead JSON costs less than a file this build has to migrate.- static const _presetsKey = 'terminal_pane_presets';-/// The ceiling on tiles, enforced on the way IN as well as out: a file written/// by a future build that allows more must not make this one try to open/// terminals it has nowhere to put.@@ -83,45 +69,6 @@ class PaneLayoutStore {}}- /// A failed write costs the layout at the next launch, which is a far smaller- /// wrong than an exception thrown out of a pane close.-- /// Chosen shapes, by tile count. An id this build does not know is dropped —- /// a shape it cannot draw is worse than the default it can.- Future<Map<int, PanePreset>> loadPresets() async {- try {- final raw = await _storage.read(_presetsKey);- if (raw == null || raw.isEmpty) return const {};- final decoded = jsonDecode(raw);- if (decoded is! Map) return const {};- final out = <int, PanePreset>{};- for (final entry in decoded.entries) {- final count = int.tryParse(entry.key.toString());- if (count == null || count < 2 || count > maxPanes) continue;- final preset = PanePreset.byId(entry.value?.toString());- if (preset == null) continue;- if (!preset.supportsCount(count)) continue;- out[count] = preset;- }- return out;- } catch (_) {- return const {};- }- }-- Future<void> savePresets(Map<int, PanePreset> presets) async {- try {- await _storage.write(- _presetsKey,- jsonEncode({- for (final entry in presets.entries) '${entry.key}': entry.value.id,- }),- );- } catch (_) {- // Kept in memory for this run; see above.- }- }-Future<Map<String, dynamic>?> loadSwarms() async {try {final value = await _storage.read('swarm_layout_v1');diff --git a/mobile/lib/state/pane_preset.dart b/mobile/lib/state/pane_preset.dartdeleted file mode 100644index 5eee2075a..000000000--- a/mobile/lib/state/pane_preset.dart+++ /dev/null@@ -1,316 +0,0 @@-import 'dart:ui' show Rect;--/// The named shapes a grid of tiles can take.-///-/// The picker offers concrete, distinct arrangements. Automatic and older-/// lattice presets still restore saved work, but are not duplicate cards in-/// the picker. New balanced grids fill every row and use all the canvas.-enum PanePreset {- /// Two tiles: split whichever side is longer. A terminal's usable size is its- /// column count first, so halving the short axis is what protects it.- splitLong,-- /// Two tiles, side by side whatever the window's shape.- columns,-- /// Two tiles, one above the other.- rows,-- /// Three tiles: two over one, the bottom one spanning. The shipped shape.- twoOverOne,-- /// Three tiles: one over two, the top one spanning.- oneOverTwo,-- /// Three tiles: one tall on the left, two stacked on the right.- mainLeft,-- /// As many columns as the window can carry at the 40-column floor. The- /// measured answer, and the one a grid gets when nobody has chosen.- auto,-- /// A stated column count, for any number of tiles. The rows fall out of it:- /// seven tiles in three columns is three rows, the last one short.- ///- /// Narrow counts are allowed to be narrow — three terminals across a 1600px- /// window with the rail open is close to the floor — because the floor itself- /// already refuses anything narrower than a terminal can use, and clamps.- cols2,- cols3,- cols4,- cols5,-- /// Five tiles: one tall down the MIDDLE, two stacked either side of it.- ///- /// The only five-tile shape that is not a lattice, and the reason to have it:- /// a lattice of five leaves the odd tile alone on a short row, while this- /// gives the work in hand a full-height column and keeps four others in- /// sight beside it.- middleMain,-- /// Four tiles in a square.- quad,-- /// Four tiles: one tall on the left, three stacked on the right.- mainAndStack,-- /// Three tiles: two on the left and one full-height on the right.- mainRight,-- /// Five tiles: two above three, with both rows filling the width.- twoOverThree,-- /// Row counts follow the requested maximum columns; panes are distributed- /// evenly between rows so there are no unused cells or sparse trailing rows.- balanced2,- balanced3,- balanced4,- balanced5,-- /// A full-height main pane beside a balanced grid of supporting panes.- mainAndGrid,-- /// A full-width main pane above a balanced grid of supporting panes.- mainOverGrid;-- /// What the picker prints.- String get label => switch (this) {- PanePreset.splitLong => 'Split',- PanePreset.columns => 'Columns',- PanePreset.rows => 'Rows',- PanePreset.twoOverOne => 'Main bottom',- PanePreset.oneOverTwo => 'Main top',- PanePreset.mainLeft => 'Main left',- PanePreset.quad => 'Grid',- PanePreset.mainAndStack => 'Main left',- PanePreset.auto => 'Auto',- PanePreset.cols2 => '2 columns',- PanePreset.cols3 => '3 columns',- PanePreset.cols4 => '4 columns',- PanePreset.cols5 => '5 columns',- PanePreset.middleMain => 'Middle + sides',- PanePreset.mainRight => 'Main right',- PanePreset.twoOverThree => 'Two over three',- PanePreset.balanced2 => '2 columns',- PanePreset.balanced3 => '3 columns',- PanePreset.balanced4 => '4 columns',- PanePreset.balanced5 => '5 columns',- PanePreset.mainAndGrid => 'Main left',- PanePreset.mainOverGrid => 'Main top',- };-- /// The column count this shape states, or null for [auto] and for the shapes- /// that are not a lattice at all.- int? get statedColumns => switch (this) {- PanePreset.cols2 => 2,- PanePreset.cols3 => 3,- PanePreset.cols4 => 4,- PanePreset.cols5 => 5,- _ => null,- };-- /// These shapes use their unit rectangles directly in both renderers.- bool get usesTileGeometry => switch (this) {- PanePreset.mainRight ||- PanePreset.twoOverThree ||- PanePreset.balanced2 ||- PanePreset.balanced3 ||- PanePreset.balanced4 ||- PanePreset.balanced5 ||- PanePreset.mainAndGrid ||- PanePreset.mainOverGrid => true,- _ => false,- };-- /// The tiles this shape makes, as fractions of the grid.- ///- /// This is the shape's DESCRIPTION, and it lives here rather than in the- /// picker that draws it so there is only one of it: the palette paints these- /// rectangles and a test measures the real layout against them, so a diagram- /// cannot drift into advertising a shape the grid does not build.- ///- /// Legacy automatic layouts accept their measured column count. They are- /// not offered in the picker because they resolve to another shape there.- List<Rect> tilesFor(int count, {int? columns}) => switch (this) {- PanePreset.columns || PanePreset.splitLong => const [- Rect.fromLTRB(0, 0, .5, 1),- Rect.fromLTRB(.5, 0, 1, 1),- ],- PanePreset.rows => _lattice(count, 1),- PanePreset.twoOverOne => const [- Rect.fromLTRB(0, 0, .5, .5),- Rect.fromLTRB(.5, 0, 1, .5),- Rect.fromLTRB(0, .5, 1, 1),- ],- PanePreset.oneOverTwo => const [- Rect.fromLTRB(0, 0, 1, .5),- Rect.fromLTRB(0, .5, .5, 1),- Rect.fromLTRB(.5, .5, 1, 1),- ],- PanePreset.mainLeft => const [- Rect.fromLTRB(0, 0, .5, 1),- Rect.fromLTRB(.5, 0, 1, .5),- Rect.fromLTRB(.5, .5, 1, 1),- ],- PanePreset.mainRight => const [- Rect.fromLTRB(0, 0, .5, .5),- Rect.fromLTRB(.5, 0, 1, 1),- Rect.fromLTRB(0, .5, .5, 1),- ],- PanePreset.quad => const [- Rect.fromLTRB(0, 0, .5, .5),- Rect.fromLTRB(.5, 0, 1, .5),- Rect.fromLTRB(0, .5, .5, 1),- Rect.fromLTRB(.5, .5, 1, 1),- ],- PanePreset.mainAndStack => const [- Rect.fromLTRB(0, 0, .5, 1),- Rect.fromLTRB(.5, 0, 1, 1 / 3),- Rect.fromLTRB(.5, 1 / 3, 1, 2 / 3),- Rect.fromLTRB(.5, 2 / 3, 1, 1),- ],- // Tile order reads across the top and then across the bottom: 1 and 4 on the- // left, 2 down the middle, 3 and 5 on the right — which is the order a- // person numbers them, not the order a column would fill.- PanePreset.middleMain => const [- Rect.fromLTRB(0, 0, 1 / 3, 1 / 2),- Rect.fromLTRB(1 / 3, 0, 2 / 3, 1),- Rect.fromLTRB(2 / 3, 0, 1, 1 / 2),- Rect.fromLTRB(0, 1 / 2, 1 / 3, 1),- Rect.fromLTRB(2 / 3, 1 / 2, 1, 1),- ],- PanePreset.twoOverThree => _balanced(count, 3, largerRowsLast: true),- PanePreset.balanced2 => _balanced(count, 2),- PanePreset.balanced3 => _balanced(count, 3),- PanePreset.balanced4 => _balanced(count, 4),- PanePreset.balanced5 => _balanced(count, 5),- PanePreset.mainAndGrid => [- const Rect.fromLTRB(0, 0, .5, 1),- for (final tile in _balanced(count - 1, 2))- Rect.fromLTRB(- .5 + tile.left / 2,- tile.top,- .5 + tile.right / 2,- tile.bottom,- ),- ],- PanePreset.mainOverGrid => [- const Rect.fromLTRB(0, 0, 1, .5),- for (final tile in _balanced(- count - 1,- count == 4 ? 3 : ((count - 1) / 2).ceil().clamp(2, 5),- ))- Rect.fromLTRB(- tile.left,- .5 + tile.top / 2,- tile.right,- .5 + tile.bottom / 2,- ),- ],- PanePreset.auto => _lattice(- count,- columns ?? _autoColumnsForDrawing(count),- ),- _ => _lattice(count, statedColumns!.clamp(1, count)),- };-- static List<Rect> _balanced(- int count,- int columns, {- bool largerRowsLast = false,- }) {- final rows = (count / columns.clamp(1, count)).ceil();- final perRow = count ~/ rows;- final extra = count % rows;- int columnsIn(int row) =>- perRow + ((largerRowsLast ? row >= rows - extra : row < extra) ? 1 : 0);- return [- for (var row = 0; row < rows; row++)- for (var col = 0; col < columnsIn(row); col++)- Rect.fromLTRB(- col / columnsIn(row),- row / rows,- (col + 1) / columnsIn(row),- (row + 1) / rows,- ),- ];- }-- /// The lattice, laid out the way `_Lattice` lays it: row-major, the last row- /// short when the count does not divide.- ///- /// Written twice would be the bug this whole file exists to prevent, so the- /// widget's own arithmetic is mirrored here and a test measures one against- /// the other.- static List<Rect> _lattice(int count, int columns) {- final cols = columns.clamp(1, count);- final rows = (count / cols).ceil();- return [- for (var i = 0; i < count; i++)- Rect.fromLTRB(- (i % cols) / cols,- (i ~/ cols) / rows,- (i % cols + 1) / cols,- (i ~/ cols + 1) / rows,- ),- ];- }-- /// Only for the DIAGRAM: what a wide window typically carries. The grid's own- /// answer is measured at build time and can differ — the point of the picture- /// is to say "the app decides", and it says that best by showing a plausible- /// grid rather than a special icon nobody can read.- static int _autoColumnsForDrawing(int count) => count <= 6 ? 3 : 4;-- /// Stable across releases: this is what lands in the state file, so it must- /// not be the enum's index — reordering the enum would silently repoint- /// everyone's saved layout at a different shape.- String get id => name;-- static PanePreset? byId(String? id) {- for (final preset in PanePreset.values) {- if (preset.id == id) return preset;- }- return _legacyIds[id];- }-- /// Saved automatic/regular grids remain valid even though the picker now- /// offers explicit, filled arrangements. Do not silently discard their IDs.- bool supportsCount(int count) => switch (this) {- PanePreset.splitLong || PanePreset.columns => count == 2,- PanePreset.rows => count >= 2 && count <= 4,- PanePreset.twoOverOne ||- PanePreset.oneOverTwo ||- PanePreset.mainLeft ||- PanePreset.mainRight => count == 3,- PanePreset.quad || PanePreset.mainAndStack => count == 4,- PanePreset.middleMain || PanePreset.twoOverThree => count == 5,- PanePreset.cols2 || PanePreset.auto => count >= 5,- PanePreset.cols3 => count >= 3,- PanePreset.cols4 => count >= 4,- PanePreset.cols5 ||- PanePreset.balanced2 ||- PanePreset.balanced3 ||- PanePreset.balanced4 ||- PanePreset.balanced5 ||- PanePreset.mainAndGrid => count >= 5,- PanePreset.mainOverGrid => count >= 4,- };-- /// What a grid of this size looks like when nobody has chosen.- static PanePreset? defaultFor(int count) {- return switch (count) {- < 2 => null,- 2 => PanePreset.splitLong,- 3 => PanePreset.twoOverOne,- 4 => PanePreset.quad,- _ => PanePreset.auto,- };- }-- /// Ids written by the build that named these two by hand, before the column- /// count became a thing any grid size could state. Read only — nothing writes- /// them any more — so a layout saved yesterday still opens the shape it was- /// left in rather than silently falling back to the default.- static const _legacyIds = {'threeColumns': cols3, 'fourColumns': cols4};-}diff --git a/mobile/lib/state/swarm.dart b/mobile/lib/state/swarm.dartindex 8baed7ae4..eb67ff759 100644--- a/mobile/lib/state/swarm.dart+++ b/mobile/lib/state/swarm.dart@@ -1,7 +1,3 @@-import 'dart:ui' show Size;--import 'pane_preset.dart';-import 'pane_arrangement.dart';import 'terminal_pane.dart';/// A named arrangement of agents. Membership never owns the agent process.@@ -33,47 +29,17 @@ class Swarm {final String id;String name;final List<TerminalPane> panes = [];- final Map<int, PanePreset> presets = {};- final Map<String, PaneArrangement> paneSizes = {};- PaneArrangement? arranged;- String? arrangedKey;- Size? arrangedMinimum;int? focusedPaneId;int? zoomedPaneId;int? previousPaneId;- int? gridColumns;final Map<int, int> pinnedSlots = {};- bool get isEmptyStarter =>- name == defaultName && panes.isEmpty && presets.isEmpty;-- 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);- }- }+ bool get isEmptyStarter => name == defaultName && panes.isEmpty;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@@ -97,11 +63,6 @@ class Swarm {'focus': agents.indexWhere((p) => p.id == focusedPaneId),'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(@@ -134,11 +95,6 @@ class ClosedAgent extends ClosedWork {machineId = pane.machineId,agentId = pane.agentId!,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;@@ -146,8 +102,6 @@ class ClosedAgent extends ClosedWork {final int index;final bool zoomed;final int? pinnedSlot;- final PaneArrangement? manualLayout;- final List<(String, String?)> remainingAgents;}/// Terminal buffers and controllers are released normally; a reopened view@@ -161,14 +115,11 @@ class ClosedSwarm extends ClosedWork {this.engine,}) : id = swarm.id,name = swarm.name,- gridColumns = swarm.gridColumns,focus = swarm.panes.indexWhere((p) => p.id == swarm.focusedPaneId),previousFocus = swarm.panes.indexWhere((p) => p.id == swarm.previousPaneId,),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)(@@ -183,18 +134,14 @@ class ClosedSwarm extends ClosedWork {final String name;final String? engine;final int index;- final int? gridColumns;final int focus;final int previousFocus;final int zoom;- final Map<int, PanePreset> presets;- final Map<String, PaneArrangement> paneSizes;final List<({String machineId, String? agentId, int? pinnedSlot})> panes;final String? replacementId;bool replacesUntouchedWelcome(Swarm swarm) =>swarm.id == replacementId &&swarm.name == Swarm.defaultName &&- swarm.panes.isEmpty &&- swarm.presets.isEmpty;+ swarm.panes.isEmpty;}