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.

fix(desktop): Add your phone links to Your devices instead of listing pairings

0xken15f350f8bebfb4
diff --git a/desktop/lib/api/api_client.dart b/desktop/lib/api/api_client.dart
index c4583a400..766bd4530 100644
--- a/desktop/lib/api/api_client.dart
+++ b/desktop/lib/api/api_client.dart
@@ -257,39 +257,6 @@ class ApiClient {
}
}
- /// What this computer trusts to read and drive its terminals — every phone
- /// paired by QR or password, and every computer linked to it — as the
- /// daemon keeps them (`GET /api/pairs`, the list `harness pairings` prints).
- /// Null when the daemon cannot say; the dialog then shows no list.
- Future<List<PairedDevice>?> pairedDevices() async {
- try {
- final res = await _dio.get('/api/pairs');
- final data = res.data;
- final pairs = data is Map ? data['pairs'] : null;
- if (res.statusCode != 200 || pairs is! List) return null;
- return [for (final raw in pairs) ?PairedDevice.fromJson(raw)];
- } catch (_) {
- return null;
- }
- }
-
- /// Take [fingerprint]'s trust away: it can no longer read or drive this
- /// computer, and any session it has open is dropped (`POST /api/revoke`,
- /// what `harness unpair` sends). True when the daemon did it.
- Future<bool> removePairedDevice(String fingerprint) async {
- try {
- final res = await _dio.post(
- '/api/revoke',
- data: {'id': fingerprint},
- options: Options(headers: {'x-adapter-local': '1'}),
- );
- final data = res.data;
- return res.statusCode == 200 && !(data is Map && data['error'] != null);
- } catch (_) {
- return false;
- }
- }
-
// -- the account's device key log (viewer builds: straight to the backend, signed) --
/// `GET /api/device-keys?since=` — the log from [since]; null when there is none to read (an older
@@ -601,46 +568,3 @@ String describeApiError(Object error) {
return '$error';
}
-/// One entry of [ApiClient.pairedDevices].
-class PairedDevice {
- const PairedDevice({
- required this.fingerprint,
- required this.label,
- required this.pairedAt,
- required this.online,
- });
-
- final String fingerprint;
-
- /// What the device called itself ("Dee's iPhone"). An older phone, or a
- /// computer linked with `harness link connect`, is `harness link` — which
- /// says nothing, so [name] says "Linked device" for it instead.
- final String label;
- final DateTime pairedAt;
- final bool online;
-
- String get name {
- final trimmed = label.trim();
- return trimmed.isEmpty || trimmed == 'harness link' || trimmed == 'browser'
- ? 'Linked device'
- : trimmed;
- }
-
- /// A `web` pairing: a phone or another computer. The dial (`device`) has
- /// its own place, in Settings.
- static PairedDevice? fromJson(Object? raw) {
- if (raw is! Map) return null;
- final fingerprint = raw['fingerprint'], label = raw['label'];
- final pairedAt = raw['pairedAt'], role = raw['role'];
- if (fingerprint is! String || fingerprint.isEmpty) return null;
- if (role != null && role != 'web') return null;
- return PairedDevice(
- fingerprint: fingerprint,
- label: label is String ? label : '',
- pairedAt: pairedAt is num
- ? DateTime.fromMillisecondsSinceEpoch(pairedAt.toInt())
- : DateTime.fromMillisecondsSinceEpoch(0),
- online: raw['online'] == true,
- );
- }
-}
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 0bc9ff18e..77a2e209c 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -2620,14 +2620,24 @@ class _SwarmScreenState extends State<SwarmScreen> {
/// Harness ▸ Add Phone… and `> add phone`: the QR a phone scans to sign in
/// and pair with this computer. See `widgets/add_phone_dialog.dart`.
- Future<void> _addPhone() => _dialog(
- () => showAddPhoneDialog(
- context,
- app,
- keymap: _keymap,
- onConnectMachine: () => unawaited(_openMachines()),
- ),
- );
+ Future<void> _addPhone() async {
+ // "Manage devices…" pops the dialog and asks for Settings, but this
+ // [_dialog] is still open until the pop lands — a [_settings] made from
+ // the callback would be refused. So it is remembered, and opened after.
+ var manageDevices = false;
+ await _dialog(
+ () => showAddPhoneDialog(
+ context,
+ app,
+ keymap: _keymap,
+ onConnectMachine: () => unawaited(_openMachines()),
+ onManageDevices: () => manageDevices = true,
+ ),
+ );
+ if (manageDevices && mounted) {
+ await _settings(SettingsSection.accountDevices);
+ }
+ }
/// Settings, by section, as rows of the box: `> usage` goes straight to
/// Settings ▸ Usage. A palette that finds a setting by name is how an editor
diff --git a/desktop/lib/widgets/add_phone_dialog.dart b/desktop/lib/widgets/add_phone_dialog.dart
index a4151aecc..a0762c1f8 100644
--- a/desktop/lib/widgets/add_phone_dialog.dart
+++ b/desktop/lib/widgets/add_phone_dialog.dart
@@ -44,8 +44,7 @@ Future<void> showAddPhoneDialog(
PhonePairCall? pair,
PhoneSignInCodeCall? signInCode,
VoidCallback? onConnectMachine,
- PairedDevicesCall? listDevices,
- RemovePairedDeviceCall? removeDevice,
+ VoidCallback? onManageDevices,
}) => showTerminalPrompt<void>(
context,
keymap: keymap,
@@ -54,8 +53,7 @@ Future<void> showAddPhoneDialog(
pair: pair,
signInCode: signInCode ?? app.api.phoneSignInCode,
onConnectMachine: onConnectMachine,
- listDevices: listDevices ?? app.api.pairedDevices,
- removeDevice: removeDevice ?? app.api.removePairedDevice,
+ onManageDevices: onManageDevices,
),
);
@@ -232,13 +230,6 @@ PhonePairCall phonePairOverRelay(AppNotifier app, String machineId) =>
/// null when there is none to be had (see [ApiClient.phoneSignInCode]).
typedef PhoneSignInCodeCall = Future<({String code, Duration ttl})?> Function();
-/// The devices paired with this computer, or null when the daemon cannot say
-/// (see [ApiClient.pairedDevices]).
-typedef PairedDevicesCall = Future<List<PairedDevice>?> Function();
-
-/// Unpair one device by its fingerprint; true when it is done.
-typedef RemovePairedDeviceCall = Future<bool> Function(String fingerprint);
-
class AddPhoneDialog extends StatefulWidget {
const AddPhoneDialog({
super.key,
@@ -246,8 +237,7 @@ class AddPhoneDialog extends StatefulWidget {
this.pair,
required this.signInCode,
this.onConnectMachine,
- this.listDevices,
- this.removeDevice,
+ this.onManageDevices,
});
final AppNotifier app;
@@ -255,10 +245,9 @@ class AddPhoneDialog extends StatefulWidget {
final PhoneSignInCodeCall signInCode;
final VoidCallback? onConnectMachine;
- /// The list under the QR — who can already reach this computer — with a way
- /// to take a device's access back. Null shows no list.
- final PairedDevicesCall? listDevices;
- final RemovePairedDeviceCall? removeDevice;
+ /// Opens Settings ▸ Your devices — where the account's devices are listed and
+ /// removed, on every device at once. Null shows no link.
+ final VoidCallback? onManageDevices;
@override
State<AddPhoneDialog> createState() => _AddPhoneDialogState();
@@ -313,16 +302,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
bool _signInAsked = false;
Timer? _signInTimer;
- /// The devices paired with this computer, newest first; null until the
- /// daemon answers, or when it cannot.
- List<PairedDevice>? _devices;
- bool _allDevices = false;
- final _removing = <String>{};
-
- /// How many devices show before "+ N more": the dialog is the QR and a
- /// line, and the list must not outweigh it.
- static const _devicesShown = 3;
-
/// No pairing to be had from this daemon — asking stopped for good.
bool _stopped = false;
String? _connected;
@@ -339,7 +318,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
app.addListener(_appChanged);
_syncLoop();
unawaited(_renewSignIn());
- unawaited(_loadDevices());
}
@override
@@ -412,8 +390,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
_connected = label;
_message = null;
});
- // The phone that just joined is on the list now.
- unawaited(_loadDevices());
if (await _sleep(_connectedHold) && mounted) {
Navigator.of(context).pop();
}
@@ -492,45 +468,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
);
}
- Future<void> _loadDevices() async {
- final list = widget.listDevices;
- if (list == null) return;
- List<PairedDevice>? devices;
- try {
- devices = await list();
- } catch (_) {
- devices = null;
- }
- if (_closed || !mounted) return;
- setState(() => _devices = devices);
- }
-
- /// Takes [device]'s access away. One click, no confirmation: undoing it is
- /// scanning the QR above again, and a device that is not yours should be
- /// gone in one move.
- Future<void> _remove(PairedDevice device) async {
- final remove = widget.removeDevice;
- if (remove == null || _removing.contains(device.fingerprint)) return;
- setState(() => _removing.add(device.fingerprint));
- bool removed;
- try {
- removed = await remove(device.fingerprint);
- } catch (_) {
- removed = false;
- }
- if (_closed || !mounted) return;
- setState(() {
- _removing.remove(device.fingerprint);
- if (removed) {
- _devices = [
- for (final kept in _devices ?? const <PairedDevice>[])
- if (kept.fingerprint != device.fingerprint) kept,
- ];
- }
- });
- if (!removed) _say("Couldn't remove ${device.name}. Try again.");
- }
-
void _say(String message, {bool sticky = false}) => setState(() {
_message = message;
_sticky = sticky;
@@ -653,77 +590,20 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
// One line, and it is the status too: what to do, then that it worked.
// The phone's own screen says the rest (Yes — scan to connect).
_status(),
- ..._devicesList(row),
- ];
- }
-
- /// Who can already reach this computer, with a way to take it back: the
- /// safety net for a QR somebody else scanned.
- List<Widget> _devicesList(double row) {
- final devices = _devices;
- if (devices == null || devices.isEmpty) return const [];
- final shown = _allDevices ? devices : devices.take(_devicesShown).toList();
- final more = devices.length - shown.length;
- return [
- SizedBox(height: row),
- Text(
- 'Paired with this ${_thisComputer()}',
- key: const ValueKey('add-phone-devices'),
- style: DesktopChrome.metadata(),
- ),
- const SizedBox(height: 8),
- for (final device in shown) _deviceRow(device),
- if (more > 0)
- Align(
- alignment: Alignment.centerLeft,
- child: TextButton(
- key: const ValueKey('add-phone-more-devices'),
- onPressed: () => setState(() => _allDevices = true),
- child: Text('Show $more more'),
- ),
+ if (widget.onManageDevices case final manage?) ...[
+ SizedBox(height: row),
+ TextButton(
+ key: const ValueKey('add-phone-manage-devices'),
+ onPressed: () {
+ Navigator.of(context).pop();
+ manage();
+ },
+ child: const Text('Manage devices…'),
),
+ ],
];
}
- Widget _deviceRow(PairedDevice device) {
- final removing = _removing.contains(device.fingerprint);
- return Padding(
- key: ValueKey('add-phone-device-${device.fingerprint}'),
- padding: const EdgeInsets.symmetric(vertical: 4),
- child: Row(
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- device.name,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- style: DesktopChrome.control(),
- ),
- const SizedBox(height: 2),
- Text(
- device.online ? 'Online' : _pairedAgo(device.pairedAt),
- style: DesktopChrome.metadata(
- color: device.online ? grid.AppPalette.online : _faint,
- ),
- ),
- ],
- ),
- ),
- const SizedBox(width: 8),
- TextButton(
- onPressed: removing || widget.removeDevice == null
- ? null
- : () => unawaited(_remove(device)),
- child: Text(removing ? 'Removing…' : 'Remove'),
- ),
- ],
- ),
- );
- }
-
Widget _status() {
final connected = _connected;
final (text, color) = connected != null
@@ -743,16 +623,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
}
}
-/// How long ago [at] was, in one short word: `now`, `5m`, `3h`, `2d`, `6w`.
-String _pairedAgo(DateTime at) {
- final ago = DateTime.now().difference(at);
- if (ago.inMinutes < 1) return 'now';
- if (ago.inHours < 1) return '${ago.inMinutes}m';
- if (ago.inDays < 1) return '${ago.inHours}h';
- if (ago.inDays < 14) return '${ago.inDays}d';
- return '${ago.inDays ~/ 7}w';
-}
-
/// "Mac" where the menu says Harness ▸ Add Phone…; the command palette also
/// reaches this dialog on Linux, where "this Mac" would be wrong.
String _thisComputer() =>
@@ -767,6 +637,9 @@ class PhonePairQr extends StatelessWidget {
final double side;
@override
- Widget build(BuildContext context) =>
- QrCodeView(data: data, side: side, semanticLabel: 'QR code to add your phone');
+ Widget build(BuildContext context) => QrCodeView(
+ data: data,
+ side: side,
+ semanticLabel: 'QR code to add your phone',
+ );
}
diff --git a/desktop/test/add_phone_dialog_test.dart b/desktop/test/add_phone_dialog_test.dart
index 0945e2ea7..c7c4c3453 100644
--- a/desktop/test/add_phone_dialog_test.dart
+++ b/desktop/test/add_phone_dialog_test.dart
@@ -5,7 +5,6 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
-import 'package:harness/api/api_client.dart';
import 'package:harness/core/models.dart';
import 'package:harness/core/config.dart';
import 'package:harness/auth/auth_session.dart';
@@ -71,8 +70,7 @@ Future<void> _open(
PhonePairCall pair, {
PhoneSignInCodeCall? signInCode,
VoidCallback? onConnectMachine,
- PairedDevicesCall? listDevices,
- RemovePairedDeviceCall? removeDevice,
+ VoidCallback? onManageDevices,
}) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(1280, 800);
@@ -91,8 +89,7 @@ Future<void> _open(
pair: pair,
signInCode: signInCode ?? _FakeSignIn().call,
onConnectMachine: onConnectMachine,
- listDevices: listDevices ?? () async => null,
- removeDevice: removeDevice ?? (_) async => false,
+ onManageDevices: onManageDevices,
),
);
await tester.pump();
@@ -308,130 +305,49 @@ void main() {
});
});
- group('the devices already paired', () {
- PairedDevice device(String id, String label, {bool online = false}) =>
- PairedDevice(
- fingerprint: id,
- label: label,
- pairedAt: DateTime.now().subtract(const Duration(days: 2)),
- online: online,
+ group('the account\'s devices', () {
+ testWidgets(
+ 'are one link away — Settings ▸ Your devices — not a list in here',
+ (tester) async {
+ final app = _signedInApp();
+ addTearDown(app.dispose);
+ var opened = 0;
+ await _open(
+ tester,
+ app,
+ _FakeDaemon(List.filled(20, _failed('NO_INTENT'))).call,
+ onManageDevices: () => opened++,
);
+ await tester.pump();
+ final link = find.byKey(const ValueKey('add-phone-manage-devices'));
+ expect(link, findsOneWidget);
+ expect(find.text('Manage devices…'), findsOneWidget);
+ await tester.tap(link);
+ await tester.pump();
+ // The dialog makes way for Settings: one is open at a time.
+ expect(opened, 1);
+ expect(find.byType(AddPhoneDialog), findsNothing);
+ await tester.pump(const Duration(seconds: 10));
+ },
+ );
- testWidgets('are listed under the QR, and one click takes one away', (
- tester,
- ) async {
- final app = _signedInApp();
- addTearDown(app.dispose);
- final removed = <String>[];
- await _open(
- tester,
- app,
- _FakeDaemon(List.filled(20, _failed('NO_INTENT'))).call,
- listDevices: () async => [
- device('AAAA', "Dee's iPhone", online: true),
- device('BBBB', 'harness link'),
- device('CCCC', 'Old phone'),
- device('DDDD', 'Older phone'),
- device('EEEE', 'Oldest phone'),
- ],
- removeDevice: (id) async {
- removed.add(id);
- return true;
- },
- );
- await tester.pump();
- expect(find.byKey(const ValueKey('add-phone-devices')), findsOneWidget);
- expect(find.text("Dee's iPhone"), findsOneWidget);
- expect(find.text('Online'), findsOneWidget);
- // A pairing that never said who it is says so in plain words.
- expect(find.text('Linked device'), findsOneWidget);
- expect(find.text('2d'), findsNWidgets(2));
- // Three, then the rest on request: the list must not outweigh the QR.
- expect(find.text('Older phone'), findsNothing);
- await tester.tap(find.widgetWithText(TextButton, 'Show 2 more'));
- await tester.pump();
- expect(find.text('Oldest phone'), findsOneWidget);
-
- await tester.tap(
- find.descendant(
- of: find.byKey(const ValueKey('add-phone-device-BBBB')),
- matching: find.widgetWithText(TextButton, 'Remove'),
- ),
- );
- await tester.pump();
- await tester.pump();
- expect(removed, ['BBBB']);
- expect(find.text('Linked device'), findsNothing);
-
- await tester.sendKeyEvent(LogicalKeyboardKey.escape);
- await tester.pump();
- await tester.pump(const Duration(seconds: 10));
- });
-
- testWidgets('a removal the daemon refuses keeps the row and says so', (
- tester,
- ) async {
+ testWidgets('no link when there is nowhere to send it', (tester) async {
final app = _signedInApp();
addTearDown(app.dispose);
await _open(
tester,
app,
_FakeDaemon(List.filled(20, _failed('NO_INTENT'))).call,
- listDevices: () async => [device('AAAA', "Dee's iPhone")],
- removeDevice: (_) async => false,
);
await tester.pump();
- await tester.tap(find.widgetWithText(TextButton, 'Remove'));
- await tester.pump();
- await tester.pump();
- expect(find.text("Dee's iPhone"), findsOneWidget);
- expect(_status(tester), "Couldn't remove Dee's iPhone. Try again.");
- await tester.sendKeyEvent(LogicalKeyboardKey.escape);
- await tester.pump();
- await tester.pump(const Duration(seconds: 10));
- });
-
- testWidgets('no list when nothing is paired, or the daemon cannot say', (
- tester,
- ) async {
- final app = _signedInApp();
- addTearDown(app.dispose);
- await _open(
- tester,
- app,
- _FakeDaemon(List.filled(20, _failed('NO_INTENT'))).call,
- listDevices: () async => const [],
+ expect(
+ find.byKey(const ValueKey('add-phone-manage-devices')),
+ findsNothing,
);
- await tester.pump();
- expect(find.byKey(const ValueKey('add-phone-devices')), findsNothing);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
await tester.pump(const Duration(seconds: 10));
});
-
- test('reads the daemon\'s list: web pairings only, named plainly', () {
- final phone = PairedDevice.fromJson({
- 'fingerprint': 'AB12',
- 'label': "Dee's iPhone",
- 'pairedAt': 1790523878148,
- 'online': true,
- 'role': 'web',
- 'current': false,
- })!;
- expect(phone.name, "Dee's iPhone");
- expect(phone.online, isTrue);
- expect(
- PairedDevice.fromJson({'fingerprint': 'X', 'role': 'device'}),
- isNull,
- reason: 'the dial is managed in Settings',
- );
- expect(PairedDevice.fromJson({'label': 'no id'}), isNull);
- expect(
- PairedDevice.fromJson({'fingerprint': 'X', 'label': 'harness link'})!
- .name,
- 'Linked device',
- );
- });
});
group('arming the daemon', () {
@@ -633,5 +549,35 @@ void main() {
expect(find.byType(AddPhoneDialog), findsNothing);
await tester.pumpWidget(const SizedBox());
});
+
+ testWidgets(
+ 'Manage devices… makes way for Settings ▸ Your devices, which opens',
+ (tester) async {
+ // The dialog is still this screen's open dialog while it pops, so a
+ // Settings asked for from the link itself was silently refused.
+ final app = _signedInApp();
+ addTearDown(app.dispose);
+ await mount(tester, app);
+ await chord(tester, LogicalKeyboardKey.keyP, shift: true);
+ await tester.enterText(
+ find.byKey(const ValueKey('swarm-search-input')),
+ '> add phone',
+ );
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ final link = find.byKey(const ValueKey('add-phone-manage-devices'));
+ expect(link, findsOneWidget);
+
+ await tester.tap(link);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.byType(AddPhoneDialog), findsNothing);
+ expect(find.text('Your devices'), findsWidgets);
+ await tester.pumpWidget(const SizedBox());
+ await tester.pump(const Duration(seconds: 10));
+ },
+ );
});
}
diff --git a/desktop/test/connection_review_render_test.dart b/desktop/test/connection_review_render_test.dart
index e1a285ad3..372bd980d 100644
--- a/desktop/test/connection_review_render_test.dart
+++ b/desktop/test/connection_review_render_test.dart
@@ -7,7 +7,6 @@ import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
-import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_link.dart';
import 'package:harness/core/config.dart';
@@ -146,32 +145,17 @@ void main() {
},
signInCode: () async =>
(code: 'synthetic-code', ttl: const Duration(seconds: 90)),
- listDevices: () async => [
- PairedDevice(
- fingerprint: 'FIXTURE',
- label: 'Design team iPhone',
- pairedAt: DateTime(2026, 9, 28),
- online: true,
- ),
- ],
- removeDevice: (_) async => false,
+ onManageDevices: () {},
),
);
await tester.pumpAndSettle();
expect(find.text('Done').hitTestable(), findsOneWidget);
expect(find.byType(PhonePairQr).hitTestable(), findsOneWidget);
await capture('add-phone');
- await tester.ensureVisible(find.text('Remove'));
- await tester.tap(find.text('Remove'));
- await tester.pumpAndSettle();
- await tester.ensureVisible(
- find.byKey(const ValueKey('add-phone-status')),
- );
- expect(
- find.text("Couldn't remove Design team iPhone. Try again."),
- findsOneWidget,
- );
- await capture('add-phone-error');
+ // The way to the account's devices stays reachable at every size.
+ final manage = find.byKey(const ValueKey('add-phone-manage-devices'));
+ await tester.ensureVisible(manage);
+ expect(manage.hitTestable(), findsOneWidget);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
}