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
Keep terminal tails visible through incremental resize redraws
dee9288ea46c80f
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex b37dd3c32..eabf786bc 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -859,6 +859,11 @@ 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;@@ -872,7 +877,11 @@ class AppNotifier extends ChangeNotifier {final resized = activeSwarm.paneSizes.keys.any((key) => key.startsWith('$paneCount:'),);- if (presetFor(paneCount) == preset && !resized) return;+ _paneLayoutRequest++;+ if (presetFor(paneCount) == preset && !resized) {+ notifyListeners();+ return;+ }panePresets[paneCount] = preset;activeSwarm.paneSizes.removeWhere((key, _) => key.startsWith('$paneCount:'),@@ -953,6 +962,7 @@ class AppNotifier extends ChangeNotifier {}activeSwarm.savePaneSizes(layoutKey, arrangement);activeSwarm.arranged = arrangement;+ _paneLayoutRequest++;notifyListeners();if (persist) _persistLayout();return true;diff --git a/desktop/lib/widgets/layout_palette.dart b/desktop/lib/widgets/layout_palette.dartindex d3b9c5caf..722f17527 100644--- a/desktop/lib/widgets/layout_palette.dart+++ b/desktop/lib/widgets/layout_palette.dart@@ -4,10 +4,11 @@ import 'package:flutter/services.dart';import '../shared/theme/app_theme.dart' as grid;import '../shared/widgets/app_dialog.dart';import '../state/app_state.dart';+import '../shortcuts/app_keymap.dart';import '../state/pane_preset.dart';import '../theme/app_theme.dart';-/// ⌘L — pick the shape of the grid.+/// ⌘S — pick the shape of the grid.////// Shapes are DRAWN, not listed. "Two over one" and "one over two" are the same/// four words in a different order, and nobody reads a layout name twice; the@@ -17,15 +18,15 @@ import '../theme/app_theme.dart';/// above that the choice is the column count, with "Auto" — as many columns as/// the width carries at the forty-column floor — sitting among them as the/// measured answer rather than as the only one.-/// Set while the palette is up, so a second ⌘L can be answered rather than+/// Set while the palette is up, so a second ⌘S can be answered rather than/// stacking a route.////// It used to be a bool and a bare return. That stopped the palette fading the/// window to black under a held key — each press laid another dialog and another-/// 30% barrier over the last — but it left ⌘L meaning "open" once and nothing+/// 30% barrier over the last — but it left ⌘S meaning "open" once and nothing/// ever after, which is the one thing a person holding a key does not expect.///-/// THE SAME KEY WALKS THE STRIP. ⌘L opens it, ⌘L again steps to the next shape,+/// THE SAME KEY WALKS THE STRIP. ⌘S opens it, ⌘S again steps to the next shape,/// Enter takes it. That is how every cycling chord on this OS behaves, and it/// means the shape can be chosen without the hand leaving the chord it arrived/// on.@@ -103,7 +104,7 @@ class _LayoutPaletteState extends State<_LayoutPalette> {/// `autofocus: true` alone was not enough: it only takes the focus when the/// enclosing scope has none to give, and by the time this is laid out the/// route that opened it has already settled focus somewhere. The symptom was- /// precise — ⌘L opened the palette and cycled it, because that chord is a+ /// precise — ⌘S opened the palette and cycled it, because that chord is a/// global binding, while the arrow keys did nothing at all, because those are/// read HERE and nothing here was listening.final FocusNode _keys = FocusNode(debugLabel: 'layout-palette');@@ -116,7 +117,7 @@ class _LayoutPaletteState extends State<_LayoutPalette> {});// Registered here rather than by the opener, so the hook cannot outlive the// widget it steps: a stale callback would move a cursor on a palette that- // is no longer on screen, and the next ⌘L would find the strip already+ // is no longer on screen, and the next ⌘S would find the strip already// walked._layoutPaletteAdvance = _advance;}@@ -128,11 +129,11 @@ class _LayoutPaletteState extends State<_LayoutPalette> {super.dispose();}- /// One step along the strip — what a SECOND ⌘L does.+ /// One step along the strip — what a SECOND ⌘S does.////// Wraps, unlike the arrow keys, and the difference is deliberate. An arrow is/// a direction: running off the end of a strip you can see the ends of reads- /// as a mis-key. A repeated chord is a CYCLE — nobody holding ⌘L means "stop+ /// as a mis-key. A repeated chord is a CYCLE — nobody holding ⌘S means "stop/// at the last one", they mean "show me the next".bool _advance() {if (!mounted || ModalRoute.isCurrentOf(context) == false) return false;@@ -417,7 +418,10 @@ class _ShapeButton extends StatelessWidget {),const SizedBox(height: 2),Text(- '⌘L then $index',+ switch (effectiveCommandHint(context, 'pane.layout')) {+ final String hint => '$hint then $index',+ null => '$index',+ },style: TextStyle(fontFamily: grid.AppFont.mono,fontSize: 9.5,diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dartindex 584573a4e..0b5c7b35e 100644--- a/desktop/lib/widgets/pane_grid.dart+++ b/desktop/lib/widgets/pane_grid.dart@@ -344,6 +344,11 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {return (notifier: app,location: (app.activeSwarmId, app.panes.indexOf(pane)),+ layoutRequest: (+ app.paneLayoutRequest,+ app.panes.length,+ app.zoomedPaneId,+ ),machine: machine?.machine,local: machine?.isLocalMachine,online: machine?.nodeOnline,@@ -1186,6 +1191,11 @@ class _PaneContent extends StatelessWidget {session: session,viewportSize: constraints.biggest,paneLocation: (notifier.activeSwarmId, notifier.panes.indexOf(pane)),+ layoutRequest: (+ notifier.paneLayoutRequest,+ notifier.panes.length,+ notifier.zoomedPaneId,+ ),focused: visible && notifier.isPaneFocused(pane.id),focusRequest: notifier.isPaneFocused(pane.id)? notifier.paneFocusRequestdiff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dartindex 3b4db4bc5..2d059bab2 100644--- a/desktop/lib/widgets/terminal_panel.dart+++ b/desktop/lib/widgets/terminal_panel.dart@@ -60,6 +60,7 @@ class TerminalPanel extends StatefulWidget {/// A shared terminal can move to another harness without being remounted.final (String, int)? paneLocation;+ final (int, int, int?)? layoutRequest;final bool compactHeader;final int focusRequest;@@ -87,6 +88,7 @@ class TerminalPanel extends StatefulWidget {this.visible = true,this.viewportSize,this.paneLocation,+ this.layoutRequest,this.compactHeader = false,this.focusRequest = 0,this.composerVisible = false,@@ -254,7 +256,8 @@ class _TerminalPanelState extends State<TerminalPanel>(!oldWidget.visible || oldWidget.paneLocation != widget.paneLocation)) {_afterTerminalMounted();}- if (oldWidget.viewportSize != widget.viewportSize) {+ if (oldWidget.viewportSize != widget.viewportSize ||+ oldWidget.layoutRequest != widget.layoutRequest) {// Geometry can change while a resize handle or another control owns// the keyboard. Refresh the viewport without claiming input ownership._afterTerminalMounted(claimFocus: false);@@ -352,6 +355,7 @@ class _TerminalPanelState extends State<TerminalPanel>void _syncTerminal(Terminal terminal) {if (identical(_viewTerminal, terminal)) return;+final previous = _viewTerminal.buffer;final next = terminal.buffer;final render = _laidOutTerminalView()?.renderTerminal;@@ -578,6 +582,7 @@ class _TerminalPanelState extends State<TerminalPanel>// Request alignment before this frame's layout, so even a retained pane's// first visible paint uses its new size. Keep Find's explicit location.if (scrollToEnd && _find == null) {+ _cancelDialInertia();_followTail = true;_laidOutTerminalView()?.scrollToBottom();}diff --git a/desktop/test/terminal_tail_lifecycle_test.dart b/desktop/test/terminal_tail_lifecycle_test.dartindex b58fea2da..d085fb69a 100644--- a/desktop/test/terminal_tail_lifecycle_test.dart+++ b/desktop/test/terminal_tail_lifecycle_test.dart@@ -1,3 +1,4 @@+import 'dart:async';import 'dart:convert';import 'package:flutter/material.dart';@@ -46,6 +47,151 @@ void atBottom(WidgetTester tester, TerminalSession session) {}void main() {+ testWidgets(+ 'incremental resize repaint cannot start a scroll bounce',+ (tester) async {+ final app = createApp();+ final session = terminal('a0', []);+ await snapshot(session, 0, 900);+ app.adoptSessionForTest(session);+ await mount(tester, app);+ final view = terminalView(tester, session);+ // Codex clears history and redraws in separate output frames. There is no+ // further keyframe to cancel a bounce created by the temporary small buffer.+ session.terminal.write('\x1b[3J\x1b[H\x1b[2JRepainting');+ await tester.pump();+ for (var chunk = 0; chunk < 5; chunk++) {+ session.terminal.write(+ '\r\n${'Repainted history\r\n' * 200}LATEST OUTPUT',+ );+ await tester.pump(const Duration(milliseconds: 16));+ }+ await tester.pump(const Duration(seconds: 2));+ expect(+ view.widget.scrollController!.position.isScrollingNotifier.value,+ isFalse,+ );+ atBottom(tester, session);+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ variant: TargetPlatformVariant({+ TargetPlatform.macOS,+ TargetPlatform.linux,+ }),+ );++ testWidgets('relayout cancels scrolling that was already in flight', (+ tester,+ ) async {+ final app = createApp();+ final sessions = [terminal('a0', []), terminal('a1', [])];+ for (final session in sessions) {+ await snapshot(session, 0, 800);+ app.adoptSessionForTest(session);+ }+ await mount(tester, app);+ for (final session in sessions) {+ unawaited(+ terminalView(tester, session).widget.scrollController!.animateTo(+ 0,+ duration: const Duration(milliseconds: 600),+ curve: Curves.linear,+ ),+ );+ }+ await tester.pump(const Duration(milliseconds: 60));+ app.setPreset(2, PanePreset.rows);+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 100));+ for (final session in sessions) {+ await snapshot(session, 1, 1000);+ }+ await tester.pump();+ await tester.pump(const Duration(seconds: 1));+ for (final session in sessions) {+ atBottom(tester, session);+ }+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ });++ testWidgets('applying a layout resets panes whose size stays the same', (+ tester,+ ) async {+ final app = createApp();+ final sessions = [terminal('a0', []), terminal('a1', [])];+ for (final session in sessions) {+ await snapshot(session, 0, 800);+ app.adoptSessionForTest(session);+ }+ await mount(tester, app);+ app.setPreset(2, PanePreset.columns);+ await tester.pump();+ for (final session in sessions) {+ terminalView(tester, session).widget.scrollController!.jumpTo(100);+ }+ await tester.pump();+ app.setPreset(2, PanePreset.columns);+ await tester.pump();+ for (final session in sessions) {+ atBottom(tester, session);+ }+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ });++ testWidgets(+ 'resize redraws and delayed captures keep following live output',+ (tester) async {+ final app = createApp();+ final sessions = [terminal('a0', []), terminal('a1', [])];+ for (final session in sessions) {+ await snapshot(session, 0, 1000);+ app.adoptSessionForTest(session);+ }+ await mount(tester, app);+ var sequence = 1;+ for (final preset in [+ PanePreset.rows,+ PanePreset.columns,+ PanePreset.rows,+ ]) {+ await chord(tester, LogicalKeyboardKey.keyS);+ await tester.pump(const Duration(milliseconds: 200));+ await tester.tap(find.text(preset.label));+ await tester.pump();+ for (final session in sessions) {+ atBottom(tester, session);+ // Codex can clear its scrollback while repainting after SIGWINCH.+ // A delayed tmux capture then seeds the full history again.+ session.terminal.write('\x1b[3J\x1b[H\x1b[2JRepainting');+ }+ await tester.pump();+ for (final session in sessions) {+ await snapshot(session, sequence, 400);+ }+ sequence++;+ await tester.pump(const Duration(milliseconds: 100));+ for (final session in sessions) {+ atBottom(tester, session);+ await snapshot(session, sequence, 1200);+ }+ sequence++;+ await tester.pump();+ for (final session in sessions) {+ atBottom(tester, session);+ }+ }+ await tester.pumpWidget(const SizedBox());+ app.dispose();+ },+ variant: TargetPlatformVariant({+ TargetPlatform.macOS,+ TargetPlatform.linux,+ }),+ );+testWidgets('returning to live output before a layout follows the new extent',(tester) async {@@ -111,6 +257,7 @@ void main() {view.widget.scrollController!.jumpTo(100);await tester.pump();await chord(tester, LogicalKeyboardKey.keyT);+ await chord(tester, LogicalKeyboardKey.keyO);await tester.enterText(find.byKey(const ValueKey('swarm-search-input')),'Agent 0',@@ -161,6 +308,9 @@ void main() {await snapshot(third, 0, 1200);app.adoptSessionForTest(third);sessions.add(third);+ // The adoption seam only inserts the session; publish a session update+ // as the real attach path does, so every retained pane is rebuilt.+ await snapshot(third, 1, 1200);await tester.pump();for (final session in sessions) {atBottom(tester, session);diff --git a/desktop/third_party/xterm/lib/src/terminal_view.dart b/desktop/third_party/xterm/lib/src/terminal_view.dartindex f56427cb1..2269071c6 100644--- a/desktop/third_party/xterm/lib/src/terminal_view.dart+++ b/desktop/third_party/xterm/lib/src/terminal_view.dart@@ -640,7 +640,14 @@ class TerminalViewState extends State<TerminalView> {}/// Show the latest output when the current buffer and viewport are laid out.- void scrollToBottom() => renderTerminal.scrollToBottom();+ void scrollToBottom() {+ // A resize can land between ticks of a fling or driven scroll. Cancelling+ // that activity is part of returning to live output; otherwise its next+ // tick overwrites the freshly aligned offset with an old history position.+ final position = _scrollableKey.currentState?.position;+ if (position is ScrollPositionWithSingleContext) position.goIdle();+ renderTerminal.scrollToBottom();+ }void _scrollToBottom() => scrollToBottom();}diff --git a/desktop/third_party/xterm/lib/src/ui/render.dart b/desktop/third_party/xterm/lib/src/ui/render.dartindex 4716df404..b8da24cd9 100644--- a/desktop/third_party/xterm/lib/src/ui/render.dart+++ b/desktop/third_party/xterm/lib/src/ui/render.dart@@ -269,12 +269,15 @@ class RenderTerminal extends RenderBox with RelayoutWhenSystemFontsChangeMixin {final followTail = _stickToBottom;_updateViewportSize();- _updateScrollOffset();-if (followTail) {+ // Correct before publishing the dimensions. A terminal redraw may empty+ // its history for one frame; publishing that short extent while pixels+ // still points into the old history starts a macOS bounce to the top.+ // That animation would keep scrolling even as the next output refills it._offset.correctBy(_maxScrollExtent - _scrollOffset);- _stickToBottom = true;}+ _updateScrollOffset();+ if (followTail) _stickToBottom = true;_laidOutMaxScrollExtent = _maxScrollExtent;_scheduleEditableRect();}