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
Linux: download the agents during setup and open the first tab on them, as on a Mac (#1128)
Deef810d23ecec5
diff --git a/desktop/lib/bootstrap/agent_prefetch.dart b/desktop/lib/bootstrap/agent_prefetch.dartindex 172d02d8f..ddc699ac0 100644--- a/desktop/lib/bootstrap/agent_prefetch.dart+++ b/desktop/lib/bootstrap/agent_prefetch.dart@@ -47,6 +47,7 @@ class AgentPrefetch {bool Function()? skip,bool Function(String engine)? installed,String? Function()? managedNode,+ bool Function()? curl,void Function(String line)? log,DateTime Function()? now,Duration nodePoll = const Duration(seconds: 1),@@ -65,6 +66,7 @@ class AgentPrefetch {_skip = skip ?? (() => alreadyHasAnAgent(_home)),_installed = installed ?? _agentInPlace,_managedNode = managedNode ?? _managedNodePath,+ _curl = curl ?? (kUnderTest ? (() => true) : _hasCurl),_log = log ?? ((_) {}),_now = now ?? DateTime.now,_nodePoll = nodePoll,@@ -82,6 +84,7 @@ class AgentPrefetch {final bool Function() _skip;final bool Function(String engine) _installed;final String? Function() _managedNode;+ final bool Function() _curl;final void Function(String line) _log;final DateTime Function() _now;final Duration _nodePoll;@@ -192,6 +195,13 @@ class AgentPrefetch {}Future<void> _runOpenCode() async {+ // A fresh Ubuntu has no curl until setup's apt step installs it (`environment_provisioner.dart`).+ if (!await _until(_curl)) {+ _log('OpenCode was not downloaded during setup: curl never arrived');+ return;+ }+ // A create's wait counts from the download itself, not from the wait for curl before it.+ _startedAt['opencode'] = _now();await _run('OpenCode',const ['opencode'],@@ -234,12 +244,8 @@ class AgentPrefetch {/// Codex and Claude Code, once setup has put Harness's Node in place: one npm, so the two never/// write the same global prefix at once.Future<void> _npmWhenNodeIsThere() async {- final deadline = _now().add(_nodeWait);- String? node = _managedNode();- while (node == null && _now().isBefore(deadline)) {- await Future<void>.delayed(_nodePoll);- node = _managedNode();- }+ String? node;+ await _until(() => (node = _managedNode()) != null);if (node == null) {_log('Codex and Claude Code were not downloaded during setup: Harness\'s Node never arrived',@@ -248,7 +254,7 @@ class AgentPrefetch {}// A create's wait counts from the download itself, not from the wait for Node before it._startedAt['codex'] = _startedAt['claude'] = _now();- final bin = File(node).parent.path;+ final bin = File(node!).parent.path;final script = ['set -o pipefail','export PATH=${_quote(bin)}:"\$PATH"',@@ -341,6 +347,35 @@ class AgentPrefetch {}}+ /// Setup is still putting in place what the downloads need (curl, Harness's Node): they wait for it+ /// as long as it runs, and [_nodeWait] more once it is over. On Linux setup waits for a password in+ /// Terminal, and on a first boot its apt queues behind Ubuntu's own updates; a wait that ran out+ /// meanwhile left the first tab to install Codex and Claude Code in two panes at once, two npm in+ /// one prefix.+ bool setupRunning = false;++ /// Stops every wait: the app is going away.+ void close() => _closed = true;+ bool _closed = false;++ /// Whether [there] holds, asked every [_nodePoll] while setup runs and until [_nodeWait] after.+ Future<bool> _until(bool Function() there) async {+ var deadline = _now().add(_nodeWait);+ var found = there();+ while (!found && !_closed) {+ if (setupRunning) deadline = _now().add(_nodeWait);+ if (!_now().isBefore(deadline)) break;+ await Future<void>.delayed(_nodePoll);+ found = there();+ }+ return found;+ }++ /// curl on the PATH the app runs downloads with.+ static bool _hasCurl() => (Platform.environment['PATH'] ?? '/usr/bin:/bin')+ .split(':')+ .any((dir) => dir.isNotEmpty && File('$dir/curl').existsSync());+static String _quote(String text) => "'${text.replaceAll("'", "'\\''")}'";static String? get _home => Platform.environment['HOME'];diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex a6e5f267f..1d75b6aef 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -4292,11 +4292,17 @@ class AppNotifier extends ChangeNotifier {final firstHarness =result.plan.any((item) => item.step == EnvironmentStep.harness) &&!harnessInstalledBefore();+ // OpenCode, Codex and Claude Code download meanwhile when it has no agent at all+ // ([AgentPrefetch.start] decides), on Linux too, where the apt step waits for a password in+ // Terminal and setup keeps its own screen: a fresh Ubuntu VM (2026-10-09) ended setup on an empty+ // box and installed OpenCode in its first pane, about 90 s to a first result against 55 s on a Mac.+ // They wait for what setup brings until it is ready ([_continueAfterEnvironmentReady]).+ if (firstHarness) {+ agentPrefetch?.setupRunning = true;+ agentPrefetch?.start();+ }if (!result.isReady && _canInstallUnattended(result, mode: null)) {if (firstHarness) {- // OpenCode, Codex and Claude Code download meanwhile when it has no agent at all- // ([AgentPrefetch.start] decides).- agentPrefetch?.start();_publishAgentDownloads();// Nobody needs to act on this install, so it runs under the welcome tour rather than on// the install screen.@@ -4410,6 +4416,7 @@ class AppNotifier extends ChangeNotifier {/// [recheckEnvironmentStep] can reach the same destination without repeating `bootstrap()`'s config/// load and update-check startup, which already ran on the launch that got stuck here.Future<void> _continueAfterEnvironmentReady() async {+ agentPrefetch?.setupRunning = false;final revision = _authRevision;if (!_authWorkCurrent(revision)) return;_cancelEnvironmentRecheckTimer();@@ -17227,6 +17234,7 @@ class AppNotifier extends ChangeNotifier {}_closeOwnerMemories();_agentDownloadsTick?.cancel();+ agentPrefetch?.close();setupDownloads.dispose();experimentalFeatures.dispose();deviceHosts.dispose();diff --git a/desktop/test/agent_prefetch_test.dart b/desktop/test/agent_prefetch_test.dartindex 2eea037e6..fbf671f3c 100644--- a/desktop/test/agent_prefetch_test.dart+++ b/desktop/test/agent_prefetch_test.dart@@ -11,12 +11,25 @@ import 'package:harness/bootstrap/setup_progress.dart';import 'package:harness/core/config.dart';import 'package:harness/core/engine_availability.dart';import 'package:harness/core/models.dart';+import 'package:harness/core/local_key_value_store.dart';import 'package:harness/state/app_state.dart';+import 'package:harness/state/first_arrival.dart';+import 'package:harness/state/pane_layout_store.dart';import 'package:harness/ws/ws_conn.dart';import 'support/guest_app.dart';/// An installer that exits when the test says so.+class _MemoryStore implements LocalKeyValueStore {+ final values = <String, String>{};+ @override+ Future<String?> read(String key) async => values[key];+ @override+ Future<void> write(String key, String value) async => values[key] = value;+ @override+ Future<void> delete(String key) async => values.remove(key);+}+class _Install implements Process {final _exit = Completer<int>();final _out = StreamController<List<int>>();@@ -236,6 +249,96 @@ void main() {},);+ // A fresh Ubuntu (2026-10-09) has no curl until setup's apt step, which waits for a password in+ // Terminal.+ test('waits for curl before OpenCode, and counts a create\'s wait from the download', () async {+ var curl = false;+ var now = DateTime(2026, 10, 9, 12);+ final runs = <List<String>>[];+ final opencode = _Install();+ final npm = _Install();+ var next = 0;+ final installs = [opencode, npm];+ final prefetch = AgentPrefetch(+ start: (executable, arguments) async {+ runs.add([executable, ...arguments]);+ return installs[next++];+ },+ skip: () => false,+ installed: (_) => false,+ managedNode: () => null,+ curl: () => curl,+ now: () => now,+ nodePoll: const Duration(milliseconds: 5),+ )..start();+ addTearDown(prefetch.close);+ await Future<void>.delayed(const Duration(milliseconds: 30));+ expect(runs, isEmpty, reason: 'no OpenCode without curl');+ now = now.add(const Duration(minutes: 8));+ curl = true;+ await Future<void>.delayed(const Duration(milliseconds: 30));+ expect(runs, hasLength(1));+ expect(+ runs.single[2],+ contains('curl -fsSL https://opencode.ai/install'),+ );+ expect(+ prefetch.waitFor('opencode', const Duration(minutes: 1)),+ isNotNull,+ reason: 'the minutes spent waiting for curl are not the download\'s',+ );+ opencode.finish(0);++ final lines = <String>[];+ final never = AgentPrefetch(+ start: (_, _) async => _Install()..finish(0),+ skip: () => false,+ installed: (_) => false,+ managedNode: () => null,+ curl: () => false,+ log: lines.add,+ nodePoll: const Duration(milliseconds: 5),+ nodeWait: const Duration(milliseconds: 20),+ )..start();+ await never.everything;+ expect(lines, contains(contains('curl never arrived')));+ });++ // On Linux setup waits for a Terminal password, and on a first boot its apt queues behind Ubuntu's+ // own updates: a wait that ran out meanwhile left Codex and Claude Code to two npm in two panes.+ test(+ 'waits for what setup brings as long as setup runs, then a while more',+ () async {+ var now = DateTime(2026, 10, 9, 12);+ final lines = <String>[];+ final prefetch = AgentPrefetch(+ start: (_, _) async => _Install()..finish(0),+ skip: () => false,+ installed: (_) => false,+ managedNode: () => null,+ log: lines.add,+ now: () => now,+ nodePoll: const Duration(milliseconds: 5),+ nodeWait: const Duration(minutes: 5),+ )..setupRunning = true;+ addTearDown(prefetch.close);+ prefetch.start();+ now = now.add(const Duration(minutes: 30));+ await Future<void>.delayed(const Duration(milliseconds: 30));+ expect(lines, isNot(contains(contains('never arrived'))));+ prefetch.setupRunning = false;+ await Future<void>.delayed(const Duration(milliseconds: 30));+ expect(+ lines,+ isNot(contains(contains('never arrived'))),+ reason: 'five minutes from the end of setup',+ );+ now = now.add(const Duration(minutes: 6));+ await prefetch.everything;+ expect(lines, contains(contains("Harness's Node never arrived")));+ },+ );+test('runs OpenCode once after its download, so a pane never pays its first run', () async {final opencode = _Install();final warm = _Install();@@ -602,20 +705,53 @@ void main() {);});- test('a setup that needs Terminal (Linux apt) does not', () async {+ const apt = EnvironmentPlanItem(+ step: EnvironmentStep.tmux,+ title: 'Linux host dependencies',+ detail: 'tmux, curl',+ command: 'sudo apt-get install -y tmux curl',+ requiresTerminal: true,+ );++ // A fresh Ubuntu VM (2026-10-09) ended setup on an empty box and installed OpenCode in its first+ // pane: about 90 s to a first result, against 55 s on a Mac.+ test('a setup that needs Terminal (Linux apt) starts it too, and opens the first tab on the agents', () async {+ var started = false;+ final store = _MemoryStore();+ final app = GuestTestApp(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ cliLogin: _FakeCliLogin(),+ paneLayoutStore: PaneLayoutStore(storage: store),+ environmentProvisioner: _Provisioner(+ _review([apt, EnvironmentPlanItem.harnessCli]),+ ),+ agentPrefetch: AgentPrefetch(+ start: (_, _) async {+ started = true;+ return _Install()..finish(0);+ },+ skip: () => false,+ managedNode: () => null,+ ),+ );+ addTearDown(app.dispose);+ await app.bootstrap();+ await pumpEventQueue();+ expect(started, isTrue);expect(- await startedFor([- const EnvironmentPlanItem(- step: EnvironmentStep.tmux,- title: 'Linux host dependencies',- detail: 'tmux',- command: 'sudo apt-get install -y tmux',- requiresTerminal: true,- ),- EnvironmentPlanItem.harnessCli,- ]),+ app.setupTourShowing,isFalse,+ reason: 'the apt step is the setup screen\'s, with its Terminal',+ );+ await app.firstArrival.restore();+ expect(+ store.values[FirstArrival.key],+ 'new',+ reason: 'the first tab opens on OpenCode, Codex and Claude Code',);+ expect(app.agentPrefetch!.setupRunning, isTrue);});});diff --git a/desktop/test/support/guest_app.dart b/desktop/test/support/guest_app.dartindex 88cdbaa93..6b92a890f 100644--- a/desktop/test/support/guest_app.dart+++ b/desktop/test/support/guest_app.dart@@ -10,6 +10,7 @@ class GuestTestApp extends AppNotifier {super.environmentProvisioner,super.agentPrefetch,super.localManualFixture,+ super.paneLayoutStore,});var daemonGates = 0;