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): add account-wide agents list to the terminal sheet

tony22d5cd6bf100
diff --git a/mobile/lib/phone/agents_list_page.dart b/mobile/lib/phone/agents_list_page.dart
new file mode 100644
index 000000000..01cfc2c34
--- /dev/null
+++ b/mobile/lib/phone/agents_list_page.dart
@@ -0,0 +1,278 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/widgets/empty_state.dart';
+import 'package:harness_mobile/state/app_state.dart';
+
+import 'agent_index.dart';
+import 'phone_header.dart';
+import 'phone_navigation.dart';
+import 'phone_search_field.dart';
+import 'phone_search_groups.dart';
+import 'phone_search_index.dart';
+import 'phone_search_rank.dart';
+import 'phone_search_row.dart';
+import 'phone_status.dart';
+import 'status_pill.dart';
+
+/// Every agent on the account, grouped by the machine it runs on.
+///
+/// [AgentsPage] answers the narrower question — one machine's agents, reached by walking into that
+/// machine — and the phone needs the wider one too: the terminal's `⋯` sheet is opened from inside
+/// an agent, and the agent somebody wants next is as often on the other laptop as on this one.
+///
+/// ⚠️ **The rows are [PhoneSearchRow], not the tabs' [PhoneCard].** This is a list somebody scans
+/// for one agent and leaves, which is what that row is built for — and the search one tap away
+/// offers the same agents in the same rows, so the two read as one list with a filter over it
+/// rather than as two features.
+class AgentsListPage extends StatefulWidget {
+ const AgentsListPage({super.key, required this.notifier, this.large = false});
+
+ final AppNotifier notifier;
+
+ /// The big title. Off where this is PUSHED — from the terminal's `⋯` sheet — where it needs the
+ /// back chevron a large header does not draw. Matches [MachinesTab.large].
+ final bool large;
+
+ @override
+ State<AgentsListPage> createState() => _AgentsListPageState();
+}
+
+class _AgentsListPageState extends State<AgentsListPage> {
+ /// The rows redraw on the agent list AND on what the agents were last asked — the second line of
+ /// a row is [SessionPreview] content, which arrives after the list does.
+ late final Listenable _changes = Listenable.merge([
+ widget.notifier,
+ widget.notifier.sessionPreviews,
+ ]);
+
+ final _controller = TextEditingController();
+ final _focus = FocusNode(debugLabel: 'Agents list search');
+ String _query = '';
+
+ @override
+ void initState() {
+ super.initState();
+ // Same warm [PhoneSearchResults] does on open, and for the same reason: the previews are what
+ // fill each row's second line, and reading them only as rows scroll into view would fill the
+ // list in visibly, line by line. Prioritised — this screen is on top, so its agents are the
+ // ones worth the next reads.
+ final notifier = widget.notifier;
+ notifier.sessionPreviews.warm([
+ for (final entry in recentAgents(agentIndex(notifier)))
+ notifier.previewKey(entry.machineId, entry.agent),
+ ], prioritize: true);
+ }
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ _focus.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) => ListenableBuilder(
+ listenable: _changes,
+ builder: (context, _) {
+ AppTheme.watch(context);
+ final all = phoneSearchIndex(widget.notifier);
+ return Scaffold(
+ backgroundColor: AppPalette.windowBg,
+ // The keyboard only comes up if the field is tapped, but when it does the list must shrink
+ // rather than run underneath it.
+ resizeToAvoidBottomInset: true,
+ body: SafeArea(
+ bottom: false,
+ child: Column(
+ children: [
+ PhoneHeader(large: widget.large, title: 'Agents'),
+ // Under the header rather than a magnifier inside it. The field is this screen's
+ // filter, not a door to another one: what it narrows is the list directly below it,
+ // and a query typed here keeps the machine headings it is filtering in view. A
+ // magnifier would have pushed a second screen over this one to answer a question
+ // this one is already showing.
+ //
+ // ⚠️ No autofocus and no back chevron in the bar — both belong to [PhoneSearchPage],
+ // where the field IS the header. Here the list is worth reading before anything is
+ // typed, and the header above already carries the way out.
+ if (all.isNotEmpty)
+ PhoneSearchField(
+ controller: _controller,
+ focus: _focus,
+ autofocus: false,
+ onChanged: (value) => setState(() => _query = value),
+ onClear: () {
+ _controller.clear();
+ setState(() => _query = '');
+ // Clearing is a step back into browsing the whole list, not out of the field —
+ // the caret stays where the next query will go.
+ _focus.requestFocus();
+ },
+ ),
+ Expanded(
+ child: _Body(
+ notifier: widget.notifier,
+ all: all,
+ query: _query.trim(),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+}
+
+class _Body extends StatelessWidget {
+ const _Body({
+ required this.notifier,
+ required this.all,
+ required this.query,
+ });
+
+ final AppNotifier notifier;
+
+ /// Every agent, most recently active first — see [recentAgents] for why recency and not the
+ /// tabs' fixed order: this screen is opened to REACH one agent, and the one reached for is
+ /// overwhelmingly the one that just finished.
+ final List<PhoneSearchResult> all;
+
+ /// Trimmed; empty means the whole list.
+ final String query;
+
+ @override
+ Widget build(BuildContext context) {
+ if (all.isEmpty) return _empty();
+ // The same ranking [PhoneSearchPage] applies, so an agent found by a word here is the agent
+ // that word finds there. Grouping happens after: ranking decides the order the rows arrive in,
+ // and [phoneMachineGroups] preserves it — so the best match still heads the first group.
+ final rows = query.isEmpty ? all : rankPhoneSearch(all, query);
+ if (rows.isEmpty) {
+ return EmptyState.noMatches(
+ compact: false,
+ message: 'Nothing matches “$query”.',
+ );
+ }
+ final groups = phoneMachineGroups(rows);
+ // ⚠️ The rows as the GROUPS hold them, not [rows] — grouping pulls a machine's agents together,
+ // so the two orders differ, and the pager below walks this one by index against what is drawn.
+ final drawn = phoneMachineGroupedRows(groups);
+ final terms = query.isEmpty ? const <String>[] : phoneSearchTerms(query);
+ final now = DateTime.now();
+ return ListView(
+ // The keyboard may be up and the finger already on the glass; dragging the list is how
+ // somebody reaches a row without putting it away first.
+ keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
+ padding: EdgeInsets.fromLTRB(
+ 16,
+ 0,
+ 16,
+ MediaQuery.paddingOf(context).bottom + 16,
+ ),
+ children: [
+ for (final group in groups) ...[
+ _MachineHeader(notifier: notifier, group: group),
+ for (final row in group.rows)
+ PhoneSearchRow(
+ row: row,
+ terms: terms,
+ now: now,
+ // The header above named the machine and nothing else, so the row still owes the
+ // folder — and must not repeat the machine.
+ place: PhoneRowContext.machined,
+ onTap: () => _open(context, drawn, row),
+ ),
+ ],
+ ],
+ );
+ }
+
+ /// Machines that are offline or unlinked contribute no agents at all ([agentIndex]), so an empty
+ /// list here is as often "no machine is answering" as "no agents exist" — and the door to both is
+ /// the same one. Machines is on the sheet this page was opened from, one back.
+ Widget _empty() => EmptyState(
+ icon: notifier.machines.isEmpty
+ ? LucideIcons.laptopMinimal300
+ : LucideIcons.squareTerminal300,
+ title: notifier.machines.isEmpty ? 'No machines yet' : 'No agents to show',
+ message: notifier.machines.isEmpty
+ ? 'Link a machine and its agents will be listed here.'
+ : 'Agents appear here once a machine is linked and answering. '
+ 'Start one from a machine, or from OpenHarness on it.',
+ );
+
+ /// Opens the agent as a pager over the other rows on screen.
+ void _open(
+ BuildContext context,
+ List<PhoneSearchResult> drawn,
+ PhoneSearchResult row,
+ ) {
+ // The keyboard goes away with the screen rather than a frame after it, so the push does not
+ // animate over a collapsing inset. [PhoneSearchRow] does this for its own tap; a row opened
+ // by any other path still has to.
+ FocusManager.instance.primaryFocus?.unfocus();
+ final entry = row.entry;
+ if (entry == null || !entry.agent.terminalAvailable) return;
+ openAgentPager(context, notifier, phoneSearchAgentEntries(drawn), entry);
+ }
+}
+
+/// The line over one machine's agents: the machine, how it is doing, and how many it holds.
+///
+/// A [StatusDot] and not a [StatusPill], though this heading is the only place the list says
+/// anything about the machine at all. Every machine listed here is one that answered — that is what
+/// [agentIndex] admits — so the pill's words would read "Ready" over group after group, for the
+/// sake of the one that says "Connecting". The dot carries that one case, and keeps its label for a
+/// long press and for a screen reader.
+class _MachineHeader extends StatelessWidget {
+ const _MachineHeader({required this.notifier, required this.group});
+
+ final AppNotifier notifier;
+ final PhoneMachineGroup group;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final machine = notifier.stateOf(group.machineId);
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(10, 14, 10, 4),
+ child: Row(
+ children: [
+ if (machine != null) ...[
+ StatusDot(summary: phoneMachineSummary(machine), size: 7),
+ const SizedBox(width: 7),
+ ],
+ // ⚠️ [Flexible] and no [Spacer]. Both take what is left over, so the two together split
+ // it — a long machine name would give up half its width to blank space instead of
+ // running on and ellipsing. The count is pushed right by this being the only flexible
+ // child, the way [PhoneSearchFolderHeader] does it.
+ Flexible(
+ child: Text(
+ group.machineName.toUpperCase(),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ color: AppPalette.textFaint,
+ fontSize: 11.5,
+ fontWeight: FontWeight.w600,
+ letterSpacing: 0.5,
+ ),
+ ),
+ ),
+ const SizedBox(width: 7),
+ Text(
+ '${group.rows.length}',
+ style: TextStyle(
+ color: AppPalette.textFaint,
+ fontSize: 12,
+ fontFeatures: AppFont.tabularFigures,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/phone_search_field.dart b/mobile/lib/phone/phone_search_field.dart
index 50cf38c05..ef92b222a 100644
--- a/mobile/lib/phone/phone_search_field.dart
+++ b/mobile/lib/phone/phone_search_field.dart
@@ -23,14 +23,27 @@ class PhoneSearchField extends StatelessWidget {
required this.focus,
required this.onChanged,
required this.onClear,
- required this.onBack,
+ this.onBack,
+ this.autofocus = true,
});
final TextEditingController controller;
final FocusNode focus;
final ValueChanged<String> onChanged;
final VoidCallback onClear;
- final VoidCallback onBack;
+
+ /// The chevron inside the bar. Null leaves it out, for a field that is not the
+ /// page's whole header — [AgentsListPage] has a [PhoneHeader] of its own above
+ /// it, whose back band is the way out, and a second chevron under the first
+ /// would be two ways back stacked one over the other.
+ final VoidCallback? onBack;
+
+ /// Whether the field takes the keyboard as it appears.
+ ///
+ /// True on [PhoneSearchPage], which exists only to be typed into. False where
+ /// the field sits over a list worth reading first: raising the keyboard there
+ /// would bury half of what the person opened the screen to look at.
+ final bool autofocus;
@override
Widget build(BuildContext context) {
@@ -63,12 +76,18 @@ class PhoneSearchField extends StatelessWidget {
),
child: Row(
children: [
- _BackButton(onTap: onBack),
+ if (onBack != null)
+ _BackButton(onTap: onBack!)
+ else
+ // The chevron's place, so the text starts on the same vertical
+ // whether or not the bar carries one.
+ const SizedBox(width: 14),
Expanded(
child: _QueryInput(
controller: controller,
focus: focus,
onChanged: onChanged,
+ autofocus: autofocus,
),
),
_ClearButton(controller: controller, onTap: onClear),
@@ -114,11 +133,13 @@ class _QueryInput extends StatelessWidget {
required this.controller,
required this.focus,
required this.onChanged,
+ required this.autofocus,
});
final TextEditingController controller;
final FocusNode focus;
final ValueChanged<String> onChanged;
+ final bool autofocus;
@override
Widget build(BuildContext context) {
@@ -126,7 +147,7 @@ class _QueryInput extends StatelessWidget {
return TextField(
controller: controller,
focusNode: focus,
- autofocus: true,
+ autofocus: autofocus,
onChanged: onChanged,
// The list is already filtered by the time a key is released; there is
// nothing left for the return key to submit, so it stays a plain "done"
diff --git a/mobile/lib/phone/phone_search_groups.dart b/mobile/lib/phone/phone_search_groups.dart
index 185d66530..f4d008822 100644
Binary files a/mobile/lib/phone/phone_search_groups.dart and b/mobile/lib/phone/phone_search_groups.dart differ
diff --git a/mobile/lib/phone/phone_search_index.dart b/mobile/lib/phone/phone_search_index.dart
index dcad81a9b..af804ff34 100644
--- a/mobile/lib/phone/phone_search_index.dart
+++ b/mobile/lib/phone/phone_search_index.dart
@@ -26,6 +26,7 @@ class PhoneSearchResult {
required this.title,
required this.subtitle,
required this.placedSubtitle,
+ required this.machinedSubtitle,
required this.fields,
required this.summary,
required this.machineId,
@@ -53,6 +54,14 @@ class PhoneSearchResult {
/// folder and the machine.
final String placedSubtitle;
+ /// The line under it when a MACHINE header above the row already names the
+ /// machine but nothing names the folder — the agents list, which groups by
+ /// machine and no deeper. [placedSubtitle] minus the machine: repeating it
+ /// down every row of a group whose header just said it is the noise the
+ /// header was added to remove, and the folder is what tells the group's own
+ /// rows apart.
+ final String machinedSubtitle;
+
/// Every searchable string, lowercased, title first. Not everything in here is
/// drawn — an agent's engine id is matched but never shown as itself — which is
/// why [SearchResultText] re-checks that a matched field is actually present in
@@ -116,6 +125,7 @@ PhoneSearchResult _agentResult(AgentEntry entry, SessionPreview? preview) {
// the mark's to show and is only spelled out when nothing else is known.
subtitle: _joined([title, branch]).ifEmpty(engine),
placedSubtitle: _joined([title, folder, entry.machineName]).ifEmpty(engine),
+ machinedSubtitle: _joined([title, folder]).ifEmpty(engine),
fields: [
agent.name,
title,
diff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dart
index 5995ba43e..12cfcf5b5 100644
--- a/mobile/lib/phone/phone_search_results.dart
+++ b/mobile/lib/phone/phone_search_results.dart
@@ -113,7 +113,7 @@ class _PhoneSearchResultsState extends State<PhoneSearchResults> {
row: row,
terms: const [],
now: now,
- placed: true,
+ place: PhoneRowContext.placed,
onTap: () => _open(rows, row),
),
],
diff --git a/mobile/lib/phone/phone_search_row.dart b/mobile/lib/phone/phone_search_row.dart
index 92f53d8cc..bf4cbd84f 100644
--- a/mobile/lib/phone/phone_search_row.dart
+++ b/mobile/lib/phone/phone_search_row.dart
@@ -11,6 +11,35 @@ import 'phone_status.dart';
import 'search_result_text.dart';
import 'status_pill.dart';
+/// How much of where an agent lives the row has to say for itself, which is
+/// decided by what the list draws ABOVE it.
+///
+/// One enum rather than a second boolean beside [PhoneSearchRow.placed] was:
+/// the three cases are exclusive, and a row that answered to two flags could be
+/// asked to repeat the machine its header just named.
+enum PhoneRowContext {
+ /// A folder header over the row names both the folder and the machine, so the
+ /// row's second line is free for what tells its agents apart.
+ grouped(),
+
+ /// Nothing above the row places it: it names its own work, folder and
+ /// machine. The search's Recent run.
+ placed(),
+
+ /// A machine header over the row names the machine and nothing else, so the
+ /// row still owes the folder. [AgentsListPage].
+ machined();
+
+ const PhoneRowContext();
+
+ /// The line this context asks [row] for.
+ String subtitleOf(PhoneSearchResult row) => switch (this) {
+ PhoneRowContext.grouped => row.subtitle,
+ PhoneRowContext.placed => row.placedSubtitle,
+ PhoneRowContext.machined => row.machinedSubtitle,
+ };
+}
+
/// One result: the mark, the two lines, and what is worth knowing before a tap.
///
/// Shorter than the tabs' 70pt [PhoneCard] and without its fill. A result list
@@ -24,7 +53,7 @@ class PhoneSearchRow extends StatefulWidget {
required this.terms,
required this.now,
required this.onTap,
- this.placed = false,
+ this.place = PhoneRowContext.grouped,
});
final PhoneSearchResult row;
@@ -35,9 +64,9 @@ class PhoneSearchRow extends StatefulWidget {
final DateTime now;
final VoidCallback onTap;
- /// Whether the row has to say where it is itself — no folder header over it,
- /// as in the Recent list. See [PhoneSearchResult.placedSubtitle].
- final bool placed;
+ /// How much of where the agent lives this row still owes — see
+ /// [PhoneRowContext], which is decided by the header the list draws over it.
+ final PhoneRowContext place;
@override
State<PhoneSearchRow> createState() => _PhoneSearchRowState();
@@ -118,8 +147,7 @@ class _PhoneSearchRowState extends State<PhoneSearchRow> {
),
const SizedBox(height: 3),
SearchResultText(
- quote ??
- (widget.placed ? row.placedSubtitle : row.subtitle),
+ quote ?? widget.place.subtitleOf(row),
matches: quote == null
? matches
: phoneContentMatches(widget.terms),
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 94222bdf2..59c0dcc50 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -21,6 +21,7 @@ import 'package:harness_mobile/terminal/terminal_session.dart';
import 'package:harness_mobile/widgets/rename_agent_dialog.dart';
import 'package:harness_mobile/widgets/terminal_panel.dart';
+import 'agents_list_page.dart';
import 'agents_page.dart' show openNewAgent;
import 'delete_agent.dart';
import 'held_height.dart';
@@ -402,6 +403,17 @@ class _TerminalPageState extends State<TerminalPage>
if (mounted) setState(() {});
}
+ /// Opens the account-wide agent list.
+ ///
+ /// Awaited for the same reason [_newAgent] is: the list is backed out of as often as it is tapped
+ /// through, and this page gets no rebuild when it lands back on top.
+ Future<void> _openAgentList() async {
+ await Navigator.of(context).push(
+ phoneRoute((_) => AgentsListPage(notifier: widget.notifier)),
+ );
+ if (mounted) setState(() {});
+ }
+
/// Fades the search screen up over the terminal.
///
/// ⚠️ The overlay is mounted on THIS frame and the animation started on it,
@@ -1121,9 +1133,9 @@ class _TerminalPageState extends State<TerminalPage>
// behind its icon. The header has no room for the path.
titleParts: [agentName],
titleDetail: AgentPlaceLines(machineName: machineName, project: project),
- // Two groups: what acts on THIS agent, and the two screens the app itself has. Machines is a
- // door like Settings rather than a list of its own — the list belongs on the page behind it,
- // where it has room for every machine and does not push the rest of this sheet down.
+ // Two groups: what acts on THIS agent, and the screens the app itself has. Each of those is a
+ // door rather than a list of its own — the lists belong on the pages behind them, where they
+ // have room for every row and do not push the rest of this sheet down.
sections: [
PhoneSheetSection(
caption: 'Agent',
@@ -1132,6 +1144,17 @@ class _TerminalPageState extends State<TerminalPage>
PhoneSheetSection(
caption: 'App',
actions: [
+ // Every agent on the account, not just this machine's: the sheet is opened from inside
+ // one agent, and the thing somebody wants from here is another agent — which is as
+ // often on the other laptop as on this one.
+ //
+ // [AgentsListPage] draws them, with the magnifier in its header for when the list is
+ // longer than a screenful.
+ PhoneSheetAction(
+ icon: LucideIcons.squareTerminal300,
+ label: 'Agents',
+ onTap: () => unawaited(_openAgentList()),
+ ),
PhoneSheetAction(
icon: LucideIcons.laptopMinimal300,
label: 'Machines',