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 opens instantly, and marks the current row by filling it
bitcoinbuilder9dc4232fd54b
diff --git a/cli/src/lib/gridModels.ts b/cli/src/lib/gridModels.tsindex 2f53027c3..37265d2e1 100644--- a/cli/src/lib/gridModels.ts+++ b/cli/src/lib/gridModels.ts@@ -39,7 +39,18 @@ const ROUTER_ENGINE = 'grid-router'*/export async function listGridModels(gridName: string | null): Promise<GridModel[]> {if (!gridName?.trim()) return []- const { value } = await gridJson<GridModelRow[]>(['--remote', 'models', gridName])+ const fresh = cached(gridName)+ if (fresh) return fresh++ // ⚠️ Concurrently, and the ordering used to cost a full second of the click. `grid models` is+ // ~830ms and the relay catalogue another ~430ms, both of them a Python CLI spawn plus a network+ // round trip; run one after the other they are the whole of what a person waits through before+ // the menu appears. Neither needs the other's answer.+ const [listed, served] = await Promise.all([+ gridJson<GridModelRow[]>(['--remote', 'models', gridName]),+ relayModelIds(gridName),+ ])+ const value = listed.valueif (!Array.isArray(value)) return []// ⚠️ `grid models` LOWERCASES the model id; the relay does not. Measured on a real engine:@@ -49,7 +60,6 @@ export async function listGridModels(gridName: string | null): Promise<GridModel// the one the RELAY knows, so the relay's own catalogue is the authority here and `grid models`// is kept only for the node label. Case is unrecoverable from the lowercased string, so this// cannot be fixed by mapping.- const served = await relayModelIds(gridName)const nodeFor = new Map<string, string>()for (const row of value) {const id = typeof row.model === 'string' ? row.model.trim() : ''@@ -68,9 +78,39 @@ export async function listGridModels(gridName: string | null): Promise<GridModelseen.add(key)models.push({ id, node: nodeFor.get(key) ?? '' })}+ remember(gridName, models)return models}+/**+ * The last answer for a grid, for a few seconds.+ *+ * The picker asks on every open, and the answer costs two subprocess spawns and two network round+ * trips — measured at ~1.4s, which is a person watching a header do nothing after a click. Reopening+ * a menu twice in a row should not pay that twice.+ *+ * Short on purpose. The list is genuinely live — an engine can join or leave between two opens — so+ * this is only the window in which a click is free, not a cache in the sense of holding state. Longer+ * would start offering models nobody is serving, which is the failure the no-caching rule existed to+ * avoid.+ */+const TTL_MS = 15_000+const memo = new Map<string, { at: number; models: GridModel[] }>()++function cached(gridName: string): GridModel[] | null {+ const hit = memo.get(gridName)+ return hit && Date.now() - hit.at < TTL_MS ? hit.models : null+}++function remember(gridName: string, models: GridModel[]): void {+ memo.set(gridName, { at: Date.now(), models })+}++/** Drop the memo — for a caller that has just changed what the grid serves. */+export function forgetGridModels(): void {+ memo.clear()+}+/** Model ids exactly as the grid's relay serves them — the names an engine must send. Empty when the* relay cannot be asked, which the caller treats as "fall back", never as "no models". */async function relayModelIds(gridName: string): Promise<string[]> {diff --git a/desktop/lib/widgets/grid_model_picker.dart b/desktop/lib/widgets/grid_model_picker.dartindex 9dcf81f95..6f08c8a98 100644--- a/desktop/lib/widgets/grid_model_picker.dart+++ b/desktop/lib/widgets/grid_model_picker.dart@@ -59,6 +59,27 @@ class GridModelPicker extends StatefulWidget {class _GridModelPickerState extends State<GridModelPicker> {bool _loading = false;ModelsMenuController? _usage;+ GridModels? _last;++ @override+ void initState() {+ super.initState();+ // Warm the answer as soon as the control exists, so a click lands on a memo rather than on two+ // subprocess spawns and two network round trips — measured at ~1.4s, which is a person watching+ // a header do nothing. Fire-and-forget: nothing here waits on it, and a failure just means the+ // first open pays what it used to.+ unawaited(_prefetch());+ }++ Future<void> _prefetch() async {+ // Created here, not only on the cold path: a warm open reads `_usage.rows` for the subscription+ // row's provider name and percentage, and skipping it left that row falling back to the bare+ // engine label with no status beside it.+ _usage ??= ModelsMenuController(remote: widget.notifier.readRemoteUsage);+ unawaited(_usage!.refresh().catchError((_) {}));+ final answer = await widget.notifier.gridModels(widget.machineId);+ if (mounted) _last = answer;+ }@overridevoid dispose() {@@ -82,8 +103,16 @@ class _GridModelPickerState extends State<GridModelPicker> {Future<void> _open() async {if (_loading) return;- setState(() => _loading = true);+ // A warm answer opens the menu with no wait at all. It is at most seconds old — the daemon's own+ // memo is what bounds that — and the refresh below lands in time for the next open.final GridModels answer;+ if (_last != null) {+ answer = _last!;+ unawaited(_prefetch());+ await _show(answer);+ return;+ }+ setState(() => _loading = true);try {_usage ??= ModelsMenuController(remote: widget.notifier.readRemoteUsage);// ⚠️ The usage read is NOT awaited. It is decoration — a percentage beside the subscription@@ -96,6 +125,14 @@ class _GridModelPickerState extends State<GridModelPicker> {} finally {if (mounted) setState(() => _loading = false);}+ _last = answer;+ if (!mounted) return;+ await _show(answer);+ }++ /// Draw the menu for an answer already in hand. Split from [_open] so a warm open shares exactly+ /// the same menu as a cold one rather than a second copy of it.+ Future<void> _show(GridModels answer) async {if (!mounted) return;final box = context.findRenderObject() as RenderBox?;@@ -122,6 +159,7 @@ class _GridModelPickerState extends State<GridModelPicker> {PopupMenuItem<_Choice>(value: const _Choice.ownLogin(),height: 32,+ padding: EdgeInsets.zero,child: _Row(selected: widget.currentModel == null,engine: widget.engineLabel,@@ -141,6 +179,7 @@ class _GridModelPickerState extends State<GridModelPicker> {PopupMenuItem<_Choice>(enabled: false,height: 30,+ padding: const EdgeInsets.only(left: _menuInset + _rowPadding),child: Text(answer.gridName == null? 'No grid on this account yet — sign in again to set one up.'@@ -152,6 +191,7 @@ class _GridModelPickerState extends State<GridModelPicker> {PopupMenuItem<_Choice>(value: _Choice.model(model),height: 32,+ padding: EdgeInsets.zero,child: _Row(selected: widget.currentModel == model.id,title: model.id,@@ -176,10 +216,11 @@ class _GridModelPickerState extends State<GridModelPicker> {PopupMenuItem<_Choice> _header(String label) => PopupMenuItem<_Choice>(enabled: false,height: 22,+ padding: EdgeInsets.zero,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),+ // 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.+ padding: const EdgeInsets.only(left: _menuInset + _rowPadding),child: Text(label,style: TextStyle(@@ -248,54 +289,63 @@ class _Row extends StatelessWidget {@overrideWidget 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,+ return Container(+ // The highlight is the row, so it needs the row's own inset rather than the item's padding —+ // which is why the `PopupMenuItem`s around these set `padding: EdgeInsets.zero`.+ margin: const EdgeInsets.symmetric(horizontal: _menuInset),+ padding: const EdgeInsets.symmetric(horizontal: _rowPadding, vertical: 5),+ decoration: selected+ // Subtle on purpose: one row in the menu is already the current one, and a mark loud+ // enough to announce that would compete with the thing a person opened the menu to read.+ ? BoxDecoration(+ color: AppColors.selected,+ borderRadius: BorderRadius.circular(5),+ )+ : null,+ child: Row(+ children: [+ 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),- ),+ 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;+/// The row's own inset from the menu edge, and the padding inside its highlight. A section header+/// carries their SUM as a left inset, so header text sits exactly above the row text it heads.+const double _menuInset = 6;+const double _rowPadding = 8;/// 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.diff --git a/desktop/test/grid_model_picker_test.dart b/desktop/test/grid_model_picker_test.dartindex c978bd579..a19c8d9a8 100644--- a/desktop/test/grid_model_picker_test.dart+++ b/desktop/test/grid_model_picker_test.dart@@ -137,6 +137,25 @@ void main() {expect(rendered.size.width, greaterThan(160));});+ testWidgets('the current row is marked by a highlight, not by a tick column', (tester) async {+ // The tick reserved a fixed column at the start of EVERY row to keep labels aligned, which cost+ // every row that indent for one row's sake. Filling the current row instead says the same thing+ // and gives the space back.+ build(models: [+ {'id': 'Qwen3.6-35B-A3B-UD-Q5_K_XL', 'node': 'macbook-m1max'},+ ]);+ await open(tester, currentModel: 'Qwen3.6-35B-A3B-UD-Q5_K_XL');++ expect(find.byIcon(Icons.check), findsNothing);++ Container rowFor(String text) => tester.widget<Container>(+ find.ancestor(of: find.text(text), matching: find.byType(Container)).first,+ );+ // The selected row is filled; the other is not.+ expect((rowFor('Qwen3.6-35B-A3B-UD-Q5_K_XL').decoration as BoxDecoration?)?.color, isNotNull);+ expect(rowFor('Anthropic').decoration, isNull);+ });+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.