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): implement agent creation flow and navigation updates
Dev jacob9a6312710766
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dartindex f3e0b9479..137662aa6 100644--- a/mobile/lib/phone/new_agent_page.dart+++ b/mobile/lib/phone/new_agent_page.dart@@ -11,6 +11,7 @@ import 'package:harness_mobile/widgets/engine_identity.dart';import 'package:harness_mobile/widgets/remote_folder_picker.dart';import 'phone_header.dart';+import 'phone_navigation.dart';import 'settings_row.dart';/// Starting an agent from the phone: a folder on that machine, and an engine to@@ -146,6 +147,10 @@ class _NewAgentPageState extends State<NewAgentPage> {_creating = true;_error = null;});+ // Held so the id of what it starts comes back here — see+ // [AgentCreationAttempt.agentId]. A fresh one per submit, which is what the+ // call made on its own before: a retry after a refusal is a new request.+ final creation = AgentCreationAttempt();final error = await widget.notifier.createAgent(widget.machineId,engine: engine,@@ -153,12 +158,11 @@ class _NewAgentPageState extends State<NewAgentPage> {// Only for Codex, and only when chosen: omitted, the machine launches// with its own default CODEX_HOME.codexHome: _showsCodexProfile ? _codexProfile?.path : null,+ attempt: creation,);if (!mounted) return;if (error == null) {- // The new agent reaches the list behind this page on its own, the way- // every other agent does — there is nothing here to hand it.- Navigator.of(context).pop();+ _open(creation.agentId);return;}setState(() {@@ -167,6 +171,30 @@ class _NewAgentPageState extends State<NewAgentPage> {});}+ /// Where a finished creation lands: inside the agent it just started.+ ///+ /// Asking for an agent and being handed back the list to find it in is a step+ /// nobody wants — the answer to "create this" is the thing created. It+ /// REPLACES this page rather than stacking on it, so back from the terminal+ /// is the list this was opened from, not a form for an agent that now exists.+ ///+ /// A machine can still confirm a creation without naming the agent — an older+ /// CLI's reply carries no record. Then there is nothing to open, and the list+ /// behind this page picks the new agent up the way it picks up every other.+ void _open(String? agentId) {+ if (agentId == null) {+ Navigator.of(context).pop();+ return;+ }+ openAgent(+ context,+ widget.notifier,+ widget.machineId,+ agentId,+ replacingCurrentPage: true,+ );+ }+@overrideWidget build(BuildContext context) => ListenableBuilder(listenable: widget.notifier,diff --git a/mobile/lib/phone/phone_navigation.dart b/mobile/lib/phone/phone_navigation.dartindex 062247012..df4eb492a 100644--- a/mobile/lib/phone/phone_navigation.dart+++ b/mobile/lib/phone/phone_navigation.dart@@ -108,26 +108,35 @@ void openMachinePager(////// [swipeNeighbours] turns the page into a pager over that list — see [AgentSwipeList] and/// [openAgentPager], which is how the Agents tab calls this.+///+/// [replacingCurrentPage] puts the agent in the place of the page it was opened FROM instead of on+/// top of it. That is what the new-agent form wants: the agent it just started opens straight away,+/// and going back from it lands on the list rather than on a form asking to create one again.void openAgent(BuildContext context,AppNotifier notifier,String machineId,String agentId, {AgentSwipeList? swipeNeighbours,+ bool replacingCurrentPage = false,}) {- Navigator.of(context).push(- phoneRoute(- (_) => AgentSwipeHost(- notifier: notifier,- machineId: machineId,- agentId: agentId,- neighbours: swipeNeighbours,- ),- // The horizontal axis belongs to the pager here — see [_NoSwipeBackRoute]. The way out is the- // header's back band, and on Android the back button as well.- swipeToGoBack: false,+ final route = phoneRoute(+ (_) => AgentSwipeHost(+ notifier: notifier,+ machineId: machineId,+ agentId: agentId,+ neighbours: swipeNeighbours,),+ // The horizontal axis belongs to the pager here — see [_NoSwipeBackRoute]. The way out is the+ // header's back band, and on Android the back button as well.+ swipeToGoBack: false,);+ final navigator = Navigator.of(context);+ if (replacingCurrentPage) {+ navigator.pushReplacement(route);+ } else {+ navigator.push(route);+ }unawaited(_openPane(notifier, machineId, agentId, keepOthers: swipeNeighbours != null));}diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 25ee1af56..f8548cf3e 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -87,9 +87,18 @@ class AgentCreationAttempt {Future<String?>? _inFlight;bool _awaitingConfirmation = false, _finished = false;String? _outcome;+ String? _agentId;bool get awaitingConfirmation => _awaitingConfirmation;+ /// The agent this attempt started, once the machine has confirmed it.+ ///+ /// The form that asked for an agent is the one screen that knows it was just+ /// asked for, so it is the one that can open it. Without this the id is known+ /// only inside the notifier, and the new agent has to be found again in the+ /// list — a step nobody wants after naming a folder and an engine.+ String? get agentId => _agentId;+String? _complete(String? error) {_finished = true;_awaitingConfirmation = false;@@ -4051,6 +4060,7 @@ class AppNotifier extends ChangeNotifier {} catch (_) {return unconfirmed;}+ creation._agentId = agent.id;creation._complete(null);if (_disposed || machineStates[machineId] != machine) return null;_upsertAgent(machine, agent);diff --git a/mobile/test/phone_new_agent_opens_test.dart b/mobile/test/phone_new_agent_opens_test.dartnew file mode 100644index 000000000..d6c4d81ca--- /dev/null+++ b/mobile/test/phone_new_agent_opens_test.dart@@ -0,0 +1,112 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/phone/agent_swipe.dart';+import 'package:harness_mobile/phone/new_agent_page.dart';+import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/ws/ws_conn.dart';++/// A machine that starts the agent it is asked for, and answers everything else with nothing.+///+/// The reply shape is the one the notifier's receipt path requires: the creation id it was handed+/// back, `created`, and the agent itself — anything less reads as unconfirmed.+class _Conn extends WsConn {+ _Conn()+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'm',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );++ @override+ Future<Map<String, dynamic>> request(+ String type, {+ Map<String, dynamic> payload = const {},+ Duration timeout = const Duration(seconds: 20),+ }) async {+ if (type != 'agent_create') return {};+ return {+ 'creationId': payload['creationId'],+ 'state': 'created',+ 'agent': {+ 'id': 'new-agent',+ 'name': 'new-agent',+ 'engine': 'claude',+ 'terminal': {'available': true},+ },+ };+ }+}++/// A machine answering, with one agent already in a folder — which is what puts a tappable folder+/// on the form. Browsing for one instead would open the remote picker, a screen of its own.+AppNotifier _app(_Conn conn) {+ final app = AppNotifier(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ connectionForTest: (_) => conn,+ );+ const machine = Machine(+ machineId: 'm',+ authMode: MachineAuthMode.remote,+ name: 'Test host',+ );+ app.machines = [machine];+ app.machineStates['m'] = MachineState(machine)+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected+ ..agentLoadStatus = AgentLoadStatus.loaded+ ..agents = [+ const Agent(+ id: 'old',+ name: 'old',+ engine: 'claude',+ project: AgentProject(name: 'grid', cwd: '/src/grid'),+ terminalAvailable: true,+ ),+ ];+ return app;+}++void main() {+ testWidgets('creating an agent opens it, and leaves no form to come back to', (+ tester,+ ) async {+ final app = _app(_Conn());+ addTearDown(app.dispose);+ await tester.pumpWidget(+ MaterialApp(home: NewAgentPage(notifier: app, machineId: 'm')),+ );+ await tester.pump();++ await tester.tap(find.text('grid'));+ await tester.pump();+ await tester.tap(find.text('Claude'));+ await tester.pump();+ await tester.tap(find.text('Create agent'));+ // The create resolves on a microtask, then the route it pushes has to slide in — and only once+ // that transition ends does the form's own route come off the stack.+ await tester.pump();+ for (var i = 0; i < 4; i++) {+ await tester.pump(const Duration(milliseconds: 400));+ }++ expect(+ find.byType(AgentSwipeHost),+ findsOneWidget,+ reason: 'the agent just asked for is what the form opens',+ );+ expect(+ find.byType(NewAgentPage),+ findsNothing,+ reason: 'the form is replaced, so back from the agent is the list behind it',+ );+ });+}