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
The first workspace and New Harness follow a harness the machine is still installing an agent for (#1230)
Dee3340eb0bd2e9
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 425a53205..32592ae63 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -258,8 +258,16 @@ class _AgentChange {}class AgentCreationAttempt {- AgentCreationAttempt({this.background = false, String? creationId})- : _id = creationId ?? _newCreationId();+ AgentCreationAttempt({+ this.background = false,+ String? creationId,+ this.holdWait,+ }) : _id = creationId ?? _newCreationId();++ /// How long a request the machine holds is waited for before the create+ /// answers ([AppNotifier._createFollowingHold]). Null answers at once with+ /// what it waits for, as a form wants: the person reads it and may cancel.+ final Duration? holdWait;String _id;String? _machineId, _targetId;Map<String, dynamic>? _choices;@@ -11651,16 +11659,56 @@ class AppNotifier extends ChangeNotifier {// same refusal for an engine that has no such thing (`AGENT_UNSUPPORTED`).'agent': ?agent,};- return _create(+ final creation = attempt ?? AgentCreationAttempt();+ Future<String?> ask() => _create(machineId,choices,projectFolder: projectFolder,dsh: dsh,swarmId: swarmId,split: split,- attempt: attempt,+ attempt: creation,placement: placement,);+ final holdWait = creation.holdWait;+ return holdWait == null+ ? ask()+ : _createFollowingHold(creation, holdWait, ask);+ }++ /// How often a harness the machine holds is asked after+ /// ([_createFollowingHold], for an [AgentCreationAttempt.holdWait]): the+ /// pace `harness new` asks at.+ @visibleForTesting+ Duration heldCreationInterval = const Duration(seconds: 2);++ /// A create that waits out a hold. The machine starts a held harness by+ /// itself (an engine it is installing, a model waking) and answers `pending`+ /// meanwhile; [ask] again reads what became of that same request, never+ /// starts a second. Asked every [heldCreationInterval] until the harness is+ /// made, refused or cancelled, or [wait] has passed, when the hold's own+ /// words are the answer as they are without this.+ ///+ /// For a caller nobody is watching. The first workspace on a new computer+ /// asked once, while setup was still downloading the agents, was told+ /// "Installing OpenCode. The harness starts once it is installed.", and+ /// opened nothing: the three harnesses then started with no pane anywhere+ /// (desktop 1.2.65 with CLI 0.3.77, a fresh Ubuntu VM, 2026-10-12).+ Future<String?> _createFollowingHold(+ AgentCreationAttempt creation,+ Duration wait,+ Future<String?> Function() ask,+ ) async {+ final deadline = DateTime.now().add(wait);+ var answer = await ask();+ while (creation.canCancelPending &&+ !_disposed &&+ DateTime.now().isBefore(deadline)) {+ await Future<void>.delayed(heldCreationInterval);+ if (_disposed || creation._finished) break;+ answer = await ask();+ }+ return answer;}/// How long, from its start, a create waits for its agent's download beside setupdiff --git a/desktop/lib/state/first_arrival.dart b/desktop/lib/state/first_arrival.dartindex dc8467b9c..12a1d676d 100644--- a/desktop/lib/state/first_arrival.dart+++ b/desktop/lib/state/first_arrival.dart@@ -155,6 +155,8 @@ class FirstArrival {Duration machineWait = const Duration(seconds: 30),Duration indexWait = const Duration(seconds: 15),Duration starterWait = const Duration(minutes: 3),+ // As long as a create waits for an agent's download beside setup (`agentPrefetchWait`).+ Duration installWait = const Duration(minutes: 10),}) {if (_inFlight case final inFlight?) return inFlight;if (!pending) return Future.value(false);@@ -164,6 +166,7 @@ class FirstArrival {machineWait: machineWait,indexWait: indexWait,starterWait: starterWait,+ installWait: installWait,);_inFlight = run;return run.whenComplete(() => _inFlight = null);@@ -177,6 +180,7 @@ class FirstArrival {required Duration machineWait,required Duration indexWait,required Duration starterWait,+ required Duration installWait,}) async {_running = true;final started = _now();@@ -224,7 +228,14 @@ class FirstArrival {if (!current()) return stop('the person took over');tabs.add(app.activeSwarmId);opened = plan.fresh.isNotEmpty- ? await _openFresh(app, machineId, plan, starterWait, current)+ ? await _openFresh(+ app,+ machineId,+ plan,+ starterWait,+ installWait,+ current,+ ): await _openSessions(app, machineId, plan.tabs, tabs, current);return opened;} finally {@@ -358,6 +369,7 @@ class FirstArrival {String machineId,FirstArrivalPlan plan,Duration starterWait,+ Duration installWait,bool Function() current,) async {final String folder;@@ -384,6 +396,11 @@ class FirstArrival {permissionMode: kDefaultPermissionMode,swarmId: tabId,placement: HarnessPlacement.currentTab,+ // Setup is often still downloading the agent, and the machine then holds the harness+ // until it is installed and starts it by itself. Asked once, this was told so, opened+ // nothing, and the three harnesses started with no pane anywhere: the first workspace+ // was an empty tab with "Harnesses 3" under it (a fresh Ubuntu VM, 2026-10-12).+ attempt: AgentCreationAttempt(holdWait: installWait),);if (error != null) _log('first arrival: $engine not started: $error');// OpenCode the full height on the left, the other two stacked on the right. Applied as soondiff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dartindex 575b80861..c172215cc 100644--- a/desktop/lib/state/new_harness.dart+++ b/desktop/lib/state/new_harness.dart@@ -3373,7 +3373,34 @@ class NewHarnessController extends ChangeNotifier {bool get checking => _attempt?.awaitingConfirmation == true;bool get canCancelPending => _attempt?.canCancelPending == true;+ /// The check [followHeld] is making. Nobody pressed for it, so it shows+ /// nothing until it has an answer.+ Future<NewHarnessOutcome>? _following;++ /// Asks after a request the machine holds, without the person pressing+ /// Check status. The machine starts a held harness by itself (an agent it is+ /// installing, a model waking). The line said "Installing Kilo. The harness+ /// starts once it is installed." and stayed after Kilo had started, with no+ /// pane, until Check status was pressed (desktop 1.2.65, a fresh Ubuntu VM,+ /// 2026-10-12). Created once it has started; failed while it still waits,+ /// or when it was refused, which the line then says.+ Future<NewHarnessOutcome> followHeld() {+ if (_following case final check?) return check;+ if (_disposed || busy || !canCancelPending) {+ return Future.value(NewHarnessOutcome.failed);+ }+ final check = create(quiet: true);+ _following = check;+ return check.whenComplete(() => _following = null);+ }+Future<void> cancelPending() async {+ // A check nobody pressed for is let finish: it holds `busy` for a moment+ // without saying so, and a Cancel pressed just then must still count.+ if (_following case final check?) {+ await check;+ if (_disposed) return;+ }if (busy || !canCancelPending) return;busy = true;notifyListeners();@@ -3418,7 +3445,9 @@ class NewHarnessController extends ChangeNotifier {return !endCompletion();}- Future<NewHarnessOutcome> create() async {+ /// [quiet] is [followHeld]'s: a check on a held request that changes+ /// nothing on screen until it has an answer.+ Future<NewHarnessOutcome> create({bool quiet = false}) async {if (busy || linkingProfile) {return NewHarnessOutcome.failed;}@@ -3534,9 +3563,11 @@ class NewHarnessController extends ChangeNotifier {}final attempt = _attempt!;busy = true;- error = null;- status = recheck ? 'Checking on the harness…' : 'Starting harness…';- notifyListeners();+ if (!(quiet && recheck)) {+ error = null;+ status = recheck ? 'Checking on the harness…' : 'Starting harness…';+ notifyListeners();+ }if (_model != null && !recheck) {await refreshModels();if (_disposed) return NewHarnessOutcome.failed;diff --git a/desktop/lib/widgets/new_harness_form.dart b/desktop/lib/widgets/new_harness_form.dartindex 5afbf474d..152c74aba 100644--- a/desktop/lib/widgets/new_harness_form.dart+++ b/desktop/lib/widgets/new_harness_form.dart@@ -158,11 +158,44 @@ class NewHarnessFormState extends State<NewHarnessForm> {// Restoring the successful agent can replace an unfocusable Terminal// editor and its attachment wrappers. Let that rebuild finish first._focusEditor();+ _followHeld();+ });+ }++ /// How often a request the machine holds is asked after ([_followHeld]).+ @visibleForTesting+ static Duration heldFollowInterval = const Duration(seconds: 3);++ Timer? _heldFollow;++ /// A request the machine holds starts by itself (an agent it is installing,+ /// a model waking). Asked after while this form is open, so the harness+ /// opens when it has started; before, it started with no pane and the form+ /// went on saying it would, until Check status was pressed+ /// ([NewHarnessController.followHeld]).+ void _followHeld() {+ if (!box.canCancelPending) {+ _heldFollow?.cancel();+ _heldFollow = null;+ return;+ }+ if (_heldFollow != null) return;+ _heldFollow = Timer(heldFollowInterval, () async {+ _heldFollow = null;+ if (!mounted) return;+ final outcome = await box.followHeld();+ if (!mounted) return;+ if (outcome == NewHarnessOutcome.created) {+ widget.onCreated();+ } else {+ _followHeld();+ }});}@overridevoid dispose() {+ _heldFollow?.cancel();widget.devicePort?.detach();box.removeListener(_onBox);terminalThemeStore.removeListener(_onBox);@@ -186,6 +219,7 @@ class NewHarnessFormState extends State<NewHarnessForm> {NewHarnessField? _observedField;void _onBox() {if (!mounted) return;+ _followHeld();if (_taskText.text != box.task) {_taskText.value = TextEditingValue(text: box.task,@@ -1906,9 +1940,13 @@ class NewHarnessFormState extends State<NewHarnessForm> {},onTapOutside: (_) {},decoration: InputDecoration(+ // An agent that takes no first message is not a terminal: with Kilo chosen+ // the box said a terminal would open (a fresh Ubuntu VM, 2026-10-12).hintText: box.takesTask? 'What would you like to work on?'- : 'Open a terminal in this repo',+ : box.isTerminal+ ? 'Open a terminal in this repo'+ : 'Type to ${box.agentLabel} once it opens',hintStyle: DesktopChrome.text(size: 15,color: DesktopChrome.muted,diff --git a/desktop/test/held_creation_follow_test.dart b/desktop/test/held_creation_follow_test.dartnew file mode 100644index 000000000..bd2137ff1--- /dev/null+++ b/desktop/test/held_creation_follow_test.dart@@ -0,0 +1,402 @@+// A harness the machine holds starts by itself: an agent it is installing, a+// model waking. Found on a fresh Ubuntu VM with desktop 1.2.65 and CLI 0.3.77+// (2026-10-12): the first workspace asked once while setup was still+// downloading the agents, was told "Installing OpenCode. The harness starts+// once it is installed.", and opened nothing, so three harnesses started with+// no pane anywhere. In the New Harness box the same line stayed after the+// harness had started, until Check status was pressed.+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/state/new_harness.dart';+import 'package:harness/widgets/new_harness_form.dart';+import 'package:harness/ws/ws_conn.dart';++import 'swarm_state_test.dart' show createApp;++const _installing = 'Installing Kilo. The harness starts once it is installed.';++/// A machine that holds a create while it installs the agent, then starts the+/// harness by itself: `pending` for [holds] answers, then made or refused.+class _Machine extends WsConn {+ _Machine()+ : super(+ wsBaseUrl: 'ws://fixture.invalid',+ autonomousEnv: 'test',+ machineId: 'm',+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ );++ int holds = 0;+ bool refuses = false;++ /// Keeps the next status answer back until it completes.+ Completer<void>? gate;+ final asked = <String>[];+ final cancels = <String>[];+ String? _engine;++ @override+ Future<Map<String, dynamic>> request(+ String type, {+ Map<String, dynamic> payload = const {},+ Duration timeout = const Duration(seconds: 20),+ }) async {+ switch (type) {+ case 'engines_probe':+ return {'engines': []};+ case 'git_project_info':+ return {'isGit': false};+ case 'fs_list_dir':+ return {'path': '/work', 'entries': []};+ case 'dsh_list':+ return {'dsh': []};+ case 'agent_create':+ asked.add(type);+ _engine = payload['engine'] as String?;+ return _answer(payload['creationId'] as String);+ case 'agent_create_status':+ asked.add(type);+ if (gate case final held?) {+ gate = null;+ await held.future;+ }+ return _answer(payload['creationId'] as String);+ case 'agent_create_cancel':+ cancels.add(payload['creationId'] as String);+ return {'creationId': payload['creationId'], 'state': 'cancelled'};+ default:+ return {};+ }+ }++ Map<String, dynamic> _answer(String creationId) {+ if (holds > 0) {+ holds--;+ return {+ 'creationId': creationId,+ 'state': 'pending',+ 'held': {'service': 'install', 'detail': _installing},+ };+ }+ if (refuses) {+ return {+ 'creationId': creationId,+ 'state': 'failed',+ 'failure': {+ 'code': 'ENGINE_INSTALL_FAILED',+ 'detail': 'Kilo could not be installed: npm ERR! network',+ },+ };+ }+ return {+ 'creationId': creationId,+ 'state': 'created',+ 'agent': {'id': 'made', 'name': 'Made', 'engine': _engine},+ };+ }+}++AppNotifier _app(_Machine machine) {+ final app = createApp(connectionForTest: (_) => machine, connected: true)+ ..heldCreationInterval = const Duration(milliseconds: 1);+ addTearDown(app.dispose);+ return app;+}++Iterable<String?> _panesOf(AppNotifier app) =>+ app.allPanes.map((pane) => pane.agentId);++void main() {+ group('a create told to wait out a hold', () {+ test('asks after the same request until the harness is made, and opens its pane', () async {+ final machine = _Machine()..holds = 3;+ final app = _app(machine);+ final attempt = AgentCreationAttempt(+ holdWait: const Duration(minutes: 1),+ );+ final error = await app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: attempt,+ );+ expect(error, isNull);+ // One create, then what became of it: never a second harness.+ expect(machine.asked, [+ 'agent_create',+ 'agent_create_status',+ 'agent_create_status',+ 'agent_create_status',+ ]);+ expect(attempt.agentId, 'made');+ expect(attempt.awaitingConfirmation, isFalse);+ expect(_panesOf(app).where((id) => id == 'made'), hasLength(1));+ });++ test('answers at once, as before, when it is not held', () async {+ final machine = _Machine();+ final app = _app(machine);+ final error = await app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: AgentCreationAttempt(holdWait: const Duration(minutes: 1)),+ );+ expect(error, isNull);+ expect(machine.asked, ['agent_create']);+ });++ test('ends on a refusal, with the machine\'s reason', () async {+ final machine = _Machine()+ ..holds = 1+ ..refuses = true;+ final app = _app(machine);+ final attempt = AgentCreationAttempt(+ holdWait: const Duration(minutes: 1),+ );+ final error = await app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: attempt,+ );+ expect(error, isNotNull);+ expect(machine.asked, ['agent_create', 'agent_create_status']);+ expect(attempt.awaitingConfirmation, isFalse);+ expect(_panesOf(app), isNot(contains('made')));+ });++ test('gives the hold\'s own words when the wait has passed, the request still saved', () async {+ final machine = _Machine()..holds = 1 << 20;+ final app = _app(machine);+ final attempt = AgentCreationAttempt(+ holdWait: const Duration(milliseconds: 40),+ );+ final error = await app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: attempt,+ );+ expect(error, _installing);+ expect(attempt.canCancelPending, isTrue);+ expect(machine.asked.where((type) => type == 'agent_create'), [+ 'agent_create',+ ]);+ expect(machine.asked.length, greaterThan(1));+ });+ });++ test(+ 'a create not told to wait answers a hold at once with what it waits for',+ () async {+ final machine = _Machine()..holds = 3;+ final app = _app(machine);+ final attempt = AgentCreationAttempt();+ final error = await app.createAgent(+ 'm',+ engine: 'kilo',+ folder: '/work',+ attempt: attempt,+ );+ expect(error, _installing);+ expect(machine.asked, ['agent_create']);+ expect(attempt.canCancelPending, isTrue);+ },+ );++ group('the New Harness box', () {+ NewHarnessController boxOn(AppNotifier app) {+ final box = NewHarnessController(+ app,+ machineId: 'm',+ engine: 'claude',+ folder: '/work',+ );+ addTearDown(box.dispose);+ return box;+ }++ test('asks after a held request by itself, changing nothing on screen until the harness has started', () async {+ final machine = _Machine()..holds = 2;+ final app = _app(machine);+ final box = boxOn(app);+ expect(await box.create(), NewHarnessOutcome.failed);+ expect(box.error, _installing);+ expect(box.canCancelPending, isTrue);++ // Still held: the line and the buttons stay exactly as they were.+ final seen = <(String?, String?)>[];+ void record() => seen.add((box.status, box.error));+ box.addListener(record);+ final still = box.followHeld();+ expect((box.status, box.error), (null, _installing));+ expect(await still, NewHarnessOutcome.failed);+ expect(seen, [(null, _installing)]);+ expect(box.canCancelPending, isTrue);+ box.removeListener(record);++ // Started: the same outcome a press of Check status would have had.+ expect(await box.followHeld(), NewHarnessOutcome.created);+ expect(box.checking, isFalse);+ expect(box.busy, isFalse);+ expect(machine.asked, [+ 'agent_create',+ 'agent_create_status',+ 'agent_create_status',+ ]);+ expect(_panesOf(app).where((id) => id == 'made'), hasLength(1));+ });++ test('has nothing to ask after when no request is held', () async {+ final machine = _Machine();+ final app = _app(machine);+ final box = boxOn(app);+ expect(await box.followHeld(), NewHarnessOutcome.failed);+ expect(machine.asked, isEmpty);+ });++ test('says a refusal that came while it waited', () async {+ final machine = _Machine()+ ..holds = 1+ ..refuses = true;+ final app = _app(machine);+ final box = boxOn(app);+ await box.create();+ expect(await box.followHeld(), NewHarnessOutcome.failed);+ expect(box.error, isNot(_installing));+ expect(box.checking, isFalse);+ expect(box.canCancelPending, isFalse);+ });++ test('still cancels when Cancel is pressed during such a check', () async {+ final machine = _Machine()..holds = 10;+ final app = _app(machine);+ final box = boxOn(app);+ await box.create();+ final gate = machine.gate = Completer<void>();+ final check = box.followHeld();+ final cancel = box.cancelPending();+ // The same check is joined, not doubled.+ expect(box.followHeld(), completion(NewHarnessOutcome.failed));+ gate.complete();+ expect(await check, NewHarnessOutcome.failed);+ await cancel;+ expect(machine.cancels, hasLength(1));+ expect(box.status, 'Creation cancelled.');+ expect(box.canCancelPending, isFalse);+ });++ for (final (engine, hint) in [+ ('claude', 'What would you like to work on?'),+ ('terminal', 'Open a terminal in this repo'),+ // Takes no first message, and is not a terminal: the box said one would open.+ ('kilo', 'Type to Kilo once it opens'),+ ]) {+ testWidgets('says what $engine does with the task line', (tester) async {+ final app = _app(_Machine());+ final box = NewHarnessController(+ app,+ machineId: 'm',+ engine: engine,+ folder: '/work',+ );+ addTearDown(box.dispose);+ await tester.pumpWidget(+ MaterialApp(+ theme: ThemeData.dark(),+ home: Scaffold(+ body: Center(+ child: SizedBox(+ width: 1000,+ height: 600,+ child: NewHarnessForm(+ controller: box,+ onClose: () {},+ onCreated: () {},+ desktop: true,+ embedded: true,+ ),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ final field = tester.widget<TextField>(+ find.byKey(const ValueKey('new-harness-task')),+ );+ expect(field.decoration?.hintText, hint);+ });+ }++ testWidgets(+ 'the form opens the harness when it has started, with no press',+ (tester) async {+ final previous = NewHarnessFormState.heldFollowInterval;+ NewHarnessFormState.heldFollowInterval = const Duration(seconds: 3);+ addTearDown(() => NewHarnessFormState.heldFollowInterval = previous);+ final machine = _Machine()..holds = 3;+ final app = _app(machine);+ final box = boxOn(app);+ var created = 0;+ await tester.pumpWidget(+ MaterialApp(+ theme: ThemeData.dark(),+ home: Scaffold(+ body: Center(+ child: SizedBox(+ width: 820,+ height: 450,+ child: NewHarnessForm(+ controller: box,+ onClose: () {},+ onCreated: () => created++,+ ),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ // Not through runAsync: a timer made there is a real one, which no pump moves.+ final first = box.create();+ await tester.pump();+ expect(await first, NewHarnessOutcome.failed);+ await tester.pump();+ expect(box.error, _installing);+ expect(find.text(_installing), findsOneWidget);+ expect(created, 0);++ // Twice still installing, then started: each a check nobody pressed for.+ await tester.pump(const Duration(seconds: 3));+ await tester.pump();+ expect(machine.asked, hasLength(2));+ expect(created, 0);+ expect(find.text(_installing), findsOneWidget);+ await tester.pump(const Duration(seconds: 3));+ await tester.pump();+ expect(created, 0);+ await tester.pump(const Duration(seconds: 3));+ await tester.pump();+ expect(created, 1);+ expect(machine.asked, [+ 'agent_create',+ 'agent_create_status',+ 'agent_create_status',+ 'agent_create_status',+ ]);++ // Nothing more is asked once it is made.+ await tester.pump(const Duration(seconds: 10));+ expect(machine.asked, hasLength(4));+ },+ );+ });+}