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
feat(mobile): rename, remove, retry computers and profiles
tony28e95521054c
diff --git a/mobile/lib/demo/sample_notifier.dart b/mobile/lib/demo/sample_notifier.dartindex 8b58a2a2a..e1b9cc288 100644--- a/mobile/lib/demo/sample_notifier.dart+++ b/mobile/lib/demo/sample_notifier.dart@@ -187,6 +187,25 @@ class SampleNotifier extends AppNotifier {Future<String?> unlinkMachine(String machineId) async =>'Sample computers stay linked.';+ // Settings ▸ Computers offers these on every computer, the sample's too. Its computers come back+ // from [SampleApiClient.machines] on every refresh, so a rename or a removal would last until the+ // next one — said instead, the way [unlinkMachine] says it.++ @override+ Future<String?> renameMachine(String machineId, String name) async =>+ 'Sample computers keep their names.';++ @override+ Future<String?> deleteMachine(String machineId) async =>+ 'Sample computers stay on the account.';++ /// Always reached, as [reloadMachineData] says: nothing to ask again.+ @override+ Future<String?> retryMachine(String machineId) async {+ notifyListeners();+ return null;+ }+@overridevoid dispose() {_stats.dispose();diff --git a/mobile/lib/phone/desk_groups.dart b/mobile/lib/phone/desk_groups.dartindex d59391549..5a4a729d3 100644--- a/mobile/lib/phone/desk_groups.dart+++ b/mobile/lib/phone/desk_groups.dart@@ -57,12 +57,15 @@ class DeskGroup {////// Never empty: a phone with no tabs, and even one with no agents, still gets/// the single group every caller below is allowed to assume.+///+/// Only the tabs the phone SHOWS — [AppNotifier.profileDeskTabs], narrowed to the+/// computer chosen under Settings ▸ Profile.List<DeskGroup> deskGroups(AppNotifier notifier, List<AgentEntry> visible) {final openable = [for (final entry in visible)if (entry.agent.terminalAvailable) entry,];- final tabs = notifier.deskTabs;+ final tabs = notifier.profileDeskTabs;// No desk, or a desk with nothing on it: one group over the lot. The strip// draws nothing for a single group, so this is the phone as it always was.if (tabs.isEmpty) {@@ -118,8 +121,11 @@ class DeskTabFilter {////// Empty where the desk has no tabs or has not answered — and then there is/// nothing to narrow by, so the list draws no filter at all.+///+/// The tabs the phone shows ([AppNotifier.profileDeskTabs]): a chip for a tab the+/// profile hides would narrow the list to a tab nowhere else on the phone.List<DeskTabFilter> deskTabFilters(AppNotifier notifier) {- final tabs = notifier.deskTabs;+ final tabs = notifier.profileDeskTabs;if (tabs.isEmpty) return const [];final names = deskTabNames(notifier);return [@@ -161,6 +167,9 @@ typedef _TabName = ({_TabTrait trait, String label, int count});/// session engine when its agent is not listed, and counts repetitions across its window-only tabs/// (Store, orchestrator) — neither of which the phone has. Both reach only a tab whose agents the/// machine has not listed, or a tie decided by repetitions.+///+/// ⚠️ Over the WHOLE desk ([AppNotifier.deskTabs]), never the profile's tabs: a tie is decided by+/// repetitions across every tab, and a profile hiding some would rename the rest on this phone alone.Map<String, String> deskTabNames(AppNotifier notifier) {final tabs = notifier.deskTabs;final candidates = <String, List<_TabName>>{};@@ -241,8 +250,12 @@ String? _tabType(String? engine) {/// Read from the desk's panes, not from [deskGroups]: an agent of a tab whose/// terminal is still being verified is missing from its group for those/// seconds, and is not untabbed for it.+///+/// Of the tabs the phone SHOWS ([AppNotifier.profileDeskTabs]): an agent whose only+/// tab the profile hides opens on its own, as one in no tab does, instead of+/// lighting a tab it is not on.bool isUntabbed(AppNotifier notifier, AgentRef agent) {- final tabs = notifier.deskTabs;+ final tabs = notifier.profileDeskTabs;if (tabs.isEmpty) return false;final key = DeskPaneRef(machineId: agent.machineId,diff --git a/mobile/lib/phone/machine_actions.dart b/mobile/lib/phone/machine_actions.dartindex b5cb9954b..aea7be4f4 100644--- a/mobile/lib/phone/machine_actions.dart+++ b/mobile/lib/phone/machine_actions.dart@@ -4,19 +4,27 @@ import 'package:flutter/material.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/widgets/rename_agent_dialog.dart'+ show showMachineRenameDialog;import 'link_page.dart';import 'phone_navigation.dart';import 'phone_sheet.dart';import 'phone_status.dart';+import 'remove_machine.dart';import 'unlink_machine.dart';import 'team_page.dart';-/// A machine that wants its password opens the form for it. One that is linked opens a sheet of-/// what can be done TO it — reload its agents, re-enter its password, unlink this phone.+/// The sheet of what can be done TO a computer — Settings ▸ Computers.///-/// Read at the tap, not when the row was drawn, so a machine that got linked in between gets the-/// sheet rather than a form it no longer needs.+/// Every computer opens it, whatever it reads, because what the account can do to a computer does+/// not wait on the computer: a rename and a removal are the backend's (`AppNotifier.renameMachine`,+/// `deleteMachine`), and an asleep or locked one is as likely as any to be the one somebody wants to+/// rename or take off the account. What its own socket can do — its swarms, its harnesses, its+/// password — is offered only where it answers.+///+/// Read at the tap, not when the row was drawn, so a computer that got linked in between gets the+/// sheet for what it is now.void openMachineActions(BuildContext context,AppNotifier notifier,@@ -24,47 +32,107 @@ void openMachineActions() {final machine = notifier.stateOf(machineId);if (machine == null) return;- switch (phoneMachineStatusOf(machine)) {+ final status = phoneMachineStatusOf(machine);+ final retrying = notifier.machineRetrying(machineId);+ final removing = notifier.machineRemoving(machineId);++ // Asleep or stuck connecting: the one thing worth a tap is asking it again.+ final tryAgain = PhoneSheetAction(+ icon: LucideIcons.refreshCw300,+ label: 'Try again',+ value: retrying ? 'trying…' : null,+ enabled: !retrying && !removing,+ onTap: () => unawaited(retryComputer(context, notifier, machineId)),+ );+ final rename = PhoneSheetAction(+ icon: LucideIcons.pencil300,+ label: 'Rename…',+ enabled: !removing,+ onTap: () =>+ unawaited(showMachineRenameDialog(context, notifier, machineId)),+ );+ final remove = PhoneSheetAction(+ icon: LucideIcons.trash2300,+ label: 'Remove from account…',+ destructive: true,+ value: removing ? 'removing…' : null,+ enabled: !removing,+ onTap: () => unawaited(confirmRemoveMachine(context, notifier, machineId)),+ );++ final List<PhoneSheetAction> actions;+ final List<PhoneSheetAction> destructive;+ switch (status) {case PhoneMachineStatus.offline:- return;+ actions = [tryAgain, rename];+ destructive = [remove];case PhoneMachineStatus.needsPassword:- openMachine(context, notifier, machineId);- return;+ actions = [+ // First, because it is what the row said a tap would do.+ PhoneSheetAction(+ icon: LucideIcons.lockOpen300,+ label: 'Unlock…',+ chevron: true,+ enabled: !removing,+ onTap: () => Navigator.of(context).push(+ phoneRoute(+ (_) => LinkPage(notifier: notifier, machineId: machineId),+ ),+ ),+ ),+ rename,+ ];+ destructive = [remove];case PhoneMachineStatus.connecting || PhoneMachineStatus.ready:- break;+ actions = [+ PhoneSheetAction(+ icon: LucideIcons.users300,+ label: 'Swarms',+ chevron: true,+ onTap: () => Navigator.of(context).push(+ phoneRoute(+ (_) => TeamPage(notifier: notifier, machineId: machineId),+ ),+ ),+ ),+ if (status == PhoneMachineStatus.connecting)+ tryAgain+ else+ PhoneSheetAction(+ icon: LucideIcons.refreshCw300,+ label: 'Reload harnesses',+ onTap: () => unawaited(notifier.reloadMachineData(machineId)),+ ),+ rename,+ PhoneSheetAction(+ icon: LucideIcons.keyRound300,+ label: 'Re-enter password…',+ onTap: () => Navigator.of(context).push(+ phoneRoute(+ (_) => LinkPage(notifier: notifier, machineId: machineId),+ ),+ ),+ ),+ ];+ destructive = [+ // No confirmation, the same as before: this sheet is the step between the tap and the+ // unlink. Removing from the account asks, because it reaches every device.+ PhoneSheetAction(+ icon: LucideIcons.unlink300,+ label: 'Unlink this phone',+ destructive: true,+ enabled: !removing,+ onTap: () => unawaited(unlinkThisPhone(context, notifier, machine)),+ ),+ remove,+ ];}showPhoneSheet(context,title: machine.machine.displayName,- actions: [- PhoneSheetAction(- icon: LucideIcons.users300,- label: 'Swarms',- chevron: true,- onTap: () => Navigator.of(context).push(- phoneRoute((_) => TeamPage(notifier: notifier, machineId: machineId)),- ),- ),- PhoneSheetAction(- icon: LucideIcons.refreshCw300,- label: 'Reload harnesses',- onTap: () => unawaited(notifier.reloadMachineData(machineId)),- ),- PhoneSheetAction(- icon: LucideIcons.keyRound300,- label: 'Re-enter password…',- onTap: () => Navigator.of(context).push(- phoneRoute((_) => LinkPage(notifier: notifier, machineId: machineId)),- ),- ),- // No confirmation, the same as the Machines tab: this sheet is the step between the tap and- // the unlink.- PhoneSheetAction(- icon: LucideIcons.unlink300,- label: 'Unlink this phone',- destructive: true,- onTap: () => unawaited(unlinkThisPhone(context, notifier, machine)),- ),- ],+ actions: actions,+ // Their own card, below a gap: the rows that end something stand apart from the ones that+ // only look or ask.+ sections: [PhoneSheetSection(actions: destructive)],);}diff --git a/mobile/lib/phone/machine_profile_picker.dart b/mobile/lib/phone/machine_profile_picker.dartnew file mode 100644index 000000000..13aa92113--- /dev/null+++ b/mobile/lib/phone/machine_profile_picker.dart@@ -0,0 +1,76 @@+import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import 'package:harness_mobile/state/app_state.dart';++import 'machine_index.dart';+import 'phone_sheet.dart';+import 'phone_status.dart';++/// What Settings ▸ Profile reads: "All computers", or the one whose tabs the phone shows.+String machineProfileLabel(AppNotifier notifier) {+ final id = notifier.machineProfileId;+ if (id == null) return 'All computers';+ // Chosen, but its row not here yet — a launch before the machine list has landed.+ return notifier.stateOf(id)?.machine.displayName ?? 'One computer';+}++/// Settings ▸ Profile: show every computer's tabs, or only one computer's — the desktop's Profiles+/// section (`desktop/lib/settings/sections/profiles_section.dart`) as a phone sheet.+///+/// One sign-in, one desk: picking a computer hides the other computers' tabs on THIS phone only+/// ([AppNotifier.setMachineProfile]). A tab is that computer's when every harness on it runs there.+///+/// A computer the phone cannot reach right now cannot be picked, as on the desktop: it has no live+/// tabs to narrow to. One already picked stays listed and picked whatever it reads, so the choice+/// on screen is never one the sheet hides.+Future<void> showMachineProfilePicker(+ BuildContext context,+ AppNotifier notifier,+) {+ final chosen = notifier.machineProfileId;+ return showPhoneSheet(+ context,+ title: 'Show tabs from',+ actions: [+ PhoneSheetAction(+ icon: chosen == null ? LucideIcons.check300 : LucideIcons.layers300,+ label: 'All computers',+ onTap: () => notifier.setMachineProfile(null),+ ),+ ],+ sections: [+ PhoneSheetSection(+ caption: "Only one computer's tabs",+ actions: [+ for (final machine in visibleMachines(notifier))+ _choice(notifier, machine, chosen),+ ],+ ),+ ],+ );+}++PhoneSheetAction _choice(+ AppNotifier notifier,+ MachineState machine,+ String? chosen,+) {+ final id = machine.machine.machineId;+ final picked = id == chosen;+ final status = phoneMachineStatusOf(machine);+ // The words the Computers page uses for the same states, so a row reads the same in both places.+ final unavailable = switch (status) {+ PhoneMachineStatus.ready => null,+ PhoneMachineStatus.connecting => 'connecting',+ PhoneMachineStatus.needsPassword => 'locked',+ PhoneMachineStatus.offline => 'asleep',+ };+ return PhoneSheetAction(+ icon: picked ? LucideIcons.check300 : LucideIcons.laptopMinimal300,+ label: machine.machine.displayName,+ value: unavailable,+ enabled: picked || unavailable == null,+ onTap: () => notifier.setMachineProfile(id),+ );+}diff --git a/mobile/lib/phone/machines_tab.dart b/mobile/lib/phone/machines_tab.dartindex 7d19d76b2..b3287e702 100644--- a/mobile/lib/phone/machines_tab.dart+++ b/mobile/lib/phone/machines_tab.dart@@ -7,7 +7,6 @@ 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 'welcome/connect_computer.dart';import 'tty_controls.dart';import 'tty.dart';@@ -155,7 +154,8 @@ class _Body extends StatelessWidget {Widget _row(BuildContext context, MachineState state, Tty tty) {final status = phoneMachineStatusOf(state);final count = state.agents.length;- final (String word, Color color, String detail) = switch (status) {+ final machineId = state.machine.machineId;+ var (String word, Color color, String detail) = switch (status) {PhoneMachineStatus.ready => ('ready',tty.green,@@ -175,31 +175,28 @@ class _Body extends StatelessWidget {'turn it on, or run harness start there',),};+ // Something asked of it by hand is still on its way: the row says so, rather than the state it+ // is about to leave.+ if (notifier.machineRemoving(machineId)) {+ (word, color) = ('removing…', tty.faint);+ } else if (notifier.machineRetrying(machineId)) {+ (word, color) = ('trying…', tty.faint);+ }return FindRow(title: state.machine.displayName,detail: detail,state: word,stateColor: color,- enabled: status != PhoneMachineStatus.offline,- onTap: status == PhoneMachineStatus.offline- ? null- : () => _open(context, state),+ // ⚠️ An asleep computer is tappable now. It used to be drawn inert, with nothing a tap could do+ // for it — and it is exactly the one somebody wants to try again, rename, or take off the+ // account.+ onTap: () => _open(context, state),);}- void _open(BuildContext context, MachineState state) {- if (state.needsLink) {- Navigator.of(context).push(- phoneRoute(- (_) =>- LinkPage(notifier: notifier, machineId: state.machine.machineId),- ),- );- return;- }- // The same sheet the terminal's `⋯` used to open for a machine — reload its agents, re-enter its- // password, unlink this phone. One place decides what a machine offers, so a machine tapped here- // and a machine tapped from there cannot drift apart.- openMachineActions(context, notifier, state.machine.machineId);- }+ /// One sheet for every computer, whatever it reads — see [openMachineActions]. A locked one has+ /// "Unlock…" at its head, the act its row offers; one place decides what a computer offers, so no+ /// state can lose the rename or the removal.+ void _open(BuildContext context, MachineState state) =>+ openMachineActions(context, notifier, state.machine.machineId);}diff --git a/mobile/lib/phone/remove_machine.dart b/mobile/lib/phone/remove_machine.dartnew file mode 100644index 000000000..016f52c26--- /dev/null+++ b/mobile/lib/phone/remove_machine.dart@@ -0,0 +1,59 @@+import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import 'package:harness_mobile/state/app_state.dart';++import 'phone_sheet.dart';++/// The one "remove this computer from the account" confirmation on the phone — Settings ▸ Computers.+/// Its own file for the reason `delete_agent.dart` and `unlink_machine.dart` give: one wording of one+/// irreversible act, and one way of reporting that it failed.+///+/// ⚠️ **Not "Unlink this phone", and the sentence has to say so.** Unlinking drops this phone's own+/// pin and leaves the computer as it was. This takes the computer off the ACCOUNT: the backend+/// signs Harness out there (`AppNotifier.deleteMachine`), on every device at once. What it does not+/// touch is the computer's disk — the projects stay — and signing in there again brings it back.+///+/// Says something only when it fails: the row leaving the list is the report that it worked.+Future<void> confirmRemoveMachine(+ BuildContext context,+ AppNotifier notifier,+ String machineId,+) async {+ final machine = notifier.stateOf(machineId)?.machine;+ if (machine == null) return;+ final name = machine.displayName;+ final hostname = machine.hostname?.trim() ?? '';+ final confirmed = await confirmPhoneAction(+ context,+ // The Remove row's own icon — see [confirmPhoneAction].+ icon: LucideIcons.trash2300,+ title: 'Remove $name?',+ // What the computer calls itself, when the account's name for it differs — two computers+ // renamed alike are still told apart at the one step that removes one.+ detail: hostname.isEmpty || hostname == name ? null : hostname,+ message:+ 'It leaves your account, and Harness on that computer is signed out. '+ 'Its projects stay there. Sign in on it again to bring it back.',+ confirmLabel: 'Remove',+ );+ if (!confirmed || !context.mounted) return;+ final error = await notifier.deleteMachine(machineId);+ if (error == null || !context.mounted) return;+ ScaffoldMessenger.maybeOf(context)+ ?.showSnackBar(SnackBar(content: Text(error)));+}++/// "Try again" on a computer that reads asleep or is stuck connecting — see+/// [AppNotifier.retryMachine]. The row's own word moves with the answer, so this says something only+/// when the account itself could not be read.+Future<void> retryComputer(+ BuildContext context,+ AppNotifier notifier,+ String machineId,+) async {+ final error = await notifier.retryMachine(machineId);+ if (error == null || !context.mounted) return;+ ScaffoldMessenger.maybeOf(context)+ ?.showSnackBar(SnackBar(content: Text(error)));+}diff --git a/mobile/lib/phone/settings_page.dart b/mobile/lib/phone/settings_page.dartindex 8740e30b0..d73eca621 100644--- a/mobile/lib/phone/settings_page.dart+++ b/mobile/lib/phone/settings_page.dart@@ -18,6 +18,7 @@ import 'package:harness_mobile/terminal/terminal_theme_store.dart';import 'approve_sign_in.dart';import 'devices_page.dart';+import 'machine_profile_picker.dart';import 'machines_tab.dart';import 'phone_navigation.dart' show phoneRoute;import 'phone_name_store.dart';@@ -164,12 +165,25 @@ class _Body extends StatelessWidget {buildUsageSettingsRow(context, notifier),// 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(phoneRoute((_) => MachinesTab(notifier: notifier, large: false)),),),+ // Which computer's tabs this phone shows — the desktop's Profiles. Beside Computers: it+ // is a choice among them, and changes nothing on any of them. Only once there IS a choice+ // — two computers or more — or one is already made, so it can be undone.+ if (notifier.machines.length > 1 || notifier.machineProfileId != null)+ SettingsRow(+ key: const Key('settings-profile'),+ title: 'Profile',+ value: machineProfileLabel(notifier),+ onTap: () =>+ unawaited(showMachineProfilePicker(context, notifier)),+ ),// Every device signed in to the account — each trusted by the others because of that, so// this is where one that is not yours is seen and taken out.// A computer showing its sign-in QR (`harness login`, or the desktop app's "Scan with yourdiff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex f1f8636b7..ad18b9e99 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -49,6 +49,7 @@ import 'pane_layout_store.dart';import 'session_preview.dart';import 'terminal_pane.dart';import 'desk_sync.dart';+import 'machine_profile.dart';import 'phone_desk.dart';import '../daemons/daemon_habits.dart';import '../daemons/individual_art.dart';@@ -473,6 +474,65 @@ class AppNotifier extends ChangeNotifier {/// before the desk existed.List<DeskTab> get deskTabs => _desk.tabs;+ /// The tabs this phone SHOWS: [deskTabs] narrowed to the computer chosen under Settings ▸ Profile+ /// ([machineProfileId]). What the swipe's groups, Find's tab chips and the launch's choice of tab+ /// read (`phone/desk_groups.dart`). [deskTabs] stays the whole desk for what has to agree with+ /// every other computer — what each tab is called, above all.+ List<DeskTab> get profileDeskTabs =>+ deskTabsForMachineProfile(_desk.tabs, machineProfileId);++ /// The computer whose tabs this phone shows, or null for every computer.+ ///+ /// A choice naming a computer the account no longer has — removed here or elsewhere — reads as+ /// every computer, rather than hiding tabs behind a machine that is not coming back. Before the+ /// list has arrived nothing is known either way, so the choice stands.+ String? get machineProfileId {+ final chosen = machineProfile.value;+ if (chosen == null) return null;+ if (machines.isEmpty || machines.any((m) => m.machineId == chosen)) {+ return chosen;+ }+ return null;+ }++ /// Show every computer's tabs ([machineId] null), or only [machineId]'s. Only this phone changes:+ /// the desk keeps every tab, and no other computer's view moves — the desktop's+ /// `setMachineProfile`.+ void setMachineProfile(String? machineId) {+ if (!machineProfile.select(machineId)) return;+ _keepActiveDeskTabShown();+ notifyListeners();+ }++ /// The tab this phone counts itself in, moved to the first one still shown when a profile hides it+ /// — the desktop's `_ensureProfileFocus`, for the reason that matters most on a phone: a harness+ /// made here joins that tab ([PhoneDesk.adopt]), and must not land in one the phone no longer+ /// shows. Silent ([PhoneDesk.note]): the caller notifies.+ void _keepActiveDeskTabShown() {+ final active = _desk.activeTabId;+ if (active == null) return;+ // ⚠️ Nothing to judge before the desk has answered: the profile lands from disk long before the+ // tabs do from the network, and an empty list would read as "the tab is hidden" and lose the+ // tab the last run was in.+ if (_desk.tabs.isEmpty) return;+ final shown = profileDeskTabs;+ if (shown.any((tab) => tab.id == active)) return;+ final first = shown.firstOrNull?.id;+ _desk.note(first);+ _rememberDeskTab(first);+ }++ /// The profile kept from the last run. Disk only, and off the launch's critical path: the screen+ /// waits for the desk's network read before it picks a tab (`AgentHome._target`), and this lands+ /// long before that.+ Future<void> _loadMachineProfile() async {+ final before = machineProfile.value;+ await machineProfile.load();+ if (_disposed || machineProfile.value == before) return;+ _keepActiveDeskTabShown();+ notifyListeners();+ }+/// The tab the phone is in, or null for an agent no tab holds.String? get activeDeskTabId => _desk.activeTabId;@@ -1006,6 +1066,7 @@ class AppNotifier extends ChangeNotifier {agentPreference = AgentPreference(paneLayoutStore?.storage),projectHistory = ProjectHistory(paneLayoutStore?.storage),lastOpenedAgent = LastOpenedAgent(paneLayoutStore?.storage),+ machineProfile = MachineProfileStore(paneLayoutStore?.storage),searchHistory = PhoneSearchHistory(paneLayoutStore?.storage),// On the same terms as the stores above: a layout store means this is a// real app with a real Harness home to cache into, and its absence means@@ -1084,6 +1145,10 @@ class AppNotifier extends ChangeNotifier {/// The agent the phone's terminal had open, kept across launches — see [LastOpenedAgent].final LastOpenedAgent lastOpenedAgent;+ /// Which computer's tabs this phone shows — Settings ▸ Profile. See [MachineProfileStore] and+ /// [profileDeskTabs].+ final MachineProfileStore machineProfile;+/// The agents and commands reached from the search, most recent first — what/// ranks the box before a word is typed. See [PhoneSearchHistory].///@@ -1354,6 +1419,9 @@ class AppNotifier extends ChangeNotifier {// (top of [bootstrap]); a sign-in in this run starts it here. See// [LastOpenedAgent.prefetch].lastOpenedAgent.prefetch();+ // Which computer's tabs to show (Settings ▸ Profile). Queued behind the record above on+ // purpose, and not awaited: nothing picks a tab before the desk's network read lands.+ unawaited(_loadMachineProfile());// No screen from the last run: the agent that record names is drawn as the skeleton until its// keyframe lands — see [KeptScreenStore]. What an earlier build kept of it on disk goes. Only in// the app, on the store's terms: a test never reaches the real cache directory.@@ -5214,37 +5282,84 @@ class AppNotifier extends ChangeNotifier {return null;}+ /// The longest name the backend keeps for a computer — `renameBody` in+ /// `backend/src/routes/machines.ts` refuses anything longer.+ static const machineNameMaxLength = 40;+/// Renames a machine via `PATCH /api/machines/:machineId` (control-plane REST — the machine's/// `name` is backend-owned, unlike an agent's, which lives on the harness CLI). Returns null on/// success, or an error message to show inline in the caller's dialog.Future<String?> renameMachine(String machineId, String name) async {- final state = machineStates[machineId];- if (state == null) return 'Machine not found';+ final revision = _authRevision;+ if (machineStates[machineId] == null) {+ return 'This computer is no longer on your account.';+ }final trimmed = name.trim();if (trimmed.isEmpty) return 'Name cannot be empty';+ if (trimmed.length > machineNameMaxLength) {+ return 'Use $machineNameMaxLength characters or fewer.';+ }try {await api.renameMachine(machineId: machineId, name: trimmed);} catch (error) {- return 'Rename failed: $error';+ return 'Rename failed: ${describeApiError(error)}';}+ // Signed out, or into another account, while the request was out: nothing here is theirs.+ if (!_authWorkCurrent(revision)) return null;+ // Looked up again — a refresh may have replaced the state while the request was out.+ final state = machineStates[machineId];+ if (state == null) return null;state.machine = state.machine.copyWith(name: trimmed);final index = machines.indexWhere((m) => m.machineId == machineId);if (index != -1) machines[index] = state.machine;+ // The next launch draws its rows from the cache before `/api/machines` answers: the old name+ // there would come back for those seconds.+ final cache = _machineCache;+ if (cache != null) _writeMachineCache(cache);notifyListeners();return null;}+ /// Machines being removed right now ([deleteMachine]). Their rows say so, and a second press joins+ /// the first rather than sending a second `DELETE`, which the backend would answer with a 404.+ final Map<String, Future<String?>> _machineDeletes = {};++ bool machineRemoving(String machineId) =>+ _machineDeletes.containsKey(machineId);+/// Permanently deletes a machine from the account (backend `DELETE /api/machines/:id`) — not to/// be confused with [unlinkMachine], which only drops this computer's local E2EE trust pin and/// leaves the machine itself intact. Returns null on success, or an error message to show inline.- Future<String?> deleteMachine(String machineId) async {- final state = machineStates[machineId];- if (state == null) return 'Machine not found';+ ///+ /// ⚠️ **The backend also signs that computer out.** It pushes `machine_revoked` down to a daemon+ /// that is connected (`MachineService.destroy`), which clears its session and stops; one that is+ /// off finds out on its next dial. The confirmation that leads here has to say so.+ Future<String?> deleteMachine(String machineId) {+ final inFlight = _machineDeletes[machineId];+ if (inFlight != null) return inFlight;+ if (machineStates[machineId] == null) {+ return Future.value('This computer is no longer on your account.');+ }+ late final Future<String?> run;+ run = _performDeleteMachine(machineId).whenComplete(() {+ if (identical(_machineDeletes[machineId], run)) {+ _machineDeletes.remove(machineId);+ }+ if (!_disposed) notifyListeners();+ });+ _machineDeletes[machineId] = run;+ notifyListeners();+ return run;+ }++ Future<String?> _performDeleteMachine(String machineId) async {+ final revision = _authRevision;try {await api.deleteMachine(machineId: machineId);} catch (error) {- return 'Delete failed: $error';+ return 'Could not remove it: ${describeApiError(error)}';}+ if (!_authWorkCurrent(revision)) return null;// Any tile still showing this machine would otherwise sit forever in the "waiting to answer"// busy state, since the machine can never be found again after this.for (final pane in panesFor(machineId).toList()) {@@ -5253,15 +5368,91 @@ class AppNotifier extends ChangeNotifier {}await _detachSession(pane, sendClose: true);}+ if (!_authWorkCurrent(revision)) return null;_persistLayout();+ // Everything [_refreshMachines] lets go of for a machine that left the account — the SOCKET+ // above all, which would otherwise go on dialling a machine nothing refers to any more.+ final state = machineStates[machineId];+ if (state != null) _clearMachineActivity(state);+ _stopOfflineRetry(machineId);_stopAgentSyncTimer(machineId);+ unawaited(_pool?.closeMachine(machineId));machineStates.remove(machineId);machines.removeWhere((m) => m.machineId == machineId);+ expandedMachines.remove(machineId);if (selectedMachineId == machineId) selectedMachineId = null;+ if (pendingPairing?.machineId == machineId) pendingPairing = null;+ // A profile on the computer that just left would show its tabs no longer; back to every one.+ if (machineProfile.value == machineId) machineProfile.select(null);+ _keepActiveDeskTabShown();+ final cache = _machineCache;+ if (cache != null) _writeMachineCache(cache);notifyListeners();return null;}+ /// Computers being tried again by hand ([retryMachine]) — the row says so while it runs.+ final Map<String, Future<String?>> _machineRetries = {};++ bool machineRetrying(String machineId) =>+ _machineRetries.containsKey(machineId);++ /// One computer asked again, by hand — Settings ▸ Computers' "Try again", for a machine that reads+ /// asleep or is stuck connecting.+ ///+ /// ⚠️ **Not [retryOfflineMachine].** That one only polls for a machine somebody is waiting on an+ /// agent of (`pendingOfflineAgentId`), which on a phone is almost never set — it would do nothing+ /// here. Nor [retryMachines], which re-reads the account but never dials a machine the account+ /// calls down ([_autoConnectAndLoadMachines]), and that status is exactly what is being doubted.+ ///+ /// So: the account's word on it now, then a dial whatever that word is — the way [reachAllMachines]+ /// dials for Find — cutting short any backoff and waking a socket the relay parked as offline+ /// ([_redialNow]). A machine waiting on its password is not dialled: that is refused again until+ /// one lands.+ ///+ /// Returns null, or why the account could not be read; the dial is made either way, on the list+ /// the phone already has.+ Future<String?> retryMachine(String machineId) {+ final inFlight = _machineRetries[machineId];+ if (inFlight != null) return inFlight;+ late final Future<String?> run;+ run = _performRetryMachine(machineId).whenComplete(() {+ if (identical(_machineRetries[machineId], run)) {+ _machineRetries.remove(machineId);+ }+ if (!_disposed) notifyListeners();+ });+ _machineRetries[machineId] = run;+ notifyListeners();+ return run;+ }++ Future<String?> _performRetryMachine(String machineId) async {+ final revision = _authRevision;+ if (!_authWorkCurrent(revision) || status == AppStatus.unauthenticated) {+ return null;+ }+ String? failure;+ try {+ await refreshMachines();+ } catch (error) {+ failure = 'Could not load computers: ${describeApiError(error)}';+ }+ if (_disposed || !_authWorkCurrent(revision)) return null;+ final state = machineStates[machineId];+ if (state == null) {+ return failure ?? 'This computer is no longer on your account.';+ }+ if (state.needsLink) return failure;+ // No transport — the same guard [reachAllMachines] keeps: [_conn] would build one out of a+ // null pool.+ if (_pool == null && connectionForTest == null) return failure;+ _connectMachine(state);+ _redialNow(machineId);+ await _loadMachineData(state, force: true);+ return failure;+ }+/// Renames an agent via `agent_update`. Returns null on success, or an error message to show/// inline in the caller's dialog.Future<String?> renameAgent(diff --git a/mobile/lib/state/machine_profile.dart b/mobile/lib/state/machine_profile.dartnew file mode 100644index 000000000..29ed94bd2--- /dev/null+++ b/mobile/lib/state/machine_profile.dart@@ -0,0 +1,92 @@+import '../core/local_key_value_store.dart';+import 'desk_sync.dart';++/// Which computer this phone is looking at — the desktop's Profiles (`desktop/lib/state/+/// machine_profile.dart`), on the account's [DeskTab]s rather than on a window's swarms.+///+/// The account still has one desk, the same tabs on every computer and on this phone; a profile only+/// decides which of those tabs the phone shows. `null` is every computer. A machine id is that+/// computer alone: a tab is in it when every agent it names runs there. A tab that names no agent+/// stays, as on the desktop, so there is always a tab to be in.+bool deskTabMatchesMachineProfile(DeskTab tab, String? machineId) {+ if (machineId == null || machineId.isEmpty) return true;+ if (tab.panes.isEmpty) return true;+ return tab.panes.every((pane) => pane.machineId == machineId);+}++/// The tabs this phone shows for [machineId], in the desk's order. The desk's own list is not+/// touched: the other computers' tabs stay on it, they are only not drawn here.+///+/// A profile only hides. When it would hide every tab the phone shows them all — the desktop's rule+/// (`swarmsForMachineProfile`), and for its reason: nothing here may make a tab to stand in, because+/// a tab made on the phone is a tab on every computer of the account.+List<DeskTab> deskTabsForMachineProfile(List<DeskTab> tabs, String? machineId) {+ if (machineId == null || machineId.isEmpty) return tabs;+ final shown = [+ for (final tab in tabs)+ if (deskTabMatchesMachineProfile(tab, machineId)) tab,+ ];+ return shown.isEmpty ? tabs : shown;+}++/// The profile this phone chose, remembered across launches on the terms of the other per-phone+/// records (`AgentPreference`, `LastOpenedAgent`): with no storage — a test — it lives for the run+/// and is written nowhere.+///+/// A phone's own choice, never the desk's, exactly as a window's profile is that window's: picking a+/// computer here changes nothing on the desktop beside it.+class MachineProfileStore {+ MachineProfileStore(this.storage);++ final LocalKeyValueStore? storage;++ /// The desktop's key for the same choice. A phone's state file is its own, so the two never meet;+ /// the name says what is stored.+ static const _key = 'machine_profile_v1';++ /// The chosen machine id, or null for every computer.+ String? get value => _value;+ String? _value;++ Future<void>? _loading;+ Future<void> _writes = Future.value();++ /// Bumped by [select], so a read that lands after a choice made in this run cannot undo it.+ int _revision = 0;++ /// Idempotent: the launch and anything that asks later share one read.+ Future<void> load() => _loading ??= _read();++ Future<void> _read() async {+ final revision = _revision;+ try {+ final stored = (await storage?.read(_key))?.trim();+ if (revision != _revision) return;+ _value = stored == null || stored.isEmpty ? null : stored;+ } catch (_) {+ // Every computer, which is what a phone with no record shows anyway.+ }+ }++ /// Null or empty is every computer. Returns whether anything changed.+ bool select(String? machineId) {+ final clean = machineId?.trim();+ final next = clean == null || clean.isEmpty ? null : clean;+ _revision++;+ if (next == _value) return false;+ _value = next;+ // In order, one after another: two quick picks must land on disk as the second.+ _writes = _writes.then((_) async {+ try {+ if (next == null) {+ await storage?.delete(_key);+ } else {+ await storage?.write(_key, next);+ }+ } catch (_) {+ // Kept for this run; the next launch shows every computer.+ }+ });+ return true;+ }+}diff --git a/mobile/lib/widgets/rename_agent_dialog.dart b/mobile/lib/widgets/rename_agent_dialog.dartindex 259f1c299..dd31dfa19 100644--- a/mobile/lib/widgets/rename_agent_dialog.dart+++ b/mobile/lib/widgets/rename_agent_dialog.dart@@ -30,15 +30,55 @@ Future<void> showAgentRenameDialog(String machineId,String agentId,String currentName,-) => showAppDialog<void>(- context: context,- builder: (_) => _RenameAgentDialog(- notifier: notifier,- machineId: machineId,- agentId: agentId,- currentName: currentName,- ),-);+) {+ final place = _placeOf(notifier, machineId, agentId);+ final agent = place.agent;+ return showAppDialog<void>(+ context: context,+ builder: (_) => _RenameDialog(+ title: 'Rename Harness',+ currentName: currentName,+ detail: place.detail,+ leading: agent == null+ ? null+ : EngineMark(+ engine: agent.engine,+ displayName: agent.engineDisplayName,+ size: 32,+ ),+ onSave: (name) => notifier.renameAgent(machineId, agentId, name),+ ),+ );+}++/// The same dialog for a computer — Settings ▸ Computers. Its name is the account's, kept by the+/// backend ([AppNotifier.renameMachine]), so it holds to the backend's length.+Future<void> showMachineRenameDialog(+ BuildContext context,+ AppNotifier notifier,+ String machineId,+) {+ final machine = notifier.stateOf(machineId)?.machine;+ if (machine == null) return Future.value();+ final hostname = machine.hostname?.trim() ?? '';+ return showAppDialog<void>(+ context: context,+ builder: (_) => _RenameDialog(+ title: 'Rename Computer',+ currentName: machine.displayName,+ // What the computer calls itself, which a rename does not change — the one name left to+ // tell it by once its own has gone.+ detail: hostname == machine.displayName ? '' : hostname,+ leading: Icon(+ LucideIcons.laptopMinimal300,+ size: 28,+ color: grid.AppPalette.textSecondary,+ ),+ maxLength: AppNotifier.machineNameMaxLength,+ onSave: (name) => notifier.renameMachine(machineId, name),+ ),+ );+}/// The field's corner — the buttons' too. Its focus ring stands 4 outside it,/// on the same curve.@@ -56,24 +96,37 @@ const double _fieldRadius = kDialogControlRadius;////// A `State` disposes on unmount instead, which happens after the transition/// has finished and the route is gone, so there is nothing left to rebuild.-class _RenameAgentDialog extends StatefulWidget {- const _RenameAgentDialog({- required this.notifier,- required this.machineId,- required this.agentId,+class _RenameDialog extends StatefulWidget {+ const _RenameDialog({+ required this.title,required this.currentName,+ required this.detail,+ required this.onSave,+ this.leading,+ this.maxLength,});- final AppNotifier notifier;- final String machineId;- final String agentId;+ /// The act, small, over the field — "Rename Harness".+ final String title;final String currentName;+ /// Where the thing lives, under the title; empty for nothing.+ final String detail;++ /// The mark beside the title — an engine's, for an agent.+ final Widget? leading;++ /// The longest name the field takes; null for no limit of its own.+ final int? maxLength;++ /// Sends the name. Null when it took, or the refusal to show under the field.+ final Future<String?> Function(String name) onSave;+@override- State<_RenameAgentDialog> createState() => _RenameAgentDialogState();+ State<_RenameDialog> createState() => _RenameDialogState();}-class _RenameAgentDialogState extends State<_RenameAgentDialog> {+class _RenameDialogState extends State<_RenameDialog> {/// Opens with the whole name selected, as the tab rename dialog does: the/// name is there to be replaced, so the first key wipes it, and a thumb that/// meant to edit it still has the caret.@@ -86,13 +139,6 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {/// The field's focus, which is what draws the ring around it.final _focus = FocusNode();- /// Where the agent runs, as it stood when the dialog opened — see [_placeOf].- late final _place = _placeOf(- widget.notifier,- widget.machineId,- widget.agentId,- );-/// The text as of the last edit. The controller also notifies on a caret/// move, and only a change to the name itself takes an error back.///@@ -197,11 +243,7 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {_busy = true;_error = null;});- final result = await widget.notifier.renameAgent(- widget.machineId,- widget.agentId,- _controller.text,- );+ final result = await widget.onSave(_controller.text);// ⚠️ `mounted` is not "still open". Cancel, the veil and Escape all stay// live while Save spins, and a dialog closed that way is still mounted for// the length of its fade — so an answer landing inside those 140ms found@@ -237,7 +279,7 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {scopesRoute: true,namesRoute: true,explicitChildNodes: true,- label: 'Rename Harness',+ label: widget.title,child: ConstrainedBox(constraints: const BoxConstraints(maxWidth: 360),child: Padding(@@ -290,18 +332,14 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {);}- /// What is being renamed: the engine's mark, the act, and where the agent- /// runs. Small on purpose — the field under it is what the dialog is for.+ /// What is being renamed: its mark, the act, and where it lives. Small on+ /// purpose — the field under it is what the dialog is for.Widget _heading() {- final agent = _place.agent;+ final leading = widget.leading;return Row(children: [- if (agent != null) ...[- EngineMark(- engine: agent.engine,- displayName: agent.engineDisplayName,- size: 32,- ),+ if (leading != null) ...[+ SizedBox.square(dimension: 32, child: Center(child: leading)),const SizedBox(width: 12),],Expanded(@@ -310,17 +348,17 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {crossAxisAlignment: CrossAxisAlignment.start,children: [Text(- 'Rename Harness',+ widget.title,style: TextStyle(color: grid.AppPalette.textPrimary,fontSize: 17,fontWeight: grid.AppFont.semibold,),),- if (_place.detail.isNotEmpty) ...[+ if (widget.detail.isNotEmpty) ...[const SizedBox(height: 2),Text(- _place.detail,+ widget.detail,maxLines: 1,overflow: TextOverflow.ellipsis,style: TextStyle(@@ -368,6 +406,10 @@ class _RenameAgentDialogState extends State<_RenameAgentDialog> {// Held still while the machine answers: an edit made under the spinner// would be a name nobody sent.readOnly: _busy,+ inputFormatters: [+ if (widget.maxLength case final max?)+ LengthLimitingTextInputFormatter(max),+ ],textInputAction: TextInputAction.done,style: grid.kFieldTextStyle.copyWith(fontSize: 17,diff --git a/mobile/test/app_state_agent_rpcs_test.dart b/mobile/test/app_state_agent_rpcs_test.dartindex b1d690d8a..180780315 100644--- a/mobile/test/app_state_agent_rpcs_test.dart+++ b/mobile/test/app_state_agent_rpcs_test.dart@@ -1410,7 +1410,10 @@ void main() {expect(rig.app.machines.single.displayName, 'Studio');expect(await rig.app.renameMachine('m', ' '), 'Name cannot be empty');- expect(await rig.app.renameMachine('ghost', 'x'), 'Machine not found');+ expect(+ await rig.app.renameMachine('ghost', 'x'),+ 'This computer is no longer on your account.',+ );rig.api.renameFailure = StateError('403');expect(await rig.app.renameMachine('m', 'x'),@@ -1427,9 +1430,15 @@ void main() {await openAgent(rig, 'm', 'a');rig.api.deleteFailure = StateError('403');- expect(await rig.app.deleteMachine('m'), startsWith('Delete failed'));+ expect(+ await rig.app.deleteMachine('m'),+ startsWith('Could not remove it'),+ );rig.api.deleteFailure = null;- expect(await rig.app.deleteMachine('ghost'), 'Machine not found');+ expect(+ await rig.app.deleteMachine('ghost'),+ 'This computer is no longer on your account.',+ );expect(await rig.app.deleteMachine('m'), isNull);expect(rig.api.deleted, ['m']);