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.

Merge branch 'main' into feat/mobile-ios-android

tony798f8550e043
diff --cc mobile/lib/app_shell.dart
index c8f2b2fb1,5b1945b48..23ff1b668
--- a/mobile/lib/app_shell.dart
+++ b/mobile/lib/app_shell.dart
@@@ -257,26 -242,34 +259,42 @@@ class RootShell extends ConsumerWidget
final app = ref.watch(appStateProvider);
return ListenableBuilder(
listenable: app,
- builder: (context, _) {
+ // ⚠️ **Made here and handed through, never made in the builder.** The notifier ticks for
+ // everything on the account — an agent synced, a turn starting on another machine — and
+ // the signed-in screen rebuilt from the top on each one: the shell, its navigator, every
+ // route on it, down to the terminal being typed into. Everything in that screen that draws
+ // from the notifier listens to it for itself, so the tick has nothing to bring it. Made
+ // here, it is the same widget on every tick and Flutter stops at it; it is made again
+ // only when this shell is (a theme or text-size change), which still rebuilds it whole.
+ child: _SignedInScreen(app: app, screen: authenticatedScreen),
- builder: (context, signedIn) => switch (app.status) {
- // `bootstrapping` covers two unrelated moments: the app starting
- // cold, and a sign-in the user just began. The second keeps the
- // signed-out screen, which carries the wait as a state of its own
- // button; swapping the window for a separate screen there was a
- // hard cut in the middle of a flow, and it is why that button's
- // spinner was almost never seen. Keyed on `signingIn`, which spans
- // the whole of it — see [AppNotifier.signingIn].
- AppStatus.bootstrapping =>
- app.signingIn ? signedOutScreen(app) : bootScreen(app),
- AppStatus.unauthenticated => signedOutScreen(app),
- AppStatus.authenticated => signedIn!,
++ builder: (context, signedIn) {
+ final screen = switch (app.status) {
+ // `bootstrapping` covers two unrelated moments: the app starting
+ // cold, and a sign-in the user just began. The second keeps the
+ // signed-out screen, which carries the wait as a state of its own
+ // button; swapping the window for a separate screen there was a
+ // hard cut in the middle of a flow, and it is why that button's
+ // spinner was almost never seen. Keyed on `signingIn`, which spans
+ // the whole of it — see [AppNotifier.signingIn].
+ AppStatus.bootstrapping =>
+ app.signingIn ? signedOutScreen(app) : bootScreen(app),
+ AppStatus.unauthenticated => signedOutScreen(app),
- AppStatus.authenticated => authenticatedScreen(app),
++ AppStatus.authenticated => signedIn!,
+ };
+ if (app.productMeasurement.surface == 'web' ||
+ app.status == AppStatus.authenticated ||
+ (app.status == AppStatus.bootstrapping && !app.signingIn)) {
+ return screen;
+ }
+ return Column(
+ children: [
+ Expanded(child: screen),
+ SafeArea(
+ top: false,
+ child: SetupUsageChoice(measurement: app.productMeasurement),
+ ),
+ ],
+ );
},
);
}
diff --cc mobile/lib/phone/settings_page.dart
index 000addb65,731c71072..3a96d33f1
--- a/mobile/lib/phone/settings_page.dart
+++ b/mobile/lib/phone/settings_page.dart
@@@ -167,10 -163,16 +168,18 @@@ class _Body extends StatelessWidget
// alone, and that is deliberate: it is the only row here anybody opens twice.
// No Stats row: counters this app keeps about itself are nobody's daily question.
buildUsageSettingsRow(context, notifier),
+ if (_sample(context) == null)
+ SettingsRow(title: 'Privacy', onTap: () => Navigator.of(context).push(
+ phoneRoute((_) => PrivacyPage(request: ({bool? enabled}) async {
+ final value = await notifier.api.productUsageSettings(enabled: enabled);
+ notifier.productMeasurement.savedChoice(value);
+ return value;
+ }, feedback: notifier.api.productUsageFeedback)),
+ )),
// The computers this phone reaches — here rather than a menu of their own: linking one is
// a once-a-while errand, and Find already reaches every agent on them.
+ // Each computer's sheet there holds what the account can do to it — try it again, rename
+ // it, take it off the account (`machine_actions.dart`).
SettingsRow(
title: 'Computers',
onTap: () => Navigator.of(context).push(
diff --cc mobile/lib/state/app_state.dart
index 79bd1ac95,c7af3635c..f88ddeab2
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@@ -1696,7 -1498,7 +1753,8 @@@ class AppNotifier extends ChangeNotifie
try {
await login.signIn(email: email, code: code);
if (!_authWorkCurrent(revision)) return;
+ signedInThisRun = true;
+ measureSignIn(ProductOutcome.ok);
status = AppStatus.bootstrapping;
notifyListeners();
await _enterSignedIn(revision);
@@@ -1728,7 -1536,7 +1793,8 @@@
try {
await login.signInWithScan(code, label: phoneClientDescriptor().name);
if (!_authWorkCurrent(revision)) return;
+ signedInThisRun = true;
+ measureSignIn(ProductOutcome.ok);
status = AppStatus.bootstrapping;
notifyListeners();
await _enterSignedIn(revision);
@@@ -2767,29 -2256,37 +2852,38 @@@
void Function(String stage)? onProgress,
}) async {
if (password.isEmpty) return 'Enter the remote password first';
- final result = await peerLinks.connect(
- machineId,
- password,
- onProgress: onProgress,
- displayName: machineStates[machineId]?.machine.displayName,
- label: phoneClientDescriptor().name,
- );
- if (result.error != null) return result.error;
- final targetId = result.linkedMachineId ?? machineId;
- final state = machineStates[targetId];
- // Already in by another way meanwhile — see [_keepsOpenConnection]: nothing to redial.
- if (state != null && !_keepsOpenConnection(state)) {
- state.needsLink = false;
- state.agentLoadStatus = AgentLoadStatus.idle;
- notifyListeners();
- // The old WsConn closed itself permanently on NO_PEER_LINK — connFor() would otherwise see a
- // matching endpointKey and hand back that dead connection instead of dialing a fresh one.
- await _pool?.closeMachine(targetId);
- _connectMachine(state);
+ final finish = productMeasurement.begin(ProductFlow.computerLink);
+ try {
+ final result = await peerLinks.connect(
+ machineId,
+ password,
+ onProgress: onProgress,
+ displayName: machineStates[machineId]?.machine.displayName,
+ label: phoneClientDescriptor().name,
+ );
+ finish(result.error == null ? ProductOutcome.ok : ProductOutcome.failed);
+ if (result.error != null) return result.error;
+ final targetId = result.linkedMachineId ?? machineId;
+ final state = machineStates[targetId];
- if (state != null) {
++ // Already in by another way meanwhile — see [_keepsOpenConnection]: nothing to redial.
++ if (state != null && !_keepsOpenConnection(state)) {
+ state.needsLink = false;
+ state.agentLoadStatus = AgentLoadStatus.idle;
+ notifyListeners();
+ // The old WsConn closed itself permanently on NO_PEER_LINK — connFor() would otherwise see a
+ // matching endpointKey and hand back that dead connection instead of dialing a fresh one.
+ await _pool?.closeMachine(targetId);
+ _connectMachine(state);
+ }
+ // One password, the whole group: this machine learns the phone's other machines, and they it.
+ unawaited(_syncGroup(targetId, spread: true));
+ return null;
+ } catch (_) {
+ finish(ProductOutcome.failed);
+ rethrow;
+ } finally {
+ finish(ProductOutcome.unknown);
}
- // One password, the whole group: this machine learns the phone's other machines, and they it.
- unawaited(_syncGroup(targetId, spread: true));
- return null;
}
// -- the account's devices: the device key log (viewer/device_log_sync.dart) --------------------
@@@ -3407,37 -2690,34 +3533,46 @@@
/// Pairs with [machineId] by the one-time code its desktop app showed, then reconnects it — the
/// QR's way in, where [connectWithPassword] is the password's. Null on success, or what to show.
Future<String?> connectWithCode(String machineId, String code) async {
- final result = await peerLinks.connectWithCode(
- machineId,
- code,
- label: phoneClientDescriptor().name,
- displayName: machineStates[machineId]?.machine.displayName,
- );
- if (result.error != null) return result.error;
- final state = machineStates[result.linkedMachineId ?? machineId];
- if (state != null && !_keepsOpenConnection(state)) {
- state.needsLink = false;
- state.agentLoadStatus = AgentLoadStatus.idle;
- notifyListeners();
- await _pool?.closeMachine(state.machine.machineId);
- _connectMachine(state);
+ final finish = productMeasurement.begin(ProductFlow.computerLink);
+ try {
+ final result = await peerLinks.connectWithCode(
+ machineId,
+ code,
+ label: phoneClientDescriptor().name,
+ displayName: machineStates[machineId]?.machine.displayName,
+ );
+ finish(result.error == null ? ProductOutcome.ok : ProductOutcome.failed);
+ if (result.error != null) return result.error;
+ final state = machineStates[result.linkedMachineId ?? machineId];
- if (state != null) {
++ if (state != null && !_keepsOpenConnection(state)) {
+ state.needsLink = false;
+ state.agentLoadStatus = AgentLoadStatus.idle;
+ notifyListeners();
+ await _pool?.closeMachine(state.machine.machineId);
+ _connectMachine(state);
+ }
+ unawaited(_syncGroup(result.linkedMachineId ?? machineId, spread: true));
+ return null;
+ } catch (_) {
+ finish(ProductOutcome.failed);
+ rethrow;
+ } finally {
+ finish(ProductOutcome.unknown);
}
- unawaited(_syncGroup(result.linkedMachineId ?? machineId, spread: true));
- return null;
}
+ /// Whether a machine just linked (by password or code) is already connected — let in meanwhile
+ /// by another way, the device log's vouched redial above all ([_redialOnceVouched]), which goes
+ /// on dialling behind a machine shown locked.
+ ///
+ /// ⚠️ **Then the link leaves its connection alone.** Both links used to close the machine and
+ /// dial it again whatever its state, to replace a socket that refused this phone — and an open
+ /// one went with it: the terminal on screen read "Connection lost. Reconnecting…" a moment after
+ /// the unlock that was meant to open it. A connected socket has passed the machine's welcome
+ /// (`WsConn._markReady`), so it is no refused one.
+ bool _keepsOpenConnection(MachineState state) =>
+ state.connectionStatus == ConnectionStatus.connected;
+
/// A test's stand-in for the trust-group roster swap; null uses [DirectLink.syncGroup].
late final GroupSync? _groupSyncOverride;
@@@ -8726,9 -6495,9 +8861,11 @@@
@override
void dispose() {
+ productMeasurement.dispose();
+ _measurementConnections.clear();
_disposed = true;
+ // A sign-in page still up has nobody left to come back to: its listener goes.
+ if (signInProvider != null) viewer.login.cancel();
_closedHistory.clear();
_stopAccountTimers();
_stopAllOfflineRetries();
diff --cc mobile/test/app_state_phone_paths_test.dart
index b42d688b7,b42d688b7..774a041ac
--- a/mobile/test/app_state_phone_paths_test.dart
+++ b/mobile/test/app_state_phone_paths_test.dart
@@@ -572,6 -572,6 +572,12 @@@ void main()
rig.app.connectionStatusForTest('m', ConnectionStatus.connected);
async.flushMicrotasks();
final lists = rig.conn('m').payloadsOf('agents_list').length;
++ // A tick waits until the list is an interval old on the real clock
++ // (`DateTime.now()`), which fakeAsync does not move: age the list by
++ // the interval the fake clock is about to pass.
++ rig.app.stateOf('m')!.agentsListedAt = DateTime.now().subtract(
++ AppNotifier.agentSyncInterval,
++ );
async.elapse(AppNotifier.agentSyncInterval);
expect(rig.conn('m').payloadsOf('agents_list'), hasLength(lists + 1));
diff --cc mobile/test/desk_fixture.dart
index 37c10bc39,37c10bc39..29ab5dff8
--- a/mobile/test/desk_fixture.dart
+++ b/mobile/test/desk_fixture.dart
@@@ -41,7 -41,7 +41,8 @@@ class DeskApi extends ApiClient
}
/// A tab of `m`'s agents, named — by hand unless [custom] is false, when the
--/// name is the desk's placeholder and the tab is called after its first agent.
++/// name is the desk's placeholder and the tab takes what most of its agents
++/// share (`deskTabNames`).
DeskTab deskTab(
String id,
String name,
diff --cc mobile/test/desk_groups_test.dart
index cc6484d15,cc6484d15..23d51074b
--- a/mobile/test/desk_groups_test.dart
+++ b/mobile/test/desk_groups_test.dart
@@@ -114,25 -114,25 +114,64 @@@ void main()
expect(activeDeskGroup(built, groups, null).name, 'Docker');
});
-- group('a tab nobody named is called after its first agent', () {
++ group('a tab nobody named takes what most of its agents share', () {
Future<AppNotifier> named(List<DeskTab> tabs) async {
final built = await deskApp(conn, tabs: tabs);
addTearDown(built.dispose);
return built;
}
-- test('its display name, as the desktop names the tab', () async {
-- final built = await named([
-- deskTab('t1', 'Untitled Tab', ['c', 'a'], custom: false),
-- ]);
++ /// Every fixture agent is Claude Code in `work` on `Test host`; [engines]
++ /// and [projects] make some of them something else.
++ void recast(
++ AppNotifier built, {
++ Map<String, String> engines = const {},
++ Map<String, String> projects = const {},
++ }) {
built.stateOf('m')!.agents = [
for (final agent in built.stateOf('m')!.agents)
-- agent.id == 'c'
-- ? Agent(id: 'c', name: 'harness-3', title: 'Greet user')
-- : agent,
++ Agent(
++ id: agent.id,
++ name: agent.name,
++ engine: engines[agent.id] ?? agent.engine,
++ project: AgentProject(
++ name: projects[agent.id] ?? agent.project!.name,
++ cwd: '/${projects[agent.id] ?? agent.project!.name}',
++ ),
++ terminalAvailable: agent.terminalAvailable,
++ ),
];
++ }
++
++ test('agents of one type name it by that type, as the desktop does', () async {
++ final built = await named([
++ deskTab('t1', 'Untitled Tab', ['c', 'a'], custom: false),
++ ]);
++
++ // Type, project and machine each hold both agents: the stronger trait wins.
++ expect(groupsOf(built).single.name, 'code');
++ });
++
++ test('the trait most of its agents share beats a stronger one', () async {
++ final built = await named([
++ deskTab('t1', 'Untitled Tab', ['a', 'b'], custom: false),
++ ]);
++ recast(built, engines: {'a': 'terminal'});
++
++ expect(groupsOf(built).single.name, 'work');
++ });
++
++ test('a tie goes to what the other tabs do not share', () async {
++ final built = await named([
++ deskTab('t1', 'Untitled Tab', ['a', 'b'], custom: false),
++ deskTab('t2', 'Untitled Tab', ['c', 'd'], custom: false),
++ ]);
++ recast(built, projects: {'c': 'site', 'd': 'site'});
-- expect(groupsOf(built).single.name, 'Greet user');
++ expect(
++ [for (final group in groupsOf(built)) group.name],
++ ['work', 'site'],
++ );
});
test('a name somebody chose stands', () async {
@@@ -143,32 -143,32 +182,33 @@@
expect(groupsOf(built).single.name, 'Docker');
});
-- test('an agent with no name of its own leaves the placeholder', () {
-- final tab = deskTab('t1', 'Untitled Tab', ['c'], custom: false);
++ test('a tab with nothing to vote is the placeholder', () async {
++ final built = await named([
++ deskTab('t1', 'Untitled Tab', [], custom: false),
++ ]);
-- expect(
-- deskTabName(tab, const Agent(id: 'c', name: 'harness-3')),
-- 'New Swarm',
-- );
-- expect(deskTabName(tab, null), 'New Swarm');
++ expect(deskTabNames(built), {'t1': 'New Swarm'});
});
-- test('legacy automatic names migrate while explicit names stay intact', () {
-- for (final legacy in [
++ test('legacy automatic names are never shown, explicit names stand', () async {
++ const legacy = [
'New tab',
'New Tab',
'Untitled Tab',
'New Harness',
'New Agent',
-- ]) {
-- expect(
-- deskTabName(deskTab('t1', legacy, [], custom: false), null),
-- 'New Swarm',
-- );
-- expect(
-- deskTabName(deskTab('t1', legacy, [], custom: true), null),
-- legacy,
-- );
++ ];
++ final built = await named([
++ for (final (i, name) in legacy.indexed) ...[
++ deskTab('auto$i', name, [], custom: false),
++ deskTab('chosen$i', name, []),
++ ],
++ ]);
++
++ final names = deskTabNames(built);
++ for (final (i, name) in legacy.indexed) {
++ expect(names['auto$i'], 'New Swarm');
++ expect(names['chosen$i'], name);
}
});
});
diff --cc mobile/test/viewer/direct_link_test.dart
index 54385d1d6,54385d1d6..26f85da7f
--- a/mobile/test/viewer/direct_link_test.dart
+++ b/mobile/test/viewer/direct_link_test.dart
@@@ -156,12 -156,12 +156,16 @@@ void main()
'CODE_MISMATCH',
'That code didn’t match. Scan the new one on Studio Mac.',
),
-- ('TIMEOUT', 'Keep “Add phone” open on Studio Mac, then scan again.'),
++ ('TIMEOUT', 'Keep “Add Phone” open on Studio Mac, then scan again.'),
(
'PAIRING_BUSY',
'Studio Mac is pairing with something else. Try again.',
),
-- ('EXPIRED', 'Couldn’t connect to Studio Mac (EXPIRED).'),
++ (
++ 'EXPIRED',
++ 'Couldn’t pair with Studio Mac. Open Add Phone… on it again and '
++ 'scan the new code.',
++ ),
]) {
final (link, socket, keys) = await linkClient();
socket.onFrame = (frame) {