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 context display with folder and branch information

Dev jacob6328fbf6fd0d
diff --git a/mobile/lib/core/models.dart b/mobile/lib/core/models.dart
index f04bba77d..ca0408391 100644
--- a/mobile/lib/core/models.dart
+++ b/mobile/lib/core/models.dart
@@ -388,6 +388,23 @@ class AgentProject {
String identity(String machineId) =>
remote != null ? 'repo:$remote' : 'folder:$machineId:${root ?? cwd}';
+ /// The folder a person names this agent by: the last segment of [cwd], falling back to [name]
+ /// when the path has no segment to take (a root, or a bare drive).
+ ///
+ /// The tail rather than the whole path, because every row that shows it is width-starved — a
+ /// phone card, a pane header — and `/Users/…/WorkPlace/Grid/autonomous-harness` spends all of
+ /// that width on the prefix that is identical for every agent somebody owns.
+ String get folder {
+ final parts = cwd.split(RegExp(r'[/\\]')).where((part) => part.isNotEmpty);
+ return parts.isEmpty ? name : parts.last;
+ }
+
+ /// The branch, or null when the daemon reported none or reported it blank.
+ String? get branchLabel {
+ final trimmed = branch?.trim();
+ return trimmed == null || trimmed.isEmpty ? null : trimmed;
+ }
+
@override
bool operator ==(Object other) =>
other is AgentProject &&
diff --git a/mobile/lib/phone/agent_context_line.dart b/mobile/lib/phone/agent_context_line.dart
new file mode 100644
index 000000000..829e978d5
--- /dev/null
+++ b/mobile/lib/phone/agent_context_line.dart
@@ -0,0 +1,88 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+/// Where an agent IS: the folder it was started in, the branch that folder is on, and the machine
+/// running it — `autonomous-harness · ⑂ main · MacBookPro2021.local`.
+///
+/// The same three facts, in the same order, as the desktop's pane header
+/// (`widgets/terminal_pane_header.dart`), so an agent recognised on one screen is recognised on the
+/// other. A name alone stops identifying anything the moment somebody has two `main` agents, which
+/// on a phone — where the Agents tab mixes every machine into one list — happens immediately.
+///
+/// ⚠️ **Two flexible halves, not one line of text.** A phone row leaves this about 240pt, and the
+/// three together want more than that: `autonomous-harness · ⑂ feat/mobile-ios-android` alone fills
+/// it. Written as a single ellipsised line, the machine — the last of the three, and the reason the
+/// line exists on a list that mixes machines — is the part that disappears entirely. Split in two,
+/// each half truncates within its own share instead, so the machine is always at least begun.
+///
+/// Which leaves the branch as the one that gives way, and deliberately: it shares the left half
+/// with the folder and is cut first when that half runs out. It is the least use in *finding* an
+/// agent, and the terminal page names it in full once one is open.
+class AgentContextLine extends StatelessWidget {
+ const AgentContextLine({
+ super.key,
+ required this.project,
+ required this.machineName,
+ });
+
+ /// Null on a daemon too old to report it, and until the first agent snapshot binds one. The line
+ /// then names the machine alone rather than holding a gap open where the folder would be.
+ final AgentProject? project;
+
+ final String machineName;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final branch = project?.branchLabel;
+ final place = <InlineSpan>[
+ if (project != null) TextSpan(text: project!.folder),
+ if (project != null && branch != null) _separator,
+ if (branch != null) ...[_branchMark, TextSpan(text: branch)],
+ ];
+ return Row(
+ children: [
+ if (place.isNotEmpty) Flexible(child: _line(place)),
+ Flexible(
+ child: _line([
+ if (place.isNotEmpty) _separator,
+ TextSpan(text: machineName),
+ ]),
+ ),
+ ],
+ );
+ }
+
+ Widget _line(List<InlineSpan> spans) => Text.rich(
+ TextSpan(children: spans),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ color: AppPalette.textSecondary,
+ fontSize: 12.5,
+ fontWeight: FontWeight.w500,
+ ),
+ );
+
+ static TextSpan get _separator => TextSpan(
+ text: ' · ',
+ style: TextStyle(color: AppPalette.textFaint),
+ );
+
+ /// Drawn rather than written, because `main` alone reads as a folder — the same glyph the
+ /// desktop's header puts in front of a branch.
+ static WidgetSpan get _branchMark => WidgetSpan(
+ alignment: PlaceholderAlignment.middle,
+ child: Padding(
+ padding: const EdgeInsets.only(right: 3.5),
+ child: Icon(
+ LucideIcons.gitBranch300,
+ size: 12,
+ color: AppPalette.textFaint,
+ ),
+ ),
+ );
+}
diff --git a/mobile/lib/phone/agent_index.dart b/mobile/lib/phone/agent_index.dart
index a18695bda..d93c6e180 100644
--- a/mobile/lib/phone/agent_index.dart
+++ b/mobile/lib/phone/agent_index.dart
@@ -1,5 +1,6 @@
import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/state/app_state.dart';
+
import 'phone_status.dart';
/// One agent, together with the machine it runs on.
@@ -17,6 +18,11 @@ class AgentEntry {
String get machineId => machine.machine.machineId;
String get machineName => machine.machine.displayName;
+ /// The folder this agent works in, as [AgentContextLine] names it. Through [MachineState.projectOf]
+ /// rather than `agent.project` directly: a locally launched agent carries its project on the
+ /// machine's own side, and a row reading the field alone shows nothing for exactly those agents.
+ AgentProject? get project => machine.projectOf(agent);
+
/// Whether this agent is blocked on an answer from the person holding the phone.
bool get isWaiting => machine.blockedAgents.containsKey(agent.id);
diff --git a/mobile/lib/phone/agent_row.dart b/mobile/lib/phone/agent_row.dart
index b5bbbfbe1..7500524f4 100644
--- a/mobile/lib/phone/agent_row.dart
+++ b/mobile/lib/phone/agent_row.dart
@@ -3,15 +3,17 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/widgets/engine_identity.dart';
+
+import 'agent_context_line.dart';
import 'agent_index.dart';
import 'phone_card.dart';
import 'status_pill.dart';
-/// One agent in the Agents tab.
+/// One agent in the Agents tab: who it is, what it is doing, and where it is.
///
-/// Differs from [AgentTile] — the row a single machine's page draws — in the one way the tab needs:
-/// it names the MACHINE, because this list mixes them and a name alone is ambiguous the moment two
-/// machines both have a `main` or a `docs` agent.
+/// The same three lines [AgentTile] draws on a machine's own page — the two rows differ now only in
+/// where they get their agent from, and both end in [AgentContextLine] so one agent reached two
+/// ways is not described two ways.
class AgentRow extends StatelessWidget {
const AgentRow({
super.key,
@@ -33,6 +35,7 @@ class AgentRow extends StatelessWidget {
AppTheme.watch(context);
final agent = entry.agent;
return PhoneCard(
+ height: kPhoneAgentCardHeight,
onTap: agent.terminalAvailable ? onTap : null,
onLongPress: onLongPress,
// A rim in the attention colour, so a waiting agent is findable in a long list without
@@ -65,8 +68,13 @@ class AgentRow extends StatelessWidget {
fontWeight: FontWeight.w600,
),
),
- const SizedBox(height: 5),
- _StatusAndMachine(entry: entry),
+ const SizedBox(height: 3),
+ StatusPill(summary: entry.summary),
+ const SizedBox(height: 3),
+ AgentContextLine(
+ project: entry.project,
+ machineName: entry.machineName,
+ ),
],
),
),
@@ -82,34 +90,3 @@ class AgentRow extends StatelessWidget {
);
}
}
-
-/// The status line, with the machine's name after it.
-///
-/// One line rather than two: a phone row is 70pt and a third line of type would either shrink the
-/// name above it or push the card taller than a thumb's reach for the list.
-class _StatusAndMachine extends StatelessWidget {
- const _StatusAndMachine({required this.entry});
-
- final AgentEntry entry;
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- return Row(
- children: [
- Flexible(child: StatusPill(summary: entry.summary)),
- const SizedBox(width: 6),
- // The machine is context, not status, so it is drawn a step quieter than the pill it
- // follows — and it yields its width first when both cannot fit.
- Flexible(
- child: Text(
- '· ${entry.machineName}',
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(color: AppPalette.textFaint, fontSize: 13),
- ),
- ),
- ],
- );
- }
-}
diff --git a/mobile/lib/phone/agent_tile.dart b/mobile/lib/phone/agent_tile.dart
index 71c1bcc56..b4c3b8b16 100644
--- a/mobile/lib/phone/agent_tile.dart
+++ b/mobile/lib/phone/agent_tile.dart
@@ -6,13 +6,19 @@ import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/widgets/engine_identity.dart';
+import 'agent_context_line.dart';
import 'phone_card.dart';
import 'phone_status.dart';
import 'status_pill.dart';
-/// One agent on a machine's page: its engine, its name, and what it is doing. An agent with no
-/// terminal to attach is drawn dimmed and does not open — but it can still be held for [onLongPress],
-/// which is the only way to reach an agent whose terminal has gone.
+/// One agent on a machine's page: its engine, its name, what it is doing, and — [AgentContextLine] —
+/// the folder and branch it is working in. An agent with no terminal to attach is drawn dimmed and
+/// does not open, but it can still be held for [onLongPress], which is the only way to reach an
+/// agent whose terminal has gone.
+///
+/// The machine is named on the line too, though this page is already about one machine: the row is
+/// the same row the Agents tab draws, and an agent should not read differently depending on which
+/// door was used to reach it.
class AgentTile extends StatelessWidget {
const AgentTile({
super.key,
@@ -31,6 +37,7 @@ class AgentTile extends StatelessWidget {
Widget build(BuildContext context) {
AppTheme.watch(context);
return PhoneCard(
+ height: kPhoneAgentCardHeight,
onTap: agent.terminalAvailable ? onTap : null,
onLongPress: onLongPress,
child: Row(
@@ -58,8 +65,13 @@ class AgentTile extends StatelessWidget {
fontWeight: FontWeight.w600,
),
),
- const SizedBox(height: 5),
+ const SizedBox(height: 3),
StatusPill(summary: phoneAgentSummary(machine, agent)),
+ const SizedBox(height: 3),
+ AgentContextLine(
+ project: machine.projectOf(agent),
+ machineName: machine.machine.displayName,
+ ),
],
),
),
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dart
index 10a998398..6c5cd71ed 100644
--- a/mobile/lib/phone/agents_page.dart
+++ b/mobile/lib/phone/agents_page.dart
@@ -227,7 +227,7 @@ class _AgentsBody extends StatelessWidget {
);
}
if (agents.isEmpty && status == PhoneMachineStatus.connecting) {
- return const PhoneListSkeleton();
+ return const PhoneListSkeleton(height: kPhoneAgentCardHeight);
}
final loadError = machine.agentsLoadError;
if (agents.isEmpty && loadError != null) {
diff --git a/mobile/lib/phone/agents_tab.dart b/mobile/lib/phone/agents_tab.dart
index 184010b4d..54e77c33e 100644
--- a/mobile/lib/phone/agents_tab.dart
+++ b/mobile/lib/phone/agents_tab.dart
@@ -178,7 +178,7 @@ class _Body extends StatelessWidget {
Widget build(BuildContext context) {
if (entries.isEmpty) {
if (notifier.machines.isEmpty && notifier.machinesLoading) {
- return const PhoneListSkeleton();
+ return const PhoneListSkeleton(height: kPhoneAgentCardHeight);
}
if (notifier.machines.isEmpty) {
return const EmptyState(
@@ -189,7 +189,9 @@ class _Body extends StatelessWidget {
'will appear here.',
);
}
- if (_stillArriving) return const PhoneListSkeleton();
+ if (_stillArriving) {
+ return const PhoneListSkeleton(height: kPhoneAgentCardHeight);
+ }
if (filtered) {
return const EmptyState(
icon: LucideIcons.squareTerminal300,
diff --git a/mobile/lib/phone/phone_card.dart b/mobile/lib/phone/phone_card.dart
index 83575b625..742c15d39 100644
--- a/mobile/lib/phone/phone_card.dart
+++ b/mobile/lib/phone/phone_card.dart
@@ -10,6 +10,12 @@ const double kPhoneCardGap = 10;
/// this, so a list that answers does not jump.
const double kPhoneCardHeight = 70;
+/// An agent card's height. Taller than [kPhoneCardHeight] by one line, because an agent row carries
+/// a third: its name, what it is doing, and — [AgentContextLine] — where it is. The alternative was
+/// folding the folder and the machine into the status line, which is what the Agents tab did while
+/// it had two lines, and at that width the status was the part that truncated.
+const double kPhoneAgentCardHeight = 88;
+
/// A phone list's padding: clear of the screen edges, and of the home indicator at the bottom.
EdgeInsets phoneListPadding(BuildContext context) =>
EdgeInsets.fromLTRB(16, 4, 16, MediaQuery.paddingOf(context).bottom + 24);
@@ -23,6 +29,7 @@ class PhoneCard extends StatefulWidget {
this.onTap,
this.onLongPress,
this.border,
+ this.height = kPhoneCardHeight,
});
final Widget child;
@@ -40,6 +47,11 @@ class PhoneCard extends StatefulWidget {
/// so it is findable in a long list before a word of it is read. Null keeps the ordinary rim.
final BoxBorder? border;
+ /// The row's height. [kPhoneAgentCardHeight] for the three-line agent rows; the two-line default
+ /// for everything else. Fixed either way, so a list of cards stays a regular column rather than
+ /// a ladder of uneven rungs.
+ final double height;
+
@override
State<PhoneCard> createState() => _PhoneCardState();
}
@@ -78,7 +90,7 @@ class _PhoneCardState extends State<PhoneCard> {
child: AnimatedContainer(
duration: AppMotion.press,
curve: AppMotion.curve,
- height: kPhoneCardHeight,
+ height: widget.height,
padding: const EdgeInsets.symmetric(horizontal: 13),
decoration: BoxDecoration(
color: _pressed ? AppGlass.rowHoverFill : AppGlass.rowFill,
@@ -144,19 +156,27 @@ class PhoneCardList extends StatelessWidget {
/// A list of cards that has not answered yet: the same cards, empty, at a real row's height.
class PhoneListSkeleton extends StatelessWidget {
- const PhoneListSkeleton({super.key, this.rows = 3});
+ const PhoneListSkeleton({
+ super.key,
+ this.rows = 3,
+ this.height = kPhoneCardHeight,
+ });
final int rows;
+ /// The height of the cards this list is standing in for — pass [kPhoneAgentCardHeight] where
+ /// agents will land, so the list does not jump a row taller the moment they arrive.
+ final double height;
+
@override
Widget build(BuildContext context) => ListView.separated(
physics: const NeverScrollableScrollPhysics(),
padding: phoneListPadding(context),
itemCount: rows,
separatorBuilder: (_, _) => const SizedBox(height: kPhoneCardGap),
- itemBuilder: (_, _) => const Skeleton(
+ itemBuilder: (_, _) => Skeleton(
width: double.infinity,
- height: kPhoneCardHeight,
+ height: height,
radius: AppCard.radius,
),
);
diff --git a/mobile/lib/phone/phone_search_index.dart b/mobile/lib/phone/phone_search_index.dart
index 619999ace..74fbb79f5 100644
--- a/mobile/lib/phone/phone_search_index.dart
+++ b/mobile/lib/phone/phone_search_index.dart
@@ -78,14 +78,21 @@ List<PhoneSearchResult> phoneSearchIndex(AppNotifier notifier) {
for (final entry in visibleAgents(agentIndex(notifier))) {
final agent = entry.agent;
final engine = agent.engineDisplayName ?? agent.engine ?? '';
+ final folder = entry.project?.folder ?? '';
results.add(
PhoneSearchResult(
kind: PhoneSearchKind.agent,
id: 'agent:${entry.machineId}:${agent.id}',
title: agent.name,
- subtitle: engine.isEmpty
- ? entry.machineName
- : '$engine · ${entry.machineName}',
+ // The tabs' rows carry the folder too ([AgentContextLine]); a result row
+ // has one line for all of it, so the three land in the same order on it,
+ // and the machine — the longest and the least distinguishing — ellipses
+ // off the end first.
+ subtitle: [
+ if (engine.isNotEmpty) engine,
+ if (folder.isNotEmpty) folder,
+ entry.machineName,
+ ].join(' · '),
fields: [
agent.name.toLowerCase(),
entry.machineName.toLowerCase(),
@@ -93,13 +100,14 @@ List<PhoneSearchResult> phoneSearchIndex(AppNotifier notifier) {
// The raw engine id as well as its display name: somebody types
// "codex", and the display name may well be "Codex CLI".
(agent.engine ?? '').toLowerCase(),
- // Neither the project nor its branch is drawn on a phone row — there
- // is no third line for either — but they are how people describe the
- // agent they are hunting for, so both stay searchable. [SearchResultText]
- // checks that a matched field is present in the text it is about to
- // emphasise, so matching here never bolds something unrelated.
- (agent.project?.name ?? '').toLowerCase(),
- (agent.project?.branch ?? '').toLowerCase(),
+ folder.toLowerCase(),
+ // The project's own name and its branch are not drawn on a result row,
+ // but they are how people describe the agent they are hunting for, so
+ // both stay searchable. [SearchResultText] checks that a matched field
+ // is present in the text it is about to emphasise, so matching here
+ // never bolds something unrelated.
+ (entry.project?.name ?? '').toLowerCase(),
+ (entry.project?.branchLabel ?? '').toLowerCase(),
].where((field) => field.isNotEmpty).toList(),
summary: entry.summary,
machineId: entry.machineId,
@@ -192,11 +200,7 @@ List<PhoneSearchResult> rankPhoneSearch(
for (final term in terms) {
int? best;
for (final (fieldIndex, field) in row.fields.indexed) {
- final score = phoneFieldMatchScore(
- field,
- term,
- title: fieldIndex == 0,
- );
+ final score = phoneFieldMatchScore(field, term, title: fieldIndex == 0);
if (score == null) continue;
if (best == null || score < best) best = score;
// Every field after the first is metadata, whose best possible score is
diff --git a/mobile/lib/widgets/terminal_pane_header.dart b/mobile/lib/widgets/terminal_pane_header.dart
index 87b7a96a0..85f5baf55 100644
--- a/mobile/lib/widgets/terminal_pane_header.dart
+++ b/mobile/lib/widgets/terminal_pane_header.dart
@@ -119,11 +119,13 @@ class TerminalPaneHeader extends StatelessWidget {
.firstOrNull;
final project = agent == null ? null : machine?.projectOf(agent);
final machineName = machine?.machine.displayName ?? session.machineId;
+ final folder = project?.folder;
+ final branch = project?.branchLabel;
final identityDetail = [
session.agentName,
machineName,
if (project != null) project.cwd,
- if (project?.branch != null) 'Branch: ${project!.branch}',
+ if (branch != null) 'Branch: $branch',
if (profile != null) 'Codex profile: $profile',
'Double-click to rename',
].join('\n');
@@ -131,20 +133,8 @@ class TerminalPaneHeader extends StatelessWidget {
? onToggleComposer
: null;
final actionsWidth = remoteComposer == null ? 88.0 : 118.0;
- final folder =
- project?.cwd
- .split(RegExp(r'[/\\]'))
- .where((part) => part.isNotEmpty)
- .lastOrNull ??
- project?.name;
- final details = [
- if (folder?.isNotEmpty == true) folder!,
- if (project?.branch?.trim().isNotEmpty == true) project!.branch!,
- machineName,
- ];
- final branchIndex = project?.branch?.trim().isNotEmpty == true
- ? (folder?.isNotEmpty == true ? 1 : 0)
- : null;
+ final details = [?folder, ?branch, machineName];
+ final branchIndex = branch == null ? null : (folder == null ? 0 : 1);
final strip = PaneHeaderHover(
child: SizedBox(
height: compact ? 38 : 46,
@@ -271,8 +261,7 @@ class TerminalPaneHeader extends StatelessWidget {
details: Tooltip(
message: [
if (project != null) project.cwd,
- if (project?.branch?.isNotEmpty == true)
- 'Branch: ${project!.branch}',
+ if (branch != null) 'Branch: $branch',
machineName,
].join('\n'),
child: Row(
diff --git a/mobile/test/agent_context_line_test.dart b/mobile/test/agent_context_line_test.dart
new file mode 100644
index 000000000..6a896d4ee
--- /dev/null
+++ b/mobile/test/agent_context_line_test.dart
@@ -0,0 +1,76 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/phone/agent_context_line.dart';
+
+/// Every character the line actually renders, in order — `find.text` matches a plain string and so
+/// sees nothing of a line built from spans across two halves.
+String _rendered(WidgetTester tester) => [
+ for (final text in tester.widgetList<Text>(find.byType(Text)))
+ text.textSpan!.toPlainText(),
+].join();
+
+Future<void> _pump(
+ WidgetTester tester, {
+ required AgentProject? project,
+ String machineName = 'MacBookPro2021.local',
+}) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: AgentContextLine(project: project, machineName: machineName),
+ ),
+ ),
+ );
+}
+
+void main() {
+ testWidgets('names the folder, the branch and the machine, in that order', (
+ tester,
+ ) async {
+ await _pump(
+ tester,
+ project: const AgentProject(
+ name: 'Harness',
+ cwd: '/Users/dev/WorkPlace/Grid/autonomous-harness',
+ branch: 'main',
+ ),
+ );
+ expect(_rendered(tester), contains('autonomous-harness'));
+ expect(
+ _rendered(tester).indexOf('main'),
+ greaterThan(_rendered(tester).indexOf('autonomous-harness')),
+ );
+ expect(
+ _rendered(tester).indexOf('MacBookPro2021.local'),
+ greaterThan(_rendered(tester).indexOf('main')),
+ );
+ });
+
+ testWidgets('the folder is the tail of the path, not the project name', (
+ tester,
+ ) async {
+ await _pump(
+ tester,
+ project: const AgentProject(name: 'Harness', cwd: '/srv/apps/backend'),
+ );
+ expect(_rendered(tester), contains('backend'));
+ expect(_rendered(tester), isNot(contains('Harness')));
+ expect(_rendered(tester), isNot(contains('/srv/apps')));
+ });
+
+ testWidgets('a blank branch draws no separator of its own', (tester) async {
+ await _pump(
+ tester,
+ project: const AgentProject(name: 'x', cwd: '/srv/api', branch: ' '),
+ );
+ expect(_rendered(tester), 'api · MacBookPro2021.local');
+ });
+
+ testWidgets('with no project reported, the machine still stands alone', (
+ tester,
+ ) async {
+ await _pump(tester, project: null);
+ expect(_rendered(tester), 'MacBookPro2021.local');
+ });
+}