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.

refactor(mobile): delete the session status helpers nothing on the phone reads

dee23da5ad06c78
diff --git a/mobile/lib/phone/phone_status.dart b/mobile/lib/phone/phone_status.dart
index 39612cc31..e74a4dd9d 100644
--- a/mobile/lib/phone/phone_status.dart
+++ b/mobile/lib/phone/phone_status.dart
@@ -1,6 +1,5 @@
import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/state/app_state.dart';
-import 'package:harness_mobile/terminal/terminal_session.dart';
/// How a phone status line is coloured. The widgets turn this into a palette colour, so the
/// rules below stay testable without a theme.
@@ -111,136 +110,3 @@ PhoneSummary phoneAgentSummary(MachineState machine, Agent agent) {
tone: PhoneTone.quiet,
);
}
-
-/// Whether the streams [machine] lost are on their way back without anybody asking: its socket is
-/// dialling, or waiting out a backoff to dial again, or it is up and still fetching what the
-/// reattach waits on — once that lands, `_attachPendingPanes` reopens every stream the drop left
-/// dead.
-///
-/// For the terminal header, which reads a dead stream as "Reconnecting…" rather than as a dead end
-/// while this holds — see [phoneSessionSummary]. A phone loses its socket every time it goes to the
-/// background, so this is the ordinary way back into a terminal, and a Reconnect button over it
-/// only ever meant "wait": the press is declined while the socket is down.
-///
-/// ⚠️ **`disconnected` is not on its way back.** It is a socket this app closed on purpose — signed
-/// out, refused by the relay, shut — and nothing redials it; `connecting` and `reconnecting` are the
-/// two with a dial behind them (`WsConn._scheduleReconnect`). An offline machine and one that needs
-/// its password are out for the same reason: no dial fixes either.
-bool phoneMachineRedialling(MachineState machine) {
- if (machine.nodeOnline == false || machine.needsLink) return false;
- return switch (machine.connectionStatus) {
- ConnectionStatus.connecting || ConnectionStatus.reconnecting => true,
- // ⚠️ **Up is not back yet.** The reattach waits for the agent list and the terminal
- // capabilities — `_attachPendingPanes` runs when the later of the two answers — and a refresh
- // over a list already held reports `agentsRefreshing` rather than `loading`. Counting only the
- // socket put "Disconnected" and its button back on screen for the stretch between the socket
- // answering and the stream reopening.
- ConnectionStatus.connected =>
- machine.agentLoadStatus == AgentLoadStatus.loading ||
- machine.agentsRefreshing ||
- machine.terminalCapabilityLoadInFlight != null,
- ConnectionStatus.disconnected => false,
- };
-}
-
-/// The terminal's own state, for the header over it. No session yet reads as attaching: the
-/// page opens before the pane has one.
-/// [takerName]: who took the terminal, when known ([phoneTakerName]) — the
-/// dot's tooltip then says "Taken over by Mac mini" rather than just that it was.
-/// [reconnecting]: a dead stream is already on its way back — its machine is redialling
-/// ([phoneMachineRedialling]), or the person has just pressed Reconnect. Disconnected and Closed
-/// then read as "Reconnecting…", busy like Attaching: there is nothing to press, and the header
-/// draws the wait rather than a dead end.
-PhoneSummary phoneSessionSummary(
- TerminalSession? session, {
- String? takerName,
- bool reconnecting = false,
-}) {
- // ⚠️ Checked BEFORE the status, because a watcher's status is `controlling` — it holds a live
- // stream and renders every byte; what it does not hold is the terminal. "Live" would promise a
- // prompt that ignores typing. See [TerminalSession.watching].
- if (session != null && session.watching) {
- return (label: 'Watching', tone: PhoneTone.attention);
- }
- return switch (session?.status) {
- null || TerminalSessionStatus.opening => (
- label: 'Attaching…',
- tone: PhoneTone.busy,
- ),
- TerminalSessionStatus.resyncing => (
- label: 'Resyncing…',
- tone: PhoneTone.busy,
- ),
- TerminalSessionStatus.controlling => (label: 'Live', tone: PhoneTone.good),
- TerminalSessionStatus.takenOver => (
- label: takerName == null ? 'Taken over' : 'Taken over by $takerName',
- tone: PhoneTone.attention,
- ),
- TerminalSessionStatus.error || TerminalSessionStatus.closed
- when reconnecting =>
- (label: 'Reconnecting…', tone: PhoneTone.busy),
- TerminalSessionStatus.error => (label: 'Disconnected', tone: PhoneTone.bad),
- TerminalSessionStatus.closed => (label: 'Closed', tone: PhoneTone.quiet),
- };
-}
-
-/// Who took this session's terminal, by the fleet's current name for their
-/// machine when this phone knows it, else the name they declared; null while
-/// nobody has, or when the daemon did not say (an older one, or a taker that
-/// did not introduce itself).
-String? phoneTakerName(
- TerminalSession? session,
- String? Function(String machineId) resolveMachine,
-) => session?.status == TerminalSessionStatus.takenOver
- ? session?.takenOverBy?.label(resolveMachine)
- : null;
-
-/// Who is driving the terminal this session only watches, when the daemon said — the fleet's name
-/// for that machine where it knows one. Null unless [TerminalSession.watching].
-String? phoneHolderName(
- TerminalSession? session,
- String? Function(String machineId) resolveMachine,
-) => session?.watching == true ? session?.heldBy?.label(resolveMachine) : null;
-
-/// The one line under the header while another client drives this terminal —
-/// the desktop's banner, at phone size. Null in every other state.
-String? phoneTakeoverNotice(TerminalSession? session, String? takerName) =>
- session?.status == TerminalSessionStatus.takenOver
- ? '${takerName ?? 'Another app'} took control of this terminal'
- : null;
-
-/// The way back into a session this device is not driving, or is no longer
-/// driving — and what the button offers to do about it.
-///
-/// `null` while the session is fine, or still coming up: there is nothing to
-/// reclaim from "Attaching…", and a button that only ever means "wait" is one
-/// the person learns to ignore.
-///
-/// The desktop puts the same two words on the same two states, in the tile
-/// header it draws (`widgets/terminal_panel.dart`); a phone hides that header
-/// and draws its own, which is how the way out went missing here.
-///
-/// [reconnecting]: as for [phoneSessionSummary] — a dead stream already on its
-/// way back offers no Reconnect, for the reason above: while the socket is down
-/// the press is declined, so the button would only ever mean "wait".
-PhoneSummary? phoneReclaimAction(
- TerminalSession? session, {
- bool reconnecting = false,
-}) {
- // A watcher is the ordinary way onto an agent another app is driving: output is already on
- // screen, and this is the button that asks for the keyboard. See [TerminalSession.watching].
- if (session != null && session.watching) {
- return (label: 'Take control', tone: PhoneTone.attention);
- }
- return switch (session?.status) {
- TerminalSessionStatus.takenOver => (
- label: 'Take control',
- tone: PhoneTone.attention,
- ),
- TerminalSessionStatus.error ||
- TerminalSessionStatus.closed when reconnecting => null,
- TerminalSessionStatus.error ||
- TerminalSessionStatus.closed => (label: 'Reconnect', tone: PhoneTone.bad),
- _ => null,
- };
-}
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 4ae5467c0..7a60318f7 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -194,7 +194,6 @@ typedef _PageFacts = ({
AgentLoadStatus? agentLoadStatus,
bool machinePresent,
PhoneMachineStatus? machineStatus,
- bool redialling,
bool imagePaste,
String? machineName,
});
@@ -640,14 +639,6 @@ class _TerminalPageState extends State<TerminalPage>
agentLoadStatus: machine?.agentLoadStatus,
machinePresent: machine != null,
machineStatus: machine == null ? null : phoneMachineStatusOf(machine),
- // Only while the stream is dead — the one state it changes how the
- // header reads. A live page has no reason to rebuild each time the agent
- // list refreshes underneath it.
- redialling:
- machine != null &&
- (session?.status == TerminalSessionStatus.error ||
- session?.status == TerminalSessionStatus.closed) &&
- phoneMachineRedialling(machine),
imagePaste: machine?.terminalImagePasteAvailable ?? false,
machineName: machine?.machine.displayName,
);
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 9d00dcb94..14faf37cc 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -5990,8 +5990,8 @@ class AppNotifier extends ChangeNotifier {
/// read-only stream and a "Take control" band in front of every agent a desktop had open,
/// including the one the app opens on.
///
- /// The displaced app is told who took it and has the same one press back; the phone's own band
- /// is for exactly that case, a terminal taken back off this device — see `phoneReclaimAction`.
+ /// The displaced app is told who took it and has the same one press back; on the phone that
+ /// press is a tap or a scroll on the terminal taken back off it.
///
/// The one open that stays polite is [warmAgentPane]'s guess about the next swipe, which is
/// nobody arriving anywhere. See [_attachSession].
diff --git a/mobile/test/phone_reclaim_test.dart b/mobile/test/phone_reclaim_test.dart
index 430e34af0..198a1418b 100644
--- a/mobile/test/phone_reclaim_test.dart
+++ b/mobile/test/phone_reclaim_test.dart
@@ -1,6 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/terminal/terminal_session.dart';
-import 'package:harness_mobile/phone/phone_status.dart';
TerminalSession _session(TerminalSessionStatus status) => TerminalSession(
machineId: 'm',
@@ -11,43 +10,9 @@ TerminalSession _session(TerminalSessionStatus status) => TerminalSession(
sendBinary: (_) async => true,
)..status = status;
+/// Who took a terminal, and who holds one this phone only watches — as the session reads them off
+/// the daemon's frames.
void main() {
- test('a session nobody else is driving offers nothing to reclaim', () {
- expect(phoneReclaimAction(null), isNull);
- for (final status in [
- TerminalSessionStatus.opening,
- TerminalSessionStatus.resyncing,
- TerminalSessionStatus.controlling,
- ]) {
- expect(
- phoneReclaimAction(_session(status)),
- isNull,
- reason: '$status has nothing to take back',
- );
- }
- });
-
- test('a taken-over session offers control back', () {
- final action = phoneReclaimAction(
- _session(TerminalSessionStatus.takenOver),
- );
-
- expect(action?.label, 'Take control');
- expect(action?.tone, PhoneTone.attention);
- });
-
- test('a dropped session offers a reconnect', () {
- for (final status in [
- TerminalSessionStatus.error,
- TerminalSessionStatus.closed,
- ]) {
- final action = phoneReclaimAction(_session(status));
-
- expect(action?.label, 'Reconnect', reason: '$status');
- expect(action?.tone, PhoneTone.bad, reason: '$status');
- }
- });
-
group('who took control', () {
TerminalSession taken({Map<String, dynamic>? takenBy}) {
final session = _session(TerminalSessionStatus.controlling)
@@ -61,7 +26,7 @@ void main() {
return session;
}
- test('the summary and the strip name the taker when the daemon said', () {
+ test('the taker is named when the daemon said', () {
final session = taken(
takenBy: {
'kind': 'desktop',
@@ -70,39 +35,27 @@ void main() {
},
);
expect(session.status, TerminalSessionStatus.takenOver);
- final name = phoneTakerName(session, (_) => null);
- expect(name, 'Mac mini');
- expect(
- phoneSessionSummary(session, takerName: name).label,
- 'Taken over by Mac mini',
- );
- expect(
- phoneTakeoverNotice(session, name),
- 'Mac mini took control of this terminal',
- );
+ expect(session.takenOverBy?.label((_) => null), 'Mac mini');
+ expect(session.errorMessage, 'Mac mini connected to this terminal.');
// The fleet's current name for that machine wins over the declared one.
expect(
- phoneTakerName(
- session,
+ session.takenOverBy?.label(
(id) => id == 'ab12ab12ab12ab12' ? 'Studio' : null,
),
'Studio',
);
});
- test('an older daemon, or a nameless taker, reads as another app', () {
+ test('an older daemon, or a nameless taker, reads as another client', () {
final session = taken();
- expect(phoneTakerName(session, (_) => null), isNull);
- expect(phoneSessionSummary(session).label, 'Taken over');
+ expect(session.status, TerminalSessionStatus.takenOver);
+ expect(session.takenOverBy, isNull);
expect(
- phoneTakeoverNotice(session, null),
- 'Another app took control of this terminal',
+ session.errorMessage,
+ 'Another client connected to this terminal.',
);
expect(
- phoneTakerName(
- taken(takenBy: {'kind': 'not a kind', 'name': 'x'}),
- (_) => null,
- ),
+ taken(takenBy: {'kind': 'not a kind', 'name': 'x'}).takenOverBy,
isNull,
);
});
@@ -136,7 +89,7 @@ void main() {
return session;
}
- test('the banner names the machine, as the desktop does', () async {
+ test('the holder is named, as the desktop names it', () async {
final session = await watching(
heldBy: {
'kind': 'desktop',
@@ -145,40 +98,21 @@ void main() {
},
);
expect(session.watching, isTrue);
- expect(phoneHolderName(session, (_) => null), 'MacBookPro2021.local');
+ expect(session.heldBy?.label((_) => null), 'MacBookPro2021.local');
// The fleet's current name for that machine wins, as it does for a taker.
expect(
- phoneHolderName(
- session,
+ session.heldBy?.label(
(id) => id == 'ab12ab12ab12ab12' ? 'Studio' : null,
),
'Studio',
);
});
- test('an older daemon names nobody — "another app", then', () async {
+ test('an older daemon names nobody', () async {
final session = await watching();
expect(session.watching, isTrue);
- expect(phoneHolderName(session, (_) => 'Mac'), isNull);
- });
-
- test('a session this phone drives has no holder to name', () {
- final session = _session(TerminalSessionStatus.controlling)
- ..heldBy = const TerminalClientDescriptor(kind: 'desktop', name: 'x');
- expect(phoneHolderName(session, (_) => null), isNull);
+ expect(session.heldBy, isNull);
});
});
-
- test('nothing to say while this phone drives, or nobody does', () {
- expect(phoneTakeoverNotice(null, null), isNull);
- for (final status in [
- TerminalSessionStatus.controlling,
- TerminalSessionStatus.closed,
- TerminalSessionStatus.error,
- ]) {
- expect(phoneTakeoverNotice(_session(status), 'Mac'), isNull);
- expect(phoneTakerName(_session(status), (_) => 'Mac'), isNull);
- }
- });
});
}