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): group the terminal ⋯ sheet into Agent, Machines and App; machines leave search

bubu-dudu412c311dbf63
diff --git a/mobile/lib/phone/machine_actions.dart b/mobile/lib/phone/machine_actions.dart
new file mode 100644
index 000000000..edb139a6b
--- /dev/null
+++ b/mobile/lib/phone/machine_actions.dart
@@ -0,0 +1,102 @@
+import 'dart:async';
+
+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/state/app_state.dart';
+
+import 'link_page.dart';
+import 'machine_index.dart';
+import 'phone_navigation.dart';
+import 'phone_sheet.dart';
+import 'phone_status.dart';
+import 'unlink_machine.dart';
+
+/// Every machine on the account as sheet rows, for the terminal's `⋯` menu — where machines are
+/// reached now that search lists agents only.
+///
+/// Each row carries its state as a word, and does what that state calls for: a password form, a
+/// sheet of actions, or — offline — nothing, drawn dimmed so its absence is not a mystery.
+List<PhoneSheetAction> machineSheetRows(
+ BuildContext context,
+ AppNotifier notifier,
+) => [
+ for (final machine in visibleMachines(notifier))
+ PhoneSheetAction(
+ icon: LucideIcons.laptopMinimal300,
+ label: machine.machine.displayName,
+ value: _stateWord(machine),
+ valueColor: _stateColor(machine),
+ enabled: phoneMachineStatusOf(machine) != PhoneMachineStatus.offline,
+ onTap: () =>
+ openMachineActions(context, notifier, machine.machine.machineId),
+ ),
+];
+
+/// Green for a machine that answers, yellow for one waiting on its password — the two states worth
+/// telling apart at a glance. The rest keep the row's faint colour.
+Color? _stateColor(MachineState machine) =>
+ switch (phoneMachineStatusOf(machine)) {
+ PhoneMachineStatus.ready => AppPalette.online,
+ PhoneMachineStatus.needsPassword => AppPalette.warn,
+ PhoneMachineStatus.connecting => AppPalette.accent,
+ PhoneMachineStatus.offline => null,
+ };
+
+String _stateWord(MachineState machine) =>
+ switch (phoneMachineStatusOf(machine)) {
+ PhoneMachineStatus.ready => 'Connected',
+ PhoneMachineStatus.connecting => 'Connecting…',
+ PhoneMachineStatus.needsPassword => 'Unlock',
+ PhoneMachineStatus.offline => 'Offline',
+ };
+
+/// A machine that wants its password opens the form for it. One that is linked opens a sheet of
+/// what can be done TO it — reload its agents, re-enter its password, unlink this phone.
+///
+/// Read at the tap, not when the row was drawn, so a machine that got linked in between gets the
+/// sheet rather than a form it no longer needs.
+void openMachineActions(
+ BuildContext context,
+ AppNotifier notifier,
+ String machineId,
+) {
+ final machine = notifier.stateOf(machineId);
+ if (machine == null) return;
+ switch (phoneMachineStatusOf(machine)) {
+ case PhoneMachineStatus.offline:
+ return;
+ case PhoneMachineStatus.needsPassword:
+ openMachine(context, notifier, machineId);
+ return;
+ case PhoneMachineStatus.connecting || PhoneMachineStatus.ready:
+ break;
+ }
+ showPhoneSheet(
+ context,
+ title: machine.machine.displayName,
+ actions: [
+ PhoneSheetAction(
+ icon: LucideIcons.refreshCw300,
+ label: 'Reload agents',
+ onTap: () => unawaited(notifier.reloadMachineData(machineId)),
+ ),
+ PhoneSheetAction(
+ icon: LucideIcons.keyRound300,
+ label: 'Re-enter password…',
+ onTap: () => Navigator.of(context).push(
+ phoneRoute((_) => LinkPage(notifier: notifier, machineId: machineId)),
+ ),
+ ),
+ // No confirmation, the same as the Machines tab: this sheet is the step between the tap and
+ // the unlink.
+ PhoneSheetAction(
+ icon: LucideIcons.unlink300,
+ label: 'Unlink this phone',
+ destructive: true,
+ onTap: () => unawaited(unlinkThisPhone(context, notifier, machine)),
+ ),
+ ],
+ );
+}
diff --git a/mobile/lib/phone/phone_search_field.dart b/mobile/lib/phone/phone_search_field.dart
index 0713bb45f..0f7acf26a 100644
--- a/mobile/lib/phone/phone_search_field.dart
+++ b/mobile/lib/phone/phone_search_field.dart
@@ -164,7 +164,7 @@ class _QueryInput extends StatelessWidget {
filled: false,
contentPadding: EdgeInsets.zero,
constraints: const BoxConstraints(),
- hintText: 'Search agents and machines',
+ hintText: 'Search agents',
hintStyle: TextStyle(color: AppPalette.textFaint, fontSize: 16),
),
);
diff --git a/mobile/lib/phone/phone_search_index.dart b/mobile/lib/phone/phone_search_index.dart
index 0edfbbf24..c7f8d6971 100644
--- a/mobile/lib/phone/phone_search_index.dart
+++ b/mobile/lib/phone/phone_search_index.dart
@@ -85,24 +85,8 @@ List<PhoneSearchResult> phoneSearchIndex(AppNotifier notifier) {
for (final entry in recentAgents(agentIndex(notifier))) {
results.add(_agentResult(entry));
}
- for (final machine in visibleMachines(notifier)) {
- final summary = phoneMachineSummary(machine);
- results.add(
- PhoneSearchResult(
- kind: PhoneSearchKind.machine,
- id: 'machine:${machine.machine.machineId}',
- title: machine.machine.displayName,
- subtitle: summary.label,
- fields: [
- machine.machine.displayName.toLowerCase(),
- summary.label.toLowerCase(),
- ].where((field) => field.isNotEmpty).toList(),
- summary: summary,
- machineId: machine.machine.machineId,
- machine: machine,
- ),
- );
- }
+ // Agents only. Machines used to be listed here as well; they are reached from the terminal's `⋯`
+ // sheet now (`machine_actions.dart`), so search answers the one question it is opened for.
return results;
}
diff --git a/mobile/lib/phone/phone_search_page.dart b/mobile/lib/phone/phone_search_page.dart
index 35226772e..c61f263f7 100644
--- a/mobile/lib/phone/phone_search_page.dart
+++ b/mobile/lib/phone/phone_search_page.dart
@@ -7,19 +7,15 @@ 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 'link_page.dart';
import 'phone_navigation.dart';
import 'phone_search_field.dart';
import 'phone_search_folder_header.dart';
import 'phone_search_groups.dart';
import 'phone_search_index.dart';
import 'phone_search_row.dart';
-import 'phone_sheet.dart';
-import 'phone_status.dart';
-import 'unlink_machine.dart';
-/// One query over everything the account can reach — agents and machines
-/// together.
+/// One query over every agent the account can reach. Machines are not searched
+/// here — they are on the terminal's `⋯` sheet.
///
/// A screen of its own rather than a field above either list, and that is the
/// whole point: the two tabs each answer half the question, and somebody who
@@ -141,7 +137,6 @@ class _Results extends StatelessWidget {
final groups = phoneSearchGroups(rows);
final agents = phoneSearchGroupedRows(groups);
- final machines = phoneSearchOfKind(rows, PhoneSearchKind.machine);
final now = DateTime.now();
return ListView(
// The keyboard is up and the finger is already on the glass; dragging the
@@ -154,9 +149,8 @@ class _Results extends StatelessWidget {
MediaQuery.paddingOf(context).bottom + 16,
),
children: [
- // Agents under their folders, machines in a section of their own. The
- // two kinds open different things, and a machine row appearing between
- // two agents is read as another agent until the icon is noticed.
+ // Agents under their folders. Machines are not searched here any more:
+ // they live in the terminal's `⋯` sheet — see `machine_actions.dart`.
for (final group in groups) ...[
PhoneSearchFolderHeader(group: group),
for (final row in group.rows)
@@ -167,16 +161,6 @@ class _Results extends StatelessWidget {
onTap: () => _openAgent(context, agents, row),
),
],
- if (machines.isNotEmpty) ...[
- _GroupLabel('Machines', count: machines.length),
- for (final row in machines)
- PhoneSearchRow(
- row: row,
- terms: terms,
- now: now,
- onTap: () => _openMachine(context, row),
- ),
- ],
],
);
}
@@ -205,94 +189,4 @@ class _Results extends StatelessWidget {
// agent, with nothing on screen to explain why.
openAgentPager(context, notifier, phoneSearchAgentEntries(agents), entry);
}
-
- /// A machine that wants its password opens the form for it. One that is
- /// linked opens a sheet of what can be done TO it — reload its agents,
- /// re-enter its password, unlink this phone — and no longer a list of its
- /// agents: those are a swipe away in the terminal, and search already lists
- /// them above.
- ///
- /// Read at the tap, not when the row was drawn, so a machine that got linked
- /// while this page was open gets the sheet rather than a form it no longer
- /// needs.
- void _openMachine(BuildContext context, PhoneSearchResult row) {
- final machine = notifier.stateOf(row.machineId);
- if (machine == null) return;
- switch (phoneMachineStatusOf(machine)) {
- case PhoneMachineStatus.offline:
- return;
- case PhoneMachineStatus.needsPassword:
- openMachine(context, notifier, row.machineId);
- return;
- case PhoneMachineStatus.connecting || PhoneMachineStatus.ready:
- break;
- }
- final machineId = row.machineId;
- showPhoneSheet(
- context,
- title: machine.machine.displayName,
- actions: [
- PhoneSheetAction(
- icon: LucideIcons.refreshCw300,
- label: 'Reload agents',
- onTap: () => unawaited(notifier.reloadMachineData(machineId)),
- ),
- PhoneSheetAction(
- icon: LucideIcons.keyRound300,
- label: 'Re-enter password…',
- onTap: () => Navigator.of(context).push(
- phoneRoute(
- (_) => LinkPage(notifier: notifier, machineId: machineId),
- ),
- ),
- ),
- // No confirmation, the same as the Machines tab: this sheet is the step
- // between the tap and the unlink.
- PhoneSheetAction(
- icon: LucideIcons.unlink300,
- label: 'Unlink this phone',
- destructive: true,
- onTap: () => unawaited(unlinkThisPhone(context, notifier, machine)),
- ),
- ],
- );
- }
-}
-
-class _GroupLabel extends StatelessWidget {
- const _GroupLabel(this.text, {required this.count});
-
- final String text;
- final int count;
-
- @override
- Widget build(BuildContext context) {
- AppTheme.watch(context);
- return Padding(
- padding: const EdgeInsets.fromLTRB(4, 12, 4, 6),
- child: Row(
- children: [
- Text(
- text.toUpperCase(),
- style: TextStyle(
- color: AppPalette.textFaint,
- fontSize: 11.5,
- fontWeight: FontWeight.w600,
- letterSpacing: 0.5,
- ),
- ),
- const SizedBox(width: 7),
- Text(
- '$count',
- style: TextStyle(
- color: AppPalette.textFaint,
- fontSize: 11.5,
- fontWeight: FontWeight.w600,
- fontFeatures: AppFont.tabularFigures,
- ),
- ),
- ],
- ),
- );
- }
}
diff --git a/mobile/lib/phone/phone_sheet.dart b/mobile/lib/phone/phone_sheet.dart
index ef0f4f5dd..2b780a30b 100644
--- a/mobile/lib/phone/phone_sheet.dart
+++ b/mobile/lib/phone/phone_sheet.dart
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
@@ -9,6 +10,9 @@ class PhoneSheetAction {
required this.label,
required this.onTap,
this.destructive = false,
+ this.value,
+ this.valueColor,
+ this.enabled = true,
});
final IconData icon;
@@ -19,17 +23,58 @@ class PhoneSheetAction {
final VoidCallback onTap;
final bool destructive;
+
+ /// A quiet word at the end of the row — a machine's state, on a machine row.
+ final String? value;
+
+ /// The colour of [value]; the faint text colour when null.
+ final Color? valueColor;
+
+ /// False draws the row dimmed and leaves the sheet open on a tap: an offline machine is listed
+ /// so its absence is not a mystery, not so it can be opened.
+ final bool enabled;
+}
+
+/// A captioned run of rows in a phone sheet.
+class PhoneSheetSection {
+ PhoneSheetSection({
+ required this.caption,
+ required this.actions,
+ this.maxVisible,
+ });
+
+ final String caption;
+ final List<PhoneSheetAction> actions;
+
+ /// Rows shown before an "N more" row that reveals the rest. Null shows everything.
+ final int? maxVisible;
+
+ bool _expanded = false;
+
+ List<PhoneSheetAction> get visible {
+ final max = maxVisible;
+ if (_expanded || max == null || actions.length <= max) return actions;
+ return actions.take(max).toList();
+ }
+
+ int get hiddenCount => actions.length - visible.length;
+
+ void expand() => _expanded = true;
}
/// The `⋯` menu on a phone page: a title line and a column of actions.
///
/// The desktop reaches the same actions through a right-click menu, which a phone has no gesture
/// for. One sheet rather than a menu per page: the actions differ, the shape does not.
+///
+/// [sections] draws captioned groups after [actions]; an empty section is left out.
Future<void> showPhoneSheet(
BuildContext context, {
required String title,
- required List<PhoneSheetAction> actions,
+ List<PhoneSheetAction> actions = const [],
+ List<PhoneSheetSection> sections = const [],
PhoneSheetAction? titleAction,
+ List<String>? titleParts,
}) => showModalBottomSheet<void>(
context: context,
useRootNavigator: true,
@@ -45,15 +90,17 @@ Future<void> showPhoneSheet(
child: Row(
children: [
Expanded(
- child: Text(
- title,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- color: AppPalette.textSecondary,
- fontSize: 13,
- ),
- ),
+ child: titleParts == null
+ ? Text(
+ title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ color: AppPalette.textSecondary,
+ fontSize: 13,
+ ),
+ )
+ : _TitleParts(parts: titleParts),
),
// [titleAction]: an icon on the title line — for something that is not about the
// subject of the sheet (Settings, on an agent's sheet), so it does not take a row
@@ -78,21 +125,58 @@ Future<void> showPhoneSheet(
// Scrolls once the rows outgrow the sheet — voice input's six languages do on a short phone —
// and is laid out exactly like a plain column until then.
Flexible(
- child: ListView(
- shrinkWrap: true,
- padding: EdgeInsets.zero,
- children: [
- for (final action in actions)
- _SheetRow(
- action: action,
- // Close first, then act: an action that opens a dialog or pushes a page must not
- // do it underneath a sheet that is still animating out.
- onTap: () {
- Navigator.of(sheetContext).pop();
- action.onTap();
- },
- ),
- ],
+ // Stateful only for [PhoneSheetSection.maxVisible]: "N more" opens the rest in place
+ // rather than closing the sheet.
+ child: StatefulBuilder(
+ builder: (context, setSheetState) => ListView(
+ shrinkWrap: true,
+ padding: EdgeInsets.zero,
+ children: [
+ for (final action in actions)
+ _SheetRow(
+ action: action,
+ // Close first, then act: an action that opens a dialog or pushes a page must not
+ // do it underneath a sheet that is still animating out.
+ onTap: () {
+ Navigator.of(sheetContext).pop();
+ action.onTap();
+ },
+ ),
+ for (final section in sections)
+ if (section.actions.isNotEmpty) ...[
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 14, 20, 4),
+ child: Text(
+ section.caption.toUpperCase(),
+ style: TextStyle(
+ color: AppPalette.textFaint,
+ fontSize: 11.5,
+ fontWeight: FontWeight.w600,
+ letterSpacing: 0.6,
+ ),
+ ),
+ ),
+ for (final action in section.visible)
+ _SheetRow(
+ action: action,
+ onTap: () {
+ Navigator.of(sheetContext).pop();
+ action.onTap();
+ },
+ ),
+ if (section.hiddenCount > 0)
+ _SheetRow(
+ action: PhoneSheetAction(
+ icon: LucideIcons.ellipsis300,
+ label: '${section.hiddenCount} more',
+ onTap: () {},
+ ),
+ // Stays open: this row reveals, it does not act.
+ onTap: () => setSheetState(section.expand),
+ ),
+ ],
+ ],
+ ),
),
),
const SizedBox(height: 8),
@@ -101,6 +185,38 @@ Future<void> showPhoneSheet(
),
);
+/// A title made of named parts — an agent, then its machine — one per line.
+///
+/// The first part reads as the title and the rest as quieter lines under it. A long name wraps, up to
+/// two lines each, and only past that is it cut with `…` — so a pathological name cannot push the
+/// actions off the sheet.
+class _TitleParts extends StatelessWidget {
+ const _TitleParts({required this.parts});
+
+ final List<String> parts;
+
+ @override
+ Widget build(BuildContext context) => Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ for (var index = 0; index < parts.length; index++)
+ Text(
+ parts[index],
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: index == 0
+ ? TextStyle(
+ color: AppPalette.textPrimary,
+ fontSize: 15,
+ fontWeight: FontWeight.w600,
+ )
+ : TextStyle(color: AppPalette.textSecondary, fontSize: 13),
+ ),
+ ],
+ );
+}
+
class _SheetRow extends StatelessWidget {
const _SheetRow({required this.action, required this.onTap});
@@ -110,11 +226,14 @@ class _SheetRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
- final color = action.destructive
+ final color = !action.enabled
+ ? AppPalette.textFaint
+ : action.destructive
? AppPalette.dangerFill
: AppPalette.textPrimary;
+ final value = action.value;
return InkWell(
- onTap: onTap,
+ onTap: action.enabled ? onTap : null,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 13),
child: Row(
@@ -124,6 +243,8 @@ class _SheetRow extends StatelessWidget {
Expanded(
child: Text(
action.label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
style: TextStyle(
color: color,
fontSize: 16,
@@ -131,6 +252,16 @@ class _SheetRow extends StatelessWidget {
),
),
),
+ if (value != null) ...[
+ const SizedBox(width: 12),
+ Text(
+ value,
+ style: TextStyle(
+ color: action.valueColor ?? AppPalette.textFaint,
+ fontSize: 13,
+ ),
+ ),
+ ],
],
),
),
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 53cc9b2e5..92034740b 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -18,6 +18,7 @@ import 'package:harness_mobile/widgets/terminal_panel.dart';
import 'agents_page.dart' show openNewAgent;
import 'delete_agent.dart';
+import 'machine_actions.dart';
import 'phone_header.dart';
import 'phone_navigation.dart' show phoneRoute;
import 'phone_search_page.dart' show openPhoneSearch;
@@ -726,60 +727,81 @@ class _TerminalPageState extends State<TerminalPage>
showPhoneSheet(
context,
title: '$agentName · $machineName',
- // Settings is an icon on the title line rather than a row: it is about the app, not about
- // this agent, and it is here only because the tab bar that used to lead to it is hidden.
- titleAction: PhoneSheetAction(
- icon: LucideIcons.settings300,
- label: 'Settings',
- onTap: () => Navigator.of(context).push(
- phoneRoute(
- (_) => SettingsPage(notifier: widget.notifier, large: false),
- ),
- ),
- ),
- actions: [
- PhoneSheetAction(
- icon: LucideIcons.pencil300,
- label: 'Rename agent…',
- onTap: () => showAgentRenameDialog(
- context,
- widget.notifier,
- widget.machineId,
- widget.agentId,
- agentName,
- ),
+ // Two lines — the agent, then its machine — shown in full.
+ titleParts: [agentName, machineName],
+ // Three groups, by what each row acts on: this agent, the app, and the machines. Machines
+ // moved here from search, which now finds agents only.
+ sections: [
+ PhoneSheetSection(
+ caption: 'Agent',
+ actions: [..._agentActions(agentName)],
),
- PhoneSheetAction(
- icon: LucideIcons.refreshCw300,
- label: 'Restart agent',
- onTap: () => unawaited(_restart()),
+ // Four machines, then "N more": the sheet has to stay short enough that App below is not
+ // pushed off a small phone by an account with a rack of machines.
+ PhoneSheetSection(
+ caption: 'Machines',
+ actions: machineSheetRows(context, widget.notifier),
+ maxVisible: 4,
),
- // Last, and alone in red: the two above are recoverable and this one is
- // not, so it does not sit where a thumb lands on the way to them.
- //
- // ⚠️ Nothing here pops this page. Deleting detaches the pane, and the
- // `_hadPane` branch above leaves on its own when that happens — the same
- // path a delete from the list, or from the desktop, already takes. A pop
- // here would be a second one, and the parked pages in this pager share
- // the route.
- PhoneSheetAction(
- icon: LucideIcons.trash2300,
- label: 'Delete agent…',
- destructive: true,
- onTap: () => unawaited(
- confirmDeleteAgent(
- context,
- widget.notifier,
- widget.machineId,
- widget.agentId,
- agentName,
+ PhoneSheetSection(
+ caption: 'App',
+ actions: [
+ PhoneSheetAction(
+ icon: LucideIcons.settings300,
+ label: 'Settings',
+ onTap: () => Navigator.of(context).push(
+ phoneRoute(
+ (_) => SettingsPage(notifier: widget.notifier, large: false),
+ ),
+ ),
),
- ),
+ ],
),
],
);
}
+ List<PhoneSheetAction> _agentActions(String agentName) => [
+ PhoneSheetAction(
+ icon: LucideIcons.pencil300,
+ label: 'Rename agent…',
+ onTap: () => showAgentRenameDialog(
+ context,
+ widget.notifier,
+ widget.machineId,
+ widget.agentId,
+ agentName,
+ ),
+ ),
+ PhoneSheetAction(
+ icon: LucideIcons.refreshCw300,
+ label: 'Restart agent',
+ onTap: () => unawaited(_restart()),
+ ),
+ // Last, and alone in red: the two above are recoverable and this one is
+ // not, so it does not sit where a thumb lands on the way to them.
+ //
+ // ⚠️ Nothing here pops this page. Deleting detaches the pane, and the
+ // `_hadPane` branch above leaves on its own when that happens — the same
+ // path a delete from the list, or from the desktop, already takes. A pop
+ // here would be a second one, and the parked pages in this pager share
+ // the route.
+ PhoneSheetAction(
+ icon: LucideIcons.trash2300,
+ label: 'Delete agent…',
+ destructive: true,
+ onTap: () => unawaited(
+ confirmDeleteAgent(
+ context,
+ widget.notifier,
+ widget.machineId,
+ widget.agentId,
+ agentName,
+ ),
+ ),
+ ),
+ ];
+
/// Restarting is a round trip that can fail, and the phone has no status rail to fail into — so
/// the answer lands as a snackbar, which is the one surface a pushed page here always has.
Future<void> _restart() async {