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): pairing by password names this phone to the computer

dee35d219cf4b60
diff --git a/mobile/lib/auth/cli_link.dart b/mobile/lib/auth/cli_link.dart
index ec8e57c80..bdf6c40e4 100644
--- a/mobile/lib/auth/cli_link.dart
+++ b/mobile/lib/auth/cli_link.dart
@@ -167,6 +167,7 @@ class CliLink implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async {
final invocation = await _runStdinNdjson(
[
diff --git a/mobile/lib/auth/peer_link_client.dart b/mobile/lib/auth/peer_link_client.dart
index 30b6d03ac..b45c08be1 100644
--- a/mobile/lib/auth/peer_link_client.dart
+++ b/mobile/lib/auth/peer_link_client.dart
@@ -12,6 +12,8 @@ abstract interface class PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ // What this device calls itself, for the computer's list of paired devices ("Dee's iPhone").
+ String? label,
});
/// Pairing by the one-time code a desktop app's "Add phone" QR carries (`viewer/code_link.dart`)
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 44c5a6170..ce1d75b08 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -3443,6 +3443,7 @@ class AppNotifier extends ChangeNotifier {
password,
onProgress: onProgress,
displayName: machineStates[machineId]?.machine.displayName,
+ label: phoneClientDescriptor().name,
);
if (result.error != null) return result.error;
final targetId = result.linkedMachineId ?? machineId;
diff --git a/mobile/lib/viewer/direct_link.dart b/mobile/lib/viewer/direct_link.dart
index eb52c9042..e89b92550 100644
--- a/mobile/lib/viewer/direct_link.dart
+++ b/mobile/lib/viewer/direct_link.dart
@@ -30,6 +30,7 @@ class DirectLink implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async {
final String token;
try {
@@ -45,6 +46,7 @@ class DirectLink implements PeerLinkClient {
wsBaseUrl: config.wsBaseUrl,
autonomousEnv: config.autonomousEnv,
onProgress: (stage) => onProgress?.call(stage.wireName),
+ label: label,
socket: socket,
);
switch (result) {
diff --git a/mobile/lib/viewer/password_link.dart b/mobile/lib/viewer/password_link.dart
index 5c366f989..5d8915675 100644
--- a/mobile/lib/viewer/password_link.dart
+++ b/mobile/lib/viewer/password_link.dart
@@ -46,8 +46,10 @@ final class PasswordLinkFailed extends PasswordLinkResult {
final DateTime? retryAt;
}
-typedef RelaySocketFactory =
- WebSocketChannel Function(Uri uri, Iterable<String> protocols);
+typedef RelaySocketFactory = WebSocketChannel Function(
+ Uri uri,
+ Iterable<String> protocols,
+);
WebSocketChannel defaultRelaySocket(Uri uri, Iterable<String> protocols) =>
WebSocketChannel.connect(uri, protocols: protocols);
@@ -66,15 +68,22 @@ Future<PasswordLinkResult> linkWithPassword({
required String wsBaseUrl,
required String autonomousEnv,
void Function(PasswordLinkStage stage)? onProgress,
+ String? label,
RelaySocketFactory socket = defaultRelaySocket,
Duration timeout = const Duration(seconds: 30),
}) async {
onProgress?.call(PasswordLinkStage.connecting);
- final uri = Uri.parse('$wsBaseUrl/api/web-ws').replace(
- queryParameters: {'autonomousEnv': autonomousEnv},
- );
+ final uri = Uri.parse('$wsBaseUrl/api/web-ws')
+ .replace(queryParameters: {'autonomousEnv': autonomousEnv});
final channel = socket(uri, [accessToken]);
- final run = _PasswordLinkRun(machineId, password, identity, channel, onProgress);
+ final run = _PasswordLinkRun(
+ machineId,
+ password,
+ identity,
+ channel,
+ onProgress,
+ label,
+ );
try {
await channel.ready;
return await run.drive().timeout(
@@ -98,6 +107,7 @@ class _PasswordLinkRun {
this.identity,
this.channel,
this.onProgress,
+ this.label,
);
final String machineId;
@@ -106,6 +116,12 @@ class _PasswordLinkRun {
final WebSocketChannel channel;
final void Function(PasswordLinkStage stage)? onProgress;
+ /// This phone's name for itself, sealed into round 4 beside its identity — as authenticated as
+ /// the key it names — so the computer's list of paired devices reads "Dee's iPhone" rather than
+ /// the "harness link" every password pairing used to be filed under. A machine that predates the
+ /// field ignores it.
+ final String? label;
+
final Uint8List _sid = secureRandomBytes(16);
late final String _sidB64 = b64e(_sid);
final String _requestId = b64e(secureRandomBytes(16));
@@ -186,7 +202,12 @@ class _PasswordLinkRun {
theirs,
ours.share,
);
- final transcript = _transcript = transcriptHash(_sid, _ci, theirs, ours.share);
+ final transcript = _transcript = transcriptHash(
+ _sid,
+ _ci,
+ theirs,
+ ours.share,
+ );
onProgress?.call(PasswordLinkStage.verifying);
_send('e2e_pw_pake', {
'sid': _sidB64,
@@ -199,7 +220,9 @@ class _PasswordLinkRun {
/// Round 3 in, round 4 out: the machine proves the password too and hands over its identity,
/// bound to this transcript; ours goes back the same way.
- Future<PasswordLinkResult?> _answerIdentity(Map<String, dynamic> payload) async {
+ Future<PasswordLinkResult?> _answerIdentity(
+ Map<String, dynamic> payload,
+ ) async {
final isk = _isk, transcript = _transcript;
if (isk == null || transcript == null) {
return const PasswordLinkFailed('PROTOCOL_ERROR');
@@ -209,7 +232,12 @@ class _PasswordLinkRun {
return _wrongPassword;
}
final key = pairKey(isk, _ci);
- final opened = aeadOpen(key, 3, utf8Bytes('e2e-id'), b64d(payload['enc'] as String));
+ final opened = aeadOpen(
+ key,
+ 3,
+ utf8Bytes('e2e-id'),
+ b64d(payload['enc'] as String),
+ );
final claim = opened == null ? null : jsonObjectOf(opened);
final id = claim?['id'], sig = claim?['sig'];
if (id is! String || sig is! String) return _wrongPassword;
@@ -221,6 +249,7 @@ class _PasswordLinkRun {
final ours = jsonEncode({
'id': b64e(identity.pub),
'sig': b64e(await pairBindSig(identity, transcript)),
+ if (label case final label? when label.trim().isNotEmpty) 'label': label,
});
_send('e2e_pw_pake', {
'sid': _sidB64,
@@ -244,7 +273,9 @@ class _PasswordLinkRun {
final retryAt = payload['retryAt'];
return PasswordLinkFailed(
_codeOr(payload['error'], 'PAIR_FAILED'),
- retryAt: retryAt is int ? DateTime.fromMillisecondsSinceEpoch(retryAt) : null,
+ retryAt: retryAt is int
+ ? DateTime.fromMillisecondsSinceEpoch(retryAt)
+ : null,
);
}
diff --git a/mobile/test/connect_computer_test.dart b/mobile/test/connect_computer_test.dart
index 1e98cb92a..e5ae1394a 100644
--- a/mobile/test/connect_computer_test.dart
+++ b/mobile/test/connect_computer_test.dart
@@ -31,6 +31,7 @@ class _Links implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async => const CliLinkConnectResult(error: 'not used');
@override
diff --git a/mobile/test/pairing_with_code_test.dart b/mobile/test/pairing_with_code_test.dart
index 00df70391..02ee55797 100644
--- a/mobile/test/pairing_with_code_test.dart
+++ b/mobile/test/pairing_with_code_test.dart
@@ -40,6 +40,7 @@ class _Links implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async => const CliLinkConnectResult(error: 'not used');
@override
diff --git a/mobile/test/unlink_machine_test.dart b/mobile/test/unlink_machine_test.dart
index f85d98646..f4528c127 100644
--- a/mobile/test/unlink_machine_test.dart
+++ b/mobile/test/unlink_machine_test.dart
@@ -16,6 +16,7 @@ class _Links implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async => const CliLinkConnectResult(error: 'not used');
@override
diff --git a/mobile/test/unlock_by_scan_test.dart b/mobile/test/unlock_by_scan_test.dart
index bc33c6614..f0b24248d 100644
--- a/mobile/test/unlock_by_scan_test.dart
+++ b/mobile/test/unlock_by_scan_test.dart
@@ -34,6 +34,7 @@ class _Links implements PeerLinkClient {
String password, {
void Function(String stage)? onProgress,
String? displayName,
+ String? label,
}) async => const CliLinkConnectResult(error: 'not used');
@override