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
feat(desktop): the model picker takes the shape of the Models menu
bitcoinbuilderd91a10bfff73
diff --git a/desktop/lib/widgets/grid_model_picker.dart b/desktop/lib/widgets/grid_model_picker.dartindex a99d29328..9dcf81f95 100644--- a/desktop/lib/widgets/grid_model_picker.dart+++ b/desktop/lib/widgets/grid_model_picker.dart@@ -1,23 +1,33 @@+import 'dart:async';+import 'package:flutter/material.dart';import '../core/models.dart';import '../state/app_state.dart';import '../theme/app_theme.dart';+import '../usage/models_menu_controller.dart';+import 'engine_identity.dart';-/// The pane header's model picker: what this agent could be run on, from the account's own grid.+/// The pane header's model picker, in two sections: **Subscription** and **Local**.+///+/// The shape is the app's own Models menu, deliberately — that menu already answers "what could this+/// run on" for the whole window, and a second control answering the same question in a different+/// visual language would read as a different KIND of question. It carries only two of that menu's+/// sections: the engine's own login, and the models the account's private grid is serving. There is+/// no API section here because this picker cannot put an agent on one.////// **Only the private harness grid.** Not every grid this computer's `grid` CLI happens to be signed-/// into — the question the header is asking is "which of MY machines could answer for this agent",-/// and a catalogue of other people's grids is a different question with a different blast radius.+/// into — the question the header asks is "which of MY machines could answer for this agent", and a+/// catalogue of other people's grids is a different question with a different blast radius.///-/// The list is fetched when the menu is opened rather than held in state, because it is live: an-/// engine can join or leave a grid between two openings, and an offer nobody is serving any more is-/// worse than a moment's spinner.+/// The list is fetched when the menu opens rather than held in state, because it is live: an engine+/// can join or leave a grid between two openings, and an offer nobody is serving any more is worse+/// than a moment's spinner.class GridModelPicker extends StatefulWidget {final AppNotifier notifier;final String machineId;- /// Called with the chosen model id.+ /// Called with the chosen grid model.final ValueChanged<GridModel>? onSelected;/// Called to put the agent back on its own vendor login. Offered FIRST and always — a picker that@@ -29,7 +39,7 @@ class GridModelPicker extends StatefulWidget {/// checkmark, so the menu answers "where am I" as well as "where could I go".final String? currentModel;- /// What this engine's own login is called, for the first row's label.+ /// The agent's engine, for the subscription row's icon and label.final String? engineLabel;const GridModelPicker({@@ -48,76 +58,92 @@ class GridModelPicker extends StatefulWidget {class _GridModelPickerState extends State<GridModelPicker> {bool _loading = false;+ ModelsMenuController? _usage;++ @override+ void dispose() {+ _usage?.dispose();+ super.dispose();+ }++ /// The subscription reading for THIS agent's engine, or null when there is none to show.+ ///+ /// Built from the same controller the window's own Models menu uses, so the percentage here and+ /// the percentage up there cannot disagree. Its refresh is capped at once a minute and it answers+ /// from cache in between, which is why opening this menu does not cost a request.+ Map<String, Object?>? _subscriptionRow() {+ final engine = widget.engineLabel?.trim().toLowerCase();+ if (engine == null || engine.isEmpty) return null;+ for (final row in _usage?.rows ?? const <Map<String, Object?>>[]) {+ if (row['engine'] == engine) return row;+ }+ return null;+ }Future<void> _open() async {if (_loading) return;setState(() => _loading = true);final GridModels answer;try {+ _usage ??= ModelsMenuController(remote: widget.notifier.readRemoteUsage);+ // ⚠️ The usage read is NOT awaited. It is decoration — a percentage beside the subscription+ // row — while the grid list is the menu's actual content, and a menu that waits on a credential+ // read to draw a list it already has is a menu that feels broken whenever that source is slow.+ // This open uses whatever is cached; the refresh lands for the next one. `refresh()` is itself+ // capped at once a minute, so opening the menu repeatedly costs nothing.+ unawaited(_usage!.refresh().catchError((_) {}));answer = await widget.notifier.gridModels(widget.machineId);} finally {if (mounted) setState(() => _loading = false);}if (!mounted) return;- // Anchored to this widget, so the menu opens where the eye already is.final box = context.findRenderObject() as RenderBox?;final overlay = Overlay.of(context).context.findRenderObject() as RenderBox?;if (box == null || overlay == null) return;final origin = box.localToGlobal(Offset.zero, ancestor: overlay);final position = RelativeRect.fromLTRB(origin.dx,- origin.dy + box.size.height + 4,+ origin.dy + box.size.height + 6,overlay.size.width - origin.dx - box.size.width,0,);- // The own-login row is built the same way whether or not the grid has anything on it: an agent- // that is ON a grid must always be able to come back, and a grid that has gone empty is exactly- // when someone most needs that.- final ownLogin = PopupMenuItem<_Choice>(- value: const _Choice.ownLogin(),- height: 34,- child: Row(- children: [- _check(widget.currentModel == null),- Flexible(- child: Text(- widget.engineLabel == null- ? 'Own login (subscription)'- : '${widget.engineLabel} login (subscription)',- overflow: TextOverflow.ellipsis,- style: TextStyle(fontSize: 12, color: AppColors.text),- ),- ),- ],- ),- );-- // 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 is "there is nothing to serve on". A single "no models"- // would send a person looking in the wrong place.+ final subscription = _subscriptionRow();final chosen = await showMenu<_Choice>(context: context,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: [- ownLogin,- const PopupMenuDivider(),+ _header('Subscription'),PopupMenuItem<_Choice>(- enabled: false,- height: 26,- child: Text(- answer.gridName ?? 'no grid on this account yet',- style: TextStyle(fontSize: 10, color: AppColors.mutedStrong),+ value: const _Choice.ownLogin(),+ height: 32,+ child: _Row(+ selected: widget.currentModel == null,+ engine: widget.engineLabel,+ title: (subscription?['title'] as String?) ?? engineIdentity(widget.engineLabel).label,+ detail: (subscription?['account'] as String?) ?? '',+ // Absent rather than "unknown": a row that cannot say how much is left says nothing,+ // which reads as "no figure" instead of as a figure that happens to be missing.+ status: subscription?['status'] as String?,),),+ const PopupMenuDivider(),+ _header('Local'),+ // 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.if (answer.models.isEmpty)PopupMenuItem<_Choice>(enabled: false,+ height: 30,child: Text(answer.gridName == null- ? 'Sign in again to set one up.'+ ? 'No grid on this account yet — sign in again to set one up.': 'Nothing is being served yet.',style: TextStyle(fontSize: 11, color: AppColors.textSoft),),@@ -125,27 +151,13 @@ class _GridModelPickerState extends State<GridModelPicker> {for (final model in answer.models)PopupMenuItem<_Choice>(value: _Choice.model(model),- height: 34,- child: Row(- children: [- _check(widget.currentModel == model.id),- Flexible(- child: Text(- model.id,- overflow: TextOverflow.ellipsis,- style: TextStyle(fontSize: 12, color: AppColors.text),- ),- ),- // Which of the user's machines answers it — the part that makes a private grid- // legible, and the reason `node` is carried through at all.- if (model.node.isNotEmpty) ...[- const SizedBox(width: 8),- Text(- model.node,- style: TextStyle(fontSize: 10, color: AppColors.mutedStrong),- ),- ],- ],+ height: 32,+ child: _Row(+ selected: widget.currentModel == model.id,+ title: model.id,+ // Which of the user's machines answers it — the part that makes a private grid+ // legible, and the reason `node` is carried through at all.+ status: model.node.isEmpty ? null : model.node,),),],@@ -157,21 +169,33 @@ class _GridModelPickerState extends State<GridModelPicker> {return;}if (chosen.model!.id != widget.currentModel) widget.onSelected?.call(chosen.model!);- return;-}- /// A fixed-width tick column, so every row's label starts at the same x whether or not it is the- /// active one — a menu whose text shifts by a few pixels between rows reads as misaligned.- Widget _check(bool on) => SizedBox(- width: 18,- child: on ? Icon(Icons.check, size: 13, color: AppColors.accent) : null,+ /// 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,+ child: Padding(+ // The same inset the tick column gives every row, so a header sits directly above the text it+ // heads rather than a few pixels to its left.+ padding: const EdgeInsets.only(left: _tickColumn),+ child: Text(+ label,+ style: TextStyle(+ fontSize: 10.5,+ fontWeight: FontWeight.w600,+ letterSpacing: .3,+ color: AppColors.mutedStrong,+ ),+ ),+ ),);@overrideWidget build(BuildContext context) {return Tooltip(- message: 'Models on your private grid',+ message: 'Where this agent runs',waitDuration: const Duration(milliseconds: 700),child: InkWell(onTap: _open,@@ -181,15 +205,17 @@ class _GridModelPickerState extends State<GridModelPicker> {child: Row(mainAxisSize: MainAxisSize.min,children: [- if (_loading)+ // 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),- )- else- Icon(Icons.memory, size: 13, color: AppColors.mutedStrong),- const SizedBox(width: 5),+ ),+ const SizedBox(width: 5),+ ],Text('Model',style: TextStyle(fontSize: 11, color: AppColors.textSoft),@@ -203,6 +229,74 @@ class _GridModelPickerState extends State<GridModelPicker> {}}+/// One menu row: tick, optional engine mark, title, a quiet detail beside it, and a right-aligned+/// status. The same column order in both sections, so the eye can run straight down the menu.+class _Row extends StatelessWidget {+ final bool selected;+ final String? engine;+ final String title;+ final String detail;+ final String? status;++ const _Row({+ required this.selected,+ required this.title,+ this.engine,+ this.detail = '',+ this.status,+ });++ @override+ Widget build(BuildContext context) {+ return Row(+ children: [+ // A fixed tick column, so every row's label starts at the same x whether or not it is the+ // active one — a menu whose text shifts between rows reads as misaligned. Section headers+ // carry the same inset, which is what lines a header up with the rows under it.+ SizedBox(+ width: _tickColumn,+ child: selected ? Icon(Icons.check, size: 12, color: AppColors.accent) : null,+ ),+ if (engine != null) ...[+ EngineMark(engine: engine, size: 14),+ const SizedBox(width: 7),+ ],+ // ⚠️ Expanded on the TITLE, not on the status. The status is a handful of characters and+ // wants only what it needs; giving it the flexible half truncated+ // `Qwen3.6-35B-A3B-UD-Q5_K_XL` to `Qwen3.6-35B-A3B-UD-Q5_K…` while empty space sat beside+ // it. The long string here is the model id, so the model id is what gets the room.+ Expanded(+ child: Text(+ title,+ overflow: TextOverflow.ellipsis,+ style: TextStyle(+ fontSize: 12.5,+ // Stated rather than inherited: a PopupMenuItem's default text style is heavier than+ // this menu wants, which read as every row being emphasised.+ fontWeight: FontWeight.w400,+ color: AppColors.text,+ ),+ ),+ ),+ if (detail.isNotEmpty) ...[+ const SizedBox(width: 6),+ Text(detail, style: TextStyle(fontSize: 11, color: AppColors.mutedStrong)),+ ],+ if (status != null) ...[+ const SizedBox(width: 14),+ Text(+ status!,+ style: TextStyle(fontSize: 11, color: AppColors.mutedStrong),+ ),+ ],+ ],+ );+ }+}++/// The inset every row's text sits behind, and every section header with it.+const double _tickColumn = 17;+/// One row's meaning: a grid model, or the engine's own login. A sealed pair rather than a nullable/// `GridModel`, because `null` already means "the menu was dismissed" in `showMenu`'s own result.class _Choice {diff --git a/desktop/test/grid_model_picker_test.dart b/desktop/test/grid_model_picker_test.dartnew file mode 100644index 000000000..c978bd579--- /dev/null+++ b/desktop/test/grid_model_picker_test.dart@@ -0,0 +1,154 @@+// The pane header's model picker: two sections, the way back always offered, and a tick that says+// where the agent actually is.+import 'package:flutter/material.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/state/app_state.dart';+import 'package:harness/widgets/grid_model_picker.dart';+import 'package:harness/ws/ws_conn.dart';++/// A connection that answers the picker's one RPC immediately. Without it the menu waits out the+/// 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)+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'local',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );++ final List<Map<String, Object?>> models;++ @override+ Future<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};+}++void main() {+ late AppNotifier notifier;++ void build({List<Map<String, Object?>> models = const []}) {+ notifier = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ connectionForTest: (_) => _Conn(models),+ );+ }++ setUp(() => build());+ tearDown(() => notifier.dispose());++ Future<void> open(+ WidgetTester tester, {+ String? currentModel,+ VoidCallback? onOwnLogin,+ ValueChanged<GridModel>? onSelected,+ }) async {+ 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',+ currentModel: currentModel,+ onUseOwnLogin: onOwnLogin,+ onSelected: onSelected,+ ),+ ),+ ),+ ));+ await tester.tap(find.text('Model'));+ // The menu waits on the grid read AND the usage read; settle covers both plus the open animation.+ await tester.pumpAndSettle();+ }++ testWidgets('shows both sections, and the way back is in the first one', (tester) async {+ await open(tester);++ // The two sections this picker has, and NOT the API section the window's own Models menu+ // carries — this control cannot put an agent on an API provider, so offering one would be a+ // choice that goes nowhere.+ expect(find.text('Subscription'), findsOneWidget);+ expect(find.text('Local'), findsOneWidget);+ expect(find.text('API'), findsNothing);++ // A picker that can only move an agent ONTO a grid is a one-way door, so the engine's own login+ // is always the first row. It is named the way the window's own Models menu names it — by+ // PROVIDER ('Anthropic'), not by engine ('Claude') — so the two controls agree about what the+ // thing is called, and it carries that menu's status text beside it.+ expect(find.text('Anthropic'), findsOneWidget);+ 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.+ await open(tester);+ expect(find.textContaining('sign in again'), findsOneWidget);+ });++ 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'},+ ]);+ GridModel? picked;+ await open(tester, onSelected: (m) => picked = m);++ expect(find.text('Qwen3.6-35B-A3B-UD-Q5_K_XL'), findsOneWidget);+ // The node is what makes a PRIVATE grid legible: it names which of the user's own machines+ // answers, which is the whole difference from a model on somebody else's grid.+ expect(find.text('macbook-m1max'), findsOneWidget);++ await tester.tap(find.text('Qwen3.6-35B-A3B-UD-Q5_K_XL'));+ await tester.pumpAndSettle();+ expect(picked?.id, 'Qwen3.6-35B-A3B-UD-Q5_K_XL');+ });++ testWidgets('a long model id is not truncated while space sits beside it', (tester) async {+ // ⚠️ REGRESSION. The status column used to take the flexible half, which cut+ // `Qwen3.6-35B-A3B-UD-Q5_K_XL` down to `Qwen3.6-35B-A3B-UD-Q5_K…` with empty menu beside it.+ // The long string in this menu is the model id, so the model id is what gets the room.+ build(models: [+ {'id': 'Qwen3.6-35B-A3B-UD-Q5_K_XL', 'node': 'macbook-m1max'},+ ]);+ await open(tester);++ final title = tester.widget<Text>(find.text('Qwen3.6-35B-A3B-UD-Q5_K_XL'));+ expect(title.overflow, TextOverflow.ellipsis); // still guarded for a truly absurd name+ final rendered = tester.renderObject<RenderBox>(find.text('Qwen3.6-35B-A3B-UD-Q5_K_XL'));+ // Laid out at its natural width rather than clipped: the painted box is as wide as the string+ // wants, which is the thing that was failing.+ expect(rendered.size.width, greaterThan(160));+ });++ testWidgets('choosing the engine login only fires when the agent is NOT already on it', (tester) async {+ var calls = 0;+ // Already on its own login: re-selecting it would respawn the pane for nothing.+ await open(tester, currentModel: null, onOwnLogin: () => calls++);+ await tester.tap(find.text('Anthropic'));+ await tester.pumpAndSettle();+ expect(calls, 0);++ // On a grid model: now it has somewhere to go.+ await open(tester, currentModel: 'Qwen-Test', onOwnLogin: () => calls++);+ await tester.tap(find.text('Anthropic'));+ await tester.pumpAndSettle();+ expect(calls, 1);+ });+}