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.

Stop search work while the start-page picker is dismissed

dee2aaa48a897c4
diff --git a/desktop/lib/state/swarm_search.dart b/desktop/lib/state/swarm_search.dart
index d613a054e..1fe23bfa8 100644
--- a/desktop/lib/state/swarm_search.dart
+++ b/desktop/lib/state/swarm_search.dart
@@ -5,8 +5,8 @@ import 'pane_arrangement.dart';
import 'swarm_catalog.dart';
import 'swarm_navigation.dart';
-/// An in-memory Add draft for a temporary detour into New agent. Membership and
-/// availability are revalidated against a fresh catalog when the picker returns.
+/// Search text and selection retained while the start-page picker is dismissed.
+/// Membership and availability are revalidated against a fresh catalog on return.
class SwarmSearchDraft {
const SwarmSearchDraft._(this.targetId, this.query, this.selectedId);
final String targetId, query;
diff --git a/desktop/lib/widgets/harness_start_page.dart b/desktop/lib/widgets/harness_start_page.dart
index dc26c1a4e..4b8d03e32 100644
--- a/desktop/lib/widgets/harness_start_page.dart
+++ b/desktop/lib/widgets/harness_start_page.dart
@@ -27,19 +27,31 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
final _query = TextEditingController();
final _focus = FocusNode(debugLabel: 'Start page search');
final _searchGroup = Object();
- late final _search = widget.createSearch();
- bool _showResults = false;
+ SwarmSearchController? _search;
+ SwarmSearchDraft? _draft;
+ bool get _showResults => _search != null;
void _open() {
// Commands can replace the editor value without a TextField onChanged.
// Reveal results for the visible text, including on keyboard-only entry.
- _search.setQuery(_query.text);
- if (!_showResults) setState(() => _showResults = true);
+ if (_search == null) {
+ final search = widget.createSearch();
+ if (_draft case final draft?) search.restoreDraft(draft);
+ search.setQuery(_query.text);
+ setState(() => _search = search);
+ } else {
+ _search!.setQuery(_query.text);
+ }
_focus.requestFocus();
}
void _close() {
- if (_showResults) setState(() => _showResults = false);
+ final search = _search;
+ if (search != null) {
+ _draft = search.draft;
+ setState(() => _search = null);
+ search.dispose();
+ }
_focus.unfocus();
}
@@ -55,7 +67,7 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
@override
void dispose() {
- _search.dispose();
+ _search?.dispose();
_query.dispose();
_focus.dispose();
super.dispose();
@@ -112,13 +124,10 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
inputKey: const ValueKey('harness-start-search'),
controller: _query,
focusNode: _focus,
- search: _showResults ? _search : null,
+ search: _search,
onChoose: _choose,
onClose: _close,
- onChanged: (value) {
- _search.setQuery(value);
- _open();
- },
+ onChanged: (_) => _open(),
onOpen: _open,
onNewAgent: _new,
onTapOutside: _close,
@@ -138,7 +147,7 @@ class _HarnessStartPageState extends State<HarnessStartPage> {
),
child: SwarmSearchResults(
key: const ValueKey('harness-start-results'),
- search: _search,
+ search: _search!,
onChoose: _choose,
onRefocus: _focus.requestFocus,
),
diff --git a/desktop/test/harness_start_page_test.dart b/desktop/test/harness_start_page_test.dart
new file mode 100644
index 000000000..d3c243c25
--- /dev/null
+++ b/desktop/test/harness_start_page_test.dart
@@ -0,0 +1,118 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/state/swarm_navigation.dart';
+import 'package:harness/state/swarm_search.dart';
+import 'package:harness/widgets/harness_start_page.dart';
+
+import 'swarm_state_test.dart' show createApp;
+
+final _input = find.byKey(const ValueKey('harness-start-search'));
+final _results = find.byKey(const ValueKey('harness-start-results'));
+
+void main() {
+ testWidgets('unused start page never builds a search catalog', (
+ tester,
+ ) async {
+ final app = createApp();
+ addTearDown(app.dispose);
+ var searches = 0;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: HarnessStartPage(
+ createSearch: () {
+ searches++;
+ return SwarmSearchController(app, [], adding: true);
+ },
+ onNew: () {},
+ onChoose: (_) {},
+ ),
+ ),
+ ),
+ );
+ expect(searches, 0);
+ await tester.pumpWidget(const SizedBox());
+ expect(searches, 0, reason: 'Closing an unused page must not index agents');
+ });
+
+ testWidgets('dismissed search is idle and reopens with current results', (
+ tester,
+ ) async {
+ final app = createApp();
+ addTearDown(app.dispose);
+ var commandReads = 0;
+ var updated = false;
+ String? chosen;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: HarnessStartPage(
+ createSearch: () => SwarmSearchController(
+ app,
+ [],
+ adding: true,
+ commands: () {
+ commandReads++;
+ return [
+ for (final id in ['one', 'two'])
+ SwarmDestination(
+ id: 'command:$id',
+ title: id == 'one'
+ ? updated
+ ? 'Updated command'
+ : 'First command'
+ : 'Second command',
+ detail: 'Commands',
+ swarmId: null,
+ current: false,
+ commandId: id,
+ ),
+ ];
+ },
+ ),
+ onNew: () {},
+ onChoose: (selection) => chosen = selection.destination.id,
+ ),
+ ),
+ ),
+ );
+ await tester.tap(_input);
+ await tester.enterText(_input, '>');
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
+ await tester.pump();
+ final selected = find.byWidgetPredicate(
+ (widget) => widget is ListTile && widget.selected,
+ );
+ expect(
+ find.descendant(of: selected, matching: find.text('Second command')),
+ findsOneWidget,
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ expect(_results, findsNothing);
+ final readsAtDismissal = commandReads;
+ updated = true;
+ app.renameSwarm(app.activeSwarmId, 'Background change');
+ await tester.pump();
+ expect(
+ commandReads,
+ readsAtDismissal,
+ reason: 'A dismissed search must not refresh commands on app updates',
+ );
+ await tester.tap(_input);
+ await tester.pump();
+ expect(tester.widget<TextField>(_input).controller!.text, '>');
+ expect(find.text('Updated command'), findsOneWidget);
+ expect(
+ find.descendant(of: selected, matching: find.text('Second command')),
+ findsOneWidget,
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ expect(chosen, 'command:two');
+ expect(_results, findsNothing);
+ await tester.pumpWidget(const SizedBox());
+ });
+}
diff --git a/docs/harness-agent-first-tabs.md b/docs/harness-agent-first-tabs.md
index 8671f67c9..06f8db7fd 100644
--- a/docs/harness-agent-first-tabs.md
+++ b/docs/harness-agent-first-tabs.md
@@ -16,6 +16,10 @@ The field starts empty and unfocused. Clicking it or Open Harness reveals the
same input, results, highlight, action arrow and keyboard navigation as Cmd-O.
Typing filters immediately; arrows select and Enter opens. Escape or clicking
outside closes the dropdown and hides the caret. The recent-agent list is removed.
+The closed page retains only search text and selection: it does not keep a live
+search subscription or build a catalog when an unused page closes. Reopening
+refreshes results against current app state. Command-mode shortcuts synchronize
+the field and results without adding editor rebuilds to arrow navigation.
A small product image and introduction sit well below the controls and link to
https://www.autonomous.ai/harness-device. The bundled image is the official
product photo from https://cdn.autonomous.ai/production/ecm/260731/2.webp.