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
fix(mobile): put a harness made from Find into the tab picked on the chips, not the tab of the harness on screen
tonyb75fd9641ef9
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dartindex 5b63da586..3b12ff8f6 100644--- a/mobile/lib/phone/agents_page.dart+++ b/mobile/lib/phone/agents_page.dart@@ -271,11 +271,15 @@ Future<void> showAgentActions(/// Returns when the form closes — by creating an agent or by being backed out/// of — so a caller whose own chrome depends on being the top route can rebuild/// (see `terminal_page.dart`). Callers that do not care can ignore it.+///+/// [deskTabId] is the tab the new agent joins, for a door that picked one — see+/// [NewAgentPage.deskTabId].Future<void> openNewAgent(BuildContext context,AppNotifier notifier,String machineId, {String? folder,+ String? deskTabId,VoiceInputController? voice,}) => Navigator.of(context).push(phoneRoute(@@ -283,6 +287,7 @@ Future<void> openNewAgent(notifier: notifier,machineId: machineId,folder: folder,+ deskTabId: deskTabId,voice: voice,),),diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dartindex 652a940ff..3b57a1a9a 100644--- a/mobile/lib/phone/new_agent_page.dart+++ b/mobile/lib/phone/new_agent_page.dart@@ -43,6 +43,7 @@ class NewAgentPage extends StatefulWidget {required this.notifier,required this.machineId,this.folder,+ this.deskTabId,this.voice,});@@ -57,6 +58,10 @@ class NewAgentPage extends StatefulWidget {/// used there.final String? folder;+ /// The desk tab the new harness joins — the tab Find was narrowed to when New Harness was tapped.+ /// Null joins the tab the phone is in. See `PhoneDesk.adopt`.+ final String? deskTabId;+@overrideState<NewAgentPage> createState() => _NewAgentPageState();}@@ -772,6 +777,7 @@ class _NewAgentPageState extends State<NewAgentPage> {// with its own default CODEX_HOME.codexHome: _showsCodexProfile ? _codexProfile?.path : null,model: _model,+ deskTabId: widget.deskTabId,attempt: creation,prompt: task.isEmpty ? null : task,// Whenever a first task is sent, the harness is called by its words until the engine titlesdiff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dartindex 7c6a9bb33..b807762c0 100644--- a/mobile/lib/phone/phone_search_results.dart+++ b/mobile/lib/phone/phone_search_results.dart@@ -103,6 +103,12 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {}}+ /// The desk tab the list is narrowed to as drawn — the chip lit — or null on All, and off the+ /// plain list, where no chips are drawn. Where New Harness puts what it makes: a harness made+ /// with a tab picked joins THAT tab, not the tab of the harness Find was opened over+ /// (`NewAgentPage.deskTabId`).+ String? get deskTabId => _tab(_tabs(widget.controller))?.id;+/// The row whose agent is being brought back, if any — see [_open].////// One at a time: the resume is a round trip to the machine, and a list thatdiff --git a/mobile/lib/phone/terminal_search.dart b/mobile/lib/phone/terminal_search.dartindex 00b217ace..677ec449b 100644--- a/mobile/lib/phone/terminal_search.dart+++ b/mobile/lib/phone/terminal_search.dart@@ -12,6 +12,7 @@ import 'package:harness_mobile/shared/widgets/app_dialog.dart'import 'package:harness_mobile/state/app_state.dart';import '../demo/sample_mode.dart' show SampleMode;+import 'agent_index.dart' show filterableMachines;import 'agents_page.dart' show openNewAgent;import 'find_models.dart';import 'tty.dart';@@ -20,6 +21,7 @@ import 'voice_input_controller.dart';import 'phone_search_actions.dart';import 'phone_search_controller.dart';import 'phone_search_results.dart';+import 'phone_status.dart';/// Find: the one way to another agent. A full-screen page in from the left edge over Focus —/// Snapchat's way to its chats — pulled by a swipe right on the terminal, or a tap on the agent's@@ -264,19 +266,34 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>/// `+ New Harness` and the button at the foot — in the project the query matched when there is/// one (the row only); else on the machine of the harness on screen; else the command's first/// ready machine.+ ///+ /// ⚠️ **Into the tab the chips are narrowed to, not the tab Find was opened over.** A harness+ /// made here joins the tab the phone is in ([AppNotifier.activeDeskTabId]), and that is the+ /// tab of the harness on screen — `AgentHome` re-derives it on every build, so selecting the+ /// picked tab before the form opens would be undone while the form is up. The picked tab+ /// travels with the request instead (`NewAgentPage.deskTabId`); on All it is null and the tab+ /// the phone is in still decides.void Function(({String machineId, String folder, String label})? place)?_newAgent() {final showing = widget.showing;final here = showing == null? null: widget.notifier.stateOf(showing.machineId);- final command = phoneSearchCommands(- context,- widget.notifier,- ).where((command) => command.id == 'agent.new').firstOrNull;final ready = here != null && here.nodeOnline != false && !here.needsLink;- if (!ready && command == null) return null;+ // The `New Harness` command's own pick (`phoneSearchCommands`), opened here rather than+ // through the command so the picked tab goes with it.+ final first = ready+ ? null+ : filterableMachines(widget.notifier)+ .where(+ (machine) =>+ phoneMachineStatusOf(machine) == PhoneMachineStatus.ready,+ )+ .firstOrNull;+ if (!ready && first == null) return null;return (place) {+ // Read before Find goes away with the chips.+ final deskTabId = _results.currentState?.deskTabId;_close();if (place != null) {unawaited(@@ -285,6 +302,7 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>widget.notifier,place.machineId,folder: place.folder,+ deskTabId: deskTabId,voice: widget.voice,),);@@ -294,11 +312,19 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>context,widget.notifier,showing!.machineId,+ deskTabId: deskTabId,voice: widget.voice,),);} else {- command!.run();+ unawaited(+ openNewAgent(+ context,+ widget.notifier,+ first!.machine.machineId,+ deskTabId: deskTabId,+ ),+ );}};}diff --git a/mobile/lib/phone/welcome/pick_up_page.dart b/mobile/lib/phone/welcome/pick_up_page.dartindex b7ccd7d96..130ac1020 100644--- a/mobile/lib/phone/welcome/pick_up_page.dart+++ b/mobile/lib/phone/welcome/pick_up_page.dart@@ -39,6 +39,9 @@ class _PickUpPageState extends State<PickUpPage> {modes: false,);+ /// The list, for the tab its chips are narrowed to — see [_newHarness].+ final _results = GlobalKey<PhoneSearchResultsState>();+@overridevoid dispose() {_search.dispose();@@ -56,14 +59,17 @@ class _PickUpPageState extends State<PickUpPage> {: '$sessions on ${computers.length} computers';}- /// `+ New Harness`: in the project a row names, else on the first computer that can take one.+ /// `+ New Harness`: in the project a row names, else on the first computer that can take one —+ /// and into the tab the chips are narrowed to, as in Find (`PhoneSearchResultsState.deskTabId`).void _newHarness(({String machineId, String folder, String label})? place) {+ final deskTabId = _results.currentState?.deskTabId;if (place != null) {openNewAgent(context,widget.notifier,place.machineId,folder: place.folder,+ deskTabId: deskTabId,);return;}@@ -74,7 +80,12 @@ class _PickUpPageState extends State<PickUpPage> {).firstOrNull;if (ready != null) {- openNewAgent(context, widget.notifier, ready.machine.machineId);+ openNewAgent(+ context,+ widget.notifier,+ ready.machine.machineId,+ deskTabId: deskTabId,+ );}}@@ -128,6 +139,7 @@ class _PickUpPageState extends State<PickUpPage> {),Expanded(child: PhoneSearchResults(+ key: _results,notifier: widget.notifier,controller: _search,onNewHarness: _newHarness,diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 4e470f772..8e6e7e2c7 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -106,6 +106,10 @@ class AgentCreationAttempt {final String _id;String? _machineId, _targetId;++ /// The desk tab the agent joins once started, picked before it was asked for — see+ /// [PhoneDesk.adopt]. Null joins the tab the phone is in.+ String? _deskTabId;Map<String, dynamic>? _choices;Future<String?>? _inFlight;bool _awaitingConfirmation = false, _finished = false;@@ -5894,6 +5898,9 @@ class AppNotifier extends ChangeNotifier {/// instruction to make one would have to guess which was meant. `cli/src/lib/projectFolder.ts`/// reads the pair, and `[folder]` stays required so the ordinary case — a folder the person/// picked — cannot be forgotten.+ ///+ /// [deskTabId] is the desk tab the agent joins once started — the one Find was narrowed to —+ /// instead of the tab the phone is in. See [PhoneDesk.adopt].Future<String?> createAgent(String machineId, {required String engine,@@ -5903,6 +5910,7 @@ class AppNotifier extends ChangeNotifier {String? codexHome,GridModel? model,String? swarmId,+ String? deskTabId,AgentCreationAttempt? attempt,String? prompt,String? name,@@ -5933,7 +5941,13 @@ class AppNotifier extends ChangeNotifier {'gridModel': ?model?.id,'gridName': ?model?.grid,};- return _create(machineId, choices, swarmId: swarmId, attempt: creation);+ return _create(+ machineId,+ choices,+ swarmId: swarmId,+ deskTabId: deskTabId,+ attempt: creation,+ );}/// A Claude Code or Codex conversation Harness did not start, opened as a harness that resumes@@ -5981,6 +5995,7 @@ class AppNotifier extends ChangeNotifier {String machineId,Map<String, dynamic> choices, {String? swarmId,+ String? deskTabId,AgentCreationAttempt? attempt,}) {final creation = attempt ?? AgentCreationAttempt();@@ -5997,6 +6012,8 @@ class AppNotifier extends ChangeNotifier {creation._choices = choices;creation._machineId = machineId;creation._targetId = swarmId ?? activeSwarmId;+ // With the request, not read again on a Check status: the tab picked is the one asked for.+ creation._deskTabId = deskTabId;}final work = _createAgentWithReceipt(creation);creation._inFlight = work;@@ -6321,12 +6338,13 @@ class AppNotifier extends ChangeNotifier {return null;}// Created HERE, so it joins the tab this phone is in — the way an agent- // created in a window joins that window's tab. See [PhoneDesk.adopt] for- // what happens when the phone is in no tab.- _desk.adopt((- machineId: machineId,- agentId: agent.id,- ), name: agent.displayName);+ // created in a window joins that window's tab — or the tab picked for it.+ // See [PhoneDesk.adopt] for what happens when the phone is in no tab.+ _desk.adopt(+ (machineId: machineId, agentId: agent.id),+ name: agent.displayName,+ tabId: creation._deskTabId,+ );await assignAgentToPane(null, machineId, agent.id, swarmId: targetId);return null;}diff --git a/mobile/lib/state/phone_desk.dart b/mobile/lib/state/phone_desk.dartindex 7a3a06a2c..a7b6b03b4 100644--- a/mobile/lib/state/phone_desk.dart+++ b/mobile/lib/state/phone_desk.dart@@ -225,7 +225,14 @@ class PhoneDesk {/// [name] is the agent's own, and it is used only by [openNextAgentInNewTab]/// — a tab made for one agent is named after it, which is what a window does/// with a tab it opens.- void adopt(AgentRef agent, {String? name}) {+ ///+ /// [tabId] is a tab the person picked for this agent before asking for it —+ /// Find narrowed to a tab when New Harness was tapped — and it wins over the+ /// tab the phone is in, which the agent ON SCREEN decides (`AgentHome`) and+ /// so still names the tab Find was opened over. The phone is in the picked tab+ /// from here, as it is after [createTabFor]. A tab closed on another computer+ /// while the form was open falls back to the tab the phone is in.+ void adopt(AgentRef agent, {String? name, String? tabId}) {if (!_state.enabled) return;final wanted = _newTabForNextAgent;_newTabForNextAgent = false;@@ -237,13 +244,21 @@ class PhoneDesk {createTabFor(agent, name: name);return;}- final tabId = _activeTabId;- if (tabId == null) return;- final tab = _state.synced.where((t) => t.id == tabId).firstOrNull;+ final picked = tabId == null+ ? null+ : _state.synced.where((t) => t.id == tabId).firstOrNull;+ final active = _activeTabId;+ final tab =+ picked ??+ (active == null+ ? null+ : _state.synced.where((t) => t.id == active).firstOrNull);if (tab == null) return;+ // Before the write, so the notice it makes already has the phone in the tab.+ if (picked != null) _activeTabId = picked.id;if (tab.panes.contains(pane)) return;_queue([- {'op': 'pane.add', 'tabId': tabId, ...pane.toJson()},+ {'op': 'pane.add', 'tabId': tab.id, ...pane.toJson()},]);}diff --git a/mobile/test/desk_writes_test.dart b/mobile/test/desk_writes_test.dartindex 715c92d44..19111a192 100644--- a/mobile/test/desk_writes_test.dart+++ b/mobile/test/desk_writes_test.dart@@ -1,30 +1,46 @@import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/ws/ws_conn.dart' show WsRequestTimeout;import 'agent_pager_fixture.dart';import 'desk_fixture.dart';/// A machine that starts and deletes the agents it is asked to, and answers/// everything else with nothing.+///+/// [losesFirstReply] drops the answer to the first `agent_create` the way a+/// relay that went away does, and answers the Check status after it.class _Conn extends PagerConn {+ _Conn({this.losesFirstReply = false});++ final bool losesFirstReply;+ var _creates = 0;++ static Map<String, dynamic> _created(Map<String, dynamic> payload) => {+ 'creationId': payload['creationId'],+ 'state': 'created',+ 'agent': {+ 'id': 'new',+ 'name': 'new',+ 'engine': 'claude',+ 'terminal': {'available': true},+ },+ };+@overrideFuture<Map<String, dynamic>> request(String type, {Map<String, dynamic> payload = const {},Duration timeout = const Duration(seconds: 20),- }) async => switch (type) {- 'agent_create' => {- 'creationId': payload['creationId'],- 'state': 'created',- 'agent': {- 'id': 'new',- 'name': 'new',- 'engine': 'claude',- 'terminal': {'available': true},- },- },- _ => {},- };+ }) async {+ if (type == 'agent_create' && losesFirstReply && _creates++ == 0) {+ throw const WsRequestTimeout('agent_create');+ }+ return switch (type) {+ 'agent_create' || 'agent_create_status' => _created(payload),+ _ => {},+ };+ }}/// What the phone tells the desk, and what the desk tells the phone.@@ -61,6 +77,71 @@ void main() {]);});+ test(+ 'an agent created for a picked tab joins it, not the tab the phone is in',+ () async {+ final app = await deskApp(+ _Conn(),+ opensTerminals: false,+ tabs: [+ deskTab('t1', 'Desktop', ['a']),+ deskTab('t2', 'Docker', ['c']),+ ],+ );+ addTearDown(app.dispose);+ // The tab of the harness Find was opened over; Find was narrowed to Docker.+ app.noteDeskTab('t1');++ final error = await app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/work',+ deskTabId: 't2',+ );+ await pumpEventQueue();++ expect(error, isNull);+ expect(agentsOf(app, 't1'), ['a']);+ expect(agentsOf(app, 't2'), ['c', 'new']);+ expect(app.activeDeskTabId, 't2');+ expect(deskApiOf(app).written, [+ {'op': 'pane.add', 'tabId': 't2', 'machineId': 'm', 'agentId': 'new'},+ ]);+ },+ );++ test('a Check status after a lost reply keeps the tab picked', () async {+ final app = await deskApp(+ _Conn(losesFirstReply: true),+ opensTerminals: false,+ tabs: [+ deskTab('t1', 'Desktop', ['a']),+ deskTab('t2', 'Docker', ['c']),+ ],+ );+ addTearDown(app.dispose);+ app.noteDeskTab('t1');+ final attempt = AgentCreationAttempt();++ final lost = await app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/work',+ deskTabId: 't2',+ attempt: attempt,+ );+ expect(lost, contains('has not confirmed the new harness yet'));+ expect(deskApiOf(app).written, isEmpty);++ // Asked about with what it was first made with — no tab handed in again.+ final checked = await app.checkAgentCreation(attempt);+ await pumpEventQueue();++ expect(checked, isNull);+ expect(agentsOf(app, 't1'), ['a']);+ expect(agentsOf(app, 't2'), ['c', 'new']);+ });+test('an agent deleted on the phone leaves the tabs it was on', () async {final app = await deskApp(_Conn(),diff --git a/mobile/test/find_tab_new_harness_test.dart b/mobile/test/find_tab_new_harness_test.dartnew file mode 100644index 000000000..5a6a14c18--- /dev/null+++ b/mobile/test/find_tab_new_harness_test.dart@@ -0,0 +1,132 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/phone/desk_tab_filter_bar.dart';+import 'package:harness_mobile/phone/new_agent_page.dart';+import 'package:harness_mobile/phone/terminal_search.dart';+import 'package:harness_mobile/phone/welcome/pick_up_page.dart';+import 'package:harness_mobile/state/app_state.dart';++import 'agent_pager_fixture.dart';+import 'desk_fixture.dart';++/// Find's New Harness makes its harness in the tab the chips are narrowed to.+///+/// ⚠️ The regression this is here for: Find opened over `a` (a Desktop harness), narrowed to+/// Docker, New Harness tapped — and the new harness landed in Desktop. The phone counts itself in+/// the tab of the harness on screen, and the chip only narrowed the list; nothing carried it to+/// the form. The form now holds the tab ([NewAgentPage.deskTabId]) and the desk write takes it+/// (`desk_writes_test.dart`, `phone_desk_test.dart`).+void main() {+ Future<AppNotifier> openFind(WidgetTester tester) async {+ final app = await deskApp(+ PagerConn(),+ opensTerminals: false,+ tabs: [+ deskTab('t1', 'Desktop', ['a', 'b']),+ deskTab('t2', 'Docker', ['c']),+ ],+ );+ addTearDown(app.dispose);+ // What the home screen records under the harness on screen.+ app.noteDeskTab('t1');+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: TerminalSearchOverlay(+ notifier: app,+ animation: const AlwaysStoppedAnimation(1),+ onClose: () {},+ showing: (machineId: 'm', agentId: 'a'),+ ),+ ),+ ),+ );+ await tester.pump();+ return app;+ }++ Future<void> pickTab(WidgetTester tester, String name) async {+ await tester.tap(+ find.descendant(+ of: find.byType(DeskTabFilterBar),+ matching: find.text(name),+ ),+ );+ await tester.pump();+ }++ Future<void> openForm(WidgetTester tester, Finder button) async {+ await tester.ensureVisible(button);+ await tester.pump();+ await tester.tap(button);+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 500));+ }++ String? formTab(WidgetTester tester) =>+ tester.widget<NewAgentPage>(find.byType(NewAgentPage)).deskTabId;++ /// Takes the form down and runs its clocks out, so no timer outlives the test.+ Future<void> unmount(WidgetTester tester) async {+ await tester.pumpWidget(const SizedBox());+ await tester.pump(const Duration(seconds: 30));+ }++ testWidgets('the button at the foot makes it in the tab picked', (+ tester,+ ) async {+ await openFind(tester);+ await pickTab(tester, 'Docker');++ await openForm(tester, find.byKey(const ValueKey('find-new-harness')));++ expect(find.byType(NewAgentPage), findsOneWidget);+ expect(formTab(tester), 't2');+ await unmount(tester);+ });++ testWidgets('so does the + New Harness row', (tester) async {+ await openFind(tester);+ await pickTab(tester, 'Docker');++ await openForm(tester, find.text('+ New Harness', findRichText: true));++ expect(formTab(tester), 't2');+ await unmount(tester);+ });++ testWidgets('on All the tab the phone is in still decides', (tester) async {+ await openFind(tester);+ await pickTab(tester, 'Docker');+ await pickTab(tester, 'All');++ await openForm(tester, find.byKey(const ValueKey('find-new-harness')));++ expect(formTab(tester), isNull);+ await unmount(tester);+ });++ // The first screen after pairing draws Find's own list, chips and `+ New Harness` included.+ testWidgets('the pick-up screen makes it in the tab picked too', (+ tester,+ ) async {+ final app = await deskApp(+ PagerConn(),+ opensTerminals: false,+ tabs: [+ deskTab('t1', 'Desktop', ['a', 'b']),+ deskTab('t2', 'Docker', ['c']),+ ],+ );+ addTearDown(app.dispose);+ app.noteDeskTab('t1');+ await tester.pumpWidget(MaterialApp(home: PickUpPage(notifier: app)));+ await tester.pump();+ await pickTab(tester, 'Docker');++ await openForm(tester, find.text('+ New Harness', findRichText: true));++ expect(formTab(tester), 't2');+ await unmount(tester);+ });+}diff --git a/mobile/test/phone_desk_test.dart b/mobile/test/phone_desk_test.dartindex d42626d5f..51e44fcee 100644--- a/mobile/test/phone_desk_test.dart+++ b/mobile/test/phone_desk_test.dart@@ -200,6 +200,60 @@ void main() {expect(backend.received, isEmpty);});+ // ⚠️ The regression this is here for: Find narrowed to Docker, New Harness tapped over an agent+ // of Desktop — and the new agent landed in Desktop, the tab of the agent on screen.+ test(+ 'an agent made for a tab picked by hand joins that tab, and the phone is in it',+ () async {+ await join();+ // The tab of the agent on screen, which the home screen records.+ desk.note('t1');++ desk.adopt((machineId: 'm', agentId: 'new'), tabId: 't2');++ expect(_agentsOf(desk, 't1'), ['a', 'b']);+ expect(_agentsOf(desk, 't2'), ['c', 'new']);+ expect(desk.activeTabId, 't2');+ await pumpEventQueue();+ expect(backend.received, [+ {'op': 'pane.add', 'tabId': 't2', 'machineId': 'm', 'agentId': 'new'},+ ]);+ },+ );++ test('a tab picked by hand counts with the phone in no tab too', () async {+ await join();+ desk.note(null);++ desk.adopt((machineId: 'm', agentId: 'new'), tabId: 't2');+ await pumpEventQueue();++ expect(_agentsOf(desk, 't2'), ['c', 'new']);+ expect(desk.activeTabId, 't2');+ expect(backend.received.map((op) => op['tabId']), ['t2']);+ });++ test(+ 'a picked tab closed on another computer meanwhile leaves the agent in the tab the phone is in',+ () async {+ await join();+ desk.note('t1');+ backend.edit([+ {'op': 'tab.close', 'id': 't2'},+ ]);+ await desk.refresh();++ desk.adopt((machineId: 'm', agentId: 'new'), tabId: 't2');+ await pumpEventQueue();++ expect(_agentsOf(desk, 't1'), ['a', 'b', 'new']);+ expect(desk.activeTabId, 't1');+ expect(backend.received, [+ {'op': 'pane.add', 'tabId': 't1', 'machineId': 'm', 'agentId': 'new'},+ ]);+ },+ );+test('an agent deleted on the phone leaves every tab that held it', () async {backend = _Backend(tabs: [