Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(desktop): use consistent defaults for three to five panes (#196)

Dee8ff7abf58028
diff --git a/.github/assets/pane-defaults/3-panes.png b/.github/assets/pane-defaults/3-panes.png
new file mode 100644
index 000000000..fc52a5fef
Binary files /dev/null and b/.github/assets/pane-defaults/3-panes.png differ
diff --git a/.github/assets/pane-defaults/4-panes.png b/.github/assets/pane-defaults/4-panes.png
new file mode 100644
index 000000000..241d2f059
Binary files /dev/null and b/.github/assets/pane-defaults/4-panes.png differ
diff --git a/.github/assets/pane-defaults/5-panes.png b/.github/assets/pane-defaults/5-panes.png
new file mode 100644
index 000000000..a5b9f5d14
Binary files /dev/null and b/.github/assets/pane-defaults/5-panes.png differ
diff --git a/desktop/lib/state/pane_preset.dart b/desktop/lib/state/pane_preset.dart
index 668a4c0cf..b9b8a41c3 100644
--- a/desktop/lib/state/pane_preset.dart
+++ b/desktop/lib/state/pane_preset.dart
@@ -16,7 +16,7 @@ enum PanePreset {
/// Two tiles, one above the other.
rows,
- /// Three tiles: two over one, the bottom one spanning. The shipped shape.
+ /// Three tiles: two over one, the bottom one spanning.
twoOverOne,
/// Three tiles: one over two, the top one spanning.
@@ -26,7 +26,7 @@ enum PanePreset {
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.
+ /// measured default for six or more tiles.
auto,
/// A stated column count, for any number of tiles. The rows fall out of it:
@@ -293,11 +293,11 @@ enum PanePreset {
< 2 => const [],
2 => const [PanePreset.columns, PanePreset.rows],
3 => const [
+ PanePreset.cols3,
PanePreset.twoOverOne,
PanePreset.oneOverTwo,
PanePreset.mainLeft,
PanePreset.mainRight,
- PanePreset.cols3,
PanePreset.rows,
],
4 => const [
@@ -308,9 +308,9 @@ enum PanePreset {
PanePreset.rows,
],
5 => const [
+ PanePreset.middleMain,
PanePreset.balanced3,
PanePreset.twoOverThree,
- PanePreset.middleMain,
PanePreset.mainAndGrid,
PanePreset.mainOverGrid,
PanePreset.cols5,
@@ -375,8 +375,9 @@ enum PanePreset {
return switch (count) {
< 2 => null,
2 => PanePreset.splitLong,
- 3 => PanePreset.twoOverOne,
+ 3 => PanePreset.cols3,
4 => PanePreset.quad,
+ 5 => PanePreset.middleMain,
_ => PanePreset.auto,
};
}
diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dart
index 2e4494db7..ea61bce4b 100644
--- a/desktop/lib/widgets/pane_grid.dart
+++ b/desktop/lib/widgets/pane_grid.dart
@@ -96,9 +96,6 @@ class PaneGrid extends StatelessWidget {
);
}
- /// Row-major, and the odd count spans rather than leaving a hole: three tiles
- /// are two over one, not two over one-and-a-gap.
- ///
/// Keyed on the number of CELLS, not of panes: mid-drag an extra drop slot
/// joins them, and the grid on screen is the one the shape has to describe.
Widget _arrange(List<Widget> cells) {
@@ -110,10 +107,8 @@ class PaneGrid extends StatelessWidget {
return _PresetCells(cells: cells, preset: preset);
}
- // Above four, one family of shapes: a grid whose COLUMN COUNT is either
- // stated by the preset or measured from the width. The hand-tuned shapes
- // below stay as they are — three tiles are two over one with the bottom one
- // SPANNING, and no uniform grid can say that.
+ // Lattices use a stated or measured column count. Spanning presets keep
+ // their own geometry, including the default five-pane middle column.
if (cells.length == 5 && preset == PanePreset.middleMain) {
// The one five-tile shape that is not a lattice: a full-height column down
// the middle, two stacked either side. Read in TILE order — 1 and 4 to the
diff --git a/desktop/test/pane_defaults_test.dart b/desktop/test/pane_defaults_test.dart
new file mode 100644
index 000000000..fc28ab3e9
--- /dev/null
+++ b/desktop/test/pane_defaults_test.dart
@@ -0,0 +1,126 @@
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/terminal/terminal_binary.dart';
+import 'package:harness/widgets/pane_grid.dart';
+import 'package:xterm/xterm.dart';
+
+import 'support/real_fonts.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;
+
+void main() {
+ testWidgets(
+ 'New Pane reflows 2 to 3 to 4 to 5 panes, retaining terminals and focus',
+ (tester) async {
+ final captures =
+ Platform.environment['HARNESS_PANE_DEFAULTS_CAPTURE_DIR'];
+ if (captures != null) await tester.runAsync(loadRealFonts);
+ final store = MemoryStore();
+ final app = createApp(store: store);
+ app.machineStates['m']!.nodeOnline = true;
+ final frames = <TerminalBinaryFrame>[];
+ final tab = app.activeSwarm;
+ final first = app.adoptSessionForTest(terminal('a0', frames));
+ app.adoptSessionForTest(terminal('a1', frames));
+ app.newSwarm(name: 'Available harnesses');
+ final available = [
+ for (var i = 2; i < 5; i++)
+ app.adoptSessionForTest(terminal('a$i', frames)),
+ ];
+ app.selectSwarm(tab.id);
+ await mountWide(tester, app);
+ final firstView = find.descendant(
+ of: find.byKey(first.cellKey),
+ matching: find.byType(TerminalView),
+ );
+ final retained = tester.element(firstView);
+ const expected = {
+ 3: [
+ Rect.fromLTRB(0, 0, 1 / 3, 1),
+ Rect.fromLTRB(1 / 3, 0, 2 / 3, 1),
+ Rect.fromLTRB(2 / 3, 0, 1, 1),
+ ],
+ 4: [
+ Rect.fromLTRB(0, 0, .5, .5),
+ Rect.fromLTRB(.5, 0, 1, .5),
+ Rect.fromLTRB(0, .5, .5, 1),
+ Rect.fromLTRB(.5, .5, 1, 1),
+ ],
+ 5: [
+ Rect.fromLTRB(0, 0, 1 / 3, .5),
+ Rect.fromLTRB(1 / 3, 0, 2 / 3, 1),
+ Rect.fromLTRB(2 / 3, 0, 1, .5),
+ Rect.fromLTRB(0, .5, 1 / 3, 1),
+ Rect.fromLTRB(2 / 3, .5, 1, 1),
+ ],
+ };
+
+ void checkShape(int count) {
+ final grid = tester.getRect(find.byType(PaneGrid));
+ for (var i = 0; i < count; i++) {
+ final rect = tester.getRect(find.byKey(app.panes[i].cellKey));
+ final want = expected[count]![i];
+ expect((rect.left - grid.left) / grid.width, closeTo(want.left, .02));
+ expect((rect.top - grid.top) / grid.height, closeTo(want.top, .02));
+ expect(
+ (rect.right - grid.left) / grid.width,
+ closeTo(want.right, .02),
+ );
+ expect(
+ (rect.bottom - grid.top) / grid.height,
+ closeTo(want.bottom, .02),
+ );
+ }
+ }
+
+ for (var count = 3; count <= 5; count++) {
+ await chord(tester, LogicalKeyboardKey.keyP);
+ await tester.enterText(
+ find.byKey(const ValueKey('swarm-search-input')),
+ 'Agent ${count - 1}',
+ );
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump(const Duration(milliseconds: 150));
+ expect(app.activeSwarm, same(tab));
+ expect(app.panes, hasLength(count));
+ expect(app.panes.last, same(available[count - 3]));
+ expect(app.focusedPaneId, app.panes.last.id);
+ expect(tester.element(firstView), same(retained));
+ checkShape(count);
+ expect(tester.takeException(), isNull);
+ if (captures != null) {
+ await expectLater(
+ find.byType(MaterialApp),
+ matchesGoldenFile(Uri.file('$captures/$count-panes.png')),
+ );
+ }
+ frames.clear();
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
+ await tester.pump(const Duration(milliseconds: 10));
+ expect(frames.single.streamId, app.panes.last.session!.streamId);
+ }
+
+ // Closing panes returns to the matching default at each smaller count.
+ for (final count in [4, 3]) {
+ await app.closePane(app.panes.last.id);
+ await tester.pump(const Duration(milliseconds: 150));
+ checkShape(count);
+ expect(tester.element(firstView), same(retained));
+ }
+ await app.flushPaneLayout();
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ final restored = createApp(store: store);
+ await restored.restorePaneLayoutForTest();
+ expect(restored.panes.map((pane) => pane.agentId), ['a0', 'a1', 'a2']);
+ expect(restored.presetFor(3)!.tilesFor(3), expected[3]);
+ restored.dispose();
+ },
+ );
+}
diff --git a/desktop/test/pane_lattice_test.dart b/desktop/test/pane_lattice_test.dart
index 8af67a978..6bbc7ba06 100644
--- a/desktop/test/pane_lattice_test.dart
+++ b/desktop/test/pane_lattice_test.dart
@@ -1,4 +1,4 @@
-// Five tiles and up: the grid.
+// Six tiles and up: the automatic grid.
//
// The shape is not ceil(sqrt(n)) — it is "as many columns as the WIDTH can
// carry at 40 usable terminal columns", because a tile narrower than that shows
@@ -79,8 +79,7 @@ void main() {
});
testWidgets('four tiles keep the shape they were tuned to', (tester) async {
- // 2×2, not a lattice. Three tiles are two over one with the bottom SPANNING,
- // and no uniform grid can say that — so the hand-tuned shapes stay.
+ // Four panes keep equal quadrants as the defaults on either side change.
await _pump(tester, 4, const Size(1750, 900));
expect(tester.takeException(), isNull);
expect(hasScrollableContent(tester), isFalse);
diff --git a/desktop/test/pane_preset_test.dart b/desktop/test/pane_preset_test.dart
index df9b04617..f8ba084cc 100644
--- a/desktop/test/pane_preset_test.dart
+++ b/desktop/test/pane_preset_test.dart
@@ -161,7 +161,6 @@ void main() {
// down the left, 2 in the middle, 3 and 5 down the right — so a person
// reading across the top gets 1, 2, 3.
final notifier = _withPanes(5);
- notifier.setPreset(5, PanePreset.middleMain);
final shape = await _layout(tester, notifier);
expect(shape[0].right, closeTo(1 / 3, 0.02), reason: 'tile 1: left column');
@@ -187,7 +186,7 @@ void main() {
});
test('a big grid offers concrete balanced arrangements', () {
- expect(PanePreset.forCount(5).first, PanePreset.balanced3);
+ expect(PanePreset.forCount(5).first, PanePreset.middleMain);
for (var count = 5; count <= 9; count++) {
for (final preset in PanePreset.forCount(count)) {
final columns = preset.statedColumns;
diff --git a/desktop/test/swarm_split_test.dart b/desktop/test/swarm_split_test.dart
index 17d29e259..e5d8da226 100644
--- a/desktop/test/swarm_split_test.dart
+++ b/desktop/test/swarm_split_test.dart
@@ -474,7 +474,9 @@ void main() {
app.focusPane(first.id);
await mountWide(tester, app);
expect(app.preparePaneSplit(PaneResizeAxis.x), isNotNull);
- tester.view.physicalSize = const Size(3000, 1800);
+ // Halving one of three columns needs room for six minimum-width panes.
+ // This case checks fixed neighbors; the cases above cover scroll growth.
+ tester.view.physicalSize = const Size(4000, 1800);
await tester.pump();
final unchanged = [second, third];
final rects = [