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): enhance agent management with output stats and improved UI elements

Dev jacob2ab75abdf47f
diff --git a/mobile/lib/core/agent_output_stats.dart b/mobile/lib/core/agent_output_stats.dart
new file mode 100644
index 000000000..ad2521a02
--- /dev/null
+++ b/mobile/lib/core/agent_output_stats.dart
@@ -0,0 +1,60 @@
+/// What a harness has produced, as its machine measured it — the desktop's `AgentOutputStats`.
+///
+/// Only counts confirmed by the harness's own tool receipts: lines its edits added and removed
+/// (repeated edits included, so not the branch diff) and pull requests it created. Each half of the
+/// edit pair is dropped without the other, so a row never shows `+12` with nothing beside it.
+class AgentOutputStats {
+ const AgentOutputStats({
+ this.linesAdded,
+ this.linesRemoved,
+ this.pullRequestsCreated,
+ this.updatedAt,
+ });
+
+ final int? linesAdded, linesRemoved, pullRequestsCreated;
+ final DateTime? updatedAt;
+
+ bool get hasEdits => linesAdded != null && linesRemoved != null;
+ bool get isEmpty => !hasEdits && pullRequestsCreated == null;
+
+ /// Null for anything that carries nothing worth drawing — an older daemon, or a harness that has
+ /// not edited or opened anything yet.
+ static AgentOutputStats? fromJson(Object? value) {
+ if (value is! Map) return null;
+ final added = wireCount(value['linesAdded']);
+ final removed = wireCount(value['linesRemoved']);
+ final stats = AgentOutputStats(
+ linesAdded: removed == null ? null : added,
+ linesRemoved: added == null ? null : removed,
+ pullRequestsCreated: wireCount(value['pullRequestsCreated']),
+ updatedAt: value['updatedAt'] is String
+ ? DateTime.tryParse(value['updatedAt'] as String)
+ : null,
+ );
+ return stats.isEmpty ? null : stats;
+ }
+
+ @override
+ bool operator ==(Object other) =>
+ other is AgentOutputStats &&
+ linesAdded == other.linesAdded &&
+ linesRemoved == other.linesRemoved &&
+ pullRequestsCreated == other.pullRequestsCreated &&
+ updatedAt == other.updatedAt;
+
+ @override
+ int get hashCode =>
+ Object.hash(linesAdded, linesRemoved, pullRequestsCreated, updatedAt);
+}
+
+/// A count off the wire, or null for anything that is not a JavaScript-safe non-negative integer.
+int? wireCount(Object? n) =>
+ n is int && n >= 0 && n <= 9007199254740991 ? n : null;
+
+/// `4.5M`, `12.3k`, `980` — the desktop's `formatTokens`, used for every count a row draws.
+String formatCount(int count) {
+ if (count >= 1000000000) return '${(count / 1000000000).toStringAsFixed(1)}B';
+ if (count >= 1000000) return '${(count / 1000000).toStringAsFixed(1)}M';
+ if (count >= 1000) return '${(count / 1000).toStringAsFixed(1)}k';
+ return '$count';
+}
diff --git a/mobile/lib/core/models.dart b/mobile/lib/core/models.dart
index a3ba4960c..946d6e9bd 100644
--- a/mobile/lib/core/models.dart
+++ b/mobile/lib/core/models.dart
@@ -1,6 +1,8 @@
/// Data models mirroring the backend/web types.
library;
+import 'agent_output_stats.dart';
+
enum MachineAuthMode { managed, remote, self, provider }
enum ConnectionStatus { disconnected, connecting, connected, reconnecting }
@@ -119,6 +121,17 @@ class Machine {
}
/// Data-plane agent (RPC agents_list).
+/// What an agent with no name of its own is called — display only, never sent to a CLI as a rename.
+const kUntitledPane = 'Untitled Pane';
+
+final _automaticHarnessName = RegExp(
+ r'^(?:(?:harness|agent)-[1-9]\d*|.+ harness \d{1,2}-\d{1,2} \d{1,2}:\d{2}(?::\d{2})?)$',
+);
+
+/// Whether [name] is one the CLI made up rather than one somebody chose — the desktop's rule.
+bool isAutomaticHarnessName(String name) =>
+ _automaticHarnessName.hasMatch(name);
+
class Agent {
final String id;
final String? sessionId;
@@ -166,6 +179,14 @@ class Agent {
final bool terminalAvailable;
final String? terminalUnavailableReason;
+ /// The conversation's token count as its machine last measured it — input, output and cached
+ /// input together. Null from a daemon that does not report usage.
+ final int? tokensUsed;
+ final DateTime? tokensUpdatedAt;
+
+ /// What the harness has produced — see [AgentOutputStats].
+ final AgentOutputStats? outputStats;
+
const Agent({
required this.id,
this.sessionId,
@@ -188,6 +209,9 @@ class Agent {
this.launchDetail,
this.terminalAvailable = false,
this.terminalUnavailableReason,
+ this.tokensUsed,
+ this.tokensUpdatedAt,
+ this.outputStats,
});
factory Agent.fromJson(Map<String, dynamic> j) {
@@ -215,6 +239,10 @@ class Agent {
_ => 'ready',
};
final grid = j['grid'];
+ // The desktop's reading of `tokenUsage`: the total alone, and nothing at all for a value no
+ // JavaScript number could have held.
+ final usage = j['tokenUsage'];
+ final tokens = usage is Map ? wireCount(usage['totalTokens']) : null;
return Agent(
id: j['id'] as String,
sessionId: _safeLabel(j['sessionId']),
@@ -244,6 +272,11 @@ class Agent {
? null
: _safeLabel(terminalMap['reason']) ??
'terminal unavailable (no verified terminal pane)',
+ tokensUsed: tokens,
+ tokensUpdatedAt: tokens != null && usage is Map
+ ? _safeTime(usage['updatedAt'])
+ : null,
+ outputStats: AgentOutputStats.fromJson(j['outputStats']),
);
}
@@ -269,6 +302,9 @@ class Agent {
launchDetail: launchDetail,
terminalAvailable: terminalAvailable,
terminalUnavailableReason: terminalUnavailableReason,
+ tokensUsed: tokensUsed,
+ tokensUpdatedAt: tokensUpdatedAt,
+ outputStats: outputStats,
);
/// Saved work the daemon is no longer running, as the desktop's [Agent] reads
@@ -284,6 +320,21 @@ class Agent {
/// (`resumeStoppedAgent.ts`): exact resume exists for Claude Code and Codex only, and only once the
/// engine has saved a session. An agent stopped before its first prompt never got one, and the
/// machine answers RESUME_UNAVAILABLE for it however many times it is asked.
+ /// Whether a row has anything to put on its stats line — see [AgentOutputStats].
+ bool get hasMonitorStats =>
+ tokensUsed != null || (outputStats != null && !outputStats!.isEmpty);
+
+ /// The name a row draws — the desktop's `displayName`, so an agent reads the same on both.
+ ///
+ /// A name the CLI made up (`harness-3`, `Claude harness 9-23 13:52`) says only when it was
+ /// started; the agent's own title says what it is about, and with neither the desktop writes
+ /// [kUntitledPane]. A name somebody chose is always kept.
+ String get displayName {
+ if (!isAutomaticHarnessName(name)) return name;
+ final own = title?.trim();
+ return own != null && own.isNotEmpty ? own : kUntitledPane;
+ }
+
bool get canResumeConversation =>
(engine == 'claude' || engine == 'codex') &&
sessionId?.isNotEmpty == true;
diff --git a/mobile/lib/phone/agent_index.dart b/mobile/lib/phone/agent_index.dart
index 1c4098221..c5c4fa4e2 100644
--- a/mobile/lib/phone/agent_index.dart
+++ b/mobile/lib/phone/agent_index.dart
@@ -1,3 +1,4 @@
+import 'package:collection/collection.dart' show compareNatural;
import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/state/app_state.dart';
@@ -119,6 +120,31 @@ List<AgentEntry> recentAgents(List<AgentEntry> entries) => _stableSorted(
_newestFirst(a.lastActiveAt, b.lastActiveAt),
);
+/// The order the desktop's Harness Monitor lists harnesses in, "Recent" — so a list the phone
+/// opens on reads top to bottom as the monitor on the laptop beside it does.
+///
+/// ⚠️ **The machine's own `updatedAt`, never [AgentEntry.lastActiveAt].** That one folds in turns
+/// THIS phone happened to see, which the desktop never saw — two lists sorted on two different
+/// clocks drift apart on exactly the agents somebody is watching. `updatedAt` reaches both apps in
+/// the same frames, so both sort on one clock. An agent with none sorts last, as it does there.
+///
+/// Then the desktop's tie-breaks: its own focus history (which a phone does not have, so it is
+/// skipped), the name as drawn in natural order, and finally the id so two rows never swap.
+int compareMonitorOrder(AgentEntry a, AgentEntry b) {
+ final activity = (b.agent.updatedAt?.millisecondsSinceEpoch ?? 0).compareTo(
+ a.agent.updatedAt?.millisecondsSinceEpoch ?? 0,
+ );
+ if (activity != 0) return activity;
+ final name = compareNatural(
+ a.agent.displayName.toLowerCase(),
+ b.agent.displayName.toLowerCase(),
+ );
+ if (name != 0) return name;
+ return '${a.machineId}/${a.agent.id}'.compareTo(
+ '${b.machineId}/${b.agent.id}',
+ );
+}
+
/// -1 when only [a] holds, 1 when only [b] does, null on a tie — so comparators chain with `??`.
int? _firstWhere(bool a, bool b) => a == b ? null : (a ? -1 : 1);
diff --git a/mobile/lib/phone/compact_age.dart b/mobile/lib/phone/compact_age.dart
index 0285b75a0..d0fac185a 100644
--- a/mobile/lib/phone/compact_age.dart
+++ b/mobile/lib/phone/compact_age.dart
@@ -12,3 +12,15 @@ String compactAge(DateTime at, DateTime now) {
if (age.inDays < 365) return '${age.inDays ~/ 7}w';
return '${age.inDays ~/ 365}y';
}
+
+/// How long ago a harness was last active, as the desktop's monitor writes it — `49m`, `3h`, `2d`.
+///
+/// Not [compactAge]: the monitor has no `now`, `w` or `y`, and a row that reads `1w` on the phone
+/// beside `9d` on the desktop is the same agent looking like two. `—` when the machine never said.
+String harnessActivityAge(DateTime? activity, DateTime now) {
+ if (activity == null) return '—';
+ final elapsed = now.difference(activity);
+ if (elapsed.inDays >= 1) return '${elapsed.inDays}d';
+ if (elapsed.inHours >= 1) return '${elapsed.inHours}h';
+ return '${elapsed.inMinutes.clamp(0, 59)}m';
+}
diff --git a/mobile/lib/phone/desk_tabs_panel.dart b/mobile/lib/phone/desk_tabs_panel.dart
index 192c72edd..91706917a 100644
--- a/mobile/lib/phone/desk_tabs_panel.dart
+++ b/mobile/lib/phone/desk_tabs_panel.dart
@@ -16,6 +16,7 @@ import 'desk_tab_rename_dialog.dart';
import 'desk_tab_strip.dart';
import 'phone_navigation.dart';
import 'phone_status.dart';
+import 'sheet_agent_lines.dart';
import 'sheet_list.dart';
/// The account's tabs, and the agents inside the one being read — what the
@@ -385,7 +386,6 @@ class DeskAgentRow extends StatelessWidget {
Widget build(BuildContext context) {
AppTheme.watch(context);
final agent = entry.agent;
- final project = entry.project;
return SheetRow(
first: first,
last: last,
@@ -396,17 +396,17 @@ class DeskAgentRow extends StatelessWidget {
engine: agent.engine,
displayName: agent.engineDisplayName,
),
- title: Text(
- agent.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: sheetRowTitleStyle(),
- ),
- subtitle: SheetPlaceLine(
- machine: entry.machineName,
- folder: project?.folder,
- branch: project?.branchLabel,
+ title: SheetAgentTitle(
+ entry: entry,
+ now: DateTime.now(),
+ name: Text(
+ agent.displayName,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: sheetRowTitleStyle(),
+ ),
),
+ subtitle: SheetAgentMeta(entry: entry),
trailing: SheetAgentStatus(summary: entry.summary, onScreen: onScreen),
chevron: !onScreen,
);
diff --git a/mobile/lib/phone/phone_search_catalog.dart b/mobile/lib/phone/phone_search_catalog.dart
index 87bd4e08c..9fd4d903b 100644
--- a/mobile/lib/phone/phone_search_catalog.dart
+++ b/mobile/lib/phone/phone_search_catalog.dart
@@ -98,6 +98,10 @@ PhoneDestination _agent(
final agent = entry.agent;
final project = entry.project;
final offline = entry.machine.nodeOnline == false;
+ // The desktop's name for it ([Agent.displayName]); the CLI's own stays
+ // searchable beside it, so typing what the terminal's title bar says still
+ // finds the row.
+ final renamed = agent.displayName != agent.name;
final detail = _harnessDetail(
label,
project,
@@ -108,7 +112,7 @@ PhoneDestination _agent(
return PhoneDestination(
id: phoneAgentId(entry.machineId, agent.id),
kind: PhoneDestinationKind.agent,
- title: agent.name,
+ title: agent.displayName,
detail: detail.text,
detailBranchOffset: detail.branchOffset,
promptContext: PhonePromptContext(
@@ -132,6 +136,7 @@ PhoneDestination _agent(
// whose folder or recap happens to mention fab.
searchFields: [
agent.title,
+ if (renamed) agent.name,
label,
entry.machineName,
project?.name,
@@ -144,7 +149,7 @@ PhoneDestination _agent(
agent.selectedModel,
agent.dshName,
],
- titleFields: agent.title == null ? 1 : 2,
+ titleFields: 1 + (agent.title == null ? 0 : 1) + (renamed ? 1 : 0),
);
}
diff --git a/mobile/lib/phone/phone_search_controller.dart b/mobile/lib/phone/phone_search_controller.dart
index a145b510c..036b3876b 100644
--- a/mobile/lib/phone/phone_search_controller.dart
+++ b/mobile/lib/phone/phone_search_controller.dart
@@ -307,6 +307,12 @@ class PhoneSearchController extends ChangeNotifier {
recent: history?.recent ?? const <String>[],
previews: notifier.sessionPreviews,
);
+ matchCount = rows.length;
+ // ⚠️ **Not with nothing typed.** That list is the desktop's Harness Monitor
+ // order ([rankPhoneDestinations]), where paused work sits among the rest by
+ // when it last moved — moving it to the bottom here is the phone's list
+ // disagreeing with the laptop's again.
+ if (_listsMonitorOrder) return;
// Keep the match order, but put rows a tap can open first. An agent whose
// terminal has gone must not bury the ones that answer.
final open = <PhoneDestination>[];
@@ -318,6 +324,14 @@ class PhoneSearchController extends ChangeNotifier {
matchCount = rows.length;
}
+ /// Whether [rows] are agents with nothing typed — the list that follows the
+ /// desktop's monitor.
+ bool get _listsMonitorOrder =>
+ !isCommandMode &&
+ !isProjectMode &&
+ !isMachineMode &&
+ matchQuery.trim().isEmpty;
+
/// With nothing typed, the commands run lately lead, newest first; the rest
/// keep their order. Once something is typed, the match decides.
List<PhoneDestination> _recentFirst(List<PhoneDestination> ranked) {
diff --git a/mobile/lib/phone/phone_search_rank.dart b/mobile/lib/phone/phone_search_rank.dart
index c9403c8eb..e7ecfd002 100644
--- a/mobile/lib/phone/phone_search_rank.dart
+++ b/mobile/lib/phone/phone_search_rank.dart
@@ -1,6 +1,7 @@
import 'package:harness_mobile/core/fuzzy_match.dart';
import 'package:harness_mobile/state/session_preview.dart';
+import 'agent_index.dart' show compareMonitorOrder;
import 'phone_destination.dart';
final _words = RegExp(r'\s+');
@@ -178,6 +179,7 @@ List<PhoneDestination> rankPhoneDestinations(
? 0
: 1;
ranked.sort((a, b) {
+ if (needle.isEmpty) return _monitorOrder(a, b);
var order = (a.content ? 1 : 0).compareTo(b.content ? 1 : 0);
if (order == 0) order = a.score.compareTo(b.score);
if (order == 0 && needle.isEmpty) {
@@ -194,6 +196,26 @@ List<PhoneDestination> rankPhoneDestinations(
return [for (final row in ranked) row.entry];
}
+/// With nothing typed, the list the field opens on: the agents in the desktop's Harness Monitor
+/// order ([compareMonitorOrder]), and whatever is not an agent after them in [all]'s order.
+///
+/// ⚠️ **Not the typed ranking with an empty query, which is what it was.** That put the agents THIS
+/// phone had visited first, then its own guess — so the field opened on a list that matched nothing
+/// on the laptop beside it, and the agent at the top of the desktop's monitor could be halfway down
+/// the phone's. Somebody moving between the two reads the same list on both now. Once a word is
+/// typed the match decides, as it always has.
+int _monitorOrder(
+ ({PhoneDestination entry, int score, bool content, int index}) a,
+ ({PhoneDestination entry, int score, bool content, int index}) b,
+) {
+ final left = a.entry.entry;
+ final right = b.entry.entry;
+ if (left != null && right != null) return compareMonitorOrder(left, right);
+ if (left != null) return -1;
+ if (right != null) return 1;
+ return a.index.compareTo(b.index);
+}
+
/// The line of [row]'s session content worth quoting under its name: the one
/// holding the first word no field matched, from a little before that word.
///
diff --git a/mobile/lib/phone/sheet_agent_lines.dart b/mobile/lib/phone/sheet_agent_lines.dart
new file mode 100644
index 000000000..f38c567c5
--- /dev/null
+++ b/mobile/lib/phone/sheet_agent_lines.dart
@@ -0,0 +1,215 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/core/agent_output_stats.dart';
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+import 'agent_index.dart';
+import 'compact_age.dart';
+import 'phone_prompt_context.dart';
+import 'search_result_text.dart';
+
+// An agent's row in the sheet, said the way the desktop's Harness Monitor says it
+// (`desktop/lib/widgets/harness_session_manager.dart`, `_SessionRow`):
+//
+// ```
+// Logo Harness_4.svg update · 50m Start failed
+// ▭ MacBookPro2021.local ▢ autonomous-harness ⑂ feat/mobile…
+// 4.5M tokens · +120 −48 · 2 PRs
+// ```
+//
+// ⚠️ **Shared by the tabs and the search**, which the sheet swaps in place: an agent keeps the row
+// it had in the tabs when the field takes focus, so the swap changes what is listed, never how.
+
+/// Metadata in the monitor's face — the terminal's monospace, as the desktop's `monoMeta` is.
+TextStyle _meta(Color color) => phoneBoxMonoStyle(size: 11.5, color: color);
+
+/// The monitor's two place colours: the folder in teal, the branch in green.
+const _folderTint = Color(0xff79bbaf);
+const _branchTint = Color(0xff8dbb79);
+
+/// The edit counts' own colours — added in the branch's green, removed red — as the desktop draws
+/// them.
+const _addedTint = _branchTint;
+const _removedTint = Color(0xffd28f87);
+
+/// The word the monitor puts after a row's age when something is wrong with it, or null.
+///
+/// Only the exceptions: ready, working, waiting and paused already have their own mark on the row
+/// (its status dot, or `Stopped` at its end), and saying them twice is noise. The desktop's `status`,
+/// less its `View only` — a phone lists no shared harnesses.
+String? agentAttention(AgentEntry entry) {
+ final agent = entry.agent;
+ if (entry.machine.nodeOnline == false) return 'Offline';
+ if (agent.isStopped) return null;
+ return switch (agent.launchState) {
+ 'failed' => 'Start failed',
+ 'starting' => 'Starting',
+ _ => null,
+ };
+}
+
+/// The name, then how long ago the agent last moved, then [agentAttention].
+///
+/// The age is the machine's `updatedAt` — the same clock the list is sorted on
+/// ([compareMonitorOrder]), so the ages read down the list in order.
+class SheetAgentTitle extends StatelessWidget {
+ const SheetAgentTitle({
+ super.key,
+ required this.entry,
+ required this.name,
+ required this.now,
+ });
+
+ final AgentEntry entry;
+
+ /// The name as the caller draws it — plain in the tabs, with the query's hits in bold in search.
+ final Widget name;
+
+ final DateTime now;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final activity = entry.agent.updatedAt;
+ final attention = agentAttention(entry);
+ return Row(
+ children: [
+ Flexible(child: name),
+ if (activity != null)
+ Padding(
+ padding: const EdgeInsets.only(left: 8),
+ child: Text(
+ '· ${harnessActivityAge(activity, now)}',
+ maxLines: 1,
+ style: _meta(AppPalette.textSecondary),
+ ),
+ ),
+ if (attention != null)
+ Padding(
+ padding: const EdgeInsets.only(left: 10),
+ child: Text(
+ attention,
+ maxLines: 1,
+ style: _meta(AppPalette.textSecondary),
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+/// Where the agent runs — machine, folder, branch, each with its mark — and, when its machine has
+/// measured any, what it has produced.
+class SheetAgentMeta extends StatelessWidget {
+ const SheetAgentMeta({
+ super.key,
+ required this.entry,
+ this.matches = const [],
+ });
+
+ final AgentEntry entry;
+
+ /// What the query reached, set in bold where it lands. Empty in the tabs, where nothing was
+ /// searched.
+ final Iterable<PhoneFieldMatch> matches;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final project = entry.project;
+ final folder = project?.folder;
+ final branch = project?.branchLabel;
+ final agent = entry.agent;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ _part(
+ LucideIcons.monitor,
+ entry.machineName,
+ AppPalette.textSecondary,
+ ),
+ if (folder != null && folder.isNotEmpty) ...[
+ const SizedBox(width: 10),
+ _part(LucideIcons.folder, folder, _folderTint),
+ ],
+ if (branch != null && branch.isNotEmpty) ...[
+ const SizedBox(width: 10),
+ _part(LucideIcons.gitBranch, branch, _branchTint),
+ ],
+ ],
+ ),
+ if (agent.hasMonitorStats) ...[
+ const SizedBox(height: 3),
+ _AgentStats(agent: agent),
+ ],
+ ],
+ );
+ }
+
+ /// One mark and its words, giving way to the others when the row runs short.
+ Widget _part(IconData icon, String text, Color color) => Flexible(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(icon, size: 11, color: color),
+ const SizedBox(width: 4),
+ Flexible(
+ child: SearchResultText(text, matches: matches, style: _meta(color)),
+ ),
+ ],
+ ),
+ );
+}
+
+/// `4.5M tokens · +120 −48 · 2 PRs` — the desktop's `_MonitorStats`, each part only when the machine
+/// reported it.
+class _AgentStats extends StatelessWidget {
+ const _AgentStats({required this.agent});
+
+ final Agent agent;
+
+ @override
+ Widget build(BuildContext context) {
+ final style = _meta(AppPalette.textSecondary);
+ final stats = agent.outputStats;
+ final tokens = agent.tokensUsed;
+ final pullRequests = stats?.pullRequestsCreated;
+ final parts = <InlineSpan>[
+ if (tokens != null) TextSpan(text: '${formatCount(tokens)} tokens'),
+ if (stats != null && stats.hasEdits)
+ TextSpan(
+ children: [
+ TextSpan(
+ text: '+${formatCount(stats.linesAdded!)}',
+ style: const TextStyle(color: _addedTint),
+ ),
+ const TextSpan(text: ' '),
+ TextSpan(
+ text: '−${formatCount(stats.linesRemoved!)}',
+ style: const TextStyle(color: _removedTint),
+ ),
+ ],
+ ),
+ if (pullRequests != null)
+ TextSpan(text: '$pullRequests ${pullRequests == 1 ? 'PR' : 'PRs'}'),
+ ];
+ return Text.rich(
+ TextSpan(
+ style: style,
+ children: [
+ for (var i = 0; i < parts.length; i++) ...[
+ if (i > 0) const TextSpan(text: ' · '),
+ parts[i],
+ ],
+ ],
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ );
+ }
+}
diff --git a/mobile/lib/phone/sheet_list.dart b/mobile/lib/phone/sheet_list.dart
index 136559670..418dd3736 100644
--- a/mobile/lib/phone/sheet_list.dart
+++ b/mobile/lib/phone/sheet_list.dart
@@ -6,7 +6,6 @@ import 'package:harness_mobile/widgets/engine_identity.dart';
import 'phone_prompt_context.dart';
import 'phone_status.dart';
-import 'search_result_text.dart';
import 'status_pill.dart';
// The pieces the terminal's search sheet lists with: iOS's inset-grouped list
@@ -484,65 +483,3 @@ class SheetRowSpinner extends StatelessWidget {
);
}
}
-
-/// Where an agent is, as one line under its name:
-/// `folder · ⑂ branch · machine`.
-///
-/// One line, ellipsed from its end, rather than [AgentContextLine]'s two
-/// halves — the row has a tile and a status beside it, and halves this narrow
-/// cut both the folder and the machine to a word each.
-class SheetPlaceLine extends StatelessWidget {
- const SheetPlaceLine({
- super.key,
- required this.machine,
- this.folder,
- this.branch,
- this.note,
- this.matches = const [],
- });
-
- final String machine;
- final String? folder;
- final String? branch;
-
- /// Said first, ahead of the place — `Offline`, for an agent whose machine is.
- final String? note;
-
- /// What the query reached, so the part of the line that earned the row its
- /// place is set in bold. Empty in the tabs, where nothing was searched.
- final Iterable<PhoneFieldMatch> matches;
-
- static const _separator = ' · ';
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- final before = [
- note,
- folder,
- ].whereType<String>().where((part) => part.isNotEmpty).join(_separator);
- final branch = this.branch;
- final hasBranch = branch != null && branch.isNotEmpty;
- final text = [
- before,
- if (hasBranch) branch,
- machine,
- ].where((part) => part.isNotEmpty).join(_separator);
- return SearchResultText(
- text,
- matches: matches,
- style: sheetRowSubtitleStyle(),
- // Drawn rather than written, because `main` alone reads as a folder.
- inlineIcon: hasBranch
- ? Icon(
- LucideIcons.gitBranch300,
- size: 12,
- color: AppPalette.textFaint,
- )
- : null,
- iconOffset: hasBranch && before.isNotEmpty
- ? before.length + _separator.length
- : 0,
- );
- }
-}
diff --git a/mobile/lib/phone/sheet_search_row.dart b/mobile/lib/phone/sheet_search_row.dart
index 22f89c6cf..a92829e5f 100644
--- a/mobile/lib/phone/sheet_search_row.dart
+++ b/mobile/lib/phone/sheet_search_row.dart
@@ -4,6 +4,7 @@ import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'phone_destination.dart';
import 'phone_search_row_trailing.dart';
+import 'sheet_agent_lines.dart';
import 'search_result_text.dart';
import 'sheet_list.dart';
@@ -68,11 +69,7 @@ class SheetSearchRow extends StatelessWidget {
selected: onScreen,
onTap: openable && !busy ? _open : null,
leading: _tile(row),
- title: SearchResultText(
- _title(row),
- matches: matches.where((match) => match.title),
- style: sheetRowTitleStyle(),
- ),
+ title: _heading(row, matches),
subtitle: _subtitle(row, matches),
trailing: _trailing(row),
chevron: openable && !onScreen && !resuming,
@@ -103,6 +100,18 @@ class SheetSearchRow extends StatelessWidget {
return glyph == null || glyph.isEmpty ? null : glyph;
}
+ /// The name — for an agent, with the monitor's age and attention after it ([SheetAgentTitle]).
+ static Widget _heading(PhoneDestination row, List<PhoneFieldMatch> matches) {
+ final name = SearchResultText(
+ _title(row),
+ matches: matches.where((match) => match.title),
+ style: sheetRowTitleStyle(),
+ );
+ final entry = row.entry;
+ if (entry == null) return name;
+ return SheetAgentTitle(entry: entry, name: name, now: DateTime.now());
+ }
+
/// The name as the row draws it. A `?` row's title carries its character at
/// its head — `> Commands` — and the tile beside it already says that.
static String _title(PhoneDestination row) {
@@ -125,16 +134,8 @@ class SheetSearchRow extends StatelessWidget {
style: sheetRowSubtitleStyle(),
);
}
- final identity = row.promptContext;
- if (identity != null) {
- return SheetPlaceLine(
- machine: identity.machine ?? row.machineLabel,
- folder: identity.project,
- branch: identity.branch,
- note: identity.leading,
- matches: details,
- );
- }
+ final entry = row.entry;
+ if (entry != null) return SheetAgentMeta(entry: entry, matches: details);
if (row.detail.isEmpty) return null;
return SearchResultText(
row.detail,
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index 4b44c6439..0385c6ae1 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -50,7 +50,7 @@ packages:
source: hosted
version: "1.2.1"
collection:
- dependency: transitive
+ dependency: "direct main"
description:
name: collection
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index 3fde84dc4..0ae32ac65 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -19,6 +19,8 @@ environment:
dependencies:
flutter:
sdk: flutter
+ # `compareNatural` — the desktop's name order, so `harness 9` sorts before `harness 10` on both.
+ collection: ^1.19.1
cupertino_icons: ^1.0.8
lucide_icons_flutter: ^3.1.15
diff --git a/mobile/test/phone_search_test.dart b/mobile/test/phone_search_test.dart
index d66a3dd4c..4f8281fc3 100644
--- a/mobile/test/phone_search_test.dart
+++ b/mobile/test/phone_search_test.dart
@@ -913,7 +913,7 @@ void main() {
expect(_agentIds(_rank(app, '', cache: cache)), ['idle', 'busy']);
});
- test('the agents visited lead, in the order they were visited', () {
+ test('with nothing typed, the desktop monitor\'s order — visits do not move it', () {
final app = _app([
_machine('box', [
_agent('alpha', minutesAgo: 90),
@@ -922,17 +922,77 @@ void main() {
]),
]);
addTearDown(app.dispose);
- // Untouched, the freshest conversation leads — the catalog's own order,
- // which is what the desktop reaches for its name comparison instead of.
+ // The freshest conversation leads, as it does in the Harness Monitor.
expect(_agentIds(_rank(app, '')), ['delta', 'bravo', 'alpha']);
- // Once something HAS been reached for, the history outranks all of that:
- // the agent visited leads even though its conversation is the stalest.
+ // ⚠️ This phone's own visits used to outrank that, so the field opened on
+ // a list the laptop beside it did not show. The monitor has no idea what
+ // the phone visited; neither does its order.
expect(_agentIds(_rank(app, '', recent: ['agent:box\u0000alpha'])), [
- 'alpha',
'delta',
'bravo',
+ 'alpha',
+ ]);
+ });
+
+ test('paused work keeps its place by when it last moved', () {
+ final app = _app([
+ _machine('box', [
+ _agent('live', minutesAgo: 60),
+ _agent('paused', minutesAgo: 1, stopped: true),
+ _agent('blank', minutesAgo: 5, stopped: true, resumable: false),
+ ]),
+ ]);
+ addTearDown(app.dispose);
+ final search = PhoneSearchController(notifier: app);
+ addTearDown(search.dispose);
+
+ // `blank` cannot be opened, and still sits where the monitor has it.
+ expect(_agentIds(search.rows), ['paused', 'blank', 'live']);
+
+ // Once something is typed the match decides, and what a tap cannot open
+ // goes last, as it always has.
+ search.setQuery('work');
+ expect(_agentIds(search.rows).last, 'blank');
+ });
+
+ test('an agent is named as the desktop names it, and found by either', () {
+ final app = _app([
+ _machine('box', [
+ Agent(
+ id: 'titled',
+ name: 'Claude harness 9-23 13:52',
+ title: 'Logo update',
+ engine: 'claude',
+ updatedAt: _now,
+ terminalAvailable: true,
+ ),
+ Agent(
+ id: 'bare',
+ name: 'Terminal harness 9-23 11:35',
+ engine: 'terminal',
+ updatedAt: _now.subtract(const Duration(minutes: 5)),
+ terminalAvailable: true,
+ ),
+ Agent(
+ id: 'chosen',
+ name: 'api-server',
+ engine: 'codex',
+ updatedAt: _now.subtract(const Duration(minutes: 9)),
+ terminalAvailable: true,
+ ),
+ ]),
+ ]);
+ addTearDown(app.dispose);
+
+ expect([for (final row in _rank(app, '')) row.title], [
+ 'Logo update',
+ kUntitledPane,
+ 'api-server',
]);
+ // The CLI's name is what the terminal's title bar shows, so it still
+ // finds the row.
+ expect(_agentIds(_rank(app, 'Terminal harness')).first, 'bare');
});
test('the agent the search was opened from is not buried', () {
diff --git a/mobile/test/sheet_agent_lines_test.dart b/mobile/test/sheet_agent_lines_test.dart
new file mode 100644
index 000000000..f7165d89c
--- /dev/null
+++ b/mobile/test/sheet_agent_lines_test.dart
@@ -0,0 +1,130 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/agent_output_stats.dart';
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/phone/agent_index.dart';
+import 'package:harness_mobile/phone/compact_age.dart';
+import 'package:harness_mobile/phone/sheet_agent_lines.dart';
+import 'package:harness_mobile/state/app_state.dart';
+
+/// An agent's row in the sheet reads as the desktop's Harness Monitor reads it.
+void main() {
+ final now = DateTime.utc(2026, 9, 23, 12);
+
+ AgentEntry entryOf(Agent agent) => AgentEntry(
+ machine: MachineState(
+ const Machine(
+ machineId: 'm',
+ authMode: MachineAuthMode.remote,
+ name: 'MacBookPro2021.local',
+ ),
+ )..nodeOnline = true,
+ agent: agent,
+ );
+
+ Map<String, dynamic> wire({Object? tokenUsage, Object? outputStats}) => {
+ 'id': 'a',
+ 'name': 'api',
+ 'engine': 'claude',
+ 'tokenUsage': ?tokenUsage,
+ 'outputStats': ?outputStats,
+ };
+
+ group('what the machine measured', () {
+ test('is read as the desktop reads it', () {
+ final agent = Agent.fromJson(
+ wire(
+ tokenUsage: {
+ 'totalTokens': 4500000,
+ 'updatedAt': '2026-09-23T11:00:00Z',
+ },
+ outputStats: {
+ 'linesAdded': 120,
+ 'linesRemoved': 48,
+ 'pullRequestsCreated': 2,
+ },
+ ),
+ );
+ expect(agent.tokensUsed, 4500000);
+ expect(agent.tokensUpdatedAt, DateTime.utc(2026, 9, 23, 11));
+ expect(agent.outputStats?.linesAdded, 120);
+ expect(agent.outputStats?.pullRequestsCreated, 2);
+ expect(agent.hasMonitorStats, isTrue);
+ });
+
+ test('drops what no count could be, and half an edit pair', () {
+ final agent = Agent.fromJson(
+ wire(
+ tokenUsage: {'totalTokens': -1},
+ outputStats: {'linesAdded': 3},
+ ),
+ );
+ expect(agent.tokensUsed, isNull);
+ expect(agent.outputStats, isNull);
+ expect(agent.hasMonitorStats, isFalse);
+ });
+ });
+
+ test('counts and ages are the desktop\'s strings', () {
+ expect(formatCount(980), '980');
+ expect(formatCount(12300), '12.3k');
+ expect(formatCount(4500000), '4.5M');
+ expect(harnessActivityAge(now.subtract(const Duration(minutes: 49)), now), '49m');
+ expect(harnessActivityAge(now.subtract(const Duration(hours: 21)), now), '21h');
+ expect(harnessActivityAge(now.subtract(const Duration(days: 9)), now), '9d');
+ expect(harnessActivityAge(null, now), '—');
+ });
+
+ testWidgets('a row says its age, its trouble, its place and its output', (
+ tester,
+ ) async {
+ final entry = entryOf(
+ Agent(
+ id: 'a',
+ name: 'Respond to greeting',
+ engine: 'claude',
+ updatedAt: now.subtract(const Duration(minutes: 50)),
+ launchState: 'failed',
+ project: const AgentProject(
+ name: 'autonomous-harness',
+ cwd: '/work/autonomous-harness',
+ branch: 'main',
+ ),
+ tokensUsed: 4500000,
+ outputStats: const AgentOutputStats(
+ linesAdded: 120,
+ linesRemoved: 48,
+ pullRequestsCreated: 1,
+ ),
+ ),
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Column(
+ children: [
+ SheetAgentTitle(
+ entry: entry,
+ name: const Text('Respond to greeting'),
+ now: now,
+ ),
+ SheetAgentMeta(entry: entry),
+ ],
+ ),
+ ),
+ ),
+ );
+
+ expect(find.text('· 50m'), findsOneWidget);
+ expect(find.text('Start failed'), findsOneWidget);
+ expect(find.text('MacBookPro2021.local'), findsOneWidget);
+ expect(find.text('autonomous-harness'), findsOneWidget);
+ expect(find.text('main'), findsOneWidget);
+ expect(
+ find.textContaining('4.5M tokens', findRichText: true),
+ findsOneWidget,
+ );
+ expect(find.textContaining('+120 −48', findRichText: true), findsOneWidget);
+ expect(find.textContaining('1 PR', findRichText: true), findsOneWidget);
+ });
+}