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.

feat(desktop): pick an agent's model from the pane header

bitcoinbuilder3fd61985f77f
diff --git a/desktop/lib/core/models.dart b/desktop/lib/core/models.dart
index f04bba77d..f0d231bd9 100644
--- a/desktop/lib/core/models.dart
+++ b/desktop/lib/core/models.dart
@@ -123,6 +123,12 @@ class Agent {
final String? engineDisplayName;
final String? engineIconHint;
final String? codexHome;
+
+ /// The grid model this agent is CURRENTLY running on, or null for its own vendor login.
+ ///
+ /// Read by the daemon off the live process on every discovery, never bookkept — so it is the
+ /// truth even for an agent someone re-pointed by hand. Null is a real answer, not a missing one.
+ final String? gridModel;
final String? parentAgentId;
final AgentProject? project;
final String status;
@@ -140,6 +146,7 @@ class Agent {
this.engineDisplayName,
this.engineIconHint,
this.codexHome,
+ this.gridModel,
this.parentAgentId,
this.project,
this.status = 'active',
@@ -182,6 +189,7 @@ class Agent {
engineDisplayName: _safeLabel(j['engineDisplayName']),
engineIconHint: _safeLabel(j['engineIconHint']),
codexHome: j['engine'] == 'codex' ? _safeCodexHome(j['codexHome']) : null,
+ gridModel: _safeLabel((j['grid'] as Map<String, dynamic>?)?['model']),
parentAgentId: _safeLabel(j['parentAgentId'] ?? j['parentId']),
project: AgentProject.fromJson(j['project']),
status: (j['status'] as String?) ?? 'active',
@@ -206,6 +214,7 @@ class Agent {
engineDisplayName: engineDisplayName,
engineIconHint: engineIconHint,
codexHome: codexHome,
+ gridModel: gridModel,
parentAgentId: parentAgentId,
project: project,
status: status,
@@ -423,3 +432,26 @@ class AgentProject {
);
}
}
+
+/// One model the account's private harness grid can answer right now.
+class GridModel {
+ /// The id an engine is pointed at, verbatim from the grid.
+ final String id;
+
+ /// Which machine serves it. Display only, and empty when the grid does not say — on a private
+ /// grid this is one of the user's own computers, which is the useful part of the answer.
+ final String node;
+
+ const GridModel({required this.id, required this.node});
+}
+
+/// The picker's whole answer: which grid was asked, and what it offers.
+///
+/// `gridName` is null when the machine has no grid yet — told apart from "a grid with nothing on
+/// it", because the two need different sentences in front of a person.
+class GridModels {
+ final String? gridName;
+ final List<GridModel> models;
+
+ const GridModels({required this.gridName, required this.models});
+}
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index d3b8fba5a..622d0ec46 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -2768,6 +2768,76 @@ class AppNotifier extends ChangeNotifier {
}
}
+ /// Put one agent back on its own vendor login — the Claude / Codex subscription it had before a
+ /// grid model was chosen.
+ ///
+ /// `clearGrid` is a separate flag rather than `gridModel: null` on purpose: the daemon treats an
+ /// absent field as "I did not mention the grid", so overloading null would make a forgotten field
+ /// and a deliberate "put it back" the same frame. Same pane respawn as picking a model.
+ Future<void> clearAgentGrid(String machineId, String agentId) async {
+ try {
+ await _conn(machineId).request(
+ 'agent_retarget',
+ payload: {'agentId': agentId, 'clearGrid': true},
+ timeout: const Duration(seconds: 30),
+ );
+ } catch (_) {
+ // The daemon owns the refusal (a busy pane, a launch that would not start) and the pane shows
+ // it; a second error surface here would tell one story twice.
+ }
+ }
+
+ /// Point one agent at a model on the account's private grid.
+ ///
+ /// Sends the model id and nothing else: the daemon on that machine resolves the endpoint and the
+ /// credential from its own signed-in `grid`, so neither travels over the relay and the app never
+ /// holds a grid key. Moving an agent re-execs its pane, which is why this is an explicit choice in
+ /// a menu rather than something that can happen by hovering.
+ Future<void> retargetAgentToGridModel(
+ String machineId,
+ String agentId,
+ String modelId,
+ ) async {
+ try {
+ await _conn(machineId).request(
+ 'agent_retarget',
+ payload: {'agentId': agentId, 'gridModel': modelId},
+ timeout: const Duration(seconds: 30),
+ );
+ } catch (_) {
+ // The daemon answers its own refusals (a busy pane, an unreachable grid) and the pane shows
+ // what actually happened; a second error surface here would be a second story about one act.
+ }
+ }
+
+ /// Live models on the account's private harness grid, for the pane header's picker.
+ ///
+ /// Asked of the machine the pane belongs to rather than kept in app state: the answer is whatever
+ /// that machine's `grid` reports at this moment (an engine can join or leave between two opens),
+ /// and a cached list would offer a model nobody is serving any more.
+ ///
+ /// Never throws — a machine whose daemon is too old to know the RPC, one with no grid, and one
+ /// that timed out are all "nothing to offer", which is what the picker shows.
+ Future<GridModels> gridModels(String machineId) async {
+ try {
+ final response = await _conn(machineId).request(
+ 'grid_models_list',
+ timeout: const Duration(seconds: 12),
+ );
+ final models = (response['models'] as List<dynamic>? ?? [])
+ .whereType<Map<String, dynamic>>()
+ .map((m) => GridModel(
+ id: (m['id'] as String?) ?? '',
+ node: (m['node'] as String?) ?? '',
+ ))
+ .where((m) => m.id.isNotEmpty)
+ .toList();
+ return GridModels(gridName: response['gridName'] as String?, models: models);
+ } catch (_) {
+ return const GridModels(gridName: null, models: []);
+ }
+ }
+
WsConn _conn(String machineId) {
final testConnection = connectionForTest;
if (testConnection != null) return testConnection(machineId);
diff --git a/desktop/lib/widgets/grid_model_picker.dart b/desktop/lib/widgets/grid_model_picker.dart
new file mode 100644
index 000000000..a99d29328
--- /dev/null
+++ b/desktop/lib/widgets/grid_model_picker.dart
@@ -0,0 +1,212 @@
+import 'package:flutter/material.dart';
+
+import '../core/models.dart';
+import '../state/app_state.dart';
+import '../theme/app_theme.dart';
+
+/// The pane header's model picker: what this agent could be run on, from the account's own grid.
+///
+/// **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.
+///
+/// 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.
+class GridModelPicker extends StatefulWidget {
+ final AppNotifier notifier;
+ final String machineId;
+
+ /// Called with the chosen model id.
+ final ValueChanged<GridModel>? onSelected;
+
+ /// Called to put the agent back on its own vendor login. Offered FIRST and always — a picker that
+ /// can only move an agent ONTO a grid is a one-way door, and the way back must not be a thing you
+ /// have to know a command for.
+ final VoidCallback? onUseOwnLogin;
+
+ /// The grid model this agent is on right now, or null when it is on its own login. Drives the
+ /// 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.
+ final String? engineLabel;
+
+ const GridModelPicker({
+ super.key,
+ required this.notifier,
+ required this.machineId,
+ this.onSelected,
+ this.onUseOwnLogin,
+ this.currentModel,
+ this.engineLabel,
+ });
+
+ @override
+ State<GridModelPicker> createState() => _GridModelPickerState();
+}
+
+class _GridModelPickerState extends State<GridModelPicker> {
+ bool _loading = false;
+
+ Future<void> _open() async {
+ if (_loading) return;
+ setState(() => _loading = true);
+ final GridModels answer;
+ try {
+ 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,
+ 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 chosen = await showMenu<_Choice>(
+ context: context,
+ position: position,
+ color: AppColors.surface,
+ items: [
+ ownLogin,
+ const PopupMenuDivider(),
+ PopupMenuItem<_Choice>(
+ enabled: false,
+ height: 26,
+ child: Text(
+ answer.gridName ?? 'no grid on this account yet',
+ style: TextStyle(fontSize: 10, color: AppColors.mutedStrong),
+ ),
+ ),
+ if (answer.models.isEmpty)
+ PopupMenuItem<_Choice>(
+ enabled: false,
+ child: Text(
+ answer.gridName == null
+ ? 'Sign in again to set one up.'
+ : 'Nothing is being served yet.',
+ style: TextStyle(fontSize: 11, color: AppColors.textSoft),
+ ),
+ ),
+ 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),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
+ );
+ if (chosen == null) return;
+ // Selecting what is already selected respawns the pane for no reason — do nothing instead.
+ if (chosen.model == null) {
+ if (widget.currentModel != null) widget.onUseOwnLogin?.call();
+ 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,
+ );
+
+ @override
+ Widget build(BuildContext context) {
+ return Tooltip(
+ message: 'Models on your private grid',
+ 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: [
+ 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),
+ Text(
+ 'Model',
+ style: TextStyle(fontSize: 11, color: AppColors.textSoft),
+ ),
+ Icon(Icons.arrow_drop_down, size: 14, color: AppColors.mutedStrong),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+/// 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 {
+ final GridModel? model;
+ const _Choice.model(GridModel this.model);
+ const _Choice.ownLogin() : model = null;
+}
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index ecb2cd162..4a6055449 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -32,6 +32,7 @@ import '../shared/theme/app_theme.dart' as grid;
import '../theme/app_theme.dart';
import 'engine_identity.dart';
import 'pane_actions_menu.dart';
+import 'grid_model_picker.dart';
/// The pane header's own horizontal inset.
const double _stripPadding = 14;
@@ -1436,6 +1437,28 @@ class _TerminalHeader extends StatelessWidget {
),
),
),
+ // The model picker sits next to the NAME, because that is the pair a person reads
+ // together: this agent, on that model. Hidden while a notice is showing — a header
+ // asking to reconnect is not the moment to offer a menu.
+ if (status == null && !readOnly) ...[
+ const SizedBox(width: 8),
+ GridModelPicker(
+ notifier: notifier,
+ machineId: session.machineId,
+ currentModel: agent?.gridModel,
+ engineLabel: session.engineId,
+ onSelected: (model) => unawaited(
+ notifier.retargetAgentToGridModel(
+ session.machineId,
+ session.agentId,
+ model.id,
+ ),
+ ),
+ onUseOwnLogin: () => unawaited(
+ notifier.clearAgentGrid(session.machineId, session.agentId),
+ ),
+ ),
+ ],
if (compact && status == null && project?.branch != null) ...[
const SizedBox(width: 16),
Tooltip(