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
fix(mobile): the Machines tab pairs and unpairs, and unlinking lets go
bubu-dudu346723cde7eb
diff --git a/mobile/lib/phone/link_page.dart b/mobile/lib/phone/link_page.dartindex d3ff7e06c..9ea5f934a 100644--- a/mobile/lib/phone/link_page.dart+++ b/mobile/lib/phone/link_page.dart@@ -3,16 +3,14 @@ import 'package:flutter/material.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';import 'package:harness_mobile/state/app_state.dart';import 'package:harness_mobile/widgets/link_machine_screen.dart';-import 'agents_page.dart';+import 'phone_header.dart';-import 'phone_navigation.dart';/// A machine's password form, as a phone page — the same [LinkMachineScreen] the desktop pops/// up, since the exchange behind it is the same.///-/// It leaves by itself both ways: forward onto the machine's agents once the link lands, and-/// back when the form's own Close is pressed — unless it is [embedded], where moving on is somebody-/// else's job.+/// It leaves by itself either way — once the link lands, and when the form's own Close is pressed —+/// unless it is [embedded], where moving on is somebody else's job.class LinkPage extends StatefulWidget {const LinkPage({super.key,@@ -82,15 +80,12 @@ class _LinkPageState extends State<LinkPage> {final machine = widget.notifier.stateOf(widget.machineId);final navigator = Navigator.of(context);if (machine != null && !machine.needsLink) {+ // Linked: this form is finished, so it leaves. It used to `pushReplacement` its way to that+ // machine's agent list, which is the navigation the Machines tab no longer does — agents+ // belong to the Agents tab, where the machine is a filter rather than a step. Going back is+ // what shows the result: the row this was opened from is now under "Linked"._leaving = true;- navigator.pushReplacement(- phoneRoute(- (_) => AgentsPage(- notifier: widget.notifier,- machineId: widget.machineId,- ),- ),- );+ navigator.maybePop();return;}final closed =diff --git a/mobile/lib/phone/machines_tab.dart b/mobile/lib/phone/machines_tab.dartindex cf2fb59de..8e7c94ca3 100644--- a/mobile/lib/phone/machines_tab.dart+++ b/mobile/lib/phone/machines_tab.dart@@ -1,15 +1,21 @@+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/shared/widgets/empty_state.dart';import 'package:harness_mobile/state/app_state.dart';++import 'link_page.dart';import 'machine_index.dart';import 'machine_tile.dart';import 'phone_card.dart';import 'phone_header.dart';import 'phone_navigation.dart';import 'phone_search_button.dart';+import 'phone_sheet.dart';+import 'unlink_machine.dart';/// The machines on the account, grouped by what they need.///@@ -91,37 +97,64 @@ class _Body extends StatelessWidget {children: [if (working.isNotEmpty) ...[const _SectionLabel('Linked'),- for (final state in working) _tile(context, ordered, state),+ for (final state in working) _tile(context, state),const SizedBox(height: 6),],if (needsAttention.isNotEmpty) ...[- if (working.isNotEmpty)- const _SectionLabel('Needs your attention'),- for (final state in needsAttention) _tile(context, ordered, state),+ if (working.isNotEmpty) const _SectionLabel('Needs your attention'),+ for (final state in needsAttention) _tile(context, state),],],),);}- Widget _tile(- BuildContext context,- List<MachineState> ordered,- MachineState state,- ) => Padding(+ Widget _tile(BuildContext context, MachineState state) => Padding(padding: const EdgeInsets.only(bottom: kPhoneCardGap),- child: MachineTile(- machine: state,- // The whole visible list goes with the tap, so the page opens as a pager over exactly the- // machines on screen. Swiping there walks this order.- onTap: () => openMachinePager(- context,- notifier,- ordered,- state.machine.machineId,- ),- ),+ child: MachineTile(machine: state, onTap: () => _open(context, state)),);++ /// This screen connects and disconnects, and does nothing else.+ ///+ /// A machine that wants its password opens the form for it. A machine that already has one has+ /// exactly one thing left to offer — giving it up — so a tap brings that rather than a page.+ ///+ /// ⚠️ Deliberately NOT the agent list any more. Agents belong to the Agents tab, which lists+ /// every one on the account and treats the machine as a filter; reaching them a second way+ /// through here made the machine something to navigate THROUGH, which is the shape that tab+ /// exists to replace.+ void _open(BuildContext context, MachineState state) {+ if (state.needsLink) {+ Navigator.of(context).push(+ phoneRoute(+ (_) =>+ LinkPage(notifier: notifier, machineId: state.machine.machineId),+ ),+ );+ return;+ }+ // ⚠️ One row, and it is load-bearing rather than a menu waiting to grow. Unlinking asks for no+ // confirmation, so this sheet IS the confirmation: the step between a finger landing on a row+ // in a list and this phone losing its pairing. Collapsing it into the tap would leave nothing+ // between them.+ //+ // No "Re-enter password" here. A machine that is linked has a working password already, and the+ // way to replace one is to give this one up and enter the new one — the row below, then the row+ // the machine lands on in "Needs your attention".+ showPhoneSheet(+ context,+ title: state.machine.displayName,+ actions: [+ // No trailing `…`: this acts on the tap rather than opening anything.+ PhoneSheetAction(+ icon: LucideIcons.unlink300,+ label: 'Unlink this phone',+ destructive: true,+ onTap: () => unawaited(unlinkThisPhone(context, notifier, state)),+ ),+ ],+ );+ }}class _SectionLabel extends StatelessWidget {diff --git a/mobile/lib/phone/unlink_machine.dart b/mobile/lib/phone/unlink_machine.dartnew file mode 100644index 000000000..8c111374a--- /dev/null+++ b/mobile/lib/phone/unlink_machine.dart@@ -0,0 +1,27 @@+import 'package:flutter/material.dart';++import 'package:harness_mobile/state/app_state.dart';++/// Drops this phone's pairing with [machine], and says so only if it fails.+///+/// ⚠️ No confirmation, by decision. The usual argument for one holds here — the pairing cannot be+/// rebuilt without that machine's password, so a mistaken tap costs a trip to find it — and it was+/// weighed and declined: the act is two taps deep inside a sheet nobody opens by accident, and the+/// row moving to "Needs your attention" is itself the report that it happened.+///+/// ⚠️ This drops THIS DEVICE's trust pin — `AppNotifier.unlinkMachine`, deliberately not+/// `deleteMachine`. The machine is untouched and its agents keep running; what ends is this phone's+/// permission to reach them.+///+/// Its own file rather than a closure in the sheet, so the one place this is done stays one place+/// when a second caller appears — the same reason `delete_agent.dart` exists.+Future<void> unlinkThisPhone(+ BuildContext context,+ AppNotifier notifier,+ MachineState machine,+) async {+ final error = await notifier.unlinkMachine(machine.machine.machineId);+ if (error == null || !context.mounted) return;+ ScaffoldMessenger.maybeOf(context)+ ?.showSnackBar(SnackBar(content: Text(error)));+}diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex f8548cf3e..265ad0e79 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -275,6 +275,7 @@ class AppNotifier extends ChangeNotifier {final AuthSession session;AppConfig config;late ApiClient api;+/// Signs in, and says whether this computer is signed in: the harness CLI in a desktop build,/// [ViewerServices.login] in a viewer build — which has no CLI — under one name, so every call/// site reads the same in both.@@ -2908,10 +2909,32 @@ class AppNotifier extends ChangeNotifier {}/// Removes a linked machine's trust pin, then refreshes the list. Returns null on success.+ ///+ /// ⚠️ Dropping the pin does NOT end the connection by itself, and that is the whole reason the+ /// teardown below exists. The pin is local to this device — the machine is never told — and the+ /// socket already open has negotiated its session, so it keeps working exactly as before. No+ /// close arrives, so nothing flips [MachineState.needsLink], and the row stays under "Linked"+ /// looking connected because it IS connected.+ ///+ /// So this does by hand what a `NO_PEER_LINK` close does on its own: shut the socket, mark the+ /// machine as wanting its password, and tell the open terminals they are no longer reachable.Future<String?> unlinkMachine(String machineId) async {final error = await peerLinks.unlink(machineId);- if (error == null) await refreshLinkedMachines();- return error;+ if (error != null) return error;+ await refreshLinkedMachines();+ final machine = machineStates[machineId];+ if (machine == null) return null;+ // Closed first: the state below says this machine wants a password, and a live socket still+ // answering underneath would make that a lie for as long as it lasted.+ await _pool?.closeMachine(machineId);+ machine.needsLink = true;+ machine.agentLoadStatus = AgentLoadStatus.needsLink;+ _markSessionsUnreachable(+ machine,+ 'This phone is no longer linked. Enter the password again to reconnect.',+ );+ notifyListeners();+ return null;}Future<void> _pollOfflineMachine(String machineId) async {diff --git a/mobile/test/unlink_machine_test.dart b/mobile/test/unlink_machine_test.dartnew file mode 100644index 000000000..fb327afd3--- /dev/null+++ b/mobile/test/unlink_machine_test.dart@@ -0,0 +1,98 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/auth/cli_link.dart';+import 'package:harness_mobile/auth/peer_link_client.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/state/app_state.dart';++/// Unlinks whatever it is asked to, so these tests are about what the APP does with that answer.+class _Links implements PeerLinkClient {+ final unlinked = <String>[];++ @override+ Future<CliLinkConnectResult> connect(+ String machineId,+ String password, {+ void Function(String stage)? onProgress,+ String? displayName,+ }) async => const CliLinkConnectResult(error: 'not used');++ @override+ Future<CliLinkListResult> list() async =>+ const CliLinkListResult(machines: []);++ @override+ Future<String?> unlink(String machineId) async {+ unlinked.add(machineId);+ return null;+ }+}++/// A machine as it looks while everything is working: linked, answering, agents listed.+AppNotifier _app(_Links links) {+ final app = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ peerLinks: links,+ );+ const machine = Machine(+ machineId: 'm',+ authMode: MachineAuthMode.remote,+ name: 'Studio',+ );+ app.machines = [machine];+ app.machineStates['m'] = MachineState(machine)+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected+ ..agentLoadStatus = AgentLoadStatus.loaded+ ..agents = const [+ Agent(id: 'a0', name: 'One', engine: 'codex', terminalAvailable: true),+ ];+ return app;+}++void main() {+ test('unlinking leaves the machine wanting its password again', () async {+ final links = _Links();+ final app = _app(links);+ addTearDown(app.dispose);++ expect(app.machineStates['m']!.needsLink, isFalse);++ final error = await app.unlinkMachine('m');++ expect(error, isNull);+ expect(links.unlinked, ['m']);+ // ⚠️ The pin is local to this device and the machine is never told, so no close arrives to flip+ // this on its own. Without the app doing it by hand the row stayed under "Linked", still+ // connected, and unlinking read as having done nothing at all.+ expect(app.machineStates['m']!.needsLink, isTrue);+ expect(+ app.machineStates['m']!.agentLoadStatus,+ AgentLoadStatus.needsLink,+ reason: 'the list has to stop offering agents it can no longer reach',+ );+ });++ test('a refused unlink changes nothing', () async {+ final links = _Refusing();+ final app = _app(links);+ addTearDown(app.dispose);++ final error = await app.unlinkMachine('m');++ expect(error, isNotNull);+ expect(+ app.machineStates['m']!.needsLink,+ isFalse,+ reason: 'a machine that is still linked must not be shown as needing a password',+ );+ });+}++class _Refusing extends _Links {+ @override+ Future<String?> unlink(String machineId) async => 'm is not linked.';+}