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.

Show useful live session previews in Harness search

dee91cfb6a0538e
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 12f021832..9d88d805a 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -902,8 +902,11 @@ class _SwarmScreenState extends State<SwarmScreen> {
Align(
alignment: const Alignment(0, -0.12),
child: SizedBox(
- width: (constraints.maxWidth - 64).clamp(280.0, 720.0),
- height: (constraints.maxHeight - 96).clamp(220.0, 540.0),
+ width: (constraints.maxWidth - 64).clamp(
+ 280.0,
+ commandsOnly ? 720.0 : 1120.0,
+ ),
+ height: (constraints.maxHeight - 96).clamp(220.0, 600.0),
child: Column(
children: [
Expanded(
diff --git a/desktop/lib/widgets/harness_start_page.dart b/desktop/lib/widgets/harness_start_page.dart
index 923ae88a5..2d6ccff6f 100644
--- a/desktop/lib/widgets/harness_start_page.dart
+++ b/desktop/lib/widgets/harness_start_page.dart
@@ -33,7 +33,7 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
canRequestFocus: false,
);
final _searchGroup = Object();
- final _searchArea = GlobalKey();
+ final _entryActions = GlobalKey();
bool _revealScheduled = false;
SwarmSearchController? _search;
SwarmSearchDraft? _draft;
@@ -45,10 +45,10 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
WidgetsBinding.instance.addPostFrameCallback((_) {
_revealScheduled = false;
if (!mounted || !_showResults || !_pickerFocus.hasFocus) return;
- // The list also scrolls internally. Keep its whole viewport visible so
- // arrow navigation cannot highlight a row below the window edge.
+ // Keep the actions below the expanded picker reachable. Its bounded
+ // viewport and internal list scrolling keep the highlighted row visible.
Scrollable.ensureVisible(
- _searchArea.currentContext!,
+ _entryActions.currentContext!,
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
);
});
@@ -112,7 +112,9 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
),
child: Center(
child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 640),
+ constraints: BoxConstraints(
+ maxWidth: _showResults ? 1120 : 640,
+ ),
child: Column(
children: [
const Text(
@@ -129,7 +131,6 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
child: Focus(
focusNode: _pickerFocus,
child: Material(
- key: _searchArea,
color: _showResults
? grid.AppPalette.swarmSearchSurface
: Colors.transparent,
@@ -180,10 +181,8 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
color: Colors.white12,
),
SizedBox(
- height: (constraints.maxHeight * 0.4).clamp(
- 168,
- 336,
- ),
+ height: (constraints.maxHeight * 0.54)
+ .clamp(260, 480),
child: SwarmSearchResults(
key: const ValueKey(
'harness-start-results',
@@ -202,6 +201,7 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
),
const SizedBox(height: 20),
Wrap(
+ key: _entryActions,
alignment: WrapAlignment.center,
spacing: 12,
runSpacing: 12,
diff --git a/desktop/lib/widgets/swarm_search_preview.dart b/desktop/lib/widgets/swarm_search_preview.dart
new file mode 100644
index 000000000..d5347ae08
--- /dev/null
+++ b/desktop/lib/widgets/swarm_search_preview.dart
@@ -0,0 +1,450 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import '../core/models.dart';
+import '../state/app_state.dart';
+import '../state/swarm_navigation.dart';
+import '../state/swarm_search.dart';
+import 'engine_identity.dart';
+
+typedef _PreviewAgent = ({MachineState machine, Agent agent});
+
+List<_PreviewAgent> _agents(AppNotifier app, SwarmDestination row) {
+ final result = <_PreviewAgent>[];
+ for (final machine in app.machineStates.values) {
+ for (final agent in machine.agents) {
+ if (row.agentId == agent.id &&
+ row.machineId == machine.machine.machineId ||
+ row.agentId == null &&
+ row.members.contains(
+ agentDestinationId(machine.machine.machineId, agent.id),
+ )) {
+ result.add((machine: machine, agent: agent));
+ }
+ }
+ }
+ int priority(_PreviewAgent item) => item.machine.nodeOnline == false
+ ? 3
+ : item.machine.blockedAgents.containsKey(item.agent.id)
+ ? 0
+ : item.machine.processingAgentIds.contains(item.agent.id)
+ ? 1
+ : 2;
+ // Waiting members come first; retain catalog order within each state.
+ return [
+ for (var p = 0; p < 4; p++) ...result.where((item) => priority(item) == p),
+ ];
+}
+
+/// One content surface shared by Cmd-O and the start page. Arrow keys only swap
+/// cached records. A short dwell warms cold records without delaying selection.
+class SwarmSearchPreview extends StatefulWidget {
+ const SwarmSearchPreview({
+ super.key,
+ required this.search,
+ this.compactHeader = false,
+ });
+ final SwarmSearchController search;
+ final bool compactHeader;
+
+ @override
+ State<SwarmSearchPreview> createState() => _SwarmSearchPreviewState();
+}
+
+class _SwarmSearchPreviewState extends State<SwarmSearchPreview> {
+ Timer? _warm;
+ String? _selectedId;
+ final _scroll = ScrollController();
+ AppNotifier get app => widget.search.app;
+
+ @override
+ void initState() {
+ super.initState();
+ widget.search.addListener(_changed);
+ _changed();
+ }
+
+ @override
+ void didUpdateWidget(SwarmSearchPreview oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.search != widget.search) {
+ oldWidget.search.removeListener(_changed);
+ widget.search.addListener(_changed);
+ _selectedId = null;
+ _changed();
+ }
+ }
+
+ void _changed() {
+ final row = widget.search.selected;
+ if (_selectedId == row?.id) return;
+ _selectedId = row?.id;
+ if (_scroll.hasClients) _scroll.jumpTo(0);
+ setState(() {});
+ _warm?.cancel();
+ _warm = Timer(const Duration(milliseconds: 140), () {
+ if (!mounted || row == null) return;
+ final selected = _agents(app, row);
+ final neighbors = widget.search.rows
+ .skip(widget.search.cursor + 1)
+ .take(2);
+ app.sessionPreviews.warm([
+ for (final item in selected)
+ app.previewKey(item.machine.machine.machineId, item.agent),
+ for (final neighbor in neighbors)
+ for (final item in _agents(app, neighbor).take(2))
+ app.previewKey(item.machine.machine.machineId, item.agent),
+ ], prioritize: true);
+ });
+ }
+
+ @override
+ void dispose() {
+ _warm?.cancel();
+ widget.search.removeListener(_changed);
+ _scroll.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) => AnimatedBuilder(
+ animation: Listenable.merge([app, app.sessionPreviews]),
+ builder: (context, _) {
+ final row = widget.search.selected;
+ if (row == null) return const SizedBox.shrink();
+ final agents = _agents(app, row);
+ return Semantics(
+ container: true,
+ label: 'Harness preview',
+ child: ColoredBox(
+ color: Colors.black.withValues(alpha: .10),
+ child: Scrollbar(
+ controller: _scroll,
+ child: agents.length != 1
+ ? ListView.builder(
+ key: ValueKey('preview-content:${row.id}'),
+ controller: _scroll,
+ padding: EdgeInsets.all(widget.compactHeader ? 16 : 24),
+ cacheExtent: 120,
+ itemCount: agents.length + 1,
+ itemBuilder: (context, index) => index == 0
+ ? Padding(
+ padding: const EdgeInsets.only(bottom: 24),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ row.title,
+ style: const TextStyle(
+ fontSize: 20,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ const SizedBox(height: 6),
+ Text(row.detail, style: _muted),
+ if (agents.isEmpty)
+ const Padding(
+ padding: EdgeInsets.only(top: 24),
+ child: Text(
+ 'No recent session text available.',
+ style: _muted,
+ ),
+ ),
+ ],
+ ),
+ )
+ : Padding(
+ padding: EdgeInsets.only(top: index > 1 ? 20 : 0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _AgentPreview(
+ app: app,
+ item: agents[index - 1],
+ compact: true,
+ ),
+ if (index < agents.length)
+ const Padding(
+ padding: EdgeInsets.only(top: 20),
+ child: Divider(
+ height: 1,
+ color: Colors.white10,
+ ),
+ ),
+ ],
+ ),
+ ),
+ )
+ : SingleChildScrollView(
+ key: ValueKey('preview-content:${row.id}'),
+ controller: _scroll,
+ padding: EdgeInsets.all(widget.compactHeader ? 16 : 24),
+ child: _AgentPreview(
+ app: app,
+ item: agents.single,
+ dense: widget.compactHeader,
+ ),
+ ),
+ ),
+ ),
+ );
+ },
+ );
+}
+
+const _muted = TextStyle(fontSize: 12, height: 1.5, color: Colors.white54);
+const _body = TextStyle(fontSize: 14, height: 1.6, color: Color(0xffe1e1e4));
+
+class _AgentPreview extends StatelessWidget {
+ const _AgentPreview({
+ required this.app,
+ required this.item,
+ this.compact = false,
+ this.dense = false,
+ });
+ final AppNotifier app;
+ final _PreviewAgent item;
+ final bool compact;
+ final bool dense;
+
+ @override
+ Widget build(BuildContext context) {
+ final (:machine, :agent) = item;
+ final record = app.sessionPreviews.read(
+ app.previewKey(machine.machine.machineId, agent),
+ );
+ final offline =
+ machine.nodeOnline == false ||
+ machine.needsLink ||
+ machine.connectionStatus != ConnectionStatus.connected;
+ final waiting = offline ? null : machine.blockedAgents[agent.id];
+ final working = !offline && machine.processingAgentIds.contains(agent.id);
+ final state = offline
+ ? 'Offline'
+ : waiting != null
+ ? 'Needs you'
+ : working
+ ? 'Working'
+ : 'Idle';
+ final color = offline
+ ? Colors.white38
+ : waiting != null
+ ? const Color(0xffe9bf79)
+ : working
+ ? const Color(0xffadc5eb)
+ : const Color(0xff9abea5);
+ final project = machine.projectOf(agent);
+ final request =
+ working && record?.turnOpen == true && record?.currentRequest != null
+ ? record!.currentRequest
+ : record?.latestRequest;
+ final requestLabel =
+ working && record?.turnOpen == true && record?.currentRequest != null
+ ? 'Current request'
+ : 'Recent request';
+ final activity = working ? record?.liveText : null;
+ final response = record?.response ?? (!working ? record?.liveText : null);
+ final excerpt =
+ waiting?.prompt ??
+ (working ? request ?? activity ?? response : response ?? request);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 2),
+ child: EngineMark(engine: agent.engine, size: compact ? 18 : 22),
+ ),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(
+ agent.name,
+ style: TextStyle(
+ fontSize: compact || dense ? 15 : 20,
+ fontWeight: FontWeight.w600,
+ height: 1.25,
+ ),
+ ),
+ ),
+ if (dense) ...[
+ const SizedBox(width: 10),
+ Text(state, style: TextStyle(fontSize: 11, color: color)),
+ ],
+ ],
+ ),
+ if (!dense) ...[
+ const SizedBox(height: 10),
+ Wrap(
+ spacing: 8,
+ runSpacing: 4,
+ crossAxisAlignment: WrapCrossAlignment.center,
+ children: [
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
+ decoration: BoxDecoration(
+ color: color.withValues(alpha: .08),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ waiting != null
+ ? LucideIcons.hand300
+ : LucideIcons.circle300,
+ size: 10,
+ color: color,
+ ),
+ const SizedBox(width: 5),
+ Text(state, style: TextStyle(fontSize: 11, color: color)),
+ ],
+ ),
+ ),
+ Text(
+ [
+ engineIdentity(
+ agent.engine,
+ displayName: agent.engineDisplayName,
+ ).label,
+ machine.machine.name,
+ ].join(' · '),
+ style: _muted,
+ ),
+ ],
+ ),
+ ],
+ if (compact) ...[
+ const SizedBox(height: 10),
+ Text(
+ _displayText(excerpt ?? 'No recent session text available.'),
+ maxLines: 4,
+ overflow: TextOverflow.ellipsis,
+ style: excerpt == null ? _muted : _body,
+ ),
+ if (project?.name != null)
+ Padding(
+ padding: const EdgeInsets.only(top: 8),
+ child: Text(
+ [project!.name, project.branch].whereType<String>().join(' · '),
+ style: _muted,
+ ),
+ ),
+ ] else ...[
+ SizedBox(height: dense ? 16 : 26),
+ if (waiting != null) ...[
+ Container(
+ width: double.infinity,
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: color.withValues(alpha: .06),
+ border: Border.all(color: color.withValues(alpha: .24)),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ 'Needs your input',
+ style: TextStyle(
+ fontSize: 12,
+ fontWeight: FontWeight.w600,
+ color: color,
+ ),
+ ),
+ const SizedBox(height: 8),
+ Text(_displayText(waiting.prompt), style: _body),
+ if (waiting.options.isNotEmpty) ...[
+ const SizedBox(height: 12),
+ Text(waiting.options.take(6).join(' · '), style: _muted),
+ ],
+ ],
+ ),
+ ),
+ const SizedBox(height: 24),
+ ],
+ if (working) ...[
+ if (request != null) _Section(requestLabel, request),
+ if (record?.earlierRequest case final earlier?)
+ _Section('Earlier request', earlier),
+ if (activity != null) _Section('Latest activity', activity),
+ if (record?.activity case final tool?) _Section('Using tool', tool),
+ if (activity == null && response != null)
+ _Section('Previous response', response),
+ ] else ...[
+ if (response != null)
+ _Section(
+ record?.interrupted == true
+ ? 'Last response · interrupted'
+ : 'Latest response',
+ response,
+ ),
+ if (request != null) _Section('Recent request', request),
+ if (record?.earlierRequest case final earlier?)
+ _Section('Earlier request', earlier),
+ ],
+ if (record?.hasContent != true && waiting == null)
+ const Padding(
+ padding: EdgeInsets.only(bottom: 24),
+ child: Text('No recent session text available.', style: _muted),
+ ),
+ const Divider(height: 1, color: Colors.white10),
+ const SizedBox(height: 16),
+ if (project?.cwd case final cwd?) Text(cwd, style: _muted),
+ if (project?.branch case final branch?)
+ Padding(
+ padding: const EdgeInsets.only(top: 4),
+ child: Row(
+ children: [
+ const Icon(
+ LucideIcons.gitBranch300,
+ size: 12,
+ color: Colors.white54,
+ ),
+ const SizedBox(width: 6),
+ Expanded(child: Text(branch, style: _muted)),
+ ],
+ ),
+ ),
+ if (record?.receivedAt case final at?)
+ Padding(
+ padding: const EdgeInsets.only(top: 8),
+ child: Text(
+ '${offline || record?.unavailable == true ? 'Saved text · ' : ''}Received ${TimeOfDay.fromDateTime(at).format(context)}',
+ style: _muted,
+ ),
+ ),
+ ],
+ ],
+ );
+ }
+}
+
+class _Section extends StatelessWidget {
+ const _Section(this.label, this.text);
+ final String label, text;
+ @override
+ Widget build(BuildContext context) => Padding(
+ padding: const EdgeInsets.only(bottom: 24),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(label, style: _muted.copyWith(fontWeight: FontWeight.w500)),
+ const SizedBox(height: 7),
+ Text(_displayText(text), style: _body),
+ ],
+ ),
+ );
+}
+
+// Plain readable excerpts, not a second transcript renderer. Preserve the words
+// and line breaks; remove only common markdown presentation delimiters.
+String _displayText(String text) => text
+ .replaceAllMapped(RegExp(r'\[([^\]]+)\]\([^\n)]+\)'), (m) => m[1]!)
+ .replaceAll(RegExp(r'^#{1,6}\s+', multiLine: true), '')
+ .replaceAll('**', '')
+ .replaceAll('`', '');
diff --git a/desktop/lib/widgets/swarm_switcher.dart b/desktop/lib/widgets/swarm_switcher.dart
index 1a6da05e9..ff1e6aebd 100644
--- a/desktop/lib/widgets/swarm_switcher.dart
+++ b/desktop/lib/widgets/swarm_switcher.dart
@@ -15,6 +15,7 @@ import '../state/swarm_navigation.dart';
import '../state/swarm_search.dart';
import 'engine_identity.dart';
import 'swarm_icon.dart';
+import 'swarm_search_preview.dart';
Future<SwarmSearchSelection?> showSwarmHistory(
BuildContext context,
@@ -325,10 +326,10 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
void _scrollToSelection() {
if (!_scroll.hasClients || search.rows.isEmpty) return;
final top = 8 + search.cursor * _rowHeight;
- final bottom = top + _rowHeight;
+ final bottom = top + _rowHeight + 8;
final position = _scroll.position;
- final offset = top < position.pixels
- ? top
+ final offset = top - 8 < position.pixels
+ ? top - 8
: bottom > position.pixels + position.viewportDimension
? bottom - position.viewportDimension
: position.pixels;
@@ -374,6 +375,11 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
);
return LayoutBuilder(
builder: (context, constraints) {
+ final compactAction =
+ (constraints.maxWidth >= 800
+ ? constraints.maxWidth / 2
+ : constraints.maxWidth) <
+ 380;
final geometry = (constraints.biggest, _rowHeight);
if (_geometry != geometry) {
_geometry = geometry;
@@ -422,6 +428,7 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
? (search.canAccept, search.actionLabel(row))
: null,
_rowHeight,
+ compactAction,
scale.scale(11),
grid.AppTheme.palette.value,
);
@@ -521,6 +528,7 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
),
child: SwarmSearchActionLabel(
search.actionLabel(row),
+ compact: compactAction,
),
),
)
@@ -537,12 +545,15 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
);
_rowWidgets[row.id] = (
presentation: presentation,
- child: tile,
+ child: MouseRegion(
+ onEnter: (_) => _focusResult(row.id),
+ child: tile,
+ ),
);
if (_rowWidgets.length > 48) {
_rowWidgets.remove(_rowWidgets.keys.first);
}
- return tile;
+ return _rowWidgets[row.id]!.child;
},
),
),
@@ -579,7 +590,33 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
],
),
);
- if (KeymapTheme.of(context) == null) return results;
+ final preview =
+ !search.isCommandMode && search.history == null && selected != null
+ ? SwarmSearchPreview(
+ key: const ValueKey('swarm-search-preview'),
+ search: search,
+ compactHeader: constraints.maxWidth < 800,
+ )
+ : null;
+ final content = preview == null
+ ? results
+ : constraints.maxWidth >= 800
+ ? Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Expanded(flex: 5, child: results),
+ const VerticalDivider(width: 1, color: Colors.white12),
+ Expanded(flex: 5, child: preview),
+ ],
+ )
+ : Column(
+ children: [
+ Expanded(flex: 5, child: results),
+ const Divider(height: 1, color: Colors.white12),
+ Expanded(flex: 6, child: preview),
+ ],
+ );
+ if (KeymapTheme.of(context) == null) return content;
// The early keymap handler owns these keys across the whole picker.
// If unbound, do not fall through to ListTile's default activation or
// directional focus traversal and silently perform the removed action.
@@ -590,7 +627,7 @@ class _SwarmSearchResultsState extends State<SwarmSearchResults> {
SingleActivator(LogicalKeyboardKey.arrowDown): DoNothingIntent(),
SingleActivator(LogicalKeyboardKey.arrowUp): DoNothingIntent(),
},
- child: results,
+ child: content,
);
},
);
@@ -602,9 +639,11 @@ class SwarmSearchActionLabel extends StatelessWidget {
this.label, {
super.key,
this.command = 'picker.accept',
+ this.compact = false,
});
final String label;
final String command;
+ final bool compact;
@override
Widget build(BuildContext context) {
@@ -613,41 +652,45 @@ class SwarmSearchActionLabel extends StatelessWidget {
command,
contextKind: KeymapContext.picker,
);
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Flexible(
- child: Text(
- label,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 11),
- ),
- ),
- if (hint != null) ...[
- const SizedBox(width: 8),
- if (RegExp(r'^[⌃⌥⇧⌘]*↵$').hasMatch(hint)) ...[
- if (hint.length > 1)
- Text(
- hint.substring(0, hint.length - 1),
+ return Semantics(
+ label: compact ? label : null,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (!compact || hint == null)
+ Flexible(
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 11),
),
- const Icon(Icons.keyboard_return, size: 14),
- ] else
- Tooltip(
- message: hint,
- child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 96),
- child: Text(
- hint.replaceAll('↵', 'Return').replaceAll('⇥', 'Tab'),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
+ ),
+ if (hint != null) ...[
+ if (!compact) const SizedBox(width: 8),
+ if (RegExp(r'^[⌃⌥⇧⌘]*↵$').hasMatch(hint)) ...[
+ if (hint.length > 1)
+ Text(
+ hint.substring(0, hint.length - 1),
style: const TextStyle(fontSize: 11),
),
+ const Icon(Icons.keyboard_return, size: 14),
+ ] else
+ Tooltip(
+ message: hint,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 96),
+ child: Text(
+ hint.replaceAll('↵', 'Return').replaceAll('⇥', 'Tab'),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: const TextStyle(fontSize: 11),
+ ),
+ ),
),
- ),
+ ],
],
- ],
+ ),
);
}
}
diff --git a/desktop/test/keymap_runtime_test.dart b/desktop/test/keymap_runtime_test.dart
index d40e55ad9..89208fa09 100644
--- a/desktop/test/keymap_runtime_test.dart
+++ b/desktop/test/keymap_runtime_test.dart
@@ -396,7 +396,7 @@ void main() {
await tester.pump();
expect(
find.byKey(const ValueKey('swarm-search-preview')),
- findsNothing,
+ findsOneWidget,
);
expect(
find.byKey(const ValueKey('swarm-search-preview-toggle')),
diff --git a/desktop/test/search_workspace_test.dart b/desktop/test/search_workspace_test.dart
index 10908b43a..2cdb874ec 100644
--- a/desktop/test/search_workspace_test.dart
+++ b/desktop/test/search_workspace_test.dart
@@ -13,7 +13,7 @@ import 'swarm_state_test.dart' show createApp;
void main() {
for (final native in [false, true]) {
testWidgets(
- 'command and Add pickers own editing without previews (native=$native)',
+ 'command and Add pickers keep editing ownership with session previews (native=$native)',
(tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
@@ -62,6 +62,10 @@ void main() {
isTrue,
);
expect(focus.hasFocus, isTrue);
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsNothing,
+ );
await key(tester, LogicalKeyboardKey.escape);
expect(field, findsNothing);
await key(tester, LogicalKeyboardKey.keyO, cmd: true);
@@ -69,7 +73,7 @@ void main() {
await tester.pump();
expect(
find.byKey(const ValueKey('swarm-search-preview')),
- findsNothing,
+ findsOneWidget,
);
expect(find.textContaining('Private terminal output'), findsNothing);
final results = tester.getRect(
@@ -78,7 +82,7 @@ void main() {
final picker = tester.getRect(
find.byKey(const ValueKey('swarm-search-results')),
);
- expect(results.width, closeTo(picker.width, 2));
+ expect(results.width, lessThan(picker.width));
expect(tester.widget<TextField>(field).focusNode!.hasFocus, isTrue);
expect(input, isEmpty);
await key(tester, LogicalKeyboardKey.escape);
diff --git a/desktop/test/swarm_search_preview_test.dart b/desktop/test/swarm_search_preview_test.dart
index f8511c88b..82738da85 100644
--- a/desktop/test/swarm_search_preview_test.dart
+++ b/desktop/test/swarm_search_preview_test.dart
@@ -1,20 +1,95 @@
+import 'dart:io';
+import 'dart:ui' as ui;
+
import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
import 'package:harness/widgets/swarm_switcher.dart';
import 'swarm_interactions_test.dart' show chord;
import 'swarm_screen_test.dart' show mount, terminal;
import 'swarm_state_test.dart' show createApp;
+import 'support/real_fonts.dart';
+
+Future<void> seedPreviews(AppNotifier app) async {
+ final machine = app.machineStates['m']!;
+ machine.nodeOnline = true;
+ machine.connectionStatus = ConnectionStatus.connected;
+ machine.agents = [
+ for (final (id, name, engine) in [
+ ('a0', 'Checkout retries', 'codex'),
+ ('a1', 'Search experience', 'claude'),
+ ('a2', 'Workspace sync', 'codex'),
+ ])
+ Agent(
+ id: id,
+ sessionId: 'session-$id',
+ name: name,
+ engine: engine,
+ terminalAvailable: true,
+ project: AgentProject(
+ name: id == 'a0' ? 'storefront' : 'workbench',
+ cwd: '/work/${id == 'a0' ? 'storefront' : 'workbench'}',
+ branch: 'feat/${id == 'a0' ? 'safe-retries' : 'search'}',
+ ),
+ ),
+ ];
+ Future<void> event(String id, String type, Map<String, dynamic> payload) =>
+ app.handleEventForTest('m', {
+ 'type': type,
+ 'payload': {'agentId': id, 'sessionId': 'session-$id', ...payload},
+ });
+ await event('a0', 'turn_started', {
+ 'userMessage':
+ 'Prevent duplicate charges when a checkout request is retried.',
+ });
+ await event('a0', 'text_delta', {
+ 'content': 'Payment retries now reuse the same idempotency key.\n\n**Verified**\n- A timed-out checkout can be retried safely.\n- The original receipt is preserved.\n- All 24 payment tests pass.',
+ });
+ await event('a0', 'turn_ended', {});
+ await event('a1', 'turn_started', {
+ 'userMessage': 'Show the current task and latest result when selecting a workspace. Keep keyboard navigation fast.',
+ });
+ await event('a1', 'text_delta', {
+ 'content': 'The cached preview is connected. I’m checking keyboard focus and resizing at narrow window widths.',
+ });
+ await event('a1', 'tool_start', {'tool': 'Read'});
+ await event('a2', 'turn_started', {
+ 'userMessage': 'Keep shared workspaces in sync across both machines.',
+ });
+ await event('a2', 'commander_question', {
+ 'requestId': 'q',
+ 'questions': [
+ {
+ 'q': 'Should a workspace reopen its last layout on another machine?',
+ 'options': ['Restore the layout', 'Start with one pane'],
+ },
+ ],
+ });
+}
void main() {
+ setUpAll(() async {
+ await loadRealFonts();
+ await (FontLoader(
+ 'MaterialIcons',
+ )..addFont(rootBundle.load('fonts/MaterialIcons-Regular.otf'))).load();
+ await (FontLoader('packages/lucide_icons_flutter/Lucide')..addFont(
+ rootBundle.load('packages/lucide_icons_flutter/assets/lucide.ttf'),
+ ))
+ .load();
+ });
for (final inline in [false, true]) {
testWidgets(
- 'agent and group results use a single list without previews (inline=$inline)',
+ 'existing content previews are immediate and preserve search focus (inline=$inline)',
(tester) async {
final app = createApp();
+ await seedPreviews(app);
app.adoptSessionForTest(
- terminal('a0', [])..terminal.write('Output belongs in the terminal'),
+ terminal('a69', [])..terminal.write('Raw terminal noise'),
);
app.newSwarm();
await mount(tester, app);
@@ -26,36 +101,130 @@ void main() {
} else {
await chord(tester, LogicalKeyboardKey.keyO);
}
- for (final query in ['Agent 0', 'Test host']) {
- await tester.enterText(field, query);
- await tester.pump();
- final search = tester
- .widget<SwarmSearchResults>(find.byType(SwarmSearchResults))
- .search;
- expect(search.rows, isNotEmpty);
- expect(
- find.byKey(const ValueKey('swarm-search-preview')),
- findsNothing,
- );
- expect(
- find.textContaining('Output belongs in the terminal'),
- findsNothing,
- );
- final list = tester.getRect(
- find.byKey(const ValueKey('swarm-search-result-list')),
- );
- final surface = tester.getRect(
- find.byKey(
- ValueKey(
- inline ? 'harness-start-results' : 'swarm-search-results',
- ),
- ),
- );
- expect(list.width, closeTo(surface.width, 2));
- }
+ await tester.enterText(field, 'Checkout retries');
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsOneWidget,
+ );
+ expect(
+ find.textContaining('Payment retries now reuse'),
+ findsOneWidget,
+ );
+ expect(find.text('Latest response'), findsOneWidget);
+ expect(find.textContaining('Raw terminal noise'), findsNothing);
+ final editor = tester.widget<EditableText>(
+ find.descendant(of: field, matching: find.byType(EditableText)),
+ );
+ expect(editor.focusNode.hasFocus, isTrue);
+ final list = tester.getRect(
+ find.byKey(const ValueKey('swarm-search-result-list')),
+ );
+ final preview = tester.getRect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ );
+ expect(preview.left, greaterThanOrEqualTo(list.right));
+
+ await tester.enterText(field, 'Search experience');
+ await tester.pump();
+ expect(find.text('Current request'), findsOneWidget);
+ expect(
+ find.textContaining('The cached preview is connected'),
+ findsOneWidget,
+ );
+ expect(find.textContaining('Payment retries now reuse'), findsNothing);
+ expect(editor.focusNode.hasFocus, isTrue);
+ await app.handleEventForTest('m', {
+ 'type': 'text_delta',
+ 'payload': {
+ 'agentId': 'a1',
+ 'sessionId': 'session-a1',
+ 'content': 'The current selection updates immediately.',
+ },
+ });
+ await tester.pump(const Duration(milliseconds: 80));
+ expect(
+ find.text('The current selection updates immediately.'),
+ findsOneWidget,
+ );
+ expect(editor.focusNode.hasFocus, isTrue);
+
+ await tester.enterText(field, 'Test host');
+ await tester.pump();
+ final search = tester
+ .widget<SwarmSearchResults>(find.byType(SwarmSearchResults))
+ .search;
+ expect(search.selected!.agentId, isNull);
+ final waiting = tester.getTopLeft(find.text('Workspace sync').last);
+ final working = tester.getTopLeft(find.text('Search experience').last);
+ expect(waiting.dy, lessThan(working.dy));
+ expect(
+ find.text(
+ 'Should a workspace reopen its last layout on another machine?',
+ ),
+ findsOneWidget,
+ );
+
+ await tester.enterText(field, 'Checkout retries');
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(app.panes.any((pane) => pane.agentId == 'a0'), isTrue);
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsNothing,
+ );
await tester.pumpWidget(const SizedBox());
app.dispose();
},
);
}
+
+ for (final size in [
+ const Size(1280, 800),
+ const Size(760, 650),
+ const Size(400, 600),
+ ]) {
+ testWidgets('preview remains readable and scrollable at $size', (
+ tester,
+ ) async {
+ final app = createApp();
+ await seedPreviews(app);
+ app.adoptSessionForTest(terminal('a69', []));
+ await mount(tester, app);
+ tester.view.physicalSize = size;
+ await tester.pump();
+ await chord(tester, LogicalKeyboardKey.keyO);
+ await tester.enterText(
+ find.byKey(const ValueKey('swarm-search-input')),
+ 'Checkout',
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ expect(tester.takeException(), isNull);
+ final preview = tester.getRect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ );
+ final list = tester.getRect(
+ find.byKey(const ValueKey('swarm-search-result-list')),
+ );
+ if (size.width < 864) {
+ expect(preview.top, greaterThanOrEqualTo(list.bottom));
+ }
+ final directory = Platform.environment['HARNESS_PREVIEW_CAPTURE_DIR'];
+ if (directory != null) {
+ final renderView = tester.binding.renderViews.first;
+ final layer = renderView.debugLayer! as OffsetLayer;
+ await tester.runAsync(() async {
+ final image = await layer.toImage(Offset.zero & size);
+ final data = await image.toByteData(format: ui.ImageByteFormat.png);
+ await Directory(directory).create(recursive: true);
+ await File('$directory/preview-${size.width.toInt()}.png')
+ .writeAsBytes(data!.buffer.asUint8List());
+ image.dispose();
+ });
+ }
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ });
+ }
}
diff --git a/desktop/test/swarm_search_render_test.dart b/desktop/test/swarm_search_render_test.dart
index 0f64516a2..430dc8ff8 100644
--- a/desktop/test/swarm_search_render_test.dart
+++ b/desktop/test/swarm_search_render_test.dart
@@ -126,7 +126,7 @@ void main() {
}
testWidgets(
- 'reopening Add reuses catalog work and resets choices without showing output',
+ 'reopening Add reuses the catalog and previews without reading terminal output',
(tester) async {
final app = createApp();
final machine = _CatalogMachine(app.machineStates['m']!.machine)
@@ -150,7 +150,10 @@ void main() {
final first = inputWidget().search!;
final oldRow = first.selected!;
expect(oldRow.agentId, 'a0');
- expect(find.byKey(const ValueKey('swarm-search-preview')), findsNothing);
+ expect(
+ find.byKey(const ValueKey('swarm-search-preview')),
+ findsOneWidget,
+ );
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
@@ -163,7 +166,11 @@ void main() {
final next = inputWidget().search!;
expect(find.textContaining('Newest useful output.'), findsNothing);
expect(next.selected, same(oldRow));
- expect(machine.projectReads, 0, reason: 'Agent metadata did not change');
+ expect(
+ machine.projectReads,
+ lessThan(12),
+ reason: 'Only visible preview members read metadata; the catalog remains cached.',
+ );
expect(input, isEmpty);
await tester.pumpWidget(const SizedBox());
app.dispose();
diff --git a/desktop/test/ws_readiness_test.dart b/desktop/test/ws_readiness_test.dart
index 8d54b57ee..e7fd7f466 100644
--- a/desktop/test/ws_readiness_test.dart
+++ b/desktop/test/ws_readiness_test.dart
@@ -180,11 +180,18 @@ void main() {
await load;
expect(machine.terminalCapabilityAvailable, isTrue);
expect(app.panes, isEmpty);
+ await hub.receive('agent_recent');
expect(hub.frames.map((f) => f['type']), [
'machine_select',
'terminal_capabilities',
'agents_list',
+ 'agent_recent',
]);
+ await hub.reply('agent_recent', {
+ 'agentId': 'a',
+ 'events': [],
+ 'asks': [],
+ });
},
);
diff --git a/docs/harness-agent-first-tabs.md b/docs/harness-agent-first-tabs.md
index 81990b318..6bdf1f701 100644
--- a/docs/harness-agent-first-tabs.md
+++ b/docs/harness-agent-first-tabs.md
@@ -9,7 +9,7 @@ proposals in the progress log.
**Cmd-T / New Tab** and the tab-bar plus open the Harness start page. Its solid
background matches the selected tab. The centered title and search controls sit
-lower with generous empty space. The field is no wider than 640 logical pixels,
+lower with generous empty space. The resting field is no wider than 640 logical pixels,
with **Open Harness** and accented **+ New Harness** buttons underneath.
The field starts empty and focused so typing works immediately. Typing, clicking
@@ -63,6 +63,25 @@ also work immediately after opening the menu, before its first frame.
The Open popup keeps its full-width **Find a harness** field, single-choice
results and 90% black backdrop. Only the highlighted row shows **Open Harness**,
**Open N Harnesses**, or **Split right/down**, depending on context.
+Both Open and inline start-page search show the same session preview. The open
+surface can grow to 1120 logical pixels, placing the list and preview side by
+side. Narrow windows stack them with a compact preview heading. Both sections
+scroll independently; the start-page actions stay reachable. Hover selects a
+preview without taking typing focus. Enter opens the highlighted result.
+
+Working sessions lead with the current observed request and latest activity.
+Idle sessions lead with an existing saved response or the latest response seen
+in the live stream. Pending questions appear prominently. Recent requests and
+saved responses without a shared turn identity are labeled separately; old
+responses never masquerade as the current turn's answer. Groups show readable
+member excerpts, waiting first, and build only visible members. Offline content
+is labeled as saved; missing content stays explicit.
+
+No previews generate summaries or start models. The bounded shared cache uses
+only existing `agent_recent` content and ordinary session events. It does not
+read full histories or attach terminals. Arrow selection reads cached records;
+background refresh fills cold records without blocking editing. Details and
+limits are recorded in [the preview design](harness-search-preview.md).
Secondary text is **project · branch · machine**, with one small muted Git branch
mark immediately before the branch in search and pane headers. Missing metadata is omitted
and the containing workspace name is not repeated.
diff --git a/docs/harness-search-preview.md b/docs/harness-search-preview.md
index 6950bef30..3c6d5c470 100644
--- a/docs/harness-search-preview.md
+++ b/docs/harness-search-preview.md
@@ -1,8 +1,8 @@
# A useful Harness search preview
-The user has approved building this preview. First establish useful real content,
-then implement the shared UI and cache; the earlier content-quality requirement
-still applies. This document records the proposed design and its acceptance bar.
+Both Open Harness and inline start-page search now display existing session
+content in a shared preview. This document records the content rules, data path,
+and remaining coverage limits.
**Content rule:** never generate a summary or start a model for previews. Display
only text and metadata already available from the session.
@@ -52,7 +52,7 @@ Missing the original request made even a meaningful final line hard to interpret
This was a content-selection and coverage problem, as well as a presentation one.
Making that same tail larger would not reliably fix it.
-## The content I recommend
+## Content selection
For an individual harness, show the latest substantive request and its latest
meaningful response or result. Put a pending question prominently when the agent
@@ -96,8 +96,9 @@ Relevant code: [desktop search](../desktop/lib/state/swarm_search.dart),
[session/recent APIs](../cli/src/backendSocket.ts), and
[commander history](../cli/src/lib/commander.ts).
-We have enough foundation to investigate this seriously. We have not established
-that every selectable harness already has a complete, useful preview record.
+The read-only audit established useful content for several existing sessions,
+but not every selectable harness has a complete preview record. An empty session
+or older daemon can still supply no readable excerpt.
## How it can feel immediate
@@ -120,7 +121,7 @@ An uncached remote session still needs time to supply fresh content. Show availa
context immediately and fill the missing content in asynchronously. Literal zero
latency for a cold remote fetch is not achievable; fast local selection is.
-## Before implementing the UI
+## Content audit and validation
Review actual candidate records for active, idle, waiting, tool-heavy, newly
created, unopened, and offline/remote harnesses across the major engines. Include
@@ -132,6 +133,8 @@ do, use those real examples to decide how much preview space is needed. Then
implement the cached-content path and verify correct identity, freshness, and
responsive selection. A good-looking empty panel is not an acceptance criterion.
-Implementation is now authorized and in progress; these notes alone are not
-evidence of completed UI or measured latency. See the
+The shared responsive UI and cache have been implemented. Focused checks cover
+working and idle content, waiting groups, keyboard focus, session identity,
+bounded fetching, offline retention and widths from 400 to 1280 logical pixels.
+These are correctness checks, not native latency measurements. See the
[Rex study](mitchellh-rex-study.md) for the related workspace and continuity lessons.