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): say what a held creation waits on, and cancel it from the New form
tony3f25e67cc855
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dartindex 73fd69e13..248986517 100644--- a/mobile/lib/phone/new_agent_page.dart+++ b/mobile/lib/phone/new_agent_page.dart@@ -903,6 +903,25 @@ class _NewAgentPageState extends State<NewAgentPage> {_answered(creation, engine, error);}+ /// Cancel request: the held request called off. Confirmed, the form is free for a new one and+ /// says so; otherwise the reason stands under the task and the request stays to be checked.+ Future<void> _cancelPending() async {+ final creation = _creation;+ if (creation == null || _creating || creation.cancelling) return;+ setState(() {});+ final problem = await widget.notifier.cancelAgentCreation(creation);+ if (!mounted) return;+ if (problem == null) {+ if (identical(_creation, creation)) _creation = null;+ ScaffoldMessenger.maybeOf(context)+ ?.showSnackBar(const SnackBar(content: Text('Creation cancelled.')));+ }+ setState(() {+ _error = problem;+ _failure = null;+ });+ }+/// 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) {@@ -1378,6 +1397,22 @@ class _NewAgentPageState extends State<NewAgentPage> {// Never a dead button: with a choice missing, Start opens its chooser.onPressed: () => unawaited(_start()),),+ // A request the machine holds before starting anything (an engine it is+ // installing) can still be called off — the desktop's Cancel request.+ if (_creation?.canCancelPending == true &&+ !_creating)+ Center(+ child: TtyTextButton(+ key: const ValueKey(+ 'cancel-pending-creation',+ ),+ label: 'Cancel request',+ size: TtySize.meta,+ onPressed: _creation!.cancelling+ ? null+ : () => unawaited(_cancelPending()),+ ),+ ),],),),diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 2f2237f93..a4088abe1 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -203,11 +203,24 @@ class AgentCreationAttempt {/// is known to take one — the desktop's `_codexHomeTrusted`. The New form, which offers profiles/// only from the machine's own engine list, leaves it false.bool _codexHomeTrusted = false;++ /// What the machine holds the request on — "Installing Kilo. The harness starts once it is+ /// installed." — from a `pending` answer that names one. Null when it holds nothing: then it is+ /// already starting the harness, and there is nothing left to cancel.+ String? _holdReason;+ bool _cancelling = false;String? _outcome;String? _agentId;bool get awaitingConfirmation => _awaitingConfirmation;+ /// The machine holds this request before starting anything (an engine it is installing), so it+ /// can still be called off — the desktop's `canCancelPending`, behind the form's Cancel request.+ bool get canCancelPending => _awaitingConfirmation && _holdReason != null;++ /// A cancel is on its way to the machine.+ bool get cancelling => _cancelling;+/// 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@@ -219,6 +232,7 @@ class AgentCreationAttempt {String? _complete(String? error) {_finished = true;_awaitingConfirmation = false;+ _holdReason = null;return _outcome = error;}}@@ -6566,6 +6580,42 @@ class AppNotifier extends ChangeNotifier {_ => 'Create harness failed: ${detail ?? code}',};+ /// Calls off a request the machine holds — the New form's Cancel request, the desktop's+ /// `cancelAgentCreation`. Null once the machine says it is cancelled; otherwise what to tell the+ /// person, with the request still kept to check.+ ///+ /// ⚠️ **Confirmed by the machine's own receipt.** A lost reply here cannot turn the original+ /// request into a fresh one: the attempt keeps its receipt, and Check status asks about it.+ Future<String?> cancelAgentCreation(AgentCreationAttempt creation) async {+ if (!creation.canCancelPending ||+ creation._cancelling ||+ creation._inFlight != null) {+ return 'Check the request status before cancelling.';+ }+ final machineId = creation._machineId;+ if (machineId == null || !machineStates.containsKey(machineId)) {+ return 'The original machine is unavailable. The request is still saved.';+ }+ creation._cancelling = true;+ try {+ final result = await _conn(machineId).request(+ 'agent_create_cancel',+ payload: {'creationId': creation._id},+ timeout: const Duration(seconds: 10),+ );+ if (result['creationId'] == creation._id &&+ result['state'] == 'cancelled') {+ creation._complete('Creation cancelled.');+ return null;+ }+ return 'The request may already be starting. Check status before starting another.';+ } catch (_) {+ return 'Cancellation is not confirmed. Check status before starting another.';+ } finally {+ creation._cancelling = false;+ }+ }+Future<String?> _createAgentWithReceipt(AgentCreationAttempt creation) async {final machineId = creation._machineId!;final targetId = creation._targetId!;@@ -6727,7 +6777,20 @@ class AppNotifier extends ChangeNotifier {return '$machineName has no record of this request. ''Use Find a harness to look for it before creating another.';case 'pending':+ // Held before anything started — an engine being installed, a model waking — the machine+ // says on what, in a sentence of its own, and the request can still be called off.+ final held = result['held'];+ if (held is Map) {+ final detail = held['detail'];+ if (detail is String && detail.isNotEmpty) {+ creation._holdReason = detail;+ return detail;+ }+ }+ creation._holdReason = null;return '$machineName is still starting your harness. Check again in a moment.';+ case 'cancelled':+ return creation._complete('Creation cancelled.');case 'unconfirmed':return '$machineName could not confirm whether this harness started. ''Use Open Harness to look for it before creating another.';diff --git a/mobile/test/phone_edge/new_check_status_test.dart b/mobile/test/phone_edge/new_check_status_test.dartindex c0df3487c..ffe933de5 100644--- a/mobile/test/phone_edge/new_check_status_test.dart+++ b/mobile/test/phone_edge/new_check_status_test.dart@@ -36,6 +36,16 @@ void main() {Map<String, dynamic> lost(Map<String, dynamic> _) =>throw const WsRequestTimeout('agent_create');+ /// Held before anything started, as a machine installing the engine answers.+ Map<String, dynamic> held(Map<String, dynamic> payload) => {+ 'creationId': payload['creationId'],+ 'state': 'pending',+ 'held': {+ 'service': 'engine',+ 'detail': 'Installing Kilo. The harness starts once it is installed.',+ },+ };+/// 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(@@ -245,4 +255,83 @@ void main() {expect(sent(conn, 'agent_create_status'), isEmpty);await close(tester, app);});++ testWidgets('held while the engine installs: says on what, and Cancel '+ 'request calls it off under the same id', (tester) async {+ final script = <String, _Answer>{+ 'agent_create': held,+ 'agent_create_cancel': (payload) => {+ 'creationId': payload['creationId'],+ 'state': 'cancelled',+ },+ };+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');+ expect(+ find.textContaining('Installing Kilo. The harness starts once'),+ findsOneWidget,+ );+ expect(find.text('Check status'), findsOneWidget);+ expect(find.text('Cancel request'), findsOneWidget);++ await press(tester, 'Cancel request');++ final [first] = sent(conn, 'agent_create');+ final [cancel] = sent(conn, 'agent_create_cancel');+ expect(cancel, {'creationId': first['creationId']});+ expect(find.text('Creation cancelled.'), findsOneWidget);+ expect(find.text('Cancel request'), findsNothing);+ expect(find.text('Check status'), findsNothing);+ expect(find.text('Start'), findsOneWidget, reason: 'free for a new one');+ expect(+ find.textContaining('Installing Kilo'),+ findsNothing,+ reason: 'the hold is over',+ );+ await close(tester, app);+ });++ testWidgets('a harness already starting has nothing to cancel', (+ tester,+ ) async {+ final script = <String, _Answer>{'agent_create': pending};+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');++ expect(find.text('Check status'), findsOneWidget);+ expect(find.text('Cancel request'), findsNothing);+ await close(tester, app);+ });++ testWidgets('a cancel the machine does not confirm keeps the request to '+ 'check', (tester) async {+ final script = <String, _Answer>{+ 'agent_create': held,+ 'agent_create_cancel': (_) =>+ throw const WsRequestTimeout('agent_create_cancel'),+ };+ final (:app, :conn) = await openNew(tester, script);++ await press(tester, 'Start');+ await press(tester, 'Cancel request');++ expect(+ find.textContaining('Cancellation is not confirmed'),+ 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');+ expect(+ sent(conn, 'agent_create_status').single['creationId'],+ first['creationId'],+ );+ expect(find.byType(AgentSwipeHost), findsOneWidget);+ await close(tester, app);+ });}diff --git a/mobile/test/state/create_cancel_test.dart b/mobile/test/state/create_cancel_test.dartnew file mode 100644index 000000000..79c1a155e--- /dev/null+++ b/mobile/test/state/create_cancel_test.dart@@ -0,0 +1,156 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/state/app_state.dart';++import '../viewer_app_fixture.dart';++/// Cancel request from the phone: a creation the machine holds before starting anything — an+/// engine it is installing — called off under its own receipt, the desktop's+/// `cancelAgentCreation`. Only a hold can be cancelled, and only the machine's word ends it.+void main() {+ const holding = 'Installing Kilo. The harness starts once it is installed.';++ Future<ViewerRig> holdingRig() async {+ final rig = viewerApp();+ rig.api.onMachines = () async => [remoteMachine('m')];+ final answers = rig.conn('m').answers;+ answers['agents_list'] = (_) => {'agents': <Object>[]};+ answers['terminal_capabilities'] = (_) => capabilities();+ answers['agent_create'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'pending',+ 'held': {'service': 'engine', 'detail': holding},+ };+ await rig.app.bootstrap();+ await settle();+ rig.app.connectionStatusForTest('m', ConnectionStatus.connected);+ await settle();+ addTearDown(rig.app.dispose);+ return rig;+ }++ Future<AgentCreationAttempt> heldCreation(ViewerRig rig) async {+ final attempt = AgentCreationAttempt();+ expect(+ await rig.app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: attempt,+ ),+ holding,+ );+ return attempt;+ }++ test('a hold names itself and can be called off under the same '+ 'receipt, after which nothing more is asked', () async {+ final rig = await holdingRig();+ final conn = rig.conn('m');+ conn.answers['agent_create_cancel'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'cancelled',+ };+ final attempt = await heldCreation(rig);+ expect(attempt.canCancelPending, isTrue);++ expect(await rig.app.cancelAgentCreation(attempt), isNull);++ final receipt = conn.payloadsOf('agent_create').single['creationId'];+ expect(conn.payloadsOf('agent_create_cancel'), [+ {'creationId': receipt},+ ]);+ expect(attempt.canCancelPending, isFalse);+ expect(attempt.awaitingConfirmation, isFalse);+ expect(await rig.app.checkAgentCreation(attempt), 'Creation cancelled.');+ expect(conn.payloadsOf('agent_create_status'), isEmpty);+ });++ test('a harness already starting holds nothing to cancel, and nothing is '+ 'sent', () async {+ final rig = await holdingRig();+ final conn = rig.conn('m');+ conn.answers['agent_create'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'pending',+ };+ final attempt = AgentCreationAttempt();+ await rig.app.createAgent(+ 'm',+ engine: 'claude',+ folder: '/work',+ attempt: attempt,+ );++ expect(attempt.awaitingConfirmation, isTrue);+ expect(attempt.canCancelPending, isFalse);+ expect(+ await rig.app.cancelAgentCreation(attempt),+ 'Check the request status before cancelling.',+ );+ expect(conn.payloadsOf('agent_create_cancel'), isEmpty);+ });++ test('a cancel answered with anything but cancelled keeps the request to '+ 'check', () async {+ final rig = await holdingRig();+ final conn = rig.conn('m');+ conn.answers['agent_create_cancel'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'pending',+ };+ final attempt = await heldCreation(rig);++ expect(+ await rig.app.cancelAgentCreation(attempt),+ 'The request may already be starting. Check status before starting '+ 'another.',+ );+ expect(attempt.awaitingConfirmation, isTrue);+ });++ test('an answer for another receipt is not this cancel', () async {+ final rig = await holdingRig();+ rig.conn('m').answers['agent_create_cancel'] = (_) => {+ 'creationId': 'someone-else',+ 'state': 'cancelled',+ };+ final attempt = await heldCreation(rig);++ expect(+ await rig.app.cancelAgentCreation(attempt),+ 'The request may already be starting. Check status before starting '+ 'another.',+ );+ expect(attempt.canCancelPending, isTrue);+ });++ test('a request cancelled elsewhere ends on a status check', () async {+ final rig = await holdingRig();+ final conn = rig.conn('m');+ final attempt = await heldCreation(rig);+ conn.answers['agent_create_status'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'cancelled',+ };++ expect(await rig.app.checkAgentCreation(attempt), 'Creation cancelled.');+ expect(attempt.awaitingConfirmation, isFalse);+ expect(attempt.canCancelPending, isFalse);+ });++ test('a hold that turns into a start is no longer cancellable', () async {+ final rig = await holdingRig();+ final conn = rig.conn('m');+ final attempt = await heldCreation(rig);+ conn.answers['agent_create_status'] = (p) => {+ 'creationId': p['creationId'],+ 'state': 'pending',+ };++ await rig.app.checkAgentCreation(attempt);++ expect(attempt.awaitingConfirmation, isTrue);+ expect(attempt.canCancelPending, isFalse);+ });+}