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.

refactor(web): the picker wears desktop's own scopes and close

Dev jacob50ec88e735fa
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.md
index 7d8135028..48ba58208 100644
--- a/desktop/CLAUDE.md
+++ b/desktop/CLAUDE.md
@@ -110,7 +110,7 @@ desktop keeps in native menus or chords must be clickable. Keys keep working but
advertised. Browser-only UI lives in `lib/web/` and is never imported by desktop code;
it plugs into shared screens through additive seams whose default is today's desktop
behavior (e.g. `SwarmScreen.chrome` / `WorkspaceChrome` in `state/workspace_chrome.dart`,
-which runs the same `_commands` table keys use, adds a bar over the picker, and turns off
+which runs the same `_commands` table keys use, gives the picker a clickable Back, and turns off
`KeyHints` — `widgets/key_hints.dart`, absent means hints shown). Below
`WorkspaceChrome.compactBelow` (web: 720px, a phone) the workspace goes compact: a tab
switcher replaces the tab row, `WorkspaceChrome.compactFooter` replaces the status bar with one
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 77a2e209c..fc8784ba9 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -5540,14 +5540,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
onClose: _dismissSearch,
onRefocus: _focusSearch,
previewBuilder: preview,
- hostBar: widget.chrome?.pickerBar?.call(
- context,
- WorkspacePicker(
- search: search,
- focus: _focusSearch,
- close: _dismissSearch,
- ),
- ),
+ showsBack: widget.chrome?.pickerShowsBack ?? false,
);
final scoped = Semantics(
scopesRoute: true,
diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dart
index 88a94a69e..c27e009c6 100644
--- a/desktop/lib/state/workspace_chrome.dart
+++ b/desktop/lib/state/workspace_chrome.dart
@@ -1,7 +1,5 @@
import 'package:flutter/widgets.dart';
-import 'swarm_search.dart';
-
/// The workspace's command table as a host composition sees it: the same ids
/// and callbacks keys, native menus and the command box already run.
class WorkspaceCommands {
@@ -17,22 +15,6 @@ class WorkspaceCommands {
final void Function(String id) run;
}
-/// The open picker as a host composition's bar sees it: its search, and the
-/// same focus and close the picker's own keys use.
-class WorkspacePicker {
- const WorkspacePicker({
- required this.search,
- required this.focus,
- required this.close,
- });
-
- final SwarmSearchController search;
-
- /// Hands typing back to the picker's input after a click.
- final VoidCallback focus;
- final VoidCallback close;
-}
-
/// One entry of the workspace footer as a host composition sees it: what it
/// names, what it currently reads, and the same action its footer link runs.
class WorkspaceFooterItem {
@@ -74,7 +56,7 @@ class WorkspaceChrome {
required this.leadingWidth,
required this.leading,
this.newHarnessMachine,
- this.pickerBar,
+ this.pickerShowsBack = false,
this.showsKeyHints = true,
this.viewMachineCloses = false,
this.showsShareStatus = false,
@@ -92,9 +74,8 @@ class WorkspaceChrome {
/// runs none. Null (or no answer) keeps sending the person to Machines.
final String? Function()? newHarnessMachine;
- /// A row above the picker's input, e.g. clickable scopes and Back.
- final Widget Function(BuildContext context, WorkspacePicker picker)?
- pickerBar;
+ /// True gives the picker a clickable Back out of an open machine or project.
+ final bool pickerShowsBack;
/// False hides keyboard hints inside the workspace's pickers ([KeyHints]).
final bool showsKeyHints;
diff --git a/desktop/lib/web/picker/web_picker_bar.dart b/desktop/lib/web/picker/web_picker_bar.dart
deleted file mode 100644
index 4db7e1ca0..000000000
--- a/desktop/lib/web/picker/web_picker_bar.dart
+++ /dev/null
@@ -1,81 +0,0 @@
-import 'package:flutter/material.dart';
-
-import '../../shared/theme/app_icons.dart';
-import '../../shared/widgets/app_icon_button.dart';
-import '../../state/workspace_chrome.dart';
-import '../../widgets/desktop_chrome.dart';
-import 'web_picker_scopes.dart';
-
-/// The row over the picker's input: Back out of a scope, the scopes the
-/// prefix keys reach, and close — each a click instead of a key. Scopes are
-/// the design system's compact scope pills (design/desktop-design-system.md).
-class WebPickerBar extends StatelessWidget {
- const WebPickerBar({super.key, required this.picker});
-
- final WorkspacePicker picker;
-
- /// Lines the first pill up with the search field's text, past its icon.
- static const _fieldTextInset = 57.0;
-
- @override
- Widget build(BuildContext context) {
- final search = picker.search;
- return ListenableBuilder(
- listenable: search,
- builder: (context, _) => Padding(
- key: const ValueKey('web-picker-bar'),
- padding: const EdgeInsets.fromLTRB(
- _fieldTextInset,
- DesktopChrome.controlGap + 4,
- DesktopChrome.controlGap,
- 0,
- ),
- child: Row(
- children: [
- if (search.canGoBack) ...[
- DesktopPill(
- key: const ValueKey('web-picker-back'),
- label: 'Back',
- leading: const Icon(AppIcons.chevronLeft, size: 14),
- quiet: true,
- compact: true,
- onPressed: () {
- if (search.back()) picker.focus();
- },
- ),
- const SizedBox(width: DesktopChrome.controlGap),
- ],
- Expanded(
- child: Wrap(
- spacing: 6,
- runSpacing: 6,
- children: [
- for (final scope in webPickerScopes(search))
- DesktopPill(
- key: ValueKey('web-picker-scope:${scope.prefix}'),
- label: scope.label,
- compact: true,
- selected:
- !search.isHelpMode &&
- search.scopePrefix == scope.prefix,
- onPressed: () {
- search.setQuery(webPickerQuery(scope));
- picker.focus();
- },
- ),
- ],
- ),
- ),
- AppIconButton(
- key: const ValueKey('web-picker-close'),
- icon: AppIcons.close,
- tooltip: 'Close',
- size: 16,
- onPressed: picker.close,
- ),
- ],
- ),
- ),
- );
- }
-}
diff --git a/desktop/lib/web/picker/web_picker_scopes.dart b/desktop/lib/web/picker/web_picker_scopes.dart
deleted file mode 100644
index 3ef60c90f..000000000
--- a/desktop/lib/web/picker/web_picker_scopes.dart
+++ /dev/null
@@ -1,27 +0,0 @@
-import '../../state/swarm_search.dart';
-
-/// One clickable scope of the picker: the query prefix a key would type, and
-/// what the scope lists.
-typedef WebPickerScope = ({String prefix, String label});
-
-/// The scopes the picker's `@ # : * >` prefixes reach, in their hint order.
-const List<WebPickerScope> kWebPickerScopes = [
- (prefix: '', label: 'Agents'),
- (prefix: '@', label: 'Machines'),
- (prefix: '#', label: 'Projects'),
- (prefix: ':', label: 'Models'),
- (prefix: '*', label: 'Store'),
- (prefix: '>', label: 'Commands'),
-];
-
-/// The scopes this picker offers: Commands only where it has commands.
-List<WebPickerScope> webPickerScopes(SwarmSearchController search) => [
- for (final scope in kWebPickerScopes)
- if (scope.prefix != '>' || search.commands != null) scope,
-];
-
-/// The query a click types for [scope] — what its key would have typed.
-String webPickerQuery(WebPickerScope scope) =>
- scope.prefix.isEmpty || scope.prefix == '>'
- ? scope.prefix
- : '${scope.prefix} ';
diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dart
index 635cce188..a62868bc1 100644
--- a/desktop/lib/web/shell/web_chrome.dart
+++ b/desktop/lib/web/shell/web_chrome.dart
@@ -1,14 +1,13 @@
import '../../state/app_state.dart';
import '../../state/workspace_chrome.dart';
import '../footer/web_footer_bar.dart';
-import '../picker/web_picker_bar.dart';
import '../tabs/web_tab_switcher.dart';
import 'web_app_menu.dart';
import 'web_layout.dart';
import 'web_machine_choice.dart';
/// Everything the browser adds to the shared workspace: a menu before the
-/// tabs, a tab switcher and a one-dropdown footer on narrow screens, a clickable bar over the picker
+/// tabs, a tab switcher and a one-dropdown footer on narrow screens, a clickable Back in the picker
/// with its key hints hidden, and a connected machine for New Harness, since
/// a browser is not a machine.
WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
@@ -16,7 +15,7 @@ WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
leading: (context, commands) =>
WebAppMenuButton(app: app, commands: commands),
newHarnessMachine: () => webNewHarnessMachine(app),
- pickerBar: (context, picker) => WebPickerBar(picker: picker),
+ pickerShowsBack: true,
showsKeyHints: false,
viewMachineCloses: true,
showsShareStatus: true,
diff --git a/desktop/lib/widgets/desktop_search_panel.dart b/desktop/lib/widgets/desktop_search_panel.dart
index 2b212f5e4..7058e2148 100644
--- a/desktop/lib/widgets/desktop_search_panel.dart
+++ b/desktop/lib/widgets/desktop_search_panel.dart
@@ -26,7 +26,7 @@ class DesktopSearchPanel extends StatelessWidget {
required this.onClose,
required this.onRefocus,
required this.previewBuilder,
- this.hostBar,
+ this.showsBack = false,
});
final SwarmSearchController search;
@@ -35,7 +35,10 @@ class DesktopSearchPanel extends StatelessWidget {
final ValueChanged<SwarmSearchSelection> onChoose;
final VoidCallback onClose, onRefocus;
final Widget Function() previewBuilder;
- final Widget? hostBar;
+
+ /// True puts a clickable Back before the scopes while a machine or project
+ /// is open — the click for what Escape does.
+ final bool showsBack;
static const maxWidth = 1120.0;
static const maxHeight = 680.0;
@@ -78,7 +81,6 @@ class DesktopSearchPanel extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- ?hostBar,
if (search.split != null)
Padding(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 0),
@@ -154,37 +156,51 @@ class DesktopSearchPanel extends StatelessWidget {
),
),
),
- if (hostBar == null)
- _toolbarButton(
- context,
- key: const ValueKey('search-close'),
- tooltip: 'Close search',
- onPressed: onClose,
- icon: const Icon(AppIcons.close, size: 18),
- ),
+ _toolbarButton(
+ context,
+ key: const ValueKey('search-close'),
+ tooltip: 'Close search',
+ onPressed: onClose,
+ icon: const Icon(AppIcons.close, size: 18),
+ ),
],
),
),
- if (hostBar == null)
- ListenableBuilder(
- listenable: search,
- builder: (context, _) => SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- padding: const EdgeInsets.fromLTRB(20, 2, 20, 14),
- child: _SearchScopes(
- selected: _prefix,
- onRefocus: onRefocus,
- onChanged: (prefix) {
- final words = search.wordsQuery;
- search.setQuery(
- prefix.isEmpty
- ? words
- : '$prefix $words'.trimRight(),
- );
- },
- ),
+ ListenableBuilder(
+ listenable: search,
+ builder: (context, _) => SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ padding: const EdgeInsets.fromLTRB(20, 2, 20, 14),
+ child: Row(
+ spacing: 6,
+ children: [
+ if (showsBack && search.canGoBack)
+ DesktopPill(
+ key: const ValueKey('search-back'),
+ label: 'Back',
+ leading: const Icon(AppIcons.chevronLeft, size: 14),
+ capsule: true,
+ quiet: true,
+ onPressed: () {
+ if (search.back()) onRefocus();
+ },
+ ),
+ _SearchScopes(
+ selected: _prefix,
+ onRefocus: onRefocus,
+ onChanged: (prefix) {
+ final words = search.wordsQuery;
+ search.setQuery(
+ prefix.isEmpty
+ ? words
+ : '$prefix $words'.trimRight(),
+ );
+ },
+ ),
+ ],
),
),
+ ),
Flexible(
child: ListenableBuilder(
listenable: search,
diff --git a/desktop/test/web/web_picker_test.dart b/desktop/test/web/web_picker_test.dart
index 82248c4fe..3b12eb395 100644
--- a/desktop/test/web/web_picker_test.dart
+++ b/desktop/test/web/web_picker_test.dart
@@ -50,12 +50,12 @@ Future<void> _tap(WidgetTester tester, String key) async {
void main() {
testWidgets('scopes switch by click, without prefix keys', (tester) async {
final app = await _mount(tester);
- expect(find.byKey(const ValueKey('web-picker-bar')), findsOneWidget);
- await _tap(tester, 'web-picker-scope:@');
+ // The desktop picker's own scopes: the browser adds no second row.
+ await _tap(tester, 'search-category-Machines');
expect(_search(tester).scopePrefix, '@');
- await _tap(tester, 'web-picker-scope::');
+ await _tap(tester, 'search-category-Models');
expect(_search(tester).scopePrefix, ':');
- await _tap(tester, 'web-picker-scope:');
+ await _tap(tester, 'search-category-Harnesses');
expect(_search(tester).scopePrefix, '');
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
@@ -66,13 +66,13 @@ void main() {
tester,
) async {
final app = await _mount(tester);
- await _tap(tester, 'web-picker-scope:@');
+ await _tap(tester, 'search-category-Machines');
final search = _search(tester);
- expect(find.byKey(const ValueKey('web-picker-back')), findsNothing);
+ expect(find.byKey(const ValueKey('search-back')), findsNothing);
expect(search.scopeToGroup('machine:remote-box'), isTrue);
await tester.pump(const Duration(milliseconds: 100));
expect(search.canGoBack, isTrue);
- await _tap(tester, 'web-picker-back');
+ await _tap(tester, 'search-back');
expect(search.canGoBack, isFalse);
expect(search.scopePrefix, '@');
// A selected machine shows its actions, not "Enter select · Esc back".
@@ -85,7 +85,7 @@ void main() {
testWidgets('the close button dismisses the picker', (tester) async {
final app = await _mount(tester);
- await _tap(tester, 'web-picker-close');
+ await _tap(tester, 'search-close');
await tester.pump(const Duration(milliseconds: 200));
expect(find.byType(SwarmSearchResults), findsNothing);
expect(tester.takeException(), isNull);
diff --git a/desktop/test/web_picker_layout_test.dart b/desktop/test/web_picker_layout_test.dart
deleted file mode 100644
index a1cef5fe5..000000000
--- a/desktop/test/web_picker_layout_test.dart
+++ /dev/null
@@ -1,105 +0,0 @@
-import 'dart:io';
-import 'dart:ui' as ui;
-
-import 'package:flutter/material.dart';
-import 'package:flutter/rendering.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:harness/auth/auth_session.dart';
-import 'package:harness/core/config.dart';
-import 'package:harness/core/models.dart';
-import 'package:harness/screens/swarm_screen.dart';
-import 'package:harness/shared/theme/app_theme.dart' as grid;
-import 'package:harness/state/app_state.dart';
-import 'package:harness/web/picker/web_picker_scopes.dart';
-import 'package:harness/web/shell/web_chrome.dart';
-
-import 'support/real_fonts.dart';
-
-/// The web picker bar, laid out with real fonts: a regression here once
-/// stacked every scope on a centered line of its own.
-void main() {
- setUpAll(loadRealFonts);
-
- testWidgets('picker scopes sit on one row, left to right', (tester) async {
- final app = AppNotifier(
- config: AppConfig.dev,
- authSession: AuthSession(),
- configStore: null,
- )..newSwarm(newTabPage: true);
- const machine = Machine(
- machineId: 'remote-box',
- name: 'harness-remote-box',
- authMode: MachineAuthMode.remote,
- );
- app.machines.add(machine);
- app.machineStates['remote-box'] = MachineState(machine)
- ..nodeOnline = true
- ..needsLink = true;
- final boundary = GlobalKey();
- tester.view.devicePixelRatio = 1;
- tester.view.physicalSize = const Size(1440, 800);
- addTearDown(tester.view.reset);
- await tester.pumpWidget(
- RepaintBoundary(
- key: boundary,
- child: MaterialApp(
- theme: grid.buildAppTheme(brightness: Brightness.dark),
- home: SwarmScreen(
- notifier: app,
- nativeTabs: false,
- chrome: webWorkspaceChrome(app),
- ),
- ),
- ),
- );
- await tester.pump(const Duration(milliseconds: 200));
- await tester.tap(find.byKey(const ValueKey('swarm-search-button')));
- await tester.pump(const Duration(milliseconds: 200));
- await tester.tap(find.byKey(const ValueKey('web-picker-scope:@')));
- await tester.pump(const Duration(milliseconds: 200));
-
- final rects = [
- for (final scope in kWebPickerScopes)
- tester.getRect(
- find.byKey(ValueKey('web-picker-scope:${scope.prefix}')),
- ),
- ];
- final close = tester.getRect(
- find.byKey(const ValueKey('web-picker-close')),
- );
- for (final rect in [...rects, close]) {
- expect(rect.center.dy, moreOrLessEquals(rects.first.center.dy));
- }
- for (var i = 1; i < rects.length; i++) {
- expect(rects[i].left, greaterThan(rects[i - 1].right));
- }
- // The bar starts where the input's text does.
- expect(
- rects.first.left,
- moreOrLessEquals(
- tester.getRect(find.byKey(const ValueKey('swarm-search-input'))).left,
- epsilon: 1,
- ),
- );
- // Each scope hugs its label rather than taking the row.
- expect(rects.first.width, lessThan(120));
- expect(tester.takeException(), isNull);
-
- final output = Platform.environment['HARNESS_REFINEMENT_CAPTURE_DIR'];
- if (output != null) {
- await tester.runAsync(() async {
- final image =
- await (boundary.currentContext!.findRenderObject()
- as RenderRepaintBoundary)
- .toImage();
- final data = await image.toByteData(format: ui.ImageByteFormat.png);
- Directory(output).createSync(recursive: true);
- File('$output/web-picker-bar.png')
- .writeAsBytesSync(data!.buffer.asUint8List());
- image.dispose();
- });
- }
- await tester.pumpWidget(const SizedBox.shrink());
- app.dispose();
- });
-}
diff --git a/desktop/test/web_picker_scopes_test.dart b/desktop/test/web_picker_scopes_test.dart
deleted file mode 100644
index d0250d8ba..000000000
--- a/desktop/test/web_picker_scopes_test.dart
+++ /dev/null
@@ -1,18 +0,0 @@
-import 'package:flutter_test/flutter_test.dart';
-import 'package:harness/web/picker/web_picker_scopes.dart';
-
-void main() {
- test('a scope click types what its prefix key would', () {
- final queries = {
- for (final scope in kWebPickerScopes) scope.label: webPickerQuery(scope),
- };
- expect(queries, {
- 'Agents': '',
- 'Machines': '@ ',
- 'Projects': '# ',
- 'Models': ': ',
- 'Store': '* ',
- 'Commands': '>',
- });
- });
-}