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.

Give the phone the way back into a terminal it is not driving

Dev jacobb1ee03c53d4d
diff --git a/mobile/lib/phone/phone_status.dart b/mobile/lib/phone/phone_status.dart
index 35506b109..de61dc01b 100644
--- a/mobile/lib/phone/phone_status.dart
+++ b/mobile/lib/phone/phone_status.dart
@@ -97,3 +97,26 @@ PhoneSummary phoneSessionSummary(
TerminalSessionStatus.error => (label: 'Disconnected', tone: PhoneTone.bad),
TerminalSessionStatus.closed => (label: 'Closed', tone: PhoneTone.quiet),
};
+
+/// 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.
+PhoneSummary? phoneReclaimAction(TerminalSession? session) =>
+ switch (session?.status) {
+ TerminalSessionStatus.takenOver => (
+ label: 'Take control',
+ tone: PhoneTone.attention,
+ ),
+ 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 19e078634..b2c534b0c 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -95,6 +95,7 @@ class _TerminalPageState extends State<TerminalPage> {
.where((a) => a.id == widget.agentId)
.firstOrNull;
final status = phoneSessionSummary(session);
+ final reclaim = phoneReclaimAction(session);
return Scaffold(
backgroundColor: AppPalette.windowBg,
body: SafeArea(
@@ -122,12 +123,29 @@ class _TerminalPageState extends State<TerminalPage> {
subtitle: StatusPill(
fontSize: 12,
summary: (
- label:
- '${machine?.machine.displayName ?? ''} · ${status.label}',
+ // The machine alone once the button beside it is saying
+ // the state: two words for one fact, in a row this
+ // narrow, is what truncated "Taken over" to "Ta…".
+ label: reclaim == null
+ ? '${machine?.machine.displayName ?? ''} · ${status.label}'
+ : machine?.machine.displayName ?? '',
tone: status.tone,
),
),
trailing: [
+ // Read-only is a state to get OUT of, so its way out is a
+ // labelled button in the header rather than a line in the
+ // actions sheet: the sheet is where you go having decided
+ // to do something, and this is the thing telling you that
+ // typing will go nowhere until you do.
+ if (reclaim != null)
+ _ReclaimButton(
+ action: reclaim,
+ onPressed: () => widget.notifier.selectAgent(
+ widget.machineId,
+ widget.agentId,
+ ),
+ ),
// Null while the agent is not loaded: there is nothing to act on yet, and a
// menu of actions that all fail is worse than no menu.
if (agent != null)
@@ -231,6 +249,42 @@ class _TerminalPageState extends State<TerminalPage> {
}
}
+/// The header's way back into a session this device is not driving.
+///
+/// Re-selecting the agent is what reclaims it — the same call the desktop tile's
+/// status chip makes, so one gesture means one thing on both.
+class _ReclaimButton extends StatelessWidget {
+ const _ReclaimButton({required this.action, required this.onPressed});
+
+ final PhoneSummary action;
+ final VoidCallback onPressed;
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final color = phoneToneColor(action.tone);
+ return TextButton.icon(
+ onPressed: onPressed,
+ icon: Icon(
+ action.tone == PhoneTone.attention
+ ? LucideIcons.lock300
+ : LucideIcons.refreshCw300,
+ size: 15,
+ ),
+ label: Text(
+ action.label,
+ style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
+ ),
+ style: TextButton.styleFrom(
+ foregroundColor: color,
+ minimumSize: Size.zero,
+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
+ ),
+ );
+ }
+}
+
class _Attaching extends StatelessWidget {
const _Attaching();
diff --git a/mobile/test/phone_reclaim_test.dart b/mobile/test/phone_reclaim_test.dart
new file mode 100644
index 000000000..5230b985c
--- /dev/null
+++ b/mobile/test/phone_reclaim_test.dart
@@ -0,0 +1,50 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/terminal/terminal_session.dart';
+import 'package:harness_mobile/phone/phone_status.dart';
+
+TerminalSession _session(TerminalSessionStatus status) => TerminalSession(
+ machineId: 'm',
+ agentId: 'a',
+ agentName: 'Agent',
+ engineId: 'codex',
+ send: (_, _) async => true,
+ sendBinary: (_) async => true,
+)..status = status;
+
+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');
+ }
+ });
+}