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(mobile): show machine status like harness rows in Find

tonyffd2aeeec137
diff --git a/mobile/lib/phone/phone_search_catalog.dart b/mobile/lib/phone/phone_search_catalog.dart
index ba718d536..99bfa648a 100644
--- a/mobile/lib/phone/phone_search_catalog.dart
+++ b/mobile/lib/phone/phone_search_catalog.dart
@@ -158,6 +158,16 @@ PhoneDestination _agent(
/// Every machine, unlike [agentIndex], which lists only the ones that can hand
/// over an agent: a machine that is off or locked is exactly the thing somebody
/// searches for when its agents are missing, and the row says which it is.
+///
+/// The state itself is the word at the row's right edge, as a harness row's is
+/// (`PhoneSearchResults._machineStateOf`); the line under the name says what it
+/// means — see [_machineDetail].
+///
+/// ⚠️ **The ones that answer first**, each group in the account's order — see
+/// [_machineRank]. With nothing typed after `@` this IS the list's order
+/// (`rankPhoneDestinations` keeps the catalog's order for rows that are not
+/// agents), and the one computer that answered used to sit wherever the account
+/// listed it, under every machine that was switched off.
List<PhoneDestination> _machines(
AppNotifier notifier,
Map<String, PhoneDestination> agents,
@@ -166,33 +176,67 @@ List<PhoneDestination> _machines(
for (final row in agents.values) {
(members[row.machineId!] ??= {}).add(row.id);
}
- return [
- for (final machine in notifier.machines)
- if (notifier.stateOf(machine.machineId) case final state?)
- PhoneDestination(
- id: 'machine:${machine.machineId}',
- kind: PhoneDestinationKind.machine,
- title: state.machine.displayName,
- detail: [
- 'Machine',
- _countLabel(members[machine.machineId]?.length ?? 0, 'harness'),
- switch (phoneMachineStatusOf(state)) {
- PhoneMachineStatus.needsPassword => 'Link required',
- PhoneMachineStatus.offline => 'Offline',
- PhoneMachineStatus.connecting => 'Connecting',
- PhoneMachineStatus.ready => null,
- },
- ].whereType<String>().join(' · '),
- machineId: machine.machineId,
- machineLabel: state.machine.displayName,
- machine: state,
- members: Set.unmodifiable(
- members[machine.machineId] ?? const <String>{},
- ),
- ),
- ];
+ final rows = <({PhoneDestination row, int rank, int index})>[];
+ for (final (index, machine) in notifier.machines.indexed) {
+ final state = notifier.stateOf(machine.machineId);
+ if (state == null) continue;
+ final status = phoneMachineStatusOf(state);
+ final ids = members[machine.machineId] ?? const <String>{};
+ rows.add((
+ row: PhoneDestination(
+ id: 'machine:${machine.machineId}',
+ kind: PhoneDestinationKind.machine,
+ title: state.machine.displayName,
+ detail: _machineDetail(status, ids.length),
+ machineId: machine.machineId,
+ machineLabel: state.machine.displayName,
+ machine: state,
+ members: Set.unmodifiable(ids),
+ ),
+ rank: _machineRank(status),
+ index: index,
+ ));
+ }
+ // `List.sort` is not stable: the account's order is the tie-break, spelled out.
+ rows.sort(
+ (a, b) => a.rank != b.rank
+ ? a.rank.compareTo(b.rank)
+ : a.index.compareTo(b.index),
+ );
+ return [for (final entry in rows) entry.row];
}
+/// Where a machine sits in `@`: the ones that answer, then a locked one, then
+/// the ones that are off.
+///
+/// ⚠️ **Connecting ranks WITH answering, not after it.** Every machine passes
+/// through connecting on the way up — on launch, and on every return to the
+/// app — so ranking the two apart moved each row the moment its socket came up,
+/// under a thumb already on its way to it.
+int _machineRank(PhoneMachineStatus status) => switch (status) {
+ PhoneMachineStatus.ready || PhoneMachineStatus.connecting => 0,
+ PhoneMachineStatus.needsPassword => 1,
+ PhoneMachineStatus.offline => 2,
+};
+
+/// The line under a machine's name: what its state means, with the state
+/// itself left to the word at the row's right edge.
+///
+/// ⚠️ **A count only where one is known.** A machine that is off or locked has
+/// told this phone nothing, and `0 harnesses` under it said it had none. One
+/// still connecting shows the list it had last — a warm start's, or the one
+/// from before the socket dropped — and says it is waiting when it has none.
+String _machineDetail(PhoneMachineStatus status, int harnesses) =>
+ switch (status) {
+ PhoneMachineStatus.ready => _countLabel(harnesses, 'harness'),
+ PhoneMachineStatus.connecting =>
+ harnesses > 0
+ ? _countLabel(harnesses, 'harness')
+ : 'Waiting for its harnesses',
+ PhoneMachineStatus.needsPassword => 'Needs its password',
+ PhoneMachineStatus.offline => 'Harness isn’t running there',
+ };
+
/// One row per repository or folder, agents grouped by [AgentProject.identity].
///
/// The same identity rule the desktop uses: checkouts group across machines
diff --git a/mobile/lib/phone/phone_search_controller.dart b/mobile/lib/phone/phone_search_controller.dart
index f8a43ecd4..413ce99da 100644
--- a/mobile/lib/phone/phone_search_controller.dart
+++ b/mobile/lib/phone/phone_search_controller.dart
@@ -12,6 +12,7 @@ import 'phone_destination.dart';
import 'phone_search_catalog.dart';
import 'phone_search_commands.dart';
import 'phone_search_rank.dart';
+import 'phone_status.dart';
/// What the box finds, said in the box.
///
@@ -277,11 +278,13 @@ class PhoneSearchController extends ChangeNotifier {
bool canSubmit(PhoneDestination row) => switch (row.kind) {
// Stopped work counts: the tap resumes it first — see [AgentEntry.isOpenable].
PhoneDestinationKind.agent => row.entry?.isOpenable ?? false,
- // A locked machine opens its password form, which is the thing to do about
- // it; a switched-off one has nothing to take a password.
- PhoneDestinationKind.machine => _catalog.any(
- (entry) => entry.id == row.id && entry.isMachine,
- ),
+ // A switched-off one has nothing to take a password and no harnesses to
+ // list: the tap narrowed Find to an empty list. Dimmed instead, and sunk
+ // under the machines that answer by the end of [_filter].
+ PhoneDestinationKind.machine =>
+ row.machine != null &&
+ phoneMachineStatusOf(row.machine!) != PhoneMachineStatus.offline &&
+ _catalog.any((entry) => entry.id == row.id && entry.isMachine),
PhoneDestinationKind.project => _catalog.any(
(entry) => entry.id == row.id && entry.isProject,
),
diff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dart
index fd10bfaee..ccf7bd41c 100644
--- a/mobile/lib/phone/phone_search_results.dart
+++ b/mobile/lib/phone/phone_search_results.dart
@@ -17,6 +17,7 @@ import 'phone_search_catalog.dart' show phoneAgentId;
import 'phone_search_commands.dart';
import 'phone_search_controller.dart';
import 'phone_search_rank.dart';
+import 'phone_status.dart';
import 'resume_agent.dart';
import 'search_result_text.dart'
show phoneResultMatches, snippetLead, snippetRuns;
@@ -338,9 +339,14 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
);
}
if (entry == null) {
+ final machine = row.isMachine ? _machineStateOf(row, tty) : null;
return FindRow(
title: row.title,
detail: row.detail,
+ // A locked machine's line is the one thing on it to act on.
+ detailColor: (machine?.asks ?? false) ? tty.text : null,
+ state: machine?.word,
+ stateColor: machine?.color,
terms: terms,
selected: selected,
enabled: openable,
@@ -392,6 +398,40 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
);
}
+ /// A machine's word at the right edge, in a harness row's colours: green for one that answers,
+ /// yellow for one that needs something from the person, faint for the rest. Read off the
+ /// machine live, like the harness rows' words; the line under it comes with the catalog, which
+ /// rebuilds on the same changes (`PhoneSearchCatalogCache`). Null for a row without its machine.
+ ({String word, Color color, bool asks})? _machineStateOf(
+ PhoneDestination row,
+ Tty tty,
+ ) {
+ final machine = row.machine;
+ if (machine == null) return null;
+ return switch (phoneMachineStatusOf(machine)) {
+ PhoneMachineStatus.ready => (
+ word: 'online',
+ color: tty.green,
+ asks: false,
+ ),
+ PhoneMachineStatus.needsPassword => (
+ word: 'locked',
+ color: tty.yellow,
+ asks: true,
+ ),
+ PhoneMachineStatus.connecting => (
+ word: 'connecting',
+ color: tty.faint,
+ asks: false,
+ ),
+ PhoneMachineStatus.offline => (
+ word: 'offline',
+ color: tty.faint,
+ asks: false,
+ ),
+ };
+ }
+
({String word, Color color}) _stateOf(
AgentEntry entry,
bool openable,