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): swipe between machines like agents
tony118a57bda49e
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dartindex 317cccdd6..36496f5a3 100644--- a/mobile/lib/phone/agents_page.dart+++ b/mobile/lib/phone/agents_page.dart@@ -25,11 +25,20 @@ class AgentsPage extends StatelessWidget {super.key,required this.notifier,required this.machineId,+ this.embedded = false,});final AppNotifier notifier;final String machineId;+ /// Whether this is a PAGE INSIDE the machine pager rather than a route of its own.+ ///+ /// The route then belongs to [MachineSwipeHost], and the two places this page would navigate have+ /// to stop: the padlock empty state's push of a [LinkPage] over the pager, and the pop after+ /// unlinking, which would drop the person back to the tab from a page they were swiping through.+ /// Both become a rebuild instead — [MachinePage] watches `needsLink` and draws the form itself.+ final bool embedded;+@overrideWidget build(BuildContext context) => ListenableBuilder(listenable: notifier,@@ -74,7 +83,11 @@ class AgentsPage extends StatelessWidget {),if (machine != null)Expanded(- child: _AgentsBody(notifier: notifier, machine: machine),+ child: _AgentsBody(+ notifier: notifier,+ machine: machine,+ embedded: embedded,+ ),),],),@@ -147,6 +160,10 @@ class AgentsPage extends StatelessWidget {?.showSnackBar(SnackBar(content: Text(error)));return;}+ // Inside the pager the page has already become the password form — `needsLink` is now true and+ // [MachinePage] rebuilds on it — so there is nothing to leave, and popping would take the whole+ // pager with it.+ if (embedded) return;// The page is now showing a machine this phone can no longer open; the list behind it is where// the re-link starts.Navigator.of(context).maybePop();@@ -154,11 +171,18 @@ class AgentsPage extends StatelessWidget {}class _AgentsBody extends StatelessWidget {- const _AgentsBody({required this.notifier, required this.machine});+ const _AgentsBody({+ required this.notifier,+ required this.machine,+ required this.embedded,+ });final AppNotifier notifier;final MachineState machine;+ /// See [AgentsPage.embedded] — here it decides what the padlock empty state's button does.+ final bool embedded;+String get _machineId => machine.machine.machineId;@override@@ -171,11 +195,17 @@ class _AgentsBody extends StatelessWidget {title: 'This machine needs its password',message: 'Every machine has its own. Enter it once to link this phone.',action: FilledButton(- onPressed: () => Navigator.of(context).pushReplacement(- phoneRoute(- (_) => LinkPage(notifier: notifier, machineId: _machineId),- ),- ),+ // Embedded, the form is this same page a rebuild away: clearing the dismissal is the whole+ // move, and [MachinePage] draws [LinkPage] on the next frame. Pushing a route instead+ // would stack a second screen over the pager — and that screen's own `pushReplacement`+ // would then replace the pager once the password landed.+ onPressed: embedded+ ? () => notifier.revisitLinkPrompt(_machineId)+ : () => Navigator.of(context).pushReplacement(+ phoneRoute(+ (_) => LinkPage(notifier: notifier, machineId: _machineId),+ ),+ ),child: const Text('Enter password'),),);diff --git a/mobile/lib/phone/link_page.dart b/mobile/lib/phone/link_page.dartindex e8cb70edb..d3ff7e06c 100644--- a/mobile/lib/phone/link_page.dart+++ b/mobile/lib/phone/link_page.dart@@ -11,13 +11,29 @@ import 'phone_navigation.dart';/// up, since the exchange behind it is the same.////// It leaves by itself both ways: forward onto the machine's agents once the link lands, and-/// back when the form's own Close is pressed.+/// back when the form's own Close is pressed — unless it is [embedded], where moving on is somebody+/// else's job.class LinkPage extends StatefulWidget {- const LinkPage({super.key, required this.notifier, required this.machineId});+ const LinkPage({+ super.key,+ required this.notifier,+ required this.machineId,+ this.embedded = false,+ });final AppNotifier notifier;final String machineId;+ /// Whether this form is a PAGE INSIDE something else — [MachinePage] in the machine pager — rather+ /// than a route of its own.+ ///+ /// ⚠️ **It turns off every navigation this page does, and it has to.** The route belongs to the+ /// pager, not to this page: a `pushReplacement` here would swap out the PAGER and take the swipe+ /// with it, and a `maybePop` would drop the person back to the tab from a page they were only+ /// swiping past. Embedded, the page just draws the form; the builder above it watches the same+ /// `needsLink` and puts the agents there the moment the link lands.+ final bool embedded;+@overrideState<LinkPage> createState() => _LinkPageState();}@@ -26,8 +42,9 @@ class _LinkPageState extends State<LinkPage> {/// The form's Close marks the prompt dismissed. One already dismissed before this page opened/// must not shut the page on its first frame.///- /// Always false in practice now that [initState] clears the mark — kept as the guard it is, so- /// the rule below still reads on its own if that ever stops being true.+ /// Always false in practice on a pushed page, now that [initState] clears the mark — kept as the+ /// guard it is, so the rule below still reads on its own if that ever stops being true. An+ /// embedded page never reaches it: [_follow] is not even subscribed there.late final bool _dismissedBefore = widget.notifier.isLinkPromptDismissed(widget.machineId,);@@ -41,8 +58,15 @@ class _LinkPageState extends State<LinkPage> {// form was Closed once could never be reached again: [_follow] reads the mark on its first// run and pops the page on the frame it opened. The desktop fixes the same bug the same way// (`revisitLinkPrompt`, 051ea5b), where the reactive gates check the mark before calling.- widget.notifier.revisitLinkPrompt(widget.machineId);- widget.notifier.addListener(_follow);+ //+ // ⚠️ Embedded, mounting is NOT somebody asking. A pager builds the pages either side of the one+ // on screen, so this would clear the dismissal of a machine nobody has opened — reopening a form+ // that was Closed, one page over, out of sight. There the mark is [MachinePage]'s to read and the+ // "Enter password" button's to clear, and both act on the machine actually being looked at.+ if (!widget.embedded) {+ widget.notifier.revisitLinkPrompt(widget.machineId);+ widget.notifier.addListener(_follow);+ }}@override@@ -52,7 +76,9 @@ class _LinkPageState extends State<LinkPage> {}void _follow() {- if (_leaving || !mounted) return;+ // Embedded, there is nowhere for this page to go: [MachinePage] rebuilds off the same notifier+ // and swaps the form for the agents itself. Listening at all would only risk the pops below.+ if (widget.embedded || _leaving || !mounted) return;final machine = widget.notifier.stateOf(widget.machineId);final navigator = Navigator.of(context);if (machine != null && !machine.needsLink) {diff --git a/mobile/lib/phone/machine_index.dart b/mobile/lib/phone/machine_index.dartnew file mode 100644index 000000000..c3fb5f49e--- /dev/null+++ b/mobile/lib/phone/machine_index.dart@@ -0,0 +1,58 @@+import 'package:harness_mobile/state/app_state.dart';+import 'phone_status.dart';++/// Every machine the Machines tab draws, in the order a finger meets them.+///+/// The tab draws two sections — the ones that work, then the ones wanting something — and that+/// concatenation, not account order, is what somebody actually sees. The machine page swipes along+/// it, so it has to be built in ONE place: a pager computing "the next machine" from a slightly+/// different order than the list it was opened from would skip a machine, or hand back the one just+/// left, and nothing on screen would explain why. The same rule the Agents tab follows with+/// `visibleAgents`.+///+/// Unlike the agent list this one keeps EVERY machine, including the ones that need a password or+/// are offline. A machine row that cannot be opened is still worth a page: the password form is+/// exactly what somebody swiping past it came for, and an offline machine says so in words rather+/// than by being missing.+List<MachineState> visibleMachines(AppNotifier notifier) {+ final states = [+ for (final machine in notifier.machines) ?notifier.stateOf(machine.machineId),+ ];+ // Two runs, by whether the machine is usable as it stands — the split [MachinesTab] renders as+ // its two sections. A machine merely connecting belongs with the working ones: it needs nothing+ // from anybody, it is just not ready yet.+ final working = <MachineState>[];+ final needsAttention = <MachineState>[];+ for (final state in states) {+ switch (phoneMachineStatusOf(state)) {+ case PhoneMachineStatus.needsPassword:+ case PhoneMachineStatus.offline:+ needsAttention.add(state);+ case PhoneMachineStatus.connecting:+ case PhoneMachineStatus.ready:+ working.add(state);+ }+ }+ return [...working, ...needsAttention];+}++/// The machines that work as they stand, in [visibleMachines] order.+///+/// Derived from that one list rather than re-partitioned here, so the sections the tab draws and+/// the order the pager walks cannot drift apart.+List<MachineState> workingMachines(List<MachineState> machines) => [+ for (final machine in machines)+ if (_works(machine)) machine,+];++/// The machines wanting something first — a password, or a Harness that is not running.+List<MachineState> machinesNeedingAttention(List<MachineState> machines) => [+ for (final machine in machines)+ if (!_works(machine)) machine,+];++bool _works(MachineState machine) =>+ switch (phoneMachineStatusOf(machine)) {+ PhoneMachineStatus.connecting || PhoneMachineStatus.ready => true,+ PhoneMachineStatus.needsPassword || PhoneMachineStatus.offline => false,+ };diff --git a/mobile/lib/phone/machine_swipe.dart b/mobile/lib/phone/machine_swipe.dartnew file mode 100644index 000000000..633fa1f2a--- /dev/null+++ b/mobile/lib/phone/machine_swipe.dart@@ -0,0 +1,191 @@+import 'package:flutter/material.dart';++import 'package:harness_mobile/state/app_state.dart';+import 'agents_page.dart';+import 'link_page.dart';++/// The machines a machine page can swipe between, in the order the list drew them.+///+/// A SNAPSHOT, taken when the page opens, for the same reason [AgentSwipeList] is one: the Machines+/// tab sorts on state that moves by itself — a machine that finishes connecting sorts upward, one+/// that drops offline sorts down — so a pager recomputing this list would renumber its own pages+/// under the finger.+///+/// ⚠️ **Machine IDS, not [MachineState]s.** The agent pager can hold its entries because an+/// `AgentEntry` is read once and drawn; a machine page is LIVE — it watches `needsLink` to decide+/// whether it shows the password form or the agents, and the notifier replaces these state objects+/// as machines answer. A held instance would go stale and the page would keep drawing the machine as+/// it was when the list was tapped.+///+/// Every machine is kept, including the ones that need a password or are offline. That is the whole+/// difference from the agent pager, which drops the rows it cannot open: a machine row that cannot+/// be opened still has something to show — the password form is exactly what somebody swiping to it+/// came for, and an offline machine says so in words.+class MachineSwipeList {+ MachineSwipeList(List<MachineState> machines)+ : machineIds = [+ for (final machine in machines) machine.machine.machineId,+ ];++ final List<String> machineIds;++ bool get isEmpty => machineIds.isEmpty;++ /// Whether the pager wraps around — past the last machine is the first one again.+ ///+ /// Needs at least TWO machines, and that is not a formality. With one, every page of an endless+ /// pager is the same machine: the screen would take a swipe, move, and land on what it just left,+ /// which reads as the gesture having failed rather than as a list with one thing in it.+ bool get wraps => machineIds.length > 1;++ /// Where a machine sits in the snapshot, or null if it is not in it.+ int? indexOf(String machineId) {+ final index = machineIds.indexOf(machineId);+ return index < 0 ? null : index;+ }+}++/// One machine's page, with the machines beside it a swipe away.+///+/// ⚠️ **The pager holds the route, and the pages inside it no longer do.** Without [neighbours] it+/// is a passthrough, which is how anything still opening a single machine keeps the old behaviour.+///+/// Nothing here mirrors the agent pager's `_attached`/`_detachAll`. That bookkeeping exists because+/// a terminal page ATTACHES a pane — a remote stream with a scrollback and a heartbeat — that+/// nothing else would ever close. A machine page holds no such thing: it reads machine state the+/// notifier keeps anyway, for every machine at once, whether this page is mounted or not. Three+/// mounted pages cost three list widgets.+class MachineSwipeHost extends StatefulWidget {+ const MachineSwipeHost({+ super.key,+ required this.notifier,+ required this.machineId,+ required this.neighbours,+ });++ final AppNotifier notifier;++ /// The machine the route was opened on — the page that is shown first.+ final String machineId;++ /// Null for a page opened without neighbours, which is then simply the page.+ final MachineSwipeList? neighbours;++ @override+ State<MachineSwipeHost> createState() => _MachineSwipeHostState();+}++class _MachineSwipeHostState extends State<MachineSwipeHost> {+ /// How many laps of the list the opening page sits above zero — see [initState].+ static const _origin = 1000;++ PageController? _controller;++ @override+ void initState() {+ super.initState();+ final neighbours = widget.neighbours;+ if (neighbours == null || neighbours.isEmpty) return;+ final start = neighbours.indexOf(widget.machineId) ?? 0;+ // Opening in the MIDDLE of the endless run, not at its start, is what lets the first swipe go+ // either way: page 0 has nothing to its left, and the last machine has to be reachable by+ // swiping back from the first one. `_origin` is far enough from both ends that neither is+ // reachable by hand — ~1,000 laps of the list — and it is a whole number of laps, so+ // `page % length` still names the machine.+ final page = neighbours.wraps+ ? _origin * neighbours.machineIds.length + start+ : start;+ _controller = PageController(initialPage: page);+ }++ @override+ void dispose() {+ _controller?.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final neighbours = widget.neighbours;+ final controller = _controller;+ if (neighbours == null || controller == null || neighbours.isEmpty) {+ return MachinePage(notifier: widget.notifier, machineId: widget.machineId);+ }+ return PageView.builder(+ controller: controller,+ // The lists below scroll vertically, so the horizontal axis is free. The one gesture still+ // competing for it is the route's own edge-swipe back, which wins at the left margin because+ // it is registered above this in the tree — deliberately kept: that is how a page goes back on+ // iOS, and the page slides out the way it came in.+ physics: const PageScrollPhysics(),+ // No count is what makes it endless: the builder answers for any page, and the modulo below+ // wraps it back onto the list. A one-machine list keeps its single page instead — see+ // [MachineSwipeList.wraps].+ itemCount: neighbours.wraps ? null : neighbours.machineIds.length,+ itemBuilder: (context, i) => MachinePage(+ // ⚠️ Keyed by PAGE, not by machine: an endless run holds several pages for the same machine+ // — the lap before and the lap after — and a machine-shaped key would make Flutter treat two+ // live pages as one widget, which throws on a duplicate key the moment both are mounted.+ key: ValueKey(i),+ notifier: widget.notifier,+ machineId:+ neighbours.machineIds[i % neighbours.machineIds.length],+ ),+ );+ }+}++/// One machine, drawn as whatever that machine currently needs.+///+/// ⚠️ **This is a SWITCH, not a route, and that is the point.** Both screens used to be pushed:+/// `openMachine` chose one, and [LinkPage] then `pushReplacement`ed its way to [AgentsPage] once the+/// password landed. Inside a pager that replacement would swap out the PAGER — the route is the+/// host's, not the page's — and the swipe would silently die the first time somebody linked a+/// machine from it. Deciding here, off the notifier, keeps the pager whole: the page simply becomes+/// the agents list under the finger, on the same page number, with its neighbours still beside it.+class MachinePage extends StatelessWidget {+ const MachinePage({+ super.key,+ required this.notifier,+ required this.machineId,+ });++ final AppNotifier notifier;+ final String machineId;++ @override+ Widget build(BuildContext context) => ListenableBuilder(+ listenable: notifier,+ builder: (context, _) {+ final machine = notifier.stateOf(machineId);+ // A machine dropped from the account while its page sits in a pager. The page stays — popping+ // one page out of a pager is not a thing a PageView can do — and [AgentsPage] already draws+ // an empty machine shell for a null state, which is the honest answer.+ //+ // ⚠️ The dismissal is half of this test, not a detail. The form's own Close only calls+ // `dismissLinkPrompt`; on a pushed [LinkPage] that lands as a pop, but a page cannot pop out of+ // a pager, so without reading the mark here Close would do nothing visible and read as broken.+ // Dismissed, the page falls through to [AgentsPage]'s padlock empty state — which is the same+ // machine, still unlinked, with its "Enter password" calling `revisitLinkPrompt` to come back+ // here. Close and that button are then the two directions of one switch.+ if (machine != null &&+ machine.needsLink &&+ !notifier.isLinkPromptDismissed(machineId)) {+ return LinkPage(+ notifier: notifier,+ machineId: machineId,+ // The form no longer navigates: this builder is what moves the page on, the moment+ // `needsLink` goes false — or the moment Close marks it dismissed.+ embedded: true,+ );+ }+ return AgentsPage(+ notifier: notifier,+ machineId: machineId,+ // Unlinking must not pop the pager, and the empty state's "Enter password" must not push a+ // second link route over it — this builder handles both by rebuilding.+ embedded: true,+ );+ },+ );+}diff --git a/mobile/lib/phone/machines_tab.dart b/mobile/lib/phone/machines_tab.dartindex c49d988d4..497a99179 100644--- a/mobile/lib/phone/machines_tab.dart+++ b/mobile/lib/phone/machines_tab.dart@@ -4,11 +4,11 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';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 'machine_index.dart';import 'machine_tile.dart';import 'phone_card.dart';import 'phone_header.dart';import 'phone_navigation.dart';-import 'phone_status.dart';/// The machines on the account, grouped by what they need.///@@ -51,14 +51,14 @@ class _Body extends StatelessWidget {@overrideWidget build(BuildContext context) {- final states = [- for (final machine in notifier.machines)- ?notifier.stateOf(machine.machineId),- ];- if (states.isEmpty && notifier.machinesLoading) {+ // The order a swipe on the machine page walks, split back into the two sections this list draws.+ // Taken from [visibleMachines] rather than partitioned here so the page and the list cannot+ // drift apart — the split below is presentation, the order is not.+ final ordered = visibleMachines(notifier);+ if (ordered.isEmpty && notifier.machinesLoading) {return const PhoneListSkeleton();}- if (states.isEmpty) {+ if (ordered.isEmpty) {return const EmptyState(icon: LucideIcons.laptopMinimal300,title: 'No machines yet',@@ -68,21 +68,8 @@ class _Body extends StatelessWidget {);}- // Two runs, by whether the machine is usable as it stands. A machine that is merely connecting- // belongs with the working ones: it needs nothing from anybody, it is just not ready yet.- // The runs are built in this order and rendered working-first; see the class comment.- final needsAttention = <MachineState>[];- final working = <MachineState>[];- for (final state in states) {- switch (phoneMachineStatusOf(state)) {- case PhoneMachineStatus.needsPassword:- case PhoneMachineStatus.offline:- needsAttention.add(state);- case PhoneMachineStatus.connecting:- case PhoneMachineStatus.ready:- working.add(state);- }- }+ final working = workingMachines(ordered);+ final needsAttention = machinesNeedingAttention(ordered);return RefreshIndicator(onRefresh: notifier.retryMachines,@@ -92,24 +79,35 @@ class _Body extends StatelessWidget {children: [if (working.isNotEmpty) ...[const _SectionLabel('Linked'),- for (final state in working) _tile(context, state),+ for (final state in working) _tile(context, ordered, state),const SizedBox(height: 6),],if (needsAttention.isNotEmpty) ...[if (working.isNotEmpty)const _SectionLabel('Needs your attention'),- for (final state in needsAttention) _tile(context, state),+ for (final state in needsAttention) _tile(context, ordered, state),],],),);}- Widget _tile(BuildContext context, MachineState state) => Padding(+ Widget _tile(+ BuildContext context,+ List<MachineState> ordered,+ MachineState state,+ ) => Padding(padding: const EdgeInsets.only(bottom: kPhoneCardGap),child: MachineTile(machine: state,- onTap: () => openMachine(context, notifier, state.machine.machineId),+ // The whole visible list goes with the tap, so the page opens as a pager over exactly the+ // machines on screen. Swiping there walks this order.+ onTap: () => openMachinePager(+ context,+ notifier,+ ordered,+ state.machine.machineId,+ ),),);}diff --git a/mobile/lib/phone/phone_navigation.dart b/mobile/lib/phone/phone_navigation.dartindex 66acab612..740b756ec 100644--- a/mobile/lib/phone/phone_navigation.dart+++ b/mobile/lib/phone/phone_navigation.dart@@ -7,6 +7,7 @@ import 'agent_index.dart';import 'agent_swipe.dart';import 'agents_page.dart';import 'link_page.dart';+import 'machine_swipe.dart';/// Every phone page slides in the iOS way, and goes back with the edge swipe.Route<void> phoneRoute(WidgetBuilder builder) =>@@ -14,9 +15,33 @@ Route<void> phoneRoute(WidgetBuilder builder) =>/// Where a tap on a machine goes. A machine this device holds no link to opens on ITS password/// form — each machine has its own remote password — and only a linked one opens on its agents.-void openMachine(BuildContext context, AppNotifier notifier, String machineId) {+///+/// [swipeNeighbours] turns the page into a pager over that list — see [MachineSwipeList] and+/// [openMachinePager], which is how the Machines tab calls this.+void openMachine(+ BuildContext context,+ AppNotifier notifier,+ String machineId, {+ MachineSwipeList? swipeNeighbours,+}) {final machine = notifier.stateOf(machineId);if (machine == null) return;+ // A pager decides page by page which of the two screens a machine needs, because that answer+ // changes under the finger — linking one mid-swipe turns its page into the agents list. Opened on+ // its own, the old pair of routes is kept: [LinkPage] then walks forward to [AgentsPage] itself,+ // which is the push the back gesture expects to find behind it.+ if (swipeNeighbours != null) {+ Navigator.of(context).push(+ phoneRoute(+ (_) => MachineSwipeHost(+ notifier: notifier,+ machineId: machineId,+ neighbours: swipeNeighbours,+ ),+ ),+ );+ return;+ }Navigator.of(context).push(phoneRoute((_) => machine.needsLink@@ -26,6 +51,25 @@ void openMachine(BuildContext context, AppNotifier notifier, String machineId) {);}+/// Opens one machine as a PAGER over [machines]: the page it lands on is the machine tapped, and a+/// horizontal swipe moves to the one beside it.+///+/// Takes the machines as a SNAPSHOT rather than a way to recompute them, for the reason+/// [openAgentPager] does: the list is sorted partly on state that moves by itself — a machine that+/// finishes connecting sorts upward — so a page recomputing "the next one" mid-session would+/// renumber itself under the finger.+void openMachinePager(+ BuildContext context,+ AppNotifier notifier,+ List<MachineState> machines,+ String machineId,+) => openMachine(+ context,+ notifier,+ machineId,+ swipeNeighbours: MachineSwipeList(machines),+);+/// Opens one agent full screen.////// ONE at a time, and that is the whole difference from the desktop grid: a phone has no room