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): check status instead of starting a second harness
tony854ec0dd1248
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dartindex 238190d81..e24e9db9d 100644--- a/mobile/lib/phone/new_agent_page.dart+++ b/mobile/lib/phone/new_agent_page.dart@@ -620,14 +620,25 @@ class _NewAgentPageState extends State<NewAgentPage> {if ((folder == null && project == null) || engine == null || _creating) {return;}+ // A request still waiting on its answer is asked about, never made again — see [_creation].+ final pending = _checking ? _creation : null;setState(() {_creating = true;+ _checkingLaunch = pending != null;_error = null;});+ if (pending != null) {+ _answered(+ pending,+ engine,+ await widget.notifier.checkAgentCreation(pending),+ );+ return;+ }// 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();+ // [AgentCreationAttempt.agentId] — and kept as [_creation] for as long as+ // its answer is outstanding.+ final creation = _creation = AgentCreationAttempt();// A folder in a repository is not sent as a bare `cwd`: the branch and the// worktree travel with it, and [gitFolderRequest] is the desktop's own rule// for turning the rows above into what the machine is asked to do. A folder@@ -675,7 +686,16 @@ class _NewAgentPageState extends State<NewAgentPage> {prompt: _engine != null && takesFirstTask(_engine!) ? _task.text : null,name: namedByTask ? taskProjectTitle(task) : null,);+ _answered(creation, engine, error);+ }++ /// What the machine said to [creation], on the form: inside the new harness when one started,+ /// otherwise the reason under the task.+ void _answered(AgentCreationAttempt creation, String engine, String? error) {if (!mounted) return;+ // Started, or refused for good: done with. The next press is a new request with an id of its+ // own, made from the rows as they read then.+ if (!creation.awaitingConfirmation) _creation = null;if (error == null) {// The harness exists: the draft that described it would be a second one waiting to be made// by accident. See [NewAgentDraft].@@ -687,12 +707,40 @@ class _NewAgentPageState extends State<NewAgentPage> {setState(() {_creating = false;_error = error;- _failed = true;+ _failure = error;});}- /// The last Start did not take: the button says Try Again, and every value stays.- bool _failed = false;+ /// The last request this form made, kept while the machine has not said whether it started —+ /// the desktop's `_attempt` (`state/new_harness.dart`).+ ///+ /// ⚠️ **A lost reply is not a refusal.** "Has not confirmed the new harness yet" and "still+ /// starting your harness" both mean a harness may exist. Pressed again with a fresh attempt,+ /// the button sent a new `creationId` and could start a second one; with this one it asks+ /// `agent_create_status` about the first. Dropped by [_answered] once the answer is final.+ ///+ /// Only for the open form. Closing it lets the request go, and the draft it leaves is a new+ /// request the next time — the desktop keeps the receipt in its draft, but its drafts are kept+ /// per place, and the phone's one draft would keep every later New on Check status, with+ /// nothing on the form to let it go.+ AgentCreationAttempt? _creation;++ /// [_creation] is waiting on its answer: the button checks on it, and the choices it was made+ /// with are held — the desktop's `checking` and `locked`.+ bool get _checking => _creation?.awaitingConfirmation ?? false;++ /// The rows take no taps: a request is on its way, or one is waiting to be checked on.+ bool get _locked => _creating || _checking;++ /// The press under way is a check on [_creation], not a new request — the desktop's+ /// `_checkingLaunch`, so the button says Checking rather than Starting.+ bool _checkingLaunch = false;++ /// What the last press was answered with. The button says Try Again while that answer is still+ /// the line under the task; a choice changed since clears the line, and the button goes back to+ /// saying what it will do.+ String? _failure;+ bool get _failed => _failure != null && _failure == _error;/// Where a finished creation lands: inside the agent it just started.///@@ -846,7 +894,7 @@ class _NewAgentPageState extends State<NewAgentPage> {detail: _engine == null? null: _engineNote(_engine!),- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseAgent()),),@@ -859,7 +907,7 @@ class _NewAgentPageState extends State<NewAgentPage> {? tty.green: null,detail: _machineNote,- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseComputer()),),@@ -873,7 +921,7 @@ class _NewAgentPageState extends State<NewAgentPage> {? tty.green: null,detail: null,- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseProject()),),@@ -883,7 +931,7 @@ class _NewAgentPageState extends State<NewAgentPage> {label: 'options',value: _optionsOpen ? '[-]' : '[+]',chevron: false,- onTap: _creating+ onTap: _locked? null: () => setState(() => _optionsOpen = !_optionsOpen,@@ -896,7 +944,7 @@ class _NewAgentPageState extends State<NewAgentPage> {_model?.id ??modelSubscriptionLabel(_engine!),detail: _model?.node,- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseModel()),),@@ -908,7 +956,7 @@ class _NewAgentPageState extends State<NewAgentPage> {valueColor: (mode?.risky ?? false)? tty.red: null,- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseApprovals()),),@@ -916,7 +964,7 @@ class _NewAgentPageState extends State<NewAgentPage> {TtyFormRow(label: 'profile',value: _codexProfile?.label ?? 'Default',- onTap: _creating+ onTap: _locked? null: () => unawaited(_chooseProfile()),),@@ -936,7 +984,7 @@ class _NewAgentPageState extends State<NewAgentPage> {? 'Choose a project': 'Not a Git repository',detail: info == null ? null : _branchNote,- onTap: info == null || _creating+ onTap: info == null || _locked? null: () => unawaited(_pickBranch(info)),),@@ -951,7 +999,7 @@ class _NewAgentPageState extends State<NewAgentPage> {? tty.faint: null,chevron: false,- onTap: info == null || _creating+ onTap: info == null || _locked? null: () => setState(() {_worktree = !_worktree;@@ -1074,8 +1122,11 @@ class _NewAgentPageState extends State<NewAgentPage> {),const SizedBox(height: 10),TtyPrimaryButton(- // Says what it will do: start, or choose what is still missing first.- label: _failed+ // Says what it will do: check on a request still unanswered, start,+ // or choose what is still missing first.+ label: _checking+ ? 'Check status'+ : _failed? 'Try Again': ready? 'Start'@@ -1083,7 +1134,9 @@ class _NewAgentPageState extends State<NewAgentPage> {? 'Choose an agent': 'Choose a project',busy: _creating,- busyLabel: 'Starting…',+ busyLabel: _checkingLaunch+ ? 'Checking…'+ : 'Starting…',// Never a dead button: with a choice missing, Start opens its chooser.onPressed: () => unawaited(_start()),),diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex faa4ba157..5187639f4 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -5793,6 +5793,27 @@ class AppNotifier extends ChangeNotifier {'resumeSessionId': sessionId,}, attempt: attempt);+ /// Asks what became of [attempt] — `agent_create_status`, under the same `creationId` — with+ /// the choices it was first made with. The New form's Check status, the desktop's.+ ///+ /// ⚠️ **Not [createAgent] again with the form's rows as they read now.** An answer that lands+ /// after the first press — a Git read, a machine's only Codex profile — changes the request the+ /// form would build, and a changed request is refused ("Check the original request…") rather+ /// than checked, so the form would be stuck saying so. The attempt holds what was asked; this+ /// asks about exactly that.+ ///+ /// Never a creation: an attempt that was not sent has nothing to check, and nothing is sent.+ Future<String?> checkAgentCreation(AgentCreationAttempt attempt) {+ if (attempt._finished) return Future.value(attempt._outcome);+ final machineId = attempt._machineId, choices = attempt._choices;+ if (!attempt.awaitingConfirmation || machineId == null || choices == null) {+ return Future.value(+ 'This request was never sent. Start the harness again.',+ );+ }+ return _create(machineId, choices, attempt: attempt);+ }+Future<String?> _create(String machineId,Map<String, dynamic> choices, {diff --git a/mobile/test/app_state_agent_rpcs_test.dart b/mobile/test/app_state_agent_rpcs_test.dartindex 180780315..7faa71ee8 100644--- a/mobile/test/app_state_agent_rpcs_test.dart+++ b/mobile/test/app_state_agent_rpcs_test.dart@@ -378,6 +378,61 @@ void main() {},);+ test('Check status asks about the request as it was made', () async {+ final rig = await signedInWith({'m': []});+ addTearDown(rig.app.dispose);+ rig.conn('m').answers['agent_create'] = (_) =>+ throw const WsRequestTimeout('agent_create');+ final attempt = AgentCreationAttempt();+ await rig.app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/work',+ attempt: attempt,+ );++ rig.conn('m').answers['agent_create_status'] = (p) => created(p, 'new');+ expect(+ await measured(rig, 'm', rig.app.checkAgentCreation(attempt)),+ isNull,+ );+ expect(rig.conn('m').payloadsOf('agent_create'), hasLength(1));+ expect(rig.conn('m').payloadsOf('agent_create_status').single, {+ 'creationId': rig+ .conn('m')+ .payloadsOf('agent_create')+ .single['creationId'],+ });+ expect(attempt.agentId, 'new');+ });++ test('Check status never makes a harness', () async {+ final rig = await signedInWith({'m': []});+ addTearDown(rig.app.dispose);+ rig.conn('m').answers['agent_create'] = (_) =>+ throw refusal('CWD_NOT_FOUND');++ // Never sent: there is nothing to ask about, and asking must not send it.+ expect(+ await rig.app.checkAgentCreation(AgentCreationAttempt()),+ contains('never sent'),+ );+ expect(rig.conn('m').payloadsOf('agent_create'), isEmpty);+ expect(rig.conn('m').payloadsOf('agent_create_status'), isEmpty);++ // Refused for good: the answer stands, and the machine is not asked again.+ final refused = AgentCreationAttempt();+ final error = await rig.app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/gone',+ attempt: refused,+ );+ expect(await rig.app.checkAgentCreation(refused), error);+ expect(rig.conn('m').payloadsOf('agent_create'), hasLength(1));+ expect(rig.conn('m').payloadsOf('agent_create_status'), isEmpty);+ });+test('two presses of one request share one answer', () async {final rig = await signedInWith({'m': []});addTearDown(rig.app.dispose);diff --git a/mobile/test/phone_edge/new_check_status_test.dart b/mobile/test/phone_edge/new_check_status_test.dartnew file mode 100644index 000000000..c0df3487c--- /dev/null+++ b/mobile/test/phone_edge/new_check_status_test.dart@@ -0,0 +1,248 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/phone/agent_swipe.dart';+import 'package:harness_mobile/phone/new_agent_draft.dart';+import 'package:harness_mobile/phone/new_agent_page.dart';+import 'package:harness_mobile/phone/tty_controls.dart' show TtyFormRow;+import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/ws/ws_conn.dart';++import 'edge_fixture.dart';++/// What the machine answers one request with; throwing stands for a reply that never arrived.+typedef _Answer = Map<String, dynamic> Function(Map<String, dynamic> payload);++/// New when the machine answers Start with neither a yes nor a no: the button checks on the+/// request it made, under the same id, and never makes a second harness to find out.+void main() {+ tearDown(() => newAgentDraft = null);++ Map<String, dynamic> created(Map<String, dynamic> payload) => {+ 'creationId': payload['creationId'],+ 'state': 'created',+ 'agent': {+ 'id': 'new-agent',+ 'name': 'new-agent',+ 'engine': 'claude',+ 'terminal': {'available': true},+ },+ };++ Map<String, dynamic> pending(Map<String, dynamic> payload) => {+ 'creationId': payload['creationId'],+ 'state': 'pending',+ };++ Map<String, dynamic> lost(Map<String, dynamic> _) =>+ throw const WsRequestTimeout('agent_create');++ /// New on `m`, whose agent's folder is the project, answering from [script] — which a test+ /// changes between presses, as the machine's answers change.+ Future<({AppNotifier app, EdgeConn conn})> openNew(+ WidgetTester tester,+ Map<String, _Answer> script,+ ) async {+ setPhone(tester, largePhone);+ final conn = EdgeConn(+ const {},+ (type, payload) => script[type]?.call(payload),+ );+ final app = edgeApp(conn: conn);+ await tester.pumpWidget(+ phoneApp(+ Builder(+ builder: (context) => TextButton(+ onPressed: () => Navigator.of(context).push(+ MaterialPageRoute<void>(+ builder: (_) => NewAgentPage(notifier: app, machineId: 'm'),+ ),+ ),+ child: const Text('focus'),+ ),+ ),+ ),+ );+ await tester.tap(find.text('focus'));+ await frames(tester);+ return (app: app, conn: conn);+ }++ Future<void> close(WidgetTester tester, AppNotifier app) async {+ await tester.pumpWidget(const SizedBox());+ await tester.pump(const Duration(seconds: 3));+ app.dispose();+ await tester.pump(const Duration(seconds: 30));+ }++ Future<void> press(WidgetTester tester, String label) async {+ await tapInView(tester, find.text(label));+ await frames(tester, count: 20);+ }++ /// Runs the clock until the harness just made is open. Its terminal is opened before the create+ /// answers, and that open waits for a handshake this fake never finishes (15s) and for a+ /// viewport nothing has measured yet (2s).+ Future<void> opened(WidgetTester tester) async {+ for (+ var i = 0;+ i < 120 && find.byType(AgentSwipeHost).evaluate().isEmpty;+ i+++ ) {+ await tester.pump(const Duration(milliseconds: 250));+ }+ await frames(tester, count: 8);+ }++ /// What the form's [label] row says.+ String row(WidgetTester tester, String label) => tester+ .widget<TtyFormRow>(+ find.byWidgetPredicate(+ (widget) => widget is TtyFormRow && widget.label == label,+ ),+ )+ .value;++ List<Map<String, dynamic>> sent(EdgeConn conn, String type) =>+ conn.payloads[type] ?? const [];++ testWidgets(+ 'a lost reply: Check status asks about the same request, and opens what it started',+ (tester) async {+ final script = <String, _Answer>{'agent_create': lost};+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');++ expect(+ find.textContaining('has not confirmed the new harness yet'),+ findsOneWidget,+ );+ expect(find.text('Check status'), findsOneWidget);+ expect(find.text('Try Again'), findsNothing);+ expect(find.text('Start'), findsNothing);++ // The choices are held while it is checked on — the request is the one on the form.+ await tapInView(tester, find.text('options'));+ await frames(tester);+ expect(row(tester, 'options'), '[+]');++ script['agent_create_status'] = created;+ await press(tester, 'Check status');+ expect(find.text('Checking…'), findsOneWidget);+ await opened(tester);++ final [first] = sent(conn, 'agent_create');+ final [status] = sent(conn, 'agent_create_status');+ expect(status['creationId'], first['creationId']);+ expect(status.keys, [+ 'creationId',+ ], reason: 'a check asks about the request; it does not make it again');+ expect(find.byType(AgentSwipeHost), findsOneWidget);+ expect(find.byType(NewAgentPage), findsNothing);+ await close(tester, app);+ },+ );++ testWidgets('still starting: checked again under the same id until it has '+ 'started', (tester) async {+ final script = <String, _Answer>{+ 'agent_create': pending,+ 'agent_create_status': pending,+ };+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');+ expect(find.textContaining('still starting your harness'), findsOneWidget);+ expect(find.text('Check status'), findsOneWidget);++ await press(tester, 'Check status');+ expect(find.textContaining('still starting your harness'), findsOneWidget);+ expect(find.text('Check status'), findsOneWidget);++ script['agent_create_status'] = created;+ await press(tester, 'Check status');+ await opened(tester);++ final [first] = sent(conn, 'agent_create');+ final checks = sent(conn, 'agent_create_status');+ expect(checks, hasLength(2));+ for (final check in checks) {+ expect(check['creationId'], first['creationId']);+ }+ expect(find.byType(AgentSwipeHost), findsOneWidget);+ await close(tester, app);+ });++ testWidgets(+ 'refused for good after a check: Try Again is a new request, under a new id',+ (tester) async {+ final script = <String, _Answer>{+ 'agent_create': lost,+ 'agent_create_status': (payload) => {+ 'creationId': payload['creationId'],+ 'state': 'failed',+ 'failure': {'code': 'CWD_NOT_FOUND'},+ },+ };+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');+ await press(tester, 'Check status');++ expect(+ find.textContaining('project folder is unavailable'),+ findsOneWidget,+ );+ expect(find.text('Try Again'), findsOneWidget);+ expect(find.text('Check status'), findsNothing);++ script['agent_create'] = created;+ await press(tester, 'Try Again');+ expect(find.text('Starting…'), findsOneWidget);+ await opened(tester);++ final [first, second] = sent(conn, 'agent_create');+ expect(second['creationId'], isA<String>());+ expect(second['creationId'], isNot(first['creationId']));+ expect(sent(conn, 'agent_create_status'), hasLength(1));+ expect(find.byType(AgentSwipeHost), findsOneWidget);+ await close(tester, app);+ },+ );++ testWidgets('Try Again lasts only while its answer is on screen', (+ tester,+ ) async {+ final script = <String, _Answer>{+ 'agent_create': (_) => throw const WsRequestFailure(+ responseType: 'agent_create_result',+ code: 'CWD_NOT_FOUND',+ ),+ };+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');+ expect(find.text('Try Again'), findsOneWidget);+ expect(find.text('Check status'), findsNothing);++ // A refusal holds nothing: the rows answer again, and a changed choice is a new request.+ await tapInView(tester, find.text('agent'));+ await frames(tester);+ await tapInView(tester, find.text('Codex', findRichText: true).last);+ await frames(tester);++ expect(row(tester, 'agent'), 'Codex');+ expect(find.textContaining('project folder is unavailable'), findsNothing);+ expect(find.text('Start'), findsOneWidget);+ expect(find.text('Try Again'), findsNothing);++ script['agent_create'] = created;+ await press(tester, 'Start');++ final [first, second] = sent(conn, 'agent_create');+ expect(second['engine'], 'codex');+ expect(second['creationId'], isNot(first['creationId']));+ expect(sent(conn, 'agent_create_status'), isEmpty);+ await close(tester, app);+ });+}