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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(mobile): delete an agent from its own page, and create one from the list
bubu-duduf50c0e1dda48
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dartindex 317cccdd6..12b43b77c 100644--- a/mobile/lib/phone/agents_page.dart+++ b/mobile/lib/phone/agents_page.dart@@ -10,6 +10,7 @@ import 'package:harness_mobile/shared/widgets/empty_state.dart';import 'package:harness_mobile/state/app_state.dart';import 'agent_tile.dart';+import 'delete_agent.dart';import 'link_page.dart';import 'phone_card.dart';import 'new_agent_page.dart';@@ -59,7 +60,7 @@ class AgentsPage extends StatelessWidget {tooltip: 'New agent',color: AppPalette.textSecondary,onPressed: () =>- _openNewAgent(context, notifier, machineId),+ openNewAgent(context, notifier, machineId),),if (machine != null)AppIconButton(@@ -210,7 +211,7 @@ class _AgentsBody extends StatelessWidget {title: 'No agents yet',message: 'Start one here, or from Harness on that machine.',action: FilledButton(- onPressed: () => _openNewAgent(context, notifier, _machineId),+ onPressed: () => openNewAgent(context, notifier, _machineId),child: const Text('New agent'),),);@@ -231,9 +232,9 @@ class _AgentsBody extends StatelessWidget {/// One agent's `⋯`, reached by holding its row.///-/// The desktop offers this from the rail row's menu and the pane's; a phone has neither, so the-/// hold is the whole door. Kept public and out of [_AgentsBody] so the terminal page can open the-/// same sheet if it ever grows one, rather than writing a second wording of the same act.+/// The desktop offers this from the rail row's menu and the pane's; a phone has neither here, so+/// the hold is this screen's whole door. The terminal page reaches the same act through its own+/// `⋯`, and both go through [confirmDeleteAgent] rather than wording it twice.Future<void> showAgentActions(BuildContext context,AppNotifier notifier,@@ -247,41 +248,20 @@ Future<void> showAgentActions(icon: LucideIcons.trash2300,label: 'Delete agent…',destructive: true,- onTap: () =>- unawaited(_confirmDeleteAgent(context, notifier, machineId, agent)),+ onTap: () => unawaited(+ confirmDeleteAgent(context, notifier, machineId, agent.id, agent.name),+ ),),],);-/// ⚠️ Deletion destroys the agent on the machine — unlike unlinking above, which only forgets a-/// password. The wording has to carry that, because both arrive through the same red sheet row.+/// The one way into [NewAgentPage] — this page's header button, its empty state, and the Agents+/// tab's `+` all come through here rather than drifting into three ways of opening it.///-/// Nothing here removes the row: `AppNotifier.deleteAgent` drops the agent from the machine's list-/// and detaches every pane still showing it, and this page rebuilds off that notifier.-Future<void> _confirmDeleteAgent(- BuildContext context,- AppNotifier notifier,- String machineId,- Agent agent,-) async {- final confirmed = await confirmPhoneAction(- context,- title: 'Delete ${agent.name}?',- message:- 'The agent and its terminal session are removed from the machine, '- "along with any work it has not finished. This can't be undone.",- confirmLabel: 'Delete',- );- if (!confirmed || !context.mounted) return;- final error = await notifier.deleteAgent(machineId, agent.id);- if (error == null || !context.mounted) return;- ScaffoldMessenger.maybeOf(context)- ?.showSnackBar(SnackBar(content: Text(error)));-}--/// The one way into [NewAgentPage], so the header's button and the empty-/// state's cannot drift into opening it two different ways.-void _openNewAgent(+/// ⚠️ [machineId] is not a detail the caller may guess at. A new agent needs the machine to list+/// its folders and name the engines it has, so every door has to establish which machine FIRST:+/// this page already knows, and the tab asks (`agents_tab.dart`).+void openNewAgent(BuildContext context,AppNotifier notifier,String machineId,diff --git a/mobile/lib/phone/agents_tab.dart b/mobile/lib/phone/agents_tab.dartindex a346dc94f..6c14dd033 100644--- a/mobile/lib/phone/agents_tab.dart+++ b/mobile/lib/phone/agents_tab.dart@@ -11,6 +11,7 @@ import 'account_button.dart';import 'machine_filter_bar.dart';import 'phone_card.dart';import 'phone_header.dart';+import 'phone_sheet.dart';import 'phone_navigation.dart';import 'phone_status.dart';@@ -51,8 +52,33 @@ class _AgentsTabState extends State<AgentsTab> {? all: all.where((entry) => entry.machineId == selected).toList();final error = widget.notifier.lastError;+ // Only machines that are answering. Creating needs one to list its folders and name the+ // engines it has, so a machine that is offline or still wants its password cannot host a new+ // agent — the same gate the machine's own page puts on its `+`.+ final ready = [+ for (final machine in machines)+ if (phoneMachineStatusOf(machine) == PhoneMachineStatus.ready) machine,+ ];return Scaffold(backgroundColor: AppPalette.windowBg,+ // ⚠️ Absent rather than disabled when nothing can host an agent. The empty state already+ // says where that is fixed (the Machines tab), and a button whose only outcome is an+ // explanation of why it does nothing is worse than no button.+ //+ // It floats above the tab bar without being told to: this Scaffold is the BODY of the+ // shell's (`phone_shell.dart`), whose own `bottomNavigationBar` sits below it.+ floatingActionButton: ready.isEmpty+ ? null+ : FloatingActionButton(+ onPressed: () => _pickMachine(context, ready),+ backgroundColor: AppPalette.accent,+ foregroundColor: Colors.white,+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(AppCard.radius),+ ),+ tooltip: 'New agent',+ child: const Icon(LucideIcons.plus300, size: 26),+ ),body: SafeArea(bottom: false,child: Column(@@ -87,6 +113,33 @@ class _AgentsTabState extends State<AgentsTab> {);},);++ /// Which machine the new agent runs on, asked before anything else.+ ///+ /// This list is the one screen that does NOT already know: it is every agent on the account, and+ /// the machine is a filter above it rather than the thing navigated through. So the `+` cannot+ /// carry a machine the way [AgentsPage]'s does, and guessing one — the first, the filtered one —+ /// would put an agent on a computer nobody named.+ ///+ /// ⚠️ Shown even when only one machine qualifies. A sheet of one still says WHERE the agent is+ /// about to be created, and that is the question this step exists to answer.+ void _pickMachine(BuildContext context, List<MachineState> ready) =>+ showPhoneSheet(+ context,+ title: 'New agent on…',+ actions: [+ for (final machine in ready)+ PhoneSheetAction(+ icon: LucideIcons.laptopMinimal300,+ label: machine.machine.displayName,+ onTap: () => openNewAgent(+ context,+ widget.notifier,+ machine.machine.machineId,+ ),+ ),+ ],+ );}class _Body extends StatelessWidget {diff --git a/mobile/lib/phone/delete_agent.dart b/mobile/lib/phone/delete_agent.dartnew file mode 100644index 000000000..67f31aada--- /dev/null+++ b/mobile/lib/phone/delete_agent.dart@@ -0,0 +1,44 @@+import 'package:flutter/material.dart';++import 'package:harness_mobile/state/app_state.dart';++import 'phone_sheet.dart';++/// The one "Delete agent" confirmation on the phone, opened from every place an+/// agent can be deleted: the list row's hold and the terminal page's `⋯`.+///+/// Its own file for the reason the desktop's `widgets/delete_agent_dialog.dart`+/// is: two copies would be two wordings of one irreversible act, and two ways of+/// reporting that it failed. Same argument order as that one, so the pair reads+/// as the same function on two platforms.+///+/// ⚠️ The wording has to say the work goes with it. Unlinking a machine — the+/// other red row in the same sheet — only forgets a password and leaves every+/// agent running; this destroys the agent on the machine. Both arrive looking+/// identical, so only the sentence tells them apart.+///+/// Nothing here removes anything from the screen. [AppNotifier.deleteAgent]+/// drops the agent from its machine's list and detaches every pane still showing+/// it; the list rebuilds off the notifier, and an open terminal page leaves on+/// its own once its pane is gone (`terminal_page.dart`, the `_hadPane` branch).+Future<void> confirmDeleteAgent(+ BuildContext context,+ AppNotifier notifier,+ String machineId,+ String agentId,+ String agentName,+) async {+ final confirmed = await confirmPhoneAction(+ context,+ title: 'Delete $agentName?',+ message:+ 'The agent and its terminal session are removed from the machine, '+ "along with any work it has not finished. This can't be undone.",+ confirmLabel: 'Delete',+ );+ if (!confirmed || !context.mounted) return;+ final error = await notifier.deleteAgent(machineId, agentId);+ if (error == null || !context.mounted) return;+ ScaffoldMessenger.maybeOf(context)+ ?.showSnackBar(SnackBar(content: Text(error)));+}diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dartindex 91fccda4c..f6e3e8eb3 100644--- a/mobile/lib/phone/terminal_page.dart+++ b/mobile/lib/phone/terminal_page.dart@@ -10,6 +10,7 @@ import 'package:harness_mobile/widgets/engine_identity.dart';import 'package:harness_mobile/widgets/rename_agent_dialog.dart';import 'package:harness_mobile/widgets/terminal_panel.dart';+import 'delete_agent.dart';import 'phone_header.dart';import 'phone_sheet.dart';import 'phone_status.dart';@@ -305,6 +306,28 @@ class _TerminalPageState extends State<TerminalPage>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,+ ),+ ),+ ),],);}diff --git a/mobile/test/phone_new_agent_test.dart b/mobile/test/phone_new_agent_test.dartnew file mode 100644index 000000000..fa507d798--- /dev/null+++ b/mobile/test/phone_new_agent_test.dart@@ -0,0 +1,86 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/phone/agents_tab.dart';+import 'package:harness_mobile/state/app_state.dart';++/// A machine that is answering, and one that is not.+///+/// The second is the whole point of the picker's filter: an agent cannot be created on a machine+/// that has not listed its folders or named its engines, so it must not be offered as a host.+AppNotifier _app({required bool anyReady}) {+ final app = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ );+ const ready = Machine(+ machineId: 'ready',+ authMode: MachineAuthMode.remote,+ name: 'Studio',+ );+ const sleeping = Machine(+ machineId: 'sleeping',+ authMode: MachineAuthMode.remote,+ name: 'Laptop',+ );+ app.machines = [ready, sleeping];+ app.machineStates['ready'] = MachineState(ready)+ ..nodeOnline = anyReady+ ..connectionStatus = ConnectionStatus.connected+ ..agentLoadStatus = AgentLoadStatus.loaded;+ // Harness is not running there: offline, whatever the socket says.+ app.machineStates['sleeping'] = MachineState(sleeping)+ ..nodeOnline = false+ ..connectionStatus = ConnectionStatus.connected+ ..agentLoadStatus = AgentLoadStatus.loaded;+ return app;+}++Future<void> _pump(WidgetTester tester, AppNotifier app) async {+ await tester.pumpWidget(MaterialApp(home: AgentsTab(notifier: app)));+ await tester.pumpAndSettle();+}++void main() {+ testWidgets('the + asks which machine, and offers only the ones answering', (+ tester,+ ) async {+ final app = _app(anyReady: true);+ addTearDown(app.dispose);+ await _pump(tester, app);++ await tester.tap(find.byType(FloatingActionButton));+ await tester.pumpAndSettle();++ expect(find.text('New agent on…'), findsOneWidget);++ // ⚠️ Scoped to the sheet. Both machines also name themselves in the filter+ // bar above the list, so an unscoped finder sees every machine twice and+ // reads the offline one as offered when it is not.+ Finder inSheet(String text) => find.descendant(+ of: find.byType(BottomSheet),+ matching: find.text(text),+ );++ expect(inSheet('Studio'), findsOneWidget);+ expect(+ inSheet('Laptop'),+ findsNothing,+ reason: 'an offline machine cannot host a new agent',+ );+ });++ testWidgets('no + at all while nothing can host an agent', (tester) async {+ final app = _app(anyReady: false);+ addTearDown(app.dispose);+ await _pump(tester, app);++ // Absent, not disabled: the empty state already says to open the Machines+ // tab, and a button whose only outcome is that same explanation is worse+ // than no button.+ expect(find.byType(FloatingActionButton), findsNothing);+ });+}