The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
desktop: the model picker says what is true and gets out of the way
bitcoinbuilderea1d16ca697e
diff --git a/desktop/lib/core/models.dart b/desktop/lib/core/models.dartindex d94cc5893..63c451a1c 100644--- a/desktop/lib/core/models.dart+++ b/desktop/lib/core/models.dart@@ -498,12 +498,29 @@ class GridModels {/// daemon is older and sends no such list — read as "offer everything", the behaviour before.final Set<String>? localModelEngines;+ /// Did the machine ANSWER? False when the request failed — offline, timed out, or a daemon too+ /// old to know the call.+ ///+ /// Kept apart from `gridName == null` because the two mean opposite things to a person. "This+ /// account has no grid" is a fact worth acting on; "we could not ask" is not a fact about the+ /// account at all, and a UI that folds them together tells a signed-in user to sign in again.+ final bool reachable;+const GridModels({required this.gridName,required this.models,this.localModelEngines,+ this.reachable = true,});+ /// The machine could not be asked. Says nothing about the account, because nothing is known —+ /// including which engines it would have offered.+ const GridModels.unreachable()+ : gridName = null,+ models = const [],+ localModelEngines = null,+ reachable = false;+/// Whether [engine] may be pointed at one of [models]: unknown engines are refused only when the/// daemon gave a list — a picker that guessed would refuse the wrong ones on an older daemon.bool canRunLocally(String? engine) {diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex facf406f0..2391f12e0 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -30,6 +30,7 @@ import '../state/swarm_attention.dart';import '../state/swarm_navigation.dart';import '../state/swarm_search.dart';import '../state/swarm.dart';+import '../widgets/transient_menus.dart';import '../widgets/layout_palette.dart';import '../widgets/engine_identity.dart';import '../widgets/harness_start_page.dart';@@ -507,6 +508,9 @@ class _SwarmScreenState extends State<SwarmScreen> {return;}_closeSearch(restoreFocus: false);+ // Same reason the search field closes: the titlebar is native, so a click on it is not a pointer+ // event any Flutter overlay can see itself.+ dismissTransientMenus();switch (call.method) {case 'new':_newTab();diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 22dd459c0..0849691c3 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -3141,7 +3141,10 @@ class AppNotifier extends ChangeNotifier {: null,);} catch (_) {- return const GridModels(gridName: null, models: []);+ // NOT `gridName: null` with an empty list — that is the shape of "this account has no grid",+ // and a caller cannot tell it from "the machine did not answer". A signed-in user whose daemon+ // was offline was told to sign in again, which was both wrong and unactionable.+ return const GridModels.unreachable();}}diff --git a/desktop/lib/widgets/grid_model_picker.dart b/desktop/lib/widgets/grid_model_picker.dartindex 734f6c8fc..792751228 100644--- a/desktop/lib/widgets/grid_model_picker.dart+++ b/desktop/lib/widgets/grid_model_picker.dart@@ -7,6 +7,7 @@ import '../state/app_state.dart';import '../theme/app_theme.dart';import '../usage/models_menu_controller.dart';import 'engine_identity.dart';+import 'transient_menus.dart';/// The pane header's model picker, in two sections: **Subscription** and **Local**.///@@ -89,8 +90,14 @@ class _GridModelPickerState extends State<GridModelPicker> {if (mounted) _last = answer;}+ /// Closes the menu this control has open, if any. Set while one is showing.+ void Function()? _close;+@overridevoid dispose() {+ // A pane can go away under an open menu — closed, moved, or its swarm switched — and an overlay+ // entry outlives the State that inserted it.+ _close?.call();_usage?.dispose();super.dispose();}@@ -166,19 +173,12 @@ class _GridModelPickerState extends State<GridModelPicker> {);final subscription = _subscriptionRow();- final chosen = await showMenu<_Choice>(- context: context,+ final chosen = await _showMenu(position: position,- color: AppColors.surface,- // Wide enough that a status can sit right-aligned against a model id without the two meeting.- // Wide enough for a full GGUF-style model id beside its node without either being cut.- constraints: const BoxConstraints(minWidth: 340, maxWidth: 540),- items: [+ children: (close) => [_header('Subscription'),- PopupMenuItem<_Choice>(- value: const _Choice.ownLogin(),- height: 32,- padding: EdgeInsets.zero,+ _item(+ onTap: () => close(const _Choice.ownLogin()),child: _Row(selected: widget.currentModel == null,engine: widget.engineLabel,@@ -189,47 +189,23 @@ class _GridModelPickerState extends State<GridModelPicker> {status: subscription?['status'] as String?,),),- const PopupMenuDivider(),+ Divider(height: 9, thickness: 1, color: AppColors.border),_header('Local'),// An engine with no way onto a Local model (Cursor talks only to its own API; the daemon// refuses the move) is told so here, instead of being offered rows whose click would do// nothing. The daemon names the capable engines beside the list; an older daemon names// none, and then every row is offered as before.if (!answer.canRunLocally(widget.engineLabel))- PopupMenuItem<_Choice>(- enabled: false,- height: 30,- padding: const EdgeInsets.only(left: _menuInset + _rowPadding),- child: Text(- '${engineIdentity(widget.engineLabel).label} can only run on its own login.',- style: TextStyle(fontSize: 11, color: AppColors.textSoft),- ),- )- // An empty grid and no grid at all are different facts, and each gets its own sentence: one- // is "nobody is serving yet", the other "there is nothing to serve on". A single "no models"- // would send a person looking in the wrong place.+ _empty('${engineIdentity(widget.engineLabel).label} can only run on its own login.')+ // THREE different facts, three sentences. "We could not ask", "this account has no grid"+ // and "the grid is serving nothing" send a person to three different places, and the one+ // that used to cover two of them told a signed-in user to sign in again.else if (answer.models.isEmpty)- PopupMenuItem<_Choice>(- enabled: false,- height: 30,- padding: const EdgeInsets.only(left: _menuInset + _rowPadding),- child: Text(- // "Local models", in the user's own vocabulary: the grid is how a Local model is- // served, not a thing this menu asks anyone to know about.- answer.gridName == null- ? 'No local models on this account yet — sign in again to set them up.'- : 'Nothing is being served yet.',- style: TextStyle(fontSize: 11, color: AppColors.textSoft),- ),- ),+ _empty(_emptySentence(answer)),if (answer.canRunLocally(widget.engineLabel))for (final model in answer.models)- PopupMenuItem<_Choice>(- value: _Choice.model(model),- // Taller only for the current row carrying a sentence; every other row keeps its- // height so the menu does not grow for a fact about one agent.- height: _subtitleFor(model) != null ? 46 : 32,- padding: EdgeInsets.zero,+ _item(+ onTap: () => close(_Choice.model(model)),child: _Row(selected: widget.currentModel == model.id,title: model.id,@@ -250,12 +226,116 @@ class _GridModelPickerState extends State<GridModelPicker> {if (chosen.model!.id != widget.currentModel) widget.onSelected?.call(chosen.model!);}+ /// What the Local section says when it lists nothing.+ ///+ /// Three states, because they are three different situations and only one of them is about the+ /// account. Folding the first two together is what put "sign in again to set them up" in front of+ /// a signed-in user whose daemon happened to be offline — advice that was wrong, and that would+ /// not have helped even if the diagnosis had been right.+ String _emptySentence(GridModels answer) {+ if (!answer.reachable) return 'Could not reach this machine.';+ if (answer.gridName == null) return 'No local models on this account yet.';+ return 'Nothing is being served yet.';+ }++ /// Show the menu in an OVERLAY rather than as a modal route.+ ///+ /// `showMenu` puts a full-screen modal barrier under its menu, and that barrier EATS the click+ /// that dismisses it: closing the menu and then clicking what you meant to click took two clicks,+ /// with the first one going nowhere. A menu is not a decision you have to finish before the app+ /// will listen again.+ ///+ /// So the dismisser is a translucent [Listener] instead. Translucent hit-test behaviour means it+ /// receives the pointer AND reports no hit, so the overlay below it — the app — is hit-tested next+ /// and gets the same event. One click closes the menu and lands where it was aimed.+ Future<_Choice?> _showMenu({+ required RelativeRect position,+ required List<Widget> Function(void Function(_Choice?) close) children,+ }) {+ final overlayState = Overlay.of(context);+ final completer = Completer<_Choice?>();+ late final OverlayEntry entry;+ late final void Function() deregister;+ var closed = false;+ void close(_Choice? choice) {+ // Guarded: a pointer-down outside and a row tap can both arrive for one gesture, and removing+ // an entry twice throws.+ if (closed) return;+ closed = true;+ deregister();+ entry.remove();+ if (!completer.isCompleted) completer.complete(choice);+ }+ // A click on the window's NATIVE tab strip is not a pointer event Flutter ever sees, so the+ // dismisser below cannot fire for it — the menu was left floating over a tab it no longer+ // belonged to. The titlebar reports its own clicks instead; see [dismissTransientMenus].+ deregister = registerTransientMenu(() => close(null));+ _close = () => close(null);++ entry = OverlayEntry(+ builder: (context) => Stack(+ children: [+ Positioned.fill(+ child: Listener(+ behavior: HitTestBehavior.translucent,+ onPointerDown: (_) => close(null),+ child: const SizedBox.expand(),+ ),+ ),+ Positioned(+ // Right-aligned to the control, which sits at the right end of a pane header — anchoring+ // the left edge would push a wide menu off-screen.+ right: position.right,+ top: position.top,+ child: ConstrainedBox(+ // Wide enough that a status can sit right-aligned against a model id without the two+ // meeting, and for a full GGUF-style model id beside its node without either cut.+ constraints: const BoxConstraints(minWidth: 340, maxWidth: 540),+ // ⚠️ IntrinsicWidth, or the menu is ALWAYS 540 wide. `Positioned` hands down unbounded+ // width, the ConstrainedBox turns that into "up to 540", and a stretching Column takes+ // all of it — so a two-line menu wore the width of the longest model id it could ever+ // hold. This measures the rows and the clamp then applies to what they actually need.+ child: IntrinsicWidth(+ child: Material(+ color: AppColors.surface,+ elevation: 8,+ borderRadius: BorderRadius.circular(8),+ clipBehavior: Clip.antiAlias,+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 6),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: children(close),+ ),+ ),+ ),+ ),+ ),+ ),+ ],+ ),+ );+ overlayState.insert(entry);+ return completer.future.whenComplete(() => _close = null);+ }++ /// One selectable row.+ Widget _item({required VoidCallback onTap, required Widget child}) => InkWell(+ onTap: onTap,+ child: child,+ );++ /// A line that states something rather than offering it — no hover, no tap.+ Widget _empty(String text) => Padding(+ padding: const EdgeInsets.fromLTRB(_menuInset + _rowPadding, 5, _menuInset + _rowPadding, 6),+ child: Text(text, style: TextStyle(fontSize: 11, color: AppColors.textSoft)),+ );+/// A section label. Non-interactive and short, so the two groups read as groups rather than as/// entries someone failed to make clickable.- PopupMenuItem<_Choice> _header(String label) => PopupMenuItem<_Choice>(- enabled: false,- height: 22,- padding: EdgeInsets.zero,+ Widget _header(String label) => Padding(+ padding: const EdgeInsets.only(top: 3, bottom: 3),child: Padding(// The row's margin plus its internal padding, so a header sits directly above the text it// heads rather than a few pixels to either side of it.@@ -280,31 +360,41 @@ class _GridModelPickerState extends State<GridModelPicker> {// the agent has no web search without opening the menu at all.message: sentence == null ? 'Where this agent runs' : 'Where this agent runs\n$sentence',waitDuration: const Duration(milliseconds: 700),- child: InkWell(- onTap: _open,- borderRadius: BorderRadius.circular(4),- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),- child: Row(- mainAxisSize: MainAxisSize.min,- children: [- // No leading glyph: the word carries the control, and a header this dense reads better- // with one fewer mark in it. The spinner takes that space only while a read is in- // flight, so the label does not shift when nothing is happening.- if (_loading) ...[- const SizedBox(- width: 11,- height: 11,- child: CircularProgressIndicator(strokeWidth: 1.5),+ child: MouseRegion(+ // Stated rather than inherited. The pane header sits over a terminal, and the cursor a+ // person sees while hovering this was whatever the surface underneath asked for — so a+ // control that opens a menu did not look like one until you clicked it.+ cursor: SystemMouseCursors.click,+ child: InkWell(+ onTap: _open,+ // Stated on the InkWell as well as on the MouseRegion above it. The cursor a person sees is+ // the INNERMOST annotation under the pointer, and InkWell installs one of its own — so an+ // ancestor asking for a hand is not, by itself, the thing that decides.+ mouseCursor: SystemMouseCursors.click,+ borderRadius: BorderRadius.circular(4),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ // No leading glyph: the word carries the control, and a header this dense reads+ // better with one fewer mark in it. The spinner takes that space only while a read+ // is in flight, so the label does not shift when nothing is happening.+ if (_loading) ...[+ const SizedBox(+ width: 11,+ height: 11,+ child: CircularProgressIndicator(strokeWidth: 1.5),+ ),+ const SizedBox(width: 5),+ ],+ Text(+ 'Model',+ style: TextStyle(fontSize: 11, color: AppColors.textSoft),),- const SizedBox(width: 5),+ Icon(Icons.arrow_drop_down, size: 14, color: AppColors.mutedStrong),],- Text(- 'Model',- style: TextStyle(fontSize: 11, color: AppColors.textSoft),- ),- Icon(Icons.arrow_drop_down, size: 14, color: AppColors.mutedStrong),- ],+ ),),),),diff --git a/desktop/lib/widgets/transient_menus.dart b/desktop/lib/widgets/transient_menus.dartnew file mode 100644index 000000000..35fa7366f--- /dev/null+++ b/desktop/lib/widgets/transient_menus.dart@@ -0,0 +1,27 @@+/// Menus the app draws in an [Overlay] rather than as a modal route.+///+/// An overlay menu dismisses itself when a pointer goes down somewhere else in the Flutter view —+/// that much it can see. What it CANNOT see is a click on native chrome: the window's AppKit tab+/// strip and menu bar are not part of Flutter's hit testing, so switching tabs from the titlebar+/// left a menu floating over the tab it no longer belonged to.+///+/// So the native side says so. Every entry point that learns "the titlebar was used" calls+/// [dismissTransientMenus], the same way it already closes the search field.+library;++/// Close callbacks for every overlay menu currently on screen.+final List<void Function()> _open = <void Function()>[];++/// Register [close] while a menu is showing. The returned callback deregisters it.+void Function() registerTransientMenu(void Function() close) {+ _open.add(close);+ return () => _open.remove(close);+}++/// Close every overlay menu. Safe to call when none are open.+void dismissTransientMenus() {+ // Over a COPY: each close deregisters itself, which would otherwise mutate the list being walked.+ for (final close in List<void Function()>.of(_open)) {+ close();+ }+}diff --git a/desktop/test/grid_model_picker_test.dart b/desktop/test/grid_model_picker_test.dartindex a8029f54c..5907eba22 100644--- a/desktop/test/grid_model_picker_test.dart+++ b/desktop/test/grid_model_picker_test.dart@@ -13,7 +13,7 @@ import 'package:harness/ws/ws_conn.dart';/// request's own 12-second timeout, and a spinner that never stops means `pumpAndSettle` never/// returns — the test would be measuring the timeout rather than the menu.class _Conn extends WsConn {- _Conn(this.models, {this.localModelEngines})+ _Conn(this.models, {this.localModelEngines, this.gridName, this.fails = false}): super(wsBaseUrl: 'ws://fixture.invalid',autonomousEnv: 'test',@@ -30,16 +30,26 @@ class _Conn extends WsConn {/// sends no such field.final List<String>? localModelEngines;+ /// The grid this account has, independent of what it is serving — so "a grid serving nothing" can+ /// be told apart from "no grid".+ final String? gridName;++ /// Make the request FAIL, the way an offline machine or a daemon too old for the call does.+ final bool fails;+@overrideFuture<Map<String, dynamic>> request(String type, {Map<String, dynamic> payload = const {},Duration timeout = const Duration(seconds: 20),- }) async => {- 'gridName': models.isEmpty ? null : 'someone-7f3a91c4',- 'models': models,- if (localModelEngines != null) 'localModelEngines': localModelEngines,- };+ }) async {+ if (fails) throw StateError('grid_models_list_result: UNSUPPORTED');+ return {+ 'gridName': gridName ?? (models.isEmpty ? null : 'someone-7f3a91c4'),+ 'models': models,+ if (localModelEngines != null) 'localModelEngines': localModelEngines,+ };+ }}void main() {@@ -48,13 +58,19 @@ void main() {void build({List<Map<String, Object?>> models = const [],List<String>? localModelEngines,+ String? gridName,+ bool fails = false,}) {notifier = AppNotifier(config: AppConfig.dev,authSession: AuthSession(),configStore: null,- connectionForTest: (_) =>- _Conn(models, localModelEngines: localModelEngines),+ connectionForTest: (_) => _Conn(+ models,+ localModelEngines: localModelEngines,+ gridName: gridName,+ fails: fails,+ ),);}@@ -110,18 +126,126 @@ void main() {expect(find.textContaining('usage'), findsOneWidget);});- testWidgets('an empty grid says nobody is serving, not that there is no grid', (tester) async {- // The daemon answers `{gridName: null, models: []}` when it cannot reach a grid at all, and- // these two facts need different sentences — one sends you to sign in, the other to serve a- // model. A single "no models" would send a person looking in the wrong place.+ // THREE situations, three sentences, one test each — a single test cannot cover them, because+ // re-pumping the same widget reuses the State and the picker answers from the memo it already has.+ // Only the middle one is about the ACCOUNT, and folding the first two together is what told a+ // signed-in user to "sign in again" when the real problem was a daemon that had not answered:+ // advice that was wrong, and useless even if the diagnosis had been right.+ testWidgets('a machine that did not answer says so, and does not blame the account', (tester) async {+ build(fails: true);+ await open(tester);+ expect(find.text('Could not reach this machine.'), findsOneWidget);+ expect(find.textContaining('sign in'), findsNothing);+ });++ testWidgets('an account with no grid says there are no local models yet', (tester) async {await open(tester);- expect(find.textContaining('sign in again'), findsOneWidget);+ expect(find.text('No local models on this account yet.'), findsOneWidget);// The user's vocabulary is "Local models", never "grid" — the grid is how a Local model is// served, not a thing the picker asks anyone to know about.- expect(find.text('No local models on this account yet — sign in again to set them up.'), findsOneWidget);expect(find.textContaining('grid'), findsNothing);});+ testWidgets('a grid serving nothing is the one state that asks for a model', (tester) async {+ build(gridName: 'someone-7f3a91c4');+ await open(tester);+ expect(find.text('Nothing is being served yet.'), findsOneWidget);+ });++ // `Positioned` hands down unbounded width, so a stretching Column takes every pixel its constraints+ // allow — a two-line menu wore the width of the longest model id it could ever hold. The minimum is+ // what keeps a status off a model id; the maximum is a CEILING, not a target. One test each, because+ // re-pumping reuses the State and the second open would answer from the first one's memo.+ testWidgets('a short menu is not as wide as the widest menu could be', (tester) async {+ await open(tester);+ final width = tester.getSize(find.byType(Material).last).width;+ expect(width, greaterThanOrEqualTo(340), reason: 'a status still clears a model id');+ expect(width, lessThan(540), reason: 'and nothing is padded out to the ceiling');+ });++ testWidgets('a long model id is given room, up to the ceiling', (tester) async {+ build(models: [+ {'id': 'Qwen3.6-35B-A3B-UD-Q5_K_XL-with-a-deliberately-long-tail', 'node': 'macbook-m1max'},+ ]);+ await open(tester);+ final width = tester.getSize(find.byType(Material).last).width;+ expect(width, greaterThan(340), reason: 'a row longer than the minimum asks for more');+ expect(width, lessThanOrEqualTo(540), reason: 'and never more than the ceiling');+ });++ testWidgets('a click outside closes the menu AND reaches what it was aimed at', (tester) async {+ // `showMenu` puts a modal barrier under the menu and that barrier EATS the dismissing click, so+ // closing the menu and then pressing a button took two clicks with the first going nowhere.+ var pressed = 0;+ tester.view.physicalSize = const Size(1200, 900);+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.reset);+ await tester.pumpWidget(MaterialApp(+ home: Scaffold(+ body: Stack(+ children: [+ Positioned(+ left: 20,+ top: 400,+ child: ElevatedButton(+ onPressed: () => pressed += 1,+ child: const Text('underneath'),+ ),+ ),+ Align(+ alignment: Alignment.topRight,+ child: GridModelPicker(+ notifier: notifier,+ machineId: 'local',+ engineLabel: 'claude',+ ),+ ),+ ],+ ),+ ),+ ));+ await tester.tap(find.text('Model'));+ await tester.pumpAndSettle();+ expect(find.text('Subscription'), findsOneWidget);++ await tester.tap(find.text('underneath'));+ await tester.pumpAndSettle();++ expect(find.text('Subscription'), findsNothing, reason: 'the menu closes');+ expect(pressed, 1, reason: 'and the same click lands on the button under it');+ });++ testWidgets('the control says it is clickable before it is clicked', (tester) async {+ // The pane header sits over a terminal, and without this the cursor over the control was+ // whatever the surface underneath asked for — so a menu control did not look like one.+ tester.view.physicalSize = const Size(1200, 900);+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.reset);+ await tester.pumpWidget(MaterialApp(+ home: Scaffold(+ body: Center(+ child: GridModelPicker(notifier: notifier, machineId: 'local', engineLabel: 'claude'),+ ),+ ),+ ));+ // The control prefetches on mount; settle so the test is not measuring that work's timers.+ await tester.pumpAndSettle();++ // BOTH annotations, because the innermost one under the pointer is what a person actually sees:+ // InkWell installs its own MouseRegion, so an ancestor asking for a hand does not decide alone.+ //+ // ⚠️ This asserts the widgets' contract, NOT the cursor the OS ends up drawing. Reading that back+ // through `MouseTracker.debugDeviceActiveCursor` does not work in this harness — a bare+ // `MouseRegion(cursor: click)` over a plain box resolves to `basic` there — so a test written+ // that way would have been measuring the harness rather than the app.+ final region = tester.widget<MouseRegion>(find.ancestor(+ of: find.byType(InkWell),+ matching: find.byType(MouseRegion),+ ).first);+ expect(region.cursor, SystemMouseCursors.click);+ expect(tester.widget<InkWell>(find.byType(InkWell)).mouseCursor, SystemMouseCursors.click);+ });+testWidgets('a served model shows under Local with the machine answering it', (tester) async {build(models: [{'id': 'Qwen3.6-35B-A3B-UD-Q5_K_XL', 'node': 'macbook-m1max'},