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.

Preview retained agent output from either search field

deef04f6d3b594b
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 7a186f196..9806ec1a9 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -288,6 +288,8 @@ class _SwarmScreenState extends State<SwarmScreen> {
search.move(1);
case 'previous':
search.move(-1);
+ case 'preview':
+ search.togglePreview();
case 'submit':
final choice = search.submit();
if (choice != null) await _chooseSearch(choice);
@@ -602,14 +604,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
(_native ? _nativeSearchWidth : _searchWidth(constraints.maxWidth))
.clamp(128.0, constraints.maxWidth - 16);
final scale = MediaQuery.textScalerOf(context);
- final rowHeight = swarmSearchRowHeight(
+ final height = swarmSearchResultsHeight(
+ search,
scale,
- commands: search.isCommandMode,
- );
- final height = (search.rows.length.clamp(1, 7) * rowHeight + 64).clamp(
- 140.0,
- constraints.maxHeight - (_native ? 12 : 56),
- );
+ ).clamp(140.0, constraints.maxHeight - (_native ? 12 : 56));
final results = SizedBox(
width: width,
height: height.toDouble(),
diff --git a/desktop/lib/state/swarm_search.dart b/desktop/lib/state/swarm_search.dart
index e429e8444..746060842 100644
--- a/desktop/lib/state/swarm_search.dart
+++ b/desktop/lib/state/swarm_search.dart
@@ -1,4 +1,7 @@
import 'package:flutter/foundation.dart';
+import 'package:xterm/xterm.dart';
+
+import '../terminal/search_output_preview.dart';
import 'app_state.dart';
import 'swarm_catalog.dart';
@@ -37,6 +40,43 @@ class SwarmSearchController extends ChangeNotifier {
String query = '';
String? _selectedId;
int cursor = 0;
+ bool previewEnabled = false;
+ SearchOutputPreview? preview;
+ String? _previewId;
+
+ bool get canPreview =>
+ !isCommandMode && selected?.agentId != null && selected?.closedId == null;
+ bool get previewVisible => previewEnabled && canPreview;
+
+ void togglePreview() {
+ if (!previewEnabled && !canPreview) return;
+ previewEnabled = !previewEnabled;
+ _updatePreview();
+ notifyListeners();
+ }
+
+ void _updatePreview() {
+ if (!previewVisible) {
+ preview = null;
+ _previewId = null;
+ return;
+ }
+ final row = selected!;
+ // Keep a snapshot while this selection stays put. Query edits and output
+ // traffic do not read the buffers again. A new selection or re-enabling
+ // preview captures fresh context, including any replacement session.
+ if (_previewId == row.id) return;
+ final terminal = app.allPanes
+ .where(
+ (pane) =>
+ pane.machineId == row.machineId && pane.agentId == row.agentId,
+ )
+ .map((pane) => pane.session?.terminal)
+ .whereType<Terminal>()
+ .firstOrNull;
+ _previewId = row.id;
+ preview = SearchOutputPreview.capture(terminal);
+ }
SwarmDestination? get selected => rows.isEmpty ? null : rows[cursor];
String get hint => isCommandMode
@@ -73,6 +113,7 @@ class SwarmSearchController extends ChangeNotifier {
? index
: cursor.clamp(0, rows.length - 1);
_selectedId = selected?.id;
+ _updatePreview();
}
void setQuery(String value) {
@@ -88,6 +129,7 @@ class SwarmSearchController extends ChangeNotifier {
if (rows.isEmpty) return;
cursor = (cursor + delta) % rows.length;
_selectedId = selected!.id;
+ _updatePreview();
notifyListeners();
}
diff --git a/desktop/lib/terminal/search_output_preview.dart b/desktop/lib/terminal/search_output_preview.dart
new file mode 100644
index 000000000..772ae0365
--- /dev/null
+++ b/desktop/lib/terminal/search_output_preview.dart
@@ -0,0 +1,36 @@
+import 'dart:math' as math;
+
+import 'package:xterm/xterm.dart';
+
+/// A small, inert excerpt of output the app already holds. Reading a preview
+/// never changes the terminal, its viewport, selection, input or connection.
+class SearchOutputPreview {
+ const SearchOutputPreview(this.text);
+
+ // Covers the maximum 120-row viewport plus a small amount of scrollback,
+ // including a short prompt near the top of an otherwise empty tall pane.
+ static const scannedLines = 160;
+ static const shownLines = 12;
+ static const shownColumns = 192;
+ final String text;
+ static final _controls = RegExp(r'[\x00-\x1f\x7f-\x9f]');
+
+ static SearchOutputPreview capture(Terminal? terminal) {
+ if (terminal == null) return const SearchOutputPreview('');
+ final lines = terminal.buffer.lines;
+ final excerpt = <String>[];
+ final start = math.max(0, lines.length - scannedLines);
+ for (var row = lines.length - 1; row >= start; row--) {
+ // getText works in terminal cells, so a wide Unicode character is not
+ // split as it could be by slicing an arbitrary UTF-16 string.
+ final text = lines[row]
+ .getText(0, shownColumns)
+ .replaceAll(_controls, '')
+ .trimRight();
+ if (text.trim().isEmpty) continue;
+ excerpt.add(text);
+ if (excerpt.length == shownLines) break;
+ }
+ return SearchOutputPreview(excerpt.reversed.join('\n'));
+ }
+}
diff --git a/desktop/lib/widgets/swarm_inline_search.dart b/desktop/lib/widgets/swarm_inline_search.dart
index fa620e21a..a99440ffd 100644
--- a/desktop/lib/widgets/swarm_inline_search.dart
+++ b/desktop/lib/widgets/swarm_inline_search.dart
@@ -109,17 +109,13 @@ class _SwarmInlineSearchState extends State<SwarmInlineSearch> {
Offset.zero & info.childSize,
);
final scale = MediaQuery.textScalerOf(context);
- final rowHeight = swarmSearchRowHeight(
- scale,
- commands: search.isCommandMode,
- );
final available = math.max(
0.0,
info.overlaySize.height - anchor.bottom - 16,
);
final height = math.min(
available,
- search.rows.length.clamp(1, 7) * rowHeight + 64,
+ swarmSearchResultsHeight(search, scale),
);
return Positioned(
top: anchor.bottom,
diff --git a/desktop/lib/widgets/swarm_switcher.dart b/desktop/lib/widgets/swarm_switcher.dart
index 9e4798d10..5f8964751 100644
--- a/desktop/lib/widgets/swarm_switcher.dart
+++ b/desktop/lib/widgets/swarm_switcher.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
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 '../state/swarm_navigation.dart';
@@ -159,6 +160,12 @@ class SwarmSearchKeys extends StatelessWidget {
run(() => search.move(1)),
const SingleActivator(LogicalKeyboardKey.arrowUp): () =>
run(() => search.move(-1)),
+ const SingleActivator(
+ LogicalKeyboardKey.keyI,
+ meta: true,
+ includeRepeats: false,
+ ): () =>
+ run(search.togglePreview),
const SingleActivator(
LogicalKeyboardKey.keyN,
control: true,
@@ -197,6 +204,15 @@ double swarmSearchRowHeight(TextScaler scale, {required bool commands}) =>
? (scale.scale(13) + 20).clamp(40, double.infinity)
: (scale.scale(13) + scale.scale(11) + 32).clamp(56, double.infinity);
+double swarmSearchResultsHeight(
+ SwarmSearchController search,
+ TextScaler scale,
+) =>
+ search.rows.length.clamp(1, search.previewVisible ? 4 : 7) *
+ swarmSearchRowHeight(scale, commands: search.isCommandMode) +
+ 64 +
+ (search.previewVisible ? scale.scale(11) * 10 + 24 : 0);
+
/// Shared results for the title bar, New swarm field and History.
class SwarmSearchResults extends StatefulWidget {
const SwarmSearchResults({
@@ -269,154 +285,257 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
final scale = MediaQuery.textScalerOf(context);
_rowHeight = swarmSearchRowHeight(scale, commands: search.isCommandMode);
final selected = search.selected;
- return Semantics(
- container: true,
- label: 'Search results',
- child: Column(
- children: [
- Expanded(
- child: search.rows.isEmpty
- ? Center(
- child: Text(
- search.isCommandMode
- ? 'No matching commands'
- : 'No matching results',
- style: const TextStyle(
- fontSize: 13,
- color: Colors.white60,
- ),
- ),
- )
- : ListView.builder(
- controller: _scroll,
- itemCount: search.rows.length,
- itemExtent: _rowHeight,
- itemBuilder: (context, index) {
- final row = search.rows[index];
- return ListTile(
- key: ValueKey(row.id),
- minTileHeight: _rowHeight,
- enabled: search.canSubmit(row),
- selected: index == search.cursor,
- selectedColor: Colors.white,
- selectedTileColor: Colors.white10,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(8),
- ),
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 12,
- ),
- leading: row.isCommand
- ? const Icon(
- Icons.keyboard_command_key,
- size: 19,
- color: Colors.white60,
- )
- : row.agentId != null
- ? EngineMark(
- engine: row.engine,
- size: 20,
- enabled: search.canSubmit(row),
- )
- : row.isSwarm
- ? const SwarmIcon(color: Colors.white60)
- : Icon(
- row.isMachine
- ? Icons.computer_outlined
- : Icons.folder_outlined,
- size: 19,
- color: Colors.white60,
- ),
- title: Text(
- row.title,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 13),
- ),
- subtitle: row.isCommand
- ? null
- : Text(
- row.detail,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(
- fontSize: 11,
- color: Colors.white70,
- ),
- ),
- trailing: row.shortcut == null
- ? null
- : Text(
- row.shortcut!,
- style: const TextStyle(
- fontSize: 11,
- color: Colors.white70,
- ),
- ),
- onTap: search.canSubmit(row)
- ? () => _submit(row)
- : null,
- );
- },
- ),
- ),
- const SizedBox(height: 4),
- Row(
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final previewHeight = (constraints.maxHeight - _rowHeight - 48).clamp(
+ 0.0,
+ scale.scale(11) * 10 + 24,
+ );
+ return Semantics(
+ container: true,
+ label: 'Search results',
+ child: Column(
children: [
Expanded(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 10),
- child: Text(
- selected != null && !search.canSubmit(selected)
- ? selected.isGroup &&
- selected.members.length > AppNotifier.maxPanes
- ? 'A swarm supports up to ${AppNotifier.maxPanes} agents'
- : 'No room to open this ${selected.isSwarm || selected.isGroup ? 'swarm' : 'agent'}'
- : selected?.closedId != null
- ? search.canSubmit(selected)
- ? 'Reopen ${selected!.isSwarm ? 'swarm' : 'agent'}'
- : 'No room to reopen'
- : selected?.agentId != null && !selected!.hasView
- ? 'Opens in ${search.targetName}'
- : search.query.isEmpty && search.commands != null
- ? 'Type > for commands'
- : '↑↓ choose · Esc close',
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 11, color: Colors.white70),
- ),
- ),
+ child: search.rows.isEmpty
+ ? Center(
+ child: Text(
+ search.isCommandMode
+ ? 'No matching commands'
+ : 'No matching results',
+ style: const TextStyle(
+ fontSize: 13,
+ color: Colors.white60,
+ ),
+ ),
+ )
+ : ListView.builder(
+ controller: _scroll,
+ itemCount: search.rows.length,
+ itemExtent: _rowHeight,
+ itemBuilder: (context, index) {
+ final row = search.rows[index];
+ return ListTile(
+ key: ValueKey(row.id),
+ minTileHeight: _rowHeight,
+ enabled: search.canSubmit(row),
+ selected: index == search.cursor,
+ selectedColor: Colors.white,
+ selectedTileColor: Colors.white10,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(8),
+ ),
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 12,
+ ),
+ leading: row.isCommand
+ ? const Icon(
+ Icons.keyboard_command_key,
+ size: 19,
+ color: Colors.white60,
+ )
+ : row.agentId != null
+ ? EngineMark(
+ engine: row.engine,
+ size: 20,
+ enabled: search.canSubmit(row),
+ )
+ : row.isSwarm
+ ? const SwarmIcon(color: Colors.white60)
+ : Icon(
+ row.isMachine
+ ? Icons.computer_outlined
+ : Icons.folder_outlined,
+ size: 19,
+ color: Colors.white60,
+ ),
+ title: Text(
+ row.title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: const TextStyle(fontSize: 13),
+ ),
+ subtitle: row.isCommand
+ ? null
+ : Text(
+ row.detail,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: const TextStyle(
+ fontSize: 11,
+ color: Colors.white70,
+ ),
+ ),
+ trailing: row.shortcut == null
+ ? null
+ : Text(
+ row.shortcut!,
+ style: const TextStyle(
+ fontSize: 11,
+ color: Colors.white70,
+ ),
+ ),
+ onTap: search.canSubmit(row)
+ ? () => _submit(row)
+ : null,
+ );
+ },
+ ),
),
- if (search.canAdd(selected))
- TextButton(
- onPressed: () => widget.onChoose(search.addHere()!),
- style: TextButton.styleFrom(foregroundColor: Colors.white70),
- child: const Text(
- 'Add to this swarm ⌘↵',
- style: TextStyle(fontSize: 11),
- ),
+ if (search.previewVisible && previewHeight >= 64)
+ SizedBox(
+ height: previewHeight,
+ child: _OutputPreview(text: search.preview?.text ?? ''),
),
- TextButton(
- onPressed: search.canSubmit(selected) ? _submit : null,
- style: TextButton.styleFrom(foregroundColor: Colors.white),
- child: search.isCommandMode
- ? const Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text('Run command', style: TextStyle(fontSize: 11)),
- SizedBox(width: 8),
- Icon(Icons.keyboard_return, size: 14),
- ],
- )
- : Text(
- '${selected == null ? 'Go to' : SwarmSearchController.action(selected)} ↵',
- style: const TextStyle(fontSize: 11),
+ const SizedBox(height: 4),
+ Row(
+ children: [
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ child: Text(
+ selected != null && !search.canSubmit(selected)
+ ? selected.isGroup &&
+ selected.members.length >
+ AppNotifier.maxPanes
+ ? 'A swarm supports up to ${AppNotifier.maxPanes} agents'
+ : 'No room to open this ${selected.isSwarm || selected.isGroup ? 'swarm' : 'agent'}'
+ : selected?.closedId != null
+ ? search.canSubmit(selected)
+ ? 'Reopen ${selected!.isSwarm ? 'swarm' : 'agent'}'
+ : 'No room to reopen'
+ : selected?.agentId != null && !selected!.hasView
+ ? 'Opens in ${search.targetName}'
+ : search.query.isEmpty && search.commands != null
+ ? 'Type > for commands'
+ : '↑↓ choose · Esc close',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: const TextStyle(
+ fontSize: 11,
+ color: Colors.white70,
+ ),
+ ),
+ ),
+ ),
+ if (search.canPreview ||
+ search.previewEnabled && !search.isCommandMode)
+ Tooltip(
+ message: search.previewEnabled
+ ? 'Hide preview (⌘I)'
+ : 'Preview recent output (⌘I)',
+ child: IconButton(
+ key: const ValueKey('swarm-search-preview-toggle'),
+ onPressed: () {
+ search.togglePreview();
+ widget.onRefocus();
+ },
+ icon: Icon(
+ search.previewEnabled
+ ? Icons.visibility
+ : Icons.visibility_outlined,
+ size: 18,
+ color: search.previewEnabled
+ ? Colors.white
+ : Colors.white70,
+ ),
+ visualDensity: VisualDensity.compact,
),
+ ),
+ if (search.canAdd(selected))
+ TextButton(
+ onPressed: () => widget.onChoose(search.addHere()!),
+ style: TextButton.styleFrom(
+ foregroundColor: Colors.white70,
+ ),
+ child: const _SearchActionLabel(
+ 'Add to this swarm',
+ command: true,
+ ),
+ ),
+ TextButton(
+ onPressed: search.canSubmit(selected) ? _submit : null,
+ style: TextButton.styleFrom(foregroundColor: Colors.white),
+ child: _SearchActionLabel(
+ selected == null
+ ? 'Go to'
+ : SwarmSearchController.action(selected),
+ ),
+ ),
+ ],
),
],
),
- ],
- ),
+ );
+ },
);
}
}
+
+class _SearchActionLabel extends StatelessWidget {
+ const _SearchActionLabel(this.label, {this.command = false});
+ final String label;
+ final bool command;
+
+ @override
+ Widget build(BuildContext context) => Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(label, style: const TextStyle(fontSize: 11)),
+ const SizedBox(width: 8),
+ if (command) const Text('⌘', style: TextStyle(fontSize: 11)),
+ const Icon(Icons.keyboard_return, size: 14),
+ ],
+ );
+}
+
+class _OutputPreview extends StatelessWidget {
+ const _OutputPreview({required this.text});
+ final String text;
+
+ @override
+ Widget build(BuildContext context) => Container(
+ key: const ValueKey('swarm-search-preview'),
+ width: double.infinity,
+ margin: const EdgeInsets.fromLTRB(8, 8, 8, 4),
+ padding: const EdgeInsets.all(10),
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: 0.16),
+ borderRadius: BorderRadius.circular(6),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const Tooltip(
+ message: 'A snapshot of available output. Turn preview off and on to refresh.',
+ child: Text(
+ 'Output preview',
+ style: TextStyle(fontSize: 11, color: Colors.white70),
+ ),
+ ),
+ const SizedBox(height: 6),
+ Flexible(
+ child: SingleChildScrollView(
+ primary: false,
+ reverse: true,
+ child: Text(
+ text.isEmpty ? 'No output available for preview.' : text,
+ style: TextStyle(
+ fontFamily: text.isEmpty
+ ? grid.AppFont.sans
+ : grid.AppFont.mono,
+ fontFamilyFallback: text.isEmpty
+ ? grid.AppFont.sansFallback
+ : grid.AppFont.monoFallback,
+ fontSize: 11,
+ height: 1.45,
+ color: text.isEmpty ? Colors.white70 : Colors.white,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+}
diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swift
index 7c53e6e05..7bf31c6b2 100644
--- a/desktop/macos/Runner/SwarmTitlebar.swift
+++ b/desktop/macos/Runner/SwarmTitlebar.swift
@@ -640,6 +640,10 @@ private final class SwarmSearchField: NSSearchField {
editor.selectAll(nil)
return true
}
+ if event.charactersIgnoringModifiers == "i" && !editor.hasMarkedText() {
+ if !event.isARepeat { command?("preview") }
+ return true
+ }
if let action = Self.resultCommand("insertNewline:", event: event, composing: editor.hasMarkedText()),
event.charactersIgnoringModifiers == "\r" || event.charactersIgnoringModifiers == "\u{3}" {
if !event.isARepeat { command?(action) }
@@ -651,6 +655,7 @@ private final class SwarmSearchField: NSSearchField {
static func resultCommand(_ selector: String, event: NSEvent?, composing: Bool) -> String? {
guard !composing else { return nil }
let modifiers = event?.modifierFlags.intersection([.command, .option, .control, .shift]) ?? []
+ if modifiers == .command && event?.charactersIgnoringModifiers == "i" { return "preview" }
if modifiers == .control {
switch event?.charactersIgnoringModifiers?.lowercased() {
case "n", "j": return "next"
@@ -875,7 +880,7 @@ private final class SwarmTabStrip: NSView, NSSearchFieldDelegate {
let event = NSApp.currentEvent
guard let action = SwarmSearchField.resultCommand(NSStringFromSelector(selector), event: event,
composing: textView.hasMarkedText()) else { return false }
- if event?.isARepeat != true || !["submit", "add", "close"].contains(action) {
+ if event?.isARepeat != true || !["submit", "add", "close", "preview"].contains(action) {
emit?("searchCommand", ["command": action])
}
return true
diff --git a/desktop/test/swarm_commands_test.dart b/desktop/test/swarm_commands_test.dart
index 4a3439823..6c6915686 100644
--- a/desktop/test/swarm_commands_test.dart
+++ b/desktop/test/swarm_commands_test.dart
@@ -74,7 +74,7 @@ void main() {
await tester.pump();
expect(find.text('⌘⇧P'), findsNothing);
expect(find.text('⇧⌘P'), findsOneWidget);
- expect(find.text('Add to this swarm ⌘↵'), findsNothing);
+ expect(find.text('Add to this swarm'), findsNothing);
expect(find.byKey(const ValueKey('command:pane.pin')), findsOneWidget);
expect(app.isPanePinned(pane), isFalse);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
diff --git a/desktop/test/swarm_history_test.dart b/desktop/test/swarm_history_test.dart
index 65e805a6a..42eb89341 100644
--- a/desktop/test/swarm_history_test.dart
+++ b/desktop/test/swarm_history_test.dart
@@ -340,6 +340,17 @@ void main() {
.width,
480,
);
+ await native('searchCommand', {'command': 'preview'});
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsOneWidget,
+ );
+ expect(
+ fieldUpdates.every((state) => !state.containsKey('query')),
+ isTrue,
+ );
+ expect(otherInput, isEmpty);
await native('searchCommand', {'command': 'submit'});
await tester.pump();
await jumping;
diff --git a/desktop/test/swarm_search_preview_test.dart b/desktop/test/swarm_search_preview_test.dart
new file mode 100644
index 000000000..94792935f
--- /dev/null
+++ b/desktop/test/swarm_search_preview_test.dart
@@ -0,0 +1,163 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/state/swarm_search.dart';
+import 'package:harness/terminal/search_output_preview.dart';
+import 'package:harness/terminal/terminal_binary.dart';
+import 'package:xterm/xterm.dart';
+
+import 'swarm_interactions_test.dart' show chord;
+import 'swarm_screen_test.dart' show mount, terminal;
+import 'swarm_state_test.dart' show createApp;
+
+void main() {
+ test(
+ 'preview bounds scrollback, rows and columns without altering Unicode',
+ () {
+ final terminal = Terminal(maxLines: 10000)..resize(300, 120);
+ terminal.write('A short prompt in a tall pane');
+ expect(
+ SearchOutputPreview.capture(terminal).text,
+ 'A short prompt in a tall pane',
+ );
+ terminal.write('\r\n');
+ for (var i = 0; i < 500; i++) {
+ terminal.write('Old line $i\r\n');
+ }
+ terminal.write('${'木' * 150}\r\nRecent result 😀\r\n> ');
+ final before = terminal.buffer.getText();
+ final position = (terminal.buffer.cursorX, terminal.buffer.cursorY);
+ final snapshot = SearchOutputPreview.capture(terminal).text;
+ expect(snapshot.split('\n').length, SearchOutputPreview.shownLines);
+ expect(snapshot, contains('木' * 96));
+ expect(snapshot, isNot(contains('木' * 97)));
+ expect(snapshot, contains('Recent result 😀'));
+ expect(snapshot, isNot(contains('Old line 0\n')));
+ expect(snapshot, isNot(contains('\uFFFD')));
+ expect(terminal.buffer.getText(), before);
+ expect((terminal.buffer.cursorX, terminal.buffer.cursorY), position);
+ terminal.write('\r\n' * (SearchOutputPreview.scannedLines + 1));
+ expect(SearchOutputPreview.capture(terminal).text, isEmpty);
+ expect(SearchOutputPreview.capture(null).text, isEmpty);
+ },
+ );
+
+ test(
+ 'preview is lazy and cached for the selection, with explicit refresh',
+ () {
+ final app = createApp();
+ addTearDown(app.dispose);
+ final output = terminal('a0', []);
+ output.terminal.write('Original context');
+ final pane = app.adoptSessionForTest(output);
+ final search = SwarmSearchController(app, []);
+ addTearDown(search.dispose);
+ search.setQuery('Agent 0');
+ expect(search.preview, isNull);
+ search.togglePreview();
+ final first = search.preview;
+ expect(first!.text, contains('Original context'));
+ output.terminal.write('\r\nNew output');
+ for (final query in ['Agent', 'Agent 0', 'Test host Agent 0']) {
+ search.setQuery(query);
+ expect(search.preview, same(first));
+ }
+ search.togglePreview();
+ expect(search.preview, isNull);
+ search.togglePreview();
+ expect(search.preview!.text, contains('New output'));
+ expect(pane.session, same(output));
+ search.setQuery('Agent 1');
+ expect(search.preview!.text, isEmpty);
+ expect(app.allPanes, [pane]);
+ search.setQuery('>');
+ expect(search.previewVisible, isFalse);
+ expect(search.preview, isNull);
+ },
+ );
+
+ for (final inline in [false, true]) {
+ testWidgets(
+ 'optional preview keeps ${inline ? 'New swarm' : 'titlebar'} input and go-to action',
+ (tester) async {
+ final app = createApp();
+ app.machineStates['m']!.nodeOnline = true;
+ final frames = <TerminalBinaryFrame>[];
+ final output = terminal('a0', frames);
+ output.terminal.write('Checking the build\r\nOne useful clue\r\n');
+ final original = app.adoptSessionForTest(output);
+ if (inline) app.newSwarm();
+ final target = app.activeSwarm;
+ await mount(tester, app);
+ final input = find.byKey(
+ ValueKey(
+ inline ? 'swarm-welcome-search-input' : 'swarm-search-input',
+ ),
+ );
+ await tester.tap(input);
+ await tester.enterText(input, 'Agent 0');
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsNothing,
+ );
+ final field = tester.widget<TextField>(input);
+ final controller = field.controller!;
+ final focus = field.focusNode!;
+ await chord(tester, LogicalKeyboardKey.keyI);
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsOneWidget,
+ );
+ expect(find.textContaining('One useful clue'), findsOneWidget);
+ expect(controller.text, 'Agent 0');
+ expect(focus.hasFocus, isTrue);
+ expect(app.activeSwarm, same(target));
+ expect(frames, isEmpty);
+
+ // Mouse toggling also keeps editing in the field that opened search.
+ await tester.tap(
+ find.byKey(const ValueKey('swarm-search-preview-toggle')),
+ );
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsNothing,
+ );
+ expect(focus.hasFocus, isTrue);
+ controller.value = const TextEditingValue(
+ text: 'Agent 0',
+ composing: TextRange(start: 0, end: 7),
+ );
+ await chord(tester, LogicalKeyboardKey.keyI);
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsNothing,
+ );
+ controller.value = const TextEditingValue(
+ text: 'Agent 0',
+ selection: TextSelection.collapsed(offset: 7),
+ );
+ await chord(tester, LogicalKeyboardKey.keyI);
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsOneWidget,
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(app.focusedPaneId, original.id);
+ expect(app.panes.single.session, same(output));
+ expect(frames, isEmpty);
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
+ await tester.pump(const Duration(milliseconds: 10));
+ expect(frames.single.bytes, [27, 91, 68]);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ },
+ );
+ }
+}
diff --git a/desktop/test/swarm_search_test.dart b/desktop/test/swarm_search_test.dart
index e55e077e0..3470e7393 100644
--- a/desktop/test/swarm_search_test.dart
+++ b/desktop/test/swarm_search_test.dart
@@ -305,7 +305,7 @@ void main() {
await chord(tester, LogicalKeyboardKey.keyP);
await tester.enterText(jumpField, 'Agent 0');
await tester.pump();
- expect(find.text('Add to this swarm ⌘↵'), findsOneWidget);
+ expect(find.text('Add to this swarm'), findsOneWidget);
await chord(tester, LogicalKeyboardKey.enter);
expect(find.byType(Dialog), findsNothing);
expect(app.activeSwarm, same(target));
diff --git a/desktop/tool/swarm_titlebar_checks.swift b/desktop/tool/swarm_titlebar_checks.swift
index cb4843fd3..ca9b24a64 100644
--- a/desktop/tool/swarm_titlebar_checks.swift
+++ b/desktop/tool/swarm_titlebar_checks.swift
@@ -130,6 +130,7 @@ private extension SwarmTabStrip {
("moveUp:", key("k", .control), "previous"),
("insertNewline:", key("\r"), "submit"),
("insertNewline:", key("\r", .command), "add"),
+ ("showInfo:", key("i", .command), "preview"),
("cancelOperation:", key("g", .control), "close")
] {
try checkTitlebar(SwarmSearchField.resultCommand(selector, event: event, composing: false) == expected,
diff --git a/docs/harness-v2-developer-tools-research.md b/docs/harness-v2-developer-tools-research.md
index ea22adf06..376e78315 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, 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. |
+| Resizing, splits, commands and preview implemented | `>` 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. Cmd-I or the eye control enables a compact snapshot of already-retained output for the selected agent; preview starts hidden and performs no network or terminal attachment. Match highlighting remains a follow-up. 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 review
diff --git a/docs/harness-v2-performance.md b/docs/harness-v2-performance.md
index 0fd3602cb..1db1bea8e 100644
--- a/docs/harness-v2-performance.md
+++ b/docs/harness-v2-performance.md
@@ -10,6 +10,14 @@ flutter test --no-pub --reporter expanded test/benchmarks/swarm_benchmark.dart
It prints `SWARM_BENCH` JSON records. Its filename deliberately does not end in `_test.dart`, so ordinary correctness runs do not include timing measurements.
+## Optional search output preview (2026-09-13)
+
+Preview is off by default. With preview enabled, changing the selected agent reads at most 160 retained rows × 192 cells, stopping after 12 nonblank lines. Query edits that keep the same selection reuse the snapshot without reading the buffer or scanning open panes again. There are no output listeners, periodic refreshes, network calls or terminal attachments. The tooltip explains that toggling preview off/on refreshes its snapshot.
+
+An isolated debug-Dart fixture used a 300-column, 120-row terminal with 4,000+ retained rows, 200 warmups and 1,000 samples. Extraction of 12 output rows took **24 µs median / 33 µs p95 / 479 µs max**. Scanning 160 blank rows took **69 µs median / 84 µs p95 / 347 µs max**. Artifacts: `/private/tmp/harness-v2-preview-benchmark.dart` and `/private/tmp/harness-v2-search-preview-final-render.log`.
+
+These measurements cover only extraction CPU time on the shared workstation. They do not measure result ranking, Flutter layout/paint, AppKit event handling, display latency or network round trips. Separate correctness checks cover Unicode, bounds, snapshot caching and unchanged query/input/terminal ownership.
+
## Unified search catalog and typing (2026-09-13)
The catalog benchmark now also exercises the production `SwarmSearchController`:
diff --git a/docs/harness-v2-progress.md b/docs/harness-v2-progress.md
index 8c05c0965..41145be6f 100644
--- a/docs/harness-v2-progress.md
+++ b/docs/harness-v2-progress.md
@@ -2,13 +2,23 @@
Updated 2026-09-13 with coordinated palettes, Models, combined closed-work History and faster unified search. This is a working preview, not a release.
-## Active follow-up: keyboard-accessible first use
+## Active follow-up: optional search preview
+
+- The eye control in open search, or **Cmd-I** while editing its query, toggles a short output preview. It starts hidden for each search session. Both the titlebar and New swarm field keep their own query, caret, selected result and Enter action. Commands, groups and closed History entries do not show an agent-output preview.
+- The preview snapshots only an already-retained matching machine/agent session. It scans at most 160 rows and 192 cells per row, keeps at most 12 nonblank lines, and retains only the current excerpt. Repeated query edits on the same selection reuse that excerpt; changing selection or toggling off/on captures again. Missing output gets an honest empty state. No network request, terminal attachment, input, resize or viewport mutation occurs.
+- The excerpt takes a compact bounded area below results and can scroll independently. The input stays in place. The final visual pass corrected excess footer space and replaced the Return text glyph with the same icon used for command actions. The native Cmd-I path and Flutter path both respect IME composition and ignore repeated toggles.
+- Validation: **1,148 Flutter tests passed, one existing skip** and **297 AppKit checks passed**. Analyzer has no errors/warnings and 12 existing vendored infos. Isolated renders covered titlebar, New swarm and an 880×560 window; no real agents received test input. Artifacts: `/private/tmp/harness-v2-search-preview-{tests,full-tests,analyze,native,final-render}.log` and `/private/tmp/harness-v2-search-preview-{top,inline,narrow}.png`.
+- The debug extraction fixture measured 0.033 ms p95 for 12 output rows and 0.084 ms p95 for 160 blank rows with 4,000+ retained rows. This is extraction CPU time, not native input-to-display latency; details are in [performance notes](harness-v2-performance.md).
+- Next: file-remapping ownership across AppKit and Flutter, keeping the approved defaults unchanged. Match highlighting remains a small search follow-up.
+- Release build succeeded (`/private/tmp/harness-v2-search-preview-build.log`) and the exact development preview was reopened. PID 23328 was normally quit and confirmed exited before rebuilding; re-observe the current preview before later interaction.
+
+## Keyboard-accessible first use checkpoint
- New agent opens immediately with a simple dimmed backdrop. The failed engine-check explanation is brief and readable; conditional CLI troubleshooting lives in Advanced. Cancel uses neutral secondary text. Explicit installation and creation behavior is unchanged.
- Machine, project folder and coding-agent controls now participate in Tab traversal. The shared select field supports Enter/Space, arrow navigation, Escape and return to the field after selection. Focus is visible without a thick glow. Folder selection restores keyboard focus after the native or remote picker completes.
- Collapsed Advanced content remains mounted for profile discovery, but cannot receive invisible keyboard focus. Submitting also excludes the choices from keyboard focus while the explicit operation is running.
- Validation: **1,144 Flutter tests passed, one existing skip** (`/private/tmp/harness-v2-form-full-tests.log`), including keyboard-only first-agent creation and picker selection on macOS, Windows and Linux test variants. Analyzer has no errors/warnings and 12 existing vendored infos. Isolated renders of the form and focused folder were reviewed (`/private/tmp/harness-v2-form-{form,keyboard}.png`); the render test also passed. These are fixture results, not real first-install conversion measurements.
-- Next: optional bounded search preview and file-remapping ownership across AppKit and Flutter. Keep the approved simple shortcuts unchanged.
+- The optional preview is now recorded above. File-remapping ownership across AppKit and Flutter remains next; keep the approved simple shortcuts unchanged.
- Release build succeeded (`/private/tmp/harness-v2-form-build.log`) and the exact development preview was reopened. Preview PID 14152 was normally quit and confirmed exited before writing its bundle; no real agent received test input. Re-observe the next preview PID before any native interaction.
## Deliberate splits checkpoint