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): delete an agent by holding its row

bubu-dudub5633dda2768
diff --git a/mobile/lib/phone/agent_tile.dart b/mobile/lib/phone/agent_tile.dart
index 1b9e7ccb8..7c97566ea 100644
--- a/mobile/lib/phone/agent_tile.dart
+++ b/mobile/lib/phone/agent_tile.dart
@@ -5,29 +5,34 @@ import 'package:harness/core/models.dart';
import 'package:harness/shared/theme/app_theme.dart';
import 'package:harness/state/app_state.dart';
import 'package:harness/widgets/engine_identity.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.
+/// 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.
class AgentTile extends StatelessWidget {
const AgentTile({
super.key,
required this.machine,
required this.agent,
required this.onTap,
+ this.onLongPress,
});
final MachineState machine;
final Agent agent;
final VoidCallback onTap;
+ final VoidCallback? onLongPress;
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
return PhoneCard(
onTap: agent.terminalAvailable ? onTap : null,
+ onLongPress: onLongPress,
child: Row(
children: [
PhoneCardGlyph(
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dart
index b7120903e..0f0bb5b25 100644
--- a/mobile/lib/phone/agents_page.dart
+++ b/mobile/lib/phone/agents_page.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
+import 'package:harness/core/models.dart';
import 'package:harness/shared/theme/app_theme.dart';
import 'package:harness/shared/widgets/app_icon_button.dart';
import 'package:harness/shared/widgets/empty_state.dart';
@@ -221,11 +222,63 @@ class _AgentsBody extends StatelessWidget {
machine: machine,
agent: agents[index],
onTap: () => openAgent(context, notifier, _machineId, agents[index].id),
+ onLongPress: () =>
+ showAgentActions(context, notifier, _machineId, agents[index]),
),
);
}
}
+/// 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.
+Future<void> showAgentActions(
+ BuildContext context,
+ AppNotifier notifier,
+ String machineId,
+ Agent agent,
+) => showPhoneSheet(
+ context,
+ title: agent.name,
+ actions: [
+ PhoneSheetAction(
+ icon: LucideIcons.trash2300,
+ label: 'Delete agent…',
+ destructive: true,
+ onTap: () =>
+ unawaited(_confirmDeleteAgent(context, notifier, machineId, agent)),
+ ),
+ ],
+);
+
+/// ⚠️ 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.
+///
+/// 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(
diff --git a/mobile/lib/phone/phone_card.dart b/mobile/lib/phone/phone_card.dart
index a74b19b89..69e2c5d04 100644
--- a/mobile/lib/phone/phone_card.dart
+++ b/mobile/lib/phone/phone_card.dart
@@ -17,11 +17,25 @@ EdgeInsets phoneListPadding(BuildContext context) =>
/// A tappable row on the phone: a glass card that sinks a little under the finger. Without an
/// [onTap] it is drawn dimmed and does not move.
class PhoneCard extends StatefulWidget {
- const PhoneCard({super.key, required this.child, this.onTap, this.border});
+ const PhoneCard({
+ super.key,
+ required this.child,
+ this.onTap,
+ this.onLongPress,
+ this.border,
+ });
final Widget child;
final VoidCallback? onTap;
+ /// The row's own `⋯` menu — a phone has no right-click, and a list row has nowhere to put a
+ /// button without crowding what the row is for.
+ ///
+ /// ⚠️ Deliberately independent of [onTap]: a row that cannot be OPENED can still be acted on,
+ /// and an agent whose terminal is gone is exactly the one somebody wants to delete. The dimming
+ /// below stays tied to [onTap] alone, because it says "this will not open", not "inert".
+ final VoidCallback? onLongPress;
+
/// Overrides the card's hairline rim. Used to mark a row that needs attention — a waiting agent —
/// so it is findable in a long list before a word of it is read. Null keeps the ordinary rim.
final BoxBorder? border;
@@ -33,8 +47,10 @@ class PhoneCard extends StatefulWidget {
class _PhoneCardState extends State<PhoneCard> {
bool _pressed = false;
+ bool get _interactive => widget.onTap != null || widget.onLongPress != null;
+
void _press(bool pressed) {
- if (widget.onTap == null || _pressed == pressed) return;
+ if (!_interactive || _pressed == pressed) return;
setState(() => _pressed = pressed);
}
@@ -47,6 +63,14 @@ class _PhoneCardState extends State<PhoneCard> {
onTapUp: (_) => _press(false),
onTapCancel: () => _press(false),
onTap: widget.onTap,
+ // Released here as well as in `onTapCancel`: the card must not stay sunk under the sheet
+ // this opens, which outlives the gesture that opened it.
+ onLongPress: widget.onLongPress == null
+ ? null
+ : () {
+ _press(false);
+ widget.onLongPress!();
+ },
child: AnimatedScale(
scale: _pressed ? 0.975 : 1,
duration: AppMotion.press,
diff --git a/mobile/test/phone_delete_agent_test.dart b/mobile/test/phone_delete_agent_test.dart
new file mode 100644
index 000000000..9a6093738
--- /dev/null
+++ b/mobile/test/phone_delete_agent_test.dart
@@ -0,0 +1,159 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/ws/ws_conn.dart';
+import 'package:harness_mobile/phone/agent_tile.dart';
+import 'package:harness_mobile/phone/agents_page.dart';
+
+/// Records what the page asks the machine for, and answers everything with a bare success.
+class _Conn extends WsConn {
+ _Conn()
+ : super(
+ wsBaseUrl: 'ws://fixture.invalid',
+ autonomousEnv: 'test',
+ machineId: 'm',
+ accessTokenProvider: (_, _) async => '',
+ onAuthFailure: (_) {},
+ onEvent: (_) {},
+ onStatus: (_) {},
+ );
+
+ final calls = <(String, Map<String, dynamic>)>[];
+
+ @override
+ Future<Map<String, dynamic>> request(
+ String type, {
+ Map<String, dynamic> payload = const {},
+ Duration timeout = const Duration(seconds: 20),
+ }) async {
+ calls.add((type, payload));
+ return {};
+ }
+
+ List<String> get deleted => [
+ for (final (type, payload) in calls)
+ if (type == 'agent_delete') payload['agentId'] as String,
+ ];
+}
+
+/// A machine answering with two agents: one whose terminal is up, one whose is not.
+///
+/// The second is the case the row's hold exists for — it cannot be opened, so a menu hung off the
+/// tap would never reach it.
+AppNotifier _app(_Conn conn) {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ connectionForTest: (_) => conn,
+ );
+ const machine = Machine(
+ machineId: 'm',
+ authMode: MachineAuthMode.remote,
+ name: 'Test host',
+ );
+ app.machines = [machine];
+ // ⚠️ `connected` is load-bearing, and not for realism. Anything less leaves the header at
+ // "Connecting…", whose StatusPill draws a CircularProgressIndicator — an animation that never
+ // ends, so `pumpAndSettle` never returns and every test here times out before its first assert.
+ app.machineStates['m'] = MachineState(machine)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agentLoadStatus = AgentLoadStatus.loaded
+ ..agents = const [
+ Agent(
+ id: 'a0',
+ name: 'Live one',
+ engine: 'codex',
+ terminalAvailable: true,
+ ),
+ Agent(
+ id: 'a1',
+ name: 'Gone one',
+ engine: 'codex',
+ terminalAvailable: false,
+ ),
+ ];
+ return app;
+}
+
+Future<void> _pump(WidgetTester tester, AppNotifier app) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: AgentsPage(notifier: app, machineId: 'm'),
+ ),
+ );
+ await tester.pumpAndSettle();
+}
+
+void main() {
+ testWidgets('holding an agent offers Delete, and Cancel deletes nothing', (
+ tester,
+ ) async {
+ final conn = _Conn();
+ final app = _app(conn);
+ addTearDown(app.dispose);
+ await _pump(tester, app);
+
+ await tester.longPress(find.byType(AgentTile).first);
+ await tester.pumpAndSettle();
+ expect(find.text('Delete agent…'), findsOneWidget);
+
+ await tester.tap(find.text('Delete agent…'));
+ await tester.pumpAndSettle();
+ expect(find.text('Delete Live one?'), findsOneWidget);
+
+ await tester.tap(find.text('Cancel'));
+ await tester.pumpAndSettle();
+
+ expect(conn.deleted, isEmpty, reason: 'backing out must ask nothing');
+ expect(app.machineStates['m']!.agents, hasLength(2));
+ });
+
+ testWidgets('confirming deletes that agent and no other', (tester) async {
+ final conn = _Conn();
+ final app = _app(conn);
+ addTearDown(app.dispose);
+ await _pump(tester, app);
+
+ await tester.longPress(find.byType(AgentTile).first);
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Delete agent…'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(FilledButton, 'Delete'));
+ await tester.pumpAndSettle();
+
+ expect(conn.deleted, ['a0']);
+ expect(app.machineStates['m']!.agents.map((agent) => agent.id), [
+ 'a1',
+ ], reason: 'the row goes because the notifier dropped it, not the page');
+ expect(find.text('Live one'), findsNothing);
+ });
+
+ testWidgets('an agent with no terminal cannot be opened but can be held', (
+ tester,
+ ) async {
+ final conn = _Conn();
+ final app = _app(conn);
+ addTearDown(app.dispose);
+ await _pump(tester, app);
+
+ final gone = find.byType(AgentTile).last;
+ // A tap is the gesture this row refuses; nothing should open.
+ await tester.tap(gone);
+ await tester.pumpAndSettle();
+ expect(find.text('Delete agent…'), findsNothing);
+
+ await tester.longPress(gone);
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Delete agent…'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(FilledButton, 'Delete'));
+ await tester.pumpAndSettle();
+
+ expect(conn.deleted, ['a1']);
+ });
+}